Send error message when DQBUF is failed 74/266474/1 accepted/tizen_6.0_unified tizen_6.0 accepted/tizen/6.0/unified/20211115.013246 submit/tizen_6.0/20211112.110150
authorJeongmo Yang <jm80.yang@samsung.com>
Fri, 12 Nov 2021 10:27:53 +0000 (19:27 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Fri, 12 Nov 2021 10:28:50 +0000 (19:28 +0900)
- 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 <jm80.yang@samsung.com>
packaging/camera-hal-v4l2.spec
src/tizen_camera_v4l2.c

index 792ea8a7a759da2946bfff07df64dde68196a751..9f445418992bcd86f8b7638643c864121aff1720 100644 (file)
@@ -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
index 62fad44d3cb192344375dec293eeae62ee67a260..499d918d3571ad3a61339ad1c9a7187337736128 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(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);