| 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 <string> | 5 #include "media/formats/mp4/aac.h" |
| 6 | 6 |
| 7 #include "media/base/mock_media_log.h" | |
| 8 #include "media/formats/mp4/aac.h" | |
| 9 #include "testing/gmock/include/gmock/gmock.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 8 |
| 12 using ::testing::InSequence; | |
| 13 using ::testing::StrictMock; | |
| 14 | |
| 15 namespace media { | 9 namespace media { |
| 16 | 10 |
| 17 namespace mp4 { | 11 namespace mp4 { |
| 18 | 12 |
| 19 MATCHER_P(AudioCodecLog, codec_string, "") { | |
| 20 return CONTAINS_STRING(arg, "Audio codec: " + std::string(codec_string)); | |
| 21 } | |
| 22 | |
| 23 class AACTest : public testing::Test { | 13 class AACTest : public testing::Test { |
| 24 public: | 14 public: |
| 25 AACTest() : media_log_(new StrictMock<MockMediaLog>()) {} | |
| 26 | |
| 27 bool Parse(const std::vector<uint8>& data) { | 15 bool Parse(const std::vector<uint8>& data) { |
| 28 return aac_.Parse(data, media_log_); | 16 return aac_.Parse(data, new MediaLog()); |
| 29 } | 17 } |
| 30 | 18 |
| 31 scoped_refptr<StrictMock<MockMediaLog>> media_log_; | |
| 32 AAC aac_; | 19 AAC aac_; |
| 33 }; | 20 }; |
| 34 | 21 |
| 35 TEST_F(AACTest, BasicProfileTest) { | 22 TEST_F(AACTest, BasicProfileTest) { |
| 36 uint8 buffer[] = {0x12, 0x10}; | 23 uint8 buffer[] = {0x12, 0x10}; |
| 37 std::vector<uint8> data; | 24 std::vector<uint8> data; |
| 38 | 25 |
| 39 data.assign(buffer, buffer + sizeof(buffer)); | 26 data.assign(buffer, buffer + sizeof(buffer)); |
| 40 | 27 |
| 41 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | |
| 42 | |
| 43 EXPECT_TRUE(Parse(data)); | 28 EXPECT_TRUE(Parse(data)); |
| 44 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); | 29 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); |
| 45 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 30 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 46 } | 31 } |
| 47 | 32 |
| 48 TEST_F(AACTest, ExtensionTest) { | 33 TEST_F(AACTest, ExtensionTest) { |
| 49 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; | 34 uint8 buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; |
| 50 std::vector<uint8> data; | 35 std::vector<uint8> data; |
| 51 | 36 |
| 52 data.assign(buffer, buffer + sizeof(buffer)); | 37 data.assign(buffer, buffer + sizeof(buffer)); |
| 53 | 38 |
| 54 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | |
| 55 | |
| 56 EXPECT_TRUE(Parse(data)); | 39 EXPECT_TRUE(Parse(data)); |
| 57 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); | 40 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
| 58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 41 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 42 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 60 } | 43 } |
| 61 | 44 |
| 62 // Test implicit SBR with mono channel config. | 45 // Test implicit SBR with mono channel config. |
| 63 // Mono channel layout should only be reported if SBR is not | 46 // Mono channel layout should only be reported if SBR is not |
| 64 // specified. Otherwise stereo should be reported. | 47 // specified. Otherwise stereo should be reported. |
| 65 // 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. |
| 66 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { | 49 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { |
| 67 uint8 buffer[] = {0x13, 0x08}; | 50 uint8 buffer[] = {0x13, 0x08}; |
| 68 std::vector<uint8> data; | 51 std::vector<uint8> data; |
| 69 | 52 |
| 70 data.assign(buffer, buffer + sizeof(buffer)); | 53 data.assign(buffer, buffer + sizeof(buffer)); |
| 71 | 54 |
| 72 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | |
| 73 | |
| 74 EXPECT_TRUE(Parse(data)); | 55 EXPECT_TRUE(Parse(data)); |
| 75 | 56 |
| 76 // Test w/o implict SBR. | 57 // Test w/o implict SBR. |
| 77 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); | 58 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
| 78 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); | 59 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); |
| 79 | 60 |
| 80 // Test implicit SBR. | 61 // Test implicit SBR. |
| 81 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 62 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 82 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 63 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
| 83 } | 64 } |
| 84 | 65 |
| 85 // Tests implicit SBR with a stereo channel config. | 66 // Tests implicit SBR with a stereo channel config. |
| 86 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { | 67 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { |
| 87 uint8 buffer[] = {0x13, 0x10}; | 68 uint8 buffer[] = {0x13, 0x10}; |
| 88 std::vector<uint8> data; | 69 std::vector<uint8> data; |
| 89 | 70 |
| 90 data.assign(buffer, buffer + sizeof(buffer)); | 71 data.assign(buffer, buffer + sizeof(buffer)); |
| 91 | 72 |
| 92 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | |
| 93 | |
| 94 EXPECT_TRUE(Parse(data)); | 73 EXPECT_TRUE(Parse(data)); |
| 95 | 74 |
| 96 // Test w/o implict SBR. | 75 // Test w/o implict SBR. |
| 97 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); | 76 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
| 98 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 77 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 99 | 78 |
| 100 // Test implicit SBR. | 79 // Test implicit SBR. |
| 101 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 80 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 102 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 81 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
| 103 } | 82 } |
| 104 | 83 |
| 105 TEST_F(AACTest, SixChannelTest) { | 84 TEST_F(AACTest, SixChannelTest) { |
| 106 uint8 buffer[] = {0x11, 0xb0}; | 85 uint8 buffer[] = {0x11, 0xb0}; |
| 107 std::vector<uint8> data; | 86 std::vector<uint8> data; |
| 108 | 87 |
| 109 data.assign(buffer, buffer + sizeof(buffer)); | 88 data.assign(buffer, buffer + sizeof(buffer)); |
| 110 | 89 |
| 111 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.2")); | |
| 112 | |
| 113 EXPECT_TRUE(Parse(data)); | 90 EXPECT_TRUE(Parse(data)); |
| 114 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); | 91 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
| 115 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); | 92 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); |
| 116 } | 93 } |
| 117 | 94 |
| 118 TEST_F(AACTest, DataTooShortTest) { | 95 TEST_F(AACTest, DataTooShortTest) { |
| 119 std::vector<uint8> data; | 96 std::vector<uint8> data; |
| 120 | 97 |
| 121 EXPECT_FALSE(Parse(data)); | 98 EXPECT_FALSE(Parse(data)); |
| 122 | 99 |
| 123 data.push_back(0x12); | 100 data.push_back(0x12); |
| 124 EXPECT_FALSE(Parse(data)); | 101 EXPECT_FALSE(Parse(data)); |
| 125 } | 102 } |
| 126 | 103 |
| 127 TEST_F(AACTest, IncorrectProfileTest) { | 104 TEST_F(AACTest, IncorrectProfileTest) { |
| 128 InSequence s; | |
| 129 uint8 buffer[] = {0x0, 0x08}; | 105 uint8 buffer[] = {0x0, 0x08}; |
| 130 std::vector<uint8> data; | 106 std::vector<uint8> data; |
| 131 | 107 |
| 132 data.assign(buffer, buffer + sizeof(buffer)); | 108 data.assign(buffer, buffer + sizeof(buffer)); |
| 133 | 109 |
| 134 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.0")); | |
| 135 EXPECT_FALSE(Parse(data)); | 110 EXPECT_FALSE(Parse(data)); |
| 136 | 111 |
| 137 data[0] = 0x08; | 112 data[0] = 0x08; |
| 138 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1")); | |
| 139 EXPECT_TRUE(Parse(data)); | 113 EXPECT_TRUE(Parse(data)); |
| 140 | 114 |
| 141 data[0] = 0x28; | 115 data[0] = 0x28; |
| 142 // No media log for this profile 5, since not enough bits are in |data| to | |
| 143 // first parse profile 5's extension frequency index. | |
| 144 EXPECT_FALSE(Parse(data)); | 116 EXPECT_FALSE(Parse(data)); |
| 145 } | 117 } |
| 146 | 118 |
| 147 TEST_F(AACTest, IncorrectFrequencyTest) { | 119 TEST_F(AACTest, IncorrectFrequencyTest) { |
| 148 uint8 buffer[] = {0x0f, 0x88}; | 120 uint8 buffer[] = {0x0f, 0x88}; |
| 149 std::vector<uint8> data; | 121 std::vector<uint8> data; |
| 150 | 122 |
| 151 data.assign(buffer, buffer + sizeof(buffer)); | 123 data.assign(buffer, buffer + sizeof(buffer)); |
| 152 | 124 |
| 153 EXPECT_FALSE(Parse(data)); | 125 EXPECT_FALSE(Parse(data)); |
| 154 | 126 |
| 155 data[0] = 0x0e; | 127 data[0] = 0x0e; |
| 156 data[1] = 0x08; | 128 data[1] = 0x08; |
| 157 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1")); | |
| 158 EXPECT_TRUE(Parse(data)); | 129 EXPECT_TRUE(Parse(data)); |
| 159 } | 130 } |
| 160 | 131 |
| 161 TEST_F(AACTest, IncorrectChannelTest) { | 132 TEST_F(AACTest, IncorrectChannelTest) { |
| 162 uint8 buffer[] = {0x0e, 0x00}; | 133 uint8 buffer[] = {0x0e, 0x00}; |
| 163 std::vector<uint8> data; | 134 std::vector<uint8> data; |
| 164 | 135 |
| 165 data.assign(buffer, buffer + sizeof(buffer)); | 136 data.assign(buffer, buffer + sizeof(buffer)); |
| 166 | 137 |
| 167 EXPECT_MEDIA_LOG(AudioCodecLog("mp4a.40.1")).Times(2); | |
| 168 | |
| 169 EXPECT_FALSE(Parse(data)); | 138 EXPECT_FALSE(Parse(data)); |
| 170 | 139 |
| 171 data[1] = 0x08; | 140 data[1] = 0x08; |
| 172 EXPECT_TRUE(Parse(data)); | 141 EXPECT_TRUE(Parse(data)); |
| 173 } | 142 } |
| 174 | 143 |
| 175 } // namespace mp4 | 144 } // namespace mp4 |
| 176 | 145 |
| 177 } // namespace media | 146 } // namespace media |
| OLD | NEW |