Adds WebRTC-Audio-PriorityBitrate for controlling audio/video rate allocation

Bug: webrtc:15769
Change-Id: Id260fb9540ecb79b0c349937e55db343e04178c9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/334702
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Commit-Queue: Dan Tan <dwtan@google.com>
Cr-Commit-Position: refs/heads/main@{#41631}
This commit is contained in:
Dan Tan 2024-01-29 15:02:59 -08:00 committed by WebRTC LUCI CQ
parent 62cee88e4b
commit 68e85b8d0d
4 changed files with 47 additions and 2 deletions

View File

@ -157,6 +157,8 @@ AudioSendStream::AudioSendStream(
event_log_(event_log),
use_legacy_overhead_calculation_(
field_trials_.IsEnabled("WebRTC-Audio-LegacyOverhead")),
enable_priority_bitrate_(
!field_trials_.IsDisabled("WebRTC-Audio-PriorityBitrate")),
bitrate_allocator_(bitrate_allocator),
rtp_transport_(rtp_transport),
rtp_rtcp_module_(channel_send_->GetRtpRtcp()),
@ -807,6 +809,10 @@ void AudioSendStream::ConfigureBitrateObserver() {
priority_bitrate = *allocation_settings_.priority_bitrate_raw;
}
if (!enable_priority_bitrate_) {
priority_bitrate = DataRate::BitsPerSec(0);
}
bitrate_allocator_->AddObserver(
this,
MediaStreamAllocationConfig{

View File

@ -173,6 +173,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
const std::unique_ptr<voe::ChannelSendInterface> channel_send_;
RtcEventLog* const event_log_;
const bool use_legacy_overhead_calculation_;
const bool enable_priority_bitrate_;
int encoder_sample_rate_hz_ RTC_GUARDED_BY(worker_thread_checker_) = 0;
size_t encoder_num_channels_ RTC_GUARDED_BY(worker_thread_checker_) = 0;

View File

@ -21,6 +21,7 @@
#include "audio/audio_state.h"
#include "audio/conversion.h"
#include "audio/mock_voe_channel_proxy.h"
#include "call/test/mock_bitrate_allocator.h"
#include "call/test/mock_rtp_transport_controller_send.h"
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
#include "modules/audio_device/include/mock_audio_device.h"
@ -155,7 +156,6 @@ struct ConfigHelper {
use_null_audio_processing
? nullptr
: rtc::make_ref_counted<NiceMock<MockAudioProcessing>>()),
bitrate_allocator_(&limit_observer_),
audio_encoder_(nullptr) {
using ::testing::Invoke;
@ -203,6 +203,7 @@ struct ConfigHelper {
MockRtpRtcpInterface* rtp_rtcp() { return &rtp_rtcp_; }
MockChannelSend* channel_send() { return channel_send_; }
RtpTransportControllerSendInterface* transport() { return &rtp_transport_; }
MockBitrateAllocator* bitrate_allocator() { return &bitrate_allocator_; }
static void AddBweToConfig(AudioSendStream::Config* config) {
config->rtp.extensions.push_back(RtpExtension(
@ -328,7 +329,7 @@ struct ConfigHelper {
::testing::NiceMock<MockRtpTransportControllerSend> rtp_transport_;
::testing::NiceMock<MockRtpRtcpInterface> rtp_rtcp_;
::testing::NiceMock<MockLimitObserver> limit_observer_;
BitrateAllocator bitrate_allocator_;
::testing::NiceMock<MockBitrateAllocator> bitrate_allocator_;
std::unique_ptr<AudioEncoder> audio_encoder_;
};
@ -924,5 +925,39 @@ TEST(AudioSendStreamTest, ReconfigureWithFrameEncryptor) {
send_stream->Reconfigure(new_config, nullptr);
}
}
TEST(AudioSendStreamTest, DefaultsHonorsPriorityBitrate) {
ConfigHelper helper(true, true, true);
ScopedKeyValueConfig field_trials(helper.field_trials,
"WebRTC-Audio-Allocation/prio_rate:20/");
auto send_stream = helper.CreateAudioSendStream();
EXPECT_CALL(*helper.bitrate_allocator(), AddObserver(send_stream.get(), _))
.WillOnce(Invoke(
[&](BitrateAllocatorObserver*, MediaStreamAllocationConfig config) {
EXPECT_EQ(config.priority_bitrate_bps, 20000);
}));
EXPECT_CALL(*helper.channel_send(), StartSend());
send_stream->Start();
EXPECT_CALL(*helper.channel_send(), StopSend());
send_stream->Stop();
}
TEST(AudioSendStreamTest, OverridesPriorityBitrate) {
ConfigHelper helper(true, true, true);
ScopedKeyValueConfig field_trials(helper.field_trials,
"WebRTC-Audio-Allocation/prio_rate:20/"
"WebRTC-Audio-PriorityBitrate/Disabled/");
auto send_stream = helper.CreateAudioSendStream();
EXPECT_CALL(*helper.bitrate_allocator(), AddObserver(send_stream.get(), _))
.WillOnce(Invoke(
[&](BitrateAllocatorObserver*, MediaStreamAllocationConfig config) {
EXPECT_EQ(config.priority_bitrate_bps, 0);
}));
EXPECT_CALL(*helper.channel_send(), StartSend());
send_stream->Start();
EXPECT_CALL(*helper.channel_send(), StopSend());
send_stream->Stop();
}
} // namespace test
} // namespace webrtc

View File

@ -53,6 +53,9 @@ ACTIVE_FIELD_TRIALS: FrozenSet[FieldTrial] = frozenset([
FieldTrial('WebRTC-Audio-OpusGeneratePlc',
'webrtc:13322',
date(2024, 4, 1)),
FieldTrial('WebRTC-Audio-PriorityBitrate',
'webrtc:15769',
date(2024, 4, 1)),
FieldTrial('WebRTC-AV1-OverridePriorityBitrate',
'webrtc:15763',
date(2024, 4, 1)),