blob: 581963e96d74ed05796ea2b74dad96ea81e178d5 [file] [log] [blame]
pbos@webrtc.org9f79fe62014-12-04 15:34:061/*
2 * Copyright (c) 2013 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
Jonas Olssona4d87372019-07-05 17:08:3311#include "modules/remote_bitrate_estimator/inter_arrival.h"
12
kwiberg92931b12016-03-01 13:32:2913#include <memory>
14
Mirko Bonadei92ea95e2017-09-15 04:47:3115#include "test/gtest.h"
pbos@webrtc.org9f79fe62014-12-04 15:34:0616
17namespace webrtc {
18namespace testing {
19
20enum {
21 kTimestampGroupLengthUs = 5000,
22 kMinStep = 20,
23 kTriggerNewGroupUs = kTimestampGroupLengthUs + kMinStep,
24 kBurstThresholdMs = 5,
25 kAbsSendTimeFraction = 18,
26 kAbsSendTimeInterArrivalUpshift = 8,
27 kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift,
28};
29
30const double kRtpTimestampToMs = 1.0 / 90.0;
31const double kAstToMs = 1000.0 / static_cast<double>(1 << kInterArrivalShift);
32
33class InterArrivalTest : public ::testing::Test {
34 protected:
35 virtual void SetUp() {
Danil Chapovalovbbc926d2023-03-21 19:46:3936 inter_arrival_.reset(new InterArrival(kTimestampGroupLengthUs / 1000, 1.0));
pbos@webrtc.org9f79fe62014-12-04 15:34:0637 inter_arrival_rtp_.reset(new InterArrival(
Danil Chapovalovbbc926d2023-03-21 19:46:3938 MakeRtpTimestamp(kTimestampGroupLengthUs), kRtpTimestampToMs));
39 inter_arrival_ast_.reset(
40 new InterArrival(MakeAbsSendTime(kTimestampGroupLengthUs), kAstToMs));
pbos@webrtc.org9f79fe62014-12-04 15:34:0641 }
42
43 // Test that neither inter_arrival instance complete the timestamp group from
44 // the given data.
Yves Gerey665174f2018-06-19 13:03:0545 void ExpectFalse(int64_t timestamp_us,
46 int64_t arrival_time_ms,
stefan64c0a0a2015-11-27 09:02:3147 size_t packet_size) {
pbos@webrtc.org9f79fe62014-12-04 15:34:0648 InternalExpectFalse(inter_arrival_rtp_.get(),
stefan64c0a0a2015-11-27 09:02:3149 MakeRtpTimestamp(timestamp_us), arrival_time_ms,
50 packet_size);
pbos@webrtc.org9f79fe62014-12-04 15:34:0651 InternalExpectFalse(inter_arrival_ast_.get(), MakeAbsSendTime(timestamp_us),
stefan64c0a0a2015-11-27 09:02:3152 arrival_time_ms, packet_size);
pbos@webrtc.org9f79fe62014-12-04 15:34:0653 }
54
55 // Test that both inter_arrival instances complete the timestamp group from
56 // the given data and that all returned deltas are as expected (except
57 // timestamp delta, which is rounded from us to different ranges and must
58 // match within an interval, given in |timestamp_near].
Yves Gerey665174f2018-06-19 13:03:0559 void ExpectTrue(int64_t timestamp_us,
60 int64_t arrival_time_ms,
61 size_t packet_size,
62 int64_t expected_timestamp_delta_us,
pbos@webrtc.org9f79fe62014-12-04 15:34:0663 int64_t expected_arrival_time_delta_ms,
stefan64c0a0a2015-11-27 09:02:3164 int expected_packet_size_delta,
pbos@webrtc.org9f79fe62014-12-04 15:34:0665 uint32_t timestamp_near) {
66 InternalExpectTrue(inter_arrival_rtp_.get(), MakeRtpTimestamp(timestamp_us),
stefan64c0a0a2015-11-27 09:02:3167 arrival_time_ms, packet_size,
pbos@webrtc.org9f79fe62014-12-04 15:34:0668 MakeRtpTimestamp(expected_timestamp_delta_us),
stefan64c0a0a2015-11-27 09:02:3169 expected_arrival_time_delta_ms,
70 expected_packet_size_delta, timestamp_near);
pbos@webrtc.org9f79fe62014-12-04 15:34:0671 InternalExpectTrue(inter_arrival_ast_.get(), MakeAbsSendTime(timestamp_us),
stefan64c0a0a2015-11-27 09:02:3172 arrival_time_ms, packet_size,
pbos@webrtc.org9f79fe62014-12-04 15:34:0673 MakeAbsSendTime(expected_timestamp_delta_us),
stefan64c0a0a2015-11-27 09:02:3174 expected_arrival_time_delta_ms,
75 expected_packet_size_delta, timestamp_near << 8);
pbos@webrtc.org9f79fe62014-12-04 15:34:0676 }
77
Yves Gerey665174f2018-06-19 13:03:0578 void WrapTestHelper(int64_t wrap_start_us,
79 uint32_t timestamp_near,
pbos@webrtc.org9f79fe62014-12-04 15:34:0680 bool unorderly_within_group) {
81 // Step through the range of a 32 bit int, 1/4 at a time to not cause
82 // packets close to wraparound to be judged as out of order.
83
84 // G1
85 int64_t arrival_time = 17;
stefan64c0a0a2015-11-27 09:02:3186 ExpectFalse(0, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:0687
88 // G2
89 arrival_time += kBurstThresholdMs + 1;
stefan64c0a0a2015-11-27 09:02:3190 ExpectFalse(wrap_start_us / 4, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:0691
92 // G3
93 arrival_time += kBurstThresholdMs + 1;
Yves Gerey665174f2018-06-19 13:03:0594 ExpectTrue(wrap_start_us / 2, arrival_time, 1, wrap_start_us / 4, 6,
95 0, // Delta G2-G1
pbos@webrtc.org9f79fe62014-12-04 15:34:0696 0);
97
98 // G4
99 arrival_time += kBurstThresholdMs + 1;
100 int64_t g4_arrival_time = arrival_time;
stefan64c0a0a2015-11-27 09:02:31101 ExpectTrue(wrap_start_us / 2 + wrap_start_us / 4, arrival_time, 1,
Yves Gerey665174f2018-06-19 13:03:05102 wrap_start_us / 4, 6, 0, // Delta G3-G2
pbos@webrtc.org9f79fe62014-12-04 15:34:06103 timestamp_near);
104
105 // G5
106 arrival_time += kBurstThresholdMs + 1;
Yves Gerey665174f2018-06-19 13:03:05107 ExpectTrue(wrap_start_us, arrival_time, 2, wrap_start_us / 4, 6,
108 0, // Delta G4-G3
pbos@webrtc.org9f79fe62014-12-04 15:34:06109 timestamp_near);
110 for (int i = 0; i < 10; ++i) {
111 // Slowly step across the wrap point.
112 arrival_time += kBurstThresholdMs + 1;
113 if (unorderly_within_group) {
114 // These packets arrive with timestamps in decreasing order but are
115 // nevertheless accumulated to group because their timestamps are higher
116 // than the initial timestamp of the group.
stefan64c0a0a2015-11-27 09:02:31117 ExpectFalse(wrap_start_us + kMinStep * (9 - i), arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06118 } else {
stefan64c0a0a2015-11-27 09:02:31119 ExpectFalse(wrap_start_us + kMinStep * i, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06120 }
121 }
122 int64_t g5_arrival_time = arrival_time;
123
124 // This packet is out of order and should be dropped.
125 arrival_time += kBurstThresholdMs + 1;
stefan64c0a0a2015-11-27 09:02:31126 ExpectFalse(wrap_start_us - 100, arrival_time, 100);
pbos@webrtc.org9f79fe62014-12-04 15:34:06127
128 // G6
129 arrival_time += kBurstThresholdMs + 1;
130 int64_t g6_arrival_time = arrival_time;
stefan64c0a0a2015-11-27 09:02:31131 ExpectTrue(wrap_start_us + kTriggerNewGroupUs, arrival_time, 10,
pbos@webrtc.org9f79fe62014-12-04 15:34:06132 wrap_start_us / 4 + 9 * kMinStep,
stefan64c0a0a2015-11-27 09:02:31133 g5_arrival_time - g4_arrival_time,
134 (2 + 10) - 1, // Delta G5-G4
135 timestamp_near);
pbos@webrtc.org9f79fe62014-12-04 15:34:06136
137 // This packet is out of order and should be dropped.
138 arrival_time += kBurstThresholdMs + 1;
stefan64c0a0a2015-11-27 09:02:31139 ExpectFalse(wrap_start_us + kTimestampGroupLengthUs, arrival_time, 100);
pbos@webrtc.org9f79fe62014-12-04 15:34:06140
141 // G7
142 arrival_time += kBurstThresholdMs + 1;
Yves Gerey665174f2018-06-19 13:03:05143 ExpectTrue(wrap_start_us + 2 * kTriggerNewGroupUs, arrival_time, 100,
pbos@webrtc.org9f79fe62014-12-04 15:34:06144 // Delta G6-G5
145 kTriggerNewGroupUs - 9 * kMinStep,
Yves Gerey665174f2018-06-19 13:03:05146 g6_arrival_time - g5_arrival_time, 10 - (2 + 10),
stefan64c0a0a2015-11-27 09:02:31147 timestamp_near);
pbos@webrtc.org9f79fe62014-12-04 15:34:06148 }
149
stefan5e12d362016-07-11 08:44:02150 std::unique_ptr<InterArrival> inter_arrival_;
151
pbos@webrtc.org9f79fe62014-12-04 15:34:06152 private:
153 static uint32_t MakeRtpTimestamp(int64_t us) {
154 return static_cast<uint32_t>(static_cast<uint64_t>(us * 90 + 500) / 1000);
155 }
156
157 static uint32_t MakeAbsSendTime(int64_t us) {
Yves Gerey665174f2018-06-19 13:03:05158 uint32_t absolute_send_time =
159 static_cast<uint32_t>(((static_cast<uint64_t>(us) << 18) + 500000) /
160 1000000) &
161 0x00FFFFFFul;
pbos@webrtc.org9f79fe62014-12-04 15:34:06162 return absolute_send_time << 8;
163 }
164
165 static void InternalExpectFalse(InterArrival* inter_arrival,
Yves Gerey665174f2018-06-19 13:03:05166 uint32_t timestamp,
167 int64_t arrival_time_ms,
stefan64c0a0a2015-11-27 09:02:31168 size_t packet_size) {
pbos@webrtc.org9f79fe62014-12-04 15:34:06169 uint32_t dummy_timestamp = 101;
170 int64_t dummy_arrival_time_ms = 303;
stefan64c0a0a2015-11-27 09:02:31171 int dummy_packet_size = 909;
stefan5e12d362016-07-11 08:44:02172 bool computed = inter_arrival->ComputeDeltas(
173 timestamp, arrival_time_ms, arrival_time_ms, packet_size,
174 &dummy_timestamp, &dummy_arrival_time_ms, &dummy_packet_size);
pbos@webrtc.org9f79fe62014-12-04 15:34:06175 EXPECT_EQ(computed, false);
176 EXPECT_EQ(101ul, dummy_timestamp);
177 EXPECT_EQ(303, dummy_arrival_time_ms);
stefan64c0a0a2015-11-27 09:02:31178 EXPECT_EQ(909, dummy_packet_size);
pbos@webrtc.org9f79fe62014-12-04 15:34:06179 }
180
181 static void InternalExpectTrue(InterArrival* inter_arrival,
Yves Gerey665174f2018-06-19 13:03:05182 uint32_t timestamp,
183 int64_t arrival_time_ms,
stefan64c0a0a2015-11-27 09:02:31184 size_t packet_size,
pbos@webrtc.org9f79fe62014-12-04 15:34:06185 uint32_t expected_timestamp_delta,
186 int64_t expected_arrival_time_delta_ms,
stefan64c0a0a2015-11-27 09:02:31187 int expected_packet_size_delta,
pbos@webrtc.org9f79fe62014-12-04 15:34:06188 uint32_t timestamp_near) {
189 uint32_t delta_timestamp = 101;
190 int64_t delta_arrival_time_ms = 303;
stefan64c0a0a2015-11-27 09:02:31191 int delta_packet_size = 909;
stefan5e12d362016-07-11 08:44:02192 bool computed = inter_arrival->ComputeDeltas(
193 timestamp, arrival_time_ms, arrival_time_ms, packet_size,
194 &delta_timestamp, &delta_arrival_time_ms, &delta_packet_size);
pbos@webrtc.org9f79fe62014-12-04 15:34:06195 EXPECT_EQ(true, computed);
196 EXPECT_NEAR(expected_timestamp_delta, delta_timestamp, timestamp_near);
197 EXPECT_EQ(expected_arrival_time_delta_ms, delta_arrival_time_ms);
stefan64c0a0a2015-11-27 09:02:31198 EXPECT_EQ(expected_packet_size_delta, delta_packet_size);
pbos@webrtc.org9f79fe62014-12-04 15:34:06199 }
200
kwiberg92931b12016-03-01 13:32:29201 std::unique_ptr<InterArrival> inter_arrival_rtp_;
202 std::unique_ptr<InterArrival> inter_arrival_ast_;
pbos@webrtc.org9f79fe62014-12-04 15:34:06203};
204
205TEST_F(InterArrivalTest, FirstPacket) {
stefan64c0a0a2015-11-27 09:02:31206 ExpectFalse(0, 17, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06207}
208
209TEST_F(InterArrivalTest, FirstGroup) {
210 // G1
211 int64_t arrival_time = 17;
212 int64_t g1_arrival_time = arrival_time;
stefan64c0a0a2015-11-27 09:02:31213 ExpectFalse(0, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06214
215 // G2
216 arrival_time += kBurstThresholdMs + 1;
217 int64_t g2_arrival_time = arrival_time;
stefan64c0a0a2015-11-27 09:02:31218 ExpectFalse(kTriggerNewGroupUs, arrival_time, 2);
pbos@webrtc.org9f79fe62014-12-04 15:34:06219
220 // G3
221 // Only once the first packet of the third group arrives, do we see the deltas
222 // between the first two.
223 arrival_time += kBurstThresholdMs + 1;
stefan64c0a0a2015-11-27 09:02:31224 ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1,
pbos@webrtc.org9f79fe62014-12-04 15:34:06225 // Delta G2-G1
Yves Gerey665174f2018-06-19 13:03:05226 kTriggerNewGroupUs, g2_arrival_time - g1_arrival_time, 1, 0);
pbos@webrtc.org9f79fe62014-12-04 15:34:06227}
228
229TEST_F(InterArrivalTest, SecondGroup) {
230 // G1
231 int64_t arrival_time = 17;
232 int64_t g1_arrival_time = arrival_time;
stefan64c0a0a2015-11-27 09:02:31233 ExpectFalse(0, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06234
235 // G2
236 arrival_time += kBurstThresholdMs + 1;
237 int64_t g2_arrival_time = arrival_time;
stefan64c0a0a2015-11-27 09:02:31238 ExpectFalse(kTriggerNewGroupUs, arrival_time, 2);
pbos@webrtc.org9f79fe62014-12-04 15:34:06239
240 // G3
241 arrival_time += kBurstThresholdMs + 1;
242 int64_t g3_arrival_time = arrival_time;
stefan64c0a0a2015-11-27 09:02:31243 ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1,
pbos@webrtc.org9f79fe62014-12-04 15:34:06244 // Delta G2-G1
Yves Gerey665174f2018-06-19 13:03:05245 kTriggerNewGroupUs, g2_arrival_time - g1_arrival_time, 1, 0);
pbos@webrtc.org9f79fe62014-12-04 15:34:06246
247 // G4
248 // First packet of 4th group yields deltas between group 2 and 3.
249 arrival_time += kBurstThresholdMs + 1;
stefan64c0a0a2015-11-27 09:02:31250 ExpectTrue(3 * kTriggerNewGroupUs, arrival_time, 2,
pbos@webrtc.org9f79fe62014-12-04 15:34:06251 // Delta G3-G2
Yves Gerey665174f2018-06-19 13:03:05252 kTriggerNewGroupUs, g3_arrival_time - g2_arrival_time, -1, 0);
pbos@webrtc.org9f79fe62014-12-04 15:34:06253}
254
255TEST_F(InterArrivalTest, AccumulatedGroup) {
256 // G1
257 int64_t arrival_time = 17;
258 int64_t g1_arrival_time = arrival_time;
stefan64c0a0a2015-11-27 09:02:31259 ExpectFalse(0, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06260
261 // G2
262 arrival_time += kBurstThresholdMs + 1;
stefan64c0a0a2015-11-27 09:02:31263 ExpectFalse(kTriggerNewGroupUs, 28, 2);
pbos@webrtc.org9f79fe62014-12-04 15:34:06264 int64_t timestamp = kTriggerNewGroupUs;
265 for (int i = 0; i < 10; ++i) {
266 // A bunch of packets arriving within the same group.
267 arrival_time += kBurstThresholdMs + 1;
268 timestamp += kMinStep;
stefan64c0a0a2015-11-27 09:02:31269 ExpectFalse(timestamp, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06270 }
271 int64_t g2_arrival_time = arrival_time;
272 int64_t g2_timestamp = timestamp;
273
274 // G3
275 arrival_time = 500;
Yves Gerey665174f2018-06-19 13:03:05276 ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 100, g2_timestamp,
277 g2_arrival_time - g1_arrival_time,
278 (2 + 10) - 1, // Delta G2-G1
stefan64c0a0a2015-11-27 09:02:31279 0);
pbos@webrtc.org9f79fe62014-12-04 15:34:06280}
281
282TEST_F(InterArrivalTest, OutOfOrderPacket) {
283 // G1
284 int64_t arrival_time = 17;
285 int64_t timestamp = 0;
stefan64c0a0a2015-11-27 09:02:31286 ExpectFalse(timestamp, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06287 int64_t g1_timestamp = timestamp;
288 int64_t g1_arrival_time = arrival_time;
289
290 // G2
291 arrival_time += 11;
292 timestamp += kTriggerNewGroupUs;
stefan64c0a0a2015-11-27 09:02:31293 ExpectFalse(timestamp, 28, 2);
pbos@webrtc.org9f79fe62014-12-04 15:34:06294 for (int i = 0; i < 10; ++i) {
295 arrival_time += kBurstThresholdMs + 1;
296 timestamp += kMinStep;
stefan64c0a0a2015-11-27 09:02:31297 ExpectFalse(timestamp, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06298 }
299 int64_t g2_timestamp = timestamp;
300 int64_t g2_arrival_time = arrival_time;
301
302 // This packet is out of order and should be dropped.
303 arrival_time = 281;
stefan64c0a0a2015-11-27 09:02:31304 ExpectFalse(g1_timestamp, arrival_time, 100);
pbos@webrtc.org9f79fe62014-12-04 15:34:06305
306 // G3
307 arrival_time = 500;
308 timestamp = 2 * kTriggerNewGroupUs;
stefan64c0a0a2015-11-27 09:02:31309 ExpectTrue(timestamp, arrival_time, 100,
pbos@webrtc.org9f79fe62014-12-04 15:34:06310 // Delta G2-G1
stefan64c0a0a2015-11-27 09:02:31311 g2_timestamp - g1_timestamp, g2_arrival_time - g1_arrival_time,
Yves Gerey665174f2018-06-19 13:03:05312 (2 + 10) - 1, 0);
pbos@webrtc.org9f79fe62014-12-04 15:34:06313}
314
315TEST_F(InterArrivalTest, OutOfOrderWithinGroup) {
316 // G1
317 int64_t arrival_time = 17;
318 int64_t timestamp = 0;
stefan64c0a0a2015-11-27 09:02:31319 ExpectFalse(timestamp, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06320 int64_t g1_timestamp = timestamp;
321 int64_t g1_arrival_time = arrival_time;
322
323 // G2
324 timestamp += kTriggerNewGroupUs;
325 arrival_time += 11;
stefan64c0a0a2015-11-27 09:02:31326 ExpectFalse(kTriggerNewGroupUs, 28, 2);
pbos@webrtc.org9f79fe62014-12-04 15:34:06327 timestamp += 10 * kMinStep;
328 int64_t g2_timestamp = timestamp;
329 for (int i = 0; i < 10; ++i) {
330 // These packets arrive with timestamps in decreasing order but are
331 // nevertheless accumulated to group because their timestamps are higher
332 // than the initial timestamp of the group.
333 arrival_time += kBurstThresholdMs + 1;
stefan64c0a0a2015-11-27 09:02:31334 ExpectFalse(timestamp, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06335 timestamp -= kMinStep;
336 }
337 int64_t g2_arrival_time = arrival_time;
338
339 // However, this packet is deemed out of order and should be dropped.
340 arrival_time = 281;
341 timestamp = g1_timestamp;
stefan64c0a0a2015-11-27 09:02:31342 ExpectFalse(timestamp, arrival_time, 100);
pbos@webrtc.org9f79fe62014-12-04 15:34:06343
344 // G3
345 timestamp = 2 * kTriggerNewGroupUs;
346 arrival_time = 500;
Yves Gerey665174f2018-06-19 13:03:05347 ExpectTrue(timestamp, arrival_time, 100, g2_timestamp - g1_timestamp,
348 g2_arrival_time - g1_arrival_time, (2 + 10) - 1, 0);
pbos@webrtc.org9f79fe62014-12-04 15:34:06349}
350
351TEST_F(InterArrivalTest, TwoBursts) {
352 // G1
353 int64_t g1_arrival_time = 17;
stefan64c0a0a2015-11-27 09:02:31354 ExpectFalse(0, g1_arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06355
356 // G2
357 int64_t timestamp = kTriggerNewGroupUs;
358 int64_t arrival_time = 100; // Simulate no packets arriving for 100 ms.
359 for (int i = 0; i < 10; ++i) {
360 // A bunch of packets arriving in one burst (within 5 ms apart).
361 timestamp += 30000;
362 arrival_time += kBurstThresholdMs;
stefan64c0a0a2015-11-27 09:02:31363 ExpectFalse(timestamp, arrival_time, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06364 }
365 int64_t g2_arrival_time = arrival_time;
366 int64_t g2_timestamp = timestamp;
367
368 // G3
369 timestamp += 30000;
370 arrival_time += kBurstThresholdMs + 1;
Yves Gerey665174f2018-06-19 13:03:05371 ExpectTrue(timestamp, arrival_time, 100, g2_timestamp,
372 g2_arrival_time - g1_arrival_time,
stefan64c0a0a2015-11-27 09:02:31373 10 - 1, // Delta G2-G1
374 0);
pbos@webrtc.org9f79fe62014-12-04 15:34:06375}
376
pbos@webrtc.org9f79fe62014-12-04 15:34:06377TEST_F(InterArrivalTest, NoBursts) {
378 // G1
stefan64c0a0a2015-11-27 09:02:31379 ExpectFalse(0, 17, 1);
pbos@webrtc.org9f79fe62014-12-04 15:34:06380
381 // G2
382 int64_t timestamp = kTriggerNewGroupUs;
383 int64_t arrival_time = 28;
stefan64c0a0a2015-11-27 09:02:31384 ExpectFalse(timestamp, arrival_time, 2);
pbos@webrtc.org9f79fe62014-12-04 15:34:06385
386 // G3
387 ExpectTrue(kTriggerNewGroupUs + 30000, arrival_time + kBurstThresholdMs + 1,
stefan64c0a0a2015-11-27 09:02:31388 100, timestamp - 0, arrival_time - 17,
389 2 - 1, // Delta G2-G1
390 0);
pbos@webrtc.org9f79fe62014-12-04 15:34:06391}
392
393// Yields 0xfffffffe when converted to internal representation in
394// inter_arrival_rtp_ and inter_arrival_ast_ respectively.
395static const int64_t kStartRtpTimestampWrapUs = 47721858827;
396static const int64_t kStartAbsSendTimeWrapUs = 63999995;
397
398TEST_F(InterArrivalTest, RtpTimestampWrap) {
399 WrapTestHelper(kStartRtpTimestampWrapUs, 1, false);
400}
401
402TEST_F(InterArrivalTest, AbsSendTimeWrap) {
403 WrapTestHelper(kStartAbsSendTimeWrapUs, 1, false);
404}
405
406TEST_F(InterArrivalTest, RtpTimestampWrapOutOfOrderWithinGroup) {
407 WrapTestHelper(kStartRtpTimestampWrapUs, 1, true);
408}
409
410TEST_F(InterArrivalTest, AbsSendTimeWrapOutOfOrderWithinGroup) {
411 WrapTestHelper(kStartAbsSendTimeWrapUs, 1, true);
412}
stefan5e12d362016-07-11 08:44:02413
414TEST_F(InterArrivalTest, PositiveArrivalTimeJump) {
415 const size_t kPacketSize = 1000;
416 uint32_t send_time_ms = 10000;
417 int64_t arrival_time_ms = 20000;
418 int64_t system_time_ms = 30000;
419
420 uint32_t send_delta;
421 int64_t arrival_delta;
422 int size_delta;
423 EXPECT_FALSE(inter_arrival_->ComputeDeltas(
424 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
425 &arrival_delta, &size_delta));
426
427 const int kTimeDeltaMs = 30;
428 send_time_ms += kTimeDeltaMs;
429 arrival_time_ms += kTimeDeltaMs;
430 system_time_ms += kTimeDeltaMs;
431 EXPECT_FALSE(inter_arrival_->ComputeDeltas(
432 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
433 &arrival_delta, &size_delta));
434
435 send_time_ms += kTimeDeltaMs;
436 arrival_time_ms += kTimeDeltaMs + InterArrival::kArrivalTimeOffsetThresholdMs;
437 system_time_ms += kTimeDeltaMs;
438 EXPECT_TRUE(inter_arrival_->ComputeDeltas(
439 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
440 &arrival_delta, &size_delta));
441 EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
442 EXPECT_EQ(kTimeDeltaMs, arrival_delta);
443 EXPECT_EQ(size_delta, 0);
444
445 send_time_ms += kTimeDeltaMs;
446 arrival_time_ms += kTimeDeltaMs;
447 system_time_ms += kTimeDeltaMs;
448 // The previous arrival time jump should now be detected and cause a reset.
449 EXPECT_FALSE(inter_arrival_->ComputeDeltas(
450 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
451 &arrival_delta, &size_delta));
452
453 // The two next packets will not give a valid delta since we're in the initial
454 // state.
455 for (int i = 0; i < 2; ++i) {
456 send_time_ms += kTimeDeltaMs;
457 arrival_time_ms += kTimeDeltaMs;
458 system_time_ms += kTimeDeltaMs;
459 EXPECT_FALSE(inter_arrival_->ComputeDeltas(
460 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
461 &arrival_delta, &size_delta));
462 }
463
464 send_time_ms += kTimeDeltaMs;
465 arrival_time_ms += kTimeDeltaMs;
466 system_time_ms += kTimeDeltaMs;
467 EXPECT_TRUE(inter_arrival_->ComputeDeltas(
468 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
469 &arrival_delta, &size_delta));
470 EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
471 EXPECT_EQ(kTimeDeltaMs, arrival_delta);
472 EXPECT_EQ(size_delta, 0);
473}
474
475TEST_F(InterArrivalTest, NegativeArrivalTimeJump) {
476 const size_t kPacketSize = 1000;
477 uint32_t send_time_ms = 10000;
478 int64_t arrival_time_ms = 20000;
479 int64_t system_time_ms = 30000;
480
481 uint32_t send_delta;
482 int64_t arrival_delta;
483 int size_delta;
484 EXPECT_FALSE(inter_arrival_->ComputeDeltas(
485 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
486 &arrival_delta, &size_delta));
487
488 const int kTimeDeltaMs = 30;
489 send_time_ms += kTimeDeltaMs;
490 arrival_time_ms += kTimeDeltaMs;
491 system_time_ms += kTimeDeltaMs;
492 EXPECT_FALSE(inter_arrival_->ComputeDeltas(
493 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
494 &arrival_delta, &size_delta));
495
496 send_time_ms += kTimeDeltaMs;
497 arrival_time_ms += kTimeDeltaMs;
498 system_time_ms += kTimeDeltaMs;
499 EXPECT_TRUE(inter_arrival_->ComputeDeltas(
500 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
501 &arrival_delta, &size_delta));
502 EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
503 EXPECT_EQ(kTimeDeltaMs, arrival_delta);
504 EXPECT_EQ(size_delta, 0);
505
506 // Three out of order will fail, after that we will be reset and two more will
507 // fail before we get our first valid delta after the reset.
508 arrival_time_ms -= 1000;
509 for (int i = 0; i < InterArrival::kReorderedResetThreshold + 3; ++i) {
510 send_time_ms += kTimeDeltaMs;
511 arrival_time_ms += kTimeDeltaMs;
512 system_time_ms += kTimeDeltaMs;
513 // The previous arrival time jump should now be detected and cause a reset.
514 EXPECT_FALSE(inter_arrival_->ComputeDeltas(
515 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
516 &arrival_delta, &size_delta));
517 }
518
519 send_time_ms += kTimeDeltaMs;
520 arrival_time_ms += kTimeDeltaMs;
521 system_time_ms += kTimeDeltaMs;
522 EXPECT_TRUE(inter_arrival_->ComputeDeltas(
523 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
524 &arrival_delta, &size_delta));
525 EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
526 EXPECT_EQ(kTimeDeltaMs, arrival_delta);
527 EXPECT_EQ(size_delta, 0);
528}
pbos@webrtc.org9f79fe62014-12-04 15:34:06529} // namespace testing
530} // namespace webrtc