123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #ifndef RTC_BASE_RATE_STATISTICS_H_
- #define RTC_BASE_RATE_STATISTICS_H_
- #include <stddef.h>
- #include <stdint.h>
- #include <deque>
- #include <memory>
- #include "absl/types/optional.h"
- #include "rtc_base/system/rtc_export.h"
- namespace webrtc {
- class RTC_EXPORT RateStatistics {
- public:
- static constexpr float kBpsScale = 8000.0f;
-
-
-
-
-
- RateStatistics(int64_t max_window_size_ms, float scale);
- RateStatistics(const RateStatistics& other);
- RateStatistics(RateStatistics&& other);
- ~RateStatistics();
-
- void Reset();
-
- void Update(int64_t count, int64_t now_ms);
-
-
-
-
-
-
- absl::optional<int64_t> Rate(int64_t now_ms) const;
-
-
- bool SetWindowSize(int64_t window_size_ms, int64_t now_ms);
- private:
- void EraseOld(int64_t now_ms);
- struct Bucket {
- explicit Bucket(int64_t timestamp);
- int64_t sum;
- int num_samples;
- const int64_t timestamp;
- };
-
- std::deque<Bucket> buckets_;
-
- int64_t accumulated_count_;
-
- int64_t first_timestamp_;
-
-
- bool overflow_ = false;
-
- int num_samples_;
-
- const float scale_;
-
- const int64_t max_window_size_ms_;
- int64_t current_window_size_ms_;
- };
- }
- #endif
|