universal7580: camera: block calls to cancel_auto_focus for 1 second after camera2_au...
authorDanny Wood <danwood76@gmail.com>
Fri, 24 May 2019 17:25:04 +0000 (18:25 +0100)
committerJan Altensen <info@stricted.net>
Fri, 16 Aug 2019 21:18:46 +0000 (23:18 +0200)
Change-Id: I8c274fb8de112ca279b98507a0d4ac2a2674da93

camera/Camera2Wrapper.cpp

index d4dc35f2245b742d1733ef4c226632c2167c37b7..e105ae1a56c0f53de5278544029cc08c5668bf05 100644 (file)
 #define LOG_TAG "Camera2Wrapper"
 #include <cutils/log.h>
 
+#include <unistd.h>
+
 #include "CameraWrapper.h"
 #include "Camera2Wrapper.h"
 
+#include <sys/time.h>
+
+/* current_timestamp() function from stack overflow:
+ * https://stackoverflow.com/questions/3756323/how-to-get-the-current-time-in-milliseconds-from-c-in-linux/17083824
+ */
+
+long long current_timestamp() {
+    struct timeval te;
+    gettimeofday(&te, NULL); // get current time
+    long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
+    // printf("milliseconds: %lld\n", milliseconds);
+    return milliseconds;
+}
+
 typedef struct wrapper_camera2_device {
     camera_device_t base;
     int id;
@@ -266,25 +282,45 @@ static void camera2_release_recording_frame(struct camera_device * device,
     VENDOR_CALL(device, release_recording_frame, opaque);
 }
 
+long long CancelAFTimeGuard = 0;
+
 static int camera2_auto_focus(struct camera_device * device)
 {
+    int Ret;
     ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera2_device_t*)device)->vendor));
 
     if(!device)
         return -EINVAL;
 
+    /* Call the auto_focus function */
+    Ret = VENDOR_CALL(device, auto_focus);
+
+    /* Set the cancel_auto_focus time guard to now plus 1 second */
+    CancelAFTimeGuard = current_timestamp() + 1000;
 
-    return VENDOR_CALL(device, auto_focus);
+    return Ret;
 }
 
 static int camera2_cancel_auto_focus(struct camera_device * device)
 {
+    int Ret;
     ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera2_device_t*)device)->vendor));
 
     if(!device)
         return -EINVAL;
 
-    return VENDOR_CALL(device, cancel_auto_focus);
+    /* Calculate the difference between our guard time and now */
+    long long TimeDiff = CancelAFTimeGuard - current_timestamp();
+    /* Post a log message and return success (skipping the call) if the diff is greater than 0 */
+    if(TimeDiff > 0) {
+        ALOGV("%s: CancelAFTimeGuard for %lli mS\n", __FUNCTION__, TimeDiff * 1000);
+        return 0;
+    }
+
+    /* No active time guard so call the vendor function */
+    Ret = VENDOR_CALL(device, cancel_auto_focus);
+
+    return Ret;
 }
 
 static int camera2_take_picture(struct camera_device * device)