blob: 801cef721568f5a8a1123d2b50171fc28d836eff [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
Tommi4ccdf9322021-05-17 12:50:1025JitterBufferDelay::JitterBufferDelay() {
26 worker_thread_checker_.Detach();
Ruslan Burakov428dcb22019-04-18 15:49:4927}
28
29void JitterBufferDelay::Set(absl::optional<double> delay_seconds) {
Tommi4ccdf9322021-05-17 12:50:1030 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Ruslan Burakov428dcb22019-04-18 15:49:4931 cached_delay_seconds_ = delay_seconds;
Tommi4ccdf9322021-05-17 12:50:1032}
33
34int 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);
Ruslan Burakov428dcb22019-04-18 15:49:4940}
41
42} // namespace webrtc