uvc摄像头代码解析5

8.初始化uvc控制

8.1 重要结构体

[cpp]  view plain copy
  1. struct uvc_control {    //uvc控制  
  2.     struct uvc_entity *entity;  //uvc实体  
  3.     struct uvc_control_info info;   //uvc控制信息  
  4.     __u8 index; //索引值  
  5.     __u8 dirty:1,  
  6.          loaded:1,  
  7.          modified:1,  
  8.          cached:1,  
  9.          initialized:1; //初始化标志  
  10.     __u8 *uvc_data; //uvc控制数据  
  11. };  


8.2 初始化uvc控制设备

[cpp]  view plain copy
  1. int uvc_ctrl_init_device(struct uvc_device *dev)  
  2. {  
  3.     struct uvc_entity *entity;  
  4.     unsigned int i;  
  5.     /* Walk the entities list and instantiate controls */  
  6.     list_for_each_entry(entity, &dev->entities, list) {  //遍历uvc设备实体entities链表  
  7.         struct uvc_control *ctrl;   //uvc控制  
  8.         unsigned int bControlSize = 0, ncontrols = 0;  
  9.         __u8 *bmControls = NULL;  
  10.         if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT) { //扩展Unit  
  11.             bmControls = entity->extension.bmControls;   //控制位图  
  12.             bControlSize = entity->extension.bControlSize;   //控制位域大小  
  13.         }   
  14.         else if (UVC_ENTITY_TYPE(entity) == UVC_VC_PROCESSING_UNIT) {   //处理Unit  
  15.             bmControls = entity->processing.bmControls;  //控制位图  
  16.             bControlSize = entity->processing.bControlSize;  //控制位域大小  
  17.         }   
  18.         else if (UVC_ENTITY_TYPE(entity) == UVC_ITT_CAMERA) {   //输入Terminal Camera  
  19.             bmControls = entity->camera.bmControls;  //控制位图  
  20.             bControlSize = entity->camera.bControlSize;  //控制位域大小  
  21.         }  
  22.         /* Remove bogus/blacklisted controls 移除假的/黑名单控制组件*/  
  23.         uvc_ctrl_prune_entity(dev, entity);  
  24.         /* Count supported controls and allocate the controls array */  
  25.         for (i = 0; i < bControlSize; ++i)  
  26.             ncontrols += hweight8(bmControls[i]);   //统计控制组件个数  
  27.         if (ncontrols == 0)  
  28.             continue;  
  29.         entity->controls = kzalloc(ncontrols * sizeof(*ctrl),GFP_KERNEL);    //分配ncontrols个uvc控制内存  
  30.         if (entity->controls == NULL)  
  31.             return -ENOMEM;  
  32.         entity->ncontrols = ncontrols;   //设置uvc控制个数  
  33.         /* Initialize all supported controls */  
  34.         ctrl = entity->controls; //指向uvc控制数组  
  35.         for (i = 0; i < bControlSize * 8; ++i) {  
  36.             if (uvc_test_bit(bmControls, i) == 0)   //跳过控制位域没设置1的  
  37.                 continue;  
  38.             ctrl->entity = entity;   //捆绑uvc实体和uvc控制  
  39.             ctrl->index = i; //设置控制位域索引  
  40.             uvc_ctrl_init_ctrl(dev, ctrl);  //9初始化uvc控件  
  41.             ctrl++; //uvc控制 指向下一个uvc控制数组项  
  42.         }  
  43.     }  
  44.     return 0;  
  45. }  
9初始化uvc控件

9.1 相关结构体
9.1.1 uvc控制信息

[cpp]  view plain copy
  1. struct uvc_control_info {   //uvc控制信息  
  2.     struct list_head mappings;  //uvc控制位图链表头  
  3.     __u8 entity[16];  
  4.     __u8 index; /* Bit index in bmControls */  
  5.     __u8 selector;  
  6.     __u16 size;  
  7.     __u32 flags;  
  8. };  


9.1.2 uvc控制位图

