OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 expected.insert(expected.end(), {1, 2, 3, 2, 1}); | 258 expected.insert(expected.end(), {1, 2, 3, 2, 1}); |
259 | 259 |
260 EXPECT_EQ(memcmp(packet.dataPtr, expected.data(), expected.size()), 0); | 260 EXPECT_EQ(memcmp(packet.dataPtr, expected.data(), expected.size()), 0); |
261 delete[] packet.dataPtr; | 261 delete[] packet.dataPtr; |
262 } | 262 } |
263 | 263 |
264 TEST_F(TestH264SpsPpsTracker, SpsPpsOutOfBand) { | 264 TEST_F(TestH264SpsPpsTracker, SpsPpsOutOfBand) { |
265 constexpr uint8_t kData[] = {1, 2, 3}; | 265 constexpr uint8_t kData[] = {1, 2, 3}; |
266 | 266 |
267 // Generated by "ffmpeg -r 30 -f avfoundation -i "default" out.h264" on macos. | 267 // Generated by "ffmpeg -r 30 -f avfoundation -i "default" out.h264" on macos. |
| 268 // width: 320, height: 240 |
268 const std::vector<uint8_t> sps( | 269 const std::vector<uint8_t> sps( |
269 {0x67, 0x7a, 0x00, 0x0d, 0xbc, 0xd9, 0x41, 0x41, 0xfa, 0x10, 0x00, 0x00, | 270 {0x67, 0x7a, 0x00, 0x0d, 0xbc, 0xd9, 0x41, 0x41, 0xfa, 0x10, 0x00, 0x00, |
270 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03, 0xc0, 0xf1, 0x42, 0x99, 0x60}); | 271 0x03, 0x00, 0x10, 0x00, 0x00, 0x03, 0x03, 0xc0, 0xf1, 0x42, 0x99, 0x60}); |
271 const std::vector<uint8_t> pps({0x68, 0xeb, 0xe3, 0xcb, 0x22, 0xc0}); | 272 const std::vector<uint8_t> pps({0x68, 0xeb, 0xe3, 0xcb, 0x22, 0xc0}); |
272 tracker_.InsertSpsPpsNalus(sps, pps); | 273 tracker_.InsertSpsPpsNalus(sps, pps); |
273 | 274 |
274 // Insert first packet of the IDR. | 275 // Insert first packet of the IDR. |
275 VCMPacket idr_packet = GetDefaultPacket(); | 276 VCMPacket idr_packet = GetDefaultPacket(); |
276 idr_packet.video_header.is_first_packet_in_frame = true; | 277 idr_packet.video_header.is_first_packet_in_frame = true; |
277 AddIdr(&idr_packet, 0); | 278 AddIdr(&idr_packet, 0); |
278 idr_packet.dataPtr = kData; | 279 idr_packet.dataPtr = kData; |
279 idr_packet.sizeBytes = sizeof(kData); | 280 idr_packet.sizeBytes = sizeof(kData); |
280 EXPECT_EQ(H264SpsPpsTracker::kInsert, | 281 EXPECT_EQ(H264SpsPpsTracker::kInsert, |
281 tracker_.CopyAndFixBitstream(&idr_packet)); | 282 tracker_.CopyAndFixBitstream(&idr_packet)); |
| 283 EXPECT_EQ(320, idr_packet.width); |
| 284 EXPECT_EQ(240, idr_packet.height); |
282 if (idr_packet.dataPtr != kData) { | 285 if (idr_packet.dataPtr != kData) { |
283 // In case CopyAndFixBitStream() prepends SPS/PPS nalus to the packet, it | 286 // In case CopyAndFixBitStream() prepends SPS/PPS nalus to the packet, it |
284 // uses new uint8_t[] to allocate memory. Caller of CopyAndFixBitStream() | 287 // uses new uint8_t[] to allocate memory. Caller of CopyAndFixBitStream() |
285 // needs to take care of freeing the memory. | 288 // needs to take care of freeing the memory. |
286 delete[] idr_packet.dataPtr; | 289 delete[] idr_packet.dataPtr; |
287 } | 290 } |
288 } | 291 } |
289 | 292 |
290 TEST_F(TestH264SpsPpsTracker, SpsPpsOutOfBandWrongNaluHeader) { | 293 TEST_F(TestH264SpsPpsTracker, SpsPpsOutOfBandWrongNaluHeader) { |
291 constexpr uint8_t kData[] = {1, 2, 3}; | 294 constexpr uint8_t kData[] = {1, 2, 3}; |
(...skipping 28 matching lines...) Expand all Loading... |
320 // Insert first packet of the IDR. | 323 // Insert first packet of the IDR. |
321 VCMPacket idr_packet = GetDefaultPacket(); | 324 VCMPacket idr_packet = GetDefaultPacket(); |
322 idr_packet.video_header.is_first_packet_in_frame = true; | 325 idr_packet.video_header.is_first_packet_in_frame = true; |
323 AddIdr(&idr_packet, 0); | 326 AddIdr(&idr_packet, 0); |
324 idr_packet.dataPtr = kData; | 327 idr_packet.dataPtr = kData; |
325 idr_packet.sizeBytes = sizeof(kData); | 328 idr_packet.sizeBytes = sizeof(kData); |
326 EXPECT_EQ(H264SpsPpsTracker::kRequestKeyframe, | 329 EXPECT_EQ(H264SpsPpsTracker::kRequestKeyframe, |
327 tracker_.CopyAndFixBitstream(&idr_packet)); | 330 tracker_.CopyAndFixBitstream(&idr_packet)); |
328 } | 331 } |
329 | 332 |
| 333 TEST_F(TestH264SpsPpsTracker, SaveRestoreWidthHeight) { |
| 334 std::vector<uint8_t> data; |
| 335 |
| 336 // Insert an SPS/PPS packet with width/height and make sure |
| 337 // that information is set on the first IDR packet. |
| 338 VCMPacket sps_pps_packet1 = GetDefaultPacket(); |
| 339 AddSps(&sps_pps_packet1, 0, &data); |
| 340 AddPps(&sps_pps_packet1, 0, 1, &data); |
| 341 sps_pps_packet1.dataPtr = data.data(); |
| 342 sps_pps_packet1.sizeBytes = data.size(); |
| 343 sps_pps_packet1.width = 320; |
| 344 sps_pps_packet1.height = 240; |
| 345 EXPECT_EQ(H264SpsPpsTracker::kDrop, |
| 346 tracker_.CopyAndFixBitstream(&sps_pps_packet1)); |
| 347 |
| 348 VCMPacket idr_packet1 = GetDefaultPacket(); |
| 349 idr_packet1.video_header.is_first_packet_in_frame = true; |
| 350 AddIdr(&idr_packet1, 1); |
| 351 data.insert(data.end(), {1, 2, 3}); |
| 352 idr_packet1.dataPtr = data.data(); |
| 353 idr_packet1.sizeBytes = data.size(); |
| 354 EXPECT_EQ(H264SpsPpsTracker::kInsert, |
| 355 tracker_.CopyAndFixBitstream(&idr_packet1)); |
| 356 |
| 357 EXPECT_EQ(320, idr_packet1.width); |
| 358 EXPECT_EQ(240, idr_packet1.height); |
| 359 delete[] idr_packet1.dataPtr; |
| 360 } |
| 361 |
330 } // namespace video_coding | 362 } // namespace video_coding |
331 } // namespace webrtc | 363 } // namespace webrtc |
OLD | NEW |