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,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...
 
随机推荐
- bazel编译im2txt的问题
			
问题: 原本可以正常运行的程序,出现找不到tensorflow的问题.打印出来sys.version和sys.path,发现python版本并不是conda环境的版本 (tensorflow) yua ...
 - Python爬虫学习==>第十章:使用Requests+正则表达式爬取猫眼电影
			
学习目的: 通过一个一个简单的爬虫应用,初窥门径. 正式步骤 Step1:流程框架 抓取单页内容:利用requests请求目标站点,得到单个页面的html代码,返回结果: 正则表达式分析:根据html ...
 - Mybatis是什么?mybatis中的对一和对多关系怎么配置
			
Mybatis是什么? 1.mybatis出来之前,由java的jdbc连接数据库,mybatis出来之后,将jdbc进行封装,实现更有效的连接: 2.mybatis的对象SqlSession,s ...
 - springMVC异常处理总结
			
a.ExceptionHandlerExceptionResolver 1.@ExceptionHandler --- 统一处理一个controller中(@ExceptionHandler所在con ...
 - 【Linux开发】linux设备驱动归纳总结(三):2.字符型设备的操作open、close、read、write
			
linux设备驱动归纳总结(三):2.字符型设备的操作open.close.read.write 一.文件操作结构体file_operations 继续上次没讲完的问题,文件操作结构体到底是什么东西, ...
 - Prometheus 和 Alertmanager实战配置
			
Prometheus时序数据库 一.Prometheus 1.Prometheus安装 1)源码安装 prometheus安装包最新版本下载地址:https://prometheus.io/downl ...
 - java 实现读取某个目录下指定类型的文件
			
我这里是读取txt类型的文件,在指定的目录下有不同类型的文件 实现代码,读取txt类型的文件并打印出该文件的绝对路径 package com.SBgong.test; import java.io.F ...
 - ETL初探
			
初识ETL 概念 ETL即Extract-Transform-Load.目的是将分散.凌乱.异质的数据整合在一起,为决策提供分析数据,是BI项目(Business Intellifence)项目中重要 ...
 - 如何實現输入字符串This is an Apple on eBay 输出       Siht si na Elppa no yAbe
			
<?php $str = "This is an Apple on eBay"; //定义字符串 $len = strlen($str); //字符串长度 $sup = [] ...
 - Git 实习一个月恍然大悟合集
			
从开始实习到现在大概有一个月了,这个月时间接触了很多新东西,其中就包括了git版本控制.分支管理等等.我在这段时间里,深深地感受到了git对公司项目代码管理和控制.团队合作带来的益处和其重要性.其实在 ...