Chromium Code Reviews| Index: media/base/mime_util_internal.cc |
| diff --git a/media/base/mime_util_internal.cc b/media/base/mime_util_internal.cc |
| index 5bd7c7f0bbeb1aed0b73d603815fad4aa8aa6f65..1823df835a2a9df6f3b197be25484c1516f74180 100644 |
| --- a/media/base/mime_util_internal.cc |
| +++ b/media/base/mime_util_internal.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/strings/string_util.h" |
| #include "build/build_config.h" |
| #include "media/base/media.h" |
| +#include "media/base/media_client.h" |
| #include "media/base/media_switches.h" |
| #include "media/base/video_codecs.h" |
| @@ -262,6 +263,24 @@ MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { |
| MimeUtil::~MimeUtil() {} |
| +VideoCodec MimeUtilToVideoCodec(MimeUtil::Codec codec) { |
| + switch (codec) { |
| + case MimeUtil::H264: |
| + return kCodecH264; |
| + case MimeUtil::HEVC: |
| + return kCodecHEVC; |
| + case MimeUtil::VP8: |
| + return kCodecVP8; |
| + case MimeUtil::VP9: |
| + return kCodecVP9; |
| + case MimeUtil::THEORA: |
| + return kCodecTheora; |
| + default: |
| + break; |
| + } |
| + return kUnknownVideoCodec; |
| +} |
| + |
| SupportsType MimeUtil::AreSupportedCodecs( |
| const CodecSet& supported_codecs, |
| const std::vector<std::string>& codecs, |
| @@ -274,8 +293,57 @@ SupportsType MimeUtil::AreSupportedCodecs( |
| for (size_t i = 0; i < codecs.size(); ++i) { |
| bool is_ambiguous = true; |
| Codec codec = INVALID_CODEC; |
| + VideoCodecProfile video_profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
| + uint8_t video_level = 0; |
| if (!StringToCodec(mime_type_lower_case, codecs[i], &codec, &is_ambiguous, |
| - is_encrypted)) { |
| + &video_profile, &video_level, is_encrypted)) { |
| + return IsNotSupported; |
| + } |
| + |
| + VideoCodec video_codec = MimeUtilToVideoCodec(codec); |
| + |
| + if (video_codec == kCodecH264) { |
|
chcunningham
2016/07/22 20:11:25
Did you mean to move this stuff out too? I feel li
miu
2016/07/22 20:58:16
Agreed. For example, Chromecast currently doesn't
servolk
2016/07/23 01:10:35
Yes, Yuri, this is exactly why I've created this c
servolk
2016/07/23 01:10:35
Chris, yes, I moved it here intentionally, since s
chcunningham
2016/07/25 17:56:16
I don't follow. This is all about how to set the i
servolk
2016/07/25 18:42:53
This is true only to some extent. The current logi
|
| + switch (video_profile) { |
| +// HIGH10PROFILE is supported through fallback to the ffmpeg decoder |
| +// which is not available on Android, or if FFMPEG is not used. |
| +#if !defined(MEDIA_DISABLE_FFMPEG) && !defined(OS_ANDROID) |
| + case H264PROFILE_HIGH10PROFILE: |
| + if (is_encrypted) { |
| + // FFmpeg is not generally used for encrypted videos, so we do not |
| + // know whether 10-bit is supported. |
| + is_ambiguous = true; |
| + break; |
| + } |
| +// Fall through. |
| +#endif |
| + |
| + case H264PROFILE_BASELINE: |
| + case H264PROFILE_MAIN: |
| + case H264PROFILE_HIGH: |
| + is_ambiguous = !IsValidH264Level(video_level); |
| + break; |
| + default: |
| + is_ambiguous = true; |
| + } |
| + } |
| + |
| + if (video_codec == kCodecVP9) { |
| + switch (video_profile) { |
| + case VP9PROFILE_PROFILE0: |
| + // Profile 0 should always be supported if VP9 is supported. |
| + is_ambiguous = false; |
| + break; |
| + default: |
| + // We don't know if the underlying platform supports these profiles. |
| + // Need to add platform level querying to get supported profiles |
| + // (crbug/604566). |
| + is_ambiguous = true; |
| + } |
| + } |
| + |
| + if (GetMediaClient() && video_codec != kUnknownVideoCodec && |
|
chcunningham
2016/07/22 20:11:25
Nice
miu
2016/07/22 20:58:16
Is GetMediaClient() global for the whole render pr
servolk
2016/07/23 01:10:35
Yes, GetMediaClient is global. But my understandin
servolk
2016/07/23 01:10:35
Acknowledged.
miu
2016/07/25 19:29:55
Yes media capabilities are static (since you eithe
|
| + !GetMediaClient()->IsSupportedVideoConfig(video_codec, video_profile, |
| + video_level)) { |
| return IsNotSupported; |
| } |
| @@ -639,7 +707,14 @@ bool MimeUtil::StringToCodec(const std::string& mime_type_lower_case, |
| const std::string& codec_id, |
| Codec* codec, |
| bool* is_ambiguous, |
| + VideoCodecProfile* out_profile, |
| + uint8_t* out_level, |
| bool is_encrypted) const { |
| + DCHECK(out_profile); |
| + DCHECK(out_level); |
| + *out_profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
| + *out_level = 0; |
| + |
| StringToCodecMappings::const_iterator itr = |
| string_to_codec_map_.find(codec_id); |
| if (itr != string_to_codec_map_.end()) { |
| @@ -651,60 +726,21 @@ bool MimeUtil::StringToCodec(const std::string& mime_type_lower_case, |
| // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
| // either H.264 or HEVC/H.265 codec ID because currently those are the only |
| // ones that are not added to the |string_to_codec_map_| and require parsing. |
| - VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; |
| - uint8_t level_idc = 0; |
| - |
| - if (ParseAVCCodecId(codec_id, &profile, &level_idc)) { |
| + if (ParseAVCCodecId(codec_id, out_profile, out_level)) { |
| *codec = MimeUtil::H264; |
| - switch (profile) { |
| -// HIGH10PROFILE is supported through fallback to the ffmpeg decoder |
| -// which is not available on Android, or if FFMPEG is not used. |
| -#if !defined(MEDIA_DISABLE_FFMPEG) && !defined(OS_ANDROID) |
| - case H264PROFILE_HIGH10PROFILE: |
| - if (is_encrypted) { |
| - // FFmpeg is not generally used for encrypted videos, so we do not |
| - // know whether 10-bit is supported. |
| - *is_ambiguous = true; |
| - break; |
| - } |
| -// Fall through. |
| -#endif |
| - |
| - case H264PROFILE_BASELINE: |
| - case H264PROFILE_MAIN: |
| - case H264PROFILE_HIGH: |
| - *is_ambiguous = !IsValidH264Level(level_idc); |
| - break; |
| - default: |
| - *is_ambiguous = true; |
| - } |
| return true; |
| } |
| - if (ParseVp9CodecID(mime_type_lower_case, codec_id, &profile)) { |
| + if (ParseVp9CodecID(mime_type_lower_case, codec_id, out_profile)) { |
| *codec = MimeUtil::VP9; |
| - switch (profile) { |
| - case VP9PROFILE_PROFILE0: |
| - // Profile 0 should always be supported if VP9 is supported. |
| - *is_ambiguous = false; |
| - break; |
| - default: |
| - // We don't know if the underlying platform supports these profiles. |
| - // Need to add platform level querying to get supported profiles |
| - // (crbug/604566). |
| - *is_ambiguous = true; |
| - } |
| + *out_level = 1; |
| return true; |
| } |
| #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| - if (ParseHEVCCodecId(codec_id, &profile, &level_idc)) { |
| - // TODO(servolk): Set |is_ambiguous| to true for now to make CanPlayType |
| - // return 'maybe' for HEVC codec ids, instead of probably. This needs to be |
| - // changed to false after adding platform-level HEVC profile and level |
| - // checks, see crbug.com/601949. |
| - *is_ambiguous = true; |
| + if (ParseHEVCCodecId(codec_id, out_profile, out_level)) { |
| *codec = MimeUtil::HEVC; |
| + *is_ambiguous = false; |
| return true; |
| } |
| #endif |