| OLD | NEW |
| 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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 }; | 558 }; |
| 559 | 559 |
| 560 TEST_F(RtpDepacketizerH264Test, TestSingleNalu) { | 560 TEST_F(RtpDepacketizerH264Test, TestSingleNalu) { |
| 561 uint8_t packet[2] = {0x05, 0xFF}; // F=0, NRI=0, Type=5 (IDR). | 561 uint8_t packet[2] = {0x05, 0xFF}; // F=0, NRI=0, Type=5 (IDR). |
| 562 RtpDepacketizer::ParsedPayload payload; | 562 RtpDepacketizer::ParsedPayload payload; |
| 563 | 563 |
| 564 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); | 564 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); |
| 565 ExpectPacket(&payload, packet, sizeof(packet)); | 565 ExpectPacket(&payload, packet, sizeof(packet)); |
| 566 EXPECT_EQ(kVideoFrameKey, payload.frame_type); | 566 EXPECT_EQ(kVideoFrameKey, payload.frame_type); |
| 567 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); | 567 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); |
| 568 EXPECT_TRUE(payload.type.Video.is_first_packet_in_frame); | 568 EXPECT_TRUE(payload.type.Video.isFirstPacket); |
| 569 EXPECT_EQ(kH264SingleNalu, | 569 EXPECT_EQ(kH264SingleNalu, |
| 570 payload.type.Video.codecHeader.H264.packetization_type); | 570 payload.type.Video.codecHeader.H264.packetization_type); |
| 571 EXPECT_EQ(kIdr, payload.type.Video.codecHeader.H264.nalu_type); | 571 EXPECT_EQ(kIdr, payload.type.Video.codecHeader.H264.nalu_type); |
| 572 } | 572 } |
| 573 | 573 |
| 574 TEST_F(RtpDepacketizerH264Test, TestSingleNaluSpsWithResolution) { | 574 TEST_F(RtpDepacketizerH264Test, TestSingleNaluSpsWithResolution) { |
| 575 uint8_t packet[] = {kSps, 0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, | 575 uint8_t packet[] = {kSps, 0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, |
| 576 0x05, 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, | 576 0x05, 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, |
| 577 0x00, 0x00, 0x03, 0x2A, 0xE0, 0xF1, 0x83, 0x25}; | 577 0x00, 0x00, 0x03, 0x2A, 0xE0, 0xF1, 0x83, 0x25}; |
| 578 RtpDepacketizer::ParsedPayload payload; | 578 RtpDepacketizer::ParsedPayload payload; |
| 579 | 579 |
| 580 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); | 580 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); |
| 581 ExpectPacket(&payload, packet, sizeof(packet)); | 581 ExpectPacket(&payload, packet, sizeof(packet)); |
| 582 EXPECT_EQ(kVideoFrameKey, payload.frame_type); | 582 EXPECT_EQ(kVideoFrameKey, payload.frame_type); |
| 583 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); | 583 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); |
| 584 EXPECT_TRUE(payload.type.Video.is_first_packet_in_frame); | 584 EXPECT_TRUE(payload.type.Video.isFirstPacket); |
| 585 EXPECT_EQ(kH264SingleNalu, | 585 EXPECT_EQ(kH264SingleNalu, |
| 586 payload.type.Video.codecHeader.H264.packetization_type); | 586 payload.type.Video.codecHeader.H264.packetization_type); |
| 587 EXPECT_EQ(1280u, payload.type.Video.width); | 587 EXPECT_EQ(1280u, payload.type.Video.width); |
| 588 EXPECT_EQ(720u, payload.type.Video.height); | 588 EXPECT_EQ(720u, payload.type.Video.height); |
| 589 } | 589 } |
| 590 | 590 |
| 591 TEST_F(RtpDepacketizerH264Test, TestStapAKey) { | 591 TEST_F(RtpDepacketizerH264Test, TestStapAKey) { |
| 592 // clang-format off | 592 // clang-format off |
| 593 const NaluInfo kExpectedNalus[] = { {H264::kSps, 0, -1}, | 593 const NaluInfo kExpectedNalus[] = { {H264::kSps, 0, -1}, |
| 594 {H264::kPps, 1, 2}, | 594 {H264::kPps, 1, 2}, |
| 595 {H264::kIdr, -1, 0} }; | 595 {H264::kIdr, -1, 0} }; |
| 596 uint8_t packet[] = {kStapA, // F=0, NRI=0, Type=24. | 596 uint8_t packet[] = {kStapA, // F=0, NRI=0, Type=24. |
| 597 // Length, nal header, payload. | 597 // Length, nal header, payload. |
| 598 0, 0x18, kExpectedNalus[0].type, | 598 0, 0x18, kExpectedNalus[0].type, |
| 599 0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05, 0xBA, | 599 0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05, 0xBA, |
| 600 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00, 0x00, 0x03, | 600 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00, 0x00, 0x03, |
| 601 0x2A, 0xE0, 0xF1, 0x83, 0x25, | 601 0x2A, 0xE0, 0xF1, 0x83, 0x25, |
| 602 0, 0xD, kExpectedNalus[1].type, | 602 0, 0xD, kExpectedNalus[1].type, |
| 603 0x69, 0xFC, 0x0, 0x0, 0x3, 0x0, 0x7, 0xFF, 0xFF, 0xFF, | 603 0x69, 0xFC, 0x0, 0x0, 0x3, 0x0, 0x7, 0xFF, 0xFF, 0xFF, |
| 604 0xF6, 0x40, | 604 0xF6, 0x40, |
| 605 0, 0xB, kExpectedNalus[2].type, | 605 0, 0xB, kExpectedNalus[2].type, |
| 606 0x85, 0xB8, 0x0, 0x4, 0x0, 0x0, 0x13, 0x93, 0x12, 0x0}; | 606 0x85, 0xB8, 0x0, 0x4, 0x0, 0x0, 0x13, 0x93, 0x12, 0x0}; |
| 607 // clang-format on | 607 // clang-format on |
| 608 | 608 |
| 609 RtpDepacketizer::ParsedPayload payload; | 609 RtpDepacketizer::ParsedPayload payload; |
| 610 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); | 610 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); |
| 611 ExpectPacket(&payload, packet, sizeof(packet)); | 611 ExpectPacket(&payload, packet, sizeof(packet)); |
| 612 EXPECT_EQ(kVideoFrameKey, payload.frame_type); | 612 EXPECT_EQ(kVideoFrameKey, payload.frame_type); |
| 613 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); | 613 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); |
| 614 EXPECT_TRUE(payload.type.Video.is_first_packet_in_frame); | 614 EXPECT_TRUE(payload.type.Video.isFirstPacket); |
| 615 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; | 615 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; |
| 616 EXPECT_EQ(kH264StapA, h264.packetization_type); | 616 EXPECT_EQ(kH264StapA, h264.packetization_type); |
| 617 // NALU type for aggregated packets is the type of the first packet only. | 617 // NALU type for aggregated packets is the type of the first packet only. |
| 618 EXPECT_EQ(kSps, h264.nalu_type); | 618 EXPECT_EQ(kSps, h264.nalu_type); |
| 619 ASSERT_EQ(3u, h264.nalus_length); | 619 ASSERT_EQ(3u, h264.nalus_length); |
| 620 for (size_t i = 0; i < h264.nalus_length; ++i) { | 620 for (size_t i = 0; i < h264.nalus_length; ++i) { |
| 621 EXPECT_EQ(kExpectedNalus[i].type, h264.nalus[i].type) | 621 EXPECT_EQ(kExpectedNalus[i].type, h264.nalus[i].type) |
| 622 << "Failed parsing nalu " << i; | 622 << "Failed parsing nalu " << i; |
| 623 EXPECT_EQ(kExpectedNalus[i].sps_id, h264.nalus[i].sps_id) | 623 EXPECT_EQ(kExpectedNalus[i].sps_id, h264.nalus[i].sps_id) |
| 624 << "Failed parsing nalu " << i; | 624 << "Failed parsing nalu " << i; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 635 0x00, 0x00, 0x03, 0x2A, 0xE0, 0xF1, 0x83, 0x25, 0x80, | 635 0x00, 0x00, 0x03, 0x2A, 0xE0, 0xF1, 0x83, 0x25, 0x80, |
| 636 0x00, 0x03, kIdr, 0xFF, 0x00, 0x00, 0x04, kIdr, 0xFF, | 636 0x00, 0x03, kIdr, 0xFF, 0x00, 0x00, 0x04, kIdr, 0xFF, |
| 637 0x00, 0x11}; | 637 0x00, 0x11}; |
| 638 | 638 |
| 639 RtpDepacketizer::ParsedPayload payload; | 639 RtpDepacketizer::ParsedPayload payload; |
| 640 | 640 |
| 641 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); | 641 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); |
| 642 ExpectPacket(&payload, packet, sizeof(packet)); | 642 ExpectPacket(&payload, packet, sizeof(packet)); |
| 643 EXPECT_EQ(kVideoFrameKey, payload.frame_type); | 643 EXPECT_EQ(kVideoFrameKey, payload.frame_type); |
| 644 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); | 644 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); |
| 645 EXPECT_TRUE(payload.type.Video.is_first_packet_in_frame); | 645 EXPECT_TRUE(payload.type.Video.isFirstPacket); |
| 646 EXPECT_EQ(kH264StapA, payload.type.Video.codecHeader.H264.packetization_type); | 646 EXPECT_EQ(kH264StapA, payload.type.Video.codecHeader.H264.packetization_type); |
| 647 EXPECT_EQ(1280u, payload.type.Video.width); | 647 EXPECT_EQ(1280u, payload.type.Video.width); |
| 648 EXPECT_EQ(720u, payload.type.Video.height); | 648 EXPECT_EQ(720u, payload.type.Video.height); |
| 649 } | 649 } |
| 650 | 650 |
| 651 TEST_F(RtpDepacketizerH264Test, TestEmptyStapARejected) { | 651 TEST_F(RtpDepacketizerH264Test, TestEmptyStapARejected) { |
| 652 uint8_t lone_empty_packet[] = {kStapA, 0x00, 0x00}; | 652 uint8_t lone_empty_packet[] = {kStapA, 0x00, 0x00}; |
| 653 | 653 |
| 654 uint8_t leading_empty_packet[] = {kStapA, 0x00, 0x00, 0x00, 0x04, | 654 uint8_t leading_empty_packet[] = {kStapA, 0x00, 0x00, 0x00, 0x04, |
| 655 kIdr, 0xFF, 0x00, 0x11}; | 655 kIdr, 0xFF, 0x00, 0x11}; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 uint8_t packet[16] = {kStapA, // F=0, NRI=0, Type=24. | 762 uint8_t packet[16] = {kStapA, // F=0, NRI=0, Type=24. |
| 763 // Length, nal header, payload. | 763 // Length, nal header, payload. |
| 764 0, 0x02, kSlice, 0xFF, 0, 0x03, kSlice, 0xFF, | 764 0, 0x02, kSlice, 0xFF, 0, 0x03, kSlice, 0xFF, |
| 765 0x00, 0, 0x04, kSlice, 0xFF, 0x00, 0x11}; | 765 0x00, 0, 0x04, kSlice, 0xFF, 0x00, 0x11}; |
| 766 RtpDepacketizer::ParsedPayload payload; | 766 RtpDepacketizer::ParsedPayload payload; |
| 767 | 767 |
| 768 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); | 768 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); |
| 769 ExpectPacket(&payload, packet, sizeof(packet)); | 769 ExpectPacket(&payload, packet, sizeof(packet)); |
| 770 EXPECT_EQ(kVideoFrameDelta, payload.frame_type); | 770 EXPECT_EQ(kVideoFrameDelta, payload.frame_type); |
| 771 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); | 771 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); |
| 772 EXPECT_TRUE(payload.type.Video.is_first_packet_in_frame); | 772 EXPECT_TRUE(payload.type.Video.isFirstPacket); |
| 773 EXPECT_EQ(kH264StapA, payload.type.Video.codecHeader.H264.packetization_type); | 773 EXPECT_EQ(kH264StapA, payload.type.Video.codecHeader.H264.packetization_type); |
| 774 // NALU type for aggregated packets is the type of the first packet only. | 774 // NALU type for aggregated packets is the type of the first packet only. |
| 775 EXPECT_EQ(kSlice, payload.type.Video.codecHeader.H264.nalu_type); | 775 EXPECT_EQ(kSlice, payload.type.Video.codecHeader.H264.nalu_type); |
| 776 } | 776 } |
| 777 | 777 |
| 778 TEST_F(RtpDepacketizerH264Test, TestFuA) { | 778 TEST_F(RtpDepacketizerH264Test, TestFuA) { |
| 779 // clang-format off | 779 // clang-format off |
| 780 uint8_t packet1[] = { | 780 uint8_t packet1[] = { |
| 781 kFuA, // F=0, NRI=0, Type=28. | 781 kFuA, // F=0, NRI=0, Type=28. |
| 782 kSBit | kIdr, // FU header. | 782 kSBit | kIdr, // FU header. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 801 const uint8_t kExpected3[] = {0x03}; | 801 const uint8_t kExpected3[] = {0x03}; |
| 802 | 802 |
| 803 RtpDepacketizer::ParsedPayload payload; | 803 RtpDepacketizer::ParsedPayload payload; |
| 804 | 804 |
| 805 // We expect that the first packet is one byte shorter since the FU-A header | 805 // We expect that the first packet is one byte shorter since the FU-A header |
| 806 // has been replaced by the original nal header. | 806 // has been replaced by the original nal header. |
| 807 ASSERT_TRUE(depacketizer_->Parse(&payload, packet1, sizeof(packet1))); | 807 ASSERT_TRUE(depacketizer_->Parse(&payload, packet1, sizeof(packet1))); |
| 808 ExpectPacket(&payload, kExpected1, sizeof(kExpected1)); | 808 ExpectPacket(&payload, kExpected1, sizeof(kExpected1)); |
| 809 EXPECT_EQ(kVideoFrameKey, payload.frame_type); | 809 EXPECT_EQ(kVideoFrameKey, payload.frame_type); |
| 810 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); | 810 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); |
| 811 EXPECT_TRUE(payload.type.Video.is_first_packet_in_frame); | 811 EXPECT_TRUE(payload.type.Video.isFirstPacket); |
| 812 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; | 812 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; |
| 813 EXPECT_EQ(kH264FuA, h264.packetization_type); | 813 EXPECT_EQ(kH264FuA, h264.packetization_type); |
| 814 EXPECT_EQ(kIdr, h264.nalu_type); | 814 EXPECT_EQ(kIdr, h264.nalu_type); |
| 815 ASSERT_EQ(1u, h264.nalus_length); | 815 ASSERT_EQ(1u, h264.nalus_length); |
| 816 EXPECT_EQ(static_cast<H264::NaluType>(kIdr), h264.nalus[0].type); | 816 EXPECT_EQ(static_cast<H264::NaluType>(kIdr), h264.nalus[0].type); |
| 817 EXPECT_EQ(-1, h264.nalus[0].sps_id); | 817 EXPECT_EQ(-1, h264.nalus[0].sps_id); |
| 818 EXPECT_EQ(0, h264.nalus[0].pps_id); | 818 EXPECT_EQ(0, h264.nalus[0].pps_id); |
| 819 | 819 |
| 820 // Following packets will be 2 bytes shorter since they will only be appended | 820 // Following packets will be 2 bytes shorter since they will only be appended |
| 821 // onto the first packet. | 821 // onto the first packet. |
| 822 payload = RtpDepacketizer::ParsedPayload(); | 822 payload = RtpDepacketizer::ParsedPayload(); |
| 823 ASSERT_TRUE(depacketizer_->Parse(&payload, packet2, sizeof(packet2))); | 823 ASSERT_TRUE(depacketizer_->Parse(&payload, packet2, sizeof(packet2))); |
| 824 ExpectPacket(&payload, kExpected2, sizeof(kExpected2)); | 824 ExpectPacket(&payload, kExpected2, sizeof(kExpected2)); |
| 825 EXPECT_EQ(kVideoFrameKey, payload.frame_type); | 825 EXPECT_EQ(kVideoFrameKey, payload.frame_type); |
| 826 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); | 826 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); |
| 827 EXPECT_FALSE(payload.type.Video.is_first_packet_in_frame); | 827 EXPECT_FALSE(payload.type.Video.isFirstPacket); |
| 828 { | 828 { |
| 829 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; | 829 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; |
| 830 EXPECT_EQ(kH264FuA, h264.packetization_type); | 830 EXPECT_EQ(kH264FuA, h264.packetization_type); |
| 831 EXPECT_EQ(kIdr, h264.nalu_type); | 831 EXPECT_EQ(kIdr, h264.nalu_type); |
| 832 // NALU info is only expected for the first FU-A packet. | 832 // NALU info is only expected for the first FU-A packet. |
| 833 EXPECT_EQ(0u, h264.nalus_length); | 833 EXPECT_EQ(0u, h264.nalus_length); |
| 834 } | 834 } |
| 835 | 835 |
| 836 payload = RtpDepacketizer::ParsedPayload(); | 836 payload = RtpDepacketizer::ParsedPayload(); |
| 837 ASSERT_TRUE(depacketizer_->Parse(&payload, packet3, sizeof(packet3))); | 837 ASSERT_TRUE(depacketizer_->Parse(&payload, packet3, sizeof(packet3))); |
| 838 ExpectPacket(&payload, kExpected3, sizeof(kExpected3)); | 838 ExpectPacket(&payload, kExpected3, sizeof(kExpected3)); |
| 839 EXPECT_EQ(kVideoFrameKey, payload.frame_type); | 839 EXPECT_EQ(kVideoFrameKey, payload.frame_type); |
| 840 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); | 840 EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); |
| 841 EXPECT_FALSE(payload.type.Video.is_first_packet_in_frame); | 841 EXPECT_FALSE(payload.type.Video.isFirstPacket); |
| 842 { | 842 { |
| 843 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; | 843 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; |
| 844 EXPECT_EQ(kH264FuA, h264.packetization_type); | 844 EXPECT_EQ(kH264FuA, h264.packetization_type); |
| 845 EXPECT_EQ(kIdr, h264.nalu_type); | 845 EXPECT_EQ(kIdr, h264.nalu_type); |
| 846 // NALU info is only expected for the first FU-A packet. | 846 // NALU info is only expected for the first FU-A packet. |
| 847 ASSERT_EQ(0u, h264.nalus_length); | 847 ASSERT_EQ(0u, h264.nalus_length); |
| 848 } | 848 } |
| 849 } | 849 } |
| 850 | 850 |
| 851 TEST_F(RtpDepacketizerH264Test, TestEmptyPayload) { | 851 TEST_F(RtpDepacketizerH264Test, TestEmptyPayload) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; | 889 const RTPVideoHeaderH264& h264 = payload.type.Video.codecHeader.H264; |
| 890 EXPECT_EQ(kH264SingleNalu, h264.packetization_type); | 890 EXPECT_EQ(kH264SingleNalu, h264.packetization_type); |
| 891 EXPECT_EQ(kSei, h264.nalu_type); | 891 EXPECT_EQ(kSei, h264.nalu_type); |
| 892 ASSERT_EQ(1u, h264.nalus_length); | 892 ASSERT_EQ(1u, h264.nalus_length); |
| 893 EXPECT_EQ(static_cast<H264::NaluType>(kSei), h264.nalus[0].type); | 893 EXPECT_EQ(static_cast<H264::NaluType>(kSei), h264.nalus[0].type); |
| 894 EXPECT_EQ(-1, h264.nalus[0].sps_id); | 894 EXPECT_EQ(-1, h264.nalus[0].sps_id); |
| 895 EXPECT_EQ(-1, h264.nalus[0].pps_id); | 895 EXPECT_EQ(-1, h264.nalus[0].pps_id); |
| 896 } | 896 } |
| 897 | 897 |
| 898 } // namespace webrtc | 898 } // namespace webrtc |
| OLD | NEW |