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

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

Issue 2029593002: Update RateStatistics to handle too-little-data case. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comment Created 4 years, 6 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
« no previous file with comments | « no previous file | webrtc/base/rate_statistics.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 (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
11 #ifndef WEBRTC_BASE_RATE_STATISTICS_H_ 11 #ifndef WEBRTC_BASE_RATE_STATISTICS_H_
12 #define WEBRTC_BASE_RATE_STATISTICS_H_ 12 #define WEBRTC_BASE_RATE_STATISTICS_H_
13 13
14 #include <memory> 14 #include <memory>
15 15
16 #include "webrtc/base/optional.h"
16 #include "webrtc/typedefs.h" 17 #include "webrtc/typedefs.h"
17 18
18 namespace webrtc { 19 namespace webrtc {
19 20
20 class RateStatistics { 21 class RateStatistics {
21 public: 22 public:
22 // window_size = window size in ms for the rate estimation 23 // max_window_size_ms = Maximum window size in ms for the rate estimation.
24 // Initial window size is set to this, but may be changed
25 // to something lower by calling SetWindowSize().
23 // scale = coefficient to convert counts/ms to desired units, 26 // scale = coefficient to convert counts/ms to desired units,
24 // ex: if counts represents bytes, use 8*1000 to go to bits/s 27 // ex: if counts represents bytes, use 8*1000 to go to bits/s
25 RateStatistics(uint32_t window_size_ms, float scale); 28 RateStatistics(int64_t max_window_size_ms, float scale);
26 ~RateStatistics(); 29 ~RateStatistics();
27 30
28 void Reset(); 31 void Reset();
29 void Update(size_t count, int64_t now_ms); 32 void Update(size_t count, int64_t now_ms);
30 uint32_t Rate(int64_t now_ms); 33 rtc::Optional<uint32_t> Rate(int64_t now_ms);
34 bool SetWindowSize(int64_t window_size_ms, int64_t now_ms);
31 35
32 private: 36 private:
33 void EraseOld(int64_t now_ms); 37 void EraseOld(int64_t now_ms);
38 bool IsInitialized();
34 39
35 // Counters are kept in buckets (circular buffer), with one bucket 40 // Counters are kept in buckets (circular buffer), with one bucket
36 // per millisecond. 41 // per millisecond.
37 const int num_buckets_; 42 struct Bucket {
38 std::unique_ptr<size_t[]> buckets_; 43 size_t sum; // Sum of all samples in this bucket.
44 size_t samples; // Number of samples in this bucket.
45 };
46 std::unique_ptr<Bucket[]> buckets_;
39 47
40 // Total count recorded in buckets. 48 // Total count recorded in buckets.
41 size_t accumulated_count_; 49 size_t accumulated_count_;
42 50
51 // The total number of samples in the buckets.
52 size_t num_samples_;
53
43 // Oldest time recorded in buckets. 54 // Oldest time recorded in buckets.
44 int64_t oldest_time_; 55 int64_t oldest_time_;
45 56
46 // Bucket index of oldest counter recorded in buckets. 57 // Bucket index of oldest counter recorded in buckets.
47 int oldest_index_; 58 uint32_t oldest_index_;
48 59
49 // To convert counts/ms to desired units 60 // To convert counts/ms to desired units
50 const float scale_; 61 const float scale_;
62
63 // The window sizes, in ms, over which the rate is calculated.
64 const int64_t max_window_size_ms_;
65 int64_t current_window_size_ms_;
51 }; 66 };
52 } // namespace webrtc 67 } // namespace webrtc
53 68
54 #endif // WEBRTC_BASE_RATE_STATISTICS_H_ 69 #endif // WEBRTC_BASE_RATE_STATISTICS_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/rate_statistics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698