"Linux development" Linux V4L2 Drive Architecture Analysis and Development guide __linux

Source: Internet
Author: User

Analysis and Development Guide of Linux V4L2 driver architecture

Andrew: As we all know, Linux can be a flexible multi-level drive architecture to unify and abstract the interface, the lowest level of drive is always directly oriented to the hardware, and the highest levels of drive in Linux is divided into "character-oriented devices, block devices, network-oriented interface" Three categories to deal with, the first two types of drivers in the file system to form a similar file "virtual files", also known as "node nodes", these nodes have different names representing different devices, in the directory/dev under the unified management, system call functions such as open, close, Read, and so on, are similar to the operations of normal files, which are abstracted by the VFS (virtual file system layer). The device facing the network interface is still assigned the name of the device (such as eth0) in the Unix/linux system, but it is not mapped into the file system, and its drive invocation mode is also different from the file system call Open, read, etc.

VIDEO4LINUX2 (V4L2) is the middle drive layer for video devices in the Linux kernel, providing a common interface for Linux applications to access video devices, and provides a unified V4L2 framework for device driver development in Linux. In Linux systems, V4L2-driven video devices (such as camera, image capture card) node paths are typically videox,v4l2 drives in/dev to provide "character devices" for user space, with the main device number 81, and the second device number 0-63 for video devices. In addition, the secondary equipment number is 64-127 radio equipment, the secondary equipment is 192-223 of the teletext equipment, the secondary device number 224-255 is VBI equipment. V4L2-driven video devices are controlled by a variety of IOCTL invocations in user space and can be mapped using mmap memory.

Linux kernel Rough Architecture (Source: "Linux Device Drivers Edition 3" chaper1)

