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 |
| 29 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 30 const bool kUsePropCodecs = true; |
| 31 #else |
| 32 const bool kUsePropCodecs = false; |
| 33 #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 34 |
26 // MIME type for use with IsCodecSupportedOnAndroid() test; type is ignored in | 35 // MIME type for use with IsCodecSupportedOnAndroid() test; type is ignored in |
27 // all cases except for when paired with the Opus codec. | 36 // all cases except for when paired with the Opus codec. |
28 const char kTestMimeType[] = "foo/foo"; | 37 const char kTestMimeType[] = "foo/foo"; |
29 | 38 |
30 // Helper method for creating a multi-value vector of |kTestStates| if | 39 // Helper method for creating a multi-value vector of |kTestStates| if |
31 // |test_all_values| is true or if false, a single value vector containing | 40 // |test_all_values| is true or if false, a single value vector containing |
32 // |single_value|. | 41 // |single_value|. |
33 static std::vector<bool> CreateTestVector(bool test_all_values, | 42 static std::vector<bool> CreateTestVector(bool test_all_values, |
34 bool single_value) { | 43 bool single_value) { |
35 const bool kTestStates[] = {true, false}; | 44 const bool kTestStates[] = {true, false}; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 236 } |
228 | 237 |
229 // Test without stripping the codec type. | 238 // Test without stripping the codec type. |
230 std::vector<std::string> codecs_out; | 239 std::vector<std::string> codecs_out; |
231 SplitCodecsToVector("avc1.42E01E, mp4a.40.2", &codecs_out, false); | 240 SplitCodecsToVector("avc1.42E01E, mp4a.40.2", &codecs_out, false); |
232 ASSERT_EQ(2u, codecs_out.size()); | 241 ASSERT_EQ(2u, codecs_out.size()); |
233 EXPECT_EQ("avc1.42E01E", codecs_out[0]); | 242 EXPECT_EQ("avc1.42E01E", codecs_out[0]); |
234 EXPECT_EQ("mp4a.40.2", codecs_out[1]); | 243 EXPECT_EQ("mp4a.40.2", codecs_out[1]); |
235 } | 244 } |
236 | 245 |
| 246 // Basic smoke test for API. More exhaustive codec string testing found in |
| 247 // media_canplaytype_browsertest.cc. |
| 248 TEST(MimeUtilTest, ParseVideoCodecString) { |
| 249 bool out_is_ambiguous; |
| 250 VideoCodec out_codec; |
| 251 VideoCodecProfile out_profile; |
| 252 uint8_t out_level; |
| 253 VideoColorSpace out_colorspace; |
| 254 |
| 255 // Valid AVC string whenever proprietary codecs are supported. |
| 256 EXPECT_EQ(kUsePropCodecs, |
| 257 ParseVideoCodecString("video/mp4", "avc3.42E01E", &out_is_ambiguous, |
| 258 &out_codec, &out_profile, &out_level, |
| 259 &out_colorspace)); |
| 260 if (kUsePropCodecs) { |
| 261 EXPECT_FALSE(out_is_ambiguous); |
| 262 EXPECT_EQ(kCodecH264, out_codec); |
| 263 EXPECT_EQ(H264PROFILE_BASELINE, out_profile); |
| 264 EXPECT_EQ(30, out_level); |
| 265 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
| 266 } |
| 267 |
| 268 // Valid VP9 string. |
| 269 EnableNewVp9CodecStringSupport(); |
| 270 EXPECT_TRUE(ParseVideoCodecString("video/webm", "vp09.00.10.08", |
| 271 &out_is_ambiguous, &out_codec, &out_profile, |
| 272 &out_level, &out_colorspace)); |
| 273 EXPECT_FALSE(out_is_ambiguous); |
| 274 EXPECT_EQ(kCodecVP9, out_codec); |
| 275 EXPECT_EQ(VP9PROFILE_PROFILE0, out_profile); |
| 276 EXPECT_EQ(10, out_level); |
| 277 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
| 278 |
| 279 // Valid VP9 string with REC601 color space. |
| 280 EXPECT_TRUE(ParseVideoCodecString("video/webm", "vp09.02.10.10.01.06.06.06", |
| 281 &out_is_ambiguous, &out_codec, &out_profile, |
| 282 &out_level, &out_colorspace)); |
| 283 EXPECT_FALSE(out_is_ambiguous); |
| 284 EXPECT_EQ(kCodecVP9, out_codec); |
| 285 EXPECT_EQ(VP9PROFILE_PROFILE2, out_profile); |
| 286 EXPECT_EQ(10, out_level); |
| 287 EXPECT_EQ(VideoColorSpace::REC601(), out_colorspace); |
| 288 |
| 289 // Restore to avoid polluting other tests. |
| 290 DisableNewVp9CodecStringSupport_ForTesting(); |
| 291 |
| 292 // Ambiguous AVC string (when proprietary codecs are supported). |
| 293 EXPECT_EQ( |
| 294 kUsePropCodecs, |
| 295 ParseVideoCodecString("video/mp4", "avc3", &out_is_ambiguous, &out_codec, |
| 296 &out_profile, &out_level, &out_colorspace)); |
| 297 if (kUsePropCodecs) { |
| 298 EXPECT_TRUE(out_is_ambiguous); |
| 299 EXPECT_EQ(kCodecH264, out_codec); |
| 300 EXPECT_EQ(VIDEO_CODEC_PROFILE_UNKNOWN, out_profile); |
| 301 EXPECT_EQ(0, out_level); |
| 302 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); |
| 303 } |
| 304 |
| 305 // Audio codecs codec is not valid for video API. |
| 306 EXPECT_FALSE(ParseVideoCodecString("video/webm", "opus", &out_is_ambiguous, |
| 307 &out_codec, &out_profile, &out_level, |
| 308 &out_colorspace)); |
| 309 |
| 310 // Made up codec is invalid. |
| 311 EXPECT_FALSE(ParseVideoCodecString("video/webm", "bogus", &out_is_ambiguous, |
| 312 &out_codec, &out_profile, &out_level, |
| 313 &out_colorspace)); |
| 314 } |
| 315 |
| 316 TEST(MimeUtilTest, ParseAudioCodecString) { |
| 317 bool out_is_ambiguous; |
| 318 AudioCodec out_codec; |
| 319 |
| 320 // Valid Opus string. |
| 321 EXPECT_TRUE(ParseAudioCodecString("audio/webm", "opus", &out_is_ambiguous, |
| 322 &out_codec)); |
| 323 EXPECT_FALSE(out_is_ambiguous); |
| 324 EXPECT_EQ(kCodecOpus, out_codec); |
| 325 |
| 326 // Valid AAC string when proprietary codecs are supported. |
| 327 EXPECT_EQ(kUsePropCodecs, |
| 328 ParseAudioCodecString("audio/mp4", "mp4a.40.2", &out_is_ambiguous, |
| 329 &out_codec)); |
| 330 if (kUsePropCodecs) { |
| 331 EXPECT_FALSE(out_is_ambiguous); |
| 332 EXPECT_EQ(kCodecAAC, out_codec); |
| 333 } |
| 334 |
| 335 // Ambiguous AAC string. |
| 336 // TODO(chcunningha): This can probably be allowed. I think we treat all |
| 337 // MPEG4_AAC the same. |
| 338 EXPECT_EQ(kUsePropCodecs, |
| 339 ParseAudioCodecString("audio/mp4", "mp4a.40", &out_is_ambiguous, |
| 340 &out_codec)); |
| 341 if (kUsePropCodecs) { |
| 342 EXPECT_TRUE(out_is_ambiguous); |
| 343 EXPECT_EQ(kCodecAAC, out_codec); |
| 344 } |
| 345 |
| 346 // Valid empty codec string. Codec unambiguously implied by mime type. |
| 347 EXPECT_TRUE( |
| 348 ParseAudioCodecString("audio/flac", "", &out_is_ambiguous, &out_codec)); |
| 349 EXPECT_FALSE(out_is_ambiguous); |
| 350 EXPECT_EQ(kCodecFLAC, out_codec); |
| 351 |
| 352 // Valid audio codec should still be allowed with video mime type. |
| 353 EXPECT_TRUE(ParseAudioCodecString("video/webm", "opus", &out_is_ambiguous, |
| 354 &out_codec)); |
| 355 EXPECT_FALSE(out_is_ambiguous); |
| 356 EXPECT_EQ(kCodecOpus, out_codec); |
| 357 |
| 358 // Video codec is not valid for audio API. |
| 359 EXPECT_FALSE(ParseAudioCodecString("audio/webm", "vp09.00.10.08", |
| 360 &out_is_ambiguous, &out_codec)); |
| 361 |
| 362 // Made up codec is also not valid. |
| 363 EXPECT_FALSE(ParseAudioCodecString("audio/webm", "bogus", &out_is_ambiguous, |
| 364 &out_codec)); |
| 365 } |
| 366 |
237 // See deeper string parsing testing in video_codecs_unittests.cc. | 367 // See deeper string parsing testing in video_codecs_unittests.cc. |
238 TEST(MimeUtilTest, ExperimentalMultiPartVp9) { | 368 TEST(MimeUtilTest, ExperimentalMultiPartVp9) { |
239 base::test::ScopedCommandLine scoped_command_line; | |
240 | 369 |
241 // Multi-part VP9 string not enabled by default. | 370 // Multi-part VP9 string not enabled by default. |
242 EXPECT_FALSE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); | 371 EXPECT_FALSE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); |
243 | 372 |
244 // Should work if enabled. | 373 // Should work if enabled. |
245 EnableNewVp9CodecStringSupport(); | 374 EnableNewVp9CodecStringSupport(); |
246 EXPECT_TRUE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); | 375 EXPECT_TRUE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); |
| 376 // Restore to avoid polluting other tests. |
| 377 DisableNewVp9CodecStringSupport_ForTesting(); |
247 } | 378 } |
248 | 379 |
249 TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecsFailWithoutPlatformSupport) { | 380 TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecsFailWithoutPlatformSupport) { |
250 // Vary all parameters except |has_platform_decoders|. | 381 // Vary all parameters except |has_platform_decoders|. |
251 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | 382 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
252 states_to_vary.has_platform_decoders = false; | 383 states_to_vary.has_platform_decoders = false; |
253 | 384 |
254 // Disable platform decoders. | 385 // Disable platform decoders. |
255 MimeUtil::PlatformInfo test_states; | 386 MimeUtil::PlatformInfo test_states; |
256 test_states.has_platform_decoders = false; | 387 test_states.has_platform_decoders = false; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info)); | 533 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info)); |
403 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( | 534 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( |
404 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); | 535 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); |
405 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( | 536 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( |
406 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); | 537 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); |
407 }); | 538 }); |
408 } | 539 } |
409 | 540 |
410 } // namespace internal | 541 } // namespace internal |
411 } // namespace media | 542 } // namespace media |
OLD | NEW |