1. 打开设备文件。
int fd=open(”/dev/video0″,O_RDWR)
2. 取得设备的capability,看看设备具有什么功能,比如是否具有视频输入,或者音频输入输出等。VIDIOC_QUERYCAP,struct v4l2_capability
v4l2_std_id std
do {
ret= ioctl(fd, VIDIOC_QUERYSTD, &std)
} while (ret == -1 &&errno == EAGAIN)
switch (std) {
case V4L2_STD_NTSC:
//……
case V4L2_STD_PAL:
//……
}
3. 选择视频输入,一个视频设备可以有多个视频输入。VIDIOC_S_INPUT,struct v4l2_input(可不要)
4. 设置视频的制式和帧格式,制式包括PAL,NTSC,帧的格式个包括宽度和高度等。
VIDIOC_S_STD,VIDIOC_S_FMT,struct v4l2_std_id,struct v4l2_format
struct v4l2_format fmt
memset ( &fmt, 0, sizeof(fmt) )
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
fmt.fmt.pix.width = 320
fmt.fmt.pix.height = 240
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG
if (ioctl(fd, VIDIOC_S_FMT, &fmt) <0)
{
printf("set format failed\n")
//return 0
}
5. 向驱动申请帧缓冲,一般不超过5个。struct v4l2_requestbuffers
struct v4l2_requestbuffers req
memset(&req, 0, sizeof (req))
req.count = 4
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
req.memory = V4L2_MEMORY_MMAP
if (ioctl(fd,VIDIOC_REQBUFS,&req) == -1)
{
perror("VIDIOC_REQBUFS error \n")
//return -1
}
6.申请物理内存
将申请到的帧缓冲映射到用户空间,这样就可以直接 *** 作采集到的帧了,而不必去复制。将申请到的帧缓冲全部入队列,以便存放采集到的数据.VIDIOC_QBUF,struct v4l2_buffer
VideoBuffer* buffers = calloc( req.count, sizeof(VideoBuffer) )
printf("sizeof(VideoBuffer) is %d\n",sizeof(VideoBuffer))
struct v4l2_buffer buf
for (numBufs = 0numBufs <req.countnumBufs++)
{
memset( &buf, 0, sizeof(buf) )
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
buf.memory = V4L2_MEMORY_MMAP
buf.index = numBufs
if (ioctl(fd, VIDIOC_QUERYBUF, &buf) <0)
{
printf("VIDIOC_QUERYBUF error\n")
//return -1
}
printf("buf len is %d\n",sizeof(buf))
//内存映射
buffers[numBufs].length = buf.length
buffers[numBufs].offset = (size_t) buf.m.offset
buffers[numBufs].start = mmap (NULL, buf.length,PROT_READ | PROT_WRITE, MAP_SHARED, fd, buf.m.offset)
printf("buffers.length = %d,buffers.offset = %d ,buffers.start[0] = %d\n",buffers[num
尊敬的联想用户,您好:
为您提供联想官方驱动下载地址:
驱动下载链接:http://support1.lenovo.com.cn/lenovo/wsi/Modules/Drive.aspx?intcmp=I_F_Driver
更多问题您可以咨询idea论坛:lenovobbs.lenovo.com.cn
Think论坛:thinkbbs.lenovo.com.cn
联想乐社区:http://bbs.lenovomobile.com/forum.php
期待您满意的评价,感谢您对联想的支持,祝您生活愉快!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)