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, | |
ddorwin
2015/06/12 00:52:26
Is there a reason that "HEVC" is used instead of "
ddorwin
2015/06/12 00:52:26
Are there HEVC profiles other than main? Is that t
servolk
2015/06/12 21:57:31
There are 3 HEVC v1 profiles: main, main10 and mai
servolk
2015/06/12 21:57:31
Re this and your other comments on HEVC/H265. As f
| |
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 only in Lollipop+ (API Level 21). According to | |
ddorwin
2015/06/12 00:52:26
nit: remove "only"
s/. According/ according/
servolk
2015/06/12 21:57:31
Done.
| |
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-looking HEVC string will work here, since these strings are | |
268 // parsed and mapped to MimeUtil::Codec enum values. | |
269 "hvc1.1.L0.0," | |
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 std::vector<std::string> mime_type_codecs; | 395 std::vector<std::string> mime_type_codecs; |
381 ParseCodecString(format_codec_mappings[i].codecs_list, | 396 ParseCodecString(format_codec_mappings[i].codecs_list, |
382 &mime_type_codecs, | 397 &mime_type_codecs, |
383 false); | 398 false); |
384 | 399 |
385 CodecSet codecs; | 400 CodecSet codecs; |
386 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { | 401 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
387 Codec codec = INVALID_CODEC; | 402 Codec codec = INVALID_CODEC; |
388 bool is_ambiguous = true; | 403 bool is_ambiguous = true; |
389 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); | 404 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); |
390 DCHECK(!is_ambiguous); | 405 DCHECK(!is_ambiguous); |
ddorwin
2015/06/12 00:52:26
Perhaps we can temporarily add (|| codec == HEVC_M
| |
391 codecs.insert(codec); | 406 codecs.insert(codec); |
392 } | 407 } |
393 | 408 |
394 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | 409 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; |
395 } | 410 } |
396 } | 411 } |
397 | 412 |
398 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 413 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
399 return media_map_.find(base::StringToLowerASCII(mime_type)) != | 414 return media_map_.find(base::StringToLowerASCII(mime_type)) != |
400 media_map_.end(); | 415 media_map_.end(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 } else { | 569 } else { |
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 = !IsValidH264Level(StringToUpperASCII(codec_id.substr(9))); | 575 *is_ambiguous = !IsValidH264Level(StringToUpperASCII(codec_id.substr(9))); |
561 return true; | 576 return true; |
562 } | 577 } |
563 | 578 |
579 #if defined(ENABLE_HEVC_DEMUXING) | |
580 static bool ParseHEVCCodecID(const std::string& codec_id, | |
581 MimeUtil::Codec* codec, | |
582 bool* is_ambiguous) { | |
583 if (StartsWithASCII(codec_id, "hev1.", true) || | |
584 StartsWithASCII(codec_id, "hvc1.", true)) { | |
585 // TODO(servolk): Implement parsing of hevc codec ids as described in | |
586 // ETSI TS 126 244 standard section A.2.2, but for now allow any | |
587 // HEVC tiers/profiles and let decoder decide if it can handle that. | |
588 // crbug.com/482761 | |
589 *codec = MimeUtil::HEVC_MAIN; | |
590 // Make this false for now to avoid dcheck at line 696 | |
591 *is_ambiguous = false; | |
ddorwin
2015/06/12 00:52:26
This isn't correct. I know it prevents the DCHECK,
servolk
2015/06/12 21:57:31
Ok, I've added a special case in this method, to e
| |
592 return true; | |
593 } | |
594 | |
595 return false; | |
596 } | |
597 #endif | |
598 | |
564 bool MimeUtil::StringToCodec(const std::string& codec_id, | 599 bool MimeUtil::StringToCodec(const std::string& codec_id, |
565 Codec* codec, | 600 Codec* codec, |
566 bool* is_ambiguous) const { | 601 bool* is_ambiguous) const { |
567 StringToCodecMappings::const_iterator itr = | 602 StringToCodecMappings::const_iterator itr = |
568 string_to_codec_map_.find(codec_id); | 603 string_to_codec_map_.find(codec_id); |
569 if (itr != string_to_codec_map_.end()) { | 604 if (itr != string_to_codec_map_.end()) { |
570 *codec = itr->second.codec; | 605 *codec = itr->second.codec; |
571 *is_ambiguous = itr->second.is_ambiguous; | 606 *is_ambiguous = itr->second.is_ambiguous; |
572 return true; | 607 return true; |
573 } | 608 } |
574 | 609 |
575 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | 610 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
576 // an H.264 codec ID because currently those are the only ones that can't be | 611 // either H.264 or HEVC/H.265 codec ID because currently those are the only |
ddorwin
2015/06/12 00:52:26
ditto on mixing synonyms for the codecs. Also, why
servolk
2015/06/12 21:57:31
See above - yes, people would understand, but ment
| |
577 // stored in the |string_to_codec_map_| and require parsing. | 612 // ones that are not added to the |string_to_codec_map_| and require parsing. |
613 #if defined(ENABLE_HEVC_DEMUXING) | |
614 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | |
ddorwin
2015/06/12 00:52:26
Note: It seems wrong to check the less common code
servolk
2015/06/12 21:57:31
Acknowledged.
| |
615 return true; | |
616 } | |
617 #endif | |
578 return ParseH264CodecID(codec_id, codec, is_ambiguous); | 618 return ParseH264CodecID(codec_id, codec, is_ambiguous); |
579 } | 619 } |
580 | 620 |
581 bool MimeUtil::IsCodecSupported(Codec codec) const { | 621 bool MimeUtil::IsCodecSupported(Codec codec) const { |
582 DCHECK_NE(codec, INVALID_CODEC); | 622 DCHECK_NE(codec, INVALID_CODEC); |
583 | 623 |
584 #if defined(OS_ANDROID) | 624 #if defined(OS_ANDROID) |
585 if (!IsCodecSupportedOnAndroid(codec)) | 625 if (!IsCodecSupportedOnAndroid(codec)) |
586 return false; | 626 return false; |
587 #endif | 627 #endif |
588 | 628 |
589 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 629 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
590 } | 630 } |
591 | 631 |
592 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 632 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
593 switch (codec) { | 633 switch (codec) { |
594 case INVALID_CODEC: | 634 case INVALID_CODEC: |
595 case MP3: | 635 case MP3: |
596 case MPEG2_AAC_LC: | 636 case MPEG2_AAC_LC: |
597 case MPEG2_AAC_MAIN: | 637 case MPEG2_AAC_MAIN: |
598 case MPEG2_AAC_SSR: | 638 case MPEG2_AAC_SSR: |
599 case MPEG4_AAC_LC: | 639 case MPEG4_AAC_LC: |
600 case MPEG4_AAC_SBR_v1: | 640 case MPEG4_AAC_SBR_v1: |
601 case MPEG4_AAC_SBR_PS_v2: | 641 case MPEG4_AAC_SBR_PS_v2: |
602 case H264_BASELINE: | 642 case H264_BASELINE: |
603 case H264_MAIN: | 643 case H264_MAIN: |
604 case H264_HIGH: | 644 case H264_HIGH: |
645 case HEVC_MAIN: | |
605 return true; | 646 return true; |
606 | 647 |
607 case PCM: | 648 case PCM: |
608 case VORBIS: | 649 case VORBIS: |
609 case OPUS: | 650 case OPUS: |
610 case VP8: | 651 case VP8: |
611 case VP9: | 652 case VP9: |
612 case THEORA: | 653 case THEORA: |
613 return false; | 654 return false; |
614 } | 655 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
659 std::vector<std::string>* codecs_out, | 700 std::vector<std::string>* codecs_out, |
660 const bool strip) { | 701 const bool strip) { |
661 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 702 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
662 } | 703 } |
663 | 704 |
664 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 705 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
665 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 706 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
666 } | 707 } |
667 | 708 |
668 } // namespace media | 709 } // namespace media |
OLD | NEW |