1 /*
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 
11 #include "modules/remote_bitrate_estimator/inter_arrival.h"
12 
13 #include <memory>
14 
15 #include "test/gtest.h"
16 
17 namespace webrtc {
18 namespace testing {
19 
20 enum {
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 
30 const double kRtpTimestampToMs = 1.0 / 90.0;
31 const double kAstToMs = 1000.0 / static_cast<double>(1 << kInterArrivalShift);
32 
33 class InterArrivalTest : public ::testing::Test {
34  protected:
SetUp()35   virtual void SetUp() {
36     inter_arrival_.reset(
37         new InterArrival(kTimestampGroupLengthUs / 1000, 1.0, true));
38     inter_arrival_rtp_.reset(new InterArrival(
39         MakeRtpTimestamp(kTimestampGroupLengthUs), kRtpTimestampToMs, true));
40     inter_arrival_ast_.reset(new InterArrival(
41         MakeAbsSendTime(kTimestampGroupLengthUs), kAstToMs, true));
42   }
43 
44   // Test that neither inter_arrival instance complete the timestamp group from
45   // the given data.
ExpectFalse(int64_t timestamp_us,int64_t arrival_time_ms,size_t packet_size)46   void ExpectFalse(int64_t timestamp_us,
47                    int64_t arrival_time_ms,
48                    size_t packet_size) {
49     InternalExpectFalse(inter_arrival_rtp_.get(),
50                         MakeRtpTimestamp(timestamp_us), arrival_time_ms,
51                         packet_size);
52     InternalExpectFalse(inter_arrival_ast_.get(), MakeAbsSendTime(timestamp_us),
53                         arrival_time_ms, packet_size);
54   }
55 
56   // Test that both inter_arrival instances complete the timestamp group from
57   // the given data and that all returned deltas are as expected (except
58   // timestamp delta, which is rounded from us to different ranges and must
59   // match within an interval, given in |timestamp_near].
ExpectTrue(int64_t timestamp_us,int64_t arrival_time_ms,size_t packet_size,int64_t expected_timestamp_delta_us,int64_t expected_arrival_time_delta_ms,int expected_packet_size_delta,uint32_t timestamp_near)60   void ExpectTrue(int64_t timestamp_us,
61                   int64_t arrival_time_ms,
62                   size_t packet_size,
63                   int64_t expected_timestamp_delta_us,
64                   int64_t expected_arrival_time_delta_ms,
65                   int expected_packet_size_delta,
66                   uint32_t timestamp_near) {
67     InternalExpectTrue(inter_arrival_rtp_.get(), MakeRtpTimestamp(timestamp_us),
68                        arrival_time_ms, packet_size,
69                        MakeRtpTimestamp(expected_timestamp_delta_us),
70                        expected_arrival_time_delta_ms,
71                        expected_packet_size_delta, timestamp_near);
72     InternalExpectTrue(inter_arrival_ast_.get(), MakeAbsSendTime(timestamp_us),
73                        arrival_time_ms, packet_size,
74                        MakeAbsSendTime(expected_timestamp_delta_us),
75                        expected_arrival_time_delta_ms,
76                        expected_packet_size_delta, timestamp_near << 8);
77   }
78 
WrapTestHelper(int64_t wrap_start_us,uint32_t timestamp_near,bool unorderly_within_group)79   void WrapTestHelper(int64_t wrap_start_us,
80                       uint32_t timestamp_near,
81                       bool unorderly_within_group) {
82     // Step through the range of a 32 bit int, 1/4 at a time to not cause
83     // packets close to wraparound to be judged as out of order.
84 
85     // G1
86     int64_t arrival_time = 17;
87     ExpectFalse(0, arrival_time, 1);
88 
89     // G2
90     arrival_time += kBurstThresholdMs + 1;
91     ExpectFalse(wrap_start_us / 4, arrival_time, 1);
92 
93     // G3
94     arrival_time += kBurstThresholdMs + 1;
95     ExpectTrue(wrap_start_us / 2, arrival_time, 1, wrap_start_us / 4, 6,
96                0,  // Delta G2-G1
97                0);
98 
99     // G4
100     arrival_time += kBurstThresholdMs + 1;
101     int64_t g4_arrival_time = arrival_time;
102     ExpectTrue(wrap_start_us / 2 + wrap_start_us / 4, arrival_time, 1,
103                wrap_start_us / 4, 6, 0,  // Delta G3-G2
104                timestamp_near);
105 
106     // G5
107     arrival_time += kBurstThresholdMs + 1;
108     ExpectTrue(wrap_start_us, arrival_time, 2, wrap_start_us / 4, 6,
109                0,  // Delta G4-G3
110                timestamp_near);
111     for (int i = 0; i < 10; ++i) {
112       // Slowly step across the wrap point.
113       arrival_time += kBurstThresholdMs + 1;
114       if (unorderly_within_group) {
115         // These packets arrive with timestamps in decreasing order but are
116         // nevertheless accumulated to group because their timestamps are higher
117         // than the initial timestamp of the group.
118         ExpectFalse(wrap_start_us + kMinStep * (9 - i), arrival_time, 1);
119       } else {
120         ExpectFalse(wrap_start_us + kMinStep * i, arrival_time, 1);
121       }
122     }
123     int64_t g5_arrival_time = arrival_time;
124 
125     // This packet is out of order and should be dropped.
126     arrival_time += kBurstThresholdMs + 1;
127     ExpectFalse(wrap_start_us - 100, arrival_time, 100);
128 
129     // G6
130     arrival_time += kBurstThresholdMs + 1;
131     int64_t g6_arrival_time = arrival_time;
132     ExpectTrue(wrap_start_us + kTriggerNewGroupUs, arrival_time, 10,
133                wrap_start_us / 4 + 9 * kMinStep,
134                g5_arrival_time - g4_arrival_time,
135                (2 + 10) - 1,  // Delta G5-G4
136                timestamp_near);
137 
138     // This packet is out of order and should be dropped.
139     arrival_time += kBurstThresholdMs + 1;
140     ExpectFalse(wrap_start_us + kTimestampGroupLengthUs, arrival_time, 100);
141 
142     // G7
143     arrival_time += kBurstThresholdMs + 1;
144     ExpectTrue(wrap_start_us + 2 * kTriggerNewGroupUs, arrival_time, 100,
145                // Delta G6-G5
146                kTriggerNewGroupUs - 9 * kMinStep,
147                g6_arrival_time - g5_arrival_time, 10 - (2 + 10),
148                timestamp_near);
149   }
150 
151   std::unique_ptr<InterArrival> inter_arrival_;
152 
153  private:
MakeRtpTimestamp(int64_t us)154   static uint32_t MakeRtpTimestamp(int64_t us) {
155     return static_cast<uint32_t>(static_cast<uint64_t>(us * 90 + 500) / 1000);
156   }
157 
MakeAbsSendTime(int64_t us)158   static uint32_t MakeAbsSendTime(int64_t us) {
159     uint32_t absolute_send_time =
160         static_cast<uint32_t>(((static_cast<uint64_t>(us) << 18) + 500000) /
161                               1000000) &
162         0x00FFFFFFul;
163     return absolute_send_time << 8;
164   }
165 
InternalExpectFalse(InterArrival * inter_arrival,uint32_t timestamp,int64_t arrival_time_ms,size_t packet_size)166   static void InternalExpectFalse(InterArrival* inter_arrival,
167                                   uint32_t timestamp,
168                                   int64_t arrival_time_ms,
169                                   size_t packet_size) {
170     uint32_t dummy_timestamp = 101;
171     int64_t dummy_arrival_time_ms = 303;
172     int dummy_packet_size = 909;
173     bool computed = inter_arrival->ComputeDeltas(
174         timestamp, arrival_time_ms, arrival_time_ms, packet_size,
175         &dummy_timestamp, &dummy_arrival_time_ms, &dummy_packet_size);
176     EXPECT_EQ(computed, false);
177     EXPECT_EQ(101ul, dummy_timestamp);
178     EXPECT_EQ(303, dummy_arrival_time_ms);
179     EXPECT_EQ(909, dummy_packet_size);
180   }
181 
InternalExpectTrue(InterArrival * inter_arrival,uint32_t timestamp,int64_t arrival_time_ms,size_t packet_size,uint32_t expected_timestamp_delta,int64_t expected_arrival_time_delta_ms,int expected_packet_size_delta,uint32_t timestamp_near)182   static void InternalExpectTrue(InterArrival* inter_arrival,
183                                  uint32_t timestamp,
184                                  int64_t arrival_time_ms,
185                                  size_t packet_size,
186                                  uint32_t expected_timestamp_delta,
187                                  int64_t expected_arrival_time_delta_ms,
188                                  int expected_packet_size_delta,
189                                  uint32_t timestamp_near) {
190     uint32_t delta_timestamp = 101;
191     int64_t delta_arrival_time_ms = 303;
192     int delta_packet_size = 909;
193     bool computed = inter_arrival->ComputeDeltas(
194         timestamp, arrival_time_ms, arrival_time_ms, packet_size,
195         &delta_timestamp, &delta_arrival_time_ms, &delta_packet_size);
196     EXPECT_EQ(true, computed);
197     EXPECT_NEAR(expected_timestamp_delta, delta_timestamp, timestamp_near);
198     EXPECT_EQ(expected_arrival_time_delta_ms, delta_arrival_time_ms);
199     EXPECT_EQ(expected_packet_size_delta, delta_packet_size);
200   }
201 
202   std::unique_ptr<InterArrival> inter_arrival_rtp_;
203   std::unique_ptr<InterArrival> inter_arrival_ast_;
204 };
205 
TEST_F(InterArrivalTest,FirstPacket)206 TEST_F(InterArrivalTest, FirstPacket) {
207   ExpectFalse(0, 17, 1);
208 }
209 
TEST_F(InterArrivalTest,FirstGroup)210 TEST_F(InterArrivalTest, FirstGroup) {
211   // G1
212   int64_t arrival_time = 17;
213   int64_t g1_arrival_time = arrival_time;
214   ExpectFalse(0, arrival_time, 1);
215 
216   // G2
217   arrival_time += kBurstThresholdMs + 1;
218   int64_t g2_arrival_time = arrival_time;
219   ExpectFalse(kTriggerNewGroupUs, arrival_time, 2);
220 
221   // G3
222   // Only once the first packet of the third group arrives, do we see the deltas
223   // between the first two.
224   arrival_time += kBurstThresholdMs + 1;
225   ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1,
226              // Delta G2-G1
227              kTriggerNewGroupUs, g2_arrival_time - g1_arrival_time, 1, 0);
228 }
229 
TEST_F(InterArrivalTest,SecondGroup)230 TEST_F(InterArrivalTest, SecondGroup) {
231   // G1
232   int64_t arrival_time = 17;
233   int64_t g1_arrival_time = arrival_time;
234   ExpectFalse(0, arrival_time, 1);
235 
236   // G2
237   arrival_time += kBurstThresholdMs + 1;
238   int64_t g2_arrival_time = arrival_time;
239   ExpectFalse(kTriggerNewGroupUs, arrival_time, 2);
240 
241   // G3
242   arrival_time += kBurstThresholdMs + 1;
243   int64_t g3_arrival_time = arrival_time;
244   ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1,
245              // Delta G2-G1
246              kTriggerNewGroupUs, g2_arrival_time - g1_arrival_time, 1, 0);
247 
248   // G4
249   // First packet of 4th group yields deltas between group 2 and 3.
250   arrival_time += kBurstThresholdMs + 1;
251   ExpectTrue(3 * kTriggerNewGroupUs, arrival_time, 2,
252              // Delta G3-G2
253              kTriggerNewGroupUs, g3_arrival_time - g2_arrival_time, -1, 0);
254 }
255 
TEST_F(InterArrivalTest,AccumulatedGroup)256 TEST_F(InterArrivalTest, AccumulatedGroup) {
257   // G1
258   int64_t arrival_time = 17;
259   int64_t g1_arrival_time = arrival_time;
260   ExpectFalse(0, arrival_time, 1);
261 
262   // G2
263   arrival_time += kBurstThresholdMs + 1;
264   ExpectFalse(kTriggerNewGroupUs, 28, 2);
265   int64_t timestamp = kTriggerNewGroupUs;
266   for (int i = 0; i < 10; ++i) {
267     // A bunch of packets arriving within the same group.
268     arrival_time += kBurstThresholdMs + 1;
269     timestamp += kMinStep;
270     ExpectFalse(timestamp, arrival_time, 1);
271   }
272   int64_t g2_arrival_time = arrival_time;
273   int64_t g2_timestamp = timestamp;
274 
275   // G3
276   arrival_time = 500;
277   ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 100, g2_timestamp,
278              g2_arrival_time - g1_arrival_time,
279              (2 + 10) - 1,  // Delta G2-G1
280              0);
281 }
282 
TEST_F(InterArrivalTest,OutOfOrderPacket)283 TEST_F(InterArrivalTest, OutOfOrderPacket) {
284   // G1
285   int64_t arrival_time = 17;
286   int64_t timestamp = 0;
287   ExpectFalse(timestamp, arrival_time, 1);
288   int64_t g1_timestamp = timestamp;
289   int64_t g1_arrival_time = arrival_time;
290 
291   // G2
292   arrival_time += 11;
293   timestamp += kTriggerNewGroupUs;
294   ExpectFalse(timestamp, 28, 2);
295   for (int i = 0; i < 10; ++i) {
296     arrival_time += kBurstThresholdMs + 1;
297     timestamp += kMinStep;
298     ExpectFalse(timestamp, arrival_time, 1);
299   }
300   int64_t g2_timestamp = timestamp;
301   int64_t g2_arrival_time = arrival_time;
302 
303   // This packet is out of order and should be dropped.
304   arrival_time = 281;
305   ExpectFalse(g1_timestamp, arrival_time, 100);
306 
307   // G3
308   arrival_time = 500;
309   timestamp = 2 * kTriggerNewGroupUs;
310   ExpectTrue(timestamp, arrival_time, 100,
311              // Delta G2-G1
312              g2_timestamp - g1_timestamp, g2_arrival_time - g1_arrival_time,
313              (2 + 10) - 1, 0);
314 }
315 
TEST_F(InterArrivalTest,OutOfOrderWithinGroup)316 TEST_F(InterArrivalTest, OutOfOrderWithinGroup) {
317   // G1
318   int64_t arrival_time = 17;
319   int64_t timestamp = 0;
320   ExpectFalse(timestamp, arrival_time, 1);
321   int64_t g1_timestamp = timestamp;
322   int64_t g1_arrival_time = arrival_time;
323 
324   // G2
325   timestamp += kTriggerNewGroupUs;
326   arrival_time += 11;
327   ExpectFalse(kTriggerNewGroupUs, 28, 2);
328   timestamp += 10 * kMinStep;
329   int64_t g2_timestamp = timestamp;
330   for (int i = 0; i < 10; ++i) {
331     // These packets arrive with timestamps in decreasing order but are
332     // nevertheless accumulated to group because their timestamps are higher
333     // than the initial timestamp of the group.
334     arrival_time += kBurstThresholdMs + 1;
335     ExpectFalse(timestamp, arrival_time, 1);
336     timestamp -= kMinStep;
337   }
338   int64_t g2_arrival_time = arrival_time;
339 
340   // However, this packet is deemed out of order and should be dropped.
341   arrival_time = 281;
342   timestamp = g1_timestamp;
343   ExpectFalse(timestamp, arrival_time, 100);
344 
345   // G3
346   timestamp = 2 * kTriggerNewGroupUs;
347   arrival_time = 500;
348   ExpectTrue(timestamp, arrival_time, 100, g2_timestamp - g1_timestamp,
349              g2_arrival_time - g1_arrival_time, (2 + 10) - 1, 0);
350 }
351 
TEST_F(InterArrivalTest,TwoBursts)352 TEST_F(InterArrivalTest, TwoBursts) {
353   // G1
354   int64_t g1_arrival_time = 17;
355   ExpectFalse(0, g1_arrival_time, 1);
356 
357   // G2
358   int64_t timestamp = kTriggerNewGroupUs;
359   int64_t arrival_time = 100;  // Simulate no packets arriving for 100 ms.
360   for (int i = 0; i < 10; ++i) {
361     // A bunch of packets arriving in one burst (within 5 ms apart).
362     timestamp += 30000;
363     arrival_time += kBurstThresholdMs;
364     ExpectFalse(timestamp, arrival_time, 1);
365   }
366   int64_t g2_arrival_time = arrival_time;
367   int64_t g2_timestamp = timestamp;
368 
369   // G3
370   timestamp += 30000;
371   arrival_time += kBurstThresholdMs + 1;
372   ExpectTrue(timestamp, arrival_time, 100, g2_timestamp,
373              g2_arrival_time - g1_arrival_time,
374              10 - 1,  // Delta G2-G1
375              0);
376 }
377 
TEST_F(InterArrivalTest,NoBursts)378 TEST_F(InterArrivalTest, NoBursts) {
379   // G1
380   ExpectFalse(0, 17, 1);
381 
382   // G2
383   int64_t timestamp = kTriggerNewGroupUs;
384   int64_t arrival_time = 28;
385   ExpectFalse(timestamp, arrival_time, 2);
386 
387   // G3
388   ExpectTrue(kTriggerNewGroupUs + 30000, arrival_time + kBurstThresholdMs + 1,
389              100, timestamp - 0, arrival_time - 17,
390              2 - 1,  // Delta G2-G1
391              0);
392 }
393 
394 // Yields 0xfffffffe when converted to internal representation in
395 // inter_arrival_rtp_ and inter_arrival_ast_ respectively.
396 static const int64_t kStartRtpTimestampWrapUs = 47721858827;
397 static const int64_t kStartAbsSendTimeWrapUs = 63999995;
398 
TEST_F(InterArrivalTest,RtpTimestampWrap)399 TEST_F(InterArrivalTest, RtpTimestampWrap) {
400   WrapTestHelper(kStartRtpTimestampWrapUs, 1, false);
401 }
402 
TEST_F(InterArrivalTest,AbsSendTimeWrap)403 TEST_F(InterArrivalTest, AbsSendTimeWrap) {
404   WrapTestHelper(kStartAbsSendTimeWrapUs, 1, false);
405 }
406 
TEST_F(InterArrivalTest,RtpTimestampWrapOutOfOrderWithinGroup)407 TEST_F(InterArrivalTest, RtpTimestampWrapOutOfOrderWithinGroup) {
408   WrapTestHelper(kStartRtpTimestampWrapUs, 1, true);
409 }
410 
TEST_F(InterArrivalTest,AbsSendTimeWrapOutOfOrderWithinGroup)411 TEST_F(InterArrivalTest, AbsSendTimeWrapOutOfOrderWithinGroup) {
412   WrapTestHelper(kStartAbsSendTimeWrapUs, 1, true);
413 }
414 
TEST_F(InterArrivalTest,PositiveArrivalTimeJump)415 TEST_F(InterArrivalTest, PositiveArrivalTimeJump) {
416   const size_t kPacketSize = 1000;
417   uint32_t send_time_ms = 10000;
418   int64_t arrival_time_ms = 20000;
419   int64_t system_time_ms = 30000;
420 
421   uint32_t send_delta;
422   int64_t arrival_delta;
423   int size_delta;
424   EXPECT_FALSE(inter_arrival_->ComputeDeltas(
425       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
426       &arrival_delta, &size_delta));
427 
428   const int kTimeDeltaMs = 30;
429   send_time_ms += kTimeDeltaMs;
430   arrival_time_ms += kTimeDeltaMs;
431   system_time_ms += kTimeDeltaMs;
432   EXPECT_FALSE(inter_arrival_->ComputeDeltas(
433       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
434       &arrival_delta, &size_delta));
435 
436   send_time_ms += kTimeDeltaMs;
437   arrival_time_ms += kTimeDeltaMs + InterArrival::kArrivalTimeOffsetThresholdMs;
438   system_time_ms += kTimeDeltaMs;
439   EXPECT_TRUE(inter_arrival_->ComputeDeltas(
440       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
441       &arrival_delta, &size_delta));
442   EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
443   EXPECT_EQ(kTimeDeltaMs, arrival_delta);
444   EXPECT_EQ(size_delta, 0);
445 
446   send_time_ms += kTimeDeltaMs;
447   arrival_time_ms += kTimeDeltaMs;
448   system_time_ms += kTimeDeltaMs;
449   // The previous arrival time jump should now be detected and cause a reset.
450   EXPECT_FALSE(inter_arrival_->ComputeDeltas(
451       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
452       &arrival_delta, &size_delta));
453 
454   // The two next packets will not give a valid delta since we're in the initial
455   // state.
456   for (int i = 0; i < 2; ++i) {
457     send_time_ms += kTimeDeltaMs;
458     arrival_time_ms += kTimeDeltaMs;
459     system_time_ms += kTimeDeltaMs;
460     EXPECT_FALSE(inter_arrival_->ComputeDeltas(
461         send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
462         &arrival_delta, &size_delta));
463   }
464 
465   send_time_ms += kTimeDeltaMs;
466   arrival_time_ms += kTimeDeltaMs;
467   system_time_ms += kTimeDeltaMs;
468   EXPECT_TRUE(inter_arrival_->ComputeDeltas(
469       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
470       &arrival_delta, &size_delta));
471   EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
472   EXPECT_EQ(kTimeDeltaMs, arrival_delta);
473   EXPECT_EQ(size_delta, 0);
474 }
475 
TEST_F(InterArrivalTest,NegativeArrivalTimeJump)476 TEST_F(InterArrivalTest, NegativeArrivalTimeJump) {
477   const size_t kPacketSize = 1000;
478   uint32_t send_time_ms = 10000;
479   int64_t arrival_time_ms = 20000;
480   int64_t system_time_ms = 30000;
481 
482   uint32_t send_delta;
483   int64_t arrival_delta;
484   int size_delta;
485   EXPECT_FALSE(inter_arrival_->ComputeDeltas(
486       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
487       &arrival_delta, &size_delta));
488 
489   const int kTimeDeltaMs = 30;
490   send_time_ms += kTimeDeltaMs;
491   arrival_time_ms += kTimeDeltaMs;
492   system_time_ms += kTimeDeltaMs;
493   EXPECT_FALSE(inter_arrival_->ComputeDeltas(
494       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
495       &arrival_delta, &size_delta));
496 
497   send_time_ms += kTimeDeltaMs;
498   arrival_time_ms += kTimeDeltaMs;
499   system_time_ms += kTimeDeltaMs;
500   EXPECT_TRUE(inter_arrival_->ComputeDeltas(
501       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
502       &arrival_delta, &size_delta));
503   EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
504   EXPECT_EQ(kTimeDeltaMs, arrival_delta);
505   EXPECT_EQ(size_delta, 0);
506 
507   // Three out of order will fail, after that we will be reset and two more will
508   // fail before we get our first valid delta after the reset.
509   arrival_time_ms -= 1000;
510   for (int i = 0; i < InterArrival::kReorderedResetThreshold + 3; ++i) {
511     send_time_ms += kTimeDeltaMs;
512     arrival_time_ms += kTimeDeltaMs;
513     system_time_ms += kTimeDeltaMs;
514     // The previous arrival time jump should now be detected and cause a reset.
515     EXPECT_FALSE(inter_arrival_->ComputeDeltas(
516         send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
517         &arrival_delta, &size_delta));
518   }
519 
520   send_time_ms += kTimeDeltaMs;
521   arrival_time_ms += kTimeDeltaMs;
522   system_time_ms += kTimeDeltaMs;
523   EXPECT_TRUE(inter_arrival_->ComputeDeltas(
524       send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
525       &arrival_delta, &size_delta));
526   EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
527   EXPECT_EQ(kTimeDeltaMs, arrival_delta);
528   EXPECT_EQ(size_delta, 0);
529 }
530 }  // namespace testing
531 }  // namespace webrtc
532