niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
andrew@webrtc.org | 9841d92 | 2012-10-31 05:22:11 +0000 | [diff] [blame] | 14 | #include "webrtc/modules/video_render/include/video_render.h" |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 15 | #include "system_wrappers/interface/map_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | class CriticalSectionWrapper; |
| 19 | class EventWrapper; |
| 20 | class ThreadWrapper; |
| 21 | class VideoRenderCallback; |
| 22 | class VideoRenderFrames; |
| 23 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 24 | struct VideoMirroring { |
| 25 | VideoMirroring() : mirror_x_axis(false), mirror_y_axis(false) {} |
| 26 | bool mirror_x_axis; |
| 27 | bool mirror_y_axis; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 30 | class IncomingVideoStream : public VideoRenderCallback { |
| 31 | public: |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 32 | IncomingVideoStream(const int32_t module_id, |
| 33 | const uint32_t stream_id); |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 34 | ~IncomingVideoStream(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 36 | int32_t ChangeModuleId(const int32_t id); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 38 | // Get callback to deliver frames to the module. |
| 39 | VideoRenderCallback* ModuleCallback(); |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 40 | virtual int32_t RenderFrame(const uint32_t stream_id, |
| 41 | I420VideoFrame& video_frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 43 | // Set callback to the platform dependent code. |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 44 | int32_t SetRenderCallback(VideoRenderCallback* render_callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 46 | // Callback for file recording, snapshot, ... |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 47 | int32_t SetExternalCallback(VideoRenderCallback* render_object); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 49 | // Start/Stop. |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 50 | int32_t Start(); |
| 51 | int32_t Stop(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 53 | // Clear all buffers. |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 54 | int32_t Reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 56 | // Properties. |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 57 | uint32_t StreamId() const; |
| 58 | uint32_t IncomingRate() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 60 | int32_t GetLastRenderedFrame(I420VideoFrame& video_frame) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 62 | int32_t SetStartImage(const I420VideoFrame& video_frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 64 | int32_t SetTimeoutImage(const I420VideoFrame& video_frame, |
| 65 | const uint32_t timeout); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 67 | int32_t EnableMirroring(const bool enable, |
| 68 | const bool mirror_xaxis, |
| 69 | const bool mirror_yaxis); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 71 | int32_t SetExpectedRenderDelay(int32_t delay_ms); |
mflodman@webrtc.org | f4f2145 | 2012-09-28 11:27:35 +0000 | [diff] [blame] | 72 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 73 | protected: |
| 74 | static bool IncomingVideoStreamThreadFun(void* obj); |
| 75 | bool IncomingVideoStreamProcess(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 76 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 77 | private: |
| 78 | enum { KEventStartupTimeMS = 10 }; |
| 79 | enum { KEventMaxWaitTimeMs = 100 }; |
| 80 | enum { KFrameRatePeriodMs = 1000 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 82 | int32_t module_id_; |
| 83 | uint32_t stream_id_; |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 84 | // Critsects in allowed to enter order. |
| 85 | CriticalSectionWrapper& stream_critsect_; |
| 86 | CriticalSectionWrapper& thread_critsect_; |
| 87 | CriticalSectionWrapper& buffer_critsect_; |
| 88 | ThreadWrapper* incoming_render_thread_; |
| 89 | EventWrapper& deliver_buffer_event_; |
| 90 | bool running_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 92 | VideoRenderCallback* external_callback_; |
| 93 | VideoRenderCallback* render_callback_; |
| 94 | VideoRenderFrames& render_buffers_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 96 | RawVideoType callbackVideoType_; |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 97 | uint32_t callbackWidth_; |
| 98 | uint32_t callbackHeight_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 100 | uint32_t incoming_rate_; |
| 101 | int64_t last_rate_calculation_time_ms_; |
| 102 | uint16_t num_frames_since_last_calculation_; |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 103 | I420VideoFrame last_rendered_frame_; |
| 104 | I420VideoFrame temp_frame_; |
| 105 | I420VideoFrame start_image_; |
| 106 | I420VideoFrame timeout_image_; |
pbos@webrtc.org | ddf94e7 | 2013-04-10 08:09:04 +0000 | [diff] [blame] | 107 | uint32_t timeout_time_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 109 | bool mirror_frames_enabled_; |
| 110 | VideoMirroring mirroring_; |
mikhal@webrtc.org | 9fedff7 | 2012-10-24 18:33:04 +0000 | [diff] [blame] | 111 | I420VideoFrame transformed_video_frame_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
mflodman@webrtc.org | 327ada1 | 2012-05-30 10:45:18 +0000 | [diff] [blame] | 114 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
| 116 | #endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_INCOMING_VIDEO_STREAM_H_ |