赞
踩
v4l2驱动框架主要的对象有video_device、v4l2_device、v4l2_subdev、videobuf
video_device
v4l2_device
嵌入到video_device中,表示一个v4l2设备的实例
v4l2_subdev
依附在v4l2_device之下,并表示一个v4l2设备的子设备,一个v4l2_devide下可以有多个sub_device
videobuf
v4l2驱动的缓存管理
v4l2_device和v4l2_subdev的关系:
subdev的设计目的是为了多路复用,就是用一个v4l2_device可以挂接多个v4l2_subdev。所谓的多路复用就是使用一个摄像头控制器来控制多个摄像头。比如手机上有前置和后置摄像头。
在V4L2驱动中,使用v4l2_device来表示摄像头控制器(ISP)。使用v4l2_subdev来表示具体的某一个摄像头(Sensor)。
对于手机而言 ,一般都有两个摄像头,一个前置摄像头,一个后置摄像头,其接发下图所示
在V4L2驱动中,使用v4l2_device来表示摄像头控制器
使用v4l2_subdev来表示具体的某一个摄像头的I2C控制模块,进而通过其控制摄像头
v4l2_device里有一个v4l2_subdev链表,可以选择v4l2_device去控制哪一个v4l2_subdev
v4l2框架图如下:
V4l2驱动的代码在drivers\media\v4l2-core文件夹下
static inline int __must_check video_register_device(struct video_device *vdev,
enum vfl_devnode_type type,
int nr)
void video_unregister_device(struct video_device *vdev);
int __must_check v4l2_device_register(struct device *dev,
struct v4l2_device *v4l2_dev);
void v4l2_device_unregister(struct v4l2_device *v4l2_dev);
int __must_check v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
struct v4l2_subdev *sd);
void v4l2_device_unregister_subdev(struct v4l2_subdev *sd);
步骤:
#include <...>
static struct video_device* video_dev;
static struct v4l2_device v4l2_dev;
/* 实现各种系统调用 */
static const struct v4l2_file_operations video_dev_fops = {
.owner = THIS_MODULE,
.release = vdev_close,
.read = vdev_read,
.poll = vdev_poll,
.ioctl = video_ioctl2,
.mmap = vdev_mmap,
};
/* 实现各种系统调用 */
static const struct v4l2_ioctl_ops video_dev_ioctl_ops = {
.vidioc_querycap = vidioc_querycap,
.vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
.vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
.vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
.vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
.vidioc_reqbufs = vidioc_reqbufs,
.vidioc_querybuf = vidioc_querybuf,
.vidioc_qbuf = vidioc_qbuf,
.vidioc_dqbuf = vidioc_dqbuf,
.vidioc_enum_input = vidioc_enum_input,
.vidioc_g_input = vidioc_g_input,
.vidioc_s_input = vidioc_s_input,
.vidioc_streamon = vidioc_streamon,
.vidioc_streamoff = vidioc_streamoff,
};
static int __init video_init(void)
{
/* 分配并设置一个video_device */
video_dev = video_device_alloc();
video_dev->fops = &video_dev_fops;
video_dev->ioctl_ops = &video_dev_ioctl_ops;
video_dev->release = video_device_release;
video_dev->tvnorms = V4L2_STD_525_60;
video_dev->current_norm = V4L2_STD_NTSC_M;
<span class="token comment">/* 注册一个v4l2_device */</span>
<span class="token function">v4l2_device_register</span><span class="token punctuation">(</span>video_dev<span class="token operator">-></span>dev<span class="token punctuation">,</span> <span class="token operator">&</span>v4l2_dev<span class="token punctuation">)</span><span class="token punctuation">;</span>
video_dev<span class="token operator">-></span>v4l2_dev <span class="token operator">=</span> <span class="token operator">&</span>v4l2_dev<span class="token punctuation">;</span>
<span class="token comment">/* 注册一个video_device字符设备 */</span>
<span class="token function">video_register_device</span><span class="token punctuation">(</span>video_dev<span class="token punctuation">,</span> VFL_TYPE_GRABBER<span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
}
static void __exit video_exit(void)
{
video_unregister_device(video_dev);
v4l2_device_unregister(&v4l2_dev);
video_device_release(video_dev);
}
module_init(video_init);
module_exit(video_exit);
驱动位于drivers\media\platform\vivid文件夹下
【转载】Linux摄像头驱动1——vivid_linux 摄像头驱动_seiyaaa的博客-CSDN博客
摄像头驱动——V4L2框架分析 - 朱果果 - 博客园 (cnblogs.com)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。