OLD | NEW |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 RTC_DCHECK_LT(now_offset, max_window_size_ms_); | 54 RTC_DCHECK_LT(now_offset, max_window_size_ms_); |
55 uint32_t index = oldest_index_ + now_offset; | 55 uint32_t index = oldest_index_ + now_offset; |
56 if (index >= max_window_size_ms_) | 56 if (index >= max_window_size_ms_) |
57 index -= max_window_size_ms_; | 57 index -= max_window_size_ms_; |
58 buckets_[index].sum += count; | 58 buckets_[index].sum += count; |
59 ++buckets_[index].samples; | 59 ++buckets_[index].samples; |
60 accumulated_count_ += count; | 60 accumulated_count_ += count; |
61 ++num_samples_; | 61 ++num_samples_; |
62 } | 62 } |
63 | 63 |
64 rtc::Optional<uint32_t> RateStatistics::Rate(int64_t now_ms) const { | 64 rtc::Optional<uint32_t> RateStatistics::Rate(int64_t now_ms) { |
65 // Yeah, this const_cast ain't pretty, but the alternative is to declare most | 65 EraseOld(now_ms); |
66 // of the members as mutable... | |
67 const_cast<RateStatistics*>(this)->EraseOld(now_ms); | |
68 | 66 |
69 // If window is a single bucket or there is only one sample in a data set that | 67 // If window is a single bucket or there is only one sample in a data set that |
70 // has not grown to the full window size, treat this as rate unavailable. | 68 // has not grown to the full window size, treat this as rate unavailable. |
71 int64_t active_window_size = now_ms - oldest_time_ + 1; | 69 int64_t active_window_size = now_ms - oldest_time_ + 1; |
72 if (num_samples_ == 0 || active_window_size <= 1 || | 70 if (num_samples_ == 0 || active_window_size <= 1 || |
73 (num_samples_ <= 1 && active_window_size < current_window_size_ms_)) { | 71 (num_samples_ <= 1 && active_window_size < current_window_size_ms_)) { |
74 return rtc::Optional<uint32_t>(); | 72 return rtc::Optional<uint32_t>(); |
75 } | 73 } |
76 | 74 |
77 float scale = scale_ / active_window_size; | 75 float scale = scale_ / active_window_size; |
(...skipping 29 matching lines...) Expand all Loading... |
107 | 105 |
108 bool RateStatistics::SetWindowSize(int64_t window_size_ms, int64_t now_ms) { | 106 bool RateStatistics::SetWindowSize(int64_t window_size_ms, int64_t now_ms) { |
109 if (window_size_ms <= 0 || window_size_ms > max_window_size_ms_) | 107 if (window_size_ms <= 0 || window_size_ms > max_window_size_ms_) |
110 return false; | 108 return false; |
111 | 109 |
112 current_window_size_ms_ = window_size_ms; | 110 current_window_size_ms_ = window_size_ms; |
113 EraseOld(now_ms); | 111 EraseOld(now_ms); |
114 return true; | 112 return true; |
115 } | 113 } |
116 | 114 |
117 bool RateStatistics::IsInitialized() const { | 115 bool RateStatistics::IsInitialized() { |
118 return oldest_time_ != -max_window_size_ms_; | 116 return oldest_time_ != -max_window_size_ms_; |
119 } | 117 } |
120 | 118 |
121 } // namespace webrtc | 119 } // namespace webrtc |
OLD | NEW |