V4L2采集图像时,总是在分配内存(mmap)时失败,求助
本帖最后由 thy110 于 2017-6-6 12:19 编辑我的是模拟摄像头+TVP5150+S3C6410,驱动是正常的,我用开发板的卖家提供的可执行程序测试过了,就是在没有源码,想自己写个程序,顺便学习一下V4L2编程。
我参考的是V4L2官方那个程序,再接在他的基础上修改了]参数,但是现在总是在分配内存(mmap)时失败。
错误信息如下:
<------------camera infomation------------->
device driver=Samsung FIMC Dris3c-fimc0
device name=s3c-fimc0
bus_infomation=FIMC AHB-bus
image_width=640
image_height=480
pixel_format=1448695129
<------------screen infomation------------->
id=s3cfb
x=800
y=480
bpp=16
redoffset=11,redlength=5,msb_right=0
greenoffset=5,greenlength=6,msb_right=0
blueoffset=0,bluelength=5,msb_right=0
screensize=768000
init_mmap
buffers.length=0
buffers.start=-1
mmap error 22, Invalid argument
相关代码如下:
static void init_mmap(void)
{
struct v4l2_requestbuffers req;
fprintf(stderr, "init_mmap\n");
//VIDIOC_REQBUFS
CLEAR(req);
req.count = 4;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
if(-1 == xioctl(fd1, VIDIOC_REQBUFS, &req))
{
if (EINVAL == errno)
{
fprintf(stderr, "%s does not support ""memory mapping\n", dev_name1);
exit(EXIT_FAILURE);
}
else
errno_exit("VIDIOC_REQBUFS");
}
if(req.count < 2)
{
fprintf(stderr, "Insufficient buffer memory on %s\n",dev_name1);
exit(EXIT_FAILURE);
}
//VIDIOC_QUERYBUF
buffers = calloc(req.count, sizeof(*buffers)); ///////////
if (!buffers)
{
fprintf(stderr, "Out of memory\n");
exit(EXIT_FAILURE);
}
for (n_buffers = 0; n_buffers < req.count; ++n_buffers)
{
struct v4l2_buffer buf;
CLEAR(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = n_buffers;
if (-1 == xioctl(fd1, VIDIOC_QUERYBUF, &buf))
errno_exit("VIDIOC_QUERYBUF");
buffers.length = buf.length;
buffers.start =mmap(NULL /* start anywhere */,buf.length,
PROT_READ | PROT_WRITE /* required */,
MAP_SHARED /* recommended */,
fd1, buf.m.offset);
fprintf(stderr, "buffers.length=%d\n", buffers.length);
fprintf(stderr, "buffers.start=%d\n", buffers.start);
if (MAP_FAILED == buffers.start)
{
errno_exit("mmap");
}
}//now n_buffers is 4
//fbmmap
fb_buffer=(char*)mmap(NULL,screensize,PROT_READ | PROT_WRITE,MAP_SHARED,fd2,0);
if(MAP_FAILED == fb_buffer)
{
errno_exit("mmap");
}
//malloc the yuv_buffer
yuv_buffer = (char*)malloc(screensize);
if (!yuv_buffer)
{
fprintf(stderr, "Out of memory\n");
exit(EXIT_FAILURE);
}
//malloc the rgb_buffer
rgb_buffer = (char*)malloc(screensize);
if (!rgb_buffer)
{
fprintf(stderr, "Out of memory\n");
exit(EXIT_FAILURE);
}
}
页:
[1]