Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93077a29 authored by Martin Storsjo's avatar Martin Storsjo
Browse files

MediaCodec: Allow getting the codec info directly

This saves the caller from manually iterating through the
MediaCodecList for finding the right codec.

This adds new public API.

Change-Id: I8462f040573427542d86d1b957a5aef53dd55e8e
parent 056ef2ed
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11199,6 +11199,7 @@ package android.media {
    method public final int dequeueInputBuffer(long);
    method public final int dequeueOutputBuffer(android.media.MediaCodec.BufferInfo, long);
    method public final void flush();
    method public android.media.MediaCodecInfo getCodecInfo();
    method public java.nio.ByteBuffer[] getInputBuffers();
    method public final java.lang.String getName();
    method public java.nio.ByteBuffer[] getOutputBuffers();
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.media;

import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.view.Surface;
@@ -504,6 +506,16 @@ final public class MediaCodec {
     */
    public native final String getName();

    /**
     * Get the codec info. If the codec was created by createDecoderByType
     * or createEncoderByType, what component is chosen is not known beforehand,
     * and thus the caller does not have the MediaCodecInfo.
     */
    public MediaCodecInfo getCodecInfo() {
        return MediaCodecList.getCodecInfoAt(
                   MediaCodecList.findCodecByName(getName()));
    }

    private native final ByteBuffer[] getBuffers(boolean input);

    private static native final void native_init();
+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ final public class MediaCodecList {
    /* package private */ static native final MediaCodecInfo.CodecCapabilities
        getCodecCapabilities(int index, String type);

    /* package private */ static native final int findCodecByName(String codec);

    private static native final void native_init();

    private MediaCodecList() {}
+22 −0
Original line number Diff line number Diff line
@@ -44,6 +44,25 @@ static jstring android_media_MediaCodecList_getCodecName(
    return env->NewStringUTF(name);
}

static jint android_media_MediaCodecList_findCodecByName(
        JNIEnv *env, jobject thiz, jstring name) {
    if (name == NULL) {
        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
        return -ENOENT;
    }

    const char *nameStr = env->GetStringUTFChars(name, NULL);

    if (nameStr == NULL) {
        // Out of memory exception already pending.
        return -ENOENT;
    }

    jint ret = MediaCodecList::getInstance()->findCodecByName(nameStr);
    env->ReleaseStringUTFChars(name, nameStr);
    return ret;
}

static jboolean android_media_MediaCodecList_isEncoder(
        JNIEnv *env, jobject thiz, jint index) {
    return MediaCodecList::getInstance()->isEncoder(index);
@@ -180,6 +199,9 @@ static JNINativeMethod gMethods[] = {
      "(ILjava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;",
      (void *)android_media_MediaCodecList_getCodecCapabilities },

    { "findCodecByName", "(Ljava/lang/String;)I",
      (void *)android_media_MediaCodecList_findCodecByName },

    { "native_init", "()V", (void *)android_media_MediaCodecList_native_init },
};