[Title] Fixed a bug that is not streaming off.
authorJinhyung Jo <jinhyung.jo@samsung.com>
Thu, 29 Mar 2012 11:55:07 +0000 (20:55 +0900)
committerJinhyung Jo <jinhyung.jo@samsung.com>
Thu, 29 Mar 2012 11:55:07 +0000 (20:55 +0900)
[Type] Bugfix
[Module] Emulator / Camera
[Priority] Major
[CQ#]
[Redmine#]
[Problem] Camera timeout error while it is starting.
[Cause] Image processing thread was not stop.
[Solution] wait until thread is stopped.
[TestCase]

tizen/src/hw/maru_camera_linux_pci.c

index 0e86dc24149dcba738c6a1d9485701c76aa34186..36f80c958bcb3031fa6b8e3c7ce757bde1e444e4 100644 (file)
@@ -153,11 +153,17 @@ static int __v4l2_grab(MaruCamState *state)
                return 0;\r
        }\r
 \r
-       if (!v4l2_fd) {\r
+       if (!v4l2_fd || (v4l2_fd == -1)) {\r
                WARN("file descriptor is closed or not opened \n");\r
                return -1;\r
        }\r
 \r
+       qemu_mutex_lock(&state->thread_mutex);\r
+       ret = state->streamon;\r
+       qemu_mutex_unlock(&state->thread_mutex);\r
+       if (!ret)\r
+              return -1;\r
+\r
        buf = state->vaddr + (state->buf_size * index);\r
        ret = v4l2_read(v4l2_fd, buf, state->buf_size);\r
        if ( ret < 0) {\r
@@ -219,6 +225,7 @@ wait_worker_thread:
                        }\r
                } else {\r
                        qemu_mutex_unlock(&state->thread_mutex);\r
+                       INFO("...... Streaming off\n");\r
                        goto wait_worker_thread;\r
                }\r
        }\r
@@ -237,7 +244,7 @@ void marucam_device_open(MaruCamState* state)
        MaruCamParam *param = state->param;\r
 \r
        param->top = 0;\r
-       v4l2_fd = v4l2_open("/dev/video0", O_RDWR | O_NONBLOCK);\r
+       v4l2_fd = v4l2_open("/dev/video0", O_RDWR);\r
        if (v4l2_fd < 0) {\r
                ERR("v4l2 device open failed.(/dev/video0)\n");\r
                param->errCode = EINVAL;\r
@@ -269,16 +276,22 @@ void marucam_device_start_preview(MaruCamState* state)
        state->buf_size = dst_fmt.fmt.pix.sizeimage;\r
        qemu_cond_signal(&state->thread_cond);\r
        qemu_mutex_unlock(&state->thread_mutex);\r
+       INFO("Starting preview!\n");\r
 }\r
 \r
 // MARUCAM_CMD_STOP_PREVIEW\r
 void marucam_device_stop_preview(MaruCamState* state)\r
 {\r
+       struct timespec req;\r
+       req.tv_sec = 0;\r
+       req.tv_nsec = 333333333;\r
+\r
        qemu_mutex_lock(&state->thread_mutex);\r
        state->streamon = 0;\r
        state->buf_size = 0;\r
        qemu_mutex_unlock(&state->thread_mutex);\r
-       sleep(0);\r
+       nanosleep(&req, NULL);\r
+       INFO("Stopping preview!\n");\r
 }\r
 \r
 void marucam_device_s_param(MaruCamState* state)\r
@@ -356,7 +369,7 @@ void marucam_device_g_fmt(MaruCamState* state)
 \r
        if (xioctl(v4l2_fd, VIDIOC_G_FMT, &format) < 0) {\r
                ERR("failed to get video format: %s\n", strerror(errno));\r
-               param->errCode = errno;         \r
+               param->errCode = errno;\r
        } else {\r
                param->stack[0] = format.fmt.pix.width;\r
                param->stack[1] = format.fmt.pix.height;\r
@@ -637,10 +650,15 @@ void marucam_device_enum_fintv(MaruCamState* state)
 // MARUCAM_CMD_CLOSE\r
 void marucam_device_close(MaruCamState* state)\r
 {\r
+       uint32_t is_streamon;\r
+\r
        qemu_mutex_lock(&state->thread_mutex);\r
-       state->streamon = 0;\r
+       is_streamon = state->streamon;\r
        qemu_mutex_unlock(&state->thread_mutex);\r
 \r
+       if (is_streamon)\r
+              marucam_device_stop_preview(state);\r
+\r
        marucam_reset_controls();\r
 \r
        v4l2_close(v4l2_fd);\r