目录
1.1. 枚举 vfl_devnode_type
1.2. 枚举 vfl_devnode_direction
1.3. 枚举 v4l2_video_device_flags
1.4. 结构体 v4l2_prio_state
1.5. v4l2_prio_init
1.6. v4l2_prio_change
1.7. v4l2_prio_open
1.8. v4l2_prio_close
1.9. v4l2_prio_max
1.10. v4l2_prio_check
1.11. 结构体 v4l2_file_operations
1.12. 结构体 video_device
1.13. media_entity_to_video_device
1.14. to_video_device
1.15. __video_register_device
1.16. video_register_device
1.17. video_register_device_no_warn
1.18. video_unregister_device
1.19. video_device_alloc
1.20. video_device_release
1.21. video_device_release_empty
1.22. v4l2_disable_ioctl
1.23. video_get_drvdata
1.24. video_set_drvdata
1.25. video_devdata
1.26. video_drvdata
1.27. video_device_node_name
1.28. video_is_registered
1.1. 枚举 vfl_devnode_type
枚举vfl_devnode_type
V4L2设备节点的类型
常量
-
VFL_TYPE_VIDEO
用于视频输入/输出设备
-
VFL_TYPE_VBI
用于垂直消隐数据(即隐藏式字幕、图文电视)
-
VFL_TYPE_RADIO
用于无线电调谐器
-
VFL_TYPE_SUBDEV
用于V4L2子设备
-
VFL_TYPE_SDR
用于软件定义无线电调谐器
-
VFL_TYPE_TOUCH
用于触摸传感器
-
VFL_TYPE_MAX
VFL类型的数量,必须始终位于枚举的最后
1.2. 枚举 vfl_devnode_direction
枚举vfl_devnode_direction
确定struct video_device是对应接收器、发射器还是内存到内存设备。
常量
-
VFL_DIR_RX
设备是接收器。
-
VFL_DIR_TX
设备是发射器。
-
VFL_DIR_M2M
该设备是一种内存到内存的设备。
注: 如果enum vfl_devnode_type为VFL_TYPE_SUBDEV,则忽略。
1.3. 枚举 v4l2_video_device_flags
枚举v4l2_video_device_flags
struct video_device 所使用的标志
常量
-
V4L2_FL_REGISTERED
表示已注册一个struct video_device。驱动程序如果想阻止所有未来的设备访问,可以清除此标志。该标志会被video_unregister_device清除。
-
V4L2_FL_USES_V4L2_FH
表示 file->private_data 指向 struct v4l2_fh。调用 v4l2_fh_init() 时,内核会设置此标志。所有新驱动程序都应使用它。
-
V4L2_FL_QUIRK_INVERTED_CROP
一些旧的M2M驱动程序错误地使用了g/s_crop/cropcap:裁剪和合成被交换了。如果设置了此标志,则v4l2-ioctl.c中的g/s_crop/cropcap函数会交换选择目标。这使得这些驱动程序能够正确实现选择API,而旧的裁剪API仍会按预期工作,以保持向后兼容性。切勿为新驱动程序设置此标志。
-
V4L2_FL_SUBDEV_RO_DEVNODE
表示视频设备节点是以只读模式注册的。该标志仅适用于为子设备注册的设备节点,当使用v4l2_device_register_ro_subdev_nodes()注册子设备的设备节点时,由内核进行设置,并被子设备ioctl处理程序用于限制对某些ioctl调用的访问。
1.4. 结构体 v4l2_prio_state
struct v4l2_prio_state 结构体
存储优先级状态
定义
struct v4l2_prio_state {
atomic_t prios[4];
};
成员
-
prios
用于存储数组优先级的元素数组
描述
注: prios数组的大小与枚举v4l2_priority定义的优先级类型数量相匹配。
1.5. v4l2_prio_init
void v4l2_prio_init(struct v4l2_prio_state *global)
初始化一个 struct v4l2_prio_state
参数
-
struct v4l2_prio_state *global
指向 struct v4l2_prio_state 的指针
1.6. v4l2_prio_change
int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local, enum v4l2_priority new)
更改v4l2文件句柄优先级
参数
-
struct v4l2_prio_state *global
指向设备节点的struct v4l2_prio_state的指针。
-
enum v4l2_priority *local
指向所需优先级的指针,由枚举v4l2_priority定义
-
enum v4l2_priority new
请求的优先级类型,由枚举v4l2_priority定义。
描述
注: 此函数仅应由V4L2核心使用。
1.7. v4l2_prio_open
void v4l2_prio_open(struct v4l2_prio_state *global,enum v4l2_priority *local)
实现文件处理器打开的优先级逻辑
参数
-
struct v4l2_prio_state *global
指向设备节点的struct v4l2_prio_state的指针。
-
enum v4l2_priority *local
指向所需优先级的指针,由枚举v4l2_priority定义
描述
注: 此函数仅应由V4L2核心使用。
1.8. v4l2_prio_close
void v4l2_prio_close(struct v4l2_prio_state *global,enum v4l2_priority local)
实现文件处理器关闭的优先级逻辑
参数
-
struct v4l2_prio_state *global
指向设备节点的struct v4l2_prio_state的指针。
-
enum v4l2_priority local
由枚举v4l2_priority定义的待释放优先级
描述
注: 此函数仅应由V4L2核心使用。
1.9. v4l2_prio_max
enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
返回存储在global数组中的最大优先级。
参数
-
struct v4l2_prio_state *global
指向设备节点的struct v4l2_prio_state的指针。
描述
注: 此函数仅应由V4L2核心使用。
1.10. v4l2_prio_check
int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local)
实现文件处理程序关闭的优先级逻辑
参数
-
struct v4l2_prio_state *global
指向设备节点的struct v4l2_prio_state的指针。
-
enum v4l2_priority local
所需优先级,由枚举v4l2_priority local定义
描述
注: 此函数仅应由V4L2核心使用。
1.11. 结构体 v4l2_file_operations
struct v4l2_file_operations
V4L2设备使用的文件系统操作
定义
struct v4l2_file_operations {
struct module *owner;
ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
__poll_t (*poll) (struct file *, struct poll_table_struct *);
long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
#ifdef CONFIG_COMPAT;
long (*compat_ioctl32) (struct file *, unsigned int, unsigned long);
#endif;
unsigned long (*get_unmapped_area) (struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct file *);
int (*release) (struct file *);
};
成员
-
owner
指向结构体模块的指针
-
read
实现read()系统调用所需的操作
-
write
实现write()系统调用所需的操作
-
poll
实现poll()系统调用所需的操作
-
unlocked_ioctl
实现ioctl()系统调用所需的操作
-
compat_ioctl32
在内核使用64位指令而用户空间使用32位的特殊情况下,实现ioctl()系统调用所需的操作。
-
get_unmapped_area
由mmap()系统调用调用,在%!CONFIG_MMU时使用
-
mmap
实现mmap()系统调用所需的操作
-
open
实现open()系统调用所需的操作
-
release
实现release()系统调用所需的操作
描述
注:这些操作用于在V4L2驱动程序中实现fs结构体file_operations。V4L2核心会用子系统所需的一些额外逻辑覆盖文件系统操作。
1.12. 结构体 video_device
struct video_device
用于创建和管理V4L2设备节点的结构。
定义
struct video_device {
#if defined(CONFIG_MEDIA_CONTROLLER);
struct media_entity entity;
struct media_intf_devnode *intf_devnode;
struct media_pipeline pipe;
#endif;
const struct v4l2_file_operations *fops;
u32 device_caps;
struct device dev;
struct cdev *cdev;
struct v4l2_device *v4l2_dev;
struct device *dev_parent;
struct v4l2_ctrl_handler *ctrl_handler;
struct vb2_queue *queue;
struct v4l2_prio_state *prio;
char name[32];
enum vfl_devnode_type vfl_type;
enum vfl_devnode_direction vfl_dir;
int minor;
u16 num;
unsigned long flags;
int index;
spinlock_t fh_lock;
struct list_head fh_list;
int dev_debug;
v4l2_std_id tvnorms;
void (*release)(struct video_device *vdev);
const struct v4l2_ioctl_ops *ioctl_ops;
unsigned long valid_ioctls[BITS_TO_LONGS(BASE_VIDIOC_PRIVATE)];
struct mutex *lock;
};
成员
-
entity
struct media_entity
-
intf_devnode
指向 struct media_intf_devnode 的指针
-
pipe
struct media_pipeline
-
fops
指向视频设备的struct v4l2_file_operations的指针
-
device_caps
v4l2_capabilities中使用的设备功能
-
dev
struct device(用于视频设备)
-
cdev
字符设备
-
v4l2_dev
指向 struct v4l2_device 父设备的指针
-
dev_parent
指向struct device的指针 parent
-
ctrl_handler
与此设备节点相关联的控制处理器。可能为NULL。
-
queue
与该设备节点相关联的struct vb2_queue。可能为NULL。
-
prio
指向struct v4l2_prio_state的指针,包含设备的优先级状态。如果为NULL,则将使用v4l2_dev->prio。
-
name
视频设备名称
-
vfl_type
V4L设备类型,由enum vfl_devnode_type定义
-
vfl_dir
V4L接收器、发射器或m2m
-
minor
设备节点“次设备号”。如果注册失败,它会被设为-1。
-
num
视频设备节点编号
-
flags
视频设备标志。使用位操作来设置/清除/测试标志。包含一组enum v4l2_video_device_flags。
-
index
用于区分同一物理设备上多个索引的属性
-
fh_lock
所有v4l2_fhs的锁
-
fh_list
struct v4l2_fh列表
-
dev_debug
设备内部调试标志,不供驱动程序使用
-
tvnorms
支持的电视制式
-
release
视频设备release()回调函数
-
ioctl_ops
指向带有ioctl回调的struct v4l2_ioctl_ops的指针
-
valid_ioctls
此设备的有效ioctl的位图
-
lock
指向struct mutex序列化锁的指针
描述
注: 只有在无法从v4l2_dev中推导出来时,才设置dev_parent。
1.13. media_entity_to_video_device
media_entity_to_video_device (__entity)
从嵌入的struct media_entity返回一个struct video_device。
参数
-
__entity
指向struct media_entity的指针
1.14. to_video_device
to_video_device (cd)
从嵌入的struct device返回一个struct video_device。
参数
-
cd
指向struct device的指针
1.15. __video_register_device
int __video_register_device(struct video_device *vdev, enum vfl_devnode_type type, int nr, int warn_if_nr_in_use, struct module *owner)
注册video4linux设备
参数
-
struct video_device *vdev
要注册的struct video_device
-
enum vfl_devnode_type type
要注册的设备类型,由enum vfl_devnode_type定义
-
int nr
期望的设备节点编号是:(0 == /dev/video0,1 == /dev/video1,……,-1 == 第一个空闲节点)
-
int warn_if_nr_in_use
如果所需的设备节点号已被使用且选择了另一个编号,则发出警告。
-
struct module *owner
拥有视频设备节点的模块
描述
注册代码根据请求的类型分配次编号和设备节点编号,并向内核注册新的设备节点。
此函数假设struct video_device在分配时已清零,且不包含任何陈旧数据。
如果找不到可用的次要编号或设备节点编号,或者设备节点注册失败,将返回错误。
成功时返回0。
注: 此函数仅用于V4L2核心内部。驱动程序应使用video_register_device()或video_register_device_no_warn()。
1.16. video_register_device
int video_register_device(struct video_device *vdev, enum vfl_devnode_type type, int nr)
注册video4linux设备
参数
-
struct video_device *vdev
要注册的struct video_device结构体
-
enum vfl_devnode_type type
要注册的设备类型,由enum vfl_devnode_type定义
-
int nr
所需的设备节点编号:(0 == /dev/video0,1 == /dev/video1,……,-1 == 第一个空闲)
描述
在内部,它会调用__video_register_device()。有关更多详细信息,请参阅其文档。
注
如果video_register_device失败,struct video_device结构体的release()回调函数不会被调用,因此调用者负责释放所有数据。通常这意味着在失败时应该调用video_device_release()。
1.17. video_register_device_no_warn
int video_register_device_no_warn(struct video_device *vdev, enum vfl_devnode_type type, int nr)
注册video4linux设备
参数
-
struct video_device *vdev
要注册的struct video_device结构体
-
enum vfl_devnode_type type
要注册的设备类型,由enum vfl_devnode_type定义
-
int nr
所需的设备节点号:(0 == /dev/video0,1 == /dev/video1,……,-1 == 第一个空闲节点)
描述
此函数与video_register_device()相同,不同之处在于,如果所需的设备节点号已在使用中,不会发出警告。
在内部,它会调用__video_register_device()。有关更多详细信息,请参阅其文档。
注如果video_register_device失败,struct video_device结构体的release()回调函数不会被调用,因此调用者负责释放所有数据。通常这意味着在失败时应该调用video_device_release()。
1.18. video_unregister_device
void video_unregister_device(struct video_device *vdev)
注销视频设备。
参数
-
struct video_device *vdev
struct video_device 用于注册
描述
如果vdev == NULL或者video_is_registered()返回false,则不执行任何操作。
1.19. video_device_alloc
struct video_device *video_device_alloc(void)
用于分配struct video_device的辅助函数
参数
-
void
无参数
描述
如果为-ENOMEM,则返回NULL;成功时返回struct video_device。
1.20. video_device_release
void video_device_release(struct video_device *vdev)
释放struct video_device的辅助函数
参数
-
struct video_device *vdev
指向 struct video_device 的指针
描述
也可用于video_device->release()。
1.21. video_device_release_empty
void video_device_release_empty(struct video_device *vdev)
用于实现video_device->release()回调的辅助函数。
参数
-
struct video_device *vdev
指向 struct video_device 的指针
描述
此释放函数不执行任何操作。
当video_device是静态全局结构体时,应使用此函数。
注: 拥有静态的video_device往好里说也是一种可疑的构造。
1.22. v4l2_disable_ioctl
void v4l2_disable_ioctl(struct video_device *vdev, unsigned int cmd)
标记给定命令未实现。不应使用核心锁定
参数
-
struct video_device *vdev
指向 struct video_device 的指针
-
unsigned int cmd
ioctl命令
描述
此函数允许驱动程序仅提供一个v4l2_ioctl_ops结构体,但会根据实际检测到的特定卡来禁用ioctl操作。
注: 这必须在 video_register_device 之前调用。另请参见 determine_valid_ioctls() 的注释。
1.23. video_get_drvdata
void *video_get_drvdata(struct video_device *vdev)
从struct video_device获取私有数据。
参数
-
struct video_device *vdev
指向struct video_device的指针
描述
返回指向私有数据的指针
1.24. video_set_drvdata
void video_set_drvdata(struct video_device *vdev, void *data)
设置来自struct video_device的私有数据。
参数
-
struct video_device *vdev
指向struct video_device的指针
-
void *data
私有数据指针
1.25. video_devdata
struct video_device *video_devdata(struct file *file)
从struct file获取struct video_device。
参数
-
struct file *file
指向struct file的指针
1.26. video_drvdata
void *video_drvdata(struct file *file)
使用struct file从struct video_device获取私有数据。
参数
-
struct file *file
指向struct file的指针
描述
这个函数结合了video_get_drvdata()和video_devdata(),因为这两个函数的组合使用非常频繁。
1.27. video_device_node_name
const char *video_device_node_name(struct video_device *vdev)
返回视频设备名称
参数
-
struct video_device *vdev
指向 struct video_device 的指针
描述
返回设备名称字符串
1.28. video_is_registered
int video_is_registered(struct video_device *vdev)
如果 struct video_device 已注册,则返回 true。
参数
-
struct video_device *vdev
指向 struct video_device 的指针
描述
网硕互联帮助中心






评论前必须登录!
注册