From 6b3a0edd9fe53ae9a7078b284eef9ed3852521f8 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Fri, 12 Nov 2021 19:27:53 +0900 Subject: [PATCH] Send error message when DQBUF is failed - Additional change : Remove state condition check in camera_add/remove_message_callback(). [Version] 0.0.16 [Issue Type] Improvement Change-Id: I17392ecfbeb66824205a2172589e6a096ec54ae6 Signed-off-by: Jeongmo Yang --- packaging/camera-hal-v4l2.spec | 2 +- src/tizen_camera_v4l2.c | 73 ++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/packaging/camera-hal-v4l2.spec b/packaging/camera-hal-v4l2.spec index 792ea8a..9f44541 100644 --- a/packaging/camera-hal-v4l2.spec +++ b/packaging/camera-hal-v4l2.spec @@ -2,7 +2,7 @@ Name: camera-hal-v4l2 Summary: Tizen Camera Hal for V4L2 -Version: 0.0.15 +Version: 0.0.16 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/tizen_camera_v4l2.c b/src/tizen_camera_v4l2.c index 62fad44..499d918 100644 --- a/src/tizen_camera_v4l2.c +++ b/src/tizen_camera_v4l2.c @@ -57,6 +57,7 @@ static GMutex g_device_info_lock; static void __camera_hal_v4l2_destructor(void) __attribute__((destructor)); +static void __camera_send_message(camera_hal_handle *handle, camera_message_type_t type, int value); static void __camera_hal_v4l2_destructor(void) { @@ -68,6 +69,47 @@ static void __camera_hal_v4l2_destructor(void) return; } +static void __camera_send_message(camera_hal_handle *handle, camera_message_type_t type, int value) +{ + camera_message_t *message = NULL; + + if (!handle) { + LOGE("NULL handle"); + return; + } + + message = g_new0(camera_message_t, 1); + + message->type = type; + + switch (type) { + case CAMERA_MESSAGE_TYPE_FOCUS_CHANGED: + message->focus_state = (camera_focus_state_t)value; + break; + case CAMERA_MESSAGE_TYPE_CAPTURED: + break; + case CAMERA_MESSAGE_TYPE_HDR_PROGRESS: + message->hdr_progress = (uint32_t)value; + break; + case CAMERA_MESSAGE_TYPE_ERROR: + message->error_code = (camera_error_t)value; + break; + default: + LOGE("unknown type[%d]", type); + g_free(message); + return; + } + + g_mutex_lock(&handle->msg_cb_lock); + + LOGD("type[%d], value[0x%x]", type, value); + + g_queue_push_tail(handle->msg_list, message); + g_cond_signal(&handle->msg_cb_cond); + + g_mutex_unlock(&handle->msg_cb_lock); +} + static int __camera_v4l2_wait_frame(int device_fd, int wait_time) { int ret = CAMERA_ERROR_NONE; @@ -261,11 +303,9 @@ static int __camera_v4l2_dqbuf(int device_fd, int type, int memory, int *index) ret = v4l2_ioctl(device_fd, VIDIOC_DQBUF, &v4l2_buf); if (ret < 0) { - if (errno != EIO) { - LOGE("dqbuf failed. [t: %d, m: %d] errno %d", - type, memory, errno); - return CAMERA_ERROR_DEVICE_READ; - } + LOGE("dqbuf failed. [t: %d, m: %d] errno %d", + type, memory, errno); + return CAMERA_ERROR_DEVICE_READ; } *index = v4l2_buf.index; @@ -915,6 +955,7 @@ _CAPTURE_DONE: static void *__camera_buffer_handler_func(gpointer data) { + int error = CAMERA_ERROR_NONE; int index = 0; camera_hal_handle *handle = (camera_hal_handle *)data; @@ -944,8 +985,9 @@ static void *__camera_buffer_handler_func(gpointer data) break; } - if (__camera_v4l2_dqbuf(handle->device_fd, handle->buffer_type, V4L2_MEMORY_MMAP, &index) != CAMERA_ERROR_NONE) { - LOGE("dqbuf failed"); + error = __camera_v4l2_dqbuf(handle->device_fd, handle->buffer_type, V4L2_MEMORY_MMAP, &index); + if (error != CAMERA_ERROR_NONE) { + LOGE("dqbuf failed[0x%x]", error); break; } @@ -975,6 +1017,9 @@ static void *__camera_buffer_handler_func(gpointer data) g_mutex_unlock(&handle->buffer_lock); + if (error != CAMERA_ERROR_NONE) + __camera_send_message(handle, CAMERA_MESSAGE_TYPE_ERROR, error); + LOGD("leave"); return NULL; @@ -1035,7 +1080,7 @@ static void *_camera_message_handler_func(gpointer data) for (i = 0 ; i < MESSAGE_CALLBACK_MAX ; i++) { if (handle->msg_cb[i]) { - LOGD("call message callback type %d", message->type); + LOGD("call message callback[%d] type[%d]", i, message->type); ((camera_message_cb)handle->msg_cb[i])(message, handle->msg_cb_data[i]); } } @@ -1347,12 +1392,6 @@ int camera_add_message_callback(void *camera_handle, camera_message_cb callback, g_mutex_lock(&handle->lock); - if (handle->state != CAMERA_STATE_OPENED) { - LOGE("invalid state %d", handle->state); - g_mutex_unlock(&handle->lock); - return CAMERA_ERROR_INVALID_STATE; - } - for (i = 0 ; i < MESSAGE_CALLBACK_MAX ; i++) { if (handle->msg_cb[i] == NULL) { handle->msg_cb[i] = callback; @@ -1387,12 +1426,6 @@ int camera_remove_message_callback(void *camera_handle, uint32_t cb_id) g_mutex_lock(&handle->lock); - if (handle->state != CAMERA_STATE_OPENED) { - LOGE("invalid state %d", handle->state); - g_mutex_unlock(&handle->lock); - return CAMERA_ERROR_INVALID_STATE; - } - if (handle->msg_cb[cb_id]) { LOGD("remove message callback %p, user data %p - cb_id %u", handle->msg_cb[cb_id], handle->msg_cb_data[cb_id], cb_id); -- 2.34.1