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

Commit c286b2cc authored by Gloria Wang's avatar Gloria Wang
Browse files

Cherry-pick from master. Do not merge.

Do not need to reset surface as NULL in MediaPlayer's _release.
Related to bug 5252296.

Change-Id: Ieab063cee70e072fcc4d861abe0f7979a7bab1ec
parent cb995121
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -244,6 +244,15 @@ getVideoSurfaceTexture(JNIEnv* env, jobject thiz) {
    return sp<ISurfaceTexture>(p);
}

static void
decVideoSurfaceRef(JNIEnv *env, jobject thiz)
{
    sp<ISurfaceTexture> old_st = getVideoSurfaceTexture(env, thiz);
    if (old_st != NULL) {
        old_st->decStrong(thiz);
    }
}

static void
setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlayerMustBeAlive)
{
@@ -255,16 +264,15 @@ setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlaye
        return;
    }

    sp<ISurfaceTexture> old_st = getVideoSurfaceTexture(env, thiz);
    decVideoSurfaceRef(env, thiz);

    sp<ISurfaceTexture> new_st;
    if (jsurface) {
        sp<Surface> surface(Surface_getSurface(env, jsurface));
        new_st = surface->getSurfaceTexture();
        new_st->incStrong(thiz);
    }
    if (old_st != NULL) {
        old_st->decStrong(thiz);
    }

    env->SetIntField(thiz, fields.surface_texture, (int)new_st.get());

    // This will fail if the media player has not been initialized yet. This
@@ -625,7 +633,7 @@ static void
android_media_MediaPlayer_release(JNIEnv *env, jobject thiz)
{
    LOGV("release");
    setVideoSurface(env, thiz, NULL, false /* mediaPlayerMustBeAlive */);
    decVideoSurfaceRef(env, thiz);
    sp<MediaPlayer> mp = setMediaPlayer(env, thiz, 0);
    if (mp != NULL) {
        // this prevents native callbacks after the object is released