Camera: Reduce latency for dejittering
There is a tradeoff between dejittering and latency. The more we delay
the presentation of frames, the longer latency there is.
- Only look ahead for 2 frames in the vsync timeline. And do not exceed
2+1 vsync timestamps when spacing out fixed frame rates in lockstep with
display vsync.
- Disable synchronizing presentation time to vsync for variable frame
rate. Fixed frame rate and video mode is typically more tolerant to
higher latency and prefers smoother user experience.
- Reduce the upper bound of holding onto buffers to 10ms.
Test: Measure photon-to-photon latency
Bug: 239775097
Change-Id: I601a0fadf89529922fd1bd5d0a17ba80832b4cab
diff --git a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
index 8b3cf44..84b5aa4 100644
--- a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
+++ b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
@@ -1410,18 +1410,24 @@
}
nsecs_t Camera3OutputStream::syncTimestampToDisplayLocked(nsecs_t t) {
+ nsecs_t currentTime = systemTime();
+ if (!mFixedFps) {
+ mLastCaptureTime = t;
+ mLastPresentTime = currentTime;
+ return t;
+ }
+
ParcelableVsyncEventData parcelableVsyncEventData;
auto res = mDisplayEventReceiver.getLatestVsyncEventData(&parcelableVsyncEventData);
if (res != OK) {
ALOGE("%s: Stream %d: Error getting latest vsync event data: %s (%d)",
__FUNCTION__, mId, strerror(-res), res);
mLastCaptureTime = t;
- mLastPresentTime = t;
+ mLastPresentTime = currentTime;
return t;
}
const VsyncEventData& vsyncEventData = parcelableVsyncEventData.vsync;
- nsecs_t currentTime = systemTime();
nsecs_t minPresentT = mLastPresentTime + vsyncEventData.frameInterval / 2;
// Find the best presentation time without worrying about previous frame's
@@ -1526,8 +1532,8 @@
}
}
- if (expectedPresentT == mLastPresentTime && expectedPresentT <=
- vsyncEventData.frameTimelines[maxTimelines].expectedPresentationTime) {
+ if (expectedPresentT == mLastPresentTime && expectedPresentT <
+ vsyncEventData.frameTimelines[maxTimelines-1].expectedPresentationTime) {
// Couldn't find a reasonable presentation time. Using last frame's
// presentation time would cause a frame drop. The best option now
// is to use the next VSync as long as the last presentation time