Linux notes (fixed USB camera hardware port, bind front and rear camera)

Source: Internet
Author: User

The Android system will have a front-facing camera and a rear camera definition, the camera is divided into the SOC type of camera and USB camera, and then to analyze is the USB camera this category.

Generally in the Android or Linux system analysis of a module, first from the overall framework of the understanding, and then in the local thin research.

First, Android camera overall architecture

The above frame, the analysis of the comparison of rough, mainly some of their own look at the code after the summary of things down. In the case of USB cameras, a device node such as/dev/video0 is generated after the USB camera is plugged in, and in the hardware abstraction layer, the device node is determined to be available for use by the Android system layer. Further analysis is the Android part of the first, temporarily do not analyze.

Second, the Linux layer in the UVC camera registration process

After the USB subsystem is judged to have a UVC device access, it will call Uvc_probe (code location:/driver/media/uvc/uvc_ DRIVER.C) to complete the creation of the USB camera, through step-by-step analysis, will eventually go to the v4l2 frame, creating the camera's device node.

Third, fixed USB camera hardware port

The previous analysis of so many, is to prepare for the next.

Now customers so use our motherboard machine, which will use two USB cameras, one as a front-facing camera for face recognition, one for the rear camera, because in the installation is not known that the port of the camera first inserted, the post-insertion (the device node first access will be allocated Video0, In Android, the general definition of Video0 as the rear camera, video1 as a front-facing camera, led to the Android system layer front and rear camera confusion.

In order to solve this problem, it is necessary to make a binding between the front and rear camera and the USB hardware port in the driver.

The specific modification is as follows:

(1) Adding variables to the video_device structure of/include/media/v4l2-dev.h Portnum

struct Video_device      struct list_head/    **/      int debug;            /* activates debug level */+    int portnum;        /* USB HW Port */

(2) Add vdev->portnum = dev->udev-> in the uvc_register_video function of/DRIVERS/MEDIA/USB/UVC/UVC_DRIVER.C Portnum;

Static int uvc_register_video (struct uvc_device *Dev,...     Stream->vdev = vdev;      +    Vdev->portnum = dev->udev->portnum;      = Video_register_device (Vdev, Vfl_type_grabber,-1);

Here first the USB portnum, in the creation of the device node, will be based on the variable to distinguish the hardware which USB is the predecessor, which USB is back

(3) in the __video_register_device function of/drivers/media/v4l2-core/v4l2-dev.c, modify

 int__video_register_device (structVideo_device *vdev,intTypeintnr, .../*Pick A Device node number*/Mutex_lock (&videodev_lock);+if(Vdev->vfl_type = =Vfl_type_grabber) {+if(4= = Vdev->portnum) {+ NR =1;+        }Else {+ NR =0;+        }+    }Else {+ nr = Devnode_find (vdev, nr = =-1?0: NR, minor_cnt);+    }+if(NR = =minor_cnt) Nr= Devnode_find (Vdev,0, minor_cnt); if(nr = = minor_cnt) {

Note: Here the "4 = = Vdev->portnum" is based on the timing of the port on the board, when debugging, you can first print out the value of the Portnum variable, you know how to distinguish.

Linux notes (fixed USB camera hardware port, bind front and rear camera)

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.