Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: media/base/mime_util.cc

Issue 816353010: Implemented HEVC video demuxing and parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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 static bool ParseHEVCCodecID(const std::string& codec_id,
582 MimeUtil::Codec* codec,
583 bool* is_ambiguous) {
584 // TODO(servolk): Full HEVC codec id parsing is not implemented yet (see
585 // crbug.com/482761), but we need to recognize at least one valid unambiguous
586 // HEVC codec id, which is added kMP4VideoCodecsExpression. We need it to be
587 // unambiguous to avoid DCHECK at line 405. We also use these in unit tests.
588 if (codec_id == "hev1.1.6.L93.B0" || codec_id == "hvc1.1.6.L93.B0") {
ddorwin 2015/06/19 21:40:15 Move this check to 601. You can even make this a s
servolk 2015/06/20 00:05:07 Done. I've kept it a separate block of code to pre
589 *codec = MimeUtil::HEVC_MAIN;
590 *is_ambiguous = false;
591 return true;
592 }
593
594 if (base::StartsWithASCII(codec_id, "hev1.", true) ||
ddorwin 2015/06/19 21:40:15 Please add a comment, possibly above the function,
servolk 2015/06/20 00:05:07 Done (I've expanded comment from line 584 and move
595 base::StartsWithASCII(codec_id, "hvc1.", true)) {
596 // TODO(servolk): Implement parsing of hevc codec ids as described in
597 // ISO/IEC FDIS 14496-15 section E.3, but for now allow any
598 // HEVC tiers/profiles and let decoder decide if it can handle that.
599 // crbug.com/482761
600 *codec = MimeUtil::HEVC_MAIN;
601 *is_ambiguous = true;
602 return true;
603 }
604
605 return false;
606 }
607 #endif
608
565 bool MimeUtil::StringToCodec(const std::string& codec_id, 609 bool MimeUtil::StringToCodec(const std::string& codec_id,
566 Codec* codec, 610 Codec* codec,
567 bool* is_ambiguous) const { 611 bool* is_ambiguous) const {
568 StringToCodecMappings::const_iterator itr = 612 StringToCodecMappings::const_iterator itr =
569 string_to_codec_map_.find(codec_id); 613 string_to_codec_map_.find(codec_id);
570 if (itr != string_to_codec_map_.end()) { 614 if (itr != string_to_codec_map_.end()) {
571 *codec = itr->second.codec; 615 *codec = itr->second.codec;
572 *is_ambiguous = itr->second.is_ambiguous; 616 *is_ambiguous = itr->second.is_ambiguous;
573 return true; 617 return true;
574 } 618 }
575 619
576 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is 620 // 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 621 // 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. 622 // ones that are not added to the |string_to_codec_map_| and require parsing.
623 #if defined(ENABLE_HEVC_DEMUXING)
624 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) {
625 return true;
626 }
627 #endif
579 return ParseH264CodecID(codec_id, codec, is_ambiguous); 628 return ParseH264CodecID(codec_id, codec, is_ambiguous);
580 } 629 }
581 630
582 bool MimeUtil::IsCodecSupported(Codec codec) const { 631 bool MimeUtil::IsCodecSupported(Codec codec) const {
583 DCHECK_NE(codec, INVALID_CODEC); 632 DCHECK_NE(codec, INVALID_CODEC);
584 633
585 #if defined(OS_ANDROID) 634 #if defined(OS_ANDROID)
586 if (!IsCodecSupportedOnAndroid(codec)) 635 if (!IsCodecSupportedOnAndroid(codec))
587 return false; 636 return false;
588 #endif 637 #endif
589 638
590 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); 639 return allow_proprietary_codecs_ || !IsCodecProprietary(codec);
591 } 640 }
592 641
593 bool MimeUtil::IsCodecProprietary(Codec codec) const { 642 bool MimeUtil::IsCodecProprietary(Codec codec) const {
594 switch (codec) { 643 switch (codec) {
595 case INVALID_CODEC: 644 case INVALID_CODEC:
596 case MP3: 645 case MP3:
597 case MPEG2_AAC_LC: 646 case MPEG2_AAC_LC:
598 case MPEG2_AAC_MAIN: 647 case MPEG2_AAC_MAIN:
599 case MPEG2_AAC_SSR: 648 case MPEG2_AAC_SSR:
600 case MPEG4_AAC_LC: 649 case MPEG4_AAC_LC:
601 case MPEG4_AAC_SBR_v1: 650 case MPEG4_AAC_SBR_v1:
602 case MPEG4_AAC_SBR_PS_v2: 651 case MPEG4_AAC_SBR_PS_v2:
603 case H264_BASELINE: 652 case H264_BASELINE:
604 case H264_MAIN: 653 case H264_MAIN:
605 case H264_HIGH: 654 case H264_HIGH:
655 case HEVC_MAIN:
606 return true; 656 return true;
607 657
608 case PCM: 658 case PCM:
609 case VORBIS: 659 case VORBIS:
610 case OPUS: 660 case OPUS:
611 case VP8: 661 case VP8:
612 case VP9: 662 case VP9:
613 case THEORA: 663 case THEORA:
614 return false; 664 return false;
615 } 665 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 std::vector<std::string>* codecs_out, 710 std::vector<std::string>* codecs_out,
661 const bool strip) { 711 const bool strip) {
662 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); 712 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip);
663 } 713 }
664 714
665 void RemoveProprietaryMediaTypesAndCodecsForTests() { 715 void RemoveProprietaryMediaTypesAndCodecsForTests() {
666 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); 716 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests();
667 } 717 }
668 718
669 } // namespace media 719 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698