forked from JumpingYang001/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds loss rate filter in BBR controller.
Adds a simple loss rate filter to the BBR network congestion controller. The loss rate is used to control error correction. Previously the value was reported as zero which would disable error correction. Bug: webrtc:8415 Change-Id: Icec8f25fcc9509432ea91eaec30b39a024f92b42 Reviewed-on: https://webrtc-review.googlesource.com/78263 Commit-Queue: Sebastian Jansson <[email protected]> Reviewed-by: Björn Terelius <[email protected]> Cr-Commit-Position: refs/heads/master@{#23467}
- Loading branch information
Showing
6 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2018 The WebRTC project authors. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by a BSD-style license | ||
* that can be found in the LICENSE file in the root of the source | ||
* tree. An additional intellectual property rights grant can be found | ||
* in the file PATENTS. All contributing project authors may | ||
* be found in the AUTHORS file in the root of the source tree. | ||
*/ | ||
#include "modules/congestion_controller/bbr/loss_rate_filter.h" | ||
|
||
namespace webrtc { | ||
namespace bbr { | ||
namespace { | ||
// From SendSideBandwidthEstimation. | ||
const int kLimitNumPackets = 20; | ||
// From RTCPSender video report interval. | ||
const int64_t kUpdateIntervalMs = 1000; | ||
} // namespace | ||
|
||
LossRateFilter::LossRateFilter() | ||
: lost_packets_since_last_loss_update_(0), | ||
expected_packets_since_last_loss_update_(0), | ||
loss_rate_estimate_(0.0), | ||
next_loss_update_ms_(0) {} | ||
|
||
void LossRateFilter::UpdateWithLossStatus(int64_t feedback_time, | ||
int packets_sent, | ||
int packets_lost) { | ||
lost_packets_since_last_loss_update_ += packets_lost; | ||
expected_packets_since_last_loss_update_ += packets_sent; | ||
|
||
if (feedback_time >= next_loss_update_ms_ && | ||
expected_packets_since_last_loss_update_ >= kLimitNumPackets) { | ||
int64_t lost = lost_packets_since_last_loss_update_; | ||
int64_t expected = expected_packets_since_last_loss_update_; | ||
loss_rate_estimate_ = static_cast<double>(lost) / expected; | ||
next_loss_update_ms_ = feedback_time + kUpdateIntervalMs; | ||
lost_packets_since_last_loss_update_ = 0; | ||
expected_packets_since_last_loss_update_ = 0; | ||
} | ||
} | ||
|
||
double LossRateFilter::GetLossRate() const { | ||
return loss_rate_estimate_; | ||
} | ||
} // namespace bbr | ||
} // namespace webrtc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2018 The WebRTC project authors. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by a BSD-style license | ||
* that can be found in the LICENSE file in the root of the source | ||
* tree. An additional intellectual property rights grant can be found | ||
* in the file PATENTS. All contributing project authors may | ||
* be found in the AUTHORS file in the root of the source tree. | ||
*/ | ||
#ifndef MODULES_CONGESTION_CONTROLLER_BBR_LOSS_RATE_FILTER_H_ | ||
#define MODULES_CONGESTION_CONTROLLER_BBR_LOSS_RATE_FILTER_H_ | ||
|
||
#include "api/optional.h" | ||
|
||
namespace webrtc { | ||
namespace bbr { | ||
|
||
// Loss rate filter based on the implementation in SendSideBandwidthEstimation | ||
// and the RTCPSender receiver report interval for video. | ||
class LossRateFilter { | ||
public: | ||
LossRateFilter(); | ||
void UpdateWithLossStatus(int64_t feedback_time_ms, | ||
int packets_sent, | ||
int packets_lost); | ||
double GetLossRate() const; | ||
|
||
private: | ||
int lost_packets_since_last_loss_update_; | ||
int expected_packets_since_last_loss_update_; | ||
double loss_rate_estimate_; | ||
int64_t next_loss_update_ms_; | ||
}; | ||
|
||
} // namespace bbr | ||
} // namespace webrtc | ||
|
||
#endif // MODULES_CONGESTION_CONTROLLER_BBR_LOSS_RATE_FILTER_H_ |
71 changes: 71 additions & 0 deletions
71
modules/congestion_controller/bbr/loss_rate_filter_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2018 The WebRTC project authors. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by a BSD-style license | ||
* that can be found in the LICENSE file in the root of the source | ||
* tree. An additional intellectual property rights grant can be found | ||
* in the file PATENTS. All contributing project authors may | ||
* be found in the AUTHORS file in the root of the source tree. | ||
*/ | ||
#include "modules/congestion_controller/bbr/loss_rate_filter.h" | ||
#include "api/units/timestamp.h" | ||
#include "test/gtest.h" | ||
|
||
namespace webrtc { | ||
namespace bbr { | ||
|
||
namespace { | ||
const Timestamp kTestStartTime = Timestamp::seconds(100000); | ||
} // namespace | ||
|
||
TEST(LossRateFilterTest, AccumulatesToOne) { | ||
LossRateFilter filter; | ||
Timestamp current_time = kTestStartTime; | ||
for (int i = 0; i < 10; i++) { | ||
filter.UpdateWithLossStatus(current_time.ms(), 10, 10); | ||
current_time += TimeDelta::seconds(1); | ||
} | ||
EXPECT_NEAR(filter.GetLossRate(), 1.0, 0.01); | ||
} | ||
|
||
TEST(LossRateFilterTest, StaysAtZero) { | ||
LossRateFilter filter; | ||
Timestamp current_time = kTestStartTime; | ||
for (int i = 0; i < 10; i++) { | ||
filter.UpdateWithLossStatus(current_time.ms(), 10, 0); | ||
current_time += TimeDelta::seconds(1); | ||
} | ||
EXPECT_NEAR(filter.GetLossRate(), 0.0, 0.01); | ||
} | ||
|
||
TEST(LossRateFilterTest, VariesWithInput) { | ||
LossRateFilter filter; | ||
Timestamp current_time = kTestStartTime; | ||
for (int j = 0; j < 10; j++) { | ||
for (int i = 0; i < 5; i++) { | ||
filter.UpdateWithLossStatus(current_time.ms(), 10, 10); | ||
current_time += TimeDelta::seconds(1); | ||
} | ||
EXPECT_NEAR(filter.GetLossRate(), 1.0, 0.1); | ||
for (int i = 0; i < 5; i++) { | ||
filter.UpdateWithLossStatus(current_time.ms(), 10, 0); | ||
current_time += TimeDelta::seconds(1); | ||
} | ||
EXPECT_NEAR(filter.GetLossRate(), 0.0, 0.1); | ||
} | ||
} | ||
|
||
TEST(LossRateFilterTest, DetectsChangingRate) { | ||
LossRateFilter filter; | ||
Timestamp current_time = kTestStartTime; | ||
for (int per_decile = 0; per_decile < 10; per_decile += 1) { | ||
// Update every 200 ms for 2 seconds | ||
for (int i = 0; i < 10; i++) { | ||
current_time += TimeDelta::ms(200); | ||
filter.UpdateWithLossStatus(current_time.ms(), 10, per_decile); | ||
} | ||
EXPECT_NEAR(filter.GetLossRate(), per_decile / 10.0, 0.05); | ||
} | ||
} | ||
} // namespace bbr | ||
} // namespace webrtc |