Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: webrtc/modules/video_coding/video_packet_buffer_unittest.cc

Issue 2989313003: Reland of Fix off-by-one bugs in PacketBuffer when the buffer is filled with a single frame. (Closed)
Patch Set: Memcpy fix Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/video_coding/packet_buffer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many_data), many)); 391 Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many_data), many));
392 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, 392 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast,
393 sizeof(bitstream_data), bitstream)); 393 sizeof(bitstream_data), bitstream));
394 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, 394 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast,
395 sizeof(such_data), such)); 395 sizeof(such_data), such));
396 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, 396 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast,
397 sizeof(data_data), data)); 397 sizeof(data_data), data));
398 398
399 ASSERT_EQ(1UL, frames_from_callback_.size()); 399 ASSERT_EQ(1UL, frames_from_callback_.size());
400 CheckFrame(seq_num); 400 CheckFrame(seq_num);
401 EXPECT_EQ(frames_from_callback_[seq_num]->size(), sizeof(result));
401 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); 402 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result));
402 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); 403 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0);
403 } 404 }
404 405
406 TEST_F(TestPacketBuffer, GetBitstreamOneFrameOnePacket) {
407 uint8_t bitstream_data[] = "All the bitstream data for this frame!";
408 uint8_t result[sizeof(bitstream_data)];
409 uint8_t* data = new uint8_t[sizeof(bitstream_data)];
410 memcpy(data, bitstream_data, sizeof(bitstream_data));
411
412 EXPECT_TRUE(
413 Insert(0, kKeyFrame, kFirst, kLast, sizeof(bitstream_data), data));
414
415 ASSERT_EQ(1UL, frames_from_callback_.size());
416 CheckFrame(0);
417 EXPECT_EQ(frames_from_callback_[0]->size(), sizeof(bitstream_data));
418 EXPECT_TRUE(frames_from_callback_[0]->GetBitstream(result));
419 EXPECT_EQ(memcmp(result, data, sizeof(bitstream_data)), 0);
420 }
421
422 TEST_F(TestPacketBuffer, GetBitstreamOneFrameFullBuffer) {
423 uint8_t* data_arr[kStartSize];
424 uint8_t expected[kStartSize];
425 uint8_t result[kStartSize];
426
427 for (uint8_t i = 0; i < kStartSize; ++i) {
428 data_arr[i] = new uint8_t[1];
429 data_arr[i][0] = i;
430 expected[i] = i;
431 }
432
433 EXPECT_TRUE(Insert(0, kKeyFrame, kFirst, kNotLast, 1, data_arr[0]));
434 for (uint8_t i = 1; i < kStartSize - 1; ++i)
435 EXPECT_TRUE(Insert(i, kKeyFrame, kNotFirst, kNotLast, 1, data_arr[i]));
436 EXPECT_TRUE(Insert(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1,
437 data_arr[kStartSize - 1]));
438
439 ASSERT_EQ(1UL, frames_from_callback_.size());
440 CheckFrame(0);
441 EXPECT_EQ(frames_from_callback_[0]->size(), static_cast<size_t>(kStartSize));
442 EXPECT_TRUE(frames_from_callback_[0]->GetBitstream(result));
443 EXPECT_EQ(memcmp(result, expected, kStartSize), 0);
444 }
445
446 TEST_F(TestPacketBuffer, GetBitstreamOneFrameFullBufferH264) {
447 uint8_t* data_arr[kStartSize];
448 uint8_t expected[kStartSize];
449 uint8_t result[kStartSize];
450
451 for (uint8_t i = 0; i < kStartSize; ++i) {
452 data_arr[i] = new uint8_t[1];
453 data_arr[i][0] = i;
454 expected[i] = i;
455 }
456
457 EXPECT_TRUE(InsertH264(0, kKeyFrame, kFirst, kNotLast, 1, 1, data_arr[0]));
458 for (uint8_t i = 1; i < kStartSize - 1; ++i) {
459 EXPECT_TRUE(
460 InsertH264(i, kKeyFrame, kNotFirst, kNotLast, 1, 1, data_arr[i]));
461 }
462 EXPECT_TRUE(InsertH264(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1, 1,
463 data_arr[kStartSize - 1]));
464
465 ASSERT_EQ(1UL, frames_from_callback_.size());
466 CheckFrame(0);
467 EXPECT_EQ(frames_from_callback_[0]->size(), static_cast<size_t>(kStartSize));
468 EXPECT_TRUE(frames_from_callback_[0]->GetBitstream(result));
469 EXPECT_EQ(memcmp(result, expected, kStartSize), 0);
470 }
471
405 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) { 472 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) {
406 uint16_t seq_num = Rand(); 473 uint16_t seq_num = Rand();
407 uint8_t data_data[] = "some plain old data"; 474 uint8_t data_data[] = "some plain old data";
408 uint8_t* data = new uint8_t[sizeof(data_data)]; 475 uint8_t* data = new uint8_t[sizeof(data_data)];
409 memcpy(data, data_data, sizeof(data_data)); 476 memcpy(data, data_data, sizeof(data_data));
410 477
411 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time. 478 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time.
412 std::unique_ptr<uint8_t[]> result( 479 std::unique_ptr<uint8_t[]> result(
413 new uint8_t[sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264]); 480 new uint8_t[sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264]);
414 481
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 TEST_F(TestPacketBuffer, OneFrameFillBufferH264) { 632 TEST_F(TestPacketBuffer, OneFrameFillBufferH264) {
566 InsertH264(0, kKeyFrame, kFirst, kNotLast, 1000); 633 InsertH264(0, kKeyFrame, kFirst, kNotLast, 1000);
567 for (int i = 1; i < kStartSize - 1; ++i) 634 for (int i = 1; i < kStartSize - 1; ++i)
568 InsertH264(i, kKeyFrame, kNotFirst, kNotLast, 1000); 635 InsertH264(i, kKeyFrame, kNotFirst, kNotLast, 1000);
569 InsertH264(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1000); 636 InsertH264(kStartSize - 1, kKeyFrame, kNotFirst, kLast, 1000);
570 637
571 EXPECT_EQ(1UL, frames_from_callback_.size()); 638 EXPECT_EQ(1UL, frames_from_callback_.size());
572 CheckFrame(0); 639 CheckFrame(0);
573 } 640 }
574 641
642 TEST_F(TestPacketBuffer, CreateFramesAfterFilledBufferH264) {
643 InsertH264(kStartSize - 2, kKeyFrame, kFirst, kLast, 0);
644 ASSERT_EQ(1UL, frames_from_callback_.size());
645 frames_from_callback_.clear();
646
647 InsertH264(kStartSize, kDeltaFrame, kFirst, kNotLast, 2000);
648 for (int i = 1; i < kStartSize; ++i)
649 InsertH264(kStartSize + i, kDeltaFrame, kNotFirst, kNotLast, 2000);
650 InsertH264(kStartSize + kStartSize, kDeltaFrame, kNotFirst, kLast, 2000);
651 ASSERT_EQ(0UL, frames_from_callback_.size());
652
653 InsertH264(kStartSize - 1, kKeyFrame, kFirst, kLast, 1000);
654 ASSERT_EQ(2UL, frames_from_callback_.size());
655 CheckFrame(kStartSize - 1);
656 CheckFrame(kStartSize);
657 }
658
575 TEST_F(TestPacketBuffer, OneFrameMaxSeqNumH264) { 659 TEST_F(TestPacketBuffer, OneFrameMaxSeqNumH264) {
576 InsertH264(65534, kKeyFrame, kFirst, kNotLast, 1000); 660 InsertH264(65534, kKeyFrame, kFirst, kNotLast, 1000);
577 InsertH264(65535, kKeyFrame, kNotFirst, kLast, 1000); 661 InsertH264(65535, kKeyFrame, kNotFirst, kLast, 1000);
578 662
579 EXPECT_EQ(1UL, frames_from_callback_.size()); 663 EXPECT_EQ(1UL, frames_from_callback_.size());
580 CheckFrame(65534); 664 CheckFrame(65534);
581 } 665 }
582 666
583 TEST_F(TestPacketBuffer, ClearMissingPacketsOnKeyframeH264) { 667 TEST_F(TestPacketBuffer, ClearMissingPacketsOnKeyframeH264) {
584 InsertH264(0, kKeyFrame, kFirst, kLast, 1000); 668 InsertH264(0, kKeyFrame, kFirst, kLast, 1000);
(...skipping 18 matching lines...) Expand all
603 687
604 ASSERT_EQ(1UL, frames_from_callback_.size()); 688 ASSERT_EQ(1UL, frames_from_callback_.size());
605 packet_buffer_->PaddingReceived(1); 689 packet_buffer_->PaddingReceived(1);
606 ASSERT_EQ(2UL, frames_from_callback_.size()); 690 ASSERT_EQ(2UL, frames_from_callback_.size());
607 CheckFrame(0); 691 CheckFrame(0);
608 CheckFrame(2); 692 CheckFrame(2);
609 } 693 }
610 694
611 } // namespace video_coding 695 } // namespace video_coding
612 } // namespace webrtc 696 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/packet_buffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698