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

Commit 5c8cbeda authored by chenguolin's avatar chenguolin Committed by Guolin Chen
Browse files

camera:fix wait request timeout in switching camera



This issue happened from two camera apps switch each other which is based on api1.In apil need do the syncwithDevice to wait the mLatestRequestsignal.In the switch case, exist prepareHalRequests return an error flags, then exit the request loop without signal mLatestRequestsignal.So it caused the app which use api1 syncwithDevice timeout.So resolution is add codes to signal mLatestRequestsignal during the last requstloop exit.It should not block the next app start.

Bug:312989788
Test: Stress test for open/close camera from different camera app

Change-Id: Iea45693fe654532f0174f50f87bc114ad2c2321b
Signed-off-by: default avatarchenguolin <chenguolin@xiaomi.corp-partner.google.com>
parent fdc86e2a
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -3649,19 +3649,18 @@ bool Camera3Device::RequestThread::threadLoop() {
        cleanUpFailedRequests(/*sendRequestError*/ true);
        // Check if any stream is abandoned.
        checkAndStopRepeatingRequest();
        // Inform waitUntilRequestProcessed thread of a failed request ID
        wakeupLatestRequest(/*failedRequestId*/true, latestRequestId);
        return true;
    } else if (res != OK) {
        cleanUpFailedRequests(/*sendRequestError*/ false);
        // Inform waitUntilRequestProcessed thread of a failed request ID
        wakeupLatestRequest(/*failedRequestId*/true, latestRequestId);
        return false;
    }

    // Inform waitUntilRequestProcessed thread of a new request ID
    {
        Mutex::Autolock al(mLatestRequestMutex);

        mLatestRequestId = latestRequestId;
        mLatestRequestSignal.signal();
    }
    wakeupLatestRequest(/*failedRequestId*/false, latestRequestId);

    // Submit a batch of requests to HAL.
    // Use flush lock only when submitting multilple requests in a batch.
@@ -4393,12 +4392,7 @@ void Camera3Device::RequestThread::cleanUpFailedRequests(bool sendRequestError)
                        hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_REQUEST,
                        captureRequest->mResultExtras);
            }
            {
                Mutex::Autolock al(mLatestRequestMutex);

                mLatestFailedRequestId = captureRequest->mResultExtras.requestId;
                mLatestRequestSignal.signal();
            }
            wakeupLatestRequest(/*failedRequestId*/true, captureRequest->mResultExtras.requestId);
        }

        // Remove yet-to-be submitted inflight request from inflightMap
@@ -5060,6 +5054,20 @@ status_t Camera3Device::RequestThread::setHalInterface(
    return OK;
}

void  Camera3Device::RequestThread::wakeupLatestRequest(
        bool latestRequestFailed,
        int32_t latestRequestId) {
    Mutex::Autolock al(mLatestRequestMutex);

    if (latestRequestFailed) {
        mLatestFailedRequestId = latestRequestId;
    } else {
        mLatestRequestId = latestRequestId;
    }
    mLatestRequestSignal.signal();
}


/**
 * PreparerThread inner class methods
 */
+5 −0
Original line number Diff line number Diff line
@@ -1026,6 +1026,11 @@ class Camera3Device :
            const sp<CaptureRequest> &request,
            const CameraMetadata& injectedSessionParams);

        /**
         * signal mLatestRequestmutex
         **/
        void wakeupLatestRequest(bool latestRequestFailed, int32_t latestRequestId);

      protected:

        virtual bool threadLoop();