# The Virtual Media Controller Driver (vimc)

_Peios Kernel / Administration / System administration / Media devices_

> The vimc driver emulates complex video hardware using the V4L2 API and the Media API. It has a capture device and three subdevices: sensor, debayer and scaler.

<a id="rst-the-virtual-media-controller-driver-vimc"></a>

<!-- SPDX-License-Identifier: GPL-2.0 -->

The vimc driver emulates complex video hardware using the V4L2 API and the Media API. It has a capture device and three subdevices: sensor, debayer and scaler.

<a id="rst-topology"></a>

## Topology

The topology is hardcoded, although you could modify it in vimc-core and recompile the driver to achieve your own topology. This is the default topology:

<a id="rst-vimc-topology-graph"></a>

```mermaid
flowchart TB
  n0["Sensor A<br/>/dev/v4l-subdev0<br/>pad 0"]
  n1["pad 0<br/>Debayer A<br/>/dev/v4l-subdev2<br/>pad 1"]
  n2["Raw Capture 0<br/>/dev/video0"]
  n3["Lens A<br/>/dev/v4l-subdev5<br/>pad"]
  n4["Sensor B<br/>/dev/v4l-subdev1<br/>pad 0"]
  n5["pad 0<br/>Debayer B<br/>/dev/v4l-subdev3<br/>pad 1"]
  n6["Raw Capture 1<br/>/dev/video1"]
  n7["Lens B<br/>/dev/v4l-subdev6<br/>pad"]
  n8["pad 0<br/>Scaler<br/>/dev/v4l-subdev5<br/>pad 1"]
  n9["RGB/YUV Input<br/>/dev/v4l-subdev4<br/>pad 0"]
  n10["RGB/YUV Capture<br/>/dev/video2"]
  n0 -->|"pad 0 → pad 0"| n1
  n0 -->|"from pad 0"| n2
  n0 --> n3
  n4 -->|"pad 0 → pad 0"| n5
  n4 -->|"from pad 0"| n6
  n4 --> n7
  n1 -->|"pad 1 → pad 0"| n8
  n5 -->|"pad 1 → pad 0"| n8
  n9 -->|"pad 0 → pad 0"| n8
  n8 -->|"from pad 1"| n10
  style n0 fill:green,color:#111
  style n1 fill:green,color:#111
  style n2 fill:yellow,color:#111
  style n3 fill:green,color:#111
  style n4 fill:green,color:#111
  style n5 fill:green,color:#111
  style n6 fill:yellow,color:#111
  style n7 fill:green,color:#111
  style n8 fill:green,color:#111
  style n9 fill:green,color:#111
  style n10 fill:yellow,color:#111
  linkStyle 0 stroke-width:3px
  linkStyle 1 stroke-width:3px
  linkStyle 3 stroke-width:3px
  linkStyle 4 stroke-width:3px
  linkStyle 7 stroke-dasharray:6 4
  linkStyle 8 stroke-dasharray:6 4
  linkStyle 9 stroke-width:3px
```

Diagram of the default media pipeline topology

Media pipeline graph on vimc

<a id="rst-configuring-the-topology"></a>

### Configuring the topology

Each subdevice will come with its default configuration (pixelformat, height, width, ...). One needs to configure the topology in order to match the configuration on each linked subdevice to stream frames through the pipeline. If the configuration doesn't match, the stream will fail. The `v4l-utils` package is a bundle of user-space applications, that comes with `media-ctl` and `v4l2-ctl` that can be used to configure the vimc configuration. This sequence of commands fits for the default topology:



```bash
media-ctl -d platform:vimc -V '"Sensor A":0[fmt:SBGGR8_1X8/640x480]'
media-ctl -d platform:vimc -V '"Debayer A":0[fmt:SBGGR8_1X8/640x480]'
media-ctl -d platform:vimc -V '"Scaler":0[fmt:RGB888_1X24/640x480]'
media-ctl -d platform:vimc -V '"Scaler":0[crop:(100,50)/400x150]'
media-ctl -d platform:vimc -V '"Scaler":1[fmt:RGB888_1X24/300x700]'
v4l2-ctl -z platform:vimc -d "RGB/YUV Capture" -v width=300,height=700
v4l2-ctl -z platform:vimc -d "Raw Capture 0" -v pixelformat=BA81
```

<a id="rst-subdevices"></a>

## Subdevices

Subdevices define the behavior of an entity in the topology. Depending on the subdevice, the entity can have multiple pads of type source or sink.

- **vimc-sensor:**

  Generates images in several formats using video test pattern generator. Exposes:

  - 1 Pad source

- **vimc-lens:**

  Ancillary lens for a sensor. Supports auto focus control. Linked to a vimc-sensor using an ancillary link. The lens supports FOCUS_ABSOLUTE control.



```bash
media-ctl -p
...
- entity 28: Lens A (0 pad, 0 link)
                type V4L2 subdev subtype Lens flags 0
                device node name /dev/v4l-subdev6
- entity 29: Lens B (0 pad, 0 link)
                type V4L2 subdev subtype Lens flags 0
                device node name /dev/v4l-subdev7
v4l2-ctl -d /dev/v4l-subdev7 -C focus_absolute
focus_absolute: 0
```

- **vimc-debayer:**

  Transforms images in bayer format into a non-bayer format. Exposes:

  - 1 Pad sink

  - 1 Pad source

- **vimc-scaler:**

  Re-size the image to meet the source pad resolution. E.g.: if the sync pad is configured to 360x480 and the source to 1280x720, the image will be stretched to fit the source resolution. Works for any resolution within the vimc limitations (even shrinking the image if necessary). Exposes:

  - 1 Pad sink

  - 1 Pad source

- **vimc-capture:**

  Exposes node /dev/videoX to allow userspace to capture the stream. Exposes:

  - 1 Pad sink

  - 1 Pad source

<a id="rst-module-options"></a>

## Module options

Vimc has a module parameter to configure the driver.

- `allocator=<unsigned int>`

  > memory allocator selection, default is 0. It specifies the way buffers will be allocated.
  >
  > > - 0: vmalloc
  > >
  > > - 1: dma-contig
