| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 // Singleton utility class for mime types. | 26 // Singleton utility class for mime types. |
| 27 class MimeUtil { | 27 class MimeUtil { |
| 28 public: | 28 public: |
| 29 enum Codec { | 29 enum Codec { |
| 30 INVALID_CODEC, | 30 INVALID_CODEC, |
| 31 PCM, | 31 PCM, |
| 32 MP3, | 32 MP3, |
| 33 AC3, |
| 34 EAC3, |
| 33 MPEG2_AAC_LC, | 35 MPEG2_AAC_LC, |
| 34 MPEG2_AAC_MAIN, | 36 MPEG2_AAC_MAIN, |
| 35 MPEG2_AAC_SSR, | 37 MPEG2_AAC_SSR, |
| 36 MPEG4_AAC_LC, | 38 MPEG4_AAC_LC, |
| 37 MPEG4_AAC_SBR_v1, | 39 MPEG4_AAC_SBR_v1, |
| 38 MPEG4_AAC_SBR_PS_v2, | 40 MPEG4_AAC_SBR_PS_v2, |
| 39 VORBIS, | 41 VORBIS, |
| 40 OPUS, | 42 OPUS, |
| 41 H264_BASELINE, | 43 H264_BASELINE, |
| 42 H264_MAIN, | 44 H264_MAIN, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 case MimeUtil::MPEG4_AAC_LC: | 147 case MimeUtil::MPEG4_AAC_LC: |
| 146 case MimeUtil::MPEG4_AAC_SBR_v1: | 148 case MimeUtil::MPEG4_AAC_SBR_v1: |
| 147 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | 149 case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
| 148 case MimeUtil::VORBIS: | 150 case MimeUtil::VORBIS: |
| 149 case MimeUtil::H264_BASELINE: | 151 case MimeUtil::H264_BASELINE: |
| 150 case MimeUtil::H264_MAIN: | 152 case MimeUtil::H264_MAIN: |
| 151 case MimeUtil::H264_HIGH: | 153 case MimeUtil::H264_HIGH: |
| 152 case MimeUtil::VP8: | 154 case MimeUtil::VP8: |
| 153 return true; | 155 return true; |
| 154 | 156 |
| 157 case MimeUtil::AC3: |
| 158 case MimeUtil::EAC3: |
| 159 // TODO(servolk): Revisit this for AC3/EAC3 support on AndroidTV |
| 160 return false; |
| 161 |
| 155 case MimeUtil::MPEG2_AAC_LC: | 162 case MimeUtil::MPEG2_AAC_LC: |
| 156 case MimeUtil::MPEG2_AAC_MAIN: | 163 case MimeUtil::MPEG2_AAC_MAIN: |
| 157 case MimeUtil::MPEG2_AAC_SSR: | 164 case MimeUtil::MPEG2_AAC_SSR: |
| 158 // MPEG-2 variants of AAC are not supported on Android. | 165 // MPEG-2 variants of AAC are not supported on Android. |
| 159 return false; | 166 return false; |
| 160 | 167 |
| 161 case MimeUtil::OPUS: | 168 case MimeUtil::OPUS: |
| 162 // Opus is supported only in Lollipop+ (API Level 21). | 169 // Opus is supported only in Lollipop+ (API Level 21). |
| 163 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 170 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
| 164 | 171 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) | 210 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) |
| 204 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for | 211 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for |
| 205 // compatibility) | 212 // compatibility) |
| 206 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) | 213 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) |
| 207 // | 214 // |
| 208 // avc1.42E0xx - H.264 Baseline | 215 // avc1.42E0xx - H.264 Baseline |
| 209 // avc1.4D40xx - H.264 Main | 216 // avc1.4D40xx - H.264 Main |
| 210 // avc1.6400xx - H.264 High | 217 // avc1.6400xx - H.264 High |
| 211 static const char kMP4AudioCodecsExpression[] = | 218 static const char kMP4AudioCodecsExpression[] = |
| 212 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 219 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 220 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 221 // Only one variant each of ac3 and eac3 codec string is sufficient here, |
| 222 // since these strings are parsed and mapped to MimeUtil::Codec enum values. |
| 223 "ac-3,ec-3," |
| 224 #endif |
| 213 "mp4a.40.05,mp4a.40.29"; | 225 "mp4a.40.05,mp4a.40.29"; |
| 214 static const char kMP4VideoCodecsExpression[] = | 226 static const char kMP4VideoCodecsExpression[] = |
| 215 // This is not a complete list of supported avc1 codecs. It is simply used | 227 // This is not a complete list of supported avc1 codecs. It is simply used |
| 216 // to register support for the corresponding Codec enum. Instead of using | 228 // to register support for the corresponding Codec enum. Instead of using |
| 217 // strings in these three arrays, we should use the Codec enum values. | 229 // strings in these three arrays, we should use the Codec enum values. |
| 218 // This will avoid confusion and unnecessary parsing at runtime. | 230 // This will avoid confusion and unnecessary parsing at runtime. |
| 219 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only | 231 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only |
| 220 // mapping from strings to codecs. See crbug.com/461009. | 232 // mapping from strings to codecs. See crbug.com/461009. |
| 221 "avc1.42E00A,avc1.4D400A,avc1.64000A," | 233 "avc1.42E00A,avc1.4D400A,avc1.64000A," |
| 222 #if defined(ENABLE_HEVC_DEMUXING) | 234 #if defined(ENABLE_HEVC_DEMUXING) |
| 223 // Any valid unambiguous HEVC codec id will work here, since these strings | 235 // Any valid unambiguous HEVC codec id will work here, since these strings |
| 224 // are parsed and mapped to MimeUtil::Codec enum values. | 236 // are parsed and mapped to MimeUtil::Codec enum values. |
| 225 "hev1.1.6.L93.B0," | 237 "hev1.1.6.L93.B0," |
| 226 #endif | 238 #endif |
| 227 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 239 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 240 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 241 // Only one variant each of ac3 and eac3 codec string is sufficient here, |
| 242 // since these strings are parsed and mapped to MimeUtil::Codec enum values. |
| 243 "ac-3,ec-3," |
| 244 #endif |
| 228 "mp4a.40.05,mp4a.40.29"; | 245 "mp4a.40.05,mp4a.40.29"; |
| 229 #endif // USE_PROPRIETARY_CODECS | 246 #endif // USE_PROPRIETARY_CODECS |
| 230 | 247 |
| 231 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and | 248 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and |
| 232 // corresponding media codecs supported by these types/containers. | 249 // corresponding media codecs supported by these types/containers. |
| 233 // Media formats marked as PROPRIETARY are not supported by Chromium, only | 250 // Media formats marked as PROPRIETARY are not supported by Chromium, only |
| 234 // Google Chrome browser supports them. | 251 // Google Chrome browser supports them. |
| 235 static const MediaFormat kFormatCodecMappings[] = { | 252 static const MediaFormat kFormatCodecMappings[] = { |
| 236 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | 253 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, |
| 237 {"audio/webm", COMMON, "opus,vorbis"}, | 254 {"audio/webm", COMMON, "opus,vorbis"}, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, | 301 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, |
| 285 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, | 302 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, |
| 286 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, | 303 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, |
| 287 {"mp4a.69", MimeUtil::MP3}, | 304 {"mp4a.69", MimeUtil::MP3}, |
| 288 {"mp4a.6B", MimeUtil::MP3}, | 305 {"mp4a.6B", MimeUtil::MP3}, |
| 289 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, | 306 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, |
| 290 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, | 307 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, |
| 291 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, | 308 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, |
| 292 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, | 309 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, |
| 293 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, | 310 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, |
| 311 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 312 // TODO(servolk): Strictly speaking only mp4a.A5 and mp4a.A6 codec ids are |
| 313 // valid according to RFC 6381 section 3.3, 3.4. Lower-case oti (mp4a.a5 and |
| 314 // mp4a.a6) should be rejected. But we used to allow those in older versions |
| 315 // of Chromecast firmware and some apps (notably MPL) depend on those codec |
| 316 // types being supported, so they should be allowed for now |
| 317 // (crbug.com/564960). |
| 318 {"ac-3", MimeUtil::AC3}, |
| 319 {"mp4a.a5", MimeUtil::AC3}, |
| 320 {"mp4a.A5", MimeUtil::AC3}, |
| 321 {"ec-3", MimeUtil::EAC3}, |
| 322 {"mp4a.a6", MimeUtil::EAC3}, |
| 323 {"mp4a.A6", MimeUtil::EAC3}, |
| 324 #endif |
| 294 {"vorbis", MimeUtil::VORBIS}, | 325 {"vorbis", MimeUtil::VORBIS}, |
| 295 {"opus", MimeUtil::OPUS}, | 326 {"opus", MimeUtil::OPUS}, |
| 296 {"vp8", MimeUtil::VP8}, | 327 {"vp8", MimeUtil::VP8}, |
| 297 {"vp8.0", MimeUtil::VP8}, | 328 {"vp8.0", MimeUtil::VP8}, |
| 298 {"vp9", MimeUtil::VP9}, | 329 {"vp9", MimeUtil::VP9}, |
| 299 {"vp9.0", MimeUtil::VP9}, | 330 {"vp9.0", MimeUtil::VP9}, |
| 300 {"theora", MimeUtil::THEORA}}; | 331 {"theora", MimeUtil::THEORA}}; |
| 301 | 332 |
| 302 // List of codec IDs that are ambiguous and don't provide | 333 // List of codec IDs that are ambiguous and don't provide |
| 303 // enough information to determine the codec and profile. | 334 // enough information to determine the codec and profile. |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 if (!IsCodecSupportedOnAndroid(codec)) | 662 if (!IsCodecSupportedOnAndroid(codec)) |
| 632 return false; | 663 return false; |
| 633 #endif | 664 #endif |
| 634 | 665 |
| 635 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 666 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
| 636 } | 667 } |
| 637 | 668 |
| 638 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 669 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
| 639 switch (codec) { | 670 switch (codec) { |
| 640 case INVALID_CODEC: | 671 case INVALID_CODEC: |
| 672 case AC3: |
| 673 case EAC3: |
| 641 case MP3: | 674 case MP3: |
| 642 case MPEG2_AAC_LC: | 675 case MPEG2_AAC_LC: |
| 643 case MPEG2_AAC_MAIN: | 676 case MPEG2_AAC_MAIN: |
| 644 case MPEG2_AAC_SSR: | 677 case MPEG2_AAC_SSR: |
| 645 case MPEG4_AAC_LC: | 678 case MPEG4_AAC_LC: |
| 646 case MPEG4_AAC_SBR_v1: | 679 case MPEG4_AAC_SBR_v1: |
| 647 case MPEG4_AAC_SBR_PS_v2: | 680 case MPEG4_AAC_SBR_PS_v2: |
| 648 case H264_BASELINE: | 681 case H264_BASELINE: |
| 649 case H264_MAIN: | 682 case H264_MAIN: |
| 650 case H264_HIGH: | 683 case H264_HIGH: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 std::vector<std::string>* codecs_out, | 734 std::vector<std::string>* codecs_out, |
| 702 const bool strip) { | 735 const bool strip) { |
| 703 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 736 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
| 704 } | 737 } |
| 705 | 738 |
| 706 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 739 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
| 707 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 740 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
| 708 } | 741 } |
| 709 | 742 |
| 710 } // namespace media | 743 } // namespace media |
| OLD | NEW |