Using units in SendSideBandwidthEstimation.

This CL moves SendSideBandwidthEstimation to use the unit types
DataRate, TimeDelta and Timestamp. This prepares for upcoming changes.

Bug: webrtc:9718
Change-Id: If10e329920dda037b53055ff3352ae7f8d7e32b8
Reviewed-on: https://webrtc-review.googlesource.com/c/104021
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25029}
This commit is contained in:
Sebastian Jansson
2018-10-05 19:56:03 +02:00
committed by Commit Bot
parent 9f80b97309
commit 35b5e5f3b0
10 changed files with 289 additions and 245 deletions

View File

@ -20,7 +20,18 @@
#include "rtc_base/logging.h"
namespace webrtc {
namespace {
absl::optional<DataRate> ToOptionalDataRate(int start_bitrate_bps) {
if (start_bitrate_bps == -1)
return absl::nullopt;
return DataRate::bps(start_bitrate_bps);
}
DataRate MaxRate(int max_bitrate_bps) {
if (max_bitrate_bps == -1)
return DataRate::Infinity();
return DataRate::bps(max_bitrate_bps);
}
} // namespace
class BitrateControllerImpl::RtcpBandwidthObserverImpl
: public RtcpBandwidthObserver {
public:
@ -80,7 +91,9 @@ RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() {
void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) {
{
rtc::CritScope cs(&critsect_);
bandwidth_estimation_.SetSendBitrate(start_bitrate_bps);
bandwidth_estimation_.SetSendBitrate(
DataRate::bps(start_bitrate_bps),
Timestamp::ms(clock_->TimeInMilliseconds()));
}
MaybeTriggerOnNetworkChanged();
}
@ -89,7 +102,8 @@ void BitrateControllerImpl::SetMinMaxBitrate(int min_bitrate_bps,
int max_bitrate_bps) {
{
rtc::CritScope cs(&critsect_);
bandwidth_estimation_.SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps);
bandwidth_estimation_.SetMinMaxBitrate(DataRate::bps(min_bitrate_bps),
DataRate::bps(max_bitrate_bps));
}
MaybeTriggerOnNetworkChanged();
}
@ -99,8 +113,9 @@ void BitrateControllerImpl::SetBitrates(int start_bitrate_bps,
int max_bitrate_bps) {
{
rtc::CritScope cs(&critsect_);
bandwidth_estimation_.SetBitrates(start_bitrate_bps, min_bitrate_bps,
max_bitrate_bps);
bandwidth_estimation_.SetBitrates(
ToOptionalDataRate(start_bitrate_bps), DataRate::bps(min_bitrate_bps),
MaxRate(max_bitrate_bps), Timestamp::ms(clock_->TimeInMilliseconds()));
}
MaybeTriggerOnNetworkChanged();
}
@ -111,8 +126,9 @@ void BitrateControllerImpl::ResetBitrates(int bitrate_bps,
{
rtc::CritScope cs(&critsect_);
bandwidth_estimation_ = SendSideBandwidthEstimation(event_log_);
bandwidth_estimation_.SetBitrates(bitrate_bps, min_bitrate_bps,
max_bitrate_bps);
bandwidth_estimation_.SetBitrates(
ToOptionalDataRate(bitrate_bps), DataRate::bps(min_bitrate_bps),
MaxRate(max_bitrate_bps), Timestamp::ms(clock_->TimeInMilliseconds()));
}
MaybeTriggerOnNetworkChanged();
}
@ -121,8 +137,8 @@ void BitrateControllerImpl::ResetBitrates(int bitrate_bps,
void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) {
{
rtc::CritScope cs(&critsect_);
bandwidth_estimation_.UpdateReceiverEstimate(clock_->TimeInMilliseconds(),
bitrate);
bandwidth_estimation_.UpdateReceiverEstimate(
Timestamp::ms(clock_->TimeInMilliseconds()), DataRate::bps(bitrate));
BWE_TEST_LOGGING_PLOT(1, "REMB_kbps", clock_->TimeInMilliseconds(),
bitrate / 1000);
}
@ -136,12 +152,15 @@ void BitrateControllerImpl::OnDelayBasedBweResult(
{
rtc::CritScope cs(&critsect_);
if (result.probe) {
bandwidth_estimation_.SetSendBitrate(result.target_bitrate_bps);
bandwidth_estimation_.SetSendBitrate(
DataRate::bps(result.target_bitrate_bps),
Timestamp::ms(clock_->TimeInMilliseconds()));
}
// Since SetSendBitrate now resets the delay-based estimate, we have to call
// UpdateDelayBasedEstimate after SetSendBitrate.
bandwidth_estimation_.UpdateDelayBasedEstimate(clock_->TimeInMilliseconds(),
result.target_bitrate_bps);
bandwidth_estimation_.UpdateDelayBasedEstimate(
Timestamp::ms(clock_->TimeInMilliseconds()),
DataRate::bps(result.target_bitrate_bps));
}
MaybeTriggerOnNetworkChanged();
}
@ -158,7 +177,8 @@ int64_t BitrateControllerImpl::TimeUntilNextProcess() {
void BitrateControllerImpl::Process() {
{
rtc::CritScope cs(&critsect_);
bandwidth_estimation_.UpdateEstimate(clock_->TimeInMilliseconds());
bandwidth_estimation_.UpdateEstimate(
Timestamp::ms(clock_->TimeInMilliseconds()));
}
MaybeTriggerOnNetworkChanged();
last_bitrate_update_ms_ = clock_->TimeInMilliseconds();
@ -213,8 +233,9 @@ void BitrateControllerImpl::OnReceivedRtcpReceiverReport(
RTC_DCHECK_GE(total_number_of_packets, 0);
bandwidth_estimation_.UpdateReceiverBlock(fraction_lost_aggregate, rtt,
total_number_of_packets, now_ms);
bandwidth_estimation_.UpdateReceiverBlock(
fraction_lost_aggregate, TimeDelta::ms(rtt), total_number_of_packets,
Timestamp::ms(now_ms));
}
MaybeTriggerOnNetworkChanged();
}