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

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: Add kCodecHEVC in media/base/android/demuxer_stream_player_params.cc Created 5 years, 5 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
« no previous file with comments | « media/base/android/media_codec_bridge.cc ('k') | media/base/video_decoder_config.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 *codec = MimeUtil::H264_BASELINE; 559 *codec = MimeUtil::H264_BASELINE;
545 *is_ambiguous = true; 560 *is_ambiguous = true;
546 return true; 561 return true;
547 } 562 }
548 563
549 *is_ambiguous = 564 *is_ambiguous =
550 !IsValidH264Level(base::StringToUpperASCII(codec_id.substr(9))); 565 !IsValidH264Level(base::StringToUpperASCII(codec_id.substr(9)));
551 return true; 566 return true;
552 } 567 }
553 568
569 #if defined(ENABLE_HEVC_DEMUXING)
570 // ISO/IEC FDIS 14496-15 standard section E.3 describes the syntax of codec ids
571 // reserved for HEVC. According to that spec HEVC codec id must start with
572 // either "hev1." or "hvc1.". We don't yet support full parsing of HEVC codec
573 // ids, but since no other codec id starts with those string we'll just treat
574 // any string starting with "hev1." or "hvc1." as valid HEVC codec ids.
575 // crbug.com/482761
576 static bool ParseHEVCCodecID(const std::string& codec_id,
577 MimeUtil::Codec* codec,
578 bool* is_ambiguous) {
579 if (base::StartsWithASCII(codec_id, "hev1.", true) ||
580 base::StartsWithASCII(codec_id, "hvc1.", true)) {
581 *codec = MimeUtil::HEVC_MAIN;
582
583 // TODO(servolk): Full HEVC codec id parsing is not implemented yet (see
584 // crbug.com/482761). So treat HEVC codec ids as ambiguous for now.
585 *is_ambiguous = true;
586
587 // TODO(servolk): Most HEVC codec ids are treated as ambiguous (see above),
588 // but we need to recognize at least one valid unambiguous HEVC codec id,
589 // which is added into kMP4VideoCodecsExpression. We need it to be
590 // unambiguous to avoid DCHECK(!is_ambiguous) in InitializeMimeTypeMaps. We
591 // also use these in unit tests (see content_browsertests).
ddorwin 2015/06/25 23:51:20 nit: That is a binary, not a filename. The latter
servolk 2015/06/26 20:57:42 Done.
592 // Remove this workaround after crbug.com/482761 is fixed.
593 if (codec_id == "hev1.1.6.L93.B0" || codec_id == "hvc1.1.6.L93.B0") {
594 *is_ambiguous = false;
595 }
596
597 return true;
598 }
599
600 return false;
601 }
602 #endif
603
554 bool MimeUtil::StringToCodec(const std::string& codec_id, 604 bool MimeUtil::StringToCodec(const std::string& codec_id,
555 Codec* codec, 605 Codec* codec,
556 bool* is_ambiguous) const { 606 bool* is_ambiguous) const {
557 StringToCodecMappings::const_iterator itr = 607 StringToCodecMappings::const_iterator itr =
558 string_to_codec_map_.find(codec_id); 608 string_to_codec_map_.find(codec_id);
559 if (itr != string_to_codec_map_.end()) { 609 if (itr != string_to_codec_map_.end()) {
560 *codec = itr->second.codec; 610 *codec = itr->second.codec;
561 *is_ambiguous = itr->second.is_ambiguous; 611 *is_ambiguous = itr->second.is_ambiguous;
562 return true; 612 return true;
563 } 613 }
564 614
565 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is 615 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is
566 // an H.264 codec ID because currently those are the only ones that can't be 616 // either H.264 or HEVC/H.265 codec ID because currently those are the only
567 // stored in the |string_to_codec_map_| and require parsing. 617 // ones that are not added to the |string_to_codec_map_| and require parsing.
618 #if defined(ENABLE_HEVC_DEMUXING)
619 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) {
620 return true;
621 }
622 #endif
568 return ParseH264CodecID(codec_id, codec, is_ambiguous); 623 return ParseH264CodecID(codec_id, codec, is_ambiguous);
569 } 624 }
570 625
571 bool MimeUtil::IsCodecSupported(Codec codec) const { 626 bool MimeUtil::IsCodecSupported(Codec codec) const {
572 DCHECK_NE(codec, INVALID_CODEC); 627 DCHECK_NE(codec, INVALID_CODEC);
573 628
574 #if defined(OS_ANDROID) 629 #if defined(OS_ANDROID)
575 if (!IsCodecSupportedOnAndroid(codec)) 630 if (!IsCodecSupportedOnAndroid(codec))
576 return false; 631 return false;
577 #endif 632 #endif
578 633
579 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); 634 return allow_proprietary_codecs_ || !IsCodecProprietary(codec);
580 } 635 }
581 636
582 bool MimeUtil::IsCodecProprietary(Codec codec) const { 637 bool MimeUtil::IsCodecProprietary(Codec codec) const {
583 switch (codec) { 638 switch (codec) {
584 case INVALID_CODEC: 639 case INVALID_CODEC:
585 case MP3: 640 case MP3:
586 case MPEG2_AAC_LC: 641 case MPEG2_AAC_LC:
587 case MPEG2_AAC_MAIN: 642 case MPEG2_AAC_MAIN:
588 case MPEG2_AAC_SSR: 643 case MPEG2_AAC_SSR:
589 case MPEG4_AAC_LC: 644 case MPEG4_AAC_LC:
590 case MPEG4_AAC_SBR_v1: 645 case MPEG4_AAC_SBR_v1:
591 case MPEG4_AAC_SBR_PS_v2: 646 case MPEG4_AAC_SBR_PS_v2:
592 case H264_BASELINE: 647 case H264_BASELINE:
593 case H264_MAIN: 648 case H264_MAIN:
594 case H264_HIGH: 649 case H264_HIGH:
650 case HEVC_MAIN:
595 return true; 651 return true;
596 652
597 case PCM: 653 case PCM:
598 case VORBIS: 654 case VORBIS:
599 case OPUS: 655 case OPUS:
600 case VP8: 656 case VP8:
601 case VP9: 657 case VP9:
602 case THEORA: 658 case THEORA:
603 return false; 659 return false;
604 } 660 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 std::vector<std::string>* codecs_out, 705 std::vector<std::string>* codecs_out,
650 const bool strip) { 706 const bool strip) {
651 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); 707 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip);
652 } 708 }
653 709
654 void RemoveProprietaryMediaTypesAndCodecsForTests() { 710 void RemoveProprietaryMediaTypesAndCodecsForTests() {
655 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); 711 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests();
656 } 712 }
657 713
658 } // namespace media 714 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/media_codec_bridge.cc ('k') | media/base/video_decoder_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698