| 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 "pc/jitter_buffer_delay.h" |
| 12 |
| 13 | #include "api/sequence_checker.h" |
| 14 | #include "rtc_base/checks.h" |
| 15 | #include "rtc_base/numerics/safe_conversions.h" |
| 16 | #include "rtc_base/numerics/safe_minmax.h" |
| 17 |
| 18 | namespace { |
| 19 | constexpr int kDefaultDelay = 0; |
| 20 | constexpr int kMaximumDelayMs = 10000; |
| 21 | } // namespace |
| 22 |
| 23 | namespace webrtc { |
| 24 |
| 25 | void JitterBufferDelay::Set(absl::optional<double> delay_seconds) { |
| 26 | RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 27 | cached_delay_seconds_ = delay_seconds; |
| 28 | } |
| 29 |
| 30 | int JitterBufferDelay::GetMs() const { |
| 31 | RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 32 | return rtc::SafeClamp( |
| 33 | rtc::saturated_cast<int>(cached_delay_seconds_.value_or(kDefaultDelay) * |
| 34 | 1000), |
| 35 | 0, kMaximumDelayMs); |
| 36 | } |
| 37 |
| 38 | } // namespace webrtc |
| 39 |