使用5.1系统的kernel,rk3288-reload开发板,在linux下开发
使用内核自带的摄像头驱动,写了一个测试程序,但是把申请的缓冲区放入队列时失败了,查找了原因,是在:
- for (i = 0; i < NB_BUFFER; i++) {
-
memset(&tV4l2Buf, 0, sizeof(struct v4l2_buffer)); -
tV4l2Buf.index = i; -
tV4l2Buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; -
tV4l2Buf.memory = V4L2_MEMORY_MMAP; -
tV4l2Buf.flags = 0; -
iRet = ioctl(v4l2_fd, VIDIOC_QUERYBUF, &tV4l2Buf); -
if (iRet < 0) { -
DWrite("Unable to query buffer.\n"); -
goto end; -
} -
printf("length: 0x%x offset: 0x%x\n", tV4l2Buf.length, tV4l2Buf.m.offset); -
pucVideoBuf[i] = (unsigned char *)mmap(0, /* start anywhere */ -
tV4l2Buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, v4l2_fd, -
tV4l2Buf.m.offset); -
if (pucVideoBuf[i] == MAP_FAILED) { -
DWrite("Unable to map buffer\n"); -
goto end; -
} -
printf("length: 0x%x offset: 0x%x\n", tV4l2Buf.length, tV4l2Buf.m.offset); - 打印出来的结果是:
- length: 0xeb000 offset: 0x0
- length: 0xeb000 offset: 0xeb000
- length: 0xeb000 offset: 0x1d6000
- length: 0xeb000 offset: 0x2c1000
随后通过映射的地址加入缓冲队列 调用
ioctl(v4l2_fd, VIDIOC_QBUF, &tV4l2Buf);
返回-1失败提示通过 fprintf(stderr, “%s error %d, %s\n”, s, errno, strerror(errno));
打印 error 22, Invalid argument”