blob: 6a6343208473380c6ba28b3c3d773f30db7324b5 [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"
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000015#include "system_wrappers/interface/map_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17namespace webrtc {
18class CriticalSectionWrapper;
19class EventWrapper;
20class ThreadWrapper;
21class VideoRenderCallback;
22class VideoRenderFrames;
23
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000024struct VideoMirroring {
25 VideoMirroring() : mirror_x_axis(false), mirror_y_axis(false) {}
26 bool mirror_x_axis;
27 bool mirror_y_axis;
niklase@google.com470e71d2011-07-07 08:21:25 +000028};
29
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000030class IncomingVideoStream : public VideoRenderCallback {
31 public:
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000032 IncomingVideoStream(const int32_t module_id,
33 const uint32_t stream_id);
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000034 ~IncomingVideoStream();
niklase@google.com470e71d2011-07-07 08:21:25 +000035
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000036 int32_t ChangeModuleId(const int32_t id);
niklase@google.com470e71d2011-07-07 08:21:25 +000037
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000038 // Get callback to deliver frames to the module.
39 VideoRenderCallback* ModuleCallback();
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000040 virtual int32_t RenderFrame(const uint32_t stream_id,
41 I420VideoFrame& video_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000042
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000043 // Set callback to the platform dependent code.
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000044 int32_t SetRenderCallback(VideoRenderCallback* render_callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000045
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000046 // Callback for file recording, snapshot, ...
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000047 int32_t SetExternalCallback(VideoRenderCallback* render_object);
niklase@google.com470e71d2011-07-07 08:21:25 +000048
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000049 // Start/Stop.
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000050 int32_t Start();
51 int32_t Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +000052
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000053 // Clear all buffers.
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000054 int32_t Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +000055
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000056 // Properties.
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000057 uint32_t StreamId() const;
58 uint32_t IncomingRate() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000060 int32_t GetLastRenderedFrame(I420VideoFrame& video_frame) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000062 int32_t SetStartImage(const I420VideoFrame& video_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +000063
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000064 int32_t SetTimeoutImage(const I420VideoFrame& video_frame,
65 const uint32_t timeout);
niklase@google.com470e71d2011-07-07 08:21:25 +000066
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000067 int32_t EnableMirroring(const bool enable,
68 const bool mirror_xaxis,
69 const bool mirror_yaxis);
niklase@google.com470e71d2011-07-07 08:21:25 +000070
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000071 int32_t SetExpectedRenderDelay(int32_t delay_ms);
mflodman@webrtc.orgf4f21452012-09-28 11:27:35 +000072
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000073 protected:
74 static bool IncomingVideoStreamThreadFun(void* obj);
75 bool IncomingVideoStreamProcess();
niklase@google.com470e71d2011-07-07 08:21:25 +000076
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000077 private:
78 enum { KEventStartupTimeMS = 10 };
79 enum { KEventMaxWaitTimeMs = 100 };
80 enum { KFrameRatePeriodMs = 1000 };
niklase@google.com470e71d2011-07-07 08:21:25 +000081
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000082 int32_t module_id_;
83 uint32_t stream_id_;
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000084 // 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.com470e71d2011-07-07 08:21:25 +000091
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000092 VideoRenderCallback* external_callback_;
93 VideoRenderCallback* render_callback_;
94 VideoRenderFrames& render_buffers_;
niklase@google.com470e71d2011-07-07 08:21:25 +000095
mflodman@webrtc.org327ada12012-05-30 10:45:18 +000096 RawVideoType callbackVideoType_;
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +000097 uint32_t callbackWidth_;
98 uint32_t callbackHeight_;
niklase@google.com470e71d2011-07-07 08:21:25 +000099
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +0000100 uint32_t incoming_rate_;
101 int64_t last_rate_calculation_time_ms_;
102 uint16_t num_frames_since_last_calculation_;
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000103 I420VideoFrame last_rendered_frame_;
104 I420VideoFrame temp_frame_;
105 I420VideoFrame start_image_;
106 I420VideoFrame timeout_image_;
pbos@webrtc.orgddf94e72013-04-10 08:09:04 +0000107 uint32_t timeout_time_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108
mflodman@webrtc.org327ada12012-05-30 10:45:18 +0000109 bool mirror_frames_enabled_;
110 VideoMirroring mirroring_;
mikhal@webrtc.org9fedff72012-10-24 18:33:04 +0000111 I420VideoFrame transformed_video_frame_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112};
113
mflodman@webrtc.org327ada12012-05-30 10:45:18 +0000114} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000115
116#endif // WEBRTC_MODULES_VIDEO_RENDER_MAIN_SOURCE_INCOMING_VIDEO_STREAM_H_