| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast)); | 298 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast)); |
| 299 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast)); | 299 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast)); |
| 300 | 300 |
| 301 ASSERT_EQ(4UL, frames_from_callback_.size()); | 301 ASSERT_EQ(4UL, frames_from_callback_.size()); |
| 302 CheckFrame(seq_num); | 302 CheckFrame(seq_num); |
| 303 CheckFrame(seq_num + 1); | 303 CheckFrame(seq_num + 1); |
| 304 CheckFrame(seq_num + 2); | 304 CheckFrame(seq_num + 2); |
| 305 CheckFrame(seq_num + 3); | 305 CheckFrame(seq_num + 3); |
| 306 } | 306 } |
| 307 | 307 |
| 308 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) { | 308 TEST_F(TestPacketBuffer, GetBitstream) { |
| 309 // "many bitstream, such data" with null termination. | 309 // "many bitstream, such data" with null termination. |
| 310 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; | 310 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; |
| 311 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, | 311 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, |
| 312 0x65, 0x61, 0x6d, 0x2c, 0x20}; | 312 0x65, 0x61, 0x6d, 0x2c, 0x20}; |
| 313 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; | 313 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; |
| 314 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; | 314 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; |
| 315 uint8_t | 315 uint8_t |
| 316 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; | 316 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; |
| 317 | 317 |
| 318 const uint16_t seq_num = Rand(); | 318 const uint16_t seq_num = Rand(); |
| 319 | 319 |
| 320 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many)); | 320 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many)); |
| 321 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, | 321 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, |
| 322 sizeof(bitstream), bitstream)); | 322 sizeof(bitstream), bitstream)); |
| 323 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, | 323 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, |
| 324 sizeof(such), such)); | 324 sizeof(such), such)); |
| 325 EXPECT_TRUE( | 325 EXPECT_TRUE( |
| 326 Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data)); | 326 Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data)); |
| 327 | 327 |
| 328 ASSERT_EQ(1UL, frames_from_callback_.size()); | 328 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 329 CheckFrame(seq_num); | 329 CheckFrame(seq_num); |
| 330 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); | 330 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); |
| 331 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); | 331 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); |
| 332 } | 332 } |
| 333 | 333 |
| 334 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) { |
| 335 uint16_t seq_num = Rand(); |
| 336 uint8_t data[] = "some plain old data"; |
| 337 |
| 338 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time. |
| 339 uint8_t* result = |
| 340 new uint8_t[sizeof(data) + EncodedImage::kBufferPaddingBytesH264]; |
| 341 |
| 342 VCMPacket packet; |
| 343 packet.seqNum = seq_num; |
| 344 packet.codec = kVideoCodecH264; |
| 345 packet.insertStartCode = true; |
| 346 packet.video_header.codecHeader.H264.packetization_type = kH264SingleNalu; |
| 347 packet.dataPtr = data; |
| 348 packet.sizeBytes = sizeof(data); |
| 349 packet.isFirstPacket = true; |
| 350 packet.markerBit = true; |
| 351 packet_buffer_->InsertPacket(packet); |
| 352 |
| 353 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 354 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._length, |
| 355 sizeof(data)); |
| 356 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._size, |
| 357 sizeof(data) + EncodedImage::kBufferPaddingBytesH264); |
| 358 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); |
| 359 EXPECT_EQ(memcmp(result, data, sizeof(data)), 0); |
| 360 delete[] result; |
| 361 } |
| 362 |
| 334 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) { | 363 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) { |
| 335 const uint16_t seq_num = Rand(); | 364 const uint16_t seq_num = Rand(); |
| 336 | 365 |
| 337 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); | 366 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); |
| 338 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast)); | 367 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast)); |
| 339 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast)); | 368 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast)); |
| 340 EXPECT_EQ(1UL, frames_from_callback_.size()); | 369 EXPECT_EQ(1UL, frames_from_callback_.size()); |
| 341 CheckFrame(seq_num); | 370 CheckFrame(seq_num); |
| 342 | 371 |
| 343 frames_from_callback_.clear(); | 372 frames_from_callback_.clear(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 | 404 |
| 376 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); | 405 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); |
| 377 ASSERT_EQ(1UL, frames_from_callback_.size()); | 406 ASSERT_EQ(1UL, frames_from_callback_.size()); |
| 378 | 407 |
| 379 packet_buffer_->Clear(); | 408 packet_buffer_->Clear(); |
| 380 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr)); | 409 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr)); |
| 381 } | 410 } |
| 382 | 411 |
| 383 } // namespace video_coding | 412 } // namespace video_coding |
| 384 } // namespace webrtc | 413 } // namespace webrtc |
| OLD | NEW |