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

Side by Side Diff: webrtc/base/rate_statistics.cc

Issue 2061423003: Refactor NACK bitrate allocation (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Moved rate limiter and addressed comments Created 4 years, 5 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 (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (num_samples_ == 0 || active_window_size <= 1 || 70 if (num_samples_ == 0 || active_window_size <= 1 ||
71 (num_samples_ <= 1 && active_window_size < current_window_size_ms_)) { 71 (num_samples_ <= 1 && active_window_size < current_window_size_ms_)) {
72 return rtc::Optional<uint32_t>(); 72 return rtc::Optional<uint32_t>();
73 } 73 }
74 74
75 float scale = scale_ / active_window_size; 75 float scale = scale_ / active_window_size;
76 return rtc::Optional<uint32_t>( 76 return rtc::Optional<uint32_t>(
77 static_cast<uint32_t>(accumulated_count_ * scale + 0.5f)); 77 static_cast<uint32_t>(accumulated_count_ * scale + 0.5f));
78 } 78 }
79 79
80 rtc::Optional<uint32_t> RateStatistics::Rate(int64_t now_ms) const {
danilchap 2016/06/28 14:26:17 May be it would be slightly cleaner if only one Ra
sprang_webrtc 2016/07/04 09:33:03 Done.
81 // Yes, this is ugly, but it's preferable to declaring all internal state
82 // mutable...
83 return const_cast<RateStatistics*>(this)->Rate(now_ms);
84 }
85
80 void RateStatistics::EraseOld(int64_t now_ms) { 86 void RateStatistics::EraseOld(int64_t now_ms) {
81 if (!IsInitialized()) 87 if (!IsInitialized())
82 return; 88 return;
83 89
84 // New oldest time that is included in data set. 90 // New oldest time that is included in data set.
85 int64_t new_oldest_time = now_ms - current_window_size_ms_ + 1; 91 int64_t new_oldest_time = now_ms - current_window_size_ms_ + 1;
86 92
87 // New oldest time is older than the current one, no need to cull data. 93 // New oldest time is older than the current one, no need to cull data.
88 if (new_oldest_time <= oldest_time_) 94 if (new_oldest_time <= oldest_time_)
89 return; 95 return;
(...skipping 20 matching lines...) Expand all
110 current_window_size_ms_ = window_size_ms; 116 current_window_size_ms_ = window_size_ms;
111 EraseOld(now_ms); 117 EraseOld(now_ms);
112 return true; 118 return true;
113 } 119 }
114 120
115 bool RateStatistics::IsInitialized() { 121 bool RateStatistics::IsInitialized() {
116 return oldest_time_ != -max_window_size_ms_; 122 return oldest_time_ != -max_window_size_ms_;
117 } 123 }
118 124
119 } // namespace webrtc 125 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698