blob: 1c50fbf541cb7567cadf1a617982e98a354fb985 [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.org42684be2014-10-03 11:25:45 +000042#include "webrtc/call.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000043#include "webrtc/common_video/interface/i420_video_frame.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000044#include "webrtc/transport.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000045#include "webrtc/video_receive_stream.h"
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000046#include "webrtc/video_renderer.h"
47#include "webrtc/video_send_stream.h"
48
49namespace webrtc {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000050class 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
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000082class WebRtcVideoChannel2;
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +000083class WebRtcVideoRenderer;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +000084
pbos@webrtc.orgafb554f42014-08-12 23:17:13 +000085class UnsignalledSsrcHandler {
86 public:
87 enum Action {
88 kDropPacket,
89 kDeliverPacket,
90 };
91 virtual Action OnUnsignalledSsrc(VideoMediaChannel* engine,
92 uint32_t ssrc) = 0;
93};
94
95// TODO(pbos): Remove, use external handlers only.
96class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler {
97 public:
98 DefaultUnsignalledSsrcHandler();
99 virtual Action OnUnsignalledSsrc(VideoMediaChannel* engine,
100 uint32_t ssrc) OVERRIDE;
101
102 VideoRenderer* GetDefaultRenderer() const;
103 void SetDefaultRenderer(VideoMediaChannel* channel, VideoRenderer* renderer);
104
105 private:
106 uint32_t default_recv_ssrc_;
107 VideoRenderer* default_renderer_;
108};
109
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000110class WebRtcVideoEncoderFactory2 {
111 public:
pbos@webrtc.org0d523ee2014-06-05 09:10:55 +0000112 virtual ~WebRtcVideoEncoderFactory2();
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000113 virtual std::vector<webrtc::VideoStream> CreateVideoStreams(
114 const VideoCodec& codec,
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000115 const VideoOptions& options,
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000116 size_t num_streams);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000117
118 virtual webrtc::VideoEncoder* CreateVideoEncoder(
119 const VideoCodec& codec,
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000120 const VideoOptions& options);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000121
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000122 virtual void* CreateVideoEncoderSettings(const VideoCodec& codec,
123 const VideoOptions& options);
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +0000124
125 virtual void DestroyVideoEncoderSettings(const VideoCodec& codec,
126 void* encoder_settings);
127
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000128 virtual bool SupportsCodec(const cricket::VideoCodec& codec);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000129};
130
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000131// CallFactory, overridden for testing to verify that webrtc::Call is configured
132// properly.
133class WebRtcCallFactory {
134 public:
135 virtual ~WebRtcCallFactory();
136 virtual webrtc::Call* CreateCall(const webrtc::Call::Config& config);
137};
138
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000139// WebRtcVideoEngine2 is used for the new native WebRTC Video API (webrtc:1667).
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000140class WebRtcVideoEngine2 : public sigslot::has_slots<>,
141 public WebRtcVideoEncoderFactory::Observer {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000142 public:
143 // Creates the WebRtcVideoEngine2 with internal VideoCaptureModule.
144 WebRtcVideoEngine2();
pbos@webrtc.orgb648b9d2014-08-26 11:08:06 +0000145 virtual ~WebRtcVideoEngine2();
146
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000147 // Used for testing to be able to check and use the webrtc::Call config.
148 void SetCallFactory(WebRtcCallFactory* call_factory);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000149
150 // Basic video engine implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000151 bool Init(rtc::Thread* worker_thread);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000152 void Terminate();
153
154 int GetCapabilities();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000155 bool SetDefaultEncoderConfig(const VideoEncoderConfig& config);
156 VideoEncoderConfig GetDefaultEncoderConfig() const;
157
158 WebRtcVideoChannel2* CreateChannel(VoiceMediaChannel* voice_channel);
159
160 const std::vector<VideoCodec>& codecs() const;
161 const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
162 void SetLogging(int min_sev, const char* filter);
163
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000164 // Set a WebRtcVideoDecoderFactory for external decoding. Video engine does
165 // not take the ownership of |decoder_factory|. The caller needs to make sure
166 // that |decoder_factory| outlives the video engine.
167 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory);
168 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does
169 // not take the ownership of |encoder_factory|. The caller needs to make sure
170 // that |encoder_factory| outlives the video engine.
171 virtual void SetExternalEncoderFactory(
172 WebRtcVideoEncoderFactory* encoder_factory);
173
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000174 bool EnableTimedRender();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000175 // This is currently ignored.
176 sigslot::repeater2<VideoCapturer*, CaptureState> SignalCaptureStateChange;
177
178 // Set the VoiceEngine for A/V sync. This can only be called before Init.
179 bool SetVoiceEngine(WebRtcVoiceEngine* voice_engine);
180
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000181 bool FindCodec(const VideoCodec& in);
182 bool CanSendCodec(const VideoCodec& in,
183 const VideoCodec& current,
184 VideoCodec* out);
185 // Check whether the supplied trace should be ignored.
186 bool ShouldIgnoreTrace(const std::string& trace);
187
buildbot@webrtc.org992febb2014-09-05 16:39:08 +0000188 VideoFormat GetStartCaptureFormat() const { return default_codec_format_; }
189
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000190 rtc::CpuMonitor* cpu_monitor() { return cpu_monitor_.get(); }
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000191
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000192 virtual WebRtcVideoEncoderFactory2* GetVideoEncoderFactory();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000193
194 private:
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000195 virtual void OnCodecsAvailable() OVERRIDE;
196
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000197 rtc::Thread* worker_thread_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000198 WebRtcVoiceEngine* voice_engine_;
199 std::vector<VideoCodec> video_codecs_;
200 std::vector<RtpHeaderExtension> rtp_header_extensions_;
buildbot@webrtc.org992febb2014-09-05 16:39:08 +0000201 VideoFormat default_codec_format_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000202
203 bool initialized_;
204
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000205 rtc::scoped_ptr<rtc::CpuMonitor> cpu_monitor_;
buildbot@webrtc.orgd41eaeb2014-06-12 07:13:26 +0000206 WebRtcVideoEncoderFactory2 default_video_encoder_factory_;
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000207
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000208 WebRtcCallFactory default_call_factory_;
209 WebRtcCallFactory* call_factory_;
210
pbos@webrtc.org0a2087a2014-09-23 09:40:22 +0000211 WebRtcVideoDecoderFactory* external_decoder_factory_;
212 WebRtcVideoEncoderFactory* external_encoder_factory_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000213};
214
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000215class WebRtcVideoChannel2 : public rtc::MessageHandler,
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000216 public VideoMediaChannel,
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000217 public webrtc::newapi::Transport,
218 public webrtc::LoadObserver {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000219 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000220 WebRtcVideoChannel2(WebRtcCallFactory* call_factory,
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000221 VoiceMediaChannel* voice_channel,
222 WebRtcVideoEncoderFactory2* encoder_factory);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000223 ~WebRtcVideoChannel2();
224 bool Init();
225
226 // VideoMediaChannel implementation
227 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE;
228 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE;
229 virtual bool GetSendCodec(VideoCodec* send_codec) OVERRIDE;
230 virtual bool SetSendStreamFormat(uint32 ssrc,
231 const VideoFormat& format) OVERRIDE;
232 virtual bool SetRender(bool render) OVERRIDE;
233 virtual bool SetSend(bool send) OVERRIDE;
234
235 virtual bool AddSendStream(const StreamParams& sp) OVERRIDE;
236 virtual bool RemoveSendStream(uint32 ssrc) OVERRIDE;
237 virtual bool AddRecvStream(const StreamParams& sp) OVERRIDE;
238 virtual bool RemoveRecvStream(uint32 ssrc) OVERRIDE;
239 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) OVERRIDE;
240 virtual bool GetStats(const StatsOptions& options,
241 VideoMediaInfo* info) OVERRIDE;
242 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) OVERRIDE;
243 virtual bool SendIntraFrame() OVERRIDE;
244 virtual bool RequestIntraFrame() OVERRIDE;
245
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000246 virtual void OnPacketReceived(rtc::Buffer* packet,
247 const rtc::PacketTime& packet_time)
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000248 OVERRIDE;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000249 virtual void OnRtcpReceived(rtc::Buffer* packet,
250 const rtc::PacketTime& packet_time)
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000251 OVERRIDE;
252 virtual void OnReadyToSend(bool ready) OVERRIDE;
253 virtual bool MuteStream(uint32 ssrc, bool mute) OVERRIDE;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000254
255 // Set send/receive RTP header extensions. This must be done before creating
256 // streams as it only has effect on future streams.
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000257 virtual bool SetRecvRtpHeaderExtensions(
258 const std::vector<RtpHeaderExtension>& extensions) OVERRIDE;
259 virtual bool SetSendRtpHeaderExtensions(
260 const std::vector<RtpHeaderExtension>& extensions) OVERRIDE;
261 virtual bool SetStartSendBandwidth(int bps) OVERRIDE;
262 virtual bool SetMaxSendBandwidth(int bps) OVERRIDE;
263 virtual bool SetOptions(const VideoOptions& options) OVERRIDE;
264 virtual bool GetOptions(VideoOptions* options) const OVERRIDE {
265 *options = options_;
266 return true;
267 }
268 virtual void SetInterface(NetworkInterface* iface) OVERRIDE;
269 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) OVERRIDE;
270
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000271 virtual void OnMessage(rtc::Message* msg) OVERRIDE;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000272
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000273 virtual void OnLoadUpdate(Load load) OVERRIDE;
274
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000275 // Implemented for VideoMediaChannelTest.
276 bool sending() const { return sending_; }
buildbot@webrtc.org2c0fb052014-08-13 16:47:12 +0000277 uint32 GetDefaultSendChannelSsrc() { return default_send_ssrc_; }
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000278 bool GetRenderer(uint32 ssrc, VideoRenderer** renderer);
279
280 private:
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000281 void ConfigureReceiverRtp(webrtc::VideoReceiveStream::Config* config,
282 const StreamParams& sp) const;
283
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000284 struct VideoCodecSettings {
285 VideoCodecSettings();
286
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000287 VideoCodec codec;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000288 webrtc::FecConfig fec;
289 int rtx_payload_type;
290 };
291
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000292 // Wrapper for the sender part, this is where the capturer is connected and
293 // frames are then converted from cricket frames to webrtc frames.
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000294 class WebRtcVideoSendStream : public sigslot::has_slots<> {
295 public:
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000296 WebRtcVideoSendStream(
297 webrtc::Call* call,
298 WebRtcVideoEncoderFactory2* encoder_factory,
299 const VideoOptions& options,
300 const Settable<VideoCodecSettings>& codec_settings,
301 const StreamParams& sp,
302 const std::vector<webrtc::RtpExtension>& rtp_extensions);
303
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000304 ~WebRtcVideoSendStream();
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000305 void SetOptions(const VideoOptions& options);
306 void SetCodec(const VideoCodecSettings& codec);
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000307 void SetRtpExtensions(
308 const std::vector<webrtc::RtpExtension>& rtp_extensions);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000309
310 void InputFrame(VideoCapturer* capturer, const VideoFrame* frame);
311 bool SetCapturer(VideoCapturer* capturer);
312 bool SetVideoFormat(const VideoFormat& format);
pbos@webrtc.orgef8bb8d2014-08-13 21:36:18 +0000313 void MuteStream(bool mute);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000314 bool DisconnectCapturer();
315
316 void Start();
317 void Stop();
318
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000319 VideoSenderInfo GetVideoSenderInfo();
320
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000321 void OnCpuResolutionRequest(
322 CoordinatedVideoAdapter::AdaptRequest adapt_request);
323
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000324 private:
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000325 // Parameters needed to reconstruct the underlying stream.
326 // webrtc::VideoSendStream doesn't support setting a lot of options on the
327 // fly, so when those need to be changed we tear down and reconstruct with
328 // similar parameters depending on which options changed etc.
329 struct VideoSendStreamParameters {
330 VideoSendStreamParameters(
331 const webrtc::VideoSendStream::Config& config,
332 const VideoOptions& options,
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000333 const Settable<VideoCodecSettings>& codec_settings);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000334 webrtc::VideoSendStream::Config config;
335 VideoOptions options;
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000336 Settable<VideoCodecSettings> codec_settings;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000337 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
338 // typically changes when setting a new resolution or reconfiguring
339 // bitrates.
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000340 webrtc::VideoEncoderConfig encoder_config;
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000341 };
342
pbos@webrtc.org5301b0f2014-07-17 08:51:46 +0000343 void SetCodecAndOptions(const VideoCodecSettings& codec,
pbos@webrtc.orgd60d79a2014-09-24 07:10:57 +0000344 const VideoOptions& options)
345 EXCLUSIVE_LOCKS_REQUIRED(lock_);
346 void RecreateWebRtcStream() EXCLUSIVE_LOCKS_REQUIRED(lock_);
pbos@webrtc.orgc4175b92014-09-03 15:25:49 +0000347 // When |override_max| is false constrain width/height to codec dimensions.
pbos@webrtc.orgd60d79a2014-09-24 07:10:57 +0000348 void SetDimensions(int width, int height, bool override_max)
349 EXCLUSIVE_LOCKS_REQUIRED(lock_);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000350
351 webrtc::Call* const call_;
352 WebRtcVideoEncoderFactory2* const encoder_factory_;
353
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000354 rtc::CriticalSection lock_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000355 webrtc::VideoSendStream* stream_ GUARDED_BY(lock_);
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000356 VideoSendStreamParameters parameters_ GUARDED_BY(lock_);
357
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000358 VideoCapturer* capturer_ GUARDED_BY(lock_);
359 bool sending_ GUARDED_BY(lock_);
360 bool muted_ GUARDED_BY(lock_);
361 VideoFormat format_ GUARDED_BY(lock_);
362
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000363 rtc::CriticalSection frame_lock_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000364 webrtc::I420VideoFrame video_frame_ GUARDED_BY(frame_lock_);
365 };
366
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000367 // Wrapper for the receiver part, contains configs etc. that are needed to
368 // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper
369 // between webrtc::VideoRenderer and cricket::VideoRenderer.
370 class WebRtcVideoReceiveStream : public webrtc::VideoRenderer {
371 public:
372 WebRtcVideoReceiveStream(
373 webrtc::Call*,
374 const webrtc::VideoReceiveStream::Config& config,
375 const std::vector<VideoCodecSettings>& recv_codecs);
376 ~WebRtcVideoReceiveStream();
377
378 void SetRecvCodecs(const std::vector<VideoCodecSettings>& recv_codecs);
379 void SetRtpExtensions(const std::vector<webrtc::RtpExtension>& extensions);
380
381 virtual void RenderFrame(const webrtc::I420VideoFrame& frame,
382 int time_to_render_ms) OVERRIDE;
383
384 void SetRenderer(cricket::VideoRenderer* renderer);
385 cricket::VideoRenderer* GetRenderer();
386
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000387 VideoReceiverInfo GetVideoReceiverInfo();
388
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000389 private:
390 void SetSize(int width, int height);
391 void RecreateWebRtcStream();
392
393 webrtc::Call* const call_;
394
395 webrtc::VideoReceiveStream* stream_;
396 webrtc::VideoReceiveStream::Config config_;
397
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000398 rtc::CriticalSection renderer_lock_;
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000399 cricket::VideoRenderer* renderer_ GUARDED_BY(renderer_lock_);
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000400 int last_width_ GUARDED_BY(renderer_lock_);
401 int last_height_ GUARDED_BY(renderer_lock_);
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000402 };
403
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000404 void Construct(webrtc::Call* call, WebRtcVideoEngine2* engine);
pbos@webrtc.org6f48f1b2014-07-22 16:29:54 +0000405 void SetDefaultOptions();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000406
407 virtual bool SendRtp(const uint8_t* data, size_t len) OVERRIDE;
408 virtual bool SendRtcp(const uint8_t* data, size_t len) OVERRIDE;
409
410 void StartAllSendStreams();
411 void StopAllSendStreams();
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000412
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000413 static std::vector<VideoCodecSettings> MapCodecs(
414 const std::vector<VideoCodec>& codecs);
415 std::vector<VideoCodecSettings> FilterSupportedCodecs(
416 const std::vector<VideoCodecSettings>& mapped_codecs);
417
pbos@webrtc.orge6f84ae2014-07-18 11:11:55 +0000418 void FillSenderStats(VideoMediaInfo* info);
419 void FillReceiverStats(VideoMediaInfo* info);
420 void FillBandwidthEstimationStats(VideoMediaInfo* info);
421
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000422 uint32_t rtcp_receiver_report_ssrc_;
423 bool sending_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000424 rtc::scoped_ptr<webrtc::Call> call_;
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000425 WebRtcCallFactory* call_factory_;
426
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000427 uint32_t default_send_ssrc_;
pbos@webrtc.orgafb554f42014-08-12 23:17:13 +0000428
429 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_;
430 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000431
432 // Using primary-ssrc (first ssrc) as key.
433 std::map<uint32, WebRtcVideoSendStream*> send_streams_;
pbos@webrtc.orgd1ea06b2014-07-18 09:35:58 +0000434 std::map<uint32, WebRtcVideoReceiveStream*> receive_streams_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000435
436 Settable<VideoCodecSettings> send_codec_;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000437 std::vector<webrtc::RtpExtension> send_rtp_extensions_;
438
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000439 WebRtcVideoEncoderFactory2* const encoder_factory_;
440 std::vector<VideoCodecSettings> recv_codecs_;
pbos@webrtc.org587ef602014-06-16 17:32:02 +0000441 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000442 VideoOptions options_;
443};
444
445} // namespace cricket
446
447#endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_