blob: 063d80bf53caec14de4a54f4d99396a5cb6bd8ac [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
11#ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
12#define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
13
14#include <map>
15#include <memory>
16#include <set>
17#include <string>
18#include <vector>
19
20#include "webrtc/api/call/transport.h"
kwiberg84f6a3f2017-09-05 08:43:13 -070021#include "webrtc/api/optional.h"
eladalonf1841382017-06-12 01:16:46 -070022#include "webrtc/api/video/video_frame.h"
andersc063f0c02017-09-11 11:50:51 -070023#include "webrtc/api/video_codecs/sdp_video_format.h"
eladalonf1841382017-06-12 01:16:46 -070024#include "webrtc/call/call.h"
25#include "webrtc/call/flexfec_receive_stream.h"
aleloi440b6d92017-08-22 05:43:23 -070026#include "webrtc/call/video_receive_stream.h"
27#include "webrtc/call/video_send_stream.h"
eladalonf1841382017-06-12 01:16:46 -070028#include "webrtc/media/base/mediaengine.h"
29#include "webrtc/media/base/videosinkinterface.h"
30#include "webrtc/media/base/videosourceinterface.h"
31#include "webrtc/media/engine/webrtcvideodecoderfactory.h"
32#include "webrtc/media/engine/webrtcvideoencoderfactory.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020033#include "webrtc/rtc_base/asyncinvoker.h"
34#include "webrtc/rtc_base/criticalsection.h"
35#include "webrtc/rtc_base/networkroute.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020036#include "webrtc/rtc_base/thread_annotations.h"
37#include "webrtc/rtc_base/thread_checker.h"
eladalonf1841382017-06-12 01:16:46 -070038
39namespace webrtc {
40class VideoDecoder;
41class VideoEncoder;
42struct MediaConfig;
43}
44
45namespace rtc {
46class Thread;
47} // namespace rtc
48
49namespace cricket {
50
andersc063f0c02017-09-11 11:50:51 -070051class DecoderFactoryAdapter;
magjeda35df422017-08-30 04:21:30 -070052class EncoderFactoryAdapter;
eladalonf1841382017-06-12 01:16:46 -070053class VideoCapturer;
54class VideoProcessor;
55class VideoRenderer;
56class VoiceMediaChannel;
57class WebRtcDecoderObserver;
58class WebRtcEncoderObserver;
59class WebRtcLocalStreamInfo;
60class WebRtcRenderAdapter;
61class WebRtcVideoChannel;
62class WebRtcVideoChannelRecvInfo;
63class WebRtcVideoChannelSendInfo;
64class WebRtcVoiceEngine;
65class WebRtcVoiceMediaChannel;
66
67struct Device;
68
69class UnsignalledSsrcHandler {
70 public:
71 enum Action {
72 kDropPacket,
73 kDeliverPacket,
74 };
75 virtual Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
76 uint32_t ssrc) = 0;
77 virtual ~UnsignalledSsrcHandler() = default;
78};
79
80// TODO(pbos): Remove, use external handlers only.
81class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler {
82 public:
83 DefaultUnsignalledSsrcHandler();
84 Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
85 uint32_t ssrc) override;
86
87 rtc::VideoSinkInterface<webrtc::VideoFrame>* GetDefaultSink() const;
88 void SetDefaultSink(WebRtcVideoChannel* channel,
89 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
90
91 virtual ~DefaultUnsignalledSsrcHandler() = default;
92
93 private:
94 rtc::VideoSinkInterface<webrtc::VideoFrame>* default_sink_;
95};
96
97// WebRtcVideoEngine is used for the new native WebRTC Video API (webrtc:1667).
98class WebRtcVideoEngine {
99 public:
magjed2475ae22017-09-12 04:42:15 -0700100 // Video engine does not take ownership of the video codec factories and the
101 // caller needs to make sure they outlive the video engine. Internal SW video
102 // codecs will be added on top of the external codecs.
103 WebRtcVideoEngine(WebRtcVideoEncoderFactory* external_video_encoder_factory,
104 WebRtcVideoDecoderFactory* external_video_decoder_factory);
eladalonf1841382017-06-12 01:16:46 -0700105 virtual ~WebRtcVideoEngine();
106
eladalonf1841382017-06-12 01:16:46 -0700107 WebRtcVideoChannel* CreateChannel(webrtc::Call* call,
108 const MediaConfig& config,
109 const VideoOptions& options);
110
111 std::vector<VideoCodec> codecs() const;
112 RtpCapabilities GetCapabilities() const;
113
eladalonf1841382017-06-12 01:16:46 -0700114 private:
magjed2475ae22017-09-12 04:42:15 -0700115 const std::unique_ptr<DecoderFactoryAdapter> decoder_factory_;
116 const std::unique_ptr<EncoderFactoryAdapter> encoder_factory_;
eladalonf1841382017-06-12 01:16:46 -0700117};
118
119class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport {
120 public:
121 WebRtcVideoChannel(webrtc::Call* call,
122 const MediaConfig& config,
123 const VideoOptions& options,
magjed2475ae22017-09-12 04:42:15 -0700124 const EncoderFactoryAdapter* encoder_factory,
125 const DecoderFactoryAdapter* decoder_factory);
eladalonf1841382017-06-12 01:16:46 -0700126 ~WebRtcVideoChannel() override;
127
128 // VideoMediaChannel implementation
129 rtc::DiffServCodePoint PreferredDscp() const override;
130
131 bool SetSendParameters(const VideoSendParameters& params) override;
132 bool SetRecvParameters(const VideoRecvParameters& params) override;
133 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
134 bool SetRtpSendParameters(uint32_t ssrc,
135 const webrtc::RtpParameters& parameters) override;
136 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override;
137 bool SetRtpReceiveParameters(
138 uint32_t ssrc,
139 const webrtc::RtpParameters& parameters) override;
140 bool GetSendCodec(VideoCodec* send_codec) override;
141 bool SetSend(bool send) override;
142 bool SetVideoSend(
143 uint32_t ssrc,
144 bool enable,
145 const VideoOptions* options,
146 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override;
147 bool AddSendStream(const StreamParams& sp) override;
148 bool RemoveSendStream(uint32_t ssrc) override;
149 bool AddRecvStream(const StreamParams& sp) override;
150 bool AddRecvStream(const StreamParams& sp, bool default_stream);
151 bool RemoveRecvStream(uint32_t ssrc) override;
152 bool SetSink(uint32_t ssrc,
153 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
154 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override;
155 bool GetStats(VideoMediaInfo* info) override;
156
157 void OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
158 const rtc::PacketTime& packet_time) override;
159 void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet,
160 const rtc::PacketTime& packet_time) override;
161 void OnReadyToSend(bool ready) override;
162 void OnNetworkRouteChanged(const std::string& transport_name,
163 const rtc::NetworkRoute& network_route) override;
164 void OnTransportOverheadChanged(int transport_overhead_per_packet) override;
165 void SetInterface(NetworkInterface* iface) override;
166
167 // Implemented for VideoMediaChannelTest.
168 bool sending() const { return sending_; }
169
170 rtc::Optional<uint32_t> GetDefaultReceiveStreamSsrc();
171
172 // AdaptReason is used for expressing why a WebRtcVideoSendStream request
173 // a lower input frame size than the currently configured camera input frame
174 // size. There can be more than one reason OR:ed together.
175 enum AdaptReason {
176 ADAPTREASON_NONE = 0,
177 ADAPTREASON_CPU = 1,
178 ADAPTREASON_BANDWIDTH = 2,
179 };
180
sprang67561a62017-06-15 06:34:42 -0700181 static constexpr int kDefaultQpMax = 56;
182
eladalonf1841382017-06-12 01:16:46 -0700183 private:
184 class WebRtcVideoReceiveStream;
185 struct VideoCodecSettings {
186 VideoCodecSettings();
187
188 // Checks if all members of |*this| are equal to the corresponding members
189 // of |other|.
190 bool operator==(const VideoCodecSettings& other) const;
191 bool operator!=(const VideoCodecSettings& other) const;
192
193 // Checks if all members of |a|, except |flexfec_payload_type|, are equal
194 // to the corresponding members of |b|.
195 static bool EqualsDisregardingFlexfec(const VideoCodecSettings& a,
196 const VideoCodecSettings& b);
197
198 VideoCodec codec;
199 webrtc::UlpfecConfig ulpfec;
200 int flexfec_payload_type;
201 int rtx_payload_type;
202 };
203
204 struct ChangedSendParameters {
205 // These optionals are unset if not changed.
206 rtc::Optional<VideoCodecSettings> codec;
207 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
208 rtc::Optional<int> max_bandwidth_bps;
209 rtc::Optional<bool> conference_mode;
210 rtc::Optional<webrtc::RtcpMode> rtcp_mode;
211 };
212
213 struct ChangedRecvParameters {
214 // These optionals are unset if not changed.
215 rtc::Optional<std::vector<VideoCodecSettings>> codec_settings;
216 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions;
217 // Keep track of the FlexFEC payload type separately from |codec_settings|.
218 // This allows us to recreate the FlexfecReceiveStream separately from the
219 // VideoReceiveStream when the FlexFEC payload type is changed.
220 rtc::Optional<int> flexfec_payload_type;
221 };
222
223 bool GetChangedSendParameters(const VideoSendParameters& params,
224 ChangedSendParameters* changed_params) const;
225 bool GetChangedRecvParameters(const VideoRecvParameters& params,
226 ChangedRecvParameters* changed_params) const;
227
228 void SetMaxSendBandwidth(int bps);
229
230 void ConfigureReceiverRtp(
231 webrtc::VideoReceiveStream::Config* config,
232 webrtc::FlexfecReceiveStream::Config* flexfec_config,
233 const StreamParams& sp) const;
234 bool ValidateSendSsrcAvailability(const StreamParams& sp) const
danilchapa37de392017-09-09 04:17:22 -0700235 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700236 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const
danilchapa37de392017-09-09 04:17:22 -0700237 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700238 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream)
danilchapa37de392017-09-09 04:17:22 -0700239 RTC_EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700240
241 static std::string CodecSettingsVectorToString(
242 const std::vector<VideoCodecSettings>& codecs);
243
244 // Wrapper for the sender part.
245 class WebRtcVideoSendStream
246 : public rtc::VideoSourceInterface<webrtc::VideoFrame> {
247 public:
248 WebRtcVideoSendStream(
249 webrtc::Call* call,
250 const StreamParams& sp,
251 webrtc::VideoSendStream::Config config,
252 const VideoOptions& options,
magjed2475ae22017-09-12 04:42:15 -0700253 const EncoderFactoryAdapter* encoder_factory,
eladalonf1841382017-06-12 01:16:46 -0700254 bool enable_cpu_overuse_detection,
255 int max_bitrate_bps,
256 const rtc::Optional<VideoCodecSettings>& codec_settings,
257 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions,
258 const VideoSendParameters& send_params);
259 virtual ~WebRtcVideoSendStream();
260
261 void SetSendParameters(const ChangedSendParameters& send_params);
262 bool SetRtpParameters(const webrtc::RtpParameters& parameters);
263 webrtc::RtpParameters GetRtpParameters() const;
264
265 // Implements rtc::VideoSourceInterface<webrtc::VideoFrame>.
266 // WebRtcVideoSendStream acts as a source to the webrtc::VideoSendStream
267 // in |stream_|. This is done to proxy VideoSinkWants from the encoder to
268 // the worker thread.
269 void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
270 const rtc::VideoSinkWants& wants) override;
271 void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
272
273 bool SetVideoSend(bool mute,
274 const VideoOptions* options,
275 rtc::VideoSourceInterface<webrtc::VideoFrame>* source);
276
277 void SetSend(bool send);
278
279 const std::vector<uint32_t>& GetSsrcs() const;
280 VideoSenderInfo GetVideoSenderInfo(bool log_stats);
281 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info);
282
283 private:
284 // Parameters needed to reconstruct the underlying stream.
285 // webrtc::VideoSendStream doesn't support setting a lot of options on the
286 // fly, so when those need to be changed we tear down and reconstruct with
287 // similar parameters depending on which options changed etc.
288 struct VideoSendStreamParameters {
289 VideoSendStreamParameters(
290 webrtc::VideoSendStream::Config config,
291 const VideoOptions& options,
292 int max_bitrate_bps,
293 const rtc::Optional<VideoCodecSettings>& codec_settings);
294 webrtc::VideoSendStream::Config config;
295 VideoOptions options;
296 int max_bitrate_bps;
297 bool conference_mode;
298 rtc::Optional<VideoCodecSettings> codec_settings;
299 // Sent resolutions + bitrates etc. by the underlying VideoSendStream,
300 // typically changes when setting a new resolution or reconfiguring
301 // bitrates.
302 webrtc::VideoEncoderConfig encoder_config;
303 };
304
eladalonf1841382017-06-12 01:16:46 -0700305 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings>
306 ConfigureVideoEncoderSettings(const VideoCodec& codec);
eladalonf1841382017-06-12 01:16:46 -0700307 void SetCodec(const VideoCodecSettings& codec,
308 bool force_encoder_allocation);
309 void RecreateWebRtcStream();
310 webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
311 const VideoCodec& codec) const;
312 void ReconfigureEncoder();
313 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters);
314
315 // Calls Start or Stop according to whether or not |sending_| is true,
316 // and whether or not the encoding in |rtp_parameters_| is active.
317 void UpdateSendState();
318
319 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference()
danilchapa37de392017-09-09 04:17:22 -0700320 const RTC_EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700321
322 rtc::ThreadChecker thread_checker_;
323 rtc::AsyncInvoker invoker_;
324 rtc::Thread* worker_thread_;
danilchapa37de392017-09-09 04:17:22 -0700325 const std::vector<uint32_t> ssrcs_ RTC_ACCESS_ON(&thread_checker_);
326 const std::vector<SsrcGroup> ssrc_groups_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700327 webrtc::Call* const call_;
328 const bool enable_cpu_overuse_detection_;
329 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_
danilchap47791cf2017-09-13 01:25:46 -0700330 RTC_ACCESS_ON(&thread_checker_);
magjed2475ae22017-09-12 04:42:15 -0700331 const EncoderFactoryAdapter* const encoder_factory_
danilchap47791cf2017-09-13 01:25:46 -0700332 RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700333
danilchapa37de392017-09-09 04:17:22 -0700334 webrtc::VideoSendStream* stream_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700335 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_
danilchapa37de392017-09-09 04:17:22 -0700336 RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700337 // Contains settings that are the same for all streams in the MediaChannel,
338 // such as codecs, header extensions, and the global bitrate limit for the
339 // entire channel.
danilchapa37de392017-09-09 04:17:22 -0700340 VideoSendStreamParameters parameters_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700341 // Contains settings that are unique for each stream, such as max_bitrate.
342 // Does *not* contain codecs, however.
343 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_.
344 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only
345 // one stream per MediaChannel.
danilchapa37de392017-09-09 04:17:22 -0700346 webrtc::RtpParameters rtp_parameters_ RTC_ACCESS_ON(&thread_checker_);
magjeda35df422017-08-30 04:21:30 -0700347 std::unique_ptr<webrtc::VideoEncoder> allocated_encoder_
danilchapa37de392017-09-09 04:17:22 -0700348 RTC_ACCESS_ON(&thread_checker_);
349 VideoCodec allocated_codec_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700350
danilchapa37de392017-09-09 04:17:22 -0700351 bool sending_ RTC_ACCESS_ON(&thread_checker_);
eladalonf1841382017-06-12 01:16:46 -0700352 };
353
354 // Wrapper for the receiver part, contains configs etc. that are needed to
355 // reconstruct the underlying VideoReceiveStream.
356 class WebRtcVideoReceiveStream
357 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
358 public:
359 WebRtcVideoReceiveStream(
360 webrtc::Call* call,
361 const StreamParams& sp,
362 webrtc::VideoReceiveStream::Config config,
magjed2475ae22017-09-12 04:42:15 -0700363 const DecoderFactoryAdapter* decoder_factory,
eladalonf1841382017-06-12 01:16:46 -0700364 bool default_stream,
365 const std::vector<VideoCodecSettings>& recv_codecs,
366 const webrtc::FlexfecReceiveStream::Config& flexfec_config);
367 ~WebRtcVideoReceiveStream();
368
369 const std::vector<uint32_t>& GetSsrcs() const;
370 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const;
371
372 void SetLocalSsrc(uint32_t local_ssrc);
373 // TODO(deadbeef): Move these feedback parameters into the recv parameters.
374 void SetFeedbackParameters(bool nack_enabled,
375 bool remb_enabled,
376 bool transport_cc_enabled,
377 webrtc::RtcpMode rtcp_mode);
378 void SetRecvParameters(const ChangedRecvParameters& recv_params);
379
380 void OnFrame(const webrtc::VideoFrame& frame) override;
381 bool IsDefaultStream() const;
382
383 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
384
385 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats);
386
387 private:
andersc063f0c02017-09-11 11:50:51 -0700388 struct SdpVideoFormatCompare {
389 bool operator()(const webrtc::SdpVideoFormat& lhs,
390 const webrtc::SdpVideoFormat& rhs) const {
391 return std::tie(lhs.name, lhs.parameters) <
392 std::tie(rhs.name, rhs.parameters);
393 }
perkj1f885312017-09-04 02:43:10 -0700394 };
andersc063f0c02017-09-11 11:50:51 -0700395 typedef std::map<webrtc::SdpVideoFormat,
396 std::unique_ptr<webrtc::VideoDecoder>,
397 SdpVideoFormatCompare>
398 DecoderMap;
perkj1f885312017-09-04 02:43:10 -0700399
eladalonf1841382017-06-12 01:16:46 -0700400 void RecreateWebRtcVideoStream();
401 void MaybeRecreateWebRtcFlexfecStream();
402
eladalonc0d481a2017-08-02 07:39:07 -0700403 void MaybeAssociateFlexfecWithVideo();
404 void MaybeDissociateFlexfecFromVideo();
405
perkj1f885312017-09-04 02:43:10 -0700406 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs,
andersc063f0c02017-09-11 11:50:51 -0700407 DecoderMap* old_codecs);
eladalonf1841382017-06-12 01:16:46 -0700408 void ConfigureFlexfecCodec(int flexfec_payload_type);
eladalonf1841382017-06-12 01:16:46 -0700409
410 std::string GetCodecNameFromPayloadType(int payload_type);
411
412 webrtc::Call* const call_;
413 StreamParams stream_params_;
414
415 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are
416 // destroyed by calling call_->DestroyVideoReceiveStream and
417 // call_->DestroyFlexfecReceiveStream, respectively.
418 webrtc::VideoReceiveStream* stream_;
419 const bool default_stream_;
420 webrtc::VideoReceiveStream::Config config_;
421 webrtc::FlexfecReceiveStream::Config flexfec_config_;
422 webrtc::FlexfecReceiveStream* flexfec_stream_;
423
magjed2475ae22017-09-12 04:42:15 -0700424 const DecoderFactoryAdapter* decoder_factory_;
andersc063f0c02017-09-11 11:50:51 -0700425 DecoderMap allocated_decoders_;
eladalonf1841382017-06-12 01:16:46 -0700426
427 rtc::CriticalSection sink_lock_;
danilchapa37de392017-09-09 04:17:22 -0700428 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_
429 RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700430 // Expands remote RTP timestamps to int64_t to be able to estimate how long
431 // the stream has been running.
432 rtc::TimestampWrapAroundHandler timestamp_wraparound_handler_
danilchapa37de392017-09-09 04:17:22 -0700433 RTC_GUARDED_BY(sink_lock_);
434 int64_t first_frame_timestamp_ RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700435 // Start NTP time is estimated as current remote NTP time (estimated from
436 // RTCP) minus the elapsed time, as soon as remote NTP time is available.
danilchapa37de392017-09-09 04:17:22 -0700437 int64_t estimated_remote_start_ntp_time_ms_ RTC_GUARDED_BY(sink_lock_);
eladalonf1841382017-06-12 01:16:46 -0700438 };
439
440 void Construct(webrtc::Call* call, WebRtcVideoEngine* engine);
441
442 bool SendRtp(const uint8_t* data,
443 size_t len,
444 const webrtc::PacketOptions& options) override;
445 bool SendRtcp(const uint8_t* data, size_t len) override;
446
447 static std::vector<VideoCodecSettings> MapCodecs(
448 const std::vector<VideoCodec>& codecs);
449 // Select what video codec will be used for sending, i.e. what codec is used
450 // for local encoding, based on supported remote codecs. The first remote
451 // codec that is supported locally will be selected.
452 rtc::Optional<VideoCodecSettings> SelectSendVideoCodec(
453 const std::vector<VideoCodecSettings>& remote_mapped_codecs) const;
454
455 static bool NonFlexfecReceiveCodecsHaveChanged(
456 std::vector<VideoCodecSettings> before,
457 std::vector<VideoCodecSettings> after);
458
459 void FillSenderStats(VideoMediaInfo* info, bool log_stats);
460 void FillReceiverStats(VideoMediaInfo* info, bool log_stats);
461 void FillBandwidthEstimationStats(const webrtc::Call::Stats& stats,
462 VideoMediaInfo* info);
463 void FillSendAndReceiveCodecStats(VideoMediaInfo* video_media_info);
464
465 rtc::ThreadChecker thread_checker_;
466
467 uint32_t rtcp_receiver_report_ssrc_;
468 bool sending_;
469 webrtc::Call* const call_;
470
471 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_;
472 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_;
473
474 const MediaConfig::Video video_config_;
475
476 rtc::CriticalSection stream_crit_;
477 // Using primary-ssrc (first ssrc) as key.
478 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_
danilchapa37de392017-09-09 04:17:22 -0700479 RTC_GUARDED_BY(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700480 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
danilchapa37de392017-09-09 04:17:22 -0700481 RTC_GUARDED_BY(stream_crit_);
482 std::set<uint32_t> send_ssrcs_ RTC_GUARDED_BY(stream_crit_);
483 std::set<uint32_t> receive_ssrcs_ RTC_GUARDED_BY(stream_crit_);
eladalonf1841382017-06-12 01:16:46 -0700484
485 rtc::Optional<VideoCodecSettings> send_codec_;
486 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_;
487
magjed2475ae22017-09-12 04:42:15 -0700488 const EncoderFactoryAdapter* const encoder_factory_;
489 const DecoderFactoryAdapter* const decoder_factory_;
eladalonf1841382017-06-12 01:16:46 -0700490 std::vector<VideoCodecSettings> recv_codecs_;
491 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
492 // See reason for keeping track of the FlexFEC payload type separately in
493 // comment in WebRtcVideoChannel::ChangedRecvParameters.
494 int recv_flexfec_payload_type_;
495 webrtc::Call::Config::BitrateConfig bitrate_config_;
496 // TODO(deadbeef): Don't duplicate information between
497 // send_params/recv_params, rtp_extensions, options, etc.
498 VideoSendParameters send_params_;
499 VideoOptions default_send_options_;
500 VideoRecvParameters recv_params_;
501 int64_t last_stats_log_ms_;
502};
503
ilnik6b826ef2017-06-16 06:53:48 -0700504class EncoderStreamFactory
505 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
506 public:
507 EncoderStreamFactory(std::string codec_name,
508 int max_qp,
509 int max_framerate,
510 bool is_screencast,
511 bool conference_mode);
512
513 private:
514 std::vector<webrtc::VideoStream> CreateEncoderStreams(
515 int width,
516 int height,
517 const webrtc::VideoEncoderConfig& encoder_config) override;
518
519 const std::string codec_name_;
520 const int max_qp_;
521 const int max_framerate_;
522 const bool is_screencast_;
523 const bool conference_mode_;
524};
525
eladalonf1841382017-06-12 01:16:46 -0700526} // namespace cricket
527
528#endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_