Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / formats / mp4 / aac_unittest.cc
blobdf1b596873161533a10705458c7b8d6066f7ddc9
1 // Copyright 2014 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 "media/formats/mp4/aac.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace media {
11 namespace mp4 {
13 class AACTest : public testing::Test {
14 public:
15 bool Parse(const std::vector<uint8>& data) {
16 return aac_.Parse(data, new MediaLog());
19 AAC aac_;
22 TEST_F(AACTest, BasicProfileTest) {
23 uint8 buffer[] = {0x12, 0x10};
24 std::vector<uint8> data;
26 data.assign(buffer, buffer + sizeof(buffer));
28 EXPECT_TRUE(Parse(data));
29 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100);
30 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
33 TEST_F(AACTest, ExtensionTest) {
34 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80};
35 std::vector<uint8> data;
37 data.assign(buffer, buffer + sizeof(buffer));
39 EXPECT_TRUE(Parse(data));
40 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000);
41 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
42 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
45 // Test implicit SBR with mono channel config.
46 // Mono channel layout should only be reported if SBR is not
47 // specified. Otherwise stereo should be reported.
48 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing.
49 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) {
50 uint8 buffer[] = {0x13, 0x08};
51 std::vector<uint8> data;
53 data.assign(buffer, buffer + sizeof(buffer));
55 EXPECT_TRUE(Parse(data));
57 // Test w/o implict SBR.
58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000);
59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO);
61 // Test implicit SBR.
62 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
63 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO);
66 // Tests implicit SBR with a stereo channel config.
67 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) {
68 uint8 buffer[] = {0x13, 0x10};
69 std::vector<uint8> data;
71 data.assign(buffer, buffer + sizeof(buffer));
73 EXPECT_TRUE(Parse(data));
75 // Test w/o implict SBR.
76 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000);
77 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO);
79 // Test implicit SBR.
80 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000);
81 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO);
84 TEST_F(AACTest, SixChannelTest) {
85 uint8 buffer[] = {0x11, 0xb0};
86 std::vector<uint8> data;
88 data.assign(buffer, buffer + sizeof(buffer));
90 EXPECT_TRUE(Parse(data));
91 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000);
92 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK);
95 TEST_F(AACTest, DataTooShortTest) {
96 std::vector<uint8> data;
98 EXPECT_FALSE(Parse(data));
100 data.push_back(0x12);
101 EXPECT_FALSE(Parse(data));
104 TEST_F(AACTest, IncorrectProfileTest) {
105 uint8 buffer[] = {0x0, 0x08};
106 std::vector<uint8> data;
108 data.assign(buffer, buffer + sizeof(buffer));
110 EXPECT_FALSE(Parse(data));
112 data[0] = 0x08;
113 EXPECT_TRUE(Parse(data));
115 data[0] = 0x28;
116 EXPECT_FALSE(Parse(data));
119 TEST_F(AACTest, IncorrectFrequencyTest) {
120 uint8 buffer[] = {0x0f, 0x88};
121 std::vector<uint8> data;
123 data.assign(buffer, buffer + sizeof(buffer));
125 EXPECT_FALSE(Parse(data));
127 data[0] = 0x0e;
128 data[1] = 0x08;
129 EXPECT_TRUE(Parse(data));
132 TEST_F(AACTest, IncorrectChannelTest) {
133 uint8 buffer[] = {0x0e, 0x00};
134 std::vector<uint8> data;
136 data.assign(buffer, buffer + sizeof(buffer));
138 EXPECT_FALSE(Parse(data));
140 data[1] = 0x08;
141 EXPECT_TRUE(Parse(data));
144 } // namespace mp4
146 } // namespace media