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