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

Commit f0348aef authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Mark streams unpreparable when using HAL buffer management

With CameraHal buffer management enabled there is a window of
opportunity where camera clients will be able to prepare streams
that already have submitted capture requests. Depending on timing
if the client is able to trigger prepare immediately after
submitting a capture request, then CameraHal might not be able to
request a buffer quickly enough and the prepare operation will
succeed which contradicts the public API guarantees.
To avoid this, mark the requested stream as unpreparable before
sending the request over to CameraHal.

Bug: 162884320
Test: Camera CTS

Change-Id: If9678fe440a5fbf12a6b2e424b9e63dd40d91fa8
parent ca362e8f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4686,6 +4686,10 @@ status_t Camera3Device::RequestThread::prepareHalRequests() {
                buffer.status = CAMERA3_BUFFER_STATUS_OK;
                buffer.acquire_fence = -1;
                buffer.release_fence = -1;
                // Mark the output stream as unpreparable to block clients from calling
                // 'prepare' after this request reaches CameraHal and before the respective
                // buffers are requested.
                outputStream->markUnpreparable();
            } else {
                res = outputStream->getBuffer(&outputBuffers->editItemAt(j),
                        waitDuration,
+7 −0
Original line number Diff line number Diff line
@@ -418,6 +418,13 @@ bool Camera3Stream::isUnpreparable() {
    return mStreamUnpreparable;
}

void Camera3Stream::markUnpreparable() {
    ATRACE_CALL();

    Mutex::Autolock l(mLock);
    mStreamUnpreparable = true;
}

status_t Camera3Stream::startPrepare(int maxCount, bool blockRequest) {
    ATRACE_CALL();

+5 −0
Original line number Diff line number Diff line
@@ -226,6 +226,11 @@ class Camera3Stream :
     */
    bool             isUnpreparable();

    /**
     * Mark the stream as unpreparable.
     */
    void             markUnpreparable() override;

    /**
     * Start stream preparation. May only be called in the CONFIGURED state,
     * when no valid buffers have yet been returned to this stream. Prepares
+5 −0
Original line number Diff line number Diff line
@@ -164,6 +164,11 @@ class Camera3StreamInterface : public virtual RefBase {
     */
    virtual bool     isUnpreparable() = 0;

    /**
     * Mark the stream as unpreparable.
     */
    virtual void     markUnpreparable() = 0;

    /**
     * Start stream preparation. May only be called in the CONFIGURED state,
     * when no valid buffers have yet been returned to this stream. Prepares