| Index: webrtc/base/rate_statistics.h
|
| diff --git a/webrtc/base/rate_statistics.h b/webrtc/base/rate_statistics.h
|
| index aea8d793fed154df0c60c3f54c52e8f2f1eb7d12..0b881a1cfb6ce783b9ce3a7e615ec204ad7c93b8 100644
|
| --- a/webrtc/base/rate_statistics.h
|
| +++ b/webrtc/base/rate_statistics.h
|
| @@ -13,41 +13,55 @@
|
|
|
| #include <memory>
|
|
|
| +#include "webrtc/base/optional.h"
|
| #include "webrtc/typedefs.h"
|
|
|
| namespace webrtc {
|
|
|
| class RateStatistics {
|
| public:
|
| - // window_size = window size in ms for the rate estimation
|
| + // max_window_size_ms = Maximum window size in ms for the rate estimation.
|
| + // Initial window size is set to this, but may be changed
|
| + // to something lower by calling SetWindowSize().
|
| // scale = coefficient to convert counts/ms to desired units,
|
| // ex: if counts represents bytes, use 8*1000 to go to bits/s
|
| - RateStatistics(uint32_t window_size_ms, float scale);
|
| + RateStatistics(int64_t max_window_size_ms, float scale);
|
| ~RateStatistics();
|
|
|
| void Reset();
|
| void Update(size_t count, int64_t now_ms);
|
| - uint32_t Rate(int64_t now_ms);
|
| + rtc::Optional<uint32_t> Rate(int64_t now_ms);
|
| + bool SetWindowSize(int64_t window_size_ms, int64_t now_ms);
|
|
|
| private:
|
| void EraseOld(int64_t now_ms);
|
|
|
| // Counters are kept in buckets (circular buffer), with one bucket
|
| // per millisecond.
|
| - const int num_buckets_;
|
| - std::unique_ptr<size_t[]> buckets_;
|
| + struct Bucket {
|
| + size_t sum; // Sum of all samples in this bucket.
|
| + size_t samples; // Number of samples in this bucket.
|
| + };
|
| + std::unique_ptr<Bucket[]> buckets_;
|
|
|
| // Total count recorded in buckets.
|
| size_t accumulated_count_;
|
|
|
| + // The total number of samples in the buckets.
|
| + size_t num_samples_;
|
| +
|
| // Oldest time recorded in buckets.
|
| int64_t oldest_time_;
|
|
|
| // Bucket index of oldest counter recorded in buckets.
|
| - int oldest_index_;
|
| + uint32_t oldest_index_;
|
|
|
| // To convert counts/ms to desired units
|
| const float scale_;
|
| +
|
| + // The window sizes, in ms, over which the rate is calculated.
|
| + const int64_t max_window_size_ms_;
|
| + int64_t current_window_size_ms_;
|
| };
|
| } // namespace webrtc
|
|
|
|
|