Linux V4L2 子系统源码分析

V4L2 设备分析


目录

v4l2_device 结构体

struct v4l2_device 结构体是v4l2 设备驱动的主要结构体。v4l2_device结构体如下:

//linux/include/media/v4l2-device.h
struct v4l2_device {
    struct device *dev;                               //pointer to struct device.
#if defined(CONFIG_MEDIA_CONTROLLER)
    struct media_device *mdev;
#endif
    struct list_head subdevs;                        //used to keep track of the registered subdevs
    spinlock_t lock;                          
    char name[V4L2_DEVICE_NAME_SIZE];                //unique device name, by default the driver name + bus ID
    void (*notify)(struct v4l2_subdev *sd,
            unsigned int notification, void *arg); //notify callback called by some sub-devices
    struct v4l2_ctrl_handler *ctrl_handler;       //The control handler. May be %NULL.
    struct v4l2_prio_state prio;
    struct kref ref;                             //Keep track of the references to this struct.
    void (*release)(struct v4l2_device *v4l2_dev);//Release function that is called when the ref count goes to 0.
};

每一个v4l2 设备都需要对用有一个struct v4l2_device。 这里需要注意的是成员subdevs,它用于管理已经注册的各个subdevice。在驱动程序中还经常需要用的是,dev->driver_data 指向了这个结构体。方便通过device 结构体找到此结构体。

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_prio_state {
    atomic_t prios[4];
};
struct v4l2_ctrl_handler {
    struct mutex _lock;
    struct mutex *lock;
    struct list_head ctrls;
    struct list_head ctrl_refs;
    struct v4l2_ctrl_ref *cached;
    struct v4l2_ctrl_ref **buckets;
    v4l2_ctrl_notify_fnc notify;
    void *notify_priv;
    u16 nr_of_buckets;
    int error;
};

V4L2设备注册

v4l2_device_register 函数完成对

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值