Understanding webcam 's Linux device drivers

13,237

Solution 1

The USB video class (UVC) is a specification to which USB webcams, etc., are supposed to conform. This way, they can be used on any system which implements support for UVC compliant devices.

V4L2 is the linux kernel video subsystem upon which the linux UVC implementation depends. In other words, in the kernel UVC support requires V4L2, but not the other way around.

The V4L2 API refers to a userspace programming interface, documented here.

Solution 2

It is amazing how much documentation you can find for Video4Linux2 - and none of it actually explains what Video4Linux is.

First, Video4Linux2 is a Linux driver framework. Framework drivers don't actually control devices directly. Instead, they provide an abstract model of some class of device, in this case video devices for applications to use. Driver frameworks provide three main benefits:

  1. Provide a unified API for applications to use with a very wide range of physical devices, whether connected by USB, PCIe, MIPI, Ethernet or other type of data transport bus
  2. In the kernel, frameworks contain the type of code that is needed in almost all of the device drivers of a particular class, thus greatly reducing the volume of disparate code
  3. In the kernel, frameworks provide a blueprint for writing new lower level drivers that actually control the hardware, thus simplifying driver development.

So, the V4L2 driver is a high-level driver that drives the UVC driver, that drives the USB driver that might be driving an even lower-level hardware driver.

This Matryoshka model is very common in the Linux kernel driver tree. V4L2 is one of the more complex examples because some camera devices require accessing large groups of sub-devices in several layers that control the camera and route the output of the camera among various components such as image processors.

You can still access the UVC driver directly from userspace using a device file and "ioctl" system calls, without going through the V4L2 driver, and you can still access the underlying USB driver directly from userspace using it's device file and "ioctl"s.

Being a general framework that provides functionality common to a wide range of devices, V4L2 doesn't provide you with the all of the functionality that the UVC driver could provide (assuming that your device actually provides more UVC functionality than is required to support V4L2).

So if you were to have a UVC device that does provide all of the functions specified in the UVC specification, then in order to actually use some of these functions you would need to access the UVC driver directly through a device file and "ioctl" system calls, assuming that the Linux kernel UVC driver in fact supports all of the UVC specification.

However, the meaning of

The uvcvideo driver implementation is adherent only to the V4L2 API

is that in the current Linux kernel UVC driver in fact does not provide any more UVC function support than is needed for V4L2.

V4L2 support in the kernel does not by itself provide UVC or USB support or lower-level USB hardware support.

Share:
13,237

Related videos on Youtube

dempap
Author by

dempap

Updated on September 18, 2022

Comments

  • dempap
    dempap over 1 year

    As far as I know, device driver is a part of SW that is able to communicate with a particular type of device that is attached to a computer.

    In case of a USB webcam, the responsible driver is UVC that supports any UVC compliant device. This means that enables OS or other computer program to access hardware functions without needing to know precise details of the hardware being used.

    For this reason, I installed UVC Linux device driver by running:

    opkg install kernel-module-uvcvideo
    

    Webcam has been recognised by Linux kernel: dev/video0. However, I still wasn't able to perform video streaming with FFmpeg, as I was missing V4L2 API. I installed V4L2, by configuring kernel.

    My queries are:

    • How UVC driver and V4L2 are linked together?
    • What is the purpose of V4L2 API?
    • If I haven't installed UVC first, it would be installed with V4L2?

    LinuxTV refers: The uvcvideo driver implementation is adherent only to the V4L2 API. This means that UVC is part of V4L2 API?

  • dempap
    dempap about 10 years
    If I understood, kernel without V4L2, can't support UVC compliant devices, even if uvc driver is installed.
  • goldilocks
    goldilocks about 10 years
    Yes. Drivers are part of the kernel; although they may be compiled as separate modules, these are compiled using a kernel source. If that's not the same source version as your running kernel, they will not work, and if they are not compiled from the same configuration, there may be significant inconsistencies. E.g., if you don't have the sound core (ALSA) built into the kernel (or available as a module), then a modular hardware driver for a sound card is useless.