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

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

Issue 1677133003: Implemented parsing of HEVC codec ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@parse-codec-id
Patch Set: Rebase + remove PPAPI changes Created 4 years, 8 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/mime_util_internal.h ('k') | media/base/mime_util_unittest.cc » ('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 "media/base/mime_util_internal.h" 5 #include "media/base/mime_util_internal.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // Valid levels taken from Table A-1 in ISO/IEC 14496-10. 207 // Valid levels taken from Table A-1 in ISO/IEC 14496-10.
208 // Level_idc represents the standard level represented as decimal number 208 // Level_idc represents the standard level represented as decimal number
209 // multiplied by ten, e.g. level_idc==32 corresponds to level==3.2 209 // multiplied by ten, e.g. level_idc==32 corresponds to level==3.2
210 return ((level_idc >= 10 && level_idc <= 13) || 210 return ((level_idc >= 10 && level_idc <= 13) ||
211 (level_idc >= 20 && level_idc <= 22) || 211 (level_idc >= 20 && level_idc <= 22) ||
212 (level_idc >= 30 && level_idc <= 32) || 212 (level_idc >= 30 && level_idc <= 32) ||
213 (level_idc >= 40 && level_idc <= 42) || 213 (level_idc >= 40 && level_idc <= 42) ||
214 (level_idc >= 50 && level_idc <= 51)); 214 (level_idc >= 50 && level_idc <= 51));
215 } 215 }
216 216
217 #if BUILDFLAG(ENABLE_HEVC_DEMUXING)
218 // ISO/IEC FDIS 14496-15 standard section E.3 describes the syntax of codec ids
219 // reserved for HEVC. According to that spec HEVC codec id must start with
220 // either "hev1." or "hvc1.". We don't yet support full parsing of HEVC codec
221 // ids, but since no other codec id starts with those string we'll just treat
222 // any string starting with "hev1." or "hvc1." as valid HEVC codec ids.
223 // crbug.com/482761
224 static bool ParseHEVCCodecID(const std::string& codec_id,
225 MimeUtil::Codec* codec,
226 bool* is_ambiguous) {
227 if (base::StartsWith(codec_id, "hev1.", base::CompareCase::SENSITIVE) ||
228 base::StartsWith(codec_id, "hvc1.", base::CompareCase::SENSITIVE)) {
229 *codec = MimeUtil::HEVC_MAIN;
230
231 // TODO(servolk): Full HEVC codec id parsing is not implemented yet (see
232 // crbug.com/482761). So treat HEVC codec ids as ambiguous for now.
233 *is_ambiguous = true;
234
235 // TODO(servolk): Most HEVC codec ids are treated as ambiguous (see above),
236 // but we need to recognize at least one valid unambiguous HEVC codec id,
237 // which is added into kMP4VideoCodecsExpression. We need it to be
238 // unambiguous to avoid DCHECK(!is_ambiguous) in InitializeMimeTypeMaps. We
239 // also use these in unit tests (see
240 // content/browser/media/media_canplaytype_browsertest.cc).
241 // Remove this workaround after crbug.com/482761 is fixed.
242 if (codec_id == "hev1.1.6.L93.B0" || codec_id == "hvc1.1.6.L93.B0") {
243 *is_ambiguous = false;
244 }
245
246 return true;
247 }
248
249 return false;
250 }
251 #endif
252
253 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { 217 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) {
254 #if defined(OS_ANDROID) 218 #if defined(OS_ANDROID)
255 platform_info_.is_unified_media_pipeline_enabled = 219 platform_info_.is_unified_media_pipeline_enabled =
256 IsUnifiedMediaPipelineEnabled(); 220 IsUnifiedMediaPipelineEnabled();
257 // When the unified media pipeline is enabled, we need support for both GPU 221 // When the unified media pipeline is enabled, we need support for both GPU
258 // video decoders and MediaCodec; indicated by HasPlatformDecoderSupport(). 222 // video decoders and MediaCodec; indicated by HasPlatformDecoderSupport().
259 // When the Android pipeline is used, we only need access to MediaCodec. 223 // When the Android pipeline is used, we only need access to MediaCodec.
260 platform_info_.has_platform_decoders = ArePlatformDecodersAvailable(); 224 platform_info_.has_platform_decoders = ArePlatformDecodersAvailable();
261 platform_info_.has_platform_vp8_decoder = 225 platform_info_.has_platform_vp8_decoder =
262 MediaCodecUtil::IsVp8DecoderAvailable(); 226 MediaCodecUtil::IsVp8DecoderAvailable();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 447
484 case H264: 448 case H264:
485 // The unified pipeline requires platform support for h264. 449 // The unified pipeline requires platform support for h264.
486 if (platform_info.is_unified_media_pipeline_enabled) 450 if (platform_info.is_unified_media_pipeline_enabled)
487 return platform_info.has_platform_decoders; 451 return platform_info.has_platform_decoders;
488 452
489 // When MediaPlayer or MediaCodec is used, h264 is always supported. 453 // When MediaPlayer or MediaCodec is used, h264 is always supported.
490 DCHECK(!is_encrypted || platform_info.has_platform_decoders); 454 DCHECK(!is_encrypted || platform_info.has_platform_decoders);
491 return true; 455 return true;
492 456
493 case HEVC_MAIN: 457 case HEVC:
494 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) 458 #if BUILDFLAG(ENABLE_HEVC_DEMUXING)
495 if (platform_info.is_unified_media_pipeline_enabled && 459 if (platform_info.is_unified_media_pipeline_enabled &&
496 !platform_info.has_platform_decoders) { 460 !platform_info.has_platform_decoders) {
497 return false; 461 return false;
498 } 462 }
499 463
500 #if defined(OS_ANDROID) 464 #if defined(OS_ANDROID)
501 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to 465 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to
502 // http://developer.android.com/reference/android/media/MediaFormat.html 466 // http://developer.android.com/reference/android/media/MediaFormat.html
503 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; 467 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21;
(...skipping 24 matching lines...) Expand all
528 // Otherwise, platform support is required. 492 // Otherwise, platform support is required.
529 return platform_info.supports_vp9; 493 return platform_info.supports_vp9;
530 } 494 }
531 } 495 }
532 496
533 return false; 497 return false;
534 } 498 }
535 499
536 bool MimeUtil::StringToCodec(const std::string& codec_id, 500 bool MimeUtil::StringToCodec(const std::string& codec_id,
537 Codec* codec, 501 Codec* codec,
538 bool* is_ambiguous) const { 502 bool* is_ambiguous) const {
ddorwin 2016/04/02 00:56:09 As you mentioned below, this is confusing. Perhaps
servolk 2016/04/07 00:59:40 Acknowledged.
539 StringToCodecMappings::const_iterator itr = 503 StringToCodecMappings::const_iterator itr =
540 string_to_codec_map_.find(codec_id); 504 string_to_codec_map_.find(codec_id);
541 if (itr != string_to_codec_map_.end()) { 505 if (itr != string_to_codec_map_.end()) {
542 *codec = itr->second.codec; 506 *codec = itr->second.codec;
543 *is_ambiguous = itr->second.is_ambiguous; 507 *is_ambiguous = itr->second.is_ambiguous;
544 return true; 508 return true;
545 } 509 }
546 510
547 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is 511 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is
548 // either H.264 or HEVC/H.265 codec ID because currently those are the only 512 // either H.264 or HEVC/H.265 codec ID because currently those are the only
549 // ones that are not added to the |string_to_codec_map_| and require parsing. 513 // ones that are not added to the |string_to_codec_map_| and require parsing.
514 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
515 uint8_t level_idc = 0;
550 516
551 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) 517 #if BUILDFLAG(ENABLE_HEVC_DEMUXING)
ddorwin 2016/04/02 00:09:06 I believe there was a reason this was originally a
servolk 2016/04/02 00:35:04 Yes, we used to have 'return ParseH264CodecId' at
552 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { 518 if (ParseHEVCCodecId(codec_id, &profile, &level_idc)) {
519 *is_ambiguous = false;
ddorwin 2016/04/02 00:09:06 This assumes that only supported profiles are retu
servolk 2016/04/02 00:35:04 Well, HEVC codec ids contain enough information to
ddorwin 2016/04/02 00:56:09 See above. Ambiguous no longer makes sense, BUT we
ddorwin 2016/04/06 01:43:56 That bug is now fixed, so you don't need to worry
servolk 2016/04/07 00:59:40 Done.
520 *codec = MimeUtil::HEVC;
553 return true; 521 return true;
554 } 522 }
555 #endif 523 #endif
556 524
557 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
558 uint8_t level_idc = 0;
559 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { 525 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) {
560 *codec = MimeUtil::H264; 526 *codec = MimeUtil::H264;
561 *is_ambiguous = 527 *is_ambiguous =
562 (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN && 528 (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN &&
563 profile != H264PROFILE_HIGH) || 529 profile != H264PROFILE_HIGH) ||
564 !IsValidH264Level(level_idc); 530 !IsValidH264Level(level_idc);
565 return true; 531 return true;
566 } 532 }
567 533
568 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; 534 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id;
(...skipping 17 matching lines...) Expand all
586 552
587 bool MimeUtil::IsCodecProprietary(Codec codec) const { 553 bool MimeUtil::IsCodecProprietary(Codec codec) const {
588 switch (codec) { 554 switch (codec) {
589 case INVALID_CODEC: 555 case INVALID_CODEC:
590 case AC3: 556 case AC3:
591 case EAC3: 557 case EAC3:
592 case MP3: 558 case MP3:
593 case MPEG2_AAC: 559 case MPEG2_AAC:
594 case MPEG4_AAC: 560 case MPEG4_AAC:
595 case H264: 561 case H264:
596 case HEVC_MAIN: 562 case HEVC:
597 return true; 563 return true;
598 564
599 case PCM: 565 case PCM:
600 case VORBIS: 566 case VORBIS:
601 case OPUS: 567 case OPUS:
602 case VP8: 568 case VP8:
603 case VP9: 569 case VP9:
604 case THEORA: 570 case THEORA:
605 return false; 571 return false;
606 } 572 }
(...skipping 22 matching lines...) Expand all
629 const std::string& mime_type_lower_case, 595 const std::string& mime_type_lower_case,
630 bool is_encrypted) const { 596 bool is_encrypted) const {
631 Codec default_codec = Codec::INVALID_CODEC; 597 Codec default_codec = Codec::INVALID_CODEC;
632 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) 598 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec))
633 return false; 599 return false;
634 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); 600 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted);
635 } 601 }
636 602
637 } // namespace internal 603 } // namespace internal
638 } // namespace media 604 } // namespace media
OLDNEW
« no previous file with comments | « media/base/mime_util_internal.h ('k') | media/base/mime_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698