From: Lajos Molnar Date: Tue, 21 Oct 2014 23:07:52 +0000 (-0700) Subject: stagefright: try to free codec instance if MediaCodec.release hangs X-Git-Tag: android-x86-6.0-r1~852^2~155^2~10^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=30358faf33fb9b638257b017fadb4c5f7352d903;p=android-x86%2Fframeworks-av.git stagefright: try to free codec instance if MediaCodec.release hangs Bug: 18033275 Change-Id: If86cd26566d7b75941976f37829bbec619800778 --- diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h index d77ddaf8f8..fcccc6d565 100644 --- a/include/media/stagefright/ACodec.h +++ b/include/media/stagefright/ACodec.h @@ -120,6 +120,7 @@ private: kWhatSetParameters = 'setP', kWhatSubmitOutputMetaDataBufferIfEOS = 'subm', kWhatOMXDied = 'OMXd', + kWhatReleaseCodecInstance = 'relC', }; enum { diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 2048808597..2f2f9cfaa3 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -498,6 +498,10 @@ void ACodec::initiateShutdown(bool keepComponentAllocated) { sp msg = new AMessage(kWhatShutdown, id()); msg->setInt32("keepComponentAllocated", keepComponentAllocated); msg->post(); + if (!keepComponentAllocated) { + // ensure shutdown completes in 3 seconds + (new AMessage(kWhatReleaseCodecInstance, id()))->post(3000000); + } } void ACodec::signalRequestIDRFrame() { @@ -3797,6 +3801,19 @@ bool ACodec::BaseState::onMessageReceived(const sp &msg) { break; } + case ACodec::kWhatReleaseCodecInstance: + { + ALOGI("[%s] forcing the release of codec", + mCodec->mComponentName.c_str()); + status_t err = mCodec->mOMX->freeNode(mCodec->mNode); + ALOGE_IF("[%s] failed to release codec instance: err=%d", + mCodec->mComponentName.c_str(), err); + sp notify = mCodec->mNotify->dup(); + notify->setInt32("what", CodecBase::kWhatShutdownCompleted); + notify->post(); + break; + } + default: return false; } @@ -4456,6 +4473,13 @@ bool ACodec::UninitializedState::onMessageReceived(const sp &msg) { break; } + case ACodec::kWhatReleaseCodecInstance: + { + // nothing to do, as we have already signaled shutdown + handled = true; + break; + } + default: return BaseState::onMessageReceived(msg); } diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp index d07ec146f5..f9c84e200d 100644 --- a/media/libstagefright/omx/OMXNodeInstance.cpp +++ b/media/libstagefright/omx/OMXNodeInstance.cpp @@ -149,6 +149,11 @@ static status_t StatusFromOMXError(OMX_ERRORTYPE err) { status_t OMXNodeInstance::freeNode(OMXMaster *master) { static int32_t kMaxNumIterations = 10; + // exit if we have already freed the node + if (mHandle == NULL) { + return OK; + } + // Transition the node from its current state all the way down // to "Loaded". // This ensures that all active buffers are properly freed even