From fb2c888943a627bad265f54b815016115885a7c3 Mon Sep 17 00:00:00 2001 From: Michael Froman Date: Mon, 11 Jul 2022 21:29:26 -0500 Subject: [PATCH] Bug 1766646 - Vendor libwebrtc from c7f691a71a Upstream commit: https://webrtc.googlesource.com/src/+/c7f691a71a0ee3b717e30d1c5f43fdc2c8314769 WebRTC-DeprecateGlobalFieldTrialString/Enabled/ - part 2 convert call/ (and the collaterals) Bug: webrtc:10335 Change-Id: I8f6bc13c032713aa2a947724b464f6f35454d39a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/254320 Reviewed-by: Mirko Bonadei Reviewed-by: Harald Alvestrand Commit-Queue: Jonas Oreland Cr-Commit-Position: refs/heads/main@{#36165} --- third_party/libwebrtc/README.moz-ff-commit | 3 + third_party/libwebrtc/README.mozilla | 2 + third_party/libwebrtc/call/BUILD.gn | 4 +- .../libwebrtc/call/adaptation/BUILD.gn | 2 + .../resource_adaptation_processor_unittest.cc | 5 +- .../call/adaptation/video_stream_adapter.cc | 4 +- .../call/adaptation/video_stream_adapter.h | 4 +- .../video_stream_adapter_unittest.cc | 16 +- third_party/libwebrtc/call/call.cc | 6 +- third_party/libwebrtc/call/rampup_tests.cc | 1 - .../libwebrtc/call/receive_time_calculator.cc | 20 +-- .../libwebrtc/call/receive_time_calculator.h | 9 +- .../call/receive_time_calculator_unittest.cc | 4 +- .../libwebrtc/call/rtp_payload_params.h | 2 +- .../call/rtp_payload_params_unittest.cc | 7 +- .../call/rtp_transport_controller_send.cc | 6 +- .../call/rtp_transport_controller_send.h | 2 + .../libwebrtc/call/rtp_video_sender.cc | 6 +- third_party/libwebrtc/call/rtp_video_sender.h | 7 +- .../call/rtp_video_sender_unittest.cc | 32 ++-- .../libwebrtc/rtc_base/experiments/BUILD.gn | 2 + .../balanced_degradation_settings.cc | 6 +- .../balanced_degradation_settings.h | 3 +- .../balanced_degradation_settings_unittest.cc | 150 +++++++++--------- third_party/libwebrtc/video/BUILD.gn | 3 + .../libwebrtc/video/adaptation/BUILD.gn | 1 + .../video/adaptation/balanced_constraint.cc | 4 +- .../video/adaptation/balanced_constraint.h | 6 +- .../video_stream_encoder_resource_manager.cc | 9 +- .../video_stream_encoder_resource_manager.h | 4 +- .../libwebrtc/video/video_send_stream.cc | 11 +- .../libwebrtc/video/video_send_stream.h | 4 +- .../libwebrtc/video/video_stream_encoder.cc | 10 +- .../libwebrtc/video/video_stream_encoder.h | 4 +- .../video/video_stream_encoder_unittest.cc | 77 +++++---- 35 files changed, 262 insertions(+), 174 deletions(-) diff --git a/third_party/libwebrtc/README.moz-ff-commit b/third_party/libwebrtc/README.moz-ff-commit index 9648ca0fbe56..aabeff6eb1c8 100644 --- a/third_party/libwebrtc/README.moz-ff-commit +++ b/third_party/libwebrtc/README.moz-ff-commit @@ -12033,3 +12033,6 @@ a5f3018c24 # MOZ_LIBWEBRTC_SRC=/home/mfroman/git-checkouts/trial-webrtc-builds/moz-libwebrtc-checkout/src MOZ_LIBWEBRTC_COMMIT=mjfdev bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh # base of lastest vendoring fdaa77cd21 +# MOZ_LIBWEBRTC_SRC=/home/mfroman/git-checkouts/trial-webrtc-builds/moz-libwebrtc-checkout/src MOZ_LIBWEBRTC_COMMIT=mjfdev bash dom/media/webrtc/third_party_build/fast-forward-libwebrtc.sh +# base of lastest vendoring +c7f691a71a diff --git a/third_party/libwebrtc/README.mozilla b/third_party/libwebrtc/README.mozilla index 7a98bfc7da2d..3327c54a4178 100644 --- a/third_party/libwebrtc/README.mozilla +++ b/third_party/libwebrtc/README.mozilla @@ -8032,3 +8032,5 @@ libwebrtc updated from /home/mfroman/git-checkouts/trial-webrtc-builds/moz-libwe libwebrtc updated from /home/mfroman/git-checkouts/trial-webrtc-builds/moz-libwebrtc-checkout/src commit mjfdev on 2022-07-12T02:28:03.768485. # python3 vendor-libwebrtc.py --from-local /home/mfroman/git-checkouts/trial-webrtc-builds/moz-libwebrtc-checkout/src --commit mjfdev libwebrtc libwebrtc updated from /home/mfroman/git-checkouts/trial-webrtc-builds/moz-libwebrtc-checkout/src commit mjfdev on 2022-07-12T02:28:43.027657. +# python3 vendor-libwebrtc.py --from-local /home/mfroman/git-checkouts/trial-webrtc-builds/moz-libwebrtc-checkout/src --commit mjfdev libwebrtc +libwebrtc updated from /home/mfroman/git-checkouts/trial-webrtc-builds/moz-libwebrtc-checkout/src commit mjfdev on 2022-07-12T02:29:21.624439. diff --git a/third_party/libwebrtc/call/BUILD.gn b/third_party/libwebrtc/call/BUILD.gn index ebf50ff86296..14e2d299ed0e 100644 --- a/third_party/libwebrtc/call/BUILD.gn +++ b/third_party/libwebrtc/call/BUILD.gn @@ -178,11 +178,11 @@ rtc_library("rtp_sender") { "../api:rtp_parameters", "../api:sequence_checker", "../api:transport_api", + "../api:webrtc_key_value_config", "../api/rtc_event_log", "../api/transport:field_trial_based_config", "../api/transport:goog_cc", "../api/transport:network_control", - "../api/transport:webrtc_key_value_config", "../api/units:data_rate", "../api/units:time_delta", "../api/units:timestamp", @@ -291,6 +291,7 @@ rtc_library("call") { "../api:sequence_checker", "../api:simulated_network_api", "../api:transport_api", + "../api:webrtc_key_value_config", "../api/rtc_event_log", "../api/transport:network_control", "../api/units:time_delta", @@ -491,6 +492,7 @@ if (rtc_include_tests) { "../test:field_trial", "../test:mock_frame_transformer", "../test:mock_transport", + "../test:scoped_key_value_config", "../test:test_common", "../test:test_support", "../test:video_test_common", diff --git a/third_party/libwebrtc/call/adaptation/BUILD.gn b/third_party/libwebrtc/call/adaptation/BUILD.gn index 10a46a3d434a..4661c3e2f687 100644 --- a/third_party/libwebrtc/call/adaptation/BUILD.gn +++ b/third_party/libwebrtc/call/adaptation/BUILD.gn @@ -35,6 +35,7 @@ rtc_library("resource_adaptation") { "../../api:rtp_parameters", "../../api:scoped_refptr", "../../api:sequence_checker", + "../../api:webrtc_key_value_config", "../../api/adaptation:resource_adaptation_api", "../../api/task_queue:task_queue", "../../api/video:video_adaptation", @@ -86,6 +87,7 @@ if (rtc_include_tests) { "../../rtc_base/synchronization:mutex", "../../test:field_trial", "../../test:rtc_expect_death", + "../../test:scoped_key_value_config", "../../test:test_support", ] absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] diff --git a/third_party/libwebrtc/call/adaptation/resource_adaptation_processor_unittest.cc b/third_party/libwebrtc/call/adaptation/resource_adaptation_processor_unittest.cc index 705223ab71b1..da2bc947b966 100644 --- a/third_party/libwebrtc/call/adaptation/resource_adaptation_processor_unittest.cc +++ b/third_party/libwebrtc/call/adaptation/resource_adaptation_processor_unittest.cc @@ -23,6 +23,7 @@ #include "rtc_base/synchronization/mutex.h" #include "rtc_base/task_queue_for_test.h" #include "test/gtest.h" +#include "test/scoped_key_value_config.h" namespace webrtc { @@ -90,7 +91,8 @@ class ResourceAdaptationProcessorTest : public ::testing::Test { other_resource_(FakeResource::Create("OtherFakeResource")), video_stream_adapter_( std::make_unique(&input_state_provider_, - &frame_rate_provider_)), + &frame_rate_provider_, + field_trials_)), processor_(std::make_unique( video_stream_adapter_.get())) { video_stream_adapter_->AddRestrictionsListener(&restrictions_listener_); @@ -133,6 +135,7 @@ class ResourceAdaptationProcessorTest : public ::testing::Test { } protected: + webrtc::test::ScopedKeyValueConfig field_trials_; FakeFrameRateProvider frame_rate_provider_; VideoStreamInputStateProvider input_state_provider_; rtc::scoped_refptr resource_; diff --git a/third_party/libwebrtc/call/adaptation/video_stream_adapter.cc b/third_party/libwebrtc/call/adaptation/video_stream_adapter.cc index ce1c300a72e8..313bcc33de02 100644 --- a/third_party/libwebrtc/call/adaptation/video_stream_adapter.cc +++ b/third_party/libwebrtc/call/adaptation/video_stream_adapter.cc @@ -203,9 +203,11 @@ const VideoAdaptationCounters& Adaptation::counters() const { VideoStreamAdapter::VideoStreamAdapter( VideoStreamInputStateProvider* input_state_provider, - VideoStreamEncoderObserver* encoder_stats_observer) + VideoStreamEncoderObserver* encoder_stats_observer, + const WebRtcKeyValueConfig& field_trials) : input_state_provider_(input_state_provider), encoder_stats_observer_(encoder_stats_observer), + balanced_settings_(field_trials), adaptation_validation_id_(0), degradation_preference_(DegradationPreference::DISABLED), awaiting_frame_size_change_(absl::nullopt) { diff --git a/third_party/libwebrtc/call/adaptation/video_stream_adapter.h b/third_party/libwebrtc/call/adaptation/video_stream_adapter.h index 7bf424a17e96..a4a52f400a79 100644 --- a/third_party/libwebrtc/call/adaptation/video_stream_adapter.h +++ b/third_party/libwebrtc/call/adaptation/video_stream_adapter.h @@ -21,6 +21,7 @@ #include "api/rtp_parameters.h" #include "api/video/video_adaptation_counters.h" #include "api/video/video_stream_encoder_observer.h" +#include "api/webrtc_key_value_config.h" #include "call/adaptation/adaptation_constraint.h" #include "call/adaptation/degradation_preference_provider.h" #include "call/adaptation/video_source_restrictions.h" @@ -123,7 +124,8 @@ class Adaptation final { class VideoStreamAdapter { public: VideoStreamAdapter(VideoStreamInputStateProvider* input_state_provider, - VideoStreamEncoderObserver* encoder_stats_observer); + VideoStreamEncoderObserver* encoder_stats_observer, + const WebRtcKeyValueConfig& field_trials); ~VideoStreamAdapter(); VideoSourceRestrictions source_restrictions() const; diff --git a/third_party/libwebrtc/call/adaptation/video_stream_adapter_unittest.cc b/third_party/libwebrtc/call/adaptation/video_stream_adapter_unittest.cc index aba9cf1f2951..8f2919425443 100644 --- a/third_party/libwebrtc/call/adaptation/video_stream_adapter_unittest.cc +++ b/third_party/libwebrtc/call/adaptation/video_stream_adapter_unittest.cc @@ -27,9 +27,9 @@ #include "call/adaptation/video_source_restrictions.h" #include "call/adaptation/video_stream_input_state.h" #include "rtc_base/string_encode.h" -#include "test/field_trial.h" #include "test/gmock.h" #include "test/gtest.h" +#include "test/scoped_key_value_config.h" #include "test/testsupport/rtc_expect_death.h" namespace webrtc { @@ -153,10 +153,12 @@ class VideoStreamAdapterTest : public ::testing::Test { VideoStreamAdapterTest() : field_trials_(BalancedFieldTrialConfig()), resource_(FakeResource::Create("FakeResource")), - adapter_(&input_state_provider_, &encoder_stats_observer_) {} + adapter_(&input_state_provider_, + &encoder_stats_observer_, + field_trials_) {} protected: - webrtc::test::ScopedFieldTrials field_trials_; + webrtc::test::ScopedKeyValueConfig field_trials_; FakeVideoStreamInputStateProvider input_state_provider_; rtc::scoped_refptr resource_; testing::StrictMock encoder_stats_observer_; @@ -919,9 +921,11 @@ TEST_F(VideoStreamAdapterTest, AdaptationConstraintDisallowsAdaptationsUp) { TEST(VideoStreamAdapterDeathTest, SetDegradationPreferenceInvalidatesAdaptations) { + webrtc::test::ScopedKeyValueConfig field_trials; FakeVideoStreamInputStateProvider input_state_provider; testing::StrictMock encoder_stats_observer_; - VideoStreamAdapter adapter(&input_state_provider, &encoder_stats_observer_); + VideoStreamAdapter adapter(&input_state_provider, &encoder_stats_observer_, + field_trials); adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE); input_state_provider.SetInputState(1280 * 720, 30, kDefaultMinPixelsPerFrame); Adaptation adaptation = adapter.GetAdaptationDown(); @@ -930,9 +934,11 @@ TEST(VideoStreamAdapterDeathTest, } TEST(VideoStreamAdapterDeathTest, AdaptDownInvalidatesAdaptations) { + webrtc::test::ScopedKeyValueConfig field_trials; FakeVideoStreamInputStateProvider input_state_provider; testing::StrictMock encoder_stats_observer_; - VideoStreamAdapter adapter(&input_state_provider, &encoder_stats_observer_); + VideoStreamAdapter adapter(&input_state_provider, &encoder_stats_observer_, + field_trials); adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION); input_state_provider.SetInputState(1280 * 720, 30, kDefaultMinPixelsPerFrame); Adaptation adaptation = adapter.GetAdaptationDown(); diff --git a/third_party/libwebrtc/call/call.cc b/third_party/libwebrtc/call/call.cc index 53b58fea01d8..8749f9dfaee3 100644 --- a/third_party/libwebrtc/call/call.cc +++ b/third_party/libwebrtc/call/call.cc @@ -812,7 +812,8 @@ Call::Call(Clock* clock, absl::bind_front(&PacketRouter::SendRemb, transport_send->packet_router()), /*network_state_estimator=*/nullptr), - receive_time_calculator_(ReceiveTimeCalculator::CreateFromFieldTrial()), + receive_time_calculator_( + ReceiveTimeCalculator::CreateFromFieldTrial(*config.trials)), video_send_delay_stats_(new SendDelayStats(clock_)), start_of_call_(clock_->CurrentTime()), transport_send_ptr_(transport_send.get()), @@ -1044,7 +1045,8 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream( call_stats_->AsRtcpRttStats(), transport_send_.get(), bitrate_allocator_.get(), video_send_delay_stats_.get(), event_log_, std::move(config), std::move(encoder_config), suspended_video_send_ssrcs_, - suspended_video_payload_states_, std::move(fec_controller)); + suspended_video_payload_states_, std::move(fec_controller), + *config_.trials); for (uint32_t ssrc : ssrcs) { RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); diff --git a/third_party/libwebrtc/call/rampup_tests.cc b/third_party/libwebrtc/call/rampup_tests.cc index abd0f1f34894..999bb5081527 100644 --- a/third_party/libwebrtc/call/rampup_tests.cc +++ b/third_party/libwebrtc/call/rampup_tests.cc @@ -26,7 +26,6 @@ #include "rtc_base/task_queue_for_test.h" #include "rtc_base/time_utils.h" #include "test/encoder_settings.h" -#include "test/field_trial.h" #include "test/gtest.h" #include "test/testsupport/perf_test.h" diff --git a/third_party/libwebrtc/call/receive_time_calculator.cc b/third_party/libwebrtc/call/receive_time_calculator.cc index 94d1fd18cc45..d6ffd39d6d6e 100644 --- a/third_party/libwebrtc/call/receive_time_calculator.cc +++ b/third_party/libwebrtc/call/receive_time_calculator.cc @@ -16,22 +16,20 @@ #include "rtc_base/experiments/field_trial_parser.h" #include "rtc_base/numerics/safe_minmax.h" -#include "system_wrappers/include/field_trial.h" namespace webrtc { namespace { -using ::webrtc::field_trial::IsEnabled; const char kBweReceiveTimeCorrection[] = "WebRTC-Bwe-ReceiveTimeFix"; } // namespace -ReceiveTimeCalculatorConfig::ReceiveTimeCalculatorConfig() +ReceiveTimeCalculatorConfig::ReceiveTimeCalculatorConfig( + const WebRtcKeyValueConfig& field_trials) : max_packet_time_repair("maxrep", TimeDelta::Millis(2000)), stall_threshold("stall", TimeDelta::Millis(5)), tolerance("tol", TimeDelta::Millis(1)), max_stall("maxstall", TimeDelta::Seconds(5)) { - std::string trial_string = - field_trial::FindFullName(kBweReceiveTimeCorrection); + std::string trial_string = field_trials.Lookup(kBweReceiveTimeCorrection); ParseFieldTrial( {&max_packet_time_repair, &stall_threshold, &tolerance, &max_stall}, trial_string); @@ -40,14 +38,16 @@ ReceiveTimeCalculatorConfig::ReceiveTimeCalculatorConfig( const ReceiveTimeCalculatorConfig&) = default; ReceiveTimeCalculatorConfig::~ReceiveTimeCalculatorConfig() = default; -ReceiveTimeCalculator::ReceiveTimeCalculator() - : config_(ReceiveTimeCalculatorConfig()) {} +ReceiveTimeCalculator::ReceiveTimeCalculator( + const WebRtcKeyValueConfig& field_trials) + : config_(field_trials) {} std::unique_ptr -ReceiveTimeCalculator::CreateFromFieldTrial() { - if (!IsEnabled(kBweReceiveTimeCorrection)) +ReceiveTimeCalculator::CreateFromFieldTrial( + const WebRtcKeyValueConfig& field_trials) { + if (!field_trials.IsEnabled(kBweReceiveTimeCorrection)) return nullptr; - return std::make_unique(); + return std::make_unique(field_trials); } int64_t ReceiveTimeCalculator::ReconcileReceiveTimes(int64_t packet_time_us, diff --git a/third_party/libwebrtc/call/receive_time_calculator.h b/third_party/libwebrtc/call/receive_time_calculator.h index 0bd3a82afcfe..276ddda72025 100644 --- a/third_party/libwebrtc/call/receive_time_calculator.h +++ b/third_party/libwebrtc/call/receive_time_calculator.h @@ -15,12 +15,14 @@ #include #include "api/units/time_delta.h" +#include "api/webrtc_key_value_config.h" #include "rtc_base/experiments/field_trial_parser.h" namespace webrtc { struct ReceiveTimeCalculatorConfig { - ReceiveTimeCalculatorConfig(); + explicit ReceiveTimeCalculatorConfig( + const WebRtcKeyValueConfig& field_trials); ReceiveTimeCalculatorConfig(const ReceiveTimeCalculatorConfig&); ReceiveTimeCalculatorConfig& operator=(const ReceiveTimeCalculatorConfig&) = default; @@ -41,8 +43,9 @@ struct ReceiveTimeCalculatorConfig { // is received. class ReceiveTimeCalculator { public: - static std::unique_ptr CreateFromFieldTrial(); - ReceiveTimeCalculator(); + static std::unique_ptr CreateFromFieldTrial( + const WebRtcKeyValueConfig& field_trials); + explicit ReceiveTimeCalculator(const WebRtcKeyValueConfig& field_trials); int64_t ReconcileReceiveTimes(int64_t packet_time_us_, int64_t system_time_us_, int64_t safe_time_us_); diff --git a/third_party/libwebrtc/call/receive_time_calculator_unittest.cc b/third_party/libwebrtc/call/receive_time_calculator_unittest.cc index d18fb1be8b26..f2e3d54f0c1b 100644 --- a/third_party/libwebrtc/call/receive_time_calculator_unittest.cc +++ b/third_party/libwebrtc/call/receive_time_calculator_unittest.cc @@ -21,6 +21,7 @@ #include "rtc_base/random.h" #include "rtc_base/time_utils.h" #include "test/gtest.h" +#include "test/scoped_key_value_config.h" namespace webrtc { namespace test { @@ -168,6 +169,7 @@ class EmulatedNonMonotoneousClock : public EmulatedClock { }; TEST(ClockRepair, NoClockDrift) { + webrtc::test::ScopedKeyValueConfig field_trials; const int kSeeds = 10; const int kFirstSeed = 1; const int64_t kRuntimeUs = 10 * rtc::kNumMicrosecsPerSec; @@ -177,7 +179,7 @@ TEST(ClockRepair, NoClockDrift) { EmulatedMonotoneousClock monotone_clock(seed); EmulatedNonMonotoneousClock non_monotone_clock( seed + 1, kRuntimeUs + rtc::kNumMicrosecsPerSec, kDrift); - ReceiveTimeCalculator reception_time_tracker; + ReceiveTimeCalculator reception_time_tracker(field_trials); int64_t corrected_clock_0 = 0; int64_t reset_during_stall_tol_us = 0; bool initial_clock_stall = true; diff --git a/third_party/libwebrtc/call/rtp_payload_params.h b/third_party/libwebrtc/call/rtp_payload_params.h index 1f03fab6dabe..b1680a9ac04a 100644 --- a/third_party/libwebrtc/call/rtp_payload_params.h +++ b/third_party/libwebrtc/call/rtp_payload_params.h @@ -15,8 +15,8 @@ #include #include "absl/types/optional.h" -#include "api/transport/webrtc_key_value_config.h" #include "api/video_codecs/video_encoder.h" +#include "api/webrtc_key_value_config.h" #include "call/rtp_config.h" #include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor.h" #include "modules/rtp_rtcp/source/rtp_video_header.h" diff --git a/third_party/libwebrtc/call/rtp_payload_params_unittest.cc b/third_party/libwebrtc/call/rtp_payload_params_unittest.cc index 8b22716f4378..b155c4c20481 100644 --- a/third_party/libwebrtc/call/rtp_payload_params_unittest.cc +++ b/third_party/libwebrtc/call/rtp_payload_params_unittest.cc @@ -27,9 +27,9 @@ #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" #include "modules/video_coding/include/video_codec_interface.h" #include "test/explicit_key_value_config.h" -#include "test/field_trial.h" #include "test/gmock.h" #include "test/gtest.h" +#include "test/scoped_key_value_config.h" using ::testing::Each; using ::testing::ElementsAre; @@ -275,8 +275,7 @@ TEST(RtpPayloadParamsTest, Tl0PicIdxUpdatedForVp9) { } TEST(RtpPayloadParamsTest, PictureIdForOldGenericFormat) { - test::ScopedFieldTrials generic_picture_id( - "WebRTC-GenericPictureId/Enabled/"); + test::ScopedKeyValueConfig field_trials("WebRTC-GenericPictureId/Enabled/"); RtpPayloadState state{}; EncodedImage encoded_image; @@ -284,7 +283,7 @@ TEST(RtpPayloadParamsTest, PictureIdForOldGenericFormat) { codec_info.codecType = kVideoCodecGeneric; encoded_image._frameType = VideoFrameType::kVideoFrameKey; - RtpPayloadParams params(kSsrc1, &state, FieldTrialBasedConfig()); + RtpPayloadParams params(kSsrc1, &state, field_trials); RTPVideoHeader header = params.GetRtpVideoHeader(encoded_image, &codec_info, 10); diff --git a/third_party/libwebrtc/call/rtp_transport_controller_send.cc b/third_party/libwebrtc/call/rtp_transport_controller_send.cc index ae962a285e7d..edbdb7846c73 100644 --- a/third_party/libwebrtc/call/rtp_transport_controller_send.cc +++ b/third_party/libwebrtc/call/rtp_transport_controller_send.cc @@ -134,7 +134,8 @@ RtpTransportControllerSend::RtpTransportControllerSend( retransmission_rate_limiter_(clock, kRetransmitWindowSizeMs), task_queue_(task_queue_factory->CreateTaskQueue( "rtp_send_controller", - TaskQueueFactory::Priority::NORMAL)) { + TaskQueueFactory::Priority::NORMAL)), + field_trials_(*trials) { ParseFieldTrial({&relay_bandwidth_cap_}, trials->Lookup("WebRTC-Bwe-NetworkRouteConstraints")); initial_config_.constraints = ConvertConstraints(bitrate_config, clock_); @@ -174,7 +175,8 @@ RtpVideoSenderInterface* RtpTransportControllerSend::CreateRtpVideoSender( // the parts of RtpTransportControllerSendInterface that are really used. this, event_log, &retransmission_rate_limiter_, std::move(fec_controller), frame_encryption_config.frame_encryptor, - frame_encryption_config.crypto_options, std::move(frame_transformer))); + frame_encryption_config.crypto_options, std::move(frame_transformer), + field_trials_)); return video_rtp_senders_.back().get(); } diff --git a/third_party/libwebrtc/call/rtp_transport_controller_send.h b/third_party/libwebrtc/call/rtp_transport_controller_send.h index e5ff162687bc..e45ab21cdade 100644 --- a/third_party/libwebrtc/call/rtp_transport_controller_send.h +++ b/third_party/libwebrtc/call/rtp_transport_controller_send.h @@ -218,6 +218,8 @@ class RtpTransportControllerSend final // `task_queue_` is defined last to ensure all pending tasks are cancelled // and deleted before any other members. rtc::TaskQueue task_queue_; + + const WebRtcKeyValueConfig& field_trials_; }; } // namespace webrtc diff --git a/third_party/libwebrtc/call/rtp_video_sender.cc b/third_party/libwebrtc/call/rtp_video_sender.cc index 35e6beeb7cb1..c5de3a72d98f 100644 --- a/third_party/libwebrtc/call/rtp_video_sender.cc +++ b/third_party/libwebrtc/call/rtp_video_sender.cc @@ -358,8 +358,10 @@ RtpVideoSender::RtpVideoSender( std::unique_ptr fec_controller, FrameEncryptorInterface* frame_encryptor, const CryptoOptions& crypto_options, - rtc::scoped_refptr frame_transformer) - : send_side_bwe_with_overhead_(!absl::StartsWith( + rtc::scoped_refptr frame_transformer, + const WebRtcKeyValueConfig& field_trials) + : field_trials_(field_trials), + send_side_bwe_with_overhead_(!absl::StartsWith( field_trials_.Lookup("WebRTC-SendSideBwe-WithOverhead"), "Disabled")), use_frame_rate_for_overhead_(absl::StartsWith( diff --git a/third_party/libwebrtc/call/rtp_video_sender.h b/third_party/libwebrtc/call/rtp_video_sender.h index 70238045061a..1fa9a8bd1e92 100644 --- a/third_party/libwebrtc/call/rtp_video_sender.h +++ b/third_party/libwebrtc/call/rtp_video_sender.h @@ -23,8 +23,8 @@ #include "api/fec_controller_override.h" #include "api/rtc_event_log/rtc_event_log.h" #include "api/sequence_checker.h" -#include "api/transport/field_trial_based_config.h" #include "api/video_codecs/video_encoder.h" +#include "api/webrtc_key_value_config.h" #include "call/rtp_config.h" #include "call/rtp_payload_params.h" #include "call/rtp_transport_controller_send_interface.h" @@ -85,7 +85,8 @@ class RtpVideoSender : public RtpVideoSenderInterface, std::unique_ptr fec_controller, FrameEncryptorInterface* frame_encryptor, const CryptoOptions& crypto_options, // move inside RtpTransport - rtc::scoped_refptr frame_transformer); + rtc::scoped_refptr frame_transformer, + const WebRtcKeyValueConfig& field_trials); ~RtpVideoSender() override; RtpVideoSender(const RtpVideoSender&) = delete; @@ -166,7 +167,7 @@ class RtpVideoSender : public RtpVideoSenderInterface, DataSize overhead_per_packet, Frequency framerate) const; - const FieldTrialBasedConfig field_trials_; + const WebRtcKeyValueConfig& field_trials_; const bool send_side_bwe_with_overhead_; const bool use_frame_rate_for_overhead_; const bool has_packet_feedback_; diff --git a/third_party/libwebrtc/call/rtp_video_sender_unittest.cc b/third_party/libwebrtc/call/rtp_video_sender_unittest.cc index c47717da7f42..2f2ffb0446cb 100644 --- a/third_party/libwebrtc/call/rtp_video_sender_unittest.cc +++ b/third_party/libwebrtc/call/rtp_video_sender_unittest.cc @@ -24,12 +24,12 @@ #include "modules/video_coding/fec_controller_default.h" #include "modules/video_coding/include/video_codec_interface.h" #include "rtc_base/rate_limiter.h" -#include "test/field_trial.h" #include "test/gmock.h" #include "test/gtest.h" #include "test/mock_frame_transformer.h" #include "test/mock_transport.h" #include "test/scenario/scenario.h" +#include "test/scoped_key_value_config.h" #include "test/time_controller/simulated_time_controller.h" #include "video/send_delay_stats.h" #include "video/send_statistics_proxy.h" @@ -118,7 +118,8 @@ class RtpVideoSenderTestFixture { int payload_type, const std::map& suspended_payload_states, FrameCountObserver* frame_count_observer, - rtc::scoped_refptr frame_transformer) + rtc::scoped_refptr frame_transformer, + const WebRtcKeyValueConfig* field_trials = nullptr) : time_controller_(Timestamp::Millis(1000000)), config_(CreateVideoSendStreamConfig(&transport_, ssrcs, @@ -134,7 +135,7 @@ class RtpVideoSenderTestFixture { bitrate_config_, time_controller_.CreateProcessThread("PacerThread"), time_controller_.GetTaskQueueFactory(), - &field_trials_), + field_trials ? field_trials : &field_trials_), stats_proxy_(time_controller_.GetClock(), config_, VideoEncoderConfig::ContentType::kRealtimeVideo), @@ -150,7 +151,8 @@ class RtpVideoSenderTestFixture { &stats_proxy_, &stats_proxy_, &send_delay_stats_), &transport_controller_, &event_log_, &retransmission_rate_limiter_, std::make_unique(time_controller_.GetClock()), - nullptr, CryptoOptions{}, frame_transformer); + nullptr, CryptoOptions{}, frame_transformer, + field_trials ? *field_trials : field_trials_); } RtpVideoSenderTestFixture( @@ -158,25 +160,29 @@ class RtpVideoSenderTestFixture { const std::vector& rtx_ssrcs, int payload_type, const std::map& suspended_payload_states, - FrameCountObserver* frame_count_observer) + FrameCountObserver* frame_count_observer, + const WebRtcKeyValueConfig* field_trials = nullptr) : RtpVideoSenderTestFixture(ssrcs, rtx_ssrcs, payload_type, suspended_payload_states, frame_count_observer, - /*frame_transformer=*/nullptr) {} + /*frame_transformer=*/nullptr, + field_trials) {} RtpVideoSenderTestFixture( const std::vector& ssrcs, const std::vector& rtx_ssrcs, int payload_type, - const std::map& suspended_payload_states) + const std::map& suspended_payload_states, + const WebRtcKeyValueConfig* field_trials = nullptr) : RtpVideoSenderTestFixture(ssrcs, rtx_ssrcs, payload_type, suspended_payload_states, /*frame_count_observer=*/nullptr, - /*frame_transformer=*/nullptr) {} + /*frame_transformer=*/nullptr, + field_trials) {} ~RtpVideoSenderTestFixture() { SetActive(false); } @@ -206,6 +212,7 @@ class RtpVideoSenderTestFixture { } private: + test::ScopedKeyValueConfig field_trials_; NiceMock transport_; NiceMock encoder_feedback_; GlobalSimulatedTimeController time_controller_; @@ -213,7 +220,6 @@ class RtpVideoSenderTestFixture { VideoSendStream::Config config_; SendDelayStats send_delay_stats_; BitrateConstraints bitrate_config_; - const FieldTrialBasedConfig field_trials_; RtpTransportControllerSend transport_controller_; SendStatisticsProxy stats_proxy_; RateLimiter retransmission_rate_limiter_; @@ -849,9 +855,9 @@ TEST(RtpVideoSenderTest, } TEST(RtpVideoSenderTest, GenerateDependecyDescriptorForGenericCodecs) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( "WebRTC-GenericCodecDependencyDescriptor/Enabled/"); - RtpVideoSenderTestFixture test({kSsrc1}, {}, kPayloadType, {}); + RtpVideoSenderTestFixture test({kSsrc1}, {}, kPayloadType, {}, &field_trials); test.SetActive(true); RtpHeaderExtensionMap extensions; @@ -1031,7 +1037,7 @@ TEST(RtpVideoSenderTest, SimulcastSenderRegistersFrameTransformers) { } TEST(RtpVideoSenderTest, OverheadIsSubtractedFromTargetBitrate) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( "WebRTC-Video-UseFrameRateForOverhead/Enabled/"); // TODO(jakobi): RTP header size should not be hard coded. @@ -1039,7 +1045,7 @@ TEST(RtpVideoSenderTest, OverheadIsSubtractedFromTargetBitrate) { constexpr uint32_t kTransportPacketOverheadBytes = 40; constexpr uint32_t kOverheadPerPacketBytes = kRtpHeaderSizeBytes + kTransportPacketOverheadBytes; - RtpVideoSenderTestFixture test({kSsrc1}, {}, kPayloadType, {}); + RtpVideoSenderTestFixture test({kSsrc1}, {}, kPayloadType, {}, &field_trials); test.router()->OnTransportOverheadChanged(kTransportPacketOverheadBytes); test.SetActive(true); diff --git a/third_party/libwebrtc/rtc_base/experiments/BUILD.gn b/third_party/libwebrtc/rtc_base/experiments/BUILD.gn index 56d500086969..b9d24ca6cc34 100644 --- a/third_party/libwebrtc/rtc_base/experiments/BUILD.gn +++ b/third_party/libwebrtc/rtc_base/experiments/BUILD.gn @@ -126,6 +126,7 @@ rtc_library("balanced_degradation_settings") { deps = [ ":field_trial_parser", "../:rtc_base_approved", + "../../api:webrtc_key_value_config", "../../api/video_codecs:video_codecs_api", "../../system_wrappers:field_trial", ] @@ -291,6 +292,7 @@ if (rtc_include_tests && !build_with_chromium) { "../../api/video_codecs:video_codecs_api", "../../system_wrappers:field_trial", "../../test:field_trial", + "../../test:scoped_key_value_config", "../../test:test_main", "../../test:test_support", ] diff --git a/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings.cc b/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings.cc index 90d44efb10f6..7cd1a675d42b 100644 --- a/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings.cc +++ b/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings.cc @@ -15,7 +15,6 @@ #include "rtc_base/experiments/field_trial_list.h" #include "rtc_base/experiments/field_trial_parser.h" #include "rtc_base/logging.h" -#include "system_wrappers/include/field_trial.h" namespace webrtc { namespace { @@ -332,7 +331,8 @@ BalancedDegradationSettings::Config::Config(int pixels, av1(av1), generic(generic) {} -BalancedDegradationSettings::BalancedDegradationSettings() { +BalancedDegradationSettings::BalancedDegradationSettings( + const WebRtcKeyValueConfig& field_trials) { FieldTrialStructList configs( {FieldTrialStructMember("pixels", [](Config* c) { return &c->pixels; }), FieldTrialStructMember("fps", [](Config* c) { return &c->fps; }), @@ -390,7 +390,7 @@ BalancedDegradationSettings::BalancedDegradationSettings() { [](Config* c) { return &c->generic.kbps_res; })}, {}); - ParseFieldTrial({&configs}, field_trial::FindFullName(kFieldTrial)); + ParseFieldTrial({&configs}, field_trials.Lookup(kFieldTrial)); configs_ = GetValidOrDefault(configs.Get()); RTC_DCHECK_GT(configs_.size(), 1); diff --git a/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings.h b/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings.h index 0b2f2f5993aa..8255547cd0d6 100644 --- a/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings.h +++ b/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings.h @@ -15,6 +15,7 @@ #include "absl/types/optional.h" #include "api/video_codecs/video_encoder.h" +#include "api/webrtc_key_value_config.h" namespace webrtc { @@ -22,7 +23,7 @@ class BalancedDegradationSettings { public: static constexpr int kNoFpsDiff = -100; - BalancedDegradationSettings(); + BalancedDegradationSettings(const WebRtcKeyValueConfig& field_trials); ~BalancedDegradationSettings(); struct CodecTypeSpecific { diff --git a/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings_unittest.cc b/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings_unittest.cc index 92833ee98ce1..a32dbb4aaa61 100644 --- a/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings_unittest.cc +++ b/third_party/libwebrtc/rtc_base/experiments/balanced_degradation_settings_unittest.cc @@ -13,8 +13,8 @@ #include #include "rtc_base/gunit.h" -#include "test/field_trial.h" #include "test/gmock.h" +#include "test/scoped_key_value_config.h" namespace webrtc { namespace { @@ -59,8 +59,8 @@ void VerifyIsDefault( } // namespace TEST(BalancedDegradationSettings, GetsDefaultConfigIfNoList) { - webrtc::test::ScopedFieldTrials field_trials(""); - BalancedDegradationSettings settings; + webrtc::test::ScopedKeyValueConfig field_trials(""); + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); EXPECT_TRUE(settings.CanAdaptUp(kVideoCodecVP8, 1, /*bitrate_bps*/ 1)); EXPECT_TRUE( @@ -75,10 +75,10 @@ TEST(BalancedDegradationSettings, GetsDefaultConfigIfNoList) { } TEST(BalancedDegradationSettings, GetsConfig) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:11|22|33,fps:5|15|25,other:4|5|6/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_THAT(settings.GetConfigs(), ::testing::ElementsAre( BalancedDegradationSettings::Config{ @@ -117,35 +117,35 @@ TEST(BalancedDegradationSettings, GetsConfig) { } TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroFpsValue) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:0|15|25/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigIfPixelsDecreases) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|999|3000,fps:5|15|25/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigIfFramerateDecreases) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|4|25/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsConfigWithSpecificFps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|8|9,vp9_fps:9|10|11," "h264_fps:11|12|13,av1_fps:1|2|3,generic_fps:13|14|15/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_THAT(settings.GetConfigs(), ::testing::ElementsAre( BalancedDegradationSettings::Config{ @@ -184,34 +184,34 @@ TEST(BalancedDegradationSettings, GetsConfigWithSpecificFps) { } TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroVp8FpsValue) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:7|15|25,vp8_fps:0|15|25/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigForInvalidFpsValue) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:7|15|25,vp8_fps:10|15|2000/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigIfVp8FramerateDecreases) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:4|5|25,vp8_fps:5|4|25/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsMinFps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(5, settings.MinFps(kVideoCodecVP8, 1)); EXPECT_EQ(5, settings.MinFps(kVideoCodecVP8, 1000)); EXPECT_EQ(15, settings.MinFps(kVideoCodecVP8, 1001)); @@ -223,10 +223,10 @@ TEST(BalancedDegradationSettings, GetsMinFps) { } TEST(BalancedDegradationSettings, GetsVp8MinFps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|10|12/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(7, settings.MinFps(kVideoCodecVP8, 1)); EXPECT_EQ(7, settings.MinFps(kVideoCodecVP8, 1000)); EXPECT_EQ(10, settings.MinFps(kVideoCodecVP8, 1001)); @@ -238,10 +238,10 @@ TEST(BalancedDegradationSettings, GetsVp8MinFps) { } TEST(BalancedDegradationSettings, GetsMaxFps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(15, settings.MaxFps(kVideoCodecVP8, 1)); EXPECT_EQ(15, settings.MaxFps(kVideoCodecVP8, 1000)); EXPECT_EQ(25, settings.MaxFps(kVideoCodecVP8, 1001)); @@ -251,10 +251,10 @@ TEST(BalancedDegradationSettings, GetsMaxFps) { } TEST(BalancedDegradationSettings, GetsVp8MaxFps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,vp8_fps:7|10|12/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP8, 1)); EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP8, 1000)); EXPECT_EQ(12, settings.MaxFps(kVideoCodecVP8, 1001)); @@ -264,39 +264,39 @@ TEST(BalancedDegradationSettings, GetsVp8MaxFps) { } TEST(BalancedDegradationSettings, GetsVp9Fps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,vp9_fps:7|10|12/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(7, settings.MinFps(kVideoCodecVP9, 1000)); EXPECT_EQ(10, settings.MaxFps(kVideoCodecVP9, 1000)); } TEST(BalancedDegradationSettings, GetsH264Fps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,h264_fps:8|11|13/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(11, settings.MinFps(kVideoCodecH264, 2000)); EXPECT_EQ(13, settings.MaxFps(kVideoCodecH264, 2000)); } TEST(BalancedDegradationSettings, GetsGenericFps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,generic_fps:9|12|14/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(14, settings.MinFps(kVideoCodecGeneric, 3000)); EXPECT_EQ(std::numeric_limits::max(), settings.MaxFps(kVideoCodecGeneric, 3000)); } TEST(BalancedDegradationSettings, GetsUnlimitedForMaxValidFps) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|100,vp8_fps:30|100|100/"); const int kUnlimitedFps = std::numeric_limits::max(); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(15, settings.MinFps(kVideoCodecH264, 2000)); EXPECT_EQ(kUnlimitedFps, settings.MinFps(kVideoCodecH264, 2001)); EXPECT_EQ(30, settings.MinFps(kVideoCodecVP8, 1000)); @@ -304,7 +304,7 @@ TEST(BalancedDegradationSettings, GetsUnlimitedForMaxValidFps) { } TEST(BalancedDegradationSettings, GetsConfigWithBitrate) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:11|22|33,fps:5|15|25,kbps:44|88|99,kbps_res:55|111|222," "vp8_kbps:11|12|13,vp8_kbps_res:14|15|16," @@ -312,7 +312,7 @@ TEST(BalancedDegradationSettings, GetsConfigWithBitrate) { "h264_kbps:31|32|33,h264_kbps_res:34|35|36," "av1_kbps:41|42|43,av1_kbps_res:44|45|46," "generic_kbps:51|52|53,generic_kbps_res:54|55|56/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_THAT(settings.GetConfigs(), ::testing::ElementsAre( BalancedDegradationSettings::Config{ @@ -351,29 +351,29 @@ TEST(BalancedDegradationSettings, GetsConfigWithBitrate) { } TEST(BalancedDegradationSettings, GetsDefaultConfigIfBitrateDecreases) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:11|22|33,fps:5|15|25,kbps:44|43|99/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigIfBitrateDecreasesWithUnsetValue) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:11|22|33,fps:5|15|25,kbps:44|0|43/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, CanAdaptUp) { VideoCodecType vp8 = kVideoCodecVP8; - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000|4000,fps:5|15|25|30,kbps:0|80|0|90," "vp9_kbps:40|50|60|70/"); - BalancedDegradationSettings s; + BalancedDegradationSettings s(field_trials); EXPECT_TRUE(s.CanAdaptUp(vp8, 1000, 0)); // No bitrate provided. EXPECT_FALSE(s.CanAdaptUp(vp8, 1000, 79000)); EXPECT_TRUE(s.CanAdaptUp(vp8, 1000, 80000)); @@ -384,12 +384,12 @@ TEST(BalancedDegradationSettings, CanAdaptUp) { } TEST(BalancedDegradationSettings, CanAdaptUpWithCodecType) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000|4000,fps:5|15|25|30,vp8_kbps:0|30|40|50," "vp9_kbps:0|60|70|80,h264_kbps:0|55|65|75,av1_kbps:0|77|88|99," "generic_kbps:0|25|35|45/"); - BalancedDegradationSettings s; + BalancedDegradationSettings s(field_trials); EXPECT_FALSE(s.CanAdaptUp(kVideoCodecVP8, 1000, 29000)); EXPECT_TRUE(s.CanAdaptUp(kVideoCodecVP8, 1000, 30000)); EXPECT_FALSE(s.CanAdaptUp(kVideoCodecVP9, 1000, 59000)); @@ -405,11 +405,11 @@ TEST(BalancedDegradationSettings, CanAdaptUpWithCodecType) { TEST(BalancedDegradationSettings, CanAdaptUpResolution) { VideoCodecType vp8 = kVideoCodecVP8; - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000|4000,fps:5|15|25|30,kbps_res:0|80|0|90," "vp9_kbps_res:40|50|60|70/"); - BalancedDegradationSettings s; + BalancedDegradationSettings s(field_trials); EXPECT_TRUE(s.CanAdaptUpResolution(vp8, 1000, 0)); // No bitrate provided. EXPECT_FALSE(s.CanAdaptUpResolution(vp8, 1000, 79000)); EXPECT_TRUE(s.CanAdaptUpResolution(vp8, 1000, 80000)); @@ -420,12 +420,12 @@ TEST(BalancedDegradationSettings, CanAdaptUpResolution) { } TEST(BalancedDegradationSettings, CanAdaptUpResolutionWithCodecType) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000|4000,fps:5|15|25|30,vp8_kbps_res:0|30|40|50," "vp9_kbps_res:0|60|70|80,h264_kbps_res:0|55|65|75," "av1_kbps_res:0|77|88|99,generic_kbps_res:0|25|35|45/"); - BalancedDegradationSettings s; + BalancedDegradationSettings s(field_trials); EXPECT_FALSE(s.CanAdaptUpResolution(kVideoCodecVP8, 1000, 29000)); EXPECT_TRUE(s.CanAdaptUpResolution(kVideoCodecVP8, 1000, 30000)); EXPECT_FALSE(s.CanAdaptUpResolution(kVideoCodecVP9, 1000, 59000)); @@ -441,10 +441,10 @@ TEST(BalancedDegradationSettings, CanAdaptUpResolutionWithCodecType) { } TEST(BalancedDegradationSettings, GetsFpsDiff) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,fps_diff:0|-2|3/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(0, settings.MinFpsDiff(1)); EXPECT_EQ(0, settings.MinFpsDiff(1000)); EXPECT_EQ(-2, settings.MinFpsDiff(1001)); @@ -455,21 +455,21 @@ TEST(BalancedDegradationSettings, GetsFpsDiff) { } TEST(BalancedDegradationSettings, GetsNoFpsDiffIfValueBelowMinSetting) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,fps_diff:-100|-99|-101/"); // Min valid fps_diff setting: -99. - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_FALSE(settings.MinFpsDiff(1000)); EXPECT_EQ(-99, settings.MinFpsDiff(2000)); EXPECT_FALSE(settings.MinFpsDiff(3000)); } TEST(BalancedDegradationSettings, QpThresholdsNotSetByDefault) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP8, 1)); EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecVP9, 1)); EXPECT_FALSE(settings.GetQpThresholds(kVideoCodecH264, 1)); @@ -478,13 +478,13 @@ TEST(BalancedDegradationSettings, QpThresholdsNotSetByDefault) { } TEST(BalancedDegradationSettings, GetsConfigWithQpThresholds) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88," "vp8_qp_high:90|91|92,vp9_qp_low:27|28|29,vp9_qp_high:120|130|140," "h264_qp_low:12|13|14,h264_qp_high:20|30|40,av1_qp_low:2|3|4," "av1_qp_high:11|33|44,generic_qp_low:7|6|5,generic_qp_high:22|23|24/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_THAT(settings.GetConfigs(), ::testing::ElementsAre( BalancedDegradationSettings::Config{ @@ -523,54 +523,54 @@ TEST(BalancedDegradationSettings, GetsConfigWithQpThresholds) { } TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasLowThreshold) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_low:89|90|88/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigIfOnlyHasHighThreshold) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25,vp8_qp_high:90|91|92/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowEqualsHigh) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25," "vp8_qp_low:89|90|88,vp8_qp_high:90|91|88/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigIfLowGreaterThanHigh) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25," "vp8_qp_low:89|90|88,vp8_qp_high:90|91|87/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsDefaultConfigForZeroQpValue) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25," "vp8_qp_low:89|0|88,vp8_qp_high:90|91|92/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); VerifyIsDefault(settings.GetConfigs()); } TEST(BalancedDegradationSettings, GetsVp8QpThresholds) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25," "vp8_qp_low:89|90|88,vp8_qp_high:90|91|92/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); EXPECT_EQ(89, settings.GetQpThresholds(kVideoCodecVP8, 1)->low); EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1)->high); EXPECT_EQ(90, settings.GetQpThresholds(kVideoCodecVP8, 1000)->high); @@ -582,11 +582,11 @@ TEST(BalancedDegradationSettings, GetsVp8QpThresholds) { } TEST(BalancedDegradationSettings, GetsVp9QpThresholds) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25," "vp9_qp_low:55|56|57,vp9_qp_high:155|156|157/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); const auto thresholds = settings.GetQpThresholds(kVideoCodecVP9, 1000); EXPECT_TRUE(thresholds); EXPECT_EQ(55, thresholds->low); @@ -594,11 +594,11 @@ TEST(BalancedDegradationSettings, GetsVp9QpThresholds) { } TEST(BalancedDegradationSettings, GetsH264QpThresholds) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25," "h264_qp_low:21|22|23,h264_qp_high:41|43|42/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); const auto thresholds = settings.GetQpThresholds(kVideoCodecH264, 2000); EXPECT_TRUE(thresholds); EXPECT_EQ(22, thresholds->low); @@ -606,11 +606,11 @@ TEST(BalancedDegradationSettings, GetsH264QpThresholds) { } TEST(BalancedDegradationSettings, GetsGenericQpThresholds) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( "WebRTC-Video-BalancedDegradationSettings/" "pixels:1000|2000|3000,fps:5|15|25," "generic_qp_low:2|3|4,generic_qp_high:22|23|24/"); - BalancedDegradationSettings settings; + BalancedDegradationSettings settings(field_trials); const auto thresholds = settings.GetQpThresholds(kVideoCodecGeneric, 3000); EXPECT_TRUE(thresholds); EXPECT_EQ(4, thresholds->low); diff --git a/third_party/libwebrtc/video/BUILD.gn b/third_party/libwebrtc/video/BUILD.gn index b3e430c778da..9c8f9042c5a8 100644 --- a/third_party/libwebrtc/video/BUILD.gn +++ b/third_party/libwebrtc/video/BUILD.gn @@ -67,6 +67,7 @@ rtc_library("video") { "../api:scoped_refptr", "../api:sequence_checker", "../api:transport_api", + "../api:webrtc_key_value_config", "../api/crypto:frame_decryptor_interface", "../api/crypto:options", "../api/rtc_event_log", @@ -429,6 +430,7 @@ rtc_library("video_stream_encoder_impl") { ":frame_cadence_adapter", "../api:rtp_parameters", "../api:sequence_checker", + "../api:webrtc_key_value_config", "../api/adaptation:resource_adaptation_api", "../api/task_queue:task_queue", "../api/units:data_rate", @@ -902,6 +904,7 @@ if (rtc_include_tests) { "../test:null_transport", "../test:perf_test", "../test:rtp_test_utils", + "../test:scoped_key_value_config", "../test:test_common", "../test:test_support", "../test:video_test_common", diff --git a/third_party/libwebrtc/video/adaptation/BUILD.gn b/third_party/libwebrtc/video/adaptation/BUILD.gn index 11962c04e3b7..84e6a3250f5a 100644 --- a/third_party/libwebrtc/video/adaptation/BUILD.gn +++ b/third_party/libwebrtc/video/adaptation/BUILD.gn @@ -36,6 +36,7 @@ rtc_library("video_adaptation") { "../../api:rtp_parameters", "../../api:scoped_refptr", "../../api:sequence_checker", + "../../api:webrtc_key_value_config", "../../api/adaptation:resource_adaptation_api", "../../api/task_queue:task_queue", "../../api/units:data_rate", diff --git a/third_party/libwebrtc/video/adaptation/balanced_constraint.cc b/third_party/libwebrtc/video/adaptation/balanced_constraint.cc index ec0b8e41d584..2a5484084edb 100644 --- a/third_party/libwebrtc/video/adaptation/balanced_constraint.cc +++ b/third_party/libwebrtc/video/adaptation/balanced_constraint.cc @@ -19,8 +19,10 @@ namespace webrtc { BalancedConstraint::BalancedConstraint( - DegradationPreferenceProvider* degradation_preference_provider) + DegradationPreferenceProvider* degradation_preference_provider, + const WebRtcKeyValueConfig& field_trials) : encoder_target_bitrate_bps_(absl::nullopt), + balanced_settings_(field_trials), degradation_preference_provider_(degradation_preference_provider) { RTC_DCHECK(degradation_preference_provider_); sequence_checker_.Detach(); diff --git a/third_party/libwebrtc/video/adaptation/balanced_constraint.h b/third_party/libwebrtc/video/adaptation/balanced_constraint.h index 0bbd67040868..ba465ab69949 100644 --- a/third_party/libwebrtc/video/adaptation/balanced_constraint.h +++ b/third_party/libwebrtc/video/adaptation/balanced_constraint.h @@ -15,6 +15,7 @@ #include "absl/types/optional.h" #include "api/sequence_checker.h" +#include "api/webrtc_key_value_config.h" #include "call/adaptation/adaptation_constraint.h" #include "call/adaptation/degradation_preference_provider.h" #include "rtc_base/experiments/balanced_degradation_settings.h" @@ -24,8 +25,9 @@ namespace webrtc { class BalancedConstraint : public AdaptationConstraint { public: - explicit BalancedConstraint( - DegradationPreferenceProvider* degradation_preference_provider); + BalancedConstraint( + DegradationPreferenceProvider* degradation_preference_provider, + const WebRtcKeyValueConfig& field_trials); ~BalancedConstraint() override = default; void OnEncoderTargetBitrateUpdated( diff --git a/third_party/libwebrtc/video/adaptation/video_stream_encoder_resource_manager.cc b/third_party/libwebrtc/video/adaptation/video_stream_encoder_resource_manager.cc index 2847cdbb8355..cb2ab144edbe 100644 --- a/third_party/libwebrtc/video/adaptation/video_stream_encoder_resource_manager.cc +++ b/third_party/libwebrtc/video/adaptation/video_stream_encoder_resource_manager.cc @@ -266,11 +266,13 @@ VideoStreamEncoderResourceManager::VideoStreamEncoderResourceManager( Clock* clock, bool experiment_cpu_load_estimator, std::unique_ptr overuse_detector, - DegradationPreferenceProvider* degradation_preference_provider) + DegradationPreferenceProvider* degradation_preference_provider, + const WebRtcKeyValueConfig& field_trials) : degradation_preference_provider_(degradation_preference_provider), bitrate_constraint_(std::make_unique()), - balanced_constraint_(std::make_unique( - degradation_preference_provider_)), + balanced_constraint_( + std::make_unique(degradation_preference_provider_, + field_trials)), encode_usage_resource_( EncodeUsageResource::Create(std::move(overuse_detector))), quality_scaler_resource_(QualityScalerResource::Create()), @@ -283,6 +285,7 @@ VideoStreamEncoderResourceManager::VideoStreamEncoderResourceManager( encoder_stats_observer_(encoder_stats_observer), degradation_preference_(DegradationPreference::DISABLED), video_source_restrictions_(), + balanced_settings_(field_trials), clock_(clock), experiment_cpu_load_estimator_(experiment_cpu_load_estimator), initial_frame_dropper_( diff --git a/third_party/libwebrtc/video/adaptation/video_stream_encoder_resource_manager.h b/third_party/libwebrtc/video/adaptation/video_stream_encoder_resource_manager.h index 26b8db3ffaf9..223af4e8014e 100644 --- a/third_party/libwebrtc/video/adaptation/video_stream_encoder_resource_manager.h +++ b/third_party/libwebrtc/video/adaptation/video_stream_encoder_resource_manager.h @@ -32,6 +32,7 @@ #include "api/video_codecs/video_codec.h" #include "api/video_codecs/video_encoder.h" #include "api/video_codecs/video_encoder_config.h" +#include "api/webrtc_key_value_config.h" #include "call/adaptation/resource_adaptation_processor_interface.h" #include "call/adaptation/video_stream_adapter.h" #include "call/adaptation/video_stream_input_state_provider.h" @@ -79,7 +80,8 @@ class VideoStreamEncoderResourceManager Clock* clock, bool experiment_cpu_load_estimator, std::unique_ptr overuse_detector, - DegradationPreferenceProvider* degradation_preference_provider); + DegradationPreferenceProvider* degradation_preference_provider, + const WebRtcKeyValueConfig& field_trials); ~VideoStreamEncoderResourceManager() override; void Initialize(rtc::TaskQueue* encoder_queue); diff --git a/third_party/libwebrtc/video/video_send_stream.cc b/third_party/libwebrtc/video/video_send_stream.cc index e78211be362c..8ab33dea68b8 100644 --- a/third_party/libwebrtc/video/video_send_stream.cc +++ b/third_party/libwebrtc/video/video_send_stream.cc @@ -114,7 +114,8 @@ std::unique_ptr CreateVideoStreamEncoder( SendStatisticsProxy* stats_proxy, const VideoStreamEncoderSettings& encoder_settings, VideoStreamEncoder::BitrateAllocationCallbackType - bitrate_allocation_callback_type) { + bitrate_allocation_callback_type, + const WebRtcKeyValueConfig& field_trials) { std::unique_ptr encoder_queue = task_queue_factory->CreateTaskQueue("EncoderQueue", TaskQueueFactory::Priority::NORMAL); @@ -123,7 +124,7 @@ std::unique_ptr CreateVideoStreamEncoder( clock, num_cpu_cores, stats_proxy, encoder_settings, std::make_unique(stats_proxy), FrameCadenceAdapterInterface::Create(clock, encoder_queue_ptr), - std::move(encoder_queue), bitrate_allocation_callback_type); + std::move(encoder_queue), bitrate_allocation_callback_type, field_trials); } } // namespace @@ -144,7 +145,8 @@ VideoSendStream::VideoSendStream( VideoEncoderConfig encoder_config, const std::map& suspended_ssrcs, const std::map& suspended_payload_states, - std::unique_ptr fec_controller) + std::unique_ptr fec_controller, + const WebRtcKeyValueConfig& field_trials) : rtp_transport_queue_(transport->GetWorkerQueue()), transport_(transport), stats_proxy_(clock, config, encoder_config.content_type), @@ -156,7 +158,8 @@ VideoSendStream::VideoSendStream( task_queue_factory, &stats_proxy_, config_.encoder_settings, - GetBitrateAllocationCallbackType(config_))), + GetBitrateAllocationCallbackType(config_), + field_trials)), encoder_feedback_( clock, config_.rtp.ssrcs, diff --git a/third_party/libwebrtc/video/video_send_stream.h b/third_party/libwebrtc/video/video_send_stream.h index 62e3c1401c1f..bb777c16a568 100644 --- a/third_party/libwebrtc/video/video_send_stream.h +++ b/third_party/libwebrtc/video/video_send_stream.h @@ -18,6 +18,7 @@ #include "api/fec_controller.h" #include "api/sequence_checker.h" #include "api/video/video_stream_encoder_interface.h" +#include "api/webrtc_key_value_config.h" #include "call/bitrate_allocator.h" #include "call/video_receive_stream.h" #include "call/video_send_stream.h" @@ -67,7 +68,8 @@ class VideoSendStream : public webrtc::VideoSendStream { VideoEncoderConfig encoder_config, const std::map& suspended_ssrcs, const std::map& suspended_payload_states, - std::unique_ptr fec_controller); + std::unique_ptr fec_controller, + const WebRtcKeyValueConfig& field_trials); ~VideoSendStream() override; diff --git a/third_party/libwebrtc/video/video_stream_encoder.cc b/third_party/libwebrtc/video/video_stream_encoder.cc index 147e0110bd9d..4c5975945b03 100644 --- a/third_party/libwebrtc/video/video_stream_encoder.cc +++ b/third_party/libwebrtc/video/video_stream_encoder.cc @@ -30,6 +30,7 @@ #include "api/video/video_layers_allocation.h" #include "api/video_codecs/sdp_video_format.h" #include "api/video_codecs/video_encoder.h" +#include "api/webrtc_key_value_config.h" #include "call/adaptation/resource_adaptation_processor.h" #include "call/adaptation/video_stream_adapter.h" #include "modules/video_coding/include/video_codec_initializer.h" @@ -597,7 +598,8 @@ VideoStreamEncoder::VideoStreamEncoder( std::unique_ptr frame_cadence_adapter, std::unique_ptr encoder_queue, - BitrateAllocationCallbackType allocation_cb_type) + BitrateAllocationCallbackType allocation_cb_type, + const WebRtcKeyValueConfig& field_trials) : worker_queue_(TaskQueueBase::Current()), number_of_cores_(number_of_cores), sink_(nullptr), @@ -645,7 +647,8 @@ VideoStreamEncoder::VideoStreamEncoder( input_state_provider_(encoder_stats_observer), video_stream_adapter_( std::make_unique(&input_state_provider_, - encoder_stats_observer)), + encoder_stats_observer, + field_trials)), degradation_preference_manager_( std::make_unique( video_stream_adapter_.get())), @@ -655,7 +658,8 @@ VideoStreamEncoder::VideoStreamEncoder( clock_, settings_.experiment_cpu_load_estimator, std::move(overuse_detector), - degradation_preference_manager_.get()), + degradation_preference_manager_.get(), + field_trials), video_source_sink_controller_(/*sink=*/frame_cadence_adapter_.get(), /*source=*/nullptr), default_limits_allowed_( diff --git a/third_party/libwebrtc/video/video_stream_encoder.h b/third_party/libwebrtc/video/video_stream_encoder.h index c667f049f82b..e89ba4a31c1e 100644 --- a/third_party/libwebrtc/video/video_stream_encoder.h +++ b/third_party/libwebrtc/video/video_stream_encoder.h @@ -28,6 +28,7 @@ #include "api/video/video_stream_encoder_settings.h" #include "api/video_codecs/video_codec.h" #include "api/video_codecs/video_encoder.h" +#include "api/webrtc_key_value_config.h" #include "call/adaptation/adaptation_constraint.h" #include "call/adaptation/resource_adaptation_processor.h" #include "call/adaptation/resource_adaptation_processor_interface.h" @@ -79,7 +80,8 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface, std::unique_ptr frame_cadence_adapter, std::unique_ptr encoder_queue, - BitrateAllocationCallbackType allocation_cb_type); + BitrateAllocationCallbackType allocation_cb_type, + const WebRtcKeyValueConfig& field_trials); ~VideoStreamEncoder() override; VideoStreamEncoder(const VideoStreamEncoder&) = delete; diff --git a/third_party/libwebrtc/video/video_stream_encoder_unittest.cc b/third_party/libwebrtc/video/video_stream_encoder_unittest.cc index aea1988df9f7..03ee684cd8e0 100644 --- a/third_party/libwebrtc/video/video_stream_encoder_unittest.cc +++ b/third_party/libwebrtc/video/video_stream_encoder_unittest.cc @@ -55,15 +55,14 @@ #include "rtc_base/logging.h" #include "rtc_base/ref_counted_object.h" #include "rtc_base/synchronization/mutex.h" -#include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/metrics.h" #include "test/encoder_settings.h" #include "test/fake_encoder.h" -#include "test/field_trial.h" #include "test/frame_forwarder.h" #include "test/gmock.h" #include "test/gtest.h" #include "test/mappable_native_buffer.h" +#include "test/scoped_key_value_config.h" #include "test/time_controller/simulated_time_controller.h" #include "test/video_encoder_proxy_factory.h" #include "video/frame_cadence_adapter.h" @@ -375,7 +374,8 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder { SendStatisticsProxy* stats_proxy, const VideoStreamEncoderSettings& settings, VideoStreamEncoder::BitrateAllocationCallbackType - allocation_callback_type) + allocation_callback_type, + const WebRtcKeyValueConfig& field_trials) : VideoStreamEncoder(time_controller->GetClock(), 1 /* number_of_cores */, stats_proxy, @@ -385,7 +385,8 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder { new CpuOveruseDetectorProxy(stats_proxy)), std::move(cadence_adapter), std::move(encoder_queue), - allocation_callback_type), + allocation_callback_type, + field_trials), time_controller_(time_controller), fake_cpu_resource_(FakeResource::Create("FakeResource[CPU]")), fake_quality_resource_(FakeResource::Create("FakeResource[QP]")), @@ -678,7 +679,8 @@ class SimpleVideoStreamEncoderFactory { std::unique_ptr CreateWithEncoderQueue( std::unique_ptr zero_hertz_adapter, - std::unique_ptr encoder_queue) { + std::unique_ptr encoder_queue, + const WebRtcKeyValueConfig* field_trials = nullptr) { auto result = std::make_unique( time_controller_.GetClock(), /*number_of_cores=*/1, @@ -686,7 +688,8 @@ class SimpleVideoStreamEncoderFactory { std::make_unique(/*stats_proxy=*/nullptr), std::move(zero_hertz_adapter), std::move(encoder_queue), VideoStreamEncoder::BitrateAllocationCallbackType:: - kVideoBitrateAllocation); + kVideoBitrateAllocation, + field_trials ? *field_trials : field_trials_); result->SetSink(&sink_, /*rotation_applied=*/false); return result; } @@ -730,6 +733,7 @@ class SimpleVideoStreamEncoderFactory { } }; + test::ScopedKeyValueConfig field_trials_; GlobalSimulatedTimeController time_controller_{Timestamp::Millis(0)}; std::unique_ptr task_queue_factory_{ time_controller_.CreateTaskQueueFactory()}; @@ -852,7 +856,7 @@ class VideoStreamEncoderTest : public ::testing::Test { video_stream_encoder_ = std::make_unique( &time_controller_, std::move(cadence_adapter), std::move(encoder_queue), stats_proxy_.get(), video_send_config_.encoder_settings, - allocation_callback_type); + allocation_callback_type, field_trials_); video_stream_encoder_->SetSink(&sink_, /*rotation_applied=*/false); video_stream_encoder_->SetSource( &video_source_, webrtc::DegradationPreference::MAINTAIN_FRAMERATE); @@ -1568,6 +1572,7 @@ class VideoStreamEncoderTest : public ::testing::Test { return time_controller_.GetTaskQueueFactory(); } + test::ScopedKeyValueConfig field_trials_; GlobalSimulatedTimeController time_controller_{Timestamp::Micros(1234)}; VideoSendStream::Config video_send_config_; VideoEncoderConfig video_encoder_config_; @@ -4119,7 +4124,8 @@ class BalancedDegradationTest : public VideoStreamEncoderTest { }; TEST_F(BalancedDegradationTest, AdaptDownTwiceIfMinFpsDiffLtThreshold) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-BalancedDegradationSettings/" "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1/"); SetupTest(); @@ -4143,7 +4149,8 @@ TEST_F(BalancedDegradationTest, AdaptDownTwiceIfMinFpsDiffLtThreshold) { } TEST_F(BalancedDegradationTest, AdaptDownOnceIfFpsDiffGeThreshold) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-BalancedDegradationSettings/" "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1/"); SetupTest(); @@ -4166,7 +4173,8 @@ TEST_F(BalancedDegradationTest, AdaptDownOnceIfFpsDiffGeThreshold) { } TEST_F(BalancedDegradationTest, AdaptDownUsesCodecSpecificFps) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-BalancedDegradationSettings/" "pixels:57600|129600|230400,fps:7|10|24,vp8_fps:8|11|22/"); SetupTest(); @@ -4184,7 +4192,8 @@ TEST_F(BalancedDegradationTest, AdaptDownUsesCodecSpecificFps) { } TEST_F(BalancedDegradationTest, NoAdaptUpIfBwEstimateIsLessThanMinBitrate) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-BalancedDegradationSettings/" "pixels:57600|129600|230400,fps:7|10|14,kbps:0|0|425/"); SetupTest(); @@ -4233,7 +4242,8 @@ TEST_F(BalancedDegradationTest, NoAdaptUpIfBwEstimateIsLessThanMinBitrate) { TEST_F(BalancedDegradationTest, InitialFrameDropAdaptsFpsAndResolutionInOneStep) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-BalancedDegradationSettings/" "pixels:57600|129600|230400,fps:7|24|24/"); SetupTest(); @@ -4264,7 +4274,8 @@ TEST_F(BalancedDegradationTest, TEST_F(BalancedDegradationTest, NoAdaptUpInResolutionIfBwEstimateIsLessThanMinBitrate) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-BalancedDegradationSettings/" "pixels:57600|129600|230400,fps:7|10|14,kbps_res:0|0|435/"); SetupTest(); @@ -4318,7 +4329,8 @@ TEST_F(BalancedDegradationTest, TEST_F(BalancedDegradationTest, NoAdaptUpInFpsAndResolutionIfBwEstimateIsLessThanMinBitrate) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-BalancedDegradationSettings/" "pixels:57600|129600|230400,fps:7|10|14,kbps:0|0|425,kbps_res:0|0|435/"); SetupTest(); @@ -5199,7 +5211,8 @@ TEST_F(VideoStreamEncoderTest, TemporalLayersDisabledIfNotSupported) { } TEST_F(VideoStreamEncoderTest, VerifyBitrateAllocationForTwoStreams) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-QualityScalerSettings/" "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2/"); // Reset encoder for field trials to take effect. @@ -5502,7 +5515,8 @@ TEST_F(VideoStreamEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { } TEST_F(VideoStreamEncoderTest, InitialFrameDropActivatesWhenBweDrops) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-QualityScalerSettings/" "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2/"); // Reset encoder for field trials to take effect. @@ -5542,7 +5556,8 @@ TEST_F(VideoStreamEncoderTest, InitialFrameDropActivatesWhenBweDrops) { TEST_F(VideoStreamEncoderTest, InitialFrameDropNotReactivatedWhenBweDropsWhenScalingDisabled) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-QualityScalerSettings/" "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2/"); fake_encoder_.SetQualityScaling(false); @@ -5833,8 +5848,8 @@ TEST_F(VideoStreamEncoderTest, } TEST_F(VideoStreamEncoderTest, DefaultMaxAndMinBitratesNotUsedIfDisabled) { - webrtc::test::ScopedFieldTrials field_trials( - "WebRTC-DefaultBitrateLimitsKillSwitch/Enabled/"); + webrtc::test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-DefaultBitrateLimitsKillSwitch/Enabled/"); VideoEncoderConfig video_encoder_config; test::FillEncoderConfiguration(PayloadStringToCodecType("VP9"), 1, &video_encoder_config); @@ -6088,7 +6103,8 @@ TEST_F(VideoStreamEncoderTest, } TEST_F(VideoStreamEncoderTest, RampsUpInQualityWhenBwIsHigh) { - webrtc::test::ScopedFieldTrials field_trials( + webrtc::test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-QualityRampupSettings/" "min_pixels:921600,min_duration_ms:2000/"); @@ -6164,8 +6180,8 @@ TEST_F(VideoStreamEncoderTest, RampsUpInQualityWhenBwIsHigh) { TEST_F(VideoStreamEncoderTest, QualityScalerAdaptationsRemovedWhenQualityScalingDisabled) { - webrtc::test::ScopedFieldTrials field_trials( - "WebRTC-Video-QualityScaling/Disabled/"); + webrtc::test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-Video-QualityScaling/Disabled/"); AdaptingFrameForwarder source(&time_controller_); source.set_adaptation_enabled(true); video_stream_encoder_->SetSource(&source, @@ -7743,7 +7759,8 @@ TEST_F(VideoStreamEncoderTest, } TEST_F(VideoStreamEncoderTest, AutomaticAnimationDetection) { - test::ScopedFieldTrials field_trials( + test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-AutomaticAnimationDetectionScreenshare/" "enabled:true,min_fps:20,min_duration_ms:1000,min_area_ratio:0.8/"); const int kFramerateFps = 30; @@ -8058,8 +8075,8 @@ TEST_F(VideoStreamEncoderTest, QpAbsent_QpParsed) { } TEST_F(VideoStreamEncoderTest, QpAbsentParsingDisabled_QpAbsent) { - webrtc::test::ScopedFieldTrials field_trials( - "WebRTC-QpParsingKillSwitch/Enabled/"); + webrtc::test::ScopedKeyValueConfig field_trials( + field_trials_, "WebRTC-QpParsingKillSwitch/Enabled/"); ResetEncoder("VP8", 1, 1, 1, false); @@ -8904,6 +8921,8 @@ TEST(VideoStreamEncoderSimpleTest, CreateDestroy) { std::unique_ptr encoder_queue(new SuperLazyTaskQueue()); + test::ScopedKeyValueConfig field_trials; + // Construct a VideoStreamEncoder instance and let it go out of scope without // doing anything else (including calling Stop()). This should be fine since // the posted init task will simply be deleted. @@ -8912,7 +8931,8 @@ TEST(VideoStreamEncoderSimpleTest, CreateDestroy) { std::make_unique(stats_proxy.get()), std::move(adapter), std::move(encoder_queue), VideoStreamEncoder::BitrateAllocationCallbackType:: - kVideoBitrateAllocation); + kVideoBitrateAllocation, + field_trials); } TEST(VideoStreamEncoderFrameCadenceTest, ActivatesFrameCadenceOnContentType) { @@ -9177,14 +9197,15 @@ TEST(VideoStreamEncoderFrameCadenceTest, "EncoderQueue", TaskQueueFactory::Priority::NORMAL); // Enables zero-hertz mode. - test::ScopedFieldTrials field_trials("WebRTC-ZeroHertzScreenshare/Enabled/"); + test::ScopedKeyValueConfig field_trials( + "WebRTC-ZeroHertzScreenshare/Enabled/"); auto adapter = FrameCadenceAdapterInterface::Create( factory.GetTimeController()->GetClock(), encoder_queue.get()); FrameCadenceAdapterInterface* adapter_ptr = adapter.get(); MockVideoSourceInterface mock_source; auto video_stream_encoder = factory.CreateWithEncoderQueue( - std::move(adapter), std::move(encoder_queue)); + std::move(adapter), std::move(encoder_queue), &field_trials); video_stream_encoder->SetSource( &mock_source, webrtc::DegradationPreference::MAINTAIN_FRAMERATE);