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