Skip to content

Commit 62c24d7

Browse files
Gloria WangAndroid (Google) Code Review
authored andcommitted
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
2 parents 68901a3 + c286b2c commit 62c24d7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

media/jni/android_media_MediaPlayer.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
247256
static void
248257
setVideoSurface(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
625633
android_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

Comments
 (0)