| 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 // Get callback to deliver frames to the module. |
| 39 VideoRenderCallback* ModuleCallback(); | 32 rtc::VideoSinkInterface<VideoFrame>* ModuleCallback(); |
| 40 virtual int32_t RenderFrame(const uint32_t stream_id, | 33 void OnFrame(const VideoFrame& video_frame) override; |
| 41 const VideoFrame& video_frame); | |
| 42 | 34 |
| 43 // Set callback to the platform dependent code. | 35 // Set callback to the platform dependent code. |
| 44 void SetRenderCallback(VideoRenderCallback* render_callback); | 36 void SetRenderCallback(rtc::VideoSinkInterface<VideoFrame>* render_callback); |
| 45 | 37 |
| 46 // Callback for file recording, snapshot, ... | 38 // Callback for file recording, snapshot, ... |
| 47 void SetExternalCallback(VideoRenderCallback* render_object); | 39 void SetExternalCallback(rtc::VideoSinkInterface<VideoFrame>* render_object); |
| 48 | 40 |
| 49 // Start/Stop. | 41 // Start/Stop. |
| 50 int32_t Start(); | 42 int32_t Start(); |
| 51 int32_t Stop(); | 43 int32_t Stop(); |
| 52 | 44 |
| 53 // Clear all buffers. | 45 // Clear all buffers. |
| 54 int32_t Reset(); | 46 int32_t Reset(); |
| 55 | 47 |
| 56 // Properties. | 48 // Properties. |
| 57 uint32_t StreamId() const; | |
| 58 uint32_t IncomingRate() const; | 49 uint32_t IncomingRate() const; |
| 59 | 50 |
| 60 int32_t SetExpectedRenderDelay(int32_t delay_ms); | 51 int32_t SetExpectedRenderDelay(int32_t delay_ms); |
| 61 | 52 |
| 62 protected: | 53 protected: |
| 63 static bool IncomingVideoStreamThreadFun(void* obj); | 54 static bool IncomingVideoStreamThreadFun(void* obj); |
| 64 bool IncomingVideoStreamProcess(); | 55 bool IncomingVideoStreamProcess(); |
| 65 | 56 |
| 66 private: | 57 private: |
| 67 enum { kEventStartupTimeMs = 10 }; | 58 enum { kEventStartupTimeMs = 10 }; |
| 68 enum { kEventMaxWaitTimeMs = 100 }; | 59 enum { kEventMaxWaitTimeMs = 100 }; |
| 69 enum { kFrameRatePeriodMs = 1000 }; | 60 enum { kFrameRatePeriodMs = 1000 }; |
| 70 | 61 |
| 71 void DeliverFrame(const VideoFrame& video_frame); | 62 void DeliverFrame(const VideoFrame& video_frame); |
| 72 | 63 |
| 73 uint32_t const stream_id_; | |
| 74 const bool disable_prerenderer_smoothing_; | 64 const bool disable_prerenderer_smoothing_; |
| 75 // Critsects in allowed to enter order. | 65 // Critsects in allowed to enter order. |
| 76 rtc::CriticalSection stream_critsect_; | 66 rtc::CriticalSection stream_critsect_; |
| 77 rtc::CriticalSection thread_critsect_; | 67 rtc::CriticalSection thread_critsect_; |
| 78 rtc::CriticalSection buffer_critsect_; | 68 rtc::CriticalSection buffer_critsect_; |
| 79 // TODO(pbos): Make plain member and stop resetting this thread, just | 69 // TODO(pbos): Make plain member and stop resetting this thread, just |
| 80 // start/stoping it is enough. | 70 // start/stoping it is enough. |
| 81 std::unique_ptr<rtc::PlatformThread> incoming_render_thread_ | 71 std::unique_ptr<rtc::PlatformThread> incoming_render_thread_ |
| 82 GUARDED_BY(thread_critsect_); | 72 GUARDED_BY(thread_critsect_); |
| 83 std::unique_ptr<EventTimerWrapper> deliver_buffer_event_; | 73 std::unique_ptr<EventTimerWrapper> deliver_buffer_event_; |
| 84 | 74 |
| 85 bool running_ GUARDED_BY(stream_critsect_); | 75 bool running_ GUARDED_BY(stream_critsect_); |
| 86 VideoRenderCallback* external_callback_ GUARDED_BY(thread_critsect_); | 76 rtc::VideoSinkInterface<VideoFrame>* external_callback_ |
| 87 VideoRenderCallback* render_callback_ GUARDED_BY(thread_critsect_); | 77 GUARDED_BY(thread_critsect_); |
| 78 rtc::VideoSinkInterface<VideoFrame>* render_callback_ |
| 79 GUARDED_BY(thread_critsect_); |
| 88 const std::unique_ptr<VideoRenderFrames> render_buffers_ | 80 const std::unique_ptr<VideoRenderFrames> render_buffers_ |
| 89 GUARDED_BY(buffer_critsect_); | 81 GUARDED_BY(buffer_critsect_); |
| 90 | 82 |
| 91 uint32_t incoming_rate_ GUARDED_BY(stream_critsect_); | 83 uint32_t incoming_rate_ GUARDED_BY(stream_critsect_); |
| 92 int64_t last_rate_calculation_time_ms_ GUARDED_BY(stream_critsect_); | 84 int64_t last_rate_calculation_time_ms_ GUARDED_BY(stream_critsect_); |
| 93 uint16_t num_frames_since_last_calculation_ GUARDED_BY(stream_critsect_); | 85 uint16_t num_frames_since_last_calculation_ GUARDED_BY(stream_critsect_); |
| 94 }; | 86 }; |
| 95 | 87 |
| 96 } // namespace webrtc | 88 } // namespace webrtc |
| 97 | 89 |
| 98 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ | 90 #endif // WEBRTC_COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ |
| OLD | NEW |