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

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

Issue 1371043003: Unify FrameType and VideoFrameType. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 5 years, 2 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) 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 frame.reset(new uint8_t[frame_size]); 76 frame.reset(new uint8_t[frame_size]);
77 frame[0] = 0x05; // F=0, NRI=0, Type=5. 77 frame[0] = 0x05; // F=0, NRI=0, Type=5.
78 for (size_t i = 0; i < frame_size - kNalHeaderSize; ++i) { 78 for (size_t i = 0; i < frame_size - kNalHeaderSize; ++i) {
79 frame[i + kNalHeaderSize] = i; 79 frame[i + kNalHeaderSize] = i;
80 } 80 }
81 RTPFragmentationHeader fragmentation; 81 RTPFragmentationHeader fragmentation;
82 fragmentation.VerifyAndAllocateFragmentationHeader(1); 82 fragmentation.VerifyAndAllocateFragmentationHeader(1);
83 fragmentation.fragmentationOffset[0] = 0; 83 fragmentation.fragmentationOffset[0] = 0;
84 fragmentation.fragmentationLength[0] = frame_size; 84 fragmentation.fragmentationLength[0] = frame_size;
85 rtc::scoped_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create( 85 rtc::scoped_ptr<RtpPacketizer> packetizer(RtpPacketizer::Create(
86 kRtpVideoH264, max_payload_size, NULL, kFrameEmpty)); 86 kRtpVideoH264, max_payload_size, NULL, kEmptyFrame));
87 packetizer->SetPayloadData(frame.get(), frame_size, &fragmentation); 87 packetizer->SetPayloadData(frame.get(), frame_size, &fragmentation);
88 88
89 rtc::scoped_ptr<uint8_t[]> packet(new uint8_t[max_payload_size]); 89 rtc::scoped_ptr<uint8_t[]> packet(new uint8_t[max_payload_size]);
90 size_t length = 0; 90 size_t length = 0;
91 bool last = false; 91 bool last = false;
92 size_t offset = kNalHeaderSize; 92 size_t offset = kNalHeaderSize;
93 for (size_t i = 0; i < expected_sizes.size(); ++i) { 93 for (size_t i = 0; i < expected_sizes.size(); ++i) {
94 ASSERT_TRUE(packetizer->NextPacket(packet.get(), &length, &last)); 94 ASSERT_TRUE(packetizer->NextPacket(packet.get(), &length, &last));
95 VerifyFua(i, frame.get(), offset, packet.get(), length, expected_sizes); 95 VerifyFua(i, frame.get(), offset, packet.get(), length, expected_sizes);
96 EXPECT_EQ(i == expected_sizes.size() - 1, last) << "FUA index: " << i; 96 EXPECT_EQ(i == expected_sizes.size() - 1, last) << "FUA index: " << i;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 150 }
151 } // namespace 151 } // namespace
152 152
153 TEST(RtpPacketizerH264Test, TestSingleNalu) { 153 TEST(RtpPacketizerH264Test, TestSingleNalu) {
154 const uint8_t frame[2] = {0x05, 0xFF}; // F=0, NRI=0, Type=5. 154 const uint8_t frame[2] = {0x05, 0xFF}; // F=0, NRI=0, Type=5.
155 RTPFragmentationHeader fragmentation; 155 RTPFragmentationHeader fragmentation;
156 fragmentation.VerifyAndAllocateFragmentationHeader(1); 156 fragmentation.VerifyAndAllocateFragmentationHeader(1);
157 fragmentation.fragmentationOffset[0] = 0; 157 fragmentation.fragmentationOffset[0] = 0;
158 fragmentation.fragmentationLength[0] = sizeof(frame); 158 fragmentation.fragmentationLength[0] = sizeof(frame);
159 rtc::scoped_ptr<RtpPacketizer> packetizer( 159 rtc::scoped_ptr<RtpPacketizer> packetizer(
160 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kFrameEmpty)); 160 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kEmptyFrame));
161 packetizer->SetPayloadData(frame, sizeof(frame), &fragmentation); 161 packetizer->SetPayloadData(frame, sizeof(frame), &fragmentation);
162 uint8_t packet[kMaxPayloadSize] = {0}; 162 uint8_t packet[kMaxPayloadSize] = {0};
163 size_t length = 0; 163 size_t length = 0;
164 bool last = false; 164 bool last = false;
165 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last)); 165 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last));
166 EXPECT_EQ(2u, length); 166 EXPECT_EQ(2u, length);
167 EXPECT_TRUE(last); 167 EXPECT_TRUE(last);
168 VerifySingleNaluPayload( 168 VerifySingleNaluPayload(
169 fragmentation, 0, frame, sizeof(frame), packet, length); 169 fragmentation, 0, frame, sizeof(frame), packet, length);
170 EXPECT_FALSE(packetizer->NextPacket(packet, &length, &last)); 170 EXPECT_FALSE(packetizer->NextPacket(packet, &length, &last));
171 } 171 }
172 172
173 TEST(RtpPacketizerH264Test, TestSingleNaluTwoPackets) { 173 TEST(RtpPacketizerH264Test, TestSingleNaluTwoPackets) {
174 const size_t kFrameSize = kMaxPayloadSize + 100; 174 const size_t kFrameSize = kMaxPayloadSize + 100;
175 uint8_t frame[kFrameSize] = {0}; 175 uint8_t frame[kFrameSize] = {0};
176 for (size_t i = 0; i < kFrameSize; ++i) 176 for (size_t i = 0; i < kFrameSize; ++i)
177 frame[i] = i; 177 frame[i] = i;
178 RTPFragmentationHeader fragmentation; 178 RTPFragmentationHeader fragmentation;
179 fragmentation.VerifyAndAllocateFragmentationHeader(2); 179 fragmentation.VerifyAndAllocateFragmentationHeader(2);
180 fragmentation.fragmentationOffset[0] = 0; 180 fragmentation.fragmentationOffset[0] = 0;
181 fragmentation.fragmentationLength[0] = kMaxPayloadSize; 181 fragmentation.fragmentationLength[0] = kMaxPayloadSize;
182 fragmentation.fragmentationOffset[1] = kMaxPayloadSize; 182 fragmentation.fragmentationOffset[1] = kMaxPayloadSize;
183 fragmentation.fragmentationLength[1] = 100; 183 fragmentation.fragmentationLength[1] = 100;
184 // Set NAL headers. 184 // Set NAL headers.
185 frame[fragmentation.fragmentationOffset[0]] = 0x01; 185 frame[fragmentation.fragmentationOffset[0]] = 0x01;
186 frame[fragmentation.fragmentationOffset[1]] = 0x01; 186 frame[fragmentation.fragmentationOffset[1]] = 0x01;
187 187
188 rtc::scoped_ptr<RtpPacketizer> packetizer( 188 rtc::scoped_ptr<RtpPacketizer> packetizer(
189 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kFrameEmpty)); 189 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kEmptyFrame));
190 packetizer->SetPayloadData(frame, kFrameSize, &fragmentation); 190 packetizer->SetPayloadData(frame, kFrameSize, &fragmentation);
191 191
192 uint8_t packet[kMaxPayloadSize] = {0}; 192 uint8_t packet[kMaxPayloadSize] = {0};
193 size_t length = 0; 193 size_t length = 0;
194 bool last = false; 194 bool last = false;
195 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last)); 195 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last));
196 ASSERT_EQ(fragmentation.fragmentationOffset[1], length); 196 ASSERT_EQ(fragmentation.fragmentationOffset[1], length);
197 VerifySingleNaluPayload(fragmentation, 0, frame, kFrameSize, packet, length); 197 VerifySingleNaluPayload(fragmentation, 0, frame, kFrameSize, packet, length);
198 198
199 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last)); 199 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last));
(...skipping 16 matching lines...) Expand all
216 RTPFragmentationHeader fragmentation; 216 RTPFragmentationHeader fragmentation;
217 fragmentation.VerifyAndAllocateFragmentationHeader(3); 217 fragmentation.VerifyAndAllocateFragmentationHeader(3);
218 fragmentation.fragmentationOffset[0] = 0; 218 fragmentation.fragmentationOffset[0] = 0;
219 fragmentation.fragmentationLength[0] = 2; 219 fragmentation.fragmentationLength[0] = 2;
220 fragmentation.fragmentationOffset[1] = 2; 220 fragmentation.fragmentationOffset[1] = 2;
221 fragmentation.fragmentationLength[1] = 2; 221 fragmentation.fragmentationLength[1] = 2;
222 fragmentation.fragmentationOffset[2] = 4; 222 fragmentation.fragmentationOffset[2] = 4;
223 fragmentation.fragmentationLength[2] = 223 fragmentation.fragmentationLength[2] =
224 kNalHeaderSize + kFrameSize - kPayloadOffset; 224 kNalHeaderSize + kFrameSize - kPayloadOffset;
225 rtc::scoped_ptr<RtpPacketizer> packetizer( 225 rtc::scoped_ptr<RtpPacketizer> packetizer(
226 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kFrameEmpty)); 226 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kEmptyFrame));
227 packetizer->SetPayloadData(frame, kFrameSize, &fragmentation); 227 packetizer->SetPayloadData(frame, kFrameSize, &fragmentation);
228 228
229 uint8_t packet[kMaxPayloadSize] = {0}; 229 uint8_t packet[kMaxPayloadSize] = {0};
230 size_t length = 0; 230 size_t length = 0;
231 bool last = false; 231 bool last = false;
232 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last)); 232 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last));
233 size_t expected_packet_size = 233 size_t expected_packet_size =
234 kNalHeaderSize + 3 * kLengthFieldLength + kFrameSize; 234 kNalHeaderSize + 3 * kLengthFieldLength + kFrameSize;
235 ASSERT_EQ(expected_packet_size, length); 235 ASSERT_EQ(expected_packet_size, length);
236 EXPECT_TRUE(last); 236 EXPECT_TRUE(last);
(...skipping 14 matching lines...) Expand all
251 RTPFragmentationHeader fragmentation; 251 RTPFragmentationHeader fragmentation;
252 fragmentation.VerifyAndAllocateFragmentationHeader(3); 252 fragmentation.VerifyAndAllocateFragmentationHeader(3);
253 fragmentation.fragmentationOffset[0] = 0; 253 fragmentation.fragmentationOffset[0] = 0;
254 fragmentation.fragmentationLength[0] = 2; 254 fragmentation.fragmentationLength[0] = 2;
255 fragmentation.fragmentationOffset[1] = 2; 255 fragmentation.fragmentationOffset[1] = 2;
256 fragmentation.fragmentationLength[1] = 2; 256 fragmentation.fragmentationLength[1] = 2;
257 fragmentation.fragmentationOffset[2] = 4; 257 fragmentation.fragmentationOffset[2] = 4;
258 fragmentation.fragmentationLength[2] = 258 fragmentation.fragmentationLength[2] =
259 kNalHeaderSize + kFrameSize - kPayloadOffset; 259 kNalHeaderSize + kFrameSize - kPayloadOffset;
260 rtc::scoped_ptr<RtpPacketizer> packetizer( 260 rtc::scoped_ptr<RtpPacketizer> packetizer(
261 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kFrameEmpty)); 261 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kEmptyFrame));
262 packetizer->SetPayloadData(frame, kFrameSize, &fragmentation); 262 packetizer->SetPayloadData(frame, kFrameSize, &fragmentation);
263 263
264 uint8_t packet[kMaxPayloadSize] = {0}; 264 uint8_t packet[kMaxPayloadSize] = {0};
265 size_t length = 0; 265 size_t length = 0;
266 bool last = false; 266 bool last = false;
267 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last)); 267 ASSERT_TRUE(packetizer->NextPacket(packet, &length, &last));
268 size_t expected_packet_size = kNalHeaderSize; 268 size_t expected_packet_size = kNalHeaderSize;
269 for (size_t i = 0; i < 2; ++i) { 269 for (size_t i = 0; i < 2; ++i) {
270 expected_packet_size += 270 expected_packet_size +=
271 kLengthFieldLength + fragmentation.fragmentationLength[i]; 271 kLengthFieldLength + fragmentation.fragmentationLength[i];
(...skipping 27 matching lines...) Expand all
299 uint8_t frame[kFrameSize]; 299 uint8_t frame[kFrameSize];
300 size_t nalu_offset = 0; 300 size_t nalu_offset = 0;
301 for (size_t i = 0; i < fragmentation.fragmentationVectorSize; ++i) { 301 for (size_t i = 0; i < fragmentation.fragmentationVectorSize; ++i) {
302 nalu_offset = fragmentation.fragmentationOffset[i]; 302 nalu_offset = fragmentation.fragmentationOffset[i];
303 frame[nalu_offset] = 0x05; // F=0, NRI=0, Type=5. 303 frame[nalu_offset] = 0x05; // F=0, NRI=0, Type=5.
304 for (size_t j = 1; j < fragmentation.fragmentationLength[i]; ++j) { 304 for (size_t j = 1; j < fragmentation.fragmentationLength[i]; ++j) {
305 frame[nalu_offset + j] = i + j; 305 frame[nalu_offset + j] = i + j;
306 } 306 }
307 } 307 }
308 rtc::scoped_ptr<RtpPacketizer> packetizer( 308 rtc::scoped_ptr<RtpPacketizer> packetizer(
309 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kFrameEmpty)); 309 RtpPacketizer::Create(kRtpVideoH264, kMaxPayloadSize, NULL, kEmptyFrame));
310 packetizer->SetPayloadData(frame, kFrameSize, &fragmentation); 310 packetizer->SetPayloadData(frame, kFrameSize, &fragmentation);
311 311
312 // First expecting two FU-A packets. 312 // First expecting two FU-A packets.
313 std::vector<size_t> fua_sizes; 313 std::vector<size_t> fua_sizes;
314 fua_sizes.push_back(1100); 314 fua_sizes.push_back(1100);
315 fua_sizes.push_back(1099); 315 fua_sizes.push_back(1099);
316 uint8_t packet[kMaxPayloadSize] = {0}; 316 uint8_t packet[kMaxPayloadSize] = {0};
317 size_t length = 0; 317 size_t length = 0;
318 bool last = false; 318 bool last = false;
319 int fua_offset = kNalHeaderSize; 319 int fua_offset = kNalHeaderSize;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 EXPECT_FALSE(depacketizer_->Parse(&payload, kPayload, sizeof(kPayload))); 563 EXPECT_FALSE(depacketizer_->Parse(&payload, kPayload, sizeof(kPayload)));
564 } 564 }
565 565
566 TEST_F(RtpDepacketizerH264Test, TestShortSpsPacket) { 566 TEST_F(RtpDepacketizerH264Test, TestShortSpsPacket) {
567 const uint8_t kPayload[] = {0x27, 0x80, 0x00}; 567 const uint8_t kPayload[] = {0x27, 0x80, 0x00};
568 RtpDepacketizer::ParsedPayload payload; 568 RtpDepacketizer::ParsedPayload payload;
569 EXPECT_TRUE(depacketizer_->Parse(&payload, kPayload, sizeof(kPayload))); 569 EXPECT_TRUE(depacketizer_->Parse(&payload, kPayload, sizeof(kPayload)));
570 } 570 }
571 571
572 } // namespace webrtc 572 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/main/test/utility.cc ('k') | webrtc/modules/rtp_rtcp/source/rtp_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698