blob: 801cef721568f5a8a1123d2b50171fc28d836eff [file] [log] [blame]
Ruslan Burakov428dcb22019-04-18 17:49:49 +02001/*
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 14:31:24 +010013#include "api/sequence_checker.h"
Ruslan Burakov428dcb22019-04-18 17:49:49 +020014#include "rtc_base/checks.h"
Ruslan Burakov428dcb22019-04-18 17:49:49 +020015#include "rtc_base/numerics/safe_conversions.h"
16#include "rtc_base/numerics/safe_minmax.h"
Ruslan Burakov428dcb22019-04-18 17:49:49 +020017
18namespace {
19constexpr int kDefaultDelay = 0;
20constexpr int kMaximumDelayMs = 10000;
21} // namespace
22
23namespace webrtc {
24
Tommi4ccdf932021-05-17 14:50:10 +020025JitterBufferDelay::JitterBufferDelay() {
26 worker_thread_checker_.Detach();
Ruslan Burakov428dcb22019-04-18 17:49:49 +020027}
28
29void JitterBufferDelay::Set(absl::optional<double> delay_seconds) {
Tommi4ccdf932021-05-17 14:50:10 +020030 RTC_DCHECK_RUN_ON(&worker_thread_checker_);
Ruslan Burakov428dcb22019-04-18 17:49:49 +020031 cached_delay_seconds_ = delay_seconds;
Tommi4ccdf932021-05-17 14:50:10 +020032}
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 17:49:49 +020040}
41
42} // namespace webrtc