Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: media/mp4/avc_unittest.cc

Issue 10536014: Implement ISO BMFF support in Media Source. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use vector in Annex B conversion instead of raw buffer Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "media/mp4/box_definitions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/gtest/include/gtest/gtest-param-test.h"
12
13 namespace media {
14 namespace mp4 {
15
16 static const uint8 kNALU1[] = { 0x01, 0x02, 0x03 };
17 static const uint8 kNALU2[] = { 0x04, 0x05, 0x06, 0x07 };
18 static const uint8 kExpected[] = {
19 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03,
20 0x00, 0x00, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07 };
21
22 static const uint8 kExpectedParamSets[] = {
23 0x00, 0x00, 0x00, 0x01, 0x67, 0x12,
24 0x00, 0x00, 0x00, 0x01, 0x67, 0x34,
25 0x00, 0x00, 0x00, 0x01, 0x68, 0x56, 0x78, 0x9a};
26
27 class AVCConversionTest : public testing::TestWithParam<int> {
28 protected:
29 void MakeInputForLength(int length_size, std::vector<uint8>* buf) {
30 buf->clear();
31 for (int i = 1; i < length_size; i++)
32 buf->push_back(0);
33 buf->push_back(sizeof(kNALU1));
34 buf->insert(buf->end(), kNALU1, kNALU1 + sizeof(kNALU1));
35
36 for (int i = 1; i < length_size; i++)
37 buf->push_back(0);
38 buf->push_back(sizeof(kNALU2));
39 buf->insert(buf->end(), kNALU2, kNALU2 + sizeof(kNALU2));
40 }
41 };
42
43 TEST_P(AVCConversionTest, ParseCorrectly) {
44 std::vector<uint8> buf;
45 MakeInputForLength(GetParam(), &buf);
46 EXPECT_TRUE(AVC::ConvertToAnnexB(GetParam(), &buf));
47 EXPECT_EQ(buf.size(), sizeof(kExpected));
48 EXPECT_EQ(0, memcmp(kExpected, &buf[0], sizeof(kExpected)));
49 }
50
51 TEST_P(AVCConversionTest, ParsePartial) {
52 std::vector<uint8> buf;
53 MakeInputForLength(GetParam(), &buf);
54 buf.pop_back();
55 EXPECT_FALSE(AVC::ConvertToAnnexB(GetParam(), &buf));
56 // This tests a buffer ending in the middle of a NAL length. For length size
57 // of one, this can't happen, so we skip that case.
58 if (GetParam() != 1) {
59 MakeInputForLength(GetParam(), &buf);
60 buf.erase(buf.end() - (sizeof(kNALU2) + 1), buf.end());
61 EXPECT_FALSE(AVC::ConvertToAnnexB(GetParam(), &buf));
62 }
63 }
64
65 TEST_P(AVCConversionTest, ParseEmpty) {
66 std::vector<uint8> buf;
67 EXPECT_TRUE(AVC::ConvertToAnnexB(GetParam(), &buf));
68 EXPECT_EQ(0u, buf.size());
69 }
70
71 INSTANTIATE_TEST_CASE_P(AVCConversionTestValues,
72 AVCConversionTest,
73 ::testing::Values(1, 2, 4));
74
75 TEST(AVC, InsertParameterSetsTest) {
76 AVCDecoderConfigurationRecord avc_config;
77 avc_config.sps_list.resize(2);
78 avc_config.sps_list[0].push_back(0x67);
79 avc_config.sps_list[0].push_back(0x12);
80 avc_config.sps_list[1].push_back(0x67);
81 avc_config.sps_list[1].push_back(0x34);
82 avc_config.pps_list.resize(1);
83 avc_config.pps_list[0].push_back(0x68);
84 avc_config.pps_list[0].push_back(0x56);
85 avc_config.pps_list[0].push_back(0x78);
86
87 std::vector<uint8> buf;
88 buf.push_back(0x9a);
89 EXPECT_TRUE(AVC::InsertParameterSets(avc_config, &buf));
90 EXPECT_EQ(0, memcmp(kExpectedParamSets, &buf[0],
91 sizeof(kExpectedParamSets)));
92 }
93
94 } // namespace mp4
95 } // namespace media
OLDNEW
« media/mp4/avc.cc ('K') | « media/mp4/avc.cc ('k') | media/mp4/box_definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698