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

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

Merge "MediaMuxer:Unblock writeSampleData,gate pushBuffer"

parents f6388bd5 7ab4b9ac
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -114,6 +114,13 @@ status_t MediaAdapter::pushBuffer(MediaBuffer *buffer) {
        return -EINVAL;
    }

    /* As mAdapterLock is unlocked while waiting for signalBufferReturned,
     * a new buffer for the same track could be pushed from another thread
     * in the client process, mBufferGatingMutex will help to hold that
     * until the previous buffer is processed.
     */
    std::unique_lock<std::mutex> lk(mBufferGatingMutex);

    Mutex::Autolock autoLock(mAdapterLock);
    if (!mStarted) {
        ALOGE("pushBuffer called before start");
+17 −10
Original line number Diff line number Diff line
@@ -175,13 +175,19 @@ status_t MediaMuxer::stop() {

status_t MediaMuxer::writeSampleData(const sp<ABuffer> &buffer, size_t trackIndex,
                                     int64_t timeUs, uint32_t flags) {
    Mutex::Autolock autoLock(mMuxerLock);

    if (buffer.get() == NULL) {
        ALOGE("WriteSampleData() get an NULL buffer.");
        return -EINVAL;
    }

    {
        /* As MediaMuxer's writeSampleData handles inputs from multiple tracks,
         * limited the scope of mMuxerLock to this inner block so that the
         * current track's buffer does not wait until the completion
         * of processing of previous buffer of the same or another track.
         * It's the responsibility of individual track - MediaAdapter object
         * to gate its buffers.
         */
        Mutex::Autolock autoLock(mMuxerLock);
        if (mState != STARTED) {
            ALOGE("WriteSampleData() is called in invalid state %d", mState);
            return INVALID_OPERATION;
@@ -191,6 +197,7 @@ status_t MediaMuxer::writeSampleData(const sp<ABuffer> &buffer, size_t trackInde
            ALOGE("WriteSampleData() get an invalid index %zu", trackIndex);
            return -EINVAL;
        }
    }

    MediaBuffer* mediaBuffer = new MediaBuffer(buffer);

+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ public:

private:
    Mutex mAdapterLock;
    std::mutex mBufferGatingMutex;
    // Make sure the read() wait for the incoming buffer.
    Condition mBufferReadCond;
    // Make sure the pushBuffer() wait for the current buffer consumed.