基于Video for Linux内核的USB摄像头视频信号采集实现.doc
基于Video for Linux内核的USB摄像头视频信号采集实现
摘要:Video for Linux是Linux中关于视频设备的内核驱动,本文介绍了在Video for Linux内核基础上,利用其提供的接口函数、数据结构完成对USB摄像头驱动进行设计,并实现在Linux下对视频信号的采集。
Abstract: Video for Linux is the Kernel driver about video device in Linux. This article uses its interface functions, data structure to complete the design of USB camera driver based on the kernel of Video for Linux, and achieve Video signal acquisition under the Linux.
关键词:Video for Linux;USB摄像头;视频采集
Key words: Video for Linux;USB camera;video acquisition
中图分类号:TP316.2 文献标识码:A文章编号:1006-4311(2011)05-0152-02
0引言
Video for Linux(简称V4L)是Linux中关于视频设备的内核驱动,它为针对视频设备的应用程序编程提供一系列接口函数,包括现今市场上流行的TV卡、视频捕捉卡和USB摄像头等。同时也提供无线电通信和文字电视广播解码和垂直消隐的数据接口。在Linux下,USB摄像头视频采集的正常使用依赖于对Video for Linux内核标准的支持,对于USB摄像头,提供其驱动程序中需要的基本I/O操作接口函数open、read、write、close的实现。并定义了在设备驱动程序中所使用的一些通用的数据结构及内核接口符号。
1Video for Linux接口函数和数据结构
在内核中的drivers/media/video/videodev.c文件,是内核开发者提供的一个Video for Linux设备驱动程序模块,它向外提供了一些内核接口符号和一些通用的数据结构,以便供驱动程序开发者在该模块的基础上堆叠出自己的特定设备的驱动程序。Video for Linux设备在内核中的注册int video_device_register(struct video_device*vfd,int type,int nr)各变量含义如下:
vfd:想要注册的video_device结构;
type:注册的设备的类型,共有以下四种:
VFL_TYPE―GRABBER_A frame grabber
VFL_TYPE_VTX-A teletext device
VFL_JYPE_VBI-Vertical blank data(undecoded)
VFL_TYPE_RADIO-A radio card
这几个宏在vidcodev.h中都有相关定义;
Video for Linux支持的主要结构体为video_device,其结构定义在videodev.h文件中,定义如下:
struct video_device
{
struct module*owner;//指明该模块的拥有者,一般为THIS_MODULE
char name[32]; //设备名称
int type; //设备类型
int hardware;
int(*open)(struct video_device*,int mode);//设备的打开函数
void(*close)(struct video_device*);//设备的关闭函数
long(*read)(struct video_device*,char*,unsigned long,int noblock); //设备的读函数
long(*write)(struct video_device*,const char*,unsigned long,int noblock);//设备的写函数
unsigned int(*poll)(struct video_device*,struct file*,poll_table*);
int(*ioctl)(struct video_device*,unsigned int,void*); //设备的I/O控制函数
int(*mmap)(struct video_device*,cons