Chromium Code Reviews| 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/containers/hash_tables.h" | 7 #include "base/containers/hash_tables.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 MPEG4_AAC_SBR_PS_v2, | 33 MPEG4_AAC_SBR_PS_v2, |
| 34 VORBIS, | 34 VORBIS, |
| 35 OPUS, | 35 OPUS, |
| 36 H264_BASELINE, | 36 H264_BASELINE, |
| 37 H264_MAIN, | 37 H264_MAIN, |
| 38 H264_HIGH, | 38 H264_HIGH, |
| 39 HEVC_MAIN, | 39 HEVC_MAIN, |
| 40 VP8, | 40 VP8, |
| 41 VP9, | 41 VP9, |
| 42 THEORA | 42 THEORA |
| 43 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
|
ddorwin
2015/11/25 22:24:08
Do we need to ifdef this? There are other propriet
servolk
2015/12/03 00:56:14
Done.
| |
| 44 , | |
| 45 AC3, | |
|
ddorwin
2015/11/25 22:24:08
Regardless, keep similar types (at least audio) to
servolk
2015/12/03 00:56:15
Done.
| |
| 46 EAC3 | |
| 47 #endif | |
| 43 }; | 48 }; |
| 44 | 49 |
| 45 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | 50 bool IsSupportedMediaMimeType(const std::string& mime_type) const; |
| 46 | 51 |
| 47 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; | 52 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; |
| 48 | 53 |
| 49 void ParseCodecString(const std::string& codecs, | 54 void ParseCodecString(const std::string& codecs, |
| 50 std::vector<std::string>* codecs_out, | 55 std::vector<std::string>* codecs_out, |
| 51 bool strip); | 56 bool strip); |
| 52 | 57 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 #else | 215 #else |
| 211 return false; | 216 return false; |
| 212 #endif | 217 #endif |
| 213 | 218 |
| 214 case MimeUtil::MPEG2_AAC_LC: | 219 case MimeUtil::MPEG2_AAC_LC: |
| 215 case MimeUtil::MPEG2_AAC_MAIN: | 220 case MimeUtil::MPEG2_AAC_MAIN: |
| 216 case MimeUtil::MPEG2_AAC_SSR: | 221 case MimeUtil::MPEG2_AAC_SSR: |
| 217 // MPEG-2 variants of AAC are not supported on Android. | 222 // MPEG-2 variants of AAC are not supported on Android. |
| 218 return false; | 223 return false; |
| 219 | 224 |
| 225 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
| 226 case MimeUtil::AC3: | |
| 227 case MimeUtil::EAC3: | |
| 228 // TODO(servolk): Revisit this for AC3/EAC3 support on AndroidTV | |
| 229 return false; | |
| 230 #endif | |
| 231 | |
| 220 case MimeUtil::VP9: | 232 case MimeUtil::VP9: |
| 221 // VP9 is supported only in KitKat+ (API Level 19). | 233 // VP9 is supported only in KitKat+ (API Level 19). |
| 222 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 234 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
| 223 | 235 |
| 224 case MimeUtil::OPUS: | 236 case MimeUtil::OPUS: |
| 225 // Opus is supported only in Lollipop+ (API Level 21). | 237 // Opus is supported only in Lollipop+ (API Level 21). |
| 226 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 238 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
| 227 | 239 |
| 228 case MimeUtil::THEORA: | 240 case MimeUtil::THEORA: |
| 229 return false; | 241 return false; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 249 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) | 261 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) |
| 250 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for | 262 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for |
| 251 // compatibility) | 263 // compatibility) |
| 252 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) | 264 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) |
| 253 // | 265 // |
| 254 // avc1.42E0xx - H.264 Baseline | 266 // avc1.42E0xx - H.264 Baseline |
| 255 // avc1.4D40xx - H.264 Main | 267 // avc1.4D40xx - H.264 Main |
| 256 // avc1.6400xx - H.264 High | 268 // avc1.6400xx - H.264 High |
| 257 static const char kMP4AudioCodecsExpression[] = | 269 static const char kMP4AudioCodecsExpression[] = |
| 258 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 270 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 271 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
| 272 "ac-3,ec-3," // Note: only one variant of eac codec string is sufficient | |
|
ddorwin
2015/11/25 22:24:08
Same as the next comment.
servolk
2015/12/03 00:56:15
Done.
| |
| 273 // here since these are converted into enums in | |
| 274 // InitializeMimeTypeMaps | |
| 275 #endif | |
| 259 "mp4a.40.05,mp4a.40.29"; | 276 "mp4a.40.05,mp4a.40.29"; |
| 260 static const char kMP4VideoCodecsExpression[] = | 277 static const char kMP4VideoCodecsExpression[] = |
| 261 // This is not a complete list of supported avc1 codecs. It is simply used | 278 // This is not a complete list of supported avc1 codecs. It is simply used |
| 262 // to register support for the corresponding Codec enum. Instead of using | 279 // to register support for the corresponding Codec enum. Instead of using |
| 263 // strings in these three arrays, we should use the Codec enum values. | 280 // strings in these three arrays, we should use the Codec enum values. |
| 264 // This will avoid confusion and unnecessary parsing at runtime. | 281 // This will avoid confusion and unnecessary parsing at runtime. |
| 265 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only | 282 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only |
| 266 // mapping from strings to codecs. See crbug.com/461009. | 283 // mapping from strings to codecs. See crbug.com/461009. |
| 267 "avc1.42E00A,avc1.4D400A,avc1.64000A," | 284 "avc1.42E00A,avc1.4D400A,avc1.64000A," |
| 268 #if defined(ENABLE_HEVC_DEMUXING) | 285 #if defined(ENABLE_HEVC_DEMUXING) |
| 269 // Any valid unambiguous HEVC codec id will work here, since these strings | 286 // Any valid unambiguous HEVC codec id will work here, since these strings |
| 270 // are parsed and mapped to MimeUtil::Codec enum values. | 287 // are parsed and mapped to MimeUtil::Codec enum values. |
| 271 "hev1.1.6.L93.B0," | 288 "hev1.1.6.L93.B0," |
| 272 #endif | 289 #endif |
| 273 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 290 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 291 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
| 292 "ac-3,ec-3," // Note: only one variant of eac codec string is sufficient | |
|
ddorwin
2015/11/25 22:24:08
Here and above, be consistent with existing text a
servolk
2015/12/03 00:56:15
Done.
| |
| 293 // here since these are converted into enums in | |
| 294 // InitializeMimeTypeMaps | |
| 295 #endif | |
| 274 "mp4a.40.05,mp4a.40.29"; | 296 "mp4a.40.05,mp4a.40.29"; |
| 275 | 297 |
| 276 // These containers are also included in | 298 // These containers are also included in |
| 277 // common_media_types/proprietary_media_types. See crbug.com/461012. | 299 // common_media_types/proprietary_media_types. See crbug.com/461012. |
| 278 static const MediaFormatStrict format_codec_mappings[] = { | 300 static const MediaFormatStrict format_codec_mappings[] = { |
| 279 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | 301 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, |
| 280 {"audio/webm", "opus,vorbis"}, | 302 {"audio/webm", "opus,vorbis"}, |
| 281 {"audio/wav", "1"}, | 303 {"audio/wav", "1"}, |
| 282 {"audio/x-wav", "1"}, | 304 {"audio/x-wav", "1"}, |
| 283 // Android does not support Opus in Ogg container. | 305 // Android does not support Opus in Ogg container. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 294 {"audio/mp3", ""}, | 316 {"audio/mp3", ""}, |
| 295 {"audio/x-mp3", ""}, | 317 {"audio/x-mp3", ""}, |
| 296 {"audio/aac", ""}, | 318 {"audio/aac", ""}, |
| 297 {"audio/mp4", kMP4AudioCodecsExpression}, | 319 {"audio/mp4", kMP4AudioCodecsExpression}, |
| 298 {"audio/x-m4a", kMP4AudioCodecsExpression}, | 320 {"audio/x-m4a", kMP4AudioCodecsExpression}, |
| 299 {"video/mp4", kMP4VideoCodecsExpression}, | 321 {"video/mp4", kMP4VideoCodecsExpression}, |
| 300 {"video/x-m4v", kMP4VideoCodecsExpression}, | 322 {"video/x-m4v", kMP4VideoCodecsExpression}, |
| 301 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) | 323 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) |
| 302 {"video/mp2t", kMP4VideoCodecsExpression}, | 324 {"video/mp2t", kMP4VideoCodecsExpression}, |
| 303 #endif | 325 #endif |
| 304 {"application/x-mpegurl", kMP4VideoCodecsExpression}, | 326 {"application/x-mpegurl", kMP4VideoCodecsExpression}, |
|
ddorwin
2015/11/25 22:24:08
Do you want to support this in HLS? The current co
servolk
2015/12/03 00:56:14
HLS is only enabled on Clank/Android, where AC3/EA
| |
| 305 {"application/vnd.apple.mpegurl", kMP4VideoCodecsExpression}}; | 327 {"application/vnd.apple.mpegurl", kMP4VideoCodecsExpression}}; |
| 306 | 328 |
| 307 struct CodecIDMappings { | 329 struct CodecIDMappings { |
| 308 const char* const codec_id; | 330 const char* const codec_id; |
| 309 MimeUtil::Codec codec; | 331 MimeUtil::Codec codec; |
| 310 }; | 332 }; |
| 311 | 333 |
| 312 // List of codec IDs that provide enough information to determine the | 334 // List of codec IDs that provide enough information to determine the |
| 313 // codec and profile being requested. | 335 // codec and profile being requested. |
| 314 // | 336 // |
| 315 // The "mp4a" strings come from RFC 6381. | 337 // The "mp4a" strings come from RFC 6381. |
| 316 static const CodecIDMappings kUnambiguousCodecStringMap[] = { | 338 static const CodecIDMappings kUnambiguousCodecStringMap[] = { |
| 317 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. | 339 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. |
| 318 // avc1/avc3.XXXXXX may be unambiguous; handled by ParseH264CodecID(). | 340 // avc1/avc3.XXXXXX may be unambiguous; handled by ParseH264CodecID(). |
|
ddorwin
2015/11/25 22:24:08
Please add a similar comment for HEVC.
| |
| 319 {"mp3", MimeUtil::MP3}, | 341 {"mp3", MimeUtil::MP3}, |
| 320 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, | 342 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, |
| 321 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, | 343 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, |
| 322 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, | 344 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, |
| 323 {"mp4a.69", MimeUtil::MP3}, | 345 {"mp4a.69", MimeUtil::MP3}, |
| 324 {"mp4a.6B", MimeUtil::MP3}, | 346 {"mp4a.6B", MimeUtil::MP3}, |
| 325 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, | 347 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, |
| 326 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, | 348 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, |
| 327 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, | 349 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, |
| 328 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, | 350 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, |
| 329 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, | 351 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, |
| 352 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
| 353 {"ac-3", MimeUtil::AC3}, | |
| 354 {"ec-3", MimeUtil::EAC3}, | |
|
ddorwin
2015/11/25 22:24:07
group the codecs together
servolk
2015/12/03 00:56:15
Done.
| |
| 355 {"mp4a.a5", MimeUtil::AC3}, | |
| 356 {"mp4a.A5", MimeUtil::AC3}, | |
|
ddorwin
2015/11/25 22:24:08
Why both cases? Is one not "correct?" With everyth
servolk
2015/12/03 00:56:15
I've copied the comment from the unit test that re
| |
| 357 {"mp4a.a6", MimeUtil::EAC3}, | |
| 358 {"mp4a.A6", MimeUtil::EAC3}, | |
| 359 #endif | |
| 330 {"vorbis", MimeUtil::VORBIS}, | 360 {"vorbis", MimeUtil::VORBIS}, |
| 331 {"opus", MimeUtil::OPUS}, | 361 {"opus", MimeUtil::OPUS}, |
| 332 {"vp8", MimeUtil::VP8}, | 362 {"vp8", MimeUtil::VP8}, |
| 333 {"vp8.0", MimeUtil::VP8}, | 363 {"vp8.0", MimeUtil::VP8}, |
| 334 {"vp9", MimeUtil::VP9}, | 364 {"vp9", MimeUtil::VP9}, |
| 335 {"vp9.0", MimeUtil::VP9}, | 365 {"vp9.0", MimeUtil::VP9}, |
| 336 {"theora", MimeUtil::THEORA}}; | 366 {"theora", MimeUtil::THEORA}}; |
| 337 | 367 |
| 338 // List of codec IDs that are ambiguous and don't provide | 368 // List of codec IDs that are ambiguous and don't provide |
| 339 // enough information to determine the codec and profile. | 369 // enough information to determine the codec and profile. |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 #if defined(OS_ANDROID) | 719 #if defined(OS_ANDROID) |
| 690 if (!IsCodecSupportedOnAndroid(codec)) | 720 if (!IsCodecSupportedOnAndroid(codec)) |
| 691 return false; | 721 return false; |
| 692 #endif | 722 #endif |
| 693 | 723 |
| 694 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 724 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
| 695 } | 725 } |
| 696 | 726 |
| 697 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 727 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
| 698 switch (codec) { | 728 switch (codec) { |
| 729 #if defined(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | |
|
ddorwin
2015/11/25 22:24:08
ditto and match order of enum.
servolk
2015/12/03 00:56:15
Done.
| |
| 730 case AC3: | |
| 731 case EAC3: | |
| 732 #endif | |
| 699 case INVALID_CODEC: | 733 case INVALID_CODEC: |
| 700 case MP3: | 734 case MP3: |
| 701 case MPEG2_AAC_LC: | 735 case MPEG2_AAC_LC: |
| 702 case MPEG2_AAC_MAIN: | 736 case MPEG2_AAC_MAIN: |
| 703 case MPEG2_AAC_SSR: | 737 case MPEG2_AAC_SSR: |
| 704 case MPEG4_AAC_LC: | 738 case MPEG4_AAC_LC: |
| 705 case MPEG4_AAC_SBR_v1: | 739 case MPEG4_AAC_SBR_v1: |
| 706 case MPEG4_AAC_SBR_PS_v2: | 740 case MPEG4_AAC_SBR_PS_v2: |
| 707 case H264_BASELINE: | 741 case H264_BASELINE: |
| 708 case H264_MAIN: | 742 case H264_MAIN: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 std::vector<std::string>* codecs_out, | 804 std::vector<std::string>* codecs_out, |
| 771 const bool strip) { | 805 const bool strip) { |
| 772 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 806 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
| 773 } | 807 } |
| 774 | 808 |
| 775 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 809 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
| 776 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 810 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
| 777 } | 811 } |
| 778 | 812 |
| 779 } // namespace media | 813 } // namespace media |
| OLD | NEW |