linux内核文档翻译之——V4L2-framework.txt V4L2 API Specification
http://blog.csdn.net/jmq_0000/article/details/7530575
V4L2驱动框架概述
=====================================这个文本文件讲述V4L2的框架所提供的各种结构和它们之间的关系.介绍
------------
由于硬件的复杂性v412驱动往往是非常复杂的: 大多数设备有多个IC,在
/dev目录下有多个设备节点, 并也创建non-V4L2的设备,如DVB,ALSA,FB,
I2C和input(IR)设备。特别是v412驱动设置配套的IC做音频/视频多路复用/编码/解码,使得它更
比大多数复杂的事实。通常这些芯片连接到主桥驱动器通过一个或多个I2C
总线,但也可以使用其他总线。这种设备被称为“子设备”。很长一段时间有限制的video_device结构框架创建v4l设备节点和video_buf
的的视频缓冲区处理(请注意,本文档不讨论video_buf框架)。这意味着,所有驱动程序必须做的设备实例的设置和连接子设备本身。
这部分是相当复杂,做应该做的事,很多驱动程序不这样做是正确的。
由于缺乏一个框架也有很多共同的代码不可重构。 因此,这个框架的基本构建块,所有的驱动程序需要与此相同的框架应更容 易进入所有驱动程序共享的实用功能重构的通用代码。驱动程序的结构 ---------------------所有的驱动程序有以下结构:1) 每个设备包含设备状态的实例结构。2) 子设备的初始化和命令方式(如果有).3) 创建V4L2的设备节点 (/dev/videoX, /dev/vbiX and /dev/radioX)和跟踪设备节点的具体数据。4)文件句柄特定的结构,包含每个文件句柄数据;5) 视频缓冲处理。
这是一个粗略的示意图,这一切是如何涉及的:
device instances(设备实例) | +-sub-device instances(子设备实例) | \-V4L2 device nodes(V4L2的设备节点) | \-filehandle instances(文件句柄实例)框架结构 --------------------------框架类似于驱动程序的结构:它是一个 v4l2_device结构的设备实例的数据, v4l2_subdev结构子设备实例的video_device结构存储V4L2的设备节点的数据, 并在将来v4l2_fh结构将保持跟踪的文件句柄实例(这是尚未实现)。 也可以选择集成框架的V4L2媒体框架。如果设置一个驱动程序的结构 v4l2_device mdev,sub-devices 和 video节点会自动出现在媒体框架作为实体。 struct v4l2_device ------------------每个设备实例结构体v4l2_device(V4L2-device.h中)的代表。只是很简单的 设备可以分配这个结构,但大多数的时候你会把这个结构体嵌入到一个更大的结构体中。
你必须注册设备的实例:
v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev);注册将初始化 v4l2_device 结构体. 如果 dev->driver_data字段是空, 它将连接到 v4l2_dev.要与媒体设备框架集成的驱动程序需要设置DEV-> driver_data手动指向驱动程序特定的设备结构
嵌入结构体v4l2_device实例。这是通过一个dev_set_drvdata()调用之前注册V4L2的设备实例。
他们必须还设置结构体v4l2_device MDEV领域指向一个正确初始化和注册media_device实例。
如果v4l2_dev->name是空,那么这将被设置为从dev取得一个值(驱动程序名称后的bus_id要准确)。如果你在调用v4l2_device_register之前设置它,那么它没有改变。如果dev是NULL,那么你‘必须’设置v4l2_dev>name在调用v4l2_device_register前。
你可以使用v4l2_device_set_name()设置名称根据驱动程序的名字和
driver-global atomic_t实例。这将产生的名字一样,ivtv0,ivtv1,等。
如果名字最后一个数字,然后将它插入一个破折号:cx18-0,cx18-1,等
这个函数返回的实例数量。第一个参数‘dev’通常是一个pci_dev的struct device的指针,
但它是ISA设备或一个设备创建多个PCI设备时这是罕见的DEV为NULL,因此makingit不可能联想到一个特定的父母v4l2_dev。
您也可以提供一个notify()回调子设备,可以通过调用通知你的事件。
取决于你是否需要设置子设备。一个子设备支持的任何通知必须在头文件中定义
include/media/<subdevice>.h. 注销:v4l2_device_unregister(struct v4l2_device *v4l2_dev);如果dev-> driver_data字段指向v4l2_dev,它将被重置为NULL。 注销也将自动注销从设备所有子设备。如果你有一个可热插拔设备(如USB设备),然后发生断开连接的时候父设备将变为无效。 由于v4l2_device有指向父设备的指针,它被清除,以及标记父设备消失。 要做到这一点调用:v4l2_device_disconnect(struct v4l2_device *v4l2_dev);这并*不*注销subdevs,所以你仍然需要调用该的v4l2_device_unregister()函数。 如果你的驱动是不能热插拔,则有无需调用v4l2_device_disconnect()。有时你需要遍历一个特定的驱动程序注册的所有设备。
这是通常情况下如果多个设备驱动程序使用相同的硬件。 例如ivtvfb驱动程序是一个使用IVTV硬件framebuffer驱动。 同样是真实的,例如ALSA驱动程序。您可以遍历所有注册的设备如下: static int callback(struct device *dev, void *p) { struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); /* test if this device was inited */ if (v4l2_dev == NULL) return 0; ... return 0; } int iterate(void *p) { struct device_driver *drv; int err; /* Find driver 'ivtv' on the PCI bus. pci_bus_type is a global. For USB busses use usb_bus_type. */ drv = driver_find("ivtv", &pci_bus_type); /* iterate over all ivtv device instances */ err = driver_for_each_device(drv, NULL, p, callback); put_driver(drv); return err; } 有时你需要保持一个设备实例运行计数器。这是常用的映射设备实例模块选项数组索引。 建议的方法如下: static atomic_t drv_instance = ATOMIC_INIT(0); static int __devinit drv_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id) { ... state->instance = atomic_inc_return(&drv_instance) - 1; } 如果你有多个设备节点然后它可以是很难知道它是安全注销v4l2_device时候。
v4l2_device引用计数的支持就是对于这样做的目的。当video_register_device
时被称之为增加引用计数,有设备节点被释放时减少引用计数。
当引用计数达到零,则v4l2_device回调release()。你可以做最后的清理。
如果其他设备节点(例如ALSA)的创建,然后你可以增加和减少以及手动调用引用计数: void v4l2_device_get(struct v4l2_device *v4l2_dev); or: int v4l2_device_put(struct v4l2_device *v4l2_dev); struct v4l2_subdev ------------------ 许多驱动程序需要与子设备进行通信。这些设备可以完成所有这类任务 但他们最常用的处理音频 和/或 视频混流,编码或解码。对于常见子设备摄像头传感器和摄像头控制器。 通常情况下,这些I2C器件,但不一定。以这些子设备的驱动程序提供一致的接口v4l2_subdev结构 (V4L2 subdev.h)创建。 每个子设备驱动程序必须有一个v4l2_subdev结构。这个结构可以独立简单的设备或者
如果需要存储更多的状态信息它可能被嵌入在一个更大的结构。一般有一个低级别
设备结构(如i2c_client),其中包含设备的数据为内核设置。
它建议在v4l2_subdev使用v4l2_set_subdevdata()的私人数据存储的指针。 这使得很容易地从一个v4l2_subdev实际低级别的总线特定的器件数据。 你还需要很长的路要走从低级结构v4l2_subdev。对于常见的i2c_client结构的i2c_set_clientdata()调用用来存储v4l2_subdev指针, 为其他总线您可能必须使用其他方法。桥接可能还需要存储每subdev私人数据如桥特定每个-subdev私人数据指针。 v4l2_subdev结构提供与v4l2_get_subdev_hostdata()和v4l2_set_subdev_hostdata()可以访问目的主机私人数据。 从桥式驱动器角度你加载的子设备模块和某种取得的v4l2_subdev指针。 对于I2C器件这是很容易: 你调用i2c_get_clientdata()。对于其他总线类似的东西需要做。Helper函数做你最棘手的工作, 这一个I2C总线上存在的子设备。每个v4l2_subdev包含函数指针的子设备驱动程序可以实现(或保留NULL,如果它不适用)。 由于子设备可以做很多不同的东西,你不想结束一个巨大的OPS结构其中只有少数的OPS通常执行,函数指针进行排序按类别, 每个类别都有其自己的OPS结构。顶层OPS结构包含的类别OPS结构,这可能是NULL如果在subdev驱动程序不支持任何从该类别指针。 它看起来像这样: struct v4l2_subdev_core_ops { int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip); int (*log_status)(struct v4l2_subdev *sd); int (*init)(struct v4l2_subdev *sd, u32 val); ... }; struct v4l2_subdev_tuner_ops { ... }; struct v4l2_subdev_audio_ops { ... }; struct v4l2_subdev_video_ops { ... }; struct v4l2_subdev_ops { const struct v4l2_subdev_core_ops *core; const struct v4l2_subdev_tuner_ops *tuner; const struct v4l2_subdev_audio_ops *audio; const struct v4l2_subdev_video_ops *video; };
参考实体将自动获得/释放时,subdev设备节点(如果有的话)打开/关闭。
不要忘了清理的media实体子设备被破坏之前: media_entity_cleanup(&sd->entity);设备(桥)驱动程序需要注册用v4l2_subdevv4l2_device: int err = v4l2_device_register_subdev(v4l2_dev, sd);这可能会失败,如果subdev模块消失之前,它可以注册。 之后,这个功能调用成功的subdev-> dev字段指向了v4l2_device。如果的v4l2_device父设备具有非空MDEV字段, 分设备实体将被自动注册用media设备。你可以注销一个子设备使用:v4l2_device_unregister_subdev(sd);事后subdev模块可以卸载和 sd->dev == NULL.你可以直接调用操作函数:err = sd->ops->core->g_chip_ident(sd, &chip);
但 那么只有那些其组ID匹配值将被调用。前桥驱动注册一个subdev它可以设置SD-> grp_id 任何值是想要(这是默认为0)。这个值是由桥式驱动器和拥有子设备驱动程序将不会修改或使用它。 这组ID给桥驱动器控制如何调用回调。例如,可能有多个音频芯片板,每一个有改变音量。但通常只 有一个实际上将被用来当用户想改变音量。 你可以设置组ID,subdev例如AUDIO_CONTROLLER和指定组ID值时调用v4l2_device_call_all()。 以确保它只会去的subdev需要。如果子设备需要通知其事件v4l2_device父母,那么它可以调用 v4l2_subdev_notify(SD,notification,ARG)。 这个宏检查是否有一个notify()的回调定义,如果没有返回-ENODEV。否则结果的通知()调用返回。 使用v4l2_subdev优势是它是一个通用结构,不包含任何对底层硬件知识。因此驱动程序可能包含几个subdevs使用I2C总线, 但也通过GPIO引脚控制subdev。这种区别是设置设备时只有关,但一旦subdev注册是是完全透明的。 V4L2的子设备用户空间的API ----------------------------- 旁边公开通过v4l2_subdev_ops结构内核API,V4L2的子设备也可以直接控制用户空间应用。可以直接访问 子设备在/ dev中创建名为V4L-subdevX设备节点。 如果一个子设备支持直接用户空间的配置它必须设定以前注册的V4L2_SUBDEV_FL_HAS_DEVNODE标志。 子设备登记后,v4l2_device司机可以由调用v4l2_device_register_subdev_nodes()与 V4L2_SUBDEV_FL_HAS_DEVNODE标记所有注册子设备创建设备节点。子设备未注册时将被自动删除这些 设备节点。设备节点处理的V4L2的API一个子集。 VIDIOC_QUERYCTRL VIDIOC_QUERYMENU VIDIOC_G_CTRL VIDIOC_S_CTRL VIDIOC_G_EXT_CTRLS VIDIOC_S_EXT_CTRLS VIDIOC_TRY_EXT_CTRLS 控制ioctls函数调用在V4L2的定义是相同的。他们的行为是相同的,唯一的例外, 他们只处理子设备执行控制。这些控制可以根据驱动程序,也可以通过一个(或几个)V4L2 的设备节点访问。 VIDIOC_DQEVENT VIDIOC_SUBSCRIBE_EVENT VIDIOC_UNSUBSCRIBE_EVENT 事件ioctls函数调用在V4L2的定义是相同。他们的行为是相同的,唯一的例外他们只分设备产生事件处理。 根据驱动程序,这些事件也可以报一个(或几个)V4L2的设备节点。 子设备驱动程序要使用的事件需要设置的V4L2_SUBDEV_USES_EVENTS v4l2_subdev::flags 和初始化之前注册的子设备v4l2_subdev:: nevents事件队列深度。注册事件后可以像往常一样 排队的v4l2_subdev:: devnode设备节点。 要正确地支持事件,poll()的文件操作实施。Private ioctls没有在上述列表所有ioctls函数调用会直接传递 到子设备驱动程序通过core::ioctl操作。 I2C sub-device drivers ---------------------- 由于这些驱动程序是很常见的,特殊的辅助功能是可以缓解使用这些驱动程序(V4L2-common.h)。 对加入v4l2_subdev支持I2C驱动的推荐的方法是嵌入到每个I2C设备实例创建状态结构v4l2_subdev结构。 很简单的设备,没有状态结构,在这种情况下,你可以直接创建一个v4l2_subdev。 一个典型的状态结构看起来像这样(where 'chipname' is replaced bythe name of the chip):
struct chipname_state {struct v4l2_subdev sd;... /* additional state fields */
};
此功能将填补所有领域v4l2_subdev和确保在v4l2_subdev和i2c_client都指向一个。 您还应该添加一个辅助内联函数从v4l2_subdev指针的去到chipname_state结构: struct chipname_state { struct v4l2_subdev sd; ... /* additional state fields */ }; 如下初始化v4l2_subdev结构: v4l2_i2c_subdev_init(&state->sd, client, subdev_ops); 此功能将填补所有领域v4l2_subdev和保证的v4l2_subdev和i2c_client都指向一个。 您还应该添加一个辅助inline函数从v4l2_subdev指针的去到chipname_state结构: static inline struct chipname_state *to_state(struct v4l2_subdev *sd) { return container_of(sd, struct chipname_state, sd); } 使用这个从v4l2_subdev结构i2c_client结构: struct i2c_client *client = v4l2_get_subdevdata(sd); 这从一个i2c_client到v4l2_subdev结构: struct v4l2_subdev *sd = i2c_get_clientdata(client); 确保调用v4l2_device_unregister_subdev(SD),remove()回调时被调用。 这将注销桥式驱动器的子设备。调用此子设备,即使是没有注册的,它是安全的。 你需要这样做,因为当桥式驱动器的销毁I2C适配器的remove()回调呼吁该适配器 上的I2C设备。之后相应v4l2_subdev结构是无效的,所以他们必须首先要注销。 v4l2_device_unregister_subdev(SD)的remove()调用的回调保证,这是一直在做正确。 桥式驱动器也有一些辅助功能,它可以使用: struct v4l2_subdev *sd = v4l2_i2c_new_subdev(v4l2_dev, adapter, "module_foo", "chipid", 0x36, NULL); 加载模块(如果没有需要加载的模块,可以为NULL)并调用i2c_adapter和 芯片/地址参数的i2c_new_device()。如果一切顺利,那么它注册这个v4l2_device 子设备。 您还可以使用最后一个参数的v4l2_i2c_new_subdev()传递一个可能的I2C地址的数组, 它应该探究。这些探头地址仅用于如果前面的参数是0。一个非零的说法意味着, 你知道确切的I2C地址,所以在这种情况下,没有探测将发生。 如果出错了,这两个函数返回NULL。 请注意,你传递 CHIPID给v4l2_i2c_new_subdev()通常是作为相同模块的名称。它允许你指定一个芯片的变型,例如 “SAA7114”或“SAA7115”。一般来说,虽然I2C驱动程序会自动检测这个。 使用CHIPID是需要看着在晚些时候更紧密的东西。它不同于之间的I2C驱动程序和这样可能会造成混淆。 看到支持该芯片的变种,你可以在I2C驱动程序代码为i2c_device_id表。这将列出所有的可能性。 有两个辅助函数: v4l2_i2c_new_subdev_cfg: this function adds new irq and platform_data arguments and has both 'addr' and 'probed_addrs' arguments: if addr is not 0 then that will be used (non-probing variant), otherwise the probed_addrs are probed. For example: this will probe for address 0x10: struct v4l2_subdev *sd = v4l2_i2c_new_subdev_cfg(v4l2_dev, adapter, "module_foo", "chipid", 0, NULL, 0, I2C_ADDRS(0x10)); v4l2_i2c_new_subdev_board uses an i2c_board_info struct which is passed to the i2c driver and replaces the irq, platform_data and addr arguments. If the subdev supports the s_config core ops, then that op is called with the irq and platform_data arguments after the subdev was setup. The older v4l2_i2c_new_(probed_)subdev functions will call s_config as well, but with irq set to 0 and platform_data set to NULL. struct video_device ------------------- 实际设备节点在/ dev目录使用的video_device结构(V4L2 dev.h)创建。 这个结构可以动态分配或嵌入在一个更大的结构。要动态分配使用: To allocate it dynamically use: struct video_device *vdev = video_device_alloc(); if (vdev == NULL) return -ENOMEM; vdev->release = video_device_release; 如果是嵌入到一个更大的结构,那么你必须设置的release()函数回调到自己的函数: struct video_device *vdev = &my_vdev->vdev; vdev->release = my_vdev_release; 释放回调必须设置时被称为最后一个用户的视频设备出口。的默认video_device_release() 回调只是调用kfree释放分配的内存。 你也应该设定这些字段: - v4l2_dev: 设置这个v4l2_device父设备。 - name: 设置为描述性和独特的东西。 - fops: 设置这个v4l2_file_operations结构。 - ioctl_ops: if you use the v4l2_ioctl_ops to simplify ioctl maintenance (highly recommended to use this and it might become compulsory in the future!), then set this to your v4l2_ioctl_ops struct. - lock: leave to NULL if you want to do all the locking in the driver. Otherwise you give it a pointer to a struct mutex_lock and before any of the v4l2_file_operations is called this lock will be taken by the core and released afterwards. - prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY. If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device. If you want to have a separate priority state per (group of) device node(s), then you can point it to your own struct v4l2_prio_state. - parent: you only set this if v4l2_device was registered with NULL as the parent device struct. This only happens in cases where one hardware device has multiple PCI devices that all share the same v4l2_device core. The cx88 driver is an example of this: one core v4l2_device struct, but it is used by both an raw video PCI device (cx8800) and a MPEG PCI device (cx8802). Since the v4l2_device cannot be associated with a particular PCI device it is setup without a parent device. But when the struct video_device is setup you do know which parent PCI device to use. - flags: optional. Set to V4L2_FL_USE_FH_PRIO if you want to let the framework handle the VIDIOC_G/S_PRIORITY ioctls. This requires that you use struct v4l2_fh. Eventually this flag will disappear once all drivers use the core priority handling. But for now it has to be set explicitly. 如果使用v4l2_ioctl_ops,那么你应该设置。unlocked_ioctl video_ioctl2在v4l2_file_operations结构。 不要使用。IOCTL!将在未来过时。 v4l2_file_operations结构的file_operations的一个子集。主要区别在于该inode参数被忽略,因为它从来没有使用过。
如果框架传媒的整合是必要的,你必须初始化media_entity结构嵌入式通过调用media_entity_init()的
video_device结构(entity字段):struct media_pad *pad = &my_vdev->pad;int err;err = media_entity_init(&vdev->entity, 1, pad, 0);垫阵列必须先前已初始化。有没有需要手动设置的结构media_entitytype和name字段。A reference to the entity will be automatically acquired/released when the
video device is opened/closed.
v4l2_file_operations 和 锁 -------------------------------- 你可以设置一个指针,在结构的video_device中mutex_lock。 通常这将是一个顶层互斥或互斥每个设备节点。如果你想更细致的锁那么你必须将其设置为NULL和你自己的锁定。 如果锁被指定那么所有的文件操作将被序列化该锁。如果您使用videobuf那么你 必须通过相同的锁的videobuf队列初始化函数:如果videobuf等待一帧到达, 然后它会暂时解除锁定和重新锁定它之后。如果您的驱动程序代码中的等待, 那么你应该做同样允许其他进程访问设备节点的第一道工序,而在等待着什么。 一个热插拔断开实施也应采取之前调用v4l2_device_disconnect锁。 video_device 注册 -------------------------
err = video_register_device(vdev, VFL_TYPE_GRABBER, -1); if (err) { video_device_release(vdev); /* or kfree(my_vdev); */ return err; }如果的v4l2_device其父节点设备具有非空MDEV字段,视频设备的实体将被自动注册用media设备。注册哪个设备依赖于类型参数。存在以下几种类型: VFL_TYPE_GRABBER: 对视频输入/输出设备video XVFL_TYPE_VBI: vbiX垂直空白数据(即关闭字幕,图文电视)VFL_TYPE_RADIO: radioX用于无线电调谐器 VFL_TYPE_VTX: vtxX图文电视设备(不建议使用,不使用) 最后一个参数给你一定数量的控制了设备使用设备节点(即在videoXX)。通常情况下你将通过-1让V4L2框架选择第一个释放号码。 但有时用户想选择一个特定的节点数量。这是常见的驱动程序允许用户通过驱动模块选项选择一个特定的设备节点数量。 这一数字然后被传递给这个函数和video_register_device将尝试选择该设备节点数量。 如果该号码已在使用中然后,下一个空闲的设备节点数量将被选中,它会发出警告的内核日志。
例如,视频捕获设备开始为0,视频输出设备在16开始。
所以,你可以使用的最后一个参数指定一个最低设备节点数量和V4L2框架将尽量挑选的第释放号码是相同或更高你通过什么。
如果失败,那么它只会选择第一个释放号码。由于在这种情况下,你不关心不能够选择指定的设备节点数量有关警告,
可以调用的函数video_register_device_no_warn()代替。每当创建一个设备节点的一些属性也为您创建。
如果你看在/ sys/class/video4linux你看到的设备。去到如video0,
你会看到“name”和“index”属性。 'name'属性的'name'字段的video_device结构。“index”属性是设备节点索引:
每个调用video_register_device()指数只上升1。寄存器总是第一个视频设备节点索引0开始。用户可以设置udev的规则,
利用索引属性使花哨的设备名称(如“mpegX MPEG视频捕捉设备节点)。之后该设备已成功注册,那么你可以使用这些字段:
- vfl_type: 设备类型传递到video_register_device。- minor: 分配装置的次设备号。- num:设备节点数目(i.e. the X in videoX). - index: 设备索引号。如果注册失败,那么你需要调用video_device_release()来释放分配的video_device结构, 或自己结构的video_device如果被嵌入。的VDEV>发布()回调将永远不会被调用, 如果注册失败,也不应该你曾经尝试注销的设备如果注册失败。 video_device 清除 -------------------- 当被删除,在卸载的驱动程序,或因为被断开USB设备,视频设备节点,那么你应该注销他们: video_unregister_device(vdev); This will remove the device nodes from sysfs (causing udev to remove them from /dev). After video_unregister_device() returns no new opens can be done. However, in the case of USB devices some application might still have one of these device nodes open. So after the unregister all file operations (except release, of course) will return an error as well. 当最后一个用户的视频设备节点退出,然后这个VDEV - >release() 回调被调用,你可以做最后的清理。 不要忘了清理媒体视频设备的实体相关的,如果它已经被初始化: media_entity_cleanup(&vdev->entity); This can be done from the release callback. video_device 辅助函数 ----------------------------- 有一些有用的辅助功能: - file/video_device private data You can set/get driver private data in the video_device struct using: void *video_get_drvdata(struct video_device *vdev); void video_set_drvdata(struct video_device *vdev, void *data); Note that you can safely call video_set_drvdata() before calling video_register_device(). And this function: struct video_device *video_devdata(struct file *file); returns the video_device belonging to the file struct. The video_drvdata function combines video_get_drvdata with video_devdata: void *video_drvdata(struct file *file); You can go from a video_device struct to the v4l2_device struct using: struct v4l2_device *v4l2_dev = vdev->v4l2_dev; - Device node name The video_device node kernel name can be retrieved using const char *video_device_node_name(struct video_device *vdev); userspace工具,如udev的名字被用来作为一个提示。应在可能的情况下使用, 而不是访问的video_device:: num和的video_device::minor字段的功能。 video buffer 辅助函数 ----------------------------- The v4l2 core API provides a set of standard methods (called "videobuf") for dealing with video buffers. Those methods allow a driver to implement read(), mmap() and overlay() in a consistent way. There are currently methods for using video buffers on devices that supports DMA with scatter/gather method (videobuf-dma-sg), DMA with linear access (videobuf-dma-contig), and vmalloced buffers, mostly used on USB drivers (videobuf-vmalloc). Please see Documentation/video4linux/videobuf for more information on how to use the videobuf layer. struct v4l2_fh -------------- 结构v4l2_fh提供了一种轻松地保持文件句柄是由V4L2的框架使用具体数据。 新的驱动程序必须使用struct v4l2_fh,因为它也可以用来实现优先处理 (VIDIOC_G/ S_PRIORITY)如果的video_device标志V4L2_FL_USE_FH_PRIO也。 (在V4L2的框架,而不是驱动器)v4l2_fh用户知道驱动程序是否使用通过测试 V4L2_FL_USES_V4L2_FH位的video_device-> flags中v4l2_fh作为其文件>private_data 的指针。每当v4l2_fh_init()被调用时设置此位。 struct v4l2_fh is allocated as a part of the driver's own file handle structure and file->private_data is set to it in the driver's open function by the driver. In many cases the struct v4l2_fh will be embedded in a larger structure. In that case you should call v4l2_fh_init+v4l2_fh_add in open() and v4l2_fh_del+v4l2_fh_exit in release(). Drivers can extract their own file handle structure by using the container_of macro. Example: struct my_fh { int blah; struct v4l2_fh fh; }; ... int my_open(struct file *file) { struct my_fh *my_fh; struct video_device *vfd; int ret; ... my_fh = kzalloc(sizeof(*my_fh), GFP_KERNEL); ... ret = v4l2_fh_init(&my_fh->fh, vfd); if (ret) { kfree(my_fh); return ret; } ... file->private_data = &my_fh->fh; v4l2_fh_add(&my_fh->fh); return 0; } int my_release(struct file *file) { struct v4l2_fh *fh = file->private_data; struct my_fh *my_fh = container_of(fh, struct my_fh, fh); ... v4l2_fh_del(&my_fh->fh); v4l2_fh_exit(&my_fh->fh); kfree(my_fh); return 0; } 下面是一个使用的v4l2_fh功能的简短说明: int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev) Initialise the file handle. This *MUST* be performed in the driver's v4l2_file_operations->open() handler. void v4l2_fh_add(struct v4l2_fh *fh) 添加v4l2_fh的video_device文件句柄列表。必须调用一次完全初始化文件句柄。 void v4l2_fh_del(struct v4l2_fh *fh) Unassociate the file handle from video_device(). The file handle exit function may now be called. void v4l2_fh_exit(struct v4l2_fh *fh) Uninitialise the file handle. After uninitialisation the v4l2_fh memory can be freed. 多个驱动程序需要做一些事情时,第一个文件句柄打开和关闭最后一个文件句柄时。 增加了两个辅助功能检查,是否v4l2_fh结构是唯一的打开文件句柄相关联的设备节点: int v4l2_fh_is_singular(struct v4l2_fh *fh) Returns 1 if the file handle is the only open file handle, else 0. int v4l2_fh_is_singular_file(struct file *filp) Same, but it calls v4l2_fh_is_singular with filp->private_data. V4L2 events ----------- V4L2的事件提供了一个通用的方式来传递事件到用户空间。 必须使用v4l2_fh的驱动程序能够支持V4L2的事件。 Useful functions: - v4l2_event_alloc() 使用事件驱动程序必须分配的文件句柄的事件。驱动程序通过调用函数不止一次, 可以保证至少n个总事件已分配。功能可能无法在原子上下文中被调用。 - v4l2_event_queue() 视频设备的队列中的事件。驱动程序的唯一责任是填写的类型和数据字段。V4L2的其他领域将被填充。 - v4l2_event_subscribe() 的video_device-> ioctl_ops> vidioc_subscribe_event必须检查驱动程序是否能 够产生与特定事件ID的事件。然后,它调用v4l2_event_subscribe()订阅该事件。 - v4l2_event_unsubscribe() 在结构v4l2_ioctl_ops vidioc_unsubscribe_event。一个驱动程序可以直接使用 v4l2_event_unsubscribe(),除非它想在取消订阅过程中涉及。 在特殊类型V4L2_EVENT_ALL的可能被用来取消所有活动。 驱动程序可能需要一种特殊的方式来处理。- v4l2_event_pending() 返回挂起的事件数量。实施调查时非常有用。 Events are delivered to user space through the poll system call. The driver can use v4l2_fh->events->wait wait_queue_head_t as the argument for poll_wait(). There are standard and private events. New standard events must use the smallest available event type. The drivers must allocate their events from their own class starting from class base. Class base is V4L2_EVENT_PRIVATE_START + n * 1000 where n is the lowest available number. The first event type in the class is reserved for future use, so the first available event type is 'class base + 1'. An example on how the V4L2 events may be used can be found in the OMAP 3 ISP driver available at <URL:http://gitorious.org/omap3camera> as of writing this.
V4L2-framework.txt 源文档在/Documentation/video4linux目录下.内核自带的 Documentation目录是一个非常有用的参考资料和学习资料。
建议多读!!!
Video for Linux Two API Specification
Revision 0.24
Michael H Schimek
<mschimek@gmx.at>
Bill Dirks
Hans Verkuil
Martin Rubli
This document is copyrighted © 1999-2008 by BillDirks, Michael H. Schimek, Hans Verkuil and Martin Rubli.
Permission is granted to copy, distribute and/or modifythis document under the terms of the GNU Free Documentation License,Version 1.1 or any later version published by the Free SoftwareFoundation; with no Invariant Sections, with no Front-Cover Texts, andwith no Back-Cover Texts. A copy of the license is included in theappendix entitled "GNU Free Documentation License".
Programming examples can be used and distributed withoutrestrictions.
-
Table of Contents
Introduction
-
- 1.1. Opening and Closing Devices
-
- 1.1.1. Device Naming1.1.2. Related Devices1.1.3. Multiple Opens1.1.4. Shared Data Streams1.1.5. Functions
- 1.2. Querying Capabilities1.3. Application Priority1.4. Video Inputs and Outputs1.5. Audio Inputs and Outputs1.6. Tuners and Modulators
-
- 1.6.1. Tuners1.6.2. Modulators1.6.3. Radio Frequency1.6.4. Satellite Receivers
- 1.7. Video Standards1.8. User Controls1.9. Extended Controls
-
- 1.9.1. Introduction1.9.2. The Extended Control API1.9.3. Enumerating Extended Controls1.9.4. Creating Control Panels1.9.5. MPEG Control Reference1.9.6. Camera Control Reference
- 1.10. Data Formats
-
- 1.10.1. Data Format Negotiation1.10.2. Image Format Enumeration
- 1.11. Image Cropping, Insertion and Scaling
-
- 1.11.1. Cropping Structures1.11.2. Scaling Adjustments1.11.3. Examples
- 1.12. Streaming Parameters
- 2. Image Formats
-
- 2.1. Standard Image Formats2.2. Colorspaces2.3. Indexed Format2.4. RGB Formats
-
- Packed RGB formats -- Packed RGB formatsV4L2_PIX_FMT_SBGGR8 ('BA81') -- Bayer RGB formatV4L2_PIX_FMT_SBGGR16 ('BA82') -- Bayer RGB format
- 2.5. YUV Formats
-
-
Packed YUV formats -- Packed YUV formatsV4L2_PIX_FMT_GREY ('GREY') -- Grey-scale imageV4L2_PIX_FMT_Y16 ('Y16 ') -- Grey-scale imageV4L2_PIX_FMT_YUYV ('YUYV') -- Packed format with ½ horizontal chromaresolution, also known as YUV 4:2:2V4L2_PIX_FMT_UYVY ('UYVY') -- Variation of
V4L2_PIX_FMT_YUYV
with different order of samplesin memoryV4L2_PIX_FMT_Y41P ('Y41P') -- Format with ¼ horizontal chromaresolution, also known as YUV 4:1:1V4L2_PIX_FMT_YVU420 ('YV12'), V4L2_PIX_FMT_YUV420 ('YU12') -- Planar formats with ½ horizontal andvertical chroma resolution, also known as YUV 4:2:0V4L2_PIX_FMT_YVU410 ('YVU9'), V4L2_PIX_FMT_YUV410 ('YUV9') -- Planar formats with ¼ horizontal andvertical chroma resolution, also known as YUV 4:1:0V4L2_PIX_FMT_YUV422P ('422P') -- Format with ½ horizontal chroma resolution,also known as YUV 4:2:2. Planar layout as opposed toV4L2_PIX_FMT_YUYV
V4L2_PIX_FMT_YUV411P ('411P') -- Format with ¼ horizontal chroma resolution,also known as YUV 4:1:1. Planar layout as opposed toV4L2_PIX_FMT_Y41P
V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21') -- Formats with ½ horizontal and verticalchroma resolution, also known as YUV 4:2:0. One luminance and onechrominance plane with alternating chroma samples as opposed toV4L2_PIX_FMT_YVU420
-
Packed YUV formats -- Packed YUV formatsV4L2_PIX_FMT_GREY ('GREY') -- Grey-scale imageV4L2_PIX_FMT_Y16 ('Y16 ') -- Grey-scale imageV4L2_PIX_FMT_YUYV ('YUYV') -- Packed format with ½ horizontal chromaresolution, also known as YUV 4:2:2V4L2_PIX_FMT_UYVY ('UYVY') -- Variation of
- 2.6. Compressed Formats2.7. Reserved Format Identifiers
- 3. Input/Output
-
- 3.1. Read/Write3.2. Streaming I/O (Memory Mapping)3.3. Streaming I/O (User Pointers)3.4. Asynchronous I/O3.5. Buffers
-
- 3.5.1. Timecodes
- 3.6. Field Order
- 4. Interfaces
-
- 4.1. Video Capture Interface
-
- 4.1.1. Querying Capabilities4.1.2. Supplemental Functions4.1.3. Image Format Negotiation4.1.4. Reading Images
- 4.2. Video Overlay Interface
-
- 4.2.1. Querying Capabilities4.2.2. Supplemental Functions4.2.3. Setup4.2.4. Overlay Window4.2.5. Enabling Overlay
- 4.3. Video Output Interface
-
- 4.3.1. Querying Capabilities4.3.2. Supplemental Functions4.3.3. Image Format Negotiation4.3.4. Writing Images
- 4.4. Video Output Overlay Interface
-
- 4.4.1. Querying Capabilities4.4.2. Framebuffer4.4.3. Overlay Window and Scaling4.4.4. Enabling Overlay
- 4.5. Codec Interface4.6. Effect Devices Interface4.7. Raw VBI Data Interface
-
- 4.7.1. Querying Capabilities4.7.2. Supplemental Functions4.7.3. Raw VBI Format Negotiation4.7.4. Reading and writing VBI images
- 4.8. Sliced VBI Data Interface
-
- 4.8.1. Querying Capabilities4.8.2. Supplemental Functions4.8.3. Sliced VBI Format Negotiation4.8.4. Reading and writing sliced VBI data
- 4.9. Teletext Interface4.10. Radio Interface
-
- 4.10.1. Querying Capabilities4.10.2. Supplemental Functions4.10.3. Programming
- 4.11. RDS Interface
- I. Function Reference
-
- V4L2 close() -- Close a V4L2 deviceV4L2 ioctl() -- Program a V4L2 deviceioctl VIDIOC_CROPCAP -- Information about the video cropping and scaling abilitiesioctl VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER -- Read or write hardware registersioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD -- Execute an encoder commandioctl VIDIOC_ENUMAUDIO -- Enumerate audio inputsioctl VIDIOC_ENUMAUDOUT -- Enumerate audio outputsioctl VIDIOC_ENUM_FMT -- Enumerate image formatsioctl VIDIOC_ENUM_FRAMESIZES -- Enumerate frame sizesioctl VIDIOC_ENUM_FRAMEINTERVALS -- Enumerate frame intervalsioctl VIDIOC_ENUMINPUT -- Enumerate video inputsioctl VIDIOC_ENUMOUTPUT -- Enumerate video outputsioctl VIDIOC_ENUMSTD -- Enumerate supported video standardsioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO -- Query or select the current audio input and itsattributesioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT -- Query or select the current audio outputioctl VIDIOC_G_CHIP_IDENT -- Identify the chips on a TV cardioctl VIDIOC_G_CROP, VIDIOC_S_CROP -- Get or set the current cropping rectangleioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL -- Get or set the value of a controlioctl VIDIOC_G_ENC_INDEX -- Get meta data about a compressed video streamioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS,VIDIOC_TRY_EXT_CTRLS -- Get or set the value of several controls, try controlvaluesioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF -- Get or set frame buffer overlay parametersioctl VIDIOC_G_FMT, VIDIOC_S_FMT,VIDIOC_TRY_FMT -- Get or set the data format, try a formatioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY -- Get or set tuner or modulator radiofrequencyioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT -- Query or select the current video inputioctl VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP -- ioctl VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR -- Get or set modulator attributesioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT -- Query or select the current video outputioctl VIDIOC_G_PARM, VIDIOC_S_PARM -- Get or set streaming parametersioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY -- Query or request the access priority associated with afile descriptorioctl VIDIOC_G_SLICED_VBI_CAP -- Query sliced VBI capabilitiesioctl VIDIOC_G_STD, VIDIOC_S_STD -- Query or select the video standard of the current inputioctl VIDIOC_G_TUNER, VIDIOC_S_TUNER -- Get or set tuner attributesioctl VIDIOC_LOG_STATUS -- Log driver status informationioctl VIDIOC_OVERLAY -- Start or stop video overlayioctl VIDIOC_QBUF, VIDIOC_DQBUF -- Exchange a buffer with the driverioctl VIDIOC_QUERYBUF -- Query the status of a bufferioctl VIDIOC_QUERYCAP -- Query device capabilitiesioctl VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU -- Enumerate controls and menu control itemsioctl VIDIOC_QUERYSTD -- Sense the video standard received by the currentinputioctl VIDIOC_REQBUFS -- Initiate Memory Mapping or User Pointer I/Oioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF -- Start or stop streaming I/OV4L2 mmap() -- Map device memory into application address spaceV4L2 munmap() -- Unmap device memoryV4L2 open() -- Open a V4L2 deviceV4L2 poll() -- Wait for some event on a file descriptorV4L2 read() -- Read from a V4L2 deviceV4L2 select() -- Synchronous I/O multiplexingV4L2 write() -- Write to a V4L2 device
- 5. V4L2 Driver Programming6. Changes
-
- 6.1. Differences between V4L and V4L2
-
- 6.1.1. Opening and Closing Devices6.1.2. Querying Capabilities6.1.3. Video Sources6.1.4. Tuning6.1.5. Image Properties6.1.6. Audio6.1.7. Frame Buffer Overlay6.1.8. Cropping6.1.9. Reading Images, Memory Mapping6.1.10. Reading Raw VBI Data6.1.11. Miscellaneous
- 6.2. Changes of the V4L2 API
-
- 6.2.1. Early Versions6.2.2. V4L2 Version 0.16 1999-01-316.2.3. V4L2 Version 0.18 1999-03-166.2.4. V4L2 Version 0.19 1999-06-056.2.5. V4L2 Version 0.20 (1999-09-10)6.2.6. V4L2 Version 0.20 incremental changes6.2.7. V4L2 Version 0.20 2000-11-236.2.8. V4L2 Version 0.20 2002-07-256.2.9. V4L2 in Linux 2.5.46, 2002-106.2.10. V4L2 2003-06-196.2.11. V4L2 2003-11-056.2.12. V4L2 in Linux 2.6.6, 2004-05-096.2.13. V4L2 in Linux 2.6.86.2.14. V4L2 spec erratum 2004-08-016.2.15. V4L2 in Linux 2.6.146.2.16. V4L2 in Linux 2.6.156.2.17. V4L2 spec erratum 2005-11-276.2.18. V4L2 spec erratum 2006-01-106.2.19. V4L2 spec erratum 2006-02-036.2.20. V4L2 spec erratum 2006-02-046.2.21. V4L2 in Linux 2.6.176.2.22. V4L2 spec erratum 2006-09-23 (Draft 0.15)6.2.23. V4L2 in Linux 2.6.186.2.24. V4L2 in Linux 2.6.196.2.25. V4L2 spec erratum 2006-10-12 (Draft 0.17)6.2.26. V4L2 in Linux 2.6.216.2.27. V4L2 in Linux 2.6.226.2.28. V4L2 in Linux 2.6.246.2.29. V4L2 in Linux 2.6.25
- 6.3. Relation of V4L2 to other Linux multimedia APIs
-
- 6.3.1. X Video Extension6.3.2. Digital Video6.3.3. Audio Interfaces
- 6.4. Experimental API Elements6.5. Obsolete API Elements
- A. Video For Linux Two Header FileB. Video Capture ExampleC. GNU Free Documentation License
-
- C.1. 0. PREAMBLEC.2. 1. APPLICABILITY AND DEFINITIONSC.3. 2. VERBATIM COPYINGC.4. 3. COPYING IN QUANTITYC.5. 4. MODIFICATIONSC.6. 5. COMBINING DOCUMENTSC.7. 6. COLLECTIONS OF DOCUMENTSC.8. 7. AGGREGATION WITH INDEPENDENT WORKSC.9. 8. TRANSLATIONC.10. 9. TERMINATIONC.11. 10. FUTURE REVISIONS OF THIS LICENSEC.12. Addendum
- List of TypesReferences
- List of Figures1-1. Image Cropping, Insertion and Scaling3-1. Field Order, Top Field First Transmitted3-2. Field Order, Bottom Field First Transmitted4-1. Line synchronization4-2. ITU-R 525 line numbering (M/NTSC and M/PAL)4-3. ITU-R 625 line numbering
-
List of Examples1-1. Information about the current video input1-2. Switching to the first video input1-3. Information about the current audio input1-4. Switching to the first audio input1-5. Information about the current video standard1-6. Listing the video standards supported by the currentinput1-7. Selecting a new video standard1-8. Enumerating all controls1-9. Changing controls1-10. Resetting the cropping parameters1-11. Simple downscaling1-12. Selecting an output area1-13. Current scaling factor and pixel aspect2-1. ITU-R Rec. BT.601 color conversion2-1.
V4L2_PIX_FMT_BGR24
4 × 4 pixelimage2-1.V4L2_PIX_FMT_SBGGR8
4 × 4pixel image2-1.V4L2_PIX_FMT_SBGGR16
4 × 4pixel image2-1.V4L2_PIX_FMT_GREY
4 × 4pixel image2-1.V4L2_PIX_FMT_Y16
4 × 4pixel image2-1.V4L2_PIX_FMT_YUYV
4 × 4pixel image2-1.V4L2_PIX_FMT_UYVY
4 × 4pixel image2-1.V4L2_PIX_FMT_Y41P
8 × 4pixel image2-1.V4L2_PIX_FMT_YVU420
4 × 4pixel image2-1.V4L2_PIX_FMT_YVU410
4 × 4pixel image2-1.V4L2_PIX_FMT_YUV422P
4 × 4pixel image2-1.V4L2_PIX_FMT_YUV411P
4 × 4pixel image2-1.V4L2_PIX_FMT_NV12
4 × 4pixel image3-1. Mapping buffers3-2. Initiating streaming I/O with user pointers4-1. Finding a framebuffer device for OSD
Chapter 1. Common API Elements
Programming a V4L2 device consists of thesesteps:
Opening the device
Changing device properties, selecting a video and audioinput, video standard, picture brightness a. o.
Negotiating a data format
Negotiating an input/output method
The actual input/output loop
Closing the device
In practice most steps are optional and can be executed out oforder. It depends on the V4L2 device type, you can read about thedetails inChapter 4. In this chapter we will discussthe basic concepts applicable to all devices.
1.1. Opening and Closing Devices
1.1.1. Device Naming
> insmod mydriver.o video_nr=0,1 radio_nr=0,1
In /etc/modules.conf this may bewritten as:
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
- When an application attempts to open a devicespecial file with major number 81 and minor number 0, 1, or 64, load"mydriver" (and the "videodev" module it depends upon).
- Register the first two video capture devices withminor number 0 and 1 (base number is 0), the first two radio devicewith minor number 64 and 65 (base 64).
When no minor number is given as moduleoption the driver supplies a default. Chapter 4recommends the base minor numbers to be used for the various devicetypes. Obviously minor numbers must be unique. When the number isalready in use theoffending device will not beregistered.
By convention system administrators create variouscharacter device special files with these major and minor numbers inthe/dev directory. The names recomended for thedifferent V4L2 device types are listed inChapter 4.
The creation of character special files (withmknod) is a privileged operation anddevices cannot be opened by major and minor number. That meansapplications cannotreliable scan for loaded orinstalled drivers. The user must enter a device name, or theapplication can try the conventional device names.
Under the device filesystem (devfs) the minor numberoptions are ignored. V4L2 drivers (or by proxy the "videodev" module)automatically create the required device files in the/dev/v4l directory using the conventional devicenames above.
1.1.3. Multiple Opens
Multiple opens are optional, although drivers shouldpermit at least concurrent accesses without data exchange, i. e. panelapplications. This impliesopen()
can return anEBUSY error code when thedevice is already in use, as well asioctl()
functions initiatingdata exchange (namely theVIDIOC_S_FMT
ioctl), and theread()
andwrite()
functions.
Mere opening a V4L2 device does not grant exclusiveaccess.[4] Initiating data exchange however assigns the rightto read or write the requested type of data, and to change relatedproperties, to this file descriptor. Applications can requestadditional access privileges using the priority mechanism described inSection 1.3.
1.4. Video Inputs and Outputs
Example 1-1. Information about the current video input
struct v4l2_input input; int index;if (-1 == ioctl (fd, VIDIOC_G_INPUT, &index)) {perror ("VIDIOC_G_INPUT");exit (EXIT_FAILURE); }memset (&input, 0, sizeof (input)); input.index = index;if (-1 == ioctl (fd, VIDIOC_ENUMINPUT, &input)) {perror ("VIDIOC_ENUMINPUT");exit (EXIT_FAILURE); }printf ("Current input: %s\n", input.name);
Example 1-2. Switching to the first video input
int index;index = 0;if (-1 == ioctl (fd, VIDIOC_S_INPUT, &index)) {perror ("VIDIOC_S_INPUT");exit (EXIT_FAILURE); }
1.5. Audio Inputs and Outputs
Audio and video inputs and outputs are associated. Selectinga video source also selects an audio source. This is most evident whenthe video and audio source is a tuner. Further audio connectors cancombine with more than one video input or output. Assumed twocomposite video inputs and two audio inputs exist, there may be up tofour valid combinations. The relation of video and audio connectorsis defined in theaudioset
field of therespective struct v4l2_input or struct v4l2_output, where each bit representsthe index number, starting at zero, of one audio input or output.
To learn about the number and attributes of theavailable inputs and outputs applications can enumerate them with theVIDIOC_ENUMAUDIO
andVIDIOC_ENUMAUDOUT
ioctl, respectively. Thestruct v4l2_audio returned by theVIDIOC_ENUMAUDIO
ioctlalso contains signal status information applicable when the currentaudio input is queried.
The VIDIOC_G_AUDIO
and VIDIOC_G_AUDOUT
ioctl reportthe current audio input and output, respectively. Note that, unlikeVIDIOC_G_INPUT
andVIDIOC_G_OUTPUT
these ioctls return a structureasVIDIOC_ENUMAUDIO
andVIDIOC_ENUMAUDOUT
do, not just an index.
To select an audio input and change its propertiesapplications call the VIDIOC_S_AUDIO
ioctl. To select an audiooutput (which presently has no changeable properties) applicationscall theVIDIOC_S_AUDOUT
ioctl.
Drivers must implement all input ioctls when the devicehas one or more inputs, all output ioctls when the device has oneor more outputs. When the device has any audio inputs or outputs thedriver must set theV4L2_CAP_AUDIO
flag in thestruct v4l2_capability returned by theVIDIOC_QUERYCAP
ioctl.
Example 1-3. Information about the current audio input
struct v4l2_audio audio;memset (&audio, 0, sizeof (audio));if (-1 == ioctl (fd, VIDIOC_G_AUDIO, &audio)) {perror ("VIDIOC_G_AUDIO");exit (EXIT_FAILURE); }printf ("Current input: %s\n", audio.name);
Example 1-4. Switching to the first audio input
struct v4l2_audio audio;memset (&audio, 0, sizeof (audio)); /* clear audio.mode, audio.reserved */audio.index = 0;if (-1 == ioctl (fd, VIDIOC_S_AUDIO, &audio)) {perror ("VIDIOC_S_AUDIO");exit (EXIT_FAILURE); }
1.6. Tuners and Modulators
1.7. Video Standards
Special rules apply to USB cameras where the notion of videostandards makes little sense. More generally any capture device,output devices accordingly, which is
incapable of capturing fields or frames at the nominalrate of the video standard, or
where timestamps referto the instant the field or frame was received by the driver, not thecapture time, or
where sequence numbersrefer to the frames received by the driver, not the capturedframes.
Here the driver shall set thestd
field of struct v4l2_input and struct v4l2_outputto zero, the VIDIOC_G_STD
,VIDIOC_S_STD
,VIDIOC_QUERYSTD
andVIDIOC_ENUMSTD
ioctls shall return theEINVAL error code.[8]
Example 1-5. Information about the current video standard
v4l2_std_id std_id; struct v4l2_standard standard;if (-1 == ioctl (fd, VIDIOC_G_STD, &std_id)) {/* Note when VIDIOC_ENUMSTD always returns EINVAL thisis no video device or it falls under the USB exception,and VIDIOC_G_STD returning EINVAL is no error. */perror ("VIDIOC_G_STD");exit (EXIT_FAILURE); }memset (&standard, 0, sizeof (standard)); standard.index = 0;while (0 == ioctl (fd, VIDIOC_ENUMSTD, &standard)) {if (standard.id & std_id) {printf ("Current video standard: %s\n", standard.name);exit (EXIT_SUCCESS);}standard.index++; }/* EINVAL indicates the end of the enumeration, which cannot beempty unless this device falls under the USB exception. */if (errno == EINVAL || standard.index == 0) {perror ("VIDIOC_ENUMSTD");exit (EXIT_FAILURE); }
Example 1-6. Listing the video standards supported by the currentinput
struct v4l2_input input; struct v4l2_standard standard;memset (&input, 0, sizeof (input));if (-1 == ioctl (fd, VIDIOC_G_INPUT, &input.index)) {perror ("VIDIOC_G_INPUT");exit (EXIT_FAILURE); }if (-1 == ioctl (fd, VIDIOC_ENUMINPUT, &input)) {perror ("VIDIOC_ENUM_INPUT");exit (EXIT_FAILURE); }printf ("Current input %s supports:\n", input.name);memset (&standard, 0, sizeof (standard)); standard.index = 0;while (0 == ioctl (fd, VIDIOC_ENUMSTD, &standard)) {if (standard.id & input.std)printf ("%s\n", standard.name);standard.index++; }/* EINVAL indicates the end of the enumeration, which cannot beempty unless this device falls under the USB exception. */if (errno != EINVAL || standard.index == 0) {perror ("VIDIOC_ENUMSTD");exit (EXIT_FAILURE); }
Example 1-7. Selecting a new video standard
struct v4l2_input input;
v4l2_std_id std_id;memset (&input, 0, sizeof (input));if (-1 == ioctl (fd, VIDIOC_G_INPUT, &input.index)) {perror ("VIDIOC_G_INPUT");exit (EXIT_FAILURE);
}if (-1 == ioctl (fd, VIDIOC_ENUMINPUT, &input)) {perror ("VIDIOC_ENUM_INPUT");exit (EXIT_FAILURE);
}if (0 == (input.std & V4L2_STD_PAL_BG)) {fprintf (stderr, "Oops. B/G PAL is not supported.\n");exit (EXIT_FAILURE);
}/* Note this is also supposed to work when only Bor G/PAL is supported. */std_id = V4L2_STD_PAL_BG;if (-1 == ioctl (fd, VIDIOC_S_STD, &std_id)) {perror ("VIDIOC_S_STD");exit (EXIT_FAILURE);
}
1.8. User Controls
Table 1-1. Control IDs
ID | Type | Description |
---|---|---|
V4L2_CID_BASE
|
First predefined ID, equal toV4L2_CID_BRIGHTNESS .
|
|
V4L2_CID_USER_BASE
|
Synonym of V4L2_CID_BASE .
|
|
V4L2_CID_BRIGHTNESS
|
integer | Picture brightness, or more precisely, the blacklevel. |
V4L2_CID_CONTRAST
|
integer | Picture contrast or luma gain. |
V4L2_CID_SATURATION
|
integer | Picture color saturation or chroma gain. |
V4L2_CID_HUE
|
integer | Hue or color balance. |
V4L2_CID_AUDIO_VOLUME
|
integer | Overall audio volume. Note some drivers alsoprovide an OSS or ALSA mixer interface. |
V4L2_CID_AUDIO_BALANCE
|
integer | Audio stereo balance. Minimum corresponds to allthe way left, maximum to right. |
V4L2_CID_AUDIO_BASS
|
integer | Audio bass adjustment. |
V4L2_CID_AUDIO_TREBLE
|
integer | Audio treble adjustment. |
V4L2_CID_AUDIO_MUTE
|
boolean |
Mute audio, i. e. set the volume to zero, howeverwithout affectingV4L2_CID_AUDIO_VOLUME . LikeALSA drivers, V4L2 drivers must mute at load time to avoid excessivenoise. Actually the entire device should be reset to a low powerconsumption state.
|
V4L2_CID_AUDIO_LOUDNESS
|
boolean | Loudness mode (bass boost). |
V4L2_CID_BLACK_LEVEL
|
integer |
Another name for brightness (not a synonym ofV4L2_CID_BRIGHTNESS ). This control is deprecatedand should not be used in new drivers and applications.
|
V4L2_CID_AUTO_WHITE_BALANCE
|
boolean | Automatic white balance (cameras). |
V4L2_CID_DO_WHITE_BALANCE
|
button |
This is an action control. When set (the value isignored), the device will do a white balance and then hold the currentsetting. Contrast this with the booleanV4L2_CID_AUTO_WHITE_BALANCE , which, whenactivated, keeps adjusting the white balance.
|
V4L2_CID_RED_BALANCE
|
integer | Red chroma balance. |
V4L2_CID_BLUE_BALANCE
|
integer | Blue chroma balance. |
V4L2_CID_GAMMA
|
integer | Gamma adjust. |
V4L2_CID_WHITENESS
|
integer |
Whiteness for grey-scale devices. This is a synonymfor V4L2_CID_GAMMA . This control is deprecatedand should not be used in new drivers and applications.
|
V4L2_CID_EXPOSURE
|
integer | Exposure (cameras). [Unit?] |
V4L2_CID_AUTOGAIN
|
boolean | Automatic gain/exposure control. |
V4L2_CID_GAIN
|
integer | Gain control. |
V4L2_CID_HFLIP
|
boolean | Mirror the picture horizontally. |
V4L2_CID_VFLIP
|
boolean | Mirror the picture vertically. |
V4L2_CID_HCENTER_DEPRECATED (formerlyV4L2_CID_HCENTER )
|
integer |
Horizontal image centering. This control isdeprecated. New drivers and applications should use theCamera class controlsV4L2_CID_PAN_ABSOLUTE ,V4L2_CID_PAN_RELATIVE andV4L2_CID_PAN_RESET instead.
|
V4L2_CID_VCENTER_DEPRECATED (formerlyV4L2_CID_VCENTER )
|
integer |
Vertical image centering. Centering is intended tophysically adjust cameras. For image cropping seeSection 1.11, for clippingSection 4.2. Thiscontrol is deprecated. New drivers and applications should use theCamera class controlsV4L2_CID_TILT_ABSOLUTE ,V4L2_CID_TILT_RELATIVE andV4L2_CID_TILT_RESET instead.
|
V4L2_CID_POWER_LINE_FREQUENCY
|
integer |
Enables a power line frequency filter to avoidflicker. Possible values are:V4L2_CID_POWER_LINE_FREQUENCY_DISABLED (0),V4L2_CID_POWER_LINE_FREQUENCY_50HZ (1) andV4L2_CID_POWER_LINE_FREQUENCY_60HZ (2).
|
V4L2_CID_HUE_AUTO
|
boolean |
Enables automatic hue control by the device. Theeffect of settingV4L2_CID_HUE while automatichue control is enabled is undefined, drivers should ignore suchrequest.
|
V4L2_CID_WHITE_BALANCE_TEMPERATURE
|
integer | This control specifies the white balance settingsas a color temperature in Kelvin. A driver should have a minimum of2800 (incandescent) to 6500 (daylight). For more information aboutcolor temperature seeWikipedia. |
V4L2_CID_SHARPNESS
|
integer | Adjusts the sharpness filters in a camera. Theminimum value disables the filters, higher values give a sharperpicture. |
V4L2_CID_BACKLIGHT_COMPENSATION
|
integer | Adjusts the backlight compensation in a camera. Theminimum value disables backlight compensation. |
V4L2_CID_LASTP1
|
End of the predefined control IDs (currentlyV4L2_CID_BACKLIGHT_COMPENSATION + 1).
|
|
V4L2_CID_PRIVATE_BASE
|
ID of the first custom (driver specific) control.Applications depending on particular custom controls should check thedriver name and version, seeSection 1.2. |
Applications can enumerate the available controls with theVIDIOC_QUERYCTRL
andVIDIOC_QUERYMENU
ioctls, get and set acontrol value with theVIDIOC_G_CTRL
andVIDIOC_S_CTRL
ioctls.Drivers must implementVIDIOC_QUERYCTRL
,VIDIOC_G_CTRL
andVIDIOC_S_CTRL
when the device has one or morecontrols,VIDIOC_QUERYMENU
when it has one ormore menu type controls.
Example 1-8. Enumerating all controls
struct v4l2_queryctrl queryctrl; struct v4l2_querymenu querymenu;static void enumerate_menu (void) {printf (" Menu items:\n");memset (&querymenu, 0, sizeof (querymenu));querymenu.id = queryctrl.id;for (querymenu.index = queryctrl.minimum;querymenu.index <= queryctrl.maximum;querymenu.index++) {if (0 == ioctl (fd, VIDIOC_QUERYMENU, &querymenu)) {printf (" %s\n", querymenu.name);} else {perror ("VIDIOC_QUERYMENU");exit (EXIT_FAILURE);}} }memset (&queryctrl, 0, sizeof (queryctrl));for (queryctrl.id = V4L2_CID_BASE;queryctrl.id < V4L2_CID_LASTP1;queryctrl.id++) {if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)continue;printf ("Control %s\n", queryctrl.name);if (queryctrl.type == V4L2_CTRL_TYPE_MENU)enumerate_menu ();} else {if (errno == EINVAL)continue;perror ("VIDIOC_QUERYCTRL");exit (EXIT_FAILURE);} }for (queryctrl.id = V4L2_CID_PRIVATE_BASE;;queryctrl.id++) {if (0 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)continue;printf ("Control %s\n", queryctrl.name);if (queryctrl.type == V4L2_CTRL_TYPE_MENU)enumerate_menu ();} else {if (errno == EINVAL)break;perror ("VIDIOC_QUERYCTRL");exit (EXIT_FAILURE);} }
Example 1-9. Changing controls
struct v4l2_queryctrl queryctrl; struct v4l2_control control;memset (&queryctrl, 0, sizeof (queryctrl)); queryctrl.id = V4L2_CID_BRIGHTNESS;if (-1 == ioctl (fd, VIDIOC_QUERYCTRL, &queryctrl)) {if (errno != EINVAL) {perror ("VIDIOC_QUERYCTRL");exit (EXIT_FAILURE);} else {printf ("V4L2_CID_BRIGHTNESS is not supported\n");} } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {printf ("V4L2_CID_BRIGHTNESS is not supported\n"); } else {memset (&control, 0, sizeof (control));control.id = V4L2_CID_BRIGHTNESS;control.value = queryctrl.default_value;if (-1 == ioctl (fd, VIDIOC_S_CTRL, &control)) {perror ("VIDIOC_S_CTRL");exit (EXIT_FAILURE);} }memset (&control, 0, sizeof (control)); control.id = V4L2_CID_CONTRAST;if (0 == ioctl (fd, VIDIOC_G_CTRL, &control)) {control.value += 1;/* The driver may clamp the value or return ERANGE, ignored here */if (-1 == ioctl (fd, VIDIOC_S_CTRL, &control)&& errno != ERANGE) {perror ("VIDIOC_S_CTRL");exit (EXIT_FAILURE);} /* Ignore if V4L2_CID_CONTRAST is unsupported */ } else if (errno != EINVAL) {perror ("VIDIOC_G_CTRL");exit (EXIT_FAILURE); }control.id = V4L2_CID_AUDIO_MUTE; control.value = TRUE; /* silence *//* Errors ignored */ ioctl (fd, VIDIOC_S_CTRL, &control);
1.9. Extended Controls
1.9.3. Enumerating Extended Controls
struct v4l2_queryctrl qctrl;qctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL; while (0 == ioctl (fd, VIDIOC_QUERYCTRL, &qctrl)) {/* ... */qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; }
The initial control ID is set to 0 ORed with theV4L2_CTRL_FLAG_NEXT_CTRL
flag. TheVIDIOC_QUERYCTRL
ioctl will return the firstcontrol with a higher ID than the specified one. When no such controlsare found an error is returned.
If you want to get all controls within a specific controlclass, then you can set the initialqctrl.id
value to the control class and addan extra check to break out of the loop when a control of anothercontrol class is found:
qctrl.id = V4L2_CTRL_CLASS_MPEG | V4L2_CTRL_FLAG_NEXT_CTRL; while (0 == ioctl (fd, VIDIOC_QUERYCTRL, &qctrl)) {if (V4L2_CTRL_ID2CLASS (qctrl.id) != V4L2_CTRL_CLASS_MPEG)break;/* ... */qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;}
The 32-bit qctrl.id
value issubdivided into three bit ranges: the top 4 bits are reserved forflags (e. g.V4L2_CTRL_FLAG_NEXT_CTRL
) and are notactually part of the ID. The remaining 28 bits form the control ID, ofwhich the most significant 12 bits define the control class and theleast significant 16 bits identify the control within the controlclass. It is guaranteed that these last 16 bits are always non-zerofor controls. The range of 0x1000 and up are reserved fordriver-specific controls. The macroV4L2_CTRL_ID2CLASS(id)
returns the control classID based on a control ID.
If the driver does not support extended controls, thenVIDIOC_QUERYCTRL
will fail when used incombination withV4L2_CTRL_FLAG_NEXT_CTRL
. Inthat case the old method of enumerating control should be used (see1.8). But if it is supported, then it is guaranteed to enumerate overall controls, including driver-private controls.
1.9.5. MPEG Control Reference
1.9.5.1. Generic MPEG Controls
Table 1-2. MPEG Control IDs
ID | Type | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_CLASS
|
class | ||||||||||||||||||||||||||||||
The MPEG classdescriptor. Calling VIDIOC_QUERYCTRL for this control will return adescription of this control class. This description can be used as thecaption of a Tab page in a GUI, for example.
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_STREAM_TYPE
|
enum | ||||||||||||||||||||||||||||||
The MPEG-1, -2 or -4output stream type. One cannot assume anything here. Each hardwareMPEG encoder tends to support different subsets of the available MPEGstream types. The currently defined stream types are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_STREAM_PID_PMT
|
integer | ||||||||||||||||||||||||||||||
Program Map TablePacket ID for the MPEG transport stream (default 16) | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_STREAM_PID_AUDIO
|
integer | ||||||||||||||||||||||||||||||
Audio Packet ID forthe MPEG transport stream (default 256) | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_STREAM_PID_VIDEO
|
integer | ||||||||||||||||||||||||||||||
Video Packet ID forthe MPEG transport stream (default 260) | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_STREAM_PID_PCR
|
integer | ||||||||||||||||||||||||||||||
Packet ID for theMPEG transport stream carrying PCR fields (default 259) | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_STREAM_PES_ID_AUDIO
|
integer | ||||||||||||||||||||||||||||||
Audio ID for MPEGPES | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_STREAM_PES_ID_VIDEO
|
integer | ||||||||||||||||||||||||||||||
Video ID for MPEGPES | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_STREAM_VBI_FMT
|
enum | ||||||||||||||||||||||||||||||
Some cards can embedVBI data (e. g. Closed Caption, Teletext) into the MPEG stream. Thiscontrol selects whether VBI data should be embedded, and if so, whatembedding method should be used. The list of possible VBI formatsdepends on the driver. The currently defined VBI format typesare: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ
|
enum | ||||||||||||||||||||||||||||||
MPEG Audio samplingfrequency. Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_ENCODING
|
enum | ||||||||||||||||||||||||||||||
MPEG Audio encoding.Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_L1_BITRATE
|
enum | ||||||||||||||||||||||||||||||
Layer I bitrate.Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_L2_BITRATE
|
enum | ||||||||||||||||||||||||||||||
Layer II bitrate.Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_L3_BITRATE
|
enum | ||||||||||||||||||||||||||||||
Layer III bitrate.Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_MODE
|
enum | ||||||||||||||||||||||||||||||
MPEG Audio mode.Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_MODE_EXTENSION
|
enum | ||||||||||||||||||||||||||||||
Joint Stereoaudio mode extension. In Layer I and II they indicate which subbandsare in intensity stereo. All other subbands are coded in stereo. LayerIII is not (yet) supported. Possible valuesare: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_EMPHASIS
|
enum | ||||||||||||||||||||||||||||||
Audio Emphasis.Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_CRC
|
enum | ||||||||||||||||||||||||||||||
CRC method. Possiblevalues are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_AUDIO_MUTE
|
bool | ||||||||||||||||||||||||||||||
Mutes the audio whencapturing. This is not done by muting audio hardware, which can stillproduce a slight hiss, but in the encoder itself, guaranteeing a fixedand reproducable audio bitstream. 0 = unmuted, 1 = muted. | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_ENCODING
|
enum | ||||||||||||||||||||||||||||||
MPEG Video encodingmethod. Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_ASPECT
|
enum | ||||||||||||||||||||||||||||||
Video aspect.Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_B_FRAMES
|
integer | ||||||||||||||||||||||||||||||
Number of B-Frames(default 2) | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_GOP_SIZE
|
integer | ||||||||||||||||||||||||||||||
GOP size (default12) | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_GOP_CLOSURE
|
bool | ||||||||||||||||||||||||||||||
GOP closure (default1) | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_PULLDOWN
|
bool | ||||||||||||||||||||||||||||||
Enable 3:2 pulldown(default 0) | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_BITRATE_MODE
|
enum | ||||||||||||||||||||||||||||||
Video bitrate mode.Possible values are: | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_BITRATE
|
integer | ||||||||||||||||||||||||||||||
Video bitrate in bitsper second. | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
|
integer | ||||||||||||||||||||||||||||||
Peak video bitrate inbits per second. Must be larger or equal to the average video bitrate.It is ignored if the video bitrate mode is set to constantbitrate. | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION
|
integer | ||||||||||||||||||||||||||||||
For every capturedframe, skip this many subsequent frames (default 0). | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_MUTE
|
bool | ||||||||||||||||||||||||||||||
"Mutes" the video to afixed color when capturing. This is useful for testing, to produce afixed video bitstream. 0 = unmuted, 1 = muted. | |||||||||||||||||||||||||||||||
V4L2_CID_MPEG_VIDEO_MUTE_YUV
|
integer | ||||||||||||||||||||||||||||||
Sets the "mute" colorof the video. The supplied 32-bit integer is interpreted as follows (bit0 = least significant bit): | |||||||||||||||||||||||||||||||
|
1.9.5.2. CX2341x MPEG Controls
Table 1-3. CX2341x Control IDs
ID | Type | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description | |||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE
|
enum | ||||||||||||
Sets the SpatialFilter mode (default MANUAL ). Possible valuesare:
|
|||||||||||||
|
|||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER
|
integer (0-15) | ||||||||||||
The setting for theSpatial Filter. 0 = off, 15 = maximum. (Default is 0.) | |||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE
|
enum | ||||||||||||
Select the algorithmto use for the Luma Spatial Filter (default1D_HOR ). Possible values:
|
|||||||||||||
|
|||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE
|
enum | ||||||||||||
Select the algorithmfor the Chroma Spatial Filter (default 1D_HOR ).Possible values are:
|
|||||||||||||
|
|||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE
|
enum | ||||||||||||
Sets the TemporalFilter mode (default MANUAL ). Possible valuesare:
|
|||||||||||||
|
|||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER
|
integer (0-31) | ||||||||||||
The setting for theTemporal Filter. 0 = off, 31 = maximum. (Default is 8 for full-scalecapturing and 0 for scaled capturing.) | |||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE
|
enum | ||||||||||||
Median Filter Type(default OFF ). Possible values are:
|
|||||||||||||
|
|||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM
|
integer (0-255) | ||||||||||||
Threshold above whichthe luminance median filter is enabled (default 0) | |||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP
|
integer (0-255) | ||||||||||||
Threshold below whichthe luminance median filter is enabled (default 255) | |||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM
|
integer (0-255) | ||||||||||||
Threshold above whichthe chroma median filter is enabled (default 0) | |||||||||||||
V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP
|
integer (0-255) | ||||||||||||
Threshold below whichthe chroma median filter is enabled (default 255) | |||||||||||||
V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS
|
bool | ||||||||||||
The CX2341X MPEG encodercan insert one empty MPEG-2 PES packet into the stream between everyfour video frames. The packet size is 2048 bytes, including thepacket_start_code_prefix and stream_id fields. The stream_id is 0xBF(private stream 2). The payload consists of 0x00 bytes, to be filledin by the application. 0 = do not insert, 1 = insert packets. |
1.9.6. Camera Control Reference
Table 1-4. Camera Control IDs
ID | Type | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Description | |||||||||||
V4L2_CID_CAMERA_CLASS
|
class | ||||||||||
The Camera classdescriptor. Calling VIDIOC_QUERYCTRL for this control will return adescription of this control class.
|
|||||||||||
V4L2_CID_EXPOSURE_AUTO
|
integer | ||||||||||
Enables automaticadjustments of the exposure time and/or iris aperture. The effect ofmanual changes of the exposure time or iris aperture while thesefeatures are enabled is undefined, drivers should ignore suchrequests. Possible values are: | |||||||||||
|
|||||||||||
V4L2_CID_EXPOSURE_ABSOLUTE
|
integer | ||||||||||
Determines the exposuretime of the camera sensor. The exposure time is limited by the frameinterval. Drivers should interpret the values as 100 µs units,where the value 1 stands for 1/10000th of a second, 10000 for 1 secondand 100000 for 10 seconds. | |||||||||||
V4L2_CID_EXPOSURE_AUTO_PRIORITY
|
boolean | ||||||||||
WhenV4L2_CID_EXPOSURE_AUTO is set toAUTO orSHUTTER_PRIORITY ,this control determines if the device may dynamically vary the framerate. By default this feature is disabled (0) and the frame rate mustremain constant.
|
|||||||||||
V4L2_CID_PAN_RELATIVE
|
integer | ||||||||||
This control turns thecamera horizontally by the specified amount. The unit is undefined. Apositive value moves the camera to the right (clockwise when viewedfrom above), a negative value to the left. A value of zero does notcause motion. | |||||||||||
V4L2_CID_TILT_RELATIVE
|
integer | ||||||||||
This control turns thecamera vertically by the specified amount. The unit is undefined. Apositive value moves the camera up, a negative value down. A value ofzero does not cause motion. | |||||||||||
V4L2_CID_PAN_RESET
|
boolean | ||||||||||
When this control is setto TRUE (1), the camera moves horizontally to thedefault position.
|
|||||||||||
V4L2_CID_TILT_RESET
|
boolean | ||||||||||
When this control is setto TRUE (1), the camera moves vertically to thedefault position.
|
|||||||||||
V4L2_CID_PAN_ABSOLUTE
|
integer | ||||||||||
This controlturns the camera horizontally to the specified position. Positivevalues move the camera to the right (clockwise when viewed from above),negative values to the left. Drivers should interpret the values as arcseconds, with valid values between -180 * 3600 and +180 * 3600inclusive. | |||||||||||
V4L2_CID_TILT_ABSOLUTE
|
integer | ||||||||||
This controlturns the camera vertically to the specified position. Positive valuesmove the camera up, negative values down. Drivers should interpret thevalues as arc seconds, with valid values between -180 * 3600 and +180* 3600 inclusive. | |||||||||||
V4L2_CID_FOCUS_ABSOLUTE
|
integer | ||||||||||
This control sets thefocal point of the camera to the specified position. The unit isundefined. Positive values set the focus closer to the camera,negative values towards infinity. | |||||||||||
V4L2_CID_FOCUS_RELATIVE
|
integer | ||||||||||
This control moves thefocal point of the camera by the specified amount. The unit isundefined. Positive values move the focus closer to the camera,negative values towards infinity. | |||||||||||
V4L2_CID_FOCUS_AUTO
|
boolean | ||||||||||
Enables automatic focusadjustments. The effect of manual focus adjustments while this featureis enabled is undefined, drivers should ignore such requests. | |||||||||||
1.10. Data Formats
1.10.1. Data Format Negotiation
The VIDIOC_S_FMT
ioctl is a majorturning-point in the initialization sequence. Prior to this pointmultiple panel applications can access the same device concurrently toselect the current input, change controls or modify other properties.The first VIDIOC_S_FMT
assigns a logical stream(video data, VBI data etc.) exclusively to one file descriptor.
Exclusive means no other application, more precisely noother file descriptor, can grab this stream or change deviceproperties inconsistent with the negotiated parameters. A videostandard change for example, when the new standard uses a differentnumber of scan lines, can invalidate the selected image format.Therefore only the file descriptor owning the stream can makeinvalidating changes. Accordingly multiple file descriptors whichgrabbed different logical streams prevent each other from interferingwith their settings. When for example video overlay is about to startor already in progress, simultaneous video capturing may be restrictedto the same cropping and image size.
When applications omit theVIDIOC_S_FMT
ioctl its locking side effects areimplied by the next step, the selection of an I/O method with theVIDIOC_REQBUFS
ioctl or implicit with the first read()
orwrite()
call.
Generally only one logical stream can be assigned to afile descriptor, the exception being drivers permitting simultaneousvideo capturing and overlay using the same file descriptor forcompatibility with V4L and earlier versions of V4L2. Switching thelogical stream or returning into "panel mode" is possible by closingand reopening the device. Driversmay support aswitch usingVIDIOC_S_FMT
.
All drivers exchanging data withapplications must support the VIDIOC_G_FMT
andVIDIOC_S_FMT
ioctl. Implementation of theVIDIOC_TRY_FMT
is highly recommended butoptional.
1.10.2. Image Format Enumeration
The VIDIOC_ENUM_FMT
ioctl must be supportedby all drivers exchanging image data with applications.
Important: Drivers are not supposed to convert image formats inkernel space. They must enumerate only formats directly supported bythe hardware. If necessary driver writers should publish an exampleconversion routine or library for integration into applications.
1.11. Image Cropping, Insertion and Scaling
Scaling requires a source and a target. On a video captureor overlay device the source is the video signal, and the croppingioctls determine the area actually sampled. The target are imagesread by the application or overlaid onto the graphics screen. Theirsize (and position for an overlay) is negotiated with theVIDIOC_G_FMT
andVIDIOC_S_FMT
ioctls.
On a video output device the source are the images passed inby the application, and their size is again negotiated with theVIDIOC_G/S_FMT
ioctls, or may be encoded in acompressed video stream. The target is the video signal, and thecropping ioctls determine the area where the images areinserted.
Source and target rectangles are defined even if the devicedoes not support scaling or theVIDIOC_G/S_CROP
ioctls. Their size (and position where applicable) will be fixed inthis case.All capture and output device must support theVIDIOC_CROPCAP
ioctl such that applications candetermine if scaling takes place.
1.11.1. Cropping Structures
Figure 1-1. Image Cropping, Insertion and Scaling
For capture devices the coordinates of the top leftcorner, width and height of the area which can be sampled is given bythebounds
substructure of thestruct v4l2_cropcap returned by theVIDIOC_CROPCAP
ioctl. To support a wide range of hardware this specification does notdefine an origin or units. However by convention drivers shouldhorizontally count unscaled samples relative to 0H (the leading edgeof the horizontal sync pulse, see Figure 4-1).Vertically ITU-R linenumbers of the first field (Figure 4-2,Figure 4-3), multiplied by two if the driver can capture bothfields.
The top left corner, width and height of the sourcerectangle, that is the area actually sampled, is given by struct v4l2_cropusing the same coordinate system as struct v4l2_cropcap. Applications canuse the VIDIOC_G_CROP
andVIDIOC_S_CROP
ioctls to get and set thisrectangle. It must lie completely within the capture boundaries andthe driver may further adjust the requested size and/or positionaccording to hardware limitations.
Each capture device has a default source rectangle, givenby the defrect
substructure ofstruct v4l2_cropcap. The center of this rectangle shall align with thecenter of the active picture area of the video signal, and cover whatthe driver writer considers the complete picture. Drivers shall resetthe source rectangle to the default when the driver is first loaded,but not later.
For output devices these structures and ioctls are usedaccordingly, defining thetarget rectangle wherethe images will be inserted into the video signal.
1.11.3. Examples
Example 1-10. Resetting the cropping parameters
(A video capture device is assumed; changeV4L2_BUF_TYPE_VIDEO_CAPTURE
for otherdevices.)
struct v4l2_cropcap cropcap; struct v4l2_crop crop;memset (&cropcap, 0, sizeof (cropcap)); cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) {perror ("VIDIOC_CROPCAP");exit (EXIT_FAILURE); }memset (&crop, 0, sizeof (crop)); crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; crop.c = cropcap.defrect; /* Ignore if cropping is not supported (EINVAL). */if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop)&& errno != EINVAL) {perror ("VIDIOC_S_CROP");exit (EXIT_FAILURE); }
Example 1-11. Simple downscaling
(A video capture device is assumed.)
struct v4l2_cropcap cropcap; struct v4l2_format format;reset_cropping_parameters ();/* Scale down to 1/4 size of full picture. */memset (&format, 0, sizeof (format)); /* defaults */format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;format.fmt.pix.width = cropcap.defrect.width >> 1; format.fmt.pix.height = cropcap.defrect.height >> 1; format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;if (-1 == ioctl (fd, VIDIOC_S_FMT, &format)) {perror ("VIDIOC_S_FORMAT");exit (EXIT_FAILURE); }/* We could check the actual image size now, the actual scaling factoror if the driver can scale at all. */
Example 1-12. Selecting an output area
struct v4l2_cropcap cropcap; struct v4l2_crop crop;memset (&cropcap, 0, sizeof (cropcap)); cropcap.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) {perror ("VIDIOC_CROPCAP");exit (EXIT_FAILURE); }memset (&crop, 0, sizeof (crop));crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; crop.c = cropcap.defrect;/* Scale the width and height to 50 % of their original sizeand center the output. */crop.c.width /= 2; crop.c.height /= 2; crop.c.left += crop.c.width / 2; crop.c.top += crop.c.height / 2;/* Ignore if cropping is not supported (EINVAL). */if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop)&& errno != EINVAL) {perror ("VIDIOC_S_CROP");exit (EXIT_FAILURE); }
Example 1-13. Current scaling factor and pixel aspect
(A video capture device is assumed.)
struct v4l2_cropcap cropcap; struct v4l2_crop crop; struct v4l2_format format; double hscale, vscale; double aspect; int dwidth, dheight;memset (&cropcap, 0, sizeof (cropcap)); cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) {perror ("VIDIOC_CROPCAP");exit (EXIT_FAILURE); }memset (&crop, 0, sizeof (crop)); crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == ioctl (fd, VIDIOC_G_CROP, &crop)) {if (errno != EINVAL) {perror ("VIDIOC_G_CROP");exit (EXIT_FAILURE);}/* Cropping not supported. */crop.c = cropcap.defrect; }memset (&format, 0, sizeof (format)); format.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == ioctl (fd, VIDIOC_G_FMT, &format)) {perror ("VIDIOC_G_FMT");exit (EXIT_FAILURE); }/* The scaling applied by the driver. */hscale = format.fmt.pix.width / (double) crop.c.width; vscale = format.fmt.pix.height / (double) crop.c.height;aspect = cropcap.pixelaspect.numerator /(double) cropcap.pixelaspect.denominator; aspect = aspect * hscale / vscale;/* Devices following ITU-R BT.601 do not capturesquare pixels. For playback on a computer monitorwe should scale the images to this size. */dwidth = format.fmt.pix.width / aspect; dheight = format.fmt.pix.height;
Chapter 2. Image Formats
Table 2-1. struct v4l2_pix_format
__u32 |
width
|
Image width in pixels. |
__u32 |
height
|
Image height in pixels. |
Applications set these fields torequest an image size, drivers return the closest possible values. Incase of planar formats thewidth andheight applies to the largest plane. Toavoid ambiguities drivers must return values rounded up to a multipleof the scale factor of any smaller planes. For example when the imageformat is YUV 4:2:0,width andheight must be multiples of two.
|
||
__u32 |
pixelformat
|
The pixel format or type of compression, set by theapplication. This is a little endianfour character code. V4L2 definesstandard RGB formats inTable 2-1, YUV formats inSection 2.5, and reserved codes inTable 2-8 |
enum v4l2_field |
field
|
Video images are typically interlaced. Applicationscan request to capture or output only the top or bottom field, or bothfields interlaced or sequentially stored in one buffer or alternatingin separate buffers. Drivers return the actual field order selected.For details see Section 3.6. |
__u32 |
bytesperline
|
Distance in bytes between the leftmost pixels in twoadjacent lines. |
Both applications and driverscan set this field to request padding bytes at the end of each line.Drivers however may ignore the value requested by the application,returning Video hardware may access padding bytes,therefore they must reside in accessible memory. Consider cases wherepadding bytes after the last line of an image cross a system pageboundary. Input devices may write padding bytes, the value isundefined. Output devices ignore the contents of paddingbytes. When the image format is planar the |
||
__u32 |
sizeimage
|
Size in bytes of the buffer to hold a complete image,set by the driver. Usually this isbytesperline timesheight . When the image consists of variablelength compressed data this is the maximum number of bytes required tohold an image.
|
enum v4l2_colorspace |
colorspace
|
This information supplements thepixelformat and must be set by the driver,seeSection 2.2.
|
__u32 |
priv
|
Reserved for custom (driver defined) additionalinformation about formats. When not used drivers and applications mustset this field to zero. |
2.2. Colorspaces
- Gamma Correction
-
[to do]
E'R = f(R)
E'G = f(G)
E'B = f(B)
- Construction of luminance and color-differencesignals
-
[to do]
E'Y =CoeffR E'R+ CoeffG E'G+ CoeffB E'B
(E'R - E'Y) = E'R- CoeffR E'R- CoeffG E'G- CoeffB E'B
(E'B - E'Y) = E'B- CoeffR E'R- CoeffG E'G- CoeffB E'B
- Re-normalized color-difference signals
-
The color-difference signals are scaled back to unityrange [-0.5;+0.5]:
KB = 0.5 / (1 - CoeffB)
KR = 0.5 / (1 - CoeffR)
PB =KB (E'B - E'Y) = 0.5 (CoeffR / CoeffB) E'R+ 0.5 (CoeffG / CoeffB) E'G+ 0.5 E'B
PR =KR (E'R - E'Y) = 0.5 E'R+ 0.5 (CoeffG / CoeffR) E'G+ 0.5 (CoeffB / CoeffR) E'B
- Quantization
-
[to do]
Y' = (Lum. Levels - 1) · E'Y + Lum. Offset
CB = (Chrom. Levels - 1)· PB + Chrom. Offset
CR = (Chrom. Levels - 1)· PR + Chrom. Offset
Rounding to the nearest integer and clamping to the range[0;255] finally yields the digital color components Y'CbCrstored in YUV images.
Example 2-1. ITU-R Rec. BT.601 color conversion
Forward Transformation
int ER, EG, EB; /* gamma corrected RGB input [0;255] */ int Y1, Cb, Cr; /* output [0;255] */double r, g, b; /* temporaries */ double y1, pb, pr;int clamp (double x) {int r = x; /* round to nearest */if (r < 0) return 0;else if (r > 255) return 255;else return r; }r = ER / 255.0; g = EG / 255.0; b = EB / 255.0;y1 = 0.299 * r + 0.587 * g + 0.114 * b; pb = -0.169 * r - 0.331 * g + 0.5 * b; pr = 0.5 * r - 0.419 * g - 0.081 * b;Y1 = clamp (219 * y1 + 16); Cb = clamp (224 * pb + 128); Cr = clamp (224 * pr + 128);/* or shorter */y1 = 0.299 * ER + 0.587 * EG + 0.114 * EB;Y1 = clamp ( (219 / 255.0) * y1 + 16); Cb = clamp (((224 / 255.0) / (2 - 2 * 0.114)) * (EB - y1) + 128); Cr = clamp (((224 / 255.0) / (2 - 2 * 0.299)) * (ER - y1) + 128);
Inverse Transformation
int Y1, Cb, Cr; /* gamma pre-corrected input [0;255] */ int ER, EG, EB; /* output [0;255] */double r, g, b; /* temporaries */ double y1, pb, pr;int clamp (double x) {int r = x; /* round to nearest */if (r < 0) return 0;else if (r > 255) return 255;else return r; }y1 = (255 / 219.0) * (Y1 - 16); pb = (255 / 224.0) * (Cb - 128); pr = (255 / 224.0) * (Cr - 128);r = 1.0 * y1 + 0 * pb + 1.402 * pr; g = 1.0 * y1 - 0.344 * pb - 0.714 * pr; b = 1.0 * y1 + 1.772 * pb + 0 * pr;ER = clamp (r * 255); /* [ok? one should prob. limit y1,pb,pr] */ EG = clamp (g * 255); EB = clamp (b * 255);
Table 2-2. enum v4l2_colorspace
Identifier | Value | Description | Chromaticities[a] | White Point | Gamma Correction | Luminance E'Y | Quantization | |||
---|---|---|---|---|---|---|---|---|---|---|
Red | Green | Blue | Y' | Cb, Cr | ||||||
V4L2_COLORSPACE_SMPTE170M
|
1 | NTSC/PAL according toSMPTE 170M,ITU BT.601 | x = 0.630, y = 0.340 | x = 0.310, y = 0.595 | x = 0.155, y = 0.070 | x = 0.3127, y = 0.3290, Illuminant D65 | E' = 4.5 I for I ≤0.018,1.099 I0.45 - 0.099 for 0.018 < I | 0.299 E'R+ 0.587 E'G+ 0.114 E'B | 219 E'Y + 16 | 224 PB,R + 128 |
V4L2_COLORSPACE_SMPTE240M
|
2 | 1125-Line (US) HDTV, see SMPTE 240M | x = 0.630, y = 0.340 | x = 0.310, y = 0.595 | x = 0.155, y = 0.070 | x = 0.3127, y = 0.3290, Illuminant D65 | E' = 4 I for I ≤0.0228,1.1115 I0.45 - 0.1115 for 0.0228 < I | 0.212 E'R+ 0.701 E'G+ 0.087 E'B | 219 E'Y + 16 | 224 PB,R + 128 |
V4L2_COLORSPACE_REC709
|
3 | HDTV and modern devices, see ITU BT.709 | x = 0.640, y = 0.330 | x = 0.300, y = 0.600 | x = 0.150, y = 0.060 | x = 0.3127, y = 0.3290, Illuminant D65 | E' = 4.5 I for I ≤0.018,1.099 I0.45 - 0.099 for 0.018 < I | 0.2125 E'R+ 0.7154 E'G+ 0.0721 E'B | 219 E'Y + 16 | 224 PB,R + 128 |
V4L2_COLORSPACE_BT878
|
4 | Broken Bt878 extents[b],ITU BT.601 | ? | ? | ? | ? | ? | 0.299 E'R+ 0.587 E'G+ 0.114 E'B | 237 E'Y + 16 | 224 PB,R + 128 (probably) |
V4L2_COLORSPACE_470_SYSTEM_M
|
5 | M/NTSC[c] according toITU BT.470,ITU BT.601 | x = 0.67, y = 0.33 | x = 0.21, y = 0.71 | x = 0.14, y = 0.08 | x = 0.310, y = 0.316, Illuminant C | ? | 0.299 E'R+ 0.587 E'G+ 0.114 E'B | 219 E'Y + 16 | 224 PB,R + 128 |
V4L2_COLORSPACE_470_SYSTEM_BG
|
6 | 625-line PAL and SECAM systems according toITU BT.470, ITU BT.601 | x = 0.64, y = 0.33 | x = 0.29, y = 0.60 | x = 0.15, y = 0.06 | x = 0.313, y = 0.329,Illuminant D65 | ? | 0.299 E'R+ 0.587 E'G+ 0.114 E'B | 219 E'Y + 16 | 224 PB,R + 128 |
V4L2_COLORSPACE_JPEG
|
7 | JPEG Y'CbCr, see JFIF,ITU BT.601 | ? | ? | ? | ? | ? | 0.299 E'R+ 0.587 E'G+ 0.114 E'B | 256 E'Y + 16[d] | 256 PB,R + 128 |
V4L2_COLORSPACE_SRGB
|
8 | [?] | x = 0.640, y = 0.330 | x = 0.300, y = 0.600 | x = 0.150, y = 0.060 | x = 0.3127, y = 0.3290, Illuminant D65 | E' = 4.5 I for I ≤0.018,1.099 I0.45 - 0.099 for 0.018 < I | n/a | ||
Notes: a. The coordinates of the color primaries aregiven in the CIE system (1931) b. The ubiquitous Bt878 video capture chipquantizes E'Y to 238 levels, yielding a rangeof Y' = 16 … 253, unlike Rec. 601 Y' = 16 …235. This is not a typo in the Bt878 documentation, it has beenimplemented in silicon. The chroma extents are unclear. c. No identifier exists for M/PAL which usesthe chromaticities of M/NTSC, the remaining parameters are equal to B andG/PAL. d. Note JFIF quantizesY'PBPR in range [0;+1] and[-0.5;+0.5] to257 levels, however Y'CbCr signalsare still clamped to [0;255]. |
2.3. Indexed Format
Table 2-3. Indexed Image Format
Identifier | Code | Byte 0 | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||||||||||||||||||||||||||||
V4L2_PIX_FMT_PAL8
|
'PAL8' | i7 | i6 | i5 | i4 | i3 | i2 | i1 | i0 |
2.4. RGB Formats
- Table of ContentsPacked RGB formats -- Packed RGB formatsV4L2_PIX_FMT_SBGGR8 ('BA81') -- Bayer RGB formatV4L2_PIX_FMT_SBGGR16 ('BA82') -- Bayer RGB format
Packed RGB formats
Name
Packed RGB formats -- Packed RGB formats
Description
These formats are designed to match the pixel formats oftypical PC graphics frame buffers. They occupy 8, 16, 24 or 32 bitsper pixel. These are all packed-pixel formats, meaning all the datafor a pixel lie next to each other in memory.
When one of these formats is used, drivers shall report thecolorspace V4L2_COLORSPACE_SRGB
.
Table 2-1. Packed RGB Image Formats
Identifier | Code | Byte 0 in memory | Byte 1 | Byte 2 | Byte 3 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |||||
V4L2_PIX_FMT_RGB332
|
'RGB1' | b1 | b0 | g2 | g1 | g0 | r2 | r1 | r0 | ||||||||||||||||||||||||||||
V4L2_PIX_FMT_RGB444
|
'R444' | g3 | g2 | g1 | g0 | b3 | b2 | b1 | b0 | a3 | a2 | a1 | a0 | r3 | r2 | r1 | r0 | ||||||||||||||||||||
V4L2_PIX_FMT_RGB555
|
'RGBO' | g2 | g1 | g0 | r4 | r3 | r2 | r1 | r0 | a | b4 | b3 | b2 | b1 | b0 | g4 | g3 | ||||||||||||||||||||
V4L2_PIX_FMT_RGB565
|
'RGBP' | g2 | g1 | g0 | r4 | r3 | r2 | r1 | r0 | b4 | b3 | b2 | b1 | b0 | g5 | g4 | g3 | ||||||||||||||||||||
V4L2_PIX_FMT_RGB555X
|
'RGBQ' | a | b4 | b3 | b2 | b1 | b0 | g4 | g3 | g2 | g1 | g0 | r4 | r3 | r2 | r1 | r0 | ||||||||||||||||||||
V4L2_PIX_FMT_RGB565X
|
'RGBR' | b4 | b3 | b2 | b1 | b0 | g5 | g4 | g3 | g2 | g1 | g0 | r4 | r3 | r2 | r1 | r0 | ||||||||||||||||||||
V4L2_PIX_FMT_BGR24
|
'BGR3' | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | g7 | g6 | g5 | g4 | g3 | g2 | g1 | g0 | r7 | r6 | r5 | r4 | r3 | r2 | r1 | r0 | ||||||||||||
V4L2_PIX_FMT_RGB24
|
'RGB3' | r7 | r6 | r5 | r4 | r3 | r2 | r1 | r0 | g7 | g6 | g5 | g4 | g3 | g2 | g1 | g0 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | ||||||||||||
V4L2_PIX_FMT_BGR32
|
'BGR4' | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | g7 | g6 | g5 | g4 | g3 | g2 | g1 | g0 | r7 | r6 | r5 | r4 | r3 | r2 | r1 | r0 | a7 | a6 | a5 | a4 | a3 | a2 | a1 | a0 | ||||
V4L2_PIX_FMT_RGB32
|
'RGB4' | r7 | r6 | r5 | r4 | r3 | r2 | r1 | r0 | g7 | g6 | g5 | g4 | g3 | g2 | g1 | g0 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | a7 | a6 | a5 | a4 | a3 | a2 | a1 | a0 |
Bit 7 is the most significant bit. The value of a = alphabits is undefined when reading from the driver, ignored when writingto the driver, except when alpha blending has been negotiated for aVideo Overlay or Video Output Overlay.
Example 2-1. V4L2_PIX_FMT_BGR24
4 × 4 pixelimage
Byte Order. Each cell is one byte.
start + 0: | B00 | G00 | R00 | B01 | G01 | R01 | B02 | G02 | R02 | B03 | G03 | R03 |
start + 12: | B10 | G10 | R10 | B11 | G11 | R11 | B12 | G12 | R12 | B13 | G13 | R13 |
start + 24: | B20 | G20 | R20 | B21 | G21 | R21 | B22 | G22 | R22 | B23 | G23 | R23 |
start + 36: | B30 | G30 | R30 | B31 | G31 | R31 | B32 | G32 | R32 | B33 | G33 | R33 |
Important: Drivers may interpret these formats differently.
Some RGB formats above are uncommon and were probablydefined in error. Drivers may interpret them as inTable 2-2.
Table 2-2. Packed RGB Image Formats (corrected)
Identifier | Code | Byte 0 in memory | Byte 1 | Byte 2 | Byte 3 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |||||
V4L2_PIX_FMT_RGB332
|
'RGB1' | r2 | r1 | r0 | g2 | g1 | g0 | b1 | b0 | ||||||||||||||||||||||||||||
V4L2_PIX_FMT_RGB444
|
'R444' | g3 | g2 | g1 | g0 | b3 | b2 | b1 | b0 | a3 | a2 | a1 | a0 | r3 | r2 | r1 | r0 | ||||||||||||||||||||
V4L2_PIX_FMT_RGB555
|
'RGBO' | g2 | g1 | g0 | b4 | b3 | b2 | b1 | b0 | a | r4 | r3 | r2 | r1 | r0 | g4 | g3 | ||||||||||||||||||||
V4L2_PIX_FMT_RGB565
|
'RGBP' | g2 | g1 | g0 | b4 | b3 | b2 | b1 | b0 | r4 | r3 | r2 | r1 | r0 | g5 | g4 | g3 | ||||||||||||||||||||
V4L2_PIX_FMT_RGB555X
|
'RGBQ' | a | r4 | r3 | r2 | r1 | r0 | g4 | g3 | g2 | g1 | g0 | b4 | b3 | b2 | b1 | b0 | ||||||||||||||||||||
V4L2_PIX_FMT_RGB565X
|
'RGBR' | r4 | r3 | r2 | r1 | r0 | g5 | g4 | g3 | g2 | g1 | g0 | b4 | b3 | b2 | b1 | b0 | ||||||||||||||||||||
V4L2_PIX_FMT_BGR24
|
'BGR3' | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | g7 | g6 | g5 | g4 | g3 | g2 | g1 | g0 | r7 | r6 | r5 | r4 | r3 | r2 | r1 | r0 | ||||||||||||
V4L2_PIX_FMT_RGB24
|
'RGB3' | r7 | r6 | r5 | r4 | r3 | r2 | r1 | r0 | g7 | g6 | g5 | g4 | g3 | g2 | g1 | g0 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | ||||||||||||
V4L2_PIX_FMT_BGR32
|
'BGR4' | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 | g7 | g6 | g5 | g4 | g3 | g2 | g1 | g0 | r7 | r6 | r5 | r4 | r3 | r2 | r1 | r0 | a7 | a6 | a5 | a4 | a3 | a2 | a1 | a0 | ||||
V4L2_PIX_FMT_RGB32
|
'RGB4' | a7 | a6 | a5 | a4 | a3 | a2 | a1 | a0 | r7 | r6 | r5 | r4 | r3 | r2 | r1 | r0 | g7 | g6 | g5 | g4 | g3 | g2 | g1 | g0 | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
A test utility to determine which RGB formats a driveractually supports is available from the LinuxTV v4l-dvb repository.Seehttp://linuxtv.org/repo/ for access instructions.
V4L2_PIX_FMT_SBGGR8 ('BA81')
Name
V4L2_PIX_FMT_SBGGR8
-- Bayer RGB format
Description
This is commonly the native format of digital cameras,reflecting the arrangement of sensors on the CCD device. Only one red,green or blue value is given for each pixel. Missing components mustbe interpolated from neighbouring pixels. From left to right the firstrow consists of a blue and green value, the second row of a green andred value. This scheme repeats to the right and down for every twocolumns and rows.
Example 2-1. V4L2_PIX_FMT_SBGGR8
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | B00 | G01 | B02 | G03 |
start + 4: | G10 | R11 | G12 | R13 |
start + 8: | B20 | G21 | B22 | G23 |
start + 12: | G30 | R31 | G32 | R33 |
V4L2_PIX_FMT_SBGGR16 ('BA82')
Name
V4L2_PIX_FMT_SBGGR16
-- Bayer RGB format
Description
This format is similar to V4L2_PIX_FMT_SBGGR8
, except each pixel hasa depth of 16 bits. The least significant byte is stored at lowermemory addresses (little-endian). Note the actual sampling precisionmay be lower than 16 bits, for example 10 bits per pixel with valuesin range 0 to 1023.
Example 2-1. V4L2_PIX_FMT_SBGGR16
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | B00low | B00high | G01low | G01high | B02low | B02high | G03low | G03high |
start + 8: | G10low | G10high | R11low | R11high | G12low | G12high | R13low | R13high |
start + 16: | B20low | B20high | G21low | G21high | B22low | B22high | G23low | G23high |
start + 24: | G30low | G30high | R31low | R31high | G32low | G32high | R33low | R33high |
2.5. YUV Formats
-
Table of ContentsPacked YUV formats -- Packed YUV formatsV4L2_PIX_FMT_GREY ('GREY') -- Grey-scale imageV4L2_PIX_FMT_Y16 ('Y16 ') -- Grey-scale imageV4L2_PIX_FMT_YUYV ('YUYV') -- Packed format with ½ horizontal chromaresolution, also known as YUV 4:2:2V4L2_PIX_FMT_UYVY ('UYVY') -- Variation of
V4L2_PIX_FMT_YUYV
with different order of samplesin memoryV4L2_PIX_FMT_Y41P ('Y41P') -- Format with ¼ horizontal chromaresolution, also known as YUV 4:1:1V4L2_PIX_FMT_YVU420 ('YV12'), V4L2_PIX_FMT_YUV420 ('YU12') -- Planar formats with ½ horizontal andvertical chroma resolution, also known as YUV 4:2:0V4L2_PIX_FMT_YVU410 ('YVU9'), V4L2_PIX_FMT_YUV410 ('YUV9') -- Planar formats with ¼ horizontal andvertical chroma resolution, also known as YUV 4:1:0V4L2_PIX_FMT_YUV422P ('422P') -- Format with ½ horizontal chroma resolution,also known as YUV 4:2:2. Planar layout as opposed toV4L2_PIX_FMT_YUYV
V4L2_PIX_FMT_YUV411P ('411P') -- Format with ¼ horizontal chroma resolution,also known as YUV 4:1:1. Planar layout as opposed toV4L2_PIX_FMT_Y41P
V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21') -- Formats with ½ horizontal and verticalchroma resolution, also known as YUV 4:2:0. One luminance and onechrominance plane with alternating chroma samples as opposed toV4L2_PIX_FMT_YVU420
YUV is the format native to TV broadcast and composite videosignals. It separates the brightness information (Y) from the colorinformation (U and V or Cb and Cr). The color information consists ofred and bluecolor difference signals, this waythe green component can be reconstructed by subtracting from thebrightness component. SeeSection 2.2 for conversionexamples. YUV was chosen because early television would only transmitbrightness information. To add color in a way compatible with existingreceivers a new signal carrier was added to transmit the colordifference signals. Secondary in the YUV format the U and V componentsusually have lower resolution than the Y component. This is an analogvideo compression technique taking advantage of a property of thehuman visual system, being more sensitive to brightnessinformation.
Packed YUV formats
Name
Packed YUV formats -- Packed YUV formats
Description
Similar to the packed RGB formats these formats storethe Y, Cb and Cr component of each pixel in one 16 or 32 bitword.
Table 2-1. Packed YUV Image Formats
Identifier | Code | Byte 0 in memory | Byte 1 | Byte 2 | Byte 3 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |||||
V4L2_PIX_FMT_YUV444
|
'Y444' | Cb3 | Cb2 | Cb1 | Cb0 | Cr3 | Cr2 | Cr1 | Cr0 | a3 | a2 | a1 | a0 | Y'3 | Y'2 | Y'1 | Y'0 | ||||||||||||||||||||
V4L2_PIX_FMT_YUV555
|
'YUVO' | Cb2 | Cb1 | Cb0 | Cr4 | Cr3 | Cr2 | Cr1 | Cr0 | a | Y'4 | Y'3 | Y'2 | Y'1 | Y'0 | Cb4 | Cb3 | ||||||||||||||||||||
V4L2_PIX_FMT_YUV565
|
'YUVP' | Cb2 | Cb1 | Cb0 | Cr4 | Cr3 | Cr2 | Cr1 | Cr0 | Y'4 | Y'3 | Y'2 | Y'1 | Y'0 | Cb5 | Cb4 | Cb3 | ||||||||||||||||||||
V4L2_PIX_FMT_YUV32
|
'YUV4' | a7 | a6 | a5 | a4 | a3 | a2 | a1 | a0 | Y'7 | Y'6 | Y'5 | Y'4 | Y'3 | Y'2 | Y'1 | Y'0 | Cb7 | Cb6 | Cb5 | Cb4 | Cb3 | Cb2 | Cb1 | Cb0 | Cr7 | Cr6 | Cr5 | Cr4 | Cr3 | Cr2 | Cr1 | Cr0 |
Bit 7 is the most significant bit. The value of a = alphabits is undefined when reading from the driver, ignored when writingto the driver, except when alpha blending has been negotiated for aVideo Overlay or Video Output Overlay.
V4L2_PIX_FMT_GREY ('GREY')
Name
V4L2_PIX_FMT_GREY
-- Grey-scale image
Description
This is a grey-scale image. It is really a degenerateY'CbCr format which simply contains no Cb or Cr data.
Example 2-1. V4L2_PIX_FMT_GREY
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Y'00 | Y'01 | Y'02 | Y'03 |
start + 4: | Y'10 | Y'11 | Y'12 | Y'13 |
start + 8: | Y'20 | Y'21 | Y'22 | Y'23 |
start + 12: | Y'30 | Y'31 | Y'32 | Y'33 |
V4L2_PIX_FMT_Y16 ('Y16 ')
Name
V4L2_PIX_FMT_Y16
-- Grey-scale image
Description
This is a grey-scale image with a depth of 16 bits perpixel. The least significant byte is stored at lower memory addresses(little-endian). Note the actual sampling precision may be lower than16 bits, for example 10 bits per pixel with values in range 0 to1023.
Example 2-1. V4L2_PIX_FMT_Y16
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Y'00low | Y'00high | Y'01low | Y'01high | Y'02low | Y'02high | Y'03low | Y'03high |
start + 8: | Y'10low | Y'10high | Y'11low | Y'11high | Y'12low | Y'12high | Y'13low | Y'13high |
start + 16: | Y'20low | Y'20high | Y'21low | Y'21high | Y'22low | Y'22high | Y'23low | Y'23high |
start + 24: | Y'30low | Y'30high | Y'31low | Y'31high | Y'32low | Y'32high | Y'33low | Y'33high |
V4L2_PIX_FMT_YUYV ('YUYV')
Name
V4L2_PIX_FMT_YUYV
-- Packed format with ½ horizontal chromaresolution, also known as YUV 4:2:2
Description
In this format each four bytes is two pixels. Each fourbytes is two Y's, a Cb and a Cr. Each Y goes to one of the pixels, andthe Cb and Cr belong to both pixels. As you can see, the Cr and Cbcomponents have half the horizontal resolution of the Y component.V4L2_PIX_FMT_YUYV
is known in the Windowsenvironment as YUY2.
Example 2-1. V4L2_PIX_FMT_YUYV
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Y'00 | Cb00 | Y'01 | Cr00 | Y'02 | Cb01 | Y'03 | Cr01 |
start + 8: | Y'10 | Cb10 | Y'11 | Cr10 | Y'12 | Cb11 | Y'13 | Cr11 |
start + 16: | Y'20 | Cb20 | Y'21 | Cr20 | Y'22 | Cb21 | Y'23 | Cr21 |
start + 24: | Y'30 | Cb30 | Y'31 | Cr30 | Y'32 | Cb31 | Y'33 | Cr31 |
Color Sample Location.
0 | 1 | 2 | 3 | ||||
0 | Y | C | Y | Y | C | Y | |
1 | Y | C | Y | Y | C | Y | |
2 | Y | C | Y | Y | C | Y | |
3 | Y | C | Y | Y | C | Y |
V4L2_PIX_FMT_UYVY ('UYVY')
Name
V4L2_PIX_FMT_UYVY
-- Variation ofV4L2_PIX_FMT_YUYV
with different order of samplesin memory
Description
In this format each four bytes is two pixels. Each fourbytes is two Y's, a Cb and a Cr. Each Y goes to one of the pixels, andthe Cb and Cr belong to both pixels. As you can see, the Cr and Cbcomponents have half the horizontal resolution of the Ycomponent.
Example 2-1. V4L2_PIX_FMT_UYVY
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Cb00 | Y'00 | Cr00 | Y'01 | Cb01 | Y'02 | Cr01 | Y'03 |
start + 8: | Cb10 | Y'10 | Cr10 | Y'11 | Cb11 | Y'12 | Cr11 | Y'13 |
start + 16: | Cb20 | Y'20 | Cr20 | Y'21 | Cb21 | Y'22 | Cr21 | Y'23 |
start + 24: | Cb30 | Y'30 | Cr30 | Y'31 | Cb31 | Y'32 | Cr31 | Y'33 |
Color Sample Location.
0 | 1 | 2 | 3 | ||||
0 | Y | C | Y | Y | C | Y | |
1 | Y | C | Y | Y | C | Y | |
2 | Y | C | Y | Y | C | Y | |
3 | Y | C | Y | Y | C | Y |
V4L2_PIX_FMT_Y41P ('Y41P')
Name
V4L2_PIX_FMT_Y41P
-- Format with ¼ horizontal chromaresolution, also known as YUV 4:1:1
Description
In this format each 12 bytes is eight pixels. In thetwelve bytes are two CbCr pairs and eight Y's. The first CbCr pairgoes with the first four Y's, and the second CbCr pair goes with theother four Y's. The Cb and Cr components have one fourth thehorizontal resolution of the Y component.
Do not confuse this format with V4L2_PIX_FMT_YUV411P
. Y41P is derived from "YUV 4:1:1packed", whileYUV411P stands for "YUV 4:1:1planar".
Example 2-1. V4L2_PIX_FMT_Y41P
8 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Cb00 | Y'00 | Cr00 | Y'01 | Cb01 | Y'02 | Cr01 | Y'03 | Y'04 | Y'05 | Y'06 | Y'07 |
start + 12: | Cb10 | Y'10 | Cr10 | Y'11 | Cb11 | Y'12 | Cr11 | Y'13 | Y'14 | Y'15 | Y'16 | Y'17 |
start + 24: | Cb20 | Y'20 | Cr20 | Y'21 | Cb21 | Y'22 | Cr21 | Y'23 | Y'24 | Y'25 | Y'26 | Y'27 |
start + 36: | Cb30 | Y'30 | Cr30 | Y'31 | Cb31 | Y'32 | Cr31 | Y'33 | Y'34 | Y'35 | Y'36 | Y'37 |
Color Sample Location.
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ||||||||
0 | Y | Y | C | Y | Y | Y | Y | C | Y | Y | |||||
1 | Y | Y | C | Y | Y | Y | Y | C | Y | Y | |||||
2 | Y | Y | C | Y | Y | Y | Y | C | Y | Y | |||||
3 | Y | Y | C | Y | Y | Y | Y | C | Y | Y |
V4L2_PIX_FMT_YVU420 ('YV12'), V4L2_PIX_FMT_YUV420 ('YU12')
Name
V4L2_PIX_FMT_YVU420
, V4L2_PIX_FMT_YUV420
-- Planar formats with ½ horizontal andvertical chroma resolution, also known as YUV 4:2:0
Description
These are planar formats, as opposed to a packed format.The three components are separated into three sub- images or planes.The Y plane is first. The Y plane has one byte per pixel. ForV4L2_PIX_FMT_YVU420
, the Cr plane immediatelyfollows the Y plane in memory. The Cr plane is half the width and halfthe height of the Y plane (and of the image). Each Cr belongs to fourpixels, a two-by-two square of the image. For example,Cr0 belongs to Y'00,Y'01, Y'10, andY'11. Following the Cr plane is the Cb plane,just like the Cr plane.V4L2_PIX_FMT_YUV420
isthe same except the Cb plane comes first, then the Cr plane.
If the Y plane has pad bytes after each row, then the Crand Cb planes have half as many pad bytes after their rows. In otherwords, two Cx rows (including padding) is exactly as long as one Y row(including padding).
Example 2-1. V4L2_PIX_FMT_YVU420
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Y'00 | Y'01 | Y'02 | Y'03 |
start + 4: | Y'10 | Y'11 | Y'12 | Y'13 |
start + 8: | Y'20 | Y'21 | Y'22 | Y'23 |
start + 12: | Y'30 | Y'31 | Y'32 | Y'33 |
start + 16: | Cr00 | Cr01 | ||
start + 18: | Cr10 | Cr11 | ||
start + 20: | Cb00 | Cb01 | ||
start + 22: | Cb10 | Cb11 |
Color Sample Location.
0 | 1 | 2 | 3 | ||||
0 | Y | Y | Y | Y | |||
C | C | ||||||
1 | Y | Y | Y | Y | |||
2 | Y | Y | Y | Y | |||
C | C | ||||||
3 | Y | Y | Y | Y |
V4L2_PIX_FMT_YVU410 ('YVU9'), V4L2_PIX_FMT_YUV410 ('YUV9')
Name
V4L2_PIX_FMT_YVU410
, V4L2_PIX_FMT_YUV410
-- Planar formats with ¼ horizontal andvertical chroma resolution, also known as YUV 4:1:0
Description
These are planar formats, as opposed to a packed format.The three components are separated into three sub-images or planes.The Y plane is first. The Y plane has one byte per pixel. ForV4L2_PIX_FMT_YVU410
, the Cr plane immediatelyfollows the Y plane in memory. The Cr plane is ¼ the width and¼ the height of the Y plane (and of the image). Each Cr belongsto 16 pixels, a four-by-four square of the image. Following the Crplane is the Cb plane, just like the Cr plane.V4L2_PIX_FMT_YUV410
is the same, except the Cbplane comes first, then the Cr plane.
If the Y plane has pad bytes after each row, then the Crand Cb planes have ¼ as many pad bytes after their rows. Inother words, four Cx rows (including padding) are exactly as long asone Y row (including padding).
Example 2-1. V4L2_PIX_FMT_YVU410
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Y'00 | Y'01 | Y'02 | Y'03 |
start + 4: | Y'10 | Y'11 | Y'12 | Y'13 |
start + 8: | Y'20 | Y'21 | Y'22 | Y'23 |
start + 12: | Y'30 | Y'31 | Y'32 | Y'33 |
start + 16: | Cr00 | |||
start + 17: | Cb00 |
Color Sample Location.
0 | 1 | 2 | 3 | ||||
0 | Y | Y | Y | Y | |||
1 | Y | Y | Y | Y | |||
C | |||||||
2 | Y | Y | Y | Y | |||
3 | Y | Y | Y | Y |
V4L2_PIX_FMT_YUV422P ('422P')
Name
V4L2_PIX_FMT_YUV422P
-- Format with ½ horizontal chroma resolution,also known as YUV 4:2:2. Planar layout as opposed toV4L2_PIX_FMT_YUYV
Description
This format is not commonly used. This is a planarversion of the YUYV format. The three components are separated intothree sub-images or planes. The Y plane is first. The Y plane has onebyte per pixel. The Cb plane immediately follows the Y plane inmemory. The Cb plane is half the width of the Y plane (and of theimage). Each Cb belongs to two pixels. For example,Cb0 belongs to Y'00,Y'01. Following the Cb plane is the Cr plane,just like the Cb plane.
If the Y plane has pad bytes after each row, then the Crand Cb planes have half as many pad bytes after their rows. In otherwords, two Cx rows (including padding) is exactly as long as one Y row(including padding).
Example 2-1. V4L2_PIX_FMT_YUV422P
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Y'00 | Y'01 | Y'02 | Y'03 |
start + 4: | Y'10 | Y'11 | Y'12 | Y'13 |
start + 8: | Y'20 | Y'21 | Y'22 | Y'23 |
start + 12: | Y'30 | Y'31 | Y'32 | Y'33 |
start + 16: | Cb00 | Cb01 | ||
start + 18: | Cb10 | Cb11 | ||
start + 20: | Cb20 | Cb21 | ||
start + 22: | Cb30 | Cb31 | ||
start + 24: | Cr00 | Cr01 | ||
start + 26: | Cr10 | Cr11 | ||
start + 28: | Cr20 | Cr21 | ||
start + 30: | Cr30 | Cr31 |
Color Sample Location.
0 | 1 | 2 | 3 | ||||
0 | Y | C | Y | Y | C | Y | |
1 | Y | C | Y | Y | C | Y | |
2 | Y | C | Y | Y | C | Y | |
3 | Y | C | Y | Y | C | Y |
V4L2_PIX_FMT_YUV411P ('411P')
Name
V4L2_PIX_FMT_YUV411P
-- Format with ¼ horizontal chroma resolution,also known as YUV 4:1:1. Planar layout as opposed toV4L2_PIX_FMT_Y41P
Description
This format is not commonly used. This is a planarformat similar to the 4:2:2 planar format except with half as manychroma. The three components are separated into three sub-images orplanes. The Y plane is first. The Y plane has one byte per pixel. TheCb plane immediately follows the Y plane in memory. The Cb plane is¼ the width of the Y plane (and of the image). Each Cb belongsto 4 pixels all on the same row. For example,Cb0 belongs to Y'00,Y'01, Y'02 andY'03. Following the Cb plane is the Cr plane,just like the Cb plane.
If the Y plane has pad bytes after each row, then the Crand Cb planes have ¼ as many pad bytes after their rows. Inother words, four C x rows (including padding) is exactly as long asone Y row (including padding).
Example 2-1. V4L2_PIX_FMT_YUV411P
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Y'00 | Y'01 | Y'02 | Y'03 |
start + 4: | Y'10 | Y'11 | Y'12 | Y'13 |
start + 8: | Y'20 | Y'21 | Y'22 | Y'23 |
start + 12: | Y'30 | Y'31 | Y'32 | Y'33 |
start + 16: | Cb00 | |||
start + 17: | Cb10 | |||
start + 18: | Cb20 | |||
start + 19: | Cb30 | |||
start + 20: | Cr00 | |||
start + 21: | Cr10 | |||
start + 22: | Cr20 | |||
start + 23: | Cr30 |
Color Sample Location.
0 | 1 | 2 | 3 | ||||
0 | Y | Y | C | Y | Y | ||
1 | Y | Y | C | Y | Y | ||
2 | Y | Y | C | Y | Y | ||
3 | Y | Y | C | Y | Y |
V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21')
Name
V4L2_PIX_FMT_NV12
, V4L2_PIX_FMT_NV21
-- Formats with ½ horizontal and verticalchroma resolution, also known as YUV 4:2:0. One luminance and onechrominance plane with alternating chroma samples as opposed toV4L2_PIX_FMT_YVU420
Description
These are two-plane versions of the YUV 4:2:0 format.The three components are separated into two sub-images or planes. TheY plane is first. The Y plane has one byte per pixel. ForV4L2_PIX_FMT_NV12
, a combined CbCr planeimmediately follows the Y plane in memory. The CbCr plane is the samewidth, in bytes, as the Y plane (and of the image), but is half astall in pixels. Each CbCr pair belongs to four pixels. For example,Cb0/Cr0 belongs toY'00, Y'01,Y'10, Y'11.V4L2_PIX_FMT_NV21
is the same except the Cb andCr bytes are swapped, the CrCb plane starts with a Cr byte.
If the Y plane has pad bytes after each row, then theCbCr plane has as many pad bytes after its rows.
Example 2-1. V4L2_PIX_FMT_NV12
4 × 4pixel image
Byte Order. Each cell is one byte.
start + 0: | Y'00 | Y'01 | Y'02 | Y'03 |
start + 4: | Y'10 | Y'11 | Y'12 | Y'13 |
start + 8: | Y'20 | Y'21 | Y'22 | Y'23 |
start + 12: | Y'30 | Y'31 | Y'32 | Y'33 |
start + 16: | Cb00 | Cr00 | Cb01 | Cr01 |
start + 20: | Cb10 | Cr10 | Cb11 | Cr11 |
Color Sample Location.
0 | 1 | 2 | 3 | ||||
0 | Y | Y | Y | Y | |||
C | C | ||||||
1 | Y | Y | Y | Y | |||
2 | Y | Y | Y | Y | |||
C | C | ||||||
3 | Y | Y | Y | Y |
2.6. Compressed Formats
Table 2-7. Compressed Image Formats
Identifier | Code | Details |
---|---|---|
V4L2_PIX_FMT_JPEG
|
'JPEG' |
TBD. See also VIDIOC_G_JPEGCOMP , VIDIOC_S_JPEGCOMP .
|
V4L2_PIX_FMT_MPEG
|
'MPEG' |
MPEG stream. The actual format is determined byextended controlV4L2_CID_MPEG_STREAM_TYPE , seeTable 1-2.
|
2.7. Reserved Format Identifiers
Table 2-8. Reserved Image Formats
Identifier | Code | Details |
---|---|---|
V4L2_PIX_FMT_DV
|
'dvsd' | unknown |
V4L2_PIX_FMT_ET61X251
|
'E625' | Compressed format of the ET61X251 driver. |
V4L2_PIX_FMT_HI240
|
'HI24' |
8 bit RGB format used by the BTTV driver,http://bytesex.org/bttv/ |
V4L2_PIX_FMT_HM12
|
'HM12' |
YUV 4:2:0 format used by theIVTV driver, http://www.ivtvdriver.org/ The format is documented in thekernel sources in the fileDocumentation/video4linux/cx2341x/README.hm12 |
V4L2_PIX_FMT_MJPEG
|
'MJPG' | Compressed format used by the Zoran driver |
V4L2_PIX_FMT_PWC1
|
'PWC1' | Compressed format of the PWC driver. |
V4L2_PIX_FMT_PWC2
|
'PWC2' | Compressed format of the PWC driver. |
V4L2_PIX_FMT_SN9C10X
|
'S910' | Compressed format of the SN9C102 driver. |
V4L2_PIX_FMT_WNVA
|
'WNVA' |
Used by the Winnov Videum driver, http://www.thedirks.org/winnov/ |
V4L2_PIX_FMT_YYUV
|
'YYUV' | unknown |
Chapter 3. Input/Output
Generally exactly one I/O method, including overlay, isassociated with each file descriptor. The only exceptions areapplications not exchanging data with a driver ("panel applications",seeSection 1.1) and drivers permitting simultaneous video capturingand overlay using the same file descriptor, for compatibility with V4Land earlier versions of V4L2.
VIDIOC_S_FMT
andVIDIOC_REQBUFS
would permit this to some degree,but for simplicity drivers need not support switching the I/O method(after first switching away from read/write) other than by closingand reopening the device.
The following sections describe the various I/O methods inmore detail.
3.1. Read/Write
> vidctrl /dev/video --input=0 --format=YUYV --size=352x288 > dd if=/dev/video of=myimage.422 bs=202752 count=1
To read from the device applications use theread()
function, to write thewrite()
function.Drivers must implement one I/O method if theyexchange data with applications, but it need not be this.[12] When reading or writing is supported, the drivermust also support the select()
and poll()
function.[13]
3.2. Streaming I/O (Memory Mapping)
Example 3-1. Mapping buffers
struct v4l2_requestbuffers reqbuf; struct {void *start;size_t length; } *buffers; unsigned int i;memset (&reqbuf, 0, sizeof (reqbuf)); reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.memory = V4L2_MEMORY_MMAP; reqbuf.count = 20;if (-1 == ioctl (fd, VIDIOC_REQBUFS, &reqbuf)) {if (errno == EINVAL)printf ("Video capturing or mmap-streaming is not supported\n");elseperror ("VIDIOC_REQBUFS");exit (EXIT_FAILURE); }/* We want at least five buffers. */if (reqbuf.count < 5) {/* You may need to free the buffers here. */printf ("Not enough buffer memory\n");exit (EXIT_FAILURE); }buffers = calloc (reqbuf.count, sizeof (*buffers)); assert (buffers != NULL);for (i = 0; i < reqbuf.count; i++) {struct v4l2_buffer buffer;memset (&buffer, 0, sizeof (buffer));buffer.type = reqbuf.type;buffer.memory = V4L2_MEMORY_MMAP;buffer.index = i;if (-1 == ioctl (fd, VIDIOC_QUERYBUF, &buffer)) {perror ("VIDIOC_QUERYBUF");exit (EXIT_FAILURE);}buffers[i].length = buffer.length; /* remember for munmap() */buffers[i].start = mmap (NULL, buffer.length,PROT_READ | PROT_WRITE, /* recommended */MAP_SHARED, /* recommended */fd, buffer.m.offset);if (MAP_FAILED == buffers[i].start) {/* If you do not exit here you should unmap() and free()the buffers mapped so far. */perror ("mmap");exit (EXIT_FAILURE);} }/* Cleanup. */for (i = 0; i < reqbuf.count; i++)munmap (buffers[i].start, buffers[i].length);
Conceptually streaming drivers maintain two buffer queues, an incomingand an outgoing queue. They separate the synchronous capture or outputoperation locked to a video clock from the application which issubject to random disk or network delays and preemption byother processes, thereby reducing the probability of data loss.The queues are organized as FIFOs, buffers will beoutput in the order enqueued in the incoming FIFO, and werecaptured in the order dequeued from the outgoing FIFO.
The driver may require a minimum number of buffers enqueuedat all times to function, apart of this no limit exists on the numberof buffers applications can enqueue in advance, or dequeue andprocess. They can also enqueue in a different order than buffers havebeen dequeued, and the driver canfill enqueuedempty buffers in any order.[15] The index number of a buffer (struct v4l2_bufferindex
) plays no role here, it onlyidentifies the buffer.
Initially all mapped buffers are in dequeued state,inaccessible by the driver. For capturing applications it is customaryto first enqueue all mapped buffers, then to start capturing and enterthe read loop. Here the application waits until a filled buffer can bedequeued, and re-enqueues the buffer when the data is no longerneeded. Output applications fill and enqueue buffers, when enoughbuffers are stacked up the output is started withVIDIOC_STREAMON
. In the write loop, whenthe application runs out of free buffers, it must wait until an emptybuffer can be dequeued and reused.
To enqueue and dequeue a buffer applications use theVIDIOC_QBUF
andVIDIOC_DQBUF
ioctl. The status of a buffer beingmapped, enqueued, full or empty can be determined at any time using theVIDIOC_QUERYBUF
ioctl. Two methods exist to suspend execution of theapplication until one or more buffers can be dequeued. By defaultVIDIOC_DQBUF
blocks when no buffer is in theoutgoing queue. When theO_NONBLOCK
flag wasgiven to theopen()
function,VIDIOC_DQBUF
returns immediately with anEAGAIN error code when no buffer is available. Theselect()
orpoll()
function are always available.
To start and stop capturing or output applications call theVIDIOC_STREAMON
andVIDIOC_STREAMOFF
ioctl. NoteVIDIOC_STREAMOFF
removes all buffers from bothqueues as a side effect. Since there is no notion of doing anything"now" on a multitasking system, if an application needs to synchronizewith another event it should examine the struct v4l2_buffertimestamp
of captured buffers, or set thefield before enqueuing buffers for output.
Drivers implementing memory mapping I/O mustsupport the VIDIOC_REQBUFS
,VIDIOC_QUERYBUF
,VIDIOC_QBUF
,VIDIOC_DQBUF
,VIDIOC_STREAMON
andVIDIOC_STREAMOFF
ioctl, themmap()
,munmap()
,select()
andpoll()
function.[16]
[capture example]
3.3. Streaming I/O (User Pointers)
Example 3-2. Initiating streaming I/O with user pointers
struct v4l2_requestbuffers reqbuf;memset (&reqbuf, 0, sizeof (reqbuf)); reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.memory = V4L2_MEMORY_USERPTR;if (ioctl (fd, VIDIOC_REQBUFS, &reqbuf) == -1) {if (errno == EINVAL)printf ("Video capturing or user pointer streaming is not supported\n");elseperror ("VIDIOC_REQBUFS");exit (EXIT_FAILURE); }
Buffer addresses and sizes are passed on the fly with theVIDIOC_QBUF
ioctl. Although buffers are commonly cycled,applications can pass different addresses and sizes at eachVIDIOC_QBUF
call. If required by the hardware thedriver swaps memory pages within physical memory to create acontinuous area of memory. This happens transparently to theapplication in the virtual memory subsystem of the kernel. When bufferpages have been swapped out to disk they are brought back and finallylocked in physical memory for DMA.[17]
Filled or displayed buffers are dequeued with theVIDIOC_DQBUF
ioctl. The driver can unlock the memory pages at anytime between the completion of the DMA and this ioctl. The memory isalso unlocked when VIDIOC_STREAMOFF
is called, VIDIOC_REQBUFS
, orwhen the device is closed. Applications must take care not to freebuffers without dequeuing. For once, the buffers remain locked untilfurther, wasting physical memory. Second the driver will not benotified when the memory is returned to the application's free listand subsequently reused for other purposes, possibly completing therequested DMA and overwriting valuable data.
For capturing applications it is customary to enqueue anumber of empty buffers, to start capturing and enter the read loop.Here the application waits until a filled buffer can be dequeued, andre-enqueues the buffer when the data is no longer needed. Outputapplications fill and enqueue buffers, when enough buffers are stackedup output is started. In the write loop, when the applicationruns out of free buffers it must wait until an empty buffer can bedequeued and reused. Two methods exist to suspend execution of theapplication until one or more buffers can be dequeued. By defaultVIDIOC_DQBUF
blocks when no buffer is in theoutgoing queue. When theO_NONBLOCK
flag wasgiven to theopen()
function,VIDIOC_DQBUF
returns immediately with anEAGAIN error code when no buffer is available. Theselect()
orpoll()
function are always available.
To start and stop capturing or output applications call theVIDIOC_STREAMON
andVIDIOC_STREAMOFF
ioctl. NoteVIDIOC_STREAMOFF
removes all buffers from bothqueues and unlocks all buffers as a side effect. Since there is nonotion of doing anything "now" on a multitasking system, if anapplication needs to synchronize with another event it should examinethe struct v4l2_buffertimestamp
of capturedbuffers, or set the field before enqueuing buffers for output.
Drivers implementing user pointer I/O mustsupport the VIDIOC_REQBUFS
,VIDIOC_QBUF
,VIDIOC_DQBUF
,VIDIOC_STREAMON
andVIDIOC_STREAMOFF
ioctl, theselect()
andpoll()
function.[18]
3.5. Buffers
Nominally timestamps refer to the first data byte transmitted.In practice however the wide range of hardware covered by the V4L2 APIlimits timestamp accuracy. Often an interrupt routine willsample the system clock shortly after the field or frame was storedcompletely in memory. So applications must expect a constantdifference up to one field or frame period plus a small (few scanlines) random error. The delay and error can be muchlarger due to compression or transmission over an external bus whenthe frames are not properly stamped by the sender. This is frequentlythe case with USB cameras. Here timestamps refer to the instant thefield or frame was received by the driver, not the capture time. Thesedevices identify by not enumerating any video standards, seeSection 1.7.
Similar limitations apply to output timestamps. Typicallythe video hardware locks to a clock controlling the video timing, thehorizontal and vertical synchronization pulses. At some point in theline sequence, possibly the vertical blanking, an interrupt routinesamples the system clock, compares against the timestamp and programsthe hardware to repeat the previous field or frame, or to display thebuffer contents.
Apart of limitations of the video device and naturalinaccuracies of all clocks, it should be noted system time itself isnot perfectly stable. It can be affected by power saving cycles,warped to insert leap seconds, or even turned back or forth by thesystem administrator affecting long term measurements. [19]
Table 3-1. struct v4l2_buffer
__u32 |
index
|
Number of the buffer, set by the application. Thisfield is only used for memory mapping I/Oand can range from zero to the number of buffers allocatedwith theVIDIOC_REQBUFS ioctl (struct v4l2_requestbufferscount ) minus one.
|
|
enum v4l2_buf_type |
type
|
Type of the buffer, same as struct v4l2_formattype or struct v4l2_requestbufferstype , set by the application.
|
|
__u32 |
bytesused
|
The number of bytes occupied by the data in thebuffer. It depends on the negotiated data format and may change witheach buffer for compressed variable size data like JPEG images.Drivers must set this field whentype refers to an input stream, applications when an output stream.
|
|
__u32 |
flags
|
Flags set by the application or driver, see Table 3-3. | |
enum v4l2_field |
field
|
Indicates the field order of the image in thebuffer, seeTable 3-8. This field is not used whenthe buffer contains VBI data. Drivers must set it whentype refers to an input stream,applications when an output stream.
|
|
struct timeval |
timestamp
|
For input streams this is thesystem time (as returned by the |
|
struct v4l2_timecode |
timecode
|
When type isV4L2_BUF_TYPE_VIDEO_CAPTURE and theV4L2_BUF_FLAG_TIMECODE flag is set inflags , this structure contains a frametimecode. InV4L2_FIELD_ALTERNATEmode the top and bottom field contain the same timecode.Timecodes are intended to help video editing and are typically recorded onvideo tapes, but also embedded in compressed formats like MPEG. Thisfield is independent of the timestamp andsequence fields.
|
|
__u32 |
sequence
|
Set by the driver, counting the frames in thesequence. | |
In V4L2_FIELD_ALTERNATE mode the top andbottom field have the same sequence number. The count starts at zeroand includes dropped or repeated frames. A dropped frame was receivedby an input device but could not be stored due to lack of free bufferspace. A repeated frame was displayed again by an output devicebecause the application did not pass new data intime. Note this may count the frames receivede.g. over USB, without taking into account the frames dropped by theremote hardware due to limited compression throughput or busbandwidth. These devices identify by not enumerating any videostandards, seeSection 1.7. |
|||
enum v4l2_memory |
memory
|
This field must be set by applications and/or driversin accordance with the selected I/O method. | |
union |
m
|
||
__u32 |
offset
|
When memory isV4L2_MEMORY_MMAP this is the offset of the bufferfrom the start of the device memory. The value is returned by thedriver and apart of serving as parameter to themmap() functionnot useful for applications. SeeSection 3.2 for details.
|
|
unsigned long |
userptr
|
When memory isV4L2_MEMORY_USERPTR this is a pointer to thebuffer (casted to unsigned long type) in virtual memory, set by theapplication. SeeSection 3.3 for details.
|
|
__u32 |
length
|
Size of the buffer (not the payload) in bytes. | |
__u32 |
input
|
Some video capture drivers support rapid andsynchronous video input changes, a function useful for example invideo surveillance applications. For this purpose applications set theV4L2_BUF_FLAG_INPUT flag, and this field to thenumber of a video input as in struct v4l2_input fieldindex .
|
|
__u32 |
reserved
|
A place holder for future extensions and custom(driver defined) buffer typesV4L2_BUF_TYPE_PRIVATE and higher.
|
Table 3-2. enum v4l2_buf_type
V4L2_BUF_TYPE_VIDEO_CAPTURE
|
1 | Buffer of a video capture stream, see Section 4.1. |
V4L2_BUF_TYPE_VIDEO_OUTPUT
|
2 | Buffer of a video output stream, see Section 4.3. |
V4L2_BUF_TYPE_VIDEO_OVERLAY
|
3 | Buffer for video overlay, see Section 4.2. |
V4L2_BUF_TYPE_VBI_CAPTURE
|
4 | Buffer of a raw VBI capture stream, see Section 4.7. |
V4L2_BUF_TYPE_VBI_OUTPUT
|
5 | Buffer of a raw VBI output stream, see Section 4.7. |
V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
|
6 | Buffer of a sliced VBI capture stream, see Section 4.8. |
V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
|
7 | Buffer of a sliced VBI output stream, see Section 4.8. |
V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
|
8 | Buffer for video output overlay (OSD), see Section 4.4. Status:Experimental. |
V4L2_BUF_TYPE_PRIVATE
|
0x80 | This and higher values are reserved for custom(driver defined) buffer types. |
Table 3-3. Buffer Flags
V4L2_BUF_FLAG_MAPPED
|
0x0001 | The buffer resides in device memory and has been mappedinto the application's address space, seeSection 3.2 for details.Drivers set or clear this flag when theVIDIOC_QUERYBUF,VIDIOC_QBUF orVIDIOC_DQBUFioctl is called. Set by the driver. |
V4L2_BUF_FLAG_QUEUED
|
0x0002 |
Internally drivers maintain two buffer queues, anincoming and outgoing queue. When this flag is set, the buffer iscurrently on the incoming queue. It automatically moves to theoutgoing queue after the buffer has been filled (capture devices) ordisplayed (output devices). Drivers set or clear this flag when theVIDIOC_QUERYBUF ioctl is called. After(successful) calling theVIDIOC_QBUF ioctl it isalways set and afterVIDIOC_DQBUF alwayscleared.
|
V4L2_BUF_FLAG_DONE
|
0x0004 |
When this flag is set, the buffer is currently onthe outgoing queue, ready to be dequeued from the driver. Drivers setor clear this flag when theVIDIOC_QUERYBUF ioctlis called. After calling theVIDIOC_QBUF orVIDIOC_DQBUF it is always cleared. Of course abuffer cannot be on both queues at the same time, theV4L2_BUF_FLAG_QUEUED andV4L2_BUF_FLAG_DONE flag are mutually exclusive.They can be both cleared however, then the buffer is in "dequeued"state, in the application domain to say so.
|
V4L2_BUF_FLAG_KEYFRAME
|
0x0008 |
Drivers set or clear this flag when calling theVIDIOC_DQBUF ioctl. It may be set by videocapture devices when the buffer contains a compressed image which is akey frame (or field), i. e. can be decompressed on its own.
|
V4L2_BUF_FLAG_PFRAME
|
0x0010 |
Similar to V4L2_BUF_FLAG_KEYFRAME this flags predicted frames or fields which contain only differences to aprevious key frame.
|
V4L2_BUF_FLAG_BFRAME
|
0x0020 |
Similar to V4L2_BUF_FLAG_PFRAME this is a bidirectional predicted frame or field. [ooc tbd]
|
V4L2_BUF_FLAG_TIMECODE
|
0x0100 |
The timecode field is valid.Drivers set or clear this flag when theVIDIOC_DQBUF ioctl is called.
|
V4L2_BUF_FLAG_INPUT
|
0x0200 |
The input field is valid.Applications set or clear this flag before calling theVIDIOC_QBUF ioctl.
|
Table 3-4. enum v4l2_memory
V4L2_MEMORY_MMAP
|
1 | The buffer is used for memorymapping I/O. |
V4L2_MEMORY_USERPTR
|
2 | The buffer is used for userpointer I/O. |
V4L2_MEMORY_OVERLAY
|
3 | [to do] |
3.5.1. Timecodes
Table 3-5. struct v4l2_timecode
__u32 |
type
|
Frame rate the timecodes are based on, see Table 3-6. |
__u32 |
flags
|
Timecode flags, see Table 3-7. |
__u8 |
frames
|
Frame count, 0 ... 23/24/29/49/59, depending on the type of timecode. |
__u8 |
seconds
|
Seconds count, 0 ... 59. This is a binary, not BCD number. |
__u8 |
minutes
|
Minutes count, 0 ... 59. This is a binary, not BCD number. |
__u8 |
hours
|
Hours count, 0 ... 29. This is a binary, not BCD number. |
__u8 |
userbits [4]
|
The "user group" bits from the timecode. |
Table 3-6. Timecode Types
V4L2_TC_TYPE_24FPS
|
1 | 24 frames per second, i. e. film. |
V4L2_TC_TYPE_25FPS
|
2 | 25 frames per second, i. e. PAL or SECAM video. |
V4L2_TC_TYPE_30FPS
|
3 | 30 frames per second, i. e. NTSC video. |
V4L2_TC_TYPE_50FPS
|
4 | |
V4L2_TC_TYPE_60FPS
|
5 |
Table 3-7. Timecode Flags
V4L2_TC_FLAG_DROPFRAME
|
0x0001 | Indicates "drop frame" semantics for counting framesin 29.97 fps material. When set, frame numbers 0 and 1 at the start ofeach minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from thecount. |
V4L2_TC_FLAG_COLORFRAME
|
0x0002 | The "color frame" flag. |
V4L2_TC_USERBITS_field
|
0x000C | Field mask for the "binary group flags". |
V4L2_TC_USERBITS_USERDEFINED
|
0x0000 | Unspecified format. |
V4L2_TC_USERBITS_8BITCHARS
|
0x0008 | 8-bit ISO characters. |
3.6. Field Order
When the driver provides or accepts images field by fieldrather than interleaved, it is also important applications understandhow the fields combine to frames. We distinguish between top andbottom fields, thespatial order: The first lineof the top field is the first line of an interlaced frame, the firstline of the bottom field is the second line of that frame.
However because fields were captured one after the other,arguing whether a frame commences with the top or bottom field ispointless. Any two successive top and bottom, or bottom and top fieldsyield a valid frame. Only when the source was progressive to beginwith, e. g. when transferring film to video, two fields may come fromthe same frame, creating a natural order.
Counter to intuition the top field is not necessarily theolder field. Whether the older field contains the top or bottom linesis a convention determined by the video standard. Hence thedistinction between temporal and spatial order of fields. The diagramsbelow should make this clearer.
All video capture and output devices must report the currentfield order. Some drivers may permit the selection of a differentorder, to this end applications initialize thefield
field of struct v4l2_pix_format beforecalling the VIDIOC_S_FMT
ioctl. If this is not desired it shouldhave the valueV4L2_FIELD_ANY
(0).
Table 3-8. enum v4l2_field
V4L2_FIELD_ANY
|
0 |
Applications request this field order when anyone of theV4L2_FIELD_NONE ,V4L2_FIELD_TOP ,V4L2_FIELD_BOTTOM , orV4L2_FIELD_INTERLACED formats is acceptable.Drivers choose depending on hardware capabilities or e. g. therequested image size, and return the actual field order. struct v4l2_bufferfield can never beV4L2_FIELD_ANY .
|
V4L2_FIELD_NONE
|
1 |
Images are in progressive format, not interlaced.The driver may also indicate this order when it cannot distinguishbetweenV4L2_FIELD_TOP andV4L2_FIELD_BOTTOM .
|
V4L2_FIELD_TOP
|
2 | Images consist of the top field only. |
V4L2_FIELD_BOTTOM
|
3 | Images consist of the bottom field only.Applications may wish to prevent a device from capturing interlacedimages because they will have "comb" or "feathering" artefacts aroundmoving objects. |
V4L2_FIELD_INTERLACED
|
4 | Images contain both fields, interleaved line byline. The temporal order of the fields (whether the top or bottomfield is first transmitted) depends on the current video standard.M/NTSC transmits the bottom field first, all other standards the topfield first. |
V4L2_FIELD_SEQ_TB
|
5 | Images contain both fields, the top field linesare stored first in memory, immediately followed by the bottom fieldlines. Fields are always stored in temporal order, the older one firstin memory. Image sizes refer to the frame, not fields. |
V4L2_FIELD_SEQ_BT
|
6 | Images contain both fields, the bottom fieldlines are stored first in memory, immediately followed by the topfield lines. Fields are always stored in temporal order, the older onefirst in memory. Image sizes refer to the frame, not fields. |
V4L2_FIELD_ALTERNATE
|
7 |
The two fields of a frame are passed in separatebuffers, in temporal order, i. e. the older one first. To indicate the fieldparity (whether the current field is a top or bottom field) the driveror application, depending on data direction, must set struct v4l2_bufferfield toV4L2_FIELD_TOP orV4L2_FIELD_BOTTOM . Any two successive fields pairto build a frame. If fields are successive, without any dropped fieldsbetween them (fields can drop individually), can be determined fromthe struct v4l2_buffersequence field. Imagesizes refer to the frame, not fields. This format cannot be selectedwhen using the read/write I/O method.
|
V4L2_FIELD_INTERLACED_TB
|
8 | Images contain both fields, interleaved line byline, top field first. The top field is transmitted first. |
V4L2_FIELD_INTERLACED_BT
|
9 | Images contain both fields, interleaved line byline, top field first. The bottom field is transmitted first. |
Figure 3-1. Field Order, Top Field First Transmitted
Figure 3-2. Field Order, Bottom Field First Transmitted
Chapter 4. Interfaces
4.1. Video Capture Interface
4.1.3. Image Format Negotiation
Cropping initialization at minimum requires to reset theparameters to defaults. An example is given inSection 1.11.
To query the current image format applications set thetype
field of a struct v4l2_format toV4L2_BUF_TYPE_VIDEO_CAPTURE
and call theVIDIOC_G_FMT
ioctl with a pointer to this structure. Drivers fillthe struct v4l2_pix_formatpix
member of thefmt
union.
To request different parameters applications set thetype
field of a struct v4l2_format as above andinitialize all fields of the struct v4l2_pix_formatvbi
member of thefmt
union, or better just modify theresults ofVIDIOC_G_FMT
, and call theVIDIOC_S_FMT
ioctl with a pointer to this structure. Drivers mayadjust the parameters and finally return the actual parameters asVIDIOC_G_FMT
does.
Like VIDIOC_S_FMT
theVIDIOC_TRY_FMT
ioctl can be used to learn about hardware limitationswithout disabling I/O or possibly time consuming hardwarepreparations.
The contents of struct v4l2_pix_format are discussed inChapter 2. See also the specification of theVIDIOC_G_FMT
,VIDIOC_S_FMT
andVIDIOC_TRY_FMT
ioctls for details. Videocapture devices must implement both theVIDIOC_G_FMT
andVIDIOC_S_FMT
ioctl, even ifVIDIOC_S_FMT
ignores all requests and alwaysreturns default parameters asVIDIOC_G_FMT
does.VIDIOC_TRY_FMT
is optional.
4.2. Video Overlay Interface
Also known as Framebuffer Overlay or Previewing
Video overlay devices have the ability to genlock (TV-)videointo the (VGA-)video signal of a graphics card, or to store capturedimages directly in video memory of a graphics card, typically withclipping. This can be considerable more efficient than capturingimages and displaying them by other means. In the old days when onlynuclear power plants needed cooling towers this used to be the onlyway to put live video into a window.
Video overlay devices are accessed through the same characterspecial files as video capture devices.Note the default function of a /dev/videodeviceis video capturing. The overlay function is only available aftercalling theVIDIOC_S_FMT
ioctl.
The driver may support simultaneous overlay and capturingusing the read/write and streaming I/O methods. If so, operation atthe nominal frame rate of the video standard is not guaranteed. Framesmay be directed away from overlay to capture, or one field may be usedfor overlay and the other for capture if the capture parameters permitthis.
Applications should use different file descriptors forcapturing and overlay. This must be supported by all drivers capableof simultaneous capturing and overlay. Optionally these drivers mayalso permit capturing and overlay with a single file descriptor forcompatibility with V4L and earlier versions of V4L2.[20]
4.2.3. Setup
A driver may support any (or none) of five clipping/blendingmethods:
Chroma-keying displays the overlaid image only wherepixels in the primary graphics surface assume a certain color.
A bitmap can be specified where each bit correspondsto a pixel in the overlaid image. When the bit is set, thecorresponding video pixel is displayed, otherwise a pixel of thegraphics surface.
A list of clipping rectangles can be specified. Inthese regions no video is displayed, so thegraphics surface can be seen here.
The framebuffer has an alpha channel that can be usedto clip or blend the framebuffer with the video.
A global alpha value can be specified to blend theframebuffer contents with video images.
When simultaneous capturing and overlay is supported andthe hardware prohibits different image and frame buffer formats, theformat requested first takes precedence. The attempt to capture(VIDIOC_S_FMT
) or overlay (VIDIOC_S_FBUF
) may fail with anEBUSY error code or return accordingly modified parameters..
4.2.4. Overlay Window
Table 4-1. struct v4l2_window
struct v4l2_rect |
w
|
Size and position of the window relative to thetop, left corner of the frame buffer defined withVIDIOC_S_FBUF . Thewindow can extend the frame buffer width and height, thex andy coordinates can be negative, and it can lie completely outside theframe buffer. The driver clips the window accordingly, or if that isnot possible, modifies its size and/or position.
|
enum v4l2_field |
field
|
Applications set this field to determine whichvideo field shall be overlaid, typically one ofV4L2_FIELD_ANY (0),V4L2_FIELD_TOP ,V4L2_FIELD_BOTTOM orV4L2_FIELD_INTERLACED . Drivers may have to choosea different field order and return the actual setting here.
|
__u32 |
chromakey
|
When chroma-keying has been negotiated withVIDIOC_S_FBUF applications set this field to the desired pixel valuefor the chroma key. The format is the same as the pixel format of theframebuffer (struct v4l2_framebufferfmt.pixelformat field), with bytes in hostorder. E. g. forV4L2_PIX_FMT_BGR24 the value should be 0xRRGGBB on a little endian, 0xBBGGRR on a bigendian host.
|
struct v4l2_clip * |
clips
|
When chroma-keying has notbeen negotiated andVIDIOC_G_FBUF indicated this capability,applications can set this field to point to an array ofclipping rectangles.
|
Like the window coordinatesw , clipping rectangles are defined relativeto the top, left corner of the frame buffer. However clippingrectangles must not extend the frame buffer width and height, and theymust not overlap. If possible applications should merge adjacentrectangles. Whether this must create x-y or y-x bands, or the order ofrectangles, is not defined. When clip lists are not supported thedriver ignores this field. Its contents after callingVIDIOC_S_FMT are undefined.
|
||
__u32 |
clipcount
|
When the application set theclips field, this field must contain thenumber of clipping rectangles in the list. When clip lists are notsupported the driver ignores this field, its contents after callingVIDIOC_S_FMT are undefined. When clip lists aresupported but no clipping is desired this field must be set tozero.
|
void * |
bitmap
|
When chroma-keying hasnot been negotiated andVIDIOC_G_FBUF indicatedthis capability, applications can set this field to point to aclipping bit mask.
|
It must be of the same sizeas the window, ((__u8 *) where When a clippingbit mask is not supported the driver ignores this field, its contentsafter calling Applications need not create aclip list or bit mask. When they pass both, or despite negotiatingchroma-keying, the results are undefined. Regardless of the chosenmethod, the clipping abilities of the hardware may be limited inquantity or quality. The results when these limits are exceeded areundefined.b |
||
__u8 |
global_alpha
|
The global alpha value used to blend theframebuffer with video images, if global alpha blending has beennegotiated ( Notethis field was added in Linux 2.6.23, extending the structure. Howeverthe VIDIOC_G/S/TRY_FMT ioctls,which take a pointer to av4l2_format parent structure with paddingbytes at the end, are not affected. |
Notes: a. Should we require w.width to be a multiple of eight?b. When the image is written into frame buffermemory it will be undesirable if the driver clips out less pixelsthan expected, because the application and graphics system are notaware these regions need to be refreshed. The driver should clip outmore pixels or not write the image at all. |
Table 4-2. struct v4l2_clip
[21]
struct v4l2_rect |
c
|
Coordinates of the clipping rectangle, relative tothe top, left corner of the frame buffer. Only window pixelsoutside all clipping rectangles aredisplayed. |
struct v4l2_clip * |
next
|
Pointer to the next clipping rectangle, NULL whenthis is the last rectangle. Drivers ignore this field, it cannot beused to pass a linked list of clipping rectangles. |
Table 4-3. struct v4l2_rect
__s32 |
left
|
Horizontal offset of the top, left corner of therectangle, in pixels. |
__s32 |
top
|
Vertical offset of the top, left corner of therectangle, in pixels. Offsets increase to the right and down. |
__s32 |
width
|
Width of the rectangle, in pixels. |
__s32 |
height
|
Height of the rectangle, in pixels. Width andheight cannot be negative, the fields are signed for hystericalreasons. |
4.3. Video Output Interface
4.3.3. Image Format Negotiation
Cropping initialization at minimum requires to reset theparameters to defaults. An example is given inSection 1.11.
To query the current image format applications set thetype
field of a struct v4l2_format toV4L2_BUF_TYPE_VIDEO_OUTPUT
and call theVIDIOC_G_FMT
ioctl with a pointer to this structure. Drivers fillthe struct v4l2_pix_formatpix
member of thefmt
union.
To request different parameters applications set thetype
field of a struct v4l2_format as above andinitialize all fields of the struct v4l2_pix_formatvbi
member of thefmt
union, or better just modify theresults ofVIDIOC_G_FMT
, and call theVIDIOC_S_FMT
ioctl with a pointer to this structure. Drivers mayadjust the parameters and finally return the actual parameters asVIDIOC_G_FMT
does.
Like VIDIOC_S_FMT
theVIDIOC_TRY_FMT
ioctl can be used to learn about hardware limitationswithout disabling I/O or possibly time consuming hardwarepreparations.
The contents of struct v4l2_pix_format are discussed inChapter 2. See also the specification of theVIDIOC_G_FMT
,VIDIOC_S_FMT
andVIDIOC_TRY_FMT
ioctls for details. Videooutput devices must implement both theVIDIOC_G_FMT
andVIDIOC_S_FMT
ioctl, even ifVIDIOC_S_FMT
ignores all requests and alwaysreturns default parameters asVIDIOC_G_FMT
does.VIDIOC_TRY_FMT
is optional.
4.4. Video Output Overlay Interface
Also known as On-Screen Display (OSD)
Experimental: This is an experimentalinterface and may change in the future.
Some video output devices can overlay a framebuffer image ontothe outgoing video signal. Applications can set up such an overlayusing this interface, which borrows structures and ioctls of theVideo Overlay interface.
The OSD function is accessible through the same characterspecial file as the Video Output function.Note the default function of such a /dev/videodeviceis video capturing or output. The OSD function is only available aftercalling theVIDIOC_S_FMT
ioctl.
4.4.2. Framebuffer
Example 4-1. Finding a framebuffer device for OSD
#include <linux/fb.h>struct v4l2_framebuffer fbuf; unsigned int i; int fb_fd;if (-1 == ioctl (fd, VIDIOC_G_FBUF, &fbuf)) {perror ("VIDIOC_G_FBUF");exit (EXIT_FAILURE); }for (i = 0; i < 30; ++i) {char dev_name[16];struct fb_fix_screeninfo si;snprintf (dev_name, sizeof (dev_name), "/dev/fb%u", i);fb_fd = open (dev_name, O_RDWR);if (-1 == fb_fd) {switch (errno) {case ENOENT: /* no such file */case ENXIO: /* no driver */continue;default:perror ("open");exit (EXIT_FAILURE);}}if (0 == ioctl (fb_fd, FBIOGET_FSCREENINFO, &si)) {if (si.smem_start == (unsigned long) fbuf.base)break;} else {/* Apparently not a framebuffer device. */}close (fb_fd);fb_fd = -1; }/* fb_fd is the file descriptor of the framebuffer devicefor the video output overlay, or -1 if no device was found. */
4.5. Codec Interface
Suspended: This interface has been be suspended from the V4L2 APIimplemented in Linux 2.6 until we have more experience with codecdevice interfaces.
A V4L2 codec can compress, decompress, transform, or otherwiseconvert video data from one format into another format, in memory.Applications send data to be converted to the driver through awrite()
call, and receive the converted data through aread()
call. For efficiency a driver may also support streamingI/O.
[to do]
4.6. Effect Devices Interface
Suspended: This interface has been be suspended from the V4L2 APIimplemented in Linux 2.6 until we have more experience with effectdevice interfaces.
A V4L2 video effect device can do image effects, filtering, orcombine two or more images or image streams. For example videotransitions or wipes. Applications send data to be processed andreceive the result data either withread()
andwrite()
functions, or through the streaming I/O mechanism.
[to do]
4.7. Raw VBI Data Interface
4.7.3. Raw VBI Format Negotiation
To query the current raw VBI capture parametersapplications set the type
field of astruct v4l2_format toV4L2_BUF_TYPE_VBI_CAPTURE
orV4L2_BUF_TYPE_VBI_OUTPUT
, and call theVIDIOC_G_FMT
ioctl with a pointer to this structure. Drivers fillthe struct v4l2_vbi_formatvbi
member of thefmt
union.
To request different parameters applications set thetype
field of a struct v4l2_format as above andinitialize all fields of the struct v4l2_vbi_formatvbi
member of thefmt
union, or better just modify theresults ofVIDIOC_G_FMT
, and call theVIDIOC_S_FMT
ioctl with a pointer to this structure. Drivers returnanEINVAL error code only when the given parameters are ambiguous, otherwisethey modify the parameters according to the hardware capabilites andreturn the actual parameters. When the driver allocates resources atthis point, it may return an EBUSY error code to indicate the returnedparameters are valid but the required resources are currently notavailable. That may happen for instance when the video and VBI areasto capture would overlap, or when the driver supports multiple opensand another process already requested VBI capturing or output. Anyway,applications must expect other resource allocation points which mayreturnEBUSY, at theVIDIOC_STREAMON
ioctland the first read(), write() and select() call.
VBI devices must implement both theVIDIOC_G_FMT
andVIDIOC_S_FMT
ioctl, even ifVIDIOC_S_FMT
ignores all requests and alwaysreturns default parameters asVIDIOC_G_FMT
does.VIDIOC_TRY_FMT
is optional.
Table 4-4. struct v4l2_vbi_format
__u32 |
sampling_rate
|
Samples per second, i. e. unit 1 Hz. |
__u32 |
offset
|
Horizontal offset of the VBI image,relative to the leading edge of the line synchronization pulse andcounted in samples: The first sample in the VBI image will be located |
__u32 |
samples_per_line
|
|
__u32 |
sample_format
|
Defines the sample format as in Chapter 2, a four-character-code.aUsually this is |
__u32 |
start [2]
|
This is the scanning system line numberassociated with the first line of the VBI image, of the first and thesecond field respectively. SeeFigure 4-2andFigure 4-3 for valid values. VBI input drivers canreturn start values 0 if the hardware cannot reliable identifyscanning lines, VBI acquisition may not require thisinformation. |
__u32 |
count [2]
|
The number of lines in the first and secondfield image, respectively. |
Drivers should be asflexibility as possible. For example, it may be possible to extend ormove the VBI capture window down to the picture area, implementing a'full field mode' to capture data service transmissions embedded inthe picture. An application can set the first or second Both To initialize the |
||
__u32 |
flags
|
See Table 4-5 below. Currentlyonly drivers set flags, applications must set this field tozero. |
__u32 |
reserved [2]
|
This array is reserved for future extensions.Drivers and applications must set it to zero. |
Notes: a. A few devices may be unable tosample VBI data at all but can extend the video capture window to theVBI region. |
Table 4-5. Raw VBI Format Flags
V4L2_VBI_UNSYNC
|
0x0001 |
This flag indicates hardware which does notproperly distinguish between fields. Normally the VBI image stores thefirst field (lower scanning line numbers) first in memory. This may bea top or bottom field depending on the video standard. When this flagis set the first or second field may be stored first, however thefields are still in correct temporal order with the older field firstin memory.a |
V4L2_VBI_INTERLACED
|
0x0002 |
By default the two field images will be passedsequentially; all lines of the first field followed by all lines ofthe second field (compareSection 3.6V4L2_FIELD_SEQ_TB andV4L2_FIELD_SEQ_BT , whether the top or bottomfield is first in memory depends on the video standard). When thisflag is set, the two fields are interlaced (cf.V4L2_FIELD_INTERLACED ). The first line of thefirst field followed by the first line of the second field, then thetwo second lines, and so on. Such a layout may be necessary when thehardware has been programmed to capture or output interlaced videoimages and is unable to separate the fields for VBI capturing atthe same time. For simplicity setting this flag implies that bothcount values are equal and non-zero.
|
Notes: a. Most VBI services transmit on both fields, butsome have different semantics depending on the field number. Thesecannot be reliable decoded or encoded when V4L2_VBI_UNSYNC is set.
|
Figure 4-1. Line synchronization
Figure 4-2. ITU-R 525 line numbering (M/NTSC and M/PAL)
(1) For the purpose of this specification field 2starts in line 264 and not 263.5 because half line capturing is notsupported.
Figure 4-3. ITU-R 625 line numbering
(1) For the purpose of this specification field 2starts in line 314 and not 313.5 because half line capturing is notsupported.
Remember the VBI image format depends on the selectedvideo standard, therefore the application must choose a new standard orquery the current standard first. Attempts to read or write data aheadof format negotiation, or after switching the video standard which mayinvalidate the negotiated VBI parameters, should be refused by thedriver. A format change during active I/O is not permitted.
4.8. Sliced VBI Data Interface
Sliced VBI devices use hardware to demodulate data transmittedin the VBI. V4L2 drivers shallnot do this bysoftware, see also theraw VBIinterface. The data is passed as short packets of fixed size,covering one scan line each. The number of packets per video frame isvariable.
Sliced VBI capture and output devices are accessed through thesame character special files as raw VBI devices. When a driversupports both interfaces, the default function of a/dev/vbi device israw VBIcapturing or output, and the sliced VBI function is only availableafter calling theVIDIOC_S_FMT
ioctl as defined below. Likewise a/dev/video device may support the sliced VBI API,however the default function here is video capturing or output.Different file descriptors must be used to pass raw and sliced VBIdata simultaneously, if this is supported by the driver.
4.8.3. Sliced VBI Format Negotiation
Table 4-6. structv4l2_sliced_vbi_format
__u32 |
service_set
|
If On return the driver sets this field to the union of allelements of the returned |
||
__u16 |
service_lines [2][24]
|
Applications initialize thisarray with sets of data services the driver shall look for or inserton the respective scan line. Subject to hardware capabilities driversreturn the requested set, a subset, which may be just a singleservice, or an empty set. When the hardware cannot handle multipleservices on the same line the driver shall choose one. No assumptionscan be made on which service the driver chooses. Dataservices are defined in Table 4-7. Array indicesmap to ITU-R line numbers (see also Figure 4-2 and Figure 4-3) as follows: |
||
Element | 525 line systems | 625 line systems | ||
service_lines [0][1]
|
1 | 1 | ||
service_lines [0][23]
|
23 | 23 | ||
service_lines [1][1]
|
264 | 314 | ||
service_lines [1][23]
|
286 | 336 | ||
Drivers must setservice_lines [0][0] andservice_lines [1][0] to zero.
|
||||
__u32 |
io_size
|
Maximum number of bytes passed byone read() or write() call, and the buffer size in bytes fortheVIDIOC_QBUF andVIDIOC_DQBUF ioctl. Drivers set this field tothe size of struct v4l2_sliced_vbi_data times the number of non-zeroelements in the returnedservice_lines array (that is the number of lines potentially carrying data).
|
||
__u32 |
reserved [2]
|
This array is reserved for futureextensions. Applications and drivers must set it to zero. | ||
Notes: a. According to ETS 300 706 lines 6-22 of thefirst field and lines 5-22 of the second field may carry Teletextdata. |
Table 4-7. Sliced VBI services
Symbol | Value | Reference | Lines, usually | Payload |
---|---|---|---|---|
V4L2_SLICED_TELETEXT_B (Teletext System B)
|
0x0001 | ETS 300 706,ITU BT.653 | PAL/SECAM line 7-22, 320-335 (second field 7-22) | Last 42 of the 45 byte Teletext packet, that iswithout clock run-in and framing code, lsb first transmitted. |
V4L2_SLICED_VPS
|
0x0400 | ETS 300 231 | PAL line 16 | Byte number 3 to 15 according to Figure 9 ofETS 300 231, lsb first transmitted. |
V4L2_SLICED_CAPTION_525
|
0x1000 | EIA 608-B | NTSC line 21, 284 (second field 21) | Two bytes in transmission order, including paritybit, lsb first transmitted. |
V4L2_SLICED_WSS_625
|
0x4000 | ITU BT.1119,EN 300 294 | PAL/SECAM line 23 |
Byte 0 1msb lsb msb lsbBit 7 6 5 4 3 2 1 0 x x 13 12 11 10 9 |
V4L2_SLICED_VBI_525
|
0x1000 | Set of services applicable to 525line systems. | ||
V4L2_SLICED_VBI_625
|
0x4401 | Set of services applicable to 625line systems. |
Drivers may return an EINVAL error code when applications attempt toread or write data without prior format negotiation, after switchingthe video standard (which may invalidate the negotiated VBIparameters) and after switching the video input (which may change thevideo standard as a side effect). The VIDIOC_S_FMT
ioctl may returnan EBUSY error code when applications attempt to change the format while i/o isin progress (between aVIDIOC_STREAMON
andVIDIOC_STREAMOFF
call,and after the firstread()
orwrite()
call).
4.8.4. Reading and writing sliced VBI data
Table 4-8. structv4l2_sliced_vbi_data
__u32 |
id
|
A flag from Table 2identifying the type of data in this packet. Only a single bit must beset. When theid of a captured packet iszero, the packet is empty and the contents of other fields areundefined. Applications shall ignore empty packets. When theid of a packet for output is zero thecontents of thedata field are undefinedand the driver must no longer insert data on the requestedfield andline .
|
__u32 |
field
|
The video field number this data has been capturedfrom, or shall be inserted at.0 for the firstfield,1 for the second field.
|
__u32 |
line
|
The field (as opposed to frame) line number thisdata has been captured from, or shall be inserted at. SeeFigure 4-2 andFigure 4-3 for validvalues. Sliced VBI capture devices can set the line number of allpackets to0 if the hardware cannot reliablyidentify scan lines. The field number must always be valid.
|
__u32 |
reserved
|
This field is reserved for future extensions.Applications and drivers must set it to zero. |
__u8 |
data [48]
|
The packet payload. See Table 2 for the contents and number ofbytes passed for each data type. The contents of padding bytes at theend of this array are undefined, drivers and applications shall ignorethem. |
Packets are always passed in ascending line number order,without duplicate line numbers. Thewrite()
function and theVIDIOC_QBUF
ioctl must return an EINVAL error code when applications violatethis rule. They must also return anEINVAL error code when applications pass anincorrect field or line number, or a combination offield
,line
andid
which has not been negotiated with theVIDIOC_G_FMT
orVIDIOC_S_FMT
ioctl. When the line numbers areunknown the driver must pass the packets in transmitted order. Thedriver can insert empty packets withid
setto zero anywhere in the packet array.
To assure synchronization and to distinguish from framedropping, when a captured frame does not carry any of the requesteddata services drivers must pass one or more empty packets. When anapplication fails to pass VBI data in time for output, the drivermust output the last VPS and WSS packet again, and disable the outputof Closed Caption and Teletext data, or output data which is ignoredby Closed Caption and Teletext decoders.
A sliced VBI device may support read/write and/or streaming (memory mapping and/oruserpointer) I/O. The latter bears the possibility of synchronizingvideo and VBI data by using buffer timestamps.
4.10. Radio Interface
This interface is intended for AM and FM (analog) radioreceivers.
4.10.2. Supplemental Functions
Radio devices can support controls, and must support the tuner ioctls.
4.11. RDS Interface
The V4L API defines its RDS API as follows.
First Octet Least Significant Byte of RDS Block
Second Octet Most Significant Byte of RDS Block
Third Octet Bit 7: Error bit. Indicates that anuncorrectable error occurred during reception of this block. Bit 6:Corrected bit. Indicates that an error was corrected for this datablock. Bits 5-3: Received Offset. Indicates the offset received by thesync system. Bits 2-0: Offset Name. Indicates the offset applied tothis data.
It was argued the RDS API should beextended before integration into V4L2, no new API has been devised yet.Please write to the Video4Linux mailing list for discussion:https://listman.redhat.com/mailman/listinfo/video4linux-list. Meanwhile no V4L2 driver should set theV4L2_CAP_RDS_CAPTURE
capability flag.
I. Function Reference
- Table of ContentsV4L2 close() -- Close a V4L2 deviceV4L2 ioctl() -- Program a V4L2 deviceioctl VIDIOC_CROPCAP -- Information about the video cropping and scaling abilitiesioctl VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER -- Read or write hardware registersioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD -- Execute an encoder commandioctl VIDIOC_ENUMAUDIO -- Enumerate audio inputsioctl VIDIOC_ENUMAUDOUT -- Enumerate audio outputsioctl VIDIOC_ENUM_FMT -- Enumerate image formatsioctl VIDIOC_ENUM_FRAMESIZES -- Enumerate frame sizesioctl VIDIOC_ENUM_FRAMEINTERVALS -- Enumerate frame intervalsioctl VIDIOC_ENUMINPUT -- Enumerate video inputsioctl VIDIOC_ENUMOUTPUT -- Enumerate video outputsioctl VIDIOC_ENUMSTD -- Enumerate supported video standardsioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO -- Query or select the current audio input and itsattributesioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT -- Query or select the current audio outputioctl VIDIOC_G_CHIP_IDENT -- Identify the chips on a TV cardioctl VIDIOC_G_CROP, VIDIOC_S_CROP -- Get or set the current cropping rectangleioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL -- Get or set the value of a controlioctl VIDIOC_G_ENC_INDEX -- Get meta data about a compressed video streamioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS,VIDIOC_TRY_EXT_CTRLS -- Get or set the value of several controls, try controlvaluesioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF -- Get or set frame buffer overlay parametersioctl VIDIOC_G_FMT, VIDIOC_S_FMT,VIDIOC_TRY_FMT -- Get or set the data format, try a formatioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY -- Get or set tuner or modulator radiofrequencyioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT -- Query or select the current video inputioctl VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP -- ioctl VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR -- Get or set modulator attributesioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT -- Query or select the current video outputioctl VIDIOC_G_PARM, VIDIOC_S_PARM -- Get or set streaming parametersioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY -- Query or request the access priority associated with afile descriptorioctl VIDIOC_G_SLICED_VBI_CAP -- Query sliced VBI capabilitiesioctl VIDIOC_G_STD, VIDIOC_S_STD -- Query or select the video standard of the current inputioctl VIDIOC_G_TUNER, VIDIOC_S_TUNER -- Get or set tuner attributesioctl VIDIOC_LOG_STATUS -- Log driver status informationioctl VIDIOC_OVERLAY -- Start or stop video overlayioctl VIDIOC_QBUF, VIDIOC_DQBUF -- Exchange a buffer with the driverioctl VIDIOC_QUERYBUF -- Query the status of a bufferioctl VIDIOC_QUERYCAP -- Query device capabilitiesioctl VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU -- Enumerate controls and menu control itemsioctl VIDIOC_QUERYSTD -- Sense the video standard received by the currentinputioctl VIDIOC_REQBUFS -- Initiate Memory Mapping or User Pointer I/Oioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF -- Start or stop streaming I/OV4L2 mmap() -- Map device memory into application address spaceV4L2 munmap() -- Unmap device memoryV4L2 open() -- Open a V4L2 deviceV4L2 poll() -- Wait for some event on a file descriptorV4L2 read() -- Read from a V4L2 deviceV4L2 select() -- Synchronous I/O multiplexingV4L2 write() -- Write to a V4L2 device
V4L2 close()
Name
v4l2-close -- Close a V4L2 device
Synopsis
#include <unistd.h>
int close
(int fd);
Arguments
-
fd
-
File descriptor returned by
open()
.
Description
Closes the device. Any I/O in progress is terminated andresources associated with the file descriptor are freed. However dataformat parameters, current input or output, control values or otherproperties remain unchanged.
Return Value
The function returns 0 onsuccess, -1 on failure and theerrno
is set appropriately. Possible errorcodes:
- EBADF
-
fd
is not a valid open filedescriptor.
V4L2 ioctl()
Name
v4l2-ioctl -- Program a V4L2 device
Synopsis
#include <sys/ioctl.h>
int ioctl
(int fd, int request, void *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
V4L2 ioctl request code as defined in the videodev.h header file, for exampleVIDIOC_QUERYCAP.
-
argp
-
Pointer to a function parameter, usually a structure.
Description
The ioctl()
function is used to programV4L2 devices. The argumentfd
must be an openfile descriptor. An ioctlrequest
has encodedin it whether the argument is an input, output or read/writeparameter, and the size of the argumentargp
inbytes. Macros and defines specifying V4L2 ioctl requests are locatedin thevideodev.h header file.Applications should use their own copy, not include the version in thekernel sources on the system they compile on. All V4L2 ioctl requests,their respective function and parameters are specified inReference I,Function Reference.
Return Value
On success the ioctl()
function returns0 and does not reset theerrno
variable. On failure-1 is returned, when the ioctl takes anoutput or read/write parameter it remains unmodified, and theerrno
variable is set appropriately. See below forpossible error codes. Generic errors likeEBADForEFAULTare not listed in the sectionsdiscussing individual ioctl requests.
Note ioctls may return undefined error codes. Since errorsmay have side effects such as a driver reset applications shouldabort on unexpected errors.
- EBADF
-
fd
is not a valid open filedescriptor. - EBUSY
-
The property cannot be changed right now. Typicallythis error code is returned when I/O is in progress or the driversupports multiple opens and another process locked the property.
- EFAULT
-
argp
references an inaccessiblememory area. - ENOTTY
-
fd
is not associated with acharacter special device. - EINVAL
-
The
request
or the data pointedto byargp
is not valid. This is a very commonerror code, see the individual ioctl requests listed inReference I,Function Reference for actual causes. - ENOMEM
-
Not enough physical or virtual memory was available tocomplete the request.
- ERANGE
-
The application attempted to set a control with the
VIDIOC_S_CTRL
ioctl to a value which is out of bounds.
ioctl VIDIOC_CROPCAP
Name
VIDIOC_CROPCAP -- Information about the video cropping and scaling abilities
Synopsis
int ioctl
(int fd, int request, struct v4l2_cropcap*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_CROPCAP
-
argp
Description
Applications use this function to query the croppinglimits, the pixel aspect of images and to calculate scale factors.They set thetype
field of a v4l2_cropcapstructure to the respective buffer (stream) type and call theVIDIOC_CROPCAP
ioctl with a pointer to thisstructure. Drivers fill the rest of the structure. The results areconstant except when switching the video standard. Remember thisswitch can occur implicit when switching the video input oroutput.
Table 1. struct v4l2_cropcap
enum v4l2_buf_type |
type
|
Type of the data stream, set by the application.Only these types are valid here:V4L2_BUF_TYPE_VIDEO_CAPTURE ,V4L2_BUF_TYPE_VIDEO_OUTPUT ,V4L2_BUF_TYPE_VIDEO_OVERLAY , and custom (driverdefined) types with code V4L2_BUF_TYPE_PRIVATE and higher.
|
struct v4l2_rect |
bounds
|
Defines the window within capturing or output ispossible, this may exclude for example the horizontal and verticalblanking areas. The cropping rectangle cannot exceed these limits.Width and height are defined in pixels, the driver writer is free tochoose origin and units of the coordinate system in the analogdomain. |
struct v4l2_rect |
defrect
|
Default cropping rectangle, it shall cover the"whole picture". Assuming pixel aspect 1/1 this could be for example a640 × 480 rectangle for NTSC, a768 × 576 rectangle for PAL and SECAM centered overthe active picture area. The same co-ordinate system as for bounds is used.
|
struct v4l2_fract |
pixelaspect
|
This is the pixel aspect (y / x) when noscaling is applied, the ratio of the actual samplingfrequency and the frequency required to get squarepixels. When cropping coordinates refer to square pixels,the driver sets |
Table 2. struct v4l2_rect
__s32 |
left
|
Horizontal offset of the top, left corner of therectangle, in pixels. |
__s32 |
top
|
Vertical offset of the top, left corner of therectangle, in pixels. |
__s32 |
width
|
Width of the rectangle, in pixels. |
__s32 |
height
|
Height of the rectangle, in pixels. Widthand height cannot be negative, the fields are signed forhysterical reasons. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_cropcap
type
isinvalid or the ioctl is not supported. This is not permitted forvideo capture, output and overlay devices, which must supportVIDIOC_CROPCAP
.
ioctl VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER
Name
VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER -- Read or write hardware registers
Synopsis
int ioctl
(int fd, int request, struct v4l2_register *argp);
int ioctl
(int fd, int request, const struct v4l2_register*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER
-
argp
Description
Experimental: This is an experimentalinterface and may change in the future.
For driver debugging purposes these ioctls allow testapplications to access hardware registers directly. Regularapplications should not use them.
Since writing or even reading registers can jeopardize thesystem security, its stability and damage the hardware, both ioctlsrequire superuser privileges. Additionally the Linux kernel must becompiled with theCONFIG_VIDEO_ADV_DEBUG
optionto enable these ioctls.
To write a register applications must initialize all fieldsof a struct v4l2_register and callVIDIOC_DBG_S_REGISTER
with a pointer to thisstructure. Thematch_type
andmatch_chip
fields select a chip on the TVcard, thereg
field specifies a registernumber and theval
field the value to bewritten into the register.
To read a register applications must initialize thematch_type
,match_chip
andreg
fields, and callVIDIOC_DBG_G_REGISTER
with a pointer to thisstructure. On success the driver stores the register value in theval
field. On failure the structure remainsunchanged.
When match_type
isV4L2_CHIP_MATCH_HOST
,match_chip
selects the nth non-I2C chipon the TV card. Drivers may also interpretmatch_chip
as a random ID, but we recommendagainst that. The number zero always selects the host chip, e. g. thechip connected to the PCI bus. You can find out which chips arepresent with theVIDIOC_G_CHIP_IDENT
ioctl.
When match_type
isV4L2_CHIP_MATCH_I2C_DRIVER
,match_chip
contains a driver ID as definedin thelinux/i2c-id.h header file. For instanceI2C_DRIVERID_SAA7127
will match any chipsupported by the saa7127 driver, regardless of its I2C bus address.When multiple chips supported by the same driver are present, theeffect of these ioctls is undefined. Again with theVIDIOC_G_CHIP_IDENT
ioctl you can find out which I2C chips arepresent.
When match_type
isV4L2_CHIP_MATCH_I2C_ADDR
,match_chip
selects a chip by its 7 bit I2Cbus address.
Success not guaranteed: Due to a flaw in the Linux I2C bus driver these ioctls mayreturn successfully without actually reading or writing a register. Tocatch the most likely failure we recommend a
VIDIOC_G_CHIP_IDENT
call confirming the presence of the selected I2C chip.
These ioctls are optional, not all drivers may support them.However when a driver supports these ioctls it must also supportVIDIOC_G_CHIP_IDENT
. Conversely it may supportVIDIOC_G_CHIP_IDENT
but not these ioctls.
VIDIOC_DBG_G_REGISTER
andVIDIOC_DBG_S_REGISTER
were introduced in Linux2.6.21.
We recommended the v4l2-dbgutility over calling these ioctls directly. It is available from theLinuxTV v4l-dvb repository; seehttp://linuxtv.org/repo/foraccess instructions.
Table 1. struct v4l2_register
__u32 |
match_type
|
See Table 2 for a list of possible types. | |
__u32 |
match_chip
|
Match a chip by this number, interpreted accordingto the match_type field.
|
|
__u64 |
reg
|
A register number. | |
__u64 |
val
|
The value read from, or to be written into theregister. |
Table 2. Chip Match Types
V4L2_CHIP_MATCH_HOST
|
0 | Match the nth chip on the card, zero for the host chip. Does not match I2C chips. |
V4L2_CHIP_MATCH_I2C_DRIVER
|
1 | Match an I2C chip by its driver ID from thelinux/i2c-id.h header file. |
V4L2_CHIP_MATCH_I2C_ADDR
|
2 | Match a chip by its 7 bit I2C bus address. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The driver does not support this ioctl, or the kernelwas not compiled with the
CONFIG_VIDEO_ADV_DEBUG
option, or thematch_type
is invalid, or theselected chip or register does not exist. - EPERM
-
Insufficient permissions. Root privileges are requiredto execute these ioctls.
ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
Name
VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD -- Execute an encoder command
Synopsis
int ioctl
(int fd, int request, struct v4l2_encoder_cmd *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD
-
argp
Description
Experimental: This is an experimentalinterface and may change in the future.
These ioctls control an audio/video (usually MPEG-) encoder.VIDIOC_ENCODER_CMD
sends a command to theencoder,VIDIOC_TRY_ENCODER_CMD
can be used totry a command without actually executing it.
To send a command applications must initialize all fields of a struct v4l2_encoder_cmd and callVIDIOC_ENCODER_CMD
orVIDIOC_TRY_ENCODER_CMD
with a pointer to this structure.
The cmd
field must contain thecommand code. Theflags
field is currentlyonly used by the STOP command and contains one bit: If theV4L2_ENC_CMD_STOP_AT_GOP_END
flag is set,encoding will continue until the end of the currentGroupOf Pictures, otherwise it will stop immediately.
A read
() call sends a START command tothe encoder if it has not been started yet. After a STOP command,read
() calls will read the remaining databuffered by the driver. When the buffer is empty,read
() will return zero and the nextread
() call will restart the encoder.
A close
() call sends an immediate STOPto the encoder, and all buffered data is discarded.
These ioctls are optional, not all drivers may supportthem. They were introduced in Linux 2.6.21.
Table 1. struct v4l2_encoder_cmd
__u32 |
cmd
|
The encoder command, see Table 2. |
__u32 |
flags
|
Flags to go with the command, see Table 3. If no flags are defined forthis command, drivers and applications must set this field tozero. |
__u32 |
data [8]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. |
Table 2. Encoder Commands
V4L2_ENC_CMD_START
|
0 | Start the encoder. When the encoder is alreadyrunning or paused, this command does nothing. No flags are defined forthis command. |
V4L2_ENC_CMD_STOP
|
1 |
Stop the encoder. When theV4L2_ENC_CMD_STOP_AT_GOP_END flag is set,encoding will continue until the end of the currentGroupOf Pictures, otherwise encoding will stop immediately.When the encoder is already stopped, this command doesnothing.
|
V4L2_ENC_CMD_PAUSE
|
2 | Pause the encoder. When the encoder has not beenstarted yet, the driver will return anEPERM error code. When the encoder isalready paused, this command does nothing. No flags are defined forthis command. |
V4L2_ENC_CMD_RESUME
|
3 | Resume encoding after a PAUSE command. When theencoder has not been started yet, the driver will return anEPERM error code.When the encoder is already running, this command does nothing. Noflags are defined for this command. |
Table 3. Encoder Command Flags
V4L2_ENC_CMD_STOP_AT_GOP_END
|
0x0001 | Stop encoding at the end of the current Group OfPictures, rather than immediately. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The driver does not support this ioctl, or the
cmd
field is invalid. - EPERM
-
The application sent a PAUSE or RESUME command whenthe encoder was not running.
ioctl VIDIOC_ENUMAUDIO
Name
VIDIOC_ENUMAUDIO -- Enumerate audio inputs
Synopsis
int ioctl
(int fd, int request, struct v4l2_audio *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENUMAUDIO
-
argp
Description
To query the attributes of an audio input applicationsinitialize the index
field and zero out thereserved
array of a struct v4l2_audioand call theVIDIOC_ENUMAUDIO
ioctl with a pointerto this structure. Drivers fill the rest of the structure or return anEINVAL error code when the index is out of bounds. To enumerate all audioinputs applications shall begin at index zero, incrementing by oneuntil the driver returnsEINVAL.
See ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO(2) for a description ofstruct v4l2_audio.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The number of the audio input is out of bounds, orthere are no audio inputs at all and this ioctl is notsupported.
ioctl VIDIOC_ENUMAUDOUT
Name
VIDIOC_ENUMAUDOUT -- Enumerate audio outputs
Synopsis
int ioctl
(int fd, int request, struct v4l2_audioout *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENUMAUDOUT
-
argp
Description
To query the attributes of an audio output applicationsinitialize the index
field and zero out thereserved
array of a struct v4l2_audioout andcall theVIDIOC_G_AUDOUT
ioctl with a pointerto this structure. Drivers fill the rest of the structure or return anEINVAL error code when the index is out of bounds. To enumerate all audiooutputs applications shall begin at index zero, incrementing by oneuntil the driver returns EINVAL.
Note connectors on a TV card to loop back the received audiosignal to a sound card are not audio outputs in this sense.
See ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT(2) for a description ofstruct v4l2_audioout.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The number of the audio output is out of bounds, orthere are no audio outputs at all and this ioctl is notsupported.
ioctl VIDIOC_ENUM_FMT
Name
VIDIOC_ENUM_FMT -- Enumerate image formats
Synopsis
int ioctl
(int fd, int request, struct v4l2_fmtdesc*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENUM_FMT
-
argp
Description
To enumerate image formats applications initialize thetype
andindex
field of struct v4l2_fmtdesc and call theVIDIOC_ENUM_FMT
ioctl with a pointer to thisstructure. Drivers fill the rest of the structure or return anEINVAL error code. All formats are enumerable by beginning at index zero andincrementing by one untilEINVAL isreturned.
Table 1. struct v4l2_fmtdesc
__u32 |
index
|
Number of the format in the enumeration, set bythe application. This is in no way related to thepixelformat field.
|
enum v4l2_buf_type |
type
|
Type of the data stream, set by the application.Only these types are valid here:V4L2_BUF_TYPE_VIDEO_CAPTURE ,V4L2_BUF_TYPE_VIDEO_OUTPUT ,V4L2_BUF_TYPE_VIDEO_OVERLAY , and custom (driverdefined) types with code V4L2_BUF_TYPE_PRIVATE and higher.
|
__u32 |
flags
|
See Table 2 |
__u8 |
description [32]
|
Description of the format, a NUL-terminated ASCIIstring. This information is intended for the user, for example: "YUV4:2:2". |
__u32 |
pixelformat
|
The image format identifier. This is afour character code as computed by the v4l2_fourcc()macro: |
#define v4l2_fourcc(a,b,c,d) (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24)) Several image formats are alreadydefined by this specification in Chapter 2. Note thesecodes are not the same as those used in the Windows world. |
||
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers must setthe array to zero. |
Table 2. Image Format Description Flags
V4L2_FMT_FLAG_COMPRESSED
|
0x0001 | This is a compressed format. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_fmtdesc
type
is not supported or theindex
is out ofbounds.
ioctl VIDIOC_ENUM_FRAMESIZES
Name
VIDIOC_ENUM_FRAMESIZES -- Enumerate frame sizes
Synopsis
int ioctl
(int fd, int request, struct v4l2_frmsizeenum *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENUM_FRAMESIZES
-
argp
-
Pointer to a struct v4l2_frmsizeenum that contains an indexand pixel format and receives a frame width and height.
Description
Experimental: This is an experimentalinterface and may change in the future.
This ioctl allows applications to enumerate all frame sizes(i. e. width and height in pixels) that the device supports for thegiven pixel format.
The supported pixel formats can be obtained by using theVIDIOC_ENUM_FMT
function.
The return value and the content of thev4l2_frmsizeenum.type
field depend on thetype of frame sizes the device supports. Here are the semantics of thefunction for the different cases:
Discrete: The functionreturns success if the given index value (zero-based) is valid. Theapplication should increase the index by one for each call until
EINVAL
is returned. Thev4l2_frmsizeenum.type
field is set toV4L2_FRMSIZE_TYPE_DISCRETE
by the driver. Of theunion only thediscrete
member isvalid.Step-wise: The functionreturns success if the given index value is zero and
EINVAL
for any other index value. Thev4l2_frmsizeenum.type
field is set toV4L2_FRMSIZE_TYPE_STEPWISE
by the driver. Of theunion only thestepwise
member isvalid.Continuous: This is aspecial case of the step-wise type above. The function returns successif the given index value is zero and
EINVAL
forany other index value. Thev4l2_frmsizeenum.type
field is set toV4L2_FRMSIZE_TYPE_CONTINUOUS
by the driver. Ofthe union only thestepwise
member is validand thestep_width
andstep_height
values are set to 1.
When the application calls the function with index zero, itmust check the type
field to determine thetype of frame size enumeration the device supports. Only for theV4L2_FRMSIZE_TYPE_DISCRETE
type does it makesense to increase the index value to receive more frame sizes.
Note that the order in which the frame sizes are returnedhas no special meaning. In particular does it not say anything aboutpotential default format sizes.
Applications can assume that the enumeration data does notchange without any interaction from the application itself. This meansthat the enumeration data is consistent if the application does notperform any other ioctl calls while it runs the frame sizeenumeration.
Structs
In the structs below, IN denotes avalue that has to be filled in by the application,OUT denotes values that the driver fills in. Theapplication should zero out all members except for theIN fields.
Table 1. struct v4l2_frmsize_discrete
__u32 |
width
|
Width of the frame [pixel]. |
__u32 |
height
|
Height of the frame [pixel]. |
Table 2. struct v4l2_frmsize_stepwise
__u32 |
min_width
|
Minimum frame width [pixel]. |
__u32 |
max_width
|
Maximum frame width [pixel]. |
__u32 |
step_width
|
Frame width step size [pixel]. |
__u32 |
min_height
|
Minimum frame height [pixel]. |
__u32 |
max_height
|
Maximum frame height [pixel]. |
__u32 |
step_height
|
Frame height step size [pixel]. |
Table 3. struct v4l2_frmsizeenum
__u32 |
index
|
IN: Index of the given frame size in the enumeration. | |
__u32 |
pixel_format
|
IN: Pixel format for which the frame sizes are enumerated. | |
__u32 |
type
|
OUT: Frame size type the device supports. | |
union | OUT: Frame size with the given index. | ||
struct v4l2_frmsize_discrete |
discrete
|
||
struct v4l2_frmsize_stepwise |
stepwise
|
||
__u32 |
reserved[2]
|
Reserved space for future use. |
Enums
Table 4. enum v4l2_frmsizetypes
V4L2_FRMSIZE_TYPE_DISCRETE
|
1 | Discrete frame size. |
V4L2_FRMSIZE_TYPE_CONTINUOUS
|
2 | Continuous frame size. |
V4L2_FRMSIZE_TYPE_STEPWISE
|
3 | Step-wise defined frame size. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
See the description section above for a list of returnvalues that errno
can have.
ioctl VIDIOC_ENUM_FRAMEINTERVALS
Name
VIDIOC_ENUM_FRAMEINTERVALS -- Enumerate frame intervals
Synopsis
int ioctl
(int fd, int request, struct v4l2_frmivalenum *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENUM_FRAMEINTERVALS
-
argp
-
Pointer to a struct v4l2_frmivalenum structure thatcontains a pixel format and size and receives a frame interval.
Description
This ioctl allows applications to enumerate all frameintervals that the device supports for the given pixel format andframe size.
The supported pixel formats and frame sizes can be obtainedby using the VIDIOC_ENUM_FMT
and VIDIOC_ENUM_FRAMESIZES
functions.
The return value and the content of thev4l2_frmivalenum.type
field depend on thetype of frame intervals the device supports. Here are the semantics ofthe function for the different cases:
Discrete: The functionreturns success if the given index value (zero-based) is valid. Theapplication should increase the index by one for each call until
EINVAL
is returned. The `v4l2_frmivalenum.type`field is set to `V4L2_FRMIVAL_TYPE_DISCRETE` by the driver. Of theunion only the `discrete` member is valid.Step-wise: The functionreturns success if the given index value is zero and
EINVAL
for any other index value. Thev4l2_frmivalenum.type
field is set toV4L2_FRMIVAL_TYPE_STEPWISE
by the driver. Of theunion only thestepwise
member isvalid.Continuous: This is aspecial case of the step-wise type above. The function returns successif the given index value is zero and
EINVAL
forany other index value. Thev4l2_frmivalenum.type
field is set toV4L2_FRMIVAL_TYPE_CONTINUOUS
by the driver. Ofthe union only thestepwise
member is validand thestep
value is set to 1.
When the application calls the function with index zero, itmust check the type
field to determine thetype of frame interval enumeration the device supports. Only for theV4L2_FRMIVAL_TYPE_DISCRETE
type does it makesense to increase the index value to receive more frameintervals.
Note that the order in which the frame intervals arereturned has no special meaning. In particular does it not sayanything about potential default frame intervals.
Applications can assume that the enumeration data does notchange without any interaction from the application itself. This meansthat the enumeration data is consistent if the application does notperform any other ioctl calls while it runs the frame intervalenumeration.
Notes
Frame intervals and framerates: The V4L2 API uses frame intervals instead of framerates. Given the frame interval the frame rate can be computed asfollows:
frame_rate = 1 / frame_interval
Structs
In the structs below, IN denotes avalue that has to be filled in by the application,OUT denotes values that the driver fills in. Theapplication should zero out all members except for theIN fields.
Table 1. struct v4l2_frmival_stepwise
struct v4l2_fract |
min
|
Minimum frame interval [s]. |
struct v4l2_fract |
max
|
Maximum frame interval [s]. |
struct v4l2_fract |
step
|
Frame interval step size [s]. |
Table 2. struct v4l2_frmivalenum
__u32 |
index
|
IN: Index of the given frame interval in theenumeration. | |
__u32 |
pixel_format
|
IN: Pixel format for which the frame intervals areenumerated. | |
__u32 |
width
|
IN: Frame width for which the frame intervals areenumerated. | |
__u32 |
height
|
IN: Frame height for which the frame intervals areenumerated. | |
__u32 |
type
|
OUT: Frame interval type the device supports. | |
union | OUT: Frame interval with the given index. | ||
struct v4l2_fract |
discrete
|
Frame interval [s]. | |
struct v4l2_frmival_stepwise |
stepwise
|
||
__u32 |
reserved[2]
|
Reserved space for future use. |
Enums
Table 3. enum v4l2_frmivaltypes
V4L2_FRMIVAL_TYPE_DISCRETE
|
1 | Discrete frame interval. |
V4L2_FRMIVAL_TYPE_CONTINUOUS
|
2 | Continuous frame interval. |
V4L2_FRMIVAL_TYPE_STEPWISE
|
3 | Step-wise defined frame interval. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
See the description section above for a list of returnvalues that errno
can have.
ioctl VIDIOC_ENUMINPUT
Name
VIDIOC_ENUMINPUT -- Enumerate video inputs
Synopsis
int ioctl
(int fd, int request, struct v4l2_input*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENUMINPUT
-
argp
Description
To query the attributes of a video input applicationsinitialize the index
field of struct v4l2_inputand call theVIDIOC_ENUMINPUT
ioctl with apointer to this structure. Drivers fill the rest of the structure orreturn anEINVAL error code when the index is out of bounds. To enumerate allinputs applications shall begin at index zero, incrementing by oneuntil the driver returnsEINVAL.
Table 1. struct v4l2_input
__u32 |
index
|
Identifies the input, set by theapplication. |
__u8 |
name [32]
|
Name of the video input, a NUL-terminated ASCIIstring, for example: "Vin (Composite 2)". This information is intendedfor the user, preferably the connector label on the device itself. |
__u32 |
type
|
Type of the input, see Table 2. |
__u32 |
audioset
|
Drivers can enumerate up to 32 video andaudio inputs. This field shows which audio inputs were selectable asaudio source if this was the currently selected video input. It is abit mask. The LSB corresponds to audio input 0, the MSB to input 31.Any number of bits can be set, or none. When the driverdoes not enumerate audio inputs no bits must be set. Applicationsshall not interpret this as lack of audio support. Some driversautomatically select audio sources and do not enumerate them sincethere is no choice anyway. For details on audio inputs andhow to select the current input see Section 1.5. |
__u32 |
tuner
|
Capture devices can have zero or more tuners (RFdemodulators). When the type is set toV4L2_INPUT_TYPE_TUNER this is an RF connector andthis field identifies the tuner. It corresponds tostruct v4l2_tuner fieldindex . For details ontuners see Section 1.6.
|
v4l2_std_id |
std
|
Every video input supports one or more differentvideo standards. This field is a set of all supported standards. Fordetails on video standards and how to switch seeSection 1.7. |
__u32 |
status
|
This field provides status information about theinput. See Table 3 for flags.status is only valid when this is thecurrent input.
|
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers must setthe array to zero. |
Table 2. Input Types
V4L2_INPUT_TYPE_TUNER
|
1 | This input uses a tuner (RF demodulator). |
V4L2_INPUT_TYPE_CAMERA
|
2 | Analog baseband input, for example CVBS /Composite Video, S-Video, RGB. |
Table 3. Input Status Flags
General | ||
V4L2_IN_ST_NO_POWER
|
0x00000001 | Attached device is off. |
V4L2_IN_ST_NO_SIGNAL
|
0x00000002 | |
V4L2_IN_ST_NO_COLOR
|
0x00000004 | The hardware supports color decoding, but does notdetect color modulation in the signal. |
Analog Video | ||
V4L2_IN_ST_NO_H_LOCK
|
0x00000100 | No horizontal sync lock. |
V4L2_IN_ST_COLOR_KILL
|
0x00000200 | A color killer circuit automatically disables colordecoding when it detects no color modulation. When this flag is setthe color killer is enabledand has shut offcolor decoding. |
Digital Video | ||
V4L2_IN_ST_NO_SYNC
|
0x00010000 | No synchronization lock. |
V4L2_IN_ST_NO_EQU
|
0x00020000 | No equalizer lock. |
V4L2_IN_ST_NO_CARRIER
|
0x00040000 | Carrier recovery failed. |
VCR and Set-Top Box | ||
V4L2_IN_ST_MACROVISION
|
0x01000000 | Macrovision is an analog copy prevention systemmangling the video signal to confuse video recorders. When thisflag is set Macrovision has been detected. |
V4L2_IN_ST_NO_ACCESS
|
0x02000000 | Conditional access denied. |
V4L2_IN_ST_VTR
|
0x04000000 | VTR time constant. [?] |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_input
index
isout of bounds.
ioctl VIDIOC_ENUMOUTPUT
Name
VIDIOC_ENUMOUTPUT -- Enumerate video outputs
Synopsis
int ioctl
(int fd, int request, struct v4l2_output *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENUMOUTPUT
-
argp
Description
To query the attributes of a video outputs applicationsinitialize the index
field of struct v4l2_outputand call theVIDIOC_ENUMOUTPUT
ioctl with apointer to this structure. Drivers fill the rest of the structure orreturn anEINVAL error code when the index is out of bounds. To enumerate alloutputs applications shall begin at index zero, incrementing by oneuntil the driver returnsEINVAL.
Table 1. struct v4l2_output
__u32 |
index
|
Identifies the output, set by theapplication. |
__u8 |
name [32]
|
Name of the video output, a NUL-terminated ASCIIstring, for example: "Vout". This information is intended for theuser, preferably the connector label on the device itself. |
__u32 |
type
|
Type of the output, see Table 2. |
__u32 |
audioset
|
Drivers can enumerate up to 32 video andaudio outputs. This field shows which audio outputs wereselectable as the current output if this was the currently selectedvideo output. It is a bit mask. The LSB corresponds to audio output 0,the MSB to output 31. Any number of bits can be set, ornone. When the driver does not enumerate audio outputs nobits must be set. Applications shall not interpret this as lack ofaudio support. Drivers may automatically select audio outputs withoutenumerating them. For details on audio outputs and how toselect the current output seeSection 1.5. |
__u32 |
modulator
|
Output devices can have zero or more RF modulators.When the type isV4L2_OUTPUT_TYPE_MODULATOR this is an RFconnector and this field identifies the modulator. It corresponds tostruct v4l2_modulator fieldindex . For detailson modulators see Section 1.6.
|
v4l2_std_id |
std
|
Every video output supports one or more differentvideo standards. This field is a set of all supported standards. Fordetails on video standards and how to switch seeSection 1.7. |
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers must setthe array to zero. |
Table 2. Output Type
V4L2_OUTPUT_TYPE_MODULATOR
|
1 | This output is an analog TV modulator. |
V4L2_OUTPUT_TYPE_ANALOG
|
2 | Analog baseband output, for example Composite /CVBS, S-Video, RGB. |
V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY
|
3 | [?] |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_output
index
is out of bounds.
ioctl VIDIOC_ENUMSTD
Name
VIDIOC_ENUMSTD -- Enumerate supported video standards
Synopsis
int ioctl
(int fd, int request, struct v4l2_standard *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_ENUMSTD
-
argp
Description
To query the attributes of a video standard,especially a custom (driver defined) one, applications initialize theindex
field of struct v4l2_standard and call theVIDIOC_ENUMSTD
ioctl with a pointer to thisstructure. Drivers fill the rest of the structure or return anEINVAL error code when the index is out of bounds. To enumerate all standardsapplications shall begin at index zero, incrementing by one until thedriver returns EINVAL. Drivers may enumerate adifferent set of standards after switching the video input oroutput.[23]
Table 1. struct v4l2_standard
__u32 |
index
|
Number of the video standard, set by theapplication. |
v4l2_std_id |
id
|
The bits in this field identify the standard asone of the common standards listed inTable 3,or if bits 32 to 63 are set as custom standards. Multiple bits can beset if the hardware does not distinguish between these standards,however separate indices do not indicate the opposite. Theid must be unique. No other enumeratedv4l2_standard structure, for this input oroutput anyway, can contain the same set of bits.
|
__u8 |
name [24]
|
Name of the standard, a NUL-terminated ASCIIstring, for example: "PAL-B/G", "NTSC Japan". This information isintended for the user. |
struct v4l2_fract |
frameperiod
|
The frame period (not field period) is numerator/ denominator. For example M/NTSC has a frame period of 1001 /30000 seconds. |
__u32 |
framelines
|
Total lines per frame including blanking,e. g. 625 for B/PAL. |
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers must setthe array to zero. |
Table 2. struct v4l2_fract
__u32 |
numerator
|
|
__u32 |
denominator
|
Table 3. typedef v4l2_std_id
__u64 |
v4l2_std_id
|
This type is a set, each bit representing anothervideo standard as listed below and inTable 4. The 32 most significant bits are reservedfor custom (driver defined) video standards. |
#define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001) #define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002) #define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004) #define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008) #define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010) #define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020) #define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040) #define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080)#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100) #define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200) #define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400) #define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800)
V4L2_STD_PAL_60
isa hybrid standard with 525 lines, 60 Hz refresh rate, and PAL colormodulation with a 4.43 MHz color subcarrier. Some PAL video recorderscan play back NTSC tapes in this mode for display on a 50/60 Hz agnosticPAL TV.
#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000) #define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000) #define V4L2_STD_NTSC_443 ((v4l2_std_id)0x00004000)
V4L2_STD_NTSC_443
is a hybrid standard with 525 lines, 60 Hz refresh rate, and NTSCcolor modulation with a 4.43 MHz colorsubcarrier.
#define V4L2_STD_NTSC_M_KR ((v4l2_std_id)0x00008000)#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000) #define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000) #define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000) #define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000) #define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000) #define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000) #define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000) #define V4L2_STD_SECAM_LC ((v4l2_std_id)0x00800000)/* ATSC/HDTV */ #define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000) #define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000)
V4L2_STD_ATSC_8_VSB
andV4L2_STD_ATSC_16_VSB
are U.S. terrestrial digitalTV standards. Presently the V4L2 API does not support digital TV. Seealso the Linux DVB API athttp://linuxtv.org.
#define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\V4L2_STD_PAL_B1 |\V4L2_STD_PAL_G) #define V4L2_STD_B (V4L2_STD_PAL_B |\V4L2_STD_PAL_B1 |\V4L2_STD_SECAM_B) #define V4L2_STD_GH (V4L2_STD_PAL_G |\V4L2_STD_PAL_H |\V4L2_STD_SECAM_G |\V4L2_STD_SECAM_H) #define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\V4L2_STD_PAL_D1 |\V4L2_STD_PAL_K) #define V4L2_STD_PAL (V4L2_STD_PAL_BG |\V4L2_STD_PAL_DK |\V4L2_STD_PAL_H |\V4L2_STD_PAL_I) #define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\V4L2_STD_NTSC_M_JP |\V4L2_STD_NTSC_M_KR) #define V4L2_STD_MN (V4L2_STD_PAL_M |\V4L2_STD_PAL_N |\V4L2_STD_PAL_Nc |\V4L2_STD_NTSC) #define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |\V4L2_STD_SECAM_K |\V4L2_STD_SECAM_K1) #define V4L2_STD_DK (V4L2_STD_PAL_DK |\V4L2_STD_SECAM_DK)#define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\V4L2_STD_SECAM_G |\V4L2_STD_SECAM_H |\V4L2_STD_SECAM_DK |\V4L2_STD_SECAM_L |\V4L2_STD_SECAM_LC)#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\V4L2_STD_PAL_60 |\V4L2_STD_NTSC |\V4L2_STD_NTSC_443) #define V4L2_STD_625_50 (V4L2_STD_PAL |\V4L2_STD_PAL_N |\V4L2_STD_PAL_Nc |\V4L2_STD_SECAM)#define V4L2_STD_UNKNOWN 0 #define V4L2_STD_ALL (V4L2_STD_525_60 |\V4L2_STD_625_50)
Table 4. Video Standards (based on [ITU BT.470])
Characteristics |
M/NTSCa |
M/PAL |
N/PALb |
B, B1, G/PAL | D, D1, K/PAL | H/PAL | I/PAL | B, G/SECAM | D, K/SECAM | K1/SECAM | L/SECAM |
---|---|---|---|---|---|---|---|---|---|---|---|
Frame lines | 525 | 625 | |||||||||
Frame period (s) | 1001/30000 | 1/25 | |||||||||
Chrominance sub-carrier frequency (Hz) | 3579545 ± 10 | 3579611.49 ± 10 | 4433618.75 ± 5 (3582056.25± 5) | 4433618.75 ± 5 | 4433618.75 ± 1 | fOR =4406250 ± 2000, fOB = 4250000± 2000 | |||||
Nominal radio-frequency channel bandwidth(MHz) | 6 | 6 | 6 | B: 7; B1, G: 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 |
Sound carrier relative to vision carrier(MHz) | + 4.5 | + 4.5 | + 4.5 |
+ 5.5 ± 0.001c de f |
+ 6.5 ± 0.001 | + 5.5 | + 5.9996 ± 0.0005 | + 5.5 ± 0.001 | + 6.5 ± 0.001 | + 6.5 |
+ 6.5 g |
Notes: a. Japan uses a standardsimilar to M/NTSC(V4L2_STD_NTSC_M_JP). b. The values inbrackets apply to the combination N/PAL a.k.a.NC used in Argentina(V4L2_STD_PAL_Nc). c. In the Federal Republic of Germany, Austria, Italy,the Netherlands, Slovakia and Switzerland a system of two soundcarriers is used, the frequency of the second carrier being242.1875 kHz above the frequency of the first sound carrier. Forstereophonic sound transmissions a similar system is used inAustralia. d. New Zealand uses a soundcarrier displaced 5.4996 ± 0.0005 MHz from the visioncarrier. e. In Denmark, Finland, NewZealand, Sweden and Spain a system of two sound carriers is used. InIceland, Norway and Poland the same system is being introduced. Thesecond carrier is 5.85 MHz above the vision carrier and is DQPSKmodulated with 728 kbit/s sound and data multiplex. (NICAMsystem) f. In the United Kingdom, asystem of two sound carriers is used. The second sound carrier is6.552 MHz above the vision carrier and is DQPSK modulated with a728 kbit/s sound and data multiplex able to carry two soundchannels. (NICAM system) g. In France, adigital carrier 5.85 MHz away from the vision carrier may be used inaddition to the main sound carrier. It is modulated in differentiallyencoded QPSK with a 728 kbit/s sound and data multiplexer capable ofcarrying two sound channels. (NICAMsystem) |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_standard
index
is out of bounds.
ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO
Name
VIDIOC_G_AUDIO, VIDIOC_S_AUDIO -- Query or select the current audio input and itsattributes
Synopsis
int ioctl
(int fd, int request, struct v4l2_audio *argp);
int ioctl
(int fd, int request, const struct v4l2_audio *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_AUDIO, VIDIOC_S_AUDIO
-
argp
Description
To query the current audio input applications zero out thereserved
array of a struct v4l2_audioand call theVIDIOC_G_AUDIO
ioctl with a pointerto this structure. Drivers fill the rest of the structure or return anEINVAL error code when the device has no audio inputs, or none which combinewith the current video input.
Audio inputs have one writable property, the audio mode. Toselect the current audio inputand change theaudio mode, applications initialize theindex
andmode
fields, and thereserved
array of av4l2_audio
structure and call theVIDIOC_S_AUDIO
ioctl. Drivers may switch to adifferent audio mode if the request cannot be satisfied. However, thisis a write-only ioctl, it does not return the actual new audiomode.
Table 1. struct v4l2_audio
__u32 |
index
|
Identifies the audio input, set by thedriver or application. |
__u8 |
name [32]
|
Name of the audio input, a NUL-terminated ASCIIstring, for example: "Line In". This information is intended for theuser, preferably the connector label on the device itself. |
__u32 |
capability
|
Audio capability flags, see Table 2. |
__u32 |
mode
|
Audio mode flags set by drivers and applications (on VIDIOC_S_AUDIO ioctl), seeTable 3.
|
__u32 |
reserved [2]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. |
Table 2. Audio Capability Flags
V4L2_AUDCAP_STEREO
|
0x00001 | This is a stereo input. The flag is intended toautomatically disable stereo recording etc. when the signal is alwaysmonaural. The API provides no means to detect if stereo isreceived, unless the audio input belongs to atuner. |
V4L2_AUDCAP_AVL
|
0x00002 | Automatic Volume Level mode is supported. |
Table 3. Audio Mode Flags
V4L2_AUDMODE_AVL
|
0x00001 | AVL mode is on. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
No audio inputs combine with the current video input,or the number of the selected audio input is out of bounds or it doesnot combine, or there are no audio inputs at all and the ioctl is notsupported.
- EBUSY
-
I/O is in progress, the input cannot beswitched.
ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT
Name
VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT -- Query or select the current audio output
Synopsis
int ioctl
(int fd, int request, struct v4l2_audioout *argp);
int ioctl
(int fd, int request, const struct v4l2_audioout *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT
-
argp
Description
To query the current audio output applications zero out thereserved
array of a struct v4l2_audioout andcall theVIDIOC_G_AUDOUT
ioctl with a pointerto this structure. Drivers fill the rest of the structure or return anEINVAL error code when the device has no audio inputs, or none which combinewith the current video output.
Audio outputs have no writable properties. Nevertheless, toselect the current audio output applications can initialize theindex
field andreserved
array (which in the future maycontain writable properties) of av4l2_audioout
structure and call theVIDIOC_S_AUDOUT
ioctl. Drivers switch to therequested output or return theEINVAL error code when the index is out ofbounds. This is a write-only ioctl, it does not return the currentaudio output attributes asVIDIOC_G_AUDOUT
does.
Note connectors on a TV card to loop back the received audiosignal to a sound card are not audio outputs in this sense.
Table 1. struct v4l2_audioout
__u32 |
index
|
Identifies the audio output, set by thedriver or application. |
__u8 |
name [32]
|
Name of the audio output, a NUL-terminated ASCIIstring, for example: "Line Out". This information is intended for theuser, preferably the connector label on the device itself. |
__u32 |
capability
|
Audio capability flags, none defined yet. Driversmust set this field to zero. |
__u32 |
mode
|
Audio mode, none defined yet. Drivers andapplications (onVIDIOC_S_AUDOUT ) must set thisfield to zero.
|
__u32 |
reserved [2]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
No audio outputs combine with the current videooutput, or the number of the selected audio output is out of bounds orit does not combine, or there are no audio outputs at all and theioctl is not supported.
- EBUSY
-
I/O is in progress, the output cannot beswitched.
ioctl VIDIOC_G_CHIP_IDENT
Name
VIDIOC_G_CHIP_IDENT -- Identify the chips on a TV card
Synopsis
int ioctl
(int fd, int request, struct v4l2_chip_ident*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_CHIP_IDENT
-
argp
Description
Experimental: This is an experimental interface and may change inthe future.
For driver debugging purposes this ioctl allows testapplications to query the driver about the chips present on the TVcard. Regular applications should not use it. When you found a chipspecific bug, please contact the Video4Linux mailing list (https://listman.redhat.com/mailman/listinfo/video4linux-list)so it can be fixed.
To query the driver applications must initialize thematch_type
andmatch_chip
fields of a struct v4l2_chip_identand call VIDIOC_G_CHIP_IDENT
with a pointer tothis structure. On success the driver stores information about theselected chip in theident
andrevision
fields. On failure the structureremains unchanged.
When match_type
isV4L2_CHIP_MATCH_HOST
,match_chip
selects the nth non-I2C chipon the TV card. You can enumerate all chips by starting at zero andincrementingmatch_chip
by one untilVIDIOC_G_CHIP_IDENT
fails with anEINVAL error code.Drivers may also interpretmatch_chip
as arandom ID, but we recommend against that. The number zero alwaysselects the host chip, e. g. the chip connected to the PCI bus.
When match_type
isV4L2_CHIP_MATCH_I2C_DRIVER
,match_chip
contains a driver ID as definedin thelinux/i2c-id.h header file. For instanceI2C_DRIVERID_SAA7127
will match any chipsupported by the saa7127 driver, regardless of its I2C bus address.When multiple chips supported by the same driver are present, theioctl will returnV4L2_IDENT_AMBIGUOUS
in theident
field.
When match_type
isV4L2_CHIP_MATCH_I2C_ADDR
,match_chip
selects a chip by its 7 bitI2C bus address.
On success, the ident
field willcontain a chip ID from the Linuxmedia/v4l2-chip-ident.h header file, and therevision
field will contain a driverspecific value, or zero if no particular revision is associated withthis chip.
When the driver could not identify the selected chip,ident
will containV4L2_IDENT_UNKNOWN
. When no chip matchedmatch_type
andmatch_chip
, the ioctl will succeed but theident
field will containV4L2_IDENT_NONE
. If multiple chips matched,ident
will containV4L2_IDENT_AMBIGUOUS
. In all these cases therevision
field remains unchanged.
This ioctl is optional, not all drivers may support it. Itwas introduced in Linux 2.6.21.
We recommended the v4l2-dbgutility over calling this ioctl directly. It is available from theLinuxTV v4l-dvb repository; seehttp://linuxtv.org/repo/foraccess instructions.
Table 1. struct v4l2_chip_ident
__u32 |
match_type
|
See Table 2 for a list ofpossible types. |
__u32 |
match_chip
|
Match a chip by this number, interpreted accordingto the match_type field.
|
__u32 |
ident
|
A chip identifier as defined in the Linuxmedia/v4l2-chip-ident.h header file, or one ofthe values fromTable 3. |
__u32 |
revision
|
A chip revision, chip and driver specific. |
Table 2. Chip Match Types
V4L2_CHIP_MATCH_HOST
|
0 | Match the nth chip on the card, zero for the host chip. Does not match I2C chips. |
V4L2_CHIP_MATCH_I2C_DRIVER
|
1 | Match an I2C chip by its driver ID from thelinux/i2c-id.h header file. |
V4L2_CHIP_MATCH_I2C_ADDR
|
2 | Match a chip by its 7 bit I2C bus address. |
Table 3. Chip Identifiers
V4L2_IDENT_NONE
|
0 | No chip matched. |
V4L2_IDENT_AMBIGUOUS
|
1 | Multiple chips matched. |
V4L2_IDENT_UNKNOWN
|
2 | A chip is present at this address, but the drivercould not identify it. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The driver does not support this ioctl, or the
match_type
is invalid.
ioctl VIDIOC_G_CROP, VIDIOC_S_CROP
Name
VIDIOC_G_CROP, VIDIOC_S_CROP -- Get or set the current cropping rectangle
Synopsis
int ioctl
(int fd, int request, struct v4l2_crop *argp);
int ioctl
(int fd, int request, const struct v4l2_crop *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_CROP, VIDIOC_S_CROP
-
argp
Description
To query the cropping rectangle size and positionapplications set the type
field of av4l2_crop
structure to the respective buffer(stream) type and call theVIDIOC_G_CROP
ioctlwith a pointer to this structure. The driver fills the rest of thestructure or returns theEINVAL error code if cropping is not supported.
To change the cropping rectangle applications initialize thetype
and struct v4l2_rect substructure namedc
of a v4l2_crop structure and call theVIDIOC_S_CROP
ioctl with a pointer to thisstructure.
The driver first adjusts the requested dimensions againsthardware limits, i. e. the bounds given by the capture/output window,and it rounds to the closest possible values of horizontal andvertical offset, width and height. In particular the driver must roundthe vertical offset of the cropping rectangle to frame lines modulotwo, such that the field order cannot be confused.
Second the driver adjusts the image size (the oppositerectangle of the scaling process, source or target depending on thedata direction) to the closest size possible while maintaining thecurrent horizontal and vertical scaling factor.
Finally the driver programs the hardware with the actualcropping and image parameters.VIDIOC_S_CROP
is awrite-only ioctl, it does not return the actual parameters. To querythem applications must callVIDIOC_G_CROP
andVIDIOC_G_FMT
. When the parameters are unsuitable the application maymodify the cropping or image parameters and repeat the cycle untilsatisfactory parameters have been negotiated.
When cropping is not supported then no parameters arechanged and VIDIOC_S_CROP
returns theEINVAL error code.
Table 1. struct v4l2_crop
enum v4l2_buf_type |
type
|
Type of the data stream, set by the application.Only these types are valid here:V4L2_BUF_TYPE_VIDEO_CAPTURE ,V4L2_BUF_TYPE_VIDEO_OUTPUT ,V4L2_BUF_TYPE_VIDEO_OVERLAY , and custom (driverdefined) types with codeV4L2_BUF_TYPE_PRIVATE and higher.
|
struct v4l2_rect |
c
|
Cropping rectangle. The same co-ordinate system asfor struct v4l2_cropcapbounds is used.
|
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
Cropping is not supported.
ioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL
Name
VIDIOC_G_CTRL, VIDIOC_S_CTRL -- Get or set the value of a control
Synopsis
int ioctl
(int fd, int request, struct v4l2_control*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_CTRL, VIDIOC_S_CTRL
-
argp
Description
To get the current value of a control applicationsinitialize the id
field of a structv4l2_control
and call theVIDIOC_G_CTRL
ioctl with a pointer to thisstructure. To change the value of a control applications initializetheid
and value
fields of a structv4l2_control
and call theVIDIOC_S_CTRL
ioctl.
When the id
is invalid driversreturn an EINVAL error code. When the value
is outof bounds drivers can choose to take the closest valid value or returnanERANGE error code, whatever seems more appropriate. However,VIDIOC_S_CTRL
is a write-only ioctl, it does notreturn the actual new value.
These ioctls work only with user controls. For othercontrol classes the VIDIOC_G_EXT_CTRLS
, VIDIOC_S_EXT_CTRLS
orVIDIOC_TRY_EXT_CTRLS
must be used.
Table 1. struct v4l2_control
__u32 |
id
|
Identifies the control, set by theapplication. |
__s32 |
value
|
New value or current value. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_control
id
isinvalid. - ERANGE
-
The struct v4l2_control
value
is out of bounds. - EBUSY
-
The control is temporarily not changeable, possiblybecause another applications took over control of the device functionthis control belongs to.
ioctl VIDIOC_G_ENC_INDEX
Name
VIDIOC_G_ENC_INDEX -- Get meta data about a compressed video stream
Synopsis
int ioctl
(int fd, int request, struct v4l2_enc_idx *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_ENC_INDEX
-
argp
Description
Experimental: This is an experimentalinterface and may change in the future.
The VIDIOC_G_ENC_INDEX
ioctl providesmeta data about a compressed video stream the same or anotherapplication currently reads from the driver, which is useful forrandom access into the stream without decoding it.
To read the data applications must callVIDIOC_G_ENC_INDEX
with a pointer to astruct v4l2_enc_idx. On success the driver fills theentry
array, stores the number of elementswritten in the entries
field, andinitializes theentries_cap
field.
Each element of the entry
arraycontains meta data about one picture. AVIDIOC_G_ENC_INDEX
call reads up toV4L2_ENC_IDX_ENTRIES
entries from a driverbuffer, which can hold up to entries_cap
entries. This number can be lower or higher thanV4L2_ENC_IDX_ENTRIES
, but not zero. When theapplication fails to read the meta data in time the oldest entrieswill be lost. When the buffer is empty or no capturing/encoding is inprogress,entries
will be zero.
Currently this ioctl is only defined for MPEG-2 programstreams and video elementary streams.
Table 1. struct v4l2_enc_idx
__u32 |
entries
|
The number of entries the driver stored in theentry array.
|
||
__u32 |
entries_cap
|
The number of entries the driver canbuffer. Must be greater than zero. | ||
__u32 |
reserved [4]
|
Reserved for future extensions.Drivers must set the array to zero. | ||
struct v4l2_enc_idx_entry |
entry [V4L2_ENC_IDX_ENTRIES ]
|
Meta data about a compressed video stream. Eachelement of the array corresponds to one picture, sorted in ascendingorder by theiroffset .
|
Table 2. struct v4l2_enc_idx_entry
__u64 |
offset
|
The offset in bytes from the beginning of thecompressed video stream to the beginning of this picture, that is aPES packet header as defined inISO 13818-1 or apictureheader as defined in ISO 13818-2. Whenthe encoder is stopped, the driver resets the offset to zero. |
__u64 |
pts
|
The 33 bit Presentation TimeStamp of this picture as defined inISO 13818-1. |
__u32 |
length
|
The length of this picture in bytes. |
__u32 |
flags
|
Flags containing the coding type of this picture, see Table 3. |
__u32 |
reserved [2]
|
Reserved for future extensions.Drivers must set the array to zero. |
Table 3. Index Entry Flags
V4L2_ENC_IDX_FRAME_I
|
0x00 | This is an Intra-coded picture. |
V4L2_ENC_IDX_FRAME_P
|
0x01 | This is a Predictive-coded picture. |
V4L2_ENC_IDX_FRAME_B
|
0x02 | This is a Bidirectionally predictive-codedpicture. |
V4L2_ENC_IDX_FRAME_MASK
|
0x0F | AND the flags field withthis mask to obtain the picture coding type. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The driver does not support this ioctl.
ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS,VIDIOC_TRY_EXT_CTRLS
Name
VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS -- Get or set the value of several controls, try controlvalues
Synopsis
int ioctl
(int fd, int request, struct v4l2_ext_controls*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS,VIDIOC_TRY_EXT_CTRLS
-
argp
Description
These ioctls allow the caller to get or set multiplecontrols atomically. Control IDs are grouped into control classes (seeTable 3) and all controls in the control arraymust belong to the same control class.
Applications must always fill in thecount
,ctrl_class
,controls
andreserved
fields of struct v4l2_ext_controls, andinitialize the struct v4l2_ext_controlarray pointed to by thecontrols
fields.
To get the current value of a set of controls applicationsinitialize the id
field of eachstruct v4l2_ext_control and call theVIDIOC_G_EXT_CTRLS
ioctl.
To change the value of a set of controls applicationsinitialize the id
andvalue
fields of a struct v4l2_ext_control andcall theVIDIOC_S_EXT_CTRLS
ioctl. The controlswill only be set ifall control values arevalid.
To check if the a set of controls have correct valuesapplications initialize theid
andvalue
fields of a struct v4l2_ext_control andcall theVIDIOC_TRY_EXT_CTRLS
ioctl. It is up tothe driver whether wrong values are automatically adjusted to a validvalue or if an error is returned.
When the id
orctrl_class
is invalid drivers return anEINVAL error code. When the value is out of bounds drivers can choose to takethe closest valid value or return an ERANGE error code, whatever seems moreappropriate. In the first case the new value is set instruct v4l2_ext_control.
The driver will only set/get these controls if all controlvalues are correct. This prevents the situation where only some of thecontrols were set/get. Only low-level errors (e. g. a failed i2ccommand) can still cause this situation.
Table 1. struct v4l2_ext_control
__u32 |
id
|
Identifies the control, set by theapplication. | |
__u32 |
reserved2 [2]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. | |
union | (anonymous) | ||
__s32 |
value
|
New value or current value. | |
__s64 |
value64
|
New value or current value. | |
void * |
reserved
|
Reserved for future pointer-type controls. Currently unused. |
Table 2. struct v4l2_ext_controls
__u32 |
ctrl_class
|
The control class to which all controls belong, seeTable 3. |
__u32 |
count
|
The number of controls in the controls array. Mayalso be zero. |
__u32 |
error_idx
|
Set by the driver in case of an error. It is theindex of the control causing the error or equal to 'count' when theerror is not associated with a particular control. Undefined when theioctl returns 0 (success). |
__u32 |
reserved [2]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. |
struct v4l2_ext_control * |
controls
|
Pointer to an array ofcount v4l2_ext_control structures. Ignoredifcount equals zero.
|
Table 3. Control classes
V4L2_CTRL_CLASS_USER
|
0x980000 |
The class containing user controls. These controlsare described inSection 1.8. All controls that can be setusing the VIDIOC_S_CTRL andVIDIOC_G_CTRL ioctl belong to thisclass.
|
V4L2_CTRL_CLASS_MPEG
|
0x990000 | The class containing MPEG compression controls.These controls are described in sectionSection 1.9.5. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_ext_control
id
is invalid or the struct v4l2_ext_controlsctrl_class
is invalid. This error code isalso returned by theVIDIOC_S_EXT_CTRLS
andVIDIOC_TRY_EXT_CTRLS
ioctls if two or morecontrol values are in conflict. - ERANGE
-
The struct v4l2_ext_control
value
is out of bounds. - EBUSY
-
The control is temporarily not changeable, possiblybecause another applications took over control of the device functionthis control belongs to.
ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF
Name
VIDIOC_G_FBUF, VIDIOC_S_FBUF -- Get or set frame buffer overlay parameters
Synopsis
int ioctl
(int fd, int request, struct v4l2_framebuffer *argp);
int ioctl
(int fd, int request, const struct v4l2_framebuffer *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_FBUF, VIDIOC_S_FBUF
-
argp
Description
Applications can use the VIDIOC_G_FBUF
andVIDIOC_S_FBUF
ioctl to get and set theframebuffer parameters for aVideoOverlay orVideo Output Overlay(OSD). The type of overlay is implied by the device type (capture oroutput device) and can be determined with theVIDIOC_QUERYCAP
ioctl.One/dev/videoN device must not support bothkinds of overlay.
The V4L2 API distinguishes destructive and non-destructiveoverlays. A destructive overlay copies captured video images into thevideo memory of a graphics card. A non-destructive overlay blendsvideo images into a VGA signal or graphics into a video signal.Video Output Overlays are alwaysnon-destructive.
To get the current parameters applications call theVIDIOC_G_FBUF
ioctl with a pointer to av4l2_framebuffer
structure. The driver fillsall fields of the structure or returns anEINVAL error code when overlays arenot supported.
To set the parameters for a Video OutputOverlay, applications must initialize theflags
field of a structv4l2_framebuffer
. Since the framebuffer isimplemented on the TV card all other parameters are determined by thedriver. When an application callsVIDIOC_S_FBUF
with a pointer to this structure, the driver prepares for the overlayand returns the framebuffer parameters asVIDIOC_G_FBUF
does, or it returns an errorcode.
To set the parameters for a non-destructiveVideo Overlay, applications must initialize theflags
field, thefmt
substructure, and callVIDIOC_S_FBUF
. Again the driver prepares for theoverlay and returns the framebuffer parameters asVIDIOC_G_FBUF
does, or it returns an errorcode.
For a destructive Video Overlayapplications must additionally provide abase
address. Setting up a DMA to arandom memory location can jeopardize the system security, itsstability or even damage the hardware, therefore only the superusercan set the parameters for a destructive video overlay.
Table 1. struct v4l2_framebuffer
__u32 |
capability
|
Overlay capability flags set by the driver, seeTable 2. | |
__u32 |
flags
|
Overlay control flags set by application anddriver, seeTable 3 | |
void * |
base
|
Physical base address of the framebuffer,that is the address of the pixel in the top left corner of theframebuffer.a This field is irrelevant tonon-destructive Video Overlays. Fordestructive Video Overlays applications mustprovide a base address. The driver may accept only base addresseswhich are a multiple of two, four or eight bytes. ForVideo Output Overlays the driver must returna valid base address, so applications can find the corresponding Linuxframebuffer device (seeSection 4.4). |
|
struct v4l2_pix_format |
fmt
|
Layout of the frame buffer. Thev4l2_pix_format structure is defined inChapter 2, for clarification the fields and acceptable values are listed below:
|
|
__u32 |
width
|
Width of the frame buffer in pixels. | |
__u32 |
height
|
Height of the frame buffer in pixels. | |
__u32 |
pixelformat
|
The pixel format of theframebuffer. For non-destructive VideoOverlays this field only defines a format for thestruct v4l2_window For destructive VideoOverlays applications must initialize this field. ForVideo Output Overlays the driver must returna valid format. Usually this is an RGB format (for example |
|
enum v4l2_field |
field
|
Drivers and applications shall ignore this field.If applicable, the field order is selected with theVIDIOC_S_FMT ioctl, using thefield field ofstruct v4l2_window.
|
|
__u32 |
bytesperline
|
Distance in bytes between the leftmost pixels intwo adjacent lines. | |
This field is irrelevant tonon-destructive VideoOverlays. For destructive VideoOverlays both applications and drivers can set this fieldto request padding bytes at the end of each line. Drivers however mayignore the requested value, returning For Video OutputOverlays the driver must return a validvalue. Video hardware may access padding bytes, thereforethey must reside in accessible memory. Consider for example the casewhere padding bytes after the last line of an image cross a systempage boundary. Capture devices may write padding bytes, the value isundefined. Output devices ignore the contents of paddingbytes. When the image format is planar the |
|||
__u32 |
sizeimage
|
This field is irrelevant tonon-destructive Video Overlays. Fordestructive Video Overlays applications mustinitialize this field. ForVideo OutputOverlays the driver must return a validformat. Together with |
|
enum v4l2_colorspace |
colorspace
|
This information supplements thepixelformat and must be set by the driver,seeSection 2.2.
|
|
__u32 |
priv
|
Reserved for additional information about custom(driver defined) formats. When not used drivers and applications mustset this field to zero. | |
Notes: a. A physical base address may not suit allplatforms. GK notes in theory we should pass something like PCI device+ memory region + offset instead. If you encounter problems pleasediscuss on the Video4Linux mailing list:https://listman.redhat.com/mailman/listinfo/video4linux-list. |
Table 2. Frame Buffer Capability Flags
V4L2_FBUF_CAP_EXTERNOVERLAY
|
0x0001 | The device is capable of non-destructive overlays.When the driver clears this flag, only destructive overlays aresupported. There are no drivers yet which support both destructive andnon-destructive overlays. |
V4L2_FBUF_CAP_CHROMAKEY
|
0x0002 | The device supports clipping by chroma-keying theimages. That is, image pixels replace pixels in the VGA or videosignal only where the latter assume a certain color. Chroma-keyingmakes no sense for destructive overlays. |
V4L2_FBUF_CAP_LIST_CLIPPING
|
0x0004 | The device supports clipping using a list of cliprectangles. |
V4L2_FBUF_CAP_BITMAP_CLIPPING
|
0x0008 | The device supports clipping using a bit mask. |
V4L2_FBUF_CAP_LOCAL_ALPHA
|
0x0010 | The device supports clipping/blending using thealpha channel of the framebuffer or VGA signal. Alpha blending makesno sense for destructive overlays. |
V4L2_FBUF_CAP_GLOBAL_ALPHA
|
0x0020 | The device supports alpha blending using a globalalpha value. Alpha blending makes no sense for destructive overlays. |
V4L2_FBUF_CAP_LOCAL_INV_ALPHA
|
0x0040 | The device supports clipping/blending using theinverted alpha channel of the framebuffer or VGA signal. Alphablending makes no sense for destructive overlays. |
Table 3. Frame Buffer Flags
V4L2_FBUF_FLAG_PRIMARY
|
0x0001 | The framebuffer is the primary graphics surface.In other words, the overlay is destructive. [?] |
V4L2_FBUF_FLAG_OVERLAY
|
0x0002 | The frame buffer is an overlay surface the samesize as the capture. [?] |
The purpose ofV4L2_FBUF_FLAG_PRIMARY andV4L2_FBUF_FLAG_OVERLAY was never quite clear.Most drivers seem to ignore these flags. For compatibility with thebttv driver applications should set theV4L2_FBUF_FLAG_OVERLAY flag.
|
||
V4L2_FBUF_FLAG_CHROMAKEY
|
0x0004 |
Use chroma-keying. The chroma-key color isdetermined by the chromakey field ofstruct v4l2_window and negotiated with theVIDIOC_S_FMT ioctl, seeSection 4.2andSection 4.4.
|
There are no flags to enableclipping using a list of clip rectangles or a bitmap. These methodsare negotiated with theVIDIOC_S_FMT ioctl, seeSection 4.2 andSection 4.4.
|
||
V4L2_FBUF_FLAG_LOCAL_ALPHA
|
0x0008 | Use the alpha channel of the framebuffer to clip orblend framebuffer pixels with video images. The blendfunction is: output = framebuffer pixel * alpha + video pixel * (1 -alpha). The actual alpha depth depends on the framebuffer pixelformat. |
V4L2_FBUF_FLAG_GLOBAL_ALPHA
|
0x0010 |
Use a global alpha value to blend the framebufferwith video images. The blend function is: output = (framebuffer pixel* alpha + video pixel * (255 - alpha)) / 255. The alpha value isdetermined by theglobal_alpha field ofstruct v4l2_window and negotiated with theVIDIOC_S_FMT ioctl, seeSection 4.2andSection 4.4.
|
V4L2_FBUF_FLAG_LOCAL_INV_ALPHA
|
0x0020 |
LikeV4L2_FBUF_FLAG_LOCAL_ALPHA , use the alpha channelof the framebuffer to clip or blend framebuffer pixels with videoimages, but with an inverted alpha value. The blend function is:output = framebuffer pixel * (1 - alpha) + video pixel * alpha. Theactual alpha depth depends on the framebuffer pixel format.
|
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EPERM
-
VIDIOC_S_FBUF
can only be calledby a privileged user to negotiate the parameters for a destructiveoverlay. - EBUSY
-
The framebuffer parameters cannot be changed at thistime because overlay is already enabled, or capturing is enabledand the hardware cannot capture and overlay simultaneously.
- EINVAL
-
The ioctl is not supported or the
VIDIOC_S_FBUF
parameters are unsuitable.
ioctl VIDIOC_G_FMT, VIDIOC_S_FMT,VIDIOC_TRY_FMT
Name
VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT -- Get or set the data format, try a format
Synopsis
int ioctl
(int fd, int request, struct v4l2_format*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT
-
argp
Description
These ioctls are used to negotiate the format of data(typically image format) exchanged between driver andapplication.
To query the current parameters applications set thetype
field of a structv4l2_format
to the respective buffer (stream)type. For example video capture devices useV4L2_BUF_TYPE_VIDEO_CAPTURE
. When the applicationcalls the VIDIOC_G_FMT
ioctl with a pointer tothis structure the driver fills the respective member of thefmt
union. In case of video capture devicesthat is the struct v4l2_pix_formatpix
member.When the requested buffer type is not supported drivers return anEINVAL error code.
To change the current format parameters applicationsinitialize the type
field and allfields of the respective fmt
union member. For details see the documentation of the various devicestypes inChapter 4. Good practice is to query thecurrent parameters first, and tomodify only those parameters not suitable for the application. Whenthe application calls theVIDIOC_S_FMT
ioctlwith a pointer to av4l2_format
structurethe driver checksand adjusts the parameters against hardware abilities. Driversshould not return an error code unless the input is ambiguous, this isa mechanism to fathom device capabilities and to approach parametersacceptable for both the application and driver. On success the drivermay program the hardware, allocate resources and generally prepare fordata exchange.Finally theVIDIOC_S_FMT
ioctl returns thecurrent format parameters asVIDIOC_G_FMT
does.Very simple, inflexible devices may even ignore all input and alwaysreturn the default parameters. However all V4L2 devices exchangingdata with the application must implement theVIDIOC_G_FMT
andVIDIOC_S_FMT
ioctl. When the requested buffertype is not supported drivers return anEINVAL error code on aVIDIOC_S_FMT
attempt. When I/O is already inprogress or the resource is not available for other reasons driversreturn theEBUSY error code.
The VIDIOC_TRY_FMT
ioctl is equivalentto VIDIOC_S_FMT
with one exception: it does notchange driver state. It can also be called at any time, neverreturningEBUSY. This function is provided tonegotiate parameters, to learn about hardware limitations, withoutdisabling I/O or possibly time consuming hardware preparations.Although strongly recommended drivers are not required to implementthis ioctl.
Table 1. struct v4l2_format
enum v4l2_buf_type |
type
|
Type of the data stream, see Table 3-2. | |
union |
fmt
|
||
struct v4l2_pix_format |
pix
|
Definition of an image format, seeChapter 2, used by video capture and outputdevices. | |
struct v4l2_window |
win
|
Definition of an overlaid image, seeSection 4.2, used by video overlay devices. | |
struct v4l2_vbi_format |
vbi
|
Raw VBI capture or output parameters. This isdiscussed in more detail in Section 4.7. Used by raw VBIcapture and output devices. | |
struct v4l2_sliced_vbi_format |
sliced
|
Sliced VBI capture or output parameters. SeeSection 4.8 for details. Used by sliced VBIcapture and output devices. | |
__u8 |
raw_data [200]
|
Place holder for future extensions and custom(driver defined) formats with type V4L2_BUF_TYPE_PRIVATE and higher.
|
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EBUSY
-
The data format cannot be changed at thistime, for example because I/O is already in progress.
- EINVAL
-
The struct v4l2_format
type
field is invalid, the requested buffer type not supported, orVIDIOC_TRY_FMT
was called and is notsupported with this buffer type.
ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY
Name
VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY -- Get or set tuner or modulator radiofrequency
Synopsis
int ioctl
(int fd, int request, struct v4l2_frequency*argp);
int ioctl
(int fd, int request, const struct v4l2_frequency*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY
-
argp
Description
To get the current tuner or modulator radio frequencyapplications set the tuner
field of astruct v4l2_frequency to the respective tuner or modulator number (onlyinput devices have tuners, only output devices have modulators), zeroout thereserved
array andcall the VIDIOC_G_FREQUENCY
ioctl with a pointerto this structure. The driver stores the current frequency in thefrequency
field.
To change the current tuner or modulator radio frequencyapplications initialize thetuner
,type
andfrequency
fields, and thereserved
array of a struct v4l2_frequency andcall theVIDIOC_S_FREQUENCY
ioctl with a pointerto this structure. When the requested frequency is not possible thedriver assumes the closest possible value. HoweverVIDIOC_S_FREQUENCY
is a write-only ioctl, it doesnot return the actual new frequency.
Table 1. struct v4l2_frequency
__u32 |
tuner
|
The tuner or modulator index number. This is thesame value as in the struct v4l2_inputtuner field and the struct v4l2_tunerindex field, orthe struct v4l2_outputmodulator field and thestruct v4l2_modulatorindex field.
|
enum v4l2_tuner_type |
type
|
The tuner type. This is the same value as in thestruct v4l2_tunertype field. The field is notapplicable to modulators, i. e. ignored by drivers.
|
__u32 |
frequency
|
Tuning frequency in units of 62.5 kHz, or if thestruct v4l2_tuner or struct v4l2_modulatorcapabilities flagV4L2_TUNER_CAP_LOW is set, in units of 62.5Hz.
|
__u32 |
reserved [8];
|
Reserved for future extensions. Drivers and applications must set the array to zero. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The
tuner
index is out ofbounds or the value in thetype
field iswrong.
ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT
Name
VIDIOC_G_INPUT, VIDIOC_S_INPUT -- Query or select the current video input
Synopsis
int ioctl
(int fd, int request, int *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_INPUT, VIDIOC_S_INPUT
-
argp
Description
To query the current video input applications call theVIDIOC_G_INPUT
ioctl with a pointer to an integerwhere the driver stores the number of the input, as in thestruct v4l2_inputindex
field. This ioctl willfail only when there are no video inputs, returningEINVAL.
To select a video input applications store the number of thedesired input in an integer and call theVIDIOC_S_INPUT
ioctl with a pointer to thisinteger. Side effects are possible. For example inputs may supportdifferent video standards, so the driver may implicitly switch thecurrent standard. It is good practice to select an input beforequerying or negotiating any other parameters.
Information about video inputs is available using theVIDIOC_ENUMINPUT
ioctl.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The number of the video input is out of bounds, orthere are no video inputs at all and this ioctl is notsupported.
- EBUSY
-
I/O is in progress, the input cannot beswitched.
ioctl VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP
Name
VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP --
Synopsis
int ioctl
(int fd, int request, v4l2_jpegcompression *argp);
int ioctl
(int fd, int request, const v4l2_jpegcompression *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP
-
argp
Description
[to do]
Ronald Bultje elaborates:
APP is some application-specific information. Theapplication can set it itself, and it'll be stored in the JPEG-encodedfields (eg; interlacing information for in an AVI or so). COM is thesame, but it's comments, like 'encoded by me' or so.
jpeg_markers describes whether the huffman tables,quantization tables and the restart interval information (allJPEG-specific stuff) should be stored in the JPEG-encoded fields.These define how the JPEG field is encoded. If you omit them,applications assume you've used standard encoding. You usually do wantto add them.
Table 1. struct v4l2_jpegcompression
int |
quality
|
|
int |
APPn
|
|
int |
APP_len
|
|
char |
APP_data [60]
|
|
int |
COM_len
|
|
char |
COM_data [60]
|
|
__u32 |
jpeg_markers
|
See Table 2. |
Table 2. JPEG Markers Flags
V4L2_JPEG_MARKER_DHT
|
(1<<3) | Define Huffman Tables |
V4L2_JPEG_MARKER_DQT
|
(1<<4) | Define Quantization Tables |
V4L2_JPEG_MARKER_DRI
|
(1<<5) | Define Restart Interval |
V4L2_JPEG_MARKER_COM
|
(1<<6) | Comment segment |
V4L2_JPEG_MARKER_APP
|
(1<<7) | App segment, driver will always use APP0 |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
This ioctl is not supported.
ioctl VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR
Name
VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR -- Get or set modulator attributes
Synopsis
int ioctl
(int fd, int request, struct v4l2_modulator*argp);
int ioctl
(int fd, int request, const struct v4l2_modulator*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR
-
argp
Description
To query the attributes of a modulator applications initializethe index
field and zero out thereserved
array of a struct v4l2_modulator andcall theVIDIOC_G_MODULATOR
ioctl with a pointerto this structure. Drivers fill the rest of the structure or return anEINVAL error code when the index is out of bounds. To enumerate all modulatorsapplications shall begin at index zero, incrementing by one until thedriver returns EINVAL.
Modulators have two writable properties, an audiomodulation set and the radio frequency. To change the modulated audiosubprograms, applications initialize theindex
andtxsubchans
fields and thereserved
array and call theVIDIOC_S_MODULATOR
ioctl. Drivers may choose adifferent audio modulation if the request cannot be satisfied. Howeverthis is a write-only ioctl, it does not return the actual audiomodulation selected.
To change the radio frequency the VIDIOC_S_FREQUENCY
ioctlis available.
Table 1. struct v4l2_modulator
__u32 |
index
|
Identifies the modulator, set by theapplication. |
__u8 |
name [32]
|
Name of the modulator, a NUL-terminated ASCIIstring. This information is intended for the user. |
__u32 |
capability
|
Modulator capability flags. No flags are definedfor this field, the tuner flags in struct v4l2_tunerare used accordingly. The audio flags indicate the abilityto encode audio subprograms. They will notchange for example with the current video standard. |
__u32 |
rangelow
|
The lowest tunable frequency in units of 62.5KHz, or if the capability flagV4L2_TUNER_CAP_LOW is set, in units of 62.5Hz.
|
__u32 |
rangehigh
|
The highest tunable frequency in units of 62.5KHz, or if the capability flagV4L2_TUNER_CAP_LOW is set, in units of 62.5Hz.
|
__u32 |
txsubchans
|
With this field applications can determine howaudio sub-carriers shall be modulated. It contains a set of flags asdefined inTable 2. Note the tunerrxsubchans flags are reused, but thesemantics are different. Video output devices are assumed to have ananalog or PCM audio input with 1-3 channels. Thetxsubchans flags select one or morechannels for modulation, together with some audio subprogramindicator, for example a stereo pilot tone.
|
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. |
Table 2. Modulator Audio Transmission Flags
V4L2_TUNER_SUB_MONO
|
0x0001 |
Modulate channel 1 as mono audio, when the inputhas more channels, a down-mix of channel 1 and 2. This flag does notcombine withV4L2_TUNER_SUB_STEREO orV4L2_TUNER_SUB_LANG1 .
|
V4L2_TUNER_SUB_STEREO
|
0x0002 |
Modulate channel 1 and 2 as left and rightchannel of a stereo audio signal. When the input has only one channelor two channels andV4L2_TUNER_SUB_SAP is alsoset, channel 1 is encoded as left and right channel. This flag doesnot combine withV4L2_TUNER_SUB_MONO orV4L2_TUNER_SUB_LANG1 . When the driver does notsupport stereo audio it shall fall back to mono.
|
V4L2_TUNER_SUB_LANG1
|
0x0008 |
Modulate channel 1 and 2 as primary and secondarylanguage of a bilingual audio signal. When the input has only onechannel it is used for both languages. It is not possible to encodethe primary or secondary language only. This flag does not combinewithV4L2_TUNER_SUB_MONO orV4L2_TUNER_SUB_STEREO . If the hardware does notsupport the respective audio matrix, or the current video standarddoes not permit bilingual audio theVIDIOC_S_MODULATOR ioctl shall return anEINVAL error codeand the driver shall fall back to mono or stereo mode.
|
V4L2_TUNER_SUB_LANG2
|
0x0004 |
Same effect asV4L2_TUNER_SUB_LANG1 .
|
V4L2_TUNER_SUB_SAP
|
0x0004 |
When combined with V4L2_TUNER_SUB_MONO the first channel is encoded as mono audio, the lastchannel as Second Audio Program. When the input has only one channelit is used for both audio tracks. When the input has three channelsthe mono track is a down-mix of channel 1 and 2. When combined withV4L2_TUNER_SUB_STEREO channel 1 and 2 areencoded as left and right stereo audio, channel 3 as Second AudioProgram. When the input has only two channels, the first is encoded asleft and right channel and the second as SAP. When the input has onlyone channel it is used for all audio tracks. It is not possible toencode a Second Audio Program only. This flag must combine withV4L2_TUNER_SUB_MONO orV4L2_TUNER_SUB_STEREO . If the hardware does notsupport the respective audio matrix, or the current video standarddoes not permit SAP theVIDIOC_S_MODULATOR ioctlshall return anEINVAL error code and driver shall fall back to mono or stereomode.
|
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_modulator
index
is out of bounds.
ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT
Name
VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT -- Query or select the current video output
Synopsis
int ioctl
(int fd, int request, int *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT
-
argp
Description
To query the current video output applications call theVIDIOC_G_OUTPUT
ioctl with a pointer to an integerwhere the driver stores the number of the output, as in thestruct v4l2_outputindex
field. This ioctlwill fail only when there are no video outputs, returning theEINVAL error code.
To select a video output applications store the number of thedesired output in an integer and call theVIDIOC_S_OUTPUT
ioctl with a pointer to this integer.Side effects are possible. For example outputs may support differentvideo standards, so the driver may implicitly switch the currentstandard. It is good practice to select an output before querying ornegotiating any other parameters.
Information about video outputs is available using theVIDIOC_ENUMOUTPUT
ioctl.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The number of the video output is out of bounds, orthere are no video outputs at all and this ioctl is notsupported.
- EBUSY
-
I/O is in progress, the output cannot beswitched.
ioctl VIDIOC_G_PARM, VIDIOC_S_PARM
Name
VIDIOC_G_PARM, VIDIOC_S_PARM -- Get or set streaming parameters
Synopsis
int ioctl
(int fd, int request, v4l2_streamparm *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_PARM, VIDIOC_S_PARM
-
argp
Description
The current video standard determines a nominal number offrames per second. If less than this number of frames is to becaptured or output, applications can request frame skipping orduplicating on the driver side. This is especially useful when usingtheread()
or write()
, whichare not augmented by timestamps or sequence counters, and to avoidunneccessary data copying.
Further these ioctls can be used to determine the number ofbuffers used internally by a driver in read/write mode. Forimplications see the section discussing theread()
function.
To get and set the streaming parameters applications callthe VIDIOC_G_PARM
andVIDIOC_S_PARM
ioctl, respectively. They take apointer to a structv4l2_streamparm
whichcontains a union holding separate parameters for input and outputdevices.
Table 1. struct v4l2_streamparm
enum v4l2_buf_type |
type
|
The buffer (stream) type, same as struct v4l2_formattype , set by the application.
|
|
union |
parm
|
||
struct v4l2_captureparm |
capture
|
Parameters for capture devices, used whentype isV4L2_BUF_TYPE_VIDEO_CAPTURE .
|
|
struct v4l2_outputparm |
output
|
Parameters for output devices, used whentype isV4L2_BUF_TYPE_VIDEO_OUTPUT .
|
|
__u8 |
raw_data [200]
|
A place holder for future extensions and custom(driver defined) buffer types V4L2_BUF_TYPE_PRIVATE andhigher.
|
Table 2. struct v4l2_captureparm
__u32 |
capability
|
See Table 4. |
__u32 |
capturemode
|
Set by drivers and applications, see Table 5. |
struct v4l2_fract |
timeperframe
|
This is is the desired period betweensuccessive frames captured by the driver, in seconds. Thefield is intended to skip frames on the driver side, saving I/Obandwidth. Applications store here the desired frameperiod, drivers return the actual frame period, which must be greateror equal to the nominal frame period determined by the current videostandard (struct v4l2_standard Drivers support this function only when they set the |
__u32 |
extendedmode
|
Custom (driver specific) streaming parameters. Whenunused, applications and drivers must set this field to zero.Applications using this field should check the driver name andversion, seeSection 1.2. |
__u32 |
readbuffers
|
Applications set this field to the desired numberof buffers used internally by the driver inread() mode. Driversreturn the actual number of buffers. When an application requests zerobuffers, drivers should just return the current setting rather thanthe minimum or an error code. For details seeSection 3.1.
|
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. |
Table 3. struct v4l2_outputparm
__u32 |
capability
|
See Table 4. |
__u32 |
outputmode
|
Set by drivers and applications, see Table 5. |
struct v4l2_fract |
timeperframe
|
This is is the desired period betweensuccessive frames output by the driver, in seconds. |
The field is intended torepeat frames on the driver side in Applications store here the desired frameperiod, drivers return the actual frame period, which must be greateror equal to the nominal frame period determined by the current videostandard (struct v4l2_standard Drivers support this function only when they set the |
||
__u32 |
extendedmode
|
Custom (driver specific) streaming parameters. Whenunused, applications and drivers must set this field to zero.Applications using this field should check the driver name andversion, seeSection 1.2. |
__u32 |
writebuffers
|
Applications set this field to the desired numberof buffers used internally by the driver inwrite() mode. Drivers return the actual number ofbuffers. When an application requests zero buffers, drivers shouldjust return the current setting rather than the minimum or an errorcode. For details seeSection 3.1.
|
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. |
Table 4. Streaming Parameters Capabilites
V4L2_CAP_TIMEPERFRAME
|
0x1000 |
The frame skipping/repeating controlled by thetimeperframe field is supported.
|
Table 5. Capture Parameters Flags
V4L2_MODE_HIGHQUALITY
|
0x0001 |
High quality imaging mode. High quality modeis intended for still imaging applications. The idea is to get thebest possible image quality that the hardware can deliver. It is notdefined how the driver writer may achieve that; it will depend on thehardware and the ingenuity of the driver writer. High quality mode isa different mode from the the regular motion video capture modes. Inhigh quality mode:
|
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
This ioctl is not supported.
ioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY
Name
VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY -- Query or request the access priority associated with afile descriptor
Synopsis
int ioctl
(int fd, int request, enum v4l2_priority *argp);
int ioctl
(int fd, int request, const enum v4l2_priority *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY
-
argp
-
Pointer to an enum v4l2_priority type.
Description
To query the current access priorityapplications call the VIDIOC_G_PRIORITY
ioctlwith a pointer to an enum v4l2_priority variable where the driver storesthe current priority.
To request an access priority applications store thedesired priority in an enum v4l2_priority variable and callVIDIOC_S_PRIORITY
ioctl with a pointer to thisvariable.
Table 1. enum v4l2_priority
V4L2_PRIORITY_UNSET
|
0 | |
V4L2_PRIORITY_BACKGROUND
|
1 | Lowest priority, usually applications running inbackground, for example monitoring VBI transmissions. A proxyapplication running in user space will be necessary if multipleapplications want to read from a device at this priority. |
V4L2_PRIORITY_INTERACTIVE
|
2 | |
V4L2_PRIORITY_DEFAULT
|
2 | Medium priority, usually applications started andinteractively controlled by the user. For example TV viewers, Teletextbrowsers, or just "panel" applications to change the channel or videocontrols. This is the default priority unless an application requestsanother. |
V4L2_PRIORITY_RECORD
|
3 | Highest priority. Only one file descriptor can havethis priority, it blocks any other fd from changing device properties.Usually applications which must not be interrupted, like videorecording. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The requested priority value is invalid, or thedriver does not support access priorities.
- EBUSY
-
Another application already requested higherpriority.
ioctl VIDIOC_G_SLICED_VBI_CAP
Name
VIDIOC_G_SLICED_VBI_CAP -- Query sliced VBI capabilities
Synopsis
int ioctl
(int fd, int request, struct v4l2_sliced_vbi_cap *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_SLICED_VBI_CAP
-
argp
Description
To find out which data services are supported by a slicedVBI capture or output device, applications initialize thetype
field of a struct v4l2_sliced_vbi_cap,clear the reserved
array andcall the VIDIOC_G_SLICED_VBI_CAP
ioctl. Thedriver fills in the remaining fields or returns anEINVAL error code if thesliced VBI API is unsupported ortype
is invalid.
Note the type
field was added,and the ioctl changed from read-only to write-read, in Linux 2.6.19.
Table 1. struct v4l2_sliced_vbi_cap
__u16 |
service_set
|
A set of all data servicessupported by the driver. Equal to the union of all elements of theservice_lines array.
|
||
__u16 |
service_lines [2][24]
|
Each element of this arraycontains a set of data services the hardware can look for or insertinto a particular scan line. Data services are defined inTable 2. Array indices map to ITU-Rline numbers (see alsoFigure 4-2 andFigure 4-3) as follows: | ||
Element | 525 line systems | 625 line systems | ||
service_lines [0][1]
|
1 | 1 | ||
service_lines [0][23]
|
23 | 23 | ||
service_lines [1][1]
|
264 | 314 | ||
service_lines [1][23]
|
286 | 336 | ||
The number of VBI lines thehardware can capture or output per frame, or the number of services itcan identify on a given line may be limited. For example on PAL line16 the hardware may be able to look for a VPS or Teletext signal, butnot both at the same time. Applications can learn about these limitsusing theVIDIOC_S_FMT ioctl as described in Section 4.8.
|
||||
Drivers must setservice_lines [0][0] andservice_lines [1][0] to zero.
|
||||
enum v4l2_buf_type |
type
|
Type of the data stream, see Table 3-2. Should beV4L2_BUF_TYPE_SLICED_VBI_CAPTURE orV4L2_BUF_TYPE_SLICED_VBI_OUTPUT .
|
||
__u32 |
reserved [3]
|
This array is reserved for futureextensions. Applications and drivers must set it to zero. |
Table 2. Sliced VBI services
Symbol | Value | Reference | Lines, usually | Payload |
---|---|---|---|---|
V4L2_SLICED_TELETEXT_B (TeletextSystem B)
|
0x0001 | ETS 300 706,ITU BT.653 | PAL/SECAM line 7-22, 320-335 (second field 7-22) | Last 42 of the 45 byte Teletext packet, that iswithout clock run-in and framing code, lsb first transmitted. |
V4L2_SLICED_VPS
|
0x0400 | ETS 300 231 | PAL line 16 | Byte number 3 to 15 according to Figure 9 ofETS 300 231, lsb first transmitted. |
V4L2_SLICED_CAPTION_525
|
0x1000 | EIA 608-B | NTSC line 21, 284 (second field 21) | Two bytes in transmission order, including paritybit, lsb first transmitted. |
V4L2_SLICED_WSS_625
|
0x4000 | EN 300 294,ITU BT.1119 | PAL/SECAM line 23 |
Byte 0 1msb lsb msb lsb Bit 7 6 5 4 3 2 1 0 x x 13 12 11 10 9 |
V4L2_SLICED_VBI_525
|
0x1000 | Set of services applicable to 525line systems. | ||
V4L2_SLICED_VBI_625
|
0x4401 | Set of services applicable to 625line systems. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The device does not support sliced VBI capturing oroutput, or the value in the
type
field iswrong.
ioctl VIDIOC_G_STD, VIDIOC_S_STD
Name
VIDIOC_G_STD, VIDIOC_S_STD -- Query or select the video standard of the current input
Synopsis
int ioctl
(int fd, int request, v4l2_std_id*argp);
int ioctl
(int fd, int request, const v4l2_std_id*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_STD, VIDIOC_S_STD
-
argp
Description
To query and select the current video standard applicationsuse the VIDIOC_G_STD
and VIDIOC_S_STD
ioctls which take a pointer to av4l2_std_id type as argument.VIDIOC_G_STD
canreturn a single flag or a set of flags as in struct v4l2_standard fieldid
. The flags must be unambiguous suchthat they appear in only one enumeratedv4l2_standard
structure.
VIDIOC_S_STD
accepts one or moreflags, being a write-only ioctl it does not return the actual new standard asVIDIOC_G_STD
does. When no flags are given orthe current input does not support the requested standard the driverreturns an EINVAL error code. When the standard set is ambiguous drivers mayreturnEINVAL or choose any of the requestedstandards.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
This ioctl is not supported, or the
VIDIOC_S_STD
parameter was unsuitable.
ioctl VIDIOC_G_TUNER, VIDIOC_S_TUNER
Name
VIDIOC_G_TUNER, VIDIOC_S_TUNER -- Get or set tuner attributes
Synopsis
int ioctl
(int fd, int request, struct v4l2_tuner*argp);
int ioctl
(int fd, int request, const struct v4l2_tuner*argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_G_TUNER, VIDIOC_S_TUNER
-
argp
Description
To query the attributes of a tuner applications initialize theindex
field and zero out thereserved
array of a struct v4l2_tuner and call theVIDIOC_G_TUNER
ioctl with a pointer to thisstructure. Drivers fill the rest of the structure or return anEINVAL error code when the index is out of bounds. To enumerate all tunersapplications shall begin at index zero, incrementing by one until thedriver returns EINVAL.
Tuners have two writable properties, the audio mode andthe radio frequency. To change the audio mode, applications initializetheindex
,audmode
andreserved
fields and call theVIDIOC_S_TUNER
ioctl. This willnot change the current tuner, which is determinedby the current video input. Drivers may choose a different audio modeif the requested mode is invalid or unsupported. Since this is awrite-only ioctl, it does not return the actuallyselected audio mode.
To change the radio frequency the VIDIOC_S_FREQUENCY
ioctlis available.
Table 1. struct v4l2_tuner
__u32 |
index
|
Identifies the tuner, set by theapplication. | |
__u8 |
name [32]
|
Name of the tuner, aNUL-terminated ASCII string. This information is intended for theuser. |
|
enum v4l2_tuner_type |
type
|
Type of the tuner, see Table 2. | |
__u32 |
capability
|
Tuner capability flags, seeTable 3. Audio flags indicate the abilityto decode audio subprograms. They willnotchange, for example with the current video standard. Whenthe structure refers to a radio tuner only the |
|
__u32 |
rangelow
|
The lowest tunable frequency inunits of 62.5 kHz, or if the capability flagV4L2_TUNER_CAP_LOW is set, in units of 62.5Hz.
|
|
__u32 |
rangehigh
|
The highest tunable frequency inunits of 62.5 kHz, or if the capability flagV4L2_TUNER_CAP_LOW is set, in units of 62.5Hz.
|
|
__u32 |
rxsubchans
|
Some tuners or audiodecoders can determine the received audio subprograms by analyzingaudio carriers, pilot tones or other indicators. To pass thisinformation drivers set flags defined inTable 4 in this field. Forexample: |
|
V4L2_TUNER_SUB_MONO
|
receiving mono audio | ||
STEREO | SAP
|
receiving stereo audio and a secondary audioprogram | ||
MONO | STEREO
|
receiving mono or stereo audio, the hardware cannotdistinguish | ||
LANG1 | LANG2
|
receiving bilingual audio | ||
MONO | STEREO | LANG1 | LANG2
|
receiving mono, stereo or bilingualaudio | ||
When the This field is valid only if this is the tuner of thecurrent video input, or when the structure refers to a radiotuner. |
|||
__u32 |
audmode
|
The selected audio mode, seeTable 5 for valid values. The audio mode doesnot affect audio subprogram detection, and like acontrol it does not automatically changeunless the requested mode is invalid or unsupported. SeeTable 6 for possible results whenthe selected and received audio programs do notmatch. Currently this is the only field of struct |
|
__u32 |
signal
|
The signal strength if known, rangingfrom 0 to 65535. Higher values indicate a better signal. | |
__s32 |
afc
|
Automatic frequency control: When theafc value is negative, the frequency is toolow, when positive too high.
|
|
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers andapplications must set the array to zero. |
Table 2. enum v4l2_tuner_type
V4L2_TUNER_RADIO
|
1 | |
V4L2_TUNER_ANALOG_TV
|
2 |
Table 3. Tuner and Modulator Capability Flags
V4L2_TUNER_CAP_LOW
|
0x0001 | When set, tuning frequencies are expressed in units of62.5 Hz, otherwise in units of 62.5 kHz. |
V4L2_TUNER_CAP_NORM
|
0x0002 |
This is a multi-standard tuner; the video standardcan or must be switched. (B/G PAL tuners for example are typically not considered multi-standard because the video standard is automatically determined from the frequency band.) The set of supported video standards is available from the struct v4l2_input pointing to this tuner, see the description of ioctlVIDIOC_ENUMINPUT for details. OnlyV4L2_TUNER_ANALOG_TV tuners can have this capability.
|
V4L2_TUNER_CAP_STEREO
|
0x0010 | Stereo audio reception is supported. |
V4L2_TUNER_CAP_LANG1
|
0x0040 |
Reception of the primary language of a bilingualaudio program is supported. Bilingual audio is a feature oftwo-channel systems, transmitting the primary language monaural on themain audio carrier and a secondary language monaural on a secondcarrier. OnlyV4L2_TUNER_ANALOG_TV tuners can have this capability.
|
V4L2_TUNER_CAP_LANG2
|
0x0020 |
Reception of the secondary language of a bilingualaudio program is supported. OnlyV4L2_TUNER_ANALOG_TV tuners can have this capability.
|
V4L2_TUNER_CAP_SAP
|
0x0020 |
Reception of a secondary audio program issupported. This is a feature of the BTSC system which accompanies theNTSC video standard. Two audio carriers are available for mono orstereo transmissions of a primary language, and an independent thirdcarrier for a monaural secondary language. Only Note the |
Table 4. Tuner Audio Reception Flags
V4L2_TUNER_SUB_MONO
|
0x0001 | The tuner receives a mono audio signal. |
V4L2_TUNER_SUB_STEREO
|
0x0002 | The tuner receives a stereo audio signal. |
V4L2_TUNER_SUB_LANG1
|
0x0008 |
The tuner receives the primary language of abilingual audio signal. Drivers must clear this flag when the currentvideo standard isV4L2_STD_NTSC_M .
|
V4L2_TUNER_SUB_LANG2
|
0x0004 | The tuner receives the secondary language of abilingual audio signal (or a second audio program). |
V4L2_TUNER_SUB_SAP
|
0x0004 |
The tuner receives a Second Audio Program. Note theV4L2_TUNER_SUB_LANG2 andV4L2_TUNER_SUB_SAP flags are synonyms. TheV4L2_TUNER_SUB_SAP flag applies when thecurrent video standard isV4L2_STD_NTSC_M .
|
Table 5. Tuner Audio Modes
V4L2_TUNER_MODE_MONO
|
0 | Play mono audio. When the tuner receives a stereosignal this a down-mix of the left and right channel. When the tunerreceives a bilingual or SAP signal this mode selects the primarylanguage. |
V4L2_TUNER_MODE_STEREO
|
1 |
Play stereo audio. When the tuner receivesbilingual audio it may play different languages on the left and rightchannel or the primary language on both channels. behave as in monomode. Playing different languages in this mode isdeprecated. New drivers should do this only in When the tunerreceives no stereo signal or does not support stereo reception thedriver shall fall back to |
V4L2_TUNER_MODE_LANG1
|
3 |
Play the primary language, mono or stereo. OnlyV4L2_TUNER_ANALOG_TV tuners support thismode.
|
V4L2_TUNER_MODE_LANG2
|
2 |
Play the secondary language, mono. When the tunerreceives no bilingual audio or SAP, or their reception is notsupported the driver shall fall back to mono or stereo mode. OnlyV4L2_TUNER_ANALOG_TV tuners support thismode.
|
V4L2_TUNER_MODE_SAP
|
2 |
Play the Second Audio Program. When the tunerreceives no bilingual audio or SAP, or their reception is notsupported the driver shall fall back to mono or stereo mode. OnlyV4L2_TUNER_ANALOG_TV tuners support this mode.Note theV4L2_TUNER_MODE_LANG2 andV4L2_TUNER_MODE_SAP are synonyms.
|
V4L2_TUNER_MODE_LANG1_LANG2
|
4 |
Play the primary language on the left channel, thesecondary language on the right channel. When the tuner receives nobilingual audio or SAP, it shall fall back toMODE_LANG1 orMODE_MONO .OnlyV4L2_TUNER_ANALOG_TV tuners support thismode.
|
Table 6. Tuner Audio Matrix
SelectedV4L2_TUNER_MODE_
|
|||||
---|---|---|---|---|---|
ReceivedV4L2_TUNER_SUB_
|
MONO
|
STEREO
|
LANG1
|
LANG2 = SAP
|
LANG1_LANG2 [a]
|
MONO
|
Mono | Mono/Mono | Mono | Mono | Mono/Mono |
MONO | SAP
|
Mono | Mono/Mono | Mono | SAP | Mono/SAP (preferred) or Mono/Mono |
STEREO
|
L+R | L/R | Stereo L/R (preferred) or Mono L+R | Stereo L/R (preferred) or Mono L+R | L/R (preferred) or L+R/L+R |
STEREO | SAP
|
L+R | L/R | Stereo L/R (preferred) or Mono L+R | SAP | L+R/SAP (preferred) or L/R or L+R/L+R |
LANG1 | LANG2
|
Language 1 | Lang1/Lang2 (deprecated[b]) orLang1/Lang1 | Language 1 | Language 2 | Lang1/Lang2 (preferred) or Lang1/Lang1 |
Notes: a. This mode has been added in Linux 2.6.17 and may not be supported by olderdrivers. b. Playback ofboth languages in MODE_STEREO is deprecated. Inthe future drivers should produce only the primary language in thismode. Applications should requestMODE_LANG1_LANG2 to record both languages or astereo signal.
|
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_tuner
index
isout of bounds.
ioctl VIDIOC_LOG_STATUS
Name
VIDIOC_LOG_STATUS -- Log driver status information
Synopsis
int ioctl
(int fd, int request);
Description
As the video/audio devices become more complicated itbecomes harder to debug problems. When this ioctl is called the driverwill output the current device status to the kernel log. This isparticular useful when dealing with problems like no sound, no videoand incorrectly tuned channels. Also many modern devices autodetectvideo and audio standards and this ioctl will report what the devicethinks what the standard is. Mismatches may give an indication wherethe problem is.
This ioctl is optional and not all drivers support it. Itwas introduced in Linux 2.6.15.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The driver does not support this ioctl.
ioctl VIDIOC_OVERLAY
Name
VIDIOC_OVERLAY -- Start or stop video overlay
Synopsis
int ioctl
(int fd, int request, const int *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_OVERLAY
-
argp
Description
This ioctl is part of the video overlay I/O method. Applications call VIDIOC_OVERLAY
to start or stop the overlay. It takes a pointer to an integer which must be set to zero by the application to stop overlay, to one to start.
Drivers do not support VIDIOC_STREAMON
orVIDIOC_STREAMOFF
withV4L2_BUF_TYPE_VIDEO_OVERLAY
.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
Video overlay is not supported, or theparameters have not been set up. See Section 4.2 for the necessary steps.
ioctl VIDIOC_QBUF, VIDIOC_DQBUF
Name
VIDIOC_QBUF, VIDIOC_DQBUF -- Exchange a buffer with the driver
Synopsis
int ioctl
(int fd, int request, struct v4l2_buffer *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_QBUF, VIDIOC_DQBUF
-
argp
Description
Applications call the VIDIOC_QBUF
ioctlto enqueue an empty (capturing) or filled (output) buffer in thedriver's incoming queue. The semantics depend on the selected I/Omethod.
To enqueue a memory mappedbuffer applications set the type
field of astruct v4l2_buffer to the same buffer type as previously struct v4l2_formattype
and struct v4l2_requestbufferstype
, thememory
field toV4L2_MEMORY_MMAP
and theindex
field. Valid index numbers range fromzero to the number of buffers allocated withVIDIOC_REQBUFS
(struct v4l2_requestbufferscount
) minus one. Thecontents of the struct v4l2_buffer
returnedby aVIDIOC_QUERYBUF
ioctl will do as well. When the buffer isintended for output (type
isV4L2_BUF_TYPE_VIDEO_OUTPUT
orV4L2_BUF_TYPE_VBI_OUTPUT
) applications must alsoinitialize thebytesused
,field
andtimestamp
fields. SeeSection 3.5 for details. WhenVIDIOC_QBUF
is called with a pointer to thisstructure the driver sets theV4L2_BUF_FLAG_MAPPED
andV4L2_BUF_FLAG_QUEUED
flags and clears theV4L2_BUF_FLAG_DONE
flag in theflags
field, or it returns anEINVAL error code.
To enqueue a user pointerbuffer applications set the type
field of astruct v4l2_buffer to the same buffer type as previously struct v4l2_formattype
and struct v4l2_requestbufferstype
, thememory
field toV4L2_MEMORY_USERPTR
and them.userptr
field to the address of thebuffer andlength
to its size. When thebuffer is intended for output additional fields must be set as above.WhenVIDIOC_QBUF
is called with a pointer to thisstructure the driver sets theV4L2_BUF_FLAG_QUEUED
flag and clears theV4L2_BUF_FLAG_MAPPED
andV4L2_BUF_FLAG_DONE
flags in theflags
field, or it returns an error code.This ioctl locks the memory pages of the buffer in physical memory,they cannot be swapped out to disk. Buffers remain locked untildequeued, until theVIDIOC_STREAMOFF
orVIDIOC_REQBUFS
ioctl arecalled, or until the device is closed.
Applications call the VIDIOC_DQBUF
ioctl to dequeue a filled (capturing) or displayed (output) bufferfrom the driver's outgoing queue. They just set thetype
andmemory
fields of a struct v4l2_buffer as above, whenVIDIOC_DQBUF
is called with a pointer to this structure the driver fills theremaining fields or returns an error code.
By default VIDIOC_DQBUF
blocks when nobuffer is in the outgoing queue. When theO_NONBLOCK
flag was given to theopen()
function,VIDIOC_DQBUF
returns immediatelywith an EAGAIN error code when no buffer is available.
The v4l2_buffer
structure isspecified in Section 3.5.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EAGAIN
-
Non-blocking I/O has been selected using
O_NONBLOCK
and no buffer was in the outgoingqueue. - EINVAL
-
The buffer
type
is notsupported, or theindex
is out of bounds,or no buffers have been allocated yet, or theuserptr
orlength
are invalid. - ENOMEM
-
Not enough physical or virtual memory was available toenqueue a user pointer buffer.
- EIO
-
VIDIOC_DQBUF
failed due to aninternal error. Can also indicate temporary problems like signalloss. Note the driver might dequeue an (empty) buffer despitereturning an error, or even stop capturing.
ioctl VIDIOC_QUERYBUF
Name
VIDIOC_QUERYBUF -- Query the status of a buffer
Synopsis
int ioctl
(int fd, int request, struct v4l2_buffer *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_QUERYBUF
-
argp
Description
This ioctl is part of the memorymapping I/O method. It can be used to query the status of abuffer at any time after buffers have been allocated with theVIDIOC_REQBUFS
ioctl.
Applications set the type
field of a struct v4l2_buffer to the same buffer type as previouslystruct v4l2_formattype
and struct v4l2_requestbufferstype
, and theindex
field. Valid index numbers range from zeroto the number of buffers allocated withVIDIOC_REQBUFS
(struct v4l2_requestbufferscount
) minus one.After calling VIDIOC_QUERYBUF
with a pointer to this structure drivers return an error code or fill the rest ofthe structure.
In the flags
field theV4L2_BUF_FLAG_MAPPED
,V4L2_BUF_FLAG_QUEUED
andV4L2_BUF_FLAG_DONE
flags will be valid. Thememory
field will be set toV4L2_MEMORY_MMAP
, the m.offset
contains the offset of the buffer from the start of the device memory,thelength
field its size. The driver mayor may not set the remaining fields and flags, they are meaningless inthis context.
The v4l2_buffer
structure is specified in Section 3.5.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The buffer
type
is notsupported, or theindex
is out of bounds.
ioctl VIDIOC_QUERYCAP
Name
VIDIOC_QUERYCAP -- Query device capabilities
Synopsis
int ioctl
(int fd, int request, struct v4l2_capability *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_QUERYCAP
-
argp
Description
All V4L2 devices support theVIDIOC_QUERYCAP
ioctl. It is used to identifykernel devices compatible with this specification and to obtaininformation about driver and hardware capabilities. The ioctl takes apointer to a struct v4l2_capability which is filled by the driver. When thedriver is not compatible with this specification the ioctl returns anEINVAL error code.
Table 1. struct v4l2_capability
__u8 |
driver [16]
|
Name of the driver, a unique NUL-terminatedASCII string. For example: "bttv". Driver specific applications canuse this information to verify the driver identity. It is also usefulto work around known bugs, or to identify drivers in error reports.The driver version is stored in the Storing strings in fixed sized arrays is badpractice but unavoidable here. Drivers and applications should takeprecautions to never read or write beyond the end of the array and tomake sure the strings are properly NUL-terminated. |
__u8 |
card [32]
|
Name of the device, a NUL-terminated ASCII string.For example: "Yoyodyne TV/FM". One driver may support different brandsor models of video hardware. This information is intended for users,for example in a menu of available devices. Since multiple TV cards ofthe same brand may be installed which are supported by the samedriver, this name should be combined with the character device filename (e. g./dev/video2) or thebus_info string to avoidambiguities.
|
__u8 |
bus_info [32]
|
Location of the device in the system, aNUL-terminated ASCII string. For example: "PCI Slot 4". Thisinformation is intended for users, to distinguish multipleidentical devices. If no such information is available the field maysimply count the devices controlled by the driver, or contain theempty string (bus_info [0] = 0).
|
__u32 |
version
|
Version number of the driver. Together withthe |
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))__u32 version = KERNEL_VERSION(0, 8, 1);printf ("Version: %u.%u.%u\n",(version >> 16) & 0xFF,(version >> 8) & 0xFF,version & 0xFF); |
||
__u32 |
capabilities
|
Device capabilities, see Table 2. |
__u32 |
reserved [4]
|
Reserved for future extensions. Drivers must setthis array to zero. |
Table 2. Device Capabilities Flags
V4L2_CAP_VIDEO_CAPTURE
|
0x00000001 | The device supports the Video Capture interface. |
V4L2_CAP_VIDEO_OUTPUT
|
0x00000002 | The device supports the Video Output interface. |
V4L2_CAP_VIDEO_OVERLAY
|
0x00000004 | The device supports the Video Overlay interface. A video overlay devicetypically stores captured images directly in the video memory of agraphics card, with hardware clipping and scaling. |
V4L2_CAP_VBI_CAPTURE
|
0x00000010 | The device supports the RawVBI Capture interface, providing Teletext and Closed Captiondata. |
V4L2_CAP_VBI_OUTPUT
|
0x00000020 | The device supports the Raw VBI Output interface. |
V4L2_CAP_SLICED_VBI_CAPTURE
|
0x00000040 | The device supports the Sliced VBI Capture interface. |
V4L2_CAP_SLICED_VBI_OUTPUT
|
0x00000080 | The device supports the Sliced VBI Output interface. |
V4L2_CAP_RDS_CAPTURE
|
0x00000100 | [to be defined] |
V4L2_CAP_VIDEO_OUTPUT_OVERLAY
|
0x00000200 |
The device supports the VideoOutput Overlay (OSD) interface. Unlike theVideoOverlay interface, this is a secondary function of videooutput devices and overlays an image onto an outgoing video signal.When the driver sets this flag, it must clear theV4L2_CAP_VIDEO_OVERLAY flag and viceversa.[a]
|
V4L2_CAP_TUNER
|
0x00010000 | The device has some sort of tuner or modulator toreceive or emit RF-modulated video signals. For more information abouttuner and modulator programming seeSection 1.6. |
V4L2_CAP_AUDIO
|
0x00020000 | The device has audio inputs or outputs. It may ormay not support audio recording or playback, in PCM or compressedformats. PCM audio support must be implemented as ALSA or OSSinterface. For more information on audio inputs and outputs seeSection 1.5. |
V4L2_CAP_RADIO
|
0x00040000 | This is a radio receiver. |
V4L2_CAP_READWRITE
|
0x01000000 | The device supports the read() and/or write()I/O methods. |
V4L2_CAP_ASYNCIO
|
0x02000000 | The device supports the asynchronous I/O methods. |
V4L2_CAP_STREAMING
|
0x04000000 | The device supports the streaming I/O method. |
Notes: a. The struct v4l2_framebuffer lacks anenum v4l2_buf_type field, therefore the type of overlay is implied by thedriver capabilities. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The device is not compatible with thisspecification.
ioctl VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU
Name
VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU -- Enumerate controls and menu control items
Synopsis
int ioctl
(int fd, int request, struct v4l2_queryctrl *argp);
int ioctl
(int fd, int request, struct v4l2_querymenu *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU
-
argp
Description
To query the attributes of a control applications set theid
field of a struct v4l2_queryctrl and call theVIDIOC_QUERYCTRL
ioctl with a pointer to thisstructure. The driver fills the rest of the structure or returns anEINVAL error code when theid
is invalid.
It is possible to enumerate controls by callingVIDIOC_QUERYCTRL
with successiveid
values starting fromV4L2_CID_BASE
up to and exclusiveV4L2_CID_BASE_LASTP1
. Drivers may returnEINVAL if a control in this range is notsupported. Further applications can enumerate private controls, whichare not defined in this specification, by starting atV4L2_CID_PRIVATE_BASE
and incrementingid
until the driver returnsEINVAL.
In both cases, when the driver sets theV4L2_CTRL_FLAG_DISABLED
flag in theflags
field this control is permanentlydisabled and should be ignored by the application.[24]
When the application ORs id
withV4L2_CTRL_FLAG_NEXT_CTRL
the driver returns thenext supported control, orEINVAL if there isnone. Drivers which do not support this flag yet always returnEINVAL.
Additional information is required for menu controls, thename of menu items. To query them applications set theid
andindex
fields of struct v4l2_querymenu and call theVIDIOC_QUERYMENU
ioctl with a pointer to thisstructure. The driver fills the rest of the structure or returns anEINVALerror code when theid
orindex
is invalid. Menu items are enumeratedby callingVIDIOC_QUERYMENU
with successiveindex
values from struct v4l2_queryctrlminimum
(0) tomaximum
, inclusive.
See also the examples in Section 1.8.
Table 1. struct v4l2_queryctrl
__u32 |
id
|
Identifies the control, set by the application. SeeTable 1-1 for predefined IDs. When the ID is ORedwith V4L2_CTRL_FLAG_NEXT_CTRL the driver clears the flag and returnsthe first control with a higher ID. Drivers which do not support thisflag yet always return anEINVAL error code. |
enum v4l2_ctrl_type |
type
|
Type of control, see Table 3. |
__u8 |
name [32]
|
Name of the control, a NUL-terminated ASCIIstring. This information is intended for the user. |
__s32 |
minimum
|
Minimum value, inclusive. This field gives a lowerbound forV4L2_CTRL_TYPE_INTEGER controls. It maynot be valid for any other type of control, includingV4L2_CTRL_TYPE_INTEGER64 controls. Note this is asigned value.
|
__s32 |
maximum
|
Maximum value, inclusive. This field gives an upperbound forV4L2_CTRL_TYPE_INTEGER controls and thehighest valid index forV4L2_CTRL_TYPE_MENU controls. It may not be valid for any other type of control, includingV4L2_CTRL_TYPE_INTEGER64 controls. Note this is asigned value.
|
__s32 |
step
|
This field gives a step size for Generally drivers should not scale hardwarecontrol values. It may be necessary for example when the This field gives the smallest change ofan integer control actually affecting hardware. Often the informationis needed when the user can change controls by keyboard or GUIbuttons, rather than a slider. When for example a hardware registeraccepts values 0-511 and the driver reports 0-65535, step should be128. Note although signed, the step value is supposed tobe always positive. |
__s32 |
default_value
|
The default value of aV4L2_CTRL_TYPE_INTEGER ,_BOOLEAN or_MENU control.Not valid for other types of controls. Drivers reset controls onlywhen the driver is loaded, not later, in particular not when thefunc-open; is called.
|
__u32 |
flags
|
Control flags, see Table 4. |
__u32 |
reserved [2]
|
Reserved for future extensions. Drivers must setthe array to zero. |
Table 2. struct v4l2_querymenu
__u32 |
id
|
Identifies the control, set by the applicationfrom the respective struct v4l2_queryctrlid .
|
__u32 |
index
|
Index of the menu item, starting at zero, set by the application. |
__u8 |
name [32]
|
Name of the menu item, a NUL-terminated ASCIIstring. This information is intended for the user. |
__u32 |
reserved
|
Reserved for future extensions. Drivers must setthe array to zero. |
Table 3. enum v4l2_ctrl_type
Type |
minimum
|
step
|
maximum
|
Description |
---|---|---|---|---|
V4L2_CTRL_TYPE_INTEGER
|
any | any | any | An integer-valued control ranging from minimum tomaximum inclusive. The step value indicates the increment betweenvalues which are actually different on the hardware. |
V4L2_CTRL_TYPE_BOOLEAN
|
0 | 1 | 1 | A boolean-valued control. Zero corresponds to"disabled", and one means "enabled". |
V4L2_CTRL_TYPE_MENU
|
0 | 1 | N-1 |
The control has a menu of N choices. The names ofthe menu items can be enumerated with theVIDIOC_QUERYMENU ioctl.
|
V4L2_CTRL_TYPE_BUTTON
|
0 | 0 | 0 |
A control which performs an action when set.Drivers must ignore the value passed withVIDIOC_S_CTRL and return anEINVAL error code on aVIDIOC_G_CTRL attempt.
|
V4L2_CTRL_TYPE_INTEGER64
|
n/a | n/a | n/a | A 64-bit integer valued control. Minimum, maximumand step size cannot be queried. |
V4L2_CTRL_TYPE_CTRL_CLASS
|
n/a | n/a | n/a |
This is not a control. WhenVIDIOC_QUERYCTRL is called with a control IDequal to a control class code (seeTable 3), theioctl returns the name of the control class and this control type.Older drivers which do not support this feature return anEINVAL error code.
|
Table 4. Control Flags
V4L2_CTRL_FLAG_DISABLED
|
0x0001 | This control is permanently disabled and should beignored by the application. Any attempt to change the control willresult in anEINVAL error code. |
V4L2_CTRL_FLAG_GRABBED
|
0x0002 | This control is temporarily unchangeable, forexample because another application took over control of therespective resource. Such controls may be displayed specially in auser interface. Attempts to change the control may result in anEBUSY error code. |
V4L2_CTRL_FLAG_READ_ONLY
|
0x0004 | This control is permanently readable only. Anyattempt to change the control will result in anEINVAL error code. |
V4L2_CTRL_FLAG_UPDATE
|
0x0008 | A hint that changing this control may affect thevalue of other controls within the same control class. Applicationsshould update their user interface accordingly. |
V4L2_CTRL_FLAG_INACTIVE
|
0x0010 | This control is not applicable to the currentconfiguration and should be displayed accordingly in a user interface.For example the flag may be set on a MPEG audio level 2 bitratecontrol when MPEG audio encoding level 1 was selected with anothercontrol. |
V4L2_CTRL_FLAG_SLIDER
|
0x0020 | A hint that this control is best represented as aslider-like element in a user interface. |
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
The struct v4l2_queryctrl
id
is invalid. The struct v4l2_querymenuid
orindex
is invalid.
ioctl VIDIOC_QUERYSTD
Name
VIDIOC_QUERYSTD -- Sense the video standard received by the currentinput
Synopsis
int ioctl
(int fd, int request, v4l2_std_id *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_QUERYSTD
-
argp
Description
The hardware may be able to detect the current videostandard automatically. To do so, applications callVIDIOC_QUERYSTD
with a pointer to av4l2_std_idtype. Thedriver stores here a set of candidates, this can be a single flag or aset of supported standards if for example the hardware can onlydistinguish between 50 and 60 Hz systems. When detection is notpossible or fails, the set must contain all standards supported by thecurrent video input or output.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
This ioctl is not supported.
ioctl VIDIOC_REQBUFS
Name
VIDIOC_REQBUFS -- Initiate Memory Mapping or User Pointer I/O
Synopsis
int ioctl
(int fd, int request, struct v4l2_requestbuffers *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_REQBUFS
-
argp
Description
This ioctl is used to initiate memorymapped or user pointerI/O. Memory mapped buffers are located in device memory and must beallocated with this ioctl before they can be mapped into theapplication's address space. User buffers are allocated byapplications themselves, and this ioctl is merely used to switch thedriver into user pointer I/O mode.
To allocate device buffers applications initialize threefields of a v4l2_requestbuffers
structure.They set the type
field to the respectivestream or buffer type, thecount
field tothe desired number of buffers, andmemory
must be set to V4L2_MEMORY_MMAP
. When the ioctlis called with a pointer to this structure the driver attempts toallocate the requested number of buffers and stores the actual numberallocated in thecount
field. It can besmaller than the number requested, even zero, when the driver runs outof free memory. A larger number is possible when the driver requiresmore buffers to function correctly.[25] When memory mapping I/O is not supported the ioctlreturns an EINVAL error code.
Applications can call VIDIOC_REQBUFS
again to change the number of buffers, however this cannot succeedwhen any buffers are still mapped. Acount
value of zero frees all buffers, after aborting or finishing any DMAin progress, an implicitVIDIOC_STREAMOFF
.
To negotiate user pointer I/O, applications initialize onlythe type
field and setmemory
toV4L2_MEMORY_USERPTR
. When the ioctl is calledwith a pointer to this structure the driver prepares for user pointerI/O, when this I/O method is not supported the ioctl returns anEINVAL error code.
Table 1. struct v4l2_requestbuffers
__u32 |
count
|
The number of buffers requested or granted. Thisfield is only used whenmemory is set toV4L2_MEMORY_MMAP .
|
enum v4l2_buf_type |
type
|
Type of the stream or buffers, this is the sameas the struct v4l2_formattype field. SeeTable 3-2 for valid values.
|
enum v4l2_memory |
memory
|
Applications set this field toV4L2_MEMORY_MMAP orV4L2_MEMORY_USERPTR .
|
__u32 |
reserved [2]
|
A place holder for future extensions and custom(driver defined) buffer types V4L2_BUF_TYPE_PRIVATE andhigher.
|
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EBUSY
-
The driver supports multiple opens and I/O is alreadyin progress, or reallocation of buffers was attempted although one ormore are still mapped.
- EINVAL
-
The buffer type (
type
field) or therequested I/O method (memory
) is notsupported.
ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF
Name
VIDIOC_STREAMON, VIDIOC_STREAMOFF -- Start or stop streaming I/O
Synopsis
int ioctl
(int fd, int request, const int *argp);
Arguments
-
fd
-
File descriptor returned by
open()
. -
request
-
VIDIOC_STREAMON, VIDIOC_STREAMOFF
-
argp
Description
The VIDIOC_STREAMON
andVIDIOC_STREAMOFF
ioctl start and stop the captureor output process during streaming (memorymapping oruser pointer) I/O.
Specifically the capture hardware is disabled and no inputbuffers are filled (if there are any empty buffers in the incomingqueue) untilVIDIOC_STREAMON
has been called.Accordingly the output hardware is disabled, no video signal isproduced untilVIDIOC_STREAMON
has been called.The ioctl will succeed only when at least one output buffer is in theincoming queue.
The VIDIOC_STREAMOFF
ioctl, apart ofaborting or finishing any DMA in progress, unlocks any user pointerbuffers locked in physical memory, and it removes all buffers from theincoming and outgoing queues. That means all images captured but notdequeued yet will be lost, likewise all images enqueued for output butnot transmitted yet. I/O returns to the same state as after callingVIDIOC_REQBUFS
and can be restarted accordingly.
Both ioctls take a pointer to an integer, the desired buffer orstream type. This is the same as struct v4l2_requestbufferstype
.
Note applications can be preempted for unknown periods rightbefore or after theVIDIOC_STREAMON
orVIDIOC_STREAMOFF
calls, there is no notion ofstarting or stopping "now". Buffer timestamps can be used tosynchronize with other events.
Return Value
On success 0 is returned, on error -1 and the errno
variable is set appropriately:
- EINVAL
-
Streaming I/O is not supported, the buffer
type
is not supported, or no buffers havebeen allocated (memory mapping) or enqueued (output) yet.
V4L2 mmap()
Name
v4l2-mmap -- Map device memory into application address space
Synopsis
#include <unistd.h> #include <sys/mman.h>
void *mmap
(void *start, size_t length, int prot, int flags, int fd, off_t offset);
Arguments
-
start
-
Map the buffer to this address in the application's address space. When the
MAP_FIXED
flag is specified,start
must be a multiple of thepagesize and mmap will fail when the specified addresscannot be used. Use of this option is discouraged; applications shouldjust specify aNULL
pointer here. -
length
-
Length of the memory area to map. This must be thesame value as returned by the driver in the struct v4l2_buffer
length
field. -
prot
-
The
prot
argument describes thedesired memory protection. Regardless of the device type and thedirection of data exchange it should be set toPROT_READ
|PROT_WRITE
,permitting read and write access to image buffers. Drivers shouldsupport at least this combination of flags. Note the Linuxvideo-buf kernel module, which is used by thebttv, saa7134, saa7146, cx88 and vivi driver supports onlyPROT_READ
|PROT_WRITE
. Whenthe driver does not support the desired protection themmap()
function fails.Note device memory accesses (e. g. the memory on agraphics card with video capturing hardware) may incur a performancepenalty compared to main memory accesses, or reads may besignificantly slower than writes or vice versa. Other I/O methods maybe more efficient in this case.
-
flags
-
The
flags
parameterspecifies the type of the mapped object, mapping options and whethermodifications made to the mapped copy of the page are private to theprocess or are to be shared with other references.MAP_FIXED
requests that thedriver selects no other address than the one specified. If thespecified address cannot be used,mmap()
will fail. IfMAP_FIXED
is specified,start
must be a multiple of the pagesize. Useof this option is discouraged.One of the
MAP_SHARED
orMAP_PRIVATE
flags must be set.MAP_SHARED
allows applications to share themapped memory with other (e. g. child-) processes. Note the Linuxvideo-buf module which is used by the bttv,saa7134, saa7146, cx88 and vivi driver supports onlyMAP_SHARED
.MAP_PRIVATE
requests copy-on-write semantics. V4L2 applications should not set theMAP_PRIVATE
,MAP_DENYWRITE
,MAP_EXECUTABLE
orMAP_ANON
flag. -
fd
-
File descriptor returned by
open()
. -
offset
-
Offset of the buffer in device memory. This must be thesame value as returned by the driver in the struct v4l2_buffer
m
unionoffset
field.
Description
The mmap()
function asks to maplength
bytes starting atoffset
in the memory of the device specified byfd
into the application address space,preferably at address start
. This latteraddress is a hint only, and is usually specified as 0.
Suitable length and offset parameters are queried with theVIDIOC_QUERYBUF
ioctl. Buffers must be allocated with theVIDIOC_REQBUFS
ioctl before they can be queried.
To unmap buffers the munmap()
function is used.
Return Value
On success mmap()
returns a pointer tothe mapped buffer. On errorMAP_FAILED
(-1) isreturned, and theerrno
variable is setappropriately. Possible error codes are:
- EBADF
-
fd
is not a valid filedescriptor. - EACCES
-
fd
isnot open for reading and writing. - EINVAL
-
The
start
orlength
oroffset
are notsuitable. (E. g. they are too large, or not aligned on aPAGESIZE
boundary.)The
flags
orprot
value is not supported.No buffers have been allocated with the
VIDIOC_REQBUFS
ioctl. - ENOMEM
-
Not enough physical or virtual memory was available tocomplete the request.
V4L2 munmap()
Name
v4l2-munmap -- Unmap device memory
Synopsis
#include <unistd.h> #include <sys/mman.h>
int munmap
(void *start, size_t length);
Arguments
-
start
-
Address of the mapped buffer as returned by the
mmap()
function. -
length
-
Length of the mapped buffer. This must be the samevalue as given to
mmap()
and returned by thedriver in the struct v4l2_bufferlength
field.
Description
Unmaps a previously with the mmap()
function mappedbuffer and frees it, if possible.
Return Value
On success munmap()
returns 0, onfailure -1 and theerrno
variable is setappropriately:
- EINVAL
-
The
start
orlength
is incorrect, or no buffers have beenmapped yet.
V4L2 open()
Name
v4l2-open -- Open a V4L2 device
Synopsis
#include <fcntl.h>
int open
(const char *device_name, int flags);
Arguments
-
device_name
-
Device to be opened.
-
flags
-
Open flags. Access mode must be
O_RDWR
. This is just a technicality, input devicesstill support only reading and output devices only writing.When the
O_NONBLOCK
flag isgiven, the read() function and theVIDIOC_DQBUF
ioctl will returntheEAGAIN error code when no data is available or no buffer is in the driveroutgoing queue, otherwise these functions block until data becomesavailable. All V4L2 drivers exchanging data with applications mustsupport theO_NONBLOCK
flag.Other flags have no effect.
Description
To open a V4L2 device applications callopen()
with the desired device name. Thisfunction has no side effects; all data format parameters, currentinput or output, control values or other properties remain unchanged.At the firstopen()
call after loading the driverthey will be reset to default values, drivers are never in anundefined state.
Return Value
On success open
returns the new filedescriptor. On error -1 is returned, and theerrno
variable is set appropriately. Possible error codes are:
- EACCES
-
The caller has no permission to access thedevice.
- EBUSY
-
The driver does not support multiple opens and thedevice is already in use.
- ENXIO
-
No device corresponding to this device special fileexists.
- ENOMEM
-
Not enough kernel memory was available to complete therequest.
- EMFILE
-
The process already has the maximum number offiles open.
- ENFILE
-
The limit on the total number of files open on thesystem has been reached.
V4L2 poll()
Name
v4l2-poll -- Wait for some event on a file descriptor
Synopsis
#include <sys/poll.h>
int poll
(struct pollfd *ufds, unsigned int nfds, int timeout);
Description
With the poll()
function applicationscan suspend execution until the driver has captured data or is readyto accept data for output.
When streaming I/O has been negotiated this function waitsuntil a buffer has been filled or displayed and can be dequeued withtheVIDIOC_DQBUF
ioctl. When buffers are already in the outgoingqueue of the driver the function returns immediately.
On success poll()
returns the number offile descriptors that have been selected (that is, file descriptorsfor which therevents
field of therespectivepollfd
structure is non-zero).Capture devices set thePOLLIN
andPOLLRDNORM
flags in therevents
field, output devices thePOLLOUT
andPOLLWRNORM
flags. When the function timed out it returns a value of zero, onfailure it returns-1 and theerrno
variable is set appropriately. When theapplication did not callVIDIOC_QBUF
orVIDIOC_STREAMON
yet thepoll()
function succeeds, but sets thePOLLERR
flag in therevents
field.
When use of the read()
function hasbeen negotiated and the driver does not capture yet, thepoll
function starts capturing. When that failsit returns aPOLLERR
as above. Otherwise it waitsuntil data has been captured and can be read. When the driver capturescontinuously (as opposed to, for example, still images) the functionmay return immediately.
When use of the write()
function hasbeen negotiated thepoll
function just waitsuntil the driver is ready for a non-blockingwrite()
call.
All drivers implementing the read()
orwrite()
function or streaming I/O must alsosupport thepoll()
function.
For more details see thepoll()
manual page.
Return Value
On success, poll()
returns the numberstructures which have non-zerorevents
fields, or zero if the call timed out. On error-1 is returned, and theerrno
variable is set appropriately:
- EBADF
-
One or more of the
ufds
membersspecify an invalid file descriptor. - EBUSY
-
The driver does not support multiple read or writestreams and the device is already in use.
- EFAULT
-
ufds
references an inaccessiblememory area. - EINTR
-
The call was interrupted by a signal.
- EINVAL
-
The
nfds
argument is greaterthanOPEN_MAX
.
V4L2 read()
Name
v4l2-read -- Read from a V4L2 device
Synopsis
#include <unistd.h>
ssize_t read
(int fd, void *buf, size_t count);
Arguments
-
fd
-
File descriptor returned by
open()
. -
buf
-
count
Description
read()
attempts to read up tocount
bytes from file descriptorfd
into the buffer starting atbuf
. The layout of the data in the buffer isdiscussed in the respective device interface section, see ##. If count
is zero,read()
returns zero and has no other results. Ifcount
is greater thanSSIZE_MAX
, the result is unspecified. Regardlessof thecount
value eachread()
call will provide at most one frame (twofields) worth of data.
By default read()
blocks until databecomes available. When theO_NONBLOCK
flag wasgiven to theopen()
function itreturns immediately with anEAGAINerror code when no data is available. Theselect()
orpoll()
functionscan always be used to suspend execution until data becomes available. Alldrivers supporting theread()
function must alsosupportselect()
andpoll()
.
Drivers can implement read functionality in differentways, using a single or multiple buffers and discarding the oldest ornewest frames once the internal buffers are filled.
read()
never returns a "snapshot" of abuffer being filled. Using a single buffer the driver will stopcapturing when the application starts reading the buffer until theread is finished. Thus only the period of the vertical blankinginterval is available for reading, or the capture rate must fall belowthe nominal frame rate of the video standard.
The behavior ofread()
when called during the active pictureperiod or the vertical blanking separating the top and bottom fielddepends on the discarding policy. A driver discarding the oldestframes keeps capturing into an internal buffer, continuouslyoverwriting the previously, not read frame, and returns the framebeing received at the time of theread()
call assoon as it is complete.
A driver discarding the newest frames stops capturing untilthe next read()
call. The frame being received atread()
time is discarded, returning the followingframe instead. Again this implies a reduction of the capture rate toone half or less of the nominal frame rate. An example of this modelis the video read mode of the bttv driver, initiating a DMA to usermemory whenread()
is called and returning whenthe DMA finished.
In the multiple buffer model drivers maintain a ring ofinternal buffers, automatically advancing to the next free buffer.This allows continuous capturing when the application can empty thebuffers fast enough. Again, the behavior when the driver runs out offree buffers depends on the discarding policy.
Applications can get and set the number of buffers usedinternally by the driver with theVIDIOC_G_PARM
andVIDIOC_S_PARM
ioctls. They are optional, however. The discarding policy is notreported and cannot be changed. For minimum requirements seeChapter 4.
Return Value
On success, the number of bytes read is returned. It is notan error if this number is smaller than the number of bytes requested,or the amount of data required for one frame. This may happen forexample becauseread()
was interrupted by asignal. On error, -1 is returned, and theerrno
variable is set appropriately. In this case the next read will startat the beginning of a new frame. Possible error codes are:
- EAGAIN
-
Non-blocking I/O has been selected usingO_NONBLOCK and no data was immediately available for reading.
- EBADF
-
fd
is not a valid filedescriptor or is not open for reading, or the process already has themaximum number of files open. - EBUSY
-
The driver does not support multiple read streams and thedevice is already in use.
- EFAULT
-
buf
references an inaccessiblememory area. - EINTR
-
The call was interrupted by a signal before anydata was read.
- EIO
-
I/O error. This indicates some hardware problem or afailure to communicate with a remote device (USB camera etc.).
- EINVAL
-
The
read()
function is notsupported by this driver, not on this device, or generally not on thistype of device.
V4L2 select()
Name
v4l2-select -- Synchronous I/O multiplexing
Synopsis
#include <sys/time.h> #include <sys/types.h> #include <unistd.h>
int select
(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
Description
With the select()
function applicationscan suspend execution until the driver has captured data or is readyto accept data for output.
When streaming I/O has been negotiated this function waitsuntil a buffer has been filled or displayed and can be dequeued withtheVIDIOC_DQBUF
ioctl. When buffers are already in the outgoingqueue of the driver the function returns immediately.
On success select()
returns the totalnumber of bits set in thefd_set
s. When thefunction timed out it returns a value of zero. On failure it returns-1and theerrno
variable is set appropriately. When the application did not callVIDIOC_QBUF
orVIDIOC_STREAMON
yet theselect()
function succeeds, setting the bit ofthe file descriptor inreadfds
orwritefds
, but subsequentVIDIOC_DQBUF
callswill fail.[26]
When use of the read()
function hasbeen negotiated and the driver does not capture yet, theselect()
function starts capturing. When thatfails,select()
returns successful and asubsequent read()
call, which also attempts tostart capturing, will return an appropriate error code. When thedriver captures continuously (as opposed to, for example, stillimages) and data is already available theselect()
function returns immediately.
When use of the write()
function hasbeen negotiated theselect()
function just waitsuntil the driver is ready for a non-blockingwrite()
call.
All drivers implementing the read()
orwrite()
function or streaming I/O must alsosupport theselect()
function.
For more details see the select()
manual page.
Return Value
On success, select()
returns the numberof descriptors contained in the three returned descriptor sets, whichwill be zero if the timeout expired. On error-1 is returned, and theerrno
variable is set appropriately; the sets andtimeout
are undefined. Possible error codesare:
- EBADF
-
One or more of the file descriptor sets specified afile descriptor that is not open.
- EBUSY
-
The driver does not support multiple read or writestreams and the device is already in use.
- EFAULT
-
The
readfds
,writefds
,exceptfds
ortimeout
pointer references an inaccessible memoryarea. - EINTR
-
The call was interrupted by a signal.
- EINVAL
-
The
nfds
argument is less thanzero or greater thanFD_SETSIZE
.
V4L2 write()
Name
v4l2-write -- Write to a V4L2 device
Synopsis
#include <unistd.h>
ssize_t write
(int fd, void *buf, size_t count);
Arguments
-
fd
-
File descriptor returned by
open()
. -
buf
-
count
Description
write()
writes up tocount
bytes to the device referenced by thefile descriptorfd
from the buffer starting atbuf
. When the hardware outputs are not activeyet, this function enables them. Whencount
iszero,write()
returns0 without any other effect.
When the application does not provide more data in time, theprevious video frame, raw VBI image, sliced VPS or WSS data isdisplayed again. Sliced Teletext or Closed Caption data is notrepeated, the driver inserts a blank line instead.
Return Value
On success, the number of bytes written are returned. Zeroindicates nothing was written. On error,-1is returned, and theerrno
variable is setappropriately. In this case the next write will start at the beginningof a new frame. Possible error codes are:
- EAGAIN
-
Non-blocking I/O has been selected using the
O_NONBLOCK
flag and nobuffer space was available to write the data immediately. - EBADF
-
fd
is not a valid filedescriptor or is not open for writing. - EBUSY
-
The driver does not support multiple write streams and thedevice is already in use.
- EFAULT
-
buf
references an inaccessiblememory area. - EINTR
-
The call was interrupted by a signal before anydata was written.
- EIO
-
I/O error. This indicates some hardware problem.
- EINVAL
-
The
write()
function is notsupported by this driver, not on this device, or generally not on thistype of device.
Chapter 6. Changes
6.1. Differences between V4L and V4L2
6.1.1. Opening and Closing Devices
Table 6-1. V4L Device Types, Names and Numbers
Device Type | File Name | Minor Numbers |
---|---|---|
Video capture and overlay |
/dev/video and/dev/bttv0a,/dev/video0 to/dev/video63 |
0-63 |
Radio receiver |
/dev/radiob, /dev/radio0 to/dev/radio63 |
64-127 |
Teletext decoder |
/dev/vtx,/dev/vtx0 to/dev/vtx31 |
192-223 |
Raw VBI capture |
/dev/vbi,/dev/vbi0 to/dev/vbi31 |
224-255 |
Notes: a. According toDocumentation/devices.txt these should be symbolic links to/dev/video0. Note the original bttv interface isnot compatible with V4L or V4L2. b. According toDocumentation/devices.txt a symbolic link to/dev/radio0. |
V4L prohibits (or used to prohibit) multiple opens of adevice file. V4L2 driversmay support multipleopens, seeSection 1.1 for details and consequences.
V4L drivers respond to V4L2 ioctls with an EINVAL error code. Thecompatibility layer in the V4L2videodev modulecan translate V4L ioctl requests to their V4L2 counterpart, however aV4L2 driver usually needs more preparation to become fully V4Lcompatible. This is covered in more detail inChapter 5.
6.1.2. Querying Capabilities
The V4L VIDIOCGCAP
ioctl isequivalent to V4L2's VIDIOC_QUERYCAP
.
structvideo_capability type
|
struct v4l2_capabilitycapabilities flags
|
Purpose |
---|---|---|
VID_TYPE_CAPTURE
|
V4L2_CAP_VIDEO_CAPTURE
|
The videocapture interface is supported. |
VID_TYPE_TUNER
|
V4L2_CAP_TUNER
|
The device has a tuner ormodulator. |
VID_TYPE_TELETEXT
|
V4L2_CAP_VBI_CAPTURE
|
The raw VBIcapture interface is supported. |
VID_TYPE_OVERLAY
|
V4L2_CAP_VIDEO_OVERLAY
|
The videooverlay interface is supported. |
VID_TYPE_CHROMAKEY
|
V4L2_FBUF_CAP_CHROMAKEY infieldcapability ofstruct v4l2_framebuffer
|
Whether chromakey overlay is supported. Formore information on overlay seeSection 4.2. |
VID_TYPE_CLIPPING
|
V4L2_FBUF_CAP_LIST_CLIPPING andV4L2_FBUF_CAP_BITMAP_CLIPPING in fieldcapability of struct v4l2_framebuffer
|
Whether clipping the overlaid image issupported, see Section 4.2. |
VID_TYPE_FRAMERAM
|
V4L2_FBUF_CAP_EXTERNOVERLAY not setin fieldcapability of struct v4l2_framebuffer
|
Whether overlay overwrites frame buffer memory,see Section 4.2. |
VID_TYPE_SCALES
|
-
|
This flag indicates if the hardware can scaleimages. The V4L2 API implies the scale factor by setting the croppingdimensions and image size with theVIDIOC_S_CROP andVIDIOC_S_FMT ioctl, respectively. The driver returns the closest sizes possible.For more information on cropping and scaling seeSection 1.11.
|
VID_TYPE_MONOCHROME
|
-
|
Applications can enumerate the supported imageformats with theVIDIOC_ENUM_FMT ioctl to determine if the devicesupports grey scale capturing only. For more information on imageformats seeChapter 2.
|
VID_TYPE_SUBCAPTURE
|
-
|
Applications can call the VIDIOC_G_CROP ioctlto determine if the device supports capturing a subsection of the fullpicture ("cropping" in V4L2). If not, the ioctl returns theEINVAL error code.For more information on cropping and scaling seeSection 1.11.
|
VID_TYPE_MPEG_DECODER
|
-
|
Applications can enumerate the supported imageformats with theVIDIOC_ENUM_FMT ioctl to determine if the devicesupports MPEG streams.
|
VID_TYPE_MPEG_ENCODER
|
-
|
See above. |
VID_TYPE_MJPEG_DECODER
|
-
|
See above. |
VID_TYPE_MJPEG_ENCODER
|
-
|
See above. |
The audios
field was replacedby capabilities
flagV4L2_CAP_AUDIO
, indicatingif the device has any audio inputs or outputs. Todetermine their number applications can enumerate audio inputs withtheVIDIOC_G_AUDIO
ioctl. The audio ioctls are described inSection 1.5.
The maxwidth
,maxheight
,minwidth
andminheight
fields were removed. Calling theVIDIOC_S_FMT
or VIDIOC_TRY_FMT
ioctl with the desired dimensionsreturns the closest size possible, taking into account the currentvideo standard, cropping and scaling limitations.
6.1.3. Video Sources
The channel
field countinginputs was renamed toindex
, the videoinput types were renamed as follows:
struct video_channel type
|
struct v4l2_inputtype
|
---|---|
VIDEO_TYPE_TV
|
V4L2_INPUT_TYPE_TUNER
|
VIDEO_TYPE_CAMERA
|
V4L2_INPUT_TYPE_CAMERA
|
Unlike the tuners
fieldexpressing the number of tuners of this input, V4L2 assumes each videoinput is connected to at most one tuner. However a tuner can have morethan one input, i. e. RF connectors, and a device can have multipletuners. The index number of the tuner associated with the input, ifany, is stored in fieldtuner
ofstruct v4l2_input. Enumeration of tuners is discussed inSection 1.6.
The redundant VIDEO_VC_TUNER
flag wasdropped. Video inputs associated with a tuner are of typeV4L2_INPUT_TYPE_TUNER
. TheVIDEO_VC_AUDIO
flag was replaced by theaudioset
field. V4L2 considers devices withup to 32 audio inputs. Each set bit in theaudioset
field represents one audio inputthis video input combines with. For information about audio inputs andhow to switch between them seeSection 1.5.
The norm
field describing thesupported video standards was replaced bystd
. The V4L specification mentions a flagVIDEO_VC_NORM
indicating whether the standard canbe changed. This flag was a later addition together with thenorm
field and has been removed in themeantime. V4L2 has a similar, albeit more comprehensive approachto video standards, seeSection 1.7 for moreinformation.
6.1.4. Tuning
The VIDEO_TUNER_LOW
flag was renamedto V4L2_TUNER_CAP_LOW
in the struct v4l2_tunercapability
field.
6.1.5. Image Properties
struct video_picture
|
V4L2 Control ID |
---|---|
brightness
|
V4L2_CID_BRIGHTNESS
|
hue
|
V4L2_CID_HUE
|
colour
|
V4L2_CID_SATURATION
|
contrast
|
V4L2_CID_CONTRAST
|
whiteness
|
V4L2_CID_WHITENESS
|
The V4L picture controls are assumed to range from 0 to65535 with no particular reset value. The V4L2 API permits arbitrarylimits and defaults which can be queried with theVIDIOC_QUERYCTRL
ioctl. For general information about controls seeSection 1.8.
The depth
(average number ofbits per pixel) of a video image is implied by the selected imageformat. V4L2 does not explicitely provide such information assumingapplications recognizing the format are aware of the image depth andothers need not know. The palette
fieldmoved into the struct v4l2_pix_format:
struct video_picture palette
|
struct v4l2_pix_formatpixfmt
|
---|---|
VIDEO_PALETTE_GREY
|
|
VIDEO_PALETTE_HI240
|
|
VIDEO_PALETTE_RGB565
|
|
VIDEO_PALETTE_RGB555
|
|
VIDEO_PALETTE_RGB24
|
|
VIDEO_PALETTE_RGB32
|
|
VIDEO_PALETTE_YUV422
|
|
|
|
VIDEO_PALETTE_UYVY
|
|
VIDEO_PALETTE_YUV420
|
None |
VIDEO_PALETTE_YUV411
|
|
VIDEO_PALETTE_RAW
|
Nonee |
VIDEO_PALETTE_YUV422P
|
|
VIDEO_PALETTE_YUV411P
|
|
VIDEO_PALETTE_YUV420P
|
|
VIDEO_PALETTE_YUV410P
|
|
Notes: a. This is a custom format used by the BTTVdriver, not one of the V4L2 standard formats. b. Presumably all V4L RGB formats arelittle-endian, although some drivers might interpret them according to machine endianess. V4L2 defines little-endian, big-endian and red/blueswapped variants. For details seeSection 2.4. c. VIDEO_PALETTE_YUV422 andVIDEO_PALETTE_YUYV are the same formats. SomeV4L drivers respond to one, some to the other.d. Not to be confused with V4L2_PIX_FMT_YUV411P , which is a planarformat.e. V4L explains thisas: "RAW capture (BT848)" f. Not to be confused with V4L2_PIX_FMT_Y41P , which is a packedformat.
|
V4L2 image formats are defined in Chapter 2. The image format can be selected with theVIDIOC_S_FMT
ioctl.
6.1.6. Audio
The audio
"channel number"field counting audio inputs was renamed toindex
.
The following fields where replaced by V4L2 controlsaccessible with the VIDIOC_QUERYCTRL
, VIDIOC_G_CTRL
andVIDIOC_S_CTRL
ioctls:
structvideo_audio
|
V4L2 Control ID |
---|---|
volume
|
V4L2_CID_AUDIO_VOLUME
|
bass
|
V4L2_CID_AUDIO_BASS
|
treble
|
V4L2_CID_AUDIO_TREBLE
|
balance
|
V4L2_CID_AUDIO_BALANCE
|
To determine which of these controls are supported by adriver V4L provides theflags
VIDEO_AUDIO_VOLUME
,VIDEO_AUDIO_BASS
,VIDEO_AUDIO_TREBLE
andVIDEO_AUDIO_BALANCE
. In the V4L2 API theVIDIOC_QUERYCTRL
ioctl reports if the respective control issupported. Accordingly theVIDEO_AUDIO_MUTABLE
and VIDEO_AUDIO_MUTE
flags where replaced by thebooleanV4L2_CID_AUDIO_MUTE
control.
All V4L2 controls have a step
attribute replacing the structvideo_audio
step
field. The V4L audio controls areassumed to range from 0 to 65535 with no particular reset value. TheV4L2 API permits arbitrary limits and defaults which can be queriedwith theVIDIOC_QUERYCTRL
ioctl. For general information aboutcontrols seeSection 1.8.
6.1.7. Frame Buffer Overlay
The VIDIOCCAPTURE
ioctl to enable ordisable overlay was renamed toVIDIOC_OVERLAY
.
6.1.9. Reading Images, Memory Mapping
6.1.9.1. Capturing using the read method
For more information about the V4L2 read interface seeSection 3.1.
6.1.9.2. Capturing using memory mapping
V4L | V4L2 |
---|---|
The image format must be selected beforebuffers are allocated, with the VIDIOC_S_FMT ioctl. When no formatis selected the driver may use the last, possibly by anotherapplication requested format.
|
|
Applications cannot change the number ofbuffers. The it is built into the driver, unless it has a moduleoption to change the number when the driver module isloaded. |
The |
Drivers map all buffers as one contiguousrange of memory. The |
Buffers are individually mapped. Theoffset and size of each buffer can be determined with the |
The The |
Drivers maintain an incoming and outgoingqueue. |
For a more in-depth discussion of memory mapping andexamples, see Section 3.2.
6.1.10. Reading Raw VBI Data
struct v4l2_vbi_format | V4L, BTTV driver |
---|---|
sampling_rate | 28636363 Hz NTSC (or any other 525-linestandard); 35468950 Hz PAL and SECAM (625-line standards) |
offset | ? |
samples_per_line | 2048 |
sample_format | V4L2_PIX_FMT_GREY. The last four bytes (amachine endianess integer) contain a frame counter. |
start[] | 10, 273 NTSC; 22, 335 PAL and SECAM |
count[] |
16, 16a |
flags | 0 |
Notes: a. Old driverversions used different values, eventually the custom BTTV_VBISIZE ioctl was added to query thecorrect values.
|
Undocumented in the V4L specification, in Linux 2.3 theVIDIOCGVBIFMT
andVIDIOCSVBIFMT
ioctls using structvbi_format
were added to determine the VBIimage parameters. These ioctls are only partially compatible with theV4L2 VBI interface specified inSection 4.7.
An offset
field does notexist, sample_format
is supposed to beVIDEO_PALETTE_RAW
, equivalent toV4L2_PIX_FMT_GREY
. The remaining fields areprobably equivalent to struct v4l2_vbi_format.
Apparently only the Zoran (ZR 36120) driver implementsthese ioctls. The semantics differ from those specified for V4L2 in twoways. The parameters are reset onopen()
andVIDIOCSVBIFMT
always returns anEINVAL error code if theparameters are invalid.
6.2. Changes of the V4L2 API
6.2.1. Early Versions
1998-08-27: The select()
function was introduced.
1998-09-10: New video standard interface.
1998-09-28: Revamped video standard. Made video controlsindividually enumerable.
1998-11-12: The read/write directon of some ioctls was misdefined.
1998-11-28: A few ioctl symbols changed. Interfaces for codecs andvideo output devices were added.
6.2.4. V4L2 Version 0.19 1999-06-05
1999-04-04: Added a few more control IDs.
1999-04-07: Added the button control type.
1999-05-20: Definition of VIDIOC_G_CTRL was wrong causinga malfunction of this ioctl.
6.2.5. V4L2 Version 0.20 (1999-09-10)
Some typos in
V4L2_FMT_FLAG
symbols were fixed. struct v4l2_clip was changed for compatibility withv4l. (1999-08-30)V4L2_TUNER_SUB_LANG1
was added.(1999-09-05)All ioctl() commands that used an integer argument nowtake a pointer to an integer. Where it makes sense, ioctls will returnthe actual new value in the integer pointed to by the argument, acommon convention in the V4L2 API. The affected ioctls are:VIDIOC_PREVIEW, VIDIOC_STREAMON, VIDIOC_STREAMOFF, VIDIOC_S_FREQ,VIDIOC_S_INPUT, VIDIOC_S_OUTPUT, VIDIOC_S_EFFECT. For example
err = ioctl (fd, VIDIOC_XXX, V4L2_XXX);
becomes
int a = V4L2_XXX; err = ioctl(fd, VIDIOC_XXX, &a);
All the different get- and set-format commands wereswept into one
VIDIOC_G_FMT
andVIDIOC_S_FMT
ioctl taking a unionand a type field selecting the union member as parameter. Purpose is tosimplify the API by eliminating several ioctls and to allow new anddriver private data streams without adding new ioctls.This change obsoletes the following ioctls:
VIDIOC_S_INFMT
,VIDIOC_G_INFMT
,VIDIOC_S_OUTFMT
,VIDIOC_G_OUTFMT
,VIDIOC_S_VBIFMT
andVIDIOC_G_VBIFMT
. The image format structurev4l2_format
was renamed to struct v4l2_pix_format,while struct v4l2_format is now the envelopping structure for all formatnegotiations.Similar to the changes above, the
VIDIOC_G_PARM
andVIDIOC_S_PARM
ioctls were merged withVIDIOC_G_OUTPARM
andVIDIOC_S_OUTPARM
. Atype
field in the new struct v4l2_streamparmselects the respective union member.This change obsoletes the
VIDIOC_G_OUTPARM
andVIDIOC_S_OUTPARM
ioctls.Control enumeration was simplified, and two newcontrol flags were introduced and one dropped. The
catname
field was replaced by agroup
field.Drivers can now flag unsupported and temporarilyunavailable controls with
V4L2_CTRL_FLAG_DISABLED
andV4L2_CTRL_FLAG_GRABBED
respectively. Thegroup
name indicates a possibly narrowerclassification than thecategory
. In otherwords, there may be multiple groups within a category. Controls withina group would typically be drawn within a group box. Controls indifferent categories might have a greater separation, or may evenappear in separate windows.The struct v4l2_buffer
timestamp
was changed to a 64 bit integer, containing the sampling or outputtime of the frame in nanoseconds. Additionally timestamps will be inabsolute system time, not starting from zero at the beginning of astream. The data type name for timestamps is stamp_t, defined as asigned 64-bit integer. Output devices should not send a buffer outuntil the time in the timestamp field has arrived. I would like tofollow SGI's lead, and adopt a multimedia timestamping system liketheir UST (Unadjusted System Time). Seehttp://reality.sgi.com/cpirazzi_engr/lg/time/intro.html. [This link isno longer valid.] UST uses timestamps that are 64-bit signed integers(not struct timeval's) and given in nanosecond units. The UST clockstarts at zero when the system is booted and runs continuously anduniformly. It takes a little over 292 years for UST to overflow. Thereis no way to set the UST clock. The regular Linux time-of-day clockcan be changed periodically, which would cause errors if it were beingused for timestamping a multimedia stream. A real UST style clock willrequire some support in the kernel that is not there yet. But inanticipation, I will change the timestamp field to a 64-bit integer,and I will change the v4l2_masterclock_gettime() function (used onlyby drivers) to return a 64-bit integer.A
sequence
field was addedto struct v4l2_buffer. Thesequence
field countscaptured frames, it is ignored by output devices. When a capturedriver drops a frame, the sequence number of that frame isskipped.
6.2.6. V4L2 Version 0.20 incremental changes
2000-01-13: The V4L2_FMT_FLAG_NOT_INTERLACED
flag was added.
2000-11-20: V4L2_TYPE_VBI_OUTPUT
andV4L2_PIX_FMT_Y41P
were added.
2000-11-25: V4L2_TYPE_VBI_INPUT
wasadded.
2000-12-04: A couple typos in symbol names were fixed.
6.2.7. V4L2 Version 0.20 2000-11-23
A number of changes were made to the raw VBIinterface.
Figures clarifying the line numbering scheme wereadded to the V4L2 API specification. The
start
[0] andstart
[1] fields no longer count linenumbers beginning at zero. Rationale: a) The previous definition wasunclear. b) Thestart
[] values are ordinalnumbers. c) There is no point in inventing a new line numberingscheme. We now use line number as defined by ITU-R, period.Compatibility: Add one to the start values. Applications depending onthe previous semantics may not function correctly.The restriction "count[0] > 0 and count[1] > 0"has been relaxed to "(count[0] + count[1]) > 0". Rationale:Drivers may allocate resources at scan line granularity and some dataservices are transmitted only on the first field. The comment thatboth
count
values will usually be equal ismisleading and pointless and has been removed. This changebreaks compatibility with earlier versions:Drivers may return EINVAL, applications may not functioncorrectly.Drivers are again permitted to return negative(unknown) start values as proposed earlier. Why this feature wasdropped is unclear. This change maybreakcompatibility with applications depending on the startvalues being positive. The use of
EBUSY
andEINVAL
error codes with theVIDIOC_S_FMT
ioctlwas clarified. TheEBUSY error code was finally documented, and thereserved2
field which was previouslymentioned only in thevideodev.h headerfile.New buffer types
V4L2_TYPE_VBI_INPUT
andV4L2_TYPE_VBI_OUTPUT
were added. The former is analias for the oldV4L2_TYPE_VBI
, the latter wasmissing in thevideodev.h file.
6.2.9. V4L2 in Linux 2.5.46, 2002-10
As specified in Section 1.1.2, driversmust make related device functions available under all minor devicenumbers.
The
open()
function requires access modeO_RDWR
regardless of the device type. All V4L2drivers exchanging data with applications must support theO_NONBLOCK
flag. TheO_NOIO
flag, a V4L2 symbol which aliased the meaninglessO_TRUNC
to indicate accesses without dataexchange (panel applications) was dropped. Drivers must stay in "panelmode" until the application attempts to initiate a data exchange, seeSection 1.1.The struct v4l2_capability changed dramatically. Note thatalso the size of the structure changed, which is encoded in the ioctlrequest code, thus older V4L2 devices will respond with an EINVAL error code tothe new
VIDIOC_QUERYCAP
ioctl.There are new fields to identify the driver, a new (asof yet unspecified) device function
V4L2_CAP_RDS_CAPTURE
, theV4L2_CAP_AUDIO
flag indicates if the device hasany audio connectors, another I/O capabilityV4L2_CAP_ASYNCIO
can be flagged. In response tothese changes thetype
field became a bitset and was merged into theflags
field.V4L2_FLAG_TUNER
was renamed toV4L2_CAP_TUNER
,V4L2_CAP_VIDEO_OVERLAY
replacedV4L2_FLAG_PREVIEW
andV4L2_CAP_VBI_CAPTURE
andV4L2_CAP_VBI_OUTPUT
replacedV4L2_FLAG_DATA_SERVICE
.V4L2_FLAG_READ
andV4L2_FLAG_WRITE
were merged intoV4L2_CAP_READWRITE
.The redundant fields
inputs
,outputs
andaudios
were removed. These propertiescan be determined as described inSection 1.4 andSection 1.5.The somewhat volatile and therefore barely usefulfields
maxwidth
,maxheight
,minwidth
,minheight
,maxframerate
were removed. This informationis available as described inSection 1.10 andSection 1.7.V4L2_FLAG_SELECT
was removed. Webelieve the select() function is important enough to require supportof it in all V4L2 drivers exchanging data with applications. TheredundantV4L2_FLAG_MONOCHROME
flag was removed,this information is available as described inSection 1.10.In struct v4l2_input the
assoc_audio
field and thecapability
field and its only flagV4L2_INPUT_CAP_AUDIO
was replaced by the newaudioset
field. Instead of linking onevideo input to one audio input this field reports all audio inputsthis video input combines with.New fields are
tuner
(reversing the former link from tuners to video inputs),std
andstatus
.Accordingly struct v4l2_output lost its
capability
andassoc_audio
fields.audioset
,modulator
andstd
where added instead.The struct v4l2_audio field
audio
was renamed toindex
, for consistency with otherstructures. A new capability flagV4L2_AUDCAP_STEREO
was added to indicated if theaudio input in question supports stereo sound.V4L2_AUDCAP_EFFECTS
and the correspondingV4L2_AUDMODE
flags where removed. This can beeasily implemented using controls. (However the same applies to AVLwhich is still there.)Again for consistency the struct v4l2_audioout field
audio
was renamed toindex
.The struct v4l2_tuner
input
field was replaced by anindex
field, permitting devices withmultiple tuners. The link between video inputs and tuners is nowreversed, inputs point to their tuner. Thestd
substructure became asimple set (more about this below) and moved into struct v4l2_input. Atype
field was added.Accordingly in struct v4l2_modulator the
output
was replaced by anindex
field.In struct v4l2_frequency the
port
field was replaced by atuner
field containing the respective tuneror modulator index number. A tunertype
field was added and thereserved
fieldbecame larger for future extensions (satellite tuners inparticular).The idea of completely transparent video standards wasdropped. Experience showed that applications must be able to work withvideo standards beyond presenting the user a menu. Instead ofenumerating supported standards with an ioctl applications can nowrefer to standards byv4l2_std_id and symbols defined in thevideodev2.h header file. For details seeSection 1.7. The
VIDIOC_G_STD
andVIDIOC_S_STD
now take a pointer to this type as argument.VIDIOC_QUERYSTD
was added to autodetect the received standard, ifthe hardware has this capability. In struct v4l2_standard anindex
field was added forVIDIOC_ENUMSTD
.Av4l2_std_id field namedid
was added asmachine readable identifier, also replacing thetransmission
field. The misleadingframerate
field was renamedtoframeperiod
. The now obsoletecolorstandard
information, originallyneeded to distguish between variations of standards, wereremoved.Struct
v4l2_enumstd
ceased tobe.VIDIOC_ENUMSTD
now takes a pointer to a struct v4l2_standarddirectly. The information which standards are supported by aparticular video input or output moved into struct v4l2_input andstruct v4l2_output fields namedstd
,respectively.The struct v4l2_queryctrl fields
category
andgroup
did not catch on and/or were notimplemented as expected and therefore removed.The
VIDIOC_TRY_FMT
ioctl was added to negotiate dataformats as withVIDIOC_S_FMT
, but without the overhead ofprogramming the hardware and regardless of I/O in progress.In struct v4l2_format the
fmt
union was extended to contain struct v4l2_window. All image formatnegotiations are now possible withVIDIOC_G_FMT
,VIDIOC_S_FMT
andVIDIOC_TRY_FMT
; ioctl. TheVIDIOC_G_WIN
andVIDIOC_S_WIN
ioctls to prepare for a videooverlay were removed. Thetype
fieldchanged to type enum v4l2_buf_type and the buffer type names changed asfollows.Old defines enum v4l2_buf_type V4L2_BUF_TYPE_CAPTURE
V4L2_BUF_TYPE_VIDEO_CAPTURE
V4L2_BUF_TYPE_CODECIN
Omitted for now V4L2_BUF_TYPE_CODECOUT
Omitted for now V4L2_BUF_TYPE_EFFECTSIN
Omitted for now V4L2_BUF_TYPE_EFFECTSIN2
Omitted for now V4L2_BUF_TYPE_EFFECTSOUT
Omitted for now V4L2_BUF_TYPE_VIDEOOUT
V4L2_BUF_TYPE_VIDEO_OUTPUT
-
V4L2_BUF_TYPE_VIDEO_OVERLAY
-
V4L2_BUF_TYPE_VBI_CAPTURE
-
V4L2_BUF_TYPE_VBI_OUTPUT
-
V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
-
V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
V4L2_BUF_TYPE_PRIVATE_BASE
V4L2_BUF_TYPE_PRIVATE
In struct v4l2_fmtdesc a enum v4l2_buf_type field named
type
was added as in struct v4l2_format. TheVIDIOC_ENUM_FBUFFMT
ioctl is no longer needed andwas removed. These calls can be replaced byVIDIOC_ENUM_FMT
withtypeV4L2_BUF_TYPE_VIDEO_OVERLAY
.In struct v4l2_pix_format the
depth
field was removed, assumingapplications which recognize the format by its four-character-codealready know the color depth, and others do not care about it. Thesame rationale lead to the removal of theV4L2_FMT_FLAG_COMPRESSED
flag. TheV4L2_FMT_FLAG_SWCONVECOMPRESSED
flag was removedbecause drivers are not supposed to convert images in kernel space. Auser library of conversion functions should be provided instead. TheV4L2_FMT_FLAG_BYTESPERLINE
flag was redundant.Applications can set thebytesperline
fieldto zero to get a reasonable default. Since the remaining flags werereplaced as well, theflags
field itselfwas removed.The interlace flags were replaced by a enum v4l2_fieldvalue in a newly added
field
field.Old flag enum v4l2_field V4L2_FMT_FLAG_NOT_INTERLACED
? V4L2_FMT_FLAG_INTERLACED
=V4L2_FMT_FLAG_COMBINED
V4L2_FIELD_INTERLACED
V4L2_FMT_FLAG_TOPFIELD
=V4L2_FMT_FLAG_ODDFIELD
V4L2_FIELD_TOP
V4L2_FMT_FLAG_BOTFIELD
=V4L2_FMT_FLAG_EVENFIELD
V4L2_FIELD_BOTTOM
-
V4L2_FIELD_SEQ_TB
-
V4L2_FIELD_SEQ_BT
-
V4L2_FIELD_ALTERNATE
The color space flags were replaced by aenum v4l2_colorspace value in a newly added
colorspace
field, where one ofV4L2_COLORSPACE_SMPTE170M
,V4L2_COLORSPACE_BT878
,V4L2_COLORSPACE_470_SYSTEM_M
orV4L2_COLORSPACE_470_SYSTEM_BG
replacesV4L2_FMT_CS_601YUV
.In struct v4l2_requestbuffers the
type
field was properly defined asenum v4l2_buf_type. Buffer types changed as mentioned above. A newmemory
field of type enum v4l2_memory wasadded to distinguish between I/O methods using buffers allocatedby the driver or the application. See Chapter 3 fordetails.In struct v4l2_buffer the
type
field was properly defined as enum v4l2_buf_type. Buffer types changed asmentioned above. Afield
field of typeenum v4l2_field was added to indicate if a buffer contains a top orbottom field. The old field flags were removed. Since no unadjustedsystem time clock was added to the kernel as planned, thetimestamp
field changed back from typestamp_t, an unsigned 64 bit integer expressing the sample time innanoseconds, to structtimeval
. With theaddition of a second memory mapping method theoffset
field moved into unionm
, and a newmemory
field of type enum v4l2_memory wasadded to distinguish between I/O methods. SeeChapter 3for details.The
V4L2_BUF_REQ_CONTIG
flag was used by the V4L compatibility layer, after changes to thiscode it was no longer needed. TheV4L2_BUF_ATTR_DEVICEMEM
flag would indicate ifthe buffer was indeed allocated in device memory rather than DMA-ablesystem memory. It was barely useful and so was removed.In struct v4l2_framebuffer the
base[3]
array anticipating double- andtriple-buffering in off-screen video memory, however without defininga synchronization mechanism, was replaced by a single pointer. TheV4L2_FBUF_CAP_SCALEUP
andV4L2_FBUF_CAP_SCALEDOWN
flags were removed.Applications can determine this capability more accurately using thenew cropping and scaling interface. TheV4L2_FBUF_CAP_CLIPPING
flag was replaced byV4L2_FBUF_CAP_LIST_CLIPPING
andV4L2_FBUF_CAP_BITMAP_CLIPPING
.In struct v4l2_clip the
x
,y
,width
andheight
field moved into ac
substructure of type struct v4l2_rect. Thex
andy
fieldswere renamed toleft
andtop
, i. e. offsets to a context dependentorigin.In struct v4l2_window the
x
,y
,width
andheight
field moved into aw
substructure as above. Afield
field of type %v4l2-field; was addedto distinguish between field and frame (interlaced) overlay.The digital zoom interface, including struct
v4l2_zoomcap
, structv4l2_zoom
,V4L2_ZOOM_NONCAP
andV4L2_ZOOM_WHILESTREAMING
was replaced by a newcropping and scaling interface. The previously unused structv4l2_cropcap
andv4l2_crop
where redefined for this purpose.SeeSection 1.11for details.In struct v4l2_vbi_format the
SAMPLE_FORMAT
field now contains afour-character-code as used to identify video image formats andV4L2_PIX_FMT_GREY
replaces theV4L2_VBI_SF_UBYTE
define. Thereserved
field was extended.In struct v4l2_captureparm the type of the
timeperframe
field changed from unsignedlong to struct v4l2_fract. This allows the accurate expression of multiplesof the NTSC-M frame rate 30000 / 1001. A new fieldreadbuffers
was added to control the driverbehaviour in read I/O mode.Similar changes were made to struct v4l2_outputparm.
The struct
v4l2_performance
andVIDIOC_G_PERF
ioctl were dropped. Except whenusing the read/write I/O method, which islimited anyway, this information is already available toapplications.The example transformation from RGB to YCbCr colorspace in the old V4L2 documentation was inaccurate, this has beencorrected inChapter 2.
6.2.10. V4L2 2003-06-19
A new capability flag
V4L2_CAP_RADIO
was added for radio devices. Priorto this change radio devices would identify solely by having exactly onetuner whose type field readsV4L2_TUNER_RADIO
.An optional driver access priority mechanism wasadded, see Section 1.3 for details.
The audio input and output interface was found to beincomplete.
Previously the
VIDIOC_G_AUDIO
ioctl would enumerate the available audio inputs. An ioctl todetermine the current audio input, if more than one combines with thecurrent video input, did not exist. SoVIDIOC_G_AUDIO
was renamed toVIDIOC_G_AUDIO_OLD
, this ioctl will be removed inthe future. TheVIDIOC_ENUMAUDIO
ioctl was added to enumerateaudio inputs, whileVIDIOC_G_AUDIO
now reports the current audioinput.The same changes were made to
VIDIOC_G_AUDOUT
andVIDIOC_ENUMAUDOUT
.Until further the "videodev" module will automaticallytranslate between the old and new ioctls, but drivers and applicationsmust be updated to successfully compile again.
The
VIDIOC_OVERLAY
ioctl was incorrectly defined withwrite-read parameter. It was changed to write-only, while the write-readversion was renamed toVIDIOC_OVERLAY_OLD
. The oldioctl will be removed in the future. Until further the "videodev"kernel module will automatically translate to the new version, so driversmust be recompiled, but not applications.Section 4.2 incorrectly stated thatclipping rectangles define regions where the video can be seen.Correct is that clipping rectangles define regions whereno video shall be displayed and so the graphicssurface can be seen.
The
VIDIOC_S_PARM
andVIDIOC_S_CTRL
ioctls weredefined with write-only parameter, inconsistent with other ioctlsmodifying their argument. They were changed to write-read, while a_OLD
suffix was added to the write-only versions.The old ioctls will be removed in the future. Drivers andapplications assuming a constant parameter need an update.
6.2.11. V4L2 2003-11-05
In Section 2.4 the following pixelformats were incorrectly transferred from Bill Dirks' V4L2specification. Descriptions below refer to bytes in memory, inascending address order.
Symbol In this document prior to revision0.5 Corrected V4L2_PIX_FMT_RGB24
B, G, R R, G, B V4L2_PIX_FMT_BGR24
R, G, B B, G, R V4L2_PIX_FMT_RGB32
B, G, R, X R, G, B, X V4L2_PIX_FMT_BGR32
R, G, B, X B, G, R, X The
V4L2_PIX_FMT_BGR24
example was alwayscorrect.In Section 6.1.5 the mappingof the V4L
VIDEO_PALETTE_RGB24
andVIDEO_PALETTE_RGB32
formats to V4L2 pixel formatswas accordingly corrected.Unrelated to the fixes above, drivers may stillinterpret some V4L2 RGB pixel formats differently. These issues haveyet to be addressed, for details seeSection 2.4.
6.2.12. V4L2 in Linux 2.6.6, 2004-05-09
The
VIDIOC_CROPCAP
ioctl was incorrectly definedwith read-only parameter. It is now defined as write-read ioctl, whilethe read-only version was renamed toVIDIOC_CROPCAP_OLD
. The old ioctl will be removedin the future.
6.2.13. V4L2 in Linux 2.6.8
A new field
input
(formerreserved[0]
) was added to the struct v4l2_bufferstructure. Purpose of this field is to alternate between video inputs(e. g. cameras) in step with the video capturing process. This functionmust be enabled with the newV4L2_BUF_FLAG_INPUT
flag. Theflags
field is no longerread-only.
6.2.14. V4L2 spec erratum 2004-08-01
The return value of theV4L2 open()(2) function was incorrectly documented.
Audio output ioctls end in -AUDOUT, not -AUDIOOUT.
In the Current Audio Input example the
VIDIOC_G_AUDIO
ioctl took the wrongargument.The documentation of the
VIDIOC_QBUF
andVIDIOC_DQBUF
ioctls did not mention the struct v4l2_buffermemory
field. It was also missing fromexamples. Also on theVIDIOC_DQBUF
page theEIO error codewas not documented.
6.2.15. V4L2 in Linux 2.6.14
A new sliced VBI interface was added. It is documentedin Section 4.8 and replaces the interface firstproposed in V4L2 specification 0.8.
6.2.16. V4L2 in Linux 2.6.15
The
VIDIOC_LOG_STATUS
ioctl was added.New video standards
V4L2_STD_NTSC_443
,V4L2_STD_SECAM_LC
,V4L2_STD_SECAM_DK
(a set of SECAM D, K and K1),andV4L2_STD_ATSC
(a set ofV4L2_STD_ATSC_8_VSB
andV4L2_STD_ATSC_16_VSB
) were defined. Note theV4L2_STD_525_60
set now includesV4L2_STD_NTSC_443
. See alsoTable 3.The
VIDIOC_G_COMP
andVIDIOC_S_COMP
ioctl were renamed toVIDIOC_G_MPEGCOMP
andVIDIOC_S_MPEGCOMP
respectively. Their argumentwas replaced by a structv4l2_mpeg_compression
pointer. (TheVIDIOC_G_MPEGCOMP
andVIDIOC_S_MPEGCOMP
ioctls where removed in Linux2.6.25.)
6.2.18. V4L2 spec erratum 2006-01-10
The
V4L2_IN_ST_COLOR_KILL
flag instruct v4l2_input not only indicates if the color killer is enabled, butalso if it is active. (The color killer disables color decoding whenit detects no color in the video signal to improve the imagequality.)VIDIOC_S_PARM
is a write-read ioctl, not write-only asstated on its reference page. The ioctl changed in 2003 as noted above.
6.2.19. V4L2 spec erratum 2006-02-03
In struct v4l2_captureparm and struct v4l2_outputparm the
timeperframe
field gives the time inseconds, not microseconds.
6.2.20. V4L2 spec erratum 2006-02-04
The
clips
field instruct v4l2_window must point to an array of struct v4l2_clip, not a linkedlist, because drivers ignore the structv4l2_clip
.next
pointer.
6.2.21. V4L2 in Linux 2.6.17
New video standard macros were added:
V4L2_STD_NTSC_M_KR
(NTSC M South Korea), and thesetsV4L2_STD_MN
,V4L2_STD_B
,V4L2_STD_GH
andV4L2_STD_DK
. TheV4L2_STD_NTSC
andV4L2_STD_SECAM
sets now includeV4L2_STD_NTSC_M_KR
andV4L2_STD_SECAM_LC
respectively.A new
V4L2_TUNER_MODE_LANG1_LANG2
was defined to record both languages of a bilingual program. Theuse ofV4L2_TUNER_MODE_STEREO
for this purposeis deprecated now. See theVIDIOC_G_TUNER
section fordetails.
6.2.22. V4L2 spec erratum 2006-09-23 (Draft 0.15)
In various places
V4L2_BUF_TYPE_SLICED_VBI_CAPTURE
andV4L2_BUF_TYPE_SLICED_VBI_OUTPUT
of the sliced VBIinterface were not mentioned along with other buffer types.In ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO(2) it was clarifiedthat the struct v4l2_audio
mode
field is a flagsfield.ioctl VIDIOC_QUERYCAP(2) did not mention thesliced VBI and radio capability flags.
In ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY(2) it wasclarified that applications must initialize the tuner
type
field of struct v4l2_frequency beforecallingVIDIOC_S_FREQUENCY
.The
reserved
arrayin struct v4l2_requestbuffers has 2 elements, not 32.In Section 4.3 andSection 4.7 the device file names/dev/vout which never caught on were replacedby/dev/video.
With Linux 2.6.15 the possible range for VBI device minornumbers was extended from 224-239 to 224-255. Accordingly device file names/dev/vbi0 to/dev/vbi31 arepossible now.
6.2.23. V4L2 in Linux 2.6.18
New ioctls
VIDIOC_G_EXT_CTRLS
,VIDIOC_S_EXT_CTRLS
andVIDIOC_TRY_EXT_CTRLS
were added, a flag to skip unsupportedcontrols withVIDIOC_QUERYCTRL
, new control typesV4L2_CTRL_TYPE_INTEGER64
andV4L2_CTRL_TYPE_CTRL_CLASS
(Table 3), and new control flagsV4L2_CTRL_FLAG_READ_ONLY
,V4L2_CTRL_FLAG_UPDATE
,V4L2_CTRL_FLAG_INACTIVE
andV4L2_CTRL_FLAG_SLIDER
(Table 4). SeeSection 1.9 for details.
6.2.24. V4L2 in Linux 2.6.19
In struct v4l2_sliced_vbi_cap a buffer type field was addedreplacing a reserved field. Note on architectures where the size ofenum types differs from int types the size of the structure changed.The
VIDIOC_G_SLICED_VBI_CAP
ioctl was redefined from being read-onlyto write-read. Applications must initialize the type field and clearthe reserved fields now. These changes maybreak thecompatibility with older drivers and applications.The ioctls
VIDIOC_ENUM_FRAMESIZES
andVIDIOC_ENUM_FRAMEINTERVALS
were added.A new pixel format
V4L2_PIX_FMT_RGB444
(Table 2-1) was added.
6.2.25. V4L2 spec erratum 2006-10-12 (Draft 0.17)
V4L2_PIX_FMT_HM12
(Table 2-8) is a YUV 4:2:0, not 4:2:2 format.
6.2.26. V4L2 in Linux 2.6.21
The videodev2.h header file isnow dual licensed under GNU General Public License version two orlater, and under a 3-clause BSD-style license.
6.2.27. V4L2 in Linux 2.6.22
Two new field orders
V4L2_FIELD_INTERLACED_TB
andV4L2_FIELD_INTERLACED_BT
were added. SeeTable 3-8 for details.Three new clipping/blending methods with a global orstraight or inverted local alpha value were added to the video overlayinterface. See the description of the
VIDIOC_G_FBUF
andVIDIOC_S_FBUF
ioctls for details.A new
global_alpha
fieldwas added tov4l2_window
,extending the structure. This maybreakcompatibility with applications using a structv4l2_window
directly. However theVIDIOC_G/S/TRY_FMT ioctls, which take apointer to av4l2_format parentstructure with padding bytes at the end, are not affected.The format of the
chromakey
field in struct v4l2_window changed from "host order RGB32" to a pixelvalue in the same format as the framebuffer. This may breakcompatibility with existing applications. Driverssupporting the "host order RGB32" format are not known.
6.2.28. V4L2 in Linux 2.6.24
The pixel formats
V4L2_PIX_FMT_PAL8
,V4L2_PIX_FMT_YUV444
,V4L2_PIX_FMT_YUV555
,V4L2_PIX_FMT_YUV565
andV4L2_PIX_FMT_YUV32
were added.
6.2.29. V4L2 in Linux 2.6.25
The pixel formats
V4L2_PIX_FMT_Y16
andV4L2_PIX_FMT_SBGGR16
were added.New controls
V4L2_CID_POWER_LINE_FREQUENCY
,V4L2_CID_HUE_AUTO
,V4L2_CID_WHITE_BALANCE_TEMPERATURE
,V4L2_CID_SHARPNESS
andV4L2_CID_BACKLIGHT_COMPENSATION
were added. ThecontrolsV4L2_CID_BLACK_LEVEL
,V4L2_CID_WHITENESS
,V4L2_CID_HCENTER
andV4L2_CID_VCENTER
were deprecated.A Camera controlsclass was added, with the new controls
V4L2_CID_EXPOSURE_AUTO
,V4L2_CID_EXPOSURE_ABSOLUTE
,V4L2_CID_EXPOSURE_AUTO_PRIORITY
,V4L2_CID_PAN_RELATIVE
,V4L2_CID_TILT_RELATIVE
,V4L2_CID_PAN_RESET
,V4L2_CID_TILT_RESET
,V4L2_CID_PAN_ABSOLUTE
,V4L2_CID_TILT_ABSOLUTE
,V4L2_CID_FOCUS_ABSOLUTE
,V4L2_CID_FOCUS_RELATIVE
andV4L2_CID_FOCUS_AUTO
.The
VIDIOC_G_MPEGCOMP
andVIDIOC_S_MPEGCOMP
ioctls, which were supersededby theextended controlsinterface in Linux 2.6.18, where finally removed from thevideodev2.h header file.
6.3. Relation of V4L2 to other Linux multimedia APIs
6.4. Experimental API Elements
The following V4L2 API elements are currently experimentaland may change in the future.
Video Output Overlay (OSD) Interface, Section 4.4.
V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
, enum v4l2_buf_type,Table 3-2.V4L2_CAP_VIDEO_OUTPUT_OVERLAY
,VIDIOC_QUERYCAP
ioctl,Table 2.VIDIOC_ENUM_FRAMESIZES
andVIDIOC_ENUM_FRAMEINTERVALS
ioctls.VIDIOC_G_ENC_INDEX
ioctl.VIDIOC_ENCODER_CMD
andVIDIOC_TRY_ENCODER_CMD
ioctls.VIDIOC_DBG_G_REGISTER
andVIDIOC_DBG_S_REGISTER
ioctls.VIDIOC_G_CHIP_IDENT
ioctl.
6.5. Obsolete API Elements
VIDIOC_G_MPEGCOMP
andVIDIOC_S_MPEGCOMP
ioctls. Use Extended Controls,Section 1.9.
Appendix A. Video For Linux Two Header File
/** Video for Linux Two header file** Copyright (C) 1999-2007 the contributors** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.** Alternatively you can redistribute this file under the terms of the* BSD license as stated below:** Redistribution and use in source and binary forms, with or without* modification, are permitted provided that the following conditions* are met:* 1. Redistributions of source code must retain the above copyright* notice, this list of conditions and the following disclaimer.* 2. Redistributions in binary form must reproduce the above copyright* notice, this list of conditions and the following disclaimer in* the documentation and/or other materials provided with the* distribution.* 3. The names of its contributors may not be used to endorse or promote* products derived from this software without specific prior written* permission.** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.** Header file for v4l or V4L2 drivers and applications* with public API.* All kernel-specific stuff were moved to media/v4l2-dev.h, so* no #if __KERNEL tests are allowed here** See http://linuxtv.org for more info** Author: Bill Dirks <bill@thedirks.org>* Justin Schoeman* Hans Verkuil <hverkuil@xs4all.nl>* et al.*/ #ifndef __LINUX_VIDEODEV2_H #define __LINUX_VIDEODEV2_H #ifdef __KERNEL__ #include <linux/time.h> /* need struct timeval */ #include <linux/compiler.h> /* need __user */ #else #define __user #include <sys/time.h> #endif #include <linux/ioctl.h> #include <linux/types.h>/** Common stuff for both V4L1 and V4L2* Moved from videodev.h*/ #define VIDEO_MAX_FRAME 32#define VID_TYPE_CAPTURE 1 /* Can capture */ #define VID_TYPE_TUNER 2 /* Can tune */ #define VID_TYPE_TELETEXT 4 /* Does teletext */ #define VID_TYPE_OVERLAY 8 /* Overlay onto frame buffer */ #define VID_TYPE_CHROMAKEY 16 /* Overlay by chromakey */ #define VID_TYPE_CLIPPING 32 /* Can clip */ #define VID_TYPE_FRAMERAM 64 /* Uses the frame buffer memory */ #define VID_TYPE_SCALES 128 /* Scalable */ #define VID_TYPE_MONOCHROME 256 /* Monochrome only */ #define VID_TYPE_SUBCAPTURE 512 /* Can capture subareas of the image */ #define VID_TYPE_MPEG_DECODER 1024 /* Can decode MPEG streams */ #define VID_TYPE_MPEG_ENCODER 2048 /* Can encode MPEG streams */ #define VID_TYPE_MJPEG_DECODER 4096 /* Can decode MJPEG streams */ #define VID_TYPE_MJPEG_ENCODER 8192 /* Can encode MJPEG streams *//** M I S C E L L A N E O U S*//* Four-character-code (FOURCC) */ #define v4l2_fourcc(a,b,c,d)\(((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))/** E N U M S*/ enum v4l2_field {V4L2_FIELD_ANY = 0, /* driver can choose from none,top, bottom, interlaceddepending on whatever it thinksis approximate ... */V4L2_FIELD_NONE = 1, /* this device has no fields ... */V4L2_FIELD_TOP = 2, /* top field only */V4L2_FIELD_BOTTOM = 3, /* bottom field only */V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into onebuffer, top-bottom order */V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order */V4L2_FIELD_ALTERNATE = 7, /* both fields alternating intoseparate buffers */V4L2_FIELD_INTERLACED_TB = 8, /* both fields interlaced, top fieldfirst and the top field istransmitted first */V4L2_FIELD_INTERLACED_BT = 9, /* both fields interlaced, top fieldfirst and the bottom field istransmitted first */ }; #define V4L2_FIELD_HAS_TOP(field) \((field) == V4L2_FIELD_TOP ||\(field) == V4L2_FIELD_INTERLACED ||\(field) == V4L2_FIELD_INTERLACED_TB ||\(field) == V4L2_FIELD_INTERLACED_BT ||\(field) == V4L2_FIELD_SEQ_TB ||\(field) == V4L2_FIELD_SEQ_BT) #define V4L2_FIELD_HAS_BOTTOM(field) \((field) == V4L2_FIELD_BOTTOM ||\(field) == V4L2_FIELD_INTERLACED ||\(field) == V4L2_FIELD_INTERLACED_TB ||\(field) == V4L2_FIELD_INTERLACED_BT ||\(field) == V4L2_FIELD_SEQ_TB ||\(field) == V4L2_FIELD_SEQ_BT) #define V4L2_FIELD_HAS_BOTH(field) \((field) == V4L2_FIELD_INTERLACED ||\(field) == V4L2_FIELD_INTERLACED_TB ||\(field) == V4L2_FIELD_INTERLACED_BT ||\(field) == V4L2_FIELD_SEQ_TB ||\(field) == V4L2_FIELD_SEQ_BT)enum v4l2_buf_type {V4L2_BUF_TYPE_VIDEO_CAPTURE = 1,V4L2_BUF_TYPE_VIDEO_OUTPUT = 2,V4L2_BUF_TYPE_VIDEO_OVERLAY = 3,V4L2_BUF_TYPE_VBI_CAPTURE = 4,V4L2_BUF_TYPE_VBI_OUTPUT = 5,V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = 6,V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = 7, #if 1 /*KEEP*//* Experimental */V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8, #endifV4L2_BUF_TYPE_PRIVATE = 0x80, };enum v4l2_ctrl_type {V4L2_CTRL_TYPE_INTEGER = 1,V4L2_CTRL_TYPE_BOOLEAN = 2,V4L2_CTRL_TYPE_MENU = 3,V4L2_CTRL_TYPE_BUTTON = 4,V4L2_CTRL_TYPE_INTEGER64 = 5,V4L2_CTRL_TYPE_CTRL_CLASS = 6, };enum v4l2_tuner_type {V4L2_TUNER_RADIO = 1,V4L2_TUNER_ANALOG_TV = 2,V4L2_TUNER_DIGITAL_TV = 3, };enum v4l2_memory {V4L2_MEMORY_MMAP = 1,V4L2_MEMORY_USERPTR = 2,V4L2_MEMORY_OVERLAY = 3, };/* see also http://vektor.theorem.ca/graphics/ycbcr/ */ enum v4l2_colorspace {/* ITU-R 601 -- broadcast NTSC/PAL */V4L2_COLORSPACE_SMPTE170M = 1,/* 1125-Line (US) HDTV */V4L2_COLORSPACE_SMPTE240M = 2,/* HD and modern captures. */V4L2_COLORSPACE_REC709 = 3,/* broken BT878 extents (601, luma range 16-253 instead of 16-235) */V4L2_COLORSPACE_BT878 = 4,/* These should be useful. Assume 601 extents. */V4L2_COLORSPACE_470_SYSTEM_M = 5,V4L2_COLORSPACE_470_SYSTEM_BG = 6,/* I know there will be cameras that send this. So, this is* unspecified chromaticities and full 0-255 on each of the* Y'CbCr components*/V4L2_COLORSPACE_JPEG = 7,/* For RGB colourspaces, this is probably a good start. */V4L2_COLORSPACE_SRGB = 8, };enum v4l2_priority {V4L2_PRIORITY_UNSET = 0, /* not initialized */V4L2_PRIORITY_BACKGROUND = 1,V4L2_PRIORITY_INTERACTIVE = 2,V4L2_PRIORITY_RECORD = 3,V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE, };struct v4l2_rect {__s32 left;__s32 top;__s32 width;__s32 height; };struct v4l2_fract {__u32 numerator;__u32 denominator; };/** D R I V E R C A P A B I L I T I E S*/ struct v4l2_capability {__u8 driver[16]; /* i.e.ie; "bttv" */__u8 card[32]; /* i.e.ie; "Hauppauge WinTV" */__u8 bus_info[32]; /* "PCI:" + pci_name(pci_dev) */__u32 version; /* should use KERNEL_VERSION() */__u32 capabilities; /* Device capabilities */__u32 reserved[4]; };/* Values for 'capabilities' field */ #define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */ #define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */ #define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */ #define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a raw VBI capture device */ #define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a raw VBI output device */ #define V4L2_CAP_SLICED_VBI_CAPTURE 0x00000040 /* Is a sliced VBI capture device */ #define V4L2_CAP_SLICED_VBI_OUTPUT 0x00000080 /* Is a sliced VBI output device */ #define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */ #define V4L2_CAP_VIDEO_OUTPUT_OVERLAY 0x00000200 /* Can do video output overlay */#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */ #define V4L2_CAP_AUDIO 0x00020000 /* has audio support */ #define V4L2_CAP_RADIO 0x00040000 /* is a radio device */#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */ #define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */ #define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls *//** V I D E O I M A G E F O R M A T*/ struct v4l2_pix_format {__u32 width;__u32 height;__u32 pixelformat;enum v4l2_field field;__u32 bytesperline; /* for padding, zero if unused */__u32 sizeimage;enum v4l2_colorspace colorspace;__u32 priv; /* private data, depends on pixelformat */ };/* Pixel format FOURCC depth Description */ #define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R','G','B','1') /* 8 RGB-3-3-2 */ #define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R','4','4','4') /* 16 xxxxrrrr ggggbbbb */ #define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R','G','B','O') /* 16 RGB-5-5-5 */ #define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R','G','B','P') /* 16 RGB-5-6-5 */ #define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R','G','B','Q') /* 16 RGB-5-5-5 BE */ #define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R','G','B','R') /* 16 RGB-5-6-5 BE */ #define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B','G','R','3') /* 24 BGR-8-8-8 */ #define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R','G','B','3') /* 24 RGB-8-8-8 */ #define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B','G','R','4') /* 32 BGR-8-8-8-8 */ #define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R','G','B','4') /* 32 RGB-8-8-8-8 */ #define V4L2_PIX_FMT_GREY v4l2_fourcc('G','R','E','Y') /* 8 Greyscale */ #define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y','1','6',' ') /* 16 Greyscale */ #define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P','A','L','8') /* 8 8-bit palette */ #define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y','V','U','9') /* 9 YVU 4:1:0 */ #define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y','V','1','2') /* 12 YVU 4:2:0 */ #define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y','U','Y','V') /* 16 YUV 4:2:2 */ #define V4L2_PIX_FMT_UYVY v4l2_fourcc('U','Y','V','Y') /* 16 YUV 4:2:2 */ #define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4','2','2','P') /* 16 YVU422 planar */ #define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4','1','1','P') /* 16 YVU411 planar */ #define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y','4','1','P') /* 12 YUV 4:1:1 */ #define V4L2_PIX_FMT_YUV444 v4l2_fourcc('Y','4','4','4') /* 16 xxxxyyyy uuuuvvvv */ #define V4L2_PIX_FMT_YUV555 v4l2_fourcc('Y','U','V','O') /* 16 YUV-5-5-5 */ #define V4L2_PIX_FMT_YUV565 v4l2_fourcc('Y','U','V','P') /* 16 YUV-5-6-5 */ #define V4L2_PIX_FMT_YUV32 v4l2_fourcc('Y','U','V','4') /* 32 YUV-8-8-8-8 *//* two planes -- one Y, one Cr + Cb interleaved */ #define V4L2_PIX_FMT_NV12 v4l2_fourcc('N','V','1','2') /* 12 Y/CbCr 4:2:0 */ #define V4L2_PIX_FMT_NV21 v4l2_fourcc('N','V','2','1') /* 12 Y/CrCb 4:2:0 *//* The following formats are not defined in the V4L2 specification */ #define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y','U','V','9') /* 9 YUV 4:1:0 */ #define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y','U','1','2') /* 12 YUV 4:2:0 */ #define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y','Y','U','V') /* 16 YUV 4:2:2 */ #define V4L2_PIX_FMT_HI240 v4l2_fourcc('H','I','2','4') /* 8 8-bit color */ #define V4L2_PIX_FMT_HM12 v4l2_fourcc('H','M','1','2') /* 8 YUV 4:2:0 16x16 macroblocks *//* see http://www.siliconimaging.com/RGB%20Bayer.htm */ #define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */ #define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B','Y','R','2') /* 16 BGBG.. GRGR.. *//* compressed formats */ #define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M','J','P','G') /* Motion-JPEG */ #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J','P','E','G') /* JFIF JPEG */ #define V4L2_PIX_FMT_DV v4l2_fourcc('d','v','s','d') /* 1394 */ #define V4L2_PIX_FMT_MPEG v4l2_fourcc('M','P','E','G') /* MPEG-1/2/4 *//* Vendor-specific formats */ #define V4L2_PIX_FMT_WNVA v4l2_fourcc('W','N','V','A') /* Winnov hw compress */ #define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S','9','1','0') /* SN9C10x compression */ #define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P','W','C','1') /* pwc older webcam */ #define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P','W','C','2') /* pwc newer webcam */ #define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E','6','2','5') /* ET61X251 compression *//** F O R M A T E N U M E R A T I O N*/ struct v4l2_fmtdesc {__u32 index; /* Format number */enum v4l2_buf_type type; /* buffer type */__u32 flags;__u8 description[32]; /* Description string */__u32 pixelformat; /* Format fourcc */__u32 reserved[4]; };#define V4L2_FMT_FLAG_COMPRESSED 0x0001#if 1 /*KEEP*//* Experimental Frame Size and frame rate enumeration */ /** F R A M E S I Z E E N U M E R A T I O N*/ enum v4l2_frmsizetypes {V4L2_FRMSIZE_TYPE_DISCRETE = 1,V4L2_FRMSIZE_TYPE_CONTINUOUS = 2,V4L2_FRMSIZE_TYPE_STEPWISE = 3, };struct v4l2_frmsize_discrete {__u32 width; /* Frame width [pixel] */__u32 height; /* Frame height [pixel] */ };struct v4l2_frmsize_stepwise {__u32 min_width; /* Minimum frame width [pixel] */__u32 max_width; /* Maximum frame width [pixel] */__u32 step_width; /* Frame width step size [pixel] */__u32 min_height; /* Minimum frame height [pixel] */__u32 max_height; /* Maximum frame height [pixel] */__u32 step_height; /* Frame height step size [pixel] */ };struct v4l2_frmsizeenum {__u32 index; /* Frame size number */__u32 pixel_format; /* Pixel format */__u32 type; /* Frame size type the device supports. */union { /* Frame size */struct v4l2_frmsize_discrete discrete;struct v4l2_frmsize_stepwise stepwise;};__u32 reserved[2]; /* Reserved space for future use */ };/** F R A M E R A T E E N U M E R A T I O N*/ enum v4l2_frmivaltypes {V4L2_FRMIVAL_TYPE_DISCRETE = 1,V4L2_FRMIVAL_TYPE_CONTINUOUS = 2,V4L2_FRMIVAL_TYPE_STEPWISE = 3, };struct v4l2_frmival_stepwise {struct v4l2_fract min; /* Minimum frame interval [s] */struct v4l2_fract max; /* Maximum frame interval [s] */struct v4l2_fract step; /* Frame interval step size [s] */ };struct v4l2_frmivalenum {__u32 index; /* Frame format index */__u32 pixel_format; /* Pixel format */__u32 width; /* Frame width */__u32 height; /* Frame height */__u32 type; /* Frame interval type the device supports. */union { /* Frame interval */struct v4l2_fract discrete;struct v4l2_frmival_stepwise stepwise;};__u32 reserved[2]; /* Reserved space for future use */ }; #endif/** T I M E C O D E*/ struct v4l2_timecode {__u32 type;__u32 flags;__u8 frames;__u8 seconds;__u8 minutes;__u8 hours;__u8 userbits[4]; };/* Type */ #define V4L2_TC_TYPE_24FPS 1 #define V4L2_TC_TYPE_25FPS 2 #define V4L2_TC_TYPE_30FPS 3 #define V4L2_TC_TYPE_50FPS 4 #define V4L2_TC_TYPE_60FPS 5/* Flags */ #define V4L2_TC_FLAG_DROPFRAME 0x0001 /* "drop-frame" mode */ #define V4L2_TC_FLAG_COLORFRAME 0x0002 #define V4L2_TC_USERBITS_field 0x000C #define V4L2_TC_USERBITS_USERDEFINED 0x0000 #define V4L2_TC_USERBITS_8BITCHARS 0x0008 /* The above is based on SMPTE timecodes */struct v4l2_jpegcompression {int quality;int APPn; /* Number of APP segment to be written,* must be 0..15 */int APP_len; /* Length of data in JPEG APPn segment */char APP_data[60]; /* Data in the JPEG APPn segment. */int COM_len; /* Length of data in JPEG COM segment */char COM_data[60]; /* Data in JPEG COM segment */__u32 jpeg_markers; /* Which markers should go into the JPEG* output. Unless you exactly know what* you do, leave them untouched.* Inluding less markers will make the* resulting code smaller, but there will* be fewer aplications which can read it.* The presence of the APP and COM marker* is influenced by APP_len and COM_len* ONLY, not by this property! */#define V4L2_JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */ #define V4L2_JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */ #define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */ #define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */ #define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will* allways use APP0 */ };/** M E M O R Y - M A P P I N G B U F F E R S*/ struct v4l2_requestbuffers {__u32 count;enum v4l2_buf_type type;enum v4l2_memory memory;__u32 reserved[2]; };struct v4l2_buffer {__u32 index;enum v4l2_buf_type type;__u32 bytesused;__u32 flags;enum v4l2_field field;struct timeval timestamp;struct v4l2_timecode timecode;__u32 sequence;/* memory location */enum v4l2_memory memory;union {__u32 offset;unsigned long userptr;} m;__u32 length;__u32 input;__u32 reserved; };/* Flags for 'flags' field */ #define V4L2_BUF_FLAG_MAPPED 0x0001 /* Buffer is mapped (flag) */ #define V4L2_BUF_FLAG_QUEUED 0x0002 /* Buffer is queued for processing */ #define V4L2_BUF_FLAG_DONE 0x0004 /* Buffer is ready */ #define V4L2_BUF_FLAG_KEYFRAME 0x0008 /* Image is a keyframe (I-frame) */ #define V4L2_BUF_FLAG_PFRAME 0x0010 /* Image is a P-frame */ #define V4L2_BUF_FLAG_BFRAME 0x0020 /* Image is a B-frame */ #define V4L2_BUF_FLAG_TIMECODE 0x0100 /* timecode field is valid */ #define V4L2_BUF_FLAG_INPUT 0x0200 /* input field is valid *//** O V E R L A Y P R E V I E W*/ struct v4l2_framebuffer {__u32 capability;__u32 flags; /* FIXME: in theory we should pass something like PCI device + memory* region + offset instead of some physical address */void* base;struct v4l2_pix_format fmt; }; /* Flags for the 'capability' field. Read only */ #define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001 #define V4L2_FBUF_CAP_CHROMAKEY 0x0002 #define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004 #define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008 #define V4L2_FBUF_CAP_LOCAL_ALPHA 0x0010 #define V4L2_FBUF_CAP_GLOBAL_ALPHA 0x0020 #define V4L2_FBUF_CAP_LOCAL_INV_ALPHA 0x0040 /* Flags for the 'flags' field. */ #define V4L2_FBUF_FLAG_PRIMARY 0x0001 #define V4L2_FBUF_FLAG_OVERLAY 0x0002 #define V4L2_FBUF_FLAG_CHROMAKEY 0x0004 #define V4L2_FBUF_FLAG_LOCAL_ALPHA 0x0008 #define V4L2_FBUF_FLAG_GLOBAL_ALPHA 0x0010 #define V4L2_FBUF_FLAG_LOCAL_INV_ALPHA 0x0020struct v4l2_clip {struct v4l2_rect c;struct v4l2_clip __user *next; };struct v4l2_window {struct v4l2_rect w;enum v4l2_field field;__u32 chromakey;struct v4l2_clip __user *clips;__u32 clipcount;void __user *bitmap;__u8 global_alpha; };/** C A P T U R E P A R A M E T E R S*/ struct v4l2_captureparm {__u32 capability; /* Supported modes */__u32 capturemode; /* Current mode */struct v4l2_fract timeperframe; /* Time per frame in .1us units */__u32 extendedmode; /* Driver-specific extensions */__u32 readbuffers; /* # of buffers for read */__u32 reserved[4]; };/* Flags for 'capability' and 'capturemode' fields */ #define V4L2_MODE_HIGHQUALITY 0x0001 /* High quality imaging mode */ #define V4L2_CAP_TIMEPERFRAME 0x1000 /* timeperframe field is supported */struct v4l2_outputparm {__u32 capability; /* Supported modes */__u32 outputmode; /* Current mode */struct v4l2_fract timeperframe; /* Time per frame in seconds */__u32 extendedmode; /* Driver-specific extensions */__u32 writebuffers; /* # of buffers for write */__u32 reserved[4]; };/** I N P U T I M A G E C R O P P I N G*/ struct v4l2_cropcap {enum v4l2_buf_type type;struct v4l2_rect bounds;struct v4l2_rect defrect;struct v4l2_fract pixelaspect; };struct v4l2_crop {enum v4l2_buf_type type;struct v4l2_rect c; };/** A N A L O G V I D E O S T A N D A R D*/typedef __u64 v4l2_std_id;/* one bit for each */ #define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001) #define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002) #define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004) #define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008) #define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010) #define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020) #define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040) #define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080)#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100) #define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200) #define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400) #define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800)#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000) #define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000) #define V4L2_STD_NTSC_443 ((v4l2_std_id)0x00004000) #define V4L2_STD_NTSC_M_KR ((v4l2_std_id)0x00008000)#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000) #define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000) #define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000) #define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000) #define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000) #define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000) #define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000) #define V4L2_STD_SECAM_LC ((v4l2_std_id)0x00800000)/* ATSC/HDTV */ #define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000) #define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000)/* FIXME:Although std_id is 64 bits, there is an issue on PPC32 architecture thatmakes switch(__u64) to break. So, there's a hack on v4l2-common.c roundingthis value to 32 bits.As, currently, the max value is for V4L2_STD_ATSC_16_VSB (30 bits wide),it should work fine. However, if needed to add more than two standards,v4l2-common.c should be fixed.*//* some merged standards */ #define V4L2_STD_MN (V4L2_STD_PAL_M|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|V4L2_STD_NTSC) #define V4L2_STD_B (V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_SECAM_B) #define V4L2_STD_GH (V4L2_STD_PAL_G|V4L2_STD_PAL_H|V4L2_STD_SECAM_G|V4L2_STD_SECAM_H) #define V4L2_STD_DK (V4L2_STD_PAL_DK|V4L2_STD_SECAM_DK)/* some common needed stuff */ #define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\V4L2_STD_PAL_B1 |\V4L2_STD_PAL_G) #define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\V4L2_STD_PAL_D1 |\V4L2_STD_PAL_K) #define V4L2_STD_PAL (V4L2_STD_PAL_BG |\V4L2_STD_PAL_DK |\V4L2_STD_PAL_H |\V4L2_STD_PAL_I) #define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\V4L2_STD_NTSC_M_JP |\V4L2_STD_NTSC_M_KR) #define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |\V4L2_STD_SECAM_K |\V4L2_STD_SECAM_K1) #define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\V4L2_STD_SECAM_G |\V4L2_STD_SECAM_H |\V4L2_STD_SECAM_DK |\V4L2_STD_SECAM_L |\V4L2_STD_SECAM_LC)#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\V4L2_STD_PAL_60 |\V4L2_STD_NTSC |\V4L2_STD_NTSC_443) #define V4L2_STD_625_50 (V4L2_STD_PAL |\V4L2_STD_PAL_N |\V4L2_STD_PAL_Nc |\V4L2_STD_SECAM) #define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |\V4L2_STD_ATSC_16_VSB)#define V4L2_STD_UNKNOWN 0 #define V4L2_STD_ALL (V4L2_STD_525_60 |\V4L2_STD_625_50)struct v4l2_standard {__u32 index;v4l2_std_id id;__u8 name[24];struct v4l2_fract frameperiod; /* Frames, not fields */__u32 framelines;__u32 reserved[4]; };/** V I D E O I N P U T S*/ struct v4l2_input {__u32 index; /* Which input */__u8 name[32]; /* Label */__u32 type; /* Type of input */__u32 audioset; /* Associated audios (bitfield) */__u32 tuner; /* Associated tuner */v4l2_std_id std;__u32 status;__u32 reserved[4]; };/* Values for the 'type' field */ #define V4L2_INPUT_TYPE_TUNER 1 #define V4L2_INPUT_TYPE_CAMERA 2/* field 'status' - general */ #define V4L2_IN_ST_NO_POWER 0x00000001 /* Attached device is off */ #define V4L2_IN_ST_NO_SIGNAL 0x00000002 #define V4L2_IN_ST_NO_COLOR 0x00000004/* field 'status' - analog */ #define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */ #define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active *//* field 'status' - digital */ #define V4L2_IN_ST_NO_SYNC 0x00010000 /* No synchronization lock */ #define V4L2_IN_ST_NO_EQU 0x00020000 /* No equalizer lock */ #define V4L2_IN_ST_NO_CARRIER 0x00040000 /* Carrier recovery failed *//* field 'status' - VCR and set-top box */ #define V4L2_IN_ST_MACROVISION 0x01000000 /* Macrovision detected */ #define V4L2_IN_ST_NO_ACCESS 0x02000000 /* Conditional access denied */ #define V4L2_IN_ST_VTR 0x04000000 /* VTR time constant *//** V I D E O O U T P U T S*/ struct v4l2_output {__u32 index; /* Which output */__u8 name[32]; /* Label */__u32 type; /* Type of output */__u32 audioset; /* Associated audios (bitfield) */__u32 modulator; /* Associated modulator */v4l2_std_id std;__u32 reserved[4]; }; /* Values for the 'type' field */ #define V4L2_OUTPUT_TYPE_MODULATOR 1 #define V4L2_OUTPUT_TYPE_ANALOG 2 #define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3/** C O N T R O L S*/ struct v4l2_control {__u32 id;__s32 value; };struct v4l2_ext_control {__u32 id;__u32 reserved2[2];union {__s32 value;__s64 value64;void *reserved;}; } __attribute__ ((packed));struct v4l2_ext_controls {__u32 ctrl_class;__u32 count;__u32 error_idx;__u32 reserved[2];struct v4l2_ext_control *controls; };/* Values for ctrl_class field */ #define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */ #define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */ #define V4L2_CTRL_CLASS_CAMERA 0x009a0000 /* Camera class controls */#define V4L2_CTRL_ID_MASK (0x0fffffff) #define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL) #define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ struct v4l2_queryctrl {__u32 id;enum v4l2_ctrl_type type;__u8 name[32]; /* Whatever */__s32 minimum; /* Note signedness */__s32 maximum;__s32 step;__s32 default_value;__u32 flags;__u32 reserved[2]; };/* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */ struct v4l2_querymenu {__u32 id;__u32 index;__u8 name[32]; /* Whatever */__u32 reserved; };/* Control flags */ #define V4L2_CTRL_FLAG_DISABLED 0x0001 #define V4L2_CTRL_FLAG_GRABBED 0x0002 #define V4L2_CTRL_FLAG_READ_ONLY 0x0004 #define V4L2_CTRL_FLAG_UPDATE 0x0008 #define V4L2_CTRL_FLAG_INACTIVE 0x0010 #define V4L2_CTRL_FLAG_SLIDER 0x0020/* Query flag, to be ORed with the control ID */ #define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000/* User-class control IDs defined by V4L2 */ #define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900) #define V4L2_CID_USER_BASE V4L2_CID_BASE /* IDs reserved for driver specific controls */ #define V4L2_CID_PRIVATE_BASE 0x08000000#define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1) #define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0) #define V4L2_CID_CONTRAST (V4L2_CID_BASE+1) #define V4L2_CID_SATURATION (V4L2_CID_BASE+2) #define V4L2_CID_HUE (V4L2_CID_BASE+3) #define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5) #define V4L2_CID_AUDIO_BALANCE (V4L2_CID_BASE+6) #define V4L2_CID_AUDIO_BASS (V4L2_CID_BASE+7) #define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8) #define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9) #define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10) #define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11) /* Deprecated */ #define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12) #define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13) #define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14) #define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15) #define V4L2_CID_GAMMA (V4L2_CID_BASE+16) #define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* Deprecated */ #define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17) #define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18) #define V4L2_CID_GAIN (V4L2_CID_BASE+19) #define V4L2_CID_HFLIP (V4L2_CID_BASE+20) #define V4L2_CID_VFLIP (V4L2_CID_BASE+21)/* Deprecated, use V4L2_CID_PAN_RESET and V4L2_CID_TILT_RESET */ #define V4L2_CID_HCENTER_DEPRECATED (V4L2_CID_BASE+22) #define V4L2_CID_VCENTER_DEPRECATED (V4L2_CID_BASE+23)#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24) enum v4l2_power_line_frequency {V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0,V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1,V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2, }; #define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25) #define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26) #define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27) #define V4L2_CID_BACKLIGHT_COMPENSATION (V4L2_CID_BASE+28) #define V4L2_CID_LASTP1 (V4L2_CID_BASE+29) /* last CID + 1 *//* MPEG-class control IDs defined by V4L2 */ #define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900) #define V4L2_CID_MPEG_CLASS (V4L2_CTRL_CLASS_MPEG | 1)/* MPEG streams */ #define V4L2_CID_MPEG_STREAM_TYPE (V4L2_CID_MPEG_BASE+0) enum v4l2_mpeg_stream_type {V4L2_MPEG_STREAM_TYPE_MPEG2_PS = 0, /* MPEG-2 program stream */V4L2_MPEG_STREAM_TYPE_MPEG2_TS = 1, /* MPEG-2 transport stream */V4L2_MPEG_STREAM_TYPE_MPEG1_SS = 2, /* MPEG-1 system stream */V4L2_MPEG_STREAM_TYPE_MPEG2_DVD = 3, /* MPEG-2 DVD-compatible stream */V4L2_MPEG_STREAM_TYPE_MPEG1_VCD = 4, /* MPEG-1 VCD-compatible stream */V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD = 5, /* MPEG-2 SVCD-compatible stream */ }; #define V4L2_CID_MPEG_STREAM_PID_PMT (V4L2_CID_MPEG_BASE+1) #define V4L2_CID_MPEG_STREAM_PID_AUDIO (V4L2_CID_MPEG_BASE+2) #define V4L2_CID_MPEG_STREAM_PID_VIDEO (V4L2_CID_MPEG_BASE+3) #define V4L2_CID_MPEG_STREAM_PID_PCR (V4L2_CID_MPEG_BASE+4) #define V4L2_CID_MPEG_STREAM_PES_ID_AUDIO (V4L2_CID_MPEG_BASE+5) #define V4L2_CID_MPEG_STREAM_PES_ID_VIDEO (V4L2_CID_MPEG_BASE+6) #define V4L2_CID_MPEG_STREAM_VBI_FMT (V4L2_CID_MPEG_BASE+7) enum v4l2_mpeg_stream_vbi_fmt {V4L2_MPEG_STREAM_VBI_FMT_NONE = 0, /* No VBI in the MPEG stream */V4L2_MPEG_STREAM_VBI_FMT_IVTV = 1, /* VBI in private packets, IVTV format */ };/* MPEG audio */ #define V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ (V4L2_CID_MPEG_BASE+100) enum v4l2_mpeg_audio_sampling_freq {V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100 = 0,V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000 = 1,V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000 = 2, }; #define V4L2_CID_MPEG_AUDIO_ENCODING (V4L2_CID_MPEG_BASE+101) enum v4l2_mpeg_audio_encoding {V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0,V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1,V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2, }; #define V4L2_CID_MPEG_AUDIO_L1_BITRATE (V4L2_CID_MPEG_BASE+102) enum v4l2_mpeg_audio_l1_bitrate {V4L2_MPEG_AUDIO_L1_BITRATE_32K = 0,V4L2_MPEG_AUDIO_L1_BITRATE_64K = 1,V4L2_MPEG_AUDIO_L1_BITRATE_96K = 2,V4L2_MPEG_AUDIO_L1_BITRATE_128K = 3,V4L2_MPEG_AUDIO_L1_BITRATE_160K = 4,V4L2_MPEG_AUDIO_L1_BITRATE_192K = 5,V4L2_MPEG_AUDIO_L1_BITRATE_224K = 6,V4L2_MPEG_AUDIO_L1_BITRATE_256K = 7,V4L2_MPEG_AUDIO_L1_BITRATE_288K = 8,V4L2_MPEG_AUDIO_L1_BITRATE_320K = 9,V4L2_MPEG_AUDIO_L1_BITRATE_352K = 10,V4L2_MPEG_AUDIO_L1_BITRATE_384K = 11,V4L2_MPEG_AUDIO_L1_BITRATE_416K = 12,V4L2_MPEG_AUDIO_L1_BITRATE_448K = 13, }; #define V4L2_CID_MPEG_AUDIO_L2_BITRATE (V4L2_CID_MPEG_BASE+103) enum v4l2_mpeg_audio_l2_bitrate {V4L2_MPEG_AUDIO_L2_BITRATE_32K = 0,V4L2_MPEG_AUDIO_L2_BITRATE_48K = 1,V4L2_MPEG_AUDIO_L2_BITRATE_56K = 2,V4L2_MPEG_AUDIO_L2_BITRATE_64K = 3,V4L2_MPEG_AUDIO_L2_BITRATE_80K = 4,V4L2_MPEG_AUDIO_L2_BITRATE_96K = 5,V4L2_MPEG_AUDIO_L2_BITRATE_112K = 6,V4L2_MPEG_AUDIO_L2_BITRATE_128K = 7,V4L2_MPEG_AUDIO_L2_BITRATE_160K = 8,V4L2_MPEG_AUDIO_L2_BITRATE_192K = 9,V4L2_MPEG_AUDIO_L2_BITRATE_224K = 10,V4L2_MPEG_AUDIO_L2_BITRATE_256K = 11,V4L2_MPEG_AUDIO_L2_BITRATE_320K = 12,V4L2_MPEG_AUDIO_L2_BITRATE_384K = 13, }; #define V4L2_CID_MPEG_AUDIO_L3_BITRATE (V4L2_CID_MPEG_BASE+104) enum v4l2_mpeg_audio_l3_bitrate {V4L2_MPEG_AUDIO_L3_BITRATE_32K = 0,V4L2_MPEG_AUDIO_L3_BITRATE_40K = 1,V4L2_MPEG_AUDIO_L3_BITRATE_48K = 2,V4L2_MPEG_AUDIO_L3_BITRATE_56K = 3,V4L2_MPEG_AUDIO_L3_BITRATE_64K = 4,V4L2_MPEG_AUDIO_L3_BITRATE_80K = 5,V4L2_MPEG_AUDIO_L3_BITRATE_96K = 6,V4L2_MPEG_AUDIO_L3_BITRATE_112K = 7,V4L2_MPEG_AUDIO_L3_BITRATE_128K = 8,V4L2_MPEG_AUDIO_L3_BITRATE_160K = 9,V4L2_MPEG_AUDIO_L3_BITRATE_192K = 10,V4L2_MPEG_AUDIO_L3_BITRATE_224K = 11,V4L2_MPEG_AUDIO_L3_BITRATE_256K = 12,V4L2_MPEG_AUDIO_L3_BITRATE_320K = 13, }; #define V4L2_CID_MPEG_AUDIO_MODE (V4L2_CID_MPEG_BASE+105) enum v4l2_mpeg_audio_mode {V4L2_MPEG_AUDIO_MODE_STEREO = 0,V4L2_MPEG_AUDIO_MODE_JOINT_STEREO = 1,V4L2_MPEG_AUDIO_MODE_DUAL = 2,V4L2_MPEG_AUDIO_MODE_MONO = 3, }; #define V4L2_CID_MPEG_AUDIO_MODE_EXTENSION (V4L2_CID_MPEG_BASE+106) enum v4l2_mpeg_audio_mode_extension {V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4 = 0,V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8 = 1,V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12 = 2,V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16 = 3, }; #define V4L2_CID_MPEG_AUDIO_EMPHASIS (V4L2_CID_MPEG_BASE+107) enum v4l2_mpeg_audio_emphasis {V4L2_MPEG_AUDIO_EMPHASIS_NONE = 0,V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS = 1,V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17 = 2, }; #define V4L2_CID_MPEG_AUDIO_CRC (V4L2_CID_MPEG_BASE+108) enum v4l2_mpeg_audio_crc {V4L2_MPEG_AUDIO_CRC_NONE = 0,V4L2_MPEG_AUDIO_CRC_CRC16 = 1, }; #define V4L2_CID_MPEG_AUDIO_MUTE (V4L2_CID_MPEG_BASE+109)/* MPEG video */ #define V4L2_CID_MPEG_VIDEO_ENCODING (V4L2_CID_MPEG_BASE+200) enum v4l2_mpeg_video_encoding {V4L2_MPEG_VIDEO_ENCODING_MPEG_1 = 0,V4L2_MPEG_VIDEO_ENCODING_MPEG_2 = 1, }; #define V4L2_CID_MPEG_VIDEO_ASPECT (V4L2_CID_MPEG_BASE+201) enum v4l2_mpeg_video_aspect {V4L2_MPEG_VIDEO_ASPECT_1x1 = 0,V4L2_MPEG_VIDEO_ASPECT_4x3 = 1,V4L2_MPEG_VIDEO_ASPECT_16x9 = 2,V4L2_MPEG_VIDEO_ASPECT_221x100 = 3, }; #define V4L2_CID_MPEG_VIDEO_B_FRAMES (V4L2_CID_MPEG_BASE+202) #define V4L2_CID_MPEG_VIDEO_GOP_SIZE (V4L2_CID_MPEG_BASE+203) #define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE (V4L2_CID_MPEG_BASE+204) #define V4L2_CID_MPEG_VIDEO_PULLDOWN (V4L2_CID_MPEG_BASE+205) #define V4L2_CID_MPEG_VIDEO_BITRATE_MODE (V4L2_CID_MPEG_BASE+206) enum v4l2_mpeg_video_bitrate_mode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR = 0,V4L2_MPEG_VIDEO_BITRATE_MODE_CBR = 1, }; #define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_MPEG_BASE+207) #define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_MPEG_BASE+208) #define V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (V4L2_CID_MPEG_BASE+209) #define V4L2_CID_MPEG_VIDEO_MUTE (V4L2_CID_MPEG_BASE+210) #define V4L2_CID_MPEG_VIDEO_MUTE_YUV (V4L2_CID_MPEG_BASE+211)/* MPEG-class control IDs specific to the CX2584x driver as defined by V4L2 */ #define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000) #define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+0) enum v4l2_mpeg_cx2341x_video_spatial_filter_mode {V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0,V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO = 1, }; #define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+1) #define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+2) enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type {V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF = 0,V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR = 1,V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT = 2,V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE = 3,V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE = 4, }; #define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+3) enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type {V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF = 0,V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR = 1, }; #define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+4) enum v4l2_mpeg_cx2341x_video_temporal_filter_mode {V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL = 0,V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO = 1, }; #define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+5) #define V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+6) enum v4l2_mpeg_cx2341x_video_median_filter_type {V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF = 0,V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR = 1,V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT = 2,V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3,V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG = 4, }; #define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+7) #define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+8) #define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+9) #define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10) #define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_MPEG_CX2341X_BASE+11)/* Camera class control IDs */ #define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900) #define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1)#define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1) enum v4l2_exposure_auto_type {V4L2_EXPOSURE_AUTO = 0,V4L2_EXPOSURE_MANUAL = 1,V4L2_EXPOSURE_SHUTTER_PRIORITY = 2,V4L2_EXPOSURE_APERTURE_PRIORITY = 3 }; #define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2) #define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3)#define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4) #define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5) #define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6) #define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7)#define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8) #define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9)#define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10) #define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11) #define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12)/** T U N I N G*/ struct v4l2_tuner {__u32 index;__u8 name[32];enum v4l2_tuner_type type;__u32 capability;__u32 rangelow;__u32 rangehigh;__u32 rxsubchans;__u32 audmode;__s32 signal;__s32 afc;__u32 reserved[4]; };struct v4l2_modulator {__u32 index;__u8 name[32];__u32 capability;__u32 rangelow;__u32 rangehigh;__u32 txsubchans;__u32 reserved[4]; };/* Flags for the 'capability' field */ #define V4L2_TUNER_CAP_LOW 0x0001 #define V4L2_TUNER_CAP_NORM 0x0002 #define V4L2_TUNER_CAP_STEREO 0x0010 #define V4L2_TUNER_CAP_LANG2 0x0020 #define V4L2_TUNER_CAP_SAP 0x0020 #define V4L2_TUNER_CAP_LANG1 0x0040/* Flags for the 'rxsubchans' field */ #define V4L2_TUNER_SUB_MONO 0x0001 #define V4L2_TUNER_SUB_STEREO 0x0002 #define V4L2_TUNER_SUB_LANG2 0x0004 #define V4L2_TUNER_SUB_SAP 0x0004 #define V4L2_TUNER_SUB_LANG1 0x0008/* Values for the 'audmode' field */ #define V4L2_TUNER_MODE_MONO 0x0000 #define V4L2_TUNER_MODE_STEREO 0x0001 #define V4L2_TUNER_MODE_LANG2 0x0002 #define V4L2_TUNER_MODE_SAP 0x0002 #define V4L2_TUNER_MODE_LANG1 0x0003 #define V4L2_TUNER_MODE_LANG1_LANG2 0x0004struct v4l2_frequency {__u32 tuner;enum v4l2_tuner_type type;__u32 frequency;__u32 reserved[8]; };/** A U D I O*/ struct v4l2_audio {__u32 index;__u8 name[32];__u32 capability;__u32 mode;__u32 reserved[2]; };/* Flags for the 'capability' field */ #define V4L2_AUDCAP_STEREO 0x00001 #define V4L2_AUDCAP_AVL 0x00002/* Flags for the 'mode' field */ #define V4L2_AUDMODE_AVL 0x00001struct v4l2_audioout {__u32 index;__u8 name[32];__u32 capability;__u32 mode;__u32 reserved[2]; };/** M P E G S E R V I C E S** NOTE: EXPERIMENTAL API*/ #if 1 /*KEEP*/ #define V4L2_ENC_IDX_FRAME_I (0) #define V4L2_ENC_IDX_FRAME_P (1) #define V4L2_ENC_IDX_FRAME_B (2) #define V4L2_ENC_IDX_FRAME_MASK (0xf)struct v4l2_enc_idx_entry {__u64 offset;__u64 pts;__u32 length;__u32 flags;__u32 reserved[2]; };#define V4L2_ENC_IDX_ENTRIES (64) struct v4l2_enc_idx {__u32 entries;__u32 entries_cap;__u32 reserved[4];struct v4l2_enc_idx_entry entry[V4L2_ENC_IDX_ENTRIES]; };#define V4L2_ENC_CMD_START (0) #define V4L2_ENC_CMD_STOP (1) #define V4L2_ENC_CMD_PAUSE (2) #define V4L2_ENC_CMD_RESUME (3)/* Flags for V4L2_ENC_CMD_STOP */ #define V4L2_ENC_CMD_STOP_AT_GOP_END (1 << 0)struct v4l2_encoder_cmd {__u32 cmd;__u32 flags;union {struct {__u32 data[8];} raw;}; };#endif/** D A T A S E R V I C E S ( V B I )** Data services API by Michael Schimek*//* Raw VBI */ struct v4l2_vbi_format {__u32 sampling_rate; /* in 1 Hz */__u32 offset;__u32 samples_per_line;__u32 sample_format; /* V4L2_PIX_FMT_* */__s32 start[2];__u32 count[2];__u32 flags; /* V4L2_VBI_* */__u32 reserved[2]; /* must be zero */ };/* VBI flags */ #define V4L2_VBI_UNSYNC (1<< 0) #define V4L2_VBI_INTERLACED (1<< 1)/* Sliced VBI** This implements is a proposal V4L2 API to allow SLICED VBI* required for some hardware encoders. It should change without* notice in the definitive implementation.*/struct v4l2_sliced_vbi_format {__u16 service_set;/* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first fieldservice_lines[1][...] specifies lines 0-23 (1-23 used) of the second field(equals frame lines 313-336 for 625 line videostandards, 263-286 for 525 line standards) */__u16 service_lines[2][24];__u32 io_size;__u32 reserved[2]; /* must be zero */ };/* Teletext World System Teletext(WST), defined on ITU-R BT.653-2 */ #define V4L2_SLICED_TELETEXT_B (0x0001) /* Video Program System, defined on ETS 300 231*/ #define V4L2_SLICED_VPS (0x0400) /* Closed Caption, defined on EIA-608 */ #define V4L2_SLICED_CAPTION_525 (0x1000) /* Wide Screen System, defined on ITU-R BT1119.1 */ #define V4L2_SLICED_WSS_625 (0x4000)#define V4L2_SLICED_VBI_525 (V4L2_SLICED_CAPTION_525) #define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625)struct v4l2_sliced_vbi_cap {__u16 service_set;/* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first fieldservice_lines[1][...] specifies lines 0-23 (1-23 used) of the second field(equals frame lines 313-336 for 625 line videostandards, 263-286 for 525 line standards) */__u16 service_lines[2][24];enum v4l2_buf_type type;__u32 reserved[3]; /* must be 0 */ };struct v4l2_sliced_vbi_data {__u32 id;__u32 field; /* 0: first field, 1: second field */__u32 line; /* 1-23 */__u32 reserved; /* must be 0 */__u8 data[48]; };/** A G G R E G A T E S T R U C T U R E S*//* Stream data format*/ struct v4l2_format {enum v4l2_buf_type type;union{struct v4l2_pix_format pix; // V4L2_BUF_TYPE_VIDEO_CAPTUREstruct v4l2_window win; // V4L2_BUF_TYPE_VIDEO_OVERLAYstruct v4l2_vbi_format vbi; // V4L2_BUF_TYPE_VBI_CAPTUREstruct v4l2_sliced_vbi_format sliced; // V4L2_BUF_TYPE_SLICED_VBI_CAPTURE__u8 raw_data[200]; // user-defined} fmt; };/* Stream type-dependent parameters*/ struct v4l2_streamparm {enum v4l2_buf_type type;union{struct v4l2_captureparm capture;struct v4l2_outputparm output;__u8 raw_data[200]; /* user-defined */} parm; };/** A D V A N C E D D E B U G G I N G** NOTE: EXPERIMENTAL API*//* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */#define V4L2_CHIP_MATCH_HOST 0 /* Match against chip ID on host (0 for the host) */ #define V4L2_CHIP_MATCH_I2C_DRIVER 1 /* Match against I2C driver ID */ #define V4L2_CHIP_MATCH_I2C_ADDR 2 /* Match against I2C 7-bit address */struct v4l2_register {__u32 match_type; /* Match type */__u32 match_chip; /* Match this chip, meaning determined by match_type */__u64 reg;__u64 val; };/* VIDIOC_G_CHIP_IDENT */ struct v4l2_chip_ident {__u32 match_type; /* Match type */__u32 match_chip; /* Match this chip, meaning determined by match_type */__u32 ident; /* chip identifier as specified in <media/v4l2-chip-ident.h> */__u32 revision; /* chip revision, chip specific */ };/** I O C T L C O D E S F O R V I D E O D E V I C E S**/ #define VIDIOC_QUERYCAP _IOR ('V', 0, struct v4l2_capability) #define VIDIOC_RESERVED _IO ('V', 1) #define VIDIOC_ENUM_FMT _IOWR ('V', 2, struct v4l2_fmtdesc) #define VIDIOC_G_FMT _IOWR ('V', 4, struct v4l2_format) #define VIDIOC_S_FMT _IOWR ('V', 5, struct v4l2_format) #define VIDIOC_REQBUFS _IOWR ('V', 8, struct v4l2_requestbuffers) #define VIDIOC_QUERYBUF _IOWR ('V', 9, struct v4l2_buffer) #define VIDIOC_G_FBUF _IOR ('V', 10, struct v4l2_framebuffer) #define VIDIOC_S_FBUF _IOW ('V', 11, struct v4l2_framebuffer) #define VIDIOC_OVERLAY _IOW ('V', 14, int) #define VIDIOC_QBUF _IOWR ('V', 15, struct v4l2_buffer) #define VIDIOC_DQBUF _IOWR ('V', 17, struct v4l2_buffer) #define VIDIOC_STREAMON _IOW ('V', 18, int) #define VIDIOC_STREAMOFF _IOW ('V', 19, int) #define VIDIOC_G_PARM _IOWR ('V', 21, struct v4l2_streamparm) #define VIDIOC_S_PARM _IOWR ('V', 22, struct v4l2_streamparm) #define VIDIOC_G_STD _IOR ('V', 23, v4l2_std_id) #define VIDIOC_S_STD _IOW ('V', 24, v4l2_std_id) #define VIDIOC_ENUMSTD _IOWR ('V', 25, struct v4l2_standard) #define VIDIOC_ENUMINPUT _IOWR ('V', 26, struct v4l2_input) #define VIDIOC_G_CTRL _IOWR ('V', 27, struct v4l2_control) #define VIDIOC_S_CTRL _IOWR ('V', 28, struct v4l2_control) #define VIDIOC_G_TUNER _IOWR ('V', 29, struct v4l2_tuner) #define VIDIOC_S_TUNER _IOW ('V', 30, struct v4l2_tuner) #define VIDIOC_G_AUDIO _IOR ('V', 33, struct v4l2_audio) #define VIDIOC_S_AUDIO _IOW ('V', 34, struct v4l2_audio) #define VIDIOC_QUERYCTRL _IOWR ('V', 36, struct v4l2_queryctrl) #define VIDIOC_QUERYMENU _IOWR ('V', 37, struct v4l2_querymenu) #define VIDIOC_G_INPUT _IOR ('V', 38, int) #define VIDIOC_S_INPUT _IOWR ('V', 39, int) #define VIDIOC_G_OUTPUT _IOR ('V', 46, int) #define VIDIOC_S_OUTPUT _IOWR ('V', 47, int) #define VIDIOC_ENUMOUTPUT _IOWR ('V', 48, struct v4l2_output) #define VIDIOC_G_AUDOUT _IOR ('V', 49, struct v4l2_audioout) #define VIDIOC_S_AUDOUT _IOW ('V', 50, struct v4l2_audioout) #define VIDIOC_G_MODULATOR _IOWR ('V', 54, struct v4l2_modulator) #define VIDIOC_S_MODULATOR _IOW ('V', 55, struct v4l2_modulator) #define VIDIOC_G_FREQUENCY _IOWR ('V', 56, struct v4l2_frequency) #define VIDIOC_S_FREQUENCY _IOW ('V', 57, struct v4l2_frequency) #define VIDIOC_CROPCAP _IOWR ('V', 58, struct v4l2_cropcap) #define VIDIOC_G_CROP _IOWR ('V', 59, struct v4l2_crop) #define VIDIOC_S_CROP _IOW ('V', 60, struct v4l2_crop) #define VIDIOC_G_JPEGCOMP _IOR ('V', 61, struct v4l2_jpegcompression) #define VIDIOC_S_JPEGCOMP _IOW ('V', 62, struct v4l2_jpegcompression) #define VIDIOC_QUERYSTD _IOR ('V', 63, v4l2_std_id) #define VIDIOC_TRY_FMT _IOWR ('V', 64, struct v4l2_format) #define VIDIOC_ENUMAUDIO _IOWR ('V', 65, struct v4l2_audio) #define VIDIOC_ENUMAUDOUT _IOWR ('V', 66, struct v4l2_audioout) #define VIDIOC_G_PRIORITY _IOR ('V', 67, enum v4l2_priority) #define VIDIOC_S_PRIORITY _IOW ('V', 68, enum v4l2_priority) #define VIDIOC_G_SLICED_VBI_CAP _IOWR ('V', 69, struct v4l2_sliced_vbi_cap) #define VIDIOC_LOG_STATUS _IO ('V', 70) #define VIDIOC_G_EXT_CTRLS _IOWR ('V', 71, struct v4l2_ext_controls) #define VIDIOC_S_EXT_CTRLS _IOWR ('V', 72, struct v4l2_ext_controls) #define VIDIOC_TRY_EXT_CTRLS _IOWR ('V', 73, struct v4l2_ext_controls) #if 1 /*KEEP*/ #define VIDIOC_ENUM_FRAMESIZES _IOWR ('V', 74, struct v4l2_frmsizeenum) #define VIDIOC_ENUM_FRAMEINTERVALS _IOWR ('V', 75, struct v4l2_frmivalenum) #define VIDIOC_G_ENC_INDEX _IOR ('V', 76, struct v4l2_enc_idx) #define VIDIOC_ENCODER_CMD _IOWR ('V', 77, struct v4l2_encoder_cmd) #define VIDIOC_TRY_ENCODER_CMD _IOWR ('V', 78, struct v4l2_encoder_cmd)/* Experimental, only implemented if CONFIG_VIDEO_ADV_DEBUG is defined */ #define VIDIOC_DBG_S_REGISTER _IOW ('V', 79, struct v4l2_register) #define VIDIOC_DBG_G_REGISTER _IOWR ('V', 80, struct v4l2_register)#define VIDIOC_G_CHIP_IDENT _IOWR ('V', 81, struct v4l2_chip_ident) #endif#ifdef __OLD_VIDIOC_ /* for compatibility, will go away some day */ #define VIDIOC_OVERLAY_OLD _IOWR ('V', 14, int) #define VIDIOC_S_PARM_OLD _IOW ('V', 22, struct v4l2_streamparm) #define VIDIOC_S_CTRL_OLD _IOW ('V', 28, struct v4l2_control) #define VIDIOC_G_AUDIO_OLD _IOWR ('V', 33, struct v4l2_audio) #define VIDIOC_G_AUDOUT_OLD _IOWR ('V', 49, struct v4l2_audioout) #define VIDIOC_CROPCAP_OLD _IOR ('V', 58, struct v4l2_cropcap) #endif#define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */#endif /* __LINUX_VIDEODEV2_H *//** Local variables:* c-basic-offset: 8* End:*/
Appendix B. Video Capture Example
/** V4L2 video capture example** This program can be used and distributed without restrictions.*/#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h>#include <getopt.h> /* getopt_long() */#include <fcntl.h> /* low-level i/o */ #include <unistd.h> #include <errno.h> #include <malloc.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/time.h> #include <sys/mman.h> #include <sys/ioctl.h>#include <asm/types.h> /* for videodev2.h */#include <linux/videodev2.h>#define CLEAR(x) memset (&(x), 0, sizeof (x))typedef enum {IO_METHOD_READ,IO_METHOD_MMAP,IO_METHOD_USERPTR, } io_method;struct buffer {void * start;size_t length; };static char * dev_name = NULL; static io_method io = IO_METHOD_MMAP; static int fd = -1; struct buffer * buffers = NULL; static unsigned int n_buffers = 0;static void errno_exit (const char * s) {fprintf (stderr, "%s error %d, %s\n",s, errno, strerror (errno));exit (EXIT_FAILURE); }static int xioctl (int fd,int request,void * arg) {int r;do r = ioctl (fd, request, arg);while (-1 == r && EINTR == errno);return r; }static void process_image (const void * p) {fputc ('.', stdout);fflush (stdout); }static int read_frame (void) {struct v4l2_buffer buf;unsigned int i;switch (io) {case IO_METHOD_READ:if (-1 == read (fd, buffers[0].start, buffers[0].length)) {switch (errno) {case EAGAIN:return 0;case EIO:/* Could ignore EIO, see spec. *//* fall through */default:errno_exit ("read");}}process_image (buffers[0].start);break;case IO_METHOD_MMAP:CLEAR (buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_MMAP;if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) {switch (errno) {case EAGAIN:return 0;case EIO:/* Could ignore EIO, see spec. *//* fall through */default:errno_exit ("VIDIOC_DQBUF");}}assert (buf.index < n_buffers);process_image (buffers[buf.index].start);if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))errno_exit ("VIDIOC_QBUF");break;case IO_METHOD_USERPTR:CLEAR (buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_USERPTR;if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) {switch (errno) {case EAGAIN:return 0;case EIO:/* Could ignore EIO, see spec. *//* fall through */default:errno_exit ("VIDIOC_DQBUF");}}for (i = 0; i < n_buffers; ++i)if (buf.m.userptr == (unsigned long) buffers[i].start&& buf.length == buffers[i].length)break;assert (i < n_buffers);process_image ((void *) buf.m.userptr);if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))errno_exit ("VIDIOC_QBUF");break;}return 1; }static void mainloop (void) {unsigned int count;count = 100;while (count-- > 0) {for (;;) {fd_set fds;struct timeval tv;int r;FD_ZERO (&fds);FD_SET (fd, &fds);/* Timeout. */tv.tv_sec = 2;tv.tv_usec = 0;r = select (fd + 1, &fds, NULL, NULL, &tv);if (-1 == r) {if (EINTR == errno)continue;errno_exit ("select");}if (0 == r) {fprintf (stderr, "select timeout\n");exit (EXIT_FAILURE);}if (read_frame ())break;/* EAGAIN - continue select loop. */}} }static void stop_capturing (void) {enum v4l2_buf_type type;switch (io) {case IO_METHOD_READ:/* Nothing to do. */break;case IO_METHOD_MMAP:case IO_METHOD_USERPTR:type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == xioctl (fd, VIDIOC_STREAMOFF, &type))errno_exit ("VIDIOC_STREAMOFF");break;} }static void start_capturing (void) {unsigned int i;enum v4l2_buf_type type;switch (io) {case IO_METHOD_READ:/* Nothing to do. */break;case IO_METHOD_MMAP:for (i = 0; i < n_buffers; ++i) {struct v4l2_buffer buf;CLEAR (buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_MMAP;buf.index = i;if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))errno_exit ("VIDIOC_QBUF");}type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == xioctl (fd, VIDIOC_STREAMON, &type))errno_exit ("VIDIOC_STREAMON");break;case IO_METHOD_USERPTR:for (i = 0; i < n_buffers; ++i) {struct v4l2_buffer buf;CLEAR (buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_USERPTR;buf.index = i;buf.m.userptr = (unsigned long) buffers[i].start;buf.length = buffers[i].length;if (-1 == xioctl (fd, VIDIOC_QBUF, &buf))errno_exit ("VIDIOC_QBUF");}type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (-1 == xioctl (fd, VIDIOC_STREAMON, &type))errno_exit ("VIDIOC_STREAMON");break;} }static void uninit_device (void) {unsigned int i;switch (io) {case IO_METHOD_READ:free (buffers[0].start);break;case IO_METHOD_MMAP:for (i = 0; i < n_buffers; ++i)if (-1 == munmap (buffers[i].start, buffers[i].length))errno_exit ("munmap");break;case IO_METHOD_USERPTR:for (i = 0; i < n_buffers; ++i)free (buffers[i].start);break;}free (buffers); }static void init_read (unsigned int buffer_size) {buffers = calloc (1, sizeof (*buffers));if (!buffers) {fprintf (stderr, "Out of memory\n");exit (EXIT_FAILURE);}buffers[0].length = buffer_size;buffers[0].start = malloc (buffer_size);if (!buffers[0].start) {fprintf (stderr, "Out of memory\n");exit (EXIT_FAILURE);} }static void init_mmap (void) {struct v4l2_requestbuffers req;CLEAR (req);req.count = 4;req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;req.memory = V4L2_MEMORY_MMAP;if (-1 == xioctl (fd, VIDIOC_REQBUFS, &req)) {if (EINVAL == errno) {fprintf (stderr, "%s does not support ""memory mapping\n", dev_name);exit (EXIT_FAILURE);} else {errno_exit ("VIDIOC_REQBUFS");}}if (req.count < 2) {fprintf (stderr, "Insufficient buffer memory on %s\n",dev_name);exit (EXIT_FAILURE);}buffers = calloc (req.count, sizeof (*buffers));if (!buffers) {fprintf (stderr, "Out of memory\n");exit (EXIT_FAILURE);}for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {struct v4l2_buffer buf;CLEAR (buf);buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;buf.memory = V4L2_MEMORY_MMAP;buf.index = n_buffers;if (-1 == xioctl (fd, VIDIOC_QUERYBUF, &buf))errno_exit ("VIDIOC_QUERYBUF");buffers[n_buffers].length = buf.length;buffers[n_buffers].start =mmap (NULL /* start anywhere */,buf.length,PROT_READ | PROT_WRITE /* required */,MAP_SHARED /* recommended */,fd, buf.m.offset);if (MAP_FAILED == buffers[n_buffers].start)errno_exit ("mmap");} }static void init_userp (unsigned int buffer_size) {struct v4l2_requestbuffers req;unsigned int page_size;page_size = getpagesize ();buffer_size = (buffer_size + page_size - 1) & ~(page_size - 1);CLEAR (req);req.count = 4;req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;req.memory = V4L2_MEMORY_USERPTR;if (-1 == xioctl (fd, VIDIOC_REQBUFS, &req)) {if (EINVAL == errno) {fprintf (stderr, "%s does not support ""user pointer i/o\n", dev_name);exit (EXIT_FAILURE);} else {errno_exit ("VIDIOC_REQBUFS");}}buffers = calloc (4, sizeof (*buffers));if (!buffers) {fprintf (stderr, "Out of memory\n");exit (EXIT_FAILURE);}for (n_buffers = 0; n_buffers < 4; ++n_buffers) {buffers[n_buffers].length = buffer_size;buffers[n_buffers].start = memalign (/* boundary */ page_size,buffer_size);if (!buffers[n_buffers].start) {fprintf (stderr, "Out of memory\n");exit (EXIT_FAILURE);}} }static void init_device (void) {struct v4l2_capability cap;struct v4l2_cropcap cropcap;struct v4l2_crop crop;struct v4l2_format fmt;unsigned int min;if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap)) {if (EINVAL == errno) {fprintf (stderr, "%s is no V4L2 device\n",dev_name);exit (EXIT_FAILURE);} else {errno_exit ("VIDIOC_QUERYCAP");}}if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {fprintf (stderr, "%s is no video capture device\n",dev_name);exit (EXIT_FAILURE);}switch (io) {case IO_METHOD_READ:if (!(cap.capabilities & V4L2_CAP_READWRITE)) {fprintf (stderr, "%s does not support read i/o\n",dev_name);exit (EXIT_FAILURE);}break;case IO_METHOD_MMAP:case IO_METHOD_USERPTR:if (!(cap.capabilities & V4L2_CAP_STREAMING)) {fprintf (stderr, "%s does not support streaming i/o\n",dev_name);exit (EXIT_FAILURE);}break;}/* Select video input, video standard and tune here. */CLEAR (cropcap);cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;if (0 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) {crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;crop.c = cropcap.defrect; /* reset to default */if (-1 == xioctl (fd, VIDIOC_S_CROP, &crop)) {switch (errno) {case EINVAL:/* Cropping not supported. */break;default:/* Errors ignored. */break;}}} else { /* Errors ignored. */}CLEAR (fmt);fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;fmt.fmt.pix.width = 640; fmt.fmt.pix.height = 480;fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt))errno_exit ("VIDIOC_S_FMT");/* Note VIDIOC_S_FMT may change width and height. *//* Buggy driver paranoia. */min = fmt.fmt.pix.width * 2;if (fmt.fmt.pix.bytesperline < min)fmt.fmt.pix.bytesperline = min;min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;if (fmt.fmt.pix.sizeimage < min)fmt.fmt.pix.sizeimage = min;switch (io) {case IO_METHOD_READ:init_read (fmt.fmt.pix.sizeimage);break;case IO_METHOD_MMAP:init_mmap ();break;case IO_METHOD_USERPTR:init_userp (fmt.fmt.pix.sizeimage);break;} }static void close_device (void) {if (-1 == close (fd))errno_exit ("close");fd = -1; }static void open_device (void) {struct stat st; if (-1 == stat (dev_name, &st)) {fprintf (stderr, "Cannot identify '%s': %d, %s\n",dev_name, errno, strerror (errno));exit (EXIT_FAILURE);}if (!S_ISCHR (st.st_mode)) {fprintf (stderr, "%s is no device\n", dev_name);exit (EXIT_FAILURE);}fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);if (-1 == fd) {fprintf (stderr, "Cannot open '%s': %d, %s\n",dev_name, errno, strerror (errno));exit (EXIT_FAILURE);} }static void usage (FILE * fp,int argc,char ** argv) {fprintf (fp,"Usage: %s [options]\n\n""Options:\n""-d | --device name Video device name [/dev/video]\n""-h | --help Print this message\n""-m | --mmap Use memory mapped buffers\n""-r | --read Use read() calls\n""-u | --userp Use application allocated buffers\n""",argv[0]); }static const char short_options [] = "d:hmru";static const struct option long_options [] = {{ "device", required_argument, NULL, 'd' },{ "help", no_argument, NULL, 'h' },{ "mmap", no_argument, NULL, 'm' },{ "read", no_argument, NULL, 'r' },{ "userp", no_argument, NULL, 'u' },{ 0, 0, 0, 0 } };int main (int argc,char ** argv) {dev_name = "/dev/video";for (;;) {int index;int c;c = getopt_long (argc, argv,short_options, long_options,&index);if (-1 == c)break;switch (c) {case 0: /* getopt_long() flag */break;case 'd':dev_name = optarg;break;case 'h':usage (stdout, argc, argv);exit (EXIT_SUCCESS);case 'm':io = IO_METHOD_MMAP;break;case 'r':io = IO_METHOD_READ;break;case 'u':io = IO_METHOD_USERPTR;break;default:usage (stderr, argc, argv);exit (EXIT_FAILURE);}}open_device ();init_device ();start_capturing ();mainloop ();stop_capturing ();uninit_device ();close_device ();exit (EXIT_SUCCESS);return 0; }
Appendix C. GNU Free Documentation License
C.3. 2. VERBATIM COPYING
You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions insection 3.
You may also lend copies, under the same conditions stated above, and you may publicly display copies.
C.4. 3. COPYING IN QUANTITY
If you publish printed copies of the Document numbering more than 100, and the Document's license notice requiresCover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.
If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a publicly-accessible computer-network location containing a complete Transparent copy of the Document, free of added material, which the general network-using public has access to download anonymously at no charge using public-standard network protocols. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.
It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.
C.5. 4. MODIFICATIONS
A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.
B. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in theModified Version, together with at least five of the principal authors of theDocument (all of its principal authors, if it has less than five).
C. State on the Title Page the name of the publisher of the Modified Version, as the publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.
F. Include, immediately after the copyright notices, a license notice giving the public permission to use theModified Version under the terms of this License, in the form shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.
H. Include an unaltered copy of this License.
I. Preserve the section entitled "History", and its title, and add to it an item stating at least the title, year, new authors, and publisher of theModified Versionas given on the Title Page. If there is no section entitled "History" in theDocument, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.
J. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the"History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.
K. In any section entitled "Acknowledgements" or"Dedications", preserve the section's title, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.
L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.
M. Delete any section entitled "Endorsements". Such a section may not be included in theModified Version.
N. Do not retitle any existing section as "Endorsements" or to conflict in title with any Invariant Section.
If the Modified Version includes new front-matter sections or appendices that qualify asSecondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list ofInvariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles.
You may add a section entitled "Endorsements", provided it contains nothing but endorsements of yourModified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.
You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list ofCover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If theDocument already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of anyModified Version.
C.6. 5. COMBINING DOCUMENTS
You may combine the Document with other documents released under this License, under the terms defined insection 4 above for modified versions, provided that you include in the combination all of theInvariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice.
The combined work need only contain one copy of this License, and multiple identicalInvariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections entitled "History" in the various original documents, forming one section entitled "History"; likewise combine any sections entitled "Acknowledgements", and any sections entitled"Dedications". You must delete all sections entitled"Endorsements."
C.9. 8. TRANSLATION
Translation is considered a kind of modification, so you may distribute translations of theDocument under the terms ofsection 4. ReplacingInvariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License provided that you also include the original English version of this License. In case of a disagreement between the translation and the original English version of this License, the original English version will prevail.
C.12. Addendum
Copyright © YEAR YOUR NAME.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with theInvariant Sections being LIST THEIR TITLES, with theFront-Cover Texts being LIST, and with theBack-Cover Texts being LIST. A copy of the license is included in the section entitled"GNU Free Documentation License".
If you have no Invariant Sections, write "with no Invariant Sections" instead of saying which ones are invariant. If you have noFront-Cover Texts, write"no Front-Cover Texts" instead of "Front-Cover Texts being LIST"; likewise forBack-Cover Texts.
If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as theGNU General Public License, to permit their use in free software.
References
[EIA 608-B] Electronic Industries Alliance (http://www.eia.org),EIA 608-B "Recommended Practice for Line 21 DataService".
[EN 300 294] European Telecommunication Standards Institute(http://www.etsi.org),EN 300 294 "625-line television Wide Screen Signalling(WSS)".
[ETS 300 231] European Telecommunication Standards Institute(http://www.etsi.org),ETS 300 231 "Specification of the domestic videoProgramme Delivery Control system (PDC)".
[ETS 300 706] European Telecommunication Standards Institute(http://www.etsi.org),ETS 300 706 "Enhanced Teletext specification".
[ISO 13818-1] International Telecommunication Union (http://www.itu.ch), InternationalOrganisation for Standardisation (http://www.iso.ch),ITU-T Rec. H.222.0 | ISO/IEC 13818-1 "Informationtechnology — Generic coding of moving pictures and associatedaudio information: Systems".
[ISO 13818-2] International Telecommunication Union (http://www.itu.ch), InternationalOrganisation for Standardisation (http://www.iso.ch),ITU-T Rec. H.262 | ISO/IEC 13818-2 "Informationtechnology — Generic coding of moving pictures and associatedaudio information: Video".
[ITU BT.470] International Telecommunication Union (http://www.itu.ch),ITU-R Recommendation BT.470-6 "Conventional TelevisionSystems".
[ITU BT.601] International Telecommunication Union (http://www.itu.ch),ITU-R Recommendation BT.601-5 "Studio Encoding Parametersof Digital Television for Standard 4:3 and Wide-Screen 16:9 AspectRatios".
[ITU BT.653] International Telecommunication Union (http://www.itu.ch),ITU-R Recommendation BT.653-3 "Teletext systems".
[ITU BT.709] International Telecommunication Union (http://www.itu.ch),ITU-R Recommendation BT.709-5 "Parameter values for theHDTV standards for production and international programmeexchange".
[ITU BT.1119] International Telecommunication Union (http://www.itu.ch),ITU-R Recommendation BT.1119 "625-linetelevision Wide Screen Signalling (WSS)".
[JFIF] Independent JPEG Group (http://www.ijg.org),JPEG File Interchange Format: Version 1.02.
[SMPTE 12M] Society of Motion Picture and Television Engineers(http://www.smpte.org),SMPTE 12M-1999 "Television, Audio and Film - Time andControl Code".
[SMPTE 170M] Society of Motion Picture and Television Engineers(http://www.smpte.org),SMPTE 170M-1999 "Television - Composite Analog VideoSignal - NTSC for Studio Applications".
[SMPTE 240M] Society of Motion Picture and Television Engineers(http://www.smpte.org),SMPTE 240M-1999 "Television - Signal Parameters -1125-Line High-Definition Production".
[V4L] Alan Cox, Video4Linux API Specification.
This file is part of the Linux kernel sources underDocumentation/video4linux.
[V4LPROG] Alan Cox, Video4Linux Programming (a.k.a. The Video4LinuxBook), 2000.
About V4L driver programming. Thisbook is part of the Linux kernel DocBook documentation, for example athttp://kernelnewbies.org/documents/. SGML sources are includedin the kernel sources.
Notes
如下初始化v4l2_subdev结构:v4l2_i2c_subdev_init(&state->sd, client, subdev_ops);
但是使用这个宏将更好和更容易:err = v4l2_subdev_call(sd, core, g_chip_ident, &chip);宏将到右边的空指针检查,并如果subdev是NULL返回-ENODEV,
-ENOIOCTLCMD if either subdev->core or subdev->core->g_chip_ident is
NULL, 或实际的结果 subdev->ops->core->g_chip_ident ops.它也可以调用全部或部分子设备:v4l2_device_call_all(v4l2_dev, 0, core, g_chip_ident, &chip);不支持这个OPS的任何子设备跳过错误的效果将被忽略。如果你想检查是否有错误,使用这个:err = v4l2_device_call_until_err(v4l2_dev, 0, core, g_chip_ident, &chip);Any error except -ENOIOCTLCMD will exit the loop with that error. If no
errors (except -ENOIOCTLCMD) occurred, then 0 is returned.这两个调用的第二个参数是一组ID。如果为0,然后所有subdevs被调用。如果不为零,
是共同所有子设备的核心操作函数,其他类别的执行取决于子设备。例如视频设备是不大可能支持音频操作,反之亦然。此设置限制的函数指针,同时还使其易于添加新操作函数和类别。子设备驱动初始化的v4l2_subdev结构使用:v4l2_subdev_init(sd, &ops);之后,您需要初始化一个独特的名字subdev->name和设置模块所有者。这样做是为了如果你使用的I2C辅助功能。如果框架媒介整合是必要的,你必须初始化的media_entity结构通过调用media_entity_init()嵌入在v4l2_subdev结构(实体领域):struct media_pad *pads = &my_sd->pads;int err;err = media_entity_init(&sd->entity, npads, pads, 0);pads数组必须此前已初始化。有没有需要手动设置结构media_entity类型和name字段,但如果需要修改字段必须初始化。
[1] |
Access permissions are associated with characterdevice special files, hence we must ensure device numbers cannotchange with the module load order. To this end minor numbers are nolonger automatically assigned by the "videodev" module as in V4L butrequested by the driver. The defaults will suffice for most peopleunless two drivers compete for the same minor numbers. |
[2] |
In earlier versions of the V4L2 API the module optionswhere named after the device special file with a "unit_" prefix, expressingthe minor number itself, not an offset. Rationale for this change is unknown.Lastly the naming and semantics are just a convention among driver writers,the point to note is that minor numbers are not supposed to be hardcodedinto drivers. |
[3] |
Given a device file name one cannot reliable findrelated devices. For once names are arbitrary and in a system withmultiple devices, where only some support VBI capturing, a/dev/video2 is not necessarily related to/dev/vbi2. The V4L |
[4] |
Drivers could recognize the |
[5] |
Actually struct v4l2_audio ought to have a |
[6] |
Some users are already confused by technical terms PAL,NTSC and SECAM. There is no point asking them to distinguish betweenB, G, D, or K when the software or hardware can do thatautomatically. |
[7] |
An alternative to the current scheme is to use pointersto indices as arguments of Indices are consistent with the rest of the APIand identify the standard unambiguously. In the present scheme ofthings an enumerated standard is looked up byv4l2_std_id. Now thestandards supported by the inputs of a device can overlap. Justassume the tuner and composite input in the example above bothexist on a device. An enumeration of "PAL-B/G", "PAL-H/I" suggestsa choice which does not exist. We cannot merge or omit sets, becauseapplications would be unable to find the standards reported by So insummary, the lookup itself is unavoidable. The difference is onlywhether the lookup is necessary to find an enumerated standard or toswitch to a standard byv4l2_std_id. |
[8] |
See Section 3.5 for a rationale. Probablyeven USB cameras follow some well known video standard. It might havebeen better to explicitly indicate elsewhere if a device cannot liveup to normal expectations, instead of this exception. |
[9] |
It will be more convenient for applications if driversmake use of the |
[10] |
Applications could call an ioctl to request events.After another process called |
[11] |
Enumerating formats an application has no a-prioriknowledge of (otherwise it could explicitely ask for them and need notenumerate) seems useless, but there are applications serving as proxybetween drivers and the actual video applications for which this isuseful. |
[12] |
It would be desirable if applications could depend ondrivers supporting all I/O interfaces, but as much as the complexmemory mapping I/O can be inadequate for some devices we have noreason to require this interface, which is most useful for simpleapplications capturing still images. |
[13] |
At the driver level |
[14] |
One could use one file descriptor and set the buffertype field accordingly when calling |
[15] |
Random enqueue order permits applications processingimages out of order (such as video codecs) to return buffers earlier,reducing the probability of data loss. Random fill order allowsdrivers to reuse buffers on a LIFO-basis, taking advantage of cachesholding scatter-gather lists and the like. |
[16] |
At the driver level |
[17] |
We expect that frequently used buffers are typically notswapped out. Anyway, the process of swapping, locking or generatingscatter-gather lists may be time consuming. The delay can be masked bythe depth of the incoming buffer queue, and perhaps by maintainingcaches assuming a buffer will be soon enqueued again. On the otherhand, to optimize memory usage drivers can limit the number of bufferslocked in advance and recycle the most recently used buffers first. Ofcourse, the pages of empty buffers in the incoming queue need not besaved to disk. Output buffers must be saved on the incoming andoutgoing queue because an application may share them with otherprocesses. |
[18] |
At the driver level |
[19] |
Since no other Linux multimediaAPI supports unadjusted time it would be foolish to introduce here. Wemust use a universally supported clock to synchronize different media,hence time of day. |
[20] |
A common application of two file descriptors is theXFree86 Xv/V4L interface driver anda V4L2 application. While the X server controls video overlay, theapplication can take advantage of memory mapping and DMA. In the opinion of the designers of this API, no driverwriter taking the efforts to support simultaneous capturing andoverlay will restrict this ability by requiring a single filedescriptor, as in V4L and earlier versions of V4L2. Making thisoptional means applications depending on two file descriptors needbackup routines to be compatible with all drivers, which isconsiderable more work than using two fds in applications which donot. Also two fd's fit the general concept of one file descriptor foreach logical stream. Hence as a complexity trade-off driversmust support two file descriptors andmay support single fd operation. |
[21] |
The X Window system defines "regions" which arevectors of struct BoxRec { short x1, y1, x2, y2; } with width = x2 -x1 and height = y2 - y1, so one cannot pass X11 clip listsdirectly. |
[22] |
ASK: Amplitude-Shift Keying. A high signallevel represents a '1' bit, a low level a '0' bit. |
[23] |
The supported standards may overlap and we need anunambiguous set to find the current standard returned by |
[24] |
|
[25] |
For example video output requires at least two buffers,one displayed and one filled by the application. |
[26] |
The Linux kernel implements |
[27]
This is not implemented in XFree86.
linux内核文档翻译之——V4L2-framework.txt V4L2 API Specification相关推荐
- Linux内核官方文档atomic_ops.txt【摘自Linux 内核文档】
摘自Linux内核文档 Documentation/atomic_ops.txt,不是本人原创 Semantics and Behavior of Atomic and Bitmask Operati ...
- Linux内核文档翻译
本博客由浙江工商大学信息学院的计算机专业学生维护,提供Linux内核有关文档的中文翻译,为Linux内核学习提供参考. 内核版本:V3.11 版本来源:http://lxr.linux.no/linu ...
- Linux内核中的同步原语:自旋锁,信号量,互斥锁,读写信号量,顺序锁
Linux内核中的同步原语 自旋锁,信号量,互斥锁,读写信号量,顺序锁 rtoax 2021年3月 在英文原文基础上,针对中文译文增加5.10.13内核源码相关内容. 1. Linux 内核中的同步原 ...
- [译] LINUX内核内存屏障
================= LINUX内核内存屏障 ================= By: David Howells <dhowells@redhat.com> Paul E ...
- LINUX内核内存屏障
================= LINUX内核内存屏障 ================= By: David Howells <dhowells@redhat.com> Paul E ...
- linux 内核 LINUX_VERSION_CODE 和 KERNEL_VERSION 宏定义 版本信息
由于Linux版本的在不断更新,当设备驱动去兼容不同版本的内核时,需要知道当前使用的内核源码版本,以此来调用对应版本的内核API,这两个宏定义在文件 /usr/include/linux/versio ...
- Linux内核自旋锁
Linux内核自旋锁 自旋锁 自旋锁(spinlock)是用在多个CPU系统中的锁机制,当一个CPU正访问自旋锁保护的临界区时,临界区将被锁上,其他需要访问此临界区的CPU只能忙等待,直到前面的CPU ...
- Linux内核概念:per-CPU,cpumask,inicall机制,通知链
Linux内核概念 per-CPU,cpumask,inicall机制,通知链 rtoax 2021年3月 在英文原文基础上,针对中文译文增加5.10.13内核源码相关内容. 1. Per-cpu 变 ...
- linux内核 自旋锁示例,自旋锁(示例代码)
一.什么是自旋锁 一直以为自旋锁也是用于多线程互斥的一种锁,原来不是! 自旋锁是专为防止多处理器并发(实现保护共享资源)而引入的一种锁机制.自旋锁与互斥锁比较类似,它们都是为了解决对某项资源的互斥使用 ...
- [网易云课堂]Linux内核分析(九)—— 课程总结
付何山+原创作品转载请注明出处+<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000; 导读:本文分为两个部分 ...
最新文章
- tortoisesvn的安装
- 分计算iv值_S71200PLC模拟量编程方法与计算原理
- malloc分配内存的原理?
- C++和C#编写调用COM组件
- Bootstrap 表格 笔记
- 交换机的质量害死人呀!
- 【李宏毅2020 ML/DL】P82 Generative Adversarial Network | Improving Sequence Generation by GAN
- 机器视觉开源处理库汇总-介绍n款计算机视觉库/人脸识别开源库/软件 -几种图像处理类库的比较-视觉相关网站...
- TX2不支持TensorRT INT8,int8 官方参考
- 炫酷的2022网页特效网站源码
- java 200以内的素数_java200以内的素数每行每列7个代码怎么写?
- 注册查看隐私协议 --- 滚动条是否滚动到底
- ZOJ 3557 (插板法+Lucas定理)
- git切换master项目,新建分支new branch
- SECTION 24 面向对象编程(三)
- 安卓开发 之小白养成-Android适配
- FinClip | 2022 年 10月产品大事记
- chrom flash提示地区不兼容, 亲测可用
- 爱普生打印机在计算机上的地址,爱普生打印机怎么使用 爱普生打印机使用方法【详解】...
- 全麦吐司和普通吐司的区别_全麦面包和普通面包的区别有哪些?