OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/test/scoped_command_line.h" | 10 #include "base/test/scoped_command_line.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "media/base/audio_codecs.h" |
12 #include "media/base/media.h" | 13 #include "media/base/media.h" |
13 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
14 #include "media/base/mime_util.h" | 15 #include "media/base/mime_util.h" |
15 #include "media/base/mime_util_internal.h" | 16 #include "media/base/mime_util_internal.h" |
| 17 #include "media/base/video_codecs.h" |
| 18 #include "media/base/video_color_space.h" |
16 #include "media/media_features.h" | 19 #include "media/media_features.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
18 | 21 |
19 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
20 #include "base/android/build_info.h" | 23 #include "base/android/build_info.h" |
21 #endif | 24 #endif |
22 | 25 |
23 namespace media { | 26 namespace media { |
24 namespace internal { | 27 namespace internal { |
25 | 28 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 222 } |
220 | 223 |
221 // Test without stripping the codec type. | 224 // Test without stripping the codec type. |
222 std::vector<std::string> codecs_out; | 225 std::vector<std::string> codecs_out; |
223 SplitCodecsToVector("avc1.42E01E, mp4a.40.2", &codecs_out, false); | 226 SplitCodecsToVector("avc1.42E01E, mp4a.40.2", &codecs_out, false); |
224 ASSERT_EQ(2u, codecs_out.size()); | 227 ASSERT_EQ(2u, codecs_out.size()); |
225 EXPECT_EQ("avc1.42E01E", codecs_out[0]); | 228 EXPECT_EQ("avc1.42E01E", codecs_out[0]); |
226 EXPECT_EQ("mp4a.40.2", codecs_out[1]); | 229 EXPECT_EQ("mp4a.40.2", codecs_out[1]); |
227 } | 230 } |
228 | 231 |
| 232 // Basic smoke test for API. More exhaustive codec string testing found in |
| 233 // media_canplaytype_browsertest.cc. |
| 234 TEST(MimeUtilTest, ParseVideoCodecString) { |
| 235 bool out_is_ambiguous; |
| 236 VideoCodec out_codec; |
| 237 VideoCodecProfile out_profile; |
| 238 uint8_t out_level; |
| 239 VideoColorSpace out_colorspace; |
| 240 |
| 241 // Valid AVC string. |
| 242 EXPECT_TRUE(ParseVideoCodecString("video/mp4", "avc3.42E01E", |
| 243 &out_is_ambiguous, &out_codec, &out_profile, |
| 244 &out_level, &out_colorspace)); |
| 245 EXPECT_FALSE(out_is_ambiguous); |
| 246 EXPECT_EQ(kCodecH264, out_codec); |
| 247 EXPECT_EQ(H264PROFILE_BASELINE, out_profile); |
| 248 EXPECT_EQ(30, out_level); |
| 249 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
| 250 |
| 251 // Valid VP9 string. |
| 252 EnableNewVp9CodecStringSupport(); |
| 253 EXPECT_TRUE(ParseVideoCodecString("video/webm", "vp09.00.10.08", |
| 254 &out_is_ambiguous, &out_codec, &out_profile, |
| 255 &out_level, &out_colorspace)); |
| 256 EXPECT_FALSE(out_is_ambiguous); |
| 257 EXPECT_EQ(kCodecVP9, out_codec); |
| 258 EXPECT_EQ(VP9PROFILE_PROFILE0, out_profile); |
| 259 EXPECT_EQ(10, out_level); |
| 260 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
| 261 |
| 262 // Ambiguous AVC string. |
| 263 EXPECT_TRUE(ParseVideoCodecString("video/mp4", "avc3", &out_is_ambiguous, |
| 264 &out_codec, &out_profile, &out_level, |
| 265 &out_colorspace)); |
| 266 EXPECT_TRUE(out_is_ambiguous); |
| 267 EXPECT_EQ(kCodecH264, out_codec); |
| 268 EXPECT_EQ(VIDEO_CODEC_PROFILE_UNKNOWN, out_profile); |
| 269 EXPECT_EQ(0, out_level); |
| 270 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
| 271 |
| 272 // Audio codecs codec is not valid for video API. |
| 273 EXPECT_FALSE(ParseVideoCodecString("video/mp4", "aac", &out_is_ambiguous, |
| 274 &out_codec, &out_profile, &out_level, |
| 275 &out_colorspace)); |
| 276 |
| 277 // Made up codec is invalid. |
| 278 EXPECT_FALSE(ParseVideoCodecString("video/mp4", "bogus", &out_is_ambiguous, |
| 279 &out_codec, &out_profile, &out_level, |
| 280 &out_colorspace)); |
| 281 } |
| 282 |
| 283 TEST(MimeUtilTest, ParseAudioCodecString) { |
| 284 bool out_is_ambiguous; |
| 285 AudioCodec out_codec; |
| 286 |
| 287 // Valid Opus string. |
| 288 EXPECT_TRUE(ParseAudioCodecString("audio/webm", "opus", &out_is_ambiguous, |
| 289 &out_codec)); |
| 290 EXPECT_FALSE(out_is_ambiguous); |
| 291 EXPECT_EQ(kCodecOpus, out_codec); |
| 292 |
| 293 // Valid AAC string. |
| 294 EXPECT_TRUE(ParseAudioCodecString("audio/mp4", "mp4a.40.2", &out_is_ambiguous, |
| 295 &out_codec)); |
| 296 EXPECT_FALSE(out_is_ambiguous); |
| 297 EXPECT_EQ(kCodecAAC, out_codec); |
| 298 |
| 299 // Ambiguous AAC string. |
| 300 // TODO(chcunningha): This can probably be allowed. I think We treat all |
| 301 // MPEG4_AAC the same. |
| 302 EXPECT_TRUE(ParseAudioCodecString("audio/mp4", "mp4a.40", &out_is_ambiguous, |
| 303 &out_codec)); |
| 304 EXPECT_TRUE(out_is_ambiguous); |
| 305 EXPECT_EQ(kCodecAAC, out_codec); |
| 306 |
| 307 // Valid empty codec string. Codec unambiguously implied by mime type. |
| 308 EXPECT_TRUE( |
| 309 ParseAudioCodecString("audio/flac", "", &out_is_ambiguous, &out_codec)); |
| 310 EXPECT_FALSE(out_is_ambiguous); |
| 311 EXPECT_EQ(kCodecFLAC, out_codec); |
| 312 |
| 313 // Valid audio codec should still be allowed with video mime type. |
| 314 EXPECT_TRUE(ParseAudioCodecString("video/webm", "opus", &out_is_ambiguous, |
| 315 &out_codec)); |
| 316 EXPECT_FALSE(out_is_ambiguous); |
| 317 EXPECT_EQ(kCodecOpus, out_codec); |
| 318 |
| 319 // Video codec is not valid for audio API. |
| 320 EXPECT_FALSE(ParseAudioCodecString("audio/webm", "vp9", &out_is_ambiguous, |
| 321 &out_codec)); |
| 322 |
| 323 // Made up codec is also not valid. |
| 324 EXPECT_FALSE(ParseAudioCodecString("audio/webm", "bogus", &out_is_ambiguous, |
| 325 &out_codec)); |
| 326 } |
| 327 |
229 // See deeper string parsing testing in video_codecs_unittests.cc. | 328 // See deeper string parsing testing in video_codecs_unittests.cc. |
230 TEST(MimeUtilTest, ExperimentalMultiPartVp9) { | 329 TEST(MimeUtilTest, ExperimentalMultiPartVp9) { |
231 base::test::ScopedCommandLine scoped_command_line; | 330 base::test::ScopedCommandLine scoped_command_line; |
232 | 331 |
233 // Multi-part VP9 string not enabled by default. | 332 // Multi-part VP9 string not enabled by default. |
234 EXPECT_FALSE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); | 333 EXPECT_FALSE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); |
235 | 334 |
236 // Should work if enabled. | 335 // Should work if enabled. |
237 EnableNewVp9CodecStringSupport(); | 336 EnableNewVp9CodecStringSupport(); |
238 EXPECT_TRUE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); | 337 EXPECT_TRUE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info)); | 487 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info)); |
389 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( | 488 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( |
390 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); | 489 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); |
391 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( | 490 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( |
392 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); | 491 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); |
393 }); | 492 }); |
394 } | 493 } |
395 | 494 |
396 } // namespace internal | 495 } // namespace internal |
397 } // namespace media | 496 } // namespace media |
OLD | NEW |