Commit aaee45e8 authored by John Rummell's avatar John Rummell Committed by Commit Bot

Improve codec checking by scanning list of available codecs supported

In order to determine what codecs are supported by a specified key
system, the current code attempts to create a decoder for each codec to
determine if it is supported. Improve this by simply querying
MediaCodecList if it is available.

Note that there may be multiple codecs supporting the specified
mime_type, so continue to the next one if the current one doesn't have
FEATURE_SecurePlayback supported as needed.

This reapplies the code removed in commit
fde644c1, along with some additional
changes (check following codecs if this one can't handle it).

Bug: 846120
Test: EncryptedMedia content_browsertests pass
Change-Id: I8a0f79e7a36d203a179c490de3c262add55cffc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1729804
Commit-Queue: John Rummell <jrummell@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683777}
parent 8a57ae11
...@@ -202,7 +202,54 @@ class MediaCodecUtil { ...@@ -202,7 +202,54 @@ class MediaCodecUtil {
*/ */
@CalledByNative @CalledByNative
private static boolean canDecode(String mime, boolean isSecure) { private static boolean canDecode(String mime, boolean isSecure) {
// TODO(crbug.com/846120): Investigate if FEATURE_SecurePlayback will work here. // Not supported on blacklisted devices.
if (!isDecoderSupportedForDevice(mime)) {
Log.e(TAG, "Decoder for type %s is not supported on this device", mime);
return false;
}
// MediaCodecInfo.CodecCapabilities.FEATURE_SecurePlayback is available as of
// API 21 (LOLLIPOP), which is the same as NewMediaCodecList.
MediaCodecListHelper codecListHelper = new MediaCodecListHelper();
if (codecListHelper.hasNewMediaCodecList()) {
for (MediaCodecInfo info : codecListHelper) {
if (info.isEncoder()) continue;
try {
CodecCapabilities caps = info.getCapabilitiesForType(mime);
if (caps != null) {
// There may be multiple entries in the list for the same family
// (e.g. OMX.qcom.video.decoder.avc and OMX.qcom.video.decoder.avc.secure),
// so return early if this one matches what we're looking for.
// If a secure decoder is required, then FEATURE_SecurePlayback must be
// supported.
if (isSecure
&& caps.isFeatureSupported(
CodecCapabilities.FEATURE_SecurePlayback)) {
return true;
}
// If a secure decoder is not required, then make sure that
// FEATURE_SecurePlayback is not required. It may work for unsecure
// content, but keep scanning for another codec that supports
// unsecure content directly.
if (!isSecure
&& !caps.isFeatureRequired(
CodecCapabilities.FEATURE_SecurePlayback)) {
return true;
}
}
} catch (IllegalArgumentException e) {
// Type is not supported.
}
}
// Unable to find a match for |mime|, so not supported.
return false;
}
// On older versions of Android attempt to create a decoder for the specified MIME type.
// TODO(liberato): Should we insist on software here? // TODO(liberato): Should we insist on software here?
CodecCreationInfo info = createDecoder(mime, isSecure ? CodecType.SECURE : CodecType.ANY); CodecCreationInfo info = createDecoder(mime, isSecure ? CodecType.SECURE : CodecType.ANY);
if (info == null || info.mediaCodec == null) return false; if (info == null || info.mediaCodec == null) return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment