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/ratetracker.cc

Issue 1410533004: Round Rate computations from RateTracker. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Correct first-bucket rounding. Created 5 years, 1 month 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
« no previous file with comments | « no previous file | webrtc/p2p/base/port.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 // If we're skipping all buckets that means that there have been no samples 67 // If we're skipping all buckets that means that there have been no samples
68 // within the sampling interval so report 0. 68 // within the sampling interval so report 0.
69 if (buckets_to_skip > bucket_count_ || 69 if (buckets_to_skip > bucket_count_ ||
70 available_interval_milliseconds == 0u) { 70 available_interval_milliseconds == 0u) {
71 return 0.0; 71 return 0.0;
72 } 72 }
73 size_t start_bucket = NextBucketIndex(current_bucket_ + buckets_to_skip); 73 size_t start_bucket = NextBucketIndex(current_bucket_ + buckets_to_skip);
74 // Only count a portion of the first bucket according to how much of the 74 // Only count a portion of the first bucket according to how much of the
75 // first bucket is within the current interval. 75 // first bucket is within the current interval.
76 size_t total_samples = sample_buckets_[start_bucket] * 76 size_t total_samples = ((sample_buckets_[start_bucket] *
77 (bucket_milliseconds_ - milliseconds_to_skip) / 77 (bucket_milliseconds_ - milliseconds_to_skip)) +
78 (bucket_milliseconds_ >> 1)) /
78 bucket_milliseconds_; 79 bucket_milliseconds_;
79 // All other buckets in the interval are counted in their entirety. 80 // All other buckets in the interval are counted in their entirety.
80 for (size_t i = NextBucketIndex(start_bucket); 81 for (size_t i = NextBucketIndex(start_bucket);
81 i != NextBucketIndex(current_bucket_); 82 i != NextBucketIndex(current_bucket_);
82 i = NextBucketIndex(i)) { 83 i = NextBucketIndex(i)) {
83 total_samples += sample_buckets_[i]; 84 total_samples += sample_buckets_[i];
84 } 85 }
85 // Convert to samples per second. 86 // Convert to samples per second.
86 return static_cast<double>(total_samples * 1000u) / 87 return static_cast<double>(total_samples * 1000u) /
87 static_cast<double>(available_interval_milliseconds); 88 static_cast<double>(available_interval_milliseconds);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // current_bucket_ increments. 139 // current_bucket_ increments.
139 sample_buckets_[current_bucket_] = 0u; 140 sample_buckets_[current_bucket_] = 0u;
140 } 141 }
141 } 142 }
142 143
143 size_t RateTracker::NextBucketIndex(size_t bucket_index) const { 144 size_t RateTracker::NextBucketIndex(size_t bucket_index) const {
144 return (bucket_index + 1u) % (bucket_count_ + 1u); 145 return (bucket_index + 1u) % (bucket_count_ + 1u);
145 } 146 }
146 147
147 } // namespace rtc 148 } // namespace rtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/base/port.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698