| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // +-+-+-+-+-+-+-+-+ | 53 // +-+-+-+-+-+-+-+-+ |
| 54 // | Bytes 4..N of | | 54 // | Bytes 4..N of | |
| 55 // | VP8 payload | | 55 // | VP8 payload | |
| 56 // : : | 56 // : : |
| 57 // +-+-+-+-+-+-+-+-+ | 57 // +-+-+-+-+-+-+-+-+ |
| 58 // | OPTIONAL RTP | | 58 // | OPTIONAL RTP | |
| 59 // | padding | | 59 // | padding | |
| 60 // : : | 60 // : : |
| 61 // +-+-+-+-+-+-+-+-+ | 61 // +-+-+-+-+-+-+-+-+ |
| 62 void VerifyBasicHeader(RTPTypeHeader* type, bool N, bool S, int part_id) { | 62 void VerifyBasicHeader(RTPTypeHeader* type, bool N, bool S, int part_id) { |
| 63 ASSERT_TRUE(type != NULL); | 63 ASSERT_TRUE(type != nullptr); |
| 64 EXPECT_EQ(N, type->Video.codecHeader.VP8.nonReference); | 64 EXPECT_EQ(N, type->Video.codecHeader.VP8.nonReference); |
| 65 EXPECT_EQ(S, type->Video.codecHeader.VP8.beginningOfPartition); | 65 EXPECT_EQ(S, type->Video.codecHeader.VP8.beginningOfPartition); |
| 66 EXPECT_EQ(part_id, type->Video.codecHeader.VP8.partitionId); | 66 EXPECT_EQ(part_id, type->Video.codecHeader.VP8.partitionId); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void VerifyExtensions(RTPTypeHeader* type, | 69 void VerifyExtensions(RTPTypeHeader* type, |
| 70 int16_t picture_id, /* I */ | 70 int16_t picture_id, /* I */ |
| 71 int16_t tl0_pic_idx, /* L */ | 71 int16_t tl0_pic_idx, /* L */ |
| 72 uint8_t temporal_idx, /* T */ | 72 uint8_t temporal_idx, /* T */ |
| 73 int key_idx /* K */) { | 73 int key_idx /* K */) { |
| 74 ASSERT_TRUE(type != NULL); | 74 ASSERT_TRUE(type != nullptr); |
| 75 EXPECT_EQ(picture_id, type->Video.codecHeader.VP8.pictureId); | 75 EXPECT_EQ(picture_id, type->Video.codecHeader.VP8.pictureId); |
| 76 EXPECT_EQ(tl0_pic_idx, type->Video.codecHeader.VP8.tl0PicIdx); | 76 EXPECT_EQ(tl0_pic_idx, type->Video.codecHeader.VP8.tl0PicIdx); |
| 77 EXPECT_EQ(temporal_idx, type->Video.codecHeader.VP8.temporalIdx); | 77 EXPECT_EQ(temporal_idx, type->Video.codecHeader.VP8.temporalIdx); |
| 78 EXPECT_EQ(key_idx, type->Video.codecHeader.VP8.keyIdx); | 78 EXPECT_EQ(key_idx, type->Video.codecHeader.VP8.keyIdx); |
| 79 } | 79 } |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 class RtpPacketizerVp8Test : public ::testing::Test { | 82 class RtpPacketizerVp8Test : public ::testing::Test { |
| 83 protected: | 83 protected: |
| 84 RtpPacketizerVp8Test() : helper_(NULL) {} | 84 RtpPacketizerVp8Test() : helper_(nullptr) {} |
| 85 virtual void TearDown() { delete helper_; } | 85 virtual void TearDown() { delete helper_; } |
| 86 bool Init(const size_t* partition_sizes, size_t num_partitions) { | 86 bool Init(const size_t* partition_sizes, size_t num_partitions) { |
| 87 hdr_info_.pictureId = kNoPictureId; | 87 hdr_info_.pictureId = kNoPictureId; |
| 88 hdr_info_.nonReference = false; | 88 hdr_info_.nonReference = false; |
| 89 hdr_info_.temporalIdx = kNoTemporalIdx; | 89 hdr_info_.temporalIdx = kNoTemporalIdx; |
| 90 hdr_info_.layerSync = false; | 90 hdr_info_.layerSync = false; |
| 91 hdr_info_.tl0PicIdx = kNoTl0PicIdx; | 91 hdr_info_.tl0PicIdx = kNoTl0PicIdx; |
| 92 hdr_info_.keyIdx = kNoKeyIdx; | 92 hdr_info_.keyIdx = kNoKeyIdx; |
| 93 if (helper_ != NULL) | 93 if (helper_ != nullptr) |
| 94 return false; | 94 return false; |
| 95 helper_ = new test::RtpFormatVp8TestHelper(&hdr_info_); | 95 helper_ = new test::RtpFormatVp8TestHelper(&hdr_info_); |
| 96 return helper_->Init(partition_sizes, num_partitions); | 96 return helper_->Init(partition_sizes, num_partitions); |
| 97 } | 97 } |
| 98 | 98 |
| 99 RTPVideoHeaderVP8 hdr_info_; | 99 RTPVideoHeaderVP8 hdr_info_; |
| 100 test::RtpFormatVp8TestHelper* helper_; | 100 test::RtpFormatVp8TestHelper* helper_; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 TEST_F(RtpPacketizerVp8Test, TestStrictMode) { | 103 TEST_F(RtpPacketizerVp8Test, TestStrictMode) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 264 |
| 265 // Verify that EqualSize mode is forced if fragmentation info is missing. | 265 // Verify that EqualSize mode is forced if fragmentation info is missing. |
| 266 TEST_F(RtpPacketizerVp8Test, TestEqualSizeModeFallback) { | 266 TEST_F(RtpPacketizerVp8Test, TestEqualSizeModeFallback) { |
| 267 const size_t kSizeVector[] = {10, 10, 10}; | 267 const size_t kSizeVector[] = {10, 10, 10}; |
| 268 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); | 268 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); |
| 269 ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); | 269 ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); |
| 270 | 270 |
| 271 hdr_info_.pictureId = 200; // > 0x7F should produce 2-byte PictureID | 271 hdr_info_.pictureId = 200; // > 0x7F should produce 2-byte PictureID |
| 272 const size_t kMaxPayloadSize = 12; // Small enough to produce 4 packets. | 272 const size_t kMaxPayloadSize = 12; // Small enough to produce 4 packets. |
| 273 RtpPacketizerVp8 packetizer(hdr_info_, kMaxPayloadSize); | 273 RtpPacketizerVp8 packetizer(hdr_info_, kMaxPayloadSize); |
| 274 packetizer.SetPayloadData( | 274 packetizer.SetPayloadData(helper_->payload_data(), helper_->payload_size(), |
| 275 helper_->payload_data(), helper_->payload_size(), NULL); | 275 nullptr); |
| 276 | 276 |
| 277 // Expecting three full packets, and one with the remainder. | 277 // Expecting three full packets, and one with the remainder. |
| 278 const size_t kExpectedSizes[] = {12, 11, 12, 11}; | 278 const size_t kExpectedSizes[] = {12, 11, 12, 11}; |
| 279 const int kExpectedPart[] = {0, 0, 0, 0}; // Always 0 for equal size mode. | 279 const int kExpectedPart[] = {0, 0, 0, 0}; // Always 0 for equal size mode. |
| 280 // Frag start only true for first packet in equal size mode. | 280 // Frag start only true for first packet in equal size mode. |
| 281 const bool kExpectedFragStart[] = {true, false, false, false}; | 281 const bool kExpectedFragStart[] = {true, false, false, false}; |
| 282 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes); | 282 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes); |
| 283 CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart); | 283 CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart); |
| 284 CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart); | 284 CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart); |
| 285 | 285 |
| 286 helper_->set_sloppy_partitioning(true); | 286 helper_->set_sloppy_partitioning(true); |
| 287 helper_->GetAllPacketsAndCheck(&packetizer, | 287 helper_->GetAllPacketsAndCheck(&packetizer, |
| 288 kExpectedSizes, | 288 kExpectedSizes, |
| 289 kExpectedPart, | 289 kExpectedPart, |
| 290 kExpectedFragStart, | 290 kExpectedFragStart, |
| 291 kExpectedNum); | 291 kExpectedNum); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Verify that non-reference bit is set. EqualSize mode fallback is expected. | 294 // Verify that non-reference bit is set. EqualSize mode fallback is expected. |
| 295 TEST_F(RtpPacketizerVp8Test, TestNonReferenceBit) { | 295 TEST_F(RtpPacketizerVp8Test, TestNonReferenceBit) { |
| 296 const size_t kSizeVector[] = {10, 10, 10}; | 296 const size_t kSizeVector[] = {10, 10, 10}; |
| 297 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); | 297 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kSizeVector); |
| 298 ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); | 298 ASSERT_TRUE(Init(kSizeVector, kNumPartitions)); |
| 299 | 299 |
| 300 hdr_info_.nonReference = true; | 300 hdr_info_.nonReference = true; |
| 301 const size_t kMaxPayloadSize = 25; // Small enough to produce two packets. | 301 const size_t kMaxPayloadSize = 25; // Small enough to produce two packets. |
| 302 RtpPacketizerVp8 packetizer(hdr_info_, kMaxPayloadSize); | 302 RtpPacketizerVp8 packetizer(hdr_info_, kMaxPayloadSize); |
| 303 packetizer.SetPayloadData( | 303 packetizer.SetPayloadData(helper_->payload_data(), helper_->payload_size(), |
| 304 helper_->payload_data(), helper_->payload_size(), NULL); | 304 nullptr); |
| 305 | 305 |
| 306 // EqualSize mode => First packet full; other not. | 306 // EqualSize mode => First packet full; other not. |
| 307 const size_t kExpectedSizes[] = {16, 16}; | 307 const size_t kExpectedSizes[] = {16, 16}; |
| 308 const int kExpectedPart[] = {0, 0}; // Always 0 for equal size mode. | 308 const int kExpectedPart[] = {0, 0}; // Always 0 for equal size mode. |
| 309 // Frag start only true for first packet in equal size mode. | 309 // Frag start only true for first packet in equal size mode. |
| 310 const bool kExpectedFragStart[] = {true, false}; | 310 const bool kExpectedFragStart[] = {true, false}; |
| 311 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes); | 311 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes); |
| 312 CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart); | 312 CHECK_ARRAY_SIZE(kExpectedNum, kExpectedPart); |
| 313 CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart); | 313 CHECK_ARRAY_SIZE(kExpectedNum, kExpectedFragStart); |
| 314 | 314 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 } | 411 } |
| 412 | 412 |
| 413 class RtpDepacketizerVp8Test : public ::testing::Test { | 413 class RtpDepacketizerVp8Test : public ::testing::Test { |
| 414 protected: | 414 protected: |
| 415 RtpDepacketizerVp8Test() | 415 RtpDepacketizerVp8Test() |
| 416 : depacketizer_(RtpDepacketizer::Create(kRtpVideoVp8)) {} | 416 : depacketizer_(RtpDepacketizer::Create(kRtpVideoVp8)) {} |
| 417 | 417 |
| 418 void ExpectPacket(RtpDepacketizer::ParsedPayload* parsed_payload, | 418 void ExpectPacket(RtpDepacketizer::ParsedPayload* parsed_payload, |
| 419 const uint8_t* data, | 419 const uint8_t* data, |
| 420 size_t length) { | 420 size_t length) { |
| 421 ASSERT_TRUE(parsed_payload != NULL); | 421 ASSERT_TRUE(parsed_payload != nullptr); |
| 422 EXPECT_THAT(std::vector<uint8_t>( | 422 EXPECT_THAT(std::vector<uint8_t>( |
| 423 parsed_payload->payload, | 423 parsed_payload->payload, |
| 424 parsed_payload->payload + parsed_payload->payload_length), | 424 parsed_payload->payload + parsed_payload->payload_length), |
| 425 ::testing::ElementsAreArray(data, length)); | 425 ::testing::ElementsAreArray(data, length)); |
| 426 } | 426 } |
| 427 | 427 |
| 428 std::unique_ptr<RtpDepacketizer> depacketizer_; | 428 std::unique_ptr<RtpDepacketizer> depacketizer_; |
| 429 }; | 429 }; |
| 430 | 430 |
| 431 TEST_F(RtpDepacketizerVp8Test, BasicHeader) { | 431 TEST_F(RtpDepacketizerVp8Test, BasicHeader) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 uint8_t data[10] = {0}; | 573 uint8_t data[10] = {0}; |
| 574 RtpPacketToSend packet(kNoExtensions); | 574 RtpPacketToSend packet(kNoExtensions); |
| 575 RTPVideoHeaderVP8 input_header; | 575 RTPVideoHeaderVP8 input_header; |
| 576 input_header.nonReference = true; | 576 input_header.nonReference = true; |
| 577 input_header.pictureId = 300; | 577 input_header.pictureId = 300; |
| 578 input_header.temporalIdx = 1; | 578 input_header.temporalIdx = 1; |
| 579 input_header.layerSync = false; | 579 input_header.layerSync = false; |
| 580 input_header.tl0PicIdx = kNoTl0PicIdx; // Disable. | 580 input_header.tl0PicIdx = kNoTl0PicIdx; // Disable. |
| 581 input_header.keyIdx = 31; | 581 input_header.keyIdx = 31; |
| 582 RtpPacketizerVp8 packetizer(input_header, 20); | 582 RtpPacketizerVp8 packetizer(input_header, 20); |
| 583 packetizer.SetPayloadData(data, 10, NULL); | 583 packetizer.SetPayloadData(data, 10, nullptr); |
| 584 bool last; | 584 bool last; |
| 585 ASSERT_TRUE(packetizer.NextPacket(&packet, &last)); | 585 ASSERT_TRUE(packetizer.NextPacket(&packet, &last)); |
| 586 EXPECT_TRUE(last); | 586 EXPECT_TRUE(last); |
| 587 EXPECT_TRUE(packet.Marker()); | 587 EXPECT_TRUE(packet.Marker()); |
| 588 | 588 |
| 589 auto rtp_payload = packet.payload(); | 589 auto rtp_payload = packet.payload(); |
| 590 RtpDepacketizer::ParsedPayload payload; | 590 RtpDepacketizer::ParsedPayload payload; |
| 591 ASSERT_TRUE( | 591 ASSERT_TRUE( |
| 592 depacketizer_->Parse(&payload, rtp_payload.data(), rtp_payload.size())); | 592 depacketizer_->Parse(&payload, rtp_payload.data(), rtp_payload.size())); |
| 593 auto vp8_payload = rtp_payload.subview(kHeaderLength); | 593 auto vp8_payload = rtp_payload.subview(kHeaderLength); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 604 input_header.layerSync); | 604 input_header.layerSync); |
| 605 } | 605 } |
| 606 | 606 |
| 607 TEST_F(RtpDepacketizerVp8Test, TestEmptyPayload) { | 607 TEST_F(RtpDepacketizerVp8Test, TestEmptyPayload) { |
| 608 // Using a wild pointer to crash on accesses from inside the depacketizer. | 608 // Using a wild pointer to crash on accesses from inside the depacketizer. |
| 609 uint8_t* garbage_ptr = reinterpret_cast<uint8_t*>(0x4711); | 609 uint8_t* garbage_ptr = reinterpret_cast<uint8_t*>(0x4711); |
| 610 RtpDepacketizer::ParsedPayload payload; | 610 RtpDepacketizer::ParsedPayload payload; |
| 611 EXPECT_FALSE(depacketizer_->Parse(&payload, garbage_ptr, 0)); | 611 EXPECT_FALSE(depacketizer_->Parse(&payload, garbage_ptr, 0)); |
| 612 } | 612 } |
| 613 } // namespace webrtc | 613 } // namespace webrtc |
| OLD | NEW |