tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 173cae6d001aa5349c12f2a519215d007397fc2b
parent 1a0c0aca061a5b4a208026a15af887bc10b9a29a
Author: Dan Baker <dbaker@mozilla.com>
Date:   Mon,  1 Dec 2025 22:51:36 -0700

Bug 2000941 - Vendor libwebrtc from 58888d69ba

Upstream commit: https://webrtc.googlesource.com/src/+/58888d69bab376f7dfac6be2899e688a8990455f
    Add RTC_DCHECK for immutable field-trials

    Bug: b/444370738
    Change-Id: I24e4ae364b0b7b2a595c9861c8a02f3516a62ac1
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/409040
    Reviewed-by: Harald Alvestrand <hta@webrtc.org>
    Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#45701}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/api/BUILD.gn | 2++
Mthird_party/libwebrtc/api/field_trials.cc | 17+++++++++++++++++
Mthird_party/libwebrtc/api/field_trials.h | 13+++++++++++--
Mthird_party/libwebrtc/api/field_trials_unittest.cc | 25+++++++++++++++++++++++++
Mthird_party/libwebrtc/api/field_trials_view.h | 2++
Mthird_party/libwebrtc/media/engine/simulcast_encoder_adapter_unittest.cc | 3++-
Mthird_party/libwebrtc/media/engine/webrtc_video_engine_unittest.cc | 334++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Mthird_party/libwebrtc/media/engine/webrtc_voice_engine_unittest.cc | 20++++++++++++++++----
Mthird_party/libwebrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc | 60+++++++++++++++++++++++++-----------------------------------
Mthird_party/libwebrtc/modules/video_coding/codecs/test/video_codec_unittest.cc | 4++++
Mthird_party/libwebrtc/modules/video_coding/codecs/test/video_codec_unittest.h | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0027.patch | 2+-
Mthird_party/libwebrtc/moz-patch-stack/s0102.patch | 2+-
Mthird_party/libwebrtc/pc/media_session_unittest.cc | 17+++++++++++------
Mthird_party/libwebrtc/video/video_send_stream_impl_unittest.cc | 43+++++++++++++++++++++++++++++++------------
Mthird_party/libwebrtc/video/video_stream_encoder_unittest.cc | 157+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
17 files changed, 450 insertions(+), 259 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T05:48:36.189413+00:00. +libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-12-02T05:51:23.235034+00:00. # base of lastest vendoring -89a301023b +58888d69ba diff --git a/third_party/libwebrtc/api/BUILD.gn b/third_party/libwebrtc/api/BUILD.gn @@ -1697,6 +1697,7 @@ if (rtc_include_tests) { ":array_view", ":candidate", ":field_trials", + ":field_trials_view", ":function_view", ":libjingle_peerconnection_api", ":rtc_error", @@ -1822,6 +1823,7 @@ rtc_library("field_trials") { ] deps = [ ":field_trials_registry", + ":field_trials_view", "../rtc_base:checks", "../rtc_base/containers:flat_map", "//third_party/abseil-cpp/absl/base:nullability", diff --git a/third_party/libwebrtc/api/field_trials.cc b/third_party/libwebrtc/api/field_trials.cc @@ -17,6 +17,7 @@ #include "absl/base/nullability.h" #include "absl/memory/memory.h" #include "absl/strings/string_view.h" +#include "api/field_trials_registry.h" #include "rtc_base/checks.h" #include "rtc_base/containers/flat_map.h" @@ -68,13 +69,26 @@ FieldTrials::FieldTrials(absl::string_view s) { RTC_CHECK(Parse(s, key_value_map_)); } +FieldTrials::FieldTrials(const FieldTrials& other) + : FieldTrialsRegistry(other) { + key_value_map_ = other.key_value_map_; +} + void FieldTrials::Merge(const FieldTrials& other) { +#ifndef NDEBUG + RTC_DCHECK(get_value_called_ == false) + << "FieldTrials are immutable once first Lookup has been performed"; +#endif for (const auto& [trial, group] : other.key_value_map_) { key_value_map_.insert_or_assign(trial, group); } } void FieldTrials::Set(absl::string_view trial, absl::string_view group) { +#ifndef NDEBUG + RTC_DCHECK(get_value_called_ == false) + << "FieldTrials are immutable once first Lookup has been performed"; +#endif RTC_CHECK(!trial.empty()); RTC_CHECK_EQ(trial.find('/'), absl::string_view::npos); RTC_CHECK_EQ(group.find('/'), absl::string_view::npos); @@ -86,6 +100,9 @@ void FieldTrials::Set(absl::string_view trial, absl::string_view group) { } std::string FieldTrials::GetValue(absl::string_view key) const { +#ifndef NDEBUG + get_value_called_ = true; +#endif auto it = key_value_map_.find(key); if (it != key_value_map_.end()) { return it->second; diff --git a/third_party/libwebrtc/api/field_trials.h b/third_party/libwebrtc/api/field_trials.h @@ -18,6 +18,7 @@ #include "absl/base/nullability.h" #include "absl/strings/string_view.h" #include "api/field_trials_registry.h" +#include "api/field_trials_view.h" #include "rtc_base/containers/flat_map.h" namespace webrtc { @@ -49,7 +50,7 @@ class FieldTrials : public FieldTrialsRegistry { // It is an error to call the constructor with an invalid field trial string. explicit FieldTrials(absl::string_view s); - FieldTrials(const FieldTrials&) = default; + FieldTrials(const FieldTrials&); FieldTrials(FieldTrials&&) = default; FieldTrials& operator=(const FieldTrials&) = default; FieldTrials& operator=(FieldTrials&&) = default; @@ -72,7 +73,11 @@ class FieldTrials : public FieldTrialsRegistry { // Create a copy of this view. std::unique_ptr<FieldTrialsView> CreateCopy() const override { - return std::make_unique<FieldTrials>(*this); + auto copy = std::make_unique<FieldTrials>(*this); +#ifndef NDEBUG + copy->get_value_called_ = false; +#endif + return copy; } private: @@ -81,6 +86,10 @@ class FieldTrials : public FieldTrialsRegistry { std::string GetValue(absl::string_view key) const override; +#ifndef NDEBUG + mutable bool get_value_called_ = false; +#endif + flat_map<std::string, std::string> key_value_map_; }; diff --git a/third_party/libwebrtc/api/field_trials_unittest.cc b/third_party/libwebrtc/api/field_trials_unittest.cc @@ -10,7 +10,11 @@ #include "api/field_trials.h" +#include <memory> + #include "absl/strings/str_cat.h" +#include "api/field_trials_view.h" +#include "rtc_base/checks.h" #include "rtc_base/containers/flat_set.h" #include "test/gmock.h" #include "test/gtest.h" @@ -165,5 +169,26 @@ TEST(FieldTrialsTest, CreateCopy) { EXPECT_EQ(copy->Lookup("Audio"), "Enabled"); } +TEST(FieldTrials, Immutable) { + FieldTrials f("Audio/Enabled/"); + f.RegisterKeysForTesting({"Audio"}); + + // Has never been read, modifyable + f.Set("Audio", "Disabled"); + EXPECT_EQ(f.Lookup("Audio"), "Disabled"); + + // A copy can be modified. + FieldTrials c(f); + c.Set("Audio", "Enabled"); + +#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) +#ifndef NDEBUG + // But FieldTrials that have been read from, + // must not be modified (as documented in FieldTrialsView). + EXPECT_DEATH(f.Set("Audio", "Enabled"), ""); +#endif +#endif +} + } // namespace } // namespace webrtc diff --git a/third_party/libwebrtc/api/field_trials_view.h b/third_party/libwebrtc/api/field_trials_view.h @@ -22,6 +22,8 @@ namespace webrtc { // An interface that provides the means to access field trials. // +// A FieldTrialsView is guaranteed to be immutable, +// // Note that there are no guarantess that the meaning of a particular key-value // mapping will be preserved over time and no announcements will be made if they // are changed. It's up to the library user to ensure that the behavior does not diff --git a/third_party/libwebrtc/media/engine/simulcast_encoder_adapter_unittest.cc b/third_party/libwebrtc/media/engine/simulcast_encoder_adapter_unittest.cc @@ -487,6 +487,7 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test, } void SetUp() override { + env_ = CreateEnvironment(field_trials_.CreateCopy()); helper_ = std::make_unique<TestSimulcastEncoderAdapterFakeHelper>( env_, use_fallback_factory_, SdpVideoFormat("VP8", sdp_video_parameters_)); @@ -672,7 +673,7 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test, protected: FieldTrials field_trials_ = CreateTestFieldTrials(); - const Environment env_ = CreateEnvironment(&field_trials_); + Environment env_ = CreateEnvironment(field_trials_.CreateCopy()); std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_; std::unique_ptr<VideoEncoder> adapter_; VideoCodec codec_; diff --git a/third_party/libwebrtc/media/engine/webrtc_video_engine_unittest.cc b/third_party/libwebrtc/media/engine/webrtc_video_engine_unittest.cc @@ -28,6 +28,7 @@ #include "absl/algorithm/container.h" #include "absl/container/inlined_vector.h" #include "absl/strings/match.h" +#include "absl/strings/string_view.h" #include "api/call/transport.h" #include "api/crypto/crypto_options.h" #include "api/environment/environment.h" @@ -385,7 +386,7 @@ class WebRtcVideoEngineTest : public ::testing::Test { explicit WebRtcVideoEngineTest(const std::string& field_trials) : field_trials_(CreateTestFieldTrials(field_trials)), time_controller_(Timestamp::Millis(4711)), - env_(CreateEnvironment(&field_trials_, + env_(CreateEnvironment(field_trials_.CreateCopy(), time_controller_.CreateTaskQueueFactory(), time_controller_.GetClock())), call_(Call::Create(CallConfig(env_))), @@ -393,12 +394,26 @@ class WebRtcVideoEngineTest : public ::testing::Test { decoder_factory_(new FakeWebRtcVideoDecoderFactory), video_bitrate_allocator_factory_( CreateBuiltinVideoBitrateAllocatorFactory()), - engine_( + engine_(std::make_unique<WebRtcVideoEngine>( std::unique_ptr<FakeWebRtcVideoEncoderFactory>(encoder_factory_), std::unique_ptr<FakeWebRtcVideoDecoderFactory>(decoder_factory_), - field_trials_) {} + env_.field_trials())) {} protected: + void ChangeFieldTrials(absl::string_view key, absl::string_view value) { + if (!key.empty()) { + field_trials_.Set(key, value); + } + env_ = CreateEnvironment(field_trials_.CreateCopy(), + time_controller_.CreateTaskQueueFactory(), + time_controller_.GetClock()); + encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); + decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); + engine_ = std::make_unique<WebRtcVideoEngine>( + std::unique_ptr<FakeWebRtcVideoEncoderFactory>(encoder_factory_), + std::unique_ptr<FakeWebRtcVideoDecoderFactory>(decoder_factory_), + env_.field_trials()); + } void AssignDefaultAptRtxTypes(); void AssignDefaultCodec(); @@ -434,7 +449,7 @@ class WebRtcVideoEngineTest : public ::testing::Test { FakeWebRtcVideoDecoderFactory* decoder_factory_; std::unique_ptr<VideoBitrateAllocatorFactory> video_bitrate_allocator_factory_; - WebRtcVideoEngine engine_; + std::unique_ptr<WebRtcVideoEngine> engine_; std::optional<Codec> default_codec_; std::map<int, int> default_apt_rtx_types_; }; @@ -443,7 +458,7 @@ TEST_F(WebRtcVideoEngineTest, DefaultRtxCodecHasAssociatedPayloadTypeSet) { encoder_factory_->AddSupportedVideoCodecType("VP8"); AssignDefaultCodec(); - std::vector<Codec> engine_codecs = engine_.LegacySendCodecs(); + std::vector<Codec> engine_codecs = engine_->LegacySendCodecs(); for (size_t i = 0; i < engine_codecs.size(); ++i) { if (engine_codecs[i].name != kRtxCodecName) continue; @@ -466,7 +481,7 @@ TEST_F(WebRtcVideoEngineTest, AddSupportedVideoCodecType("VP9"); AddSupportedVideoCodecType("AV1"); AddSupportedVideoCodecType("H264"); - for (const Codec& codec : engine_.LegacySendCodecs()) { + for (const Codec& codec : engine_->LegacySendCodecs()) { if (codec.name != kRtxCodecName) continue; int associated_payload_type; @@ -474,7 +489,7 @@ TEST_F(WebRtcVideoEngineTest, &associated_payload_type)); EXPECT_EQ(codec.id, associated_payload_type + 1); } - for (const Codec& codec : engine_.LegacyRecvCodecs()) { + for (const Codec& codec : engine_->LegacyRecvCodecs()) { if (codec.name != kRtxCodecName) continue; int associated_payload_type; @@ -506,8 +521,8 @@ TEST_F(WebRtcVideoEngineTest, SupportingTwoKindsOfVp9IsOk) { AddSupportedVideoCodec(SdpVideoFormat( "AV1", {{"level-idx", "5"}, {"profile", "0"}, {"tier", "0"}})); AddSupportedVideoCodec(SdpVideoFormat("VP9")); // No parameters - ASSERT_THAT(engine_.LegacySendCodecs(), HasUniquePtValues()); - ASSERT_THAT(engine_.LegacyRecvCodecs(), HasUniquePtValues()); + ASSERT_THAT(engine_->LegacySendCodecs(), HasUniquePtValues()); + ASSERT_THAT(engine_->LegacyRecvCodecs(), HasUniquePtValues()); } TEST_F(WebRtcVideoEngineTest, SupportsTimestampOffsetHeaderExtension) { @@ -711,9 +726,9 @@ TEST_F(WebRtcVideoEngineTest, SetSendFailsBeforeSettingCodecs) { AddSupportedVideoCodecType("VP8"); std::unique_ptr<VideoMediaSendChannelInterface> send_channel = - engine_.CreateSendChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions(), - video_bitrate_allocator_factory_.get()); + engine_->CreateSendChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions(), + video_bitrate_allocator_factory_.get()); EXPECT_TRUE(send_channel->AddSendStream(StreamParams::CreateLegacy(123))); @@ -727,16 +742,16 @@ TEST_F(WebRtcVideoEngineTest, GetStatsWithoutCodecsSetDoesNotCrash) { AddSupportedVideoCodecType("VP8"); std::unique_ptr<VideoMediaSendChannelInterface> send_channel = - engine_.CreateSendChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions(), - video_bitrate_allocator_factory_.get()); + engine_->CreateSendChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions(), + video_bitrate_allocator_factory_.get()); EXPECT_TRUE(send_channel->AddSendStream(StreamParams::CreateLegacy(123))); VideoMediaSendInfo send_info; send_channel->GetStats(&send_info); std::unique_ptr<VideoMediaReceiveChannelInterface> receive_channel = - engine_.CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions()); + engine_->CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions()); EXPECT_TRUE(receive_channel->AddRecvStream(StreamParams::CreateLegacy(123))); VideoMediaReceiveInfo receive_info; receive_channel->GetStats(&receive_info); @@ -798,7 +813,7 @@ TEST_F(WebRtcVideoEngineTest, RtxCodecAddedForH264Codec) { encoder_factory_->AddSupportedVideoCodec(h264_high); // First figure out what payload types the test codecs got assigned. - const std::vector<Codec> codecs = engine_.LegacySendCodecs(); + const std::vector<Codec> codecs = engine_->LegacySendCodecs(); // Now search for RTX codecs for them. Expect that they all have associated // RTX codecs. EXPECT_TRUE(HasRtxCodec( @@ -874,7 +889,7 @@ TEST_F(WebRtcVideoEngineTest, PropagatesInputFrameTimestamp) { } void WebRtcVideoEngineTest::AssignDefaultAptRtxTypes() { - std::vector<Codec> engine_codecs = engine_.LegacySendCodecs(); + std::vector<Codec> engine_codecs = engine_->LegacySendCodecs(); RTC_DCHECK(!engine_codecs.empty()); for (const Codec& codec : engine_codecs) { if (codec.name == "rtx") { @@ -888,7 +903,7 @@ void WebRtcVideoEngineTest::AssignDefaultAptRtxTypes() { } void WebRtcVideoEngineTest::AssignDefaultCodec() { - std::vector<Codec> engine_codecs = engine_.LegacySendCodecs(); + std::vector<Codec> engine_codecs = engine_->LegacySendCodecs(); RTC_DCHECK(!engine_codecs.empty()); bool codec_set = false; for (const Codec& codec : engine_codecs) { @@ -904,7 +919,7 @@ void WebRtcVideoEngineTest::AssignDefaultCodec() { size_t WebRtcVideoEngineTest::GetEngineCodecIndex( const std::string& name) const { - const std::vector<Codec> codecs = engine_.LegacySendCodecs(); + const std::vector<Codec> codecs = engine_->LegacySendCodecs(); for (size_t i = 0; i < codecs.size(); ++i) { const Codec engine_codec = codecs[i]; if (!absl::EqualsIgnoreCase(name, engine_codec.name)) @@ -927,7 +942,7 @@ size_t WebRtcVideoEngineTest::GetEngineCodecIndex( } Codec WebRtcVideoEngineTest::GetEngineCodec(const std::string& name) const { - return engine_.LegacySendCodecs()[GetEngineCodecIndex(name)]; + return engine_->LegacySendCodecs()[GetEngineCodecIndex(name)]; } void WebRtcVideoEngineTest::AddSupportedVideoCodecType( @@ -945,9 +960,9 @@ void WebRtcVideoEngineTest::AddSupportedVideoCodec(SdpVideoFormat format) { std::unique_ptr<VideoMediaSendChannelInterface> WebRtcVideoEngineTest::SetSendParamsWithAllSupportedCodecs() { std::unique_ptr<VideoMediaSendChannelInterface> channel = - engine_.CreateSendChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions(), - video_bitrate_allocator_factory_.get()); + engine_->CreateSendChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions(), + video_bitrate_allocator_factory_.get()); VideoSenderParameters parameters; // We need to look up the codec in the engine to get the correct payload type. for (const SdpVideoFormat& format : encoder_factory_->GetSupportedFormats()) { @@ -966,8 +981,8 @@ std::unique_ptr<VideoMediaReceiveChannelInterface> WebRtcVideoEngineTest::SetRecvParamsWithSupportedCodecs( const std::vector<Codec>& codecs) { std::unique_ptr<VideoMediaReceiveChannelInterface> channel = - engine_.CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions()); + engine_->CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions()); VideoReceiverParameters parameters; parameters.codecs = codecs; EXPECT_TRUE(channel->SetReceiverParameters(parameters)); @@ -991,7 +1006,7 @@ WebRtcVideoEngineTest::SetRecvParamsWithAllSupportedCodecs() { void WebRtcVideoEngineTest::ExpectRtpCapabilitySupport(const char* uri, bool supported) const { const std::vector<RtpExtension> header_extensions = - GetDefaultEnabledRtpHeaderExtensions(engine_, + GetDefaultEnabledRtpHeaderExtensions(*engine_.get(), /* field_trials= */ nullptr); if (supported) { EXPECT_THAT(header_extensions, Contains(Field(&RtpExtension::uri, uri))); @@ -1001,35 +1016,35 @@ void WebRtcVideoEngineTest::ExpectRtpCapabilitySupport(const char* uri, } TEST_F(WebRtcVideoEngineTest, ReceiveBufferSizeViaFieldTrial) { - field_trials_.Set("WebRTC-ReceiveBufferSize", "size_bytes:10000"); + ChangeFieldTrials("WebRTC-ReceiveBufferSize", "size_bytes:10000"); std::unique_ptr<VideoMediaReceiveChannelInterface> receive_channel = - engine_.CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions()); + engine_->CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions()); FakeNetworkInterface network; receive_channel->SetInterface(&network); EXPECT_EQ(10000, network.recvbuf_size()); receive_channel->SetInterface(nullptr); } -TEST_F(WebRtcVideoEngineTest, TooLowReceiveBufferSizeViaFieldTrial) { +TEST_F(WebRtcVideoEngineTest, TooHighReceiveBufferSizeViaFieldTrial) { // 10000001 is too high, it will revert to the default // kVideoRtpRecvBufferSize. - field_trials_.Set("WebRTC-ReceiveBufferSize", "size_bytes:10000001"); + ChangeFieldTrials("WebRTC-ReceiveBufferSize", "size_bytes:10000001"); std::unique_ptr<VideoMediaReceiveChannelInterface> receive_channel = - engine_.CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions()); + engine_->CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions()); FakeNetworkInterface network; receive_channel->SetInterface(&network); EXPECT_EQ(kVideoRtpRecvBufferSize, network.recvbuf_size()); receive_channel->SetInterface(nullptr); } -TEST_F(WebRtcVideoEngineTest, TooHighReceiveBufferSizeViaFieldTrial) { +TEST_F(WebRtcVideoEngineTest, TooLowReceiveBufferSizeViaFieldTrial) { // 9999 is too low, it will revert to the default kVideoRtpRecvBufferSize. - field_trials_.Set("WebRTC-ReceiveBufferSize", "size_bytes:9999"); + ChangeFieldTrials("WebRTC-ReceiveBufferSize", "size_bytes:9999"); std::unique_ptr<VideoMediaReceiveChannelInterface> receive_channel = - engine_.CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions()); + engine_->CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions()); FakeNetworkInterface network; receive_channel->SetInterface(&network); EXPECT_EQ(kVideoRtpRecvBufferSize, network.recvbuf_size()); @@ -1041,13 +1056,13 @@ TEST_F(WebRtcVideoEngineTest, UpdatesUnsignaledRtxSsrcAndRecoversPayload) { // extension. Receive stream is not explicitly configured. AddSupportedVideoCodecType("VP8"); std::vector<Codec> supported_codecs = - engine_.LegacyRecvCodecs(/*include_rtx=*/true); + engine_->LegacyRecvCodecs(/*include_rtx=*/true); ASSERT_EQ(supported_codecs[1].name, "rtx"); int rtx_payload_type = supported_codecs[1].id; std::unique_ptr<VideoMediaReceiveChannelInterface> receive_channel = - engine_.CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions()); + engine_->CreateReceiveChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions()); VideoReceiverParameters parameters; parameters.codecs = supported_codecs; ASSERT_TRUE(receive_channel->SetReceiverParameters(parameters)); @@ -1126,9 +1141,9 @@ TEST_F(WebRtcVideoEngineTest, ChannelWithH264CanChangeToVp8) { FakeFrameSource frame_source(1280, 720, kNumMicrosecsPerSec / 30); std::unique_ptr<VideoMediaSendChannelInterface> send_channel = - engine_.CreateSendChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions(), - video_bitrate_allocator_factory_.get()); + engine_->CreateSendChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions(), + video_bitrate_allocator_factory_.get()); VideoSenderParameters parameters; parameters.codecs.push_back(GetEngineCodec("H264")); EXPECT_TRUE(send_channel->SetSenderParameters(parameters)); @@ -1158,9 +1173,9 @@ TEST_F(WebRtcVideoEngineTest, AddSupportedVideoCodecType("H264"); std::unique_ptr<VideoMediaSendChannelInterface> send_channel = - engine_.CreateSendChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions(), - video_bitrate_allocator_factory_.get()); + engine_->CreateSendChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions(), + video_bitrate_allocator_factory_.get()); VideoSenderParameters parameters; parameters.codecs.push_back(GetEngineCodec("VP8")); EXPECT_TRUE(send_channel->SetSenderParameters(parameters)); @@ -1197,9 +1212,9 @@ TEST_F(WebRtcVideoEngineTest, AddSupportedVideoCodecType("H264"); std::unique_ptr<VideoMediaSendChannelInterface> send_channel = - engine_.CreateSendChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions(), - video_bitrate_allocator_factory_.get()); + engine_->CreateSendChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions(), + video_bitrate_allocator_factory_.get()); VideoSenderParameters parameters; parameters.codecs.push_back(GetEngineCodec("H264")); EXPECT_TRUE(send_channel->SetSenderParameters(parameters)); @@ -1227,9 +1242,9 @@ TEST_F(WebRtcVideoEngineTest, SimulcastEnabledForH264) { AddSupportedVideoCodecType("H264"); std::unique_ptr<VideoMediaSendChannelInterface> send_channel = - engine_.CreateSendChannel(env_, call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions(), - video_bitrate_allocator_factory_.get()); + engine_->CreateSendChannel(env_, call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions(), + video_bitrate_allocator_factory_.get()); VideoSenderParameters parameters; parameters.codecs.push_back(GetEngineCodec("H264")); @@ -1257,26 +1272,32 @@ TEST_F(WebRtcVideoEngineTest, SimulcastEnabledForH264) { // Test that FlexFEC is not supported as a send video codec by default. // Only enabling field trial should allow advertising FlexFEC send codec. -TEST_F(WebRtcVideoEngineTest, Flexfec03SendCodecEnablesWithFieldTrial) { - encoder_factory_->AddSupportedVideoCodecType("VP8"); +class WebRtcVideoEngineTestWithFlexfec : public WebRtcVideoEngineTest { + public: + WebRtcVideoEngineTestWithFlexfec() + : WebRtcVideoEngineTest("WebRTC-FlexFEC-03-Advertised/Enabled/") {} +}; +TEST_F(WebRtcVideoEngineTest, Flexfec03SendCodecEnablesWithoutFieldTrial) { + encoder_factory_->AddSupportedVideoCodecType("VP8"); auto flexfec = Field("name", &Codec::name, "flexfec-03"); + EXPECT_THAT(engine_->LegacySendCodecs(), Not(Contains(flexfec))); +} - EXPECT_THAT(engine_.LegacySendCodecs(), Not(Contains(flexfec))); - - field_trials_.Set("WebRTC-FlexFEC-03-Advertised", "Enabled"); - EXPECT_THAT(engine_.LegacySendCodecs(), Contains(flexfec)); +TEST_F(WebRtcVideoEngineTestWithFlexfec, + Flexfec03SendCodecEnablesWithFieldTrial) { + encoder_factory_->AddSupportedVideoCodecType("VP8"); + auto flexfec = Field("name", &Codec::name, "flexfec-03"); + EXPECT_THAT(engine_->LegacySendCodecs(), Contains(flexfec)); } // Test that the FlexFEC "codec" gets assigned to the lower payload type range -TEST_F(WebRtcVideoEngineTest, Flexfec03LowerPayloadTypeRange) { +TEST_F(WebRtcVideoEngineTestWithFlexfec, Flexfec03LowerPayloadTypeRange) { encoder_factory_->AddSupportedVideoCodecType("VP8"); auto flexfec = Field("name", &Codec::name, "flexfec-03"); - // FlexFEC is active with field trial. - field_trials_.Set("WebRTC-FlexFEC-03-Advertised", "Enabled"); - auto send_codecs = engine_.LegacySendCodecs(); + auto send_codecs = engine_->LegacySendCodecs(); auto it = std::find_if( send_codecs.begin(), send_codecs.end(), [](const Codec& codec) { return codec.name == "flexfec-03"; }); @@ -1306,11 +1327,11 @@ TEST_F(WebRtcVideoEngineTest, ReportSupportedAddedCodec) { // Set up external encoder factory with first codec, and initialize engine. encoder_factory_->AddSupportedVideoCodecType(kFakeExternalCodecName1); - std::vector<Codec> codecs_before(engine_.LegacySendCodecs()); + std::vector<Codec> codecs_before(engine_->LegacySendCodecs()); // Add second codec. encoder_factory_->AddSupportedVideoCodecType(kFakeExternalCodecName2); - std::vector<Codec> codecs_after(engine_.LegacySendCodecs()); + std::vector<Codec> codecs_after(engine_->LegacySendCodecs()); // The codec itself and RTX should have been added. EXPECT_EQ(codecs_before.size() + 2, codecs_after.size()); @@ -1326,7 +1347,7 @@ TEST_F(WebRtcVideoEngineTest, ReportRtxForExternalCodec) { encoder_factory_->AddSupportedVideoCodecType(kFakeCodecName); const size_t fake_codec_index = GetEngineCodecIndex(kFakeCodecName); - EXPECT_EQ("rtx", engine_.LegacySendCodecs().at(fake_codec_index + 1).name); + EXPECT_EQ("rtx", engine_->LegacySendCodecs().at(fake_codec_index + 1).name); } TEST_F(WebRtcVideoEngineTest, RegisterDecodersIfSupported) { @@ -1593,15 +1614,15 @@ TEST_F(WebRtcVideoEngineTest, SetVideoRtxEnabled) { std::vector<Codec> recv_codecs; // Don't want RTX - send_codecs = engine_.LegacySendCodecs(false); + send_codecs = engine_->LegacySendCodecs(false); EXPECT_FALSE(HasAnyRtxCodec(send_codecs)); - recv_codecs = engine_.LegacyRecvCodecs(false); + recv_codecs = engine_->LegacyRecvCodecs(false); EXPECT_FALSE(HasAnyRtxCodec(recv_codecs)); // Want RTX - send_codecs = engine_.LegacySendCodecs(true); + send_codecs = engine_->LegacySendCodecs(true); EXPECT_TRUE(HasAnyRtxCodec(send_codecs)); - recv_codecs = engine_.LegacyRecvCodecs(true); + recv_codecs = engine_->LegacyRecvCodecs(true); EXPECT_TRUE(HasAnyRtxCodec(recv_codecs)); } @@ -1779,11 +1800,11 @@ class WebRtcVideoChannelBaseTest : public ::testing::Test { protected: WebRtcVideoChannelBaseTest() : field_trials_(CreateTestFieldTrials()), - env_(CreateTestEnvironment( - {.field_trials = &field_trials_, .time = &time_controller_})), + env_(CreateTestEnvironment({.field_trials = field_trials_.CreateCopy(), + .time = &time_controller_})), video_bitrate_allocator_factory_( CreateBuiltinVideoBitrateAllocatorFactory()), - engine_( + engine_(std::make_unique<WebRtcVideoEngine>( std::make_unique< VideoEncoderFactoryTemplate<LibvpxVp8EncoderTemplateAdapter, LibvpxVp9EncoderTemplateAdapter, @@ -1794,7 +1815,7 @@ class WebRtcVideoChannelBaseTest : public ::testing::Test { LibvpxVp9DecoderTemplateAdapter, OpenH264DecoderTemplateAdapter, Dav1dDecoderTemplateAdapter>>(), - field_trials_) {} + env_.field_trials())) {} void SetUp() override { // One testcase calls SetUp in a loop, only create call_ once. @@ -1808,10 +1829,10 @@ class WebRtcVideoChannelBaseTest : public ::testing::Test { // needs to be disabled, otherwise, tests which check the size of received // frames become flaky. media_config.video.enable_cpu_adaptation = false; - send_channel_ = engine_.CreateSendChannel( + send_channel_ = engine_->CreateSendChannel( env_, call_.get(), media_config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); - receive_channel_ = engine_.CreateReceiveChannel( + receive_channel_ = engine_->CreateReceiveChannel( env_, call_.get(), media_config, VideoOptions(), CryptoOptions()); send_channel_->OnReadyToSend(true); receive_channel_->SetReceive(true); @@ -1819,7 +1840,7 @@ class WebRtcVideoChannelBaseTest : public ::testing::Test { send_channel_->SetInterface(&network_interface_); receive_channel_->SetInterface(&network_interface_); VideoReceiverParameters parameters; - parameters.codecs = engine_.LegacySendCodecs(); + parameters.codecs = engine_->LegacySendCodecs(); receive_channel_->SetReceiverParameters(parameters); EXPECT_TRUE(send_channel_->AddSendStream(DefaultSendStreamParams())); frame_forwarder_ = std::make_unique<FrameForwarder>(); @@ -1874,6 +1895,8 @@ class WebRtcVideoChannelBaseTest : public ::testing::Test { } void ResetTest() { + env_ = CreateTestEnvironment({.field_trials = field_trials_.CreateCopy(), + .time = &time_controller_}); TearDown(); SetUp(); } @@ -1979,7 +2002,7 @@ class WebRtcVideoChannelBaseTest : public ::testing::Test { } Codec GetEngineCodec(const std::string& name) { - for (const Codec& engine_codec : engine_.LegacySendCodecs()) { + for (const Codec& engine_codec : engine_->LegacySendCodecs()) { if (absl::EqualsIgnoreCase(name, engine_codec.name)) return engine_codec; } @@ -2001,7 +2024,7 @@ class WebRtcVideoChannelBaseTest : public ::testing::Test { std::unique_ptr<Call> call_; std::unique_ptr<VideoBitrateAllocatorFactory> video_bitrate_allocator_factory_; - WebRtcVideoEngine engine_; + std::unique_ptr<WebRtcVideoEngine> engine_; std::unique_ptr<FakeFrameSource> frame_source_; std::unique_ptr<FrameForwarder> frame_forwarder_; @@ -2705,12 +2728,12 @@ class WebRtcVideoChannelTest : public WebRtcVideoEngineTest { #endif fake_call_ = std::make_unique<FakeCall>(env_); - send_channel_ = engine_.CreateSendChannel( + send_channel_ = engine_->CreateSendChannel( env_, fake_call_.get(), GetMediaConfig(), VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); receive_channel_ = - engine_.CreateReceiveChannel(env_, fake_call_.get(), GetMediaConfig(), - VideoOptions(), CryptoOptions()); + engine_->CreateReceiveChannel(env_, fake_call_.get(), GetMediaConfig(), + VideoOptions(), CryptoOptions()); send_channel_->SetSsrcListChangedCallback( [receive_channel = receive_channel_.get()](const std::set<uint32_t>& choices) { @@ -2725,8 +2748,8 @@ class WebRtcVideoChannelTest : public WebRtcVideoEngineTest { send_channel_->OnReadyToSend(true); receive_channel_->SetReceive(true); last_ssrc_ = 123; - send_parameters_.codecs = engine_.LegacySendCodecs(); - recv_parameters_.codecs = engine_.LegacyRecvCodecs(); + send_parameters_.codecs = engine_->LegacySendCodecs(); + recv_parameters_.codecs = engine_->LegacyRecvCodecs(); ASSERT_TRUE(send_channel_->SetSenderParameters(send_parameters_)); } @@ -2740,6 +2763,7 @@ class WebRtcVideoChannelTest : public WebRtcVideoEngineTest { void ResetTest() { TearDown(); + WebRtcVideoEngineTest::ChangeFieldTrials("", ""); SetUp(); } @@ -2756,7 +2780,7 @@ class WebRtcVideoChannelTest : public WebRtcVideoEngineTest { } Codec GetEngineCodec(const std::string& name) { - for (const Codec& engine_codec : engine_.LegacySendCodecs()) { + for (const Codec& engine_codec : engine_->LegacySendCodecs()) { if (absl::EqualsIgnoreCase(name, engine_codec.name)) return engine_codec; } @@ -2934,7 +2958,7 @@ class WebRtcVideoChannelTest : public WebRtcVideoEngineTest { VerifyCodecHasDefaultFeedbackParams(*default_codec_, expect_lntf_enabled); VideoSenderParameters parameters; - parameters.codecs = engine_.LegacySendCodecs(); + parameters.codecs = engine_->LegacySendCodecs(); EXPECT_TRUE(send_channel_->SetSenderParameters(parameters)); EXPECT_TRUE(send_channel_->SetSend(true)); @@ -3079,7 +3103,7 @@ TEST_F(WebRtcVideoChannelTest, SetsSyncGroupFromSyncLabel) { TEST_F(WebRtcVideoChannelTest, RecvStreamWithSimAndRtx) { VideoSenderParameters parameters; - parameters.codecs = engine_.LegacySendCodecs(); + parameters.codecs = engine_->LegacySendCodecs(); EXPECT_TRUE(send_channel_->SetSenderParameters(parameters)); EXPECT_TRUE(send_channel_->SetSend(true)); parameters.conference_mode = true; @@ -3172,8 +3196,15 @@ TEST_F(WebRtcVideoChannelTest, RecvAbsoluteSendTimeHeaderExtensions) { TestSetRecvRtpHeaderExtensions(RtpExtension::kAbsSendTimeUri); } -TEST_F(WebRtcVideoChannelTest, FiltersExtensionsPicksTransportSeqNum) { - field_trials_.Set("WebRTC-FilterAbsSendTimeExtension", "Enabled"); +class WebRtcVideoChannelWithFilterAbsSendTimeExtensionTest + : public WebRtcVideoChannelTest { + public: + WebRtcVideoChannelWithFilterAbsSendTimeExtensionTest() + : WebRtcVideoChannelTest("WebRTC-FilterAbsSendTimeExtension/Enabled/") {} +}; + +TEST_F(WebRtcVideoChannelWithFilterAbsSendTimeExtensionTest, + FiltersExtensionsPicksTransportSeqNum) { // Enable three redundant extensions. std::vector<std::string> extensions; extensions.push_back(RtpExtension::kAbsSendTimeUri); @@ -3405,22 +3436,26 @@ TEST_F(WebRtcVideoChannelTest, LossNotificationIsDisabledByDefault) { TestLossNotificationState(false); } -TEST_F(WebRtcVideoChannelTest, LossNotificationIsEnabledByFieldTrial) { - field_trials_.Set("WebRTC-RtcpLossNotification", "Enabled"); - ResetTest(); +class WebRtcVideoChannelWithRtcpLossNotificationTest + : public WebRtcVideoChannelTest { + public: + WebRtcVideoChannelWithRtcpLossNotificationTest() + : WebRtcVideoChannelTest("WebRTC-RtcpLossNotification/Enabled/") {} +}; + +TEST_F(WebRtcVideoChannelWithRtcpLossNotificationTest, + LossNotificationIsEnabledByFieldTrial) { TestLossNotificationState(true); } -TEST_F(WebRtcVideoChannelTest, LossNotificationCanBeEnabledAndDisabled) { - field_trials_.Set("WebRTC-RtcpLossNotification", "Enabled"); - ResetTest(); - +TEST_F(WebRtcVideoChannelWithRtcpLossNotificationTest, + LossNotificationCanBeEnabledAndDisabled) { AssignDefaultCodec(); VerifyCodecHasDefaultFeedbackParams(*default_codec_, true); { VideoSenderParameters parameters; - parameters.codecs = engine_.LegacySendCodecs(); + parameters.codecs = engine_->LegacySendCodecs(); EXPECT_TRUE(send_channel_->SetSenderParameters(parameters)); EXPECT_TRUE(send_channel_->SetSend(true)); } @@ -3444,7 +3479,7 @@ TEST_F(WebRtcVideoChannelTest, LossNotificationCanBeEnabledAndDisabled) { EXPECT_FALSE(send_stream->GetConfig().rtp.lntf.enabled); // Setting the default codecs again, including VP8, turns LNTF back on. - parameters.codecs = engine_.LegacySendCodecs(); + parameters.codecs = engine_->LegacySendCodecs(); EXPECT_TRUE(send_channel_->SetSenderParameters(parameters)); recv_stream = fake_call_->GetVideoReceiveStreams()[0]; EXPECT_TRUE(recv_stream->GetConfig().rtp.lntf.enabled); @@ -3457,7 +3492,7 @@ TEST_F(WebRtcVideoChannelTest, NackIsEnabledByDefault) { VerifyCodecHasDefaultFeedbackParams(*default_codec_, false); VideoSenderParameters parameters; - parameters.codecs = engine_.LegacySendCodecs(); + parameters.codecs = engine_->LegacySendCodecs(); EXPECT_TRUE(send_channel_->SetSenderParameters(parameters)); EXPECT_TRUE(send_channel_->SetSend(true)); @@ -3495,7 +3530,7 @@ TEST_F(WebRtcVideoChannelTest, NackCanBeEnabledAndDisabled) { // Verify that NACK is turned on when setting default codecs since the // default codecs have NACK enabled. - parameters.codecs = engine_.LegacySendCodecs(); + parameters.codecs = engine_->LegacySendCodecs(); EXPECT_TRUE(send_channel_->SetSenderParameters(parameters)); recv_stream = fake_call_->GetVideoReceiveStreams()[0]; EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); @@ -3639,10 +3674,10 @@ TEST_F(WebRtcVideoChannelTest, SetMediaConfigSuspendBelowMinBitrate) { MediaConfig media_config = GetMediaConfig(); media_config.video.suspend_below_min_bitrate = true; - send_channel_ = engine_.CreateSendChannel( + send_channel_ = engine_->CreateSendChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); - receive_channel_ = engine_.CreateReceiveChannel( + receive_channel_ = engine_->CreateReceiveChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions()); send_channel_->OnReadyToSend(true); @@ -3652,10 +3687,10 @@ TEST_F(WebRtcVideoChannelTest, SetMediaConfigSuspendBelowMinBitrate) { EXPECT_TRUE(stream->GetConfig().suspend_below_min_bitrate); media_config.video.suspend_below_min_bitrate = false; - send_channel_ = engine_.CreateSendChannel( + send_channel_ = engine_->CreateSendChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); - receive_channel_ = engine_.CreateReceiveChannel( + receive_channel_ = engine_->CreateReceiveChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions()); send_channel_->OnReadyToSend(true); @@ -3860,7 +3895,7 @@ class Vp9SettingsTest : public WebRtcVideoChannelTest { protected: void TearDown() override { // Remove references to encoder_factory_ since this will be destroyed - // before send_channel_ and engine_. + // before send_channel_ and engine_-> ASSERT_TRUE(send_channel_->SetSenderParameters(send_parameters_)); } }; @@ -4218,9 +4253,15 @@ TEST_F(WebRtcVideoChannelTest, VerifyMinBitrate) { EXPECT_EQ(kDefaultMinVideoBitrateBps, streams[0].min_bitrate_bps); } -TEST_F(WebRtcVideoChannelTest, VerifyMinBitrateWithForcedFallbackFieldTrial) { - field_trials_.Set("WebRTC-VP8-Forced-Fallback-Encoder-v2", - "Enabled-1,2,34567"); +class WebRtcVideoChanneWithForcedFallbackTest : public WebRtcVideoChannelTest { + public: + WebRtcVideoChanneWithForcedFallbackTest() + : WebRtcVideoChannelTest( + "WebRTC-VP8-Forced-Fallback-Encoder-v2/Enabled-1,2,34567/") {} +}; + +TEST_F(WebRtcVideoChanneWithForcedFallbackTest, + VerifyMinBitrateWithForcedFallbackFieldTrial) { std::vector<VideoStream> streams = AddSendStream()->GetVideoStreams(); ASSERT_EQ(1u, streams.size()); EXPECT_EQ(34567, streams[0].min_bitrate_bps); @@ -4228,15 +4269,20 @@ TEST_F(WebRtcVideoChannelTest, VerifyMinBitrateWithForcedFallbackFieldTrial) { TEST_F(WebRtcVideoChannelTest, BalancedDegradationPreferenceNotSupportedWithoutFieldtrial) { - field_trials_.Set("WebRTC-Video-BalancedDegradation", "Disabled"); const bool kResolutionScalingEnabled = true; const bool kFpsScalingEnabled = false; TestDegradationPreference(kResolutionScalingEnabled, kFpsScalingEnabled); } -TEST_F(WebRtcVideoChannelTest, +class WebRtcVideoChannelWithBalancedDegradationTest + : public WebRtcVideoChannelTest { + public: + WebRtcVideoChannelWithBalancedDegradationTest() + : WebRtcVideoChannelTest("WebRTC-Video-BalancedDegradation/Enabled/") {} +}; + +TEST_F(WebRtcVideoChannelWithBalancedDegradationTest, BalancedDegradationPreferenceSupportedBehindFieldtrial) { - field_trials_.Set("WebRTC-Video-BalancedDegradation", "Enabled"); const bool kResolutionScalingEnabled = true; const bool kFpsScalingEnabled = true; TestDegradationPreference(kResolutionScalingEnabled, kFpsScalingEnabled); @@ -4265,10 +4311,10 @@ TEST_F(WebRtcVideoChannelTest, PreviousAdaptationDoesNotApplyToScreenshare) { MediaConfig media_config = GetMediaConfig(); media_config.video.enable_cpu_adaptation = true; - send_channel_ = engine_.CreateSendChannel( + send_channel_ = engine_->CreateSendChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); - receive_channel_ = engine_.CreateReceiveChannel( + receive_channel_ = engine_->CreateReceiveChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions()); send_channel_->OnReadyToSend(true); @@ -4319,10 +4365,10 @@ void WebRtcVideoChannelTest::TestDegradationPreference( MediaConfig media_config = GetMediaConfig(); media_config.video.enable_cpu_adaptation = true; - send_channel_ = engine_.CreateSendChannel( + send_channel_ = engine_->CreateSendChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); - receive_channel_ = engine_.CreateReceiveChannel( + receive_channel_ = engine_->CreateReceiveChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions()); send_channel_->OnReadyToSend(true); @@ -4355,10 +4401,10 @@ void WebRtcVideoChannelTest::TestCpuAdaptation(bool enable_overuse, if (enable_overuse) { media_config.video.enable_cpu_adaptation = true; } - send_channel_ = engine_.CreateSendChannel( + send_channel_ = engine_->CreateSendChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); - receive_channel_ = engine_.CreateReceiveChannel( + receive_channel_ = engine_->CreateReceiveChannel( env_, fake_call_.get(), media_config, VideoOptions(), CryptoOptions()); send_channel_->OnReadyToSend(true); @@ -4440,7 +4486,7 @@ TEST_F(WebRtcVideoChannelTest, SetDefaultSendCodecs) { std::optional<Codec> codec = send_channel_->GetSendCodec(); ASSERT_TRUE(codec); - EXPECT_TRUE(codec->Matches(engine_.LegacySendCodecs()[0])); + EXPECT_TRUE(codec->Matches(engine_->LegacySendCodecs()[0])); // Using a RTX setup to verify that the default RTX payload type is good. const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); @@ -4806,7 +4852,7 @@ TEST_F(WebRtcVideoChannelFlexfecRecvTest, TEST_F(WebRtcVideoChannelTest, SetSendCodecRejectsRtxWithoutAssociatedPayloadType) { const int kUnusedPayloadType = 127; - EXPECT_FALSE(FindCodecById(engine_.LegacySendCodecs(), kUnusedPayloadType)); + EXPECT_FALSE(FindCodecById(engine_->LegacySendCodecs(), kUnusedPayloadType)); VideoSenderParameters parameters; Codec rtx_codec = CreateVideoCodec(kUnusedPayloadType, "rtx"); @@ -4819,8 +4865,8 @@ TEST_F(WebRtcVideoChannelTest, SetSendCodecRejectsRtxWithoutMatchingVideoCodec) { const int kUnusedPayloadType1 = 126; const int kUnusedPayloadType2 = 127; - EXPECT_FALSE(FindCodecById(engine_.LegacySendCodecs(), kUnusedPayloadType1)); - EXPECT_FALSE(FindCodecById(engine_.LegacySendCodecs(), kUnusedPayloadType2)); + EXPECT_FALSE(FindCodecById(engine_->LegacySendCodecs(), kUnusedPayloadType1)); + EXPECT_FALSE(FindCodecById(engine_->LegacySendCodecs(), kUnusedPayloadType2)); { Codec rtx_codec = CreateVideoRtxCodec(kUnusedPayloadType1, GetEngineCodec("VP8").id); @@ -4843,8 +4889,8 @@ TEST_F(WebRtcVideoChannelTest, TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithChangedRtxPayloadType) { const int kUnusedPayloadType1 = 126; const int kUnusedPayloadType2 = 127; - EXPECT_FALSE(FindCodecById(engine_.LegacySendCodecs(), kUnusedPayloadType1)); - EXPECT_FALSE(FindCodecById(engine_.LegacySendCodecs(), kUnusedPayloadType2)); + EXPECT_FALSE(FindCodecById(engine_->LegacySendCodecs(), kUnusedPayloadType1)); + EXPECT_FALSE(FindCodecById(engine_->LegacySendCodecs(), kUnusedPayloadType2)); // SSRCs for RTX. StreamParams params = StreamParams::CreateLegacy(kSsrcs1[0]); @@ -5279,8 +5325,8 @@ TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithOnlyVp8) { TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithRtx) { const int kUnusedPayloadType1 = 126; const int kUnusedPayloadType2 = 127; - EXPECT_FALSE(FindCodecById(engine_.LegacyRecvCodecs(), kUnusedPayloadType1)); - EXPECT_FALSE(FindCodecById(engine_.LegacyRecvCodecs(), kUnusedPayloadType2)); + EXPECT_FALSE(FindCodecById(engine_->LegacyRecvCodecs(), kUnusedPayloadType1)); + EXPECT_FALSE(FindCodecById(engine_->LegacyRecvCodecs(), kUnusedPayloadType2)); VideoReceiverParameters parameters; parameters.codecs.push_back(GetEngineCodec("VP8")); @@ -5376,8 +5422,8 @@ TEST_F(WebRtcVideoChannelTest, DuplicateRedCodecIsDropped) { TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithChangedRtxPayloadType) { const int kUnusedPayloadType1 = 126; const int kUnusedPayloadType2 = 127; - EXPECT_FALSE(FindCodecById(engine_.LegacyRecvCodecs(), kUnusedPayloadType1)); - EXPECT_FALSE(FindCodecById(engine_.LegacyRecvCodecs(), kUnusedPayloadType2)); + EXPECT_FALSE(FindCodecById(engine_->LegacyRecvCodecs(), kUnusedPayloadType1)); + EXPECT_FALSE(FindCodecById(engine_->LegacyRecvCodecs(), kUnusedPayloadType2)); // SSRCs for RTX. StreamParams params = StreamParams::CreateLegacy(kSsrcs1[0]); @@ -5418,8 +5464,8 @@ TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithChangedRtxPayloadType) { TEST_F(WebRtcVideoChannelTest, SetRecvCodecsRtxWithRtxTime) { const int kUnusedPayloadType1 = 126; const int kUnusedPayloadType2 = 127; - EXPECT_FALSE(FindCodecById(engine_.LegacyRecvCodecs(), kUnusedPayloadType1)); - EXPECT_FALSE(FindCodecById(engine_.LegacyRecvCodecs(), kUnusedPayloadType2)); + EXPECT_FALSE(FindCodecById(engine_->LegacyRecvCodecs(), kUnusedPayloadType1)); + EXPECT_FALSE(FindCodecById(engine_->LegacyRecvCodecs(), kUnusedPayloadType2)); // SSRCs for RTX. StreamParams params = StreamParams::CreateLegacy(kSsrcs1[0]); @@ -5493,14 +5539,14 @@ TEST_F(WebRtcVideoChannelTest, SetRecvCodecsDifferentPayloadType) { TEST_F(WebRtcVideoChannelTest, SetRecvCodecsAcceptDefaultCodecs) { VideoReceiverParameters parameters; - parameters.codecs = engine_.LegacyRecvCodecs(); + parameters.codecs = engine_->LegacyRecvCodecs(); EXPECT_TRUE(receive_channel_->SetReceiverParameters(parameters)); FakeVideoReceiveStream* stream = AddRecvStream(); const VideoReceiveStreamInterface::Config& config = stream->GetConfig(); - EXPECT_EQ(engine_.LegacyRecvCodecs()[0].name, + EXPECT_EQ(engine_->LegacyRecvCodecs()[0].name, config.decoders[0].video_format.name); - EXPECT_EQ(engine_.LegacyRecvCodecs()[0].id, config.decoders[0].payload_type); + EXPECT_EQ(engine_->LegacyRecvCodecs()[0].id, config.decoders[0].payload_type); } TEST_F(WebRtcVideoChannelTest, SetRecvCodecsRejectUnsupportedCodec) { @@ -5713,7 +5759,7 @@ TEST_F(WebRtcVideoChannelTest, TestSetDscpOptions) { std::unique_ptr<VideoMediaSendChannelInterface> send_channel; RtpParameters parameters; - send_channel = engine_.CreateSendChannel( + send_channel = engine_->CreateSendChannel( env_, call_.get(), config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); @@ -5725,7 +5771,7 @@ TEST_F(WebRtcVideoChannelTest, TestSetDscpOptions) { // Default value when DSCP is enabled is also DSCP_DEFAULT, until it is set // through rtp parameters. config.enable_dscp = true; - send_channel = engine_.CreateSendChannel( + send_channel = engine_->CreateSendChannel( env_, call_.get(), config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); send_channel->SetInterface(network_interface.get()); @@ -5756,7 +5802,7 @@ TEST_F(WebRtcVideoChannelTest, TestSetDscpOptions) { // Verify that setting the option to false resets the // DiffServCodePoint. config.enable_dscp = false; - send_channel = engine_.CreateSendChannel( + send_channel = engine_->CreateSendChannel( env_, call_.get(), config, VideoOptions(), CryptoOptions(), video_bitrate_allocator_factory_.get()); send_channel->SetInterface(network_interface.get()); @@ -7478,7 +7524,7 @@ void WebRtcVideoChannelTest::TestReceiveUnsignaledSsrcPacket( uint8_t payload_type, bool expect_created_receive_stream) { // kRedRtxPayloadType must currently be unused. - EXPECT_FALSE(FindCodecById(engine_.LegacyRecvCodecs(), kRedRtxPayloadType)); + EXPECT_FALSE(FindCodecById(engine_->LegacyRecvCodecs(), kRedRtxPayloadType)); // Add a RED RTX codec. Codec red_rtx_codec = @@ -8073,6 +8119,7 @@ TEST_P(WebRtcVideoChannelScaleResolutionDownByTest, ScaleResolutionDownBy) { ScaleResolutionDownByTestParameters test_params = std::get<0>(GetParam()); std::string codec_name = std::get<1>(GetParam()); field_trials_.Merge(FieldTrials(test_params.field_trials)); + ResetTest(); // Set up WebRtcVideoChannel for 3-layer simulcast. encoder_factory_->AddSupportedVideoCodecType(codec_name); VideoSenderParameters parameters; @@ -9096,9 +9143,15 @@ TEST_F(WebRtcVideoChannelTest, EXPECT_TRUE(send_channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); } -TEST_F(WebRtcVideoChannelTest, SetMixedCodecSimulcastStreamConfig) { - field_trials_.Set("WebRTC-MixedCodecSimulcast", "Enabled"); +class WebRtcVideoChannelWithMixedCodecSimulcastTest + : public WebRtcVideoChannelTest { + public: + WebRtcVideoChannelWithMixedCodecSimulcastTest() + : WebRtcVideoChannelTest("WebRTC-MixedCodecSimulcast/Enabled/") {} +}; +TEST_F(WebRtcVideoChannelWithMixedCodecSimulcastTest, + SetMixedCodecSimulcastStreamConfig) { StreamParams sp = CreateSimStreamParams("cname", {123, 456, 789}); std::vector<RidDescription> rid_descriptions; @@ -9144,9 +9197,8 @@ TEST_F(WebRtcVideoChannelTest, SetMixedCodecSimulcastStreamConfig) { } #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) -TEST_F(WebRtcVideoChannelTest, +TEST_F(WebRtcVideoChannelWithMixedCodecSimulcastTest, SetMixedCodecSimulcastWithDifferentConfigSettingsSizes) { - field_trials_.Set("WebRTC-MixedCodecSimulcast", "Enabled"); AddSendStream(); VideoSenderParameters parameters; diff --git a/third_party/libwebrtc/media/engine/webrtc_voice_engine_unittest.cc b/third_party/libwebrtc/media/engine/webrtc_voice_engine_unittest.cc @@ -22,6 +22,7 @@ #include <vector> #include "absl/strings/match.h" +#include "absl/strings/string_view.h" #include "api/array_view.h" #include "api/audio/audio_processing.h" #include "api/audio/builtin_audio_processing_builder.h" @@ -252,9 +253,9 @@ class FakeAudioSource : public webrtc::AudioSource { class WebRtcVoiceEngineTestFake : public ::testing::TestWithParam<bool> { public: - WebRtcVoiceEngineTestFake() + explicit WebRtcVoiceEngineTestFake(absl::string_view field_trials_string = "") : use_null_apm_(GetParam()), - field_trials_(CreateTestFieldTrials()), + field_trials_(CreateTestFieldTrials(field_trials_string)), env_(CreateEnvironment(&field_trials_)), adm_(webrtc::test::MockAudioDeviceModule::CreateStrict()), apm_(use_null_apm_ @@ -1323,12 +1324,23 @@ TEST_P(WebRtcVoiceEngineTestFake, GetAudioNetworkAdaptorConfig(kSsrcX)); } -TEST_P(WebRtcVoiceEngineTestFake, AdaptivePtimeFieldTrial) { - field_trials_.Set("WebRTC-Audio-AdaptivePtime", "enabled:true"); +class WebRtcVoiceEngineTestWithAdaptivePtime + : public WebRtcVoiceEngineTestFake { + public: + WebRtcVoiceEngineTestWithAdaptivePtime() + : WebRtcVoiceEngineTestFake("WebRTC-Audio-AdaptivePtime/enabled:true/") {} +}; + +TEST_P(WebRtcVoiceEngineTestWithAdaptivePtime, AdaptivePtimeFieldTrial) { + // field_trials_.Set("WebRTC-Audio-AdaptivePtime", "enabled:true"); EXPECT_TRUE(SetupSendStream()); EXPECT_TRUE(GetAudioNetworkAdaptorConfig(kSsrcX)); } +INSTANTIATE_TEST_SUITE_P(TestBothWithAndWithoutNullApm, + WebRtcVoiceEngineTestWithAdaptivePtime, + ::testing::Values(false, true)); + // Test that SetRtpSendParameters configures the correct encoding channel for // each SSRC. TEST_P(WebRtcVoiceEngineTestFake, RtpParametersArePerStream) { diff --git a/third_party/libwebrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc b/third_party/libwebrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red_unittest.cc @@ -18,6 +18,7 @@ #include <utility> #include <vector> +#include "absl/strings/string_view.h" #include "api/array_view.h" #include "api/audio_codecs/audio_encoder.h" #include "api/field_trials.h" @@ -51,12 +52,12 @@ constexpr size_t kRedLastHeaderLength = class AudioEncoderCopyRedTest : public ::testing::Test { protected: AudioEncoderCopyRedTest() - : field_trials_(CreateTestFieldTrials()), - mock_encoder_(new MockAudioEncoder), + : mock_encoder_(new MockAudioEncoder), timestamp_(4711), sample_rate_hz_(16000), num_audio_samples_10ms(sample_rate_hz_ / 100), - red_payload_type_(63) { + red_payload_type_(63), + field_trials_(CreateTestFieldTrials()) { AudioEncoderCopyRed::Config config; config.payload_type = red_payload_type_; config.speech_encoder = std::unique_ptr<AudioEncoder>(mock_encoder_); @@ -78,7 +79,17 @@ class AudioEncoderCopyRedTest : public ::testing::Test { timestamp_ += checked_cast<uint32_t>(num_audio_samples_10ms); } - FieldTrials field_trials_; + void ChangeFieldTrials(absl::string_view key, absl::string_view value) { + modified_field_trials_ = std::make_unique<FieldTrials>(field_trials_); + modified_field_trials_->Set(key, value); + + AudioEncoderCopyRed::Config config; + config.payload_type = red_payload_type_; + config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); + red_.reset( + new AudioEncoderCopyRed(std::move(config), *modified_field_trials_)); + } + MockAudioEncoder* mock_encoder_; std::unique_ptr<AudioEncoderCopyRed> red_; uint32_t timestamp_; @@ -88,6 +99,10 @@ class AudioEncoderCopyRedTest : public ::testing::Test { Buffer encoded_; AudioEncoder::EncodedInfo encoded_info_; const int red_payload_type_; + + private: + FieldTrials field_trials_; + std::unique_ptr<FieldTrials> modified_field_trials_; }; TEST_F(AudioEncoderCopyRedTest, CreateAndDestroy) {} @@ -209,12 +224,7 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes1) { // Checks that the correct payload sizes are populated into the redundancy // information for a redundancy level of 0. TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes0) { - field_trials_.Set("WebRTC-Audio-Red-For-Opus", "Enabled-0"); - // Recreate the RED encoder to take the new field trial setting into account. - AudioEncoderCopyRed::Config config; - config.payload_type = red_payload_type_; - config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); - red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials_)); + ChangeFieldTrials("WebRTC-Audio-Red-For-Opus", "Enabled-0"); // Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence // of calls. @@ -234,12 +244,7 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes0) { // Checks that the correct payload sizes are populated into the redundancy // information for a redundancy level of 2. TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes2) { - field_trials_.Set("WebRTC-Audio-Red-For-Opus", "Enabled-2"); - // Recreate the RED encoder to take the new field trial setting into account. - AudioEncoderCopyRed::Config config; - config.payload_type = red_payload_type_; - config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); - red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials_)); + ChangeFieldTrials("WebRTC-Audio-Red-For-Opus", "Enabled-2"); // Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence // of calls. @@ -275,12 +280,7 @@ TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes2) { // Checks that the correct payload sizes are populated into the redundancy // information for a redundancy level of 3. TEST_F(AudioEncoderCopyRedTest, CheckPayloadSizes3) { - field_trials_.Set("WebRTC-Audio-Red-For-Opus", "Enabled-3"); - // Recreate the RED encoder to take the new field trial setting into account. - AudioEncoderCopyRed::Config config; - config.payload_type = red_payload_type_; - config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); - red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials_)); + ChangeFieldTrials("WebRTC-Audio-Red-For-Opus", "Enabled-3"); // Let the mock encoder return payload sizes 1, 2, 3, ..., 10 for the sequence // of calls. @@ -488,12 +488,7 @@ TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header) { // Variant with a redundancy of 0. TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header0) { - field_trials_.Set("WebRTC-Audio-Red-For-Opus", "Enabled-0"); - // Recreate the RED encoder to take the new field trial setting into account. - AudioEncoderCopyRed::Config config; - config.payload_type = red_payload_type_; - config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); - red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials_)); + ChangeFieldTrials("WebRTC-Audio-Red-For-Opus", "Enabled-0"); const int primary_payload_type = red_payload_type_ + 1; AudioEncoder::EncodedInfo info; @@ -515,12 +510,7 @@ TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header0) { } // Variant with a redundancy of 2. TEST_F(AudioEncoderCopyRedTest, CheckRFC2198Header2) { - field_trials_.Set("WebRTC-Audio-Red-For-Opus", "Enabled-2"); - // Recreate the RED encoder to take the new field trial setting into account. - AudioEncoderCopyRed::Config config; - config.payload_type = red_payload_type_; - config.speech_encoder = std::move(red_->ReclaimContainedEncoders()[0]); - red_.reset(new AudioEncoderCopyRed(std::move(config), field_trials_)); + ChangeFieldTrials("WebRTC-Audio-Red-For-Opus", "Enabled-2"); const int primary_payload_type = red_payload_type_ + 1; AudioEncoder::EncodedInfo info; @@ -650,7 +640,7 @@ TEST_F(AudioEncoderCopyRedDeathTest, NullSpeechEncoder) { AudioEncoderCopyRed::Config config; config.speech_encoder = nullptr; RTC_EXPECT_DEATH( - red = new AudioEncoderCopyRed(std::move(config), field_trials_), + red = new AudioEncoderCopyRed(std::move(config), CreateTestFieldTrials()), "Speech encoder not provided."); // The delete operation is needed to avoid leak reports from memcheck. delete red; diff --git a/third_party/libwebrtc/modules/video_coding/codecs/test/video_codec_unittest.cc b/third_party/libwebrtc/modules/video_coding/codecs/test/video_codec_unittest.cc @@ -17,6 +17,7 @@ #include <utility> #include <vector> +#include "api/environment/environment_factory.h" #include "api/test/create_frame_generator.h" #include "api/test/frame_generator_interface.h" #include "api/units/time_delta.h" @@ -81,6 +82,9 @@ void VideoCodecUnitTest::FakeDecodeCompleteCallback::Decoded( } void VideoCodecUnitTest::SetUp() { + EnvironmentFactory factory(env_); + factory.Set(field_trials_.CreateCopy()); + env_ = factory.Create(); test::CodecSettings(kVideoCodecVP8, &codec_settings_); codec_settings_.startBitrate = kStartBitrate; codec_settings_.maxBitrate = kMaxBitrate; diff --git a/third_party/libwebrtc/modules/video_coding/codecs/test/video_codec_unittest.h b/third_party/libwebrtc/modules/video_coding/codecs/test/video_codec_unittest.h @@ -40,7 +40,7 @@ class VideoCodecUnitTest : public ::testing::Test { public: VideoCodecUnitTest() : field_trials_(CreateTestFieldTrials()), - env_(CreateEnvironment(&field_trials_)), + env_(CreateEnvironment(field_trials_.CreateCopy())), encode_complete_callback_(this), decode_complete_callback_(this), wait_for_encoded_frames_threshold_(1), @@ -109,7 +109,7 @@ class VideoCodecUnitTest : public ::testing::Test { size_t GetNumEncodedFrames(); FieldTrials field_trials_; - const Environment env_; + Environment env_; VideoCodec codec_settings_; std::unique_ptr<VideoEncoder> encoder_; diff --git a/third_party/libwebrtc/moz-patch-stack/s0027.patch b/third_party/libwebrtc/moz-patch-stack/s0027.patch @@ -203,7 +203,7 @@ index 3efce2dd19..cbfc05f243 100644 } diff --git a/api/BUILD.gn b/api/BUILD.gn -index bdb7239070..04b8afc63d 100644 +index 02ca836077..5a072619ee 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -44,6 +44,9 @@ rtc_library("enable_media") { diff --git a/third_party/libwebrtc/moz-patch-stack/s0102.patch b/third_party/libwebrtc/moz-patch-stack/s0102.patch @@ -126,7 +126,7 @@ index 771e0b196a..7e1e8353ab 100644 "Generated during 'gn gen' by //BUILD.gn.", "", diff --git a/api/BUILD.gn b/api/BUILD.gn -index 04b8afc63d..662d798bd0 100644 +index 5a072619ee..84569eb8c6 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -8,8 +8,8 @@ diff --git a/third_party/libwebrtc/pc/media_session_unittest.cc b/third_party/libwebrtc/pc/media_session_unittest.cc @@ -530,8 +530,8 @@ MediaSessionOptions CreateAudioMediaSession() { // these tests may be obsolete as a result, and should be refactored or removed. class MediaSessionDescriptionFactoryTest : public testing::Test { public: - MediaSessionDescriptionFactoryTest() - : field_trials_(CreateTestFieldTrials()), + MediaSessionDescriptionFactoryTest(absl::string_view field_trials_string = "") + : field_trials_(CreateTestFieldTrials(field_trials_string)), tdf1_(field_trials_), tdf2_(field_trials_), codec_lookup_helper_1_(field_trials_), @@ -3657,10 +3657,16 @@ TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateMultipleRtxSsrcs) { EXPECT_EQ(3u, fid_ssrcs.size()); } +class MediaSessionDescriptionFactoryFecTest + : public MediaSessionDescriptionFactoryTest { + public: + MediaSessionDescriptionFactoryFecTest() + : MediaSessionDescriptionFactoryTest("WebRTC-FlexFEC-03/Enabled/") {} +}; + // Test that, when the FlexFEC codec is added, a FlexFEC ssrc is created // together with a FEC-FR grouping. Guarded by WebRTC-FlexFEC-03 trial. -TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { - field_trials_.Set("WebRTC-FlexFEC-03", "Enabled"); +TEST_F(MediaSessionDescriptionFactoryFecTest, GenerateFlexfecSsrc) { MediaSessionOptions opts; AddMediaDescriptionOptions(webrtc::MediaType::VIDEO, kVideoMid, RtpTransceiverDirection::kSendRecv, kActive, @@ -3702,8 +3708,7 @@ TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { // Test that FlexFEC is disabled for simulcast. // TODO(brandtr): Remove this test when we support simulcast, either through // multiple FlexfecSenders, or through multistream protection. -TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateNoFlexfecSsrcs) { - field_trials_.Set("WebRTC-FlexFEC-03", "Enabled"); +TEST_F(MediaSessionDescriptionFactoryFecTest, SimSsrcsGenerateNoFlexfecSsrcs) { MediaSessionOptions opts; AddMediaDescriptionOptions(webrtc::MediaType::VIDEO, kVideoMid, RtpTransceiverDirection::kSendRecv, kActive, diff --git a/third_party/libwebrtc/video/video_send_stream_impl_unittest.cc b/third_party/libwebrtc/video/video_send_stream_impl_unittest.cc @@ -25,6 +25,7 @@ #include "api/call/bitrate_allocation.h" #include "api/environment/environment_factory.h" #include "api/field_trials.h" +#include "api/field_trials_view.h" #include "api/rtc_event_log/rtc_event_log.h" #include "api/rtp_parameters.h" #include "api/task_queue/task_queue_base.h" @@ -187,7 +188,8 @@ class VideoSendStreamImplTest : public ::testing::Test { } std::unique_ptr<VideoSendStreamImpl> CreateVideoSendStreamImpl( - VideoEncoderConfig encoder_config) { + VideoEncoderConfig encoder_config, + const FieldTrialsView* field_trials = nullptr) { EXPECT_CALL(bitrate_allocator_, GetStartBitrate).WillOnce(Return(123000)); std::map<uint32_t, RtpState> suspended_ssrcs; @@ -198,7 +200,8 @@ class VideoSendStreamImplTest : public ::testing::Test { video_stream_encoder_ = video_stream_encoder.get(); auto ret = std::make_unique<VideoSendStreamImpl>( - CreateEnvironment(&field_trials_, time_controller_.GetClock(), + CreateEnvironment(field_trials ? field_trials : &field_trials_, + time_controller_.GetClock(), time_controller_.GetTaskQueueFactory()), /*num_cpu_cores=*/1, /*call_stats=*/nullptr, &transport_controller_, @@ -215,6 +218,12 @@ class VideoSendStreamImplTest : public ::testing::Test { return ret; } + FieldTrials SetFieldTrial(absl::string_view key, absl::string_view value) { + FieldTrials copy(field_trials_); + copy.Set(key, value); + return copy; + } + protected: GlobalSimulatedTimeController time_controller_; FieldTrials field_trials_; @@ -509,11 +518,13 @@ TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChangeWithAlr) { TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChangeWithSimulcastVideoHysteresis) { - field_trials_.Set("WebRTC-VideoRateControl", "video_hysteresis:1.25"); + auto field_trials = + SetFieldTrial("WebRTC-VideoRateControl", "video_hysteresis:1.25"); config_.rtp.ssrcs.emplace_back(1); config_.rtp.ssrcs.emplace_back(2); - auto vss_impl = CreateVideoSendStreamImpl(TestVideoEncoderConfig()); + auto vss_impl = + CreateVideoSendStreamImpl(TestVideoEncoderConfig(), &field_trials); vss_impl->Start(); // 2-layer video simulcast. @@ -565,7 +576,8 @@ TEST_F(VideoSendStreamImplTest, } TEST_F(VideoSendStreamImplTest, SetsScreensharePacingFactorWithFeedback) { - field_trials_.Set(AlrExperimentSettings::kScreenshareProbingBweExperimentName, + auto field_trials = + SetFieldTrial(AlrExperimentSettings::kScreenshareProbingBweExperimentName, kAlrProbingExperimentValue); constexpr int kId = 1; @@ -575,16 +587,19 @@ TEST_F(VideoSendStreamImplTest, SetsScreensharePacingFactorWithFeedback) { SetPacingFactor(kAlrProbingExperimentPaceMultiplier)) .Times(1); auto vss_impl = CreateVideoSendStreamImpl( - TestVideoEncoderConfig(VideoEncoderConfig::ContentType::kScreen)); + TestVideoEncoderConfig(VideoEncoderConfig::ContentType::kScreen), + &field_trials); vss_impl->Start(); vss_impl->Stop(); } TEST_F(VideoSendStreamImplTest, DoesNotSetPacingFactorWithoutFeedback) { - field_trials_.Set(AlrExperimentSettings::kScreenshareProbingBweExperimentName, + auto field_trials = + SetFieldTrial(AlrExperimentSettings::kScreenshareProbingBweExperimentName, kAlrProbingExperimentValue); auto vss_impl = CreateVideoSendStreamImpl( - TestVideoEncoderConfig(VideoEncoderConfig::ContentType::kScreen)); + TestVideoEncoderConfig(VideoEncoderConfig::ContentType::kScreen), + &field_trials); EXPECT_CALL(transport_controller_, SetPacingFactor(_)).Times(0); vss_impl->Start(); vss_impl->Stop(); @@ -851,9 +866,11 @@ TEST_F(VideoSendStreamImplTest, PriorityBitrateConfigInactiveByDefault) { } TEST_F(VideoSendStreamImplTest, PriorityBitrateConfigAffectsAV1) { - field_trials_.Set("WebRTC-AV1-OverridePriorityBitrate", "bitrate:20000"); + auto field_trials = + SetFieldTrial("WebRTC-AV1-OverridePriorityBitrate", "bitrate:20000"); config_.rtp.payload_name = "AV1"; - auto vss_impl = CreateVideoSendStreamImpl(TestVideoEncoderConfig()); + auto vss_impl = + CreateVideoSendStreamImpl(TestVideoEncoderConfig(), &field_trials); EXPECT_CALL( bitrate_allocator_, AddObserver( @@ -878,9 +895,11 @@ TEST_F(VideoSendStreamImplTest, int min_transmit_bitrate_bps = 30000; - field_trials_.Set("WebRTC-AV1-OverridePriorityBitrate", "bitrate:20000"); + auto field_trials = + SetFieldTrial("WebRTC-AV1-OverridePriorityBitrate", "bitrate:20000"); config_.rtp.payload_name = "AV1"; - auto vss_impl = CreateVideoSendStreamImpl(TestVideoEncoderConfig()); + auto vss_impl = + CreateVideoSendStreamImpl(TestVideoEncoderConfig(), &field_trials); EXPECT_CALL( bitrate_allocator_, AddObserver( diff --git a/third_party/libwebrtc/video/video_stream_encoder_unittest.cc b/third_party/libwebrtc/video/video_stream_encoder_unittest.cc @@ -23,6 +23,7 @@ #include "absl/algorithm/container.h" #include "absl/container/inlined_vector.h" #include "absl/functional/any_invocable.h" +#include "absl/strings/string_view.h" #include "api/adaptation/resource.h" #include "api/array_view.h" #include "api/environment/environment.h" @@ -919,13 +920,20 @@ class VideoStreamEncoderTest : public ::testing::Test { ConfigureEncoder(std::move(video_encoder_config)); } + FieldTrials SetFieldTrial(absl::string_view key, absl::string_view value) { + FieldTrials copy(field_trials_); + copy.Set(key, value); + return copy; + } + void ConfigureEncoder( VideoEncoderConfig video_encoder_config, VideoStreamEncoder::BitrateAllocationCallbackType allocation_callback_type = VideoStreamEncoder::BitrateAllocationCallbackType:: kVideoBitrateAllocationWhenScreenSharing, - int num_cores = 1) { + int num_cores = 1, + const FieldTrialsView* field_trials = nullptr) { if (video_stream_encoder_) video_stream_encoder_->Stop(); @@ -935,7 +943,14 @@ class VideoStreamEncoderTest : public ::testing::Test { std::unique_ptr<FrameCadenceAdapterInterface> cadence_adapter = FrameCadenceAdapterInterface::Create( time_controller_.GetClock(), encoder_queue_ptr, - /*metronome=*/nullptr, /*worker_queue=*/nullptr, field_trials_); + /*metronome=*/nullptr, /*worker_queue=*/nullptr, + field_trials ? *field_trials : field_trials_); + if (field_trials) { + auto factory = EnvironmentFactory(env_); + factory.Set(field_trials->CreateCopy()); + env_ = factory.Create(); + } + video_stream_encoder_ = std::make_unique<VideoStreamEncoderUnderTest>( env_, &time_controller_, std::move(cadence_adapter), std::move(encoder_queue), stats_proxy_.get(), @@ -960,7 +975,8 @@ class VideoStreamEncoderTest : public ::testing::Test { allocation_callback_type = VideoStreamEncoder::BitrateAllocationCallbackType:: kVideoBitrateAllocationWhenScreenSharing, - int num_cores = 1) { + int num_cores = 1, + const FieldTrialsView* field_trials = nullptr) { video_send_config_.rtp.payload_name = payload_name; VideoEncoderConfig video_encoder_config; @@ -986,7 +1002,7 @@ class VideoStreamEncoderTest : public ::testing::Test { vp9_settings); } ConfigureEncoder(std::move(video_encoder_config), allocation_callback_type, - num_cores); + num_cores, field_trials); } VideoFrame CreateFrame(int64_t ntp_time_ms, Event* destruction_event) const { @@ -1694,10 +1710,9 @@ class VideoStreamEncoderTest : public ::testing::Test { protected: FieldTrials field_trials_ = CreateTestFieldTrials(); GlobalSimulatedTimeController time_controller_{Timestamp::Micros(1234)}; - const Environment env_ = - CreateEnvironment(&field_trials_, - time_controller_.GetClock(), - time_controller_.GetTaskQueueFactory()); + Environment env_ = CreateEnvironment(&field_trials_, + time_controller_.GetClock(), + time_controller_.GetTaskQueueFactory()); VideoSendStream::Config video_send_config_; VideoEncoderConfig video_encoder_config_; int codec_width_; @@ -4554,9 +4569,14 @@ TEST_F(VideoStreamEncoderTest, DropFirstFramesIfBwEstimateIsTooLow) { class BalancedDegradationTest : public VideoStreamEncoderTest { protected: - void SetupTest() { + void SetupTestWithFieldTrial(absl::string_view key, absl::string_view value) { + extra_trials_ = std::make_unique<FieldTrials>(field_trials_); + extra_trials_->Set(key, value); // Reset encoder for field trials to take effect. - ConfigureEncoder(video_encoder_config_.Copy()); + ConfigureEncoder(video_encoder_config_.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoLayersAllocation, + /* num_cores= */ 1, extra_trials_.get()); OnBitrateUpdated(kTargetBitrate); // Enable BALANCED preference. @@ -4584,12 +4604,13 @@ class BalancedDegradationTest : public VideoStreamEncoderTest { const int64_t kFrameIntervalMs = 150; // Use low fps to not drop any frame. int64_t timestamp_ms_ = 0; AdaptingFrameForwarder source_{&time_controller_}; + std::unique_ptr<FieldTrials> extra_trials_; }; TEST_F(BalancedDegradationTest, AdaptDownTwiceIfMinFpsDiffLtThreshold) { - field_trials_.Set("WebRTC-Video-BalancedDegradationSettings", - "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1"); - SetupTest(); + SetupTestWithFieldTrial( + "WebRTC-Video-BalancedDegradationSettings", + "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1"); // Force input frame rate. const int kInputFps = 24; @@ -4610,9 +4631,9 @@ TEST_F(BalancedDegradationTest, AdaptDownTwiceIfMinFpsDiffLtThreshold) { } TEST_F(BalancedDegradationTest, AdaptDownOnceIfFpsDiffGeThreshold) { - field_trials_.Set("WebRTC-Video-BalancedDegradationSettings", - "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1"); - SetupTest(); + SetupTestWithFieldTrial( + "WebRTC-Video-BalancedDegradationSettings", + "pixels:57600|129600|230400,fps:7|10|24,fps_diff:1|1|1"); // Force input frame rate. const int kInputFps = 25; @@ -4632,9 +4653,9 @@ TEST_F(BalancedDegradationTest, AdaptDownOnceIfFpsDiffGeThreshold) { } TEST_F(BalancedDegradationTest, AdaptDownUsesCodecSpecificFps) { - field_trials_.Set("WebRTC-Video-BalancedDegradationSettings", - "pixels:57600|129600|230400,fps:7|10|24,vp8_fps:8|11|22"); - SetupTest(); + SetupTestWithFieldTrial( + "WebRTC-Video-BalancedDegradationSettings", + "pixels:57600|129600|230400,fps:7|10|24,vp8_fps:8|11|22"); EXPECT_EQ(kVideoCodecVP8, video_encoder_config_.codec_type); @@ -4649,9 +4670,9 @@ TEST_F(BalancedDegradationTest, AdaptDownUsesCodecSpecificFps) { } TEST_F(BalancedDegradationTest, NoAdaptUpIfBwEstimateIsLessThanMinBitrate) { - field_trials_.Set("WebRTC-Video-BalancedDegradationSettings", - "pixels:57600|129600|230400,fps:7|10|14,kbps:0|0|425"); - SetupTest(); + SetupTestWithFieldTrial( + "WebRTC-Video-BalancedDegradationSettings", + "pixels:57600|129600|230400,fps:7|10|14,kbps:0|0|425"); const DataRate kMinBitrate = DataRate::KilobitsPerSec(425); const DataRate kTooLowMinBitrate = DataRate::KilobitsPerSec(424); @@ -4697,9 +4718,8 @@ TEST_F(BalancedDegradationTest, NoAdaptUpIfBwEstimateIsLessThanMinBitrate) { TEST_F(BalancedDegradationTest, InitialFrameDropAdaptsFpsAndResolutionInOneStep) { - field_trials_.Set("WebRTC-Video-BalancedDegradationSettings", - "pixels:57600|129600|230400,fps:7|24|24"); - SetupTest(); + SetupTestWithFieldTrial("WebRTC-Video-BalancedDegradationSettings", + "pixels:57600|129600|230400,fps:7|24|24"); OnBitrateUpdated(kLowTargetBitrate); EXPECT_THAT(source_.sink_wants(), UnlimitedSinkWants()); @@ -4727,9 +4747,9 @@ TEST_F(BalancedDegradationTest, TEST_F(BalancedDegradationTest, NoAdaptUpInResolutionIfBwEstimateIsLessThanMinBitrate) { - field_trials_.Set("WebRTC-Video-BalancedDegradationSettings", - "pixels:57600|129600|230400,fps:7|10|14,kbps_res:0|0|435"); - SetupTest(); + SetupTestWithFieldTrial( + "WebRTC-Video-BalancedDegradationSettings", + "pixels:57600|129600|230400,fps:7|10|14,kbps_res:0|0|435"); const DataRate kResolutionMinBitrate = DataRate::KilobitsPerSec(435); const DataRate kTooLowMinResolutionBitrate = DataRate::KilobitsPerSec(434); @@ -4780,10 +4800,9 @@ TEST_F(BalancedDegradationTest, TEST_F(BalancedDegradationTest, NoAdaptUpInFpsAndResolutionIfBwEstimateIsLessThanMinBitrate) { - field_trials_.Set( + SetupTestWithFieldTrial( "WebRTC-Video-BalancedDegradationSettings", "pixels:57600|129600|230400,fps:7|10|14,kbps:0|0|425,kbps_res:0|0|435"); - SetupTest(); const DataRate kMinBitrate = DataRate::KilobitsPerSec(425); const DataRate kTooLowMinBitrate = DataRate::KilobitsPerSec(424); @@ -5678,11 +5697,14 @@ TEST_F(VideoStreamEncoderTest, TemporalLayersDisabledIfNotSupported) { } TEST_F(VideoStreamEncoderTest, VerifyBitrateAllocationForTwoStreams) { - field_trials_.Set( + auto field_trials = SetFieldTrial( "WebRTC-Video-QualityScalerSettings", "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2"); // Reset encoder for field trials to take effect. - ConfigureEncoder(video_encoder_config_.Copy()); + ConfigureEncoder(video_encoder_config_.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); // 2 TLs configured, temporal layers only supported for first stream. ResetEncoder("VP8", 2, /*num_temporal_layers*/ 2, 1, /*screenshare*/ false, @@ -5984,11 +6006,15 @@ TEST_F(VideoStreamEncoderTest, InitialFrameDropOffWhenEncoderDisabledScaling) { } TEST_F(VideoStreamEncoderTest, InitialFrameDropActivatesWhenBweDrops) { - field_trials_.Set( + auto field_trials = SetFieldTrial( "WebRTC-Video-QualityScalerSettings", "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2"); // Reset encoder for field trials to take effect. - ConfigureEncoder(video_encoder_config_.Copy()); + ConfigureEncoder(video_encoder_config_.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); + const int kNotTooLowBitrateForFrameSizeBps = kTargetBitrate.bps() * 0.2; const int kTooLowBitrateForFrameSizeBps = kTargetBitrate.bps() * 0.19; const int kWidth = 640; @@ -6024,11 +6050,15 @@ TEST_F(VideoStreamEncoderTest, InitialFrameDropActivatesWhenBweDrops) { TEST_F(VideoStreamEncoderTest, InitialFrameDropNotReactivatedWhenBweDropsWhenScalingDisabled) { - field_trials_.Set( + auto field_trials = SetFieldTrial( "WebRTC-Video-QualityScalerSettings", "initial_bitrate_interval_ms:1000,initial_bitrate_factor:0.2"); fake_encoder_.SetQualityScaling(false); - ConfigureEncoder(video_encoder_config_.Copy()); + ConfigureEncoder(video_encoder_config_.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); + const int kNotTooLowBitrateForFrameSizeBps = kTargetBitrate.bps() * 0.2; const int kTooLowBitrateForFrameSizeBps = kTargetBitrate.bps() * 0.19; const int kWidth = 640; @@ -6352,7 +6382,8 @@ TEST_F(VideoStreamEncoderTest, } TEST_F(VideoStreamEncoderTest, DefaultMaxAndMinBitratesNotUsedIfDisabled) { - field_trials_.Set("WebRTC-DefaultBitrateLimitsKillSwitch", "Enabled"); + auto field_trials = + SetFieldTrial("WebRTC-DefaultBitrateLimitsKillSwitch", "Enabled"); VideoEncoderConfig video_encoder_config; test::FillEncoderConfiguration(PayloadStringToCodecType("VP9"), 1, &video_encoder_config); @@ -6373,7 +6404,10 @@ TEST_F(VideoStreamEncoderTest, DefaultMaxAndMinBitratesNotUsedIfDisabled) { video_encoder_config.simulcast_layers[2].active = false; // Reset encoder for field trials to take effect. - ConfigureEncoder(video_encoder_config.Copy()); + ConfigureEncoder(video_encoder_config.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); video_stream_encoder_->ConfigureEncoder(video_encoder_config.Copy(), kMaxPayloadLength); @@ -6714,7 +6748,13 @@ TEST_P(VideoStreamEncoderInitialFrameDropperTest, TEST_F(VideoStreamEncoderTest, QualityScalerAdaptationsRemovedWhenQualityScalingDisabled) { - field_trials_.Set("WebRTC-Video-QualityScaling", "Disabled"); + // Reset encoder for new configuration to take effect. + auto field_trials = SetFieldTrial("WebRTC-Video-QualityScaling", "Disabled"); + ConfigureEncoder(video_encoder_config_.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); + AdaptingFrameForwarder source(&time_controller_); source.set_adaptation_enabled(true); video_stream_encoder_->SetSource(&source, @@ -8232,8 +8272,8 @@ TEST_F(VideoStreamEncoderTest, SwitchEncoderOnInitFailureWithEncoderSelector) { TEST_F(VideoStreamEncoderTest, SwitchEncoderOnInitFailureWithoutEncoderSelector) { - field_trials_.Set("WebRTC-SwitchEncoderFollowCodecPreferenceOrder", - "Disabled"); + auto field_trials = SetFieldTrial( + "WebRTC-SwitchEncoderFollowCodecPreferenceOrder", "Disabled"); NiceMock<MockVideoEncoder> video_encoder; StrictMock<MockEncoderSwitchRequestCallback> switch_callback; @@ -8244,7 +8284,10 @@ TEST_F(VideoStreamEncoderTest, video_send_config_.encoder_settings.encoder_factory = encoder_factory.get(); // Reset encoder for new configuration to take effect. - ConfigureEncoder(video_encoder_config_.Copy()); + ConfigureEncoder(video_encoder_config_.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources( kTargetBitrate, kTargetBitrate, /*fraction_lost=*/0, @@ -8388,8 +8431,8 @@ TEST_F(VideoStreamEncoderTest, constexpr int kDontCare = 100; constexpr int kNumFrames = 8; - field_trials_.Set("WebRTC-SwitchEncoderFollowCodecPreferenceOrder", - "Enabled"); + auto field_trials = SetFieldTrial( + "WebRTC-SwitchEncoderFollowCodecPreferenceOrder", "Enabled"); NiceMock<MockVideoEncoder> video_encoder; StrictMock<MockEncoderSwitchRequestCallback> switch_callback; @@ -8400,7 +8443,10 @@ TEST_F(VideoStreamEncoderTest, video_send_config_.encoder_settings.encoder_factory = encoder_factory.get(); // Reset encoder for new configuration to take effect. - ConfigureEncoder(video_encoder_config_.Copy()); + ConfigureEncoder(video_encoder_config_.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); // The VideoStreamEncoder needs some bitrate before it can start encoding, // setting some bitrate so that subsequent calls to WaitForEncodedFrame does @@ -8460,8 +8506,8 @@ TEST_F(VideoStreamEncoderTest, NoPreferenceDefaultFallbackToVP8Enabled) { constexpr int kSufficientBitrateToNotDrop = 1000; constexpr int kDontCare = 100; - field_trials_.Set("WebRTC-SwitchEncoderFollowCodecPreferenceOrder", - "Disabled"); + auto field_trials = SetFieldTrial( + "WebRTC-SwitchEncoderFollowCodecPreferenceOrder", "Disabled"); NiceMock<MockVideoEncoder> video_encoder; StrictMock<MockEncoderSwitchRequestCallback> switch_callback; @@ -8473,7 +8519,10 @@ TEST_F(VideoStreamEncoderTest, NoPreferenceDefaultFallbackToVP8Enabled) { video_encoder_config_.codec_type = kVideoCodecVP9; // Reset encoder for new configuration to take effect. - ConfigureEncoder(video_encoder_config_.Copy()); + ConfigureEncoder(video_encoder_config_.Copy(), + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); // The VideoStreamEncoder needs some bitrate before it can start encoding, // setting some bitrate so that subsequent calls to WaitForEncodedFrame does @@ -8919,9 +8968,12 @@ TEST_F(VideoStreamEncoderTest, QpAbsent_QpParsed) { } TEST_F(VideoStreamEncoderTest, QpAbsentParsingDisabled_QpAbsent) { - field_trials_.Set("WebRTC-QpParsingKillSwitch", "Enabled"); + auto field_trials = SetFieldTrial("WebRTC-QpParsingKillSwitch", "Enabled"); - ResetEncoder("VP8", 1, 1, 1, false); + ResetEncoder("VP8", 1, 1, 1, false, kDefaultFramerate, + VideoStreamEncoder::BitrateAllocationCallbackType:: + kVideoBitrateAllocationWhenScreenSharing, + /* num_cores= */ 1, &field_trials); // Force encoder reconfig. video_source_.IncomingCapturedFrame( @@ -9198,7 +9250,8 @@ TEST_F(VideoStreamEncoderTest, NormalComplexityWithMoreThanTwoCores) { TEST_F(VideoStreamEncoderTest, NormalComplexityWhenLowTierOptimizationsAreDisabled) { - field_trials_.Set("WebRTC-VP9-LowTierOptimizations", "Disabled"); + auto field_trials = + SetFieldTrial("WebRTC-VP9-LowTierOptimizations", "Disabled"); ResetEncoder("VP9", /*num_streams=*/1, /*num_temporal_layers=*/1, /*num_spatial_layers=*/1, @@ -9206,7 +9259,7 @@ TEST_F(VideoStreamEncoderTest, kDefaultFramerate, /*allocation_callback_type=*/ VideoStreamEncoder::BitrateAllocationCallbackType:: kVideoBitrateAllocationWhenScreenSharing, - /*num_cores=*/2); + /*num_cores=*/2, &field_trials); video_stream_encoder_->OnBitrateUpdatedAndWaitForManagedResources( kTargetBitrate, kTargetBitrate, 0, 0, 0);