v4l2架构专题模块handler分析 -- handler ctrl的注册2

Linux v4l2架构学习总链接

上一篇文章中忽略了ctrl class,这里补上

static int handler_new_ref(struct v4l2_ctrl_handler *hdl,
			   struct v4l2_ctrl *ctrl)
{
	struct v4l2_ctrl_ref *ref;
	struct v4l2_ctrl_ref *new_ref;
	u32 id = ctrl->id;
	u32 class_ctrl = V4L2_CTRL_ID2WHICH(id) | 1;
	...

	/*
	 * Automatically add the control class if it is not yet present and
	 * the new control is not a compound control.
	 */
	if (ctrl->type < V4L2_CTRL_COMPOUND_TYPES &&
	    id != class_ctrl && find_ref_lock(hdl, class_ctrl) == NULL)
		if (!v4l2_ctrl_new_std(hdl, NULL, class_ctrl, 0, 0, 0, 0))
			return hdl->error;
            ...
        }
}

对于id为V4L2_CID_LINK_FREQ

#define V4L2_CID_IMAGE_PROC_CLASS		(V4L2_CTRL_CLASS_IMAGE_PROC | 1)
#define V4L2_CTRL_CLASS_IMAGE_PROC	0x009f0000	/* Image processing controls */
#define V4L2_CID_IMAGE_PROC_CLASS_BASE		(V4L2_CTRL_CLASS_IMAGE_PROC | 0x900)
#define V4L2_CID_LINK_FREQ			(V4L2_CID_IMAGE_PROC_CLASS_BASE + 1)

其ctrl class值为 V4L2_CID_IMAGE_PROC_CLASS

这里看一下代码中的 find_ref_lock函数

static struct v4l2_ctrl_ref *find_ref_lock(
		struct v4l2_ctrl_handler *hdl, u32 id)
{
	struct v4l2_ctrl_ref *ref = NULL;

	if (hdl) {
		mutex_lock(hdl->lock);
		ref = find_ref(hdl, id);
		mutex_unlock(hdl->lock);
	}
	return ref;
}

static struct v4l2_ctrl_ref *find_ref(struct v4l2_ctrl_handler *hdl, u32 id)
{
	struct v4l2_ctrl_ref *ref;
	int bucket;

	id &= V4L2_CTRL_ID_MASK;

	/* Old-style private controls need special handling */
	if (id >= V4L2_CID_PRIVATE_BASE)
		return find_private_ref(hdl, id);

        /*
         * 根据id判断所在的bucket编号
         */
	bucket = id % hdl->nr_of_buckets;

	/* Simple optimization: cache the last control found */


        /*
         * hdl->cached保存上一次查找到的ref
         * 如果本次查找和上次保存到一样,这里可以直接返回
         * 节省时间
         */

	if (hdl->cached && hdl->cached->ctrl->id == id)
		return hdl->cached;

	/* Not in cache, search the hash */
        
        /*
         * cache中没有找到,现在找hash
         * 根据bucket编号,找到buckets
         */

	ref = hdl->buckets ? hdl->buckets[bucket] : NULL;

        /*
         * 通过ref->next依次遍历当前buckets中的ref
         */
	while (ref && ref->ctrl->id != id)
		ref = ref->next;

        /*
         * 成功找到ref
         * 将这个ref保存到cached
         */
	if (ref)
		hdl->cached = ref; /* cache it! */
	return ref;
}

对于我们的分析来说,这里是不会找到ref,因为现在还没有ctrl class

对于ctl class来说,依然是通过v4l2_ctl_new_std这个函数来注册,这里就不分析了

使用v4l2-ctrl可以看到具体的ctrl

[root@RV1126_RV1109:/]# v4l2-ctl -d /dev/v4l-subdev3 -l

User Controls

                       exposure 0x00980911 (int)    : min=2 max=647 step=1 default=284 value=284
                horizontal_flip 0x00980914 (bool)   : default=0 value=0
                  vertical_flip 0x00980915 (bool)   : default=0 value=0

Image Source Controls

              vertical_blanking 0x009e0901 (int)    : min=459 max=65343 step=1 default=459 value=459
            horizontal_blanking 0x009e0902 (int)    : min=30 max=30 step=1 default=30 value=30 flags=read-only
                  analogue_gain 0x009e0903 (int)    : min=16 max=3964 step=1 default=16 value=16

Image Processing Controls

                 link_frequency 0x009f0901 (intmenu): min=0 max=0 default=0 value=0
                     pixel_rate 0x009f0902 (int64)  : min=0 max=4410525 step=1 default=4410525 value=4410525 flags=read-only
                   test_pattern 0x009f0903 (menu)   : min=0 max=4 default=0 value=0

可以看到Image Process Controls类下面有link_frequency

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dianlong_lee

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值