blob: 3bd335532a4ba0de2437437fe2b5049851ebbbe6 [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"
pbos@webrtc.org575d1262014-10-08 14:48:08 +000040#include "webrtc/base/criticalsection.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000041#include "webrtc/base/scoped_ptr.h"
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000042#include "webrtc/base/thread_annotations.h"
pbos@webrtc.org42684be2014-10-03 11:25:45 +000043#include "webrtc/call.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000044#include "webrtc/common_video/interface/i420_video_frame.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000045#include "webrtc/transport.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000046#include "webrtc/video_receive_stream.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000047#include "webrtc/video_renderer.h"
48#include "webrtc/video_send_stream.h"
49
50namespace webrtc {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000051class VideoCaptureModule;
52class VideoDecoder;
53class VideoEncoder;
54class VideoRender;
55class VideoSendStreamInput;
56class VideoReceiveStream;
57}
58
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059namespace rtc {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000060class CpuMonitor;
61class Thread;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000062} // namespace rtc
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000063
64namespace cricket {
65
66class VideoCapturer;
67class VideoFrame;
68class VideoProcessor;
69class VideoRenderer;
70class VoiceMediaChannel;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000071class WebRtcDecoderObserver;
72class WebRtcEncoderObserver;
73class WebRtcLocalStreamInfo;
74class WebRtcRenderAdapter;
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +000075class WebRtcVideoChannel2;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000076class WebRtcVideoChannelRecvInfo;
77class WebRtcVideoChannelSendInfo;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000078class WebRtcVoiceEngine;
79
80struct CapturedFrame;
81struct Device;
82
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000083class 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
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000132// CallFactory, overridden for testing to verify that webrtc::Call is configured
133// properly.
134class WebRtcCallFactory {
135 public:
136 virtual ~WebRtcCallFactory();
137 virtual webrtc::Call* CreateCall(const webrtc::Call::Config& config);
138};
139
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000140// WebRtcVideoEngine2 is used for the new native WebRTC Video API (webrtc:1667).
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000141class WebRtcVideoEngine2 : public sigslot::has_slots<>,
142 public WebRtcVideoEncoderFactory::Observer {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000143 public:
144 // Creates the WebRtcVideoEngine2 with internal VideoCaptureModule.
145 WebRtcVideoEngine2();
pbos@webrtc.orgb648b9d2014-08-26 11:08:06 +0000146 virtual ~WebRtcVideoEngine2();
147
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000148 // Used for testing to be able to check and use the webrtc::Call config.
149 void SetCallFactory(WebRtcCallFactory* call_factory);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000150
151 // Basic video engine implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000152 bool Init(rtc::Thread* worker_thread);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000153 void Terminate();
154
155 int GetCapabilities();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000156 bool SetDefaultEncoderConfig(const VideoEncoderConfig& config);
157 VideoEncoderConfig GetDefaultEncoderConfig() const;
158
159 WebRtcVideoChannel2* CreateChannel(VoiceMediaChannel* voice_channel);
160
161 const std::vector<VideoCodec>& codecs() const;
162 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
163 void SetLogging(int min_sev, const char* filter);
164
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000165 // Set a WebRtcVideoDecoderFactory for external decoding. Video engine does
166 // not take the ownership of |decoder_factory|. The caller needs to make sure
167 // that |decoder_factory| outlives the video engine.
168 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory);
169 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does
170 // not take the ownership of |encoder_factory|. The caller needs to make sure
171 // that |encoder_factory| outlives the video engine.
172 virtual void SetExternalEncoderFactory(
173 WebRtcVideoEncoderFactory* encoder_factory);
174
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000175 bool EnableTimedRender();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000176 // This is currently ignored.
177 sigslot::repeater2<VideoCapturer*, CaptureState> SignalCaptureStateChange;
178
179 // Set the VoiceEngine for A/V sync. This can only be called before Init.
180 bool SetVoiceEngine(WebRtcVoiceEngine* voice_engine);
181
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000182 bool FindCodec(const VideoCodec& in);
183 bool CanSendCodec(const VideoCodec& in,
184 const VideoCodec& current,
185 VideoCodec* out);
186 // Check whether the supplied trace should be ignored.
187 bool ShouldIgnoreTrace(const std::string& trace);
188
buildbot@webrtc.org992febb2014-09-05 16:39:08 +0000189 VideoFormat GetStartCaptureFormat() const { return default_codec_format_; }
190
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000191 rtc::CpuMonitor* cpu_monitor() { return cpu_monitor_.get(); }
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000192
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000193 virtual WebRtcVideoEncoderFactory2* GetVideoEncoderFactory();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000194
195 private:
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000196 virtual void OnCodecsAvailable() OVERRIDE;
197
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000198 rtc::Thread* worker_thread_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000199 WebRtcVoiceEngine* voice_engine_;
200 std::vector<VideoCodec> video_codecs_;
201 std::vector<RtpHeaderExtension> rtp_header_extensions_;
buildbot@webrtc.org992febb2014-09-05 16:39:08 +0000202 VideoFormat default_codec_format_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000203
204 bool initialized_;
205
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000206 rtc::scoped_ptr<rtc::CpuMonitor> cpu_monitor_;
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000207 WebRtcVideoEncoderFactory2 default_video_encoder_factory_;
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000208
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000209 WebRtcCallFactory default_call_factory_;
210 WebRtcCallFactory* call_factory_;
211
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000212 WebRtcVideoDecoderFactory* external_decoder_factory_;
213 WebRtcVideoEncoderFactory* external_encoder_factory_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000214};
215
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000216class WebRtcVideoChannel2 : public rtc::MessageHandler,
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000217 public VideoMediaChannel,
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000218 public webrtc::newapi::Transport,
219 public webrtc::LoadObserver {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000220 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000221 WebRtcVideoChannel2(WebRtcCallFactory* call_factory,
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000222 VoiceMediaChannel* voice_channel,
223 WebRtcVideoEncoderFactory2* encoder_factory);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000224 ~WebRtcVideoChannel2();
225 bool Init();
226
227 // VideoMediaChannel implementation
228 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE;
229 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE;
230 virtual bool GetSendCodec(VideoCodec* send_codec) OVERRIDE;
231 virtual bool SetSendStreamFormat(uint32 ssrc,
232 const VideoFormat& format) OVERRIDE;
233 virtual bool SetRender(bool render) OVERRIDE;
234 virtual bool SetSend(bool send) OVERRIDE;
235
236 virtual bool AddSendStream(const StreamParams& sp) OVERRIDE;
237 virtual bool RemoveSendStream(uint32 ssrc) OVERRIDE;
238 virtual bool AddRecvStream(const StreamParams& sp) OVERRIDE;
239 virtual bool RemoveRecvStream(uint32 ssrc) OVERRIDE;
240 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) OVERRIDE;
241 virtual bool GetStats(const StatsOptions& options,
242 VideoMediaInfo* info) OVERRIDE;
243 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) OVERRIDE;
244 virtual bool SendIntraFrame() OVERRIDE;
245 virtual bool RequestIntraFrame() OVERRIDE;
246
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000247 virtual void OnPacketReceived(rtc::Buffer* packet,
248 const rtc::PacketTime& packet_time)
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000249 OVERRIDE;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000250 virtual void OnRtcpReceived(rtc::Buffer* packet,
251 const rtc::PacketTime& packet_time)
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000252 OVERRIDE;
253 virtual void OnReadyToSend(bool ready) OVERRIDE;
254 virtual bool MuteStream(uint32 ssrc, bool mute) OVERRIDE;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000255
256 // Set send/receive RTP header extensions. This must be done before creating
257 // streams as it only has effect on future streams.
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000258 virtual bool SetRecvRtpHeaderExtensions(
259 const std::vector<RtpHeaderExtension>& extensions) OVERRIDE;
260 virtual bool SetSendRtpHeaderExtensions(
261 const std::vector<RtpHeaderExtension>& extensions) OVERRIDE;
262 virtual bool SetStartSendBandwidth(int bps) OVERRIDE;
263 virtual bool SetMaxSendBandwidth(int bps) OVERRIDE;
264 virtual bool SetOptions(const VideoOptions& options) OVERRIDE;
265 virtual bool GetOptions(VideoOptions* options) const OVERRIDE {
266 *options = options_;
267 return true;
268 }
269 virtual void SetInterface(NetworkInterface* iface) OVERRIDE;
270 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) OVERRIDE;
271
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000272 virtual void OnMessage(rtc::Message* msg) OVERRIDE;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000273
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000274 virtual void OnLoadUpdate(Load load) OVERRIDE;
275
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000276 // Implemented for VideoMediaChannelTest.
277 bool sending() const { return sending_; }
buildbot@webrtc.org2c0fb052014-08-13 16:47:12 +0000278 uint32 GetDefaultSendChannelSsrc() { return default_send_ssrc_; }
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000279 bool GetRenderer(uint32 ssrc, VideoRenderer** renderer);
280
281 private:
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000282 void ConfigureReceiverRtp(webrtc::VideoReceiveStream::Config* config,
283 const StreamParams& sp) const;
284
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000285 struct VideoCodecSettings {
286 VideoCodecSettings();
287
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000288 VideoCodec codec;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000289 webrtc::FecConfig fec;
290 int rtx_payload_type;
291 };
292
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000293 // Wrapper for the sender part, this is where the capturer is connected and
294 // frames are then converted from cricket frames to webrtc frames.
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000295 class WebRtcVideoSendStream : public sigslot::has_slots<> {
296 public:
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000297 WebRtcVideoSendStream(
298 webrtc::Call* call,
299 WebRtcVideoEncoderFactory2* encoder_factory,
300 const VideoOptions& options,
301 const Settable<VideoCodecSettings>& codec_settings,
302 const StreamParams& sp,
303 const std::vector<webrtc::RtpExtension>& rtp_extensions);
304
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000305 ~WebRtcVideoSendStream();
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000306 void SetOptions(const VideoOptions& options);
307 void SetCodec(const VideoCodecSettings& codec);
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000308 void SetRtpExtensions(
309 const std::vector<webrtc::RtpExtension>& rtp_extensions);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000310
311 void InputFrame(VideoCapturer* capturer, const VideoFrame* frame);
312 bool SetCapturer(VideoCapturer* capturer);
313 bool SetVideoFormat(const VideoFormat& format);
pbos@webrtc.orgef8bb8d2014-08-13 21:36:18 +0000314 void MuteStream(bool mute);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000315 bool DisconnectCapturer();
316
317 void Start();
318 void Stop();
319
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000320 VideoSenderInfo GetVideoSenderInfo();
321
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000322 void OnCpuResolutionRequest(
323 CoordinatedVideoAdapter::AdaptRequest adapt_request);
324
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000325 private:
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000326 // Parameters needed to reconstruct the underlying stream.
327 // webrtc::VideoSendStream doesn't support setting a lot of options on the
328 // fly, so when those need to be changed we tear down and reconstruct with
329 // similar parameters depending on which options changed etc.
330 struct VideoSendStreamParameters {
331 VideoSendStreamParameters(
332 const webrtc::VideoSendStream::Config& config,
333 const VideoOptions& options,
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000334 const Settable<VideoCodecSettings>& codec_settings);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000335 webrtc::VideoSendStream::Config config;
336 VideoOptions options;
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000337 Settable<VideoCodecSettings> codec_settings;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000338 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
339 // typically changes when setting a new resolution or reconfiguring
340 // bitrates.
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000341 webrtc::VideoEncoderConfig encoder_config;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000342 };
343
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000344 void SetCodecAndOptions(const VideoCodecSettings& codec,
pbos@webrtc.orgd60d79a2014-09-24 07:10:57 +0000345 const VideoOptions& options)
346 EXCLUSIVE_LOCKS_REQUIRED(lock_);
347 void RecreateWebRtcStream() EXCLUSIVE_LOCKS_REQUIRED(lock_);
pbos@webrtc.orgc4175b92014-09-03 15:25:49 +0000348 // When |override_max| is false constrain width/height to codec dimensions.
pbos@webrtc.orgd60d79a2014-09-24 07:10:57 +0000349 void SetDimensions(int width, int height, bool override_max)
350 EXCLUSIVE_LOCKS_REQUIRED(lock_);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000351
352 webrtc::Call* const call_;
353 WebRtcVideoEncoderFactory2* const encoder_factory_;
354
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000355 rtc::CriticalSection lock_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000356 webrtc::VideoSendStream* stream_ GUARDED_BY(lock_);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000357 VideoSendStreamParameters parameters_ GUARDED_BY(lock_);
358
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000359 VideoCapturer* capturer_ GUARDED_BY(lock_);
360 bool sending_ GUARDED_BY(lock_);
361 bool muted_ GUARDED_BY(lock_);
362 VideoFormat format_ GUARDED_BY(lock_);
363
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000364 rtc::CriticalSection frame_lock_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000365 webrtc::I420VideoFrame video_frame_ GUARDED_BY(frame_lock_);
366 };
367
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000368 // Wrapper for the receiver part, contains configs etc. that are needed to
369 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper
370 // between webrtc::VideoRenderer and cricket::VideoRenderer.
371 class WebRtcVideoReceiveStream : public webrtc::VideoRenderer {
372 public:
373 WebRtcVideoReceiveStream(
374 webrtc::Call*,
375 const webrtc::VideoReceiveStream::Config& config,
376 const std::vector<VideoCodecSettings>& recv_codecs);
377 ~WebRtcVideoReceiveStream();
378
379 void SetRecvCodecs(const std::vector<VideoCodecSettings>& recv_codecs);
380 void SetRtpExtensions(const std::vector<webrtc::RtpExtension>& extensions);
381
382 virtual void RenderFrame(const webrtc::I420VideoFrame& frame,
383 int time_to_render_ms) OVERRIDE;
384
385 void SetRenderer(cricket::VideoRenderer* renderer);
386 cricket::VideoRenderer* GetRenderer();
387
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000388 VideoReceiverInfo GetVideoReceiverInfo();
389
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000390 private:
391 void SetSize(int width, int height);
392 void RecreateWebRtcStream();
393
394 webrtc::Call* const call_;
395
396 webrtc::VideoReceiveStream* stream_;
397 webrtc::VideoReceiveStream::Config config_;
398
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000399 rtc::CriticalSection renderer_lock_;
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000400 cricket::VideoRenderer* renderer_ GUARDED_BY(renderer_lock_);
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000401 int last_width_ GUARDED_BY(renderer_lock_);
402 int last_height_ GUARDED_BY(renderer_lock_);
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000403 };
404
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000405 void Construct(webrtc::Call* call, WebRtcVideoEngine2* engine);
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +0000406 void SetDefaultOptions();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000407
408 virtual bool SendRtp(const uint8_t* data, size_t len) OVERRIDE;
409 virtual bool SendRtcp(const uint8_t* data, size_t len) OVERRIDE;
410
411 void StartAllSendStreams();
412 void StopAllSendStreams();
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000413
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000414 static std::vector<VideoCodecSettings> MapCodecs(
415 const std::vector<VideoCodec>& codecs);
416 std::vector<VideoCodecSettings> FilterSupportedCodecs(
417 const std::vector<VideoCodecSettings>& mapped_codecs);
418
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000419 void FillSenderStats(VideoMediaInfo* info);
420 void FillReceiverStats(VideoMediaInfo* info);
421 void FillBandwidthEstimationStats(VideoMediaInfo* info);
422
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000423 uint32_t rtcp_receiver_report_ssrc_;
424 bool sending_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000425 rtc::scoped_ptr<webrtc::Call> call_;
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000426 WebRtcCallFactory* call_factory_;
427
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000428 uint32_t default_send_ssrc_;
pbos@webrtc.orgafb554f42014-08-12 23:17:13 +0000429
430 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_;
431 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000432
pbos@webrtc.org575d1262014-10-08 14:48:08 +0000433 rtc::CriticalSection stream_crit_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000434 // Using primary-ssrc (first ssrc) as key.
pbos@webrtc.org575d1262014-10-08 14:48:08 +0000435 std::map<uint32, WebRtcVideoSendStream*> send_streams_
436 GUARDED_BY(stream_crit_);
437 std::map<uint32, WebRtcVideoReceiveStream*> receive_streams_
438 GUARDED_BY(stream_crit_);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000439
440 Settable<VideoCodecSettings> send_codec_;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000441 std::vector<webrtc::RtpExtension> send_rtp_extensions_;
442
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000443 WebRtcVideoEncoderFactory2* const encoder_factory_;
444 std::vector<VideoCodecSettings> recv_codecs_;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000445 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000446 VideoOptions options_;
447};
448
449} // namespace cricket
450
451#endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_