@@ -244,6 +244,15 @@ getVideoSurfaceTexture(JNIEnv* env, jobject thiz) {
244244 return sp<ISurfaceTexture>(p);
245245}
246246
247+ static void
248+ decVideoSurfaceRef (JNIEnv *env, jobject thiz)
249+ {
250+ sp<ISurfaceTexture> old_st = getVideoSurfaceTexture (env, thiz);
251+ if (old_st != NULL ) {
252+ old_st->decStrong (thiz);
253+ }
254+ }
255+
247256static void
248257setVideoSurface (JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlayerMustBeAlive)
249258{
@@ -255,16 +264,15 @@ setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface, jboolean mediaPlaye
255264 return ;
256265 }
257266
258- sp<ISurfaceTexture> old_st = getVideoSurfaceTexture (env, thiz);
267+ decVideoSurfaceRef (env, thiz);
268+
259269 sp<ISurfaceTexture> new_st;
260270 if (jsurface) {
261271 sp<Surface> surface (Surface_getSurface (env, jsurface));
262272 new_st = surface->getSurfaceTexture ();
263273 new_st->incStrong (thiz);
264274 }
265- if (old_st != NULL ) {
266- old_st->decStrong (thiz);
267- }
275+
268276 env->SetIntField (thiz, fields.surface_texture , (int )new_st.get ());
269277
270278 // This will fail if the media player has not been initialized yet. This
@@ -625,7 +633,7 @@ static void
625633android_media_MediaPlayer_release (JNIEnv *env, jobject thiz)
626634{
627635 LOGV (" release" );
628- setVideoSurface (env, thiz, NULL , false /* mediaPlayerMustBeAlive */ );
636+ decVideoSurfaceRef (env, thiz);
629637 sp<MediaPlayer> mp = setMediaPlayer (env, thiz, 0 );
630638 if (mp != NULL ) {
631639 // this prevents native callbacks after the object is released
0 commit comments