以vivi.c为例,说明v4l2的框架。
摄像头驱动程序框架:
1. 分配video_device:video_device_alloc
vfd = video_device_alloc();
2. 设置: *vfd = vivi_template;
static struct video_device vivi_template = {
.name = "vivi",
.fops = &vivi_fops,
.ioctl_ops = &vivi_ioctl_ops,
.release = video_device_release,
.tvnorms = V4L2_STD_525_60,
.current_norm = V4L2_STD_NTSC_M,
};
.fops
.ioctl_ops (里面需要设置11项)
如果要用内核提供的缓冲区操作函数,还需要构造一个videobuf_queue_ops
3. 注册: video_register_device
ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);