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

Commit b4b95f70 authored by Dichen Zhang's avatar Dichen Zhang Committed by Android (Google) Code Review
Browse files

Merge "MediaPlayer2: directly pass AudioAttributes to AudioTrack without native parcel conversion"

parents d65a1323 923a1736
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -246,15 +246,14 @@ public final class MediaPlayer2Impl extends MediaPlayer2 {
                    final String msg = "Cannot set AudioAttributes to null";
                    throw new IllegalArgumentException(msg);
                }
                setParameter(KEY_PARAMETER_AUDIO_ATTRIBUTES, attributes);
                native_setAudioAttributes(attributes);
            }
        });
    }

    @Override
    public @NonNull AudioAttributes getAudioAttributes() {
        AudioAttributes attributes = (AudioAttributes) getParameter(KEY_PARAMETER_AUDIO_ATTRIBUTES);
        return attributes;
        return native_getAudioAttributes();
    }

    @Override
@@ -1102,14 +1101,12 @@ public final class MediaPlayer2Impl extends MediaPlayer2 {
    // Keep KEY_PARAMETER_* in sync with include/media/mediaplayer2.h
    private final static int KEY_PARAMETER_AUDIO_ATTRIBUTES = 1400;
    /**
     * Sets the parameter indicated by key.
     * @param key key indicates the parameter to be set.
     * Sets the audio attributes.
     * @param value value of the parameter to be set.
     * @return true if the parameter is set successfully, false otherwise
     */
    private native boolean setParameter(int key, Object value);

    private native Object getParameter(int key);
    private native boolean native_setAudioAttributes(AudioAttributes audioAttributes);
    private native AudioAttributes native_getAudioAttributes();


    /**
+12 −39
Original line number Diff line number Diff line
@@ -846,56 +846,29 @@ android_media_MediaPlayer2_reset(JNIEnv *env, jobject thiz)
}

static jboolean
android_media_MediaPlayer2_setParameter(JNIEnv *env, jobject thiz, jint key, jobject)
android_media_MediaPlayer2_setAudioAttributes(JNIEnv *env, jobject thiz, jobject attributes)
{
    ALOGV("setParameter: key %d", key);
    ALOGV("setAudioAttributes");
    sp<MediaPlayer2> mp = getMediaPlayer(env, thiz);
    if (mp == NULL ) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return false;
    }

    return false;
    // TODO: set/getParameter is temporarily disabled to remove android_runtime.so dependency.
    //       Once JAudioTrack migration is done, the AudioAttribute jobject
    //       should be directly passed to AudioTrack without native parcel conversion.
    /*
    Parcel *request = parcelForJavaObject(env, java_request);
    status_t err = mp->setParameter(key, *request);
    if (err == OK) {
        return true;
    } else {
        return false;
    }
    */
    status_t err = mp->setAudioAttributes(attributes);
    return err == OK;
}

static jobject
android_media_MediaPlayer2_getParameter(JNIEnv *env, jobject thiz, jint key)
android_media_MediaPlayer2_getAudioAttributes(JNIEnv *env, jobject thiz)
{
    ALOGV("getParameter: key %d", key);
    ALOGV("getAudioAttributes");
    sp<MediaPlayer2> mp = getMediaPlayer(env, thiz);
    if (mp == NULL) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return NULL;
    }

    return NULL;
    // TODO: set/getParameter is temporarily disabled to remove android_runtime.so dependency.
    //       Once JAudioTrack migration is done, the AudioAttribute jobject
    //       should be directly passed to AudioTrack without native parcel conversion.
    /*
    jobject jParcel = createJavaParcelObject(env);
    if (jParcel != NULL) {
        Parcel* nativeParcel = parcelForJavaObject(env, jParcel);
        status_t err = mp->getParameter(key, nativeParcel);
        if (err != OK) {
            env->DeleteLocalRef(jParcel);
            return NULL;
        }
    }
    return jParcel;
    */
    return mp->getAudioAttributes();
}

static void
@@ -1437,8 +1410,8 @@ static const JNINativeMethod gMethods[] = {
    {"getDuration",         "()J",                              (void *)android_media_MediaPlayer2_getDuration},
    {"_release",            "()V",                              (void *)android_media_MediaPlayer2_release},
    {"_reset",              "()V",                              (void *)android_media_MediaPlayer2_reset},
    {"setParameter",        "(ILjava/lang/Object;)Z",          (void *)android_media_MediaPlayer2_setParameter},
    {"getParameter",        "(I)Ljava/lang/Object;",           (void *)android_media_MediaPlayer2_getParameter},
    {"native_setAudioAttributes", "(Landroid/media/AudioAttributes;)Z", (void *)android_media_MediaPlayer2_setAudioAttributes},
    {"native_getAudioAttributes", "()Landroid/media/AudioAttributes;", (void *)android_media_MediaPlayer2_getAudioAttributes},
    {"setLooping",          "(Z)V",                             (void *)android_media_MediaPlayer2_setLooping},
    {"isLooping",           "()Z",                              (void *)android_media_MediaPlayer2_isLooping},
    {"native_setVolume",    "(F)V",                             (void *)android_media_MediaPlayer2_setVolume},