| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string.h> |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "media/mp4/avc.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/gtest/include/gtest/gtest-param-test.h" |
| 11 |
| 12 using media::mp4::ConvertAVCCToAnnexB; |
| 13 |
| 14 const static uint8 kNALU1[] = { 0x01, 0x02, 0x03 }; |
| 15 const static uint8 kNALU2[] = { 0x04, 0x05, 0x06, 0x07 }; |
| 16 const static uint8 kExpected[] = { |
| 17 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, |
| 18 0x00, 0x00, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07 }; |
| 19 |
| 20 class AVCCConversionTest : public testing::TestWithParam<uint32> { |
| 21 protected: |
| 22 void MakeInputForLength(uint32 length_size, std::vector<uint8>* buf) { |
| 23 buf->clear(); |
| 24 for (uint32 i = 1; i < length_size; i++) { |
| 25 buf->push_back(0); |
| 26 } |
| 27 buf->push_back(sizeof(kNALU1)); |
| 28 buf->insert(buf->end(), kNALU1, kNALU1 + sizeof(kNALU1)); |
| 29 |
| 30 for (uint32 i = 1; i < length_size; i++) { |
| 31 buf->push_back(0); |
| 32 } |
| 33 buf->push_back(sizeof(kNALU2)); |
| 34 buf->insert(buf->end(), kNALU2, kNALU2 + sizeof(kNALU2)); |
| 35 } |
| 36 }; |
| 37 |
| 38 TEST_P(AVCCConversionTest, ParseCorrectly) { |
| 39 std::vector<uint8> buf; |
| 40 MakeInputForLength(GetParam(), &buf); |
| 41 EXPECT_TRUE(ConvertAVCCToAnnexB(GetParam(), &buf)); |
| 42 ASSERT_EQ(buf.size(), sizeof(kExpected)); |
| 43 ASSERT_EQ(0, memcmp(kExpected, &buf[0], sizeof(kExpected))); |
| 44 } |
| 45 |
| 46 TEST_P(AVCCConversionTest, ParsePartial) { |
| 47 std::vector<uint8> buf; |
| 48 MakeInputForLength(GetParam(), &buf); |
| 49 buf.pop_back(); |
| 50 EXPECT_FALSE(ConvertAVCCToAnnexB(GetParam(), &buf)); |
| 51 // This actually still works for one-byte sizes. |
| 52 if (GetParam() != 1) { |
| 53 MakeInputForLength(GetParam(), &buf); |
| 54 buf.erase(buf.end() - (sizeof(kNALU2) + 1), buf.end()); |
| 55 EXPECT_FALSE(ConvertAVCCToAnnexB(GetParam(), &buf)); |
| 56 } |
| 57 } |
| 58 |
| 59 TEST_P(AVCCConversionTest, ParseEmpty) { |
| 60 std::vector<uint8> buf; |
| 61 EXPECT_TRUE(ConvertAVCCToAnnexB(GetParam(), &buf)); |
| 62 EXPECT_EQ(0u, buf.size()); |
| 63 } |
| 64 |
| 65 INSTANTIATE_TEST_CASE_P(AVCCConversionTestValues, |
| 66 AVCCConversionTest, |
| 67 ::testing::Values(1, 2, 4)); |
| OLD | NEW |