From 815dd298dc903606181afee3aec23e9cee629e8f Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 18 Apr 2013 13:24:17 -0700 Subject: Make sure MediaCodec::stop() and MediaCodec::release() still return instead of blocking indefinitely if the mediaserver died while the call is pending. Change-Id: If2789b7fe99634d947ce4a3bb69c04baff5f8b10 related-to-bug: 8397711 --- media/libstagefright/MediaCodec.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'media/libstagefright/MediaCodec.cpp') diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index 0d89c0f..e4e95d2 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -534,6 +534,20 @@ void MediaCodec::onMessageReceived(const sp &msg) { // the shutdown complete notification. sendErrorReponse = false; + + if (omxError == OMX_ErrorResourcesLost + && internalError == DEAD_OBJECT) { + // MediaServer died, there definitely won't + // be a shutdown complete notification after + // all. + + // note that we're directly going from + // STOPPING->UNINITIALIZED, instead of the + // usual STOPPING->INITIALIZED state. + setState(UNINITIALIZED); + + (new AMessage)->postReply(mReplyID); + } break; } @@ -1013,8 +1027,16 @@ void MediaCodec::onMessageReceived(const sp &msg) { if (mState != INITIALIZED && mState != CONFIGURED && mState != STARTED) { + // We may be in "UNINITIALIZED" state already without the + // client being aware of this if media server died while + // we were being stopped. The client would assume that + // after stop() returned, it would be safe to call release() + // and it should be in this case, no harm to allow a release() + // if we're already uninitialized. sp response = new AMessage; - response->setInt32("err", INVALID_OPERATION); + response->setInt32( + "err", + mState == UNINITIALIZED ? OK : INVALID_OPERATION); response->postReply(replyID); break; -- cgit v1.1