Using unit classes in BitrateAllocationUpdate struct.
This prepares for moving BitrateAllocationUpdate to API. Bug: webrtc:9718 Change-Id: Ib2bcedb6b68fde33b6a2466f40829e86438aa973 Reviewed-on: https://webrtc-review.googlesource.com/c/111507 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Reviewed-by: Oskar Sundbom <ossu@webrtc.org> Cr-Commit-Position: refs/heads/master@{#25737}
This commit is contained in:
parent
e4cccae299
commit
13e5903626
@ -465,18 +465,18 @@ uint32_t AudioSendStream::OnBitrateUpdated(BitrateAllocationUpdate update) {
|
||||
// A send stream may be allocated a bitrate of zero if the allocator decides
|
||||
// to disable it. For now we ignore this decision and keep sending on min
|
||||
// bitrate.
|
||||
if (update.bitrate_bps == 0) {
|
||||
update.bitrate_bps = config_.min_bitrate_bps;
|
||||
if (update.target_bitrate.IsZero()) {
|
||||
update.target_bitrate = DataRate::bps(config_.min_bitrate_bps);
|
||||
}
|
||||
RTC_DCHECK_GE(update.bitrate_bps,
|
||||
static_cast<uint32_t>(config_.min_bitrate_bps));
|
||||
RTC_DCHECK_GE(update.target_bitrate.bps<int>(), config_.min_bitrate_bps);
|
||||
// The bitrate allocator might allocate an higher than max configured bitrate
|
||||
// if there is room, to allow for, as example, extra FEC. Ignore that for now.
|
||||
const uint32_t max_bitrate_bps = config_.max_bitrate_bps;
|
||||
if (update.bitrate_bps > max_bitrate_bps)
|
||||
update.bitrate_bps = max_bitrate_bps;
|
||||
const DataRate max_bitrate = DataRate::bps(config_.max_bitrate_bps);
|
||||
if (update.target_bitrate > max_bitrate)
|
||||
update.target_bitrate = max_bitrate;
|
||||
|
||||
channel_send_->SetBitrate(update.bitrate_bps, update.bwe_period_ms);
|
||||
channel_send_->SetBitrate(update.target_bitrate.bps(),
|
||||
update.bwe_period.ms());
|
||||
|
||||
// The amount of audio protection is not exposed by the encoder, hence
|
||||
// always returning 0.
|
||||
|
||||
@ -474,10 +474,10 @@ TEST(AudioSendStreamTest, DoesNotPassHigherBitrateThanMaxBitrate) {
|
||||
EXPECT_CALL(*helper.channel_send(),
|
||||
SetBitrate(helper.config().max_bitrate_bps, _));
|
||||
BitrateAllocationUpdate update;
|
||||
update.bitrate_bps = helper.config().max_bitrate_bps + 5000;
|
||||
update.fraction_loss = 0;
|
||||
update.rtt = 50;
|
||||
update.bwe_period_ms = 6000;
|
||||
update.target_bitrate = DataRate::bps(helper.config().max_bitrate_bps + 5000);
|
||||
update.packet_loss_ratio = 0;
|
||||
update.round_trip_time = TimeDelta::ms(50);
|
||||
update.bwe_period = TimeDelta::ms(6000);
|
||||
send_stream->OnBitrateUpdated(update);
|
||||
}
|
||||
|
||||
@ -486,10 +486,10 @@ TEST(AudioSendStreamTest, ProbingIntervalOnBitrateUpdated) {
|
||||
auto send_stream = helper.CreateAudioSendStream();
|
||||
EXPECT_CALL(*helper.channel_send(), SetBitrate(_, 5000));
|
||||
BitrateAllocationUpdate update;
|
||||
update.bitrate_bps = helper.config().max_bitrate_bps + 5000;
|
||||
update.fraction_loss = 0;
|
||||
update.rtt = 50;
|
||||
update.bwe_period_ms = 5000;
|
||||
update.target_bitrate = DataRate::bps(helper.config().max_bitrate_bps + 5000);
|
||||
update.packet_loss_ratio = 0;
|
||||
update.round_trip_time = TimeDelta::ms(50);
|
||||
update.bwe_period = TimeDelta::ms(5000);
|
||||
send_stream->OnBitrateUpdated(update);
|
||||
}
|
||||
|
||||
|
||||
@ -164,6 +164,8 @@ rtc_source_set("bitrate_allocator") {
|
||||
"bitrate_allocator.h",
|
||||
]
|
||||
deps = [
|
||||
"../api/units:data_rate",
|
||||
"../api/units:time_delta",
|
||||
"../modules/bitrate_controller",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:rtc_base_approved",
|
||||
|
||||
@ -55,6 +55,7 @@ BitrateAllocator::BitrateAllocator(LimitObserver* limit_observer)
|
||||
last_non_zero_bitrate_bps_(kDefaultBitrateBps),
|
||||
last_fraction_loss_(0),
|
||||
last_rtt_(0),
|
||||
last_bwe_period_ms_(1000),
|
||||
num_pause_events_(0),
|
||||
clock_(Clock::GetRealTimeClock()),
|
||||
last_bwe_log_time_(0),
|
||||
@ -115,10 +116,13 @@ void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps,
|
||||
for (auto& config : bitrate_observer_configs_) {
|
||||
uint32_t allocated_bitrate = allocation[config.observer];
|
||||
uint32_t allocated_bandwidth = bandwidth_allocation[config.observer];
|
||||
uint32_t protection_bitrate =
|
||||
config.observer->OnBitrateUpdated(BitrateAllocationUpdate{
|
||||
allocated_bitrate, allocated_bandwidth, last_fraction_loss_,
|
||||
last_rtt_, last_bwe_period_ms_});
|
||||
BitrateAllocationUpdate update;
|
||||
update.target_bitrate = DataRate::bps(allocated_bitrate);
|
||||
update.link_capacity = DataRate::bps(allocated_bandwidth);
|
||||
update.packet_loss_ratio = last_fraction_loss_ / 256.0;
|
||||
update.round_trip_time = TimeDelta::ms(last_rtt_);
|
||||
update.bwe_period = TimeDelta::ms(last_bwe_period_ms_);
|
||||
uint32_t protection_bitrate = config.observer->OnBitrateUpdated(update);
|
||||
|
||||
if (allocated_bitrate == 0 && config.allocated_bitrate_bps > 0) {
|
||||
if (target_bitrate_bps > 0)
|
||||
@ -179,10 +183,13 @@ void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer,
|
||||
for (auto& config : bitrate_observer_configs_) {
|
||||
uint32_t allocated_bitrate = allocation[config.observer];
|
||||
uint32_t bandwidth = bandwidth_allocation[config.observer];
|
||||
uint32_t protection_bitrate =
|
||||
config.observer->OnBitrateUpdated(BitrateAllocationUpdate{
|
||||
allocated_bitrate, bandwidth, last_fraction_loss_, last_rtt_,
|
||||
last_bwe_period_ms_});
|
||||
BitrateAllocationUpdate update;
|
||||
update.target_bitrate = DataRate::bps(allocated_bitrate);
|
||||
update.link_capacity = DataRate::bps(bandwidth);
|
||||
update.packet_loss_ratio = last_fraction_loss_ / 256.0;
|
||||
update.round_trip_time = TimeDelta::ms(last_rtt_);
|
||||
update.bwe_period = TimeDelta::ms(last_bwe_period_ms_);
|
||||
uint32_t protection_bitrate = config.observer->OnBitrateUpdated(update);
|
||||
config.allocated_bitrate_bps = allocated_bitrate;
|
||||
if (allocated_bitrate > 0)
|
||||
config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate);
|
||||
@ -191,8 +198,14 @@ void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer,
|
||||
// Currently, an encoder is not allowed to produce frames.
|
||||
// But we still have to return the initial config bitrate + let the
|
||||
// observer know that it can not produce frames.
|
||||
observer->OnBitrateUpdated(BitrateAllocationUpdate{
|
||||
0, 0, last_fraction_loss_, last_rtt_, last_bwe_period_ms_});
|
||||
|
||||
BitrateAllocationUpdate update;
|
||||
update.target_bitrate = DataRate::Zero();
|
||||
update.link_capacity = DataRate::Zero();
|
||||
update.packet_loss_ratio = last_fraction_loss_ / 256.0;
|
||||
update.round_trip_time = TimeDelta::ms(last_rtt_);
|
||||
update.bwe_period = TimeDelta::ms(last_bwe_period_ms_);
|
||||
observer->OnBitrateUpdated(update);
|
||||
}
|
||||
UpdateAllocationLimits();
|
||||
}
|
||||
|
||||
@ -19,6 +19,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "api/units/data_rate.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/bitrateallocationstrategy.h"
|
||||
#include "rtc_base/sequenced_task_checker.h"
|
||||
|
||||
@ -27,12 +29,11 @@ namespace webrtc {
|
||||
class Clock;
|
||||
|
||||
struct BitrateAllocationUpdate {
|
||||
// TODO(srte): Rename to target_bitrate.
|
||||
uint32_t bitrate_bps;
|
||||
uint32_t link_capacity_bps;
|
||||
uint8_t fraction_loss;
|
||||
int64_t rtt;
|
||||
int64_t bwe_period_ms;
|
||||
DataRate target_bitrate = DataRate::Zero();
|
||||
DataRate link_capacity = DataRate::Zero();
|
||||
double packet_loss_ratio = 0;
|
||||
TimeDelta round_trip_time = TimeDelta::PlusInfinity();
|
||||
TimeDelta bwe_period = TimeDelta::PlusInfinity();
|
||||
};
|
||||
// Used by all send streams with adaptive bitrate, to get the currently
|
||||
// allocated bitrate for the send stream. The current network properties are
|
||||
|
||||
@ -60,11 +60,12 @@ class TestBitrateObserver : public BitrateAllocatorObserver {
|
||||
}
|
||||
|
||||
uint32_t OnBitrateUpdated(BitrateAllocationUpdate update) override {
|
||||
last_bitrate_bps_ = update.bitrate_bps;
|
||||
last_fraction_loss_ = update.fraction_loss;
|
||||
last_rtt_ms_ = update.rtt;
|
||||
last_probing_interval_ms_ = update.bwe_period_ms;
|
||||
return update.bitrate_bps * protection_ratio_;
|
||||
last_bitrate_bps_ = update.target_bitrate.bps();
|
||||
last_fraction_loss_ =
|
||||
rtc::dchecked_cast<uint8_t>(update.packet_loss_ratio * 256);
|
||||
last_rtt_ms_ = update.round_trip_time.ms();
|
||||
last_probing_interval_ms_ = update.bwe_period.ms();
|
||||
return update.target_bitrate.bps() * protection_ratio_;
|
||||
}
|
||||
uint32_t last_bitrate_bps_;
|
||||
uint8_t last_fraction_loss_;
|
||||
|
||||
@ -616,14 +616,17 @@ uint32_t VideoSendStreamImpl::OnBitrateUpdated(BitrateAllocationUpdate update) {
|
||||
RTC_DCHECK(rtp_video_sender_->IsActive())
|
||||
<< "VideoSendStream::Start has not been called.";
|
||||
|
||||
rtp_video_sender_->OnBitrateUpdated(update.bitrate_bps, update.fraction_loss,
|
||||
update.rtt,
|
||||
stats_proxy_->GetSendFrameRate());
|
||||
rtp_video_sender_->OnBitrateUpdated(
|
||||
update.target_bitrate.bps(),
|
||||
rtc::dchecked_cast<uint8_t>(update.packet_loss_ratio * 256),
|
||||
update.round_trip_time.ms(), stats_proxy_->GetSendFrameRate());
|
||||
encoder_target_rate_bps_ = rtp_video_sender_->GetPayloadBitrateBps();
|
||||
encoder_target_rate_bps_ =
|
||||
std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_);
|
||||
video_stream_encoder_->OnBitrateUpdated(encoder_target_rate_bps_,
|
||||
update.fraction_loss, update.rtt);
|
||||
video_stream_encoder_->OnBitrateUpdated(
|
||||
encoder_target_rate_bps_,
|
||||
rtc::dchecked_cast<uint8_t>(update.packet_loss_ratio * 256),
|
||||
update.round_trip_time.ms());
|
||||
stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_);
|
||||
return rtp_video_sender_->GetProtectionBitrateBps();
|
||||
}
|
||||
|
||||
@ -72,9 +72,9 @@ class MockRtpVideoSender : public RtpVideoSenderInterface {
|
||||
|
||||
BitrateAllocationUpdate CreateAllocation(int bitrate_bps) {
|
||||
BitrateAllocationUpdate update;
|
||||
update.bitrate_bps = bitrate_bps;
|
||||
update.fraction_loss = 0;
|
||||
update.rtt = 0;
|
||||
update.target_bitrate = DataRate::bps(bitrate_bps);
|
||||
update.packet_loss_ratio = 0;
|
||||
update.round_trip_time = TimeDelta::Zero();
|
||||
return update;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user