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" |
16 | 17 |
17 #if defined(OS_ANDROID) | 18 #if defined(OS_ANDROID) |
18 #include "base/android/build_info.h" | 19 #include "base/android/build_info.h" |
19 #include "media/base/android/media_codec_util.h" | 20 #include "media/base/android/media_codec_util.h" |
20 #endif | 21 #endif |
21 | 22 |
22 namespace media { | 23 namespace media { |
23 namespace internal { | 24 namespace internal { |
24 | 25 |
25 struct CodecIDMappings { | 26 struct CodecIDMappings { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 } | 240 } |
240 | 241 |
241 if (is_ambiguous) | 242 if (is_ambiguous) |
242 result = MayBeSupported; | 243 result = MayBeSupported; |
243 } | 244 } |
244 | 245 |
245 return result; | 246 return result; |
246 } | 247 } |
247 | 248 |
248 void MimeUtil::InitializeMimeTypeMaps() { | 249 void MimeUtil::InitializeMimeTypeMaps() { |
249 #if defined(USE_PROPRIETARY_CODECS) | 250 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
250 allow_proprietary_codecs_ = true; | 251 allow_proprietary_codecs_ = true; |
251 #endif | 252 #endif |
252 | 253 |
253 for (size_t i = 0; i < arraysize(kUnambiguousCodecStringMap); ++i) { | 254 for (size_t i = 0; i < arraysize(kUnambiguousCodecStringMap); ++i) { |
254 string_to_codec_map_[kUnambiguousCodecStringMap[i].codec_id] = | 255 string_to_codec_map_[kUnambiguousCodecStringMap[i].codec_id] = |
255 CodecEntry(kUnambiguousCodecStringMap[i].codec, false); | 256 CodecEntry(kUnambiguousCodecStringMap[i].codec, false); |
256 } | 257 } |
257 | 258 |
258 for (size_t i = 0; i < arraysize(kAmbiguousCodecStringMap); ++i) { | 259 for (size_t i = 0; i < arraysize(kAmbiguousCodecStringMap); ++i) { |
259 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = | 260 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = |
(...skipping 24 matching lines...) Expand all Loading... |
284 | 285 |
285 CodecSet webm_audio_codecs; | 286 CodecSet webm_audio_codecs; |
286 webm_audio_codecs.insert(OPUS); | 287 webm_audio_codecs.insert(OPUS); |
287 webm_audio_codecs.insert(VORBIS); | 288 webm_audio_codecs.insert(VORBIS); |
288 CodecSet webm_video_codecs; | 289 CodecSet webm_video_codecs; |
289 webm_video_codecs.insert(VP8); | 290 webm_video_codecs.insert(VP8); |
290 webm_video_codecs.insert(VP9); | 291 webm_video_codecs.insert(VP9); |
291 CodecSet webm_codecs(webm_audio_codecs); | 292 CodecSet webm_codecs(webm_audio_codecs); |
292 webm_codecs.insert(webm_video_codecs.begin(), webm_video_codecs.end()); | 293 webm_codecs.insert(webm_video_codecs.begin(), webm_video_codecs.end()); |
293 | 294 |
294 #if defined(USE_PROPRIETARY_CODECS) | 295 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
295 CodecSet mp3_codecs; | 296 CodecSet mp3_codecs; |
296 mp3_codecs.insert(MP3); | 297 mp3_codecs.insert(MP3); |
297 | 298 |
298 CodecSet aac; | 299 CodecSet aac; |
299 aac.insert(MPEG2_AAC); | 300 aac.insert(MPEG2_AAC); |
300 aac.insert(MPEG4_AAC); | 301 aac.insert(MPEG4_AAC); |
301 | 302 |
302 CodecSet avc_and_aac(aac); | 303 CodecSet avc_and_aac(aac); |
303 avc_and_aac.insert(H264); | 304 avc_and_aac.insert(H264); |
304 | 305 |
305 CodecSet mp4_audio_codecs(aac); | 306 CodecSet mp4_audio_codecs(aac); |
306 mp4_audio_codecs.insert(MP3); | 307 mp4_audio_codecs.insert(MP3); |
307 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 308 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
308 mp4_audio_codecs.insert(AC3); | 309 mp4_audio_codecs.insert(AC3); |
309 mp4_audio_codecs.insert(EAC3); | 310 mp4_audio_codecs.insert(EAC3); |
310 #endif // BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 311 #endif // BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
311 | 312 |
312 CodecSet mp4_video_codecs; | 313 CodecSet mp4_video_codecs; |
313 mp4_video_codecs.insert(H264); | 314 mp4_video_codecs.insert(H264); |
314 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 315 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
315 mp4_video_codecs.insert(HEVC); | 316 mp4_video_codecs.insert(HEVC); |
316 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) | 317 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) |
317 // Only VP9 with valid codec string vp09.xx.xx.xx.xx.xx.xx.xx is supported. | 318 // Only VP9 with valid codec string vp09.xx.xx.xx.xx.xx.xx.xx is supported. |
318 // See ParseVp9CodecID for details. | 319 // See ParseVp9CodecID for details. |
319 mp4_video_codecs.insert(VP9); | 320 mp4_video_codecs.insert(VP9); |
320 CodecSet mp4_codecs(mp4_audio_codecs); | 321 CodecSet mp4_codecs(mp4_audio_codecs); |
321 mp4_codecs.insert(mp4_video_codecs.begin(), mp4_video_codecs.end()); | 322 mp4_codecs.insert(mp4_video_codecs.begin(), mp4_video_codecs.end()); |
322 #endif // defined(USE_PROPRIETARY_CODECS) | 323 #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) |
323 | 324 |
324 AddContainerWithCodecs("audio/wav", wav_codecs, false); | 325 AddContainerWithCodecs("audio/wav", wav_codecs, false); |
325 AddContainerWithCodecs("audio/x-wav", wav_codecs, false); | 326 AddContainerWithCodecs("audio/x-wav", wav_codecs, false); |
326 AddContainerWithCodecs("audio/webm", webm_audio_codecs, false); | 327 AddContainerWithCodecs("audio/webm", webm_audio_codecs, false); |
327 DCHECK(!webm_video_codecs.empty()); | 328 DCHECK(!webm_video_codecs.empty()); |
328 AddContainerWithCodecs("video/webm", webm_codecs, false); | 329 AddContainerWithCodecs("video/webm", webm_codecs, false); |
329 AddContainerWithCodecs("audio/ogg", ogg_audio_codecs, false); | 330 AddContainerWithCodecs("audio/ogg", ogg_audio_codecs, false); |
330 // video/ogg is only supported if an appropriate video codec is supported. | 331 // video/ogg is only supported if an appropriate video codec is supported. |
331 // Note: This assumes such codecs cannot be later excluded. | 332 // Note: This assumes such codecs cannot be later excluded. |
332 if (!ogg_video_codecs.empty()) | 333 if (!ogg_video_codecs.empty()) |
333 AddContainerWithCodecs("video/ogg", ogg_codecs, false); | 334 AddContainerWithCodecs("video/ogg", ogg_codecs, false); |
334 // TODO(ddorwin): Should the application type support Opus? | 335 // TODO(ddorwin): Should the application type support Opus? |
335 AddContainerWithCodecs("application/ogg", ogg_codecs, false); | 336 AddContainerWithCodecs("application/ogg", ogg_codecs, false); |
336 AddContainerWithCodecs("audio/flac", implicit_codec, false); | 337 AddContainerWithCodecs("audio/flac", implicit_codec, false); |
337 | 338 |
338 #if defined(USE_PROPRIETARY_CODECS) | 339 #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
339 AddContainerWithCodecs("audio/mpeg", mp3_codecs, true); // Allow "mp3". | 340 AddContainerWithCodecs("audio/mpeg", mp3_codecs, true); // Allow "mp3". |
340 AddContainerWithCodecs("audio/mp3", implicit_codec, true); | 341 AddContainerWithCodecs("audio/mp3", implicit_codec, true); |
341 AddContainerWithCodecs("audio/x-mp3", implicit_codec, true); | 342 AddContainerWithCodecs("audio/x-mp3", implicit_codec, true); |
342 AddContainerWithCodecs("audio/aac", implicit_codec, true); // AAC / ADTS. | 343 AddContainerWithCodecs("audio/aac", implicit_codec, true); // AAC / ADTS. |
343 AddContainerWithCodecs("audio/mp4", mp4_audio_codecs, true); | 344 AddContainerWithCodecs("audio/mp4", mp4_audio_codecs, true); |
344 DCHECK(!mp4_video_codecs.empty()); | 345 DCHECK(!mp4_video_codecs.empty()); |
345 AddContainerWithCodecs("video/mp4", mp4_codecs, true); | 346 AddContainerWithCodecs("video/mp4", mp4_codecs, true); |
346 // These strings are supported for backwards compatibility only and thus only | 347 // These strings are supported for backwards compatibility only and thus only |
347 // support the codecs needed for compatibility. | 348 // support the codecs needed for compatibility. |
348 AddContainerWithCodecs("audio/x-m4a", aac, true); | 349 AddContainerWithCodecs("audio/x-m4a", aac, true); |
(...skipping 10 matching lines...) Expand all Loading... |
359 CodecSet hls_codecs(avc_and_aac); | 360 CodecSet hls_codecs(avc_and_aac); |
360 hls_codecs.insert(MP3); | 361 hls_codecs.insert(MP3); |
361 AddContainerWithCodecs("application/x-mpegurl", hls_codecs, true); | 362 AddContainerWithCodecs("application/x-mpegurl", hls_codecs, true); |
362 AddContainerWithCodecs("application/vnd.apple.mpegurl", hls_codecs, true); | 363 AddContainerWithCodecs("application/vnd.apple.mpegurl", hls_codecs, true); |
363 AddContainerWithCodecs("audio/mpegurl", hls_codecs, true); | 364 AddContainerWithCodecs("audio/mpegurl", hls_codecs, true); |
364 // Not documented by Apple, but unfortunately used extensively by Apple and | 365 // Not documented by Apple, but unfortunately used extensively by Apple and |
365 // others for both audio-only and audio+video playlists. See | 366 // others for both audio-only and audio+video playlists. See |
366 // https://crbug.com/675552 for details and examples. | 367 // https://crbug.com/675552 for details and examples. |
367 AddContainerWithCodecs("audio/x-mpegurl", hls_codecs, true); | 368 AddContainerWithCodecs("audio/x-mpegurl", hls_codecs, true); |
368 #endif // defined(OS_ANDROID) | 369 #endif // defined(OS_ANDROID) |
369 #endif // defined(USE_PROPRIETARY_CODECS) | 370 #endif // BUILDFLAG(USE_PROPRIETARY_CODECS) |
370 } | 371 } |
371 | 372 |
372 void MimeUtil::AddContainerWithCodecs(const std::string& mime_type, | 373 void MimeUtil::AddContainerWithCodecs(const std::string& mime_type, |
373 const CodecSet& codecs, | 374 const CodecSet& codecs, |
374 bool is_proprietary_mime_type) { | 375 bool is_proprietary_mime_type) { |
375 #if !defined(USE_PROPRIETARY_CODECS) | 376 #if !BUILDFLAG(USE_PROPRIETARY_CODECS) |
376 DCHECK(!is_proprietary_mime_type); | 377 DCHECK(!is_proprietary_mime_type); |
377 #endif | 378 #endif |
378 | 379 |
379 media_format_map_[mime_type] = codecs; | 380 media_format_map_[mime_type] = codecs; |
380 | 381 |
381 if (is_proprietary_mime_type) | 382 if (is_proprietary_mime_type) |
382 proprietary_media_containers_.push_back(mime_type); | 383 proprietary_media_containers_.push_back(mime_type); |
383 } | 384 } |
384 | 385 |
385 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 386 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 const std::string& mime_type_lower_case, | 739 const std::string& mime_type_lower_case, |
739 bool is_encrypted) const { | 740 bool is_encrypted) const { |
740 Codec default_codec = Codec::INVALID_CODEC; | 741 Codec default_codec = Codec::INVALID_CODEC; |
741 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 742 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
742 return false; | 743 return false; |
743 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); | 744 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); |
744 } | 745 } |
745 | 746 |
746 } // namespace internal | 747 } // namespace internal |
747 } // namespace media | 748 } // namespace media |
OLD | NEW |