| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/formats/mp4/aac.h" | 5 #include "media/formats/mp4/aac.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| 11 namespace mp4 { | 11 namespace mp4 { |
| 12 | 12 |
| 13 TEST(AACTest, BasicProfileTest) { | 13 class AACTest : public testing::Test { |
| 14 AAC aac; | 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) { |
| 15 uint8 buffer[] = {0x12, 0x10}; | 23 uint8 buffer[] = {0x12, 0x10}; |
| 16 std::vector<uint8> data; | 24 std::vector<uint8> data; |
| 17 | 25 |
| 18 data.assign(buffer, buffer + sizeof(buffer)); | 26 data.assign(buffer, buffer + sizeof(buffer)); |
| 19 | 27 |
| 20 EXPECT_TRUE(aac.Parse(data)); | 28 EXPECT_TRUE(Parse(data)); |
| 21 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 44100); | 29 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); |
| 22 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 30 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 23 } | 31 } |
| 24 | 32 |
| 25 TEST(AACTest, ExtensionTest) { | 33 TEST_F(AACTest, ExtensionTest) { |
| 26 AAC aac; | |
| 27 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; | 34 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; |
| 28 std::vector<uint8> data; | 35 std::vector<uint8> data; |
| 29 | 36 |
| 30 data.assign(buffer, buffer + sizeof(buffer)); | 37 data.assign(buffer, buffer + sizeof(buffer)); |
| 31 | 38 |
| 32 EXPECT_TRUE(aac.Parse(data)); | 39 EXPECT_TRUE(Parse(data)); |
| 33 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 48000); | 40 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
| 34 EXPECT_EQ(aac.GetOutputSamplesPerSecond(true), 48000); | 41 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 35 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 42 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 36 } | 43 } |
| 37 | 44 |
| 38 // Test implicit SBR with mono channel config. | 45 // Test implicit SBR with mono channel config. |
| 39 // Mono channel layout should only be reported if SBR is not | 46 // Mono channel layout should only be reported if SBR is not |
| 40 // specified. Otherwise stereo should be reported. | 47 // specified. Otherwise stereo should be reported. |
| 41 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing. | 48 // See ISO-14496-3 Section 1.6.6.1.2 for details about this special casing. |
| 42 TEST(AACTest, ImplicitSBR_ChannelConfig0) { | 49 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { |
| 43 AAC aac; | |
| 44 uint8 buffer[] = {0x13, 0x08}; | 50 uint8 buffer[] = {0x13, 0x08}; |
| 45 std::vector<uint8> data; | 51 std::vector<uint8> data; |
| 46 | 52 |
| 47 data.assign(buffer, buffer + sizeof(buffer)); | 53 data.assign(buffer, buffer + sizeof(buffer)); |
| 48 | 54 |
| 49 EXPECT_TRUE(aac.Parse(data)); | 55 EXPECT_TRUE(Parse(data)); |
| 50 | 56 |
| 51 // Test w/o implict SBR. | 57 // Test w/o implict SBR. |
| 52 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 24000); | 58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
| 53 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); | 59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); |
| 54 | 60 |
| 55 // Test implicit SBR. | 61 // Test implicit SBR. |
| 56 EXPECT_EQ(aac.GetOutputSamplesPerSecond(true), 48000); | 62 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 57 EXPECT_EQ(aac.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 63 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
| 58 } | 64 } |
| 59 | 65 |
| 60 // Tests implicit SBR with a stereo channel config. | 66 // Tests implicit SBR with a stereo channel config. |
| 61 TEST(AACTest, ImplicitSBR_ChannelConfig1) { | 67 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { |
| 62 AAC aac; | |
| 63 uint8 buffer[] = {0x13, 0x10}; | 68 uint8 buffer[] = {0x13, 0x10}; |
| 64 std::vector<uint8> data; | 69 std::vector<uint8> data; |
| 65 | 70 |
| 66 data.assign(buffer, buffer + sizeof(buffer)); | 71 data.assign(buffer, buffer + sizeof(buffer)); |
| 67 | 72 |
| 68 EXPECT_TRUE(aac.Parse(data)); | 73 EXPECT_TRUE(Parse(data)); |
| 69 | 74 |
| 70 // Test w/o implict SBR. | 75 // Test w/o implict SBR. |
| 71 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 24000); | 76 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
| 72 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 77 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 73 | 78 |
| 74 // Test implicit SBR. | 79 // Test implicit SBR. |
| 75 EXPECT_EQ(aac.GetOutputSamplesPerSecond(true), 48000); | 80 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 76 EXPECT_EQ(aac.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 81 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
| 77 } | 82 } |
| 78 | 83 |
| 79 TEST(AACTest, SixChannelTest) { | 84 TEST_F(AACTest, SixChannelTest) { |
| 80 AAC aac; | |
| 81 uint8 buffer[] = {0x11, 0xb0}; | 85 uint8 buffer[] = {0x11, 0xb0}; |
| 82 std::vector<uint8> data; | 86 std::vector<uint8> data; |
| 83 | 87 |
| 84 data.assign(buffer, buffer + sizeof(buffer)); | 88 data.assign(buffer, buffer + sizeof(buffer)); |
| 85 | 89 |
| 86 EXPECT_TRUE(aac.Parse(data)); | 90 EXPECT_TRUE(Parse(data)); |
| 87 EXPECT_EQ(aac.GetOutputSamplesPerSecond(false), 48000); | 91 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
| 88 EXPECT_EQ(aac.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); | 92 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); |
| 89 } | 93 } |
| 90 | 94 |
| 91 TEST(AACTest, DataTooShortTest) { | 95 TEST_F(AACTest, DataTooShortTest) { |
| 92 AAC aac; | |
| 93 std::vector<uint8> data; | 96 std::vector<uint8> data; |
| 94 | 97 |
| 95 EXPECT_FALSE(aac.Parse(data)); | 98 EXPECT_FALSE(Parse(data)); |
| 96 | 99 |
| 97 data.push_back(0x12); | 100 data.push_back(0x12); |
| 98 EXPECT_FALSE(aac.Parse(data)); | 101 EXPECT_FALSE(Parse(data)); |
| 99 } | 102 } |
| 100 | 103 |
| 101 TEST(AACTest, IncorrectProfileTest) { | 104 TEST_F(AACTest, IncorrectProfileTest) { |
| 102 AAC aac; | |
| 103 uint8 buffer[] = {0x0, 0x08}; | 105 uint8 buffer[] = {0x0, 0x08}; |
| 104 std::vector<uint8> data; | 106 std::vector<uint8> data; |
| 105 | 107 |
| 106 data.assign(buffer, buffer + sizeof(buffer)); | 108 data.assign(buffer, buffer + sizeof(buffer)); |
| 107 | 109 |
| 108 EXPECT_FALSE(aac.Parse(data)); | 110 EXPECT_FALSE(Parse(data)); |
| 109 | 111 |
| 110 data[0] = 0x08; | 112 data[0] = 0x08; |
| 111 EXPECT_TRUE(aac.Parse(data)); | 113 EXPECT_TRUE(Parse(data)); |
| 112 | 114 |
| 113 data[0] = 0x28; | 115 data[0] = 0x28; |
| 114 EXPECT_FALSE(aac.Parse(data)); | 116 EXPECT_FALSE(Parse(data)); |
| 115 } | 117 } |
| 116 | 118 |
| 117 TEST(AACTest, IncorrectFrequencyTest) { | 119 TEST_F(AACTest, IncorrectFrequencyTest) { |
| 118 AAC aac; | |
| 119 uint8 buffer[] = {0x0f, 0x88}; | 120 uint8 buffer[] = {0x0f, 0x88}; |
| 120 std::vector<uint8> data; | 121 std::vector<uint8> data; |
| 121 | 122 |
| 122 data.assign(buffer, buffer + sizeof(buffer)); | 123 data.assign(buffer, buffer + sizeof(buffer)); |
| 123 | 124 |
| 124 EXPECT_FALSE(aac.Parse(data)); | 125 EXPECT_FALSE(Parse(data)); |
| 125 | 126 |
| 126 data[0] = 0x0e; | 127 data[0] = 0x0e; |
| 127 data[1] = 0x08; | 128 data[1] = 0x08; |
| 128 EXPECT_TRUE(aac.Parse(data)); | 129 EXPECT_TRUE(Parse(data)); |
| 129 } | 130 } |
| 130 | 131 |
| 131 TEST(AACTest, IncorrectChannelTest) { | 132 TEST_F(AACTest, IncorrectChannelTest) { |
| 132 AAC aac; | |
| 133 uint8 buffer[] = {0x0e, 0x00}; | 133 uint8 buffer[] = {0x0e, 0x00}; |
| 134 std::vector<uint8> data; | 134 std::vector<uint8> data; |
| 135 | 135 |
| 136 data.assign(buffer, buffer + sizeof(buffer)); | 136 data.assign(buffer, buffer + sizeof(buffer)); |
| 137 | 137 |
| 138 EXPECT_FALSE(aac.Parse(data)); | 138 EXPECT_FALSE(Parse(data)); |
| 139 | 139 |
| 140 data[1] = 0x08; | 140 data[1] = 0x08; |
| 141 EXPECT_TRUE(aac.Parse(data)); | 141 EXPECT_TRUE(Parse(data)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace mp4 | 144 } // namespace mp4 |
| 145 | 145 |
| 146 } // namespace media | 146 } // namespace media |
| OLD | NEW |