[cpp]  view plain copy
  1. struct uvc_control_mapping {    //uvc控制位图  
  2.     struct list_head list;  //链表  
  3.     struct uvc_control_info *ctrl;  //uvc控制信息  
  4.     __u32 id;  
  5.     __u8 name[32];  
  6.     __u8 entity[16];  
  7.     __u8 selector;  
  8.     __u8 size;  
  9.     __u8 offset;  
  10.     enum v4l2_ctrl_type v4l2_type;  //v4l2控制类型  
  11.     __u32 data_type;  
  12.     struct uvc_menu_info *menu_info;    //uvc菜单信息  
  13.     __u32 menu_count;   //uvc菜单个数  
  14.     __s32 (*get) (struct uvc_control_mapping *mapping, __u8 query,const __u8 *data);  
  15.     void (*set) (struct uvc_control_mapping *mapping, __s32 value,__u8 *data);  
  16. };  

9.2 初始化uvc控制

[cpp]  view plain copy
  1. static void uvc_ctrl_init_ctrl(struct uvc_device *dev, struct uvc_control *ctrl)  
  2. {  
  3.     const struct uvc_control_info *info = uvc_ctrls;    //指向全局静态uvc控制信息数组  
  4.     const struct uvc_control_info *iend = info + ARRAY_SIZE(uvc_ctrls); //指向数组末端  
  5.     const struct uvc_control_mapping *mapping = uvc_ctrl_mappings;  //指向全局静态uvc控制位图数组  
  6.     const struct uvc_control_mapping *mend = mapping + ARRAY_SIZE(uvc_ctrl_mappings);   //指向数组末端  
  7.     if (UVC_ENTITY_TYPE(ctrl->entity) == UVC_VC_EXTENSION_UNIT)  //ctrl->entity->type为扩展Unit(延后扩展Unit的初始化到当它第一次使用)  
  8.         return;  
  9.     for (; info < iend; ++info) {    //遍历整个uvc控制信息数据  
  10.         if (uvc_entity_match_guid(ctrl->entity, info->entity) && ctrl->index == info->index) {  //匹配条件  
  11.             uvc_ctrl_add_info(dev, ctrl, info); //添加uvc控制信息  
  12.             break;  
  13.          }  
  14.     }  
  15.     if (!ctrl->initialized)  //已经给初始化  
  16.         return;  
  17.     for (; mapping < mend; ++mapping) {  //遍历整个uvc控制位图数组  
  18.         if (uvc_entity_match_guid(ctrl->entity, mapping->entity) && ctrl->info.selector == mapping->selector)   //匹配条件  
  19.             __uvc_ctrl_add_mapping(dev, ctrl, mapping); //添加控制位图  
  20.     }  
  21. }  


9.2.1 全局静态uvc控制信息数组uvc-ctrls

