| 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 "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 TestCallback test_func) { | 50 TestCallback test_func) { |
| 51 #define MAKE_TEST_VECTOR(name) \ | 51 #define MAKE_TEST_VECTOR(name) \ |
| 52 std::vector<bool> name##_states = \ | 52 std::vector<bool> name##_states = \ |
| 53 CreateTestVector(states_to_vary.name, test_states.name) | 53 CreateTestVector(states_to_vary.name, test_states.name) |
| 54 | 54 |
| 55 // Stuff states to test into vectors for easy for_each() iteration. | 55 // Stuff states to test into vectors for easy for_each() iteration. |
| 56 MAKE_TEST_VECTOR(has_platform_decoders); | 56 MAKE_TEST_VECTOR(has_platform_decoders); |
| 57 MAKE_TEST_VECTOR(has_platform_vp8_decoder); | 57 MAKE_TEST_VECTOR(has_platform_vp8_decoder); |
| 58 MAKE_TEST_VECTOR(has_platform_vp9_decoder); | 58 MAKE_TEST_VECTOR(has_platform_vp9_decoder); |
| 59 MAKE_TEST_VECTOR(supports_opus); | 59 MAKE_TEST_VECTOR(supports_opus); |
| 60 MAKE_TEST_VECTOR(is_unified_media_pipeline_enabled); | |
| 61 #undef MAKE_TEST_VECTOR | 60 #undef MAKE_TEST_VECTOR |
| 62 | 61 |
| 63 MimeUtil::PlatformInfo info; | 62 MimeUtil::PlatformInfo info; |
| 64 | 63 |
| 65 #define RUN_TEST_VECTOR(name) \ | 64 #define RUN_TEST_VECTOR(name) \ |
| 66 size_t name##_index = 0; \ | 65 size_t name##_index = 0; \ |
| 67 for (info.name = name##_states[name##_index]; \ | 66 for (info.name = name##_states[name##_index]; \ |
| 68 name##_index < name##_states.size(); ++name##_index) | 67 name##_index < name##_states.size(); ++name##_index) |
| 69 | 68 |
| 70 RUN_TEST_VECTOR(has_platform_decoders) { | 69 RUN_TEST_VECTOR(has_platform_decoders) { |
| 71 RUN_TEST_VECTOR(has_platform_vp8_decoder) { | 70 RUN_TEST_VECTOR(has_platform_vp8_decoder) { |
| 72 RUN_TEST_VECTOR(has_platform_vp9_decoder) { | 71 RUN_TEST_VECTOR(has_platform_vp9_decoder) { |
| 73 RUN_TEST_VECTOR(supports_opus) { | 72 RUN_TEST_VECTOR(supports_opus) { |
| 74 RUN_TEST_VECTOR(is_unified_media_pipeline_enabled) { | 73 for (int codec = MimeUtil::INVALID_CODEC; |
| 75 for (int codec = MimeUtil::INVALID_CODEC; | 74 codec <= MimeUtil::LAST_CODEC; ++codec) { |
| 76 codec <= MimeUtil::LAST_CODEC; ++codec) { | 75 SCOPED_TRACE(base::StringPrintf( |
| 77 SCOPED_TRACE(base::StringPrintf( | 76 "has_platform_decoders=%d, has_platform_vp8_decoder=%d, " |
| 78 "has_platform_decoders=%d, has_platform_vp8_decoder=%d, " | 77 "supports_opus=%d, " |
| 79 "supports_opus=%d, " | 78 "has_platform_vp9_decoder=%d, " |
| 80 "has_platform_vp9_decoder=%d, " | 79 "codec=%d", |
| 81 "is_unified_media_pipeline_enabled=%d, " | 80 info.has_platform_decoders, info.has_platform_vp8_decoder, |
| 82 "codec=%d", | 81 info.supports_opus, info.has_platform_vp9_decoder, codec)); |
| 83 info.has_platform_decoders, info.has_platform_vp8_decoder, | 82 test_func(info, static_cast<MimeUtil::Codec>(codec)); |
| 84 info.supports_opus, info.has_platform_vp9_decoder, | |
| 85 info.is_unified_media_pipeline_enabled, codec)); | |
| 86 test_func(info, static_cast<MimeUtil::Codec>(codec)); | |
| 87 } | |
| 88 } | 83 } |
| 89 } | 84 } |
| 90 } | 85 } |
| 91 } | 86 } |
| 92 } | 87 } |
| 93 #undef RUN_TEST_VECTOR | 88 #undef RUN_TEST_VECTOR |
| 94 } | 89 } |
| 95 | 90 |
| 96 // Helper method for generating the |states_to_vary| value used by | 91 // Helper method for generating the |states_to_vary| value used by |
| 97 // RunPlatformCodecTest(). Marks all fields to be varied. | 92 // RunPlatformCodecTest(). Marks all fields to be varied. |
| 98 static MimeUtil::PlatformInfo VaryAllFields() { | 93 static MimeUtil::PlatformInfo VaryAllFields() { |
| 99 MimeUtil::PlatformInfo states_to_vary; | 94 MimeUtil::PlatformInfo states_to_vary; |
| 100 states_to_vary.has_platform_vp8_decoder = true; | 95 states_to_vary.has_platform_vp8_decoder = true; |
| 101 states_to_vary.has_platform_vp9_decoder = true; | 96 states_to_vary.has_platform_vp9_decoder = true; |
| 102 states_to_vary.supports_opus = true; | 97 states_to_vary.supports_opus = true; |
| 103 states_to_vary.is_unified_media_pipeline_enabled = true; | |
| 104 states_to_vary.has_platform_decoders = true; | 98 states_to_vary.has_platform_decoders = true; |
| 105 return states_to_vary; | 99 return states_to_vary; |
| 106 } | 100 } |
| 107 | 101 |
| 108 static bool HasHevcSupport() { | 102 static bool HasHevcSupport() { |
| 109 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 103 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 110 #if defined(OS_ANDROID) | 104 #if defined(OS_ANDROID) |
| 111 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 105 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
| 112 #else | 106 #else |
| 113 return true; | 107 return true; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 EXPECT_EQ(info.has_platform_vp9_decoder, result); | 281 EXPECT_EQ(info.has_platform_vp9_decoder, result); |
| 288 break; | 282 break; |
| 289 | 283 |
| 290 case MimeUtil::HEVC: | 284 case MimeUtil::HEVC: |
| 291 EXPECT_EQ(HasHevcSupport(), result); | 285 EXPECT_EQ(HasHevcSupport(), result); |
| 292 break; | 286 break; |
| 293 } | 287 } |
| 294 }); | 288 }); |
| 295 } | 289 } |
| 296 | 290 |
| 297 TEST(IsCodecSupportedOnPlatformTest, ClearCodecBehaviorWithAndroidPipeline) { | 291 TEST(IsCodecSupportedOnPlatformTest, ClearCodecBehavior) { |
| 298 // Vary all parameters except |is_unified_media_pipeline_enabled|. | |
| 299 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | 292 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| 300 states_to_vary.is_unified_media_pipeline_enabled = false; | |
| 301 | 293 |
| 302 // Disable the unified pipeline. | |
| 303 MimeUtil::PlatformInfo test_states; | 294 MimeUtil::PlatformInfo test_states; |
| 304 test_states.is_unified_media_pipeline_enabled = false; | |
| 305 | 295 |
| 306 RunCodecSupportTest( | 296 RunCodecSupportTest( |
| 307 states_to_vary, test_states, | 297 states_to_vary, test_states, |
| 308 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | |
| 309 const bool result = MimeUtil::IsCodecSupportedOnPlatform( | |
| 310 codec, kTestMimeType, false, info); | |
| 311 switch (codec) { | |
| 312 // These codecs are never supported by the Android platform. | |
| 313 case MimeUtil::INVALID_CODEC: | |
| 314 case MimeUtil::AC3: | |
| 315 case MimeUtil::EAC3: | |
| 316 case MimeUtil::MPEG2_AAC: | |
| 317 case MimeUtil::THEORA: | |
| 318 EXPECT_FALSE(result); | |
| 319 break; | |
| 320 | |
| 321 // These codecs are always available via MediaPlayer. | |
| 322 case MimeUtil::FLAC: | |
| 323 case MimeUtil::PCM: | |
| 324 case MimeUtil::MP3: | |
| 325 case MimeUtil::MPEG4_AAC: | |
| 326 case MimeUtil::VORBIS: | |
| 327 case MimeUtil::H264: | |
| 328 case MimeUtil::VP8: | |
| 329 EXPECT_TRUE(result); | |
| 330 break; | |
| 331 | |
| 332 // The remaining codecs depend on the platform version. | |
| 333 case MimeUtil::OPUS: | |
| 334 EXPECT_EQ(info.supports_opus, result); | |
| 335 break; | |
| 336 | |
| 337 case MimeUtil::VP9: | |
| 338 // MediaPlayer only supports VP9 in WebM. | |
| 339 EXPECT_FALSE(result); | |
| 340 break; | |
| 341 | |
| 342 case MimeUtil::HEVC: | |
| 343 EXPECT_EQ(HasHevcSupport(), result); | |
| 344 break; | |
| 345 } | |
| 346 }); | |
| 347 | |
| 348 // Verify vp9 support in WebM. | |
| 349 RunCodecSupportTest( | |
| 350 states_to_vary, test_states, | |
| 351 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | |
| 352 const bool result = MimeUtil::IsCodecSupportedOnPlatform( | |
| 353 codec, "video/webm", true, info); | |
| 354 if (codec == MimeUtil::VP9) | |
| 355 EXPECT_EQ(info.has_platform_vp9_decoder, result); | |
| 356 }); | |
| 357 } | |
| 358 | |
| 359 TEST(IsCodecSupportedOnPlatformTest, ClearCodecBehaviorWithUnifiedPipeline) { | |
| 360 // Vary all parameters except |is_unified_media_pipeline_enabled|. | |
| 361 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | |
| 362 states_to_vary.is_unified_media_pipeline_enabled = false; | |
| 363 | |
| 364 // Enable the unified pipeline. | |
| 365 MimeUtil::PlatformInfo test_states; | |
| 366 test_states.is_unified_media_pipeline_enabled = true; | |
| 367 | |
| 368 RunCodecSupportTest( | |
| 369 states_to_vary, test_states, | |
| 370 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | 298 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { |
| 371 const bool result = MimeUtil::IsCodecSupportedOnPlatform( | 299 const bool result = MimeUtil::IsCodecSupportedOnPlatform( |
| 372 codec, kTestMimeType, false, info); | 300 codec, kTestMimeType, false, info); |
| 373 switch (codec) { | 301 switch (codec) { |
| 374 // These codecs are never supported by the Android platform. | 302 // These codecs are never supported by the Android platform. |
| 375 case MimeUtil::INVALID_CODEC: | 303 case MimeUtil::INVALID_CODEC: |
| 376 case MimeUtil::AC3: | 304 case MimeUtil::AC3: |
| 377 case MimeUtil::EAC3: | 305 case MimeUtil::EAC3: |
| 378 case MimeUtil::THEORA: | 306 case MimeUtil::THEORA: |
| 379 EXPECT_FALSE(result); | 307 EXPECT_FALSE(result); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 405 } | 333 } |
| 406 | 334 |
| 407 TEST(IsCodecSupportedOnPlatformTest, OpusOggSupport) { | 335 TEST(IsCodecSupportedOnPlatformTest, OpusOggSupport) { |
| 408 // Vary all parameters; thus use default initial state. | 336 // Vary all parameters; thus use default initial state. |
| 409 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | 337 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| 410 MimeUtil::PlatformInfo test_states; | 338 MimeUtil::PlatformInfo test_states; |
| 411 | 339 |
| 412 RunCodecSupportTest( | 340 RunCodecSupportTest( |
| 413 states_to_vary, test_states, | 341 states_to_vary, test_states, |
| 414 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | 342 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { |
| 415 EXPECT_EQ(info.is_unified_media_pipeline_enabled, | 343 EXPECT_TRUE(MimeUtil::IsCodecSupportedOnPlatform( |
| 416 MimeUtil::IsCodecSupportedOnPlatform( | 344 MimeUtil::OPUS, "audio/ogg", false, info)); |
| 417 MimeUtil::OPUS, "audio/ogg", false, info)); | |
| 418 }); | 345 }); |
| 419 } | 346 } |
| 420 | 347 |
| 421 TEST(IsCodecSupportedOnPlatformTest, HLSDoesNotSupportMPEG2AAC) { | 348 TEST(IsCodecSupportedOnPlatformTest, HLSDoesNotSupportMPEG2AAC) { |
| 422 // Vary all parameters; thus use default initial state. | 349 // Vary all parameters; thus use default initial state. |
| 423 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | 350 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| 424 MimeUtil::PlatformInfo test_states; | 351 MimeUtil::PlatformInfo test_states; |
| 425 | 352 |
| 426 RunCodecSupportTest( | 353 RunCodecSupportTest( |
| 427 states_to_vary, test_states, | 354 states_to_vary, test_states, |
| 428 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | 355 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { |
| 429 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( | 356 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( |
| 430 MimeUtil::MPEG2_AAC, "application/x-mpegurl", false, info)); | 357 MimeUtil::MPEG2_AAC, "application/x-mpegurl", false, info)); |
| 431 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( | 358 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( |
| 432 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info)); | 359 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info)); |
| 433 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( | 360 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( |
| 434 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); | 361 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); |
| 435 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( | 362 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( |
| 436 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); | 363 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); |
| 437 }); | 364 }); |
| 438 } | 365 } |
| 439 | 366 |
| 440 } // namespace internal | 367 } // namespace internal |
| 441 } // namespace media | 368 } // namespace media |
| OLD | NEW |