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 18 matching lines...) Expand all Loading... | |
29 MPEG2_AAC_MAIN, | 29 MPEG2_AAC_MAIN, |
30 MPEG2_AAC_SSR, | 30 MPEG2_AAC_SSR, |
31 MPEG4_AAC_LC, | 31 MPEG4_AAC_LC, |
32 MPEG4_AAC_SBR_v1, | 32 MPEG4_AAC_SBR_v1, |
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 VP8, | 40 VP8, |
40 VP9, | 41 VP9, |
41 THEORA | 42 THEORA |
42 }; | 43 }; |
43 | 44 |
44 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | 45 bool IsSupportedMediaMimeType(const std::string& mime_type) const; |
45 | 46 |
46 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; | 47 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; |
47 | 48 |
48 void ParseCodecString(const std::string& codecs, | 49 void ParseCodecString(const std::string& codecs, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 case MimeUtil::MPEG4_AAC_LC: | 193 case MimeUtil::MPEG4_AAC_LC: |
193 case MimeUtil::MPEG4_AAC_SBR_v1: | 194 case MimeUtil::MPEG4_AAC_SBR_v1: |
194 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | 195 case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
195 case MimeUtil::H264_BASELINE: | 196 case MimeUtil::H264_BASELINE: |
196 case MimeUtil::H264_MAIN: | 197 case MimeUtil::H264_MAIN: |
197 case MimeUtil::H264_HIGH: | 198 case MimeUtil::H264_HIGH: |
198 case MimeUtil::VP8: | 199 case MimeUtil::VP8: |
199 case MimeUtil::VORBIS: | 200 case MimeUtil::VORBIS: |
200 return true; | 201 return true; |
201 | 202 |
203 case MimeUtil::HEVC_MAIN: | |
204 #if defined(ENABLE_HEVC_DEMUXING) | |
205 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to | |
206 // http://developer.android.com/reference/android/media/MediaFormat.html | |
207 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | |
208 #else | |
209 return false; | |
210 #endif | |
211 | |
202 case MimeUtil::MPEG2_AAC_LC: | 212 case MimeUtil::MPEG2_AAC_LC: |
203 case MimeUtil::MPEG2_AAC_MAIN: | 213 case MimeUtil::MPEG2_AAC_MAIN: |
204 case MimeUtil::MPEG2_AAC_SSR: | 214 case MimeUtil::MPEG2_AAC_SSR: |
205 // MPEG-2 variants of AAC are not supported on Android. | 215 // MPEG-2 variants of AAC are not supported on Android. |
206 return false; | 216 return false; |
207 | 217 |
208 case MimeUtil::VP9: | 218 case MimeUtil::VP9: |
209 // VP9 is supported only in KitKat+ (API Level 19). | 219 // VP9 is supported only in KitKat+ (API Level 19). |
210 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 220 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; |
211 | 221 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 256 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
247 "mp4a.40.05,mp4a.40.29"; | 257 "mp4a.40.05,mp4a.40.29"; |
248 static const char kMP4VideoCodecsExpression[] = | 258 static const char kMP4VideoCodecsExpression[] = |
249 // This is not a complete list of supported avc1 codecs. It is simply used | 259 // This is not a complete list of supported avc1 codecs. It is simply used |
250 // to register support for the corresponding Codec enum. Instead of using | 260 // to register support for the corresponding Codec enum. Instead of using |
251 // strings in these three arrays, we should use the Codec enum values. | 261 // strings in these three arrays, we should use the Codec enum values. |
252 // This will avoid confusion and unnecessary parsing at runtime. | 262 // This will avoid confusion and unnecessary parsing at runtime. |
253 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only | 263 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only |
254 // mapping from strings to codecs. See crbug.com/461009. | 264 // mapping from strings to codecs. See crbug.com/461009. |
255 "avc1.42E00A,avc1.4D400A,avc1.64000A," | 265 "avc1.42E00A,avc1.4D400A,avc1.64000A," |
266 #if defined(ENABLE_HEVC_DEMUXING) | |
267 // Any valid unambiguous HEVC codec id will work here, since these strings | |
268 // are parsed and mapped to MimeUtil::Codec enum values. | |
269 "hev1.1.6.L93.B0," | |
270 #endif | |
256 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 271 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
257 "mp4a.40.05,mp4a.40.29"; | 272 "mp4a.40.05,mp4a.40.29"; |
258 | 273 |
259 // These containers are also included in | 274 // These containers are also included in |
260 // common_media_types/proprietary_media_types. See crbug.com/461012. | 275 // common_media_types/proprietary_media_types. See crbug.com/461012. |
261 static const MediaFormatStrict format_codec_mappings[] = { | 276 static const MediaFormatStrict format_codec_mappings[] = { |
262 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | 277 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, |
263 {"audio/webm", "opus,vorbis"}, | 278 {"audio/webm", "opus,vorbis"}, |
264 {"audio/wav", "1"}, | 279 {"audio/wav", "1"}, |
265 {"audio/x-wav", "1"}, | 280 {"audio/x-wav", "1"}, |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 *codec = MimeUtil::H264_BASELINE; | 570 *codec = MimeUtil::H264_BASELINE; |
556 *is_ambiguous = true; | 571 *is_ambiguous = true; |
557 return true; | 572 return true; |
558 } | 573 } |
559 | 574 |
560 *is_ambiguous = | 575 *is_ambiguous = |
561 !IsValidH264Level(base::StringToUpperASCII(codec_id.substr(9))); | 576 !IsValidH264Level(base::StringToUpperASCII(codec_id.substr(9))); |
562 return true; | 577 return true; |
563 } | 578 } |
564 | 579 |
580 #if defined(ENABLE_HEVC_DEMUXING) | |
581 // HEVC/H.265 is a new video codec, evolution of the H.264/AVC standard. ISO/IEC | |
ddorwin
2015/06/20 00:28:21
I don't think the first sentence is relevant.
servolk
2015/06/25 23:02:09
Done.
| |
582 // FDIS 14496-15 standard section E.3 describes the syntax of codec ids | |
583 // reserved for HEVC. According to that spec HEVC codec id must start with | |
584 // either "hev1." or "hvc1.". We don't yet support full parsing of HEVC codec | |
585 // ids, but since no other codec id starts with those string we'll just treat | |
586 // any string starting with "hev1." or "hvc1." as valid HEVC codec ids. | |
587 // crbug.com/482761 | |
588 static bool ParseHEVCCodecID(const std::string& codec_id, | |
589 MimeUtil::Codec* codec, | |
590 bool* is_ambiguous) { | |
591 if (base::StartsWithASCII(codec_id, "hev1.", true) || | |
592 base::StartsWithASCII(codec_id, "hvc1.", true)) { | |
593 *codec = MimeUtil::HEVC_MAIN; | |
594 *is_ambiguous = true; | |
ddorwin
2015/06/20 00:28:21
This line should be below the TODO, since it would
servolk
2015/06/25 23:02:09
Done.
| |
595 | |
596 // TODO(servolk): Full HEVC codec id parsing is not implemented yet (see | |
597 // crbug.com/482761), but we need to recognize at least one valid | |
598 // unambiguous HEVC codec id, which is added kMP4VideoCodecsExpression. We | |
599 // need it to be unambiguous to avoid DCHECK at line 405. We also use these | |
600 // in unit tests. Remove this workaround after crbug.com/482761 is fixed. | |
601 if (codec_id == "hev1.1.6.L93.B0" || codec_id == "hvc1.1.6.L93.B0") { | |
602 *is_ambiguous = false; | |
603 } | |
604 | |
605 return true; | |
606 } | |
607 | |
608 return false; | |
609 } | |
610 #endif | |
611 | |
565 bool MimeUtil::StringToCodec(const std::string& codec_id, | 612 bool MimeUtil::StringToCodec(const std::string& codec_id, |
566 Codec* codec, | 613 Codec* codec, |
567 bool* is_ambiguous) const { | 614 bool* is_ambiguous) const { |
568 StringToCodecMappings::const_iterator itr = | 615 StringToCodecMappings::const_iterator itr = |
569 string_to_codec_map_.find(codec_id); | 616 string_to_codec_map_.find(codec_id); |
570 if (itr != string_to_codec_map_.end()) { | 617 if (itr != string_to_codec_map_.end()) { |
571 *codec = itr->second.codec; | 618 *codec = itr->second.codec; |
572 *is_ambiguous = itr->second.is_ambiguous; | 619 *is_ambiguous = itr->second.is_ambiguous; |
573 return true; | 620 return true; |
574 } | 621 } |
575 | 622 |
576 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | 623 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
577 // an H.264 codec ID because currently those are the only ones that can't be | 624 // either H.264 or HEVC/H.265 codec ID because currently those are the only |
578 // stored in the |string_to_codec_map_| and require parsing. | 625 // ones that are not added to the |string_to_codec_map_| and require parsing. |
626 #if defined(ENABLE_HEVC_DEMUXING) | |
627 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | |
628 return true; | |
629 } | |
630 #endif | |
579 return ParseH264CodecID(codec_id, codec, is_ambiguous); | 631 return ParseH264CodecID(codec_id, codec, is_ambiguous); |
580 } | 632 } |
581 | 633 |
582 bool MimeUtil::IsCodecSupported(Codec codec) const { | 634 bool MimeUtil::IsCodecSupported(Codec codec) const { |
583 DCHECK_NE(codec, INVALID_CODEC); | 635 DCHECK_NE(codec, INVALID_CODEC); |
584 | 636 |
585 #if defined(OS_ANDROID) | 637 #if defined(OS_ANDROID) |
586 if (!IsCodecSupportedOnAndroid(codec)) | 638 if (!IsCodecSupportedOnAndroid(codec)) |
587 return false; | 639 return false; |
588 #endif | 640 #endif |
589 | 641 |
590 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 642 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
591 } | 643 } |
592 | 644 |
593 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 645 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
594 switch (codec) { | 646 switch (codec) { |
595 case INVALID_CODEC: | 647 case INVALID_CODEC: |
596 case MP3: | 648 case MP3: |
597 case MPEG2_AAC_LC: | 649 case MPEG2_AAC_LC: |
598 case MPEG2_AAC_MAIN: | 650 case MPEG2_AAC_MAIN: |
599 case MPEG2_AAC_SSR: | 651 case MPEG2_AAC_SSR: |
600 case MPEG4_AAC_LC: | 652 case MPEG4_AAC_LC: |
601 case MPEG4_AAC_SBR_v1: | 653 case MPEG4_AAC_SBR_v1: |
602 case MPEG4_AAC_SBR_PS_v2: | 654 case MPEG4_AAC_SBR_PS_v2: |
603 case H264_BASELINE: | 655 case H264_BASELINE: |
604 case H264_MAIN: | 656 case H264_MAIN: |
605 case H264_HIGH: | 657 case H264_HIGH: |
658 case HEVC_MAIN: | |
606 return true; | 659 return true; |
607 | 660 |
608 case PCM: | 661 case PCM: |
609 case VORBIS: | 662 case VORBIS: |
610 case OPUS: | 663 case OPUS: |
611 case VP8: | 664 case VP8: |
612 case VP9: | 665 case VP9: |
613 case THEORA: | 666 case THEORA: |
614 return false; | 667 return false; |
615 } | 668 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 std::vector<std::string>* codecs_out, | 713 std::vector<std::string>* codecs_out, |
661 const bool strip) { | 714 const bool strip) { |
662 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 715 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
663 } | 716 } |
664 | 717 |
665 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 718 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
666 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 719 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
667 } | 720 } |
668 | 721 |
669 } // namespace media | 722 } // namespace media |
OLD | NEW |