From 0fc736f321b01995d9f5913d2490cbb479554266 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Fri, 10 Jul 2009 09:34:59 -0700 Subject: Don't pass references to temporary objects, and handle the case where we dont have a Surface. --- media/jni/android_media_MediaPlayer.cpp | 9 ++++----- media/libmedia/mediaplayer.cpp | 5 ++++- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'media') diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp index b173129..d26d039 100644 --- a/media/jni/android_media_MediaPlayer.cpp +++ b/media/jni/android_media_MediaPlayer.cpp @@ -101,10 +101,9 @@ void JNIMediaPlayerListener::notify(int msg, int ext1, int ext2) // ---------------------------------------------------------------------------- -static sp get_surface(JNIEnv* env, jobject clazz) +static Surface* get_surface(JNIEnv* env, jobject clazz) { - Surface* const p = (Surface*)env->GetIntField(clazz, fields.surface_native); - return sp(p); + return (Surface*)env->GetIntField(clazz, fields.surface_native); } static sp getMediaPlayer(JNIEnv* env, jobject thiz) @@ -205,7 +204,7 @@ static void setVideoSurface(const sp& mp, JNIEnv *env, jobject thiz { jobject surface = env->GetObjectField(thiz, fields.surface); if (surface != NULL) { - const sp& native_surface = get_surface(env, surface); + const sp native_surface = get_surface(env, surface); LOGV("prepare: surface=%p (id=%d)", native_surface.get(), native_surface->ID()); mp->setVideoSurface(native_surface); @@ -245,7 +244,7 @@ android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz) } jobject surface = env->GetObjectField(thiz, fields.surface); if (surface != NULL) { - const sp& native_surface = get_surface(env, surface); + const sp native_surface = get_surface(env, surface); LOGV("prepareAsync: surface=%p (id=%d)", native_surface.get(), native_surface->ID()); mp->setVideoSurface(native_surface); diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp index 6b35fa7..aeb43c5 100644 --- a/media/libmedia/mediaplayer.cpp +++ b/media/libmedia/mediaplayer.cpp @@ -233,7 +233,10 @@ status_t MediaPlayer::setVideoSurface(const sp& surface) LOGV("setVideoSurface"); Mutex::Autolock _l(mLock); if (mPlayer == 0) return NO_INIT; - return mPlayer->setVideoSurface(surface->getISurface()); + if (surface != NULL) + return mPlayer->setVideoSurface(surface->getISurface()); + else + return mPlayer->setVideoSurface(NULL); } // must call with lock held -- cgit v1.1