OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ | 11 #ifndef WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ |
12 #define WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ | 12 #define WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "webrtc/base/criticalsection.h" | 16 #include "webrtc/base/criticalsection.h" |
17 #include "webrtc/base/platform_thread.h" | 17 #include "webrtc/base/platform_thread.h" |
18 #include "webrtc/base/thread_annotations.h" | 18 #include "webrtc/base/thread_annotations.h" |
19 #include "webrtc/common_video/video_render_frames.h" | 19 #include "webrtc/common_video/video_render_frames.h" |
| 20 #include "webrtc/media/base/videosinkinterface.h" |
20 | 21 |
21 namespace webrtc { | 22 namespace webrtc { |
22 class EventTimerWrapper; | 23 class EventTimerWrapper; |
23 | 24 |
24 class VideoRenderCallback { | 25 |
| 26 class IncomingVideoStream : public rtc::VideoSinkInterface<VideoFrame> { |
25 public: | 27 public: |
26 virtual int32_t RenderFrame(const uint32_t streamId, | 28 explicit IncomingVideoStream(bool disable_prerenderer_smoothing); |
27 const VideoFrame& videoFrame) = 0; | |
28 | |
29 protected: | |
30 virtual ~VideoRenderCallback() {} | |
31 }; | |
32 | |
33 class IncomingVideoStream : public VideoRenderCallback { | |
34 public: | |
35 IncomingVideoStream(uint32_t stream_id, bool disable_prerenderer_smoothing); | |
36 ~IncomingVideoStream(); | 29 ~IncomingVideoStream(); |
37 | 30 |
38 // Get callback to deliver frames to the module. | 31 // Overrides VideoSinkInterface |
39 VideoRenderCallback* ModuleCallback(); | 32 void OnFrame(const VideoFrame& video_frame) override; |
40 virtual int32_t RenderFrame(const uint32_t stream_id, | |
41 const VideoFrame& video_frame); | |
42 | 33 |
43 // Set callback to the platform dependent code. | 34 // Set callback to the platform dependent code. |
44 void SetRenderCallback(VideoRenderCallback* render_callback); | 35 void SetRenderCallback(rtc::VideoSinkInterface<VideoFrame>* render_callback); |
45 | 36 |
46 // Callback for file recording, snapshot, ... | 37 // Callback for file recording, snapshot, ... |
47 void SetExternalCallback(VideoRenderCallback* render_object); | 38 void SetExternalCallback(rtc::VideoSinkInterface<VideoFrame>* render_object); |
48 | 39 |
49 // Start/Stop. | 40 // Start/Stop. |
50 int32_t Start(); | 41 int32_t Start(); |
51 int32_t Stop(); | 42 int32_t Stop(); |
52 | 43 |
53 // Clear all buffers. | 44 // Clear all buffers. |
54 int32_t Reset(); | 45 int32_t Reset(); |
55 | 46 |
56 // Properties. | 47 // Properties. |
57 uint32_t StreamId() const; | |
58 uint32_t IncomingRate() const; | 48 uint32_t IncomingRate() const; |
59 | 49 |
60 int32_t SetExpectedRenderDelay(int32_t delay_ms); | 50 int32_t SetExpectedRenderDelay(int32_t delay_ms); |
61 | 51 |
62 protected: | 52 protected: |
63 static bool IncomingVideoStreamThreadFun(void* obj); | 53 static bool IncomingVideoStreamThreadFun(void* obj); |
64 bool IncomingVideoStreamProcess(); | 54 bool IncomingVideoStreamProcess(); |
65 | 55 |
66 private: | 56 private: |
67 enum { kEventStartupTimeMs = 10 }; | 57 enum { kEventStartupTimeMs = 10 }; |
68 enum { kEventMaxWaitTimeMs = 100 }; | 58 enum { kEventMaxWaitTimeMs = 100 }; |
69 enum { kFrameRatePeriodMs = 1000 }; | 59 enum { kFrameRatePeriodMs = 1000 }; |
70 | 60 |
71 void DeliverFrame(const VideoFrame& video_frame); | 61 void DeliverFrame(const VideoFrame& video_frame); |
72 | 62 |
73 uint32_t const stream_id_; | |
74 const bool disable_prerenderer_smoothing_; | 63 const bool disable_prerenderer_smoothing_; |
75 // Critsects in allowed to enter order. | 64 // Critsects in allowed to enter order. |
76 rtc::CriticalSection stream_critsect_; | 65 rtc::CriticalSection stream_critsect_; |
77 rtc::CriticalSection thread_critsect_; | 66 rtc::CriticalSection thread_critsect_; |
78 rtc::CriticalSection buffer_critsect_; | 67 rtc::CriticalSection buffer_critsect_; |
79 // TODO(pbos): Make plain member and stop resetting this thread, just | 68 // TODO(pbos): Make plain member and stop resetting this thread, just |
80 // start/stoping it is enough. | 69 // start/stoping it is enough. |
81 std::unique_ptr<rtc::PlatformThread> incoming_render_thread_ | 70 std::unique_ptr<rtc::PlatformThread> incoming_render_thread_ |
82 GUARDED_BY(thread_critsect_); | 71 GUARDED_BY(thread_critsect_); |
83 std::unique_ptr<EventTimerWrapper> deliver_buffer_event_; | 72 std::unique_ptr<EventTimerWrapper> deliver_buffer_event_; |
84 | 73 |
85 bool running_ GUARDED_BY(stream_critsect_); | 74 bool running_ GUARDED_BY(stream_critsect_); |
86 VideoRenderCallback* external_callback_ GUARDED_BY(thread_critsect_); | 75 rtc::VideoSinkInterface<VideoFrame>* external_callback_ |
87 VideoRenderCallback* render_callback_ GUARDED_BY(thread_critsect_); | 76 GUARDED_BY(thread_critsect_); |
| 77 rtc::VideoSinkInterface<VideoFrame>* render_callback_ |
| 78 GUARDED_BY(thread_critsect_); |
88 const std::unique_ptr<VideoRenderFrames> render_buffers_ | 79 const std::unique_ptr<VideoRenderFrames> render_buffers_ |
89 GUARDED_BY(buffer_critsect_); | 80 GUARDED_BY(buffer_critsect_); |
90 | 81 |
91 uint32_t incoming_rate_ GUARDED_BY(stream_critsect_); | 82 uint32_t incoming_rate_ GUARDED_BY(stream_critsect_); |
92 int64_t last_rate_calculation_time_ms_ GUARDED_BY(stream_critsect_); | 83 int64_t last_rate_calculation_time_ms_ GUARDED_BY(stream_critsect_); |
93 uint16_t num_frames_since_last_calculation_ GUARDED_BY(stream_critsect_); | 84 uint16_t num_frames_since_last_calculation_ GUARDED_BY(stream_critsect_); |
94 }; | 85 }; |
95 | 86 |
96 } // namespace webrtc | 87 } // namespace webrtc |
97 | 88 |
98 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ | 89 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ |
OLD | NEW |