CongestionController::SetBweBitrates may now trigger probing.

BUG=webrtc:5859
R=stefan@webrtc.org

Review URL: https://codereview.webrtc.org/2246403002 .

Cr-Commit-Position: refs/heads/master@{#13791}
This commit is contained in:
philipel 2016-08-17 11:11:59 +02:00
parent c594aa61bc
commit eb680eac5d
8 changed files with 42 additions and 9 deletions

View File

@ -171,6 +171,7 @@ CongestionController::CongestionController(
remote_estimator_proxy_(clock_, packet_router_.get()),
transport_feedback_adapter_(bitrate_controller_.get(), clock_),
min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
max_bitrate_bps_(0),
last_reported_bitrate_bps_(0),
last_reported_fraction_loss_(0),
last_reported_rtt_(0),
@ -200,6 +201,7 @@ CongestionController::CongestionController(
remote_estimator_proxy_(clock_, packet_router_.get()),
transport_feedback_adapter_(bitrate_controller_.get(), clock_),
min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
max_bitrate_bps_(0),
last_reported_bitrate_bps_(0),
last_reported_fraction_loss_(0),
last_reported_rtt_(0),
@ -214,6 +216,8 @@ void CongestionController::Init() {
new DelayBasedBwe(&transport_feedback_adapter_, clock_));
transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
min_bitrate_bps_);
pacer_->CreateProbeCluster(900000, 6);
pacer_->CreateProbeCluster(1800000, 5);
}
void CongestionController::SetBweBitrates(int min_bitrate_bps,
@ -224,6 +228,21 @@ void CongestionController::SetBweBitrates(int min_bitrate_bps,
min_bitrate_bps,
max_bitrate_bps);
{
// Only do probing if:
// - we are mid-call, which we consider to be if
// |last_reported_bitrate_bps_| != 0, and
// - the current bitrate is lower than the new |max_bitrate_bps|, and
// - we actually want to increase the |max_bitrate_bps_|.
rtc::CritScope cs(&critsect_);
if (last_reported_bitrate_bps_ != 0 &&
last_reported_bitrate_bps_ < static_cast<uint32_t>(max_bitrate_bps) &&
max_bitrate_bps > max_bitrate_bps_) {
pacer_->CreateProbeCluster(max_bitrate_bps, 5);
}
}
max_bitrate_bps_ = max_bitrate_bps;
if (remote_bitrate_estimator_)
remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
min_bitrate_bps_ = min_bitrate_bps;
@ -241,6 +260,7 @@ void CongestionController::ResetBweAndBitrates(int bitrate_bps,
bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps,
max_bitrate_bps);
min_bitrate_bps_ = min_bitrate_bps;
max_bitrate_bps_ = max_bitrate_bps;
// TODO(honghaiz): Recreate this object once the remote bitrate estimator is
// no longer exposed outside CongestionController.
if (remote_bitrate_estimator_)

View File

@ -124,6 +124,7 @@ class CongestionController : public CallStatsObserver, public Module {
RemoteEstimatorProxy remote_estimator_proxy_;
TransportFeedbackAdapter transport_feedback_adapter_;
int min_bitrate_bps_;
int max_bitrate_bps_;
rtc::CriticalSection critsect_;
uint32_t last_reported_bitrate_bps_ GUARDED_BY(critsect_);
uint8_t last_reported_fraction_loss_ GUARDED_BY(critsect_);

View File

@ -59,12 +59,13 @@ void BitrateProber::OnIncomingPacket(size_t packet_size) {
// Don't initialize probing unless we have something large enough to start
// probing.
if (probing_state_ == ProbingState::kInactive &&
!clusters_.empty() &&
packet_size >= PacedSender::kMinProbePacketSize) {
probing_state_ = ProbingState::kActive;
}
}
void BitrateProber::ProbeAtBitrate(uint32_t bitrate_bps, int num_packets) {
void BitrateProber::CreateProbeCluster(int bitrate_bps, int num_packets) {
ProbeCluster cluster;
cluster.max_probe_packets = num_packets;
cluster.probe_bitrate_bps = bitrate_bps;
@ -85,8 +86,8 @@ void BitrateProber::ResetState() {
std::queue<ProbeCluster> clusters;
clusters.swap(clusters_);
while (!clusters.empty()) {
ProbeAtBitrate(clusters.front().probe_bitrate_bps,
clusters.front().max_probe_packets);
CreateProbeCluster(clusters.front().probe_bitrate_bps,
clusters.front().max_probe_packets);
clusters.pop();
}
// If its enabled, reset to inactive.

View File

@ -38,7 +38,7 @@ class BitrateProber {
// Create a cluster used to probe for |bitrate_bps| with |num_packets| number
// of packets.
void ProbeAtBitrate(uint32_t bitrate_bps, int num_packets);
void CreateProbeCluster(int bitrate_bps, int num_packets);
// Returns the number of milliseconds until the next packet should be sent to
// get accurate probing.

View File

@ -21,8 +21,8 @@ TEST(BitrateProberTest, VerifyStatesAndTimeBetweenProbes) {
int64_t now_ms = 0;
EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms));
prober.ProbeAtBitrate(900000, 6);
prober.ProbeAtBitrate(1800000, 5);
prober.CreateProbeCluster(900000, 6);
prober.CreateProbeCluster(1800000, 5);
EXPECT_FALSE(prober.IsProbing());
prober.OnIncomingPacket(1000);
@ -60,7 +60,7 @@ TEST(BitrateProberTest, DoesntProbeWithoutRecentPackets) {
int64_t now_ms = 0;
EXPECT_EQ(-1, prober.TimeUntilNextProbe(now_ms));
prober.ProbeAtBitrate(900000, 6);
prober.CreateProbeCluster(900000, 6);
EXPECT_FALSE(prober.IsProbing());
prober.OnIncomingPacket(1000);

View File

@ -261,12 +261,15 @@ PacedSender::PacedSender(Clock* clock, PacketSender* packet_sender)
packets_(new paced_sender::PacketQueue(clock)),
packet_counter_(0) {
UpdateBytesPerInterval(kMinPacketLimitMs);
prober_->ProbeAtBitrate(900000, 6);
prober_->ProbeAtBitrate(1800000, 5);
}
PacedSender::~PacedSender() {}
void PacedSender::CreateProbeCluster(int bitrate_bps, int num_packets) {
CriticalSectionScoped cs(critsect_.get());
prober_->CreateProbeCluster(bitrate_bps, num_packets);
}
void PacedSender::Pause() {
LOG(LS_INFO) << "PacedSender paused.";
CriticalSectionScoped cs(critsect_.get());

View File

@ -71,6 +71,8 @@ class PacedSender : public Module, public RtpPacketSender {
virtual ~PacedSender();
void CreateProbeCluster(int bitrate_bps, int num_packets);
// Temporarily pause all sending.
void Pause();

View File

@ -110,6 +110,8 @@ class PacedSenderTest : public ::testing::Test {
srand(0);
// Need to initialize PacedSender after we initialize clock.
send_bucket_.reset(new PacedSender(&clock_, &callback_));
send_bucket_->CreateProbeCluster(900000, 6);
send_bucket_->CreateProbeCluster(1800000, 5);
// Default to bitrate probing disabled for testing purposes. Probing tests
// have to enable probing, either by creating a new PacedSender instance or
// by calling SetProbingEnabled(true).
@ -814,6 +816,8 @@ TEST_F(PacedSenderTest, ProbingWithInitialFrame) {
expected_deltas + kNumDeltas);
PacedSenderProbing callback(expected_deltas_list, &clock_);
send_bucket_.reset(new PacedSender(&clock_, &callback));
send_bucket_->CreateProbeCluster(900000, 6);
send_bucket_->CreateProbeCluster(1800000, 5);
send_bucket_->SetEstimatedBitrate(kInitialBitrateBps);
for (int i = 0; i < kNumPackets; ++i) {
@ -844,6 +848,8 @@ TEST_F(PacedSenderTest, ProbingWithTooSmallInitialFrame) {
expected_deltas + kNumDeltas);
PacedSenderProbing callback(expected_deltas_list, &clock_);
send_bucket_.reset(new PacedSender(&clock_, &callback));
send_bucket_->CreateProbeCluster(900000, 6);
send_bucket_->CreateProbeCluster(1800000, 5);
send_bucket_->SetEstimatedBitrate(kInitialBitrateBps);
for (int i = 0; i < kNumPackets - 5; ++i) {