From: Jinhyung Jo Date: Thu, 29 Mar 2012 11:55:07 +0000 (+0900) Subject: [Title] Fixed a bug that is not streaming off. X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~1714 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ac6178e7490eafcec9318584c9b406c3e9194969;p=sdk%2Femulator%2Fqemu.git [Title] Fixed a bug that is not streaming off. [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] --- diff --git a/tizen/src/hw/maru_camera_linux_pci.c b/tizen/src/hw/maru_camera_linux_pci.c index 0e86dc2414..36f80c958b 100644 --- a/tizen/src/hw/maru_camera_linux_pci.c +++ b/tizen/src/hw/maru_camera_linux_pci.c @@ -153,11 +153,17 @@ static int __v4l2_grab(MaruCamState *state) return 0; } - if (!v4l2_fd) { + if (!v4l2_fd || (v4l2_fd == -1)) { WARN("file descriptor is closed or not opened \n"); return -1; } + qemu_mutex_lock(&state->thread_mutex); + ret = state->streamon; + qemu_mutex_unlock(&state->thread_mutex); + if (!ret) + return -1; + buf = state->vaddr + (state->buf_size * index); ret = v4l2_read(v4l2_fd, buf, state->buf_size); if ( ret < 0) { @@ -219,6 +225,7 @@ wait_worker_thread: } } else { qemu_mutex_unlock(&state->thread_mutex); + INFO("...... Streaming off\n"); goto wait_worker_thread; } } @@ -237,7 +244,7 @@ void marucam_device_open(MaruCamState* state) MaruCamParam *param = state->param; param->top = 0; - v4l2_fd = v4l2_open("/dev/video0", O_RDWR | O_NONBLOCK); + v4l2_fd = v4l2_open("/dev/video0", O_RDWR); if (v4l2_fd < 0) { ERR("v4l2 device open failed.(/dev/video0)\n"); param->errCode = EINVAL; @@ -269,16 +276,22 @@ void marucam_device_start_preview(MaruCamState* state) state->buf_size = dst_fmt.fmt.pix.sizeimage; qemu_cond_signal(&state->thread_cond); qemu_mutex_unlock(&state->thread_mutex); + INFO("Starting preview!\n"); } // MARUCAM_CMD_STOP_PREVIEW void marucam_device_stop_preview(MaruCamState* state) { + struct timespec req; + req.tv_sec = 0; + req.tv_nsec = 333333333; + qemu_mutex_lock(&state->thread_mutex); state->streamon = 0; state->buf_size = 0; qemu_mutex_unlock(&state->thread_mutex); - sleep(0); + nanosleep(&req, NULL); + INFO("Stopping preview!\n"); } void marucam_device_s_param(MaruCamState* state) @@ -356,7 +369,7 @@ void marucam_device_g_fmt(MaruCamState* state) if (xioctl(v4l2_fd, VIDIOC_G_FMT, &format) < 0) { ERR("failed to get video format: %s\n", strerror(errno)); - param->errCode = errno; + param->errCode = errno; } else { param->stack[0] = format.fmt.pix.width; param->stack[1] = format.fmt.pix.height; @@ -637,10 +650,15 @@ void marucam_device_enum_fintv(MaruCamState* state) // MARUCAM_CMD_CLOSE void marucam_device_close(MaruCamState* state) { + uint32_t is_streamon; + qemu_mutex_lock(&state->thread_mutex); - state->streamon = 0; + is_streamon = state->streamon; qemu_mutex_unlock(&state->thread_mutex); + if (is_streamon) + marucam_device_stop_preview(state); + marucam_reset_controls(); v4l2_close(v4l2_fd);