| Index: media/mp4/avc_unittest.cc
|
| diff --git a/media/mp4/avc_unittest.cc b/media/mp4/avc_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cdcc413037426de42535f03ef4bf67ce27d75b5d
|
| --- /dev/null
|
| +++ b/media/mp4/avc_unittest.cc
|
| @@ -0,0 +1,96 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <string.h>
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "media/base/stream_parser_buffer.h"
|
| +#include "media/mp4/avc.h"
|
| +#include "media/mp4/box_definitions.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "testing/gtest/include/gtest/gtest-param-test.h"
|
| +
|
| +namespace media {
|
| +namespace mp4 {
|
| +
|
| +static const uint8 kNALU1[] = { 0x01, 0x02, 0x03 };
|
| +static const uint8 kNALU2[] = { 0x04, 0x05, 0x06, 0x07 };
|
| +static const uint8 kExpected[] = {
|
| + 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03,
|
| + 0x00, 0x00, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07 };
|
| +
|
| +static const uint8 kExpectedParamSets[] = {
|
| + 0x00, 0x00, 0x00, 0x01, 0x67, 0x12,
|
| + 0x00, 0x00, 0x00, 0x01, 0x67, 0x34,
|
| + 0x00, 0x00, 0x00, 0x01, 0x68, 0x56, 0x78, 0x9a};
|
| +
|
| +class AVCConversionTest : public testing::TestWithParam<int> {
|
| + protected:
|
| + void MakeInputForLength(int length_size, std::vector<uint8>* buf) {
|
| + buf->clear();
|
| + for (int i = 1; i < length_size; i++)
|
| + buf->push_back(0);
|
| + buf->push_back(sizeof(kNALU1));
|
| + buf->insert(buf->end(), kNALU1, kNALU1 + sizeof(kNALU1));
|
| +
|
| + for (int i = 1; i < length_size; i++)
|
| + buf->push_back(0);
|
| + buf->push_back(sizeof(kNALU2));
|
| + buf->insert(buf->end(), kNALU2, kNALU2 + sizeof(kNALU2));
|
| + }
|
| +};
|
| +
|
| +TEST_P(AVCConversionTest, ParseCorrectly) {
|
| + std::vector<uint8> buf;
|
| + MakeInputForLength(GetParam(), &buf);
|
| + EXPECT_TRUE(AVC::ConvertToAnnexB(GetParam(), &buf));
|
| + EXPECT_EQ(buf.size(), sizeof(kExpected));
|
| + EXPECT_EQ(0, memcmp(kExpected, &buf[0], sizeof(kExpected)));
|
| +}
|
| +
|
| +TEST_P(AVCConversionTest, ParsePartial) {
|
| + std::vector<uint8> buf;
|
| + MakeInputForLength(GetParam(), &buf);
|
| + buf.pop_back();
|
| + EXPECT_FALSE(AVC::ConvertToAnnexB(GetParam(), &buf));
|
| + // This tests a buffer ending in the middle of a NAL length. For length size
|
| + // of one, this can't happen, so we skip that case.
|
| + if (GetParam() != 1) {
|
| + MakeInputForLength(GetParam(), &buf);
|
| + buf.erase(buf.end() - (sizeof(kNALU2) + 1), buf.end());
|
| + EXPECT_FALSE(AVC::ConvertToAnnexB(GetParam(), &buf));
|
| + }
|
| +}
|
| +
|
| +TEST_P(AVCConversionTest, ParseEmpty) {
|
| + std::vector<uint8> buf;
|
| + EXPECT_TRUE(AVC::ConvertToAnnexB(GetParam(), &buf));
|
| + EXPECT_EQ(0u, buf.size());
|
| +}
|
| +
|
| +INSTANTIATE_TEST_CASE_P(AVCConversionTestValues,
|
| + AVCConversionTest,
|
| + ::testing::Values(1, 2, 4));
|
| +
|
| +TEST(AVC, InsertParameterSetsTest) {
|
| + AVCDecoderConfigurationRecord avc_config;
|
| + avc_config.sps_list.resize(2);
|
| + avc_config.sps_list[0].push_back(0x67);
|
| + avc_config.sps_list[0].push_back(0x12);
|
| + avc_config.sps_list[1].push_back(0x67);
|
| + avc_config.sps_list[1].push_back(0x34);
|
| + avc_config.pps_list.resize(1);
|
| + avc_config.pps_list[0].push_back(0x68);
|
| + avc_config.pps_list[0].push_back(0x56);
|
| + avc_config.pps_list[0].push_back(0x78);
|
| +
|
| + std::vector<uint8> buf;
|
| + buf.push_back(0x9a);
|
| + EXPECT_TRUE(AVC::InsertParameterSets(avc_config, &buf));
|
| + EXPECT_EQ(0, memcmp(kExpectedParamSets, &buf[0],
|
| + sizeof(kExpectedParamSets)));
|
| +}
|
| +
|
| +} // namespace mp4
|
| +} // namespace media
|
|
|