目
录
Chapter 1. 通用 API(Common API Elements) ............................................................................................. 1
1.1. 打开和关闭设备(Opening and Closing Devices) ....................................................................... 1
1.1.1. 设备命名(Device Naming) .................................................................................................... 1
1.1.2. 相关设备(Related Devices) .................................................................................................. 2
1.1.3. 并发打开(Multiple Opens) ................................................................................................... 3
1.1.4. 共享数据流(Shared Data Streams) ...................................................................................... 3
1.1.5. 函数(Functions) .................................................................................................................... 3
1.2. 功能查询(Querying Capabilities) .................................................................................................... 3
1.3. 应用程序的优先级(Application Priority) ........................................................................................ 4
1.4. 视频输入/输出(Video Inputs and Outputs) .................................................................................... 4
1.5. 音频输入/输出(Audio Inputs and Outputs) .................................................................................... 5
1.6. 高频头和调制器(Tuners and Modulators) ................................................................................ 8
1.6.1. 高频头(Tuners) ..................................................................................................................... 8
1.6.2. 调制器(Modulators) ........................................................................................................ 9
1.6.3. 无线频率(Radio Frequency) ................................................................................................. 9
1.6.4. 卫星接收器(Satellite Receivers) ......................................................................................... 10
1.7. 视频标准(Video Standards) .......................................................................................................... 10
1.8. 用户控制(User Controls) ............................................................................................................... 14
1.9. 扩展控制(Extended Controls) ....................................................................................................... 20
1.9.1. 介绍(Introduction) .............................................................................................................. 20
1.9.2. 扩展类控制 API(The Extended Control API) ................................................................... 21
1.9.3. 扩展 control 值的枚举(Enumeration Extended Controls) ................................................. 21
1.9.4. 创建 control 面板(Creating Control Panels) ....................................................................... 22
1.9.5. MPEG Control Reference .................................................................................................... 22
1.9.6. 摄像头 control 参考(Camera Control Reference) .............................................................. 27
1.10. 数据格式(Data Formats) ............................................................................................................. 27
1.10.1. 协商数据格式(Data Format Negotiation) ........................................................................ 27
I
1.10.2. 枚举图片格式(Image Format Enumeration) ................................................................... 28
1.11. 图片修剪,插入和缩放(Image Cropping,Insertion and Scalling) ........................................... 28
1.11.1. 修剪结构(Cropping Structures) ........................................................................................ 29
1.11.2. 缩放调整(Scaling Adjustments) ....................................................................................... 30
1.11.3. 样例程序(Examples) ......................................................................................................... 30
1.12. Streaming 参数(Streaming Parameters) ...................................................................................... 34
Notes ........................................................................................................................................................ 34
Chapter 2. 图像格式(Image Formats) ............................................................................................................ 35
2.1. 标准图片格式(Standard Image Formats) ..................................................................................... 36
2.2. 色彩空间(Colorspaces) .................................................................................................................. 37
2.3. 索引格式(Indexed Format) ............................................................................................................ 40
2.4. RGB 格式(RGB Formats) ................................................................................................................ 40
2.5. YUV 格式(YUV Formats) ................................................................................................................ 43
2.6. 压缩格式(Compressed Formats) ................................................................................................... 44
2.7. 保留的格式标识符(Reserved Format Identifiers) ........................................................................ 45
Chapter 3. 输入/输出(Input/Output) ............................................................................................................. 46
3.1. 读和写(Read/Write) ...................................................................................................................... 46
3.2. 流式 I/O(内存映射缓冲区)(Streaming I/O(Memory Mapping)) .................................................. 47
3.3. 流 I/O(用户空间缓冲区(用户指针))(Streaming I/O(User Pointers)) ........................................... 50
3.4. 异步 I/O(Asynchronous I/O) .......................................................................................................... 52
3.5. 缓冲(Buffers) .................................................................................................................................. 52
3.5.1. 时码(Timecodes) ................................................................................................................ 55
3.6. field 次序(Field Order) ................................................................................................................... 55
Notes ........................................................................................................................................................ 56
Chapter 4. 接口(Interface) .............................................................................................................................. 57
4.1. 视频采集接口(Video Capture Interface) ........................................................................................ 57
4.1.1. 查询设备属性(Querying Capabilities) ................................................................................. 57
4.1.2. 附加功能(Supplemental Functions) ..................................................................................... 57
4.1.3. 图片格式协商(Image Format Negotiation) ......................................................................... 58
II
4.1.4. 读取图片(Reading Images) ................................................................................................... 58
4.2. Video Overlay Interface .................................................................................................................... 58
4.2.1. 查询设备属性(Querying Capabilities) ............................................................................... 59
4.2.2. 附加功能(Supplemental Functions) ..................................................................................... 59
4.2.3. 设置(Setup) ........................................................................................................................... 59
4.2.4.Overlay 窗口(Overlay Window) ..................................................................................... 59
4.2.5. 使能 overlay(Enabling Overlay)....................................................................................... 60
4.3. 视频输出接口(Video Output Interface) ......................................................................................... 61
4.3.1. 设备功能查询(Querying Capabilities) ................................................................................. 61
4.3.2. 附加功能(Supplemental Functions) ............................................................................... 61
4.3.3. 图片格式协商(Images Format Negotiation) .................................................................. 61
4.3.4. 写图片(Writing Image) .................................................................................................... 61
4.4. 视频输出 overlay 接口(Video Output Overlay Interface) ......................................................... 62
4.4.1. 设备功能查询(Querying Capabilities) ............................................................................ 62
4.4.2. 帧缓冲(Framebuffer) ...................................................................................................... 62
4.4.3. overlay 窗口和缩放 ............................................................................................................... 63
4.4.4. 使能 overlay(Enabling Overlay)....................................................................................... 63
4.5. 编码接口(Codec Interface) ........................................................................................................ 64
4.6. 特效设备接口(Effect Devices Interface) .................................................................................... 64
4.7. 原始 VBI 数据接口(Raw VBI Data Interface) ............................................................................. 64
4.8. 分离 VBI 数据接口(Sliced VBI Data Interface) .......................................................................... 64
4.9. 图文电视接口(Teltext Interface) ............................................................................................... 64
4.10. 无线电接口(Radio Interface) ................................................................................................... 65
4.11. 无线数据广播系统(Radio Data Interface) .............................................................................. 65
Notes ........................................................................................................................................................ 65
Chapter 5. 驱动编写 ....................................................................................................................................... 66
III
Chapter 1. 通用 API(Common API Elements)
编程以支持一个 V4l2 的设备包含以下步骤:
.打开设备
.修改设备的属性,选择音频和视频输入,视频的标准(编码格式?),图片的亮度等
.协商数据格式
.协商输入/输出的方法
.输入/输出循环
.关闭设备
1.1.
打开和关闭设备(
Opening and Closing Devices
)
1.1.1. 设备命名(Device Naming)
V4L2 以模块的方式在内核中实现,可以被管理员手动的加载或者是当设备第一次打开时被加载。
驱动模块被挂在内核模块"videodev"下。在这份文档中,提供了辅助函数和一个通用的应用程序接口
规范。
每个驱动加载时都会用主设备号 81 和次设备号 0-255 来注册一个或多个设备节点。该如何分配
次设备号给这些个 V4L2 设备,完全取决于系统管理员,这主要是为了解决设备间的冲突(为了区分
不同的设备)
1
。当选定次设备号后,模块将会以"_nr"为后缀来命名特殊的设备文件名。举个例子来
说,像"video_nr"就是代表视频采集设备的(在内核中表示为)/dev/video。数字则是和设备类型相关
并基于次设备号的一个偏移
2
。
当驱动支持同一型号的多个设备时,这时就可以赋予多个次设备号了,并以逗号隔开:
> insmod mydriver.o video_nr=0,1 radio_nr=0,1
在/etc/modules.conf 文件中,可能显示如下:
alias char-major-81-0 mydriver
alias char-major-81-1 mydriver
alias char-major-81-64 mydriver
Options mydriver video_nr=0,1 radio_nr=0,1
当应用程序试图打开主设备号 81,次设备号 0,1,64 的设备时会加载驱动"mydriver"
注册前两个视频采集设备时是从主设备号 0 开始的,接着是 1...一直到 63,而音频设备则是从
次设备号 64 开始的。
如果未显式给定次设备号,那么模块将提供一个默认值。第四章将阐述不同型号设备的起始次设
备号。显然次设备号必须是独一无二的。假如所请求的设备号正在使用时,很明显起冲突的设备将不
会被注册。
按照惯例,系统管理员会根据主、次设备号在/dev 目录下创建不同功用的特殊设备文件。文件名
1