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 const_cast<RateStatistics*>(this)->EraseOld(now_ms); |
stefan-webrtc
2016/07/06 12:43:21
Isn't mutable an option instead?
sprang_webrtc
2016/07/06 14:13:07
We'd have to declare more or less all members as m
stefan-webrtc
2016/07/08 11:55:58
Acknowledged.
| |
66 | 66 |
67 // 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 |
68 // 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. |
69 int64_t active_window_size = now_ms - oldest_time_ + 1; | 69 int64_t active_window_size = now_ms - oldest_time_ + 1; |
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; |
(...skipping 29 matching lines...) Expand all Loading... | |
105 | 105 |
106 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) { |
107 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_) |
108 return false; | 108 return false; |
109 | 109 |
110 current_window_size_ms_ = window_size_ms; | 110 current_window_size_ms_ = window_size_ms; |
111 EraseOld(now_ms); | 111 EraseOld(now_ms); |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 bool RateStatistics::IsInitialized() { | 115 bool RateStatistics::IsInitialized() const { |
116 return oldest_time_ != -max_window_size_ms_; | 116 return oldest_time_ != -max_window_size_ms_; |
117 } | 117 } |
118 | 118 |
119 } // namespace webrtc | 119 } // namespace webrtc |
OLD | NEW |