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

Commit a141c5f3 authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: StreamSplitter: Return overwritten buffer to input

For Async buffer queue, if a pending buffer is overwritten by an
incoming buffer, onBufferReleased callback isn't called. But the stream
splitter depends on the onBufferReleased to return buffer to input.

Fix the problem by checking the bufferReplaced flag in
QueueBufferOutput.

Test: Camera CTS
Bug: 33777818
Change-Id: I270c7bae7873797ae9b050782828b5a124d3eff9
parent 758c2153
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -322,6 +322,13 @@ void Camera3StreamSplitter::onFrameAvailable(const BufferItem& /* item */) {
                        "queueing buffer to output failed (%d)", status);
                        "queueing buffer to output failed (%d)", status);
            }
            }


            // If the queued buffer replaces a pending buffer in the async
            // queue, no onBufferReleased is called by the buffer queue.
            // Proactively trigger the callback to avoid buffer loss.
            if (queueOutput.bufferReplaced) {
                onBufferReleasedByOutputLocked(mOutputs[id]);
            }

            ALOGV("queued buffer %#" PRIx64 " to output %p",
            ALOGV("queued buffer %#" PRIx64 " to output %p",
                    bufferItem.mGraphicBuffer->getId(), mOutputs[id].get());
                    bufferItem.mGraphicBuffer->getId(), mOutputs[id].get());
        }
        }
@@ -335,6 +342,12 @@ void Camera3StreamSplitter::onBufferReleasedByOutput(
    ATRACE_CALL();
    ATRACE_CALL();
    Mutex::Autolock lock(mMutex);
    Mutex::Autolock lock(mMutex);


    onBufferReleasedByOutputLocked(from);
}

void Camera3StreamSplitter::onBufferReleasedByOutputLocked(
        const sp<IGraphicBufferProducer>& from) {

    sp<GraphicBuffer> buffer;
    sp<GraphicBuffer> buffer;
    sp<Fence> fence;
    sp<Fence> fence;
    status_t status = from->detachNextBuffer(&buffer, &fence);
    status_t status = from->detachNextBuffer(&buffer, &fence);
+5 −0
Original line number Original line Diff line number Diff line
@@ -103,6 +103,11 @@ private:
    // onFrameAvailable call to proceed.
    // onFrameAvailable call to proceed.
    void onBufferReleasedByOutput(const sp<IGraphicBufferProducer>& from);
    void onBufferReleasedByOutput(const sp<IGraphicBufferProducer>& from);


    // This is the implementation of onBufferReleasedByOutput without the mutex locked.
    // It could either be called from onBufferReleasedByOutput or from
    // onFrameAvailable when a buffer in the async buffer queue is overwritten.
    void onBufferReleasedByOutputLocked(const sp<IGraphicBufferProducer>& from);

    // When this is called, the splitter disconnects from (i.e., abandons) its
    // When this is called, the splitter disconnects from (i.e., abandons) its
    // input queue and signals any waiting onFrameAvailable calls to wake up.
    // input queue and signals any waiting onFrameAvailable calls to wake up.
    // It still processes callbacks from other outputs, but only detaches their
    // It still processes callbacks from other outputs, but only detaches their