Linux Camera Driver Learning: (iv) uvc-camera driver Framework Analysis

Source: Internet
Author: User

Uvc:usb Video Class
UVC Drive: drivers\media\video\uvc\

UVC_DRIVER.C Analysis:
1. Usb_register (&uvc_driver.driver);
2. Uvc_probe
Uvc_register_video
Vdev = Video_device_alloc ();
Vdev->fops = &uvc_fops;
Video_register_device

Download the UVC specification in www.usb.org,
UVC 1.5 Class specification.pdf: Detailed description
Usb_video_example 1.5.pdf: There are examples

Controlled by Videocontrol interface,
Videostreaming interface to read video data,
VC contains a number of unit/terminal and other functional modules, can be accessed through these modules for control, such as brightness adjustment

Analyze the UVC driver invocation process:
const struct V4l2_file_operations uvc_fops = {
. Owner = This_module,
. open = Uvc_v4l2_open,
. Release = Uvc_v4l2_release,
. IOCTL = Uvc_v4l2_ioctl,
. Read = Uvc_v4l2_read,
. mmap = Uvc_v4l2_mmap,
. Poll = Uvc_v4l2_poll,
};

1. Open:
Uvc_v4l2_open
2. Vidioc_querycap//Video->streaming->type should be set when the descriptor is parsed when the device is enumerated
if (Video->streaming->type = = v4l2_buf_type_video_capture)
Cap->capabilities = V4l2_cap_video_capture
| v4l2_cap_streaming;
Else
Cap->capabilities = V4l2_cap_video_output
| v4l2_cap_streaming;
3. The VIDIOC_ENUM_FMT//format array should be set when the device is enumerated
format = &video->streaming->format[fmt->index];
4. Vidioc_g_fmt
Uvc_v4l2_get_format//USB camera supports multiple formats Fromat with multiple frames in each format (e.g. resolution)
struct Uvc_format *format = video->streaming->cur_format;
struct Uvc_frame *frame = video->streaming->cur_frame;
5. Vidioc_try_fmt
Uvc_v4l2_try_format
/* Check If the hardware supports the requested format. */

/* Find the closest image size. The distance between image sizes is
* The size in pixels of the non-overlapping regions between the
* Requested size and the frame-specified size.
*/
6. VIDIOC_S_FMT//Just save the parameters, not to the USB camera
Uvc_v4l2_set_format
Uvc_v4l2_try_format
Video->streaming->cur_format = format;
Video->streaming->cur_frame = frame;
7. Vidioc_reqbufs
Uvc_alloc_buffers
for (; nbuffers > 0;--nbuffers) {
MEM = vmalloc_32 (Nbuffers * bufsize);
if (mem! = NULL)
Break
}
8. Vidioc_querybuf
Uvc_query_buffer
__uvc_query_buffer
memcpy (V4l2_buf, &buf->buf, sizeof *v4l2_buf); Copy parameters
9. Mmap
Uvc_v4l2_mmap

Ten. Vidioc_qbuf
Uvc_queue_buffer
List_add_tail (&buf->stream, &queue->mainqueue);
List_add_tail (&buf->queue, &queue->irqqueue);

Vidioc_streamon.
Uvc_video_enable (video, 1)//Set the parameters to the hardware, and then start the camera
/* Commit the streaming parameters. */
Uvc_commit_video
Uvc_set_video_ctrl/* Set format Fromat, Frame */
ret = __uvc_query_ctrl (Video->dev/* which USB device */, set_cur, 0,
Video->streaming->intfnum/* Which interface: VS */,
Probe? Vs_probe_control:vs_commit_control, data, size,
Uvc_timeout_param);

/* Start: Initialize isochronous/bulk URBs and allocate transfer buffers. */
Uvc_init_video (video, Gfp_kernel);
Uvc_init_video_isoc/uvc_init_video_bulk
Urb->complete = Uvc_video_complete; (This function is called when the data is received, and it calls Video->decode (URB, video, buf); ==> uvc_video_decode_isoc/uvc_video_encode_bulk = Uvc_ Queue_next_buffer = wake_up (&buf->wait);)

Usb_submit_urb
Poll.
Uvc_v4l2_poll
Uvc_queue_poll
Poll_wait (file, &buf->wait, wait); Hibernate waiting for data

Vidioc_dqbuf.
Uvc_dequeue_buffer
List_del (&buf->stream);

Vidioc_streamoff.
Uvc_video_enable (video, 0);
Usb_kill_urb (URB);
Usb_free_urb (URB);

Analyze setting the Brightness process:
Ioctl:vidioc_s_ctrl
Uvc_ctrl_set
Uvc_ctrl_commit
__uvc_ctrl_commit (video, 0);
Uvc_ctrl_commit_entity (Video->dev, entity, rollback);
ret = Uvc_query_ctrl (dev/* which USB device */, Set_cur, Ctrl->entity->id/* Which one unit/terminal */,
Dev->intfnum/* Which interface: VC interface */, Ctrl->info->selector,
Uvc_ctrl_data (CTRL, Uvc_ctrl_data_current),
Ctrl->info->size);


Summarize:
1. UVC Device has 2 Interface:videocontrol Interface, videostreaming Interface
2. Videocontrol interface for control, such as setting brightness. It has multiple unit/terminal inside (unit/terminal is called entity in the program)
This can be accessed through a similar function:
ret = Uvc_query_ctrl (dev/* which USB device */, Set_cur, Ctrl->entity->id/* Which one unit/terminal */,
Dev->intfnum/* Which interface: VC interface */, Ctrl->info->selector,
Uvc_ctrl_data (CTRL, Uvc_ctrl_data_current),
Ctrl->info->size);
3. Videostreaming interface is used to obtain video data and can also be used to select Fromat/frame (vs may have multiple format, one format supports multiple frames, and frame is used to represent resolution information)
This can be accessed through a similar function:
ret = __uvc_query_ctrl (Video->dev/* which USB device */, set_cur, 0,
Video->streaming->intfnum/* Which interface: VS */,
Probe? Vs_probe_control:vs_commit_control, data, size,
Uvc_timeout_param);
4. When setting format, we simply use Video->streaming->format[fmt->index] and other data,
Where did this data come from?
Should be set when the device is enumerated, that is, when parsing its descriptor.

5. The focus of the UVC drive is:
The analysis of descriptors
Control of properties: set by Videocontrol interface
Format selection: set by Videostreaming interface
Data acquisition: obtained by Videostreaming Interface's URB

(---End---)

Linux Camera Driver Learning: (iv) uvc-camera driver 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.