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

Commit 4b35b1d1 authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Avoid over-delaying frames in PreviewFrameSpacer

There could be 1 or 2 ms between calculating the timeToWait and
queueBuffer(). As a result currently we are over-delaying each
frame for about 1ms. This over-delay can accumulate and recover
once the maximum 10ms limit is reached or 2 frames are queued.

To compensate, wait up to until (mLastPresentTime + captureInterval - 2ms)
So that the presentation intervals don't always exceed captureInternal.

Bug: 251183098
Test: Camera CTS, vendor testing
Test: testPreviewJitterSurfaceTexture
Change-Id: I2728d0516686950141c8e6d41e041d8d6dc00c8a
parent 3560d53f
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -69,7 +69,9 @@ bool PreviewFrameSpacer::threadLoop() {
    }

    // Cache the frame to match readout time interval, for up to kMaxFrameWaitTime
    nsecs_t expectedQueueTime = mLastCameraPresentTime + readoutInterval;
    // Because the code between here and queueBuffer() takes time to execute, make sure the
    // presentationInterval is slightly shorter than readoutInterval.
    nsecs_t expectedQueueTime = mLastCameraPresentTime + readoutInterval - kFrameAdjustThreshold;
    nsecs_t frameWaitTime = std::min(kMaxFrameWaitTime, expectedQueueTime - currentTime);
    if (frameWaitTime > 0 && mPendingBuffers.size() < 2) {
        mBufferCond.waitRelative(mLock, frameWaitTime);
@@ -78,9 +80,9 @@ bool PreviewFrameSpacer::threadLoop() {
        }
        currentTime = systemTime();
    }
    ALOGV("%s: readoutInterval %" PRId64 ", queueInterval %" PRId64 ", waited for %" PRId64
    ALOGV("%s: readoutInterval %" PRId64 ", waited for %" PRId64
            ", timestamp %" PRId64, __FUNCTION__, readoutInterval,
            currentTime - mLastCameraPresentTime, frameWaitTime, buffer.timestamp);
            mPendingBuffers.size() < 2 ? frameWaitTime : 0, buffer.timestamp);
    mPendingBuffers.pop();
    queueBufferToClientLocked(buffer, currentTime);
    return true;
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ class PreviewFrameSpacer : public Thread {
    static constexpr nsecs_t kWaitDuration = 5000000LL; // 50ms
    static constexpr nsecs_t kFrameIntervalThreshold = 80000000LL; // 80ms
    static constexpr nsecs_t kMaxFrameWaitTime = 10000000LL; // 10ms
    static constexpr nsecs_t kFrameAdjustThreshold = 2000000LL; // 2ms
};

}; //namespace camera3