blob: 18a80d7ad7f131bf06d8d6161fc5ed5a1feaa65a [file] [log] [blame]
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +00001/*
2 * libjingle
3 * Copyright 2014 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_
29#define TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_
30
31#include <map>
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000032#include <string>
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000033#include <vector>
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000034
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000035#include "talk/media/base/mediaengine.h"
36#include "talk/media/webrtc/webrtcvideochannelfactory.h"
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +000037#include "talk/media/webrtc/webrtcvideodecoderfactory.h"
38#include "talk/media/webrtc/webrtcvideoencoderfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "webrtc/base/cpumonitor.h"
40#include "webrtc/base/scoped_ptr.h"
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000041#include "webrtc/base/thread_annotations.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000042#include "webrtc/common_video/interface/i420_video_frame.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000043#include "webrtc/transport.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000044#include "webrtc/video_receive_stream.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000045#include "webrtc/video_renderer.h"
46#include "webrtc/video_send_stream.h"
47
48namespace webrtc {
49class Call;
50class VideoCaptureModule;
51class VideoDecoder;
52class VideoEncoder;
53class VideoRender;
54class VideoSendStreamInput;
55class VideoReceiveStream;
56}
57
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000058namespace rtc {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000059class CpuMonitor;
60class Thread;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000061} // namespace rtc
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000062
63namespace cricket {
64
65class VideoCapturer;
66class VideoFrame;
67class VideoProcessor;
68class VideoRenderer;
69class VoiceMediaChannel;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000070class WebRtcDecoderObserver;
71class WebRtcEncoderObserver;
72class WebRtcLocalStreamInfo;
73class WebRtcRenderAdapter;
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +000074class WebRtcVideoChannel2;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000075class WebRtcVideoChannelRecvInfo;
76class WebRtcVideoChannelSendInfo;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000077class WebRtcVoiceEngine;
78
79struct CapturedFrame;
80struct Device;
81
82class WebRtcVideoEngine2;
83class WebRtcVideoChannel2;
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +000084class WebRtcVideoRenderer;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000085
pbos@webrtc.orgafb554f42014-08-12 23:17:13 +000086class UnsignalledSsrcHandler {
87 public:
88 enum Action {
89 kDropPacket,
90 kDeliverPacket,
91 };
92 virtual Action OnUnsignalledSsrc(VideoMediaChannel* engine,
93 uint32_t ssrc) = 0;
94};
95
96// TODO(pbos): Remove, use external handlers only.
97class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler {
98 public:
99 DefaultUnsignalledSsrcHandler();
100 virtual Action OnUnsignalledSsrc(VideoMediaChannel* engine,
101 uint32_t ssrc) OVERRIDE;
102
103 VideoRenderer* GetDefaultRenderer() const;
104 void SetDefaultRenderer(VideoMediaChannel* channel, VideoRenderer* renderer);
105
106 private:
107 uint32_t default_recv_ssrc_;
108 VideoRenderer* default_renderer_;
109};
110
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000111class WebRtcVideoEncoderFactory2 {
112 public:
pbos@webrtc.org0d523ee2014-06-05 09:10:55 +0000113 virtual ~WebRtcVideoEncoderFactory2();
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000114 virtual std::vector<webrtc::VideoStream> CreateVideoStreams(
115 const VideoCodec& codec,
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000116 const VideoOptions& options,
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000117 size_t num_streams);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000118
119 virtual webrtc::VideoEncoder* CreateVideoEncoder(
120 const VideoCodec& codec,
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000121 const VideoOptions& options);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000122
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000123 virtual void* CreateVideoEncoderSettings(const VideoCodec& codec,
124 const VideoOptions& options);
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +0000125
126 virtual void DestroyVideoEncoderSettings(const VideoCodec& codec,
127 void* encoder_settings);
128
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000129 virtual bool SupportsCodec(const cricket::VideoCodec& codec);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000130};
131
132// WebRtcVideoEngine2 is used for the new native WebRTC Video API (webrtc:1667).
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000133class WebRtcVideoEngine2 : public sigslot::has_slots<>,
134 public WebRtcVideoEncoderFactory::Observer {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000135 public:
136 // Creates the WebRtcVideoEngine2 with internal VideoCaptureModule.
137 WebRtcVideoEngine2();
pbos@webrtc.orgb648b9d2014-08-26 11:08:06 +0000138 virtual ~WebRtcVideoEngine2();
139
140 // Use a custom WebRtcVideoChannelFactory (for testing purposes).
141 void SetChannelFactory(WebRtcVideoChannelFactory* channel_factory);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000142
143 // Basic video engine implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000144 bool Init(rtc::Thread* worker_thread);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000145 void Terminate();
146
147 int GetCapabilities();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000148 bool SetDefaultEncoderConfig(const VideoEncoderConfig& config);
149 VideoEncoderConfig GetDefaultEncoderConfig() const;
150
151 WebRtcVideoChannel2* CreateChannel(VoiceMediaChannel* voice_channel);
152
153 const std::vector<VideoCodec>& codecs() const;
154 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
155 void SetLogging(int min_sev, const char* filter);
156
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000157 // Set a WebRtcVideoDecoderFactory for external decoding. Video engine does
158 // not take the ownership of |decoder_factory|. The caller needs to make sure
159 // that |decoder_factory| outlives the video engine.
160 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory);
161 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does
162 // not take the ownership of |encoder_factory|. The caller needs to make sure
163 // that |encoder_factory| outlives the video engine.
164 virtual void SetExternalEncoderFactory(
165 WebRtcVideoEncoderFactory* encoder_factory);
166
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000167 bool EnableTimedRender();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000168 // This is currently ignored.
169 sigslot::repeater2<VideoCapturer*, CaptureState> SignalCaptureStateChange;
170
171 // Set the VoiceEngine for A/V sync. This can only be called before Init.
172 bool SetVoiceEngine(WebRtcVoiceEngine* voice_engine);
173
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000174 bool FindCodec(const VideoCodec& in);
175 bool CanSendCodec(const VideoCodec& in,
176 const VideoCodec& current,
177 VideoCodec* out);
178 // Check whether the supplied trace should be ignored.
179 bool ShouldIgnoreTrace(const std::string& trace);
180
buildbot@webrtc.org992febb2014-09-05 16:39:08 +0000181 VideoFormat GetStartCaptureFormat() const { return default_codec_format_; }
182
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000183 rtc::CpuMonitor* cpu_monitor() { return cpu_monitor_.get(); }
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000184
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000185 virtual WebRtcVideoEncoderFactory2* GetVideoEncoderFactory();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000186
187 private:
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000188 virtual void OnCodecsAvailable() OVERRIDE;
189
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000190 rtc::Thread* worker_thread_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000191 WebRtcVoiceEngine* voice_engine_;
192 std::vector<VideoCodec> video_codecs_;
193 std::vector<RtpHeaderExtension> rtp_header_extensions_;
buildbot@webrtc.org992febb2014-09-05 16:39:08 +0000194 VideoFormat default_codec_format_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000195
196 bool initialized_;
197
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000198 // Critical section to protect the media processor register/unregister
199 // while processing a frame
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000200 rtc::CriticalSection signal_media_critical_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000201
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000202 rtc::scoped_ptr<rtc::CpuMonitor> cpu_monitor_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000203 WebRtcVideoChannelFactory* channel_factory_;
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000204 WebRtcVideoEncoderFactory2 default_video_encoder_factory_;
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000205
206 WebRtcVideoDecoderFactory* external_decoder_factory_;
207 WebRtcVideoEncoderFactory* external_encoder_factory_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000208};
209
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000210class WebRtcVideoChannel2 : public rtc::MessageHandler,
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000211 public VideoMediaChannel,
212 public webrtc::newapi::Transport {
213 public:
214 WebRtcVideoChannel2(WebRtcVideoEngine2* engine,
215 VoiceMediaChannel* voice_channel,
216 WebRtcVideoEncoderFactory2* encoder_factory);
217 // For testing purposes insert a pre-constructed call to verify that
218 // WebRtcVideoChannel2 calls the correct corresponding methods.
219 WebRtcVideoChannel2(webrtc::Call* call,
220 WebRtcVideoEngine2* engine,
221 WebRtcVideoEncoderFactory2* encoder_factory);
222 ~WebRtcVideoChannel2();
223 bool Init();
224
225 // VideoMediaChannel implementation
226 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE;
227 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE;
228 virtual bool GetSendCodec(VideoCodec* send_codec) OVERRIDE;
229 virtual bool SetSendStreamFormat(uint32 ssrc,
230 const VideoFormat& format) OVERRIDE;
231 virtual bool SetRender(bool render) OVERRIDE;
232 virtual bool SetSend(bool send) OVERRIDE;
233
234 virtual bool AddSendStream(const StreamParams& sp) OVERRIDE;
235 virtual bool RemoveSendStream(uint32 ssrc) OVERRIDE;
236 virtual bool AddRecvStream(const StreamParams& sp) OVERRIDE;
237 virtual bool RemoveRecvStream(uint32 ssrc) OVERRIDE;
238 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) OVERRIDE;
239 virtual bool GetStats(const StatsOptions& options,
240 VideoMediaInfo* info) OVERRIDE;
241 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) OVERRIDE;
242 virtual bool SendIntraFrame() OVERRIDE;
243 virtual bool RequestIntraFrame() OVERRIDE;
244
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000245 virtual void OnPacketReceived(rtc::Buffer* packet,
246 const rtc::PacketTime& packet_time)
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000247 OVERRIDE;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000248 virtual void OnRtcpReceived(rtc::Buffer* packet,
249 const rtc::PacketTime& packet_time)
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000250 OVERRIDE;
251 virtual void OnReadyToSend(bool ready) OVERRIDE;
252 virtual bool MuteStream(uint32 ssrc, bool mute) OVERRIDE;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000253
254 // Set send/receive RTP header extensions. This must be done before creating
255 // streams as it only has effect on future streams.
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000256 virtual bool SetRecvRtpHeaderExtensions(
257 const std::vector<RtpHeaderExtension>& extensions) OVERRIDE;
258 virtual bool SetSendRtpHeaderExtensions(
259 const std::vector<RtpHeaderExtension>& extensions) OVERRIDE;
260 virtual bool SetStartSendBandwidth(int bps) OVERRIDE;
261 virtual bool SetMaxSendBandwidth(int bps) OVERRIDE;
262 virtual bool SetOptions(const VideoOptions& options) OVERRIDE;
263 virtual bool GetOptions(VideoOptions* options) const OVERRIDE {
264 *options = options_;
265 return true;
266 }
267 virtual void SetInterface(NetworkInterface* iface) OVERRIDE;
268 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) OVERRIDE;
269
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000270 virtual void OnMessage(rtc::Message* msg) OVERRIDE;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000271
272 // Implemented for VideoMediaChannelTest.
273 bool sending() const { return sending_; }
buildbot@webrtc.org2c0fb052014-08-13 16:47:12 +0000274 uint32 GetDefaultSendChannelSsrc() { return default_send_ssrc_; }
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000275 bool GetRenderer(uint32 ssrc, VideoRenderer** renderer);
276
277 private:
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000278 void ConfigureReceiverRtp(webrtc::VideoReceiveStream::Config* config,
279 const StreamParams& sp) const;
280
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000281 struct VideoCodecSettings {
282 VideoCodecSettings();
283
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000284 VideoCodec codec;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000285 webrtc::FecConfig fec;
286 int rtx_payload_type;
287 };
288
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000289 // Wrapper for the sender part, this is where the capturer is connected and
290 // frames are then converted from cricket frames to webrtc frames.
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000291 class WebRtcVideoSendStream : public sigslot::has_slots<> {
292 public:
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000293 WebRtcVideoSendStream(
294 webrtc::Call* call,
295 WebRtcVideoEncoderFactory2* encoder_factory,
296 const VideoOptions& options,
297 const Settable<VideoCodecSettings>& codec_settings,
298 const StreamParams& sp,
299 const std::vector<webrtc::RtpExtension>& rtp_extensions);
300
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000301 ~WebRtcVideoSendStream();
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000302 void SetOptions(const VideoOptions& options);
303 void SetCodec(const VideoCodecSettings& codec);
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000304 void SetRtpExtensions(
305 const std::vector<webrtc::RtpExtension>& rtp_extensions);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000306
307 void InputFrame(VideoCapturer* capturer, const VideoFrame* frame);
308 bool SetCapturer(VideoCapturer* capturer);
309 bool SetVideoFormat(const VideoFormat& format);
pbos@webrtc.orgef8bb8d2014-08-13 21:36:18 +0000310 void MuteStream(bool mute);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000311 bool DisconnectCapturer();
312
313 void Start();
314 void Stop();
315
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000316 VideoSenderInfo GetVideoSenderInfo();
317
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000318 private:
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000319 // Parameters needed to reconstruct the underlying stream.
320 // webrtc::VideoSendStream doesn't support setting a lot of options on the
321 // fly, so when those need to be changed we tear down and reconstruct with
322 // similar parameters depending on which options changed etc.
323 struct VideoSendStreamParameters {
324 VideoSendStreamParameters(
325 const webrtc::VideoSendStream::Config& config,
326 const VideoOptions& options,
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000327 const Settable<VideoCodecSettings>& codec_settings);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000328 webrtc::VideoSendStream::Config config;
329 VideoOptions options;
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000330 Settable<VideoCodecSettings> codec_settings;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000331 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
332 // typically changes when setting a new resolution or reconfiguring
333 // bitrates.
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000334 webrtc::VideoEncoderConfig encoder_config;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000335 };
336
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000337 void SetCodecAndOptions(const VideoCodecSettings& codec,
pbos@webrtc.orgd60d79a2014-09-24 07:10:57 +0000338 const VideoOptions& options)
339 EXCLUSIVE_LOCKS_REQUIRED(lock_);
340 void RecreateWebRtcStream() EXCLUSIVE_LOCKS_REQUIRED(lock_);
pbos@webrtc.orgc4175b92014-09-03 15:25:49 +0000341 // When |override_max| is false constrain width/height to codec dimensions.
pbos@webrtc.orgd60d79a2014-09-24 07:10:57 +0000342 void SetDimensions(int width, int height, bool override_max)
343 EXCLUSIVE_LOCKS_REQUIRED(lock_);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000344
345 webrtc::Call* const call_;
346 WebRtcVideoEncoderFactory2* const encoder_factory_;
347
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000348 rtc::CriticalSection lock_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000349 webrtc::VideoSendStream* stream_ GUARDED_BY(lock_);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000350 VideoSendStreamParameters parameters_ GUARDED_BY(lock_);
351
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000352 VideoCapturer* capturer_ GUARDED_BY(lock_);
353 bool sending_ GUARDED_BY(lock_);
354 bool muted_ GUARDED_BY(lock_);
355 VideoFormat format_ GUARDED_BY(lock_);
356
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000357 rtc::CriticalSection frame_lock_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000358 webrtc::I420VideoFrame video_frame_ GUARDED_BY(frame_lock_);
359 };
360
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000361 // Wrapper for the receiver part, contains configs etc. that are needed to
362 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper
363 // between webrtc::VideoRenderer and cricket::VideoRenderer.
364 class WebRtcVideoReceiveStream : public webrtc::VideoRenderer {
365 public:
366 WebRtcVideoReceiveStream(
367 webrtc::Call*,
368 const webrtc::VideoReceiveStream::Config& config,
369 const std::vector<VideoCodecSettings>& recv_codecs);
370 ~WebRtcVideoReceiveStream();
371
372 void SetRecvCodecs(const std::vector<VideoCodecSettings>& recv_codecs);
373 void SetRtpExtensions(const std::vector<webrtc::RtpExtension>& extensions);
374
375 virtual void RenderFrame(const webrtc::I420VideoFrame& frame,
376 int time_to_render_ms) OVERRIDE;
377
378 void SetRenderer(cricket::VideoRenderer* renderer);
379 cricket::VideoRenderer* GetRenderer();
380
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000381 VideoReceiverInfo GetVideoReceiverInfo();
382
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000383 private:
384 void SetSize(int width, int height);
385 void RecreateWebRtcStream();
386
387 webrtc::Call* const call_;
388
389 webrtc::VideoReceiveStream* stream_;
390 webrtc::VideoReceiveStream::Config config_;
391
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000392 rtc::CriticalSection renderer_lock_;
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000393 cricket::VideoRenderer* renderer_ GUARDED_BY(renderer_lock_);
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000394 int last_width_ GUARDED_BY(renderer_lock_);
395 int last_height_ GUARDED_BY(renderer_lock_);
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000396 };
397
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000398 void Construct(webrtc::Call* call, WebRtcVideoEngine2* engine);
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +0000399 void SetDefaultOptions();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000400
401 virtual bool SendRtp(const uint8_t* data, size_t len) OVERRIDE;
402 virtual bool SendRtcp(const uint8_t* data, size_t len) OVERRIDE;
403
404 void StartAllSendStreams();
405 void StopAllSendStreams();
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000406
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000407 static std::vector<VideoCodecSettings> MapCodecs(
408 const std::vector<VideoCodec>& codecs);
409 std::vector<VideoCodecSettings> FilterSupportedCodecs(
410 const std::vector<VideoCodecSettings>& mapped_codecs);
411
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000412 void FillSenderStats(VideoMediaInfo* info);
413 void FillReceiverStats(VideoMediaInfo* info);
414 void FillBandwidthEstimationStats(VideoMediaInfo* info);
415
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000416 uint32_t rtcp_receiver_report_ssrc_;
417 bool sending_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000418 rtc::scoped_ptr<webrtc::Call> call_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000419 uint32_t default_send_ssrc_;
pbos@webrtc.orgafb554f42014-08-12 23:17:13 +0000420
421 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_;
422 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000423
424 // Using primary-ssrc (first ssrc) as key.
425 std::map<uint32, WebRtcVideoSendStream*> send_streams_;
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000426 std::map<uint32, WebRtcVideoReceiveStream*> receive_streams_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000427
428 Settable<VideoCodecSettings> send_codec_;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000429 std::vector<webrtc::RtpExtension> send_rtp_extensions_;
430
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000431 WebRtcVideoEncoderFactory2* const encoder_factory_;
432 std::vector<VideoCodecSettings> recv_codecs_;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000433 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000434 VideoOptions options_;
435};
436
437} // namespace cricket
438
439#endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_