| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | #ifndef RTC_BASE_FREQUENCY_TRACKER_H_ |
| 12 | #define RTC_BASE_FREQUENCY_TRACKER_H_ |
| 13 |
| 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
| 16 |
| 17 | #include "absl/types/optional.h" |
| 18 | #include "api/units/frequency.h" |
| 19 | #include "api/units/time_delta.h" |
| 20 | #include "api/units/timestamp.h" |
| 21 | #include "rtc_base/rate_statistics.h" |
| 22 | #include "rtc_base/system/rtc_export.h" |
| 23 |
| 24 | namespace webrtc { |
| 25 | // Class to estimate frequency (e.g. frame rate) over running window. |
| 26 | // Timestamps used in Update() and Rate() must never decrease for two |
| 27 | // consecutive calls. |
| 28 | // This class is thread unsafe. |
| 29 | class RTC_EXPORT FrequencyTracker { |
| 30 | public: |
| 31 | explicit FrequencyTracker(TimeDelta window_size); |
| 32 |
| 33 | FrequencyTracker(const FrequencyTracker&) = default; |
| 34 | FrequencyTracker(FrequencyTracker&&) = default; |
| 35 | FrequencyTracker& operator=(const FrequencyTracker&) = delete; |
| 36 | FrequencyTracker& operator=(FrequencyTracker&&) = delete; |
| 37 |
| 38 | ~FrequencyTracker() = default; |
| 39 |
| 40 | // Reset instance to original state. |
| 41 | void Reset() { impl_.Reset(); } |
| 42 |
| 43 | // Update rate with a new data point, moving averaging window as needed. |
| 44 | void Update(int64_t count, Timestamp now); |
| 45 | void Update(Timestamp now) { Update(1, now); } |
| 46 |
| 47 | // Returns rate, moving averaging window as needed. |
| 48 | // Returns nullopt when rate can't be measured. |
| 49 | absl::optional<Frequency> Rate(Timestamp now) const; |
| 50 |
| 51 | private: |
| 52 | RateStatistics impl_; |
| 53 | }; |
| 54 | } // namespace webrtc |
| 55 |
| 56 | #endif // RTC_BASE_FREQUENCY_TRACKER_H_ |
| 57 |