我拟采用 V4L2 dmabuf的方式实现 图像的采集,但是 提示错误:Failed to queue buffer: Invalid argument
代码如下:
actual_width = actual_fmt.fmt.pix_mp.width;
actual_height = actual_fmt.fmt.pix_mp.height;
for (int i = 0; i < BUFFER_COUNT ; ++i)
{
if (dma_buf_alloc(DMA_HEAP_UNCACHE_PATH,
buffer_size,
&frame_buffers[i].dmabuf_fd,
&frame_buffers[i].map)!=0){
perror("Failed to allocate DMA buffer");
return -1;
}
frame_buffers[i].index=i;
frame_buffers[i].size =buffer_size;
frame_buffers[i].y_size =actual_width*actual_height;
frame_buffers[i].vu_size = buffer_size-actual_width*actual_height;
//将缓冲区注册到摄像头
struct v4l2_buffer buf={0};
struct v4l2_plane planes[1]={0};
buf.index =0;
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
buf.memory = V4L2_MEMORY_DMABUF;
buf.length = 1;
buf.m.planes = planes;
planes[0].m.fd = frame_buffers[i].dmabuf_fd;
planes[0].length =buffer_size;
if (ioctl(cam_fd, VIDIOC_QBUF, &buf) < 0) {
perror("Failed to queue buffer");
return -1;
}
}
初始化方法 如上 ,不知道是不是内核不支持 DAMBUF的方式,相机输入大小 1920X1080,想通过 // 调用VIDIOC_QUERYCAP获取设备能力集
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) {
perror(“Failed to query device capabilities (VIDIOC_QUERYCAP)”);
return false;
}
// 检查是否支持DMA控制(DMABUF核心标志)和流式传输
bool has_dma_control = (cap.capabilities & V4L2_CAP_DMA_CONTROL) != 0; 发现头文件不支持V4L2_CAP_DMA_CONTROL宏 ,怀疑是不是不支持DMABUF的方式