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

Commit c6696cc0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "muxer: set observer before we start waiting for read"

parents 2a274126 2531d69c
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -45,18 +45,25 @@ status_t MediaAdapter::start(MetaData * /* params */) {
}

status_t MediaAdapter::stop() {
    MediaBuffer *currentBuffer = NULL;
    {
        Mutex::Autolock autoLock(mAdapterLock);
        if (mStarted) {
            mStarted = false;
            // If stop() happens immediately after a pushBuffer(), we should
        // clean up the mCurrentMediaBuffer
        if (mCurrentMediaBuffer != NULL) {
            mCurrentMediaBuffer->release();
            // clean up the mCurrentMediaBuffer. But need to release without
            // the lock as signalBufferReturned() will acquire the lock.
            currentBuffer = mCurrentMediaBuffer;
            mCurrentMediaBuffer = NULL;
        }

            // While read() is still waiting, we should signal it to finish.
            mBufferReadCond.signal();
        }
    }
    if (currentBuffer != NULL) {
        currentBuffer->release();
        currentBuffer = NULL;
    }
    return OK;
}

@@ -97,7 +104,6 @@ status_t MediaAdapter::read(

    *buffer = mCurrentMediaBuffer;
    mCurrentMediaBuffer = NULL;
    (*buffer)->setObserver(this);

    return OK;
}
@@ -114,6 +120,7 @@ status_t MediaAdapter::pushBuffer(MediaBuffer *buffer) {
        return INVALID_OPERATION;
    }
    mCurrentMediaBuffer = buffer;
    mCurrentMediaBuffer->setObserver(this);
    mBufferReadCond.signal();

    ALOGV("wait for the buffer returned @ pushBuffer! %p", buffer);