/* * Copyright 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.
*/
void BitrateAdjuster::SetTargetBitrateBps(uint32_t bitrate_bps) {
MutexLock lock(&mutex_); // If the change in target bitrate is large, update the adjusted bitrate // immediately since it's likely we have gained or lost a sizeable amount of // bandwidth and we'll want to respond quickly. // If the change in target bitrate fits within the existing tolerance of // encoder output, wait for the next adjustment time to preserve // existing penalties and not forcibly reset the adjusted bitrate to target. // However, if we received many small deltas within an update time // window and one of them exceeds the tolerance when compared to the last // target we updated against, treat it as a large change in target bitrate. if (!IsWithinTolerance(bitrate_bps, target_bitrate_bps_) ||
!IsWithinTolerance(bitrate_bps, last_adjusted_target_bitrate_bps_)) {
adjusted_bitrate_bps_ = bitrate_bps;
last_adjusted_target_bitrate_bps_ = bitrate_bps;
}
target_bitrate_bps_ = bitrate_bps;
}
// Only safe to call this after Update calls have stopped void BitrateAdjuster::Reset() {
MutexLock lock(&mutex_);
target_bitrate_bps_ = 0;
adjusted_bitrate_bps_ = 0;
last_adjusted_target_bitrate_bps_ = 0;
last_bitrate_update_time_ms_ = 0;
frames_since_last_update_ = 0;
bitrate_tracker_.Reset();
}
void BitrateAdjuster::UpdateBitrate(uint32_t current_time_ms) {
uint32_t time_since_last_update_ms =
current_time_ms - last_bitrate_update_time_ms_; // Don't attempt to update bitrate unless enough time and frames have passed.
++frames_since_last_update_; if (time_since_last_update_ms < kBitrateUpdateIntervalMs ||
frames_since_last_update_ < kBitrateUpdateFrameInterval) { return;
} float target_bitrate_bps = target_bitrate_bps_; float estimated_bitrate_bps =
bitrate_tracker_.Rate(current_time_ms).value_or(target_bitrate_bps); float error = target_bitrate_bps - estimated_bitrate_bps;
// Adjust if we've overshot by any amount or if we've undershot too much. if (estimated_bitrate_bps > target_bitrate_bps ||
error > kBitrateTolerancePct * target_bitrate_bps) { // Adjust the bitrate by a fraction of the error. float adjustment = .5 * error; float adjusted_bitrate_bps = target_bitrate_bps + adjustment;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.