blob: 92d5a279eae11242b786b77c15fe425edfa29ba2 [file] [log] [blame]
Sebastian Janssonb34556e2018-03-21 14:38:32 +01001/*
2 * Copyright (c) 2018 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 "call/receive_time_calculator.h"
12
13#include "test/gtest.h"
14
15namespace webrtc {
16namespace test {
17namespace {
18
19int64_t ReconcileMs(ReceiveTimeCalculator* calc,
20 int64_t packet_time_ms,
21 int64_t safe_time_ms) {
22 return calc->ReconcileReceiveTimes(packet_time_ms * 1000,
23 safe_time_ms * 1000) /
24 1000;
25}
26} // namespace
27
28TEST(ReceiveTimeCalculatorTest, UsesSmallerIncrements) {
29 int64_t kMinDeltaMs = -20;
30 int64_t kMaxDeltaDiffMs = 100;
31 ReceiveTimeCalculator calc(kMinDeltaMs, kMaxDeltaDiffMs);
32 // Initialize offset.
33 ReconcileMs(&calc, 10000, 20000);
34
35 EXPECT_EQ(ReconcileMs(&calc, 10010, 20100), 20010);
36 EXPECT_EQ(ReconcileMs(&calc, 10020, 20100), 20020);
37 EXPECT_EQ(ReconcileMs(&calc, 10030, 20100), 20030);
38
39 EXPECT_EQ(ReconcileMs(&calc, 10110, 20200), 20110);
40 EXPECT_EQ(ReconcileMs(&calc, 10120, 20200), 20120);
41 EXPECT_EQ(ReconcileMs(&calc, 10130, 20200), 20130);
42
43 // Small jumps backwards are let trough, they might be due to reordering.
44 EXPECT_EQ(ReconcileMs(&calc, 10120, 20200), 20120);
45 // The safe clock might be smaller than the packet clock.
46 EXPECT_EQ(ReconcileMs(&calc, 10210, 20200), 20210);
47 EXPECT_EQ(ReconcileMs(&calc, 10240, 20200), 20240);
48}
49
50TEST(ReceiveTimeCalculatorTest, CorrectsJumps) {
51 int64_t kMinDeltaMs = -20;
52 int64_t kMaxDeltaDiffMs = 100;
53 ReceiveTimeCalculator calc(kMinDeltaMs, kMaxDeltaDiffMs);
54 // Initialize offset.
55 ReconcileMs(&calc, 10000, 20000);
56
57 EXPECT_EQ(ReconcileMs(&calc, 10010, 20100), 20010);
58 EXPECT_EQ(ReconcileMs(&calc, 10020, 20100), 20020);
59 EXPECT_EQ(ReconcileMs(&calc, 10030, 20100), 20030);
60
61 // Jump forward in time.
62 EXPECT_EQ(ReconcileMs(&calc, 10240, 20200), 20200);
63 EXPECT_EQ(ReconcileMs(&calc, 10250, 20200), 20210);
64 EXPECT_EQ(ReconcileMs(&calc, 10260, 20200), 20220);
65
66 // Jump backward in time.
67 EXPECT_EQ(ReconcileMs(&calc, 10230, 20300), 20300);
68 EXPECT_EQ(ReconcileMs(&calc, 10240, 20300), 20310);
69 EXPECT_EQ(ReconcileMs(&calc, 10250, 20300), 20320);
70}
71
72} // namespace test
73
74} // namespace webrtc