summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Pechetty Sravani (xWF) <pechetty@google.com> 2024-12-18 23:14:41 -0800
committer Pechetty Sravani (xWF) <pechetty@google.com> 2024-12-18 23:14:41 -0800
commit14f5d21fe4f730b84d01e5525565a31e5cc28c26 (patch)
tree773349ba0bc52bcd6fa0677546e04f5dec637a8a
parent8b2f9968bb2529b3894fac3c56c9f219f256403d (diff)
Revert "Java and JNI support for native EncoderCapabilities."
Revert submission 3093180 Reason for revert: <Droidmonitor created revert due to b/385023849.Will be verified through ABTD for standard investigation.> Reverted changes: /q/submissionid:3093180 Change-Id: Ife0a7c6f2f2111a595449164318c732c04e62c67
-rw-r--r--media/java/android/media/MediaCodecInfo.java434
-rw-r--r--media/jni/android_media_CodecCapabilities.cpp49
2 files changed, 164 insertions, 319 deletions
diff --git a/media/java/android/media/MediaCodecInfo.java b/media/java/android/media/MediaCodecInfo.java
index 06d428212c34..3ae1b8e80f26 100644
--- a/media/java/android/media/MediaCodecInfo.java
+++ b/media/java/android/media/MediaCodecInfo.java
@@ -4312,7 +4312,27 @@ public final class MediaCodecInfo {
* A class that supports querying the encoding capabilities of a codec.
*/
public static final class EncoderCapabilities {
- private static final String TAG = "EncoderCapabilities";
+ /**
+ * Returns the supported range of quality values.
+ *
+ * Quality is implementation-specific. As a general rule, a higher quality
+ * setting results in a better image quality and a lower compression ratio.
+ */
+ public Range<Integer> getQualityRange() {
+ return mQualityRange;
+ }
+
+ /**
+ * Returns the supported range of encoder complexity values.
+ * <p>
+ * Some codecs may support multiple complexity levels, where higher
+ * complexity values use more encoder tools (e.g. perform more
+ * intensive calculations) to improve the quality or the compression
+ * ratio. Use a lower value to save power and/or time.
+ */
+ public Range<Integer> getComplexityRange() {
+ return mComplexityRange;
+ }
/** Constant quality mode */
public static final int BITRATE_MODE_CQ = 0;
@@ -4323,314 +4343,188 @@ public final class MediaCodecInfo {
/** Constant bitrate mode with frame drops */
public static final int BITRATE_MODE_CBR_FD = 3;
- /* package private */ interface EncoderCapsIntf {
- public Range<Integer> getQualityRange();
-
- public Range<Integer> getComplexityRange();
-
- public boolean isBitrateModeSupported(int mode);
-
- public void getDefaultFormat(MediaFormat format);
-
- public boolean supportsFormat(MediaFormat format);
+ private static final Feature[] bitrates = new Feature[] {
+ new Feature("VBR", BITRATE_MODE_VBR, true),
+ new Feature("CBR", BITRATE_MODE_CBR, false),
+ new Feature("CQ", BITRATE_MODE_CQ, false),
+ new Feature("CBR-FD", BITRATE_MODE_CBR_FD, false)
+ };
+
+ private static int parseBitrateMode(String mode) {
+ for (Feature feat: bitrates) {
+ if (feat.mName.equalsIgnoreCase(mode)) {
+ return feat.mValue;
+ }
+ }
+ return 0;
}
- /* package private */ static final class EncoderCapsLegacyImpl implements EncoderCapsIntf {
- private CodecCapabilities mParent;
+ /**
+ * Query whether a bitrate mode is supported.
+ */
+ public boolean isBitrateModeSupported(int mode) {
+ for (Feature feat: bitrates) {
+ if (mode == feat.mValue) {
+ return (mBitControl & (1 << mode)) != 0;
+ }
+ }
+ return false;
+ }
- private Range<Integer> mQualityRange;
- private Range<Integer> mComplexityRange;
+ private Range<Integer> mQualityRange;
+ private Range<Integer> mComplexityRange;
+ private CodecCapabilities mParent;
- public Range<Integer> getQualityRange() {
- return mQualityRange;
- }
+ /* no public constructor */
+ private EncoderCapabilities() { }
- public Range<Integer> getComplexityRange() {
- return mComplexityRange;
- }
+ /** @hide */
+ public static EncoderCapabilities create(
+ MediaFormat info, CodecCapabilities parent) {
+ EncoderCapabilities caps = new EncoderCapabilities();
+ caps.init(info, parent);
+ return caps;
+ }
- private static final Feature[] bitrates = new Feature[] {
- new Feature("VBR", BITRATE_MODE_VBR, true),
- new Feature("CBR", BITRATE_MODE_CBR, false),
- new Feature("CQ", BITRATE_MODE_CQ, false),
- new Feature("CBR-FD", BITRATE_MODE_CBR_FD, false)
- };
+ private void init(MediaFormat info, CodecCapabilities parent) {
+ // no support for complexity or quality yet
+ mParent = parent;
+ mComplexityRange = Range.create(0, 0);
+ mQualityRange = Range.create(0, 0);
+ mBitControl = (1 << BITRATE_MODE_VBR);
- private static int parseBitrateMode(String mode) {
- for (Feature feat: bitrates) {
- if (feat.mName.equalsIgnoreCase(mode)) {
- return feat.mValue;
- }
- }
- return 0;
- }
+ applyLevelLimits();
+ parseFromInfo(info);
+ }
- public boolean isBitrateModeSupported(int mode) {
- for (Feature feat: bitrates) {
- if (mode == feat.mValue) {
- return (mBitControl & (1 << mode)) != 0;
- }
- }
- return false;
+ private void applyLevelLimits() {
+ String mime = mParent.getMimeType();
+ if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_FLAC)) {
+ mComplexityRange = Range.create(0, 8);
+ mBitControl = (1 << BITRATE_MODE_CQ);
+ } else if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_AMR_NB)
+ || mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_AMR_WB)
+ || mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_G711_ALAW)
+ || mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_G711_MLAW)
+ || mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_MSGSM)) {
+ mBitControl = (1 << BITRATE_MODE_CBR);
}
+ }
- /* no public constructor */
- private EncoderCapsLegacyImpl() { }
+ private int mBitControl;
+ private Integer mDefaultComplexity;
+ private Integer mDefaultQuality;
+ private String mQualityScale;
- /** @hide */
- public static EncoderCapsLegacyImpl create(
- MediaFormat info, CodecCapabilities parent) {
- if (GetFlag(() -> android.media.codec.Flags.nativeCapabilites())) {
- Log.d(TAG, "Legacy implementation is called while native flag is on.");
- }
+ private void parseFromInfo(MediaFormat info) {
+ Map<String, Object> map = info.getMap();
- EncoderCapsLegacyImpl caps = new EncoderCapsLegacyImpl();
- caps.init(info, parent);
- return caps;
+ if (info.containsKey("complexity-range")) {
+ mComplexityRange = Utils
+ .parseIntRange(info.getString("complexity-range"), mComplexityRange);
+ // TODO should we limit this to level limits?
}
-
- private void init(MediaFormat info, CodecCapabilities parent) {
- // no support for complexity or quality yet
- mParent = parent;
- mComplexityRange = Range.create(0, 0);
- mQualityRange = Range.create(0, 0);
- mBitControl = (1 << BITRATE_MODE_VBR);
-
- applyLevelLimits();
- parseFromInfo(info);
+ if (info.containsKey("quality-range")) {
+ mQualityRange = Utils
+ .parseIntRange(info.getString("quality-range"), mQualityRange);
}
-
- private void applyLevelLimits() {
- String mime = mParent.getMimeType();
- if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_FLAC)) {
- mComplexityRange = Range.create(0, 8);
- mBitControl = (1 << BITRATE_MODE_CQ);
- } else if (mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_AMR_NB)
- || mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_AMR_WB)
- || mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_G711_ALAW)
- || mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_G711_MLAW)
- || mime.equalsIgnoreCase(MediaFormat.MIMETYPE_AUDIO_MSGSM)) {
- mBitControl = (1 << BITRATE_MODE_CBR);
+ if (info.containsKey("feature-bitrate-modes")) {
+ mBitControl = 0;
+ for (String mode: info.getString("feature-bitrate-modes").split(",")) {
+ mBitControl |= (1 << parseBitrateMode(mode));
}
}
- private int mBitControl;
- private Integer mDefaultComplexity;
- private Integer mDefaultQuality;
- private String mQualityScale;
+ try {
+ mDefaultComplexity = Integer.parseInt((String)map.get("complexity-default"));
+ } catch (NumberFormatException e) { }
- private void parseFromInfo(MediaFormat info) {
- Map<String, Object> map = info.getMap();
+ try {
+ mDefaultQuality = Integer.parseInt((String)map.get("quality-default"));
+ } catch (NumberFormatException e) { }
- if (info.containsKey("complexity-range")) {
- mComplexityRange = Utils
- .parseIntRange(info.getString("complexity-range"), mComplexityRange);
- // TODO should we limit this to level limits?
- }
- if (info.containsKey("quality-range")) {
- mQualityRange = Utils
- .parseIntRange(info.getString("quality-range"), mQualityRange);
- }
- if (info.containsKey("feature-bitrate-modes")) {
- mBitControl = 0;
- for (String mode: info.getString("feature-bitrate-modes").split(",")) {
- mBitControl |= (1 << parseBitrateMode(mode));
- }
- }
-
- try {
- mDefaultComplexity = Integer.parseInt((String)map.get("complexity-default"));
- } catch (NumberFormatException e) { }
-
- try {
- mDefaultQuality = Integer.parseInt((String)map.get("quality-default"));
- } catch (NumberFormatException e) { }
+ mQualityScale = (String)map.get("quality-scale");
+ }
- mQualityScale = (String)map.get("quality-scale");
+ private boolean supports(
+ Integer complexity, Integer quality, Integer profile) {
+ boolean ok = true;
+ if (ok && complexity != null) {
+ ok = mComplexityRange.contains(complexity);
}
-
- private boolean supports(
- Integer complexity, Integer quality, Integer profile) {
- boolean ok = true;
- if (ok && complexity != null) {
- ok = mComplexityRange.contains(complexity);
- }
- if (ok && quality != null) {
- ok = mQualityRange.contains(quality);
- }
- if (ok && profile != null) {
- for (CodecProfileLevel pl: mParent.profileLevels) {
- if (pl.profile == profile) {
- profile = null;
- break;
- }
- }
- ok = profile == null;
- }
- return ok;
+ if (ok && quality != null) {
+ ok = mQualityRange.contains(quality);
}
-
- /** @hide */
- public void getDefaultFormat(MediaFormat format) {
- // don't list trivial quality/complexity as default for now
- if (!mQualityRange.getUpper().equals(mQualityRange.getLower())
- && mDefaultQuality != null) {
- format.setInteger(MediaFormat.KEY_QUALITY, mDefaultQuality);
- }
- if (!mComplexityRange.getUpper().equals(mComplexityRange.getLower())
- && mDefaultComplexity != null) {
- format.setInteger(MediaFormat.KEY_COMPLEXITY, mDefaultComplexity);
- }
- // bitrates are listed in order of preference
- for (Feature feat: bitrates) {
- if ((mBitControl & (1 << feat.mValue)) != 0) {
- format.setInteger(MediaFormat.KEY_BITRATE_MODE, feat.mValue);
+ if (ok && profile != null) {
+ for (CodecProfileLevel pl: mParent.profileLevels) {
+ if (pl.profile == profile) {
+ profile = null;
break;
}
}
+ ok = profile == null;
}
+ return ok;
+ }
- /** @hide */
- public boolean supportsFormat(MediaFormat format) {
- final Map<String, Object> map = format.getMap();
- final String mime = mParent.getMimeType();
-
- Integer mode = (Integer)map.get(MediaFormat.KEY_BITRATE_MODE);
- if (mode != null && !isBitrateModeSupported(mode)) {
- return false;
- }
-
- Integer complexity = (Integer)map.get(MediaFormat.KEY_COMPLEXITY);
- if (MediaFormat.MIMETYPE_AUDIO_FLAC.equalsIgnoreCase(mime)) {
- Integer flacComplexity =
- (Integer)map.get(MediaFormat.KEY_FLAC_COMPRESSION_LEVEL);
- if (complexity == null) {
- complexity = flacComplexity;
- } else if (flacComplexity != null && !complexity.equals(flacComplexity)) {
- throw new IllegalArgumentException(
- "conflicting values for complexity and " +
- "flac-compression-level");
- }
- }
-
- // other audio parameters
- Integer profile = (Integer)map.get(MediaFormat.KEY_PROFILE);
- if (MediaFormat.MIMETYPE_AUDIO_AAC.equalsIgnoreCase(mime)) {
- Integer aacProfile = (Integer)map.get(MediaFormat.KEY_AAC_PROFILE);
- if (profile == null) {
- profile = aacProfile;
- } else if (aacProfile != null && !aacProfile.equals(profile)) {
- throw new IllegalArgumentException(
- "conflicting values for profile and aac-profile");
- }
+ /** @hide */
+ public void getDefaultFormat(MediaFormat format) {
+ // don't list trivial quality/complexity as default for now
+ if (!mQualityRange.getUpper().equals(mQualityRange.getLower())
+ && mDefaultQuality != null) {
+ format.setInteger(MediaFormat.KEY_QUALITY, mDefaultQuality);
+ }
+ if (!mComplexityRange.getUpper().equals(mComplexityRange.getLower())
+ && mDefaultComplexity != null) {
+ format.setInteger(MediaFormat.KEY_COMPLEXITY, mDefaultComplexity);
+ }
+ // bitrates are listed in order of preference
+ for (Feature feat: bitrates) {
+ if ((mBitControl & (1 << feat.mValue)) != 0) {
+ format.setInteger(MediaFormat.KEY_BITRATE_MODE, feat.mValue);
+ break;
}
-
- Integer quality = (Integer)map.get(MediaFormat.KEY_QUALITY);
-
- return supports(complexity, quality, profile);
}
}
- /* package private */ static final class EncoderCapsNativeImpl implements EncoderCapsIntf {
- private long mNativeContext; // accessed by native methods
-
- private Range<Integer> mQualityRange;
- private Range<Integer> mComplexityRange;
-
- /* no public constructor */
- private EncoderCapsNativeImpl() { }
-
- // Constructor called from native
- /* package private */ EncoderCapsNativeImpl(Range<Integer> qualityRange,
- Range<Integer> complexityRange) {
- mQualityRange = qualityRange;
- mComplexityRange = complexityRange;
- }
-
- public Range<Integer> getQualityRange() {
- return mQualityRange;
- }
-
- public Range<Integer> getComplexityRange() {
- return mComplexityRange;
- }
-
- public boolean isBitrateModeSupported(int mode) {
- return native_isBitrateModeSupported(mode);
- }
+ /** @hide */
+ public boolean supportsFormat(MediaFormat format) {
+ final Map<String, Object> map = format.getMap();
+ final String mime = mParent.getMimeType();
- // This API is for internal Java implementation only. Should not be called.
- public void getDefaultFormat(MediaFormat format) {
- throw new UnsupportedOperationException(
- "Java Implementation should not call native implemenatation");
+ Integer mode = (Integer)map.get(MediaFormat.KEY_BITRATE_MODE);
+ if (mode != null && !isBitrateModeSupported(mode)) {
+ return false;
}
- // This API is for internal Java implementation only. Should not be called.
- public boolean supportsFormat(MediaFormat format) {
- throw new UnsupportedOperationException(
- "Java Implementation should not call native implemenatation");
+ Integer complexity = (Integer)map.get(MediaFormat.KEY_COMPLEXITY);
+ if (MediaFormat.MIMETYPE_AUDIO_FLAC.equalsIgnoreCase(mime)) {
+ Integer flacComplexity =
+ (Integer)map.get(MediaFormat.KEY_FLAC_COMPRESSION_LEVEL);
+ if (complexity == null) {
+ complexity = flacComplexity;
+ } else if (flacComplexity != null && !complexity.equals(flacComplexity)) {
+ throw new IllegalArgumentException(
+ "conflicting values for complexity and " +
+ "flac-compression-level");
+ }
}
- private native boolean native_isBitrateModeSupported(int mode);
- private static native void native_init();
-
- static {
- System.loadLibrary("media_jni");
- native_init();
+ // other audio parameters
+ Integer profile = (Integer)map.get(MediaFormat.KEY_PROFILE);
+ if (MediaFormat.MIMETYPE_AUDIO_AAC.equalsIgnoreCase(mime)) {
+ Integer aacProfile = (Integer)map.get(MediaFormat.KEY_AAC_PROFILE);
+ if (profile == null) {
+ profile = aacProfile;
+ } else if (aacProfile != null && !aacProfile.equals(profile)) {
+ throw new IllegalArgumentException(
+ "conflicting values for profile and aac-profile");
+ }
}
- }
-
- private EncoderCapsIntf mImpl;
-
- /** @hide */
- public static EncoderCapabilities create(
- MediaFormat info, CodecCapabilities parent) {
- EncoderCapsLegacyImpl impl = EncoderCapsLegacyImpl.create(info, parent);
- EncoderCapabilities caps = new EncoderCapabilities(impl);
- return caps;
- }
-
- /* package private */ EncoderCapabilities(EncoderCapsIntf impl) {
- mImpl = impl;
- }
-
- /**
- * Returns the supported range of quality values.
- *
- * Quality is implementation-specific. As a general rule, a higher quality
- * setting results in a better image quality and a lower compression ratio.
- */
- public Range<Integer> getQualityRange() {
- return mImpl.getQualityRange();
- }
-
- /**
- * Returns the supported range of encoder complexity values.
- * <p>
- * Some codecs may support multiple complexity levels, where higher
- * complexity values use more encoder tools (e.g. perform more
- * intensive calculations) to improve the quality or the compression
- * ratio. Use a lower value to save power and/or time.
- */
- public Range<Integer> getComplexityRange() {
- return mImpl.getComplexityRange();
- }
- /**
- * Query whether a bitrate mode is supported.
- */
- public boolean isBitrateModeSupported(int mode) {
- return mImpl.isBitrateModeSupported(mode);
- }
+ Integer quality = (Integer)map.get(MediaFormat.KEY_QUALITY);
- /** @hide */
- public void getDefaultFormat(MediaFormat format) {
- mImpl.getDefaultFormat(format);
- }
-
- /** @hide */
- public boolean supportsFormat(MediaFormat format) {
- return mImpl.supportsFormat(format);
+ return supports(complexity, quality, profile);
}
};
diff --git a/media/jni/android_media_CodecCapabilities.cpp b/media/jni/android_media_CodecCapabilities.cpp
index 29695d60eeb2..ccaa140845dc 100644
--- a/media/jni/android_media_CodecCapabilities.cpp
+++ b/media/jni/android_media_CodecCapabilities.cpp
@@ -21,7 +21,6 @@
#include "jni.h"
#include <media/AudioCapabilities.h>
-#include <media/EncoderCapabilities.h>
#include <media/VideoCapabilities.h>
#include <media/stagefright/foundation/ADebug.h>
#include <nativehelper/JNIHelp.h>
@@ -31,7 +30,6 @@ namespace android {
struct fields_t {
jfieldID audioCapsContext;
jfieldID videoCapsContext;
- jfieldID encoderCapsContext;
};
static fields_t fields;
@@ -49,12 +47,6 @@ static VideoCapabilities* getVideoCapabilities(JNIEnv *env, jobject thiz) {
return p;
}
-static EncoderCapabilities* getEncoderCapabilities(JNIEnv *env, jobject thiz) {
- EncoderCapabilities* const p = (EncoderCapabilities*)env->GetLongField(
- thiz, fields.encoderCapsContext);
- return p;
-}
-
// Utils
static jobject convertToJavaIntRange(JNIEnv *env, const Range<int32_t>& range) {
@@ -313,35 +305,6 @@ static jint android_media_VideoCapabilities_getSmallerDimensionUpperLimit(JNIEnv
return smallerDimensionUpperLimit;
}
-// EncoderCapabilities
-
-static void android_media_EncoderCapabilities_native_init(JNIEnv *env, jobject /* thiz */) {
- jclass clazz = env->FindClass(
- "android/media/MediaCodecInfo$EncoderCapabilities$EncoderCapsNativeImpl");
- if (clazz == NULL) {
- return;
- }
-
- fields.encoderCapsContext = env->GetFieldID(clazz, "mNativeContext", "J");
- if (fields.encoderCapsContext == NULL) {
- return;
- }
-
- env->DeleteLocalRef(clazz);
-}
-
-static jboolean android_media_EncoderCapabilities_isBitrateModeSupported(JNIEnv *env, jobject thiz,
- int mode) {
- EncoderCapabilities* const encoderCaps = getEncoderCapabilities(env, thiz);
- if (encoderCaps == nullptr) {
- jniThrowException(env, "java/lang/IllegalStateException", NULL);
- return 0;
- }
-
- bool res = encoderCaps->isBitrateModeSupported(mode);
- return res;
-}
-
// ----------------------------------------------------------------------------
static const JNINativeMethod gAudioCapsMethods[] = {
@@ -367,11 +330,6 @@ static const JNINativeMethod gVideoCapsMethods[] = {
{"native_getSmallerDimensionUpperLimit", "()I", (void *)android_media_VideoCapabilities_getSmallerDimensionUpperLimit}
};
-static const JNINativeMethod gEncoderCapsMethods[] = {
- {"native_init", "()V", (void *)android_media_EncoderCapabilities_native_init},
- {"native_isBitrateModeSupported", "(I)Z", (void *)android_media_EncoderCapabilities_isBitrateModeSupported}
-};
-
int register_android_media_CodecCapabilities(JNIEnv *env) {
int result = AndroidRuntime::registerNativeMethods(env,
"android/media/MediaCodecInfo$AudioCapabilities$AudioCapsNativeImpl",
@@ -394,12 +352,5 @@ int register_android_media_CodecCapabilities(JNIEnv *env) {
return result;
}
- result = AndroidRuntime::registerNativeMethods(env,
- "android/media/MediaCodecInfo$EncoderCapabilities$EncoderCapsNativeImpl",
- gEncoderCapsMethods, NELEM(gEncoderCapsMethods));
- if (result != JNI_OK) {
- return result;
- }
-
return result;
} \ No newline at end of file