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 "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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 } | 230 } |
| 228 | 231 |
| 229 // Test without stripping the codec type. | 232 // Test without stripping the codec type. |
| 230 std::vector<std::string> codecs_out; | 233 std::vector<std::string> codecs_out; |
| 231 SplitCodecsToVector("avc1.42E01E, mp4a.40.2", &codecs_out, false); | 234 SplitCodecsToVector("avc1.42E01E, mp4a.40.2", &codecs_out, false); |
| 232 ASSERT_EQ(2u, codecs_out.size()); | 235 ASSERT_EQ(2u, codecs_out.size()); |
| 233 EXPECT_EQ("avc1.42E01E", codecs_out[0]); | 236 EXPECT_EQ("avc1.42E01E", codecs_out[0]); |
| 234 EXPECT_EQ("mp4a.40.2", codecs_out[1]); | 237 EXPECT_EQ("mp4a.40.2", codecs_out[1]); |
| 235 } | 238 } |
| 236 | 239 |
| 240 // Basic smoke test for API. More exhaustive codec string testing found in | |
| 241 // media_canplaytype_browsertest.cc. | |
| 242 TEST(MimeUtilTest, ParseVideoCodecString) { | |
| 243 bool out_is_ambiguous; | |
| 244 VideoCodec out_codec; | |
| 245 VideoCodecProfile out_profile; | |
| 246 uint8_t out_level; | |
| 247 VideoColorSpace out_colorspace; | |
| 248 | |
| 249 // Valid AVC string. | |
| 250 EXPECT_TRUE(ParseVideoCodecString("video/mp4", "avc3.42E01E", | |
| 251 &out_is_ambiguous, &out_codec, &out_profile, | |
| 252 &out_level, &out_colorspace)); | |
| 253 EXPECT_FALSE(out_is_ambiguous); | |
| 254 EXPECT_EQ(kCodecH264, out_codec); | |
| 255 EXPECT_EQ(H264PROFILE_BASELINE, out_profile); | |
| 256 EXPECT_EQ(30, out_level); | |
| 257 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); | |
| 258 | |
| 259 // Valid VP9 string. | |
| 260 EnableNewVp9CodecStringSupport(); | |
| 261 EXPECT_TRUE(ParseVideoCodecString("video/webm", "vp09.00.10.08", | |
| 262 &out_is_ambiguous, &out_codec, &out_profile, | |
| 263 &out_level, &out_colorspace)); | |
| 264 EXPECT_FALSE(out_is_ambiguous); | |
| 265 EXPECT_EQ(kCodecVP9, out_codec); | |
| 266 EXPECT_EQ(VP9PROFILE_PROFILE0, out_profile); | |
| 267 EXPECT_EQ(10, out_level); | |
| 268 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); | |
| 269 // Restore to avoid polluting other tests. | |
| 270 DisableNewVp9CodecStringSupport_ForTesting(); | |
| 271 | |
| 272 // Ambiguous AVC string. | |
| 273 EXPECT_TRUE(ParseVideoCodecString("video/mp4", "avc3", &out_is_ambiguous, | |
| 274 &out_codec, &out_profile, &out_level, | |
| 275 &out_colorspace)); | |
| 276 EXPECT_TRUE(out_is_ambiguous); | |
| 277 EXPECT_EQ(kCodecH264, out_codec); | |
| 278 EXPECT_EQ(VIDEO_CODEC_PROFILE_UNKNOWN, out_profile); | |
| 279 EXPECT_EQ(0, out_level); | |
| 280 EXPECT_EQ(VideoColorSpace::REC709(), out_colorspace); | |
|
tguilbert
2017/05/17 20:58:33
Can you add a UT for a out_colorspace that isn't R
chcunningham
2017/05/18 01:29:42
Done.
| |
| 281 | |
| 282 // Audio codecs codec is not valid for video API. | |
| 283 EXPECT_FALSE(ParseVideoCodecString("video/mp4", "aac", &out_is_ambiguous, | |
| 284 &out_codec, &out_profile, &out_level, | |
| 285 &out_colorspace)); | |
| 286 | |
| 287 // Made up codec is invalid. | |
| 288 EXPECT_FALSE(ParseVideoCodecString("video/mp4", "bogus", &out_is_ambiguous, | |
| 289 &out_codec, &out_profile, &out_level, | |
| 290 &out_colorspace)); | |
| 291 } | |
| 292 | |
| 293 TEST(MimeUtilTest, ParseAudioCodecString) { | |
| 294 bool out_is_ambiguous; | |
| 295 AudioCodec out_codec; | |
| 296 | |
| 297 // Valid Opus string. | |
| 298 EXPECT_TRUE(ParseAudioCodecString("audio/webm", "opus", &out_is_ambiguous, | |
| 299 &out_codec)); | |
| 300 EXPECT_FALSE(out_is_ambiguous); | |
| 301 EXPECT_EQ(kCodecOpus, out_codec); | |
| 302 | |
| 303 // Valid AAC string. | |
| 304 EXPECT_TRUE(ParseAudioCodecString("audio/mp4", "mp4a.40.2", &out_is_ambiguous, | |
| 305 &out_codec)); | |
| 306 EXPECT_FALSE(out_is_ambiguous); | |
| 307 EXPECT_EQ(kCodecAAC, out_codec); | |
| 308 | |
| 309 // Ambiguous AAC string. | |
| 310 // TODO(chcunningha): This can probably be allowed. I think We treat all | |
| 311 // MPEG4_AAC the same. | |
| 312 EXPECT_TRUE(ParseAudioCodecString("audio/mp4", "mp4a.40", &out_is_ambiguous, | |
| 313 &out_codec)); | |
| 314 EXPECT_TRUE(out_is_ambiguous); | |
| 315 EXPECT_EQ(kCodecAAC, out_codec); | |
| 316 | |
| 317 // Valid empty codec string. Codec unambiguously implied by mime type. | |
| 318 EXPECT_TRUE( | |
| 319 ParseAudioCodecString("audio/flac", "", &out_is_ambiguous, &out_codec)); | |
| 320 EXPECT_FALSE(out_is_ambiguous); | |
| 321 EXPECT_EQ(kCodecFLAC, out_codec); | |
| 322 | |
| 323 // Valid audio codec should still be allowed with video mime type. | |
| 324 EXPECT_TRUE(ParseAudioCodecString("video/webm", "opus", &out_is_ambiguous, | |
| 325 &out_codec)); | |
| 326 EXPECT_FALSE(out_is_ambiguous); | |
| 327 EXPECT_EQ(kCodecOpus, out_codec); | |
| 328 | |
| 329 // Video codec is not valid for audio API. | |
| 330 EXPECT_FALSE(ParseAudioCodecString("audio/webm", "vp09.00.10.08", | |
| 331 &out_is_ambiguous, &out_codec)); | |
| 332 | |
| 333 // Made up codec is also not valid. | |
| 334 EXPECT_FALSE(ParseAudioCodecString("audio/webm", "bogus", &out_is_ambiguous, | |
| 335 &out_codec)); | |
| 336 } | |
| 337 | |
| 237 // See deeper string parsing testing in video_codecs_unittests.cc. | 338 // See deeper string parsing testing in video_codecs_unittests.cc. |
| 238 TEST(MimeUtilTest, ExperimentalMultiPartVp9) { | 339 TEST(MimeUtilTest, ExperimentalMultiPartVp9) { |
| 239 base::test::ScopedCommandLine scoped_command_line; | |
| 240 | 340 |
| 241 // Multi-part VP9 string not enabled by default. | 341 // Multi-part VP9 string not enabled by default. |
| 242 EXPECT_FALSE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); | 342 EXPECT_FALSE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); |
| 243 | 343 |
| 244 // Should work if enabled. | 344 // Should work if enabled. |
| 245 EnableNewVp9CodecStringSupport(); | 345 EnableNewVp9CodecStringSupport(); |
| 246 EXPECT_TRUE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); | 346 EXPECT_TRUE(IsSupportedMediaFormat("video/webm", {"vp09.00.10.08"})); |
| 347 // Restore to avoid polluting other tests. | |
| 348 DisableNewVp9CodecStringSupport_ForTesting(); | |
| 247 } | 349 } |
| 248 | 350 |
| 249 TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecsFailWithoutPlatformSupport) { | 351 TEST(IsCodecSupportedOnAndroidTest, EncryptedCodecsFailWithoutPlatformSupport) { |
| 250 // Vary all parameters except |has_platform_decoders|. | 352 // Vary all parameters except |has_platform_decoders|. |
| 251 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); | 353 MimeUtil::PlatformInfo states_to_vary = VaryAllFields(); |
| 252 states_to_vary.has_platform_decoders = false; | 354 states_to_vary.has_platform_decoders = false; |
| 253 | 355 |
| 254 // Disable platform decoders. | 356 // Disable platform decoders. |
| 255 MimeUtil::PlatformInfo test_states; | 357 MimeUtil::PlatformInfo test_states; |
| 256 test_states.has_platform_decoders = false; | 358 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)); | 504 MimeUtil::MPEG2_AAC, "application/vnd.apple.mpegurl", false, info)); |
| 403 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( | 505 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( |
| 404 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); | 506 MimeUtil::MPEG2_AAC, "audio/mpegurl", false, info)); |
| 405 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( | 507 EXPECT_FALSE(MimeUtil::IsCodecSupportedOnAndroid( |
| 406 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); | 508 MimeUtil::MPEG2_AAC, "audio/x-mpegurl", false, info)); |
| 407 }); | 509 }); |
| 408 } | 510 } |
| 409 | 511 |
| 410 } // namespace internal | 512 } // namespace internal |
| 411 } // namespace media | 513 } // namespace media |
| OLD | NEW |