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

Commit f9d74471 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix race while setting ASyncNotify callback" into tm-qpr-dev am: a9c774f6 am: 8bf04edf

parents abd4ae3f 8bf04edf
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -529,22 +529,31 @@ media_status_t AMediaCodec_setAsyncNotifyCallback(
        AMediaCodecOnAsyncNotifyCallback callback,
        void *userdata) {

    {
        Mutex::Autolock _l(mData->mAsyncCallbackLock);

        if (mData->mAsyncNotify == NULL) {
            mData->mAsyncNotify = new AMessage(kWhatAsyncNotify, mData->mHandler);
        }
        // we set this ahead so that we can be ready
        // to receive callbacks as soon as the next call is a
        // success.
        mData->mAsyncCallback = callback;
        mData->mAsyncCallbackUserData = userdata;
    }

    // always call, codec may have been reset/re-configured since last call.
    status_t err = mData->mCodec->setCallback(mData->mAsyncNotify);
    if (err != OK) {
        {
            //The setup gone wrong. clean up the pointers.
            Mutex::Autolock _l(mData->mAsyncCallbackLock);
            mData->mAsyncCallback = {};
            mData->mAsyncCallbackUserData = nullptr;
        }
        ALOGE("setAsyncNotifyCallback: err(%d), failed to set async callback", err);
        return translate_error(err);
    }

    mData->mAsyncCallback = callback;
    mData->mAsyncCallbackUserData = userdata;

    return AMEDIA_OK;
}