diff options
| author | 2024-06-25 21:59:12 +0000 | |
|---|---|---|
| committer | 2024-12-18 02:41:47 +0000 | |
| commit | 15045b109eab58e060455a501532bc083be1be0c (patch) | |
| tree | 9a113ed783c3d8778734ec8c6fd1f1d804904c44 | |
| parent | b279f15f6791f5bb4e52808f4e72f3c2c2b8edc0 (diff) | |
Java and JNI support for native PerformancePoint.
Bug: b/306023029
Test: MediaCodecCapabilitiesTest
Change-Id: Ie0864e21923fee4a4d72cfb8251ca78c37bca363
| -rw-r--r-- | media/java/android/media/MediaCodecInfo.java | 98 | ||||
| -rw-r--r-- | media/jni/android_media_CodecCapabilities.cpp | 74 |
2 files changed, 158 insertions, 14 deletions
diff --git a/media/java/android/media/MediaCodecInfo.java b/media/java/android/media/MediaCodecInfo.java index dbcba57520e6..26bc1926bed4 100644 --- a/media/java/android/media/MediaCodecInfo.java +++ b/media/java/android/media/MediaCodecInfo.java @@ -2388,6 +2388,24 @@ public final class MediaCodecInfo { } /** + * Width in macroblocks. + * + * @hide + */ + /** package private */ int getWidth() { + return mWidth; + } + + /** + * Height in macroblocks. + * + * @hide + */ + /** package private */ int getHeight() { + return mHeight; + } + + /** * Maximum frame rate in frames per second. * * @hide @@ -2407,6 +2425,24 @@ public final class MediaCodecInfo { return mMaxMacroBlockRate; } + /** + * Codec block width in macroblocks. + * + * @hide + */ + /** package private */ int getBlockWidth() { + return mBlockSize.getWidth(); + } + + /** + * Codec block height in macroblocks. + * + * @hide + */ + /** package private */ int getBlockHeight() { + return mBlockSize.getHeight(); + } + /** Convert to a debug string */ public String toString() { int blockWidth = 16 * mBlockSize.getWidth(); @@ -2494,6 +2530,20 @@ public final class MediaCodecInfo { this(width, height, frameRate, frameRate /* maxFrameRate */, new Size(16, 16)); } + /* package private */ PerformancePoint(int width, int height, int maxFrameRate, + long maxMacroBlockRate, int blockSizeWidth, int blockSizeHeight) { + mWidth = width; + mHeight = height; + mMaxFrameRate = maxFrameRate; + mMaxMacroBlockRate = maxMacroBlockRate; + mBlockSize = new Size(blockSizeWidth, blockSizeHeight); + } + + private PerformancePoint(PerformancePoint pp) { + this(pp.mWidth, pp.mHeight, pp.mMaxFrameRate, pp.mMaxMacroBlockRate, + pp.mBlockSize.getWidth(), pp.mBlockSize.getHeight()); + } + /** Saturates a long value to int */ private int saturateLongToInt(long value) { if (value < Integer.MIN_VALUE) { @@ -2547,14 +2597,18 @@ public final class MediaCodecInfo { * @return {@code true} if the performance point covers the other. */ public boolean covers(@NonNull PerformancePoint other) { - // convert performance points to common block size - Size commonSize = getCommonBlockSize(other); - PerformancePoint aligned = new PerformancePoint(this, commonSize); - PerformancePoint otherAligned = new PerformancePoint(other, commonSize); - - return (aligned.getMaxMacroBlocks() >= otherAligned.getMaxMacroBlocks() - && aligned.mMaxFrameRate >= otherAligned.mMaxFrameRate - && aligned.mMaxMacroBlockRate >= otherAligned.mMaxMacroBlockRate); + if (GetFlag(() -> android.media.codec.Flags.nativeCapabilites())) { + return native_covers(other); + } else { + // convert performance points to common block size + Size commonSize = getCommonBlockSize(other); + PerformancePoint aligned = new PerformancePoint(this, commonSize); + PerformancePoint otherAligned = new PerformancePoint(other, commonSize); + + return (aligned.getMaxMacroBlocks() >= otherAligned.getMaxMacroBlocks() + && aligned.mMaxFrameRate >= otherAligned.mMaxFrameRate + && aligned.mMaxMacroBlockRate >= otherAligned.mMaxMacroBlockRate); + } } private @NonNull Size getCommonBlockSize(@NonNull PerformancePoint other) { @@ -2568,17 +2622,28 @@ public final class MediaCodecInfo { if (o instanceof PerformancePoint) { // convert performance points to common block size PerformancePoint other = (PerformancePoint)o; - Size commonSize = getCommonBlockSize(other); - PerformancePoint aligned = new PerformancePoint(this, commonSize); - PerformancePoint otherAligned = new PerformancePoint(other, commonSize); + if (GetFlag(() -> android.media.codec.Flags.nativeCapabilites())) { + return native_equals(other); + } else { + Size commonSize = getCommonBlockSize(other); + PerformancePoint aligned = new PerformancePoint(this, commonSize); + PerformancePoint otherAligned = new PerformancePoint(other, commonSize); - return (aligned.getMaxMacroBlocks() == otherAligned.getMaxMacroBlocks() - && aligned.mMaxFrameRate == otherAligned.mMaxFrameRate - && aligned.mMaxMacroBlockRate == otherAligned.mMaxMacroBlockRate); + return (aligned.getMaxMacroBlocks() == otherAligned.getMaxMacroBlocks() + && aligned.mMaxFrameRate == otherAligned.mMaxFrameRate + && aligned.mMaxMacroBlockRate == otherAligned.mMaxMacroBlockRate); + } } return false; } + private native boolean native_covers(PerformancePoint other); + private native boolean native_equals(PerformancePoint other); + + static { + System.loadLibrary("media_jni"); + } + /** 480p 24fps */ @NonNull public static final PerformancePoint SD_24 = new PerformancePoint(720, 480, 24); @@ -4995,5 +5060,10 @@ public final class MediaCodecInfo { private static Range<Integer> constructIntegerRange(int lower, int upper) { return Range.create(Integer.valueOf(lower), Integer.valueOf(upper)); } + + private static List<VideoCapabilities.PerformancePoint> + constructPerformancePointList(VideoCapabilities.PerformancePoint[] array) { + return Arrays.asList(array); + } } } diff --git a/media/jni/android_media_CodecCapabilities.cpp b/media/jni/android_media_CodecCapabilities.cpp index d5e574764181..94dcc1ea8626 100644 --- a/media/jni/android_media_CodecCapabilities.cpp +++ b/media/jni/android_media_CodecCapabilities.cpp @@ -21,6 +21,7 @@ #include "jni.h" #include <media/AudioCapabilities.h> +#include <media/VideoCapabilities.h> #include <media/stagefright/foundation/ADebug.h> #include <nativehelper/JNIHelp.h> @@ -39,6 +40,47 @@ static AudioCapabilities* getAudioCapabilities(JNIEnv *env, jobject thiz) { return p; } +// Converters between Java objects and native instances + +static VideoCapabilities::PerformancePoint convertToNativePerformancePoint( + JNIEnv *env, jobject pp) { + if (pp == NULL) { + jniThrowException(env, "java/lang/NullPointerException", NULL); + } + + jclass clazz = env->FindClass( + "android/media/MediaCodecInfo$VideoCapabilities$PerformancePoint"); + CHECK(clazz != NULL); + CHECK(env->IsInstanceOf(pp, clazz)); + + jmethodID getWidthID = env->GetMethodID(clazz, "getWidth", "()I"); + CHECK(getWidthID != NULL); + jint width = env->CallIntMethod(pp, getWidthID); + + jmethodID getHeightID = env->GetMethodID(clazz, "getHeight", "()I"); + CHECK(getHeightID != NULL); + jint height = env->CallIntMethod(pp, getHeightID); + + jmethodID getMaxFrameRateID = env->GetMethodID(clazz, "getMaxFrameRate", "()I"); + CHECK(getMaxFrameRateID != NULL); + jint maxFrameRate = env->CallIntMethod(pp, getMaxFrameRateID); + + jmethodID getMaxMacroBlockRateID = env->GetMethodID(clazz, "getMaxMacroBlockRate", "()J"); + CHECK(getMaxMacroBlockRateID != NULL); + jlong maxMacroBlockRate = env->CallLongMethod(pp, getMaxMacroBlockRateID); + + jmethodID getBlockWidthID = env->GetMethodID(clazz, "getBlockWidth", "()I"); + CHECK(getBlockWidthID != NULL); + jint blockWidth = env->CallIntMethod(pp, getBlockWidthID); + + jmethodID getBlockHeightID = env->GetMethodID(clazz, "getBlockHeight", "()I"); + CHECK(getBlockHeightID != NULL); + jint blockHeight = env->CallIntMethod(pp, getBlockHeightID); + + return VideoCapabilities::PerformancePoint(VideoSize(blockWidth, blockHeight), + width, height, maxFrameRate, maxMacroBlockRate); +} + } // namespace android // ---------------------------------------------------------------------------- @@ -96,6 +138,26 @@ static jboolean android_media_AudioCapabilities_isSampleRateSupported(JNIEnv *en return res; } +// PerformancePoint + +static jboolean android_media_VideoCapabilities_PerformancePoint_covers(JNIEnv *env, jobject thiz, + jobject other) { + VideoCapabilities::PerformancePoint pp0 = convertToNativePerformancePoint(env, thiz); + VideoCapabilities::PerformancePoint pp1 = convertToNativePerformancePoint(env, other); + + bool res = pp0.covers(pp1); + return res; +} + +static jboolean android_media_VideoCapabilities_PerformancePoint_equals(JNIEnv *env, jobject thiz, + jobject other) { + VideoCapabilities::PerformancePoint pp0 = convertToNativePerformancePoint(env, thiz); + VideoCapabilities::PerformancePoint pp1 = convertToNativePerformancePoint(env, other); + + bool res = pp0.equals(pp1); + return res; +} + // ---------------------------------------------------------------------------- static const JNINativeMethod gAudioCapsMethods[] = { @@ -105,6 +167,11 @@ static const JNINativeMethod gAudioCapsMethods[] = { {"native_isSampleRateSupported", "(I)Z", (void *)android_media_AudioCapabilities_isSampleRateSupported} }; +static const JNINativeMethod gPerformancePointMethods[] = { + {"native_covers", "(Landroid/media/MediaCodecInfo$VideoCapabilities$PerformancePoint;)Z", (void *)android_media_VideoCapabilities_PerformancePoint_covers}, + {"native_equals", "(Landroid/media/MediaCodecInfo$VideoCapabilities$PerformancePoint;)Z", (void *)android_media_VideoCapabilities_PerformancePoint_equals}, +}; + int register_android_media_CodecCapabilities(JNIEnv *env) { int result = AndroidRuntime::registerNativeMethods(env, "android/media/MediaCodecInfo$AudioCapabilities$AudioCapsNativeImpl", @@ -113,5 +180,12 @@ int register_android_media_CodecCapabilities(JNIEnv *env) { return result; } + result = AndroidRuntime::registerNativeMethods(env, + "android/media/MediaCodecInfo$VideoCapabilities$PerformancePoint", + gPerformancePointMethods, NELEM(gPerformancePointMethods)); + if (result != JNI_OK) { + return result; + } + return result; }
\ No newline at end of file |