blob: c6f54128eb404022a1c744040193cb4778d75d56 [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"
Patrik Höglundbe214a22018-01-04 12:14:35 +010024#include "api/videosinkinterface.h"
Patrik Höglund9e194032018-01-04 15:58:20 +010025#include "api/videosourceinterface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "call/call.h"
27#include "call/flexfec_receive_stream.h"
28#include "call/video_receive_stream.h"
29#include "call/video_send_stream.h"
30#include "media/base/mediaengine.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#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
eladalonf1841382017-06-12 01:16:46 -070068class UnsignalledSsrcHandler {
69 public:
70 enum Action {
71 kDropPacket,
72 kDeliverPacket,
73 };
74 virtual Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
75 uint32_t ssrc) = 0;
76 virtual ~UnsignalledSsrcHandler() = default;
77};
78
79// TODO(pbos): Remove, use external handlers only.
80class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler {
81 public:
82 DefaultUnsignalledSsrcHandler();
83 Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
84 uint32_t ssrc) override;
85
86 rtc::VideoSinkInterface<webrtc::VideoFrame>* GetDefaultSink() const;
87 void SetDefaultSink(WebRtcVideoChannel* channel,
88 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
89
90 virtual ~DefaultUnsignalledSsrcHandler() = default;
91
92 private:
93 rtc::VideoSinkInterface<webrtc::VideoFrame>* default_sink_;
94};
95
96// WebRtcVideoEngine is used for the new native WebRTC Video API (webrtc:1667).
97class WebRtcVideoEngine {
98 public:
Magnus Jedvert02e7a192017-09-23 17:21:32 +020099 // Internal SW video codecs will be added on top of the external codecs.
100 WebRtcVideoEngine(
101 std::unique_ptr<WebRtcVideoEncoderFactory> external_video_encoder_factory,
102 std::unique_ptr<WebRtcVideoDecoderFactory>
103 external_video_decoder_factory);
Magnus Jedvertd4b0c052017-09-14 10:24:54 +0200104
105 // These video codec factories represents all video codecs, i.e. both software
106 // and external hardware codecs.
107 WebRtcVideoEngine(
108 std::unique_ptr<webrtc::VideoEncoderFactory> video_encoder_factory,
109 std::unique_ptr<webrtc::VideoDecoderFactory> video_decoder_factory);
110
eladalonf1841382017-06-12 01:16:46 -0700111 virtual ~WebRtcVideoEngine();
112
eladalonf1841382017-06-12 01:16:46 -0700113 WebRtcVideoChannel* CreateChannel(webrtc::Call* call,
114 const MediaConfig& config,
115 const VideoOptions& options);
116
117 std::vector<VideoCodec> codecs() const;
118 RtpCapabilities GetCapabilities() const;
119
eladalonf1841382017-06-12 01:16:46 -0700120 private:
magjed2475ae22017-09-12 04:42:15 -0700121 const std::unique_ptr<DecoderFactoryAdapter> decoder_factory_;
Magnus Jedvert07e0d012017-10-31 11:24:54 +0100122 const std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory_;
eladalonf1841382017-06-12 01:16:46 -0700123};
124
125class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport {
126 public:
127 WebRtcVideoChannel(webrtc::Call* call,
128 const MediaConfig& config,
129 const VideoOptions& options,
Magnus Jedvert07e0d012017-10-31 11:24:54 +0100130 webrtc::VideoEncoderFactory* encoder_factory,
131 DecoderFactoryAdapter* decoder_factory);
eladalonf1841382017-06-12 01:16:46 -0700132 ~WebRtcVideoChannel() override;
133
134 // VideoMediaChannel implementation
135 rtc::DiffServCodePoint PreferredDscp() const override;
136
137 bool SetSendParameters(const VideoSendParameters& params) override;
138 bool SetRecvParameters(const VideoRecvParameters& params) override;
139 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
Zach Steinba37b4b2018-01-23 15:02:36 -0800140 webrtc::RTCError SetRtpSendParameters(
141 uint32_t ssrc,
142 const webrtc::RtpParameters& parameters) override;
eladalonf1841382017-06-12 01:16:46 -0700143 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override;
144 bool SetRtpReceiveParameters(
145 uint32_t ssrc,
146 const webrtc::RtpParameters& parameters) override;
147 bool GetSendCodec(VideoCodec* send_codec) override;
148 bool SetSend(bool send) override;
149 bool SetVideoSend(
150 uint32_t ssrc,
151 bool enable,
152 const VideoOptions* options,
153 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override;
154 bool AddSendStream(const StreamParams& sp) override;
155 bool RemoveSendStream(uint32_t ssrc) override;
156 bool AddRecvStream(const StreamParams& sp) override;
157 bool AddRecvStream(const StreamParams& sp, bool default_stream);
158 bool RemoveRecvStream(uint32_t ssrc) override;
159 bool SetSink(uint32_t ssrc,
160 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
161 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override;
162 bool GetStats(VideoMediaInfo* info) override;
163
164 void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
165 const rtc::PacketTime& packet_time) override;
166 void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
167 const rtc::PacketTime& packet_time) override;
168 void OnReadyToSend(bool ready) override;
169 void OnNetworkRouteChanged(const std::string& transport_name,
170 const rtc::NetworkRoute& network_route) override;
eladalonf1841382017-06-12 01:16:46 -0700171 void SetInterface(NetworkInterface* iface) override;
172
173 // Implemented for VideoMediaChannelTest.
174 bool sending() const { return sending_; }
175
176 rtc::Optional<uint32_t> GetDefaultReceiveStreamSsrc();
177
178 // AdaptReason is used for expressing why a WebRtcVideoSendStream request
179 // a lower input frame size than the currently configured camera input frame
180 // size. There can be more than one reason OR:ed together.
181 enum AdaptReason {
182 ADAPTREASON_NONE = 0,
183 ADAPTREASON_CPU = 1,
184 ADAPTREASON_BANDWIDTH = 2,
185 };
186
sprang67561a62017-06-15 06:34:42 -0700187 static constexpr int kDefaultQpMax = 56;
188
eladalonf1841382017-06-12 01:16:46 -0700189 private:
190 class WebRtcVideoReceiveStream;
191 struct VideoCodecSettings {
192 VideoCodecSettings();
193
194 // Checks if all members of |*this| are equal to the corresponding members
195 // of |other|.
196 bool operator==(const VideoCodecSettings& other) const;
197 bool operator!=(const VideoCodecSettings& other) const;
198
199 // Checks if all members of |a|, except |flexfec_payload_type|, are equal
200 // to the corresponding members of |b|.
201 static bool EqualsDisregardingFlexfec(const VideoCodecSettings& a,
202 const VideoCodecSettings& b);
203
204 VideoCodec codec;
205 webrtc::UlpfecConfig ulpfec;
206 int flexfec_payload_type;
207 int rtx_payload_type;
208 };
209
210 struct ChangedSendParameters {
211 // These optionals are unset if not changed.
212 rtc::Optional<VideoCodecSettings> codec;
213 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
214 rtc::Optional<int> max_bandwidth_bps;
215 rtc::Optional<bool> conference_mode;
216 rtc::Optional<webrtc::RtcpMode> rtcp_mode;
217 };
218
219 struct ChangedRecvParameters {
220 // These optionals are unset if not changed.
221 rtc::Optional<std::vector<VideoCodecSettings>> codec_settings;
222 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
223 // Keep track of the FlexFEC payload type separately from |codec_settings|.
224 // This allows us to recreate the FlexfecReceiveStream separately from the
225 // VideoReceiveStream when the FlexFEC payload type is changed.
226 rtc::Optional<int> flexfec_payload_type;
227 };
228
229 bool GetChangedSendParameters(const VideoSendParameters& params,
230 ChangedSendParameters* changed_params) const;
231 bool GetChangedRecvParameters(const VideoRecvParameters& params,
232 ChangedRecvParameters* changed_params) const;
233
234 void SetMaxSendBandwidth(int bps);
235
236 void ConfigureReceiverRtp(
237 webrtc::VideoReceiveStream::Config* config,
238 webrtc::FlexfecReceiveStream::Config* flexfec_config,
239 const StreamParams& sp) const;
240 bool ValidateSendSsrcAvailability(const StreamParams& sp) const
danilchapa37de392017-09-09 04:17:22 -0700241 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700242 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const
danilchapa37de392017-09-09 04:17:22 -0700243 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700244 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream)
danilchapa37de392017-09-09 04:17:22 -0700245 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700246
247 static std::string CodecSettingsVectorToString(
248 const std::vector<VideoCodecSettings>& codecs);
249
250 // Wrapper for the sender part.
251 class WebRtcVideoSendStream
252 : public rtc::VideoSourceInterface<webrtc::VideoFrame> {
253 public:
254 WebRtcVideoSendStream(
255 webrtc::Call* call,
256 const StreamParams& sp,
257 webrtc::VideoSendStream::Config config,
258 const VideoOptions& options,
Magnus Jedvert07e0d012017-10-31 11:24:54 +0100259 webrtc::VideoEncoderFactory* encoder_factory,
eladalonf1841382017-06-12 01:16:46 -0700260 bool enable_cpu_overuse_detection,
261 int max_bitrate_bps,
262 const rtc::Optional<VideoCodecSettings>& codec_settings,
263 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions,
264 const VideoSendParameters& send_params);
265 virtual ~WebRtcVideoSendStream();
266
267 void SetSendParameters(const ChangedSendParameters& send_params);
Zach Steinba37b4b2018-01-23 15:02:36 -0800268 webrtc::RTCError SetRtpParameters(const webrtc::RtpParameters& parameters);
eladalonf1841382017-06-12 01:16:46 -0700269 webrtc::RtpParameters GetRtpParameters() const;
270
271 // Implements rtc::VideoSourceInterface<webrtc::VideoFrame>.
272 // WebRtcVideoSendStream acts as a source to the webrtc::VideoSendStream
273 // in |stream_|. This is done to proxy VideoSinkWants from the encoder to
274 // the worker thread.
275 void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
276 const rtc::VideoSinkWants& wants) override;
277 void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
278
279 bool SetVideoSend(bool mute,
280 const VideoOptions* options,
281 rtc::VideoSourceInterface<webrtc::VideoFrame>* source);
282
283 void SetSend(bool send);
284
285 const std::vector<uint32_t>& GetSsrcs() const;
286 VideoSenderInfo GetVideoSenderInfo(bool log_stats);
287 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info);
288
289 private:
290 // Parameters needed to reconstruct the underlying stream.
291 // webrtc::VideoSendStream doesn't support setting a lot of options on the
292 // fly, so when those need to be changed we tear down and reconstruct with
293 // similar parameters depending on which options changed etc.
294 struct VideoSendStreamParameters {
295 VideoSendStreamParameters(
296 webrtc::VideoSendStream::Config config,
297 const VideoOptions& options,
298 int max_bitrate_bps,
299 const rtc::Optional<VideoCodecSettings>& codec_settings);
300 webrtc::VideoSendStream::Config config;
301 VideoOptions options;
302 int max_bitrate_bps;
303 bool conference_mode;
304 rtc::Optional<VideoCodecSettings> codec_settings;
305 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
306 // typically changes when setting a new resolution or reconfiguring
307 // bitrates.
308 webrtc::VideoEncoderConfig encoder_config;
309 };
310
eladalonf1841382017-06-12 01:16:46 -0700311 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings>
312 ConfigureVideoEncoderSettings(const VideoCodec& codec);
eladalonf1841382017-06-12 01:16:46 -0700313 void SetCodec(const VideoCodecSettings& codec,
314 bool force_encoder_allocation);
315 void RecreateWebRtcStream();
316 webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
317 const VideoCodec& codec) const;
318 void ReconfigureEncoder();
Zach Steinba37b4b2018-01-23 15:02:36 -0800319 webrtc::RTCError ValidateRtpParameters(
320 const webrtc::RtpParameters& parameters);
eladalonf1841382017-06-12 01:16:46 -0700321
322 // Calls Start or Stop according to whether or not |sending_| is true,
323 // and whether or not the encoding in |rtp_parameters_| is active.
324 void UpdateSendState();
325
326 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference()
danilchapa37de392017-09-09 04:17:22 -0700327 const RTC_EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700328
329 rtc::ThreadChecker thread_checker_;
330 rtc::AsyncInvoker invoker_;
331 rtc::Thread* worker_thread_;
danilchapa37de392017-09-09 04:17:22 -0700332 const std::vector<uint32_t> ssrcs_ RTC_ACCESS_ON(&thread_checker_);
333 const std::vector<SsrcGroup> ssrc_groups_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700334 webrtc::Call* const call_;
335 const bool enable_cpu_overuse_detection_;
336 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_
danilchap47791cf2017-09-13 01:25:46 -0700337 RTC_ACCESS_ON(&thread_checker_);
Magnus Jedvert07e0d012017-10-31 11:24:54 +0100338 webrtc::VideoEncoderFactory* const encoder_factory_
danilchap47791cf2017-09-13 01:25:46 -0700339 RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700340
danilchapa37de392017-09-09 04:17:22 -0700341 webrtc::VideoSendStream* stream_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700342 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_
danilchapa37de392017-09-09 04:17:22 -0700343 RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700344 // Contains settings that are the same for all streams in the MediaChannel,
345 // such as codecs, header extensions, and the global bitrate limit for the
346 // entire channel.
danilchapa37de392017-09-09 04:17:22 -0700347 VideoSendStreamParameters parameters_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700348 // Contains settings that are unique for each stream, such as max_bitrate.
349 // Does *not* contain codecs, however.
350 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_.
351 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only
352 // one stream per MediaChannel.
danilchapa37de392017-09-09 04:17:22 -0700353 webrtc::RtpParameters rtp_parameters_ RTC_ACCESS_ON(&thread_checker_);
magjeda35df422017-08-30 04:21:30 -0700354 std::unique_ptr<webrtc::VideoEncoder> allocated_encoder_
danilchapa37de392017-09-09 04:17:22 -0700355 RTC_ACCESS_ON(&thread_checker_);
356 VideoCodec allocated_codec_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700357
danilchapa37de392017-09-09 04:17:22 -0700358 bool sending_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700359 };
360
361 // Wrapper for the receiver part, contains configs etc. that are needed to
362 // reconstruct the underlying VideoReceiveStream.
363 class WebRtcVideoReceiveStream
364 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
365 public:
366 WebRtcVideoReceiveStream(
367 webrtc::Call* call,
368 const StreamParams& sp,
369 webrtc::VideoReceiveStream::Config config,
Magnus Jedvert07e0d012017-10-31 11:24:54 +0100370 DecoderFactoryAdapter* decoder_factory,
eladalonf1841382017-06-12 01:16:46 -0700371 bool default_stream,
372 const std::vector<VideoCodecSettings>& recv_codecs,
373 const webrtc::FlexfecReceiveStream::Config& flexfec_config);
374 ~WebRtcVideoReceiveStream();
375
376 const std::vector<uint32_t>& GetSsrcs() const;
377 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const;
378
379 void SetLocalSsrc(uint32_t local_ssrc);
380 // TODO(deadbeef): Move these feedback parameters into the recv parameters.
381 void SetFeedbackParameters(bool nack_enabled,
382 bool remb_enabled,
383 bool transport_cc_enabled,
384 webrtc::RtcpMode rtcp_mode);
385 void SetRecvParameters(const ChangedRecvParameters& recv_params);
386
387 void OnFrame(const webrtc::VideoFrame& frame) override;
388 bool IsDefaultStream() const;
389
390 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
391
392 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats);
393
394 private:
andersc063f0c02017-09-11 11:50:51 -0700395 struct SdpVideoFormatCompare {
396 bool operator()(const webrtc::SdpVideoFormat& lhs,
397 const webrtc::SdpVideoFormat& rhs) const {
398 return std::tie(lhs.name, lhs.parameters) <
399 std::tie(rhs.name, rhs.parameters);
400 }
perkj1f885312017-09-04 02:43:10 -0700401 };
andersc063f0c02017-09-11 11:50:51 -0700402 typedef std::map<webrtc::SdpVideoFormat,
403 std::unique_ptr<webrtc::VideoDecoder>,
404 SdpVideoFormatCompare>
405 DecoderMap;
perkj1f885312017-09-04 02:43:10 -0700406
eladalonf1841382017-06-12 01:16:46 -0700407 void RecreateWebRtcVideoStream();
408 void MaybeRecreateWebRtcFlexfecStream();
409
eladalonc0d481a2017-08-02 07:39:07 -0700410 void MaybeAssociateFlexfecWithVideo();
411 void MaybeDissociateFlexfecFromVideo();
412
perkj1f885312017-09-04 02:43:10 -0700413 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs,
andersc063f0c02017-09-11 11:50:51 -0700414 DecoderMap* old_codecs);
eladalonf1841382017-06-12 01:16:46 -0700415 void ConfigureFlexfecCodec(int flexfec_payload_type);
eladalonf1841382017-06-12 01:16:46 -0700416
417 std::string GetCodecNameFromPayloadType(int payload_type);
418
419 webrtc::Call* const call_;
420 StreamParams stream_params_;
421
422 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are
423 // destroyed by calling call_->DestroyVideoReceiveStream and
424 // call_->DestroyFlexfecReceiveStream, respectively.
425 webrtc::VideoReceiveStream* stream_;
426 const bool default_stream_;
427 webrtc::VideoReceiveStream::Config config_;
428 webrtc::FlexfecReceiveStream::Config flexfec_config_;
429 webrtc::FlexfecReceiveStream* flexfec_stream_;
430
Magnus Jedvert07e0d012017-10-31 11:24:54 +0100431 DecoderFactoryAdapter* decoder_factory_;
andersc063f0c02017-09-11 11:50:51 -0700432 DecoderMap allocated_decoders_;
eladalonf1841382017-06-12 01:16:46 -0700433
434 rtc::CriticalSection sink_lock_;
danilchapa37de392017-09-09 04:17:22 -0700435 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_
436 RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700437 // Expands remote RTP timestamps to int64_t to be able to estimate how long
438 // the stream has been running.
439 rtc::TimestampWrapAroundHandler timestamp_wraparound_handler_
danilchapa37de392017-09-09 04:17:22 -0700440 RTC_GUARDED_BY(sink_lock_);
441 int64_t first_frame_timestamp_ RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700442 // Start NTP time is estimated as current remote NTP time (estimated from
443 // RTCP) minus the elapsed time, as soon as remote NTP time is available.
danilchapa37de392017-09-09 04:17:22 -0700444 int64_t estimated_remote_start_ntp_time_ms_ RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700445 };
446
447 void Construct(webrtc::Call* call, WebRtcVideoEngine* engine);
448
449 bool SendRtp(const uint8_t* data,
450 size_t len,
451 const webrtc::PacketOptions& options) override;
452 bool SendRtcp(const uint8_t* data, size_t len) override;
453
454 static std::vector<VideoCodecSettings> MapCodecs(
455 const std::vector<VideoCodec>& codecs);
456 // Select what video codec will be used for sending, i.e. what codec is used
457 // for local encoding, based on supported remote codecs. The first remote
458 // codec that is supported locally will be selected.
459 rtc::Optional<VideoCodecSettings> SelectSendVideoCodec(
460 const std::vector<VideoCodecSettings>& remote_mapped_codecs) const;
461
462 static bool NonFlexfecReceiveCodecsHaveChanged(
463 std::vector<VideoCodecSettings> before,
464 std::vector<VideoCodecSettings> after);
465
466 void FillSenderStats(VideoMediaInfo* info, bool log_stats);
467 void FillReceiverStats(VideoMediaInfo* info, bool log_stats);
468 void FillBandwidthEstimationStats(const webrtc::Call::Stats& stats,
469 VideoMediaInfo* info);
470 void FillSendAndReceiveCodecStats(VideoMediaInfo* video_media_info);
471
472 rtc::ThreadChecker thread_checker_;
473
474 uint32_t rtcp_receiver_report_ssrc_;
475 bool sending_;
476 webrtc::Call* const call_;
477
478 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_;
479 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_;
480
481 const MediaConfig::Video video_config_;
482
483 rtc::CriticalSection stream_crit_;
484 // Using primary-ssrc (first ssrc) as key.
485 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_
danilchapa37de392017-09-09 04:17:22 -0700486 RTC_GUARDED_BY(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700487 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
danilchapa37de392017-09-09 04:17:22 -0700488 RTC_GUARDED_BY(stream_crit_);
489 std::set<uint32_t> send_ssrcs_ RTC_GUARDED_BY(stream_crit_);
490 std::set<uint32_t> receive_ssrcs_ RTC_GUARDED_BY(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700491
492 rtc::Optional<VideoCodecSettings> send_codec_;
493 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_;
494
Magnus Jedvert07e0d012017-10-31 11:24:54 +0100495 webrtc::VideoEncoderFactory* const encoder_factory_;
496 DecoderFactoryAdapter* const decoder_factory_;
eladalonf1841382017-06-12 01:16:46 -0700497 std::vector<VideoCodecSettings> recv_codecs_;
498 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
499 // See reason for keeping track of the FlexFEC payload type separately in
500 // comment in WebRtcVideoChannel::ChangedRecvParameters.
501 int recv_flexfec_payload_type_;
502 webrtc::Call::Config::BitrateConfig bitrate_config_;
503 // TODO(deadbeef): Don't duplicate information between
504 // send_params/recv_params, rtp_extensions, options, etc.
505 VideoSendParameters send_params_;
506 VideoOptions default_send_options_;
507 VideoRecvParameters recv_params_;
508 int64_t last_stats_log_ms_;
509};
510
ilnik6b826ef2017-06-16 06:53:48 -0700511class EncoderStreamFactory
512 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
513 public:
514 EncoderStreamFactory(std::string codec_name,
515 int max_qp,
516 int max_framerate,
517 bool is_screencast,
518 bool conference_mode);
519
520 private:
521 std::vector<webrtc::VideoStream> CreateEncoderStreams(
522 int width,
523 int height,
524 const webrtc::VideoEncoderConfig& encoder_config) override;
525
526 const std::string codec_name_;
527 const int max_qp_;
528 const int max_framerate_;
529 const bool is_screencast_;
530 const bool conference_mode_;
531};
532
eladalonf1841382017-06-12 01:16:46 -0700533} // namespace cricket
534
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200535#endif // MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_