Skip to content

Commit

Permalink
WebRTC-DeprecateGlobalFieldTrialString/Enabled/ - part 19/inf
Browse files Browse the repository at this point in the history
Convert most field trials used in PCLF tests.

Change-Id: I26c0c4b1164bb0870aae1a488942cde888cb459d
Bug: webrtc:10335
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/322703
Commit-Queue: Jeremy Leconte <[email protected]>
Reviewed-by: Harald Alvestrand <[email protected]>
Reviewed-by: Jonas Oreland <[email protected]>
Cr-Commit-Position: refs/heads/main@{#40909}
  • Loading branch information
jleconte2 authored and WebRTC LUCI CQ committed Oct 11, 2023
1 parent c941579 commit 1a8d529
Show file tree
Hide file tree
Showing 23 changed files with 225 additions and 157 deletions.
4 changes: 3 additions & 1 deletion media/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,10 @@ rtc_library("rtc_simulcast_encoder_adapter") {
deps = [
":rtc_media_base",
"../api:fec_controller_api",
"../api:field_trials_view",
"../api:scoped_refptr",
"../api:sequence_checker",
"../api/transport:field_trial_based_config",
"../api/video:video_codec_constants",
"../api/video:video_frame",
"../api/video:video_rtp_headers",
Expand All @@ -357,7 +359,6 @@ rtc_library("rtc_simulcast_encoder_adapter") {
"../rtc_base/system:no_unique_address",
"../rtc_base/system:rtc_export",
"../system_wrappers",
"../system_wrappers:field_trial",
]
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
Expand Down Expand Up @@ -813,6 +814,7 @@ if (rtc_include_tests) {
":stream_params",
":turn_utils",
"../api:create_simulcast_test_fixture_api",
"../api:field_trials_view",
"../api:libjingle_peerconnection_api",
"../api:mock_encoder_selector",
"../api:mock_video_bitrate_allocator",
Expand Down
33 changes: 25 additions & 8 deletions media/engine/simulcast_encoder_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <utility>

#include "absl/algorithm/container.h"
#include "api/field_trials_view.h"
#include "api/scoped_refptr.h"
#include "api/transport/field_trial_based_config.h"
#include "api/video/i420_buffer.h"
#include "api/video/video_codec_constants.h"
#include "api/video/video_frame_buffer.h"
Expand All @@ -33,7 +35,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/experiments/rate_control_settings.h"
#include "rtc_base/logging.h"
#include "system_wrappers/include/field_trial.h"

namespace {

Expand All @@ -42,9 +43,10 @@ const unsigned int kDefaultMaxQp = 56;
// Max qp for lowest spatial resolution when doing simulcast.
const unsigned int kLowestResMaxQp = 45;

absl::optional<unsigned int> GetScreenshareBoostedQpValue() {
absl::optional<unsigned int> GetScreenshareBoostedQpValue(
const webrtc::FieldTrialsView& field_trials) {
std::string experiment_group =
webrtc::field_trial::FindFullName("WebRTC-BoostedScreenshareQp");
field_trials.Lookup("WebRTC-BoostedScreenshareQp");
unsigned int qp;
if (sscanf(experiment_group.c_str(), "%u", &qp) != 1)
return absl::nullopt;
Expand Down Expand Up @@ -244,23 +246,38 @@ void SimulcastEncoderAdapter::StreamContext::OnDroppedFrame(

SimulcastEncoderAdapter::SimulcastEncoderAdapter(VideoEncoderFactory* factory,
const SdpVideoFormat& format)
: SimulcastEncoderAdapter(factory, nullptr, format) {}
: SimulcastEncoderAdapter(factory,
nullptr,
format,
FieldTrialBasedConfig()) {}

SimulcastEncoderAdapter::SimulcastEncoderAdapter(
VideoEncoderFactory* primary_factory,
VideoEncoderFactory* fallback_factory,
const SdpVideoFormat& format)
: SimulcastEncoderAdapter(primary_factory,
fallback_factory,
format,
FieldTrialBasedConfig()) {}

SimulcastEncoderAdapter::SimulcastEncoderAdapter(
VideoEncoderFactory* primary_factory,
VideoEncoderFactory* fallback_factory,
const SdpVideoFormat& format,
const FieldTrialsView& field_trials)
: inited_(0),
primary_encoder_factory_(primary_factory),
fallback_encoder_factory_(fallback_factory),
video_format_(format),
total_streams_count_(0),
bypass_mode_(false),
encoded_complete_callback_(nullptr),
experimental_boosted_screenshare_qp_(GetScreenshareBoostedQpValue()),
boost_base_layer_quality_(RateControlSettings::ParseFromFieldTrials()
.Vp8BoostBaseLayerQuality()),
prefer_temporal_support_on_base_layer_(field_trial::IsEnabled(
experimental_boosted_screenshare_qp_(
GetScreenshareBoostedQpValue(field_trials)),
boost_base_layer_quality_(
RateControlSettings::ParseFromKeyValueConfig(&field_trials)
.Vp8BoostBaseLayerQuality()),
prefer_temporal_support_on_base_layer_(field_trials.IsEnabled(
"WebRTC-Video-PreferTemporalSupportOnBaseLayer")) {
RTC_DCHECK(primary_factory);

Expand Down
5 changes: 5 additions & 0 deletions media/engine/simulcast_encoder_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "absl/types/optional.h"
#include "api/fec_controller_override.h"
#include "api/field_trials_view.h"
#include "api/sequence_checker.h"
#include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_encoder.h"
Expand Down Expand Up @@ -49,6 +50,10 @@ class RTC_EXPORT SimulcastEncoderAdapter : public VideoEncoder {
SimulcastEncoderAdapter(VideoEncoderFactory* primary_factory,
VideoEncoderFactory* fallback_factory,
const SdpVideoFormat& format);
SimulcastEncoderAdapter(VideoEncoderFactory* primary_factory,
VideoEncoderFactory* fallback_factory,
const SdpVideoFormat& format,
const FieldTrialsView& field_trials);
~SimulcastEncoderAdapter() override;

// Implements VideoEncoder.
Expand Down
31 changes: 21 additions & 10 deletions media/engine/simulcast_encoder_adapter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <memory>
#include <vector>

#include "api/field_trials_view.h"
#include "api/test/create_simulcast_test_fixture.h"
#include "api/test/simulcast_test_fixture.h"
#include "api/test/video/function_video_decoder_factory.h"
Expand All @@ -29,9 +30,9 @@
#include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/utility/simulcast_test_fixture_impl.h"
#include "rtc_base/checks.h"
#include "test/field_trial.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"

using ::testing::_;
using ::testing::Return;
Expand Down Expand Up @@ -402,17 +403,20 @@ class TestSimulcastEncoderAdapterFakeHelper {
public:
explicit TestSimulcastEncoderAdapterFakeHelper(
bool use_fallback_factory,
const SdpVideoFormat& video_format)
const SdpVideoFormat& video_format,
const FieldTrialsView& field_trials)
: primary_factory_(new MockVideoEncoderFactory()),
fallback_factory_(use_fallback_factory ? new MockVideoEncoderFactory()
: nullptr),
video_format_(video_format) {}
video_format_(video_format),
field_trials_(field_trials) {}

// Can only be called once as the SimulcastEncoderAdapter will take the
// ownership of `factory_`.
VideoEncoder* CreateMockEncoderAdapter() {
return new SimulcastEncoderAdapter(primary_factory_.get(),
fallback_factory_.get(), video_format_);
fallback_factory_.get(), video_format_,
field_trials_);
}

MockVideoEncoderFactory* factory() { return primary_factory_.get(); }
Expand All @@ -424,6 +428,7 @@ class TestSimulcastEncoderAdapterFakeHelper {
std::unique_ptr<MockVideoEncoderFactory> primary_factory_;
std::unique_ptr<MockVideoEncoderFactory> fallback_factory_;
SdpVideoFormat video_format_;
const FieldTrialsView& field_trials_;
};

static const int kTestTemporalLayerProfile[3] = {3, 2, 1};
Expand All @@ -441,7 +446,8 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test,

void SetUp() override {
helper_.reset(new TestSimulcastEncoderAdapterFakeHelper(
use_fallback_factory_, SdpVideoFormat("VP8", sdp_video_parameters_)));
use_fallback_factory_, SdpVideoFormat("VP8", sdp_video_parameters_),
field_trials_));
adapter_.reset(helper_->CreateMockEncoderAdapter());
last_encoded_image_width_ = absl::nullopt;
last_encoded_image_height_ = absl::nullopt;
Expand Down Expand Up @@ -581,6 +587,7 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test,
std::unique_ptr<SimulcastRateAllocator> rate_allocator_;
bool use_fallback_factory_;
SdpVideoFormat::Parameters sdp_video_parameters_;
test::ScopedKeyValueConfig field_trials_;
};

TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) {
Expand Down Expand Up @@ -1435,12 +1442,14 @@ TEST_F(TestSimulcastEncoderAdapterFake,
TEST_F(
TestSimulcastEncoderAdapterFake,
EncoderInfoFromFieldTrialDoesNotOverrideExistingBitrateLimitsInSinglecast) {
test::ScopedFieldTrials field_trials(
test::ScopedKeyValueConfig field_trials(
field_trials_,
"WebRTC-SimulcastEncoderAdapter-GetEncoderInfoOverride/"
"frame_size_pixels:123|456|789,"
"min_start_bitrate_bps:11000|22000|33000,"
"min_bitrate_bps:44000|55000|66000,"
"max_bitrate_bps:77000|88000|99000/");
SetUp();

std::vector<VideoEncoder::ResolutionBitrateLimits> bitrate_limits;
bitrate_limits.push_back(
Expand All @@ -1463,7 +1472,8 @@ TEST_F(
}

TEST_F(TestSimulcastEncoderAdapterFake, EncoderInfoFromFieldTrial) {
test::ScopedFieldTrials field_trials(
test::ScopedKeyValueConfig field_trials(
field_trials_,
"WebRTC-SimulcastEncoderAdapter-GetEncoderInfoOverride/"
"requested_resolution_alignment:8,"
"apply_alignment_to_all_simulcast_layers/");
Expand All @@ -1483,7 +1493,8 @@ TEST_F(TestSimulcastEncoderAdapterFake, EncoderInfoFromFieldTrial) {

TEST_F(TestSimulcastEncoderAdapterFake,
EncoderInfoFromFieldTrialForSingleStream) {
test::ScopedFieldTrials field_trials(
test::ScopedKeyValueConfig field_trials(
field_trials_,
"WebRTC-SimulcastEncoderAdapter-GetEncoderInfoOverride/"
"requested_resolution_alignment:9,"
"frame_size_pixels:123|456|789,"
Expand Down Expand Up @@ -1798,8 +1809,8 @@ TEST_F(TestSimulcastEncoderAdapterFake,
// Normally SEA reuses encoders. But, when TL-based SW fallback is enabled,
// the encoder which served the lowest stream should be recreated before it
// can be used to process an upper layer and vice-versa.
test::ScopedFieldTrials field_trials(
"WebRTC-Video-PreferTemporalSupportOnBaseLayer/Enabled/");
test::ScopedKeyValueConfig field_trials(
field_trials_, "WebRTC-Video-PreferTemporalSupportOnBaseLayer/Enabled/");
use_fallback_factory_ = true;
ReSetUp();

Expand Down
2 changes: 2 additions & 0 deletions modules/video_coding/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ rtc_library("video_coding_utility") {
":video_codec_interface",
"../../api:array_view",
"../../api:field_trials_view",
"../../api:field_trials_view",
"../../api:scoped_refptr",
"../../api:sequence_checker",
"../../api/units:time_delta",
Expand Down Expand Up @@ -1263,6 +1264,7 @@ if (rtc_include_tests) {
"../../api:array_view",
"../../api:create_simulcast_test_fixture_api",
"../../api:fec_controller_api",
"../../api:field_trials_view",
"../../api:mock_fec_controller_override",
"../../api:mock_video_decoder",
"../../api:mock_video_encoder",
Expand Down
26 changes: 14 additions & 12 deletions modules/video_coding/utility/quality_scaler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <memory>
#include <utility>

#include "api/field_trials_view.h"
#include "api/units/time_delta.h"
#include "api/video/video_adaptation_reason.h"
#include "rtc_base/checks.h"
Expand Down Expand Up @@ -175,37 +176,38 @@ class QualityScaler::CheckQpTask {
};

QualityScaler::QualityScaler(QualityScalerQpUsageHandlerInterface* handler,
VideoEncoder::QpThresholds thresholds)
: QualityScaler(handler, thresholds, kMeasureMs) {}
VideoEncoder::QpThresholds thresholds,
const FieldTrialsView& field_trials)
: QualityScaler(handler, thresholds, field_trials, kMeasureMs) {}

// Protected ctor, should not be called directly.
QualityScaler::QualityScaler(QualityScalerQpUsageHandlerInterface* handler,
VideoEncoder::QpThresholds thresholds,
const FieldTrialsView& field_trials,
int64_t default_sampling_period_ms)
: handler_(handler),
thresholds_(thresholds),
sampling_period_ms_(QualityScalerSettings::ParseFromFieldTrials()
sampling_period_ms_(QualityScalerSettings(field_trials)
.SamplingPeriodMs()
.value_or(default_sampling_period_ms)),
fast_rampup_(true),
// Arbitrarily choose size based on 30 fps for 5 seconds.
average_qp_(QualityScalerSettings::ParseFromFieldTrials()
average_qp_(QualityScalerSettings(field_trials)
.AverageQpWindow()
.value_or(5 * 30)),
framedrop_percent_media_opt_(5 * 30),
framedrop_percent_all_(5 * 30),
experiment_enabled_(QualityScalingExperiment::Enabled()),
min_frames_needed_(
QualityScalerSettings::ParseFromFieldTrials().MinFrames().value_or(
kMinFramesNeededToScale)),
initial_scale_factor_(QualityScalerSettings::ParseFromFieldTrials()
experiment_enabled_(QualityScalingExperiment::Enabled(field_trials)),
min_frames_needed_(QualityScalerSettings(field_trials)
.MinFrames()
.value_or(kMinFramesNeededToScale)),
initial_scale_factor_(QualityScalerSettings(field_trials)
.InitialScaleFactor()
.value_or(kSamplePeriodScaleFactor)),
scale_factor_(
QualityScalerSettings::ParseFromFieldTrials().ScaleFactor()) {
scale_factor_(QualityScalerSettings(field_trials).ScaleFactor()) {
RTC_DCHECK_RUN_ON(&task_checker_);
if (experiment_enabled_) {
config_ = QualityScalingExperiment::GetConfig();
config_ = QualityScalingExperiment::GetConfig(field_trials);
qp_smoother_high_.reset(new QpSmoother(config_.alpha_high));
qp_smoother_low_.reset(new QpSmoother(config_.alpha_low));
}
Expand Down
5 changes: 4 additions & 1 deletion modules/video_coding/utility/quality_scaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <memory>

#include "absl/types/optional.h"
#include "api/field_trials_view.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/video_codecs/video_encoder.h"
Expand All @@ -40,7 +41,8 @@ class QualityScaler {
// This starts the quality scaler periodically checking what the average QP
// has been recently.
QualityScaler(QualityScalerQpUsageHandlerInterface* handler,
VideoEncoder::QpThresholds thresholds);
VideoEncoder::QpThresholds thresholds,
const FieldTrialsView& field_trials);
virtual ~QualityScaler();
// Should be called each time a frame is dropped at encoding.
void ReportDroppedFrameByMediaOpt();
Expand All @@ -55,6 +57,7 @@ class QualityScaler {
protected:
QualityScaler(QualityScalerQpUsageHandlerInterface* handler,
VideoEncoder::QpThresholds thresholds,
const FieldTrialsView& field_trials,
int64_t sampling_period_ms);

private:
Expand Down
13 changes: 8 additions & 5 deletions modules/video_coding/utility/quality_scaler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#include <memory>
#include <string>

#include "api/field_trials_view.h"
#include "api/units/time_delta.h"
#include "rtc_base/checks.h"
#include "rtc_base/event.h"
#include "rtc_base/task_queue_for_test.h"
#include "test/field_trial.h"
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"

namespace webrtc {
namespace {
Expand Down Expand Up @@ -53,8 +54,9 @@ class FakeQpUsageHandler : public QualityScalerQpUsageHandlerInterface {
class QualityScalerUnderTest : public QualityScaler {
public:
explicit QualityScalerUnderTest(QualityScalerQpUsageHandlerInterface* handler,
VideoEncoder::QpThresholds thresholds)
: QualityScaler(handler, thresholds, 5) {}
VideoEncoder::QpThresholds thresholds,
const FieldTrialsView& field_trials)
: QualityScaler(handler, thresholds, field_trials, 5) {}
};

class QualityScalerTest : public ::testing::Test,
Expand All @@ -74,7 +76,8 @@ class QualityScalerTest : public ::testing::Test,
handler_(std::make_unique<FakeQpUsageHandler>()) {
task_queue_.SendTask([this] {
qs_ = std::unique_ptr<QualityScaler>(new QualityScalerUnderTest(
handler_.get(), VideoEncoder::QpThresholds(kLowQp, kHighQp)));
handler_.get(), VideoEncoder::QpThresholds(kLowQp, kHighQp),
scoped_field_trial_));
});
}

Expand Down Expand Up @@ -104,7 +107,7 @@ class QualityScalerTest : public ::testing::Test,
}
}

test::ScopedFieldTrials scoped_field_trial_;
test::ScopedKeyValueConfig scoped_field_trial_;
TaskQueueForTest task_queue_;
std::unique_ptr<QualityScaler> qs_;
std::unique_ptr<FakeQpUsageHandler> handler_;
Expand Down
Loading

0 comments on commit 1a8d529

Please sign in to comment.