Support new command and camera_v4l2_set_batch_command() 22/258322/4 accepted/tizen/unified/20210602.122536 submit/tizen/20210531.033817
authorJeongmo Yang <jm80.yang@samsung.com>
Thu, 13 May 2021 11:08:21 +0000 (20:08 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Mon, 31 May 2021 03:28:47 +0000 (12:28 +0900)
- Command list
 : CAMERA_COMMAND_FOCUS_MODE
 : CAMERA_COMMAND_FOCUS_RANGE
 : CAMERA_COMMAND_FOCUS_LEVEL

[Version] 0.1.2
[Issue Type] New feature

Change-Id: I521fe0ba81c60d341ecac70881d3bb94484b413e
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/camera-hal-v4l2.spec
src/hal_camera_v4l2.c
src/hal_camera_v4l2_private.h

index f52c565..5550a84 100644 (file)
@@ -1,6 +1,6 @@
 Name:       camera-hal-v4l2
 Summary:    Tizen Camera Hal for V4L2
-Version:    0.1.1
+Version:    0.1.2
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 6738f85..8fbfb20 100644 (file)
@@ -1948,13 +1948,11 @@ int camera_v4l2_release_extra_preview_buffer(void *camera_handle, int stream_id,
 }
 
 
-int camera_v4l2_set_command(void *camera_handle, int64_t command, void *value)
+static int __set_command(hal_camera_handle *handle, int64_t command, void *value)
 {
-       int ret = CAMERA_ERROR_NONE;
        int cid = 0;
        int ctrl_ret = 0;
        int set_value = 0;
-       hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
 
        if (!handle || !value) {
                LOGE("NULL param %p %p", handle, value);
@@ -1963,12 +1961,9 @@ int camera_v4l2_set_command(void *camera_handle, int64_t command, void *value)
 
        set_value = *(int *)value;
 
-       g_mutex_lock(&handle->lock);
-
        if (handle->state < CAMERA_STATE_OPENED) {
                LOGE("invalid state %d", handle->state);
-               ret = CAMERA_ERROR_INVALID_STATE;
-               goto _SET_COMMAND_DONE;
+               return CAMERA_ERROR_INVALID_STATE;
        }
 
        LOGD("set command %"PRIx64" - state %d", command, handle->state);
@@ -1989,9 +1984,9 @@ int camera_v4l2_set_command(void *camera_handle, int64_t command, void *value)
        case CAMERA_COMMAND_PTZ_TYPE:
                if (set_value != CAMERA_PTZ_TYPE_ELECTRONIC) {
                        LOGE("not supported PTZ type %d", set_value);
-                       ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
+                       return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
                }
-               goto _SET_COMMAND_DONE;
+               return CAMERA_ERROR_NONE;
        case CAMERA_COMMAND_PAN:
                cid = V4L2_CID_PAN_ABSOLUTE;
                break;
@@ -2001,21 +1996,32 @@ int camera_v4l2_set_command(void *camera_handle, int64_t command, void *value)
        case CAMERA_COMMAND_FLIP:
                if (set_value != CAMERA_FLIP_NONE) {
                        LOGE("NOT_SUPPORTED flip %d", set_value);
-                       ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
+                       return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
                }
-               goto _SET_COMMAND_DONE;
+               return CAMERA_ERROR_NONE;
        case CAMERA_COMMAND_CAPTURE_COUNT:
                handle->capture_count = set_value;
                LOGI("capture count %u", handle->capture_count);
-               goto _SET_COMMAND_DONE;
+               return CAMERA_ERROR_NONE;
        case CAMERA_COMMAND_CAPTURE_INTERVAL:
                handle->capture_interval_ms = set_value;
                LOGI("capture interval %u ms", handle->capture_interval_ms);
-               goto _SET_COMMAND_DONE;
+               return CAMERA_ERROR_NONE;
+       case CAMERA_COMMAND_FOCUS_MODE:
+               LOGI("set focus mode [old:%d -> new:%d]", handle->focus_mode, set_value);
+               handle->focus_mode = set_value;
+               return CAMERA_ERROR_NONE;
+       case CAMERA_COMMAND_FOCUS_RANGE:
+               LOGI("set focus range [old:%d -> new:%d]", handle->focus_range, set_value);
+               handle->focus_range = set_value;
+               return CAMERA_ERROR_NONE;
+       case CAMERA_COMMAND_FOCUS_LEVEL:
+               LOGI("set focus level [old:%d -> new:%d]", handle->focus_level, set_value);
+               handle->focus_level = set_value;
+               return CAMERA_ERROR_NONE;
        default:
                LOGE("NOT_SUPPORTED command %"PRIx64, command);
-               ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
-               goto _SET_COMMAND_DONE;
+               return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
        }
 
        ctrl_ret = __camera_v4l2_s_ctrl(handle->device_fd, cid, set_value);
@@ -2024,28 +2030,35 @@ int camera_v4l2_set_command(void *camera_handle, int64_t command, void *value)
                case EACCES:
                case EPERM:
                        LOGE("Permission denied %d", errno);
-                       ret = CAMERA_ERROR_PERMISSION_DENIED;
-                       break;
+                       return CAMERA_ERROR_PERMISSION_DENIED;
                case EINVAL:
                        LOGE("Invalid argument");
-                       ret = CAMERA_ERROR_INVALID_PARAMETER;
-                       break;
+                       return CAMERA_ERROR_INVALID_PARAMETER;
                case EBUSY:
                        LOGE("Device busy");
-                       ret = CAMERA_ERROR_DEVICE_BUSY;
-                       break;
+                       return CAMERA_ERROR_DEVICE_BUSY;
                case ENOTSUP:
                        LOGE("Not supported");
-                       ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
-                       break;
+                       return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
                default:
                        LOGE("Unknown errro %d", errno);
-                       ret = CAMERA_ERROR_INTERNAL;
-                       break;
+                       return CAMERA_ERROR_INTERNAL;
                }
        }
 
