DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
/*
/*
 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include <memory>
#include <memory>

#include "common_types.h"  // NOLINT(build/include)
#include "modules/remote_bitrate_estimator/inter_arrival.h"
#include "test/gtest.h"

namespace webrtc {
namespace testing {
namespace testing {

enum {
  kTimestampGroupLengthUs = 5000,
  kMinStep = 20,
  kTriggerNewGroupUs = kTimestampGroupLengthUs + kMinStep,
  kTriggerNewGroupUs = kTimestampGroupLengthUs + kMinStep,
  kBurstThresholdMs = 5,
  kAbsSendTimeFraction = 18,
  kAbsSendTimeInterArrivalUpshift = 8,
  kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift,
};
};

const double kRtpTimestampToMs = 1.0 / 90.0;
const double kAstToMs = 1000.0 / static_cast<double>(1 << kInterArrivalShift);

class InterArrivalTest : public ::testing::Test {
class InterArrivalTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    inter_arrival_.reset(
        new InterArrival(kTimestampGroupLengthUs / 1000, 1.0, true));
    inter_arrival_rtp_.reset(new InterArrival(
    inter_arrival_rtp_.reset(new InterArrival(
        MakeRtpTimestamp(kTimestampGroupLengthUs),
        kRtpTimestampToMs,
        true));
    inter_arrival_ast_.reset(new InterArrival(
        MakeAbsSendTime(kTimestampGroupLengthUs),
        MakeAbsSendTime(kTimestampGroupLengthUs),
        kAstToMs,
        true));
  }

  // Test that neither inter_arrival instance complete the timestamp group from
  // Test that neither inter_arrival instance complete the timestamp group from
  // the given data.
  void ExpectFalse(int64_t timestamp_us, int64_t arrival_time_ms,
                   size_t packet_size) {
    InternalExpectFalse(inter_arrival_rtp_.get(),
                        MakeRtpTimestamp(timestamp_us), arrival_time_ms,
                        MakeRtpTimestamp(timestamp_us), arrival_time_ms,
                        packet_size);
    InternalExpectFalse(inter_arrival_ast_.get(), MakeAbsSendTime(timestamp_us),
                        arrival_time_ms, packet_size);
  }

  // Test that both inter_arrival instances complete the timestamp group from
  // the given data and that all returned deltas are as expected (except
  // the given data and that all returned deltas are as expected (except
  // timestamp delta, which is rounded from us to different ranges and must
  // match within an interval, given in |timestamp_near].
  void 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,
                  int64_t expected_arrival_time_delta_ms,
                  int expected_packet_size_delta,
                  uint32_t timestamp_near) {
    InternalExpectTrue(inter_arrival_rtp_.get(), MakeRtpTimestamp(timestamp_us),
                       arrival_time_ms, packet_size,
                       MakeRtpTimestamp(expected_timestamp_delta_us),
                       MakeRtpTimestamp(expected_timestamp_delta_us),
                       expected_arrival_time_delta_ms,
                       expected_packet_size_delta, timestamp_near);
    InternalExpectTrue(inter_arrival_ast_.get(), MakeAbsSendTime(timestamp_us),
                       arrival_time_ms, packet_size,
                       MakeAbsSendTime(expected_timestamp_delta_us),
                       MakeAbsSendTime(expected_timestamp_delta_us),
                       expected_arrival_time_delta_ms,
                       expected_packet_size_delta, timestamp_near << 8);
  }

  void WrapTestHelper(int64_t wrap_start_us, uint32_t timestamp_near,
  void WrapTestHelper(int64_t wrap_start_us, uint32_t timestamp_near,
                      bool unorderly_within_group) {
    // Step through the range of a 32 bit int, 1/4 at a time to not cause
    // packets close to wraparound to be judged as out of order.

    // G1
    int64_t arrival_time = 17;
    ExpectFalse(0, arrival_time, 1);

    // G2
    arrival_time += kBurstThresholdMs + 1;
    ExpectFalse(wrap_start_us / 4, arrival_time, 1);


    // G3
    arrival_time += kBurstThresholdMs + 1;
    ExpectTrue(wrap_start_us / 2, arrival_time, 1,
               wrap_start_us / 4, 6, 0,   // Delta G2-G1
               0);
               0);

    // G4
    arrival_time += kBurstThresholdMs + 1;
    int64_t g4_arrival_time = arrival_time;
    ExpectTrue(wrap_start_us / 2 + wrap_start_us / 4, arrival_time, 1,
    ExpectTrue(wrap_start_us / 2 + wrap_start_us / 4, arrival_time, 1,
               wrap_start_us / 4, 6, 0,   // Delta G3-G2
               timestamp_near);

    // G5
    arrival_time += kBurstThresholdMs + 1;
    arrival_time += kBurstThresholdMs + 1;
    ExpectTrue(wrap_start_us, arrival_time, 2,
               wrap_start_us / 4, 6, 0,   // Delta G4-G3
               timestamp_near);
    for (int i = 0; i < 10; ++i) {
    for (int i = 0; i < 10; ++i) {
      // Slowly step across the wrap point.
      arrival_time += kBurstThresholdMs + 1;
      if (unorderly_within_group) {
        // These packets arrive with timestamps in decreasing order but are
        // nevertheless accumulated to group because their timestamps are higher
        // nevertheless accumulated to group because their timestamps are higher
        // than the initial timestamp of the group.
        ExpectFalse(wrap_start_us + kMinStep * (9 - i), arrival_time, 1);
      } else {
        ExpectFalse(wrap_start_us + kMinStep * i, arrival_time, 1);
      }
    }
    }
    int64_t g5_arrival_time = arrival_time;

    // This packet is out of order and should be dropped.
    arrival_time += kBurstThresholdMs + 1;
    arrival_time += kBurstThresholdMs + 1;
    ExpectFalse(wrap_start_us - 100, arrival_time, 100);

    // G6
    arrival_time += kBurstThresholdMs + 1;
    int64_t g6_arrival_time = arrival_time;
    int64_t g6_arrival_time = arrival_time;
    ExpectTrue(wrap_start_us + kTriggerNewGroupUs, arrival_time, 10,
               wrap_start_us / 4 + 9 * kMinStep,
               g5_arrival_time - g4_arrival_time,
               (2 + 10) - 1,  // Delta G5-G4
               timestamp_near);
               timestamp_near);

    // This packet is out of order and should be dropped.
    arrival_time += kBurstThresholdMs + 1;
    ExpectFalse(wrap_start_us + kTimestampGroupLengthUs, arrival_time, 100);


    // G7
    arrival_time += kBurstThresholdMs + 1;
    ExpectTrue(wrap_start_us + 2 * kTriggerNewGroupUs,
               arrival_time, 100,
               // Delta G6-G5
               // Delta G6-G5
               kTriggerNewGroupUs - 9 * kMinStep,
               g6_arrival_time - g5_arrival_time,
               10 - (2 + 10),
               timestamp_near);
  }
  }

  std::unique_ptr<InterArrival> inter_arrival_;

 private:
  static uint32_t MakeRtpTimestamp(int64_t us) {
    return static_cast<uint32_t>(static_cast<uint64_t>(us * 90 + 500) / 1000);
    return static_cast<uint32_t>(static_cast<uint64_t>(us * 90 + 500) / 1000);
  }

  static uint32_t MakeAbsSendTime(int64_t us) {
    uint32_t absolute_send_time = static_cast<uint32_t>(
        ((static_cast<uint64_t>(us) << 18) + 500000) / 1000000) & 0x00FFFFFFul;
        ((static_cast<uint64_t>(us) << 18) + 500000) / 1000000) & 0x00FFFFFFul;
    return absolute_send_time << 8;
  }

  static void InternalExpectFalse(InterArrival* inter_arrival,
                                  uint32_t timestamp, int64_t arrival_time_ms,
                                  uint32_t timestamp, int64_t arrival_time_ms,
                                  size_t packet_size) {
    uint32_t dummy_timestamp = 101;
    int64_t dummy_arrival_time_ms = 303;
    int dummy_packet_size = 909;
    bool computed = inter_arrival->ComputeDeltas(
    bool computed = inter_arrival->ComputeDeltas(
        timestamp, arrival_time_ms, arrival_time_ms, packet_size,
        &dummy_timestamp, &dummy_arrival_time_ms, &dummy_packet_size);
    EXPECT_EQ(computed, false);
    EXPECT_EQ(101ul, dummy_timestamp);
    EXPECT_EQ(303, dummy_arrival_time_ms);
    EXPECT_EQ(303, dummy_arrival_time_ms);
    EXPECT_EQ(909, dummy_packet_size);
  }

  static void 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) {
                                 uint32_t timestamp_near) {
    uint32_t delta_timestamp = 101;
    int64_t delta_arrival_time_ms = 303;
    int delta_packet_size = 909;
    bool computed = inter_arrival->ComputeDeltas(
        timestamp, arrival_time_ms, arrival_time_ms, packet_size,
        timestamp, arrival_time_ms, arrival_time_ms, packet_size,
        &delta_timestamp, &delta_arrival_time_ms, &delta_packet_size);
    EXPECT_EQ(true, computed);
    EXPECT_NEAR(expected_timestamp_delta, delta_timestamp, timestamp_near);
    EXPECT_EQ(expected_arrival_time_delta_ms, delta_arrival_time_ms);
    EXPECT_EQ(expected_packet_size_delta, delta_packet_size);
    EXPECT_EQ(expected_packet_size_delta, delta_packet_size);
  }

  std::unique_ptr<InterArrival> inter_arrival_rtp_;
  std::unique_ptr<InterArrival> inter_arrival_ast_;
};
};

TEST_F(InterArrivalTest, FirstPacket) {
  ExpectFalse(0, 17, 1);
}

TEST_F(InterArrivalTest, FirstGroup) {
  // G1
  // G1
  int64_t arrival_time = 17;
  int64_t g1_arrival_time = arrival_time;
  ExpectFalse(0, arrival_time, 1);

  // G2
  // G2
  arrival_time += kBurstThresholdMs + 1;
  int64_t g2_arrival_time = arrival_time;
  ExpectFalse(kTriggerNewGroupUs, arrival_time, 2);

  // G3
  // G3
  // Only once the first packet of the third group arrives, do we see the deltas
  // between the first two.
  arrival_time += kBurstThresholdMs + 1;
  ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1,
  ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1,
             // Delta G2-G1
             kTriggerNewGroupUs, g2_arrival_time - g1_arrival_time, 1,
             0);
}


TEST_F(InterArrivalTest, SecondGroup) {
  // G1
  int64_t arrival_time = 17;
  int64_t g1_arrival_time = arrival_time;
  ExpectFalse(0, arrival_time, 1);
  ExpectFalse(0, arrival_time, 1);

  // G2
  arrival_time += kBurstThresholdMs + 1;
  int64_t g2_arrival_time = arrival_time;
  ExpectFalse(kTriggerNewGroupUs, arrival_time, 2);
  ExpectFalse(kTriggerNewGroupUs, arrival_time, 2);

  // G3
  arrival_time += kBurstThresholdMs + 1;
  int64_t g3_arrival_time = arrival_time;
  ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1,
  ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1,
             // Delta G2-G1
             kTriggerNewGroupUs, g2_arrival_time - g1_arrival_time, 1,
             0);

  // G4
  // G4
  // First packet of 4th group yields deltas between group 2 and 3.
  arrival_time += kBurstThresholdMs + 1;
  ExpectTrue(3 * kTriggerNewGroupUs, arrival_time, 2,
             // Delta G3-G2
             kTriggerNewGroupUs, g3_arrival_time - g2_arrival_time, -1,
             kTriggerNewGroupUs, g3_arrival_time - g2_arrival_time, -1,
             0);
}


TEST_F(InterArrivalTest, AccumulatedGroup) {
TEST_F(InterArrivalTest, AccumulatedGroup) {
  // G1
  int64_t arrival_time = 17;
  int64_t g1_arrival_time = arrival_time;
  int64_t g1_arrival_time = arrival_time;
  ExpectFalse(0, arrival_time, 1);

  // G2
  arrival_time += kBurstThresholdMs + 1;
  ExpectFalse(kTriggerNewGroupUs, 28, 2);
  ExpectFalse(kTriggerNewGroupUs, 28, 2);
  int64_t timestamp = kTriggerNewGroupUs;
  for (int i = 0; i < 10; ++i) {
    // A bunch of packets arriving within the same group.
    arrival_time += kBurstThresholdMs + 1;
    timestamp += kMinStep;
    timestamp += kMinStep;
    ExpectFalse(timestamp, arrival_time, 1);
  }
  int64_t g2_arrival_time = arrival_time;
  int64_t g2_timestamp = timestamp;


  // G3
  arrival_time = 500;
  ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 100,
             g2_timestamp, g2_arrival_time - g1_arrival_time,
             (2 + 10) - 1,   // Delta G2-G1
             (2 + 10) - 1,   // Delta G2-G1
             0);
             0);
}

TEST_F(InterArrivalTest, OutOfOrderPacket) {
  // G1
  int64_t arrival_time = 17;
  int64_t arrival_time = 17;
  int64_t timestamp = 0;
  ExpectFalse(timestamp, arrival_time, 1);
  int64_t g1_timestamp = timestamp;
  int64_t g1_arrival_time = arrival_time;


  // G2
  arrival_time += 11;
  timestamp += kTriggerNewGroupUs;
  ExpectFalse(timestamp, 28, 2);
  for (int i = 0; i < 10; ++i) {
  for (int i = 0; i < 10; ++i) {
    arrival_time += kBurstThresholdMs + 1;
    timestamp += kMinStep;
    ExpectFalse(timestamp, arrival_time, 1);
  }
  int64_t g2_timestamp = timestamp;
  int64_t g2_timestamp = timestamp;
  int64_t g2_arrival_time = arrival_time;

  // This packet is out of order and should be dropped.
  arrival_time = 281;
  ExpectFalse(g1_timestamp, arrival_time, 100);

  // G3
  arrival_time = 500;
  timestamp = 2 * kTriggerNewGroupUs;
  timestamp = 2 * kTriggerNewGroupUs;
  ExpectTrue(timestamp, arrival_time, 100,
             // Delta G2-G1
             g2_timestamp - g1_timestamp, g2_arrival_time - g1_arrival_time,
             (2 + 10) - 1,
             0);
}

TEST_F(InterArrivalTest, OutOfOrderWithinGroup) {
TEST_F(InterArrivalTest, OutOfOrderWithinGroup) {
  // G1
  int64_t arrival_time = 17;
  int64_t timestamp = 0;
  ExpectFalse(timestamp, arrival_time, 1);
  int64_t g1_timestamp = timestamp;
  int64_t g1_timestamp = timestamp;
  int64_t g1_arrival_time = arrival_time;

  // G2
  timestamp += kTriggerNewGroupUs;
  timestamp += kTriggerNewGroupUs;
  arrival_time += 11;
  ExpectFalse(kTriggerNewGroupUs, 28, 2);
  timestamp += 10 * kMinStep;
  int64_t g2_timestamp = timestamp;
  for (int i = 0; i < 10; ++i) {
  for (int i = 0; i < 10; ++i) {
    // These packets arrive with timestamps in decreasing order but are
    // nevertheless accumulated to group because their timestamps are higher
    // than the initial timestamp of the group.
    arrival_time += kBurstThresholdMs + 1;
    ExpectFalse(timestamp, arrival_time, 1);
    ExpectFalse(timestamp, arrival_time, 1);
    timestamp -= kMinStep;
  }
  int64_t g2_arrival_time = arrival_time;

  // However, this packet is deemed out of order and should be dropped.
  // However, this packet is deemed out of order and should be dropped.
  arrival_time = 281;
  timestamp = g1_timestamp;
  ExpectFalse(timestamp, arrival_time, 100);

  // G3
  timestamp = 2 * kTriggerNewGroupUs;
  arrival_time = 500;
  ExpectTrue(timestamp, arrival_time, 100,
  ExpectTrue(timestamp, arrival_time, 100,
             g2_timestamp - g1_timestamp, g2_arrival_time - g1_arrival_time,
             (2 + 10) - 1,
             0);
}


TEST_F(InterArrivalTest, TwoBursts) {
  // G1
  int64_t g1_arrival_time = 17;
  ExpectFalse(0, g1_arrival_time, 1);


  // G2
  int64_t timestamp = kTriggerNewGroupUs;
  int64_t arrival_time = 100;  // Simulate no packets arriving for 100 ms.
  for (int i = 0; i < 10; ++i) {
    // A bunch of packets arriving in one burst (within 5 ms apart).
    // A bunch of packets arriving in one burst (within 5 ms apart).
    timestamp += 30000;
    arrival_time += kBurstThresholdMs;
    ExpectFalse(timestamp, arrival_time, 1);
  }
  int64_t g2_arrival_time = arrival_time;
  int64_t g2_arrival_time = arrival_time;
  int64_t g2_timestamp = timestamp;

  // G3
  timestamp += 30000;
  timestamp += 30000;
  arrival_time += kBurstThresholdMs + 1;
  ExpectTrue(timestamp, arrival_time, 100,
             g2_timestamp, g2_arrival_time - g1_arrival_time,
             10 - 1,  // Delta G2-G1
             0);
             0);
}


TEST_F(InterArrivalTest, NoBursts) {
  // G1
  // G1
  ExpectFalse(0, 17, 1);

  // G2
  int64_t timestamp = kTriggerNewGroupUs;
  int64_t arrival_time = 28;
  int64_t arrival_time = 28;
  ExpectFalse(timestamp, arrival_time, 2);

  // G3
  ExpectTrue(kTriggerNewGroupUs + 30000, arrival_time + kBurstThresholdMs + 1,
             100, timestamp - 0, arrival_time - 17,
             100, timestamp - 0, arrival_time - 17,
             2 - 1,  // Delta G2-G1
             0);
}

// Yields 0xfffffffe when converted to internal representation in
// Yields 0xfffffffe when converted to internal representation in
// inter_arrival_rtp_ and inter_arrival_ast_ respectively.
static const int64_t kStartRtpTimestampWrapUs = 47721858827;
static const int64_t kStartAbsSendTimeWrapUs = 63999995;
static const int64_t kStartAbsSendTimeWrapUs = 63999995;


TEST_F(InterArrivalTest, RtpTimestampWrap) {
  WrapTestHelper(kStartRtpTimestampWrapUs, 1, false);
}
}

TEST_F(InterArrivalTest, AbsSendTimeWrap) {
  WrapTestHelper(kStartAbsSendTimeWrapUs, 1, false);
}


TEST_F(InterArrivalTest, RtpTimestampWrapOutOfOrderWithinGroup) {
  WrapTestHelper(kStartRtpTimestampWrapUs, 1, true);
  WrapTestHelper(kStartRtpTimestampWrapUs, 1, true);
}

TEST_F(InterArrivalTest, AbsSendTimeWrapOutOfOrderWithinGroup) {
  WrapTestHelper(kStartAbsSendTimeWrapUs, 1, true);
}
}

TEST_F(InterArrivalTest, PositiveArrivalTimeJump) {
  const size_t kPacketSize = 1000;
  uint32_t send_time_ms = 10000;
  int64_t arrival_time_ms = 20000;
  int64_t arrival_time_ms = 20000;
  int64_t system_time_ms = 30000;

  uint32_t send_delta;
  int64_t arrival_delta;
  int64_t arrival_delta;
  int size_delta;
  EXPECT_FALSE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));


  const int kTimeDeltaMs = 30;
  send_time_ms += kTimeDeltaMs;
  arrival_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  EXPECT_FALSE(inter_arrival_->ComputeDeltas(
  EXPECT_FALSE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));

  send_time_ms += kTimeDeltaMs;
  arrival_time_ms += kTimeDeltaMs + InterArrival::kArrivalTimeOffsetThresholdMs;
  arrival_time_ms += kTimeDeltaMs + InterArrival::kArrivalTimeOffsetThresholdMs;
  system_time_ms += kTimeDeltaMs;
  EXPECT_TRUE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));
  EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
  EXPECT_EQ(kTimeDeltaMs, arrival_delta);
  EXPECT_EQ(size_delta, 0);
  EXPECT_EQ(size_delta, 0);

  send_time_ms += kTimeDeltaMs;
  arrival_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  // The previous arrival time jump should now be detected and cause a reset.
  EXPECT_FALSE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));


  // The two next packets will not give a valid delta since we're in the initial
  // state.
  for (int i = 0; i < 2; ++i) {
    send_time_ms += kTimeDeltaMs;
    arrival_time_ms += kTimeDeltaMs;
    arrival_time_ms += kTimeDeltaMs;
    system_time_ms += kTimeDeltaMs;
    EXPECT_FALSE(inter_arrival_->ComputeDeltas(
        send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
        &arrival_delta, &size_delta));
  }
  }

  send_time_ms += kTimeDeltaMs;
  arrival_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  EXPECT_TRUE(inter_arrival_->ComputeDeltas(
  EXPECT_TRUE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));
  EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
  EXPECT_EQ(kTimeDeltaMs, arrival_delta);
  EXPECT_EQ(size_delta, 0);
  EXPECT_EQ(size_delta, 0);
}

TEST_F(InterArrivalTest, NegativeArrivalTimeJump) {
  const size_t kPacketSize = 1000;
  const size_t kPacketSize = 1000;
  uint32_t send_time_ms = 10000;
  int64_t arrival_time_ms = 20000;
  int64_t system_time_ms = 30000;

  uint32_t send_delta;
  uint32_t send_delta;
  int64_t arrival_delta;
  int size_delta;
  EXPECT_FALSE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));
      &arrival_delta, &size_delta));

  const int kTimeDeltaMs = 30;
  send_time_ms += kTimeDeltaMs;
  arrival_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  EXPECT_FALSE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));

  send_time_ms += kTimeDeltaMs;
  arrival_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  EXPECT_TRUE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));
  EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
  EXPECT_EQ(kTimeDeltaMs, arrival_delta);
  EXPECT_EQ(kTimeDeltaMs, arrival_delta);
  EXPECT_EQ(size_delta, 0);

  // Three out of order will fail, after that we will be reset and two more will
  // fail before we get our first valid delta after the reset.
  arrival_time_ms -= 1000;
  for (int i = 0; i < InterArrival::kReorderedResetThreshold + 3; ++i) {
    send_time_ms += kTimeDeltaMs;
    send_time_ms += kTimeDeltaMs;
    arrival_time_ms += kTimeDeltaMs;
    system_time_ms += kTimeDeltaMs;
    // The previous arrival time jump should now be detected and cause a reset.
    EXPECT_FALSE(inter_arrival_->ComputeDeltas(
        send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
        send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
        &arrival_delta, &size_delta));
  }

  send_time_ms += kTimeDeltaMs;
  arrival_time_ms += kTimeDeltaMs;
  arrival_time_ms += kTimeDeltaMs;
  system_time_ms += kTimeDeltaMs;
  EXPECT_TRUE(inter_arrival_->ComputeDeltas(
      send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta,
      &arrival_delta, &size_delta));
  EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
  EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta));
  EXPECT_EQ(kTimeDeltaMs, arrival_delta);
  EXPECT_EQ(size_delta, 0);
}
}  // namespace testing
}  // namespace webrtc
}  // namespace webrtc