[cpp]  view plain copy
  1. static struct uvc_control_info uvc_ctrls[] = {  
  2.     {   //背光控制  
  3.         .entity     = UVC_GUID_UVC_PROCESSING,  
  4.         .selector   = UVC_PU_BRIGHTNESS_CONTROL,  
  5.         .index      = 0,  
  6.         .size       = 2,  
  7.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  8.     },  
  9.     {   //对比度控制  
  10.         .entity     = UVC_GUID_UVC_PROCESSING,  
  11.         .selector   = UVC_PU_CONTRAST_CONTROL,  
  12.         .index      = 1,  
  13.         .size       = 2,  
  14.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  15.     },  
  16.     {   //色度控制  
  17.         .entity     = UVC_GUID_UVC_PROCESSING,  
  18.         .selector   = UVC_PU_HUE_CONTROL,  
  19.         .index      = 2,  
  20.         .size       = 2,  
  21.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  22.     },  
  23.     {   //饱和度控制  
  24.         .entity     = UVC_GUID_UVC_PROCESSING,  
  25.         .selector   = UVC_PU_SATURATION_CONTROL,  
  26.         .index      = 3,  
  27.         .size       = 2,  
  28.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  29.     },  
  30.     {   //锐度控制  
  31.         .entity     = UVC_GUID_UVC_PROCESSING,  
  32.         .selector   = UVC_PU_SHARPNESS_CONTROL,  
  33.         .index      = 4,  
  34.         .size       = 2,  
  35.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  36.     },  
  37.     {   //gamma设置  
  38.         .entity     = UVC_GUID_UVC_PROCESSING,  
  39.         .selector   = UVC_PU_GAMMA_CONTROL,  
  40.         .index      = 5,  
  41.         .size       = 2,  
  42.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  43.     },  
  44.     {   //白平衡温度控制  
  45.         .entity     = UVC_GUID_UVC_PROCESSING,  
  46.         .selector   = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL,  
  47.         .index      = 6,  
  48.         .size       = 2,  
  49.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  50.     },  
  51.     {   //白平衡组件  
  52.         .entity     = UVC_GUID_UVC_PROCESSING,  
  53.         .selector   = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,  
  54.         .index      = 7,  
  55.         .size       = 4,  
  56.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  57.     },  
  58.     {   //背光补偿  
  59.         .entity     = UVC_GUID_UVC_PROCESSING,  
  60.         .selector   = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL,  
  61.         .index      = 8,  
  62.         .size       = 2,  
  63.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  64.     },  
  65.     {   //增益  
  66.         .entity     = UVC_GUID_UVC_PROCESSING,  
  67.         .selector   = UVC_PU_GAIN_CONTROL,  
  68.         .index      = 9,  
  69.         .size       = 2,  
  70.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  71.     },  
  72.     {   //电源线频率  
  73.         .entity     = UVC_GUID_UVC_PROCESSING,  
  74.         .selector   = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,  
  75.         .index      = 10,  
  76.         .size       = 1,  
  77.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,  
  78.     },  
  79.     {   //自动色度调节  
  80.         .entity     = UVC_GUID_UVC_PROCESSING,  
  81.         .selector   = UVC_PU_HUE_AUTO_CONTROL,  
  82.         .index      = 11,  
  83.         .size       = 1,  
  84.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,  
  85.     },  
  86.     {   //白平衡色温自动调节  
  87.         .entity     = UVC_GUID_UVC_PROCESSING,  
  88.         .selector   = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,  
  89.         .index      = 12,  
  90.         .size       = 1,  
  91.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,  
  92.     },  
  93.     {   //白平衡自动调节  
  94.         .entity     = UVC_GUID_UVC_PROCESSING,  
  95.         .selector   = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,  
  96.         .index      = 13,  
  97.         .size       = 1,  
  98.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,  
  99.     },  
  100.     {   //数字多功能控制  
  101.         .entity     = UVC_GUID_UVC_PROCESSING,  
  102.         .selector   = UVC_PU_DIGITAL_MULTIPLIER_CONTROL,  
  103.         .index      = 14,  
  104.         .size       = 2,  
  105.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  106.     },    
  107.     {   //数字多功能限制控制  
  108.         .entity     = UVC_GUID_UVC_PROCESSING,  
  109.         .selector   = UVC_PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL,  
  110.         .index      = 15,  
  111.         .size       = 2,  
  112.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  113.     },  
  114.     {   //模拟视频标准控制  
  115.         .entity     = UVC_GUID_UVC_PROCESSING,  
  116.         .selector   = UVC_PU_ANALOG_VIDEO_STANDARD_CONTROL,  
  117.         .index      = 16,  
  118.         .size       = 1,  
  119.         .flags      = UVC_CONTROL_GET_CUR,  
  120.     },  
  121.     {   //模拟视频锁存状态  
  122.         .entity     = UVC_GUID_UVC_PROCESSING,  
  123.         .selector   = UVC_PU_ANALOG_LOCK_STATUS_CONTROL,  
  124.         .index      = 17,  
  125.         .size       = 1,  
  126.         .flags      = UVC_CONTROL_GET_CUR,  
  127.     },  
  128.     {   //扫描模式  
  129.         .entity     = UVC_GUID_UVC_CAMERA,  
  130.         .selector   = UVC_CT_SCANNING_MODE_CONTROL,  
  131.         .index      = 0,  
  132.         .size       = 1,  
  133.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_RESTORE,  
  134.     },  
  135.     {   //。。。  
  136.         .entity     = UVC_GUID_UVC_CAMERA,  
  137.         .selector   = UVC_CT_AE_MODE_CONTROL,  
  138.         .index      = 1,  
  139.         .size       = 1,  
  140.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_GET_DEF | UVC_CONTROL_GET_RES| UVC_CONTROL_RESTORE,  
  141.     },  
  142.     {  
  143.         .entity     = UVC_GUID_UVC_CAMERA,  
  144.         .selector   = UVC_CT_AE_PRIORITY_CONTROL,  
  145.         .index      = 2,  
  146.         .size       = 1,  
  147.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_RESTORE,  
  148.     },  
  149.     {  
  150.         .entity     = UVC_GUID_UVC_CAMERA,  
  151.         .selector   = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL,  
  152.         .index      = 3,  
  153.         .size       = 4,  
  154.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE,  
  155.     },  
  156.     {  
  157.         .entity     = UVC_GUID_UVC_CAMERA,  
  158.         .selector   = UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL,  
  159.         .index      = 4,  
  160.         .size       = 1,  
  161.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_RESTORE,  
  162.     },  
  163.     {  
  164.         .entity     = UVC_GUID_UVC_CAMERA,  
  165.         .selector   = UVC_CT_FOCUS_ABSOLUTE_CONTROL,  
  166.         .index      = 5,  
  167.         .size       = 2,  
  168.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  169.     },  
  170.     {  
  171.         .entity     = UVC_GUID_UVC_CAMERA,  
  172.         .selector   = UVC_CT_FOCUS_RELATIVE_CONTROL,  
  173.         .index      = 6,  
  174.         .size       = 2,  
  175.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN| UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES| UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,  
  176.     },  
  177.     {  
  178.         .entity     = UVC_GUID_UVC_CAMERA,  
  179.         .selector   = UVC_CT_IRIS_ABSOLUTE_CONTROL,  
  180.         .index      = 7,  
  181.         .size       = 2,  
  182.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  183.     },  
  184.     {  
  185.         .entity     = UVC_GUID_UVC_CAMERA,  
  186.         .selector   = UVC_CT_IRIS_RELATIVE_CONTROL,  
  187.         .index      = 8,  
  188.         .size       = 1,  
  189.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_AUTO_UPDATE,  
  190.     },  
  191.     {  
  192.         .entity     = UVC_GUID_UVC_CAMERA,  
  193.         .selector   = UVC_CT_ZOOM_ABSOLUTE_CONTROL,  
  194.         .index      = 9,  
  195.         .size       = 2,  
  196.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  197.     },  
  198.     {  
  199.         .entity     = UVC_GUID_UVC_CAMERA,  
  200.         .selector   = UVC_CT_ZOOM_RELATIVE_CONTROL,  
  201.         .index      = 10,  
  202.         .size       = 3,  
  203.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN| UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES| UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,  
  204.     },  
  205.     {  
  206.         .entity     = UVC_GUID_UVC_CAMERA,  
  207.         .selector   = UVC_CT_PANTILT_ABSOLUTE_CONTROL,  
  208.         .index      = 11,  
  209.         .size       = 8,  
  210.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  211.     },  
  212.     {  
  213.         .entity     = UVC_GUID_UVC_CAMERA,  
  214.         .selector   = UVC_CT_PANTILT_RELATIVE_CONTROL,  
  215.         .index      = 12,  
  216.         .size       = 4,  
  217.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN| UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES| UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,  
  218.     },  
  219.     {  
  220.         .entity     = UVC_GUID_UVC_CAMERA,  
  221.         .selector   = UVC_CT_ROLL_ABSOLUTE_CONTROL,  
  222.         .index      = 13,  
  223.         .size       = 2,  
  224.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  225.     },  
  226.     {  
  227.         .entity     = UVC_GUID_UVC_CAMERA,  
  228.         .selector   = UVC_CT_ROLL_RELATIVE_CONTROL,  
  229.         .index      = 14,  
  230.         .size       = 2,  
  231.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN  
  232.                 | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES  
  233.                 | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,  
  234.     },  
  235.     {  
  236.         .entity     = UVC_GUID_UVC_CAMERA,  
  237.         .selector   = UVC_CT_FOCUS_AUTO_CONTROL,  
  238.         .index      = 17,  
  239.         .size       = 1,  
  240.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,  
  241.     },  
  242.     {  
  243.         .entity     = UVC_GUID_UVC_CAMERA,  
  244.         .selector   = UVC_CT_PRIVACY_CONTROL,  
  245.         .index      = 18,  
  246.         .size       = 1,  
  247.         .flags      = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR| UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,  
  248.     },  
  249. };  

