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

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

Issue 3005363002: Reland of Prepare for injectable SW decoders (Closed)
Patch Set: Address comments. 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;
42 } 43 }
43 44
44 namespace rtc { 45 namespace rtc {
45 class Thread; 46 class Thread;
46 } // namespace rtc 47 } // namespace rtc
47 48
48 namespace cricket { 49 namespace cricket {
49 50
51 class DecoderFactoryAdapter;
50 class EncoderFactoryAdapter; 52 class EncoderFactoryAdapter;
51 class VideoCapturer; 53 class VideoCapturer;
52 class VideoProcessor; 54 class VideoProcessor;
53 class VideoRenderer; 55 class VideoRenderer;
54 class VoiceMediaChannel; 56 class VoiceMediaChannel;
55 class WebRtcDecoderObserver; 57 class WebRtcDecoderObserver;
56 class WebRtcEncoderObserver; 58 class WebRtcEncoderObserver;
57 class WebRtcLocalStreamInfo; 59 class WebRtcLocalStreamInfo;
58 class WebRtcRenderAdapter; 60 class WebRtcRenderAdapter;
59 class WebRtcVideoChannel; 61 class WebRtcVideoChannel;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory); 116 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory);
115 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does 117 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does
116 // not take the ownership of |encoder_factory|. The caller needs to make sure 118 // not take the ownership of |encoder_factory|. The caller needs to make sure
117 // that |encoder_factory| outlives the video engine. 119 // that |encoder_factory| outlives the video engine.
118 virtual void SetExternalEncoderFactory( 120 virtual void SetExternalEncoderFactory(
119 WebRtcVideoEncoderFactory* encoder_factory); 121 WebRtcVideoEncoderFactory* encoder_factory);
120 122
121 private: 123 private:
122 bool initialized_; 124 bool initialized_;
123 125
124 WebRtcVideoDecoderFactory* external_decoder_factory_; 126 std::unique_ptr<DecoderFactoryAdapter> decoder_factory_;
125 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_; 127 std::unique_ptr<EncoderFactoryAdapter> encoder_factory_;
126 }; 128 };
127 129
128 class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport { 130 class WebRtcVideoChannel : public VideoMediaChannel, public webrtc::Transport {
129 public: 131 public:
130 WebRtcVideoChannel(webrtc::Call* call, 132 WebRtcVideoChannel(webrtc::Call* call,
131 const MediaConfig& config, 133 const MediaConfig& config,
132 const VideoOptions& options, 134 const VideoOptions& options,
133 const EncoderFactoryAdapter& encoder_factory, 135 const EncoderFactoryAdapter& encoder_factory,
134 WebRtcVideoDecoderFactory* external_decoder_factory); 136 const DecoderFactoryAdapter& decoder_factory);
135 ~WebRtcVideoChannel() override; 137 ~WebRtcVideoChannel() override;
136 138
137 // VideoMediaChannel implementation 139 // VideoMediaChannel implementation
138 rtc::DiffServCodePoint PreferredDscp() const override; 140 rtc::DiffServCodePoint PreferredDscp() const override;
139 141
140 bool SetSendParameters(const VideoSendParameters& params) override; 142 bool SetSendParameters(const VideoSendParameters& params) override;
141 bool SetRecvParameters(const VideoRecvParameters& params) override; 143 bool SetRecvParameters(const VideoRecvParameters& params) override;
142 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override; 144 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override;
143 bool SetRtpSendParameters(uint32_t ssrc, 145 bool SetRtpSendParameters(uint32_t ssrc,
144 const webrtc::RtpParameters& parameters) override; 146 const webrtc::RtpParameters& parameters) override;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 364
363 // Wrapper for the receiver part, contains configs etc. that are needed to 365 // Wrapper for the receiver part, contains configs etc. that are needed to
364 // reconstruct the underlying VideoReceiveStream. 366 // reconstruct the underlying VideoReceiveStream.
365 class WebRtcVideoReceiveStream 367 class WebRtcVideoReceiveStream
366 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { 368 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
367 public: 369 public:
368 WebRtcVideoReceiveStream( 370 WebRtcVideoReceiveStream(
369 webrtc::Call* call, 371 webrtc::Call* call,
370 const StreamParams& sp, 372 const StreamParams& sp,
371 webrtc::VideoReceiveStream::Config config, 373 webrtc::VideoReceiveStream::Config config,
372 WebRtcVideoDecoderFactory* external_decoder_factory, 374 const DecoderFactoryAdapter& decoder_factory,
373 bool default_stream, 375 bool default_stream,
374 const std::vector<VideoCodecSettings>& recv_codecs, 376 const std::vector<VideoCodecSettings>& recv_codecs,
375 const webrtc::FlexfecReceiveStream::Config& flexfec_config); 377 const webrtc::FlexfecReceiveStream::Config& flexfec_config);
376 ~WebRtcVideoReceiveStream(); 378 ~WebRtcVideoReceiveStream();
377 379
378 const std::vector<uint32_t>& GetSsrcs() const; 380 const std::vector<uint32_t>& GetSsrcs() const;
379 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const; 381 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const;
380 382
381 void SetLocalSsrc(uint32_t local_ssrc); 383 void SetLocalSsrc(uint32_t local_ssrc);
382 // TODO(deadbeef): Move these feedback parameters into the recv parameters. 384 // TODO(deadbeef): Move these feedback parameters into the recv parameters.
383 void SetFeedbackParameters(bool nack_enabled, 385 void SetFeedbackParameters(bool nack_enabled,
384 bool remb_enabled, 386 bool remb_enabled,
385 bool transport_cc_enabled, 387 bool transport_cc_enabled,
386 webrtc::RtcpMode rtcp_mode); 388 webrtc::RtcpMode rtcp_mode);
387 void SetRecvParameters(const ChangedRecvParameters& recv_params); 389 void SetRecvParameters(const ChangedRecvParameters& recv_params);
388 390
389 void OnFrame(const webrtc::VideoFrame& frame) override; 391 void OnFrame(const webrtc::VideoFrame& frame) override;
390 bool IsDefaultStream() const; 392 bool IsDefaultStream() const;
391 393
392 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink); 394 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink);
393 395
394 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats); 396 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats);
395 397
396 private: 398 private:
397 struct AllocatedDecoder { 399 struct SdpVideoFormatCompare {
398 AllocatedDecoder(webrtc::VideoDecoder* decoder, 400 bool operator()(const webrtc::SdpVideoFormat& lhs,
399 webrtc::VideoCodecType type, 401 const webrtc::SdpVideoFormat& rhs) const {
400 bool external); 402 return std::tie(lhs.name, lhs.parameters) <
401 webrtc::VideoDecoder* decoder; 403 std::tie(rhs.name, rhs.parameters);
402 // Decoder wrapped into a fallback decoder to permit software fallback. 404 }
403 webrtc::VideoDecoder* external_decoder;
404 webrtc::VideoCodecType type;
405 bool external;
406 }; 405 };
406 typedef std::map<webrtc::SdpVideoFormat,
407 std::unique_ptr<webrtc::VideoDecoder>,
408 SdpVideoFormatCompare>
409 DecoderMap;
407 410
408 void RecreateWebRtcVideoStream(); 411 void RecreateWebRtcVideoStream();
409 void MaybeRecreateWebRtcFlexfecStream(); 412 void MaybeRecreateWebRtcFlexfecStream();
410 413
411 void MaybeAssociateFlexfecWithVideo(); 414 void MaybeAssociateFlexfecWithVideo();
412 void MaybeDissociateFlexfecFromVideo(); 415 void MaybeDissociateFlexfecFromVideo();
413 416
414 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs, 417 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs,
415 std::vector<AllocatedDecoder>* old_codecs); 418 DecoderMap* old_codecs);
416 void ConfigureFlexfecCodec(int flexfec_payload_type); 419 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 420
422 std::string GetCodecNameFromPayloadType(int payload_type); 421 std::string GetCodecNameFromPayloadType(int payload_type);
423 422
424 webrtc::Call* const call_; 423 webrtc::Call* const call_;
425 StreamParams stream_params_; 424 StreamParams stream_params_;
426 425
427 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are 426 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are
428 // destroyed by calling call_->DestroyVideoReceiveStream and 427 // destroyed by calling call_->DestroyVideoReceiveStream and
429 // call_->DestroyFlexfecReceiveStream, respectively. 428 // call_->DestroyFlexfecReceiveStream, respectively.
430 webrtc::VideoReceiveStream* stream_; 429 webrtc::VideoReceiveStream* stream_;
431 const bool default_stream_; 430 const bool default_stream_;
432 webrtc::VideoReceiveStream::Config config_; 431 webrtc::VideoReceiveStream::Config config_;
433 webrtc::FlexfecReceiveStream::Config flexfec_config_; 432 webrtc::FlexfecReceiveStream::Config flexfec_config_;
434 webrtc::FlexfecReceiveStream* flexfec_stream_; 433 webrtc::FlexfecReceiveStream* flexfec_stream_;
435 434
436 WebRtcVideoDecoderFactory* const external_decoder_factory_; 435 std::unique_ptr<DecoderFactoryAdapter> decoder_factory_;
437 std::vector<AllocatedDecoder> allocated_decoders_; 436 DecoderMap 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
« no previous file with comments | « webrtc/media/engine/videodecodersoftwarefallbackwrapper_unittest.cc ('k') | webrtc/media/engine/webrtcvideoengine.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698