【正文】
s two shortages:when driving program is being designed, you cannot open multiple equipment at the same time。 then, the structure v4l2_device is added for each device, and the pointer directing to the structure v4l2_device is passed to v4l2_register_device(),which calls initialization functions of v4l2_device to initialize devices. Before calling v4l2_register_device(), the information of name, type, minor number and open function must be added to driver. When a driver is touched off by applications, thecontrol will firstly be delivered to the functions of videodev, videodev has responsibility to transform file or node structure pointer passed by applications to V4L2 structure pointer, and calls processing functions of V4L2 driver. 2) Image acquisition based on V4L2 The main steps of video capture of V4L2 are as follows: a) open video device v4l2_fd = open(V4L2_DEV_NODE, O_RDWR)。 fb_fd = open(FB_DEV_NODE, O_RDWR)。 b) device initialization Query the device properties and get function supported by VIDIOC_QUERYCAP。 allocate memory buffer in the kernel space and user space respectively through VIDIOC_REQBUFS and malloc(),and finally utilize mmap() for memory mapping. c) image acquisition and display Start and stop acquisition by VIDIOC_STREAMON and IDIOC_STREAMOFF. There are two ways for video acquisition: memory mapping and reading data directly from device. Image collection by double cache through mmap() is used here. Compile preview function v4l2_show_on_fb(v4l2_fd,fbmem, preview_frames) to preview the pictures. d) close video device 3) Close the device through close() . The flow chart of image acquisition based on V4L2 is as figure 2: There are two important system calls for V4L2 during video acquisition :ioctl() and mmap(). a) main itctl() mand ioctl() is a powerful function. It can control the I/O channels of equipment, set the format of video and frame, and also can inquiry current device properties. Main ioctl mands are shown as table I: Header files such as include/linux/ or can be added to the kernel to achieve the above function calls. b) memory mapping mmap() There are two ways to capture the video image: one is read() for reading directly, and the other is mmap() for memory mapping. Mmap() gives a chance for sharing memory between processes through mapping a mon file. After a general file is mapped to the address space of process, the file can be accessed by processes as ordinary memory, that is, the memory can be read and wrote directly, and there is no need to call read() and write(),it can accelerate I/O access. In the third step of image acquisition above, data copy is replaced by multiple cache for image collection through mmap() to improve efficiency. Two image buffers are created in the kernel space, when applications need images, data will be shared by mapping the kernel buffer to user space through mmap(). The process of video image collection using double frame buffer is as follows: First, request image buffer through VIDIOC_REQBUFS。 third, add the buffer to collection sequence beside driver by VIDIOC_QBUF。 fifth, VIDIOC_STREAMOFF is called to stop collecting image. At this point, the driver will au