From 7dae00baa6e8957be15523c46bb948bd1dde64c3 Mon Sep 17 00:00:00 2001 From: Jamie Gennis Date: Wed, 26 Oct 2011 18:36:31 -0700 Subject: Stagefright: ANW::connect in MediaPlayerService This change moves the ANativeWindow connect and disconnect logic from MediaPlayer to MediaPlayerService::Client. Bug: 5502654 Change-Id: Ifc43b98b01ad8f35d62d7ece43110724ec7fda3d --- media/libmedia/mediaplayer.cpp | 98 +----------------------------------------- 1 file changed, 2 insertions(+), 96 deletions(-) (limited to 'media/libmedia/mediaplayer.cpp') diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp index 37a82e9..f72300b 100644 --- a/media/libmedia/mediaplayer.cpp +++ b/media/libmedia/mediaplayer.cpp @@ -86,8 +86,6 @@ void MediaPlayer::disconnect() if (p != 0) { p->disconnect(); } - - disconnectNativeWindow(); } // always call with lock held @@ -221,63 +219,12 @@ status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *m return mPlayer->getMetadata(update_only, apply_filter, metadata); } -void MediaPlayer::disconnectNativeWindow() { - if (mConnectedWindow != NULL) { - status_t err = native_window_api_disconnect(mConnectedWindow.get(), - NATIVE_WINDOW_API_MEDIA); - - if (err != OK) { - LOGW("native_window_api_disconnect returned an error: %s (%d)", - strerror(-err), err); - } - } - mConnectedWindow.clear(); -} - status_t MediaPlayer::setVideoSurface(const sp& surface) { LOGV("setVideoSurface"); Mutex::Autolock _l(mLock); if (mPlayer == 0) return NO_INIT; - - sp binder(surface == NULL ? NULL : surface->asBinder()); - if (mConnectedWindowBinder == binder) { - return OK; - } - - if (surface != NULL) { - status_t err = native_window_api_connect(surface.get(), - NATIVE_WINDOW_API_MEDIA); - - if (err != OK) { - LOGE("setVideoSurface failed: %d", err); - // Note that we must do the reset before disconnecting from the ANW. - // Otherwise queue/dequeue calls could be made on the disconnected - // ANW, which may result in errors. - reset_l(); - - disconnectNativeWindow(); - - return err; - } - } - - // Note that we must set the player's new surface before disconnecting the - // old one. Otherwise queue/dequeue calls could be made on the disconnected - // ANW, which may result in errors. - status_t err = mPlayer->setVideoSurface(surface); - - disconnectNativeWindow(); - - mConnectedWindow = surface; - - if (err == OK) { - mConnectedWindowBinder = binder; - } else { - disconnectNativeWindow(); - } - - return err; + return mPlayer->setVideoSurface(surface); } status_t MediaPlayer::setVideoSurfaceTexture( @@ -286,48 +233,7 @@ status_t MediaPlayer::setVideoSurfaceTexture( LOGV("setVideoSurfaceTexture"); Mutex::Autolock _l(mLock); if (mPlayer == 0) return NO_INIT; - - sp binder(surfaceTexture == NULL ? NULL : - surfaceTexture->asBinder()); - if (mConnectedWindowBinder == binder) { - return OK; - } - - sp anw; - if (surfaceTexture != NULL) { - anw = new SurfaceTextureClient(surfaceTexture); - status_t err = native_window_api_connect(anw.get(), - NATIVE_WINDOW_API_MEDIA); - - if (err != OK) { - LOGE("setVideoSurfaceTexture failed: %d", err); - // Note that we must do the reset before disconnecting from the ANW. - // Otherwise queue/dequeue calls could be made on the disconnected - // ANW, which may result in errors. - reset_l(); - - disconnectNativeWindow(); - - return err; - } - } - - // Note that we must set the player's new SurfaceTexture before - // disconnecting the old one. Otherwise queue/dequeue calls could be made - // on the disconnected ANW, which may result in errors. - status_t err = mPlayer->setVideoSurfaceTexture(surfaceTexture); - - disconnectNativeWindow(); - - mConnectedWindow = anw; - - if (err == OK) { - mConnectedWindowBinder = binder; - } else { - disconnectNativeWindow(); - } - - return err; + return mPlayer->setVideoSurfaceTexture(surfaceTexture); } // must call with lock held -- cgit v1.1