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