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

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

Merge "Camera: Wait until the current request id appears in the results"

parents ffc0cf5c 2a8e2838
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -959,6 +959,11 @@ void Camera2Client::stopPreviewL() {
        case Parameters::RECORD:
        case Parameters::PREVIEW:
            syncWithDevice();
            // Due to flush a camera device sync is not a sufficient
            // guarantee that the current client parameters are
            // correctly applied. To resolve this wait for the current
            // request id to return in the results.
            waitUntilCurrentRequestIdLocked();
            res = stopStream();
            if (res != OK) {
                ALOGE("%s: Camera %d: Can't stop streaming: %s (%d)",
@@ -2259,6 +2264,46 @@ int32_t Camera2Client::setAudioRestriction(int /*mode*/) {
    return INVALID_OPERATION;
}

status_t Camera2Client::waitUntilCurrentRequestIdLocked() {
    int32_t activeRequestId = mStreamingProcessor->getActiveRequestId();
    if (activeRequestId != 0) {
        auto res = waitUntilRequestIdApplied(activeRequestId,
                mDevice->getExpectedInFlightDuration());
        if (res == TIMED_OUT) {
            ALOGE("%s: Camera %d: Timed out waiting for current request id to return in results!",
                    __FUNCTION__, mCameraId);
            return res;
        } else if (res != OK) {
            ALOGE("%s: Camera %d: Error while waiting for current request id to return in results!",
                    __FUNCTION__, mCameraId);
            return res;
        }
    }

    return OK;
}

status_t Camera2Client::waitUntilRequestIdApplied(int32_t requestId, nsecs_t timeout) {
    Mutex::Autolock l(mLatestRequestMutex);
    while (mLatestRequestId != requestId) {
        nsecs_t startTime = systemTime();

        auto res = mLatestRequestSignal.waitRelative(mLatestRequestMutex, timeout);
        if (res != OK) return res;

        timeout -= (systemTime() - startTime);
    }

    return OK;
}

void Camera2Client::notifyRequestId(int32_t requestId) {
    Mutex::Autolock al(mLatestRequestMutex);

    mLatestRequestId = requestId;
    mLatestRequestSignal.signal();
}

const char* Camera2Client::kAutofocusLabel = "autofocus";
const char* Camera2Client::kTakepictureLabel = "take_picture";

+8 −0
Original line number Diff line number Diff line
@@ -123,6 +123,8 @@ public:

    camera2::SharedParameters& getParameters();

    void notifyRequestId(int32_t requestId);

    int getPreviewStreamId() const;
    int getCaptureStreamId() const;
    int getCallbackStreamId() const;
@@ -228,6 +230,12 @@ private:
    status_t initializeImpl(TProviderPtr providerPtr, const String8& monitorTags);

    bool isZslEnabledInStillTemplate();

    mutable Mutex mLatestRequestMutex;
    Condition mLatestRequestSignal;
    int32_t mLatestRequestId = -1;
    status_t waitUntilRequestIdApplied(int32_t requestId, nsecs_t timeout);
    status_t waitUntilCurrentRequestIdLocked();
};

}; // namespace android
+6 −0
Original line number Diff line number Diff line
@@ -86,6 +86,12 @@ bool FrameProcessor::processSingleFrame(CaptureResult &frame,
        process3aState(frame, client);
    }

    if (mCurrentRequestId != frame.mResultExtras.requestId) {
        mCurrentRequestId = frame.mResultExtras.requestId;

        client->notifyRequestId(mCurrentRequestId);
    }

    return FrameProcessorBase::processSingleFrame(frame, device);
}

+1 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ class FrameProcessor : public FrameProcessorBase {
    };

    AlgState m3aState;
    int32_t mCurrentRequestId = -1;

    // frame number -> pending 3A states that not all data are received yet.
    KeyedVector<int32_t, AlgState> mPending3AStates;
+6 −0
Original line number Diff line number Diff line
@@ -383,6 +383,12 @@ class CameraDeviceBase : public virtual RefBase {
     * drop buffers for stream of streamId.
     */
    virtual status_t dropStreamBuffers(bool /*dropping*/, int /*streamId*/) = 0;

    /**
     * Returns the maximum expected time it'll take for all currently in-flight
     * requests to complete, based on their settings
     */
    virtual nsecs_t getExpectedInFlightDuration() = 0;
};

}; // namespace android
Loading