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 "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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // Valid levels taken from Table A-1 in ISO/IEC 14496-10. | 224 // Valid levels taken from Table A-1 in ISO/IEC 14496-10. |
225 // Level_idc represents the standard level represented as decimal number | 225 // Level_idc represents the standard level represented as decimal number |
226 // multiplied by ten, e.g. level_idc==32 corresponds to level==3.2 | 226 // multiplied by ten, e.g. level_idc==32 corresponds to level==3.2 |
227 return ((level_idc >= 10 && level_idc <= 13) || | 227 return ((level_idc >= 10 && level_idc <= 13) || |
228 (level_idc >= 20 && level_idc <= 22) || | 228 (level_idc >= 20 && level_idc <= 22) || |
229 (level_idc >= 30 && level_idc <= 32) || | 229 (level_idc >= 30 && level_idc <= 32) || |
230 (level_idc >= 40 && level_idc <= 42) || | 230 (level_idc >= 40 && level_idc <= 42) || |
231 (level_idc >= 50 && level_idc <= 51)); | 231 (level_idc >= 50 && level_idc <= 51)); |
232 } | 232 } |
233 | 233 |
234 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | |
235 // ISO/IEC FDIS 14496-15 standard section E.3 describes the syntax of codec ids | |
236 // reserved for HEVC. According to that spec HEVC codec id must start with | |
237 // either "hev1." or "hvc1.". We don't yet support full parsing of HEVC codec | |
238 // ids, but since no other codec id starts with those string we'll just treat | |
239 // any string starting with "hev1." or "hvc1." as valid HEVC codec ids. | |
240 // crbug.com/482761 | |
241 static bool ParseHEVCCodecID(const std::string& codec_id, | |
242 MimeUtil::Codec* codec, | |
243 bool* is_ambiguous) { | |
244 if (base::StartsWith(codec_id, "hev1.", base::CompareCase::SENSITIVE) || | |
245 base::StartsWith(codec_id, "hvc1.", base::CompareCase::SENSITIVE)) { | |
246 *codec = MimeUtil::HEVC_MAIN; | |
247 | |
248 // TODO(servolk): Full HEVC codec id parsing is not implemented yet (see | |
249 // crbug.com/482761). So treat HEVC codec ids as ambiguous for now. | |
250 *is_ambiguous = true; | |
251 | |
252 // TODO(servolk): Most HEVC codec ids are treated as ambiguous (see above), | |
253 // but we need to recognize at least one valid unambiguous HEVC codec id, | |
254 // which is added into kMP4VideoCodecsExpression. We need it to be | |
255 // unambiguous to avoid DCHECK(!is_ambiguous) in InitializeMimeTypeMaps. We | |
256 // also use these in unit tests (see | |
257 // content/browser/media/media_canplaytype_browsertest.cc). | |
258 // Remove this workaround after crbug.com/482761 is fixed. | |
259 if (codec_id == "hev1.1.6.L93.B0" || codec_id == "hvc1.1.6.L93.B0") { | |
260 *is_ambiguous = false; | |
261 } | |
262 | |
263 return true; | |
264 } | |
265 | |
266 return false; | |
267 } | |
268 #endif | |
269 | |
270 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { | 234 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { |
271 #if defined(OS_ANDROID) | 235 #if defined(OS_ANDROID) |
272 platform_info_.is_unified_media_pipeline_enabled = | 236 platform_info_.is_unified_media_pipeline_enabled = |
273 IsUnifiedMediaPipelineEnabled(); | 237 IsUnifiedMediaPipelineEnabled(); |
274 // When the unified media pipeline is enabled, we need support for both GPU | 238 // When the unified media pipeline is enabled, we need support for both GPU |
275 // video decoders and MediaCodec; indicated by HasPlatformDecoderSupport(). | 239 // video decoders and MediaCodec; indicated by HasPlatformDecoderSupport(). |
276 // When the Android pipeline is used, we only need access to MediaCodec. | 240 // When the Android pipeline is used, we only need access to MediaCodec. |
277 platform_info_.has_platform_decoders = | 241 platform_info_.has_platform_decoders = |
278 platform_info_.is_unified_media_pipeline_enabled | 242 platform_info_.is_unified_media_pipeline_enabled |
279 ? HasPlatformDecoderSupport() | 243 ? HasPlatformDecoderSupport() |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 466 |
503 case H264: | 467 case H264: |
504 // The unified pipeline requires platform support for h264. | 468 // The unified pipeline requires platform support for h264. |
505 if (platform_info.is_unified_media_pipeline_enabled) | 469 if (platform_info.is_unified_media_pipeline_enabled) |
506 return platform_info.has_platform_decoders; | 470 return platform_info.has_platform_decoders; |
507 | 471 |
508 // When MediaPlayer or MediaCodec is used, h264 is always supported. | 472 // When MediaPlayer or MediaCodec is used, h264 is always supported. |
509 DCHECK(!is_encrypted || platform_info.has_platform_decoders); | 473 DCHECK(!is_encrypted || platform_info.has_platform_decoders); |
510 return true; | 474 return true; |
511 | 475 |
512 case HEVC_MAIN: | 476 case HEVC: |
513 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 477 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
514 if (platform_info.is_unified_media_pipeline_enabled && | 478 if (platform_info.is_unified_media_pipeline_enabled && |
515 !platform_info.has_platform_decoders) { | 479 !platform_info.has_platform_decoders) { |
516 return false; | 480 return false; |
517 } | 481 } |
518 | 482 |
519 #if defined(OS_ANDROID) | 483 #if defined(OS_ANDROID) |
520 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to | 484 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to |
521 // http://developer.android.com/reference/android/media/MediaFormat.html | 485 // http://developer.android.com/reference/android/media/MediaFormat.html |
522 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 486 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 string_to_codec_map_.find(codec_id); | 523 string_to_codec_map_.find(codec_id); |
560 if (itr != string_to_codec_map_.end()) { | 524 if (itr != string_to_codec_map_.end()) { |
561 *codec = itr->second.codec; | 525 *codec = itr->second.codec; |
562 *is_ambiguous = itr->second.is_ambiguous; | 526 *is_ambiguous = itr->second.is_ambiguous; |
563 return true; | 527 return true; |
564 } | 528 } |
565 | 529 |
566 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | 530 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
567 // either H.264 or HEVC/H.265 codec ID because currently those are the only | 531 // either H.264 or HEVC/H.265 codec ID because currently those are the only |
568 // ones that are not added to the |string_to_codec_map_| and require parsing. | 532 // ones that are not added to the |string_to_codec_map_| and require parsing. |
| 533 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
| 534 uint8_t level_idc = 0; |
569 | 535 |
570 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 536 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
571 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | 537 if (ParseHEVCCodecId(codec_id, &profile, &level_idc)) { |
| 538 *is_ambiguous = false; |
| 539 *codec = MimeUtil::HEVC; |
572 return true; | 540 return true; |
573 } | 541 } |
574 #endif | 542 #endif |
575 | 543 |
576 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; | |
577 uint8_t level_idc = 0; | |
578 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { | 544 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { |
579 *codec = MimeUtil::H264; | 545 *codec = MimeUtil::H264; |
580 *is_ambiguous = | 546 *is_ambiguous = |
581 (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN && | 547 (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN && |
582 profile != H264PROFILE_HIGH) || | 548 profile != H264PROFILE_HIGH) || |
583 !IsValidH264Level(level_idc); | 549 !IsValidH264Level(level_idc); |
584 return true; | 550 return true; |
585 } | 551 } |
586 | 552 |
587 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; | 553 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; |
(...skipping 21 matching lines...) Expand all Loading... |
609 case AC3: | 575 case AC3: |
610 case EAC3: | 576 case EAC3: |
611 case MP3: | 577 case MP3: |
612 case MPEG2_AAC_LC: | 578 case MPEG2_AAC_LC: |
613 case MPEG2_AAC_MAIN: | 579 case MPEG2_AAC_MAIN: |
614 case MPEG2_AAC_SSR: | 580 case MPEG2_AAC_SSR: |
615 case MPEG4_AAC_LC: | 581 case MPEG4_AAC_LC: |
616 case MPEG4_AAC_SBR_v1: | 582 case MPEG4_AAC_SBR_v1: |
617 case MPEG4_AAC_SBR_PS_v2: | 583 case MPEG4_AAC_SBR_PS_v2: |
618 case H264: | 584 case H264: |
619 case HEVC_MAIN: | 585 case HEVC: |
620 return true; | 586 return true; |
621 | 587 |
622 case PCM: | 588 case PCM: |
623 case VORBIS: | 589 case VORBIS: |
624 case OPUS: | 590 case OPUS: |
625 case VP8: | 591 case VP8: |
626 case VP9: | 592 case VP9: |
627 case THEORA: | 593 case THEORA: |
628 return false; | 594 return false; |
629 } | 595 } |
(...skipping 22 matching lines...) Expand all Loading... |
652 const std::string& mime_type_lower_case, | 618 const std::string& mime_type_lower_case, |
653 bool is_encrypted) const { | 619 bool is_encrypted) const { |
654 Codec default_codec = Codec::INVALID_CODEC; | 620 Codec default_codec = Codec::INVALID_CODEC; |
655 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 621 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
656 return false; | 622 return false; |
657 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); | 623 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); |
658 } | 624 } |
659 | 625 |
660 } // namespace internal | 626 } // namespace internal |
661 } // namespace media | 627 } // namespace media |
OLD | NEW |