blob: f22b0650f9a9873da92d5170ea7fd1c50fb33dfb [file] [log] [blame]
Ruslan Burakov428dcb22019-04-18 15:49:491/*
2 * Copyright 2019 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
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
Artem Titovd15a5752021-02-10 13:31:2413#include "api/sequence_checker.h"
Ruslan Burakov428dcb22019-04-18 15:49:4914#include "rtc_base/checks.h"
Ruslan Burakov428dcb22019-04-18 15:49:4915#include "rtc_base/numerics/safe_conversions.h"
16#include "rtc_base/numerics/safe_minmax.h"
Ruslan Burakov428dcb22019-04-18 15:49:4917
18namespace {
19constexpr int kDefaultDelay = 0;
20constexpr int kMaximumDelayMs = 10000;
21} // namespace
22
23namespace webrtc {
24
Ruslan Burakov428dcb22019-04-18 15:49:4925void JitterBufferDelay::Set(absl::optional<double> delay_seconds) {
Tommi4ccdf9322021-05-17 12:50:1026 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Ruslan Burakov428dcb22019-04-18 15:49:4927 cached_delay_seconds_ = delay_seconds;
Tommi4ccdf9322021-05-17 12:50:1028}
29
30int 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);
Ruslan Burakov428dcb22019-04-18 15:49:4936}
37
38} // namespace webrtc