OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "media/base/mime_util_internal.h" | 5 #include "media/base/mime_util_internal.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "media/base/media.h" | 12 #include "media/base/media.h" |
13 #include "media/base/media_client.h" | 13 #include "media/base/media_client.h" |
14 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
15 #include "media/base/video_codecs.h" | 15 #include "media/base/video_codecs.h" |
16 #include "media/media_features.h" | |
17 | 16 |
18 #if defined(OS_ANDROID) | 17 #if defined(OS_ANDROID) |
19 #include "base/android/build_info.h" | 18 #include "base/android/build_info.h" |
20 #include "media/base/android/media_codec_util.h" | 19 #include "media/base/android/media_codec_util.h" |
21 #endif | 20 #endif |
22 | 21 |
23 namespace media { | 22 namespace media { |
24 namespace internal { | 23 namespace internal { |
25 | 24 |
26 struct CodecIDMappings { | 25 struct CodecIDMappings { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 239 } |
241 | 240 |
242 if (is_ambiguous) | 241 if (is_ambiguous) |
243 result = MayBeSupported; | 242 result = MayBeSupported; |
244 } | 243 } |
245 | 244 |
246 return result; | 245 return result; |
247 } | 246 } |
248 | 247 |
249 void MimeUtil::InitializeMimeTypeMaps() { | 248 void MimeUtil::InitializeMimeTypeMaps() { |
250 #if BUILDFLAG(USE_PROPRIETARY_CODECS) | 249 #if defined(USE_PROPRIETARY_CODECS) |
251 allow_proprietary_codecs_ = true; | 250 allow_proprietary_codecs_ = true; |
252 #endif | 251 #endif |
253 | 252 |
254 for (size_t i = 0; i < arraysize(kUnambiguousCodecStringMap); ++i) { | 253 for (size_t i = 0; i < arraysize(kUnambiguousCodecStringMap); ++i) { |
255 string_to_codec_map_[kUnambiguousCodecStringMap[i].codec_id] = | 254 string_to_codec_map_[kUnambiguousCodecStringMap[i].codec_id] = |
256 CodecEntry(kUnambiguousCodecStringMap[i].codec, false); | 255 CodecEntry(kUnambiguousCodecStringMap[i].codec, false); |
257 } | 256 } |
258 | 257 |
259 for (size_t i = 0; i < arraysize(kAmbiguousCodecStringMap); ++i) { | 258 for (size_t i = 0; i < arraysize(kAmbiguousCodecStringMap); ++i) { |
260 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = | 259 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = |
(...skipping 24 matching lines...) Expand all Loading... |
285 | 284 |
286 CodecSet webm_audio_codecs; | 285 CodecSet webm_audio_codecs; |
287 webm_audio_codecs.insert(OPUS); | 286 webm_audio_codecs.insert(OPUS); |
288 webm_audio_codecs.insert(VORBIS); | 287 webm_audio_codecs.insert(VORBIS); |
289 CodecSet webm_video_codecs; | 288 CodecSet webm_video_codecs; |
290 webm_video_codecs.insert(VP8); | 289 webm_video_codecs.insert(VP8); |
291 webm_video_codecs.insert(VP9); | 290 webm_video_codecs.insert(VP9); |
292 CodecSet webm_codecs(webm_audio_codecs); | 291 CodecSet webm_codecs(webm_audio_codecs); |
293 webm_codecs.insert(webm_video_codecs.begin(), webm_video_codecs.end()); | 292 webm_codecs.insert(webm_video_codecs.begin(), webm_video_codecs.end()); |
294 | 293 |
295 #if BUILDFLAG(USE_PROPRIETARY_CODECS) | 294 #if defined(USE_PROPRIETARY_CODECS) |
296 CodecSet mp3_codecs; | 295 CodecSet mp3_codecs; |
297 mp3_codecs.insert(MP3); | 296 mp3_codecs.insert(MP3); |
298 | 297 |
299 CodecSet aac; | 298 CodecSet aac; |
300 aac.insert(MPEG2_AAC); | 299 aac.insert(MPEG2_AAC); |
301 aac.insert(MPEG4_AAC); | 300 aac.insert(MPEG4_AAC); |
302 | 301 |
303 CodecSet avc_and_aac(aac); | 302 CodecSet avc_and_aac(aac); |
304 avc_and_aac.insert(H264); | 303 avc_and_aac.insert(H264); |
305 | 304 |
306 CodecSet mp4_audio_codecs(aac); | 305 CodecSet mp4_audio_codecs(aac); |
307 mp4_audio_codecs.insert(MP3); | 306 mp4_audio_codecs.insert(MP3); |
308 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 307 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
309 mp4_audio_codecs.insert(AC3); | 308 mp4_audio_codecs.insert(AC3); |
310 mp4_audio_codecs.insert(EAC3); | 309 mp4_audio_codecs.insert(EAC3); |
311 #endif // BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 310 #endif // BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
312 | 311 |
313 CodecSet mp4_video_codecs; | 312 CodecSet mp4_video_codecs; |
314 mp4_video_codecs.insert(H264); | 313 mp4_video_codecs.insert(H264); |
315 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 314 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
316 mp4_video_codecs.insert(HEVC); | 315 mp4_video_codecs.insert(HEVC); |
317 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) | 316 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) |
318 // Only VP9 with valid codec string vp09.xx.xx.xx.xx.xx.xx.xx is supported. | 317 // Only VP9 with valid codec string vp09.xx.xx.xx.xx.xx.xx.xx is supported. |
319 // See ParseVp9CodecID for details. | 318 // See ParseVp9CodecID for details. |
320 mp4_video_codecs.insert(VP9); | 319 mp4_video_codecs.insert(VP9); |
321 CodecSet mp4_codecs(mp4_audio_codecs); | 320 CodecSet mp4_codecs(mp4_audio_codecs); |
322 mp4_codecs.insert(mp4_video_codecs.begin(), mp4_video_codecs.end()); | 321 mp4_codecs.insert(mp4_video_codecs.begin(), mp4_video_codecs.end()); |
323 #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) | 322 #endif // defined(USE_PROPRIETARY_CODECS) |
324 | 323 |
325 AddContainerWithCodecs("audio/wav", wav_codecs, false); | 324 AddContainerWithCodecs("audio/wav", wav_codecs, false); |
326 AddContainerWithCodecs("audio/x-wav", wav_codecs, false); | 325 AddContainerWithCodecs("audio/x-wav", wav_codecs, false); |
327 AddContainerWithCodecs("audio/webm", webm_audio_codecs, false); | 326 AddContainerWithCodecs("audio/webm", webm_audio_codecs, false); |
328 DCHECK(!webm_video_codecs.empty()); | 327 DCHECK(!webm_video_codecs.empty()); |
329 AddContainerWithCodecs("video/webm", webm_codecs, false); | 328 AddContainerWithCodecs("video/webm", webm_codecs, false); |
330 AddContainerWithCodecs("audio/ogg", ogg_audio_codecs, false); | 329 AddContainerWithCodecs("audio/ogg", ogg_audio_codecs, false); |
331 // video/ogg is only supported if an appropriate video codec is supported. | 330 // video/ogg is only supported if an appropriate video codec is supported. |
332 // Note: This assumes such codecs cannot be later excluded. | 331 // Note: This assumes such codecs cannot be later excluded. |
333 if (!ogg_video_codecs.empty()) | 332 if (!ogg_video_codecs.empty()) |
334 AddContainerWithCodecs("video/ogg", ogg_codecs, false); | 333 AddContainerWithCodecs("video/ogg", ogg_codecs, false); |
335 // TODO(ddorwin): Should the application type support Opus? | 334 // TODO(ddorwin): Should the application type support Opus? |
336 AddContainerWithCodecs("application/ogg", ogg_codecs, false); | 335 AddContainerWithCodecs("application/ogg", ogg_codecs, false); |
337 AddContainerWithCodecs("audio/flac", implicit_codec, false); | 336 AddContainerWithCodecs("audio/flac", implicit_codec, false); |
338 | 337 |
339 #if BUILDFLAG(USE_PROPRIETARY_CODECS) | 338 #if defined(USE_PROPRIETARY_CODECS) |
340 AddContainerWithCodecs("audio/mpeg", mp3_codecs, true); // Allow "mp3". | 339 AddContainerWithCodecs("audio/mpeg", mp3_codecs, true); // Allow "mp3". |
341 AddContainerWithCodecs("audio/mp3", implicit_codec, true); | 340 AddContainerWithCodecs("audio/mp3", implicit_codec, true); |
342 AddContainerWithCodecs("audio/x-mp3", implicit_codec, true); | 341 AddContainerWithCodecs("audio/x-mp3", implicit_codec, true); |
343 AddContainerWithCodecs("audio/aac", implicit_codec, true); // AAC / ADTS. | 342 AddContainerWithCodecs("audio/aac", implicit_codec, true); // AAC / ADTS. |
344 AddContainerWithCodecs("audio/mp4", mp4_audio_codecs, true); | 343 AddContainerWithCodecs("audio/mp4", mp4_audio_codecs, true); |
345 DCHECK(!mp4_video_codecs.empty()); | 344 DCHECK(!mp4_video_codecs.empty()); |
346 AddContainerWithCodecs("video/mp4", mp4_codecs, true); | 345 AddContainerWithCodecs("video/mp4", mp4_codecs, true); |
347 // These strings are supported for backwards compatibility only and thus only | 346 // These strings are supported for backwards compatibility only and thus only |
348 // support the codecs needed for compatibility. | 347 // support the codecs needed for compatibility. |
349 AddContainerWithCodecs("audio/x-m4a", aac, true); | 348 AddContainerWithCodecs("audio/x-m4a", aac, true); |
350 AddContainerWithCodecs("video/x-m4v", avc_and_aac, true); | 349 AddContainerWithCodecs("video/x-m4v", avc_and_aac, true); |
351 | 350 |
352 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 351 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
353 // TODO(ddorwin): Exactly which codecs should be supported? | 352 // TODO(ddorwin): Exactly which codecs should be supported? |
354 DCHECK(!mp4_video_codecs.empty()); | 353 DCHECK(!mp4_video_codecs.empty()); |
355 AddContainerWithCodecs("video/mp2t", mp4_codecs, true); | 354 AddContainerWithCodecs("video/mp2t", mp4_codecs, true); |
356 #endif // BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 355 #endif // BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
357 #if defined(OS_ANDROID) | 356 #if defined(OS_ANDROID) |
358 // HTTP Live Streaming (HLS). | 357 // HTTP Live Streaming (HLS). |
359 // TODO(ddorwin): Is any MP3 codec string variant included in real queries? | 358 // TODO(ddorwin): Is any MP3 codec string variant included in real queries? |
360 CodecSet hls_codecs(avc_and_aac); | 359 CodecSet hls_codecs(avc_and_aac); |
361 hls_codecs.insert(MP3); | 360 hls_codecs.insert(MP3); |
362 AddContainerWithCodecs("application/x-mpegurl", hls_codecs, true); | 361 AddContainerWithCodecs("application/x-mpegurl", hls_codecs, true); |
363 AddContainerWithCodecs("application/vnd.apple.mpegurl", hls_codecs, true); | 362 AddContainerWithCodecs("application/vnd.apple.mpegurl", hls_codecs, true); |
364 #endif // defined(OS_ANDROID) | 363 #endif // defined(OS_ANDROID) |
365 #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) | 364 #endif // defined(USE_PROPRIETARY_CODECS) |
366 } | 365 } |
367 | 366 |
368 void MimeUtil::AddContainerWithCodecs(const std::string& mime_type, | 367 void MimeUtil::AddContainerWithCodecs(const std::string& mime_type, |
369 const CodecSet& codecs, | 368 const CodecSet& codecs, |
370 bool is_proprietary_mime_type) { | 369 bool is_proprietary_mime_type) { |
371 #if !BUILDFLAG(USE_PROPRIETARY_CODECS) | 370 #if !defined(USE_PROPRIETARY_CODECS) |
372 DCHECK(!is_proprietary_mime_type); | 371 DCHECK(!is_proprietary_mime_type); |
373 #endif | 372 #endif |
374 | 373 |
375 media_format_map_[mime_type] = codecs; | 374 media_format_map_[mime_type] = codecs; |
376 | 375 |
377 if (is_proprietary_mime_type) | 376 if (is_proprietary_mime_type) |
378 proprietary_media_containers_.push_back(mime_type); | 377 proprietary_media_containers_.push_back(mime_type); |
379 } | 378 } |
380 | 379 |
381 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 380 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 const std::string& mime_type_lower_case, | 733 const std::string& mime_type_lower_case, |
735 bool is_encrypted) const { | 734 bool is_encrypted) const { |
736 Codec default_codec = Codec::INVALID_CODEC; | 735 Codec default_codec = Codec::INVALID_CODEC; |
737 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 736 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
738 return false; | 737 return false; |
739 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); | 738 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); |
740 } | 739 } |
741 | 740 |
742 } // namespace internal | 741 } // namespace internal |
743 } // namespace media | 742 } // namespace media |
OLD | NEW |