Update for camera_set/get_command function 48/186248/1 accepted/tizen_5.0_unified accepted/tizen/5.0/unified/20181102.012207 accepted/tizen/unified/20180813.061401 submit/tizen/20180810.054355 submit/tizen_5.0/20181101.000001
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 8 Aug 2018 09:15:26 +0000 (18:15 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 8 Aug 2018 09:15:26 +0000 (18:15 +0900)
[Version] 0.0.2
[Profile] Common
[Issue Type] Update
[Dependency module] N/A

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

index 73acc1f..f589367 100644 (file)
@@ -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
index f24bf92..fb7c87e 100644 (file)
@@ -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)