Linux下V4L2拍照测试用例
作者:网络转载 发布时间:[ 2013/8/26 14:13:38 ] 推荐标签:
一、源码test.c
#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
int main(){
//////
int fd = open("/dev/video0",O_RDWR);
printf("TK------->>>fd is %d
",fd);
//////
struct v4l2_capability cap;
ioctl(fd,VIDIOC_QUERYCAP,&cap);
printf("TK---------->>>>>Driver Name:%s
Card Name:%s
Bus info:%s
",cap.driver,cap.card,cap.bus_info);
//////
struct v4l2_fmtdesc fmtdesc;
fmtdesc.index = 0; fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
while(ioctl(fd,VIDIOC_ENUM_FMT,&fmtdesc) != -1){
printf("TK-------->>>>>fmtdesc.description is %s
",fmtdesc.description);
fmtdesc.index ++;
}
//////
struct v4l2_format fmt;
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ioctl(fd,VIDIOC_G_FMT,&fmt);
printf("TK----------->>>>>fmt.fmt.width is %d
fmt.fmt.pix.height is %d
fmt.fmt.pix.colorspace is %d
",fmt.fmt.pix.width,fmt.fmt.pix.height,fmt.fmt.pix.colorspace);
//////
struct v4l2_requestbuffers req;
req.count = 4;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
ioctl(fd,VIDIOC_REQBUFS,&req);
struct buffer{
void *start;
unsigned int length;
}*buffers;
buffers = (struct buffer*)calloc (req.count, sizeof(*buffers));
unsigned int n_buffers = 0;
for(n_buffers = 0; n_buffers < req.count; ++n_buffers){
struct v4l2_buffer buf;
memset(&buf,0,sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = n_buffers;
if(ioctl(fd,VIDIOC_QUERYBUF,&buf) == -1){
printf("TK---------_>>>>>>error
");
close(fd);
exit(-1);
}
buffers[n_buffers].length = buf.length;
buffers[n_buffers].start = mmap(NULL,buf.length,PROT_READ|PROT_WRITE,MAP_SHARED,fd,buf.m.offset);
if(MAP_FAILED == buffers[n_buffers].start){
printf("TK--------__>>>>>error 2
");
close(fd);
exit(-1);
}
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11