Merge "Cherry-pick from master. Do not merge. Do not need to reset surface as NULL in MediaPlayer's _release. Related to bug 5252296." into ics-factoryrom

This commit is contained in:
Gloria Wang
2011-09-15 17:04:02 -07:00
committed by Android (Google) Code Review

View File

@@ -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