Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: webrtc/media/engine/webrtcvideoengine.h

Issue 3005363002: Reland of Prepare for injectable SW decoders (Closed)
Patch Set: Use both codec name and params as key in allocated decoders map. Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_ 11 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_ 12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
13 13
14 #include <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <set> 16 #include <set>
17 #include <string> 17 #include <string>
18 #include <vector> 18 #include <vector>
19 19
20 #include "webrtc/api/call/transport.h" 20 #include "webrtc/api/call/transport.h"
21 #include "webrtc/api/optional.h" 21 #include "webrtc/api/optional.h"
22 #include "webrtc/api/video/video_frame.h" 22 #include "webrtc/api/video/video_frame.h"
23 #include "webrtc/api/video_codecs/sdp_video_format.h"
23 #include "webrtc/call/call.h" 24 #include "webrtc/call/call.h"
24 #include "webrtc/call/flexfec_receive_stream.h" 25 #include "webrtc/call/flexfec_receive_stream.h"
25 #include "webrtc/call/video_receive_stream.h" 26 #include "webrtc/call/video_receive_stream.h"
26 #include "webrtc/call/video_send_stream.h" 27 #include "webrtc/call/video_send_stream.h"
27 #include "webrtc/media/base/mediaengine.h" 28 #include "webrtc/media/base/mediaengine.h"
28 #include "webrtc/media/base/videosinkinterface.h" 29 #include "webrtc/media/base/videosinkinterface.h"
29 #include "webrtc/media/base/videosourceinterface.h" 30 #include "webrtc/media/base/videosourceinterface.h"
30 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" 31 #include "webrtc/media/engine/webrtcvideodecoderfactory.h"
31 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" 32 #include "webrtc/media/engine/webrtcvideoencoderfactory.h"
32 #include "webrtc/rtc_base/asyncinvoker.h" 33 #include "webrtc/rtc_base/asyncinvoker.h"
33 #include "webrtc/rtc_base/criticalsection.h" 34 #include "webrtc/rtc_base/criticalsection.h"
34 #include "webrtc/rtc_base/networkroute.h" 35 #include "webrtc/rtc_base/networkroute.h"
35 #include "webrtc/rtc_base/thread_annotations.h" 36 #include "webrtc/rtc_base/thread_annotations.h"
36 #include "webrtc/rtc_base/thread_checker.h" 37 #include "webrtc/rtc_base/thread_checker.h"
37 38
38 namespace webrtc { 39 namespace webrtc {
39 class VideoDecoder; 40 class VideoDecoder;
40 class VideoEncoder; 41 class VideoEncoder;
41 struct MediaConfig; 42 struct MediaConfig;
43
44 struct SdpVideoFormatCompare {
45 bool operator()(const SdpVideoFormat& lhs, const SdpVideoFormat& rhs) const {
46 return std::tie(lhs.name, lhs.parameters) <
47 std::tie(rhs.name, rhs.parameters);
48 }
49 };
magjed_webrtc 2017/09/11 14:59:21 Move this to the private section of the WebRtcVide
andersc 2017/09/11 15:29:09 Done.
42 } 50 }
43 51
44 namespace rtc { 52 namespace rtc {
45 class Thread; 53 class Thread;
46 } // namespace rtc 54 } // namespace rtc
47 55
48 namespace cricket { 56 namespace cricket {
49 57
58 class DecoderFactoryAdapter;
50 class EncoderFactoryAdapter; 59 class EncoderFactoryAdapter;
51 class VideoCapturer; 60 class VideoCapturer;
52 class VideoProcessor; 61 class VideoProcessor;
53 class VideoRenderer; 62 class VideoRenderer;
54 class VoiceMediaChannel; 63 class VoiceMediaChannel;
55 class WebRtcDecoderObserver; 64 class WebRtcDecoderObserver;
56 class WebRtcEncoderObserver; 65 class WebRtcEncoderObserver;
57 class WebRtcLocalStreamInfo; 66 class WebRtcLocalStreamInfo;
58 class WebRtcRenderAdapter; 67 class WebRtcRenderAdapter;
59 class WebRtcVideoChannel; 68 class WebRtcVideoChannel;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory); 123 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory);
115 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does 124 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does
116 // not take the ownership of |encoder_factory|. The caller needs to make sure 125 // not take the ownership of |encoder_factory|. The caller needs to make sure
117 // that |encoder_factory| outlives the video engine. 126 // that |encoder_factory| outlives the video engine.
118 virtual void SetExternalEncoderFactory( 127 virtual void SetExternalEncoderFactory(
119 WebRtcVideoEncoderFactory* encoder_factory); 128 WebRtcVideoEncoderFactory* encoder_factory);
120 129
121 private: 130 private:
122 bool initialized_; 131 bool initialized_;
123 132
124 WebRtcVideoDecoderFactory* external_decoder_factory_; 133 std::unique_ptr<DecoderFactoryAdapter> decoder_factory_;
125 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_; 134 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_;
126 }; 135 };
127 136
128 class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport { 137 class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport {
129 public: 138 public:
130 WebRtcVideoChannel(webrtc::Call* call, 139 WebRtcVideoChannel(webrtc::Call* call,
131 const MediaConfig& config, 140 const MediaConfig& config,
132 const VideoOptions& options, 141 const VideoOptions& options,
133 const EncoderFactoryAdapter& encoder_factory, 142 const EncoderFactoryAdapter& encoder_factory,
134 WebRtcVideoDecoderFactory* external_decoder_factory); 143 const DecoderFactoryAdapter& decoder_factory);
135 ~WebRtcVideoChannel() override; 144 ~WebRtcVideoChannel() override;
136 145
137 // VideoMediaChannel implementation 146 // VideoMediaChannel implementation
138 rtc::DiffServCodePoint PreferredDscp() const override; 147 rtc::DiffServCodePoint PreferredDscp() const override;
139 148
140 bool SetSendParameters(const VideoSendParameters& params) override; 149 bool SetSendParameters(const VideoSendParameters& params) override;
141 bool SetRecvParameters(const VideoRecvParameters& params) override; 150 bool SetRecvParameters(const VideoRecvParameters& params) override;
142 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override; 151 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
143 bool SetRtpSendParameters(uint32_t ssrc, 152 bool SetRtpSendParameters(uint32_t ssrc,
144 const webrtc::RtpParameters& parameters) override; 153 const webrtc::RtpParameters& parameters) override;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 371
363 // Wrapper for the receiver part, contains configs etc. that are needed to 372 // Wrapper for the receiver part, contains configs etc. that are needed to
364 // reconstruct the underlying VideoReceiveStream. 373 // reconstruct the underlying VideoReceiveStream.
365 class WebRtcVideoReceiveStream 374 class WebRtcVideoReceiveStream
366 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { 375 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
367 public: 376 public:
368 WebRtcVideoReceiveStream( 377 WebRtcVideoReceiveStream(
369 webrtc::Call* call, 378 webrtc::Call* call,
370 const StreamParams& sp, 379 const StreamParams& sp,
371 webrtc::VideoReceiveStream::Config config, 380 webrtc::VideoReceiveStream::Config config,
372 WebRtcVideoDecoderFactory* external_decoder_factory, 381 const DecoderFactoryAdapter& decoder_factory,
373 bool default_stream, 382 bool default_stream,
374 const std::vector<VideoCodecSettings>& recv_codecs, 383 const std::vector<VideoCodecSettings>& recv_codecs,
375 const webrtc::FlexfecReceiveStream::Config& flexfec_config); 384 const webrtc::FlexfecReceiveStream::Config& flexfec_config);
376 ~WebRtcVideoReceiveStream(); 385 ~WebRtcVideoReceiveStream();
377 386
378 const std::vector<uint32_t>& GetSsrcs() const; 387 const std::vector<uint32_t>& GetSsrcs() const;
379 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const; 388 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const;
380 389
381 void SetLocalSsrc(uint32_t local_ssrc); 390 void SetLocalSsrc(uint32_t local_ssrc);
382 // TODO(deadbeef): Move these feedback parameters into the recv parameters. 391 // TODO(deadbeef): Move these feedback parameters into the recv parameters.
383 void SetFeedbackParameters(bool nack_enabled, 392 void SetFeedbackParameters(bool nack_enabled,
384 bool remb_enabled, 393 bool remb_enabled,
385 bool transport_cc_enabled, 394 bool transport_cc_enabled,
386 webrtc::RtcpMode rtcp_mode); 395 webrtc::RtcpMode rtcp_mode);
387 void SetRecvParameters(const ChangedRecvParameters& recv_params); 396 void SetRecvParameters(const ChangedRecvParameters& recv_params);
388 397
389 void OnFrame(const webrtc::VideoFrame& frame) override; 398 void OnFrame(const webrtc::VideoFrame& frame) override;
390 bool IsDefaultStream() const; 399 bool IsDefaultStream() const;
391 400
392 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink); 401 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
393 402
394 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats); 403 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats);
395 404
396 private: 405 private:
397 struct AllocatedDecoder {
398 AllocatedDecoder(webrtc::VideoDecoder* decoder,
399 webrtc::VideoCodecType type,
400 bool external);
401 webrtc::VideoDecoder* decoder;
402 // Decoder wrapped into a fallback decoder to permit software fallback.
403 webrtc::VideoDecoder* external_decoder;
404 webrtc::VideoCodecType type;
405 bool external;
406 };
407
408 void RecreateWebRtcVideoStream(); 406 void RecreateWebRtcVideoStream();
409 void MaybeRecreateWebRtcFlexfecStream(); 407 void MaybeRecreateWebRtcFlexfecStream();
410 408
411 void MaybeAssociateFlexfecWithVideo(); 409 void MaybeAssociateFlexfecWithVideo();
412 void MaybeDissociateFlexfecFromVideo(); 410 void MaybeDissociateFlexfecFromVideo();
413 411
414 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs, 412 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs,
415 std::vector<AllocatedDecoder>* old_codecs); 413 std::map<webrtc::SdpVideoFormat,
414 std::unique_ptr<webrtc::VideoDecoder>,
415 webrtc::SdpVideoFormatCompare>* old_codecs);
416 void ConfigureFlexfecCodec(int flexfec_payload_type); 416 void ConfigureFlexfecCodec(int flexfec_payload_type);
417 AllocatedDecoder CreateOrReuseVideoDecoder(
418 std::vector<AllocatedDecoder>* old_decoder,
419 const VideoCodec& codec);
420 void ClearDecoders(std::vector<AllocatedDecoder>* allocated_decoders);
421 417
422 std::string GetCodecNameFromPayloadType(int payload_type); 418 std::string GetCodecNameFromPayloadType(int payload_type);
423 419
424 webrtc::Call* const call_; 420 webrtc::Call* const call_;
425 StreamParams stream_params_; 421 StreamParams stream_params_;
426 422
427 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are 423 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are
428 // destroyed by calling call_->DestroyVideoReceiveStream and 424 // destroyed by calling call_->DestroyVideoReceiveStream and
429 // call_->DestroyFlexfecReceiveStream, respectively. 425 // call_->DestroyFlexfecReceiveStream, respectively.
430 webrtc::VideoReceiveStream* stream_; 426 webrtc::VideoReceiveStream* stream_;
431 const bool default_stream_; 427 const bool default_stream_;
432 webrtc::VideoReceiveStream::Config config_; 428 webrtc::VideoReceiveStream::Config config_;
433 webrtc::FlexfecReceiveStream::Config flexfec_config_; 429 webrtc::FlexfecReceiveStream::Config flexfec_config_;
434 webrtc::FlexfecReceiveStream* flexfec_stream_; 430 webrtc::FlexfecReceiveStream* flexfec_stream_;
435 431
436 WebRtcVideoDecoderFactory* const external_decoder_factory_; 432 std::unique_ptr<DecoderFactoryAdapter> decoder_factory_;
437 std::vector<AllocatedDecoder> allocated_decoders_; 433 std::map<webrtc::SdpVideoFormat,
434 std::unique_ptr<webrtc::VideoDecoder>,
435 webrtc::SdpVideoFormatCompare>
436 allocated_decoders_;
438 437
439 rtc::CriticalSection sink_lock_; 438 rtc::CriticalSection sink_lock_;
440 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_ 439 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_
441 RTC_GUARDED_BY(sink_lock_); 440 RTC_GUARDED_BY(sink_lock_);
442 // Expands remote RTP timestamps to int64_t to be able to estimate how long 441 // Expands remote RTP timestamps to int64_t to be able to estimate how long
443 // the stream has been running. 442 // the stream has been running.
444 rtc::TimestampWrapAroundHandler timestamp_wraparound_handler_ 443 rtc::TimestampWrapAroundHandler timestamp_wraparound_handler_
445 RTC_GUARDED_BY(sink_lock_); 444 RTC_GUARDED_BY(sink_lock_);
446 int64_t first_frame_timestamp_ RTC_GUARDED_BY(sink_lock_); 445 int64_t first_frame_timestamp_ RTC_GUARDED_BY(sink_lock_);
447 // Start NTP time is estimated as current remote NTP time (estimated from 446 // Start NTP time is estimated as current remote NTP time (estimated from
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 RTC_GUARDED_BY(stream_crit_); 490 RTC_GUARDED_BY(stream_crit_);
492 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_ 491 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_
493 RTC_GUARDED_BY(stream_crit_); 492 RTC_GUARDED_BY(stream_crit_);
494 std::set<uint32_t> send_ssrcs_ RTC_GUARDED_BY(stream_crit_); 493 std::set<uint32_t> send_ssrcs_ RTC_GUARDED_BY(stream_crit_);
495 std::set<uint32_t> receive_ssrcs_ RTC_GUARDED_BY(stream_crit_); 494 std::set<uint32_t> receive_ssrcs_ RTC_GUARDED_BY(stream_crit_);
496 495
497 rtc::Optional<VideoCodecSettings> send_codec_; 496 rtc::Optional<VideoCodecSettings> send_codec_;
498 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_; 497 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_;
499 498
500 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_; 499 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_;
501 WebRtcVideoDecoderFactory* const external_decoder_factory_; 500 std::unique_ptr<DecoderFactoryAdapter> decoder_factory_;
502 std::vector<VideoCodecSettings> recv_codecs_; 501 std::vector<VideoCodecSettings> recv_codecs_;
503 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; 502 std::vector<webrtc::RtpExtension> recv_rtp_extensions_;
504 // See reason for keeping track of the FlexFEC payload type separately in 503 // See reason for keeping track of the FlexFEC payload type separately in
505 // comment in WebRtcVideoChannel::ChangedRecvParameters. 504 // comment in WebRtcVideoChannel::ChangedRecvParameters.
506 int recv_flexfec_payload_type_; 505 int recv_flexfec_payload_type_;
507 webrtc::Call::Config::BitrateConfig bitrate_config_; 506 webrtc::Call::Config::BitrateConfig bitrate_config_;
508 // TODO(deadbeef): Don't duplicate information between 507 // TODO(deadbeef): Don't duplicate information between
509 // send_params/recv_params, rtp_extensions, options, etc. 508 // send_params/recv_params, rtp_extensions, options, etc.
510 VideoSendParameters send_params_; 509 VideoSendParameters send_params_;
511 VideoOptions default_send_options_; 510 VideoOptions default_send_options_;
(...skipping 19 matching lines...) Expand all
531 const std::string codec_name_; 530 const std::string codec_name_;
532 const int max_qp_; 531 const int max_qp_;
533 const int max_framerate_; 532 const int max_framerate_;
534 const bool is_screencast_; 533 const bool is_screencast_;
535 const bool conference_mode_; 534 const bool conference_mode_;
536 }; 535 };
537 536
538 } // namespace cricket 537 } // namespace cricket
539 538
540 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_ 539 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698