Adds WebRTC-DisableRtxRateLimiter for enable/disable RTX rate limiter.

Change-Id: I22e65c5b2a0b5017aa52a3f1af0fc2fd6357f439
Bug: webrtc:15184
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/305660
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Ying Wang <yinwa@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40116}
This commit is contained in:
Ying Wang 2023-05-17 20:59:49 +08:00 committed by WebRTC LUCI CQ
parent f67d1fd42c
commit aa6d4fa622
3 changed files with 19 additions and 1 deletions

View File

@ -490,6 +490,7 @@ rtc_library("rate_limiter") {
":macromagic", ":macromagic",
":rate_statistics", ":rate_statistics",
"../system_wrappers", "../system_wrappers",
"../system_wrappers:field_trial",
"synchronization:mutex", "synchronization:mutex",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
@ -1867,6 +1868,7 @@ if (rtc_include_tests) {
"../api/numerics", "../api/numerics",
"../api/units:time_delta", "../api/units:time_delta",
"../system_wrappers", "../system_wrappers",
"../test:field_trial",
"../test:fileutils", "../test:fileutils",
"../test:test_main", "../test:test_main",
"../test:test_support", "../test:test_support",

View File

@ -14,6 +14,7 @@
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "system_wrappers/include/field_trial.h"
namespace webrtc { namespace webrtc {
@ -34,7 +35,8 @@ bool RateLimiter::TryUseRate(size_t packet_size_bytes) {
MutexLock lock(&lock_); MutexLock lock(&lock_);
int64_t now_ms = clock_->TimeInMilliseconds(); int64_t now_ms = clock_->TimeInMilliseconds();
absl::optional<uint32_t> current_rate = current_rate_.Rate(now_ms); absl::optional<uint32_t> current_rate = current_rate_.Rate(now_ms);
if (current_rate) { if (!webrtc::field_trial::IsEnabled("WebRTC-DisableRtxRateLimiter") &&
current_rate) {
// If there is a current rate, check if adding bytes would cause maximum // If there is a current rate, check if adding bytes would cause maximum
// bitrate target to be exceeded. If there is NOT a valid current rate, // bitrate target to be exceeded. If there is NOT a valid current rate,
// allow allocating rate even if target is exceeded. This prevents // allow allocating rate even if target is exceeded. This prevents

View File

@ -15,6 +15,7 @@
#include "rtc_base/event.h" #include "rtc_base/event.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#include "system_wrappers/include/clock.h" #include "system_wrappers/include/clock.h"
#include "test/field_trial.h"
#include "test/gtest.h" #include "test/gtest.h"
namespace webrtc { namespace webrtc {
@ -106,6 +107,19 @@ TEST_F(RateLimitTest, WindowSizeLimits) {
EXPECT_FALSE(rate_limiter->SetWindowSize(kWindowSizeMs + 1)); EXPECT_FALSE(rate_limiter->SetWindowSize(kWindowSizeMs + 1));
} }
TEST_F(RateLimitTest, DiablesRtxRateLimiterByFieldTrial) {
webrtc::test::ScopedFieldTrials trial(
"WebRTC-DisableRtxRateLimiter/Enabled/");
// Fill rate, extend window to full size.
EXPECT_TRUE(rate_limiter->TryUseRate(kRateFillingBytes / 2));
clock_.AdvanceTimeMilliseconds(kWindowSizeMs - 1);
EXPECT_TRUE(rate_limiter->TryUseRate(kRateFillingBytes / 2));
// Does not limit rate even when all rate consumed.
EXPECT_TRUE(rate_limiter->TryUseRate(1));
}
static constexpr TimeDelta kMaxTimeout = TimeDelta::Seconds(30); static constexpr TimeDelta kMaxTimeout = TimeDelta::Seconds(30);
class ThreadTask { class ThreadTask {