cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / mp4 / avc_unittest.cc
blob766a9791967ecb7564b4da94257c7ae677897edd
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.
5 #include <string.h>
7 #include "base/basictypes.h"
8 #include "media/base/stream_parser_buffer.h"
9 #include "media/mp4/avc.h"
10 #include "media/mp4/box_definitions.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/gtest/include/gtest/gtest-param-test.h"
14 namespace media {
15 namespace mp4 {
17 static const uint8 kNALU1[] = { 0x01, 0x02, 0x03 };
18 static const uint8 kNALU2[] = { 0x04, 0x05, 0x06, 0x07 };
19 static const uint8 kExpected[] = {
20 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03,
21 0x00, 0x00, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07 };
23 static const uint8 kExpectedParamSets[] = {
24 0x00, 0x00, 0x00, 0x01, 0x67, 0x12,
25 0x00, 0x00, 0x00, 0x01, 0x67, 0x34,
26 0x00, 0x00, 0x00, 0x01, 0x68, 0x56, 0x78};
28 class AVCConversionTest : public testing::TestWithParam<int> {
29 protected:
30 void MakeInputForLength(int length_size, std::vector<uint8>* buf) {
31 buf->clear();
32 for (int i = 1; i < length_size; i++)
33 buf->push_back(0);
34 buf->push_back(sizeof(kNALU1));
35 buf->insert(buf->end(), kNALU1, kNALU1 + sizeof(kNALU1));
37 for (int i = 1; i < length_size; i++)
38 buf->push_back(0);
39 buf->push_back(sizeof(kNALU2));
40 buf->insert(buf->end(), kNALU2, kNALU2 + sizeof(kNALU2));
44 TEST_P(AVCConversionTest, ParseCorrectly) {
45 std::vector<uint8> buf;
46 MakeInputForLength(GetParam(), &buf);
47 EXPECT_TRUE(AVC::ConvertFrameToAnnexB(GetParam(), &buf));
48 EXPECT_EQ(buf.size(), sizeof(kExpected));
49 EXPECT_EQ(0, memcmp(kExpected, &buf[0], sizeof(kExpected)));
52 TEST_P(AVCConversionTest, ParsePartial) {
53 std::vector<uint8> buf;
54 MakeInputForLength(GetParam(), &buf);
55 buf.pop_back();
56 EXPECT_FALSE(AVC::ConvertFrameToAnnexB(GetParam(), &buf));
57 // This tests a buffer ending in the middle of a NAL length. For length size
58 // of one, this can't happen, so we skip that case.
59 if (GetParam() != 1) {
60 MakeInputForLength(GetParam(), &buf);
61 buf.erase(buf.end() - (sizeof(kNALU2) + 1), buf.end());
62 EXPECT_FALSE(AVC::ConvertFrameToAnnexB(GetParam(), &buf));
66 TEST_P(AVCConversionTest, ParseEmpty) {
67 std::vector<uint8> buf;
68 EXPECT_TRUE(AVC::ConvertFrameToAnnexB(GetParam(), &buf));
69 EXPECT_EQ(0u, buf.size());
72 INSTANTIATE_TEST_CASE_P(AVCConversionTestValues,
73 AVCConversionTest,
74 ::testing::Values(1, 2, 4));
76 TEST_F(AVCConversionTest, ConvertConfigToAnnexB) {
77 AVCDecoderConfigurationRecord avc_config;
78 avc_config.sps_list.resize(2);
79 avc_config.sps_list[0].push_back(0x67);
80 avc_config.sps_list[0].push_back(0x12);
81 avc_config.sps_list[1].push_back(0x67);
82 avc_config.sps_list[1].push_back(0x34);
83 avc_config.pps_list.resize(1);
84 avc_config.pps_list[0].push_back(0x68);
85 avc_config.pps_list[0].push_back(0x56);
86 avc_config.pps_list[0].push_back(0x78);
88 std::vector<uint8> buf;
89 EXPECT_TRUE(AVC::ConvertConfigToAnnexB(avc_config, &buf));
90 EXPECT_EQ(0, memcmp(kExpectedParamSets, &buf[0],
91 sizeof(kExpectedParamSets)));
94 } // namespace mp4
95 } // namespace media