Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2dc737d2 authored by Shivaprasad Hongal's avatar Shivaprasad Hongal Committed by Linux Build Service Account
Browse files

ACodec: Fix error handling in OutputPortSettingsChangedState

Freeing the input buffers & node in ACodec::OutputPortSettingsChangedState
on error, can cause NuPlayerDecoder to deference freed buffers.
Instead of freeing the node internally on error in
OutputPortSettingsChangedState, notify error to NuPlayer, and add
kWhatShutDown handling to initiate Idle state transition.

Change-Id: I7778d759c564fad27d266ac63d293bf0c30c029b
parent 5b46d290
Loading
Loading
Loading
Loading
+27 −10
Original line number Diff line number Diff line
@@ -7425,8 +7425,34 @@ bool ACodec::OutputPortSettingsChangedState::onMessageReceived(
    bool handled = false;

    switch (msg->what()) {
        case kWhatFlush:
        case kWhatShutdown:
        {
            int32_t keepComponentAllocated;
            CHECK(msg->findInt32(
                        "keepComponentAllocated", &keepComponentAllocated));

            mCodec->mShutdownInProgress = true;
            mCodec->mExplicitShutdown = true;
            mCodec->mKeepComponentAllocated = keepComponentAllocated;

            status_t err = mCodec->mOMX->sendCommand(
                    mCodec->mNode, OMX_CommandStateSet, OMX_StateIdle);
            if (err != OK) {
                if (keepComponentAllocated) {
                    mCodec->signalError(OMX_ErrorUndefined, FAILED_TRANSACTION);
                }
                // TODO: do some recovery here.
            } else {
                // This is technically not correct, but appears to be
                // the only way to free the component instance using
                // ExectingToIdleState.
                mCodec->changeState(mCodec->mExecutingToIdleState);
            }

            handled = true;
            break;
        }
        case kWhatFlush:
        case kWhatResume:
        case kWhatSetParameters:
        {
@@ -7493,15 +7519,6 @@ bool ACodec::OutputPortSettingsChangedState::onOMXEvent(

                if (err != OK) {
                    mCodec->signalError(OMX_ErrorUndefined, makeNoSideEffectStatus(err));

                    // This is technically not correct, but appears to be
                    // the only way to free the component instance.
                    // Controlled transitioning from excecuting->idle
                    // and idle->loaded seem impossible probably because
                    // the output port never finishes re-enabling.
                    mCodec->mShutdownInProgress = true;
                    mCodec->mKeepComponentAllocated = false;
                    mCodec->changeState(mCodec->mLoadedState);
                }

                return true;