OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 |
11 #include <string.h> | 11 #include <string.h> |
12 | 12 |
13 #include <list> | 13 #include <list> |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/modules/video_coding/frame_buffer.h" | 16 #include "webrtc/modules/video_coding/frame_buffer.h" |
17 #include "webrtc/modules/video_coding/jitter_buffer.h" | 17 #include "webrtc/modules/video_coding/jitter_buffer.h" |
18 #include "webrtc/modules/video_coding/media_opt_util.h" | 18 #include "webrtc/modules/video_coding/media_opt_util.h" |
19 #include "webrtc/modules/video_coding/packet.h" | 19 #include "webrtc/modules/video_coding/packet.h" |
20 #include "webrtc/modules/video_coding/test/stream_generator.h" | 20 #include "webrtc/modules/video_coding/test/stream_generator.h" |
21 #include "webrtc/modules/video_coding/test/test_util.h" | 21 #include "webrtc/modules/video_coding/test/test_util.h" |
22 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
23 #include "webrtc/system_wrappers/include/metrics.h" | 23 #include "webrtc/system_wrappers/include/metrics.h" |
24 #include "webrtc/test/histogram.h" | 24 #include "webrtc/test/histogram.h" |
25 | 25 |
26 namespace webrtc { | 26 namespace webrtc { |
27 | 27 |
28 namespace { | 28 namespace { |
29 const uint32_t kProcessIntervalSec = 60; | 29 const uint32_t kProcessIntervalSec = 60; |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 class Vp9SsMapTest : public ::testing::Test { | 32 class Vp9SsMapTest : public ::testing::Test { |
33 protected: | 33 protected: |
34 Vp9SsMapTest() | 34 Vp9SsMapTest() : packet_(data_, 1400, 1234, 1, true) {} |
35 : packet_(data_, 1400, 1234, 1, true) {} | |
36 | 35 |
37 virtual void SetUp() { | 36 virtual void SetUp() { |
38 packet_.isFirstPacket = true; | 37 packet_.isFirstPacket = true; |
39 packet_.markerBit = true; | 38 packet_.markerBit = true; |
40 packet_.frameType = kVideoFrameKey; | 39 packet_.frameType = kVideoFrameKey; |
41 packet_.codec = kVideoCodecVP9; | 40 packet_.codec = kVideoCodecVP9; |
42 packet_.codecSpecificHeader.codec = kRtpVideoVp9; | 41 packet_.codecSpecificHeader.codec = kRtpVideoVp9; |
43 packet_.codecSpecificHeader.codecHeader.VP9.flexible_mode = false; | 42 packet_.codecSpecificHeader.codecHeader.VP9.flexible_mode = false; |
44 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 0; | 43 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 0; |
45 packet_.codecSpecificHeader.codecHeader.VP9.temporal_idx = kNoTemporalIdx; | 44 packet_.codecSpecificHeader.codecHeader.VP9.temporal_idx = kNoTemporalIdx; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 VCMEncodedFrame* DecodeIncompleteFrame() { | 226 VCMEncodedFrame* DecodeIncompleteFrame() { |
228 uint32_t timestamp = 0; | 227 uint32_t timestamp = 0; |
229 bool found_frame = jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp); | 228 bool found_frame = jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp); |
230 if (!found_frame) | 229 if (!found_frame) |
231 return NULL; | 230 return NULL; |
232 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(timestamp); | 231 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(timestamp); |
233 return frame; | 232 return frame; |
234 } | 233 } |
235 | 234 |
236 void CheckOutFrame(VCMEncodedFrame* frame_out, | 235 void CheckOutFrame(VCMEncodedFrame* frame_out, |
237 unsigned int size, | 236 unsigned int size, |
238 bool startCode) { | 237 bool startCode) { |
239 ASSERT_TRUE(frame_out); | 238 ASSERT_TRUE(frame_out); |
240 | 239 |
241 const uint8_t* outData = frame_out->Buffer(); | 240 const uint8_t* outData = frame_out->Buffer(); |
242 unsigned int i = 0; | 241 unsigned int i = 0; |
243 | 242 |
244 if (startCode) { | 243 if (startCode) { |
245 EXPECT_EQ(0, outData[0]); | 244 EXPECT_EQ(0, outData[0]); |
246 EXPECT_EQ(0, outData[1]); | 245 EXPECT_EQ(0, outData[1]); |
247 EXPECT_EQ(0, outData[2]); | 246 EXPECT_EQ(0, outData[2]); |
248 EXPECT_EQ(1, outData[3]); | 247 EXPECT_EQ(1, outData[3]); |
(...skipping 24 matching lines...) Expand all Loading... |
273 uint16_t seq_num_; | 272 uint16_t seq_num_; |
274 uint32_t timestamp_; | 273 uint32_t timestamp_; |
275 int size_; | 274 int size_; |
276 uint8_t data_[1500]; | 275 uint8_t data_[1500]; |
277 rtc::scoped_ptr<VCMPacket> packet_; | 276 rtc::scoped_ptr<VCMPacket> packet_; |
278 rtc::scoped_ptr<SimulatedClock> clock_; | 277 rtc::scoped_ptr<SimulatedClock> clock_; |
279 NullEventFactory event_factory_; | 278 NullEventFactory event_factory_; |
280 rtc::scoped_ptr<VCMJitterBuffer> jitter_buffer_; | 279 rtc::scoped_ptr<VCMJitterBuffer> jitter_buffer_; |
281 }; | 280 }; |
282 | 281 |
283 | |
284 class TestRunningJitterBuffer : public ::testing::Test { | 282 class TestRunningJitterBuffer : public ::testing::Test { |
285 protected: | 283 protected: |
286 enum { kDataBufferSize = 10 }; | 284 enum { kDataBufferSize = 10 }; |
287 | 285 |
288 virtual void SetUp() { | 286 virtual void SetUp() { |
289 clock_.reset(new SimulatedClock(0)); | 287 clock_.reset(new SimulatedClock(0)); |
290 max_nack_list_size_ = 150; | 288 max_nack_list_size_ = 150; |
291 oldest_packet_to_nack_ = 250; | 289 oldest_packet_to_nack_ = 250; |
292 jitter_buffer_ = new VCMJitterBuffer( | 290 jitter_buffer_ = new VCMJitterBuffer( |
293 clock_.get(), | 291 clock_.get(), |
294 rtc::scoped_ptr<EventWrapper>(event_factory_.CreateEvent())); | 292 rtc::scoped_ptr<EventWrapper>(event_factory_.CreateEvent())); |
295 stream_generator_ = new StreamGenerator(0, clock_->TimeInMilliseconds()); | 293 stream_generator_ = new StreamGenerator(0, clock_->TimeInMilliseconds()); |
296 jitter_buffer_->Start(); | 294 jitter_buffer_->Start(); |
297 jitter_buffer_->SetNackSettings(max_nack_list_size_, | 295 jitter_buffer_->SetNackSettings(max_nack_list_size_, oldest_packet_to_nack_, |
298 oldest_packet_to_nack_, 0); | 296 0); |
299 memset(data_buffer_, 0, kDataBufferSize); | 297 memset(data_buffer_, 0, kDataBufferSize); |
300 } | 298 } |
301 | 299 |
302 virtual void TearDown() { | 300 virtual void TearDown() { |
303 jitter_buffer_->Stop(); | 301 jitter_buffer_->Stop(); |
304 delete stream_generator_; | 302 delete stream_generator_; |
305 delete jitter_buffer_; | 303 delete jitter_buffer_; |
306 } | 304 } |
307 | 305 |
308 VCMFrameBufferEnum InsertPacketAndPop(int index) { | 306 VCMFrameBufferEnum InsertPacketAndPop(int index) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 uint8_t data_buffer_[kDataBufferSize]; | 387 uint8_t data_buffer_[kDataBufferSize]; |
390 }; | 388 }; |
391 | 389 |
392 class TestJitterBufferNack : public TestRunningJitterBuffer { | 390 class TestJitterBufferNack : public TestRunningJitterBuffer { |
393 protected: | 391 protected: |
394 virtual void SetUp() { | 392 virtual void SetUp() { |
395 TestRunningJitterBuffer::SetUp(); | 393 TestRunningJitterBuffer::SetUp(); |
396 jitter_buffer_->SetNackMode(kNack, -1, -1); | 394 jitter_buffer_->SetNackMode(kNack, -1, -1); |
397 } | 395 } |
398 | 396 |
399 virtual void TearDown() { | 397 virtual void TearDown() { TestRunningJitterBuffer::TearDown(); } |
400 TestRunningJitterBuffer::TearDown(); | |
401 } | |
402 }; | 398 }; |
403 | 399 |
404 TEST_F(TestBasicJitterBuffer, StopRunning) { | 400 TEST_F(TestBasicJitterBuffer, StopRunning) { |
405 jitter_buffer_->Stop(); | 401 jitter_buffer_->Stop(); |
406 EXPECT_TRUE(NULL == DecodeCompleteFrame()); | 402 EXPECT_TRUE(NULL == DecodeCompleteFrame()); |
407 EXPECT_TRUE(NULL == DecodeIncompleteFrame()); | 403 EXPECT_TRUE(NULL == DecodeIncompleteFrame()); |
408 jitter_buffer_->Start(); | 404 jitter_buffer_->Start(); |
409 // Allow selective errors. | 405 // Allow selective errors. |
410 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors); | 406 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors); |
411 | 407 |
(...skipping 12 matching lines...) Expand all Loading... |
424 TEST_F(TestBasicJitterBuffer, SinglePacketFrame) { | 420 TEST_F(TestBasicJitterBuffer, SinglePacketFrame) { |
425 // Always start with a complete key frame when not allowing errors. | 421 // Always start with a complete key frame when not allowing errors. |
426 jitter_buffer_->SetDecodeErrorMode(kNoErrors); | 422 jitter_buffer_->SetDecodeErrorMode(kNoErrors); |
427 packet_->frameType = kVideoFrameKey; | 423 packet_->frameType = kVideoFrameKey; |
428 packet_->isFirstPacket = true; | 424 packet_->isFirstPacket = true; |
429 packet_->markerBit = true; | 425 packet_->markerBit = true; |
430 packet_->timestamp += 123 * 90; | 426 packet_->timestamp += 123 * 90; |
431 | 427 |
432 // Insert the packet to the jitter buffer and get a frame. | 428 // Insert the packet to the jitter buffer and get a frame. |
433 bool retransmitted = false; | 429 bool retransmitted = false; |
434 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 430 EXPECT_EQ(kCompleteSession, |
435 &retransmitted)); | 431 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
436 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 432 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
437 CheckOutFrame(frame_out, size_, false); | 433 CheckOutFrame(frame_out, size_, false); |
438 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 434 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
439 jitter_buffer_->ReleaseFrame(frame_out); | 435 jitter_buffer_->ReleaseFrame(frame_out); |
440 } | 436 } |
441 | 437 |
442 TEST_F(TestBasicJitterBuffer, VerifyHistogramStats) { | 438 TEST_F(TestBasicJitterBuffer, VerifyHistogramStats) { |
443 test::ClearHistograms(); | 439 test::ClearHistograms(); |
444 // Always start with a complete key frame when not allowing errors. | 440 // Always start with a complete key frame when not allowing errors. |
445 jitter_buffer_->SetDecodeErrorMode(kNoErrors); | 441 jitter_buffer_->SetDecodeErrorMode(kNoErrors); |
446 packet_->frameType = kVideoFrameKey; | 442 packet_->frameType = kVideoFrameKey; |
447 packet_->isFirstPacket = true; | 443 packet_->isFirstPacket = true; |
448 packet_->markerBit = true; | 444 packet_->markerBit = true; |
449 packet_->timestamp += 123 * 90; | 445 packet_->timestamp += 123 * 90; |
450 | 446 |
451 // Insert single packet frame to the jitter buffer and get a frame. | 447 // Insert single packet frame to the jitter buffer and get a frame. |
452 bool retransmitted = false; | 448 bool retransmitted = false; |
453 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 449 EXPECT_EQ(kCompleteSession, |
454 &retransmitted)); | 450 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
455 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 451 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
456 CheckOutFrame(frame_out, size_, false); | 452 CheckOutFrame(frame_out, size_, false); |
457 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 453 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
458 jitter_buffer_->ReleaseFrame(frame_out); | 454 jitter_buffer_->ReleaseFrame(frame_out); |
459 | 455 |
460 // Verify that histograms are updated when the jitter buffer is stopped. | 456 // Verify that histograms are updated when the jitter buffer is stopped. |
461 clock_->AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); | 457 clock_->AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000); |
462 jitter_buffer_->Stop(); | 458 jitter_buffer_->Stop(); |
463 EXPECT_EQ(0, test::LastHistogramSample( | 459 EXPECT_EQ( |
464 "WebRTC.Video.DiscardedPacketsInPercent")); | 460 0, test::LastHistogramSample("WebRTC.Video.DiscardedPacketsInPercent")); |
465 EXPECT_EQ(0, test::LastHistogramSample( | 461 EXPECT_EQ( |
466 "WebRTC.Video.DuplicatedPacketsInPercent")); | 462 0, test::LastHistogramSample("WebRTC.Video.DuplicatedPacketsInPercent")); |
467 EXPECT_NE(-1, test::LastHistogramSample( | 463 EXPECT_NE(-1, test::LastHistogramSample( |
468 "WebRTC.Video.CompleteFramesReceivedPerSecond")); | 464 "WebRTC.Video.CompleteFramesReceivedPerSecond")); |
469 EXPECT_EQ(1000, test::LastHistogramSample( | 465 EXPECT_EQ(1000, test::LastHistogramSample( |
470 "WebRTC.Video.KeyFramesReceivedInPermille")); | 466 "WebRTC.Video.KeyFramesReceivedInPermille")); |
471 | 467 |
472 // Verify that histograms are not updated if stop is called again. | 468 // Verify that histograms are not updated if stop is called again. |
473 jitter_buffer_->Stop(); | 469 jitter_buffer_->Stop(); |
| 470 EXPECT_EQ( |
| 471 1, test::NumHistogramSamples("WebRTC.Video.DiscardedPacketsInPercent")); |
| 472 EXPECT_EQ( |
| 473 1, test::NumHistogramSamples("WebRTC.Video.DuplicatedPacketsInPercent")); |
474 EXPECT_EQ(1, test::NumHistogramSamples( | 474 EXPECT_EQ(1, test::NumHistogramSamples( |
475 "WebRTC.Video.DiscardedPacketsInPercent")); | 475 "WebRTC.Video.CompleteFramesReceivedPerSecond")); |
476 EXPECT_EQ(1, test::NumHistogramSamples( | 476 EXPECT_EQ( |
477 "WebRTC.Video.DuplicatedPacketsInPercent")); | 477 1, test::NumHistogramSamples("WebRTC.Video.KeyFramesReceivedInPermille")); |
478 EXPECT_EQ(1, test::NumHistogramSamples( | |
479 "WebRTC.Video.CompleteFramesReceivedPerSecond")); | |
480 EXPECT_EQ(1, test::NumHistogramSamples( | |
481 "WebRTC.Video.KeyFramesReceivedInPermille")); | |
482 } | 478 } |
483 | 479 |
484 TEST_F(TestBasicJitterBuffer, DualPacketFrame) { | 480 TEST_F(TestBasicJitterBuffer, DualPacketFrame) { |
485 packet_->frameType = kVideoFrameKey; | 481 packet_->frameType = kVideoFrameKey; |
486 packet_->isFirstPacket = true; | 482 packet_->isFirstPacket = true; |
487 packet_->markerBit = false; | 483 packet_->markerBit = false; |
488 | 484 |
489 bool retransmitted = false; | 485 bool retransmitted = false; |
490 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 486 EXPECT_EQ(kIncomplete, |
491 &retransmitted)); | 487 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
492 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 488 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
493 // Should not be complete. | 489 // Should not be complete. |
494 EXPECT_TRUE(frame_out == NULL); | 490 EXPECT_TRUE(frame_out == NULL); |
495 | 491 |
496 ++seq_num_; | 492 ++seq_num_; |
497 packet_->isFirstPacket = false; | 493 packet_->isFirstPacket = false; |
498 packet_->markerBit = true; | 494 packet_->markerBit = true; |
499 packet_->seqNum = seq_num_; | 495 packet_->seqNum = seq_num_; |
500 | 496 |
501 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 497 EXPECT_EQ(kCompleteSession, |
502 &retransmitted)); | 498 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
503 | 499 |
504 frame_out = DecodeCompleteFrame(); | 500 frame_out = DecodeCompleteFrame(); |
505 CheckOutFrame(frame_out, 2 * size_, false); | 501 CheckOutFrame(frame_out, 2 * size_, false); |
506 | 502 |
507 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 503 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
508 jitter_buffer_->ReleaseFrame(frame_out); | 504 jitter_buffer_->ReleaseFrame(frame_out); |
509 } | 505 } |
510 | 506 |
511 TEST_F(TestBasicJitterBuffer, 100PacketKeyFrame) { | 507 TEST_F(TestBasicJitterBuffer, 100PacketKeyFrame) { |
512 packet_->frameType = kVideoFrameKey; | 508 packet_->frameType = kVideoFrameKey; |
513 packet_->isFirstPacket = true; | 509 packet_->isFirstPacket = true; |
514 packet_->markerBit = false; | 510 packet_->markerBit = false; |
515 | 511 |
516 bool retransmitted = false; | 512 bool retransmitted = false; |
517 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 513 EXPECT_EQ(kIncomplete, |
518 &retransmitted)); | 514 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
519 | 515 |
520 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 516 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
521 | 517 |
522 // Frame should not be complete. | 518 // Frame should not be complete. |
523 EXPECT_TRUE(frame_out == NULL); | 519 EXPECT_TRUE(frame_out == NULL); |
524 | 520 |
525 // Insert 98 frames. | 521 // Insert 98 frames. |
526 int loop = 0; | 522 int loop = 0; |
527 do { | 523 do { |
528 seq_num_++; | 524 seq_num_++; |
529 packet_->isFirstPacket = false; | 525 packet_->isFirstPacket = false; |
530 packet_->markerBit = false; | 526 packet_->markerBit = false; |
531 packet_->seqNum = seq_num_; | 527 packet_->seqNum = seq_num_; |
532 | 528 |
533 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 529 EXPECT_EQ(kIncomplete, |
534 &retransmitted)); | 530 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
535 loop++; | 531 loop++; |
536 } while (loop < 98); | 532 } while (loop < 98); |
537 | 533 |
538 // Insert last packet. | 534 // Insert last packet. |
539 ++seq_num_; | 535 ++seq_num_; |
540 packet_->isFirstPacket = false; | 536 packet_->isFirstPacket = false; |
541 packet_->markerBit = true; | 537 packet_->markerBit = true; |
542 packet_->seqNum = seq_num_; | 538 packet_->seqNum = seq_num_; |
543 | 539 |
544 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 540 EXPECT_EQ(kCompleteSession, |
545 &retransmitted)); | 541 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
546 | 542 |
547 frame_out = DecodeCompleteFrame(); | 543 frame_out = DecodeCompleteFrame(); |
548 | 544 |
549 CheckOutFrame(frame_out, 100 * size_, false); | 545 CheckOutFrame(frame_out, 100 * size_, false); |
550 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 546 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
551 jitter_buffer_->ReleaseFrame(frame_out); | 547 jitter_buffer_->ReleaseFrame(frame_out); |
552 } | 548 } |
553 | 549 |
554 TEST_F(TestBasicJitterBuffer, 100PacketDeltaFrame) { | 550 TEST_F(TestBasicJitterBuffer, 100PacketDeltaFrame) { |
555 // Always start with a complete key frame. | 551 // Always start with a complete key frame. |
556 packet_->frameType = kVideoFrameKey; | 552 packet_->frameType = kVideoFrameKey; |
557 packet_->isFirstPacket = true; | 553 packet_->isFirstPacket = true; |
558 packet_->markerBit = true; | 554 packet_->markerBit = true; |
559 | 555 |
560 bool retransmitted = false; | 556 bool retransmitted = false; |
561 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 557 EXPECT_EQ(kCompleteSession, |
562 &retransmitted)); | 558 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
563 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 559 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
564 EXPECT_FALSE(frame_out == NULL); | 560 EXPECT_FALSE(frame_out == NULL); |
565 jitter_buffer_->ReleaseFrame(frame_out); | 561 jitter_buffer_->ReleaseFrame(frame_out); |
566 | 562 |
567 ++seq_num_; | 563 ++seq_num_; |
568 packet_->seqNum = seq_num_; | 564 packet_->seqNum = seq_num_; |
569 packet_->markerBit = false; | 565 packet_->markerBit = false; |
570 packet_->frameType = kVideoFrameDelta; | 566 packet_->frameType = kVideoFrameDelta; |
571 packet_->timestamp += 33 * 90; | 567 packet_->timestamp += 33 * 90; |
572 | 568 |
573 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 569 EXPECT_EQ(kIncomplete, |
574 &retransmitted)); | 570 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
575 | 571 |
576 frame_out = DecodeCompleteFrame(); | 572 frame_out = DecodeCompleteFrame(); |
577 | 573 |
578 // Frame should not be complete. | 574 // Frame should not be complete. |
579 EXPECT_TRUE(frame_out == NULL); | 575 EXPECT_TRUE(frame_out == NULL); |
580 | 576 |
581 packet_->isFirstPacket = false; | 577 packet_->isFirstPacket = false; |
582 // Insert 98 frames. | 578 // Insert 98 frames. |
583 int loop = 0; | 579 int loop = 0; |
584 do { | 580 do { |
585 ++seq_num_; | 581 ++seq_num_; |
586 packet_->seqNum = seq_num_; | 582 packet_->seqNum = seq_num_; |
587 | 583 |
588 // Insert a packet into a frame. | 584 // Insert a packet into a frame. |
589 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 585 EXPECT_EQ(kIncomplete, |
590 &retransmitted)); | 586 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
591 loop++; | 587 loop++; |
592 } while (loop < 98); | 588 } while (loop < 98); |
593 | 589 |
594 // Insert the last packet. | 590 // Insert the last packet. |
595 ++seq_num_; | 591 ++seq_num_; |
596 packet_->isFirstPacket = false; | 592 packet_->isFirstPacket = false; |
597 packet_->markerBit = true; | 593 packet_->markerBit = true; |
598 packet_->seqNum = seq_num_; | 594 packet_->seqNum = seq_num_; |
599 | 595 |
600 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 596 EXPECT_EQ(kCompleteSession, |
601 &retransmitted)); | 597 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
602 | 598 |
603 frame_out = DecodeCompleteFrame(); | 599 frame_out = DecodeCompleteFrame(); |
604 | 600 |
605 CheckOutFrame(frame_out, 100 * size_, false); | 601 CheckOutFrame(frame_out, 100 * size_, false); |
606 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); | 602 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); |
607 jitter_buffer_->ReleaseFrame(frame_out); | 603 jitter_buffer_->ReleaseFrame(frame_out); |
608 } | 604 } |
609 | 605 |
610 TEST_F(TestBasicJitterBuffer, PacketReorderingReverseOrder) { | 606 TEST_F(TestBasicJitterBuffer, PacketReorderingReverseOrder) { |
611 // Insert the "first" packet last. | 607 // Insert the "first" packet last. |
612 seq_num_ += 100; | 608 seq_num_ += 100; |
613 packet_->frameType = kVideoFrameKey; | 609 packet_->frameType = kVideoFrameKey; |
614 packet_->isFirstPacket = false; | 610 packet_->isFirstPacket = false; |
615 packet_->markerBit = true; | 611 packet_->markerBit = true; |
616 packet_->seqNum = seq_num_; | 612 packet_->seqNum = seq_num_; |
617 packet_->timestamp = timestamp_; | 613 packet_->timestamp = timestamp_; |
618 | 614 |
619 bool retransmitted = false; | 615 bool retransmitted = false; |
620 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 616 EXPECT_EQ(kIncomplete, |
621 &retransmitted)); | 617 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
622 | 618 |
623 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 619 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
624 | 620 |
625 EXPECT_TRUE(frame_out == NULL); | 621 EXPECT_TRUE(frame_out == NULL); |
626 | 622 |
627 // Insert 98 packets. | 623 // Insert 98 packets. |
628 int loop = 0; | 624 int loop = 0; |
629 do { | 625 do { |
630 seq_num_--; | 626 seq_num_--; |
631 packet_->isFirstPacket = false; | 627 packet_->isFirstPacket = false; |
632 packet_->markerBit = false; | 628 packet_->markerBit = false; |
633 packet_->seqNum = seq_num_; | 629 packet_->seqNum = seq_num_; |
634 | 630 |
635 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 631 EXPECT_EQ(kIncomplete, |
636 &retransmitted)); | 632 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
637 loop++; | 633 loop++; |
638 } while (loop < 98); | 634 } while (loop < 98); |
639 | 635 |
640 // Insert the last packet. | 636 // Insert the last packet. |
641 seq_num_--; | 637 seq_num_--; |
642 packet_->isFirstPacket = true; | 638 packet_->isFirstPacket = true; |
643 packet_->markerBit = false; | 639 packet_->markerBit = false; |
644 packet_->seqNum = seq_num_; | 640 packet_->seqNum = seq_num_; |
645 | 641 |
646 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 642 EXPECT_EQ(kCompleteSession, |
647 &retransmitted)); | 643 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
648 | 644 |
649 frame_out = DecodeCompleteFrame();; | 645 frame_out = DecodeCompleteFrame(); |
650 | 646 |
651 CheckOutFrame(frame_out, 100 * size_, false); | 647 CheckOutFrame(frame_out, 100 * size_, false); |
652 | 648 |
653 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 649 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
654 jitter_buffer_->ReleaseFrame(frame_out); | 650 jitter_buffer_->ReleaseFrame(frame_out); |
655 } | 651 } |
656 | 652 |
657 TEST_F(TestBasicJitterBuffer, FrameReordering2Frames2PacketsEach) { | 653 TEST_F(TestBasicJitterBuffer, FrameReordering2Frames2PacketsEach) { |
658 packet_->frameType = kVideoFrameDelta; | 654 packet_->frameType = kVideoFrameDelta; |
659 packet_->isFirstPacket = true; | 655 packet_->isFirstPacket = true; |
660 packet_->markerBit = false; | 656 packet_->markerBit = false; |
661 | 657 |
662 bool retransmitted = false; | 658 bool retransmitted = false; |
663 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 659 EXPECT_EQ(kIncomplete, |
664 &retransmitted)); | 660 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
665 | 661 |
666 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 662 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
667 | 663 |
668 EXPECT_TRUE(frame_out == NULL); | 664 EXPECT_TRUE(frame_out == NULL); |
669 | 665 |
670 seq_num_++; | 666 seq_num_++; |
671 packet_->isFirstPacket = false; | 667 packet_->isFirstPacket = false; |
672 packet_->markerBit = true; | 668 packet_->markerBit = true; |
673 packet_->seqNum = seq_num_; | 669 packet_->seqNum = seq_num_; |
674 | 670 |
675 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 671 EXPECT_EQ(kCompleteSession, |
676 &retransmitted)); | 672 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
677 | 673 |
678 // check that we fail to get frame since seqnum is not continuous | 674 // check that we fail to get frame since seqnum is not continuous |
679 frame_out = DecodeCompleteFrame(); | 675 frame_out = DecodeCompleteFrame(); |
680 EXPECT_TRUE(frame_out == NULL); | 676 EXPECT_TRUE(frame_out == NULL); |
681 | 677 |
682 seq_num_ -= 3; | 678 seq_num_ -= 3; |
683 timestamp_ -= 33*90; | 679 timestamp_ -= 33 * 90; |
684 packet_->frameType = kVideoFrameKey; | 680 packet_->frameType = kVideoFrameKey; |
685 packet_->isFirstPacket = true; | 681 packet_->isFirstPacket = true; |
686 packet_->markerBit = false; | 682 packet_->markerBit = false; |
687 packet_->seqNum = seq_num_; | 683 packet_->seqNum = seq_num_; |
688 packet_->timestamp = timestamp_; | 684 packet_->timestamp = timestamp_; |
689 | 685 |
690 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 686 EXPECT_EQ(kIncomplete, |
691 &retransmitted)); | 687 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
692 | 688 |
693 frame_out = DecodeCompleteFrame(); | 689 frame_out = DecodeCompleteFrame(); |
694 | 690 |
695 // It should not be complete. | 691 // It should not be complete. |
696 EXPECT_TRUE(frame_out == NULL); | 692 EXPECT_TRUE(frame_out == NULL); |
697 | 693 |
698 seq_num_++; | 694 seq_num_++; |
699 packet_->isFirstPacket = false; | 695 packet_->isFirstPacket = false; |
700 packet_->markerBit = true; | 696 packet_->markerBit = true; |
701 packet_->seqNum = seq_num_; | 697 packet_->seqNum = seq_num_; |
702 | 698 |
703 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 699 EXPECT_EQ(kCompleteSession, |
704 &retransmitted)); | 700 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
705 | 701 |
706 frame_out = DecodeCompleteFrame(); | 702 frame_out = DecodeCompleteFrame(); |
707 CheckOutFrame(frame_out, 2 * size_, false); | 703 CheckOutFrame(frame_out, 2 * size_, false); |
708 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 704 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
709 jitter_buffer_->ReleaseFrame(frame_out); | 705 jitter_buffer_->ReleaseFrame(frame_out); |
710 | 706 |
711 frame_out = DecodeCompleteFrame(); | 707 frame_out = DecodeCompleteFrame(); |
712 CheckOutFrame(frame_out, 2 * size_, false); | 708 CheckOutFrame(frame_out, 2 * size_, false); |
713 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); | 709 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); |
714 jitter_buffer_->ReleaseFrame(frame_out); | 710 jitter_buffer_->ReleaseFrame(frame_out); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 TEST_F(TestBasicJitterBuffer, DuplicatePackets) { | 770 TEST_F(TestBasicJitterBuffer, DuplicatePackets) { |
775 packet_->frameType = kVideoFrameKey; | 771 packet_->frameType = kVideoFrameKey; |
776 packet_->isFirstPacket = true; | 772 packet_->isFirstPacket = true; |
777 packet_->markerBit = false; | 773 packet_->markerBit = false; |
778 packet_->seqNum = seq_num_; | 774 packet_->seqNum = seq_num_; |
779 packet_->timestamp = timestamp_; | 775 packet_->timestamp = timestamp_; |
780 EXPECT_EQ(0, jitter_buffer_->num_packets()); | 776 EXPECT_EQ(0, jitter_buffer_->num_packets()); |
781 EXPECT_EQ(0, jitter_buffer_->num_duplicated_packets()); | 777 EXPECT_EQ(0, jitter_buffer_->num_duplicated_packets()); |
782 | 778 |
783 bool retransmitted = false; | 779 bool retransmitted = false; |
784 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 780 EXPECT_EQ(kIncomplete, |
785 &retransmitted)); | 781 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
786 | 782 |
787 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 783 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
788 | 784 |
789 EXPECT_TRUE(frame_out == NULL); | 785 EXPECT_TRUE(frame_out == NULL); |
790 EXPECT_EQ(1, jitter_buffer_->num_packets()); | 786 EXPECT_EQ(1, jitter_buffer_->num_packets()); |
791 EXPECT_EQ(0, jitter_buffer_->num_duplicated_packets()); | 787 EXPECT_EQ(0, jitter_buffer_->num_duplicated_packets()); |
792 | 788 |
793 // Insert a packet into a frame. | 789 // Insert a packet into a frame. |
794 EXPECT_EQ(kDuplicatePacket, jitter_buffer_->InsertPacket(*packet_, | 790 EXPECT_EQ(kDuplicatePacket, |
795 &retransmitted)); | 791 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
796 EXPECT_EQ(2, jitter_buffer_->num_packets()); | 792 EXPECT_EQ(2, jitter_buffer_->num_packets()); |
797 EXPECT_EQ(1, jitter_buffer_->num_duplicated_packets()); | 793 EXPECT_EQ(1, jitter_buffer_->num_duplicated_packets()); |
798 | 794 |
799 seq_num_++; | 795 seq_num_++; |
800 packet_->seqNum = seq_num_; | 796 packet_->seqNum = seq_num_; |
801 packet_->markerBit = true; | 797 packet_->markerBit = true; |
802 packet_->isFirstPacket = false; | 798 packet_->isFirstPacket = false; |
803 | 799 |
804 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 800 EXPECT_EQ(kCompleteSession, |
805 &retransmitted)); | 801 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
806 | 802 |
807 frame_out = DecodeCompleteFrame(); | 803 frame_out = DecodeCompleteFrame(); |
808 ASSERT_TRUE(frame_out != NULL); | 804 ASSERT_TRUE(frame_out != NULL); |
809 CheckOutFrame(frame_out, 2 * size_, false); | 805 CheckOutFrame(frame_out, 2 * size_, false); |
810 | 806 |
811 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 807 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
812 EXPECT_EQ(3, jitter_buffer_->num_packets()); | 808 EXPECT_EQ(3, jitter_buffer_->num_packets()); |
813 EXPECT_EQ(1, jitter_buffer_->num_duplicated_packets()); | 809 EXPECT_EQ(1, jitter_buffer_->num_duplicated_packets()); |
814 jitter_buffer_->ReleaseFrame(frame_out); | 810 jitter_buffer_->ReleaseFrame(frame_out); |
815 } | 811 } |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 | 1075 |
1080 TEST_F(TestBasicJitterBuffer, H264InsertStartCode) { | 1076 TEST_F(TestBasicJitterBuffer, H264InsertStartCode) { |
1081 packet_->frameType = kVideoFrameKey; | 1077 packet_->frameType = kVideoFrameKey; |
1082 packet_->isFirstPacket = true; | 1078 packet_->isFirstPacket = true; |
1083 packet_->markerBit = false; | 1079 packet_->markerBit = false; |
1084 packet_->seqNum = seq_num_; | 1080 packet_->seqNum = seq_num_; |
1085 packet_->timestamp = timestamp_; | 1081 packet_->timestamp = timestamp_; |
1086 packet_->insertStartCode = true; | 1082 packet_->insertStartCode = true; |
1087 | 1083 |
1088 bool retransmitted = false; | 1084 bool retransmitted = false; |
1089 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1085 EXPECT_EQ(kIncomplete, |
1090 &retransmitted)); | 1086 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1091 | 1087 |
1092 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1088 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1093 | 1089 |
1094 // Frame should not be complete. | 1090 // Frame should not be complete. |
1095 EXPECT_TRUE(frame_out == NULL); | 1091 EXPECT_TRUE(frame_out == NULL); |
1096 | 1092 |
1097 seq_num_++; | 1093 seq_num_++; |
1098 packet_->isFirstPacket = false; | 1094 packet_->isFirstPacket = false; |
1099 packet_->markerBit = true; | 1095 packet_->markerBit = true; |
1100 packet_->seqNum = seq_num_; | 1096 packet_->seqNum = seq_num_; |
1101 | 1097 |
1102 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1098 EXPECT_EQ(kCompleteSession, |
1103 &retransmitted)); | 1099 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1104 | 1100 |
1105 frame_out = DecodeCompleteFrame(); | 1101 frame_out = DecodeCompleteFrame(); |
1106 CheckOutFrame(frame_out, size_ * 2 + 4 * 2, true); | 1102 CheckOutFrame(frame_out, size_ * 2 + 4 * 2, true); |
1107 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1103 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1108 jitter_buffer_->ReleaseFrame(frame_out); | 1104 jitter_buffer_->ReleaseFrame(frame_out); |
1109 } | 1105 } |
1110 | 1106 |
1111 // Test threshold conditions of decodable state. | 1107 // Test threshold conditions of decodable state. |
1112 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsThresholdCheck) { | 1108 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsThresholdCheck) { |
1113 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors); | 1109 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors); |
1114 // Always start with a key frame. Use 10 packets to test Decodable State | 1110 // Always start with a key frame. Use 10 packets to test Decodable State |
1115 // boundaries. | 1111 // boundaries. |
1116 packet_->frameType = kVideoFrameKey; | 1112 packet_->frameType = kVideoFrameKey; |
1117 packet_->isFirstPacket = true; | 1113 packet_->isFirstPacket = true; |
1118 packet_->markerBit = false; | 1114 packet_->markerBit = false; |
1119 packet_->seqNum = seq_num_; | 1115 packet_->seqNum = seq_num_; |
1120 packet_->timestamp = timestamp_; | 1116 packet_->timestamp = timestamp_; |
1121 | 1117 |
1122 bool retransmitted = false; | 1118 bool retransmitted = false; |
1123 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1119 EXPECT_EQ(kIncomplete, |
1124 &retransmitted)); | 1120 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1125 uint32_t timestamp = 0; | 1121 uint32_t timestamp = 0; |
1126 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1122 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1127 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1123 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1128 | 1124 |
1129 packet_->isFirstPacket = false; | 1125 packet_->isFirstPacket = false; |
1130 for (int i = 1; i < 9; ++i) { | 1126 for (int i = 1; i < 9; ++i) { |
1131 packet_->seqNum++; | 1127 packet_->seqNum++; |
1132 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1128 EXPECT_EQ(kIncomplete, |
1133 &retransmitted)); | 1129 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1134 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1130 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1135 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1131 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1136 } | 1132 } |
1137 | 1133 |
1138 // last packet | 1134 // last packet |
1139 packet_->markerBit = true; | 1135 packet_->markerBit = true; |
1140 packet_->seqNum++; | 1136 packet_->seqNum++; |
1141 | 1137 |
1142 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1138 EXPECT_EQ(kCompleteSession, |
1143 &retransmitted)); | 1139 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1144 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1140 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1145 CheckOutFrame(frame_out, 10 * size_, false); | 1141 CheckOutFrame(frame_out, 10 * size_, false); |
1146 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1142 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1147 jitter_buffer_->ReleaseFrame(frame_out); | 1143 jitter_buffer_->ReleaseFrame(frame_out); |
1148 | 1144 |
1149 // An incomplete frame can only be decoded once a subsequent frame has begun | 1145 // An incomplete frame can only be decoded once a subsequent frame has begun |
1150 // to arrive. Insert packet in distant frame for this purpose. | 1146 // to arrive. Insert packet in distant frame for this purpose. |
1151 packet_->frameType = kVideoFrameDelta; | 1147 packet_->frameType = kVideoFrameDelta; |
1152 packet_->isFirstPacket = true; | 1148 packet_->isFirstPacket = true; |
1153 packet_->markerBit = false; | 1149 packet_->markerBit = false; |
1154 packet_->seqNum += 100; | 1150 packet_->seqNum += 100; |
1155 packet_->timestamp += 33 * 90 * 8; | 1151 packet_->timestamp += 33 * 90 * 8; |
1156 | 1152 |
1157 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1153 EXPECT_EQ(kDecodableSession, |
1158 &retransmitted)); | 1154 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1159 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1155 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1160 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1156 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1161 | 1157 |
1162 // Insert second frame | 1158 // Insert second frame |
1163 packet_->seqNum -= 99; | 1159 packet_->seqNum -= 99; |
1164 packet_->timestamp -= 33 * 90 * 7; | 1160 packet_->timestamp -= 33 * 90 * 7; |
1165 | 1161 |
1166 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1162 EXPECT_EQ(kDecodableSession, |
1167 &retransmitted)); | 1163 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1168 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1164 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1169 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1165 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1170 | 1166 |
1171 packet_->isFirstPacket = false; | 1167 packet_->isFirstPacket = false; |
1172 for (int i = 1; i < 8; ++i) { | 1168 for (int i = 1; i < 8; ++i) { |
1173 packet_->seqNum++; | 1169 packet_->seqNum++; |
1174 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1170 EXPECT_EQ(kDecodableSession, |
1175 &retransmitted)); | 1171 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1176 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1172 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1177 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1173 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1178 } | 1174 } |
1179 | 1175 |
1180 packet_->seqNum++; | 1176 packet_->seqNum++; |
1181 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1177 EXPECT_EQ(kDecodableSession, |
1182 &retransmitted)); | 1178 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1183 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1179 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1184 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1180 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1185 | 1181 |
1186 frame_out = DecodeIncompleteFrame(); | 1182 frame_out = DecodeIncompleteFrame(); |
1187 ASSERT_FALSE(NULL == frame_out); | 1183 ASSERT_FALSE(NULL == frame_out); |
1188 CheckOutFrame(frame_out, 9 * size_, false); | 1184 CheckOutFrame(frame_out, 9 * size_, false); |
1189 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); | 1185 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); |
1190 jitter_buffer_->ReleaseFrame(frame_out); | 1186 jitter_buffer_->ReleaseFrame(frame_out); |
1191 | 1187 |
1192 packet_->markerBit = true; | 1188 packet_->markerBit = true; |
1193 packet_->seqNum++; | 1189 packet_->seqNum++; |
1194 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, | 1190 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1195 &retransmitted)); | |
1196 } | 1191 } |
1197 | 1192 |
1198 // Make sure first packet is present before a frame can be decoded. | 1193 // Make sure first packet is present before a frame can be decoded. |
1199 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsIncompleteKey) { | 1194 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsIncompleteKey) { |
1200 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors); | 1195 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors); |
1201 // Always start with a key frame. | 1196 // Always start with a key frame. |
1202 packet_->frameType = kVideoFrameKey; | 1197 packet_->frameType = kVideoFrameKey; |
1203 packet_->isFirstPacket = true; | 1198 packet_->isFirstPacket = true; |
1204 packet_->markerBit = true; | 1199 packet_->markerBit = true; |
1205 packet_->seqNum = seq_num_; | 1200 packet_->seqNum = seq_num_; |
1206 packet_->timestamp = timestamp_; | 1201 packet_->timestamp = timestamp_; |
1207 | 1202 |
1208 bool retransmitted = false; | 1203 bool retransmitted = false; |
1209 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1204 EXPECT_EQ(kCompleteSession, |
1210 &retransmitted)); | 1205 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1211 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1206 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1212 CheckOutFrame(frame_out, size_, false); | 1207 CheckOutFrame(frame_out, size_, false); |
1213 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1208 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1214 jitter_buffer_->ReleaseFrame(frame_out); | 1209 jitter_buffer_->ReleaseFrame(frame_out); |
1215 | 1210 |
1216 // An incomplete frame can only be decoded once a subsequent frame has begun | 1211 // An incomplete frame can only be decoded once a subsequent frame has begun |
1217 // to arrive. Insert packet in distant frame for this purpose. | 1212 // to arrive. Insert packet in distant frame for this purpose. |
1218 packet_->frameType = kVideoFrameDelta; | 1213 packet_->frameType = kVideoFrameDelta; |
1219 packet_->isFirstPacket = false; | 1214 packet_->isFirstPacket = false; |
1220 packet_->markerBit = false; | 1215 packet_->markerBit = false; |
1221 packet_->seqNum += 100; | 1216 packet_->seqNum += 100; |
1222 packet_->timestamp += 33*90*8; | 1217 packet_->timestamp += 33 * 90 * 8; |
1223 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1218 EXPECT_EQ(kIncomplete, |
1224 &retransmitted)); | 1219 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1225 uint32_t timestamp; | 1220 uint32_t timestamp; |
1226 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1221 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1227 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1222 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1228 | 1223 |
1229 // Insert second frame - an incomplete key frame. | 1224 // Insert second frame - an incomplete key frame. |
1230 packet_->frameType = kVideoFrameKey; | 1225 packet_->frameType = kVideoFrameKey; |
1231 packet_->isFirstPacket = true; | 1226 packet_->isFirstPacket = true; |
1232 packet_->seqNum -= 99; | 1227 packet_->seqNum -= 99; |
1233 packet_->timestamp -= 33*90*7; | 1228 packet_->timestamp -= 33 * 90 * 7; |
1234 | 1229 |
1235 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1230 EXPECT_EQ(kIncomplete, |
1236 &retransmitted)); | 1231 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1237 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1232 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1238 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1233 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1239 | 1234 |
1240 // Insert a few more packets. Make sure we're waiting for the key frame to be | 1235 // Insert a few more packets. Make sure we're waiting for the key frame to be |
1241 // complete. | 1236 // complete. |
1242 packet_->isFirstPacket = false; | 1237 packet_->isFirstPacket = false; |
1243 for (int i = 1; i < 5; ++i) { | 1238 for (int i = 1; i < 5; ++i) { |
1244 packet_->seqNum++; | 1239 packet_->seqNum++; |
1245 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1240 EXPECT_EQ(kIncomplete, |
1246 &retransmitted)); | 1241 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1247 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1242 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1248 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1243 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1249 } | 1244 } |
1250 | 1245 |
1251 // Complete key frame. | 1246 // Complete key frame. |
1252 packet_->markerBit = true; | 1247 packet_->markerBit = true; |
1253 packet_->seqNum++; | 1248 packet_->seqNum++; |
1254 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1249 EXPECT_EQ(kCompleteSession, |
1255 &retransmitted)); | 1250 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1256 frame_out = DecodeCompleteFrame(); | 1251 frame_out = DecodeCompleteFrame(); |
1257 CheckOutFrame(frame_out, 6 * size_, false); | 1252 CheckOutFrame(frame_out, 6 * size_, false); |
1258 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1253 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1259 jitter_buffer_->ReleaseFrame(frame_out); | 1254 jitter_buffer_->ReleaseFrame(frame_out); |
1260 } | 1255 } |
1261 | 1256 |
1262 // Make sure first packet is present before a frame can be decoded. | 1257 // Make sure first packet is present before a frame can be decoded. |
1263 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsMissingFirstPacket) { | 1258 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsMissingFirstPacket) { |
1264 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors); | 1259 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors); |
1265 // Always start with a key frame. | 1260 // Always start with a key frame. |
1266 packet_->frameType = kVideoFrameKey; | 1261 packet_->frameType = kVideoFrameKey; |
1267 packet_->isFirstPacket = true; | 1262 packet_->isFirstPacket = true; |
1268 packet_->markerBit = true; | 1263 packet_->markerBit = true; |
1269 packet_->seqNum = seq_num_; | 1264 packet_->seqNum = seq_num_; |
1270 packet_->timestamp = timestamp_; | 1265 packet_->timestamp = timestamp_; |
1271 | 1266 |
1272 bool retransmitted = false; | 1267 bool retransmitted = false; |
1273 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1268 EXPECT_EQ(kCompleteSession, |
1274 &retransmitted)); | 1269 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1275 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1270 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1276 CheckOutFrame(frame_out, size_, false); | 1271 CheckOutFrame(frame_out, size_, false); |
1277 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1272 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1278 jitter_buffer_->ReleaseFrame(frame_out); | 1273 jitter_buffer_->ReleaseFrame(frame_out); |
1279 | 1274 |
1280 // An incomplete frame can only be decoded once a subsequent frame has begun | 1275 // An incomplete frame can only be decoded once a subsequent frame has begun |
1281 // to arrive. Insert packet in distant frame for this purpose. | 1276 // to arrive. Insert packet in distant frame for this purpose. |
1282 packet_->frameType = kVideoFrameDelta; | 1277 packet_->frameType = kVideoFrameDelta; |
1283 packet_->isFirstPacket = false; | 1278 packet_->isFirstPacket = false; |
1284 packet_->markerBit = false; | 1279 packet_->markerBit = false; |
1285 packet_->seqNum += 100; | 1280 packet_->seqNum += 100; |
1286 packet_->timestamp += 33*90*8; | 1281 packet_->timestamp += 33 * 90 * 8; |
1287 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1282 EXPECT_EQ(kIncomplete, |
1288 &retransmitted)); | 1283 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1289 uint32_t timestamp; | 1284 uint32_t timestamp; |
1290 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1285 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1291 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1286 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1292 | 1287 |
1293 // Insert second frame with the first packet missing. Make sure we're waiting | 1288 // Insert second frame with the first packet missing. Make sure we're waiting |
1294 // for the key frame to be complete. | 1289 // for the key frame to be complete. |
1295 packet_->seqNum -= 98; | 1290 packet_->seqNum -= 98; |
1296 packet_->timestamp -= 33*90*7; | 1291 packet_->timestamp -= 33 * 90 * 7; |
1297 | 1292 |
1298 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1293 EXPECT_EQ(kIncomplete, |
1299 &retransmitted)); | 1294 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1300 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1295 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1301 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1296 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1302 | 1297 |
1303 for (int i = 0; i < 5; ++i) { | 1298 for (int i = 0; i < 5; ++i) { |
1304 packet_->seqNum++; | 1299 packet_->seqNum++; |
1305 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1300 EXPECT_EQ(kIncomplete, |
1306 &retransmitted)); | 1301 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1307 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1302 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1308 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1303 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1309 } | 1304 } |
1310 | 1305 |
1311 // Add first packet. Frame should now be decodable, but incomplete. | 1306 // Add first packet. Frame should now be decodable, but incomplete. |
1312 packet_->isFirstPacket = true; | 1307 packet_->isFirstPacket = true; |
1313 packet_->seqNum -= 6; | 1308 packet_->seqNum -= 6; |
1314 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1309 EXPECT_EQ(kDecodableSession, |
1315 &retransmitted)); | 1310 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1316 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); | 1311 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, ×tamp)); |
1317 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); | 1312 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(×tamp)); |
1318 | 1313 |
1319 frame_out = DecodeIncompleteFrame(); | 1314 frame_out = DecodeIncompleteFrame(); |
1320 CheckOutFrame(frame_out, 7 * size_, false); | 1315 CheckOutFrame(frame_out, 7 * size_, false); |
1321 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); | 1316 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); |
1322 jitter_buffer_->ReleaseFrame(frame_out); | 1317 jitter_buffer_->ReleaseFrame(frame_out); |
1323 } | 1318 } |
1324 | 1319 |
1325 TEST_F(TestBasicJitterBuffer, DiscontinuousStreamWhenDecodingWithErrors) { | 1320 TEST_F(TestBasicJitterBuffer, DiscontinuousStreamWhenDecodingWithErrors) { |
1326 // Will use one packet per frame. | 1321 // Will use one packet per frame. |
1327 jitter_buffer_->SetDecodeErrorMode(kWithErrors); | 1322 jitter_buffer_->SetDecodeErrorMode(kWithErrors); |
1328 packet_->frameType = kVideoFrameKey; | 1323 packet_->frameType = kVideoFrameKey; |
1329 packet_->isFirstPacket = true; | 1324 packet_->isFirstPacket = true; |
1330 packet_->markerBit = true; | 1325 packet_->markerBit = true; |
1331 packet_->seqNum = seq_num_; | 1326 packet_->seqNum = seq_num_; |
1332 packet_->timestamp = timestamp_; | 1327 packet_->timestamp = timestamp_; |
1333 bool retransmitted = false; | 1328 bool retransmitted = false; |
1334 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1329 EXPECT_EQ(kCompleteSession, |
1335 &retransmitted)); | 1330 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1336 uint32_t next_timestamp; | 1331 uint32_t next_timestamp; |
1337 EXPECT_TRUE(jitter_buffer_->NextCompleteTimestamp(0, &next_timestamp)); | 1332 EXPECT_TRUE(jitter_buffer_->NextCompleteTimestamp(0, &next_timestamp)); |
1338 EXPECT_EQ(packet_->timestamp, next_timestamp); | 1333 EXPECT_EQ(packet_->timestamp, next_timestamp); |
1339 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(next_timestamp); | 1334 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(next_timestamp); |
1340 EXPECT_TRUE(frame != NULL); | 1335 EXPECT_TRUE(frame != NULL); |
1341 jitter_buffer_->ReleaseFrame(frame); | 1336 jitter_buffer_->ReleaseFrame(frame); |
1342 | 1337 |
1343 // Drop a complete frame. | 1338 // Drop a complete frame. |
1344 timestamp_ += 2 * 33 * 90; | 1339 timestamp_ += 2 * 33 * 90; |
1345 seq_num_ += 2; | 1340 seq_num_ += 2; |
1346 packet_->frameType = kVideoFrameDelta; | 1341 packet_->frameType = kVideoFrameDelta; |
1347 packet_->isFirstPacket = true; | 1342 packet_->isFirstPacket = true; |
1348 packet_->markerBit = false; | 1343 packet_->markerBit = false; |
1349 packet_->seqNum = seq_num_; | 1344 packet_->seqNum = seq_num_; |
1350 packet_->timestamp = timestamp_; | 1345 packet_->timestamp = timestamp_; |
1351 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1346 EXPECT_EQ(kDecodableSession, |
1352 &retransmitted)); | 1347 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1353 // Insert a packet (so the previous one will be released). | 1348 // Insert a packet (so the previous one will be released). |
1354 timestamp_ += 33 * 90; | 1349 timestamp_ += 33 * 90; |
1355 seq_num_ += 2; | 1350 seq_num_ += 2; |
1356 packet_->frameType = kVideoFrameDelta; | 1351 packet_->frameType = kVideoFrameDelta; |
1357 packet_->isFirstPacket = true; | 1352 packet_->isFirstPacket = true; |
1358 packet_->markerBit = false; | 1353 packet_->markerBit = false; |
1359 packet_->seqNum = seq_num_; | 1354 packet_->seqNum = seq_num_; |
1360 packet_->timestamp = timestamp_; | 1355 packet_->timestamp = timestamp_; |
1361 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1356 EXPECT_EQ(kDecodableSession, |
1362 &retransmitted)); | 1357 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1363 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &next_timestamp)); | 1358 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &next_timestamp)); |
1364 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(&next_timestamp)); | 1359 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(&next_timestamp)); |
1365 EXPECT_EQ(packet_->timestamp - 33 * 90, next_timestamp); | 1360 EXPECT_EQ(packet_->timestamp - 33 * 90, next_timestamp); |
1366 } | 1361 } |
1367 | 1362 |
1368 TEST_F(TestBasicJitterBuffer, PacketLoss) { | 1363 TEST_F(TestBasicJitterBuffer, PacketLoss) { |
1369 // Verify missing packets statistics and not decodable packets statistics. | 1364 // Verify missing packets statistics and not decodable packets statistics. |
1370 // Insert 10 frames consisting of 4 packets and remove one from all of them. | 1365 // Insert 10 frames consisting of 4 packets and remove one from all of them. |
1371 // The last packet is an empty (non-media) packet. | 1366 // The last packet is an empty (non-media) packet. |
1372 | 1367 |
1373 // Select a start seqNum which triggers a difficult wrap situation | 1368 // Select a start seqNum which triggers a difficult wrap situation |
1374 // The JB will only output (incomplete)frames if the next one has started | 1369 // The JB will only output (incomplete)frames if the next one has started |
1375 // to arrive. Start by inserting one frame (key). | 1370 // to arrive. Start by inserting one frame (key). |
1376 jitter_buffer_->SetDecodeErrorMode(kWithErrors); | 1371 jitter_buffer_->SetDecodeErrorMode(kWithErrors); |
1377 seq_num_ = 0xffff - 4; | 1372 seq_num_ = 0xffff - 4; |
1378 seq_num_++; | 1373 seq_num_++; |
1379 packet_->frameType = kVideoFrameKey; | 1374 packet_->frameType = kVideoFrameKey; |
1380 packet_->isFirstPacket = true; | 1375 packet_->isFirstPacket = true; |
1381 packet_->markerBit = false; | 1376 packet_->markerBit = false; |
1382 packet_->seqNum = seq_num_; | 1377 packet_->seqNum = seq_num_; |
1383 packet_->timestamp = timestamp_; | 1378 packet_->timestamp = timestamp_; |
1384 packet_->completeNALU = kNaluStart; | 1379 packet_->completeNALU = kNaluStart; |
1385 | 1380 |
1386 bool retransmitted = false; | 1381 bool retransmitted = false; |
1387 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1382 EXPECT_EQ(kDecodableSession, |
1388 &retransmitted)); | 1383 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1389 for (int i = 0; i < 11; ++i) { | 1384 for (int i = 0; i < 11; ++i) { |
1390 webrtc::FrameType frametype = kVideoFrameDelta; | 1385 webrtc::FrameType frametype = kVideoFrameDelta; |
1391 seq_num_++; | 1386 seq_num_++; |
1392 timestamp_ += 33*90; | 1387 timestamp_ += 33 * 90; |
1393 packet_->frameType = frametype; | 1388 packet_->frameType = frametype; |
1394 packet_->isFirstPacket = true; | 1389 packet_->isFirstPacket = true; |
1395 packet_->markerBit = false; | 1390 packet_->markerBit = false; |
1396 packet_->seqNum = seq_num_; | 1391 packet_->seqNum = seq_num_; |
1397 packet_->timestamp = timestamp_; | 1392 packet_->timestamp = timestamp_; |
1398 packet_->completeNALU = kNaluStart; | 1393 packet_->completeNALU = kNaluStart; |
1399 | 1394 |
1400 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1395 EXPECT_EQ(kDecodableSession, |
1401 &retransmitted)); | 1396 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1402 | 1397 |
1403 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1398 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1404 | 1399 |
1405 // Should not be complete. | 1400 // Should not be complete. |
1406 EXPECT_TRUE(frame_out == NULL); | 1401 EXPECT_TRUE(frame_out == NULL); |
1407 | 1402 |
1408 seq_num_ += 2; | 1403 seq_num_ += 2; |
1409 packet_->isFirstPacket = false; | 1404 packet_->isFirstPacket = false; |
1410 packet_->markerBit = true; | 1405 packet_->markerBit = true; |
1411 packet_->seqNum = seq_num_; | 1406 packet_->seqNum = seq_num_; |
(...skipping 13 matching lines...) Expand all Loading... |
1425 EXPECT_EQ(jitter_buffer_->InsertPacket(*packet_, &retransmitted), | 1420 EXPECT_EQ(jitter_buffer_->InsertPacket(*packet_, &retransmitted), |
1426 kDecodableSession); | 1421 kDecodableSession); |
1427 frame_out = DecodeIncompleteFrame(); | 1422 frame_out = DecodeIncompleteFrame(); |
1428 | 1423 |
1429 // One of the packets has been discarded by the jitter buffer. | 1424 // One of the packets has been discarded by the jitter buffer. |
1430 // Last frame can't be extracted yet. | 1425 // Last frame can't be extracted yet. |
1431 if (i < 10) { | 1426 if (i < 10) { |
1432 CheckOutFrame(frame_out, size_, false); | 1427 CheckOutFrame(frame_out, size_, false); |
1433 | 1428 |
1434 if (i == 0) { | 1429 if (i == 0) { |
1435 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1430 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1436 } else { | 1431 } else { |
1437 EXPECT_EQ(frametype, frame_out->FrameType()); | 1432 EXPECT_EQ(frametype, frame_out->FrameType()); |
1438 } | 1433 } |
1439 EXPECT_FALSE(frame_out->Complete()); | 1434 EXPECT_FALSE(frame_out->Complete()); |
1440 EXPECT_FALSE(frame_out->MissingFrame()); | 1435 EXPECT_FALSE(frame_out->MissingFrame()); |
1441 } | 1436 } |
1442 | 1437 |
1443 jitter_buffer_->ReleaseFrame(frame_out); | 1438 jitter_buffer_->ReleaseFrame(frame_out); |
1444 } | 1439 } |
1445 | 1440 |
1446 // Insert 3 old packets and verify that we have 3 discarded packets | 1441 // Insert 3 old packets and verify that we have 3 discarded packets |
1447 // Match value to actual latest timestamp decoded. | 1442 // Match value to actual latest timestamp decoded. |
1448 timestamp_ -= 33 * 90; | 1443 timestamp_ -= 33 * 90; |
1449 packet_->timestamp = timestamp_ - 1000; | 1444 packet_->timestamp = timestamp_ - 1000; |
1450 | 1445 |
1451 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, | 1446 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1452 &retransmitted)); | |
1453 | 1447 |
1454 packet_->timestamp = timestamp_ - 500; | 1448 packet_->timestamp = timestamp_ - 500; |
1455 | 1449 |
1456 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, | 1450 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1457 &retransmitted)); | |
1458 | 1451 |
1459 packet_->timestamp = timestamp_ - 100; | 1452 packet_->timestamp = timestamp_ - 100; |
1460 | 1453 |
1461 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, | 1454 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1462 &retransmitted)); | |
1463 | 1455 |
1464 EXPECT_EQ(3, jitter_buffer_->num_discarded_packets()); | 1456 EXPECT_EQ(3, jitter_buffer_->num_discarded_packets()); |
1465 | 1457 |
1466 jitter_buffer_->Flush(); | 1458 jitter_buffer_->Flush(); |
1467 | 1459 |
1468 // This statistic shouldn't be reset by a flush. | 1460 // This statistic shouldn't be reset by a flush. |
1469 EXPECT_EQ(3, jitter_buffer_->num_discarded_packets()); | 1461 EXPECT_EQ(3, jitter_buffer_->num_discarded_packets()); |
1470 } | 1462 } |
1471 | 1463 |
1472 TEST_F(TestBasicJitterBuffer, DeltaFrame100PacketsWithSeqNumWrap) { | 1464 TEST_F(TestBasicJitterBuffer, DeltaFrame100PacketsWithSeqNumWrap) { |
1473 seq_num_ = 0xfff0; | 1465 seq_num_ = 0xfff0; |
1474 packet_->frameType = kVideoFrameKey; | 1466 packet_->frameType = kVideoFrameKey; |
1475 packet_->isFirstPacket = true; | 1467 packet_->isFirstPacket = true; |
1476 packet_->markerBit = false; | 1468 packet_->markerBit = false; |
1477 packet_->seqNum = seq_num_; | 1469 packet_->seqNum = seq_num_; |
1478 packet_->timestamp = timestamp_; | 1470 packet_->timestamp = timestamp_; |
1479 | 1471 |
1480 bool retransmitted = false; | 1472 bool retransmitted = false; |
1481 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1473 EXPECT_EQ(kIncomplete, |
1482 &retransmitted)); | 1474 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1483 | 1475 |
1484 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1476 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1485 | 1477 |
1486 EXPECT_TRUE(frame_out == NULL); | 1478 EXPECT_TRUE(frame_out == NULL); |
1487 | 1479 |
1488 int loop = 0; | 1480 int loop = 0; |
1489 do { | 1481 do { |
1490 seq_num_++; | 1482 seq_num_++; |
1491 packet_->isFirstPacket = false; | 1483 packet_->isFirstPacket = false; |
1492 packet_->markerBit = false; | 1484 packet_->markerBit = false; |
1493 packet_->seqNum = seq_num_; | 1485 packet_->seqNum = seq_num_; |
1494 | 1486 |
1495 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1487 EXPECT_EQ(kIncomplete, |
1496 &retransmitted)); | 1488 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1497 | 1489 |
1498 frame_out = DecodeCompleteFrame(); | 1490 frame_out = DecodeCompleteFrame(); |
1499 | 1491 |
1500 EXPECT_TRUE(frame_out == NULL); | 1492 EXPECT_TRUE(frame_out == NULL); |
1501 | 1493 |
1502 loop++; | 1494 loop++; |
1503 } while (loop < 98); | 1495 } while (loop < 98); |
1504 | 1496 |
1505 seq_num_++; | 1497 seq_num_++; |
1506 packet_->isFirstPacket = false; | 1498 packet_->isFirstPacket = false; |
1507 packet_->markerBit = true; | 1499 packet_->markerBit = true; |
1508 packet_->seqNum = seq_num_; | 1500 packet_->seqNum = seq_num_; |
1509 | 1501 |
1510 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1502 EXPECT_EQ(kCompleteSession, |
1511 &retransmitted)); | 1503 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1512 | 1504 |
1513 frame_out = DecodeCompleteFrame(); | 1505 frame_out = DecodeCompleteFrame(); |
1514 | 1506 |
1515 CheckOutFrame(frame_out, 100 * size_, false); | 1507 CheckOutFrame(frame_out, 100 * size_, false); |
1516 | 1508 |
1517 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1509 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1518 jitter_buffer_->ReleaseFrame(frame_out); | 1510 jitter_buffer_->ReleaseFrame(frame_out); |
1519 } | 1511 } |
1520 | 1512 |
1521 TEST_F(TestBasicJitterBuffer, PacketReorderingReverseWithNegSeqNumWrap) { | 1513 TEST_F(TestBasicJitterBuffer, PacketReorderingReverseWithNegSeqNumWrap) { |
1522 // Insert "first" packet last seqnum. | 1514 // Insert "first" packet last seqnum. |
1523 seq_num_ = 10; | 1515 seq_num_ = 10; |
1524 packet_->frameType = kVideoFrameKey; | 1516 packet_->frameType = kVideoFrameKey; |
1525 packet_->isFirstPacket = false; | 1517 packet_->isFirstPacket = false; |
1526 packet_->markerBit = true; | 1518 packet_->markerBit = true; |
1527 packet_->seqNum = seq_num_; | 1519 packet_->seqNum = seq_num_; |
1528 | 1520 |
1529 bool retransmitted = false; | 1521 bool retransmitted = false; |
1530 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1522 EXPECT_EQ(kIncomplete, |
1531 &retransmitted)); | 1523 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1532 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1524 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1533 | 1525 |
1534 // Should not be complete. | 1526 // Should not be complete. |
1535 EXPECT_TRUE(frame_out == NULL); | 1527 EXPECT_TRUE(frame_out == NULL); |
1536 | 1528 |
1537 // Insert 98 frames. | 1529 // Insert 98 frames. |
1538 int loop = 0; | 1530 int loop = 0; |
1539 do { | 1531 do { |
1540 seq_num_--; | 1532 seq_num_--; |
1541 packet_->isFirstPacket = false; | 1533 packet_->isFirstPacket = false; |
1542 packet_->markerBit = false; | 1534 packet_->markerBit = false; |
1543 packet_->seqNum = seq_num_; | 1535 packet_->seqNum = seq_num_; |
1544 | 1536 |
1545 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1537 EXPECT_EQ(kIncomplete, |
1546 &retransmitted)); | 1538 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1547 | 1539 |
1548 frame_out = DecodeCompleteFrame(); | 1540 frame_out = DecodeCompleteFrame(); |
1549 | 1541 |
1550 EXPECT_TRUE(frame_out == NULL); | 1542 EXPECT_TRUE(frame_out == NULL); |
1551 | 1543 |
1552 loop++; | 1544 loop++; |
1553 } while (loop < 98); | 1545 } while (loop < 98); |
1554 | 1546 |
1555 // Insert last packet. | 1547 // Insert last packet. |
1556 seq_num_--; | 1548 seq_num_--; |
1557 packet_->isFirstPacket = true; | 1549 packet_->isFirstPacket = true; |
1558 packet_->markerBit = false; | 1550 packet_->markerBit = false; |
1559 packet_->seqNum = seq_num_; | 1551 packet_->seqNum = seq_num_; |
1560 | 1552 |
1561 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1553 EXPECT_EQ(kCompleteSession, |
1562 &retransmitted)); | 1554 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1563 | 1555 |
1564 frame_out = DecodeCompleteFrame(); | 1556 frame_out = DecodeCompleteFrame(); |
1565 CheckOutFrame(frame_out, 100 * size_, false); | 1557 CheckOutFrame(frame_out, 100 * size_, false); |
1566 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1558 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1567 jitter_buffer_->ReleaseFrame(frame_out); | 1559 jitter_buffer_->ReleaseFrame(frame_out); |
1568 } | 1560 } |
1569 | 1561 |
1570 TEST_F(TestBasicJitterBuffer, TestInsertOldFrame) { | 1562 TEST_F(TestBasicJitterBuffer, TestInsertOldFrame) { |
1571 // ------- ------- | 1563 // ------- ------- |
1572 // | 2 | | 1 | | 1564 // | 2 | | 1 | |
1573 // ------- ------- | 1565 // ------- ------- |
1574 // t = 3000 t = 2000 | 1566 // t = 3000 t = 2000 |
1575 seq_num_ = 2; | 1567 seq_num_ = 2; |
1576 timestamp_ = 3000; | 1568 timestamp_ = 3000; |
1577 packet_->frameType = kVideoFrameKey; | 1569 packet_->frameType = kVideoFrameKey; |
1578 packet_->isFirstPacket = true; | 1570 packet_->isFirstPacket = true; |
1579 packet_->markerBit = true; | 1571 packet_->markerBit = true; |
1580 packet_->timestamp = timestamp_; | 1572 packet_->timestamp = timestamp_; |
1581 packet_->seqNum = seq_num_; | 1573 packet_->seqNum = seq_num_; |
1582 | 1574 |
1583 bool retransmitted = false; | 1575 bool retransmitted = false; |
1584 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1576 EXPECT_EQ(kCompleteSession, |
1585 &retransmitted)); | 1577 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1586 | 1578 |
1587 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1579 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1588 EXPECT_EQ(3000u, frame_out->TimeStamp()); | 1580 EXPECT_EQ(3000u, frame_out->TimeStamp()); |
1589 CheckOutFrame(frame_out, size_, false); | 1581 CheckOutFrame(frame_out, size_, false); |
1590 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1582 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1591 jitter_buffer_->ReleaseFrame(frame_out); | 1583 jitter_buffer_->ReleaseFrame(frame_out); |
1592 | 1584 |
1593 seq_num_--; | 1585 seq_num_--; |
1594 timestamp_ = 2000; | 1586 timestamp_ = 2000; |
1595 packet_->frameType = kVideoFrameDelta; | 1587 packet_->frameType = kVideoFrameDelta; |
1596 packet_->isFirstPacket = true; | 1588 packet_->isFirstPacket = true; |
1597 packet_->markerBit = true; | 1589 packet_->markerBit = true; |
1598 packet_->seqNum = seq_num_; | 1590 packet_->seqNum = seq_num_; |
1599 packet_->timestamp = timestamp_; | 1591 packet_->timestamp = timestamp_; |
1600 | 1592 |
1601 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, | 1593 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1602 &retransmitted)); | |
1603 } | 1594 } |
1604 | 1595 |
1605 TEST_F(TestBasicJitterBuffer, TestInsertOldFrameWithSeqNumWrap) { | 1596 TEST_F(TestBasicJitterBuffer, TestInsertOldFrameWithSeqNumWrap) { |
1606 // ------- ------- | 1597 // ------- ------- |
1607 // | 2 | | 1 | | 1598 // | 2 | | 1 | |
1608 // ------- ------- | 1599 // ------- ------- |
1609 // t = 3000 t = 0xffffff00 | 1600 // t = 3000 t = 0xffffff00 |
1610 | 1601 |
1611 seq_num_ = 2; | 1602 seq_num_ = 2; |
1612 timestamp_ = 3000; | 1603 timestamp_ = 3000; |
1613 packet_->frameType = kVideoFrameKey; | 1604 packet_->frameType = kVideoFrameKey; |
1614 packet_->isFirstPacket = true; | 1605 packet_->isFirstPacket = true; |
1615 packet_->markerBit = true; | 1606 packet_->markerBit = true; |
1616 packet_->seqNum = seq_num_; | 1607 packet_->seqNum = seq_num_; |
1617 packet_->timestamp = timestamp_; | 1608 packet_->timestamp = timestamp_; |
1618 | 1609 |
1619 bool retransmitted = false; | 1610 bool retransmitted = false; |
1620 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1611 EXPECT_EQ(kCompleteSession, |
1621 &retransmitted)); | 1612 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1622 | 1613 |
1623 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1614 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1624 EXPECT_EQ(timestamp_, frame_out->TimeStamp()); | 1615 EXPECT_EQ(timestamp_, frame_out->TimeStamp()); |
1625 | 1616 |
1626 CheckOutFrame(frame_out, size_, false); | 1617 CheckOutFrame(frame_out, size_, false); |
1627 | 1618 |
1628 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1619 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1629 | 1620 |
1630 jitter_buffer_->ReleaseFrame(frame_out); | 1621 jitter_buffer_->ReleaseFrame(frame_out); |
1631 | 1622 |
1632 seq_num_--; | 1623 seq_num_--; |
1633 timestamp_ = 0xffffff00; | 1624 timestamp_ = 0xffffff00; |
1634 packet_->frameType = kVideoFrameDelta; | 1625 packet_->frameType = kVideoFrameDelta; |
1635 packet_->isFirstPacket = true; | 1626 packet_->isFirstPacket = true; |
1636 packet_->markerBit = true; | 1627 packet_->markerBit = true; |
1637 packet_->seqNum = seq_num_; | 1628 packet_->seqNum = seq_num_; |
1638 packet_->timestamp = timestamp_; | 1629 packet_->timestamp = timestamp_; |
1639 | 1630 |
1640 | |
1641 // This timestamp is old. | 1631 // This timestamp is old. |
1642 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, | 1632 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1643 &retransmitted)); | |
1644 } | 1633 } |
1645 | 1634 |
1646 TEST_F(TestBasicJitterBuffer, TimestampWrap) { | 1635 TEST_F(TestBasicJitterBuffer, TimestampWrap) { |
1647 // --------------- --------------- | 1636 // --------------- --------------- |
1648 // | 1 | 2 | | 3 | 4 | | 1637 // | 1 | 2 | | 3 | 4 | |
1649 // --------------- --------------- | 1638 // --------------- --------------- |
1650 // t = 0xffffff00 t = 33*90 | 1639 // t = 0xffffff00 t = 33*90 |
1651 | 1640 |
1652 timestamp_ = 0xffffff00; | 1641 timestamp_ = 0xffffff00; |
1653 packet_->frameType = kVideoFrameKey; | 1642 packet_->frameType = kVideoFrameKey; |
1654 packet_->isFirstPacket = true; | 1643 packet_->isFirstPacket = true; |
1655 packet_->markerBit = false; | 1644 packet_->markerBit = false; |
1656 packet_->seqNum = seq_num_; | 1645 packet_->seqNum = seq_num_; |
1657 packet_->timestamp = timestamp_; | 1646 packet_->timestamp = timestamp_; |
1658 | 1647 |
1659 bool retransmitted = false; | 1648 bool retransmitted = false; |
1660 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1649 EXPECT_EQ(kIncomplete, |
1661 &retransmitted)); | 1650 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1662 | 1651 |
1663 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1652 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1664 EXPECT_TRUE(frame_out == NULL); | 1653 EXPECT_TRUE(frame_out == NULL); |
1665 | 1654 |
1666 seq_num_++; | 1655 seq_num_++; |
1667 packet_->isFirstPacket = false; | 1656 packet_->isFirstPacket = false; |
1668 packet_->markerBit = true; | 1657 packet_->markerBit = true; |
1669 packet_->seqNum = seq_num_; | 1658 packet_->seqNum = seq_num_; |
1670 | 1659 |
1671 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1660 EXPECT_EQ(kCompleteSession, |
1672 &retransmitted)); | 1661 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1673 | 1662 |
1674 frame_out = DecodeCompleteFrame(); | 1663 frame_out = DecodeCompleteFrame(); |
1675 CheckOutFrame(frame_out, 2 * size_, false); | 1664 CheckOutFrame(frame_out, 2 * size_, false); |
1676 jitter_buffer_->ReleaseFrame(frame_out); | 1665 jitter_buffer_->ReleaseFrame(frame_out); |
1677 | 1666 |
1678 seq_num_++; | 1667 seq_num_++; |
1679 timestamp_ += 33*90; | 1668 timestamp_ += 33 * 90; |
1680 packet_->frameType = kVideoFrameDelta; | 1669 packet_->frameType = kVideoFrameDelta; |
1681 packet_->isFirstPacket = true; | 1670 packet_->isFirstPacket = true; |
1682 packet_->markerBit = false; | 1671 packet_->markerBit = false; |
1683 packet_->seqNum = seq_num_; | 1672 packet_->seqNum = seq_num_; |
1684 packet_->timestamp = timestamp_; | 1673 packet_->timestamp = timestamp_; |
1685 | 1674 |
1686 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1675 EXPECT_EQ(kIncomplete, |
1687 &retransmitted)); | 1676 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1688 | 1677 |
1689 frame_out = DecodeCompleteFrame(); | 1678 frame_out = DecodeCompleteFrame(); |
1690 EXPECT_TRUE(frame_out == NULL); | 1679 EXPECT_TRUE(frame_out == NULL); |
1691 | 1680 |
1692 seq_num_++; | 1681 seq_num_++; |
1693 packet_->isFirstPacket = false; | 1682 packet_->isFirstPacket = false; |
1694 packet_->markerBit = true; | 1683 packet_->markerBit = true; |
1695 packet_->seqNum = seq_num_; | 1684 packet_->seqNum = seq_num_; |
1696 | 1685 |
1697 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1686 EXPECT_EQ(kCompleteSession, |
1698 &retransmitted)); | 1687 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1699 | 1688 |
1700 frame_out = DecodeCompleteFrame(); | 1689 frame_out = DecodeCompleteFrame(); |
1701 CheckOutFrame(frame_out, 2 * size_, false); | 1690 CheckOutFrame(frame_out, 2 * size_, false); |
1702 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); | 1691 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType()); |
1703 jitter_buffer_->ReleaseFrame(frame_out); | 1692 jitter_buffer_->ReleaseFrame(frame_out); |
1704 } | 1693 } |
1705 | 1694 |
1706 TEST_F(TestBasicJitterBuffer, 2FrameWithTimestampWrap) { | 1695 TEST_F(TestBasicJitterBuffer, 2FrameWithTimestampWrap) { |
1707 // ------- ------- | 1696 // ------- ------- |
1708 // | 1 | | 2 | | 1697 // | 1 | | 2 | |
1709 // ------- ------- | 1698 // ------- ------- |
1710 // t = 0xffffff00 t = 2700 | 1699 // t = 0xffffff00 t = 2700 |
1711 | 1700 |
1712 timestamp_ = 0xffffff00; | 1701 timestamp_ = 0xffffff00; |
1713 packet_->frameType = kVideoFrameKey; | 1702 packet_->frameType = kVideoFrameKey; |
1714 packet_->isFirstPacket = true; | 1703 packet_->isFirstPacket = true; |
1715 packet_->markerBit = true; | 1704 packet_->markerBit = true; |
1716 packet_->timestamp = timestamp_; | 1705 packet_->timestamp = timestamp_; |
1717 | 1706 |
1718 bool retransmitted = false; | 1707 bool retransmitted = false; |
1719 // Insert first frame (session will be complete). | 1708 // Insert first frame (session will be complete). |
1720 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1709 EXPECT_EQ(kCompleteSession, |
1721 &retransmitted)); | 1710 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1722 | 1711 |
1723 // Insert next frame. | 1712 // Insert next frame. |
1724 seq_num_++; | 1713 seq_num_++; |
1725 timestamp_ = 2700; | 1714 timestamp_ = 2700; |
1726 packet_->frameType = kVideoFrameDelta; | 1715 packet_->frameType = kVideoFrameDelta; |
1727 packet_->isFirstPacket = true; | 1716 packet_->isFirstPacket = true; |
1728 packet_->markerBit = true; | 1717 packet_->markerBit = true; |
1729 packet_->seqNum = seq_num_; | 1718 packet_->seqNum = seq_num_; |
1730 packet_->timestamp = timestamp_; | 1719 packet_->timestamp = timestamp_; |
1731 | 1720 |
1732 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1721 EXPECT_EQ(kCompleteSession, |
1733 &retransmitted)); | 1722 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1734 | 1723 |
1735 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1724 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1736 EXPECT_EQ(0xffffff00, frame_out->TimeStamp()); | 1725 EXPECT_EQ(0xffffff00, frame_out->TimeStamp()); |
1737 CheckOutFrame(frame_out, size_, false); | 1726 CheckOutFrame(frame_out, size_, false); |
1738 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1727 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1739 jitter_buffer_->ReleaseFrame(frame_out); | 1728 jitter_buffer_->ReleaseFrame(frame_out); |
1740 | 1729 |
1741 VCMEncodedFrame* frame_out2 = DecodeCompleteFrame(); | 1730 VCMEncodedFrame* frame_out2 = DecodeCompleteFrame(); |
1742 EXPECT_EQ(2700u, frame_out2->TimeStamp()); | 1731 EXPECT_EQ(2700u, frame_out2->TimeStamp()); |
1743 CheckOutFrame(frame_out2, size_, false); | 1732 CheckOutFrame(frame_out2, size_, false); |
1744 EXPECT_EQ(kVideoFrameDelta, frame_out2->FrameType()); | 1733 EXPECT_EQ(kVideoFrameDelta, frame_out2->FrameType()); |
1745 jitter_buffer_->ReleaseFrame(frame_out2); | 1734 jitter_buffer_->ReleaseFrame(frame_out2); |
1746 } | 1735 } |
1747 | 1736 |
1748 TEST_F(TestBasicJitterBuffer, Insert2FramesReOrderedWithTimestampWrap) { | 1737 TEST_F(TestBasicJitterBuffer, Insert2FramesReOrderedWithTimestampWrap) { |
1749 // ------- ------- | 1738 // ------- ------- |
1750 // | 2 | | 1 | | 1739 // | 2 | | 1 | |
1751 // ------- ------- | 1740 // ------- ------- |
1752 // t = 2700 t = 0xffffff00 | 1741 // t = 2700 t = 0xffffff00 |
1753 | 1742 |
1754 seq_num_ = 2; | 1743 seq_num_ = 2; |
1755 timestamp_ = 2700; | 1744 timestamp_ = 2700; |
1756 packet_->frameType = kVideoFrameDelta; | 1745 packet_->frameType = kVideoFrameDelta; |
1757 packet_->isFirstPacket = true; | 1746 packet_->isFirstPacket = true; |
1758 packet_->markerBit = true; | 1747 packet_->markerBit = true; |
1759 packet_->seqNum = seq_num_; | 1748 packet_->seqNum = seq_num_; |
1760 packet_->timestamp = timestamp_; | 1749 packet_->timestamp = timestamp_; |
1761 | 1750 |
1762 bool retransmitted = false; | 1751 bool retransmitted = false; |
1763 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1752 EXPECT_EQ(kCompleteSession, |
1764 &retransmitted)); | 1753 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1765 | 1754 |
1766 // Insert second frame | 1755 // Insert second frame |
1767 seq_num_--; | 1756 seq_num_--; |
1768 timestamp_ = 0xffffff00; | 1757 timestamp_ = 0xffffff00; |
1769 packet_->frameType = kVideoFrameKey; | 1758 packet_->frameType = kVideoFrameKey; |
1770 packet_->isFirstPacket = true; | 1759 packet_->isFirstPacket = true; |
1771 packet_->markerBit = true; | 1760 packet_->markerBit = true; |
1772 packet_->seqNum = seq_num_; | 1761 packet_->seqNum = seq_num_; |
1773 packet_->timestamp = timestamp_; | 1762 packet_->timestamp = timestamp_; |
1774 | 1763 |
1775 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1764 EXPECT_EQ(kCompleteSession, |
1776 &retransmitted)); | 1765 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1777 | 1766 |
1778 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 1767 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
1779 EXPECT_EQ(0xffffff00, frame_out->TimeStamp()); | 1768 EXPECT_EQ(0xffffff00, frame_out->TimeStamp()); |
1780 CheckOutFrame(frame_out, size_, false); | 1769 CheckOutFrame(frame_out, size_, false); |
1781 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); | 1770 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType()); |
1782 jitter_buffer_->ReleaseFrame(frame_out); | 1771 jitter_buffer_->ReleaseFrame(frame_out); |
1783 | 1772 |
1784 VCMEncodedFrame* frame_out2 = DecodeCompleteFrame(); | 1773 VCMEncodedFrame* frame_out2 = DecodeCompleteFrame(); |
1785 EXPECT_EQ(2700u, frame_out2->TimeStamp()); | 1774 EXPECT_EQ(2700u, frame_out2->TimeStamp()); |
1786 CheckOutFrame(frame_out2, size_, false); | 1775 CheckOutFrame(frame_out2, size_, false); |
1787 EXPECT_EQ(kVideoFrameDelta, frame_out2->FrameType()); | 1776 EXPECT_EQ(kVideoFrameDelta, frame_out2->FrameType()); |
1788 jitter_buffer_->ReleaseFrame(frame_out2); | 1777 jitter_buffer_->ReleaseFrame(frame_out2); |
1789 } | 1778 } |
1790 | 1779 |
1791 TEST_F(TestBasicJitterBuffer, DeltaFrameWithMoreThanMaxNumberOfPackets) { | 1780 TEST_F(TestBasicJitterBuffer, DeltaFrameWithMoreThanMaxNumberOfPackets) { |
1792 int loop = 0; | 1781 int loop = 0; |
1793 bool firstPacket = true; | 1782 bool firstPacket = true; |
1794 bool retransmitted = false; | 1783 bool retransmitted = false; |
1795 // Insert kMaxPacketsInJitterBuffer into frame. | 1784 // Insert kMaxPacketsInJitterBuffer into frame. |
1796 do { | 1785 do { |
1797 seq_num_++; | 1786 seq_num_++; |
1798 packet_->isFirstPacket = false; | 1787 packet_->isFirstPacket = false; |
1799 packet_->markerBit = false; | 1788 packet_->markerBit = false; |
1800 packet_->seqNum = seq_num_; | 1789 packet_->seqNum = seq_num_; |
1801 | 1790 |
1802 if (firstPacket) { | 1791 if (firstPacket) { |
1803 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1792 EXPECT_EQ(kIncomplete, |
1804 &retransmitted)); | 1793 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1805 firstPacket = false; | 1794 firstPacket = false; |
1806 } else { | 1795 } else { |
1807 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, | 1796 EXPECT_EQ(kIncomplete, |
1808 &retransmitted)); | 1797 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1809 } | 1798 } |
1810 | 1799 |
1811 loop++; | 1800 loop++; |
1812 } while (loop < kMaxPacketsInSession); | 1801 } while (loop < kMaxPacketsInSession); |
1813 | 1802 |
1814 // Max number of packets inserted. | 1803 // Max number of packets inserted. |
1815 // Insert one more packet. | 1804 // Insert one more packet. |
1816 seq_num_++; | 1805 seq_num_++; |
1817 packet_->isFirstPacket = false; | 1806 packet_->isFirstPacket = false; |
1818 packet_->markerBit = true; | 1807 packet_->markerBit = true; |
1819 packet_->seqNum = seq_num_; | 1808 packet_->seqNum = seq_num_; |
1820 | 1809 |
1821 // Insert the packet -> frame recycled. | 1810 // Insert the packet -> frame recycled. |
1822 EXPECT_EQ(kSizeError, jitter_buffer_->InsertPacket(*packet_, | 1811 EXPECT_EQ(kSizeError, jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1823 &retransmitted)); | |
1824 EXPECT_TRUE(NULL == DecodeCompleteFrame()); | 1812 EXPECT_TRUE(NULL == DecodeCompleteFrame()); |
1825 | |
1826 } | 1813 } |
1827 | 1814 |
1828 TEST_F(TestBasicJitterBuffer, ExceedNumOfFrameWithSeqNumWrap) { | 1815 TEST_F(TestBasicJitterBuffer, ExceedNumOfFrameWithSeqNumWrap) { |
1829 // TEST fill JB with more than max number of frame (50 delta frames + | 1816 // TEST fill JB with more than max number of frame (50 delta frames + |
1830 // 51 key frames) with wrap in seq_num_ | 1817 // 51 key frames) with wrap in seq_num_ |
1831 // | 1818 // |
1832 // -------------------------------------------------------------- | 1819 // -------------------------------------------------------------- |
1833 // | 65485 | 65486 | 65487 | .... | 65535 | 0 | 1 | 2 | .....| 50 | | 1820 // | 65485 | 65486 | 65487 | .... | 65535 | 0 | 1 | 2 | .....| 50 | |
1834 // -------------------------------------------------------------- | 1821 // -------------------------------------------------------------- |
1835 // |<-----------delta frames------------->|<------key frames----->| | 1822 // |<-----------delta frames------------->|<------key frames----->| |
1836 | 1823 |
1837 // Make sure the jitter doesn't request a keyframe after too much non- | 1824 // Make sure the jitter doesn't request a keyframe after too much non- |
1838 // decodable frames. | 1825 // decodable frames. |
1839 jitter_buffer_->SetNackMode(kNack, -1, -1); | 1826 jitter_buffer_->SetNackMode(kNack, -1, -1); |
1840 jitter_buffer_->SetNackSettings(kMaxNumberOfFrames, | 1827 jitter_buffer_->SetNackSettings(kMaxNumberOfFrames, kMaxNumberOfFrames, 0); |
1841 kMaxNumberOfFrames, 0); | |
1842 | 1828 |
1843 int loop = 0; | 1829 int loop = 0; |
1844 seq_num_ = 65485; | 1830 seq_num_ = 65485; |
1845 uint32_t first_key_frame_timestamp = 0; | 1831 uint32_t first_key_frame_timestamp = 0; |
1846 bool retransmitted = false; | 1832 bool retransmitted = false; |
1847 // Insert MAX_NUMBER_OF_FRAMES frames. | 1833 // Insert MAX_NUMBER_OF_FRAMES frames. |
1848 do { | 1834 do { |
1849 timestamp_ += 33*90; | 1835 timestamp_ += 33 * 90; |
1850 seq_num_++; | 1836 seq_num_++; |
1851 packet_->isFirstPacket = true; | 1837 packet_->isFirstPacket = true; |
1852 packet_->markerBit = true; | 1838 packet_->markerBit = true; |
1853 packet_->seqNum = seq_num_; | 1839 packet_->seqNum = seq_num_; |
1854 packet_->timestamp = timestamp_; | 1840 packet_->timestamp = timestamp_; |
1855 | 1841 |
1856 if (loop == 50) { | 1842 if (loop == 50) { |
1857 first_key_frame_timestamp = packet_->timestamp; | 1843 first_key_frame_timestamp = packet_->timestamp; |
1858 packet_->frameType = kVideoFrameKey; | 1844 packet_->frameType = kVideoFrameKey; |
1859 } | 1845 } |
1860 | 1846 |
1861 // Insert frame. | 1847 // Insert frame. |
1862 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 1848 EXPECT_EQ(kCompleteSession, |
1863 &retransmitted)); | 1849 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1864 | 1850 |
1865 loop++; | 1851 loop++; |
1866 } while (loop < kMaxNumberOfFrames); | 1852 } while (loop < kMaxNumberOfFrames); |
1867 | 1853 |
1868 // Max number of frames inserted. | 1854 // Max number of frames inserted. |
1869 | 1855 |
1870 // Insert one more frame. | 1856 // Insert one more frame. |
1871 timestamp_ += 33*90; | 1857 timestamp_ += 33 * 90; |
1872 seq_num_++; | 1858 seq_num_++; |
1873 packet_->isFirstPacket = true; | 1859 packet_->isFirstPacket = true; |
1874 packet_->markerBit = true; | 1860 packet_->markerBit = true; |
1875 packet_->seqNum = seq_num_; | 1861 packet_->seqNum = seq_num_; |
1876 packet_->timestamp = timestamp_; | 1862 packet_->timestamp = timestamp_; |
1877 | 1863 |
1878 // Now, no free frame - frames will be recycled until first key frame. | 1864 // Now, no free frame - frames will be recycled until first key frame. |
1879 EXPECT_EQ(kFlushIndicator, | 1865 EXPECT_EQ(kFlushIndicator, |
1880 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); | 1866 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1881 | 1867 |
(...skipping 13 matching lines...) Expand all Loading... |
1895 bool retransmitted = false; | 1881 bool retransmitted = false; |
1896 for (int i = 0; i < maxSize + 10; i++) { | 1882 for (int i = 0; i < maxSize + 10; i++) { |
1897 timestamp_ += 33 * 90; | 1883 timestamp_ += 33 * 90; |
1898 seq_num_++; | 1884 seq_num_++; |
1899 packet_->isFirstPacket = false; | 1885 packet_->isFirstPacket = false; |
1900 packet_->markerBit = false; | 1886 packet_->markerBit = false; |
1901 packet_->seqNum = seq_num_; | 1887 packet_->seqNum = seq_num_; |
1902 packet_->timestamp = timestamp_; | 1888 packet_->timestamp = timestamp_; |
1903 packet_->frameType = kEmptyFrame; | 1889 packet_->frameType = kEmptyFrame; |
1904 | 1890 |
1905 EXPECT_EQ(kNoError, jitter_buffer_->InsertPacket(*packet_, | 1891 EXPECT_EQ(kNoError, jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1906 &retransmitted)); | |
1907 VCMEncodedFrame* testFrame = DecodeIncompleteFrame(); | 1892 VCMEncodedFrame* testFrame = DecodeIncompleteFrame(); |
1908 // Timestamp should never be the last TS inserted. | 1893 // Timestamp should never be the last TS inserted. |
1909 if (testFrame != NULL) { | 1894 if (testFrame != NULL) { |
1910 EXPECT_TRUE(testFrame->TimeStamp() < timestamp_); | 1895 EXPECT_TRUE(testFrame->TimeStamp() < timestamp_); |
1911 jitter_buffer_->ReleaseFrame(testFrame); | 1896 jitter_buffer_->ReleaseFrame(testFrame); |
1912 } | 1897 } |
1913 } | 1898 } |
1914 } | 1899 } |
1915 | 1900 |
1916 TEST_F(TestBasicJitterBuffer, H264IncompleteNalu) { | 1901 TEST_F(TestBasicJitterBuffer, H264IncompleteNalu) { |
1917 jitter_buffer_->SetNackMode(kNoNack, -1, -1); | 1902 jitter_buffer_->SetNackMode(kNoNack, -1, -1); |
1918 jitter_buffer_->SetDecodeErrorMode(kWithErrors); | 1903 jitter_buffer_->SetDecodeErrorMode(kWithErrors); |
1919 ++seq_num_; | 1904 ++seq_num_; |
1920 timestamp_ += 33 * 90; | 1905 timestamp_ += 33 * 90; |
1921 int insertedLength = 0; | 1906 int insertedLength = 0; |
1922 packet_->seqNum = seq_num_; | 1907 packet_->seqNum = seq_num_; |
1923 packet_->timestamp = timestamp_; | 1908 packet_->timestamp = timestamp_; |
1924 packet_->frameType = kVideoFrameKey; | 1909 packet_->frameType = kVideoFrameKey; |
1925 packet_->isFirstPacket = true; | 1910 packet_->isFirstPacket = true; |
1926 packet_->completeNALU = kNaluStart; | 1911 packet_->completeNALU = kNaluStart; |
1927 packet_->markerBit = false; | 1912 packet_->markerBit = false; |
1928 bool retransmitted = false; | 1913 bool retransmitted = false; |
1929 | 1914 |
1930 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1915 EXPECT_EQ(kDecodableSession, |
1931 &retransmitted)); | 1916 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1932 | 1917 |
1933 seq_num_ += 2; // Skip one packet. | 1918 seq_num_ += 2; // Skip one packet. |
1934 packet_->seqNum = seq_num_; | 1919 packet_->seqNum = seq_num_; |
1935 packet_->frameType = kVideoFrameKey; | 1920 packet_->frameType = kVideoFrameKey; |
1936 packet_->isFirstPacket = false; | 1921 packet_->isFirstPacket = false; |
1937 packet_->completeNALU = kNaluIncomplete; | 1922 packet_->completeNALU = kNaluIncomplete; |
1938 packet_->markerBit = false; | 1923 packet_->markerBit = false; |
1939 | 1924 |
1940 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1925 EXPECT_EQ(kDecodableSession, |
1941 &retransmitted)); | 1926 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1942 | 1927 |
1943 seq_num_++; | 1928 seq_num_++; |
1944 packet_->seqNum = seq_num_; | 1929 packet_->seqNum = seq_num_; |
1945 packet_->frameType = kVideoFrameKey; | 1930 packet_->frameType = kVideoFrameKey; |
1946 packet_->isFirstPacket = false; | 1931 packet_->isFirstPacket = false; |
1947 packet_->completeNALU = kNaluEnd; | 1932 packet_->completeNALU = kNaluEnd; |
1948 packet_->markerBit = false; | 1933 packet_->markerBit = false; |
1949 | 1934 |
1950 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1935 EXPECT_EQ(kDecodableSession, |
1951 &retransmitted)); | 1936 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1952 | 1937 |
1953 seq_num_++; | 1938 seq_num_++; |
1954 packet_->seqNum = seq_num_; | 1939 packet_->seqNum = seq_num_; |
1955 packet_->completeNALU = kNaluComplete; | 1940 packet_->completeNALU = kNaluComplete; |
1956 packet_->markerBit = true; // Last packet. | 1941 packet_->markerBit = true; // Last packet. |
1957 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1942 EXPECT_EQ(kDecodableSession, |
1958 &retransmitted)); | 1943 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1959 // The JB will only output (incomplete) frames if a packet belonging to a | 1944 // The JB will only output (incomplete) frames if a packet belonging to a |
1960 // subsequent frame was already inserted. Insert one packet of a subsequent | 1945 // subsequent frame was already inserted. Insert one packet of a subsequent |
1961 // frame. place high timestamp so the JB would always have a next frame | 1946 // frame. place high timestamp so the JB would always have a next frame |
1962 // (otherwise, for every inserted frame we need to take care of the next | 1947 // (otherwise, for every inserted frame we need to take care of the next |
1963 // frame as well). | 1948 // frame as well). |
1964 packet_->seqNum = 1; | 1949 packet_->seqNum = 1; |
1965 packet_->timestamp = timestamp_ + 33 * 90 * 10; | 1950 packet_->timestamp = timestamp_ + 33 * 90 * 10; |
1966 packet_->frameType = kVideoFrameDelta; | 1951 packet_->frameType = kVideoFrameDelta; |
1967 packet_->isFirstPacket = false; | 1952 packet_->isFirstPacket = false; |
1968 packet_->completeNALU = kNaluStart; | 1953 packet_->completeNALU = kNaluStart; |
1969 packet_->markerBit = false; | 1954 packet_->markerBit = false; |
1970 | 1955 |
1971 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1956 EXPECT_EQ(kDecodableSession, |
1972 &retransmitted)); | 1957 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1973 | 1958 |
1974 VCMEncodedFrame* frame_out = DecodeIncompleteFrame(); | 1959 VCMEncodedFrame* frame_out = DecodeIncompleteFrame(); |
1975 | 1960 |
1976 // We can decode everything from a NALU until a packet has been lost. | 1961 // We can decode everything from a NALU until a packet has been lost. |
1977 // Thus we can decode the first packet of the first NALU and the second NALU | 1962 // Thus we can decode the first packet of the first NALU and the second NALU |
1978 // which consists of one packet. | 1963 // which consists of one packet. |
1979 CheckOutFrame(frame_out, packet_->sizeBytes * 2, false); | 1964 CheckOutFrame(frame_out, packet_->sizeBytes * 2, false); |
1980 jitter_buffer_->ReleaseFrame(frame_out); | 1965 jitter_buffer_->ReleaseFrame(frame_out); |
1981 | 1966 |
1982 // Test reordered start frame + 1 lost. | 1967 // Test reordered start frame + 1 lost. |
1983 seq_num_ += 2; // Re-order 1 frame. | 1968 seq_num_ += 2; // Re-order 1 frame. |
1984 timestamp_ += 33*90; | 1969 timestamp_ += 33 * 90; |
1985 insertedLength = 0; | 1970 insertedLength = 0; |
1986 | 1971 |
1987 packet_->seqNum = seq_num_; | 1972 packet_->seqNum = seq_num_; |
1988 packet_->timestamp = timestamp_; | 1973 packet_->timestamp = timestamp_; |
1989 packet_->frameType = kVideoFrameKey; | 1974 packet_->frameType = kVideoFrameKey; |
1990 packet_->isFirstPacket = false; | 1975 packet_->isFirstPacket = false; |
1991 packet_->completeNALU = kNaluEnd; | 1976 packet_->completeNALU = kNaluEnd; |
1992 packet_->markerBit = false; | 1977 packet_->markerBit = false; |
1993 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1978 EXPECT_EQ(kDecodableSession, |
1994 &retransmitted)); | 1979 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
1995 insertedLength += packet_->sizeBytes; // This packet should be decoded. | 1980 insertedLength += packet_->sizeBytes; // This packet should be decoded. |
1996 seq_num_--; | 1981 seq_num_--; |
1997 packet_->seqNum = seq_num_; | 1982 packet_->seqNum = seq_num_; |
1998 packet_->timestamp = timestamp_; | 1983 packet_->timestamp = timestamp_; |
1999 packet_->frameType = kVideoFrameKey; | 1984 packet_->frameType = kVideoFrameKey; |
2000 packet_->isFirstPacket = true; | 1985 packet_->isFirstPacket = true; |
2001 packet_->completeNALU = kNaluStart; | 1986 packet_->completeNALU = kNaluStart; |
2002 packet_->markerBit = false; | 1987 packet_->markerBit = false; |
2003 | 1988 |
2004 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 1989 EXPECT_EQ(kDecodableSession, |
2005 &retransmitted)); | 1990 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
2006 insertedLength += packet_->sizeBytes; // This packet should be decoded. | 1991 insertedLength += packet_->sizeBytes; // This packet should be decoded. |
2007 | 1992 |
2008 seq_num_ += 3; // One packet drop. | 1993 seq_num_ += 3; // One packet drop. |
2009 packet_->seqNum = seq_num_; | 1994 packet_->seqNum = seq_num_; |
2010 packet_->timestamp = timestamp_; | 1995 packet_->timestamp = timestamp_; |
2011 packet_->frameType = kVideoFrameKey; | 1996 packet_->frameType = kVideoFrameKey; |
2012 packet_->isFirstPacket = false; | 1997 packet_->isFirstPacket = false; |
2013 packet_->completeNALU = kNaluComplete; | 1998 packet_->completeNALU = kNaluComplete; |
2014 packet_->markerBit = false; | 1999 packet_->markerBit = false; |
2015 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 2000 EXPECT_EQ(kDecodableSession, |
2016 &retransmitted)); | 2001 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
2017 insertedLength += packet_->sizeBytes; // This packet should be decoded. | 2002 insertedLength += packet_->sizeBytes; // This packet should be decoded. |
2018 seq_num_++; | 2003 seq_num_++; |
2019 packet_->seqNum = seq_num_; | 2004 packet_->seqNum = seq_num_; |
2020 packet_->timestamp = timestamp_; | 2005 packet_->timestamp = timestamp_; |
2021 packet_->frameType = kVideoFrameKey; | 2006 packet_->frameType = kVideoFrameKey; |
2022 packet_->isFirstPacket = false; | 2007 packet_->isFirstPacket = false; |
2023 packet_->completeNALU = kNaluStart; | 2008 packet_->completeNALU = kNaluStart; |
2024 packet_->markerBit = false; | 2009 packet_->markerBit = false; |
2025 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 2010 EXPECT_EQ(kDecodableSession, |
2026 &retransmitted)); | 2011 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
2027 // This packet should be decoded since it's the beginning of a NAL. | 2012 // This packet should be decoded since it's the beginning of a NAL. |
2028 insertedLength += packet_->sizeBytes; | 2013 insertedLength += packet_->sizeBytes; |
2029 | 2014 |
2030 seq_num_ += 2; | 2015 seq_num_ += 2; |
2031 packet_->seqNum = seq_num_; | 2016 packet_->seqNum = seq_num_; |
2032 packet_->timestamp = timestamp_; | 2017 packet_->timestamp = timestamp_; |
2033 packet_->frameType = kVideoFrameKey; | 2018 packet_->frameType = kVideoFrameKey; |
2034 packet_->isFirstPacket = false; | 2019 packet_->isFirstPacket = false; |
2035 packet_->completeNALU = kNaluEnd; | 2020 packet_->completeNALU = kNaluEnd; |
2036 packet_->markerBit = true; | 2021 packet_->markerBit = true; |
2037 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 2022 EXPECT_EQ(kDecodableSession, |
2038 &retransmitted)); | 2023 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
2039 // This packet should not be decoded because it is an incomplete NAL if it | 2024 // This packet should not be decoded because it is an incomplete NAL if it |
2040 // is the last. | 2025 // is the last. |
2041 frame_out = DecodeIncompleteFrame(); | 2026 frame_out = DecodeIncompleteFrame(); |
2042 // Only last NALU is complete. | 2027 // Only last NALU is complete. |
2043 CheckOutFrame(frame_out, insertedLength, false); | 2028 CheckOutFrame(frame_out, insertedLength, false); |
2044 jitter_buffer_->ReleaseFrame(frame_out); | 2029 jitter_buffer_->ReleaseFrame(frame_out); |
2045 | 2030 |
2046 // Test to insert empty packet. | 2031 // Test to insert empty packet. |
2047 seq_num_++; | 2032 seq_num_++; |
2048 timestamp_ += 33 * 90; | 2033 timestamp_ += 33 * 90; |
2049 VCMPacket emptypacket(data_, 0, seq_num_, timestamp_, true); | 2034 VCMPacket emptypacket(data_, 0, seq_num_, timestamp_, true); |
2050 emptypacket.seqNum = seq_num_; | 2035 emptypacket.seqNum = seq_num_; |
2051 emptypacket.timestamp = timestamp_; | 2036 emptypacket.timestamp = timestamp_; |
2052 emptypacket.frameType = kVideoFrameKey; | 2037 emptypacket.frameType = kVideoFrameKey; |
2053 emptypacket.isFirstPacket = true; | 2038 emptypacket.isFirstPacket = true; |
2054 emptypacket.completeNALU = kNaluComplete; | 2039 emptypacket.completeNALU = kNaluComplete; |
2055 emptypacket.markerBit = true; | 2040 emptypacket.markerBit = true; |
2056 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(emptypacket, | 2041 EXPECT_EQ(kCompleteSession, |
2057 &retransmitted)); | 2042 jitter_buffer_->InsertPacket(emptypacket, &retransmitted)); |
2058 // This packet should not be decoded because it is an incomplete NAL if it | 2043 // This packet should not be decoded because it is an incomplete NAL if it |
2059 // is the last. | 2044 // is the last. |
2060 | 2045 |
2061 // Will be sent to the decoder, as a packet belonging to a subsequent frame | 2046 // Will be sent to the decoder, as a packet belonging to a subsequent frame |
2062 // has arrived. | 2047 // has arrived. |
2063 frame_out = DecodeIncompleteFrame(); | 2048 frame_out = DecodeIncompleteFrame(); |
2064 EXPECT_TRUE(frame_out != NULL); | 2049 EXPECT_TRUE(frame_out != NULL); |
2065 jitter_buffer_->ReleaseFrame(frame_out); | 2050 jitter_buffer_->ReleaseFrame(frame_out); |
2066 | 2051 |
2067 // Test that a frame can include an empty packet. | 2052 // Test that a frame can include an empty packet. |
2068 seq_num_++; | 2053 seq_num_++; |
2069 timestamp_ += 33 * 90; | 2054 timestamp_ += 33 * 90; |
2070 | 2055 |
2071 packet_->seqNum = seq_num_; | 2056 packet_->seqNum = seq_num_; |
2072 packet_->timestamp = timestamp_; | 2057 packet_->timestamp = timestamp_; |
2073 packet_->frameType = kVideoFrameKey; | 2058 packet_->frameType = kVideoFrameKey; |
2074 packet_->isFirstPacket = true; | 2059 packet_->isFirstPacket = true; |
2075 packet_->completeNALU = kNaluComplete; | 2060 packet_->completeNALU = kNaluComplete; |
2076 packet_->markerBit = false; | 2061 packet_->markerBit = false; |
2077 | 2062 |
2078 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 2063 EXPECT_EQ(kDecodableSession, |
2079 &retransmitted)); | 2064 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
2080 | 2065 |
2081 seq_num_++; | 2066 seq_num_++; |
2082 emptypacket.seqNum = seq_num_; | 2067 emptypacket.seqNum = seq_num_; |
2083 emptypacket.timestamp = timestamp_; | 2068 emptypacket.timestamp = timestamp_; |
2084 emptypacket.frameType = kVideoFrameKey; | 2069 emptypacket.frameType = kVideoFrameKey; |
2085 emptypacket.isFirstPacket = true; | 2070 emptypacket.isFirstPacket = true; |
2086 emptypacket.completeNALU = kNaluComplete; | 2071 emptypacket.completeNALU = kNaluComplete; |
2087 emptypacket.markerBit = true; | 2072 emptypacket.markerBit = true; |
2088 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(emptypacket, | 2073 EXPECT_EQ(kCompleteSession, |
2089 &retransmitted)); | 2074 jitter_buffer_->InsertPacket(emptypacket, &retransmitted)); |
2090 | 2075 |
2091 frame_out = DecodeCompleteFrame(); | 2076 frame_out = DecodeCompleteFrame(); |
2092 // Only last NALU is complete | 2077 // Only last NALU is complete |
2093 CheckOutFrame(frame_out, packet_->sizeBytes, false); | 2078 CheckOutFrame(frame_out, packet_->sizeBytes, false); |
2094 jitter_buffer_->ReleaseFrame(frame_out); | 2079 jitter_buffer_->ReleaseFrame(frame_out); |
2095 } | 2080 } |
2096 | 2081 |
2097 TEST_F(TestBasicJitterBuffer, NextFrameWhenIncomplete) { | 2082 TEST_F(TestBasicJitterBuffer, NextFrameWhenIncomplete) { |
2098 // Test that a we cannot get incomplete frames from the JB if we haven't | 2083 // Test that a we cannot get incomplete frames from the JB if we haven't |
2099 // received the marker bit, unless we have received a packet from a later | 2084 // received the marker bit, unless we have received a packet from a later |
2100 // timestamp. | 2085 // timestamp. |
2101 jitter_buffer_->SetDecodeErrorMode(kWithErrors); | 2086 jitter_buffer_->SetDecodeErrorMode(kWithErrors); |
2102 // Start with a complete key frame - insert and decode. | 2087 // Start with a complete key frame - insert and decode. |
2103 packet_->frameType = kVideoFrameKey; | 2088 packet_->frameType = kVideoFrameKey; |
2104 packet_->isFirstPacket = true; | 2089 packet_->isFirstPacket = true; |
2105 packet_->markerBit = true; | 2090 packet_->markerBit = true; |
2106 bool retransmitted = false; | 2091 bool retransmitted = false; |
2107 | 2092 |
2108 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, | 2093 EXPECT_EQ(kCompleteSession, |
2109 &retransmitted)); | 2094 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
2110 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); | 2095 VCMEncodedFrame* frame_out = DecodeCompleteFrame(); |
2111 EXPECT_TRUE(frame_out != NULL); | 2096 EXPECT_TRUE(frame_out != NULL); |
2112 jitter_buffer_->ReleaseFrame(frame_out); | 2097 jitter_buffer_->ReleaseFrame(frame_out); |
2113 | 2098 |
2114 packet_->seqNum += 2; | 2099 packet_->seqNum += 2; |
2115 packet_->timestamp += 33 * 90; | 2100 packet_->timestamp += 33 * 90; |
2116 packet_->frameType = kVideoFrameDelta; | 2101 packet_->frameType = kVideoFrameDelta; |
2117 packet_->isFirstPacket = false; | 2102 packet_->isFirstPacket = false; |
2118 packet_->markerBit = false; | 2103 packet_->markerBit = false; |
2119 | 2104 |
2120 | 2105 EXPECT_EQ(kDecodableSession, |
2121 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 2106 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
2122 &retransmitted)); | |
2123 | 2107 |
2124 frame_out = DecodeIncompleteFrame(); | 2108 frame_out = DecodeIncompleteFrame(); |
2125 EXPECT_TRUE(frame_out == NULL); | 2109 EXPECT_TRUE(frame_out == NULL); |
2126 | 2110 |
2127 packet_->seqNum += 2; | 2111 packet_->seqNum += 2; |
2128 packet_->timestamp += 33 * 90; | 2112 packet_->timestamp += 33 * 90; |
2129 packet_->isFirstPacket = true; | 2113 packet_->isFirstPacket = true; |
2130 | 2114 |
2131 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_, | 2115 EXPECT_EQ(kDecodableSession, |
2132 &retransmitted)); | 2116 jitter_buffer_->InsertPacket(*packet_, &retransmitted)); |
2133 | 2117 |
2134 frame_out = DecodeIncompleteFrame(); | 2118 frame_out = DecodeIncompleteFrame(); |
2135 CheckOutFrame(frame_out, packet_->sizeBytes, false); | 2119 CheckOutFrame(frame_out, packet_->sizeBytes, false); |
2136 jitter_buffer_->ReleaseFrame(frame_out); | 2120 jitter_buffer_->ReleaseFrame(frame_out); |
2137 } | 2121 } |
2138 | 2122 |
2139 TEST_F(TestRunningJitterBuffer, Full) { | 2123 TEST_F(TestRunningJitterBuffer, Full) { |
2140 // Make sure the jitter doesn't request a keyframe after too much non- | 2124 // Make sure the jitter doesn't request a keyframe after too much non- |
2141 // decodable frames. | 2125 // decodable frames. |
2142 jitter_buffer_->SetNackMode(kNack, -1, -1); | 2126 jitter_buffer_->SetNackMode(kNack, -1, -1); |
2143 jitter_buffer_->SetNackSettings(kMaxNumberOfFrames, | 2127 jitter_buffer_->SetNackSettings(kMaxNumberOfFrames, kMaxNumberOfFrames, 0); |
2144 kMaxNumberOfFrames, 0); | |
2145 // Insert a key frame and decode it. | 2128 // Insert a key frame and decode it. |
2146 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError); | 2129 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError); |
2147 EXPECT_TRUE(DecodeCompleteFrame()); | 2130 EXPECT_TRUE(DecodeCompleteFrame()); |
2148 DropFrame(1); | 2131 DropFrame(1); |
2149 // Fill the jitter buffer. | 2132 // Fill the jitter buffer. |
2150 EXPECT_GE(InsertFrames(kMaxNumberOfFrames, kVideoFrameDelta), kNoError); | 2133 EXPECT_GE(InsertFrames(kMaxNumberOfFrames, kVideoFrameDelta), kNoError); |
2151 // Make sure we can't decode these frames. | 2134 // Make sure we can't decode these frames. |
2152 EXPECT_FALSE(DecodeCompleteFrame()); | 2135 EXPECT_FALSE(DecodeCompleteFrame()); |
2153 // This frame will make the jitter buffer recycle frames until a key frame. | 2136 // This frame will make the jitter buffer recycle frames until a key frame. |
2154 // Since none is found it will have to wait until the next key frame before | 2137 // Since none is found it will have to wait until the next key frame before |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2283 | 2266 |
2284 TEST_F(TestJitterBufferNack, NackTooOldPackets) { | 2267 TEST_F(TestJitterBufferNack, NackTooOldPackets) { |
2285 // Insert a key frame and decode it. | 2268 // Insert a key frame and decode it. |
2286 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError); | 2269 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError); |
2287 EXPECT_TRUE(DecodeCompleteFrame()); | 2270 EXPECT_TRUE(DecodeCompleteFrame()); |
2288 | 2271 |
2289 // Drop one frame and insert |kNackHistoryLength| to trigger NACKing a too | 2272 // Drop one frame and insert |kNackHistoryLength| to trigger NACKing a too |
2290 // old packet. | 2273 // old packet. |
2291 DropFrame(1); | 2274 DropFrame(1); |
2292 // Insert a frame which should trigger a recycle until the next key frame. | 2275 // Insert a frame which should trigger a recycle until the next key frame. |
2293 EXPECT_EQ(kFlushIndicator, InsertFrames(oldest_packet_to_nack_ + 1, | 2276 EXPECT_EQ(kFlushIndicator, |
2294 kVideoFrameDelta)); | 2277 InsertFrames(oldest_packet_to_nack_ + 1, kVideoFrameDelta)); |
2295 EXPECT_FALSE(DecodeCompleteFrame()); | 2278 EXPECT_FALSE(DecodeCompleteFrame()); |
2296 | 2279 |
2297 bool request_key_frame = false; | 2280 bool request_key_frame = false; |
2298 std::vector<uint16_t> nack_list = | 2281 std::vector<uint16_t> nack_list = |
2299 jitter_buffer_->GetNackList(&request_key_frame); | 2282 jitter_buffer_->GetNackList(&request_key_frame); |
2300 // No key frame will be requested since the jitter buffer is empty. | 2283 // No key frame will be requested since the jitter buffer is empty. |
2301 EXPECT_FALSE(request_key_frame); | 2284 EXPECT_FALSE(request_key_frame); |
2302 EXPECT_EQ(0u, nack_list.size()); | 2285 EXPECT_EQ(0u, nack_list.size()); |
2303 | 2286 |
2304 EXPECT_GE(InsertFrame(kVideoFrameDelta), kNoError); | 2287 EXPECT_GE(InsertFrame(kVideoFrameDelta), kNoError); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2375 jitter_buffer_->GetNackList(&request_key_frame); | 2358 jitter_buffer_->GetNackList(&request_key_frame); |
2376 // No list generated, and a key frame request is signaled. | 2359 // No list generated, and a key frame request is signaled. |
2377 EXPECT_EQ(0u, nack_list.size()); | 2360 EXPECT_EQ(0u, nack_list.size()); |
2378 EXPECT_TRUE(request_key_frame); | 2361 EXPECT_TRUE(request_key_frame); |
2379 } | 2362 } |
2380 | 2363 |
2381 TEST_F(TestJitterBufferNack, NackListBuiltBeforeFirstDecode) { | 2364 TEST_F(TestJitterBufferNack, NackListBuiltBeforeFirstDecode) { |
2382 stream_generator_->Init(0, clock_->TimeInMilliseconds()); | 2365 stream_generator_->Init(0, clock_->TimeInMilliseconds()); |
2383 InsertFrame(kVideoFrameKey); | 2366 InsertFrame(kVideoFrameKey); |
2384 stream_generator_->GenerateFrame(kVideoFrameDelta, 2, 0, | 2367 stream_generator_->GenerateFrame(kVideoFrameDelta, 2, 0, |
2385 clock_->TimeInMilliseconds()); | 2368 clock_->TimeInMilliseconds()); |
2386 stream_generator_->NextPacket(NULL); // Drop packet. | 2369 stream_generator_->NextPacket(NULL); // Drop packet. |
2387 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); | 2370 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); |
2388 EXPECT_TRUE(DecodeCompleteFrame()); | 2371 EXPECT_TRUE(DecodeCompleteFrame()); |
2389 bool extended = false; | 2372 bool extended = false; |
2390 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended); | 2373 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended); |
2391 EXPECT_EQ(1u, nack_list.size()); | 2374 EXPECT_EQ(1u, nack_list.size()); |
2392 } | 2375 } |
2393 | 2376 |
2394 TEST_F(TestJitterBufferNack, VerifyRetransmittedFlag) { | 2377 TEST_F(TestJitterBufferNack, VerifyRetransmittedFlag) { |
2395 stream_generator_->Init(0, clock_->TimeInMilliseconds()); | 2378 stream_generator_->Init(0, clock_->TimeInMilliseconds()); |
2396 stream_generator_->GenerateFrame(kVideoFrameKey, 3, 0, | 2379 stream_generator_->GenerateFrame(kVideoFrameKey, 3, 0, |
2397 clock_->TimeInMilliseconds()); | 2380 clock_->TimeInMilliseconds()); |
2398 VCMPacket packet; | 2381 VCMPacket packet; |
2399 stream_generator_->PopPacket(&packet, 0); | 2382 stream_generator_->PopPacket(&packet, 0); |
2400 bool retransmitted = false; | 2383 bool retransmitted = false; |
2401 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(packet, &retransmitted)); | 2384 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(packet, &retransmitted)); |
2402 EXPECT_FALSE(retransmitted); | 2385 EXPECT_FALSE(retransmitted); |
2403 // Drop second packet. | 2386 // Drop second packet. |
2404 stream_generator_->PopPacket(&packet, 1); | 2387 stream_generator_->PopPacket(&packet, 1); |
2405 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(packet, &retransmitted)); | 2388 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(packet, &retransmitted)); |
2406 EXPECT_FALSE(retransmitted); | 2389 EXPECT_FALSE(retransmitted); |
2407 EXPECT_FALSE(DecodeCompleteFrame()); | 2390 EXPECT_FALSE(DecodeCompleteFrame()); |
2408 bool extended = false; | 2391 bool extended = false; |
2409 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended); | 2392 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended); |
2410 EXPECT_EQ(1u, nack_list.size()); | 2393 EXPECT_EQ(1u, nack_list.size()); |
2411 stream_generator_->PopPacket(&packet, 0); | 2394 stream_generator_->PopPacket(&packet, 0); |
2412 EXPECT_EQ(packet.seqNum, nack_list[0]); | 2395 EXPECT_EQ(packet.seqNum, nack_list[0]); |
2413 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(packet, | 2396 EXPECT_EQ(kCompleteSession, |
2414 &retransmitted)); | 2397 jitter_buffer_->InsertPacket(packet, &retransmitted)); |
2415 EXPECT_TRUE(retransmitted); | 2398 EXPECT_TRUE(retransmitted); |
2416 EXPECT_TRUE(DecodeCompleteFrame()); | 2399 EXPECT_TRUE(DecodeCompleteFrame()); |
2417 } | 2400 } |
2418 | 2401 |
2419 TEST_F(TestJitterBufferNack, UseNackToRecoverFirstKeyFrame) { | 2402 TEST_F(TestJitterBufferNack, UseNackToRecoverFirstKeyFrame) { |
2420 stream_generator_->Init(0, clock_->TimeInMilliseconds()); | 2403 stream_generator_->Init(0, clock_->TimeInMilliseconds()); |
2421 stream_generator_->GenerateFrame(kVideoFrameKey, 3, 0, | 2404 stream_generator_->GenerateFrame(kVideoFrameKey, 3, 0, |
2422 clock_->TimeInMilliseconds()); | 2405 clock_->TimeInMilliseconds()); |
2423 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); | 2406 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); |
2424 // Drop second packet. | 2407 // Drop second packet. |
2425 EXPECT_EQ(kIncomplete, InsertPacketAndPop(1)); | 2408 EXPECT_EQ(kIncomplete, InsertPacketAndPop(1)); |
2426 EXPECT_FALSE(DecodeCompleteFrame()); | 2409 EXPECT_FALSE(DecodeCompleteFrame()); |
2427 bool extended = false; | 2410 bool extended = false; |
2428 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended); | 2411 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended); |
2429 EXPECT_EQ(1u, nack_list.size()); | 2412 EXPECT_EQ(1u, nack_list.size()); |
2430 VCMPacket packet; | 2413 VCMPacket packet; |
2431 stream_generator_->GetPacket(&packet, 0); | 2414 stream_generator_->GetPacket(&packet, 0); |
2432 EXPECT_EQ(packet.seqNum, nack_list[0]); | 2415 EXPECT_EQ(packet.seqNum, nack_list[0]); |
(...skipping 27 matching lines...) Expand all Loading... |
2460 EXPECT_EQ(kNack, jitter_buffer_->nack_mode()); | 2443 EXPECT_EQ(kNack, jitter_buffer_->nack_mode()); |
2461 jitter_buffer_->SetDecodeErrorMode(kWithErrors); | 2444 jitter_buffer_->SetDecodeErrorMode(kWithErrors); |
2462 | 2445 |
2463 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError); | 2446 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError); |
2464 EXPECT_TRUE(DecodeIncompleteFrame()); | 2447 EXPECT_TRUE(DecodeIncompleteFrame()); |
2465 | 2448 |
2466 // ---------------------------------------------------------------- | 2449 // ---------------------------------------------------------------- |
2467 // | 1 | 2 | .. | 8 | 9 | x | 11 | 12 | .. | 19 | x | 21 | .. | 100 | | 2450 // | 1 | 2 | .. | 8 | 9 | x | 11 | 12 | .. | 19 | x | 21 | .. | 100 | |
2468 // ---------------------------------------------------------------- | 2451 // ---------------------------------------------------------------- |
2469 stream_generator_->GenerateFrame(kVideoFrameKey, 100, 0, | 2452 stream_generator_->GenerateFrame(kVideoFrameKey, 100, 0, |
2470 clock_->TimeInMilliseconds()); | 2453 clock_->TimeInMilliseconds()); |
2471 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); | 2454 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); |
2472 EXPECT_EQ(kDecodableSession, InsertPacketAndPop(0)); | 2455 EXPECT_EQ(kDecodableSession, InsertPacketAndPop(0)); |
2473 // Verify that the frame is incomplete. | 2456 // Verify that the frame is incomplete. |
2474 EXPECT_FALSE(DecodeCompleteFrame()); | 2457 EXPECT_FALSE(DecodeCompleteFrame()); |
2475 while (stream_generator_->PacketsRemaining() > 1) { | 2458 while (stream_generator_->PacketsRemaining() > 1) { |
2476 if (stream_generator_->NextSequenceNumber() % 10 != 0) { | 2459 if (stream_generator_->NextSequenceNumber() % 10 != 0) { |
2477 EXPECT_EQ(kDecodableSession, InsertPacketAndPop(0)); | 2460 EXPECT_EQ(kDecodableSession, InsertPacketAndPop(0)); |
2478 } else { | 2461 } else { |
2479 stream_generator_->NextPacket(NULL); // Drop packet | 2462 stream_generator_->NextPacket(NULL); // Drop packet |
2480 } | 2463 } |
(...skipping 15 matching lines...) Expand all Loading... |
2496 TEST_F(TestJitterBufferNack, NormalOperationWrap) { | 2479 TEST_F(TestJitterBufferNack, NormalOperationWrap) { |
2497 bool request_key_frame = false; | 2480 bool request_key_frame = false; |
2498 // ------- ------------------------------------------------------------ | 2481 // ------- ------------------------------------------------------------ |
2499 // | 65532 | | 65533 | 65534 | 65535 | x | 1 | .. | 9 | x | 11 |.....| 96 | | 2482 // | 65532 | | 65533 | 65534 | 65535 | x | 1 | .. | 9 | x | 11 |.....| 96 | |
2500 // ------- ------------------------------------------------------------ | 2483 // ------- ------------------------------------------------------------ |
2501 stream_generator_->Init(65532, clock_->TimeInMilliseconds()); | 2484 stream_generator_->Init(65532, clock_->TimeInMilliseconds()); |
2502 InsertFrame(kVideoFrameKey); | 2485 InsertFrame(kVideoFrameKey); |
2503 EXPECT_FALSE(request_key_frame); | 2486 EXPECT_FALSE(request_key_frame); |
2504 EXPECT_TRUE(DecodeCompleteFrame()); | 2487 EXPECT_TRUE(DecodeCompleteFrame()); |
2505 stream_generator_->GenerateFrame(kVideoFrameDelta, 100, 0, | 2488 stream_generator_->GenerateFrame(kVideoFrameDelta, 100, 0, |
2506 clock_->TimeInMilliseconds()); | 2489 clock_->TimeInMilliseconds()); |
2507 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); | 2490 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); |
2508 while (stream_generator_->PacketsRemaining() > 1) { | 2491 while (stream_generator_->PacketsRemaining() > 1) { |
2509 if (stream_generator_->NextSequenceNumber() % 10 != 0) { | 2492 if (stream_generator_->NextSequenceNumber() % 10 != 0) { |
2510 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); | 2493 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); |
2511 EXPECT_FALSE(request_key_frame); | 2494 EXPECT_FALSE(request_key_frame); |
2512 } else { | 2495 } else { |
2513 stream_generator_->NextPacket(NULL); // Drop packet | 2496 stream_generator_->NextPacket(NULL); // Drop packet |
2514 } | 2497 } |
2515 } | 2498 } |
2516 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); | 2499 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0)); |
(...skipping 16 matching lines...) Expand all Loading... |
2533 // | 65532 | 65533 | 65534 | x | 0 | 1 | | 2516 // | 65532 | 65533 | 65534 | x | 0 | 1 | |
2534 // ----------------------------------- | 2517 // ----------------------------------- |
2535 stream_generator_->Init(65532, clock_->TimeInMilliseconds()); | 2518 stream_generator_->Init(65532, clock_->TimeInMilliseconds()); |
2536 InsertFrame(kVideoFrameKey); | 2519 InsertFrame(kVideoFrameKey); |
2537 EXPECT_FALSE(request_key_frame); | 2520 EXPECT_FALSE(request_key_frame); |
2538 EXPECT_TRUE(DecodeCompleteFrame()); | 2521 EXPECT_TRUE(DecodeCompleteFrame()); |
2539 stream_generator_->GenerateFrame(kVideoFrameDelta, 1, 0, | 2522 stream_generator_->GenerateFrame(kVideoFrameDelta, 1, 0, |
2540 clock_->TimeInMilliseconds()); | 2523 clock_->TimeInMilliseconds()); |
2541 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); | 2524 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); |
2542 for (int i = 0; i < 5; ++i) { | 2525 for (int i = 0; i < 5; ++i) { |
2543 if (stream_generator_->NextSequenceNumber() != 65535) { | 2526 if (stream_generator_->NextSequenceNumber() != 65535) { |
2544 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0)); | 2527 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0)); |
2545 EXPECT_FALSE(request_key_frame); | 2528 EXPECT_FALSE(request_key_frame); |
2546 } else { | 2529 } else { |
2547 stream_generator_->NextPacket(NULL); // Drop packet | 2530 stream_generator_->NextPacket(NULL); // Drop packet |
2548 } | 2531 } |
2549 stream_generator_->GenerateFrame(kVideoFrameDelta, 1, 0, | 2532 stream_generator_->GenerateFrame(kVideoFrameDelta, 1, 0, |
2550 clock_->TimeInMilliseconds()); | 2533 clock_->TimeInMilliseconds()); |
2551 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); | 2534 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); |
2552 } | 2535 } |
2553 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0)); | 2536 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0)); |
(...skipping 25 matching lines...) Expand all Loading... |
2579 | 2562 |
2580 // Stream should be decodable from this point. | 2563 // Stream should be decodable from this point. |
2581 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); | 2564 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); |
2582 InsertFrame(kVideoFrameDelta); | 2565 InsertFrame(kVideoFrameDelta); |
2583 EXPECT_TRUE(DecodeCompleteFrame()); | 2566 EXPECT_TRUE(DecodeCompleteFrame()); |
2584 nack_list = jitter_buffer_->GetNackList(&extended); | 2567 nack_list = jitter_buffer_->GetNackList(&extended); |
2585 EXPECT_EQ(0u, nack_list.size()); | 2568 EXPECT_EQ(0u, nack_list.size()); |
2586 } | 2569 } |
2587 | 2570 |
2588 } // namespace webrtc | 2571 } // namespace webrtc |
OLD | NEW |