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

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

Issue 1525003002: Revert of Refactor MediaCodecBridge to add support for NDK APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix rebase errors Created 5 years 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/MediaCodecBridge.java
diff --git a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
index 3a62582bd50b888efadcd9f8a0e12ca8a1b351f5..72c39647a2a9febc67217122211ff4d016deddaf 100644
--- a/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
+++ b/media/base/android/java/src/org/chromium/media/MediaCodecBridge.java
@@ -22,6 +22,9 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
/**
* A wrapper of the MediaCodec class to facilitate exception capturing and
@@ -44,6 +47,10 @@ class MediaCodecBridge {
private static final int MEDIA_CODEC_ABORT = 8;
private static final int MEDIA_CODEC_ERROR = 9;
+ // Codec direction. Keep this in sync with media_codec_bridge.h.
+ private static final int MEDIA_CODEC_DECODER = 0;
+ private static final int MEDIA_CODEC_ENCODER = 1;
+
// Max adaptive playback size to be supplied to the decoder.
private static final int MAX_ADAPTIVE_PLAYBACK_WIDTH = 1920;
private static final int MAX_ADAPTIVE_PLAYBACK_HEIGHT = 1080;
@@ -93,6 +100,37 @@ class MediaCodecBridge {
}
}
+ /**
+ * This class represents supported android codec information.
+ */
+ private static class CodecInfo {
+ private final String mCodecType; // e.g. "video/x-vnd.on2.vp8".
+ private final String mCodecName; // e.g. "OMX.google.vp8.decoder".
+ private final int mDirection;
+
+ private CodecInfo(String codecType, String codecName,
+ int direction) {
+ mCodecType = codecType;
+ mCodecName = codecName;
+ mDirection = direction;
+ }
+
+ @CalledByNative("CodecInfo")
+ private String codecType() {
+ return mCodecType;
+ }
+
+ @CalledByNative("CodecInfo")
+ private String codecName() {
+ return mCodecName;
+ }
+
+ @CalledByNative("CodecInfo")
+ private int direction() {
+ return mDirection;
+ }
+ }
+
private static class DequeueOutputResult {
private final int mStatus;
private final int mIndex;
@@ -142,6 +180,105 @@ class MediaCodecBridge {
}
}
+ /**
+ * Get a list of supported android codec mimes.
+ */
+ @SuppressWarnings("deprecation")
+ @CalledByNative
+ private static CodecInfo[] getCodecsInfo() {
+ // Return the first (highest-priority) codec for each MIME type.
+ Map<String, CodecInfo> encoderInfoMap = new HashMap<String, CodecInfo>();
+ Map<String, CodecInfo> decoderInfoMap = new HashMap<String, CodecInfo>();
+ int count = MediaCodecList.getCodecCount();
+ for (int i = 0; i < count; ++i) {
+ MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
+ int direction =
+ info.isEncoder() ? MEDIA_CODEC_ENCODER : MEDIA_CODEC_DECODER;
+ String codecString = info.getName();
+ String[] supportedTypes = info.getSupportedTypes();
+ for (int j = 0; j < supportedTypes.length; ++j) {
+ Map<String, CodecInfo> map = info.isEncoder() ? encoderInfoMap : decoderInfoMap;
+ if (!map.containsKey(supportedTypes[j])) {
+ map.put(supportedTypes[j], new CodecInfo(
+ supportedTypes[j], codecString, direction));
+ }
+ }
+ }
+ ArrayList<CodecInfo> codecInfos = new ArrayList<CodecInfo>(
+ decoderInfoMap.size() + encoderInfoMap.size());
+ codecInfos.addAll(encoderInfoMap.values());
+ codecInfos.addAll(decoderInfoMap.values());
+ return codecInfos.toArray(new CodecInfo[codecInfos.size()]);
+ }
+
+ /**
+ * Get a name of default android codec.
+ */
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
+ @SuppressWarnings("deprecation")
+ @CalledByNative
+ private static String getDefaultCodecName(String mime, int direction) {
+ String codecName = "";
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ try {
+ MediaCodec mediaCodec = null;
+ if (direction == MEDIA_CODEC_ENCODER) {
+ mediaCodec = MediaCodec.createEncoderByType(mime);
+ } else {
+ mediaCodec = MediaCodec.createDecoderByType(mime);
+ }
+ codecName = mediaCodec.getName();
+ mediaCodec.release();
+ } catch (Exception e) {
+ Log.w(TAG, "getDefaultCodecName: Failed to create MediaCodec: %s, direction: %d",
+ mime, direction, e);
+ }
+ }
+ return codecName;
+ }
+
+ /**
+ * Get a list of encoder supported color formats for specified mime type.
+ */
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ @SuppressWarnings("deprecation")
+ @CalledByNative
+ private static int[] getEncoderColorFormatsForMime(String mime) {
+ MediaCodecInfo[] codecs = null;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
+ codecs = mediaCodecList.getCodecInfos();
+ } else {
+ int count = MediaCodecList.getCodecCount();
+ if (count <= 0) {
+ return null;
+ }
+ codecs = new MediaCodecInfo[count];
+ for (int i = 0; i < count; ++i) {
+ MediaCodecInfo info = MediaCodecList.getCodecInfoAt(i);
+ codecs[i] = info;
+ }
+ }
+
+ for (int i = 0; i < codecs.length; i++) {
+ if (!codecs[i].isEncoder()) {
+ continue;
+ }
+
+ String[] supportedTypes = codecs[i].getSupportedTypes();
+ for (int j = 0; j < supportedTypes.length; ++j) {
+ if (!supportedTypes[j].equalsIgnoreCase(mime)) {
+ continue;
+ }
+
+ MediaCodecInfo.CodecCapabilities capabilities =
+ codecs[i].getCapabilitiesForType(mime);
+ return capabilities.colorFormats;
+ }
+ }
+ return null;
+ }
+
@SuppressWarnings("deprecation")
private static String getDecoderNameForMime(String mime) {
int count = MediaCodecList.getCodecCount();
@@ -184,9 +321,8 @@ class MediaCodecBridge {
boolean adaptivePlaybackSupported = false;
try {
// |isSecure| only applies to video decoders.
- if (mime.startsWith("video") && isSecure
- && direction == MediaCodecUtil.MEDIA_CODEC_DECODER) {
- String decoderName = MediaCodecUtil.getDecoderNameForMime(mime);
+ if (mime.startsWith("video") && isSecure && direction == MEDIA_CODEC_DECODER) {
+ String decoderName = getDecoderNameForMime(mime);
if (decoderName == null) {
return null;
}
@@ -200,7 +336,7 @@ class MediaCodecBridge {
}
mediaCodec = MediaCodec.createByCodecName(decoderName + ".secure");
} else {
- if (direction == MediaCodecUtil.MEDIA_CODEC_ENCODER) {
+ if (direction == MEDIA_CODEC_ENCODER) {
mediaCodec = MediaCodec.createEncoderByType(mime);
} else {
mediaCodec = MediaCodec.createDecoderByType(mime);
« no previous file with comments | « media/base/android/audio_decoder_job.cc ('k') | media/base/android/java/src/org/chromium/media/MediaCodecUtil.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698