From ce31fbc48a43ea4265be1d20f157e8749b3e11dd Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Wed, 14 Sep 2011 06:55:16 -0700 Subject: Fixes "stop device" issue on Linux Apparently, video driver doesn't allow frame size change, once it has been explicitly set. In order to get around this we need to reset the handle to the camera device by closing, and then reopening it. Change-Id: Icfd37b3c196d2643507218b965c5015884ed455b --- android/camera/camera-capture-linux.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'android/camera') diff --git a/android/camera/camera-capture-linux.c b/android/camera/camera-capture-linux.c index 5c7e242..072d06e 100644 --- a/android/camera/camera-capture-linux.c +++ b/android/camera/camera-capture-linux.c @@ -808,6 +808,10 @@ camera_device_start_capturing(CameraDevice* ccd, return -1; } cd = (LinuxCameraDevice*)ccd->opaque; + if (cd->handle < 0) { + E("%s: Camera device is not opened", __FUNCTION__); + return -1; + } /* Try to set pixel format with the given dimensions. */ CLEAR(fmt); @@ -890,6 +894,10 @@ camera_device_stop_capturing(CameraDevice* ccd) return -1; } cd = (LinuxCameraDevice*)ccd->opaque; + if (cd->handle < 0) { + E("%s: Camera device is not opened", __FUNCTION__); + return -1; + } switch (cd->io_type) { case CAMERA_IO_DIRECT: @@ -916,6 +924,13 @@ camera_device_stop_capturing(CameraDevice* ccd) cd->framebuffers = NULL; cd->framebuffer_num = 0; } + + /* Reopen the device to reset its internal state. It seems that if we don't + * do that, an attempt to reinit the device with different frame dimensions + * would fail. */ + close(cd->handle); + cd->handle = open(cd->device_name, O_RDWR | O_NONBLOCK, 0); + return 0; } @@ -932,6 +947,10 @@ camera_device_read_frame(CameraDevice* ccd, return -1; } cd = (LinuxCameraDevice*)ccd->opaque; + if (cd->handle < 0) { + E("%s: Camera device is not opened", __FUNCTION__); + return -1; + } if (cd->io_type == CAMERA_IO_DIRECT) { /* Read directly from the device. */ -- cgit v1.1