blob: deb13b1d2c6063dd95bcf166bad8fdf2b89917f7 [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"
21#include "webrtc/api/video/video_frame.h"
eladalonf1841382017-06-12 01:16:46 -070022#include "webrtc/call/call.h"
23#include "webrtc/call/flexfec_receive_stream.h"
aleloi440b6d92017-08-22 05:43:23 -070024#include "webrtc/call/video_receive_stream.h"
25#include "webrtc/call/video_send_stream.h"
eladalonf1841382017-06-12 01:16:46 -070026#include "webrtc/media/base/mediaengine.h"
27#include "webrtc/media/base/videosinkinterface.h"
28#include "webrtc/media/base/videosourceinterface.h"
29#include "webrtc/media/engine/webrtcvideodecoderfactory.h"
30#include "webrtc/media/engine/webrtcvideoencoderfactory.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020031#include "webrtc/rtc_base/asyncinvoker.h"
32#include "webrtc/rtc_base/criticalsection.h"
33#include "webrtc/rtc_base/networkroute.h"
34#include "webrtc/rtc_base/optional.h"
35#include "webrtc/rtc_base/thread_annotations.h"
36#include "webrtc/rtc_base/thread_checker.h"
eladalonf1841382017-06-12 01:16:46 -070037
38namespace webrtc {
39class VideoDecoder;
40class VideoEncoder;
41struct MediaConfig;
42}
43
44namespace rtc {
45class Thread;
46} // namespace rtc
47
48namespace cricket {
49
50class VideoCapturer;
51class VideoProcessor;
52class VideoRenderer;
53class VoiceMediaChannel;
54class WebRtcDecoderObserver;
55class WebRtcEncoderObserver;
56class WebRtcLocalStreamInfo;
57class WebRtcRenderAdapter;
58class WebRtcVideoChannel;
59class WebRtcVideoChannelRecvInfo;
60class WebRtcVideoChannelSendInfo;
61class WebRtcVoiceEngine;
62class WebRtcVoiceMediaChannel;
63
64struct Device;
65
66class UnsignalledSsrcHandler {
67 public:
68 enum Action {
69 kDropPacket,
70 kDeliverPacket,
71 };
72 virtual Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
73 uint32_t ssrc) = 0;
74 virtual ~UnsignalledSsrcHandler() = default;
75};
76
77// TODO(pbos): Remove, use external handlers only.
78class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler {
79 public:
80 DefaultUnsignalledSsrcHandler();
81 Action OnUnsignalledSsrc(WebRtcVideoChannel* channel,
82 uint32_t ssrc) override;
83
84 rtc::VideoSinkInterface<webrtc::VideoFrame>* GetDefaultSink() const;
85 void SetDefaultSink(WebRtcVideoChannel* channel,
86 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
87
88 virtual ~DefaultUnsignalledSsrcHandler() = default;
89
90 private:
91 rtc::VideoSinkInterface<webrtc::VideoFrame>* default_sink_;
92};
93
94// WebRtcVideoEngine is used for the new native WebRTC Video API (webrtc:1667).
95class WebRtcVideoEngine {
96 public:
97 WebRtcVideoEngine();
98 virtual ~WebRtcVideoEngine();
99
100 // Basic video engine implementation.
101 void Init();
102
103 WebRtcVideoChannel* CreateChannel(webrtc::Call* call,
104 const MediaConfig& config,
105 const VideoOptions& options);
106
107 std::vector<VideoCodec> codecs() const;
108 RtpCapabilities GetCapabilities() const;
109
110 // Set a WebRtcVideoDecoderFactory for external decoding. Video engine does
111 // not take the ownership of |decoder_factory|. The caller needs to make sure
112 // that |decoder_factory| outlives the video engine.
113 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory);
114 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does
115 // not take the ownership of |encoder_factory|. The caller needs to make sure
116 // that |encoder_factory| outlives the video engine.
117 virtual void SetExternalEncoderFactory(
118 WebRtcVideoEncoderFactory* encoder_factory);
119
120 private:
121 bool initialized_;
122
123 WebRtcVideoDecoderFactory* external_decoder_factory_;
124 WebRtcVideoEncoderFactory* external_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,
132 WebRtcVideoEncoderFactory* external_encoder_factory,
133 WebRtcVideoDecoderFactory* external_decoder_factory);
134 ~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
243 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
244 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const
245 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
246 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream)
247 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_);
248
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,
261 WebRtcVideoEncoderFactory* external_encoder_factory,
262 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
magjed3f897582017-08-28 08:05:42 -0700313 class AllocatedEncoder {
314 public:
315 AllocatedEncoder() = default;
316 AllocatedEncoder(AllocatedEncoder&&) = default;
317 AllocatedEncoder& operator=(AllocatedEncoder&&) = default;
318
319 AllocatedEncoder(std::unique_ptr<webrtc::VideoEncoder> encoder,
magjedf52d34d2017-08-29 00:58:52 -0700320 bool is_external,
eladalonf1841382017-06-12 01:16:46 -0700321 const cricket::VideoCodec& codec,
magjed3f897582017-08-28 08:05:42 -0700322 bool has_internal_source);
323
324 // Returns a raw pointer to the allocated encoder. This object still has
325 // ownership of the encoder and is responsible for deleting it.
326 webrtc::VideoEncoder* encoder() { return encoder_.get(); }
327
328 // Returns true if the encoder is external.
magjedf52d34d2017-08-29 00:58:52 -0700329 bool IsExternal() { return is_external_; }
magjed3f897582017-08-28 08:05:42 -0700330
331 cricket::VideoCodec codec() { return codec_; }
332
333 bool HasInternalSource() { return has_internal_source_; }
334
335 // Release the encoders this object manages.
336 void Reset();
337
338 private:
339 std::unique_ptr<webrtc::VideoEncoder> encoder_;
magjedf52d34d2017-08-29 00:58:52 -0700340 bool is_external_;
magjed3f897582017-08-28 08:05:42 -0700341 cricket::VideoCodec codec_;
342 bool has_internal_source_;
eladalonf1841382017-06-12 01:16:46 -0700343 };
344
345 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings>
346 ConfigureVideoEncoderSettings(const VideoCodec& codec);
magjed3f897582017-08-28 08:05:42 -0700347 // Creates and returns a new AllocatedEncoder of the specified codec type.
348 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec);
eladalonf1841382017-06-12 01:16:46 -0700349 void SetCodec(const VideoCodecSettings& codec,
350 bool force_encoder_allocation);
351 void RecreateWebRtcStream();
352 webrtc::VideoEncoderConfig CreateVideoEncoderConfig(
353 const VideoCodec& codec) const;
354 void ReconfigureEncoder();
355 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters);
356
357 // Calls Start or Stop according to whether or not |sending_| is true,
358 // and whether or not the encoding in |rtp_parameters_| is active.
359 void UpdateSendState();
360
361 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference()
362 const EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_);
363
364 rtc::ThreadChecker thread_checker_;
365 rtc::AsyncInvoker invoker_;
366 rtc::Thread* worker_thread_;
367 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_);
368 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_);
369 webrtc::Call* const call_;
370 const bool enable_cpu_overuse_detection_;
371 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_
372 ACCESS_ON(&thread_checker_);
373 WebRtcVideoEncoderFactory* const external_encoder_factory_
374 ACCESS_ON(&thread_checker_);
375 const std::unique_ptr<WebRtcVideoEncoderFactory> internal_encoder_factory_
376 ACCESS_ON(&thread_checker_);
377
378 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_);
379 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_
380 ACCESS_ON(&thread_checker_);
381 // Contains settings that are the same for all streams in the MediaChannel,
382 // such as codecs, header extensions, and the global bitrate limit for the
383 // entire channel.
384 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_);
385 // Contains settings that are unique for each stream, such as max_bitrate.
386 // Does *not* contain codecs, however.
387 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_.
388 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only
389 // one stream per MediaChannel.
390 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_);
391 AllocatedEncoder allocated_encoder_ ACCESS_ON(&thread_checker_);
392
393 bool sending_ ACCESS_ON(&thread_checker_);
394 };
395
396 // Wrapper for the receiver part, contains configs etc. that are needed to
397 // reconstruct the underlying VideoReceiveStream.
398 class WebRtcVideoReceiveStream
399 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
400 public:
401 WebRtcVideoReceiveStream(
402 webrtc::Call* call,
403 const StreamParams& sp,
404 webrtc::VideoReceiveStream::Config config,
405 WebRtcVideoDecoderFactory* external_decoder_factory,
406 bool default_stream,
407 const std::vector<VideoCodecSettings>& recv_codecs,
408 const webrtc::FlexfecReceiveStream::Config& flexfec_config);
409 ~WebRtcVideoReceiveStream();
410
411 const std::vector<uint32_t>& GetSsrcs() const;
412 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const;
413
414 void SetLocalSsrc(uint32_t local_ssrc);
415 // TODO(deadbeef): Move these feedback parameters into the recv parameters.
416 void SetFeedbackParameters(bool nack_enabled,
417 bool remb_enabled,
418 bool transport_cc_enabled,
419 webrtc::RtcpMode rtcp_mode);
420 void SetRecvParameters(const ChangedRecvParameters& recv_params);
421
422 void OnFrame(const webrtc::VideoFrame& frame) override;
423 bool IsDefaultStream() const;
424
425 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
426
427 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats);
428
429 private:
430 struct AllocatedDecoder {
431 AllocatedDecoder(webrtc::VideoDecoder* decoder,
432 webrtc::VideoCodecType type,
433 bool external);
434 webrtc::VideoDecoder* decoder;
435 // Decoder wrapped into a fallback decoder to permit software fallback.
436 webrtc::VideoDecoder* external_decoder;
437 webrtc::VideoCodecType type;
438 bool external;
439 };
440
441 void RecreateWebRtcVideoStream();
442 void MaybeRecreateWebRtcFlexfecStream();
443
eladalonc0d481a2017-08-02 07:39:07 -0700444 void MaybeAssociateFlexfecWithVideo();
445 void MaybeDissociateFlexfecFromVideo();
446
eladalonf1841382017-06-12 01:16:46 -0700447 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs,
448 std::vector<AllocatedDecoder>* old_codecs);
449 void ConfigureFlexfecCodec(int flexfec_payload_type);
450 AllocatedDecoder CreateOrReuseVideoDecoder(
451 std::vector<AllocatedDecoder>* old_decoder,
452 const VideoCodec& codec);
453 void ClearDecoders(std::vector<AllocatedDecoder>* allocated_decoders);
454
455 std::string GetCodecNameFromPayloadType(int payload_type);
456
457 webrtc::Call* const call_;
458 StreamParams stream_params_;
459
460 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are
461 // destroyed by calling call_->DestroyVideoReceiveStream and
462 // call_->DestroyFlexfecReceiveStream, respectively.
463 webrtc::VideoReceiveStream* stream_;
464 const bool default_stream_;
465 webrtc::VideoReceiveStream::Config config_;
466 webrtc::FlexfecReceiveStream::Config flexfec_config_;
467 webrtc::FlexfecReceiveStream* flexfec_stream_;
468
469 WebRtcVideoDecoderFactory* const external_decoder_factory_;
470 std::vector<AllocatedDecoder> allocated_decoders_;
471
472 rtc::CriticalSection sink_lock_;
473 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_ GUARDED_BY(sink_lock_);
474 // Expands remote RTP timestamps to int64_t to be able to estimate how long
475 // the stream has been running.
476 rtc::TimestampWrapAroundHandler timestamp_wraparound_handler_
477 GUARDED_BY(sink_lock_);
478 int64_t first_frame_timestamp_ GUARDED_BY(sink_lock_);
479 // Start NTP time is estimated as current remote NTP time (estimated from
480 // RTCP) minus the elapsed time, as soon as remote NTP time is available.
481 int64_t estimated_remote_start_ntp_time_ms_ GUARDED_BY(sink_lock_);
482 };
483
484 void Construct(webrtc::Call* call, WebRtcVideoEngine* engine);
485
486 bool SendRtp(const uint8_t* data,
487 size_t len,
488 const webrtc::PacketOptions& options) override;
489 bool SendRtcp(const uint8_t* data, size_t len) override;
490
491 static std::vector<VideoCodecSettings> MapCodecs(
492 const std::vector<VideoCodec>& codecs);
493 // Select what video codec will be used for sending, i.e. what codec is used
494 // for local encoding, based on supported remote codecs. The first remote
495 // codec that is supported locally will be selected.
496 rtc::Optional<VideoCodecSettings> SelectSendVideoCodec(
497 const std::vector<VideoCodecSettings>& remote_mapped_codecs) const;
498
499 static bool NonFlexfecReceiveCodecsHaveChanged(
500 std::vector<VideoCodecSettings> before,
501 std::vector<VideoCodecSettings> after);
502
503 void FillSenderStats(VideoMediaInfo* info, bool log_stats);
504 void FillReceiverStats(VideoMediaInfo* info, bool log_stats);
505 void FillBandwidthEstimationStats(const webrtc::Call::Stats& stats,
506 VideoMediaInfo* info);
507 void FillSendAndReceiveCodecStats(VideoMediaInfo* video_media_info);
508
509 rtc::ThreadChecker thread_checker_;
510
511 uint32_t rtcp_receiver_report_ssrc_;
512 bool sending_;
513 webrtc::Call* const call_;
514
515 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_;
516 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_;
517
518 const MediaConfig::Video video_config_;
519
520 rtc::CriticalSection stream_crit_;
521 // Using primary-ssrc (first ssrc) as key.
522 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_
523 GUARDED_BY(stream_crit_);
524 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
525 GUARDED_BY(stream_crit_);
526 std::set<uint32_t> send_ssrcs_ GUARDED_BY(stream_crit_);
527 std::set<uint32_t> receive_ssrcs_ GUARDED_BY(stream_crit_);
528
529 rtc::Optional<VideoCodecSettings> send_codec_;
530 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_;
531
532 WebRtcVideoEncoderFactory* const external_encoder_factory_;
533 WebRtcVideoDecoderFactory* const external_decoder_factory_;
534 std::vector<VideoCodecSettings> recv_codecs_;
535 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
536 // See reason for keeping track of the FlexFEC payload type separately in
537 // comment in WebRtcVideoChannel::ChangedRecvParameters.
538 int recv_flexfec_payload_type_;
539 webrtc::Call::Config::BitrateConfig bitrate_config_;
540 // TODO(deadbeef): Don't duplicate information between
541 // send_params/recv_params, rtp_extensions, options, etc.
542 VideoSendParameters send_params_;
543 VideoOptions default_send_options_;
544 VideoRecvParameters recv_params_;
545 int64_t last_stats_log_ms_;
546};
547
ilnik6b826ef2017-06-16 06:53:48 -0700548class EncoderStreamFactory
549 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
550 public:
551 EncoderStreamFactory(std::string codec_name,
552 int max_qp,
553 int max_framerate,
554 bool is_screencast,
555 bool conference_mode);
556
557 private:
558 std::vector<webrtc::VideoStream> CreateEncoderStreams(
559 int width,
560 int height,
561 const webrtc::VideoEncoderConfig& encoder_config) override;
562
563 const std::string codec_name_;
564 const int max_qp_;
565 const int max_framerate_;
566 const bool is_screencast_;
567 const bool conference_mode_;
568};
569
eladalonf1841382017-06-12 01:16:46 -0700570} // namespace cricket
571
572#endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_