webrtc_m130/webrtc/modules/pacing/alr_detector.cc
Sergey Ulanov 0182f85fd1 More reliable ALR detection
Previously AlrDetector was measuring amount of data sent in each 100ms
interval and would enter ALR mode after 5 consecutive intervals when
average bandwidth usage doesn't exceed 30% of the current estimate
estimate. This meant that an application that uses only slightely more
than 6% of total bandwidth may stay out of ALR mode, e.g. if it sends
a frame of size BW*30ms every 0.5 seconds. 100ms is too short interval
to average over, particularly when frame-rate falls below 10fps.

With this change AlrDetector averages BW usage over last 500ms. It then
enters ALR state when usage falls below 30% and exits it when usage
exceeds 50%.

BUG=webrtc:6332
R=philipel@webrtc.org, stefan@webrtc.org

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

Cr-Commit-Position: refs/heads/master@{#15109}
2016-11-16 23:42:22 +00:00

64 lines
2.0 KiB
C++

/*
* Copyright (c) 2016 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 "webrtc/modules/pacing/alr_detector.h"
#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
namespace {
// Time period over which outgoing traffic is measured.
constexpr int kMeasurementPeriodMs = 500;
// Sent traffic percentage as a function of network capacity used to determine
// application-limited region. ALR region start when bandwidth usage drops below
// kAlrStartUsagePercent and ends when it raises above kAlrEndUsagePercent.
// NOTE: This is intentionally conservative at the moment until BW adjustments
// of application limited region is fine tuned.
constexpr int kAlrStartUsagePercent = 30;
constexpr int kAlrEndUsagePercent = 50;
} // namespace
namespace webrtc {
AlrDetector::AlrDetector()
: rate_(kMeasurementPeriodMs, RateStatistics::kBpsScale) {}
AlrDetector::~AlrDetector() {}
void AlrDetector::OnBytesSent(size_t bytes_sent, int64_t now_ms) {
RTC_DCHECK(estimated_bitrate_bps_);
rate_.Update(bytes_sent, now_ms);
rtc::Optional<uint32_t> rate = rate_.Rate(now_ms);
if (!rate)
return;
int percentage = static_cast<int>(*rate) * 100 / estimated_bitrate_bps_;
if (percentage < kAlrStartUsagePercent && !application_limited_) {
application_limited_ = true;
} else if (percentage > kAlrEndUsagePercent && application_limited_) {
application_limited_ = false;
}
}
void AlrDetector::SetEstimatedBitrate(int bitrate_bps) {
RTC_DCHECK(bitrate_bps);
estimated_bitrate_bps_ = bitrate_bps;
}
bool AlrDetector::InApplicationLimitedRegion() const {
return application_limited_;
}
} // namespace webrtc