diff --git a/media/BUILD.gn b/media/BUILD.gn index cc203c6847..5b40e86a73 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -323,6 +323,7 @@ rtc_static_library("rtc_audio_video") { "../rtc_base:rtc_base", "../rtc_base:rtc_task_queue", "../rtc_base:stringutils", + "../rtc_base/experiments:normalize_simulcast_size_experiment", "../system_wrappers", "//third_party/abseil-cpp/absl/types:optional", ] diff --git a/media/engine/simulcast.cc b/media/engine/simulcast.cc index c42e1dcae2..de3d8df097 100644 --- a/media/engine/simulcast.cc +++ b/media/engine/simulcast.cc @@ -18,6 +18,7 @@ #include "media/engine/simulcast.h" #include "modules/video_coding/utility/simulcast_rate_allocator.h" #include "rtc_base/arraysize.h" +#include "rtc_base/experiments/normalize_simulcast_size_experiment.h" #include "rtc_base/logging.h" #include "system_wrappers/include/field_trial.h" @@ -140,7 +141,13 @@ int FindSimulcastFormatIndex(int width, int height, size_t max_layers) { // Simulcast stream width and height must both be dividable by // |2 ^ (simulcast_layers - 1)|. int NormalizeSimulcastSize(int size, size_t simulcast_layers) { - const int base2_exponent = static_cast(simulcast_layers) - 1; + int base2_exponent = static_cast(simulcast_layers) - 1; + const absl::optional experimental_base2_exponent = + webrtc::NormalizeSimulcastSizeExperiment::GetBase2Exponent(); + if (experimental_base2_exponent && + (size > (1 << *experimental_base2_exponent))) { + base2_exponent = *experimental_base2_exponent; + } return ((size >> base2_exponent) << base2_exponent); } diff --git a/media/engine/simulcast_unittest.cc b/media/engine/simulcast_unittest.cc index f416368697..0c27816068 100644 --- a/media/engine/simulcast_unittest.cc +++ b/media/engine/simulcast_unittest.cc @@ -179,7 +179,7 @@ TEST(SimulcastTest, GetConfigWithNormalizedResolution) { kMaxLayers, 640 + 1, 360 + 1, kMaxBitrateBps, kBitratePriority, kQpMax, kMaxFps, !kScreenshare); - // Must be dividable by |2 ^ (num_layers - 1)|. + // Must be divisible by |2 ^ (num_layers - 1)|. EXPECT_EQ(kMaxLayers, streams.size()); EXPECT_EQ(320u, streams[0].width); EXPECT_EQ(180u, streams[0].height); @@ -187,6 +187,40 @@ TEST(SimulcastTest, GetConfigWithNormalizedResolution) { EXPECT_EQ(360u, streams[1].height); } +TEST(SimulcastTest, GetConfigWithNormalizedResolutionDivisibleBy4) { + test::ScopedFieldTrials field_trials( + "WebRTC-NormalizeSimulcastResolution/Enabled-2/"); + + const size_t kMaxLayers = 2; + std::vector streams = cricket::GetSimulcastConfig( + kMaxLayers, 709, 501, kMaxBitrateBps, kBitratePriority, kQpMax, kMaxFps, + !kScreenshare); + + // Must be divisible by |2 ^ 2|. + EXPECT_EQ(kMaxLayers, streams.size()); + EXPECT_EQ(354u, streams[0].width); + EXPECT_EQ(250u, streams[0].height); + EXPECT_EQ(708u, streams[1].width); + EXPECT_EQ(500u, streams[1].height); +} + +TEST(SimulcastTest, GetConfigWithNormalizedResolutionDivisibleBy8) { + test::ScopedFieldTrials field_trials( + "WebRTC-NormalizeSimulcastResolution/Enabled-3/"); + + const size_t kMaxLayers = 2; + std::vector streams = cricket::GetSimulcastConfig( + kMaxLayers, 709, 501, kMaxBitrateBps, kBitratePriority, kQpMax, kMaxFps, + !kScreenshare); + + // Must be divisible by |2 ^ 3|. + EXPECT_EQ(kMaxLayers, streams.size()); + EXPECT_EQ(352u, streams[0].width); + EXPECT_EQ(248u, streams[0].height); + EXPECT_EQ(704u, streams[1].width); + EXPECT_EQ(496u, streams[1].height); +} + TEST(SimulcastTest, GetConfigForScreenshare) { const size_t kMaxLayers = 3; std::vector streams = cricket::GetSimulcastConfig( diff --git a/rtc_base/experiments/BUILD.gn b/rtc_base/experiments/BUILD.gn index b10d0c1545..5c2e4a7a04 100644 --- a/rtc_base/experiments/BUILD.gn +++ b/rtc_base/experiments/BUILD.gn @@ -63,6 +63,18 @@ rtc_static_library("quality_scaling_experiment") { ] } +rtc_static_library("normalize_simulcast_size_experiment") { + sources = [ + "normalize_simulcast_size_experiment.cc", + "normalize_simulcast_size_experiment.h", + ] + deps = [ + "../:rtc_base_approved", + "../../system_wrappers:field_trial", + "//third_party/abseil-cpp/absl/types:optional", + ] +} + rtc_static_library("rtt_mult_experiment") { sources = [ "rtt_mult_experiment.cc", @@ -82,12 +94,14 @@ if (rtc_include_tests) { "congestion_controller_experiment_unittest.cc", "field_trial_parser_unittest.cc", "field_trial_units_unittest.cc", + "normalize_simulcast_size_experiment_unittest.cc", "quality_scaling_experiment_unittest.cc", "rtt_mult_experiment_unittest.cc", ] deps = [ ":congestion_controller_experiment", ":field_trial_parser", + ":normalize_simulcast_size_experiment", ":quality_scaling_experiment", ":rtt_mult_experiment", "../:rtc_base_tests_main", diff --git a/rtc_base/experiments/normalize_simulcast_size_experiment.cc b/rtc_base/experiments/normalize_simulcast_size_experiment.cc new file mode 100644 index 0000000000..9ce5f57f8f --- /dev/null +++ b/rtc_base/experiments/normalize_simulcast_size_experiment.cc @@ -0,0 +1,47 @@ +/* + * Copyright 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "rtc_base/experiments/normalize_simulcast_size_experiment.h" + +#include + +#include "rtc_base/logging.h" +#include "system_wrappers/include/field_trial.h" + +namespace webrtc { +namespace { +constexpr char kFieldTrial[] = "WebRTC-NormalizeSimulcastResolution"; +constexpr int kMinSetting = 0; +constexpr int kMaxSetting = 5; +} // namespace + +absl::optional NormalizeSimulcastSizeExperiment::GetBase2Exponent() { + if (!webrtc::field_trial::IsEnabled(kFieldTrial)) + return absl::nullopt; + + const std::string group = webrtc::field_trial::FindFullName(kFieldTrial); + if (group.empty()) + return absl::nullopt; + + int exponent; + if (sscanf(group.c_str(), "Enabled-%d", &exponent) != 1) { + RTC_LOG(LS_WARNING) << "No parameter provided."; + return absl::nullopt; + } + + if (exponent < kMinSetting || exponent > kMaxSetting) { + RTC_LOG(LS_WARNING) << "Unsupported exp value provided, value ignored."; + return absl::nullopt; + } + + return absl::optional(exponent); +} + +} // namespace webrtc diff --git a/rtc_base/experiments/normalize_simulcast_size_experiment.h b/rtc_base/experiments/normalize_simulcast_size_experiment.h new file mode 100644 index 0000000000..6b358202b2 --- /dev/null +++ b/rtc_base/experiments/normalize_simulcast_size_experiment.h @@ -0,0 +1,25 @@ +/* + * Copyright 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef RTC_BASE_EXPERIMENTS_NORMALIZE_SIMULCAST_SIZE_EXPERIMENT_H_ +#define RTC_BASE_EXPERIMENTS_NORMALIZE_SIMULCAST_SIZE_EXPERIMENT_H_ + +#include "absl/types/optional.h" + +namespace webrtc { +class NormalizeSimulcastSizeExperiment { + public: + // Returns the base two exponent from field trial. + static absl::optional GetBase2Exponent(); +}; + +} // namespace webrtc + +#endif // RTC_BASE_EXPERIMENTS_NORMALIZE_SIMULCAST_SIZE_EXPERIMENT_H_ diff --git a/rtc_base/experiments/normalize_simulcast_size_experiment_unittest.cc b/rtc_base/experiments/normalize_simulcast_size_experiment_unittest.cc new file mode 100644 index 0000000000..c37b80917f --- /dev/null +++ b/rtc_base/experiments/normalize_simulcast_size_experiment_unittest.cc @@ -0,0 +1,59 @@ +/* + * Copyright 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "rtc_base/experiments/normalize_simulcast_size_experiment.h" + +#include "rtc_base/gunit.h" +#include "test/field_trial.h" + +namespace webrtc { + +TEST(NormalizeSimulcastSizeExperimentTest, GetExponent) { + webrtc::test::ScopedFieldTrials field_trials( + "WebRTC-NormalizeSimulcastResolution/Enabled-2/"); + EXPECT_EQ(2, NormalizeSimulcastSizeExperiment::GetBase2Exponent()); +} + +TEST(NormalizeSimulcastSizeExperimentTest, GetExponentWithTwoParameters) { + webrtc::test::ScopedFieldTrials field_trials( + "WebRTC-NormalizeSimulcastResolution/Enabled-3-4/"); + EXPECT_EQ(3, NormalizeSimulcastSizeExperiment::GetBase2Exponent()); +} + +TEST(NormalizeSimulcastSizeExperimentTest, GetExponentFailsIfNotEnabled) { + webrtc::test::ScopedFieldTrials field_trials( + "WebRTC-NormalizeSimulcastResolution/Disabled/"); + EXPECT_FALSE(NormalizeSimulcastSizeExperiment::GetBase2Exponent()); +} + +TEST(NormalizeSimulcastSizeExperimentTest, + GetExponentFailsForInvalidFieldTrial) { + webrtc::test::ScopedFieldTrials field_trials( + "WebRTC-NormalizeSimulcastResolution/Enabled-invalid/"); + EXPECT_FALSE(NormalizeSimulcastSizeExperiment::GetBase2Exponent()); +} + +TEST(NormalizeSimulcastSizeExperimentTest, + GetExponentFailsForNegativeOutOfBoundValue) { + // Supported range: [0, 5]. + webrtc::test::ScopedFieldTrials field_trials( + "WebRTC-NormalizeSimulcastResolution/Enabled--1/"); + EXPECT_FALSE(NormalizeSimulcastSizeExperiment::GetBase2Exponent()); +} + +TEST(NormalizeSimulcastSizeExperimentTest, + GetExponentFailsForPositiveOutOfBoundValue) { + // Supported range: [0, 5]. + webrtc::test::ScopedFieldTrials field_trials( + "WebRTC-NormalizeSimulcastResolution/Enabled-6/"); + EXPECT_FALSE(NormalizeSimulcastSizeExperiment::GetBase2Exponent()); +} + +} // namespace webrtc