Camera3: Add pending request count in metadata

More than one requests may fall onto the same frame interval,
in which case camera daemon needs to delay one request to
the next frame interval.

To solve this problem, add a new field in metadata to indicate
number of pending requests. Only if the number of pending requests
is 0, HAL would unblock process_capture_request.

Change-Id: I018b00315b48d5a15420d0ba145e0944d11fdeec
diff --git a/camera/QCamera2/HAL3/QCamera3HWI.cpp b/camera/QCamera2/HAL3/QCamera3HWI.cpp
index 6e042d0..0a513c7 100644
--- a/camera/QCamera2/HAL3/QCamera3HWI.cpp
+++ b/camera/QCamera2/HAL3/QCamera3HWI.cpp
@@ -1003,6 +1003,8 @@
         metadata_buffer_t *metadata = (metadata_buffer_t *)metadata_buf->bufs[0]->buffer;
         int32_t frame_number_valid = *(int32_t *)
             POINTER_OF(CAM_INTF_META_FRAME_NUMBER_VALID, metadata);
+        uint32_t pending_requests = *(uint32_t *)POINTER_OF(
+            CAM_INTF_META_PENDING_REQUESTS, metadata);
         uint32_t frame_number = *(uint32_t *)
             POINTER_OF(CAM_INTF_META_FRAME_NUMBER, metadata);
         const struct timeval *tv = (const struct timeval *)
@@ -1116,7 +1118,7 @@
                 break;
             }
         }
-        if (!max_buffers_dequeued) {
+        if (!max_buffers_dequeued && !pending_requests) {
             // Unblock process_capture_request
             mPendingRequest = 0;
             pthread_cond_signal(&mRequestCond);
diff --git a/camera/QCamera2/stack/common/cam_intf.h b/camera/QCamera2/stack/common/cam_intf.h
index b899e0e..889352f 100644
--- a/camera/QCamera2/stack/common/cam_intf.h
+++ b/camera/QCamera2/stack/common/cam_intf.h
@@ -473,6 +473,7 @@
     INCLUDE(CAM_INTF_META_GOOD_FRAME_IDX_RANGE,       cam_frame_idx_range_t,       1);
     /* Specific to HAL3 */
     INCLUDE(CAM_INTF_META_FRAME_NUMBER_VALID,         int32_t,                     1);
+    INCLUDE(CAM_INTF_META_PENDING_REQUESTS,           uint32_t,                    1);
     INCLUDE(CAM_INTF_META_FRAME_NUMBER,               uint32_t,                    1);
     INCLUDE(CAM_INTF_META_COLOR_CORRECT_MODE,         uint8_t,                     1);
     INCLUDE(CAM_INTF_META_AEC_PRECAPTURE_ID,          int32_t,                     1);
diff --git a/camera/QCamera2/stack/common/cam_types.h b/camera/QCamera2/stack/common/cam_types.h
index 7acf4c5..a87a0e5 100644
--- a/camera/QCamera2/stack/common/cam_types.h
+++ b/camera/QCamera2/stack/common/cam_types.h
@@ -769,6 +769,8 @@
     /* specific to HAL3 */
     /* Whether the metadata maps to a valid frame number */
     CAM_INTF_META_FRAME_NUMBER_VALID,
+    /* Number of pending requests yet to be processed */
+    CAM_INTF_META_PENDING_REQUESTS,
     /* COLOR CORRECTION.*/
     CAM_INTF_META_COLOR_CORRECT_MODE,
     /* A transform matrix to chromatically adapt pixels in the CIE XYZ (1931)