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

Commit 056ef2ed authored by Martin Storsjo's avatar Martin Storsjo
Browse files

MediaCodec: Allow getting the chosen component name

Currently, when the codec was opened by createDecoder/EncoderByType,
the caller does not know what codec actually was chosen, and
(for encoders) thus cannot know what color formats it supports.

This adds new public API.

Change-Id: Ie471f40f8104b37d27ced3dba5a54facc6504b1b
parent 4299f63e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11200,6 +11200,7 @@ package android.media {
    method public final int dequeueOutputBuffer(android.media.MediaCodec.BufferInfo, long);
    method public final void flush();
    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;
+6 −0
Original line number Diff line number Diff line
@@ -498,6 +498,12 @@ 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();

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

    private static native final void native_init();
+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: