Add method CanAdaptUp based on bitrate to BalancedDegradationSettings.
Bug: none Change-Id: Ibeded1f7193384a8ae5bd3f2ce4ccaa4c7db7290 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150333 Reviewed-by: Mirta Dvornicic <mirtad@webrtc.org> Commit-Queue: Åsa Persson <asapersson@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28957}
This commit is contained in:
@ -317,6 +317,16 @@ absl::optional<int> BalancedDegradationSettings::NextHigherBitrateKbps(
|
|||||||
return absl::nullopt;
|
return absl::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BalancedDegradationSettings::CanAdaptUp(int pixels,
|
||||||
|
uint32_t bitrate_bps) const {
|
||||||
|
absl::optional<int> next_layer_min_kbps = NextHigherBitrateKbps(pixels);
|
||||||
|
if (!next_layer_min_kbps.has_value() || bitrate_bps == 0) {
|
||||||
|
return true; // No limit configured or bitrate provided.
|
||||||
|
}
|
||||||
|
return bitrate_bps >=
|
||||||
|
static_cast<uint32_t>(next_layer_min_kbps.value() * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
absl::optional<int> BalancedDegradationSettings::MinFpsDiff(int pixels) const {
|
absl::optional<int> BalancedDegradationSettings::MinFpsDiff(int pixels) const {
|
||||||
for (const auto& config : configs_) {
|
for (const auto& config : configs_) {
|
||||||
if (pixels <= config.pixels) {
|
if (pixels <= config.pixels) {
|
||||||
|
@ -82,6 +82,9 @@ class BalancedDegradationSettings {
|
|||||||
// Gets the bitrate for the first resolution above |pixels|.
|
// Gets the bitrate for the first resolution above |pixels|.
|
||||||
absl::optional<int> NextHigherBitrateKbps(int pixels) const;
|
absl::optional<int> NextHigherBitrateKbps(int pixels) const;
|
||||||
|
|
||||||
|
// Checks if quality can be increased based on |pixels| and |bitrate_bps|.
|
||||||
|
bool CanAdaptUp(int pixels, uint32_t bitrate_bps) const;
|
||||||
|
|
||||||
// Gets the min framerate diff from |configs_| based on |pixels|.
|
// Gets the min framerate diff from |configs_| based on |pixels|.
|
||||||
absl::optional<int> MinFpsDiff(int pixels) const;
|
absl::optional<int> MinFpsDiff(int pixels) const;
|
||||||
|
|
||||||
|
@ -359,6 +359,20 @@ TEST(BalancedDegradationSettings, GetsNextHigherBitrateWithUnsetValue) {
|
|||||||
EXPECT_FALSE(settings.NextHigherBitrateKbps(2001));
|
EXPECT_FALSE(settings.NextHigherBitrateKbps(2001));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(BalancedDegradationSettings, CanAdaptUpIfBitrateGeNextHigherKbpsLimit) {
|
||||||
|
webrtc::test::ScopedFieldTrials field_trials(
|
||||||
|
"WebRTC-Video-BalancedDegradationSettings/"
|
||||||
|
"pixels:1000|2000|3000|4000,fps:5|15|25|30,kbps:0|80|0|90/");
|
||||||
|
BalancedDegradationSettings settings;
|
||||||
|
EXPECT_TRUE(settings.CanAdaptUp(1000, 0)); // No bitrate provided.
|
||||||
|
EXPECT_FALSE(settings.CanAdaptUp(1000, 79000));
|
||||||
|
EXPECT_TRUE(settings.CanAdaptUp(1000, 80000));
|
||||||
|
EXPECT_TRUE(settings.CanAdaptUp(1001, 1)); // No limit configured.
|
||||||
|
EXPECT_FALSE(settings.CanAdaptUp(3000, 89000));
|
||||||
|
EXPECT_TRUE(settings.CanAdaptUp(3000, 90000));
|
||||||
|
EXPECT_TRUE(settings.CanAdaptUp(3001, 1)); // No limit.
|
||||||
|
}
|
||||||
|
|
||||||
TEST(BalancedDegradationSettings, GetsFpsDiff) {
|
TEST(BalancedDegradationSettings, GetsFpsDiff) {
|
||||||
webrtc::test::ScopedFieldTrials field_trials(
|
webrtc::test::ScopedFieldTrials field_trials(
|
||||||
"WebRTC-Video-BalancedDegradationSettings/"
|
"WebRTC-Video-BalancedDegradationSettings/"
|
||||||
|
@ -1912,14 +1912,10 @@ void VideoStreamEncoder::AdaptUp(AdaptReason reason) {
|
|||||||
|
|
||||||
switch (degradation_preference_) {
|
switch (degradation_preference_) {
|
||||||
case DegradationPreference::BALANCED: {
|
case DegradationPreference::BALANCED: {
|
||||||
// Do not adapt up if bwe is less than min bitrate for next resolution.
|
// Check if quality should be increased based on bitrate.
|
||||||
absl::optional<int> next_layer_min_kbps =
|
if (reason == kQuality &&
|
||||||
balanced_settings_.NextHigherBitrateKbps(
|
!balanced_settings_.CanAdaptUp(last_frame_info_->pixel_count(),
|
||||||
last_frame_info_->pixel_count());
|
encoder_start_bitrate_bps_)) {
|
||||||
if (next_layer_min_kbps && encoder_start_bitrate_bps_ > 0 &&
|
|
||||||
reason == kQuality &&
|
|
||||||
encoder_start_bitrate_bps_ <
|
|
||||||
static_cast<uint32_t>(next_layer_min_kbps.value() * 1000)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Try scale up framerate, if higher.
|
// Try scale up framerate, if higher.
|
||||||
|
Reference in New Issue
Block a user