Camera: Fix rounding issue with minInterval

Existing formula to calculate minInterval may set the minInterval too
large.

For example, if the vSyncInterval is 16.5ms, minFrameDurtion is 33.3ms,
the existing calculation may derive minInterval to be 2+ vSync intervals,
Due to rounding up in calculation, the minInterval could cause the
expectedPresentationTime to be 3 vSyncs. That spaces frames too far away.

Test: Switch between front/back and 30fps/60fps video mode in GCA
Bug: 232722528
Change-Id: I430d571b44a87d32153c54cc661dbf5e42e6ed56
diff --git a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
index 4a9b259..d2167e3 100644
--- a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
+++ b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
@@ -1406,9 +1406,13 @@
     nsecs_t expectedPresentT = mLastPresentTime;
     nsecs_t minDiff = INT64_MAX;
     // Derive minimum intervals between presentation times based on minimal
-    // expected duration.
-    size_t minVsyncs = (mMinExpectedDuration + vsyncEventData.frameInterval - 1) /
-            vsyncEventData.frameInterval - 1;
+    // expected duration. The minimum number of Vsyncs is:
+    // - 0 if minFrameDuration in (0, 1.5] * vSyncInterval,
+    // - 1 if minFrameDuration in (1.5, 2.5] * vSyncInterval,
+    // - and so on.
+    int minVsyncs = (mMinExpectedDuration - vsyncEventData.frameInterval / 2) /
+            vsyncEventData.frameInterval;
+    if (minVsyncs < 0) minVsyncs = 0;
     nsecs_t minInterval = minVsyncs * vsyncEventData.frameInterval + kTimelineThresholdNs;
     // Find best timestamp in the vsync timeline:
     // - closest to the ideal present time,