Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: clear the buffers in the correct place #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions lib/src/v4l2_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ static int set_io_method(enum io_method io_meth)
static int stop_capturing(void)
{
enum v4l2_buf_type type;
struct v4l2_requestbuffers req;

switch (io) {
case IO_METHOD_READ:
Expand All @@ -97,23 +96,6 @@ static int stop_capturing(void)
break;
}

CLEAR(req);

/*
* Request to clear the buffers. This helps with changing resolution.
*/
req.count = 0;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;

if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
if (EINVAL == errno) {
fprintf(stderr, "The device does not support "
"memory mapping\n");
}
return ERR;
}

return 0;
}

Expand Down Expand Up @@ -181,6 +163,7 @@ static int start_capturing(void)

static int uninit_device(void)
{
struct v4l2_requestbuffers req;
unsigned int i;
int ret = 0;

Expand All @@ -202,6 +185,24 @@ static int uninit_device(void)
}

free(buffers);

CLEAR(req);

/*
* Request to clear the buffers. This helps with changing resolution.
*/
req.count = 0;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;

if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
if (EINVAL == errno) {
fprintf(stderr, "The device does not support "
"memory mapping\n");
}
return ERR;
}

return ret;
}

Expand Down