Chromium Code Reviews| 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 namespace media { | |
| 13 namespace mp4 { | |
| 14 | |
| 15 const static uint8 kNALU1[] = { 0x01, 0x02, 0x03 }; | |
|
acolwell GONE FROM CHROMIUM
2012/06/08 16:10:38
lint nit: static comes first
strobe_
2012/06/11 18:44:21
Done.
| |
| 16 const static uint8 kNALU2[] = { 0x04, 0x05, 0x06, 0x07 }; | |
| 17 const static uint8 kExpected[] = { | |
| 18 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, | |
| 19 0x00, 0x00, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07 }; | |
| 20 | |
| 21 class AVCCConversionTest : public testing::TestWithParam<int> { | |
| 22 protected: | |
| 23 void MakeInputForLength(int length_size, std::vector<uint8>* buf) { | |
| 24 buf->clear(); | |
| 25 for (int i = 1; i < length_size; i++) | |
| 26 buf->push_back(0); | |
| 27 buf->push_back(sizeof(kNALU1)); | |
| 28 buf->insert(buf->end(), kNALU1, kNALU1 + sizeof(kNALU1)); | |
| 29 | |
| 30 for (int i = 1; i < length_size; i++) | |
| 31 buf->push_back(0); | |
| 32 buf->push_back(sizeof(kNALU2)); | |
| 33 buf->insert(buf->end(), kNALU2, kNALU2 + sizeof(kNALU2)); | |
| 34 } | |
| 35 }; | |
| 36 | |
| 37 TEST_P(AVCCConversionTest, ParseCorrectly) { | |
| 38 std::vector<uint8> buf; | |
| 39 MakeInputForLength(GetParam(), &buf); | |
| 40 EXPECT_TRUE(ConvertAVCCToAnnexB(GetParam(), &buf)); | |
| 41 ASSERT_EQ(buf.size(), sizeof(kExpected)); | |
| 42 ASSERT_EQ(0, memcmp(kExpected, &buf[0], sizeof(kExpected))); | |
| 43 } | |
| 44 | |
| 45 TEST_P(AVCCConversionTest, ParsePartial) { | |
| 46 std::vector<uint8> buf; | |
| 47 MakeInputForLength(GetParam(), &buf); | |
| 48 buf.pop_back(); | |
| 49 EXPECT_FALSE(ConvertAVCCToAnnexB(GetParam(), &buf)); | |
| 50 // This tests a buffer ending in the middle of a NAL length. For length size | |
| 51 // of one, this can't happen, so we skip that case. | |
| 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)); | |
| 68 | |
| 69 } // namespace mp4 | |
| 70 } // namespace media | |
| OLD | NEW |