From: Jeongmo Yang Date: Wed, 10 Nov 2021 12:50:54 +0000 (+0900) Subject: Send error message when DQBUF is failed X-Git-Tag: accepted/tizen/7.0/unified/20221110.062530~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ac33b34fa3c6e7c2b69ed46596ebb94b8603ee20;p=platform%2Fadaptation%2Fcamera-hal-v4l2.git Send error message when DQBUF is failed - Additional change : Remove state condition check in camera_v4l2_add/remove_message_callback(). [Version] 0.1.10 [Issue Type] Improvement Change-Id: I83e480e42624617b46220632755534096b08495d Signed-off-by: Jeongmo Yang --- diff --git a/packaging/camera-hal-v4l2.spec b/packaging/camera-hal-v4l2.spec index cdb0b26..a08a7f1 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.1.9 +Version: 0.1.10 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/hal_camera_v4l2.c b/src/hal_camera_v4l2.c index 9f28a01..4d8d994 100644 --- a/src/hal_camera_v4l2.c +++ b/src/hal_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(hal_camera_handle *handle, camera_message_type_e type, int value); static void __camera_hal_v4l2_destructor(void) @@ -70,6 +71,48 @@ static void __camera_hal_v4l2_destructor(void) } +static void __camera_send_message(hal_camera_handle *handle, camera_message_type_e type, int value) +{ + camera_message_s *message = NULL; + + if (!handle) { + LOGE("NULL handle"); + return; + } + + message = g_new0(camera_message_s, 1); + + message->type = type; + + switch (type) { + case CAMERA_MESSAGE_TYPE_FOCUS_CHANGED: + message->focus_state = (camera_focus_state_e)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_e)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; @@ -263,11 +306,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; @@ -977,6 +1018,7 @@ _CAPTURE_DONE: static void *__camera_buffer_handler_func(gpointer data) { + int error = CAMERA_ERROR_NONE; int index = 0; hal_camera_handle *handle = (hal_camera_handle *)data; @@ -1006,8 +1048,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; } @@ -1048,6 +1091,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; @@ -1108,7 +1154,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); handle->msg_cb[i](message, handle->msg_cb_data[i]); } } @@ -1434,12 +1480,6 @@ int camera_v4l2_add_message_callback(void *camera_handle, hal_camera_message_cb 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; @@ -1475,12 +1515,6 @@ int camera_v4l2_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);