2.5 V4L2 device

v4l2 用来抽象最顶层的 v4l2 设备,包含一系列子设备。

通过v4l2_device_register(dev, v4l2_dev)注册。

还需要设置好 v4l2->mdev 为 media_device 结构体。

在调用 v4l2_device_register 之前如果没有设置 v4l2_device->name,那么会自动分配。

还可以提供一个 notify 回调,给 subdev 向 v4l2_device 发送 event,events 定义在v4l2-subdev.h,官方文档里写只能使用 v4l2-subdev.h 中定义的 event,但看到有的 driver 自定义了一些 event。

通过v4l2_device_unregister()注销,如果是 hotpluggable 设备,在此之前还需要调用v4l2_device_disconnect()

v4l2-device.h:

Data Structure and APIs

struct v4l2_device {
	struct device *dev;
	struct media_device *mdev;
	struct list_head subdevs;
	spinlock_t lock;
	char name[36];
	void (*notify)(struct v4l2_subdev *sd,
			unsigned int notification, void *arg);
	struct v4l2_ctrl_handler *ctrl_handler;
	struct v4l2_prio_state prio;
	struct kref ref;
	void (*release)(struct v4l2_device *v4l2_dev);
};

dev: 底层 device 设备。
mdev: 指向 media device.
subdevs: 子设备列表。
name: v4l2 设备名称。
notify: 子设备调用的通知回调函数。
ctrl_handler: v4l2 控制句柄。
prio: 设备的优先级状态。
ref: 引用计数。
release: 释放回调函数。