/* It should set the capture resolution Cheated from the openCV cap_libv4l.cpp the method is the following: Turn off the stream (video_disable) Unmap buffers Close the filedescriptor Initialize the camera again with the new resolution */ int setResolution(struct vdIn *vd, int width, int height) { int ret; DBG("setResolution(%d, %d)\n", width, height); vd->streamingState = STREAMING_PAUSED; if(video_disable(vd, STREAMING_PAUSED) == 0) { // do streamoff DBG("Unmap buffers\n"); int i; for(i = 0; i < NB_BUFFER; i++) munmap(vd->mem[i], vd->buf.length); if(CLOSE_VIDEO(vd->fd) == 0) { DBG("Device closed successfully\n"); } vd->width = width; vd->height = height; if(init_v4l2(vd) < 0) { fprintf(stderr, " Init v4L2 failed !! exit fatal \n"); return -1; } else { DBG("reinit done\n"); video_enable(vd); return 0; } } else { DBG("Unable to disable streaming\n"); return -1; } return ret; }
int CameraManager2::close_v4l2() { int i; if (vd->isstreaming) video_disable(); /* If the memory maps are not released the device will remain opened even after a call to close(); */ for (i = 0; i < NB_BUFFER; i++) { munmap (vd->mem[i], vd->buf.length); } if (vd->tmpbuffer) free (vd->tmpbuffer); vd->tmpbuffer = NULL; free (vd->framebuffer); vd->framebuffer = NULL; free (vd->videodevice); free (vd->status); free (vd->pictName); vd->videodevice = NULL; vd->status = NULL; vd->pictName = NULL; close (vd->fd); return 0; }
void destroy_video_device(struct video_device *vd) { if (vd->streaming_state == STREAMING_ON) { video_disable(vd, STREAMING_OFF); } if (CLOSE_VIDEO(vd->fd) != 0) { log_itf(LOG_ERROR, "Failed to close device %s.", vd->device_filename); } free(vd->framebuffer); vd->framebuffer = NULL; free(vd->device_filename); vd->device_filename = NULL; free(vd->formats); vd->formats = NULL; vd->format_count = 0; free(vd->resolutions); vd->resolutions = NULL; vd->resolution_count = 0; free(vd); }
int setResolution(struct vdIn *vd, int width, int height) { int ret; DBG("setResolution(%d, %d)\n", width, height); vd->streamingState = STREAMING_PAUSED; if (video_disable(vd, STREAMING_PAUSED) == 0) { ret = IOCTL_VIDEO(vd->fd, VIDIOC_G_FMT, &vd->fmt); if (ret != 0) { DBG("Unable to get current format\n"); return ret; } else { DBG("Current size: %d, %d)\n", vd->fmt.fmt.pix.width, vd->fmt.fmt.pix.height); } vd->fmt.fmt.pix.width = width; vd->fmt.fmt.pix.height = height; ret = IOCTL_VIDEO(vd->fd, VIDIOC_S_FMT, &vd->fmt); if (ret != 0) { DBG("Unable to set the new format code: %d errno: %d\n", ret, errno); if (errno == EBUSY) DBG("EBUSY: IO is in progress\n"); } else { DBG("New resolution is successfully applied\n"); } if (video_enable(vd) == 0) { DBG("Streaming on again\n"); memset(&vd->rb, 0, sizeof(struct v4l2_requestbuffers)); vd->rb.count = NB_BUFFER; vd->rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; vd->rb.memory = V4L2_MEMORY_MMAP; ret = IOCTL_VIDEO(vd->fd, VIDIOC_REQBUFS, &vd->rb); if (ret < 0) { perror("Unable to reallocate buffers"); } } else { DBG("Unable to reenable streaming\n"); return -1; } } else { DBG("Unable to disable streaming\n"); return -1; } return ret; }
void close_v4l2(struct vdIn *vd) { if (vd->isstreaming) video_disable(vd); if (vd->tmpbuffer) free(vd->tmpbuffer); vd->tmpbuffer = NULL; free(vd->framebuffer); vd->framebuffer = NULL; free(vd->videodevice); free(vd->status); free(vd->pictName); vd->videodevice = NULL; vd->status = NULL; vd->pictName = NULL; }
int close_v4l2(struct vdIn *vd) { if(vd->streamingState == STREAMING_ON) video_disable(vd, STREAMING_OFF); if(vd->tmpbuffer) free(vd->tmpbuffer); vd->tmpbuffer = NULL; free(vd->framebuffer); vd->framebuffer = NULL; free(vd->videodevice); free(vd->status); free(vd->pictName); vd->videodevice = NULL; vd->status = NULL; vd->pictName = NULL; return 0; }