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