Merge "Camera: fix burst capture failure on some devices" into pie-cts-dev
diff --git a/tests/camera/src/android/hardware/camera2/cts/BurstCaptureTest.java b/tests/camera/src/android/hardware/camera2/cts/BurstCaptureTest.java
index b0aae41..db2b616 100644
--- a/tests/camera/src/android/hardware/camera2/cts/BurstCaptureTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/BurstCaptureTest.java
@@ -127,6 +127,7 @@
         // Create session and start up preview
 
         SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
+        SimpleCaptureCallback burstResultListener = new SimpleCaptureCallback();
         ImageDropperListener imageDropper = new ImageDropperListener();
 
         prepareCaptureAndStartPreview(
@@ -214,7 +215,7 @@
 
         if (maxSyncLatency == CameraCharacteristics.SYNC_MAX_LATENCY_PER_FRAME_CONTROL) {
             // The locked result we have is already synchronized so start the burst
-            mSession.captureBurst(burst, resultListener, mHandler);
+            mSession.captureBurst(burst, burstResultListener, mHandler);
         } else {
             // Need to get a synchronized result, and may need to start burst later to
             // be synchronized correctly
@@ -232,7 +233,7 @@
             int requestsNeededToSync = numFramesWaited - pipelineDepth;
             for (int i = 0; i < numFramesWaited; i++) {
                 if (!burstSent && requestsNeededToSync <= 0) {
-                    mSession.captureBurst(burst, resultListener, mHandler);
+                    mSession.captureBurst(burst, burstResultListener, mHandler);
                     burstSent = true;
                 }
                 lockedResult = resultListener.getCaptureResult(MAX_PREVIEW_RESULT_TIMEOUT_MS);
@@ -270,12 +271,14 @@
         // Process burst results
         int burstIndex = 0;
         CaptureResult burstResult =
-                resultListener.getCaptureResultForRequest(burst.get(burstIndex),
-                    maxPipelineDepth + 1);
+                burstResultListener.getCaptureResult(MAX_PREVIEW_RESULT_TIMEOUT_MS);
         long prevTimestamp = -1;
         final long frameDurationBound = (long)
                 (minStillFrameDuration * (1 + FRAME_DURATION_MARGIN_FRACTION) );
 
+        long burstStartTimestamp = burstResult.get(CaptureResult.SENSOR_TIMESTAMP);
+        long burstEndTimeStamp = 0;
+
         List<Long> frameDurations = new ArrayList<>();
 
         while(true) {
@@ -307,8 +310,25 @@
 
             // Get next result
             burstIndex++;
-            if (burstIndex == BURST_SIZE) break;
-            burstResult = resultListener.getCaptureResult(MAX_PREVIEW_RESULT_TIMEOUT_MS);
+            if (burstIndex == BURST_SIZE) {
+                burstEndTimeStamp = burstResult.get(CaptureResult.SENSOR_TIMESTAMP);
+                break;
+            }
+            burstResult = burstResultListener.getCaptureResult(MAX_PREVIEW_RESULT_TIMEOUT_MS);
+        }
+
+        // Verify no preview frames interleaved in burst results
+        while (true)         {
+            CaptureResult previewResult =
+                    resultListener.getCaptureResult(MAX_PREVIEW_RESULT_TIMEOUT_MS);
+            long previewTimestamp = previewResult.get(CaptureResult.SENSOR_TIMESTAMP);
+            if (previewTimestamp >= burstStartTimestamp && previewTimestamp <= burstEndTimeStamp) {
+                fail("Preview frame is interleaved with burst frames! Preview timestamp:" +
+                        previewTimestamp + ", burst [" + burstStartTimestamp + ", " +
+                        burstEndTimeStamp + "]");
+            } else if (previewTimestamp > burstEndTimeStamp) {
+                break;
+            }
         }
 
         // Verify inter-frame durations