blob: 383a4b7382f759407311d02386bd89c602b38f38 [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 <stdint.h>
12
13#include "absl/types/optional.h"
14#include "api/scoped_refptr.h"
15#include "pc/jitter_buffer_delay.h"
16#include "pc/test/mock_delayable.h"
17#include "rtc_base/ref_counted_object.h"
18#include "rtc_base/thread.h"
19#include "test/gmock.h"
20#include "test/gtest.h"
21
22using ::testing::Return;
23
24namespace {
25constexpr int kSsrc = 1234;
26} // namespace
27
28namespace webrtc {
29
30class JitterBufferDelayTest : public ::testing::Test {
31 public:
32 JitterBufferDelayTest()
33 : delay_(new rtc::RefCountedObject<JitterBufferDelay>(
34 rtc::Thread::Current())) {}
35
36 protected:
37 rtc::scoped_refptr<JitterBufferDelayInterface> delay_;
38 MockDelayable delayable_;
39};
40
41TEST_F(JitterBufferDelayTest, Set) {
42 delay_->OnStart(&delayable_, kSsrc);
43
44 EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 3000))
45 .WillOnce(Return(true));
46
47 // Delay in seconds.
48 delay_->Set(3.0);
49}
50
51TEST_F(JitterBufferDelayTest, Caching) {
52 // Check that value is cached before start.
53 delay_->Set(4.0);
54
55 // Check that cached value applied on the start.
56 EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 4000))
57 .WillOnce(Return(true));
58 delay_->OnStart(&delayable_, kSsrc);
59}
60
61TEST_F(JitterBufferDelayTest, Clamping) {
62 delay_->OnStart(&delayable_, kSsrc);
63
64 // In current Jitter Buffer implementation (Audio or Video) maximum supported
65 // value is 10000 milliseconds.
66 EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 10000))
67 .WillOnce(Return(true));
68 delay_->Set(10.5);
69
70 // Test int overflow.
71 EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 10000))
72 .WillOnce(Return(true));
73 delay_->Set(21474836470.0);
74
75 EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 0))
76 .WillOnce(Return(true));
77 delay_->Set(-21474836470.0);
78
79 // Boundary value in seconds to milliseconds conversion.
80 EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 0))
81 .WillOnce(Return(true));
82 delay_->Set(0.0009);
83
84 EXPECT_CALL(delayable_, SetBaseMinimumPlayoutDelayMs(kSsrc, 0))
85 .WillOnce(Return(true));
86
87 delay_->Set(-2.0);
88}
89
90} // namespace webrtc