From 84ae447d99fab43baa5867d0bdcf2290cf5697b6 Mon Sep 17 00:00:00 2001 From: Danny Wood Date: Sat, 25 May 2019 13:33:19 +0100 Subject: [PATCH] universal7580: camera: block notify callbacks during the cancel_auto_focus function as this can cause a race condition and a lockup shorten the cancel_auto_focus blocking delay to 500mS to improve loading speed Change-Id: I20cc5401bbc80bfd8f79d744d987f540206ce0c2 --- camera/Camera2Wrapper.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/camera/Camera2Wrapper.cpp b/camera/Camera2Wrapper.cpp index e105ae1..1eead7c 100644 --- a/camera/Camera2Wrapper.cpp +++ b/camera/Camera2Wrapper.cpp @@ -142,6 +142,19 @@ static int camera2_set_preview_window(struct camera_device * device, return rc; } +uint8_t BlockNotifyCb = 0; +camera_notify_callback UserNotifyCb = NULL; + +void WrappedNotifyCb (int32_t msg_type, int32_t ext1, int32_t ext2, void *user) { + ALOGV("%s->In", __FUNCTION__); + + /* If the notify callback is valid and we are not blocking callbacks */ + if((UserNotifyCb != NULL) && (BlockNotifyCb == 0)) { + ALOGV("%s->Calling UserNotifyCb", __FUNCTION__); + UserNotifyCb(msg_type, ext1, ext2, user); + } +} + static void camera2_set_callbacks(struct camera_device * device, camera_notify_callback notify_cb, camera_data_callback data_cb, @@ -154,7 +167,11 @@ static void camera2_set_callbacks(struct camera_device * device, if(!device) return; - VENDOR_CALL(device, set_callbacks, notify_cb, data_cb, data_cb_timestamp, get_memory, user); + /* Copy the notify_cb to our user pointer */ + UserNotifyCb = notify_cb; + + /* Call the set_callbacks function substituting the notify callback with our wrapper */ + VENDOR_CALL(device, set_callbacks, WrappedNotifyCb, data_cb, data_cb_timestamp, get_memory, user); } static void camera2_enable_msg_type(struct camera_device * device, int32_t msg_type) @@ -295,8 +312,8 @@ static int camera2_auto_focus(struct camera_device * device) /* 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; + /* Set the cancel_auto_focus time guard to now plus 500mS */ + CancelAFTimeGuard = current_timestamp() + 500; return Ret; } @@ -317,9 +334,15 @@ static int camera2_cancel_auto_focus(struct camera_device * device) return 0; } + /* Block notify callbacks whilst we are in cancel_auto_focus */ + BlockNotifyCb = 1; + /* No active time guard so call the vendor function */ Ret = VENDOR_CALL(device, cancel_auto_focus); + /* Clear the block flag */ + BlockNotifyCb = 0; + return Ret; } @@ -436,6 +459,7 @@ static int camera2_device_close(hw_device_t* device) done: gPreviewWindow = 0; gPreviewStartDeferred = false; + UserNotifyCb = NULL; return ret; } -- 2.20.1