More info: I found this in v4l2_driver.c. That "sleep (1)" seems bad.
int v4l2_free_bufs(struct v4l2_driver *drv)
{
unsigned int i;
if (!drv->n_bufs)
return 0;
/* Requests the driver to free all buffers */
drv->reqbuf.count = 0;
drv->reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
drv->reqbuf.memory = V4L2_MEMORY_MMAP;
/* stop capture */
if (xioctl(drv->fd,VIDIOC_STREAMOFF,&drv->reqbuf.type)<0)
return errno;
sleep (1); // FIXME: Should check if all buffers are stopped
/* V4L2 API says REQBUFS with count=0 should be used to release buffer.
However, video-buf.c doesn't implement it.
*/
#if 0
if (xioctl(drv->fd,VIDIOC_REQBUFS,&drv->reqbuf)<0) {
perror("reqbufs while freeing buffers");
return errno;
}
#endif