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 const int kStartSize = 16; | 101 static constexpr int kStartSize = 16; |
102 const int kMaxSize = 64; | 102 static constexpr 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)); |
377 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); | 378 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); |
378 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); | 379 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); |
379 } | 380 } |
380 | 381 |
| 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 |
381 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) { | 432 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) { |
382 uint16_t seq_num = Rand(); | 433 uint16_t seq_num = Rand(); |
383 uint8_t data_data[] = "some plain old data"; | 434 uint8_t data_data[] = "some plain old data"; |
384 uint8_t* data = new uint8_t[sizeof(data_data)]; | 435 uint8_t* data = new uint8_t[sizeof(data_data)]; |
385 memcpy(data, data_data, sizeof(data_data)); | 436 memcpy(data, data_data, sizeof(data_data)); |
386 | 437 |
387 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time. | 438 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time. |
388 std::unique_ptr<uint8_t[]> result( | 439 std::unique_ptr<uint8_t[]> result( |
389 new uint8_t[sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264]); | 440 new uint8_t[sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264]); |
390 | 441 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 TEST_F(TestPacketBuffer, OneFrameFillBufferH264) { | 592 TEST_F(TestPacketBuffer, OneFrameFillBufferH264) { |
542 InsertH264(0, kKeyFrame, kFirst, kNotLast, 1000); | 593 InsertH264(0, kKeyFrame, kFirst, kNotLast, 1000); |
543 for (int i = 1; i < kStartSize - 1; ++i) | 594 for (int i = 1; i < kStartSize - 1; ++i) |
544 InsertH264(i, kKeyFrame, kNotFirst, kNotLast, 1000); | 595 InsertH264(i, kKeyFrame, kNotFirst, kNotLast, 1000); |
545 InsertH264(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1000); | 596 InsertH264(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1000); |
546 | 597 |
547 EXPECT_EQ(1UL, frames_from_callback_.size()); | 598 EXPECT_EQ(1UL, frames_from_callback_.size()); |
548 CheckFrame(0); | 599 CheckFrame(0); |
549 } | 600 } |
550 | 601 |
| 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 |
551 TEST_F(TestPacketBuffer, OneFrameMaxSeqNumH264) { | 619 TEST_F(TestPacketBuffer, OneFrameMaxSeqNumH264) { |
552 InsertH264(65534, kKeyFrame, kFirst, kNotLast, 1000); | 620 InsertH264(65534, kKeyFrame, kFirst, kNotLast, 1000); |
553 InsertH264(65535, kKeyFrame, kNotFirst, kLast, 1000); | 621 InsertH264(65535, kKeyFrame, kNotFirst, kLast, 1000); |
554 | 622 |
555 EXPECT_EQ(1UL, frames_from_callback_.size()); | 623 EXPECT_EQ(1UL, frames_from_callback_.size()); |
556 CheckFrame(65534); | 624 CheckFrame(65534); |
557 } | 625 } |
558 | 626 |
559 TEST_F(TestPacketBuffer, ClearMissingPacketsOnKeyframeH264) { | 627 TEST_F(TestPacketBuffer, ClearMissingPacketsOnKeyframeH264) { |
560 InsertH264(0, kKeyFrame, kFirst, kLast, 1000); | 628 InsertH264(0, kKeyFrame, kFirst, kLast, 1000); |
(...skipping 18 matching lines...) Expand all Loading... |
579 | 647 |
580 ASSERT_EQ(1UL, frames_from_callback_.size()); | 648 ASSERT_EQ(1UL, frames_from_callback_.size()); |
581 packet_buffer_->PaddingReceived(1); | 649 packet_buffer_->PaddingReceived(1); |
582 ASSERT_EQ(2UL, frames_from_callback_.size()); | 650 ASSERT_EQ(2UL, frames_from_callback_.size()); |
583 CheckFrame(0); | 651 CheckFrame(0); |
584 CheckFrame(2); | 652 CheckFrame(2); |
585 } | 653 } |
586 | 654 |
587 } // namespace video_coding | 655 } // namespace video_coding |
588 } // namespace webrtc | 656 } // namespace webrtc |
OLD | NEW |