|
使用V4L2代码如下:
/* 第四步:让摄像头驱动申请存放图像数据的缓冲区 */
struct v4l2_requestbuffers reqbuf;
reqbuf.count = COUNT; // 缓冲区个数
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; // 缓冲区类型
reqbuf.memory = V4L2_MEMORY_MMAP; // 缓冲区的用途:用于内存映射
ret = ioctl(fd, VIDIOC_REQBUFS, &reqbuf);
if (-1 == ret)
{
perror("ioctl VIDIOC_REQBUFS");
close(fd);
return -4;
}
printf("qrequbuf.count is %d\n", reqbuf.count);
/* 第五步:查询每个缓冲区的信息,同时进行内存映射 */
for (i = 0; i < COUNT; i++)
{
struct v4l2_buffer buff;
buff.type = reqbuf.type;
buff.memory = reqbuf.memory;
buff.index = i;
ret = ioctl(fd, VIDIOC_QUERYBUF, &buff);
if (-1 == ret) // 操作失败
{
printf("querybuf falied\n");
break;
}
/* 打印缓冲区的长度和偏移量 */
printf("buf[%d]: len = %d offset: %d\n", i, buff.length, buff.m.offset);
查询每个缓冲区时,ioctl(fd, VIDIOC_QUERYBUF, &buff)返回-1。其中COUNT= 5.
|
|