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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 *codec = MimeUtil::H264_BASELINE; | 548 *codec = MimeUtil::H264_BASELINE; |
534 *is_ambiguous = true; | 549 *is_ambiguous = true; |
535 return true; | 550 return true; |
536 } | 551 } |
537 | 552 |
538 // Validate level. | 553 // Validate level. |
539 *is_ambiguous = !IsValidH264Level(base::ToUpperASCII(codec_id.substr(9))); | 554 *is_ambiguous = !IsValidH264Level(base::ToUpperASCII(codec_id.substr(9))); |
540 return true; | 555 return true; |
541 } | 556 } |
542 | 557 |
558 #if defined(ENABLE_HEVC_DEMUXING) | |
559 // ISO/IEC FDIS 14496-15 standard section E.3 describes the syntax of codec ids | |
560 // reserved for HEVC. According to that spec HEVC codec id must start with | |
561 // either "hev1." or "hvc1.". We don't yet support full parsing of HEVC codec | |
562 // ids, but since no other codec id starts with those string we'll just treat | |
563 // any string starting with "hev1." or "hvc1." as valid HEVC codec ids. | |
564 // crbug.com/482761 | |
565 static bool ParseHEVCCodecID(const std::string& codec_id, | |
566 MimeUtil::Codec* codec, | |
567 bool* is_ambiguous) { | |
568 if (base::StartsWith(codec_id, "hev1.", base::CompareCase::SENSITIVE) || | |
569 base::StartsWith(codec_id, "hvc1.", base::CompareCase::SENSITIVE)) { | |
570 *codec = MimeUtil::HEVC_MAIN; | |
571 | |
572 // TODO(servolk): Full HEVC codec id parsing is not implemented yet (see | |
573 // crbug.com/482761). So treat HEVC codec ids as ambiguous for now. | |
574 *is_ambiguous = true; | |
575 | |
576 // TODO(servolk): Most HEVC codec ids are treated as ambiguous (see above), | |
577 // but we need to recognize at least one valid unambiguous HEVC codec id, | |
578 // which is added into kMP4VideoCodecsExpression. We need it to be | |
579 // unambiguous to avoid DCHECK(!is_ambiguous) in InitializeMimeTypeMaps. We | |
580 // also use these in unit tests (see | |
581 // content/browser/media/media_canplaytype_browsertest.cc). | |
582 // Remove this workaround after crbug.com/482761 is fixed. | |
583 if (codec_id == "hev1.1.6.L93.B0" || codec_id == "hvc1.1.6.L93.B0") { | |
584 *is_ambiguous = false; | |
585 } | |
586 | |
587 return true; | |
588 } | |
589 | |
590 return false; | |
591 } | |
592 #endif | |
593 | |
543 bool MimeUtil::StringToCodec(const std::string& codec_id, | 594 bool MimeUtil::StringToCodec(const std::string& codec_id, |
544 Codec* codec, | 595 Codec* codec, |
545 bool* is_ambiguous) const { | 596 bool* is_ambiguous) const { |
546 StringToCodecMappings::const_iterator itr = | 597 StringToCodecMappings::const_iterator itr = |
547 string_to_codec_map_.find(codec_id); | 598 string_to_codec_map_.find(codec_id); |
548 if (itr != string_to_codec_map_.end()) { | 599 if (itr != string_to_codec_map_.end()) { |
549 *codec = itr->second.codec; | 600 *codec = itr->second.codec; |
550 *is_ambiguous = itr->second.is_ambiguous; | 601 *is_ambiguous = itr->second.is_ambiguous; |
551 return true; | 602 return true; |
552 } | 603 } |
553 | 604 |
554 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | 605 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
555 // an H.264 codec ID because currently those are the only ones that can't be | 606 // either H.264 or HEVC/H.265 codec ID because currently those are the only |
556 // stored in the |string_to_codec_map_| and require parsing. | 607 // ones that are not added to the |string_to_codec_map_| and require parsing. |
608 #if defined(ENABLE_HEVC_DEMUXING) | |
wolenetz
2015/09/02 20:43:18
nit: move the condition start prior to the comment
servolk
2015/09/03 00:17:51
But this comment talks about both H.264 and HEVC.
| |
609 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | |
610 return true; | |
611 } | |
612 #endif | |
557 return ParseH264CodecID(codec_id, codec, is_ambiguous); | 613 return ParseH264CodecID(codec_id, codec, is_ambiguous); |
558 } | 614 } |
559 | 615 |
560 bool MimeUtil::IsCodecSupported(Codec codec) const { | 616 bool MimeUtil::IsCodecSupported(Codec codec) const { |
561 DCHECK_NE(codec, INVALID_CODEC); | 617 DCHECK_NE(codec, INVALID_CODEC); |
562 | 618 |
563 #if defined(OS_ANDROID) | 619 #if defined(OS_ANDROID) |
564 if (!IsCodecSupportedOnAndroid(codec)) | 620 if (!IsCodecSupportedOnAndroid(codec)) |
565 return false; | 621 return false; |
566 #endif | 622 #endif |
567 | 623 |
568 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 624 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
569 } | 625 } |
570 | 626 |
571 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 627 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
572 switch (codec) { | 628 switch (codec) { |
573 case INVALID_CODEC: | 629 case INVALID_CODEC: |
574 case MP3: | 630 case MP3: |
575 case MPEG2_AAC_LC: | 631 case MPEG2_AAC_LC: |
576 case MPEG2_AAC_MAIN: | 632 case MPEG2_AAC_MAIN: |
577 case MPEG2_AAC_SSR: | 633 case MPEG2_AAC_SSR: |
578 case MPEG4_AAC_LC: | 634 case MPEG4_AAC_LC: |
579 case MPEG4_AAC_SBR_v1: | 635 case MPEG4_AAC_SBR_v1: |
580 case MPEG4_AAC_SBR_PS_v2: | 636 case MPEG4_AAC_SBR_PS_v2: |
581 case H264_BASELINE: | 637 case H264_BASELINE: |
582 case H264_MAIN: | 638 case H264_MAIN: |
583 case H264_HIGH: | 639 case H264_HIGH: |
640 case HEVC_MAIN: | |
584 return true; | 641 return true; |
585 | 642 |
586 case PCM: | 643 case PCM: |
587 case VORBIS: | 644 case VORBIS: |
588 case OPUS: | 645 case OPUS: |
589 case VP8: | 646 case VP8: |
590 case VP9: | 647 case VP9: |
591 case THEORA: | 648 case THEORA: |
592 return false; | 649 return false; |
593 } | 650 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 std::vector<std::string>* codecs_out, | 695 std::vector<std::string>* codecs_out, |
639 const bool strip) { | 696 const bool strip) { |
640 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 697 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
641 } | 698 } |
642 | 699 |
643 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 700 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
644 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 701 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
645 } | 702 } |
646 | 703 |
647 } // namespace media | 704 } // namespace media |
OLD | NEW |