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

Commit 2644494a authored by Andreas Huber's avatar Andreas Huber Committed by Gerrit Code Review
Browse files

Merge changes I8462f040,Ie471f40f

* changes:
  MediaCodec: Allow getting the codec info directly
  MediaCodec: Allow getting the chosen component name
parents 940ad4aa 93077a29
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -11199,7 +11199,9 @@ 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();
    method public final android.media.MediaFormat getOutputFormat();
    method public final void queueInputBuffer(int, int, int, long, int) throws android.media.MediaCodec.CryptoException;
+18 −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;
@@ -498,6 +500,22 @@ final public class MediaCodec {
     */
    public native final void setVideoScalingMode(int mode);

    /**
     * Get the component name. If the codec was created by createDecoderByType
     * or createEncoderByType, what component is chosen is not known beforehand.
     */
    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() {}
+40 −0
Original line number Diff line number Diff line
@@ -264,6 +264,20 @@ status_t JMediaCodec::getBuffers(
    return OK;
}

status_t JMediaCodec::getName(JNIEnv *env, jstring *nameStr) const {
    AString name;

    status_t err = mCodec->getName(&name);

    if (err != OK) {
        return err;
    }

    *nameStr = env->NewStringUTF(name.c_str());

    return OK;
}

void JMediaCodec::setVideoScalingMode(int mode) {
    if (mSurfaceTextureClient != NULL) {
        native_window_set_scaling_mode(mSurfaceTextureClient.get(), mode);
@@ -706,6 +720,29 @@ static jobjectArray android_media_MediaCodec_getBuffers(
    return NULL;
}

static jobject android_media_MediaCodec_getName(
        JNIEnv *env, jobject thiz) {
    ALOGV("android_media_MediaCodec_getName");

    sp<JMediaCodec> codec = getMediaCodec(env, thiz);

    if (codec == NULL) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return NULL;
    }

    jstring name;
    status_t err = codec->getName(env, &name);

    if (err == OK) {
        return name;
    }

    throwExceptionAsNecessary(env, err);

    return NULL;
}

static void android_media_MediaCodec_setVideoScalingMode(
        JNIEnv *env, jobject thiz, jint mode) {
    sp<JMediaCodec> codec = getMediaCodec(env, thiz);
@@ -826,6 +863,9 @@ static JNINativeMethod gMethods[] = {
    { "getBuffers", "(Z)[Ljava/nio/ByteBuffer;",
      (void *)android_media_MediaCodec_getBuffers },

    { "getName", "()Ljava/lang/String;",
      (void *)android_media_MediaCodec_getName },

    { "setVideoScalingMode", "(I)V",
      (void *)android_media_MediaCodec_setVideoScalingMode },

+2 −0
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ struct JMediaCodec : public RefBase {
    status_t getBuffers(
            JNIEnv *env, bool input, jobjectArray *bufArray) const;

    status_t getName(JNIEnv *env, jstring *name) const;

    void setVideoScalingMode(int mode);

protected:
Loading