9.2.2 全局静态uvc控制位图数组(uvc_ctrl_mappings)

[cpp]  view plain copy
  1. static struct uvc_control_mapping uvc_ctrl_mappings[] = {  
  2.     {  
  3.         .id     = V4L2_CID_BRIGHTNESS,  
  4.         .name       = "Brightness",  
  5.         .entity     = UVC_GUID_UVC_PROCESSING,  
  6.         .selector   = UVC_PU_BRIGHTNESS_CONTROL,  
  7.         .size       = 16,  
  8.         .offset     = 0,  
  9.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  10.         .data_type  = UVC_CTRL_DATA_TYPE_SIGNED,  
  11.     },  
  12.     {  
  13.         .id     = V4L2_CID_CONTRAST,  
  14.         .name       = "Contrast",  
  15.         .entity     = UVC_GUID_UVC_PROCESSING,  
  16.         .selector   = UVC_PU_CONTRAST_CONTROL,  
  17.         .size       = 16,  
  18.         .offset     = 0,  
  19.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  20.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  21.     },  
  22.     {  
  23.         .id     = V4L2_CID_HUE,  
  24.         .name       = "Hue",  
  25.         .entity     = UVC_GUID_UVC_PROCESSING,  
  26.         .selector   = UVC_PU_HUE_CONTROL,  
  27.         .size       = 16,  
  28.         .offset     = 0,  
  29.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  30.         .data_type  = UVC_CTRL_DATA_TYPE_SIGNED,  
  31.     },  
  32.     {  
  33.         .id     = V4L2_CID_SATURATION,  
  34.         .name       = "Saturation",  
  35.         .entity     = UVC_GUID_UVC_PROCESSING,  
  36.         .selector   = UVC_PU_SATURATION_CONTROL,  
  37.         .size       = 16,  
  38.         .offset     = 0,  
  39.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  40.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  41.     },  
  42.     {  
  43.         .id     = V4L2_CID_SHARPNESS,  
  44.         .name       = "Sharpness",  
  45.         .entity     = UVC_GUID_UVC_PROCESSING,  
  46.         .selector   = UVC_PU_SHARPNESS_CONTROL,  
  47.         .size       = 16,  
  48.         .offset     = 0,  
  49.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  50.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  51.     },  
  52.     {  
  53.         .id     = V4L2_CID_GAMMA,  
  54.         .name       = "Gamma",  
  55.         .entity     = UVC_GUID_UVC_PROCESSING,  
  56.         .selector   = UVC_PU_GAMMA_CONTROL,  
  57.         .size       = 16,  
  58.         .offset     = 0,  
  59.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  60.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  61.     },  
  62.     {  
  63.         .id     = V4L2_CID_BACKLIGHT_COMPENSATION,  
  64.         .name       = "Backlight Compensation",  
  65.         .entity     = UVC_GUID_UVC_PROCESSING,  
  66.         .selector   = UVC_PU_BACKLIGHT_COMPENSATION_CONTROL,  
  67.         .size       = 16,  
  68.         .offset     = 0,  
  69.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  70.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  71.     },  
  72.     {  
  73.         .id     = V4L2_CID_GAIN,  
  74.         .name       = "Gain",  
  75.         .entity     = UVC_GUID_UVC_PROCESSING,  
  76.         .selector   = UVC_PU_GAIN_CONTROL,  
  77.         .size       = 16,  
  78.         .offset     = 0,  
  79.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  80.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  81.     },  
  82.     {  
  83.         .id     = V4L2_CID_POWER_LINE_FREQUENCY,  
  84.         .name       = "Power Line Frequency",  
  85.         .entity     = UVC_GUID_UVC_PROCESSING,  
  86.         .selector   = UVC_PU_POWER_LINE_FREQUENCY_CONTROL,  
  87.         .size       = 2,  
  88.         .offset     = 0,  
  89.         .v4l2_type  = V4L2_CTRL_TYPE_MENU,  
  90.         .data_type  = UVC_CTRL_DATA_TYPE_ENUM,  
  91.         .menu_info  = power_line_frequency_controls,  
  92.         .menu_count = ARRAY_SIZE(power_line_frequency_controls),  
  93.     },  
  94.     {  
  95.         .id     = V4L2_CID_HUE_AUTO,  
  96.         .name       = "Hue, Auto",  
  97.         .entity     = UVC_GUID_UVC_PROCESSING,  
  98.         .selector   = UVC_PU_HUE_AUTO_CONTROL,  
  99.         .size       = 1,  
  100.         .offset     = 0,  
  101.         .v4l2_type  = V4L2_CTRL_TYPE_BOOLEAN,  
  102.         .data_type  = UVC_CTRL_DATA_TYPE_BOOLEAN,  
  103.     },  
  104.     {  
  105.         .id     = V4L2_CID_EXPOSURE_AUTO,  
  106.         .name       = "Exposure, Auto",  
  107.         .entity     = UVC_GUID_UVC_CAMERA,  
  108.         .selector   = UVC_CT_AE_MODE_CONTROL,  
  109.         .size       = 4,  
  110.         .offset     = 0,  
  111.         .v4l2_type  = V4L2_CTRL_TYPE_MENU,  
  112.         .data_type  = UVC_CTRL_DATA_TYPE_BITMASK,  
  113.         .menu_info  = exposure_auto_controls,  
  114.         .menu_count = ARRAY_SIZE(exposure_auto_controls),  
  115.     },  
  116.     {  
  117.         .id     = V4L2_CID_EXPOSURE_AUTO_PRIORITY,  
  118.         .name       = "Exposure, Auto Priority",  
  119.         .entity     = UVC_GUID_UVC_CAMERA,  
  120.         .selector   = UVC_CT_AE_PRIORITY_CONTROL,  
  121.         .size       = 1,  
  122.         .offset     = 0,  
  123.         .v4l2_type  = V4L2_CTRL_TYPE_BOOLEAN,  
  124.         .data_type  = UVC_CTRL_DATA_TYPE_BOOLEAN,  
  125.     },  
  126.     {  
  127.         .id     = V4L2_CID_EXPOSURE_ABSOLUTE,  
  128.         .name       = "Exposure (Absolute)",  
  129.         .entity     = UVC_GUID_UVC_CAMERA,  
  130.         .selector   = UVC_CT_EXPOSURE_TIME_ABSOLUTE_CONTROL,  
  131.         .size       = 32,  
  132.         .offset     = 0,  
  133.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  134.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  135.     },  
  136.     {  
  137.         .id     = V4L2_CID_AUTO_WHITE_BALANCE,  
  138.         .name       = "White Balance Temperature, Auto",  
  139.         .entity     = UVC_GUID_UVC_PROCESSING,  
  140.         .selector   = UVC_PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,  
  141.         .size       = 1,  
  142.         .offset     = 0,  
  143.         .v4l2_type  = V4L2_CTRL_TYPE_BOOLEAN,  
  144.         .data_type  = UVC_CTRL_DATA_TYPE_BOOLEAN,  
  145.     },  
  146.     {  
  147.         .id     = V4L2_CID_WHITE_BALANCE_TEMPERATURE,  
  148.         .name       = "White Balance Temperature",  
  149.         .entity     = UVC_GUID_UVC_PROCESSING,  
  150.         .selector   = UVC_PU_WHITE_BALANCE_TEMPERATURE_CONTROL,  
  151.         .size       = 16,  
  152.         .offset     = 0,  
  153.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  154.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  155.     },  
  156.     {  
  157.         .id     = V4L2_CID_AUTO_WHITE_BALANCE,  
  158.         .name       = "White Balance Component, Auto",  
  159.         .entity     = UVC_GUID_UVC_PROCESSING,  
  160.         .selector   = UVC_PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,  
  161.         .size       = 1,  
  162.         .offset     = 0,  
  163.         .v4l2_type  = V4L2_CTRL_TYPE_BOOLEAN,  
  164.         .data_type  = UVC_CTRL_DATA_TYPE_BOOLEAN,  
  165.     },  
  166.     {  
  167.         .id     = V4L2_CID_BLUE_BALANCE,  
  168.         .name       = "White Balance Blue Component",  
  169.         .entity     = UVC_GUID_UVC_PROCESSING,  
  170.         .selector   = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,  
  171.         .size       = 16,  
  172.         .offset     = 0,  
  173.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  174.         .data_type  = UVC_CTRL_DATA_TYPE_SIGNED,  
  175.     },  
  176.     {  
  177.         .id     = V4L2_CID_RED_BALANCE,  
  178.         .name       = "White Balance Red Component",  
  179.         .entity     = UVC_GUID_UVC_PROCESSING,  
  180.         .selector   = UVC_PU_WHITE_BALANCE_COMPONENT_CONTROL,  
  181.         .size       = 16,  
  182.         .offset     = 16,  
  183.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  184.         .data_type  = UVC_CTRL_DATA_TYPE_SIGNED,  
  185.     },  
  186.     {  
  187.         .id     = V4L2_CID_FOCUS_ABSOLUTE,  
  188.         .name       = "Focus (absolute)",  
  189.         .entity     = UVC_GUID_UVC_CAMERA,  
  190.         .selector   = UVC_CT_FOCUS_ABSOLUTE_CONTROL,  
  191.         .size       = 16,  
  192.         .offset     = 0,  
  193.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  194.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  195.     },  
  196.     {  
  197.         .id     = V4L2_CID_FOCUS_AUTO,  
  198.         .name       = "Focus, Auto",  
  199.         .entity     = UVC_GUID_UVC_CAMERA,  
  200.         .selector   = UVC_CT_FOCUS_AUTO_CONTROL,  
  201.         .size       = 1,  
  202.         .offset     = 0,  
  203.         .v4l2_type  = V4L2_CTRL_TYPE_BOOLEAN,  
  204.         .data_type  = UVC_CTRL_DATA_TYPE_BOOLEAN,  
  205.     },  
  206.     {  
  207.         .id     = V4L2_CID_IRIS_ABSOLUTE,  
  208.         .name       = "Iris, Absolute",  
  209.         .entity     = UVC_GUID_UVC_CAMERA,  
  210.         .selector   = UVC_CT_IRIS_ABSOLUTE_CONTROL,  
  211.         .size       = 16,  
  212.         .offset     = 0,  
  213.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  214.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  215.     },  
  216.     {  
  217.         .id     = V4L2_CID_IRIS_RELATIVE,  
  218.         .name       = "Iris, Relative",  
  219.         .entity     = UVC_GUID_UVC_CAMERA,  
  220.         .selector   = UVC_CT_IRIS_RELATIVE_CONTROL,  
  221.         .size       = 8,  
  222.         .offset     = 0,  
  223.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  224.         .data_type  = UVC_CTRL_DATA_TYPE_SIGNED,  
  225.     },  
  226.     {  
  227.         .id     = V4L2_CID_ZOOM_ABSOLUTE,  
  228.         .name       = "Zoom, Absolute",  
  229.         .entity     = UVC_GUID_UVC_CAMERA,  
  230.         .selector   = UVC_CT_ZOOM_ABSOLUTE_CONTROL,  
  231.         .size       = 16,  
  232.         .offset     = 0,  
  233.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  234.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  235.     },  
  236.     {  
  237.         .id     = V4L2_CID_ZOOM_CONTINUOUS,  
  238.         .name       = "Zoom, Continuous",  
  239.         .entity     = UVC_GUID_UVC_CAMERA,  
  240.         .selector   = UVC_CT_ZOOM_RELATIVE_CONTROL,  
  241.         .size       = 0,  
  242.         .offset     = 0,  
  243.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  244.         .data_type  = UVC_CTRL_DATA_TYPE_SIGNED,  
  245.         .get        = uvc_ctrl_get_zoom,  
  246.         .set        = uvc_ctrl_set_zoom,  
  247.     },  
  248.     {  
  249.         .id     = V4L2_CID_PAN_ABSOLUTE,  
  250.         .name       = "Pan (Absolute)",  
  251.         .entity     = UVC_GUID_UVC_CAMERA,  
  252.         .selector   = UVC_CT_PANTILT_ABSOLUTE_CONTROL,  
  253.         .size       = 32,  
  254.         .offset     = 0,  
  255.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  256.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  257.     },  
  258.     {  
  259.         .id     = V4L2_CID_TILT_ABSOLUTE,  
  260.         .name       = "Tilt (Absolute)",  
  261.         .entity     = UVC_GUID_UVC_CAMERA,  
  262.         .selector   = UVC_CT_PANTILT_ABSOLUTE_CONTROL,  
  263.         .size       = 32,  
  264.         .offset     = 32,  
  265.         .v4l2_type  = V4L2_CTRL_TYPE_INTEGER,  
  266.         .data_type  = UVC_CTRL_DATA_TYPE_UNSIGNED,  
  267.     },  
  268.     {  
  269.         .id     = V4L2_CID_PRIVACY,  
  270.         .name       = "Privacy",  
  271.         .entity     = UVC_GUID_UVC_CAMERA,  
  272.         .selector   = UVC_CT_PRIVACY_CONTROL,  
  273.         .size       = 1,  
  274.         .offset     = 0,  
  275.         .v4l2_type  = V4L2_CTRL_TYPE_BOOLEAN,  
  276.         .data_type  = UVC_CTRL_DATA_TYPE_BOOLEAN,  
  277.     },  
  278. };  

