• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_INCOMING_VIDEO_STREAM_H_
12 #define WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_INCOMING_VIDEO_STREAM_H_
13 
14 #include "webrtc/modules/video_render/include/video_render.h"
15 
16 namespace webrtc {
17 class CriticalSectionWrapper;
18 class EventWrapper;
19 class ThreadWrapper;
20 class VideoRenderCallback;
21 class VideoRenderFrames;
22 
23 struct VideoMirroring {
VideoMirroringVideoMirroring24   VideoMirroring() : mirror_x_axis(false), mirror_y_axis(false) {}
25   bool mirror_x_axis;
26   bool mirror_y_axis;
27 };
28 
29 class IncomingVideoStream : public VideoRenderCallback {
30  public:
31   IncomingVideoStream(const int32_t module_id,
32                       const uint32_t stream_id);
33   ~IncomingVideoStream();
34 
35   int32_t ChangeModuleId(const int32_t id);
36 
37   // Get callback to deliver frames to the module.
38   VideoRenderCallback* ModuleCallback();
39   virtual int32_t RenderFrame(const uint32_t stream_id,
40                               I420VideoFrame& video_frame);
41 
42   // Set callback to the platform dependent code.
43   int32_t SetRenderCallback(VideoRenderCallback* render_callback);
44 
45   // Callback for file recording, snapshot, ...
46   int32_t SetExternalCallback(VideoRenderCallback* render_object);
47 
48   // Start/Stop.
49   int32_t Start();
50   int32_t Stop();
51 
52   // Clear all buffers.
53   int32_t Reset();
54 
55   // Properties.
56   uint32_t StreamId() const;
57   uint32_t IncomingRate() const;
58 
59   int32_t GetLastRenderedFrame(I420VideoFrame& video_frame) const;
60 
61   int32_t SetStartImage(const I420VideoFrame& video_frame);
62 
63   int32_t SetTimeoutImage(const I420VideoFrame& video_frame,
64                           const uint32_t timeout);
65 
66   int32_t EnableMirroring(const bool enable,
67                           const bool mirror_xaxis,
68                           const bool mirror_yaxis);
69 
70   int32_t SetExpectedRenderDelay(int32_t delay_ms);
71 
72  protected:
73   static bool IncomingVideoStreamThreadFun(void* obj);
74   bool IncomingVideoStreamProcess();
75 
76  private:
77   enum { KEventStartupTimeMS = 10 };
78   enum { KEventMaxWaitTimeMs = 100 };
79   enum { KFrameRatePeriodMs = 1000 };
80 
81   int32_t module_id_;
82   uint32_t stream_id_;
83   // Critsects in allowed to enter order.
84   CriticalSectionWrapper& stream_critsect_;
85   CriticalSectionWrapper& thread_critsect_;
86   CriticalSectionWrapper& buffer_critsect_;
87   ThreadWrapper* incoming_render_thread_;
88   EventWrapper& deliver_buffer_event_;
89   bool running_;
90 
91   VideoRenderCallback* external_callback_;
92   VideoRenderCallback* render_callback_;
93   VideoRenderFrames& render_buffers_;
94 
95   RawVideoType callbackVideoType_;
96   uint32_t callbackWidth_;
97   uint32_t callbackHeight_;
98 
99   uint32_t incoming_rate_;
100   int64_t last_rate_calculation_time_ms_;
101   uint16_t num_frames_since_last_calculation_;
102   I420VideoFrame last_rendered_frame_;
103   I420VideoFrame temp_frame_;
104   I420VideoFrame start_image_;
105   I420VideoFrame timeout_image_;
106   uint32_t timeout_time_;
107 
108   bool mirror_frames_enabled_;
109   VideoMirroring mirroring_;
110   I420VideoFrame transformed_video_frame_;
111 };
112 
113 }  // namespace webrtc
114 
115 #endif  // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_INCOMING_VIDEO_STREAM_H_
116