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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_vp9_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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 size_t payload_size_; 137 size_t payload_size_;
138 size_t payload_pos_; 138 size_t payload_pos_;
139 RTPVideoHeaderVP9 expected_; 139 RTPVideoHeaderVP9 expected_;
140 std::unique_ptr<RtpPacketizerVp9> packetizer_; 140 std::unique_ptr<RtpPacketizerVp9> packetizer_;
141 141
142 void Init(size_t payload_size, size_t packet_size) { 142 void Init(size_t payload_size, size_t packet_size) {
143 payload_.reset(new uint8_t[payload_size]); 143 payload_.reset(new uint8_t[payload_size]);
144 memset(payload_.get(), 7, payload_size); 144 memset(payload_.get(), 7, payload_size);
145 payload_size_ = payload_size; 145 payload_size_ = payload_size;
146 payload_pos_ = 0; 146 payload_pos_ = 0;
147 packetizer_.reset(new RtpPacketizerVp9(expected_, packet_size)); 147 packetizer_.reset(new RtpPacketizerVp9(expected_, packet_size, 0));
148 packetizer_->SetPayloadData(payload_.get(), payload_size_, NULL); 148 packetizer_->SetPayloadData(payload_.get(), payload_size_, NULL);
149 } 149 }
150 150
151 void CheckPayload(const uint8_t* packet, 151 void CheckPayload(const uint8_t* packet,
152 size_t start_pos, 152 size_t start_pos,
153 size_t end_pos, 153 size_t end_pos,
154 bool last) { 154 bool last) {
155 for (size_t i = start_pos; i < end_pos; ++i) { 155 for (size_t i = start_pos; i < end_pos; ++i) {
156 EXPECT_EQ(packet[i], payload_[payload_pos_++]); 156 EXPECT_EQ(packet[i], payload_[payload_pos_++]);
157 } 157 }
158 EXPECT_EQ(last, payload_pos_ == payload_size_); 158 EXPECT_EQ(last, payload_pos_ == payload_size_);
159 } 159 }
160 160
161 void CreateParseAndCheckPackets(const size_t* expected_hdr_sizes, 161 void CreateParseAndCheckPackets(const size_t* expected_hdr_sizes,
162 const size_t* expected_sizes, 162 const size_t* expected_sizes,
163 size_t expected_num_packets) { 163 size_t expected_num_packets) {
164 ASSERT_TRUE(packetizer_.get() != NULL); 164 ASSERT_TRUE(packetizer_.get() != NULL);
165 bool last = false;
166 if (expected_num_packets == 0) { 165 if (expected_num_packets == 0) {
167 EXPECT_FALSE(packetizer_->NextPacket(&packet_, &last)); 166 EXPECT_FALSE(packetizer_->NextPacket(&packet_));
168 return; 167 return;
169 } 168 }
169 EXPECT_EQ(expected_num_packets, packetizer_->TotalPackets());
170 for (size_t i = 0; i < expected_num_packets; ++i) { 170 for (size_t i = 0; i < expected_num_packets; ++i) {
171 EXPECT_TRUE(packetizer_->NextPacket(&packet_, &last)); 171 EXPECT_TRUE(packetizer_->NextPacket(&packet_));
172 auto rtp_payload = packet_.payload(); 172 auto rtp_payload = packet_.payload();
173 EXPECT_EQ(expected_sizes[i], rtp_payload.size()); 173 EXPECT_EQ(expected_sizes[i], rtp_payload.size());
174 RTPVideoHeaderVP9 hdr = expected_; 174 RTPVideoHeaderVP9 hdr = expected_;
175 hdr.beginning_of_frame = (i == 0); 175 hdr.beginning_of_frame = (i == 0);
176 hdr.end_of_frame = last; 176 hdr.end_of_frame = (i + 1) == expected_num_packets;
177 ParseAndCheckPacket(rtp_payload.data(), hdr, expected_hdr_sizes[i], 177 ParseAndCheckPacket(rtp_payload.data(), hdr, expected_hdr_sizes[i],
178 rtp_payload.size()); 178 rtp_payload.size());
179 CheckPayload(rtp_payload.data(), expected_hdr_sizes[i], 179 CheckPayload(rtp_payload.data(), expected_hdr_sizes[i],
180 rtp_payload.size(), last); 180 rtp_payload.size(), (i + 1) == expected_num_packets);
181 } 181 }
182 EXPECT_TRUE(last);
183 } 182 }
184 }; 183 };
185 184
186 TEST_F(RtpPacketizerVp9Test, TestEqualSizedMode_OnePacket) { 185 TEST_F(RtpPacketizerVp9Test, TestEqualSizedMode_OnePacket) {
187 const size_t kFrameSize = 25; 186 const size_t kFrameSize = 25;
188 const size_t kPacketSize = 26; 187 const size_t kPacketSize = 26;
189 Init(kFrameSize, kPacketSize); 188 Init(kFrameSize, kPacketSize);
190 189
191 // One packet: 190 // One packet:
192 // I:0, P:0, L:0, F:0, B:1, E:1, V:0 (1hdr + 25 payload) 191 // I:0, P:0, L:0, F:0, B:1, E:1, V:0 (1hdr + 25 payload)
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 const size_t kPacketSize = 9; // 2 packet per frame. 436 const size_t kPacketSize = 9; // 2 packet per frame.
438 const uint8_t kFrame[kFrameSize] = {7}; 437 const uint8_t kFrame[kFrameSize] = {7};
439 const RTPFragmentationHeader* kNoFragmentation = nullptr; 438 const RTPFragmentationHeader* kNoFragmentation = nullptr;
440 439
441 RTPVideoHeaderVP9 vp9_header; 440 RTPVideoHeaderVP9 vp9_header;
442 vp9_header.InitRTPVideoHeaderVP9(); 441 vp9_header.InitRTPVideoHeaderVP9();
443 vp9_header.flexible_mode = true; 442 vp9_header.flexible_mode = true;
444 vp9_header.num_spatial_layers = 3; 443 vp9_header.num_spatial_layers = 3;
445 444
446 RtpPacketToSend packet(kNoExtensions); 445 RtpPacketToSend packet(kNoExtensions);
447 bool last;
448 446
449 vp9_header.spatial_idx = 0; 447 vp9_header.spatial_idx = 0;
450 RtpPacketizerVp9 packetizer0(vp9_header, kPacketSize); 448 RtpPacketizerVp9 packetizer0(vp9_header, kPacketSize, 0);
451 packetizer0.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation); 449 packetizer0.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation);
452 ASSERT_TRUE(packetizer0.NextPacket(&packet, &last)); 450 EXPECT_EQ(packetizer0.TotalPackets(), 2u);
453 EXPECT_FALSE(last); 451 ASSERT_TRUE(packetizer0.NextPacket(&packet));
454 EXPECT_FALSE(packet.Marker()); 452 EXPECT_FALSE(packet.Marker());
455 ASSERT_TRUE(packetizer0.NextPacket(&packet, &last)); 453 ASSERT_TRUE(packetizer0.NextPacket(&packet));
456 EXPECT_TRUE(last);
457 EXPECT_FALSE(packet.Marker()); 454 EXPECT_FALSE(packet.Marker());
458 455
459 vp9_header.spatial_idx = 1; 456 vp9_header.spatial_idx = 1;
460 RtpPacketizerVp9 packetizer1(vp9_header, kPacketSize); 457 RtpPacketizerVp9 packetizer1(vp9_header, kPacketSize, 0);
461 packetizer1.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation); 458 packetizer1.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation);
462 ASSERT_TRUE(packetizer1.NextPacket(&packet, &last)); 459 EXPECT_EQ(packetizer1.TotalPackets(), 2u);
463 EXPECT_FALSE(last); 460 ASSERT_TRUE(packetizer1.NextPacket(&packet));
464 EXPECT_FALSE(packet.Marker()); 461 EXPECT_FALSE(packet.Marker());
465 ASSERT_TRUE(packetizer1.NextPacket(&packet, &last)); 462 ASSERT_TRUE(packetizer1.NextPacket(&packet));
466 EXPECT_TRUE(last);
467 EXPECT_FALSE(packet.Marker()); 463 EXPECT_FALSE(packet.Marker());
468 464
469 vp9_header.spatial_idx = 2; 465 vp9_header.spatial_idx = 2;
470 RtpPacketizerVp9 packetizer2(vp9_header, kPacketSize); 466 RtpPacketizerVp9 packetizer2(vp9_header, kPacketSize, 0);
471 packetizer2.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation); 467 packetizer2.SetPayloadData(kFrame, sizeof(kFrame), kNoFragmentation);
472 ASSERT_TRUE(packetizer2.NextPacket(&packet, &last)); 468 EXPECT_EQ(packetizer2.TotalPackets(), 2u);
473 EXPECT_FALSE(last); 469 ASSERT_TRUE(packetizer2.NextPacket(&packet));
474 EXPECT_FALSE(packet.Marker()); 470 EXPECT_FALSE(packet.Marker());
475 ASSERT_TRUE(packetizer2.NextPacket(&packet, &last)); 471 ASSERT_TRUE(packetizer2.NextPacket(&packet));
476 EXPECT_TRUE(last);
477 EXPECT_TRUE(packet.Marker()); 472 EXPECT_TRUE(packet.Marker());
478 } 473 }
479 474
480 TEST_F(RtpPacketizerVp9Test, TestBaseLayerProtectionAndStorageType) { 475 TEST_F(RtpPacketizerVp9Test, TestBaseLayerProtectionAndStorageType) {
481 const size_t kFrameSize = 10; 476 const size_t kFrameSize = 10;
482 const size_t kPacketSize = 12; 477 const size_t kPacketSize = 12;
483 478
484 // I:0, P:0, L:1, F:1, B:1, E:1, V:0 (2hdr + 10 payload) 479 // I:0, P:0, L:1, F:1, B:1, E:1, V:0 (2hdr + 10 payload)
485 // L: T:0, U:0, S:0, D:0 480 // L: T:0, U:0, S:0, D:0
486 expected_.flexible_mode = true; 481 expected_.flexible_mode = true;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 } 725 }
731 726
732 TEST_F(RtpDepacketizerVp9Test, ParseFailsForTooShortBufferToFitPayload) { 727 TEST_F(RtpDepacketizerVp9Test, ParseFailsForTooShortBufferToFitPayload) {
733 const uint8_t kHeaderLength = 1; 728 const uint8_t kHeaderLength = 1;
734 uint8_t packet[kHeaderLength] = {0}; 729 uint8_t packet[kHeaderLength] = {0};
735 RtpDepacketizer::ParsedPayload parsed; 730 RtpDepacketizer::ParsedPayload parsed;
736 EXPECT_FALSE(depacketizer_->Parse(&parsed, packet, sizeof(packet))); 731 EXPECT_FALSE(depacketizer_->Parse(&parsed, packet, sizeof(packet)));
737 } 732 }
738 733
739 } // namespace webrtc 734 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698