| 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/bitrate_tracker.h" |
| 12 |
| 13 | #include "absl/types/optional.h" |
| 14 | #include "api/units/data_rate.h" |
| 15 | #include "api/units/timestamp.h" |
| 16 | #include "rtc_base/rate_statistics.h" |
| 17 |
| 18 | namespace webrtc { |
| 19 |
| 20 | BitrateTracker::BitrateTracker(TimeDelta max_window_size) |
| 21 | : impl_(max_window_size.ms(), RateStatistics::kBpsScale) {} |
| 22 |
| 23 | absl::optional<DataRate> BitrateTracker::Rate(Timestamp now) const { |
| 24 | if (absl::optional<int64_t> rate = impl_.Rate(now.ms())) { |
| 25 | return DataRate::BitsPerSec(*rate); |
| 26 | } |
| 27 | return absl::nullopt; |
| 28 | } |
| 29 |
| 30 | bool BitrateTracker::SetWindowSize(TimeDelta window_size, Timestamp now) { |
| 31 | return impl_.SetWindowSize(window_size.ms(), now.ms()); |
| 32 | } |
| 33 |
| 34 | void BitrateTracker::Update(int64_t bytes, Timestamp now) { |
| 35 | impl_.Update(bytes, now.ms()); |
| 36 | } |
| 37 |
| 38 | } // namespace webrtc |
| 39 |