-_SET_COMMAND_DONE:
+       return CAMERA_ERROR_NONE;
+}
+
+
+int camera_v4l2_set_command(void *camera_handle, int64_t command, void *value)
+{
+       int ret = CAMERA_ERROR_NONE;
+       hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
+
+       g_mutex_lock(&handle->lock);
+
+       ret = __set_command(handle, command, value);
+
        g_mutex_unlock(&handle->lock);
 
        return ret;
@@ -2066,7 +2079,7 @@ int camera_v4l2_get_command(void *camera_handle, int64_t command, void **value)
 
        g_mutex_lock(&handle->lock);
 
-       LOGD("get command %"PRId64" - state %d", command, handle->state);
+       LOGD("get command %"PRIx64" - state %d", command, handle->state);
 
        switch (command) {
        case CAMERA_COMMAND_BRIGHTNESS:
@@ -2081,13 +2094,25 @@ int camera_v4l2_get_command(void *camera_handle, int64_t command, void **value)
        case CAMERA_COMMAND_SHARPNESS:
                cid = V4L2_CID_SHARPNESS;
                break;
+       case CAMERA_COMMAND_FOCUS_MODE:
+               **(int **)value = handle->focus_mode;
+               LOGI("get focus mode %d", **(int **)value);
+               goto _GET_COMMAND_DONE;
+       case CAMERA_COMMAND_FOCUS_RANGE:
+               **(int **)value = handle->focus_range;
+               LOGI("get focus range %d", **(int **)value);
+               goto _GET_COMMAND_DONE;
+       case CAMERA_COMMAND_FOCUS_LEVEL:
+               **(int **)value = handle->focus_level;
+               LOGI("get focus level %d", **(int **)value);
+               goto _GET_COMMAND_DONE;
        default:
-               LOGE("NOT_SUPPORTED %"PRId64, command);
+               LOGE("NOT_SUPPORTED %"PRIx64, command);
                g_mutex_unlock(&handle->lock);
                return CAMERA_ERROR_DEVICE_NOT_SUPPORTED;
        }
 
-       ctrl_ret = __camera_v4l2_g_ctrl(handle->device_fd, cid, (int *)value);
+       ctrl_ret = __camera_v4l2_g_ctrl(handle->device_fd, cid, (int *)*value);
        if (ctrl_ret < 0) {
                switch (errno) {
                case EACCES:
@@ -2114,15 +2139,79 @@ int camera_v4l2_get_command(void *camera_handle, int64_t command, void **value)
                }
        }
 
+_GET_COMMAND_DONE:
        g_mutex_unlock(&handle->lock);
 
        return ret;
 }
 
 
