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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc

Issue 2238253002: Add pps id and sps id parsing to the h.264 depacketizer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Retry without including h264_common.h Created 4 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/rtp_rtcp/source/rtp_format_h264.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) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 EXPECT_EQ(kVideoFrameKey, payload.frame_type); 524 EXPECT_EQ(kVideoFrameKey, payload.frame_type);
525 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); 525 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec);
526 EXPECT_TRUE(payload.type.Video.isFirstPacket); 526 EXPECT_TRUE(payload.type.Video.isFirstPacket);
527 EXPECT_EQ(kH264SingleNalu, 527 EXPECT_EQ(kH264SingleNalu,
528 payload.type.Video.codecHeader.H264.packetization_type); 528 payload.type.Video.codecHeader.H264.packetization_type);
529 EXPECT_EQ(1280u, payload.type.Video.width); 529 EXPECT_EQ(1280u, payload.type.Video.width);
530 EXPECT_EQ(720u, payload.type.Video.height); 530 EXPECT_EQ(720u, payload.type.Video.height);
531 } 531 }
532 532
533 TEST_F(RtpDepacketizerH264Test, TestStapAKey) { 533 TEST_F(RtpDepacketizerH264Test, TestStapAKey) {
534 uint8_t packet[16] = {kStapA, // F=0, NRI=0, Type=24. 534 // clang-format off
535 // Length, nal header, payload. 535 const NaluInfo kExpectedNalus[] = { {H264::kSps, 0, -1},
536 0, 0x02, kSps, 0xFF, 536 {H264::kPps, 1, 2},
537 0, 0x03, kPps, 0xFF, 0x00, 537 {H264::kIdr, -1, 0} };
538 0, 0x04, kIdr, 0xFF, 0x00, 0x11}; 538 uint8_t packet[] = {kStapA, // F=0, NRI=0, Type=24.
539 // Length, nal header, payload.
540 0, 0x18, kExpectedNalus[0].type,
541 0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05, 0xBA,
542 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00, 0x00, 0x03,
543 0x2A, 0xE0, 0xF1, 0x83, 0x25,
544 0, 0xD, kExpectedNalus[1].type,
545 0x69, 0xFC, 0x0, 0x0, 0x3, 0x0, 0x7, 0xFF, 0xFF, 0xFF,
546 0xF6, 0x40,
547 0, 0xB, kExpectedNalus[2].type,
548 0x85, 0xB8, 0x0, 0x4, 0x0, 0x0, 0x13, 0x93, 0x12, 0x0};
549 // clang-format on
550
539 RtpDepacketizer::ParsedPayload payload; 551 RtpDepacketizer::ParsedPayload payload;
540
541 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); 552 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet)));
542 ExpectPacket(&payload, packet, sizeof(packet)); 553 ExpectPacket(&payload, packet, sizeof(packet));
543 EXPECT_EQ(kVideoFrameKey, payload.frame_type); 554 EXPECT_EQ(kVideoFrameKey, payload.frame_type);
544 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); 555 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec);
545 EXPECT_TRUE(payload.type.Video.isFirstPacket); 556 EXPECT_TRUE(payload.type.Video.isFirstPacket);
546 EXPECT_EQ(kH264StapA, payload.type.Video.codecHeader.H264.packetization_type); 557 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264;
558 EXPECT_EQ(kH264StapA, h264.packetization_type);
547 // NALU type for aggregated packets is the type of the first packet only. 559 // NALU type for aggregated packets is the type of the first packet only.
548 EXPECT_EQ(kSps, payload.type.Video.codecHeader.H264.nalu_type); 560 EXPECT_EQ(kSps, h264.nalu_type);
561 ASSERT_EQ(3u, h264.nalus_length);
562 for (size_t i = 0; i < h264.nalus_length; ++i) {
563 EXPECT_EQ(kExpectedNalus[i].type, h264.nalus[i].type)
564 << "Failed parsing nalu " << i;
565 EXPECT_EQ(kExpectedNalus[i].sps_id, h264.nalus[i].sps_id)
566 << "Failed parsing nalu " << i;
567 EXPECT_EQ(kExpectedNalus[i].pps_id, h264.nalus[i].pps_id)
568 << "Failed parsing nalu " << i;
569 }
549 } 570 }
550 571
551 TEST_F(RtpDepacketizerH264Test, TestStapANaluSpsWithResolution) { 572 TEST_F(RtpDepacketizerH264Test, TestStapANaluSpsWithResolution) {
552 uint8_t packet[] = {kStapA, // F=0, NRI=0, Type=24. 573 uint8_t packet[] = {kStapA, // F=0, NRI=0, Type=24.
553 // Length (2 bytes), nal header, payload. 574 // Length (2 bytes), nal header, payload.
554 0x00, 0x19, kSps, 0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 575 0x00, 0x19, kSps, 0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40,
555 0x50, 0x05, 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 576 0x50, 0x05, 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0,
556 0x00, 0x00, 0x03, 0x2A, 0xE0, 0xF1, 0x83, 0x25, 0x80, 577 0x00, 0x00, 0x03, 0x2A, 0xE0, 0xF1, 0x83, 0x25, 0x80,
557 0x00, 0x03, kIdr, 0xFF, 0x00, 0x00, 0x04, kIdr, 0xFF, 578 0x00, 0x03, kIdr, 0xFF, 0x00, 0x00, 0x04, kIdr, 0xFF,
558 0x00, 0x11}; 579 0x00, 0x11};
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 ExpectPacket(&payload, packet, sizeof(packet)); 711 ExpectPacket(&payload, packet, sizeof(packet));
691 EXPECT_EQ(kVideoFrameDelta, payload.frame_type); 712 EXPECT_EQ(kVideoFrameDelta, payload.frame_type);
692 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); 713 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec);
693 EXPECT_TRUE(payload.type.Video.isFirstPacket); 714 EXPECT_TRUE(payload.type.Video.isFirstPacket);
694 EXPECT_EQ(kH264StapA, payload.type.Video.codecHeader.H264.packetization_type); 715 EXPECT_EQ(kH264StapA, payload.type.Video.codecHeader.H264.packetization_type);
695 // NALU type for aggregated packets is the type of the first packet only. 716 // NALU type for aggregated packets is the type of the first packet only.
696 EXPECT_EQ(kSlice, payload.type.Video.codecHeader.H264.nalu_type); 717 EXPECT_EQ(kSlice, payload.type.Video.codecHeader.H264.nalu_type);
697 } 718 }
698 719
699 TEST_F(RtpDepacketizerH264Test, TestFuA) { 720 TEST_F(RtpDepacketizerH264Test, TestFuA) {
700 uint8_t packet1[3] = { 721 // clang-format off
722 uint8_t packet1[] = {
701 kFuA, // F=0, NRI=0, Type=28. 723 kFuA, // F=0, NRI=0, Type=28.
702 kSBit | kIdr, // FU header. 724 kSBit | kIdr, // FU header.
703 0x01 // Payload. 725 0x85, 0xB8, 0x0, 0x4, 0x0, 0x0, 0x13, 0x93, 0x12, 0x0 // Payload.
704 }; 726 };
705 const uint8_t kExpected1[2] = {kIdr, 0x01}; 727 // clang-format on
728 const uint8_t kExpected1[] = {kIdr, 0x85, 0xB8, 0x0, 0x4, 0x0,
729 0x0, 0x13, 0x93, 0x12, 0x0};
706 730
707 uint8_t packet2[3] = { 731 uint8_t packet2[] = {
708 kFuA, // F=0, NRI=0, Type=28. 732 kFuA, // F=0, NRI=0, Type=28.
709 kIdr, // FU header. 733 kIdr, // FU header.
710 0x02 // Payload. 734 0x02 // Payload.
711 }; 735 };
712 const uint8_t kExpected2[1] = {0x02}; 736 const uint8_t kExpected2[] = {0x02};
713 737
714 uint8_t packet3[3] = { 738 uint8_t packet3[] = {
715 kFuA, // F=0, NRI=0, Type=28. 739 kFuA, // F=0, NRI=0, Type=28.
716 kEBit | kIdr, // FU header. 740 kEBit | kIdr, // FU header.
717 0x03 // Payload. 741 0x03 // Payload.
718 }; 742 };
719 const uint8_t kExpected3[1] = {0x03}; 743 const uint8_t kExpected3[] = {0x03};
720 744
721 RtpDepacketizer::ParsedPayload payload; 745 RtpDepacketizer::ParsedPayload payload;
722 746
723 // We expect that the first packet is one byte shorter since the FU-A header 747 // We expect that the first packet is one byte shorter since the FU-A header
724 // has been replaced by the original nal header. 748 // has been replaced by the original nal header.
725 ASSERT_TRUE(depacketizer_->Parse(&payload, packet1, sizeof(packet1))); 749 ASSERT_TRUE(depacketizer_->Parse(&payload, packet1, sizeof(packet1)));
726 ExpectPacket(&payload, kExpected1, sizeof(kExpected1)); 750 ExpectPacket(&payload, kExpected1, sizeof(kExpected1));
727 EXPECT_EQ(kVideoFrameKey, payload.frame_type); 751 EXPECT_EQ(kVideoFrameKey, payload.frame_type);
728 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); 752 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec);
729 EXPECT_TRUE(payload.type.Video.isFirstPacket); 753 EXPECT_TRUE(payload.type.Video.isFirstPacket);
730 EXPECT_EQ(kH264FuA, payload.type.Video.codecHeader.H264.packetization_type); 754 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264;
731 EXPECT_EQ(kIdr, payload.type.Video.codecHeader.H264.nalu_type); 755 EXPECT_EQ(kH264FuA, h264.packetization_type);
756 EXPECT_EQ(kIdr, h264.nalu_type);
757 ASSERT_EQ(1u, h264.nalus_length);
758 EXPECT_EQ(static_cast<H264::NaluType>(kIdr), h264.nalus[0].type);
759 EXPECT_EQ(-1, h264.nalus[0].sps_id);
760 EXPECT_EQ(0, h264.nalus[0].pps_id);
732 761
733 // Following packets will be 2 bytes shorter since they will only be appended 762 // Following packets will be 2 bytes shorter since they will only be appended
734 // onto the first packet. 763 // onto the first packet.
735 payload = RtpDepacketizer::ParsedPayload(); 764 payload = RtpDepacketizer::ParsedPayload();
736 ASSERT_TRUE(depacketizer_->Parse(&payload, packet2, sizeof(packet2))); 765 ASSERT_TRUE(depacketizer_->Parse(&payload, packet2, sizeof(packet2)));
737 ExpectPacket(&payload, kExpected2, sizeof(kExpected2)); 766 ExpectPacket(&payload, kExpected2, sizeof(kExpected2));
738 EXPECT_EQ(kVideoFrameKey, payload.frame_type); 767 EXPECT_EQ(kVideoFrameKey, payload.frame_type);
739 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); 768 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec);
740 EXPECT_FALSE(payload.type.Video.isFirstPacket); 769 EXPECT_FALSE(payload.type.Video.isFirstPacket);
741 EXPECT_EQ(kH264FuA, payload.type.Video.codecHeader.H264.packetization_type); 770 {
742 EXPECT_EQ(kIdr, payload.type.Video.codecHeader.H264.nalu_type); 771 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264;
772 EXPECT_EQ(kH264FuA, h264.packetization_type);
773 EXPECT_EQ(kIdr, h264.nalu_type);
774 ASSERT_EQ(1u, h264.nalus_length);
775 EXPECT_EQ(static_cast<H264::NaluType>(kIdr), h264.nalus[0].type);
776 EXPECT_EQ(-1, h264.nalus[0].sps_id);
777 EXPECT_EQ(-1, h264.nalus[0].pps_id);
778 }
743 779
744 payload = RtpDepacketizer::ParsedPayload(); 780 payload = RtpDepacketizer::ParsedPayload();
745 ASSERT_TRUE(depacketizer_->Parse(&payload, packet3, sizeof(packet3))); 781 ASSERT_TRUE(depacketizer_->Parse(&payload, packet3, sizeof(packet3)));
746 ExpectPacket(&payload, kExpected3, sizeof(kExpected3)); 782 ExpectPacket(&payload, kExpected3, sizeof(kExpected3));
747 EXPECT_EQ(kVideoFrameKey, payload.frame_type); 783 EXPECT_EQ(kVideoFrameKey, payload.frame_type);
748 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); 784 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec);
749 EXPECT_FALSE(payload.type.Video.isFirstPacket); 785 EXPECT_FALSE(payload.type.Video.isFirstPacket);
750 EXPECT_EQ(kH264FuA, payload.type.Video.codecHeader.H264.packetization_type); 786 {
751 EXPECT_EQ(kIdr, payload.type.Video.codecHeader.H264.nalu_type); 787 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264;
788 EXPECT_EQ(kH264FuA, h264.packetization_type);
789 EXPECT_EQ(kIdr, h264.nalu_type);
790 ASSERT_EQ(1u, h264.nalus_length);
791 EXPECT_EQ(static_cast<H264::NaluType>(kIdr), h264.nalus[0].type);
792 EXPECT_EQ(-1, h264.nalus[0].sps_id);
793 EXPECT_EQ(-1, h264.nalus[0].pps_id);
794 }
752 } 795 }
753 796
754 TEST_F(RtpDepacketizerH264Test, TestEmptyPayload) { 797 TEST_F(RtpDepacketizerH264Test, TestEmptyPayload) {
755 // Using a wild pointer to crash on accesses from inside the depacketizer. 798 // Using a wild pointer to crash on accesses from inside the depacketizer.
756 uint8_t* garbage_ptr = reinterpret_cast<uint8_t*>(0x4711); 799 uint8_t* garbage_ptr = reinterpret_cast<uint8_t*>(0x4711);
757 RtpDepacketizer::ParsedPayload payload; 800 RtpDepacketizer::ParsedPayload payload;
758 EXPECT_FALSE(depacketizer_->Parse(&payload, garbage_ptr, 0)); 801 EXPECT_FALSE(depacketizer_->Parse(&payload, garbage_ptr, 0));
759 } 802 }
760 803
761 TEST_F(RtpDepacketizerH264Test, TestTruncatedFuaNalu) { 804 TEST_F(RtpDepacketizerH264Test, TestTruncatedFuaNalu) {
(...skipping 14 matching lines...) Expand all
776 EXPECT_FALSE(depacketizer_->Parse(&payload, kPayload, sizeof(kPayload))); 819 EXPECT_FALSE(depacketizer_->Parse(&payload, kPayload, sizeof(kPayload)));
777 } 820 }
778 821
779 TEST_F(RtpDepacketizerH264Test, TestShortSpsPacket) { 822 TEST_F(RtpDepacketizerH264Test, TestShortSpsPacket) {
780 const uint8_t kPayload[] = {0x27, 0x80, 0x00}; 823 const uint8_t kPayload[] = {0x27, 0x80, 0x00};
781 RtpDepacketizer::ParsedPayload payload; 824 RtpDepacketizer::ParsedPayload payload;
782 EXPECT_TRUE(depacketizer_->Parse(&payload, kPayload, sizeof(kPayload))); 825 EXPECT_TRUE(depacketizer_->Parse(&payload, kPayload, sizeof(kPayload)));
783 } 826 }
784 827
785 } // namespace webrtc 828 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtp_format_h264.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698