uvc摄像头代码解析5
8.初始化uvc控制8.1 重要结构体
[cpp]
struct uvc_control { //uvc控制
struct uvc_entity *entity; //uvc实体
struct uvc_control_info info; //uvc控制信息
__u8 index; //索引值
__u8 dirty:1,
loaded:1,
modified:1,
cached:1,
initialized:1; //初始化标志
__u8 *uvc_data; //uvc控制数据
};
8.2 初始化uvc控制设备
[cpp]
int uvc_ctrl_init_device(struct uvc_device *dev)
{
struct uvc_entity *entity;
unsigned int i;
/* Walk the entities list and instantiate controls */
list_for_each_entry(entity, &dev->entities, list) { //遍历uvc设备实体entities链表
struct uvc_control *ctrl; //uvc控制
unsigned int bControlSize = 0, ncontrols = 0;
__u8 *bmControls = NULL;
if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) { //扩展Unit
bmControls = entity->extension.bmControls; //控制位图
bControlSize = entity->extension.bControlSize; //控制位域大小
}
else if (UVC_ENTITY_TYPE(entity) == UVC_VC_PROCESSING_UNIT) { //处理Unit
bmControls = entity->processing.bmControls; //控制位图
bControlSize = entity->processing.bControlSize; //控制位域大小
}
else if (UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) { //输入Terminal Camera
bmControls = entity->camera.bmControls; //控制位图
bControlSize = entity->camera.bControlSize; //控制位域大小
}
/* Remove bogus/blacklisted controls 移除假的/黑名单控制组件*/
uvc_ctrl_prune_entity(dev, entity);
/* Count supported controls and allocate the controls array */
for (i = 0; i < bControlSize; ++i)
ncontrols += hweight8(bmControls[i]); //统计控制组件个数
if (ncontrols == 0)
continue;
entity->controls = kzalloc(ncontrols * sizeof(*ctrl),GFP_KERNEL); //分配ncontrols个uvc控制内存
if (entity->controls == NULL)
return -ENOMEM;
entity->ncontrols = ncontrols; //设置uvc控制个数
/* Initialize all supported controls */
ctrl = entity->controls; //指向uvc控制数组
for (i = 0; i < bControlSize * 8; ++i) {
if (uvc_test_bit(bmControls, i) == 0) //跳过控制位域没设置1的
continue;
ctrl->entity = entity; //易做图uvc实体和uvc控制
ctrl->index = i; //设置控制位域索引
uvc_ctrl_init_ctrl(dev, ctrl); //9初始化uvc控件
ctrl++; //uvc控制 指向下一个uvc控制数组项
}
}
return 0;
}
9初始化uvc控件
9.1 相关结构体
9.1.1 uvc控制信息
[cpp]
struct uvc_control_info { //uvc控制信息
struct list_head mappings; //uvc控制位图链表头
__u8 entity[16];
__u8 index; /* Bit index in bmControls */
__u8 selector;
__u16 size;
__u32 flags;
};
9.1.2 uvc控制位图
[cpp]
struct uvc_control_mapping { //uvc控制位图
struct list_head list; //链表
struct uvc_control_info *ctrl; //uvc控制信息
__u32 id;
__u8 name[32];
__u8 entity[16];
__u8 selector;
__u8 size;
__u8 offset;
enum v4l2_ctrl_type v4l2_type; //v4l2控制类型
__u32 data_type;
struct uvc_menu_info *menu_info; //uvc菜单信息
__u32 menu_count; //uvc菜单个数
__s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,const __u8 *data);
void (*set) (struct uvc_control_mapping *mapping, __s32 value,__u8 *data);
};
9.2 初始化uvc控制
[cpp]
static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl)
{
const struct uvc_control_info *info = uvc_ctrls; //指向全局静态uvc控制信息数组
const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls); //指向数组末端
const struct uvc_control_mapping *mapping = uvc_ctrl_mappings; //指向全局静态uvc控制位图数组
const struct uvc_control_mapping *mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings); //指向数组末端
if (UVC_ENTITY_TYPE(ctrl->entity) == UVC_VC_EXTENSION_UNIT) //ctrl->entity->type为扩展Unit(延后扩展Unit的初始化到当它第一次使用)
return;
for (; info < iend; ++info) { //遍历整个uvc控制信息数据
if (uvc_entity_match_guid(ctrl->entity, info->entity) && ctrl->index == info->index) { //匹配条件
uvc_ctrl_add_info(dev, ctrl, info); //添加uvc控制信息
break;
}
}
补充:软件开发 , C++ ,
上一个:uvc摄像头代码解析6
下一个:uvc摄像头代码解析4
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