blob: 87fe2de9d2ec86e192f831d216ddfe36a0174174 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.org327ada12012-05-30 10:45:18 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.org9841d922012-10-31 05:22:11 +000014#include "webrtc/modules/video_render/include/video_render.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000015
16namespace webrtc {
17class CriticalSectionWrapper;
18class EventWrapper;
19class ThreadWrapper;
20class VideoRenderCallback;
21class VideoRenderFrames;
22
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000023struct VideoMirroring {
24 VideoMirroring() : mirror_x_axis(false), mirror_y_axis(false) {}
25 bool mirror_x_axis;
26 bool mirror_y_axis;
niklase@google.com470e71d2011-07-07 08:21:25 +000027};
28
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000029class IncomingVideoStream : public VideoRenderCallback {
30 public:
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000031 IncomingVideoStream(const int32_t module_id,
32 const uint32_t stream_id);
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000033 ~IncomingVideoStream();
niklase@google.com470e71d2011-07-07 08:21:25 +000034
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000035 int32_t ChangeModuleId(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000036
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000037 // Get callback to deliver frames to the module.
38 VideoRenderCallback* ModuleCallback();
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000039 virtual int32_t RenderFrame(const uint32_t stream_id,
40 I420VideoFrame& video_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000041
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000042 // Set callback to the platform dependent code.
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000043 int32_t SetRenderCallback(VideoRenderCallback* render_callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000044
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000045 // Callback for file recording, snapshot, ...
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000046 int32_t SetExternalCallback(VideoRenderCallback* render_object);
niklase@google.com470e71d2011-07-07 08:21:25 +000047
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000048 // Start/Stop.
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000049 int32_t Start();
50 int32_t Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +000051
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000052 // Clear all buffers.
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000053 int32_t Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +000054
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000055 // Properties.
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000056 uint32_t StreamId() const;
57 uint32_t IncomingRate() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000059 int32_t GetLastRenderedFrame(I420VideoFrame& video_frame) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000060
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000061 int32_t SetStartImage(const I420VideoFrame& video_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000062
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000063 int32_t SetTimeoutImage(const I420VideoFrame& video_frame,
64 const uint32_t timeout);
niklase@google.com470e71d2011-07-07 08:21:25 +000065
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000066 int32_t EnableMirroring(const bool enable,
67 const bool mirror_xaxis,
68 const bool mirror_yaxis);
niklase@google.com470e71d2011-07-07 08:21:25 +000069
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000070 int32_t SetExpectedRenderDelay(int32_t delay_ms);
mflodman@webrtc.orgf4f21452012-09-28 11:27:35 +000071
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000072 protected:
73 static bool IncomingVideoStreamThreadFun(void* obj);
74 bool IncomingVideoStreamProcess();
niklase@google.com470e71d2011-07-07 08:21:25 +000075
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000076 private:
77 enum { KEventStartupTimeMS = 10 };
78 enum { KEventMaxWaitTimeMs = 100 };
79 enum { KFrameRatePeriodMs = 1000 };
niklase@google.com470e71d2011-07-07 08:21:25 +000080
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000081 int32_t module_id_;
82 uint32_t stream_id_;
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000083 // 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_;
niklase@google.com470e71d2011-07-07 08:21:25 +000090
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000091 VideoRenderCallback* external_callback_;
92 VideoRenderCallback* render_callback_;
93 VideoRenderFrames& render_buffers_;
niklase@google.com470e71d2011-07-07 08:21:25 +000094
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000095 RawVideoType callbackVideoType_;
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000096 uint32_t callbackWidth_;
97 uint32_t callbackHeight_;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000099 uint32_t incoming_rate_;
100 int64_t last_rate_calculation_time_ms_;
101 uint16_t num_frames_since_last_calculation_;
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000102 I420VideoFrame last_rendered_frame_;
103 I420VideoFrame temp_frame_;
104 I420VideoFrame start_image_;
105 I420VideoFrame timeout_image_;
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +0000106 uint32_t timeout_time_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
mflodman@webrtc.org327ada12012-05-30 10:45:18 +0000108 bool mirror_frames_enabled_;
109 VideoMirroring mirroring_;
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000110 I420VideoFrame transformed_video_frame_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111};
112
mflodman@webrtc.org327ada12012-05-30 10:45:18 +0000113} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000114
115#endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_INCOMING_VIDEO_STREAM_H_