linux_cam_test文件
相机测试:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <sys/mman.h>
#include <assert.h>
#include <linux/videodev2.h>
#include <linux/fb.h> #define CLEAR(x) memset(&(x), 0, sizeof(x))
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int DWORD;
typedef long LONG; #define CHECKNUM 8 struct {
unsigned int type;
char *name;
} enum_fmt[]={
{V4L2_CAP_VIDEO_CAPTURE, "V4L2_CAP_VIDEO_CAPTURE"},
{V4L2_CAP_VIDEO_OUTPUT, "V4L2_CAP_VIDEO_OUTPUT"},
{V4L2_CAP_VIDEO_OVERLAY, "V4L2_CAP_VIDEO_OVERLAY"},
{V4L2_CAP_VIDEO_CAPTURE_MPLANE, "V4L2_CAP_VIDEO_CAPTURE_MPLANE"},
{V4L2_CAP_VIDEO_OUTPUT_MPLANE, "V4L2_CAP_VIDEO_OUTPUT_MPLANE"},
{V4L2_CAP_VIDEO_M2M_MPLANE, "V4L2_CAP_VIDEO_M2M_MPLANE"},
{V4L2_CAP_VIDEO_M2M, "V4L2_CAP_VIDEO_M2M"},
{V4L2_CAP_STREAMING, "V4L2_CAP_STREAMING"},
}; int open_camer_device(char *path)
{
int fd; if((fd = open(path,O_RDWR | O_NONBLOCK)) < )
{
perror("Fail to open");
exit(EXIT_FAILURE);
} printf("open cam:%s success %d\n",path, fd);
return fd;
} void enum_video_ctrls_and_menus(int fd){
/*
\* To query the attributes of a control applications set the id field of a struct
\* v4l2_queryctrl and call the VIDIOC_QUERYCTRL ioctl with a pointer to this
\* structure. The driver fills the rest of the structure or returns an EINVAL
\* error code when the id is invalid.
\*
\* To enumerate controls call VIDIOC_QUERYCTRL with successive
\* id values starting from V4L2_CID_BASE up to and exclusive V4L2_CID_LASTP1,
\* or starting from V4L2_CID_PRIVATE_BASE until the driver returns EINVAL.
*/
struct v4l2_queryctrl queryctrl; /* Query Control structure as defined in <sys/videodev2.h> */
struct v4l2_querymenu querymenu; /* Query Menu Structure as defined in <sys/videodev2.h> */ fprintf(stdout,"Discovering controls:\n"); memset (&queryctrl, , sizeof (queryctrl));
for (queryctrl.id = V4L2_CID_BASE; queryctrl.id < V4L2_CID_LASTP1; queryctrl.id++) {
if ( ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl) == ) {
/* Check to see if this control is permanently disabled and should be ignored by the application */
if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
continue;
/* We got a video control back */
fprintf(stdout,"\nVIDIOC_QUERYCTRL(V4L2_CID_BASE+%d)\n", queryctrl.id-V4L2_CID_BASE);
fprintf(stdout," id: %d\n", queryctrl.id);
switch (queryctrl.type){
case V4L2_CTRL_TYPE_INTEGER:
fprintf(stdout, " type: INTEGER\n");
break;
case V4L2_CTRL_TYPE_BOOLEAN:
fprintf(stdout, " type: BOOLEAN\n");
break;
case V4L2_CTRL_TYPE_MENU:
fprintf(stdout, " type: MENU\n");
/* Additional information is required for menu controls, the name of menu items.
\* To query them applications set the id and index fields of struct v4l2_querymenu
\* and call the VIDIOC_QUERYMENU ioctl with a pointer to this structure. The driver
\* fills the rest of the structure or returns an EINVAL error code when the id or
\* index is invalid. Menu items are enumerated by calling VIDIOC_QUERYMENU with
\* successive index values from struct v4l2_queryctrl minimum (0) to maximum, inclusive.
*/
querymenu.id = queryctrl.id;
for (querymenu.index = queryctrl.minimum; querymenu.index < queryctrl.maximum; querymenu.index++){
fprintf(stdout, " menu id:%d\n", querymenu.index);
fprintf(stdout, " menu name:%s\n", querymenu.name);
}
break;
case V4L2_CTRL_TYPE_BUTTON:
fprintf(stdout, " type: BUTTON\n");
break;
}
fprintf(stdout," name: %s\n", queryctrl.name);
fprintf(stdout," minimum: %d\n", queryctrl.minimum);
fprintf(stdout," maximum: %d\n", queryctrl.maximum);
fprintf(stdout," step: %d\n", queryctrl.step);
fprintf(stdout," default_value: %d\n", queryctrl.default_value);
fprintf(stdout," flags: %d\n", queryctrl.flags);
} else { if (errno == EINVAL)
continue; perror("VIDIOC_QUERYCTRL");
break;
} } } /* End of enum_video_ctrls_and_menus() */ int main(int argc, char** argv)
{
int fd;
struct v4l2_fmtdesc fmt;
struct v4l2_capability cap;
struct v4l2_format stream_fmt;
struct v4l2_input input;
struct v4l2_control ctrl;
struct v4l2_streamparm stream;
int err;
int ret;
int i; if (argc < ) {
// printusage(argv[0]);
printf("please input path\n");
return -;
}
fd = open_camer_device(argv[]); for(i = ; i < CHECKNUM; i++)
{
memset(&fmt,,sizeof(fmt));
fmt.index = ;
fmt.type = enum_fmt[i].type;
//printf("enum_fmt:%s\n", enum_fmt[i].name);
while((ret = ioctl(fd,VIDIOC_ENUM_FMT,&fmt)) == )
{
fmt.index ++ ;
printf("%s:{pixelformat = %c%c%c%c},description = '%s'\n",
enum_fmt[i].name,
fmt.pixelformat & 0xff,(fmt.pixelformat >> )&0xff,
(fmt.pixelformat >> ) & 0xff,(fmt.pixelformat >> )&0xff,
fmt.description);
}
}
printf("\n\n");
enum_video_ctrls_and_menus(fd);
//查询视频设备支持的功能
ret = ioctl(fd,VIDIOC_QUERYCAP,&cap);
if(ret < ){
perror("FAIL to ioctl VIDIOC_QUERYCAP");
//exit(EXIT_FAILURE);
}
//printf("capabilities:%08x\n", cap.capabilities);
printf("\ncheck the support capabilities\n");
for(i = ; i < CHECKNUM; i++)
{
if(cap.capabilities & enum_fmt[i].type)
printf("%s\n",enum_fmt[i].name);
}
printf("\n");
if(!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
printf("The Current device is not a video capture device\n");
//exit(EXIT_FAILURE); }
else
printf("The Current device is a video capture device\n");
if(!(cap.capabilities & V4L2_CAP_STREAMING))
{
printf("The Current device does not support streaming i/o\n");
//exit(EXIT_FAILURE);
}
else
printf("The Current device support streaming i/o\n"); return ;
}
linux_cam_test文件的更多相关文章
- Mapreduce的文件和hbase共同输入
Mapreduce的文件和hbase共同输入 package duogemap; import java.io.IOException; import org.apache.hadoop.co ...
- mapreduce多文件输出的两方法
mapreduce多文件输出的两方法 package duogemap; import java.io.IOException; import org.apache.hadoop.conf ...
- 01.SQLServer性能优化之----强大的文件组----分盘存储
汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 文章内容皆自己的理解,如有不足之处欢迎指正~谢谢 前天有学弟问逆天:“逆天,有没有一种方 ...
- SQL Server 大数据搬迁之文件组备份还原实战
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 解决方案(Solution) 搬迁步骤(Procedure) 搬迁脚本(SQL Codes) ...
- SQLSERVER将一个文件组的数据移动到另一个文件组
SQLSERVER将一个文件组的数据移动到另一个文件组 有经验的大侠可以直接忽视这篇文章~ 这个问题有经验的人都知道怎麽做,因为我们公司的数据量不大没有这个需求,也不知道怎麽做实验 今天求助了QQ群里 ...
- SQL Server中的高可用性(2)----文件与文件组
在谈到SQL Server的高可用性之前,我们首先要谈一谈单实例的高可用性.在单实例的高可用性中,不可忽略的就是文件和文件组的高可用性.SQL Server允许在某些文件损坏或离线的情况下,允 ...
- C# ini文件操作【源码下载】
介绍C#如何对ini文件进行读写操作,C#可以通过调用[kernel32.dll]文件中的 WritePrivateProfileString()和GetPrivateProfileString()函 ...
- 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用
有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...
- 【原】Android热更新开源项目Tinker源码解析系列之二:资源文件热更新
上一篇文章介绍了Dex文件的热更新流程,本文将会分析Tinker中对资源文件的热更新流程. 同Dex,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...
随机推荐
- FSCalendar使用和注意事项
相信大家项目中或多或少都有日历这一块的内容吧,公司作为教育行业的软件公司,当然也是一定有的. 最近被日历这一块的内容弄得很头疼啊,改来改去的,不过还是学到了很多东西,至少FSCalendar的使用基本 ...
- 重启sshd服务
查看状态: systemctl status sshd.service 启动服务: systemctl start sshd.service 重启服务: systemctl restart sshd. ...
- document.documentElement 和 document.body
MDN : The Document.documentElement read-only property returns the Element that is the root element o ...
- 安装 Git 并连接 Github
下载安装 Git, 下载地址:https://git-scm.com/download/win . 在命令行中输入 git 测试 Git 是否安装成功. 在桌面鼠标右击打开 Git Bash Here ...
- PJzhang:python基础入门的7个疗程-four
猫宁!!! 参考链接:易灵微课-21天轻松掌握零基础python入门必修课-售价29元人民币 https://www.liaoxuefeng.com/wiki/1016959663602400 第十天 ...
- MyBatis 简单入门
添加maven 依赖 <dependencies> <dependency> <groupId>org.mybatis</groupId> <ar ...
- mysql常用排查命令
1.查看服务器使用状态 mysqladmin -uroot -p -S /tmp/mysql.sock -r -i 1 ext |\ awk -F"|" \ "BEGIN ...
- kmp算法分析和C++实现
知乎高赞分析 作者:逍遥行 链接:https://www.zhihu.com/question/21923021/answer/37475572来源:知乎著作权归作者所有.商业转载请联系作者获得授权, ...
- 小菜鸟之Oracle数据库之事务
Oracle数据库之事务 1. 什么是事务 在数据库中事务是工作的逻辑单元,一个事务是由一个或多个完成一组的相关行为的SQL语句组成,通过事务机制确保这一组SQL语句所作的操作要么都成功执行,完成整个 ...
- python简单验证码识别
在学习python通过接口自动登录网站时,用户名密码.cookies.headers都好解决但是在碰到验证码这个时就有点棘手了:于是通过网上看贴,看官网完成了对简单验证码的识别,如果是复杂的请看大神的 ...