| 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 | JitterBufferDelay::JitterBufferDelay() { |
| 26 | worker_thread_checker_.Detach(); |
| 27 | } |
| 28 |
| 29 | void JitterBufferDelay::Set(absl::optional<double> delay_seconds) { |
| 30 | RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 31 | cached_delay_seconds_ = delay_seconds; |
| 32 | } |
| 33 |
| 34 | int JitterBufferDelay::GetMs() const { |
| 35 | RTC_DCHECK_RUN_ON(&worker_thread_checker_); |
| 36 | return rtc::SafeClamp( |
| 37 | rtc::saturated_cast<int>(cached_delay_seconds_.value_or(kDefaultDelay) * |
| 38 | 1000), |
| 39 | 0, kMaximumDelayMs); |
| 40 | } |
| 41 |
| 42 | } // namespace webrtc |
| 43 |