Loading include/media/stagefright/SurfaceUtils.h +2 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ status_t setNativeWindowSizeFormatAndUsage( ANativeWindow *nativeWindow /* nonnull */, int width, int height, int format, int rotation, int usage, bool reconnect); status_t pushBlankBuffersToNativeWindow(ANativeWindow *nativeWindow /* nonnull */); status_t nativeWindowConnect(ANativeWindow *surface, const char *reason); status_t nativeWindowDisconnect(ANativeWindow *surface, const char *reason); } // namespace android Loading media/libmediaplayerservice/MediaPlayerService.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ #include <media/stagefright/Utils.h> #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/ALooperRoster.h> #include <media/stagefright/SurfaceUtils.h> #include <mediautils/BatteryNotifier.h> #include <memunreachable/memunreachable.h> Loading Loading @@ -903,11 +904,11 @@ status_t MediaPlayerService::Client::setDataSource( void MediaPlayerService::Client::disconnectNativeWindow() { if (mConnectedWindow != NULL) { status_t err = native_window_api_disconnect(mConnectedWindow.get(), NATIVE_WINDOW_API_MEDIA); status_t err = nativeWindowDisconnect( mConnectedWindow.get(), "disconnectNativeWindow"); if (err != OK) { ALOGW("native_window_api_disconnect returned an error: %s (%d)", ALOGW("nativeWindowDisconnect returned an error: %s (%d)", strerror(-err), err); } } Loading @@ -929,8 +930,7 @@ status_t MediaPlayerService::Client::setVideoSurfaceTexture( sp<ANativeWindow> anw; if (bufferProducer != NULL) { anw = new Surface(bufferProducer, true /* controlledByApp */); status_t err = native_window_api_connect(anw.get(), NATIVE_WINDOW_API_MEDIA); status_t err = nativeWindowConnect(anw.get(), "setVideoSurfaceTexture"); if (err != OK) { ALOGE("setVideoSurfaceTexture failed: %d", err); Loading media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp +6 −8 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ #include <media/stagefright/MediaCodec.h> #include <media/stagefright/MediaDefs.h> #include <media/stagefright/MediaErrors.h> #include <media/stagefright/SurfaceUtils.h> #include <gui/Surface.h> #include "avc_utils.h" Loading Loading @@ -232,21 +232,21 @@ void NuPlayer::Decoder::onMessageReceived(const sp<AMessage> &msg) { // // at this point MediaPlayerService::client has already connected to the // surface, which MediaCodec does not expect err = native_window_api_disconnect(surface.get(), NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(surface.get(), "kWhatSetVideoSurface(surface)"); if (err == OK) { err = mCodec->setSurface(surface); ALOGI_IF(err, "codec setSurface returned: %d", err); if (err == OK) { // reconnect to the old surface as MPS::Client will expect to // be able to disconnect from it. (void)native_window_api_connect(mSurface.get(), NATIVE_WINDOW_API_MEDIA); (void)nativeWindowConnect(mSurface.get(), "kWhatSetVideoSurface(mSurface)"); mSurface = surface; } } if (err != OK) { // reconnect to the new surface on error as MPS::Client will expect to // be able to disconnect from it. (void)native_window_api_connect(surface.get(), NATIVE_WINDOW_API_MEDIA); (void)nativeWindowConnect(surface.get(), "kWhatSetVideoSurface(err)"); } } Loading Loading @@ -313,8 +313,7 @@ void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) { status_t err; if (mSurface != NULL) { // disconnect from surface as MediaCodec will reconnect err = native_window_api_disconnect( mSurface.get(), NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(mSurface.get(), "onConfigure"); // We treat this as a warning, as this is a preparatory step. // Codec will try to connect to the surface, which is where // any error signaling will occur. Loading Loading @@ -510,8 +509,7 @@ void NuPlayer::Decoder::onShutdown(bool notifyComplete) { if (mSurface != NULL) { // reconnect to surface as MediaCodec disconnected from it status_t error = native_window_api_connect(mSurface.get(), NATIVE_WINDOW_API_MEDIA); status_t error = nativeWindowConnect(mSurface.get(), "onShutdown"); ALOGW_IF(error != NO_ERROR, "[%s] failed to connect to native window, error=%d", mComponentName.c_str(), error); Loading media/libstagefright/MediaCodec.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -2914,7 +2914,7 @@ status_t MediaCodec::connectToSurface(const sp<Surface> &surface) { return ALREADY_EXISTS; } err = native_window_api_connect(surface.get(), NATIVE_WINDOW_API_MEDIA); err = nativeWindowConnect(surface.get(), "connectToSurface"); if (err == OK) { // Require a fresh set of buffers after each connect by using a unique generation // number. Rely on the fact that max supported process id by Linux is 2^22. Loading @@ -2929,12 +2929,12 @@ status_t MediaCodec::connectToSurface(const sp<Surface> &surface) { // This is needed as the consumer may be holding onto stale frames that it can reattach // to this surface after disconnect/connect, and those free frames would inherit the new // generation number. Disconnecting after setting a unique generation prevents this. native_window_api_disconnect(surface.get(), NATIVE_WINDOW_API_MEDIA); err = native_window_api_connect(surface.get(), NATIVE_WINDOW_API_MEDIA); nativeWindowDisconnect(surface.get(), "connectToSurface(reconnect)"); err = nativeWindowConnect(surface.get(), "connectToSurface(reconnect)"); } if (err != OK) { ALOGE("native_window_api_connect returned an error: %s (%d)", strerror(-err), err); ALOGE("nativeWindowConnect returned an error: %s (%d)", strerror(-err), err); } } // do not return ALREADY_EXISTS unless surfaces are the same Loading @@ -2946,9 +2946,9 @@ status_t MediaCodec::disconnectFromSurface() { if (mSurface != NULL) { // Resetting generation is not technically needed, but there is no need to keep it either mSurface->setGenerationNumber(0); err = native_window_api_disconnect(mSurface.get(), NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(mSurface.get(), "disconnectFromSurface"); if (err != OK) { ALOGW("native_window_api_disconnect returned an error: %s (%d)", strerror(-err), err); ALOGW("nativeWindowDisconnect returned an error: %s (%d)", strerror(-err), err); } // assume disconnected even on error mSurface.clear(); Loading media/libstagefright/SurfaceUtils.cpp +24 −7 Original line number Diff line number Diff line Loading @@ -31,15 +31,15 @@ status_t setNativeWindowSizeFormatAndUsage( // In some cases we need to reconnect so that we can dequeue all buffers if (reconnect) { err = native_window_api_disconnect(nativeWindow, NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(nativeWindow, "setNativeWindowSizeFormatAndUsage"); if (err != NO_ERROR) { ALOGE("native_window_api_disconnect failed: %s (%d)", strerror(-err), -err); ALOGE("nativeWindowDisconnect failed: %s (%d)", strerror(-err), -err); return err; } err = native_window_api_connect(nativeWindow, NATIVE_WINDOW_API_MEDIA); err = nativeWindowConnect(nativeWindow, "setNativeWindowSizeFormatAndUsage"); if (err != NO_ERROR) { ALOGE("native_window_api_connect failed: %s (%d)", strerror(-err), -err); ALOGE("nativeWindowConnect failed: %s (%d)", strerror(-err), -err); return err; } } Loading Loading @@ -127,7 +127,7 @@ status_t pushBlankBuffersToNativeWindow(ANativeWindow *nativeWindow /* nonnull * // We need to reconnect to the ANativeWindow as a CPU client to ensure that // no frames get dropped by SurfaceFlinger assuming that these are video // frames. err = native_window_api_disconnect(nativeWindow, NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(nativeWindow, "pushBlankBuffersToNativeWindow"); if (err != NO_ERROR) { ALOGE("error pushing blank frames: api_disconnect failed: %s (%d)", strerror(-err), -err); return err; Loading @@ -136,7 +136,7 @@ status_t pushBlankBuffersToNativeWindow(ANativeWindow *nativeWindow /* nonnull * err = native_window_api_connect(nativeWindow, NATIVE_WINDOW_API_CPU); if (err != NO_ERROR) { ALOGE("error pushing blank frames: api_connect failed: %s (%d)", strerror(-err), -err); (void)native_window_api_connect(nativeWindow, NATIVE_WINDOW_API_MEDIA); (void)nativeWindowConnect(nativeWindow, "pushBlankBuffersToNativeWindow(err)"); return err; } Loading Loading @@ -219,7 +219,7 @@ error: } } err2 = native_window_api_connect(nativeWindow, NATIVE_WINDOW_API_MEDIA); err2 = nativeWindowConnect(nativeWindow, "pushBlankBuffersToNativeWindow(err2)"); if (err2 != NO_ERROR) { ALOGE("error pushing blank frames: api_connect failed: %s (%d)", strerror(-err), -err); if (err == NO_ERROR) { Loading @@ -230,5 +230,22 @@ error: return err; } status_t nativeWindowConnect(ANativeWindow *surface, const char *reason) { ALOGD("connecting to surface %p, reason %s", surface, reason); status_t err = native_window_api_connect(surface, NATIVE_WINDOW_API_MEDIA); ALOGE_IF(err != OK, "Failed to connect to surface %p, err %d", surface, err); return err; } status_t nativeWindowDisconnect(ANativeWindow *surface, const char *reason) { ALOGD("disconnecting from surface %p, reason %s", surface, reason); status_t err = native_window_api_disconnect(surface, NATIVE_WINDOW_API_MEDIA); ALOGE_IF(err != OK, "Failed to disconnect from surface %p, err %d", surface, err); return err; } } // namespace android Loading
include/media/stagefright/SurfaceUtils.h +2 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ status_t setNativeWindowSizeFormatAndUsage( ANativeWindow *nativeWindow /* nonnull */, int width, int height, int format, int rotation, int usage, bool reconnect); status_t pushBlankBuffersToNativeWindow(ANativeWindow *nativeWindow /* nonnull */); status_t nativeWindowConnect(ANativeWindow *surface, const char *reason); status_t nativeWindowDisconnect(ANativeWindow *surface, const char *reason); } // namespace android Loading
media/libmediaplayerservice/MediaPlayerService.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ #include <media/stagefright/Utils.h> #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/ALooperRoster.h> #include <media/stagefright/SurfaceUtils.h> #include <mediautils/BatteryNotifier.h> #include <memunreachable/memunreachable.h> Loading Loading @@ -903,11 +904,11 @@ status_t MediaPlayerService::Client::setDataSource( void MediaPlayerService::Client::disconnectNativeWindow() { if (mConnectedWindow != NULL) { status_t err = native_window_api_disconnect(mConnectedWindow.get(), NATIVE_WINDOW_API_MEDIA); status_t err = nativeWindowDisconnect( mConnectedWindow.get(), "disconnectNativeWindow"); if (err != OK) { ALOGW("native_window_api_disconnect returned an error: %s (%d)", ALOGW("nativeWindowDisconnect returned an error: %s (%d)", strerror(-err), err); } } Loading @@ -929,8 +930,7 @@ status_t MediaPlayerService::Client::setVideoSurfaceTexture( sp<ANativeWindow> anw; if (bufferProducer != NULL) { anw = new Surface(bufferProducer, true /* controlledByApp */); status_t err = native_window_api_connect(anw.get(), NATIVE_WINDOW_API_MEDIA); status_t err = nativeWindowConnect(anw.get(), "setVideoSurfaceTexture"); if (err != OK) { ALOGE("setVideoSurfaceTexture failed: %d", err); Loading
media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp +6 −8 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ #include <media/stagefright/MediaCodec.h> #include <media/stagefright/MediaDefs.h> #include <media/stagefright/MediaErrors.h> #include <media/stagefright/SurfaceUtils.h> #include <gui/Surface.h> #include "avc_utils.h" Loading Loading @@ -232,21 +232,21 @@ void NuPlayer::Decoder::onMessageReceived(const sp<AMessage> &msg) { // // at this point MediaPlayerService::client has already connected to the // surface, which MediaCodec does not expect err = native_window_api_disconnect(surface.get(), NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(surface.get(), "kWhatSetVideoSurface(surface)"); if (err == OK) { err = mCodec->setSurface(surface); ALOGI_IF(err, "codec setSurface returned: %d", err); if (err == OK) { // reconnect to the old surface as MPS::Client will expect to // be able to disconnect from it. (void)native_window_api_connect(mSurface.get(), NATIVE_WINDOW_API_MEDIA); (void)nativeWindowConnect(mSurface.get(), "kWhatSetVideoSurface(mSurface)"); mSurface = surface; } } if (err != OK) { // reconnect to the new surface on error as MPS::Client will expect to // be able to disconnect from it. (void)native_window_api_connect(surface.get(), NATIVE_WINDOW_API_MEDIA); (void)nativeWindowConnect(surface.get(), "kWhatSetVideoSurface(err)"); } } Loading Loading @@ -313,8 +313,7 @@ void NuPlayer::Decoder::onConfigure(const sp<AMessage> &format) { status_t err; if (mSurface != NULL) { // disconnect from surface as MediaCodec will reconnect err = native_window_api_disconnect( mSurface.get(), NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(mSurface.get(), "onConfigure"); // We treat this as a warning, as this is a preparatory step. // Codec will try to connect to the surface, which is where // any error signaling will occur. Loading Loading @@ -510,8 +509,7 @@ void NuPlayer::Decoder::onShutdown(bool notifyComplete) { if (mSurface != NULL) { // reconnect to surface as MediaCodec disconnected from it status_t error = native_window_api_connect(mSurface.get(), NATIVE_WINDOW_API_MEDIA); status_t error = nativeWindowConnect(mSurface.get(), "onShutdown"); ALOGW_IF(error != NO_ERROR, "[%s] failed to connect to native window, error=%d", mComponentName.c_str(), error); Loading
media/libstagefright/MediaCodec.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -2914,7 +2914,7 @@ status_t MediaCodec::connectToSurface(const sp<Surface> &surface) { return ALREADY_EXISTS; } err = native_window_api_connect(surface.get(), NATIVE_WINDOW_API_MEDIA); err = nativeWindowConnect(surface.get(), "connectToSurface"); if (err == OK) { // Require a fresh set of buffers after each connect by using a unique generation // number. Rely on the fact that max supported process id by Linux is 2^22. Loading @@ -2929,12 +2929,12 @@ status_t MediaCodec::connectToSurface(const sp<Surface> &surface) { // This is needed as the consumer may be holding onto stale frames that it can reattach // to this surface after disconnect/connect, and those free frames would inherit the new // generation number. Disconnecting after setting a unique generation prevents this. native_window_api_disconnect(surface.get(), NATIVE_WINDOW_API_MEDIA); err = native_window_api_connect(surface.get(), NATIVE_WINDOW_API_MEDIA); nativeWindowDisconnect(surface.get(), "connectToSurface(reconnect)"); err = nativeWindowConnect(surface.get(), "connectToSurface(reconnect)"); } if (err != OK) { ALOGE("native_window_api_connect returned an error: %s (%d)", strerror(-err), err); ALOGE("nativeWindowConnect returned an error: %s (%d)", strerror(-err), err); } } // do not return ALREADY_EXISTS unless surfaces are the same Loading @@ -2946,9 +2946,9 @@ status_t MediaCodec::disconnectFromSurface() { if (mSurface != NULL) { // Resetting generation is not technically needed, but there is no need to keep it either mSurface->setGenerationNumber(0); err = native_window_api_disconnect(mSurface.get(), NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(mSurface.get(), "disconnectFromSurface"); if (err != OK) { ALOGW("native_window_api_disconnect returned an error: %s (%d)", strerror(-err), err); ALOGW("nativeWindowDisconnect returned an error: %s (%d)", strerror(-err), err); } // assume disconnected even on error mSurface.clear(); Loading
media/libstagefright/SurfaceUtils.cpp +24 −7 Original line number Diff line number Diff line Loading @@ -31,15 +31,15 @@ status_t setNativeWindowSizeFormatAndUsage( // In some cases we need to reconnect so that we can dequeue all buffers if (reconnect) { err = native_window_api_disconnect(nativeWindow, NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(nativeWindow, "setNativeWindowSizeFormatAndUsage"); if (err != NO_ERROR) { ALOGE("native_window_api_disconnect failed: %s (%d)", strerror(-err), -err); ALOGE("nativeWindowDisconnect failed: %s (%d)", strerror(-err), -err); return err; } err = native_window_api_connect(nativeWindow, NATIVE_WINDOW_API_MEDIA); err = nativeWindowConnect(nativeWindow, "setNativeWindowSizeFormatAndUsage"); if (err != NO_ERROR) { ALOGE("native_window_api_connect failed: %s (%d)", strerror(-err), -err); ALOGE("nativeWindowConnect failed: %s (%d)", strerror(-err), -err); return err; } } Loading Loading @@ -127,7 +127,7 @@ status_t pushBlankBuffersToNativeWindow(ANativeWindow *nativeWindow /* nonnull * // We need to reconnect to the ANativeWindow as a CPU client to ensure that // no frames get dropped by SurfaceFlinger assuming that these are video // frames. err = native_window_api_disconnect(nativeWindow, NATIVE_WINDOW_API_MEDIA); err = nativeWindowDisconnect(nativeWindow, "pushBlankBuffersToNativeWindow"); if (err != NO_ERROR) { ALOGE("error pushing blank frames: api_disconnect failed: %s (%d)", strerror(-err), -err); return err; Loading @@ -136,7 +136,7 @@ status_t pushBlankBuffersToNativeWindow(ANativeWindow *nativeWindow /* nonnull * err = native_window_api_connect(nativeWindow, NATIVE_WINDOW_API_CPU); if (err != NO_ERROR) { ALOGE("error pushing blank frames: api_connect failed: %s (%d)", strerror(-err), -err); (void)native_window_api_connect(nativeWindow, NATIVE_WINDOW_API_MEDIA); (void)nativeWindowConnect(nativeWindow, "pushBlankBuffersToNativeWindow(err)"); return err; } Loading Loading @@ -219,7 +219,7 @@ error: } } err2 = native_window_api_connect(nativeWindow, NATIVE_WINDOW_API_MEDIA); err2 = nativeWindowConnect(nativeWindow, "pushBlankBuffersToNativeWindow(err2)"); if (err2 != NO_ERROR) { ALOGE("error pushing blank frames: api_connect failed: %s (%d)", strerror(-err), -err); if (err == NO_ERROR) { Loading @@ -230,5 +230,22 @@ error: return err; } status_t nativeWindowConnect(ANativeWindow *surface, const char *reason) { ALOGD("connecting to surface %p, reason %s", surface, reason); status_t err = native_window_api_connect(surface, NATIVE_WINDOW_API_MEDIA); ALOGE_IF(err != OK, "Failed to connect to surface %p, err %d", surface, err); return err; } status_t nativeWindowDisconnect(ANativeWindow *surface, const char *reason) { ALOGD("disconnecting from surface %p, reason %s", surface, reason); status_t err = native_window_api_disconnect(surface, NATIVE_WINDOW_API_MEDIA); ALOGE_IF(err != OK, "Failed to disconnect from surface %p, err %d", surface, err); return err; } } // namespace android