Uvc camera code parsing 5

Source: Internet
Author: User

8. initialize uvc control 8.1 important struct [cpp] struct uvc_control {// uvc controls struct uvc_entity * entity; // uvc entity struct uvc_control_info info; // uvc control information _ u8 index; // index value _ u8 dirty: 1, loaded: 1, modified: 1, cached: 1, initialized: 1; // initialization flag _ u8 * uvc_data; // uvc control data}; 8.2 initialize uvc control device [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) {// traverse uvc device entity linked list struct uvc_control * ctrl; // uvc controls unsigned int bControlSize = 0, ncontrols = 0; _ u8 * bmControls = NULL; if (UVC_ENTITY_TYPE (entity) = UVC_VC_EXTENSION_UNIT) {// extended Unit bmControls = entity-> extension. bmControls; // controls the bitmap bControlSize = entity-> extension. bControlSize; // control bit domain size} else if (UVC_ENTITY_TYPE (entity) = UVC_VC_PROCESSING_UNIT) {// process Unit bmControls = entity-> processing. bmControls; // controls the bitmap bControlSize = entity-> processing. bControlSize; // control bit domain size} else if (UVC_ENTITY_TYPE (entity) = UVC_ITT_CAMERA) {// enter Terminal Camera bmControls = entity-> camera. bmControls; // controls the bitmap bControlSize = entity-> camera. bControlSize; // control bit domain size}/* Remove bogus/blacklisted controls Remove the false/blacklist control component */uvc_ctrl_prune_entity (dev, Entity);/* Count supported controls and allocate the controls array */for (I = 0; I <bControlSize; ++ I) ncontrols + = hweight8 (bmControls [I]); // The number of statistical control components if (ncontrols = 0) continue; entity-> controls = kzarloc (ncontrols * sizeof (* ctrl), GFP_KERNEL ); // allocate ncontrols uvc control memory if (entity-> controls = NULL) return-ENOMEM; entity-> ncontrols = ncontrols; // set the number of uvc controls/* Initialize all supported controls */Ctrl = entity-> controls; // point to the uvc control array for (I = 0; I <bControlSize * 8; ++ I) {if (uvc_test_bit (bmControls, I) = 0) // skip the continue where 1 is not set for the control bit field; ctrl-> entity = entity; // bind the uvc object and uvc control ctrl-> index = I; // set the control bit domain index uvc_ctrl_init_ctrl (dev, ctrl); // 9 initialize the uvc control ctrl ++; // uvc control points to the next uvc control array item} return 0 ;} 9 initialize the uvc control 9.1 struct 9.1.1 uvc control information [cpp] struct uvc_control_info {// uvc control information struct list_head mappings ;/ /Uvc controls the bitmap linked list header _ u8 entity [16]; _ u8 index;/* Bit index in bmControls */_ u8 selector; _ 002 size; _ u32 flags;}; 9.1.2 uvc-controlled bitmap [cpp] struct uvc_control_mapping {// uvc-controlled bitmap struct list_head list; // chain table struct uvc_control_info * ctrl; // uvc control information _ u32 id; _ u8 name [32]; _ u8 entity [16]; _ u8 selector; _ u8 size; _ u8 offset; enum v4l2_ctrl_type v4l2_type; // v4l2 control type _ u32 data_type; struct uvc_menu_inf O * menu_info; // uvc menu Information _ u32 menu_count; // uvc menu number _ 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 initialize uvc control [cpp] static void uvc_ctrl_init_ctrl (struct uvc_device * dev, struct uvc_control * ctrl) {const struct uvc_control_info * info = uvc_ctrls; // point to the Global static uvc control information array const struct uvc_cont Rol_info * iend = info + ARRAY_SIZE (uvc_ctrls); // point to the array End const struct uvc_control_mapping * mapping = uvc_ctrl_mappings; // point to the Global static uvc control bitmap array const struct uvc_control_mapping * mend = mapping + ARRAY_SIZE (uvc_ctrl_mappings); // point to the array End if (UVC_ENTITY_TYPE (ctrl-> entity) = warning) // ctrl-> entity-> type is extended Unit (Extended Unit is initialized until it is used for the first time) return; for (; info <iend; ++ info) {// traverse the entire uvc control information data if (uvc _ Entity_match_guid (ctrl-> entity, info-> entity) & ctrl-> index = info-> index) {// match condition uvc_ctrl_add_info (dev, ctrl, info ); // Add uvc control information break;} if (! Ctrl-> initialized) // The initialization return has been given; for (; mapping <mend; ++ mapping) {// traverse the entire uvc control bitmap array if (uvc_entity_match_guid (ctrl-> entity, mapping-> entity) & ctrl-> info. selector = mapping-> selector) // match condition _ uvc_ctrl_add_mapping (dev, ctrl, mapping); // Add control bitmap}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.