| 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/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = | 245 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = |
| 246 CodecEntry(kAmbiguousCodecStringMap[i].codec, true); | 246 CodecEntry(kAmbiguousCodecStringMap[i].codec, true); |
| 247 } | 247 } |
| 248 | 248 |
| 249 AddSupportedMediaFormats(); | 249 AddSupportedMediaFormats(); |
| 250 } | 250 } |
| 251 | 251 |
| 252 // Each call to AddContainerWithCodecs() contains a media type | 252 // Each call to AddContainerWithCodecs() contains a media type |
| 253 // (https://en.wikipedia.org/wiki/Media_type) and corresponding media codec(s) | 253 // (https://en.wikipedia.org/wiki/Media_type) and corresponding media codec(s) |
| 254 // supported by these types/containers. | 254 // supported by these types/containers. |
| 255 // | 255 // TODO(ddorwin): Replace insert() calls with initializer_list when allowed. |
| 256 // Strings used as the |codecs_list| only need one valid unambiguous variant for | |
| 257 // each supported MimeUtil::Codec enum value. Each codec string is parsed and | |
| 258 // mapped to corresponding MimeUtil::Codec value. See https://crbug.com/461009. | |
| 259 void MimeUtil::AddSupportedMediaFormats() { | 256 void MimeUtil::AddSupportedMediaFormats() { |
| 260 const std::string ogg_audio_codecs = "opus,vorbis"; | 257 CodecSet implicit_codec; |
| 261 std::string ogg_video_codecs; | 258 CodecSet wav_codecs; |
| 259 wav_codecs.insert(PCM); |
| 260 |
| 261 CodecSet ogg_audio_codecs; |
| 262 ogg_audio_codecs.insert(OPUS); |
| 263 ogg_audio_codecs.insert(VORBIS); |
| 264 CodecSet ogg_video_codecs; |
| 262 #if !defined(OS_ANDROID) | 265 #if !defined(OS_ANDROID) |
| 263 ogg_video_codecs = "theora"; | 266 ogg_video_codecs.insert(THEORA); |
| 264 #endif // !defined(OS_ANDROID) | 267 #endif // !defined(OS_ANDROID) |
| 265 std::string ogg_codecs = ogg_audio_codecs; | 268 CodecSet ogg_codecs(ogg_audio_codecs); |
| 266 if (!ogg_video_codecs.empty()) | 269 ogg_codecs.insert(ogg_video_codecs.begin(), ogg_video_codecs.end()); |
| 267 ogg_codecs += "," + ogg_video_codecs; | 270 |
| 271 CodecSet webm_audio_codecs; |
| 272 webm_audio_codecs.insert(OPUS); |
| 273 webm_audio_codecs.insert(VORBIS); |
| 274 CodecSet webm_video_codecs; |
| 275 webm_video_codecs.insert(VP8); |
| 276 webm_video_codecs.insert(VP9); |
| 277 CodecSet webm_codecs(webm_audio_codecs); |
| 278 webm_codecs.insert(webm_video_codecs.begin(), webm_video_codecs.end()); |
| 268 | 279 |
| 269 #if defined(USE_PROPRIETARY_CODECS) | 280 #if defined(USE_PROPRIETARY_CODECS) |
| 270 const std::string aac = "mp4a.66,mp4a.40.2"; // MPEG-2 and MPEG-4 AAC. | 281 CodecSet mp3_codecs; |
| 271 const std::string mp3 = "mp4a.69"; | 282 mp3_codecs.insert(MP3); |
| 272 const std::string avc = "avc1.42E00A"; | |
| 273 | 283 |
| 274 const std::string avc_and_aac = avc + "," + aac; | 284 CodecSet aac; |
| 275 std::string mp4_audio_codecs = aac + "," + mp3; | 285 aac.insert(MPEG2_AAC); |
| 286 aac.insert(MPEG4_AAC); |
| 287 |
| 288 CodecSet avc_and_aac(aac); |
| 289 avc_and_aac.insert(H264); |
| 290 |
| 291 CodecSet mp4_audio_codecs(aac); |
| 292 mp4_audio_codecs.insert(MP3); |
| 276 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 293 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 277 mp4_audio_codecs += ",ac-3,ec-3"; // AC-3 and E-AC-3. | 294 mp4_audio_codecs.insert(AC3); |
| 295 mp4_audio_codecs.insert(EAC3); |
| 278 #endif // BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 296 #endif // BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 279 | 297 |
| 280 std::string mp4_video_codecs = avc; | 298 CodecSet mp4_video_codecs; |
| 299 mp4_video_codecs.insert(H264); |
| 281 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 300 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 282 mp4_video_codecs += ",hev1.1.6.L93.B0"; | 301 mp4_video_codecs.insert(HEVC_MAIN); |
| 283 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) | 302 #endif // BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 284 const std::string mp4_codecs = mp4_video_codecs + "," + mp4_audio_codecs; | 303 CodecSet mp4_codecs(mp4_audio_codecs); |
| 304 mp4_codecs.insert(mp4_video_codecs.begin(), mp4_video_codecs.end()); |
| 285 #endif // defined(USE_PROPRIETARY_CODECS) | 305 #endif // defined(USE_PROPRIETARY_CODECS) |
| 286 | 306 |
| 287 AddContainerWithCodecs("audio/wav", "1", false); | 307 AddContainerWithCodecs("audio/wav", wav_codecs, false); |
| 288 AddContainerWithCodecs("audio/x-wav", "1", false); | 308 AddContainerWithCodecs("audio/x-wav", wav_codecs, false); |
| 289 AddContainerWithCodecs("audio/webm", "opus,vorbis", false); | 309 AddContainerWithCodecs("audio/webm", webm_audio_codecs, false); |
| 290 AddContainerWithCodecs("video/webm", "opus,vorbis,vp8,vp9", false); | 310 DCHECK(!webm_video_codecs.empty()); |
| 311 AddContainerWithCodecs("video/webm", webm_codecs, false); |
| 291 AddContainerWithCodecs("audio/ogg", ogg_audio_codecs, false); | 312 AddContainerWithCodecs("audio/ogg", ogg_audio_codecs, false); |
| 292 // video/ogg is only supported if an appropriate video codec is supported. | 313 // video/ogg is only supported if an appropriate video codec is supported. |
| 293 // Note: This assumes such codecs cannot be later excluded. | 314 // Note: This assumes such codecs cannot be later excluded. |
| 294 if (!ogg_video_codecs.empty()) | 315 if (!ogg_video_codecs.empty()) |
| 295 AddContainerWithCodecs("video/ogg", ogg_codecs, false); | 316 AddContainerWithCodecs("video/ogg", ogg_codecs, false); |
| 296 // TODO(ddorwin): Should the application type support Opus? | 317 // TODO(ddorwin): Should the application type support Opus? |
| 297 AddContainerWithCodecs("application/ogg", ogg_codecs, false); | 318 AddContainerWithCodecs("application/ogg", ogg_codecs, false); |
| 298 | 319 |
| 299 #if defined(USE_PROPRIETARY_CODECS) | 320 #if defined(USE_PROPRIETARY_CODECS) |
| 300 AddContainerWithCodecs("audio/mpeg", "mp3", true); | 321 AddContainerWithCodecs("audio/mpeg", mp3_codecs, true); // Allow "mp3". |
| 301 AddContainerWithCodecs("audio/mp3", "", true); | 322 AddContainerWithCodecs("audio/mp3", implicit_codec, true); |
| 302 AddContainerWithCodecs("audio/x-mp3", "", true); | 323 AddContainerWithCodecs("audio/x-mp3", implicit_codec, true); |
| 303 AddContainerWithCodecs("audio/aac", "", true); // AAC / ADTS | 324 AddContainerWithCodecs("audio/aac", implicit_codec, true); // AAC / ADTS. |
| 304 AddContainerWithCodecs("audio/mp4", mp4_audio_codecs, true); | 325 AddContainerWithCodecs("audio/mp4", mp4_audio_codecs, true); |
| 305 DCHECK(!mp4_video_codecs.empty()); | 326 DCHECK(!mp4_video_codecs.empty()); |
| 306 AddContainerWithCodecs("video/mp4", mp4_codecs, true); | 327 AddContainerWithCodecs("video/mp4", mp4_codecs, true); |
| 307 // These strings are supported for backwards compatibility only and thus only | 328 // These strings are supported for backwards compatibility only and thus only |
| 308 // support the codecs needed for compatibility. | 329 // support the codecs needed for compatibility. |
| 309 AddContainerWithCodecs("audio/x-m4a", aac, true); | 330 AddContainerWithCodecs("audio/x-m4a", aac, true); |
| 310 AddContainerWithCodecs("video/x-m4v", avc_and_aac, true); | 331 AddContainerWithCodecs("video/x-m4v", avc_and_aac, true); |
| 311 | 332 |
| 312 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 333 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
| 313 // TODO(ddorwin): Exactly which codecs should be supported? | 334 // TODO(ddorwin): Exactly which codecs should be supported? |
| 314 DCHECK(!mp4_video_codecs.empty()); | 335 DCHECK(!mp4_video_codecs.empty()); |
| 315 AddContainerWithCodecs("video/mp2t", mp4_codecs, true); | 336 AddContainerWithCodecs("video/mp2t", mp4_codecs, true); |
| 316 #endif // BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 337 #endif // BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
| 317 #if defined(OS_ANDROID) | 338 #if defined(OS_ANDROID) |
| 318 // HTTP Live Streaming (HLS). | 339 // HTTP Live Streaming (HLS). |
| 319 // TODO(ddorwin): Is any MP3 codec string variant included in real queries? | 340 // TODO(ddorwin): Is any MP3 codec string variant included in real queries? |
| 320 const std::string hls_codecs = avc_and_aac + "," + mp3; | 341 CodecSet hls_codecs(avc_and_aac); |
| 342 hls_codecs.insert(MP3); |
| 321 AddContainerWithCodecs("application/x-mpegurl", hls_codecs, true); | 343 AddContainerWithCodecs("application/x-mpegurl", hls_codecs, true); |
| 322 AddContainerWithCodecs("application/vnd.apple.mpegurl", hls_codecs, true); | 344 AddContainerWithCodecs("application/vnd.apple.mpegurl", hls_codecs, true); |
| 323 #endif // defined(OS_ANDROID) | 345 #endif // defined(OS_ANDROID) |
| 324 #endif // defined(USE_PROPRIETARY_CODECS) | 346 #endif // defined(USE_PROPRIETARY_CODECS) |
| 325 } | 347 } |
| 326 | 348 |
| 327 // TODO(ddorwin): Replace |codecs_list| with a vector of MimeUtil::Codec values. | |
| 328 // See https://crbug.com/461009. | |
| 329 void MimeUtil::AddContainerWithCodecs(const std::string& mime_type, | 349 void MimeUtil::AddContainerWithCodecs(const std::string& mime_type, |
| 330 const std::string& codecs_list, | 350 const CodecSet& codecs, |
| 331 bool is_proprietary_mime_type) { | 351 bool is_proprietary_mime_type) { |
| 332 #if !defined(USE_PROPRIETARY_CODECS) | 352 #if !defined(USE_PROPRIETARY_CODECS) |
| 333 DCHECK(!is_proprietary_mime_type); | 353 DCHECK(!is_proprietary_mime_type); |
| 334 #endif | 354 #endif |
| 335 | 355 |
| 336 std::vector<std::string> codec_strings; | |
| 337 ParseCodecString(codecs_list, &codec_strings, false); | |
| 338 | |
| 339 CodecSet codecs; | |
| 340 for (const auto& codec_string : codec_strings) { | |
| 341 DCHECK(!codec_string.empty()) << codecs_list; | |
| 342 Codec codec = INVALID_CODEC; | |
| 343 bool is_ambiguous = true; | |
| 344 CHECK(StringToCodec(codec_string, &codec, &is_ambiguous, false)); | |
| 345 DCHECK(!is_ambiguous) << codec_string; | |
| 346 codecs.insert(codec); | |
| 347 } | |
| 348 | |
| 349 media_format_map_[mime_type] = codecs; | 356 media_format_map_[mime_type] = codecs; |
| 350 | 357 |
| 351 if (is_proprietary_mime_type) | 358 if (is_proprietary_mime_type) |
| 352 proprietary_media_containers_.push_back(mime_type); | 359 proprietary_media_containers_.push_back(mime_type); |
| 353 } | 360 } |
| 354 | 361 |
| 355 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 362 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
| 356 return media_format_map_.find(base::ToLowerASCII(mime_type)) != | 363 return media_format_map_.find(base::ToLowerASCII(mime_type)) != |
| 357 media_format_map_.end(); | 364 media_format_map_.end(); |
| 358 } | 365 } |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 const std::string& mime_type_lower_case, | 675 const std::string& mime_type_lower_case, |
| 669 bool is_encrypted) const { | 676 bool is_encrypted) const { |
| 670 Codec default_codec = Codec::INVALID_CODEC; | 677 Codec default_codec = Codec::INVALID_CODEC; |
| 671 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 678 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
| 672 return false; | 679 return false; |
| 673 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); | 680 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); |
| 674 } | 681 } |
| 675 | 682 |
| 676 } // namespace internal | 683 } // namespace internal |
| 677 } // namespace media | 684 } // namespace media |
| OLD | NEW |