blob: f9c053a0967f234f775dc50b0f6c53ab057be4e3 [file] [log] [blame]
eladalonf1841382017-06-12 01:16:46 -07001/*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
12#define MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
eladalonf1841382017-06-12 01:16:46 -070013
14#include <map>
15#include <memory>
16#include <set>
17#include <string>
18#include <vector>
19
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "api/call/transport.h"
21#include "api/optional.h"
22#include "api/video/video_frame.h"
23#include "api/video_codecs/sdp_video_format.h"
24#include "call/call.h"
25#include "call/flexfec_receive_stream.h"
26#include "call/video_receive_stream.h"
27#include "call/video_send_stream.h"
28#include "media/base/mediaengine.h"
29#include "media/base/videosinkinterface.h"
30#include "media/base/videosourceinterface.h"
31#include "media/engine/webrtcvideodecoderfactory.h"
32#include "media/engine/webrtcvideoencoderfactory.h"
33#include "rtc_base/asyncinvoker.h"
34#include "rtc_base/criticalsection.h"
35#include "rtc_base/networkroute.h"
36#include "rtc_base/thread_annotations.h"
37#include "rtc_base/thread_checker.h"
eladalonf1841382017-06-12 01:16:46 -070038
39namespace webrtc {
40class VideoDecoder;
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020041class VideoDecoderFactory;
eladalonf1841382017-06-12 01:16:46 -070042class VideoEncoder;
Magnus Jedvertd4b0c052017-09-14 10:24:54 +020043class VideoEncoderFactory;
eladalonf1841382017-06-12 01:16:46 -070044struct MediaConfig;
45}
46
47namespace rtc {
48class Thread;
49} // namespace rtc
50
51namespace cricket {
52
andersc063f0c02017-09-11 11:50:51 -070053class DecoderFactoryAdapter;
eladalonf1841382017-06-12 01:16:46 -070054class VideoCapturer;
55class VideoProcessor;
56class VideoRenderer;
57class VoiceMediaChannel;
58class WebRtcDecoderObserver;
59class WebRtcEncoderObserver;
60class WebRtcLocalStreamInfo;
61class WebRtcRenderAdapter;
62class WebRtcVideoChannel;
63class WebRtcVideoChannelRecvInfo;
64class WebRtcVideoChannelSendInfo;
65class WebRtcVoiceEngine;
66class WebRtcVoiceMediaChannel;
67
68struct Device;
69
70class UnsignalledSsrcHandler {
71 public:
72 enum Action {
73 kDropPacket,
74 kDeliverPacket,
75 };
76 virtual Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
77 uint32_t ssrc) = 0;
78 virtual ~UnsignalledSsrcHandler() = default;
79};
80
81// TODO(pbos): Remove, use external handlers only.
82class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler {
83 public:
84 DefaultUnsignalledSsrcHandler();
85 Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
86 uint32_t ssrc) override;
87
88 rtc::VideoSinkInterface<webrtc::VideoFrame>* GetDefaultSink() const;
89 void SetDefaultSink(WebRtcVideoChannel* channel,
90 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
91
92 virtual ~DefaultUnsignalledSsrcHandler() = default;
93
94 private:
95 rtc::VideoSinkInterface<webrtc::VideoFrame>* default_sink_;
96};
97
98// WebRtcVideoEngine is used for the new native WebRTC Video API (webrtc:1667).
99class WebRtcVideoEngine {
100 public:
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200101 // Internal SW video codecs will be added on top of the external codecs.
102 WebRtcVideoEngine(
103 std::unique_ptr<WebRtcVideoEncoderFactory> external_video_encoder_factory,
104 std::unique_ptr<WebRtcVideoDecoderFactory>
105 external_video_decoder_factory);
Magnus Jedvertd4b0c052017-09-14 10:24:54 +0200106
107 // These video codec factories represents all video codecs, i.e. both software
108 // and external hardware codecs.
109 WebRtcVideoEngine(
110 std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory,
111 std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory);
112
eladalonf1841382017-06-12 01:16:46 -0700113 virtual ~WebRtcVideoEngine();
114
eladalonf1841382017-06-12 01:16:46 -0700115 WebRtcVideoChannel* CreateChannel(webrtc::Call* call,
116 const MediaConfig& config,
117 const VideoOptions& options);
118
119 std::vector<VideoCodec> codecs() const;
120 RtpCapabilities GetCapabilities() const;
121
eladalonf1841382017-06-12 01:16:46 -0700122 private:
magjed2475ae22017-09-12 04:42:15 -0700123 const std::unique_ptr<DecoderFactoryAdapter> decoder_factory_;
Magnus Jedvert1c9623c2017-10-30 14:26:20 +0100124 const std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory_;
eladalonf1841382017-06-12 01:16:46 -0700125};
126
127class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport {
128 public:
129 WebRtcVideoChannel(webrtc::Call* call,
130 const MediaConfig& config,
131 const VideoOptions& options,
Magnus Jedvert1c9623c2017-10-30 14:26:20 +0100132 webrtc::VideoEncoderFactory* encoder_factory,
133 DecoderFactoryAdapter* decoder_factory);
eladalonf1841382017-06-12 01:16:46 -0700134 ~WebRtcVideoChannel() override;
135
136 // VideoMediaChannel implementation
137 rtc::DiffServCodePoint PreferredDscp() const override;
138
139 bool SetSendParameters(const VideoSendParameters& params) override;
140 bool SetRecvParameters(const VideoRecvParameters& params) override;
141 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
142 bool SetRtpSendParameters(uint32_t ssrc,
143 const webrtc::RtpParameters& parameters) override;
144 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override;
145 bool SetRtpReceiveParameters(
146 uint32_t ssrc,
147 const webrtc::RtpParameters& parameters) override;
148 bool GetSendCodec(VideoCodec* send_codec) override;
149 bool SetSend(bool send) override;
150 bool SetVideoSend(
151 uint32_t ssrc,
152 bool enable,
153 const VideoOptions* options,
154 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override;
155 bool AddSendStream(const StreamParams& sp) override;
156 bool RemoveSendStream(uint32_t ssrc) override;
157 bool AddRecvStream(const StreamParams& sp) override;
158 bool AddRecvStream(const StreamParams& sp, bool default_stream);
159 bool RemoveRecvStream(uint32_t ssrc) override;
160 bool SetSink(uint32_t ssrc,
161 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
162 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override;
163 bool GetStats(VideoMediaInfo* info) override;
164
165 void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
166 const rtc::PacketTime& packet_time) override;
167 void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
168 const rtc::PacketTime& packet_time) override;
169 void OnReadyToSend(bool ready) override;
170 void OnNetworkRouteChanged(const std::string& transport_name,
171 const rtc::NetworkRoute& network_route) override;
172 void OnTransportOverheadChanged(int transport_overhead_per_packet) override;
173 void SetInterface(NetworkInterface* iface) override;
174
175 // Implemented for VideoMediaChannelTest.
176 bool sending() const { return sending_; }
177
178 rtc::Optional<uint32_t> GetDefaultReceiveStreamSsrc();
179
180 // AdaptReason is used for expressing why a WebRtcVideoSendStream request
181 // a lower input frame size than the currently configured camera input frame
182 // size. There can be more than one reason OR:ed together.
183 enum AdaptReason {
184 ADAPTREASON_NONE = 0,
185 ADAPTREASON_CPU = 1,
186 ADAPTREASON_BANDWIDTH = 2,
187 };
188
sprang67561a62017-06-15 06:34:42 -0700189 static constexpr int kDefaultQpMax = 56;
190
eladalonf1841382017-06-12 01:16:46 -0700191 private:
192 class WebRtcVideoReceiveStream;
193 struct VideoCodecSettings {
194 VideoCodecSettings();
195
196 // Checks if all members of |*this| are equal to the corresponding members
197 // of |other|.
198 bool operator==(const VideoCodecSettings& other) const;
199 bool operator!=(const VideoCodecSettings& other) const;
200
201 // Checks if all members of |a|, except |flexfec_payload_type|, are equal
202 // to the corresponding members of |b|.
203 static bool EqualsDisregardingFlexfec(const VideoCodecSettings& a,
204 const VideoCodecSettings& b);
205
206 VideoCodec codec;
207 webrtc::UlpfecConfig ulpfec;
208 int flexfec_payload_type;
209 int rtx_payload_type;
210 };
211
212 struct ChangedSendParameters {
213 // These optionals are unset if not changed.
214 rtc::Optional<VideoCodecSettings> codec;
215 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
216 rtc::Optional<int> max_bandwidth_bps;
217 rtc::Optional<bool> conference_mode;
218 rtc::Optional<webrtc::RtcpMode> rtcp_mode;
219 };
220
221 struct ChangedRecvParameters {
222 // These optionals are unset if not changed.
223 rtc::Optional<std::vector<VideoCodecSettings>> codec_settings;
224 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
225 // Keep track of the FlexFEC payload type separately from |codec_settings|.
226 // This allows us to recreate the FlexfecReceiveStream separately from the
227 // VideoReceiveStream when the FlexFEC payload type is changed.
228 rtc::Optional<int> flexfec_payload_type;
229 };
230
231 bool GetChangedSendParameters(const VideoSendParameters& params,
232 ChangedSendParameters* changed_params) const;
233 bool GetChangedRecvParameters(const VideoRecvParameters& params,
234 ChangedRecvParameters* changed_params) const;
235
236 void SetMaxSendBandwidth(int bps);
237
238 void ConfigureReceiverRtp(
239 webrtc::VideoReceiveStream::Config* config,
240 webrtc::FlexfecReceiveStream::Config* flexfec_config,
241 const StreamParams& sp) const;
242 bool ValidateSendSsrcAvailability(const StreamParams& sp) const
danilchapa37de392017-09-09 04:17:22 -0700243 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700244 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const
danilchapa37de392017-09-09 04:17:22 -0700245 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700246 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream)
danilchapa37de392017-09-09 04:17:22 -0700247 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700248
249 static std::string CodecSettingsVectorToString(
250 const std::vector<VideoCodecSettings>& codecs);
251
252 // Wrapper for the sender part.
253 class WebRtcVideoSendStream
254 : public rtc::VideoSourceInterface<webrtc::VideoFrame> {
255 public:
256 WebRtcVideoSendStream(
257 webrtc::Call* call,
258 const StreamParams& sp,
259 webrtc::VideoSendStream::Config config,
260 const VideoOptions& options,
Magnus Jedvert1c9623c2017-10-30 14:26:20 +0100261 webrtc::VideoEncoderFactory* encoder_factory,
eladalonf1841382017-06-12 01:16:46 -0700262 bool enable_cpu_overuse_detection,
263 int max_bitrate_bps,
264 const rtc::Optional<VideoCodecSettings>& codec_settings,
265 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions,
266 const VideoSendParameters& send_params);
267 virtual ~WebRtcVideoSendStream();
268
269 void SetSendParameters(const ChangedSendParameters& send_params);
270 bool SetRtpParameters(const webrtc::RtpParameters& parameters);
271 webrtc::RtpParameters GetRtpParameters() const;
272
273 // Implements rtc::VideoSourceInterface<webrtc::VideoFrame>.
274 // WebRtcVideoSendStream acts as a source to the webrtc::VideoSendStream
275 // in |stream_|. This is done to proxy VideoSinkWants from the encoder to
276 // the worker thread.
277 void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
278 const rtc::VideoSinkWants& wants) override;
279 void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
280
281 bool SetVideoSend(bool mute,
282 const VideoOptions* options,
283 rtc::VideoSourceInterface<webrtc::VideoFrame>* source);
284
285 void SetSend(bool send);
286
287 const std::vector<uint32_t>& GetSsrcs() const;
288 VideoSenderInfo GetVideoSenderInfo(bool log_stats);
289 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info);
290
291 private:
292 // Parameters needed to reconstruct the underlying stream.
293 // webrtc::VideoSendStream doesn't support setting a lot of options on the
294 // fly, so when those need to be changed we tear down and reconstruct with
295 // similar parameters depending on which options changed etc.
296 struct VideoSendStreamParameters {
297 VideoSendStreamParameters(
298 webrtc::VideoSendStream::Config config,
299 const VideoOptions& options,
300 int max_bitrate_bps,
301 const rtc::Optional<VideoCodecSettings>& codec_settings);
302 webrtc::VideoSendStream::Config config;
303 VideoOptions options;
304 int max_bitrate_bps;
305 bool conference_mode;
306 rtc::Optional<VideoCodecSettings> codec_settings;
307 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
308 // typically changes when setting a new resolution or reconfiguring
309 // bitrates.
310 webrtc::VideoEncoderConfig encoder_config;
311 };
312
eladalonf1841382017-06-12 01:16:46 -0700313 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings>
314 ConfigureVideoEncoderSettings(const VideoCodec& codec);
eladalonf1841382017-06-12 01:16:46 -0700315 void SetCodec(const VideoCodecSettings& codec,
316 bool force_encoder_allocation);
317 void RecreateWebRtcStream();
318 webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
319 const VideoCodec& codec) const;
320 void ReconfigureEncoder();
321 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters);
322
323 // Calls Start or Stop according to whether or not |sending_| is true,
324 // and whether or not the encoding in |rtp_parameters_| is active.
325 void UpdateSendState();
326
327 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference()
danilchapa37de392017-09-09 04:17:22 -0700328 const RTC_EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700329
330 rtc::ThreadChecker thread_checker_;
331 rtc::AsyncInvoker invoker_;
332 rtc::Thread* worker_thread_;
danilchapa37de392017-09-09 04:17:22 -0700333 const std::vector<uint32_t> ssrcs_ RTC_ACCESS_ON(&thread_checker_);
334 const std::vector<SsrcGroup> ssrc_groups_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700335 webrtc::Call* const call_;
336 const bool enable_cpu_overuse_detection_;
337 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_
danilchap47791cf2017-09-13 01:25:46 -0700338 RTC_ACCESS_ON(&thread_checker_);
Magnus Jedvert1c9623c2017-10-30 14:26:20 +0100339 webrtc::VideoEncoderFactory* const encoder_factory_
danilchap47791cf2017-09-13 01:25:46 -0700340 RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700341
danilchapa37de392017-09-09 04:17:22 -0700342 webrtc::VideoSendStream* stream_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700343 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_
danilchapa37de392017-09-09 04:17:22 -0700344 RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700345 // Contains settings that are the same for all streams in the MediaChannel,
346 // such as codecs, header extensions, and the global bitrate limit for the
347 // entire channel.
danilchapa37de392017-09-09 04:17:22 -0700348 VideoSendStreamParameters parameters_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700349 // Contains settings that are unique for each stream, such as max_bitrate.
350 // Does *not* contain codecs, however.
351 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_.
352 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only
353 // one stream per MediaChannel.
danilchapa37de392017-09-09 04:17:22 -0700354 webrtc::RtpParameters rtp_parameters_ RTC_ACCESS_ON(&thread_checker_);
magjeda35df422017-08-30 04:21:30 -0700355 std::unique_ptr<webrtc::VideoEncoder> allocated_encoder_
danilchapa37de392017-09-09 04:17:22 -0700356 RTC_ACCESS_ON(&thread_checker_);
357 VideoCodec allocated_codec_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700358
danilchapa37de392017-09-09 04:17:22 -0700359 bool sending_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700360 };
361
362 // Wrapper for the receiver part, contains configs etc. that are needed to
363 // reconstruct the underlying VideoReceiveStream.
364 class WebRtcVideoReceiveStream
365 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
366 public:
367 WebRtcVideoReceiveStream(
368 webrtc::Call* call,
369 const StreamParams& sp,
370 webrtc::VideoReceiveStream::Config config,
Magnus Jedvert1c9623c2017-10-30 14:26:20 +0100371 DecoderFactoryAdapter* decoder_factory,
eladalonf1841382017-06-12 01:16:46 -0700372 bool default_stream,
373 const std::vector<VideoCodecSettings>& recv_codecs,
374 const webrtc::FlexfecReceiveStream::Config& flexfec_config);
375 ~WebRtcVideoReceiveStream();
376
377 const std::vector<uint32_t>& GetSsrcs() const;
378 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const;
379
380 void SetLocalSsrc(uint32_t local_ssrc);
381 // TODO(deadbeef): Move these feedback parameters into the recv parameters.
382 void SetFeedbackParameters(bool nack_enabled,
383 bool remb_enabled,
384 bool transport_cc_enabled,
385 webrtc::RtcpMode rtcp_mode);
386 void SetRecvParameters(const ChangedRecvParameters& recv_params);
387
388 void OnFrame(const webrtc::VideoFrame& frame) override;
389 bool IsDefaultStream() const;
390
391 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
392
393 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats);
394
395 private:
andersc063f0c02017-09-11 11:50:51 -0700396 struct SdpVideoFormatCompare {
397 bool operator()(const webrtc::SdpVideoFormat& lhs,
398 const webrtc::SdpVideoFormat& rhs) const {
399 return std::tie(lhs.name, lhs.parameters) <
400 std::tie(rhs.name, rhs.parameters);
401 }
perkj1f885312017-09-04 02:43:10 -0700402 };
andersc063f0c02017-09-11 11:50:51 -0700403 typedef std::map<webrtc::SdpVideoFormat,
404 std::unique_ptr<webrtc::VideoDecoder>,
405 SdpVideoFormatCompare>
406 DecoderMap;
perkj1f885312017-09-04 02:43:10 -0700407
eladalonf1841382017-06-12 01:16:46 -0700408 void RecreateWebRtcVideoStream();
409 void MaybeRecreateWebRtcFlexfecStream();
410
eladalonc0d481a2017-08-02 07:39:07 -0700411 void MaybeAssociateFlexfecWithVideo();
412 void MaybeDissociateFlexfecFromVideo();
413
perkj1f885312017-09-04 02:43:10 -0700414 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs,
andersc063f0c02017-09-11 11:50:51 -0700415 DecoderMap* old_codecs);
eladalonf1841382017-06-12 01:16:46 -0700416 void ConfigureFlexfecCodec(int flexfec_payload_type);
eladalonf1841382017-06-12 01:16:46 -0700417
418 std::string GetCodecNameFromPayloadType(int payload_type);
419
420 webrtc::Call* const call_;
421 StreamParams stream_params_;
422
423 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are
424 // destroyed by calling call_->DestroyVideoReceiveStream and
425 // call_->DestroyFlexfecReceiveStream, respectively.
426 webrtc::VideoReceiveStream* stream_;
427 const bool default_stream_;
428 webrtc::VideoReceiveStream::Config config_;
429 webrtc::FlexfecReceiveStream::Config flexfec_config_;
430 webrtc::FlexfecReceiveStream* flexfec_stream_;
431
Magnus Jedvert1c9623c2017-10-30 14:26:20 +0100432 DecoderFactoryAdapter* decoder_factory_;
andersc063f0c02017-09-11 11:50:51 -0700433 DecoderMap allocated_decoders_;
eladalonf1841382017-06-12 01:16:46 -0700434
435 rtc::CriticalSection sink_lock_;
danilchapa37de392017-09-09 04:17:22 -0700436 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_
437 RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700438 // Expands remote RTP timestamps to int64_t to be able to estimate how long
439 // the stream has been running.
440 rtc::TimestampWrapAroundHandler timestamp_wraparound_handler_
danilchapa37de392017-09-09 04:17:22 -0700441 RTC_GUARDED_BY(sink_lock_);
442 int64_t first_frame_timestamp_ RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700443 // Start NTP time is estimated as current remote NTP time (estimated from
444 // RTCP) minus the elapsed time, as soon as remote NTP time is available.
danilchapa37de392017-09-09 04:17:22 -0700445 int64_t estimated_remote_start_ntp_time_ms_ RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700446 };
447
448 void Construct(webrtc::Call* call, WebRtcVideoEngine* engine);
449
450 bool SendRtp(const uint8_t* data,
451 size_t len,
452 const webrtc::PacketOptions& options) override;
453 bool SendRtcp(const uint8_t* data, size_t len) override;
454
455 static std::vector<VideoCodecSettings> MapCodecs(
456 const std::vector<VideoCodec>& codecs);
457 // Select what video codec will be used for sending, i.e. what codec is used
458 // for local encoding, based on supported remote codecs. The first remote
459 // codec that is supported locally will be selected.
460 rtc::Optional<VideoCodecSettings> SelectSendVideoCodec(
461 const std::vector<VideoCodecSettings>& remote_mapped_codecs) const;
462
463 static bool NonFlexfecReceiveCodecsHaveChanged(
464 std::vector<VideoCodecSettings> before,
465 std::vector<VideoCodecSettings> after);
466
467 void FillSenderStats(VideoMediaInfo* info, bool log_stats);
468 void FillReceiverStats(VideoMediaInfo* info, bool log_stats);
469 void FillBandwidthEstimationStats(const webrtc::Call::Stats& stats,
470 VideoMediaInfo* info);
471 void FillSendAndReceiveCodecStats(VideoMediaInfo* video_media_info);
472
473 rtc::ThreadChecker thread_checker_;
474
475 uint32_t rtcp_receiver_report_ssrc_;
476 bool sending_;
477 webrtc::Call* const call_;
478
479 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_;
480 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_;
481
482 const MediaConfig::Video video_config_;
483
484 rtc::CriticalSection stream_crit_;
485 // Using primary-ssrc (first ssrc) as key.
486 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_
danilchapa37de392017-09-09 04:17:22 -0700487 RTC_GUARDED_BY(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700488 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
danilchapa37de392017-09-09 04:17:22 -0700489 RTC_GUARDED_BY(stream_crit_);
490 std::set<uint32_t> send_ssrcs_ RTC_GUARDED_BY(stream_crit_);
491 std::set<uint32_t> receive_ssrcs_ RTC_GUARDED_BY(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700492
493 rtc::Optional<VideoCodecSettings> send_codec_;
494 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_;
495
Magnus Jedvert1c9623c2017-10-30 14:26:20 +0100496 webrtc::VideoEncoderFactory* const encoder_factory_;
497 DecoderFactoryAdapter* const decoder_factory_;
eladalonf1841382017-06-12 01:16:46 -0700498 std::vector<VideoCodecSettings> recv_codecs_;
499 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
500 // See reason for keeping track of the FlexFEC payload type separately in
501 // comment in WebRtcVideoChannel::ChangedRecvParameters.
502 int recv_flexfec_payload_type_;
503 webrtc::Call::Config::BitrateConfig bitrate_config_;
504 // TODO(deadbeef): Don't duplicate information between
505 // send_params/recv_params, rtp_extensions, options, etc.
506 VideoSendParameters send_params_;
507 VideoOptions default_send_options_;
508 VideoRecvParameters recv_params_;
509 int64_t last_stats_log_ms_;
510};
511
ilnik6b826ef2017-06-16 06:53:48 -0700512class EncoderStreamFactory
513 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
514 public:
515 EncoderStreamFactory(std::string codec_name,
516 int max_qp,
517 int max_framerate,
518 bool is_screencast,
519 bool conference_mode);
520
521 private:
522 std::vector<webrtc::VideoStream> CreateEncoderStreams(
523 int width,
524 int height,
525 const webrtc::VideoEncoderConfig& encoder_config) override;
526
527 const std::string codec_name_;
528 const int max_qp_;
529 const int max_framerate_;
530 const bool is_screencast_;
531 const bool conference_mode_;
532};
533
eladalonf1841382017-06-12 01:16:46 -0700534} // namespace cricket
535
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200536#endif // MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_