Keep Environment instead of test field trials in FakeCall test object
To pass field trials to EncoderStreamFactory in FakeVideoSendStream and thus reduce dependency on the global field trial.
Bug: webrtc:10335
Change-Id: Iad32881c2d9158fe1d77f1b71f8d606374ea111e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/346340
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42023}
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 794f7a1..2a05940 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -720,8 +720,8 @@
":media_channel",
":rtc_data_sctp_transport_internal",
"../api:array_view",
- "../api/environment",
"../api:libjingle_peerconnection_api",
+ "../api/environment",
"../api/task_queue:pending_task_safety_flag",
"../api/task_queue:task_queue",
"../net/dcsctp/public:factory",
@@ -812,7 +812,6 @@
"../api/environment",
"../api/task_queue",
"../api/task_queue:pending_task_safety_flag",
- "../api/transport:field_trial_based_config",
"../api/units:timestamp",
"../api/video:encoded_image",
"../api/video:video_bitrate_allocation",
@@ -844,7 +843,6 @@
"../rtc_base:timeutils",
"../rtc_base/synchronization:mutex",
"../rtc_base/third_party/sigslot",
- "../test:scoped_key_value_config",
"../test:test_support",
"../video/config:streams_config",
"//testing/gtest",
diff --git a/media/engine/fake_webrtc_call.cc b/media/engine/fake_webrtc_call.cc
index 2536c9d..8ca7880 100644
--- a/media/engine/fake_webrtc_call.cc
+++ b/media/engine/fake_webrtc_call.cc
@@ -16,6 +16,7 @@
#include "absl/algorithm/container.h"
#include "absl/strings/string_view.h"
#include "api/call/audio_sink.h"
+#include "api/environment/environment.h"
#include "api/units/timestamp.h"
#include "call/packet_receiver.h"
#include "media/base/media_channel.h"
@@ -27,6 +28,7 @@
namespace cricket {
+using ::webrtc::Environment;
using ::webrtc::ParseRtpSsrc;
FakeAudioSendStream::FakeAudioSendStream(
@@ -144,9 +146,11 @@
}
FakeVideoSendStream::FakeVideoSendStream(
+ const Environment& env,
webrtc::VideoSendStream::Config config,
webrtc::VideoEncoderConfig encoder_config)
- : sending_(false),
+ : env_(env),
+ sending_(false),
config_(std::move(config)),
codec_settings_set_(false),
resolution_scaling_enabled_(false),
@@ -256,7 +260,8 @@
encoder_config_.video_format.name, encoder_config_.max_qp,
encoder_config_.content_type ==
webrtc::VideoEncoderConfig::ContentType::kScreen,
- encoder_config_.legacy_conference_mode, encoder_info);
+ encoder_config_.legacy_conference_mode, encoder_info,
+ absl::nullopt, &env_.field_trials());
video_streams_ = factory->CreateEncoderStreams(
frame.width(), frame.height(), encoder_config_);
@@ -444,19 +449,19 @@
RTC_DCHECK_NOTREACHED() << "Not implemented.";
}
-FakeCall::FakeCall(webrtc::test::ScopedKeyValueConfig* field_trials)
- : FakeCall(rtc::Thread::Current(), rtc::Thread::Current(), field_trials) {}
+FakeCall::FakeCall(const Environment& env)
+ : FakeCall(env, rtc::Thread::Current(), rtc::Thread::Current()) {}
-FakeCall::FakeCall(webrtc::TaskQueueBase* worker_thread,
- webrtc::TaskQueueBase* network_thread,
- webrtc::test::ScopedKeyValueConfig* field_trials)
- : network_thread_(network_thread),
+FakeCall::FakeCall(const Environment& env,
+ webrtc::TaskQueueBase* worker_thread,
+ webrtc::TaskQueueBase* network_thread)
+ : env_(env),
+ network_thread_(network_thread),
worker_thread_(worker_thread),
audio_network_state_(webrtc::kNetworkUp),
video_network_state_(webrtc::kNetworkUp),
num_created_send_streams_(0),
- num_created_receive_streams_(0),
- trials_(field_trials ? field_trials : &fallback_trials_) {}
+ num_created_receive_streams_(0) {}
FakeCall::~FakeCall() {
EXPECT_EQ(0u, video_send_streams_.size());
@@ -574,8 +579,8 @@
webrtc::VideoSendStream* FakeCall::CreateVideoSendStream(
webrtc::VideoSendStream::Config config,
webrtc::VideoEncoderConfig encoder_config) {
- FakeVideoSendStream* fake_stream =
- new FakeVideoSendStream(std::move(config), std::move(encoder_config));
+ FakeVideoSendStream* fake_stream = new FakeVideoSendStream(
+ env_, std::move(config), std::move(encoder_config));
video_send_streams_.push_back(fake_stream);
++num_created_send_streams_;
return fake_stream;
diff --git a/media/engine/fake_webrtc_call.h b/media/engine/fake_webrtc_call.h
index d67a7ee..9a6bc0a 100644
--- a/media/engine/fake_webrtc_call.h
+++ b/media/engine/fake_webrtc_call.h
@@ -27,7 +27,7 @@
#include <vector>
#include "absl/strings/string_view.h"
-#include "api/transport/field_trial_based_config.h"
+#include "api/environment/environment.h"
#include "api/video/video_frame.h"
#include "call/audio_receive_stream.h"
#include "call/audio_send_stream.h"
@@ -38,7 +38,6 @@
#include "call/video_send_stream.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "rtc_base/buffer.h"
-#include "test/scoped_key_value_config.h"
namespace cricket {
class FakeAudioSendStream final : public webrtc::AudioSendStream {
@@ -158,7 +157,8 @@
: public webrtc::VideoSendStream,
public rtc::VideoSinkInterface<webrtc::VideoFrame> {
public:
- FakeVideoSendStream(webrtc::VideoSendStream::Config config,
+ FakeVideoSendStream(const webrtc::Environment& env,
+ webrtc::VideoSendStream::Config config,
webrtc::VideoEncoderConfig encoder_config);
~FakeVideoSendStream() override;
const webrtc::VideoSendStream::Config& GetConfig() const;
@@ -215,6 +215,7 @@
void ReconfigureVideoEncoder(webrtc::VideoEncoderConfig config,
webrtc::SetParametersCallback callback) override;
+ const webrtc::Environment env_;
bool sending_;
webrtc::VideoSendStream::Config config_;
webrtc::VideoEncoderConfig encoder_config_;
@@ -363,10 +364,10 @@
class FakeCall final : public webrtc::Call, public webrtc::PacketReceiver {
public:
- explicit FakeCall(webrtc::test::ScopedKeyValueConfig* field_trials = nullptr);
- FakeCall(webrtc::TaskQueueBase* worker_thread,
- webrtc::TaskQueueBase* network_thread,
- webrtc::test::ScopedKeyValueConfig* field_trials = nullptr);
+ explicit FakeCall(const webrtc::Environment& env);
+ FakeCall(const webrtc::Environment& env,
+ webrtc::TaskQueueBase* worker_thread,
+ webrtc::TaskQueueBase* network_thread);
~FakeCall() override;
webrtc::MockRtpTransportControllerSend* GetMockTransportControllerSend() {
@@ -406,14 +407,10 @@
void SetClientBitratePreferences(
const webrtc::BitrateSettings& preferences) override {}
-
- void SetFieldTrial(const std::string& field_trial_string) {
- trials_overrides_ = std::make_unique<webrtc::test::ScopedKeyValueConfig>(
- *trials_, field_trial_string);
+ const webrtc::FieldTrialsView& trials() const override {
+ return env_.field_trials();
}
- const webrtc::FieldTrialsView& trials() const override { return *trials_; }
-
private:
webrtc::AudioSendStream* CreateAudioSendStream(
const webrtc::AudioSendStream::Config& config) override;
@@ -480,6 +477,7 @@
absl::string_view sync_group) override;
void OnSentPacket(const rtc::SentPacket& sent_packet) override;
+ const webrtc::Environment env_;
webrtc::TaskQueueBase* const network_thread_;
webrtc::TaskQueueBase* const worker_thread_;
@@ -502,16 +500,6 @@
int num_created_send_streams_;
int num_created_receive_streams_;
-
- // The field trials that are in use, either supplied by caller
- // or pointer to &fallback_trials_.
- webrtc::test::ScopedKeyValueConfig* trials_;
-
- // fallback_trials_ is used if caller does not provide any field trials.
- webrtc::test::ScopedKeyValueConfig fallback_trials_;
-
- // An extra field trial that can be set using SetFieldTrial.
- std::unique_ptr<webrtc::test::ScopedKeyValueConfig> trials_overrides_;
};
} // namespace cricket
diff --git a/media/engine/webrtc_video_engine_unittest.cc b/media/engine/webrtc_video_engine_unittest.cc
index 403d58a..ca69dca 100644
--- a/media/engine/webrtc_video_engine_unittest.cc
+++ b/media/engine/webrtc_video_engine_unittest.cc
@@ -747,7 +747,7 @@
TEST_F(WebRtcVideoEngineTest, PropagatesInputFrameTimestamp) {
AddSupportedVideoCodecType("VP8");
- FakeCall* fake_call = new FakeCall();
+ FakeCall* fake_call = new FakeCall(env_);
call_.reset(fake_call);
auto send_channel = SetSendParamsWithAllSupportedCodecs();
@@ -1476,7 +1476,7 @@
TEST_F(WebRtcVideoEngineTest, DISABLED_RecreatesEncoderOnContentTypeChange) {
encoder_factory_->AddSupportedVideoCodecType("VP8");
- std::unique_ptr<FakeCall> fake_call(new FakeCall());
+ auto fake_call = std::make_unique<FakeCall>(env_);
auto send_channel = SetSendParamsWithAllSupportedCodecs();
ASSERT_TRUE(
@@ -2622,7 +2622,7 @@
AddSupportedVideoCodecType("H264");
#endif
- fake_call_.reset(new FakeCall(&field_trials_));
+ fake_call_ = std::make_unique<FakeCall>(env_);
send_channel_ = engine_.CreateSendChannel(
fake_call_.get(), GetMediaConfig(), VideoOptions(),
webrtc::CryptoOptions(), video_bitrate_allocator_factory_.get());
@@ -9489,7 +9489,7 @@
class WebRtcVideoChannelSimulcastTest : public ::testing::Test {
public:
WebRtcVideoChannelSimulcastTest()
- : fake_call_(),
+ : fake_call_(CreateEnvironment(&field_trials_)),
encoder_factory_(new cricket::FakeWebRtcVideoEncoderFactory),
decoder_factory_(new cricket::FakeWebRtcVideoDecoderFactory),
mock_rate_allocator_factory_(
diff --git a/media/engine/webrtc_voice_engine_unittest.cc b/media/engine/webrtc_voice_engine_unittest.cc
index d5efbca..852abd9 100644
--- a/media/engine/webrtc_voice_engine_unittest.cc
+++ b/media/engine/webrtc_voice_engine_unittest.cc
@@ -195,13 +195,13 @@
public:
WebRtcVoiceEngineTestFake()
: use_null_apm_(GetParam()),
- task_queue_factory_(webrtc::CreateDefaultTaskQueueFactory()),
+ env_(CreateEnvironment(&field_trials_)),
adm_(webrtc::test::MockAudioDeviceModule::CreateStrict()),
apm_(use_null_apm_
? nullptr
: rtc::make_ref_counted<
StrictMock<webrtc::test::MockAudioProcessing>>()),
- call_(&field_trials_) {
+ call_(env_) {
// AudioDeviceModule.
AdmSetupExpectations(adm_.get());
@@ -220,9 +220,9 @@
// factories. Those tests should probably be moved elsewhere.
auto encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
auto decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
- engine_.reset(new cricket::WebRtcVoiceEngine(
- task_queue_factory_.get(), adm_.get(), encoder_factory, decoder_factory,
- nullptr, apm_, nullptr, field_trials_));
+ engine_ = std::make_unique<cricket::WebRtcVoiceEngine>(
+ &env_.task_queue_factory(), adm_.get(), encoder_factory,
+ decoder_factory, nullptr, apm_, nullptr, env_.field_trials());
engine_->Init();
send_parameters_.codecs.push_back(kPcmuCodec);
recv_parameters_.codecs.push_back(kPcmuCodec);
@@ -846,7 +846,7 @@
rtc::AutoThread main_thread_;
const bool use_null_apm_;
webrtc::test::ScopedKeyValueConfig field_trials_;
- std::unique_ptr<webrtc::TaskQueueFactory> task_queue_factory_;
+ const Environment env_;
rtc::scoped_refptr<webrtc::test::MockAudioDeviceModule> adm_;
rtc::scoped_refptr<StrictMock<webrtc::test::MockAudioProcessing>> apm_;
cricket::FakeCall call_;
diff --git a/pc/rtp_sender_receiver_unittest.cc b/pc/rtp_sender_receiver_unittest.cc
index 4387aed..259b2d2 100644
--- a/pc/rtp_sender_receiver_unittest.cc
+++ b/pc/rtp_sender_receiver_unittest.cc
@@ -25,6 +25,7 @@
#include "api/crypto/frame_decryptor_interface.h"
#include "api/crypto/frame_encryptor_interface.h"
#include "api/dtmf_sender_interface.h"
+#include "api/environment/environment_factory.h"
#include "api/media_stream_interface.h"
#include "api/rtc_error.h"
#include "api/rtc_event_log/rtc_event_log.h"
@@ -109,7 +110,7 @@
// Create fake media engine/etc. so we can create channels to use to
// test RtpSenders/RtpReceivers.
media_engine_(std::make_unique<cricket::FakeMediaEngine>()),
- fake_call_(worker_thread_, network_thread_),
+ fake_call_(CreateEnvironment(), worker_thread_, network_thread_),
local_stream_(MediaStream::Create(kStreamId1)) {
rtp_dtls_transport_ = std::make_unique<cricket::FakeDtlsTransport>(
"fake_dtls_transport", cricket::ICE_CANDIDATE_COMPONENT_RTP);
diff --git a/video/video_receive_stream2_unittest.cc b/video/video_receive_stream2_unittest.cc
index f4802e4..5e0f1f0 100644
--- a/video/video_receive_stream2_unittest.cc
+++ b/video/video_receive_stream2_unittest.cc
@@ -199,6 +199,7 @@
config_(&mock_transport_, &mock_h264_decoder_factory_),
call_stats_(&env_.clock(), time_controller_.GetMainThread()),
fake_renderer_(&time_controller_),
+ fake_call_(env_),
fake_metronome_(TimeDelta::Millis(16)),
decode_sync_(&env_.clock(),
&fake_metronome_,