From: Jeongmo Yang Date: Wed, 8 Aug 2018 09:15:26 +0000 (+0900) Subject: Update for camera_set/get_command function X-Git-Tag: submit/tizen/20180810.054355^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_5.0_unified;p=platform%2Fadaptation%2Fcamera-hal-v4l2.git Update for camera_set/get_command function [Version] 0.0.2 [Profile] Common [Issue Type] Update [Dependency module] N/A Change-Id: Ia109d37b9f36258f06581425d0b791dee7fa84e2 Signed-off-by: Jeongmo Yang --- diff --git a/packaging/camera-hal-v4l2.spec b/packaging/camera-hal-v4l2.spec index 73acc1f..f589367 100644 --- a/packaging/camera-hal-v4l2.spec +++ b/packaging/camera-hal-v4l2.spec @@ -1,6 +1,6 @@ Name: camera-hal-v4l2 Summary: Tizen Camera Hal for V4L2 -Version: 0.0.1 +Version: 0.0.2 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 diff --git a/src/tizen_camera_v4l2.c b/src/tizen_camera_v4l2.c index f24bf92..fb7c87e 100644 --- a/src/tizen_camera_v4l2.c +++ b/src/tizen_camera_v4l2.c @@ -109,6 +109,48 @@ static int _camera_v4l2_wait_frame(int device_fd, int wait_time) } +static int _camera_v4l2_g_ctrl(int device_fd, int cid, int *value) +{ + int ret = 0; + struct v4l2_control ctrl; + + if (!value) { + LOGE("NULL param"); + return CAMERA_ERROR_INVALID_PARAMETER; + } + + memset(&ctrl, 0x0, sizeof(struct v4l2_control)); + + ctrl.id = cid; + + ret = ioctl(device_fd, VIDIOC_G_CTRL, &ctrl); + + *value = ctrl.value; + + LOGD("G_CTRL id 0x%x, value %d, ret %d", cid, *value, ret); + + return ret; +} + + +static int _camera_v4l2_s_ctrl(int device_fd, int cid, int value) +{ + int ret = 0; + struct v4l2_control ctrl; + + memset(&ctrl, 0x0, sizeof(struct v4l2_control)); + + ctrl.id = cid; + ctrl.value = value; + + ret = ioctl(device_fd, VIDIOC_S_CTRL, &ctrl); + + LOGD("S_CTRL id 0x%x, value %d, ret %d", cid, value, ret); + + return ret; +} + + static int _camera_v4l2_stream(int device_fd, int type, gboolean onoff) { if (device_fd < 0) { @@ -1598,6 +1640,9 @@ int camera_stop_record(void *camera_handle) int camera_set_command(void *camera_handle, int64_t command, void *value) { + int ret = CAMERA_ERROR_NONE; + int cid = 0; + int ctrl_ret = 0; camera_hal_handle *handle = NULL; if (!camera_handle) { @@ -1620,17 +1665,64 @@ int camera_set_command(void *camera_handle, int64_t command, void *value) return CAMERA_ERROR_INVALID_STATE; } - LOGD("set command %lld - state %d", command, handle->state); + LOGD("set command %llx - state %d", command, handle->state); - /* TODO: to be implemented */ + switch (command) { + case CAMERA_COMMAND_EXPOSURE: + cid = V4L2_CID_BRIGHTNESS; + break; + case CAMERA_COMMAND_CONTRAST: + cid = V4L2_CID_CONTRAST; + break; + case CAMERA_COMMAND_SATURATION: + cid = V4L2_CID_SATURATION; + break; + case CAMERA_COMMAND_SHARPNESS: + cid = V4L2_CID_SHARPNESS; + break; + default: + LOGE("NOT_SUPPORTED %llx", command); + g_mutex_unlock(&handle->lock); + return CAMERA_ERROR_DEVICE_NOT_SUPPORTED; + } + + ctrl_ret = _camera_v4l2_s_ctrl(handle->device_fd, cid, (int)value); + if (ctrl_ret < 0) { + switch (errno) { + case EACCES: + case EPERM: + LOGE("Permission denied %d", errno); + ret = CAMERA_ERROR_PERMISSION_DENIED; + break; + case EINVAL: + LOGE("Invalid argument"); + ret = CAMERA_ERROR_INVALID_PARAMETER; + break; + case EBUSY: + LOGE("Device busy"); + ret = CAMERA_ERROR_DEVICE_BUSY; + break; + case ENOTSUP: + LOGE("Not supported"); + ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED; + break; + default: + LOGE("Unknown errro %d", errno); + ret = CAMERA_ERROR_INTERNAL; + break; + } + } g_mutex_unlock(&handle->lock); - return CAMERA_ERROR_NONE; + return ret; } int camera_get_command(void *camera_handle, int64_t command, void **value) { + int ret = CAMERA_ERROR_NONE; + int cid = 0; + int ctrl_ret = 0; camera_hal_handle *handle = NULL; if (!camera_handle) { @@ -1647,13 +1739,57 @@ int camera_get_command(void *camera_handle, int64_t command, void **value) g_mutex_lock(&handle->lock); - LOGD("get command %lld - state %d", command, handle->state); + LOGD("get command %llx - state %d", command, handle->state); - /* TODO: to be implemented */ + switch (command) { + case CAMERA_COMMAND_EXPOSURE: + cid = V4L2_CID_BRIGHTNESS; + break; + case CAMERA_COMMAND_CONTRAST: + cid = V4L2_CID_CONTRAST; + break; + case CAMERA_COMMAND_SATURATION: + cid = V4L2_CID_SATURATION; + break; + case CAMERA_COMMAND_SHARPNESS: + cid = V4L2_CID_SHARPNESS; + break; + default: + LOGE("NOT_SUPPORTED %llx", command); + g_mutex_unlock(&handle->lock); + return CAMERA_ERROR_DEVICE_NOT_SUPPORTED; + } + + ctrl_ret = _camera_v4l2_g_ctrl(handle->device_fd, cid, (int *)value); + if (ctrl_ret < 0) { + switch (errno) { + case EACCES: + case EPERM: + LOGE("Permission denied %d", errno); + ret = CAMERA_ERROR_PERMISSION_DENIED; + break; + case EINVAL: + LOGE("Invalid argument"); + ret = CAMERA_ERROR_INVALID_PARAMETER; + break; + case EBUSY: + LOGE("Device busy"); + ret = CAMERA_ERROR_DEVICE_BUSY; + break; + case ENOTSUP: + LOGE("Not supported"); + ret = CAMERA_ERROR_DEVICE_NOT_SUPPORTED; + break; + default: + LOGE("Unknown errro %d", errno); + ret = CAMERA_ERROR_INTERNAL; + break; + } + } g_mutex_unlock(&handle->lock); - return CAMERA_ERROR_NONE; + return ret; } int camera_set_batch_command(void *camera_handle, camera_batch_command_control_t *batch_command, int64_t *error_command)