Camera2: Move non-ZSL shutter sound firing to be later.

Instead of firing shutter sound when capture request is submitted for
non-ZSL captures, fire it when the metadata frame is received. This
guarantees that the shutter sound fires after picture capture is
completed by the sensor.

Bug: 7259900
Change-Id: I4a1eeed89ed0400bf80b0f0cc2d5799c3d9bb9e3
diff --git a/services/camera/libcameraservice/camera2/CaptureSequencer.cpp b/services/camera/libcameraservice/camera2/CaptureSequencer.cpp
index 5156539..fe4abc0 100644
--- a/services/camera/libcameraservice/camera2/CaptureSequencer.cpp
+++ b/services/camera/libcameraservice/camera2/CaptureSequencer.cpp
@@ -40,6 +40,7 @@
         mNewAEState(false),
         mNewFrameReceived(false),
         mNewCaptureReceived(false),
+        mShutterNotified(false),
         mClient(client),
         mCaptureState(IDLE),
         mTriggerId(0),
@@ -308,6 +309,7 @@
     } else {
         nextState = STANDARD_START;
     }
+    mShutterNotified = false;
 
     return nextState;
 }
@@ -342,7 +344,7 @@
     SharedParameters::Lock l(client->getParameters());
     /* warning: this also locks a SharedCameraClient */
     shutterNotifyLocked(l.mParameters, client);
-
+    mShutterNotified = true;
     mTimeoutCount = kMaxTimeoutsForCaptureEnd;
     return STANDARD_CAPTURE_WAIT;
 }
@@ -474,9 +476,6 @@
         return DONE;
     }
 
-    /* warning: this also locks a SharedCameraClient */
-    shutterNotifyLocked(l.mParameters, client);
-
     mTimeoutCount = kMaxTimeoutsForCaptureEnd;
     return STANDARD_CAPTURE_WAIT;
 }
@@ -493,7 +492,13 @@
             break;
         }
     }
-    while (!mNewCaptureReceived) {
+    if (mNewFrameReceived && !mShutterNotified) {
+        SharedParameters::Lock l(client->getParameters());
+        /* warning: this also locks a SharedCameraClient */
+        shutterNotifyLocked(l.mParameters, client);
+        mShutterNotified = true;
+    }
+    while (mNewFrameReceived && !mNewCaptureReceived) {
         res = mNewCaptureSignal.waitRelative(mInputMutex, kWaitDuration);
         if (res == TIMED_OUT) {
             mTimeoutCount--;