| 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 | #include "rtc_base/frequency_tracker.h" |
| 12 |
| 13 | #include "absl/types/optional.h" |
| 14 | #include "api/units/frequency.h" |
| 15 | #include "api/units/time_delta.h" |
| 16 | #include "api/units/timestamp.h" |
| 17 | #include "rtc_base/rate_statistics.h" |
| 18 |
| 19 | namespace webrtc { |
| 20 |
| 21 | FrequencyTracker::FrequencyTracker(TimeDelta max_window_size) |
| 22 | : impl_(max_window_size.ms(), 1'000'000) {} |
| 23 |
| 24 | absl::optional<Frequency> FrequencyTracker::Rate(Timestamp now) const { |
| 25 | if (absl::optional<int64_t> rate = impl_.Rate(now.ms())) { |
| 26 | return Frequency::MilliHertz(*rate); |
| 27 | } |
| 28 | return absl::nullopt; |
| 29 | } |
| 30 |
| 31 | void FrequencyTracker::Update(int64_t count, Timestamp now) { |
| 32 | impl_.Update(count, now.ms()); |
| 33 | } |
| 34 |
| 35 | } // namespace webrtc |
| 36 |