Linux camera-driven learning: (i) V4L2_ Framework Analysis

Source: Internet
Author: User

This time began to engage in Android camera low-level driver, the previous Linux video driver review, this article mainly summarizes VFL2 (video for Linux 2).

I. V4L2 framework: Video for Linux version 2
Virtual Video driver VIVI.C Analysis:
1. assigning Video_device
2. Set up
3. Registration: Video_register_device

Vivi_init
Vivi_create_instance
V4l2_device_register//Not primary, just used to initialize something, such as spin lock, reference count
Video_device_alloc
Set up
1. VFD:
. FoPs = &vivi_fops,
. Ioctl_ops = &vivi_ioctl_ops,
. Release = Video_device_release,
2.
Vfd->v4l2_dev = &dev->v4l2_dev;
3. Set the Ctrl property (IOCTL for the app):
V4l2_ctrl_handler_init (HDL, 11);
Dev->volume = V4L2_CTRL_NEW_STD (HDL, &vivi_ctrl_ops,
V4l2_cid_audio_volume, 0, 255, 1, 200);
Dev->brightness = V4L2_CTRL_NEW_STD (HDL, &vivi_ctrl_ops,
v4l2_cid_brightness, 0, 255, 1, 127);
Dev->contrast = V4L2_CTRL_NEW_STD (HDL, &vivi_ctrl_ops,
V4l2_cid_contrast, 0, 255, 1, 16);
Video_register_device (Video_device, Type:vfl_type_grabber, nr)
__video_register_device
Vdev->cdev = Cdev_alloc ();
Vdev->cdev->ops = &v4l2_fops;
Cdev_add

Video_device[vdev->minor] = Vdev;

          if (Vdev->ctrl_handler = = NULL)
            vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
               
                

Analyzing open,read,write,ioctl procedures for VIVI.C
1. Open
app:     open ("/dev/video0",....)
---------------------------------------------------
drv:     v4l2_fops.v4l2_open
            Vdev = Video_devdata (FILP); // Get Video_device from the array according to the secondary device number
            ret = vdev-> Fops->open (FILP);
                         Vivi_ioctl_ops.open
                              V4l2_fh_open

2. Read
App:read ....
---------------------------------------------------
Drv:v4l2_fops.v4l2_read
struct Video_device *vdev = Video_devdata (FILP);
ret = Vdev->fops->read (FILP, buf, SZ, off);

3. IOCTL
App:ioctl
----------------------------------------------------
Drv:v4l2_fops.unlocked_ioctl
V4l2_ioctl
struct Video_device *vdev = Video_devdata (FILP);
ret = Vdev->fops->unlocked_ioctl (Filp, CMD, arg);
Video_ioctl2
Video_usercopy (file, cmd, ARG, __VIDEO_DO_IOCTL);
__video_do_ioctl
struct Video_device *vfd = video_devdata (file);
According to the app's incoming cmd to get, set "some properties" V4l2_ctrl_handler use process:
__video_do_ioctl
struct Video_device *vfd = video_devdata (file); Case Vidioc_queryctrl:
{
struct V4l2_queryctrl *p = arg;

if (VFH && vfh->ctrl_handler)
ret = V4l2_queryctrl (Vfh->ctrl_handler, p);
else if (vfd->ctrl_handler)//Where is the setting? In Video_register_device
ret = V4l2_queryctrl (Vfd->ctrl_handler, p);
Find V4l2_ctrl in Ctrl_handler based on ID, return its value ...}

[18721.327983] USB 2-1: USB Disconnect, address 4
[18724.929301] USB 2-1: New full speed USB device using UHCI_HCD and address 5
[18725.196200] USB 2-1: Configuration #1 chosen from 1 choice
[18725.204999] uvcvideo:found UVC 1.00 device <unnamed> (1b3b:2977)
[18725.222065] INPUT:UVC Camera (1b3b:2977) as/devices/pci0000:00/0000:00:07.2/usb2/2-1/2-1:1.0/input/input7
[25252.578719] USB 2-1: USB Disconnect, address 5

By the above USB camera inserted DMESG printing information, search the UVC keyword to get the relevant code: UVC.DRIVER.C->uvc_driver Structure->video_register_device method.

Second, how to write V4l2 drive:

① Construction, Setup, registration: V4l2_device:v4l2_device_register, V4l2_device

② allocation: Video_device, Video_device_alloc

③ settings: A. Vfd->v4l2_dev

B. vfd:. fops = ***.open/read/write <-Upper app Call

. ioctl_ops <-driver V4l2_fops {open,read,write, "ioctl"}

C.app is set by the IOCTL to obtain information such as brightness.

Driver: V4l2_ctrl: property.

V4l2_ctrl_handler: Management ===> (1) Initialization: V4l2_ctrl_handler_init

(2) Set: V4L2_CTRL_NEW_STD, V4l2_ctrl_new_custom, set create V4l2_ctrl and join list.

(3) associated with Vdev: V4l2_dev.ctrl_handler = HDL

Video_dev, V4l2_dev.

The writing of the specific driver code will continue in the next article ....

Linux camera-driven learning: (i) V4L2_ Framework analysis

Related Article

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.