Fix for calling OnNetworkChanged too often.

Review URL: https://webrtc-codereview.appspot.com/508006

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2085 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pwestin@webrtc.org 2012-04-23 08:32:47 +00:00
parent 88ad06b999
commit a2cd732139
6 changed files with 44 additions and 29 deletions

View File

@ -207,5 +207,9 @@ void BitrateControllerImpl::OnNetworkChanged(const uint32_t bitrate,
max_it = list_max_bitrates.begin();
}
}
bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const {
return bandwidth_estimation_.AvailableBandwidth(bandwidth);
}
} // namespace webrtc

View File

@ -33,6 +33,8 @@ class BitrateControllerImpl : public BitrateController {
explicit BitrateControllerImpl();
virtual ~BitrateControllerImpl();
virtual bool AvailableBandwidth(uint32_t* bandwidth) const;
virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver();
virtual void SetBitrateObserver(BitrateObserver* observer,

View File

@ -30,12 +30,9 @@ class BitrateObserver {
const uint8_t fraction_loss, // 0 - 255.
const uint32_t rtt) = 0;
protected:
virtual ~BitrateObserver() {}
};
// TODO(pwestin) move code from vie_remb in here
class BitrateController {
/*
* This class collects feedback from all streams sent to a peer (via
@ -49,6 +46,8 @@ class BitrateController {
virtual RtcpBandwidthObserver* CreateRtcpBandwidthObserver() = 0;
virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
/*
* Set the start and max send bitrate used by the bandwidth management.
*

View File

@ -113,9 +113,8 @@ bool SendSideBandwidthEstimation::UpdatePacketLoss(
}
// Keep for next time.
last_fraction_loss_ = *loss;
uint32_t bitrate = ShapeSimple(*loss, rtt, now_ms);
if (bitrate == 0) {
uint32_t bitrate = 0;
if (!ShapeSimple(*loss, rtt, now_ms, &bitrate)) {
// No change.
return false;
}
@ -158,22 +157,24 @@ uint32_t SendSideBandwidthEstimation::CalcTFRCbps(uint16_t rtt, uint8_t loss) {
return (static_cast<uint32_t>(X * 8)); // bits/second
}
uint32_t SendSideBandwidthEstimation::ShapeSimple(uint8_t loss, uint32_t rtt,
uint32_t now_ms) {
bool SendSideBandwidthEstimation::ShapeSimple(const uint8_t loss,
const uint32_t rtt,
const uint32_t now_ms,
uint32_t* bitrate) {
uint32_t new_bitrate = 0;
bool reducing = false;
// Limit the rate increases to once a kBWEIncreaseIntervalMs.
if (loss <= 5) {
if ((now_ms - time_last_increase_) < kBWEIncreaseIntervalMs) {
return bitrate_;
return false;
}
time_last_increase_ = now_ms;
}
// Limit the rate decreases to once a kBWEDecreaseIntervalMs + rtt.
if (loss > 26) {
if ((now_ms - time_last_decrease_) < kBWEDecreaseIntervalMs + rtt) {
return bitrate_;
return false;
}
time_last_decrease_ = now_ms;
}
@ -218,6 +219,7 @@ uint32_t SendSideBandwidthEstimation::ShapeSimple(uint8_t loss, uint32_t rtt,
min_bitrate_configured_ / 1000, new_bitrate / 1000);
new_bitrate = min_bitrate_configured_;
}
return new_bitrate;
*bitrate = new_bitrate;
return true;
}
} // namespace webrtc

View File

@ -43,7 +43,8 @@ class SendSideBandwidthEstimation {
void SetMinMaxBitrate(const uint32_t min_bitrate, const uint32_t max_bitrate);
private:
uint32_t ShapeSimple(uint8_t loss, uint32_t rtt, uint32_t now_ms);
bool ShapeSimple(const uint8_t loss, const uint32_t rtt,
const uint32_t now_ms, uint32_t* bitrate);
uint32_t CalcTFRCbps(uint16_t rtt, uint8_t loss);

View File

@ -74,13 +74,15 @@ TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) {
// Test start bitrate.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 1, 1);
EXPECT_EQ(bitrate_observer.last_bitrate, 200000u);
EXPECT_EQ(bitrate_observer.last_bitrate, 0u);
EXPECT_EQ(bitrate_observer.last_fraction_loss, 0);
EXPECT_EQ(bitrate_observer.last_rtt, 50u);
EXPECT_EQ(bitrate_observer.last_rtt, 0u);
// Test bitrate increase 8% per second.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 21, 1001);
EXPECT_EQ(bitrate_observer.last_bitrate, 217000u);
EXPECT_EQ(bitrate_observer.last_fraction_loss, 0);
EXPECT_EQ(bitrate_observer.last_rtt, 50u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 41, 2001);
EXPECT_EQ(bitrate_observer.last_bitrate, 235360u);
@ -88,7 +90,7 @@ TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) {
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 61, 3001);
EXPECT_EQ(bitrate_observer.last_bitrate, 255189u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 81, 4001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 801, 4001);
EXPECT_EQ(bitrate_observer.last_bitrate, 276604u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 101, 5001);
@ -124,14 +126,16 @@ TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) {
// Test start bitrate.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 1, 1);
second_bandwidth_observer->OnReceivedRtcpReceiverReport(1, 0, 100, 1, 1);
EXPECT_EQ(bitrate_observer.last_bitrate, 200000u);
EXPECT_EQ(bitrate_observer.last_bitrate, 0u);
EXPECT_EQ(bitrate_observer.last_fraction_loss, 0);
EXPECT_EQ(bitrate_observer.last_rtt, 100u);
EXPECT_EQ(bitrate_observer.last_rtt, 0u);
// Test bitrate increase 8% per second.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 21, 1001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 21, 501);
second_bandwidth_observer->OnReceivedRtcpReceiverReport(1, 0, 100, 21, 1001);
EXPECT_EQ(bitrate_observer.last_bitrate, 217000u);
EXPECT_EQ(bitrate_observer.last_fraction_loss, 0);
EXPECT_EQ(bitrate_observer.last_rtt, 100u);
// Extra report should not change estimate.
second_bandwidth_observer->OnReceivedRtcpReceiverReport(1, 0, 100, 31, 1501);
@ -139,6 +143,7 @@ TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) {
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 41, 2001);
EXPECT_EQ(bitrate_observer.last_bitrate, 235360u);
// Second report should not change estimate.
second_bandwidth_observer->OnReceivedRtcpReceiverReport(1, 0, 100, 41, 2001);
EXPECT_EQ(bitrate_observer.last_bitrate, 235360u);
@ -183,6 +188,9 @@ TEST_F(BitrateControllerTest, TwoBitrateObserversOneRtcpObserver) {
// Test too low start bitrate, hence lower than sum of min.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 1, 1);
// Test bitrate increase 8% per second, distributed equally.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 21, 1001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 100000u);
EXPECT_EQ(bitrate_observer_1.last_fraction_loss, 0);
EXPECT_EQ(bitrate_observer_1.last_rtt, 50u);
@ -191,48 +199,47 @@ TEST_F(BitrateControllerTest, TwoBitrateObserversOneRtcpObserver) {
EXPECT_EQ(bitrate_observer_2.last_fraction_loss, 0);
EXPECT_EQ(bitrate_observer_2.last_rtt, 50u);
// Test bitrate increase 8% per second, distributed equaly.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 21, 1001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 41, 2001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 112500u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 212500u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 41, 2001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 61, 3001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 126000u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 226000u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 61, 3001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 81, 4001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 140580u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 240580u);
// Check that the bitrate sum honor our REMB.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 81, 4001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 101, 5001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 150000u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 250000u);
// Remove REMB cap, higher than sum of max.
bandwidth_observer_->OnReceivedEstimatedBitrate(700000);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 101, 5001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 121, 6001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 166500u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 266500u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 121, 6001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 141, 7001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 184320u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 284320u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 141, 7001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 161, 8001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 207130u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 300000u); // Max cap.
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 161, 8001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 181, 9001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 248700u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 300000u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 181, 9001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 201, 10001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 293596u);
EXPECT_EQ(bitrate_observer_2.last_bitrate, 300000u);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 201, 10001);
bandwidth_observer_->OnReceivedRtcpReceiverReport(1, 0, 50, 221, 11001);
EXPECT_EQ(bitrate_observer_1.last_bitrate, 300000u); // Max cap.
EXPECT_EQ(bitrate_observer_2.last_bitrate, 300000u);