Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: webrtc/common_video/bitrate_adjuster.cc

Issue 2029593002: Update RateStatistics to handle too-little-data case. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comment Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 uint32_t BitrateAdjuster::GetTargetBitrateBps() const { 63 uint32_t BitrateAdjuster::GetTargetBitrateBps() const {
64 rtc::CritScope cs(&crit_); 64 rtc::CritScope cs(&crit_);
65 return target_bitrate_bps_; 65 return target_bitrate_bps_;
66 } 66 }
67 67
68 uint32_t BitrateAdjuster::GetAdjustedBitrateBps() const { 68 uint32_t BitrateAdjuster::GetAdjustedBitrateBps() const {
69 rtc::CritScope cs(&crit_); 69 rtc::CritScope cs(&crit_);
70 return adjusted_bitrate_bps_; 70 return adjusted_bitrate_bps_;
71 } 71 }
72 72
73 uint32_t BitrateAdjuster::GetEstimatedBitrateBps() { 73 rtc::Optional<uint32_t> BitrateAdjuster::GetEstimatedBitrateBps() {
74 rtc::CritScope cs(&crit_); 74 rtc::CritScope cs(&crit_);
75 return bitrate_tracker_.Rate(clock_->TimeInMilliseconds()); 75 return bitrate_tracker_.Rate(clock_->TimeInMilliseconds());
76 } 76 }
77 77
78 void BitrateAdjuster::Update(size_t frame_size) { 78 void BitrateAdjuster::Update(size_t frame_size) {
79 rtc::CritScope cs(&crit_); 79 rtc::CritScope cs(&crit_);
80 uint32_t current_time_ms = clock_->TimeInMilliseconds(); 80 uint32_t current_time_ms = clock_->TimeInMilliseconds();
81 bitrate_tracker_.Update(frame_size, current_time_ms); 81 bitrate_tracker_.Update(frame_size, current_time_ms);
82 UpdateBitrate(current_time_ms); 82 UpdateBitrate(current_time_ms);
83 } 83 }
(...skipping 30 matching lines...) Expand all
114 114
115 void BitrateAdjuster::UpdateBitrate(uint32_t current_time_ms) { 115 void BitrateAdjuster::UpdateBitrate(uint32_t current_time_ms) {
116 uint32_t time_since_last_update_ms = 116 uint32_t time_since_last_update_ms =
117 current_time_ms - last_bitrate_update_time_ms_; 117 current_time_ms - last_bitrate_update_time_ms_;
118 // Don't attempt to update bitrate unless enough time and frames have passed. 118 // Don't attempt to update bitrate unless enough time and frames have passed.
119 ++frames_since_last_update_; 119 ++frames_since_last_update_;
120 if (time_since_last_update_ms < kBitrateUpdateIntervalMs || 120 if (time_since_last_update_ms < kBitrateUpdateIntervalMs ||
121 frames_since_last_update_ < kBitrateUpdateFrameInterval) { 121 frames_since_last_update_ < kBitrateUpdateFrameInterval) {
122 return; 122 return;
123 } 123 }
124 float estimated_bitrate_bps = bitrate_tracker_.Rate(current_time_ms);
125 float target_bitrate_bps = target_bitrate_bps_; 124 float target_bitrate_bps = target_bitrate_bps_;
125 float estimated_bitrate_bps =
126 bitrate_tracker_.Rate(current_time_ms).value_or(target_bitrate_bps);
126 float error = target_bitrate_bps - estimated_bitrate_bps; 127 float error = target_bitrate_bps - estimated_bitrate_bps;
127 128
128 // Adjust if we've overshot by any amount or if we've undershot too much. 129 // Adjust if we've overshot by any amount or if we've undershot too much.
129 if (estimated_bitrate_bps > target_bitrate_bps || 130 if (estimated_bitrate_bps > target_bitrate_bps ||
130 error > kBitrateTolerancePct * target_bitrate_bps) { 131 error > kBitrateTolerancePct * target_bitrate_bps) {
131 // Adjust the bitrate by a fraction of the error. 132 // Adjust the bitrate by a fraction of the error.
132 float adjustment = .5 * error; 133 float adjustment = .5 * error;
133 float adjusted_bitrate_bps = target_bitrate_bps + adjustment; 134 float adjusted_bitrate_bps = target_bitrate_bps + adjustment;
134 135
135 // Clamp the adjustment. 136 // Clamp the adjustment.
(...skipping 16 matching lines...) Expand all
152 << static_cast<uint32_t>(adjusted_bitrate_bps); 153 << static_cast<uint32_t>(adjusted_bitrate_bps);
153 adjusted_bitrate_bps_ = adjusted_bitrate_bps; 154 adjusted_bitrate_bps_ = adjusted_bitrate_bps;
154 } 155 }
155 } 156 }
156 last_bitrate_update_time_ms_ = current_time_ms; 157 last_bitrate_update_time_ms_ = current_time_ms;
157 frames_since_last_update_ = 0; 158 frames_since_last_update_ = 0;
158 last_adjusted_target_bitrate_bps_ = target_bitrate_bps_; 159 last_adjusted_target_bitrate_bps_ = target_bitrate_bps_;
159 } 160 }
160 161
161 } // namespace webrtc 162 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/base/rate_statistics_unittest.cc ('k') | webrtc/common_video/bitrate_adjuster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698