OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return packet_buffer_->InsertPacket(&packet); | 91 return packet_buffer_->InsertPacket(&packet); |
92 } | 92 } |
93 | 93 |
94 void CheckFrame(uint16_t first_seq_num) { | 94 void CheckFrame(uint16_t first_seq_num) { |
95 auto frame_it = frames_from_callback_.find(first_seq_num); | 95 auto frame_it = frames_from_callback_.find(first_seq_num); |
96 ASSERT_FALSE(frame_it == frames_from_callback_.end()) | 96 ASSERT_FALSE(frame_it == frames_from_callback_.end()) |
97 << "Could not find frame with first sequence number " << first_seq_num | 97 << "Could not find frame with first sequence number " << first_seq_num |
98 << "."; | 98 << "."; |
99 } | 99 } |
100 | 100 |
101 static constexpr int kStartSize = 16; | 101 const int kStartSize = 16; |
102 static constexpr int kMaxSize = 64; | 102 const int kMaxSize = 64; |
103 | 103 |
104 Random rand_; | 104 Random rand_; |
105 std::unique_ptr<SimulatedClock> clock_; | 105 std::unique_ptr<SimulatedClock> clock_; |
106 rtc::scoped_refptr<PacketBuffer> packet_buffer_; | 106 rtc::scoped_refptr<PacketBuffer> packet_buffer_; |
107 std::map<uint16_t, std::unique_ptr<RtpFrameObject>> frames_from_callback_; | 107 std::map<uint16_t, std::unique_ptr<RtpFrameObject>> frames_from_callback_; |
108 }; | 108 }; |
109 | 109 |
110 TEST_F(TestPacketBuffer, InsertOnePacket) { | 110 TEST_F(TestPacketBuffer, InsertOnePacket) { |
111 const uint16_t seq_num = Rand(); | 111 const uint16_t seq_num = Rand(); |
112 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); | 112 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many_data), many)); | 367 Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many_data), many)); |
368 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, | 368 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, |
369 sizeof(bitstream_data), bitstream)); | 369 sizeof(bitstream_data), bitstream)); |
370 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, | 370 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, |
371 sizeof(such_data), such)); | 371 sizeof(such_data), such)); |
372 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, | 372 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, |
373 sizeof(data_data), data)); | 373 sizeof(data_data), data)); |
374 | 374 |
375 ASSERT_EQ(1UL, frames_from_callback_.size()); | 375 ASSERT_EQ(1UL, frames_from_callback_.size()); |
376 CheckFrame(seq_num); | 376 CheckFrame(seq_num); |
377 EXPECT_EQ(frames_from_callback_[seq_num]->size(), sizeof(result)); | |
378 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); | 377 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); |
379 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); | 378 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); |
380 } | 379 } |
381 | 380 |
382 TEST_F(TestPacketBuffer, GetBitstreamOneFrameFullBuffer) { | |
383 uint8_t* data_arr[kStartSize]; | |
384 uint8_t expected[kStartSize]; | |
385 uint8_t result[kStartSize]; | |
386 | |
387 for (uint8_t i = 0; i < kStartSize; ++i) { | |
388 data_arr[i] = new uint8_t[1]; | |
389 data_arr[i][0] = i; | |
390 expected[i] = i; | |
391 } | |
392 | |
393 EXPECT_TRUE(Insert(0, kKeyFrame, kFirst, kNotLast, 1, data_arr[0])); | |
394 for (uint8_t i = 1; i < kStartSize - 1; ++i) | |
395 EXPECT_TRUE(Insert(i, kKeyFrame, kNotFirst, kNotLast, 1, data_arr[i])); | |
396 EXPECT_TRUE(Insert(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1, | |
397 data_arr[kStartSize - 1])); | |
398 | |
399 ASSERT_EQ(1UL, frames_from_callback_.size()); | |
400 CheckFrame(0); | |
401 EXPECT_EQ(frames_from_callback_[0]->size(), static_cast<size_t>(kStartSize)); | |
402 EXPECT_TRUE(frames_from_callback_[0]->GetBitstream(result)); | |
403 EXPECT_EQ(memcmp(result, expected, kStartSize), 0); | |
404 } | |
405 | |
406 TEST_F(TestPacketBuffer, GetBitstreamOneFrameFullBufferH264) { | |
407 uint8_t* data_arr[kStartSize]; | |
408 uint8_t expected[kStartSize]; | |
409 uint8_t result[kStartSize]; | |
410 | |
411 for (uint8_t i = 0; i < kStartSize; ++i) { | |
412 data_arr[i] = new uint8_t[1]; | |
413 data_arr[i][0] = i; | |
414 expected[i] = i; | |
415 } | |
416 | |
417 EXPECT_TRUE(InsertH264(0, kKeyFrame, kFirst, kNotLast, 1, 1, data_arr[0])); | |
418 for (uint8_t i = 1; i < kStartSize - 1; ++i) { | |
419 EXPECT_TRUE( | |
420 InsertH264(i, kKeyFrame, kNotFirst, kNotLast, 1, 1, data_arr[i])); | |
421 } | |
422 EXPECT_TRUE(InsertH264(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1, 1, | |
423 data_arr[kStartSize - 1])); | |
424 | |
425 ASSERT_EQ(1UL, frames_from_callback_.size()); | |
426 CheckFrame(0); | |
427 EXPECT_EQ(frames_from_callback_[0]->size(), static_cast<size_t>(kStartSize)); | |
428 EXPECT_TRUE(frames_from_callback_[0]->GetBitstream(result)); | |
429 EXPECT_EQ(memcmp(result, expected, kStartSize), 0); | |
430 } | |
431 | |
432 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) { | 381 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) { |
433 uint16_t seq_num = Rand(); | 382 uint16_t seq_num = Rand(); |
434 uint8_t data_data[] = "some plain old data"; | 383 uint8_t data_data[] = "some plain old data"; |
435 uint8_t* data = new uint8_t[sizeof(data_data)]; | 384 uint8_t* data = new uint8_t[sizeof(data_data)]; |
436 memcpy(data, data_data, sizeof(data_data)); | 385 memcpy(data, data_data, sizeof(data_data)); |
437 | 386 |
438 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time. | 387 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time. |
439 std::unique_ptr<uint8_t[]> result( | 388 std::unique_ptr<uint8_t[]> result( |
440 new uint8_t[sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264]); | 389 new uint8_t[sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264]); |
441 | 390 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 TEST_F(TestPacketBuffer, OneFrameFillBufferH264) { | 541 TEST_F(TestPacketBuffer, OneFrameFillBufferH264) { |
593 InsertH264(0, kKeyFrame, kFirst, kNotLast, 1000); | 542 InsertH264(0, kKeyFrame, kFirst, kNotLast, 1000); |
594 for (int i = 1; i < kStartSize - 1; ++i) | 543 for (int i = 1; i < kStartSize - 1; ++i) |
595 InsertH264(i, kKeyFrame, kNotFirst, kNotLast, 1000); | 544 InsertH264(i, kKeyFrame, kNotFirst, kNotLast, 1000); |
596 InsertH264(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1000); | 545 InsertH264(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1000); |
597 | 546 |
598 EXPECT_EQ(1UL, frames_from_callback_.size()); | 547 EXPECT_EQ(1UL, frames_from_callback_.size()); |
599 CheckFrame(0); | 548 CheckFrame(0); |
600 } | 549 } |
601 | 550 |
602 TEST_F(TestPacketBuffer, CreateFramesAfterFilledBufferH264) { | |
603 InsertH264(kStartSize - 2, kKeyFrame, kFirst, kLast, 0); | |
604 ASSERT_EQ(1UL, frames_from_callback_.size()); | |
605 frames_from_callback_.clear(); | |
606 | |
607 InsertH264(kStartSize, kDeltaFrame, kFirst, kNotLast, 2000); | |
608 for (int i = 1; i < kStartSize; ++i) | |
609 InsertH264(kStartSize + i, kDeltaFrame, kNotFirst, kNotLast, 2000); | |
610 InsertH264(kStartSize + kStartSize, kDeltaFrame, kNotFirst, kLast, 2000); | |
611 ASSERT_EQ(0UL, frames_from_callback_.size()); | |
612 | |
613 InsertH264(kStartSize - 1, kKeyFrame, kFirst, kLast, 1000); | |
614 ASSERT_EQ(2UL, frames_from_callback_.size()); | |
615 CheckFrame(kStartSize - 1); | |
616 CheckFrame(kStartSize); | |
617 } | |
618 | |
619 TEST_F(TestPacketBuffer, OneFrameMaxSeqNumH264) { | 551 TEST_F(TestPacketBuffer, OneFrameMaxSeqNumH264) { |
620 InsertH264(65534, kKeyFrame, kFirst, kNotLast, 1000); | 552 InsertH264(65534, kKeyFrame, kFirst, kNotLast, 1000); |
621 InsertH264(65535, kKeyFrame, kNotFirst, kLast, 1000); | 553 InsertH264(65535, kKeyFrame, kNotFirst, kLast, 1000); |
622 | 554 |
623 EXPECT_EQ(1UL, frames_from_callback_.size()); | 555 EXPECT_EQ(1UL, frames_from_callback_.size()); |
624 CheckFrame(65534); | 556 CheckFrame(65534); |
625 } | 557 } |
626 | 558 |
627 TEST_F(TestPacketBuffer, ClearMissingPacketsOnKeyframeH264) { | 559 TEST_F(TestPacketBuffer, ClearMissingPacketsOnKeyframeH264) { |
628 InsertH264(0, kKeyFrame, kFirst, kLast, 1000); | 560 InsertH264(0, kKeyFrame, kFirst, kLast, 1000); |
(...skipping 18 matching lines...) Expand all Loading... |
647 | 579 |
648 ASSERT_EQ(1UL, frames_from_callback_.size()); | 580 ASSERT_EQ(1UL, frames_from_callback_.size()); |
649 packet_buffer_->PaddingReceived(1); | 581 packet_buffer_->PaddingReceived(1); |
650 ASSERT_EQ(2UL, frames_from_callback_.size()); | 582 ASSERT_EQ(2UL, frames_from_callback_.size()); |
651 CheckFrame(0); | 583 CheckFrame(0); |
652 CheckFrame(2); | 584 CheckFrame(2); |
653 } | 585 } |
654 | 586 |
655 } // namespace video_coding | 587 } // namespace video_coding |
656 } // namespace webrtc | 588 } // namespace webrtc |
OLD | NEW |