Send error message when DQBUF is failed 16/266316/3
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 10 Nov 2021 12:50:54 +0000 (21:50 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Thu, 11 Nov 2021 05:44:43 +0000 (14:44 +0900)
- 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 <jm80.yang@samsung.com>
packaging/camera-hal-v4l2.spec
src/hal_camera_v4l2.c

index cdb0b26..a08a7f1 100644 (file)
@@ -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
index 9f28a01..4d8d994 100644 (file)
@@ -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);