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

Unified Diff: webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc

Issue 2871173008: Fix packetization logic to leave space for extensions in the last packet (Closed)
Patch Set: Fix packet buffer allocations bugs and old tests with incorrect assumptions about extensions locati… Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc
diff --git a/webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc
index 1f926d9eeb010246d7fa06190798f60eddd8b2d4..ff1b69f72d1a81c79bb3bf2bd4b2416a5ffa8f13 100644
--- a/webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc
@@ -66,7 +66,7 @@ RtpPacketizer* CreateH264Packetizer(H264PacketizationMode mode,
size_t max_payload_size) {
RTPVideoTypeHeader type_header;
type_header.H264.packetization_mode = mode;
- return RtpPacketizer::Create(kRtpVideoH264, max_payload_size, &type_header,
+ return RtpPacketizer::Create(kRtpVideoH264, max_payload_size, 0, &type_header,
kEmptyFrame);
}
@@ -115,16 +115,15 @@ void TestFua(size_t frame_size,
RtpPacketToSend packet(kNoExtensions);
ASSERT_LE(max_payload_size, packet.FreeCapacity());
- bool last = false;
size_t offset = kNalHeaderSize;
+ EXPECT_EQ(packetizer->TotalPackets(), expected_sizes.size());
for (size_t i = 0; i < expected_sizes.size(); ++i) {
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
VerifyFua(i, frame.get(), offset, packet.payload(), expected_sizes);
- EXPECT_EQ(i == expected_sizes.size() - 1, last) << "FUA index: " << i;
offset += expected_sizes[i];
}
- EXPECT_FALSE(packetizer->NextPacket(&packet, &last));
+ EXPECT_FALSE(packetizer->NextPacket(&packet));
}
size_t GetExpectedNaluOffset(const RTPFragmentationHeader& fragmentation,
@@ -186,12 +185,11 @@ TEST_P(RtpPacketizerH264ModeTest, TestSingleNalu) {
packetizer->SetPayloadData(frame, sizeof(frame), &fragmentation);
RtpPacketToSend packet(kNoExtensions);
ASSERT_LE(kMaxPayloadSize, packet.FreeCapacity());
- bool last = false;
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_EQ(packetizer->TotalPackets(), 1u);
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
EXPECT_EQ(2u, packet.payload_size());
- EXPECT_TRUE(last);
VerifySingleNaluPayload(fragmentation, 0, frame, packet.payload());
- EXPECT_FALSE(packetizer->NextPacket(&packet, &last));
+ EXPECT_FALSE(packetizer->NextPacket(&packet));
}
TEST_P(RtpPacketizerH264ModeTest, TestSingleNaluTwoPackets) {
@@ -214,17 +212,16 @@ TEST_P(RtpPacketizerH264ModeTest, TestSingleNaluTwoPackets) {
packetizer->SetPayloadData(frame, kFrameSize, &fragmentation);
RtpPacketToSend packet(kNoExtensions);
- bool last = false;
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_EQ(packetizer->TotalPackets(), 2u);
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
ASSERT_EQ(fragmentation.fragmentationOffset[1], packet.payload_size());
VerifySingleNaluPayload(fragmentation, 0, frame, packet.payload());
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
ASSERT_EQ(fragmentation.fragmentationLength[1], packet.payload_size());
VerifySingleNaluPayload(fragmentation, 1, frame, packet.payload());
- EXPECT_TRUE(last);
- EXPECT_FALSE(packetizer->NextPacket(&packet, &last));
+ EXPECT_FALSE(packetizer->NextPacket(&packet));
}
INSTANTIATE_TEST_CASE_P(
@@ -250,16 +247,16 @@ TEST(RtpPacketizerH264Test, TestStapA) {
RtpPacketToSend packet(kNoExtensions);
ASSERT_LE(kMaxPayloadSize, packet.FreeCapacity());
- bool last = false;
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_EQ(packetizer->TotalPackets(), 1u);
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
size_t expected_packet_size =
kNalHeaderSize + 3 * kLengthFieldLength + kFrameSize;
ASSERT_EQ(expected_packet_size, packet.payload_size());
- EXPECT_TRUE(last);
+
for (size_t i = 0; i < fragmentation.fragmentationVectorSize; ++i)
VerifyStapAPayload(fragmentation, 0, i, frame, packet.payload());
- EXPECT_FALSE(packetizer->NextPacket(&packet, &last));
+ EXPECT_FALSE(packetizer->NextPacket(&packet));
}
TEST(RtpPacketizerH264Test, TestSingleNalUnitModeHasNoStapA) {
@@ -279,12 +276,11 @@ TEST(RtpPacketizerH264Test, TestSingleNalUnitModeHasNoStapA) {
packetizer->SetPayloadData(frame, kFrameSize, &fragmentation);
RtpPacketToSend packet(kNoExtensions);
- bool last = false;
// The three fragments should be returned as three packets.
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
- EXPECT_FALSE(packetizer->NextPacket(&packet, &last));
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
+ EXPECT_FALSE(packetizer->NextPacket(&packet));
}
TEST(RtpPacketizerH264Test, TestTooSmallForStapAHeaders) {
@@ -310,25 +306,23 @@ TEST(RtpPacketizerH264Test, TestTooSmallForStapAHeaders) {
RtpPacketToSend packet(kNoExtensions);
ASSERT_LE(kMaxPayloadSize, packet.FreeCapacity());
- bool last = false;
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_EQ(packetizer->TotalPackets(), 2u);
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
size_t expected_packet_size = kNalHeaderSize;
for (size_t i = 0; i < 2; ++i) {
expected_packet_size +=
kLengthFieldLength + fragmentation.fragmentationLength[i];
}
ASSERT_EQ(expected_packet_size, packet.payload_size());
- EXPECT_FALSE(last);
for (size_t i = 0; i < 2; ++i)
VerifyStapAPayload(fragmentation, 0, i, frame, packet.payload());
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
expected_packet_size = fragmentation.fragmentationLength[2];
ASSERT_EQ(expected_packet_size, packet.payload_size());
- EXPECT_TRUE(last);
VerifySingleNaluPayload(fragmentation, 2, frame, packet.payload());
- EXPECT_FALSE(packetizer->NextPacket(&packet, &last));
+ EXPECT_FALSE(packetizer->NextPacket(&packet));
}
TEST(RtpPacketizerH264Test, TestMixedStapA_FUA) {
@@ -362,24 +356,22 @@ TEST(RtpPacketizerH264Test, TestMixedStapA_FUA) {
fua_sizes.push_back(1099);
RtpPacketToSend packet(kNoExtensions);
ASSERT_LE(kMaxPayloadSize, packet.FreeCapacity());
- bool last = false;
+ ASSERT_EQ(packetizer->TotalPackets(), 3u);
int fua_offset = kNalHeaderSize;
for (size_t i = 0; i < 2; ++i) {
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
VerifyFua(i, frame, fua_offset, packet.payload(), fua_sizes);
- EXPECT_FALSE(last);
fua_offset += fua_sizes[i];
}
// Then expecting one STAP-A packet with two nal units.
- ASSERT_TRUE(packetizer->NextPacket(&packet, &last));
+ ASSERT_TRUE(packetizer->NextPacket(&packet));
size_t expected_packet_size =
kNalHeaderSize + 2 * kLengthFieldLength + 2 * kStapANaluSize;
ASSERT_EQ(expected_packet_size, packet.payload_size());
- EXPECT_TRUE(last);
for (size_t i = 1; i < fragmentation.fragmentationVectorSize; ++i)
VerifyStapAPayload(fragmentation, 1, i, frame, packet.payload());
- EXPECT_FALSE(packetizer->NextPacket(&packet, &last));
+ EXPECT_FALSE(packetizer->NextPacket(&packet));
}
TEST(RtpPacketizerH264Test, TestFUAOddSize) {
@@ -495,18 +487,17 @@ TEST_F(RtpPacketizerH264TestSpsRewriting, FuASps) {
packetizer_->SetPayloadData(in_buffer_.data(), in_buffer_.size(),
&fragmentation_header_);
- bool last_packet = true;
RtpPacketToSend packet(kNoExtensions);
ASSERT_LE(sizeof(kOriginalSps) + kHeaderOverhead, packet.FreeCapacity());
- EXPECT_TRUE(packetizer_->NextPacket(&packet, &last_packet));
+ EXPECT_TRUE(packetizer_->NextPacket(&packet));
size_t offset = H264::kNaluTypeSize;
size_t length = packet.payload_size() - kFuAHeaderSize;
EXPECT_THAT(packet.payload().subview(kFuAHeaderSize),
ElementsAreArray(&kRewrittenSps[offset], length));
offset += length;
- EXPECT_TRUE(packetizer_->NextPacket(&packet, &last_packet));
+ EXPECT_TRUE(packetizer_->NextPacket(&packet));
length = packet.payload_size() - kFuAHeaderSize;
EXPECT_THAT(packet.payload().subview(kFuAHeaderSize),
ElementsAreArray(&kRewrittenSps[offset], length));
@@ -528,11 +519,10 @@ TEST_F(RtpPacketizerH264TestSpsRewriting, StapASps) {
packetizer_->SetPayloadData(in_buffer_.data(), in_buffer_.size(),
&fragmentation_header_);
- bool last_packet = true;
RtpPacketToSend packet(kNoExtensions);
ASSERT_LE(kExpectedTotalSize + kHeaderOverhead, packet.FreeCapacity());
- EXPECT_TRUE(packetizer_->NextPacket(&packet, &last_packet));
+ EXPECT_TRUE(packetizer_->NextPacket(&packet));
EXPECT_EQ(kExpectedTotalSize, packet.payload_size());
EXPECT_THAT(packet.payload().subview(H264::kNaluTypeSize + kLengthFieldLength,
sizeof(kRewrittenSps)),

Powered by Google App Engine
This is Rietveld 408576698