Linux Kernel - media subsystem

The Linux Kernel Media Subsystems provide support for devices like webcams, streaming capture and output, analog TV, digital TV, AM/FM radio, Sofware Digital Radio (SDR), remote controllers and encoders/decoders for compressed video formats. It offers native support for a large number of drivers for commonly available PCI cards and USB devices, but the subsystems are also targeted towards Linux based set-top-boxes and embedded devices like mobile phones.linuxtv.org Here is a blog article that I have written for this topic: https://sebastianfricke.me/video-4-linux-the-basics/

35 flashcards · Computer Science · by initBasti

  1. What is the difference between video and photo capture? [Basics]

    A photo is a single image, while a video is a series of images. The series is perceived as motion through the amount frames, that are drawn per second. https://en.wikipedia.org/wiki/Frame_rate

  2. What is a digital image? [Basics]

    A raster map of pixels, with a fixed amount of rows and columns, where each pixel holds data about the brightness of a specific color. There are also vector images, where the different point of the image are mapped on a coordinate system, with lines an curves connecting different points. https://en.wikipedia.org/wiki/Digital_image

  3. What is a pixel? [Basics]

    The smallest controllable element of a picture on a screen (display devices) A single point within a raster image matrix is called a pixel (picture element). One pixel represents the intensity (usually a numeric value) of a given color. A synonym for the term sensel, which is a single photodiode inside of a image sensor https://en.wikipedia.org/wiki/Pixel

  4. What does the term "bit-depth" mean? [Basics]

    The amount of bits a pixel utilizes to represent the brightness of the colors red, green and blue. For example a bit depth of 1-bit, would result in only two possible colors: black or white.While a 4 bit image can already represent 16 colors, 8-bit images go up to 256 colors and the usual bit-depth for most high quality images: 24-bit has a total amount of over 16 million color combination. (8-bits are used for each red, green and blue)https://en.wikipedia.org/wiki/Color_depth

  5. What are 3 commonly used color models? [Basics]

    RGB (Red, Green & Blue) uses a combination of the brightness levels of these 3 base colors to represent colors, it's an additive color model, which means that a combination of the maximum values of the three base colors results in white. Used for most digital input & output devices. CMY(CMYK) (Cyan, Magenta & Yellow) works similar to RGB but works as a subtractive color model => the mix of the maximum values of the 3 base colors results in black, which is useful for printing as the background c…

  6. The reflected light-waves of the motive are focused onto an image sensor with a lens. The image sensor is made of millions of tiny photodiodes, which generate a small analog signal|electrical current through a light wave within a wave-length range that can be processed. On CMOS image sensors, that signal is directly amplified and send to one of the analog-to-digital converters. In order to capture colors, a color filter array|color-filter-array|cfa|CFA is placed above the image sensor in a spec…

    Overview over the process of creating an image [Basics]

  7. Describe an image sensor. [Basics]

    A device used to determine and transfer information of incoming light for the creation of images. It utilizes millions of tiny photodiodes, which are mostly made from silicon and covered by a specific color filter pattern in order to capture color information. Image source https://en.wikipedia.org/wiki/Image_sensor

  8. How does a photodiode within an image sensor work? [Basics]

    A photodiode is basically a combination of 2 types of semiconductors, a P(positive)-type that has a lack of electrons and a N(negative)-type, which is over saturated with electrons. The photodiode contains a depleted region, which is an area where no electron state can exist, by applying reverse bias. When a light beam hits the surface of the photodiode, a electron-hole pair is created and through the electric field, that was created duo to the depletion, the electron is pulled towards the posi…

  9. What are pros of CCD & CMOS image sensors? [Basics]

    CCD: + produces high quality videos and images with less noise CMOS: + cheap, fast, requires fewer parts than a CCD and needs less power https://en.wikipedia.org/wiki/Image_sensor

  10. What is a Bayer filter? [Basics]

    A type of color filter array, which is a set of red, green & blue filters placed above each of the image sensor's sensor elements. A red filter only allows light with a wavelength of red light to pass through, while a green filter does the same with green light and so on. The result is a mosaic of purely red, green and blue pixels, where 50% of the pixels are green, 25% are red and the remaining 25% are blue. That mosaic is then used during image processing for the debayering (demosaicing) proc…

  11. Explain the process of demosaicing / debayering an image. [Basics]

    Reconstruct a full-color image (red,green & blue color info for each pixel) from a color-filter array, where 50% of the pixels only contain green, 25% only contain red and 25% only contain blue color information (bayer-filter). This is achieved with interpolation, which is the approximation of missing values through nearby known values. Here an example: https://www.cse.iitb.ac.in/~ajitvr/CS663_Fall2016/demosaicing.pdf

  12. Name 5 techniques used to compress the size of a video. [Basics]

    Spatial compression (reuse color within a block of pixels with only the same-color in a single frame) Temporal compression (reuse large portions of certain key-frames throughout multiple frames, by only recording the changed pixels) Chroma sub-sampling (reduce the amount of color information stored in a frame by using less resolution for the color than the brightness) Bit-depth reduction (shrink the size of each pixel by decreasing the number of possible brightness levels for each color and the…

  13. Explain the meaning of the term binning, within the context of image processing? [Basics]

    Combining a cluster of pixels into a single pixel. For example: 2x2 binning combines a group of 4 pixels into a single 'superpixel'. The result is a reduced impact of read noise with a lower overall resolution. This might be useful when using a high read noise camera or when capturing at very dark sites. source

  14. What are I/B/P frames? [Basics]

    I-Frame (Intra-coded picture): Also called key frame is an image with all information upon which P- & B-Frames rely. (similar to an JPEG) P-Frame (Predicted picture): Contains the changes from the previous frame (I-Frame), B-Frame (Bidirectional predicted picture): Holds the differences between the current, the previous, and the next frame (even less data than a P-Frame) Makes a reference to future frames and therefore not useful for live streaming source

  15. Explain the term codec and how it works. [Basics]

    Short-form for compressor-decompressor There are lossless and lossy codecs. Lossless codecs cannot compress the size to the extent that lossy codecs are capable of, but they don't lose any information. We have hardware and software codecs, where hardware codecs tend to provide fast high-quality output and software codecs offer flexibility at a lower cost, with easier end-to-end encryption and archival functionality. Different codecs are preferred for different use-cases, examples are: capture c…

  16. Point out the difference between a stateful hardware codec and a stateless hardware codec. [Basics]

    Stateful hardware codec: Works like a black-box, you feed in a byte-stream of encoded data and get out the raw video data Clients do not have to maintain the decoded state of the frames neither do they have to keep the order requires firmware for the hardware to work (which is often proprietary) stateful decoder working principle diagram Stateless hardware codec: The client has to provide a sub-set of the byte-stream together with a reference frame and proper parameters to receive frames The ha…

  17. What is exposure and how is it controlled? [Basics]

    Exposure is the amount of light that hits the image sensor A short exposure corresponds to a darker image, while a longer exposure means brighter images with more motion blur Exposure is affected by 3 controls: Aperture: The size of the opening in front of the sensor Shutter speed: The length of time the sensor is exposed to the light (Most modern cameras don't use an actual shutter but instead make the sensor sensitive/insensitive to light) Gain (ISO): The amount of amplification that went int…

  18. What is gain and how is it used?

    Gain is the amplification of the analog signal captured by a photodiode before the conversion to a digital signal with the ADC (Analog to Digital Converter). It is used as a last resort to make a picture brighter, as it increases the noise of the signal along the way. Digital gain is applied on the digital signal after the ADC, which means that one loses resolution as the signal is simply multiplied (no more odd values). magiclantern.fm #reply3 PDF John Chouinard page 53

  19. Describe the terms horizontal/vertical timing and blanking. [Basics]

    (Also called frame blanking) Vertical blanking is the idle period after reading a frame and horizontal blanking is the idle period after reading a row, the terms stem from the past when a certain interval was required for the electron gun of a cathode ray tube to move back to the top of the screen or the start of the next line. Vertical timing is the total height of a camera's sensor photosensor array and vertical blanking is the difference between the vertical timing and the actively used heig…

  20. What is white balance/auto white balance (AWB)? How does it work? [Basics]

    Introduction Different lighting scenarios come with different color temperatures. A low color temperature causes a picture to be reddish and warm, while a high color temperature causes the image to seem more bluish and cold. Our eyes have the ability to automatically adjust to these scenarios and identify colors correctly. But cameras do not have that ability. Definition The act of white balance (WB) tries to adjust the color temperature of an image so that white in person is rendered as white…

  21. Describe how an application interacts with the Video4Linux API in order to receive a certain amount of frames from a capture device. [V4L2 Basics]

    At first, the application has to receive information about the state of the device, it's capabilities, and current settings (controls). After a quick check for an active selection of the capture area and the type of input source, it creates and initializes a set of capture buffers (usually 4). Subsequently, it will query the offset of those buffers and then queue all of those buffers into the incoming queue of the driver. Now, it has to start the streaming process, which causes the driver to ac…

  22. What are 3 different buffer types support by Video4Linux ? [V4L2 Basics]

    Video capture buffers (single- & multi-planar) (get data from the device) Video output buffers (single- & multi- planar) (send data to the device) Video overlay buffers (store captured frames directly into the memory of the graphics card) Metadata buffers (statistics data that can be used to fine-tune the settings depending on the circumstances brightness, white balance etc.) Buffers for analog video devices (VBA) Buffers for software defined Radio (SDR) www.kernel.org/doc

  23. An application that uses the V4L2 API, can listen (subscribe) to certain events, name 3 events that can occur while capturing/streaming video. [V4L2 Basics]

    End of stream reached A control (brightness, gamma, contrast etc.) was changed either at the device or through the flags Receiving a frame from the camera Vertical sync is performed Parameter change at runtime (resolution change, format change from the input etc.) Motion detected while capturing video Or a driver private event (custom) www.kernel.org/doc

  24. Which are the 3 available types of input sources found in the V4L2 API? [V4L2 Basics]

    Tuner Video device (for example a camera sensor or HDMI) Touch devices (touch screen, touch pad etc.) www.kernel.org/doc

  25. What are the 3 ways in which an user-space application can access the video data from the capture device? [V4L2 Basics]

    Memory mapped (v4l2-ctl option --stream-mmap): Use the mmap syscall to map the memory from the driver directly into user-space for access. User-space pointer (v4l2-ctl option --stream-user): Allocate the buffers into user-space only. DMA buffer (v4l2-ctl option --stream-dmabuf): Either create a DMA buffers for sharing with other applications/devices (exporter role) or use an existing DMA buffer (importer role) www.kernel.org/doc

  26. Describe what the media controller API is, what it is used for, and the general concept. [Media Controller Basics]

    Present the hardware device topology as a graph instead of a tree, to approach the increasingly more complex devices with functionalities that spread across multiple subsystems. The graph consists of multiple blocks called entities, each entity contains connection points (pads), which are linked to other entities through data links. www.kernel.org/doc Here is an example of a media controller topology (simple USB camera of my laptop): The 0's and 1's are the IDs of the pads for the entities the…

  27. What is the purpose of the V4L2-subdevice API? [V4L2 Basics]

    When a camera only exposes a single memory interface (/dev node), like for example a simple USB webcam, that device's camera pipeline is completely handled within the hardware. But there are camera pipelines, especially on SoC(System on a Chip) platforms, that allow more fine-grained control of the different parts of the pipeline. Example Rockchip RK3399 SoC: As you can see above the whole pipeline is created through the sub-devices: ISP, resizer, and the camera sensor. They are paired with mem…

  28. What is a 'Try' format and why is it used? [V4L2 Basics]

    When setting or getting formats at a V4L2 sub-device (G_FMT / S_FMT), applications can choose to set the which flag to V4L2_SUBDEV_FORMAT_TRY. In this case the application will not change the device configuration, but only the active format kept on the sub-device file handle. This is beneficial, when multiple applications try to work with the same sub-devices without interacting with each other, as they can query the limitations and negotiate parameters without interfering with other applicatio…

  29. All V4L drivers have the following structure: A struct for each device instance|device-instance|deviceinstance containing the device state|device-state|devicestate. A way of initializing and commanding sub-devices|subdevices|sub devices (if any). Creating V4L2 device nodes|device nodes|device-nodes and keeping track of device-node specific data|device-node data|dev node data. Filehandle|filehandle-specific structs containing per-filehandle data|Filehandle data; video buffer|Video buffer handlin…

    The basic structure that all Video 4 Linux drivers should stick to.

  30. Explain the difference between single- and multi-planar APIs. [V4L2 Basics]

    The multi-planar API is used when a video device requires the data for each frame to be split into multiple planes (sub-buffers). With the single-planar API, the data for a frame is provided by a single memory address. An application has to handle a certain number of VIDIOC ioctls differently depending on which API it uses. The multi-planar API uses different buffers and has to handle the different planes while queuing and dequeuing buffers. kernel.org/doc

  31. What is an image format and why do we need it? [V4L2 basics]

    An image format is a set of attributes, that describe how image data should be interpreted. It is required when drivers and applications want to exchange image data. Each format has a unique four-character code (FourCC), single and multiplanar formats are not sharing these codes. The attributes of an image format include information about the resolution, colorspace, bytes per line, specific FourCC, etc. There are different formats for different buffer types (capture, output, metadata..). kernel…

  32. Explain the differences between these two pixel-formats: bayer_bggr16le - bayer_gbrg16be [V4L2 Basics]

    Both have in common that they are raw uncompressed Bayer formats (RGB), with 10bit samples stored in 16bit words.[1] The differences are the Bayer order: BGGR vs GBRG and the suffix: le (little-endian) vs be (big-endian).[2] [1] Kernel doc [2] Endianness

  33. What is a MIPI CSI? [Hardware basics]

    A CSI is a camera serial interface, which means it defines how the camera has to interface with the host processor. MIPI is a global organization that creates various interface specifications, primarily for mobile devices. Wikipedia MIPI

  34. What is the difference between an RX-PHY and a TX-PHY? [Hardware basics]

    RX stands for receiver and TX means transmitter. This means an RX is used to receive image data from an external camera and send it to the host processor. And a TX is used to send image data from the host processor to an external display device. MIPI D-PHY article on edn.com

  35. Explain the term cross-talk for the area of image processing. [Advanced]

    It is a phenomenon, that is encountered especially on very dense image sensors. It is caused by Photon and electron leakages through optical refraction (change of direction of a light wave) and minority carriers*, which results in an interaction between neighboring pixels. The result of this behavior is increased color noise, which increases uncertainty about the color family and makes the image look muddy. *minority carriers (electrons are majority carriers and holes are minority carriers in n…