+static void __dump_batch_command(camera_batch_command_control_s *batch_command)
+{
+       if (!batch_command) {
+               LOGE("NULL batch command");
+               return;
+       }
+
+       LOGI("[WHITE_BALANCE] %d", batch_command->white_balance);
+       LOGI("[ISO] %d", batch_command->iso);
+       LOGI("[CONTRAST] %d", batch_command->contrast);
+       LOGI("[HUE] %d", batch_command->hue);
+       LOGI("[SATURATION] %d", batch_command->saturation);
+       LOGI("[SHARPNESS] %d", batch_command->sharpness);
+       LOGI("[BRIGHTNESS] %d", batch_command->brightness);
+       LOGI("[EFFECT] %d", batch_command->effect);
+       LOGI("[SCENE_MODE] %d", batch_command->scene_mode);
+       LOGI("[EXPOSURE_MODE] %d", batch_command->exposure_mode);
+       LOGI("[EXPOSURE] %d", batch_command->exposure);
+       LOGI("[ROTATION] %d", batch_command->rotation);
+       LOGI("[FLIP] %d", batch_command->flip);
+       LOGI("[FOCUS_MODE] %d", batch_command->focus_mode);
+       LOGI("[FOCUS_RANGE] %d", batch_command->focus_range);
+       LOGI("[FOCUS_AREA] %d,%d,%dx%d", batch_command->focus_area.x, batch_command->focus_area.y,
+               batch_command->focus_area.width, batch_command->focus_area.height);
+       LOGI("[FOCUS_LEVEL] %d", batch_command->focus_level);
+       LOGI("[SHOT_MODE] %d", batch_command->shot_mode);
+       LOGI("[ANTI_SHAKE] %d", batch_command->anti_shake);
+       LOGI("[DIGITAL_ZOOM] %d", batch_command->digital_zoom);
+       LOGI("[OPTICAL_ZOOM] %d", batch_command->optical_zoom);
+       LOGI("[RECORDING_HINT] %d", batch_command->recording_hint);
+       LOGI("[WDR] %d", batch_command->wdr);
+       LOGI("[SHUTTER_SPEED] %d/%d", batch_command->shutter_speed.numerator, batch_command->shutter_speed.denominator);
+       LOGI("[FLASH_MODE] %d", batch_command->flash_mode);
+       LOGI("[FLASH_BRIGHTNESS] %d", batch_command->flash_brightness);
+       LOGI("[FACE_DETECTION] %d", batch_command->face_detection);
+       LOGI("[PTZ_TYPE] %d", batch_command->ptz_type);
+       LOGI("[PAN] %d", batch_command->pan);
+       LOGI("[TILT] %d", batch_command->tilt);
+       LOGI("[BITRATE] %d", batch_command->bitrate);
+       LOGI("[GOP_INTERVAL] %d", batch_command->gop_interval);
+       LOGI("[CAPTURE_COUNT] %d", batch_command->capture_count);
+       LOGI("[CAPTURE_INTERVAL] %d", batch_command->capture_interval);
+}
+
+
 int camera_v4l2_set_batch_command(void *camera_handle, camera_batch_command_control_s *batch_command, int64_t *error_command)
 {
+       int ret = CAMERA_ERROR_NONE;
+       int i = 0;
+       int support_count = 0;
        hal_camera_handle *handle = (hal_camera_handle *)camera_handle;
+       set_batch_table_s set_table[] = {
+               {CAMERA_COMMAND_BRIGHTNESS, batch_command ? (void *)&batch_command->brightness : NULL},
+               {CAMERA_COMMAND_CONTRAST, batch_command ? (void *)&batch_command->contrast : NULL},
+               {CAMERA_COMMAND_SATURATION, batch_command ? (void *)&batch_command->saturation : NULL},
+               {CAMERA_COMMAND_SHARPNESS, batch_command ? (void *)&batch_command->sharpness : NULL},
+               {CAMERA_COMMAND_PTZ_TYPE, batch_command ? (void *)&batch_command->ptz_type : NULL},
+               {CAMERA_COMMAND_PAN, batch_command ? (void *)&batch_command->pan : NULL},
+               {CAMERA_COMMAND_TILT, batch_command ? (void *)&batch_command->tilt : NULL},
+               {CAMERA_COMMAND_FLIP, batch_command ? (void *)&batch_command->flip : NULL},
+               {CAMERA_COMMAND_CAPTURE_COUNT, batch_command ? (void *)&batch_command->capture_count : NULL},
+               {CAMERA_COMMAND_CAPTURE_INTERVAL, batch_command ? (void *)&batch_command->capture_interval : NULL},
+               {CAMERA_COMMAND_FOCUS_MODE, batch_command ? (void *)&batch_command->focus_mode : NULL},
+               {CAMERA_COMMAND_FOCUS_RANGE, batch_command ? (void *)&batch_command->focus_range : NULL},
+               {CAMERA_COMMAND_FOCUS_LEVEL, batch_command ? (void *)&batch_command->focus_level : NULL}
+       };
 
        if (!handle || !batch_command) {
                LOGE("NULL param %p %p", handle, batch_command);
@@ -2131,14 +2220,26 @@ int camera_v4l2_set_batch_command(void *camera_handle, camera_batch_command_cont
 
        g_mutex_lock(&handle->lock);
 
-       LOGD("set batch command - flag %"PRIx64", state %d",
-               batch_command->command_set_flag, handle->state);
+       support_count = sizeof(set_table) / sizeof(set_batch_table_s);
+
+       LOGD("set batch command - support count %d", support_count);
+
+       __dump_batch_command(batch_command);
+
+       for (i = 0 ; i < support_count ; i++) {
+               if (!(batch_command->command_set_flag & set_table[i].command))
+                       continue;
 
-       /* TODO: to be implemented */
+               ret = __set_command(handle, set_table[i].command, set_table[i].value);
+               if (ret != CAMERA_ERROR_NONE) {
+                       LOGE("failed command %"PRIx64", ret 0x%x", set_table[i].command, ret);
+                       break;
+               }
+       }
 
        g_mutex_unlock(&handle->lock);
 
-       return CAMERA_ERROR_NONE;
+       return ret;
 }
 
 
index d4e6397..8c0761d 100644 (file)
 #define BUFFER_MAX                  4
 #define V4L2_PLANES_MAX             4
 
+typedef struct _set_batch_table_s {
+       int64_t command;
+       void *value;
+} set_batch_table_s;
+
 typedef struct _camera_hal_handle {
        /* tbm */
        tbm_bufmgr bufmgr;
@@ -76,6 +81,11 @@ typedef struct _camera_hal_handle {
        GMutex msg_cb_lock;
        GCond msg_cb_cond;
 
+       /* focus */
+       gint32 focus_mode;
+       gint32 focus_range;
+       gint32 focus_level;
+
        /* etc */
        GMutex lock;
        camera_state_e state;