am 32bb2005: Merge "Camera: improve precision of frame drop logic" into lmp-sprout-dev

* commit '32bb2005ace5b3cc2d59b429febd14716f87db35':
  Camera: improve precision of frame drop logic
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/RecordingTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/RecordingTest.java
index b2194fd..005d948 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/RecordingTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/RecordingTest.java
@@ -59,7 +59,7 @@
     private static final boolean DEBUG_DUMP = Log.isLoggable(TAG, Log.DEBUG);
     private static final int RECORDING_DURATION_MS = 3000;
     private static final int DURATION_MARGIN_MS = 600;
-    private static final int FRAME_DURATION_ERROR_TOLERANCE_MS = 3;
+    private static final double FRAME_DURATION_ERROR_TOLERANCE_MS = 3.0;
     private static final int BIT_RATE_1080P = 16000000;
     private static final int BIT_RATE_MIN = 64000;
     private static final int BIT_RATE_MAX = 40000000;
@@ -79,7 +79,7 @@
     private static final int MAX_VIDEO_SNAPSHOT_IMAGES = 5;
     private static final int BURST_VIDEO_SNAPSHOT_NUM = 3;
     private static final int SLOWMO_SLOW_FACTOR = 4;
-    private static final int MAX_NUM_FRAME_DROP_ALLOWED = 4;
+    private static final int MAX_NUM_FRAME_DROP_INTERVAL_ALLOWED = 4;
     private List<Size> mSupportedVideoSizes;
     private Surface mRecordingSurface;
     private MediaRecorder mMediaRecorder;
@@ -981,7 +981,7 @@
      */
     private int validateFrameDropAroundVideoSnapshot(
             SimpleCaptureCallback resultListener, long imageTimeStamp) {
-        int expectedDurationMs = 1000 / mVideoFrameRate;
+        double expectedDurationMs = 1000.0 / mVideoFrameRate;
         CaptureResult prevResult = resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
         long prevTS = getValueNotNull(prevResult, CaptureResult.SENSOR_TIMESTAMP);
         while (!resultListener.hasMoreResults()) {
@@ -993,7 +993,7 @@
                 CaptureResult nextResult =
                         resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
                 long nextTS = getValueNotNull(nextResult, CaptureResult.SENSOR_TIMESTAMP);
-                int durationMs = (int) (currentTS - prevTS) / 1000000;
+                double durationMs = (currentTS - prevTS) / 1000000.0;
                 int totalFramesDropped = 0;
 
                 // Snapshots in legacy mode pause the preview briefly.  Skip the duration
@@ -1002,17 +1002,17 @@
                     mCollector.expectTrue(
                             String.format(
                                     "Video %dx%d Frame drop detected before video snapshot: " +
-                                            "duration %dms (expected %dms)",
+                                            "duration %.2fms (expected %.2fms)",
                                     mVideoSize.getWidth(), mVideoSize.getHeight(),
                                     durationMs, expectedDurationMs
                             ),
-                            durationMs <= (expectedDurationMs * MAX_NUM_FRAME_DROP_ALLOWED)
+                            durationMs <= (expectedDurationMs * MAX_NUM_FRAME_DROP_INTERVAL_ALLOWED)
                     );
                     // Log a warning is there is any frame drop detected.
                     if (durationMs >= expectedDurationMs * 2) {
                         Log.w(TAG, String.format(
                                 "Video %dx%d Frame drop detected before video snapshot: " +
-                                        "duration %dms (expected %dms)",
+                                        "duration %.2fms (expected %.2fms)",
                                 mVideoSize.getWidth(), mVideoSize.getHeight(),
                                 durationMs, expectedDurationMs
                         ));
@@ -1022,11 +1022,11 @@
                     mCollector.expectTrue(
                             String.format(
                                     "Video %dx%d Frame drop detected after video snapshot: " +
-                                            "duration %dms (expected %dms)",
+                                            "duration %.2fms (expected %.2fms)",
                                     mVideoSize.getWidth(), mVideoSize.getHeight(),
                                     durationMs, expectedDurationMs
                             ),
-                            durationMs <= (expectedDurationMs * MAX_NUM_FRAME_DROP_ALLOWED)
+                            durationMs <= (expectedDurationMs * MAX_NUM_FRAME_DROP_INTERVAL_ALLOWED)
                     );
                     // Log a warning is there is any frame drop detected.
                     if (durationMs >= expectedDurationMs * 2) {
@@ -1038,10 +1038,9 @@
                         ));
                     }
 
-                    int totalDurationMs = (int) (nextTS - prevTS) / 1000000;
-                    // Rounding and minus 2 for the expected 2 frames interval
-                    totalFramesDropped =
-                            (totalDurationMs + expectedDurationMs / 2) /expectedDurationMs - 2;
+                    double totalDurationMs = (nextTS - prevTS) / 1000000.0;
+                    // Minus 2 for the expected 2 frames interval
+                    totalFramesDropped = (int) (totalDurationMs / expectedDurationMs) - 2;
                     if (totalFramesDropped < 0) {
                         Log.w(TAG, "totalFrameDropped is " + totalFramesDropped +
                                 ". Video frame rate might be too fast.");
@@ -1060,19 +1059,19 @@
      * Validate frame jittering from the input simple listener's buffered results
      */
     private void validateJittering(SimpleCaptureCallback resultListener) {
-        int expectedDurationMs = 1000 / mVideoFrameRate;
+        double expectedDurationMs = 1000.0 / mVideoFrameRate;
         CaptureResult prevResult = resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
         long prevTS = getValueNotNull(prevResult, CaptureResult.SENSOR_TIMESTAMP);
         while (!resultListener.hasMoreResults()) {
             CaptureResult currentResult =
                     resultListener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
             long currentTS = getValueNotNull(currentResult, CaptureResult.SENSOR_TIMESTAMP);
-            int durationMs = (int) (currentTS - prevTS) / 1000000;
-            int durationError = Math.abs(durationMs - expectedDurationMs);
+            double durationMs = (currentTS - prevTS) / 1000000.0;
+            double durationError = Math.abs(durationMs - expectedDurationMs);
             long frameNumber = currentResult.getFrameNumber();
             mCollector.expectTrue(
                     String.format(
-                            "Resolution %dx%d Frame %d: jittering (%dms) exceeds bound [%dms,%dms]",
+                            "Resolution %dx%d Frame %d: jittering (%.2fms) exceeds bound [%.2fms,%.2fms]",
                             mVideoSize.getWidth(), mVideoSize.getHeight(),
                             frameNumber, durationMs,
                             expectedDurationMs - FRAME_DURATION_ERROR_TOLERANCE_MS,