| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/blink/webmediacapabilitiesclient_impl.h" | 5 #include "media/blink/webmediacapabilitiesclient_impl.h" |
| 6 | 6 |
| 7 #include "media/base/audio_codecs.h" |
| 8 #include "media/base/decode_capabilities.h" |
| 7 #include "media/base/mime_util.h" | 9 #include "media/base/mime_util.h" |
| 10 #include "media/base/video_codecs.h" |
| 11 #include "media/base/video_color_space.h" |
| 8 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebAudio
Configuration.h" | 12 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebAudio
Configuration.h" |
| 9 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebMedia
CapabilitiesInfo.h" | 13 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebMedia
CapabilitiesInfo.h" |
| 10 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebMedia
Configuration.h" | 14 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebMedia
Configuration.h" |
| 11 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebVideo
Configuration.h" | 15 #include "third_party/WebKit/public/platform/modules/media_capabilities/WebVideo
Configuration.h" |
| 12 | 16 |
| 13 namespace media { | 17 namespace media { |
| 14 | 18 |
| 15 WebMediaCapabilitiesClientImpl::WebMediaCapabilitiesClientImpl() = default; | 19 WebMediaCapabilitiesClientImpl::WebMediaCapabilitiesClientImpl() = default; |
| 16 | 20 |
| 17 WebMediaCapabilitiesClientImpl::~WebMediaCapabilitiesClientImpl() = default; | 21 WebMediaCapabilitiesClientImpl::~WebMediaCapabilitiesClientImpl() = default; |
| 18 | 22 |
| 19 void WebMediaCapabilitiesClientImpl::DecodingInfo( | 23 void WebMediaCapabilitiesClientImpl::DecodingInfo( |
| 20 const blink::WebMediaConfiguration& configuration, | 24 const blink::WebMediaConfiguration& configuration, |
| 21 std::unique_ptr<blink::WebMediaCapabilitiesQueryCallbacks> callbacks) { | 25 std::unique_ptr<blink::WebMediaCapabilitiesQueryCallbacks> callbacks) { |
| 22 std::unique_ptr<blink::WebMediaCapabilitiesInfo> info( | 26 std::unique_ptr<blink::WebMediaCapabilitiesInfo> info( |
| 23 new blink::WebMediaCapabilitiesInfo()); | 27 new blink::WebMediaCapabilitiesInfo()); |
| 24 | 28 |
| 25 SupportsType audio_support = IsSupported; | 29 bool audio_supported = true; |
| 26 SupportsType video_support = IsSupported; | 30 bool video_supported = true; |
| 27 | 31 |
| 28 if (configuration.audio_configuration) { | 32 if (configuration.audio_configuration) { |
| 29 const blink::WebAudioConfiguration& audio_config = | 33 const blink::WebAudioConfiguration& audio_config = |
| 30 configuration.audio_configuration.value(); | 34 configuration.audio_configuration.value(); |
| 31 std::vector<std::string> codec_vector; | 35 AudioCodec audio_codec; |
| 32 SplitCodecsToVector(audio_config.codec.Ascii(), &codec_vector, false); | 36 bool is_audio_codec_ambiguous; |
| 33 | 37 |
| 34 // TODO(chcunningham): Update to throw exception pending outcome of | 38 if (!ParseAudioCodecString(audio_config.mime_type.Ascii(), |
| 35 // https://github.com/WICG/media-capabilities/issues/32 | 39 audio_config.codec.Ascii(), |
| 36 DCHECK_LE(codec_vector.size(), 1U); | 40 &is_audio_codec_ambiguous, &audio_codec)) { |
| 37 | 41 // TODO(chcunningham): Replace this and other DVLOGs here with MEDIA_LOG. |
| 38 audio_support = | 42 // MediaCapabilities may need its own tab in chrome://media-internals. |
| 39 IsSupportedMediaFormat(audio_config.mime_type.Ascii(), codec_vector); | 43 DVLOG(2) << __func__ << " Failed to parse audio codec string:" |
| 44 << audio_config.codec.Ascii(); |
| 45 audio_supported = false; |
| 46 } else if (is_audio_codec_ambiguous) { |
| 47 DVLOG(2) << __func__ << " Invalid (ambiguous) audio codec string:" |
| 48 << audio_config.codec.Ascii(); |
| 49 audio_supported = false; |
| 50 } else { |
| 51 AudioConfig audio_config = {audio_codec}; |
| 52 audio_supported = IsSupportedAudioConfig(audio_config); |
| 53 } |
| 40 } | 54 } |
| 41 | 55 |
| 42 if (configuration.video_configuration) { | 56 if (configuration.video_configuration) { |
| 43 const blink::WebVideoConfiguration& video_config = | 57 const blink::WebVideoConfiguration& video_config = |
| 44 configuration.video_configuration.value(); | 58 configuration.video_configuration.value(); |
| 45 std::vector<std::string> codec_vector; | 59 VideoCodec video_codec; |
| 46 SplitCodecsToVector(video_config.codec.Ascii(), &codec_vector, false); | 60 VideoCodecProfile video_profile; |
| 61 uint8_t video_level; |
| 62 VideoColorSpace video_color_space; |
| 63 bool is_video_codec_ambiguous; |
| 47 | 64 |
| 48 // TODO(chcunningham): Update to throw exception pending outcome of | 65 if (!ParseVideoCodecString( |
| 49 // https://github.com/WICG/media-capabilities/issues/32 | 66 video_config.mime_type.Ascii(), video_config.codec.Ascii(), |
| 50 DCHECK_LE(codec_vector.size(), 1U); | 67 &is_video_codec_ambiguous, &video_codec, &video_profile, |
| 51 | 68 &video_level, &video_color_space)) { |
| 52 video_support = | 69 DVLOG(2) << __func__ << " Failed to parse video codec string:" |
| 53 IsSupportedMediaFormat(video_config.mime_type.Ascii(), codec_vector); | 70 << video_config.codec.Ascii(); |
| 71 video_supported = false; |
| 72 } else if (is_video_codec_ambiguous) { |
| 73 DVLOG(2) << __func__ << " Invalid (ambiguous) video codec string:" |
| 74 << video_config.codec.Ascii(); |
| 75 video_supported = false; |
| 76 } else { |
| 77 VideoConfig video_config = {video_codec, video_profile, video_level, |
| 78 video_color_space}; |
| 79 video_supported = IsSupportedVideoConfig(video_config); |
| 80 } |
| 54 } | 81 } |
| 55 | 82 |
| 56 // TODO(chcunningham): API should never have to mask uncertainty. Log a metric | 83 info->supported = audio_supported && video_supported; |
| 57 // for any content type that is "maybe" supported. | |
| 58 if (video_support == MayBeSupported) | |
| 59 video_support = IsSupported; | |
| 60 if (audio_support == MayBeSupported) | |
| 61 audio_support = IsSupported; | |
| 62 | |
| 63 info->supported = | |
| 64 audio_support == IsSupported && video_support == IsSupported; | |
| 65 | 84 |
| 66 // TODO(chcunningham, mlamouri): real implementation for these. | 85 // TODO(chcunningham, mlamouri): real implementation for these. |
| 67 info->smooth = info->power_efficient = info->supported; | 86 info->smooth = info->power_efficient = info->supported; |
| 68 | 87 |
| 69 callbacks->OnSuccess(std::move(info)); | 88 callbacks->OnSuccess(std::move(info)); |
| 70 } | 89 } |
| 71 | 90 |
| 72 } // namespace media | 91 } // namespace media |
| OLD | NEW |