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 "media/mp4/aac.h"
7 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(AACTest
, BasicProfileTest
) {
15 uint8 buffer
[] = {0x12, 0x10};
16 std::vector
<uint8
> data
;
18 data
.assign(buffer
, buffer
+ sizeof(buffer
));
20 EXPECT_TRUE(aac
.Parse(data
));
21 EXPECT_EQ(aac
.GetOutputSamplesPerSecond(false), 44100);
22 EXPECT_EQ(aac
.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO
);
25 TEST(AACTest
, ExtensionTest
) {
27 uint8 buffer
[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80};
28 std::vector
<uint8
> data
;
30 data
.assign(buffer
, buffer
+ sizeof(buffer
));
32 EXPECT_TRUE(aac
.Parse(data
));
33 EXPECT_EQ(aac
.GetOutputSamplesPerSecond(false), 48000);
34 EXPECT_EQ(aac
.GetOutputSamplesPerSecond(true), 48000);
35 EXPECT_EQ(aac
.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO
);
38 // Test implicit SBR with mono channel config.
39 // Mono channel layout should only be reported if SBR is not
40 // specified. Otherwise stereo should be reported.
41 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing.
42 TEST(AACTest
, ImplicitSBR_ChannelConfig0
) {
44 uint8 buffer
[] = {0x13, 0x08};
45 std::vector
<uint8
> data
;
47 data
.assign(buffer
, buffer
+ sizeof(buffer
));
49 EXPECT_TRUE(aac
.Parse(data
));
51 // Test w/o implict SBR.
52 EXPECT_EQ(aac
.GetOutputSamplesPerSecond(false), 24000);
53 EXPECT_EQ(aac
.GetChannelLayout(false), CHANNEL_LAYOUT_MONO
);
56 EXPECT_EQ(aac
.GetOutputSamplesPerSecond(true), 48000);
57 EXPECT_EQ(aac
.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO
);
60 // Tests implicit SBR with a stereo channel config.
61 TEST(AACTest
, ImplicitSBR_ChannelConfig1
) {
63 uint8 buffer
[] = {0x13, 0x10};
64 std::vector
<uint8
> data
;
66 data
.assign(buffer
, buffer
+ sizeof(buffer
));
68 EXPECT_TRUE(aac
.Parse(data
));
70 // Test w/o implict SBR.
71 EXPECT_EQ(aac
.GetOutputSamplesPerSecond(false), 24000);
72 EXPECT_EQ(aac
.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO
);
75 EXPECT_EQ(aac
.GetOutputSamplesPerSecond(true), 48000);
76 EXPECT_EQ(aac
.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO
);
79 TEST(AACTest
, SixChannelTest
) {
81 uint8 buffer
[] = {0x11, 0xb0};
82 std::vector
<uint8
> data
;
84 data
.assign(buffer
, buffer
+ sizeof(buffer
));
86 EXPECT_TRUE(aac
.Parse(data
));
87 EXPECT_EQ(aac
.GetOutputSamplesPerSecond(false), 48000);
88 EXPECT_EQ(aac
.GetChannelLayout(false), CHANNEL_LAYOUT_5_1
);
91 TEST(AACTest
, DataTooShortTest
) {
93 std::vector
<uint8
> data
;
95 EXPECT_FALSE(aac
.Parse(data
));
98 EXPECT_FALSE(aac
.Parse(data
));
101 TEST(AACTest
, IncorrectProfileTest
) {
103 uint8 buffer
[] = {0x0, 0x08};
104 std::vector
<uint8
> data
;
106 data
.assign(buffer
, buffer
+ sizeof(buffer
));
108 EXPECT_FALSE(aac
.Parse(data
));
111 EXPECT_TRUE(aac
.Parse(data
));
114 EXPECT_FALSE(aac
.Parse(data
));
117 TEST(AACTest
, IncorrectFrequencyTest
) {
119 uint8 buffer
[] = {0x0f, 0x88};
120 std::vector
<uint8
> data
;
122 data
.assign(buffer
, buffer
+ sizeof(buffer
));
124 EXPECT_FALSE(aac
.Parse(data
));
128 EXPECT_TRUE(aac
.Parse(data
));
131 TEST(AACTest
, IncorrectChannelTest
) {
133 uint8 buffer
[] = {0x0e, 0x00};
134 std::vector
<uint8
> data
;
136 data
.assign(buffer
, buffer
+ sizeof(buffer
));
138 EXPECT_FALSE(aac
.Parse(data
));
141 EXPECT_TRUE(aac
.Parse(data
));