diff --git a/AUTHORS b/AUTHORS index 9424a61de1..f4dd64134d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -56,6 +56,7 @@ Frederik Riedel, Frogg GmbH Gao Chun Giji Gangadharan Graham Yoakum +Guillaume Petit Gustavo Garcia Hans Knoechel Helmut Januschka diff --git a/rtc_base/experiments/encoder_info_settings.cc b/rtc_base/experiments/encoder_info_settings.cc index 82480ea298..eabf8b182d 100644 --- a/rtc_base/experiments/encoder_info_settings.cc +++ b/rtc_base/experiments/encoder_info_settings.cc @@ -144,6 +144,12 @@ EncoderInfoSettings::GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted( return bitrate_limits[interpolation_index]; } + // 0 means our resolution is smaller than the smallest resolution in the list, + // we will select smallest data as the return result. + if (interpolation_index == 0) { + return *bitrate_limits.begin(); + } + // No matching resolution, do a linear interpolate. int lower_pixel_count = bitrate_limits[interpolation_index - 1].frame_size_pixels; diff --git a/rtc_base/experiments/encoder_info_settings_unittest.cc b/rtc_base/experiments/encoder_info_settings_unittest.cc index 916f980ebe..70c0b7f0ba 100644 --- a/rtc_base/experiments/encoder_info_settings_unittest.cc +++ b/rtc_base/experiments/encoder_info_settings_unittest.cc @@ -103,4 +103,49 @@ TEST(EncoderSettingsTest, CommonSettingsUsedIfEncoderNameUnspecified) { EXPECT_EQ(3u, vp9_settings.requested_resolution_alignment()); } +TEST(GetSinglecastBitrateLimitForResolutionWhenQpIsUntrustedTests, + LinearInterpolationUnderflow) { + std::optional frame_size_pixels = 480 * 360; + std::vector resolution_bitrate_limits( + {{1280 * 720, 1500000, 30000, 2500000}, + {1920 * 1080, 2500000, 30000, 4000000}}); + + const auto resolutionBitrateLimit = EncoderInfoSettings:: + GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted( + frame_size_pixels, resolution_bitrate_limits); + EXPECT_TRUE(resolutionBitrateLimit.has_value()); + EXPECT_EQ(resolutionBitrateLimit.value(), resolution_bitrate_limits.front()); +} + +TEST(GetSinglecastBitrateLimitForResolutionWhenQpIsUntrustedTests, + LinearInterpolationOverflow) { + std::optional frame_size_pixels = 4096 * 2160; + std::vector resolution_bitrate_limits( + {{1280 * 720, 1500000, 30000, 2500000}, + {1920 * 1080, 2500000, 30000, 4000000}}); + + const auto resolutionBitrateLimit = EncoderInfoSettings:: + GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted( + frame_size_pixels, resolution_bitrate_limits); + EXPECT_TRUE(resolutionBitrateLimit.has_value()); + EXPECT_EQ(resolutionBitrateLimit.value(), resolution_bitrate_limits.back()); +} + +TEST(GetSinglecastBitrateLimitForResolutionWhenQpIsUntrustedTests, + LinearInterpolationExactMatch) { + std::optional frame_size_pixels = 1920 * 1080; + VideoEncoder::ResolutionBitrateLimits expected_match{1920 * 1080, 2500000, + 30000, 4000000}; + std::vector resolution_bitrate_limits( + {{1280 * 720, 1500000, 30000, 2500000}, + expected_match, + {4096 * 2160, 4000000, 30000, 8000000}}); + + const auto resolutionBitrateLimit = EncoderInfoSettings:: + GetSinglecastBitrateLimitForResolutionWhenQpIsUntrusted( + frame_size_pixels, resolution_bitrate_limits); + EXPECT_TRUE(resolutionBitrateLimit.has_value()); + EXPECT_EQ(resolutionBitrateLimit.value(), expected_match); +} + } // namespace webrtc