| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "media/base/mock_media_log.h" | 9 #include "media/base/mock_media_log.h" |
| 10 #include "media/formats/mp4/aac.h" | 10 #include "media/formats/mp4/aac.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using ::testing::AllOf; | 14 using ::testing::AllOf; |
| 15 using ::testing::HasSubstr; | 15 using ::testing::HasSubstr; |
| 16 using ::testing::InSequence; | 16 using ::testing::InSequence; |
| 17 using ::testing::StrictMock; | 17 using ::testing::StrictMock; |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 | 20 |
| 21 namespace mp4 { | 21 namespace mp4 { |
| 22 | 22 |
| 23 MATCHER_P(AudioProfileLog, profile_string, "") { | |
| 24 return CONTAINS_STRING(arg, | |
| 25 "Audio codec: " + std::string(profile_string) + "."); | |
| 26 } | |
| 27 | |
| 28 MATCHER_P(AudioSamplingFrequencyLog, frequency_string, "") { | |
| 29 return CONTAINS_STRING( | |
| 30 arg, "Sampling frequency: " + std::string(frequency_string) + "Hz."); | |
| 31 } | |
| 32 | |
| 33 MATCHER_P(AudioExtensionSamplingFrequencyLog, ex_string, "") { | |
| 34 return CONTAINS_STRING( | |
| 35 arg, "Sampling frequency(Extension): " + std::string(ex_string) + "Hz."); | |
| 36 } | |
| 37 | |
| 38 MATCHER_P(AudioChannelLayoutLog, layout_string, "") { | |
| 39 return CONTAINS_STRING( | |
| 40 arg, "Channel layout: " + std::string(layout_string) + "."); | |
| 41 } | |
| 42 | |
| 43 MATCHER_P(UnsupportedFrequencyIndexLog, frequency_index, "") { | 23 MATCHER_P(UnsupportedFrequencyIndexLog, frequency_index, "") { |
| 44 return CONTAINS_STRING( | 24 return CONTAINS_STRING( |
| 45 arg, | 25 arg, |
| 46 "Sampling Frequency Index(0x" + | 26 "Sampling Frequency Index(0x" + |
| 47 std::string(frequency_index) + ") is not supported."); | 27 std::string(frequency_index) + ") is not supported."); |
| 48 } | 28 } |
| 49 | 29 |
| 50 MATCHER_P(UnsupportedExtensionFrequencyIndexLog, frequency_index, "") { | 30 MATCHER_P(UnsupportedExtensionFrequencyIndexLog, frequency_index, "") { |
| 51 return CONTAINS_STRING( | 31 return CONTAINS_STRING( |
| 52 arg, | 32 arg, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 78 scoped_refptr<StrictMock<MockMediaLog>> media_log_; | 58 scoped_refptr<StrictMock<MockMediaLog>> media_log_; |
| 79 AAC aac_; | 59 AAC aac_; |
| 80 }; | 60 }; |
| 81 | 61 |
| 82 TEST_F(AACTest, BasicProfileTest) { | 62 TEST_F(AACTest, BasicProfileTest) { |
| 83 uint8_t buffer[] = {0x12, 0x10}; | 63 uint8_t buffer[] = {0x12, 0x10}; |
| 84 std::vector<uint8_t> data; | 64 std::vector<uint8_t> data; |
| 85 | 65 |
| 86 data.assign(buffer, buffer + sizeof(buffer)); | 66 data.assign(buffer, buffer + sizeof(buffer)); |
| 87 | 67 |
| 88 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 89 AudioSamplingFrequencyLog("44100"), | |
| 90 AudioExtensionSamplingFrequencyLog("0"), | |
| 91 AudioChannelLayoutLog("3"))); | |
| 92 EXPECT_TRUE(Parse(data)); | 68 EXPECT_TRUE(Parse(data)); |
| 93 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); | 69 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 44100); |
| 94 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 70 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 95 } | 71 } |
| 96 | 72 |
| 97 TEST_F(AACTest, ExtensionTest) { | 73 TEST_F(AACTest, ExtensionTest) { |
| 98 uint8_t buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; | 74 uint8_t buffer[] = {0x13, 0x08, 0x56, 0xe5, 0x9d, 0x48, 0x80}; |
| 99 std::vector<uint8_t> data; | 75 std::vector<uint8_t> data; |
| 100 | 76 |
| 101 data.assign(buffer, buffer + sizeof(buffer)); | 77 data.assign(buffer, buffer + sizeof(buffer)); |
| 102 | 78 |
| 103 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 104 AudioSamplingFrequencyLog("24000"), | |
| 105 AudioExtensionSamplingFrequencyLog("48000"), | |
| 106 AudioChannelLayoutLog("3"))); | |
| 107 EXPECT_TRUE(Parse(data)); | 79 EXPECT_TRUE(Parse(data)); |
| 108 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); | 80 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
| 109 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 81 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 110 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 82 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 111 } | 83 } |
| 112 | 84 |
| 113 // Test implicit SBR with mono channel config. | 85 // Test implicit SBR with mono channel config. |
| 114 // Mono channel layout should only be reported if SBR is not | 86 // Mono channel layout should only be reported if SBR is not |
| 115 // specified. Otherwise stereo should be reported. | 87 // specified. Otherwise stereo should be reported. |
| 116 // See ISO 14496-3:2005 Section 1.6.5.3 for details about this special casing. | 88 // See ISO 14496-3:2005 Section 1.6.5.3 for details about this special casing. |
| 117 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { | 89 TEST_F(AACTest, ImplicitSBR_ChannelConfig0) { |
| 118 uint8_t buffer[] = {0x13, 0x08}; | 90 uint8_t buffer[] = {0x13, 0x08}; |
| 119 std::vector<uint8_t> data; | 91 std::vector<uint8_t> data; |
| 120 | 92 |
| 121 data.assign(buffer, buffer + sizeof(buffer)); | 93 data.assign(buffer, buffer + sizeof(buffer)); |
| 122 | 94 |
| 123 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 124 AudioSamplingFrequencyLog("24000"), | |
| 125 AudioExtensionSamplingFrequencyLog("0"), | |
| 126 AudioChannelLayoutLog("2"))); | |
| 127 EXPECT_TRUE(Parse(data)); | 95 EXPECT_TRUE(Parse(data)); |
| 128 | 96 |
| 129 // Test w/o implict SBR. | 97 // Test w/o implict SBR. |
| 130 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); | 98 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
| 131 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); | 99 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_MONO); |
| 132 | 100 |
| 133 // Test implicit SBR. | 101 // Test implicit SBR. |
| 134 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 102 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 135 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 103 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
| 136 } | 104 } |
| 137 | 105 |
| 138 // Tests implicit SBR with a stereo channel config. | 106 // Tests implicit SBR with a stereo channel config. |
| 139 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { | 107 TEST_F(AACTest, ImplicitSBR_ChannelConfig1) { |
| 140 uint8_t buffer[] = {0x13, 0x10}; | 108 uint8_t buffer[] = {0x13, 0x10}; |
| 141 std::vector<uint8_t> data; | 109 std::vector<uint8_t> data; |
| 142 | 110 |
| 143 data.assign(buffer, buffer + sizeof(buffer)); | 111 data.assign(buffer, buffer + sizeof(buffer)); |
| 144 | 112 |
| 145 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 146 AudioSamplingFrequencyLog("24000"), | |
| 147 AudioExtensionSamplingFrequencyLog("0"), | |
| 148 AudioChannelLayoutLog("3"))); | |
| 149 EXPECT_TRUE(Parse(data)); | 113 EXPECT_TRUE(Parse(data)); |
| 150 | 114 |
| 151 // Test w/o implict SBR. | 115 // Test w/o implict SBR. |
| 152 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); | 116 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 24000); |
| 153 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); | 117 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_STEREO); |
| 154 | 118 |
| 155 // Test implicit SBR. | 119 // Test implicit SBR. |
| 156 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); | 120 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(true), 48000); |
| 157 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); | 121 EXPECT_EQ(aac_.GetChannelLayout(true), CHANNEL_LAYOUT_STEREO); |
| 158 } | 122 } |
| 159 | 123 |
| 160 TEST_F(AACTest, SixChannelTest) { | 124 TEST_F(AACTest, SixChannelTest) { |
| 161 uint8_t buffer[] = {0x11, 0xb0}; | 125 uint8_t buffer[] = {0x11, 0xb0}; |
| 162 std::vector<uint8_t> data; | 126 std::vector<uint8_t> data; |
| 163 | 127 |
| 164 data.assign(buffer, buffer + sizeof(buffer)); | 128 data.assign(buffer, buffer + sizeof(buffer)); |
| 165 | 129 |
| 166 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 167 AudioSamplingFrequencyLog("48000"), | |
| 168 AudioExtensionSamplingFrequencyLog("0"), | |
| 169 AudioChannelLayoutLog("12"))); | |
| 170 EXPECT_TRUE(Parse(data)); | 130 EXPECT_TRUE(Parse(data)); |
| 171 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); | 131 EXPECT_EQ(aac_.GetOutputSamplesPerSecond(false), 48000); |
| 172 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); | 132 EXPECT_EQ(aac_.GetChannelLayout(false), CHANNEL_LAYOUT_5_1_BACK); |
| 173 } | 133 } |
| 174 | 134 |
| 175 TEST_F(AACTest, DataTooShortTest) { | 135 TEST_F(AACTest, DataTooShortTest) { |
| 176 std::vector<uint8_t> data; | 136 std::vector<uint8_t> data; |
| 177 | 137 |
| 178 EXPECT_FALSE(Parse(data)); | 138 EXPECT_FALSE(Parse(data)); |
| 179 | 139 |
| 180 data.push_back(0x12); | 140 data.push_back(0x12); |
| 181 EXPECT_FALSE(Parse(data)); | 141 EXPECT_FALSE(Parse(data)); |
| 182 } | 142 } |
| 183 | 143 |
| 184 TEST_F(AACTest, IncorrectProfileTest) { | 144 TEST_F(AACTest, IncorrectProfileTest) { |
| 185 InSequence s; | 145 InSequence s; |
| 186 uint8_t buffer[] = {0x0, 0x08}; | 146 uint8_t buffer[] = {0x0, 0x08}; |
| 187 std::vector<uint8_t> data; | 147 std::vector<uint8_t> data; |
| 188 | 148 |
| 189 data.assign(buffer, buffer + sizeof(buffer)); | 149 data.assign(buffer, buffer + sizeof(buffer)); |
| 190 EXPECT_MEDIA_LOG(UnsupportedAudioProfileLog("mp4a.40.0")); | 150 EXPECT_MEDIA_LOG(UnsupportedAudioProfileLog("mp4a.40.0")); |
| 191 EXPECT_FALSE(Parse(data)); | 151 EXPECT_FALSE(Parse(data)); |
| 192 | 152 |
| 193 data[0] = 0x08; | 153 data[0] = 0x08; |
| 194 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.1"), | 154 |
| 195 AudioSamplingFrequencyLog("96000"), | |
| 196 AudioExtensionSamplingFrequencyLog("0"), | |
| 197 AudioChannelLayoutLog("2"))); | |
| 198 EXPECT_TRUE(Parse(data)); | 155 EXPECT_TRUE(Parse(data)); |
| 199 | 156 |
| 200 data[0] = 0x28; | 157 data[0] = 0x28; |
| 201 // No media log for this profile 5, since not enough bits are in |data| to | 158 // No media log for this profile 5, since not enough bits are in |data| to |
| 202 // first parse profile 5's extension frequency index. | 159 // first parse profile 5's extension frequency index. |
| 203 EXPECT_FALSE(Parse(data)); | 160 EXPECT_FALSE(Parse(data)); |
| 204 } | 161 } |
| 205 | 162 |
| 206 TEST_F(AACTest, IncorrectFrequencyTest) { | 163 TEST_F(AACTest, IncorrectFrequencyTest) { |
| 207 uint8_t buffer[] = {0x0f, 0x88}; | 164 uint8_t buffer[] = {0x0f, 0x88}; |
| 208 std::vector<uint8_t> data; | 165 std::vector<uint8_t> data; |
| 209 | 166 |
| 210 data.assign(buffer, buffer + sizeof(buffer)); | 167 data.assign(buffer, buffer + sizeof(buffer)); |
| 211 EXPECT_FALSE(Parse(data)); | 168 EXPECT_FALSE(Parse(data)); |
| 212 | 169 |
| 213 data[0] = 0x0e; | 170 data[0] = 0x0e; |
| 214 data[1] = 0x08; | 171 data[1] = 0x08; |
| 215 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.1"), | |
| 216 AudioSamplingFrequencyLog("7350"), | |
| 217 AudioExtensionSamplingFrequencyLog("0"), | |
| 218 AudioChannelLayoutLog("2"))); | |
| 219 EXPECT_TRUE(Parse(data)); | 172 EXPECT_TRUE(Parse(data)); |
| 220 } | 173 } |
| 221 | 174 |
| 222 TEST_F(AACTest, IncorrectChannelTest) { | 175 TEST_F(AACTest, IncorrectChannelTest) { |
| 223 uint8_t buffer[] = {0x0e, 0x00}; | 176 uint8_t buffer[] = {0x0e, 0x00}; |
| 224 std::vector<uint8_t> data; | 177 std::vector<uint8_t> data; |
| 225 | 178 |
| 226 data.assign(buffer, buffer + sizeof(buffer)); | 179 data.assign(buffer, buffer + sizeof(buffer)); |
| 227 EXPECT_FALSE(Parse(data)); | 180 EXPECT_FALSE(Parse(data)); |
| 228 | 181 |
| 229 data[1] = 0x08; | 182 data[1] = 0x08; |
| 230 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.1"), | |
| 231 AudioSamplingFrequencyLog("7350"), | |
| 232 AudioExtensionSamplingFrequencyLog("0"), | |
| 233 AudioChannelLayoutLog("2"))); | |
| 234 EXPECT_TRUE(Parse(data)); | 183 EXPECT_TRUE(Parse(data)); |
| 235 } | 184 } |
| 236 | 185 |
| 237 TEST_F(AACTest, UnsupportedProfileTest) { | 186 TEST_F(AACTest, UnsupportedProfileTest) { |
| 238 InSequence s; | 187 InSequence s; |
| 239 uint8_t buffer[] = {0x3a, 0x08}; | 188 uint8_t buffer[] = {0x3a, 0x08}; |
| 240 std::vector<uint8_t> data; | 189 std::vector<uint8_t> data; |
| 241 | 190 |
| 242 data.assign(buffer, buffer + sizeof(buffer)); | 191 data.assign(buffer, buffer + sizeof(buffer)); |
| 243 EXPECT_MEDIA_LOG(UnsupportedAudioProfileLog("mp4a.40.7")); | 192 EXPECT_MEDIA_LOG(UnsupportedAudioProfileLog("mp4a.40.7")); |
| 244 EXPECT_FALSE(Parse(data)); | 193 EXPECT_FALSE(Parse(data)); |
| 245 | 194 |
| 246 data[0] = 0x12; | 195 data[0] = 0x12; |
| 247 data[1] = 0x18; | 196 data[1] = 0x18; |
| 248 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 249 AudioSamplingFrequencyLog("44100"), | |
| 250 AudioExtensionSamplingFrequencyLog("0"), | |
| 251 AudioChannelLayoutLog("5"))); | |
| 252 EXPECT_TRUE(Parse(data)); | 197 EXPECT_TRUE(Parse(data)); |
| 253 } | 198 } |
| 254 | 199 |
| 255 TEST_F(AACTest, UnsupportedChannelLayoutTest) { | 200 TEST_F(AACTest, UnsupportedChannelLayoutTest) { |
| 256 InSequence s; | 201 InSequence s; |
| 257 uint8_t buffer[] = {0x12, 0x78}; | 202 uint8_t buffer[] = {0x12, 0x78}; |
| 258 std::vector<uint8_t> data; | 203 std::vector<uint8_t> data; |
| 259 | 204 |
| 260 data.assign(buffer, buffer + sizeof(buffer)); | 205 data.assign(buffer, buffer + sizeof(buffer)); |
| 261 EXPECT_MEDIA_LOG(UnsupportedChannelConfigLog("15")); | 206 EXPECT_MEDIA_LOG(UnsupportedChannelConfigLog("15")); |
| 262 EXPECT_FALSE(Parse(data)); | 207 EXPECT_FALSE(Parse(data)); |
| 263 | 208 |
| 264 data[1] = 0x18; | 209 data[1] = 0x18; |
| 265 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 266 AudioSamplingFrequencyLog("44100"), | |
| 267 AudioExtensionSamplingFrequencyLog("0"), | |
| 268 AudioChannelLayoutLog("5"))); | |
| 269 EXPECT_TRUE(Parse(data)); | 210 EXPECT_TRUE(Parse(data)); |
| 270 } | 211 } |
| 271 | 212 |
| 272 TEST_F(AACTest, UnsupportedFrequencyIndexTest) { | 213 TEST_F(AACTest, UnsupportedFrequencyIndexTest) { |
| 273 InSequence s; | 214 InSequence s; |
| 274 uint8_t buffer[] = {0x17, 0x10}; | 215 uint8_t buffer[] = {0x17, 0x10}; |
| 275 std::vector<uint8_t> data; | 216 std::vector<uint8_t> data; |
| 276 | 217 |
| 277 data.assign(buffer, buffer + sizeof(buffer)); | 218 data.assign(buffer, buffer + sizeof(buffer)); |
| 278 EXPECT_MEDIA_LOG(UnsupportedFrequencyIndexLog("e")); | 219 EXPECT_MEDIA_LOG(UnsupportedFrequencyIndexLog("e")); |
| 279 EXPECT_FALSE(Parse(data)); | 220 EXPECT_FALSE(Parse(data)); |
| 280 | 221 |
| 281 data[0] = 0x13; | 222 data[0] = 0x13; |
| 282 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 283 AudioSamplingFrequencyLog("24000"), | |
| 284 AudioExtensionSamplingFrequencyLog("0"), | |
| 285 AudioChannelLayoutLog("3"))); | |
| 286 EXPECT_TRUE(Parse(data)); | 223 EXPECT_TRUE(Parse(data)); |
| 287 } | 224 } |
| 288 | 225 |
| 289 TEST_F(AACTest, UnsupportedExFrequencyIndexTest) { | 226 TEST_F(AACTest, UnsupportedExFrequencyIndexTest) { |
| 290 InSequence s; | 227 InSequence s; |
| 291 uint8_t buffer[] = {0x29, 0x17, 0x08, 0x0}; | 228 uint8_t buffer[] = {0x29, 0x17, 0x08, 0x0}; |
| 292 std::vector<uint8_t> data; | 229 std::vector<uint8_t> data; |
| 293 | 230 |
| 294 data.assign(buffer, buffer + sizeof(buffer)); | 231 data.assign(buffer, buffer + sizeof(buffer)); |
| 295 EXPECT_MEDIA_LOG(UnsupportedExtensionFrequencyIndexLog("e")); | 232 EXPECT_MEDIA_LOG(UnsupportedExtensionFrequencyIndexLog("e")); |
| 296 EXPECT_FALSE(Parse(data)); | 233 EXPECT_FALSE(Parse(data)); |
| 297 | 234 |
| 298 data[1] = 0x11; | 235 data[1] = 0x11; |
| 299 EXPECT_MEDIA_LOG(AllOf(AudioProfileLog("mp4a.40.2"), | |
| 300 AudioSamplingFrequencyLog("64000"), | |
| 301 AudioExtensionSamplingFrequencyLog("64000"), | |
| 302 AudioChannelLayoutLog("3"))); | |
| 303 EXPECT_TRUE(Parse(data)); | 236 EXPECT_TRUE(Parse(data)); |
| 304 } | 237 } |
| 305 | 238 |
| 306 } // namespace mp4 | 239 } // namespace mp4 |
| 307 | 240 |
| 308 } // namespace media | 241 } // namespace media |
| OLD | NEW |