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,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...
随机推荐
- EUREKA 删除 or 强制下线/上线 实例
开发环境,EUREKA 注册中心 某服务被注册了多个实例,feign 调用时 服务请求到其他实例上,请求收不到,使用一下命令删除 或者强制下线实例: 1 .DELETE 删除注册实例,但是如果被删除 ...
- Python浮点型数据小数点的取舍
python默认的是17位小数的精度 1.round()内置方法 π=3.1415926535 new_num=round(π,2) #四舍五入保留两位小数 print(new_num) ...
- Kali Linux 2019.2使用华为源
一.将默认的配置源注释掉 root@zinuo:~# vim /etc/apt/sources.list 注释: #deb http://http.kali.org/kali kali-rolling ...
- C++学习笔记-C++对C语言的函数拓展
内联函数 内联函数是指用inline关键字修饰的函数.在类内定义的函数被默认成内联函数.内联函数从源代码层看,有函数的结构,而在编译后,却不具备函数的性质 inline关键字只是给编译器一个建议,编译 ...
- 使用PowerShell 自动创建DFS复制组
运行环境:Windows Server 2012 R2 DFS 复制概述 DFS复制组 PowerShell脚本命令 需要注意的是DFS依赖域,若此服务器未存在于域控上,或未存在域内,则此脚本会报错 ...
- 学习shell的第三天
编程原理:1.编程介绍 早期编程: 驱动 硬件默认是不能使用的: 不同的厂家硬件设备之间需要进行指令沟通,我们需要驱动程序来进行“翻译”: 更趋近与硬件开发的工程师,要学习“汇编语言”:而“汇 ...
- zip 命令
NAME zip - package and compress (archive) files SYNOPSIS zip [-aABcdDeEfFghjklLmoqrRSTuvVwXy ...
- 【Spring 基础】通过注解注入Bean
原课程:通过注解注入Bean 注入bean知识点思维导图 Spring 4.x推荐使用基于构造器的方式进行bean注入7.4.1 Dependency Injection spring为什么推荐使用构 ...
- Python操作 RabbitMQ、Redis、Memcache
Python操作 RabbitMQ.Redis.Memcache Memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数 ...
- [转帖]U盘安装centos 的方法
通过U盘或CD/DVD装centos7,出现“dracut-initqueue timeout..."解决办法 1.在用CD/DVD挂载centos7镜像安装系统时,出现“dracut- ...