(Can't upload, reader to turn the book ...) )

V4L2 driver Architecture in Linux (Edit by Andrew):

You can see that the entire drive chain from video input hardware is abstracted into 3 levels:

1, the bottom is directly hardware-oriented, the driving framework provided by V4L2. It is noteworthy that this layer is often driven by the need for bus-driven support, such as the common USB2.0 bus.

2, the middle layer is v4l2. This is the second edition of V4L, which was first developed by Bill Dirks, and was ultimately driven by the revenue standard Kernel drive tree.

3, the upper layer is one of the three major drivers of the Linux kernel "character device drive layer", so the final video device in the file system in the/dev directory of the appearance of the character device, and is used by the application.

V4L2 is the second version of V4L. The original v4l was introduced into the late development cycle of the Linux kernel 2.1.x. VIDEO4LINUX2 fixes some design flaws and starts appearing in the 2.5.X kernel, and after the kernel 2.6.38, cancels the support for the first version v4l. The video4linux2 driver includes the compatibility mode of the VIDEO4LINUX1 application, but in practice, the support is incomplete and it is recommended that the V4L2 device use the V4L2 mode. The project's Dvb-wiki is now hosted on the LINUXTV (--->http://linuxtv.org/wiki/index.php/main_page) Web site.

To understand V4L2, there are several important documents that you must read:

1, source Documentation/video4linux directory of V4l2-framework.txt and VIDEOBUF

2, V4L2 official API document V4L2 API specification

3, the source code drivers/media/video directory of sample program VIVI.C (Virtual video driver, this code simulates a real video device v4l2 API).

V4L2 can support a variety of devices, and it can have several interfaces:

1. Video acquisition interface (Capture interface): The device for this application can be a high-frequency head or a camera. The original design of V4L2 is applied to this function.

2. Video output Interface (interface): A device that can drive a computer's peripheral video-image device, such as an output TV signal format.

3. Direct Transmission Video Overlay interface: Its main work is to send the signal from the video capture device directly to the output device, without having to go through the CPU of the system.

4. Video interval blanking signal interface (VBI interface): It allows applications to access the video signal of the transmission blanking period.

5. Radio Interface (radio interface): Used to process audio streams received from AM or FM HF head devices.

Andrew: It's worth noting that the kernel's underlying driver support is often something we care about. Recommend this blog post "Linux under the camera driver support situation" http://weijb0606.blog.163.com/blog/static/131286274201063152423963/here to make a brief summary:

1, because after the kernel 2.6.38 has fully supported the V4L2, and abandoned the first edition. Today (2012-11) has a kernel version of 3.3.6, and almost all video device drivers have transitioned to the new edition, so it should be developed in accordance with the V4L2 version API standard when developing programs.

2, the general market easy to buy "drive-free" camera is in line with the UVC standard, the kernel can support.

3, other types such as the ZC3XX, Sunplus series, GSPCA General can support, the kernel is also brought from.

4, the kernel supports all kinds of video device drivers, can be found under the file system directory/lib/modules/kernel%uname–r/kernel/driver/meida/video. Or when compiling the kernel, enumerate them.

Related websites:

http://linuxtv.org

The Http://linuxtv.org/wiki/index.php/Main_Page LINUXTV Web site is a defender of the v4l-(DVB) Digital video Broadcasting.

Http://www.ideasonboard.org/uvc/linux UVC Driver Homepage

http://mxhaard.free.fr/spca5xx.html GSPCA Driver Homepage

=========== some v4l2 drive layer details ==========

Note that these details are not called by the application, but are written by the driver, or some details about the V4L2 itself.

Some details about writing applications are "http://www.cnblogs.com/andrew-wang/archive/2012/11/14/2770701.html".

All V4L2 drivers have the following structure:

1 Each device contains the instance structure of the device state.

2 initialization and order of the child devices (if any).

3 Create V4L2 Device nodes (/dev/videox,/dev/vbix and/dev/radiox) and trace the specific data of the device node.

4 file handle specific structure, containing each file handle data;

5 Video buffer processing.

V4L2 Drive Core

V4L2 driver source code in the Drivers/media/video directory, the main core codes are:

V4L2-DEV.C                  //linux version 2 video capture interface, main structure video_device registration
v4l2-common.c               / The Linux operating system uses a lower-level operation of a device-structures/vectors Universal Video Device interface.
                            //This file will replace the videodev.c file with a regular kernel allocation.
v4l2-device.c               //v4l2 device support.
a generic framework for registering V4l2_device V4L22-IOCTL.C               //handling V4L2 IOCTL commands.
v4l2-subdev.c               //v4l2 Sub device
V4L2-MEM2MEM.C              //memory to memory for Linux and VIDEOBUF Video device framework. The auxiliary function of the device, using its source and destination Videobuf buffers.

header Files Linux/videodev2.h, Media/v4l2-common.h, Media/v4l2-device.h, Media/v4l2-ioctl.h, Media/v4l2-dev.h, media/ V4l2-ioctl.h and so on.

V4L2 related structural body

1.v4l2_device

struct v4l2_device{/
    * dev-> driver_data points to this structure. Note: Dev may be empty if no parent device is like ISA device. * *
      struct device *dev;
    /* To track the registration of Subdevs
      /struct list_head Subdevs;
    /* Lock This structure, the driver that can be used, and if the structure is embedded into a larger structure. * *
      spinlock_t lock;
    /* Unique device name, by default, driver name + Bus ID
      /char name[v4l2_device_name_size];
    /* Reports callback functions that are called by some child devices. */
      Void (*notify) (struct V4l2_subdev *sd,
                    unsigned int notification, void *arg);

;

V4l2_device Registration and cancellation

The first parameter ' dev ' is usually a pointer to a pci_dev struct device, but it is a rare dev null when an ISA device or a device creates multiple PCI devices, so Makingit cannot associate a particular parent V4l2_dev. You can also provide a notify () back-tone device that notifies you of events by calling. Depends on whether you need to set up a child device. Any notifications supported by a child device must be defined in the header file.

The V4l2_device structure is initialized when registering. If the Dev->driver_data field is empty, it is connected to the V4l2_dev.

V4l2_device_unregister (struct v4l2_device *v4l2_dev);

Logging off also automatically logs out all child devices for the device.

2.video_device (the most important and most common feature of V4L when making video programming)

The struct Video_device (v4l2_dev.h) that is used by the device node in the/dev directory is created.

struct Video_device {/* Device operation function/const struct v4l2_file_operations *fops;        /* Virtual File system * * struct device dev;        /* V4L Equipment * * struct CDEV *cdev;        /* Character equipment */struct device *parent;    * * Parent device/struct V4l2_device *v4l2_dev;
         * V4l2_device Parent *////* Device information * * Char name[32];
         int vfl_type;
         /* ' minor ' is set to-1 if the registration failed/int minor;
         U16 Num;
         /* Use Bitops to set/clear/test flags */unsigned long flags;
         /* attribute to differentiate multiple indexes on a physical device */INT index;   /* V4L2 file handle */spinlock_t fh_lock; /* Lock All V4L2_FHS * * struct list_head fh_list;                   /* List of struct V4L2_FH/int debug;         /* Activates debug level*//* Video Standard VARs * * v4l2_std_id tvnorms;    /* Supported TV norms * * v4l2_std_id current_norm;
/* Current Tvnorm * *         /* Released callback function * * 

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.