| 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); | 
| 349   AddContainerWithCodecs("video/x-m4v", avc_and_aac, true); | 350   AddContainerWithCodecs("video/x-m4v", avc_and_aac, true); | 
| 350 | 351 | 
| 351 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 352 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 
| 352   // TODO(ddorwin): Exactly which codecs should be supported? | 353   // TODO(ddorwin): Exactly which codecs should be supported? | 
| 353   DCHECK(!mp4_video_codecs.empty()); | 354   DCHECK(!mp4_video_codecs.empty()); | 
| 354   AddContainerWithCodecs("video/mp2t", mp4_codecs, true); | 355   AddContainerWithCodecs("video/mp2t", mp4_codecs, true); | 
| 355 #endif  // BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 356 #endif  // BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 
| 356 #if defined(OS_ANDROID) | 357 #if defined(OS_ANDROID) | 
| 357   // HTTP Live Streaming (HLS). | 358   // HTTP Live Streaming (HLS). | 
| 358   // TODO(ddorwin): Is any MP3 codec string variant included in real queries? | 359   // TODO(ddorwin): Is any MP3 codec string variant included in real queries? | 
| 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 #endif  // defined(OS_ANDROID) | 364 #endif  // defined(OS_ANDROID) | 
| 364 #endif  // defined(USE_PROPRIETARY_CODECS) | 365 #endif  // BUILDFLAG(USE_PROPRIETARY_CODECS) | 
| 365 } | 366 } | 
| 366 | 367 | 
| 367 void MimeUtil::AddContainerWithCodecs(const std::string& mime_type, | 368 void MimeUtil::AddContainerWithCodecs(const std::string& mime_type, | 
| 368                                       const CodecSet& codecs, | 369                                       const CodecSet& codecs, | 
| 369                                       bool is_proprietary_mime_type) { | 370                                       bool is_proprietary_mime_type) { | 
| 370 #if !defined(USE_PROPRIETARY_CODECS) | 371 #if !BUILDFLAG(USE_PROPRIETARY_CODECS) | 
| 371   DCHECK(!is_proprietary_mime_type); | 372   DCHECK(!is_proprietary_mime_type); | 
| 372 #endif | 373 #endif | 
| 373 | 374 | 
| 374   media_format_map_[mime_type] = codecs; | 375   media_format_map_[mime_type] = codecs; | 
| 375 | 376 | 
| 376   if (is_proprietary_mime_type) | 377   if (is_proprietary_mime_type) | 
| 377     proprietary_media_containers_.push_back(mime_type); | 378     proprietary_media_containers_.push_back(mime_type); | 
| 378 } | 379 } | 
| 379 | 380 | 
| 380 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 381 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 733     const std::string& mime_type_lower_case, | 734     const std::string& mime_type_lower_case, | 
| 734     bool is_encrypted) const { | 735     bool is_encrypted) const { | 
| 735   Codec default_codec = Codec::INVALID_CODEC; | 736   Codec default_codec = Codec::INVALID_CODEC; | 
| 736   if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 737   if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 
| 737     return false; | 738     return false; | 
| 738   return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); | 739   return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); | 
| 739 } | 740 } | 
| 740 | 741 | 
| 741 }  // namespace internal | 742 }  // namespace internal | 
| 742 }  // namespace media | 743 }  // namespace media | 
| OLD | NEW | 
|---|