Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Unified Diff: media/base/android/java/src/org/chromium/media/MediaCodecUtil.java

Issue 2106133003: [M52] Make AVDA fall back to software decoding if needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/android/java/src/org/chromium/media/MediaCodecUtil.java
diff --git a/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java b/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java
index 5bda3df60c9b0e6abe2797e20d21738b4b17f1a5..8d313c179a813db80f0abbf337455b18feaacc9c 100644
--- a/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java
+++ b/media/base/android/java/src/org/chromium/media/MediaCodecUtil.java
@@ -80,13 +80,28 @@ class MediaCodecUtil {
}
/**
+ * Return true if and only if name is a software codec.
+ * @param name The codec name, e.g. from MediaCodecInfo.getName().
+ */
+ public static boolean isSoftwareCodec(String name) {
+ // This is structured identically to libstagefright/OMXCodec.cpp .
+ if (name.startsWith("OMX.google.")) return true;
+
+ if (name.startsWith("OMX.")) return false;
+
+ return true;
+ }
+
+ /**
* Get a name of default android codec.
* @param mime MIME type of the media.
* @param direction Whether this is encoder or decoder.
+ * @param requireSoftwareCodec Whether we require a software codec.
* @return name of the codec.
*/
@CalledByNative
- private static String getDefaultCodecName(String mime, int direction) {
+ private static String getDefaultCodecName(
+ String mime, int direction, boolean requireSoftwareCodec) {
MediaCodecListHelper codecListHelper = new MediaCodecListHelper();
int codecCount = codecListHelper.getCodecCount();
for (int i = 0; i < codecCount; ++i) {
@@ -95,6 +110,8 @@ class MediaCodecUtil {
int codecDirection = info.isEncoder() ? MEDIA_CODEC_ENCODER : MEDIA_CODEC_DECODER;
if (codecDirection != direction) continue;
+ if (requireSoftwareCodec && !isSoftwareCodec(info.getName())) continue;
+
String[] supportedTypes = info.getSupportedTypes();
for (int j = 0; j < supportedTypes.length; ++j) {
if (supportedTypes[j].equalsIgnoreCase(mime)) return info.getName();
@@ -136,7 +153,8 @@ class MediaCodecUtil {
*/
@CalledByNative
private static boolean canDecode(String mime, boolean isSecure) {
- CodecCreationInfo info = createDecoder(mime, isSecure);
+ // TODO(liberato): Should we insist on software here?
+ CodecCreationInfo info = createDecoder(mime, isSecure, false);
if (info.mediaCodec == null) return false;
try {
@@ -151,9 +169,11 @@ class MediaCodecUtil {
* Creates MediaCodec decoder.
* @param mime MIME type of the media.
* @param secure Whether secure decoder is required.
+ * @param requireSoftwareCodec Whether a software decoder is required.
* @return CodecCreationInfo object
*/
- static CodecCreationInfo createDecoder(String mime, boolean isSecure) {
+ static CodecCreationInfo createDecoder(
+ String mime, boolean isSecure, boolean requireSoftwareCodec) {
// Always return a valid CodecCreationInfo, its |mediaCodec| field will be null
// if we cannot create the codec.
CodecCreationInfo result = new CodecCreationInfo();
@@ -173,7 +193,8 @@ class MediaCodecUtil {
try {
// |isSecure| only applies to video decoders.
if (mime.startsWith("video") && isSecure) {
- String decoderName = getDefaultCodecName(mime, MEDIA_CODEC_DECODER);
+ String decoderName =
+ getDefaultCodecName(mime, MEDIA_CODEC_DECODER, requireSoftwareCodec);
if (decoderName.equals("")) return null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// To work around an issue that we cannot get the codec info from the secure
@@ -188,12 +209,19 @@ class MediaCodecUtil {
}
result.mediaCodec = MediaCodec.createByCodecName(decoderName + ".secure");
} else {
- result.mediaCodec = MediaCodec.createDecoderByType(mime);
+ if (requireSoftwareCodec) {
+ String decoderName =
+ getDefaultCodecName(mime, MEDIA_CODEC_DECODER, requireSoftwareCodec);
+ result.mediaCodec = MediaCodec.createByCodecName(decoderName);
+ } else {
+ result.mediaCodec = MediaCodec.createDecoderByType(mime);
+ }
result.supportsAdaptivePlayback =
codecSupportsAdaptivePlayback(result.mediaCodec, mime);
}
} catch (Exception e) {
- Log.e(TAG, "Failed to create MediaCodec: %s, isSecure: %s", mime, isSecure, e);
+ Log.e(TAG, "Failed to create MediaCodec: %s, isSecure: %s, requireSoftwareCodec: %s",
+ mime, isSecure, requireSoftwareCodec ? "yes" : "no", e);
result.mediaCodec = null;
}
return result;
« no previous file with comments | « media/base/android/java/src/org/chromium/media/MediaCodecBridge.java ('k') | media/base/android/media_codec_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698