9.2.3 添加uvc控制信息

[cpp]  view plain copy
  1. static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl,const struct uvc_control_info *info)  
  2. {  
  3.     int ret = 0;  
  4.     memcpy(&ctrl->info, info, sizeof(*info));    //初始化uvc控制的uvc控制信息对象  
  5.     INIT_LIST_HEAD(&ctrl->info.mappings);    //初始化uvc控制信息的uvc链表头  
  6.     /* Allocate an array to save control values (cur, def, max, etc.) */  
  7.     ctrl->uvc_data = kzalloc(ctrl->info.size * UVC_CTRL_DATA_LAST + 1,GFP_KERNEL);    //分配uvc控制数据内存  
  8.     if (ctrl->uvc_data == NULL) {  
  9.         ret = -ENOMEM;  
  10.         goto done;  
  11.     }  
  12.     ctrl->initialized = 1;   //设置uvc控制初始化标准  
  13.     uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s entity %u\n", ctrl->info.entity, ctrl->info.selector,dev->udev->devpath, ctrl->entity->id);  
  14. done:  
  15.     if (ret < 0)  
  16.         kfree(ctrl->uvc_data);  
  17.     return ret;  
  18. }  

9.2.4 添加uvc位图

[cpp]  view plain copy
  1. static int __uvc_ctrl_add_mapping(struct uvc_device *dev,struct uvc_control *ctrl, const struct uvc_control_mapping *mapping)  
  2. {  
  3.     struct uvc_control_mapping *map;  
  4.     unsigned int size;  
  5.     map = kmemdup(mapping, sizeof(*mapping), GFP_KERNEL);   //分配uvc控制位图内存  
  6.     if (map == NULL)  
  7.         return -ENOMEM;  
  8.     size = sizeof(*mapping->menu_info) * mapping->menu_count; //计算uvc菜单数组占用空间  
  9.     map->menu_info = kmemdup(mapping->menu_info, size, GFP_KERNEL);   //分配uvc菜单数组内存  
  10.     if (map->menu_info == NULL) {  
  11.         kfree(map);  
  12.         return -ENOMEM;  
  13.     }  
  14.     if (map->get == NULL)  
  15.         map->get = uvc_get_le_value; //设置默认获取方法  
  16.     if (map->set == NULL)  
  17.         map->set = uvc_set_le_value; //设置默认设置方法  
  18.     map->ctrl = &ctrl->info;  //捆绑uvc控制信息和uvc控制信息位图  
  19.     list_add_tail(&map->list, &ctrl->info.mappings);  //添加uvc控制位图到uvc控制信息的位图链表  
  20.     uvc_trace(UVC_TRACE_CONTROL,"Adding mapping '%s' to control %pUl/%u.\n",map->name, ctrl->info.entity, ctrl->info.selector);  
  21.     return 0;  
  22. }  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值