OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 kAbsSendTimeInterArrivalUpshift = 8, | 27 kAbsSendTimeInterArrivalUpshift = 8, |
28 kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, | 28 kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, |
29 }; | 29 }; |
30 | 30 |
31 const double kRtpTimestampToMs = 1.0 / 90.0; | 31 const double kRtpTimestampToMs = 1.0 / 90.0; |
32 const double kAstToMs = 1000.0 / static_cast<double>(1 << kInterArrivalShift); | 32 const double kAstToMs = 1000.0 / static_cast<double>(1 << kInterArrivalShift); |
33 | 33 |
34 class InterArrivalTest : public ::testing::Test { | 34 class InterArrivalTest : public ::testing::Test { |
35 protected: | 35 protected: |
36 virtual void SetUp() { | 36 virtual void SetUp() { |
| 37 inter_arrival_.reset( |
| 38 new InterArrival(kTimestampGroupLengthUs / 1000, 1.0, true)); |
37 inter_arrival_rtp_.reset(new InterArrival( | 39 inter_arrival_rtp_.reset(new InterArrival( |
38 MakeRtpTimestamp(kTimestampGroupLengthUs), | 40 MakeRtpTimestamp(kTimestampGroupLengthUs), |
39 kRtpTimestampToMs, | 41 kRtpTimestampToMs, |
40 true)); | 42 true)); |
41 inter_arrival_ast_.reset(new InterArrival( | 43 inter_arrival_ast_.reset(new InterArrival( |
42 MakeAbsSendTime(kTimestampGroupLengthUs), | 44 MakeAbsSendTime(kTimestampGroupLengthUs), |
43 kAstToMs, | 45 kAstToMs, |
44 true)); | 46 true)); |
45 } | 47 } |
46 | 48 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 arrival_time += kBurstThresholdMs + 1; | 144 arrival_time += kBurstThresholdMs + 1; |
143 ExpectTrue(wrap_start_us + 2 * kTriggerNewGroupUs, | 145 ExpectTrue(wrap_start_us + 2 * kTriggerNewGroupUs, |
144 arrival_time, 100, | 146 arrival_time, 100, |
145 // Delta G6-G5 | 147 // Delta G6-G5 |
146 kTriggerNewGroupUs - 9 * kMinStep, | 148 kTriggerNewGroupUs - 9 * kMinStep, |
147 g6_arrival_time - g5_arrival_time, | 149 g6_arrival_time - g5_arrival_time, |
148 10 - (2 + 10), | 150 10 - (2 + 10), |
149 timestamp_near); | 151 timestamp_near); |
150 } | 152 } |
151 | 153 |
| 154 std::unique_ptr<InterArrival> inter_arrival_; |
| 155 |
152 private: | 156 private: |
153 static uint32_t MakeRtpTimestamp(int64_t us) { | 157 static uint32_t MakeRtpTimestamp(int64_t us) { |
154 return static_cast<uint32_t>(static_cast<uint64_t>(us * 90 + 500) / 1000); | 158 return static_cast<uint32_t>(static_cast<uint64_t>(us * 90 + 500) / 1000); |
155 } | 159 } |
156 | 160 |
157 static uint32_t MakeAbsSendTime(int64_t us) { | 161 static uint32_t MakeAbsSendTime(int64_t us) { |
158 uint32_t absolute_send_time = static_cast<uint32_t>( | 162 uint32_t absolute_send_time = static_cast<uint32_t>( |
159 ((static_cast<uint64_t>(us) << 18) + 500000) / 1000000) & 0x00FFFFFFul; | 163 ((static_cast<uint64_t>(us) << 18) + 500000) / 1000000) & 0x00FFFFFFul; |
160 return absolute_send_time << 8; | 164 return absolute_send_time << 8; |
161 } | 165 } |
162 | 166 |
163 static void InternalExpectFalse(InterArrival* inter_arrival, | 167 static void InternalExpectFalse(InterArrival* inter_arrival, |
164 uint32_t timestamp, int64_t arrival_time_ms, | 168 uint32_t timestamp, int64_t arrival_time_ms, |
165 size_t packet_size) { | 169 size_t packet_size) { |
166 uint32_t dummy_timestamp = 101; | 170 uint32_t dummy_timestamp = 101; |
167 int64_t dummy_arrival_time_ms = 303; | 171 int64_t dummy_arrival_time_ms = 303; |
168 int dummy_packet_size = 909; | 172 int dummy_packet_size = 909; |
169 bool computed = inter_arrival->ComputeDeltas(timestamp, | 173 bool computed = inter_arrival->ComputeDeltas( |
170 arrival_time_ms, | 174 timestamp, arrival_time_ms, arrival_time_ms, packet_size, |
171 packet_size, | 175 &dummy_timestamp, &dummy_arrival_time_ms, &dummy_packet_size); |
172 &dummy_timestamp, | |
173 &dummy_arrival_time_ms, | |
174 &dummy_packet_size); | |
175 EXPECT_EQ(computed, false); | 176 EXPECT_EQ(computed, false); |
176 EXPECT_EQ(101ul, dummy_timestamp); | 177 EXPECT_EQ(101ul, dummy_timestamp); |
177 EXPECT_EQ(303, dummy_arrival_time_ms); | 178 EXPECT_EQ(303, dummy_arrival_time_ms); |
178 EXPECT_EQ(909, dummy_packet_size); | 179 EXPECT_EQ(909, dummy_packet_size); |
179 } | 180 } |
180 | 181 |
181 static void InternalExpectTrue(InterArrival* inter_arrival, | 182 static void InternalExpectTrue(InterArrival* inter_arrival, |
182 uint32_t timestamp, int64_t arrival_time_ms, | 183 uint32_t timestamp, int64_t arrival_time_ms, |
183 size_t packet_size, | 184 size_t packet_size, |
184 uint32_t expected_timestamp_delta, | 185 uint32_t expected_timestamp_delta, |
185 int64_t expected_arrival_time_delta_ms, | 186 int64_t expected_arrival_time_delta_ms, |
186 int expected_packet_size_delta, | 187 int expected_packet_size_delta, |
187 uint32_t timestamp_near) { | 188 uint32_t timestamp_near) { |
188 uint32_t delta_timestamp = 101; | 189 uint32_t delta_timestamp = 101; |
189 int64_t delta_arrival_time_ms = 303; | 190 int64_t delta_arrival_time_ms = 303; |
190 int delta_packet_size = 909; | 191 int delta_packet_size = 909; |
191 bool computed = inter_arrival->ComputeDeltas(timestamp, | 192 bool computed = inter_arrival->ComputeDeltas( |
192 arrival_time_ms, | 193 timestamp, arrival_time_ms, arrival_time_ms, packet_size, |
193 packet_size, | 194 &delta_timestamp, &delta_arrival_time_ms, &delta_packet_size); |
194 &delta_timestamp, | |
195 &delta_arrival_time_ms, | |
196 &delta_packet_size); | |
197 EXPECT_EQ(true, computed); | 195 EXPECT_EQ(true, computed); |
198 EXPECT_NEAR(expected_timestamp_delta, delta_timestamp, timestamp_near); | 196 EXPECT_NEAR(expected_timestamp_delta, delta_timestamp, timestamp_near); |
199 EXPECT_EQ(expected_arrival_time_delta_ms, delta_arrival_time_ms); | 197 EXPECT_EQ(expected_arrival_time_delta_ms, delta_arrival_time_ms); |
200 EXPECT_EQ(expected_packet_size_delta, delta_packet_size); | 198 EXPECT_EQ(expected_packet_size_delta, delta_packet_size); |
201 } | 199 } |
202 | 200 |
203 std::unique_ptr<InterArrival> inter_arrival_rtp_; | 201 std::unique_ptr<InterArrival> inter_arrival_rtp_; |
204 std::unique_ptr<InterArrival> inter_arrival_ast_; | 202 std::unique_ptr<InterArrival> inter_arrival_ast_; |
205 }; | 203 }; |
206 | 204 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 WrapTestHelper(kStartAbsSendTimeWrapUs, 1, false); | 410 WrapTestHelper(kStartAbsSendTimeWrapUs, 1, false); |
413 } | 411 } |
414 | 412 |
415 TEST_F(InterArrivalTest, RtpTimestampWrapOutOfOrderWithinGroup) { | 413 TEST_F(InterArrivalTest, RtpTimestampWrapOutOfOrderWithinGroup) { |
416 WrapTestHelper(kStartRtpTimestampWrapUs, 1, true); | 414 WrapTestHelper(kStartRtpTimestampWrapUs, 1, true); |
417 } | 415 } |
418 | 416 |
419 TEST_F(InterArrivalTest, AbsSendTimeWrapOutOfOrderWithinGroup) { | 417 TEST_F(InterArrivalTest, AbsSendTimeWrapOutOfOrderWithinGroup) { |
420 WrapTestHelper(kStartAbsSendTimeWrapUs, 1, true); | 418 WrapTestHelper(kStartAbsSendTimeWrapUs, 1, true); |
421 } | 419 } |
| 420 |
| 421 TEST_F(InterArrivalTest, PositiveArrivalTimeJump) { |
| 422 const size_t kPacketSize = 1000; |
| 423 uint32_t send_time_ms = 10000; |
| 424 int64_t arrival_time_ms = 20000; |
| 425 int64_t system_time_ms = 30000; |
| 426 |
| 427 uint32_t send_delta; |
| 428 int64_t arrival_delta; |
| 429 int size_delta; |
| 430 EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 431 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 432 &arrival_delta, &size_delta)); |
| 433 |
| 434 const int kTimeDeltaMs = 30; |
| 435 send_time_ms += kTimeDeltaMs; |
| 436 arrival_time_ms += kTimeDeltaMs; |
| 437 system_time_ms += kTimeDeltaMs; |
| 438 EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 439 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 440 &arrival_delta, &size_delta)); |
| 441 |
| 442 send_time_ms += kTimeDeltaMs; |
| 443 arrival_time_ms += kTimeDeltaMs + InterArrival::kArrivalTimeOffsetThresholdMs; |
| 444 system_time_ms += kTimeDeltaMs; |
| 445 EXPECT_TRUE(inter_arrival_->ComputeDeltas( |
| 446 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 447 &arrival_delta, &size_delta)); |
| 448 EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta)); |
| 449 EXPECT_EQ(kTimeDeltaMs, arrival_delta); |
| 450 EXPECT_EQ(size_delta, 0); |
| 451 |
| 452 send_time_ms += kTimeDeltaMs; |
| 453 arrival_time_ms += kTimeDeltaMs; |
| 454 system_time_ms += kTimeDeltaMs; |
| 455 // The previous arrival time jump should now be detected and cause a reset. |
| 456 EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 457 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 458 &arrival_delta, &size_delta)); |
| 459 |
| 460 // The two next packets will not give a valid delta since we're in the initial |
| 461 // state. |
| 462 for (int i = 0; i < 2; ++i) { |
| 463 send_time_ms += kTimeDeltaMs; |
| 464 arrival_time_ms += kTimeDeltaMs; |
| 465 system_time_ms += kTimeDeltaMs; |
| 466 EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 467 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 468 &arrival_delta, &size_delta)); |
| 469 } |
| 470 |
| 471 send_time_ms += kTimeDeltaMs; |
| 472 arrival_time_ms += kTimeDeltaMs; |
| 473 system_time_ms += kTimeDeltaMs; |
| 474 EXPECT_TRUE(inter_arrival_->ComputeDeltas( |
| 475 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 476 &arrival_delta, &size_delta)); |
| 477 EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta)); |
| 478 EXPECT_EQ(kTimeDeltaMs, arrival_delta); |
| 479 EXPECT_EQ(size_delta, 0); |
| 480 } |
| 481 |
| 482 TEST_F(InterArrivalTest, NegativeArrivalTimeJump) { |
| 483 const size_t kPacketSize = 1000; |
| 484 uint32_t send_time_ms = 10000; |
| 485 int64_t arrival_time_ms = 20000; |
| 486 int64_t system_time_ms = 30000; |
| 487 |
| 488 uint32_t send_delta; |
| 489 int64_t arrival_delta; |
| 490 int size_delta; |
| 491 EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 492 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 493 &arrival_delta, &size_delta)); |
| 494 |
| 495 const int kTimeDeltaMs = 30; |
| 496 send_time_ms += kTimeDeltaMs; |
| 497 arrival_time_ms += kTimeDeltaMs; |
| 498 system_time_ms += kTimeDeltaMs; |
| 499 EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 500 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 501 &arrival_delta, &size_delta)); |
| 502 |
| 503 send_time_ms += kTimeDeltaMs; |
| 504 arrival_time_ms += kTimeDeltaMs; |
| 505 system_time_ms += kTimeDeltaMs; |
| 506 EXPECT_TRUE(inter_arrival_->ComputeDeltas( |
| 507 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 508 &arrival_delta, &size_delta)); |
| 509 EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta)); |
| 510 EXPECT_EQ(kTimeDeltaMs, arrival_delta); |
| 511 EXPECT_EQ(size_delta, 0); |
| 512 |
| 513 // Three out of order will fail, after that we will be reset and two more will |
| 514 // fail before we get our first valid delta after the reset. |
| 515 arrival_time_ms -= 1000; |
| 516 for (int i = 0; i < InterArrival::kReorderedResetThreshold + 3; ++i) { |
| 517 send_time_ms += kTimeDeltaMs; |
| 518 arrival_time_ms += kTimeDeltaMs; |
| 519 system_time_ms += kTimeDeltaMs; |
| 520 // The previous arrival time jump should now be detected and cause a reset. |
| 521 EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 522 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 523 &arrival_delta, &size_delta)); |
| 524 } |
| 525 |
| 526 send_time_ms += kTimeDeltaMs; |
| 527 arrival_time_ms += kTimeDeltaMs; |
| 528 system_time_ms += kTimeDeltaMs; |
| 529 EXPECT_TRUE(inter_arrival_->ComputeDeltas( |
| 530 send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 531 &arrival_delta, &size_delta)); |
| 532 EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta)); |
| 533 EXPECT_EQ(kTimeDeltaMs, arrival_delta); |
| 534 EXPECT_EQ(size_delta, 0); |
| 535 } |
422 } // namespace testing | 536 } // namespace testing |
423 } // namespace webrtc | 537 } // namespace webrtc |
OLD | NEW |