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

Commit 43ef9138 authored by James Dong's avatar James Dong
Browse files

If release has been called before finalize, do not expect MediaPlayer still exists

o also, we should releae the surface object when release is called, not wait until finalize is called.

related-to-bug: 5157956

Change-Id: I0233ad61d8349c3e3800de68b752b9548ece1742
parent 6e97ed21
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ android_media_MediaPlayer_setDataSourceAndHeaders(
    if (tmp == NULL) {  // Out of memory
        return;
    }
    LOGV("setDataSource: path %s", tmp);

    String8 pathStr(tmp);
    env->ReleaseStringUTFChars(path, tmp);
@@ -201,7 +202,6 @@ android_media_MediaPlayer_setDataSourceAndHeaders(
        return;
    }

    LOGV("setDataSource: path %s", pathStr);
    status_t opStatus =
        mp->setDataSource(
                pathStr,
@@ -243,11 +243,13 @@ getVideoSurfaceTexture(JNIEnv* env, jobject thiz) {
}

static void
android_media_MediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface)
setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlayerMustBeAlive)
{
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    if (mp == NULL) {
        if (mediaPlayerMustBeAlive) {
            jniThrowException(env, "java/lang/IllegalStateException", NULL);
        }
        return;
    }

@@ -270,6 +272,12 @@ android_media_MediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsu
    mp->setVideoSurfaceTexture(new_st);
}

static void
android_media_MediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface)
{
    setVideoSurface(env, thiz, jsurface, true /* mediaPlayerMustBeAlive */);
}

static void
android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz)
{
@@ -615,6 +623,7 @@ static void
android_media_MediaPlayer_release(JNIEnv *env, jobject thiz)
{
    LOGV("release");
    setVideoSurface(env, thiz, NULL, false /* mediaPlayerMustBeAlive */);
    sp<MediaPlayer> mp = setMediaPlayer(env, thiz, 0);
    if (mp != NULL) {
        // this prevents native callbacks after the object is released
@@ -627,7 +636,6 @@ static void
android_media_MediaPlayer_native_finalize(JNIEnv *env, jobject thiz)
{
    LOGV("native_finalize");
    android_media_MediaPlayer_setVideoSurface(env, thiz, NULL);
    android_media_MediaPlayer_release(env, thiz);
}