应用层:
循环两次去获取内核申请的两个buffer的起始地址,通过这两个地址用mmap映射,这样用户层可以通过操作这两个地址,访问内存空间的buffer
for (n_buffers=0; n_buffers<req.count; ++n_buffers) { //循环两次,询问两次buffer
struct v4l2_buffer buf;
CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = n_buffers; //把结构体 struct v4l2_buffer的内容从用户层传递到内核 分别是buffers[0] buffers[1]往内核里传递
if (-1 == xioctl(fd, VIDIOC_QUERYBUF, &buf))
errno_exit("VIDIOC_QUERYBUF");
buffers[n_buffers].length = buf.length;
buffers[n_buffers].start = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.offset); //映射内存 buffers[0] buffers[1]
if (MAP_FAILED == buffers[n_buffers].start)
errno_exit("mmap");
}
-------------------------------------------------------------------