diff --git a/api/video_codecs/video_encoder_config.h b/api/video_codecs/video_encoder_config.h index 3d1b176738..500ef6fdf2 100644 --- a/api/video_codecs/video_encoder_config.h +++ b/api/video_codecs/video_encoder_config.h @@ -158,6 +158,9 @@ class VideoEncoderConfig { VideoCodecType codec_type; SdpVideoFormat video_format; + // Note: This factory can be unset, and VideoStreamEncoder will + // then use the EncoderStreamFactory. The factory is only set by + // tests. rtc::scoped_refptr video_stream_factory; std::vector spatial_layers; ContentType content_type; @@ -189,6 +192,11 @@ class VideoEncoderConfig { // Indicates whether quality scaling can be used or not. bool is_quality_scaling_allowed; + // Maximum Quantization Parameter. + // This value is fed into EncoderStreamFactory that + // apply it to all simulcast layers/spatial layers. + int max_qp; + private: // Access to the copy constructor is private to force use of the Copy() // method for those exceptional cases where we do use it. diff --git a/media/BUILD.gn b/media/BUILD.gn index 59b8c62944..69f18c29f7 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -331,7 +331,6 @@ rtc_library("rtc_audio_video") { "../rtc_base/third_party/base64", "../system_wrappers", "../system_wrappers:metrics", - "../video/config:streams_config", ] absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", @@ -527,6 +526,7 @@ if (rtc_include_tests) { "../rtc_base/third_party/sigslot", "../test:scoped_key_value_config", "../test:test_support", + "../video/config:streams_config", "//testing/gtest", ] absl_deps = [ diff --git a/media/DEPS b/media/DEPS index 25b8c63723..7ae46d0324 100644 --- a/media/DEPS +++ b/media/DEPS @@ -28,4 +28,7 @@ specific_include_rules = { ".*webrtc_video_engine_unittest\.cc": [ "+video/config", ], + ".*fake_webrtc_call\.cc": [ + "+video/config", + ], } diff --git a/media/engine/fake_webrtc_call.cc b/media/engine/fake_webrtc_call.cc index 52f4965b9e..9fe5cf8337 100644 --- a/media/engine/fake_webrtc_call.cc +++ b/media/engine/fake_webrtc_call.cc @@ -19,6 +19,7 @@ #include "rtc_base/checks.h" #include "rtc_base/gunit.h" #include "rtc_base/thread.h" +#include "video/config/encoder_stream_factory.h" namespace cricket { @@ -241,8 +242,23 @@ void FakeVideoSendStream::OnFrame(const webrtc::VideoFrame& frame) { if (!last_frame_ || frame.width() != last_frame_->width() || frame.height() != last_frame_->height() || frame.rotation() != last_frame_->rotation()) { - video_streams_ = encoder_config_.video_stream_factory->CreateEncoderStreams( - frame.width(), frame.height(), encoder_config_); + if (encoder_config_.video_stream_factory) { + // Note: only tests set their own EncoderStreamFactory... + video_streams_ = + encoder_config_.video_stream_factory->CreateEncoderStreams( + frame.width(), frame.height(), encoder_config_); + } else { + rtc::scoped_refptr< + webrtc::VideoEncoderConfig::VideoStreamFactoryInterface> + factory = rtc::make_ref_counted( + encoder_config_.video_format.name, encoder_config_.max_qp, + encoder_config_.content_type == + webrtc::VideoEncoderConfig::ContentType::kScreen, + encoder_config_.legacy_conference_mode); + + video_streams_ = factory->CreateEncoderStreams( + frame.width(), frame.height(), encoder_config_); + } } last_frame_ = frame; } @@ -265,8 +281,21 @@ void FakeVideoSendStream::ReconfigureVideoEncoder( } else { width = height = 0; } - video_streams_ = - config.video_stream_factory->CreateEncoderStreams(width, height, config); + if (config.video_stream_factory) { + // Note: only tests set their own EncoderStreamFactory... + video_streams_ = config.video_stream_factory->CreateEncoderStreams( + width, height, config); + } else { + rtc::scoped_refptr + factory = rtc::make_ref_counted( + config.video_format.name, config.max_qp, + config.content_type == + webrtc::VideoEncoderConfig::ContentType::kScreen, + config.legacy_conference_mode); + + video_streams_ = factory->CreateEncoderStreams(width, height, config); + } + if (config.encoder_specific_settings != nullptr) { const unsigned char num_temporal_layers = static_cast( video_streams_.back().num_temporal_layers.value_or(1)); diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index f86ac97007..bcefa5b2d2 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -2512,9 +2512,7 @@ WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig( int max_qp = kDefaultQpMax; codec.GetParam(kCodecParamMaxQuantization, &max_qp); - encoder_config.video_stream_factory = - rtc::make_ref_counted( - codec.name, max_qp, is_screencast, parameters_.conference_mode); + encoder_config.max_qp = max_qp; return encoder_config; } diff --git a/media/engine/webrtc_video_engine.h b/media/engine/webrtc_video_engine.h index ec31bf7ae7..eb95fbecd0 100644 --- a/media/engine/webrtc_video_engine.h +++ b/media/engine/webrtc_video_engine.h @@ -37,7 +37,6 @@ #include "rtc_base/synchronization/mutex.h" #include "rtc_base/system/no_unique_address.h" #include "rtc_base/thread_annotations.h" -#include "video/config/encoder_stream_factory.h" namespace webrtc { class VideoDecoderFactory; diff --git a/video/BUILD.gn b/video/BUILD.gn index 7dc15ff5f3..ac603f5e74 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn @@ -434,6 +434,7 @@ rtc_library("video_stream_encoder_impl") { "../system_wrappers:field_trial", "../system_wrappers:metrics", "adaptation:video_adaptation", + "config:streams_config", ] absl_deps = [ "//third_party/abseil-cpp/absl/algorithm:container", diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index 1018df4ea8..046148e06d 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -51,6 +51,7 @@ #include "system_wrappers/include/metrics.h" #include "video/adaptation/video_stream_encoder_resource_manager.h" #include "video/alignment_adjuster.h" +#include "video/config/encoder_stream_factory.h" #include "video/frame_cadence_adapter.h" namespace webrtc { @@ -936,9 +937,22 @@ void VideoStreamEncoder::ReconfigureEncoder() { AlignmentAdjuster::GetAlignmentAndMaybeAdjustScaleFactors( encoder_->GetEncoderInfo(), &encoder_config_, absl::nullopt); - std::vector streams = - encoder_config_.video_stream_factory->CreateEncoderStreams( - last_frame_info_->width, last_frame_info_->height, encoder_config_); + std::vector streams; + if (encoder_config_.video_stream_factory) { + // Note: only tests set their own EncoderStreamFactory... + streams = encoder_config_.video_stream_factory->CreateEncoderStreams( + last_frame_info_->width, last_frame_info_->height, encoder_config_); + } else { + rtc::scoped_refptr + factory = rtc::make_ref_counted( + encoder_config_.video_format.name, encoder_config_.max_qp, + encoder_config_.content_type == + webrtc::VideoEncoderConfig::ContentType::kScreen, + encoder_config_.legacy_conference_mode); + + streams = factory->CreateEncoderStreams( + last_frame_info_->width, last_frame_info_->height, encoder_config_); + } // Get alignment when actual number of layers are known. int alignment = AlignmentAdjuster::GetAlignmentAndMaybeAdjustScaleFactors(