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 "media/mp4/aac.h" 6 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 namespace media { 10 11 namespace mp4 { 12 13 TEST(AACTest, BasicProfileTest) { 14 AAC aac; 15 uint8 buffer[] = {0x12, 0x10}; 16 std::vector<uint8> data; 17 18 data.assign(buffer, buffer + sizeof(buffer)); 19 20 EXPECT_TRUE(aac.Parse(data)); 21 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 44100); 22 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); 23 } 24 25 TEST(AACTest, ExtensionTest) { 26 AAC aac; 27 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; 28 std::vector<uint8> data; 29 30 data.assign(buffer, buffer + sizeof(buffer)); 31 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); 36 } 37 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) { 43 AAC aac; 44 uint8 buffer[] = {0x13, 0x08}; 45 std::vector<uint8> data; 46 47 data.assign(buffer, buffer + sizeof(buffer)); 48 49 EXPECT_TRUE(aac.Parse(data)); 50 51 // Test w/o implict SBR. 52 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 24000); 53 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); 54 55 // Test implicit SBR. 56 EXPECT_EQ(aac.GetOutputSamplesPerSecond(true), 48000); 57 EXPECT_EQ(aac.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); 58 } 59 60 // Tests implicit SBR with a stereo channel config. 61 TEST(AACTest, ImplicitSBR_ChannelConfig1) { 62 AAC aac; 63 uint8 buffer[] = {0x13, 0x10}; 64 std::vector<uint8> data; 65 66 data.assign(buffer, buffer + sizeof(buffer)); 67 68 EXPECT_TRUE(aac.Parse(data)); 69 70 // Test w/o implict SBR. 71 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 24000); 72 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); 73 74 // Test implicit SBR. 75 EXPECT_EQ(aac.GetOutputSamplesPerSecond(true), 48000); 76 EXPECT_EQ(aac.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); 77 } 78 79 TEST(AACTest, SixChannelTest) { 80 AAC aac; 81 uint8 buffer[] = {0x11, 0xb0}; 82 std::vector<uint8> data; 83 84 data.assign(buffer, buffer + sizeof(buffer)); 85 86 EXPECT_TRUE(aac.Parse(data)); 87 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 48000); 88 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_5_1); 89 } 90 91 TEST(AACTest, DataTooShortTest) { 92 AAC aac; 93 std::vector<uint8> data; 94 95 EXPECT_FALSE(aac.Parse(data)); 96 97 data.push_back(0x12); 98 EXPECT_FALSE(aac.Parse(data)); 99 } 100 101 TEST(AACTest, IncorrectProfileTest) { 102 AAC aac; 103 uint8 buffer[] = {0x0, 0x08}; 104 std::vector<uint8> data; 105 106 data.assign(buffer, buffer + sizeof(buffer)); 107 108 EXPECT_FALSE(aac.Parse(data)); 109 110 data[0] = 0x08; 111 EXPECT_TRUE(aac.Parse(data)); 112 113 data[0] = 0x28; 114 EXPECT_FALSE(aac.Parse(data)); 115 } 116 117 TEST(AACTest, IncorrectFrequencyTest) { 118 AAC aac; 119 uint8 buffer[] = {0x0f, 0x88}; 120 std::vector<uint8> data; 121 122 data.assign(buffer, buffer + sizeof(buffer)); 123 124 EXPECT_FALSE(aac.Parse(data)); 125 126 data[0] = 0x0e; 127 data[1] = 0x08; 128 EXPECT_TRUE(aac.Parse(data)); 129 } 130 131 TEST(AACTest, IncorrectChannelTest) { 132 AAC aac; 133 uint8 buffer[] = {0x0e, 0x00}; 134 std::vector<uint8> data; 135 136 data.assign(buffer, buffer + sizeof(buffer)); 137 138 EXPECT_FALSE(aac.Parse(data)); 139 140 data[1] = 0x08; 141 EXPECT_TRUE(aac.Parse(data)); 142 } 143 144 } // namespace mp4 145 146 } // namespace media 147