| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 const std::vector<std::string>& codecs, | 209 const std::vector<std::string>& codecs, |
| 210 const std::string& mime_type_lower_case, | 210 const std::string& mime_type_lower_case, |
| 211 bool is_encrypted) const { | 211 bool is_encrypted) const { |
| 212 DCHECK(!supported_codecs.empty()); | 212 DCHECK(!supported_codecs.empty()); |
| 213 DCHECK(!codecs.empty()); | 213 DCHECK(!codecs.empty()); |
| 214 | 214 |
| 215 SupportsType result = IsSupported; | 215 SupportsType result = IsSupported; |
| 216 for (size_t i = 0; i < codecs.size(); ++i) { | 216 for (size_t i = 0; i < codecs.size(); ++i) { |
| 217 bool is_ambiguous = true; | 217 bool is_ambiguous = true; |
| 218 Codec codec = INVALID_CODEC; | 218 Codec codec = INVALID_CODEC; |
| 219 if (!StringToCodec(codecs[i], &codec, &is_ambiguous)) | 219 if (!StringToCodec(codecs[i], &codec, &is_ambiguous, is_encrypted)) |
| 220 return IsNotSupported; | 220 return IsNotSupported; |
| 221 | 221 |
| 222 if (!IsCodecSupported(codec, mime_type_lower_case, is_encrypted) || | 222 if (!IsCodecSupported(codec, mime_type_lower_case, is_encrypted) || |
| 223 supported_codecs.find(codec) == supported_codecs.end()) { | 223 supported_codecs.find(codec) == supported_codecs.end()) { |
| 224 return IsNotSupported; | 224 return IsNotSupported; |
| 225 } | 225 } |
| 226 | 226 |
| 227 if (is_ambiguous) | 227 if (is_ambiguous) |
| 228 result = MayBeSupported; | 228 result = MayBeSupported; |
| 229 } | 229 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 #endif | 334 #endif |
| 335 | 335 |
| 336 std::vector<std::string> codec_strings; | 336 std::vector<std::string> codec_strings; |
| 337 ParseCodecString(codecs_list, &codec_strings, false); | 337 ParseCodecString(codecs_list, &codec_strings, false); |
| 338 | 338 |
| 339 CodecSet codecs; | 339 CodecSet codecs; |
| 340 for (const auto& codec_string : codec_strings) { | 340 for (const auto& codec_string : codec_strings) { |
| 341 DCHECK(!codec_string.empty()) << codecs_list; | 341 DCHECK(!codec_string.empty()) << codecs_list; |
| 342 Codec codec = INVALID_CODEC; | 342 Codec codec = INVALID_CODEC; |
| 343 bool is_ambiguous = true; | 343 bool is_ambiguous = true; |
| 344 CHECK(StringToCodec(codec_string, &codec, &is_ambiguous)); | 344 CHECK(StringToCodec(codec_string, &codec, &is_ambiguous, false)); |
| 345 DCHECK(!is_ambiguous) << codec_string; | 345 DCHECK(!is_ambiguous) << codec_string; |
| 346 codecs.insert(codec); | 346 codecs.insert(codec); |
| 347 } | 347 } |
| 348 | 348 |
| 349 media_format_map_[mime_type] = codecs; | 349 media_format_map_[mime_type] = codecs; |
| 350 | 350 |
| 351 if (is_proprietary_mime_type) | 351 if (is_proprietary_mime_type) |
| 352 proprietary_media_containers_.push_back(mime_type); | 352 proprietary_media_containers_.push_back(mime_type); |
| 353 } | 353 } |
| 354 | 354 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 // Otherwise, platform support is required. | 548 // Otherwise, platform support is required. |
| 549 return platform_info.supports_vp9; | 549 return platform_info.supports_vp9; |
| 550 } | 550 } |
| 551 } | 551 } |
| 552 | 552 |
| 553 return false; | 553 return false; |
| 554 } | 554 } |
| 555 | 555 |
| 556 bool MimeUtil::StringToCodec(const std::string& codec_id, | 556 bool MimeUtil::StringToCodec(const std::string& codec_id, |
| 557 Codec* codec, | 557 Codec* codec, |
| 558 bool* is_ambiguous) const { | 558 bool* is_ambiguous, |
| 559 bool is_encrypted) const { |
| 559 StringToCodecMappings::const_iterator itr = | 560 StringToCodecMappings::const_iterator itr = |
| 560 string_to_codec_map_.find(codec_id); | 561 string_to_codec_map_.find(codec_id); |
| 561 if (itr != string_to_codec_map_.end()) { | 562 if (itr != string_to_codec_map_.end()) { |
| 562 *codec = itr->second.codec; | 563 *codec = itr->second.codec; |
| 563 *is_ambiguous = itr->second.is_ambiguous; | 564 *is_ambiguous = itr->second.is_ambiguous; |
| 564 return true; | 565 return true; |
| 565 } | 566 } |
| 566 | 567 |
| 567 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | 568 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
| 568 // either H.264 or HEVC/H.265 codec ID because currently those are the only | 569 // either H.264 or HEVC/H.265 codec ID because currently those are the only |
| 569 // ones that are not added to the |string_to_codec_map_| and require parsing. | 570 // ones that are not added to the |string_to_codec_map_| and require parsing. |
| 570 | 571 |
| 571 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 572 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 572 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | 573 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { |
| 573 return true; | 574 return true; |
| 574 } | 575 } |
| 575 #endif | 576 #endif |
| 576 | 577 |
| 577 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; | 578 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
| 578 uint8_t level_idc = 0; | 579 uint8_t level_idc = 0; |
| 579 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { | 580 if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { |
| 580 *codec = MimeUtil::H264; | 581 *codec = MimeUtil::H264; |
| 581 *is_ambiguous = | 582 switch (profile) { |
| 582 (profile != H264PROFILE_BASELINE && profile != H264PROFILE_MAIN && | 583 // HIGH10PROFILE is supported through fallback to the ffmpeg decoder |
| 583 profile != H264PROFILE_HIGH) || | 584 // which is not available on Android, or if FFMPEG is not used. |
| 584 !IsValidH264Level(level_idc); | 585 #if !defined(MEDIA_DISABLE_FFMPEG) && !defined(OS_ANDROID) |
| 586 case H264PROFILE_HIGH10PROFILE: |
| 587 if (is_encrypted) { |
| 588 // FFmpeg is not generally used for encrypted videos, so we do not |
| 589 // know whether 10-bit is supported. |
| 590 *is_ambiguous = true; |
| 591 break; |
| 592 } |
| 593 // Fall through. |
| 594 #endif |
| 595 |
| 596 case H264PROFILE_BASELINE: |
| 597 case H264PROFILE_MAIN: |
| 598 case H264PROFILE_HIGH: |
| 599 *is_ambiguous = !IsValidH264Level(level_idc); |
| 600 break; |
| 601 default: |
| 602 *is_ambiguous = true; |
| 603 } |
| 585 return true; | 604 return true; |
| 586 } | 605 } |
| 587 | 606 |
| 588 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; | 607 DVLOG(4) << __FUNCTION__ << ": Unrecognized codec id " << codec_id; |
| 589 return false; | 608 return false; |
| 590 } | 609 } |
| 591 | 610 |
| 592 bool MimeUtil::IsCodecSupported(Codec codec, | 611 bool MimeUtil::IsCodecSupported(Codec codec, |
| 593 const std::string& mime_type_lower_case, | 612 const std::string& mime_type_lower_case, |
| 594 bool is_encrypted) const { | 613 bool is_encrypted) const { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 const std::string& mime_type_lower_case, | 668 const std::string& mime_type_lower_case, |
| 650 bool is_encrypted) const { | 669 bool is_encrypted) const { |
| 651 Codec default_codec = Codec::INVALID_CODEC; | 670 Codec default_codec = Codec::INVALID_CODEC; |
| 652 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | 671 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) |
| 653 return false; | 672 return false; |
| 654 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); | 673 return IsCodecSupported(default_codec, mime_type_lower_case, is_encrypted); |
| 655 } | 674 } |
| 656 | 675 |
| 657 } // namespace internal | 676 } // namespace internal |
| 658 } // namespace media | 677 } // namespace media |
| OLD | NEW |