Chromium Code Reviews| 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 "build/build_config.h" | 10 #include "build/build_config.h" |
| 10 #include "media/base/mime_util.h" | 11 #include "media/base/mime_util.h" |
| 12 #include "media/base/mime_util_internal.h" | |
| 11 #include "media/media_features.h" | 13 #include "media/media_features.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 16 #if defined(OS_ANDROID) | |
| 17 #include "base/android/build_info.h" | |
| 18 #endif | |
| 19 | |
| 14 namespace media { | 20 namespace media { |
| 21 namespace internal { | |
| 22 | |
| 23 const char kTestMimeType[] = "foo/foo"; | |
|
ddorwin
2016/02/19 19:53:23
Suggest:
// Type is ignored in nearly all cases.
DaleCurtis
2016/02/19 20:28:35
Done with some further elaboration.
| |
| 24 | |
| 25 // Helper method for creating a multi-value vector of |kTestStates| if | |
| 26 // |test_all_values| is true or if false, a single value vector containing | |
| 27 // |single_value|. | |
| 28 static std::vector<bool> CreateTestVector(bool test_all_values, | |
| 29 bool single_value) { | |
| 30 const bool kTestStates[] = {true, false}; | |
| 31 if (test_all_values) | |
| 32 return std::vector<bool>(kTestStates, kTestStates + arraysize(kTestStates)); | |
| 33 return std::vector<bool>(1, single_value); | |
| 34 } | |
| 35 | |
| 36 // Helper method for running IsCodecSupportedOnPlatform() tests that will | |
| 37 // iterate over all possible field values for a MimeUtil::PlatformInfo struct. | |
| 38 // | |
| 39 // To request a field be varied, set its value to true in the |states_to_vary| | |
| 40 // struct. If false, the only value tested will be the field value from | |
| 41 // |test_state|. | |
| 42 // | |
| 43 // |test_func| should have the signature <void(const MimeUtil::PlatformInfo&, | |
| 44 // MimeUtil::Codec)>. | |
| 45 template <typename TestCallback> | |
| 46 static void RunCodecSupportTest(const MimeUtil::PlatformInfo& test_state, | |
|
ddorwin
2016/02/19 19:53:23
state*s*
DaleCurtis
2016/02/19 20:28:35
Done.
| |
| 47 const MimeUtil::PlatformInfo& states_to_vary, | |
|
ddorwin
2016/02/19 19:53:23
It's strange and potentially error-prone that the
DaleCurtis
2016/02/19 20:28:35
Flipped.
| |
| 48 TestCallback test_func) { | |
| 49 #define MAKE_TEST_VECTOR(name) \ | |
| 50 std::vector<bool> name##_states = \ | |
| 51 CreateTestVector(states_to_vary.name, test_state.name) | |
| 52 | |
| 53 // Stuff states to test into vectors for easy for_each() iteration. | |
| 54 MAKE_TEST_VECTOR(has_platform_decoders); | |
| 55 MAKE_TEST_VECTOR(has_platform_vp8_decoder); | |
| 56 MAKE_TEST_VECTOR(supports_opus); | |
| 57 MAKE_TEST_VECTOR(supports_vp9); | |
| 58 MAKE_TEST_VECTOR(is_unified_media_pipeline_enabled); | |
| 59 #undef MAKE_TEST_VECTOR | |
| 60 | |
| 61 MimeUtil::PlatformInfo info; | |
| 62 for (bool has_platform_decoders : has_platform_decoders_states) { | |
| 63 info.has_platform_decoders = has_platform_decoders; | |
| 64 for (bool has_platform_vp8_decoder : has_platform_vp8_decoder_states) { | |
| 65 info.has_platform_vp8_decoder = has_platform_vp8_decoder; | |
| 66 for (bool supports_opus : supports_opus_states) { | |
| 67 info.supports_opus = supports_opus; | |
| 68 for (bool supports_vp9 : supports_vp9_states) { | |
| 69 info.supports_vp9 = supports_vp9; | |
| 70 for (bool is_unified_media_pipeline_enabled : | |
| 71 is_unified_media_pipeline_enabled_states) { | |
| 72 info.is_unified_media_pipeline_enabled = | |
| 73 is_unified_media_pipeline_enabled; | |
| 74 for (int codec = MimeUtil::INVALID_CODEC; | |
| 75 codec <= MimeUtil::LAST_CODEC; ++codec) { | |
| 76 SCOPED_TRACE(base::StringPrintf( | |
| 77 "has_platform_decoders=%d, has_platform_vp8_decoder=%d, " | |
| 78 "supports_opus=%d, " | |
| 79 "supports_vp9=%d, is_unified_media_pipeline_enabled=%d, " | |
| 80 "codec=%d", | |
| 81 info.has_platform_decoders, info.has_platform_vp8_decoder, | |
| 82 info.supports_opus, info.supports_vp9, | |
| 83 info.is_unified_media_pipeline_enabled, codec)); | |
| 84 test_func(info, static_cast<MimeUtil::Codec>(codec)); | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 } | |
| 89 } | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 // Helper method for generating the |states_to_vary| value used by | |
| 94 // RunPlatformCodecTest(). Marks all fields to be varied. | |
| 95 static MimeUtil::PlatformInfo VaryAllFields() { | |
| 96 MimeUtil::PlatformInfo states_to_vary; | |
| 97 states_to_vary.has_platform_vp8_decoder = true; | |
| 98 states_to_vary.supports_opus = true; | |
| 99 states_to_vary.supports_vp9 = true; | |
| 100 states_to_vary.is_unified_media_pipeline_enabled = true; | |
| 101 states_to_vary.has_platform_decoders = true; | |
| 102 return states_to_vary; | |
| 103 } | |
| 104 | |
| 105 static bool HasHevcSupport() { | |
| 106 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | |
| 107 #if defined(OS_ANDROID) | |
| 108 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | |
| 109 #else | |
| 110 return true; | |
| 111 #endif // defined(OS_ANDROID) | |
| 112 #else | |
| 113 return false; | |
| 114 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) | |
| 115 } | |
| 15 | 116 |
| 16 TEST(MimeUtilTest, CommonMediaMimeType) { | 117 TEST(MimeUtilTest, CommonMediaMimeType) { |
| 17 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm")); | 118 EXPECT_TRUE(IsSupportedMediaMimeType("audio/webm")); |
| 18 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm")); | 119 EXPECT_TRUE(IsSupportedMediaMimeType("video/webm")); |
| 19 | 120 |
| 20 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav")); | 121 EXPECT_TRUE(IsSupportedMediaMimeType("audio/wav")); |
| 21 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav")); | 122 EXPECT_TRUE(IsSupportedMediaMimeType("audio/x-wav")); |
| 22 | 123 |
| 23 EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg")); | 124 EXPECT_TRUE(IsSupportedMediaMimeType("audio/ogg")); |
| 24 EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg")); | 125 EXPECT_TRUE(IsSupportedMediaMimeType("application/ogg")); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 } | 205 } |
| 105 | 206 |
| 106 // Test without stripping the codec type. | 207 // Test without stripping the codec type. |
| 107 std::vector<std::string> codecs_out; | 208 std::vector<std::string> codecs_out; |
| 108 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); | 209 ParseCodecString("avc1.42E01E, mp4a.40.2", &codecs_out, false); |
| 109 ASSERT_EQ(2u, codecs_out.size()); | 210 ASSERT_EQ(2u, codecs_out.size()); |
| 110 EXPECT_EQ("avc1.42E01E", codecs_out[0]); | 211 EXPECT_EQ("avc1.42E01E", codecs_out[0]); |
| 111 EXPECT_EQ("mp4a.40.2", codecs_out[1]); | 212 EXPECT_EQ("mp4a.40.2", codecs_out[1]); |
| 112 } | 213 } |
| 113 | 214 |
| 215 TEST(IsCodecSupportedOnPlatformTest, | |
| 216 EncryptedCodecsFailWithoutPlatformSupport) { | |
| 217 // Vary all parameters except |has_platform_decoders|. | |
| 218 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | |
| 219 states_to_vary.has_platform_decoders = false; | |
| 220 | |
| 221 // Disable platform decoders. | |
| 222 MimeUtil::PlatformInfo test_state; | |
| 223 test_state.has_platform_decoders = false; | |
| 224 | |
| 225 // Every codec should fail since platform support is missing and we've | |
| 226 // requested encrypted codecs. | |
| 227 RunCodecSupportTest( | |
| 228 test_state, states_to_vary, | |
| 229 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | |
| 230 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, | |
| 231 true, info)); | |
| 232 }); | |
| 233 } | |
| 234 | |
| 235 TEST(IsCodecSupportedOnPlatformTest, EncryptedCodecBehavior) { | |
| 236 // Vary all parameters except |has_platform_decoders|. | |
| 237 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | |
| 238 states_to_vary.has_platform_decoders = false; | |
| 239 | |
| 240 // Enable platform decoders. | |
| 241 MimeUtil::PlatformInfo test_state; | |
| 242 test_state.has_platform_decoders = true; | |
| 243 | |
| 244 RunCodecSupportTest( | |
| 245 test_state, states_to_vary, | |
| 246 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | |
| 247 switch (codec) { | |
| 248 // These codecs are never supported by the Android platform. | |
| 249 case MimeUtil::INVALID_CODEC: | |
| 250 case MimeUtil::AC3: | |
| 251 case MimeUtil::EAC3: | |
| 252 case MimeUtil::MPEG2_AAC_LC: | |
| 253 case MimeUtil::MPEG2_AAC_MAIN: | |
| 254 case MimeUtil::MPEG2_AAC_SSR: | |
| 255 case MimeUtil::THEORA: | |
| 256 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( | |
|
ddorwin
2016/02/19 19:53:23
Every call is identical for each test. Should we i
DaleCurtis
2016/02/19 20:28:35
Good suggestion, done!
| |
| 257 codec, kTestMimeType, true, info)); | |
| 258 break; | |
| 259 | |
| 260 // These codecs are always available with platform decoder support. | |
| 261 case MimeUtil::PCM: | |
| 262 case MimeUtil::MP3: | |
| 263 case MimeUtil::MPEG4_AAC_LC: | |
| 264 case MimeUtil::MPEG4_AAC_SBR_v1: | |
| 265 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | |
| 266 case MimeUtil::VORBIS: | |
| 267 case MimeUtil::H264: | |
| 268 EXPECT_TRUE(MimeUtil::IsCodecSupportedOnPlatform( | |
| 269 codec, kTestMimeType, true, info)); | |
| 270 break; | |
| 271 | |
| 272 // The remaining codecs are not available on all platforms even when | |
| 273 // a platform decoder is available. | |
| 274 case MimeUtil::OPUS: | |
| 275 EXPECT_EQ(info.supports_opus, | |
| 276 MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, | |
| 277 true, info)); | |
| 278 break; | |
| 279 | |
| 280 case MimeUtil::VP8: | |
| 281 EXPECT_EQ(info.has_platform_vp8_decoder, | |
| 282 MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, | |
| 283 true, info)); | |
| 284 break; | |
| 285 | |
| 286 case MimeUtil::VP9: | |
| 287 EXPECT_EQ(info.supports_vp9, MimeUtil::IsCodecSupportedOnPlatform( | |
| 288 codec, kTestMimeType, true, info)); | |
| 289 break; | |
| 290 | |
| 291 case MimeUtil::HEVC_MAIN: | |
| 292 EXPECT_EQ(HasHevcSupport(), MimeUtil::IsCodecSupportedOnPlatform( | |
| 293 codec, kTestMimeType, true, info)); | |
| 294 break; | |
| 295 } | |
| 296 }); | |
| 297 } | |
| 298 | |
| 299 TEST(IsCodecSupportedOnPlatformTest, ClearCodecBehaviorWithAndroidPipeline) { | |
| 300 // Vary all parameters except |is_unified_media_pipeline_enabled|. | |
| 301 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | |
| 302 states_to_vary.is_unified_media_pipeline_enabled = false; | |
| 303 | |
| 304 // Disable the unified pipeline. | |
| 305 MimeUtil::PlatformInfo test_state; | |
| 306 test_state.is_unified_media_pipeline_enabled = false; | |
| 307 | |
| 308 RunCodecSupportTest( | |
| 309 test_state, states_to_vary, | |
| 310 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | |
| 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_LC: | |
| 317 case MimeUtil::MPEG2_AAC_MAIN: | |
| 318 case MimeUtil::MPEG2_AAC_SSR: | |
| 319 case MimeUtil::THEORA: | |
| 320 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( | |
| 321 codec, kTestMimeType, false, info)); | |
| 322 break; | |
| 323 | |
| 324 // These codecs are always available via MediaPlayer. | |
| 325 case MimeUtil::PCM: | |
| 326 case MimeUtil::MP3: | |
| 327 case MimeUtil::MPEG4_AAC_LC: | |
| 328 case MimeUtil::MPEG4_AAC_SBR_v1: | |
| 329 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | |
| 330 case MimeUtil::VORBIS: | |
| 331 case MimeUtil::H264: | |
| 332 case MimeUtil::VP8: | |
| 333 EXPECT_TRUE(MimeUtil::IsCodecSupportedOnPlatform( | |
| 334 codec, kTestMimeType, false, info)); | |
| 335 break; | |
| 336 | |
| 337 // The remaining codecs depend on the platform version. | |
| 338 case MimeUtil::OPUS: | |
| 339 EXPECT_EQ(info.supports_opus, | |
| 340 MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, | |
| 341 false, info)); | |
| 342 break; | |
| 343 | |
| 344 case MimeUtil::VP9: | |
| 345 EXPECT_EQ(info.supports_vp9, | |
| 346 MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, | |
| 347 false, info)); | |
| 348 break; | |
| 349 | |
| 350 case MimeUtil::HEVC_MAIN: | |
| 351 EXPECT_EQ(HasHevcSupport(), MimeUtil::IsCodecSupportedOnPlatform( | |
| 352 codec, kTestMimeType, false, info)); | |
| 353 break; | |
| 354 } | |
| 355 }); | |
| 356 } | |
| 357 | |
| 358 TEST(IsCodecSupportedOnPlatformTest, ClearCodecBehaviorWithUnifiedPipeline) { | |
| 359 // Vary all parameters except |is_unified_media_pipeline_enabled|. | |
| 360 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | |
| 361 states_to_vary.is_unified_media_pipeline_enabled = false; | |
| 362 | |
| 363 // Enable the unified pipeline. | |
| 364 MimeUtil::PlatformInfo test_state; | |
| 365 test_state.is_unified_media_pipeline_enabled = true; | |
| 366 | |
| 367 RunCodecSupportTest( | |
| 368 test_state, states_to_vary, | |
| 369 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | |
| 370 switch (codec) { | |
| 371 // These codecs are never supported by the Android platform. | |
| 372 case MimeUtil::INVALID_CODEC: | |
| 373 case MimeUtil::AC3: | |
| 374 case MimeUtil::EAC3: | |
| 375 case MimeUtil::THEORA: | |
| 376 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnPlatform( | |
| 377 codec, kTestMimeType, false, info)); | |
| 378 break; | |
| 379 | |
| 380 // These codecs are always supported with the unified pipeline. | |
| 381 case MimeUtil::PCM: | |
| 382 case MimeUtil::MPEG2_AAC_LC: | |
| 383 case MimeUtil::MPEG2_AAC_MAIN: | |
| 384 case MimeUtil::MPEG2_AAC_SSR: | |
| 385 case MimeUtil::MP3: | |
| 386 case MimeUtil::MPEG4_AAC_LC: | |
| 387 case MimeUtil::MPEG4_AAC_SBR_v1: | |
| 388 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | |
| 389 case MimeUtil::OPUS: | |
| 390 case MimeUtil::VORBIS: | |
| 391 case MimeUtil::VP8: | |
| 392 case MimeUtil::VP9: | |
| 393 EXPECT_TRUE(MimeUtil::IsCodecSupportedOnPlatform( | |
| 394 codec, kTestMimeType, false, info)); | |
| 395 break; | |
| 396 | |
| 397 // These codecs are only supported if platform decoders are supported. | |
| 398 case MimeUtil::H264: | |
| 399 EXPECT_EQ(info.has_platform_decoders, | |
| 400 MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, | |
| 401 false, info)); | |
| 402 break; | |
| 403 | |
| 404 case MimeUtil::HEVC_MAIN: | |
| 405 EXPECT_EQ(HasHevcSupport() && info.has_platform_decoders, | |
| 406 MimeUtil::IsCodecSupportedOnPlatform(codec, kTestMimeType, | |
| 407 false, info)); | |
| 408 break; | |
| 409 } | |
| 410 }); | |
| 411 } | |
| 412 | |
| 413 TEST(IsCodecSupportedOnPlatformTest, OpusOggSupport) { | |
| 414 // Vary all parameters; thus use default initial state. | |
| 415 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | |
| 416 MimeUtil::PlatformInfo test_state; | |
| 417 | |
| 418 RunCodecSupportTest( | |
| 419 test_state, states_to_vary, | |
| 420 [](const MimeUtil::PlatformInfo& info, MimeUtil::Codec codec) { | |
| 421 EXPECT_EQ(info.is_unified_media_pipeline_enabled, | |
| 422 MimeUtil::IsCodecSupportedOnPlatform( | |
| 423 MimeUtil::OPUS, "audio/ogg", false, info)); | |
| 424 }); | |
| 425 } | |
| 426 | |
| 427 } // namespace internal | |
| 114 } // namespace media | 428 } // namespace media |
| OLD | NEW |