# System and device interfaces

> System-call, protocol and device ABI reference.

---

# Kernel interfaces for userspace

_Peios Kernel / Userspace interfaces / System and device interfaces / Interface overview_

> Find system-call, device and protocol interface reference.

<a id="rst-the-linux-kernel-user-space-api-guide"></a>
<a id="rst-man-pages"></a>
<a id="rst-system-calls"></a>
<a id="rst-security-related-interfaces"></a>
<a id="rst-devices-and-i-o"></a>
<a id="rst-everything-else"></a>

This collection documents interfaces between userspace and the kernel.
General guides cover execution, synchronisation, memory and security controls;
device and protocol topics contain the detailed ABI references.

- **Execution and synchronisation:** [ELF](</kernel/userspace/userspace-api/execution/elf.md>),
  [Futexes](</kernel/userspace/userspace-api/execution/futex2.md>) and
  [Restartable sequences](</kernel/userspace/userspace-api/execution/rseq.md>).
- **Device access:** [ioctl conventions](</kernel/userspace/userspace-api/ioctl/index.md>),
  [GPIO](</kernel/userspace/userspace-api/gpio/index.md>) and
  [Netlink](</kernel/userspace/userspace-api/netlink/index.md>).
- **Media:** [Video4Linux](</kernel/userspace/userspace-api/media-v4l/v4l2.md>),
  [Digital television](</kernel/userspace/userspace-api/media-dvb/dvbapi.md>) and
  [Media controllers](</kernel/userspace/userspace-api/media-mediactl/media-controller.md>).

The media shelf separates video, television, HDMI CEC, media controllers and
remote-control interfaces. The [Kernel ABI catalogue](</kernel/administration/admin-guide/abi/abi.md>)
also documents exported attributes and their stability categories.

An interface described here may depend on configuration or a loaded driver;
its presence in the reference does not guarantee availability on every system.

---

# Linux-specific ELF idiosyncrasies

_Peios Kernel / Userspace interfaces / System and device interfaces / Execution and synchronisation_

> "First" program header is the one with the smallest offset in the file: e_phoff.

<a id="rst-linux-specific-elf-idiosyncrasies"></a>

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

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

## Definitions

"First" program header is the one with the smallest offset in the file: e_phoff.

"Last" program header is the one with the biggest offset in the file: e_phoff + (e_phnum - 1) \* sizeof(Elf_Phdr).

<a id="rst-pt-interp"></a>

## PT_INTERP

First PT_INTERP program header is used to locate the filename of ELF interpreter. Other PT_INTERP headers are ignored (since Linux 2.4.11).

<a id="rst-pt-gnu-stack"></a>

## PT_GNU_STACK

Last PT_GNU_STACK program header defines userspace stack executability (since Linux 2.6.6). Other PT_GNU_STACK headers are ignored.

<a id="rst-pt-gnu-property"></a>

## PT_GNU_PROPERTY

ELF interpreter's last PT_GNU_PROPERTY program header is used (since Linux 5.8). If interpreter doesn't have one, then the last PT_GNU_PROPERTY program header of an executable is used. Other PT_GNU_PROPERTY headers are ignored.

---

# Executability check

_Peios Kernel / Userspace interfaces / System and device interfaces / Execution and synchronisation_

> The AT_EXECVE_CHECK execveat(2) flag, and the SECBIT_EXEC_RESTRICT_FILE and SECBIT_EXEC_DENY_INTERACTIVE securebits are intended for script interpreters and dynamic linkers to enforce a consistent execution security policy handled by the…

<a id="rst-executability-check"></a>

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

<!-- Copyright © 2024 Microsoft Corporation -->

The `AT_EXECVE_CHECK` `execveat(2)` flag, and the `SECBIT_EXEC_RESTRICT_FILE` and `SECBIT_EXEC_DENY_INTERACTIVE` securebits are intended for script interpreters and dynamic linkers to enforce a consistent execution security policy handled by the kernel.  See the [samples/check-exec/inc.c](<https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/samples/check-exec/inc.c>) example.

Whether an interpreter should check these securebits or not depends on the security risk of running malicious scripts with respect to the execution environment, and whether the kernel can check if a script is trustworthy or not.  For instance, Python scripts running on a server can use arbitrary syscalls and access arbitrary files.  Such interpreters should then be enlighten to use these securebits and let users define their security policy. However, a JavaScript engine running in a web browser should already be sandboxed and then should not be able to harm the user's environment.

Script interpreters or dynamic linkers built for tailored execution environments (e.g. hardened Linux distributions or hermetic container images) could use `AT_EXECVE_CHECK` without checking the related securebits if backward compatibility is handled by something else (e.g. atomic update ensuring that all legitimate libraries are allowed to be executed).  It is then recommended for script interpreters and dynamic linkers to check the securebits at run time by default, but also to provide the ability for custom builds to behave like if `SECBIT_EXEC_RESTRICT_FILE` or `SECBIT_EXEC_DENY_INTERACTIVE` were always set to 1 (i.e. always enforce restrictions).

<a id="rst-at-execve-check"></a>

## AT_EXECVE_CHECK

Passing the `AT_EXECVE_CHECK` flag to `execveat(2)` only performs a check on a regular file and returns 0 if execution of this file would be allowed, ignoring the file format and then the related interpreter dependencies (e.g. ELF libraries, script's shebang).

Programs should always perform this check to apply kernel-level checks against files that are not directly executed by the kernel but passed to a user space interpreter instead.  All files that contain executable code, from the point of view of the interpreter, should be checked.  However the result of this check should only be enforced according to `SECBIT_EXEC_RESTRICT_FILE` or `SECBIT_EXEC_DENY_INTERACTIVE.`.

The main purpose of this flag is to improve the security and consistency of an execution environment to ensure that direct file execution (e.g. `./script.sh`) and indirect file execution (e.g. `sh script.sh`) lead to the same result.  For instance, this can be used to check if a file is trustworthy according to the caller's environment.

In a secure environment, libraries and any executable dependencies should also be checked.  For instance, dynamic linking should make sure that all libraries are allowed for execution to avoid trivial bypass (e.g. using `LD_PRELOAD`). For such secure execution environment to make sense, only trusted code should be executable, which also requires integrity guarantees.

To avoid race conditions leading to time-of-check to time-of-use issues, `AT_EXECVE_CHECK` should be used with `AT_EMPTY_PATH` to check against a file descriptor instead of a path.

<a id="rst-secbit-exec-restrict-file-and-secbit-exec-deny-interactive"></a>

## SECBIT_EXEC_RESTRICT_FILE and SECBIT_EXEC_DENY_INTERACTIVE

When `SECBIT_EXEC_RESTRICT_FILE` is set, a process should only interpret or execute a file if a call to `execveat(2)` with the related file descriptor and the `AT_EXECVE_CHECK` flag succeed.

This secure bit may be set by user session managers, service managers, container runtimes, sandboxer tools...  Except for test environments, the related `SECBIT_EXEC_RESTRICT_FILE_LOCKED` bit should also be set.

Programs should only enforce consistent restrictions according to the securebits but without relying on any other user-controlled configuration. Indeed, the use case for these securebits is to only trust executable code vetted by the system configuration (through the kernel), so we should be careful to not let untrusted users control this configuration.

However, script interpreters may still use user configuration such as environment variables as long as it is not a way to disable the securebits checks.  For instance, the `PATH` and `LD_PRELOAD` variables can be set by a script's caller.  Changing these variables may lead to unintended code executions, but only from vetted executable programs, which is OK.  For this to make sense, the system should provide a consistent security policy to avoid arbitrary code execution e.g., by enforcing a write xor execute policy.

When `SECBIT_EXEC_DENY_INTERACTIVE` is set, a process should never interpret interactive user commands (e.g. scripts).  However, if such commands are passed through a file descriptor (e.g. stdin), its content should be interpreted if a call to `execveat(2)` with the related file descriptor and the `AT_EXECVE_CHECK` flag succeed.

For instance, script interpreters called with a script snippet as argument should always deny such execution if `SECBIT_EXEC_DENY_INTERACTIVE` is set.

This secure bit may be set by user session managers, service managers, container runtimes, sandboxer tools...  Except for test environments, the related `SECBIT_EXEC_DENY_INTERACTIVE_LOCKED` bit should also be set.

Here is the expected behavior for a script interpreter according to combination of any exec securebits:

1. `SECBIT_EXEC_RESTRICT_FILE=0` and `SECBIT_EXEC_DENY_INTERACTIVE=0`

   Always interpret scripts, and allow arbitrary user commands (default).

   No threat, everyone and everything is trusted, but we can get ahead of potential issues thanks to the call to `execveat(2)` with `AT_EXECVE_CHECK` which should always be performed but ignored by the script interpreter.  Indeed, this check is still important to enable systems administrators to verify requests (e.g. with audit) and prepare for migration to a secure mode.

2. `SECBIT_EXEC_RESTRICT_FILE=1` and `SECBIT_EXEC_DENY_INTERACTIVE=0`

   Deny script interpretation if they are not executable, but allow arbitrary user commands.

   The threat is (potential) malicious scripts run by trusted (and not fooled) users.  That can protect against unintended script executions (e.g. `sh /tmp/*.sh`).  This makes sense for (semi-restricted) user sessions.

3. `SECBIT_EXEC_RESTRICT_FILE=0` and `SECBIT_EXEC_DENY_INTERACTIVE=1`

   Always interpret scripts, but deny arbitrary user commands.

   This use case may be useful for secure services (i.e. without interactive user session) where scripts' integrity is verified (e.g.  with IMA/EVM or dm-verity/IPE) but where access rights might not be ready yet.  Indeed, arbitrary interactive commands would be much more difficult to check.

4. `SECBIT_EXEC_RESTRICT_FILE=1` and `SECBIT_EXEC_DENY_INTERACTIVE=1`

   Deny script interpretation if they are not executable, and also deny any arbitrary user commands.

   The threat is malicious scripts run by untrusted users (but trusted code). This makes sense for system services that may only execute trusted scripts.

<!-- Links -->

<a id="rst-samples-check-exec-inc-c"></a>

---

# futex2

_Peios Kernel / Userspace interfaces / System and device interfaces / Execution and synchronisation_

> futex, or fast user mutex, is a set of syscalls to allow userspace to create performant synchronization mechanisms, such as mutexes, semaphores and conditional variables in userspace. C standard libraries, like glibc, uses it as a means to…

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

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

**Author:** André Almeida &lt;[andrealmeid@collabora.com](<mailto:andrealmeid@collabora.com>)&gt;

futex, or fast user mutex, is a set of syscalls to allow userspace to create performant synchronization mechanisms, such as mutexes, semaphores and conditional variables in userspace. C standard libraries, like glibc, uses it as a means to implement more high level interfaces like pthreads.

futex2 is a followup version of the initial futex syscall, designed to overcome limitations of the original interface.

<a id="rst-user-api"></a>

## User API

<a id="rst-futex-waitv"></a>

### `futex_waitv()`

Wait on an array of futexes, wake on any:



```text
futex_waitv(struct futex_waitv *waiters, unsigned int nr_futexes,
            unsigned int flags, struct timespec *timeout, clockid_t clockid)

struct futex_waitv {
      __u64 val;
      __u64 uaddr;
      __u32 flags;
      __u32 __reserved;
};
```

Userspace sets an array of struct futex_waitv (up to a max of 128 entries), using `uaddr` for the address to wait for, `val` for the expected value and `flags` to specify the type (e.g. private) and size of futex. `__reserved` needs to be 0, but it can be used for future extension. The pointer for the first item of the array is passed as `waiters`. An invalid address for `waiters` or for any `uaddr` returns `-EFAULT`.

If userspace has 32-bit pointers, it should do a explicit cast to make sure the upper bits are zeroed. `uintptr_t` does the tricky and it works for both 32/64-bit pointers.

`nr_futexes` specifies the size of the array. Numbers out of \[1, 128\] interval will make the syscall return `-EINVAL`.

The `flags` argument of the syscall needs to be 0, but it can be used for future extension.

For each entry in `waiters` array, the current value at `uaddr` is compared to `val`. If it's different, the syscall undo all the work done so far and return `-EAGAIN`. If all tests and verifications succeeds, syscall waits until one of the following happens:

- The timeout expires, returning `-ETIMEOUT`.

- A signal was sent to the sleeping task, returning `-ERESTARTSYS`.

- Some futex at the list was woken, returning the index of some waked futex.

An example of how to use the interface can be found at `tools/testing/selftests/futex/functional/futex_waitv.c`.

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

### Timeout

`struct timespec *timeout` argument is an optional argument that points to an absolute timeout. You need to specify the type of clock being used at `clockid` argument. `CLOCK_MONOTONIC` and `CLOCK_REALTIME` are supported. This syscall accepts only 64bit timespec structs.

<a id="rst-types-of-futex"></a>

### Types of futex

A futex can be either private or shared. Private is used for processes that shares the same memory space and the virtual address of the futex will be the same for all processes. This allows for optimizations in the kernel. To use private futexes, it's necessary to specify `FUTEX_PRIVATE_FLAG` in the futex flag. For processes that doesn't share the same memory space and therefore can have different virtual addresses for the same futex (using, for instance, a file-backed shared memory) requires different internal mechanisms to be get properly enqueued. This is the default behavior, and it works with both private and shared futexes.

Futexes can be of different sizes: 8, 16, 32 or 64 bits. Currently, the only supported one is 32 bit sized futex, and it need to be specified using `FUTEX_32` flag.

---

# Live Update uAPI

_Peios Kernel / Userspace interfaces / System and device interfaces / Execution and synchronisation_

> Live Update Orchestrator </core-api/liveupdate>

<a id="rst-live-update-uapi"></a>

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

**Author:** Pasha Tatashin &lt;[pasha.tatashin@soleen.com](<mailto:pasha.tatashin@soleen.com>)&gt;

<a id="rst-ioctl-interface"></a>

## ioctl interface


The IOCTL user-space control interface for the LUO subsystem.
It registers a character device, typically found at `/dev/liveupdate`,
which allows a userspace agent to manage the LUO state machine and its
associated resources, such as preservable file descriptors.

To ensure that the state machine is controlled by a single entity, access
to this device is exclusive: only one process is permitted to have
`/dev/liveupdate` open at any given time. Subsequent open attempts will
fail with -EBUSY until the first process closes its file descriptor.
This singleton model simplifies state management by preventing conflicting
commands from multiple userspace agents.


<a id="rst-ioctl-uapi"></a>

## ioctl uAPI


**General ioctl format**

The ioctl interface follows a general format to allow for extensibility. Each
ioctl is passed in a structure pointer as the argument providing the size of
the structure in the first u32. The kernel checks that any structure space
beyond what it understands is 0. This allows userspace to use the backward
compatible portion while consistently using the newer, larger, structures.

ioctls use a standard meaning for common errnos:

- ENOTTY: The IOCTL number itself is not supported at all
- E2BIG: The IOCTL number is supported, but the provided structure has
  non-zero in a part the kernel does not understand.
- EOPNOTSUPP: The IOCTL number is supported, and the structure is
  understood, however a known field has a value the kernel does not
  understand or support.
- EINVAL: Everything about the IOCTL was understood, but a field is not
  correct.
- ENOENT: A provided token does not exist.
- ENOMEM: Out of memory.
- EOVERFLOW: Mathematics overflowed.

As well as additional errnos, within specific ioctls.

#### <a id="c-struct-liveupdate_ioctl_create_session"></a>`struct liveupdate_ioctl_create_session`

ioctl(LIVEUPDATE_IOCTL_CREATE_SESSION)

**Definition**

```c
struct liveupdate_ioctl_create_session {
    __u32 size;
    __s32 fd;
    __u8 name[LIVEUPDATE_SESSION_NAME_LENGTH];
};
```

**Members**

- `size`: Input; sizeof(struct liveupdate_ioctl_create_session)
- `fd`: Output; The new file descriptor for the created session.
- `name`: Input; A null-terminated string for the session name, max
  length `LIVEUPDATE_SESSION_NAME_LENGTH` including termination
  character.

**Description**

Creates a new live update session for managing preserved resources.
This ioctl can only be called on the main /dev/liveupdate device.

**Return**

0 on success, negative error code on failure.

#### <a id="c-struct-liveupdate_ioctl_retrieve_session"></a>`struct liveupdate_ioctl_retrieve_session`

ioctl(LIVEUPDATE_IOCTL_RETRIEVE_SESSION)

**Definition**

```c
struct liveupdate_ioctl_retrieve_session {
    __u32 size;
    __s32 fd;
    __u8 name[LIVEUPDATE_SESSION_NAME_LENGTH];
};
```

**Members**

- `size`: Input; sizeof(struct liveupdate_ioctl_retrieve_session)
- `fd`: Output; The new file descriptor for the retrieved session.
- `name`: Input; A null-terminated string identifying the session to retrieve.
  The name must exactly match the name used when the session was
  created in the previous kernel.

**Description**

Retrieves a handle (a new file descriptor) for a preserved session by its
name. This is the primary mechanism for a userspace agent to regain control
of its preserved resources after a live update.

The userspace application provides the null-terminated `name` of a session
it created before the live update. If a preserved session with a matching
name is found, the kernel instantiates it and returns a new file descriptor
in the `fd` field. This new session FD can then be used for all file-specific
operations, such as restoring individual file descriptors with
LIVEUPDATE_SESSION_RETRIEVE_FD.

It is the responsibility of the userspace application to know the names of
the sessions it needs to retrieve. If no session with the given name is
found, the ioctl will fail with -ENOENT.

This ioctl can only be called on the main /dev/liveupdate device when the
system is in the LIVEUPDATE_STATE_UPDATED state.

#### <a id="c-struct-liveupdate_session_preserve_fd"></a>`struct liveupdate_session_preserve_fd`

ioctl(LIVEUPDATE_SESSION_PRESERVE_FD)

**Definition**

```c
struct liveupdate_session_preserve_fd {
    __u32 size;
    __s32 fd;
    __aligned_u64 token;
};
```

**Members**

- `size`: Input; sizeof(struct liveupdate_session_preserve_fd)
- `fd`: Input; The user-space file descriptor to be preserved.
- `token`: Input; An opaque, unique token for preserved resource.

**Description**

Holds parameters for preserving a file descriptor.

User sets the **fd** field identifying the file descriptor to preserve
(e.g., memfd, kvm, iommufd, VFIO). The kernel validates if this FD type
and its dependencies are supported for preservation. If validation passes,
the kernel marks the FD internally and *initiates the process* of preparing
its state for saving. The actual snapshotting of the state typically occurs
during the subsequent `LIVEUPDATE_IOCTL_PREPARE` execution phase, though
some finalization might occur during freeze.
On successful validation and initiation, the kernel uses the **token**
field with an opaque identifier representing the resource being preserved.
This token confirms the FD is targeted for preservation and is required for
the subsequent `LIVEUPDATE_SESSION_RETRIEVE_FD` call after the live update.

**Return**

0 on success (validation passed, preservation initiated), negative
error code on failure (e.g., unsupported FD type, dependency issue,
validation failed).

#### <a id="c-struct-liveupdate_session_retrieve_fd"></a>`struct liveupdate_session_retrieve_fd`

ioctl(LIVEUPDATE_SESSION_RETRIEVE_FD)

**Definition**

```c
struct liveupdate_session_retrieve_fd {
    __u32 size;
    __s32 fd;
    __aligned_u64 token;
};
```

**Members**

- `size`: Input; sizeof(struct liveupdate_session_retrieve_fd)
- `fd`: Output; The new file descriptor representing the fully restored
  kernel resource.
- `token`: Input; An opaque, token that was used to preserve the resource.

**Description**

Retrieve a previously preserved file descriptor.

User sets the **token** field to the value obtained from a successful
`LIVEUPDATE_IOCTL_FD_PRESERVE` call before the live update. On success,
the kernel restores the state (saved during the PREPARE/FREEZE phases)
associated with the token and populates the **fd** field with a new file
descriptor referencing the restored resource in the current (new) kernel.
This operation must be performed *before* signaling completion via
`LIVEUPDATE_IOCTL_FINISH`.

**Return**

0 on success, negative error code on failure (e.g., invalid token).

#### <a id="c-struct-liveupdate_session_finish"></a>`struct liveupdate_session_finish`

ioctl(LIVEUPDATE_SESSION_FINISH)

**Definition**

```c
struct liveupdate_session_finish {
    __u32 size;
    __u32 reserved;
};
```

**Members**

- `size`: Input; sizeof(struct liveupdate_session_finish)
- `reserved`: Input; Must be zero. Reserved for future use.

**Description**

Signals the completion of the restoration process for a retrieved session.
This is the final operation that should be performed on a session file
descriptor after a live update.

This ioctl must be called once all required file descriptors for the session
have been successfully retrieved (using `LIVEUPDATE_SESSION_RETRIEVE_FD`) and
are fully restored from the userspace and kernel perspective.

Upon success, the kernel releases its ownership of the preserved resources
associated with this session. This allows internal resources to be freed,
typically by decrementing reference counts on the underlying preserved
objects.

If this operation fails, the resources remain preserved in memory. Userspace
may attempt to call finish again. The resources will otherwise be reset
during the next live update cycle.

**Return**

0 on success, negative error code on failure.


<a id="rst-see-also"></a>

## See Also

- [Live Update Orchestrator](</kernel/internals/core-api/liveupdate.md>)

---

# NT synchronization primitive driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Execution and synchronisation_

> This page documents the user-space API for the ntsync driver.

<a id="rst-nt-synchronization-primitive-driver"></a>

This page documents the user-space API for the ntsync driver.

ntsync is a support driver for emulation of NT synchronization primitives by user-space NT emulators. It exists because implementation in user-space, using existing tools, cannot match Windows performance while offering accurate semantics. It is implemented entirely in software, and does not drive any hardware device.

This interface is meant as a compatibility tool only, and should not be used for general synchronization. Instead use generic, versatile interfaces such as futex(2) and poll(2).

<a id="rst-synchronization-primitives"></a>

## Synchronization primitives

The ntsync driver exposes three types of synchronization primitives: semaphores, mutexes, and events.

A semaphore holds a single volatile 32-bit counter, and a static 32-bit integer denoting the maximum value. It is considered signaled (that is, can be acquired without contention, or will wake up a waiting thread) when the counter is nonzero. The counter is decremented by one when a wait is satisfied. Both the initial and maximum count are established when the semaphore is created.

A mutex holds a volatile 32-bit recursion count, and a volatile 32-bit identifier denoting its owner. A mutex is considered signaled when its owner is zero (indicating that it is not owned). The recursion count is incremented when a wait is satisfied, and ownership is set to the given identifier.

A mutex also holds an internal flag denoting whether its previous owner has died; such a mutex is said to be abandoned. Owner death is not tracked automatically based on thread death, but rather must be communicated using `NTSYNC_IOC_MUTEX_KILL`. An abandoned mutex is inherently considered unowned.

Except for the "unowned" semantics of zero, the actual value of the owner identifier is not interpreted by the ntsync driver at all. The intended use is to store a thread identifier; however, the ntsync driver does not actually validate that a calling thread provides consistent or unique identifiers.

An event is similar to a semaphore with a maximum count of one. It holds a volatile boolean state denoting whether it is signaled or not. There are two types of events, auto-reset and manual-reset. An auto-reset event is designaled when a wait is satisfied; a manual-reset event is not. The event type is specified when the event is created.

Unless specified otherwise, all operations on an object are atomic and totally ordered with respect to other operations on the same object.

Objects are represented by files. When all file descriptors to an object are closed, that object is deleted.

<a id="rst-char-device"></a>

## Char device

The ntsync driver creates a single char device /dev/ntsync. Each file description opened on the device represents a unique instance intended to back an individual NT virtual machine. Objects created by one ntsync instance may only be used with other objects created by the same instance.

<a id="rst-ioctl-reference"></a>

## ioctl reference

All operations on the device are done through ioctls. There are four structures used in ioctl calls:



```text
struct ntsync_sem_args {
     __u32 count;
     __u32 max;
};

struct ntsync_mutex_args {
     __u32 owner;
     __u32 count;
};

struct ntsync_event_args {
     __u32 signaled;
     __u32 manual;
};

struct ntsync_wait_args {
     __u64 timeout;
     __u64 objs;
     __u32 count;
     __u32 owner;
     __u32 index;
     __u32 alert;
     __u32 flags;
     __u32 pad;
};
```

Depending on the ioctl, members of the structure may be used as input, output, or not at all.

The ioctls on the device file are as follows:





<a id="c-NTSYNC_IOC_CREATE_SEM"></a>

```c
NTSYNC_IOC_CREATE_SEM
```

Create a semaphore object. Takes a pointer to struct `ntsync_sem_args`, which is used as follows:


<table>
<tbody>
<tr>
<td>


`count`

</td>
<td>


Initial count of the semaphore.

</td>
</tr>
<tr>
<td>


`max`

</td>
<td>


Maximum count of the semaphore.

</td>
</tr>
</tbody>
</table>

Fails with `EINVAL` if `count` is greater than `max`. On success, returns a file descriptor the created semaphore.





<a id="c-NTSYNC_IOC_CREATE_MUTEX"></a>

```c
NTSYNC_IOC_CREATE_MUTEX
```

Create a mutex object. Takes a pointer to struct `ntsync_mutex_args`, which is used as follows:


<table>
<tbody>
<tr>
<td>


`count`

</td>
<td>


Initial recursion count of the mutex.

</td>
</tr>
<tr>
<td>


`owner`

</td>
<td>


Initial owner of the mutex.

</td>
</tr>
</tbody>
</table>

If `owner` is nonzero and `count` is zero, or if `owner` is zero and `count` is nonzero, the function fails with `EINVAL`. On success, returns a file descriptor the created mutex.





<a id="c-NTSYNC_IOC_CREATE_EVENT"></a>

```c
NTSYNC_IOC_CREATE_EVENT
```

Create an event object. Takes a pointer to struct `ntsync_event_args`, which is used as follows:


<table>
<tbody>
<tr>
<td>


`signaled`

</td>
<td>


If nonzero, the event is initially signaled, otherwise nonsignaled.

</td>
</tr>
<tr>
<td>


`manual`

</td>
<td>


If nonzero, the event is a manual-reset event, otherwise auto-reset.

</td>
</tr>
</tbody>
</table>

On success, returns a file descriptor the created event.

The ioctls on the individual objects are as follows:





<a id="c-NTSYNC_IOC_SEM_POST"></a>

```c
NTSYNC_IOC_SEM_POST
```

Post to a semaphore object. Takes a pointer to a 32-bit integer, which on input holds the count to be added to the semaphore, and on output contains its previous count.

If adding to the semaphore's current count would raise the latter past the semaphore's maximum count, the ioctl fails with `EOVERFLOW` and the semaphore is not affected. If raising the semaphore's count causes it to become signaled, eligible threads waiting on this semaphore will be woken and the semaphore's count decremented appropriately.





<a id="c-NTSYNC_IOC_MUTEX_UNLOCK"></a>

```c
NTSYNC_IOC_MUTEX_UNLOCK
```

Release a mutex object. Takes a pointer to struct `ntsync_mutex_args`, which is used as follows:


<table>
<tbody>
<tr>
<td>


`owner`

</td>
<td>


Specifies the owner trying to release this mutex.

</td>
</tr>
<tr>
<td>


`count`

</td>
<td>


On output, contains the previous recursion count.

</td>
</tr>
</tbody>
</table>

If `owner` is zero, the ioctl fails with `EINVAL`. If `owner` is not the current owner of the mutex, the ioctl fails with `EPERM`.

The mutex's count will be decremented by one. If decrementing the mutex's count causes it to become zero, the mutex is marked as unowned and signaled, and eligible threads waiting on it will be woken as appropriate.





<a id="c-NTSYNC_IOC_SET_EVENT"></a>

```c
NTSYNC_IOC_SET_EVENT
```

Signal an event object. Takes a pointer to a 32-bit integer, which on output contains the previous state of the event.

Eligible threads will be woken, and auto-reset events will be designaled appropriately.





<a id="c-NTSYNC_IOC_RESET_EVENT"></a>

```c
NTSYNC_IOC_RESET_EVENT
```

Designal an event object. Takes a pointer to a 32-bit integer, which on output contains the previous state of the event.





<a id="c-NTSYNC_IOC_PULSE_EVENT"></a>

```c
NTSYNC_IOC_PULSE_EVENT
```

Wake threads waiting on an event object while leaving it in an unsignaled state. Takes a pointer to a 32-bit integer, which on output contains the previous state of the event.

A pulse operation can be thought of as a set followed by a reset, performed as a single atomic operation. If two threads are waiting on an auto-reset event which is pulsed, only one will be woken. If two threads are waiting a manual-reset event which is pulsed, both will be woken. However, in both cases, the event will be unsignaled afterwards, and a simultaneous read operation will always report the event as unsignaled.





<a id="c-NTSYNC_IOC_READ_SEM"></a>

```c
NTSYNC_IOC_READ_SEM
```

Read the current state of a semaphore object. Takes a pointer to struct `ntsync_sem_args`, which is used as follows:


<table>
<tbody>
<tr>
<td>


`count`

</td>
<td>


On output, contains the current count of the semaphore.

</td>
</tr>
<tr>
<td>


`max`

</td>
<td>


On output, contains the maximum count of the semaphore.

</td>
</tr>
</tbody>
</table>





<a id="c-NTSYNC_IOC_READ_MUTEX"></a>

```c
NTSYNC_IOC_READ_MUTEX
```

Read the current state of a mutex object. Takes a pointer to struct `ntsync_mutex_args`, which is used as follows:


<table>
<tbody>
<tr>
<td>


`owner`

</td>
<td>


On output, contains the current owner of the mutex, or zero if the mutex is not currently owned.

</td>
</tr>
<tr>
<td>


`count`

</td>
<td>


On output, contains the current recursion count of the mutex.

</td>
</tr>
</tbody>
</table>

If the mutex is marked as abandoned, the function fails with `EOWNERDEAD`. In this case, `count` and `owner` are set to zero.





<a id="c-NTSYNC_IOC_READ_EVENT"></a>

```c
NTSYNC_IOC_READ_EVENT
```

Read the current state of an event object. Takes a pointer to struct `ntsync_event_args`, which is used as follows:


<table>
<tbody>
<tr>
<td>


`signaled`

</td>
<td>


On output, contains the current state of the event.

</td>
</tr>
<tr>
<td>


`manual`

</td>
<td>


On output, contains 1 if the event is a manual-reset event, and 0 otherwise.

</td>
</tr>
</tbody>
</table>





<a id="c-NTSYNC_IOC_KILL_OWNER"></a>

```c
NTSYNC_IOC_KILL_OWNER
```

Mark a mutex as unowned and abandoned if it is owned by the given owner. Takes an input-only pointer to a 32-bit integer denoting the owner. If the owner is zero, the ioctl fails with `EINVAL`. If the owner does not own the mutex, the function fails with `EPERM`.

Eligible threads waiting on the mutex will be woken as appropriate (and such waits will fail with `EOWNERDEAD`, as described below).





<a id="c-NTSYNC_IOC_WAIT_ANY"></a>

```c
NTSYNC_IOC_WAIT_ANY
```

Poll on any of a list of objects, atomically acquiring at most one. Takes a pointer to struct `ntsync_wait_args`, which is used as follows:


<table>
<tbody>
<tr>
<td>


`timeout`

</td>
<td>


Absolute timeout in nanoseconds. If `NTSYNC_WAIT_REALTIME` is set, the timeout is measured against the REALTIME clock; otherwise it is measured against the MONOTONIC clock. If the timeout is equal to or earlier than the current time, the function returns immediately without sleeping. If `timeout` is U64_MAX, the function will sleep until an object is signaled, and will not fail with `ETIMEDOUT`.

</td>
</tr>
<tr>
<td>


`objs`

</td>
<td>


Pointer to an array of `count` file descriptors (specified as an integer so that the structure has the same size regardless of architecture). If any object is invalid, the function fails with `EINVAL`.

</td>
</tr>
<tr>
<td>


`count`

</td>
<td>


Number of objects specified in the `objs` array. If greater than `NTSYNC_MAX_WAIT_COUNT`, the function fails with `EINVAL`.

</td>
</tr>
<tr>
<td>


`owner`

</td>
<td>


Mutex owner identifier. If any object in `objs` is a mutex, the ioctl will attempt to acquire that mutex on behalf of `owner`. If `owner` is zero, the ioctl fails with `EINVAL`.

</td>
</tr>
<tr>
<td>


`index`

</td>
<td>


On success, contains the index (into `objs`) of the object which was signaled. If `alert` was signaled instead, this contains `count`.

</td>
</tr>
<tr>
<td>


`alert`

</td>
<td>


Optional event object file descriptor. If nonzero, this specifies an "alert" event object which, if signaled, will terminate the wait. If nonzero, the identifier must point to a valid event.

</td>
</tr>
<tr>
<td>


`flags`

</td>
<td>


Zero or more flags. Currently the only flag is `NTSYNC_WAIT_REALTIME`, which causes the timeout to be measured against the REALTIME clock instead of MONOTONIC.

</td>
</tr>
<tr>
<td>


`pad`

</td>
<td>


Unused, must be set to zero.

</td>
</tr>
</tbody>
</table>

This function attempts to acquire one of the given objects. If unable to do so, it sleeps until an object becomes signaled, subsequently acquiring it, or the timeout expires. In the latter case the ioctl fails with `ETIMEDOUT`. The function only acquires one object, even if multiple objects are signaled.

A semaphore is considered to be signaled if its count is nonzero, and is acquired by decrementing its count by one. A mutex is considered to be signaled if it is unowned or if its owner matches the `owner` argument, and is acquired by incrementing its recursion count by one and setting its owner to the `owner` argument. An auto-reset event is acquired by designaling it; a manual-reset event is not affected by acquisition.

Acquisition is atomic and totally ordered with respect to other operations on the same object. If two wait operations (with different `owner` identifiers) are queued on the same mutex, only one is signaled. If two wait operations are queued on the same semaphore, and a value of one is posted to it, only one is signaled.

If an abandoned mutex is acquired, the ioctl fails with `EOWNERDEAD`. Although this is a failure return, the function may otherwise be considered successful. The mutex is marked as owned by the given owner (with a recursion count of 1) and as no longer abandoned, and `index` is still set to the index of the mutex.

The `alert` argument is an "extra" event which can terminate the wait, independently of all other objects.

It is valid to pass the same object more than once, including by passing the same event in the `objs` array and in `alert`. If a wakeup occurs due to that object being signaled, `index` is set to the lowest index corresponding to that object.

The function may fail with `EINTR` if a signal is received.





<a id="c-NTSYNC_IOC_WAIT_ALL"></a>

```c
NTSYNC_IOC_WAIT_ALL
```

Poll on a list of objects, atomically acquiring all of them. Takes a pointer to struct `ntsync_wait_args`, which is used identically to `NTSYNC_IOC_WAIT_ANY`, except that `index` is always filled with zero on success if not woken via alert.

This function attempts to simultaneously acquire all of the given objects. If unable to do so, it sleeps until all objects become simultaneously signaled, subsequently acquiring them, or the timeout expires. In the latter case the ioctl fails with `ETIMEDOUT` and no objects are modified.

Objects may become signaled and subsequently designaled (through acquisition by other threads) while this thread is sleeping. Only once all objects are simultaneously signaled does the ioctl acquire them and return. The entire acquisition is atomic and totally ordered with respect to other operations on any of the given objects.

If an abandoned mutex is acquired, the ioctl fails with `EOWNERDEAD`. Similarly to `NTSYNC_IOC_WAIT_ANY`, all objects are nevertheless marked as acquired. Note that if multiple mutex objects are specified, there is no way to know which were marked as abandoned.

As with "any" waits, the `alert` argument is an "extra" event which can terminate the wait. Critically, however, an "all" wait will succeed if all members in `objs` are signaled, *or* if `alert` is signaled. In the latter case `index` will be set to `count`. As with "any" waits, if both conditions are filled, the former takes priority, and objects in `objs` will be acquired.

Unlike `NTSYNC_IOC_WAIT_ANY`, it is not valid to pass the same object more than once, nor is it valid to pass the same object in `objs` and in `alert`. If this is attempted, the function fails with `EINVAL`.

---

# Restartable Sequences

_Peios Kernel / Userspace interfaces / System and device interfaces / Execution and synchronisation_

> Restartable Sequences allow to register a per thread userspace memory area to be used as an ABI between kernel and userspace for three purposes:

<a id="rst-restartable-sequences"></a>

Restartable Sequences allow to register a per thread userspace memory area to be used as an ABI between kernel and userspace for three purposes:

> - userspace restartable sequences
>
> - quick access to read the current CPU number, node ID from userspace
>
> - scheduler time slice extensions

<a id="rst-restartable-sequences-per-cpu-atomics"></a>

## Restartable sequences (per-cpu atomics)

Restartable sequences allow userspace to perform update operations on per-cpu data without requiring heavyweight atomic operations. The actual ABI is unfortunately only available in the code and selftests.

<a id="rst-quick-access-to-cpu-number-node-id"></a>

## Quick access to CPU number, node ID

Allows to implement per CPU data efficiently. Documentation is in code and selftests. :(

<a id="rst-scheduler-time-slice-extensions"></a>

## Scheduler time slice extensions

This allows a thread to request a time slice extension when it enters a critical section to avoid contention on a resource when the thread is scheduled out inside of the critical section.

The prerequisites for this functionality are:

> - Enabled in Kconfig
>
> - Enabled at boot time (default is enabled)
>
> - A rseq userspace pointer has been registered for the thread

The thread has to enable the functionality via prctl(2):



```text
prctl(PR_RSEQ_SLICE_EXTENSION, PR_RSEQ_SLICE_EXTENSION_SET,
      PR_RSEQ_SLICE_EXT_ENABLE, 0, 0);
```

prctl() returns 0 on success or otherwise with the following error codes:


<table>
<thead>
<tr>
<th>


Errorcode

</th>
<th>


Meaning

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


EINVAL

</td>
<td>


Functionality not available or invalid function arguments. Note: arg4 and arg5 must be zero

</td>
</tr>
<tr>
<td>


ENOTSUPP

</td>
<td>


Functionality was disabled on the kernel command line

</td>
</tr>
<tr>
<td>


ENXIO

</td>
<td>


Available, but no rseq user struct registered

</td>
</tr>
</tbody>
</table>

The state can be also queried via prctl(2):



```text
prctl(PR_RSEQ_SLICE_EXTENSION, PR_RSEQ_SLICE_EXTENSION_GET, 0, 0, 0);
```

prctl() returns `PR_RSEQ_SLICE_EXT_ENABLE` when it is enabled or 0 if disabled. Otherwise it returns with the following error codes:


<table>
<thead>
<tr>
<th>


Errorcode

</th>
<th>


Meaning

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


EINVAL

</td>
<td>


Functionality not available or invalid function arguments. Note: arg3 and arg4 and arg5 must be zero

</td>
</tr>
</tbody>
</table>

The availability and status is also exposed via the rseq ABI struct flags field via the `RSEQ_CS_FLAG_SLICE_EXT_AVAILABLE_BIT` and the `RSEQ_CS_FLAG_SLICE_EXT_ENABLED_BIT`. These bits are read-only for user space and only for informational purposes.

If the mechanism was enabled via prctl(), the thread can request a time slice extension by setting rseq::slice_ctrl::request to 1. If the thread is interrupted and the interrupt results in a reschedule request in the kernel, then the kernel can grant a time slice extension and return to userspace instead of scheduling out. The length of the extension is determined by debugfs:rseq/slice_ext_nsec. The default value is 5 usec; which is the minimum value. It can be incremented to 50 usecs, however doing so can/will affect the minimum scheduling latency.

Any proposed changes to this default will have to come with a selftest and rseq-slice-hist.py output that shows the new value has merrit.

The kernel indicates the grant by clearing rseq::slice_ctrl::request and setting rseq::slice_ctrl::granted to 1. If there is a reschedule of the thread after granting the extension, the kernel clears the granted bit to indicate that to userspace.

If the request bit is still set when the leaving the critical section, userspace can clear it and continue.

If the granted bit is set, then userspace invokes rseq_slice_yield(2) when leaving the critical section to relinquish the CPU. The kernel enforces this by arming a timer to prevent misbehaving userspace from abusing this mechanism.

If both the request bit and the granted bit are false when leaving the critical section, then this indicates that a grant was revoked and no further action is required by userspace.

The required code flow is as follows:



```text
rseq->slice_ctrl.request = 1;
barrier();  // Prevent compiler reordering
critical_section();
barrier();  // Prevent compiler reordering
rseq->slice_ctrl.request = 0;
if (rseq->slice_ctrl.granted)
    rseq_slice_yield();
```

As all of this is strictly CPU local, there are no atomicity requirements. Checking the granted state is racy, but that cannot be avoided at all:



```text
if (rseq->slice_ctrl.granted)
  -> Interrupt results in schedule and grant revocation
    rseq_slice_yield();
```

So there is no point in pretending that this might be solved by an atomic operation.

If the thread issues a syscall other than rseq_slice_yield(2) within the granted timeslice extension, the grant is also revoked and the CPU is relinquished immediately when entering the kernel. This is required as syscalls might consume arbitrary CPU time until they reach a scheduling point when the preemption model is either NONE or VOLUNTARY and therefore might exceed the grant by far.

The preferred solution for user space is to use rseq_slice_yield(2) which is side effect free. The support for arbitrary syscalls is required to support onion layer architectured applications, where the code handling the critical section and requesting the time slice extension has no control over the code within the critical section.

The kernel enforces flag consistency and terminates the thread with SIGSEGV if it detects a violation.

---

# unshare system call

_Peios Kernel / Userspace interfaces / System and device interfaces / Execution and synchronisation_

> Unsharing process resources and namespaces in the Peios kernel.

<a id="rst-unshare-system-call"></a>

`unshare()` separates selected parts of the calling task's context from other
tasks that share them. It does not create a new process or grant native authority.

<a id="rst-change-log"></a>

## Document history

Adapted from Janak Desai's January 2006 design document for the implementation
in the Peios kernel. The old proposal's address-space splitting and
unimplemented-System-V-semaphore descriptions do not describe this kernel.

<a id="rst-contents"></a>
<a id="rst-overview"></a>

## Overview

`clone()` selects resources to share when creating a task. `unshare()` lets an
existing task stop sharing selected resources, subject to flag combinations,
task state, namespace configuration and authorization checks. An unshared file
descriptor table still refers to the same open file descriptions: it does not
reopen files, reset their positions or obtain new KACS handle grants.

<a id="rst-benefits"></a>
<a id="rst-per-security-context-namespaces"></a>

## Private filesystem views

A private mount namespace permits changes to a task's mount view without
necessarily changing the original namespace. Mount propagation settings can
still propagate events between namespaces. Creating the namespace and making
mounts within it are separate operations with their own authorization.

Peios has a native mount-namespace creation path. When the requested nsproxy
namespace flags select only `CLONE_NEWNS`, `kernel/nsproxy.c` does not impose
its generic `CAP_SYS_ADMIN` gate. Native mount-namespace checks still apply.
Adding another nsproxy namespace type, such as `CLONE_NEWNET` or `CLONE_NEWIPC`,
retains that gate, interpreted as enabled `SeTcbPrivilege`. A new user namespace
does not create native token privileges. See
[Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>).

<a id="rst-unsharing-of-virtual-memory-and-or-open-files"></a>

## File tables and address spaces

`CLONE_FILES` can copy a shared file descriptor table. `CLONE_FS` can separate
the root directory, working directory and umask context. In contrast,
`CLONE_VM`, `CLONE_SIGHAND` and `CLONE_THREAD` do not split an actively shared
address space, signal-handler table or thread group. They are accepted only
when the corresponding sharing checks establish there is nothing to split;
otherwise the call fails with `EINVAL`.

<a id="rst-cost"></a>
<a id="rst-requirements"></a>

## Allocation and lifetime

The implementation prepares replacement contexts before publishing them to
the current task. Allocation can fail. Contexts still shared with other tasks
remain alive through their references. Operations must obey the relevant task,
filesystem-context, namespace and credential locking rules.

<a id="rst-functional-specification"></a>

## Interface

```c
#define _GNU_SOURCE
#include <sched.h>

int unshare(int flags);
```

The libc interface returns zero on success, or `-1` with `errno` on failure.
Flags include:

| Flag | Effect or constraint |
| --- | --- |
| `CLONE_FILES` | Separate the file descriptor table if shared. |
| `CLONE_FS` | Separate filesystem context if needed. |
| `CLONE_NEWNS` | Create a mount namespace; implies `CLONE_FS`. |
| `CLONE_NEWUSER` | Create a user namespace; implies `CLONE_THREAD` and `CLONE_FS`, with user-namespace and single-thread checks. |
| `CLONE_NEWUTS`, `CLONE_NEWIPC`, `CLONE_NEWNET`, `CLONE_NEWCGROUP` | Request the corresponding namespace, subject to configuration and authorization. |
| `CLONE_NEWPID`, `CLONE_NEWTIME` | Change the namespace context used for subsequent children; these do not move the caller into the new PID/time namespace. |
| `CLONE_SYSVSEM` | Detach from the shared System V semaphore undo list. `CLONE_NEWIPC` also detaches it. |
| `CLONE_VM` | Implies `CLONE_SIGHAND`; requires an already single-threaded, unshared context. |
| `CLONE_SIGHAND` | Implies `CLONE_THREAD`; cannot split a shared signal-handler table. |
| `CLONE_THREAD` | Requires an empty thread group apart from the caller. |

Unknown or incompatible flags and unsupported sharing requests can return
`EINVAL`. Authorization failures can return `EPERM` or a native denial such as
`EACCES`; allocation failures can return `ENOMEM`. Namespace creation also has
its own configuration, nesting and resource limits, so this is not an exhaustive
error list. UID 0 alone is not the native authorization rule.

<a id="rst-high-level-design"></a>
<a id="rst-low-level-design"></a>
<a id="rst-reorganization-of-copy-functions"></a>

## Implementation

`ksys_unshare()` in `kernel/fork.c` normalizes implied flags, checks supported
combinations, prepares filesystem/file-table changes, then prepares the user
namespace and nsproxy. Namespace-specific creation code runs its own checks.
The function also prepares credential accounting before publishing new state.

<a id="rst-unshare-system-call-service-function"></a>

On success it detaches semaphore state when requested, handles shared-memory
state for a new IPC namespace, installs the nsproxy, swaps the filesystem and
file-table pointers under the required locks, and commits new user-namespace
credentials. It then releases old or unused references. Failure paths release
prepared state rather than leaving partially installed replacement contexts.

<a id="rst-unshare-helper-functions"></a>

`unshare_fs()`, `unshare_fd()`, `unshare_userns()` and
`unshare_nsproxy_namespaces()` prepare the relevant changes. Unlike the original
design proposal, `CLONE_SYSVSEM` is implemented. No helper clones a live shared
address space to implement `CLONE_VM` unsharing.

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

Architecture syscall tables expose the existing `unshare` syscall; adding a
new resource flag does not require a new syscall number.

<a id="rst-test-specification"></a>

## Validation considerations

Test actual resource separation, implied flags, invalid combinations, failure
cleanup and namespace limits. For file tables, distinguish an independent table
from the shared open file descriptions it contains. For Peios, include native
authorization denials and the difference between mount-only namespace requests
and combined namespace requests. These are review requirements, not a report
that this documentation change ran runtime tests.

<a id="rst-future-work"></a>

## Unsupported sharing changes

Splitting a live thread group, shared signal-handler table or shared address
space is not implemented by `unshare()`. Programs requiring a separate address
space should use an appropriate process-creation interface instead.

---

# Exchanging pixel buffers

_Peios Kernel / Userspace interfaces / System and device interfaces / Memory and device access_

> As originally designed, the Linux graphics subsystem had extremely limited support for sharing pixel-buffer allocations between processes, devices, and subsystems. Modern systems require extensive integration between all three classes;…

<a id="rst-exchanging-pixel-buffers"></a>

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

<!-- Copyright 2021-2023 Collabora Ltd. -->

As originally designed, the Linux graphics subsystem had extremely limited support for sharing pixel-buffer allocations between processes, devices, and subsystems. Modern systems require extensive integration between all three classes; this document details how applications and kernel subsystems should approach this sharing for two-dimensional image data.

It is written with reference to the DRM subsystem for GPU and display devices, V4L2 for media devices, and also to Vulkan, EGL and Wayland, for userspace support, however any other subsystems should also follow this design and advice.

<a id="rst-glossary-of-terms"></a>

## Glossary of terms



- **<a id="rst-term-image"></a>image:**

  Conceptually a two-dimensional array of pixels. The pixels may be stored in one or more memory buffers. Has width and height in pixels, pixel format and modifier (implicit or explicit).

- **<a id="rst-term-row"></a>row:**

  A span along a single y-axis value, e.g. from co-ordinates (0,100) to (200,100).

- **<a id="rst-term-scanline"></a>scanline:**

  Synonym for row.

- **<a id="rst-term-column"></a>column:**

  A span along a single x-axis value, e.g. from co-ordinates (100,0) to (100,100).

- **<a id="rst-term-memory-buffer"></a>memory buffer:**

  A piece of memory for storing (parts of) pixel data. Has stride and size in bytes and at least one handle in some API. May contain one or more planes.

- **<a id="rst-term-plane"></a>plane:**

  A two-dimensional array of some or all of an image's color and alpha channel values.

- **<a id="rst-term-pixel"></a>pixel:**

  A picture element. Has a single color value which is defined by one or more color channels values, e.g. R, G and B, or Y, Cb and Cr. May also have an alpha value as an additional channel.

- **<a id="rst-term-pixel-data"></a>pixel data:**

  Bytes or bits that represent some or all of the color/alpha channel values of a pixel or an image. The data for one pixel may be spread over several planes or memory buffers depending on format and modifier.

- **<a id="rst-term-color-value"></a>color value:**

  A tuple of numbers, representing a color. Each element in the tuple is a color channel value.

- **<a id="rst-term-color-channel"></a>color channel:**

  One of the dimensions in a color model. For example, RGB model has channels R, G, and B. Alpha channel is sometimes counted as a color channel as well.

- **<a id="rst-term-pixel-format"></a>pixel format:**

  A description of how pixel data represents the pixel's color and alpha values.

- **<a id="rst-term-modifier"></a>modifier:**

  A description of how pixel data is laid out in memory buffers.

- **<a id="rst-term-alpha"></a>alpha:**

  A value that denotes the color coverage in a pixel. Sometimes used for translucency instead.

- **<a id="rst-term-stride"></a>stride:**

  A value that denotes the relationship between pixel-location co-ordinates and byte-offset values. Typically used as the byte offset between two pixels at the start of vertically-consecutive tiling blocks. For linear layouts, the byte offset between two vertically-adjacent pixels. For non-linear formats the stride must be computed in a consistent way, which usually is done as-if the layout was linear.

- **<a id="rst-term-pitch"></a>pitch:**

  Synonym for stride.

<a id="rst-formats-and-modifiers"></a>

## Formats and modifiers

Each buffer must have an underlying format. This format describes the color values provided for each pixel. Although each subsystem has its own format descriptions (e.g. V4L2 and fbdev), the `DRM_FORMAT_*` tokens should be reused wherever possible, as they are the standard descriptions used for interchange. These tokens are described in the `drm_fourcc.h` file, which is a part of DRM's uAPI.

Each `DRM_FORMAT_*` token describes the translation between a pixel co-ordinate in an image, and the color values for that pixel contained within its memory buffers. The number and type of color channels are described: whether they are RGB or YUV, integer or floating-point, the size of each channel and their locations within the pixel memory, and the relationship between color planes.

For example, `DRM_FORMAT_ARGB8888` describes a format in which each pixel has a single 32-bit value in memory. Alpha, red, green, and blue, color channels are available at 8-bit precision per channel, ordered respectively from most to least significant bits in little-endian storage. `DRM_FORMAT_*` is not affected by either CPU or device endianness; the byte pattern in memory is always as described in the format definition, which is usually little-endian.

As a more complex example, `DRM_FORMAT_NV12` describes a format in which luma and chroma YUV samples are stored in separate planes, where the chroma plane is stored at half the resolution in both dimensions (i.e. one U/V chroma sample is stored for each 2x2 pixel grouping).

Format modifiers describe a translation mechanism between these per-pixel memory samples, and the actual memory storage for the buffer. The most straightforward modifier is `DRM_FORMAT_MOD_LINEAR`, describing a scheme in which each plane is laid out row-sequentially, from the top-left to the bottom-right corner. This is considered the baseline interchange format, and most convenient for CPU access.

Modern hardware employs much more sophisticated access mechanisms, typically making use of tiled access and possibly also compression. For example, the `DRM_FORMAT_MOD_VIVANTE_TILED` modifier describes memory storage where pixels are stored in 4x4 blocks arranged in row-major ordering, i.e. the first tile in a plane stores pixels (0,0) to (3,3) inclusive, and the second tile in a plane stores pixels (4,0) to (7,3) inclusive.

Some modifiers may modify the number of planes required for an image; for example, the `I915_FORMAT_MOD_Y_TILED_CCS` modifier adds a second plane to RGB formats in which it stores data about the status of every tile, notably including whether the tile is fully populated with pixel data, or can be expanded from a single solid color.

These extended layouts are highly vendor-specific, and even specific to particular generations or configurations of devices per-vendor. For this reason, support of modifiers must be explicitly enumerated and negotiated by all users in order to ensure a compatible and optimal pipeline, as discussed below.

<a id="rst-dimensions-and-size"></a>

## Dimensions and size

Each pixel buffer must be accompanied by logical pixel dimensions. This refers to the number of unique samples which can be extracted from, or stored to, the underlying memory storage. For example, even though a 1920x1080 `DRM_FORMAT_NV12` buffer has a luma plane containing 1920x1080 samples for the Y component, and 960x540 samples for the U and V components, the overall buffer is still described as having dimensions of 1920x1080.

The in-memory storage of a buffer is not guaranteed to begin immediately at the base address of the underlying memory, nor is it guaranteed that the memory storage is tightly clipped to either dimension.

Each plane must therefore be described with an `offset` in bytes, which will be added to the base address of the memory storage before performing any per-pixel calculations. This may be used to combine multiple planes into a single memory buffer; for example, `DRM_FORMAT_NV12` may be stored in a single memory buffer where the luma plane's storage begins immediately at the start of the buffer with an offset of 0, and the chroma plane's storage follows within the same buffer beginning from the byte offset for that plane.

Each plane must also have a `stride` in bytes, expressing the offset in memory between two contiguous row. For example, a `DRM_FORMAT_MOD_LINEAR` buffer with dimensions of 1000x1000 may have been allocated as if it were 1024x1000, in order to allow for aligned access patterns. In this case, the buffer will still be described with a width of 1000, however the stride will be `1024 * bpp`, indicating that there are 24 pixels at the positive extreme of the x axis whose values are not significant.

Buffers may also be padded further in the y dimension, simply by allocating a larger area than would ordinarily be required. For example, many media decoders are not able to natively output buffers of height 1080, but instead require an effective height of 1088 pixels. In this case, the buffer continues to be described as having a height of 1080, with the memory allocation for each buffer being increased to account for the extra padding.

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

## Enumeration

Every user of pixel buffers must be able to enumerate a set of supported formats and modifiers, described together. Within KMS, this is achieved with the `IN_FORMATS` property on each DRM plane, listing the supported DRM formats, and the modifiers supported for each format. In userspace, this is supported through the [EGL\_EXT\_image\_dma\_buf\_import\_modifiers](<https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_image_dma_buf_import_modifiers.txt>) extension entrypoints for EGL, the [VK\_EXT\_image\_drm\_format\_modifier](<https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_image_drm_format_modifier.html>) extension for Vulkan, and the [zwp\_linux\_dmabuf\_v1](<https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml>) extension for Wayland.

Each of these interfaces allows users to query a set of supported format+modifier combinations.

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

## Negotiation

It is the responsibility of userspace to negotiate an acceptable format+modifier combination for its usage. This is performed through a simple intersection of lists. For example, if a user wants to use Vulkan to render an image to be displayed on a KMS plane, it must:

> - query KMS for the `IN_FORMATS` property for the given plane
>
> - query Vulkan for the supported formats for its physical device, making sure to pass the `VkImageUsageFlagBits` and `VkImageCreateFlagBits` corresponding to the intended rendering use
>
> - intersect these formats to determine the most appropriate one
>
> - for this format, intersect the lists of supported modifiers for both KMS and Vulkan, to obtain a final list of acceptable modifiers for that format

This intersection must be performed for all usages. For example, if the user also wishes to encode the image to a video stream, it must query the media API it intends to use for encoding for the set of modifiers it supports, and additionally intersect against this list.

If the intersection of all lists is an empty list, it is not possible to share buffers in this way, and an alternate strategy must be considered (e.g. using CPU access routines to copy data between the different uses, with the corresponding performance cost).

The resulting modifier list is unsorted; the order is not significant.

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

## Allocation

Once userspace has determined an appropriate format, and corresponding list of acceptable modifiers, it must allocate the buffer. As there is no universal buffer-allocation interface available at either kernel or userspace level, the client makes an arbitrary choice of allocation interface such as Vulkan, GBM, or a media API.

Each allocation request must take, at a minimum: the pixel format, a list of acceptable modifiers, and the buffer's width and height. Each API may extend this set of properties in different ways, such as allowing allocation in more than two dimensions, intended usage patterns, etc.

The component which allocates the buffer will make an arbitrary choice of what it considers the 'best' modifier within the acceptable list for the requested allocation, any padding required, and further properties of the underlying memory buffers such as whether they are stored in system or device-specific memory, whether or not they are physically contiguous, and their cache mode. These properties of the memory buffer are not visible to userspace, however the `dma-heaps` API is an effort to address this.

After allocation, the client must query the allocator to determine the actual modifier selected for the buffer, as well as the per-plane offset and stride. Allocators are not permitted to vary the format in use, to select a modifier not provided within the acceptable list, nor to vary the pixel dimensions other than the padding expressed through offset, stride, and size.

Communicating additional constraints, such as alignment of stride or offset, placement within a particular memory area, etc, is out of scope of dma-buf, and is not solved by format and modifier tokens.

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

## Import

To use a buffer within a different context, device, or subsystem, the user passes these parameters (format, modifier, width, height, and per-plane offset and stride) to an importing API.

Each memory buffer is referred to by a buffer handle, which may be unique or duplicated within an image. For example, a `DRM_FORMAT_NV12` buffer may have the luma and chroma buffers combined into a single memory buffer by use of the per-plane offset parameters, or they may be completely separate allocations in memory. For this reason, each import and allocation API must provide a separate handle for each plane.

Each kernel subsystem has its own types and interfaces for buffer management. DRM uses GEM buffer objects (BOs), V4L2 has its own references, etc. These types are not portable between contexts, processes, devices, or subsystems.

To address this, `dma-buf` handles are used as the universal interchange for buffers. Subsystem-specific operations are used to export native buffer handles to a `dma-buf` file descriptor, and to import those file descriptors into a native buffer handle. dma-buf file descriptors can be transferred between contexts, processes, devices, and subsystems.

For example, a Wayland media player may use V4L2 to decode a video frame into a `DRM_FORMAT_NV12` buffer. This will result in two memory planes (luma and chroma) being dequeued by the user from V4L2. These planes are then exported to one dma-buf file descriptor per plane, these descriptors are then sent along with the metadata (format, modifier, width, height, per-plane offset and stride) to the Wayland server. The Wayland server will then import these file descriptors as an EGLImage for use through EGL/OpenGL (ES), a VkImage for use through Vulkan, or a KMS framebuffer object; each of these import operations will take the same metadata and convert the dma-buf file descriptors into their native buffer handles.

Having a non-empty intersection of supported modifiers does not guarantee that import will succeed into all consumers; they may have constraints beyond those implied by modifiers which must be satisfied.

<a id="rst-implicit-modifiers"></a>

## Implicit modifiers

The concept of modifiers post-dates all of the subsystems mentioned above. As such, it has been retrofitted into all of these APIs, and in order to ensure backwards compatibility, support is needed for drivers and userspace which do not (yet) support modifiers.

As an example, GBM is used to allocate buffers to be shared between EGL for rendering and KMS for display. It has two entrypoints for allocating buffers: `gbm_bo_create` which only takes the format, width, height, and a usage token, and `gbm_bo_create_with_modifiers` which extends this with a list of modifiers.

In the latter case, the allocation is as discussed above, being provided with a list of acceptable modifiers that the implementation can choose from (or fail if it is not possible to allocate within those constraints). In the former case where modifiers are not provided, the GBM implementation must make its own choice as to what is likely to be the 'best' layout. Such a choice is entirely implementation-specific: some will internally use tiled layouts which are not CPU-accessible if the implementation decides that is a good idea through whatever heuristic. It is the implementation's responsibility to ensure that this choice is appropriate.

To support this case where the layout is not known because there is no awareness of modifiers, a special `DRM_FORMAT_MOD_INVALID` token has been defined. This pseudo-modifier declares that the layout is not known, and that the driver should use its own logic to determine what the underlying layout may be.

> [!NOTE]
>
> `DRM_FORMAT_MOD_INVALID` is a non-zero value. The modifier value zero is `DRM_FORMAT_MOD_LINEAR`, which is an explicit guarantee that the image has the linear layout. Care and attention should be taken to ensure that zero as a default value is not mixed up with either no modifier or the linear modifier. Also note that in some APIs the invalid modifier value is specified with an out-of-band flag, like in `DRM_IOCTL_MODE_ADDFB2`.

- **There are four cases where this token may be used:**

  - during enumeration, an interface may return `DRM_FORMAT_MOD_INVALID`, either as the sole member of a modifier list to declare that explicit modifiers are not supported, or as part of a larger list to declare that implicit modifiers may be used

  - during allocation, a user may supply `DRM_FORMAT_MOD_INVALID`, either as the sole member of a modifier list (equivalent to not supplying a modifier list at all) to declare that explicit modifiers are not supported and must not be used, or as part of a larger list to declare that an allocation using implicit modifiers is acceptable

  - in a post-allocation query, an implementation may return `DRM_FORMAT_MOD_INVALID` as the modifier of the allocated buffer to declare that the underlying layout is implementation-defined and that an explicit modifier description is not available; per the above rules, this may only be returned when the user has included `DRM_FORMAT_MOD_INVALID` as part of the list of acceptable modifiers, or not provided a list

  - when importing a buffer, the user may supply `DRM_FORMAT_MOD_INVALID` as the buffer modifier (or not supply a modifier) to indicate that the modifier is unknown for whatever reason; this is only acceptable when the buffer has not been allocated with an explicit modifier

It follows from this that for any single buffer, the complete chain of operations formed by the producer and all the consumers must be either fully implicit or fully explicit. For example, if a user wishes to allocate a buffer for use between GPU, display, and media, but the media API does not support modifiers, then the user <strong>must not</strong> allocate the buffer with explicit modifiers and attempt to import the buffer into the media API with no modifier, but either perform the allocation using implicit modifiers, or allocate the buffer for media use separately and copy between the two buffers.

As one exception to the above, allocations may be 'upgraded' from implicit to explicit modifiers. For example, if the buffer is allocated with `gbm_bo_create` (taking no modifiers), the user may then query the modifier with `gbm_bo_get_modifier` and then use this modifier as an explicit modifier token if a valid modifier is returned.

When allocating buffers for exchange between different users and modifiers are not available, implementations are strongly encouraged to use `DRM_FORMAT_MOD_LINEAR` for their allocation, as this is the universal baseline for exchange. However, it is not guaranteed that this will result in the correct interpretation of buffer content, as implicit modifier operation may still be subject to driver-specific heuristics.

Any new users - userspace programs and protocols, kernel subsystems, etc - wishing to exchange buffers must offer interoperability through dma-buf file descriptors for memory planes, DRM format tokens to describe the format, DRM format modifiers to describe the layout in memory, at least width and height for dimensions, and at least offset and stride for each memory plane.

<a id="rst-zwp-linux-dmabuf-v1"></a>



<a id="rst-vk-ext-image-drm-format-modifier"></a>



<a id="rst-egl-ext-image-dma-buf-import-modifiers"></a>

---

# Allocating dma-buf using heaps

_Peios Kernel / Userspace interfaces / System and device interfaces / Memory and device access_

> Dma-buf Heaps are a way for userspace to allocate dma-buf objects. They are typically used to allocate buffers from a specific allocation pool, or to share buffers across frameworks.

<a id="rst-allocating-dma-buf-using-heaps"></a>

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

Dma-buf Heaps are a way for userspace to allocate dma-buf objects. They are typically used to allocate buffers from a specific allocation pool, or to share buffers across frameworks.

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

## Heaps

A heap represents a specific allocator. The Linux kernel currently supports the following heaps:

> - The `system` heap allocates virtually contiguous, cacheable, buffers.
>
> - The `default_cma_region` heap allocates physically contiguous, cacheable, buffers. Only present if a CMA region is present. Such a region is usually created either through the kernel commandline through the `cma` parameter, a memory region Device-Tree node with the `linux,cma-default` property set, or through the `CMA_SIZE_MBYTES` or `CMA_SIZE_PERCENTAGE` Kconfig options. Prior to Linux 6.17, its name wasn't stable and could be called `reserved`, `linux,cma`, or `default-pool`, depending on the platform.
>
> - A heap will be created for each reusable region in the device tree with the `shared-dma-pool` compatible, using the full device tree node name as its name. The buffer semantics are identical to `default-cma-region`.

<a id="rst-naming-convention"></a>

## Naming Convention

`dma-buf` heaps name should meet a number of constraints:

- The name must be stable, and must not change from one version to the other. Userspace identifies heaps by their name, so if the names ever change, we would be likely to introduce regressions.

- The name must describe the memory region the heap will allocate from, and must uniquely identify it in a given platform. Since userspace applications use the heap name as the discriminant, it must be able to tell which heap it wants to use reliably if there's multiple heaps.

- The name must not mention implementation details, such as the allocator. The heap driver will change over time, and implementation details when it was introduced might not be relevant in the future.

- The name should describe properties of the buffers that would be allocated. Doing so will make heap identification easier for userspace. Such properties are:

  - `contiguous` for physically contiguous buffers;

  - `protected` for encrypted buffers not accessible the OS;

- The name may describe intended usage. Doing so will make heap identification easier for userspace applications and users.

For example, assuming a platform with a reserved memory region located at the RAM address 0x42000000, intended to allocate video framebuffers, physically contiguous, and backed by the CMA kernel allocator, good names would be `memory@42000000-contiguous` or `video@42000000`, but `cma-video` wouldn't.

---

# IOMMUFD

_Peios Kernel / Userspace interfaces / System and device interfaces / Memory and device access_

> IOMMUFD is the user API to control the IOMMU subsystem as it relates to managing IO page tables from userspace using file descriptors. It intends to be general and consumable by any driver that wants to expose DMA to userspace. These…

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

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

**Author:** Jason Gunthorpe

**Author:** Kevin Tian

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

## Overview

IOMMUFD is the user API to control the IOMMU subsystem as it relates to managing IO page tables from userspace using file descriptors. It intends to be general and consumable by any driver that wants to expose DMA to userspace. These drivers are eventually expected to deprecate any internal IOMMU logic they may already/historically implement (e.g. vfio_iommu_type1.c).

At minimum iommufd provides universal support of managing I/O address spaces and I/O page tables for all IOMMUs, with room in the design to add non-generic features to cater to specific hardware functionality.

In this context the capital letter (IOMMUFD) refers to the subsystem while the small letter (iommufd) refers to the file descriptors created via /dev/iommu for use by userspace.

<a id="rst-key-concepts"></a>

## Key Concepts

<a id="rst-user-visible-objects"></a>

### User Visible Objects

Following IOMMUFD objects are exposed to userspace:

- IOMMUFD_OBJ_IOAS, representing an I/O address space (IOAS), allowing map/unmap of user space memory into ranges of I/O Virtual Address (IOVA).

  The IOAS is a functional replacement for the VFIO container, and like the VFIO container it copies an IOVA map to a list of iommu_domains held within it.

- IOMMUFD_OBJ_DEVICE, representing a device that is bound to iommufd by an external driver.

- IOMMUFD_OBJ_HWPT_PAGING, representing an actual hardware I/O page table (i.e. a single struct iommu_domain) managed by the iommu driver. "PAGING" primarily indicates this type of HWPT should be linked to an IOAS. It also indicates that it is backed by an iommu_domain with \__IOMMU_DOMAIN_PAGING feature flag. This can be either an UNMANAGED stage-1 domain for a device running in the user space, or a nesting parent stage-2 domain for mappings from guest-level physical addresses to host-level physical addresses.

  The IOAS has a list of HWPT_PAGINGs that share the same IOVA mapping and it will synchronize its mapping with each member HWPT_PAGING.

- IOMMUFD_OBJ_HWPT_NESTED, representing an actual hardware I/O page table (i.e. a single struct iommu_domain) managed by user space (e.g. guest OS). "NESTED" indicates that this type of HWPT should be linked to an HWPT_PAGING. It also indicates that it is backed by an iommu_domain that has a type of IOMMU_DOMAIN_NESTED. This must be a stage-1 domain for a device running in the user space (e.g. in a guest VM enabling the IOMMU nested translation feature.) As such, it must be created with a given nesting parent stage-2 domain to associate to. This nested stage-1 page table managed by the user space usually has mappings from guest-level I/O virtual addresses to guest- level physical addresses.

- IOMMUFD_FAULT, representing a software queue for an HWPT reporting IO page faults using the IOMMU HW's PRI (Page Request Interface). This queue object provides user space an FD to poll the page fault events and also to respond to those events. A FAULT object must be created first to get a fault_id that could be then used to allocate a fault-enabled HWPT via the IOMMU_HWPT_ALLOC command by setting the IOMMU_HWPT_FAULT_ID_VALID bit in its flags field.

- IOMMUFD_OBJ_VIOMMU, representing a slice of the physical IOMMU instance, passed to or shared with a VM. It may be some HW-accelerated virtualization features and some SW resources used by the VM. For examples:

  - Security namespace for guest owned ID, e.g. guest-controlled cache tags

  - Non-device-affiliated event reporting, e.g. invalidation queue errors

  - Access to a shareable nesting parent pagetable across physical IOMMUs

  - Virtualization of various platforms IDs, e.g. RIDs and others

  - Delivery of paravirtualized invalidation

  - Direct assigned invalidation queues

  - Direct assigned interrupts

  Such a vIOMMU object generally has the access to a nesting parent pagetable to support some HW-accelerated virtualization features. So, a vIOMMU object must be created given a nesting parent HWPT_PAGING object, and then it would encapsulate that HWPT_PAGING object. Therefore, a vIOMMU object can be used to allocate an HWPT_NESTED object in place of the encapsulated HWPT_PAGING.

  > [!NOTE]
  >
  > The name "vIOMMU" isn't necessarily identical to a virtualized IOMMU in a VM. A VM can have one giant virtualized IOMMU running on a machine having multiple physical IOMMUs, in which case the VMM will dispatch the requests or configurations from this single virtualized IOMMU instance to multiple vIOMMU objects created for individual slices of different physical IOMMUs. In other words, a vIOMMU object is always a representation of one physical IOMMU, not necessarily of a virtualized IOMMU. For VMMs that want the full virtualization features from physical IOMMUs, it is suggested to build the same number of virtualized IOMMUs as the number of physical IOMMUs, so the passed-through devices would be connected to their own virtualized IOMMUs backed by corresponding vIOMMU objects, in which case a guest OS would do the "dispatch" naturally instead of VMM trappings.

- IOMMUFD_OBJ_VDEVICE, representing a virtual device for an IOMMUFD_OBJ_DEVICE against an IOMMUFD_OBJ_VIOMMU. This virtual device holds the device's virtual information or attributes (related to the vIOMMU) in a VM. An immediate vDATA example can be the virtual ID of the device on a vIOMMU, which is a unique ID that VMM assigns to the device for a translation channel/port of the vIOMMU, e.g. vSID of ARM SMMUv3, vDeviceID of AMD IOMMU, and vRID of Intel VT-d to a Context Table. Potential use cases of some advanced security information can be forwarded via this object too, such as security level or realm information in a Confidential Compute Architecture. A VMM should create a vDEVICE object to forward all the device information in a VM, when it connects a device to a vIOMMU, which is a separate ioctl call from attaching the same device to an HWPT_PAGING that the vIOMMU holds.

- IOMMUFD_OBJ_VEVENTQ, representing a software queue for a vIOMMU to report its events such as translation faults occurred to a nested stage-1 (excluding I/O page faults that should go through IOMMUFD_OBJ_FAULT) and HW-specific events. This queue object provides user space an FD to poll/read the vIOMMU events. A vIOMMU object must be created first to get its viommu_id, which could be then used to allocate a vEVENTQ. Each vIOMMU can support multiple types of vEVENTS, but is confined to one vEVENTQ per vEVENTQ type.

- IOMMUFD_OBJ_HW_QUEUE, representing a hardware accelerated queue, as a subset of IOMMU's virtualization features, for the IOMMU HW to directly read or write the virtual queue memory owned by a guest OS. This HW-acceleration feature can allow VM to work with the IOMMU HW directly without a VM Exit, so as to reduce overhead from the hypercalls. Along with the HW QUEUE object, iommufd provides user space an mmap interface for VMM to mmap a physical MMIO region from the host physical address space to the guest physical address space, allowing the guest OS to directly control the allocated HW QUEUE. Thus, when allocating a HW QUEUE, the VMM must request a pair of mmap info (offset/length) and pass in exactly to an mmap syscall via its offset and length arguments.

All user-visible objects are destroyed via the IOMMU_DESTROY uAPI.

The diagrams below show relationships between user-visible objects and kernel datastructures (external to iommufd), with numbers referred to operations creating the objects and links:



```text
 _______________________________________________________________________
|                      iommufd (HWPT_PAGING only)                       |
|                                                                       |
|        [1]                  [3]                                [2]    |
|  ________________      _____________                        ________  |
| |                |    |             |                      |        | |
| |      IOAS      |<---| HWPT_PAGING |<---------------------| DEVICE | |
| |________________|    |_____________|                      |________| |
|         |                    |                                  |     |
|_________|____________________|__________________________________|_____|
          |                    |                                  |
          |              ______v_____                          ___v__
          | PFN storage |  (paging)  |                        |struct|
          |------------>|iommu_domain|<-----------------------|device|
                        |____________|                        |______|

 _______________________________________________________________________
|                      iommufd (with HWPT_NESTED)                       |
|                                                                       |
|        [1]                  [3]                [4]             [2]    |
|  ________________      _____________      _____________     ________  |
| |                |    |             |    |             |   |        | |
| |      IOAS      |<---| HWPT_PAGING |<---| HWPT_NESTED |<--| DEVICE | |
| |________________|    |_____________|    |_____________|   |________| |
|         |                    |                  |               |     |
|_________|____________________|__________________|_______________|_____|
          |                    |                  |               |
          |              ______v_____       ______v_____       ___v__
          | PFN storage |  (paging)  |     |  (nested)  |     |struct|
          |------------>|iommu_domain|<----|iommu_domain|<----|device|
                        |____________|     |____________|     |______|

 _______________________________________________________________________
|                      iommufd (with vIOMMU/vDEVICE)                    |
|                                                                       |
|                             [5]                [6]                    |
|                        _____________      _____________               |
|                       |             |    |             |              |
|      |----------------|    vIOMMU   |<---|   vDEVICE   |<----|        |
|      |                |             |    |_____________|     |        |
|      |                |             |                        |        |
|      |      [1]       |             |          [4]           | [2]    |
|      |     ______     |             |     _____________     _|______  |
|      |    |      |    |     [3]     |    |             |   |        | |
|      |    | IOAS |<---|(HWPT_PAGING)|<---| HWPT_NESTED |<--| DEVICE | |
|      |    |______|    |_____________|    |_____________|   |________| |
|      |        |              |                  |               |     |
|______|________|______________|__________________|_______________|_____|
       |        |              |                  |               |
 ______v_____   |        ______v_____       ______v_____       ___v__
|   struct   |  |  PFN  |  (paging)  |     |  (nested)  |     |struct|
|iommu_device|  |------>|iommu_domain|<----|iommu_domain|<----|device|
|____________|   storage|____________|     |____________|     |______|
```

1. IOMMUFD_OBJ_IOAS is created via the IOMMU_IOAS_ALLOC uAPI. An iommufd can hold multiple IOAS objects. IOAS is the most generic object and does not expose interfaces that are specific to single IOMMU drivers. All operations on the IOAS must operate equally on each of the iommu_domains inside of it.

2. IOMMUFD_OBJ_DEVICE is created when an external driver calls the IOMMUFD kAPI to bind a device to an iommufd. The driver is expected to implement a set of ioctls to allow userspace to initiate the binding operation. Successful completion of this operation establishes the desired DMA ownership over the device. The driver must also set the driver_managed_dma flag and must not touch the device until this operation succeeds.

3. IOMMUFD_OBJ_HWPT_PAGING can be created in two ways:

   - IOMMUFD_OBJ_HWPT_PAGING is automatically created when an external driver calls the IOMMUFD kAPI to attach a bound device to an IOAS. Similarly the external driver uAPI allows userspace to initiate the attaching operation. If a compatible member HWPT_PAGING object exists in the IOAS's HWPT_PAGING list, then it will be reused. Otherwise a new HWPT_PAGING that represents an iommu_domain to userspace will be created, and then added to the list. Successful completion of this operation sets up the linkages among IOAS, device and iommu_domain. Once this completes the device could do DMA.

   - IOMMUFD_OBJ_HWPT_PAGING can be manually created via the IOMMU_HWPT_ALLOC uAPI, provided an ioas_id via @pt_id to associate the new HWPT_PAGING to the corresponding IOAS object. The benefit of this manual allocation is to allow allocation flags (defined in enum iommufd_hwpt_alloc_flags), e.g. it allocates a nesting parent HWPT_PAGING if the IOMMU_HWPT_ALLOC_NEST_PARENT flag is set.

4. IOMMUFD_OBJ_HWPT_NESTED can be only manually created via the IOMMU_HWPT_ALLOC uAPI, provided an hwpt_id or a viommu_id of a vIOMMU object encapsulating a nesting parent HWPT_PAGING via @pt_id to associate the new HWPT_NESTED object to the corresponding HWPT_PAGING object. The associating HWPT_PAGING object must be a nesting parent manually allocated via the same uAPI previously with an IOMMU_HWPT_ALLOC_NEST_PARENT flag, otherwise the allocation will fail. The allocation will be further validated by the IOMMU driver to ensure that the nesting parent domain and the nested domain being allocated are compatible. Successful completion of this operation sets up linkages among IOAS, device, and iommu_domains. Once this completes the device could do DMA via a 2-stage translation, a.k.a nested translation. Note that multiple HWPT_NESTED objects can be allocated by (and then associated to) the same nesting parent.

   > [!NOTE]
   >
   > Either a manual IOMMUFD_OBJ_HWPT_PAGING or an IOMMUFD_OBJ_HWPT_NESTED is created via the same IOMMU_HWPT_ALLOC uAPI. The difference is at the type of the object passed in via the @pt_id field of struct iommufd_hwpt_alloc.

5. IOMMUFD_OBJ_VIOMMU can be only manually created via the IOMMU_VIOMMU_ALLOC uAPI, provided a dev_id (for the device's physical IOMMU to back the vIOMMU) and an hwpt_id (to associate the vIOMMU to a nesting parent HWPT_PAGING). The iommufd core will link the vIOMMU object to the struct iommu_device that the struct device is behind. And an IOMMU driver can implement a viommu_alloc op to allocate its own vIOMMU data structure embedding the core-level structure iommufd_viommu and some driver-specific data. If necessary, the driver can also configure its HW virtualization feature for that vIOMMU (and thus for the VM). Successful completion of this operation sets up the linkages between the vIOMMU object and the HWPT_PAGING, then this vIOMMU object can be used as a nesting parent object to allocate an HWPT_NESTED object described above.

6. IOMMUFD_OBJ_VDEVICE can be only manually created via the IOMMU_VDEVICE_ALLOC uAPI, provided a viommu_id for an iommufd_viommu object and a dev_id for an iommufd_device object. The vDEVICE object will be the binding between these two parent objects. Another @virt_id will be also set via the uAPI providing the iommufd core an index to store the vDEVICE object to a vDEVICE array per vIOMMU. If necessary, the IOMMU driver may choose to implement a vdevce_alloc op to init its HW for virtualization feature related to a vDEVICE. Successful completion of this operation sets up the linkages between vIOMMU and device.

A device can only bind to an iommufd due to DMA ownership claim and attach to at most one IOAS object (no support of PASID yet).

<a id="rst-kernel-datastructure"></a>

### Kernel Datastructure

User visible objects are backed by following datastructures:

- iommufd_ioas for IOMMUFD_OBJ_IOAS.

- iommufd_device for IOMMUFD_OBJ_DEVICE.

- iommufd_hwpt_paging for IOMMUFD_OBJ_HWPT_PAGING.

- iommufd_hwpt_nested for IOMMUFD_OBJ_HWPT_NESTED.

- iommufd_fault for IOMMUFD_OBJ_FAULT.

- iommufd_viommu for IOMMUFD_OBJ_VIOMMU.

- iommufd_vdevice for IOMMUFD_OBJ_VDEVICE.

- iommufd_veventq for IOMMUFD_OBJ_VEVENTQ.

- iommufd_hw_queue for IOMMUFD_OBJ_HW_QUEUE.

Several terminologies when looking at these datastructures:

- Automatic domain - refers to an iommu domain created automatically when attaching a device to an IOAS object. This is compatible to the semantics of VFIO type1.

- Manual domain - refers to an iommu domain designated by the user as the target pagetable to be attached to by a device. Though currently there are no uAPIs to directly create such domain, the datastructure and algorithms are ready for handling that use case.

- In-kernel user - refers to something like a VFIO mdev that is using the IOMMUFD access interface to access the IOAS. This starts by creating an iommufd_access object that is similar to the domain binding a physical device would do. The access object will then allow converting IOVA ranges into struct page \* lists, or doing direct read/write to an IOVA.

iommufd_ioas serves as the metadata datastructure to manage how IOVA ranges are mapped to memory pages, composed of:

- struct io_pagetable holding the IOVA map

- struct iopt_area's representing populated portions of IOVA

- struct iopt_pages representing the storage of PFNs

- struct iommu_domain representing the IO page table in the IOMMU

- struct iopt_pages_access representing in-kernel users of PFNs

- struct xarray pinned_pfns holding a list of pages pinned by in-kernel users

Each iopt_pages represents a logical linear array of full PFNs. The PFNs are ultimately derived from userspace VAs via an mm_struct. Once they have been pinned the PFNs are stored in IOPTEs of an iommu_domain or inside the pinned_pfns xarray if they have been pinned through an iommufd_access.

PFN have to be copied between all combinations of storage locations, depending on what domains are present and what kinds of in-kernel "software access" users exist. The mechanism ensures that a page is pinned only once.

An io_pagetable is composed of iopt_areas pointing at iopt_pages, along with a list of iommu_domains that mirror the IOVA to PFN map.

Multiple io_pagetable-s, through their iopt_area-s, can share a single iopt_pages which avoids multi-pinning and double accounting of page consumption.

iommufd_ioas is shareable between subsystems, e.g. VFIO and VDPA, as long as devices managed by different subsystems are bound to a same iommufd.

<a id="rst-iommufd-user-api"></a>

## IOMMUFD User API


**General ioctl format**

The ioctl interface follows a general format to allow for extensibility. Each
ioctl is passed in a structure pointer as the argument providing the size of
the structure in the first u32. The kernel checks that any structure space
beyond what it understands is 0. This allows userspace to use the backward
compatible portion while consistently using the newer, larger, structures.

ioctls use a standard meaning for common errnos:

- ENOTTY: The IOCTL number itself is not supported at all
- E2BIG: The IOCTL number is supported, but the provided structure has
  non-zero in a part the kernel does not understand.
- EOPNOTSUPP: The IOCTL number is supported, and the structure is
  understood, however a known field has a value the kernel does not
  understand or support.
- EINVAL: Everything about the IOCTL was understood, but a field is not
  correct.
- ENOENT: An ID or IOVA provided does not exist.
- ENOMEM: Out of memory.
- EOVERFLOW: Mathematics overflowed.

As well as additional errnos, within specific ioctls.

#### <a id="c-struct-iommu_destroy"></a>`struct iommu_destroy`

ioctl(IOMMU_DESTROY)

**Definition**

```c
struct iommu_destroy {
    __u32 size;
    __u32 id;
};
```

**Members**

- `size`: sizeof(struct iommu_destroy)
- `id`: iommufd object ID to destroy. Can be any destroyable object type.

**Description**

Destroy any object held within iommufd.

#### <a id="c-struct-iommu_ioas_alloc"></a>`struct iommu_ioas_alloc`

ioctl(IOMMU_IOAS_ALLOC)

**Definition**

```c
struct iommu_ioas_alloc {
    __u32 size;
    __u32 flags;
    __u32 out_ioas_id;
};
```

**Members**

- `size`: sizeof(struct iommu_ioas_alloc)
- `flags`: Must be 0
- `out_ioas_id`: Output IOAS ID for the allocated object

**Description**

Allocate an IO Address Space (IOAS) which holds an IO Virtual Address (IOVA)
to memory mapping.

#### <a id="c-struct-iommu_iova_range"></a>`struct iommu_iova_range`

ioctl(IOMMU_IOVA_RANGE)

**Definition**

```c
struct iommu_iova_range {
    __aligned_u64 start;
    __aligned_u64 last;
};
```

**Members**

- `start`: First IOVA
- `last`: Inclusive last IOVA

**Description**

An interval in IOVA space.

#### <a id="c-struct-iommu_ioas_iova_ranges"></a>`struct iommu_ioas_iova_ranges`

ioctl(IOMMU_IOAS_IOVA_RANGES)

**Definition**

```c
struct iommu_ioas_iova_ranges {
    __u32 size;
    __u32 ioas_id;
    __u32 num_iovas;
    __u32 __reserved;
    __aligned_u64 allowed_iovas;
    __aligned_u64 out_iova_alignment;
};
```

**Members**

- `size`: sizeof(struct iommu_ioas_iova_ranges)
- `ioas_id`: IOAS ID to read ranges from
- `num_iovas`: Input/Output total number of ranges in the IOAS
- `__reserved`: Must be 0
- `allowed_iovas`: Pointer to the output array of struct iommu_iova_range
- `out_iova_alignment`: Minimum alignment required for mapping IOVA

**Description**

Query an IOAS for ranges of allowed IOVAs. Mapping IOVA outside these ranges
is not allowed. num_iovas will be set to the total number of iovas and
the allowed_iovas\[\] will be filled in as space permits.

The allowed ranges are dependent on the HW path the DMA operation takes, and
can change during the lifetime of the IOAS. A fresh empty IOAS will have a
full range, and each attached device will narrow the ranges based on that
device's HW restrictions. Detaching a device can widen the ranges. Userspace
should query ranges after every attach/detach to know what IOVAs are valid
for mapping.

On input num_iovas is the length of the allowed_iovas array. On output it is
the total number of iovas filled in. The ioctl will return -EMSGSIZE and set
num_iovas to the required value if num_iovas is too small. In this case the
caller should allocate a larger output array and re-issue the ioctl.

out_iova_alignment returns the minimum IOVA alignment that can be given
to IOMMU_IOAS_MAP/COPY. IOVA's must satisfy:

```text
starting_iova % out_iova_alignment == 0
(starting_iova + length) % out_iova_alignment == 0
```

out_iova_alignment can be 1 indicating any IOVA is allowed. It cannot
be higher than the system PAGE_SIZE.

#### <a id="c-struct-iommu_ioas_allow_iovas"></a>`struct iommu_ioas_allow_iovas`

ioctl(IOMMU_IOAS_ALLOW_IOVAS)

**Definition**

```c
struct iommu_ioas_allow_iovas {
    __u32 size;
    __u32 ioas_id;
    __u32 num_iovas;
    __u32 __reserved;
    __aligned_u64 allowed_iovas;
};
```

**Members**

- `size`: sizeof(struct iommu_ioas_allow_iovas)
- `ioas_id`: IOAS ID to allow IOVAs from
- `num_iovas`: Input/Output total number of ranges in the IOAS
- `__reserved`: Must be 0
- `allowed_iovas`: Pointer to array of struct iommu_iova_range

**Description**

Ensure a range of IOVAs are always available for allocation. If this call
succeeds then IOMMU_IOAS_IOVA_RANGES will never return a list of IOVA ranges
that are narrower than the ranges provided here. This call will fail if
IOMMU_IOAS_IOVA_RANGES is currently narrower than the given ranges.

When an IOAS is first created the IOVA_RANGES will be maximally sized, and as
devices are attached the IOVA will narrow based on the device restrictions.
When an allowed range is specified any narrowing will be refused, ie device
attachment can fail if the device requires limiting within the allowed range.

Automatic IOVA allocation is also impacted by this call. MAP will only
allocate within the allowed IOVAs if they are present.

This call replaces the entire allowed list with the given list.

#### <a id="c-enum-iommufd_ioas_map_flags"></a>`enum iommufd_ioas_map_flags`

Flags for map and copy

**Constants**

- `IOMMU_IOAS_MAP_FIXED_IOVA`: If clear the kernel will compute an appropriate
  IOVA to place the mapping at
- `IOMMU_IOAS_MAP_WRITEABLE`: DMA is allowed to write to this mapping
- `IOMMU_IOAS_MAP_READABLE`: DMA is allowed to read from this mapping

#### <a id="c-struct-iommu_ioas_map"></a>`struct iommu_ioas_map`

ioctl(IOMMU_IOAS_MAP)

**Definition**

```c
struct iommu_ioas_map {
    __u32 size;
    __u32 flags;
    __u32 ioas_id;
    __u32 __reserved;
    __aligned_u64 user_va;
    __aligned_u64 length;
    __aligned_u64 iova;
};
```

**Members**

- `size`: sizeof(struct iommu_ioas_map)
- `flags`: Combination of enum iommufd_ioas_map_flags
- `ioas_id`: IOAS ID to change the mapping of
- `__reserved`: Must be 0
- `user_va`: Userspace pointer to start mapping from
- `length`: Number of bytes to map
- `iova`: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is set
  then this must be provided as input.

**Description**

Set an IOVA mapping from a user pointer. If FIXED_IOVA is specified then the
mapping will be established at iova, otherwise a suitable location based on
the reserved and allowed lists will be automatically selected and returned in
iova.

If IOMMU_IOAS_MAP_FIXED_IOVA is specified then the iova range must currently
be unused, existing IOVA cannot be replaced.

#### <a id="c-struct-iommu_ioas_map_file"></a>`struct iommu_ioas_map_file`

ioctl(IOMMU_IOAS_MAP_FILE)

**Definition**

```c
struct iommu_ioas_map_file {
    __u32 size;
    __u32 flags;
    __u32 ioas_id;
    __s32 fd;
    __aligned_u64 start;
    __aligned_u64 length;
    __aligned_u64 iova;
};
```

**Members**

- `size`: sizeof(struct iommu_ioas_map_file)
- `flags`: same as for iommu_ioas_map
- `ioas_id`: same as for iommu_ioas_map
- `fd`: the memfd to map
- `start`: byte offset from start of file to map from
- `length`: same as for iommu_ioas_map
- `iova`: same as for iommu_ioas_map

**Description**

Set an IOVA mapping from a memfd file.  All other arguments and semantics
match those of IOMMU_IOAS_MAP.

#### <a id="c-struct-iommu_ioas_copy"></a>`struct iommu_ioas_copy`

ioctl(IOMMU_IOAS_COPY)

**Definition**

```c
struct iommu_ioas_copy {
    __u32 size;
    __u32 flags;
    __u32 dst_ioas_id;
    __u32 src_ioas_id;
    __aligned_u64 length;
    __aligned_u64 dst_iova;
    __aligned_u64 src_iova;
};
```

**Members**

- `size`: sizeof(struct iommu_ioas_copy)
- `flags`: Combination of enum iommufd_ioas_map_flags
- `dst_ioas_id`: IOAS ID to change the mapping of
- `src_ioas_id`: IOAS ID to copy from
- `length`: Number of bytes to copy and map
- `dst_iova`: IOVA the mapping was placed at. If IOMMU_IOAS_MAP_FIXED_IOVA is
  set then this must be provided as input.
- `src_iova`: IOVA to start the copy

**Description**

Copy an already existing mapping from src_ioas_id and establish it in
dst_ioas_id. The src iova/length must exactly match a range used with
IOMMU_IOAS_MAP.

This may be used to efficiently clone a subset of an IOAS to another, or as a
kind of 'cache' to speed up mapping. Copy has an efficiency advantage over
establishing equivalent new mappings, as internal resources are shared, and
the kernel will pin the user memory only once.

#### <a id="c-struct-iommu_ioas_unmap"></a>`struct iommu_ioas_unmap`

ioctl(IOMMU_IOAS_UNMAP)

**Definition**

```c
struct iommu_ioas_unmap {
    __u32 size;
    __u32 ioas_id;
    __aligned_u64 iova;
    __aligned_u64 length;
};
```

**Members**

- `size`: sizeof(struct iommu_ioas_unmap)
- `ioas_id`: IOAS ID to change the mapping of
- `iova`: IOVA to start the unmapping at
- `length`: Number of bytes to unmap, and return back the bytes unmapped

**Description**

Unmap an IOVA range. The iova/length must be a superset of a previously
mapped range used with IOMMU_IOAS_MAP or IOMMU_IOAS_COPY. Splitting or
truncating ranges is not allowed. The values 0 to U64_MAX will unmap
everything.

#### <a id="c-enum-iommufd_option"></a>`enum iommufd_option`

ioctl(IOMMU_OPTION_RLIMIT_MODE) and ioctl(IOMMU_OPTION_HUGE_PAGES)

**Constants**

- `IOMMU_OPTION_RLIMIT_MODE`: Change how RLIMIT_MEMLOCK accounting works. The caller must have privilege
  to invoke this. Value 0 (default) is user based accounting, 1 uses process
  based accounting. Global option, object_id must be 0
- `IOMMU_OPTION_HUGE_PAGES`: Value 1 (default) allows contiguous pages to be combined when generating
  iommu mappings. Value 0 disables combining, everything is mapped to
  PAGE_SIZE. This can be useful for benchmarking.  This is a per-IOAS
  option, the object_id must be the IOAS ID.

#### <a id="c-enum-iommufd_option_ops"></a>`enum iommufd_option_ops`

ioctl(IOMMU_OPTION_OP_SET) and ioctl(IOMMU_OPTION_OP_GET)

**Constants**

- `IOMMU_OPTION_OP_SET`: Set the option's value
- `IOMMU_OPTION_OP_GET`: Get the option's value

#### <a id="c-struct-iommu_option"></a>`struct iommu_option`

iommu option multiplexer

**Definition**

```c
struct iommu_option {
    __u32 size;
    __u32 option_id;
    __u16 op;
    __u16 __reserved;
    __u32 object_id;
    __aligned_u64 val64;
};
```

**Members**

- `size`: sizeof(struct iommu_option)
- `option_id`: One of enum iommufd_option
- `op`: One of enum iommufd_option_ops
- `__reserved`: Must be 0
- `object_id`: ID of the object if required
- `val64`: Option value to set or value returned on get

**Description**

Change a simple option value. This multiplexor allows controlling options
on objects. IOMMU_OPTION_OP_SET will load an option and IOMMU_OPTION_OP_GET
will return the current value.

#### <a id="c-enum-iommufd_vfio_ioas_op"></a>`enum iommufd_vfio_ioas_op`

IOMMU_VFIO_IOAS_* ioctls

**Constants**

- `IOMMU_VFIO_IOAS_GET`: Get the current compatibility IOAS
- `IOMMU_VFIO_IOAS_SET`: Change the current compatibility IOAS
- `IOMMU_VFIO_IOAS_CLEAR`: Disable VFIO compatibility

#### <a id="c-struct-iommu_vfio_ioas"></a>`struct iommu_vfio_ioas`

ioctl(IOMMU_VFIO_IOAS)

**Definition**

```c
struct iommu_vfio_ioas {
    __u32 size;
    __u32 ioas_id;
    __u16 op;
    __u16 __reserved;
};
```

**Members**

- `size`: sizeof(struct iommu_vfio_ioas)
- `ioas_id`: For IOMMU_VFIO_IOAS_SET the input IOAS ID to set
  For IOMMU_VFIO_IOAS_GET will output the IOAS ID
- `op`: One of enum iommufd_vfio_ioas_op
- `__reserved`: Must be 0

**Description**

The VFIO compatibility support uses a single ioas because VFIO APIs do not
support the ID field. Set or Get the IOAS that VFIO compatibility will use.
When VFIO_GROUP_SET_CONTAINER is used on an iommufd it will get the
compatibility ioas, either by taking what is already set, or auto creating
one. From then on VFIO will continue to use that ioas and is not effected by
this ioctl. SET or CLEAR does not destroy any auto-created IOAS.

#### <a id="c-enum-iommufd_hwpt_alloc_flags"></a>`enum iommufd_hwpt_alloc_flags`

Flags for HWPT allocation

**Constants**

- `IOMMU_HWPT_ALLOC_NEST_PARENT`: If set, allocate a HWPT that can serve as
  the parent HWPT in a nesting configuration.
- `IOMMU_HWPT_ALLOC_DIRTY_TRACKING`: Dirty tracking support for device IOMMU is
  enforced on device attachment
- `IOMMU_HWPT_FAULT_ID_VALID`: The fault_id field of hwpt allocation data is
  valid.
- `IOMMU_HWPT_ALLOC_PASID`: Requests a domain that can be used with PASID. The
  domain can be attached to any PASID on the device.
  Any domain attached to the non-PASID part of the
  device must also be flagged, otherwise attaching a
  PASID will blocked.
  For the user that wants to attach PASID, ioas is
  not recommended for both the non-PASID part
  and PASID part of the device.
  If IOMMU does not support PASID it will return
  error (-EOPNOTSUPP).

#### <a id="c-enum-iommu_hwpt_vtd_s1_flags"></a>`enum iommu_hwpt_vtd_s1_flags`

Intel VT-d stage-1 page table entry attributes

**Constants**

- `IOMMU_VTD_S1_SRE`: Supervisor request
- `IOMMU_VTD_S1_EAFE`: Extended access enable
- `IOMMU_VTD_S1_WPE`: Write protect enable

#### <a id="c-struct-iommu_hwpt_vtd_s1"></a>`struct iommu_hwpt_vtd_s1`

Intel VT-d stage-1 page table info (IOMMU_HWPT_DATA_VTD_S1)

**Definition**

```c
struct iommu_hwpt_vtd_s1 {
    __aligned_u64 flags;
    __aligned_u64 pgtbl_addr;
    __u32 addr_width;
    __u32 __reserved;
};
```

**Members**

- `flags`: Combination of enum iommu_hwpt_vtd_s1_flags
- `pgtbl_addr`: The base address of the stage-1 page table.
- `addr_width`: The address width of the stage-1 page table
- `__reserved`: Must be 0

#### <a id="c-struct-iommu_hwpt_arm_smmuv3"></a>`struct iommu_hwpt_arm_smmuv3`

ARM SMMUv3 nested STE (IOMMU_HWPT_DATA_ARM_SMMUV3)

**Definition**

```c
struct iommu_hwpt_arm_smmuv3 {
    __aligned_le64 ste[2];
};
```

**Members**

- `ste`: The first two double words of the user space Stream Table Entry for
  the translation. Must be little-endian.
  Allowed fields: (Refer to "5.2 Stream Table Entry" in SMMUv3 HW Spec)
  - word-0: V, Cfg, S1Fmt, S1ContextPtr, S1CDMax
  - word-1: EATS, S1DSS, S1CIR, S1COR, S1CSH, S1STALLD

**Description**

-EIO will be returned if **ste** is not legal or contains any non-allowed field.
Cfg can be used to select a S1, Bypass or Abort configuration. A Bypass
nested domain will translate the same as the nesting parent. The S1 will
install a Context Descriptor Table pointing at userspace memory translated
by the nesting parent.

It's suggested to allocate a vDEVICE object carrying vSID and then re-attach
the nested domain, as soon as the vSID is available in the VMM level:

- when Cfg=translate, a vDEVICE must be allocated prior to attaching to the
  allocated nested domain, as CD/ATS invalidations and vevents need a vSID.
- when Cfg=bypass/abort, a vDEVICE is not enforced during the nested domain
  attachment, to support a GBPA case where VM sets CR0.SMMUEN=0. However, if
  VM sets CR0.SMMUEN=1 while missing a vDEVICE object, kernel would fail to
  report events to the VM. E.g. F_TRANSLATION when guest STE.Cfg=abort.

#### <a id="c-struct-iommu_hwpt_amd_guest"></a>`struct iommu_hwpt_amd_guest`

AMD IOMMU guest I/O page table data (IOMMU_HWPT_DATA_AMD_GUEST)

**Definition**

```c
struct iommu_hwpt_amd_guest {
    __aligned_u64 dte[4];
};
```

**Members**

- `dte`: Guest Device Table Entry (DTE)

#### <a id="c-enum-iommu_hwpt_data_type"></a>`enum iommu_hwpt_data_type`

IOMMU HWPT Data Type

**Constants**

- `IOMMU_HWPT_DATA_NONE`: no data
- `IOMMU_HWPT_DATA_VTD_S1`: Intel VT-d stage-1 page table
- `IOMMU_HWPT_DATA_ARM_SMMUV3`: ARM SMMUv3 Context Descriptor Table
- `IOMMU_HWPT_DATA_AMD_GUEST`: AMD IOMMU guest page table

#### <a id="c-struct-iommu_hwpt_alloc"></a>`struct iommu_hwpt_alloc`

ioctl(IOMMU_HWPT_ALLOC)

**Definition**

```c
struct iommu_hwpt_alloc {
    __u32 size;
    __u32 flags;
    __u32 dev_id;
    __u32 pt_id;
    __u32 out_hwpt_id;
    __u32 __reserved;
    __u32 data_type;
    __u32 data_len;
    __aligned_u64 data_uptr;
    __u32 fault_id;
    __u32 __reserved2;
};
```

**Members**

- `size`: sizeof(struct iommu_hwpt_alloc)
- `flags`: Combination of enum iommufd_hwpt_alloc_flags
- `dev_id`: The device to allocate this HWPT for
- `pt_id`: The IOAS or HWPT or vIOMMU to connect this HWPT to
- `out_hwpt_id`: The ID of the new HWPT
- `__reserved`: Must be 0
- `data_type`: One of enum iommu_hwpt_data_type
- `data_len`: Length of the type specific data
- `data_uptr`: User pointer to the type specific data
- `fault_id`: The ID of IOMMUFD_FAULT object. Valid only if flags field of
  IOMMU_HWPT_FAULT_ID_VALID is set.
- `__reserved2`: Padding to 64-bit alignment. Must be 0.

**Description**

Explicitly allocate a hardware page table object. This is the same object
type that is returned by [`iommufd_device_attach()`](#c-iommufd_device_attach) and represents the
underlying iommu driver's iommu_domain kernel object.

A kernel-managed HWPT will be created with the mappings from the given
IOAS via the **pt_id**. The **data_type** for this allocation must be set to
IOMMU_HWPT_DATA_NONE. The HWPT can be allocated as a parent HWPT for a
nesting configuration by passing IOMMU_HWPT_ALLOC_NEST_PARENT via **flags**.

A user-managed nested HWPT will be created from a given vIOMMU (wrapping a
parent HWPT) or a parent HWPT via **pt_id**, in which the parent HWPT must be
allocated previously via the same ioctl from a given IOAS (**pt_id**). In this
case, the **data_type** must be set to a pre-defined type corresponding to an
I/O page table type supported by the underlying IOMMU hardware. The device
via **dev_id** and the vIOMMU via **pt_id** must be associated to the same IOMMU
instance.

If the **data_type** is set to IOMMU_HWPT_DATA_NONE, **data_len** and
**data_uptr** should be zero. Otherwise, both **data_len** and **data_uptr**
must be given.

#### <a id="c-enum-iommu_hw_info_vtd_flags"></a>`enum iommu_hw_info_vtd_flags`

Flags for VT-d hw_info

**Constants**

- `IOMMU_HW_INFO_VTD_ERRATA_772415_SPR17`: If set, disallow read-only mappings
  on a nested_parent domain.
  https://www.intel.com/content/www/us/en/content-details/772415/content-details.html

#### <a id="c-struct-iommu_hw_info_vtd"></a>`struct iommu_hw_info_vtd`

Intel VT-d hardware information

**Definition**

```c
struct iommu_hw_info_vtd {
    __u32 flags;
    __u32 __reserved;
    __aligned_u64 cap_reg;
    __aligned_u64 ecap_reg;
};
```

**Members**

- `flags`: Combination of enum iommu_hw_info_vtd_flags
- `__reserved`: Must be 0
- `cap_reg`: Value of Intel VT-d capability register defined in VT-d spec
  section 11.4.2 Capability Register.
- `ecap_reg`: Value of Intel VT-d capability register defined in VT-d spec
  section 11.4.3 Extended Capability Register.

**Description**

User needs to understand the Intel VT-d specification to decode the
register value.

#### <a id="c-struct-iommu_hw_info_arm_smmuv3"></a>`struct iommu_hw_info_arm_smmuv3`

ARM SMMUv3 hardware information (IOMMU_HW_INFO_TYPE_ARM_SMMUV3)

**Definition**

```c
struct iommu_hw_info_arm_smmuv3 {
    __u32 flags;
    __u32 __reserved;
    __u32 idr[6];
    __u32 iidr;
    __u32 aidr;
};
```

**Members**

- `flags`: Must be set to 0
- `__reserved`: Must be 0
- `idr`: Implemented features for ARM SMMU Non-secure programming interface
- `iidr`: Information about the implementation and implementer of ARM SMMU,
  and architecture version supported
- `aidr`: ARM SMMU architecture version

**Description**

For the details of **idr**, **iidr** and **aidr**, please refer to the chapters
from 6.3.1 to 6.3.6 in the SMMUv3 Spec.

This reports the raw HW capability, and not all bits are meaningful to be
read by userspace. Only the following fields should be used:

idr\[0\]: ST_LEVEL, TERM_MODEL, STALL_MODEL, TTENDIAN , CD2L, ASID16, TTF
idr\[1\]: SIDSIZE, SSIDSIZE
idr\[3\]: BBML, RIL
idr\[5\]: VAX, GRAN64K, GRAN16K, GRAN4K

- S1P should be assumed to be true if a NESTED HWPT can be created
- VFIO/iommufd only support platforms with COHACC, it should be assumed to be
  true.
- ATS is a per-device property. If the VMM describes any devices as ATS
  capable in ACPI/DT it should set the corresponding idr.

This list may expand in future (eg E0PD, AIE, PBHA, D128, DS etc). It is
important that VMMs do not read bits outside the list to allow for
compatibility with future kernels. Several features in the SMMUv3
architecture are not currently supported by the kernel for nesting: HTTU,
BTM, MPAM and others.

#### <a id="c-struct-iommu_hw_info_tegra241_cmdqv"></a>`struct iommu_hw_info_tegra241_cmdqv`

NVIDIA Tegra241 CMDQV Hardware Information (IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV)

**Definition**

```c
struct iommu_hw_info_tegra241_cmdqv {
    __u32 flags;
    __u8 version;
    __u8 log2vcmdqs;
    __u8 log2vsids;
    __u8 __reserved;
};
```

**Members**

- `flags`: Must be 0
- `version`: Version number for the CMDQ-V HW for PARAM bits\[03:00\]
- `log2vcmdqs`: Log2 of the total number of VCMDQs for PARAM bits\[07:04\]
- `log2vsids`: Log2 of the total number of SID replacements for PARAM bits\[15:12\]
- `__reserved`: Must be 0

**Description**

VMM can use these fields directly in its emulated global PARAM register. Note
that only one Virtual Interface (VINTF) should be exposed to a VM, i.e. PARAM
bits\[11:08\] should be set to 0 for log2 of the total number of VINTFs.

#### <a id="c-struct-iommu_hw_info_amd"></a>`struct iommu_hw_info_amd`

AMD IOMMU device info

**Definition**

```c
struct iommu_hw_info_amd {
    __aligned_u64 efr;
    __aligned_u64 efr2;
};
```

**Members**

- `efr`: Value of AMD IOMMU Extended Feature Register (EFR)
- `efr2`: Value of AMD IOMMU Extended Feature 2 Register (EFR2)

**Description**

Please See description of these registers in the following sections of
the AMD I/O Virtualization Technology (IOMMU) Specification.
(https://docs.amd.com/v/u/en-US/48882_3.10_PUB)

- MMIO Offset 0030h IOMMU Extended Feature Register
- MMIO Offset 01A0h IOMMU Extended Feature 2 Register

**Note**

The EFR and EFR2 are raw values reported by hardware.
VMM is responsible to determine the appropriate flags to be exposed to
the VM since cetertain features are not currently supported by the kernel
for HW-vIOMMU.

Current VMM-allowed list of feature flags are:
- EFR\[GTSup, GASup, GioSup, PPRSup, EPHSup, GATS, GLX, PASmax\]

#### <a id="c-enum-iommu_hw_info_type"></a>`enum iommu_hw_info_type`

IOMMU Hardware Info Types

**Constants**

- `IOMMU_HW_INFO_TYPE_NONE`: Output by the drivers that do not report hardware
  info
- `IOMMU_HW_INFO_TYPE_DEFAULT`: Input to request for a default type
- `IOMMU_HW_INFO_TYPE_INTEL_VTD`: Intel VT-d iommu info type
- `IOMMU_HW_INFO_TYPE_ARM_SMMUV3`: ARM SMMUv3 iommu info type
- `IOMMU_HW_INFO_TYPE_TEGRA241_CMDQV`: NVIDIA Tegra241 CMDQV (extension for ARM
  SMMUv3) info type
- `IOMMU_HW_INFO_TYPE_AMD`: AMD IOMMU info type

#### <a id="c-enum-iommufd_hw_capabilities"></a>`enum iommufd_hw_capabilities`

**Constants**

- `IOMMU_HW_CAP_DIRTY_TRACKING`: IOMMU hardware support for dirty tracking
  If available, it means the following APIs
  are supported:
- `IOMMU_HW_CAP_PCI_PASID_EXEC`: Execute Permission Supported, user ignores it
  when the struct
  iommu_hw_info::out_max_pasid_log2 is zero.
- `IOMMU_HW_CAP_PCI_PASID_PRIV`: Privileged Mode Supported, user ignores it
  when the struct
  iommu_hw_info::out_max_pasid_log2 is zero.

**Description**

IOMMU_HWPT_GET_DIRTY_BITMAP
IOMMU_HWPT_SET_DIRTY_TRACKING

#### <a id="c-enum-iommufd_hw_info_flags"></a>`enum iommufd_hw_info_flags`

Flags for iommu_hw_info

**Constants**

- `IOMMU_HW_INFO_FLAG_INPUT_TYPE`: If set, **in_data_type** carries an input type
  for user space to request for a specific info

#### <a id="c-struct-iommu_hw_info"></a>`struct iommu_hw_info`

ioctl(IOMMU_GET_HW_INFO)

**Definition**

```c
struct iommu_hw_info {
    __u32 size;
    __u32 flags;
    __u32 dev_id;
    __u32 data_len;
    __aligned_u64 data_uptr;
    union {
        __u32 in_data_type;
        __u32 out_data_type;
    };
    __u8 out_max_pasid_log2;
    __u8 __reserved[3];
    __aligned_u64 out_capabilities;
};
```

**Members**

- `size`: sizeof(struct iommu_hw_info)
- `flags`: Must be 0
- `dev_id`: The device bound to the iommufd
- `data_len`: Input the length of a user buffer in bytes. Output the length of
  data that kernel supports
- `data_uptr`: User pointer to a user-space buffer used by the kernel to fill
  the iommu type specific hardware information data
- `{unnamed_union}`: anonymous
- `in_data_type`: This shares the same field with **out_data_type**, making it be
  a bidirectional field. When IOMMU_HW_INFO_FLAG_INPUT_TYPE is
  set, an input type carried via this **in_data_type** field will
  be valid, requesting for the info data to the given type. If
  IOMMU_HW_INFO_FLAG_INPUT_TYPE is unset, any input value will
  be seen as IOMMU_HW_INFO_TYPE_DEFAULT
- `out_data_type`: Output the iommu hardware info type as defined in the enum
  iommu_hw_info_type.
- `out_max_pasid_log2`: Output the width of PASIDs. 0 means no PASID support.
  PCI devices turn to out_capabilities to check if the
  specific capabilities is supported or not.
- `__reserved`: Must be 0
- `out_capabilities`: Output the generic iommu capability info type as defined
  in the enum iommu_hw_capabilities.

**Description**

Query an iommu type specific hardware information data from an iommu behind
a given device that has been bound to iommufd. This hardware info data will
be used to sync capabilities between the virtual iommu and the physical
iommu, e.g. a nested translation setup needs to check the hardware info, so
a guest stage-1 page table can be compatible with the physical iommu.

To capture an iommu type specific hardware information data, **data_uptr** and
its length **data_len** must be provided. Trailing bytes will be zeroed if the
user buffer is larger than the data that kernel has. Otherwise, kernel only
fills the buffer using the given length in **data_len**. If the ioctl succeeds,
**data_len** will be updated to the length that kernel actually supports,
**out_data_type** will be filled to decode the data filled in the buffer
pointed by **data_uptr**. Input **data_len** == zero is allowed.

#### <a id="c-struct-iommu_hwpt_set_dirty_tracking"></a>`struct iommu_hwpt_set_dirty_tracking`

ioctl(IOMMU_HWPT_SET_DIRTY_TRACKING)

**Definition**

```c
struct iommu_hwpt_set_dirty_tracking {
    __u32 size;
    __u32 flags;
    __u32 hwpt_id;
    __u32 __reserved;
};
```

**Members**

- `size`: sizeof(struct iommu_hwpt_set_dirty_tracking)
- `flags`: Combination of enum iommufd_hwpt_set_dirty_tracking_flags
- `hwpt_id`: HW pagetable ID that represents the IOMMU domain
- `__reserved`: Must be 0

**Description**

Toggle dirty tracking on an HW pagetable.

#### <a id="c-enum-iommufd_hwpt_get_dirty_bitmap_flags"></a>`enum iommufd_hwpt_get_dirty_bitmap_flags`

Flags for getting dirty bits

**Constants**

- `IOMMU_HWPT_GET_DIRTY_BITMAP_NO_CLEAR`: Just read the PTEs without clearing
  any dirty bits metadata. This flag
  can be passed in the expectation
  where the next operation is an unmap
  of the same IOVA range.

#### <a id="c-struct-iommu_hwpt_get_dirty_bitmap"></a>`struct iommu_hwpt_get_dirty_bitmap`

ioctl(IOMMU_HWPT_GET_DIRTY_BITMAP)

**Definition**

```c
struct iommu_hwpt_get_dirty_bitmap {
    __u32 size;
    __u32 hwpt_id;
    __u32 flags;
    __u32 __reserved;
    __aligned_u64 iova;
    __aligned_u64 length;
    __aligned_u64 page_size;
    __aligned_u64 data;
};
```

**Members**

- `size`: sizeof(struct iommu_hwpt_get_dirty_bitmap)
- `hwpt_id`: HW pagetable ID that represents the IOMMU domain
- `flags`: Combination of enum iommufd_hwpt_get_dirty_bitmap_flags
- `__reserved`: Must be 0
- `iova`: base IOVA of the bitmap first bit
- `length`: IOVA range size
- `page_size`: page size granularity of each bit in the bitmap
- `data`: bitmap where to set the dirty bits. The bitmap bits each
  represent a page_size which you deviate from an arbitrary iova.

**Description**

Checking a given IOVA is dirty:

data\[(iova / page_size) / 64\] & (1ULL \<\< ((iova / page_size) % 64))

Walk the IOMMU pagetables for a given IOVA range to return a bitmap
with the dirty IOVAs. In doing so it will also by default clear any
dirty bit metadata set in the IOPTE.

#### <a id="c-enum-iommu_hwpt_invalidate_data_type"></a>`enum iommu_hwpt_invalidate_data_type`

IOMMU HWPT Cache Invalidation Data Type

**Constants**

- `IOMMU_HWPT_INVALIDATE_DATA_VTD_S1`: Invalidation data for VTD_S1
- `IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3`: Invalidation data for ARM SMMUv3

#### <a id="c-enum-iommu_hwpt_vtd_s1_invalidate_flags"></a>`enum iommu_hwpt_vtd_s1_invalidate_flags`

Flags for Intel VT-d stage-1 cache invalidation

**Constants**

- `IOMMU_VTD_INV_FLAGS_LEAF`: Indicates whether the invalidation applies
  to all-levels page structure cache or just
  the leaf PTE cache.

#### <a id="c-struct-iommu_hwpt_vtd_s1_invalidate"></a>`struct iommu_hwpt_vtd_s1_invalidate`

Intel VT-d cache invalidation (IOMMU_HWPT_INVALIDATE_DATA_VTD_S1)

**Definition**

```c
struct iommu_hwpt_vtd_s1_invalidate {
    __aligned_u64 addr;
    __aligned_u64 npages;
    __u32 flags;
    __u32 __reserved;
};
```

**Members**

- `addr`: The start address of the range to be invalidated. It needs to
  be 4KB aligned.
- `npages`: Number of contiguous 4K pages to be invalidated.
- `flags`: Combination of enum iommu_hwpt_vtd_s1_invalidate_flags
- `__reserved`: Must be 0

**Description**

The Intel VT-d specific invalidation data for user-managed stage-1 cache
invalidation in nested translation. Userspace uses this structure to
tell the impacted cache scope after modifying the stage-1 page table.

Invalidating all the caches related to the page table by setting **addr**
to be 0 and **npages** to be U64_MAX.

The device TLB will be invalidated automatically if ATS is enabled.

#### <a id="c-struct-iommu_viommu_arm_smmuv3_invalidate"></a>`struct iommu_viommu_arm_smmuv3_invalidate`

ARM SMMUv3 cache invalidation (IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3)

**Definition**

```c
struct iommu_viommu_arm_smmuv3_invalidate {
    __aligned_le64 cmd[2];
};
```

**Members**

- `cmd`: 128-bit cache invalidation command that runs in SMMU CMDQ.
  Must be little-endian.

**Description**

- Supported command list only when passing in a vIOMMU via **hwpt_id**:
  CMDQ_OP_TLBI_NSNH_ALL
  CMDQ_OP_TLBI_NH_VA
  CMDQ_OP_TLBI_NH_VAA
  CMDQ_OP_TLBI_NH_ALL
  CMDQ_OP_TLBI_NH_ASID
  CMDQ_OP_ATC_INV
  CMDQ_OP_CFGI_CD
  CMDQ_OP_CFGI_CD_ALL

-EIO will be returned if the command is not supported.

#### <a id="c-struct-iommu_hwpt_invalidate"></a>`struct iommu_hwpt_invalidate`

ioctl(IOMMU_HWPT_INVALIDATE)

**Definition**

```c
struct iommu_hwpt_invalidate {
    __u32 size;
    __u32 hwpt_id;
    __aligned_u64 data_uptr;
    __u32 data_type;
    __u32 entry_len;
    __u32 entry_num;
    __u32 __reserved;
};
```

**Members**

- `size`: sizeof(struct iommu_hwpt_invalidate)
- `hwpt_id`: ID of a nested HWPT or a vIOMMU, for cache invalidation
- `data_uptr`: User pointer to an array of driver-specific cache invalidation
  data.
- `data_type`: One of enum iommu_hwpt_invalidate_data_type, defining the data
  type of all the entries in the invalidation request array. It
  should be a type supported by the hwpt pointed by **hwpt_id**.
- `entry_len`: Length (in bytes) of a request entry in the request array
- `entry_num`: Input the number of cache invalidation requests in the array.
  Output the number of requests successfully handled by kernel.
- `__reserved`: Must be 0.

**Description**

Invalidate iommu cache for user-managed page table or vIOMMU. Modifications
on a user-managed page table should be followed by this operation, if a HWPT
is passed in via **hwpt_id**. Other caches, such as device cache or descriptor
cache can be flushed if a vIOMMU is passed in via the **hwpt_id** field.

Each ioctl can support one or more cache invalidation requests in the array
that has a total size of **entry_len** * **entry_num**.

An empty invalidation request array by setting **entry_num**==0 is allowed, and
**entry_len** and **data_uptr** would be ignored in this case. This can be used to
check if the given **data_type** is supported or not by kernel.

#### <a id="c-enum-iommu_hwpt_pgfault_flags"></a>`enum iommu_hwpt_pgfault_flags`

flags for struct iommu_hwpt_pgfault

**Constants**

- `IOMMU_PGFAULT_FLAGS_PASID_VALID`: The pasid field of the fault data is
  valid.
- `IOMMU_PGFAULT_FLAGS_LAST_PAGE`: It's the last fault of a fault group.

#### <a id="c-enum-iommu_hwpt_pgfault_perm"></a>`enum iommu_hwpt_pgfault_perm`

perm bits for struct iommu_hwpt_pgfault

**Constants**

- `IOMMU_PGFAULT_PERM_READ`: request for read permission
- `IOMMU_PGFAULT_PERM_WRITE`: request for write permission
- `IOMMU_PGFAULT_PERM_EXEC`: (PCIE 10.4.1) request with a PASID that has the
  Execute Requested bit set in PASID TLP Prefix.
- `IOMMU_PGFAULT_PERM_PRIV`: (PCIE 10.4.1) request with a PASID that has the
  Privileged Mode Requested bit set in PASID TLP
  Prefix.

#### <a id="c-struct-iommu_hwpt_pgfault"></a>`struct iommu_hwpt_pgfault`

iommu page fault data

**Definition**

```c
struct iommu_hwpt_pgfault {
    __u32 flags;
    __u32 dev_id;
    __u32 pasid;
    __u32 grpid;
    __u32 perm;
    __u32 __reserved;
    __aligned_u64 addr;
    __u32 length;
    __u32 cookie;
};
```

**Members**

- `flags`: Combination of enum iommu_hwpt_pgfault_flags
- `dev_id`: id of the originated device
- `pasid`: Process Address Space ID
- `grpid`: Page Request Group Index
- `perm`: Combination of enum iommu_hwpt_pgfault_perm
- `__reserved`: Must be 0.
- `addr`: Fault address
- `length`: a hint of how much data the requestor is expecting to fetch. For
  example, if the PRI initiator knows it is going to do a 10MB
  transfer, it could fill in 10MB and the OS could pre-fault in
  10MB of IOVA. It's default to 0 if there's no such hint.
- `cookie`: kernel-managed cookie identifying a group of fault messages. The
  cookie number encoded in the last page fault of the group should
  be echoed back in the response message.

#### <a id="c-enum-iommufd_page_response_code"></a>`enum iommufd_page_response_code`

Return status of fault handlers

**Constants**

- `IOMMUFD_PAGE_RESP_SUCCESS`: Fault has been handled and the page tables
  populated, retry the access. This is the
  "Success" defined in PCI 10.4.2.1.
- `IOMMUFD_PAGE_RESP_INVALID`: Could not handle this fault, don't retry the
  access. This is the "Invalid Request" in PCI
  10.4.2.1.

#### <a id="c-struct-iommu_hwpt_page_response"></a>`struct iommu_hwpt_page_response`

IOMMU page fault response

**Definition**

```c
struct iommu_hwpt_page_response {
    __u32 cookie;
    __u32 code;
};
```

**Members**

- `cookie`: The kernel-managed cookie reported in the fault message.
- `code`: One of response code in enum iommufd_page_response_code.

#### <a id="c-struct-iommu_fault_alloc"></a>`struct iommu_fault_alloc`

ioctl(IOMMU_FAULT_QUEUE_ALLOC)

**Definition**

```c
struct iommu_fault_alloc {
    __u32 size;
    __u32 flags;
    __u32 out_fault_id;
    __u32 out_fault_fd;
};
```

**Members**

- `size`: sizeof(struct iommu_fault_alloc)
- `flags`: Must be 0
- `out_fault_id`: The ID of the new FAULT
- `out_fault_fd`: The fd of the new FAULT

**Description**

Explicitly allocate a fault handling object.

#### <a id="c-enum-iommu_viommu_type"></a>`enum iommu_viommu_type`

Virtual IOMMU Type

**Constants**

- `IOMMU_VIOMMU_TYPE_DEFAULT`: Reserved for future use
- `IOMMU_VIOMMU_TYPE_ARM_SMMUV3`: ARM SMMUv3 driver specific type
- `IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV`: NVIDIA Tegra241 CMDQV (extension for ARM
  SMMUv3) enabled ARM SMMUv3 type

#### <a id="c-struct-iommu_viommu_tegra241_cmdqv"></a>`struct iommu_viommu_tegra241_cmdqv`

NVIDIA Tegra241 CMDQV Virtual Interface (IOMMU_VIOMMU_TYPE_TEGRA241_CMDQV)

**Definition**

```c
struct iommu_viommu_tegra241_cmdqv {
    __aligned_u64 out_vintf_mmap_offset;
    __aligned_u64 out_vintf_mmap_length;
};
```

**Members**

- `out_vintf_mmap_offset`: mmap offset argument for VINTF's page0
- `out_vintf_mmap_length`: mmap length argument for VINTF's page0

**Description**

Both **out_vintf_mmap_offset** and **out_vintf_mmap_length** are reported by kernel
for user space to mmap the VINTF page0 from the host physical address space
to the guest physical address space so that a guest kernel can directly R/W
access to the VINTF page0 in order to control its virtual command queues.

#### <a id="c-struct-iommu_viommu_alloc"></a>`struct iommu_viommu_alloc`

ioctl(IOMMU_VIOMMU_ALLOC)

**Definition**

```c
struct iommu_viommu_alloc {
    __u32 size;
    __u32 flags;
    __u32 type;
    __u32 dev_id;
    __u32 hwpt_id;
    __u32 out_viommu_id;
    __u32 data_len;
    __u32 __reserved;
    __aligned_u64 data_uptr;
};
```

**Members**

- `size`: sizeof(struct iommu_viommu_alloc)
- `flags`: Must be 0
- `type`: Type of the virtual IOMMU. Must be defined in enum iommu_viommu_type
- `dev_id`: The device's physical IOMMU will be used to back the virtual IOMMU
- `hwpt_id`: ID of a nesting parent HWPT to associate to
- `out_viommu_id`: Output virtual IOMMU ID for the allocated object
- `data_len`: Length of the type specific data
- `__reserved`: Must be 0
- `data_uptr`: User pointer to a driver-specific virtual IOMMU data

**Description**

Allocate a virtual IOMMU object, representing the underlying physical IOMMU's
virtualization support that is a security-isolated slice of the real IOMMU HW
that is unique to a specific VM. Operations global to the IOMMU are connected
to the vIOMMU, such as:
- Security namespace for guest owned ID, e.g. guest-controlled cache tags
- Non-device-affiliated event reporting, e.g. invalidation queue errors
- Access to a sharable nesting parent pagetable across physical IOMMUs
- Virtualization of various platforms IDs, e.g. RIDs and others
- Delivery of paravirtualized invalidation
- Direct assigned invalidation queues
- Direct assigned interrupts

#### <a id="c-struct-iommu_vdevice_alloc"></a>`struct iommu_vdevice_alloc`

ioctl(IOMMU_VDEVICE_ALLOC)

**Definition**

```c
struct iommu_vdevice_alloc {
    __u32 size;
    __u32 viommu_id;
    __u32 dev_id;
    __u32 out_vdevice_id;
    __aligned_u64 virt_id;
};
```

**Members**

- `size`: sizeof(struct iommu_vdevice_alloc)
- `viommu_id`: vIOMMU ID to associate with the virtual device
- `dev_id`: The physical device to allocate a virtual instance on the vIOMMU
- `out_vdevice_id`: Object handle for the vDevice. Pass to IOMMU_DESTORY
- `virt_id`: Virtual device ID per vIOMMU, e.g. vSID of ARM SMMUv3, vDeviceID
  of AMD IOMMU, and vRID of Intel VT-d

**Description**

Allocate a virtual device instance (for a physical device) against a vIOMMU.
This instance holds the device's information (related to its vIOMMU) in a VM.
User should use IOMMU_DESTROY to destroy the virtual device before
destroying the physical device (by closing vfio_cdev fd). Otherwise the
virtual device would be forcibly destroyed on physical device destruction,
its vdevice_id would be permanently leaked (unremovable & unreusable) until
iommu fd closed.

#### <a id="c-struct-iommu_ioas_change_process"></a>`struct iommu_ioas_change_process`

ioctl(VFIO_IOAS_CHANGE_PROCESS)

**Definition**

```c
struct iommu_ioas_change_process {
    __u32 size;
    __u32 __reserved;
};
```

**Members**

- `size`: sizeof(struct iommu_ioas_change_process)
- `__reserved`: Must be 0

**Description**

This transfers pinned memory counts for every memory map in every IOAS
in the context to the current process.  This only supports maps created
with IOMMU_IOAS_MAP_FILE, and returns EINVAL if other maps are present.
If the ioctl returns a failure status, then nothing is changed.

This API is useful for transferring operation of a device from one process
to another, such as during userland live update.

#### <a id="c-enum-iommu_veventq_flag"></a>`enum iommu_veventq_flag`

flag for struct iommufd_vevent_header

**Constants**

- `IOMMU_VEVENTQ_FLAG_LOST_EVENTS`: vEVENTQ has lost vEVENTs

#### <a id="c-struct-iommufd_vevent_header"></a>`struct iommufd_vevent_header`

Virtual Event Header for a vEVENTQ Status

**Definition**

```c
struct iommufd_vevent_header {
    __u32 flags;
    __u32 sequence;
};
```

**Members**

- `flags`: Combination of enum iommu_veventq_flag
- `sequence`: The sequence index of a vEVENT in the vEVENTQ, with a range of
  \[0, INT_MAX\] where the following index of INT_MAX is 0

**Description**

Each iommufd_vevent_header reports a sequence index of the following vEVENT:

```text
+----------------------+-------+----------------------+-------+---+-------+
| header0 {sequence=0} | data0 | header1 {sequence=1} | data1 |...| dataN |
+----------------------+-------+----------------------+-------+---+-------+
```

And this sequence index is expected to be monotonic to the sequence index of
the previous vEVENT. If two adjacent sequence indexes has a delta larger than
1, it means that delta - 1 number of vEVENTs has lost, e.g. two lost vEVENTs:

```text
+-----+----------------------+-------+----------------------+-------+-----+
| ... | header3 {sequence=3} | data3 | header6 {sequence=6} | data6 | ... |
+-----+----------------------+-------+----------------------+-------+-----+
```

If a vEVENT lost at the tail of the vEVENTQ and there is no following vEVENT
providing the next sequence index, an IOMMU_VEVENTQ_FLAG_LOST_EVENTS header
would be added to the tail, and no data would follow this header:

```text
+--+----------------------+-------+-----------------------------------------+
|..| header3 {sequence=3} | data3 | header4 {flags=LOST_EVENTS, sequence=4} |
+--+----------------------+-------+-----------------------------------------+
```

#### <a id="c-enum-iommu_veventq_type"></a>`enum iommu_veventq_type`

Virtual Event Queue Type

**Constants**

- `IOMMU_VEVENTQ_TYPE_DEFAULT`: Reserved for future use
- `IOMMU_VEVENTQ_TYPE_ARM_SMMUV3`: ARM SMMUv3 Virtual Event Queue
- `IOMMU_VEVENTQ_TYPE_TEGRA241_CMDQV`: NVIDIA Tegra241 CMDQV Extension IRQ

#### <a id="c-struct-iommu_vevent_arm_smmuv3"></a>`struct iommu_vevent_arm_smmuv3`

ARM SMMUv3 Virtual Event (IOMMU_VEVENTQ_TYPE_ARM_SMMUV3)

**Definition**

```c
struct iommu_vevent_arm_smmuv3 {
    __aligned_le64 evt[4];
};
```

**Members**

- `evt`: 256-bit ARM SMMUv3 Event record, little-endian.
  Reported event records: (Refer to "7.3 Event records" in SMMUv3 HW Spec)
  - 0x04 C_BAD_STE
  - 0x06 F_STREAM_DISABLED
  - 0x08 C_BAD_SUBSTREAMID
  - 0x0a C_BAD_CD
  - 0x10 F_TRANSLATION
  - 0x11 F_ADDR_SIZE
  - 0x12 F_ACCESS
  - 0x13 F_PERMISSION

**Description**

StreamID field reports a virtual device ID. To receive a virtual event for a
device, a vDEVICE must be allocated via IOMMU_VDEVICE_ALLOC.

#### <a id="c-struct-iommu_vevent_tegra241_cmdqv"></a>`struct iommu_vevent_tegra241_cmdqv`

Tegra241 CMDQV IRQ (IOMMU_VEVENTQ_TYPE_TEGRA241_CMDQV)

**Definition**

```c
struct iommu_vevent_tegra241_cmdqv {
    __aligned_le64 lvcmdq_err_map[2];
};
```

**Members**

- `lvcmdq_err_map`: 128-bit logical vcmdq error map, little-endian.
  (Refer to register LVCMDQ_ERR_MAPs per VINTF )

**Description**

The 128-bit register value from HW exclusively reflect the error bits for a
Virtual Interface represented by a vIOMMU object. Read and report directly.

#### <a id="c-struct-iommu_veventq_alloc"></a>`struct iommu_veventq_alloc`

ioctl(IOMMU_VEVENTQ_ALLOC)

**Definition**

```c
struct iommu_veventq_alloc {
    __u32 size;
    __u32 flags;
    __u32 viommu_id;
    __u32 type;
    __u32 veventq_depth;
    __u32 out_veventq_id;
    __u32 out_veventq_fd;
    __u32 __reserved;
};
```

**Members**

- `size`: sizeof(struct iommu_veventq_alloc)
- `flags`: Must be 0
- `viommu_id`: virtual IOMMU ID to associate the vEVENTQ with
- `type`: Type of the vEVENTQ. Must be defined in enum iommu_veventq_type
- `veventq_depth`: Maximum number of events in the vEVENTQ
- `out_veventq_id`: The ID of the new vEVENTQ
- `out_veventq_fd`: The fd of the new vEVENTQ. User space must close the
  successfully returned fd after using it
- `__reserved`: Must be 0

**Description**

Explicitly allocate a virtual event queue interface for a vIOMMU. A vIOMMU
can have multiple FDs for different types, but is confined to one per **type**.
User space should open the **out_veventq_fd** to read vEVENTs out of a vEVENTQ,
if there are vEVENTs available. A vEVENTQ will lose events due to overflow,
if the number of the vEVENTs hits **veventq_depth**.

Each vEVENT in a vEVENTQ encloses a struct iommufd_vevent_header followed by
a type-specific data structure, in a normal case:

```text
+-+---------+-------+---------+-------+-----+---------+-------+-+
| | header0 | data0 | header1 | data1 | ... | headerN | dataN | |
+-+---------+-------+---------+-------+-----+---------+-------+-+
```

unless a tailing IOMMU_VEVENTQ_FLAG_LOST_EVENTS header is logged (refer to
struct iommufd_vevent_header).

#### <a id="c-enum-iommu_hw_queue_type"></a>`enum iommu_hw_queue_type`

HW Queue Type

**Constants**

- `IOMMU_HW_QUEUE_TYPE_DEFAULT`: Reserved for future use
- `IOMMU_HW_QUEUE_TYPE_TEGRA241_CMDQV`: NVIDIA Tegra241 CMDQV (extension for ARM
  SMMUv3) Virtual Command Queue (VCMDQ)

#### <a id="c-struct-iommu_hw_queue_alloc"></a>`struct iommu_hw_queue_alloc`

ioctl(IOMMU_HW_QUEUE_ALLOC)

**Definition**

```c
struct iommu_hw_queue_alloc {
    __u32 size;
    __u32 flags;
    __u32 viommu_id;
    __u32 type;
    __u32 index;
    __u32 out_hw_queue_id;
    __aligned_u64 nesting_parent_iova;
    __aligned_u64 length;
};
```

**Members**

- `size`: sizeof(struct iommu_hw_queue_alloc)
- `flags`: Must be 0
- `viommu_id`: Virtual IOMMU ID to associate the HW queue with
- `type`: One of enum iommu_hw_queue_type
- `index`: The logical index to the HW queue per virtual IOMMU for a multi-queue
  model
- `out_hw_queue_id`: The ID of the new HW queue
- `nesting_parent_iova`: Base address of the queue memory in the guest physical
  address space
- `length`: Length of the queue memory

**Description**

Allocate a HW queue object for a vIOMMU-specific HW-accelerated queue, which
allows HW to access a guest queue memory described using **nesting_parent_iova**
and **length**.

A vIOMMU can allocate multiple queues, but it must use a different **index** per
type to separate each allocation, e.g:

```text
Type1 HW queue0, Type1 HW queue1, Type2 HW queue0, ...
```


<a id="rst-iommufd-kernel-api"></a>

## IOMMUFD Kernel API

The IOMMUFD kAPI is device-centric with group-related tricks managed behind the scene. This allows the external drivers calling such kAPI to implement a simple device-centric uAPI for connecting its device to an iommufd, instead of explicitly imposing the group semantics in its uAPI as VFIO does.


#### <a id="c-iommufd_device_bind"></a>`iommufd_device_bind()`

```c
struct iommufd_device * iommufd_device_bind(struct iommufd_ctx *ictx, struct device *dev, u32 *id)
```

Bind a physical device to an iommu fd

**Parameters**

- `struct iommufd_ctx *ictx`: iommufd file descriptor
- `struct device *dev`: Pointer to a physical device struct
- `u32 *id`: Output ID number to return to userspace for this device

**Description**

A successful bind establishes an ownership over the device and returns
struct iommufd_device pointer, otherwise returns error pointer.

A driver using this API must set driver_managed_dma and must not touch
the device until this routine succeeds and establishes ownership.

Binding a PCI device places the entire RID under iommufd control.

The caller must undo this with [`iommufd_device_unbind()`](#c-iommufd_device_unbind)

#### <a id="c-iommufd_ctx_has_group"></a>`iommufd_ctx_has_group()`

```c
bool iommufd_ctx_has_group(struct iommufd_ctx *ictx, struct iommu_group *group)
```

True if any device within the group is bound to the ictx

**Parameters**

- `struct iommufd_ctx *ictx`: iommufd file descriptor
- `struct iommu_group *group`: Pointer to a physical iommu_group struct

**Description**

True if any device within the group has been bound to this ictx, ex. via
[`iommufd_device_bind()`](#c-iommufd_device_bind), therefore implying ictx ownership of the group.

#### <a id="c-iommufd_device_unbind"></a>`iommufd_device_unbind()`

```c
void iommufd_device_unbind(struct iommufd_device *idev)
```

Undo [`iommufd_device_bind()`](#c-iommufd_device_bind)

**Parameters**

- `struct iommufd_device *idev`: Device returned by [`iommufd_device_bind()`](#c-iommufd_device_bind)

**Description**

Release the device from iommufd control. The DMA ownership will return back
to unowned with DMA controlled by the DMA API. This invalidates the
iommufd_device pointer, other APIs that consume it must not be called
concurrently.

#### <a id="c-iommufd_device_attach"></a>`iommufd_device_attach()`

```c
int iommufd_device_attach(struct iommufd_device *idev, ioasid_t pasid, u32 *pt_id)
```

Connect a device/pasid to an iommu_domain

**Parameters**

- `struct iommufd_device *idev`: device to attach
- `ioasid_t pasid`: pasid to attach
- `u32 *pt_id`: Input a IOMMUFD_OBJ_IOAS, or IOMMUFD_OBJ_HWPT_PAGING
  Output the IOMMUFD_OBJ_HWPT_PAGING ID

**Description**

This connects the device/pasid to an iommu_domain, either automatically
or manually selected. Once this completes the device could do DMA with
**pasid**. **pasid** is IOMMU_NO_PASID if this attach is for no pasid usage.

The caller should return the resulting pt_id back to userspace.
This function is undone by calling [`iommufd_device_detach()`](#c-iommufd_device_detach).

#### <a id="c-iommufd_device_replace"></a>`iommufd_device_replace()`

```c
int iommufd_device_replace(struct iommufd_device *idev, ioasid_t pasid, u32 *pt_id)
```

Change the device/pasid's iommu_domain

**Parameters**

- `struct iommufd_device *idev`: device to change
- `ioasid_t pasid`: pasid to change
- `u32 *pt_id`: Input a IOMMUFD_OBJ_IOAS, or IOMMUFD_OBJ_HWPT_PAGING
  Output the IOMMUFD_OBJ_HWPT_PAGING ID

**Description**

This is the same as:

```text
iommufd_device_detach();
iommufd_device_attach();
```

If it fails then no change is made to the attachment. The iommu driver may
implement this so there is no disruption in translation. This can only be
called if [`iommufd_device_attach()`](#c-iommufd_device_attach) has already succeeded. **pasid** is
IOMMU_NO_PASID for no pasid usage.

#### <a id="c-iommufd_device_detach"></a>`iommufd_device_detach()`

```c
void iommufd_device_detach(struct iommufd_device *idev, ioasid_t pasid)
```

Disconnect a device/device to an iommu_domain

**Parameters**

- `struct iommufd_device *idev`: device to detach
- `ioasid_t pasid`: pasid to detach

**Description**

Undo [`iommufd_device_attach()`](#c-iommufd_device_attach). This disconnects the idev from the previously
attached pt_id. The device returns back to a blocked DMA translation.
**pasid** is IOMMU_NO_PASID for no pasid usage.

#### <a id="c-iommufd_access_create"></a>`iommufd_access_create()`

```c
struct iommufd_access * iommufd_access_create(struct iommufd_ctx *ictx, const struct iommufd_access_ops *ops, void *data, u32 *id)
```

Create an iommufd_access

**Parameters**

- `struct iommufd_ctx *ictx`: iommufd file descriptor
- `const struct iommufd_access_ops *ops`: Driver's ops to associate with the access
- `void *data`: Opaque data to pass into ops functions
- `u32 *id`: Output ID number to return to userspace for this access

**Description**

An iommufd_access allows a driver to read/write to the IOAS without using
DMA. The underlying CPU memory can be accessed using the
[`iommufd_access_pin_pages()`](#c-iommufd_access_pin_pages) or [`iommufd_access_rw()`](#c-iommufd_access_rw) functions.

The provided ops are required to use [`iommufd_access_pin_pages()`](#c-iommufd_access_pin_pages).

#### <a id="c-iommufd_access_destroy"></a>`iommufd_access_destroy()`

```c
void iommufd_access_destroy(struct iommufd_access *access)
```

Destroy an iommufd_access

**Parameters**

- `struct iommufd_access *access`: The access to destroy

**Description**

The caller must stop using the access before destroying it.

#### <a id="c-iommufd_access_unpin_pages"></a>`iommufd_access_unpin_pages()`

```c
void iommufd_access_unpin_pages(struct iommufd_access *access, unsigned long iova, unsigned long length)
```

Undo iommufd_access_pin_pages

**Parameters**

- `struct iommufd_access *access`: IOAS access to act on
- `unsigned long iova`: Starting IOVA
- `unsigned long length`: Number of bytes to access

**Description**

Return the struct page's. The caller must stop accessing them before calling
this. The iova/length must exactly match the one provided to access_pages.

#### <a id="c-iommufd_access_pin_pages"></a>`iommufd_access_pin_pages()`

```c
int iommufd_access_pin_pages(struct iommufd_access *access, unsigned long iova, unsigned long length, struct page **out_pages, unsigned int flags)
```

Return a list of pages under the iova

**Parameters**

- `struct iommufd_access *access`: IOAS access to act on
- `unsigned long iova`: Starting IOVA
- `unsigned long length`: Number of bytes to access
- `struct page **out_pages`: Output page list
- `unsigned int flags`: IOPMMUFD_ACCESS_RW_* flags

**Description**

Reads **length** bytes starting at iova and returns the struct page * pointers.
These can be kmap'd by the caller for CPU access.

The caller must perform [`iommufd_access_unpin_pages()`](#c-iommufd_access_unpin_pages) when done to balance
this.

This API always requires a page aligned iova. This happens naturally if the
ioas alignment is >= PAGE_SIZE and the iova is PAGE_SIZE aligned. However
smaller alignments have corner cases where this API can fail on otherwise
aligned iova.

#### <a id="c-iommufd_access_rw"></a>`iommufd_access_rw()`

```c
int iommufd_access_rw(struct iommufd_access *access, unsigned long iova, void *data, size_t length, unsigned int flags)
```

Read or write data under the iova

**Parameters**

- `struct iommufd_access *access`: IOAS access to act on
- `unsigned long iova`: Starting IOVA
- `void *data`: Kernel buffer to copy to/from
- `size_t length`: Number of bytes to access
- `unsigned int flags`: IOMMUFD_ACCESS_RW_* flags

**Description**

Copy kernel to/from data into the range given by IOVA/length. If flags
indicates IOMMUFD_ACCESS_RW_KTHREAD then a large copy can be optimized
by changing it into copy_to/`from_user()`.



#### <a id="c-iommufd_ctx_get"></a>`iommufd_ctx_get()`

```c
void iommufd_ctx_get(struct iommufd_ctx *ictx)
```

Get a context reference

**Parameters**

- `struct iommufd_ctx *ictx`: Context to get

**Description**

The caller must already hold a valid reference to ictx.

#### <a id="c-iommufd_ctx_from_file"></a>`iommufd_ctx_from_file()`

```c
struct iommufd_ctx * iommufd_ctx_from_file(struct file *file)
```

Acquires a reference to the iommufd context

**Parameters**

- `struct file *file`: File to obtain the reference from

**Description**

Returns a pointer to the iommufd_ctx, otherwise ERR_PTR. The struct file
remains owned by the caller and the caller must still do fput. On success
the caller is responsible to call [`iommufd_ctx_put()`](#c-iommufd_ctx_put).

#### <a id="c-iommufd_ctx_from_fd"></a>`iommufd_ctx_from_fd()`

```c
struct iommufd_ctx * iommufd_ctx_from_fd(int fd)
```

Acquires a reference to the iommufd context

**Parameters**

- `int fd`: File descriptor to obtain the reference from

**Description**

Returns a pointer to the iommufd_ctx, otherwise ERR_PTR. On success
the caller is responsible to call [`iommufd_ctx_put()`](#c-iommufd_ctx_put).

#### <a id="c-iommufd_ctx_put"></a>`iommufd_ctx_put()`

```c
void iommufd_ctx_put(struct iommufd_ctx *ictx)
```

Put back a reference

**Parameters**

- `struct iommufd_ctx *ictx`: Context to put back


<a id="rst-vfio-and-iommufd"></a>

### VFIO and IOMMUFD

Connecting a VFIO device to iommufd can be done in two ways.

First is a VFIO compatible way by directly implementing the /dev/vfio/vfio container IOCTLs by mapping them into io_pagetable operations. Doing so allows the use of iommufd in legacy VFIO applications by symlinking /dev/vfio/vfio to /dev/iommufd or extending VFIO to SET_CONTAINER using an iommufd instead of a container fd.

The second approach directly extends VFIO to support a new set of device-centric user API based on aforementioned IOMMUFD kernel API. It requires userspace change but better matches the IOMMUFD API semantics and easier to support new iommufd features when comparing it to the first approach.

Currently both approaches are still work-in-progress.

There are still a few gaps to be resolved to catch up with VFIO type1, as documented in iommufd_vfio_check_extension().

<a id="rst-future-todos"></a>

## Future TODOs

Currently IOMMUFD supports only kernel-managed I/O page table, similar to VFIO type1. New features on the radar include:

> - Binding iommu_domain's to PASID/SSID
>
> - Userspace page tables, for ARM, x86 and S390
>
> - Kernel bypass'd invalidation of user page tables
>
> - Re-use of the KVM page table in the IOMMU
>
> - Dirty page tracking in the IOMMU
>
> - Runtime Increase/Decrease of IOPTE size
>
> - PRI support with faults resolved in userspace

---

# Introduction of mseal

_Peios Kernel / Userspace interfaces / System and device interfaces / Memory and device access_

> Modern CPUs support memory permissions such as RW and NX bits. The memory permission feature improves security stance on memory corruption bugs, i.e. the attacker can’t just write to arbitrary memory and point the code to it, the memory…

<a id="rst-introduction-of-mseal"></a>

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

**Author:** Jeff Xu &lt;[jeffxu@chromium.org](<mailto:jeffxu@chromium.org>)&gt;

Modern CPUs support memory permissions such as RW and NX bits. The memory permission feature improves security stance on memory corruption bugs, i.e. the attacker can’t just write to arbitrary memory and point the code to it, the memory has to be marked with X bit, or else an exception will happen.

Memory sealing additionally protects the mapping itself against modifications. This is useful to mitigate memory corruption issues where a corrupted pointer is passed to a memory management system. For example, such an attacker primitive can break control-flow integrity guarantees since read-only memory that is supposed to be trusted can become writable or .text pages can get remapped. Memory sealing can automatically be applied by the runtime loader to seal .text and .rodata pages and applications can additionally seal security critical data at runtime.

A similar feature already exists in the XNU kernel with the VM_FLAGS_PERMANENT flag \[1\] and on OpenBSD with the mimmutable syscall \[2\].

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

## SYSCALL

<a id="rst-mseal-syscall-signature"></a>

### mseal syscall signature

> `int mseal(void *addr, size_t len, unsigned long flags)`
>
> - ****addr**/**len**: virtual memory address range.**
>
>   - **The address range set by **addr**/**len** must meet:**
>
>     - The start address must be in an allocated VMA.
>
>     - The start address must be page aligned.
>
>     - The end address (**addr** + **len**) must be in an allocated VMA.
>
>     - no gap (unallocated memory) between start and end address.
>
>   The `len` will be paged aligned implicitly by the kernel.
>
> **flags**: reserved for future use.
>
> - ****Return values**:**
>
>   - **0**: Success.
>
>   - - ****-EINVAL**:**
>
>       - Invalid input `flags`.
>
>       - The start address (`addr`) is not page aligned.
>
>       - Address range (`addr` + `len`) overflow.
>
>   - - ****-ENOMEM**:**
>
>       - The start address (`addr`) is not allocated.
>
>       - The end address (`addr` + `len`) is not allocated.
>
>       - A gap (unallocated memory) between start and end address.
>
>   - - ****-EPERM**:**
>
>       - sealing is supported only on 64-bit CPUs, 32-bit is not supported.
>
> - ****Note about error return**:**
>
>   - For above error cases, users can expect the given memory range is unmodified, i.e. no partial update.
>
>   - There might be other internal errors/cases not listed here, e.g. error during merging/splitting VMAs, or the process reaching the maximum number of supported VMAs. In those cases, partial updates to the given memory range could happen. However, those cases should be rare.
>
> - ****Architecture support**:**
>
>   mseal only works on 64-bit CPUs, not 32-bit CPUs.
>
> - ****Idempotent**:**
>
>   users can call mseal multiple times. mseal on an already sealed memory is a no-action (not error).
>
> - ****no munseal****
>
>   Once mapping is sealed, it can't be unsealed. The kernel should never have munseal, this is consistent with other sealing feature, e.g. F_SEAL_SEAL for file.

<a id="rst-blocked-mm-syscall-for-sealed-mapping"></a>

### Blocked mm syscall for sealed mapping

> It might be important to note: **once the mapping is sealed, it will stay in the process's memory until the process terminates**.
>
> Example:
>
>
>
> ```text
> *ptr = mmap(0, 4096, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
> rc = mseal(ptr, 4096, 0);
> /* munmap will fail */
> rc = munmap(ptr, 4096);
> assert(rc < 0);
> ```
>
> - **Blocked mm syscall:**
>
>   - munmap
>
>   - mmap
>
>   - mremap
>
>   - mprotect and pkey_mprotect
>
>   - some destructive madvise behaviors: MADV_DONTNEED, MADV_FREE, MADV_DONTNEED_LOCKED, MADV_FREE, MADV_DONTFORK, MADV_WIPEONFORK
>
> The first set of syscalls to block is munmap, mremap, mmap. They can either leave an empty space in the address space, therefore allowing replacement with a new mapping with new set of attributes, or can overwrite the existing mapping with another mapping.
>
> mprotect and pkey_mprotect are blocked because they changes the protection bits (RWX) of the mapping.
>
> Certain destructive madvise behaviors, specifically MADV_DONTNEED, MADV_FREE, MADV_DONTNEED_LOCKED, and MADV_WIPEONFORK, can introduce risks when applied to anonymous memory by threads lacking write permissions. Consequently, these operations are prohibited under such conditions. The aforementioned behaviors have the potential to modify region contents by discarding pages, effectively performing a memset(0) operation on the anonymous memory.
>
> Kernel will return -EPERM for blocked syscalls.
>
> When blocked syscall return -EPERM due to sealing, the memory regions may or may not be changed, depends on the syscall being blocked:
>
> > - munmap: munmap is atomic. If one of VMAs in the given range is sealed, none of VMAs are updated.
> >
> > - mprotect, pkey_mprotect, madvise: partial update might happen, e.g. when mprotect over multiple VMAs, mprotect might update the beginning VMAs before reaching the sealed VMA and return -EPERM.
> >
> > - mmap and mremap: undefined behavior.

<a id="rst-use-cases"></a>

## Use cases

- glibc: The dynamic linker, during loading ELF executables, can apply sealing to mapping segments.

- Chrome browser: protect some security sensitive data structures.

- System mappings: The system mappings are created by the kernel and includes vdso, vvar, vvar_vclock, vectors (arm compat-mode), sigpage (arm compat-mode), uprobes.

  Those system mappings are readonly only or execute only, memory sealing can protect them from ever changing to writable or unmmap/remapped as different attributes. This is useful to mitigate memory corruption issues where a corrupted pointer is passed to a memory management system.

  If supported by an architecture (CONFIG_ARCH_SUPPORTS_MSEAL_SYSTEM_MAPPINGS), the CONFIG_MSEAL_SYSTEM_MAPPINGS seals all system mappings of this architecture.

  The following architectures currently support this feature: x86-64, arm64, loongarch and s390.

  WARNING: This feature breaks programs which rely on relocating or unmapping system mappings. Known broken software at the time of writing includes CHECKPOINT_RESTORE, UML, gVisor, rr. Therefore this config can't be enabled universally.

<a id="rst-when-not-to-use-mseal"></a>

## When not to use mseal

Applications can apply sealing to any virtual memory region from userspace, but it is *crucial to thoroughly analyze the mapping's lifetime* prior to apply the sealing. This is because the sealed mapping *won’t be unmapped* until the process terminates or the exec system call is invoked.

- **For example:**

  - aio/shm aio/shm can call mmap and  munmap on behalf of userspace, e.g. ksys_shmdt() in shm.c. The lifetimes of those mapping are not tied to the lifetime of the process. If those memories are sealed from userspace, then munmap will fail, causing leaks in VMA address space during the lifetime of the process.

  - ptr allocated by malloc (heap) Don't use mseal on the memory ptr return from malloc(). malloc() is implemented by allocator, e.g. by glibc. Heap manager might allocate a ptr from brk or mapping created by mmap. If an app calls mseal on a ptr returned from malloc(), this can affect the heap manager's ability to manage the mappings; the outcome is non-deterministic.

    Example:



    ```text
    ptr = malloc(size);
    /* don't call mseal on ptr return from malloc. */
    mseal(ptr, size);
    /* free will success, allocator can't shrink heap lower than ptr */
    free(ptr);
    ```

<a id="rst-mseal-doesn-t-block"></a>

## mseal doesn't block

In a nutshell, mseal blocks certain mm syscall from modifying some of VMA's attributes, such as protection bits (RWX). Sealed mappings doesn't mean the memory is immutable.

As Jann Horn pointed out in \[3\], there are still a few ways to write to RO memory, which is, in a way, by design. And those could be blocked by different security measures.

Those cases are:

> - Write to read-only memory through /proc/self/mem interface (FOLL_FORCE).
>
> - Write to read-only memory through ptrace (such as PTRACE_POKETEXT).
>
> - userfaultfd.

The idea that inspired this patch comes from Stephen Röttger’s work in V8 CFI \[4\]. Chrome browser in ChromeOS will be the first user of this API.

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

## Reference

- \[1\] [https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/osfmk/mach/vm_statistics.h\#L274](<https://github.com/apple-oss-distributions/xnu/blob/1031c584a5e37aff177559b9f69dbd3c8c3fd30a/osfmk/mach/vm_statistics.h#L274>)

- \[2\] [https://man.openbsd.org/mimmutable.2](<https://man.openbsd.org/mimmutable.2>)

- \[3\] [https://lore.kernel.org/lkml/CAG48ez3ShUYey+ZAFsU2i1RpQn0a5eOs2hzQ426FkcgnfUGLvA@mail.gmail.com](<https://lore.kernel.org/lkml/CAG48ez3ShUYey+ZAFsU2i1RpQn0a5eOs2hzQ426FkcgnfUGLvA@mail.gmail.com>)

- \[4\] [https://docs.google.com/document/d/1O2jwK4dxI3nRcOJuPYkonhTkNQfbmwdvxQMyXgeaRHo/edit\#heading=h.bvaojj9fu6hc](<https://docs.google.com/document/d/1O2jwK4dxI3nRcOJuPYkonhTkNQfbmwdvxQMyXgeaRHo/edit#heading=h.bvaojj9fu6hc>)

---

# VDUSE - "vDPA Device in Userspace"

_Peios Kernel / Userspace interfaces / System and device interfaces / Memory and device access_

> vDPA (virtio data path acceleration) device is a device that uses a datapath which complies with the virtio specifications with vendor specific control path. vDPA devices can be both physically located on the hardware or emulated by…

<a id="rst-vduse-vdpa-device-in-userspace"></a>

vDPA (virtio data path acceleration) device is a device that uses a datapath which complies with the virtio specifications with vendor specific control path. vDPA devices can be both physically located on the hardware or emulated by software. VDUSE is a framework that makes it possible to implement software-emulated vDPA devices in userspace. And to make the device emulation more secure, the emulated vDPA device's control path is handled in the kernel and only the data path is implemented in the userspace.

Note that only virtio block device is supported by VDUSE framework now, which can reduce security risks when the userspace process that implements the data path is run by an unprivileged user. The support for other device types can be added after the security issue of corresponding device driver is clarified or fixed in the future.

<a id="rst-create-destroy-vduse-devices"></a>

## Create/Destroy VDUSE devices

VDUSE devices are created as follows:

1. Create a new VDUSE instance with ioctl(VDUSE_CREATE_DEV) on /dev/vduse/control.

2. Setup each virtqueue with ioctl(VDUSE_VQ_SETUP) on /dev/vduse/$NAME.

3. Begin processing VDUSE messages from /dev/vduse/$NAME. The first messages will arrive while attaching the VDUSE instance to vDPA bus.

4. Send the VDPA_CMD_DEV_NEW netlink message to attach the VDUSE instance to vDPA bus.

VDUSE devices are destroyed as follows:

1. Send the VDPA_CMD_DEV_DEL netlink message to detach the VDUSE instance from vDPA bus.

2. Close the file descriptor referring to /dev/vduse/$NAME.

3. Destroy the VDUSE instance with ioctl(VDUSE_DESTROY_DEV) on /dev/vduse/control.

The netlink messages can be sent via vdpa tool in iproute2 or use the below sample codes:



```c
static int netlink_add_vduse(const char *name, enum vdpa_command cmd)
{
        struct nl_sock *nlsock;
        struct nl_msg *msg;
        int famid;

        nlsock = nl_socket_alloc();
        if (!nlsock)
                return -ENOMEM;

        if (genl_connect(nlsock))
                goto free_sock;

        famid = genl_ctrl_resolve(nlsock, VDPA_GENL_NAME);
        if (famid < 0)
                goto close_sock;

        msg = nlmsg_alloc();
        if (!msg)
                goto close_sock;

        if (!genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, famid, 0, 0, cmd, 0))
                goto nla_put_failure;

        NLA_PUT_STRING(msg, VDPA_ATTR_DEV_NAME, name);
        if (cmd == VDPA_CMD_DEV_NEW)
                NLA_PUT_STRING(msg, VDPA_ATTR_MGMTDEV_DEV_NAME, "vduse");

        if (nl_send_sync(nlsock, msg))
                goto close_sock;

        nl_close(nlsock);
        nl_socket_free(nlsock);

        return 0;
nla_put_failure:
        nlmsg_free(msg);
close_sock:
        nl_close(nlsock);
free_sock:
        nl_socket_free(nlsock);
        return -1;
}
```

<a id="rst-how-vduse-works"></a>

## How VDUSE works

As mentioned above, a VDUSE device is created by ioctl(VDUSE_CREATE_DEV) on /dev/vduse/control. With this ioctl, userspace can specify some basic configuration such as device name (uniquely identify a VDUSE device), virtio features, virtio configuration space, the number of virtqueues and so on for this emulated device. Then a char device interface (/dev/vduse/$NAME) is exported to userspace for device emulation. Userspace can use the VDUSE_VQ_SETUP ioctl on /dev/vduse/$NAME to add per-virtqueue configuration such as the max size of virtqueue to the device.

After the initialization, the VDUSE device can be attached to vDPA bus via the VDPA_CMD_DEV_NEW netlink message. Userspace needs to read()/write() on /dev/vduse/$NAME to receive/reply some control messages from/to VDUSE kernel module as follows:



```c
static int vduse_message_handler(int dev_fd)
{
        int len;
        struct vduse_dev_request req;
        struct vduse_dev_response resp;

        len = read(dev_fd, &req, sizeof(req));
        if (len != sizeof(req))
                return -1;

        resp.request_id = req.request_id;

        switch (req.type) {

        /* handle different types of messages */

        }

        len = write(dev_fd, &resp, sizeof(resp));
        if (len != sizeof(resp))
                return -1;

        return 0;
}
```

There are now three types of messages introduced by VDUSE framework:

- VDUSE_GET_VQ_STATE: Get the state for virtqueue, userspace should return avail index for split virtqueue or the device/driver ring wrap counters and the avail and used index for packed virtqueue.

- VDUSE_SET_STATUS: Set the device status, userspace should follow the virtio spec: [https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.html](<https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.html>) to process this message. For example, fail to set the FEATURES_OK device status bit if the device can not accept the negotiated virtio features get from the VDUSE_DEV_GET_FEATURES ioctl.

- VDUSE_UPDATE_IOTLB: Notify userspace to update the memory mapping for specified IOVA range, userspace should firstly remove the old mapping, then setup the new mapping via the VDUSE_IOTLB_GET_FD ioctl.

After DRIVER_OK status bit is set via the VDUSE_SET_STATUS message, userspace is able to start the dataplane processing as follows:

1. Get the specified virtqueue's information with the VDUSE_VQ_GET_INFO ioctl, including the size, the IOVAs of descriptor table, available ring and used ring, the state and the ready status.

2. Pass the above IOVAs to the VDUSE_IOTLB_GET_FD ioctl so that those IOVA regions can be mapped into userspace. Some sample codes is shown below:



```c
static int perm_to_prot(uint8_t perm)
{
        int prot = 0;

        switch (perm) {
        case VDUSE_ACCESS_WO:
                prot |= PROT_WRITE;
                break;
        case VDUSE_ACCESS_RO:
                prot |= PROT_READ;
                break;
        case VDUSE_ACCESS_RW:
                prot |= PROT_READ | PROT_WRITE;
                break;
        }

        return prot;
}

static void *iova_to_va(int dev_fd, uint64_t iova, uint64_t *len)
{
        int fd;
        void *addr;
        size_t size;
        struct vduse_iotlb_entry entry;

        entry.start = iova;
        entry.last = iova;

        /*
         * Find the first IOVA region that overlaps with the specified
         * range [start, last] and return the corresponding file descriptor.
         */
        fd = ioctl(dev_fd, VDUSE_IOTLB_GET_FD, &entry);
        if (fd < 0)
                return NULL;

        size = entry.last - entry.start + 1;
        *len = entry.last - iova + 1;
        addr = mmap(0, size, perm_to_prot(entry.perm), MAP_SHARED,
                    fd, entry.offset);
        close(fd);
        if (addr == MAP_FAILED)
                return NULL;

        /*
         * Using some data structures such as linked list to store
         * the iotlb mapping. The munmap(2) should be called for the
         * cached mapping when the corresponding VDUSE_UPDATE_IOTLB
         * message is received or the device is reset.
         */

        return addr + iova - entry.start;
}
```

3. Setup the kick eventfd for the specified virtqueues with the VDUSE_VQ_SETUP_KICKFD ioctl. The kick eventfd is used by VDUSE kernel module to notify userspace to consume the available ring. This is optional since userspace can choose to poll the available ring instead.

4. Listen to the kick eventfd (optional) and consume the available ring. The buffer described by the descriptors in the descriptor table should be also mapped into userspace via the VDUSE_IOTLB_GET_FD ioctl before accessing.

5. Inject an interrupt for specific virtqueue with the VDUSE_INJECT_VQ_IRQ ioctl after the used ring is filled.

<a id="rst-enabling-asid-api-version-1"></a>

## Enabling ASID (API version 1)

VDUSE supports per-address-space identifiers (ASIDs) starting with API version 1. Set it up with ioctl(VDUSE_SET_API_VERSION) on `/dev/vduse/control` and pass `VDUSE_API_VERSION_1` before creating a new VDUSE instance with ioctl(VDUSE_CREATE_DEV).

Afterwards, you can use the member asid of ioctl(VDUSE_VQ_SETUP) argument to select the address space of the IOTLB you are querying.  The driver could change the address space of any virtqueue group by using the VDUSE_SET_VQ_GROUP_ASID VDUSE message type, and the VDUSE instance needs to reply with VDUSE_REQ_RESULT_OK if it was possible to change it.

Similarly, you can use ioctl(VDUSE_IOTLB_GET_FD2) to obtain the file descriptor describing an IOVA region of a specific ASID. Example usage:



```c
static void *iova_to_va(int dev_fd, uint32_t asid, uint64_t iova,
                        uint64_t *len)
{
        int fd;
        void *addr;
        size_t size;
        struct vduse_iotlb_entry_v2 entry = { 0 };

        entry.v1.start = iova;
        entry.v1.last = iova;
        entry.asid = asid;

        fd = ioctl(dev_fd, VDUSE_IOTLB_GET_FD2, &entry);
        if (fd < 0)
                return NULL;

        size = entry.v1.last - entry.v1.start + 1;
        *len = entry.v1.last - iova + 1;
        addr = mmap(0, size, perm_to_prot(entry.v1.perm), MAP_SHARED,
                    fd, entry.v1.offset);
        close(fd);
        if (addr == MAP_FAILED)
                return NULL;

        /*
         * Using some data structures such as linked list to store
         * the iotlb mapping. The munmap(2) should be called for the
         * cached mapping when the corresponding VDUSE_UPDATE_IOTLB
         * message is received or the device is reset.
         */

        return addr + iova - entry.v1.start;
}
```

For more details on the uAPI, please see include/uapi/linux/vduse.h.

---

# Landlock: unprivileged access control

_Peios Kernel / Userspace interfaces / System and device interfaces / Security controls_

> The goal of Landlock is to enable restriction of ambient rights (e.g. global filesystem or network access) for a set of processes. Because Landlock is a stackable LSM, it makes it possible to create safe security sandboxes as new security…

> **Peios:** Landlock is included in the configured LSM list and can impose additional restrictions. It cannot grant access refused by KACS. Ptrace and cross-process access additionally require the native process rights and PIP dominance described in [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>).


<a id="rst-landlock-unprivileged-access-control"></a>

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

<!-- Copyright © 2017-2020 Mickaël Salaün <mic@digikod.net> -->

<!-- Copyright © 2019-2020 ANSSI -->

<!-- Copyright © 2021-2022 Microsoft Corporation -->

**Author:** Mickaël Salaün

**Date:** March 2026

The goal of Landlock is to enable restriction of ambient rights (e.g. global filesystem or network access) for a set of processes.  Because Landlock is a stackable LSM, it makes it possible to create safe security sandboxes as new security layers in addition to the existing system-wide access-controls. This kind of sandbox is expected to help mitigate the security impact of bugs or unexpected/malicious behaviors in user space applications.  Landlock empowers any process, including unprivileged ones, to securely restrict themselves.

We can quickly make sure that Landlock is enabled in the running system by looking for "landlock: Up and running" in kernel logs (as root): `dmesg | grep landlock || journalctl -kb -g landlock` . Developers can also easily check for Landlock support with a [related system call](<#rst-landlock-abi-versions>). If Landlock is not currently supported, we need to [configure the kernel appropriately](<#rst-kernel-support>).

<a id="rst-landlock-rules"></a>

## Landlock rules

A Landlock rule describes an action on an object which the process intends to perform.  A set of rules is aggregated in a ruleset, which can then restrict the thread enforcing it, and its future children.

The two existing types of rules are:

- **Filesystem rules**

  For these rules, the object is a file hierarchy, and the related filesystem actions are defined with `filesystem access rights`.

- **Network rules (since ABI v4)**

  For these rules, the object is a TCP port, and the related actions are defined with `network access rights`.

<a id="rst-defining-and-enforcing-a-security-policy"></a>

### Defining and enforcing a security policy

We first need to define the ruleset that will contain our rules.

For this example, the ruleset will contain rules that only allow filesystem read actions and establish a specific TCP connection. Filesystem write actions and other TCP actions will be denied.

The ruleset then needs to handle both these kinds of actions.  This is required for backward and forward compatibility (i.e. the kernel and user space may not know each other's supported restrictions), hence the need to be explicit about the denied-by-default access rights.



```c
struct landlock_ruleset_attr ruleset_attr = {
    .handled_access_fs =
        LANDLOCK_ACCESS_FS_EXECUTE |
        LANDLOCK_ACCESS_FS_WRITE_FILE |
        LANDLOCK_ACCESS_FS_READ_FILE |
        LANDLOCK_ACCESS_FS_READ_DIR |
        LANDLOCK_ACCESS_FS_REMOVE_DIR |
        LANDLOCK_ACCESS_FS_REMOVE_FILE |
        LANDLOCK_ACCESS_FS_MAKE_CHAR |
        LANDLOCK_ACCESS_FS_MAKE_DIR |
        LANDLOCK_ACCESS_FS_MAKE_REG |
        LANDLOCK_ACCESS_FS_MAKE_SOCK |
        LANDLOCK_ACCESS_FS_MAKE_FIFO |
        LANDLOCK_ACCESS_FS_MAKE_BLOCK |
        LANDLOCK_ACCESS_FS_MAKE_SYM |
        LANDLOCK_ACCESS_FS_REFER |
        LANDLOCK_ACCESS_FS_TRUNCATE |
        LANDLOCK_ACCESS_FS_IOCTL_DEV,
    .handled_access_net =
        LANDLOCK_ACCESS_NET_BIND_TCP |
        LANDLOCK_ACCESS_NET_CONNECT_TCP,
    .scoped =
        LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET |
        LANDLOCK_SCOPE_SIGNAL,
};
```

Because we may not know which kernel version an application will be executed on, it is safer to follow a best-effort security approach.  Indeed, we should try to protect users as much as possible whatever the kernel they are using.

To be compatible with older Linux versions, we detect the available Landlock ABI version, and only use the available subset of access rights:



```c
int abi;

abi = landlock_create_ruleset(NULL, 0, LANDLOCK_CREATE_RULESET_VERSION);
if (abi < 0) {
    /* Degrades gracefully if Landlock is not handled. */
    perror("The running kernel does not enable to use Landlock");
    return 0;
}
switch (abi) {
case 1:
    /* Removes LANDLOCK_ACCESS_FS_REFER for ABI < 2 */
    ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_REFER;
    __attribute__((fallthrough));
case 2:
    /* Removes LANDLOCK_ACCESS_FS_TRUNCATE for ABI < 3 */
    ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_TRUNCATE;
    __attribute__((fallthrough));
case 3:
    /* Removes network support for ABI < 4 */
    ruleset_attr.handled_access_net &=
        ~(LANDLOCK_ACCESS_NET_BIND_TCP |
          LANDLOCK_ACCESS_NET_CONNECT_TCP);
    __attribute__((fallthrough));
case 4:
    /* Removes LANDLOCK_ACCESS_FS_IOCTL_DEV for ABI < 5 */
    ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_IOCTL_DEV;
    __attribute__((fallthrough));
case 5:
    /* Removes LANDLOCK_SCOPE_* for ABI < 6 */
    ruleset_attr.scoped &= ~(LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET |
                             LANDLOCK_SCOPE_SIGNAL);
}
```

This enables the creation of an inclusive ruleset that will contain our rules.



```c
int ruleset_fd;

ruleset_fd = landlock_create_ruleset(&ruleset_attr, sizeof(ruleset_attr), 0);
if (ruleset_fd < 0) {
    perror("Failed to create a ruleset");
    return 1;
}
```

We can now add a new rule to this ruleset thanks to the returned file descriptor referring to this ruleset.  The rule will allow reading and executing the file hierarchy `/usr`.  Without another rule, write actions would then be denied by the ruleset.  To add `/usr` to the ruleset, we open it with the `O_PATH` flag and fill the &amp;struct landlock_path_beneath_attr with this file descriptor.



```c
int err;
struct landlock_path_beneath_attr path_beneath = {
    .allowed_access =
        LANDLOCK_ACCESS_FS_EXECUTE |
        LANDLOCK_ACCESS_FS_READ_FILE |
        LANDLOCK_ACCESS_FS_READ_DIR,
};

path_beneath.parent_fd = open("/usr", O_PATH | O_CLOEXEC);
if (path_beneath.parent_fd < 0) {
    perror("Failed to open file");
    close(ruleset_fd);
    return 1;
}
err = landlock_add_rule(ruleset_fd, LANDLOCK_RULE_PATH_BENEATH,
                        &path_beneath, 0);
close(path_beneath.parent_fd);
if (err) {
    perror("Failed to update ruleset");
    close(ruleset_fd);
    return 1;
}
```

It may also be required to create rules following the same logic as explained for the ruleset creation, by filtering access rights according to the Landlock ABI version.  In this example, this is not required because all of the requested `allowed_access` rights are already available in ABI 1.

For network access-control, we can add a set of rules that allow to use a port number for a specific action: HTTPS connections.



```c
struct landlock_net_port_attr net_port = {
    .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
    .port = 443,
};

err = landlock_add_rule(ruleset_fd, LANDLOCK_RULE_NET_PORT,
                        &net_port, 0);
```

When passing a non-zero `flags` argument to `landlock_restrict_self()`, a similar backwards compatibility check is needed for the restrict flags (see sys_landlock_restrict_self() documentation for available flags):



```c
__u32 restrict_flags =
    LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON |
    LANDLOCK_RESTRICT_SELF_TSYNC;
switch (abi) {
case 1 ... 6:
    /* Removes logging flags for ABI < 7 */
    restrict_flags &= ~(LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF |
                        LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON |
                        LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF);
    __attribute__((fallthrough));
case 7:
    /*
     * Removes multithreaded enforcement flag for ABI < 8
     *
     * WARNING: Without this flag, calling landlock_restrict_self(2) is
     * only equivalent if the calling process is single-threaded. Below
     * ABI v8 (and as of ABI v8, when not using this flag), a Landlock
     * policy would only be enforced for the calling thread and its
     * children (and not for all threads, including parents and siblings).
     */
    restrict_flags &= ~LANDLOCK_RESTRICT_SELF_TSYNC;
}
```

The next step is to restrict the current thread from gaining more privileges (e.g. through a SUID binary).  We now have a ruleset with the first rule allowing read and execute access to `/usr` while denying all other handled accesses for the filesystem, and a second rule allowing HTTPS connections.



```c
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
    perror("Failed to restrict privileges");
    close(ruleset_fd);
    return 1;
}
```

The current thread is now ready to sandbox itself with the ruleset.



```c
if (landlock_restrict_self(ruleset_fd, restrict_flags)) {
    perror("Failed to enforce ruleset");
    close(ruleset_fd);
    return 1;
}
close(ruleset_fd);
```

If the `landlock_restrict_self` system call succeeds, the current thread is now restricted and this policy will be enforced on all its subsequently created children as well.  Once a thread is landlocked, there is no way to remove its security policy; only adding more restrictions is allowed.  These threads are now in a new Landlock domain, which is a merger of their parent one (if any) with the new ruleset.

Full working code can be found in [samples/landlock/sandboxer.c](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/samples/landlock/sandboxer.c>).

<a id="rst-good-practices"></a>

### Good practices

It is recommended to set access rights to file hierarchy leaves as much as possible.  For instance, it is better to be able to have `~/doc/` as a read-only hierarchy and `~/tmp/` as a read-write hierarchy, compared to `~/` as a read-only hierarchy and `~/tmp/` as a read-write hierarchy. Following this good practice leads to self-sufficient hierarchies that do not depend on their location (i.e. parent directories).  This is particularly relevant when we want to allow linking or renaming.  Indeed, having consistent access rights per directory enables changing the location of such directories without relying on the destination directory access rights (except those that are required for this operation, see `LANDLOCK_ACCESS_FS_REFER` documentation).

Having self-sufficient hierarchies also helps to tighten the required access rights to the minimal set of data.  This also helps avoid sinkhole directories, i.e. directories where data can be linked to but not linked from.  However, this depends on data organization, which might not be controlled by developers. In this case, granting read-write access to `~/tmp/`, instead of write-only access, would potentially allow moving `~/tmp/` to a non-readable directory and still keep the ability to list the content of `~/tmp/`.

<a id="rst-layers-of-file-path-access-rights"></a>

### Layers of file path access rights

Each time a thread enforces a ruleset on itself, it updates its Landlock domain with a new layer of policy.  This complementary policy is stacked with any other rulesets potentially already restricting this thread.  A sandboxed thread can then safely add more constraints to itself with a new enforced ruleset.

One policy layer grants access to a file path if at least one of its rules encountered on the path grants the access.  A sandboxed thread can only access a file path if all its enforced policy layers grant the access as well as all the other system access controls (e.g. filesystem DAC, other LSM policies, etc.).

<a id="rst-bind-mounts-and-overlayfs"></a>

### Bind mounts and OverlayFS

Landlock enables restricting access to file hierarchies, which means that these access rights can be propagated with bind mounts (cf. [Documentation/filesystems/sharedsubtree.rst](/kernel/internals/filesystems/sharedsubtree.md)) but not with [Documentation/filesystems/overlayfs.rst](/kernel/internals/filesystems/overlayfs.md).

A bind mount mirrors a source file hierarchy to a destination.  The destination hierarchy is then composed of the exact same files, on which Landlock rules can be tied, either via the source or the destination path.  These rules restrict access when they are encountered on a path, which means that they can restrict access to multiple file hierarchies at the same time, whether these hierarchies are the result of bind mounts or not.

An OverlayFS mount point consists of upper and lower layers.  These layers are combined in a merge directory, and that merged directory becomes available at the mount point.  This merge hierarchy may include files from the upper and lower layers, but modifications performed on the merge hierarchy only reflect on the upper layer.  From a Landlock policy point of view, all OverlayFS layers and merge hierarchies are standalone and each contains their own set of files and directories, which is different from bind mounts.  A policy restricting an OverlayFS layer will not restrict the resulted merged hierarchy, and vice versa. Landlock users should then only think about file hierarchies they want to allow access to, regardless of the underlying filesystem.

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

### Inheritance

Every new thread resulting from a `clone(2)` inherits Landlock domain restrictions from its parent.  This is similar to seccomp inheritance (cf. [Documentation/userspace-api/seccomp_filter.rst](/kernel/userspace/userspace-api/security/seccomp-filter.md)) or any other LSM dealing with task's `credentials(7)`.  For instance, one process's thread may apply Landlock rules to itself, but they will not be automatically applied to other sibling threads (unlike POSIX thread credential changes, cf. `nptl(7)`).

When a thread sandboxes itself, we have the guarantee that the related security policy will stay enforced on all this thread's descendants.  This allows creating standalone and modular security policies per application, which will automatically be composed between themselves according to their runtime parent policies.

<a id="rst-ptrace-restrictions"></a>

### Ptrace restrictions

A sandboxed process has less privileges than a non-sandboxed process and must then be subject to additional restrictions when manipulating another process. To be allowed to use `ptrace(2)` and related syscalls on a target process, a sandboxed process should have a superset of the target process's access rights, which means the tracee must be in a sub-domain of the tracer.

<a id="rst-ipc-scoping"></a>

### IPC scoping

Similar to the implicit [Ptrace restrictions](<#rst-ptrace-restrictions>), we may want to further restrict interactions between sandboxes.  Therefore, at ruleset creation time, each Landlock domain can restrict the scope for certain operations, so that these operations can only reach out to processes within the same Landlock domain or in a nested Landlock domain (the "scope").

The operations which can be scoped are:

- **`LANDLOCK_SCOPE_SIGNAL`**

  This limits the sending of signals to target processes which run within the same or a nested Landlock domain.

- **`LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET`**

  This limits the set of abstract `unix(7)` sockets to which we can `connect(2)` to socket addresses which were created by a process in the same or a nested Landlock domain.

  A `sendto(2)` on a non-connected datagram socket is treated as if it were doing an implicit `connect(2)` and will be blocked if the remote end does not stem from the same or a nested Landlock domain.

  A `sendto(2)` on a socket which was previously connected will not be restricted.  This works for both datagram and stream sockets.

IPC scoping does not support exceptions via `landlock_add_rule(2)`. If an operation is scoped within a domain, no rules can be added to allow access to resources or processes outside of the scope.

<a id="rst-truncating-files"></a>

### Truncating files

The operations covered by `LANDLOCK_ACCESS_FS_WRITE_FILE` and `LANDLOCK_ACCESS_FS_TRUNCATE` both change the contents of a file and sometimes overlap in non-intuitive ways.  It is recommended to always specify both of these together.

A particularly surprising example is `creat(2)`.  The name suggests that this system call requires the rights to create and write files.  However, it also requires the truncate right if an existing file under the same name is already present.

It should also be noted that truncating files does not require the `LANDLOCK_ACCESS_FS_WRITE_FILE` right.  Apart from the `truncate(2)` system call, this can also be done through `open(2)` with the flags `O_RDONLY | O_TRUNC`.

The truncate right is associated with the opened file (see below).

<a id="rst-rights-associated-with-file-descriptors"></a>

### Rights associated with file descriptors

When opening a file, the availability of the `LANDLOCK_ACCESS_FS_TRUNCATE` and `LANDLOCK_ACCESS_FS_IOCTL_DEV` rights is associated with the newly created file descriptor and will be used for subsequent truncation and ioctl attempts using `ftruncate(2)` and `ioctl(2)`.  The behavior is similar to opening a file for reading or writing, where permissions are checked during `open(2)`, but not during the subsequent `read(2)` and `write(2)` calls.

As a consequence, it is possible that a process has multiple open file descriptors referring to the same file, but Landlock enforces different things when operating with these file descriptors.  This can happen when a Landlock ruleset gets enforced and the process keeps file descriptors which were opened both before and after the enforcement.  It is also possible to pass such file descriptors between processes, keeping their Landlock properties, even when some of the involved processes do not have an enforced Landlock ruleset.

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

## Compatibility

<a id="rst-backward-and-forward-compatibility"></a>

### Backward and forward compatibility

Landlock is designed to be compatible with past and future versions of the kernel.  This is achieved thanks to the system call attributes and the associated bitflags, particularly the ruleset's `handled_access_fs`.  Making handled access rights explicit enables the kernel and user space to have a clear contract with each other.  This is required to make sure sandboxing will not get stricter with a system update, which could break applications.

Developers can subscribe to the [Landlock mailing list](<https://subspace.kernel.org/lists.linux.dev.html>)<a id="rst-landlock-mailing-list"></a> to knowingly update and test their applications with the latest available features.  In the interest of users, and because they may use different kernel versions, it is strongly encouraged to follow a best-effort security approach by checking the Landlock ABI version at runtime and only enforcing the supported features.

<a id="rst-landlock-abi-versions-1"></a>
<a id="rst-landlock-abi-versions"></a>

### Landlock ABI versions

The Landlock ABI version can be read with the sys_landlock_create_ruleset() system call:



```c
int abi;

abi = landlock_create_ruleset(NULL, 0, LANDLOCK_CREATE_RULESET_VERSION);
if (abi < 0) {
    switch (errno) {
    case ENOSYS:
        printf("Landlock is not supported by the current kernel.\n");
        break;
    case EOPNOTSUPP:
        printf("Landlock is currently disabled.\n");
        break;
    }
    return 0;
}
if (abi >= 2) {
    printf("Landlock supports LANDLOCK_ACCESS_FS_REFER.\n");
}
```

All Landlock kernel interfaces are supported by the first ABI version unless explicitly noted in their documentation.

<a id="rst-landlock-errata"></a>

### Landlock errata

In addition to ABI versions, Landlock provides an errata mechanism to track fixes for issues that may affect backwards compatibility or require userspace awareness.  The errata bitmask can be queried using:



```c
int errata;

errata = landlock_create_ruleset(NULL, 0, LANDLOCK_CREATE_RULESET_ERRATA);
if (errata < 0) {
    /* Landlock not available or disabled */
    return 0;
}
```

The returned value is a bitmask where each bit represents a specific erratum. If bit N is set (`errata & (1 << (N - 1))`), then erratum N has been fixed in the running kernel.

> [!WARNING]
>
> **Most applications should NOT check errata.** In 99.9% of cases, checking errata is unnecessary, increases code complexity, and can potentially decrease protection if misused.  For example, disabling the sandbox when an erratum is not fixed could leave the system less secure than using Landlock's best-effort protection.  When in doubt, ignore errata.


**Erratum 1: TCP socket identification**

This fix addresses an issue where IPv4 and IPv6 stream sockets (e.g., SMC,
MPTCP, or SCTP) were incorrectly restricted by TCP access rights during
`bind(2)` and `connect(2)` operations. This change ensures
that only TCP sockets are subject to TCP access rights, allowing other
protocols to operate without unnecessary restrictions.

Impact:

In kernels without this fix, using `LANDLOCK_ACCESS_NET_BIND_TCP` or
`LANDLOCK_ACCESS_NET_CONNECT_TCP` would incorrectly restrict non-TCP
stream protocols (SMC, MPTCP, SCTP), potentially breaking applications
that rely on these protocols while using Landlock network restrictions.



**Erratum 2: Scoped signal handling**

This fix addresses an issue where signal scoping was overly restrictive,
preventing sandboxed threads from signaling other threads within the same
process if they belonged to different domains.  Because threads are not
security boundaries, user space might assume that all threads within the same
process can send signals between themselves (see `nptl(7)` and
`libpsx(3)`).  Consistent with `ptrace(2)` behavior, direct
interaction between threads of the same process should always be allowed.
This change ensures that any thread is allowed to send signals to any other
thread within the same process, regardless of their domain.

Impact:

This problem only manifests when the userspace process is itself using
`libpsx(3)` or an equivalent mechanism to enforce a Landlock policy
on multiple already-running threads at once.  Programs which enforce a
Landlock policy at startup time and only then become multithreaded are not
affected.  Without this fix, signal scoping could break multi-threaded
applications that expect threads within the same process to freely signal
each other.



**Erratum 3: Disconnected directory handling**

This fix addresses an issue with disconnected directories that occur when a
directory is moved outside the scope of a bind mount.  The change ensures
that evaluated access rights include both those from the disconnected file
hierarchy down to its filesystem root and those from the related mount point
hierarchy.  This prevents access right widening through rename or link
actions.

Impact:

Without this fix, it was possible to widen access rights through rename or
link actions involving disconnected directories, potentially bypassing
`LANDLOCK_ACCESS_FS_REFER` restrictions.  This could allow privilege
escalation in complex mount scenarios where directories become disconnected
from their original mount points.


<a id="rst-how-to-check-for-errata"></a>

#### How to check for errata

If you determine that your application needs to check for specific errata, use this pattern:



```c
int errata = landlock_create_ruleset(NULL, 0, LANDLOCK_CREATE_RULESET_ERRATA);
if (errata >= 0) {
    /* Check for specific erratum (1-indexed) */
    if (errata & (1 << (erratum_number - 1))) {
        /* Erratum N is fixed in this kernel */
    } else {
        /* Erratum N is NOT fixed - consider implications for your use case */
    }
}
```

**Important:** Only check errata if your application specifically relies on behavior that changed due to the fix.  The fixes generally make Landlock less restrictive or more correct, not more restrictive.

<a id="rst-kernel-interface"></a>

## Kernel interface

<a id="rst-access-rights"></a>

### Access rights


A set of actions on kernel objects may be defined by an attribute (e.g.
[`struct landlock_path_beneath_attr`](#c-struct-landlock_path_beneath_attr)) including a bitmask of access.

**Filesystem flags**

These flags enable to restrict a sandboxed process to a set of actions on
files and directories.  Files or directories opened before the sandboxing
are not subject to these restrictions.

The following access rights apply only to files:

- `LANDLOCK_ACCESS_FS_EXECUTE`: Execute a file.
- `LANDLOCK_ACCESS_FS_WRITE_FILE`: Open a file with write access.  When
  opening files for writing, you will often additionally need the
  `LANDLOCK_ACCESS_FS_TRUNCATE` right.  In many cases, these system calls
  truncate existing files when overwriting them (e.g., `creat(2)`).
- `LANDLOCK_ACCESS_FS_READ_FILE`: Open a file with read access.
- `LANDLOCK_ACCESS_FS_TRUNCATE`: Truncate a file with `truncate(2)`,
  `ftruncate(2)`, `creat(2)`, or `open(2)` with
  `O_TRUNC`.  This access right is available since the third version of the
  Landlock ABI.
- `LANDLOCK_ACCESS_FS_IOCTL_DEV`: Invoke `ioctl(2)` commands on an opened
  character or block device.

  This access right applies to all `ioctl(2)` commands implemented by device
  drivers.  However, the following common IOCTL commands continue to be
  invokable independent of the `LANDLOCK_ACCESS_FS_IOCTL_DEV` right:

  * IOCTL commands targeting file descriptors (`FIOCLEX`, `FIONCLEX`),
  * IOCTL commands targeting file descriptions (`FIONBIO`, `FIOASYNC`),
  * IOCTL commands targeting file systems (`FIFREEZE`, `FITHAW`,
    `FIGETBSZ`, `FS_IOC_GETFSUUID`, `FS_IOC_GETFSSYSFSPATH`)
  * Some IOCTL commands which do not make sense when used with devices, but
    whose implementations are safe and return the right error codes
    (`FS_IOC_FIEMAP`, `FICLONE`, `FICLONERANGE`, `FIDEDUPERANGE`)

  This access right is available since the fifth version of the Landlock
  ABI.

Whether an opened file can be truncated with `ftruncate(2)` or used
with `ioctl(2)` is determined during `open(2)`, in the same way as
read and write permissions are checked during `open(2)` using
`LANDLOCK_ACCESS_FS_READ_FILE` and `LANDLOCK_ACCESS_FS_WRITE_FILE`.

A directory can receive access rights related to files or directories.  The
following access right is applied to the directory itself, and the
directories beneath it:

- `LANDLOCK_ACCESS_FS_READ_DIR`: Open a directory or list its content.

However, the following access rights only apply to the content of a
directory, not the directory itself:

- `LANDLOCK_ACCESS_FS_REMOVE_DIR`: Remove an empty directory or rename one.
- `LANDLOCK_ACCESS_FS_REMOVE_FILE`: Unlink (or rename) a file.
- `LANDLOCK_ACCESS_FS_MAKE_CHAR`: Create (or rename or link) a character
  device.
- `LANDLOCK_ACCESS_FS_MAKE_DIR`: Create (or rename) a directory.
- `LANDLOCK_ACCESS_FS_MAKE_REG`: Create (or rename or link) a regular file.
- `LANDLOCK_ACCESS_FS_MAKE_SOCK`: Create (or rename or link) a UNIX domain
  socket.
- `LANDLOCK_ACCESS_FS_MAKE_FIFO`: Create (or rename or link) a named pipe.
- `LANDLOCK_ACCESS_FS_MAKE_BLOCK`: Create (or rename or link) a block device.
- `LANDLOCK_ACCESS_FS_MAKE_SYM`: Create (or rename or link) a symbolic link.
- `LANDLOCK_ACCESS_FS_REFER`: Link or rename a file from or to a different
  directory (i.e. reparent a file hierarchy).

  This access right is available since the second version of the Landlock
  ABI.

  This is the only access right which is denied by default by any ruleset,
  even if the right is not specified as handled at ruleset creation time.
  The only way to make a ruleset grant this right is to explicitly allow it
  for a specific directory by adding a matching rule to the ruleset.

  In particular, when using the first Landlock ABI version, Landlock will
  always deny attempts to reparent files between different directories.

  In addition to the source and destination directories having the
  `LANDLOCK_ACCESS_FS_REFER` access right, the attempted link or rename
  operation must meet the following constraints:

  * The reparented file may not gain more access rights in the destination
    directory than it previously had in the source directory.  If this is
    attempted, the operation results in an `EXDEV` error.

  * When linking or renaming, the `LANDLOCK_ACCESS_FS_MAKE_*` right for the
    respective file type must be granted for the destination directory.
    Otherwise, the operation results in an `EACCES` error.

  * When renaming, the `LANDLOCK_ACCESS_FS_REMOVE_*` right for the
    respective file type must be granted for the source directory.  Otherwise,
    the operation results in an `EACCES` error.

  If multiple requirements are not met, the `EACCES` error code takes
  precedence over `EXDEV`.

> [!WARNING]
> It is currently not possible to restrict some file-related actions
> accessible through these syscall families: `chdir(2)`,
> `stat(2)`, `flock(2)`, `chmod(2)`,
> `chown(2)`, `setxattr(2)`, `utime(2)`,
> `fcntl(2)`, `access(2)`.
> Future Landlock evolutions will enable to restrict them.

**Network flags**

These flags enable to restrict a sandboxed process to a set of network
actions.

The following access rights apply to TCP port numbers:

- `LANDLOCK_ACCESS_NET_BIND_TCP`: Bind TCP sockets to the given local
  port. Support added in Landlock ABI version 4.
- `LANDLOCK_ACCESS_NET_CONNECT_TCP`: Connect TCP sockets to the given
  remote port. Support added in Landlock ABI version 4.

**Scope flags**

These flags enable to isolate a sandboxed process from a set of IPC actions.
Setting a flag for a ruleset will isolate the Landlock domain to forbid
connections to resources outside the domain.

This is supported since Landlock ABI version 6.

Scopes:

- `LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET`: Restrict a sandboxed process from
  connecting to an abstract UNIX socket created by a process outside the
  related Landlock domain (e.g., a parent domain or a non-sandboxed process).
- `LANDLOCK_SCOPE_SIGNAL`: Restrict a sandboxed process from sending a signal
  to another process outside the domain.


<a id="rst-creating-a-new-ruleset"></a>

### Creating a new ruleset


#### <a id="c-sys_landlock_create_ruleset"></a>`sys_landlock_create_ruleset()`

```c
long sys_landlock_create_ruleset(const struct landlock_ruleset_attr __user *const attr, const size_t size, const __u32 flags)
```

Create a new ruleset

**Parameters**

- `const struct landlock_ruleset_attr __user *const attr`: Pointer to a [`struct landlock_ruleset_attr`](#c-struct-landlock_ruleset_attr) identifying the scope of
  the new ruleset.
- `const size_t size`: Size of the pointed [`struct landlock_ruleset_attr`](#c-struct-landlock_ruleset_attr) (needed for
  backward and forward compatibility).
- `const __u32 flags`: Supported values:

**Description**

- `LANDLOCK_CREATE_RULESET_VERSION`
- `LANDLOCK_CREATE_RULESET_ERRATA`

This system call enables to create a new Landlock ruleset, and returns the
related file descriptor on success.

If `LANDLOCK_CREATE_RULESET_VERSION` or `LANDLOCK_CREATE_RULESET_ERRATA` is
set, then **attr** must be NULL and **size** must be 0.

Possible returned errors are:

- `EOPNOTSUPP`: Landlock is supported by the kernel but disabled at boot time;
- `EINVAL`: unknown **flags**, or unknown access, or unknown scope, or too small **size**;
- `E2BIG`: **attr** or **size** inconsistencies;
- `EFAULT`: **attr** or **size** inconsistencies;
- `ENOMSG`: empty [`landlock_ruleset_attr.handled_access_fs`](#c-struct-landlock_ruleset_attr).

**Flags**

- `LANDLOCK_CREATE_RULESET_VERSION`:
  Get the highest supported Landlock ABI version (starting at 1).

- `LANDLOCK_CREATE_RULESET_ERRATA`:
  Get a bitmask of fixed issues for the current Landlock ABI version.



#### <a id="c-struct-landlock_ruleset_attr"></a>`struct landlock_ruleset_attr`

Ruleset definition.

**Definition**

```c
struct landlock_ruleset_attr {
    __u64 handled_access_fs;
    __u64 handled_access_net;
    __u64 scoped;
};
```

**Members**

- `handled_access_fs`: Bitmask of handled filesystem actions
  (cf. `Filesystem flags`).
- `handled_access_net`: Bitmask of handled network actions (cf. `Network flags`).
- `scoped`: Bitmask of scopes (cf. `Scope flags`)
  restricting a Landlock domain from accessing outside
  resources (e.g. IPCs).

**Description**

Argument of [`sys_landlock_create_ruleset()`](#c-sys_landlock_create_ruleset).

This structure defines a set of *handled access rights*, a set of actions on
different object types, which should be denied by default when the ruleset is
enacted.  Vice versa, access rights that are not specifically listed here are
not going to be denied by this ruleset when it is enacted.

For historical reasons, the `LANDLOCK_ACCESS_FS_REFER` right is always denied
by default, even when its bit is not set in **handled_access_fs**.  In order to
add new rules with this access right, the bit must still be set explicitly
(cf. `Filesystem flags`).

The explicit listing of *handled access rights* is required for backwards
compatibility reasons.  In most use cases, processes that use Landlock will
*handle* a wide range or all access rights that they know about at build time
(and that they have tested with a kernel that supported them all).

This structure can grow in future Landlock versions.


<a id="rst-extending-a-ruleset"></a>

### Extending a ruleset


#### <a id="c-sys_landlock_add_rule"></a>`sys_landlock_add_rule()`

```c
long sys_landlock_add_rule(const int ruleset_fd, const enum landlock_rule_type rule_type, const void __user *const rule_attr, const __u32 flags)
```

Add a new rule to a ruleset

**Parameters**

- `const int ruleset_fd`: File descriptor tied to the ruleset that should be extended
  with the new rule.
- `const enum landlock_rule_type rule_type`: Identify the structure type pointed to by **rule_attr**:
  `LANDLOCK_RULE_PATH_BENEATH` or `LANDLOCK_RULE_NET_PORT`.
- `const void __user *const rule_attr`: Pointer to a rule (matching the **rule_type**).
- `const __u32 flags`: Must be 0.

**Description**

This system call enables to define a new rule and add it to an existing
ruleset.

Possible returned errors are:

- `EOPNOTSUPP`: Landlock is supported by the kernel but disabled at boot time;
- `EAFNOSUPPORT`: **rule_type** is `LANDLOCK_RULE_NET_PORT` but TCP/IP is not
  supported by the running kernel;
- `EINVAL`: **flags** is not 0;
- `EINVAL`: The rule accesses are inconsistent (i.e.
  [`landlock_path_beneath_attr.allowed_access`](#c-struct-landlock_path_beneath_attr) or
  [`landlock_net_port_attr.allowed_access`](#c-struct-landlock_net_port_attr) is not a subset of the ruleset
  handled accesses)
- `EINVAL`: [`landlock_net_port_attr.port`](#c-struct-landlock_net_port_attr) is greater than 65535;
- `ENOMSG`: Empty accesses (e.g. [`landlock_path_beneath_attr.allowed_access`](#c-struct-landlock_path_beneath_attr) is
  0);
- `EBADF`: **ruleset_fd** is not a file descriptor for the current thread, or a
  member of **rule_attr** is not a file descriptor as expected;
- `EBADFD`: **ruleset_fd** is not a ruleset file descriptor, or a member of
  **rule_attr** is not the expected file descriptor type;
- `EPERM`: **ruleset_fd** has no write access to the underlying ruleset;
- `EFAULT`: **rule_attr** was not a valid address.



#### <a id="c-enum-landlock_rule_type"></a>`enum landlock_rule_type`

Landlock rule type

**Constants**

- `LANDLOCK_RULE_PATH_BENEATH`: Type of a [`struct landlock_path_beneath_attr`](#c-struct-landlock_path_beneath_attr) .
- `LANDLOCK_RULE_NET_PORT`: Type of a [`struct landlock_net_port_attr`](#c-struct-landlock_net_port_attr) .

**Description**

Argument of [`sys_landlock_add_rule()`](#c-sys_landlock_add_rule).

#### <a id="c-struct-landlock_path_beneath_attr"></a>`struct landlock_path_beneath_attr`

Path hierarchy definition

**Definition**

```c
struct landlock_path_beneath_attr {
    __u64 allowed_access;
    __s32 parent_fd;
};
```

**Members**

- `allowed_access`: Bitmask of allowed actions for this file hierarchy
  (cf. `Filesystem flags`).
- `parent_fd`: File descriptor, preferably opened with `O_PATH`,
  which identifies the parent directory of a file hierarchy, or just a
  file.

**Description**

Argument of [`sys_landlock_add_rule()`](#c-sys_landlock_add_rule).

#### <a id="c-struct-landlock_net_port_attr"></a>`struct landlock_net_port_attr`

Network port definition

**Definition**

```c
struct landlock_net_port_attr {
    __u64 allowed_access;
    __u64 port;
};
```

**Members**

- `allowed_access`: Bitmask of allowed network actions for a port
  (cf. `Network flags`).
- `port`: Network port in host endianness.

  It should be noted that port 0 passed to `bind(2)` will bind
  to an available port from the ephemeral port range.  This can be
  configured with the `/proc/sys/net/ipv4/ip_local_port_range` sysctl
  (also used for IPv6), and within that range, on a per-socket basis
  with `setsockopt(IP_LOCAL_PORT_RANGE)`.

  A Landlock rule with port 0 and the `LANDLOCK_ACCESS_NET_BIND_TCP`
  right means that requesting to bind on port 0 is allowed and it will
  automatically translate to binding on a kernel-assigned ephemeral
  port.

**Description**

Argument of [`sys_landlock_add_rule()`](#c-sys_landlock_add_rule).


<a id="rst-enforcing-a-ruleset"></a>

### Enforcing a ruleset


#### <a id="c-sys_landlock_restrict_self"></a>`sys_landlock_restrict_self()`

```c
long sys_landlock_restrict_self(const int ruleset_fd, const __u32 flags)
```

Enforce a ruleset on the calling thread

**Parameters**

- `const int ruleset_fd`: File descriptor tied to the ruleset to merge with the target.
- `const __u32 flags`: Supported values:

**Description**

- `LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF`
- `LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON`
- `LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF`
- `LANDLOCK_RESTRICT_SELF_TSYNC`

This system call enforces a Landlock ruleset on the current thread.
Enforcing a ruleset requires that the task has `CAP_SYS_ADMIN` in its
namespace or is running with no_new_privs.  This avoids scenarios where
unprivileged tasks can affect the behavior of privileged children.

Possible returned errors are:

- `EOPNOTSUPP`: Landlock is supported by the kernel but disabled at boot time;
- `EINVAL`: **flags** contains an unknown bit.
- `EBADF`: **ruleset_fd** is not a file descriptor for the current thread;
- `EBADFD`: **ruleset_fd** is not a ruleset file descriptor;
- `EPERM`: **ruleset_fd** has no read access to the underlying ruleset, or the
  current thread is not running with no_new_privs, or it doesn't have
  `CAP_SYS_ADMIN` in its namespace.
- `E2BIG`: The maximum number of stacked rulesets is reached for the current
  thread.

**Flags**

By default, denied accesses originating from programs that sandbox themselves
are logged via the audit subsystem. Such events typically indicate unexpected
behavior, such as bugs or exploitation attempts. However, to avoid excessive
logging, access requests denied by a domain not created by the originating
program are not logged by default. The rationale is that programs should know
their own behavior, but not necessarily the behavior of other programs.  This
default configuration is suitable for most programs that sandbox themselves.
For specific use cases, the following flags allow programs to modify this
default logging behavior.

The `LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF` and
`LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON` flags apply to the newly created
Landlock domain.

- `LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF`:
  Disables logging of denied accesses originating from the thread creating
  the Landlock domain, as well as its children, as long as they continue
  running the same executable code (i.e., without an intervening
  `execve(2)` call). This is intended for programs that execute
  unknown code without invoking `execve(2)`, such as script
  interpreters. Programs that only sandbox themselves should not set this
  flag, so users can be notified of unauthorized access attempts via system
  logs.

- `LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON`:
  Enables logging of denied accesses after an `execve(2)` call,
  providing visibility into unauthorized access attempts by newly executed
  programs within the created Landlock domain. This flag is recommended
  only when all potential executables in the domain are expected to comply
  with the access restrictions, as excessive audit log entries could make
  it more difficult to identify critical events.

- `LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF`:
  Disables logging of denied accesses originating from nested Landlock
  domains created by the caller or its descendants. This flag should be set
  according to runtime configuration, not hardcoded, to avoid suppressing
  important security events. It is useful for container runtimes or
  sandboxing tools that may launch programs which themselves create
  Landlock domains and could otherwise generate excessive logs. Unlike
  `LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF`, this flag only affects
  future nested domains, not the one being created. It can also be used
  with a **ruleset_fd** value of -1 to mute subdomain logs without creating a
  domain.  When combined with `LANDLOCK_RESTRICT_SELF_TSYNC` and a
  **ruleset_fd** value of -1, this configuration is propagated to all threads
  of the current process.

The following flag supports policy enforcement in multithreaded processes:

- `LANDLOCK_RESTRICT_SELF_TSYNC`:
  Applies the new Landlock configuration atomically to all threads of the
  current process, including the Landlock domain and logging
  configuration. This overrides the Landlock configuration of sibling
  threads, irrespective of previously established Landlock domains and
  logging configurations on these threads.

  If the calling thread is running with no_new_privs, this operation
  enables no_new_privs on the sibling threads as well.


<a id="rst-current-limitations"></a>

## Current limitations

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

### Filesystem topology modification

Threads sandboxed with filesystem restrictions cannot modify filesystem topology, whether via `mount(2)` or `pivot_root(2)`. However, `chroot(2)` calls are not denied.

<a id="rst-special-filesystems"></a>

### Special filesystems

Access to regular files and directories can be restricted by Landlock, according to the handled accesses of a ruleset.  However, files that do not come from a user-visible filesystem (e.g. pipe, socket), but can still be accessed through `/proc/<pid>/fd/*`, cannot currently be explicitly restricted.  Likewise, some special kernel filesystems such as nsfs, which can be accessed through `/proc/<pid>/ns/*`, cannot currently be explicitly restricted.  However, thanks to the [ptrace restrictions](<#rst-ptrace-restrictions>), access to such sensitive `/proc` files are automatically restricted according to domain hierarchies.  Future Landlock evolutions could still enable to explicitly restrict such paths with dedicated ruleset flags.

<a id="rst-ruleset-layers"></a>

### Ruleset layers

There is a limit of 16 layers of stacked rulesets.  This can be an issue for a task willing to enforce a new ruleset in complement to its 16 inherited rulesets.  Once this limit is reached, sys_landlock_restrict_self() returns E2BIG.  It is then strongly suggested to carefully build rulesets once in the life of a thread, especially for applications able to launch other applications that may also want to sandbox themselves (e.g. shells, container managers, etc.).

<a id="rst-memory-usage"></a>

### Memory usage

Kernel memory allocated to create rulesets is accounted and can be restricted by the [Documentation/admin-guide/cgroup-v1/memory.rst](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/admin-guide/cgroup-v1/memory.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92).

<a id="rst-ioctl-support"></a>

### IOCTL support

The `LANDLOCK_ACCESS_FS_IOCTL_DEV` right restricts the use of `ioctl(2)`, but it only applies to *newly opened* device files.  This means specifically that pre-existing file descriptors like stdin, stdout and stderr are unaffected.

Users should be aware that TTY devices have traditionally permitted to control other processes on the same TTY through the `TIOCSTI` and `TIOCLINUX` IOCTL commands.  Both of these require `CAP_SYS_ADMIN` on modern Linux systems, but the behavior is configurable for `TIOCSTI`.

On older systems, it is therefore recommended to close inherited TTY file descriptors, or to reopen them from `/proc/self/fd/*` without the `LANDLOCK_ACCESS_FS_IOCTL_DEV` right, if possible.

Landlock's IOCTL support is coarse-grained at the moment, but may become more fine-grained in the future.  Until then, users are advised to establish the guarantees that they need through the file hierarchy, by only allowing the `LANDLOCK_ACCESS_FS_IOCTL_DEV` right on files where it is really required.

<a id="rst-previous-limitations"></a>

## Previous limitations

<a id="rst-file-renaming-and-linking-abi-2"></a>

### File renaming and linking (ABI &lt; 2)

Because Landlock targets unprivileged access controls, it needs to properly handle composition of rules.  Such property also implies rules nesting. Properly handling multiple layers of rulesets, each one of them able to restrict access to files, also implies inheritance of the ruleset restrictions from a parent to its hierarchy.  Because files are identified and restricted by their hierarchy, moving or linking a file from one directory to another implies propagation of the hierarchy constraints, or restriction of these actions according to the potentially lost constraints.  To protect against privilege escalations through renaming or linking, and for the sake of simplicity, Landlock previously limited linking and renaming to the same directory. Starting with the Landlock ABI version 2, it is now possible to securely control renaming and linking thanks to the new `LANDLOCK_ACCESS_FS_REFER` access right.

<a id="rst-file-truncation-abi-3"></a>

### File truncation (ABI &lt; 3)

File truncation could not be denied before the third Landlock ABI, so it is always allowed when using a kernel that only supports the first or second ABI.

Starting with the Landlock ABI version 3, it is now possible to securely control truncation thanks to the new `LANDLOCK_ACCESS_FS_TRUNCATE` access right.

<a id="rst-tcp-bind-and-connect-abi-4"></a>

### TCP bind and connect (ABI &lt; 4)

Starting with the Landlock ABI version 4, it is now possible to restrict TCP bind and connect actions to only a set of allowed ports thanks to the new `LANDLOCK_ACCESS_NET_BIND_TCP` and `LANDLOCK_ACCESS_NET_CONNECT_TCP` access rights.

<a id="rst-device-ioctl-abi-5"></a>

### Device IOCTL (ABI &lt; 5)

IOCTL operations could not be denied before the fifth Landlock ABI, so `ioctl(2)` is always allowed when using a kernel that only supports an earlier ABI.

Starting with the Landlock ABI version 5, it is possible to restrict the use of `ioctl(2)` on character and block devices using the new `LANDLOCK_ACCESS_FS_IOCTL_DEV` right.

<a id="rst-abstract-unix-socket-abi-6"></a>

### Abstract UNIX socket (ABI &lt; 6)

Starting with the Landlock ABI version 6, it is possible to restrict connections to an abstract `unix(7)` socket by setting `LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET` to the `scoped` ruleset attribute.

<a id="rst-signal-abi-6"></a>

### Signal (ABI &lt; 6)

Starting with the Landlock ABI version 6, it is possible to restrict `signal(7)` sending by setting `LANDLOCK_SCOPE_SIGNAL` to the `scoped` ruleset attribute.

<a id="rst-logging-abi-7"></a>

### Logging (ABI &lt; 7)

Starting with the Landlock ABI version 7, it is possible to control logging of Landlock audit events with the `LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF`, `LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON`, and `LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF` flags passed to sys_landlock_restrict_self().  See [Documentation/admin-guide/LSM/landlock.rst](/kernel/administration/admin-guide/lsm/landlock.md) for more details on audit.

<a id="rst-thread-synchronization-abi-8"></a>

### Thread synchronization (ABI &lt; 8)

Starting with the Landlock ABI version 8, it is now possible to enforce Landlock rulesets across all threads of the calling process using the `LANDLOCK_RESTRICT_SELF_TSYNC` flag passed to sys_landlock_restrict_self().

<a id="rst-kernel-support-1"></a>
<a id="rst-kernel-support"></a>

## Kernel support

<a id="rst-build-time-configuration"></a>

### Build time configuration

Landlock was first introduced in Linux 5.13 but it must be configured at build time with `CONFIG_SECURITY_LANDLOCK=y`.  Landlock must also be enabled at boot time like other security modules.  The list of security modules enabled by default is set with `CONFIG_LSM`.  The kernel configuration should then contain `CONFIG_LSM=landlock,[...]` with `[...]`  as the list of other potentially useful security modules for the running system (see the `CONFIG_LSM` help).

<a id="rst-boot-time-configuration"></a>

### Boot time configuration

If the running kernel does not have `landlock` in `CONFIG_LSM`, then we can enable Landlock by adding `lsm=landlock,[...]` to [Documentation/admin-guide/kernel-parameters.rst](/kernel/administration/admin-guide/boot/kernel-parameters.md) in the boot loader configuration.

For example, if the current built-in configuration is:



```console
$ zgrep -h "^CONFIG_LSM=" "/boot/config-$(uname -r)" /proc/config.gz 2>/dev/null
CONFIG_LSM="lockdown,yama,integrity,apparmor"
```

...and if the cmdline doesn't contain `landlock` either:



```console
$ sed -n 's/.*\(\<lsm=\S\+\).*/\1/p' /proc/cmdline
lsm=lockdown,yama,integrity,apparmor
```

...we should configure the boot loader to set a cmdline extending the `lsm` list with the `landlock,` prefix:



```text
lsm=landlock,lockdown,yama,integrity,apparmor
```

After a reboot, we can check that Landlock is up and running by looking at kernel logs:



```console
# dmesg | grep landlock || journalctl -kb -g landlock
[    0.000000] Command line: [...] lsm=landlock,lockdown,yama,integrity,apparmor
[    0.000000] Kernel command line: [...] lsm=landlock,lockdown,yama,integrity,apparmor
[    0.000000] LSM: initializing lsm=lockdown,capability,landlock,yama,integrity,apparmor
[    0.000000] landlock: Up and running.
```

The kernel may be configured at build time to always load the `lockdown` and `capability` LSMs.  In that case, these LSMs will appear at the beginning of the `LSM: initializing` log line as well, even if they are not configured in the boot loader.

<a id="rst-network-support"></a>

### Network support

To be able to explicitly allow TCP operations (e.g., adding a network rule with `LANDLOCK_ACCESS_NET_BIND_TCP`), the kernel must support TCP (`CONFIG_INET=y`).  Otherwise, sys_landlock_add_rule() returns an `EAFNOSUPPORT` error, which can safely be ignored because this kind of TCP operation is already not possible.

<a id="rst-questions-and-answers"></a>

## Questions and answers

<a id="rst-what-about-user-space-sandbox-managers"></a>

### What about user space sandbox managers?

Using user space processes to enforce restrictions on kernel resources can lead to race conditions or inconsistent evaluations (i.e. [Incorrect mirroring of the OS code and state](<https://www.ndss-symposium.org/ndss2003/traps-and-pitfalls-practical-problems-system-call-interposition-based-security-tools/>)<a id="rst-incorrect-mirroring-of-the-os-code-and-state"></a>).

<a id="rst-what-about-namespaces-and-containers"></a>

### What about namespaces and containers?

Namespaces can help create sandboxes but they are not designed for access-control and then miss useful features for such use case (e.g. no fine-grained restrictions).  Moreover, their complexity can lead to security issues, especially when untrusted processes can manipulate them (cf. [Controlling access to user namespaces](<https://lwn.net/Articles/673597/>)<a id="rst-controlling-access-to-user-namespaces"></a>).

<a id="rst-how-to-disable-landlock-audit-records"></a>

### How to disable Landlock audit records?

You might want to put in place filters as explained here: [Documentation/admin-guide/LSM/landlock.rst](/kernel/administration/admin-guide/lsm/landlock.md)

<a id="rst-additional-documentation"></a>

## Additional documentation

- [Documentation/admin-guide/LSM/landlock.rst](/kernel/administration/admin-guide/lsm/landlock.md)

- [Documentation/security/landlock.rst](/kernel/internals/security/landlock.md)

- [https://landlock.io](<https://landlock.io>)

<!-- Links -->

<a id="rst-samples-landlock-sandboxer-c"></a>

---

# Linux Security Modules

_Peios Kernel / Userspace interfaces / System and device interfaces / Security controls_

> Linux security modules (LSM) provide a mechanism to implement additional access controls to the Linux security policies.

> **Peios:** The LSM examples here describe upstream interfaces and implementation choices. Peios configures `landlock,lockdown,integrity,pkm`; SELinux, Smack, AppArmor and their attribute/policy interfaces are not the active native access model. Use the native token/SD interfaces for Peios authority. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>).


<a id="rst-linux-security-modules"></a>

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

<!-- Copyright (C) 2022 Casey Schaufler <casey@schaufler-ca.com> -->

<!-- Copyright (C) 2022 Intel Corporation -->

**Author:** Casey Schaufler

**Date:** July 2023

Linux security modules (LSM) provide a mechanism to implement additional access controls to the Linux security policies.

The various security modules may support any of these attributes:

`LSM_ATTR_CURRENT` is the current, active security context of the process. The proc filesystem provides this value in `/proc/self/attr/current`. This is supported by the SELinux, Smack and AppArmor security modules. Smack also provides this value in `/proc/self/attr/smack/current`. AppArmor also provides this value in `/proc/self/attr/apparmor/current`.

`LSM_ATTR_EXEC` is the security context of the process at the time the current image was executed. The proc filesystem provides this value in `/proc/self/attr/exec`. This is supported by the SELinux and AppArmor security modules. AppArmor also provides this value in `/proc/self/attr/apparmor/exec`.

`LSM_ATTR_FSCREATE` is the security context of the process used when creating file system objects. The proc filesystem provides this value in `/proc/self/attr/fscreate`. This is supported by the SELinux security module.

`LSM_ATTR_KEYCREATE` is the security context of the process used when creating key objects. The proc filesystem provides this value in `/proc/self/attr/keycreate`. This is supported by the SELinux security module.

`LSM_ATTR_PREV` is the security context of the process at the time the current security context was set. The proc filesystem provides this value in `/proc/self/attr/prev`. This is supported by the SELinux and AppArmor security modules. AppArmor also provides this value in `/proc/self/attr/apparmor/prev`.

`LSM_ATTR_SOCKCREATE` is the security context of the process used when creating socket objects. The proc filesystem provides this value in `/proc/self/attr/sockcreate`. This is supported by the SELinux security module.

<a id="rst-kernel-interface"></a>

## Kernel interface

<a id="rst-set-a-security-attribute-of-the-current-process"></a>

### Set a security attribute of the current process


#### <a id="c-sys_lsm_set_self_attr"></a>`sys_lsm_set_self_attr()`

```c
long sys_lsm_set_self_attr(unsigned int attr, struct lsm_ctx __user * ctx, u32 size, u32 flags)
```

Set current task's security module attribute

**Parameters**

- `unsigned int attr`: which attribute to set
- `struct lsm_ctx __user * ctx`: the LSM contexts
- `u32 size`: size of **ctx**
- `u32 flags`: reserved for future use

**Description**

Sets the calling task's LSM context. On success this function
returns 0. If the attribute specified cannot be set a negative
value indicating the reason for the error is returned.


<a id="rst-get-the-specified-security-attributes-of-the-current-process"></a>

### Get the specified security attributes of the current process


#### <a id="c-sys_lsm_get_self_attr"></a>`sys_lsm_get_self_attr()`

```c
long sys_lsm_get_self_attr(unsigned int attr, struct lsm_ctx __user * ctx, u32 __user * size, u32 flags)
```

Return current task's security module attributes

**Parameters**

- `unsigned int attr`: which attribute to return
- `struct lsm_ctx __user * ctx`: the user-space destination for the information, or NULL
- `u32 __user * size`: pointer to the size of space available to receive the data
- `u32 flags`: special handling options. LSM_FLAG_SINGLE indicates that only
  attributes associated with the LSM identified in the passed **ctx** be
  reported.

**Description**

Returns the calling task's LSM contexts. On success this
function returns the number of **ctx** array elements. This value
may be zero if there are no LSM contexts assigned. If **size** is
insufficient to contain the return data -E2BIG is returned and
**size** is set to the minimum required size. In all other cases
a negative value indicating the error is returned.



#### <a id="c-sys_lsm_list_modules"></a>`sys_lsm_list_modules()`

```c
long sys_lsm_list_modules(u64 __user * ids, u32 __user * size, u32 flags)
```

Return a list of the active security modules

**Parameters**

- `u64 __user * ids`: the LSM module ids
- `u32 __user * size`: pointer to size of **ids**, updated on return
- `u32 flags`: reserved for future use, must be zero

**Description**

Returns a list of the active LSM ids. On success this function
returns the number of **ids** array elements. This value may be zero
if there are no LSMs active. If **size** is insufficient to contain
the return data -E2BIG is returned and **size** is set to the minimum
required size. In all other cases a negative value indicating the
error is returned.


<a id="rst-additional-documentation"></a>

## Additional documentation

- [Documentation/security/lsm.rst](/kernel/internals/security/lsm.md)

- [Documentation/security/lsm-development.rst](/kernel/internals/security/lsm-development.md)

---

# Introduction of non-executable mfd

_Peios Kernel / Userspace interfaces / System and device interfaces / Security controls_

> Since Linux introduced the memfd feature, memfds have always had their execute bit set, and the memfd_create() syscall doesn't allow setting it differently.

<a id="rst-introduction-of-non-executable-mfd"></a>

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

**Author:** Daniel Verkamp &lt;[dverkamp@chromium.org](<mailto:dverkamp@chromium.org>)&gt; Jeff Xu &lt;[jeffxu@chromium.org](<mailto:jeffxu@chromium.org>)&gt;

**Contributor:** Aleksa Sarai &lt;[cyphar@cyphar.com](<mailto:cyphar@cyphar.com>)&gt;

Since Linux introduced the memfd feature, memfds have always had their execute bit set, and the memfd_create() syscall doesn't allow setting it differently.

However, in a secure-by-default system, such as ChromeOS, (where all executables should come from the rootfs, which is protected by verified boot), this executable nature of memfd opens a door for NoExec bypass and enables “confused deputy attack”.  E.g, in VRP bug \[1\]: cros_vm process created a memfd to share the content with an external process, however the memfd is overwritten and used for executing arbitrary code and root escalation. \[2\] lists more VRP of this kind.

On the other hand, executable memfd has its legit use: runc uses memfd’s seal and executable feature to copy the contents of the binary then execute them. For such a system, we need a solution to differentiate runc's use of executable memfds and an attacker's \[3\].

- **To address those above:**

  - Let memfd_create() set X bit at creation time.

  - Let memfd be sealed for modifying X bit when NX is set.

  - Add a new pid namespace sysctl: vm.memfd_noexec to help applications in migrating and enforcing non-executable MFD.

<a id="rst-user-api"></a>

## User API

`int memfd_create(const char *name, unsigned int flags)`

- **`MFD_NOEXEC_SEAL`**

  When MFD_NOEXEC_SEAL bit is set in the `flags`, memfd is created with NX. F_SEAL_EXEC is set and the memfd can't be modified to add X later. MFD_ALLOW_SEALING is also implied. This is the most common case for the application to use memfd.

- **`MFD_EXEC`**

  When MFD_EXEC bit is set in the `flags`, memfd is created with X.

- **Note:**

  `MFD_NOEXEC_SEAL` implies `MFD_ALLOW_SEALING`. In case that an app doesn't want sealing, it can add F_SEAL_SEAL after creation.

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

## Sysctl:

`pid namespaced sysctl vm.memfd_noexec`

The new pid namespaced sysctl vm.memfd_noexec has 3 values:

> - - **0: MEMFD_NOEXEC_SCOPE_EXEC**
>
>     memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL acts like MFD_EXEC was set.
>
> - - **1: MEMFD_NOEXEC_SCOPE_NOEXEC_SEAL**
>
>     memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL acts like MFD_NOEXEC_SEAL was set.
>
> - - **2: MEMFD_NOEXEC_SCOPE_NOEXEC_ENFORCED**
>
>     memfd_create() without MFD_NOEXEC_SEAL will be rejected.

The sysctl allows finer control of memfd_create for old software that doesn't set the executable bit; for example, a container with vm.memfd_noexec=1 means the old software will create non-executable memfd by default while new software can create executable memfd by setting MFD_EXEC.

The value of vm.memfd_noexec is passed to child namespace at creation time. In addition, the setting is hierarchical, i.e. during memfd_create, we will search from current ns to root ns and use the most restrictive setting.

\[1\] [https://crbug.com/1305267](<https://crbug.com/1305267>)

\[2\] [https://bugs.chromium.org/p/chromium/issues/list?q=type%3Dbug-security%20memfd%20escalation&amp;can=1](<https://bugs.chromium.org/p/chromium/issues/list?q=type%3Dbug-security%20memfd%20escalation&can=1>)

\[3\] [https://lwn.net/Articles/781013/](<https://lwn.net/Articles/781013/>)

---

# No New Privileges Flag

_Peios Kernel / Userspace interfaces / System and device interfaces / Security controls_

> The irreversible exec restriction and its interaction with Peios integrity and tokens.

<a id="rst-no-new-privileges-flag"></a>

Any task can set `no_new_privs`. Once set, the bit is inherited across fork,
clone and exec and cannot be unset:

```c
prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
```

Linux uses this flag to prevent exec from gaining authority through set-user-ID,
set-group-ID and file-capability transitions. Peios retains the flag and adds
an integrity rule: exec under `no_new_privs` cannot raise the process's PIP type
or trust above its current label. The same cap applies to unsafe traced execs.
Executing a more highly signed image therefore does not automatically raise
the integrity of a process controlled by a less trusted supervisor.

Peios authority comes from native tokens, descriptors and enabled privileges.
Unix-ID setters and `setcap` are not native authority-granting operations, even
without `no_new_privs`. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for those compatibility rules.

The flag is useful when installing seccomp filters that persist across exec.
The unprivileged filter-installation path requires `no_new_privs`; the alternative
privileged path retains its native capability check. Seccomp and Landlock add
restrictions, rather than granting access refused by KACS.

`no_new_privs` does not revoke the current token, remove already enabled native
privileges or close existing handles. It is not a substitute for native token
restriction. Transfers of descriptors with `SCM_RIGHTS` are not prohibited by
this flag itself; their own access and transfer rules still apply. Nor does
the flag authorize namespace creation or `chroot` on its own.

---

# Seccomp BPF (SECure COMPuting with filters)

_Peios Kernel / Userspace interfaces / System and device interfaces / Security controls_

> A large number of system calls are exposed to every userland process with many of them going unused for the entire lifetime of the process. As system calls change and mature, bugs are found and eradicated. A certain subset of userland…

> **Peios:** The privileged filter-installation check `CAP_SYS_ADMIN` maps to enabled `SeTcbPrivilege`; user-namespace UID 0 does not create it. `no_new_privs` also prevents exec from raising the PIP label. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>).


<a id="rst-seccomp-bpf-secure-computing-with-filters"></a>

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

## Introduction

A large number of system calls are exposed to every userland process with many of them going unused for the entire lifetime of the process. As system calls change and mature, bugs are found and eradicated.  A certain subset of userland applications benefit by having a reduced set of available system calls.  The resulting set reduces the total kernel surface exposed to the application.  System call filtering is meant for use with those applications.

Seccomp filtering provides a means for a process to specify a filter for incoming system calls.  The filter is expressed as a Berkeley Packet Filter (BPF) program, as with socket filters, except that the data operated on is related to the system call being made: system call number and the system call arguments.  This allows for expressive filtering of system calls using a filter program language with a long history of being exposed to userland and a straightforward data set.

Additionally, BPF makes it impossible for users of seccomp to fall prey to time-of-check-time-of-use (TOCTOU) attacks that are common in system call interposition frameworks.  BPF programs may not dereference pointers which constrains all filters to solely evaluating the system call arguments directly.

<a id="rst-what-it-isn-t"></a>

## What it isn't

System call filtering isn't a sandbox.  It provides a clearly defined mechanism for minimizing the exposed kernel surface.  It is meant to be a tool for sandbox developers to use.  Beyond that, policy for logical behavior and information flow should be managed with a combination of other system hardening techniques and, potentially, an LSM of your choosing.  Expressive, dynamic filters provide further options down this path (avoiding pathological sizes or selecting which of the multiplexed system calls in socketcall() is allowed, for instance) which could be construed, incorrectly, as a more complete sandboxing solution.

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

## Usage

An additional seccomp mode is added and is enabled using the same prctl(2) call as the strict seccomp.  If the architecture has `CONFIG_HAVE_ARCH_SECCOMP_FILTER`, then filters may be added as below:

- **`PR_SET_SECCOMP`:**

  Now takes an additional argument which specifies a new filter using a BPF program. The BPF program will be executed over struct seccomp_data reflecting the system call number, arguments, and other metadata.  The BPF program must then return one of the acceptable values to inform the kernel which action should be taken.

  Usage:



  ```text
  prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, prog);
  ```

  The 'prog' argument is a pointer to a struct sock_fprog which will contain the filter program.  If the program is invalid, the call will return -1 and set errno to `EINVAL`.

  If `fork`/`clone` and `execve` are allowed by @prog, any child processes will be constrained to the same filters and system call ABI as the parent.

  Before installing a filter, the task must set `no_new_privs` (for example, `prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)`) or pass the namespace `CAP_SYS_ADMIN` check. In Peios the latter requires enabled `SeTcbPrivilege`; creating a user namespace does not grant it. Otherwise installation fails with `EACCES`. The unprivileged path prevents exec-based elevation through the installed filter. It does not revoke existing native authority or prevent separately authorized native token operations.

  Additionally, if `prctl(2)` is allowed by the attached filter, additional filters may be layered on which will increase evaluation time, but allow for further decreasing the attack surface during execution of a process.

The above call returns 0 on success and non-zero on error.

<a id="rst-return-values"></a>

## Return values

A seccomp filter may return any of the following values. If multiple filters exist, the return value for the evaluation of a given system call will always use the highest precedent value. (For example, `SECCOMP_RET_KILL_PROCESS` will always take precedence.)

In precedence order, they are:

- **`SECCOMP_RET_KILL_PROCESS`:**

  Results in the entire process exiting immediately without executing the system call.  The exit status of the task (`status & 0x7f`) will be `SIGSYS`, not `SIGKILL`.

- **`SECCOMP_RET_KILL_THREAD`:**

  Results in the task exiting immediately without executing the system call.  The exit status of the task (`status & 0x7f`) will be `SIGSYS`, not `SIGKILL`.

- **`SECCOMP_RET_TRAP`:**

  Results in the kernel sending a `SIGSYS` signal to the triggering task without executing the system call. `siginfo->si_call_addr` will show the address of the system call instruction, and `siginfo->si_syscall` and `siginfo->si_arch` will indicate which syscall was attempted.  The program counter will be as though the syscall happened (i.e. it will not point to the syscall instruction).  The return value register will contain an arch- dependent value -- if resuming execution, set it to something sensible.  (The architecture dependency is because replacing it with `-ENOSYS` could overwrite some useful information.)

  The `SECCOMP_RET_DATA` portion of the return value will be passed as `si_errno`.

  `SIGSYS` triggered by seccomp will have a si_code of `SYS_SECCOMP`.

- **`SECCOMP_RET_ERRNO`:**

  Results in the lower 16-bits of the return value being passed to userland as the errno without executing the system call.

- **`SECCOMP_RET_USER_NOTIF`:**

  Results in a `struct seccomp_notif` message sent on the userspace notification fd, if it is attached, or `-ENOSYS` if it is not. See below on discussion of how to handle user notifications.

- **`SECCOMP_RET_TRACE`:**

  When returned, this value will cause the kernel to attempt to notify a `ptrace()`-based tracer prior to executing the system call.  If there is no tracer present, `-ENOSYS` is returned to userland and the system call is not executed.

  A tracer will be notified if it requests `PTRACE_O_TRACESECCOMP` using `ptrace(PTRACE_SETOPTIONS)`.  The tracer will be notified of a `PTRACE_EVENT_SECCOMP` and the `SECCOMP_RET_DATA` portion of the BPF program return value will be available to the tracer via `PTRACE_GETEVENTMSG`.

  The tracer can skip the system call by changing the syscall number to -1.  Alternatively, the tracer can change the system call requested by changing the system call to a valid syscall number.  If the tracer asks to skip the system call, then the system call will appear to return the value that the tracer puts in the return value register.

  The seccomp check will not be run again after the tracer is notified.  (This means that seccomp-based sandboxes MUST NOT allow use of ptrace, even of other sandboxed processes, without extreme care; ptracers can use this mechanism to escape.)

- **`SECCOMP_RET_LOG`:**

  Results in the system call being executed after it is logged. This should be used by application developers to learn which syscalls their application needs without having to iterate through multiple test and development cycles to build the list.

  This action will only be logged if "log" is present in the actions_logged sysctl string.

- **`SECCOMP_RET_ALLOW`:**

  Results in the system call being executed.

If multiple filters exist, the return value for the evaluation of a given system call will always use the highest precedent value.

Precedence is only determined using the `SECCOMP_RET_ACTION` mask.  When multiple filters return values of the same precedence, only the `SECCOMP_RET_DATA` from the most recently installed filter will be returned.

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

## Pitfalls

The biggest pitfall to avoid during use is filtering on system call number without checking the architecture value.  Why?  On any architecture that supports multiple system call invocation conventions, the system call numbers may vary based on the specific invocation.  If the numbers in the different calling conventions overlap, then checks in the filters may be abused.  Always check the arch value\!

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

## Example

The `samples/seccomp/` directory contains both an x86-specific example and a more generic example of a higher level macro interface for BPF program generation.

<a id="rst-userspace-notification"></a>

## Userspace Notification

The `SECCOMP_RET_USER_NOTIF` return code lets seccomp filters pass a particular syscall to userspace to be handled. This may be useful for applications like container managers, which wish to intercept particular syscalls (`mount()`, `finit_module()`, etc.) and change their behavior.

To acquire a notification FD, use the `SECCOMP_FILTER_FLAG_NEW_LISTENER` argument to the `seccomp()` syscall:



```c
fd = seccomp(SECCOMP_SET_MODE_FILTER, SECCOMP_FILTER_FLAG_NEW_LISTENER, &prog);
```

which (on success) will return a listener fd for the filter, which can then be passed around via `SCM_RIGHTS` or similar. Note that filter fds correspond to a particular filter, and not a particular task. So if this task then forks, notifications from both tasks will appear on the same filter fd. Reads and writes to/from a filter fd are also synchronized, so a filter fd can safely have many readers.

The interface for a seccomp notification fd consists of two structures:



```c
struct seccomp_notif_sizes {
    __u16 seccomp_notif;
    __u16 seccomp_notif_resp;
    __u16 seccomp_data;
};

struct seccomp_notif {
    __u64 id;
    __u32 pid;
    __u32 flags;
    struct seccomp_data data;
};

struct seccomp_notif_resp {
    __u64 id;
    __s64 val;
    __s32 error;
    __u32 flags;
};
```

The `struct seccomp_notif_sizes` structure can be used to determine the size of the various structures used in seccomp notifications. The size of `struct seccomp_data` may change in the future, so code should use:



```c
struct seccomp_notif_sizes sizes;
seccomp(SECCOMP_GET_NOTIF_SIZES, 0, &sizes);
```

to determine the size of the various structures to allocate. See samples/seccomp/user-trap.c for an example.

Users can read via `ioctl(SECCOMP_IOCTL_NOTIF_RECV)`  (or `poll()`) on a seccomp notification fd to receive a `struct seccomp_notif`, which contains five members: the input length of the structure, a unique-per-filter `id`, the `pid` of the task which triggered this request (which may be 0 if the task is in a pid ns not visible from the listener's pid namespace). The notification also contains the `data` passed to seccomp, and a filters flag. The structure should be zeroed out prior to calling the ioctl.

Userspace can then make a decision based on this information about what to do, and `ioctl(SECCOMP_IOCTL_NOTIF_SEND)` a response, indicating what should be returned to userspace. The `id` member of `struct seccomp_notif_resp` should be the same `id` as in `struct seccomp_notif`.

Userspace can also add file descriptors to the notifying process via `ioctl(SECCOMP_IOCTL_NOTIF_ADDFD)`. The `id` member of `struct seccomp_notif_addfd` should be the same `id` as in `struct seccomp_notif`. The `newfd_flags` flag may be used to set flags like O_CLOEXEC on the file descriptor in the notifying process. If the supervisor wants to inject the file descriptor with a specific number, the `SECCOMP_ADDFD_FLAG_SETFD` flag can be used, and set the `newfd` member to the specific number to use. If that file descriptor is already open in the notifying process it will be replaced. The supervisor can also add an FD, and respond atomically by using the `SECCOMP_ADDFD_FLAG_SEND` flag and the return value will be the injected file descriptor number.

The notifying process can be preempted, resulting in the notification being aborted. This can be problematic when trying to take actions on behalf of the notifying process that are long-running and typically retryable (mounting a filesystem). Alternatively, at filter installation time, the `SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV` flag can be set. This flag makes it such that when a user notification is received by the supervisor, the notifying process will ignore non-fatal signals until the response is sent. Signals that are sent prior to the notification being received by userspace are handled normally.

It is worth noting that `struct seccomp_data` contains the values of register arguments to the syscall, but does not contain pointers to memory. Reading a different process's memory through `/proc/PID/mem` needs native `PROCESS_VM_READ` access and PIP dominance; ptrace attachment requires `PROCESS_VM_WRITE`. `SeDebugPrivilege` can rescue eligible descriptor denials but cannot bypass PIP. However, care should be taken to avoid the TOCTOU mentioned above in this document: all arguments being read from the tracee's memory should be read into the tracer's memory before any policy decisions are made. This allows for an atomic decision on syscall arguments.

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

## Sysctls

Seccomp's sysctl files can be found in the `/proc/sys/kernel/seccomp/` directory. Here's a description of each file in that directory:

- **`actions_avail`:**

  A read-only ordered list of seccomp return values (refer to the `SECCOMP_RET_*` macros above) in string form. The ordering, from left-to-right, is the least permissive return value to the most permissive return value.

  The list represents the set of seccomp return values supported by the kernel. A userspace program may use this list to determine if the actions found in the `seccomp.h`, when the program was built, differs from the set of actions actually supported in the current running kernel.

- **`actions_logged`:**

  A read-write ordered list of seccomp return values (refer to the `SECCOMP_RET_*` macros above) that are allowed to be logged. Writes to the file do not need to be in ordered form but reads from the file will be ordered in the same way as the actions_avail sysctl.

  The `allow` string is not accepted in the `actions_logged` sysctl as it is not possible to log `SECCOMP_RET_ALLOW` actions. Attempting to write `allow` to the sysctl will result in an EINVAL being returned.

<a id="rst-adding-architecture-support"></a>

## Adding architecture support

See `arch/Kconfig` for the authoritative requirements.  In general, if an architecture supports both ptrace_event and seccomp, it will be able to support seccomp filter with minor fixup: `SIGSYS` support and seccomp return value checking.  Then it must just add `CONFIG_HAVE_ARCH_SECCOMP_FILTER` to its arch-specific Kconfig.

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

## Caveats

The vDSO can cause some system calls to run entirely in userspace, leading to surprises when you run programs on different machines that fall back to real syscalls.  To minimize these surprises on x86, make sure you test with `/sys/devices/system/clocksource/clocksource0/current_clocksource` set to something like `acpi_pm`.

On x86-64, vsyscall emulation is enabled by default.  (vsyscalls are legacy variants on vDSO calls.)  Currently, emulated vsyscalls will honor seccomp, with a few oddities:

- A return value of `SECCOMP_RET_TRAP` will set a `si_call_addr` pointing to the vsyscall entry for the given call and not the address after the 'syscall' instruction.  Any code which wants to restart the call should be aware that (a) a ret instruction has been emulated and (b) trying to resume the syscall will again trigger the standard vsyscall emulation security checks, making resuming the syscall mostly pointless.

- A return value of `SECCOMP_RET_TRACE` will signal the tracer as usual, but the syscall may not be changed to another system call using the orig_rax register. It may only be changed to -1 order to skip the currently emulated call. Any other change MAY terminate the process. The rip value seen by the tracer will be the syscall entry address; this is different from normal behavior.  The tracer MUST NOT modify rip or rsp.  (Do not rely on other changes terminating the process. They might work.  For example, on some kernels, choosing a syscall that only exists in future kernels will be correctly emulated (by returning `-ENOSYS`).

To detect this quirky behavior, check for `addr & ~0x0C00 == 0xFFFFFFFFFF600000`.  (For `SECCOMP_RET_TRACE`, use rip.  For `SECCOMP_RET_TRAP`, use `siginfo->si_call_addr`.)  Do not check any other condition: future kernels may improve vsyscall emulation and current kernels in vsyscall=native mode will behave differently, but the instructions at `0xF...F600{0,4,8,C}00` will not be system calls in these cases.

Note that modern systems are unlikely to use vsyscalls at all -- they are a legacy feature and they are considerably slower than standard syscalls.  New code will use the vDSO, and vDSO-issued system calls are indistinguishable from normal system calls.

---

# Speculation Control

_Peios Kernel / Userspace interfaces / System and device interfaces / Security controls_

> Quite some CPUs have speculation-related misfeatures which are in fact vulnerabilities causing data leaks in various forms even across privilege domains.

<a id="rst-speculation-control"></a>

Quite some CPUs have speculation-related misfeatures which are in fact vulnerabilities causing data leaks in various forms even across privilege domains.

The kernel provides mitigation for such vulnerabilities in various forms. Some of these mitigations are compile-time configurable and some can be supplied on the kernel command line.

There is also a class of mitigations which are very expensive, but they can be restricted to a certain set of processes or tasks in controlled environments. The mechanism to control these mitigations is via `prctl(2)`.

There are two prctl options which are related to this:

> - PR_GET_SPECULATION_CTRL
>
> - PR_SET_SPECULATION_CTRL

<a id="rst-pr-get-speculation-ctrl"></a>

## PR_GET_SPECULATION_CTRL

PR_GET_SPECULATION_CTRL returns the state of the speculation misfeature which is selected with arg2 of prctl(2). The return value uses bits 0-3 with the following meaning (with the caveat that PR_SPEC_L1D_FLUSH has less obvious semantics, see documentation for that specific control below):


<table>
<thead>
<tr>
<th>


Bit

</th>
<th>


Define

</th>
<th>


Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0

</td>
<td>


PR_SPEC_PRCTL

</td>
<td>


Mitigation can be controlled per task by PR_SET_SPECULATION_CTRL.

</td>
</tr>
<tr>
<td>


1

</td>
<td>


PR_SPEC_ENABLE

</td>
<td>


The speculation feature is enabled, mitigation is disabled.

</td>
</tr>
<tr>
<td>


2

</td>
<td>


PR_SPEC_DISABLE

</td>
<td>


The speculation feature is disabled, mitigation is enabled.

</td>
</tr>
<tr>
<td>


3

</td>
<td>


PR_SPEC_FORCE_DISABLE

</td>
<td>


Same as PR_SPEC_DISABLE, but cannot be undone. A subsequent prctl(..., PR_SPEC_ENABLE) will fail.

</td>
</tr>
<tr>
<td>


4

</td>
<td>


PR_SPEC_DISABLE_NOEXEC

</td>
<td>


Same as PR_SPEC_DISABLE, but the state will be cleared on `execve(2)`.

</td>
</tr>
</tbody>
</table>

If all bits are 0 the CPU is not affected by the speculation misfeature.

If PR_SPEC_PRCTL is set, then the per-task control of the mitigation is available. If not set, prctl(PR_SET_SPECULATION_CTRL) for the speculation misfeature will fail.

<a id="rst-pr-set-speculation-ctrl"></a>
<a id="rst-set-spec-ctrl"></a>

## PR_SET_SPECULATION_CTRL

PR_SET_SPECULATION_CTRL allows to control the speculation misfeature, which is selected by arg2 of `prctl(2)` per task. arg3 is used to hand in the control value, i.e. either PR_SPEC_ENABLE or PR_SPEC_DISABLE or PR_SPEC_FORCE_DISABLE.

<a id="rst-common-error-codes"></a>

## Common error codes


<table>
<thead>
<tr>
<th>


Value

</th>
<th>


Meaning

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


EINVAL

</td>
<td>


The prctl is not implemented by the architecture or unused prctl(2) arguments are not 0.

</td>
</tr>
<tr>
<td>


ENODEV

</td>
<td>


arg2 is selecting a not supported speculation misfeature.

</td>
</tr>
</tbody>
</table>

<a id="rst-pr-set-speculation-ctrl-error-codes"></a>

## PR_SET_SPECULATION_CTRL error codes


<table>
<thead>
<tr>
<th>


Value

</th>
<th>


Meaning

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0

</td>
<td>


Success

</td>
</tr>
<tr>
<td>


ERANGE

</td>
<td>


arg3 is incorrect, i.e. it's neither PR_SPEC_ENABLE nor PR_SPEC_DISABLE nor PR_SPEC_FORCE_DISABLE.

</td>
</tr>
<tr>
<td>


ENXIO

</td>
<td>


For PR_SPEC_STORE_BYPASS: control of the selected speculation misfeature is not possible via prctl, because of the system's boot configuration.

</td>
</tr>
<tr>
<td>


EPERM

</td>
<td>


Speculation was disabled with PR_SPEC_FORCE_DISABLE and caller tried to enable it again.

</td>
</tr>
<tr>
<td>


EPERM

</td>
<td>


For PR_SPEC_L1D_FLUSH and PR_SPEC_INDIRECT_BRANCH: control of the mitigation is not possible because of the system's boot configuration.

</td>
</tr>
</tbody>
</table>

<a id="rst-speculation-misfeature-controls"></a>

## Speculation misfeature controls

- PR_SPEC_STORE_BYPASS: Speculative Store Bypass

  - **Invocations:**

    - prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, 0, 0, 0);

    - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_ENABLE, 0, 0);

    - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE, 0, 0);

    - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_FORCE_DISABLE, 0, 0);

    - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS, PR_SPEC_DISABLE_NOEXEC, 0, 0);

- - **PR_SPEC_INDIR_BRANCH: Indirect Branch Speculation in User Processes**

    (Mitigate Spectre V2 style attacks against user processes)

  - **Invocations:**

    - prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, 0, 0, 0);

    - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, PR_SPEC_ENABLE, 0, 0);

    - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, PR_SPEC_DISABLE, 0, 0);

    - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH, PR_SPEC_FORCE_DISABLE, 0, 0);

- - **PR_SPEC_L1D_FLUSH: Flush L1D Cache on context switch out of the task**

    (works only when tasks run on non SMT cores)

For this control, PR_SPEC_ENABLE means that the **mitigation** is enabled (L1D is flushed), PR_SPEC_DISABLE means it is disabled.

> - **Invocations:**
>
>   - prctl(PR_GET_SPECULATION_CTRL, PR_SPEC_L1D_FLUSH, 0, 0, 0);
>
>   - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_L1D_FLUSH, PR_SPEC_ENABLE, 0, 0);
>
>   - prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_L1D_FLUSH, PR_SPEC_DISABLE, 0, 0);

---

# TEE (Trusted Execution Environment) Userspace API

_Peios Kernel / Userspace interfaces / System and device interfaces / Security controls_

> include/uapi/linux/tee.h defines the generic interface to a TEE.

<a id="rst-tee-trusted-execution-environment-userspace-api"></a>

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

<!-- tee: -->

include/uapi/linux/tee.h defines the generic interface to a TEE.

User space (the client) connects to the driver by opening /dev/tee\[0-9\]\* or /dev/teepriv\[0-9\]\*.

- TEE_IOC_SHM_ALLOC allocates shared memory and returns a file descriptor which user space can mmap. When user space doesn't need the file descriptor any more, it should be closed. When shared memory isn't needed any longer it should be unmapped with munmap() to allow the reuse of memory.

- TEE_IOC_VERSION lets user space know which TEE this driver handles and its capabilities.

- TEE_IOC_OPEN_SESSION opens a new session to a Trusted Application.

- TEE_IOC_INVOKE invokes a function in a Trusted Application.

- TEE_IOC_CANCEL may cancel an ongoing TEE_IOC_OPEN_SESSION or TEE_IOC_INVOKE.

- TEE_IOC_CLOSE_SESSION closes a session to a Trusted Application.

There are two classes of clients, normal clients and supplicants. The latter is a helper process for the TEE to access resources in Linux, for example file system access. A normal client opens /dev/tee\[0-9\]\* and a supplicant opens /dev/teepriv\[0-9\].

Much of the communication between clients and the TEE is opaque to the driver. The main job for the driver is to receive requests from the clients, forward them to the TEE and send back the results. In the case of supplicants the communication goes in the other direction, the TEE sends requests to the supplicant which then sends back the result.

---

# Dell Systems Management Base Driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Platform and performance interfaces_

> The Dell Systems Management Base Driver provides a sysfs interface for systems management software such as Dell OpenManage to perform system management interrupts and host control actions (system power cycle or power off after OS shutdown)…

<a id="rst-dell-systems-management-base-driver"></a>

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

## Overview

The Dell Systems Management Base Driver provides a sysfs interface for systems management software such as Dell OpenManage to perform system management interrupts and host control actions (system power cycle or power off after OS shutdown) on certain Dell systems.

Dell OpenManage requires this driver on the following Dell PowerEdge systems: 300, 1300, 1400, 400SC, 500SC, 1500SC, 1550, 600SC, 1600SC, 650, 1655MC, 700, and 750.  Other Dell software such as the open source libsmbios project is expected to make use of this driver, and it may include the use of this driver on other Dell systems.

The Dell libsmbios project aims towards providing access to as much BIOS information as possible.  See [http://linux.dell.com/libsmbios/main/](<http://linux.dell.com/libsmbios/main/>) for more information about the libsmbios project.

<a id="rst-system-management-interrupt"></a>

## System Management Interrupt

On some Dell systems, systems management software must access certain management information via a system management interrupt (SMI).  The SMI data buffer must reside in 32-bit address space, and the physical address of the buffer is required for the SMI.  The driver maintains the memory required for the SMI and provides a way for the application to generate the SMI. The driver creates the following sysfs entries for systems management software to perform these system management interrupts:



```text
/sys/devices/platform/dcdbas/smi_data
/sys/devices/platform/dcdbas/smi_data_buf_phys_addr
/sys/devices/platform/dcdbas/smi_data_buf_size
/sys/devices/platform/dcdbas/smi_request
```

Systems management software must perform the following steps to execute a SMI using this driver:

1. Lock smi_data.

2. Write system management command to smi_data.

3. Write "1" to smi_request to generate a calling interface SMI or "2" to generate a raw SMI.

4. Read system management command response from smi_data.

5. Unlock smi_data.

<a id="rst-host-control-action"></a>

## Host Control Action

Dell OpenManage supports a host control feature that allows the administrator to perform a power cycle or power off of the system after the OS has finished shutting down.  On some Dell systems, this host control feature requires that a driver perform a SMI after the OS has finished shutting down.

The driver creates the following sysfs entries for systems management software to schedule the driver to perform a power cycle or power off host control action after the system has finished shutting down:

/sys/devices/platform/dcdbas/host_control_action /sys/devices/platform/dcdbas/host_control_smi_type /sys/devices/platform/dcdbas/host_control_on_shutdown

Dell OpenManage performs the following steps to execute a power cycle or power off host control action using this driver:

1. Write host control action to be performed to host_control_action.

2. Write type of SMI that driver needs to perform to host_control_smi_type.

3. Write "1" to host_control_on_shutdown to enable host control action.

4. Initiate OS shutdown. (Driver will perform host control SMI when it is notified that the OS has finished shutting down.)

<a id="rst-host-control-smi-type"></a>

## Host Control SMI Type

The following table shows the value to write to host_control_smi_type to perform a power cycle or power off host control action:


<table>
<thead>
<tr>
<th>


PowerEdge System

</th>
<th>


Host Control SMI Type

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


300

</td>
<td>


HC_SMITYPE_TYPE1

</td>
</tr>
<tr>
<td>


1300

</td>
<td>


HC_SMITYPE_TYPE1

</td>
</tr>
<tr>
<td>


1400

</td>
<td>


HC_SMITYPE_TYPE2

</td>
</tr>
<tr>
<td>


500SC

</td>
<td>


HC_SMITYPE_TYPE2

</td>
</tr>
<tr>
<td>


1500SC

</td>
<td>


HC_SMITYPE_TYPE2

</td>
</tr>
<tr>
<td>


1550

</td>
<td>


HC_SMITYPE_TYPE2

</td>
</tr>
<tr>
<td>


600SC

</td>
<td>


HC_SMITYPE_TYPE2

</td>
</tr>
<tr>
<td>


1600SC

</td>
<td>


HC_SMITYPE_TYPE2

</td>
</tr>
<tr>
<td>


650

</td>
<td>


HC_SMITYPE_TYPE2

</td>
</tr>
<tr>
<td>


1655MC

</td>
<td>


HC_SMITYPE_TYPE2

</td>
</tr>
<tr>
<td>


700

</td>
<td>


HC_SMITYPE_TYPE3

</td>
</tr>
<tr>
<td>


750

</td>
<td>


HC_SMITYPE_TYPE3

</td>
</tr>
</tbody>
</table>

---

# ISA Plug & Play support

_Peios Kernel / Userspace interfaces / System and device interfaces / Platform and performance interfaces_

> The interface was removed in kernel 2.5.53. See pnp.rst for more details.

<a id="rst-isa-plug-play-support"></a>

<a id="rst-interface-proc-isapnp"></a>

## Interface /proc/isapnp

The interface was removed in kernel 2.5.53. See pnp.rst for more details.

<a id="rst-interface-proc-bus-isapnp"></a>

## Interface /proc/bus/isapnp

This directory allows access to ISA PnP cards and logical devices. The regular files contain the contents of ISA PnP registers for a logical device.

---

# Perf ring buffer

_Peios Kernel / Userspace interfaces / System and device interfaces / Platform and performance interfaces_

> The ring buffer is a fundamental mechanism for data transfer. perf uses ring buffers to transfer event data from kernel to user space, another kind of ring buffer which is so called auxiliary (AUX) ring buffer also plays an important role…

<a id="rst-perf-ring-buffer"></a>

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

<!-- CONTENTS

1. Introduction

2. Ring buffer implementation
2.1  Basic algorithm
2.2  Ring buffer for different tracing modes
2.2.1       Default mode
2.2.2       Per-thread mode
2.2.3       Per-CPU mode
2.2.4       System wide mode
2.3  Accessing buffer
2.3.1       Producer-consumer model
2.3.2       Properties of the ring buffers
2.3.3       Writing samples into buffer
2.3.4       Reading samples from buffer
2.3.5       Memory synchronization

3. The mechanism of AUX ring buffer
3.1  The relationship between AUX and regular ring buffers
3.2  AUX events
3.3  Snapshot mode -->

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

## 1. Introduction

The ring buffer is a fundamental mechanism for data transfer.  perf uses ring buffers to transfer event data from kernel to user space, another kind of ring buffer which is so called auxiliary (AUX) ring buffer also plays an important role for hardware tracing with Intel PT, Arm CoreSight, etc.

The ring buffer implementation is critical but it's also a very challenging work.  On the one hand, the kernel and perf tool in the user space use the ring buffer to exchange data and stores data into data file, thus the ring buffer needs to transfer data with high throughput; on the other hand, the ring buffer management should avoid significant overload to distract profiling results.

This documentation dives into the details for perf ring buffer with two parts: firstly it explains the perf ring buffer implementation, then the second part discusses the AUX ring buffer mechanism.

<a id="rst-ring-buffer-implementation"></a>

## 2. Ring buffer implementation

<a id="rst-basic-algorithm"></a>

### 2.1 Basic algorithm

That said, a typical ring buffer is managed by a head pointer and a tail pointer; the head pointer is manipulated by a writer and the tail pointer is updated by a reader respectively.



```text
+---------------------------+
|   |   |***|***|***|   |   |
+---------------------------+
        `-> Tail    `-> Head

* : the data is filled by the writer.

        Figure 1. Ring buffer
```

Perf uses the same way to manage its ring buffer.  In the implementation there are two key data structures held together in a set of consecutive pages, the control structure and then the ring buffer itself.  The page with the control structure in is known as the "user page".  Being held in continuous virtual addresses simplifies locating the ring buffer address, it is in the pages after the page with the user page.

The control structure is named as `perf_event_mmap_page`, it contains a head pointer `data_head` and a tail pointer `data_tail`.  When the kernel starts to fill records into the ring buffer, it updates the head pointer to reserve the memory so later it can safely store events into the buffer.  On the other side, when the user page is a writable mapping, the perf tool has the permission to update the tail pointer after consuming data from the ring buffer.  Yet another case is for the user page's read-only mapping, which is to be addressed in the section [2.3.3 Writing samples into buffer](<#rst-writing-samples-into-buffer>).



```text
      user page                          ring buffer
+---------+---------+   +---------------------------------------+
|data_head|data_tail|...|   |   |***|***|***|***|***|   |   |   |
+---------+---------+   +---------------------------------------+
    `          `----------------^                   ^
     `----------------------------------------------|

          * : the data is filled by the writer.

            Figure 2. Perf ring buffer
```

When using the `perf record` tool, we can specify the ring buffer size with option `-m` or `--mmap-pages=`, the given size will be rounded up to a power of two that is a multiple of a page size.  Though the kernel allocates at once for all memory pages, it's deferred to map the pages to VMA area until the perf tool accesses the buffer from the user space. In other words, at the first time accesses the buffer's page from user space in the perf tool, a data abort exception for page fault is taken and the kernel uses this occasion to map the page into process VMA (see `perf_mmap_fault()`), thus the perf tool can continue to access the page after returning from the exception.

<a id="rst-ring-buffer-for-different-tracing-modes"></a>

### 2.2 Ring buffer for different tracing modes

The perf profiles programs with different modes: default mode, per thread mode, per cpu mode, and system wide mode.  This section describes these modes and how the ring buffer meets requirements for them.  At last we will review the race conditions caused by these modes.

<a id="rst-default-mode"></a>

#### 2.2.1 Default mode

Usually we execute `perf record` command followed by a profiling program name, like below command:



```text
perf record test_program
```

This command doesn't specify any options for CPU and thread modes, the perf tool applies the default mode on the perf event.  It maps all the CPUs in the system and the profiled program's PID on the perf event, and it enables inheritance mode on the event so that child tasks inherits the events.  As a result, the perf event is attributed as:



```text
evsel::cpus::map[]    = { 0 .. _SC_NPROCESSORS_ONLN-1 }
evsel::threads::map[] = { pid }
evsel::attr::inherit  = 1
```

These attributions finally will be reflected on the deployment of ring buffers.  As shown below, the perf tool allocates individual ring buffer for each CPU, but it only enables events for the profiled program rather than for all threads in the system.  The *T1* thread represents the thread context of the 'test_program', whereas *T2* and *T3* are irrelevant threads in the system.   The perf samples are exclusively collected for the *T1* thread and stored in the ring buffer associated with the CPU on which the *T1* thread is running.



```text
          T1                      T2                 T1
        +----+              +-----------+          +----+
CPU0    |xxxx|              |xxxxxxxxxxx|          |xxxx|
        +----+--------------+-----------+----------+----+-------->
          |                                          |
          v                                          v
        +-----------------------------------------------------+
        |                  Ring buffer 0                      |
        +-----------------------------------------------------+

               T1
             +-----+
CPU1         |xxxxx|
        -----+-----+--------------------------------------------->
                |
                v
        +-----------------------------------------------------+
        |                  Ring buffer 1                      |
        +-----------------------------------------------------+

                                    T1              T3
                                  +----+        +-------+
CPU2                              |xxxx|        |xxxxxxx|
        --------------------------+----+--------+-------+-------->
                                    |
                                    v
        +-----------------------------------------------------+
        |                  Ring buffer 2                      |
        +-----------------------------------------------------+

                          T1
                   +--------------+
CPU3               |xxxxxxxxxxxxxx|
        -----------+--------------+------------------------------>
                          |
                          v
        +-----------------------------------------------------+
        |                  Ring buffer 3                      |
        +-----------------------------------------------------+

        T1: Thread 1; T2: Thread 2; T3: Thread 3
        x: Thread is in running state

            Figure 3. Ring buffer for default mode
```

<a id="rst-per-thread-mode"></a>

#### 2.2.2 Per-thread mode

By specifying option `--per-thread` in perf command, e.g.



```text
perf record --per-thread test_program
```

The perf event doesn't map to any CPUs and is only bound to the profiled process, thus, the perf event's attributions are:



```text
evsel::cpus::map[0]   = { -1 }
evsel::threads::map[] = { pid }
evsel::attr::inherit  = 0
```

In this mode, a single ring buffer is allocated for the profiled thread; if the thread is scheduled on a CPU, the events on that CPU will be enabled; and if the thread is scheduled out from the CPU, the events on the CPU will be disabled.  When the thread is migrated from one CPU to another, the events are to be disabled on the previous CPU and enabled on the next CPU correspondingly.



```text
          T1                      T2                 T1
        +----+              +-----------+          +----+
CPU0    |xxxx|              |xxxxxxxxxxx|          |xxxx|
        +----+--------------+-----------+----------+----+-------->
          |                                           |
          |    T1                                     |
          |  +-----+                                  |
CPU1      |  |xxxxx|                                  |
        --|--+-----+----------------------------------|---------->
          |     |                                     |
          |     |                   T1            T3  |
          |     |                 +----+        +---+ |
CPU2      |     |                 |xxxx|        |xxx| |
        --|-----|-----------------+----+--------+---+-|---------->
          |     |                   |                 |
          |     |         T1        |                 |
          |     |  +--------------+ |                 |
CPU3      |     |  |xxxxxxxxxxxxxx| |                 |
        --|-----|--+--------------+-|-----------------|---------->
          |     |         |         |                 |
          v     v         v         v                 v
        +-----------------------------------------------------+
        |                  Ring buffer                        |
        +-----------------------------------------------------+

        T1: Thread 1
        x: Thread is in running state

            Figure 4. Ring buffer for per-thread mode
```

When perf runs in per-thread mode, a ring buffer is allocated for the profiled thread *T1*.  The ring buffer is dedicated for thread *T1*, if the thread *T1* is running, the perf events will be recorded into the ring buffer; when the thread is sleeping, all associated events will be disabled, thus no trace data will be recorded into the ring buffer.

<a id="rst-per-cpu-mode"></a>

#### 2.2.3 Per-CPU mode

The option `-C` is used to collect samples on the list of CPUs, for example the below perf command receives option `-C 0,2`:



```text
perf record -C 0,2 test_program
```

It maps the perf event to CPUs 0 and 2, and the event is not associated to any PID.  Thus the perf event attributions are set as:



```text
evsel::cpus::map[0]   = { 0, 2 }
evsel::threads::map[] = { -1 }
evsel::attr::inherit  = 0
```

This results in the session of `perf record` will sample all threads on CPU0 and CPU2, and be terminated until test_program exits.  Even there have tasks running on CPU1 and CPU3, since the ring buffer is absent for them, any activities on these two CPUs will be ignored.  A usage case is to combine the options for per-thread mode and per-CPU mode, e.g. the options `–C 0,2` and `––per–thread` are specified together, the samples are recorded only when the profiled thread is scheduled on any of the listed CPUs.



```text
          T1                      T2                 T1
        +----+              +-----------+          +----+
CPU0    |xxxx|              |xxxxxxxxxxx|          |xxxx|
        +----+--------------+-----------+----------+----+-------->
          |                       |                  |
          v                       v                  v
        +-----------------------------------------------------+
        |                  Ring buffer 0                      |
        +-----------------------------------------------------+

               T1
             +-----+
CPU1         |xxxxx|
        -----+-----+--------------------------------------------->

                                    T1              T3
                                  +----+        +-------+
CPU2                              |xxxx|        |xxxxxxx|
        --------------------------+----+--------+-------+-------->
                                    |               |
                                    v               v
        +-----------------------------------------------------+
        |                  Ring buffer 1                      |
        +-----------------------------------------------------+

                          T1
                   +--------------+
CPU3               |xxxxxxxxxxxxxx|
        -----------+--------------+------------------------------>

        T1: Thread 1; T2: Thread 2; T3: Thread 3
        x: Thread is in running state

            Figure 5. Ring buffer for per-CPU mode
```

<a id="rst-system-wide-mode"></a>

#### 2.2.4 System wide mode

By using option `–a` or `––all–cpus`, perf collects samples on all CPUs for all tasks, we call it as the system wide mode, the command is:



```text
perf record -a test_program
```

Similar to the per-CPU mode, the perf event doesn't bind to any PID, and it maps to all CPUs in the system:



```text
evsel::cpus::map[]    = { 0 .. _SC_NPROCESSORS_ONLN-1 }
evsel::threads::map[] = { -1 }
evsel::attr::inherit  = 0
```

In the system wide mode, every CPU has its own ring buffer, all threads are monitored during the running state and the samples are recorded into the ring buffer belonging to the CPU which the events occurred on.



```text
          T1                      T2                 T1
        +----+              +-----------+          +----+
CPU0    |xxxx|              |xxxxxxxxxxx|          |xxxx|
        +----+--------------+-----------+----------+----+-------->
          |                       |                  |
          v                       v                  v
        +-----------------------------------------------------+
        |                  Ring buffer 0                      |
        +-----------------------------------------------------+

               T1
             +-----+
CPU1         |xxxxx|
        -----+-----+--------------------------------------------->
                |
                v
        +-----------------------------------------------------+
        |                  Ring buffer 1                      |
        +-----------------------------------------------------+

                                    T1              T3
                                  +----+        +-------+
CPU2                              |xxxx|        |xxxxxxx|
        --------------------------+----+--------+-------+-------->
                                    |               |
                                    v               v
        +-----------------------------------------------------+
        |                  Ring buffer 2                      |
        +-----------------------------------------------------+

                          T1
                   +--------------+
CPU3               |xxxxxxxxxxxxxx|
        -----------+--------------+------------------------------>
                          |
                          v
        +-----------------------------------------------------+
        |                  Ring buffer 3                      |
        +-----------------------------------------------------+

        T1: Thread 1; T2: Thread 2; T3: Thread 3
        x: Thread is in running state

            Figure 6. Ring buffer for system wide mode
```

<a id="rst-accessing-buffer"></a>

### 2.3 Accessing buffer

Based on the understanding of how the ring buffer is allocated in various modes, this section explains access the ring buffer.

<a id="rst-producer-consumer-model"></a>

#### 2.3.1 Producer-consumer model

In the Linux kernel, the PMU events can produce samples which are stored into the ring buffer; the perf command in user space consumes the samples by reading out data from the ring buffer and finally saves the data into the file for post analysis.  It’s a typical producer-consumer model for using the ring buffer.

The perf process polls on the PMU events and sleeps when no events are incoming.  To prevent frequent exchanges between the kernel and user space, the kernel event core layer introduces a watermark, which is stored in the `perf_buffer::watermark`.  When a sample is recorded into the ring buffer, and if the used buffer exceeds the watermark, the kernel wakes up the perf process to read samples from the ring buffer.



```text
                   Perf
                   / | Read samples
         Polling  /  `--------------|               Ring buffer
                 v                  v    ;---------------------v
+----------------+     +---------+---------+   +-------------------+
|Event wait queue|     |data_head|data_tail|   |***|***|   |   |***|
+----------------+     +---------+---------+   +-------------------+
         ^                  ^ `------------------------^
         | Wake up tasks    | Store samples
      +-----------------------------+
      |  Kernel event core layer    |
      +-----------------------------+

          * : the data is filled by the writer.

            Figure 7. Writing and reading the ring buffer
```

When the kernel event core layer notifies the user space, because multiple events might share the same ring buffer for recording samples, the core layer iterates every event associated with the ring buffer and wakes up tasks waiting on the event.  This is fulfilled by the kernel function `ring_buffer_wakeup()`.

After the perf process is woken up, it starts to check the ring buffers one by one, if it finds any ring buffer containing samples it will read out the samples for statistics or saving into the data file.  Given the perf process is able to run on any CPU, this leads to the ring buffer potentially being accessed from multiple CPUs simultaneously, which causes race conditions.  The race condition handling is described in the section [2.3.5 Memory synchronization](<#rst-memory-synchronization>).

<a id="rst-properties-of-the-ring-buffers"></a>

#### 2.3.2 Properties of the ring buffers

Linux kernel supports two write directions for the ring buffer: forward and backward.  The forward writing saves samples from the beginning of the ring buffer, the backward writing stores data from the end of the ring buffer with the reversed direction.  The perf tool determines the writing direction.

Additionally, the tool can map buffers in either read-write mode or read-only mode to the user space.

The ring buffer in the read-write mode is mapped with the property `PROT_READ | PROT_WRITE`.  With the write permission, the perf tool updates the `data_tail` to indicate the data start position.  Combining with the head pointer `data_head`, which works as the end position of the current data, the perf tool can easily know where read out the data from.

Alternatively, in the read-only mode, only the kernel keeps to update the `data_head` while the user space cannot access the `data_tail` due to the mapping property `PROT_READ`.

As a result, the matrix below illustrates the various combinations of direction and mapping characteristics.  The perf tool employs two of these combinations to support buffer types: the non-overwrite buffer and the overwritable buffer.


<table>
<thead>
<tr>
<th>


Mapping mode

</th>
<th>


Forward

</th>
<th>


Backward

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


read-write

</td>
<td>


Non-overwrite ring buffer

</td>
<td>


Not used

</td>
</tr>
<tr>
<td>


read-only

</td>
<td>


Not used

</td>
<td>


Overwritable ring buffer

</td>
</tr>
</tbody>
</table>

The non-overwrite ring buffer uses the read-write mapping with forward writing.  It starts to save data from the beginning of the ring buffer and wrap around when overflow, which is used with the read-write mode in the normal ring buffer.  When the consumer doesn't keep up with the producer, it would lose some data, the kernel keeps how many records it lost and generates the `PERF_RECORD_LOST` records in the next time when it finds a space in the ring buffer.

The overwritable ring buffer uses the backward writing with the read-only mode.  It saves the data from the end of the ring buffer and the `data_head` keeps the position of current data, the perf always knows where it starts to read and until the end of the ring buffer, thus it don't need the `data_tail`.  In this mode, it will not generate the `PERF_RECORD_LOST` records.

<a id="rst-writing-samples-into-buffer-1"></a>
<a id="rst-writing-samples-into-buffer"></a>

#### 2.3.3 Writing samples into buffer

When a sample is taken and saved into the ring buffer, the kernel prepares sample fields based on the sample type; then it prepares the info for writing ring buffer which is stored in the structure `perf_output_handle`.  In the end, the kernel outputs the sample into the ring buffer and updates the head pointer in the user page so the perf tool can see the latest value.

The structure `perf_output_handle` serves as a temporary context for tracking the information related to the buffer.  The advantages of it is that it enables concurrent writing to the buffer by different events. For example, a software event and a hardware PMU event both are enabled for profiling, two instances of `perf_output_handle` serve as separate contexts for the software event and the hardware event respectively. This allows each event to reserve its own memory space for populating the record data.

<a id="rst-reading-samples-from-buffer"></a>

#### 2.3.4 Reading samples from buffer

In the user space, the perf tool utilizes the `perf_event_mmap_page` structure to handle the head and tail of the buffer.  It also uses `perf_mmap` structure to keep track of a context for the ring buffer, this context includes information about the buffer's starting and ending addresses.  Additionally, the mask value can be utilized to compute the circular buffer pointer even for an overflow.

Similar to the kernel, the perf tool in the user space first reads out the recorded data from the ring buffer, and then updates the buffer's tail pointer `perf_event_mmap_page::data_tail`.

<a id="rst-memory-synchronization-1"></a>
<a id="rst-memory-synchronization"></a>

#### 2.3.5 Memory synchronization

The modern CPUs with relaxed memory model cannot promise the memory ordering, this means it’s possible to access the ring buffer and the `perf_event_mmap_page` structure out of order.  To assure the specific sequence for memory accessing perf ring buffer, memory barriers are used to assure the data dependency.  The rationale for the memory synchronization is as below:



```text
Kernel                          User space

if (LOAD ->data_tail) {         LOAD ->data_head
                 (A)            smp_rmb()        (C)
  STORE $data                   LOAD $data
  smp_wmb()      (B)            smp_mb()         (D)
  STORE ->data_head             STORE ->data_tail
}
```

The comments in tools/include/linux/ring_buffer.h gives nice description for why and how to use memory barriers, here we will just provide an alternative explanation:

(A) is a control dependency so that CPU assures order between checking pointer `perf_event_mmap_page::data_tail` and filling sample into ring buffer;

(D) pairs with (A).  (D) separates the ring buffer data reading from writing the pointer `data_tail`, perf tool first consumes samples and then tells the kernel that the data chunk has been released.  Since a reading operation is followed by a writing operation, thus (D) is a full memory barrier.

(B) is a writing barrier in the middle of two writing operations, which makes sure that recording a sample must be prior to updating the head pointer.

(C) pairs with (B).  (C) is a read memory barrier to ensure the head pointer is fetched before reading samples.

To implement the above algorithm, the `perf_output_put_handle()` function in the kernel and two helpers `ring_buffer_read_head()` and `ring_buffer_write_tail()` in the user space are introduced, they rely on memory barriers as described above to ensure the data dependency.

Some architectures support one-way permeable barrier with load-acquire and store-release operations, these barriers are more relaxed with less performance penalty, so (C) and (D) can be optimized to use barriers `smp_load_acquire()` and `smp_store_release()` respectively.

If an architecture doesn’t support load-acquire and store-release in its memory model, it will roll back to the old fashion of memory barrier operations.  In this case, `smp_load_acquire()` encapsulates `READ_ONCE()` + `smp_mb()`, since `smp_mb()` is costly, `ring_buffer_read_head()` doesn't invoke `smp_load_acquire()` and it uses the barriers `READ_ONCE()` + `smp_rmb()` instead.

<a id="rst-the-mechanism-of-aux-ring-buffer"></a>

## 3. The mechanism of AUX ring buffer

In this chapter, we will explain the implementation of the AUX ring buffer.  In the first part it will discuss the connection between the AUX ring buffer and the regular ring buffer, then the second part will examine how the AUX ring buffer co-works with the regular ring buffer, as well as the additional features introduced by the AUX ring buffer for the sampling mechanism.

<a id="rst-the-relationship-between-aux-and-regular-ring-buffers"></a>

### 3.1 The relationship between AUX and regular ring buffers

Generally, the AUX ring buffer is an auxiliary for the regular ring buffer.  The regular ring buffer is primarily used to store the event samples and every event format complies with the definition in the union `perf_event`; the AUX ring buffer is for recording the hardware trace data and the trace data format is hardware IP dependent.

The general use and advantage of the AUX ring buffer is that it is written directly by hardware rather than by the kernel.  For example, regular profile samples that write to the regular ring buffer cause an interrupt.  Tracing execution requires a high number of samples and using interrupts would be overwhelming for the regular ring buffer mechanism.  Having an AUX buffer allows for a region of memory more decoupled from the kernel and written to directly by hardware tracing.

The AUX ring buffer reuses the same algorithm with the regular ring buffer for the buffer management.  The control structure `perf_event_mmap_page` extends the new fields `aux_head` and `aux_tail` for the head and tail pointers of the AUX ring buffer.

During the initialisation phase, besides the mmap()-ed regular ring buffer, the perf tool invokes a second syscall in the `auxtrace_mmap__mmap()` function for the mmap of the AUX buffer with non-zero file offset; `rb_alloc_aux()` in the kernel allocates pages correspondingly, these pages will be deferred to map into VMA when handling the page fault, which is the same lazy mechanism with the regular ring buffer.

AUX events and AUX trace data are two different things.  Let's see an example:



```text
perf record -a -e cycles -e cs_etm// -- sleep 2
```

The above command enables two events: one is the event *cycles* from PMU and another is the AUX event *cs_etm* from Arm CoreSight, both are saved into the regular ring buffer while the CoreSight's AUX trace data is stored in the AUX ring buffer.

As a result, we can see the regular ring buffer and the AUX ring buffer are allocated in pairs.  The perf in default mode allocates the regular ring buffer and the AUX ring buffer per CPU-wise, which is the same as the system wide mode, however, the default mode records samples only for the profiled program, whereas the latter mode profiles for all programs in the system.  For per-thread mode, the perf tool allocates only one regular ring buffer and one AUX ring buffer for the whole session.  For the per-CPU mode, the perf allocates two kinds of ring buffers for selected CPUs specified by the option `-C`.

The below figure demonstrates the buffers' layout in the system wide mode; if there are any activities on one CPU, the AUX event samples and the hardware trace data will be recorded into the dedicated buffers for the CPU.



```text
          T1                      T2                 T1
        +----+              +-----------+          +----+
CPU0    |xxxx|              |xxxxxxxxxxx|          |xxxx|
        +----+--------------+-----------+----------+----+-------->
          |                       |                  |
          v                       v                  v
        +-----------------------------------------------------+
        |                  Ring buffer 0                      |
        +-----------------------------------------------------+
          |                       |                  |
          v                       v                  v
        +-----------------------------------------------------+
        |               AUX Ring buffer 0                     |
        +-----------------------------------------------------+

               T1
             +-----+
CPU1         |xxxxx|
        -----+-----+--------------------------------------------->
                |
                v
        +-----------------------------------------------------+
        |                  Ring buffer 1                      |
        +-----------------------------------------------------+
                |
                v
        +-----------------------------------------------------+
        |               AUX Ring buffer 1                     |
        +-----------------------------------------------------+

                                    T1              T3
                                  +----+        +-------+
CPU2                              |xxxx|        |xxxxxxx|
        --------------------------+----+--------+-------+-------->
                                    |               |
                                    v               v
        +-----------------------------------------------------+
        |                  Ring buffer 2                      |
        +-----------------------------------------------------+
                                    |               |
                                    v               v
        +-----------------------------------------------------+
        |               AUX Ring buffer 2                     |
        +-----------------------------------------------------+

                          T1
                   +--------------+
CPU3               |xxxxxxxxxxxxxx|
        -----------+--------------+------------------------------>
                          |
                          v
        +-----------------------------------------------------+
        |                  Ring buffer 3                      |
        +-----------------------------------------------------+
                          |
                          v
        +-----------------------------------------------------+
        |               AUX Ring buffer 3                     |
        +-----------------------------------------------------+

        T1: Thread 1; T2: Thread 2; T3: Thread 3
        x: Thread is in running state

            Figure 8. AUX ring buffer for system wide mode
```

<a id="rst-aux-events"></a>

### 3.2 AUX events

Similar to `perf_output_begin()` and `perf_output_end()`'s working for the regular ring buffer, `perf_aux_output_begin()` and `perf_aux_output_end()` serve for the AUX ring buffer for processing the hardware trace data.

Once the hardware trace data is stored into the AUX ring buffer, the PMU driver will stop hardware tracing by calling the `pmu::stop()` callback. Similar to the regular ring buffer, the AUX ring buffer needs to apply the memory synchronization mechanism as discussed in the section [2.3.5 Memory synchronization](<#rst-memory-synchronization>).  Since the AUX ring buffer is managed by the PMU driver, the barrier (B), which is a writing barrier to ensure the trace data is externally visible prior to updating the head pointer, is asked to be implemented in the PMU driver.

Then `pmu::stop()` can safely call the `perf_aux_output_end()` function to finish two things:

- It fills an event `PERF_RECORD_AUX` into the regular ring buffer, this event delivers the information of the start address and data size for a chunk of hardware trace data has been stored into the AUX ring buffer;

- Since the hardware trace driver has stored new trace data into the AUX ring buffer, the argument *size* indicates how many bytes have been consumed by the hardware tracing, thus `perf_aux_output_end()` updates the header pointer `perf_buffer::aux_head` to reflect the latest buffer usage.

At the end, the PMU driver will restart hardware tracing.  During this temporary suspending period, it will lose hardware trace data, which will introduce a discontinuity during decoding phase.

The event `PERF_RECORD_AUX` presents an AUX event which is handled in the kernel, but it lacks the information for saving the AUX trace data in the perf file.  When the perf tool copies the trace data from AUX ring buffer to the perf data file, it synthesizes a `PERF_RECORD_AUXTRACE` event which is not a kernel ABI, it's defined by the perf tool to describe which portion of data in the AUX ring buffer is saved.  Afterwards, the perf tool reads out the AUX trace data from the perf file based on the `PERF_RECORD_AUXTRACE` events, and the `PERF_RECORD_AUX` event is used to decode a chunk of data by correlating with time order.

<a id="rst-snapshot-mode"></a>

### 3.3 Snapshot mode

Perf supports snapshot mode for AUX ring buffer, in this mode, users only record AUX trace data at a specific time point which users are interested in.  E.g. below gives an example of how to take snapshots with 1 second interval with Arm CoreSight:



```text
perf record -e cs_etm//u -S -a program &
PERFPID=$!
while true; do
    kill -USR2 $PERFPID
    sleep 1
done
```

The main flow for snapshot mode is:

- Before a snapshot is taken, the AUX ring buffer acts in free run mode. During free run mode the perf doesn't record any of the AUX events and trace data;

- Once the perf tool receives the *USR2* signal, it triggers the callback function `auxtrace_record::snapshot_start()` to deactivate hardware tracing.  The kernel driver then populates the AUX ring buffer with the hardware trace data, and the event `PERF_RECORD_AUX` is stored in the regular ring buffer;

- Then perf tool takes a snapshot, `record__read_auxtrace_snapshot()` reads out the hardware trace data from the AUX ring buffer and saves it into perf data file;

- After the snapshot is finished, `auxtrace_record::snapshot_finish()` restarts the PMU event for AUX tracing.

The perf only accesses the head pointer `perf_event_mmap_page::aux_head` in snapshot mode and doesn’t touch tail pointer `aux_tail`, this is because the AUX ring buffer can overflow in free run mode, the tail pointer is useless in this case.  Alternatively, the callback `auxtrace_record::find_snapshot()` is introduced for making the decision of whether the AUX ring buffer has been wrapped around or not, at the end it fixes up the AUX buffer's head which are used to calculate the trace data size.

As we know, the buffers' deployment can be per-thread mode, per-CPU mode, or system wide mode, and the snapshot can be applied to any of these modes.  Below is an example of taking snapshot with system wide mode.



```text
                                     Snapshot is taken
                                             |
                                             v
                    +------------------------+
                    |  AUX Ring buffer 0     | <- aux_head
                    +------------------------+
                                             v
            +--------------------------------+
            |          AUX Ring buffer 1     | <- aux_head
            +--------------------------------+
                                             v
+--------------------------------------------+
|                      AUX Ring buffer 2     | <- aux_head
+--------------------------------------------+
                                             v
     +---------------------------------------+
     |                 AUX Ring buffer 3     | <- aux_head
     +---------------------------------------+

            Figure 9. Snapshot with system wide mode
```

---

# Platform Profile Selection (e.g. /sys/firmware/acpi/platform_profile)

_Peios Kernel / Userspace interfaces / System and device interfaces / Platform and performance interfaces_

> On modern systems the platform performance, temperature, fan and other hardware related characteristics are often dynamically configurable. The platform configuration is often automatically adjusted to the current conditions by some…

<a id="rst-platform-profile-selection-e-g-sys-firmware-acpi-platform-profile"></a>

On modern systems the platform performance, temperature, fan and other hardware related characteristics are often dynamically configurable. The platform configuration is often automatically adjusted to the current conditions by some automatic mechanism (which may very well live outside the kernel).

These auto platform adjustment mechanisms often can be configured with one of several platform profiles, with either a bias towards low power operation or towards performance.

The purpose of the platform_profile attribute is to offer a generic sysfs API for selecting the platform profile of these automatic mechanisms.

Note that this API is only for selecting the platform profile, it is NOT a goal of this API to allow monitoring the resulting performance characteristics. Monitoring performance is best done with device/vendor specific tools, e.g. turbostat.

Specifically, when selecting a high performance profile the actual achieved performance may be limited by various factors such as: the heat generated by other components, room temperature, free air flow at the bottom of a laptop, etc. It is explicitly NOT a goal of this API to let userspace know about any sub-optimal conditions which are impeding reaching the requested performance level.

Since numbers on their own cannot represent the multiple variables that a profile will adjust (power consumption, heat generation, etc) this API uses strings to describe the various profiles. To make sure that userspace gets a consistent experience the sysfs-platform_profile ABI document defines a fixed set of profile names. Drivers *must* map their internal profile representation onto this fixed set.

If there is no good match when mapping then a new profile name may be added. Drivers which wish to introduce new profile names must:

> 1. Explain why the existing profile names cannot be used.
>
> 2. Add the new profile name, along with a clear description of the expected behaviour, to the sysfs-platform_profile ABI documentation.

<a id="rst-custom-profile-support"></a>

## "Custom" profile support

The platform_profile class also supports profiles advertising a "custom" profile. This is intended to be set by drivers when the settings in the driver have been modified in a way that a standard profile doesn't represent the current state.

<a id="rst-multiple-driver-support"></a>

## Multiple driver support

When multiple drivers on a system advertise a platform profile handler, the platform profile handler core will only advertise the profiles that are common between all drivers to the `/sys/firmware/acpi` interfaces.

This is to ensure there is no ambiguity on what the profile names mean when all handlers don't support a profile.

Individual drivers will register a 'platform_profile' class device that has similar semantics as the `/sys/firmware/acpi/platform_profile` interface.

To discover which driver is associated with a platform profile handler the user can read the `name` attribute of the class device.

To discover available profiles from the class interface the user can read the `choices` attribute.

If a user wants to select a profile for a specific driver, they can do so by writing to the `profile` attribute of the driver's class device.

This will allow users to set different profiles for different drivers on the same system. If the selected profile by individual drivers differs the platform profile handler core will display the profile 'custom' to indicate that the profiles are not the same.

While the `platform_profile` attribute has the value `custom`, writing a common profile from `platform_profile_choices` to the platform_profile attribute of the platform profile handler core will set the profile for all drivers.

---

# OpenCAPI (Open Coherent Accelerator Processor Interface)

_Peios Kernel / Userspace interfaces / System and device interfaces / Compute accelerators_

> OpenCAPI is an interface between processors and accelerators. It aims at being low-latency and high-bandwidth.

<a id="rst-opencapi-open-coherent-accelerator-processor-interface"></a>

OpenCAPI is an interface between processors and accelerators. It aims at being low-latency and high-bandwidth.

The specification was developed by the OpenCAPI Consortium, and is now available from the [Compute Express Link Consortium](<https://computeexpresslink.org/resource/opencapi-specification-archive/>)<a id="rst-compute-express-link-consortium"></a>.

It allows an accelerator (which could be an FPGA, ASICs, ...) to access the host memory coherently, using virtual addresses. An OpenCAPI device can also host its own memory, that can be accessed from the host.

OpenCAPI is known in linux as 'ocxl', as the open, processor-agnostic evolution of 'cxl' (the driver for the IBM CAPI interface for powerpc), which was named that way to avoid confusion with the ISDN CAPI subsystem.

<a id="rst-high-level-view"></a>

## High-level view

OpenCAPI defines a Data Link Layer (DL) and Transaction Layer (TL), to be implemented on top of a physical link. Any processor or device implementing the DL and TL can start sharing memory.



```text
+-----------+                         +-------------+
|           |                         |             |
|           |                         | Accelerated |
| Processor |                         |  Function   |
|           |  +--------+             |    Unit     |  +--------+
|           |--| Memory |             |    (AFU)    |--| Memory |
|           |  +--------+             |             |  +--------+
+-----------+                         +-------------+
     |                                       |
+-----------+                         +-------------+
|    TL     |                         |    TLX      |
+-----------+                         +-------------+
     |                                       |
+-----------+                         +-------------+
|    DL     |                         |    DLX      |
+-----------+                         +-------------+
     |                                       |
     |                   PHY                 |
     +---------------------------------------+
```

<a id="rst-device-discovery"></a>

## Device discovery

OpenCAPI relies on a PCI-like configuration space, implemented on the device. So the host can discover AFUs by querying the config space.

OpenCAPI devices in Linux are treated like PCI devices (with a few caveats). The firmware is expected to abstract the hardware as if it was a PCI link. A lot of the existing PCI infrastructure is reused: devices are scanned and BARs are assigned during the standard PCI enumeration. Commands like 'lspci' can therefore be used to see what devices are available.

The configuration space defines the AFU(s) that can be found on the physical adapter, such as its name, how many memory contexts it can work with, the size of its MMIO areas, ...

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

## MMIO

OpenCAPI defines two MMIO areas for each AFU:

- the global MMIO area, with registers pertinent to the whole AFU.

- a per-process MMIO area, which has a fixed size for each context.

<a id="rst-afu-interrupts"></a>

## AFU interrupts

OpenCAPI includes the possibility for an AFU to send an interrupt to a host process. It is done through a 'intrp_req' defined in the Transaction Layer, specifying a 64-bit object handle which defines the interrupt.

The driver allows a process to allocate an interrupt and obtain its 64-bit object handle, that can be passed to the AFU.

<a id="rst-char-devices"></a>

## char devices

The driver creates one char device per AFU found on the physical device. A physical device may have multiple functions and each function can have multiple AFUs. At the time of this writing though, it has only been tested with devices exporting only one AFU.

Char devices can be found in /dev/ocxl/ and are named as: /dev/ocxl/&lt;AFU name&gt;.&lt;location&gt;.&lt;index&gt;

where &lt;AFU name&gt; is a max 20-character long name, as found in the config space of the AFU. &lt;location&gt; is added by the driver and can help distinguish devices when a system has more than one instance of the same OpenCAPI device. &lt;index&gt; is also to help distinguish AFUs in the unlikely case where a device carries multiple copies of the same AFU.

<a id="rst-sysfs-class"></a>

## Sysfs class

An ocxl class is added for the devices representing the AFUs. See /sys/class/ocxl. The layout is described in Documentation/ABI/testing/sysfs-class-ocxl

<a id="rst-user-api"></a>

## User API

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

### open

Based on the AFU definition found in the config space, an AFU may support working with more than one memory context, in which case the associated char device may be opened multiple times by different processes.

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

### ioctl

OCXL_IOCTL_ATTACH:

> Attach the memory context of the calling process to the AFU so that the AFU can access its memory.

OCXL_IOCTL_IRQ_ALLOC:

> Allocate an AFU interrupt and return an identifier.

OCXL_IOCTL_IRQ_FREE:

> Free a previously allocated AFU interrupt.

OCXL_IOCTL_IRQ_SET_FD:

> Associate an event fd to an AFU interrupt so that the user process can be notified when the AFU sends an interrupt.

OCXL_IOCTL_GET_METADATA:

> Obtains configuration information from the card, such at the size of MMIO areas, the AFU version, and the PASID for the current context.

OCXL_IOCTL_ENABLE_P9_WAIT:

> Allows the AFU to wake a userspace thread executing 'wait'. Returns information to userspace to allow it to configure the AFU. Note that this is only available on POWER9.

OCXL_IOCTL_GET_FEATURES:

> Reports on which CPU features that affect OpenCAPI are usable from userspace.

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

### mmap

A process can mmap the per-process MMIO area for interactions with the AFU.

---

# eBPF Userspace API

_Peios Kernel / Userspace interfaces / System and device interfaces / eBPF_

> eBPF is a kernel mechanism to provide a sandboxed runtime environment in the Linux kernel for runtime extension and instrumentation without changing kernel source code or loading kernel modules. eBPF programs can be attached to various…

<a id="rst-ebpf-userspace-api"></a>

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

eBPF is a kernel mechanism to provide a sandboxed runtime environment in the Linux kernel for runtime extension and instrumentation without changing kernel source code or loading kernel modules. eBPF programs can be attached to various kernel subsystems, including networking, tracing and Linux security modules (LSM).

For internal kernel documentation on eBPF, see [Documentation/bpf/index.rst](/kernel/internals/bpf/index.md).

- [eBPF Syscall](</kernel/userspace/userspace-api/ebpf/syscall.md>)

---

# eBPF Syscall

_Peios Kernel / Userspace interfaces / System and device interfaces / eBPF_

> The primary info for the bpf syscall is available in the man-pages for bpf(2).

<a id="rst-ebpf-syscall"></a>

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

**Authors:** - Alexei Starovoitov &lt;[ast@kernel.org](<mailto:ast@kernel.org>)&gt;

- Joe Stringer &lt;[joe@wand.net.nz](<mailto:joe@wand.net.nz>)&gt;

- Michael Kerrisk &lt;[mtk.manpages@gmail.com](<mailto:mtk.manpages@gmail.com>)&gt;

The primary info for the bpf syscall is available in the [man-pages](<https://www.kernel.org/doc/man-pages/>) for [bpf(2)](<https://man7.org/linux/man-pages/man2/bpf.2.html>).

<a id="rst-bpf-subcommand-reference"></a>

## bpf() subcommand reference


The operation to be performed by the **bpf**\ () system call is determined
by the *cmd* argument. Each operation takes an accompanying argument,
provided via *attr*, which is a pointer to a union of type *bpf_attr* (see
below). The size argument is the size of the union pointed to by *attr*.



- BPF_MAP_CREATE:
  Description
  Create a map and return a file descriptor that refers to the
  map. The close-on-exec file descriptor flag (see **fcntl**\ (2))
  is automatically enabled for the new file descriptor.

  Applying **close**\ (2) to the file descriptor returned by
  **BPF_MAP_CREATE** will delete the map (but see NOTES).

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_MAP_LOOKUP_ELEM:
  Description
  Look up an element with a given *key* in the map referred to
  by the file descriptor *map_fd*.

  The *flags* argument may be specified as one of the
  following:

  **BPF_F_LOCK**
  Look up the value of a spin-locked map without
  returning the lock. This must be specified if the
  elements contain a spinlock.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_MAP_UPDATE_ELEM:
  Description
  Create or update an element (key/value pair) in a specified map.

  The *flags* argument should be specified as one of the
  following:

  **BPF_ANY**
  Create a new element or update an existing element.
  **BPF_NOEXIST**
  Create a new element only if it did not exist.
  **BPF_EXIST**
  Update an existing element.
  **BPF_F_LOCK**
  Update a spin_lock-ed map element.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

  May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**,
  **E2BIG**, **EEXIST**, or **ENOENT**.

  **E2BIG**
  The number of elements in the map reached the
  *max_entries* limit specified at map creation time.
  **EEXIST**
  If *flags* specifies **BPF_NOEXIST** and the element
  with *key* already exists in the map.
  **ENOENT**
  If *flags* specifies **BPF_EXIST** and the element with
  *key* does not exist in the map.

- BPF_MAP_DELETE_ELEM:
  Description
  Look up and delete an element by key in a specified map.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_MAP_GET_NEXT_KEY:
  Description
  Look up an element by key in a specified map and return the key
  of the next element. Can be used to iterate over all elements
  in the map.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

  The following cases can be used to iterate over all elements of
  the map:

  * If *key* is not found, the operation returns zero and sets
    the *next_key* pointer to the key of the first element.
  * If *key* is found, the operation returns zero and sets the
    *next_key* pointer to the key of the next element.
  * If *key* is the last element, returns -1 and *errno* is set
    to **ENOENT**.

  May set *errno* to **ENOMEM**, **EFAULT**, **EPERM**, or
  **EINVAL** on error.

- BPF_PROG_LOAD:
  Description
  Verify and load an eBPF program, returning a new file
  descriptor associated with the program.

  Applying **close**\ (2) to the file descriptor returned by
  **BPF_PROG_LOAD** will unload the eBPF program (but see NOTES).

  The close-on-exec file descriptor flag (see **fcntl**\ (2)) is
  automatically enabled for the new file descriptor.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_OBJ_PIN:
  Description
  Pin an eBPF program or map referred by the specified *bpf_fd*
  to the provided *pathname* on the filesystem.

  The *pathname* argument must not contain a dot (".").

  On success, *pathname* retains a reference to the eBPF object,
  preventing deallocation of the object when the original
  *bpf_fd* is closed. This allow the eBPF object to live beyond
  **close**\ (\ *bpf_fd*\ ), and hence the lifetime of the parent
  process.

  Applying **unlink**\ (2) or similar calls to the *pathname*
  unpins the object from the filesystem, removing the reference.
  If no other file descriptors or filesystem nodes refer to the
  same object, it will be deallocated (see NOTES).

  The filesystem type for the parent directory of *pathname* must
  be **BPF_FS_MAGIC**.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_OBJ_GET:
  Description
  Open a file descriptor for the eBPF object pinned to the
  specified *pathname*.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_PROG_ATTACH:
  Description
  Attach an eBPF program to a *target_fd* at the specified
  *attach_type* hook.

  The *attach_type* specifies the eBPF attachment point to
  attach the program to, and must be one of *bpf_attach_type*
  (see below).

  The *attach_bpf_fd* must be a valid file descriptor for a
  loaded eBPF program of a cgroup, flow dissector, LIRC, sockmap
  or sock_ops type corresponding to the specified *attach_type*.

  The *target_fd* must be a valid file descriptor for a kernel
  object which depends on the attach type of *attach_bpf_fd*:

  **BPF_PROG_TYPE_CGROUP_DEVICE**,
  **BPF_PROG_TYPE_CGROUP_SKB**,
  **BPF_PROG_TYPE_CGROUP_SOCK**,
  **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
  **BPF_PROG_TYPE_CGROUP_SOCKOPT**,
  **BPF_PROG_TYPE_CGROUP_SYSCTL**,
  **BPF_PROG_TYPE_SOCK_OPS**

  Control Group v2 hierarchy with the eBPF controller
  enabled. Requires the kernel to be compiled with
  **CONFIG_CGROUP_BPF**.

  **BPF_PROG_TYPE_FLOW_DISSECTOR**

  Network namespace (eg /proc/self/ns/net).

  **BPF_PROG_TYPE_LIRC_MODE2**

  LIRC device path (eg /dev/lircN). Requires the kernel
  to be compiled with **CONFIG_BPF_LIRC_MODE2**.

  **BPF_PROG_TYPE_SK_SKB**,
  **BPF_PROG_TYPE_SK_MSG**

  eBPF map of socket type (eg **BPF_MAP_TYPE_SOCKHASH**).

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_PROG_DETACH:
  Description
  Detach the eBPF program associated with the *target_fd* at the
  hook specified by *attach_type*. The program must have been
  previously attached using **BPF_PROG_ATTACH**.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_PROG_TEST_RUN:
  Description
  Run the eBPF program associated with the *prog_fd* a *repeat*
  number of times against a provided program context *ctx_in* and
  data *data_in*, and return the modified program context
  *ctx_out*, *data_out* (for example, packet data), result of the
  execution *retval*, and *duration* of the test run.

  The sizes of the buffers provided as input and output
  parameters *ctx_in*, *ctx_out*, *data_in*, and *data_out* must
  be provided in the corresponding variables *ctx_size_in*,
  *ctx_size_out*, *data_size_in*, and/or *data_size_out*. If any
  of these parameters are not provided (ie set to NULL), the
  corresponding size field must be zero.

  Some program types have particular requirements:

  **BPF_PROG_TYPE_SK_LOOKUP**
  *data_in* and *data_out* must be NULL.

  **BPF_PROG_TYPE_RAW_TRACEPOINT**,
  **BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE**

  *ctx_out*, *data_in* and *data_out* must be NULL.
  *repeat* must be zero.

  BPF_PROG_RUN is an alias for BPF_PROG_TEST_RUN.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

  **ENOSPC**
  Either *data_size_out* or *ctx_size_out* is too small.
  **ENOTSUPP**
  This command is not supported by the program type of
  the program referred to by *prog_fd*.

- BPF_PROG_GET_NEXT_ID:
  Description
  Fetch the next eBPF program currently loaded into the kernel.

  Looks for the eBPF program with an id greater than *start_id*
  and updates *next_id* on success. If no other eBPF programs
  remain with ids higher than *start_id*, returns -1 and sets
  *errno* to **ENOENT**.

  Return
  Returns zero on success. On error, or when no id remains, -1
  is returned and *errno* is set appropriately.

- BPF_MAP_GET_NEXT_ID:
  Description
  Fetch the next eBPF map currently loaded into the kernel.

  Looks for the eBPF map with an id greater than *start_id*
  and updates *next_id* on success. If no other eBPF maps
  remain with ids higher than *start_id*, returns -1 and sets
  *errno* to **ENOENT**.

  Return
  Returns zero on success. On error, or when no id remains, -1
  is returned and *errno* is set appropriately.

- BPF_PROG_GET_FD_BY_ID:
  Description
  Open a file descriptor for the eBPF program corresponding to
  *prog_id*.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_MAP_GET_FD_BY_ID:
  Description
  Open a file descriptor for the eBPF map corresponding to
  *map_id*.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_OBJ_GET_INFO_BY_FD:
  Description
  Obtain information about the eBPF object corresponding to
  *bpf_fd*.

  Populates up to *info_len* bytes of *info*, which will be in
  one of the following formats depending on the eBPF object type
  of *bpf_fd*:

  * **struct bpf_prog_info**
  * **struct bpf_map_info**
  * **struct bpf_btf_info**
  * **struct bpf_link_info**
  * **struct bpf_token_info**

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_PROG_QUERY:
  Description
  Obtain information about eBPF programs associated with the
  specified *attach_type* hook.

  The *target_fd* must be a valid file descriptor for a kernel
  object which depends on the attach type of *attach_bpf_fd*:

  **BPF_PROG_TYPE_CGROUP_DEVICE**,
  **BPF_PROG_TYPE_CGROUP_SKB**,
  **BPF_PROG_TYPE_CGROUP_SOCK**,
  **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
  **BPF_PROG_TYPE_CGROUP_SOCKOPT**,
  **BPF_PROG_TYPE_CGROUP_SYSCTL**,
  **BPF_PROG_TYPE_SOCK_OPS**

  Control Group v2 hierarchy with the eBPF controller
  enabled. Requires the kernel to be compiled with
  **CONFIG_CGROUP_BPF**.

  **BPF_PROG_TYPE_FLOW_DISSECTOR**

  Network namespace (eg /proc/self/ns/net).

  **BPF_PROG_TYPE_LIRC_MODE2**

  LIRC device path (eg /dev/lircN). Requires the kernel
  to be compiled with **CONFIG_BPF_LIRC_MODE2**.

  **BPF_PROG_QUERY** always fetches the number of programs
  attached and the *attach_flags* which were used to attach those
  programs. Additionally, if *prog_ids* is nonzero and the number
  of attached programs is less than *prog_cnt*, populates
  *prog_ids* with the eBPF program ids of the programs attached
  at *target_fd*.

  The following flags may alter the result:

  **BPF_F_QUERY_EFFECTIVE**
  Only return information regarding programs which are
  currently effective at the specified *target_fd*.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_RAW_TRACEPOINT_OPEN:
  Description
  Attach an eBPF program to a tracepoint *name* to access kernel
  internal arguments of the tracepoint in their raw form.

  The *prog_fd* must be a valid file descriptor associated with
  a loaded eBPF program of type **BPF_PROG_TYPE_RAW_TRACEPOINT**.

  No ABI guarantees are made about the content of tracepoint
  arguments exposed to the corresponding eBPF program.

  Applying **close**\ (2) to the file descriptor returned by
  **BPF_RAW_TRACEPOINT_OPEN** will delete the map (but see NOTES).

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_BTF_LOAD:
  Description
  Verify and load BPF Type Format (BTF) metadata into the kernel,
  returning a new file descriptor associated with the metadata.
  BTF is described in more detail at
  https://www.kernel.org/doc/html/latest/bpf/btf.html.

  The *btf* parameter must point to valid memory providing
  *btf_size* bytes of BTF binary metadata.

  The returned file descriptor can be passed to other **bpf**\ ()
  subcommands such as **BPF_PROG_LOAD** or **BPF_MAP_CREATE** to
  associate the BTF with those objects.

  Similar to **BPF_PROG_LOAD**, **BPF_BTF_LOAD** has optional
  parameters to specify a *btf_log_buf*, *btf_log_size* and
  *btf_log_level* which allow the kernel to return freeform log
  output regarding the BTF verification process.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_BTF_GET_FD_BY_ID:
  Description
  Open a file descriptor for the BPF Type Format (BTF)
  corresponding to *btf_id*.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_TASK_FD_QUERY:
  Description
  Obtain information about eBPF programs associated with the
  target process identified by *pid* and *fd*.

  If the *pid* and *fd* are associated with a tracepoint, kprobe
  or uprobe perf event, then the *prog_id* and *fd_type* will
  be populated with the eBPF program id and file descriptor type
  of type **bpf_task_fd_type**. If associated with a kprobe or
  uprobe, the  *probe_offset* and *probe_addr* will also be
  populated. Optionally, if *buf* is provided, then up to
  *buf_len* bytes of *buf* will be populated with the name of
  the tracepoint, kprobe or uprobe.

  The resulting *prog_id* may be introspected in deeper detail
  using **BPF_PROG_GET_FD_BY_ID** and **BPF_OBJ_GET_INFO_BY_FD**.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_MAP_LOOKUP_AND_DELETE_ELEM:
  Description
  Look up an element with the given *key* in the map referred to
  by the file descriptor *fd*, and if found, delete the element.

  For **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map
  types, the *flags* argument needs to be set to 0, but for other
  map types, it may be specified as:

  **BPF_F_LOCK**
  Look up and delete the value of a spin-locked map
  without returning the lock. This must be specified if
  the elements contain a spinlock.

  The **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map types
  implement this command as a "pop" operation, deleting the top
  element rather than one corresponding to *key*.
  The *key* and *key_len* parameters should be zeroed when
  issuing this operation for these map types.

  This command is only valid for the following map types:
  * **BPF_MAP_TYPE_QUEUE**
  * **BPF_MAP_TYPE_STACK**
  * **BPF_MAP_TYPE_HASH**
  * **BPF_MAP_TYPE_PERCPU_HASH**
  * **BPF_MAP_TYPE_LRU_HASH**
  * **BPF_MAP_TYPE_LRU_PERCPU_HASH**

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_MAP_FREEZE:
  Description
  Freeze the permissions of the specified map.

  Write permissions may be frozen by passing zero *flags*.
  Upon success, no future syscall invocations may alter the
  map state of *map_fd*. Write operations from eBPF programs
  are still possible for a frozen map.

  Not supported for maps of type **BPF_MAP_TYPE_STRUCT_OPS**.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_BTF_GET_NEXT_ID:
  Description
  Fetch the next BPF Type Format (BTF) object currently loaded
  into the kernel.

  Looks for the BTF object with an id greater than *start_id*
  and updates *next_id* on success. If no other BTF objects
  remain with ids higher than *start_id*, returns -1 and sets
  *errno* to **ENOENT**.

  Return
  Returns zero on success. On error, or when no id remains, -1
  is returned and *errno* is set appropriately.

- BPF_MAP_LOOKUP_BATCH:
  Description
  Iterate and fetch multiple elements in a map.

  Two opaque values are used to manage batch operations,
  *in_batch* and *out_batch*. Initially, *in_batch* must be set
  to NULL to begin the batched operation. After each subsequent
  **BPF_MAP_LOOKUP_BATCH**, the caller should pass the resultant
  *out_batch* as the *in_batch* for the next operation to
  continue iteration from the current point. Both *in_batch* and
  *out_batch* must point to memory large enough to hold a key,
  except for maps of type **BPF_MAP_TYPE_{HASH, PERCPU_HASH,
  LRU_HASH, LRU_PERCPU_HASH}**, for which batch parameters
  must be at least 4 bytes wide regardless of key size.

  The *keys* and *values* are output parameters which must point
  to memory large enough to hold *count* items based on the key
  and value size of the map *map_fd*. The *keys* buffer must be
  of *key_size* * *count*. The *values* buffer must be of
  *value_size* * *count*.

  The *elem_flags* argument may be specified as one of the
  following:

  **BPF_F_LOCK**
  Look up the value of a spin-locked map without
  returning the lock. This must be specified if the
  elements contain a spinlock.

  On success, *count* elements from the map are copied into the
  user buffer, with the keys copied into *keys* and the values
  copied into the corresponding indices in *values*.

  If an error is returned and *errno* is not **EFAULT**, *count*
  is set to the number of successfully processed elements.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

  May set *errno* to **ENOSPC** to indicate that *keys* or
  *values* is too small to dump an entire bucket during
  iteration of a hash-based map type.

- BPF_MAP_LOOKUP_AND_DELETE_BATCH:
  Description
  Iterate and delete all elements in a map.

  This operation has the same behavior as
  **BPF_MAP_LOOKUP_BATCH** with two exceptions:

  * Every element that is successfully returned is also deleted
    from the map. This is at least *count* elements. Note that
    *count* is both an input and an output parameter.
  * Upon returning with *errno* set to **EFAULT**, up to
    *count* elements may be deleted without returning the keys
    and values of the deleted elements.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_MAP_UPDATE_BATCH:
  Description
  Update multiple elements in a map by *key*.

  The *keys* and *values* are input parameters which must point
  to memory large enough to hold *count* items based on the key
  and value size of the map *map_fd*. The *keys* buffer must be
  of *key_size* * *count*. The *values* buffer must be of
  *value_size* * *count*.

  Each element specified in *keys* is sequentially updated to the
  value in the corresponding index in *values*. The *in_batch*
  and *out_batch* parameters are ignored and should be zeroed.

  The *elem_flags* argument should be specified as one of the
  following:

  **BPF_ANY**
  Create new elements or update a existing elements.
  **BPF_NOEXIST**
  Create new elements only if they do not exist.
  **BPF_EXIST**
  Update existing elements.
  **BPF_F_LOCK**
  Update spin_lock-ed map elements. This must be
  specified if the map value contains a spinlock.

  On success, *count* elements from the map are updated.

  If an error is returned and *errno* is not **EFAULT**, *count*
  is set to the number of successfully processed elements.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

  May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**, or
  **E2BIG**. **E2BIG** indicates that the number of elements in
  the map reached the *max_entries* limit specified at map
  creation time.

  May set *errno* to one of the following error codes under
  specific circumstances:

  **EEXIST**
  If *flags* specifies **BPF_NOEXIST** and the element
  with *key* already exists in the map.
  **ENOENT**
  If *flags* specifies **BPF_EXIST** and the element with
  *key* does not exist in the map.

- BPF_MAP_DELETE_BATCH:
  Description
  Delete multiple elements in a map by *key*.

  The *keys* parameter is an input parameter which must point
  to memory large enough to hold *count* items based on the key
  size of the map *map_fd*, that is, *key_size* * *count*.

  Each element specified in *keys* is sequentially deleted. The
  *in_batch*, *out_batch*, and *values* parameters are ignored
  and should be zeroed.

  The *elem_flags* argument may be specified as one of the
  following:

  **BPF_F_LOCK**
  Look up the value of a spin-locked map without
  returning the lock. This must be specified if the
  elements contain a spinlock.

  On success, *count* elements from the map are updated.

  If an error is returned and *errno* is not **EFAULT**, *count*
  is set to the number of successfully processed elements. If
  *errno* is **EFAULT**, up to *count* elements may be been
  deleted.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_LINK_CREATE:
  Description
  Attach an eBPF program to a *target_fd* at the specified
  *attach_type* hook and return a file descriptor handle for
  managing the link.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_LINK_UPDATE:
  Description
  Update the eBPF program in the specified *link_fd* to
  *new_prog_fd*.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_LINK_GET_FD_BY_ID:
  Description
  Open a file descriptor for the eBPF Link corresponding to
  *link_id*.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_LINK_GET_NEXT_ID:
  Description
  Fetch the next eBPF link currently loaded into the kernel.

  Looks for the eBPF link with an id greater than *start_id*
  and updates *next_id* on success. If no other eBPF links
  remain with ids higher than *start_id*, returns -1 and sets
  *errno* to **ENOENT**.

  Return
  Returns zero on success. On error, or when no id remains, -1
  is returned and *errno* is set appropriately.

- BPF_ENABLE_STATS:
  Description
  Enable eBPF runtime statistics gathering.

  Runtime statistics gathering for the eBPF runtime is disabled
  by default to minimize the corresponding performance overhead.
  This command enables statistics globally.

  Multiple programs may independently enable statistics.
  After gathering the desired statistics, eBPF runtime statistics
  may be disabled again by calling **close**\ (2) for the file
  descriptor returned by this function. Statistics will only be
  disabled system-wide when all outstanding file descriptors
  returned by prior calls for this subcommand are closed.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_ITER_CREATE:
  Description
  Create an iterator on top of the specified *link_fd* (as
  previously created using **BPF_LINK_CREATE**) and return a
  file descriptor that can be used to trigger the iteration.

  If the resulting file descriptor is pinned to the filesystem
  using  **BPF_OBJ_PIN**, then subsequent **read**\ (2) syscalls
  for that path will trigger the iterator to read kernel state
  using the eBPF program attached to *link_fd*.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_LINK_DETACH:
  Description
  Forcefully detach the specified *link_fd* from its
  corresponding attachment point.

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_PROG_BIND_MAP:
  Description
  Bind a map to the lifetime of an eBPF program.

  The map identified by *map_fd* is bound to the program
  identified by *prog_fd* and only released when *prog_fd* is
  released. This may be used in cases where metadata should be
  associated with a program which otherwise does not contain any
  references to the map (for example, embedded in the eBPF
  program instructions).

  Return
  Returns zero on success. On error, -1 is returned and *errno*
  is set appropriately.

- BPF_TOKEN_CREATE:
  Description
  Create BPF token with embedded information about what
  BPF-related functionality it allows:
  - a set of allowed `bpf()` syscall commands;
  - a set of allowed BPF map types to be created with
  BPF_MAP_CREATE command, if BPF_MAP_CREATE itself is allowed;
  - a set of allowed BPF program types and BPF program attach
  types to be loaded with BPF_PROG_LOAD command, if
  BPF_PROG_LOAD itself is allowed.

  BPF token is created (derived) from an instance of BPF FS,
  assuming it has necessary delegation mount options specified.
  This BPF token can be passed as an extra parameter to various
  `bpf()` syscall commands to grant BPF subsystem functionality to
  unprivileged processes.

  When created, BPF token is "associated" with the owning
  user namespace of BPF FS instance (super block) that it was
  derived from, and subsequent BPF operations performed with
  BPF token would be performing capabilities checks (i.e.,
  CAP_BPF, CAP_PERFMON, CAP_NET_ADMIN, CAP_SYS_ADMIN) within
  that user namespace. Without BPF token, such capabilities
  have to be granted in init user namespace, making `bpf()`
  syscall incompatible with user namespace, for the most part.

  Return
  A new file descriptor (a nonnegative integer), or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_PROG_STREAM_READ_BY_FD:
  Description
  Read data of a program's BPF stream. The program is identified
  by *prog_fd*, and the stream is identified by the *stream_id*.
  The data is copied to a buffer pointed to by *stream_buf*, and
  filled less than or equal to *stream_buf_len* bytes.

  Return
  Number of bytes read from the stream on success, or -1 if an
  error occurred (in which case, *errno* is set appropriately).

- BPF_PROG_ASSOC_STRUCT_OPS:
  Description
  Associate a BPF program with a struct_ops map. The struct_ops
  map is identified by *map_fd* and the BPF program is
  identified by *prog_fd*.

  Return
  0 on success or -1 if an error occurred (in which case,
  *errno* is set appropriately).

- NOTES:
  eBPF objects (maps and programs) can be shared between processes.

  * After **fork**\ (2), the child inherits file descriptors
    referring to the same eBPF objects.
  * File descriptors referring to eBPF objects can be transferred over
    **unix**\ (7) domain sockets.
  * File descriptors referring to eBPF objects can be duplicated in the
    usual way, using **dup**\ (2) and similar calls.
  * File descriptors referring to eBPF objects can be pinned to the
    filesystem using the **BPF_OBJ_PIN** command of **bpf**\ (2).

  An eBPF object is deallocated only after all file descriptors referring
  to the object have been closed and no references remain pinned to the
  filesystem or attached (for example, bound to a program or device).


<!-- Links: -->

<a id="rst-man-pages"></a>



<a id="rst-bpf-2"></a>

---

# Firmware Control (FWCTL) Userspace API

_Peios Kernel / Userspace interfaces / System and device interfaces / Device firmware control_

> A framework that define a common set of limited rules that allows user space to securely construct and execute RPCs inside device firmware.

<a id="rst-firmware-control-fwctl-userspace-api"></a>

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

A framework that define a common set of limited rules that allows user space to securely construct and execute RPCs inside device firmware.

- [fwctl subsystem](</kernel/userspace/userspace-api/fwctl/fwctl.md>)
- [fwctl cxl driver](</kernel/userspace/userspace-api/fwctl/fwctl-cxl.md>)
- [fwctl pds driver](</kernel/userspace/userspace-api/fwctl/pds-fwctl.md>)

---

# fwctl cxl driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Device firmware control_

> The CXL spec defines a set of commands that can be issued to the mailbox of a CXL device or switch. It also left room for vendor specific commands to be issued to the mailbox as well. fwctl provides a path to issue a set of allowed mailbox…

<a id="rst-fwctl-cxl-driver"></a>

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

**Author:** Dave Jiang

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

## Overview

The CXL spec defines a set of commands that can be issued to the mailbox of a CXL device or switch. It also left room for vendor specific commands to be issued to the mailbox as well. fwctl provides a path to issue a set of allowed mailbox commands from user space to the device moderated by the kernel driver.

The following 3 commands will be used to support CXL Features: CXL spec r3.1 8.2.9.6.1 Get Supported Features (Opcode 0500h) CXL spec r3.1 8.2.9.6.2 Get Feature (Opcode 0501h) CXL spec r3.1 8.2.9.6.3 Set Feature (Opcode 0502h)

The "Get Supported Features" return data may be filtered by the kernel driver to drop any features that are forbidden by the kernel or being exclusively used by the kernel. The driver will set the "Set Feature Size" of the "Get Supported Features Supported Feature Entry" to 0 to indicate that the Feature cannot be modified. The "Get Supported Features" command and the "Get Features" falls under the fwctl policy of FWCTL_RPC_CONFIGURATION.

For "Set Feature" command, the access policy currently is broken down into two categories depending on the Set Feature effects reported by the device. If the Set Feature will cause immediate change to the device, the fwctl access policy must be FWCTL_RPC_DEBUG_WRITE_FULL. The effects for this level are "immediate config change", "immediate data change", "immediate policy change", or "immediate log change" for the set effects mask. If the effects are "config change with cold reset" or "config change with conventional reset", then the fwctl access policy must be FWCTL_RPC_DEBUG_WRITE or higher.

<a id="rst-fwctl-cxl-user-api"></a>

## fwctl cxl User API


#### <a id="c-struct-fwctl_rpc_cxl"></a>`struct fwctl_rpc_cxl`

ioctl(FWCTL_RPC) input for CXL

**Definition**

```c
struct fwctl_rpc_cxl {
    __u32 opcode;
    __u32 flags;
    __u32 op_size;
    __u32 reserved1;
    union {
        struct cxl_mbox_get_sup_feats_in get_sup_feats_in;
        struct cxl_mbox_get_feat_in get_feat_in;
        struct cxl_mbox_set_feat_in set_feat_in;
    };
};
```

**Members**

- `opcode`: CXL mailbox command opcode
- `flags`: Flags for the command (input).
- `op_size`: Size of input payload.
- `reserved1`: Reserved. Must be 0s.
- `{unnamed_union}`: anonymous
- `get_sup_feats_in`: Get Supported Features input
- `get_feat_in`: Get Feature input
- `set_feat_in`: Set Feature input

#### <a id="c-struct-fwctl_rpc_cxl_out"></a>`struct fwctl_rpc_cxl_out`

ioctl(FWCTL_RPC) output for CXL

**Definition**

```c
struct fwctl_rpc_cxl_out {
    __u32 size;
    __u32 retval;
    union {
        struct cxl_mbox_get_sup_feats_out get_sup_feats_out;
        __u8 payload[];
    };
};
```

**Members**

- `size`: Size of the output payload
- `retval`: Return value from device
- `{unnamed_union}`: anonymous
- `get_sup_feats_out`: Get Supported Features output
- `payload`: raw byte stream of payload


<a id="rst-driver-info-query"></a>

### 1. Driver info query

First step for the app is to issue the ioctl(FWCTL_CMD_INFO). Successful invocation of the ioctl implies the Features capability is operational and returns an all zeros 32bit payload. A `struct fwctl_info` needs to be filled out with the `fwctl_info.out_device_type` set to `FWCTL_DEVICE_TYPE_CXL`. The return data should be `struct fwctl_info_cxl` that contains a reserved 32bit field that should be all zeros.

<a id="rst-send-hardware-commands"></a>

### 2. Send hardware commands

Next step is to send the 'Get Supported Features' command to the driver from user space via ioctl(FWCTL_RPC). A `struct fwctl_rpc_cxl` is pointed to by `fwctl_rpc.in`. `struct fwctl_rpc_cxl.in_payload` points to the hardware input structure that is defined by the CXL spec. `fwctl_rpc.out` points to the buffer that contains a `struct fwctl_rpc_cxl_out` that includes the hardware output data inlined as `fwctl_rpc_cxl_out.payload`. This command is called twice. First time to retrieve the number of features supported. A second time to retrieve the specific feature details as the output data.

After getting the specific feature details, a Get/Set Feature command can be appropriately programmed and sent. For a "Set Feature" command, the retrieved feature info contains an effects field that details the resulting "Set Feature" command will trigger. That will inform the user whether the system is configured to allowed the "Set Feature" command or not.

<a id="rst-code-example-of-a-get-feature"></a>

#### Code example of a Get Feature



```c
static int cxl_fwctl_rpc_get_test_feature(int fd, struct test_feature *feat_ctx,
                                          const uint32_t expected_data)
{
        struct cxl_mbox_get_feat_in *feat_in;
        struct fwctl_rpc_cxl_out *out;
        struct fwctl_rpc rpc = {0};
        struct fwctl_rpc_cxl *in;
        size_t out_size, in_size;
        uint32_t val;
        void *data;
        int rc;

        in_size = sizeof(*in) + sizeof(*feat_in);
        rc = posix_memalign((void **)&in, 16, in_size);
        if (rc)
                return -ENOMEM;
        memset(in, 0, in_size);
        feat_in = &in->get_feat_in;

        uuid_copy(feat_in->uuid, feat_ctx->uuid);
        feat_in->count = feat_ctx->get_size;

        out_size = sizeof(*out) + feat_ctx->get_size;
        rc = posix_memalign((void **)&out, 16, out_size);
        if (rc)
                goto free_in;
        memset(out, 0, out_size);

        in->opcode = CXL_MBOX_OPCODE_GET_FEATURE;
        in->op_size = sizeof(*feat_in);

        rpc.size = sizeof(rpc);
        rpc.scope = FWCTL_RPC_CONFIGURATION;
        rpc.in_len = in_size;
        rpc.out_len = out_size;
        rpc.in = (uint64_t)(uint64_t *)in;
        rpc.out = (uint64_t)(uint64_t *)out;

        rc = send_command(fd, &rpc, out);
        if (rc)
                goto free_all;

        data = out->payload;
        val = le32toh(*(__le32 *)data);
        if (memcmp(&val, &expected_data, sizeof(val)) != 0) {
                rc = -ENXIO;
                goto free_all;
        }

free_all:
        free(out);
free_in:
        free(in);
        return rc;
}
```

Take a look at CXL CLI test directory &lt;[https://github.com/pmem/ndctl/tree/main/test/fwctl.c](<https://github.com/pmem/ndctl/tree/main/test/fwctl.c>)&gt; for a detailed user code for examples on how to exercise this path.

<a id="rst-fwctl-cxl-kernel-api"></a>

## fwctl cxl Kernel API


#### <a id="c-devm_cxl_setup_features"></a>`devm_cxl_setup_features()`

```c
int devm_cxl_setup_features(struct cxl_dev_state *cxlds)
```

Allocate and initialize features context

**Parameters**

- `struct cxl_dev_state *cxlds`: CXL device context

**Description**

Return 0 on success or -errno on failure.



#### <a id="c-struct-cxl_features_state"></a>`struct cxl_features_state`

The Features state for the device

**Definition**

```c
struct cxl_features_state {
    struct cxl_dev_state *cxlds;
    struct cxl_feat_entries {
        int num_features;
        int num_user_features;
        struct cxl_feat_entry ent[] ;
    } *entries;
};
```

**Members**

- `cxlds`: Pointer to CXL device state
- `entries`: CXl feature entry context

---

# fwctl subsystem

_Peios Kernel / Userspace interfaces / System and device interfaces / Device firmware control_

> Modern devices contain extensive amounts of FW, and in many cases, are largely software-defined pieces of hardware. The evolution of this approach is largely a reaction to Moore's Law where a chip tape out is now highly expensive, and the…

> **Peios:** Linux capability names in this interface retain their API meaning, but KACS evaluates them through native token privileges or compatibility rules. UID 0, `setcap` and Unix mode bits do not independently grant native authority. Object access and PIP checks remain additional constraints where applicable. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for the mapping and exceptions.


<a id="rst-fwctl-subsystem"></a>

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

**Author:** Jason Gunthorpe

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

## Overview

Modern devices contain extensive amounts of FW, and in many cases, are largely software-defined pieces of hardware. The evolution of this approach is largely a reaction to Moore's Law where a chip tape out is now highly expensive, and the chip design is extremely large. Replacing fixed HW logic with a flexible and tightly coupled FW/HW combination is an effective risk mitigation against chip respin. Problems in the HW design can be counteracted in device FW. This is especially true for devices which present a stable and backwards compatible interface to the operating system driver (such as NVMe).

The FW layer in devices has grown to incredible size and devices frequently integrate clusters of fast processors to run it. For example, mlx5 devices have over 30MB of FW code, and big configurations operate with over 1GB of FW managed runtime state.

The availability of such a flexible layer has created quite a variety in the industry where single pieces of silicon are now configurable software-defined devices and can operate in substantially different ways depending on the need. Further, we often see cases where specific sites wish to operate devices in ways that are highly specialized and require applications that have been tailored to their unique configuration.

Further, devices have become multi-functional and integrated to the point they no longer fit neatly into the kernel's division of subsystems. Modern multi-functional devices have drivers, such as bnxt/ice/mlx5/pds, that span many subsystems while sharing the underlying hardware using the auxiliary device system.

All together this creates a challenge for the operating system, where devices have an expansive FW environment that needs robust device-specific debugging support, and FW-driven functionality that is not well suited to “generic” interfaces. fwctl seeks to allow access to the full device functionality from user space in the areas of debuggability, management, and first-boot/nth-boot provisioning.

fwctl is aimed at the common device design pattern where the OS and FW communicate via an RPC message layer constructed with a queue or mailbox scheme. In this case the driver will typically have some layer to deliver RPC messages and collect RPC responses from device FW. The in-kernel subsystem drivers that operate the device for its primary purposes will use these RPCs to build their drivers, but devices also usually have a set of ancillary RPCs that don't really fit into any specific subsystem. For example, a HW RAID controller is primarily operated by the block layer but also comes with a set of RPCs to administer the construction of drives within the HW RAID.

In the past when devices were more single function, individual subsystems would grow different approaches to solving some of these common problems. For instance, monitoring device health, manipulating its FLASH, debugging the FW, provisioning, all have various unique interfaces across the kernel.

fwctl's purpose is to define a common set of limited rules, described below, that allow user space to securely construct and execute RPCs inside device FW. The rules serve as an agreement between the operating system and FW on how to correctly design the RPC interface. As a uAPI the subsystem provides a thin layer of discovery and a generic uAPI to deliver the RPCs and collect the response. It supports a system of user space libraries and tools which will use this interface to control the device using the device native protocols.

<a id="rst-scope-of-action"></a>

### Scope of Action

fwctl drivers are strictly restricted to being a way to operate the device FW. It is not an avenue to access random kernel internals, or other operating system SW states.

fwctl instances must operate on a well-defined device function, and the device should have a well-defined security model for what scope within the physical device the function is permitted to access. For instance, the most complex PCIe device today may broadly have several function-level scopes:

> 1. A privileged function with full access to the on-device global state and configuration
>
> 2. Multiple hypervisor functions with control over itself and child functions used with VMs
>
> 3. Multiple VM functions tightly scoped within the VM

The device may create a logical parent/child relationship between these scopes. For instance, a child VM's FW may be within the scope of the hypervisor FW. It is quite common in the VFIO world that the hypervisor environment has a complex provisioning/profiling/configuration responsibility for the function VFIO assigns to the VM.

Further, within the function, devices often have RPC commands that fall within some general scopes of action (see enum fwctl_rpc_scope):

> 1. Access to function &amp; child configuration, FLASH, etc. that becomes live at a function reset. Access to function &amp; child runtime configuration that is transparent or non-disruptive to any driver or VM.
>
> 2. Read-only access to function debug information that may report on FW objects in the function &amp; child, including FW objects owned by other kernel subsystems.
>
> 3. Write access to function &amp; child debug information strictly compatible with the principles of kernel lockdown and kernel integrity protection. Triggers a kernel taint.
>
> 4. Full debug device access. Triggers a kernel taint, requires CAP_SYS_RAWIO.

User space will provide a scope label on each RPC and the kernel must enforce the above CAPs and taints based on that scope. A combination of kernel and FW can enforce that RPCs are placed in the correct scope by user space.

<a id="rst-disallowed-behavior"></a>

### Disallowed behavior

There are many things this interface must not allow user space to do (without a taint or CAP), broadly derived from the principles of kernel lockdown. Some examples:

> 1. DMA to/from arbitrary memory, hang the system, compromise FW integrity with untrusted code, or otherwise compromise device or system security and integrity.
>
> 2. Provide an abnormal “back door” to kernel drivers. No manipulation of kernel objects owned by kernel drivers.
>
> 3. Directly configure or otherwise control kernel drivers. A subsystem kernel driver can react to the device configuration at function reset/driver load time, but otherwise must not be coupled to fwctl.
>
> 4. Operate the HW in a way that overlaps with the core purpose of another primary kernel subsystem, such as read/write to LBAs, send/receive of network packets, or operate an accelerator's data plane.

fwctl is not a replacement for device direct access subsystems like uacce or VFIO.

Operations exposed through fwctl's non-tainting interfaces should be fully sharable with other users of the device. For instance, exposing a RPC through fwctl should never prevent a kernel subsystem from also concurrently using that same RPC or hardware unit down the road. In such cases fwctl will be less important than proper kernel subsystems that eventually emerge. Mistakes in this area resulting in clashes will be resolved in favour of a kernel implementation.

<a id="rst-fwctl-user-api"></a>

## fwctl User API


**General ioctl format**

The ioctl interface follows a general format to allow for extensibility. Each
ioctl is passed a structure pointer as the argument providing the size of
the structure in the first u32. The kernel checks that any structure space
beyond what it understands is 0. This allows userspace to use the backward
compatible portion while consistently using the newer, larger, structures.

ioctls use a standard meaning for common errnos:

- ENOTTY: The IOCTL number itself is not supported at all
- E2BIG: The IOCTL number is supported, but the provided structure has
  non-zero in a part the kernel does not understand.
- EOPNOTSUPP: The IOCTL number is supported, and the structure is
  understood, however a known field has a value the kernel does not
  understand or support.
- EINVAL: Everything about the IOCTL was understood, but a field is not
  correct.
- ENOMEM: Out of memory.
- ENODEV: The underlying device has been hot-unplugged and the FD is
  orphaned.

As well as additional errnos, within specific ioctls.

#### <a id="c-struct-fwctl_info"></a>`struct fwctl_info`

ioctl(FWCTL_INFO)

**Definition**

```c
struct fwctl_info {
    __u32 size;
    __u32 flags;
    __u32 out_device_type;
    __u32 device_data_len;
    __aligned_u64 out_device_data;
};
```

**Members**

- `size`: sizeof(struct fwctl_info)
- `flags`: Must be 0
- `out_device_type`: Returns the type of the device from enum fwctl_device_type
- `device_data_len`: On input the length of the out_device_data memory. On
  output the size of the kernel's device_data which may be larger or
  smaller than the input. Maybe 0 on input.
- `out_device_data`: Pointer to a memory of device_data_len bytes. Kernel will
  fill the entire memory, zeroing as required.

**Description**

Returns basic information about this fwctl instance, particularly what driver
is being used to define the device_data format.

#### <a id="c-enum-fwctl_rpc_scope"></a>`enum fwctl_rpc_scope`

Scope of access for the RPC

**Constants**

- `FWCTL_RPC_CONFIGURATION`: Device configuration access scope

  Read/write access to device configuration. When configuration
  is written to the device it remains in a fully supported state.
- `FWCTL_RPC_DEBUG_READ_ONLY`: Read only access to debug information

  Readable debug information. Debug information is compatible with
  kernel lockdown, and does not disclose any sensitive information. For
  instance exposing any encryption secrets from this information is
  forbidden.
- `FWCTL_RPC_DEBUG_WRITE`: Writable access to lockdown compatible debug information

  Allows write access to data in the device which may leave a fully
  supported state. This is intended to permit intensive and possibly
  invasive debugging. This scope will taint the kernel.
- `FWCTL_RPC_DEBUG_WRITE_FULL`: Write access to all debug information

  Allows read/write access to everything. Requires CAP_SYS_RAW_IO, so
  it is not required to follow lockdown principals. If in doubt
  debugging should be placed in this scope. This scope will taint the
  kernel.

**Description**

Refer to fwctl.rst for a more detailed discussion of these scopes.

#### <a id="c-struct-fwctl_rpc"></a>`struct fwctl_rpc`

ioctl(FWCTL_RPC)

**Definition**

```c
struct fwctl_rpc {
    __u32 size;
    __u32 scope;
    __u32 in_len;
    __u32 out_len;
    __aligned_u64 in;
    __aligned_u64 out;
};
```

**Members**

- `size`: sizeof(struct fwctl_rpc)
- `scope`: One of enum fwctl_rpc_scope, required scope for the RPC
- `in_len`: Length of the in memory
- `out_len`: Length of the out memory
- `in`: Request message in device specific format
- `out`: Response message in device specific format

**Description**

Deliver a Remote Procedure Call to the device FW and return the response. The
call's parameters and return are marshaled into linear buffers of memory. Any
errno indicates that delivery of the RPC to the device failed. Return status
originating in the device during a successful delivery must be encoded into
out.

The format of the buffers matches the out_device_type from FWCTL_INFO.



#### <a id="c-struct-fwctl_info_mlx5"></a>`struct fwctl_info_mlx5`

ioctl(FWCTL_INFO) out_device_data

**Definition**

```c
struct fwctl_info_mlx5 {
    __u32 uid;
    __u32 uctx_caps;
};
```

**Members**

- `uid`: The FW UID this FD is bound to. Each command header will force
  this value.
- `uctx_caps`: The FW capabilities that are enabled for the uid.

**Description**

Return basic information about the FW interface available.



#### <a id="c-struct-fwctl_info_pds"></a>`struct fwctl_info_pds`

**Definition**

```c
struct fwctl_info_pds {
    __u32 uctx_caps;
};
```

**Members**

- `uctx_caps`: bitmap of firmware capabilities

**Description**

Return basic information about the FW interface available.

#### <a id="c-enum-pds_fwctl_capabilities"></a>`enum pds_fwctl_capabilities`

**Constants**

- `PDS_FWCTL_QUERY_CAP`: firmware can be queried for information
- `PDS_FWCTL_SEND_CAP`: firmware can be sent commands

#### <a id="c-struct-fwctl_rpc_pds"></a>`struct fwctl_rpc_pds`

**Definition**

```c
struct fwctl_rpc_pds {
    struct {
        __u32 op;
        __u32 ep;
        __u32 rsvd;
        __u32 len;
        __aligned_u64 payload;
    } in;
    struct {
        __u32 retval;
        __u32 rsvd[2];
        __u32 len;
        __aligned_u64 payload;
    } out;
};
```

**Members**

- `in`: rpc in parameters
- `in.op`: requested operation code
- `in.ep`: firmware endpoint to operate on
- `in.rsvd`: reserved
- `in.len`: length of payload data
- `in.payload`: address of payload buffer
- `out`: rpc out parameters
- `out.retval`: operation result value
- `out.rsvd`: reserved
- `out.len`: length of result data buffer
- `out.payload`: address of payload data buffer


<a id="rst-sysfs-class"></a>

### sysfs Class

fwctl has a sysfs class (/sys/class/fwctl/fwctlNN/) and character devices (/dev/fwctl/fwctlNN) with a simple numbered scheme. The character device operates the iotcl uAPI described above.

fwctl devices can be related to driver components in other subsystems through sysfs:



```text
$ ls /sys/class/fwctl/fwctl0/device/infiniband/
ibp0s10f0

$ ls /sys/class/infiniband/ibp0s10f0/device/fwctl/
fwctl0/

$ ls /sys/devices/pci0000:00/0000:00:0a.0/fwctl/fwctl0
dev  device  power  subsystem  uevent
```

<a id="rst-user-space-community"></a>

### User space Community

Drawing inspiration from nvme-cli, participating in the kernel side must come with a user space in a common TBD git tree, at a minimum to usefully operate the kernel driver. Providing such an implementation is a pre-condition to merging a kernel driver.

The goal is to build user space community around some of the shared problems we all have, and ideally develop some common user space programs with some starting themes of:

> - Device in-field debugging
>
> - HW provisioning
>
> - VFIO child device profiling before VM boot
>
> - Confidential Compute topics (attestation, secure provisioning)

that stretch across all subsystems in the kernel. fwupd is a great example of how an excellent user space experience can emerge out of kernel-side diversity.

<a id="rst-fwctl-kernel-api"></a>

## fwctl Kernel API


#### <a id="c-fwctl_register"></a>`fwctl_register()`

```c
int fwctl_register(struct fwctl_device *fwctl)
```

Register a new device to the subsystem

**Parameters**

- `struct fwctl_device *fwctl`: Previously allocated fwctl_device

**Description**

On return the device is visible through sysfs and /dev, driver ops may be
called.

#### <a id="c-fwctl_unregister"></a>`fwctl_unregister()`

```c
void fwctl_unregister(struct fwctl_device *fwctl)
```

Unregister a device from the subsystem

**Parameters**

- `struct fwctl_device *fwctl`: Previously allocated and registered fwctl_device

**Description**

Undoes [`fwctl_register()`](#c-fwctl_register). On return no driver ops will be called. The
caller must still call `fwctl_put()` to free the fwctl.

Unregister will return even if userspace still has file descriptors open.
This will call ops->`close_uctx()` on any open FDs and after return no driver
op will be called. The FDs remain open but all fops will return -ENODEV.

The design of fwctl allows this sort of disassociation of the driver from the
subsystem primarily by keeping memory allocations owned by the core subsytem.
The fwctl_device and fwctl_uctx can both be freed without requiring a driver
callback. This allows the module to remain unlocked while FDs are open.



#### <a id="c-struct-fwctl_ops"></a>`struct fwctl_ops`

Driver provided operations

**Definition**

```c
struct fwctl_ops {
    enum fwctl_device_type device_type;
    size_t uctx_size;
    int (*open_uctx)(struct fwctl_uctx *uctx);
    void (*close_uctx)(struct fwctl_uctx *uctx);
    void *(*info)(struct fwctl_uctx *uctx, size_t *length);
    void *(*fw_rpc)(struct fwctl_uctx *uctx, enum fwctl_rpc_scope scope, void *rpc_in, size_t in_len, size_t *out_len);
};
```

**Members**

- `device_type`: The drivers assigned device_type number. This is uABI.
- `uctx_size`: The size of the fwctl_uctx struct to allocate. The first
  bytes of this memory will be a fwctl_uctx. The driver can use the
  remaining bytes as its private memory.
- `open_uctx`: Called when a file descriptor is opened before the uctx
  is ever used.
- `close_uctx`: Called when the uctx is destroyed, usually when the FD
  is closed.
- `info`: Implement FWCTL_INFO. Return a [`kmalloc()`](/kernel/internals/core-api/mm-api.md#c-kmalloc) memory that is copied
  to out_device_data. On input length indicates the size of the user
  buffer on output it indicates the size of the memory. The driver can
  ignore length on input, the core code will handle everything.
- `fw_rpc`: Implement FWCTL_RPC. Deliver rpc_in/in_len to the FW and
  return the response and set out_len. rpc_in can be returned as the
  response pointer. Otherwise the returned pointer is freed with
  [`kvfree()`](/kernel/internals/core-api/mm-api.md#c-kvfree).

**Description**

[`fwctl_unregister()`](#c-fwctl_unregister) will wait until all excuting ops are completed before it
returns. Drivers should be mindful to not let their ops run for too long as
it will block device hot unplug and module unloading.

#### <a id="c-struct-fwctl_device"></a>`struct fwctl_device`

Per-driver registration struct

**Definition**

```c
struct fwctl_device {
    struct device dev;
};
```

**Members**

- `dev`: The sysfs (class/fwctl/fwctlXX) device

**Description**

Each driver instance will have one of these structs with the driver private
data following immediately after. This struct is refcounted, it is freed by
calling `fwctl_put()`.

#### <a id="c-fwctl_alloc_device"></a>`fwctl_alloc_device()`

```c
fwctl_alloc_device(parent, ops, drv_struct, member)
```

Allocate a fwctl

**Parameters**

- `parent`: Physical device that provides the FW interface
- `ops`: Driver ops to register
- `drv_struct`: 'struct driver_fwctl' that holds the struct fwctl_device
- `member`: Name of the struct fwctl_device in **drv_struct**

**Description**

This allocates and initializes the fwctl_device embedded in the drv_struct.
Upon success the pointer must be freed via `fwctl_put()`. Returns a 'drv_struct
\*' on success, NULL on error.

#### <a id="c-struct-fwctl_uctx"></a>`struct fwctl_uctx`

Per user FD context

**Definition**

```c
struct fwctl_uctx {
    struct fwctl_device *fwctl;
};
```

**Members**

- `fwctl`: fwctl instance that owns the context

**Description**

Every FD opened by userspace will get a unique context allocation. Any driver
private data will follow immediately after.


<a id="rst-fwctl-driver-design"></a>

### fwctl Driver design

In many cases a fwctl driver is going to be part of a larger cross-subsystem device possibly using the auxiliary_device mechanism. In that case several subsystems are going to be sharing the same device and FW interface layer so the device design must already provide for isolation and cooperation between kernel subsystems. fwctl should fit into that same model.

Part of the driver should include a description of how its scope restrictions and security model work. The driver and FW together must ensure that RPCs provided by user space are mapped to the appropriate scope. If the validation is done in the driver then the validation can read a 'command effects' report from the device, or hardwire the enforcement. If the validation is done in the FW, then the driver should pass the fwctl_rpc_scope to the FW along with the command.

The driver and FW must cooperate to ensure that either fwctl cannot allocate any FW resources, or any resources it does allocate are freed on FD closure.  A driver primarily constructed around FW RPCs may find that its core PCI function and RPC layer belongs under fwctl with auxiliary devices connecting to other subsystems.

Each device type must be mindful of Linux's philosophy for stable ABI. The FW RPC interface does not have to meet a strictly stable ABI, but it does need to meet an expectation that user space tools that are deployed and in significant use don't needlessly break. FW upgrade and kernel upgrade should keep widely deployed tooling working.

Development and debugging focused RPCs under more permissive scopes can have less stability if the tools using them are only run under exceptional circumstances and not for every day use of the device. Debugging tools may even require exact version matching as they may require something similar to DWARF debug information from the FW binary.

<a id="rst-security-response"></a>

## Security Response

The kernel remains the gatekeeper for this interface. If violations of the scopes, security or isolation principles are found, we have options to let devices fix them with a FW update, push a kernel patch to parse and block RPC commands or push a kernel patch to block entire firmware versions/devices.

While the kernel can always directly parse and restrict RPCs, it is expected that the existing kernel pattern of allowing drivers to delegate validation to FW to be a useful design.

<a id="rst-existing-similar-examples"></a>

## Existing Similar Examples

The approach described in this document is not a new idea. Direct, or near direct device access has been offered by the kernel in different areas for decades. With more devices wanting to follow this design pattern it is becoming clear that it is not entirely well understood and, more importantly, the security considerations are not well defined or agreed upon.

Some examples:

> - HW RAID controllers. This includes RPCs to do things like compose drives into a RAID volume, configure RAID parameters, monitor the HW and more.
>
> - Baseboard managers. RPCs for configuring settings in the device and more.
>
> - NVMe vendor command capsules. nvme-cli provides access to some monitoring functions that different products have defined, but more exist.
>
> - CXL also has a NVMe-like vendor command system.
>
> - DRM allows user space drivers to send commands to the device via kernel mediation.
>
> - RDMA allows user space drivers to directly push commands to the device without kernel involvement.
>
> - Various “raw” APIs, raw HID (SDL2), raw USB, NVMe Generic Interface, etc.

The first 4 are examples of areas that fwctl intends to cover. The latter three are examples of disallowed behavior as they fully overlap with the primary purpose of a kernel subsystem.

Some key lessons learned from these past efforts are the importance of having a common user space project to use as a pre-condition for obtaining a kernel driver. Developing good community around useful software in user space is key to getting companies to fund participation to enable their products.

---

# fwctl pds driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Device firmware control_

> The PDS Core device makes a fwctl service available through an auxiliary_device named pds_core.fwctl.N. The pds_fwctl driver binds to this device and registers itself with the fwctl subsystem. The resulting userspace interface is used by…

<a id="rst-fwctl-pds-driver"></a>

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

**Author:** Shannon Nelson

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

## Overview

The PDS Core device makes a fwctl service available through an auxiliary_device named pds_core.fwctl.N.  The pds_fwctl driver binds to this device and registers itself with the fwctl subsystem.  The resulting userspace interface is used by an application that is a part of the AMD Pensando software package for the Distributed Service Card (DSC).

The pds_fwctl driver has little knowledge of the firmware's internals. It only knows how to send commands through pds_core's message queue to the firmware for fwctl requests.  The set of fwctl operations available depends on the firmware in the DSC, and the userspace application version must match the firmware so that they can talk to each other.

When a connection is created the pds_fwctl driver requests from the firmware a list of firmware object endpoints, and for each endpoint the driver requests a list of operations for that endpoint.

Each operation description includes a firmware defined command attribute that maps to the FWCTL scope levels.  The driver translates those firmware values into the FWCTL scope values which can then be used for filtering the scoped user requests.

<a id="rst-pds-fwctl-user-api"></a>

## pds_fwctl User API

Each RPC request includes the target endpoint and the operation id, and in and out buffer lengths and pointers.  The driver verifies the existence of the requested endpoint and operations, then checks the request scope against the required scope of the operation.  The request is then put together with the request data and sent through pds_core's message queue to the firmware, and the results are returned to the caller.

The RPC endpoints, operations, and buffer contents are defined by the particular firmware package in the device, which varies across the available product configurations.  The details are available in the specific product SDK documentation.

---

# GPIO

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Reference for GPIO.

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

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

- [Character Device Userspace API](</kernel/userspace/userspace-api/gpio/chardev.md>)
- [Obsolete Userspace APIs](</kernel/userspace/userspace-api/gpio/obsolete.md>)

---

# GPIO Character Device Userspace API

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> This is latest version (v2) of the character device API, as defined in include/uapi/linux/gpio.h.

<a id="rst-gpio-character-device-userspace-api"></a>

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

This is latest version (v2) of the character device API, as defined in `include/uapi/linux/gpio.h.`

First added in 5.10.

> [!NOTE]
>
> Do NOT abuse userspace APIs to control hardware that has proper kernel drivers. There may already be a driver for your use case, and an existing kernel driver is sure to provide a superior solution to bitbashing from userspace.
>
> Read [Documentation/driver-api/gpio/drivers-on-gpio.rst](/kernel/hardware/driver-api/gpio/drivers-on-gpio.md) to avoid reinventing kernel wheels in userspace.
>
> Similarly, for multi-function lines there may be other subsystems, such as [Documentation/spi/index.rst](/kernel/hardware/spi/index.md), [Documentation/i2c/index.rst](/kernel/hardware/i2c/index.md), [Documentation/driver-api/pwm.rst](/kernel/hardware/driver-api/services/pwm.md), [Documentation/w1/index.rst](/kernel/hardware/w1/index.md) etc, that provide suitable drivers and APIs for your hardware.

Basic examples using the character device API can be found in `tools/gpio/*`.

The API is based around two major objects, the [Chip](<#rst-gpio-v2-chip>) and the [Line Request](<#rst-gpio-v2-line-request>).

<a id="rst-chip"></a>
<a id="rst-gpio-v2-chip"></a>

## Chip

The Chip represents a single GPIO chip and is exposed to userspace using device files of the form `/dev/gpiochipX`.

Each chip supports a number of GPIO lines, `chip.lines<gpiochip_info>`. Lines on the chip are identified by an `offset` in the range from 0 to `chip.lines - 1`, i.e. `[0,chip.lines)`.

Lines are requested from the chip using [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md) and the resulting line request is used to access the GPIO chip's lines or monitor the lines for edge events.

Within this documentation, the file descriptor returned by calling `open()` on the GPIO device file is referred to as `chip_fd`.

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

### Operations

The following operations may be performed on the chip:

- [Get Line](</kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md>)
- [Get Chip Info](</kernel/userspace/userspace-api/gpio/gpio-get-chipinfo-ioctl.md>)
- [Get Line Info](</kernel/userspace/userspace-api/gpio/gpio-v2-get-lineinfo-ioctl.md>)
- [Watch Line Info](</kernel/userspace/userspace-api/gpio/gpio-v2-get-lineinfo-watch-ioctl.md>)
- [Unwatch Line Info](</kernel/userspace/userspace-api/gpio/gpio-get-lineinfo-unwatch-ioctl.md>)
- [Read Line Info Changed Events](</kernel/userspace/userspace-api/gpio/gpio-v2-lineinfo-changed-read.md>)

<a id="rst-line-request"></a>
<a id="rst-gpio-v2-line-request"></a>

## Line Request

Line requests are created by [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md) and provide access to a set of requested lines.  The line request is exposed to userspace via the anonymous file descriptor returned in `request.fd<gpio_v2_line_request>` by [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md).

Within this documentation, the line request file descriptor is referred to as `req_fd`.

<a id="rst-operations-1"></a>

### Operations

The following operations may be performed on the line request:

- [Get Line Values](</kernel/userspace/userspace-api/gpio/gpio-v2-line-get-values-ioctl.md>)
- [Set Line Values](</kernel/userspace/userspace-api/gpio/gpio-v2-line-set-values-ioctl.md>)
- [Read Line Edge Events](</kernel/userspace/userspace-api/gpio/gpio-v2-line-event-read.md>)
- [Reconfigure Lines](</kernel/userspace/userspace-api/gpio/gpio-v2-line-set-config-ioctl.md>)

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

## Types

This section contains the structs and enums that are referenced by the API v2, as defined in `include/uapi/linux/gpio.h`.


#### <a id="c-struct-gpiochip_info"></a>`struct gpiochip_info`

Information about a certain GPIO chip

**Definition**

```c
struct gpiochip_info {
    char name[GPIO_MAX_NAME_SIZE];
    char label[GPIO_MAX_NAME_SIZE];
    __u32 lines;
};
```

**Members**

- `name`: the Linux kernel name of this GPIO chip
- `label`: a functional name for this GPIO chip, such as a product
  number, may be empty (i.e. label\[0\] == '\0')
- `lines`: number of GPIO lines on this chip

#### <a id="c-enum-gpio_v2_line_flag"></a>`enum gpio_v2_line_flag`

[`struct gpio_v2_line_attribute`](#c-struct-gpio_v2_line_attribute).flags values

**Constants**

- `GPIO_V2_LINE_FLAG_USED`: line is not available for request
- `GPIO_V2_LINE_FLAG_ACTIVE_LOW`: line active state is physical low
- `GPIO_V2_LINE_FLAG_INPUT`: line is an input
- `GPIO_V2_LINE_FLAG_OUTPUT`: line is an output
- `GPIO_V2_LINE_FLAG_EDGE_RISING`: line detects rising (inactive to active)
  edges
- `GPIO_V2_LINE_FLAG_EDGE_FALLING`: line detects falling (active to
  inactive) edges
- `GPIO_V2_LINE_FLAG_OPEN_DRAIN`: line is an open drain output
- `GPIO_V2_LINE_FLAG_OPEN_SOURCE`: line is an open source output
- `GPIO_V2_LINE_FLAG_BIAS_PULL_UP`: line has pull-up bias enabled
- `GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN`: line has pull-down bias enabled
- `GPIO_V2_LINE_FLAG_BIAS_DISABLED`: line has bias disabled
- `GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME`: line events contain REALTIME timestamps
- `GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE`: line events contain timestamps from
  the hardware timestamping engine (HTE) subsystem

#### <a id="c-struct-gpio_v2_line_values"></a>`struct gpio_v2_line_values`

Values of GPIO lines

**Definition**

```c
struct gpio_v2_line_values {
    __aligned_u64 bits;
    __aligned_u64 mask;
};
```

**Members**

- `bits`: a bitmap containing the value of the lines, set to 1 for active
  and 0 for inactive
- `mask`: a bitmap identifying the lines to get or set, with each bit
  number corresponding to the index into [`struct gpio_v2_line_request`](#c-struct-gpio_v2_line_request).offsets

#### <a id="c-enum-gpio_v2_line_attr_id"></a>`enum gpio_v2_line_attr_id`

[`struct gpio_v2_line_attribute`](#c-struct-gpio_v2_line_attribute).id values identifying which field of the attribute union is in use.

**Constants**

- `GPIO_V2_LINE_ATTR_ID_FLAGS`: flags field is in use
- `GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES`: values field is in use
- `GPIO_V2_LINE_ATTR_ID_DEBOUNCE`: debounce_period_us field is in use

#### <a id="c-struct-gpio_v2_line_attribute"></a>`struct gpio_v2_line_attribute`

a configurable attribute of a line

**Definition**

```c
struct gpio_v2_line_attribute {
    __u32 id;
    __u32 padding;
    union {
        __aligned_u64 flags;
        __aligned_u64 values;
        __u32 debounce_period_us;
    };
};
```

**Members**

- `id`: attribute identifier with value from [`enum gpio_v2_line_attr_id`](#c-enum-gpio_v2_line_attr_id)
- `padding`: reserved for future use and must be zero filled
- `{unnamed_union}`: anonymous
- `flags`: if id is `GPIO_V2_LINE_ATTR_ID_FLAGS`, the flags for the GPIO
  line, with values from [`enum gpio_v2_line_flag`](#c-enum-gpio_v2_line_flag), such as
  `GPIO_V2_LINE_FLAG_ACTIVE_LOW`, `GPIO_V2_LINE_FLAG_OUTPUT` etc, added
  together.  This overrides the default flags contained in the [`struct gpio_v2_line_config`](#c-struct-gpio_v2_line_config) for the associated line.
- `values`: if id is `GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES`, a bitmap
  containing the values to which the lines will be set, with each bit
  number corresponding to the index into [`struct gpio_v2_line_request`](#c-struct-gpio_v2_line_request).offsets
- `debounce_period_us`: if id is `GPIO_V2_LINE_ATTR_ID_DEBOUNCE`, the
  desired debounce period, in microseconds

#### <a id="c-struct-gpio_v2_line_config_attribute"></a>`struct gpio_v2_line_config_attribute`

a configuration attribute associated with one or more of the requested lines.

**Definition**

```c
struct gpio_v2_line_config_attribute {
    struct gpio_v2_line_attribute attr;
    __aligned_u64 mask;
};
```

**Members**

- `attr`: the configurable attribute
- `mask`: a bitmap identifying the lines to which the attribute applies,
  with each bit number corresponding to the index into [`struct gpio_v2_line_request`](#c-struct-gpio_v2_line_request).offsets

#### <a id="c-struct-gpio_v2_line_config"></a>`struct gpio_v2_line_config`

Configuration for GPIO lines

**Definition**

```c
struct gpio_v2_line_config {
    __aligned_u64 flags;
    __u32 num_attrs;
    __u32 padding[5];
    struct gpio_v2_line_config_attribute attrs[GPIO_V2_LINE_NUM_ATTRS_MAX];
};
```

**Members**

- `flags`: flags for the GPIO lines, with values from [`enum gpio_v2_line_flag`](#c-enum-gpio_v2_line_flag), such as `GPIO_V2_LINE_FLAG_ACTIVE_LOW`,
  `GPIO_V2_LINE_FLAG_OUTPUT` etc, added together.  This is the default for
  all requested lines but may be overridden for particular lines using
  **attrs**.
- `num_attrs`: the number of attributes in **attrs**
- `padding`: reserved for future use and must be zero filled
- `attrs`: the configuration attributes associated with the requested
  lines.  Any attribute should only be associated with a particular line
  once.  If an attribute is associated with a line multiple times then the
  first occurrence (i.e. lowest index) has precedence.

#### <a id="c-struct-gpio_v2_line_request"></a>`struct gpio_v2_line_request`

Information about a request for GPIO lines

**Definition**

```c
struct gpio_v2_line_request {
    __u32 offsets[GPIO_V2_LINES_MAX];
    char consumer[GPIO_MAX_NAME_SIZE];
    struct gpio_v2_line_config config;
    __u32 num_lines;
    __u32 event_buffer_size;
    __u32 padding[5];
    __s32 fd;
};
```

**Members**

- `offsets`: an array of desired lines, specified by offset index for the
  associated GPIO chip
- `consumer`: a desired consumer label for the selected GPIO lines such as
  "my-bitbanged-relay"
- `config`: requested configuration for the lines
- `num_lines`: number of lines requested in this request, i.e. the number
  of valid fields in the `GPIO_V2_LINES_MAX` sized arrays, set to 1 to
  request a single line
- `event_buffer_size`: a suggested minimum number of line events that the
  kernel should buffer.  This is only relevant if edge detection is
  enabled in the configuration. Note that this is only a suggested value
  and the kernel may allocate a larger buffer or cap the size of the
  buffer. If this field is zero then the buffer size defaults to a minimum
  of **num_lines** * 16.
- `padding`: reserved for future use and must be zero filled
- `fd`: after a successful `GPIO_V2_GET_LINE_IOCTL` operation, contains
  a valid anonymous file descriptor representing the request

#### <a id="c-struct-gpio_v2_line_info"></a>`struct gpio_v2_line_info`

Information about a certain GPIO line

**Definition**

```c
struct gpio_v2_line_info {
    char name[GPIO_MAX_NAME_SIZE];
    char consumer[GPIO_MAX_NAME_SIZE];
    __u32 offset;
    __u32 num_attrs;
    __aligned_u64 flags;
    struct gpio_v2_line_attribute attrs[GPIO_V2_LINE_NUM_ATTRS_MAX];
    __u32 padding[4];
};
```

**Members**

- `name`: the name of this GPIO line, such as the output pin of the line on
  the chip, a rail or a pin header name on a board, as specified by the
  GPIO chip, may be empty (i.e. name\[0\] == '\0')
- `consumer`: a functional name for the consumer of this GPIO line as set
  by whatever is using it, will be empty if there is no current user but
  may also be empty if the consumer doesn't set this up
- `offset`: the local offset on this GPIO chip, fill this in when
  requesting the line information from the kernel
- `num_attrs`: the number of attributes in **attrs**
- `flags`: flags for this GPIO line, with values from [`enum gpio_v2_line_flag`](#c-enum-gpio_v2_line_flag), such as `GPIO_V2_LINE_FLAG_ACTIVE_LOW`,
  `GPIO_V2_LINE_FLAG_OUTPUT` etc, added together
- `attrs`: the configuration attributes associated with the line
- `padding`: reserved for future use

#### <a id="c-enum-gpio_v2_line_changed_type"></a>`enum gpio_v2_line_changed_type`

`struct gpio_v2_line_changed`.event_type values

**Constants**

- `GPIO_V2_LINE_CHANGED_REQUESTED`: line has been requested
- `GPIO_V2_LINE_CHANGED_RELEASED`: line has been released
- `GPIO_V2_LINE_CHANGED_CONFIG`: line has been reconfigured

#### <a id="c-struct-gpio_v2_line_info_changed"></a>`struct gpio_v2_line_info_changed`

Information about a change in status of a GPIO line

**Definition**

```c
struct gpio_v2_line_info_changed {
    struct gpio_v2_line_info info;
    __aligned_u64 timestamp_ns;
    __u32 event_type;
    __u32 padding[5];
};
```

**Members**

- `info`: updated line information
- `timestamp_ns`: estimate of time of status change occurrence, in nanoseconds
- `event_type`: the type of change with a value from [`enum gpio_v2_line_changed_type`](#c-enum-gpio_v2_line_changed_type)
- `padding`: reserved for future use

#### <a id="c-enum-gpio_v2_line_event_id"></a>`enum gpio_v2_line_event_id`

[`struct gpio_v2_line_event`](#c-struct-gpio_v2_line_event).id values

**Constants**

- `GPIO_V2_LINE_EVENT_RISING_EDGE`: event triggered by a rising edge
- `GPIO_V2_LINE_EVENT_FALLING_EDGE`: event triggered by a falling edge

#### <a id="c-struct-gpio_v2_line_event"></a>`struct gpio_v2_line_event`

The actual event being pushed to userspace

**Definition**

```c
struct gpio_v2_line_event {
    __aligned_u64 timestamp_ns;
    __u32 id;
    __u32 offset;
    __u32 seqno;
    __u32 line_seqno;
    __u32 padding[6];
};
```

**Members**

- `timestamp_ns`: best estimate of time of event occurrence, in nanoseconds
- `id`: event identifier with value from [`enum gpio_v2_line_event_id`](#c-enum-gpio_v2_line_event_id)
- `offset`: the offset of the line that triggered the event
- `seqno`: the sequence number for this event in the sequence of events for
  all the lines in this line request
- `line_seqno`: the sequence number for this event in the sequence of
  events on this particular line
- `padding`: reserved for future use

**Description**

By default the **timestamp_ns** is read from `CLOCK_MONOTONIC` and is
intended to allow the accurate measurement of the time between events.
It does not provide the wall-clock time.

If the `GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME` flag is set then the
**timestamp_ns** is read from `CLOCK_REALTIME`.

If the `GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE` flag is set then the
**timestamp_ns** is provided by the hardware timestamping engine (HTE)
subsystem.


- [GPIO Error Codes](</kernel/userspace/userspace-api/gpio/error-codes.md>)

---

# GPIO Character Device Userspace API (v1)

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> First added in 4.8.

<a id="rst-gpio-character-device-userspace-api-v1"></a>

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

> [!WARNING]
>
> This API is obsoleted by [chardev.rst](/kernel/userspace/userspace-api/gpio/chardev.md) (v2).
>
> New developments should use the v2 API, and existing developments are encouraged to migrate as soon as possible, as this API will be removed in the future. The v2 API is a functional superset of the v1 API so any v1 call can be directly translated to a v2 equivalent.
>
> This interface will continue to be maintained for the migration period, but new features will only be added to the new API.

First added in 4.8.

The API is based around three major objects, the [Chip](<#rst-gpio-v1-chip>), the [Line Handle](<#rst-gpio-v1-line-handle>), and the [Line Event](<#rst-gpio-v1-line-event>).

Where "line event" is used in this document it refers to the request that can monitor a line for edge events, not the edge events themselves.

<a id="rst-chip"></a>
<a id="rst-gpio-v1-chip"></a>

## Chip

The Chip represents a single GPIO chip and is exposed to userspace using device files of the form `/dev/gpiochipX`.

Each chip supports a number of GPIO lines, `chip.lines<gpiochip_info>`. Lines on the chip are identified by an `offset` in the range from 0 to `chip.lines - 1`, i.e. `[0,chip.lines)`.

Lines are requested from the chip using either [gpio-get-linehandle-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md) and the resulting line handle is used to access the GPIO chip's lines, or [gpio-get-lineevent-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineevent-ioctl.md) and the resulting line event is used to monitor a GPIO line for edge events.

Within this documentation, the file descriptor returned by calling `open()` on the GPIO device file is referred to as `chip_fd`.

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

### Operations

The following operations may be performed on the chip:

- [Get Line Handle](</kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md>)
- [Get Line Event](</kernel/userspace/userspace-api/gpio/gpio-get-lineevent-ioctl.md>)
- [Get Chip Info](</kernel/userspace/userspace-api/gpio/gpio-get-chipinfo-ioctl.md>)
- [Get Line Info](</kernel/userspace/userspace-api/gpio/gpio-get-lineinfo-ioctl.md>)
- [Watch Line Info](</kernel/userspace/userspace-api/gpio/gpio-get-lineinfo-watch-ioctl.md>)
- [Unwatch Line Info](</kernel/userspace/userspace-api/gpio/gpio-get-lineinfo-unwatch-ioctl.md>)
- [Read Line Info Changed Events](</kernel/userspace/userspace-api/gpio/gpio-lineinfo-changed-read.md>)

<a id="rst-line-handle"></a>
<a id="rst-gpio-v1-line-handle"></a>

## Line Handle

Line handles are created by [gpio-get-linehandle-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md) and provide access to a set of requested lines.  The line handle is exposed to userspace via the anonymous file descriptor returned  in `request.fd<gpiohandle_request>` by [gpio-get-linehandle-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md).

Within this documentation, the line handle file descriptor is referred to as `handle_fd`.

<a id="rst-operations-1"></a>

### Operations

The following operations may be performed on the line handle:

- [Get Line Values](</kernel/userspace/userspace-api/gpio/gpio-handle-get-line-values-ioctl.md>)
- [Set Line Values](</kernel/userspace/userspace-api/gpio/gpio-handle-set-line-values-ioctl.md>)
- [Reconfigure Lines](</kernel/userspace/userspace-api/gpio/gpio-handle-set-config-ioctl.md>)

<a id="rst-line-event"></a>
<a id="rst-gpio-v1-line-event"></a>

## Line Event

Line events are created by [gpio-get-lineevent-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineevent-ioctl.md) and provide access to a requested line.  The line event is exposed to userspace via the anonymous file descriptor returned  in `request.fd<gpioevent_request>` by [gpio-get-lineevent-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineevent-ioctl.md).

Within this documentation, the line event file descriptor is referred to as `event_fd`.

<a id="rst-operations-2"></a>

### Operations

The following operations may be performed on the line event:

- [Get Line Value](</kernel/userspace/userspace-api/gpio/gpio-handle-get-line-values-ioctl.md>)
- [Read Line Edge Events](</kernel/userspace/userspace-api/gpio/gpio-lineevent-data-read.md>)

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

## Types

This section contains the structs that are referenced by the ABI v1.

The `struct gpiochip_info<gpiochip_info>` is common to ABI v1 and v2.


#### <a id="c-struct-gpioline_info"></a>`struct gpioline_info`

Information about a certain GPIO line

**Definition**

```c
struct gpioline_info {
    __u32 line_offset;
    __u32 flags;
    char name[GPIO_MAX_NAME_SIZE];
    char consumer[GPIO_MAX_NAME_SIZE];
};
```

**Members**

- `line_offset`: the local offset on this GPIO device, fill this in when
  requesting the line information from the kernel
- `flags`: various flags for this line
- `name`: the name of this GPIO line, such as the output pin of the line on the
  chip, a rail or a pin header name on a board, as specified by the gpio
  chip, may be empty (i.e. name\[0\] == '\0')
- `consumer`: a functional name for the consumer of this GPIO line as set by
  whatever is using it, will be empty if there is no current user but may
  also be empty if the consumer doesn't set this up

**Note**

This struct is part of ABI v1 and is deprecated.
Use ABI v2 and [`struct gpio_v2_line_info`](/kernel/userspace/userspace-api/gpio/chardev.md#c-struct-gpio_v2_line_info) instead.

#### <a id="c-struct-gpioline_info_changed"></a>`struct gpioline_info_changed`

Information about a change in status of a GPIO line

**Definition**

```c
struct gpioline_info_changed {
    struct gpioline_info info;
    __u64 timestamp;
    __u32 event_type;
    __u32 padding[5];
};
```

**Members**

- `info`: updated line information
- `timestamp`: estimate of time of status change occurrence, in nanoseconds
- `event_type`: one of `GPIOLINE_CHANGED_REQUESTED`,
  `GPIOLINE_CHANGED_RELEASED` and `GPIOLINE_CHANGED_CONFIG`
- `padding`: reserved for future use

**Description**

The [`struct gpioline_info`](#c-struct-gpioline_info) embedded here has 32-bit alignment on its own,
but it works fine with 64-bit alignment too. With its 72 byte size, we can
guarantee there are no implicit holes between it and subsequent members.
The 20-byte padding at the end makes sure we don't add any implicit padding
at the end of the structure on 64-bit architectures.

**Note**

This struct is part of ABI v1 and is deprecated.
Use ABI v2 and [`struct gpio_v2_line_info_changed`](/kernel/userspace/userspace-api/gpio/chardev.md#c-struct-gpio_v2_line_info_changed) instead.

#### <a id="c-struct-gpiohandle_request"></a>`struct gpiohandle_request`

Information about a GPIO handle request

**Definition**

```c
struct gpiohandle_request {
    __u32 lineoffsets[GPIOHANDLES_MAX];
    __u32 flags;
    __u8 default_values[GPIOHANDLES_MAX];
    char consumer_label[GPIO_MAX_NAME_SIZE];
    __u32 lines;
    int fd;
};
```

**Members**

- `lineoffsets`: an array of desired lines, specified by offset index for the
  associated GPIO device
- `flags`: desired flags for the desired GPIO lines, such as
  `GPIOHANDLE_REQUEST_OUTPUT`, `GPIOHANDLE_REQUEST_ACTIVE_LOW` etc, added
  together. Note that even if multiple lines are requested, the same flags
  must be applicable to all of them, if you want lines with individual
  flags set, request them one by one. It is possible to select
  a batch of input or output lines, but they must all have the same
  characteristics, i.e. all inputs or all outputs, all active low etc
- `default_values`: if the `GPIOHANDLE_REQUEST_OUTPUT` is set for a requested
  line, this specifies the default output value, should be 0 (inactive) or
  1 (active).  Anything other than 0 or 1 will be interpreted as active.
- `consumer_label`: a desired consumer label for the selected GPIO line(s)
  such as "my-bitbanged-relay"
- `lines`: number of lines requested in this request, i.e. the number of
  valid fields in the above arrays, set to 1 to request a single line
- `fd`: after a successful `GPIO_GET_LINEHANDLE_IOCTL` operation, contains
  a valid anonymous file descriptor representing the request

**Note**

This struct is part of ABI v1 and is deprecated.
Use ABI v2 and [`struct gpio_v2_line_request`](/kernel/userspace/userspace-api/gpio/chardev.md#c-struct-gpio_v2_line_request) instead.

#### <a id="c-struct-gpiohandle_config"></a>`struct gpiohandle_config`

Configuration for a GPIO handle request

**Definition**

```c
struct gpiohandle_config {
    __u32 flags;
    __u8 default_values[GPIOHANDLES_MAX];
    __u32 padding[4];
};
```

**Members**

- `flags`: updated flags for the requested GPIO lines, such as
  `GPIOHANDLE_REQUEST_OUTPUT`, `GPIOHANDLE_REQUEST_ACTIVE_LOW` etc, added
  together
- `default_values`: if the `GPIOHANDLE_REQUEST_OUTPUT` is set in flags,
  this specifies the default output value, should be 0 (inactive) or
  1 (active).  Anything other than 0 or 1 will be interpreted as active.
- `padding`: reserved for future use and should be zero filled

**Note**

This struct is part of ABI v1 and is deprecated.
Use ABI v2 and [`struct gpio_v2_line_config`](/kernel/userspace/userspace-api/gpio/chardev.md#c-struct-gpio_v2_line_config) instead.

#### <a id="c-struct-gpiohandle_data"></a>`struct gpiohandle_data`

Information of values on a GPIO handle

**Definition**

```c
struct gpiohandle_data {
    __u8 values[GPIOHANDLES_MAX];
};
```

**Members**

- `values`: when getting the state of lines this contains the current
  state of a line, when setting the state of lines these should contain
  the desired target state.  States are 0 (inactive) or 1 (active).
  When setting, anything other than 0 or 1 will be interpreted as active.

**Note**

This struct is part of ABI v1 and is deprecated.
Use ABI v2 and [`struct gpio_v2_line_values`](/kernel/userspace/userspace-api/gpio/chardev.md#c-struct-gpio_v2_line_values) instead.

#### <a id="c-struct-gpioevent_request"></a>`struct gpioevent_request`

Information about a GPIO event request

**Definition**

```c
struct gpioevent_request {
    __u32 lineoffset;
    __u32 handleflags;
    __u32 eventflags;
    char consumer_label[GPIO_MAX_NAME_SIZE];
    int fd;
};
```

**Members**

- `lineoffset`: the desired line to subscribe to events from, specified by
  offset index for the associated GPIO device
- `handleflags`: desired handle flags for the desired GPIO line, such as
  `GPIOHANDLE_REQUEST_ACTIVE_LOW` or `GPIOHANDLE_REQUEST_OPEN_DRAIN`
- `eventflags`: desired flags for the desired GPIO event line, such as
  `GPIOEVENT_REQUEST_RISING_EDGE` or `GPIOEVENT_REQUEST_FALLING_EDGE`
- `consumer_label`: a desired consumer label for the selected GPIO line(s)
  such as "my-listener"
- `fd`: after a successful `GPIO_GET_LINEEVENT_IOCTL` operation, contains a
  valid anonymous file descriptor representing the request

**Note**

This struct is part of ABI v1 and is deprecated.
Use ABI v2 and [`struct gpio_v2_line_request`](/kernel/userspace/userspace-api/gpio/chardev.md#c-struct-gpio_v2_line_request) instead.

#### <a id="c-struct-gpioevent_data"></a>`struct gpioevent_data`

The actual event being pushed to userspace

**Definition**

```c
struct gpioevent_data {
    __u64 timestamp;
    __u32 id;
};
```

**Members**

- `timestamp`: best estimate of time of event occurrence, in nanoseconds
- `id`: event identifier, one of `GPIOEVENT_EVENT_RISING_EDGE` or
  `GPIOEVENT_EVENT_FALLING_EDGE`

**Note**

This struct is part of ABI v1 and is deprecated.
Use ABI v2 and [`struct gpio_v2_line_event`](/kernel/userspace/userspace-api/gpio/chardev.md#c-struct-gpio_v2_line_event) instead.


- [GPIO Error Codes](</kernel/userspace/userspace-api/gpio/error-codes.md>)

---

# GPIO Error Codes

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Reference for GPIO Error Codes.

<a id="rst-gpio-error-codes"></a>
<a id="rst-gpio-errors"></a>

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

<a id="rst-gpio-errors-1"></a>



<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<caption>Common GPIO error codes</caption>
<tbody>
<tr>
<td>


`EAGAIN` (aka `EWOULDBLOCK`)

</td>
<td>


The device was opened in non-blocking mode and a read can't be performed as there is no data available.

</td>
</tr>
<tr>
<td>


`EBADF`

</td>
<td>


The file descriptor is not valid.

</td>
</tr>
<tr>
<td>


`EBUSY`

</td>
<td>


The ioctl can't be handled because the device is busy. Typically returned when an ioctl attempts something that would require the usage of a resource that was already allocated. The ioctl must not be retried without performing another action to fix the problem first.

</td>
</tr>
<tr>
<td>


`EFAULT`

</td>
<td>


There was a failure while copying data from/to userspace, probably caused by an invalid pointer reference.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td>


One or more of the ioctl parameters are invalid or out of the allowed range. This is a widely used error code.

</td>
</tr>
<tr>
<td>


`ENODEV`

</td>
<td>


Device not found or was removed.

</td>
</tr>
<tr>
<td>


`ENOMEM`

</td>
<td>


There's not enough memory to handle the desired operation.

</td>
</tr>
<tr>
<td>


`EPERM`

</td>
<td>


Permission denied. Typically returned in response to an attempt to perform an action incompatible with the current line configuration.

</td>
</tr>
<tr>
<td>


`EIO`

</td>
<td>


I/O error. Typically returned when there are problems communicating with a hardware device or requesting features that hardware does not support. This could indicate broken or flaky hardware. It's a 'Something is wrong, I give up\!' type of error.

</td>
</tr>
<tr>
<td>


`ENXIO`

</td>
<td>


Typically returned when a feature requiring interrupt support was requested, but the line does not support interrupts.

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> 1. This list is not exhaustive; ioctls may return other error codes. Since errors may have side effects such as a driver reset, applications should abort on unexpected errors, or otherwise assume that the device is in a bad state.
>
> 2. Request-specific error codes are listed in the individual requests descriptions.

---

# GPIO_GET_CHIPINFO_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_get_chipinfo_ioctl".

<a id="rst-gpio-get-chipinfo-ioctl-1"></a>
<a id="rst-gpio-get-chipinfo-ioctl"></a>

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

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

## Name

GPIO_GET_CHIPINFO_IOCTL - Get the publicly available information for a chip.

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

## Synopsis





<a id="c-GPIO_GET_CHIPINFO_IOCTL"></a>

```c
GPIO_GET_CHIPINFO_IOCTL
```

`int ioctl(int chip_fd, GPIO_GET_CHIPINFO_IOCTL, struct gpiochip_info *info)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`info`**

  The `chip_info<gpiochip_info>` to be populated.

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

## Description

Gets the publicly available information for a particular GPIO chip.

<a id="rst-return-value"></a>

## Return Value

On success 0 and `info` is populated with the chip info.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_GET_LINEEVENT_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_get_lineevent_ioctl".

<a id="rst-gpio-get-lineevent-ioctl-1"></a>
<a id="rst-gpio-get-lineevent-ioctl"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md).

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

## Name

GPIO_GET_LINEEVENT_IOCTL - Request a line with edge detection from the kernel.

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

## Synopsis





<a id="c-GPIO_GET_LINEEVENT_IOCTL"></a>

```c
GPIO_GET_LINEEVENT_IOCTL
```

`int ioctl(int chip_fd, GPIO_GET_LINEEVENT_IOCTL, struct gpioevent_request *request)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`request`**

  The `event_request<gpioevent_request>` specifying the line to request and its configuration.

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

## Description

Request a line with edge detection from the kernel.

On success, the requesting process is granted exclusive access to the line value and may receive events when edges are detected on the line, as described in [gpio-lineevent-data-read.rst](/kernel/userspace/userspace-api/gpio/gpio-lineevent-data-read.md).

The state of a line is guaranteed to remain as requested until the returned file descriptor is closed. Once the file descriptor is closed, the state of the line becomes uncontrolled from the userspace perspective, and may revert to its default state.

Requesting a line already in use is an error (**EBUSY**).

Requesting edge detection on a line that does not support interrupts is an error (**ENXIO**).

As with the [line handle](</kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md#rst-gpio-get-linehandle-config-support>), the bias configuration is best effort.

Closing the `chip_fd` has no effect on existing line events.

<a id="rst-configuration-rules"></a>

### Configuration Rules

The following configuration rules apply:

The line event is requested as an input, so no flags specific to output lines, `GPIOHANDLE_REQUEST_OUTPUT`, `GPIOHANDLE_REQUEST_OPEN_DRAIN`, or `GPIOHANDLE_REQUEST_OPEN_SOURCE`, may be set.

Only one bias flag, `GPIOHANDLE_REQUEST_BIAS_xxx`, may be set. If no bias flags are set then the bias configuration is not changed.

The edge flags, `GPIOEVENT_REQUEST_RISING_EDGE` and `GPIOEVENT_REQUEST_FALLING_EDGE`, may be combined to detect both rising and falling edges.

Requesting an invalid configuration is an error (**EINVAL**).

<a id="rst-return-value"></a>

## Return Value

On success 0 and the `request.fd<gpioevent_request>` contains the file descriptor for the request.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_GET_LINEHANDLE_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_get_linehandle_ioctl".

<a id="rst-gpio-get-linehandle-ioctl-1"></a>
<a id="rst-gpio-get-linehandle-ioctl"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md).

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

## Name

GPIO_GET_LINEHANDLE_IOCTL - Request a line or lines from the kernel.

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

## Synopsis





<a id="c-GPIO_GET_LINEHANDLE_IOCTL"></a>

```c
GPIO_GET_LINEHANDLE_IOCTL
```

`int ioctl(int chip_fd, GPIO_GET_LINEHANDLE_IOCTL, struct gpiohandle_request *request)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`request`**

  The `handle_request<gpiohandle_request>` specifying the lines to request and their configuration.

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

## Description

Request a line or lines from the kernel.

While multiple lines may be requested, the same configuration applies to all lines in the request.

On success, the requesting process is granted exclusive access to the line value and write access to the line configuration.

The state of a line, including the value of output lines, is guaranteed to remain as requested until the returned file descriptor is closed. Once the file descriptor is closed, the state of the line becomes uncontrolled from the userspace perspective, and may revert to its default state.

Requesting a line already in use is an error (**EBUSY**).

Closing the `chip_fd` has no effect on existing line handles.

<a id="rst-configuration-rules"></a>
<a id="rst-gpio-get-linehandle-config-rules"></a>

### Configuration Rules

The following configuration rules apply:

The direction flags, `GPIOHANDLE_REQUEST_INPUT` and `GPIOHANDLE_REQUEST_OUTPUT`, cannot be combined. If neither are set then the only other flag that may be set is `GPIOHANDLE_REQUEST_ACTIVE_LOW` and the line is requested "as-is" to allow reading of the line value without altering the electrical configuration.

The drive flags, `GPIOHANDLE_REQUEST_OPEN_xxx`, require the `GPIOHANDLE_REQUEST_OUTPUT` to be set. Only one drive flag may be set. If none are set then the line is assumed push-pull.

Only one bias flag, `GPIOHANDLE_REQUEST_BIAS_xxx`, may be set, and it requires a direction flag to also be set. If no bias flags are set then the bias configuration is not changed.

Requesting an invalid configuration is an error (**EINVAL**).

<a id="rst-configuration-support"></a>
<a id="rst-gpio-get-linehandle-config-support"></a>

### Configuration Support

Where the requested configuration is not directly supported by the underlying hardware and driver, the kernel applies one of these approaches:

> - reject the request
>
> - emulate the feature in software
>
> - treat the feature as best effort

The approach applied depends on whether the feature can reasonably be emulated in software, and the impact on the hardware and userspace if the feature is not supported. The approach applied for each feature is as follows:


<table>
<thead>
<tr>
<th>


Feature

</th>
<th>


Approach

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


Bias

</td>
<td>


best effort

</td>
</tr>
<tr>
<td>


Direction

</td>
<td>


reject

</td>
</tr>
<tr>
<td>


Drive

</td>
<td>


emulate

</td>
</tr>
</tbody>
</table>

Bias is treated as best effort to allow userspace to apply the same configuration for platforms that support internal bias as those that require external bias. Worst case the line floats rather than being biased as expected.

Drive is emulated by switching the line to an input when the line should not be driven.

In all cases, the configuration reported by [gpio-get-lineinfo-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineinfo-ioctl.md) is the requested configuration, not the resulting hardware configuration. Userspace cannot determine if a feature is supported in hardware, is emulated, or is best effort.

<a id="rst-return-value"></a>

## Return Value

On success 0 and the `request.fd<gpiohandle_request>` contains the file descriptor for the request.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_GET_LINEINFO_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_get_lineinfo_ioctl".

<a id="rst-gpio-get-lineinfo-ioctl-1"></a>
<a id="rst-gpio-get-lineinfo-ioctl"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-get-lineinfo-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-lineinfo-ioctl.md).

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

## Name

GPIO_GET_LINEINFO_IOCTL - Get the publicly available information for a line.

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

## Synopsis





<a id="c-GPIO_GET_LINEINFO_IOCTL"></a>

```c
GPIO_GET_LINEINFO_IOCTL
```

`int ioctl(int chip_fd, GPIO_GET_LINEINFO_IOCTL, struct gpioline_info *info)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`info`**

  The `line_info<gpioline_info>` to be populated, with the `offset` field set to indicate the line to be collected.

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

## Description

Get the publicly available information for a line.

This information is available independent of whether the line is in use.

> [!NOTE]
>
> The line info does not include the line value.
>
> The line must be requested using [gpio-get-linehandle-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md) or [gpio-get-lineevent-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineevent-ioctl.md) to access its value.

<a id="rst-return-value"></a>

## Return Value

On success 0 and `info` is populated with the chip info.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_GET_LINEINFO_UNWATCH_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_get_lineinfo_unwatch_ioctl".

<a id="rst-gpio-get-lineinfo-unwatch-ioctl-1"></a>
<a id="rst-gpio-get-lineinfo-unwatch-ioctl"></a>

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

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

## Name

GPIO_GET_LINEINFO_UNWATCH_IOCTL - Disable watching a line for changes to its requested state and configuration information.

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

## Synopsis





<a id="c-GPIO_GET_LINEINFO_UNWATCH_IOCTL"></a>

```c
GPIO_GET_LINEINFO_UNWATCH_IOCTL
```

`int ioctl(int chip_fd, GPIO_GET_LINEINFO_UNWATCH_IOCTL, u32 *offset)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`offset`**

  The offset of the line to no longer watch.

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

## Description

Remove the line from the list of lines being watched on this `chip_fd`.

This is the reverse of [gpio-v2-get-lineinfo-watch-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-lineinfo-watch-ioctl.md) (v2) and [gpio-get-lineinfo-watch-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineinfo-watch-ioctl.md) (v1).

Unwatching a line that is not watched is an error (**EBUSY**).

First added in 5.7.

<a id="rst-return-value"></a>

## Return Value

On success 0.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_GET_LINEINFO_WATCH_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_get_lineinfo_watch_ioctl".

<a id="rst-gpio-get-lineinfo-watch-ioctl-1"></a>
<a id="rst-gpio-get-lineinfo-watch-ioctl"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-get-lineinfo-watch-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-lineinfo-watch-ioctl.md).

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

## Name

GPIO_GET_LINEINFO_WATCH_IOCTL - Enable watching a line for changes to its request state and configuration information.

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

## Synopsis





<a id="c-GPIO_GET_LINEINFO_WATCH_IOCTL"></a>

```c
GPIO_GET_LINEINFO_WATCH_IOCTL
```

`int ioctl(int chip_fd, GPIO_GET_LINEINFO_WATCH_IOCTL, struct gpioline_info *info)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`info`**

  The `line_info<gpioline_info>` struct to be populated, with the `offset` set to indicate the line to watch

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

## Description

Enable watching a line for changes to its request state and configuration information. Changes to line info include a line being requested, released or reconfigured.

> [!NOTE]
>
> Watching line info is not generally required, and would typically only be used by a system monitoring component.
>
> The line info does NOT include the line value.
>
> The line must be requested using [gpio-get-linehandle-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md) or [gpio-get-lineevent-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineevent-ioctl.md) to access its value, and the line event can monitor a line for events using [gpio-lineevent-data-read.rst](/kernel/userspace/userspace-api/gpio/gpio-lineevent-data-read.md).

By default all lines are unwatched when the GPIO chip is opened.

Multiple lines may be watched simultaneously by adding a watch for each.

Once a watch is set, any changes to line info will generate events which can be read from the `chip_fd` as described in [gpio-lineinfo-changed-read.rst](/kernel/userspace/userspace-api/gpio/gpio-lineinfo-changed-read.md).

Adding a watch to a line that is already watched is an error (**EBUSY**).

Watches are specific to the `chip_fd` and are independent of watches on the same GPIO chip opened with a separate call to `open()`.

First added in 5.7.

<a id="rst-return-value"></a>

## Return Value

On success 0 and `info` is populated with the current line info.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIOHANDLE_GET_LINE_VALUES_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpiohandle_get_line_values_ioctl".

<a id="rst-gpiohandle-get-line-values-ioctl-1"></a>
<a id="rst-gpiohandle-get-line-values-ioctl"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-line-get-values-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-get-values-ioctl.md).

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

## Name

GPIOHANDLE_GET_LINE_VALUES_IOCTL - Get the values of all requested lines.

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

## Synopsis





<a id="c-GPIOHANDLE_GET_LINE_VALUES_IOCTL"></a>

```c
GPIOHANDLE_GET_LINE_VALUES_IOCTL
```

`int ioctl(int handle_fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, struct gpiohandle_data *values)`

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

## Arguments

- **`handle_fd`**

  The file descriptor of the GPIO character device, as returned in the `request.fd<gpiohandle_request>` by [gpio-get-linehandle-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md).

- **`values`**

  The `line_values<gpiohandle_data>` to be populated.

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

## Description

Get the values of all requested lines.

The values returned are logical, indicating if the line is active or inactive. The `GPIOHANDLE_REQUEST_ACTIVE_LOW` flag controls the mapping between physical values (high/low) and logical values (active/inactive). If `GPIOHANDLE_REQUEST_ACTIVE_LOW` is not set then high is active and low is inactive. If `GPIOHANDLE_REQUEST_ACTIVE_LOW` is set then low is active and high is inactive.

The values of both input and output lines may be read.

For output lines, the value returned is driver and configuration dependent and may be either the output buffer (the last requested value set) or the input buffer (the actual level of the line), and depending on the hardware and configuration these may differ.

This ioctl can also be used to read the line value for line events, substituting the `event_fd` for the `handle_fd`.  As there is only one line requested in that case, only the one value is returned in `values`.

<a id="rst-return-value"></a>

## Return Value

On success 0 and `values` populated with the values read.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIOHANDLE_SET_CONFIG_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpiohandle_set_config_ioctl".

<a id="rst-gpiohandle-set-config-ioctl-1"></a>
<a id="rst-gpiohandle-set-config-ioctl"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-line-set-config-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-set-config-ioctl.md).

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

## Name

GPIOHANDLE_SET_CONFIG_IOCTL - Update the configuration of previously requested lines.

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

## Synopsis





<a id="c-GPIOHANDLE_SET_CONFIG_IOCTL"></a>

```c
GPIOHANDLE_SET_CONFIG_IOCTL
```

`int ioctl(int handle_fd, GPIOHANDLE_SET_CONFIG_IOCTL, struct gpiohandle_config *config)`

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

## Arguments

- **`handle_fd`**

  The file descriptor of the GPIO character device, as returned in the `request.fd<gpiohandle_request>` by [gpio-get-linehandle-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md).

- **`config`**

  The new `configuration<gpiohandle_config>` to apply to the requested lines.

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

## Description

Update the configuration of previously requested lines, without releasing the line or introducing potential glitches.

The configuration applies to all requested lines.

The same [Configuration Rules](</kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md#rst-gpio-get-linehandle-config-rules>) and [Configuration Support](</kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md#rst-gpio-get-linehandle-config-support>) that apply when requesting the lines also apply when updating the line configuration, with the additional restriction that a direction flag must be set. Requesting an invalid configuration, including without a direction flag set, is an error (**EINVAL**).

The motivating use case for this command is changing direction of bi-directional lines between input and output, but it may be used more generally to move lines seamlessly from one configuration state to another.

To only change the value of output lines, use [gpio-handle-set-line-values-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-handle-set-line-values-ioctl.md).

First added in 5.5.

<a id="rst-return-value"></a>

## Return Value

On success 0.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_HANDLE_SET_LINE_VALUES_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_handle_set_line_values_ioctl".

<a id="rst-gpio-handle-set-line-values-ioctl-1"></a>
<a id="rst-gpio-handle-set-line-values-ioctl"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-line-set-values-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-set-values-ioctl.md).

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

## Name

GPIO_HANDLE_SET_LINE_VALUES_IOCTL - Set the values of all requested output lines.

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

## Synopsis





<a id="c-GPIO_HANDLE_SET_LINE_VALUES_IOCTL"></a>

```c
GPIO_HANDLE_SET_LINE_VALUES_IOCTL
```

`int ioctl(int handle_fd, GPIO_HANDLE_SET_LINE_VALUES_IOCTL, struct gpiohandle_data *values)`

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

## Arguments

- **`handle_fd`**

  The file descriptor of the GPIO character device, as returned in the `request.fd<gpiohandle_request>` by [gpio-get-linehandle-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-linehandle-ioctl.md).

- **`values`**

  The `line_values<gpiohandle_data>` to set.

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

## Description

Set the values of all requested output lines.

The values set are logical, indicating if the line is to be active or inactive. The `GPIOHANDLE_REQUEST_ACTIVE_LOW` flag controls the mapping between logical values (active/inactive) and physical values (high/low). If  `GPIOHANDLE_REQUEST_ACTIVE_LOW` is not set then active is high and inactive is low. If `GPIOHANDLE_REQUEST_ACTIVE_LOW` is set then active is low and inactive is high.

Only the values of output lines may be set. Attempting to set the value of input lines is an error (**EPERM**).

<a id="rst-return-value"></a>

## Return Value

On success 0.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_LINEEVENT_DATA_READ

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_lineevent_data_read".

<a id="rst-gpio-lineevent-data-read-1"></a>
<a id="rst-gpio-lineevent-data-read"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-line-event-read.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-event-read.md).

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

## Name

GPIO_LINEEVENT_DATA_READ - Read edge detection events from a line event.

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

## Synopsis

`int read(int event_fd, void *buf, size_t count)`

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

## Arguments

- **`event_fd`**

  The file descriptor of the GPIO character device, as returned in the `request.fd<gpioevent_request>` by [gpio-get-lineevent-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineevent-ioctl.md).

- **`buf`**

  The buffer to contain the `events<gpioevent_data>`.

- **`count`**

  The number of bytes available in `buf`, which must be at least the size of a `gpioevent_data`.

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

## Description

Read edge detection events for a line from a line event.

Edge detection must be enabled for the input line using either `GPIOEVENT_REQUEST_RISING_EDGE` or `GPIOEVENT_REQUEST_FALLING_EDGE`, or both. Edge events are then generated whenever edge interrupts are detected on the input line.

Edges are defined in terms of changes to the logical line value, so an inactive to active transition is a rising edge.  If `GPIOHANDLE_REQUEST_ACTIVE_LOW` is set then logical polarity is the opposite of physical polarity, and `GPIOEVENT_REQUEST_RISING_EDGE` then corresponds to a falling physical edge.

The kernel captures and timestamps edge events as close as possible to their occurrence and stores them in a buffer from where they can be read by userspace at its convenience using `read()`.

The source of the clock for `event.timestamp<gpioevent_data>` is `CLOCK_MONOTONIC`, except for kernels earlier than Linux 5.7 when it was `CLOCK_REALTIME`.  There is no indication in the `gpioevent_data` as to which clock source is used, it must be determined from either the kernel version or sanity checks on the timestamp itself.

Events read from the buffer are always in the same order that they were detected by the kernel.

The size of the kernel event buffer is fixed at 16 events.

The buffer may overflow if bursts of events occur quicker than they are read by userspace. If an overflow occurs then the most recent event is discarded. Overflow cannot be detected from userspace.

To minimize the number of calls required to copy events from the kernel to userspace, `read()` supports copying multiple events. The number of events copied is the lower of the number available in the kernel buffer and the number that will fit in the userspace buffer (`buf`).

The `read()` will block if no event is available and the `event_fd` has not been set **O_NONBLOCK**.

The presence of an event can be tested for by checking that the `event_fd` is readable using `poll()` or an equivalent.

<a id="rst-return-value"></a>

## Return Value

On success the number of bytes read, which will be a multiple of the size of a `gpio_lineevent_data` event.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_LINEINFO_CHANGED_READ

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_lineinfo_changed_read".

<a id="rst-gpio-lineinfo-changed-read-1"></a>
<a id="rst-gpio-lineinfo-changed-read"></a>

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

> [!WARNING]
>
> This ioctl is part of [chardev_v1.rst](/kernel/userspace/userspace-api/gpio/chardev-v1.md) and is obsoleted by [gpio-v2-lineinfo-changed-read.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-lineinfo-changed-read.md).

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

## Name

GPIO_LINEINFO_CHANGED_READ - Read line info change events for watched lines from the chip.

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

## Synopsis

`int read(int chip_fd, void *buf, size_t count)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`buf`**

  The buffer to contain the `events<gpioline_info_changed>`.

- **`count`**

  The number of bytes available in `buf`, which must be at least the size of a `gpioline_info_changed` event.

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

## Description

Read line info change events for watched lines from the chip.

> [!NOTE]
>
> Monitoring line info changes is not generally required, and would typically only be performed by a system monitoring component.
>
> These events relate to changes in a line's request state or configuration, not its value. Use [gpio-lineevent-data-read.rst](/kernel/userspace/userspace-api/gpio/gpio-lineevent-data-read.md) to receive events when a line changes value.

A line must be watched using [gpio-get-lineinfo-watch-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-get-lineinfo-watch-ioctl.md) to generate info changed events.  Subsequently, a request, release, or reconfiguration of the line will generate an info changed event.

The kernel timestamps events when they occur and stores them in a buffer from where they can be read by userspace at its convenience using `read()`.

The size of the kernel event buffer is fixed at 32 events per `chip_fd`.

The buffer may overflow if bursts of events occur quicker than they are read by userspace. If an overflow occurs then the most recent event is discarded. Overflow cannot be detected from userspace.

Events read from the buffer are always in the same order that they were detected by the kernel, including when multiple lines are being monitored by the one `chip_fd`.

To minimize the number of calls required to copy events from the kernel to userspace, `read()` supports copying multiple events. The number of events copied is the lower of the number available in the kernel buffer and the number that will fit in the userspace buffer (`buf`).

A `read()` will block if no event is available and the `chip_fd` has not been set **O_NONBLOCK**.

The presence of an event can be tested for by checking that the `chip_fd` is readable using `poll()` or an equivalent.

First added in 5.7.

<a id="rst-return-value"></a>

## Return Value

On success the number of bytes read, which will be a multiple of the size of a `gpioline_info_changed` event.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_V2_GET_LINE_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_v2_get_line_ioctl".

<a id="rst-gpio-v2-get-line-ioctl-1"></a>
<a id="rst-gpio-v2-get-line-ioctl"></a>

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

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

## Name

GPIO_V2_GET_LINE_IOCTL - Request a line or lines from the kernel.

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

## Synopsis





<a id="c-GPIO_V2_GET_LINE_IOCTL"></a>

```c
GPIO_V2_GET_LINE_IOCTL
```

`int ioctl(int chip_fd, GPIO_V2_GET_LINE_IOCTL, struct gpio_v2_line_request *request)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`request`**

  The `line_request<gpio_v2_line_request>` specifying the lines to request and their configuration.

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

## Description

On success, the requesting process is granted exclusive access to the line value, write access to the line configuration, and may receive events when edges are detected on the line, all of which are described in more detail in [Line Request](</kernel/userspace/userspace-api/gpio/chardev.md#rst-gpio-v2-line-request>).

A number of lines may be requested in the one line request, and request operations are performed on the requested lines by the kernel as atomically as possible. e.g. [gpio-v2-line-get-values-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-get-values-ioctl.md) will read all the requested lines at once.

The state of a line, including the value of output lines, is guaranteed to remain as requested until the returned file descriptor is closed. Once the file descriptor is closed, the state of the line becomes uncontrolled from the userspace perspective, and may revert to its default state.

Requesting a line already in use is an error (**EBUSY**).

Closing the `chip_fd` has no effect on existing line requests.

<a id="rst-configuration-rules"></a>
<a id="rst-gpio-v2-get-line-config-rules"></a>

### Configuration Rules

For any given requested line, the following configuration rules apply:

The direction flags, `GPIO_V2_LINE_FLAG_INPUT` and `GPIO_V2_LINE_FLAG_OUTPUT`, cannot be combined. If neither are set then the only other flag that may be set is `GPIO_V2_LINE_FLAG_ACTIVE_LOW` and the line is requested "as-is" to allow reading of the line value without altering the electrical configuration.

The drive flags, `GPIO_V2_LINE_FLAG_OPEN_xxx`, require the `GPIO_V2_LINE_FLAG_OUTPUT` to be set. Only one drive flag may be set. If none are set then the line is assumed push-pull.

Only one bias flag, `GPIO_V2_LINE_FLAG_BIAS_xxx`, may be set, and it requires a direction flag to also be set. If no bias flags are set then the bias configuration is not changed.

The edge flags, `GPIO_V2_LINE_FLAG_EDGE_xxx`, require `GPIO_V2_LINE_FLAG_INPUT` to be set and may be combined to detect both rising and falling edges.  Requesting edge detection from a line that does not support it is an error (**ENXIO**).

Only one event clock flag, `GPIO_V2_LINE_FLAG_EVENT_CLOCK_xxx`, may be set. If none are set then the event clock defaults to `CLOCK_MONOTONIC`. The `GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE` flag requires supporting hardware and a kernel with `CONFIG_HTE` set.  Requesting HTE from a device that doesn't support it is an error (**EOPNOTSUPP**).

The `debounce_period_us<gpio_v2_line_attribute>` attribute may only be applied to lines with `GPIO_V2_LINE_FLAG_INPUT` set. When set, debounce applies to both the values returned by [gpio-v2-line-get-values-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-get-values-ioctl.md) and the edges returned by [gpio-v2-line-event-read.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-event-read.md).  If not supported directly by hardware, debouncing is emulated in software by the kernel.  Requesting debounce on a line that supports neither debounce in hardware nor interrupts, as required for software emulation, is an error (**ENXIO**).

Requesting an invalid configuration is an error (**EINVAL**).

<a id="rst-configuration-support"></a>
<a id="rst-gpio-v2-get-line-config-support"></a>

### Configuration Support

Where the requested configuration is not directly supported by the underlying hardware and driver, the kernel applies one of these approaches:

> - reject the request
>
> - emulate the feature in software
>
> - treat the feature as best effort

The approach applied depends on whether the feature can reasonably be emulated in software, and the impact on the hardware and userspace if the feature is not supported. The approach applied for each feature is as follows:


<table>
<thead>
<tr>
<th>


Feature

</th>
<th>


Approach

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


Bias

</td>
<td>


best effort

</td>
</tr>
<tr>
<td>


Debounce

</td>
<td>


emulate

</td>
</tr>
<tr>
<td>


Direction

</td>
<td>


reject

</td>
</tr>
<tr>
<td>


Drive

</td>
<td>


emulate

</td>
</tr>
<tr>
<td>


Edge Detection

</td>
<td>


reject

</td>
</tr>
</tbody>
</table>

Bias is treated as best effort to allow userspace to apply the same configuration for platforms that support internal bias as those that require external bias. Worst case the line floats rather than being biased as expected.

Debounce is emulated by applying a filter to hardware interrupts on the line. An edge event is generated after an edge is detected and the line remains stable for the debounce period. The event timestamp corresponds to the end of the debounce period.

Drive is emulated by switching the line to an input when the line should not be actively driven.

Edge detection requires interrupt support, and is rejected if that is not supported. Emulation by polling can still be performed from userspace.

In all cases, the configuration reported by [gpio-v2-get-lineinfo-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-lineinfo-ioctl.md) is the requested configuration, not the resulting hardware configuration. Userspace cannot determine if a feature is supported in hardware, is emulated, or is best effort.

<a id="rst-return-value"></a>

## Return Value

On success 0 and the `request.fd<gpio_v2_line_request>` contains the file descriptor for the request.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_V2_GET_LINEINFO_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_v2_get_lineinfo_ioctl".

<a id="rst-gpio-v2-get-lineinfo-ioctl-1"></a>
<a id="rst-gpio-v2-get-lineinfo-ioctl"></a>

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

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

## Name

GPIO_V2_GET_LINEINFO_IOCTL - Get the publicly available information for a line.

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

## Synopsis





<a id="c-GPIO_V2_GET_LINEINFO_IOCTL"></a>

```c
GPIO_V2_GET_LINEINFO_IOCTL
```

`int ioctl(int chip_fd, GPIO_V2_GET_LINEINFO_IOCTL, struct gpio_v2_line_info *info)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`info`**

  The `line_info<gpio_v2_line_info>` to be populated, with the `offset` field set to indicate the line to be collected.

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

## Description

Get the publicly available information for a line.

This information is available independent of whether the line is in use.

> [!NOTE]
>
> The line info does not include the line value.
>
> The line must be requested using [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md) to access its value.

<a id="rst-return-value"></a>

## Return Value

On success 0 and `info` is populated with the chip info.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_V2_GET_LINEINFO_WATCH_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_v2_get_lineinfo_watch_ioctl".

<a id="rst-gpio-v2-get-lineinfo-watch-ioctl-1"></a>
<a id="rst-gpio-v2-get-lineinfo-watch-ioctl"></a>

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

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

## Name

GPIO_V2_GET_LINEINFO_WATCH_IOCTL - Enable watching a line for changes to its request state and configuration information.

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

## Synopsis





<a id="c-GPIO_V2_GET_LINEINFO_WATCH_IOCTL"></a>

```c
GPIO_V2_GET_LINEINFO_WATCH_IOCTL
```

`int ioctl(int chip_fd, GPIO_V2_GET_LINEINFO_WATCH_IOCTL, struct gpio_v2_line_info *info)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`info`**

  The `line_info<gpio_v2_line_info>` struct to be populated, with the `offset` set to indicate the line to watch

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

## Description

Enable watching a line for changes to its request state and configuration information. Changes to line info include a line being requested, released or reconfigured.

> [!NOTE]
>
> Watching line info is not generally required, and would typically only be used by a system monitoring component.
>
> The line info does NOT include the line value. The line must be requested using [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md) to access its value, and the line request can monitor a line for events using [gpio-v2-line-event-read.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-event-read.md).

By default all lines are unwatched when the GPIO chip is opened.

Multiple lines may be watched simultaneously by adding a watch for each.

Once a watch is set, any changes to line info will generate events which can be read from the `chip_fd` as described in [gpio-v2-lineinfo-changed-read.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-lineinfo-changed-read.md).

Adding a watch to a line that is already watched is an error (**EBUSY**).

Watches are specific to the `chip_fd` and are independent of watches on the same GPIO chip opened with a separate call to `open()`.

<a id="rst-return-value"></a>

## Return Value

On success 0 and `info` is populated with the current line info.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_V2_LINE_EVENT_READ

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_v2_line_event_read".

<a id="rst-gpio-v2-line-event-read-1"></a>
<a id="rst-gpio-v2-line-event-read"></a>

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

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

## Name

GPIO_V2_LINE_EVENT_READ - Read edge detection events for lines from a request.

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

## Synopsis

`int read(int req_fd, void *buf, size_t count)`

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

## Arguments

- **`req_fd`**

  The file descriptor of the GPIO character device, as returned in the `request.fd<gpio_v2_line_request>` by [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md).

- **`buf`**

  The buffer to contain the `events<gpio_v2_line_event>`.

- **`count`**

  The number of bytes available in `buf`, which must be at least the size of a `gpio_v2_line_event`.

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

## Description

Read edge detection events for lines from a request.

Edge detection must be enabled for the input line using either `GPIO_V2_LINE_FLAG_EDGE_RISING` or `GPIO_V2_LINE_FLAG_EDGE_FALLING`, or both. Edge events are then generated whenever edge interrupts are detected on the input line.

Edges are defined in terms of changes to the logical line value, so an inactive to active transition is a rising edge.  If `GPIO_V2_LINE_FLAG_ACTIVE_LOW` is set then logical polarity is the opposite of physical polarity, and `GPIO_V2_LINE_FLAG_EDGE_RISING` then corresponds to a falling physical edge.

The kernel captures and timestamps edge events as close as possible to their occurrence and stores them in a buffer from where they can be read by userspace at its convenience using `read()`.

Events read from the buffer are always in the same order that they were detected by the kernel, including when multiple lines are being monitored by the one request.

The size of the kernel event buffer is fixed at the time of line request creation, and can be influenced by the `request.event_buffer_size<gpio_v2_line_request>`. The default size is 16 times the number of lines requested.

The buffer may overflow if bursts of events occur quicker than they are read by userspace. If an overflow occurs then the oldest buffered event is discarded. Overflow can be detected from userspace by monitoring the event sequence numbers.

To minimize the number of calls required to copy events from the kernel to userspace, `read()` supports copying multiple events. The number of events copied is the lower of the number available in the kernel buffer and the number that will fit in the userspace buffer (`buf`).

Changing the edge detection flags using [gpio-v2-line-set-config-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-set-config-ioctl.md) does not remove or modify the events already contained in the kernel event buffer.

The `read()` will block if no event is available and the `req_fd` has not been set **O_NONBLOCK**.

The presence of an event can be tested for by checking that the `req_fd` is readable using `poll()` or an equivalent.

<a id="rst-return-value"></a>

## Return Value

On success the number of bytes read, which will be a multiple of the size of a `gpio_v2_line_event` event.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_V2_LINE_GET_VALUES_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_v2_line_get_values_ioctl".

<a id="rst-gpio-v2-line-get-values-ioctl-1"></a>
<a id="rst-gpio-v2-line-get-values-ioctl"></a>

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

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

## Name

GPIO_V2_LINE_GET_VALUES_IOCTL - Get the values of requested lines.

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

## Synopsis





<a id="c-GPIO_V2_LINE_GET_VALUES_IOCTL"></a>

```c
GPIO_V2_LINE_GET_VALUES_IOCTL
```

`int ioctl(int req_fd, GPIO_V2_LINE_GET_VALUES_IOCTL, struct gpio_v2_line_values *values)`

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

## Arguments

- **`req_fd`**

  The file descriptor of the GPIO character device, as returned in the `request.fd<gpio_v2_line_request>` by [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md).

- **`values`**

  The `line_values<gpio_v2_line_values>` to get with the `mask` set to indicate the subset of requested lines to get.

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

## Description

Get the values of requested lines.

The values returned are logical, indicating if the line is active or inactive. The `GPIO_V2_LINE_FLAG_ACTIVE_LOW` flag controls the mapping between physical values (high/low) and logical values (active/inactive). If `GPIO_V2_LINE_FLAG_ACTIVE_LOW` is not set then high is active and low is inactive.  If `GPIO_V2_LINE_FLAG_ACTIVE_LOW` is set then low is active and high is inactive.

The values of both input and output lines may be read.

For output lines, the value returned is driver and configuration dependent and may be either the output buffer (the last requested value set) or the input buffer (the actual level of the line), and depending on the hardware and configuration these may differ.

<a id="rst-return-value"></a>

## Return Value

On success 0 and the corresponding `values.bits<gpio_v2_line_values>` contain the value read.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_V2_LINE_SET_CONFIG_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_v2_line_set_config_ioctl".

<a id="rst-gpio-v2-line-set-config-ioctl-1"></a>
<a id="rst-gpio-v2-line-set-config-ioctl"></a>

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

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

## Name

GPIO_V2_LINE_SET_CONFIG_IOCTL - Update the configuration of previously requested lines.

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

## Synopsis





<a id="c-GPIO_V2_LINE_SET_CONFIG_IOCTL"></a>

```c
GPIO_V2_LINE_SET_CONFIG_IOCTL
```

`int ioctl(int req_fd, GPIO_V2_LINE_SET_CONFIG_IOCTL, struct gpio_v2_line_config *config)`

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

## Arguments

- **`req_fd`**

  The file descriptor of the GPIO character device, as returned in the `request.fd<gpio_v2_line_request>` by [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md).

- **`config`**

  The new `configuration<gpio_v2_line_config>` to apply to the requested lines.

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

## Description

Update the configuration of previously requested lines, without releasing the line or introducing potential glitches.

The new configuration must specify a configuration for all requested lines.

The same [Configuration Rules](</kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md#rst-gpio-v2-get-line-config-rules>) and [Configuration Support](</kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md#rst-gpio-v2-get-line-config-support>) that apply when requesting the lines also apply when updating the line configuration, with the additional restriction that a direction flag must be set to enable reconfiguration. If no direction flag is set in the configuration for a given line then the configuration for that line is left unchanged.

The motivating use case for this command is changing direction of bi-directional lines between input and output, but it may also be used to dynamically control edge detection, or more generally move lines seamlessly from one configuration state to another.

To only change the value of output lines, use [gpio-v2-line-set-values-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-set-values-ioctl.md).

<a id="rst-return-value"></a>

## Return Value

On success 0.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_V2_LINE_SET_VALUES_IOCTL

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_v2_line_set_values_ioctl".

<a id="rst-gpio-v2-line-set-values-ioctl-1"></a>
<a id="rst-gpio-v2-line-set-values-ioctl"></a>

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

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

## Name

GPIO_V2_LINE_SET_VALUES_IOCTL - Set the values of requested output lines.

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

## Synopsis





<a id="c-GPIO_V2_LINE_SET_VALUES_IOCTL"></a>

```c
GPIO_V2_LINE_SET_VALUES_IOCTL
```

`int ioctl(int req_fd, GPIO_V2_LINE_SET_VALUES_IOCTL, struct gpio_v2_line_values *values)`

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

## Arguments

- **`req_fd`**

  The file descriptor of the GPIO character device, as returned in the `request.fd<gpio_v2_line_request>` by [gpio-v2-get-line-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-line-ioctl.md).

- **`values`**

  The `line_values<gpio_v2_line_values>` to set with the `mask` set to indicate the subset of requested lines to set and `bits` set to indicate the new value.

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

## Description

Set the values of requested output lines.

The values set are logical, indicating if the line is to be active or inactive. The `GPIO_V2_LINE_FLAG_ACTIVE_LOW` flag controls the mapping between logical values (active/inactive) and physical values (high/low). If `GPIO_V2_LINE_FLAG_ACTIVE_LOW` is not set then active is high and inactive is low.  If `GPIO_V2_LINE_FLAG_ACTIVE_LOW` is set then active is low and inactive is high.

Only the values of output lines may be set. Attempting to set the value of an input line is an error (**EPERM**).

<a id="rst-return-value"></a>

## Return Value

On success 0.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# GPIO_V2_LINEINFO_CHANGED_READ

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Duplicate implicit target name: "gpio_v2_lineinfo_changed_read".

<a id="rst-gpio-v2-lineinfo-changed-read-1"></a>
<a id="rst-gpio-v2-lineinfo-changed-read"></a>

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

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

## Name

GPIO_V2_LINEINFO_CHANGED_READ - Read line info changed events for watched lines from the chip.

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

## Synopsis

`int read(int chip_fd, void *buf, size_t count)`

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

## Arguments

- **`chip_fd`**

  The file descriptor of the GPIO character device returned by `open()`.

- **`buf`**

  The buffer to contain the `events<gpio_v2_line_info_changed>`.

- **`count`**

  The number of bytes available in `buf`, which must be at least the size of a `gpio_v2_line_info_changed` event.

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

## Description

Read line info changed events for watched lines from the chip.

> [!NOTE]
>
> Monitoring line info changes is not generally required, and would typically only be performed by a system monitoring component.
>
> These events relate to changes in a line's request state or configuration, not its value. Use [gpio-v2-line-event-read.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-line-event-read.md) to receive events when a line changes value.

A line must be watched using [gpio-v2-get-lineinfo-watch-ioctl.rst](/kernel/userspace/userspace-api/gpio/gpio-v2-get-lineinfo-watch-ioctl.md) to generate info changed events.  Subsequently, a request, release, or reconfiguration of the line will generate an info changed event.

The kernel timestamps events when they occur and stores them in a buffer from where they can be read by userspace at its convenience using `read()`.

The size of the kernel event buffer is fixed at 32 events per `chip_fd`.

The buffer may overflow if bursts of events occur quicker than they are read by userspace. If an overflow occurs then the most recent event is discarded. Overflow cannot be detected from userspace.

Events read from the buffer are always in the same order that they were detected by the kernel, including when multiple lines are being monitored by the one `chip_fd`.

To minimize the number of calls required to copy events from the kernel to userspace, `read()` supports copying multiple events. The number of events copied is the lower of the number available in the kernel buffer and the number that will fit in the userspace buffer (`buf`).

A `read()` will block if no event is available and the `chip_fd` has not been set **O_NONBLOCK**.

The presence of an event can be tested for by checking that the `chip_fd` is readable using `poll()` or an equivalent.

<a id="rst-return-value"></a>

## Return Value

On success the number of bytes read, which will be a multiple of the size of a `gpio_v2_line_info_changed` event.

On error -1 and the `errno` variable is set appropriately. Common error codes are described in [error-codes.rst](/kernel/userspace/userspace-api/gpio/error-codes.md).

---

# Obsolete GPIO Userspace APIs

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Reference for Obsolete GPIO Userspace APIs.

<a id="rst-obsolete-gpio-userspace-apis"></a>

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

- [Character Device Userspace API (v1)](</kernel/userspace/userspace-api/gpio/chardev-v1.md>)
- [Sysfs Interface](</kernel/userspace/userspace-api/gpio/sysfs.md>)

---

# GPIO Sysfs Interface for Userspace

_Peios Kernel / Userspace interfaces / System and device interfaces / GPIO_

> Platforms which use the "gpiolib" implementors framework may choose to configure a sysfs user interface to GPIOs. This is different from the debugfs interface, since it provides control over GPIO direction and value instead of just showing…

<a id="rst-gpio-sysfs-interface-for-userspace"></a>

> [!WARNING]
>
> This API is obsoleted by the [chardev.rst](/kernel/userspace/userspace-api/gpio/chardev.md) and the ABI documentation has been moved to Documentation/ABI/obsolete/sysfs-gpio.
>
> New developments should use the [chardev.rst](/kernel/userspace/userspace-api/gpio/chardev.md), and existing developments are encouraged to migrate as soon as possible, as this API will be removed in the future.
>
> This interface will continue to be maintained for the migration period, but new features will only be added to the new API.

<a id="rst-the-obsolete-sysfs-abi"></a>

## The obsolete sysfs ABI

Platforms which use the "gpiolib" implementors framework may choose to configure a sysfs user interface to GPIOs. This is different from the debugfs interface, since it provides control over GPIO direction and value instead of just showing a gpio state summary. Plus, it could be present on production systems without debugging support.

Given appropriate hardware documentation for the system, userspace could know for example that GPIO \#23 controls the write protect line used to protect boot loader segments in flash memory. System upgrade procedures may need to temporarily remove that protection, first importing a GPIO, then changing its output state, then updating the code before re-enabling the write protection. In normal use, GPIO \#23 would never be touched, and the kernel would have no need to know about it.

Again depending on appropriate hardware documentation, on some systems userspace GPIO can be used to determine system configuration data that standard kernels won't know about. And for some tasks, simple userspace GPIO drivers could be all that the system really needs.

> [!NOTE]
>
> Do NOT abuse sysfs to control hardware that has proper kernel drivers. Please read [Documentation/driver-api/gpio/drivers-on-gpio.rst](/kernel/hardware/driver-api/gpio/drivers-on-gpio.md) to avoid reinventing kernel wheels in userspace.
>
> I MEAN IT. REALLY.

<a id="rst-paths-in-sysfs"></a>

## Paths in Sysfs

There are three kinds of entries in /sys/class/gpio:

> - Control interfaces used to get userspace control over GPIOs;
>
> - GPIOs themselves; and
>
> - GPIO controllers ("gpio_chip" instances).

That's in addition to standard files including the "device" symlink.

The control interfaces are write-only:

> /sys/class/gpio/
>
> > - **"export" ...**
> >
> >   Userspace may ask the kernel to export control of a GPIO to userspace by writing its number to this file.
> >
> >   Example:  "echo 19 &gt; export" will create a "gpio19" node for GPIO \#19, if that's not requested by kernel code.
> >
> > - **"unexport" ...**
> >
> >   Reverses the effect of exporting to userspace.
> >
> >   Example:  "echo 19 &gt; unexport" will remove a "gpio19" node exported using the "export" file.

GPIO signals have paths like /sys/class/gpio/gpio42/ (for GPIO \#42) and have the following read/write attributes:

> /sys/class/gpio/gpioN/
>
> > - **"direction" ...**
> >
> >   reads as either "in" or "out". This value may normally be written. Writing as "out" defaults to initializing the value as low. To ensure glitch free operation, values "low" and "high" may be written to configure the GPIO as an output with that initial value.
> >
> >   Note that this attribute *will not exist* if the kernel doesn't support changing the direction of a GPIO, or it was exported by kernel code that didn't explicitly allow userspace to reconfigure this GPIO's direction.
> >
> > - **"value" ...**
> >
> >   reads as either 0 (inactive) or 1 (active). If the GPIO is configured as an output, this value may be written; any nonzero value is treated as active.
> >
> >   If the pin can be configured as interrupt-generating interrupt and if it has been configured to generate interrupts (see the description of "edge"), you can poll(2) on that file and poll(2) will return whenever the interrupt was triggered. If you use poll(2), set the events POLLPRI and POLLERR. If you use select(2), set the file descriptor in exceptfds. After poll(2) returns, use pread(2) to read the value at offset zero. Alternatively, either lseek(2) to the beginning of the sysfs file and read the new value or close the file and re-open it to read the value.
> >
> > - **"edge" ...**
> >
> >   reads as either "none", "rising", "falling", or "both". Write these strings to select the signal edge(s) that will make poll(2) on the "value" file return.
> >
> >   This file exists only if the pin can be configured as an interrupt generating input pin.
> >
> > - **"active_low" ...**
> >
> >   reads as either 0 (false) or 1 (true). Write any nonzero value to invert the value attribute both for reading and writing. Existing and subsequent poll(2) support configuration via the edge attribute for "rising" and "falling" edges will follow this setting.

GPIO controllers have paths like /sys/class/gpio/gpiochip42/ (for the controller implementing GPIOs starting at \#42) and have the following read-only attributes:

> /sys/class/gpio/gpiochipN/
>
> > - **"base" ...**
> >
> >   same as N, the first GPIO managed by this chip
> >
> > - **"label" ...**
> >
> >   provided for diagnostics (not always unique)
> >
> > - **"ngpio" ...**
> >
> >   how many GPIOs this manages (N to N + ngpio - 1)

Board documentation should in most cases cover what GPIOs are used for what purposes. However, those numbers are not always stable; GPIOs on a daughtercard might be different depending on the base board being used, or other cards in the stack. In such cases, you may need to use the gpiochip nodes (possibly in conjunction with schematics) to determine the correct GPIO number to use for a given signal.

<a id="rst-exporting-from-kernel-code"></a>

## Exporting from Kernel code

Kernel code can explicitly manage exports of GPIOs which have already been requested using gpio_request():



```text
/* export the GPIO to userspace */
int gpiod_export(struct gpio_desc *desc, bool direction_may_change);

/* reverse gpiod_export() */
void gpiod_unexport(struct gpio_desc *desc);

/* create a sysfs link to an exported GPIO node */
int gpiod_export_link(struct device *dev, const char *name,
              struct gpio_desc *desc);
```

After a kernel driver requests a GPIO, it may only be made available in the sysfs interface by gpiod_export(). The driver can control whether the signal direction may change. This helps drivers prevent userspace code from accidentally clobbering important system state.

This explicit exporting can help with debugging (by making some kinds of experiments easier), or can provide an always-there interface that's suitable for documenting as part of a board support package.

After the GPIO has been exported, gpiod_export_link() allows creating symlinks from elsewhere in sysfs to the GPIO sysfs node. Drivers can use this to provide the interface under their own device in sysfs with a descriptive name.

---

# IOCTLs

_Peios Kernel / Userspace interfaces / System and device interfaces / ioctl conventions_

> Reference for IOCTLs.

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

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

- [Ioctl Numbers](</kernel/userspace/userspace-api/ioctl/ioctl-number.md>)
- [Decoding an IOCTL Magic Number](</kernel/userspace/userspace-api/ioctl/ioctl-decoding.md>)
- [Summary of CDROM ioctl calls](</kernel/userspace/userspace-api/ioctl/cdrom.md>)
- [Summary of HDIO\_ ioctl calls](</kernel/userspace/userspace-api/ioctl/hdio.md>)

---

# Summary of CDROM ioctl calls

_Peios Kernel / Userspace interfaces / System and device interfaces / ioctl conventions_

> Edward A. Falk <efalk@google.com>

> **Peios:** Linux capability names in this interface retain their API meaning, but KACS evaluates them through native token privileges or compatibility rules. UID 0, `setcap` and Unix mode bits do not independently grant native authority. Object access and PIP checks remain additional constraints where applicable. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for the mapping and exceptions.


<a id="rst-summary-of-cdrom-ioctl-calls"></a>

- Edward A. Falk &lt;[efalk@google.com](<mailto:efalk@google.com>)&gt;

November, 2004

This document attempts to describe the ioctl(2) calls supported by the CDROM layer.  These are by-and-large implemented (as of Linux 2.6) in drivers/cdrom/cdrom.c and drivers/block/scsi_ioctl.c

ioctl values are listed in &lt;linux/cdrom.h&gt;.  As of this writing, they are as follows:

>
> <table>
> <tbody>
> <tr>
> <td>
>
>
> CDROMPAUSE
>
> </td>
> <td>
>
>
> Pause Audio Operation
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMRESUME
>
> </td>
> <td>
>
>
> Resume paused Audio Operation
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMPLAYMSF
>
> </td>
> <td>
>
>
> Play Audio MSF (struct cdrom_msf)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMPLAYTRKIND
>
> </td>
> <td>
>
>
> Play Audio Track/index (struct cdrom_ti)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMREADTOCHDR
>
> </td>
> <td>
>
>
> Read TOC header (struct cdrom_tochdr)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMREADTOCENTRY
>
> </td>
> <td>
>
>
> Read TOC entry (struct cdrom_tocentry)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMSTOP
>
> </td>
> <td>
>
>
> Stop the cdrom drive
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMSTART
>
> </td>
> <td>
>
>
> Start the cdrom drive
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMEJECT
>
> </td>
> <td>
>
>
> Ejects the cdrom media
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMVOLCTRL
>
> </td>
> <td>
>
>
> Control output volume (struct cdrom_volctrl)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMSUBCHNL
>
> </td>
> <td>
>
>
> Read subchannel data (struct cdrom_subchnl)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMREADMODE2
>
> </td>
> <td>
>
>
> Read CDROM mode 2 data (2336 Bytes) (struct cdrom_read)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMREADMODE1
>
> </td>
> <td>
>
>
> Read CDROM mode 1 data (2048 Bytes) (struct cdrom_read)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMREADAUDIO
>
> </td>
> <td>
>
>
> (struct cdrom_read_audio)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMEJECT_SW
>
> </td>
> <td>
>
>
> enable(1)/disable(0) auto-ejecting
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMMULTISESSION
>
> </td>
> <td>
>
>
> Obtain the start-of-last-session address of multi session disks (struct cdrom_multisession)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_GET_MCN
>
> </td>
> <td>
>
>
> Obtain the "Universal Product Code" if available (struct cdrom_mcn)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_GET_UPC
>
> </td>
> <td>
>
>
> Deprecated, use CDROM_GET_MCN instead.
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMRESET
>
> </td>
> <td>
>
>
> hard-reset the drive
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMVOLREAD
>
> </td>
> <td>
>
>
> Get the drive's volume setting (struct cdrom_volctrl)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMREADRAW
>
> </td>
> <td>
>
>
> read data in raw mode (2352 Bytes) (struct cdrom_read)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMREADCOOKED
>
> </td>
> <td>
>
>
> read data in cooked mode
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMSEEK
>
> </td>
> <td>
>
>
> seek msf address
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMPLAYBLK
>
> </td>
> <td>
>
>
> scsi-cd only, (struct cdrom_blk)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMREADALL
>
> </td>
> <td>
>
>
> read all 2646 bytes
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMGETSPINDOWN
>
> </td>
> <td>
>
>
> return 4-bit spindown value
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMSETSPINDOWN
>
> </td>
> <td>
>
>
> set 4-bit spindown value
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMCLOSETRAY
>
> </td>
> <td>
>
>
> pendant of CDROMEJECT
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_SET_OPTIONS
>
> </td>
> <td>
>
>
> Set behavior options
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_CLEAR_OPTIONS
>
> </td>
> <td>
>
>
> Clear behavior options
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_SELECT_SPEED
>
> </td>
> <td>
>
>
> Set the CD-ROM speed
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_SELECT_DISC
>
> </td>
> <td>
>
>
> Select disc (for juke-boxes)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_MEDIA_CHANGED
>
> </td>
> <td>
>
>
> Check is media changed
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_TIMED_MEDIA_CHANGE
>
> </td>
> <td>
>
>
> Check if media changed since given time (struct cdrom_timed_media_change_info)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_DRIVE_STATUS
>
> </td>
> <td>
>
>
> Get tray position, etc.
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_DISC_STATUS
>
> </td>
> <td>
>
>
> Get disc type, etc.
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_CHANGER_NSLOTS
>
> </td>
> <td>
>
>
> Get number of slots
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_LOCKDOOR
>
> </td>
> <td>
>
>
> lock or unlock door
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_DEBUG
>
> </td>
> <td>
>
>
> Turn debug messages on/off
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_GET_CAPABILITY
>
> </td>
> <td>
>
>
> get capabilities
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROMAUDIOBUFSIZ
>
> </td>
> <td>
>
>
> set the audio buffer size
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> DVD_READ_STRUCT
>
> </td>
> <td>
>
>
> Read structure
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> DVD_WRITE_STRUCT
>
> </td>
> <td>
>
>
> Write structure
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> DVD_AUTH
>
> </td>
> <td>
>
>
> Authentication
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_SEND_PACKET
>
> </td>
> <td>
>
>
> send a packet to the drive
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_NEXT_WRITABLE
>
> </td>
> <td>
>
>
> get next writable block
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> CDROM_LAST_WRITTEN
>
> </td>
> <td>
>
>
> get last block written on disc
>
> </td>
> </tr>
> </tbody>
> </table>

The information that follows was determined from reading kernel source code.  It is likely that some corrections will be made over time.

---

General:

> Unless otherwise specified, all ioctl calls return 0 on success and -1 with errno set to an appropriate value on error.  (Some ioctls return non-negative data values.)
>
> Unless otherwise specified, all ioctl calls return -1 and set errno to EFAULT on a failed attempt to copy data to or from user address space.
>
> Individual drivers may return error codes not listed here.
>
> Unless otherwise specified, all data structures and constants are defined in &lt;linux/cdrom.h&gt;

---

- **CDROMPAUSE**

  Pause Audio Operation

  usage:



  ```text
  ioctl(fd, CDROMPAUSE, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

- **CDROMRESUME**

  Resume paused Audio Operation

  usage:



  ```text
  ioctl(fd, CDROMRESUME, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

- **CDROMPLAYMSF**

  Play Audio MSF

  (struct cdrom_msf)

  usage:



  ```text
  struct cdrom_msf msf;

  ioctl(fd, CDROMPLAYMSF, &msf);
  ```

  - **inputs:**

    cdrom_msf structure, describing a segment of music to play

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

  - **notes:**

    - MSF stands for minutes-seconds-frames

    - LBA stands for logical block address

    - Segment is described as start and end times, where each time is described as minutes:seconds:frames. A frame is 1/75 of a second.

- **CDROMPLAYTRKIND**

  Play Audio Track/index

  (struct cdrom_ti)

  usage:



  ```text
  struct cdrom_ti ti;

  ioctl(fd, CDROMPLAYTRKIND, &ti);
  ```

  - **inputs:**

    cdrom_ti structure, describing a segment of music to play

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

  - **notes:**

    - Segment is described as start and end times, where each time is described as a track and an index.

- **CDROMREADTOCHDR**

  Read TOC header

  (struct cdrom_tochdr)

  usage:



  ```text
  cdrom_tochdr header;

  ioctl(fd, CDROMREADTOCHDR, &header);
  ```

  - **inputs:**

    cdrom_tochdr structure

  - **outputs:**

    cdrom_tochdr structure

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

- **CDROMREADTOCENTRY**

  Read TOC entry

  (struct cdrom_tocentry)

  usage:



  ```text
  struct cdrom_tocentry entry;

  ioctl(fd, CDROMREADTOCENTRY, &entry);
  ```

  - **inputs:**

    cdrom_tocentry structure

  - **outputs:**

    cdrom_tocentry structure

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

    - EINVAL      entry.cdte_format not CDROM_MSF or CDROM_LBA

    - EINVAL      requested track out of bounds

    - EIO         I/O error reading TOC

  - **notes:**

    - TOC stands for Table Of Contents

    - MSF stands for minutes-seconds-frames

    - LBA stands for logical block address

- **CDROMSTOP**

  Stop the cdrom drive

  usage:



  ```text
  ioctl(fd, CDROMSTOP, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

  - **notes:**

    - Exact interpretation of this ioctl depends on the device, but most seem to spin the drive down.

- **CDROMSTART**

  Start the cdrom drive

  usage:



  ```text
  ioctl(fd, CDROMSTART, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

  - **notes:**

    - Exact interpretation of this ioctl depends on the device, but most seem to spin the drive up and/or close the tray. Other devices ignore the ioctl completely.

- **CDROMEJECT**

  - Ejects the cdrom media

  usage:



  ```text
  ioctl(fd, CDROMEJECT, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    none

  - **error returns:**

    - ENOSYS      cd drive not capable of ejecting

    - EBUSY       other processes are accessing drive, or door is locked

  - **notes:**

    - See CDROM_LOCKDOOR, below.

- **CDROMCLOSETRAY**

  pendant of CDROMEJECT

  usage:



  ```text
  ioctl(fd, CDROMCLOSETRAY, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    none

  - **error returns:**

    - ENOSYS      cd drive not capable of closing the tray

    - EBUSY       other processes are accessing drive, or door is locked

  - **notes:**

    - See CDROM_LOCKDOOR, below.

- **CDROMVOLCTRL**

  Control output volume (struct cdrom_volctrl)

  usage:



  ```text
  struct cdrom_volctrl volume;

  ioctl(fd, CDROMVOLCTRL, &volume);
  ```

  - **inputs:**

    cdrom_volctrl structure containing volumes for up to 4 channels.

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

- **CDROMVOLREAD**

  Get the drive's volume setting

  (struct cdrom_volctrl)

  usage:



  ```text
  struct cdrom_volctrl volume;

  ioctl(fd, CDROMVOLREAD, &volume);
  ```

  - **inputs:**

    none

  - **outputs:**

    The current volume settings.

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

- **CDROMSUBCHNL**

  Read subchannel data

  (struct cdrom_subchnl)

  usage:



  ```text
  struct cdrom_subchnl q;

  ioctl(fd, CDROMSUBCHNL, &q);
  ```

  - **inputs:**

    cdrom_subchnl structure

  - **outputs:**

    cdrom_subchnl structure

  - **error return:**

    - ENOSYS      cd drive not audio-capable.

    - EINVAL      format not CDROM_MSF or CDROM_LBA

  - **notes:**

    - Format is converted to CDROM_MSF or CDROM_LBA as per user request on return

- **CDROMREADRAW**

  read data in raw mode (2352 Bytes)

  (struct cdrom_read)

  usage:



  ```text
  union {

    struct cdrom_msf msf;               /* input */
    char buffer[CD_FRAMESIZE_RAW];      /* return */
  } arg;
  ioctl(fd, CDROMREADRAW, &arg);
  ```

  - **inputs:**

    cdrom_msf structure indicating an address to read.

    Only the start values are significant.

  - **outputs:**

    Data written to address provided by user.

  - **error return:**

    - EINVAL      address less than 0, or msf less than 0:2:0

    - ENOMEM      out of memory

  - **notes:**

    - As of 2.6.8.1, comments in &lt;linux/cdrom.h&gt; indicate that this ioctl accepts a cdrom_read structure, but actual source code reads a cdrom_msf structure and writes a buffer of data to the same address.

    - MSF values are converted to LBA values via this formula:



      ```text
      lba = (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
      ```

- **CDROMREADMODE1**

  Read CDROM mode 1 data (2048 Bytes)

  (struct cdrom_read)

  - **notes:**

    Identical to CDROMREADRAW except that block size is CD_FRAMESIZE (2048) bytes

- **CDROMREADMODE2**

  Read CDROM mode 2 data (2336 Bytes)

  (struct cdrom_read)

  - **notes:**

    Identical to CDROMREADRAW except that block size is CD_FRAMESIZE_RAW0 (2336) bytes

- **CDROMREADAUDIO**

  (struct cdrom_read_audio)

  usage:



  ```text
  struct cdrom_read_audio ra;

  ioctl(fd, CDROMREADAUDIO, &ra);
  ```

  - **inputs:**

    cdrom_read_audio structure containing read start point and length

  - **outputs:**

    audio data, returned to buffer indicated by ra

  - **error return:**

    - EINVAL      format not CDROM_MSF or CDROM_LBA

    - EINVAL      nframes not in range \[1 75\]

    - ENXIO       drive has no queue (probably means invalid fd)

    - ENOMEM      out of memory

- **CDROMEJECT_SW**

  enable(1)/disable(0) auto-ejecting

  usage:



  ```text
  int val;

  ioctl(fd, CDROMEJECT_SW, val);
  ```

  - **inputs:**

    Flag specifying auto-eject flag.

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      Drive is not capable of ejecting.

    - EBUSY       Door is locked

- **CDROMMULTISESSION**

  Obtain the start-of-last-session address of multi session disks

  (struct cdrom_multisession)

  usage:



  ```text
  struct cdrom_multisession ms_info;

  ioctl(fd, CDROMMULTISESSION, &ms_info);
  ```

  - **inputs:**

    > cdrom_multisession structure containing desired

    format.

  - **outputs:**

    cdrom_multisession structure is filled with last_session information.

  - **error return:**

    - EINVAL      format not CDROM_MSF or CDROM_LBA

- **CDROM_GET_MCN**

  Obtain the "Universal Product Code" if available

  (struct cdrom_mcn)

  usage:



  ```text
  struct cdrom_mcn mcn;

  ioctl(fd, CDROM_GET_MCN, &mcn);
  ```

  - **inputs:**

    none

  - **outputs:**

    Universal Product Code

  - **error return:**

    - ENOSYS      Drive is not capable of reading MCN data.

  - **notes:**

    - Source code comments state:



      ```text
      The following function is implemented, although very few
      audio discs give Universal Product Code information, which
      should just be the Medium Catalog Number on the box.  Note,
      that the way the code is written on the CD is /not/ uniform
      across all discs!
      ```

- **CDROM_GET_UPC**

  CDROM_GET_MCN  (deprecated)

  Not implemented, as of 2.6.8.1

- **CDROMRESET**

  hard-reset the drive

  usage:



  ```text
  ioctl(fd, CDROMRESET, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    none

  - **error return:**

    - EACCES      Access denied:  requires CAP_SYS_ADMIN

    - ENOSYS      Drive is not capable of resetting.

- **CDROMREADCOOKED**

  read data in cooked mode

  usage:



  ```text
  u8 buffer[CD_FRAMESIZE]

  ioctl(fd, CDROMREADCOOKED, buffer);
  ```

  - **inputs:**

    none

  - **outputs:**

    2048 bytes of data, "cooked" mode.

  - **notes:**

    Not implemented on all drives.

- **CDROMREADALL**

  read all 2646 bytes

  Same as CDROMREADCOOKED, but reads 2646 bytes.

- **CDROMSEEK**

  seek msf address

  usage:



  ```text
  struct cdrom_msf msf;

  ioctl(fd, CDROMSEEK, &msf);
  ```

  - **inputs:**

    MSF address to seek to.

  - **outputs:**

    none

- **CDROMPLAYBLK**

  scsi-cd only

  (struct cdrom_blk)

  usage:



  ```text
  struct cdrom_blk blk;

  ioctl(fd, CDROMPLAYBLK, &blk);
  ```

  - **inputs:**

    Region to play

  - **outputs:**

    none

- **CDROMGETSPINDOWN**

  Obsolete, was ide-cd only

  usage:



  ```text
  char spindown;

  ioctl(fd, CDROMGETSPINDOWN, &spindown);
  ```

  - **inputs:**

    none

  - **outputs:**

    The value of the current 4-bit spindown value.

- **CDROMSETSPINDOWN**

  Obsolete, was ide-cd only

  usage:



  ```text
  char spindown

  ioctl(fd, CDROMSETSPINDOWN, &spindown);
  ```

  - **inputs:**

    4-bit value used to control spindown (TODO: more detail here)

  - **outputs:**

    none

- **CDROM_SET_OPTIONS**

  Set behavior options

  usage:



  ```text
  int options;

  ioctl(fd, CDROM_SET_OPTIONS, options);
  ```

  - **inputs:**

    > New values for drive options.  The logical 'or' of:


    <table>
    <tbody>
    <tr>
    <td>


    CDO_AUTO_CLOSE

    </td>
    <td>


    close tray on first open(2)

    </td>
    </tr>
    <tr>
    <td>


    CDO_AUTO_EJECT

    </td>
    <td>


    open tray on last release

    </td>
    </tr>
    <tr>
    <td>


    CDO_USE_FFLAGS

    </td>
    <td>


    use O_NONBLOCK information on open

    </td>
    </tr>
    <tr>
    <td>


    CDO_LOCK

    </td>
    <td>


    lock tray on open files

    </td>
    </tr>
    <tr>
    <td>


    CDO_CHECK_TYPE

    </td>
    <td>


    check type on open for data

    </td>
    </tr>
    </tbody>
    </table>

  - **outputs:**

    Returns the resulting options settings in the ioctl return value.  Returns -1 on error.

  - **error return:**

    - ENOSYS      selected option(s) not supported by drive.

- **CDROM_CLEAR_OPTIONS**

  Clear behavior options

  Same as CDROM_SET_OPTIONS, except that selected options are turned off.

- **CDROM_SELECT_SPEED**

  Set the CD-ROM speed

  usage:



  ```text
  int speed;

  ioctl(fd, CDROM_SELECT_SPEED, speed);
  ```

  - **inputs:**

    New drive speed.

  - **outputs:**

    none

  - **error return:**

    - ENOSYS      speed selection not supported by drive.

- **CDROM_SELECT_DISC**

  Select disc (for juke-boxes)

  usage:



  ```text
  int disk;

  ioctl(fd, CDROM_SELECT_DISC, disk);
  ```

  - **inputs:**

    Disk to load into drive.

  - **outputs:**

    none

  - **error return:**

    - EINVAL      Disk number beyond capacity of drive

- **CDROM_MEDIA_CHANGED**

  Check is media changed

  usage:



  ```text
  int slot;

  ioctl(fd, CDROM_MEDIA_CHANGED, slot);
  ```

  - **inputs:**

    Slot number to be tested, always zero except for jukeboxes.

    May also be special values CDSL_NONE or CDSL_CURRENT

  - **outputs:**

    > Ioctl return value is 0 or 1 depending on whether the media

    has been changed, or -1 on error.

  - **error returns:**

    - ENOSYS      Drive can't detect media change

    - EINVAL      Slot number beyond capacity of drive

    - ENOMEM      Out of memory

- **CDROM_DRIVE_STATUS**

  Get tray position, etc.

  usage:



  ```text
  int slot;

  ioctl(fd, CDROM_DRIVE_STATUS, slot);
  ```

  - **inputs:**

    Slot number to be tested, always zero except for jukeboxes.

    May also be special values CDSL_NONE or CDSL_CURRENT

  - **outputs:**

    > Ioctl return value will be one of the following values

    from &lt;linux/cdrom.h&gt;:

    >
    > <table>
    > <tbody>
    > <tr>
    > <td>
    >
    >
    > CDS_NO_INFO
    >
    > </td>
    > <td>
    >
    >
    > Information not available.
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > CDS_NO_DISC
    >
    > </td>
    > <td>
    >
    >
    >
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > CDS_TRAY_OPEN
    >
    > </td>
    > <td>
    >
    >
    >
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > CDS_DRIVE_NOT_READY
    >
    > </td>
    > <td>
    >
    >
    >
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > CDS_DISC_OK
    >
    > </td>
    > <td>
    >
    >
    >
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > -1
    >
    > </td>
    > <td>
    >
    >
    > error
    >
    > </td>
    > </tr>
    > </tbody>
    > </table>

  - **error returns:**

    - ENOSYS      Drive can't detect drive status

    - EINVAL      Slot number beyond capacity of drive

    - ENOMEM      Out of memory

- **CDROM_DISC_STATUS**

  Get disc type, etc.

  usage:



  ```text
  ioctl(fd, CDROM_DISC_STATUS, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    > Ioctl return value will be one of the following values

    from &lt;linux/cdrom.h&gt;:

    > - CDS_NO_INFO
    >
    > - CDS_AUDIO
    >
    > - CDS_MIXED
    >
    > - CDS_XA_2_2
    >
    > - CDS_XA_2_1
    >
    > - CDS_DATA_1

  - **error returns:**

    none at present

  - **notes:**

    - Source code comments state:



      ```text
      Ok, this is where problems start.  The current interface for
      the CDROM_DISC_STATUS ioctl is flawed.  It makes the false
      assumption that CDs are all CDS_DATA_1 or all CDS_AUDIO, etc.
      Unfortunately, while this is often the case, it is also
      very common for CDs to have some tracks with data, and some
      tracks with audio.      Just because I feel like it, I declare
      the following to be the best way to cope.  If the CD has
      ANY data tracks on it, it will be returned as a data CD.
      If it has any XA tracks, I will return it as that.      Now I
      could simplify this interface by combining these returns with
      the above, but this more clearly demonstrates the problem
      with the current interface.  Too bad this wasn't designed
      to use bitmasks...             -Erik

      Well, now we have the option CDS_MIXED: a mixed-type CD.
      User level programmers might feel the ioctl is not very
      useful.
                      ---david
      ```

- **CDROM_CHANGER_NSLOTS**

  Get number of slots

  usage:



  ```text
  ioctl(fd, CDROM_CHANGER_NSLOTS, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    The ioctl return value will be the number of slots in a CD changer.  Typically 1 for non-multi-disk devices.

  - **error returns:**

    none

- **CDROM_LOCKDOOR**

  lock or unlock door

  usage:



  ```text
  int lock;

  ioctl(fd, CDROM_LOCKDOOR, lock);
  ```

  - **inputs:**

    Door lock flag, 1=lock, 0=unlock

  - **outputs:**

    none

  - **error returns:**

    - EDRIVE_CANT_DO_THIS

      > Door lock function not supported.

    - EBUSY

      > Attempt to unlock when multiple users have the drive open and not CAP_SYS_ADMIN

  - **notes:**

    As of 2.6.8.1, the lock flag is a global lock, meaning that all CD drives will be locked or unlocked together.  This is probably a bug.

    The EDRIVE_CANT_DO_THIS value is defined in &lt;linux/cdrom.h&gt; and is currently (2.6.8.1) the same as EOPNOTSUPP

- **CDROM_DEBUG**

  Turn debug messages on/off

  usage:



  ```text
  int debug;

  ioctl(fd, CDROM_DEBUG, debug);
  ```

  - **inputs:**

    Cdrom debug flag, 0=disable, 1=enable

  - **outputs:**

    The ioctl return value will be the new debug flag.

  - **error return:**

    - EACCES      Access denied:  requires CAP_SYS_ADMIN

- **CDROM_GET_CAPABILITY**

  get capabilities

  usage:



  ```text
  ioctl(fd, CDROM_GET_CAPABILITY, 0);
  ```

  - **inputs:**

    none

  - **outputs:**

    The ioctl return value is the current device capability flags.  See CDC_CLOSE_TRAY, CDC_OPEN_TRAY, etc.

- **CDROMAUDIOBUFSIZ**

  set the audio buffer size

  usage:



  ```text
  int arg;

  ioctl(fd, CDROMAUDIOBUFSIZ, val);
  ```

  - **inputs:**

    New audio buffer size

  - **outputs:**

    The ioctl return value is the new audio buffer size, or -1 on error.

  - **error return:**

    - ENOSYS      Not supported by this driver.

  - **notes:**

    Not supported by all drivers.

DVD_READ_STRUCT                 Read structure

> usage:
>
>
>
> ```text
> dvd_struct s;
>
> ioctl(fd, DVD_READ_STRUCT, &s);
> ```
>
> - **inputs:**
>
>   > dvd_struct structure, containing:
>
>
>   <table>
>   <tbody>
>   <tr>
>   <td>
>
>
>   type
>
>   </td>
>   <td>
>
>
>   specifies the information desired, one of DVD_STRUCT_PHYSICAL, DVD_STRUCT_COPYRIGHT, DVD_STRUCT_DISCKEY, DVD_STRUCT_BCA, DVD_STRUCT_MANUFACT
>
>   </td>
>   </tr>
>   <tr>
>   <td>
>
>
>   physical.layer_num
>
>   </td>
>   <td>
>
>
>   desired layer, indexed from 0
>
>   </td>
>   </tr>
>   <tr>
>   <td>
>
>
>   copyright.layer_num
>
>   </td>
>   <td>
>
>
>   desired layer, indexed from 0
>
>   </td>
>   </tr>
>   <tr>
>   <td>
>
>
>   disckey.agid
>
>   </td>
>   <td>
>
>
>
>
>   </td>
>   </tr>
>   </tbody>
>   </table>
>
> - **outputs:**
>
>   > dvd_struct structure, containing:
>
>
>   <table>
>   <tbody>
>   <tr>
>   <td>
>
>
>   physical
>
>   </td>
>   <td>
>
>
>   for type == DVD_STRUCT_PHYSICAL
>
>   </td>
>   </tr>
>   <tr>
>   <td>
>
>
>   copyright
>
>   </td>
>   <td>
>
>
>   for type == DVD_STRUCT_COPYRIGHT
>
>   </td>
>   </tr>
>   <tr>
>   <td>
>
>
>   disckey.value
>
>   </td>
>   <td>
>
>
>   for type == DVD_STRUCT_DISCKEY
>
>   </td>
>   </tr>
>   <tr>
>   <td>
>
>
>   bca.\{len,value\}
>
>   </td>
>   <td>
>
>
>   for type == DVD_STRUCT_BCA
>
>   </td>
>   </tr>
>   <tr>
>   <td>
>
>
>   manufact.\{len,valu\}
>
>   </td>
>   <td>
>
>
>   for type == DVD_STRUCT_MANUFACT
>
>   </td>
>   </tr>
>   </tbody>
>   </table>
>
> - **error returns:**
>
>   - EINVAL      physical.layer_num exceeds number of layers
>
>   - EIO         Received invalid response from drive

DVD_WRITE_STRUCT                Write structure

> Not implemented, as of 2.6.8.1

DVD_AUTH                        Authentication

> usage:
>
>
>
> ```text
> dvd_authinfo ai;
>
> ioctl(fd, DVD_AUTH, &ai);
> ```
>
> - **inputs:**
>
>   dvd_authinfo structure.  See &lt;linux/cdrom.h&gt;
>
> - **outputs:**
>
>   dvd_authinfo structure.
>
> - **error return:**
>
>   - ENOTTY      ai.type not recognized.

- **CDROM_SEND_PACKET**

  send a packet to the drive

  usage:



  ```text
  struct cdrom_generic_command cgc;

  ioctl(fd, CDROM_SEND_PACKET, &cgc);
  ```

  - **inputs:**

    cdrom_generic_command structure containing the packet to send.

  - **outputs:**

    > none

    cdrom_generic_command structure containing results.

  - **error return:**

    - EIO

      > command failed.

    - EPERM

      > Operation not permitted, either because a write command was attempted on a drive which is opened read-only, or because the command requires CAP_SYS_RAWIO

    - EINVAL

      > cgc.data_direction not set

- **CDROM_NEXT_WRITABLE**

  get next writable block

  usage:



  ```text
  long next;

  ioctl(fd, CDROM_NEXT_WRITABLE, &next);
  ```

  - **inputs:**

    none

  - **outputs:**

    The next writable block.

  - **notes:**

    > If the device does not support this ioctl directly, the

    ioctl will return CDROM_LAST_WRITTEN + 7.

- **CDROM_LAST_WRITTEN**

  get last block written on disc

  usage:



  ```text
  long last;

  ioctl(fd, CDROM_LAST_WRITTEN, &last);
  ```

  - **inputs:**

    none

  - **outputs:**

    The last block written on disc

  - **notes:**

    If the device does not support this ioctl directly, the result is derived from the disc's table of contents.  If the table of contents can't be read, this ioctl returns an error.

---

# Summary of HDIO_ ioctl calls

_Peios Kernel / Userspace interfaces / System and device interfaces / ioctl conventions_

> Edward A. Falk <efalk@google.com>

> **Peios:** Linux capability names in this interface retain their API meaning, but KACS evaluates them through native token privileges or compatibility rules. UID 0, `setcap` and Unix mode bits do not independently grant native authority. Object access and PIP checks remain additional constraints where applicable. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for the mapping and exceptions.


<a id="rst-summary-of-hdio-ioctl-calls"></a>

- Edward A. Falk &lt;[efalk@google.com](<mailto:efalk@google.com>)&gt;

November, 2004

This document attempts to describe the ioctl(2) calls supported by the HD/IDE layer.  These are by-and-large implemented (as of Linux 5.11) drivers/ata/libata-scsi.c.

ioctl values are listed in &lt;linux/hdreg.h&gt;.  As of this writing, they are as follows:

> ioctls that pass argument pointers to user space:
>
> >
> > <table>
> > <tbody>
> > <tr>
> > <td>
> >
> >
> > HDIO_GETGEO
> >
> > </td>
> > <td>
> >
> >
> > get device geometry
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > HDIO_GET_32BIT
> >
> > </td>
> > <td>
> >
> >
> > get current io_32bit setting
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > HDIO_GET_IDENTITY
> >
> > </td>
> > <td>
> >
> >
> > get IDE identification info
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > HDIO_DRIVE_TASKFILE
> >
> > </td>
> > <td>
> >
> >
> > execute raw taskfile
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > HDIO_DRIVE_TASK
> >
> > </td>
> > <td>
> >
> >
> > execute task and special drive command
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > HDIO_DRIVE_CMD
> >
> > </td>
> > <td>
> >
> >
> > execute a special drive command
> >
> > </td>
> > </tr>
> > </tbody>
> > </table>
>
> ioctls that pass non-pointer values:
>
> >
> > <table>
> > <tbody>
> > <tr>
> > <td>
> >
> >
> > HDIO_SET_32BIT
> >
> > </td>
> > <td>
> >
> >
> > change io_32bit flags
> >
> > </td>
> > </tr>
> > </tbody>
> > </table>

The information that follows was determined from reading kernel source code.  It is likely that some corrections will be made over time.

---

General:

> Unless otherwise specified, all ioctl calls return 0 on success and -1 with errno set to an appropriate value on error.
>
> Unless otherwise specified, all ioctl calls return -1 and set errno to EFAULT on a failed attempt to copy data to or from user address space.
>
> Unless otherwise specified, all data structures and constants are defined in &lt;linux/hdreg.h&gt;

---

- **HDIO_GETGEO**

  get device geometry

  usage:



  ```text
  struct hd_geometry geom;

  ioctl(fd, HDIO_GETGEO, &geom);
  ```

  - **inputs:**

    none

  - **outputs:**

    > hd_geometry structure containing:


    <table>
    <tbody>
    <tr>
    <td>


    heads

    </td>
    <td>


    number of heads

    </td>
    </tr>
    <tr>
    <td>


    sectors

    </td>
    <td>


    number of sectors/track

    </td>
    </tr>
    <tr>
    <td>


    cylinders

    </td>
    <td>


    number of cylinders, mod 65536

    </td>
    </tr>
    <tr>
    <td>


    start

    </td>
    <td>


    starting sector of this partition.

    </td>
    </tr>
    </tbody>
    </table>

  - **error returns:**

    - EINVAL

      > if the device is not a disk drive or floppy drive, or if the user passes a null pointer

  - **notes:**

    Not particularly useful with modern disk drives, whose geometry is a polite fiction anyway.  Modern drives are addressed purely by sector number nowadays (lba addressing), and the drive geometry is an abstraction which is actually subject to change.  Currently (as of Nov 2004), the geometry values are the "bios" values -- presumably the values the drive had when Linux first booted.

    In addition, the cylinders field of the hd_geometry is an unsigned short, meaning that on most architectures, this ioctl will not return a meaningful value on drives with more than 65535 tracks.

    The start field is unsigned long, meaning that it will not contain a meaningful value for disks over 219 Gb in size.

- **HDIO_GET_IDENTITY**

  get IDE identification info

  usage:



  ```text
  unsigned char identity[512];

  ioctl(fd, HDIO_GET_IDENTITY, identity);
  ```

  - **inputs:**

    none

  - **outputs:**

    ATA drive identity information.  For full description, see the IDENTIFY DEVICE and IDENTIFY PACKET DEVICE commands in the ATA specification.

  - **error returns:**

    - EINVAL      Called on a partition instead of the whole disk device

    - ENOMSG      IDENTIFY DEVICE information not available

  - **notes:**

    Returns information that was obtained when the drive was probed.  Some of this information is subject to change, and this ioctl does not re-probe the drive to update the information.

    This information is also available from /proc/ide/hdX/identify

- **HDIO_GET_32BIT**

  get current io_32bit setting

  usage:



  ```text
  long val;

  ioctl(fd, HDIO_GET_32BIT, &val);
  ```

  - **inputs:**

    none

  - **outputs:**

    The value of the current io_32bit setting

  - **notes:**

    0=16-bit, 1=32-bit, 2,3 = 32bit+sync

- **HDIO_DRIVE_TASKFILE**

  execute raw taskfile

  - **Note:**

    If you don't have a copy of the ANSI ATA specification handy, you should probably ignore this ioctl.

  - Execute an ATA disk command directly by writing the "taskfile" registers of the drive.  Requires ADMIN and RAWIO access privileges.

  usage:



  ```text
  struct {

    ide_task_request_t req_task;
    u8 outbuf[OUTPUT_SIZE];
    u8 inbuf[INPUT_SIZE];
  } task;
  memset(&task.req_task, 0, sizeof(task.req_task));
  task.req_task.out_size = sizeof(task.outbuf);
  task.req_task.in_size = sizeof(task.inbuf);
  ...
  ioctl(fd, HDIO_DRIVE_TASKFILE, &task);
  ...
  ```

  inputs:

  > (See below for details on memory area passed to ioctl.)
  >
  >
  > <table>
  > <tbody>
  > <tr>
  > <td>
  >
  >
  > io_ports\[8\]
  >
  > </td>
  > <td>
  >
  >
  > values to be written to taskfile registers
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > hob_ports\[8\]
  >
  > </td>
  > <td>
  >
  >
  > high-order bytes, for extended commands.
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > out_flags
  >
  > </td>
  > <td>
  >
  >
  > flags indicating which registers are valid
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > in_flags
  >
  > </td>
  > <td>
  >
  >
  > flags indicating which registers should be returned
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > data_phase
  >
  > </td>
  > <td>
  >
  >
  > see below
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > req_cmd
  >
  > </td>
  > <td>
  >
  >
  > command type to be executed
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > out_size
  >
  > </td>
  > <td>
  >
  >
  > size of output buffer
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > outbuf
  >
  > </td>
  > <td>
  >
  >
  > buffer of data to be transmitted to disk
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > inbuf
  >
  > </td>
  > <td>
  >
  >
  > buffer of data to be received from disk (see \[1\])
  >
  > </td>
  > </tr>
  > </tbody>
  > </table>

  outputs:

  >
  > <table>
  > <tbody>
  > <tr>
  > <td>
  >
  >
  > io_ports\[\]
  >
  > </td>
  > <td>
  >
  >
  > values returned in the taskfile registers
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > hob_ports\[\]
  >
  > </td>
  > <td>
  >
  >
  > high-order bytes, for extended commands.
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > out_flags
  >
  > </td>
  > <td>
  >
  >
  > flags indicating which registers are valid (see \[2\])
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > in_flags
  >
  > </td>
  > <td>
  >
  >
  > flags indicating which registers should be returned
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > outbuf
  >
  > </td>
  > <td>
  >
  >
  > buffer of data to be transmitted to disk (see \[1\])
  >
  > </td>
  > </tr>
  > <tr>
  > <td>
  >
  >
  > inbuf
  >
  > </td>
  > <td>
  >
  >
  > buffer of data to be received from disk
  >
  > </td>
  > </tr>
  > </tbody>
  > </table>

  - **error returns:**

    - EACCES      CAP_SYS_ADMIN or CAP_SYS_RAWIO privilege not set.

    - ENOMSG      Device is not a disk drive.

    - ENOMEM      Unable to allocate memory for task

    - EFAULT      req_cmd == TASKFILE_IN_OUT (not implemented as of 2.6.8)

    - EPERM

      > req_cmd == TASKFILE_MULTI_OUT and drive multi-count not yet set.

    - EIO         Drive failed the command.

  notes:

  > \[1\] READ THE FOLLOWING NOTES *CAREFULLY*.  THIS IOCTL IS FULL OF GOTCHAS.  Extreme caution should be used with using this ioctl.  A mistake can easily corrupt data or hang the system.
  >
  > \[2\] Both the input and output buffers are copied from the user and written back to the user, even when not used.
  >
  > \[3\] If one or more bits are set in out_flags and in_flags is zero, the following values are used for in_flags.all and written back into in_flags on completion.
  >
  > > - IDE_TASKFILE_STD_IN_FLAGS \| (IDE_HOB_STD_IN_FLAGS &lt;&lt; 8) if LBA48 addressing is enabled for the drive
  > >
  > > - IDE_TASKFILE_STD_IN_FLAGS if CHS/LBA28
  >
  > The association between in_flags.all and each enable bitfield flips depending on endianness; fortunately, TASKFILE only uses inflags.b.data bit and ignores all other bits. The end result is that, on any endian machines, it has no effect other than modifying in_flags on completion.
  >
  > \[4\] The default value of SELECT is (0xa0\|DEV_bit\|LBA_bit) except for four drives per port chipsets.  For four drives per port chipsets, it's (0xa0\|DEV_bit\|LBA_bit) for the first pair and (0x80\|DEV_bit\|LBA_bit) for the second pair.
  >
  > \[5\] The argument to the ioctl is a pointer to a region of memory containing a ide_task_request_t structure, followed by an optional buffer of data to be transmitted to the drive, followed by an optional buffer to receive data from the drive.
  >
  > Command is passed to the disk drive via the ide_task_request_t structure, which contains these fields:
  >
  > >
  > > <table>
  > > <tbody>
  > > <tr>
  > > <td>
  > >
  > >
  > > io_ports\[8\]
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > values for the taskfile registers
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > hob_ports\[8\]
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > high-order bytes, for extended commands
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > out_flags
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > flags indicating which entries in the io_ports\[\] and hob_ports\[\] arrays contain valid values.  Type ide_reg_valid_t.
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > in_flags
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > flags indicating which entries in the io_ports\[\] and hob_ports\[\] arrays are expected to contain valid values on return.
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > data_phase
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > See below
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > req_cmd
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > Command type, see below
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > out_size
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > output (user-&gt;drive) buffer size, bytes
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > in_size
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > input (drive-&gt;user) buffer size, bytes
  > >
  > > </td>
  > > </tr>
  > > </tbody>
  > > </table>
  >
  > When out_flags is zero, the following registers are loaded.
  >
  > >
  > > <table>
  > > <tbody>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_FEATURE
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_NSECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_SECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_LCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_HCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > FEATURE
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > NSECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > SECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > LCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > SELECT
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > First, masked with 0xE0 if LBA48, 0xEF otherwise; then, or'ed with the default value of SELECT.
  > >
  > > </td>
  > > </tr>
  > > </tbody>
  > > </table>
  >
  > If any bit in out_flags is set, the following registers are loaded.
  >
  > >
  > > <table>
  > > <tbody>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_DATA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.data is set.  HOB_DATA will travel on DD8-DD15 on little endian machines and on DD0-DD7 on big endian machines.
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > DATA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.data is set.  DATA will travel on DD0-DD7 on little endian machines and on DD8-DD15 on big endian machines.
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_NSECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.nsector_hob is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_SECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.sector_hob is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_LCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.lcyl_hob is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_HCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.hcyl_hob is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > FEATURE
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.feature is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > NSECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.nsector is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > SECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.sector is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > LCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.lcyl is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If out_flags.b.hcyl is set
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > SELECT
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > Or'ed with the default value of SELECT and loaded regardless of out_flags.b.select.
  > >
  > > </td>
  > > </tr>
  > > </tbody>
  > > </table>
  >
  > Taskfile registers are read back from the drive into \{io\|hob\}\_ports\[\] after the command completes iff one of the following conditions is met; otherwise, the original values will be written back, unchanged.
  >
  > > 1. The drive fails the command (EIO).
  > >
  > > 2. One or more than one bits are set in out_flags.
  > >
  > > 3. The requested data_phase is TASKFILE_NO_DATA.
  > >
  > >
  > > <table>
  > > <tbody>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_DATA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If in_flags.b.data is set.  It will contain DD8-DD15 on little endian machines and DD0-DD7 on big endian machines.
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > DATA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If in_flags.b.data is set.  It will contain DD0-DD7 on little endian machines and DD8-DD15 on big endian machines.
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_FEATURE
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_NSECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_SECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_LCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HOB_HCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > If the drive supports LBA48
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > NSECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > SECTOR
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > LCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > HCYL
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > </tbody>
  > > </table>
  >
  > The data_phase field describes the data transfer to be performed.  Value is one of:
  >
  > >
  > > <table>
  > > <tbody>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_IN
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_MULTI_IN
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_OUT
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_MULTI_OUT
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_IN_OUT
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_IN_DMA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_IN_DMAQ
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > == IN_DMA (queueing not supported)
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_OUT_DMA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_OUT_DMAQ
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > == OUT_DMA (queueing not supported)
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_P_IN
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > unimplemented
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_P_IN_DMA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > unimplemented
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_P_IN_DMAQ
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > unimplemented
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_P_OUT
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > unimplemented
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_P_OUT_DMA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > unimplemented
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > TASKFILE_P_OUT_DMAQ
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > unimplemented
  > >
  > > </td>
  > > </tr>
  > > </tbody>
  > > </table>
  >
  > The req_cmd field classifies the command type.  It may be one of:
  >
  > >
  > > <table>
  > > <tbody>
  > > <tr>
  > > <td>
  > >
  > >
  > > IDE_DRIVE_TASK_NO_DATA
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > IDE_DRIVE_TASK_SET_XFER
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > unimplemented
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > IDE_DRIVE_TASK_IN
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > IDE_DRIVE_TASK_OUT
  > >
  > > </td>
  > > <td>
  > >
  > >
  > > unimplemented
  > >
  > > </td>
  > > </tr>
  > > <tr>
  > > <td>
  > >
  > >
  > > IDE_DRIVE_TASK_RAW_WRITE
  > >
  > > </td>
  > > <td>
  > >
  > >
  > >
  > >
  > > </td>
  > > </tr>
  > > </tbody>
  > > </table>
  >
  > \[6\] Do not access \{in\|out\}\_flags-&gt;all except for resetting all the bits.  Always access individual bit fields.  -&gt;all value will flip depending on endianness.  For the same reason, do not use IDE\_\{TASKFILE\|HOB\}\_STD\_\{OUT\|IN\}\_FLAGS constants defined in hdreg.h.

- **HDIO_DRIVE_CMD**

  execute a special drive command

  Note:  If you don't have a copy of the ANSI ATA specification handy, you should probably ignore this ioctl.

  usage:



  ```text
  u8 args[4+XFER_SIZE];

  ...
  ioctl(fd, HDIO_DRIVE_CMD, args);
  ```

  - **inputs:**

    Commands other than WIN_SMART:


    <table>
    <tbody>
    <tr>
    <td>


    args\[0\]

    </td>
    <td>


    COMMAND

    </td>
    </tr>
    <tr>
    <td>


    args\[1\]

    </td>
    <td>


    NSECTOR

    </td>
    </tr>
    <tr>
    <td>


    args\[2\]

    </td>
    <td>


    FEATURE

    </td>
    </tr>
    <tr>
    <td>


    args\[3\]

    </td>
    <td>


    NSECTOR

    </td>
    </tr>
    </tbody>
    </table>

    WIN_SMART:


    <table>
    <tbody>
    <tr>
    <td>


    args\[0\]

    </td>
    <td>


    COMMAND

    </td>
    </tr>
    <tr>
    <td>


    args\[1\]

    </td>
    <td>


    SECTOR

    </td>
    </tr>
    <tr>
    <td>


    args\[2\]

    </td>
    <td>


    FEATURE

    </td>
    </tr>
    <tr>
    <td>


    args\[3\]

    </td>
    <td>


    NSECTOR

    </td>
    </tr>
    </tbody>
    </table>

  - **outputs:**

    > args\[\] buffer is filled with register values followed by any

    data returned by the disk.

    >
    > <table>
    > <tbody>
    > <tr>
    > <td>
    >
    >
    > args\[0\]
    >
    > </td>
    > <td>
    >
    >
    > status
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > args\[1\]
    >
    > </td>
    > <td>
    >
    >
    > error
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > args\[2\]
    >
    > </td>
    > <td>
    >
    >
    > NSECTOR
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > args\[3\]
    >
    > </td>
    > <td>
    >
    >
    > undefined
    >
    > </td>
    > </tr>
    > <tr>
    > <td>
    >
    >
    > args\[4+\]
    >
    > </td>
    > <td>
    >
    >
    > NSECTOR \* 512 bytes of data returned by the command.
    >
    > </td>
    > </tr>
    > </tbody>
    > </table>

  - **error returns:**

    - EACCES      Access denied:  requires CAP_SYS_RAWIO

    - ENOMEM      Unable to allocate memory for task

    - EIO         Drive reports error

  notes:

  > \[1\] For commands other than WIN_SMART, args\[1\] should equal args\[3\].  SECTOR, LCYL and HCYL are undefined.  For WIN_SMART, 0x4f and 0xc2 are loaded into LCYL and HCYL respectively.  In both cases SELECT will contain the default value for the drive.  Please refer to HDIO_DRIVE_TASKFILE notes for the default value of SELECT.
  >
  > \[2\] If NSECTOR value is greater than zero and the drive sets DRQ when interrupting for the command, NSECTOR \* 512 bytes are read from the device into the area following NSECTOR. In the above example, the area would be args\[4..4+XFER_SIZE\].  16bit PIO is used regardless of HDIO_SET_32BIT setting.
  >
  > \[3\] If COMMAND == WIN_SETFEATURES &amp;&amp; FEATURE == SETFEATURES_XFER &amp;&amp; NSECTOR &gt;= XFER_SW_DMA_0 &amp;&amp; the drive supports any DMA mode, IDE driver will try to tune the transfer mode of the drive accordingly.

- **HDIO_DRIVE_TASK**

  execute task and special drive command

  Note:  If you don't have a copy of the ANSI ATA specification handy, you should probably ignore this ioctl.

  usage:



  ```text
  u8 args[7];

  ...
  ioctl(fd, HDIO_DRIVE_TASK, args);
  ```

  - **inputs:**

    Taskfile register values:


    <table>
    <tbody>
    <tr>
    <td>


    args\[0\]

    </td>
    <td>


    COMMAND

    </td>
    </tr>
    <tr>
    <td>


    args\[1\]

    </td>
    <td>


    FEATURE

    </td>
    </tr>
    <tr>
    <td>


    args\[2\]

    </td>
    <td>


    NSECTOR

    </td>
    </tr>
    <tr>
    <td>


    args\[3\]

    </td>
    <td>


    SECTOR

    </td>
    </tr>
    <tr>
    <td>


    args\[4\]

    </td>
    <td>


    LCYL

    </td>
    </tr>
    <tr>
    <td>


    args\[5\]

    </td>
    <td>


    HCYL

    </td>
    </tr>
    <tr>
    <td>


    args\[6\]

    </td>
    <td>


    SELECT

    </td>
    </tr>
    </tbody>
    </table>

  - **outputs:**

    Taskfile register values:


    <table>
    <tbody>
    <tr>
    <td>


    args\[0\]

    </td>
    <td>


    status

    </td>
    </tr>
    <tr>
    <td>


    args\[1\]

    </td>
    <td>


    error

    </td>
    </tr>
    <tr>
    <td>


    args\[2\]

    </td>
    <td>


    NSECTOR

    </td>
    </tr>
    <tr>
    <td>


    args\[3\]

    </td>
    <td>


    SECTOR

    </td>
    </tr>
    <tr>
    <td>


    args\[4\]

    </td>
    <td>


    LCYL

    </td>
    </tr>
    <tr>
    <td>


    args\[5\]

    </td>
    <td>


    HCYL

    </td>
    </tr>
    <tr>
    <td>


    args\[6\]

    </td>
    <td>


    SELECT

    </td>
    </tr>
    </tbody>
    </table>

  - **error returns:**

    - EACCES      Access denied:  requires CAP_SYS_RAWIO

    - ENOMEM      Unable to allocate memory for task

    - ENOMSG      Device is not a disk drive.

    - EIO         Drive failed the command.

  notes:

  > \[1\] DEV bit (0x10) of SELECT register is ignored and the appropriate value for the drive is used.  All other bits are used unaltered.

- **HDIO_SET_32BIT**

  change io_32bit flags

  usage:



  ```text
  int val;

  ioctl(fd, HDIO_SET_32BIT, val);
  ```

  - **inputs:**

    New value for io_32bit flag

  - **outputs:**

    none

  - **error return:**

    - EINVAL      Called on a partition instead of the whole disk device

    - EACCES      Access denied:  requires CAP_SYS_ADMIN

    - EINVAL      value out of range \[0 3\]

    - EBUSY       Controller busy

---

# Decoding an IOCTL Magic Number

_Peios Kernel / Userspace interfaces / System and device interfaces / ioctl conventions_

> To decode a hex IOCTL code:

<a id="rst-decoding-an-ioctl-magic-number"></a>

To decode a hex IOCTL code:

Most architectures use this generic format, but check include/ARCH/ioctl.h for specifics, e.g. powerpc uses 3 bits to encode read/write and 13 bits for size.

>
> <table>
> <thead>
> <tr>
> <th>
>
>
> bits
>
> </th>
> <th>
>
>
> meaning
>
> </th>
> </tr>
> </thead>
> <tbody>
> <tr>
> <td>
>
>
> 31-30
>
> </td>
> <td>
>
>
> 00 - no parameters: uses \_IO macro 10 - read: \_IOR 01 - write: \_IOW 11 - read/write: \_IOWR
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> 29-16
>
> </td>
> <td>
>
>
> size of arguments
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> 15-8
>
> </td>
> <td>
>
>
> ascii character supposedly unique to each driver
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> 7-0
>
> </td>
> <td>
>
>
> function \#
>
> </td>
> </tr>
> </tbody>
> </table>

So for example 0x82187201 is a read with arg length of 0x218, character 'r' function 1. Grepping the source reveals this is:



```text
#define VFAT_IOCTL_READDIR_BOTH         _IOR('r', 1, struct dirent [2])
```

---

# Ioctl Numbers

_Peios Kernel / Userspace interfaces / System and device interfaces / ioctl conventions_

> 19 October 1999

<a id="rst-ioctl-numbers"></a>

19 October 1999

Michael Elizabeth Chastain &lt;[mec@shout.net](<mailto:mec@shout.net>)&gt;

If you are adding new ioctl's to the kernel, you should use the \_IO macros defined in &lt;linux/ioctl.h&gt;:

>
> <table>
> <thead>
> <tr>
> <th>
>
>
> macro
>
> </th>
> <th>
>
>
> parameters
>
> </th>
> </tr>
> </thead>
> <tbody>
> <tr>
> <td>
>
>
> \_IO
>
> </td>
> <td>
>
>
> none
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> \_IOW
>
> </td>
> <td>
>
>
> write (read from userspace)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> \_IOR
>
> </td>
> <td>
>
>
> read (write to userspace)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> \_IOWR
>
> </td>
> <td>
>
>
> write and read
>
> </td>
> </tr>
> </tbody>
> </table>

'Write' and 'read' are from the user's point of view, just like the system calls 'write' and 'read'.  For example, a SET_FOO ioctl would be \_IOW, although the kernel would actually read data from user space; a GET_FOO ioctl would be \_IOR, although the kernel would actually write data to user space.

The first argument to the macros is an identifying letter or number from the table below. Because of the large number of drivers, many drivers share a partial letter with other drivers.

If you are writing a driver for a new device and need a letter, pick an unused block with enough room for expansion: 32 to 256 ioctl commands should suffice. You can register the block by patching this file and submitting the patch through [usual patch submission process](</kernel/development/process/submitting-patches.md>).

The second argument is a sequence number to distinguish ioctls from each other. The third argument (not applicable to \_IO) is the type of the data going into the kernel or coming out of the kernel (e.g.  'int' or 'struct foo').

> [!NOTE]
>
> Do NOT use sizeof(arg) as the third argument as this results in your ioctl thinking it passes an argument of type size_t.

Some devices use their major number as the identifier; this is OK, as long as it is unique.  Some devices are irregular and don't follow any convention at all.

Following this convention is good because:

1. Keeping the ioctl's globally unique helps error checking: if a program calls an ioctl on the wrong device, it will get an error rather than some unexpected behaviour.

2. The 'strace' build procedure automatically finds ioctl numbers defined with the macros.

3. 'strace' can decode numbers back into useful names when the numbers are unique.

4. People looking for ioctls can grep for them more easily when this convention is used to define the ioctl numbers.

5. When following the convention, the driver code can use generic code to copy the parameters between user and kernel space.

This table lists ioctls visible from userland, excluding ones from drivers/staging/.


<table>
<thead>
<tr>
<th>


Code

</th>
<th>


Seq\# (hex)

</th>
<th>


Include File

</th>
<th>


Comments

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0x00

</td>
<td>


00-1F

</td>
<td>


linux/fs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


0x00

</td>
<td>


00-1F

</td>
<td>


scsi/scsi_ioctl.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


0x00

</td>
<td>


00-1F

</td>
<td>


linux/fb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


0x00

</td>
<td>


00-1F

</td>
<td>


linux/wavefront.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


0x02

</td>
<td>


all

</td>
<td>


linux/fd.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x03

</td>
<td>


all

</td>
<td>


linux/hdreg.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x04

</td>
<td>


D2-DC

</td>
<td>


linux/umsdos_fs.h

</td>
<td>


Dead since 2.6.11, but don't reuse these.

</td>
</tr>
<tr>
<td>


0x06

</td>
<td>


all

</td>
<td>


linux/lp.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x07

</td>
<td>


9F-D0

</td>
<td>


linux/vmw_vmci_defs.h, uapi/linux/vm_sockets.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x09

</td>
<td>


all

</td>
<td>


linux/raid/md_u.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x10

</td>
<td>


00-0F

</td>
<td>


drivers/char/s390/vmcp.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x10

</td>
<td>


10-1F

</td>
<td>


arch/s390/include/uapi/sclp_ctl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x10

</td>
<td>


20-2F

</td>
<td>


arch/s390/include/uapi/asm/hypfs.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x12

</td>
<td>


all

</td>
<td>


linux/fs.h linux/blkpg.h linux/blkzoned.h linux/blk-crypto.h

</td>
<td>


BLK\* ioctls

</td>
</tr>
<tr>
<td>


0x15

</td>
<td>


all

</td>
<td>


linux/fs.h

</td>
<td>


FS_IOC\_\* ioctls

</td>
</tr>
<tr>
<td>


0x1b

</td>
<td>


all

</td>
<td>




</td>
<td>


InfiniBand Subsystem &lt;[http://infiniband.sourceforge.net/](<http://infiniband.sourceforge.net/>)&gt;

</td>
</tr>
<tr>
<td>


0x20

</td>
<td>


all

</td>
<td>


drivers/cdrom/cm206.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x22

</td>
<td>


all

</td>
<td>


scsi/sg.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x3E

</td>
<td>


00-0F

</td>
<td>


linux/counter.h

</td>
<td>


&lt;[mailto:linux-iio@vger.kernel.org](<mailto:linux-iio@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


'\!'

</td>
<td>


00-1F

</td>
<td>


uapi/linux/seccomp.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'\#'

</td>
<td>


00-3F

</td>
<td>




</td>
<td>


IEEE 1394 Subsystem Block for the entire subsystem

</td>
</tr>
<tr>
<td>


'$'

</td>
<td>


00-0F

</td>
<td>


linux/perf_counter.h, linux/perf_event.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'%'

</td>
<td>


00-0F

</td>
<td>


include/uapi/linux/stm.h

</td>
<td>


System Trace Module subsystem &lt;[mailto:alexander.shishkin@linux.intel.com](<mailto:alexander.shishkin@linux.intel.com>)&gt;

</td>
</tr>
<tr>
<td>


'&amp;'

</td>
<td>


00-07

</td>
<td>


drivers/firewire/nosy-user.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'\*'

</td>
<td>


00-1F

</td>
<td>


uapi/linux/user_events.h

</td>
<td>


User Events Subsystem &lt;[mailto:linux-trace-kernel@vger.kernel.org](<mailto:linux-trace-kernel@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


'1'

</td>
<td>


00-1F

</td>
<td>


linux/timepps.h

</td>
<td>


PPS kit from Ulrich Windl &lt;[ftp://ftp.de.kernel.org/pub/linux/daemons/ntp/PPS/](<ftp://ftp.de.kernel.org/pub/linux/daemons/ntp/PPS/>)&gt;

</td>
</tr>
<tr>
<td>


'2'

</td>
<td>


01-04

</td>
<td>


linux/i2o.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'3'

</td>
<td>


00-0F

</td>
<td>


drivers/s390/char/raw3270.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'3'

</td>
<td>


00-1F

</td>
<td>


linux/suspend_ioctls.h, kernel/power/user.c

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'8'

</td>
<td>


all

</td>
<td>




</td>
<td>


SNP8023 advanced NIC card &lt;[mailto:mcr@solidum.com](<mailto:mcr@solidum.com>)&gt;

</td>
</tr>
<tr>
<td>


';'

</td>
<td>


64-7F

</td>
<td>


linux/vfio.h

</td>
<td>




</td>
</tr>
<tr>
<td>


';'

</td>
<td>


80-FF

</td>
<td>


linux/iommufd.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'='

</td>
<td>


00-3f

</td>
<td>


uapi/linux/ptp_clock.h

</td>
<td>


&lt;[mailto:richardcochran@gmail.com](<mailto:richardcochran@gmail.com>)&gt;

</td>
</tr>
<tr>
<td>


'@'

</td>
<td>


00-0F

</td>
<td>


linux/radeonfb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'@'

</td>
<td>


00-0F

</td>
<td>


drivers/video/aty/aty128fb.c

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'A'

</td>
<td>


00-1F

</td>
<td>


linux/apm_bios.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'A'

</td>
<td>


00-0F

</td>
<td>


linux/agpgart.h, drivers/char/agp/compat_ioctl.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'A'

</td>
<td>


00-7F

</td>
<td>


sound/asound.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'B'

</td>
<td>


00-1F

</td>
<td>


linux/cciss_ioctl.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'B'

</td>
<td>


00-0F

</td>
<td>


include/linux/pmu.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'B'

</td>
<td>


C0-FF

</td>
<td>


advanced bbus

</td>
<td>


&lt;[mailto:maassen@uni-freiburg.de](<mailto:maassen@uni-freiburg.de>)&gt;

</td>
</tr>
<tr>
<td>


'B'

</td>
<td>


00-0F

</td>
<td>


xen/xenbus_dev.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'C'

</td>
<td>


all

</td>
<td>


linux/soundcard.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'C'

</td>
<td>


01-2F

</td>
<td>


linux/capi.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'C'

</td>
<td>


F0-FF

</td>
<td>


drivers/net/wan/cosa.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'D'

</td>
<td>


all

</td>
<td>


arch/s390/include/asm/dasd.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'D'

</td>
<td>


40-5F

</td>
<td>


drivers/scsi/dpt/dtpi_ioctl.h

</td>
<td>


Dead since 2022

</td>
</tr>
<tr>
<td>


'D'

</td>
<td>


05

</td>
<td>


drivers/scsi/pmcraid.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'E'

</td>
<td>


all

</td>
<td>


linux/input.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'E'

</td>
<td>


00-0F

</td>
<td>


xen/evtchn.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


all

</td>
<td>


linux/fb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


01-02

</td>
<td>


drivers/scsi/pmcraid.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


20

</td>
<td>


drivers/video/fsl-diu-fb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


20

</td>
<td>


linux/ivtvfb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


20

</td>
<td>


linux/matroxfb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


20

</td>
<td>


drivers/video/aty/atyfb_base.c

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


00-0F

</td>
<td>


video/da8xx-fb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


80-8F

</td>
<td>


linux/arcfb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'F'

</td>
<td>


DD

</td>
<td>


video/sstfb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'G'

</td>
<td>


00-3F

</td>
<td>


drivers/misc/sgi-gru/grulib.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'G'

</td>
<td>


00-0F

</td>
<td>


xen/gntalloc.h, xen/gntdev.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


00-7F

</td>
<td>


linux/hiddev.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


00-0F

</td>
<td>


linux/hidraw.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


01

</td>
<td>


linux/mei.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


02

</td>
<td>


linux/mei.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


03

</td>
<td>


linux/mei.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


00-0F

</td>
<td>


sound/asound.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


20-40

</td>
<td>


sound/asound_fm.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


80-8F

</td>
<td>


sound/sfnt_info.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


10-8F

</td>
<td>


sound/emu10k1.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


10-1F

</td>
<td>


sound/sb16_csp.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


10-1F

</td>
<td>


sound/hda_hwdep.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


40-4F

</td>
<td>


sound/hdspm.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


40-4F

</td>
<td>


sound/hdsp.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


90

</td>
<td>


sound/usb/usx2y/usb_stream.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


00-0F

</td>
<td>


uapi/misc/habanalabs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


A0

</td>
<td>


uapi/linux/usb/cdc-wdm.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


C0-F0

</td>
<td>


net/bluetooth/hci.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


C0-DF

</td>
<td>


net/bluetooth/hidp/hidp.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


C0-DF

</td>
<td>


net/bluetooth/cmtp/cmtp.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


C0-DF

</td>
<td>


net/bluetooth/bnep/bnep.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


F1

</td>
<td>


linux/hid-roccat.h

</td>
<td>


&lt;[mailto:erazor_de@users.sourceforge.net](<mailto:erazor_de@users.sourceforge.net>)&gt;

</td>
</tr>
<tr>
<td>


'H'

</td>
<td>


F8-FA

</td>
<td>


sound/firewire.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'I'

</td>
<td>


all

</td>
<td>


linux/isdn.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'I'

</td>
<td>


00-0F

</td>
<td>


drivers/isdn/divert/isdn_divert.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'I'

</td>
<td>


40-4F

</td>
<td>


linux/mISDNif.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'K'

</td>
<td>


all

</td>
<td>


linux/kd.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'L'

</td>
<td>


00-1F

</td>
<td>


linux/loop.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'L'

</td>
<td>


10-1F

</td>
<td>


drivers/scsi/mpt3sas/mpt3sas_ctl.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'L'

</td>
<td>


E0-FF

</td>
<td>


linux/ppdd.h

</td>
<td>


encrypted disk device driver &lt;[http://linux01.gwdg.de/\~alatham/ppdd.html](<http://linux01.gwdg.de/~alatham/ppdd.html>)&gt;

</td>
</tr>
<tr>
<td>


'M'

</td>
<td>


all

</td>
<td>


linux/soundcard.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'M'

</td>
<td>


01-16 and

</td>
<td>


mtd/mtd-abi.h drivers/mtd/mtdchar.c

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'M'

</td>
<td>


01-03

</td>
<td>


drivers/scsi/megaraid/megaraid_sas.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'M'

</td>
<td>


00-0F

</td>
<td>


drivers/video/fsl-diu-fb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'N'

</td>
<td>


00-1F

</td>
<td>


drivers/usb/scanner.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'N'

</td>
<td>


40-7F

</td>
<td>


drivers/block/nvme.c

</td>
<td>




</td>
</tr>
<tr>
<td>


'N'

</td>
<td>


80-8F

</td>
<td>


uapi/linux/ntsync.h

</td>
<td>


NT synchronization primitives &lt;[mailto:wine-devel@winehq.org](<mailto:wine-devel@winehq.org>)&gt;

</td>
</tr>
<tr>
<td>


'O'

</td>
<td>


00-06

</td>
<td>


mtd/ubi-user.h

</td>
<td>


UBI

</td>
</tr>
<tr>
<td>


'P'

</td>
<td>


all

</td>
<td>


linux/soundcard.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'P'

</td>
<td>


60-6F

</td>
<td>


sound/sscape_ioctl.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'P'

</td>
<td>


00-0F

</td>
<td>


drivers/usb/class/usblp.c

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'P'

</td>
<td>


01-09

</td>
<td>


drivers/misc/pci_endpoint_test.c

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'P'

</td>
<td>


00-0F

</td>
<td>


xen/privcmd.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'P'

</td>
<td>


00-05

</td>
<td>


linux/tps6594_pfsm.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'Q'

</td>
<td>


all

</td>
<td>


linux/soundcard.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'R'

</td>
<td>


00-1F

</td>
<td>


linux/random.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'R'

</td>
<td>


01

</td>
<td>


linux/rfkill.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'R'

</td>
<td>


20-2F

</td>
<td>


linux/trace_mmap.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'R'

</td>
<td>


C0-DF

</td>
<td>


net/bluetooth/rfcomm.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'R'

</td>
<td>


E0

</td>
<td>


uapi/linux/fsl_mc.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'S'

</td>
<td>


all

</td>
<td>


linux/cdrom.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'S'

</td>
<td>


80-81

</td>
<td>


scsi/scsi_ioctl.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'S'

</td>
<td>


82-FF

</td>
<td>


scsi/scsi.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'S'

</td>
<td>


00-7F

</td>
<td>


sound/asequencer.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'T'

</td>
<td>


all

</td>
<td>


linux/soundcard.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'T'

</td>
<td>


00-AF

</td>
<td>


sound/asound.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'T'

</td>
<td>


all

</td>
<td>


arch/x86/include/asm/ioctls.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'T'

</td>
<td>


C0-DF

</td>
<td>


linux/if_tun.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'U'

</td>
<td>


all

</td>
<td>


sound/asound.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'U'

</td>
<td>


00-CF

</td>
<td>


linux/uinput.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'U'

</td>
<td>


00-EF

</td>
<td>


linux/usbdevice_fs.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'U'

</td>
<td>


C0-CF

</td>
<td>


drivers/bluetooth/hci_uart.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'V'

</td>
<td>


all

</td>
<td>


linux/vt.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'V'

</td>
<td>


all

</td>
<td>


linux/videodev2.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'V'

</td>
<td>


C0

</td>
<td>


linux/ivtvfb.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'V'

</td>
<td>


C0

</td>
<td>


linux/ivtv.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'V'

</td>
<td>


C0

</td>
<td>


media/si4713.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'W'

</td>
<td>


00-1F

</td>
<td>


linux/watchdog.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'W'

</td>
<td>


00-1F

</td>
<td>


linux/wanrouter.h

</td>
<td>


conflict\! (pre 3.9)

</td>
</tr>
<tr>
<td>


'W'

</td>
<td>


00-3F

</td>
<td>


sound/asound.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'W'

</td>
<td>


40-5F

</td>
<td>


drivers/pci/switch/switchtec.c

</td>
<td>




</td>
</tr>
<tr>
<td>


'W'

</td>
<td>


60-61

</td>
<td>


linux/watch_queue.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'X'

</td>
<td>


all

</td>
<td>


fs/xfs/xfs_fs.h, fs/xfs/linux-2.6/xfs_ioctl32.h, include/linux/falloc.h, linux/fs.h,

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'X'

</td>
<td>


all

</td>
<td>


fs/ocfs2/ocfs_fs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'Z'

</td>
<td>


14-15

</td>
<td>


drivers/message/fusion/mptctl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'\['

</td>
<td>


00-3F

</td>
<td>


linux/usb/tmc.h

</td>
<td>


USB Test and Measurement Devices &lt;[mailto:gregkh@linuxfoundation.org](<mailto:gregkh@linuxfoundation.org>)&gt;

</td>
</tr>
<tr>
<td>


'a'

</td>
<td>


all

</td>
<td>


linux/atm\*.h, linux/sonet.h

</td>
<td>


ATM on linux &lt;[http://lrcwww.epfl.ch/](<http://lrcwww.epfl.ch/>)&gt;

</td>
</tr>
<tr>
<td>


'a'

</td>
<td>


00-0F

</td>
<td>


drivers/crypto/qat/qat_common/adf_cfg_common.h

</td>
<td>


conflict\! qat driver

</td>
</tr>
<tr>
<td>


'b'

</td>
<td>


00-FF

</td>
<td>




</td>
<td>


conflict\! bit3 vme host bridge &lt;[mailto:natalia@nikhefk.nikhef.nl](<mailto:natalia@nikhefk.nikhef.nl>)&gt;

</td>
</tr>
<tr>
<td>


'b'

</td>
<td>


00-0F

</td>
<td>


linux/dma-buf.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'c'

</td>
<td>


00-7F

</td>
<td>


linux/comstats.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'c'

</td>
<td>


00-7F

</td>
<td>


linux/coda.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'c'

</td>
<td>


00-1F

</td>
<td>


linux/chio.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'c'

</td>
<td>


80-9F

</td>
<td>


arch/s390/include/asm/chsc.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'c'

</td>
<td>


A0-AF

</td>
<td>


arch/x86/include/asm/msr.h conflict\!

</td>
<td>




</td>
</tr>
<tr>
<td>


'd'

</td>
<td>


00-FF

</td>
<td>


linux/char/drm/drm.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'd'

</td>
<td>


02-40

</td>
<td>


pcmcia/ds.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'd'

</td>
<td>


F0-FF

</td>
<td>


linux/digi1.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'e'

</td>
<td>


all

</td>
<td>


linux/digi1.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'f'

</td>
<td>


00-1F

</td>
<td>


linux/ext2_fs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'f'

</td>
<td>


00-1F

</td>
<td>


linux/ext3_fs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'f'

</td>
<td>


00-0F

</td>
<td>


fs/jfs/jfs_dinode.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'f'

</td>
<td>


00-0F

</td>
<td>


fs/ext4/ext4.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'f'

</td>
<td>


00-0F

</td>
<td>


linux/fs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'f'

</td>
<td>


00-0F

</td>
<td>


fs/ocfs2/ocfs2_fs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'f'

</td>
<td>


13-27

</td>
<td>


linux/fscrypt.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'f'

</td>
<td>


81-8F

</td>
<td>


linux/fsverity.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'g'

</td>
<td>


00-0F

</td>
<td>


linux/usb/gadgetfs.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'g'

</td>
<td>


20-2F

</td>
<td>


linux/usb/g_printer.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'h'

</td>
<td>


00-7F

</td>
<td>




</td>
<td>


conflict\! Charon filesystem &lt;[mailto:zapman@interlan.net](<mailto:zapman@interlan.net>)&gt;

</td>
</tr>
<tr>
<td>


'h'

</td>
<td>


00-1F

</td>
<td>


linux/hpet.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'h'

</td>
<td>


80-8F

</td>
<td>


fs/hfsplus/ioctl.c

</td>
<td>




</td>
</tr>
<tr>
<td>


'i'

</td>
<td>


00-3F

</td>
<td>


linux/i2o-dev.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'i'

</td>
<td>


0B-1F

</td>
<td>


linux/ipmi.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'i'

</td>
<td>


80-8F

</td>
<td>


linux/i8k.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'i'

</td>
<td>


90-9F

</td>
<td>


`linux/iio/*.h`

</td>
<td>


IIO

</td>
</tr>
<tr>
<td>


'j'

</td>
<td>


00-3F

</td>
<td>


linux/joystick.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'k'

</td>
<td>


00-0F

</td>
<td>


linux/spi/spidev.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'k'

</td>
<td>


00-05

</td>
<td>


video/kyro.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'k'

</td>
<td>


10-17

</td>
<td>


linux/hsi/hsi_char.h

</td>
<td>


HSI character device

</td>
</tr>
<tr>
<td>


'l'

</td>
<td>


00-3F

</td>
<td>


linux/tcfs_fs.h

</td>
<td>


transparent cryptographic file system &lt;[http://web.archive.org/web/%2A/http://mikonos.dia.unisa.it/tcfs](<http://web.archive.org/web/%2A/http://mikonos.dia.unisa.it/tcfs>)&gt;

</td>
</tr>
<tr>
<td>


'l'

</td>
<td>


40-7F

</td>
<td>


linux/udf_fs_i.h

</td>
<td>


in development: &lt;[https://github.com/pali/udftools](<https://github.com/pali/udftools>)&gt;

</td>
</tr>
<tr>
<td>


'm'

</td>
<td>


00-09

</td>
<td>


linux/mmtimer.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'm'

</td>
<td>


all

</td>
<td>


linux/mtio.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'm'

</td>
<td>


all

</td>
<td>


linux/soundcard.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'm'

</td>
<td>


all

</td>
<td>


linux/synclink.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'm'

</td>
<td>


00-19

</td>
<td>


drivers/message/fusion/mptctl.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'm'

</td>
<td>


00

</td>
<td>


drivers/scsi/megaraid/megaraid_ioctl.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'n'

</td>
<td>


00-7F

</td>
<td>


linux/ncp_fs.h and fs/ncpfs/ioctl.c

</td>
<td>




</td>
</tr>
<tr>
<td>


'n'

</td>
<td>


80-8F

</td>
<td>


uapi/linux/nilfs2_api.h

</td>
<td>


NILFS2

</td>
</tr>
<tr>
<td>


'n'

</td>
<td>


E0-FF

</td>
<td>


linux/matroxfb.h

</td>
<td>


matroxfb

</td>
</tr>
<tr>
<td>


'o'

</td>
<td>


00-1F

</td>
<td>


fs/ocfs2/ocfs2_fs.h

</td>
<td>


OCFS2

</td>
</tr>
<tr>
<td>


'o'

</td>
<td>


00-03

</td>
<td>


mtd/ubi-user.h

</td>
<td>


conflict\! (OCFS2 and UBI overlaps)

</td>
</tr>
<tr>
<td>


'o'

</td>
<td>


40-41

</td>
<td>


mtd/ubi-user.h

</td>
<td>


UBI

</td>
</tr>
<tr>
<td>


'o'

</td>
<td>


01-A1

</td>
<td>


`linux/dvb/*.h`

</td>
<td>


DVB

</td>
</tr>
<tr>
<td>


'p'

</td>
<td>


00-0F

</td>
<td>


linux/phantom.h

</td>
<td>


conflict\! (OpenHaptics needs this)

</td>
</tr>
<tr>
<td>


'p'

</td>
<td>


00-1F

</td>
<td>


linux/rtc.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'p'

</td>
<td>


40-7F

</td>
<td>


linux/nvram.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'p'

</td>
<td>


80-9F

</td>
<td>


linux/ppdev.h

</td>
<td>


user-space parport &lt;[mailto:tim@cyberelk.net](<mailto:tim@cyberelk.net>)&gt;

</td>
</tr>
<tr>
<td>


'p'

</td>
<td>


A1-A5

</td>
<td>


linux/pps.h

</td>
<td>


LinuxPPS

</td>
</tr>
<tr>
<td>


'p'

</td>
<td>


B1-B3

</td>
<td>


linux/pps_gen.h

</td>
<td>


LinuxPPS &lt;[mailto:giometti@linux.it](<mailto:giometti@linux.it>)&gt;

</td>
</tr>
<tr>
<td>


'q'

</td>
<td>


00-1F

</td>
<td>


linux/serio.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'q'

</td>
<td>


80-FF

</td>
<td>


linux/telephony.h linux/ixjuser.h

</td>
<td>


Internet PhoneJACK, Internet LineJACK &lt;[http://web.archive.org/web/%2A/http://www.quicknet.net](<http://web.archive.org/web/%2A/http://www.quicknet.net>)&gt;

</td>
</tr>
<tr>
<td>


'r'

</td>
<td>


00-1F

</td>
<td>


linux/msdos_fs.h and fs/fat/dir.c

</td>
<td>




</td>
</tr>
<tr>
<td>


's'

</td>
<td>


all

</td>
<td>


linux/cdk.h

</td>
<td>




</td>
</tr>
<tr>
<td>


't'

</td>
<td>


00-7F

</td>
<td>


linux/ppp-ioctl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


't'

</td>
<td>


80-8F

</td>
<td>


linux/isdn_ppp.h

</td>
<td>




</td>
</tr>
<tr>
<td>


't'

</td>
<td>


90-91

</td>
<td>


linux/toshiba.h

</td>
<td>


toshiba and toshiba_acpi SMM

</td>
</tr>
<tr>
<td>


'u'

</td>
<td>


00-1F

</td>
<td>


linux/smb_fs.h

</td>
<td>


gone

</td>
</tr>
<tr>
<td>


'u'

</td>
<td>


00-2F

</td>
<td>


linux/ublk_cmd.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'u'

</td>
<td>


20-3F

</td>
<td>


linux/uvcvideo.h

</td>
<td>


USB video class host driver

</td>
</tr>
<tr>
<td>


'u'

</td>
<td>


40-4f

</td>
<td>


linux/udmabuf.h

</td>
<td>


userspace dma-buf misc device

</td>
</tr>
<tr>
<td>


'v'

</td>
<td>


00-1F

</td>
<td>


linux/ext2_fs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'v'

</td>
<td>


00-1F

</td>
<td>


linux/fs.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'v'

</td>
<td>


00-0F

</td>
<td>


linux/sonypi.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'v'

</td>
<td>


00-0F

</td>
<td>


media/v4l2-subdev.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'v'

</td>
<td>


20-27

</td>
<td>


arch/powerpc/include/uapi/asm/vas-api.h

</td>
<td>


VAS API

</td>
</tr>
<tr>
<td>


'v'

</td>
<td>


C0-FF

</td>
<td>


linux/meye.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'w'

</td>
<td>


all

</td>
<td>




</td>
<td>


CERN SCI driver

</td>
</tr>
<tr>
<td>


'y'

</td>
<td>


00-1F

</td>
<td>




</td>
<td>


packet based user level communications &lt;[mailto:zapman@interlan.net](<mailto:zapman@interlan.net>)&gt;

</td>
</tr>
<tr>
<td>


'z'

</td>
<td>


00-3F

</td>
<td>




</td>
<td>


CAN bus card conflict\! &lt;[mailto:hdstich@connectu.ulm.circular.de](<mailto:hdstich@connectu.ulm.circular.de>)&gt;

</td>
</tr>
<tr>
<td>


'z'

</td>
<td>


40-7F

</td>
<td>




</td>
<td>


CAN bus card conflict\! &lt;[mailto:oe@port.de](<mailto:oe@port.de>)&gt;

</td>
</tr>
<tr>
<td>


'z'

</td>
<td>


10-4F

</td>
<td>


drivers/s390/crypto/zcrypt_api.h

</td>
<td>


conflict\!

</td>
</tr>
<tr>
<td>


'\|'

</td>
<td>


00-7F

</td>
<td>


linux/media.h

</td>
<td>




</td>
</tr>
<tr>
<td>


'\|'

</td>
<td>


80-9F

</td>
<td>


samples/

</td>
<td>


Any sample and example drivers

</td>
</tr>
<tr>
<td>


0x80

</td>
<td>


00-1F

</td>
<td>


linux/fb.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x81

</td>
<td>


00-1F

</td>
<td>


linux/vduse.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x89

</td>
<td>


00-06

</td>
<td>


arch/x86/include/asm/sockios.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x89

</td>
<td>


0B-DF

</td>
<td>


linux/sockios.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x89

</td>
<td>


E0-EF

</td>
<td>


linux/sockios.h

</td>
<td>


SIOCPROTOPRIVATE range

</td>
</tr>
<tr>
<td>


0x89

</td>
<td>


F0-FF

</td>
<td>


linux/sockios.h

</td>
<td>


SIOCDEVPRIVATE range

</td>
</tr>
<tr>
<td>


0x8A

</td>
<td>


00-1F

</td>
<td>


linux/eventpoll.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x8B

</td>
<td>


all

</td>
<td>


linux/wireless.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x8C

</td>
<td>


00-3F

</td>
<td>




</td>
<td>


WiNRADiO driver &lt;[http://www.winradio.com.au/](<http://www.winradio.com.au/>)&gt;

</td>
</tr>
<tr>
<td>


0x90

</td>
<td>


00

</td>
<td>


drivers/cdrom/sbpcd.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x92

</td>
<td>


00-0F

</td>
<td>


drivers/usb/mon/mon_bin.c

</td>
<td>




</td>
</tr>
<tr>
<td>


0x93

</td>
<td>


60-7F

</td>
<td>


linux/auto_fs.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0x94

</td>
<td>


all

</td>
<td>


fs/btrfs/ioctl.h and linux/fs.h

</td>
<td>


Btrfs filesystem some lifted to vfs/generic

</td>
</tr>
<tr>
<td>


0x97

</td>
<td>


00-7F

</td>
<td>


fs/ceph/ioctl.h

</td>
<td>


Ceph file system

</td>
</tr>
<tr>
<td>


0x99

</td>
<td>


00-0F

</td>
<td>




</td>
<td>


537-Addinboard driver &lt;[mailto:buk@buks.ipn.de](<mailto:buk@buks.ipn.de>)&gt;

</td>
</tr>
<tr>
<td>


0x9A

</td>
<td>


00-0F

</td>
<td>


include/uapi/fwctl/fwctl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xA0

</td>
<td>


all

</td>
<td>


linux/sdp/sdp.h

</td>
<td>


Industrial Device Project &lt;[mailto:kenji@bitgate.com](<mailto:kenji@bitgate.com>)&gt;

</td>
</tr>
<tr>
<td>


0xA1

</td>
<td>


0

</td>
<td>


linux/vtpm_proxy.h

</td>
<td>


TPM Emulator Proxy Driver

</td>
</tr>
<tr>
<td>


0xA2

</td>
<td>


all

</td>
<td>


uapi/linux/acrn.h

</td>
<td>


ACRN hypervisor

</td>
</tr>
<tr>
<td>


0xA3

</td>
<td>


80-8F

</td>
<td>




</td>
<td>


Port ACL  in development: &lt;[mailto:tlewis@mindspring.com](<mailto:tlewis@mindspring.com>)&gt;

</td>
</tr>
<tr>
<td>


0xA3

</td>
<td>


90-9F

</td>
<td>


linux/dtlk.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xA4

</td>
<td>


00-1F

</td>
<td>


uapi/linux/tee.h

</td>
<td>


Generic TEE subsystem

</td>
</tr>
<tr>
<td>


0xA4

</td>
<td>


00-1F

</td>
<td>


uapi/asm/sgx.h

</td>
<td>


&lt;[mailto:linux-sgx@vger.kernel.org](<mailto:linux-sgx@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


0xA5

</td>
<td>


01-05

</td>
<td>


linux/surface_aggregator/cdev.h

</td>
<td>


Microsoft Surface Platform System Aggregator &lt;[mailto:luzmaximilian@gmail.com](<mailto:luzmaximilian@gmail.com>)&gt;

</td>
</tr>
<tr>
<td>


0xA5

</td>
<td>


20-2F

</td>
<td>


linux/surface_aggregator/dtx.h

</td>
<td>


Microsoft Surface DTX driver &lt;[mailto:luzmaximilian@gmail.com](<mailto:luzmaximilian@gmail.com>)&gt;

</td>
</tr>
<tr>
<td>


0xAA

</td>
<td>


00-3F

</td>
<td>


linux/uapi/linux/userfaultfd.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xAB

</td>
<td>


00-1F

</td>
<td>


linux/nbd.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xAC

</td>
<td>


00-1F

</td>
<td>


linux/raw.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xAD

</td>
<td>


00

</td>
<td>




</td>
<td>


Netfilter device in development: &lt;[mailto:rusty@rustcorp.com.au](<mailto:rusty@rustcorp.com.au>)&gt;

</td>
</tr>
<tr>
<td>


0xAE

</td>
<td>


00-1F

</td>
<td>


linux/kvm.h

</td>
<td>


Kernel-based Virtual Machine &lt;[mailto:kvm@vger.kernel.org](<mailto:kvm@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


0xAE

</td>
<td>


40-FF

</td>
<td>


linux/kvm.h

</td>
<td>


Kernel-based Virtual Machine &lt;[mailto:kvm@vger.kernel.org](<mailto:kvm@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


0xAE

</td>
<td>


20-3F

</td>
<td>


linux/nitro_enclaves.h

</td>
<td>


Nitro Enclaves

</td>
</tr>
<tr>
<td>


0xAF

</td>
<td>


00-1F

</td>
<td>


linux/fsl_hypervisor.h

</td>
<td>


Freescale hypervisor

</td>
</tr>
<tr>
<td>


0xB0

</td>
<td>


all

</td>
<td>




</td>
<td>


RATIO devices in development: &lt;[mailto:vgo@ratio.de](<mailto:vgo@ratio.de>)&gt;

</td>
</tr>
<tr>
<td>


0xB1

</td>
<td>


00-1F

</td>
<td>




</td>
<td>


PPPoX &lt;[mailto:mostrows@styx.uwaterloo.ca](<mailto:mostrows@styx.uwaterloo.ca>)&gt;

</td>
</tr>
<tr>
<td>


0xB2

</td>
<td>


00

</td>
<td>


arch/powerpc/include/uapi/asm/papr-vpd.h

</td>
<td>


powerpc/pseries VPD API &lt;[mailto:linuxppc-dev@lists.ozlabs.org](<mailto:linuxppc-dev@lists.ozlabs.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB2

</td>
<td>


01-02

</td>
<td>


arch/powerpc/include/uapi/asm/papr-sysparm.h

</td>
<td>


powerpc/pseries system parameter API &lt;[mailto:linuxppc-dev@lists.ozlabs.org](<mailto:linuxppc-dev@lists.ozlabs.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB2

</td>
<td>


03-05

</td>
<td>


arch/powerpc/include/uapi/asm/papr-indices.h

</td>
<td>


powerpc/pseries indices API &lt;[mailto:linuxppc-dev@lists.ozlabs.org](<mailto:linuxppc-dev@lists.ozlabs.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB2

</td>
<td>


06-07

</td>
<td>


arch/powerpc/include/uapi/asm/papr-platform-dump.h

</td>
<td>


powerpc/pseries Platform Dump API &lt;[mailto:linuxppc-dev@lists.ozlabs.org](<mailto:linuxppc-dev@lists.ozlabs.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB2

</td>
<td>


08

</td>
<td>


arch/powerpc/include/uapi/asm/papr-physical-attestation.h

</td>
<td>


powerpc/pseries Physical Attestation API &lt;[mailto:linuxppc-dev@lists.ozlabs.org](<mailto:linuxppc-dev@lists.ozlabs.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB2

</td>
<td>


09

</td>
<td>


arch/powerpc/include/uapi/asm/papr-hvpipe.h

</td>
<td>


powerpc/pseries HVPIPE API &lt;[mailto:linuxppc-dev@lists.ozlabs.org](<mailto:linuxppc-dev@lists.ozlabs.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB3

</td>
<td>


00

</td>
<td>


linux/mmc/ioctl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xB4

</td>
<td>


00-0F

</td>
<td>


linux/gpio.h

</td>
<td>


&lt;[mailto:linux-gpio@vger.kernel.org](<mailto:linux-gpio@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB5

</td>
<td>


00-0F

</td>
<td>


uapi/linux/rpmsg.h

</td>
<td>


&lt;[mailto:linux-remoteproc@vger.kernel.org](<mailto:linux-remoteproc@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB6

</td>
<td>


all

</td>
<td>


linux/fpga-dfl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xB7

</td>
<td>


all

</td>
<td>


uapi/linux/remoteproc_cdev.h

</td>
<td>


&lt;[mailto:linux-remoteproc@vger.kernel.org](<mailto:linux-remoteproc@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


0xB7

</td>
<td>


all

</td>
<td>


uapi/linux/nsfs.h

</td>
<td>


&lt;[mailto:Andrei](<mailto:Andrei>) Vagin &lt;[avagin@openvz.org](<mailto:avagin@openvz.org>)&gt;&gt;

</td>
</tr>
<tr>
<td>


0xB8

</td>
<td>


01-02

</td>
<td>


uapi/misc/mrvl_cn10k_dpi.h

</td>
<td>


Marvell CN10K DPI driver

</td>
</tr>
<tr>
<td>


0xB8

</td>
<td>


all

</td>
<td>


uapi/linux/mshv.h

</td>
<td>


Microsoft Hyper-V /dev/mshv driver &lt;[mailto:linux-hyperv@vger.kernel.org](<mailto:linux-hyperv@vger.kernel.org>)&gt;

</td>
</tr>
<tr>
<td>


0xBA

</td>
<td>


00-0F

</td>
<td>


uapi/linux/liveupdate.h

</td>
<td>


Pasha Tatashin &lt;[mailto:pasha.tatashin@soleen.com](<mailto:pasha.tatashin@soleen.com>)&gt;

</td>
</tr>
<tr>
<td>


0xC0

</td>
<td>


00-0F

</td>
<td>


linux/usb/iowarrior.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xCA

</td>
<td>


00-0F

</td>
<td>


uapi/misc/cxl.h

</td>
<td>


Dead since 6.15

</td>
</tr>
<tr>
<td>


0xCA

</td>
<td>


10-2F

</td>
<td>


uapi/misc/ocxl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xCA

</td>
<td>


80-BF

</td>
<td>


uapi/scsi/cxlflash_ioctl.h

</td>
<td>


Dead since 6.15

</td>
</tr>
<tr>
<td>


0xCB

</td>
<td>


00-1F

</td>
<td>




</td>
<td>


CBM serial IEC bus in development: &lt;[mailto:michael.klein@puffin.lb.shuttle.de](<mailto:michael.klein@puffin.lb.shuttle.de>)&gt;

</td>
</tr>
<tr>
<td>


0xCC

</td>
<td>


00-0F

</td>
<td>


drivers/misc/ibmvmc.h

</td>
<td>


pseries VMC driver

</td>
</tr>
<tr>
<td>


0xCD

</td>
<td>


01

</td>
<td>


linux/reiserfs_fs.h

</td>
<td>


Dead since 6.13

</td>
</tr>
<tr>
<td>


0xCE

</td>
<td>


01-02

</td>
<td>


uapi/linux/cxl_mem.h

</td>
<td>


Compute Express Link Memory Devices

</td>
</tr>
<tr>
<td>


0xCF

</td>
<td>


02

</td>
<td>


fs/smb/client/cifs_ioctl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xDD

</td>
<td>


00-3F

</td>
<td>




</td>
<td>


ZFCP device driver see drivers/s390/scsi/ &lt;[mailto:aherrman@de.ibm.com](<mailto:aherrman@de.ibm.com>)&gt;

</td>
</tr>
<tr>
<td>


0xE5

</td>
<td>


00-3F

</td>
<td>


linux/fuse.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xEC

</td>
<td>


00-01

</td>
<td>


drivers/platform/chrome/cros_ec_dev.h

</td>
<td>


ChromeOS EC driver

</td>
</tr>
<tr>
<td>


0xEE

</td>
<td>


00-09

</td>
<td>


uapi/linux/pfrut.h

</td>
<td>


Platform Firmware Runtime Update and Telemetry

</td>
</tr>
<tr>
<td>


0xF3

</td>
<td>


00-3F

</td>
<td>


drivers/usb/misc/sisusbvga/sisusb.h

</td>
<td>


sisfb (in development) &lt;[mailto:thomas@winischhofer.net](<mailto:thomas@winischhofer.net>)&gt;

</td>
</tr>
<tr>
<td>


0xF6

</td>
<td>


all

</td>
<td>




</td>
<td>


LTTng Linux Trace Toolkit Next Generation &lt;[mailto:mathieu.desnoyers@efficios.com](<mailto:mathieu.desnoyers@efficios.com>)&gt;

</td>
</tr>
<tr>
<td>


0xF8

</td>
<td>


all

</td>
<td>


arch/x86/include/uapi/asm/amd_hsmp.h

</td>
<td>


AMD HSMP EPYC system management interface driver &lt;[mailto:nchatrad@amd.com](<mailto:nchatrad@amd.com>)&gt;

</td>
</tr>
<tr>
<td>


0xF9

</td>
<td>


00-0F

</td>
<td>


uapi/misc/amd-apml.h

</td>
<td>


AMD side band system management interface driver &lt;[mailto:naveenkrishna.chatradhi@amd.com](<mailto:naveenkrishna.chatradhi@amd.com>)&gt;

</td>
</tr>
<tr>
<td>


0xFD

</td>
<td>


all

</td>
<td>


linux/dm-ioctl.h

</td>
<td>




</td>
</tr>
<tr>
<td>


0xFE

</td>
<td>


all

</td>
<td>


linux/isst_if.h

</td>
<td>




</td>
</tr>
</tbody>
</table>

---

# Netlink Handbook

_Peios Kernel / Userspace interfaces / System and device interfaces / Netlink_

> Netlink documentation for users.

<a id="rst-netlink-handbook"></a>

<!-- SPDX-License-Identifier: BSD-3-Clause -->

Netlink documentation for users.

- [Introduction to Netlink](</kernel/userspace/userspace-api/netlink/intro.md>)
- [Using Netlink protocol specifications](</kernel/userspace/userspace-api/netlink/intro-specs.md>)
- [Netlink protocol specifications (in YAML)](</kernel/userspace/userspace-api/netlink/specs.md>)
- [Netlink spec C code generation](</kernel/userspace/userspace-api/netlink/c-code-gen.md>)
- [Netlink specification support for legacy Generic Netlink families](</kernel/userspace/userspace-api/netlink/genetlink-legacy.md>)
- [Netlink specification support for raw Netlink families](</kernel/userspace/userspace-api/netlink/netlink-raw.md>)

- **See also:**

  - [Documentation/core-api/netlink.rst](</kernel/internals/core-api/netlink.md#rst-kernel-netlink>)

  - [Documentation/netlink/specs/index.rst](</kernel/internals/netlink/specs/index.md#rst-specs>)

---

# Netlink spec C code generation

_Peios Kernel / Userspace interfaces / System and device interfaces / Netlink_

> This document describes how Netlink specifications are used to render C code (uAPI, policies etc.). It also defines the additional properties allowed in older families by the genetlink-c protocol level, to control the naming.

<a id="rst-netlink-spec-c-code-generation"></a>

<!-- SPDX-License-Identifier: BSD-3-Clause -->

This document describes how Netlink specifications are used to render C code (uAPI, policies etc.). It also defines the additional properties allowed in older families by the `genetlink-c` protocol level, to control the naming.

For brevity this document refers to `name` properties of various objects by the object type. For example `$attr` is the value of `name` in an attribute, and `$family` is the name of the family (the global `name` property).

The upper case is used to denote literal values, e.g. `$family-CMD` means the concatenation of `$family`, a dash character, and the literal `CMD`.

The names of `#defines` and enum values are always converted to upper case, and with dashes (`-`) replaced by underscores (`_`).

If the constructed name is a C keyword, an extra underscore is appended (`do` -&gt; `do_`).

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

## Globals

`c-family-name` controls the name of the `#define` for the family name, default is `$family-FAMILY-NAME`.

`c-version-name` controls the name of the `#define` for the version of the family, default is `$family-FAMILY-VERSION`.

`max-by-define` selects if max values for enums are defined as a `#define` rather than inside the enum.

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

## Definitions

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

### Constants

Every constant is rendered as a `#define`. The name of the constant is `$family-$constant` and the value is rendered as a string or integer according to its type in the spec.

<a id="rst-enums-and-flags"></a>

### Enums and flags

Enums are named `$family-$enum`. The full name can be set directly or suppressed by specifying the `enum-name` property. Default entry name is `$family-$enum-$entry`. If `name-prefix` is specified it replaces the `$family-$enum` portion of the entry name.

Boolean `render-max` controls creation of the max values (which are enabled by default for attribute enums). These max values are named `__$pfx-MAX` and `$pfx-MAX`. The name of the first value can be overridden via `enum-cnt-name` property.

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

## Attributes

Each attribute set (excluding fractional sets) is rendered as an enum.

Attribute enums are traditionally unnamed in netlink headers. If naming is desired `enum-name` can be used to specify the name.

The default attribute name prefix is `$family-A` if the name of the set is the same as the name of the family and `$family-A-$set` if the names differ. The prefix can be overridden by the `name-prefix` property of a set. The rest of the section will refer to the prefix as `$pfx`.

Attributes are named `$pfx-$attribute`.

Attribute enums end with two special values `__$pfx-MAX` and `$pfx-MAX` which are used for sizing attribute tables. These two names can be specified directly with the `attr-cnt-name` and `attr-max-name` properties respectively.

If `max-by-define` is set to `true` at the global level `attr-max-name` will be specified as a `#define` rather than an enum value.

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

## Operations

Operations are named `$family-CMD-$operation`. If `name-prefix` is specified it replaces the `$family-CMD` portion of the name.

Similarly to attribute enums operation enums end with special count and max attributes. For operations those attributes can be renamed with `cmd-cnt-name` and `cmd-max-name`. Max will be a define if `max-by-define` is `true`.

<a id="rst-multicast-groups"></a>

## Multicast groups

Each multicast group gets a define rendered into the kernel uAPI header. The name of the define is `$family-MCGRP-$group`, and can be overwritten with the `c-define-name` property.

<a id="rst-code-generation"></a>

## Code generation

uAPI header is assumed to come from `<linux/$family.h>` in the default header search path. It can be changed using the `uapi-header` global property.

---

# Netlink specification support for legacy Generic Netlink families

_Peios Kernel / Userspace interfaces / System and device interfaces / Netlink_

> This document describes the many additional quirks and properties required to describe older Generic Netlink families which form the genetlink-legacy protocol level.

<a id="rst-netlink-specification-support-for-legacy-generic-netlink-families"></a>

<!-- SPDX-License-Identifier: BSD-3-Clause -->

This document describes the many additional quirks and properties required to describe older Generic Netlink families which form the `genetlink-legacy` protocol level.

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

## Specification

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

### Globals

Attributes listed directly at the root level of the spec file.

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

#### version

Generic Netlink family version, default is 1.

`version` has historically been used to introduce family changes which may break backwards compatibility. Since compatibility breaking changes are generally not allowed `version` is very rarely used.

<a id="rst-attribute-type-nests"></a>

### Attribute type nests

New Netlink families should use `multi-attr` to define arrays. Older families (e.g. `genetlink` control family) attempted to define array types reusing attribute type to carry information.

For reference the `multi-attr` array may look like this:



```text
[ARRAY-ATTR]
  [INDEX (optionally)]
  [MEMBER1]
  [MEMBER2]
[SOME-OTHER-ATTR]
[ARRAY-ATTR]
  [INDEX (optionally)]
  [MEMBER1]
  [MEMBER2]
```

where `ARRAY-ATTR` is the array entry type.

<a id="rst-indexed-array"></a>

#### indexed-array

`indexed-array` wraps the entire array in an extra attribute (hence limiting its size to 64kB). The `ENTRY` nests are special and have the index of the entry as their type instead of normal attribute type.

A `sub-type` is needed to describe what type in the `ENTRY`. A `nest` `sub-type` means there are nest arrays in the `ENTRY`, with the structure looks like:



```text
[SOME-OTHER-ATTR]
[ARRAY-ATTR]
  [ENTRY]
    [MEMBER1]
    [MEMBER2]
  [ENTRY]
    [MEMBER1]
    [MEMBER2]
```

Other `sub-type` like `u32` means there is only one member as described in `sub-type` in the `ENTRY`. The structure looks like:



```text
[SOME-OTHER-ATTR]
[ARRAY-ATTR]
  [ENTRY u32]
  [ENTRY u32]
```

<a id="rst-type-value"></a>

#### type-value

`type-value` is a construct which uses attribute types to carry information about a single object (often used when array is dumped entry-by-entry).

`type-value` can have multiple levels of nesting, for example genetlink's policy dumps create the following structures:



```text
[POLICY-IDX]
  [ATTR-IDX]
    [POLICY-INFO-ATTR1]
    [POLICY-INFO-ATTR2]
```

Where the first level of nest has the policy index as it's attribute type, it contains a single nest which has the attribute index as its type. Inside the attr-index nest are the policy attributes. Modern Netlink families should have instead defined this as a flat structure, the nesting serves no good purpose here.

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

## Operations

<a id="rst-enum-message-id-model"></a>

### Enum (message ID) model

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

#### unified

Modern families use the `unified` message ID model, which uses a single enumeration for all messages within family. Requests and responses share the same message ID. Notifications have separate IDs from the same space. For example given the following list of operations:



```yaml
-
  name: a
  value: 1
  do: ...
-
  name: b
  do: ...
-
  name: c
  value: 4
  notify: a
-
  name: d
  do: ...
```

Requests and responses for operation `a` will have the ID of 1, the requests and responses of `b` - 2 (since there is no explicit `value` it's previous operation `+ 1`). Notification `c` will use the ID of 4, operation `d` 5 etc.

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

#### directional

The `directional` model splits the ID assignment by the direction of the message. Messages from and to the kernel can't be confused with each other so this conserves the ID space (at the cost of making the programming more cumbersome).

In this case `value` attribute should be specified in the `request` `reply` sections of the operations (if an operation has both `do` and `dump` the IDs are shared, `value` should be set in `do`). For notifications the `value` is provided at the op level but it only allocates a `reply` (i.e. a "from-kernel" ID). Let's look at an example:



```yaml
-
  name: a
  do:
    request:
      value: 2
      attributes: ...
    reply:
      value: 1
      attributes: ...
-
  name: b
  notify: a
-
  name: c
  notify: a
  value: 7
-
  name: d
  do: ...
```

In this case `a` will use 2 when sending the message to the kernel and expects message with ID 1 in response. Notification `b` allocates a "from-kernel" ID which is 2. `c` allocates "from-kernel" ID of 7. If operation `d` does not set `values` explicitly in the spec it will be allocated 3 for the request (`a` is the previous operation with a request section and the value of 2) and 8 for response (`c` is the previous operation in the "from-kernel" direction).

<a id="rst-other-quirks"></a>

## Other quirks

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

### Structures

Legacy families can define C structures both to be used as the contents of an attribute and as a fixed message header. Structures are defined in `definitions`  and referenced in operations or attributes.

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

#### members

> - `name` - The attribute name of the struct member
>
> - `type` - One of the scalar types `u8`, `u16`, `u32`, `u64`, `s8`, `s16`, `s32`, `s64`, `string`, `binary` or `bitfield32`.
>
> - `byte-order` - `big-endian` or `little-endian`
>
> - `doc`, `enum`, `enum-as-flags`, `display-hint` - Same as for [attribute definitions](</kernel/userspace/userspace-api/netlink/specs.md#rst-attribute-properties>)

Note that structures defined in YAML are implicitly packed according to C conventions. For example, the following struct is 4 bytes, not 6 bytes:



```c
struct {
        u8 a;
        u16 b;
        u8 c;
}
```

Any padding must be explicitly added and C-like languages should infer the need for explicit padding from whether the members are naturally aligned.

Here is the struct definition from above, declared in YAML:



```yaml
definitions:
  -
    name: message-header
    type: struct
    members:
      -
        name: a
        type: u8
      -
        name: b
        type: u16
      -
        name: c
        type: u8
```

<a id="rst-fixed-headers"></a>

#### Fixed Headers

Fixed message headers can be added to operations using `fixed-header`. The default `fixed-header` can be set in `operations` and it can be set or overridden for each operation.



```yaml
operations:
  fixed-header: message-header
  list:
    -
      name: get
      fixed-header: custom-header
      attribute-set: message-attrs
```

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

#### Attributes

A `binary` attribute can be interpreted as a C structure using a `struct` property with the name of the structure definition. The `struct` property implies `sub-type: struct` so it is not necessary to specify a sub-type.



```yaml
attribute-sets:
  -
    name: stats-attrs
    attributes:
      -
        name: stats
        type: binary
        struct: vport-stats
```

<a id="rst-c-arrays"></a>

### C Arrays

Legacy families also use `binary` attributes to encapsulate C arrays. The `sub-type` is used to identify the type of scalar to extract.



```yaml
attributes:
  -
    name: ports
    type: binary
    sub-type: u32
```

<a id="rst-multi-message-do"></a>

### Multi-message DO

New Netlink families should never respond to a DO operation with multiple replies, with `NLM_F_MULTI` set. Use a filtered dump instead.

At the spec level we can define a `dumps` property for the `do`, perhaps with values of `combine` and `multi-object` depending on how the parsing should be implemented (parse into a single reply vs list of objects i.e. pretty much a dump).

---

# Using Netlink protocol specifications

_Peios Kernel / Userspace interfaces / System and device interfaces / Netlink_

> This document is a quick starting guide for using Netlink protocol specifications. For more detailed description of the specs see specs.

<a id="rst-using-netlink-protocol-specifications"></a>

<!-- SPDX-License-Identifier: BSD-3-Clause -->

This document is a quick starting guide for using Netlink protocol specifications. For more detailed description of the specs see [Netlink protocol specifications (in YAML)](</kernel/userspace/userspace-api/netlink/specs.md>).

<a id="rst-simple-cli"></a>

## Simple CLI

Kernel comes with a simple CLI tool which should be useful when developing Netlink related code. The tool is implemented in Python and can use a YAML specification to issue Netlink requests to the kernel.

The tool is located at `tools/net/ynl/pyynl/cli.py`. It accepts a handful of arguments, the most important ones are:

> - `--spec` - point to the spec file
>
> - `--do $name` / `--dump $name` - issue request `$name`
>
> - `--json $attrs` - provide attributes for the request
>
> - `--subscribe $group` - receive notifications from `$group`

YAML specs can be found under `Documentation/netlink/specs/`.

Example use:



```text
$ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/ethtool.yaml \
      --do rings-get \
      --json '{"header":{"dev-index": 18}}'
{'header': {'dev-index': 18, 'dev-name': 'eni1np1'},
 'rx': 0,
 'rx-jumbo': 0,
 'rx-jumbo-max': 4096,
 'rx-max': 4096,
 'rx-mini': 0,
 'rx-mini-max': 4096,
 'tx': 0,
 'tx-max': 4096,
 'tx-push': 0}
```

The input arguments are parsed as JSON, while the output is only Python-pretty-printed. This is because some Netlink types can't be expressed as JSON directly. If such attributes are needed in the input some hacking of the script will be necessary.

The spec and Netlink internals are factored out as a standalone library - it should be easy to write Python tools / tests reusing code from `cli.py`.

<a id="rst-generating-kernel-code"></a>

## Generating kernel code

`tools/net/ynl/ynl-regen.sh` scans the kernel tree in search of auto-generated files which need to be updated. Using this tool is the easiest way to generate / update auto-generated code.

By default code is re-generated only if spec is newer than the source, to force regeneration use `-f`.

`ynl-regen.sh` searches for `YNL-GEN` in the contents of files (note that it only scans files in the git index, that is only files tracked by git\!) For instance the `fou_nl.c` kernel source contains:



```text
/*    Documentation/netlink/specs/fou.yaml */
/* YNL-GEN kernel source */
```

`ynl-regen.sh` will find this marker and replace the file with kernel source based on fou.yaml.

The simplest way to generate a new file based on a spec is to add the two marker lines like above to a file, add that file to git, and run the regeneration tool. Grep the tree for `YNL-GEN` to see other examples.

The code generation itself is performed by `tools/net/ynl/pyynl/ynl_gen_c.py` but it takes a few arguments so calling it directly for each file quickly becomes tedious.

<a id="rst-ynl-lib"></a>

## YNL lib

`tools/net/ynl/lib/` contains an implementation of a C library (based on libmnl) which integrates with code generated by `tools/net/ynl/pyynl/ynl_gen_c.py` to create easy to use netlink wrappers.

<a id="rst-ynl-basics"></a>

### YNL basics

The YNL library consists of two parts - the generic code (functions prefix by `ynl_`) and per-family auto-generated code (prefixed with the name of the family).

To create a YNL socket call ynl_sock_create() passing the family struct (family structs are exported by the auto-generated code). ynl_sock_destroy() closes the socket.

<a id="rst-ynl-requests"></a>

### YNL requests

Steps for issuing YNL requests are best explained on an example. All the functions and types in this example come from the auto-generated code (for the netdev family in this case):



```c
// 0. Request and response pointers
struct netdev_dev_get_req *req;
struct netdev_dev_get_rsp *d;

// 1. Allocate a request
req = netdev_dev_get_req_alloc();
// 2. Set request parameters (as needed)
netdev_dev_get_req_set_ifindex(req, ifindex);

// 3. Issues the request
d = netdev_dev_get(ys, req);
// 4. Free the request arguments
netdev_dev_get_req_free(req);
// 5. Error check (the return value from step 3)
if (!d) {
     // 6. Print the YNL-generated error
     fprintf(stderr, "YNL: %s\n", ys->err.msg);
     return -1;
}

// ... do stuff with the response @d

// 7. Free response
netdev_dev_get_rsp_free(d);
```

<a id="rst-ynl-dumps"></a>

### YNL dumps

Performing dumps follows similar pattern as requests. Dumps return a list of objects terminated by a special marker, or NULL on error. Use `ynl_dump_foreach()` to iterate over the result.

<a id="rst-ynl-notifications"></a>

### YNL notifications

YNL lib supports using the same socket for notifications and requests. In case notifications arrive during processing of a request they are queued internally and can be retrieved at a later time.

To subscribed to notifications use `ynl_subscribe()`. The notifications have to be read out from the socket, `ynl_socket_get_fd()` returns the underlying socket fd which can be plugged into appropriate asynchronous IO API like `poll`, or `select`.

Notifications can be retrieved using `ynl_ntf_dequeue()` and have to be freed using `ynl_ntf_free()`. Since we don't know the notification type upfront the notifications are returned as `struct ynl_ntf_base_type *` and user is expected to cast them to the appropriate full type based on the `cmd` member.

---

# Introduction to Netlink

_Peios Kernel / Userspace interfaces / System and device interfaces / Netlink_

> Netlink is often described as an ioctl() replacement. It aims to replace fixed-format C structures as supplied to ioctl() with a format which allows an easy way to add or extended the arguments.

<a id="rst-introduction-to-netlink"></a>

<!-- SPDX-License-Identifier: BSD-3-Clause -->

Netlink is often described as an ioctl() replacement. It aims to replace fixed-format C structures as supplied to ioctl() with a format which allows an easy way to add or extended the arguments.

To achieve this Netlink uses a minimal fixed-format metadata header followed by multiple attributes in the TLV (type, length, value) format.

Unfortunately the protocol has evolved over the years, in an organic and undocumented fashion, making it hard to coherently explain. To make the most practical sense this document starts by describing netlink as it is used today and dives into more "historical" uses in later sections.

<a id="rst-opening-a-socket"></a>

## Opening a socket

Netlink communication happens over sockets, a socket needs to be opened first:



```c
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
```

The use of sockets allows for a natural way of exchanging information in both directions (to and from the kernel). The operations are still performed synchronously when applications send() the request but a separate recv() system call is needed to read the reply.

A very simplified flow of a Netlink "call" will therefore look something like:



```c
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);

/* format the request */
send(fd, &request, sizeof(request));
n = recv(fd, &response, RSP_BUFFER_SIZE);
/* interpret the response */
```

Netlink also provides natural support for "dumping", i.e. communicating to user space all objects of a certain type (e.g. dumping all network interfaces).



```c
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);

/* format the dump request */
send(fd, &request, sizeof(request));
while (1) {
  n = recv(fd, &buffer, RSP_BUFFER_SIZE);
  /* one recv() call can read multiple messages, hence the loop below */
  for (nl_msg in buffer) {
    if (nl_msg.nlmsg_type == NLMSG_DONE)
      goto dump_finished;
    /* process the object */
  }
}
dump_finished:
```

The first two arguments of the socket() call require little explanation - it is opening a Netlink socket, with all headers provided by the user (hence NETLINK, RAW). The last argument is the protocol within Netlink. This field used to identify the subsystem with which the socket will communicate.

<a id="rst-classic-vs-generic-netlink"></a>

### Classic vs Generic Netlink

Initial implementation of Netlink depended on a static allocation of IDs to subsystems and provided little supporting infrastructure. Let us refer to those protocols collectively as **Classic Netlink**. The list of them is defined on top of the `include/uapi/linux/netlink.h` file, they include among others - general networking (NETLINK_ROUTE), iSCSI (NETLINK_ISCSI), and audit (NETLINK_AUDIT).

**Generic Netlink** (introduced in 2005) allows for dynamic registration of subsystems (and subsystem ID allocation), introspection and simplifies implementing the kernel side of the interface.

The following section describes how to use Generic Netlink, as the number of subsystems using Generic Netlink outnumbers the older protocols by an order of magnitude. There are also no plans for adding more Classic Netlink protocols to the kernel. Basic information on how communicating with core networking parts of the Linux kernel (or another of the 20 subsystems using Classic Netlink) differs from Generic Netlink is provided later in this document.

<a id="rst-generic-netlink"></a>

## Generic Netlink

In addition to the Netlink fixed metadata header each Netlink protocol defines its own fixed metadata header. (Similarly to how network headers stack - Ethernet &gt; IP &gt; TCP we have Netlink &gt; Generic N. &gt; Family.)

A Netlink message always starts with struct nlmsghdr, which is followed by a protocol-specific header. In case of Generic Netlink the protocol header is struct genlmsghdr.

The practical meaning of the fields in case of Generic Netlink is as follows:



```c
struct nlmsghdr {
      __u32   nlmsg_len;      /* Length of message including headers */
      __u16   nlmsg_type;     /* Generic Netlink Family (subsystem) ID */
      __u16   nlmsg_flags;    /* Flags - request or dump */
      __u32   nlmsg_seq;      /* Sequence number */
      __u32   nlmsg_pid;      /* Port ID, set to 0 */
};
struct genlmsghdr {
      __u8    cmd;            /* Command, as defined by the Family */
      __u8    version;        /* Irrelevant, set to 1 */
      __u16   reserved;       /* Reserved, set to 0 */
};
/* TLV attributes follow... */
```

In Classic Netlink `nlmsghdr.nlmsg_type` used to identify which operation within the subsystem the message was referring to (e.g. get information about a netdev). Generic Netlink needs to mux multiple subsystems in a single protocol so it uses this field to identify the subsystem, and `genlmsghdr.cmd` identifies the operation instead. (See [Resolving the Family ID](<#rst-res-fam>) for information on how to find the Family ID of the subsystem of interest.) Note that the first 16 values (0 - 15) of this field are reserved for control messages both in Classic Netlink and Generic Netlink. See [Netlink message types](<#rst-nl-msg-type>) for more details.

There are 3 usual types of message exchanges on a Netlink socket:

> - performing a single action (`do`);
>
> - dumping information (`dump`);
>
> - getting asynchronous notifications (`multicast`).

Classic Netlink is very flexible and presumably allows other types of exchanges to happen, but in practice those are the three that get used.

Asynchronous notifications are sent by the kernel and received by the user sockets which subscribed to them. `do` and `dump` requests are initiated by the user. `nlmsghdr.nlmsg_flags` should be set as follows:

> - for `do`: `NLM_F_REQUEST | NLM_F_ACK`
>
> - for `dump`: `NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP`

`nlmsghdr.nlmsg_seq` should be a set to a monotonically increasing value. The value gets echoed back in responses and doesn't matter in practice, but setting it to an increasing value for each message sent is considered good hygiene. The purpose of the field is matching responses to requests. Asynchronous notifications will have `nlmsghdr.nlmsg_seq` of `0`.

`nlmsghdr.nlmsg_pid` is the Netlink equivalent of an address. This field can be set to `0` when talking to the kernel. See [nlmsg_pid](<#rst-nlmsg-pid-1>) for the (uncommon) uses of the field.

The expected use for `genlmsghdr.version` was to allow versioning of the APIs provided by the subsystems. No subsystem to date made significant use of this field, so setting it to `1` seems like a safe bet.

<a id="rst-netlink-message-types"></a>
<a id="rst-nl-msg-type"></a>

### Netlink message types

As previously mentioned `nlmsghdr.nlmsg_type` carries protocol specific values but the first 16 identifiers are reserved (first subsystem specific message type should be equal to `NLMSG_MIN_TYPE` which is `0x10`).

There are only 4 Netlink control messages defined:

> - `NLMSG_NOOP` - ignore the message, not used in practice;
>
> - `NLMSG_ERROR` - carries the return code of an operation;
>
> - `NLMSG_DONE` - marks the end of a dump;
>
> - `NLMSG_OVERRUN` - socket buffer has overflown, not used to date.

`NLMSG_ERROR` and `NLMSG_DONE` are of practical importance. They carry return codes for operations. Note that unless the `NLM_F_ACK` flag is set on the request Netlink will not respond with `NLMSG_ERROR` if there is no error. To avoid having to special-case this quirk it is recommended to always set `NLM_F_ACK`.

The format of `NLMSG_ERROR` is described by struct nlmsgerr:



```text
----------------------------------------------
| struct nlmsghdr - response header          |
----------------------------------------------
|    int error                               |
----------------------------------------------
| struct nlmsghdr - original request header |
----------------------------------------------
| ** optionally (1) payload of the request   |
----------------------------------------------
| ** optionally (2) extended ACK             |
----------------------------------------------
```

There are two instances of struct nlmsghdr here, first of the response and second of the request. `NLMSG_ERROR` carries the information about the request which led to the error. This could be useful when trying to match requests to responses or re-parse the request to dump it into logs.

The payload of the request is not echoed in messages reporting success (`error == 0`) or if `NETLINK_CAP_ACK` setsockopt() was set. The latter is common and perhaps recommended as having to read a copy of every request back from the kernel is rather wasteful. The absence of request payload is indicated by `NLM_F_CAPPED` in `nlmsghdr.nlmsg_flags`.

The second optional element of `NLMSG_ERROR` are the extended ACK attributes. See [Extended ACK](<#rst-ext-ack>) for more details. The presence of extended ACK is indicated by `NLM_F_ACK_TLVS` in `nlmsghdr.nlmsg_flags`.

`NLMSG_DONE` is simpler, the request is never echoed but the extended ACK attributes may be present:



```text
----------------------------------------------
| struct nlmsghdr - response header          |
----------------------------------------------
|    int error                               |
----------------------------------------------
| ** optionally extended ACK                 |
----------------------------------------------
```

Note that some implementations may issue custom `NLMSG_DONE` messages in reply to `do` action requests. In that case the payload is implementation-specific and may also be absent.

<a id="rst-resolving-the-family-id"></a>
<a id="rst-res-fam"></a>

### Resolving the Family ID

This section explains how to find the Family ID of a subsystem. It also serves as an example of Generic Netlink communication.

Generic Netlink is itself a subsystem exposed via the Generic Netlink API. To avoid a circular dependency Generic Netlink has a statically allocated Family ID (`GENL_ID_CTRL` which is equal to `NLMSG_MIN_TYPE`). The Generic Netlink family implements a command used to find out information about other families (`CTRL_CMD_GETFAMILY`).

To get information about the Generic Netlink family named for example `"test1"` we need to send a message on the previously opened Generic Netlink socket. The message should target the Generic Netlink Family (1), be a `do` (2) call to `CTRL_CMD_GETFAMILY` (3). A `dump` version of this call would make the kernel respond with information about *all* the families it knows about. Last but not least the name of the family in question has to be specified (4) as an attribute with the appropriate type:



```text
struct nlmsghdr:
  __u32 nlmsg_len:    32
  __u16 nlmsg_type:   GENL_ID_CTRL               // (1)
  __u16 nlmsg_flags:  NLM_F_REQUEST | NLM_F_ACK  // (2)
  __u32 nlmsg_seq:    1
  __u32 nlmsg_pid:    0

struct genlmsghdr:
  __u8 cmd:           CTRL_CMD_GETFAMILY         // (3)
  __u8 version:       2 /* or 1, doesn't matter */
  __u16 reserved:     0

struct nlattr:                                   // (4)
  __u16 nla_len:      10
  __u16 nla_type:     CTRL_ATTR_FAMILY_NAME
  char data:          test1\0

(padding:)
  char data:          \0\0
```

The length fields in Netlink (`nlmsghdr.nlmsg_len` and `nlattr.nla_len`) always *include* the header. Attribute headers in netlink must be aligned to 4 bytes from the start of the message, hence the extra `\0\0` after `CTRL_ATTR_FAMILY_NAME`. The attribute lengths *exclude* the padding.

If the family is found kernel will reply with two messages, the response with all the information about the family:



```text
/* Message #1 - reply */
struct nlmsghdr:
  __u32 nlmsg_len:    136
  __u16 nlmsg_type:   GENL_ID_CTRL
  __u16 nlmsg_flags:  0
  __u32 nlmsg_seq:    1    /* echoed from our request */
  __u32 nlmsg_pid:    5831 /* The PID of our user space process */

struct genlmsghdr:
  __u8 cmd:           CTRL_CMD_GETFAMILY
  __u8 version:       2
  __u16 reserved:     0

struct nlattr:
  __u16 nla_len:      10
  __u16 nla_type:     CTRL_ATTR_FAMILY_NAME
  char data:          test1\0

(padding:)
  data:               \0\0

struct nlattr:
  __u16 nla_len:      6
  __u16 nla_type:     CTRL_ATTR_FAMILY_ID
  __u16:              123  /* The Family ID we are after */

(padding:)
  char data:          \0\0

struct nlattr:
  __u16 nla_len:      9
  __u16 nla_type:     CTRL_ATTR_FAMILY_VERSION
  __u16:              1

/* ... etc, more attributes will follow. */
```

And the error code (success) since `NLM_F_ACK` had been set on the request:



```text
/* Message #2 - the ACK */
struct nlmsghdr:
  __u32 nlmsg_len:    36
  __u16 nlmsg_type:   NLMSG_ERROR
  __u16 nlmsg_flags:  NLM_F_CAPPED /* There won't be a payload */
  __u32 nlmsg_seq:    1    /* echoed from our request */
  __u32 nlmsg_pid:    5831 /* The PID of our user space process */

int error:            0

struct nlmsghdr: /* Copy of the request header as we sent it */
  __u32 nlmsg_len:    32
  __u16 nlmsg_type:   GENL_ID_CTRL
  __u16 nlmsg_flags:  NLM_F_REQUEST | NLM_F_ACK
  __u32 nlmsg_seq:    1
  __u32 nlmsg_pid:    0
```

The order of attributes (struct nlattr) is not guaranteed so the user has to walk the attributes and parse them.

Note that Generic Netlink sockets are not associated or bound to a single family. A socket can be used to exchange messages with many different families, selecting the recipient family on message-by-message basis using the `nlmsghdr.nlmsg_type` field.

<a id="rst-extended-ack"></a>
<a id="rst-ext-ack"></a>

### Extended ACK

Extended ACK controls reporting of additional error/warning TLVs in `NLMSG_ERROR` and `NLMSG_DONE` messages. To maintain backward compatibility this feature has to be explicitly enabled by setting the `NETLINK_EXT_ACK` setsockopt() to `1`.

Types of extended ack attributes are defined in enum nlmsgerr_attrs. The most commonly used attributes are `NLMSGERR_ATTR_MSG`, `NLMSGERR_ATTR_OFFS` and `NLMSGERR_ATTR_MISS_*`.

`NLMSGERR_ATTR_MSG` carries a message in English describing the encountered problem. These messages are far more detailed than what can be expressed thru standard UNIX error codes.

`NLMSGERR_ATTR_OFFS` points to the attribute which caused the problem.

`NLMSGERR_ATTR_MISS_TYPE` and `NLMSGERR_ATTR_MISS_NEST` inform about a missing attribute.

Extended ACKs can be reported on errors as well as in case of success. The latter should be treated as a warning.

Extended ACKs greatly improve the usability of Netlink and should always be enabled, appropriately parsed and reported to the user.

<a id="rst-advanced-topics"></a>

## Advanced topics

<a id="rst-dump-consistency"></a>

### Dump consistency

Some of the data structures kernel uses for storing objects make it hard to provide an atomic snapshot of all the objects in a dump (without impacting the fast-paths updating them).

Kernel may set the `NLM_F_DUMP_INTR` flag on any message in a dump (including the `NLMSG_DONE` message) if the dump was interrupted and may be inconsistent (e.g. missing objects). User space should retry the dump if it sees the flag set.

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

### Introspection

The basic introspection abilities are enabled by access to the Family object as reported in [Resolving the Family ID](<#rst-res-fam>). User can query information about the Generic Netlink family, including which operations are supported by the kernel and what attributes the kernel understands. Family information includes the highest ID of an attribute kernel can parse, a separate command (`CTRL_CMD_GETPOLICY`) provides detailed information about supported attributes, including ranges of values the kernel accepts.

Querying family information is useful in cases when user space needs to make sure that the kernel has support for a feature before issuing a request.

<a id="rst-nlmsg-pid-1"></a>
<a id="rst-nlmsg-pid"></a>

### nlmsg_pid

`nlmsghdr.nlmsg_pid` is the Netlink equivalent of an address. It is referred to as Port ID, sometimes Process ID because for historical reasons if the application does not select (bind() to) an explicit Port ID kernel will automatically assign it the ID equal to its Process ID (as reported by the getpid() system call).

Similarly to the bind() semantics of the TCP/IP network protocols the value of zero means "assign automatically", hence it is common for applications to leave the `nlmsghdr.nlmsg_pid` field initialized to `0`.

The field is still used today in rare cases when kernel needs to send a unicast notification. User space application can use bind() to associate its socket with a specific PID, it then communicates its PID to the kernel. This way the kernel can reach the specific user space process.

This sort of communication is utilized in UMH (User Mode Helper)-like scenarios when kernel needs to trigger user space processing or ask user space for a policy decision.

<a id="rst-multicast-notifications"></a>

### Multicast notifications

One of the strengths of Netlink is the ability to send event notifications to user space. This is a unidirectional form of communication (kernel -&gt; user) and does not involve any control messages like `NLMSG_ERROR` or `NLMSG_DONE`.

For example the Generic Netlink family itself defines a set of multicast notifications about registered families. When a new family is added the sockets subscribed to the notifications will get the following message:



```text
struct nlmsghdr:
  __u32 nlmsg_len:    136
  __u16 nlmsg_type:   GENL_ID_CTRL
  __u16 nlmsg_flags:  0
  __u32 nlmsg_seq:    0
  __u32 nlmsg_pid:    0

struct genlmsghdr:
  __u8 cmd:           CTRL_CMD_NEWFAMILY
  __u8 version:       2
  __u16 reserved:     0

struct nlattr:
  __u16 nla_len:      10
  __u16 nla_type:     CTRL_ATTR_FAMILY_NAME
  char data:          test1\0

(padding:)
  data:               \0\0

struct nlattr:
  __u16 nla_len:      6
  __u16 nla_type:     CTRL_ATTR_FAMILY_ID
  __u16:              123  /* The Family ID we are after */

(padding:)
  char data:          \0\0

struct nlattr:
  __u16 nla_len:      9
  __u16 nla_type:     CTRL_ATTR_FAMILY_VERSION
  __u16:              1

/* ... etc, more attributes will follow. */
```

The notification contains the same information as the response to the `CTRL_CMD_GETFAMILY` request.

The Netlink headers of the notification are mostly 0 and irrelevant. The `nlmsghdr.nlmsg_seq` may be either zero or a monotonically increasing notification sequence number maintained by the family.

To receive notifications the user socket must subscribe to the relevant notification group. Much like the Family ID, the Group ID for a given multicast group is dynamic and can be found inside the Family information. The `CTRL_ATTR_MCAST_GROUPS` attribute contains nests with names (`CTRL_ATTR_MCAST_GRP_NAME`) and IDs (`CTRL_ATTR_MCAST_GRP_ID`) of the groups family.

Once the Group ID is known a setsockopt() call adds the socket to the group:



```c
unsigned int group_id;

/* .. find the group ID... */

setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP,
           &group_id, sizeof(group_id));
```

The socket will now receive notifications.

It is recommended to use separate sockets for receiving notifications and sending requests to the kernel. The asynchronous nature of notifications means that they may get mixed in with the responses making the message handling much harder.

<a id="rst-buffer-sizing"></a>

### Buffer sizing

Netlink sockets are datagram sockets rather than stream sockets, meaning that each message must be received in its entirety by a single recv()/recvmsg() system call. If the buffer provided by the user is too short, the message will be truncated and the `MSG_TRUNC` flag set in struct msghdr (struct msghdr is the second argument of the recvmsg() system call, *not* a Netlink header).

Upon truncation the remaining part of the message is discarded.

Netlink expects that the user buffer will be at least 8kB or a page size of the CPU architecture, whichever is bigger. Particular Netlink families may, however, require a larger buffer. 32kB buffer is recommended for most efficient handling of dumps (larger buffer fits more dumped objects and therefore fewer recvmsg() calls are needed).

<a id="rst-classic-netlink-1"></a>
<a id="rst-classic-netlink"></a>

## Classic Netlink

The main differences between Classic and Generic Netlink are the dynamic allocation of subsystem identifiers and availability of introspection. In theory the protocol does not differ significantly, however, in practice Classic Netlink experimented with concepts which were abandoned in Generic Netlink (really, they usually only found use in a small corner of a single subsystem). This section is meant as an explainer of a few of such concepts, with the explicit goal of giving the Generic Netlink users the confidence to ignore them when reading the uAPI headers.

Most of the concepts and examples here refer to the `NETLINK_ROUTE` family, which covers much of the configuration of the Linux networking stack. Real documentation of that family, deserves a chapter (or a book) of its own.

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

### Families

Netlink refers to subsystems as families. This is a remnant of using sockets and the concept of protocol families, which are part of message demultiplexing in `NETLINK_ROUTE`.

Sadly every layer of encapsulation likes to refer to whatever it's carrying as "families" making the term very confusing:

> 1. AF_NETLINK is a bona fide socket protocol family
>
> 2. AF_NETLINK's documentation refers to what comes after its own header (struct nlmsghdr) in a message as a "Family Header"
>
> 3. Generic Netlink is a family for AF_NETLINK (struct genlmsghdr follows struct nlmsghdr), yet it also calls its users "Families".

Note that the Generic Netlink Family IDs are in a different "ID space" and overlap with Classic Netlink protocol numbers (e.g. `NETLINK_CRYPTO` has the Classic Netlink protocol ID of 21 which Generic Netlink will happily allocate to one of its families as well).

<a id="rst-strict-checking"></a>

### Strict checking

The `NETLINK_GET_STRICT_CHK` socket option enables strict input checking in `NETLINK_ROUTE`. It was needed because historically kernel did not validate the fields of structures it didn't process. This made it impossible to start using those fields later without risking regressions in applications which initialized them incorrectly or not at all.

`NETLINK_GET_STRICT_CHK` declares that the application is initializing all fields correctly. It also opts into validating that message does not contain trailing data and requests that kernel rejects attributes with type higher than largest attribute type known to the kernel.

`NETLINK_GET_STRICT_CHK` is not used outside of `NETLINK_ROUTE`.

<a id="rst-unknown-attributes"></a>

### Unknown attributes

Historically Netlink ignored all unknown attributes. The thinking was that it would free the application from having to probe what kernel supports. The application could make a request to change the state and check which parts of the request "stuck".

This is no longer the case for new Generic Netlink families and those opting in to strict checking. See enum netlink_validation for validation types performed.

<a id="rst-fixed-metadata-and-structures"></a>

### Fixed metadata and structures

Classic Netlink made liberal use of fixed-format structures within the messages. Messages would commonly have a structure with a considerable number of fields after struct nlmsghdr. It was also common to put structures with multiple members inside attributes, without breaking each member into an attribute of its own.

This has caused problems with validation and extensibility and therefore using binary structures is actively discouraged for new attributes.

<a id="rst-request-types"></a>

### Request types

`NETLINK_ROUTE` categorized requests into 4 types `NEW`, `DEL`, `GET`, and `SET`. Each object can handle all or some of those requests (objects being netdevs, routes, addresses, qdiscs etc.) Request type is defined by the 2 lowest bits of the message type, so commands for new objects would always be allocated with a stride of 4.

Each object would also have its own fixed metadata shared by all request types (e.g. struct ifinfomsg for netdev requests, struct ifaddrmsg for address requests, struct tcmsg for qdisc requests).

Even though other protocols and Generic Netlink commands often use the same verbs in their message names (`GET`, `SET`) the concept of request types did not find wider adoption.

<a id="rst-notification-echo"></a>

### Notification echo

`NLM_F_ECHO` requests for notifications resulting from the request to be queued onto the requesting socket. This is useful to discover the impact of the request.

Note that this feature is not universally implemented.

<a id="rst-other-request-type-specific-flags"></a>

### Other request-type-specific flags

Classic Netlink defined various flags for its `GET`, `NEW` and `DEL` requests in the upper byte of nlmsg_flags in struct nlmsghdr. Since request types have not been generalized the request type specific flags are rarely used (and considered deprecated for new families).

For `GET` - `NLM_F_ROOT` and `NLM_F_MATCH` are combined into `NLM_F_DUMP`, and not used separately. `NLM_F_ATOMIC` is never used.

For `DEL` - `NLM_F_NONREC` is only used by nftables and `NLM_F_BULK` only by FDB some operations.

The flags for `NEW` are used most commonly in classic Netlink. Unfortunately, the meaning is not crystal clear. The following description is based on the best guess of the intention of the authors, and in practice all families stray from it in one way or another. `NLM_F_REPLACE` asks to replace an existing object, if no matching object exists the operation should fail. `NLM_F_EXCL` has the opposite semantics and only succeeds if object already existed. `NLM_F_CREATE` asks for the object to be created if it does not exist, it can be combined with `NLM_F_REPLACE` and `NLM_F_EXCL`.

A comment in the main Netlink uAPI header states:



```text
4.4BSD ADD           NLM_F_CREATE|NLM_F_EXCL
4.4BSD CHANGE        NLM_F_REPLACE

True CHANGE          NLM_F_CREATE|NLM_F_REPLACE
Append               NLM_F_CREATE
Check                NLM_F_EXCL
```

which seems to indicate that those flags predate request types. `NLM_F_REPLACE` without `NLM_F_CREATE` was initially used instead of `SET` commands. `NLM_F_EXCL` without `NLM_F_CREATE` was used to check if object exists without creating it, presumably predating `GET` commands.

`NLM_F_APPEND` indicates that if one key can have multiple objects associated with it (e.g. multiple next-hop objects for a route) the new object should be added to the list rather than replacing the entire list.

<a id="rst-uapi-reference"></a>

## uAPI reference


#### <a id="c-struct-nlmsghdr"></a>`struct nlmsghdr`

fixed format metadata header of Netlink messages

**Definition**

```c
struct nlmsghdr {
    __u32 nlmsg_len;
    __u16 nlmsg_type;
    __u16 nlmsg_flags;
    __u32 nlmsg_seq;
    __u32 nlmsg_pid;
};
```

**Members**

- `nlmsg_len`: Length of message including header
- `nlmsg_type`: Message content type
- `nlmsg_flags`: Additional flags
- `nlmsg_seq`: Sequence number
- `nlmsg_pid`: Sending process port ID

#### <a id="c-enum-nlmsgerr_attrs"></a>`enum nlmsgerr_attrs`

nlmsgerr attributes

**Constants**

- `NLMSGERR_ATTR_UNUSED`: unused
- `NLMSGERR_ATTR_MSG`: error message string (string)
- `NLMSGERR_ATTR_OFFS`: offset of the invalid attribute in the original
  message, counting from the beginning of the header (u32)
- `NLMSGERR_ATTR_COOKIE`: arbitrary subsystem specific cookie to
  be used - in the success case - to identify a created
  object or operation or similar (binary)
- `NLMSGERR_ATTR_POLICY`: policy for a rejected attribute
- `NLMSGERR_ATTR_MISS_TYPE`: type of a missing required attribute,
  `NLMSGERR_ATTR_MISS_NEST` will not be present if the attribute was
  missing at the message level
- `NLMSGERR_ATTR_MISS_NEST`: offset of the nest where attribute was missing
- `__NLMSGERR_ATTR_MAX`: number of attributes
- `NLMSGERR_ATTR_MAX`: highest attribute number

#### <a id="c-enum-netlink_attribute_type"></a>`enum netlink_attribute_type`

type of an attribute

**Constants**

- `NL_ATTR_TYPE_INVALID`: unused
- `NL_ATTR_TYPE_FLAG`: flag attribute (present/not present)
- `NL_ATTR_TYPE_U8`: 8-bit unsigned attribute
- `NL_ATTR_TYPE_U16`: 16-bit unsigned attribute
- `NL_ATTR_TYPE_U32`: 32-bit unsigned attribute
- `NL_ATTR_TYPE_U64`: 64-bit unsigned attribute
- `NL_ATTR_TYPE_S8`: 8-bit signed attribute
- `NL_ATTR_TYPE_S16`: 16-bit signed attribute
- `NL_ATTR_TYPE_S32`: 32-bit signed attribute
- `NL_ATTR_TYPE_S64`: 64-bit signed attribute
- `NL_ATTR_TYPE_BINARY`: binary data, min/max length may be specified
- `NL_ATTR_TYPE_STRING`: string, min/max length may be specified
- `NL_ATTR_TYPE_NUL_STRING`: NUL-terminated string,
  min/max length may be specified
- `NL_ATTR_TYPE_NESTED`: nested, i.e. the content of this attribute
  consists of sub-attributes. The nested policy and maxtype
  inside may be specified.
- `NL_ATTR_TYPE_NESTED_ARRAY`: nested array, i.e. the content of this
  attribute contains sub-attributes whose type is irrelevant
  (just used to separate the array entries) and each such array
  entry has attributes again, the policy for those inner ones
  and the corresponding maxtype may be specified.
- `NL_ATTR_TYPE_BITFIELD32`: `struct nla_bitfield32` attribute
- `NL_ATTR_TYPE_SINT`: 32-bit or 64-bit signed attribute, aligned to 4B
- `NL_ATTR_TYPE_UINT`: 32-bit or 64-bit unsigned attribute, aligned to 4B

#### <a id="c-enum-netlink_policy_type_attr"></a>`enum netlink_policy_type_attr`

policy type attributes

**Constants**

- `NL_POLICY_TYPE_ATTR_UNSPEC`: unused
- `NL_POLICY_TYPE_ATTR_TYPE`: type of the attribute,
  [`enum netlink_attribute_type`](#c-enum-netlink_attribute_type) (U32)
- `NL_POLICY_TYPE_ATTR_MIN_VALUE_S`: minimum value for signed
  integers (S64)
- `NL_POLICY_TYPE_ATTR_MAX_VALUE_S`: maximum value for signed
  integers (S64)
- `NL_POLICY_TYPE_ATTR_MIN_VALUE_U`: minimum value for unsigned
  integers (U64)
- `NL_POLICY_TYPE_ATTR_MAX_VALUE_U`: maximum value for unsigned
  integers (U64)
- `NL_POLICY_TYPE_ATTR_MIN_LENGTH`: minimum length for binary
  attributes, no minimum if not given (U32)
- `NL_POLICY_TYPE_ATTR_MAX_LENGTH`: maximum length for binary
  attributes, no maximum if not given (U32)
- `NL_POLICY_TYPE_ATTR_POLICY_IDX`: sub policy for nested and
  nested array types (U32)
- `NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE`: maximum sub policy
  attribute for nested and nested array types, this can
  in theory be \< the size of the policy pointed to by
  the index, if limited inside the nesting (U32)
- `NL_POLICY_TYPE_ATTR_BITFIELD32_MASK`: valid mask for the
  bitfield32 type (U32)
- `NL_POLICY_TYPE_ATTR_PAD`: pad attribute for 64-bit alignment
- `NL_POLICY_TYPE_ATTR_MASK`: mask of valid bits for unsigned integers (U64)
- `__NL_POLICY_TYPE_ATTR_MAX`: number of attributes
- `NL_POLICY_TYPE_ATTR_MAX`: highest attribute number

---

# Netlink specification support for raw Netlink families

_Peios Kernel / Userspace interfaces / System and device interfaces / Netlink_

> Additional specification properties for raw Netlink families, including sub-messages and nested structures.

<a id="rst-netlink-specification-support-for-raw-netlink-families"></a>

<!-- SPDX-License-Identifier: BSD-3-Clause -->

This document describes the additional properties required by raw Netlink families such as `NETLINK_ROUTE` which use the `netlink-raw` protocol specification.

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

## Specification

The netlink-raw schema extends the [genetlink-legacy](</kernel/userspace/userspace-api/netlink/genetlink-legacy.md>) schema with properties that are needed to specify the protocol numbers and multicast IDs used by raw netlink families. See [classic\_netlink](</kernel/userspace/userspace-api/netlink/intro.md#rst-classic-netlink>) for more information. The raw netlink families also make use of type-specific sub-messages.

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

### Globals

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

#### protonum

The `protonum` property is used to specify the protocol number to use when opening a netlink socket.



```yaml
# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)

name: rt-addr
protocol: netlink-raw
protonum: 0             # part of the NETLINK_ROUTE protocol
```

<a id="rst-multicast-group-properties"></a>

### Multicast group properties

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

#### value

The `value` property is used to specify the group ID to use for multicast group registration.



```yaml
mcast-groups:
  list:
    -
      name: rtnlgrp-ipv4-ifaddr
      value: 5
    -
      name: rtnlgrp-ipv6-ifaddr
      value: 9
    -
      name: rtnlgrp-mctp-ifaddr
      value: 34
```

<a id="rst-sub-messages"></a>

### Sub-messages

Several raw netlink families such as [rt-link](</kernel/internals/netlink/specs/rt-link.md#rst-netlink-rt-link>) and [tc](</kernel/internals/netlink/specs/tc.md#rst-netlink-tc>) use attribute nesting as an abstraction to carry module specific information.

Conceptually it looks as follows:



```text
[OUTER NEST OR MESSAGE LEVEL]
  [GENERIC ATTR 1]
  [GENERIC ATTR 2]
  [GENERIC ATTR 3]
  [GENERIC ATTR - wrapper]
    [MODULE SPECIFIC ATTR 1]
    [MODULE SPECIFIC ATTR 2]
```

The `GENERIC ATTRs` at the outer level are defined in the core (or rt\_link or core TC), while specific drivers, TC classifiers, qdiscs etc. can carry their own information wrapped in the `GENERIC ATTR - wrapper`. Even though the example above shows attributes nesting inside the wrapper, the modules generally have full freedom to define the format of the nest. In practice the payload of the wrapper attr has very similar characteristics to a netlink message. It may contain a fixed header / structure, netlink attributes, or both. Because of those shared characteristics we refer to the payload of the wrapper attribute as a sub-message.

A sub-message attribute uses the value of another attribute as a selector key to choose the right sub-message format. For example if the following attribute has already been decoded:



```json
{ "kind": "gre" }
```

and we encounter the following attribute spec:



```yaml
-
  name: data
  type: sub-message
  sub-message: linkinfo-data-msg
  selector: kind
```

Then we look for a sub-message definition called `linkinfo-data-msg` and use the value of the `kind` attribute i.e. `gre` as the key to choose the correct format for the sub-message:



```yaml
sub-messages:
  name: linkinfo-data-msg
  formats:
    -
      value: bridge
      attribute-set: linkinfo-bridge-attrs
    -
      value: gre
      attribute-set: linkinfo-gre-attrs
    -
      value: geneve
      attribute-set: linkinfo-geneve-attrs
```

This would decode the attribute value as a sub-message with the attribute-set called `linkinfo-gre-attrs` as the attribute space.

A sub-message can have an optional `fixed-header` followed by zero or more attributes from an `attribute-set`. For example the following `tc-options-msg` sub-message defines message formats that use a mixture of `fixed-header`, `attribute-set` or both together:



```yaml
sub-messages:
  -
    name: tc-options-msg
    formats:
      -
        value: bfifo
        fixed-header: tc-fifo-qopt
      -
        value: cake
        attribute-set: tc-cake-attrs
      -
        value: netem
        fixed-header: tc-netem-qopt
        attribute-set: tc-netem-attrs
```

Note that a selector attribute must appear in a netlink message before any sub-message attributes that depend on it.

If an attribute such as `kind` is defined at more than one nest level, then a sub-message selector will be resolved using the value 'closest' to the selector. For example, if the same attribute name is defined in a nested `attribute-set` alongside a sub-message selector and also in a top level `attribute-set`, then the selector will be resolved using the value 'closest' to the selector. If the value is not present in the message at the same level as defined in the spec then this is an error.

<a id="rst-nested-struct-definitions"></a>

### Nested struct definitions

Many raw netlink families such as [tc](</kernel/internals/netlink/specs/tc.md#rst-netlink-tc>) make use of nested struct definitions. The `netlink-raw` schema makes it possible to embed a struct within a struct definition using the `struct` property. For example, the following struct definition embeds the `tc-ratespec` struct definition for both the `rate` and the `peakrate` members of `struct tc-tbf-qopt`.



```yaml
-
  name: tc-tbf-qopt
  type: struct
  members:
    -
      name: rate
      type: binary
      struct: tc-ratespec
    -
      name: peakrate
      type: binary
      struct: tc-ratespec
    -
      name: limit
      type: u32
    -
      name: buffer
      type: u32
    -
      name: mtu
      type: u32
```

---

# Netlink protocol specifications (in YAML)

_Peios Kernel / Userspace interfaces / System and device interfaces / Netlink_

> Netlink protocol specifications are complete, machine readable descriptions of Netlink protocols written in YAML. The goal of the specifications is to allow separating Netlink parsing from user space logic and minimize the amount of hand…

<a id="rst-netlink-protocol-specifications-in-yaml"></a>

<!-- SPDX-License-Identifier: BSD-3-Clause -->

Netlink protocol specifications are complete, machine readable descriptions of Netlink protocols written in YAML. The goal of the specifications is to allow separating Netlink parsing from user space logic and minimize the amount of hand written Netlink code for each new family, command, attribute. Netlink specs should be complete and not depend on any other spec or C header file, making it easy to use in languages which can't include kernel headers directly.

Internally kernel uses the YAML specs to generate:

> - the C uAPI header
>
> - documentation of the protocol as a ReST file - see [Documentation/netlink/specs/index.rst](</kernel/internals/netlink/specs/index.md#rst-specs>)
>
> - policy tables for input attribute validation
>
> - operation tables

YAML specifications can be found under `Documentation/netlink/specs/`

This document describes details of the schema. See [Using Netlink protocol specifications](</kernel/userspace/userspace-api/netlink/intro-specs.md>) for a practical starting guide.

All specs must be licensed under `((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)` to allow for easy adoption in user space code.

<a id="rst-compatibility-levels"></a>

## Compatibility levels

There are four schema levels for Netlink specs, from the simplest used by new families to the most complex covering all the quirks of the old ones. Each next level inherits the attributes of the previous level, meaning that user capable of parsing more complex `genetlink` schemas is also compatible with simpler ones. The levels are:

> - `genetlink` - most streamlined, should be used by all new families
>
> - `genetlink-c` - superset of `genetlink` with extra attributes allowing customization of define and enum type and value names; this schema should be equivalent to `genetlink` for all implementations which don't interact directly with C uAPI headers
>
> - `genetlink-legacy` - Generic Netlink catch all schema supporting quirks of all old genetlink families, strange attribute formats, binary structures etc.
>
> - `netlink-raw` - catch all schema supporting pre-Generic Netlink protocols such as `NETLINK_ROUTE`

The definition of the schemas (in `jsonschema`) can be found under `Documentation/netlink/`.

<a id="rst-schema-structure"></a>

## Schema structure

YAML schema has the following conceptual sections:

> - globals
>
> - definitions
>
> - attributes
>
> - operations
>
> - multicast groups

Most properties in the schema accept (or in fact require) a `doc` sub-property documenting the defined object.

The following sections describe the properties of the most modern `genetlink` schema. See the documentation of [genetlink-c](</kernel/userspace/userspace-api/netlink/c-code-gen.md>) for information on how C names are derived from name properties.

See also [Documentation/core-api/netlink.rst](</kernel/internals/core-api/netlink.md#rst-kernel-netlink>) for information on the Netlink specification properties that are only relevant to the kernel space and not part of the user space API.

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

## genetlink

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

### Globals

Attributes listed directly at the root level of the spec file.

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

#### name

Name of the family. Name identifies the family in a unique way, since the Family IDs are allocated dynamically.

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

#### protocol

The schema level, default is `genetlink`, which is the only value allowed for new `genetlink` families.

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

### definitions

Array of type and constant definitions.

<a id="rst-name-1"></a>

#### name

Name of the type / constant.

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

#### type

One of the following types:

> - const - a single, standalone constant
>
> - enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)
>
> - flags - defines an integer enumeration, with values for each entry occupying a bit, starting from bit 0, (e.g. 1, 2, 4, 8)

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

#### value

The value for the `const`.

<a id="rst-value-start"></a>

#### value-start

The first value for `enum` and `flags`, allows overriding the default start value of `0` (for `enum`) and starting bit (for `flags`). For `flags` `value-start` selects the starting bit, not the shifted value.

Sparse enumerations are not supported.

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

#### entries

Array of names of the entries for `enum` and `flags`.

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

#### header

For C-compatible languages, header which already defines this value. In case the definition is shared by multiple families (e.g. `IFNAMSIZ`) code generators for C-compatible languages may prefer to add an appropriate include instead of rendering a new definition.

<a id="rst-attribute-sets"></a>

### attribute-sets

This property contains information about netlink attributes of the family. All families have at least one attribute set, most have multiple. `attribute-sets` is an array, with each entry describing a single set.

Note that the spec is "flattened" and is not meant to visually resemble the format of the netlink messages (unlike certain ad-hoc documentation formats seen in kernel comments). In the spec subordinate attribute sets are not defined inline as a nest, but defined in a separate attribute set referred to with a `nested-attributes` property of the container.

Spec may also contain fractional sets - sets which contain a `subset-of` property. Such sets describe a section of a full set, allowing narrowing down which attributes are allowed in a nest or refining the validation criteria. Fractional sets can only be used in nests. They are not rendered to the uAPI in any fashion.

<a id="rst-name-2"></a>

#### name

Uniquely identifies the attribute set, operations and nested attributes refer to the sets by the `name`.

<a id="rst-subset-of"></a>

#### subset-of

Re-defines a portion of another set (a fractional set). Allows narrowing down fields and changing validation criteria or even types of attributes depending on the nest in which they are contained. The `value` of each attribute in the fractional set is implicitly the same as in the main set.

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

#### attributes

List of attributes in the set.

<a id="rst-attribute-properties-1"></a>
<a id="rst-attribute-properties"></a>

### Attribute properties

<a id="rst-name-3"></a>

#### name

Identifies the attribute, unique within the set.

<a id="rst-type-1"></a>

#### type

Netlink attribute type, see [Attribute types](<#rst-attr-types>).

<a id="rst-value-1"></a>
<a id="rst-assign-val"></a>

#### value

Numerical attribute ID, used in serialized Netlink messages. The `value` property can be skipped, in which case the attribute ID will be the value of the previous attribute plus one (recursively) and `1` for the first attribute in the attribute set.

Attributes (and operations) use `1` as the default value for the first entry (unlike enums in definitions which start from `0`) because entry `0` is almost always reserved as undefined. Spec can explicitly set value to `0` if needed.

Note that the `value` of an attribute is defined only in its main set (not in subsets).

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

#### enum

For integer types specifies that values in the attribute belong to an `enum` or `flags` from the `definitions` section.

<a id="rst-enum-as-flags"></a>

#### enum-as-flags

Treat `enum` as `flags` regardless of its type in `definitions`. When both `enum` and `flags` forms are needed `definitions` should contain an `enum` and attributes which need the `flags` form should use this attribute.

<a id="rst-nested-attributes"></a>

#### nested-attributes

Identifies the attribute space for attributes nested within given attribute. Only valid for complex attributes which may have sub-attributes.

<a id="rst-multi-attr-arrays"></a>

#### multi-attr (arrays)

Boolean property signifying that the attribute may be present multiple times. Allowing an attribute to repeat is the recommended way of implementing arrays (no extra nesting).

<a id="rst-byte-order"></a>

#### byte-order

For integer types specifies attribute byte order - `little-endian` or `big-endian`.

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

#### checks

Input validation constraints used by the kernel. User space should query the policy of the running kernel using Generic Netlink introspection, rather than depend on what is specified in the spec file.

The validation policy in the kernel is formed by combining the type definition (`type` and `nested-attributes`) and the `checks`.

<a id="rst-sub-type"></a>

#### sub-type

Legacy families have special ways of expressing arrays. `sub-type` can be used to define the type of array members in case array members are not fully defined as attributes (in a bona fide attribute space). For instance a C array of u32 values can be specified with `type: binary` and `sub-type: u32`. Binary types and legacy array formats are described in more detail in [Netlink specification support for legacy Generic Netlink families](</kernel/userspace/userspace-api/netlink/genetlink-legacy.md>).

<a id="rst-display-hint"></a>

#### display-hint

Optional format indicator that is intended only for choosing the right formatting mechanism when displaying values of this type. Currently supported hints are `hex`, `mac`, `fddi`, `ipv4`, `ipv6` and `uuid`.

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

### operations

This section describes messages passed between the kernel and the user space. There are three types of entries in this section - operations, notifications and events.

Operations describe the most common request - response communication. User sends a request and kernel replies. Each operation may contain any combination of the two modes familiar to netlink users - `do` and `dump`. `do` and `dump` in turn contain a combination of `request` and `response` properties. If no explicit message with attributes is passed in a given direction (e.g. a `dump` which does not accept filter, or a `do` of a SET operation to which the kernel responds with just the netlink error code) `request` or `response` section can be skipped. `request` and `response` sections list the attributes allowed in a message. The list contains only the names of attributes from a set referred to by the `attribute-set` property.

Notifications and events both refer to the asynchronous messages sent by the kernel to members of a multicast group. The difference between the two is that a notification shares its contents with a GET operation (the name of the GET operation is specified in the `notify` property). This arrangement is commonly used for notifications about objects where the notification carries the full object definition.

Events are more focused and carry only a subset of information rather than full object state (a made up example would be a link state change event with just the interface name and the new link state). Events contain the `event` property. Events are considered less idiomatic for netlink and notifications should be preferred.

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

#### list

The only property of `operations` for `genetlink`, holds the list of operations, notifications etc.

<a id="rst-operation-properties"></a>

### Operation properties

<a id="rst-name-4"></a>

#### name

Identifies the operation.

<a id="rst-value-2"></a>

#### value

Numerical message ID, used in serialized Netlink messages. The same enumeration rules are applied as to [attribute values](<#rst-value-1>).

<a id="rst-attribute-set"></a>

#### attribute-set

Specifies the attribute set contained within the message.

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

#### do

Specification for the `doit` request. Should contain `request`, `reply` or both of these properties, each holding a [Message attribute list](<#rst-attr-list>).

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

#### dump

Specification for the `dumpit` request. Should contain `request`, `reply` or both of these properties, each holding a [Message attribute list](<#rst-attr-list>).

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

#### notify

Designates the message as a notification. Contains the name of the operation (possibly the same as the operation holding this property) which shares the contents with the notification (`do`).

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

#### event

Specification of attributes in the event, holds a [Message attribute list](<#rst-attr-list>). `event` property is mutually exclusive with `notify`.

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

#### mcgrp

Used with `event` and `notify`, specifies which multicast group message belongs to.

<a id="rst-message-attribute-list"></a>
<a id="rst-attr-list"></a>

### Message attribute list

`request`, `reply` and `event` properties have a single `attributes` property which holds the list of attribute names.

Messages can also define `pre` and `post` properties which will be rendered as `pre_doit` and `post_doit` calls in the kernel (these properties should be ignored by user space).

<a id="rst-mcast-groups"></a>

### mcast-groups

This section lists the multicast groups of the family.

<a id="rst-list-1"></a>

#### list

The only property of `mcast-groups` for `genetlink`, holds the list of groups.

<a id="rst-multicast-group-properties"></a>

### Multicast group properties

<a id="rst-name-5"></a>

#### name

Uniquely identifies the multicast group in the family. Similarly to Family ID, Multicast Group ID needs to be resolved at runtime, based on the name.

<a id="rst-attribute-types"></a>
<a id="rst-attr-types"></a>

## Attribute types

This section describes the attribute types supported by the `genetlink` compatibility level. Refer to documentation of different levels for additional attribute types.

<a id="rst-common-integer-types"></a>

### Common integer types

`sint` and `uint` represent signed and unsigned 64 bit integers. If the value can fit on 32 bits only 32 bits are carried in netlink messages, otherwise full 64 bits are carried. Note that the payload is only aligned to 4B, so the full 64 bit value may be unaligned\!

Common integer types should be preferred over fix-width types in majority of cases.

<a id="rst-fix-width-integer-types"></a>

### Fix-width integer types

Fixed-width integer types include: `u8`, `u16`, `u32`, `u64`, `s8`, `s16`, `s32`, `s64`.

Note that types smaller than 32 bit should be avoided as using them does not save any memory in Netlink messages (due to alignment). See [pad](<#rst-pad-type>) for padding of 64 bit attributes.

The payload of the attribute is the integer in host order unless `byte-order` specifies otherwise.

64 bit values are usually aligned by the kernel but it is recommended that the user space is able to deal with unaligned values.

<a id="rst-pad"></a>
<a id="rst-pad-type"></a>

### pad

Special attribute type used for padding attributes which require alignment bigger than standard 4B alignment required by netlink (e.g. 64 bit integers). There can only be a single attribute of the `pad` type in any attribute set and it should be automatically used for padding when needed.

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

### flag

Attribute with no payload, its presence is the entire information.

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

### binary

Raw binary data attribute, the contents are opaque to generic code.

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

### string

Character string. Unless `checks` has `unterminated-ok` set to `true` the string is required to be null terminated. `max-len` in `checks` indicates the longest possible string, if not present the length of the string is unbounded.

Note that `max-len` does not count the terminating character.

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

### nest

Attribute containing other (nested) attributes. `nested-attributes` specifies which attribute set is used inside.

---

# Linux Media Infrastructure userspace API

_Peios Kernel / Userspace interfaces / System and device interfaces / Media devices_

> This section contains the driver development information and Kernel APIs used by media devices.

<a id="rst-linux-media-infrastructure-userspace-api"></a>

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

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

This section contains the  driver development information and Kernel APIs used by media devices.

Please see:

[Documentation/admin-guide/media/index.rst](/kernel/administration/admin-guide/media/index.md)

> - for usage information about media subsystem and supported drivers;

[Documentation/driver-api/media/index.rst](/kernel/hardware/driver-api/media/index.md)

> - for driver development information and Kernel APIs used by media devices;

**Table of Contents**

- [Introduction](</kernel/userspace/userspace-api/media/intro.md>)
- [Part I - Video for Linux API](</kernel/userspace/userspace-api/media-v4l/v4l2.md>)
- [Part II - Digital TV API](</kernel/userspace/userspace-api/media-dvb/dvbapi.md>)
- [Part III - Remote Controller API](</kernel/userspace/userspace-api/media-rc/remote-controllers.md>)
- [Part IV - Media Controller API](</kernel/userspace/userspace-api/media-mediactl/media-controller.md>)
- [Part V - Consumer Electronics Control API](</kernel/userspace/userspace-api/media-cec/cec-api.md>)
- [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md>)
- [glossary](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/glossary.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [GNU Free Documentation License](</kernel/userspace/userspace-api/media/fdl-appendix.md>)
- [Video4Linux (V4L)  driver-specific documentation](</kernel/userspace/userspace-api/media-drivers/index.md>)

**Copyright** © 2009-2020 : LinuxTV Developers



```text
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation, with no
Invariant Sections. A copy of the license is included in the chapter
entitled "GNU Free Documentation License".
```

Please notice that some documents inside the media userspace API, when explicitly mentioned on its source code, are dual-licensed with GNU Free Documentation License  Version 1.1 and with the GNU General Public License:



```text
This documentation is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) any
later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.

For more details see the file COPYING in the source distribution of Linux.
```

---

# GNU Free Documentation License

_Peios Kernel / Userspace interfaces / System and device interfaces / Media devices_

> The purpose of this License is to make a manual, textbook, or other written document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or…

<a id="rst-gnu-free-documentation-license"></a>
<a id="rst-fdl"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<a id="rst-preamble"></a>
<a id="rst-fdl-preamble"></a>

## 0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other written document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.

This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.

We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.

<a id="rst-applicability-and-definitions"></a>
<a id="rst-fdl-section1"></a>

## 1. APPLICABILITY AND DEFINITIONS

<a id="rst-fdl-document"></a>

This License applies to any manual or other work that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you".

<a id="rst-fdl-modified"></a>

A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.

<a id="rst-fdl-secondary"></a>

A "Secondary Section" is a named appendix or a front-matter section of the [Document](<#rst-fdl-document>) that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (For example, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.

<a id="rst-fdl-invariant"></a>

The "Invariant Sections" are certain [Secondary Sections](<#rst-fdl-secondary>) whose titles are designated, as being those of Invariant Sections, in the notice that says that the [Document](<#rst-fdl-document>) is released under this License.

<a id="rst-fdl-cover-texts"></a>

The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the [Document](<#rst-fdl-document>) is released under this License.

<a id="rst-fdl-transparent"></a>

A "Transparent" copy of the [Document](<#rst-fdl-document>) means a machine-readable copy, represented in a format whose specification is available to the general public, whose contents can be viewed and edited directly and straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup has been designed to thwart or discourage subsequent modification by readers is not Transparent. A copy that is not "Transparent" is called "Opaque".

Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML designed for human modification. Opaque formats include PostScript, PDF, proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML produced by some word processors for output purposes only.

<a id="rst-fdl-title-page"></a>

The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text.

<a id="rst-verbatim-copying"></a>
<a id="rst-fdl-section2"></a>

## 2. VERBATIM COPYING

You may copy and distribute the [Document](<#rst-fdl-document>) in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in [section 3](<#rst-fdl-section3>).

You may also lend copies, under the same conditions stated above, and you may publicly display copies.

<a id="rst-copying-in-quantity"></a>
<a id="rst-fdl-section3"></a>

## 3. COPYING IN QUANTITY

If you publish printed copies of the [Document](<#rst-fdl-document>) numbering more than 100, and the Document's license notice requires [Cover Texts](<#rst-fdl-cover-texts>), you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the [Document](<#rst-fdl-document>) and satisfy these conditions, can be treated as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

If you publish or distribute [Opaque](<#rst-fdl-transparent>) copies of the [Document](<#rst-fdl-document>) numbering more than 100, you must either include a machine-readable [Transparent](<#rst-fdl-transparent>) copy along with each Opaque copy, or state in or with each Opaque copy a publicly-accessible computer-network location containing a complete Transparent copy of the Document, free of added material, which the general network-using public has access to download anonymously at no charge using public-standard network protocols. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

It is requested, but not required, that you contact the authors of the [Document](<#rst-fdl-document>) well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

<a id="rst-modifications"></a>
<a id="rst-fdl-section4"></a>

## 4. MODIFICATIONS

You may copy and distribute a [Modified Version](<#rst-fdl-modified>) of the [Document](<#rst-fdl-document>) under the conditions of sections [2](<#rst-fdl-section2>) and [3](<#rst-fdl-section3>) above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:

- **A.** Use in the [Title Page](<#rst-fdl-title-page>) (and on the covers, if any) a title distinct from that of the [Document](<#rst-fdl-document>), and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.

- **B.** List on the [Title Page](<#rst-fdl-title-page>), as authors, one or more persons or entities responsible for authorship of the modifications in the [Modified Version](<#rst-fdl-modified>), together with at least five of the principal authors of the [Document](<#rst-fdl-document>) (all of its principal authors, if it has less than five).

- **C.** State on the [Title Page](<#rst-fdl-title-page>) the name of the publisher of the [Modified Version](<#rst-fdl-modified>), as the publisher.

- **D.** Preserve all the copyright notices of the [Document](<#rst-fdl-document>).

- **E.** Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.

- **F.** Include, immediately after the copyright notices, a license notice giving the public permission to use the [Modified Version](<#rst-fdl-modified>) under the terms of this License, in the form shown in the Addendum below.

- **G.** Preserve in that license notice the full lists of [Invariant Sections](<#rst-fdl-invariant>) and required [Cover Texts](<#rst-fdl-cover-texts>) given in the [Document's](<#rst-fdl-document>) license notice.

- **H.** Include an unaltered copy of this License.

- **I.** Preserve the section entitled "History", and its title, and add to it an item stating at least the title, year, new authors, and publisher of the [Modified Version](<#rst-fdl-modified>) as given on the [Title Page](<#rst-fdl-title-page>). If there is no section entitled "History" in the [Document](<#rst-fdl-document>), create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.

- **J.** Preserve the network location, if any, given in the [Document](<#rst-fdl-document>) for public access to a [Transparent](<#rst-fdl-transparent>) copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.

- **K.** In any section entitled "Acknowledgements" or "Dedications", preserve the section's title, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.

- **L.** Preserve all the [Invariant Sections](<#rst-fdl-invariant>) of the [Document](<#rst-fdl-document>), unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.

- **M.** Delete any section entitled "Endorsements". Such a section may not be included in the [Modified Version](<#rst-fdl-modified>).

- **N.** Do not retitle any existing section as "Endorsements" or to conflict in title with any [Invariant Section](<#rst-fdl-invariant>).

If the [Modified Version](<#rst-fdl-modified>) includes new front-matter sections or appendices that qualify as [Secondary Sections](<#rst-fdl-secondary>) and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of [Invariant Sections](<#rst-fdl-invariant>) in the Modified Version's license notice. These titles must be distinct from any other section titles.

You may add a section entitled "Endorsements", provided it contains nothing but endorsements of your [Modified Version](<#rst-fdl-modified>) by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.

You may add a passage of up to five words as a [Front-Cover Text](<#rst-fdl-cover-texts>), and a passage of up to 25 words as a [Back-Cover Text](<#rst-fdl-cover-texts>), to the end of the list of [Cover Texts](<#rst-fdl-cover-texts>) in the [Modified Version](<#rst-fdl-modified>). Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the [Document](<#rst-fdl-document>) already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the [Document](<#rst-fdl-document>) do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any [Modified Version](<#rst-fdl-modified>).

<a id="rst-combining-documents"></a>
<a id="rst-fdl-section5"></a>

## 5. COMBINING DOCUMENTS

You may combine the [Document](<#rst-fdl-document>) with other documents released under this License, under the terms defined in [section 4](<#rst-fdl-section4>) above for modified versions, provided that you include in the combination all of the [Invariant Sections](<#rst-fdl-invariant>) of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice.

The combined work need only contain one copy of this License, and multiple identical [Invariant Sections](<#rst-fdl-invariant>) may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.

In the combination, you must combine any sections entitled "History" in the various original documents, forming one section entitled "History"; likewise combine any sections entitled "Acknowledgements", and any sections entitled "Dedications". You must delete all sections entitled "Endorsements."

<a id="rst-collections-of-documents"></a>
<a id="rst-fdl-section6"></a>

## 6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting of the [Document](<#rst-fdl-document>) and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.

You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.

<a id="rst-aggregation-with-independent-works"></a>
<a id="rst-fdl-section7"></a>

## 7. AGGREGATION WITH INDEPENDENT WORKS

A compilation of the [Document](<#rst-fdl-document>) or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, does not as a whole count as a [Modified Version](<#rst-fdl-modified>) of the Document, provided no compilation copyright is claimed for the compilation. Such a compilation is called an "aggregate", and this License does not apply to the other self-contained works thus compiled with the Document , on account of their being thus compiled, if they are not themselves derivative works of the Document. If the [Cover Text](<#rst-fdl-cover-texts>) requirement of [section 3](<#rst-fdl-section3>) is applicable to these copies of the Document, then if the Document is less than one quarter of the entire aggregate, the Document's Cover Texts may be placed on covers that surround only the Document within the aggregate. Otherwise they must appear on covers around the whole aggregate.

<a id="rst-translation"></a>
<a id="rst-fdl-section8"></a>

## 8. TRANSLATION

Translation is considered a kind of modification, so you may distribute translations of the [Document](<#rst-fdl-document>) under the terms of [section 4](<#rst-fdl-section4>). Replacing [Invariant Sections](<#rst-fdl-invariant>) with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License provided that you also include the original English version of this License. In case of a disagreement between the translation and the original English version of this License, the original English version will prevail.

<a id="rst-termination"></a>
<a id="rst-fdl-section9"></a>

## 9. TERMINATION

You may not copy, modify, sublicense, or distribute the [Document](<#rst-fdl-document>) except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

<a id="rst-future-revisions-of-this-license"></a>
<a id="rst-fdl-section10"></a>

## 10. FUTURE REVISIONS OF THIS LICENSE

The [Free Software Foundation](<http://www.gnu.org/fsf/fsf.html>) may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See [http://www.gnu.org/copyleft/](<http://www.gnu.org/copyleft>).

Each version of the License is given a distinguishing version number. If the [Document](<#rst-fdl-document>) specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation.

<a id="rst-addendum"></a>
<a id="rst-fdl-using"></a>

## Addendum

To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:

> Copyright © YEAR YOUR NAME.
>
> Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the [Invariant Sections](<#rst-fdl-invariant>) being LIST THEIR TITLES, with the [Front-Cover Texts](<#rst-fdl-cover-texts>) being LIST, and with the [Back-Cover Texts](<#rst-fdl-cover-texts>) being LIST. A copy of the license is included in the section entitled "GNU Free Documentation License".

If you have no [Invariant Sections](<#rst-fdl-invariant>), write "with no Invariant Sections" instead of saying which ones are invariant. If you have no [Front-Cover Texts](<#rst-fdl-cover-texts>), write "no Front-Cover Texts" instead of "Front-Cover Texts being LIST"; likewise for [Back-Cover Texts](<#rst-fdl-cover-texts>).

If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the [GNU General Public License](<http://www.gnu.org/copyleft/gpl.html>), to permit their use in free software.

---

# Generic Error Codes

_Peios Kernel / Userspace interfaces / System and device interfaces / Media devices_

> Reference for Generic Error Codes.

> **Peios:** References to Unix root and file modes below describe the inherited interface conventions. They are not sufficient Peios authorization: native descriptor/handle checks, the separate sysfs write gate, and mapped native privileges apply as appropriate. Debugfs additionally remains subject to integrity lockdown. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>).


<a id="rst-generic-error-codes"></a>
<a id="rst-gen-errors"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<a id="rst-gen-errors-1"></a>



<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<caption>Generic error codes</caption>
<tbody>
<tr>
<td>


`EAGAIN` (aka `EWOULDBLOCK`)

</td>
<td>


The ioctl can't be handled because the device is in state where it can't perform it. This could happen for example in case where device is sleeping and ioctl is performed to query statistics. It is also returned when the ioctl would need to wait for an event, but the device was opened in non-blocking mode.

</td>
</tr>
<tr>
<td>


`EBADF`

</td>
<td>


The file descriptor is not a valid.

</td>
</tr>
<tr>
<td>


`EBUSY`

</td>
<td>


The ioctl can't be handled because the device is busy. This is typically return while device is streaming, and an ioctl tried to change something that would affect the stream, or would require the usage of a hardware resource that was already allocated. The ioctl must not be retried without performing another action to fix the problem first (typically: stop the stream before retrying).

</td>
</tr>
<tr>
<td>


`EFAULT`

</td>
<td>


There was a failure while copying data from/to userspace, probably caused by an invalid pointer reference.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td>


One or more of the ioctl parameters are invalid or out of the allowed range. This is a widely used error code. See the individual ioctl requests for specific causes.

</td>
</tr>
<tr>
<td>


`ENODEV`

</td>
<td>


Device not found or was removed.

</td>
</tr>
<tr>
<td>


`ENOMEM`

</td>
<td>


There's not enough memory to handle the desired operation.

</td>
</tr>
<tr>
<td>


`ENOTTY`

</td>
<td>


The ioctl is not supported by the file descriptor.

</td>
</tr>
<tr>
<td>


`ENOSPC`

</td>
<td>


On USB devices, the stream ioctl's can return this error, meaning that this request would overcommit the usb bandwidth reserved for periodic transfers (up to 80% of the USB bandwidth).

</td>
</tr>
<tr>
<td>


`EPERM`

</td>
<td>


Permission denied. Can be returned if the device needs write permission, or some special capabilities is needed (e. g. root)

</td>
</tr>
<tr>
<td>


`EIO`

</td>
<td>


I/O error. Typically used when there are problems communicating with a hardware device. This could indicate broken or flaky hardware. It's a 'Something is wrong, I give up\!' type of error.

</td>
</tr>
<tr>
<td>


`ENXIO`

</td>
<td>


No device corresponding to this device special file exists.

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> 1. This list is not exhaustive; ioctls may return other error codes. Since errors may have side effects such as a driver reset, applications should abort on unexpected errors, or otherwise assume that the device is in a bad state.
>
> 2. Request-specific error codes are listed in the individual requests descriptions.

---

# Glossary

_Peios Kernel / Userspace interfaces / System and device interfaces / Media devices_

> A Device Driver that implements the main logic to talk with media hardware.

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

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

> [!NOTE]
>
> The goal of this section is to standardize the terms used within the media userspace API documentation. This is Work In Progress.

<!-- Please keep the glossary entries in alphabetical order -->



- **<a id="rst-term-bridge-driver"></a>Bridge Driver**

  A [Device Driver](<#rst-term-device-driver>) that implements the main logic to talk with media hardware.

- **<a id="rst-term-cec-api"></a>CEC API**

  <strong>Consumer Electronics Control API</strong>

  An API designed to receive and transmit data via an HDMI CEC interface.

  See [cec](</kernel/userspace/userspace-api/media-cec/cec-api.md#rst-cec>).

- **<a id="rst-term-data-unit"></a>Data Unit**

  Unit of data transported by a bus. On parallel buses, the data unit consists of one or more related samples while on serial buses the data unit is logical. If the data unit is image data, it may also be called a pixel.

- **<a id="rst-term-device-driver"></a>Device Driver**

  Part of the Linux Kernel that implements support for a hardware component.

- **<a id="rst-term-device-node"></a>Device Node**

  A character device node in the file system used to control and transfer data in and out of a Kernel driver.

- **<a id="rst-term-digital-tv-api"></a>Digital TV API**

  <strong>Previously known as DVB API</strong>

  An API designed to control a subset of the [Media Hardware](<#rst-term-media-hardware>) that implements digital TV (e. g. DVB, ATSC, ISDB, etc).

  See [dvbapi](</kernel/userspace/userspace-api/media-dvb/dvbapi.md#rst-dvbapi>).

- **<a id="rst-term-dsp"></a>DSP**

  <strong>Digital Signal Processor</strong>

  A specialized [Microprocessor](<#rst-term-microprocessor>), with its architecture optimized for the operational needs of digital signal processing.

- **<a id="rst-term-fpga"></a>FPGA**

  <strong>Field-programmable Gate Array</strong>

  An [IC](<#rst-term-ic>) circuit designed to be configured by a customer or a designer after manufacturing.

  See [https://en.wikipedia.org/wiki/Field-programmable\_gate\_array](<https://en.wikipedia.org/wiki/Field-programmable_gate_array>).

- **<a id="rst-term-hardware-component"></a>Hardware Component**

  A subset of the [Media Hardware](<#rst-term-media-hardware>). For example an [I²C](<#rst-term-i2c>) or [SPI](<#rst-term-spi>) device, or an [IP Block](<#rst-term-ip-block>) inside an [SoC](<#rst-term-soc>) or [FPGA](<#rst-term-fpga>).

- **<a id="rst-term-hardware-peripheral"></a>Hardware Peripheral**

  A group of [hardware components](<#rst-term-hardware-component>) that together make a larger user-facing functional peripheral. For instance, the [SoC](<#rst-term-soc>) [ISP](<#rst-term-isp>) [IP Block](<#rst-term-ip-block>) and the external camera sensors together make a camera hardware peripheral.

  Also known as [Peripheral](<#rst-term-peripheral>).

- **<a id="rst-term-i2c"></a>I²C**

  <strong>Inter-Integrated Circuit</strong>

  A  multi-master, multi-slave, packet switched, single-ended, serial computer bus used to control some hardware components like sub-device hardware components.

  See [http://www.nxp.com/docs/en/user-guide/UM10204.pdf](<http://www.nxp.com/docs/en/user-guide/UM10204.pdf>).

- **<a id="rst-term-ic"></a>IC**

  <strong>Integrated circuit</strong>

  A set of electronic circuits on one small flat piece of semiconductor material, normally silicon.

  Also known as chip.

- **<a id="rst-term-ip-block"></a>IP Block**

  <strong>Intellectual property core</strong>

  In electronic design a semiconductor intellectual property core, is a reusable unit of logic, cell, or integrated circuit layout design that is the intellectual property of one party. IP Blocks may be licensed to another party or can be owned and used by a single party alone.

  See [https://en.wikipedia.org/wiki/Semiconductor\_intellectual\_property\_core](<https://en.wikipedia.org/wiki/Semiconductor_intellectual_property_core>)).

- **<a id="rst-term-isp"></a>ISP**

  <strong>Image Signal Processor</strong>

  A specialized processor that implements a set of algorithms for processing image data. ISPs may implement algorithms for lens shading correction, demosaicing, scaling and pixel format conversion as well as produce statistics for the use of the control algorithms (e.g. automatic exposure, white balance and focus).

- **<a id="rst-term-media-api"></a>Media API**

  A set of userspace APIs used to control the media hardware. It is composed by:

  > - [CEC API](<#rst-term-cec-api>);
  >
  > - [Digital TV API](<#rst-term-digital-tv-api>);
  >
  > - [MC API](<#rst-term-mc-api>);
  >
  > - [RC API](<#rst-term-rc-api>); and
  >
  > - [V4L2 API](<#rst-term-v4l2-api>).

  See [Documentation/userspace-api/media/index.rst](/kernel/userspace/userspace-api/media/index.md).

- **<a id="rst-term-mc-api"></a>MC API**

  <strong>Media Controller API</strong>

  An API designed to expose and control the relationships between multimedia devices and sub-devices.

  See [media\_controller](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>).

- **<a id="rst-term-mc-centric"></a>MC-centric**

  [V4L2 Hardware](<#rst-term-v4l2-hardware>) device driver that requires [MC API](<#rst-term-mc-api>).

  Such drivers have `V4L2_CAP_IO_MC` device\_caps field set (see [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>)).

  See [v4l2\_hardware\_control](</kernel/userspace/userspace-api/media-v4l/open.md#rst-v4l2-hardware-control>) for more details.

- **<a id="rst-term-media-hardware"></a>Media Hardware**

  Subset of the hardware that is supported by the Linux Media API.

  This includes audio and video capture and playback hardware, digital and analog TV, camera sensors, ISPs, remote controllers, codecs, HDMI Consumer Electronics Control, HDMI capture, etc.

- **<a id="rst-term-microprocessor"></a>Microprocessor**

  Electronic circuitry that carries out the instructions of a computer program by performing the basic arithmetic, logical, control and input/output (I/O) operations specified by the instructions on a single integrated circuit.

- **<a id="rst-term-peripheral"></a>Peripheral**

  The same as [Hardware Peripheral](<#rst-term-hardware-peripheral>).

- **<a id="rst-term-rc-api"></a>RC API**

  <strong>Remote Controller API</strong>

  An API designed to receive and transmit data from remote controllers.

  See [remote\_controllers](</kernel/userspace/userspace-api/media-rc/remote-controllers.md#rst-remote-controllers>).

- **<a id="rst-term-smbus"></a>SMBus**

  A subset of I²C, which defines a stricter usage of the bus.

- **<a id="rst-term-spi"></a>SPI**

  <strong>Serial Peripheral Interface Bus</strong>

  Synchronous serial communication interface specification used for short distance communication, primarily in embedded systems.

- **<a id="rst-term-soc"></a>SoC**

  <strong>System on a Chip</strong>

  An integrated circuit that integrates all components of a computer or other electronic systems.

- **<a id="rst-term-stream"></a>Stream**

  A distinct flow of data (image data or metadata) from an initial source to a final sink. The initial source may be e.g. an image sensor and the final sink e.g. a memory buffer.

- **<a id="rst-term-v4l2-api"></a>V4L2 API**

  <strong>V4L2 userspace API</strong>

  The userspace API defined in [v4l2spec](</kernel/userspace/userspace-api/media-v4l/v4l2.md#rst-v4l2spec>), which is used to control a V4L2 hardware.

- **<a id="rst-term-v4l2-device-node"></a>V4L2 Device Node**

  A [Device Node](<#rst-term-device-node>) that is associated to a V4L driver.

  The V4L2 device node naming is specified at [v4l2\_device\_naming](</kernel/userspace/userspace-api/media-v4l/open.md#rst-v4l2-device-naming>).

- **<a id="rst-term-v4l2-hardware"></a>V4L2 Hardware**

  Part of the media hardware which is supported by the [V4L2 API](<#rst-term-v4l2-api>).

- **<a id="rst-term-v4l2-sub-device"></a>V4L2 Sub-device**

  V4L2 hardware components that aren't controlled by a [Bridge Driver](<#rst-term-bridge-driver>). See [Sub-device Interface](</kernel/userspace/userspace-api/media-v4l/dev-subdev.md#rst-subdev>).

- **<a id="rst-term-video-node-centric"></a>Video-node-centric**

  V4L2 device driver that doesn't require a media controller to be used.

  Such drivers have the `V4L2_CAP_IO_MC` device\_caps field unset (see [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>)).

- **<a id="rst-term-v4l2-sub-device-api"></a>V4L2 Sub-device API**

  Part of the [V4L2 API](<#rst-term-v4l2-api>) which control [V4L2 sub-devices](<#rst-term-v4l2-sub-device>), like sensors, HDMI receivers, scalers, deinterlacers.

  See [v4l2\_hardware\_control](</kernel/userspace/userspace-api/media-v4l/open.md#rst-v4l2-hardware-control>) for more details.

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Media devices_

> This document covers the Linux Kernel to Userspace API's used by video and radio streaming devices, including video cameras, analog and digital TV receiver cards, AM/FM receiver cards, Software Defined Radio (SDR), streaming capture and…

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

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

This document covers the Linux Kernel to Userspace API's used by video and radio streaming devices, including video cameras, analog and digital TV receiver cards, AM/FM receiver cards, Software Defined Radio (SDR), streaming capture and output devices, codec devices and remote controllers.

A typical media device hardware is shown at [typical_media_device](<#rst-typical-media-device>).

<a id="rst-typical-media-device"></a>

![typical_media_device.svg](/kernel/userspace/userspace-api/media/asset-40a61b16a3eb-typical-media-device.svg)

Typical Media Device

The media infrastructure API was designed to control such devices. It is divided into five parts.

1. The [first part](</kernel/userspace/userspace-api/media-v4l/v4l2.md#rst-v4l2spec>) covers radio, video capture and output, cameras, analog TV devices and codecs.

2. The [second part](</kernel/userspace/userspace-api/media-dvb/dvbapi.md#rst-dvbapi>) covers the API used for digital TV and Internet reception via one of the several digital tv standards. While it is called as DVB API, in fact it covers several different video standards including DVB-T/T2, DVB-S/S2, DVB-C, ATSC, ISDB-T, ISDB-S, DTMB, etc. The complete list of supported standards can be found at `fe_delivery_system`.

3. The [third part](</kernel/userspace/userspace-api/media-rc/remote-controllers.md#rst-remote-controllers>) covers the Remote Controller API.

4. The [fourth part](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>) covers the Media Controller API.

5. The [fifth part](</kernel/userspace/userspace-api/media-cec/cec-api.md#rst-cec>) covers the CEC (Consumer Electronics Control) API.

It should also be noted that a media device may also have audio components, like mixers, PCM capture, PCM playback, etc, which are controlled via ALSA API.  For additional information and for the latest development code, see: [https://linuxtv.org](<https://linuxtv.org>).  For discussing improvements, reporting troubles, sending new drivers, etc, please mail to: [Linux Media Mailing List (LMML)](<http://vger.kernel.org/vger-lists.html#linux-media>).

---

# Part V - Consumer Electronics Control API

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> This part describes the CEC: Consumer Electronics Control

<a id="rst-part-v-consumer-electronics-control-api"></a>
<a id="rst-cec"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

This part describes the CEC: Consumer Electronics Control

**Table of Contents**

1. [Introduction](</kernel/userspace/userspace-api/media-cec/cec-intro.md>)
2. [Function Reference](</kernel/userspace/userspace-api/media-cec/cec-funcs.md>)
3. [CEC Pin Framework Error Injection](</kernel/userspace/userspace-api/media-cec/cec-pin-error-inj.md>)
4. [cec-header](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/cec/cec-header.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

<a id="rst-revision-and-copyright"></a>

## Revision and Copyright

Authors:

- Verkuil, Hans &lt;[hverkuil@kernel.org](<mailto:hverkuil@kernel.org>)&gt;

> - Initial version.

**Copyright** © 2016 : Hans Verkuil

<a id="rst-revision-history"></a>

## Revision History

**revision:** 1.0.0 / 2016-03-17 (*hv*)

Initial revision

---

# cec close()

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> cec-close - Close a cec device

<a id="rst-cec-close"></a>
<a id="rst-cec-func-close"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

cec-close - Close a cec device

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-close"></a>

```c
int close( int fd )
```

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

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

## Description

Closes the cec device. Resources associated with the file descriptor are freed. The device configuration remain unchanged.

<a id="rst-return-value"></a>

## Return Value

`close()` returns 0 on success. On error, -1 is returned, and `errno` is set appropriately. Possible error codes are:

- **`EBADF`**

  `fd` is not a valid open file descriptor.

---

# cec ioctl()

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> cec-ioctl - Control a cec device

<a id="rst-cec-ioctl"></a>
<a id="rst-cec-func-ioctl"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

cec-ioctl - Control a cec device

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

## Synopsis



```c
#include <sys/ioctl.h>
```

`int ioctl(int fd, int request, void *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`request`**

  CEC ioctl request code as defined in the cec.h header file, for example [CEC_ADAP_G_CAPS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-adap-g-caps>).

- **`argp`**

  Pointer to a request-specific structure.

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

## Description

The `ioctl()` function manipulates cec device parameters. The argument `fd` must be an open file descriptor.

The ioctl `request` code specifies the cec function to be called. It has encoded in it whether the argument is an input, output or read/write parameter, and the size of the argument `argp` in bytes.

Macros and structures definitions specifying cec ioctl requests and their parameters are located in the cec.h header file. All cec ioctl requests, their respective function and parameters are specified in [Function Reference](</kernel/userspace/userspace-api/media-cec/cec-funcs.md#rst-cec-user-func>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

Request-specific error codes are listed in the individual requests descriptions.

When an ioctl that takes an output or read/write parameter fails, the parameter remains unmodified.

---

# cec open()

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> cec-open - Open a cec device

<a id="rst-cec-open"></a>
<a id="rst-cec-func-open"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

cec-open - Open a cec device

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

## Synopsis



```c
#include <fcntl.h>
```





<a id="c-open"></a>

```c
int open( const char *device_name, int flags )
```

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

## Arguments

- **`device_name`**

  Device to be opened.

- **`flags`**

  Open flags. Access mode must be `O_RDWR`.

  When the `O_NONBLOCK` flag is given, the [CEC_RECEIVE](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-receive>) and [CEC_DQEVENT](</kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-dqevent>) ioctls will return the `EAGAIN` error code when no message or event is available, and ioctls [CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>), [CEC_ADAP_S_PHYS_ADDR](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-s-phys-addr>) and [CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>) all return 0.

  Other flags have no effect.

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

## Description

To open a cec device applications call `open()` with the desired device name. The function has no side effects; the device configuration remain unchanged.

When the device is opened in read-only mode, attempts to modify its configuration will result in an error, and `errno` will be set to EBADF.

<a id="rst-return-value"></a>

## Return Value

`open()` returns the new file descriptor on success. On error, -1 is returned, and `errno` is set appropriately. Possible error codes include:

- **`EACCES`**

  The requested access to the file is not allowed.

- **`EMFILE`**

  The process already has the maximum number of files open.

- **`ENFILE`**

  The system limit on the total number of open files has been reached.

- **`ENOMEM`**

  Insufficient kernel memory was available.

- **`ENODEV`**

  Device not found or was removed.

---

# cec poll()

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> cec-poll - Wait for some event on a file descriptor

<a id="rst-cec-poll"></a>
<a id="rst-cec-func-poll"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

cec-poll - Wait for some event on a file descriptor

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

## Synopsis



```c
#include <sys/poll.h>
```





<a id="c-poll"></a>

```c
int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
```

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

## Arguments

- **`ufds`**

  List of FD events to be watched

- **`nfds`**

  Number of FD events at the \*ufds array

- **`timeout`**

  Timeout to wait for events

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

## Description

With the `poll()` function applications can wait for CEC events.

On success `poll()` returns the number of file descriptors that have been selected (that is, file descriptors for which the `revents` field of the respective struct `pollfd` is non-zero). CEC devices set the `POLLIN` and `POLLRDNORM` flags in the `revents` field if there are messages in the receive queue. If the transmit queue has room for new messages, the `POLLOUT` and `POLLWRNORM` flags are set. If there are events in the event queue, then the `POLLPRI` flag is set. When the function times out it returns a value of zero, on failure it returns -1 and the `errno` variable is set appropriately.

For more details see the `poll()` manual page.

<a id="rst-return-value"></a>

## Return Value

On success, `poll()` returns the number structures which have non-zero `revents` fields, or zero if the call timed out. On error -1 is returned, and the `errno` variable is set appropriately:

- **`EBADF`**

  One or more of the `ufds` members specify an invalid file descriptor.

- **`EFAULT`**

  `ufds` references an inaccessible memory area.

- **`EINTR`**

  The call was interrupted by a signal.

- **`EINVAL`**

  The `nfds` value exceeds the `RLIMIT_NOFILE` value. Use `getrlimit()` to obtain this value.

---

# Function Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> Reference for Function Reference.

<a id="rst-function-reference"></a>
<a id="rst-cec-user-func"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

- [cec open()](</kernel/userspace/userspace-api/media-cec/cec-func-open.md>)
- [cec close()](</kernel/userspace/userspace-api/media-cec/cec-func-close.md>)
- [cec ioctl()](</kernel/userspace/userspace-api/media-cec/cec-func-ioctl.md>)
- [cec poll()](</kernel/userspace/userspace-api/media-cec/cec-func-poll.md>)
- [ioctl CEC_ADAP_G_CAPS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md>)
- [ioctls CEC_ADAP_G_LOG_ADDRS and CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md>)
- [ioctls CEC_ADAP_G_PHYS_ADDR and CEC_ADAP_S_PHYS_ADDR](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md>)
- [ioctl CEC_ADAP_G_CONNECTOR_INFO](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md>)
- [ioctl CEC_DQEVENT](</kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md>)
- [ioctls CEC_G_MODE and CEC_S_MODE](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md>)
- [ioctls CEC_RECEIVE and CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md>)

---

# CEC uAPI Symbols

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> Reference for CEC uAPI Symbols.

<a id="rst-cec-uapi-symbols"></a>
<a id="rst-cec-header"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->


## IOCTL Commands

- [`CEC_ADAP_G_CAPS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-adap-g-caps): `include/uapi/linux/cec.h`, line 503
- [`CEC_ADAP_G_CONNECTOR_INFO`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#rst-cec-adap-g-connector-info): `include/uapi/linux/cec.h`, line 545
- [`CEC_ADAP_G_LOG_ADDRS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-g-log-addrs): `include/uapi/linux/cec.h`, line 528
- [`CEC_ADAP_G_PHYS_ADDR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-g-phys-addr): `include/uapi/linux/cec.h`, line 517
- [`CEC_ADAP_S_LOG_ADDRS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs): `include/uapi/linux/cec.h`, line 529
- [`CEC_ADAP_S_PHYS_ADDR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-s-phys-addr): `include/uapi/linux/cec.h`, line 518
- [`CEC_DQEVENT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-dqevent): `include/uapi/linux/cec.h`, line 536
- [`CEC_G_MODE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-g-mode): `include/uapi/linux/cec.h`, line 541
- [`CEC_RECEIVE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-receive): `include/uapi/linux/cec.h`, line 533
- [`CEC_S_MODE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-s-mode): `include/uapi/linux/cec.h`, line 542
- [`CEC_TRANSMIT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit): `include/uapi/linux/cec.h`, line 532

## Macros and Definitions

- [`CEC_CAP_CONNECTOR_INFO`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-connector-info): `include/uapi/linux/cec.h`, line 346
- [`CEC_CAP_LOG_ADDRS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-log-addrs): `include/uapi/linux/cec.h`, line 330
- [`CEC_CAP_MONITOR_ALL`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-monitor-all): `include/uapi/linux/cec.h`, line 340
- [`CEC_CAP_MONITOR_PIN`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-monitor-pin): `include/uapi/linux/cec.h`, line 344
- [`CEC_CAP_NEEDS_HPD`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-needs-hpd): `include/uapi/linux/cec.h`, line 342
- [`CEC_CAP_PASSTHROUGH`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-passthrough): `include/uapi/linux/cec.h`, line 336
- [`CEC_CAP_PHYS_ADDR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-phys-addr): `include/uapi/linux/cec.h`, line 328
- [`CEC_CAP_RC`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-rc): `include/uapi/linux/cec.h`, line 338
- [`CEC_CAP_REPLY_VENDOR_ID`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-reply-vendor-id): `include/uapi/linux/cec.h`, line 348
- [`CEC_CAP_TRANSMIT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-transmit): `include/uapi/linux/cec.h`, line 332
- [`CEC_CONNECTOR_TYPE_DRM`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#rst-cec-connector-type-drm): `include/uapi/linux/cec.h`, line 419
- [`CEC_CONNECTOR_TYPE_NO_CONNECTOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#rst-cec-connector-type-no-connector): `include/uapi/linux/cec.h`, line 418
- [`CEC_EVENT_FL_DROPPED_EVENTS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-fl-dropped-events): `include/uapi/linux/cec.h`, line 453
- [`CEC_EVENT_FL_INITIAL_STATE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-fl-initial-state): `include/uapi/linux/cec.h`, line 452
- [`CEC_EVENT_LOST_MSGS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-lost-msgs): `include/uapi/linux/cec.h`, line 444
- [`CEC_EVENT_PIN_5V_HIGH`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-5v-high): `include/uapi/linux/cec.h`, line 450
- [`CEC_EVENT_PIN_5V_LOW`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-5v-low): `include/uapi/linux/cec.h`, line 449
- [`CEC_EVENT_PIN_CEC_HIGH`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-cec-high): `include/uapi/linux/cec.h`, line 446
- [`CEC_EVENT_PIN_CEC_LOW`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-cec-low): `include/uapi/linux/cec.h`, line 445
- [`CEC_EVENT_PIN_HPD_HIGH`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-hpd-high): `include/uapi/linux/cec.h`, line 448
- [`CEC_EVENT_PIN_HPD_LOW`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-pin-hpd-low): `include/uapi/linux/cec.h`, line 447
- [`CEC_EVENT_STATE_CHANGE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-state-change): `include/uapi/linux/cec.h`, line 439
- [`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-allow-rc-passthru): `include/uapi/linux/cec.h`, line 403
- [`CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-allow-unreg-fallback): `include/uapi/linux/cec.h`, line 401
- [`CEC_LOG_ADDRS_FL_CDC_ONLY`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-cdc-only): `include/uapi/linux/cec.h`, line 405
- [`CEC_LOG_ADDR_TYPE_AUDIOSYSTEM`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-audiosystem): `include/uapi/linux/cec.h`, line 234
- [`CEC_LOG_ADDR_TYPE_PLAYBACK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-playback): `include/uapi/linux/cec.h`, line 233
- [`CEC_LOG_ADDR_TYPE_RECORD`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-record): `include/uapi/linux/cec.h`, line 231
- [`CEC_LOG_ADDR_TYPE_SPECIFIC`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-specific): `include/uapi/linux/cec.h`, line 235
- [`CEC_LOG_ADDR_TYPE_TUNER`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-tuner): `include/uapi/linux/cec.h`, line 232
- [`CEC_LOG_ADDR_TYPE_TV`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-tv): `include/uapi/linux/cec.h`, line 230
- [`CEC_LOG_ADDR_TYPE_UNREGISTERED`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addr-type-unregistered): `include/uapi/linux/cec.h`, line 236
- [`CEC_MODE_EXCL_FOLLOWER`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-excl-follower): `include/uapi/linux/cec.h`, line 320
- [`CEC_MODE_EXCL_FOLLOWER_PASSTHRU`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-excl-follower-passthru): `include/uapi/linux/cec.h`, line 321
- [`CEC_MODE_EXCL_INITIATOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-excl-initiator): `include/uapi/linux/cec.h`, line 314
- [`CEC_MODE_FOLLOWER`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-follower): `include/uapi/linux/cec.h`, line 319
- [`CEC_MODE_INITIATOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-initiator): `include/uapi/linux/cec.h`, line 313
- [`CEC_MODE_MONITOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-monitor): `include/uapi/linux/cec.h`, line 323
- [`CEC_MODE_MONITOR_ALL`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-monitor-all): `include/uapi/linux/cec.h`, line 324
- [`CEC_MODE_MONITOR_PIN`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-monitor-pin): `include/uapi/linux/cec.h`, line 322
- [`CEC_MODE_NO_FOLLOWER`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-no-follower): `include/uapi/linux/cec.h`, line 318
- [`CEC_MODE_NO_INITIATOR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-mode-no-initiator): `include/uapi/linux/cec.h`, line 312
- [`CEC_MSG_FL_RAW`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-msg-fl-raw): `include/uapi/linux/cec.h`, line 171
- [`CEC_MSG_FL_REPLY_TO_FOLLOWERS`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-msg-fl-reply-to-followers): `include/uapi/linux/cec.h`, line 170
- [`CEC_MSG_FL_REPLY_VENDOR_ID`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-msg-fl-reply-vendor-id): `include/uapi/linux/cec.h`, line 172
- [`CEC_RX_STATUS_ABORTED`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-rx-status-aborted): `include/uapi/linux/cec.h`, line 187
- [`CEC_RX_STATUS_FEATURE_ABORT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-rx-status-feature-abort): `include/uapi/linux/cec.h`, line 186
- [`CEC_RX_STATUS_OK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-rx-status-ok): `include/uapi/linux/cec.h`, line 184
- [`CEC_RX_STATUS_TIMEOUT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-rx-status-timeout): `include/uapi/linux/cec.h`, line 185
- [`CEC_TX_STATUS_ABORTED`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-aborted): `include/uapi/linux/cec.h`, line 181
- [`CEC_TX_STATUS_ARB_LOST`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-arb-lost): `include/uapi/linux/cec.h`, line 176
- [`CEC_TX_STATUS_ERROR`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-error): `include/uapi/linux/cec.h`, line 179
- [`CEC_TX_STATUS_LOW_DRIVE`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-low-drive): `include/uapi/linux/cec.h`, line 178
- [`CEC_TX_STATUS_MAX_RETRIES`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-max-retries): `include/uapi/linux/cec.h`, line 180
- [`CEC_TX_STATUS_NACK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-nack): `include/uapi/linux/cec.h`, line 177
- [`CEC_TX_STATUS_OK`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-ok): `include/uapi/linux/cec.h`, line 175
- [`CEC_TX_STATUS_TIMEOUT`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-tx-status-timeout): `include/uapi/linux/cec.h`, line 182

## Structures

- [`cec_caps`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#c-cec_caps): `include/uapi/linux/cec.h`, line 358
- [`cec_connector_info`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#c-cec_connector_info): `include/uapi/linux/cec.h`, line 428
- [`cec_drm_connector_info`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#c-cec_drm_connector_info): `include/uapi/linux/cec.h`, line 413
- [`cec_event`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#c-cec_event): `include/uapi/linux/cec.h`, line 489
- [`cec_event_lost_msgs`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#c-cec_event_lost_msgs): `include/uapi/linux/cec.h`, line 476
- [`cec_event_state_change`](/kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#c-cec_event_state_change): `include/uapi/linux/cec.h`, line 466
- [`cec_log_addrs`](/kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#c-cec_log_addrs): `include/uapi/linux/cec.h`, line 384
- [`cec_msg`](/kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#c-cec_msg): `include/uapi/linux/cec.h`, line 57

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> HDMI connectors provide a single pin for use by the Consumer Electronics Control protocol. This protocol allows different devices connected by an HDMI cable to communicate. The protocol for CEC version 1.4 is defined in supplements 1 (CEC)…

<a id="rst-introduction"></a>
<a id="rst-cec-intro"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

HDMI connectors provide a single pin for use by the Consumer Electronics Control protocol. This protocol allows different devices connected by an HDMI cable to communicate. The protocol for CEC version 1.4 is defined in supplements 1 (CEC) and 2 (HEAC or HDMI Ethernet and Audio Return Channel) of the HDMI 1.4a ([HDMI](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hdmi-1>)) specification and the extensions added to CEC version 2.0 are defined in chapter 11 of the HDMI 2.0 ([HDMI2](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hdmi2-1>)) specification.

The bitrate is very slow (effectively no more than 36 bytes per second) and is based on the ancient AV.link protocol used in old SCART connectors. The protocol closely resembles a crazy Rube Goldberg contraption and is an unholy mix of low and high level messages. Some messages, especially those part of the HEAC protocol layered on top of CEC, need to be handled by the kernel, others can be handled either by the kernel or by userspace.

In addition, CEC can be implemented in HDMI receivers, transmitters and in USB devices that have an HDMI input and an HDMI output and that control just the CEC pin.

Drivers that support CEC will create a CEC device node (/dev/cecX) to give userspace access to the CEC adapter. The [ioctl CEC_ADAP_G_CAPS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-adap-g-caps>) ioctl will tell userspace what it is allowed to do.

In order to check the support and test it, it is suggested to download the [v4l-utils](<https://git.linuxtv.org/v4l-utils.git/>)<a id="rst-v4l-utils"></a> package. It provides three tools to handle CEC:

- cec-ctl: the Swiss army knife of CEC. Allows you to configure, transmit and monitor CEC messages.

- cec-compliance: does a CEC compliance test of a remote CEC device to determine how compliant the CEC implementation is.

- cec-follower: emulates a CEC follower.

---

# ioctl CEC_ADAP_G_CAPS

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_ADAP_G_CAPS - Query device capabilities

<a id="rst-ioctl-cec-adap-g-caps"></a>
<a id="rst-cec-adap-g-caps"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

CEC_ADAP_G_CAPS - Query device capabilities

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

## Synopsis





<a id="c-CEC_ADAP_G_CAPS"></a>

```c
CEC_ADAP_G_CAPS
```

`int ioctl(int fd, CEC_ADAP_G_CAPS, struct cec_caps *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

`argp`

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

## Description

All cec devices must support [ioctl CEC_ADAP_G_CAPS](<#rst-cec-adap-g-caps>). To query device information, applications call the ioctl with a pointer to a struct `cec_caps`. The driver fills the structure and returns the information to the application. The ioctl never fails.

<!-- tabularcolumns: |p{1.2cm}|p{2.5cm}|p{13.6cm}| -->





<a id="c-cec_caps"></a>

```c
cec_caps
```


<table>
<caption>struct cec_caps</caption>
<tbody>
<tr>
<td>


char

</td>
<td>


`driver[32]`

</td>
<td>


The name of the cec adapter driver.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`name[32]`

</td>
<td>


The name of this CEC adapter. The combination `driver` and `name` must be unique.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`available_log_addrs`

</td>
<td>


The maximum number of logical addresses that can be configured.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capabilities`

</td>
<td>


The capabilities of the CEC adapter, see [cec-capabilities](<#rst-cec-capabilities>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`version`

</td>
<td>


CEC Framework API version, formatted with the `KERNEL_VERSION()` macro.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{2.5cm}|p{10.4cm}| -->

<a id="rst-cec-capabilities"></a>


<table>
<caption>CEC Capabilities Flags</caption>
<tbody>
<tr>
<td>


`CEC_CAP_PHYS_ADDR`

</td>
<td>


0x00000001

</td>
<td>


<a id="rst-cec-cap-phys-addr"></a>

Userspace has to configure the physical address by calling [ioctl CEC_ADAP_S_PHYS_ADDR](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-s-phys-addr>). If this capability isn't set, then setting the physical address is handled by the kernel whenever the EDID is set (for an HDMI receiver) or read (for an HDMI transmitter).

</td>
</tr>
<tr>
<td>


`CEC_CAP_LOG_ADDRS`

</td>
<td>


0x00000002

</td>
<td>


<a id="rst-cec-cap-log-addrs"></a>

Userspace has to configure the logical addresses by calling [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>). If this capability isn't set, then the kernel will have configured this.

</td>
</tr>
<tr>
<td>


`CEC_CAP_TRANSMIT`

</td>
<td>


0x00000004

</td>
<td>


<a id="rst-cec-cap-transmit"></a>

Userspace can transmit CEC messages by calling [ioctl CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>). This implies that userspace can be a follower as well, since being able to transmit messages is a prerequisite of becoming a follower. If this capability isn't set, then the kernel will handle all CEC transmits and process all CEC messages it receives.

</td>
</tr>
<tr>
<td>


`CEC_CAP_PASSTHROUGH`

</td>
<td>


0x00000008

</td>
<td>


<a id="rst-cec-cap-passthrough"></a>

Userspace can use the passthrough mode by calling [ioctl CEC_S_MODE](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-s-mode>).

</td>
</tr>
<tr>
<td>


`CEC_CAP_RC`

</td>
<td>


0x00000010

</td>
<td>


<a id="rst-cec-cap-rc"></a>

This adapter supports the remote control protocol.

</td>
</tr>
<tr>
<td>


`CEC_CAP_MONITOR_ALL`

</td>
<td>


0x00000020

</td>
<td>


<a id="rst-cec-cap-monitor-all"></a>

The CEC hardware can monitor all messages, not just directed and broadcast messages.

</td>
</tr>
<tr>
<td>


`CEC_CAP_NEEDS_HPD`

</td>
<td>


0x00000040

</td>
<td>


<a id="rst-cec-cap-needs-hpd"></a>

The CEC hardware is only active if the HDMI Hotplug Detect pin is high. This makes it impossible to use CEC to wake up displays that set the HPD pin low when in standby mode, but keep the CEC bus alive.

</td>
</tr>
<tr>
<td>


`CEC_CAP_MONITOR_PIN`

</td>
<td>


0x00000080

</td>
<td>


<a id="rst-cec-cap-monitor-pin"></a>

The CEC hardware can monitor CEC pin changes from low to high voltage and vice versa. When in pin monitoring mode the application will receive `CEC_EVENT_PIN_CEC_LOW` and `CEC_EVENT_PIN_CEC_HIGH` events.

</td>
</tr>
<tr>
<td>


`CEC_CAP_CONNECTOR_INFO`

</td>
<td>


0x00000100

</td>
<td>


<a id="rst-cec-cap-connector-info"></a>

If this capability is set, then [ioctl CEC_ADAP_G_CONNECTOR_INFO](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-conn-info.md#rst-cec-adap-g-connector-info>) can be used.

</td>
</tr>
<tr>
<td>


`CEC_CAP_REPLY_VENDOR_ID`

</td>
<td>


0x00000200

</td>
<td>


<a id="rst-cec-cap-reply-vendor-id"></a>

If this capability is set, then [CEC_MSG_FL_REPLY_VENDOR_ID](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-msg-flags>) can be used.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl CEC_ADAP_G_CONNECTOR_INFO

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_ADAP_G_CONNECTOR_INFO - Query HDMI connector information

<a id="rst-ioctl-cec-adap-g-connector-info"></a>
<a id="rst-cec-adap-g-connector-info"></a>

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

<!--  -->

<!-- Copyright 2019 Google LLC -->

<!--  -->

<!-- c:namespace: CEC -->

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

## Name

CEC_ADAP_G_CONNECTOR_INFO - Query HDMI connector information

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

## Synopsis





<a id="c-CEC_ADAP_G_CONNECTOR_INFO"></a>

```c
CEC_ADAP_G_CONNECTOR_INFO
```

`int ioctl(int fd, CEC_ADAP_G_CONNECTOR_INFO, struct cec_connector_info *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

`argp`

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

## Description

Using this ioctl an application can learn which HDMI connector this CEC device corresponds to. While calling this ioctl the application should provide a pointer to a cec_connector_info struct which will be populated by the kernel with the info provided by the adapter's driver. This ioctl is only available if the `CEC_CAP_CONNECTOR_INFO` capability is set.

<!-- tabularcolumns: |p{1.0cm}|p{4.4cm}|p{2.5cm}|p{9.2cm}| -->





<a id="c-cec_connector_info"></a>

```c
cec_connector_info
```


<table>
<caption>struct cec_connector_info</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


The type of connector this adapter is associated with.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


`(anonymous)`

</td>
</tr>
<tr>
<td>


`struct cec_drm_connector_info`

</td>
<td>


drm

</td>
<td>


[cec-drm-connector-info](<#rst-cec-drm-connector-info>)

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{2.5cm}|p{10.4cm}| -->

<a id="rst-connector-type"></a>


<table>
<caption>Connector types</caption>
<tbody>
<tr>
<td>


`CEC_CONNECTOR_TYPE_NO_CONNECTOR`

</td>
<td>


0

</td>
<td>


<a id="rst-cec-connector-type-no-connector"></a>

No connector is associated with the adapter/the information is not provided by the driver.

</td>
</tr>
<tr>
<td>


`CEC_CONNECTOR_TYPE_DRM`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-connector-type-drm"></a>

Indicates that a DRM connector is associated with this adapter. Information about the connector can be found in [cec-drm-connector-info](<#rst-cec-drm-connector-info>).

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{2.5cm}|p{10.4cm}| -->





<a id="c-cec_drm_connector_info"></a>

```c
cec_drm_connector_info
```

<a id="rst-cec-drm-connector-info"></a>


<table>
<caption>struct cec_drm_connector_info</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`card_no`

</td>
<td>


<a id="rst-cec-drm-connector-type-card-no"></a>

DRM card number: the number from a card's path, e.g. 0 in case of /dev/card0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`connector_id`

</td>
<td>


<a id="rst-cec-drm-connector-type-connector-id"></a>

DRM connector ID.

</td>
</tr>
</tbody>
</table>

---

# ioctls CEC_ADAP_G_LOG_ADDRS and CEC_ADAP_S_LOG_ADDRS

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_ADAP_G_LOG_ADDRS, CEC_ADAP_S_LOG_ADDRS - Get or set the logical addresses

<a id="rst-ioctls-cec-adap-g-log-addrs-and-cec-adap-s-log-addrs"></a>
<a id="rst-cec-adap-s-log-addrs"></a>
<a id="rst-cec-adap-g-log-addrs"></a>
<a id="rst-cec-adap-log-addrs"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

CEC_ADAP_G_LOG_ADDRS, CEC_ADAP_S_LOG_ADDRS - Get or set the logical addresses

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

## Synopsis





<a id="c-CEC_ADAP_G_LOG_ADDRS"></a>

```c
CEC_ADAP_G_LOG_ADDRS
```

`int ioctl(int fd, CEC_ADAP_G_LOG_ADDRS, struct cec_log_addrs *argp)`





<a id="c-CEC_ADAP_S_LOG_ADDRS"></a>

```c
CEC_ADAP_S_LOG_ADDRS
```

`int ioctl(int fd, CEC_ADAP_S_LOG_ADDRS, struct cec_log_addrs *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `cec_log_addrs`.

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

## Description

To query the current CEC logical addresses, applications call [ioctl CEC_ADAP_G_LOG_ADDRS](<#rst-cec-adap-g-log-addrs>) with a pointer to a struct `cec_log_addrs` where the driver stores the logical addresses.

To set new logical addresses, applications fill in struct `cec_log_addrs` and call [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) with a pointer to this struct. The [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) is only available if `CEC_CAP_LOG_ADDRS` is set (the `ENOTTY` error code is returned otherwise). The [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) can only be called by a file descriptor in initiator mode (see [ioctls CEC_G_MODE and CEC_S_MODE](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-s-mode>)), if not the `EBUSY` error code will be returned.

To clear existing logical addresses set `num_log_addrs` to 0. All other fields will be ignored in that case. The adapter will go to the unconfigured state and the `cec_version`, `vendor_id` and `osd_name` fields are all reset to their default values (CEC version 2.0, no vendor ID and an empty OSD name).

If the physical address is valid (see [ioctl CEC_ADAP_S_PHYS_ADDR](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-phys-addr.md#rst-cec-adap-s-phys-addr>)), then this ioctl will block until all requested logical addresses have been claimed. If the file descriptor is in non-blocking mode then it will not wait for the logical addresses to be claimed, instead it just returns 0.

A [CEC_EVENT_STATE_CHANGE](</kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-state-change>) event is sent when the logical addresses are claimed or cleared.

Attempting to call [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) when logical address types are already defined will return with error `EBUSY`.





<a id="c-cec_log_addrs"></a>

```c
cec_log_addrs
```

<!-- tabularcolumns: |p{1.0cm}|p{8.0cm}|p{8.0cm}| -->


<table>
<caption>struct cec_log_addrs</caption>
<tbody>
<tr>
<td>


\__u8

</td>
<td>


`log_addr[CEC_MAX_LOG_ADDRS]`

</td>
<td>


The actual logical addresses that were claimed. This is set by the driver. If no logical address could be claimed, then it is set to `CEC_LOG_ADDR_INVALID`. If this adapter is Unregistered, then `log_addr[0]` is set to 0xf and all others to `CEC_LOG_ADDR_INVALID`.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`log_addr_mask`

</td>
<td>


The bitmask of all logical addresses this adapter has claimed. If this adapter is Unregistered then `log_addr_mask` sets bit 15 and clears all other bits. If this adapter is not configured at all, then `log_addr_mask` is set to 0. Set by the driver.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`cec_version`

</td>
<td>


The CEC version that this adapter shall use. See [cec-versions](<#rst-cec-versions>). Used to implement the `CEC_MSG_CEC_VERSION` and `CEC_MSG_REPORT_FEATURES` messages. Note that [CEC_OP_CEC_VERSION_1_3A](<#rst-cec-op-cec-version-1-3a>) is not allowed by the CEC framework.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`num_log_addrs`

</td>
<td>


Number of logical addresses to set up. Must be ≤ `available_log_addrs` as returned by [ioctl CEC_ADAP_G_CAPS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-adap-g-caps>). All arrays in this structure are only filled up to index `available_log_addrs`-1. The remaining array elements will be ignored. Note that the CEC 2.0 standard allows for a maximum of 2 logical addresses, although some hardware has support for more. `CEC_MAX_LOG_ADDRS` is 4. The driver will return the actual number of logical addresses it could claim, which may be less than what was requested. If this field is set to 0, then the CEC adapter shall clear all claimed logical addresses and all other fields will be ignored.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`vendor_id`

</td>
<td>


The vendor ID is a 24-bit number that identifies the specific vendor or entity. Based on this ID vendor specific commands may be defined. If you do not want a vendor ID then set it to `CEC_VENDOR_ID_NONE`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags. See [cec-log-addrs-flags](<#rst-cec-log-addrs-flags>) for a list of available flags.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`osd_name[15]`

</td>
<td>


The On-Screen Display name as is returned by the `CEC_MSG_SET_OSD_NAME` message.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`primary_device_type[CEC_MAX_LOG_ADDRS]`

</td>
<td>


Primary device type for each logical address. See [cec-prim-dev-types](<#rst-cec-prim-dev-types>) for possible types.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`log_addr_type[CEC_MAX_LOG_ADDRS]`

</td>
<td>


Logical address types. See [cec-log-addr-types](<#rst-cec-log-addr-types>) for possible types. The driver will update this with the actual logical address type that it claimed (e.g. it may have to fallback to [CEC_LOG_ADDR_TYPE_UNREGISTERED](<#rst-cec-log-addr-type-unregistered>)).

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`all_device_types[CEC_MAX_LOG_ADDRS]`

</td>
<td>


CEC 2.0 specific: the bit mask of all device types. See [cec-all-dev-types-flags](<#rst-cec-all-dev-types-flags>). It is used in the CEC 2.0 `CEC_MSG_REPORT_FEATURES` message. For CEC 1.4 you can either leave this field to 0, or fill it in according to the CEC 2.0 guidelines to give the CEC framework more information about the device type, even though the framework won't use it directly in the CEC message.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`features[CEC_MAX_LOG_ADDRS][12]`

</td>
<td>


Features for each logical address. It is used in the CEC 2.0 `CEC_MSG_REPORT_FEATURES` message. The 12 bytes include both the RC Profile and the Device Features. For CEC 1.4 you can either leave this field to all 0, or fill it in according to the CEC 2.0 guidelines to give the CEC framework more information about the device type, even though the framework won't use it directly in the CEC message.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.8cm}|p{1.0cm}|p{8.5cm}| -->

<a id="rst-cec-log-addrs-flags"></a>


<table>
<caption>Flags for struct cec_log_addrs</caption>
<tbody>
<tr>
<td>


`CEC_LOG_ADDRS_FL_ALLOW_UNREG_FALLBACK`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-log-addrs-fl-allow-unreg-fallback"></a>

By default if no logical address of the requested type can be claimed, then it will go back to the unconfigured state. If this flag is set, then it will fallback to the Unregistered logical address. Note that if the Unregistered logical address was explicitly requested, then this flag has no effect.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-log-addrs-fl-allow-rc-passthru"></a>

By default the `CEC_MSG_USER_CONTROL_PRESSED` and `CEC_MSG_USER_CONTROL_RELEASED` messages are only passed on to the follower(s), if any. If this flag is set, then these messages are also passed on to the remote control input subsystem and will appear as keystrokes. This features needs to be enabled explicitly. If CEC is used to enter e.g. passwords, then you may not want to enable this to avoid trivial snooping of the keystrokes.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDRS_FL_CDC_ONLY`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-log-addrs-fl-cdc-only"></a>

If this flag is set, then the device is CDC-Only. CDC-Only CEC devices are CEC devices that can only handle CDC messages.

All other messages are ignored.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.8cm}|p{1.0cm}|p{8.5cm}| -->

<a id="rst-cec-versions"></a>


<table>
<caption>CEC Versions</caption>
<tbody>
<tr>
<td>


`CEC_OP_CEC_VERSION_1_3A`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-op-cec-version-1-3a"></a>

CEC version according to the HDMI 1.3a standard.

</td>
</tr>
<tr>
<td>


`CEC_OP_CEC_VERSION_1_4B`

</td>
<td>


5

</td>
<td>


<a id="rst-cec-op-cec-version-1-4b"></a>

CEC version according to the HDMI 1.4b standard.

</td>
</tr>
<tr>
<td>


`CEC_OP_CEC_VERSION_2_0`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-op-cec-version-2-0"></a>

CEC version according to the HDMI 2.0 standard.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-cec-prim-dev-types"></a>


<table>
<caption>CEC Primary Device Types</caption>
<tbody>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_TV`

</td>
<td>


0

</td>
<td>


<a id="rst-cec-op-prim-devtype-tv"></a>

Use for a TV.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_RECORD`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-op-prim-devtype-record"></a>

Use for a recording device.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_TUNER`

</td>
<td>


3

</td>
<td>


<a id="rst-cec-op-prim-devtype-tuner"></a>

Use for a device with a tuner.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_PLAYBACK`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-op-prim-devtype-playback"></a>

Use for a playback device.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM`

</td>
<td>


5

</td>
<td>


<a id="rst-cec-op-prim-devtype-audiosystem"></a>

Use for an audio system (e.g. an audio/video receiver).

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_SWITCH`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-op-prim-devtype-switch"></a>

Use for a CEC switch.

</td>
</tr>
<tr>
<td>


`CEC_OP_PRIM_DEVTYPE_VIDEOPROC`

</td>
<td>


7

</td>
<td>


<a id="rst-cec-op-prim-devtype-videoproc"></a>

Use for a video processor device.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-cec-log-addr-types"></a>


<table>
<caption>CEC Logical Address Types</caption>
<tbody>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_TV`

</td>
<td>


0

</td>
<td>


<a id="rst-cec-log-addr-type-tv"></a>

Use for a TV.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_RECORD`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-log-addr-type-record"></a>

Use for a recording device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_TUNER`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-log-addr-type-tuner"></a>

Use for a tuner device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_PLAYBACK`

</td>
<td>


3

</td>
<td>


<a id="rst-cec-log-addr-type-playback"></a>

Use for a playback device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_AUDIOSYSTEM`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-log-addr-type-audiosystem"></a>

Use for an audio system device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_SPECIFIC`

</td>
<td>


5

</td>
<td>


<a id="rst-cec-log-addr-type-specific"></a>

Use for a second TV or for a video processor device.

</td>
</tr>
<tr>
<td>


`CEC_LOG_ADDR_TYPE_UNREGISTERED`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-log-addr-type-unregistered"></a>

Use this if you just want to remain unregistered. Used for pure CEC switches or CDC-only devices (CDC: Capability Discovery and Control).

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-cec-all-dev-types-flags"></a>


<table>
<caption>CEC All Device Types Flags</caption>
<tbody>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_TV`

</td>
<td>


0x80

</td>
<td>


<a id="rst-cec-op-all-devtype-tv"></a>

This supports the TV type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_RECORD`

</td>
<td>


0x40

</td>
<td>


<a id="rst-cec-op-all-devtype-record"></a>

This supports the Recording type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_TUNER`

</td>
<td>


0x20

</td>
<td>


<a id="rst-cec-op-all-devtype-tuner"></a>

This supports the Tuner type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_PLAYBACK`

</td>
<td>


0x10

</td>
<td>


<a id="rst-cec-op-all-devtype-playback"></a>

This supports the Playback type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM`

</td>
<td>


0x08

</td>
<td>


<a id="rst-cec-op-all-devtype-audiosystem"></a>

This supports the Audio System type.

</td>
</tr>
<tr>
<td>


`CEC_OP_ALL_DEVTYPE_SWITCH`

</td>
<td>


0x04

</td>
<td>


<a id="rst-cec-op-all-devtype-switch"></a>

This supports the CEC Switch or Video Processing type.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_ADAP_S_LOG_ADDRS](<#rst-cec-adap-s-log-addrs>) can return the following error codes:

- **ENOTTY**

  The `CEC_CAP_LOG_ADDRS` capability wasn't set, so this ioctl is not supported.

- **EBUSY**

  The CEC adapter is currently configuring itself, or it is already configured and `num_log_addrs` is non-zero, or another filehandle is in exclusive follower or initiator mode, or the filehandle is in mode `CEC_MODE_NO_INITIATOR`.

- **EINVAL**

  The contents of struct `cec_log_addrs` is invalid.

---

# ioctls CEC_ADAP_G_PHYS_ADDR and CEC_ADAP_S_PHYS_ADDR

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_ADAP_G_PHYS_ADDR, CEC_ADAP_S_PHYS_ADDR - Get or set the physical address

<a id="rst-ioctls-cec-adap-g-phys-addr-and-cec-adap-s-phys-addr"></a>
<a id="rst-cec-adap-s-phys-addr"></a>
<a id="rst-cec-adap-g-phys-addr"></a>
<a id="rst-cec-adap-phys-addr"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

CEC_ADAP_G_PHYS_ADDR, CEC_ADAP_S_PHYS_ADDR - Get or set the physical address

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

## Synopsis





<a id="c-CEC_ADAP_G_PHYS_ADDR"></a>

```c
CEC_ADAP_G_PHYS_ADDR
```

`int ioctl(int fd, CEC_ADAP_G_PHYS_ADDR, __u16 *argp)`





<a id="c-CEC_ADAP_S_PHYS_ADDR"></a>

```c
CEC_ADAP_S_PHYS_ADDR
```

`int ioctl(int fd, CEC_ADAP_S_PHYS_ADDR, __u16 *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to the CEC address.

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

## Description

To query the current physical address applications call [ioctl CEC_ADAP_G_PHYS_ADDR](<#rst-cec-adap-g-phys-addr>) with a pointer to a \__u16 where the driver stores the physical address.

To set a new physical address applications store the physical address in a \__u16 and call [ioctl CEC_ADAP_S_PHYS_ADDR](<#rst-cec-adap-s-phys-addr>) with a pointer to this integer. The [ioctl CEC_ADAP_S_PHYS_ADDR](<#rst-cec-adap-s-phys-addr>) is only available if `CEC_CAP_PHYS_ADDR` is set (the `ENOTTY` error code will be returned otherwise). The [ioctl CEC_ADAP_S_PHYS_ADDR](<#rst-cec-adap-s-phys-addr>) can only be called by a file descriptor in initiator mode (see [ioctls CEC_G_MODE and CEC_S_MODE](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-s-mode>)), if not the `EBUSY` error code will be returned.

To clear an existing physical address use `CEC_PHYS_ADDR_INVALID`. The adapter will go to the unconfigured state.

If logical address types have been defined (see [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>)), then this ioctl will block until all requested logical addresses have been claimed. If the file descriptor is in non-blocking mode then it will not wait for the logical addresses to be claimed, instead it just returns 0.

A [CEC_EVENT_STATE_CHANGE](</kernel/userspace/userspace-api/media-cec/cec-ioc-dqevent.md#rst-cec-event-state-change>) event is sent when the physical address changes.

The physical address is a 16-bit number where each group of 4 bits represent a digit of the physical address a.b.c.d where the most significant 4 bits represent 'a'. The CEC root device (usually the TV) has address 0.0.0.0. Every device that is hooked up to an input of the TV has address a.0.0.0 (where 'a' is ≥ 1), devices hooked up to those in turn have addresses a.b.0.0, etc. So a topology of up to 5 devices deep is supported. The physical address a device shall use is stored in the EDID of the sink.

For example, the EDID for each HDMI input of the TV will have a different physical address of the form a.0.0.0 that the sources will read out and use as their physical address.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_ADAP_S_PHYS_ADDR](<#rst-cec-adap-s-phys-addr>) can return the following error codes:

- **ENOTTY**

  The `CEC_CAP_PHYS_ADDR` capability wasn't set, so this ioctl is not supported.

- **EBUSY**

  Another filehandle is in exclusive follower or initiator mode, or the filehandle is in mode `CEC_MODE_NO_INITIATOR`.

- **EINVAL**

  The physical address is malformed.

---

# ioctl CEC_DQEVENT

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_DQEVENT - Dequeue a CEC event

<a id="rst-ioctl-cec-dqevent"></a>
<a id="rst-cec-dqevent"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

CEC_DQEVENT - Dequeue a CEC event

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

## Synopsis





<a id="c-CEC_DQEVENT"></a>

```c
CEC_DQEVENT
```

`int ioctl(int fd, CEC_DQEVENT, struct cec_event *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

`argp`

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

## Description

CEC devices can send asynchronous events. These can be retrieved by calling `CEC_DQEVENT()`. If the file descriptor is in non-blocking mode and no event is pending, then it will return -1 and set errno to the `EAGAIN` error code.

The internal event queues are per-filehandle and per-event type. If there is no more room in a queue then the last event is overwritten with the new one. This means that intermediate results can be thrown away but that the latest event is always available. This also means that is it possible to read two successive events that have the same value (e.g. two [CEC_EVENT_STATE_CHANGE](<#rst-cec-event-state-change>) events with the same state). In that case the intermediate state changes were lost but it is guaranteed that the state did change in between the two events.

<!-- tabularcolumns: |p{1.2cm}|p{2.9cm}|p{13.2cm}| -->





<a id="c-cec_event_state_change"></a>

```c
cec_event_state_change
```


<table>
<caption>struct cec_event_state_change</caption>
<tbody>
<tr>
<td>


\__u16

</td>
<td>


`phys_addr`

</td>
<td>


The current physical address. This is `CEC_PHYS_ADDR_INVALID` if no valid physical address is set.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`log_addr_mask`

</td>
<td>


The current set of claimed logical addresses. This is 0 if no logical addresses are claimed or if `phys_addr` is `CEC_PHYS_ADDR_INVALID`. If bit 15 is set (`1 << CEC_LOG_ADDR_UNREGISTERED`) then this device has the unregistered logical address. In that case all other bits are 0.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`have_conn_info`

</td>
<td>


If non-zero, then HDMI connector information is available. This field is only valid if `CEC_CAP_CONNECTOR_INFO` is set. If that capability is set and `have_conn_info` is zero, then that indicates that the HDMI connector device is not instantiated, either because the HDMI driver is still configuring the device or because the HDMI device was unbound.

</td>
</tr>
</tbody>
</table>





<a id="c-cec_event_lost_msgs"></a>

```c
cec_event_lost_msgs
```

<!-- tabularcolumns: |p{1.0cm}|p{2.0cm}|p{14.3cm}| -->


<table>
<caption>struct cec_event_lost_msgs</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`lost_msgs`

</td>
<td>


Set to the number of lost messages since the filehandle was opened or since the last time this event was dequeued for this filehandle. The messages lost are the oldest messages. So when a new message arrives and there is no more room, then the oldest message is discarded to make room for the new one. The internal size of the message queue guarantees that all messages received in the last two seconds will be stored. Since messages should be replied to within a second according to the CEC specification, this is more than enough.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.0cm}|p{4.4cm}|p{2.5cm}|p{9.2cm}| -->





<a id="c-cec_event"></a>

```c
cec_event
```


<table>
<caption>struct cec_event</caption>
<tbody>
<tr>
<td>


\__u64

</td>
<td>


`ts`

</td>
<td>


Timestamp of the event in ns.

The timestamp has been taken from the `CLOCK_MONOTONIC` clock.

To access the same clock from userspace use `clock_gettime()`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`event`

</td>
<td>


The CEC event type, see [cec-events](<#rst-cec-events>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Event flags, see [cec-event-flags](<#rst-cec-event-flags>).

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


(anonymous)

</td>
</tr>
<tr>
<td>


struct cec_event_state_change

</td>
<td>


`state_change`

</td>
<td>


The new adapter state as sent by the [CEC_EVENT_STATE_CHANGE](<#rst-cec-event-state-change>) event.

</td>
</tr>
<tr>
<td>


struct cec_event_lost_msgs

</td>
<td>


`lost_msgs`

</td>
<td>


The number of lost messages as sent by the [CEC_EVENT_LOST_MSGS](<#rst-cec-event-lost-msgs>) event.

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.6cm}|p{0.9cm}|p{10.8cm}| -->

<a id="rst-cec-events"></a>


<table>
<caption>CEC Events Types</caption>
<tbody>
<tr>
<td>


`CEC_EVENT_STATE_CHANGE`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-event-state-change"></a>

Generated when the CEC Adapter's state changes. When open() is called an initial event will be generated for that filehandle with the CEC Adapter's state at that time.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_LOST_MSGS`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-event-lost-msgs"></a>

Generated if one or more CEC messages were lost because the application didn't dequeue CEC messages fast enough.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_CEC_LOW`

</td>
<td>


3

</td>
<td>


<a id="rst-cec-event-pin-cec-low"></a>

Generated if the CEC pin goes from a high voltage to a low voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_CEC_HIGH`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-event-pin-cec-high"></a>

Generated if the CEC pin goes from a low voltage to a high voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_HPD_LOW`

</td>
<td>


5

</td>
<td>


<a id="rst-cec-event-pin-hpd-low"></a>

Generated if the HPD pin goes from a high voltage to a low voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set. When open() is called, the HPD pin can be read and if the HPD is low, then an initial event will be generated for that filehandle.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_HPD_HIGH`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-event-pin-hpd-high"></a>

Generated if the HPD pin goes from a low voltage to a high voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set. When open() is called, the HPD pin can be read and if the HPD is high, then an initial event will be generated for that filehandle.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_5V_LOW`

</td>
<td>


6

</td>
<td>


<a id="rst-cec-event-pin-5v-low"></a>

Generated if the 5V pin goes from a high voltage to a low voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set. When open() is called, the 5V pin can be read and if the 5V is low, then an initial event will be generated for that filehandle.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_PIN_5V_HIGH`

</td>
<td>


7

</td>
<td>


<a id="rst-cec-event-pin-5v-high"></a>

Generated if the 5V pin goes from a low voltage to a high voltage. Only applies to adapters that have the `CEC_CAP_MONITOR_PIN` capability set. When open() is called, the 5V pin can be read and if the 5V is high, then an initial event will be generated for that filehandle.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.0cm}|p{0.6cm}|p{10.7cm}| -->

<a id="rst-cec-event-flags"></a>


<table>
<caption>CEC Event Flags</caption>
<tbody>
<tr>
<td>


`CEC_EVENT_FL_INITIAL_STATE`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-event-fl-initial-state"></a>

Set for the initial events that are generated when the device is opened. See the table above for which events do this. This allows applications to learn the initial state of the CEC adapter at open() time.

</td>
</tr>
<tr>
<td>


`CEC_EVENT_FL_DROPPED_EVENTS`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-event-fl-dropped-events"></a>

Set if one or more events of the given event type have been dropped. This is an indication that the application cannot keep up.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_DQEVENT](<#rst-cec-dqevent>) can return the following error codes:

- **EAGAIN**

  This is returned when the filehandle is in non-blocking mode and there are no pending events.

- **ERESTARTSYS**

  An interrupt (e.g. Ctrl-C) arrived while in blocking mode waiting for events to arrive.

---

# ioctls CEC_G_MODE and CEC_S_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_G_MODE, CEC_S_MODE - Get or set exclusive use of the CEC adapter

> **Peios:** Linux capability names in this interface retain their API meaning, but KACS evaluates them through native token privileges or compatibility rules. UID 0, `setcap` and Unix mode bits do not independently grant native authority. Object access and PIP checks remain additional constraints where applicable. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for the mapping and exceptions.


<a id="rst-ioctls-cec-g-mode-and-cec-s-mode"></a>
<a id="rst-cec-s-mode"></a>
<a id="rst-cec-g-mode"></a>
<a id="rst-cec-mode"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

CEC_G_MODE, CEC_S_MODE - Get or set exclusive use of the CEC adapter

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

## Synopsis





<a id="c-CEC_G_MODE"></a>

```c
CEC_G_MODE
```

`int ioctl(int fd, CEC_G_MODE, __u32 *argp)`





<a id="c-CEC_S_MODE"></a>

```c
CEC_S_MODE
```

`int ioctl(int fd, CEC_S_MODE, __u32 *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to CEC mode.

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

## Description

By default any filehandle can use [ioctls CEC_RECEIVE and CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>), but in order to prevent applications from stepping on each others toes it must be possible to obtain exclusive access to the CEC adapter. This ioctl sets the filehandle to initiator and/or follower mode which can be exclusive depending on the chosen mode. The initiator is the filehandle that is used to initiate messages, i.e. it commands other CEC devices. The follower is the filehandle that receives messages sent to the CEC adapter and processes them. The same filehandle can be both initiator and follower, or this role can be taken by two different filehandles.

When a CEC message is received, then the CEC framework will decide how it will be processed. If the message is a reply to an earlier transmitted message, then the reply is sent back to the filehandle that is waiting for it. In addition the CEC framework will process it.

If the message is not a reply, then the CEC framework will process it first. If there is no follower, then the message is just discarded and a feature abort is sent back to the initiator if the framework couldn't process it. If there is a follower, then the message is passed on to the follower who will use [ioctl CEC_RECEIVE](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-receive>) to dequeue the new message. The framework expects the follower to make the right decisions.

The CEC framework will process core messages unless requested otherwise by the follower. The follower can enable the passthrough mode. In that case, the CEC framework will pass on most core messages without processing them and the follower will have to implement those messages. There are some messages that the core will always process, regardless of the passthrough mode. See [cec-core-processing](<#rst-cec-core-processing>) for details.

If there is no initiator, then any CEC filehandle can use [ioctl CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>). If there is an exclusive initiator then only that initiator can call [ioctls CEC_RECEIVE and CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>). The follower can of course always call [ioctl CEC_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-receive.md#rst-cec-transmit>).

Available initiator modes are:

<!-- tabularcolumns: |p{5.6cm}|p{0.9cm}|p{10.8cm}| -->

<a id="rst-cec-mode-initiator-e"></a>


<table>
<caption>Initiator Modes</caption>
<tbody>
<tr>
<td>


`CEC_MODE_NO_INITIATOR`

</td>
<td>


0x0

</td>
<td>


<a id="rst-cec-mode-no-initiator"></a>

This is not an initiator, i.e. it cannot transmit CEC messages or make any other changes to the CEC adapter.

</td>
</tr>
<tr>
<td>


`CEC_MODE_INITIATOR`

</td>
<td>


0x1

</td>
<td>


<a id="rst-cec-mode-initiator"></a>

This is an initiator (the default when the device is opened) and it can transmit CEC messages and make changes to the CEC adapter, unless there is an exclusive initiator.

</td>
</tr>
<tr>
<td>


`CEC_MODE_EXCL_INITIATOR`

</td>
<td>


0x2

</td>
<td>


<a id="rst-cec-mode-excl-initiator"></a>

This is an exclusive initiator and this file descriptor is the only one that can transmit CEC messages and make changes to the CEC adapter. If someone else is already the exclusive initiator then an attempt to become one will return the `EBUSY` error code error.

</td>
</tr>
</tbody>
</table>

Available follower modes are:

<!-- tabularcolumns: |p{6.6cm}|p{0.9cm}|p{9.8cm}| -->

<a id="rst-cec-mode-follower-e"></a>


<table>
<caption>Follower Modes</caption>
<tbody>
<tr>
<td>


`CEC_MODE_NO_FOLLOWER`

</td>
<td>


0x00

</td>
<td>


<a id="rst-cec-mode-no-follower"></a>

This is not a follower (the default when the device is opened).

</td>
</tr>
<tr>
<td>


`CEC_MODE_FOLLOWER`

</td>
<td>


0x10

</td>
<td>


<a id="rst-cec-mode-follower"></a>

This is a follower and it will receive CEC messages unless there is an exclusive follower. You cannot become a follower if [CEC_CAP_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-transmit>) is not set or if [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>) was specified, the `EINVAL` error code is returned in that case.

</td>
</tr>
<tr>
<td>


`CEC_MODE_EXCL_FOLLOWER`

</td>
<td>


0x20

</td>
<td>


<a id="rst-cec-mode-excl-follower"></a>

This is an exclusive follower and only this file descriptor will receive CEC messages for processing. If someone else is already the exclusive follower then an attempt to become one will return the `EBUSY` error code. You cannot become a follower if [CEC_CAP_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-transmit>) is not set or if [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>) was specified, the `EINVAL` error code is returned in that case.

</td>
</tr>
<tr>
<td>


`CEC_MODE_EXCL_FOLLOWER_PASSTHRU`

</td>
<td>


0x30

</td>
<td>


<a id="rst-cec-mode-excl-follower-passthru"></a>

This is an exclusive follower and only this file descriptor will receive CEC messages for processing. In addition it will put the CEC device into passthrough mode, allowing the exclusive follower to handle most core messages instead of relying on the CEC framework for that. If someone else is already the exclusive follower then an attempt to become one will return the `EBUSY` error code. You cannot become a follower if [CEC_CAP_TRANSMIT](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-transmit>) is not set or if [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>) was specified, the `EINVAL` error code is returned in that case.

</td>
</tr>
<tr>
<td>


`CEC_MODE_MONITOR_PIN`

</td>
<td>


0xd0

</td>
<td>


<a id="rst-cec-mode-monitor-pin"></a>

Put the file descriptor into pin monitoring mode. Can only be used in combination with [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>), otherwise the `EINVAL` error code will be returned. This mode requires that the [CEC_CAP_MONITOR_PIN](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-monitor-pin>) capability is set, otherwise the `EINVAL` error code is returned. While in pin monitoring mode this file descriptor can receive the `CEC_EVENT_PIN_CEC_LOW` and `CEC_EVENT_PIN_CEC_HIGH` events to see the low-level CEC pin transitions. This is very useful for debugging. This mode is only allowed if the process has the `CAP_NET_ADMIN` capability. If that is not set, then the `EPERM` error code is returned.

</td>
</tr>
<tr>
<td>


`CEC_MODE_MONITOR`

</td>
<td>


0xe0

</td>
<td>


<a id="rst-cec-mode-monitor"></a>

Put the file descriptor into monitor mode. Can only be used in combination with [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>), otherwise the `EINVAL` error code will be returned. In monitor mode all messages this CEC device transmits and all messages it receives (both broadcast messages and directed messages for one its logical addresses) will be reported. This is very useful for debugging. This is only allowed if the process has the `CAP_NET_ADMIN` capability. If that is not set, then the `EPERM` error code is returned.

</td>
</tr>
<tr>
<td>


`CEC_MODE_MONITOR_ALL`

</td>
<td>


0xf0

</td>
<td>


<a id="rst-cec-mode-monitor-all"></a>

Put the file descriptor into 'monitor all' mode. Can only be used in combination with [CEC_MODE_NO_INITIATOR](<#rst-cec-mode-no-initiator>), otherwise the `EINVAL` error code will be returned. In 'monitor all' mode all messages this CEC device transmits and all messages it receives, including directed messages for other CEC devices, will be reported. This is very useful for debugging, but not all devices support this. This mode requires that the [CEC_CAP_MONITOR_ALL](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-monitor-all>) capability is set, otherwise the `EINVAL` error code is returned. This is only allowed if the process has the `CAP_NET_ADMIN` capability. If that is not set, then the `EPERM` error code is returned.

</td>
</tr>
</tbody>
</table>

Core message processing details:

<!-- tabularcolumns: |p{6.6cm}|p{10.9cm}| -->

<a id="rst-cec-core-processing"></a>


<table>
<caption>Core Message Processing</caption>
<tbody>
<tr>
<td>


`CEC_MSG_GET_CEC_VERSION`

</td>
<td>


<a id="rst-cec-msg-get-cec-version"></a>

The core will return the CEC version that was set with [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>), except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_GIVE_DEVICE_VENDOR_ID`

</td>
<td>


<a id="rst-cec-msg-give-device-vendor-id"></a>

The core will return the vendor ID that was set with [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>), except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_ABORT`

</td>
<td>


<a id="rst-cec-msg-abort"></a>

The core will return a Feature Abort message with reason 'Feature Refused' as per the specification, except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_GIVE_PHYSICAL_ADDR`

</td>
<td>


<a id="rst-cec-msg-give-physical-addr"></a>

The core will report the current physical address, except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_GIVE_OSD_NAME`

</td>
<td>


<a id="rst-cec-msg-give-osd-name"></a>

The core will report the current OSD name that was set with [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>), except when in passthrough mode. In passthrough mode the core does nothing and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_GIVE_FEATURES`

</td>
<td>


<a id="rst-cec-msg-give-features"></a>

The core will do nothing if the CEC version is older than 2.0, otherwise it will report the current features that were set with [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>), except when in passthrough mode. In passthrough mode the core does nothing (for any CEC version) and this message has to be handled by a follower instead.

</td>
</tr>
<tr>
<td>


`CEC_MSG_USER_CONTROL_PRESSED`

</td>
<td>


<a id="rst-cec-msg-user-control-pressed"></a>

If [CEC_CAP_RC](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-rc>) is set and if [CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-allow-rc-passthru>) is set, then generate a remote control key press. This message is always passed on to the follower(s).

</td>
</tr>
<tr>
<td>


`CEC_MSG_USER_CONTROL_RELEASED`

</td>
<td>


<a id="rst-cec-msg-user-control-released"></a>

If [CEC_CAP_RC](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-caps.md#rst-cec-cap-rc>) is set and if [CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-log-addrs-fl-allow-rc-passthru>) is set, then generate a remote control key release. This message is always passed on to the follower(s).

</td>
</tr>
<tr>
<td>


`CEC_MSG_REPORT_PHYSICAL_ADDR`

</td>
<td>


<a id="rst-cec-msg-report-physical-addr"></a>

The CEC framework will make note of the reported physical address and then just pass the message on to the follower(s).

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_S_MODE](<#rst-cec-s-mode>) can return the following error codes:

- **EINVAL**

  The requested mode is invalid.

- **EPERM**

  Monitor mode is requested, but the process does have the `CAP_NET_ADMIN` capability.

- **EBUSY**

  Someone else is already an exclusive follower or initiator.

---

# ioctls CEC_RECEIVE and CEC_TRANSMIT

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message

> **Peios:** Linux capability names in this interface retain their API meaning, but KACS evaluates them through native token privileges or compatibility rules. UID 0, `setcap` and Unix mode bits do not independently grant native authority. Object access and PIP checks remain additional constraints where applicable. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for the mapping and exceptions.


<a id="rst-ioctls-cec-receive-and-cec-transmit"></a>
<a id="rst-cec-receive"></a>
<a id="rst-cec-transmit"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: CEC -->

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

## Name

CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message

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

## Synopsis





<a id="c-CEC_RECEIVE"></a>

```c
CEC_RECEIVE
```

`int ioctl(int fd, CEC_RECEIVE, struct cec_msg *argp)`





<a id="c-CEC_TRANSMIT"></a>

```c
CEC_TRANSMIT
```

`int ioctl(int fd, CEC_TRANSMIT, struct cec_msg *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct cec_msg.

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

## Description

To receive a CEC message the application has to fill in the `timeout` field of struct `cec_msg` and pass it to [ioctl CEC_RECEIVE](<#rst-cec-receive>). If the file descriptor is in non-blocking mode and there are no received messages pending, then it will return -1 and set errno to the `EAGAIN` error code. If the file descriptor is in blocking mode and `timeout` is non-zero and no message arrived within `timeout` milliseconds, then it will return -1 and set errno to the `ETIMEDOUT` error code.

A received message can be:

1. a message received from another CEC device (the `sequence` field will be 0, `tx_status` will be 0 and `rx_status` will be non-zero).

2. the transmit result of an earlier non-blocking transmit (the `sequence` field will be non-zero, `tx_status` will be non-zero and `rx_status` will be 0).

3. the reply to an earlier non-blocking transmit (the `sequence` field will be non-zero, `tx_status` will be 0 and `rx_status` will be non-zero).

To send a CEC message the application has to fill in the struct `cec_msg` and pass it to [ioctl CEC_TRANSMIT](<#rst-cec-transmit>). The [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) is only available if `CEC_CAP_TRANSMIT` is set. If there is no more room in the transmit queue, then it will return -1 and set errno to the `EBUSY` error code. The transmit queue has enough room for 18 messages (about 1 second worth of 2-byte messages). Note that the CEC kernel framework will also reply to core messages (see [cec-core-processing](</kernel/userspace/userspace-api/media-cec/cec-ioc-g-mode.md#rst-cec-core-processing>)), so it is not a good idea to fully fill up the transmit queue.

If the file descriptor is in non-blocking mode then the transmit will return 0 and the result of the transmit will be available via [ioctl CEC_RECEIVE](<#rst-cec-receive>) once the transmit has finished. If a non-blocking transmit also specified waiting for a reply, then the reply will arrive in a later message. The `sequence` field can be used to associate both transmit results and replies with the original transmit.

Normally calling [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) when the physical address is invalid (due to e.g. a disconnect) will return `ENONET`.

However, the CEC specification allows sending messages from 'Unregistered' to 'TV' when the physical address is invalid since some TVs pull the hotplug detect pin of the HDMI connector low when they go into standby, or when switching to another input.

When the hotplug detect pin goes low the EDID disappears, and thus the physical address, but the cable is still connected and CEC still works. In order to detect/wake up the device it is allowed to send poll and 'Image/Text View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').

<!-- tabularcolumns: |p{1.0cm}|p{3.5cm}|p{12.8cm}| -->





<a id="c-cec_msg"></a>

```c
cec_msg
```


<table>
<caption>struct cec_msg</caption>
<tbody>
<tr>
<td>


\__u64

</td>
<td>


`tx_ts`

</td>
<td>


Timestamp in ns of when the last byte of the message was transmitted. The timestamp has been taken from the `CLOCK_MONOTONIC` clock. To access the same clock from userspace use `clock_gettime()`.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`rx_ts`

</td>
<td>


Timestamp in ns of when the last byte of the message was received. The timestamp has been taken from the `CLOCK_MONOTONIC` clock. To access the same clock from userspace use `clock_gettime()`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`len`

</td>
<td>


The length of the message. For [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) this is filled in by the application. The driver will fill this in for [ioctl CEC_RECEIVE](<#rst-cec-receive>). For [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) it will be filled in by the driver with the length of the reply message if `reply` was set.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`timeout`

</td>
<td>


The timeout in milliseconds. This is the time the device will wait for a message to be received before timing out. If it is set to 0, then it will wait indefinitely when it is called by [ioctl CEC_RECEIVE](<#rst-cec-receive>). If it is 0 and it is called by [ioctl CEC_TRANSMIT](<#rst-cec-transmit>), then it will be replaced by 1000 if the `reply` is non-zero or ignored if `reply` is 0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`sequence`

</td>
<td>


A non-zero sequence number is automatically assigned by the CEC framework for all transmitted messages. It is used by the CEC framework when it queues the transmit result for a non-blocking transmit. This allows the application to associate the received message with the original transmit.

In addition, if a non-blocking transmit will wait for a reply (ii.e. `timeout` was not 0), then the `sequence` field of the reply will be set to the sequence value of the original transmit. This allows the application to associate the received message with the original transmit.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags. See [cec-msg-flags](<#rst-cec-msg-flags>) for a list of available flags.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`msg[16]`

</td>
<td>


The message payload. For [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) this is filled in by the application. The driver will fill this in for [ioctl CEC_RECEIVE](<#rst-cec-receive>). For [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) it will be filled in by the driver with the payload of the reply message if `timeout` was set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`reply`

</td>
<td>


Wait until this message is replied. If `reply` is 0 and the `timeout` is 0, then don't wait for a reply but return after transmitting the message. Ignored by [ioctl CEC_RECEIVE](<#rst-cec-receive>). The case where `reply` is 0 (this is the opcode for the Feature Abort message) and `timeout` is non-zero is specifically allowed to make it possible to send a message and wait up to `timeout` milliseconds for a Feature Abort reply. In this case `rx_status` will either be set to [CEC_RX_STATUS_TIMEOUT](<#rst-cec-rx-status-timeout>) or [CEC_RX_STATUS_FEATURE_ABORT](<#rst-cec-rx-status-feature-abort>).

If the transmitter message is `CEC_MSG_INITIATE_ARC` then the `reply` values `CEC_MSG_REPORT_ARC_INITIATED` and `CEC_MSG_REPORT_ARC_TERMINATED` are processed differently: either value will match both possible replies. The reason is that the `CEC_MSG_INITIATE_ARC` message is the only CEC message that has two possible replies other than Feature Abort. The `reply` field will be updated with the actual reply so that it is synchronized with the contents of the received message.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`rx_status`

</td>
<td>


The status bits of the received message. See [cec-rx-status](<#rst-cec-rx-status>) for the possible status values.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_status`

</td>
<td>


The status bits of the transmitted message. See [cec-tx-status](<#rst-cec-tx-status>) for the possible status values. When calling [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) in non-blocking mode, this field will be 0 if the transmit started, or non-0 if the transmit result is known immediately. The latter would be the case when attempting to transmit a Poll message to yourself. That results in a [CEC_TX_STATUS_NACK](<#rst-cec-tx-status-nack>) without ever actually transmitting the Poll message.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_arb_lost_cnt`

</td>
<td>


A counter of the number of transmit attempts that resulted in the Arbitration Lost error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the [CEC_TX_STATUS_ARB_LOST](<#rst-cec-tx-status-arb-lost>) status bit is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_nack_cnt`

</td>
<td>


A counter of the number of transmit attempts that resulted in the Not Acknowledged error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the [CEC_TX_STATUS_NACK](<#rst-cec-tx-status-nack>) status bit is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_low_drive_cnt`

</td>
<td>


A counter of the number of transmit attempts that resulted in the Arbitration Lost error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the [CEC_TX_STATUS_LOW_DRIVE](<#rst-cec-tx-status-low-drive>) status bit is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`tx_error_cnt`

</td>
<td>


A counter of the number of transmit errors other than Arbitration Lost or Not Acknowledged. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the [CEC_TX_STATUS_ERROR](<#rst-cec-tx-status-error>) status bit is set.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.2cm}|p{1.0cm}|p{10.1cm}| -->

<a id="rst-cec-msg-flags"></a>


<table>
<caption>Flags for struct cec_msg</caption>
<tbody>
<tr>
<td>


`CEC_MSG_FL_REPLY_TO_FOLLOWERS`

</td>
<td>


1

</td>
<td>


<a id="rst-cec-msg-fl-reply-to-followers"></a>

If a CEC transmit expects a reply, then by default that reply is only sent to the filehandle that called [ioctl CEC_TRANSMIT](<#rst-cec-transmit>). If this flag is set, then the reply is also sent to all followers, if any. If the filehandle that called [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) is also a follower, then that filehandle will receive the reply twice: once as the result of the [ioctl CEC_TRANSMIT](<#rst-cec-transmit>), and once via [ioctl CEC_RECEIVE](<#rst-cec-receive>).

</td>
</tr>
<tr>
<td>


`CEC_MSG_FL_RAW`

</td>
<td>


2

</td>
<td>


<a id="rst-cec-msg-fl-raw"></a>

Normally CEC messages are validated before transmitting them. If this flag is set when [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) is called, then no validation takes place and the message is transmitted as-is. This is useful when debugging CEC issues. This flag is only allowed if the process has the `CAP_SYS_RAWIO` capability. If that is not set, then the `EPERM` error code is returned.

</td>
</tr>
<tr>
<td>


`CEC_MSG_FL_REPLY_VENDOR_ID`

</td>
<td>


4

</td>
<td>


<a id="rst-cec-msg-fl-reply-vendor-id"></a>

This flag is only available if the `CEC_CAP_REPLY_VENDOR_ID` capability is set. If this flag is set, then the reply is expected to consist of the `CEC_MSG_VENDOR_COMMAND_WITH_ID` opcode followed by the Vendor ID (in bytes 1-4 of the message), followed by the `struct cec_msg` `reply` field.

Note that this assumes that the byte after the Vendor ID is a vendor-specific opcode.

This flag makes it easier to wait for replies to vendor commands.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.6cm}|p{0.9cm}|p{10.8cm}| -->

<a id="rst-cec-tx-status"></a>


<table>
<caption>CEC Transmit Status</caption>
<tbody>
<tr>
<td>


`CEC_TX_STATUS_OK`

</td>
<td>


0x01

</td>
<td>


<a id="rst-cec-tx-status-ok"></a>

The message was transmitted successfully. This is mutually exclusive with [CEC_TX_STATUS_MAX_RETRIES](<#rst-cec-tx-status-max-retries>). Other bits can still be set if earlier attempts met with failure before the transmit was eventually successful.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_ARB_LOST`

</td>
<td>


0x02

</td>
<td>


<a id="rst-cec-tx-status-arb-lost"></a>

CEC line arbitration was lost, i.e. another transmit started at the same time with a higher priority. Optional status, not all hardware can detect this error condition.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_NACK`

</td>
<td>


0x04

</td>
<td>


<a id="rst-cec-tx-status-nack"></a>

Message was not acknowledged. Note that some hardware cannot tell apart a 'Not Acknowledged' status from other error conditions, i.e. the result of a transmit is just OK or FAIL. In that case this status will be returned when the transmit failed.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_LOW_DRIVE`

</td>
<td>


0x08

</td>
<td>


<a id="rst-cec-tx-status-low-drive"></a>

Low drive was detected on the CEC bus. This indicates that a follower detected an error on the bus and requests a retransmission. Optional status, not all hardware can detect this error condition.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_ERROR`

</td>
<td>


0x10

</td>
<td>


<a id="rst-cec-tx-status-error"></a>

Some error occurred. This is used for any errors that do not fit `CEC_TX_STATUS_ARB_LOST` or `CEC_TX_STATUS_LOW_DRIVE`, either because the hardware could not tell which error occurred, or because the hardware tested for other conditions besides those two. Optional status.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_MAX_RETRIES`

</td>
<td>


0x20

</td>
<td>


<a id="rst-cec-tx-status-max-retries"></a>

The transmit failed after one or more retries. This status bit is mutually exclusive with [CEC_TX_STATUS_OK](<#rst-cec-tx-status-ok>). Other bits can still be set to explain which failures were seen.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_ABORTED`

</td>
<td>


0x40

</td>
<td>


<a id="rst-cec-tx-status-aborted"></a>

The transmit was aborted due to an HDMI disconnect, or the adapter was unconfigured, or a transmit was interrupted, or the driver returned an error when attempting to start a transmit.

</td>
</tr>
<tr>
<td>


`CEC_TX_STATUS_TIMEOUT`

</td>
<td>


0x80

</td>
<td>


<a id="rst-cec-tx-status-timeout"></a>

The transmit timed out. This should not normally happen and this indicates a driver problem.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.6cm}|p{0.9cm}|p{10.8cm}| -->

<a id="rst-cec-rx-status"></a>


<table>
<caption>CEC Receive Status</caption>
<tbody>
<tr>
<td>


`CEC_RX_STATUS_OK`

</td>
<td>


0x01

</td>
<td>


<a id="rst-cec-rx-status-ok"></a>

The message was received successfully.

</td>
</tr>
<tr>
<td>


`CEC_RX_STATUS_TIMEOUT`

</td>
<td>


0x02

</td>
<td>


<a id="rst-cec-rx-status-timeout"></a>

The reply to an earlier transmitted message timed out.

</td>
</tr>
<tr>
<td>


`CEC_RX_STATUS_FEATURE_ABORT`

</td>
<td>


0x04

</td>
<td>


<a id="rst-cec-rx-status-feature-abort"></a>

The message was received successfully but the reply was `CEC_MSG_FEATURE_ABORT`. This status is only set if this message was the reply to an earlier transmitted message.

</td>
</tr>
<tr>
<td>


`CEC_RX_STATUS_ABORTED`

</td>
<td>


0x08

</td>
<td>


<a id="rst-cec-rx-status-aborted"></a>

The wait for a reply to an earlier transmitted message was aborted because the HDMI cable was disconnected, the adapter was unconfigured or the [CEC_TRANSMIT](<#rst-cec-receive>) that waited for a reply was interrupted.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

The [ioctl CEC_RECEIVE](<#rst-cec-receive>) can return the following error codes:

- **EAGAIN**

  No messages are in the receive queue, and the filehandle is in non-blocking mode.

- **ETIMEDOUT**

  The `timeout` was reached while waiting for a message.

- **ERESTARTSYS**

  The wait for a message was interrupted (e.g. by Ctrl-C).

The [ioctl CEC_TRANSMIT](<#rst-cec-transmit>) can return the following error codes:

- **ENOTTY**

  The `CEC_CAP_TRANSMIT` capability wasn't set, so this ioctl is not supported.

- **EPERM**

  The CEC adapter is not configured, i.e. [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>) has never been called, or `CEC_MSG_FL_RAW` was used from a process that did not have the `CAP_SYS_RAWIO` capability.

- **ENONET**

  The CEC adapter is not configured, i.e. [ioctl CEC_ADAP_S_LOG_ADDRS](</kernel/userspace/userspace-api/media-cec/cec-ioc-adap-g-log-addrs.md#rst-cec-adap-s-log-addrs>) was called, but the physical address is invalid so no logical address was claimed. An exception is made in this case for transmits from initiator 0xf ('Unregistered') to destination 0 ('TV'). In that case the transmit will proceed as usual.

- **EBUSY**

  Another filehandle is in exclusive follower or initiator mode, or the filehandle is in mode `CEC_MODE_NO_INITIATOR`. This is also returned if the transmit queue is full.

- **EINVAL**

  The contents of struct `cec_msg` is invalid.

- **ERESTARTSYS**

  The wait for a successful transmit was interrupted (e.g. by Ctrl-C).

---

# CEC Pin Framework Error Injection

_Peios Kernel / Userspace interfaces / System and device interfaces / HDMI CEC_

> The CEC Pin Framework is a core CEC framework for CEC hardware that only has low-level support for the CEC bus. Most hardware today will have high-level CEC support where the hardware deals with driving the CEC bus, but some older devices…

<a id="rst-cec-pin-framework-error-injection"></a>
<a id="rst-cec-pin-error-inj"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The CEC Pin Framework is a core CEC framework for CEC hardware that only has low-level support for the CEC bus. Most hardware today will have high-level CEC support where the hardware deals with driving the CEC bus, but some older devices aren't that fancy. However, this framework also allows you to connect the CEC pin to a GPIO on e.g. a Raspberry Pi and you have now made a CEC adapter.

What makes doing this so interesting is that since we have full control over the bus it is easy to support error injection. This is ideal to test how well CEC adapters can handle error conditions.

Currently only the cec-gpio driver (when the CEC line is directly connected to a pull-up GPIO line) and the AllWinner A10/A20 drm driver support this framework.

If `CONFIG_CEC_PIN_ERROR_INJ` is enabled, then error injection is available through debugfs. Specifically, in `/sys/kernel/debug/cec/cecX/` there is now an `error-inj` file.

> [!NOTE]
>
> The error injection commands are not a stable ABI and may change in the future.

With `cat error-inj` you can see both the possible commands and the current error injection status:



```text
$ cat /sys/kernel/debug/cec/cec0/error-inj
# Clear error injections:
#   clear          clear all rx and tx error injections
#   rx-clear       clear all rx error injections
#   tx-clear       clear all tx error injections
#   <op> clear     clear all rx and tx error injections for <op>
#   <op> rx-clear  clear all rx error injections for <op>
#   <op> tx-clear  clear all tx error injections for <op>
#
# RX error injection settings:
#   rx-no-low-drive                    do not generate low-drive pulses
#
# RX error injection:
#   <op>[,<mode>] rx-nack              NACK the message instead of sending an ACK
#   <op>[,<mode>] rx-low-drive <bit>   force a low-drive condition at this bit position
#   <op>[,<mode>] rx-add-byte          add a spurious byte to the received CEC message
#   <op>[,<mode>] rx-remove-byte       remove the last byte from the received CEC message
#    any[,<mode>] rx-arb-lost [<poll>] generate a POLL message to trigger an arbitration lost
#
# TX error injection settings:
#   tx-ignore-nack-until-eom           ignore early NACKs until EOM
#   tx-custom-low-usecs <usecs>        define the 'low' time for the custom pulse
#   tx-custom-high-usecs <usecs>       define the 'high' time for the custom pulse
#   tx-custom-pulse                    transmit the custom pulse once the bus is idle
#   tx-glitch-low-usecs <usecs>        define the 'low' time for the glitch pulse
#   tx-glitch-high-usecs <usecs>       define the 'high' time for the glitch pulse
#   tx-glitch-falling-edge             send the glitch pulse after every falling edge
#   tx-glitch-rising-edge              send the glitch pulse after every rising edge
#
# TX error injection:
#   <op>[,<mode>] tx-no-eom            don't set the EOM bit
#   <op>[,<mode>] tx-early-eom         set the EOM bit one byte too soon
#   <op>[,<mode>] tx-add-bytes <num>   append <num> (1-255) spurious bytes to the message
#   <op>[,<mode>] tx-remove-byte       drop the last byte from the message
#   <op>[,<mode>] tx-short-bit <bit>   make this bit shorter than allowed
#   <op>[,<mode>] tx-long-bit <bit>    make this bit longer than allowed
#   <op>[,<mode>] tx-custom-bit <bit>  send the custom pulse instead of this bit
#   <op>[,<mode>] tx-short-start       send a start pulse that's too short
#   <op>[,<mode>] tx-long-start        send a start pulse that's too long
#   <op>[,<mode>] tx-custom-start      send the custom pulse instead of the start pulse
#   <op>[,<mode>] tx-last-bit <bit>    stop sending after this bit
#   <op>[,<mode>] tx-low-drive <bit>   force a low-drive condition at this bit position
#
# <op>       CEC message opcode (0-255) or 'any'
# <mode>     'once' (default), 'always', 'toggle' or 'off'
# <bit>      CEC message bit (0-159)
#            10 bits per 'byte': bits 0-7: data, bit 8: EOM, bit 9: ACK
# <poll>     CEC poll message used to test arbitration lost (0x00-0xff, default 0x0f)
# <usecs>    microseconds (0-10000000, default 1000)

clear
```

You can write error injection commands to `error-inj` using `echo 'cmd' >error-inj` or `cat cmd.txt >error-inj`. The `cat error-inj` output contains the current error commands. You can save the output to a file and use it as an input to `error-inj` later.

<a id="rst-basic-syntax"></a>

## Basic Syntax

Leading spaces/tabs are ignored. If the next character is a `#` or the end of the line was reached, then the whole line is ignored. Otherwise a command is expected.

The error injection commands fall in two main groups: those relating to receiving CEC messages and those relating to transmitting CEC messages. In addition, there are commands to clear existing error injection commands and to create custom pulses on the CEC bus.

Most error injection commands can be executed for specific CEC opcodes or for all opcodes (`any`). Each command also has a 'mode' which can be `off` (can be used to turn off an existing error injection command), `once` (the default) which will trigger the error injection only once for the next received or transmitted message, `always` to always trigger the error injection and `toggle` to toggle the error injection on or off for every transmit or receive.

So '`any rx-nack`' will NACK the next received CEC message, '`any,always rx-nack`' will NACK all received CEC messages and '`0x82,toggle rx-nack`' will only NACK if an Active Source message was received and do that only for every other received message.

After an error was injected with mode `once` the error injection command is cleared automatically, so `once` is a one-time deal.

All combinations of `<op>` and error injection commands can co-exist. So this is fine:



```text
0x9e tx-add-bytes 1
0x9e tx-early-eom
0x9f tx-add-bytes 2
any rx-nack
```

All four error injection commands will be active simultaneously.

However, if the same `<op>` and command combination is specified, but with different arguments:



```text
0x9e tx-add-bytes 1
0x9e tx-add-bytes 2
```

Then the second will overwrite the first.

<a id="rst-clear-error-injections"></a>

## Clear Error Injections

- **`clear`**

  Clear all error injections.

- **`rx-clear`**

  Clear all receive error injections

- **`tx-clear`**

  Clear all transmit error injections

- **`<op> clear`**

  Clear all error injections for the given opcode.

- **`<op> rx-clear`**

  Clear all receive error injections for the given opcode.

- **`<op> tx-clear`**

  Clear all transmit error injections for the given opcode.

<a id="rst-receive-messages"></a>

## Receive Messages

- **`<op>[,<mode>] rx-nack`**

  NACK broadcast messages and messages directed to this CEC adapter. Every byte of the message will be NACKed in case the transmitter keeps transmitting after the first byte was NACKed.

- **`<op>[,<mode>] rx-low-drive <bit>`**

  Force a Low Drive condition at this bit position. If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. This tests if the transmitter can handle the Low Drive condition correctly and reports the error correctly. Note that a Low Drive in the first 4 bits can also be interpreted as an Arbitration Lost condition by the transmitter. This is implementation dependent.

- **`<op>[,<mode>] rx-add-byte`**

  Add a spurious 0x55 byte to the received CEC message, provided the message was 15 bytes long or less. This is useful to test the high-level protocol since spurious bytes should be ignored.

- **`<op>[,<mode>] rx-remove-byte`**

  Remove the last byte from the received CEC message, provided it was at least 2 bytes long. This is useful to test the high-level protocol since messages that are too short should be ignored.

- **`<op>[,<mode>] rx-arb-lost <poll>`**

  Generate a POLL message to trigger an Arbitration Lost condition. This command is only allowed for `<op>` values of `next` or `all`. As soon as a start bit has been received the CEC adapter will switch to transmit mode and it will transmit a POLL message. By default this is 0x0f, but it can also be specified explicitly via the `<poll>` argument.

  This command can be used to test the Arbitration Lost condition in the remote CEC transmitter. Arbitration happens when two CEC adapters start sending a message at the same time. In that case the initiator with the most leading zeroes wins and the other transmitter has to stop transmitting ('Arbitration Lost'). This is very hard to test, except by using this error injection command.

  This does not work if the remote CEC transmitter has logical address 0 ('TV') since that will always win.

- **`rx-no-low-drive`**

  The receiver will ignore situations that would normally generate a Low Drive pulse (3.6 ms). This is typically done if a spurious pulse is detected when receiving a message, and it indicates to the transmitter that the message has to be retransmitted since the receiver got confused. Disabling this is useful to test how other CEC devices handle glitches by ensuring we will not be the one that generates a Low Drive.

<a id="rst-transmit-messages"></a>

## Transmit Messages

- **`tx-ignore-nack-until-eom`**

  This setting changes the behavior of transmitting CEC messages. Normally as soon as the receiver NACKs a byte the transmit will stop, but the specification also allows that the full message is transmitted and only at the end will the transmitter look at the ACK bit. This is not recommended behavior since there is no point in keeping the CEC bus busy for longer than is strictly needed. Especially given how slow the bus is.

  This setting can be used to test how well a receiver deals with transmitters that ignore NACKs until the very end of the message.

- **`<op>[,<mode>] tx-no-eom`**

  Don't set the EOM bit. Normally the last byte of the message has the EOM (End-Of-Message) bit set. With this command the transmit will just stop without ever sending an EOM. This can be used to test how a receiver handles this case. Normally receivers have a time-out after which they will go back to the Idle state.

- **`<op>[,<mode>] tx-early-eom`**

  Set the EOM bit one byte too soon. This obviously only works for messages of two bytes or more. The EOM bit will be set for the second-to-last byte and not for the final byte. The receiver should ignore the last byte in this case. Since the resulting message is likely to be too short for this same reason the whole message is typically ignored. The receiver should be in Idle state after the last byte was transmitted.

- **`<op>[,<mode>] tx-add-bytes <num>`**

  Append `<num>` (1-255) spurious bytes to the message. The extra bytes have the value of the byte position in the message. So if you transmit a two byte message (e.g. a Get CEC Version message) and add 2 bytes, then the full message received by the remote CEC adapter is `0x40 0x9f 0x02 0x03`.

  This command can be used to test buffer overflows in the receiver. E.g. what does it do when it receives more than the maximum message size of 16 bytes.

- **`<op>[,<mode>] tx-remove-byte`**

  Drop the last byte from the message, provided the message is at least two bytes long. The receiver should ignore messages that are too short.

- **`<op>[,<mode>] tx-short-bit <bit>`**

  Make this bit period shorter than allowed. The bit position cannot be an Ack bit.  If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. Normally the period of a data bit is between 2.05 and 2.75 milliseconds. With this command the period of this bit is 1.8 milliseconds, this is done by reducing the time the CEC bus is high. This bit period is less than is allowed and the receiver should respond with a Low Drive condition.

  This command is ignored for 0 bits in bit positions 0 to 3. This is because the receiver also looks for an Arbitration Lost condition in those first four bits and it is undefined what will happen if it sees a too-short 0 bit.

- **`<op>[,<mode>] tx-long-bit <bit>`**

  Make this bit period longer than is valid. The bit position cannot be an Ack bit.  If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. Normally the period of a data bit is between 2.05 and 2.75 milliseconds. With this command the period of this bit is 2.9 milliseconds, this is done by increasing the time the CEC bus is high.

  Even though this bit period is longer than is valid it is undefined what a receiver will do. It might just accept it, or it might time out and return to Idle state. Unfortunately the CEC specification is silent about this.

  This command is ignored for 0 bits in bit positions 0 to 3. This is because the receiver also looks for an Arbitration Lost condition in those first four bits and it is undefined what will happen if it sees a too-long 0 bit.

- **`<op>[,<mode>] tx-short-start`**

  Make this start bit period shorter than allowed. Normally the period of a start bit is between 4.3 and 4.7 milliseconds. With this command the period of the start bit is 4.1 milliseconds, this is done by reducing the time the CEC bus is high. This start bit period is less than is allowed and the receiver should return to Idle state when this is detected.

- **`<op>[,<mode>] tx-long-start`**

  Make this start bit period longer than is valid. Normally the period of a start bit is between 4.3 and 4.7 milliseconds. With this command the period of the start bit is 5 milliseconds, this is done by increasing the time the CEC bus is high. This start bit period is more than is valid and the receiver should return to Idle state when this is detected.

  Even though this start bit period is longer than is valid it is undefined what a receiver will do. It might just accept it, or it might time out and return to Idle state. Unfortunately the CEC specification is silent about this.

- **`<op>[,<mode>] tx-last-bit <bit>`**

  Just stop transmitting after this bit.  If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. This command can be used to test how the receiver reacts when a message just suddenly stops. It should time out and go back to Idle state.

- **`<op>[,<mode>] tx-low-drive <bit>`**

  Force a Low Drive condition at this bit position. If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet. This can be used to test how the receiver handles Low Drive conditions. Note that if this happens at bit positions 0-3 the receiver can interpret this as an Arbitration Lost condition. This is implementation dependent.

<a id="rst-custom-pulses"></a>

## Custom Pulses

- **`tx-custom-low-usecs <usecs>`**

  This defines the duration in microseconds that the custom pulse pulls the CEC line low. The default is 1000 microseconds.

- **`tx-custom-high-usecs <usecs>`**

  This defines the duration in microseconds that the custom pulse keeps the CEC line high (unless another CEC adapter pulls it low in that time). The default is 1000 microseconds. The total period of the custom pulse is `tx-custom-low-usecs + tx-custom-high-usecs`.

- **`<op>[,<mode>] tx-custom-bit <bit>`**

  Send the custom bit instead of a regular data bit. The bit position cannot be an Ack bit.  If &lt;op&gt; specifies a specific CEC opcode then the bit position must be at least 18, otherwise the opcode hasn't been received yet.

- **`<op>[,<mode>] tx-custom-start`**

  Send the custom bit instead of a regular start bit.

- **`tx-custom-pulse`**

  Transmit a single custom pulse as soon as the CEC bus is idle.

<a id="rst-glitch-pulses"></a>

## Glitch Pulses

This emulates what happens if the signal on the CEC line is seeing spurious pulses. Typically this happens after the falling or rising edge where there is a short voltage fluctuation that, if the CEC hardware doesn't do deglitching, can be seen as a spurious pulse and can cause a Low Drive condition or corrupt data.

- **`tx-glitch-low-usecs <usecs>`**

  This defines the duration in microseconds that the glitch pulse pulls the CEC line low. The default is 1 microsecond. The range is 0-100 microseconds. If 0, then no glitch pulse will be generated.

- **`tx-glitch-high-usecs <usecs>`**

  This defines the duration in microseconds that the glitch pulse keeps the CEC line high (unless another CEC adapter pulls it low in that time). The default is 1 microseconds. The range is 0-100 microseconds. If 0, then no glitch pulse will be generated.The total period of the glitch pulse is `tx-custom-low-usecs + tx-custom-high-usecs`.

- **`tx-glitch-falling-edge`**

  Send the glitch pulse right after the falling edge.

- **`tx-glitch-rising-edge`**

  Send the glitch pulse right after the rising edge.

---

# Video4Linux (V4L)  driver-specific documentation

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> Copyright © 1999-2016 : LinuxTV Developers

<a id="rst-video4linux-v4l-driver-specific-documentation"></a>
<a id="rst-v4l-drivers-uapi"></a>

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

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

**Copyright** © 1999-2016 : LinuxTV Developers

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

For more details see the file COPYING in the source distribution of Linux.

**Table of Contents**

1. [ASPEED video driver](</kernel/userspace/userspace-api/media-drivers/aspeed-video.md>)
2. [Using camera sensor drivers](</kernel/userspace/userspace-api/media-drivers/camera-sensor.md>)
3. [MIPI CCS camera sensor driver](</kernel/userspace/userspace-api/media-drivers/ccs.md>)
4. [The cx2341x driver](</kernel/userspace/userspace-api/media-drivers/cx2341x-uapi.md>)
5. [DW100 dewarp driver](</kernel/userspace/userspace-api/media-drivers/dw100.md>)
6. [i.MX Video Capture Driver](</kernel/userspace/userspace-api/media-drivers/imx-uapi.md>)
7. [Arm Mali-C55 ISP driver](</kernel/userspace/userspace-api/media-drivers/mali-c55.md>)
8. [Maxim Integrated MAX2175 RF to bits tuner driver](</kernel/userspace/userspace-api/media-drivers/max2175.md>)
9. [NPCM video driver](</kernel/userspace/userspace-api/media-drivers/npcm-video.md>)
10. [OMAP 3 Image Signal Processor (ISP) driver](</kernel/userspace/userspace-api/media-drivers/omap3isp-uapi.md>)
11. [THine THP7312 ISP driver](</kernel/userspace/userspace-api/media-drivers/thp7312.md>)
12. [The Linux USB Video Class (UVC) driver](</kernel/userspace/userspace-api/media-drivers/uvcvideo.md>)
13. [ST VGXY61 camera sensor driver](</kernel/userspace/userspace-api/media-drivers/vgxy61.md>)

---

# ASPEED video driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> ASPEED Video Engine found on AST2400/2500/2600 SoC supports high performance video compressions with a wide range of video quality and compression ratio options. The adopted compressing algorithm is a modified JPEG algorithm.

<a id="rst-aspeed-video-driver"></a>

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

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

ASPEED Video Engine found on AST2400/2500/2600 SoC supports high performance video compressions with a wide range of video quality and compression ratio options. The adopted compressing algorithm is a modified JPEG algorithm.

There are 2 types of compressions in this IP.

- JPEG JFIF standard mode: for single frame and management compression

- ASPEED proprietary mode: for multi-frame and differential compression. Support 2-pass (high quality) video compression scheme (Patent pending by ASPEED). Provide visually lossless video compression quality or to reduce the network average loading under intranet KVM applications.

VIDIOC_S_FMT can be used to choose which format you want. V4L2_PIX_FMT_JPEG stands for JPEG JFIF standard mode; V4L2_PIX_FMT_AJPG stands for ASPEED proprietary mode.

More details on the ASPEED video hardware operations can be found in *chapter 6.2.16 KVM Video Driver* of SDK_User_Guide which available on [github](<https://github.com/AspeedTech-BMC/openbmc/releases/>).

The ASPEED video driver implements the following driver-specific control:

<a id="rst-v4l2-cid-aspeed-hq-mode"></a>

## `V4L2_CID_ASPEED_HQ_MODE`

> Enable/Disable ASPEED's High quality mode. This is a private control that can be used to enable high quality for aspeed proprietary mode.


<table>
<tbody>
<tr>
<td>


`(0)`

</td>
<td>


ASPEED HQ mode is disabled.

</td>
</tr>
<tr>
<td>


`(1)`

</td>
<td>


ASPEED HQ mode is enabled.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-cid-aspeed-hq-jpeg-quality"></a>

## `V4L2_CID_ASPEED_HQ_JPEG_QUALITY`

> Define the quality of ASPEED's High quality mode. This is a private control that can be used to decide compression quality if High quality mode enabled . Higher the value, better the quality and bigger the size.


<table>
<tbody>
<tr>
<td>


`(1)`

</td>
<td>


minimum

</td>
</tr>
<tr>
<td>


`(12)`

</td>
<td>


maximum

</td>
</tr>
<tr>
<td>


`(1)`

</td>
<td>


step

</td>
</tr>
<tr>
<td>


`(1)`

</td>
<td>


default

</td>
</tr>
</tbody>
</table>

**Copyright** © 2022 ASPEED Technology Inc.

---

# Using camera sensor drivers

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> This section describes common practices for how the V4L2 sub-device interface is used to control the camera sensor drivers.

<a id="rst-using-camera-sensor-drivers"></a>
<a id="rst-media-using-camera-sensor-drivers"></a>

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

This section describes common practices for how the V4L2 sub-device interface is used to control the camera sensor drivers.

You may also find [Writing camera sensor drivers](</kernel/hardware/driver-api/media/camera-sensor.md#rst-media-writing-camera-sensor-drivers>) useful.

<a id="rst-sensor-internal-pipeline-configuration"></a>

## Sensor internal pipeline configuration

Camera sensors have an internal processing pipeline including cropping and binning functionality. The sensor drivers belong to two distinct classes, freely configurable and register list-based drivers, depending on how the driver configures this functionality.

<a id="rst-freely-configurable-camera-sensor-drivers"></a>

### Freely configurable camera sensor drivers

Freely configurable camera sensor drivers expose the device's internal processing pipeline as one or more sub-devices with different cropping and scaling configurations. The output size of the device is the result of a series of cropping and scaling operations from the device's pixel array's size.

An example of such a driver is the CCS driver.

<a id="rst-register-list-based-drivers"></a>

### Register list-based drivers

Register list-based drivers generally, instead of able to configure the device they control based on user requests, are limited to a number of preset configurations that combine a number of different parameters that on hardware level are independent. How a driver picks such configuration is based on the format set on a source pad at the end of the device's internal pipeline.

Most sensor drivers are implemented this way.

<a id="rst-frame-interval-configuration"></a>

## Frame interval configuration

There are two different methods for obtaining possibilities for different frame intervals as well as configuring the frame interval. Which one to implement depends on the type of the device.

<a id="rst-raw-camera-sensors"></a>

### Raw camera sensors

Instead of a high level parameter such as frame interval, the frame interval is a result of the configuration of a number of camera sensor implementation specific parameters. Luckily, these parameters tend to be the same for more or less all modern raw camera sensors.

The frame interval is calculated using the following equation:



```text
frame interval = (analogue crop width + horizontal blanking) *
                 (analogue crop height + vertical blanking) / pixel rate
```

The formula is bus independent and is applicable for raw timing parameters on large variety of devices beyond camera sensors. Devices that have no analogue crop, use the full source image size, i.e. pixel array size.

Horizontal and vertical blanking are specified by `V4L2_CID_HBLANK` and `V4L2_CID_VBLANK`, respectively. The unit of the `V4L2_CID_HBLANK` control is pixels and the unit of the `V4L2_CID_VBLANK` is lines. The pixel rate in the sensor's **pixel array** is specified by `V4L2_CID_PIXEL_RATE` in the same sub-device. The unit of that control is pixels per second.

Register list-based drivers need to implement read-only sub-device nodes for the purpose. Devices that are not register list based need these to configure the device's internal processing pipeline.

The first entity in the linear pipeline is the pixel array. The pixel array may be followed by other entities that are there to allow configuring binning, skipping, scaling or digital crop, see [VIDIOC_SUBDEV_G_SELECTION](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-selection.md#rst-vidioc-subdev-g-selection>).

<a id="rst-usb-cameras-etc-devices"></a>

### USB cameras etc. devices

USB video class hardware, as well as many cameras offering a similar higher level interface natively, generally use the concept of frame interval (or frame rate) on device level in firmware or hardware. This means lower level controls implemented by raw cameras may not be used on uAPI (or even kAPI) to control the frame interval on these devices.

<a id="rst-rotation-orientation-and-flipping"></a>

## Rotation, orientation and flipping

Some systems have the camera sensor mounted upside down compared to its natural mounting rotation. In such cases, drivers shall expose the information to userspace with the [V4L2_CID_CAMERA_SENSOR_ROTATION](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) control.

Sensor drivers shall also report the sensor's mounting orientation with the [V4L2_CID_CAMERA_SENSOR_ORIENTATION](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

Sensor drivers that have any vertical or horizontal flips embedded in the register programming sequences shall initialize the [V4L2_CID_HFLIP](</kernel/userspace/userspace-api/media-v4l/control.md#rst-v4l2-cid-hflip>) and [V4L2_CID_VFLIP](</kernel/userspace/userspace-api/media-v4l/control.md#rst-v4l2-cid-vflip>) controls with the values programmed by the register sequences. The default values of these controls shall be 0 (disabled). Especially these controls shall not be inverted, independently of the sensor's mounting rotation.

---

# MIPI CCS camera sensor driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> The MIPI CCS camera sensor driver is a generic driver for MIPI CCS compliant camera sensors. It exposes three sub-devices representing the pixel array, the binner and the scaler.

<a id="rst-mipi-ccs-camera-sensor-driver"></a>
<a id="rst-media-ccs-uapi"></a>

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

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

The MIPI CCS camera sensor driver is a generic driver for [MIPI CCS](<https://www.mipi.org/specifications/camera-command-set>)<a id="rst-mipi-ccs"></a> compliant camera sensors. It exposes three sub-devices representing the pixel array, the binner and the scaler.

As the capabilities of individual devices vary, the driver exposes interfaces based on the capabilities that exist in hardware.

Also see [the CCS driver kernel documentation](</kernel/hardware/driver-api/media-drivers-ccs/ccs.md#rst-media-ccs-driver>).

<a id="rst-pixel-array-sub-device"></a>

## Pixel Array sub-device

The pixel array sub-device represents the camera sensor's pixel matrix, as well as analogue crop functionality present in many compliant devices. The analogue crop is configured using the `V4L2_SEL_TGT_CROP` on the source pad (0) of the entity. The size of the pixel matrix can be obtained by getting the `V4L2_SEL_TGT_NATIVE_SIZE` target.

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

## Binner

The binner sub-device represents the binning functionality on the sensor. For that purpose, selection target `V4L2_SEL_TGT_COMPOSE` is supported on the sink pad (0).

Additionally, if a device has no scaler or digital crop functionality, the source pad (1) exposes another digital crop selection rectangle that can only crop at the end of the lines and frames.

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

## Scaler

The scaler sub-device represents the digital crop and scaling functionality of the sensor. The V4L2 selection target `V4L2_SEL_TGT_CROP` is used to configure the digital crop on the sink pad (0) when digital crop is supported. Scaling is configured using selection target `V4L2_SEL_TGT_COMPOSE` on the sink pad (0) as well.

Additionally, if the scaler sub-device exists, its source pad (1) exposes another digital crop selection rectangle that can only crop at the end of the lines and frames.

<a id="rst-digital-and-analogue-crop"></a>

## Digital and analogue crop

Digital crop functionality is referred to as cropping that effectively works by dropping some data on the floor. Analogue crop, on the other hand, means that the cropped information is never retrieved. In case of camera sensors, the analogue data is never read from the pixel matrix that are outside the configured selection rectangle that designates crop. The difference has an effect in device timing and likely also in power consumption.

<a id="rst-private-controls"></a>

## Private controls

The MIPI CCS driver implements a number of private controls under `V4L2_CID_USER_BASE_CCS` to control the MIPI CCS compliant camera sensors.

<a id="rst-analogue-gain-model"></a>

### Analogue gain model

The CCS defines an analogue gain model where the gain can be calculated using the following formula:

> gain = m0 \* x + c0 / (m1 \* x + c1)

Either m0 or c0 will be zero. The constants that are device specific, can be obtained from the following controls:

> V4L2_CID_CCS_ANALOGUE_GAIN_M0 V4L2_CID_CCS_ANALOGUE_GAIN_M1 V4L2_CID_CCS_ANALOGUE_GAIN_C0 V4L2_CID_CCS_ANALOGUE_GAIN_C1

The analogue gain (`x` in the formula) is controlled through `V4L2_CID_ANALOGUE_GAIN` in this case.

<a id="rst-alternate-analogue-gain-model"></a>

### Alternate analogue gain model

The CCS defines another analogue gain model called alternate analogue gain. In this case, the formula to calculate actual gain consists of linear and exponential parts:

> gain = linear \* 2 ^ exponent

The `linear` and `exponent` factors can be set using the `V4L2_CID_CCS_ANALOGUE_LINEAR_GAIN` and `V4L2_CID_CCS_ANALOGUE_EXPONENTIAL_GAIN` controls, respectively

<a id="rst-shading-correction"></a>

### Shading correction

The CCS standard supports lens shading correction. The feature can be controlled using `V4L2_CID_CCS_SHADING_CORRECTION`. Additionally, the luminance correction level may be changed using `V4L2_CID_CCS_LUMINANCE_CORRECTION_LEVEL`, where value 0 indicates no correction and 128 indicates correcting the luminance in corners to 10 % less than in the centre.

Shading correction needs to be enabled for luminance correction level to have an effect.

**Copyright** © 2020 Intel Corporation

---

# The cx2341x driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> The cx23416 can produce (and the cx23415 can also read) raw YUV output. The format of a YUV frame is 16x16 linear tiled NV12 (V4L2_PIX_FMT_NV12_16L16).

<a id="rst-the-cx2341x-driver"></a>

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

<a id="rst-non-compressed-file-format"></a>

## Non-compressed file format

The cx23416 can produce (and the cx23415 can also read) raw YUV output. The format of a YUV frame is 16x16 linear tiled NV12 (V4L2_PIX_FMT_NV12_16L16).

The format is YUV 4:2:0 which uses 1 Y byte per pixel and 1 U and V byte per four pixels.

The data is encoded as two macroblock planes, the first containing the Y values, the second containing UV macroblocks.

The Y plane is divided into blocks of 16x16 pixels from left to right and from top to bottom. Each block is transmitted in turn, line-by-line.

So the first 16 bytes are the first line of the top-left block, the second 16 bytes are the second line of the top-left block, etc. After transmitting this block the first line of the block on the right to the first block is transmitted, etc.

The UV plane is divided into blocks of 16x8 UV values going from left to right, top to bottom. Each block is transmitted in turn, line-by-line.

So the first 16 bytes are the first line of the top-left block and contain 8 UV value pairs (16 bytes in total). The second 16 bytes are the second line of 8 UV pairs of the top-left block, etc. After transmitting this block the first line of the block on the right to the first block is transmitted, etc.

The code below is given as an example on how to convert V4L2_PIX_FMT_NV12_16L16 to separate Y, U and V planes. This code assumes frames of 720x576 (PAL) pixels.

The width of a frame is always 720 pixels, regardless of the actual specified width.

If the height is not a multiple of 32 lines, then the captured video is missing macroblocks at the end and is unusable. So the height must be a multiple of 32.

<a id="rst-raw-format-c-example"></a>

### Raw format c example



```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static unsigned char frame[576*720*3/2];
static unsigned char framey[576*720];
static unsigned char frameu[576*720 / 4];
static unsigned char framev[576*720 / 4];

static void de_macro_y(unsigned char* dst, unsigned char *src, int dstride, int w, int h)
{
unsigned int y, x, i;

// descramble Y plane
// dstride = 720 = w
// The Y plane is divided into blocks of 16x16 pixels
// Each block in transmitted in turn, line-by-line.
for (y = 0; y < h; y += 16) {
        for (x = 0; x < w; x += 16) {
        for (i = 0; i < 16; i++) {
                memcpy(dst + x + (y + i) * dstride, src, 16);
                src += 16;
        }
        }
}
}

static void de_macro_uv(unsigned char *dstu, unsigned char *dstv, unsigned char *src, int dstride, int w, int h)
{
unsigned int y, x, i;

// descramble U/V plane
// dstride = 720 / 2 = w
// The U/V values are interlaced (UVUV...).
// Again, the UV plane is divided into blocks of 16x16 UV values.
// Each block in transmitted in turn, line-by-line.
for (y = 0; y < h; y += 16) {
        for (x = 0; x < w; x += 8) {
        for (i = 0; i < 16; i++) {
                int idx = x + (y + i) * dstride;

                dstu[idx+0] = src[0];  dstv[idx+0] = src[1];
                dstu[idx+1] = src[2];  dstv[idx+1] = src[3];
                dstu[idx+2] = src[4];  dstv[idx+2] = src[5];
                dstu[idx+3] = src[6];  dstv[idx+3] = src[7];
                dstu[idx+4] = src[8];  dstv[idx+4] = src[9];
                dstu[idx+5] = src[10]; dstv[idx+5] = src[11];
                dstu[idx+6] = src[12]; dstv[idx+6] = src[13];
                dstu[idx+7] = src[14]; dstv[idx+7] = src[15];
                src += 16;
        }
        }
}
}

/*************************************************************************/
int main(int argc, char **argv)
{
FILE *fin;
int i;

if (argc == 1) fin = stdin;
else fin = fopen(argv[1], "r");

if (fin == NULL) {
        fprintf(stderr, "cannot open input\n");
        exit(-1);
}
while (fread(frame, sizeof(frame), 1, fin) == 1) {
        de_macro_y(framey, frame, 720, 720, 576);
        de_macro_uv(frameu, framev, frame + 720 * 576, 720 / 2, 720 / 2, 576 / 2);
        fwrite(framey, sizeof(framey), 1, stdout);
        fwrite(framev, sizeof(framev), 1, stdout);
        fwrite(frameu, sizeof(frameu), 1, stdout);
}
fclose(fin);
return 0;
}
```

<a id="rst-format-of-embedded-v4l2-mpeg-stream-vbi-fmt-ivtv-vbi-data"></a>

## Format of embedded V4L2_MPEG_STREAM_VBI_FMT_IVTV VBI data

Author: Hans Verkuil &lt;[hverkuil@kernel.org](<mailto:hverkuil@kernel.org>)&gt;

This section describes the V4L2_MPEG_STREAM_VBI_FMT_IVTV format of the VBI data embedded in an MPEG-2 program stream. This format is in part dictated by some hardware limitations of the ivtv driver (the driver for the Conexant cx23415/6 chips), in particular a maximum size for the VBI data. Anything longer is cut off when the MPEG stream is played back through the cx23415.

The advantage of this format is it is very compact and that all VBI data for all lines can be stored while still fitting within the maximum allowed size.

The stream ID of the VBI data is 0xBD. The maximum size of the embedded data is 4 + 43 \* 36, which is 4 bytes for a header and 2 \* 18 VBI lines with a 1 byte header and a 42 bytes payload each. Anything beyond this limit is cut off by the cx23415/6 firmware. Besides the data for the VBI lines we also need 36 bits for a bitmask determining which lines are captured and 4 bytes for a magic cookie, signifying that this data package contains V4L2_MPEG_STREAM_VBI_FMT_IVTV VBI data. If all lines are used, then there is no longer room for the bitmask. To solve this two different magic numbers were introduced:

'itv0': After this magic number two unsigned longs follow. Bits 0-17 of the first unsigned long denote which lines of the first field are captured. Bits 18-31 of the first unsigned long and bits 0-3 of the second unsigned long are used for the second field.

'ITV0': This magic number assumes all VBI lines are captured, i.e. it implicitly implies that the bitmasks are 0xffffffff and 0xf.

After these magic cookies (and the 8 byte bitmask in case of cookie 'itv0') the captured VBI lines start:

For each line the least significant 4 bits of the first byte contain the data type. Possible values are shown in the table below. The payload is in the following 42 bytes.

Here is the list of possible data types:



```c
#define IVTV_SLICED_TYPE_TELETEXT       0x1     // Teletext (uses lines 6-22 for PAL)
#define IVTV_SLICED_TYPE_CC             0x4     // Closed Captions (line 21 NTSC)
#define IVTV_SLICED_TYPE_WSS            0x5     // Wide Screen Signal (line 23 PAL)
#define IVTV_SLICED_TYPE_VPS            0x7     // Video Programming System (PAL) (line 16)
```

---

# DW100 dewarp driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> The Vivante DW100 Dewarp Processor IP core found on i.MX8MP SoC applies a programmable geometrical transformation on the input image to correct distortion introduced by lenses.

<a id="rst-dw100-dewarp-driver"></a>

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

The Vivante DW100 Dewarp Processor IP core found on i.MX8MP SoC applies a programmable geometrical transformation on the input image to correct distortion introduced by lenses.

The transformation function is exposed by the hardware as a grid map with 16x16 pixel macroblocks indexed using X, Y vertex coordinates.



```text
                       Image width
        <--------------------------------------->

   ^    .-------.-------.-------.-------.-------.
   |    | 16x16 |       |       |       |       |
I  |    | pixel |       |       |       |       |
m  |    | block |       |       |       |       |
a  |    .-------.-------.-------.-------.-------.
g  |    |       |       |       |       |       |
e  |    |       |       |       |       |       |
   |    |       |       |       |       |       |
h  |    .-------.-------.-------.-------.-------.
e  |    |       |       |       |       |       |
i  |    |       |       |       |       |       |
g  |    |       |       |       |       |       |
h  |    .-------.-------.-------.-------.-------.
t  |    |       |       |       |       |       |
   |    |       |       |       |       |       |
   |    |       |       |       |       |       |
   v    '-------'-------'-------'-------'-------'

         Grid of Image Blocks for Dewarping Map
```

Each x, y coordinate register uses 16 bits to record the coordinate address in an unsigned 12.4 fixed point format (UQ12.4).



```text
.----------------------.--------..----------------------.--------.
|         31~20        | 19~16  ||         15~4         |  3~0   |
|       (integer)      | (frac) ||       (integer)      | (frac) |
'----------------------'--------''----------------------'--------'
<-------------------------------><------------------------------->
            Y coordinate                     X coordinate

                       Remap Register Layout
```

The dewarping map is set from applications using the V4L2_CID_DW100_DEWARPING_16x16_VERTEX_MAP control. The control contains an array of u32 values storing (x, y) destination coordinates for each vertex of the grid. The x coordinate is stored in the 16 LSBs and the y coordinate in the 16 MSBs.

The number of elements in the array must match the image size:



```C
elems = (DIV_ROUND_UP(width, 16) + 1) * (DIV_ROUND_UP(height, 16) + 1);
```

If the control has not been set by the application, the driver uses an identity map.

More details on the DW100 hardware operations can be found in *chapter 13.15 DeWarp* of [IMX8MP](<https://www.nxp.com/webapp/Download?colCode=IMX8MPRM>) reference manual.

The Vivante DW100 m2m driver implements the following driver-specific control:

- **`V4L2_CID_DW100_DEWARPING_16x16_VERTEX_MAP (__u32 array)`**

  Specifies to DW100 driver its dewarping map (aka LUT) blob as described in *chapter 13.15.2.3 Dewarping Remap* of [IMX8MP](<https://www.nxp.com/webapp/Download?colCode=IMX8MPRM>) reference manual as an U32 dynamic array. The image is divided into many small 16x16 blocks. If the width/height of the image is not divisible by 16, the size of the rightmost/bottommost block is the remainder. The dewarping map only saves the vertex coordinates of the block. The dewarping grid map is comprised of vertex coordinates for x and y. Each x, y coordinate register uses 16 bits (UQ12.4) to record the coordinate address, with the Y coordinate in the upper bits and X in the lower bits. The driver modifies the dimensions of this control when the sink format is changed, to reflect the new input resolution.

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

---

# i.MX Video Capture Driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> This subdev can generate the following event when enabling the second IDMAC source pad:

<a id="rst-i-mx-video-capture-driver"></a>

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

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

## Events

<a id="rst-ipux-csiy"></a>
<a id="rst-imx-api-ipux-csiy"></a>

### ipuX_csiY

This subdev can generate the following event when enabling the second IDMAC source pad:

- V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR

The user application can subscribe to this event from the ipuX_csiY subdev node. This event is generated by the Frame Interval Monitor (see below for more on the FIM).

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

## Controls

<a id="rst-frame-interval-monitor-in-ipux-csiy"></a>
<a id="rst-imx-api-fim"></a>

### Frame Interval Monitor in ipuX_csiY

The adv718x decoders can occasionally send corrupt fields during NTSC/PAL signal re-sync (too little or too many video lines). When this happens, the IPU triggers a mechanism to re-establish vertical sync by adding 1 dummy line every frame, which causes a rolling effect from image to image, and can last a long time before a stable image is recovered. Or sometimes the mechanism doesn't work at all, causing a permanent split image (one frame contains lines from two consecutive captured images).

From experiment it was found that during image rolling, the frame intervals (elapsed time between two EOF's) drop below the nominal value for the current standard, by about one frame time (60 usec), and remain at that value until rolling stops.

While the reason for this observation isn't known (the IPU dummy line mechanism should show an increase in the intervals by 1 line time every frame, not a fixed value), we can use it to detect the corrupt fields using a frame interval monitor. If the FIM detects a bad frame interval, the ipuX_csiY subdev will send the event V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR. Userland can register with the FIM event notification on the ipuX_csiY subdev device node. Userland can issue a streaming restart when this event is received to correct the rolling/split image.

The ipuX_csiY subdev includes custom controls to tweak some dials for FIM. If one of these controls is changed during streaming, the FIM will be reset and will continue at the new settings.

- V4L2_CID_IMX_FIM_ENABLE

Enable/disable the FIM.

- V4L2_CID_IMX_FIM_NUM

How many frame interval measurements to average before comparing against the nominal frame interval reported by the sensor. This can reduce noise caused by interrupt latency.

- V4L2_CID_IMX_FIM_TOLERANCE_MIN

If the averaged intervals fall outside nominal by this amount, in microseconds, the V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR event is sent.

- V4L2_CID_IMX_FIM_TOLERANCE_MAX

If any intervals are higher than this value, those samples are discarded and do not enter into the average. This can be used to discard really high interval errors that might be due to interrupt latency from high system load.

- V4L2_CID_IMX_FIM_NUM_SKIP

How many frames to skip after a FIM reset or stream restart before FIM begins to average intervals.

- V4L2_CID_IMX_FIM_ICAP_CHANNEL / V4L2_CID_IMX_FIM_ICAP_EDGE

These controls will configure an input capture channel as the method for measuring frame intervals. This is superior to the default method of measuring frame intervals via EOF interrupt, since it is not subject to uncertainty errors introduced by interrupt latency.

Input capture requires hardware support. A VSYNC signal must be routed to one of the i.MX6 input capture channel pads.

V4L2_CID_IMX_FIM_ICAP_CHANNEL configures which i.MX6 input capture channel to use. This must be 0 or 1.

V4L2_CID_IMX_FIM_ICAP_EDGE configures which signal edge will trigger input capture events. By default the input capture method is disabled with a value of IRQ_TYPE_NONE. Set this control to IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, or IRQ_TYPE_EDGE_BOTH to enable input capture, triggered on the given signal edge(s).

When input capture is disabled, frame intervals will be measured via EOF interrupt.

<a id="rst-file-list"></a>

### File list

drivers/staging/media/imx/ include/media/imx.h include/linux/imx-media.h

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

### Authors

- Steve Longerbeam &lt;[steve_longerbeam@mentor.com](<mailto:steve_longerbeam@mentor.com>)&gt;

- Philipp Zabel &lt;[kernel@pengutronix.de](<mailto:kernel@pengutronix.de>)&gt;

- Russell King &lt;[linux@armlinux.org.uk](<mailto:linux@armlinux.org.uk>)&gt;

Copyright (C) 2012-2017 Mentor Graphics Inc.

---

# Arm Mali-C55 ISP driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> The Arm Mali-C55 ISP driver implements a single driver-specific control:

<a id="rst-arm-mali-c55-isp-driver"></a>

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

The Arm Mali-C55 ISP driver implements a single driver-specific control:

- **`V4L2_CID_MALI_C55_CAPABILITIES (bitmask)`**

  Detail the capabilities of the ISP by giving detail about the fitted blocks.


  <table>
  <caption>Bitmask meaning definitions</caption>
  <thead>
  <tr>
  <th>


  Bit

  </th>
  <th>


  Macro

  </th>
  <th>


  Meaning

  </th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>


  0

  </td>
  <td>


  MALI_C55_PONG

  </td>
  <td>


  Pong configuration space is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  1

  </td>
  <td>


  MALI_C55_WDR

  </td>
  <td>


  WDR Framestitch, offset and gain is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  2

  </td>
  <td>


  MALI_C55_COMPRESSION

  </td>
  <td>


  Temper compression is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  3

  </td>
  <td>


  MALI_C55_TEMPER

  </td>
  <td>


  Temper is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  4

  </td>
  <td>


  MALI_C55_SINTER_LITE

  </td>
  <td>


  Sinter Lite is fitted in the ISP instead of the full Sinter version

  </td>
  </tr>
  <tr>
  <td>


  5

  </td>
  <td>


  MALI_C55_SINTER

  </td>
  <td>


  Sinter is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  6

  </td>
  <td>


  MALI_C55_IRIDIX_LTM

  </td>
  <td>


  Iridix local tone mappine is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  7

  </td>
  <td>


  MALI_C55_IRIDIX_GTM

  </td>
  <td>


  Iridix global tone mapping is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  8

  </td>
  <td>


  MALI_C55_CNR

  </td>
  <td>


  Colour noise reduction is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  9

  </td>
  <td>


  MALI_C55_FRSCALER

  </td>
  <td>


  The full resolution pipe scaler is fitted in the ISP

  </td>
  </tr>
  <tr>
  <td>


  10

  </td>
  <td>


  MALI_C55_DS_PIPE

  </td>
  <td>


  The downscale pipe is fitted in the ISP

  </td>
  </tr>
  </tbody>
  </table>

  The Mali-C55 ISP can be configured in a number of ways to include or exclude blocks which may not be necessary. This control provides a way for the driver to communicate to userspace which of the blocks are fitted in the design.

---

# Maxim Integrated MAX2175 RF to bits tuner driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> The MAX2175 driver implements the following driver-specific controls:

<a id="rst-maxim-integrated-max2175-rf-to-bits-tuner-driver"></a>

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

The MAX2175 driver implements the following driver-specific controls:

<a id="rst-v4l2-cid-max2175-i2s-enable"></a>

## `V4L2_CID_MAX2175_I2S_ENABLE`

> Enable/Disable I2S output of the tuner. This is a private control that can be accessed only using the subdev interface. Refer to [Documentation/driver-api/media/v4l2-controls.rst](/kernel/hardware/driver-api/media/v4l2-controls.md) for more details.


<table>
<tbody>
<tr>
<td>


`(0)`

</td>
<td>


I2S output is disabled.

</td>
</tr>
<tr>
<td>


`(1)`

</td>
<td>


I2S output is enabled.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-cid-max2175-hsls"></a>

## `V4L2_CID_MAX2175_HSLS`

> The high-side/low-side (HSLS) control of the tuner for a given band.


<table>
<tbody>
<tr>
<td>


`(0)`

</td>
<td>


The LO frequency position is below the desired frequency.

</td>
</tr>
<tr>
<td>


`(1)`

</td>
<td>


The LO frequency position is above the desired frequency.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-cid-max2175-rx-mode-menu"></a>

## `V4L2_CID_MAX2175_RX_MODE (menu)`

> The Rx mode controls a number of preset parameters of the tuner like sample clock (sck), sampling rate etc. These multiple settings are provided under one single label called Rx mode in the datasheet. The list below shows the supported modes with a brief description.


<table>
<tbody>
<tr>
<td colspan="2">


`"Europe modes"`

</td>
</tr>
<tr>
<td>


`"FM 1.2" (0)`

</td>
<td>


This configures FM band with a sample rate of 0.512 million samples/sec with a 10.24 MHz sck.

</td>
</tr>
<tr>
<td>


`"DAB 1.2" (1)`

</td>
<td>


This configures VHF band with a sample rate of 2.048 million samples/sec with a 32.768 MHz sck.

</td>
</tr>
<tr>
<td colspan="2">


`"North America modes"`

</td>
</tr>
<tr>
<td>


`"FM 1.0" (0)`

</td>
<td>


This configures FM band with a sample rate of 0.7441875 million samples/sec with a 14.88375 MHz sck.

</td>
</tr>
<tr>
<td>


`"DAB 1.2" (1)`

</td>
<td>


This configures FM band with a sample rate of 0.372 million samples/sec with a 7.441875 MHz sck.

</td>
</tr>
</tbody>
</table>

---

# NPCM video driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> This driver is used to control the Video Capture/Differentiation (VCD) engine and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. The VCD can capture a frame from digital video input and compare two frames in memory, and…

<a id="rst-npcm-video-driver"></a>

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

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

This driver is used to control the Video Capture/Differentiation (VCD) engine and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. The VCD can capture a frame from digital video input and compare two frames in memory, and the ECE can compress the frame data into HEXTILE format.

<a id="rst-driver-specific-controls"></a>

## Driver-specific Controls

<a id="rst-v4l2-cid-npcm-capture-mode"></a>

### V4L2_CID_NPCM_CAPTURE_MODE

The VCD engine supports two modes:

- COMPLETE mode:

  Capture the next complete frame into memory.

- DIFF mode:

  Compare the incoming frame with the frame stored in memory, and updates the differentiated frame in memory.

Application can use `V4L2_CID_NPCM_CAPTURE_MODE` control to set the VCD mode with different control values (enum v4l2_npcm_capture_mode):

- `V4L2_NPCM_CAPTURE_MODE_COMPLETE`: will set VCD to COMPLETE mode.

- `V4L2_NPCM_CAPTURE_MODE_DIFF`: will set VCD to DIFF mode.

<a id="rst-v4l2-cid-npcm-rect-count"></a>

### V4L2_CID_NPCM_RECT_COUNT

If using V4L2_PIX_FMT_HEXTILE format, VCD will capture frame data and then ECE will compress the data into HEXTILE rectangles and store them in V4L2 video buffer with the layout defined in Remote Framebuffer Protocol:



```text
(RFC 6143, https://www.rfc-editor.org/rfc/rfc6143.html#section-7.6.1)

+--------------+--------------+-------------------+
| No. of bytes | Type [Value] | Description       |
+--------------+--------------+-------------------+
| 2            | U16          | x-position        |
| 2            | U16          | y-position        |
| 2            | U16          | width             |
| 2            | U16          | height            |
| 4            | S32          | encoding-type (5) |
+--------------+--------------+-------------------+
|             HEXTILE rectangle data              |
+-------------------------------------------------+
```

Application can get the video buffer through VIDIOC_DQBUF, and followed by calling `V4L2_CID_NPCM_RECT_COUNT` control to get the number of HEXTILE rectangles in this buffer.

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

## References

include/uapi/linux/npcm-video.h

**Copyright** © 2022 Nuvoton Technologies

---

# OMAP 3 Image Signal Processor (ISP) driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> Copyright © 2010 Nokia Corporation

<a id="rst-omap-3-image-signal-processor-isp-driver"></a>

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

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

Copyright © 2010 Nokia Corporation

Copyright © 2009 Texas Instruments, Inc.

Contacts: Laurent Pinchart &lt;[laurent.pinchart@ideasonboard.com](<mailto:laurent.pinchart@ideasonboard.com>)&gt;, Sakari Ailus &lt;[sakari.ailus@iki.fi](<mailto:sakari.ailus@iki.fi>)&gt;, David Cohen &lt;[dacohen@gmail.com](<mailto:dacohen@gmail.com>)&gt;

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

## Events

The OMAP 3 ISP driver does support the V4L2 event interface on CCDC and statistics (AEWB, AF and histogram) subdevs.

The CCDC subdev produces V4L2_EVENT_FRAME_SYNC type event on HS_VS interrupt which is used to signal frame start. Earlier version of this driver used V4L2_EVENT_OMAP3ISP_HS_VS for this purpose. The event is triggered exactly when the reception of the first line of the frame starts in the CCDC module. The event can be subscribed on the CCDC subdev.

(When using parallel interface one must pay account to correct configuration of the VS signal polarity. This is automatically correct when using the serial receivers.)

Each of the statistics subdevs is able to produce events. An event is generated whenever a statistics buffer can be dequeued by a user space application using the VIDIOC_OMAP3ISP_STAT_REQ IOCTL. The events available are:

- V4L2_EVENT_OMAP3ISP_AEWB

- V4L2_EVENT_OMAP3ISP_AF

- V4L2_EVENT_OMAP3ISP_HIST

The type of the event data is struct omap3isp_stat_event_status for these ioctls. If there is an error calculating the statistics, there will be an event as usual, but no related statistics buffer. In this case omap3isp_stat_event_status.buf_err is set to non-zero.

<a id="rst-private-ioctls"></a>

## Private IOCTLs

The OMAP 3 ISP driver supports standard V4L2 IOCTLs and controls where possible and practical. Much of the functions provided by the ISP, however, does not fall under the standard IOCTLs --- gamma tables and configuration of statistics collection are examples of such.

In general, there is a private ioctl for configuring each of the blocks containing hardware-dependent functions.

The following private IOCTLs are supported:

- VIDIOC_OMAP3ISP_CCDC_CFG

- VIDIOC_OMAP3ISP_PRV_CFG

- VIDIOC_OMAP3ISP_AEWB_CFG

- VIDIOC_OMAP3ISP_HIST_CFG

- VIDIOC_OMAP3ISP_AF_CFG

- VIDIOC_OMAP3ISP_STAT_REQ

- VIDIOC_OMAP3ISP_STAT_EN

The parameter structures used by these ioctls are described in include/linux/omap3isp.h. The detailed functions of the ISP itself related to a given ISP block is described in the Technical Reference Manuals (TRMs) --- see the end of the document for those.

While it is possible to use the ISP driver without any use of these private IOCTLs it is not possible to obtain optimal image quality this way. The AEWB, AF and histogram modules cannot be used without configuring them using the appropriate private IOCTLs.

<a id="rst-ccdc-and-preview-block-ioctls"></a>

## CCDC and preview block IOCTLs

The VIDIOC_OMAP3ISP_CCDC_CFG and VIDIOC_OMAP3ISP_PRV_CFG IOCTLs are used to configure, enable and disable functions in the CCDC and preview blocks, respectively. Both IOCTLs control several functions in the blocks they control. VIDIOC_OMAP3ISP_CCDC_CFG IOCTL accepts a pointer to struct omap3isp_ccdc_update_config as its argument. Similarly VIDIOC_OMAP3ISP_PRV_CFG accepts a pointer to struct omap3isp_prev_update_config. The definition of both structures is available in <a id="rst-footnote-reference-1"></a>[1](#rst-footnote-1).

The update field in the structures tells whether to update the configuration for the specific function and the flag tells whether to enable or disable the function.

The update and flag bit masks accept the following values. Each separate functions in the CCDC and preview blocks is associated with a flag (either disable or enable; part of the flag field in the structure) and a pointer to configuration data for the function.

Valid values for the update and flag fields are listed here for VIDIOC_OMAP3ISP_CCDC_CFG. Values may be or'ed to configure more than one function in the same IOCTL call.

- OMAP3ISP_CCDC_ALAW

- OMAP3ISP_CCDC_LPF

- OMAP3ISP_CCDC_BLCLAMP

- OMAP3ISP_CCDC_BCOMP

- OMAP3ISP_CCDC_FPC

- OMAP3ISP_CCDC_CULL

- OMAP3ISP_CCDC_CONFIG_LSC

- OMAP3ISP_CCDC_TBL_LSC

The corresponding values for the VIDIOC_OMAP3ISP_PRV_CFG are here:

- OMAP3ISP_PREV_LUMAENH

- OMAP3ISP_PREV_INVALAW

- OMAP3ISP_PREV_HRZ_MED

- OMAP3ISP_PREV_CFA

- OMAP3ISP_PREV_CHROMA_SUPP

- OMAP3ISP_PREV_WB

- OMAP3ISP_PREV_BLKADJ

- OMAP3ISP_PREV_RGB2RGB

- OMAP3ISP_PREV_COLOR_CONV

- OMAP3ISP_PREV_YC_LIMIT

- OMAP3ISP_PREV_DEFECT_COR

- OMAP3ISP_PREV_GAMMABYPASS

- OMAP3ISP_PREV_DRK_FRM_CAPTURE

- OMAP3ISP_PREV_DRK_FRM_SUBTRACT

- OMAP3ISP_PREV_LENS_SHADING

- OMAP3ISP_PREV_NF

- OMAP3ISP_PREV_GAMMA

The associated configuration pointer for the function may not be NULL when enabling the function. When disabling a function the configuration pointer is ignored.

<a id="rst-statistic-blocks-ioctls"></a>

## Statistic blocks IOCTLs

The statistics subdevs do offer more dynamic configuration options than the other subdevs. They can be enabled, disable and reconfigured when the pipeline is in streaming state.

The statistics blocks always get the input image data from the CCDC (as the histogram memory read isn't implemented). The statistics are dequeueable by the user from the statistics subdev nodes using private IOCTLs.

The private IOCTLs offered by the AEWB, AF and histogram subdevs are heavily reflected by the register level interface offered by the ISP hardware. There are aspects that are purely related to the driver implementation and these are discussed next.

<a id="rst-vidioc-omap3isp-stat-en"></a>

## VIDIOC_OMAP3ISP_STAT_EN

This private IOCTL enables/disables a statistic module. If this request is done before streaming, it will take effect as soon as the pipeline starts to stream.  If the pipeline is already streaming, it will take effect as soon as the CCDC becomes idle.

<a id="rst-vidioc-omap3isp-aewb-cfg-vidioc-omap3isp-hist-cfg-and-vidioc-omap3isp-af-cfg"></a>

## VIDIOC_OMAP3ISP_AEWB_CFG, VIDIOC_OMAP3ISP_HIST_CFG and VIDIOC_OMAP3ISP_AF_CFG

Those IOCTLs are used to configure the modules. They require user applications to have an in-depth knowledge of the hardware. Most of the fields explanation can be found on OMAP's TRMs. The two following fields common to all the above configure private IOCTLs require explanation for better understanding as they are not part of the TRM.

omap3isp\_\[h3a_af/h3a_aewb/hist\]\_config.buf_size:

The modules handle their buffers internally. The necessary buffer size for the module's data output depends on the requested configuration. Although the driver supports reconfiguration while streaming, it does not support a reconfiguration which requires bigger buffer size than what is already internally allocated if the module is enabled. It will return -EBUSY on this case. In order to avoid such condition, either disable/reconfigure/enable the module or request the necessary buffer size during the first configuration while the module is disabled.

The internal buffer size allocation considers the requested configuration's minimum buffer size and the value set on buf_size field. If buf_size field is out of \[minimum, maximum\] buffer size range, it's clamped to fit in there. The driver then selects the biggest value. The corrected buf_size value is written back to user application.

omap3isp\_\[h3a_af/h3a_aewb/hist\]\_config.config_counter:

As the configuration doesn't take effect synchronously to the request, the driver must provide a way to track this information to provide more accurate data. After a configuration is requested, the config_counter returned to user space application will be an unique value associated to that request. When user application receives an event for buffer availability or when a new buffer is requested, this config_counter is used to match a buffer data and a configuration.

<a id="rst-vidioc-omap3isp-stat-req"></a>

## VIDIOC_OMAP3ISP_STAT_REQ

Send to user space the oldest data available in the internal buffer queue and discards such buffer afterwards. The field omap3isp_stat_data.frame_number matches with the video buffer's field_count.

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

## References

<a id="rst-footnote-1"></a>



**[1]** include/linux/omap3isp.h

---

# THine THP7312 ISP driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> The THP7312 driver implements the following driver-specific controls:

<a id="rst-thine-thp7312-isp-driver"></a>

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

The THP7312 driver implements the following driver-specific controls:

- **`V4L2_CID_THP7312_LOW_LIGHT_COMPENSATION`**

  Enable/Disable auto-adjustment, based on lighting conditions, of the frame rate when auto-exposure is enabled.

- **`V4L2_CID_THP7312_AUTO_FOCUS_METHOD`**

  Set method of auto-focus. Only takes effect when auto-focus is enabled.


  <table>
  <tbody>
  <tr>
  <td>


  `0`

  </td>
  <td>


  Contrast-based auto-focus

  </td>
  </tr>
  <tr>
  <td>


  `1`

  </td>
  <td>


  PDAF

  </td>
  </tr>
  <tr>
  <td>


  `2`

  </td>
  <td>


  Hybrid of contrast-based and PDAF

  </td>
  </tr>
  </tbody>
  </table>

  Supported values for the control depend on the camera sensor module connected to the THP7312. If the module doesn't have a focus lens actuator, this control will not be exposed by the THP7312 driver. If the module has a controllable focus lens but the sensor doesn't support PDAF, only the contrast-based auto-focus value will be valid. Otherwise all values for the controls will be supported.

- **`V4L2_CID_THP7312_NOISE_REDUCTION_AUTO`**

  Enable/Disable auto noise reduction.

- **`V4L2_CID_THP7312_NOISE_REDUCTION_ABSOLUTE`**

  Set the noise reduction strength, where 0 is the weakest and 10 is the strongest.

---

# The Linux USB Video Class (UVC) driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> This file documents some driver-specific aspects of the UVC driver, such as driver-specific ioctls and implementation notes.

<a id="rst-the-linux-usb-video-class-uvc-driver"></a>

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

This file documents some driver-specific aspects of the UVC driver, such as driver-specific ioctls and implementation notes.

Questions and remarks can be sent to the Linux UVC development mailing list at [linux-media@vger.kernel.org](<mailto:linux-media@vger.kernel.org>).

<a id="rst-extension-unit-xu-support"></a>

## Extension Unit (XU) support

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

### Introduction

The UVC specification allows for vendor-specific extensions through extension units (XUs). The Linux UVC driver supports extension unit controls (XU controls) through two separate mechanisms:

> - through mappings of XU controls to V4L2 controls
>
> - through a driver-specific ioctl interface

The first one allows generic V4L2 applications to use XU controls by mapping certain XU controls onto V4L2 controls, which then show up during ordinary control enumeration.

The second mechanism requires uvcvideo-specific knowledge for the application to access XU controls but exposes the entire UVC XU concept to user space for maximum flexibility.

Both mechanisms complement each other and are described in more detail below.

<a id="rst-control-mappings"></a>

### Control mappings

The UVC driver provides an API for user space applications to define so-called control mappings at runtime. These allow for individual XU controls or byte ranges thereof to be mapped to new V4L2 controls. Such controls appear and function exactly like normal V4L2 controls (i.e. the stock controls, such as brightness, contrast, etc.). However, reading or writing of such a V4L2 controls triggers a read or write of the associated XU control.

The ioctl used to create these control mappings is called UVCIOC_CTRL_MAP. Previous driver versions (before 0.2.0) required another ioctl to be used beforehand (UVCIOC_CTRL_ADD) to pass XU control information to the UVC driver. This is no longer necessary as newer uvcvideo versions query the information directly from the device.

For details on the UVCIOC_CTRL_MAP ioctl please refer to the section titled "IOCTL reference" below.

3. Driver specific XU control interface

For applications that need to access XU controls directly, e.g. for testing purposes, firmware upload, or accessing binary controls, a second mechanism to access XU controls is provided in the form of a driver-specific ioctl, namely UVCIOC_CTRL_QUERY.

A call to this ioctl allows applications to send queries to the UVC driver that directly map to the low-level UVC control requests.

In order to make such a request the UVC unit ID of the control's extension unit and the control selector need to be known. This information either needs to be hardcoded in the application or queried using other ways such as by parsing the UVC descriptor or, if available, using the media controller API to enumerate a device's entities.

Unless the control size is already known it is necessary to first make a UVC_GET_LEN requests in order to be able to allocate a sufficiently large buffer and set the buffer size to the correct value. Similarly, to find out whether UVC_GET_CUR or UVC_SET_CUR are valid requests for a given control, a UVC_GET_INFO request should be made. The bits 0 (GET supported) and 1 (SET supported) of the resulting byte indicate which requests are valid.

With the addition of the UVCIOC_CTRL_QUERY ioctl the UVCIOC_CTRL_GET and UVCIOC_CTRL_SET ioctls have become obsolete since their functionality is a subset of the former ioctl. For the time being they are still supported but application developers are encouraged to use UVCIOC_CTRL_QUERY instead.

For details on the UVCIOC_CTRL_QUERY ioctl please refer to the section titled "IOCTL reference" below.

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

### Security

The API doesn't currently provide a fine-grained access control facility. The UVCIOC_CTRL_ADD and UVCIOC_CTRL_MAP ioctls require super user permissions.

Suggestions on how to improve this are welcome.

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

### Debugging

In order to debug problems related to XU controls or controls in general it is recommended to enable the UVC_TRACE_CONTROL bit in the module parameter 'trace'. This causes extra output to be written into the system log.

<a id="rst-ioctl-reference"></a>

### IOCTL reference

<a id="rst-uvcioc-ctrl-map-map-a-uvc-control-to-a-v4l2-control"></a>

#### UVCIOC_CTRL_MAP - Map a UVC control to a V4L2 control

Argument: struct uvc_xu_control_mapping

**Description**:

> This ioctl creates a mapping between a UVC control or part of a UVC control and a V4L2 control. Once mappings are defined, userspace applications can access vendor-defined UVC control through the V4L2 control API.
>
> To create a mapping, applications fill the uvc_xu_control_mapping structure with information about an existing UVC control defined with UVCIOC_CTRL_ADD and a new V4L2 control.
>
> A UVC control can be mapped to several V4L2 controls. For instance, a UVC pan/tilt control could be mapped to separate pan and tilt V4L2 controls. The UVC control is divided into non overlapping fields using the 'size' and 'offset' fields and are then independently mapped to V4L2 control.
>
> For signed integer V4L2 controls the data_type field should be set to UVC_CTRL_DATA_TYPE_SIGNED. Other values are currently ignored.

**Return value**:

> On success 0 is returned. On error -1 is returned and errno is set appropriately.
>
> - **ENOMEM**
>
>   Not enough memory to perform the operation.
>
> - **EPERM**
>
>   Insufficient privileges (super user privileges are required).
>
> - **EINVAL**
>
>   No such UVC control.
>
> - **EOVERFLOW**
>
>   The requested offset and size would overflow the UVC control.
>
> - **EEXIST**
>
>   Mapping already exists.

**Data types**:



```none
* struct uvc_xu_control_mapping

__u32   id              V4L2 control identifier
__u8    name[32]        V4L2 control name
__u8    entity[16]      UVC extension unit GUID
__u8    selector        UVC control selector
__u8    size            V4L2 control size (in bits)
__u8    offset          V4L2 control offset (in bits)
enum v4l2_ctrl_type
        v4l2_type       V4L2 control type
enum uvc_control_data_type
        data_type       UVC control data type
struct uvc_menu_info
        *menu_info      Array of menu entries (for menu controls only)
__u32   menu_count      Number of menu entries (for menu controls only)

* struct uvc_menu_info

__u32   value           Menu entry value used by the device
__u8    name[32]        Menu entry name


* enum uvc_control_data_type

UVC_CTRL_DATA_TYPE_RAW          Raw control (byte array)
UVC_CTRL_DATA_TYPE_SIGNED       Signed integer
UVC_CTRL_DATA_TYPE_UNSIGNED     Unsigned integer
UVC_CTRL_DATA_TYPE_BOOLEAN      Boolean
UVC_CTRL_DATA_TYPE_ENUM         Enumeration
UVC_CTRL_DATA_TYPE_BITMASK      Bitmask
UVC_CTRL_DATA_TYPE_RECT         Rectangular area
```

<a id="rst-uvcioc-ctrl-query-query-a-uvc-xu-control"></a>

#### UVCIOC_CTRL_QUERY - Query a UVC XU control

Argument: struct uvc_xu_control_query

**Description**:

> This ioctl queries a UVC XU control identified by its extension unit ID and control selector.
>
> There are a number of different queries available that closely correspond to the low-level control requests described in the UVC specification. These requests are:
>
> - **UVC_GET_CUR**
>
>   Obtain the current value of the control.
>
> - **UVC_GET_MIN**
>
>   Obtain the minimum value of the control.
>
> - **UVC_GET_MAX**
>
>   Obtain the maximum value of the control.
>
> - **UVC_GET_DEF**
>
>   Obtain the default value of the control.
>
> - **UVC_GET_RES**
>
>   Query the resolution of the control, i.e. the step size of the allowed control values.
>
> - **UVC_GET_LEN**
>
>   Query the size of the control in bytes.
>
> - **UVC_GET_INFO**
>
>   Query the control information bitmap, which indicates whether get/set requests are supported.
>
> - **UVC_SET_CUR**
>
>   Update the value of the control.
>
> Applications must set the 'size' field to the correct length for the control. Exceptions are the UVC_GET_LEN and UVC_GET_INFO queries, for which the size must be set to 2 and 1, respectively. The 'data' field must point to a valid writable buffer big enough to hold the indicated number of data bytes.
>
> Data is copied directly from the device without any driver-side processing. Applications are responsible for data buffer formatting, including little-endian/big-endian conversion. This is particularly important for the result of the UVC_GET_LEN requests, which is always returned as a little-endian 16-bit integer by the device.

**Return value**:

> On success 0 is returned. On error -1 is returned and errno is set appropriately.
>
> - **ENOENT**
>
>   The device does not support the given control or the specified extension unit could not be found.
>
> - **ENOBUFS**
>
>   The specified buffer size is incorrect (too big or too small).
>
> - **EINVAL**
>
>   An invalid request code was passed.
>
> - **EBADRQC**
>
>   The given request is not supported by the given control.
>
> - **EFAULT**
>
>   The data pointer references an inaccessible memory area.

**Data types**:



```none
* struct uvc_xu_control_query

__u8    unit            Extension unit ID
__u8    selector        Control selector
__u8    query           Request code to send to the device
__u16   size            Control data size (in bytes)
__u8    *data           Control value
```

<a id="rst-driver-specific-v4l2-controls"></a>

## Driver-specific V4L2 controls

The uvcvideo driver implements the following UVC-specific controls:

- **`V4L2_CID_UVC_REGION_OF_INTEREST_RECT (struct)`**

  This control determines the region of interest (ROI). ROI is a rectangular area represented by a struct `v4l2_rect`. The rectangle is in global sensor coordinates using pixel units. It is independent of the field of view, not impacted by any cropping or scaling.

  Use `V4L2_CTRL_WHICH_MIN_VAL` and `V4L2_CTRL_WHICH_MAX_VAL` to query the range of rectangle sizes.

  Setting a ROI allows the camera to optimize the capture for the region. The value of `V4L2_CID_REGION_OF_INTEREST_AUTO` control determines the detailed behavior.

  An example of use of this control, can be found in the: `Chrome OS USB camera HAL. <https://chromium.googlesource.com/chromiumos/platform2/+/refs/heads/release-R121-15699.B/camera/hal/usb/>`

- **`V4L2_CID_UVC_REGION_OF_INTEREST_AUTO (bitmask)`**

  This determines which, if any, on-board features should track to the Region of Interest specified by the current value of `V4L2_CID_UVD__REGION_OF_INTEREST_RECT`.

  Max value is a mask indicating all supported Auto Controls.


<table>
<tbody>
<tr>
<td>


`V4L2_UVC_REGION_OF_INTEREST_AUTO_EXPOSURE`

</td>
<td>


Setting this bit causes automatic exposure to track the region of interest instead of the whole image.

</td>
</tr>
<tr>
<td>


`V4L2_UVC_REGION_OF_INTEREST_AUTO_IRIS`

</td>
<td>


Setting this bit causes automatic iris to track the region of interest instead of the whole image.

</td>
</tr>
<tr>
<td>


`V4L2_UVC_REGION_OF_INTEREST_AUTO_WHITE_BALANCE`

</td>
<td>


Setting this bit causes automatic white balance to track the region of interest instead of the whole image.

</td>
</tr>
<tr>
<td>


`V4L2_UVC_REGION_OF_INTEREST_AUTO_FOCUS`

</td>
<td>


Setting this bit causes automatic focus adjustment to track the region of interest instead of the whole image.

</td>
</tr>
<tr>
<td>


`V4L2_UVC_REGION_OF_INTEREST_AUTO_FACE_DETECT`

</td>
<td>


Setting this bit causes automatic face detection to track the region of interest instead of the whole image.

</td>
</tr>
<tr>
<td>


`V4L2_UVC_REGION_OF_INTEREST_AUTO_DETECT_AND_TRACK`

</td>
<td>


Setting this bit enables automatic face detection and tracking. The current value of `V4L2_CID_REGION_OF_INTEREST_RECT` may be updated by the driver.

</td>
</tr>
<tr>
<td>


`V4L2_UVC_REGION_OF_INTEREST_AUTO_IMAGE_STABILIZATION`

</td>
<td>


Setting this bit enables automatic image stabilization. The current value of `V4L2_CID_REGION_OF_INTEREST_RECT` may be updated by the driver.

</td>
</tr>
<tr>
<td>


`V4L2_UVC_REGION_OF_INTEREST_AUTO_HIGHER_QUALITY`

</td>
<td>


Setting this bit enables automatically capture the specified region with higher quality if possible.

</td>
</tr>
</tbody>
</table>

---

# ST VGXY61 camera sensor driver

_Peios Kernel / Userspace interfaces / System and device interfaces / Media driver interfaces_

> The ST VGXY61 driver implements the following controls:

<a id="rst-st-vgxy61-camera-sensor-driver"></a>

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

The ST VGXY61 driver implements the following controls:

<a id="rst-v4l2-cid-hdr-sensor-mode"></a>

## `V4L2_CID_HDR_SENSOR_MODE`

> Change the sensor HDR mode. A HDR picture is obtained by merging two captures of the same scene using two different exposure periods.


<table>
<tbody>
<tr>
<td>


HDR linearize

</td>
<td>


The merger outputs a long exposure capture as long as it is not saturated.

</td>
</tr>
<tr>
<td>


HDR subtraction

</td>
<td>


This involves subtracting the short exposure frame from the long exposure frame.

</td>
</tr>
<tr>
<td>


No HDR

</td>
<td>


This mode is used for standard dynamic range (SDR) exposures.

</td>
</tr>
</tbody>
</table>

---

# Digital TV CA close()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Digital TV CA close()

<a id="rst-digital-tv-ca-close"></a>
<a id="rst-ca-fclose"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

Digital TV CA close()

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

## Synopsis





<a id="c-close"></a>

```c
int close(int fd)
```

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

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

## Description

This system call closes a previously opened CA device.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Digital TV CA open()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Digital TV CA open()

<a id="rst-digital-tv-ca-open"></a>
<a id="rst-ca-fopen"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

Digital TV CA open()

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

## Synopsis





<a id="c-open"></a>

```c
int open(const char *name, int flags)
```

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

## Arguments

- **`name`**

  Name of specific Digital TV CA device.

- **`flags`**

  A bit-wise OR of the following flags:

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`O_RDONLY`

</td>
<td>


read-only access

</td>
</tr>
<tr>
<td>


`O_RDWR`

</td>
<td>


read/write access

</td>
</tr>
<tr>
<td>


`O_NONBLOCK`

</td>
<td>


open in non-blocking mode (blocking mode is the default)

</td>
</tr>
</tbody>
</table>

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

## Description

This system call opens a named ca device (e.g. `/dev/dvb/adapter?/ca?`) for subsequent use.

When an `open()` call has succeeded, the device will be ready for use. The significance of blocking or non-blocking mode is described in the documentation for functions where there is a difference. It does not affect the semantics of the `open()` call itself. A device opened in blocking mode can later be put into non-blocking mode (and vice versa) using the `F_SETFL` command of the `fcntl` system call. This is a standard system call, documented in the Linux manual page for fcntl. Only one user can open the CA Device in `O_RDWR` mode. All other attempts to open the device in this mode will fail, and an error code will be returned.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# CA_GET_CAP

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "ca_get_cap".

<a id="rst-ca-get-cap-1"></a>
<a id="rst-ca-get-cap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

CA_GET_CAP

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

## Synopsis





<a id="c-CA_GET_CAP"></a>

```c
CA_GET_CAP
```

`int ioctl(fd, CA_GET_CAP, struct ca_caps *caps)`

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

- **`caps`**

  Pointer to struct `ca_caps`.

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

## Description

Queries the Kernel for information about the available CA and descrambler slots, and their types.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned and `ca_caps` is filled.

On error, -1 is returned and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# CA_GET_DESCR_INFO

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "ca_get_descr_info".

<a id="rst-ca-get-descr-info-1"></a>
<a id="rst-ca-get-descr-info"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

CA_GET_DESCR_INFO

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

## Synopsis





<a id="c-CA_GET_DESCR_INFO"></a>

```c
CA_GET_DESCR_INFO
```

`int ioctl(fd, CA_GET_DESCR_INFO, struct ca_descr_info *desc)`

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

- **`desc`**

  Pointer to struct `ca_descr_info`.

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

## Description

Returns information about all descrambler slots.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, and `ca_descr_info` is filled.

On error -1 is returned, and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# CA_GET_MSG

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "ca_get_msg".

<a id="rst-ca-get-msg-1"></a>
<a id="rst-ca-get-msg"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

CA_GET_MSG

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

## Synopsis





<a id="c-CA_GET_MSG"></a>

```c
CA_GET_MSG
```

`int ioctl(fd, CA_GET_MSG, struct ca_msg *msg)`

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

- **`msg`**

  Pointer to struct `ca_msg`.

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

## Description

Receives a message via a CI CA module.

> [!NOTE]
>
> Please notice that, on most drivers, this is done by reading from the /dev/adapter?/ca? device node.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# CA_GET_SLOT_INFO

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "ca_get_slot_info".

<a id="rst-ca-get-slot-info-1"></a>
<a id="rst-ca-get-slot-info"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

CA_GET_SLOT_INFO

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

## Synopsis





<a id="c-CA_GET_SLOT_INFO"></a>

```c
CA_GET_SLOT_INFO
```

`int ioctl(fd, CA_GET_SLOT_INFO, struct ca_slot_info *info)`

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

- **`info`**

  Pointer to struct `ca_slot_info`.

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

## Description

Returns information about a CA slot identified by `ca_slot_info`.slot_num.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, and `ca_slot_info` is filled.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`ENODEV`

</td>
<td>


the slot is not available.

</td>
</tr>
</tbody>
</table>

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# CA_RESET

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "ca_reset".

<a id="rst-ca-reset-1"></a>
<a id="rst-ca-reset"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

CA_RESET

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

## Synopsis





<a id="c-CA_RESET"></a>

```c
CA_RESET
```

`int ioctl(fd, CA_RESET)`

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

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

## Description

Puts the Conditional Access hardware on its initial state. It should be called before start using the CA hardware.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# CA_SEND_MSG

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "ca_send_msg".

<a id="rst-ca-send-msg-1"></a>
<a id="rst-ca-send-msg"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

CA_SEND_MSG

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

## Synopsis





<a id="c-CA_SEND_MSG"></a>

```c
CA_SEND_MSG
```

`int ioctl(fd, CA_SEND_MSG, struct ca_msg *msg)`

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

- **`msg`**

  Pointer to struct `ca_msg`.

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

## Description

Sends a message via a CI CA module.

> [!NOTE]
>
> Please notice that, on most drivers, this is done by writing to the /dev/adapter?/ca? device node.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# CA_SET_DESCR

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "ca_set_descr".

<a id="rst-ca-set-descr-1"></a>
<a id="rst-ca-set-descr"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.ca -->

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

## Name

CA_SET_DESCR

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

## Synopsis





<a id="c-CA_SET_DESCR"></a>

```c
CA_SET_DESCR
```

`int ioctl(fd, CA_SET_DESCR, struct ca_descr *desc)`

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

- **`msg`**

  Pointer to struct `ca_descr`.

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

## Description

CA_SET_DESCR is used for feeding descrambler CA slots with descrambling keys (referred as control words).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Digital TV CA Device

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The Digital TV CA device controls the conditional access hardware. It can be accessed through /dev/dvb/adapter?/ca?. Data types and ioctl definitions can be accessed by including linux/dvb/ca.h in your application.

<a id="rst-digital-tv-ca-device"></a>
<a id="rst-dvb-ca"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The Digital TV CA device controls the conditional access hardware. It can be accessed through `/dev/dvb/adapter?/ca?`. Data types and ioctl definitions can be accessed by including `linux/dvb/ca.h` in your application.

> [!NOTE]
>
> There are three ioctls at this API that aren't documented: [CA_GET_MSG](</kernel/userspace/userspace-api/media-dvb/ca-get-msg.md#rst-ca-get-msg-1>), [CA_SEND_MSG](</kernel/userspace/userspace-api/media-dvb/ca-send-msg.md#rst-ca-send-msg-1>) and [CA_SET_DESCR](</kernel/userspace/userspace-api/media-dvb/ca-set-descr.md#rst-ca-set-descr-1>). Documentation for them are welcome.

- [CA Data Types](</kernel/userspace/userspace-api/media-dvb/ca-data-types.md>)
- [CA Function Calls](</kernel/userspace/userspace-api/media-dvb/ca-function-calls.md>)
- [The High level CI API](</kernel/userspace/userspace-api/media-dvb/ca-high-level.md>)

---

# CA Data Types

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for CA Data Types.

<a id="rst-ca-data-types-1"></a>
<a id="rst-ca-data-types"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->


#### <a id="c-struct-ca_slot_info"></a>`struct ca_slot_info`

CA slot interface types and info.

**Definition**

```c
struct ca_slot_info {
        int num;
        int type;
    #define CA_CI            1;
    #define CA_CI_LINK       2;
    #define CA_CI_PHYS       4;
    #define CA_DESCR         8;
    #define CA_SC          128;
        unsigned int flags;
    #define CA_CI_MODULE_PRESENT 1;
    #define CA_CI_MODULE_READY   2;
};
```

**Members**

- `num`: slot number.
- `type`: slot type.
- `flags`: flags applicable to the slot.

**Description**

This struct stores the CA slot information.

**type** can be:

- `CA_CI` - CI high level interface;
- `CA_CI_LINK` - CI link layer level interface;
- `CA_CI_PHYS` - CI physical layer level interface;
- `CA_DESCR` - built-in descrambler;
- `CA_SC` -simple smart card interface.

**flags** can be:

- `CA_CI_MODULE_PRESENT` - module (or card) inserted;
- `CA_CI_MODULE_READY` - module is ready for usage.

#### <a id="c-struct-ca_descr_info"></a>`struct ca_descr_info`

descrambler types and info.

**Definition**

```c
struct ca_descr_info {
        unsigned int num;
        unsigned int type;
    #define CA_ECD           1;
    #define CA_NDS           2;
    #define CA_DSS           4;
};
```

**Members**

- `num`: number of available descramblers (keys).
- `type`: type of supported scrambling system.

**Description**

Identifies the number of descramblers and their type.

**type** can be:

- `CA_ECD` - European Common Descrambler (ECD) hardware;
- `CA_NDS` - Videoguard (NDS) hardware;
- `CA_DSS` - Distributed Sample Scrambling (DSS) hardware.

#### <a id="c-struct-ca_caps"></a>`struct ca_caps`

CA slot interface capabilities.

**Definition**

```c
struct ca_caps {
    unsigned int slot_num;
    unsigned int slot_type;
    unsigned int descr_num;
    unsigned int descr_type;
};
```

**Members**

- `slot_num`: total number of CA card and module slots.
- `slot_type`: bitmap with all supported types as defined at
  [`struct ca_slot_info`](#c-struct-ca_slot_info) (e. g. `CA_CI`, `CA_CI_LINK`, etc).
- `descr_num`: total number of descrambler slots (keys)
- `descr_type`: bitmap with all supported types as defined at
  [`struct ca_descr_info`](#c-struct-ca_descr_info) (e. g. `CA_ECD`, `CA_NDS`, etc).

#### <a id="c-struct-ca_msg"></a>`struct ca_msg`

a message to/from a CI-CAM

**Definition**

```c
struct ca_msg {
    unsigned int index;
    unsigned int type;
    unsigned int length;
    unsigned char msg[256];
};
```

**Members**

- `index`: unused
- `type`: unused
- `length`: length of the message
- `msg`: message

**Description**

This struct carries a message to be send/received from a CI CA module.

#### <a id="c-struct-ca_descr"></a>`struct ca_descr`

CA descrambler control words info

**Definition**

```c
struct ca_descr {
    unsigned int index;
    unsigned int parity;
    unsigned char cw[8];
};
```

**Members**

- `index`: CA Descrambler slot
- `parity`: control words parity, where 0 means even and 1 means odd
- `cw`: CA Descrambler control words

---

# CA Function Calls

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for CA Function Calls.

<a id="rst-ca-function-calls-1"></a>
<a id="rst-ca-function-calls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

- [Digital TV CA open()](</kernel/userspace/userspace-api/media-dvb/ca-fopen.md>)
- [Digital TV CA close()](</kernel/userspace/userspace-api/media-dvb/ca-fclose.md>)
- [CA_RESET](</kernel/userspace/userspace-api/media-dvb/ca-reset.md>)
- [CA_GET_CAP](</kernel/userspace/userspace-api/media-dvb/ca-get-cap.md>)
- [CA_GET_SLOT_INFO](</kernel/userspace/userspace-api/media-dvb/ca-get-slot-info.md>)
- [CA_GET_DESCR_INFO](</kernel/userspace/userspace-api/media-dvb/ca-get-descr-info.md>)
- [CA_GET_MSG](</kernel/userspace/userspace-api/media-dvb/ca-get-msg.md>)
- [CA_SEND_MSG](</kernel/userspace/userspace-api/media-dvb/ca-send-msg.md>)
- [CA_SET_DESCR](</kernel/userspace/userspace-api/media-dvb/ca-set-descr.md>)

---

# The High level CI API

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> This document describes the high level CI API as in accordance to the Linux DVB API.

<a id="rst-the-high-level-ci-api"></a>

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

> [!NOTE]
>
> This documentation is outdated.

This document describes the high level CI API as in accordance to the Linux DVB API.

With the High Level CI approach any new card with almost any random architecture can be implemented with this style, the definitions inside the switch statement can be easily adapted for any card, thereby eliminating the need for any additional ioctls.

The disadvantage is that the driver/hardware has to manage the rest. For the application programmer it would be as simple as sending/receiving an array to/from the CI ioctls as defined in the Linux DVB API. No changes have been made in the API to accommodate this feature.

<a id="rst-why-the-need-for-another-ci-interface"></a>

## Why the need for another CI interface?

This is one of the most commonly asked question. Well a nice question. Strictly speaking this is not a new interface.

The CI interface is defined in the DVB API in ca.h as:



```c
typedef struct ca_slot_info {
        int num;               /* slot number */

        int type;              /* CA interface this slot supports */
#define CA_CI            1     /* CI high level interface */
#define CA_CI_LINK       2     /* CI link layer level interface */
#define CA_CI_PHYS       4     /* CI physical layer level interface */
#define CA_DESCR         8     /* built-in descrambler */
#define CA_SC          128     /* simple smart card interface */

        unsigned int flags;
#define CA_CI_MODULE_PRESENT 1 /* module (or card) inserted */
#define CA_CI_MODULE_READY   2
} ca_slot_info_t;
```

This CI interface follows the CI high level interface, which is not implemented by most applications. Hence this area is revisited.

This CI interface is quite different in the case that it tries to accommodate all other CI based devices, that fall into the other categories.

This means that this CI interface handles the EN50221 style tags in the Application layer only and no session management is taken care of by the application. The driver/hardware will take care of all that.

This interface is purely an EN50221 interface exchanging APDU's. This means that no session management, link layer or a transport layer do exist in this case in the application to driver communication. It is as simple as that. The driver/hardware has to take care of that.

With this High Level CI interface, the interface can be defined with the regular ioctls.

All these ioctls are also valid for the High level CI interface

\#define CA_RESET          \_IO('o', 128) \#define CA_GET_CAP        \_IOR('o', 129, ca_caps_t) \#define CA_GET_SLOT_INFO  \_IOR('o', 130, ca_slot_info_t) \#define CA_GET_DESCR_INFO \_IOR('o', 131, ca_descr_info_t) \#define CA_GET_MSG        \_IOR('o', 132, ca_msg_t) \#define CA_SEND_MSG       \_IOW('o', 133, ca_msg_t) \#define CA_SET_DESCR      \_IOW('o', 134, ca_descr_t)

On querying the device, the device yields information thus:



```none
CA_GET_SLOT_INFO
----------------------------
Command = [info]
APP: Number=[1]
APP: Type=[1]
APP: flags=[1]
APP: CI High level interface
APP: CA/CI Module Present

CA_GET_CAP
----------------------------
Command = [caps]
APP: Slots=[1]
APP: Type=[1]
APP: Descrambler keys=[16]
APP: Type=[1]

CA_SEND_MSG
----------------------------
Descriptors(Program Level)=[ 09 06 06 04 05 50 ff f1]
Found CA descriptor @ program level

(20) ES type=[2] ES pid=[201]  ES length =[0 (0x0)]
(25) ES type=[4] ES pid=[301]  ES length =[0 (0x0)]
ca_message length is 25 (0x19) bytes
EN50221 CA MSG=[ 9f 80 32 19 03 01 2d d1 f0 08 01 09 06 06 04 05 50 ff f1 02 e0 c9 00 00 04 e1 2d 00 00]
```

Not all ioctl's are implemented in the driver from the API, the other features of the hardware that cannot be implemented by the API are achieved using the CA_GET_MSG and CA_SEND_MSG ioctls. An EN50221 style wrapper is used to exchange the data to maintain compatibility with other hardware.



```c
/* a message to/from a CI-CAM */
typedef struct ca_msg {
        unsigned int index;
        unsigned int type;
        unsigned int length;
        unsigned char msg[256];
} ca_msg_t;
```

The flow of data can be described thus,



```none
     App (User)
     -----
     parse
       |
       |
       v
     en50221 APDU (package)
--------------------------------------
|      |                             | High Level CI driver
|      |                             |
|      v                             |
|    en50221 APDU (unpackage)        |
|      |                             |
|      |                             |
|      v                             |
|    sanity checks                   |
|      |                             |
|      |                             |
|      v                             |
|    do (H/W dep)                    |
--------------------------------------
       |    Hardware
       |
       v
```

The High Level CI interface uses the EN50221 DVB standard, following a standard ensures futureproofness.

---

# Digital TV Demux Device

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The Digital TV demux device controls the MPEG-TS filters for the digital TV. If the driver and hardware supports, those filters are implemented at the hardware. Otherwise, the Kernel provides a software emulation.

<a id="rst-digital-tv-demux-device"></a>
<a id="rst-dvb-demux"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The Digital TV demux device controls the MPEG-TS filters for the digital TV. If the driver and hardware supports, those filters are implemented at the hardware. Otherwise, the Kernel provides a software emulation.

It can be accessed through `/dev/adapter?/demux?`. Data types and ioctl definitions can be accessed by including `linux/dvb/dmx.h` in your application.

- [Demux Data Types](</kernel/userspace/userspace-api/media-dvb/dmx-types.md>)
- [Demux Function Calls](</kernel/userspace/userspace-api/media-dvb/dmx-fcalls.md>)

---

# DMX_ADD_PID

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_add_pid".

<a id="rst-dmx-add-pid-1"></a>
<a id="rst-dmx-add-pid"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_ADD_PID

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

## Synopsis





<a id="c-DMX_ADD_PID"></a>

```c
DMX_ADD_PID
```

`int ioctl(fd, DMX_ADD_PID, __u16 *pid)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`pid`**

  PID number to be filtered.

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

## Description

This ioctl call allows to add multiple PIDs to a transport stream filter previously set up with [DMX_SET_PES_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-pes-filter.md#rst-dmx-set-pes-filter-1>) and output equal to `DMX_OUT_TSDEMUX_TAP <dmx_output>`.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl DMX_EXPBUF

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> DMX_EXPBUF - Export a buffer as a DMABUF file descriptor.

<a id="rst-ioctl-dmx-expbuf"></a>
<a id="rst-dmx-expbuf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_EXPBUF - Export a buffer as a DMABUF file descriptor.

> [!WARNING]
>
> this API is still experimental

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

## Synopsis





<a id="c-DMX_EXPBUF"></a>

```c
DMX_EXPBUF
```

`int ioctl(int fd, DMX_EXPBUF, struct dmx_exportbuffer *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `dmx_exportbuffer`.

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

## Description

This ioctl is an extension to the memory mapping I/O method. It can be used to export a buffer as a DMABUF file at any time after buffers have been allocated with the [ioctl DMX_REQBUFS](</kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md#rst-dmx-reqbufs>) ioctl.

To export a buffer, applications fill struct `dmx_exportbuffer`. Applications must set the `index` field. Valid index numbers range from zero to the number of buffers allocated with [ioctl DMX_REQBUFS](</kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md#rst-dmx-reqbufs>) (struct `dmx_requestbuffers` `count`) minus one. Additional flags may be posted in the `flags` field. Refer to a manual for open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, and O_RDWR are supported. All other fields must be set to zero. In the case of multi-planar API, every plane is exported separately using multiple [ioctl DMX_EXPBUF](<#rst-dmx-expbuf>) calls.

After calling [ioctl DMX_EXPBUF](<#rst-dmx-expbuf>) the `fd` field will be set by a driver, on success. This is a DMABUF file descriptor. The application may pass it to other DMABUF-aware devices. It is recommended to close a DMABUF file when it is no longer used to allow the associated memory to be reclaimed.

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

## Examples



```c
int buffer_export(int v4lfd, enum dmx_buf_type bt, int index, int *dmafd)
{
    struct dmx_exportbuffer expbuf;

    memset(&expbuf, 0, sizeof(expbuf));
    expbuf.type = bt;
    expbuf.index = index;
    if (ioctl(v4lfd, DMX_EXPBUF, &expbuf) == -1) {
        perror("DMX_EXPBUF");
        return -1;
    }

    *dmafd = expbuf.fd;

    return 0;
}
```

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  A queue is not in MMAP mode or DMABUF exporting is not supported or `flags` or `index` fields are invalid.

---

# Digital TV demux close()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Digital TV demux close()

<a id="rst-digital-tv-demux-close"></a>
<a id="rst-dmx-fclose"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

Digital TV demux close()

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

## Synopsis





<a id="c-close"></a>

```c
int close(int fd)
```

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

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

## Description

This system call deactivates and deallocates a filter that was previously allocated via the `open()` call.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error, -1 is returned and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Digital TV demux open()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Digital TV demux open()

<a id="rst-digital-tv-demux-open"></a>
<a id="rst-dmx-fopen"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

Digital TV demux open()

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

## Synopsis





<a id="c-open"></a>

```c
int open(const char *deviceName, int flags)
```

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

## Arguments

- **`name`**

  Name of specific Digital TV demux device.

- **`flags`**

  A bit-wise OR of the following flags:

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`O_RDONLY`

</td>
<td>


read-only access

</td>
</tr>
<tr>
<td>


`O_RDWR`

</td>
<td>


read/write access

</td>
</tr>
<tr>
<td>


`O_NONBLOCK`

</td>
<td>


open in non-blocking mode (blocking mode is the default)

</td>
</tr>
</tbody>
</table>

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

## Description

This system call, used with a device name of `/dev/dvb/adapter?/demux?`, allocates a new filter and returns a handle which can be used for subsequent control of that filter. This call has to be made for each filter to be used, i.e. every returned file descriptor is a reference to a single filter. `/dev/dvb/adapter?/dvr?` is a logical device to be used for retrieving Transport Streams for digital video recording. When reading from this device a transport stream containing the packets from all PES filters set in the corresponding demux device (`/dev/dvb/adapter?/demux?`) having the output set to `DMX_OUT_TS_TAP`. A recorded Transport Stream is replayed by writing to this device.

The significance of blocking or non-blocking mode is described in the documentation for functions where there is a difference. It does not affect the semantics of the `open()` call itself. A device opened in blocking mode can later be put into non-blocking mode (and vice versa) using the `F_SETFL` command of the fcntl system call.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`EMFILE`

</td>
<td>


"Too many open files", i.e. no more filters available.

</td>
</tr>
</tbody>
</table>

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Digital TV demux read()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Digital TV demux read()

<a id="rst-digital-tv-demux-read"></a>
<a id="rst-dmx-fread"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

Digital TV demux read()

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

## Synopsis





<a id="c-read"></a>

```c
size_t read(int fd, void *buf, size_t count)
```

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

## Arguments

- **`fd`**

  > File descriptor returned by a previous call to `open()`.

  - **`buf`**

    Buffer to be filled

- **`count`**

  Max number of bytes to read

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

## Description

This system call returns filtered data, which might be section or Packetized Elementary Stream (PES) data. The filtered data is transferred from the driver's internal circular buffer to `buf`. The maximum amount of data to be transferred is implied by count.

> [!NOTE]
>
> if a section filter created with `DMX_CHECK_CRC <dmx_sct_filter_params>` flag set, data that fails on CRC check will be silently ignored.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`EWOULDBLOCK`

</td>
<td>


No data to return and `O_NONBLOCK` was specified.

</td>
</tr>
<tr>
<td>


`EOVERFLOW`

</td>
<td>


The filtered data was not read from the buffer in due time, resulting in non-read data being lost. The buffer is flushed.

</td>
</tr>
<tr>
<td>


`ETIMEDOUT`

</td>
<td>


The section was not loaded within the stated timeout period. See ioctl [DMX_SET_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-filter.md#rst-dmx-set-filter-1>) for how to set a timeout.

</td>
</tr>
<tr>
<td>


`EFAULT`

</td>
<td>


The driver failed to write to the callers buffer due to an invalid \*buf pointer.

</td>
</tr>
</tbody>
</table>

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Digital TV demux write()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Digital TV demux write()

<a id="rst-digital-tv-demux-write"></a>
<a id="rst-dmx-fwrite"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

Digital TV demux write()

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

## Synopsis





<a id="c-write"></a>

```c
ssize_t write(int fd, const void *buf, size_t count)
```

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

## Arguments

- **`fd`**

  File descriptor returned by a previous call to `open()`.

- **`buf`**

  Buffer with data to be written

- **`count`**

  Number of bytes at the buffer

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

## Description

This system call is only provided by the logical device `/dev/dvb/adapter?/dvr?`, associated with the physical demux device that provides the actual DVR functionality. It is used for replay of a digitally recorded Transport Stream. Matching filters have to be defined in the corresponding physical demux device, `/dev/dvb/adapter?/demux?`. The amount of data to be transferred is implied by count.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`EWOULDBLOCK`

</td>
<td>


No data was written. This might happen if `O_NONBLOCK` was specified and there is no more buffer space available (if `O_NONBLOCK` is not specified the function will block until buffer space is available).

</td>
</tr>
<tr>
<td>


`EBUSY`

</td>
<td>


This error code indicates that there are conflicting requests. The corresponding demux device is setup to receive data from the front- end. Make sure that these filters are stopped and that the filters with input set to `DMX_IN_DVR` are started.

</td>
</tr>
</tbody>
</table>

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# DMX_GET_PES_PIDS

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_get_pes_pids".

<a id="rst-dmx-get-pes-pids-1"></a>
<a id="rst-dmx-get-pes-pids"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_GET_PES_PIDS

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

## Synopsis





<a id="c-DMX_GET_PES_PIDS"></a>

```c
DMX_GET_PES_PIDS
```

`int ioctl(fd, DMX_GET_PES_PIDS, __u16 pids[5])`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`pids`**

  Array used to store 5 Program IDs.

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

## Description

This ioctl allows to query a DVB device to return the first PID used by audio, video, textext, subtitle and PCR programs on a given service. They're stored as:


<table>
<thead>
<tr>
<th>


PID  element

</th>
<th>


position

</th>
<th>


content

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


pids\[DMX_PES_AUDIO\]

</td>
<td>


0

</td>
<td>


first audio PID

</td>
</tr>
<tr>
<td>


pids\[DMX_PES_VIDEO\]

</td>
<td>


1

</td>
<td>


first video PID

</td>
</tr>
<tr>
<td>


pids\[DMX_PES_TELETEXT\]

</td>
<td>


2

</td>
<td>


first teletext PID

</td>
</tr>
<tr>
<td>


pids\[DMX_PES_SUBTITLE\]

</td>
<td>


3

</td>
<td>


first subtitle PID

</td>
</tr>
<tr>
<td>


pids\[DMX_PES_PCR\]

</td>
<td>


4

</td>
<td>


first Program Clock Reference PID

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> A value equal to 0xffff means that the PID was not filled by the Kernel.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# DMX_GET_STC

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_get_stc".

<a id="rst-dmx-get-stc-1"></a>
<a id="rst-dmx-get-stc"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_GET_STC

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

## Synopsis





<a id="c-DMX_GET_STC"></a>

```c
DMX_GET_STC
```

`int ioctl(int fd, DMX_GET_STC, struct dmx_stc *stc)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`stc`**

  Pointer to `dmx_stc` where the stc data is to be stored.

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

## Description

This ioctl call returns the current value of the system time counter (which is driven by a PES filter of type `DMX_PES_PCR <dmx_ts_pes>`). Some hardware supports more than one STC, so you must specify which one by setting the `num <dmx_stc>` field of stc before the ioctl (range 0...n). The result is returned in form of a ratio with a 64 bit numerator and a 32 bit denominator, so the real 90kHz STC value is `stc->stc / stc->base`.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`EINVAL`

</td>
<td>


Invalid stc number.

</td>
</tr>
</tbody>
</table>

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Digital TV mmap()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> dmx-mmap - Map device memory into application address space

<a id="rst-digital-tv-mmap"></a>
<a id="rst-dmx-mmap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

dmx-mmap - Map device memory into application address space

> [!WARNING]
>
> this API is still experimental

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

## Synopsis



```c
#include <unistd.h>
#include <sys/mman.h>
```





<a id="c-mmap"></a>

```c
void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset )
```

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

## Arguments

- **`start`**

  Map the buffer to this address in the application's address space. When the `MAP_FIXED` flag is specified, `start` must be a multiple of the pagesize and mmap will fail when the specified address cannot be used. Use of this option is discouraged; applications should just specify a `NULL` pointer here.

- **`length`**

  Length of the memory area to map. This must be a multiple of the DVB packet length (188, on most drivers).

- **`prot`**

  The `prot` argument describes the desired memory protection. Regardless of the device type and the direction of data exchange it should be set to `PROT_READ` \| `PROT_WRITE`, permitting read and write access to image buffers. Drivers should support at least this combination of flags.

- **`flags`**

  The `flags` parameter specifies the type of the mapped object, mapping options and whether modifications made to the mapped copy of the page are private to the process or are to be shared with other references.

  `MAP_FIXED` requests that the driver selects no other address than the one specified. If the specified address cannot be used, `mmap()` will fail. If `MAP_FIXED` is specified, `start` must be a multiple of the pagesize. Use of this option is discouraged.

  One of the `MAP_SHARED` or `MAP_PRIVATE` flags must be set. `MAP_SHARED` allows applications to share the mapped memory with other (e. g. child-) processes.

  > [!NOTE]
  >
  > The Linux Digital TV applications should not set the `MAP_PRIVATE`, `MAP_DENYWRITE`, `MAP_EXECUTABLE` or `MAP_ANON` flags.

- **`fd`**

  File descriptor returned by `open()`.

- **`offset`**

  Offset of the buffer in device memory, as returned by [ioctl DMX_QUERYBUF](</kernel/userspace/userspace-api/media-dvb/dmx-querybuf.md#rst-dmx-querybuf>) ioctl.

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

## Description

The `mmap()` function asks to map `length` bytes starting at `offset` in the memory of the device specified by `fd` into the application address space, preferably at address `start`. This latter address is a hint only, and is usually specified as 0.

Suitable length and offset parameters are queried with the [ioctl DMX_QUERYBUF](</kernel/userspace/userspace-api/media-dvb/dmx-querybuf.md#rst-dmx-querybuf>) ioctl. Buffers must be allocated with the [ioctl DMX_REQBUFS](</kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md#rst-dmx-reqbufs>) ioctl before they can be queried.

To unmap buffers the `munmap()` function is used.

<a id="rst-return-value"></a>

## Return Value

On success `mmap()` returns a pointer to the mapped buffer. On error `MAP_FAILED` (-1) is returned, and the `errno` variable is set appropriately. Possible error codes are:

- **EBADF**

  `fd` is not a valid file descriptor.

- **EACCES**

  `fd` is not open for reading and writing.

- **EINVAL**

  The `start` or `length` or `offset` are not suitable. (E. g. they are too large, or not aligned on a `PAGESIZE` boundary.)

  The `flags` or `prot` value is not supported.

  No buffers have been allocated with the [ioctl DMX_REQBUFS](</kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md#rst-dmx-reqbufs>) ioctl.

- **ENOMEM**

  Not enough physical or virtual memory was available to complete the request.

---

# DVB munmap()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> dmx-munmap - Unmap device memory

<a id="rst-dvb-munmap"></a>
<a id="rst-dmx-munmap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

dmx-munmap - Unmap device memory

> [!WARNING]
>
> This API is still experimental.

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

## Synopsis



```c
#include <unistd.h>
#include <sys/mman.h>
```





<a id="c-munmap"></a>

```c
int munmap( void *start, size_t length )
```

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

## Arguments

- **`start`**

  Address of the mapped buffer as returned by the `mmap()` function.

- **`length`**

  Length of the mapped buffer. This must be the same value as given to `mmap()`.

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

## Description

Unmaps a previously with the `mmap()` function mapped buffer and frees it, if possible.

<a id="rst-return-value"></a>

## Return Value

On success `munmap()` returns 0, on failure -1 and the `errno` variable is set appropriately:

- **EINVAL**

  The `start` or `length` is incorrect, or no buffers have been mapped yet.

---

# ioctl DMX_QBUF, DMX_DQBUF

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> DMX_QBUF - DMX_DQBUF - Exchange a buffer with the driver

<a id="rst-ioctl-dmx-qbuf-dmx-dqbuf"></a>
<a id="rst-dmx-qbuf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_QBUF - DMX_DQBUF - Exchange a buffer with the driver

> [!WARNING]
>
> this API is still experimental

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

## Synopsis





<a id="c-DMX_QBUF"></a>

```c
DMX_QBUF
```

`int ioctl(int fd, DMX_QBUF, struct dmx_buffer *argp)`





<a id="c-DMX_DQBUF"></a>

```c
DMX_DQBUF
```

`int ioctl(int fd, DMX_DQBUF, struct dmx_buffer *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `dmx_buffer`.

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

## Description

Applications call the `DMX_QBUF` ioctl to enqueue an empty (capturing) or filled (output) buffer in the driver's incoming queue. The semantics depend on the selected I/O method.

To enqueue a buffer applications set the `index` field. Valid index numbers range from zero to the number of buffers allocated with [ioctl DMX_REQBUFS](</kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md#rst-dmx-reqbufs>) (struct `dmx_requestbuffers` `count`) minus one. The contents of the struct `dmx_buffer` returned by a [ioctl DMX_QUERYBUF](</kernel/userspace/userspace-api/media-dvb/dmx-querybuf.md#rst-dmx-querybuf>) ioctl will do as well.

When `DMX_QBUF` is called with a pointer to this structure, it locks the memory pages of the buffer in physical memory, so they cannot be swapped out to disk. Buffers remain locked until dequeued, until the device is closed.

Applications call the `DMX_DQBUF` ioctl to dequeue a filled (capturing) buffer from the driver's outgoing queue. They just set the `index` field with the buffer ID to be queued. When `DMX_DQBUF` is called with a pointer to struct `dmx_buffer`, the driver fills the remaining fields or returns an error code.

By default `DMX_DQBUF` blocks when no buffer is in the outgoing queue. When the `O_NONBLOCK` flag was given to the `open()` function, `DMX_DQBUF` returns immediately with an `EAGAIN` error code when no buffer is available.

The struct `dmx_buffer` structure is specified in [buffer](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/buffer.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EAGAIN**

  Non-blocking I/O has been selected using `O_NONBLOCK` and no buffer was in the outgoing queue.

- **EINVAL**

  The `index` is out of bounds, or no buffers have been allocated yet.

- **EIO**

  `DMX_DQBUF` failed due to an internal error. Can also indicate temporary problems like signal loss or CRC errors.

---

# ioctl DMX_QUERYBUF

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> DMX_QUERYBUF - Query the status of a buffer

<a id="rst-ioctl-dmx-querybuf"></a>
<a id="rst-dmx-querybuf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_QUERYBUF - Query the status of a buffer

> [!WARNING]
>
> this API is still experimental

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

## Synopsis





<a id="c-DMX_QUERYBUF"></a>

```c
DMX_QUERYBUF
```

`int ioctl(int fd, DMX_QUERYBUF, struct dvb_buffer *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `dvb_buffer`.

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

## Description

This ioctl is part of the mmap streaming I/O method. It can be used to query the status of a buffer at any time after buffers have been allocated with the [ioctl DMX_REQBUFS](</kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md#rst-dmx-reqbufs>) ioctl.

Applications set the `index` field. Valid index numbers range from zero to the number of buffers allocated with [ioctl DMX_REQBUFS](</kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md#rst-dmx-reqbufs>) (struct `dvb_requestbuffers` `count`) minus one.

After calling [ioctl DMX_QUERYBUF](<#rst-dmx-querybuf>) with a pointer to this structure, drivers return an error code or fill the rest of the structure.

On success, the `offset` will contain the offset of the buffer from the start of the device memory, the `length` field its size, and the `bytesused` the number of bytes occupied by data in the buffer (payload).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, the `offset` will contain the offset of the buffer from the start of the device memory, the `length` field its size, and the `bytesused` the number of bytes occupied by data in the buffer (payload).

On error it returns -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The `index` is out of bounds.

---

# DMX_REMOVE_PID

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_remove_pid".

<a id="rst-dmx-remove-pid-1"></a>
<a id="rst-dmx-remove-pid"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_REMOVE_PID

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

## Synopsis





<a id="c-DMX_REMOVE_PID"></a>

```c
DMX_REMOVE_PID
```

`int ioctl(fd, DMX_REMOVE_PID, __u16 *pid)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`pid`**

  PID of the PES filter to be removed.

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

## Description

This ioctl call allows to remove a PID when multiple PIDs are set on a transport stream filter, e. g. a filter previously set up with output equal to `DMX_OUT_TSDEMUX_TAP <dmx_output>`, created via either [DMX_SET_PES_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-pes-filter.md#rst-dmx-set-pes-filter-1>) or [DMX_ADD_PID](</kernel/userspace/userspace-api/media-dvb/dmx-add-pid.md#rst-dmx-add-pid-1>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl DMX_REQBUFS

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> DMX_REQBUFS - Initiate Memory Mapping and/or DMA buffer I/O

<a id="rst-ioctl-dmx-reqbufs"></a>
<a id="rst-dmx-reqbufs"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_REQBUFS - Initiate Memory Mapping and/or DMA buffer I/O

> [!WARNING]
>
> this API is still experimental

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

## Synopsis





<a id="c-DMX_REQBUFS"></a>

```c
DMX_REQBUFS
```

`int ioctl(int fd, DMX_REQBUFS, struct dmx_requestbuffers *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `dmx_requestbuffers`.

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

## Description

This ioctl is used to initiate a memory mapped or DMABUF based demux I/O.

Memory mapped buffers are located in device memory and must be allocated with this ioctl before they can be mapped into the application's address space. User buffers are allocated by applications themselves, and this ioctl is merely used to switch the driver into user pointer I/O mode and to setup some internal structures. Similarly, DMABUF buffers are allocated by applications through a device driver, and this ioctl only configures the driver into DMABUF I/O mode without performing any direct allocation.

To allocate device buffers applications initialize all fields of the struct `dmx_requestbuffers` structure. They set the  `count` field to the desired number of buffers,  and `size` to the size of each buffer.

When the ioctl is called with a pointer to this structure, the driver will attempt to allocate the requested number of buffers and it stores the actual number allocated in the `count` field. The `count` can be smaller than the number requested, even zero, when the driver runs out of free memory. A larger number is also possible when the driver requires more buffers to function correctly. The actual allocated buffer size can is returned at `size`, and can be smaller than what's requested.

When this I/O method is not supported, the ioctl returns an `EOPNOTSUPP` error code.

Applications can call [ioctl DMX_REQBUFS](<#rst-dmx-reqbufs>) again to change the number of buffers, however this cannot succeed when any buffers are still mapped. A `count` value of zero frees all buffers, after aborting or finishing any DMA in progress.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EOPNOTSUPP**

  The  the requested I/O method is not supported.

---

# DMX_SET_BUFFER_SIZE

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_set_buffer_size".

<a id="rst-dmx-set-buffer-size-1"></a>
<a id="rst-dmx-set-buffer-size"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_SET_BUFFER_SIZE

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

## Synopsis





<a id="c-DMX_SET_BUFFER_SIZE"></a>

```c
DMX_SET_BUFFER_SIZE
```

`int ioctl(int fd, DMX_SET_BUFFER_SIZE, unsigned long size)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`size`**

  Unsigned long size

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

## Description

This ioctl call is used to set the size of the circular buffer used for filtered data. The default size is two maximum sized sections, i.e. if this function is not called a buffer size of `2 * 4096` bytes will be used.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# DMX_SET_FILTER

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_set_filter".

<a id="rst-dmx-set-filter-1"></a>
<a id="rst-dmx-set-filter"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_SET_FILTER

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

## Synopsis





<a id="c-DMX_SET_FILTER"></a>

```c
DMX_SET_FILTER
```

`int ioctl(int fd, DMX_SET_FILTER, struct dmx_sct_filter_params *params)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

`params`

> Pointer to structure containing filter parameters.

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

## Description

This ioctl call sets up a filter according to the filter and mask parameters provided. A timeout may be defined stating number of seconds to wait for a section to be loaded. A value of 0 means that no timeout should be applied. Finally there is a flag field where it is possible to state whether a section should be CRC-checked, whether the filter should be a "one-shot" filter, i.e. if the filtering operation should be stopped after the first section is received, and whether the filtering operation should be started immediately (without waiting for a [DMX_START](</kernel/userspace/userspace-api/media-dvb/dmx-start.md#rst-dmx-start-1>) ioctl call). If a filter was previously set-up, this filter will be canceled, and the receive buffer will be flushed.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# DMX_SET_PES_FILTER

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_set_pes_filter".

<a id="rst-dmx-set-pes-filter-1"></a>
<a id="rst-dmx-set-pes-filter"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_SET_PES_FILTER

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

## Synopsis





<a id="c-DMX_SET_PES_FILTER"></a>

```c
DMX_SET_PES_FILTER
```

`int ioctl(int fd, DMX_SET_PES_FILTER, struct dmx_pes_filter_params *params)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`params`**

  Pointer to structure containing filter parameters.

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

## Description

This ioctl call sets up a PES filter according to the parameters provided. By a PES filter is meant a filter that is based just on the packet identifier (PID), i.e. no PES header or payload filtering capability is supported.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`EBUSY`

</td>
<td>


This error code indicates that there are conflicting requests. There are active filters filtering data from another input source. Make sure that these filters are stopped before starting this filter.

</td>
</tr>
</tbody>
</table>

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# DMX_START

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_start".

<a id="rst-dmx-start-1"></a>
<a id="rst-dmx-start"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_START

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

## Synopsis





<a id="c-DMX_START"></a>

```c
DMX_START
```

`int ioctl(int fd, DMX_START)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

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

## Description

This ioctl call is used to start the actual filtering operation defined via the ioctl calls [DMX_SET_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-filter.md#rst-dmx-set-filter-1>) or [DMX_SET_PES_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-pes-filter.md#rst-dmx-set-pes-filter-1>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`EINVAL`

</td>
<td>


Invalid argument, i.e. no filtering parameters provided via the [DMX_SET_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-filter.md#rst-dmx-set-filter-1>) or [DMX_SET_PES_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-pes-filter.md#rst-dmx-set-pes-filter-1>) ioctls.

</td>
</tr>
<tr>
<td>


`EBUSY`

</td>
<td>


This error code indicates that there are conflicting requests. There are active filters filtering data from another input source. Make sure that these filters are stopped before starting this filter.

</td>
</tr>
</tbody>
</table>

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# DMX_STOP

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "dmx_stop".

<a id="rst-dmx-stop-1"></a>
<a id="rst-dmx-stop"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->

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

## Name

DMX_STOP

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

## Synopsis





<a id="c-DMX_STOP"></a>

```c
DMX_STOP
```

`int ioctl(int fd, DMX_STOP)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

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

## Description

This ioctl call is used to stop the actual filtering operation defined via the ioctl calls [DMX_SET_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-filter.md#rst-dmx-set-filter-1>) or [DMX_SET_PES_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-pes-filter.md#rst-dmx-set-pes-filter-1>) and started via the [DMX_START](</kernel/userspace/userspace-api/media-dvb/dmx-start.md#rst-dmx-start-1>) command.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Demux Function Calls

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for Demux Function Calls.

<a id="rst-demux-function-calls"></a>
<a id="rst-dmx-fcalls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

- [Digital TV demux open()](</kernel/userspace/userspace-api/media-dvb/dmx-fopen.md>)
- [Digital TV demux close()](</kernel/userspace/userspace-api/media-dvb/dmx-fclose.md>)
- [Digital TV demux read()](</kernel/userspace/userspace-api/media-dvb/dmx-fread.md>)
- [Digital TV demux write()](</kernel/userspace/userspace-api/media-dvb/dmx-fwrite.md>)
- [Digital TV mmap()](</kernel/userspace/userspace-api/media-dvb/dmx-mmap.md>)
- [DVB munmap()](</kernel/userspace/userspace-api/media-dvb/dmx-munmap.md>)
- [DMX_START](</kernel/userspace/userspace-api/media-dvb/dmx-start.md>)
- [DMX_STOP](</kernel/userspace/userspace-api/media-dvb/dmx-stop.md>)
- [DMX_SET_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-filter.md>)
- [DMX_SET_PES_FILTER](</kernel/userspace/userspace-api/media-dvb/dmx-set-pes-filter.md>)
- [DMX_SET_BUFFER_SIZE](</kernel/userspace/userspace-api/media-dvb/dmx-set-buffer-size.md>)
- [DMX_GET_STC](</kernel/userspace/userspace-api/media-dvb/dmx-get-stc.md>)
- [DMX_GET_PES_PIDS](</kernel/userspace/userspace-api/media-dvb/dmx-get-pes-pids.md>)
- [DMX_ADD_PID](</kernel/userspace/userspace-api/media-dvb/dmx-add-pid.md>)
- [DMX_REMOVE_PID](</kernel/userspace/userspace-api/media-dvb/dmx-remove-pid.md>)
- [ioctl DMX_REQBUFS](</kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md>)
- [ioctl DMX_QUERYBUF](</kernel/userspace/userspace-api/media-dvb/dmx-querybuf.md>)
- [ioctl DMX_EXPBUF](</kernel/userspace/userspace-api/media-dvb/dmx-expbuf.md>)
- [ioctl DMX_QBUF, DMX_DQBUF](</kernel/userspace/userspace-api/media-dvb/dmx-qbuf.md>)

---

# Demux Data Types

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for Demux Data Types.

<a id="rst-demux-data-types"></a>
<a id="rst-dmx-types"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.dmx -->


#### <a id="c-enum-dmx_output"></a>`enum dmx_output`

Output for the demux.

**Constants**

- `DMX_OUT_DECODER`: Streaming directly to decoder.
- `DMX_OUT_TAP`: Output going to a memory buffer (to be retrieved via the read command).
  Delivers the stream output to the demux device on which the ioctl
  is called.
- `DMX_OUT_TS_TAP`: Output multiplexed into a new TS (to be retrieved by reading from the
  logical DVR device). Routes output to the logical DVR device
  `/dev/dvb/adapter?/dvr?`, which delivers a TS multiplexed from all
  filters for which **DMX_OUT_TS_TAP** was specified.
- `DMX_OUT_TSDEMUX_TAP`: Like **DMX_OUT_TS_TAP** but retrieved from the DMX device.

#### <a id="c-enum-dmx_input"></a>`enum dmx_input`

Input from the demux.

**Constants**

- `DMX_IN_FRONTEND`: Input from a front-end device.
- `DMX_IN_DVR`: Input from the logical DVR device.

#### <a id="c-enum-dmx_ts_pes"></a>`enum dmx_ts_pes`

type of the PES filter.

**Constants**

- `DMX_PES_AUDIO0`: first audio PID. Also referred as **DMX_PES_AUDIO**.
- `DMX_PES_VIDEO0`: first video PID. Also referred as **DMX_PES_VIDEO**.
- `DMX_PES_TELETEXT0`: first teletext PID. Also referred as **DMX_PES_TELETEXT**.
- `DMX_PES_SUBTITLE0`: first subtitle PID. Also referred as **DMX_PES_SUBTITLE**.
- `DMX_PES_PCR0`: first Program Clock Reference PID.
  Also referred as **DMX_PES_PCR**.
- `DMX_PES_AUDIO1`: second audio PID.
- `DMX_PES_VIDEO1`: second video PID.
- `DMX_PES_TELETEXT1`: second teletext PID.
- `DMX_PES_SUBTITLE1`: second subtitle PID.
- `DMX_PES_PCR1`: second Program Clock Reference PID.
- `DMX_PES_AUDIO2`: third audio PID.
- `DMX_PES_VIDEO2`: third video PID.
- `DMX_PES_TELETEXT2`: third teletext PID.
- `DMX_PES_SUBTITLE2`: third subtitle PID.
- `DMX_PES_PCR2`: third Program Clock Reference PID.
- `DMX_PES_AUDIO3`: fourth audio PID.
- `DMX_PES_VIDEO3`: fourth video PID.
- `DMX_PES_TELETEXT3`: fourth teletext PID.
- `DMX_PES_SUBTITLE3`: fourth subtitle PID.
- `DMX_PES_PCR3`: fourth Program Clock Reference PID.
- `DMX_PES_OTHER`: any other PID.

#### <a id="c-struct-dmx_filter"></a>`struct dmx_filter`

Specifies a section header filter.

**Definition**

```c
struct dmx_filter {
    __u8 filter[DMX_FILTER_SIZE];
    __u8 mask[DMX_FILTER_SIZE];
    __u8 mode[DMX_FILTER_SIZE];
};
```

**Members**

- `filter`: bit array with bits to be matched at the section header.
- `mask`: bits that are valid at the filter bit array.
- `mode`: mode of match: if bit is zero, it will match if equal (positive
  match); if bit is one, it will match if the bit is negated.

**Note**

All arrays in this struct have a size of DMX_FILTER_SIZE (16 bytes).

#### <a id="c-struct-dmx_sct_filter_params"></a>`struct dmx_sct_filter_params`

Specifies a section filter.

**Definition**

```c
struct dmx_sct_filter_params {
        __u16 pid;
        struct dmx_filter filter;
        __u32 timeout;
        __u32 flags;
    #define DMX_CHECK_CRC       1;
    #define DMX_ONESHOT         2;
    #define DMX_IMMEDIATE_START 4;
};
```

**Members**

- `pid`: PID to be filtered.
- `filter`: section header filter, as defined by [`struct dmx_filter`](#c-struct-dmx_filter).
- `timeout`: maximum time to filter, in milliseconds.
- `flags`: extra flags for the section filter.

**Description**

Carries the configuration for a MPEG-TS section filter.

The **flags** can be:

- `DMX_CHECK_CRC` - only deliver sections where the CRC check succeeded;
- `DMX_ONESHOT` - disable the section filter after one section
  has been delivered;
- `DMX_IMMEDIATE_START` - Start filter immediately without requiring a
  DMX_START.

#### <a id="c-struct-dmx_pes_filter_params"></a>`struct dmx_pes_filter_params`

Specifies Packetized Elementary Stream (PES) filter parameters.

**Definition**

```c
struct dmx_pes_filter_params {
    __u16 pid;
    enum dmx_input  input;
    enum dmx_output output;
    enum dmx_ts_pes pes_type;
    __u32 flags;
};
```

**Members**

- `pid`: PID to be filtered.
- `input`: Demux input, as specified by [`enum dmx_input`](#c-enum-dmx_input).
- `output`: Demux output, as specified by [`enum dmx_output`](#c-enum-dmx_output).
- `pes_type`: Type of the pes filter, as specified by `enum dmx_pes_type`.
- `flags`: Demux PES flags.

#### <a id="c-struct-dmx_stc"></a>`struct dmx_stc`

Stores System Time Counter (STC) information.

**Definition**

```c
struct dmx_stc {
    unsigned int num;
    unsigned int base;
    __u64 stc;
};
```

**Members**

- `num`: input data: number of the STC, from 0 to N.
- `base`: output: divisor for STC to get 90 kHz clock.
- `stc`: output: stc in **base** * 90 kHz units.

#### <a id="c-enum-dmx_buffer_flags"></a>`enum dmx_buffer_flags`

DMX memory-mapped buffer flags

**Constants**

- `DMX_BUFFER_FLAG_HAD_CRC32_DISCARD`: Indicates that the Kernel discarded one or more frames due to wrong
  CRC32 checksum.
- `DMX_BUFFER_FLAG_TEI`: Indicates that the Kernel has detected a Transport Error indicator
  (TEI) on a filtered pid.
- `DMX_BUFFER_PKT_COUNTER_MISMATCH`: Indicates that the Kernel has detected a packet counter mismatch
  on a filtered pid.
- `DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED`: Indicates that the Kernel has detected one or more frame discontinuity.
- `DMX_BUFFER_FLAG_DISCONTINUITY_INDICATOR`: Received at least one packet with a frame discontinuity indicator.

#### <a id="c-struct-dmx_buffer"></a>`struct dmx_buffer`

dmx buffer info

**Definition**

```c
struct dmx_buffer {
    __u32 index;
    __u32 bytesused;
    __u32 offset;
    __u32 length;
    __u32 flags;
    __u32 count;
};
```

**Members**

- `index`: id number of the buffer
- `bytesused`: number of bytes occupied by data in the buffer (payload);
- `offset`: for buffers with memory == DMX_MEMORY_MMAP;
  offset from the start of the device memory for this plane,
  (or a "cookie" that should be passed to `mmap()` as offset)
- `length`: size in bytes of the buffer
- `flags`: bit array of buffer flags as defined by [`enum dmx_buffer_flags`](#c-enum-dmx_buffer_flags).
  Filled only at `DMX_DQBUF`.
- `count`: monotonic counter for filled buffers. Helps to identify
  data stream loses. Filled only at `DMX_DQBUF`.

**Description**

Contains data exchanged by application and driver using one of the streaming
I/O methods.

Please notice that, for `DMX_QBUF`, only **index** should be filled.
On `DMX_DQBUF` calls, all fields will be filled by the Kernel.

#### <a id="c-struct-dmx_requestbuffers"></a>`struct dmx_requestbuffers`

request dmx buffer information

**Definition**

```c
struct dmx_requestbuffers {
    __u32 count;
    __u32 size;
};
```

**Members**

- `count`: number of requested buffers,
- `size`: size in bytes of the requested buffer

**Description**

Contains data used for requesting a dmx buffer.
All reserved fields must be set to zero.

#### <a id="c-struct-dmx_exportbuffer"></a>`struct dmx_exportbuffer`

export of dmx buffer as DMABUF file descriptor

**Definition**

```c
struct dmx_exportbuffer {
    __u32 index;
    __u32 flags;
    __s32 fd;
};
```

**Members**

- `index`: id number of the buffer
- `flags`: flags for newly created file, currently only O_CLOEXEC is
  supported, refer to manual of open syscall for more details
- `fd`: file descriptor associated with DMABUF (set by driver)

**Description**

Contains data used for exporting a dmx buffer as DMABUF file descriptor.
The buffer is identified by a 'cookie' returned by DMX_QUERYBUF
(identical to the cookie used to `mmap()` the buffer to userspace). All
reserved fields must be set to zero. The field reserved0 is expected to
become a structure 'type' allowing an alternative layout of the structure
content. Therefore this field should not be used for any other extensions.

---

# Querying frontend status and statistics

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Once FE_SET_PROPERTY <FE_GET_PROPERTY> is called, the frontend will run a kernel thread that will periodically check for the tuner lock status and provide statistics about the quality of the signal.

<a id="rst-querying-frontend-status-and-statistics"></a>
<a id="rst-dvb-fe-read-status"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

Once [FE_SET_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>) is called, the frontend will run a kernel thread that will periodically check for the tuner lock status and provide statistics about the quality of the signal.

The information about the frontend tuner locking status can be queried using [ioctl FE_READ_STATUS](</kernel/userspace/userspace-api/media-dvb/fe-read-status.md#rst-fe-read-status>).

Signal statistics are provided via [ioctl FE_SET_PROPERTY, FE_GET_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>).

> [!NOTE]
>
> Most statistics require the demodulator to be fully locked (e. g. with `FE_HAS_LOCK <fe_status>` bit set). See [Frontend statistics indicators](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) for more details.

---

# frontend events

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for frontend events.

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->





<a id="c-dvb_frontend_event"></a>

```c
dvb_frontend_event
```

<a id="rst-frontend-events"></a>

## frontend events



```c
struct dvb_frontend_event {
    fe_status_t status;
    struct dvb_frontend_parameters parameters;
};
```

---

# frontend parameters

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The kind of parameters passed to the frontend device for tuning depend on the kind of hardware you are using.

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->





<a id="c-dvb_frontend_parameters"></a>

```c
dvb_frontend_parameters
```

<a id="rst-frontend-parameters"></a>

## frontend parameters

The kind of parameters passed to the frontend device for tuning depend on the kind of hardware you are using.

The struct `dvb_frontend_parameters` uses a union with specific per-system parameters. However, as newer delivery systems required more data, the structure size weren't enough to fit, and just extending its size would break the existing applications. So, those parameters were replaced by the usage of [FE_GET_PROPERTY/FE_SET_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>) ioctl's. The new API is flexible enough to add new parameters to existing delivery systems, and to add newer delivery systems.

So, newer applications should use [FE_GET_PROPERTY/FE_SET_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>) instead, in order to be able to support the newer System Delivery like DVB-S2, DVB-T2, DVB-C2, ISDB, etc.

All kinds of parameters are combined as a union in the `dvb_frontend_parameters` structure:



```c
struct dvb_frontend_parameters {
    uint32_t frequency;     /* (absolute) frequency in Hz for QAM/OFDM */
                /* intermediate frequency in kHz for QPSK */
    fe_spectral_inversion_t inversion;
    union {
        struct dvb_qpsk_parameters qpsk;
        struct dvb_qam_parameters  qam;
        struct dvb_ofdm_parameters ofdm;
        struct dvb_vsb_parameters  vsb;
    } u;
};
```

In the case of QPSK frontends the `frequency` field specifies the intermediate frequency, i.e. the offset which is effectively added to the local oscillator frequency (LOF) of the LNB. The intermediate frequency has to be specified in units of kHz. For QAM and OFDM frontends the `frequency` specifies the absolute frequency and is given in Hz.





<a id="c-dvb_qpsk_parameters"></a>

```c
dvb_qpsk_parameters
```

<a id="rst-qpsk-parameters"></a>

### QPSK parameters

For satellite QPSK frontends you have to use the `dvb_qpsk_parameters` structure:



```c
struct dvb_qpsk_parameters {
    uint32_t        symbol_rate;  /* symbol rate in Symbols per second */
    fe_code_rate_t  fec_inner;    /* forward error correction (see above) */
};
```





<a id="c-dvb_qam_parameters"></a>

```c
dvb_qam_parameters
```

<a id="rst-qam-parameters"></a>

### QAM parameters

for cable QAM frontend you use the `dvb_qam_parameters` structure:



```c
struct dvb_qam_parameters {
    uint32_t         symbol_rate; /* symbol rate in Symbols per second */
    fe_code_rate_t   fec_inner;   /* forward error correction (see above) */
    fe_modulation_t  modulation;  /* modulation type (see above) */
};
```





<a id="c-dvb_vsb_parameters"></a>

```c
dvb_vsb_parameters
```

<a id="rst-vsb-parameters"></a>

### VSB parameters

ATSC frontends are supported by the `dvb_vsb_parameters` structure:



```c
struct dvb_vsb_parameters {
    fe_modulation_t modulation; /* modulation type (see above) */
};
```





<a id="c-dvb_ofdm_parameters"></a>

```c
dvb_ofdm_parameters
```

<a id="rst-ofdm-parameters"></a>

### OFDM parameters

DVB-T frontends are supported by the `dvb_ofdm_parameters` structure:



```c
struct dvb_ofdm_parameters {
    fe_bandwidth_t      bandwidth;
    fe_code_rate_t      code_rate_HP;  /* high priority stream code rate */
    fe_code_rate_t      code_rate_LP;  /* low priority stream code rate */
    fe_modulation_t     constellation; /* modulation type (see above) */
    fe_transmit_mode_t  transmission_mode;
    fe_guard_interval_t guard_interval;
    fe_hierarchy_t      hierarchy_information;
};
```

---

# Part II - Digital TV API

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Version 5.10

<a id="rst-part-ii-digital-tv-api"></a>
<a id="rst-dvbapi"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

> [!NOTE]
>
> This API is also known as Linux **DVB API**.
>
> It it was originally written to support the European digital TV standard (DVB), and later extended to support all digital TV standards.
>
> In order to avoid confusion, within this document, it was opted to refer to it, and to associated hardware as **Digital TV**.
>
> The word **DVB** is reserved to be used for:
>
> > - the Digital TV API version (e. g. DVB API version 3 or DVB API version 5);
> >
> > - digital TV data types (enums, structs, defines, etc);
> >
> > - digital TV device nodes (`/dev/dvb/...`);
> >
> > - the European DVB standard.

**Version 5.10**

**Table of Contents**

1. [Introduction](</kernel/userspace/userspace-api/media-dvb/intro.md>)
2. [Digital TV Frontend API](</kernel/userspace/userspace-api/media-dvb/frontend.md>)
3. [Digital TV Demux Device](</kernel/userspace/userspace-api/media-dvb/demux.md>)
4. [Digital TV CA Device](</kernel/userspace/userspace-api/media-dvb/ca.md>)
5. [Digital TV Network API](</kernel/userspace/userspace-api/media-dvb/net.md>)
6. [Digital TV Deprecated APIs](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-apis.md>)
7. [Examples](</kernel/userspace/userspace-api/media-dvb/examples.md>)
8. [headers](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/dvb/headers.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

<a id="rst-revision-and-copyright"></a>

## Revision and Copyright

Authors:

- - **J.** - **K.** Metzler, Ralph &lt;[rjkm@metzlerbros.de](<mailto:rjkm@metzlerbros.de>)&gt;

> - Original author of the Digital TV API documentation.

- - **O.** - **C.** Metzler, Marcus &lt;[rjkm@metzlerbros.de](<mailto:rjkm@metzlerbros.de>)&gt;

> - Original author of the Digital TV API documentation.

- Carvalho Chehab, Mauro &lt;[mchehab+samsung@kernel.org](<mailto:mchehab+samsung@kernel.org>)&gt;

> - Ported document to Docbook XML, addition of DVBv5 API, documentation gaps fix.

**Copyright** © 2002-2003 : Convergence GmbH

**Copyright** © 2009-2017 : Mauro Carvalho Chehab

<a id="rst-revision-history"></a>

## Revision History

**revision:** 2.2.0 / 2017-09-01 (*mcc*)

Most gaps between the uAPI document and the Kernel implementation got fixed for the non-legacy API.

**revision:** 2.1.0 / 2015-05-29 (*mcc*)

DocBook improvements and cleanups, in order to document the system calls on a more standard way and provide more description about the current Digital TV API.

**revision:** 2.0.4 / 2011-05-06 (*mcc*)

Add more information about DVBv5 API, better describing the frontend GET/SET props ioctl's.

**revision:** 2.0.3 / 2010-07-03 (*mcc*)

Add some frontend capabilities flags, present on kernel, but missing at the specs.

**revision:** 2.0.2 / 2009-10-25 (*mcc*)

documents FE_SET_FRONTEND_TUNE_MODE and FE_DISHETWORK_SEND_LEGACY_CMD ioctls.

**revision:** 2.0.1 / 2009-09-16 (*mcc*)

Added ISDB-T test originally written by Patrick Boettcher

**revision:** 2.0.0 / 2009-09-06 (*mcc*)

Conversion from LaTex to DocBook XML. The contents is the same as the original LaTex version.

**revision:** 1.0.0 / 2003-07-24 (*rjkm*)

Initial revision on LaTEX.

---

# Property types

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Tuning into a Digital TV physical channel and starting decoding it requires changing a set of parameters, in order to control the tuner, the demodulator, the Linear Low-noise Amplifier (LNA) and to set the antenna subsystem via Satellite…

<a id="rst-property-types"></a>
<a id="rst-frontend-properties"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

Tuning into a Digital TV physical channel and starting decoding it requires changing a set of parameters, in order to control the tuner, the demodulator, the Linear Low-noise Amplifier (LNA) and to set the antenna subsystem via Satellite Equipment Control - SEC (on satellite systems). The actual parameters are specific to each particular digital TV standards, and may change as the digital TV specs evolves.

In the past (up to DVB API version 3 - DVBv3), the strategy used was to have a union with the parameters needed to tune for DVB-S, DVB-C, DVB-T and ATSC delivery systems grouped there. The problem is that, as the second generation standards appeared, the size of such union was not big enough to group the structs that would be required for those new standards. Also, extending it would break userspace.

So, the legacy union/struct based approach was deprecated, in favor of a properties set approach. On such approach, [FE\_GET\_PROPERTY and FE\_SET\_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>) are used to setup the frontend and read its status.

The actual action is determined by a set of dtv\_property cmd/data pairs. With one single ioctl, is possible to get/set up to 64 properties.

This section describes the new and recommended way to set the frontend, with supports all digital TV delivery systems.

> [!NOTE]
>
> 1. On Linux DVB API version 3, setting a frontend was done via struct `dvb_frontend_parameters`.
>
> 2. Don't use DVB API version 3 calls on hardware with supports newer standards. Such API provides no support or a very limited support to new standards and/or new hardware.
>
> 3. Nowadays, most frontends support multiple delivery systems. Only with DVB API version 5 calls it is possible to switch between the multiple delivery systems supported by a frontend.
>
> 4. DVB API version 5 is also called <em>S2API</em>, as the first new standard added to it was DVB-S2.

<strong>Example</strong>: in order to set the hardware to tune into a DVB-C channel at 651 kHz, modulated with 256-QAM, FEC 3/4 and symbol rate of 5.217 Mbauds, those properties should be sent to [FE\_SET\_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>) ioctl:

> [DTV\_DELIVERY\_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>) = SYS\_DVBC\_ANNEX\_A
>
> [DTV\_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>) = 651000000
>
> [DTV\_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>) = QAM\_256
>
> [DTV\_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>) = INVERSION\_AUTO
>
> [DTV\_SYMBOL\_RATE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-symbol-rate>) = 5217000
>
> [DTV\_INNER\_FEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inner-fec>) = FEC\_3\_4
>
> [DTV\_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

The code that would that would do the above is show in [dtv-prop-example](<#rst-dtv-prop-example>).

Example: Setting digital TV frontend properties

<a id="rst-dtv-prop-example"></a>



```c
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/dvb/frontend.h>

static struct dtv_property props[] = {
    { .cmd = DTV_DELIVERY_SYSTEM, .u.data = SYS_DVBC_ANNEX_A },
    { .cmd = DTV_FREQUENCY,       .u.data = 651000000 },
    { .cmd = DTV_MODULATION,      .u.data = QAM_256 },
    { .cmd = DTV_INVERSION,       .u.data = INVERSION_AUTO },
    { .cmd = DTV_SYMBOL_RATE,     .u.data = 5217000 },
    { .cmd = DTV_INNER_FEC,       .u.data = FEC_3_4 },
    { .cmd = DTV_TUNE }
};

static struct dtv_properties dtv_prop = {
    .num = 6, .props = props
};

int main(void)
{
    int fd = open("/dev/dvb/adapter0/frontend0", O_RDWR);

    if (!fd) {
        perror ("open");
        return -1;
    }
    if (ioctl(fd, FE_SET_PROPERTY, &dtv_prop) == -1) {
        perror("ioctl");
        return -1;
    }
    printf("Frontend set\\n");
    return 0;
}
```

> [!NOTE]
>
> While it is possible to directly call the Kernel code like the above example, it is strongly recommended to use [libdvbv5](<https://linuxtv.org/docs/libdvbv5/index.html>), as it provides abstraction to work with the supported digital TV standards and provides methods for usual operations like program scanning and to read/write channel descriptor files.

- [Digital TV property parameters](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md>)
- [Frontend statistics indicators](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md>)
- [Properties used on terrestrial delivery systems](</kernel/userspace/userspace-api/media-dvb/frontend-property-terrestrial-systems.md>)
- [Properties used on cable delivery systems](</kernel/userspace/userspace-api/media-dvb/frontend-property-cable-systems.md>)
- [Properties used on satellite delivery systems](</kernel/userspace/userspace-api/media-dvb/frontend-property-satellite-systems.md>)
- [Frontend uAPI data types](</kernel/userspace/userspace-api/media-dvb/frontend-header.md>)

---

# Examples

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> In the past, we used to have a set of examples here. However, those examples got out of date and doesn't even compile nowadays.

<a id="rst-examples"></a>
<a id="rst-dvb-examples"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

In the past, we used to have a set of examples here. However, those examples got out of date and doesn't even compile nowadays.

Also, nowadays, the best is to use the libdvbv5 DVB API nowadays, with is fully documented.

Please refer to the [libdvbv5](<https://linuxtv.org/docs/libdvbv5/index.html>) for updated/recommended examples.

---

# Frontend bandwidth

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for Frontend bandwidth.

<a id="rst-frontend-bandwidth"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->





<a id="c-fe_bandwidth"></a>

```c
fe_bandwidth
```


<table>
<caption>enum fe_bandwidth</caption>
<thead>
<tr>
<th>


ID

</th>
<th>


Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


<a id="rst-bandwidth-auto"></a>

`BANDWIDTH_AUTO`

</td>
<td>


Autodetect bandwidth (if supported)

</td>
</tr>
<tr>
<td>


<a id="rst-bandwidth-1-712-mhz"></a>

`BANDWIDTH_1_712_MHZ`

</td>
<td>


1.712 MHz

</td>
</tr>
<tr>
<td>


<a id="rst-bandwidth-5-mhz"></a>

`BANDWIDTH_5_MHZ`

</td>
<td>


5 MHz

</td>
</tr>
<tr>
<td>


<a id="rst-bandwidth-6-mhz"></a>

`BANDWIDTH_6_MHZ`

</td>
<td>


6 MHz

</td>
</tr>
<tr>
<td>


<a id="rst-bandwidth-7-mhz"></a>

`BANDWIDTH_7_MHZ`

</td>
<td>


7 MHz

</td>
</tr>
<tr>
<td>


<a id="rst-bandwidth-8-mhz"></a>

`BANDWIDTH_8_MHZ`

</td>
<td>


8 MHz

</td>
</tr>
<tr>
<td>


<a id="rst-bandwidth-10-mhz"></a>

`BANDWIDTH_10_MHZ`

</td>
<td>


10 MHz

</td>
</tr>
</tbody>
</table>

---

# ioctl FE_DISEQC_RECV_SLAVE_REPLY

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_DISEQC_RECV_SLAVE_REPLY - Receives reply from a DiSEqC 2.0 command

<a id="rst-ioctl-fe-diseqc-recv-slave-reply"></a>
<a id="rst-fe-diseqc-recv-slave-reply"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_DISEQC_RECV_SLAVE_REPLY - Receives reply from a DiSEqC 2.0 command

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

## Synopsis





<a id="c-FE_DISEQC_RECV_SLAVE_REPLY"></a>

```c
FE_DISEQC_RECV_SLAVE_REPLY
```

`int ioctl(int fd, FE_DISEQC_RECV_SLAVE_REPLY, struct dvb_diseqc_slave_reply *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  pointer to struct `dvb_diseqc_slave_reply`.

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

## Description

Receives reply from a DiSEqC 2.0 command.

The received message is stored at the buffer pointed by `argp`.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_DISEQC_RESET_OVERLOAD

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_DISEQC_RESET_OVERLOAD - Restores the power to the antenna subsystem, if it was powered off due - to power overload.

<a id="rst-ioctl-fe-diseqc-reset-overload"></a>
<a id="rst-fe-diseqc-reset-overload"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_DISEQC_RESET_OVERLOAD - Restores the power to the antenna subsystem, if it was powered off due - to power overload.

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

## Synopsis





<a id="c-FE_DISEQC_RESET_OVERLOAD"></a>

```c
FE_DISEQC_RESET_OVERLOAD
```

`int ioctl(int fd, FE_DISEQC_RESET_OVERLOAD, NULL)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

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

## Description

If the bus has been automatically powered off due to power overload, this ioctl call restores the power to the bus. The call requires read/write access to the device. This call has no effect if the device is manually powered off. Not all Digital TV adapters support this ioctl.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_DISEQC_SEND_BURST

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_DISEQC_SEND_BURST - Sends a 22KHz tone burst for 2x1 mini DiSEqC satellite selection.

<a id="rst-ioctl-fe-diseqc-send-burst"></a>
<a id="rst-fe-diseqc-send-burst"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_DISEQC_SEND_BURST - Sends a 22KHz tone burst for 2x1 mini DiSEqC satellite selection.

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

## Synopsis





<a id="c-FE_DISEQC_SEND_BURST"></a>

```c
FE_DISEQC_SEND_BURST
```

`int ioctl(int fd, FE_DISEQC_SEND_BURST, enum fe_sec_mini_cmd tone)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`tone`**

  An integer enumerated value described at `fe_sec_mini_cmd`.

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

## Description

This ioctl is used to set the generation of a 22kHz tone burst for mini DiSEqC satellite selection for 2x1 switches. This call requires read/write permissions.

It provides support for what's specified at [Digital Satellite Equipment Control (DiSEqC) - Simple "ToneBurst" Detection Circuit specification.](<http://www.eutelsat.com/files/contributed/satellites/pdf/Diseqc/associated%20docs/simple_tone_burst_detec.pdf>)

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_DISEQC_SEND_MASTER_CMD

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_DISEQC_SEND_MASTER_CMD - Sends a DiSEqC command

<a id="rst-ioctl-fe-diseqc-send-master-cmd"></a>
<a id="rst-fe-diseqc-send-master-cmd"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_DISEQC_SEND_MASTER_CMD - Sends a DiSEqC command

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

## Synopsis





<a id="c-FE_DISEQC_SEND_MASTER_CMD"></a>

```c
FE_DISEQC_SEND_MASTER_CMD
```

`int ioctl(int fd, FE_DISEQC_SEND_MASTER_CMD, struct dvb_diseqc_master_cmd *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  pointer to struct `dvb_diseqc_master_cmd`

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

## Description

Sends the DiSEqC command pointed by `dvb_diseqc_master_cmd` to the antenna subsystem.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# FE_DISHNETWORK_SEND_LEGACY_CMD

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "fe_dishnetwork_send_legacy_cmd".

<a id="rst-fe-dishnetwork-send-legacy-cmd-1"></a>
<a id="rst-fe-dishnetwork-send-legacy-cmd"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_DISHNETWORK_SEND_LEGACY_CMD

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

## Synopsis





<a id="c-FE_DISHNETWORK_SEND_LEGACY_CMD"></a>

```c
FE_DISHNETWORK_SEND_LEGACY_CMD
```

`int ioctl(int fd, FE_DISHNETWORK_SEND_LEGACY_CMD, unsigned long cmd)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`cmd`**

  Sends the specified raw cmd to the dish via DISEqC.

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

## Description

> [!WARNING]
>
> This is a very obscure legacy command, used only at stv0299 driver. Should not be used on newer drivers.

It provides a non-standard method for selecting Diseqc voltage on the frontend, for Dish Network legacy switches.

As support for this ioctl were added in 2004, this means that such dishes were already legacy in 2004.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_ENABLE_HIGH_LNB_VOLTAGE

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_ENABLE_HIGH_LNB_VOLTAGE - Select output DC level between normal LNBf voltages or higher LNBf - voltages.

<a id="rst-ioctl-fe-enable-high-lnb-voltage"></a>
<a id="rst-fe-enable-high-lnb-voltage"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_ENABLE_HIGH_LNB_VOLTAGE - Select output DC level between normal LNBf voltages or higher LNBf - voltages.

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

## Synopsis





<a id="c-FE_ENABLE_HIGH_LNB_VOLTAGE"></a>

```c
FE_ENABLE_HIGH_LNB_VOLTAGE
```

`int ioctl(int fd, FE_ENABLE_HIGH_LNB_VOLTAGE, unsigned int high)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`high`**

  Valid flags:

  - 0 - normal 13V and 18V.

  - &gt;0 - enables slightly higher voltages instead of 13/18V, in order to compensate for long antenna cables.

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

## Description

Select output DC level between normal LNBf voltages or higher LNBf voltages between 0 (normal) or a value grater than 0 for higher voltages.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# FE_GET_EVENT

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "fe_get_event".

<a id="rst-fe-get-event-1"></a>
<a id="rst-fe-get-event"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_GET_EVENT

> [!NOTE]
>
> This ioctl is deprecated.

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

## Synopsis





<a id="c-FE_GET_EVENT"></a>

```c
FE_GET_EVENT
```

`int ioctl(int fd, FE_GET_EVENT, struct dvb_frontend_event *ev)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`ev`**

  Points to the location where the event, if any, is to be stored.

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

## Description

This ioctl call returns a frontend event if available. If an event is not available, the behavior depends on whether the device is in blocking or non-blocking mode. In the latter case, the call fails immediately with errno set to `EWOULDBLOCK`. In the former case, the call blocks until an event becomes available.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.


<table>
<tbody>
<tr>
<td>


`EWOULDBLOCK`

</td>
<td>


There is no event pending, and the device is in non-blocking mode.

</td>
</tr>
<tr>
<td>


`EOVERFLOW`

</td>
<td>


Overflow in event queue - one or more events were lost.

</td>
</tr>
</tbody>
</table>

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# FE_GET_FRONTEND

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "fe_get_frontend".

<a id="rst-fe-get-frontend-1"></a>
<a id="rst-fe-get-frontend"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_GET_FRONTEND

> [!NOTE]
>
> This ioctl is deprecated.

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

## Synopsis





<a id="c-FE_GET_FRONTEND"></a>

```c
FE_GET_FRONTEND
```

`int ioctl(int fd, FE_GET_FRONTEND, struct dvb_frontend_parameters *p)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`p`**

  Points to parameters for tuning operation.

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

## Description

This ioctl call queries the currently effective frontend parameters. For this command, read-only access to the device is sufficient.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.


<table>
<tbody>
<tr>
<td>


`EINVAL`

</td>
<td>


Maximum supported symbol rate reached.

</td>
</tr>
</tbody>
</table>

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_GET_INFO

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_GET_INFO - Query Digital TV frontend capabilities and returns information about the - front-end. This call only requires read-only access to the device.

<a id="rst-ioctl-fe-get-info"></a>
<a id="rst-fe-get-info"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_GET_INFO - Query Digital TV frontend capabilities and returns information about the - front-end. This call only requires read-only access to the device.

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

## Synopsis





<a id="c-FE_GET_INFO"></a>

```c
FE_GET_INFO
```

`int ioctl(int fd, FE_GET_INFO, struct dvb_frontend_info *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  pointer to struct `dvb_frontend_info`

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

## Description

All Digital TV frontend devices support the [ioctl FE_GET_INFO](<#rst-fe-get-info>) ioctl. It is used to identify kernel devices compatible with this specification and to obtain information about driver and hardware capabilities. The ioctl takes a pointer to dvb_frontend_info which is filled by the driver. When the driver is not compatible with this specification the ioctl returns an error.

<a id="rst-frontend-capabilities"></a>

## frontend capabilities

Capabilities describe what a frontend can do. Some capabilities are supported only on some specific frontend types.

The frontend capabilities are described at `fe_caps`.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_SET_PROPERTY, FE_GET_PROPERTY

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_SET_PROPERTY - FE_GET_PROPERTY - FE_SET_PROPERTY sets one or more frontend properties. - FE_GET_PROPERTY returns one or more frontend properties.

<a id="rst-ioctl-fe-set-property-fe-get-property"></a>
<a id="rst-fe-get-property"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_SET_PROPERTY - FE_GET_PROPERTY - FE_SET_PROPERTY sets one or more frontend properties. - FE_GET_PROPERTY returns one or more frontend properties.

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

## Synopsis





<a id="c-FE_GET_PROPERTY"></a>

```c
FE_GET_PROPERTY
```

`int ioctl(int fd, FE_GET_PROPERTY, struct dtv_properties *argp)`





<a id="c-FE_SET_PROPERTY"></a>

```c
FE_SET_PROPERTY
```

`int ioctl(int fd, FE_SET_PROPERTY, struct dtv_properties *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `dtv_properties`.

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

## Description

All Digital TV frontend devices support the `FE_SET_PROPERTY` and `FE_GET_PROPERTY` ioctls. The supported properties and statistics depends on the delivery system and on the device:

- `FE_SET_PROPERTY:`

  - This ioctl is used to set one or more frontend properties.

  - This is the basic command to request the frontend to tune into some frequency and to start decoding the digital TV signal.

  - This call requires read/write access to the device.

> [!NOTE]
>
> At return, the values aren't updated to reflect the actual parameters used. If the actual parameters are needed, an explicit call to `FE_GET_PROPERTY` is needed.

- `FE_GET_PROPERTY:`

  - This ioctl is used to get properties and statistics from the frontend.

  - No properties are changed, and statistics aren't reset.

  - This call only requires read-only access to the device.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# FE_READ_BER

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "fe_read_ber".

<a id="rst-fe-read-ber-1"></a>
<a id="rst-fe-read-ber"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_READ_BER

> [!NOTE]
>
> This ioctl is deprecated.

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

## Synopsis





<a id="c-FE_READ_BER"></a>

```c
FE_READ_BER
```

`int ioctl(int fd, FE_READ_BER, uint32_t *ber)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`ber`**

  The bit error rate is stored into \*ber.

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

## Description

This ioctl call returns the bit error rate for the signal currently received/demodulated by the front-end. For this command, read-only access to the device is sufficient.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# FE_READ_SIGNAL_STRENGTH

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "fe_read_signal_strength".

<a id="rst-fe-read-signal-strength-1"></a>
<a id="rst-fe-read-signal-strength"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_READ_SIGNAL_STRENGTH

> [!NOTE]
>
> This ioctl is deprecated.

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

## Synopsis





<a id="c-FE_READ_SIGNAL_STRENGTH"></a>

```c
FE_READ_SIGNAL_STRENGTH
```

`int ioctl(int fd, FE_READ_SIGNAL_STRENGTH, uint16_t *strength)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`strength`**

  The signal strength value is stored into \*strength.

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

## Description

This ioctl call returns the signal strength value for the signal currently received by the front-end. For this command, read-only access to the device is sufficient.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# FE_READ_SNR

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "fe_read_snr".

<a id="rst-fe-read-snr-1"></a>
<a id="rst-fe-read-snr"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_READ_SNR

> [!NOTE]
>
> This ioctl is deprecated.

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

## Synopsis





<a id="c-FE_READ_SNR"></a>

```c
FE_READ_SNR
```

`int ioctl(int fd, FE_READ_SNR, int16_t *snr)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`snr`**

  The signal-to-noise ratio is stored into \*snr.

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

## Description

This ioctl call returns the signal-to-noise ratio for the signal currently received by the front-end. For this command, read-only access to the device is sufficient.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_READ_STATUS

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_READ_STATUS - Returns status information about the front-end. This call only requires - read-only access to the device

<a id="rst-ioctl-fe-read-status"></a>
<a id="rst-fe-read-status"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_READ_STATUS - Returns status information about the front-end. This call only requires - read-only access to the device

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

## Synopsis





<a id="c-FE_READ_STATUS"></a>

```c
FE_READ_STATUS
```

`int ioctl(int fd, FE_READ_STATUS, unsigned int *status)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`status`**

  pointer to a bitmask integer filled with the values defined by enum `fe_status`.

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

## Description

All Digital TV frontend devices support the `FE_READ_STATUS` ioctl. It is used to check about the locking status of the frontend after being tuned. The ioctl takes a pointer to an integer where the status will be written.

> [!NOTE]
>
> The size of status is actually sizeof(enum fe_status), with varies according with the architecture. This needs to be fixed in the future.

<a id="rst-int-fe-status"></a>

## int fe_status

The fe_status parameter is used to indicate the current state and/or state changes of the frontend hardware. It is produced using the enum `fe_status` values on a bitmask

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# FE_READ_UNCORRECTED_BLOCKS

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "fe_read_uncorrected_blocks".

<a id="rst-fe-read-uncorrected-blocks-1"></a>
<a id="rst-fe-read-uncorrected-blocks"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_READ_UNCORRECTED_BLOCKS

> [!NOTE]
>
> This ioctl is deprecated.

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

## Synopsis





<a id="c-FE_READ_UNCORRECTED_BLOCKS"></a>

```c
FE_READ_UNCORRECTED_BLOCKS
```

`int ioctl(int fd, FE_READ_UNCORRECTED_BLOCKS, uint32_t *ublocks)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`ublocks`**

  The total number of uncorrected blocks seen by the driver so far.

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

## Description

This ioctl call returns the number of uncorrected blocks detected by the device driver during its lifetime. For meaningful measurements, the increment in block count during a specific time interval should be calculated. For this command, read-only access to the device is sufficient.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_SET_FRONTEND_TUNE_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_SET_FRONTEND_TUNE_MODE - Allow setting tuner mode flags to the frontend.

<a id="rst-ioctl-fe-set-frontend-tune-mode"></a>
<a id="rst-fe-set-frontend-tune-mode"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_SET_FRONTEND_TUNE_MODE - Allow setting tuner mode flags to the frontend.

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

## Synopsis





<a id="c-FE_SET_FRONTEND_TUNE_MODE"></a>

```c
FE_SET_FRONTEND_TUNE_MODE
```

`int ioctl(int fd, FE_SET_FRONTEND_TUNE_MODE, unsigned int flags)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`flags`**

  Valid flags:

  - 0 - normal tune mode

  - `FE_TUNE_MODE_ONESHOT` - When set, this flag will disable any zigzagging or other "normal" tuning behaviour. Additionally, there will be no automatic monitoring of the lock status, and hence no frontend events will be generated. If a frontend device is closed, this flag will be automatically turned off when the device is reopened read-write.

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

## Description

Allow setting tuner mode flags to the frontend, between 0 (normal) or `FE_TUNE_MODE_ONESHOT` mode

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# FE_SET_FRONTEND

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Duplicate implicit target name: "fe_set_frontend".

<a id="rst-fe-set-frontend-1"></a>
<a id="rst-fe-set-frontend"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

> [!NOTE]
>
> This ioctl is deprecated.

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

## Name

FE_SET_FRONTEND

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

## Synopsis





<a id="c-FE_SET_FRONTEND"></a>

```c
FE_SET_FRONTEND
```

`int ioctl(int fd, FE_SET_FRONTEND, struct dvb_frontend_parameters *p)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`p`**

  Points to parameters for tuning operation.

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

## Description

This ioctl call starts a tuning operation using specified parameters. The result of this call will be successful if the parameters were valid and the tuning could be initiated. The result of the tuning operation in itself, however, will arrive asynchronously as an event (see documentation for [FE_GET_EVENT](</kernel/userspace/userspace-api/media-dvb/fe-get-event.md#rst-fe-get-event-1>) and FrontendEvent.) If a new [FE_SET_FRONTEND](<#rst-fe-set-frontend-1>) operation is initiated before the previous one was completed, the previous operation will be aborted in favor of the new one. This command requires read/write access to the device.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`EINVAL`

</td>
<td>


Maximum supported symbol rate reached.

</td>
</tr>
</tbody>
</table>

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_SET_TONE

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_SET_TONE - Sets/resets the generation of the continuous 22kHz tone.

<a id="rst-ioctl-fe-set-tone"></a>
<a id="rst-fe-set-tone"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_SET_TONE - Sets/resets the generation of the continuous 22kHz tone.

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

## Synopsis





<a id="c-FE_SET_TONE"></a>

```c
FE_SET_TONE
```

`int ioctl(int fd, FE_SET_TONE, enum fe_sec_tone_mode tone)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`tone`**

  An integer enumerated value described at `fe_sec_tone_mode`

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

## Description

This ioctl is used to set the generation of the continuous 22kHz tone. This call requires read/write permissions.

Usually, satellite antenna subsystems require that the digital TV device to send a 22kHz tone in order to select between high/low band on some dual-band LNBf. It is also used to send signals to DiSEqC equipment, but this is done using the DiSEqC ioctls.

> [!NOTE]
>
> If more than one device is connected to the same antenna, setting a tone may interfere on other devices, as they may lose the capability of selecting the band. So, it is recommended that applications would change to SEC_TONE_OFF when the device is not used.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl FE_SET_VOLTAGE

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> FE_SET_VOLTAGE - Allow setting the DC level sent to the antenna subsystem.

<a id="rst-ioctl-fe-set-voltage"></a>
<a id="rst-fe-set-voltage"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

FE_SET_VOLTAGE - Allow setting the DC level sent to the antenna subsystem.

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

## Synopsis





<a id="c-FE_SET_VOLTAGE"></a>

```c
FE_SET_VOLTAGE
```

`int ioctl(int fd, FE_SET_VOLTAGE, enum fe_sec_voltage voltage)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`voltage`**

  An integer enumerated value described at `fe_sec_voltage`

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

## Description

This ioctl allows to set the DC voltage level sent through the antenna cable to 13V, 18V or off.

Usually, a satellite antenna subsystems require that the digital TV device to send a DC voltage to feed power to the LNBf. Depending on the LNBf type, the polarization or the intermediate frequency (IF) of the LNBf can controlled by the voltage level. Other devices (for example, the ones that implement DISEqC and multipoint LNBf's don't need to control the voltage level, provided that either 13V or 18V is sent to power up the LNBf.

> [!NOTE]
>
> if more than one device is connected to the same antenna, setting a voltage level may interfere on other devices, as they may lose the capability of setting polarization or IF. So, on those cases, setting the voltage to SEC_VOLTAGE_OFF while the device is not is used is recommended.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Frontend type

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> For historical reasons, frontend types are named by the type of modulation used in transmission. The fontend types are given by fe_type_t type, defined as:

<a id="rst-frontend-type"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

For historical reasons, frontend types are named by the type of modulation used in transmission. The fontend types are given by fe_type_t type, defined as:





<a id="c-fe_type"></a>

```c
fe_type
```

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->


<table>
<caption>Frontend types</caption>
<thead>
<tr>
<th>


fe_type

</th>
<th>


Description

</th>
<th>


[DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>) equivalent type

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


<a id="rst-fe-qpsk"></a>

`FE_QPSK`

</td>
<td>


For DVB-S standard

</td>
<td>


`SYS_DVBS`

</td>
</tr>
<tr>
<td>


<a id="rst-fe-qam"></a>

`FE_QAM`

</td>
<td>


For DVB-C annex A standard

</td>
<td>


`SYS_DVBC_ANNEX_A`

</td>
</tr>
<tr>
<td>


<a id="rst-fe-ofdm"></a>

`FE_OFDM`

</td>
<td>


For DVB-T standard

</td>
<td>


`SYS_DVBT`

</td>
</tr>
<tr>
<td>


<a id="rst-fe-atsc"></a>

`FE_ATSC`

</td>
<td>


For ATSC standard (terrestrial) or for DVB-C Annex B (cable) used in US.

</td>
<td>


`SYS_ATSC` (terrestrial) or `SYS_DVBC_ANNEX_B` (cable)

</td>
</tr>
</tbody>
</table>

Newer formats like DVB-S2, ISDB-T, ISDB-S and DVB-T2 are not described at the above, as they're supported via the new [FE_GET_PROPERTY/FE_GET_SET_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>) ioctl's, using the [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>) parameter.

In the old days, struct `dvb_frontend_info` used to contain `fe_type_t` field to indicate the delivery systems, filled with either `FE_QPSK, FE_QAM, FE_OFDM` or `FE_ATSC`. While this is still filled to keep backward compatibility, the usage of this field is deprecated, as it can report just one delivery system, but some devices support multiple delivery systems. Please use [DTV_ENUM_DELSYS](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-enum-delsys>) instead.

On devices that support multiple delivery systems, struct `dvb_frontend_info`::`fe_type_t` is filled with the currently standard, as selected by the last call to [FE_SET_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>) using the [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>) property.

---

# Digital TV property parameters

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> There are several different Digital TV parameters that can be used by FE_SET_PROPERTY and FE_GET_PROPERTY ioctls<FE_GET_PROPERTY>. This section describes each of them. Please notice, however, that only a subset of them are needed to setup…

<a id="rst-digital-tv-property-parameters"></a>
<a id="rst-fe-property-parameters"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

There are several different Digital TV parameters that can be used by [FE_SET_PROPERTY and FE_GET_PROPERTY ioctls](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property>). This section describes each of them. Please notice, however, that only a subset of them are needed to setup a frontend.

<a id="rst-dtv-undefined-1"></a>
<a id="rst-dtv-undefined"></a>

## DTV_UNDEFINED

Used internally. A GET/SET operation for it won't change or return anything.

<a id="rst-dtv-tune-1"></a>
<a id="rst-dtv-tune"></a>

## DTV_TUNE

Interpret the cache of data, build either a traditional frontend tunerequest so we can pass validation in the `FE_SET_FRONTEND` ioctl.

<a id="rst-dtv-clear-1"></a>
<a id="rst-dtv-clear"></a>

## DTV_CLEAR

Reset a cache of data specific to the frontend here. This does not effect hardware.

<a id="rst-dtv-frequency-1"></a>
<a id="rst-dtv-frequency"></a>

## DTV_FREQUENCY

Frequency of the digital TV transponder/channel.

> [!NOTE]
>
> 1. For satellite delivery systems, the frequency is in kHz.
>
> 2. For cable and terrestrial delivery systems, the frequency is in Hz.
>
> 3. On most delivery systems, the frequency is the center frequency of the transponder/channel. The exception is for ISDB-T, where the main carrier has a 1/7 offset from the center.
>
> 4. For ISDB-T, the channels are usually transmitted with an offset of about 143kHz. E.g. a valid frequency could be 474,143 kHz. The stepping is  bound to the bandwidth of the channel which is typically 6MHz.
>
> 5. In ISDB-Tsb, the channel consists of only one or three segments the frequency step is 429kHz, 3\*429 respectively.

<a id="rst-dtv-modulation-1"></a>
<a id="rst-dtv-modulation"></a>

## DTV_MODULATION

Specifies the frontend modulation type for delivery systems that support multiple modulations.

The modulation can be one of the types defined by enum `fe_modulation`.

Most of the digital TV standards offer more than one possible modulation type.

The table below presents a summary of the types of modulation types supported by each delivery system, as currently defined by specs.


<table>
<thead>
<tr>
<th>


Standard

</th>
<th>


Modulation types

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


ATSC (version 1)

</td>
<td>


8-VSB and 16-VSB.

</td>
</tr>
<tr>
<td>


DMTB

</td>
<td>


4-QAM, 16-QAM, 32-QAM, 64-QAM and 4-QAM-NR.

</td>
</tr>
<tr>
<td>


DVB-C Annex A/C

</td>
<td>


16-QAM, 32-QAM, 64-QAM and 256-QAM.

</td>
</tr>
<tr>
<td>


DVB-C Annex B

</td>
<td>


64-QAM.

</td>
</tr>
<tr>
<td>


DVB-C2

</td>
<td>


QPSK, 16-QAM, 64-QAM, 256-QAM, 1024-QAM and 4096-QAM.

</td>
</tr>
<tr>
<td>


DVB-T

</td>
<td>


QPSK, 16-QAM and 64-QAM.

</td>
</tr>
<tr>
<td>


DVB-T2

</td>
<td>


QPSK, 16-QAM, 64-QAM and 256-QAM.

</td>
</tr>
<tr>
<td>


DVB-S

</td>
<td>


No need to set. It supports only QPSK.

</td>
</tr>
<tr>
<td>


DVB-S2

</td>
<td>


QPSK, 8-PSK, 16-APSK and 32-APSK.

</td>
</tr>
<tr>
<td>


DVB-S2X

</td>
<td>


8-APSK-L, 16-APSK-L, 32-APSK-L, 64-APSK and 64-APSK-L.

</td>
</tr>
<tr>
<td>


ISDB-T

</td>
<td>


QPSK, DQPSK, 16-QAM and 64-QAM.

</td>
</tr>
<tr>
<td>


ISDB-S

</td>
<td>


8-PSK, QPSK and BPSK.

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> As DVB-S2X specifies extensions to the DVB-S2 standard, the same delivery system enum value is used (SYS_DVBS2).
>
> Please notice that some of the above modulation types may not be defined currently at the Kernel. The reason is simple: no driver needed such definition yet.

<a id="rst-dtv-bandwidth-hz-1"></a>
<a id="rst-dtv-bandwidth-hz"></a>

## DTV_BANDWIDTH_HZ

Bandwidth for the channel, in HZ.

Should be set only for terrestrial delivery systems.

Possible values: `1712000`, `5000000`, `6000000`, `7000000`, `8000000`, `10000000`.


<table>
<thead>
<tr>
<th>


Terrestrial Standard

</th>
<th>


Possible values for bandwidth

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


ATSC (version 1)

</td>
<td>


No need to set. It is always 6MHz.

</td>
</tr>
<tr>
<td>


DMTB

</td>
<td>


No need to set. It is always 8MHz.

</td>
</tr>
<tr>
<td>


DVB-T

</td>
<td>


6MHz, 7MHz and 8MHz.

</td>
</tr>
<tr>
<td>


DVB-T2

</td>
<td>


1.172 MHz, 5MHz, 6MHz, 7MHz, 8MHz and 10MHz

</td>
</tr>
<tr>
<td>


ISDB-T

</td>
<td>


5MHz, 6MHz, 7MHz and 8MHz, although most places use 6MHz.

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> 1. For ISDB-Tsb, the bandwidth can vary depending on the number of connected segments.
>
>    It can be easily derived from other parameters (DTV_ISDBT_SB_SEGMENT_IDX, DTV_ISDBT_SB_SEGMENT_COUNT).
>
> 2. On Satellite and Cable delivery systems, the bandwidth depends on the symbol rate. The kernel will silently ignore any [DTV_BANDWIDTH_HZ](<#rst-dtv-bandwidth-hz>) setting and overwrites it with bandwidth estimation.
>
>    Such bandwidth estimation takes into account the symbol rate set with [DTV_SYMBOL_RATE](<#rst-dtv-symbol-rate>), and the rolloff factor, with is fixed for DVB-C and DVB-S.
>
>    For DVB-S2, the rolloff should also be set via [DTV_ROLLOFF](<#rst-dtv-rolloff>).

<a id="rst-dtv-inversion-1"></a>
<a id="rst-dtv-inversion"></a>

## DTV_INVERSION

Specifies if the frontend should do spectral inversion or not.

The acceptable values are defined by `fe_spectral_inversion`.

<a id="rst-dtv-diseqc-master-1"></a>
<a id="rst-dtv-diseqc-master"></a>

## DTV_DISEQC_MASTER

Currently not implemented.

<a id="rst-dtv-symbol-rate-1"></a>
<a id="rst-dtv-symbol-rate"></a>

## DTV_SYMBOL_RATE

Used on cable and satellite delivery systems.

Digital TV symbol rate, in bauds (symbols/second).

<a id="rst-dtv-inner-fec-1"></a>
<a id="rst-dtv-inner-fec"></a>

## DTV_INNER_FEC

Used on cable and satellite delivery systems.

The acceptable values are defined by `fe_code_rate`.

<a id="rst-dtv-voltage-1"></a>
<a id="rst-dtv-voltage"></a>

## DTV_VOLTAGE

Used on satellite delivery systems.

The voltage is usually used with non-DiSEqC capable LNBs to switch the polarization (horizontal/vertical). When using DiSEqC equipment this voltage has to be switched consistently to the DiSEqC commands as described in the DiSEqC spec.

The acceptable values are defined by `fe_sec_voltage`.

<a id="rst-dtv-tone-1"></a>
<a id="rst-dtv-tone"></a>

## DTV_TONE

Currently not used.

<a id="rst-dtv-pilot-1"></a>
<a id="rst-dtv-pilot"></a>

## DTV_PILOT

Used on DVB-S2.

Sets DVB-S2 pilot.

The acceptable values are defined by `fe_pilot`.

<a id="rst-dtv-rolloff-1"></a>
<a id="rst-dtv-rolloff"></a>

## DTV_ROLLOFF

Used on DVB-S2.

Sets DVB-S2 rolloff.

The acceptable values are defined by `fe_rolloff`.

<a id="rst-dtv-diseqc-slave-reply-1"></a>
<a id="rst-dtv-diseqc-slave-reply"></a>

## DTV_DISEQC_SLAVE_REPLY

Currently not implemented.

<a id="rst-dtv-fe-capability-count-1"></a>
<a id="rst-dtv-fe-capability-count"></a>

## DTV_FE_CAPABILITY_COUNT

Currently not implemented.

<a id="rst-dtv-fe-capability-1"></a>
<a id="rst-dtv-fe-capability"></a>

## DTV_FE_CAPABILITY

Currently not implemented.

<a id="rst-dtv-delivery-system-1"></a>
<a id="rst-dtv-delivery-system"></a>

## DTV_DELIVERY_SYSTEM

Specifies the type of the delivery system.

The acceptable values are defined by `fe_delivery_system`.

<a id="rst-dtv-isdbt-partial-reception-1"></a>
<a id="rst-dtv-isdbt-partial-reception"></a>

## DTV_ISDBT_PARTIAL_RECEPTION

Used only on ISDB.

If `DTV_ISDBT_SOUND_BROADCASTING` is '0' this bit field represents whether the channel is in partial reception mode or not.

If '1' `DTV_ISDBT_LAYERA_*` values are assigned to the center segment and `DTV_ISDBT_LAYERA_SEGMENT_COUNT` has to be '1'.

If in addition `DTV_ISDBT_SOUND_BROADCASTING` is '1' `DTV_ISDBT_PARTIAL_RECEPTION` represents whether this ISDB-Tsb channel is consisting of one segment and layer or three segments and two layers.

Possible values: 0, 1, -1 (AUTO)

<a id="rst-dtv-isdbt-sound-broadcasting-1"></a>
<a id="rst-dtv-isdbt-sound-broadcasting"></a>

## DTV_ISDBT_SOUND_BROADCASTING

Used only on ISDB.

This field represents whether the other DTV_ISDBT\_\*-parameters are referring to an ISDB-T and an ISDB-Tsb channel. (See also `DTV_ISDBT_PARTIAL_RECEPTION`).

Possible values: 0, 1, -1 (AUTO)

<a id="rst-dtv-isdbt-sb-subchannel-id-1"></a>
<a id="rst-dtv-isdbt-sb-subchannel-id"></a>

## DTV_ISDBT_SB_SUBCHANNEL_ID

Used only on ISDB.

This field only applies if `DTV_ISDBT_SOUND_BROADCASTING` is '1'.

(Note of the author: This might not be the correct description of the `SUBCHANNEL-ID` in all details, but it is my understanding of the technical background needed to program a device)

An ISDB-Tsb channel (1 or 3 segments) can be broadcasted alone or in a set of connected ISDB-Tsb channels. In this set of channels every channel can be received independently. The number of connected ISDB-Tsb segment can vary, e.g. depending on the frequency spectrum bandwidth available.

Example: Assume 8 ISDB-Tsb connected segments are broadcasted. The broadcaster has several possibilities to put those channels in the air: Assuming a normal 13-segment ISDB-T spectrum he can align the 8 segments from position 1-8 to 5-13 or anything in between.

The underlying layer of segments are sub-channels: each segment is consisting of several sub-channels with a predefined IDs. A sub-channel is used to help the demodulator to synchronize on the channel.

An ISDB-T channel is always centered over all sub-channels. As for the example above, in ISDB-Tsb it is no longer as simple as that.

`The DTV_ISDBT_SB_SUBCHANNEL_ID` parameter is used to give the sub-channel ID of the segment to be demodulated.

Possible values: 0 .. 41, -1 (AUTO)

<a id="rst-dtv-isdbt-sb-segment-idx-1"></a>
<a id="rst-dtv-isdbt-sb-segment-idx"></a>

## DTV_ISDBT_SB_SEGMENT_IDX

Used only on ISDB.

This field only applies if `DTV_ISDBT_SOUND_BROADCASTING` is '1'.

`DTV_ISDBT_SB_SEGMENT_IDX` gives the index of the segment to be demodulated for an ISDB-Tsb channel where several of them are transmitted in the connected manner.

Possible values: 0 .. `DTV_ISDBT_SB_SEGMENT_COUNT` - 1

Note: This value cannot be determined by an automatic channel search.

<a id="rst-dtv-isdbt-sb-segment-count-1"></a>
<a id="rst-dtv-isdbt-sb-segment-count"></a>

## DTV_ISDBT_SB_SEGMENT_COUNT

Used only on ISDB.

This field only applies if `DTV_ISDBT_SOUND_BROADCASTING` is '1'.

`DTV_ISDBT_SB_SEGMENT_COUNT` gives the total count of connected ISDB-Tsb channels.

Possible values: 1 .. 13

Note: This value cannot be determined by an automatic channel search.

<a id="rst-dtv-isdbt-layer-a-c-parameters"></a>
<a id="rst-isdb-hierq-layers"></a>

## DTV-ISDBT-LAYER\[A-C\] parameters

Used only on ISDB.

ISDB-T channels can be coded hierarchically. As opposed to DVB-T in ISDB-T hierarchical layers can be decoded simultaneously. For that reason a ISDB-T demodulator has 3 Viterbi and 3 Reed-Solomon decoders.

ISDB-T has 3 hierarchical layers which each can use a part of the available segments. The total number of segments over all layers has to 13 in ISDB-T.

There are 3 parameter sets, for Layers A, B and C.

<a id="rst-dtv-isdbt-layer-enabled-1"></a>
<a id="rst-dtv-isdbt-layer-enabled"></a>

### DTV_ISDBT_LAYER_ENABLED

Used only on ISDB.

Hierarchical reception in ISDB-T is achieved by enabling or disabling layers in the decoding process. Setting all bits of `DTV_ISDBT_LAYER_ENABLED` to '1' forces all layers (if applicable) to be demodulated. This is the default.

If the channel is in the partial reception mode (`DTV_ISDBT_PARTIAL_RECEPTION` = 1) the central segment can be decoded independently of the other 12 segments. In that mode layer A has to have a `SEGMENT_COUNT` of 1.

In ISDB-Tsb only layer A is used, it can be 1 or 3 in ISDB-Tsb according to `DTV_ISDBT_PARTIAL_RECEPTION`. `SEGMENT_COUNT` must be filled accordingly.

Only the values of the first 3 bits are used. Other bits will be silently ignored:

`DTV_ISDBT_LAYER_ENABLED` bit 0: layer A enabled

`DTV_ISDBT_LAYER_ENABLED` bit 1: layer B enabled

`DTV_ISDBT_LAYER_ENABLED` bit 2: layer C enabled

`DTV_ISDBT_LAYER_ENABLED` bits 3-31: unused

<a id="rst-dtv-isdbt-layer-a-c-fec"></a>
<a id="rst-dtv-isdbt-layer-fec"></a>

### DTV_ISDBT_LAYER\[A-C\]\_FEC

Used only on ISDB.

The Forward Error Correction mechanism used by a given ISDB Layer, as defined by `fe_code_rate`.

Possible values are: `FEC_AUTO`, `FEC_1_2`, `FEC_2_3`, `FEC_3_4`, `FEC_5_6`, `FEC_7_8`

<a id="rst-dtv-isdbt-layer-a-c-modulation"></a>
<a id="rst-dtv-isdbt-layer-modulation"></a>

### DTV_ISDBT_LAYER\[A-C\]\_MODULATION

Used only on ISDB.

The modulation used by a given ISDB Layer, as defined by `fe_modulation`.

Possible values are: `QAM_AUTO`, `QPSK`, `QAM_16`, `QAM_64`, `DQPSK`

> [!NOTE]
>
> 1. If layer C is `DQPSK`, then layer B has to be `DQPSK`.
>
> 2. If layer B is `DQPSK` and `DTV_ISDBT_PARTIAL_RECEPTION`= 0, then layer has to be `DQPSK`.

<a id="rst-dtv-isdbt-layer-a-c-segment-count"></a>
<a id="rst-dtv-isdbt-layer-segment-count"></a>

### DTV_ISDBT_LAYER\[A-C\]\_SEGMENT_COUNT

Used only on ISDB.

Possible values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1 (AUTO)

Note: Truth table for `DTV_ISDBT_SOUND_BROADCASTING` and `DTV_ISDBT_PARTIAL_RECEPTION` and `LAYER[A-C]_SEGMENT_COUNT`

<a id="rst-isdbt-layer-seg-cnt-table"></a>


<table>
<caption>Truth table for ISDB-T Sound Broadcasting</caption>
<thead>
<tr>
<th>


Partial Reception

</th>
<th>


Sound Broadcasting

</th>
<th>


Layer A width

</th>
<th>


Layer B width

</th>
<th>


Layer C width

</th>
<th>


total width

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0

</td>
<td>


0

</td>
<td>


1 .. 13

</td>
<td>


1 .. 13

</td>
<td>


1 .. 13

</td>
<td>


13

</td>
</tr>
<tr>
<td>


1

</td>
<td>


0

</td>
<td>


1

</td>
<td>


1 .. 13

</td>
<td>


1 .. 13

</td>
<td>


13

</td>
</tr>
<tr>
<td>


0

</td>
<td>


1

</td>
<td>


1

</td>
<td>


0

</td>
<td>


0

</td>
<td>


1

</td>
</tr>
<tr>
<td>


1

</td>
<td>


1

</td>
<td>


1

</td>
<td>


2

</td>
<td>


0

</td>
<td>


13

</td>
</tr>
</tbody>
</table>

<a id="rst-dtv-isdbt-layer-a-c-time-interleaving"></a>
<a id="rst-dtv-isdbt-layer-time-interleaving"></a>

### DTV_ISDBT_LAYER\[A-C\]\_TIME_INTERLEAVING

Used only on ISDB.

Valid values: 0, 1, 2, 4, -1 (AUTO)

when DTV_ISDBT_SOUND_BROADCASTING is active, value 8 is also valid.

Note: The real time interleaving length depends on the mode (fft-size). The values here are referring to what can be found in the TMCC-structure, as shown in the table below.





<a id="c-isdbt_layer_interleaving_table"></a>

```c
isdbt_layer_interleaving_table
```


<table>
<caption>ISDB-T time interleaving modes</caption>
<thead>
<tr>
<th>


`DTV_ISDBT_LAYER[A-C]_TIME_INTERLEAVING`

</th>
<th>


Mode 1 (2K FFT)

</th>
<th>


Mode 2 (4K FFT)

</th>
<th>


Mode 3 (8K FFT)

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
</tr>
<tr>
<td>


1

</td>
<td>


4

</td>
<td>


2

</td>
<td>


1

</td>
</tr>
<tr>
<td>


2

</td>
<td>


8

</td>
<td>


4

</td>
<td>


2

</td>
</tr>
<tr>
<td>


4

</td>
<td>


16

</td>
<td>


8

</td>
<td>


4

</td>
</tr>
</tbody>
</table>

<a id="rst-dtv-atscmh-fic-ver-1"></a>
<a id="rst-dtv-atscmh-fic-ver"></a>

### DTV_ATSCMH_FIC_VER

Used only on ATSC-MH.

Version number of the FIC (Fast Information Channel) signaling data.

FIC is used for relaying information to allow rapid service acquisition by the receiver.

Possible values: 0, 1, 2, 3, ..., 30, 31

<a id="rst-dtv-atscmh-parade-id-1"></a>
<a id="rst-dtv-atscmh-parade-id"></a>

### DTV_ATSCMH_PARADE_ID

Used only on ATSC-MH.

Parade identification number

A parade is a collection of up to eight MH groups, conveying one or two ensembles.

Possible values: 0, 1, 2, 3, ..., 126, 127

<a id="rst-dtv-atscmh-nog-1"></a>
<a id="rst-dtv-atscmh-nog"></a>

### DTV_ATSCMH_NOG

Used only on ATSC-MH.

Number of MH groups per MH subframe for a designated parade.

Possible values: 1, 2, 3, 4, 5, 6, 7, 8

<a id="rst-dtv-atscmh-tnog-1"></a>
<a id="rst-dtv-atscmh-tnog"></a>

### DTV_ATSCMH_TNOG

Used only on ATSC-MH.

Total number of MH groups including all MH groups belonging to all MH parades in one MH subframe.

Possible values: 0, 1, 2, 3, ..., 30, 31

<a id="rst-dtv-atscmh-sgn-1"></a>
<a id="rst-dtv-atscmh-sgn"></a>

### DTV_ATSCMH_SGN

Used only on ATSC-MH.

Start group number.

Possible values: 0, 1, 2, 3, ..., 14, 15

<a id="rst-dtv-atscmh-prc-1"></a>
<a id="rst-dtv-atscmh-prc"></a>

### DTV_ATSCMH_PRC

Used only on ATSC-MH.

Parade repetition cycle.

Possible values: 1, 2, 3, 4, 5, 6, 7, 8

<a id="rst-dtv-atscmh-rs-frame-mode-1"></a>
<a id="rst-dtv-atscmh-rs-frame-mode"></a>

### DTV_ATSCMH_RS_FRAME_MODE

Used only on ATSC-MH.

Reed Solomon (RS) frame mode.

The acceptable values are defined by `atscmh_rs_frame_mode`.

<a id="rst-dtv-atscmh-rs-frame-ensemble-1"></a>
<a id="rst-dtv-atscmh-rs-frame-ensemble"></a>

### DTV_ATSCMH_RS_FRAME_ENSEMBLE

Used only on ATSC-MH.

Reed Solomon (RS) frame ensemble.

The acceptable values are defined by `atscmh_rs_frame_ensemble`.

<a id="rst-dtv-atscmh-rs-code-mode-pri-1"></a>
<a id="rst-dtv-atscmh-rs-code-mode-pri"></a>

### DTV_ATSCMH_RS_CODE_MODE_PRI

Used only on ATSC-MH.

Reed Solomon (RS) code mode (primary).

The acceptable values are defined by `atscmh_rs_code_mode`.

<a id="rst-dtv-atscmh-rs-code-mode-sec-1"></a>
<a id="rst-dtv-atscmh-rs-code-mode-sec"></a>

### DTV_ATSCMH_RS_CODE_MODE_SEC

Used only on ATSC-MH.

Reed Solomon (RS) code mode (secondary).

The acceptable values are defined by `atscmh_rs_code_mode`.

<a id="rst-dtv-atscmh-sccc-block-mode-1"></a>
<a id="rst-dtv-atscmh-sccc-block-mode"></a>

### DTV_ATSCMH_SCCC_BLOCK_MODE

Used only on ATSC-MH.

Series Concatenated Convolutional Code Block Mode.

The acceptable values are defined by `atscmh_sccc_block_mode`.

<a id="rst-dtv-atscmh-sccc-code-mode-a-1"></a>
<a id="rst-dtv-atscmh-sccc-code-mode-a"></a>

### DTV_ATSCMH_SCCC_CODE_MODE_A

Used only on ATSC-MH.

Series Concatenated Convolutional Code Rate.

The acceptable values are defined by `atscmh_sccc_code_mode`.

<a id="rst-dtv-atscmh-sccc-code-mode-b-1"></a>
<a id="rst-dtv-atscmh-sccc-code-mode-b"></a>

### DTV_ATSCMH_SCCC_CODE_MODE_B

Used only on ATSC-MH.

Series Concatenated Convolutional Code Rate.

Possible values are the same as documented on enum `atscmh_sccc_code_mode`.

<a id="rst-dtv-atscmh-sccc-code-mode-c-1"></a>
<a id="rst-dtv-atscmh-sccc-code-mode-c"></a>

### DTV_ATSCMH_SCCC_CODE_MODE_C

Used only on ATSC-MH.

Series Concatenated Convolutional Code Rate.

Possible values are the same as documented on enum `atscmh_sccc_code_mode`.

<a id="rst-dtv-atscmh-sccc-code-mode-d-1"></a>
<a id="rst-dtv-atscmh-sccc-code-mode-d"></a>

### DTV_ATSCMH_SCCC_CODE_MODE_D

Used only on ATSC-MH.

Series Concatenated Convolutional Code Rate.

Possible values are the same as documented on enum `atscmh_sccc_code_mode`.

<a id="rst-dtv-api-version-1"></a>
<a id="rst-dtv-api-version"></a>

## DTV_API_VERSION

Returns the major/minor version of the Digital TV API

<a id="rst-dtv-code-rate-hp-1"></a>
<a id="rst-dtv-code-rate-hp"></a>

## DTV_CODE_RATE_HP

Used on terrestrial transmissions.

The acceptable values are defined by `fe_transmit_mode`.

<a id="rst-dtv-code-rate-lp-1"></a>
<a id="rst-dtv-code-rate-lp"></a>

## DTV_CODE_RATE_LP

Used on terrestrial transmissions.

The acceptable values are defined by `fe_transmit_mode`.

<a id="rst-dtv-guard-interval-1"></a>
<a id="rst-dtv-guard-interval"></a>

## DTV_GUARD_INTERVAL

The acceptable values are defined by `fe_guard_interval`.

> [!NOTE]
>
> 1. If `DTV_GUARD_INTERVAL` is set the `GUARD_INTERVAL_AUTO` the hardware will try to find the correct guard interval (if capable) and will use TMCC to fill in the missing parameters.
>
> 2. Interval `GUARD_INTERVAL_1_64` is used only for DVB-C2.
>
> 3. Interval `GUARD_INTERVAL_1_128` is used for both DVB-C2 and DVB_T2.
>
> 4. Intervals `GUARD_INTERVAL_19_128` and `GUARD_INTERVAL_19_256` are used only for DVB-T2.
>
> 5. Intervals `GUARD_INTERVAL_PN420`, `GUARD_INTERVAL_PN595` and `GUARD_INTERVAL_PN945` are used only for DMTB at the present. On such standard, only those intervals and `GUARD_INTERVAL_AUTO` are valid.

<a id="rst-dtv-transmission-mode-1"></a>
<a id="rst-dtv-transmission-mode"></a>

## DTV_TRANSMISSION_MODE

Used only on OFTM-based standards, e. g. DVB-T/T2, ISDB-T, DTMB.

Specifies the FFT size (with corresponds to the approximate number of carriers) used by the standard.

The acceptable values are defined by `fe_transmit_mode`.

> [!NOTE]
>
> 1. ISDB-T supports three carrier/symbol-size: 8K, 4K, 2K. It is called **mode** on such standard, and are numbered from 1 to 3:
>
>
>    <table>
>    <thead>
>    <tr>
>    <th>
>
>
>    Mode
>
>    </th>
>    <th>
>
>
>    FFT size
>
>    </th>
>    <th>
>
>
>    Transmission mode
>
>    </th>
>    </tr>
>    </thead>
>    <tbody>
>    <tr>
>    <td>
>
>
>    1
>
>    </td>
>    <td>
>
>
>    2K
>
>    </td>
>    <td>
>
>
>    `TRANSMISSION_MODE_2K`
>
>    </td>
>    </tr>
>    <tr>
>    <td>
>
>
>    2
>
>    </td>
>    <td>
>
>
>    4K
>
>    </td>
>    <td>
>
>
>    `TRANSMISSION_MODE_4K`
>
>    </td>
>    </tr>
>    <tr>
>    <td>
>
>
>    3
>
>    </td>
>    <td>
>
>
>    8K
>
>    </td>
>    <td>
>
>
>    `TRANSMISSION_MODE_8K`
>
>    </td>
>    </tr>
>    </tbody>
>    </table>
>
> 2. If `DTV_TRANSMISSION_MODE` is set the `TRANSMISSION_MODE_AUTO` the hardware will try to find the correct FFT-size (if capable) and will use TMCC to fill in the missing parameters.
>
> 3. DVB-T specifies 2K and 8K as valid sizes.
>
> 4. DVB-T2 specifies 1K, 2K, 4K, 8K, 16K and 32K.
>
> 5. DTMB specifies C1 and C3780.

<a id="rst-dtv-hierarchy-1"></a>
<a id="rst-dtv-hierarchy"></a>

## DTV_HIERARCHY

Used only on DVB-T and DVB-T2.

Frontend hierarchy.

The acceptable values are defined by `fe_hierarchy`.

<a id="rst-dtv-stream-id-1"></a>
<a id="rst-dtv-stream-id"></a>

## DTV_STREAM_ID

Used on DVB-C2, DVB-S2, DVB-T2 and ISDB-S.

DVB-C2, DVB-S2, DVB-T2 and ISDB-S support the transmission of several streams on a single transport stream. This property enables the digital TV driver to handle substream filtering, when supported by the hardware. By default, substream filtering is disabled.

For DVB-C2, DVB-S2 and DVB-T2, the valid substream id range is from 0 to 255.

For ISDB, the valid substream id range is from 1 to 65535.

To disable it, you should use the special macro NO_STREAM_ID_FILTER.

Note: any value outside the id range also disables filtering.

<a id="rst-dtv-dvbt2-plp-id-legacy-1"></a>
<a id="rst-dtv-dvbt2-plp-id-legacy"></a>

## DTV_DVBT2_PLP_ID_LEGACY

Obsolete, replaced with DTV_STREAM_ID.

<a id="rst-dtv-enum-delsys-1"></a>
<a id="rst-dtv-enum-delsys"></a>

## DTV_ENUM_DELSYS

A Multi standard frontend needs to advertise the delivery systems provided. Applications need to enumerate the provided delivery systems, before using any other operation with the frontend. Prior to its introduction, FE_GET_INFO was used to determine a frontend type. A frontend which provides more than a single delivery system, FE_GET_INFO doesn't help much. Applications which intends to use a multistandard frontend must enumerate the delivery systems associated with it, rather than trying to use FE_GET_INFO. In the case of a legacy frontend, the result is just the same as with FE_GET_INFO, but in a more structured format.

The acceptable values are defined by `fe_delivery_system`.

<a id="rst-dtv-interleaving-1"></a>
<a id="rst-dtv-interleaving"></a>

## DTV_INTERLEAVING

Time interleaving to be used.

The acceptable values are defined by `fe_interleaving`.

<a id="rst-dtv-lna-1"></a>
<a id="rst-dtv-lna"></a>

## DTV_LNA

Low-noise amplifier.

Hardware might offer controllable LNA which can be set manually using that parameter. Usually LNA could be found only from terrestrial devices if at all.

Possible values: 0, 1, LNA_AUTO

0, LNA off

1, LNA on

use the special macro LNA_AUTO to set LNA auto

<a id="rst-dtv-scrambling-sequence-index-1"></a>
<a id="rst-dtv-scrambling-sequence-index"></a>

## DTV_SCRAMBLING_SEQUENCE_INDEX

Used on DVB-S2.

This 18 bit field, when present, carries the index of the DVB-S2 physical layer scrambling sequence as defined in clause 5.5.4 of EN 302 307. There is no explicit signalling method to convey scrambling sequence index to the receiver. If S2 satellite delivery system descriptor is available it can be used to read the scrambling sequence index (EN 300 468 table 41).

By default, gold scrambling sequence index 0 is used.

The valid scrambling sequence index range is from 0 to 262142.

---

# Frontend uAPI data types

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for Frontend uAPI data types.

<a id="rst-frontend-uapi-data-types"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->


#### <a id="c-enum-fe_caps"></a>`enum fe_caps`

Frontend capabilities

**Constants**

- `FE_IS_STUPID`: There's something wrong at the
  frontend, and it can't report its
  capabilities.
- `FE_CAN_INVERSION_AUTO`: Can auto-detect frequency spectral
  band inversion
- `FE_CAN_FEC_1_2`: Supports FEC 1/2
- `FE_CAN_FEC_2_3`: Supports FEC 2/3
- `FE_CAN_FEC_3_4`: Supports FEC 3/4
- `FE_CAN_FEC_4_5`: Supports FEC 4/5
- `FE_CAN_FEC_5_6`: Supports FEC 5/6
- `FE_CAN_FEC_6_7`: Supports FEC 6/7
- `FE_CAN_FEC_7_8`: Supports FEC 7/8
- `FE_CAN_FEC_8_9`: Supports FEC 8/9
- `FE_CAN_FEC_AUTO`: Can auto-detect FEC
- `FE_CAN_QPSK`: Supports QPSK modulation
- `FE_CAN_QAM_16`: Supports 16-QAM modulation
- `FE_CAN_QAM_32`: Supports 32-QAM modulation
- `FE_CAN_QAM_64`: Supports 64-QAM modulation
- `FE_CAN_QAM_128`: Supports 128-QAM modulation
- `FE_CAN_QAM_256`: Supports 256-QAM modulation
- `FE_CAN_QAM_AUTO`: Can auto-detect QAM modulation
- `FE_CAN_TRANSMISSION_MODE_AUTO`: Can auto-detect transmission mode
- `FE_CAN_BANDWIDTH_AUTO`: Can auto-detect bandwidth
- `FE_CAN_GUARD_INTERVAL_AUTO`: Can auto-detect guard interval
- `FE_CAN_HIERARCHY_AUTO`: Can auto-detect hierarchy
- `FE_CAN_8VSB`: Supports 8-VSB modulation
- `FE_CAN_16VSB`: Supporta 16-VSB modulation
- `FE_HAS_EXTENDED_CAPS`: Unused
- `FE_CAN_MULTISTREAM`: Supports multistream filtering
- `FE_CAN_TURBO_FEC`: Supports "turbo FEC" modulation
- `FE_CAN_2G_MODULATION`: Supports "2nd generation" modulation,
  e. g. DVB-S2, DVB-T2, DVB-C2
- `FE_NEEDS_BENDING`: Unused
- `FE_CAN_RECOVER`: Can recover from a cable unplug
  automatically
- `FE_CAN_MUTE_TS`: Can stop spurious TS data output

#### <a id="c-struct-dvb_frontend_info"></a>`struct dvb_frontend_info`

Frontend properties and capabilities

**Definition**

```c
struct dvb_frontend_info {
    char name[128];
    enum fe_type type;
    __u32 frequency_min;
    __u32 frequency_max;
    __u32 frequency_stepsize;
    __u32 frequency_tolerance;
    __u32 symbol_rate_min;
    __u32 symbol_rate_max;
    __u32 symbol_rate_tolerance;
    __u32 notifier_delay;
    enum fe_caps caps;
};
```

**Members**

- `name`: Name of the frontend
- `type`:

  **DEPRECATED**.
  Should not be used on modern programs,
  as a frontend may have more than one type.
  In order to get the support types of a given
  frontend, use `DTV_ENUM_DELSYS`
  instead.
- `frequency_min`: Minimal frequency supported by the frontend.
- `frequency_max`: Minimal frequency supported by the frontend.
- `frequency_stepsize`: All frequencies are multiple of this value.
- `frequency_tolerance`: Frequency tolerance.
- `symbol_rate_min`: Minimal symbol rate, in bauds
  (for Cable/Satellite systems).
- `symbol_rate_max`: Maximal symbol rate, in bauds
  (for Cable/Satellite systems).
- `symbol_rate_tolerance`: Maximal symbol rate tolerance, in ppm
  (for Cable/Satellite systems).
- `notifier_delay`:

  **DEPRECATED**. Not used by any driver.
- `caps`: Capabilities supported by the frontend,
  as specified in [`enum fe_caps`](#c-enum-fe_caps).

**Description**

#### <a id="c-struct-dvb_diseqc_master_cmd"></a>`struct dvb_diseqc_master_cmd`

DiSEqC master command

**Definition**

```c
struct dvb_diseqc_master_cmd {
    __u8 msg[6];
    __u8 msg_len;
};
```

**Members**

- `msg`: DiSEqC message to be sent. It contains a 3 bytes header with:
  framing + address + command, and an optional argument
  of up to 3 bytes of data.
- `msg_len`: Length of the DiSEqC message. Valid values are 3 to 6.

**Description**

Check out the DiSEqC bus spec available on http://www.eutelsat.org/ for
the possible messages that can be used.

#### <a id="c-struct-dvb_diseqc_slave_reply"></a>`struct dvb_diseqc_slave_reply`

DiSEqC received data

**Definition**

```c
struct dvb_diseqc_slave_reply {
    __u8 msg[4];
    __u8 msg_len;
    int timeout;
};
```

**Members**

- `msg`: DiSEqC message buffer to store a message received via DiSEqC.
  It contains one byte header with: framing and
  an optional argument of up to 3 bytes of data.
- `msg_len`: Length of the DiSEqC message. Valid values are 0 to 4,
  where 0 means no message.
- `timeout`: Return from ioctl after timeout ms with errorcode when
  no message was received.

**Description**

Check out the DiSEqC bus spec available on http://www.eutelsat.org/ for
the possible messages that can be used.

#### <a id="c-enum-fe_sec_voltage"></a>`enum fe_sec_voltage`

DC Voltage used to feed the LNBf

**Constants**

- `SEC_VOLTAGE_13`: Output 13V to the LNBf
- `SEC_VOLTAGE_18`: Output 18V to the LNBf
- `SEC_VOLTAGE_OFF`: Don't feed the LNBf with a DC voltage

#### <a id="c-enum-fe_sec_tone_mode"></a>`enum fe_sec_tone_mode`

Type of tone to be send to the LNBf.

**Constants**

- `SEC_TONE_ON`: Sends a 22kHz tone burst to the antenna.
- `SEC_TONE_OFF`: Don't send a 22kHz tone to the antenna (except
  if the `FE_DISEQC_*` ioctls are called).

#### <a id="c-enum-fe_sec_mini_cmd"></a>`enum fe_sec_mini_cmd`

Type of mini burst to be sent

**Constants**

- `SEC_MINI_A`: Sends a mini-DiSEqC 22kHz '0' Tone Burst to select
  satellite-A
- `SEC_MINI_B`: Sends a mini-DiSEqC 22kHz '1' Data Burst to select
  satellite-B

#### <a id="c-enum-fe_status"></a>`enum fe_status`

Enumerates the possible frontend status.

**Constants**

- `FE_NONE`: The frontend doesn't have any kind of lock.
  That's the initial frontend status
- `FE_HAS_SIGNAL`: Has found something above the noise level.
- `FE_HAS_CARRIER`: Has found a signal.
- `FE_HAS_VITERBI`: FEC inner coding (Viterbi, LDPC or other inner code).
  is stable.
- `FE_HAS_SYNC`: Synchronization bytes was found.
- `FE_HAS_LOCK`: Digital TV were locked and everything is working.
- `FE_TIMEDOUT`: Fo lock within the last about 2 seconds.
- `FE_REINIT`: Frontend was reinitialized, application is recommended
  to reset DiSEqC, tone and parameters.

#### <a id="c-enum-fe_spectral_inversion"></a>`enum fe_spectral_inversion`

Type of inversion band

**Constants**

- `INVERSION_OFF`: Don't do spectral band inversion.
- `INVERSION_ON`: Do spectral band inversion.
- `INVERSION_AUTO`: Autodetect spectral band inversion.

**Description**

This parameter indicates if spectral inversion should be presumed or
not. In the automatic setting (`INVERSION_AUTO`) the hardware will try
to figure out the correct setting by itself. If the hardware doesn't
support, the `dvb_frontend` will try to lock at the carrier first with
inversion off. If it fails, it will try to enable inversion.

#### <a id="c-enum-fe_code_rate"></a>`enum fe_code_rate`

Type of Forward Error Correction (FEC)

**Constants**

- `FEC_NONE`: No Forward Error Correction Code
- `FEC_1_2`: Forward Error Correction Code 1/2
- `FEC_2_3`: Forward Error Correction Code 2/3
- `FEC_3_4`: Forward Error Correction Code 3/4
- `FEC_4_5`: Forward Error Correction Code 4/5
- `FEC_5_6`: Forward Error Correction Code 5/6
- `FEC_6_7`: Forward Error Correction Code 6/7
- `FEC_7_8`: Forward Error Correction Code 7/8
- `FEC_8_9`: Forward Error Correction Code 8/9
- `FEC_AUTO`: Autodetect Error Correction Code
- `FEC_3_5`: Forward Error Correction Code 3/5
- `FEC_9_10`: Forward Error Correction Code 9/10
- `FEC_2_5`: Forward Error Correction Code 2/5
- `FEC_1_3`: Forward Error Correction Code 1/3
- `FEC_1_4`: Forward Error Correction Code 1/4
- `FEC_5_9`: Forward Error Correction Code 5/9
- `FEC_7_9`: Forward Error Correction Code 7/9
- `FEC_8_15`: Forward Error Correction Code 8/15
- `FEC_11_15`: Forward Error Correction Code 11/15
- `FEC_13_18`: Forward Error Correction Code 13/18
- `FEC_9_20`: Forward Error Correction Code 9/20
- `FEC_11_20`: Forward Error Correction Code 11/20
- `FEC_23_36`: Forward Error Correction Code 23/36
- `FEC_25_36`: Forward Error Correction Code 25/36
- `FEC_13_45`: Forward Error Correction Code 13/45
- `FEC_26_45`: Forward Error Correction Code 26/45
- `FEC_28_45`: Forward Error Correction Code 28/45
- `FEC_32_45`: Forward Error Correction Code 32/45
- `FEC_77_90`: Forward Error Correction Code 77/90
- `FEC_11_45`: Forward Error Correction Code 11/45
- `FEC_4_15`: Forward Error Correction Code 4/15
- `FEC_14_45`: Forward Error Correction Code 14/45
- `FEC_7_15`: Forward Error Correction Code 7/15

**Description**

Please note that not all FEC types are supported by a given standard.

#### <a id="c-enum-fe_modulation"></a>`enum fe_modulation`

Type of modulation/constellation

**Constants**

- `QPSK`: QPSK modulation
- `QAM_16`: 16-QAM modulation
- `QAM_32`: 32-QAM modulation
- `QAM_64`: 64-QAM modulation
- `QAM_128`: 128-QAM modulation
- `QAM_256`: 256-QAM modulation
- `QAM_AUTO`: Autodetect QAM modulation
- `VSB_8`: 8-VSB modulation
- `VSB_16`: 16-VSB modulation
- `PSK_8`: 8-PSK modulation
- `APSK_16`: 16-APSK modulation
- `APSK_32`: 32-APSK modulation
- `DQPSK`: DQPSK modulation
- `QAM_4_NR`: 4-QAM-NR modulation
- `QAM_1024`: 1024-QAM modulation
- `QAM_4096`: 4096-QAM modulation
- `APSK_8_L`: 8APSK-L modulation
- `APSK_16_L`: 16APSK-L modulation
- `APSK_32_L`: 32APSK-L modulation
- `APSK_64`: 64APSK modulation
- `APSK_64_L`: 64APSK-L modulation

**Description**

Please note that not all modulations are supported by a given standard.

#### <a id="c-enum-fe_transmit_mode"></a>`enum fe_transmit_mode`

Transmission mode

**Constants**

- `TRANSMISSION_MODE_2K`: Transmission mode 2K
- `TRANSMISSION_MODE_8K`: Transmission mode 8K
- `TRANSMISSION_MODE_AUTO`: Autodetect transmission mode. The hardware will try to find the
  correct FFT-size (if capable) to fill in the missing parameters.
- `TRANSMISSION_MODE_4K`: Transmission mode 4K
- `TRANSMISSION_MODE_1K`: Transmission mode 1K
- `TRANSMISSION_MODE_16K`: Transmission mode 16K
- `TRANSMISSION_MODE_32K`: Transmission mode 32K
- `TRANSMISSION_MODE_C1`: Single Carrier (C=1) transmission mode (DTMB only)
- `TRANSMISSION_MODE_C3780`: Multi Carrier (C=3780) transmission mode (DTMB only)

**Description**

Please note that not all transmission modes are supported by a given
standard.

#### <a id="c-enum-fe_guard_interval"></a>`enum fe_guard_interval`

Guard interval

**Constants**

- `GUARD_INTERVAL_1_32`: Guard interval 1/32
- `GUARD_INTERVAL_1_16`: Guard interval 1/16
- `GUARD_INTERVAL_1_8`: Guard interval 1/8
- `GUARD_INTERVAL_1_4`: Guard interval 1/4
- `GUARD_INTERVAL_AUTO`: Autodetect the guard interval
- `GUARD_INTERVAL_1_128`: Guard interval 1/128
- `GUARD_INTERVAL_19_128`: Guard interval 19/128
- `GUARD_INTERVAL_19_256`: Guard interval 19/256
- `GUARD_INTERVAL_PN420`: PN length 420 (1/4)
- `GUARD_INTERVAL_PN595`: PN length 595 (1/6)
- `GUARD_INTERVAL_PN945`: PN length 945 (1/9)
- `GUARD_INTERVAL_1_64`: Guard interval 1/64

**Description**

Please note that not all guard intervals are supported by a given standard.

#### <a id="c-enum-fe_hierarchy"></a>`enum fe_hierarchy`

Hierarchy

**Constants**

- `HIERARCHY_NONE`: No hierarchy
- `HIERARCHY_1`: Hierarchy 1
- `HIERARCHY_2`: Hierarchy 2
- `HIERARCHY_4`: Hierarchy 4
- `HIERARCHY_AUTO`: Autodetect hierarchy (if supported)

**Description**

Please note that not all hierarchy types are supported by a given standard.

#### <a id="c-enum-fe_interleaving"></a>`enum fe_interleaving`

Interleaving

**Constants**

- `INTERLEAVING_NONE`: No interleaving.
- `INTERLEAVING_AUTO`: Auto-detect interleaving.
- `INTERLEAVING_240`: Interleaving of 240 symbols.
- `INTERLEAVING_720`: Interleaving of 720 symbols.

**Description**

Please note that, currently, only DTMB uses it.

#### <a id="c-enum-fe_pilot"></a>`enum fe_pilot`

Type of pilot tone

**Constants**

- `PILOT_ON`: Pilot tones enabled
- `PILOT_OFF`: Pilot tones disabled
- `PILOT_AUTO`: Autodetect pilot tones

#### <a id="c-enum-fe_rolloff"></a>`enum fe_rolloff`

Rolloff factor

**Constants**

- `ROLLOFF_35`: Roloff factor: α=35%
- `ROLLOFF_20`: Roloff factor: α=20%
- `ROLLOFF_25`: Roloff factor: α=25%
- `ROLLOFF_AUTO`: Auto-detect the roloff factor.
- `ROLLOFF_15`: Rolloff factor: α=15%
- `ROLLOFF_10`: Rolloff factor: α=10%
- `ROLLOFF_5`: Rolloff factor: α=5%

**Description**

#### <a id="c-enum-fe_delivery_system"></a>`enum fe_delivery_system`

Type of the delivery system

**Constants**

- `SYS_UNDEFINED`: Undefined standard. Generally, indicates an error
- `SYS_DVBC_ANNEX_A`: Cable TV: DVB-C following ITU-T J.83 Annex A spec
- `SYS_DVBC_ANNEX_B`: Cable TV: DVB-C following ITU-T J.83 Annex B spec (ClearQAM)
- `SYS_DVBT`: Terrestrial TV: DVB-T
- `SYS_DSS`: Satellite TV: DSS (not fully supported)
- `SYS_DVBS`: Satellite TV: DVB-S
- `SYS_DVBS2`: Satellite TV: DVB-S2 and DVB-S2X
- `SYS_DVBH`: Terrestrial TV (mobile): DVB-H (standard deprecated)
- `SYS_ISDBT`: Terrestrial TV: ISDB-T
- `SYS_ISDBS`: Satellite TV: ISDB-S
- `SYS_ISDBC`: Cable TV: ISDB-C (no drivers yet)
- `SYS_ATSC`: Terrestrial TV: ATSC
- `SYS_ATSCMH`: Terrestrial TV (mobile): ATSC-M/H
- `SYS_DTMB`: Terrestrial TV: DTMB
- `SYS_CMMB`: Terrestrial TV (mobile): CMMB (not fully supported)
- `SYS_DAB`: Digital audio: DAB (not fully supported)
- `SYS_DVBT2`: Terrestrial TV: DVB-T2
- `SYS_TURBO`: Satellite TV: DVB-S Turbo
- `SYS_DVBC_ANNEX_C`: Cable TV: DVB-C following ITU-T J.83 Annex C spec
- `SYS_DVBC2`: Cable TV: DVB-C2

#### <a id="c-enum-atscmh_sccc_block_mode"></a>`enum atscmh_sccc_block_mode`

Type of Series Concatenated Convolutional Code Block Mode.

**Constants**

- `ATSCMH_SCCC_BLK_SEP`: Separate SCCC: the SCCC outer code mode shall be set independently
  for each Group Region (A, B, C, D)
- `ATSCMH_SCCC_BLK_COMB`: Combined SCCC: all four Regions shall have the same SCCC outer
  code mode.
- `ATSCMH_SCCC_BLK_RES`: Reserved. Shouldn't be used.

#### <a id="c-enum-atscmh_sccc_code_mode"></a>`enum atscmh_sccc_code_mode`

Type of Series Concatenated Convolutional Code Rate.

**Constants**

- `ATSCMH_SCCC_CODE_HLF`: The outer code rate of a SCCC Block is 1/2 rate.
- `ATSCMH_SCCC_CODE_QTR`: The outer code rate of a SCCC Block is 1/4 rate.
- `ATSCMH_SCCC_CODE_RES`: Reserved. Should not be used.

#### <a id="c-enum-atscmh_rs_frame_ensemble"></a>`enum atscmh_rs_frame_ensemble`

Reed Solomon(RS) frame ensemble.

**Constants**

- `ATSCMH_RSFRAME_ENS_PRI`: Primary Ensemble.
- `ATSCMH_RSFRAME_ENS_SEC`: Secondary Ensemble.

#### <a id="c-enum-atscmh_rs_frame_mode"></a>`enum atscmh_rs_frame_mode`

Reed Solomon (RS) frame mode.

**Constants**

- `ATSCMH_RSFRAME_PRI_ONLY`: Single Frame: There is only a primary RS Frame for all Group
  Regions.
- `ATSCMH_RSFRAME_PRI_SEC`: Dual Frame: There are two separate RS Frames: Primary RS Frame for
  Group Region A and B and Secondary RS Frame for Group Region C and
  D.
- `ATSCMH_RSFRAME_RES`: Reserved. Shouldn't be used.

#### <a id="c-enum-atscmh_rs_code_mode"></a>`enum atscmh_rs_code_mode`

ATSC-M/H Reed Solomon modes

**Constants**

- `ATSCMH_RSCODE_211_187`: Reed Solomon code (211,187).
- `ATSCMH_RSCODE_223_187`: Reed Solomon code (223,187).
- `ATSCMH_RSCODE_235_187`: Reed Solomon code (235,187).
- `ATSCMH_RSCODE_RES`: Reserved. Shouldn't be used.

#### <a id="c-enum-fecap_scale_params"></a>`enum fecap_scale_params`

scale types for the quality parameters.

**Constants**

- `FE_SCALE_NOT_AVAILABLE`: That QoS measure is not available. That
  could indicate a temporary or a permanent
  condition.
- `FE_SCALE_DECIBEL`: The scale is measured in 0.001 dB steps, typically
  used on signal measures.
- `FE_SCALE_RELATIVE`: The scale is a relative percentual measure,
  ranging from 0 (0%) to 0xffff (100%).
- `FE_SCALE_COUNTER`: The scale counts the occurrence of an event, like
  bit error, block error, lapsed time.

#### <a id="c-struct-dtv_stats"></a>`struct dtv_stats`

Used for reading a DTV status property

**Definition**

```c
struct dtv_stats {
    __u8 scale;
    union {
        __u64 uvalue;
        __s64 svalue;
    };
};
```

**Members**

- `scale`: Filled with enum fecap_scale_params - the scale in usage
  for that parameter
- `{unnamed_union}`: anonymous
- `uvalue`: unsigned integer value of the measure, used when **scale** is
  either `FE_SCALE_RELATIVE` or `FE_SCALE_COUNTER`.
- `svalue`: integer value of the measure, for `FE_SCALE_DECIBEL`,
  used for dB measures. The unit is 0.001 dB.

**Description**

For most delivery systems, this will return a single value for each
parameter.

It should be noticed, however, that new OFDM delivery systems like
ISDB can use different modulation types for each group of carriers.
On such standards, up to 8 groups of statistics can be provided, one
for each carrier group (called "layer" on ISDB).

In order to be consistent with other delivery systems, the first
value refers to the entire set of carriers ("global").

**scale** should use the value `FE_SCALE_NOT_AVAILABLE` when
the value for the entire group of carriers or from one specific layer
is not provided by the hardware.

**len** should be filled with the latest filled status + 1.

In other words, for ISDB, those values should be filled like:

```text
u.st.stat.svalue[0] = global statistics;
u.st.stat.scale[0] = FE_SCALE_DECIBEL;
u.st.stat.value[1] = layer A statistics;
u.st.stat.scale[1] = FE_SCALE_NOT_AVAILABLE (if not available);
u.st.stat.svalue[2] = layer B statistics;
u.st.stat.scale[2] = FE_SCALE_DECIBEL;
u.st.stat.svalue[3] = layer C statistics;
u.st.stat.scale[3] = FE_SCALE_DECIBEL;
u.st.len = 4;
```

#### <a id="c-struct-dtv_fe_stats"></a>`struct dtv_fe_stats`

store Digital TV frontend statistics

**Definition**

```c
struct dtv_fe_stats {
    __u8 len;
    struct dtv_stats stat[MAX_DTV_STATS];
};
```

**Members**

- `len`: length of the statistics - if zero, stats is disabled.
- `stat`: array with digital TV statistics.

**Description**

On most standards, **len** can either be 0 or 1. However, for ISDB, each
layer is modulated in separate. So, each layer may have its own set
of statistics. If so, stat\[0\] carries on a global value for the property.
Indexes 1 to 3 means layer A to B.

#### <a id="c-struct-dtv_property"></a>`struct dtv_property`

store one of frontend command and its value

**Definition**

```c
struct dtv_property {
    __u32 cmd;
    __u32 reserved[3];
    union {
        __u32 data;
        struct dtv_fe_stats st;
        struct {
            __u8 data[32];
            __u32 len;
            __u32 reserved1[3];
            void *reserved2;
        } buffer;
    } u;
    int result;
};
```

**Members**

- `cmd`: Digital TV command.
- `reserved`: Not used.
- `u`: Union with the values for the command.
- `u.data`: A unsigned 32 bits integer with command value.
- `u.st`: a [`struct dtv_fe_stats`](#c-struct-dtv_fe_stats) array of statistics.
- `u.buffer`: Struct to store bigger properties.
  Currently unused.
- `u.buffer.data`: an unsigned 32-bits array.
- `u.buffer.len`: number of elements of the buffer.
- `u.buffer.reserved1`: Reserved.
- `u.buffer.reserved2`: Reserved.
- `result`: Currently unused.

#### <a id="c-struct-dtv_properties"></a>`struct dtv_properties`

a set of command/value pairs.

**Definition**

```c
struct dtv_properties {
    __u32 num;
    struct dtv_property *props;
};
```

**Members**

- `num`: amount of commands stored at the struct.
- `props`: a pointer to [`struct dtv_property`](#c-struct-dtv_property).

---

# Properties used on cable delivery systems

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The DVB-C Annex-A is the widely used cable standard. Transmission uses QAM modulation.

<a id="rst-properties-used-on-cable-delivery-systems"></a>
<a id="rst-frontend-property-cable-systems"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<a id="rst-dvb-c-delivery-system"></a>
<a id="rst-dvbc-params"></a>

## DVB-C delivery system

The DVB-C Annex-A is the widely used cable standard. Transmission uses QAM modulation.

The DVB-C Annex-C is optimized for 6MHz, and is used in Japan. It supports a subset of the Annex A modulation types, and a roll-off of 0.13, instead of 0.15

The following parameters are valid for DVB-C Annex A/C:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>)

- [DTV_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>)

- [DTV_SYMBOL_RATE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-symbol-rate>)

- [DTV_INNER_FEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inner-fec>)

- [DTV_LNA](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-lna>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

<a id="rst-dvb-c-annex-b-delivery-system"></a>
<a id="rst-dvbc-annex-b-params"></a>

## DVB-C Annex B delivery system

The DVB-C Annex-B is only used on a few Countries like the United States.

The following parameters are valid for DVB-C Annex B:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>)

- [DTV_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>)

- [DTV_LNA](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-lna>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

---

# Properties used on satellite delivery systems

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The following parameters are valid for DVB-S:

<a id="rst-properties-used-on-satellite-delivery-systems"></a>
<a id="rst-frontend-property-satellite-systems"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<a id="rst-dvb-s-delivery-system"></a>
<a id="rst-dvbs-params"></a>

## DVB-S delivery system

The following parameters are valid for DVB-S:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>)

- [DTV_SYMBOL_RATE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-symbol-rate>)

- [DTV_INNER_FEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inner-fec>)

- [DTV_VOLTAGE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-voltage>)

- [DTV_TONE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tone>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

Future implementations might add those two missing parameters:

- [DTV_DISEQC_MASTER](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-diseqc-master>)

- [DTV_DISEQC_SLAVE_REPLY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-diseqc-slave-reply>)

<a id="rst-dvb-s2-delivery-system"></a>
<a id="rst-dvbs2-params"></a>

## DVB-S2 delivery system

In addition to all parameters valid for DVB-S, DVB-S2 supports the following parameters:

- [DTV_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>)

- [DTV_PILOT](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-pilot>)

- [DTV_ROLLOFF](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-rolloff>)

- [DTV_STREAM_ID](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-stream-id>)

- [DTV_SCRAMBLING_SEQUENCE_INDEX](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-scrambling-sequence-index>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

<a id="rst-turbo-code-delivery-system"></a>
<a id="rst-turbo-params"></a>

## Turbo code delivery system

In addition to all parameters valid for DVB-S, turbo code supports the following parameters:

- [DTV_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>)

<a id="rst-isdb-s-delivery-system"></a>
<a id="rst-isdbs-params"></a>

## ISDB-S delivery system

The following parameters are valid for ISDB-S:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>)

- [DTV_SYMBOL_RATE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-symbol-rate>)

- [DTV_INNER_FEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inner-fec>)

- [DTV_VOLTAGE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-voltage>)

- [DTV_STREAM_ID](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-stream-id>)

---

# Properties used on terrestrial delivery systems

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The following parameters are valid for DVB-T:

<a id="rst-properties-used-on-terrestrial-delivery-systems"></a>
<a id="rst-frontend-property-terrestrial-systems"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<a id="rst-dvb-t-delivery-system"></a>
<a id="rst-dvbt-params"></a>

## DVB-T delivery system

The following parameters are valid for DVB-T:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>)

- [DTV_BANDWIDTH_HZ](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-bandwidth-hz>)

- [DTV_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>)

- [DTV_CODE_RATE_HP](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-code-rate-hp>)

- [DTV_CODE_RATE_LP](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-code-rate-lp>)

- [DTV_GUARD_INTERVAL](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-guard-interval>)

- [DTV_TRANSMISSION_MODE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-transmission-mode>)

- [DTV_HIERARCHY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-hierarchy>)

- [DTV_LNA](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-lna>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

<a id="rst-dvb-t2-delivery-system"></a>
<a id="rst-dvbt2-params"></a>

## DVB-T2 delivery system

DVB-T2 support is currently in the early stages of development, so expect that this section may grow and become more detailed with time.

The following parameters are valid for DVB-T2:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>)

- [DTV_BANDWIDTH_HZ](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-bandwidth-hz>)

- [DTV_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>)

- [DTV_CODE_RATE_HP](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-code-rate-hp>)

- [DTV_CODE_RATE_LP](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-code-rate-lp>)

- [DTV_GUARD_INTERVAL](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-guard-interval>)

- [DTV_TRANSMISSION_MODE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-transmission-mode>)

- [DTV_HIERARCHY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-hierarchy>)

- [DTV_STREAM_ID](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-stream-id>)

- [DTV_LNA](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-lna>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

<a id="rst-isdb-t-delivery-system"></a>
<a id="rst-isdbt"></a>

## ISDB-T delivery system

This ISDB-T/ISDB-Tsb API extension should reflect all information needed to tune any ISDB-T/ISDB-Tsb hardware. Of course it is possible that some very sophisticated devices won't need certain parameters to tune.

The information given here should help application writers to know how to handle ISDB-T and ISDB-Tsb hardware using the Linux Digital TV API.

The details given here about ISDB-T and ISDB-Tsb are just enough to basically show the dependencies between the needed parameter values, but surely some information is left out. For more detailed information see the following documents:

ARIB STD-B31 - "Transmission System for Digital Terrestrial Television Broadcasting" and

ARIB TR-B14 - "Operational Guidelines for Digital Terrestrial Television Broadcasting".

In order to understand the ISDB specific parameters, one has to have some knowledge the channel structure in ISDB-T and ISDB-Tsb. I.e. it has to be known to the reader that an ISDB-T channel consists of 13 segments, that it can have up to 3 layer sharing those segments, and things like that.

The following parameters are valid for ISDB-T:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_BANDWIDTH_HZ](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-bandwidth-hz>)

- [DTV_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>)

- [DTV_GUARD_INTERVAL](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-guard-interval>)

- [DTV_TRANSMISSION_MODE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-transmission-mode>)

- [DTV_ISDBT_LAYER_ENABLED](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-enabled>)

- [DTV_ISDBT_PARTIAL_RECEPTION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-partial-reception>)

- [DTV_ISDBT_SOUND_BROADCASTING](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-sound-broadcasting>)

- [DTV_ISDBT_SB_SUBCHANNEL_ID](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-sb-subchannel-id>)

- [DTV_ISDBT_SB_SEGMENT_IDX](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-sb-segment-idx>)

- [DTV_ISDBT_SB_SEGMENT_COUNT](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-sb-segment-count>)

- [DTV_ISDBT_LAYERA_FEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-fec>)

- [DTV_ISDBT_LAYERA_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-modulation>)

- [DTV_ISDBT_LAYERA_SEGMENT_COUNT](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-segment-count>)

- [DTV_ISDBT_LAYERA_TIME_INTERLEAVING](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-time-interleaving>)

- [DTV_ISDBT_LAYERB_FEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-fec>)

- [DTV_ISDBT_LAYERB_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-modulation>)

- [DTV_ISDBT_LAYERB_SEGMENT_COUNT](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-segment-count>)

- [DTV_ISDBT_LAYERB_TIME_INTERLEAVING](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-time-interleaving>)

- [DTV_ISDBT_LAYERC_FEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-fec>)

- [DTV_ISDBT_LAYERC_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-modulation>)

- [DTV_ISDBT_LAYERC_SEGMENT_COUNT](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-segment-count>)

- [DTV_ISDBT_LAYERC_TIME_INTERLEAVING](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-time-interleaving>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

<a id="rst-atsc-delivery-system"></a>
<a id="rst-atsc-params"></a>

## ATSC delivery system

The following parameters are valid for ATSC:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>)

- [DTV_BANDWIDTH_HZ](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-bandwidth-hz>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

<a id="rst-atsc-mh-delivery-system"></a>
<a id="rst-atscmh-params"></a>

## ATSC-MH delivery system

The following parameters are valid for ATSC-MH:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_BANDWIDTH_HZ](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-bandwidth-hz>)

- [DTV_ATSCMH_FIC_VER](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-fic-ver>)

- [DTV_ATSCMH_PARADE_ID](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-parade-id>)

- [DTV_ATSCMH_NOG](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-nog>)

- [DTV_ATSCMH_TNOG](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-tnog>)

- [DTV_ATSCMH_SGN](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sgn>)

- [DTV_ATSCMH_PRC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-prc>)

- [DTV_ATSCMH_RS_FRAME_MODE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-rs-frame-mode>)

- [DTV_ATSCMH_RS_FRAME_ENSEMBLE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-rs-frame-ensemble>)

- [DTV_ATSCMH_RS_CODE_MODE_PRI](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-rs-code-mode-pri>)

- [DTV_ATSCMH_RS_CODE_MODE_SEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-rs-code-mode-sec>)

- [DTV_ATSCMH_SCCC_BLOCK_MODE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-block-mode>)

- [DTV_ATSCMH_SCCC_CODE_MODE_A](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-code-mode-a>)

- [DTV_ATSCMH_SCCC_CODE_MODE_B](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-code-mode-b>)

- [DTV_ATSCMH_SCCC_CODE_MODE_C](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-code-mode-c>)

- [DTV_ATSCMH_SCCC_CODE_MODE_D](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-code-mode-d>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

<a id="rst-dtmb-delivery-system"></a>
<a id="rst-dtmb-params"></a>

## DTMB delivery system

The following parameters are valid for DTMB:

- [DTV_API_VERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version>)

- [DTV_DELIVERY_SYSTEM](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system>)

- [DTV_TUNE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune>)

- [DTV_CLEAR](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear>)

- [DTV_FREQUENCY](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency>)

- [DTV_MODULATION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation>)

- [DTV_BANDWIDTH_HZ](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-bandwidth-hz>)

- [DTV_INVERSION](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion>)

- [DTV_INNER_FEC](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inner-fec>)

- [DTV_GUARD_INTERVAL](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-guard-interval>)

- [DTV_TRANSMISSION_MODE](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-transmission-mode>)

- [DTV_INTERLEAVING](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-interleaving>)

- [DTV_LNA](</kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-lna>)

In addition, the [DTV QoS statistics](</kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-frontend-stat-properties>) are also valid.

---

# Frontend statistics indicators

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The values are returned via dtv_property.stat. If the property is supported, dtv_property.stat.len is bigger than zero.

<a id="rst-frontend-statistics-indicators"></a>
<a id="rst-frontend-stat-properties"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The values are returned via `dtv_property.stat`. If the property is supported, `dtv_property.stat.len` is bigger than zero.

For most delivery systems, `dtv_property.stat.len` will be 1 if the stats is supported, and the properties will return a single value for each parameter.

It should be noted, however, that new OFDM delivery systems like ISDB can use different modulation types for each group of carriers. On such standards, up to 3 groups of statistics can be provided, and `dtv_property.stat.len` is updated to reflect the "global" metrics, plus one metric per each carrier group (called "layer" on ISDB).

So, in order to be consistent with other delivery systems, the first value at `dtv_property.stat.dtv_stats <dtv_stats>` array refers to the global metric. The other elements of the array represent each layer, starting from layer A(index 1), layer B (index 2) and so on.

The number of filled elements are stored at `dtv_property.stat.len`.

Each element of the `dtv_property.stat.dtv_stats` array consists on two elements:

- `svalue` or `uvalue`, where `svalue` is for signed values of the measure (dB measures) and `uvalue` is for unsigned values (counters, relative scale)

- `scale` - Scale for the value. It can be:

  - `FE_SCALE_NOT_AVAILABLE` - The parameter is supported by the frontend, but it was not possible to collect it (could be a transitory or permanent condition)

  - `FE_SCALE_DECIBEL` - parameter is a signed value, measured in 1/1000 dB

  - `FE_SCALE_RELATIVE` - parameter is a unsigned value, where 0 means 0% and 65535 means 100%.

  - `FE_SCALE_COUNTER` - parameter is a unsigned value that counts the occurrence of an event, like bit error, block error, or lapsed time.

<a id="rst-dtv-stat-signal-strength-1"></a>
<a id="rst-dtv-stat-signal-strength"></a>

## DTV_STAT_SIGNAL_STRENGTH

Indicates the signal strength level at the analog part of the tuner or of the demod.

Possible scales for this metric are:

- `FE_SCALE_NOT_AVAILABLE` - it failed to measure it, or the measurement was not complete yet.

- `FE_SCALE_DECIBEL` - signal strength is in 0.001 dBm units, power measured in miliwatts. This value is generally negative.

- `FE_SCALE_RELATIVE` - The frontend provides a 0% to 100% measurement for power (actually, 0 to 65535).

<a id="rst-dtv-stat-cnr-1"></a>
<a id="rst-dtv-stat-cnr"></a>

## DTV_STAT_CNR

Indicates the Signal to Noise ratio for the main carrier.

Possible scales for this metric are:

- `FE_SCALE_NOT_AVAILABLE` - it failed to measure it, or the measurement was not complete yet.

- `FE_SCALE_DECIBEL` - Signal/Noise ratio is in 0.001 dB units.

- `FE_SCALE_RELATIVE` - The frontend provides a 0% to 100% measurement for Signal/Noise (actually, 0 to 65535).

<a id="rst-dtv-stat-pre-error-bit-count-1"></a>
<a id="rst-dtv-stat-pre-error-bit-count"></a>

## DTV_STAT_PRE_ERROR_BIT_COUNT

Measures the number of bit errors before the forward error correction (FEC) on the inner coding block (before Viterbi, LDPC or other inner code).

This measure is taken during the same interval as `DTV_STAT_PRE_TOTAL_BIT_COUNT`.

In order to get the BER (Bit Error Rate) measurement, it should be divided by [DTV_STAT_PRE_TOTAL_BIT_COUNT](<#rst-dtv-stat-pre-total-bit-count>).

This measurement is monotonically increased, as the frontend gets more bit count measurements. The frontend may reset it when a channel/transponder is tuned.

Possible scales for this metric are:

- `FE_SCALE_NOT_AVAILABLE` - it failed to measure it, or the measurement was not complete yet.

- `FE_SCALE_COUNTER` - Number of error bits counted before the inner coding.

<a id="rst-dtv-stat-pre-total-bit-count-1"></a>
<a id="rst-dtv-stat-pre-total-bit-count"></a>

## DTV_STAT_PRE_TOTAL_BIT_COUNT

Measures the amount of bits received before the inner code block, during the same period as [DTV_STAT_PRE_ERROR_BIT_COUNT](<#rst-dtv-stat-pre-error-bit-count>) measurement was taken.

It should be noted that this measurement can be smaller than the total amount of bits on the transport stream, as the frontend may need to manually restart the measurement, losing some data between each measurement interval.

This measurement is monotonically increased, as the frontend gets more bit count measurements. The frontend may reset it when a channel/transponder is tuned.

Possible scales for this metric are:

- `FE_SCALE_NOT_AVAILABLE` - it failed to measure it, or the measurement was not complete yet.

- `FE_SCALE_COUNTER` - Number of bits counted while measuring [DTV_STAT_PRE_ERROR_BIT_COUNT](<#rst-dtv-stat-pre-error-bit-count>).

<a id="rst-dtv-stat-post-error-bit-count-1"></a>
<a id="rst-dtv-stat-post-error-bit-count"></a>

## DTV_STAT_POST_ERROR_BIT_COUNT

Measures the number of bit errors after the forward error correction (FEC) done by inner code block (after Viterbi, LDPC or other inner code).

This measure is taken during the same interval as `DTV_STAT_POST_TOTAL_BIT_COUNT`.

In order to get the BER (Bit Error Rate) measurement, it should be divided by [DTV_STAT_POST_TOTAL_BIT_COUNT](<#rst-dtv-stat-post-total-bit-count>).

This measurement is monotonically increased, as the frontend gets more bit count measurements. The frontend may reset it when a channel/transponder is tuned.

Possible scales for this metric are:

- `FE_SCALE_NOT_AVAILABLE` - it failed to measure it, or the measurement was not complete yet.

- `FE_SCALE_COUNTER` - Number of error bits counted after the inner coding.

<a id="rst-dtv-stat-post-total-bit-count-1"></a>
<a id="rst-dtv-stat-post-total-bit-count"></a>

## DTV_STAT_POST_TOTAL_BIT_COUNT

Measures the amount of bits received after the inner coding, during the same period as [DTV_STAT_POST_ERROR_BIT_COUNT](<#rst-dtv-stat-post-error-bit-count>) measurement was taken.

It should be noted that this measurement can be smaller than the total amount of bits on the transport stream, as the frontend may need to manually restart the measurement, losing some data between each measurement interval.

This measurement is monotonically increased, as the frontend gets more bit count measurements. The frontend may reset it when a channel/transponder is tuned.

Possible scales for this metric are:

- `FE_SCALE_NOT_AVAILABLE` - it failed to measure it, or the measurement was not complete yet.

- `FE_SCALE_COUNTER` - Number of bits counted while measuring [DTV_STAT_POST_ERROR_BIT_COUNT](<#rst-dtv-stat-post-error-bit-count>).

<a id="rst-dtv-stat-error-block-count-1"></a>
<a id="rst-dtv-stat-error-block-count"></a>

## DTV_STAT_ERROR_BLOCK_COUNT

Measures the number of block errors after the outer forward error correction coding (after Reed-Solomon or other outer code).

This measurement is monotonically increased, as the frontend gets more bit count measurements. The frontend may reset it when a channel/transponder is tuned.

Possible scales for this metric are:

- `FE_SCALE_NOT_AVAILABLE` - it failed to measure it, or the measurement was not complete yet.

- `FE_SCALE_COUNTER` - Number of error blocks counted after the outer coding.

<a id="rst-dtv-stat-total-block-count-1"></a>
<a id="rst-dtv-stat-total-block-count"></a>

## DTV-STAT_TOTAL_BLOCK_COUNT

Measures the total number of blocks received during the same period as [DTV_STAT_ERROR_BLOCK_COUNT](<#rst-dtv-stat-error-block-count>) measurement was taken.

It can be used to calculate the PER indicator, by dividing [DTV_STAT_ERROR_BLOCK_COUNT](<#rst-dtv-stat-error-block-count>) by [DTV-STAT_TOTAL_BLOCK_COUNT](<#rst-dtv-stat-total-block-count>).

Possible scales for this metric are:

- `FE_SCALE_NOT_AVAILABLE` - it failed to measure it, or the measurement was not complete yet.

- `FE_SCALE_COUNTER` - Number of blocks counted while measuring [DTV_STAT_ERROR_BLOCK_COUNT](<#rst-dtv-stat-error-block-count>).

---

# Digital TV Frontend API

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The Digital TV frontend API was designed to support three groups of delivery systems: Terrestrial, cable and Satellite. Currently, the following delivery systems are supported:

<a id="rst-digital-tv-frontend-api"></a>
<a id="rst-dvb-frontend"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The Digital TV frontend API was designed to support three groups of delivery systems: Terrestrial, cable and Satellite. Currently, the following delivery systems are supported:

- Terrestrial systems: DVB-T, DVB-T2, ATSC, ATSC M/H, ISDB-T, DVB-H, DTMB, CMMB

- Cable systems: DVB-C Annex A/C, ClearQAM (DVB-C Annex B)

- Satellite systems: DVB-S, DVB-S2, DVB Turbo, ISDB-S, DSS

The Digital TV frontend controls several sub-devices including:

- Tuner

- Digital TV demodulator

- Low noise amplifier (LNA)

- Satellite Equipment Control (SEC) <a id="rst-footnote-reference-1"></a>[1](#rst-f1).

The frontend can be accessed through `/dev/dvb/adapter?/frontend?`. Data types and ioctl definitions can be accessed by including `linux/dvb/frontend.h` in your application.

> [!NOTE]
>
> Transmission via the internet (DVB-IP) and MMT (MPEG Media Transport) is not yet handled by this API but a future extension is possible.

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



**[1]** On Satellite systems, the API support for the Satellite Equipment Control (SEC) allows to power control and to send/receive signals to control the antenna subsystem, selecting the polarization and choosing the Intermediate Frequency IF) of the Low Noise Block Converter Feed Horn (LNBf). It supports the DiSEqC and V-SEC protocols. The DiSEqC (digital SEC) specification is available at [Eutelsat](<http://www.eutelsat.com/satellites/4_5_5.html>).

- [Querying frontend information](</kernel/userspace/userspace-api/media-dvb/query-dvb-frontend-info.md>)
- [Querying frontend status and statistics](</kernel/userspace/userspace-api/media-dvb/dvb-fe-read-status.md>)
- [dvbproperty](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/dvb/dvbproperty.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Frontend Function Calls](</kernel/userspace/userspace-api/media-dvb/frontend-fcalls.md>)

---

# Digital TV frontend close()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> fe-close - Close a frontend device

<a id="rst-digital-tv-frontend-close"></a>
<a id="rst-frontend-f-close"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

fe-close - Close a frontend device

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-close"></a>

```c
int close( int fd )
```

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

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

## Description

This system call closes a previously opened front-end device. After closing a front-end device, its corresponding hardware might be powered down automatically.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned.

On error -1 is returned, and the `errno` variable is set appropriately.

Generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Digital TV frontend open()

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> fe-open - Open a frontend device

<a id="rst-digital-tv-frontend-open"></a>
<a id="rst-frontend-f-open"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.fe -->

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

## Name

fe-open - Open a frontend device

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

## Synopsis



```c
#include <fcntl.h>
```





<a id="c-open"></a>

```c
int open( const char *device_name, int flags )
```

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

## Arguments

- **`device_name`**

  Device to be opened.

- **`flags`**

  Open flags. Access can either be `O_RDWR` or `O_RDONLY`.

  Multiple opens are allowed with `O_RDONLY`. In this mode, only query and read ioctls are allowed.

  Only one open is allowed in `O_RDWR`. In this mode, all ioctls are allowed.

  When the `O_NONBLOCK` flag is given, the system calls may return `EAGAIN` error code when no data is available or when the device driver is temporarily busy.

  Other flags have no effect.

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

## Description

This system call opens a named frontend device (`/dev/dvb/adapter?/frontend?`) for subsequent use. Usually the first thing to do after a successful open is to find out the frontend type with [ioctl FE_GET_INFO](</kernel/userspace/userspace-api/media-dvb/fe-get-info.md#rst-fe-get-info>).

The device can be opened in read-only mode, which only allows monitoring of device status and statistics, or read/write mode, which allows any kind of use (e.g. performing tuning operations.)

In a system with multiple front-ends, it is usually the case that multiple devices cannot be open in read/write mode simultaneously. As long as a front-end device is opened in read/write mode, other open() calls in read/write mode will either fail or block, depending on whether non-blocking or blocking mode was specified. A front-end device opened in blocking mode can later be put into non-blocking mode (and vice versa) using the F_SETFL command of the fcntl system call. This is a standard system call, documented in the Linux manual page for fcntl. When an open() call has succeeded, the device will be ready for use in the specified mode. This implies that the corresponding hardware is powered up, and that other front-ends may have been powered down to make that possible.

<a id="rst-return-value"></a>

## Return Value

On success `open()` returns the new file descriptor. On error, -1 is returned, and the `errno` variable is set appropriately.

Possible error codes are:

On success 0 is returned, and `ca_slot_info` is filled.

On error -1 is returned, and the `errno` variable is set appropriately.

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`EPERM`

</td>
<td>


The caller has no permission to access the device.

</td>
</tr>
<tr>
<td>


`EBUSY`

</td>
<td>


The device driver is already in use.

</td>
</tr>
<tr>
<td>


`EMFILE`

</td>
<td>


The process already has the maximum number of files open.

</td>
</tr>
<tr>
<td>


`ENFILE`

</td>
<td>


The limit on the total number of files open on the system has been reached.

</td>
</tr>
</tbody>
</table>

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Frontend Function Calls

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for Frontend Function Calls.

<a id="rst-frontend-function-calls"></a>
<a id="rst-frontend-fcalls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

- [Digital TV frontend open()](</kernel/userspace/userspace-api/media-dvb/frontend-f-open.md>)
- [Digital TV frontend close()](</kernel/userspace/userspace-api/media-dvb/frontend-f-close.md>)
- [ioctl FE_GET_INFO](</kernel/userspace/userspace-api/media-dvb/fe-get-info.md>)
- [ioctl FE_READ_STATUS](</kernel/userspace/userspace-api/media-dvb/fe-read-status.md>)
- [ioctl FE_SET_PROPERTY, FE_GET_PROPERTY](</kernel/userspace/userspace-api/media-dvb/fe-get-property.md>)
- [ioctl FE_DISEQC_RESET_OVERLOAD](</kernel/userspace/userspace-api/media-dvb/fe-diseqc-reset-overload.md>)
- [ioctl FE_DISEQC_SEND_MASTER_CMD](</kernel/userspace/userspace-api/media-dvb/fe-diseqc-send-master-cmd.md>)
- [ioctl FE_DISEQC_RECV_SLAVE_REPLY](</kernel/userspace/userspace-api/media-dvb/fe-diseqc-recv-slave-reply.md>)
- [ioctl FE_DISEQC_SEND_BURST](</kernel/userspace/userspace-api/media-dvb/fe-diseqc-send-burst.md>)
- [ioctl FE_SET_TONE](</kernel/userspace/userspace-api/media-dvb/fe-set-tone.md>)
- [ioctl FE_SET_VOLTAGE](</kernel/userspace/userspace-api/media-dvb/fe-set-voltage.md>)
- [ioctl FE_ENABLE_HIGH_LNB_VOLTAGE](</kernel/userspace/userspace-api/media-dvb/fe-enable-high-lnb-voltage.md>)
- [ioctl FE_SET_FRONTEND_TUNE_MODE](</kernel/userspace/userspace-api/media-dvb/fe-set-frontend-tune-mode.md>)

---

# Frontend Legacy Data Types

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Those functions are defined at DVB version 3. The support is kept in the kernel due to compatibility issues only. Their usage is strongly not recommended

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<a id="rst-frontend-legacy-data-types"></a>
<a id="rst-frontend-legacy-types"></a>

## Frontend Legacy Data Types

- [Frontend type](</kernel/userspace/userspace-api/media-dvb/fe-type-t.md>)
- [Frontend bandwidth](</kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md>)
- [frontend parameters](</kernel/userspace/userspace-api/media-dvb/dvb-frontend-parameters.md>)
- [frontend events](</kernel/userspace/userspace-api/media-dvb/dvb-frontend-event.md>)

<a id="rst-frontend-legacy-function-calls"></a>
<a id="rst-frontend-legacy-fcalls"></a>

## Frontend Legacy Function Calls

Those functions are defined at DVB version 3. The support is kept in the kernel due to compatibility issues only. Their usage is strongly not recommended

- [FE_READ_BER](</kernel/userspace/userspace-api/media-dvb/fe-read-ber.md>)
- [FE_READ_SNR](</kernel/userspace/userspace-api/media-dvb/fe-read-snr.md>)
- [FE_READ_SIGNAL_STRENGTH](</kernel/userspace/userspace-api/media-dvb/fe-read-signal-strength.md>)
- [FE_READ_UNCORRECTED_BLOCKS](</kernel/userspace/userspace-api/media-dvb/fe-read-uncorrected-blocks.md>)
- [FE_SET_FRONTEND](</kernel/userspace/userspace-api/media-dvb/fe-set-frontend.md>)
- [FE_GET_FRONTEND](</kernel/userspace/userspace-api/media-dvb/fe-get-frontend.md>)
- [FE_GET_EVENT](</kernel/userspace/userspace-api/media-dvb/fe-get-event.md>)
- [FE_DISHNETWORK_SEND_LEGACY_CMD](</kernel/userspace/userspace-api/media-dvb/fe-dishnetwork-send-legacy-cmd.md>)

---

# Digital TV Frontend legacy API (a. k. a. DVBv3)

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The usage of this API is deprecated, as it doesn't support all digital TV standards, doesn't provide good statistics measurements and provides incomplete information. This is kept only to support legacy applications.

<a id="rst-digital-tv-frontend-legacy-api-a-k-a-dvbv3"></a>
<a id="rst-frontend-legacy-dvbv3-api"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The usage of this API is deprecated, as it doesn't support all digital TV standards, doesn't provide good statistics measurements and provides incomplete information. This is kept only to support legacy applications.

- [Frontend Legacy Data Types](</kernel/userspace/userspace-api/media-dvb/frontend-legacy-api.md>)

---

# Digital TV uAPI symbols

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Frontend

<a id="rst-digital-tv-uapi-symbols"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<a id="rst-table-of-contents"></a>



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

## Frontend


## Enumeration values

- [`BANDWIDTH_10_MHZ`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#rst-bandwidth-10-mhz): `include/uapi/linux/dvb/frontend.h`, line 987
- [`BANDWIDTH_1_712_MHZ`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#rst-bandwidth-1-712-mhz): `include/uapi/linux/dvb/frontend.h`, line 988
- [`BANDWIDTH_5_MHZ`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#rst-bandwidth-5-mhz): `include/uapi/linux/dvb/frontend.h`, line 986
- [`BANDWIDTH_6_MHZ`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#rst-bandwidth-6-mhz): `include/uapi/linux/dvb/frontend.h`, line 984
- [`BANDWIDTH_7_MHZ`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#rst-bandwidth-7-mhz): `include/uapi/linux/dvb/frontend.h`, line 983
- [`BANDWIDTH_8_MHZ`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#rst-bandwidth-8-mhz): `include/uapi/linux/dvb/frontend.h`, line 982
- [`BANDWIDTH_AUTO`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#rst-bandwidth-auto): `include/uapi/linux/dvb/frontend.h`, line 985
- [`FE_ATSC`](/kernel/userspace/userspace-api/media-dvb/fe-type-t.md#rst-fe-atsc): `include/uapi/linux/dvb/frontend.h`, line 98
- [`FE_OFDM`](/kernel/userspace/userspace-api/media-dvb/fe-type-t.md#rst-fe-ofdm): `include/uapi/linux/dvb/frontend.h`, line 97
- [`FE_QAM`](/kernel/userspace/userspace-api/media-dvb/fe-type-t.md#rst-fe-qam): `include/uapi/linux/dvb/frontend.h`, line 96
- [`FE_QPSK`](/kernel/userspace/userspace-api/media-dvb/fe-type-t.md#rst-fe-qpsk): `include/uapi/linux/dvb/frontend.h`, line 95

## Enumerations

- [`atscmh_rs_code_mode`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-atscmh_rs_code_mode): `include/uapi/linux/dvb/frontend.h`, line 778
- [`atscmh_rs_frame_ensemble`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-atscmh_rs_frame_ensemble): `include/uapi/linux/dvb/frontend.h`, line 747
- [`atscmh_rs_frame_mode`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-atscmh_rs_frame_mode): `include/uapi/linux/dvb/frontend.h`, line 765
- [`atscmh_sccc_block_mode`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-atscmh_sccc_block_mode): `include/uapi/linux/dvb/frontend.h`, line 718
- [`atscmh_sccc_code_mode`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-atscmh_sccc_code_mode): `include/uapi/linux/dvb/frontend.h`, line 735
- [`fe_bandwidth`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#c-fe_bandwidth): `include/uapi/linux/dvb/frontend.h`, line 981
- [`fe_caps`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_caps): `include/uapi/linux/dvb/frontend.h`, line 57
- [`fe_code_rate`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_code_rate): `include/uapi/linux/dvb/frontend.h`, line 306
- [`fe_delivery_system`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_delivery_system): `include/uapi/linux/dvb/frontend.h`, line 676
- [`fe_guard_interval`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_guard_interval): `include/uapi/linux/dvb/frontend.h`, line 449
- [`fe_hierarchy`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_hierarchy): `include/uapi/linux/dvb/frontend.h`, line 474
- [`fe_interleaving`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_interleaving): `include/uapi/linux/dvb/frontend.h`, line 491
- [`fe_modulation`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_modulation): `include/uapi/linux/dvb/frontend.h`, line 369
- [`fe_pilot`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_pilot): `include/uapi/linux/dvb/frontend.h`, line 602
- [`fe_rolloff`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_rolloff): `include/uapi/linux/dvb/frontend.h`, line 622
- [`fe_sec_mini_cmd`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_sec_mini_cmd): `include/uapi/linux/dvb/frontend.h`, line 218
- [`fe_sec_tone_mode`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_sec_tone_mode): `include/uapi/linux/dvb/frontend.h`, line 205
- [`fe_sec_voltage`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_sec_voltage): `include/uapi/linux/dvb/frontend.h`, line 193
- [`fe_spectral_inversion`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_spectral_inversion): `include/uapi/linux/dvb/frontend.h`, line 261
- [`fe_status`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_status): `include/uapi/linux/dvb/frontend.h`, line 237
- [`fe_transmit_mode`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_transmit_mode): `include/uapi/linux/dvb/frontend.h`, line 419
- [`fe_type`](/kernel/userspace/userspace-api/media-dvb/fe-type-t.md#c-fe_type): `include/uapi/linux/dvb/frontend.h`, line 94
- [`fecap_scale_params`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fecap_scale_params): `include/uapi/linux/dvb/frontend.h`, line 801

## IOCTL Commands

- [`FE_DISEQC_RECV_SLAVE_REPLY`](/kernel/userspace/userspace-api/media-dvb/fe-diseqc-recv-slave-reply.md#rst-fe-diseqc-recv-slave-reply): `include/uapi/linux/dvb/frontend.h`, line 941
- [`FE_DISEQC_RESET_OVERLOAD`](/kernel/userspace/userspace-api/media-dvb/fe-diseqc-reset-overload.md#rst-fe-diseqc-reset-overload): `include/uapi/linux/dvb/frontend.h`, line 939
- [`FE_DISEQC_SEND_BURST`](/kernel/userspace/userspace-api/media-dvb/fe-diseqc-send-burst.md#rst-fe-diseqc-send-burst): `include/uapi/linux/dvb/frontend.h`, line 942
- [`FE_DISEQC_SEND_MASTER_CMD`](/kernel/userspace/userspace-api/media-dvb/fe-diseqc-send-master-cmd.md#rst-fe-diseqc-send-master-cmd): `include/uapi/linux/dvb/frontend.h`, line 940
- [`FE_DISHNETWORK_SEND_LEGACY_CMD`](/kernel/userspace/userspace-api/media-dvb/fe-dishnetwork-send-legacy-cmd.md#rst-fe-dishnetwork-send-legacy-cmd): `include/uapi/linux/dvb/frontend.h`, line 957
- [`FE_ENABLE_HIGH_LNB_VOLTAGE`](/kernel/userspace/userspace-api/media-dvb/fe-enable-high-lnb-voltage.md#rst-fe-enable-high-lnb-voltage): `include/uapi/linux/dvb/frontend.h`, line 946
- [`FE_GET_EVENT`](/kernel/userspace/userspace-api/media-dvb/fe-get-event.md#rst-fe-get-event): `include/uapi/linux/dvb/frontend.h`, line 955
- [`FE_GET_FRONTEND`](/kernel/userspace/userspace-api/media-dvb/fe-get-frontend.md#rst-fe-get-frontend): `include/uapi/linux/dvb/frontend.h`, line 1056
- [`FE_GET_INFO`](/kernel/userspace/userspace-api/media-dvb/fe-get-info.md#rst-fe-get-info): `include/uapi/linux/dvb/frontend.h`, line 937
- [`FE_GET_PROPERTY`](/kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property): `include/uapi/linux/dvb/frontend.h`, line 960
- [`FE_READ_BER`](/kernel/userspace/userspace-api/media-dvb/fe-read-ber.md#rst-fe-read-ber): `include/uapi/linux/dvb/frontend.h`, line 949
- [`FE_READ_SIGNAL_STRENGTH`](/kernel/userspace/userspace-api/media-dvb/fe-read-signal-strength.md#rst-fe-read-signal-strength): `include/uapi/linux/dvb/frontend.h`, line 950
- [`FE_READ_SNR`](/kernel/userspace/userspace-api/media-dvb/fe-read-snr.md#rst-fe-read-snr): `include/uapi/linux/dvb/frontend.h`, line 951
- [`FE_READ_STATUS`](/kernel/userspace/userspace-api/media-dvb/fe-read-status.md#rst-fe-read-status): `include/uapi/linux/dvb/frontend.h`, line 948
- [`FE_READ_UNCORRECTED_BLOCKS`](/kernel/userspace/userspace-api/media-dvb/fe-read-uncorrected-blocks.md#rst-fe-read-uncorrected-blocks): `include/uapi/linux/dvb/frontend.h`, line 952
- [`FE_SET_FRONTEND`](/kernel/userspace/userspace-api/media-dvb/fe-set-frontend.md#rst-fe-set-frontend): `include/uapi/linux/dvb/frontend.h`, line 1055
- [`FE_SET_FRONTEND_TUNE_MODE`](/kernel/userspace/userspace-api/media-dvb/fe-set-frontend-tune-mode.md#rst-fe-set-frontend-tune-mode): `include/uapi/linux/dvb/frontend.h`, line 954
- [`FE_SET_PROPERTY`](/kernel/userspace/userspace-api/media-dvb/fe-get-property.md#rst-fe-get-property): `include/uapi/linux/dvb/frontend.h`, line 959
- [`FE_SET_TONE`](/kernel/userspace/userspace-api/media-dvb/fe-set-tone.md#rst-fe-set-tone): `include/uapi/linux/dvb/frontend.h`, line 944
- [`FE_SET_VOLTAGE`](/kernel/userspace/userspace-api/media-dvb/fe-set-voltage.md#rst-fe-set-voltage): `include/uapi/linux/dvb/frontend.h`, line 945

## Macros and Definitions

- [`DTV_API_VERSION`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-api-version): `include/uapi/linux/dvb/frontend.h`, line 544
- [`DTV_ATSCMH_FIC_VER`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-fic-ver): `include/uapi/linux/dvb/frontend.h`, line 561
- [`DTV_ATSCMH_NOG`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-nog): `include/uapi/linux/dvb/frontend.h`, line 563
- [`DTV_ATSCMH_PARADE_ID`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-parade-id): `include/uapi/linux/dvb/frontend.h`, line 562
- [`DTV_ATSCMH_PRC`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-prc): `include/uapi/linux/dvb/frontend.h`, line 566
- [`DTV_ATSCMH_RS_CODE_MODE_PRI`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-rs-code-mode-pri): `include/uapi/linux/dvb/frontend.h`, line 569
- [`DTV_ATSCMH_RS_CODE_MODE_SEC`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-rs-code-mode-sec): `include/uapi/linux/dvb/frontend.h`, line 570
- [`DTV_ATSCMH_RS_FRAME_ENSEMBLE`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-rs-frame-ensemble): `include/uapi/linux/dvb/frontend.h`, line 568
- [`DTV_ATSCMH_RS_FRAME_MODE`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-rs-frame-mode): `include/uapi/linux/dvb/frontend.h`, line 567
- [`DTV_ATSCMH_SCCC_BLOCK_MODE`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-block-mode): `include/uapi/linux/dvb/frontend.h`, line 571
- [`DTV_ATSCMH_SCCC_CODE_MODE_A`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-code-mode-a): `include/uapi/linux/dvb/frontend.h`, line 572
- [`DTV_ATSCMH_SCCC_CODE_MODE_B`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-code-mode-b): `include/uapi/linux/dvb/frontend.h`, line 573
- [`DTV_ATSCMH_SCCC_CODE_MODE_C`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-code-mode-c): `include/uapi/linux/dvb/frontend.h`, line 574
- [`DTV_ATSCMH_SCCC_CODE_MODE_D`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sccc-code-mode-d): `include/uapi/linux/dvb/frontend.h`, line 575
- [`DTV_ATSCMH_SGN`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-sgn): `include/uapi/linux/dvb/frontend.h`, line 565
- [`DTV_ATSCMH_TNOG`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-atscmh-tnog): `include/uapi/linux/dvb/frontend.h`, line 564
- [`DTV_BANDWIDTH_HZ`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-bandwidth-hz): `include/uapi/linux/dvb/frontend.h`, line 505
- [`DTV_CLEAR`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-clear): `include/uapi/linux/dvb/frontend.h`, line 502
- [`DTV_CODE_RATE_HP`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-code-rate-hp): `include/uapi/linux/dvb/frontend.h`, line 546
- [`DTV_CODE_RATE_LP`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-code-rate-lp): `include/uapi/linux/dvb/frontend.h`, line 547
- [`DTV_DELIVERY_SYSTEM`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-delivery-system): `include/uapi/linux/dvb/frontend.h`, line 519
- [`DTV_DISEQC_MASTER`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-diseqc-master): `include/uapi/linux/dvb/frontend.h`, line 507
- [`DTV_DISEQC_SLAVE_REPLY`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-diseqc-slave-reply): `include/uapi/linux/dvb/frontend.h`, line 514
- [`DTV_DVBT2_PLP_ID_LEGACY`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-dvbt2-plp-id-legacy): `include/uapi/linux/dvb/frontend.h`, line 556
- [`DTV_ENUM_DELSYS`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-enum-delsys): `include/uapi/linux/dvb/frontend.h`, line 558
- [`DTV_FE_CAPABILITY`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-fe-capability): `include/uapi/linux/dvb/frontend.h`, line 518
- [`DTV_FE_CAPABILITY_COUNT`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-fe-capability-count): `include/uapi/linux/dvb/frontend.h`, line 517
- [`DTV_FREQUENCY`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-frequency): `include/uapi/linux/dvb/frontend.h`, line 503
- [`DTV_GUARD_INTERVAL`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-guard-interval): `include/uapi/linux/dvb/frontend.h`, line 548
- [`DTV_HIERARCHY`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-hierarchy): `include/uapi/linux/dvb/frontend.h`, line 550
- [`DTV_INNER_FEC`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inner-fec): `include/uapi/linux/dvb/frontend.h`, line 509
- [`DTV_INTERLEAVING`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-interleaving): `include/uapi/linux/dvb/frontend.h`, line 577
- [`DTV_INVERSION`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-inversion): `include/uapi/linux/dvb/frontend.h`, line 506
- [`DTV_ISDBT_LAYERA_FEC`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-fec): `include/uapi/linux/dvb/frontend.h`, line 529
- [`DTV_ISDBT_LAYERA_MODULATION`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-modulation): `include/uapi/linux/dvb/frontend.h`, line 530
- [`DTV_ISDBT_LAYERA_SEGMENT_COUNT`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-segment-count): `include/uapi/linux/dvb/frontend.h`, line 531
- [`DTV_ISDBT_LAYERA_TIME_INTERLEAVING`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-time-interleaving): `include/uapi/linux/dvb/frontend.h`, line 532
- [`DTV_ISDBT_LAYERB_FEC`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-fec): `include/uapi/linux/dvb/frontend.h`, line 534
- [`DTV_ISDBT_LAYERB_MODULATION`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-modulation): `include/uapi/linux/dvb/frontend.h`, line 535
- [`DTV_ISDBT_LAYERB_SEGMENT_COUNT`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-segment-count): `include/uapi/linux/dvb/frontend.h`, line 536
- [`DTV_ISDBT_LAYERB_TIME_INTERLEAVING`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-time-interleaving): `include/uapi/linux/dvb/frontend.h`, line 537
- [`DTV_ISDBT_LAYERC_FEC`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-fec): `include/uapi/linux/dvb/frontend.h`, line 539
- [`DTV_ISDBT_LAYERC_MODULATION`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-modulation): `include/uapi/linux/dvb/frontend.h`, line 540
- [`DTV_ISDBT_LAYERC_SEGMENT_COUNT`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-segment-count): `include/uapi/linux/dvb/frontend.h`, line 541
- [`DTV_ISDBT_LAYERC_TIME_INTERLEAVING`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-time-interleaving): `include/uapi/linux/dvb/frontend.h`, line 542
- [`DTV_ISDBT_LAYER_ENABLED`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-layer-enabled): `include/uapi/linux/dvb/frontend.h`, line 552
- [`DTV_ISDBT_PARTIAL_RECEPTION`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-partial-reception): `include/uapi/linux/dvb/frontend.h`, line 522
- [`DTV_ISDBT_SB_SEGMENT_COUNT`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-sb-segment-count): `include/uapi/linux/dvb/frontend.h`, line 527
- [`DTV_ISDBT_SB_SEGMENT_IDX`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-sb-segment-idx): `include/uapi/linux/dvb/frontend.h`, line 526
- [`DTV_ISDBT_SB_SUBCHANNEL_ID`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-sb-subchannel-id): `include/uapi/linux/dvb/frontend.h`, line 525
- [`DTV_ISDBT_SOUND_BROADCASTING`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-isdbt-sound-broadcasting): `include/uapi/linux/dvb/frontend.h`, line 523
- [`DTV_LNA`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-lna): `include/uapi/linux/dvb/frontend.h`, line 578
- [`DTV_MODULATION`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-modulation): `include/uapi/linux/dvb/frontend.h`, line 504
- [`DTV_PILOT`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-pilot): `include/uapi/linux/dvb/frontend.h`, line 512
- [`DTV_ROLLOFF`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-rolloff): `include/uapi/linux/dvb/frontend.h`, line 513
- [`DTV_SCRAMBLING_SEQUENCE_INDEX`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-scrambling-sequence-index): `include/uapi/linux/dvb/frontend.h`, line 591
- [`DTV_STAT_CNR`](/kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-dtv-stat-cnr): `include/uapi/linux/dvb/frontend.h`, line 582
- [`DTV_STAT_ERROR_BLOCK_COUNT`](/kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-dtv-stat-error-block-count): `include/uapi/linux/dvb/frontend.h`, line 587
- [`DTV_STAT_POST_ERROR_BIT_COUNT`](/kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-dtv-stat-post-error-bit-count): `include/uapi/linux/dvb/frontend.h`, line 585
- [`DTV_STAT_POST_TOTAL_BIT_COUNT`](/kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-dtv-stat-post-total-bit-count): `include/uapi/linux/dvb/frontend.h`, line 586
- [`DTV_STAT_PRE_ERROR_BIT_COUNT`](/kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-dtv-stat-pre-error-bit-count): `include/uapi/linux/dvb/frontend.h`, line 583
- [`DTV_STAT_PRE_TOTAL_BIT_COUNT`](/kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-dtv-stat-pre-total-bit-count): `include/uapi/linux/dvb/frontend.h`, line 584
- [`DTV_STAT_SIGNAL_STRENGTH`](/kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-dtv-stat-signal-strength): `include/uapi/linux/dvb/frontend.h`, line 581
- [`DTV_STAT_TOTAL_BLOCK_COUNT`](/kernel/userspace/userspace-api/media-dvb/frontend-stat-properties.md#rst-dtv-stat-total-block-count): `include/uapi/linux/dvb/frontend.h`, line 588
- [`DTV_STREAM_ID`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-stream-id): `include/uapi/linux/dvb/frontend.h`, line 554
- [`DTV_SYMBOL_RATE`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-symbol-rate): `include/uapi/linux/dvb/frontend.h`, line 508
- [`DTV_TONE`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tone): `include/uapi/linux/dvb/frontend.h`, line 511
- [`DTV_TRANSMISSION_MODE`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-transmission-mode): `include/uapi/linux/dvb/frontend.h`, line 549
- [`DTV_TUNE`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-tune): `include/uapi/linux/dvb/frontend.h`, line 501
- [`DTV_UNDEFINED`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-undefined): `include/uapi/linux/dvb/frontend.h`, line 500
- [`DTV_VOLTAGE`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-voltage): `include/uapi/linux/dvb/frontend.h`, line 510
- [`FE_TUNE_MODE_ONESHOT`](/kernel/userspace/userspace-api/media-dvb/fe-set-frontend-tune-mode.md#rst-fe-set-frontend-tune-mode): `include/uapi/linux/dvb/frontend.h`, line 933
- [`LNA_AUTO`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-lna): `include/uapi/linux/dvb/frontend.h`, line 786
- [`NO_STREAM_ID_FILTER`](/kernel/userspace/userspace-api/media-dvb/fe-property-parameters.md#rst-dtv-stream-id): `include/uapi/linux/dvb/frontend.h`, line 785

## Structures

- [`dtv_fe_stats`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-struct-dtv_fe_stats): `include/uapi/linux/dvb/frontend.h`, line 874
- [`dtv_properties`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-struct-dtv_properties): `include/uapi/linux/dvb/frontend.h`, line 921
- [`dtv_property`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-struct-dtv_property): `include/uapi/linux/dvb/frontend.h`, line 896
- [`dtv_stats`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-struct-dtv_stats): `include/uapi/linux/dvb/frontend.h`, line 852
- [`dvb_diseqc_master_cmd`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-struct-dvb_diseqc_master_cmd): `include/uapi/linux/dvb/frontend.h`, line 158
- [`dvb_diseqc_slave_reply`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-struct-dvb_diseqc_slave_reply): `include/uapi/linux/dvb/frontend.h`, line 180
- [`dvb_frontend_event`](/kernel/userspace/userspace-api/media-dvb/dvb-frontend-event.md#c-dvb_frontend_event): `include/uapi/linux/dvb/frontend.h`, line 1048
- [`dvb_frontend_info`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-struct-dvb_frontend_info): `include/uapi/linux/dvb/frontend.h`, line 131
- [`dvb_frontend_parameters`](/kernel/userspace/userspace-api/media-dvb/dvb-frontend-parameters.md#c-dvb_frontend_parameters): `include/uapi/linux/dvb/frontend.h`, line 1036
- [`dvb_ofdm_parameters`](/kernel/userspace/userspace-api/media-dvb/dvb-frontend-parameters.md#c-dvb_ofdm_parameters): `include/uapi/linux/dvb/frontend.h`, line 1026
- [`dvb_qam_parameters`](/kernel/userspace/userspace-api/media-dvb/dvb-frontend-parameters.md#c-dvb_qam_parameters): `include/uapi/linux/dvb/frontend.h`, line 1016
- [`dvb_qpsk_parameters`](/kernel/userspace/userspace-api/media-dvb/dvb-frontend-parameters.md#c-dvb_qpsk_parameters): `include/uapi/linux/dvb/frontend.h`, line 1011
- [`dvb_vsb_parameters`](/kernel/userspace/userspace-api/media-dvb/dvb-frontend-parameters.md#c-dvb_vsb_parameters): `include/uapi/linux/dvb/frontend.h`, line 1022

## Type Definitions

- [`fe_bandwidth_t`](/kernel/userspace/userspace-api/media-dvb/fe-bandwidth-t.md#c-fe_bandwidth): `include/uapi/linux/dvb/frontend.h`, line 1002
- [`fe_caps_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_caps): `include/uapi/linux/dvb/frontend.h`, line 993
- [`fe_code_rate_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_code_rate): `include/uapi/linux/dvb/frontend.h`, line 999
- [`fe_delivery_system_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_delivery_system): `include/uapi/linux/dvb/frontend.h`, line 1007
- [`fe_guard_interval_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_guard_interval): `include/uapi/linux/dvb/frontend.h`, line 1003
- [`fe_hierarchy_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_hierarchy): `include/uapi/linux/dvb/frontend.h`, line 1004
- [`fe_modulation_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_modulation): `include/uapi/linux/dvb/frontend.h`, line 1000
- [`fe_pilot_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_pilot): `include/uapi/linux/dvb/frontend.h`, line 1005
- [`fe_rolloff_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_rolloff): `include/uapi/linux/dvb/frontend.h`, line 1006
- [`fe_sec_mini_cmd_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_sec_mini_cmd): `include/uapi/linux/dvb/frontend.h`, line 996
- [`fe_sec_tone_mode_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_sec_tone_mode): `include/uapi/linux/dvb/frontend.h`, line 995
- [`fe_sec_voltage_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_sec_voltage): `include/uapi/linux/dvb/frontend.h`, line 992
- [`fe_spectral_inversion_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_spectral_inversion): `include/uapi/linux/dvb/frontend.h`, line 998
- [`fe_status_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_status): `include/uapi/linux/dvb/frontend.h`, line 997
- [`fe_transmit_mode_t`](/kernel/userspace/userspace-api/media-dvb/frontend-header.md#c-enum-fe_transmit_mode): `include/uapi/linux/dvb/frontend.h`, line 1001
- [`fe_type_t`](/kernel/userspace/userspace-api/media-dvb/fe-type-t.md#c-fe_type): `include/uapi/linux/dvb/frontend.h`, line 994


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

## Demux


## Enumeration values

- [`DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_buffer_flags): `include/uapi/linux/dvb/dmx.h`, line 221
- [`DMX_BUFFER_FLAG_DISCONTINUITY_INDICATOR`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_buffer_flags): `include/uapi/linux/dvb/dmx.h`, line 222
- [`DMX_BUFFER_FLAG_HAD_CRC32_DISCARD`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_buffer_flags): `include/uapi/linux/dvb/dmx.h`, line 218
- [`DMX_BUFFER_FLAG_TEI`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_buffer_flags): `include/uapi/linux/dvb/dmx.h`, line 219
- [`DMX_BUFFER_PKT_COUNTER_MISMATCH`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_buffer_flags): `include/uapi/linux/dvb/dmx.h`, line 220
- [`DMX_IN_DVR`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_input): `include/uapi/linux/dvb/dmx.h`, line 54
- [`DMX_IN_FRONTEND`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_input): `include/uapi/linux/dvb/dmx.h`, line 53
- [`DMX_OUT_DECODER`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_output): `include/uapi/linux/dvb/dmx.h`, line 39
- [`DMX_OUT_TAP`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_output): `include/uapi/linux/dvb/dmx.h`, line 40
- [`DMX_OUT_TSDEMUX_TAP`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_output): `include/uapi/linux/dvb/dmx.h`, line 42
- [`DMX_OUT_TS_TAP`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_output): `include/uapi/linux/dvb/dmx.h`, line 41
- [`DMX_PES_AUDIO0`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 89
- [`DMX_PES_AUDIO1`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 95
- [`DMX_PES_AUDIO2`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 101
- [`DMX_PES_AUDIO3`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 107
- [`DMX_PES_OTHER`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 113
- [`DMX_PES_PCR0`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 93
- [`DMX_PES_PCR1`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 99
- [`DMX_PES_PCR2`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 105
- [`DMX_PES_PCR3`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 111
- [`DMX_PES_SUBTITLE0`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 92
- [`DMX_PES_SUBTITLE1`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 98
- [`DMX_PES_SUBTITLE2`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 104
- [`DMX_PES_SUBTITLE3`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 110
- [`DMX_PES_TELETEXT0`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 91
- [`DMX_PES_TELETEXT1`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 97
- [`DMX_PES_TELETEXT2`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 103
- [`DMX_PES_TELETEXT3`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 109
- [`DMX_PES_VIDEO0`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 90
- [`DMX_PES_VIDEO1`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 96
- [`DMX_PES_VIDEO2`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 102
- [`DMX_PES_VIDEO3`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 108

## Enumerations

- [`dmx_buffer_flags`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_buffer_flags): `include/uapi/linux/dvb/dmx.h`, line 217
- [`dmx_input`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_input): `include/uapi/linux/dvb/dmx.h`, line 52
- [`dmx_output`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_output): `include/uapi/linux/dvb/dmx.h`, line 38
- [`dmx_ts_pes`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 88

## IOCTL Commands

- [`DMX_ADD_PID`](/kernel/userspace/userspace-api/media-dvb/dmx-add-pid.md#rst-dmx-add-pid): `include/uapi/linux/dvb/dmx.h`, line 296
- [`DMX_DQBUF`](/kernel/userspace/userspace-api/media-dvb/dmx-qbuf.md#rst-dmx-qbuf): `include/uapi/linux/dvb/dmx.h`, line 313
- [`DMX_EXPBUF`](/kernel/userspace/userspace-api/media-dvb/dmx-expbuf.md#rst-dmx-expbuf): `include/uapi/linux/dvb/dmx.h`, line 311
- [`DMX_GET_PES_PIDS`](/kernel/userspace/userspace-api/media-dvb/dmx-get-pes-pids.md#rst-dmx-get-pes-pids): `include/uapi/linux/dvb/dmx.h`, line 294
- [`DMX_GET_STC`](/kernel/userspace/userspace-api/media-dvb/dmx-get-stc.md#rst-dmx-get-stc): `include/uapi/linux/dvb/dmx.h`, line 295
- [`DMX_QBUF`](/kernel/userspace/userspace-api/media-dvb/dmx-qbuf.md#rst-dmx-qbuf): `include/uapi/linux/dvb/dmx.h`, line 312
- [`DMX_QUERYBUF`](/kernel/userspace/userspace-api/media-dvb/dmx-querybuf.md#rst-dmx-querybuf): `include/uapi/linux/dvb/dmx.h`, line 310
- [`DMX_REMOVE_PID`](/kernel/userspace/userspace-api/media-dvb/dmx-remove-pid.md#rst-dmx-remove-pid): `include/uapi/linux/dvb/dmx.h`, line 297
- [`DMX_REQBUFS`](/kernel/userspace/userspace-api/media-dvb/dmx-reqbufs.md#rst-dmx-reqbufs): `include/uapi/linux/dvb/dmx.h`, line 309
- [`DMX_SET_BUFFER_SIZE`](/kernel/userspace/userspace-api/media-dvb/dmx-set-buffer-size.md#rst-dmx-set-buffer-size): `include/uapi/linux/dvb/dmx.h`, line 293
- [`DMX_SET_FILTER`](/kernel/userspace/userspace-api/media-dvb/dmx-set-filter.md#rst-dmx-set-filter): `include/uapi/linux/dvb/dmx.h`, line 291
- [`DMX_SET_PES_FILTER`](/kernel/userspace/userspace-api/media-dvb/dmx-set-pes-filter.md#rst-dmx-set-pes-filter): `include/uapi/linux/dvb/dmx.h`, line 292
- [`DMX_START`](/kernel/userspace/userspace-api/media-dvb/dmx-start.md#rst-dmx-start): `include/uapi/linux/dvb/dmx.h`, line 289
- [`DMX_STOP`](/kernel/userspace/userspace-api/media-dvb/dmx-stop.md#rst-dmx-stop): `include/uapi/linux/dvb/dmx.h`, line 290

## Macros and Definitions

- [`DMX_CHECK_CRC`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_sct_filter_params): `include/uapi/linux/dvb/dmx.h`, line 163
- [`DMX_IMMEDIATE_START`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_sct_filter_params): `include/uapi/linux/dvb/dmx.h`, line 165
- [`DMX_ONESHOT`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_sct_filter_params): `include/uapi/linux/dvb/dmx.h`, line 164

## Structures

- [`dmx_buffer`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_buffer): `include/uapi/linux/dvb/dmx.h`, line 245
- [`dmx_exportbuffer`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_exportbuffer): `include/uapi/linux/dvb/dmx.h`, line 283
- [`dmx_filter`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_filter): `include/uapi/linux/dvb/dmx.h`, line 134
- [`dmx_pes_filter_params`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_pes_filter_params): `include/uapi/linux/dvb/dmx.h`, line 178
- [`dmx_requestbuffers`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_requestbuffers): `include/uapi/linux/dvb/dmx.h`, line 263
- [`dmx_sct_filter_params`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_sct_filter_params): `include/uapi/linux/dvb/dmx.h`, line 158
- [`dmx_stc`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_stc): `include/uapi/linux/dvb/dmx.h`, line 193

## Type Definitions

- [`dmx_filter_t`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-struct-dmx_filter): `include/uapi/linux/dvb/dmx.h`, line 305
- [`dmx_input_t`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_input): `include/uapi/linux/dvb/dmx.h`, line 303
- [`dmx_output_t`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_output): `include/uapi/linux/dvb/dmx.h`, line 302
- [`dmx_pes_type_t`](/kernel/userspace/userspace-api/media-dvb/dmx-types.md#c-enum-dmx_ts_pes): `include/uapi/linux/dvb/dmx.h`, line 304


<a id="rst-conditional-access"></a>

## Conditional Access


## IOCTL Commands

- [`CA_GET_CAP`](/kernel/userspace/userspace-api/media-dvb/ca-get-cap.md#rst-ca-get-cap): `include/uapi/linux/dvb/ca.h`, line 121
- [`CA_GET_DESCR_INFO`](/kernel/userspace/userspace-api/media-dvb/ca-get-descr-info.md#rst-ca-get-descr-info): `include/uapi/linux/dvb/ca.h`, line 123
- [`CA_GET_MSG`](/kernel/userspace/userspace-api/media-dvb/ca-get-msg.md#rst-ca-get-msg): `include/uapi/linux/dvb/ca.h`, line 124
- [`CA_GET_SLOT_INFO`](/kernel/userspace/userspace-api/media-dvb/ca-get-slot-info.md#rst-ca-get-slot-info): `include/uapi/linux/dvb/ca.h`, line 122
- [`CA_RESET`](/kernel/userspace/userspace-api/media-dvb/ca-reset.md#rst-ca-reset): `include/uapi/linux/dvb/ca.h`, line 120
- [`CA_SEND_MSG`](/kernel/userspace/userspace-api/media-dvb/ca-send-msg.md#rst-ca-send-msg): `include/uapi/linux/dvb/ca.h`, line 125
- [`CA_SET_DESCR`](/kernel/userspace/userspace-api/media-dvb/ca-set-descr.md#rst-ca-set-descr): `include/uapi/linux/dvb/ca.h`, line 126

## Macros and Definitions

- [`CA_CI`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 39
- [`CA_CI_LINK`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 40
- [`CA_CI_MODULE_PRESENT`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 46
- [`CA_CI_MODULE_READY`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 47
- [`CA_CI_PHYS`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 41
- [`CA_DESCR`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 42
- [`CA_DSS`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_descr_info): `include/uapi/linux/dvb/ca.h`, line 70
- [`CA_ECD`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_descr_info): `include/uapi/linux/dvb/ca.h`, line 68
- [`CA_NDS`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_descr_info): `include/uapi/linux/dvb/ca.h`, line 69
- [`CA_SC`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 43

## Structures

- [`ca_caps`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_caps): `include/uapi/linux/dvb/ca.h`, line 83
- [`ca_descr`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_descr): `include/uapi/linux/dvb/ca.h`, line 114
- [`ca_descr_info`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_descr_info): `include/uapi/linux/dvb/ca.h`, line 65
- [`ca_msg`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_msg): `include/uapi/linux/dvb/ca.h`, line 100
- [`ca_slot_info`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 36

## Type Definitions

- [`ca_caps_t`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_caps): `include/uapi/linux/dvb/ca.h`, line 133
- [`ca_descr_info_t`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_descr_info): `include/uapi/linux/dvb/ca.h`, line 132
- [`ca_descr_t`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_descr): `include/uapi/linux/dvb/ca.h`, line 135
- [`ca_msg_t`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_msg): `include/uapi/linux/dvb/ca.h`, line 134
- [`ca_slot_info_t`](/kernel/userspace/userspace-api/media-dvb/ca-data-types.md#c-struct-ca_slot_info): `include/uapi/linux/dvb/ca.h`, line 131


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

## Network


## IOCTL Commands

- [`NET_ADD_IF`](/kernel/userspace/userspace-api/media-dvb/net-add-if.md#rst-net-add-if): `include/uapi/linux/dvb/net.h`, line 39
- [`NET_GET_IF`](/kernel/userspace/userspace-api/media-dvb/net-get-if.md#rst-net-get-if): `include/uapi/linux/dvb/net.h`, line 41
- [`NET_REMOVE_IF`](/kernel/userspace/userspace-api/media-dvb/net-remove-if.md#rst-net-remove-if): `include/uapi/linux/dvb/net.h`, line 40

## Macros and Definitions

- [`DVB_NET_FEEDTYPE_MPE`](/kernel/userspace/userspace-api/media-dvb/net-types.md#c-struct-dvb_net_if): `include/uapi/linux/dvb/net.h`, line 34
- [`DVB_NET_FEEDTYPE_ULE`](/kernel/userspace/userspace-api/media-dvb/net-types.md#c-struct-dvb_net_if): `include/uapi/linux/dvb/net.h`, line 35

## Structures

- [`dvb_net_if`](/kernel/userspace/userspace-api/media-dvb/net-types.md#c-struct-dvb_net_if): `include/uapi/linux/dvb/net.h`, line 30

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The reader of this document is required to have some knowledge in the area of digital video broadcasting (Digital TV) and should be familiar with part I of the MPEG2 specification ISO/IEC 13818 (aka ITU-T H.222), i.e you should know what a…

<a id="rst-introduction"></a>
<a id="rst-dvb-introduction"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<a id="rst-what-you-need-to-know"></a>
<a id="rst-requisites"></a>

## What you need to know

The reader of this document is required to have some knowledge in the area of digital video broadcasting (Digital TV) and should be familiar with part I of the MPEG2 specification ISO/IEC 13818 (aka ITU-T H.222), i.e you should know what a program/transport stream (PS/TS) is and what is meant by a packetized elementary stream (PES) or an I-frame.

Various Digital TV standards documents are available for download at:

- European standards (DVB): [http://www.dvb.org](<http://www.dvb.org>) and/or [http://www.etsi.org](<http://www.etsi.org>).

- American standards (ATSC): [https://www.atsc.org/standards/](<https://www.atsc.org/standards/>)

- Japanese standards (ISDB): [http://www.dibeg.org/](<http://www.dibeg.org/>)

It is also necessary to know how to access Linux devices and how to use ioctl calls. This also includes the knowledge of C or C++.

<a id="rst-history-1"></a>
<a id="rst-history"></a>

## History

The first API for Digital TV cards we used at Convergence in late 1999 was an extension of the Video4Linux API which was primarily developed for frame grabber cards. As such it was not really well suited to be used for Digital TV cards and their new features like recording MPEG streams and filtering several section and PES data streams at the same time.

In early 2000, Convergence was approached by Nokia with a proposal for a new standard Linux Digital TV API. As a commitment to the development of terminals based on open standards, Nokia and Convergence made it available to all Linux developers and published it on [https://linuxtv.org](<https://linuxtv.org>) in September 2000. With the Linux driver for the Siemens/Hauppauge DVB PCI card, Convergence provided a first implementation of the Linux Digital TV API. Convergence was the maintainer of the Linux Digital TV API in the early days.

Now, the API is maintained by the LinuxTV community (i.e. you, the reader of this document). The Linux  Digital TV API is constantly reviewed and improved together with the improvements at the subsystem's core at the Kernel.

<a id="rst-overview-1"></a>
<a id="rst-overview"></a>

## Overview

<a id="rst-stb-components"></a>

![dvbstb.svg](/kernel/userspace/userspace-api/media-dvb/asset-33acbf158a50-dvbstb.svg)

Components of a Digital TV card/STB

A Digital TV card or set-top-box (STB) usually consists of the following main hardware components:

- **Frontend consisting of tuner and digital TV demodulator**

  Here the raw signal reaches the digital TV hardware from a satellite dish or antenna or directly from cable. The frontend down-converts and demodulates this signal into an MPEG transport stream (TS). In case of a satellite frontend, this includes a facility for satellite equipment control (SEC), which allows control of LNB polarization, multi feed switches or dish rotors.

- **Conditional Access (CA) hardware like CI adapters and smartcard slots**

  The complete TS is passed through the CA hardware. Programs to which the user has access (controlled by the smart card) are decoded in real time and re-inserted into the TS.

  > [!NOTE]
  >
  > Not every digital TV hardware provides conditional access hardware.

- **Demultiplexer which filters the incoming Digital TV MPEG-TS stream**

  The demultiplexer splits the TS into its components like audio and video streams. Besides usually several of such audio and video streams it also contains data streams with information about the programs offered in this or other streams of the same provider.

- **Audio and video decoder**

  The main targets of the demultiplexer are audio and video decoders. After decoding, they pass on the uncompressed audio and video to the computer screen or to a TV set.

  > [!NOTE]
  >
  > Modern hardware usually doesn't have a separate decoder hardware, as such functionality can be provided by the main CPU, by the graphics adapter of the system or by a signal processing hardware embedded on a Systems on a Chip (SoC) integrated circuit.
  >
  > It may also not be needed for certain usages (e.g. for data-only uses like "internet over satellite").

[stb_components](<#rst-stb-components>) shows a crude schematic of the control and data flow between those components.

<a id="rst-linux-digital-tv-devices"></a>
<a id="rst-dvb-devices"></a>

## Linux Digital TV Devices

The Linux Digital TV API lets you control these hardware components through currently six Unix-style character devices for video, audio, frontend, demux, CA and IP-over-DVB networking. The video and audio devices control the MPEG2 decoder hardware, the frontend device the tuner and the Digital TV demodulator. The demux device gives you control over the PES and section filters of the hardware. If the hardware does not support filtering, these filters can be implemented in software. Finally, the CA device controls all the conditional access capabilities of the hardware. It can depend on the individual security requirements of the platform, if and how many of the CA functions are made available to the application through this device.

All devices can be found in the `/dev` tree under `/dev/dvb`. The individual devices are called:

- `/dev/dvb/adapterN/audioM`,

- `/dev/dvb/adapterN/videoM`,

- `/dev/dvb/adapterN/frontendM`,

- `/dev/dvb/adapterN/netM`,

- `/dev/dvb/adapterN/demuxM`,

- `/dev/dvb/adapterN/dvrM`,

- `/dev/dvb/adapterN/caM`,

where `N` enumerates the Digital TV cards in a system starting from 0, and `M` enumerates the devices of each type within each adapter, starting from 0, too. We will omit the "`/dev/dvb/adapterN/`" in the further discussion of these devices.

More details about the data structures and function calls of all the devices are described in the following chapters.

<a id="rst-api-include-files"></a>
<a id="rst-include-files"></a>

## API include files

For each of the Digital TV devices a corresponding include file exists. The Digital TV API include files should be included in application sources with a partial path like:



```c
#include <linux/dvb/ca.h>

#include <linux/dvb/dmx.h>

#include <linux/dvb/frontend.h>

#include <linux/dvb/net.h>
```

To enable applications to support different API version, an additional include file `linux/dvb/version.h` exists, which defines the constant `DVB_API_VERSION`. This document describes `DVB_API_VERSION 5.10`.

---

# Digital TV Deprecated APIs

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The APIs described here should not be used on new drivers or applications.

<a id="rst-digital-tv-deprecated-apis"></a>
<a id="rst-legacy-dvb-apis"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The APIs described here **should not** be used on new drivers or applications.

The DVBv3 frontend API has issues with new delivery systems, including DVB-S2, DVB-T2, ISDB, etc.

> [!NOTE]
>
> The APIs described here doesn't necessarily reflect the current code implementation, as this section of the document was written for DVB version 1, while the code reflects DVB version 3 implementation.

- [Digital TV Frontend legacy API (a. k. a. DVBv3)](</kernel/userspace/userspace-api/media-dvb/frontend-legacy-dvbv3-api.md>)
- [Legacy DVB MPEG Decoder APIs](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md>)

---

# DVB Audio Device

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The DVB audio device controls the MPEG2 audio decoder of the DVB hardware. It can be accessed through /dev/dvb/adapter?/audio?. Data types and ioctl definitions can be accessed by including linux/dvb/audio.h in your application.

<a id="rst-dvb-audio-device"></a>
<a id="rst-dvb-audio"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later OR GPL-2.0 -->

<!-- c:namespace: dtv.legacy.audio -->

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

The DVB audio device controls the MPEG2 audio decoder of the DVB hardware. It can be accessed through `/dev/dvb/adapter?/audio?`. Data types and ioctl definitions can be accessed by including `linux/dvb/audio.h` in your application.

Please note that most DVB cards don’t have their own MPEG decoder, which results in the omission of the audio and video device.

These ioctls were also used by V4L2 to control MPEG decoders implemented in V4L2. The use of these ioctls for that purpose has been made obsolete and proper V4L2 ioctls or controls have been created to replace that functionality. Use [V4L2 ioctls](</kernel/userspace/userspace-api/media-v4l/audio.md#rst-audio>) for new drivers\!

<a id="rst-audio-data-types"></a>

## Audio Data Types

This section describes the structures, data types and defines used when talking to the audio device.

---

<a id="rst-audio-stream-source-t"></a>

### audio_stream_source_t

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

#### Synopsis





<a id="c-enum-audio_stream_source_t"></a>

```c
audio_stream_source_t
```



```c
typedef enum {
AUDIO_SOURCE_DEMUX,
AUDIO_SOURCE_MEMORY
} audio_stream_source_t;
```

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

#### Constants


<table>
<tbody>
<tr>
<td>


`AUDIO_SOURCE_DEMUX`

</td>
<td colspan="2">


 Selects the demultiplexer (fed either by the frontend or the DVR device) as the source of the video stream.

</td>
</tr>
<tr>
<td>


`AUDIO_SOURCE_MEMORY`

</td>
<td colspan="2">


Selects the stream from the application that comes through the [write()](<#rst-write>) system call.

</td>
</tr>
</tbody>
</table>

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

#### Description

The audio stream source is set through the [AUDIO_SELECT_SOURCE](<#rst-audio-select-source>) call and can take the following values, depending on whether we are replaying from an internal (demux) or external (user write) source.

The data fed to the decoder is also controlled by the PID-filter. Output selection: `dmx_output` `DMX_OUT_DECODER`.

---

<a id="rst-audio-play-state-t"></a>

### audio_play_state_t

<a id="rst-synopsis-1"></a>

#### Synopsis





<a id="c-enum-audio_play_state_t"></a>

```c
audio_play_state_t
```



```c
typedef enum {
    AUDIO_STOPPED,
    AUDIO_PLAYING,
    AUDIO_PAUSED
} audio_play_state_t;
```

<a id="rst-constants-1"></a>

#### Constants


<table>
<tbody>
<tr>
<td>


`AUDIO_STOPPED`

</td>
<td>


Audio is stopped.

</td>
</tr>
<tr>
<td>


`AUDIO_PLAYING`

</td>
<td>


Audio is currently playing.

</td>
</tr>
<tr>
<td>


`AUDIO_PAUSE`

</td>
<td>


Audio is frozen.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-1"></a>

#### Description

This values can be returned by the [AUDIO_GET_STATUS](<#rst-audio-get-status>) call representing the state of audio playback.

---

<a id="rst-audio-channel-select-t"></a>

### audio_channel_select_t

<a id="rst-synopsis-2"></a>

#### Synopsis





<a id="c-enum-audio_channel_select_t"></a>

```c
audio_channel_select_t
```



```c
typedef enum {
    AUDIO_STEREO,
    AUDIO_MONO_LEFT,
    AUDIO_MONO_RIGHT,
    AUDIO_MONO,
    AUDIO_STEREO_SWAPPED
} audio_channel_select_t;
```

<a id="rst-constants-2"></a>

#### Constants


<table>
<tbody>
<tr>
<td>


`AUDIO_STEREO`

</td>
<td>


Stereo.

</td>
</tr>
<tr>
<td>


`AUDIO_MONO_LEFT`

</td>
<td>


Mono, select left stereo channel as source.

</td>
</tr>
<tr>
<td>


`AUDIO_MONO_RIGHT`

</td>
<td>


Mono, select right stereo channel as source.

</td>
</tr>
<tr>
<td>


`AUDIO_MONO`

</td>
<td>


Mono source only.

</td>
</tr>
<tr>
<td>


`AUDIO_STEREO_SWAPPED`

</td>
<td>


Stereo, swap L &amp; R.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-2"></a>

#### Description

The audio channel selected via [AUDIO_CHANNEL_SELECT](<#rst-audio-channel-select>) is determined by this value.

---

<a id="rst-audio-mixer-t"></a>

### audio_mixer_t

<a id="rst-synopsis-3"></a>

#### Synopsis





<a id="c-struct-audio_mixer"></a>

```c
audio_mixer
```



```c
typedef struct audio_mixer {
    unsigned int volume_left;
    unsigned int volume_right;
} audio_mixer_t;
```

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

#### Variables


<table>
<tbody>
<tr>
<td>


`unsigned int volume_left`

</td>
<td>


Volume left channel. Valid range: 0 ... 255

</td>
</tr>
<tr>
<td>


`unsigned int volume_right`

</td>
<td>


Volume right channel. Valid range: 0 ... 255

</td>
</tr>
</tbody>
</table>

<a id="rst-description-3"></a>

#### Description

This structure is used by the [AUDIO_SET_MIXER](<#rst-audio-set-mixer>) call to set the audio volume.

---

<a id="rst-audio-status"></a>

### audio_status

<a id="rst-synopsis-4"></a>

#### Synopsis





<a id="c-struct-audio_status"></a>

```c
audio_status
```



```c
typedef struct audio_status {
    int AV_sync_state;
    int mute_state;
    audio_play_state_t play_state;
    audio_stream_source_t stream_source;
    audio_channel_select_t channel_select;
    int bypass_mode;
    audio_mixer_t mixer_state;
} audio_status_t;
```

<a id="rst-variables-1"></a>

#### Variables


<table>
<tbody>
<tr>
<td rowspan="3">


 `int AV_sync_state`

</td>
<td colspan="2">


 Shows if A/V synchronization is ON or OFF.

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


AV-sync ON.

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


AV-sync OFF.

</td>
</tr>
<tr>
<td rowspan="3">


 `int mute_state`

</td>
<td colspan="2">


 Indicates if audio is muted or not.

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


mute audio

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


unmute audio

</td>
</tr>
<tr>
<td>


[audio_play_state_t](<#rst-audio-play-state-t>) `play_state`

</td>
<td colspan="2">


Current playback state.

</td>
</tr>
<tr>
<td>


[audio_stream_source_t](<#rst-audio-stream-source-t>) `stream_source`

</td>
<td colspan="2">


Current source of the data.

</td>
</tr>
<tr>
<td rowspan="3">


 `int bypass_mode`

</td>
<td colspan="2">


 Is the decoding of the current Audio stream in the DVB subsystem enabled or disabled.

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


Bypass disabled.

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


Bypass enabled.

</td>
</tr>
<tr>
<td>


[audio_mixer_t](<#rst-audio-mixer-t>) `mixer_state`

</td>
<td colspan="2">


Current volume settings.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-4"></a>

#### Description

The [AUDIO_GET_STATUS](<#rst-audio-get-status>) call returns this structure as information about various states of the playback operation.

---

<a id="rst-audio-encodings"></a>

### audio encodings

<a id="rst-synopsis-5"></a>

#### Synopsis



```c
#define AUDIO_CAP_DTS    1
#define AUDIO_CAP_LPCM   2
#define AUDIO_CAP_MP1    4
#define AUDIO_CAP_MP2    8
#define AUDIO_CAP_MP3   16
#define AUDIO_CAP_AAC   32
#define AUDIO_CAP_OGG   64
#define AUDIO_CAP_SDDS 128
#define AUDIO_CAP_AC3  256
```

<a id="rst-constants-3"></a>

#### Constants


<table>
<tbody>
<tr>
<td>


`AUDIO_CAP_DTS`

</td>
<td colspan="2">


 The hardware accepts DTS audio tracks.

</td>
</tr>
<tr>
<td>


`AUDIO_CAP_LPCM`

</td>
<td colspan="2">


The hardware accepts uncompressed audio with Linear Pulse-Code Modulation (LPCM)

</td>
</tr>
<tr>
<td>


`AUDIO_CAP_MP1`

</td>
<td colspan="2">


The hardware accepts MPEG-1 Audio Layer 1.

</td>
</tr>
<tr>
<td>


`AUDIO_CAP_MP2`

</td>
<td colspan="2">


The hardware accepts MPEG-1 Audio Layer 2. Also known as MUSICAM.

</td>
</tr>
<tr>
<td>


`AUDIO_CAP_MP3`

</td>
<td colspan="2">


The hardware accepts MPEG-1 Audio Layer III. Commonly known as .mp3.

</td>
</tr>
<tr>
<td>


`AUDIO_CAP_AAC`

</td>
<td colspan="2">


The hardware accepts AAC (Advanced Audio Coding).

</td>
</tr>
<tr>
<td>


`AUDIO_CAP_OGG`

</td>
<td colspan="2">


The hardware accepts Vorbis audio tracks.

</td>
</tr>
<tr>
<td>


`AUDIO_CAP_SDDS`

</td>
<td colspan="2">


The hardware accepts Sony Dynamic Digital Sound (SDDS).

</td>
</tr>
<tr>
<td>


`AUDIO_CAP_AC3`

</td>
<td colspan="2">


The hardware accepts Dolby Digital ATSC A/52 audio. Also known as AC-3.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-5"></a>

#### Description

A call to [AUDIO_GET_CAPABILITIES](<#rst-audio-get-capabilities>) returns an unsigned integer with the following bits set according to the hardwares capabilities.

---

<a id="rst-audio-function-calls"></a>

## Audio Function Calls

<a id="rst-audio-stop"></a>

### AUDIO_STOP

<a id="rst-synopsis-6"></a>

#### Synopsis





<a id="c-AUDIO_STOP"></a>

```c
AUDIO_STOP
```



```c
int ioctl(int fd, int request = AUDIO_STOP)
```

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

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


 Equals `AUDIO_STOP` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-6"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Audio Device to stop playing the current stream.

<a id="rst-return-value"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-play"></a>

### AUDIO_PLAY

<a id="rst-synopsis-7"></a>

#### Synopsis





<a id="c-AUDIO_PLAY"></a>

```c
AUDIO_PLAY
```



```c
int  ioctl(int fd, int request = AUDIO_PLAY)
```

<a id="rst-arguments-1"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


 Equals `AUDIO_PLAY` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-7"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Audio Device to start playing an audio stream from the selected source.

<a id="rst-return-value-1"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-pause"></a>

### AUDIO_PAUSE

<a id="rst-synopsis-8"></a>

#### Synopsis





<a id="c-AUDIO_PAUSE"></a>

```c
AUDIO_PAUSE
```



```c
int  ioctl(int fd, int request = AUDIO_PAUSE)
```

<a id="rst-arguments-2"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_PAUSE` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-8"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call suspends the audio stream being played. Decoding and playing are paused. It is then possible to restart again decoding and playing process of the audio stream using [AUDIO_CONTINUE](<#rst-audio-continue>) command.

<a id="rst-return-value-2"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-continue"></a>

### AUDIO_CONTINUE

<a id="rst-synopsis-9"></a>

#### Synopsis





<a id="c-AUDIO_CONTINUE"></a>

```c
AUDIO_CONTINUE
```



```c
int  ioctl(int fd, int request = AUDIO_CONTINUE)
```

<a id="rst-arguments-3"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_CONTINUE` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-9"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl restarts the decoding and playing process previously paused with [AUDIO_PAUSE](<#rst-audio-pause>) command.

<a id="rst-return-value-3"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-select-source"></a>

### AUDIO_SELECT_SOURCE

<a id="rst-synopsis-10"></a>

#### Synopsis





<a id="c-AUDIO_SELECT_SOURCE"></a>

```c
AUDIO_SELECT_SOURCE
```



```c
int ioctl(int fd, int request = AUDIO_SELECT_SOURCE,
audio_stream_source_t source)
```

<a id="rst-arguments-4"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_SELECT_SOURCE` for this command.

</td>
</tr>
<tr>
<td>


[audio_stream_source_t](<#rst-audio-stream-source-t>) `source`

</td>
<td colspan="2">


Indicates the source that shall be used for the Audio stream.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-10"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call informs the audio device which source shall be used for the input data. The possible sources are demux or memory. If `AUDIO_SOURCE_MEMORY` is selected, the data is fed to the Audio Device through the write command. If `AUDIO_SOURCE_DEMUX` is selected, the data is directly transferred from the onboard demux-device to the decoder. Note: This only supports DVB-devices with one demux and one decoder so far.

<a id="rst-return-value-4"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-set-mute"></a>

### AUDIO_SET_MUTE

<a id="rst-synopsis-11"></a>

#### Synopsis





<a id="c-AUDIO_SET_MUTE"></a>

```c
AUDIO_SET_MUTE
```



```c
int  ioctl(int fd, int request = AUDIO_SET_MUTE, int state)
```

<a id="rst-arguments-5"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


 Equals `AUDIO_SET_MUTE` for this command.

</td>
</tr>
<tr>
<td rowspan="3">


 `int state`

</td>
<td colspan="2">


 Indicates if audio device shall mute or not.

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


mute audio

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


unmute audio

</td>
</tr>
</tbody>
</table>

<a id="rst-description-11"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is for DVB devices only. To control a V4L2 decoder use the V4L2 [ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) with the `V4L2_DEC_CMD_START_MUTE_AUDIO` flag instead.

This ioctl call asks the audio device to mute the stream that is currently being played.

<a id="rst-return-value-5"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-set-av-sync"></a>

### AUDIO_SET_AV_SYNC

<a id="rst-synopsis-12"></a>

#### Synopsis





<a id="c-AUDIO_SET_AV_SYNC"></a>

```c
AUDIO_SET_AV_SYNC
```



```c
int  ioctl(int fd, int request = AUDIO_SET_AV_SYNC, int state)
```

<a id="rst-arguments-6"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


 Equals `AUDIO_AV_SYNC` for this command.

</td>
</tr>
<tr>
<td rowspan="3">


 `int state`

</td>
<td colspan="2">


 Tells the DVB subsystem if A/V synchronization shall be ON or OFF.

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


AV-sync ON.

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


AV-sync OFF.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-12"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Audio Device to turn ON or OFF A/V synchronization.

<a id="rst-return-value-6"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-set-bypass-mode"></a>

### AUDIO_SET_BYPASS_MODE

<a id="rst-synopsis-13"></a>

#### Synopsis





<a id="c-AUDIO_SET_BYPASS_MODE"></a>

```c
AUDIO_SET_BYPASS_MODE
```



```c
int ioctl(int fd, int request = AUDIO_SET_BYPASS_MODE, int mode)
```

<a id="rst-arguments-7"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


 Equals `AUDIO_SET_BYPASS_MODE` for this command.

</td>
</tr>
<tr>
<td rowspan="3">


 `int mode`

</td>
<td colspan="2">


 Enables or disables the decoding of the current Audio stream in the DVB subsystem.

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


Disable bypass

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


Enable bypass

</td>
</tr>
</tbody>
</table>

<a id="rst-description-13"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Audio Device to bypass the Audio decoder and forward the stream without decoding. This mode shall be used if streams that can’t be handled by the DVB system shall be decoded. Dolby DigitalTM streams are automatically forwarded by the DVB subsystem if the hardware can handle it.

<a id="rst-return-value-7"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-channel-select"></a>

### AUDIO_CHANNEL_SELECT

<a id="rst-synopsis-14"></a>

#### Synopsis





<a id="c-AUDIO_CHANNEL_SELECT"></a>

```c
AUDIO_CHANNEL_SELECT
```



```c
int ioctl(int fd, int request = AUDIO_CHANNEL_SELECT,
audio_channel_select_t)
```

<a id="rst-arguments-8"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_CHANNEL_SELECT` for this command.

</td>
</tr>
<tr>
<td>


[audio_channel_select_t](<#rst-audio-channel-select-t>) `ch`

</td>
<td colspan="2">


Select the output format of the audio (mono left/right, stereo).

</td>
</tr>
</tbody>
</table>

<a id="rst-description-14"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is for DVB devices only. To control a V4L2 decoder use the V4L2 `V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK` control instead.

This ioctl call asks the Audio Device to select the requested channel if possible.

<a id="rst-return-value-8"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-get-status"></a>

### AUDIO_GET_STATUS

<a id="rst-synopsis-15"></a>

#### Synopsis





<a id="c-AUDIO_GET_STATUS"></a>

```c
AUDIO_GET_STATUS
```



```c
int ioctl(int fd, int request = AUDIO_GET_STATUS,
struct audio_status *status)
```

<a id="rst-arguments-9"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals AUDIO_GET_STATUS for this command.

</td>
</tr>
<tr>
<td>


`struct` [audio_status](<#rst-audio-status>) `*status`

</td>
<td colspan="2">


Returns the current state of Audio Device.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-15"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Audio Device to return the current state of the Audio Device.

<a id="rst-return-value-9"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-get-capabilities"></a>

### AUDIO_GET_CAPABILITIES

<a id="rst-synopsis-16"></a>

#### Synopsis





<a id="c-AUDIO_GET_CAPABILITIES"></a>

```c
AUDIO_GET_CAPABILITIES
```



```c
int ioctl(int fd, int request = AUDIO_GET_CAPABILITIES,
unsigned int *cap)
```

<a id="rst-arguments-10"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_GET_CAPABILITIES` for this command.

</td>
</tr>
<tr>
<td>


`unsigned int *cap`

</td>
<td colspan="2">


Returns a bit array of supported sound formats. Bits are defined in [audio encodings](<#rst-audio-encodings>).

</td>
</tr>
</tbody>
</table>

<a id="rst-description-16"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Audio Device to tell us about the decoding capabilities of the audio hardware.

<a id="rst-return-value-10"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-clear-buffer"></a>

### AUDIO_CLEAR_BUFFER

<a id="rst-synopsis-17"></a>

#### Synopsis





<a id="c-AUDIO_CLEAR_BUFFER"></a>

```c
AUDIO_CLEAR_BUFFER
```



```c
int  ioctl(int fd, int request = AUDIO_CLEAR_BUFFER)
```

<a id="rst-arguments-11"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_CLEAR_BUFFER` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-17"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Audio Device to clear all software and hardware buffers of the audio decoder device.

<a id="rst-return-value-11"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-set-id"></a>

### AUDIO_SET_ID

<a id="rst-synopsis-18"></a>

#### Synopsis





<a id="c-AUDIO_SET_ID"></a>

```c
AUDIO_SET_ID
```



```c
int  ioctl(int fd, int request = AUDIO_SET_ID, int id)
```

<a id="rst-arguments-12"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_SET_ID` for this command.

</td>
</tr>
<tr>
<td>


`int id`

</td>
<td colspan="2">


Audio sub-stream id.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-18"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl selects which sub-stream is to be decoded if a program or system stream is sent to the video device.

If no audio stream type is set the id has to be in range \[0xC0,0xDF\] for MPEG sound, in \[0x80,0x87\] for AC3 and in \[0xA0,0xA7\] for LPCM. See ITU-T H.222.0 \| ISO/IEC 13818-1 for further description.

If the stream type is set with [AUDIO_SET_STREAMTYPE](<#rst-audio-set-streamtype>), specifies the id just the sub-stream id of the audio stream and only the first 5 bits (&amp; 0x1F) are recognized.

<a id="rst-return-value-12"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-set-mixer"></a>

### AUDIO_SET_MIXER

<a id="rst-synopsis-19"></a>

#### Synopsis





<a id="c-AUDIO_SET_MIXER"></a>

```c
AUDIO_SET_MIXER
```



```c
int ioctl(int fd, int request = AUDIO_SET_MIXER, audio_mixer_t *mix)
```

<a id="rst-arguments-13"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_SET_MIXER` for this command.

</td>
</tr>
<tr>
<td>


`audio_mixer_t *mix`

</td>
<td colspan="2">


Mixer settings.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-19"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl lets you adjust the mixer settings of the audio decoder.

<a id="rst-return-value-13"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-audio-set-streamtype"></a>

### AUDIO_SET_STREAMTYPE

<a id="rst-synopsis-20"></a>

#### Synopsis





<a id="c-AUDIO_SET_STREAMTYPE"></a>

```c
AUDIO_SET_STREAMTYPE
```



```c
int  ioctl(fd, int request = AUDIO_SET_STREAMTYPE, int type)
```

<a id="rst-arguments-14"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_SET_STREAMTYPE` for this command.

</td>
</tr>
<tr>
<td>


`int type`

</td>
<td colspan="2">


Stream type.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-20"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl tells the driver which kind of audio stream to expect. This is useful if the stream offers several audio sub-streams like LPCM and AC3.

Stream types defined in ITU-T H.222.0 \| ISO/IEC 13818-1 are used.

<a id="rst-return-value-14"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.


<table>
<tbody>
<tr>
<td>


`EINVAL`

</td>
<td>


Type is not a valid or supported stream type.

</td>
</tr>
</tbody>
</table>

---

<a id="rst-audio-bilingual-channel-select"></a>

### AUDIO_BILINGUAL_CHANNEL_SELECT

<a id="rst-synopsis-21"></a>

#### Synopsis





<a id="c-AUDIO_BILINGUAL_CHANNEL_SELECT"></a>

```c
AUDIO_BILINGUAL_CHANNEL_SELECT
```



```c
int ioctl(int fd, int request = AUDIO_BILINGUAL_CHANNEL_SELECT,
audio_channel_select_t)
```

<a id="rst-arguments-15"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `AUDIO_BILINGUAL_CHANNEL_SELECT` for this command.

</td>
</tr>
<tr>
<td>


`audio_channel_select_t ch`

</td>
<td colspan="2">


Select the output format of the audio (mono left/right, stereo).

</td>
</tr>
</tbody>
</table>

<a id="rst-description-21"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl has been replaced by the V4L2 `V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK` control for MPEG decoders controlled through V4L2.

This ioctl call asks the Audio Device to select the requested channel for bilingual streams if possible.

<a id="rst-return-value-15"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

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

### open()

<a id="rst-synopsis-22"></a>

#### Synopsis



```c
#include <fcntl.h>
```





<a id="c-open"></a>

```c
int  open(const char *deviceName, int flags)
```

<a id="rst-arguments-16"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`const char *deviceName`

</td>
<td colspan="2">


Name of specific audio device.

</td>
</tr>
<tr>
<td rowspan="4">


 `int flags`

</td>
<td colspan="2">


 A bit-wise OR of the following flags:

</td>
</tr>
<tr>
<td>


`O_RDONLY`

</td>
<td>


read-only access

</td>
</tr>
<tr>
<td>


`O_RDWR`

</td>
<td>


read/write access

</td>
</tr>
<tr>
<td>


`O_NONBLOCK`

</td>
<td>


Open in non-blocking mode  
(blocking mode is the default)

</td>
</tr>
</tbody>
</table>

<a id="rst-description-22"></a>

#### Description

This system call opens a named audio device (e.g. `/dev/dvb/adapter0/audio0`) for subsequent use. When an open() call has succeeded, the device will be ready for use. The significance of blocking or non-blocking mode is described in the documentation for functions where there is a difference. It does not affect the semantics of the open() call itself. A device opened in blocking mode can later be put into non-blocking mode (and vice versa) using the F_SETFL command of the fcntl system call. This is a standard system call, documented in the Linux manual page for fcntl. Only one user can open the Audio Device in O_RDWR mode. All other attempts to open the device in this mode will fail, and an error code will be returned. If the Audio Device is opened in O_RDONLY mode, the only ioctl call that can be used is [AUDIO_GET_STATUS](<#rst-audio-get-status>). All other call will return with an error code.

<a id="rst-return-value-16"></a>

#### Return Value


<table>
<tbody>
<tr>
<td>


`ENODEV`

</td>
<td>


Device driver not loaded/available.

</td>
</tr>
<tr>
<td>


`EBUSY`

</td>
<td>


Device or resource busy.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td>


Invalid argument.

</td>
</tr>
</tbody>
</table>

---

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

### close()

<a id="rst-synopsis-23"></a>

#### Synopsis





<a id="c-close"></a>

```c
int close(int fd)
```

<a id="rst-arguments-17"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
</tbody>
</table>

<a id="rst-description-23"></a>

#### Description

This system call closes a previously opened audio device.

<a id="rst-return-value-17"></a>

#### Return Value


<table>
<tbody>
<tr>
<td>


`EBADF`

</td>
<td>


Fd is not a valid open file descriptor.

</td>
</tr>
</tbody>
</table>

---

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

### write()

<a id="rst-synopsis-24"></a>

#### Synopsis



```c
size_t write(int fd, const void *buf, size_t count)
```

<a id="rst-arguments-18"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`void *buf`

</td>
<td colspan="2">


Pointer to the buffer containing the PES data.

</td>
</tr>
<tr>
<td>


`size_t count`

</td>
<td colspan="2">


Size of buf.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-24"></a>

#### Description

This system call can only be used if `AUDIO_SOURCE_MEMORY` is selected in the ioctl call [AUDIO_SELECT_SOURCE](<#rst-audio-select-source>). The data provided shall be in PES format. If `O_NONBLOCK` is not specified the function will block until buffer space is available. The amount of data to be transferred is implied by count.

<a id="rst-return-value-18"></a>

#### Return Value


<table>
<tbody>
<tr>
<td>


`EPERM`

</td>
<td colspan="2">


 Mode `AUDIO_SOURCE_MEMORY` not selected.

</td>
</tr>
<tr>
<td>


`ENOMEM`

</td>
<td colspan="2">


Attempted to write more data than the internal buffer can hold.

</td>
</tr>
<tr>
<td>


`EBADF`

</td>
<td colspan="2">


Fd is not a valid open file descriptor.

</td>
</tr>
</tbody>
</table>

---

# Legacy DVB MPEG Decoder APIs

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> This API has originally been designed for DVB only and is therefore limited to the legacy_dvb_decoder_formats used in such digital TV-broadcastsystems.

<a id="rst-legacy-dvb-mpeg-decoder-apis"></a>
<a id="rst-legacy-dvb-decoder-api"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later OR GPL-2.0 -->

<a id="rst-general-notes"></a>
<a id="rst-legacy-dvb-decoder-notes"></a>

## General Notes

This API has originally been designed for DVB only and is therefore limited to the [Data Formats](<#rst-legacy-dvb-decoder-formats>) used in such digital TV-broadcastsystems.

To circumvent this limitations the more versatile [V4L2](</kernel/userspace/userspace-api/media-v4l/v4l2.md#rst-v4l2spec>) API has been designed. Which replaces this part of the DVB API.

Nevertheless there have been projects build around this API. To ensure compatibility this API is kept as it is.

> [!NOTE]
>
> Do **not** use this API in new drivers\!
>
> For audio and video use the [V4L2](</kernel/userspace/userspace-api/media-v4l/v4l2.md#rst-v4l2spec>) and ALSA APIs.
>
> Pipelines should be set up using the [Media Controller API](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>).

Practically the decoders seem to be treated differently. The application typically knows which decoder is in use or it is specially written for one decoder type. Querying capabilities are rarely used because they are already known.

<a id="rst-data-formats"></a>
<a id="rst-legacy-dvb-decoder-formats"></a>

## Data Formats

The API has been designed for DVB and compatible broadcastsystems. Because of that fact the only supported data formats are ISO/IEC 13818-1 compatible MPEG streams. The supported payloads may vary depending on the used decoder.

Timestamps are always MPEG PTS as defined in ITU T-REC-H.222.0 / ISO/IEC 13818-1, if not otherwise noted.

For storing recordings typically TS streams are used, in lesser extent PES. Both variants are commonly accepted for playback, but it may be driver dependent.

<a id="rst-table-of-contents"></a>

## Table of Contents

- [DVB Video Device](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-video.md>)
- [DVB Audio Device](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-audio.md>)
- [DVB OSD Device](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-osd.md>)

---

# DVB OSD Device

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The DVB OSD device controls the OnScreen-Display of the AV7110 based DVB-cards with hardware MPEG2 decoder. It can be accessed through /dev/dvb/adapter?/osd0. Data types and ioctl definitions can be accessed by including linux/dvb/osd.h in…

<a id="rst-dvb-osd-device"></a>
<a id="rst-dvb-osd"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later OR GPL-2.0 -->

<!-- c:namespace: dtv.legacy.osd -->

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

The DVB OSD device controls the OnScreen-Display of the AV7110 based DVB-cards with hardware MPEG2 decoder. It can be accessed through `/dev/dvb/adapter?/osd0`. Data types and ioctl definitions can be accessed by including `linux/dvb/osd.h` in your application.

The OSD is not a frame-buffer like on many other cards. It is a kind of canvas one can draw on. The color-depth is limited depending on the memory size installed. An appropriate palette of colors has to be set up. The installed memory size can be identified with the [OSD_GET_CAPABILITY](<#rst-osd-get-capability>) ioctl.

<a id="rst-osd-data-types"></a>

## OSD Data Types

<a id="rst-osd-command"></a>

### OSD_Command

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

#### Synopsis



```c
typedef enum {
    /* All functions return -2 on "not open" */
    OSD_Close = 1,
    OSD_Open,
    OSD_Show,
    OSD_Hide,
    OSD_Clear,
    OSD_Fill,
    OSD_SetColor,
    OSD_SetPalette,
    OSD_SetTrans,
    OSD_SetPixel,
    OSD_GetPixel,
    OSD_SetRow,
    OSD_SetBlock,
    OSD_FillRow,
    OSD_FillBlock,
    OSD_Line,
    OSD_Query,
    OSD_Test,
    OSD_Text,
    OSD_SetWindow,
    OSD_MoveWindow,
    OSD_OpenRaw,
} OSD_Command;
```

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

#### Commands

> [!NOTE]
>
> All functions return -2 on "not open"


<table>
<thead>
<tr>
<th>


Command

</th>
<th>


Used variables of `struct` [osd_cmd_t](<#rst-osd-cmd-t>).  
Usage\{variable\} if alternative use.

</th>
<th colspan="3">


 Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`OSD_Close`

</td>
<td>


- <!-- empty source list item -->

</td>
<td colspan="3">


Disables OSD and releases the buffers.  
Returns 0 on success.

</td>
</tr>
<tr>
<td>


`OSD_Open`

</td>
<td>


x0,y0,x1,y1,  
BitPerPixel\[2/4/8\]\{color&amp;0x0F\},  
mix\[0..15\]\{color&amp;0xF0\}

</td>
<td colspan="3">


Opens OSD with this size and bit depth  
Returns 0 on success,  
-1 on DRAM allocation error,  
-2 on "already open".

</td>
</tr>
<tr>
<td>


`OSD_Show`

</td>
<td>


- <!-- empty source list item -->

</td>
<td colspan="3">


Enables OSD mode.  
Returns 0 on success.

</td>
</tr>
<tr>
<td>


`OSD_Hide`

</td>
<td>


- <!-- empty source list item -->

</td>
<td colspan="3">


Disables OSD mode.  
Returns 0 on success.

</td>
</tr>
<tr>
<td>


`OSD_Clear`

</td>
<td>


- <!-- empty source list item -->

</td>
<td colspan="3">


Sets all pixel to color 0.  
Returns 0 on success.

</td>
</tr>
<tr>
<td>


`OSD_Fill`

</td>
<td>


color

</td>
<td colspan="3">


Sets all pixel to color &lt;color&gt;.  
Returns 0 on success.

</td>
</tr>
<tr>
<td>


`OSD_SetColor`

</td>
<td>


color,  
R\{x0\},G\{y0\},B\{x1\},  
opacity\{y1\}

</td>
<td colspan="3">


Set palette entry &lt;num&gt; to &lt;r,g,b&gt;, &lt;mix&gt; and &lt;trans&gt; apply  
R,G,B: 0..255  
R=Red, G=Green, B=Blue  
opacity=0:      pixel opacity 0% (only video pixel shows)  
opacity=1..254: pixel opacity as specified in header  
opacity=255:    pixel opacity 100% (only OSD pixel shows)  
Returns 0 on success, -1 on error.

</td>
</tr>
<tr>
<td>


`OSD_SetPalette`

</td>
<td>


firstcolor\{color\},  
lastcolor\{x0\},data

</td>
<td colspan="3">


Set a number of entries in the palette.  
Sets the entries "firstcolor" through "lastcolor" from the
array "data".  
Data has 4 byte for each color:  
R,G,B, and a opacity value: 0-&gt;transparent, 1..254-&gt;mix,
255-&gt;pixel

</td>
</tr>
<tr>
<td>


`OSD_SetTrans`

</td>
<td>


transparency\{color\}

</td>
<td colspan="3">


Sets transparency of mixed pixel (0..15).  
Returns 0 on success.

</td>
</tr>
<tr>
<td>


`OSD_SetPixel`

</td>
<td>


x0,y0,color

</td>
<td colspan="3">


Sets pixel &lt;x&gt;,&lt;y&gt; to color number &lt;color&gt;.  
Returns 0 on success, -1 on error.

</td>
</tr>
<tr>
<td>


`OSD_GetPixel`

</td>
<td>


x0,y0

</td>
<td colspan="3">


Returns color number of pixel &lt;x&gt;,&lt;y&gt;,  or -1.  
Command currently not supported by the AV7110\!

</td>
</tr>
<tr>
<td>


`OSD_SetRow`

</td>
<td>


x0,y0,x1,data

</td>
<td colspan="3">


Fills pixels x0,y through  x1,y with the content of data\[\].  
Returns 0 on success, -1 on clipping all pixel (no pixel
drawn).

</td>
</tr>
<tr>
<td>


`OSD_SetBlock`

</td>
<td>


x0,y0,x1,y1,  
increment\{color\},  
data

</td>
<td colspan="3">


Fills pixels x0,y0 through  x1,y1 with the content of data\[\].  
Inc contains the width of one line in the data block,  
inc&lt;=0 uses block width as line width.  
Returns 0 on success, -1 on clipping all pixel.

</td>
</tr>
<tr>
<td>


`OSD_FillRow`

</td>
<td>


x0,y0,x1,color

</td>
<td colspan="3">


Fills pixels x0,y through  x1,y with the color &lt;color&gt;.  
Returns 0 on success, -1 on clipping all pixel.

</td>
</tr>
<tr>
<td>


`OSD_FillBlock`

</td>
<td>


x0,y0,x1,y1,color

</td>
<td colspan="3">


Fills pixels x0,y0 through  x1,y1 with the color &lt;color&gt;.  
Returns 0 on success, -1 on clipping all pixel.

</td>
</tr>
<tr>
<td>


`OSD_Line`

</td>
<td>


x0,y0,x1,y1,color

</td>
<td colspan="3">


Draw a line from x0,y0 to x1,y1 with the color &lt;color&gt;.  
Returns 0 on success.

</td>
</tr>
<tr>
<td>


`OSD_Query`

</td>
<td>


x0,y0,x1,y1,  
xasp\{color\}; yasp=11

</td>
<td colspan="3">


Fills parameters with the picture dimensions and the pixel
aspect ratio.  
Returns 0 on success.  
Command currently not supported by the AV7110\!

</td>
</tr>
<tr>
<td>


`OSD_Test`

</td>
<td>


- <!-- empty source list item -->

</td>
<td colspan="3">


Draws a test picture.  
For debugging purposes only.  
Returns 0 on success.

</td>
</tr>
<tr>
<td>


`OSD_Text`

</td>
<td>


x0,y0,size,color,text

</td>
<td colspan="3">


Draws a text at position x0,y0 with the color &lt;color&gt;.

</td>
</tr>
<tr>
<td>


`OSD_SetWindow`

</td>
<td>


x0

</td>
<td colspan="3">


Set window with number 0&lt;x0&lt;8 as current.

</td>
</tr>
<tr>
<td>


`OSD_MoveWindow`

</td>
<td>


x0,y0

</td>
<td colspan="3">


Move current window to (x0, y0).

</td>
</tr>
<tr>
<td>


`OSD_OpenRaw`

</td>
<td>


x0,y0,x1,y1,  
[osd_raw_window_t](<#rst-osd-raw-window-t>) \{color\}

</td>
<td colspan="3">


Open other types of OSD windows.

</td>
</tr>
</tbody>
</table>

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

#### Description

The `OSD_Command` data type is used with the [OSD_SEND_CMD](<#rst-osd-send-cmd>) ioctl to tell the driver which OSD_Command to execute.

---

<a id="rst-osd-cmd-t"></a>

### osd_cmd_t

<a id="rst-synopsis-1"></a>

#### Synopsis



```c
typedef struct osd_cmd_s {
    OSD_Command cmd;
    int x0;
    int y0;
    int x1;
    int y1;
    int color;
    void __user *data;
} osd_cmd_t;
```

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

#### Variables


<table>
<tbody>
<tr>
<td>


`OSD_Command cmd`

</td>
<td>


[OSD_Command](<#rst-osd-command>) to be executed.

</td>
</tr>
<tr>
<td>


`int x0`

</td>
<td>


First horizontal position.

</td>
</tr>
<tr>
<td>


`int y0`

</td>
<td>


First vertical position.

</td>
</tr>
<tr>
<td>


`int x1`

</td>
<td>


Second horizontal position.

</td>
</tr>
<tr>
<td>


`int y1`

</td>
<td>


Second vertical position.

</td>
</tr>
<tr>
<td>


`int color`

</td>
<td>


Number of the color in the palette.

</td>
</tr>
<tr>
<td>


`void __user *data`

</td>
<td>


Command specific Data.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-1"></a>

#### Description

The `osd_cmd_t` data type is used with the [OSD_SEND_CMD](<#rst-osd-send-cmd>) ioctl. It contains the data for the OSD_Command and the [OSD_Command](<#rst-osd-command>) itself. The structure has to be passed to the driver and the components may be modified by it.

---

<a id="rst-osd-raw-window-t"></a>

### osd_raw_window_t

<a id="rst-synopsis-2"></a>

#### Synopsis



```c
typedef enum {
    OSD_BITMAP1,
    OSD_BITMAP2,
    OSD_BITMAP4,
    OSD_BITMAP8,
    OSD_BITMAP1HR,
    OSD_BITMAP2HR,
    OSD_BITMAP4HR,
    OSD_BITMAP8HR,
    OSD_YCRCB422,
    OSD_YCRCB444,
    OSD_YCRCB444HR,
    OSD_VIDEOTSIZE,
    OSD_VIDEOHSIZE,
    OSD_VIDEOQSIZE,
    OSD_VIDEODSIZE,
    OSD_VIDEOTHSIZE,
    OSD_VIDEOTQSIZE,
    OSD_VIDEOTDSIZE,
    OSD_VIDEONSIZE,
    OSD_CURSOR
} osd_raw_window_t;
```

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

#### Constants


<table>
<tbody>
<tr>
<td>


`OSD_BITMAP1`

</td>
<td colspan="2">


 1 bit bitmap

</td>
</tr>
<tr>
<td>


`OSD_BITMAP2`

</td>
<td colspan="2">


2 bit bitmap

</td>
</tr>
<tr>
<td>


`OSD_BITMAP4`

</td>
<td colspan="2">


4 bit bitmap

</td>
</tr>
<tr>
<td>


`OSD_BITMAP8`

</td>
<td colspan="2">


8 bit bitmap

</td>
</tr>
<tr>
<td>


`OSD_BITMAP1HR`

</td>
<td colspan="2">


1 Bit bitmap half resolution

</td>
</tr>
<tr>
<td>


`OSD_BITMAP2HR`

</td>
<td colspan="2">


2 Bit bitmap half resolution

</td>
</tr>
<tr>
<td>


`OSD_BITMAP4HR`

</td>
<td colspan="2">


4 Bit bitmap half resolution

</td>
</tr>
<tr>
<td>


`OSD_BITMAP8HR`

</td>
<td colspan="2">


8 Bit bitmap half resolution

</td>
</tr>
<tr>
<td>


`OSD_YCRCB422`

</td>
<td colspan="2">


4:2:2 YCRCB Graphic Display

</td>
</tr>
<tr>
<td>


`OSD_YCRCB444`

</td>
<td colspan="2">


4:4:4 YCRCB Graphic Display

</td>
</tr>
<tr>
<td>


`OSD_YCRCB444HR`

</td>
<td colspan="2">


4:4:4 YCRCB graphic half resolution

</td>
</tr>
<tr>
<td>


`OSD_VIDEOTSIZE`

</td>
<td colspan="2">


True Size Normal MPEG Video Display

</td>
</tr>
<tr>
<td>


`OSD_VIDEOHSIZE`

</td>
<td colspan="2">


MPEG Video Display Half Resolution

</td>
</tr>
<tr>
<td>


`OSD_VIDEOQSIZE`

</td>
<td colspan="2">


MPEG Video Display Quarter Resolution

</td>
</tr>
<tr>
<td>


`OSD_VIDEODSIZE`

</td>
<td colspan="2">


MPEG Video Display Double Resolution

</td>
</tr>
<tr>
<td>


`OSD_VIDEOTHSIZE`

</td>
<td colspan="2">


True Size MPEG Video Display Half Resolution

</td>
</tr>
<tr>
<td>


`OSD_VIDEOTQSIZE`

</td>
<td colspan="2">


True Size MPEG Video Display Quarter Resolution

</td>
</tr>
<tr>
<td>


`OSD_VIDEOTDSIZE`

</td>
<td colspan="2">


True Size MPEG Video Display Double Resolution

</td>
</tr>
<tr>
<td>


`OSD_VIDEONSIZE`

</td>
<td colspan="2">


Full Size MPEG Video Display

</td>
</tr>
<tr>
<td>


`OSD_CURSOR`

</td>
<td colspan="2">


Cursor

</td>
</tr>
</tbody>
</table>

<a id="rst-description-2"></a>

#### Description

The `osd_raw_window_t` data type is used with the [OSD_Command](<#rst-osd-command>) OSD_OpenRaw to tell the driver which type of OSD to open.

---

<a id="rst-osd-cap-t"></a>

### osd_cap_t

<a id="rst-synopsis-3"></a>

#### Synopsis



```c
typedef struct osd_cap_s {
    int  cmd;
#define OSD_CAP_MEMSIZE         1
    long val;
} osd_cap_t;
```

<a id="rst-variables-1"></a>

#### Variables


<table>
<tbody>
<tr>
<td>


`int  cmd`

</td>
<td>


Capability to query.

</td>
</tr>
<tr>
<td>


`long val`

</td>
<td>


Used to store the Data.

</td>
</tr>
</tbody>
</table>

<a id="rst-supported-capabilities"></a>

#### Supported capabilities


<table>
<tbody>
<tr>
<td>


`OSD_CAP_MEMSIZE`

</td>
<td>


Memory size installed on the card.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-3"></a>

#### Description

This structure of data used with the [OSD_GET_CAPABILITY](<#rst-osd-get-capability>) call.

---

<a id="rst-osd-function-calls"></a>

## OSD Function Calls

<a id="rst-osd-send-cmd"></a>

### OSD_SEND_CMD

<a id="rst-synopsis-4"></a>

#### Synopsis





<a id="c-OSD_SEND_CMD"></a>

```c
OSD_SEND_CMD
```



```c
int ioctl(int fd, int request = OSD_SEND_CMD, enum osd_cmd_t *cmd)
```

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

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Pointer to the location of the structure [osd_cmd_t](<#rst-osd-cmd-t>) for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-4"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl sends the [OSD_Command](<#rst-osd-command>) to the card.

<a id="rst-return-value"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.


<table>
<tbody>
<tr>
<td>


`EINVAL`

</td>
<td>


Command is out of range.

</td>
</tr>
</tbody>
</table>

---

<a id="rst-osd-get-capability"></a>

### OSD_GET_CAPABILITY

<a id="rst-synopsis-5"></a>

#### Synopsis





<a id="c-OSD_GET_CAPABILITY"></a>

```c
OSD_GET_CAPABILITY
```



```c
int ioctl(int fd, int request = OSD_GET_CAPABILITY,
struct osd_cap_t *cap)
```

<a id="rst-arguments-1"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `OSD_GET_CAPABILITY` for this command.

</td>
</tr>
<tr>
<td>


`unsigned int *cap`

</td>
<td colspan="2">


Pointer to the location of the structure [osd_cap_t](<#rst-osd-cap-t>) for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-5"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is used to get the capabilities of the OSD of the AV7110 based DVB-decoder-card in use.

> [!NOTE]
>
> The structure osd_cap_t has to be setup by the user and passed to the driver.

<a id="rst-return-value-1"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.


<table>
<tbody>
<tr>
<td>


`EINVAL`

</td>
<td>


Unsupported capability.

</td>
</tr>
</tbody>
</table>

---

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

### open()

<a id="rst-synopsis-6"></a>

#### Synopsis



```c
#include <fcntl.h>
```





<a id="c-open"></a>

```c
int open(const char *deviceName, int flags)
```

<a id="rst-arguments-2"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`const char *deviceName`

</td>
<td colspan="2">


Name of specific OSD device.

</td>
</tr>
<tr>
<td rowspan="4">


 `int flags`

</td>
<td colspan="2">


 A bit-wise OR of the following flags:

</td>
</tr>
<tr>
<td>


`O_RDONLY`

</td>
<td>


read-only access

</td>
</tr>
<tr>
<td>


`O_RDWR`

</td>
<td>


read/write access

</td>
</tr>
<tr>
<td>


`O_NONBLOCK`

</td>
<td>


Open in non-blocking mode  
(blocking mode is the default)

</td>
</tr>
</tbody>
</table>

<a id="rst-description-6"></a>

#### Description

This system call opens a named OSD device (e.g. `/dev/dvb/adapter?/osd0`) for subsequent use.

<a id="rst-return-value-2"></a>

#### Return Value


<table>
<tbody>
<tr>
<td>


`ENODEV`

</td>
<td>


Device driver not loaded/available.

</td>
</tr>
<tr>
<td>


`EINTERNAL`

</td>
<td>


Internal error.

</td>
</tr>
<tr>
<td>


`EBUSY`

</td>
<td>


Device or resource busy.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td>


Invalid argument.

</td>
</tr>
</tbody>
</table>

---

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

### close()

<a id="rst-synopsis-7"></a>

#### Synopsis





<a id="c-close"></a>

```c
int close(int fd)
```

<a id="rst-arguments-3"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>) .

</td>
</tr>
</tbody>
</table>

<a id="rst-description-7"></a>

#### Description

This system call closes a previously opened OSD device.

<a id="rst-return-value-3"></a>

#### Return Value


<table>
<tbody>
<tr>
<td>


`EBADF`

</td>
<td>


fd is not a valid open file descriptor.

</td>
</tr>
</tbody>
</table>

---

# DVB Video Device

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The DVB video device controls the MPEG2 video decoder of the DVB hardware. It can be accessed through /dev/dvb/adapter0/video0. Data types and ioctl definitions can be accessed by including linux/dvb/video.h in your application.

<a id="rst-dvb-video-device"></a>
<a id="rst-dvb-video"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later OR GPL-2.0 -->

<!-- c:namespace: dtv.legacy.video -->

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

The DVB video device controls the MPEG2 video decoder of the DVB hardware. It can be accessed through `/dev/dvb/adapter0/video0`. Data types and ioctl definitions can be accessed by including `linux/dvb/video.h` in your application.

Note that the DVB video device only controls decoding of the MPEG video stream, not its presentation on the TV or computer screen. On PCs this is typically handled by an associated video4linux device, e.g. `/dev/video`, which allows scaling and defining output windows.

Most DVB cards don’t have their own MPEG decoder, which results in the omission of the audio and video device as well as the video4linux device.

These ioctls were also used by V4L2 to control MPEG decoders implemented in V4L2. The use of these ioctls for that purpose has been made obsolete and proper V4L2 ioctls or controls have been created to replace that functionality. Use [V4L2 ioctls](</kernel/userspace/userspace-api/media-v4l/video.md#rst-video>) for new drivers\!

<a id="rst-video-data-types"></a>

## Video Data Types

<a id="rst-video-format-t"></a>

### video_format_t

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

#### Synopsis



```c
typedef enum {
    VIDEO_FORMAT_4_3,
    VIDEO_FORMAT_16_9,
    VIDEO_FORMAT_221_1
} video_format_t;
```

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

#### Constants


<table>
<tbody>
<tr>
<td>


`VIDEO_FORMAT_4_3`

</td>
<td>


Select 4:3 format.

</td>
</tr>
<tr>
<td>


`VIDEO_FORMAT_16_9`

</td>
<td>


Select 16:9 format.

</td>
</tr>
<tr>
<td>


`VIDEO_FORMAT_221_1`

</td>
<td>


Select 2.21:1 format.

</td>
</tr>
</tbody>
</table>

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

#### Description

The `video_format_t` data type is used in the [VIDEO_SET_FORMAT](<#rst-video-set-format>) function to tell the driver which aspect ratio the output hardware (e.g. TV) has. It is also used in the data structures [video_status](<#rst-video-status>) returned by [VIDEO_GET_STATUS](<#rst-video-get-status>) and [video_event](<#rst-video-event>) returned by [VIDEO_GET_EVENT](<#rst-video-get-event>) which report about the display format of the current video stream.

---

<a id="rst-video-displayformat-t"></a>

### video_displayformat_t

<a id="rst-synopsis-1"></a>

#### Synopsis



```c
typedef enum {
    VIDEO_PAN_SCAN,
    VIDEO_LETTER_BOX,
    VIDEO_CENTER_CUT_OUT
} video_displayformat_t;
```

<a id="rst-constants-1"></a>

#### Constants


<table>
<tbody>
<tr>
<td>


`VIDEO_PAN_SCAN`

</td>
<td>


Use pan and scan format.

</td>
</tr>
<tr>
<td>


`VIDEO_LETTER_BOX`

</td>
<td>


Use letterbox format.

</td>
</tr>
<tr>
<td>


`VIDEO_CENTER_CUT_OUT`

</td>
<td>


Use center cut out format.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-1"></a>

#### Description

In case the display format of the video stream and of the display hardware differ the application has to specify how to handle the cropping of the picture. This can be done using the [VIDEO_SET_DISPLAY_FORMAT](<#rst-video-set-display-format>) call which accepts this enum as argument.

---

<a id="rst-video-size-t"></a>

### video_size_t

<a id="rst-synopsis-2"></a>

#### Synopsis



```c
typedef struct {
    int w;
    int h;
    video_format_t aspect_ratio;
} video_size_t;
```

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

#### Variables


<table>
<tbody>
<tr>
<td>


`int w`

</td>
<td>


Video width in pixels.

</td>
</tr>
<tr>
<td>


`int h`

</td>
<td>


Video height in pixels.

</td>
</tr>
<tr>
<td>


[video_format_t](<#rst-video-format-t>) `aspect_ratio`

</td>
<td>


Aspect ratio.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-2"></a>

#### Description

Used in the struct [video_event](<#rst-video-event>). It stores the resolution and aspect ratio of the video.

---

<a id="rst-video-stream-source-t"></a>

### video_stream_source_t

<a id="rst-synopsis-3"></a>

#### Synopsis



```c
typedef enum {
    VIDEO_SOURCE_DEMUX,
    VIDEO_SOURCE_MEMORY
} video_stream_source_t;
```

<a id="rst-constants-2"></a>

#### Constants


<table>
<tbody>
<tr>
<td>


`VIDEO_SOURCE_DEMUX`

</td>
<td colspan="2">


 Select the demux as the main source.

</td>
</tr>
<tr>
<td>


`VIDEO_SOURCE_MEMORY`

</td>
<td colspan="2">


If this source is selected, the stream comes from the user through the write system call.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-3"></a>

#### Description

The video stream source is set through the [VIDEO_SELECT_SOURCE](<#rst-video-select-source>) call and can take the following values, depending on whether we are replaying from an internal (demuxer) or external (user write) source. VIDEO_SOURCE_DEMUX selects the demultiplexer (fed either by the frontend or the DVR device) as the source of the video stream. If VIDEO_SOURCE_MEMORY is selected the stream comes from the application through the [write()](<#rst-write>) system call.

---

<a id="rst-video-play-state-t"></a>

### video_play_state_t

<a id="rst-synopsis-4"></a>

#### Synopsis



```c
typedef enum {
    VIDEO_STOPPED,
    VIDEO_PLAYING,
    VIDEO_FREEZED
} video_play_state_t;
```

<a id="rst-constants-3"></a>

#### Constants


<table>
<tbody>
<tr>
<td>


`VIDEO_STOPPED`

</td>
<td>


Video is stopped.

</td>
</tr>
<tr>
<td>


`VIDEO_PLAYING`

</td>
<td>


Video is currently playing.

</td>
</tr>
<tr>
<td>


`VIDEO_FREEZED`

</td>
<td>


Video is frozen.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-4"></a>

#### Description

This values can be returned by the [VIDEO_GET_STATUS](<#rst-video-get-status>) call representing the state of video playback.

---

<a id="rst-struct-video-command"></a>

### struct video_command

<a id="rst-synopsis-5"></a>

#### Synopsis



```c
struct video_command {
    __u32 cmd;
    __u32 flags;
    union {
        struct {
            __u64 pts;
        } stop;

        struct {
            __s32 speed;
            __u32 format;
        } play;

        struct {
            __u32 data[16];
        } raw;
    };
};
```

<a id="rst-variables-1"></a>

#### Variables


<table>
<tbody>
<tr>
<td>


`__u32 cmd`

</td>
<td colspan="2">


[Decoder command](<#rst-decoder-command>)

</td>
</tr>
<tr>
<td>


`__u32 flags`

</td>
<td colspan="2">


Flags for the [Decoder command](<#rst-decoder-command>).

</td>
</tr>
<tr>
<td>


`struct stop`

</td>
<td>


`__u64 pts`

</td>
<td>


MPEG PTS

</td>
</tr>
<tr>
<td rowspan="6">


 `stuct play`

</td>
<td rowspan="5">


 `__s32 speed`

</td>
<td>


0 or 1000 specifies normal speed,

</td>
</tr>
<tr>
<td>


1:  specifies forward single stepping,

</td>
</tr>
<tr>
<td>


-1: specifies backward single stepping,

</td>
</tr>
<tr>
<td>


&gt;1: playback at speed / 1000 of the normal speed

</td>
</tr>
<tr>
<td>


&lt;-1: reverse playback at ( -speed / 1000 ) of the normal speed.

</td>
</tr>
<tr>
<td>


`__u32 format`

</td>
<td>


[Play input formats](<#rst-play-input-formats>)

</td>
</tr>
<tr>
<td>


`__u32 data[16]`

</td>
<td colspan="2">


Reserved

</td>
</tr>
</tbody>
</table>

<a id="rst-description-5"></a>

#### Description

The structure must be zeroed before use by the application. This ensures it can be extended safely in the future.

---

<a id="rst-predefined-decoder-commands-and-flags"></a>

### Predefined decoder commands and flags

<a id="rst-synopsis-6"></a>

#### Synopsis



```c
#define VIDEO_CMD_PLAY                      (0)
#define VIDEO_CMD_STOP                      (1)
#define VIDEO_CMD_FREEZE                    (2)
#define VIDEO_CMD_CONTINUE                  (3)

#define VIDEO_CMD_FREEZE_TO_BLACK      (1 << 0)

#define VIDEO_CMD_STOP_TO_BLACK        (1 << 0)
#define VIDEO_CMD_STOP_IMMEDIATELY     (1 << 1)

#define VIDEO_PLAY_FMT_NONE                 (0)
#define VIDEO_PLAY_FMT_GOP                  (1)

#define VIDEO_VSYNC_FIELD_UNKNOWN           (0)
#define VIDEO_VSYNC_FIELD_ODD               (1)
#define VIDEO_VSYNC_FIELD_EVEN              (2)
#define VIDEO_VSYNC_FIELD_PROGRESSIVE       (3)
```

<a id="rst-constants-4"></a>

#### Constants


<table>
<tbody>
<tr>
<td rowspan="4">


 <a id="rst-decoder-command"></a>

</td>
<td>


`VIDEO_CMD_PLAY`

</td>
<td>


Start playback.

</td>
</tr>
<tr>
<td>


`VIDEO_CMD_STOP`

</td>
<td>


Stop playback.

</td>
</tr>
<tr>
<td>


`VIDEO_CMD_FREEZE`

</td>
<td>


Freeze playback.

</td>
</tr>
<tr>
<td>


`VIDEO_CMD_CONTINUE`

</td>
<td>


Continue playback after freeze.

</td>
</tr>
<tr>
<td>


Flags for `VIDEO_CMD_FREEZE`

</td>
<td>


`VIDEO_CMD_FREEZE_TO_BLACK`

</td>
<td>


Show black picture on freeze.

</td>
</tr>
<tr>
<td rowspan="2">


 Flags for `VIDEO_CMD_STOP`

</td>
<td>


`VIDEO_CMD_STOP_TO_BLACK`

</td>
<td>


Show black picture on stop.

</td>
</tr>
<tr>
<td>


`VIDEO_CMD_STOP_IMMEDIATELY`

</td>
<td>


Stop immediately, without emptying buffers.

</td>
</tr>
<tr>
<td rowspan="2">


 <a id="rst-play-input-formats"></a>

</td>
<td>


`VIDEO_PLAY_FMT_NONE`

</td>
<td>


The decoder has no special format requirements

</td>
</tr>
<tr>
<td>


`VIDEO_PLAY_FMT_GOP`

</td>
<td>


The decoder requires full GOPs

</td>
</tr>
<tr>
<td rowspan="4">


 Field order

</td>
<td>


`VIDEO_VSYNC_FIELD_UNKNOWN`

</td>
<td>


FIELD_UNKNOWN can be used if the hardware does not know whether the Vsync is for an odd, even or progressive (i.e. non-interlaced) field.

</td>
</tr>
<tr>
<td>


`VIDEO_VSYNC_FIELD_ODD`

</td>
<td>


Vsync is for an odd field.

</td>
</tr>
<tr>
<td>


`VIDEO_VSYNC_FIELD_EVEN`

</td>
<td>


Vsync is for an even field.

</td>
</tr>
<tr>
<td>


`VIDEO_VSYNC_FIELD_PROGRESSIVE`

</td>
<td>


progressive (i.e. non-interlaced)

</td>
</tr>
</tbody>
</table>

---

<a id="rst-video-event"></a>

### video_event

<a id="rst-synopsis-7"></a>

#### Synopsis



```c
struct video_event {
    __s32 type;
#define VIDEO_EVENT_SIZE_CHANGED        1
#define VIDEO_EVENT_FRAME_RATE_CHANGED  2
#define VIDEO_EVENT_DECODER_STOPPED     3
#define VIDEO_EVENT_VSYNC               4
    long timestamp;
    union {
        video_size_t size;
        unsigned int frame_rate;
        unsigned char vsync_field;
    } u;
};
```

<a id="rst-variables-2"></a>

#### Variables


<table>
<tbody>
<tr>
<td rowspan="5">


 `__s32 type`

</td>
<td colspan="2">


 Event type.

</td>
</tr>
<tr>
<td>


`VIDEO_EVENT_SIZE_CHANGED`

</td>
<td>


Size changed.

</td>
</tr>
<tr>
<td>


`VIDEO_EVENT_FRAME_RATE_CHANGED`

</td>
<td>


Framerate changed.

</td>
</tr>
<tr>
<td>


`VIDEO_EVENT_DECODER_STOPPED`

</td>
<td>


Decoder stopped.

</td>
</tr>
<tr>
<td>


`VIDEO_EVENT_VSYNC`

</td>
<td>


Vsync occurred.

</td>
</tr>
<tr>
<td>


`long timestamp`

</td>
<td colspan="2">


 MPEG PTS at occurrence.

</td>
</tr>
<tr>
<td rowspan="3">


 `union u`

</td>
<td>


[video_size_t](<#rst-video-size-t>) size

</td>
<td>


Resolution and aspect ratio of the video.

</td>
</tr>
<tr>
<td>


`unsigned int frame_rate`

</td>
<td>


in frames per 1000sec

</td>
</tr>
<tr>
<td>


`unsigned char vsync_field`

</td>
<td>


unknown / odd / even / progressive  
See: [Predefined decoder commands and flags](<#rst-predefined-decoder-commands-and-flags>)

</td>
</tr>
</tbody>
</table>

<a id="rst-description-6"></a>

#### Description

This is the structure of a video event as it is returned by the [VIDEO_GET_EVENT](<#rst-video-get-event>) call. See there for more details.

---

<a id="rst-video-status"></a>

### video_status

<a id="rst-synopsis-8"></a>

#### Synopsis

The [VIDEO_GET_STATUS](<#rst-video-get-status>) call returns the following structure informing about various states of the playback operation.



```c
struct video_status {
    int                    video_blank;
    video_play_state_t     play_state;
    video_stream_source_t  stream_source;
    video_format_t         video_format;
    video_displayformat_t  display_format;
};
```

<a id="rst-variables-3"></a>

#### Variables


<table>
<tbody>
<tr>
<td rowspan="3">


 `int video_blank`

</td>
<td colspan="2">


 Show blank video on freeze?

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


Blank screen when freeze.

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


Show last decoded frame.

</td>
</tr>
<tr>
<td>


[video_play_state_t](<#rst-video-play-state-t>) `play_state`

</td>
<td colspan="2">


Current state of playback.

</td>
</tr>
<tr>
<td>


[video_stream_source_t](<#rst-video-stream-source-t>) `stream_source`

</td>
<td colspan="2">


Current source (demux/memory).

</td>
</tr>
<tr>
<td>


[video_format_t](<#rst-video-format-t>) `video_format`

</td>
<td colspan="2">


Current aspect ratio of stream.

</td>
</tr>
<tr>
<td>


[video_displayformat_t](<#rst-video-displayformat-t>) `display_format`

</td>
<td colspan="2">


Applied cropping mode.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-7"></a>

#### Description

If `video_blank` is set `TRUE` video will be blanked out if the channel is changed or if playback is stopped. Otherwise, the last picture will be displayed. `play_state` indicates if the video is currently frozen, stopped, or being played back. The `stream_source` corresponds to the selected source for the video stream. It can come either from the demultiplexer or from memory. The `video_format` indicates the aspect ratio (one of 4:3 or 16:9) of the currently played video stream. Finally, `display_format` corresponds to the applied cropping mode in case the source video format is not the same as the format of the output device.

---

<a id="rst-video-still-picture"></a>

### video_still_picture

<a id="rst-synopsis-9"></a>

#### Synopsis



```c
struct video_still_picture {
char *iFrame;
int32_t size;
};
```

<a id="rst-variables-4"></a>

#### Variables


<table>
<tbody>
<tr>
<td>


`char *iFrame`

</td>
<td>


Pointer to a single iframe in memory.

</td>
</tr>
<tr>
<td>


`int32_t size`

</td>
<td>


Size of the iframe.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-8"></a>

#### Description

An I-frame displayed via the [VIDEO_STILLPICTURE](<#rst-video-stillpicture>) call is passed on within this structure.

---

<a id="rst-video-capabilities"></a>

### video capabilities

<a id="rst-synopsis-10"></a>

#### Synopsis



```c
#define VIDEO_CAP_MPEG1   1
#define VIDEO_CAP_MPEG2   2
#define VIDEO_CAP_SYS     4
#define VIDEO_CAP_PROG    8
```

<a id="rst-constants-5"></a>

#### Constants

Bit definitions for capabilities:


<table>
<tbody>
<tr>
<td>


`VIDEO_CAP_MPEG1`

</td>
<td colspan="2">


 The hardware can decode MPEG1.

</td>
</tr>
<tr>
<td>


`VIDEO_CAP_MPEG2`

</td>
<td colspan="2">


The hardware can decode MPEG2.

</td>
</tr>
<tr>
<td>


`VIDEO_CAP_SYS`

</td>
<td colspan="2">


The video device accepts system stream.

You still have to open the video and the audio device but only send the stream to the video device.

</td>
</tr>
<tr>
<td>


`VIDEO_CAP_PROG`

</td>
<td colspan="2">


The video device accepts program stream.

You still have to open the video and the audio device but only send the stream to the video device.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-9"></a>

#### Description

A call to [VIDEO_GET_CAPABILITIES](<#rst-video-get-capabilities>) returns an unsigned integer with the following bits set according to the hardware's capabilities.

---

<a id="rst-video-function-calls"></a>

## Video Function Calls

<a id="rst-video-stop"></a>

### VIDEO_STOP

<a id="rst-synopsis-11"></a>

#### Synopsis





<a id="c-VIDEO_STOP"></a>

```c
VIDEO_STOP
```



```c
int ioctl(fd, VIDEO_STOP, int mode)
```

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

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


 Equals `VIDEO_STOP` for this command.

</td>
</tr>
<tr>
<td rowspan="3">


 `int mode`

</td>
<td colspan="2">


 Indicates how the screen shall be handled.

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


Blank screen when stop.

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


Show last decoded frame.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-10"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is for Digital TV devices only. To control a V4L2 decoder use the V4L2 [ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) instead.

This ioctl call asks the Video Device to stop playing the current stream. Depending on the input parameter, the screen can be blanked out or displaying the last decoded frame.

<a id="rst-return-value"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-play"></a>

### VIDEO_PLAY

<a id="rst-synopsis-12"></a>

#### Synopsis





<a id="c-VIDEO_PLAY"></a>

```c
VIDEO_PLAY
```



```c
int ioctl(fd, VIDEO_PLAY)
```

<a id="rst-arguments-1"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_PLAY` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-11"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is for Digital TV devices only. To control a V4L2 decoder use the V4L2 [ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) instead.

This ioctl call asks the Video Device to start playing a video stream from the selected source.

<a id="rst-return-value-1"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-freeze"></a>

### VIDEO_FREEZE

<a id="rst-synopsis-13"></a>

#### Synopsis





<a id="c-VIDEO_FREEZE"></a>

```c
VIDEO_FREEZE
```



```c
int ioctl(fd, VIDEO_FREEZE)
```

<a id="rst-arguments-2"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_FREEZE` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-12"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is for Digital TV devices only. To control a V4L2 decoder use the V4L2 [ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) instead.

This ioctl call suspends the live video stream being played, if VIDEO_SOURCE_DEMUX is selected. Decoding and playing are frozen. It is then possible to restart the decoding and playing process of the video stream using the [VIDEO_CONTINUE](<#rst-video-continue>) command. If VIDEO_SOURCE_MEMORY is selected in the ioctl call [VIDEO_SELECT_SOURCE](<#rst-video-select-source>), the Digital TV subsystem will not decode any more data until the ioctl call [VIDEO_CONTINUE](<#rst-video-continue>) or [VIDEO_PLAY](<#rst-video-play>) is performed.

<a id="rst-return-value-2"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-continue"></a>

### VIDEO_CONTINUE

<a id="rst-synopsis-14"></a>

#### Synopsis





<a id="c-VIDEO_CONTINUE"></a>

```c
VIDEO_CONTINUE
```



```c
int ioctl(fd, VIDEO_CONTINUE)
```

<a id="rst-arguments-3"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_CONTINUE` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-13"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is for Digital TV devices only. To control a V4L2 decoder use the V4L2 [ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) instead.

This ioctl call restarts decoding and playing processes of the video stream which was played before a call to [VIDEO_FREEZE](<#rst-video-freeze>) was made.

<a id="rst-return-value-3"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-select-source"></a>

### VIDEO_SELECT_SOURCE

<a id="rst-synopsis-15"></a>

#### Synopsis





<a id="c-VIDEO_SELECT_SOURCE"></a>

```c
VIDEO_SELECT_SOURCE
```



```c
int ioctl(fd, VIDEO_SELECT_SOURCE, video_stream_source_t source)
```

<a id="rst-arguments-4"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_SELECT_SOURCE` for this command.

</td>
</tr>
<tr>
<td>


[video_stream_source_t](<#rst-video-stream-source-t>) `source`

</td>
<td colspan="2">


Indicates which source shall be used for the Video stream.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-14"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is for Digital TV devices only. This ioctl was also supported by the V4L2 ivtv driver, but that has been replaced by the ivtv-specific `IVTV_IOC_PASSTHROUGH_MODE` ioctl.

This ioctl call informs the video device which source shall be used for the input data. The possible sources are demux or memory. If memory is selected, the data is fed to the video device through the write command using the struct [video_stream_source_t](<#rst-video-stream-source-t>). If demux is selected, the data is directly transferred from the onboard demux-device to the decoder.

The data fed to the decoder is also controlled by the PID-filter. Output selection: `dmx_output` `DMX_OUT_DECODER`.

<a id="rst-return-value-4"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-set-blank"></a>

### VIDEO_SET_BLANK

<a id="rst-synopsis-16"></a>

#### Synopsis





<a id="c-VIDEO_SET_BLANK"></a>

```c
VIDEO_SET_BLANK
```



```c
int ioctl(fd, VIDEO_SET_BLANK, int mode)
```

<a id="rst-arguments-5"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


 Equals `VIDEO_SET_BLANK` for this command.

</td>
</tr>
<tr>
<td rowspan="3">


 `int mode`

</td>
<td colspan="2">


 Indicates if the screen shall be blanked.

</td>
</tr>
<tr>
<td>


TRUE  ( \!= 0 )

</td>
<td>


Blank screen when stop.

</td>
</tr>
<tr>
<td>


FALSE ( == 0 )

</td>
<td>


Show last decoded frame.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-15"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Video Device to blank out the picture.

<a id="rst-return-value-5"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-get-status"></a>

### VIDEO_GET_STATUS

<a id="rst-synopsis-17"></a>

#### Synopsis





<a id="c-VIDEO_GET_STATUS"></a>

```c
VIDEO_GET_STATUS
```



```c
int ioctl(fd, int request = VIDEO_GET_STATUS,
struct video_status *status)
```

<a id="rst-arguments-6"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_GET_STATUS` for this command.

</td>
</tr>
<tr>
<td>


`struct` [video_status](<#rst-video-status>) `*status`

</td>
<td colspan="2">


Returns the current status of the Video Device.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-16"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Video Device to return the current status of the device.

<a id="rst-return-value-6"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-get-event"></a>

### VIDEO_GET_EVENT

<a id="rst-synopsis-18"></a>

#### Synopsis





<a id="c-VIDEO_GET_EVENT"></a>

```c
VIDEO_GET_EVENT
```



```c
int ioctl(fd, int request = VIDEO_GET_EVENT,
struct video_event *ev)
```

<a id="rst-arguments-7"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_GET_EVENT` for this command.

</td>
</tr>
<tr>
<td>


`struct` [video_event](<#rst-video-event>) `*ev`

</td>
<td colspan="2">


Points to the location where the event, if any, is to be stored.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-17"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl is for DVB devices only. To get events from a V4L2 decoder use the V4L2 [ioctl VIDIOC_DQEVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-vidioc-dqevent>) ioctl instead.

This ioctl call returns an event of type [video_event](<#rst-video-event>) if available. A certain number of the latest events will be cued and returned in order of occurrence. Older events may be discarded if not fetched in time. If an event is not available, the behavior depends on whether the device is in blocking or non-blocking mode. In the latter case, the call fails immediately with errno set to `EWOULDBLOCK`. In the former case, the call blocks until an event becomes available. The standard Linux poll() and/or select() system calls can be used with the device file descriptor to watch for new events. For select(), the file descriptor should be included in the exceptfds argument, and for poll(), POLLPRI should be specified as the wake-up condition. Read-only permissions are sufficient for this ioctl call.

<a id="rst-return-value-7"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.


<table>
<tbody>
<tr>
<td>


`EWOULDBLOCK`

</td>
<td colspan="2">


 There is no event pending, and the device is in non-blocking mode.

</td>
</tr>
<tr>
<td>


`EOVERFLOW`

</td>
<td colspan="2">


Overflow in event queue - one or more events were lost.

</td>
</tr>
</tbody>
</table>

---

<a id="rst-video-set-display-format"></a>

### VIDEO_SET_DISPLAY_FORMAT

<a id="rst-synopsis-19"></a>

#### Synopsis





<a id="c-VIDEO_SET_DISPLAY_FORMAT"></a>

```c
VIDEO_SET_DISPLAY_FORMAT
```



```c
int ioctl(fd, int request = VIDEO_SET_DISPLAY_FORMAT,
video_display_format_t format)
```

<a id="rst-arguments-8"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_SET_DISPLAY_FORMAT` for this command.

</td>
</tr>
<tr>
<td>


[video_displayformat_t](<#rst-video-displayformat-t>) `format`

</td>
<td colspan="2">


Selects the video format to be used.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-18"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Video Device to select the video format to be applied by the MPEG chip on the video.

<a id="rst-return-value-8"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-stillpicture"></a>

### VIDEO_STILLPICTURE

<a id="rst-synopsis-20"></a>

#### Synopsis





<a id="c-VIDEO_STILLPICTURE"></a>

```c
VIDEO_STILLPICTURE
```



```c
int ioctl(fd, int request = VIDEO_STILLPICTURE,
struct video_still_picture *sp)
```

<a id="rst-arguments-9"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_STILLPICTURE` for this command.

</td>
</tr>
<tr>
<td>


`struct` [video_still_picture](<#rst-video-still-picture>) `*sp`

</td>
<td colspan="2">


Pointer to the location where the struct with the I-frame and size is stored.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-19"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Video Device to display a still picture (I-frame). The input data shall be the section of an elementary video stream containing an I-frame. Typically this section is extracted from a TS or PES recording. Resolution and codec (see [video capabilities](<#rst-video-capabilities>)) must be supported by the device. If the pointer is NULL, then the current displayed still picture is blanked.

e.g. The AV7110 supports MPEG1 and MPEG2 with the common PAL-SD resolutions.

<a id="rst-return-value-9"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-fast-forward"></a>

### VIDEO_FAST_FORWARD

<a id="rst-synopsis-21"></a>

#### Synopsis





<a id="c-VIDEO_FAST_FORWARD"></a>

```c
VIDEO_FAST_FORWARD
```



```c
int ioctl(fd, int request = VIDEO_FAST_FORWARD, int nFrames)
```

<a id="rst-arguments-10"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_FAST_FORWARD` for this command.

</td>
</tr>
<tr>
<td>


`int nFrames`

</td>
<td colspan="2">


The number of frames to skip.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-20"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the Video Device to skip decoding of N number of I-frames. This call can only be used if `VIDEO_SOURCE_MEMORY` is selected.

<a id="rst-return-value-10"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.


<table>
<tbody>
<tr>
<td>


`EPERM`

</td>
<td>


Mode `VIDEO_SOURCE_MEMORY` not selected.

</td>
</tr>
</tbody>
</table>

---

<a id="rst-video-slowmotion"></a>

### VIDEO_SLOWMOTION

<a id="rst-synopsis-22"></a>

#### Synopsis





<a id="c-VIDEO_SLOWMOTION"></a>

```c
VIDEO_SLOWMOTION
```



```c
int ioctl(fd, int request = VIDEO_SLOWMOTION, int nFrames)
```

<a id="rst-arguments-11"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_SLOWMOTION` for this command.

</td>
</tr>
<tr>
<td>


`int nFrames`

</td>
<td colspan="2">


The number of times to repeat each frame.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-21"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the video device to repeat decoding frames N number of times. This call can only be used if `VIDEO_SOURCE_MEMORY` is selected.

<a id="rst-return-value-11"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.


<table>
<tbody>
<tr>
<td>


`EPERM`

</td>
<td>


Mode `VIDEO_SOURCE_MEMORY` not selected.

</td>
</tr>
</tbody>
</table>

---

<a id="rst-video-get-capabilities"></a>

### VIDEO_GET_CAPABILITIES

<a id="rst-synopsis-23"></a>

#### Synopsis





<a id="c-VIDEO_GET_CAPABILITIES"></a>

```c
VIDEO_GET_CAPABILITIES
```



```c
int ioctl(fd, int request = VIDEO_GET_CAPABILITIES, unsigned int *cap)
```

<a id="rst-arguments-12"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_GET_CAPABILITIES` for this command.

</td>
</tr>
<tr>
<td>


`unsigned int *cap`

</td>
<td colspan="2">


Pointer to a location where to store the capability information.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-22"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call asks the video device about its decoding capabilities. On success it returns an integer which has bits set according to the defines in [video capabilities](<#rst-video-capabilities>).

<a id="rst-return-value-12"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-clear-buffer"></a>

### VIDEO_CLEAR_BUFFER

<a id="rst-synopsis-24"></a>

#### Synopsis





<a id="c-VIDEO_CLEAR_BUFFER"></a>

```c
VIDEO_CLEAR_BUFFER
```



```c
int ioctl(fd, int request = VIDEO_CLEAR_BUFFER)
```

<a id="rst-arguments-13"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_CLEAR_BUFFER` for this command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-23"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl call clears all video buffers in the driver and in the decoder hardware.

<a id="rst-return-value-13"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-set-streamtype"></a>

### VIDEO_SET_STREAMTYPE

<a id="rst-synopsis-25"></a>

#### Synopsis





<a id="c-VIDEO_SET_STREAMTYPE"></a>

```c
VIDEO_SET_STREAMTYPE
```



```c
int ioctl(fd, int request = VIDEO_SET_STREAMTYPE, int type)
```

<a id="rst-arguments-14"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_SET_STREAMTYPE` for this command.

</td>
</tr>
<tr>
<td>


`int type`

</td>
<td colspan="2">


Stream type.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-24"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl tells the driver which kind of stream to expect being written to it. Intelligent decoder might also not support or ignore (like the AV7110) this call and determine the stream type themselves.

Currently used stream types:


<table>
<thead>
<tr>
<th>


Codec

</th>
<th>


Stream type

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


MPEG2

</td>
<td>


0

</td>
</tr>
<tr>
<td>


MPEG4 h.264

</td>
<td>


1

</td>
</tr>
<tr>
<td>


VC1

</td>
<td>


3

</td>
</tr>
<tr>
<td>


MPEG4 Part2

</td>
<td>


4

</td>
</tr>
<tr>
<td>


VC1 SM

</td>
<td>


5

</td>
</tr>
<tr>
<td>


MPEG1

</td>
<td>


6

</td>
</tr>
<tr>
<td>


HEVC h.265

</td>
<td>


7  
DREAMBOX: 22

</td>
</tr>
<tr>
<td>


AVS

</td>
<td>


16

</td>
</tr>
<tr>
<td>


AVS2

</td>
<td>


40

</td>
</tr>
</tbody>
</table>

Not every decoder supports all stream types.

<a id="rst-return-value-14"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-set-format"></a>

### VIDEO_SET_FORMAT

<a id="rst-synopsis-26"></a>

#### Synopsis





<a id="c-VIDEO_SET_FORMAT"></a>

```c
VIDEO_SET_FORMAT
```



```c
int ioctl(fd, int request = VIDEO_SET_FORMAT, video_format_t format)
```

<a id="rst-arguments-15"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_SET_FORMAT` for this command.

</td>
</tr>
<tr>
<td>


[video_format_t](<#rst-video-format-t>) `format`

</td>
<td colspan="2">


Video format of TV as defined in section [video_format_t](<#rst-video-format-t>).

</td>
</tr>
</tbody>
</table>

<a id="rst-description-25"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl sets the screen format (aspect ratio) of the connected output device (TV) so that the output of the decoder can be adjusted accordingly.

<a id="rst-return-value-15"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-get-size"></a>

### VIDEO_GET_SIZE

<a id="rst-synopsis-27"></a>

#### Synopsis





<a id="c-VIDEO_GET_SIZE"></a>

```c
VIDEO_GET_SIZE
```



```c
int ioctl(int fd, int request = VIDEO_GET_SIZE, video_size_t *size)
```

<a id="rst-arguments-16"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call, to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_GET_SIZE` for this command.

</td>
</tr>
<tr>
<td>


[video_size_t](<#rst-video-size-t>) `*size`

</td>
<td colspan="2">


Returns the size and aspect ratio.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-26"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

This ioctl returns the size and aspect ratio.

<a id="rst-return-value-16"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-get-pts"></a>

### VIDEO_GET_PTS

<a id="rst-synopsis-28"></a>

#### Synopsis





<a id="c-VIDEO_GET_PTS"></a>

```c
VIDEO_GET_PTS
```



```c
int ioctl(int fd, int request = VIDEO_GET_PTS, __u64 *pts)
```

<a id="rst-arguments-17"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_GET_PTS` for this command.

</td>
</tr>
<tr>
<td>


`__u64 *pts`

</td>
<td colspan="2">


Returns the 33-bit timestamp as defined in ITU T-REC-H.222.0 / ISO/IEC 13818-1.

The PTS should belong to the currently played frame if possible, but may also be a value close to it like the PTS of the last decoded frame or the last PTS extracted by the PES parser.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-27"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

For V4L2 decoders this ioctl has been replaced by the `V4L2_CID_MPEG_VIDEO_DEC_PTS` control.

This ioctl call asks the Video Device to return the current PTS timestamp.

<a id="rst-return-value-17"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-get-frame-count"></a>

### VIDEO_GET_FRAME_COUNT

<a id="rst-synopsis-29"></a>

#### Synopsis





<a id="c-VIDEO_GET_FRAME_COUNT"></a>

```c
VIDEO_GET_FRAME_COUNT
```



```c
int ioctl(int fd, VIDEO_GET_FRAME_COUNT, __u64 *pts)
```

<a id="rst-arguments-18"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_GET_FRAME_COUNT` for this command.

</td>
</tr>
<tr>
<td>


`__u64 *pts`

</td>
<td colspan="2">


Returns the number of frames displayed since the decoder was started.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-28"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

For V4L2 decoders this ioctl has been replaced by the `V4L2_CID_MPEG_VIDEO_DEC_FRAME` control.

This ioctl call asks the Video Device to return the number of displayed frames since the decoder was started.

<a id="rst-return-value-18"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-command"></a>

### VIDEO_COMMAND

<a id="rst-synopsis-30"></a>

#### Synopsis





<a id="c-VIDEO_COMMAND"></a>

```c
VIDEO_COMMAND
```



```c
int ioctl(int fd, int request = VIDEO_COMMAND,
struct video_command *cmd)
```

<a id="rst-arguments-19"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_COMMAND` for this command.

</td>
</tr>
<tr>
<td>


[struct video_command](<#rst-struct-video-command>) `*cmd`

</td>
<td colspan="2">


Commands the decoder.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-29"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

For V4L2 decoders this ioctl has been replaced by the [ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) ioctl.

This ioctl commands the decoder. The [struct video_command](<#rst-struct-video-command>) is a subset of the `v4l2_decoder_cmd` struct, so refer to the [ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) documentation for more information.

<a id="rst-return-value-19"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

<a id="rst-video-try-command"></a>

### VIDEO_TRY_COMMAND

<a id="rst-synopsis-31"></a>

#### Synopsis





<a id="c-VIDEO_TRY_COMMAND"></a>

```c
VIDEO_TRY_COMMAND
```



```c
int ioctl(int fd, int request = VIDEO_TRY_COMMAND,
struct video_command *cmd)
```

<a id="rst-arguments-20"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`int request`

</td>
<td colspan="2">


Equals `VIDEO_TRY_COMMAND` for this command.

</td>
</tr>
<tr>
<td>


[struct video_command](<#rst-struct-video-command>) `*cmd`

</td>
<td colspan="2">


Try a decoder command.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-30"></a>

#### Description

> [!NOTE]
>
> Do **not** use in new drivers\! See: [General Notes](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-notes>)

For V4L2 decoders this ioctl has been replaced by the [VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) ioctl.

This ioctl tries a decoder command. The [struct video_command](<#rst-struct-video-command>) is a subset of the `v4l2_decoder_cmd` struct, so refer to the [VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>) documentation for more information.

<a id="rst-return-value-20"></a>

#### Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

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

### open()

<a id="rst-synopsis-32"></a>

#### Synopsis



```c
#include <fcntl.h>
```





<a id="c-open"></a>

```c
int open(const char *deviceName, int flags)
```

<a id="rst-arguments-21"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`const char *deviceName`

</td>
<td colspan="2">


Name of specific video device.

</td>
</tr>
<tr>
<td rowspan="4">


 `int flags`

</td>
<td colspan="2">


 A bit-wise OR of the following flags:

</td>
</tr>
<tr>
<td>


`O_RDONLY`

</td>
<td>


read-only access

</td>
</tr>
<tr>
<td>


`O_RDWR`

</td>
<td>


read/write access

</td>
</tr>
<tr>
<td>


`O_NONBLOCK`

</td>
<td>


Open in non-blocking mode  
(blocking mode is the default)

</td>
</tr>
</tbody>
</table>

<a id="rst-description-31"></a>

#### Description

This system call opens a named video device (e.g. /dev/dvb/adapter?/video?) for subsequent use.

When an open() call has succeeded, the device will be ready for use. The significance of blocking or non-blocking mode is described in the documentation for functions where there is a difference. It does not affect the semantics of the open() call itself. A device opened in blocking mode can later be put into non-blocking mode (and vice versa) using the F_SETFL command of the fcntl system call. This is a standard system call, documented in the Linux manual page for fcntl. Only one user can open the Video Device in O_RDWR mode. All other attempts to open the device in this mode will fail, and an error-code will be returned. If the Video Device is opened in O_RDONLY mode, the only ioctl call that can be used is [VIDEO_GET_STATUS](<#rst-video-get-status>). All other call will return an error code.

<a id="rst-return-value-21"></a>

#### Return Value


<table>
<tbody>
<tr>
<td>


`ENODEV`

</td>
<td colspan="2">


 Device driver not loaded/available.

</td>
</tr>
<tr>
<td>


`EINTERNAL`

</td>
<td colspan="2">


Internal error.

</td>
</tr>
<tr>
<td>


`EBUSY`

</td>
<td colspan="2">


Device or resource busy.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td colspan="2">


Invalid argument.

</td>
</tr>
</tbody>
</table>

---

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

### close()

<a id="rst-synopsis-33"></a>

#### Synopsis





<a id="c-close"></a>

```c
int close(int fd)
```

<a id="rst-arguments-22"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
</tbody>
</table>

<a id="rst-description-32"></a>

#### Description

This system call closes a previously opened video device.

<a id="rst-return-value-22"></a>

#### Return Value


<table>
<tbody>
<tr>
<td>


`EBADF`

</td>
<td>


fd is not a valid open file descriptor.

</td>
</tr>
</tbody>
</table>

---

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

### write()

<a id="rst-synopsis-34"></a>

#### Synopsis





<a id="c-write"></a>

```c
size_t write(int fd, const void *buf, size_t count)
```

<a id="rst-arguments-23"></a>

#### Arguments


<table>
<tbody>
<tr>
<td>


`int fd`

</td>
<td colspan="2">


 File descriptor returned by a previous call to [open()](<#rst-open>).

</td>
</tr>
<tr>
<td>


`void *buf`

</td>
<td colspan="2">


Pointer to the buffer containing the PES data.

</td>
</tr>
<tr>
<td>


`size_t count`

</td>
<td colspan="2">


Size of buf.

</td>
</tr>
</tbody>
</table>

<a id="rst-description-33"></a>

#### Description

This system call can only be used if VIDEO_SOURCE_MEMORY is selected in the ioctl call [VIDEO_SELECT_SOURCE](<#rst-video-select-source>). The data provided shall be in PES format, unless the capability allows other formats. TS is the most common format for storing DVB-data, it is usually supported too. If O_NONBLOCK is not specified the function will block until buffer space is available. The amount of data to be transferred is implied by count.

> [!NOTE]
>
> See: [DVB Data Formats](</kernel/userspace/userspace-api/media-dvb/legacy-dvb-decoder-api.md#rst-legacy-dvb-decoder-formats>)

<a id="rst-return-value-23"></a>

#### Return Value


<table>
<tbody>
<tr>
<td>


`EPERM`

</td>
<td colspan="2">


 Mode `VIDEO_SOURCE_MEMORY` not selected.

</td>
</tr>
<tr>
<td>


`ENOMEM`

</td>
<td colspan="2">


Attempted to write more data than the internal buffer can hold.

</td>
</tr>
<tr>
<td>


`EBADF`

</td>
<td colspan="2">


fd is not a valid open file descriptor.

</td>
</tr>
</tbody>
</table>

---

# ioctl NET_ADD_IF

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> NET_ADD_IF - Creates a new network interface for a given Packet ID.

<a id="rst-ioctl-net-add-if"></a>
<a id="rst-net-add-if"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.net -->

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

## Name

NET_ADD_IF - Creates a new network interface for a given Packet ID.

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

## Synopsis





<a id="c-NET_ADD_IF"></a>

```c
NET_ADD_IF
```

`int ioctl(int fd, NET_ADD_IF, struct dvb_net_if *net_if)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`net_if`**

  pointer to struct `dvb_net_if`

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

## Description

The NET_ADD_IF ioctl system call selects the Packet ID (PID) that contains a TCP/IP traffic, the type of encapsulation to be used (MPE or ULE) and the interface number for the new interface to be created. When the system call successfully returns, a new virtual network interface is created.

The struct `dvb_net_if`::ifnum field will be filled with the number of the created interface.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, and `ca_slot_info` is filled.

On error -1 is returned, and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl NET_GET_IF

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> NET_GET_IF - Read the configuration data of an interface created via - NET_ADD_IF <net>.

<a id="rst-ioctl-net-get-if"></a>
<a id="rst-net-get-if"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.net -->

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

## Name

NET_GET_IF - Read the configuration data of an interface created via - [NET_ADD_IF](</kernel/userspace/userspace-api/media-dvb/net.md#rst-net>).

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

## Synopsis





<a id="c-NET_GET_IF"></a>

```c
NET_GET_IF
```

`int ioctl(int fd, NET_GET_IF, struct dvb_net_if *net_if)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`net_if`**

  pointer to struct `dvb_net_if`

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

## Description

The NET_GET_IF ioctl uses the interface number given by the struct `dvb_net_if`::ifnum field and fills the content of struct `dvb_net_if` with the packet ID and encapsulation type used on such interface. If the interface was not created yet with [NET_ADD_IF](</kernel/userspace/userspace-api/media-dvb/net.md#rst-net>), it will return -1 and fill the `errno` with `EINVAL` error code.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, and `ca_slot_info` is filled.

On error -1 is returned, and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl NET_REMOVE_IF

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> NET_REMOVE_IF - Removes a network interface.

<a id="rst-ioctl-net-remove-if"></a>
<a id="rst-net-remove-if"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: DTV.net -->

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

## Name

NET_REMOVE_IF - Removes a network interface.

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

## Synopsis





<a id="c-NET_REMOVE_IF"></a>

```c
NET_REMOVE_IF
```

`int ioctl(int fd, NET_REMOVE_IF, int ifnum)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`net_if`**

  number of the interface to be removed

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

## Description

The NET_REMOVE_IF ioctl deletes an interface previously created via [NET_ADD_IF](</kernel/userspace/userspace-api/media-dvb/net.md#rst-net>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, and `ca_slot_info` is filled.

On error -1 is returned, and the `errno` variable is set appropriately.

The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Net Data Types

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Reference for Net Data Types.

<a id="rst-net-data-types"></a>
<a id="rst-net-types"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->


#### <a id="c-struct-dvb_net_if"></a>`struct dvb_net_if`

describes a DVB network interface

**Definition**

```c
struct dvb_net_if {
        __u16 pid;
        __u16 if_num;
        __u8 feedtype;
    #define DVB_NET_FEEDTYPE_MPE 0;
    #define DVB_NET_FEEDTYPE_ULE 1;
};
```

**Members**

- `pid`: Packet ID (PID) of the MPEG-TS that contains data
- `if_num`: number of the Digital TV interface.
- `feedtype`: Encapsulation type of the feed.

**Description**

A MPEG-TS stream may contain packet IDs with IP packages on it.
This struct describes it, and the type of encoding.

**feedtype** can be:

- `DVB_NET_FEEDTYPE_MPE` for MPE encoding
- `DVB_NET_FEEDTYPE_ULE` for ULE encoding.

---

# Digital TV Network API

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> The Digital TV net device controls the mapping of data packages that are part of a transport stream to be mapped into a virtual network interface, visible through the standard Linux network protocol stack.

<a id="rst-digital-tv-network-api"></a>
<a id="rst-net"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

The Digital TV net device controls the mapping of data packages that are part of a transport stream to be mapped into a virtual network interface, visible through the standard Linux network protocol stack.

Currently, two encapsulations are supported:

- [Multi Protocol Encapsulation (MPE)](<http://en.wikipedia.org/wiki/Multiprotocol_Encapsulation>)

- [Ultra Lightweight Encapsulation (ULE)](<http://en.wikipedia.org/wiki/Unidirectional_Lightweight_Encapsulation>)

In order to create the Linux virtual network interfaces, an application needs to tell to the Kernel what are the PIDs and the encapsulation types that are present on the transport stream. This is done through `/dev/dvb/adapter?/net?` device node. The data will be available via virtual `dvb?_?` network interfaces, and will be controlled/routed via the standard ip tools (like ip, route, netstat, ifconfig, etc).

Data types and ioctl definitions are defined via `linux/dvb/net.h` header.

<a id="rst-digital-tv-net-function-calls"></a>
<a id="rst-net-fcalls"></a>

## Digital TV net Function Calls

- [Net Data Types](</kernel/userspace/userspace-api/media-dvb/net-types.md>)
- [ioctl NET_ADD_IF](</kernel/userspace/userspace-api/media-dvb/net-add-if.md>)
- [ioctl NET_REMOVE_IF](</kernel/userspace/userspace-api/media-dvb/net-remove-if.md>)
- [ioctl NET_GET_IF](</kernel/userspace/userspace-api/media-dvb/net-get-if.md>)

---

# Querying frontend information

_Peios Kernel / Userspace interfaces / System and device interfaces / Digital television (DVB)_

> Usually, the first thing to do when the frontend is opened is to check the frontend capabilities. This is done using FE_GET_INFO. This ioctl will enumerate the Digital TV API version and other characteristics about the frontend, and can be…

<a id="rst-querying-frontend-information"></a>
<a id="rst-query-dvb-frontend-info"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

Usually, the first thing to do when the frontend is opened is to check the frontend capabilities. This is done using [ioctl FE_GET_INFO](</kernel/userspace/userspace-api/media-dvb/fe-get-info.md#rst-fe-get-info>). This ioctl will enumerate the Digital TV API version and other characteristics about the frontend, and can be opened either in read only or read/write mode.

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> Media devices increasingly handle multiple related functions. Many USB cameras include microphones, video capture hardware can also output video, or SoC camera interfaces also perform memory-to-memory operations similar to video codecs.

<a id="rst-introduction"></a>
<a id="rst-media-controller-intro"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

Media devices increasingly handle multiple related functions. Many USB cameras include microphones, video capture hardware can also output video, or SoC camera interfaces also perform memory-to-memory operations similar to video codecs.

Independent functions, even when implemented in the same hardware, can be modelled as separate devices. A USB camera with a microphone will be presented to userspace applications as V4L2 and ALSA capture devices. The devices' relationships (when using a webcam, end-users shouldn't have to manually select the associated USB microphone), while not made available directly to applications by the drivers, can usually be retrieved from sysfs.

With more and more advanced SoC devices being introduced, the current approach will not scale. Device topologies are getting increasingly complex and can't always be represented by a tree structure. Hardware blocks are shared between different functions, creating dependencies between seemingly unrelated devices.

Kernel abstraction APIs such as V4L2 and ALSA provide means for applications to access hardware parameters. As newer hardware expose an increasingly high number of those parameters, drivers need to guess what applications really require based on limited information, thereby implementing policies that belong to userspace.

The media controller API aims at solving those problems.

---

# Media device model

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> Discovering a device internal topology, and configuring it at runtime, is one of the goals of the media controller API. To achieve this, hardware devices and Linux Kernel interfaces are modelled as graph objects on an oriented graph. The…

<a id="rst-media-device-model"></a>
<a id="rst-media-controller-model"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

Discovering a device internal topology, and configuring it at runtime, is one of the goals of the media controller API. To achieve this, hardware devices and Linux Kernel interfaces are modelled as graph objects on an oriented graph. The object types that constitute the graph are:

- An **entity** is a basic media hardware or software building block. It can correspond to a large variety of logical blocks such as physical hardware devices (CMOS sensor for instance), logical hardware devices (a building block in a System-on-Chip image processing pipeline), DMA channels or physical connectors.

- An **interface** is a graph representation of a Linux Kernel userspace API interface, like a device node or a sysfs file that controls one or more entities in the graph.

- A **pad** is a data connection endpoint through which an entity can interact with other entities. Data (not restricted to video) produced by an entity flows from the entity's output to one or more entity inputs. Pads should not be confused with physical pins at chip boundaries.

- A **data link** is a point-to-point oriented connection between two pads, either on the same entity or on different entities. Data flows from a source pad to a sink pad.

- An **interface link** is a point-to-point bidirectional control connection between a Linux Kernel interface and an entity.

- An **ancillary link** is a point-to-point connection denoting that two entities form a single logical unit. For example this could represent the fact that a particular camera sensor and lens controller form a single physical module, meaning this lens controller drives the lens for this camera sensor.

---

# Part IV - Media Controller API

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> Authors:

<a id="rst-part-iv-media-controller-api"></a>
<a id="rst-media-controller"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

**Table of Contents**

1. [Introduction](</kernel/userspace/userspace-api/media-mediactl/media-controller-intro.md>)
2. [Media device model](</kernel/userspace/userspace-api/media-mediactl/media-controller-model.md>)
3. [Types and flags used to represent the media graph elements](</kernel/userspace/userspace-api/media-mediactl/media-types.md>)
4. [Request API](</kernel/userspace/userspace-api/media-mediactl/request-api.md>)
5. [Function Reference](</kernel/userspace/userspace-api/media-mediactl/media-funcs.md>)
6. [media-header](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/mediactl/media-header.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

<a id="rst-revision-and-copyright"></a>

## Revision and Copyright

Authors:

- Pinchart, Laurent &lt;[laurent.pinchart@ideasonboard.com](<mailto:laurent.pinchart@ideasonboard.com>)&gt;

> - Initial version.

- Carvalho Chehab, Mauro &lt;[mchehab@kernel.org](<mailto:mchehab@kernel.org>)&gt;

> - MEDIA_IOC_G_TOPOLOGY documentation and documentation improvements.

**Copyright** © 2010 : Laurent Pinchart

**Copyright** © 2015-2016 : Mauro Carvalho Chehab

<a id="rst-revision-history"></a>

## Revision History

**revision:** 1.1.0 / 2015-12-12 (*mcc*)

**revision:** 1.0.0 / 2010-11-10 (*lp*)

Initial revision

---

# media close()

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> media-close - Close a media device

<a id="rst-media-close"></a>
<a id="rst-media-func-close"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

media-close - Close a media device

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-close"></a>

```c
int close( int fd )
```

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

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

## Description

Closes the media device. Resources associated with the file descriptor are freed. The device configuration remain unchanged.

<a id="rst-return-value"></a>

## Return Value

`close()` returns 0 on success. On error, -1 is returned, and `errno` is set appropriately. Possible error codes are:

- **EBADF**

  `fd` is not a valid open file descriptor.

---

# media ioctl()

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> media-ioctl - Control a media device

<a id="rst-media-ioctl"></a>
<a id="rst-media-func-ioctl"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

media-ioctl - Control a media device

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

## Synopsis



```c
#include <sys/ioctl.h>
```

`int ioctl(int fd, int request, void *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`request`**

  Media ioctl request code as defined in the media.h header file, for example MEDIA_IOC_SETUP_LINK.

- **`argp`**

  Pointer to a request-specific structure.

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

## Description

The [ioctl()](<#rst-media-func-ioctl>) function manipulates media device parameters. The argument `fd` must be an open file descriptor.

The ioctl `request` code specifies the media function to be called. It has encoded in it whether the argument is an input, output or read/write parameter, and the size of the argument `argp` in bytes.

Macros and structures definitions specifying media ioctl requests and their parameters are located in the media.h header file. All media ioctl requests, their respective function and parameters are specified in [Function Reference](</kernel/userspace/userspace-api/media-mediactl/media-funcs.md#rst-media-user-func>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

Request-specific error codes are listed in the individual requests descriptions.

When an ioctl that takes an output or read/write parameter fails, the parameter remains unmodified.

---

# media open()

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> media-open - Open a media device

<a id="rst-media-open"></a>
<a id="rst-media-func-open"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

media-open - Open a media device

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

## Synopsis



```c
#include <fcntl.h>
```





<a id="c-open"></a>

```c
int open( const char *device_name, int flags )
```

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

## Arguments

- **`device_name`**

  Device to be opened.

- **`flags`**

  Open flags. Access mode must be either `O_RDONLY` or `O_RDWR`. Other flags have no effect.

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

## Description

To open a media device applications call `open()` with the desired device name. The function has no side effects; the device configuration remain unchanged.

When the device is opened in read-only mode, attempts to modify its configuration will result in an error, and `errno` will be set to EBADF.

<a id="rst-return-value"></a>

## Return Value

`open()` returns the new file descriptor on success. On error, -1 is returned, and `errno` is set appropriately. Possible error codes are:

- **EACCES**

  The requested access to the file is not allowed.

- **EMFILE**

  The process already has the maximum number of files open.

- **ENFILE**

  The system limit on the total number of open files has been reached.

- **ENOMEM**

  Insufficient kernel memory was available.

- **ENXIO**

  No device corresponding to this device special file exists.

---

# Function Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> Reference for Function Reference.

<a id="rst-function-reference"></a>
<a id="rst-media-user-func"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

- [media open()](</kernel/userspace/userspace-api/media-mediactl/media-func-open.md>)
- [media close()](</kernel/userspace/userspace-api/media-mediactl/media-func-close.md>)
- [media ioctl()](</kernel/userspace/userspace-api/media-mediactl/media-func-ioctl.md>)
- [ioctl MEDIA_IOC_DEVICE_INFO](</kernel/userspace/userspace-api/media-mediactl/media-ioc-device-info.md>)
- [ioctl MEDIA_IOC_G_TOPOLOGY](</kernel/userspace/userspace-api/media-mediactl/media-ioc-g-topology.md>)
- [ioctl MEDIA_IOC_ENUM_ENTITIES](</kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-entities.md>)
- [ioctl MEDIA_IOC_ENUM_LINKS](</kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-links.md>)
- [ioctl MEDIA_IOC_SETUP_LINK](</kernel/userspace/userspace-api/media-mediactl/media-ioc-setup-link.md>)
- [ioctl MEDIA_IOC_REQUEST_ALLOC](</kernel/userspace/userspace-api/media-mediactl/media-ioc-request-alloc.md>)
- [request close()](</kernel/userspace/userspace-api/media-mediactl/request-func-close.md>)
- [request ioctl()](</kernel/userspace/userspace-api/media-mediactl/request-func-ioctl.md>)
- [request poll()](</kernel/userspace/userspace-api/media-mediactl/request-func-poll.md>)
- [ioctl MEDIA_REQUEST_IOC_QUEUE](</kernel/userspace/userspace-api/media-mediactl/media-request-ioc-queue.md>)
- [ioctl MEDIA_REQUEST_IOC_REINIT](</kernel/userspace/userspace-api/media-mediactl/media-request-ioc-reinit.md>)

---

# Media controller uAPI symbols

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> Reference for Media controller uAPI symbols.

<a id="rst-media-controller-uapi-symbols"></a>
<a id="rst-media-header"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->


## IOCTL Commands

- [`MEDIA_IOC_DEVICE_INFO`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-device-info.md#rst-media-ioc-device-info): `include/uapi/linux/media.h`, line 371
- [`MEDIA_IOC_ENUM_ENTITIES`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-entities.md#rst-media-ioc-enum-entities): `include/uapi/linux/media.h`, line 372
- [`MEDIA_IOC_ENUM_LINKS`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-links.md#rst-media-ioc-enum-links): `include/uapi/linux/media.h`, line 373
- [`MEDIA_IOC_G_TOPOLOGY`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-g-topology.md#rst-media-ioc-g-topology): `include/uapi/linux/media.h`, line 375
- [`MEDIA_IOC_REQUEST_ALLOC`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-request-alloc.md#rst-media-ioc-request-alloc): `include/uapi/linux/media.h`, line 376
- [`MEDIA_IOC_SETUP_LINK`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-setup-link.md#rst-media-ioc-setup-link): `include/uapi/linux/media.h`, line 374
- [`MEDIA_REQUEST_IOC_QUEUE`](/kernel/userspace/userspace-api/media-mediactl/media-request-ioc-queue.md#rst-media-request-ioc-queue): `include/uapi/linux/media.h`, line 382
- [`MEDIA_REQUEST_IOC_REINIT`](/kernel/userspace/userspace-api/media-mediactl/media-request-ioc-reinit.md#rst-media-request-ioc-reinit): `include/uapi/linux/media.h`, line 383

## Macros and Definitions

- [`MEDIA_ENT_FL_CONNECTOR`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-fl-connector): `include/uapi/linux/media.h`, line 144
- [`MEDIA_ENT_FL_DEFAULT`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-fl-default): `include/uapi/linux/media.h`, line 143
- [`MEDIA_ENT_F_ATV_DECODER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-atv-decoder): `include/uapi/linux/media.h`, line 138
- [`MEDIA_ENT_F_AUDIO_CAPTURE`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-audio-capture): `include/uapi/linux/media.h`, line 112
- [`MEDIA_ENT_F_AUDIO_MIXER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-audio-mixer): `include/uapi/linux/media.h`, line 114
- [`MEDIA_ENT_F_AUDIO_PLAYBACK`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-audio-playback): `include/uapi/linux/media.h`, line 113
- [`MEDIA_ENT_F_CAM_SENSOR`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-cam-sensor): `include/uapi/linux/media.h`, line 84
- [`MEDIA_ENT_F_CONN_COMPOSITE`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-conn-composite): `include/uapi/linux/media.h`, line 281
- [`MEDIA_ENT_F_CONN_RF`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-conn-rf): `include/uapi/linux/media.h`, line 279
- [`MEDIA_ENT_F_CONN_SVIDEO`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-conn-svideo): `include/uapi/linux/media.h`, line 280
- [`MEDIA_ENT_F_DTV_CA`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-dtv-ca): `include/uapi/linux/media.h`, line 70
- [`MEDIA_ENT_F_DTV_DEMOD`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-dtv-demod): `include/uapi/linux/media.h`, line 68
- [`MEDIA_ENT_F_DTV_NET_DECAP`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-dtv-net-decap): `include/uapi/linux/media.h`, line 71
- [`MEDIA_ENT_F_DV_DECODER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-dv-decoder): `include/uapi/linux/media.h`, line 139
- [`MEDIA_ENT_F_DV_ENCODER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-dv-encoder): `include/uapi/linux/media.h`, line 140
- [`MEDIA_ENT_F_FLASH`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-flash): `include/uapi/linux/media.h`, line 85
- [`MEDIA_ENT_F_IF_AUD_DECODER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-if-aud-decoder): `include/uapi/linux/media.h`, line 107
- [`MEDIA_ENT_F_IF_VID_DECODER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-if-vid-decoder): `include/uapi/linux/media.h`, line 106
- [`MEDIA_ENT_F_IO_DTV`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-io-dtv): `include/uapi/linux/media.h`, line 77
- [`MEDIA_ENT_F_IO_SWRADIO`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-io-swradio): `include/uapi/linux/media.h`, line 79
- [`MEDIA_ENT_F_IO_V4L`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-io-v4l): `include/uapi/linux/media.h`, line 76
- [`MEDIA_ENT_F_IO_VBI`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-io-vbi): `include/uapi/linux/media.h`, line 78
- [`MEDIA_ENT_F_LENS`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-lens): `include/uapi/linux/media.h`, line 86
- [`MEDIA_ENT_F_PROC_VIDEO_COMPOSER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-composer): `include/uapi/linux/media.h`, line 119
- [`MEDIA_ENT_F_PROC_VIDEO_DECODER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-decoder): `include/uapi/linux/media.h`, line 126
- [`MEDIA_ENT_F_PROC_VIDEO_ENCODER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-encoder): `include/uapi/linux/media.h`, line 125
- [`MEDIA_ENT_F_PROC_VIDEO_ISP`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-isp): `include/uapi/linux/media.h`, line 127
- [`MEDIA_ENT_F_PROC_VIDEO_LUT`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-lut): `include/uapi/linux/media.h`, line 122
- [`MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-pixel-enc-conv): `include/uapi/linux/media.h`, line 121
- [`MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-pixel-formatter): `include/uapi/linux/media.h`, line 120
- [`MEDIA_ENT_F_PROC_VIDEO_SCALER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-scaler): `include/uapi/linux/media.h`, line 123
- [`MEDIA_ENT_F_PROC_VIDEO_STATISTICS`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-proc-video-statistics): `include/uapi/linux/media.h`, line 124
- [`MEDIA_ENT_F_TS_DEMUX`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-ts-demux): `include/uapi/linux/media.h`, line 69
- [`MEDIA_ENT_F_TUNER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-tuner): `include/uapi/linux/media.h`, line 98
- [`MEDIA_ENT_F_UNKNOWN`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-unknown): `include/uapi/linux/media.h`, line 56
- [`MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-v4l2-subdev-unknown): `include/uapi/linux/media.h`, line 63
- [`MEDIA_ENT_F_VID_IF_BRIDGE`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-vid-if-bridge): `include/uapi/linux/media.h`, line 133
- [`MEDIA_ENT_F_VID_MUX`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-ent-f-vid-mux): `include/uapi/linux/media.h`, line 132
- [`MEDIA_ENT_ID_FLAG_NEXT`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-entities.md#rst-media-ent-id-flag-next): `include/uapi/linux/media.h`, line 147
- [`MEDIA_INTF_T_ALSA_COMPRESS`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-alsa-compress): `include/uapi/linux/media.h`, line 428
- [`MEDIA_INTF_T_ALSA_CONTROL`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-alsa-control): `include/uapi/linux/media.h`, line 267
- [`MEDIA_INTF_T_ALSA_HWDEP`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-alsa-hwdep): `include/uapi/linux/media.h`, line 430
- [`MEDIA_INTF_T_ALSA_PCM_CAPTURE`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-alsa-pcm-capture): `include/uapi/linux/media.h`, line 265
- [`MEDIA_INTF_T_ALSA_PCM_PLAYBACK`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-alsa-pcm-playback): `include/uapi/linux/media.h`, line 266
- [`MEDIA_INTF_T_ALSA_RAWMIDI`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-alsa-rawmidi): `include/uapi/linux/media.h`, line 429
- [`MEDIA_INTF_T_ALSA_SEQUENCER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-alsa-sequencer): `include/uapi/linux/media.h`, line 431
- [`MEDIA_INTF_T_ALSA_TIMER`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-alsa-timer): `include/uapi/linux/media.h`, line 432
- [`MEDIA_INTF_T_DVB_CA`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-dvb-ca): `include/uapi/linux/media.h`, line 254
- [`MEDIA_INTF_T_DVB_DEMUX`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-dvb-demux): `include/uapi/linux/media.h`, line 252
- [`MEDIA_INTF_T_DVB_DVR`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-dvb-dvr): `include/uapi/linux/media.h`, line 253
- [`MEDIA_INTF_T_DVB_FE`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-dvb-fe): `include/uapi/linux/media.h`, line 251
- [`MEDIA_INTF_T_DVB_NET`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-dvb-net): `include/uapi/linux/media.h`, line 255
- [`MEDIA_INTF_T_V4L_RADIO`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-v4l-radio): `include/uapi/linux/media.h`, line 259
- [`MEDIA_INTF_T_V4L_SUBDEV`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-v4l-subdev): `include/uapi/linux/media.h`, line 260
- [`MEDIA_INTF_T_V4L_SWRADIO`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-v4l-swradio): `include/uapi/linux/media.h`, line 261
- [`MEDIA_INTF_T_V4L_TOUCH`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-v4l-touch): `include/uapi/linux/media.h`, line 262
- [`MEDIA_INTF_T_V4L_VBI`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-v4l-vbi): `include/uapi/linux/media.h`, line 258
- [`MEDIA_INTF_T_V4L_VIDEO`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-t-v4l-video): `include/uapi/linux/media.h`, line 257
- [`MEDIA_LNK_FL_ANCILLARY_LINK`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-lnk-fl-ancillary-link): `include/uapi/linux/media.h`, line 226
- [`MEDIA_LNK_FL_DATA_LINK`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-lnk-fl-data-link): `include/uapi/linux/media.h`, line 224
- [`MEDIA_LNK_FL_DYNAMIC`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-lnk-fl-dynamic): `include/uapi/linux/media.h`, line 221
- [`MEDIA_LNK_FL_ENABLED`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-lnk-fl-enabled): `include/uapi/linux/media.h`, line 219
- [`MEDIA_LNK_FL_IMMUTABLE`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-lnk-fl-immutable): `include/uapi/linux/media.h`, line 220
- [`MEDIA_LNK_FL_INTERFACE_LINK`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-lnk-fl-interface-link): `include/uapi/linux/media.h`, line 225
- [`MEDIA_LNK_FL_LINK_TYPE`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-lnk-fl-link-type): `include/uapi/linux/media.h`, line 223
- [`MEDIA_PAD_FL_MUST_CONNECT`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-pad-fl-must-connect): `include/uapi/linux/media.h`, line 210
- [`MEDIA_PAD_FL_SINK`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-pad-fl-sink): `include/uapi/linux/media.h`, line 208
- [`MEDIA_PAD_FL_SOURCE`](/kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-pad-fl-source): `include/uapi/linux/media.h`, line 209

## Structures

- [`media_device_info`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-device-info.md#c-media_device_info): `include/uapi/linux/media.h`, line 26
- [`media_entity_desc`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-entities.md#c-media_entity_desc): `include/uapi/linux/media.h`, line 149
- [`media_link_desc`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-links.md#c-media_link_desc): `include/uapi/linux/media.h`, line 228
- [`media_links_enum`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-links.md#c-media_links_enum): `include/uapi/linux/media.h`, line 235
- [`media_pad_desc`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-links.md#c-media_pad_desc): `include/uapi/linux/media.h`, line 212
- [`media_v2_entity`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-g-topology.md#c-media_v2_entity): `include/uapi/linux/media.h`, line 298
- [`media_v2_interface`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-g-topology.md#c-media_v2_interface): `include/uapi/linux/media.h`, line 312
- [`media_v2_intf_devnode`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-g-topology.md#c-media_v2_intf_devnode): `include/uapi/linux/media.h`, line 307
- [`media_v2_link`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-g-topology.md#c-media_v2_link): `include/uapi/linux/media.h`, line 341
- [`media_v2_pad`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-g-topology.md#c-media_v2_pad): `include/uapi/linux/media.h`, line 333
- [`media_v2_topology`](/kernel/userspace/userspace-api/media-mediactl/media-ioc-g-topology.md#c-media_v2_topology): `include/uapi/linux/media.h`, line 349

---

# ioctl MEDIA_IOC_DEVICE_INFO

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> MEDIA_IOC_DEVICE_INFO - Query device information

<a id="rst-ioctl-media-ioc-device-info"></a>
<a id="rst-media-ioc-device-info"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

MEDIA_IOC_DEVICE_INFO - Query device information

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

## Synopsis





<a id="c-MEDIA_IOC_DEVICE_INFO"></a>

```c
MEDIA_IOC_DEVICE_INFO
```

`int ioctl(int fd, MEDIA_IOC_DEVICE_INFO, struct media_device_info *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `media_device_info`.

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

## Description

All media devices must support the `MEDIA_IOC_DEVICE_INFO` ioctl. To query device information, applications call the ioctl with a pointer to a struct `media_device_info`. The driver fills the structure and returns the information to the application. The ioctl never fails.





<a id="c-media_device_info"></a>

```c
media_device_info
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct media_device_info</caption>
<tbody>
<tr>
<td>


char

</td>
<td>


`driver`\[16\]

</td>
<td>


Name of the driver implementing the media API as a NUL-terminated ASCII string. The driver version is stored in the `driver_version` field.

Driver specific applications can use this information to verify the driver identity. It is also useful to work around known bugs, or to identify drivers in error reports.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`model`\[32\]

</td>
<td>


Device model name as a NUL-terminated UTF-8 string. The device version is stored in the `device_version` field and is not be appended to the model name.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`serial`\[40\]

</td>
<td>


Serial number as a NUL-terminated ASCII string.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`bus_info`\[32\]

</td>
<td>


Location of the device in the system as a NUL-terminated ASCII string. This includes the bus type name (PCI, USB, ...) and a bus-specific identifier.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`media_version`

</td>
<td>


Media API version, formatted with the `KERNEL_VERSION()` macro.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`hw_revision`

</td>
<td>


Hardware device revision in a driver-specific format.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`driver_version`

</td>
<td>


Media device driver version, formatted with the `KERNEL_VERSION()` macro. Together with the `driver` field this identifies a particular driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[31\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set this array to zero.

</td>
</tr>
</tbody>
</table>

The `serial` and `bus_info` fields can be used to distinguish between multiple instances of otherwise identical hardware. The serial number takes precedence when provided and can be assumed to be unique. If the serial number is an empty string, the `bus_info` field can be used instead. The `bus_info` field is guaranteed to be unique, but can vary across reboots or device unplug/replug.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl MEDIA_IOC_ENUM_ENTITIES

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> MEDIA_IOC_ENUM_ENTITIES - Enumerate entities and their properties

<a id="rst-ioctl-media-ioc-enum-entities"></a>
<a id="rst-media-ioc-enum-entities"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

MEDIA_IOC_ENUM_ENTITIES - Enumerate entities and their properties

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

## Synopsis





<a id="c-MEDIA_IOC_ENUM_ENTITIES"></a>

```c
MEDIA_IOC_ENUM_ENTITIES
```

`int ioctl(int fd, MEDIA_IOC_ENUM_ENTITIES, struct media_entity_desc *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `media_entity_desc`.

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

## Description

To query the attributes of an entity, applications set the id field of a struct `media_entity_desc` structure and call the MEDIA_IOC_ENUM_ENTITIES ioctl with a pointer to this structure. The driver fills the rest of the structure or returns an EINVAL error code when the id is invalid.

<a id="rst-media-ent-id-flag-next"></a>

Entities can be enumerated by or'ing the id with the `MEDIA_ENT_ID_FLAG_NEXT` flag. The driver will return information about the entity with the smallest id strictly larger than the requested one ('next entity'), or the `EINVAL` error code if there is none.

Entity IDs can be non-contiguous. Applications must *not* try to enumerate entities by calling MEDIA_IOC_ENUM_ENTITIES with increasing id's until they get an error.





<a id="c-media_entity_desc"></a>

```c
media_entity_desc
```

<!-- tabularcolumns: |p{1.5cm}|p{1.7cm}|p{1.6cm}|p{1.5cm}|p{10.6cm}| -->


<table>
<caption>struct media_entity_desc</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`id`

</td>
<td>




</td>
<td>


Entity ID, set by the application. When the ID is or'ed with `MEDIA_ENT_ID_FLAG_NEXT`, the driver clears the flag and returns the first entity with a larger ID. Do not expect that the ID will always be the same for each instance of the device. In other words, do not hardcode entity IDs in an application.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`name`\[32\]

</td>
<td>




</td>
<td>


Entity name as an UTF-8 NULL-terminated string. This name must be unique within the media topology.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>




</td>
<td>


Entity type, see [media-entity-functions](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-entity-functions>) for details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`revision`

</td>
<td>




</td>
<td>


Entity revision. Always zero (obsolete)

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>




</td>
<td>


Entity flags, see [media-entity-flag](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-entity-flag>) for details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`group_id`

</td>
<td>




</td>
<td>


Entity group ID. Always zero (obsolete)

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`pads`

</td>
<td>




</td>
<td>


Number of pads

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`links`

</td>
<td>




</td>
<td>


Total number of outbound links. Inbound links are not counted in this field.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[4]`

</td>
<td>




</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="3">


(anonymous)

</td>
</tr>
<tr>
<td>


struct

</td>
<td>


`dev`

</td>
<td>




</td>
<td>


Valid for (sub-)devices that create a single device node.

</td>
</tr>
<tr>
<td>




</td>
<td>


\__u32

</td>
<td>


`major`

</td>
<td>


Device node major number.

</td>
</tr>
<tr>
<td>




</td>
<td>


\__u32

</td>
<td>


`minor`

</td>
<td>


Device node minor number.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`raw`\[184\]

</td>
<td>




</td>
<td>




</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="3">




</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `media_entity_desc` `id` references a non-existing entity.

---

# ioctl MEDIA_IOC_ENUM_LINKS

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> MEDIA_IOC_ENUM_LINKS - Enumerate all pads and links for a given entity

<a id="rst-ioctl-media-ioc-enum-links"></a>
<a id="rst-media-ioc-enum-links"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

MEDIA_IOC_ENUM_LINKS - Enumerate all pads and links for a given entity

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

## Synopsis





<a id="c-MEDIA_IOC_ENUM_LINKS"></a>

```c
MEDIA_IOC_ENUM_LINKS
```

`int ioctl(int fd, MEDIA_IOC_ENUM_LINKS, struct media_links_enum *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `media_links_enum`.

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

## Description

To enumerate pads and/or links for a given entity, applications set the entity field of a struct `media_links_enum` structure and initialize the struct `media_pad_desc` and struct `media_link_desc` structure arrays pointed by the `pads` and `links` fields. They then call the MEDIA_IOC_ENUM_LINKS ioctl with a pointer to this structure.

If the `pads` field is not NULL, the driver fills the `pads` array with information about the entity's pads. The array must have enough room to store all the entity's pads. The number of pads can be retrieved with [ioctl MEDIA_IOC_ENUM_ENTITIES](</kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-entities.md#rst-media-ioc-enum-entities>).

If the `links` field is not NULL, the driver fills the `links` array with information about the entity's outbound links. The array must have enough room to store all the entity's outbound links. The number of outbound links can be retrieved with [ioctl MEDIA_IOC_ENUM_ENTITIES](</kernel/userspace/userspace-api/media-mediactl/media-ioc-enum-entities.md#rst-media-ioc-enum-entities>).

Only forward links that originate at one of the entity's source pads are returned during the enumeration process.





<a id="c-media_links_enum"></a>

```c
media_links_enum
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct media_links_enum</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`entity`

</td>
<td>


Entity id, set by the application.

</td>
</tr>
<tr>
<td>


struct `media_pad_desc`

</td>
<td>


\*`pads`

</td>
<td>


Pointer to a pads array allocated by the application. Ignored if NULL.

</td>
</tr>
<tr>
<td>


struct `media_link_desc`

</td>
<td>


\*`links`

</td>
<td>


Pointer to a links array allocated by the application. Ignored if NULL.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[4]`

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>





<a id="c-media_pad_desc"></a>

```c
media_pad_desc
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct media_pad_desc</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`entity`

</td>
<td>


ID of the entity this pad belongs to.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`index`

</td>
<td>


Pad index, starts at 0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Pad flags, see [media-pad-flag](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-pad-flag>) for more details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[2]`

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>





<a id="c-media_link_desc"></a>

```c
media_link_desc
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct media_link_desc</caption>
<tbody>
<tr>
<td>


struct `media_pad_desc`

</td>
<td>


`source`

</td>
<td>


Pad at the origin of this link.

</td>
</tr>
<tr>
<td>


struct `media_pad_desc`

</td>
<td>


`sink`

</td>
<td>


Pad at the target of this link.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Link flags, see [media-link-flag](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-link-flag>) for more details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[2]`

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `media_links_enum` `id` references a non-existing entity.

---

# ioctl MEDIA_IOC_G_TOPOLOGY

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> MEDIA_IOC_G_TOPOLOGY - Enumerate the graph topology and graph element properties

<a id="rst-ioctl-media-ioc-g-topology"></a>
<a id="rst-media-ioc-g-topology"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

MEDIA_IOC_G_TOPOLOGY - Enumerate the graph topology and graph element properties

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

## Synopsis





<a id="c-MEDIA_IOC_G_TOPOLOGY"></a>

```c
MEDIA_IOC_G_TOPOLOGY
```

`int ioctl(int fd, MEDIA_IOC_G_TOPOLOGY, struct media_v2_topology *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `media_v2_topology`.

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

## Description

The typical usage of this ioctl is to call it twice. On the first call, the structure defined at struct `media_v2_topology` should be zeroed. At return, if no errors happen, this ioctl will return the `topology_version` and the total number of entities, interfaces, pads and links.

Before the second call, the userspace should allocate arrays to store the graph elements that are desired, putting the pointers to them at the ptr_entities, ptr_interfaces, ptr_links and/or ptr_pads, keeping the other values untouched.

If the `topology_version` remains the same, the ioctl should fill the desired arrays with the media graph elements.

<!-- tabularcolumns: |p{1.6cm}|p{3.4cm}|p{12.3cm}| -->





<a id="c-media_v2_topology"></a>

```c
media_v2_topology
```


<table>
<caption>struct media_v2_topology</caption>
<tbody>
<tr>
<td>


\__u64

</td>
<td>


`topology_version`

</td>
<td>


Version of the media graph topology. When the graph is created, this field starts with zero. Every time a graph element is added or removed, this field is incremented.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`num_entities`

</td>
<td>


Number of entities in the graph

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved1`

</td>
<td>


Applications and drivers shall set this to 0.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`ptr_entities`

</td>
<td>


A pointer to a memory area where the entities array will be stored, converted to a 64-bits integer. It can be zero. if zero, the ioctl won't store the entities. It will just update `num_entities`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`num_interfaces`

</td>
<td>


Number of interfaces in the graph

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved2`

</td>
<td>


Applications and drivers shall set this to 0.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`ptr_interfaces`

</td>
<td>


A pointer to a memory area where the interfaces array will be stored, converted to a 64-bits integer. It can be zero. if zero, the ioctl won't store the interfaces. It will just update `num_interfaces`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`num_pads`

</td>
<td>


Total number of pads in the graph

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved3`

</td>
<td>


Applications and drivers shall set this to 0.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`ptr_pads`

</td>
<td>


A pointer to a memory area where the pads array will be stored, converted to a 64-bits integer. It can be zero. if zero, the ioctl won't store the pads. It will just update `num_pads`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`num_links`

</td>
<td>


Total number of data and interface links in the graph

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved4`

</td>
<td>


Applications and drivers shall set this to 0.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`ptr_links`

</td>
<td>


A pointer to a memory area where the links array will be stored, converted to a 64-bits integer. It can be zero. if zero, the ioctl won't store the links. It will just update `num_links`

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.6cm}|p{3.2cm}|p{12.5cm}| -->





<a id="c-media_v2_entity"></a>

```c
media_v2_entity
```


<table>
<caption>struct media_v2_entity</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`id`

</td>
<td>


Unique ID for the entity. Do not expect that the ID will always be the same for each instance of the device. In other words, do not hardcode entity IDs in an application.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`name`\[64\]

</td>
<td>


Entity name as an UTF-8 NULL-terminated string. This name must be unique within the media topology.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`function`

</td>
<td>


Entity main function, see [media-entity-functions](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-entity-functions>) for details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Entity flags, see [media-entity-flag](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-entity-flag>) for details. Only valid if `MEDIA_V2_ENTITY_HAS_FLAGS(media_version)` returns true. The `media_version` is defined in struct `media_device_info` and can be retrieved using [ioctl MEDIA_IOC_DEVICE_INFO](</kernel/userspace/userspace-api/media-mediactl/media-ioc-device-info.md#rst-media-ioc-device-info>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[5\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set this array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.6cm}|p{3.2cm}|p{12.5cm}| -->





<a id="c-media_v2_interface"></a>

```c
media_v2_interface
```


<table>
<caption>struct media_v2_interface</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`id`

</td>
<td>


Unique ID for the interface. Do not expect that the ID will always be the same for each instance of the device. In other words, do not hardcode interface IDs in an application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`intf_type`

</td>
<td>


Interface type, see [media-intf-type](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-intf-type>) for details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Interface flags. Currently unused.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[9\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set this array to zero.

</td>
</tr>
<tr>
<td>


struct media_v2_intf_devnode

</td>
<td>


`devnode`

</td>
<td>


Used only for device node interfaces. See `media_v2_intf_devnode` for details.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.6cm}|p{3.2cm}|p{12.5cm}| -->





<a id="c-media_v2_intf_devnode"></a>

```c
media_v2_intf_devnode
```


<table>
<caption>struct media_v2_intf_devnode</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`major`

</td>
<td>


Device node major number.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`minor`

</td>
<td>


Device node minor number.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.6cm}|p{3.2cm}|p{12.5cm}| -->





<a id="c-media_v2_pad"></a>

```c
media_v2_pad
```


<table>
<caption>struct media_v2_pad</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`id`

</td>
<td>


Unique ID for the pad. Do not expect that the ID will always be the same for each instance of the device. In other words, do not hardcode pad IDs in an application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`entity_id`

</td>
<td>


Unique ID for the entity where this pad belongs.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Pad flags, see [media-pad-flag](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-pad-flag>) for more details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Pad index, starts at 0. Only valid if `MEDIA_V2_PAD_HAS_INDEX(media_version)` returns true. The `media_version` is defined in struct `media_device_info` and can be retrieved using [ioctl MEDIA_IOC_DEVICE_INFO](</kernel/userspace/userspace-api/media-mediactl/media-ioc-device-info.md#rst-media-ioc-device-info>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[4\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set this array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.6cm}|p{3.2cm}|p{12.5cm}| -->





<a id="c-media_v2_link"></a>

```c
media_v2_link
```


<table>
<caption>struct media_v2_link</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`id`

</td>
<td>


Unique ID for the link. Do not expect that the ID will always be the same for each instance of the device. In other words, do not hardcode link IDs in an application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`source_id`

</td>
<td>


On pad to pad links: unique ID for the source pad.

On interface to entity links: unique ID for the interface.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`sink_id`

</td>
<td>


On pad to pad links: unique ID for the sink pad.

On interface to entity links: unique ID for the entity.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Link flags, see [media-link-flag](</kernel/userspace/userspace-api/media-mediactl/media-types.md#rst-media-link-flag>) for more details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[6\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set this array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **ENOSPC**

  This is returned when either one or more of the num_entities, num_interfaces, num_links or num_pads are non-zero and are smaller than the actual number of elements inside the graph. This may happen if the `topology_version` changed when compared to the last time this ioctl was called. Userspace should usually free the area for the pointers, zero the struct elements and call this ioctl again.

---

# ioctl MEDIA_IOC_REQUEST_ALLOC

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> MEDIA_IOC_REQUEST_ALLOC - Allocate a request

<a id="rst-ioctl-media-ioc-request-alloc"></a>
<a id="rst-media-ioc-request-alloc"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

MEDIA_IOC_REQUEST_ALLOC - Allocate a request

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

## Synopsis





<a id="c-MEDIA_IOC_REQUEST_ALLOC"></a>

```c
MEDIA_IOC_REQUEST_ALLOC
```

`int ioctl(int fd, MEDIA_IOC_REQUEST_ALLOC, int *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to an integer.

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

## Description

If the media device supports [requests](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>), then this ioctl can be used to allocate a request. If it is not supported, then `errno` is set to `ENOTTY`. A request is accessed through a file descriptor that is returned in `*argp`.

If the request was successfully allocated, then the request file descriptor can be passed to the [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_G_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), [VIDIOC_S_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and [VIDIOC_TRY_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctls.

In addition, the request can be queued by calling [ioctl MEDIA_REQUEST_IOC_QUEUE](</kernel/userspace/userspace-api/media-mediactl/media-request-ioc-queue.md#rst-media-request-ioc-queue>) and re-initialized by calling [ioctl MEDIA_REQUEST_IOC_REINIT](</kernel/userspace/userspace-api/media-mediactl/media-request-ioc-reinit.md#rst-media-request-ioc-reinit>).

Finally, the file descriptor can be [polled](</kernel/userspace/userspace-api/media-mediactl/request-func-poll.md#rst-request-func-poll>) to wait for the request to complete.

The request will remain allocated until all the file descriptors associated with it are closed by `close()` and the driver no longer uses the request internally. See also [here](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-life-time>) for more information.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **ENOTTY**

  The driver has no support for requests.

---

# ioctl MEDIA_IOC_SETUP_LINK

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> MEDIA_IOC_SETUP_LINK - Modify the properties of a link

<a id="rst-ioctl-media-ioc-setup-link"></a>
<a id="rst-media-ioc-setup-link"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

MEDIA_IOC_SETUP_LINK - Modify the properties of a link

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

## Synopsis





<a id="c-MEDIA_IOC_SETUP_LINK"></a>

```c
MEDIA_IOC_SETUP_LINK
```

`int ioctl(int fd, MEDIA_IOC_SETUP_LINK, struct media_link_desc *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `media_link_desc`.

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

## Description

To change link properties applications fill a struct `media_link_desc` with link identification information (source and sink pad) and the new requested link flags. They then call the MEDIA_IOC_SETUP_LINK ioctl with a pointer to that structure.

The only configurable property is the `ENABLED` link flag to enable/disable a link. Links marked with the `IMMUTABLE` link flag can not be enabled or disabled.

Link configuration has no side effect on other links. If an enabled link at the sink pad prevents the link from being enabled, the driver returns with an `EBUSY` error code.

Only links marked with the `DYNAMIC` link flag can be enabled/disabled while streaming media data. Attempting to enable or disable a streaming non-dynamic link will return an `EBUSY` error code.

If the specified link can't be found the driver returns with an `EINVAL` error code.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `media_link_desc` references a non-existing link, or the link is immutable and an attempt to modify its configuration was made.

---

# ioctl MEDIA_REQUEST_IOC_QUEUE

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> MEDIA_REQUEST_IOC_QUEUE - Queue a request

<a id="rst-ioctl-media-request-ioc-queue"></a>
<a id="rst-media-request-ioc-queue"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

MEDIA_REQUEST_IOC_QUEUE - Queue a request

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

## Synopsis





<a id="c-MEDIA_REQUEST_IOC_QUEUE"></a>

```c
MEDIA_REQUEST_IOC_QUEUE
```

`int ioctl(int request_fd, MEDIA_REQUEST_IOC_QUEUE)`

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

## Arguments

- **`request_fd`**

  File descriptor returned by [ioctl MEDIA_IOC_REQUEST_ALLOC](</kernel/userspace/userspace-api/media-mediactl/media-ioc-request-alloc.md#rst-media-ioc-request-alloc>).

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

## Description

If the media device supports [requests](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>), then this request ioctl can be used to queue a previously allocated request.

If the request was successfully queued, then the file descriptor can be [polled](</kernel/userspace/userspace-api/media-mediactl/request-func-poll.md#rst-request-func-poll>) to wait for the request to complete.

If the request was already queued before, then `EBUSY` is returned. Other errors can be returned if the contents of the request contained invalid or inconsistent data, see the next section for a list of common error codes. On error both the request and driver state are unchanged.

Once a request is queued, then the driver is required to gracefully handle errors that occur when the request is applied to the hardware. The exception is the `EIO` error which signals a fatal error that requires the application to stop streaming to reset the hardware state.

It is not allowed to mix queuing requests with queuing buffers directly (without a request). `EBUSY` will be returned if the first buffer was queued directly and you next try to queue a request, or vice versa.

A request must contain at least one buffer, otherwise this ioctl will return an `ENOENT` error.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EBUSY**

  The request was already queued or the application queued the first buffer directly, but later attempted to use a request. It is not permitted to mix the two APIs.

- **ENOENT**

  The request did not contain any buffers. All requests are required to have at least one buffer. This can also be returned if some required configuration is missing in the request.

- **ENOMEM**

  Out of memory when allocating internal data structures for this request.

- **EINVAL**

  The request has invalid data.

- **EIO**

  The hardware is in a bad state. To recover, the application needs to stop streaming to reset the hardware state and then try to restart streaming.

---

# ioctl MEDIA_REQUEST_IOC_REINIT

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> MEDIA_REQUEST_IOC_REINIT - Re-initialize a request

<a id="rst-ioctl-media-request-ioc-reinit"></a>
<a id="rst-media-request-ioc-reinit"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

MEDIA_REQUEST_IOC_REINIT - Re-initialize a request

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

## Synopsis





<a id="c-MEDIA_REQUEST_IOC_REINIT"></a>

```c
MEDIA_REQUEST_IOC_REINIT
```

`int ioctl(int request_fd, MEDIA_REQUEST_IOC_REINIT)`

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

## Arguments

- **`request_fd`**

  File descriptor returned by [ioctl MEDIA_IOC_REQUEST_ALLOC](</kernel/userspace/userspace-api/media-mediactl/media-ioc-request-alloc.md#rst-media-ioc-request-alloc>).

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

## Description

If the media device supports [requests](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>), then this request ioctl can be used to re-initialize a previously allocated request.

Re-initializing a request will clear any existing data from the request. This avoids having to `close()` a completed request and allocate a new request. Instead the completed request can just be re-initialized and it is ready to be used again.

A request can only be re-initialized if it either has not been queued yet, or if it was queued and completed. Otherwise it will set `errno` to `EBUSY`. No other error codes can be returned.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately.

- **EBUSY**

  The request is queued but not yet completed.

---

# Types and flags used to represent the media graph elements

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> One and only one of MEDIA_PAD_FL_SINK and MEDIA_PAD_FL_SOURCE must be set for every pad.

<a id="rst-types-and-flags-used-to-represent-the-media-graph-elements"></a>
<a id="rst-media-controller-types"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- tabularcolumns: |p{8.2cm}|p{9.3cm}| -->

<a id="rst-media-ent-f-dv-encoder"></a>
<a id="rst-media-ent-f-dv-decoder"></a>
<a id="rst-media-ent-f-vid-if-bridge"></a>
<a id="rst-media-ent-f-vid-mux"></a>
<a id="rst-media-ent-f-proc-video-isp"></a>
<a id="rst-media-ent-f-proc-video-decoder"></a>
<a id="rst-media-ent-f-proc-video-encoder"></a>
<a id="rst-media-ent-f-proc-video-statistics"></a>
<a id="rst-media-ent-f-proc-video-scaler"></a>
<a id="rst-media-ent-f-proc-video-lut"></a>
<a id="rst-media-ent-f-proc-video-pixel-enc-conv"></a>
<a id="rst-media-ent-f-proc-video-pixel-formatter"></a>
<a id="rst-media-ent-f-proc-video-composer"></a>
<a id="rst-media-ent-f-audio-mixer"></a>
<a id="rst-media-ent-f-audio-playback"></a>
<a id="rst-media-ent-f-audio-capture"></a>
<a id="rst-media-ent-f-if-aud-decoder"></a>
<a id="rst-media-ent-f-if-vid-decoder"></a>
<a id="rst-media-ent-f-tuner"></a>
<a id="rst-media-ent-f-atv-decoder"></a>
<a id="rst-media-ent-f-lens"></a>
<a id="rst-media-ent-f-flash"></a>
<a id="rst-media-ent-f-cam-sensor"></a>
<a id="rst-media-ent-f-conn-composite"></a>
<a id="rst-media-ent-f-conn-svideo"></a>
<a id="rst-media-ent-f-conn-rf"></a>
<a id="rst-media-ent-f-dtv-net-decap"></a>
<a id="rst-media-ent-f-dtv-ca"></a>
<a id="rst-media-ent-f-ts-demux"></a>
<a id="rst-media-ent-f-dtv-demod"></a>
<a id="rst-media-ent-f-io-dtv"></a>
<a id="rst-media-ent-f-io-swradio"></a>
<a id="rst-media-ent-f-io-vbi"></a>
<a id="rst-media-ent-f-io-v4l"></a>
<a id="rst-media-ent-f-v4l2-subdev-unknown"></a>
<a id="rst-media-ent-f-unknown"></a>
<a id="rst-media-entity-functions"></a>


<table>
<caption>Media entity functions</caption>
<tbody>
<tr>
<td>


`MEDIA_ENT_F_UNKNOWN` and `MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN`

</td>
<td>


Unknown entity. That generally indicates that a driver didn't initialize properly the entity, which is a Kernel bug

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_IO_V4L`

</td>
<td>


Data streaming input and/or output entity.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_IO_VBI`

</td>
<td>


V4L VBI streaming input or output entity

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_IO_SWRADIO`

</td>
<td>


V4L Software Digital Radio (SDR) streaming input or output entity

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_IO_DTV`

</td>
<td>


DVB Digital TV streaming input or output entity

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_DTV_DEMOD`

</td>
<td>


Digital TV demodulator entity.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_TS_DEMUX`

</td>
<td>


MPEG Transport stream demux entity. Could be implemented on hardware or in Kernelspace by the Linux DVB subsystem.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_DTV_CA`

</td>
<td>


Digital TV Conditional Access module (CAM) entity

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_DTV_NET_DECAP`

</td>
<td>


Digital TV network ULE/MLE desencapsulation entity. Could be implemented on hardware or in Kernelspace

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_CONN_RF`

</td>
<td>


Connector for a Radio Frequency (RF) signal.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_CONN_SVIDEO`

</td>
<td>


Connector for a S-Video signal.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_CONN_COMPOSITE`

</td>
<td>


Connector for a RGB composite signal.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_CAM_SENSOR`

</td>
<td>


Camera video sensor entity.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_FLASH`

</td>
<td>


Flash controller entity.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_LENS`

</td>
<td>


Lens controller entity.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_ATV_DECODER`

</td>
<td>


Analog video decoder, the basic function of the video decoder is to accept analogue video from a wide variety of sources such as broadcast, DVD players, cameras and video cassette recorders, in either NTSC, PAL, SECAM or HD format, separating the stream into its component parts, luminance and chrominance, and output it in some digital video standard, with appropriate timing signals.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_TUNER`

</td>
<td>


Digital TV, analog TV, radio and/or software radio tuner, with consists on a PLL tuning stage that converts radio frequency (RF) signal into an Intermediate Frequency (IF). Modern tuners have internally IF-PLL decoders for audio and video, but older models have those stages implemented on separate entities.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_IF_VID_DECODER`

</td>
<td>


IF-PLL video decoder. It receives the IF from a PLL and decodes the analog TV video signal. This is commonly found on some very old analog tuners, like Philips MK3 designs. They all contain a tda9887 (or some software compatible similar chip, like tda9885). Those devices use a different I2C address than the tuner PLL.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_IF_AUD_DECODER`

</td>
<td>


IF-PLL sound decoder. It receives the IF from a PLL and decodes the analog TV audio signal. This is commonly found on some very old analog hardware, like Micronas msp3400, Philips tda9840, tda985x, etc. Those devices use a different I2C address than the tuner PLL and should be controlled together with the IF-PLL video decoder.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_AUDIO_CAPTURE`

</td>
<td>


Audio Capture Function Entity.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_AUDIO_PLAYBACK`

</td>
<td>


Audio Playback Function Entity.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_AUDIO_MIXER`

</td>
<td>


Audio Mixer Function Entity.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_COMPOSER`

</td>
<td>


Video composer (blender). An entity capable of video composing must have at least two sink pads and one source pad, and composes input video frames onto output video frames. Composition can be performed using alpha blending, color keying, raster operations (ROP), stitching or any other means.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER`

</td>
<td>


Video pixel formatter. An entity capable of pixel formatting must have at least one sink pad and one source pad. Read pixel formatters read pixels from memory and perform a subset of unpacking, cropping, color keying, alpha multiplication and pixel encoding conversion. Write pixel formatters perform a subset of dithering, pixel encoding conversion and packing and write pixels to memory.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_PIXEL_ENC_CONV`

</td>
<td>


Video pixel encoding converter. An entity capable of pixel encoding conversion must have at least one sink pad and one source pad, and convert the encoding of pixels received on its sink pad(s) to a different encoding output on its source pad(s). Pixel encoding conversion includes but isn't limited to RGB to/from HSV, RGB to/from YUV and CFA (Bayer) to RGB conversions.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_LUT`

</td>
<td>


Video look-up table. An entity capable of video lookup table processing must have one sink pad and one source pad. It uses the values of the pixels received on its sink pad to look up entries in internal tables and output them on its source pad. The lookup processing can be performed on all components separately or combine them for multi-dimensional table lookups.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_SCALER`

</td>
<td>


Video scaler. An entity capable of video scaling must have at least one sink pad and one source pad, and scale the video frame(s) received on its sink pad(s) to a different resolution output on its source pad(s). The range of supported scaling ratios is entity-specific and can differ between the horizontal and vertical directions (in particular scaling can be supported in one direction only). Binning and sub-sampling (occasionally also referred to as skipping) are considered as scaling.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_STATISTICS`

</td>
<td>


Video statistics computation (histogram, 3A, etc.). An entity capable of statistics computation must have one sink pad and one source pad. It computes statistics over the frames received on its sink pad and outputs the statistics data on its source pad.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_ENCODER`

</td>
<td>


Video (MPEG, HEVC, VPx, etc.) encoder. An entity capable of compressing video frames. Must have one sink pad and at least one source pad.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_DECODER`

</td>
<td>


Video (MPEG, HEVC, VPx, etc.) decoder. An entity capable of decompressing a compressed video stream into uncompressed video frames. Must have one sink pad and at least one source pad.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_PROC_VIDEO_ISP`

</td>
<td>


An Image Signal Processor (ISP) device. ISPs generally are one of a kind devices that have their specific control interfaces using a combination of custom V4L2 controls and IOCTLs, and parameters supplied in a metadata buffer.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_VID_MUX`

</td>
<td>


Video multiplexer. An entity capable of multiplexing must have at least two sink pads and one source pad, and must pass the video frame(s) received from the active sink pad to the source pad.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_VID_IF_BRIDGE`

</td>
<td>


Video interface bridge. A video interface bridge entity must have at least one sink pad and at least one source pad. It receives video frames on its sink pad from an input video bus of one type (HDMI, eDP, MIPI CSI-2, etc.), and outputs them on its source pad to an output video bus of another type (eDP, MIPI CSI-2, parallel, etc.).

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_DV_DECODER`

</td>
<td>


Digital video decoder. The basic function of the video decoder is to accept digital video from a wide variety of sources and output it in some digital video standard, with appropriate timing signals.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_F_DV_ENCODER`

</td>
<td>


Digital video encoder. The basic function of the video encoder is to accept digital video from some digital video standard with appropriate timing signals (usually a parallel video bus with sync signals) and output this to a digital video output connector such as HDMI or DisplayPort.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.5cm}|p{12.0cm}| -->

<a id="rst-media-ent-fl-connector"></a>
<a id="rst-media-ent-fl-default"></a>
<a id="rst-media-entity-flag"></a>


<table>
<caption>Media entity flags</caption>
<tbody>
<tr>
<td>


`MEDIA_ENT_FL_DEFAULT`

</td>
<td>


Default entity for its type. Used to discover the default audio, VBI and video devices, the default camera sensor, etc.

</td>
</tr>
<tr>
<td>


`MEDIA_ENT_FL_CONNECTOR`

</td>
<td>


The entity represents a connector.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.5cm}|p{6.0cm}|p{4.8cm}| -->

<a id="rst-media-intf-t-alsa-timer"></a>
<a id="rst-media-intf-t-alsa-sequencer"></a>
<a id="rst-media-intf-t-alsa-hwdep"></a>
<a id="rst-media-intf-t-alsa-rawmidi"></a>
<a id="rst-media-intf-t-alsa-compress"></a>
<a id="rst-media-intf-t-alsa-control"></a>
<a id="rst-media-intf-t-alsa-pcm-playback"></a>
<a id="rst-media-intf-t-alsa-pcm-capture"></a>
<a id="rst-media-intf-t-v4l-touch"></a>
<a id="rst-media-intf-t-v4l-swradio"></a>
<a id="rst-media-intf-t-v4l-subdev"></a>
<a id="rst-media-intf-t-v4l-radio"></a>
<a id="rst-media-intf-t-v4l-vbi"></a>
<a id="rst-media-intf-t-v4l-video"></a>
<a id="rst-media-intf-t-dvb-net"></a>
<a id="rst-media-intf-t-dvb-ca"></a>
<a id="rst-media-intf-t-dvb-dvr"></a>
<a id="rst-media-intf-t-dvb-demux"></a>
<a id="rst-media-intf-t-dvb-fe"></a>
<a id="rst-media-intf-type"></a>


<table>
<caption>Media interface types</caption>
<tbody>
<tr>
<td>


`MEDIA_INTF_T_DVB_FE`

</td>
<td>


Device node interface for the Digital TV frontend

</td>
<td>


typically, /dev/dvb/adapter?/frontend?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_DVB_DEMUX`

</td>
<td>


Device node interface for the Digital TV demux

</td>
<td>


typically, /dev/dvb/adapter?/demux?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_DVB_DVR`

</td>
<td>


Device node interface for the Digital TV DVR

</td>
<td>


typically, /dev/dvb/adapter?/dvr?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_DVB_CA`

</td>
<td>


Device node interface for the Digital TV Conditional Access

</td>
<td>


typically, /dev/dvb/adapter?/ca?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_DVB_NET`

</td>
<td>


Device node interface for the Digital TV network control

</td>
<td>


typically, /dev/dvb/adapter?/net?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_V4L_VIDEO`

</td>
<td>


Device node interface for video (V4L)

</td>
<td>


typically, /dev/video?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_V4L_VBI`

</td>
<td>


Device node interface for VBI (V4L)

</td>
<td>


typically, /dev/vbi?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_V4L_RADIO`

</td>
<td>


Device node interface for radio (V4L)

</td>
<td>


typically, /dev/radio?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_V4L_SUBDEV`

</td>
<td>


Device node interface for a V4L subdevice

</td>
<td>


typically, /dev/v4l-subdev?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_V4L_SWRADIO`

</td>
<td>


Device node interface for Software Defined Radio (V4L)

</td>
<td>


typically, /dev/swradio?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_V4L_TOUCH`

</td>
<td>


Device node interface for Touch device (V4L)

</td>
<td>


typically, /dev/v4l-touch?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_ALSA_PCM_CAPTURE`

</td>
<td>


Device node interface for ALSA PCM Capture

</td>
<td>


typically, /dev/snd/pcmC?D?c

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_ALSA_PCM_PLAYBACK`

</td>
<td>


Device node interface for ALSA PCM Playback

</td>
<td>


typically, /dev/snd/pcmC?D?p

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_ALSA_CONTROL`

</td>
<td>


Device node interface for ALSA Control

</td>
<td>


typically, /dev/snd/controlC?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_ALSA_COMPRESS`

</td>
<td>


Device node interface for ALSA Compress

</td>
<td>


typically, /dev/snd/compr?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_ALSA_RAWMIDI`

</td>
<td>


Device node interface for ALSA Raw MIDI

</td>
<td>


typically, /dev/snd/midi?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_ALSA_HWDEP`

</td>
<td>


Device node interface for ALSA Hardware Dependent

</td>
<td>


typically, /dev/snd/hwC?D?

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_ALSA_SEQUENCER`

</td>
<td>


Device node interface for ALSA Sequencer

</td>
<td>


typically, /dev/snd/seq

</td>
</tr>
<tr>
<td>


`MEDIA_INTF_T_ALSA_TIMER`

</td>
<td>


Device node interface for ALSA Timer

</td>
<td>


typically, /dev/snd/timer

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.5cm}|p{12.0cm}| -->

<a id="rst-media-pad-fl-must-connect"></a>
<a id="rst-media-pad-fl-source"></a>
<a id="rst-media-pad-fl-sink"></a>
<a id="rst-media-pad-flag"></a>


<table>
<caption>Media pad flags</caption>
<tbody>
<tr>
<td>


`MEDIA_PAD_FL_SINK`

</td>
<td>


Input pad, relative to the entity. Input pads sink data and are targets of links.

</td>
</tr>
<tr>
<td>


`MEDIA_PAD_FL_SOURCE`

</td>
<td>


Output pad, relative to the entity. Output pads source data and are origins of links.

</td>
</tr>
<tr>
<td>


`MEDIA_PAD_FL_MUST_CONNECT`

</td>
<td>


If this flag is set, then for this pad to be able to stream, it must be connected by at least one enabled link. There could be temporary reasons (e.g. device configuration dependent) for the pad to need enabled links even when this flag isn't set; the absence of the flag doesn't imply there is none.

</td>
</tr>
</tbody>
</table>

One and only one of `MEDIA_PAD_FL_SINK` and `MEDIA_PAD_FL_SOURCE` must be set for every pad.

<!-- tabularcolumns: |p{5.5cm}|p{12.0cm}| -->

<a id="rst-media-lnk-fl-link-type"></a>
<a id="rst-media-lnk-fl-dynamic"></a>
<a id="rst-media-lnk-fl-immutable"></a>
<a id="rst-media-lnk-fl-enabled"></a>
<a id="rst-media-link-flag"></a>


<table>
<caption>Media link flags</caption>
<tbody>
<tr>
<td>


`MEDIA_LNK_FL_ENABLED`

</td>
<td>


The link is enabled and can be used to transfer media data. When two or more links target a sink pad, only one of them can be enabled at a time.

</td>
</tr>
<tr>
<td>


`MEDIA_LNK_FL_IMMUTABLE`

</td>
<td>


The link enabled state can't be modified at runtime. An immutable link is always enabled.

</td>
</tr>
<tr>
<td>


`MEDIA_LNK_FL_DYNAMIC`

</td>
<td>


The link enabled state can be modified during streaming. This flag is set by drivers and is read-only for applications.

</td>
</tr>
<tr>
<td>


`MEDIA_LNK_FL_LINK_TYPE`

</td>
<td>


This is a bitmask that defines the type of the link. The following link types are currently supported:

<a id="rst-media-lnk-fl-data-link"></a>

`MEDIA_LNK_FL_DATA_LINK` for links that represent a data connection between two pads.

<a id="rst-media-lnk-fl-interface-link"></a>

`MEDIA_LNK_FL_INTERFACE_LINK` for links that associate an entity to its interface.

<a id="rst-media-lnk-fl-ancillary-link"></a>

`MEDIA_LNK_FL_ANCILLARY_LINK` for links that represent a physical relationship between two entities. The link may or may not be immutable, so applications must not assume either case.

</td>
</tr>
</tbody>
</table>

---

# Request API

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> The Request API has been designed to allow V4L2 to deal with requirements of modern devices (stateless codecs, complex camera pipelines, ...) and APIs (Android Codec v2). One such requirement is the ability for devices belonging to the…

<a id="rst-request-api"></a>
<a id="rst-media-request-api"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

The Request API has been designed to allow V4L2 to deal with requirements of modern devices (stateless codecs, complex camera pipelines, ...) and APIs (Android Codec v2). One such requirement is the ability for devices belonging to the same pipeline to reconfigure and collaborate closely on a per-frame basis. Another is support of stateless codecs, which require controls to be applied to specific frames (aka 'per-frame controls') in order to be used efficiently.

While the initial use-case was V4L2, it can be extended to other subsystems as well, as long as they use the media controller.

Supporting these features without the Request API is not always possible and if it is, it is terribly inefficient: user-space would have to flush all activity on the media pipeline, reconfigure it for the next frame, queue the buffers to be processed with that configuration, and wait until they are all available for dequeuing before considering the next frame. This defeats the purpose of having buffer queues since in practice only one buffer would be queued at a time.

The Request API allows a specific configuration of the pipeline (media controller topology + configuration for each media entity) to be associated with specific buffers. This allows user-space to schedule several tasks ("requests") with different configurations in advance, knowing that the configuration will be applied when needed to get the expected result. Configuration values at the time of request completion are also available for reading.

<a id="rst-general-usage"></a>

## General Usage

The Request API extends the Media Controller API and cooperates with subsystem-specific APIs to support request usage. At the Media Controller level, requests are allocated from the supporting Media Controller device node. Their life cycle is then managed through the request file descriptors in an opaque way. Configuration data, buffer handles and processing results stored in requests are accessed through subsystem-specific APIs extended for request support, such as V4L2 APIs that take an explicit `request_fd` parameter.

<a id="rst-request-allocation"></a>

## Request Allocation

User-space allocates requests using [ioctl MEDIA_IOC_REQUEST_ALLOC](</kernel/userspace/userspace-api/media-mediactl/media-ioc-request-alloc.md#rst-media-ioc-request-alloc>) for the media device node. This returns a file descriptor representing the request. Typically, several such requests will be allocated.

<a id="rst-request-preparation"></a>

## Request Preparation

Standard V4L2 ioctls can then receive a request file descriptor to express the fact that the ioctl is part of said request, and is not to be applied immediately. See [ioctl MEDIA_IOC_REQUEST_ALLOC](</kernel/userspace/userspace-api/media-mediactl/media-ioc-request-alloc.md#rst-media-ioc-request-alloc>) for a list of ioctls that support this. Configurations set with a `request_fd` parameter are stored instead of being immediately applied, and buffers queued to a request do not enter the regular buffer queue until the request itself is queued.

<a id="rst-request-submission"></a>

## Request Submission

Once the configuration and buffers of the request are specified, it can be queued by calling [ioctl MEDIA_REQUEST_IOC_QUEUE](</kernel/userspace/userspace-api/media-mediactl/media-request-ioc-queue.md#rst-media-request-ioc-queue>) on the request file descriptor. A request must contain at least one buffer, otherwise `ENOENT` is returned. A queued request cannot be modified anymore.

> [!CAUTION]
>
> For [memory-to-memory devices](</kernel/userspace/userspace-api/media-v4l/dev-mem2mem.md#rst-mem2mem>) you can use requests only for output buffers, not for capture buffers. Attempting to add a capture buffer to a request will result in an `EBADR` error.

If the request contains configurations for multiple entities, individual drivers may synchronize so the requested pipeline's topology is applied before the buffers are processed. Media controller drivers do a best effort implementation since perfect atomicity may not be possible due to hardware limitations.

> [!CAUTION]
>
> It is not allowed to mix queuing requests with directly queuing buffers: whichever method is used first locks this in place until [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) is called or the device is [closed](</kernel/userspace/userspace-api/media-v4l/func-close.md#rst-func-close>). Attempts to directly queue a buffer when earlier a buffer was queued via a request or vice versa will result in an `EBUSY` error.

Controls can still be set without a request and are applied immediately, regardless of whether a request is in use or not.

> [!CAUTION]
>
> Setting the same control through a request and also directly can lead to undefined behavior\!

User-space can `poll()` a request file descriptor in order to wait until the request completes. A request is considered complete once all its associated buffers are available for dequeuing and all the associated controls have been updated with the values at the time of completion. Note that user-space does not need to wait for the request to complete to dequeue its buffers: buffers that are available halfway through a request can be dequeued independently of the request's state.

A completed request contains the state of the device after the request was executed. User-space can query that state by calling [ioctl VIDIOC_G_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) with the request file descriptor. Calling [ioctl VIDIOC_G_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for a request that has been queued but not yet completed will return `EBUSY` since the control values might be changed at any time by the driver while the request is in flight.

<a id="rst-recycling-and-destruction"></a>
<a id="rst-media-request-life-time"></a>

## Recycling and Destruction

Finally, a completed request can either be discarded or be reused. Calling `close()` on a request file descriptor will make that file descriptor unusable and the request will be freed once it is no longer in use by the kernel. That is, if the request is queued and then the file descriptor is closed, then it won't be freed until the driver completed the request.

The [ioctl MEDIA_REQUEST_IOC_REINIT](</kernel/userspace/userspace-api/media-mediactl/media-request-ioc-reinit.md#rst-media-request-ioc-reinit>) will clear a request's state and make it available again. No state is retained by this operation: the request is as if it had just been allocated.

<a id="rst-example-for-a-codec-device"></a>

## Example for a Codec Device

For use-cases such as [codecs](</kernel/userspace/userspace-api/media-v4l/dev-mem2mem.md#rst-mem2mem>), the request API can be used to associate specific controls to be applied by the driver for the OUTPUT buffer, allowing user-space to queue many such buffers in advance. It can also take advantage of requests' ability to capture the state of controls when the request completes to read back information that may be subject to change.

Put into code, after obtaining a request, user-space can assign controls and one OUTPUT buffer to it:



```c
struct v4l2_buffer buf;
struct v4l2_ext_controls ctrls;
int req_fd;
...
if (ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &req_fd))
        return errno;
...
ctrls.which = V4L2_CTRL_WHICH_REQUEST_VAL;
ctrls.request_fd = req_fd;
if (ioctl(codec_fd, VIDIOC_S_EXT_CTRLS, &ctrls))
        return errno;
...
buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
buf.flags |= V4L2_BUF_FLAG_REQUEST_FD;
buf.request_fd = req_fd;
if (ioctl(codec_fd, VIDIOC_QBUF, &buf))
        return errno;
```

Note that it is not allowed to use the Request API for CAPTURE buffers since there are no per-frame settings to report there.

Once the request is fully prepared, it can be queued to the driver:



```c
if (ioctl(req_fd, MEDIA_REQUEST_IOC_QUEUE))
        return errno;
```

User-space can then either wait for the request to complete by calling poll() on its file descriptor, or start dequeuing CAPTURE buffers. Most likely, it will want to get CAPTURE buffers as soon as possible and this can be done using a regular [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>):



```c
struct v4l2_buffer buf;

memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (ioctl(codec_fd, VIDIOC_DQBUF, &buf))
        return errno;
```

Note that this example assumes for simplicity that for every OUTPUT buffer there will be one CAPTURE buffer, but this does not have to be the case.

We can then, after ensuring that the request is completed via polling the request file descriptor, query control values at the time of its completion via a call to [VIDIOC_G_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>). This is particularly useful for volatile controls for which we want to query values as soon as the capture buffer is produced.



```c
struct pollfd pfd = { .events = POLLPRI, .fd = req_fd };
poll(&pfd, 1, -1);
...
ctrls.which = V4L2_CTRL_WHICH_REQUEST_VAL;
ctrls.request_fd = req_fd;
if (ioctl(codec_fd, VIDIOC_G_EXT_CTRLS, &ctrls))
        return errno;
```

Once we don't need the request anymore, we can either recycle it for reuse with [ioctl MEDIA_REQUEST_IOC_REINIT](</kernel/userspace/userspace-api/media-mediactl/media-request-ioc-reinit.md#rst-media-request-ioc-reinit>)...



```c
if (ioctl(req_fd, MEDIA_REQUEST_IOC_REINIT))
        return errno;
```

... or close its file descriptor to completely dispose of it.



```c
close(req_fd);
```

<a id="rst-example-for-a-simple-capture-device"></a>

## Example for a Simple Capture Device

With a simple capture device, requests can be used to specify controls to apply for a given CAPTURE buffer.



```c
struct v4l2_buffer buf;
struct v4l2_ext_controls ctrls;
int req_fd;
...
if (ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &req_fd))
        return errno;
...
ctrls.which = V4L2_CTRL_WHICH_REQUEST_VAL;
ctrls.request_fd = req_fd;
if (ioctl(camera_fd, VIDIOC_S_EXT_CTRLS, &ctrls))
        return errno;
...
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.flags |= V4L2_BUF_FLAG_REQUEST_FD;
buf.request_fd = req_fd;
if (ioctl(camera_fd, VIDIOC_QBUF, &buf))
        return errno;
```

Once the request is fully prepared, it can be queued to the driver:



```c
if (ioctl(req_fd, MEDIA_REQUEST_IOC_QUEUE))
        return errno;
```

User-space can then dequeue buffers, wait for the request completion, query controls and recycle the request as in the M2M example above.

---

# request close()

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> request-close - Close a request file descriptor

<a id="rst-request-close"></a>
<a id="rst-request-func-close"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC.request -->

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

## Name

request-close - Close a request file descriptor

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-close"></a>

```c
int close( int fd )
```

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

## Arguments

- **`fd`**

  File descriptor returned by [ioctl MEDIA_IOC_REQUEST_ALLOC](</kernel/userspace/userspace-api/media-mediactl/media-ioc-request-alloc.md#rst-media-ioc-request-alloc>).

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

## Description

Closes the request file descriptor. Resources associated with the request are freed once all file descriptors associated with the request are closed and the driver has completed the request. See [here](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-life-time>) for more information.

<a id="rst-return-value"></a>

## Return Value

`close()` returns 0 on success. On error, -1 is returned, and `errno` is set appropriately. Possible error codes are:

- **EBADF**

  `fd` is not a valid open file descriptor.

---

# request ioctl()

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> request-ioctl - Control a request file descriptor

<a id="rst-request-ioctl"></a>
<a id="rst-request-func-ioctl"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

request-ioctl - Control a request file descriptor

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

## Synopsis



```c
#include <sys/ioctl.h>
```

`int ioctl(int fd, int cmd, void *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by [ioctl MEDIA_IOC_REQUEST_ALLOC](</kernel/userspace/userspace-api/media-mediactl/media-ioc-request-alloc.md#rst-media-ioc-request-alloc>).

- **`cmd`**

  The request ioctl command code as defined in the media.h header file, for example [ioctl MEDIA_REQUEST_IOC_QUEUE](</kernel/userspace/userspace-api/media-mediactl/media-request-ioc-queue.md#rst-media-request-ioc-queue>).

- **`argp`**

  Pointer to a request-specific structure.

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

## Description

The [ioctl()](<#rst-request-func-ioctl>) function manipulates request parameters. The argument `fd` must be an open file descriptor.

The ioctl `cmd` code specifies the request function to be called. It has encoded in it whether the argument is an input, output or read/write parameter, and the size of the argument `argp` in bytes.

Macros and structures definitions specifying request ioctl commands and their parameters are located in the media.h header file. All request ioctl commands, their respective function and parameters are specified in [Function Reference](</kernel/userspace/userspace-api/media-mediactl/media-funcs.md#rst-media-user-func>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

Command-specific error codes are listed in the individual command descriptions.

When an ioctl that takes an output or read/write parameter fails, the parameter remains unmodified.

---

# request poll()

_Peios Kernel / Userspace interfaces / System and device interfaces / Media controllers_

> request-poll - Wait for some event on a file descriptor

<a id="rst-request-poll"></a>
<a id="rst-request-func-poll"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: MC -->

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

## Name

request-poll - Wait for some event on a file descriptor

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

## Synopsis



```c
#include <sys/poll.h>
```





<a id="c-poll"></a>

```c
int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
```

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

## Arguments

- **`ufds`**

  List of file descriptor events to be watched

- **`nfds`**

  Number of file descriptor events at the \*ufds array

- **`timeout`**

  Timeout to wait for events

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

## Description

With the `poll()` function applications can wait for a request to complete.

On success `poll()` returns the number of file descriptors that have been selected (that is, file descriptors for which the `revents` field of the respective struct `pollfd` is non-zero). Request file descriptor set the `POLLPRI` flag in `revents` when the request was completed.  When the function times out it returns a value of zero, on failure it returns -1 and the `errno` variable is set appropriately.

Attempting to poll for a request that is not yet queued will set the `POLLERR` flag in `revents`.

<a id="rst-return-value"></a>

## Return Value

On success, `poll()` returns the number of structures which have non-zero `revents` fields, or zero if the call timed out. On error -1 is returned, and the `errno` variable is set appropriately:

- **`EBADF`**

  One or more of the `ufds` members specify an invalid file descriptor.

- **`EFAULT`**

  `ufds` references an inaccessible memory area.

- **`EINTR`**

  The call was interrupted by a signal.

- **`EINVAL`**

  The `nfds` value exceeds the `RLIMIT_NOFILE` value. Use `getrlimit()` to obtain this value.

---

# file: uapi/v4l/keytable.c

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Reference for file: uapi/v4l/keytable.c.

<a id="rst-file-uapi-v4l-keytable-c"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->



```c
/* keytable.c - This program allows checking/replacing keys at IR

   Copyright (C) 2006-2009 Mauro Carvalho Chehab <mchehab@kernel.org>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 */

#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/input.h>
#include <sys/ioctl.h>

#include "parse.h"

void prtcode (int *codes)
{
        struct parse_key *p;

        for (p=keynames;p->name!=NULL;p++) {
                if (p->value == (unsigned)codes[1]) {
                        printf("scancode 0x%04x = %s (0x%02x)\\n", codes[0], p->name, codes[1]);
                        return;
                }
        }

        if (isprint (codes[1]))
                printf("scancode %d = '%c' (0x%02x)\\n", codes[0], codes[1], codes[1]);
        else
                printf("scancode %d = 0x%02x\\n", codes[0], codes[1]);
}

int parse_code(char *string)
{
        struct parse_key *p;

        for (p=keynames;p->name!=NULL;p++) {
                if (!strcasecmp(p->name, string)) {
                        return p->value;
                }
        }
        return -1;
}

int main (int argc, char *argv[])
{
        int fd;
        unsigned int i, j;
        int codes[2];

        if (argc<2 || argc>4) {
                printf ("usage: %s <device> to get table; or\\n"
                        "       %s <device> <scancode> <keycode>\\n"
                        "       %s <device> <keycode_file>n",*argv,*argv,*argv);
                return -1;
        }

        if ((fd = open(argv[1], O_RDONLY)) < 0) {
                perror("Couldn't open input device");
                return(-1);
        }

        if (argc==4) {
                int value;

                value=parse_code(argv[3]);

                if (value==-1) {
                        value = strtol(argv[3], NULL, 0);
                        if (errno)
                                perror("value");
                }

                codes [0] = (unsigned) strtol(argv[2], NULL, 0);
                codes [1] = (unsigned) value;

                if(ioctl(fd, EVIOCSKEYCODE, codes))
                        perror ("EVIOCSKEYCODE");

                if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
                        prtcode(codes);
                return 0;
        }

        if (argc==3) {
                FILE *fin;
                int value;
                char *scancode, *keycode, s[2048];

                fin=fopen(argv[2],"r");
                if (fin==NULL) {
                        perror ("opening keycode file");
                        return -1;
                }

                /* Clears old table */
                for (j = 0; j < 256; j++) {
                        for (i = 0; i < 256; i++) {
                                codes[0] = (j << 8) | i;
                                codes[1] = KEY_RESERVED;
                                ioctl(fd, EVIOCSKEYCODE, codes);
                        }
                }

                while (fgets(s,sizeof(s),fin)) {
                        scancode=strtok(s,"\\n\\t =:");
                        if (!scancode) {
                                perror ("parsing input file scancode");
                                return -1;
                        }
                        if (!strcasecmp(scancode, "scancode")) {
                                scancode = strtok(NULL,"\\n\\t =:");
                                if (!scancode) {
                                        perror ("parsing input file scancode");
                                        return -1;
                                }
                        }

                        keycode=strtok(NULL,"\\n\\t =:(");
                        if (!keycode) {
                                perror ("parsing input file keycode");
                                return -1;
                        }

                        // printf ("parsing %s=%s:", scancode, keycode);
                        value=parse_code(keycode);
                        // printf ("\\tvalue=%d\\n",value);

                        if (value==-1) {
                                value = strtol(keycode, NULL, 0);
                                if (errno)
                                        perror("value");
                        }

                        codes [0] = (unsigned) strtol(scancode, NULL, 0);
                        codes [1] = (unsigned) value;

                        // printf("\\t%04x=%04x\\n",codes[0], codes[1]);
                        if(ioctl(fd, EVIOCSKEYCODE, codes)) {
                                fprintf(stderr, "Setting scancode 0x%04x with 0x%04x via ",codes[0], codes[1]);
                                perror ("EVIOCSKEYCODE");
                        }

                        if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
                                prtcode(codes);
                }
                return 0;
        }

        /* Get scancode table */
        for (j = 0; j < 256; j++) {
                for (i = 0; i < 256; i++) {
                        codes[0] = (j << 8) | i;
                        if (!ioctl(fd, EVIOCGKEYCODE, codes) && codes[1] != KEY_RESERVED)
                                prtcode(codes);
                }
        }
        return 0;
}
```

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC stands for Linux Infrared Remote Control. The LIRC device interface is a bi-directional interface for transporting raw IR and decoded scancodes data between userspace and kernelspace. Fundamentally, it is just a chardev (/dev/lircX,…

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<a id="rst-introduction"></a>
<a id="rst-lirc-dev-intro"></a>

## Introduction

LIRC stands for Linux Infrared Remote Control. The LIRC device interface is a bi-directional interface for transporting raw IR and decoded scancodes data between userspace and kernelspace. Fundamentally, it is just a chardev (/dev/lircX, for X = 0, 1, 2, ...), with a number of standard struct file_operations defined on it. With respect to transporting raw IR and decoded scancodes to and fro, the essential fops are read, write and ioctl.

It is also possible to attach a BPF program to a LIRC device for decoding raw IR into scancodes.

Example dmesg output upon a driver registering w/LIRC:



```none
$ dmesg |grep lirc_dev
rc rc0: lirc_dev: driver mceusb registered at minor = 0, raw IR receiver, raw IR transmitter
```

What you should see for a chardev:



```none
$ ls -l /dev/lirc*
crw-rw---- 1 root root 248, 0 Jul 2 22:20 /dev/lirc0
```

Note that the package [v4l-utils](<https://git.linuxtv.org/v4l-utils.git/>)<a id="rst-v4l-utils"></a> contains tools for working with LIRC devices:

> - ir-ctl: can receive raw IR and transmit IR, as well as query LIRC device features.
>
> - ir-keytable: can load keymaps; allows you to set IR kernel protocols; load BPF IR decoders and test IR decoding. Some BPF IR decoders are also provided.

<a id="rst-lirc-modes-1"></a>
<a id="rst-lirc-modes"></a>

## LIRC modes

LIRC supports some modes of receiving and sending IR codes, as shown on the following table.

<a id="rst-lirc-scancode-flag-repeat"></a>
<a id="rst-lirc-scancode-flag-toggle"></a>
<a id="rst-lirc-mode-scancode"></a>

`LIRC_MODE_SCANCODE`

> This mode is for both sending and receiving IR.
>
> For transmitting (aka sending), create a struct lirc_scancode with the desired scancode set in the `scancode` member, `rc_proto` set to the [IR protocol](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>), and all other members set to 0. Write this struct to the lirc device.
>
> For receiving, you read struct lirc_scancode from the LIRC device. The `scancode` field is set to the received scancode and the [IR protocol](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>) is set in `rc_proto`. If the scancode maps to a valid key code, this is set in the `keycode` field, else it is set to `KEY_RESERVED`.
>
> The `flags` can have `LIRC_SCANCODE_FLAG_TOGGLE` set if the toggle bit is set in protocols that support it (e.g. rc-5 and rc-6), or `LIRC_SCANCODE_FLAG_REPEAT` for when a repeat is received for protocols that support it (e.g. nec).
>
> In the Sanyo and NEC protocol, if you hold a button on remote, rather than repeating the entire scancode, the remote sends a shorter message with no scancode, which just means button is held, a "repeat". When this is received, the `LIRC_SCANCODE_FLAG_REPEAT` is set and the scancode and keycode is repeated.
>
> With nec, there is no way to distinguish "button hold" from "repeatedly pressing the same button". The rc-5 and rc-6 protocols have a toggle bit. When a button is released and pressed again, the toggle bit is inverted. If the toggle bit is set, the `LIRC_SCANCODE_FLAG_TOGGLE` is set.
>
> The `timestamp` field is filled with the time nanoseconds (in `CLOCK_MONOTONIC`) when the scancode was decoded.

<a id="rst-lirc-mode-mode2"></a>

`LIRC_MODE_MODE2`

> The driver returns a sequence of pulse and space codes to userspace, as a series of u32 values.
>
> This mode is used only for IR receive.
>
> The upper 8 bits determine the packet type, and the lower 24 bits the payload. Use `LIRC_VALUE()` macro to get the payload, and the macro `LIRC_MODE2()` will give you the type, which is one of:
>
> `LIRC_MODE2_PULSE`
>
> > Signifies the presence of IR in microseconds, also known as *flash*.
>
> `LIRC_MODE2_SPACE`
>
> > Signifies absence of IR in microseconds, also known as *gap*.
>
> `LIRC_MODE2_FREQUENCY`
>
> > If measurement of the carrier frequency was enabled with [ioctl LIRC_SET_MEASURE_CARRIER_MODE](</kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md#rst-lirc-set-measure-carrier-mode>) then this packet gives you the carrier frequency in Hertz.
>
> `LIRC_MODE2_TIMEOUT`
>
> > When the timeout set with [ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-set-rec-timeout>) expires due to no IR being detected, this packet will be sent, with the number of microseconds with no IR.
>
> `LIRC_MODE2_OVERFLOW`
>
> > Signifies that the IR receiver encounter an overflow, and some IR is missing. The IR data after this should be correct again. The actual value is not important, but this is set to 0xffffff by the kernel for compatibility with lircd.

<a id="rst-lirc-mode-pulse"></a>

`LIRC_MODE_PULSE`

> In pulse mode, a sequence of pulse/space integer values are written to the lirc device using [LIRC write()](</kernel/userspace/userspace-api/media-rc/lirc-write.md#rst-lirc-write>).
>
> The values are alternating pulse and space lengths, in microseconds. The first and last entry must be a pulse, so there must be an odd number of entries.
>
> This mode is used only for IR send.

<a id="rst-data-types-used-by-lirc-mode-scancode"></a>

## Data types used by LIRC_MODE_SCANCODE


#### <a id="c-struct-lirc_scancode"></a>`struct lirc_scancode`

decoded scancode with protocol for use with LIRC_MODE_SCANCODE

**Definition**

```c
struct lirc_scancode {
    __u64 timestamp;
    __u16 flags;
    __u16 rc_proto;
    __u32 keycode;
    __u64 scancode;
};
```

**Members**

- `timestamp`: Timestamp in nanoseconds using CLOCK_MONOTONIC when IR
  was decoded.
- `flags`: should be 0 for transmit. When receiving scancodes,
  LIRC_SCANCODE_FLAG_TOGGLE or LIRC_SCANCODE_FLAG_REPEAT can be set
  depending on the protocol
- `rc_proto`: see enum rc_proto
- `keycode`: the translated keycode. Set to 0 for transmit.
- `scancode`: the scancode received or to be sent

#### <a id="c-enum-rc_proto"></a>`enum rc_proto`

the Remote Controller protocol

**Constants**

- `RC_PROTO_UNKNOWN`: Protocol not known
- `RC_PROTO_OTHER`: Protocol known but proprietary
- `RC_PROTO_RC5`: Philips RC5 protocol
- `RC_PROTO_RC5X_20`: Philips RC5x 20 bit protocol
- `RC_PROTO_RC5_SZ`: StreamZap variant of RC5
- `RC_PROTO_JVC`: JVC protocol
- `RC_PROTO_SONY12`: Sony 12 bit protocol
- `RC_PROTO_SONY15`: Sony 15 bit protocol
- `RC_PROTO_SONY20`: Sony 20 bit protocol
- `RC_PROTO_NEC`: NEC protocol
- `RC_PROTO_NECX`: Extended NEC protocol
- `RC_PROTO_NEC32`: NEC 32 bit protocol
- `RC_PROTO_SANYO`: Sanyo protocol
- `RC_PROTO_MCIR2_KBD`: RC6-ish MCE keyboard
- `RC_PROTO_MCIR2_MSE`: RC6-ish MCE mouse
- `RC_PROTO_RC6_0`: Philips RC6-0-16 protocol
- `RC_PROTO_RC6_6A_20`: Philips RC6-6A-20 protocol
- `RC_PROTO_RC6_6A_24`: Philips RC6-6A-24 protocol
- `RC_PROTO_RC6_6A_32`: Philips RC6-6A-32 protocol
- `RC_PROTO_RC6_MCE`: MCE (Philips RC6-6A-32 subtype) protocol
- `RC_PROTO_SHARP`: Sharp protocol
- `RC_PROTO_XMP`: XMP protocol
- `RC_PROTO_CEC`: CEC protocol
- `RC_PROTO_IMON`: iMon Pad protocol
- `RC_PROTO_RCMM12`: RC-MM protocol 12 bits
- `RC_PROTO_RCMM24`: RC-MM protocol 24 bits
- `RC_PROTO_RCMM32`: RC-MM protocol 32 bits
- `RC_PROTO_XBOX_DVD`: Xbox DVD Movie Playback Kit protocol
- `RC_PROTO_MAX`: Maximum value of enum rc_proto


<a id="rst-bpf-based-ir-decoder"></a>

## BPF based IR decoder

The kernel has support for decoding the most common [IR protocols](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>), but there are many protocols which are not supported. To support these, it is possible to load an BPF program which does the decoding. This can only be done on LIRC devices which support reading raw IR.

First, using the [bpf(2)](<http://man7.org/linux/man-pages/man2/bpf.2.html>) syscall with the `BPF_LOAD_PROG` argument, program must be loaded of type `BPF_PROG_TYPE_LIRC_MODE2`. Once attached to the LIRC device, this program will be called for each pulse, space or timeout event on the LIRC device. The context for the BPF program is a pointer to a unsigned int, which is a [LIRC_MODE_MODE2](<#rst-lirc-mode-mode2>) value. When the program has decoded the scancode, it can be submitted using the BPF functions `bpf_rc_keydown()` or `bpf_rc_repeat()`. Mouse or pointer movements can be reported using `bpf_rc_pointer_rel()`.

Once you have the file descriptor for the `BPF_PROG_TYPE_LIRC_MODE2` BPF program, it can be attached to the LIRC device using the [bpf(2)](<http://man7.org/linux/man-pages/man2/bpf.2.html>) syscall. The target must be the file descriptor for the LIRC device, and the attach type must be `BPF_LIRC_MODE2`. No more than 64 BPF programs can be attached to a single LIRC device at a time.

<a id="rst-bpf-2"></a>

---

# LIRC Device Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Reference for LIRC Device Interface.

<a id="rst-lirc-device-interface"></a>
<a id="rst-lirc-dev"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

- [Introduction](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md>)
- [LIRC Function Reference](</kernel/userspace/userspace-api/media-rc/lirc-func.md>)
- [lirc-header](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/rc/lirc-header.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

---

# LIRC Function Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Reference for LIRC Function Reference.

<a id="rst-lirc-function-reference"></a>
<a id="rst-lirc-func"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

- [LIRC read()](</kernel/userspace/userspace-api/media-rc/lirc-read.md>)
- [LIRC write()](</kernel/userspace/userspace-api/media-rc/lirc-write.md>)
- [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md>)
- [ioctls LIRC_GET_SEND_MODE and LIRC_SET_SEND_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md>)
- [ioctls LIRC_GET_REC_MODE and LIRC_SET_REC_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md>)
- [ioctl LIRC_GET_REC_RESOLUTION](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-resolution.md>)
- [ioctl LIRC_SET_SEND_DUTY_CYCLE](</kernel/userspace/userspace-api/media-rc/lirc-set-send-duty-cycle.md>)
- [ioctls LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-get-timeout.md>)
- [ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md>)
- [ioctl LIRC_SET_REC_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier.md>)
- [ioctl LIRC_SET_REC_CARRIER_RANGE](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier-range.md>)
- [ioctl LIRC_SET_SEND_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-send-carrier.md>)
- [ioctl LIRC_SET_TRANSMITTER_MASK](</kernel/userspace/userspace-api/media-rc/lirc-set-transmitter-mask.md>)
- [ioctl LIRC_SET_MEASURE_CARRIER_MODE](</kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md>)
- [ioctl LIRC_SET_WIDEBAND_RECEIVER](</kernel/userspace/userspace-api/media-rc/lirc-set-wideband-receiver.md>)

---

# ioctl LIRC_GET_FEATURES

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_FEATURES - Get the underlying hardware device's features

<a id="rst-ioctl-lirc-get-features"></a>
<a id="rst-lirc-get-features"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_GET_FEATURES - Get the underlying hardware device's features

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

## Synopsis





<a id="c-LIRC_GET_FEATURES"></a>

```c
LIRC_GET_FEATURES
```

`int ioctl(int fd, LIRC_GET_FEATURES, __u32 *features)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`features`**

  Bitmask with the LIRC features.

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

## Description

Get the underlying hardware device's features. If a driver does not announce support of certain features, calling of the corresponding ioctls is undefined.

<a id="rst-lirc-features"></a>

## LIRC features

<a id="rst-lirc-can-rec-raw"></a>

`LIRC_CAN_REC_RAW`

> Unused. Kept just to avoid breaking uAPI.

<a id="rst-lirc-can-rec-pulse"></a>

`LIRC_CAN_REC_PULSE`

> Unused. Kept just to avoid breaking uAPI. [LIRC_MODE_PULSE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse>) can only be used for transmitting.

<a id="rst-lirc-can-rec-mode2"></a>

`LIRC_CAN_REC_MODE2`

> This is raw IR driver for receiving. This means that [LIRC_MODE_MODE2](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2>) is used. This also implies that [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) is also supported, as long as the kernel is recent enough. Use the [ioctls LIRC_GET_REC_MODE and LIRC_SET_REC_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md#rst-lirc-set-rec-mode>) to switch modes.

<a id="rst-lirc-can-rec-lirccode"></a>

`LIRC_CAN_REC_LIRCCODE`

> Unused. Kept just to avoid breaking uAPI.

<a id="rst-lirc-can-rec-scancode"></a>

`LIRC_CAN_REC_SCANCODE`

> This is a scancode driver for receiving. This means that [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) is used.

<a id="rst-lirc-can-set-send-carrier"></a>

`LIRC_CAN_SET_SEND_CARRIER`

> The driver supports changing the modulation frequency via [ioctl LIRC_SET_SEND_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-send-carrier.md#rst-lirc-set-send-carrier>).

<a id="rst-lirc-can-set-send-duty-cycle"></a>

`LIRC_CAN_SET_SEND_DUTY_CYCLE`

> The driver supports changing the duty cycle using [ioctl LIRC_SET_SEND_DUTY_CYCLE](</kernel/userspace/userspace-api/media-rc/lirc-set-send-duty-cycle.md#rst-lirc-set-send-duty-cycle>).

<a id="rst-lirc-can-set-transmitter-mask"></a>

`LIRC_CAN_SET_TRANSMITTER_MASK`

> The driver supports changing the active transmitter(s) using [ioctl LIRC_SET_TRANSMITTER_MASK](</kernel/userspace/userspace-api/media-rc/lirc-set-transmitter-mask.md#rst-lirc-set-transmitter-mask>).

<a id="rst-lirc-can-set-rec-carrier"></a>

`LIRC_CAN_SET_REC_CARRIER`

> The driver supports setting the receive carrier frequency using [ioctl LIRC_SET_REC_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier.md#rst-lirc-set-rec-carrier>).

<a id="rst-lirc-can-set-rec-carrier-range"></a>

`LIRC_CAN_SET_REC_CARRIER_RANGE`

> The driver supports [ioctl LIRC_SET_REC_CARRIER_RANGE](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier-range.md#rst-lirc-set-rec-carrier-range>).

<a id="rst-lirc-can-get-rec-resolution"></a>

`LIRC_CAN_GET_REC_RESOLUTION`

> The driver supports [ioctl LIRC_GET_REC_RESOLUTION](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-resolution.md#rst-lirc-get-rec-resolution>).

<a id="rst-lirc-can-set-rec-timeout"></a>

`LIRC_CAN_SET_REC_TIMEOUT`

> The driver supports [ioctl LIRC_SET_REC_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-set-rec-timeout>).

<a id="rst-lirc-can-measure-carrier"></a>

`LIRC_CAN_MEASURE_CARRIER`

> The driver supports measuring of the modulation frequency using [ioctl LIRC_SET_MEASURE_CARRIER_MODE](</kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md#rst-lirc-set-measure-carrier-mode>).

<a id="rst-lirc-can-use-wideband-receiver"></a>

`LIRC_CAN_USE_WIDEBAND_RECEIVER`

> The driver supports learning mode using [ioctl LIRC_SET_WIDEBAND_RECEIVER](</kernel/userspace/userspace-api/media-rc/lirc-set-wideband-receiver.md#rst-lirc-set-wideband-receiver>).

<a id="rst-lirc-can-send-raw"></a>

`LIRC_CAN_SEND_RAW`

> Unused. Kept just to avoid breaking uAPI.

<a id="rst-lirc-can-send-pulse"></a>

`LIRC_CAN_SEND_PULSE`

> The driver supports sending (also called as IR blasting or IR TX) using [LIRC_MODE_PULSE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse>). This implies that [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) is also supported for transmit, as long as the kernel is recent enough. Use the [ioctls LIRC_GET_SEND_MODE and LIRC_SET_SEND_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md#rst-lirc-set-send-mode>) to switch modes.

<a id="rst-lirc-can-send-mode2"></a>

`LIRC_CAN_SEND_MODE2`

> Unused. Kept just to avoid breaking uAPI. [LIRC_MODE_MODE2](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2>) can only be used for receiving.

<a id="rst-lirc-can-send-lirccode"></a>

`LIRC_CAN_SEND_LIRCCODE`

> Unused. Kept just to avoid breaking uAPI.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctls LIRC_GET_REC_MODE and LIRC_SET_REC_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_REC_MODE/LIRC_SET_REC_MODE - Get/set current receive mode.

<a id="rst-ioctls-lirc-get-rec-mode-and-lirc-set-rec-mode"></a>
<a id="rst-lirc-set-rec-mode"></a>
<a id="rst-lirc-get-rec-mode"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_GET_REC_MODE/LIRC_SET_REC_MODE - Get/set current receive mode.

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

## Synopsis





<a id="c-LIRC_GET_REC_MODE"></a>

```c
LIRC_GET_REC_MODE
```

`int ioctl(int fd, LIRC_GET_REC_MODE, __u32 *mode)`





<a id="c-LIRC_SET_REC_MODE"></a>

```c
LIRC_SET_REC_MODE
```

`int ioctl(int fd, LIRC_SET_REC_MODE, __u32 *mode)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`mode`**

  Mode used for receive.

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

## Description

Get and set the current receive mode. Only [LIRC_MODE_MODE2](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2>) and [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) are supported. Use [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) to find out which modes the driver supports.

<a id="rst-return-value"></a>

## Return Value

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`ENODEV`

</td>
<td>


Device not available.

</td>
</tr>
<tr>
<td>


`ENOTTY`

</td>
<td>


Device does not support receiving.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td>


Invalid mode or invalid mode for this device.

</td>
</tr>
</tbody>
</table>

---

# ioctl LIRC_GET_REC_RESOLUTION

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_REC_RESOLUTION - Obtain the value of receive resolution, in microseconds.

<a id="rst-ioctl-lirc-get-rec-resolution"></a>
<a id="rst-lirc-get-rec-resolution"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_GET_REC_RESOLUTION - Obtain the value of receive resolution, in microseconds.

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

## Synopsis





<a id="c-LIRC_GET_REC_RESOLUTION"></a>

```c
LIRC_GET_REC_RESOLUTION
```

`int ioctl(int fd, LIRC_GET_REC_RESOLUTION, __u32 *microseconds)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`microseconds`**

  Resolution, in microseconds.

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

## Description

Some receivers have maximum resolution which is defined by internal sample rate or data format limitations. E.g. it's common that signals can only be reported in 50 microsecond steps.

This ioctl returns the integer value with such resolution, with can be used by userspace applications like lircd to automatically adjust the tolerance value.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctls LIRC_GET_SEND_MODE and LIRC_SET_SEND_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_SEND_MODE/LIRC_SET_SEND_MODE - Get/set current transmit mode.

<a id="rst-ioctls-lirc-get-send-mode-and-lirc-set-send-mode"></a>
<a id="rst-lirc-set-send-mode"></a>
<a id="rst-lirc-get-send-mode"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_GET_SEND_MODE/LIRC_SET_SEND_MODE - Get/set current transmit mode.

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

## Synopsis





<a id="c-LIRC_GET_SEND_MODE"></a>

```c
LIRC_GET_SEND_MODE
```

`int ioctl(int fd, LIRC_GET_SEND_MODE, __u32 *mode)`





<a id="c-LIRC_SET_SEND_MODE"></a>

```c
LIRC_SET_SEND_MODE
```

`int ioctl(int fd, LIRC_SET_SEND_MODE, __u32 *mode)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`mode`**

  The mode used for transmitting.

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

## Description

Get/set current transmit mode.

Only [LIRC_MODE_PULSE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse>) and [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) are supported by for IR send, depending on the driver. Use [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) to find out which modes the driver supports.

<a id="rst-return-value"></a>

## Return Value

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`ENODEV`

</td>
<td>


Device not available.

</td>
</tr>
<tr>
<td>


`ENOTTY`

</td>
<td>


Device does not support transmitting.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td>


Invalid mode or invalid mode for this device.

</td>
</tr>
</tbody>
</table>

---

# ioctls LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_MIN_TIMEOUT / LIRC_GET_MAX_TIMEOUT - Obtain the possible timeout range for IR receive.

<a id="rst-ioctls-lirc-get-min-timeout-and-lirc-get-max-timeout"></a>
<a id="rst-lirc-get-max-timeout"></a>
<a id="rst-lirc-get-min-timeout"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_GET_MIN_TIMEOUT / LIRC_GET_MAX_TIMEOUT - Obtain the possible timeout range for IR receive.

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

## Synopsis





<a id="c-LIRC_GET_MIN_TIMEOUT"></a>

```c
LIRC_GET_MIN_TIMEOUT
```

`int ioctl(int fd, LIRC_GET_MIN_TIMEOUT, __u32 *timeout)`





<a id="c-LIRC_GET_MAX_TIMEOUT"></a>

```c
LIRC_GET_MAX_TIMEOUT
```

`int ioctl(int fd, LIRC_GET_MAX_TIMEOUT, __u32 *timeout)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`timeout`**

  Timeout, in microseconds.

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

## Description

Some devices have internal timers that can be used to detect when there's no IR activity for a long time. This can help lircd in detecting that a IR signal is finished and can speed up the decoding process. Returns an integer value with the minimum/maximum timeout that can be set.

> [!NOTE]
>
> Some devices have a fixed timeout, in that case both ioctls will return the same value even though the timeout cannot be changed via [ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-set-rec-timeout>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# LIRC uAPI symbols

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Reference for LIRC uAPI symbols.

<a id="rst-lirc-uapi-symbols"></a>
<a id="rst-lirc-header"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->


## Enumerations

- [`rc_proto`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#c-enum-rc_proto): `include/uapi/linux/lirc.h`, line 205

## IOCTL Commands

- [`LIRC_GET_FEATURES`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features): `include/uapi/linux/lirc.h`, line 96
- [`LIRC_GET_MAX_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-get-timeout.md#rst-lirc-get-max-timeout): `include/uapi/linux/lirc.h`, line 103
- [`LIRC_GET_MIN_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-get-timeout.md#rst-lirc-get-min-timeout): `include/uapi/linux/lirc.h`, line 102
- [`LIRC_GET_REC_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md#rst-lirc-get-rec-mode): `include/uapi/linux/lirc.h`, line 99
- [`LIRC_GET_REC_RESOLUTION`](/kernel/userspace/userspace-api/media-rc/lirc-get-rec-resolution.md#rst-lirc-get-rec-resolution): `include/uapi/linux/lirc.h`, line 100
- [`LIRC_GET_REC_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-get-rec-timeout): `include/uapi/linux/lirc.h`, line 144
- [`LIRC_GET_SEND_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md#rst-lirc-get-send-mode): `include/uapi/linux/lirc.h`, line 98
- [`LIRC_SET_MEASURE_CARRIER_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md#rst-lirc-set-measure-carrier-mode): `include/uapi/linux/lirc.h`, line 130
- [`LIRC_SET_REC_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier.md#rst-lirc-set-rec-carrier): `include/uapi/linux/lirc.h`, line 112
- [`LIRC_SET_REC_CARRIER_RANGE`](/kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier-range.md#rst-lirc-set-rec-carrier-range): `include/uapi/linux/lirc.h`, line 136
- [`LIRC_SET_REC_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md#rst-lirc-set-rec-mode): `include/uapi/linux/lirc.h`, line 109
- [`LIRC_SET_REC_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-set-rec-timeout): `include/uapi/linux/lirc.h`, line 121
- [`LIRC_SET_SEND_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-set-send-carrier.md#rst-lirc-set-send-carrier): `include/uapi/linux/lirc.h`, line 111
- [`LIRC_SET_SEND_DUTY_CYCLE`](/kernel/userspace/userspace-api/media-rc/lirc-set-send-duty-cycle.md#rst-lirc-set-send-duty-cycle): `include/uapi/linux/lirc.h`, line 113
- [`LIRC_SET_SEND_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md#rst-lirc-set-send-mode): `include/uapi/linux/lirc.h`, line 108
- [`LIRC_SET_TRANSMITTER_MASK`](/kernel/userspace/userspace-api/media-rc/lirc-set-transmitter-mask.md#rst-lirc-set-transmitter-mask): `include/uapi/linux/lirc.h`, line 114
- [`LIRC_SET_WIDEBAND_RECEIVER`](/kernel/userspace/userspace-api/media-rc/lirc-set-wideband-receiver.md#rst-lirc-set-wideband-receiver): `include/uapi/linux/lirc.h`, line 138

## Macros and Definitions

- [`LIRC_CAN_GET_REC_RESOLUTION`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-get-rec-resolution): `include/uapi/linux/lirc.h`, line 78
- [`LIRC_CAN_MEASURE_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-measure-carrier): `include/uapi/linux/lirc.h`, line 81
- [`LIRC_CAN_REC_LIRCCODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-lirccode): `include/uapi/linux/lirc.h`, line 71
- [`LIRC_CAN_REC_MODE2`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-mode2): `include/uapi/linux/lirc.h`, line 69
- [`LIRC_CAN_REC_PULSE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-pulse): `include/uapi/linux/lirc.h`, line 68
- [`LIRC_CAN_REC_RAW`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-raw): `include/uapi/linux/lirc.h`, line 67
- [`LIRC_CAN_REC_SCANCODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-scancode): `include/uapi/linux/lirc.h`, line 70
- [`LIRC_CAN_SEND_LIRCCODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-send-lirccode): `include/uapi/linux/lirc.h`, line 59
- [`LIRC_CAN_SEND_MODE2`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-send-mode2): `include/uapi/linux/lirc.h`, line 58
- [`LIRC_CAN_SEND_PULSE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-send-pulse): `include/uapi/linux/lirc.h`, line 57
- [`LIRC_CAN_SEND_RAW`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-send-raw): `include/uapi/linux/lirc.h`, line 56
- [`LIRC_CAN_SET_REC_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-rec-carrier): `include/uapi/linux/lirc.h`, line 75
- [`LIRC_CAN_SET_REC_CARRIER_RANGE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-rec-carrier-range): `include/uapi/linux/lirc.h`, line 77
- [`LIRC_CAN_SET_REC_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-rec-timeout): `include/uapi/linux/lirc.h`, line 79
- [`LIRC_CAN_SET_SEND_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-send-carrier): `include/uapi/linux/lirc.h`, line 63
- [`LIRC_CAN_SET_SEND_DUTY_CYCLE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-send-duty-cycle): `include/uapi/linux/lirc.h`, line 64
- [`LIRC_CAN_SET_TRANSMITTER_MASK`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-transmitter-mask): `include/uapi/linux/lirc.h`, line 65
- [`LIRC_CAN_USE_WIDEBAND_RECEIVER`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-use-wideband-receiver): `include/uapi/linux/lirc.h`, line 82
- [`LIRC_MODE2_FREQUENCY`](/kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md#rst-lirc-mode2-frequency): `include/uapi/linux/lirc.h`, line 17
- [`LIRC_MODE_MODE2`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2): `include/uapi/linux/lirc.h`, line 51
- [`LIRC_MODE_PULSE`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse): `include/uapi/linux/lirc.h`, line 50
- [`LIRC_MODE_SCANCODE`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode): `include/uapi/linux/lirc.h`, line 52
- [`LIRC_SCANCODE_FLAG_REPEAT`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-scancode-flag-repeat): `include/uapi/linux/lirc.h`, line 170
- [`LIRC_SCANCODE_FLAG_TOGGLE`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-scancode-flag-toggle): `include/uapi/linux/lirc.h`, line 168

## Structures

- [`lirc_scancode`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#c-struct-lirc_scancode): `include/uapi/linux/lirc.h`, line 159

---

# LIRC read()

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> lirc-read - Read from a LIRC device

<a id="rst-lirc-read-1"></a>
<a id="rst-lirc-read"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

lirc-read - Read from a LIRC device

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-read"></a>

```c
ssize_t read( int fd, void *buf, size_t count )
```

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`buf`**

  Buffer to be filled

- **`count`**

  Max number of bytes to read

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

## Description

`read()` attempts to read up to `count` bytes from file descriptor `fd` into the buffer starting at `buf`.  If `count` is zero, `read()` returns zero and has no other results. If `count` is greater than `SSIZE_MAX`, the result is unspecified.

The exact format of the data depends on what [LIRC modes](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-modes>) a driver uses. Use [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) to get the supported mode, and use [ioctls LIRC_GET_REC_MODE and LIRC_SET_REC_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md#rst-lirc-set-rec-mode>) set the current active mode.

The mode [LIRC_MODE_MODE2](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2>) is for raw IR, in which packets containing an unsigned int value describing an IR signal are read from the chardev.

Alternatively, [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) can be available, in this mode scancodes which are either decoded by software decoders, or by hardware decoders. The `rc_proto` member is set to the [IR protocol](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>) used for transmission, and `scancode` to the decoded scancode, and the `keycode` set to the keycode or `KEY_RESERVED`.

<a id="rst-return-value"></a>

## Return Value

On success, the number of bytes read is returned. It is not an error if this number is smaller than the number of bytes requested, or the amount of data required for one frame.  On error, -1 is returned, and the `errno` variable is set appropriately.

---

# ioctl LIRC_SET_MEASURE_CARRIER_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_MEASURE_CARRIER_MODE - enable or disable measure mode

<a id="rst-ioctl-lirc-set-measure-carrier-mode"></a>
<a id="rst-lirc-set-measure-carrier-mode"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_SET_MEASURE_CARRIER_MODE - enable or disable measure mode

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

## Synopsis





<a id="c-LIRC_SET_MEASURE_CARRIER_MODE"></a>

```c
LIRC_SET_MEASURE_CARRIER_MODE
```

`int ioctl(int fd, LIRC_SET_MEASURE_CARRIER_MODE, __u32 *enable)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`enable`**

  enable = 1 means enable measure mode, enable = 0 means disable measure mode.

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

## Description

<a id="rst-lirc-mode2-frequency"></a>

Enable or disable measure mode. If enabled, from the next key press on, the driver will send `LIRC_MODE2_FREQUENCY` packets. By default this should be turned off.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_REC_CARRIER_RANGE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_REC_CARRIER_RANGE - Set lower bound of the carrier used to modulate IR receive.

<a id="rst-ioctl-lirc-set-rec-carrier-range"></a>
<a id="rst-lirc-set-rec-carrier-range"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_SET_REC_CARRIER_RANGE - Set lower bound of the carrier used to modulate IR receive.

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

## Synopsis





<a id="c-LIRC_SET_REC_CARRIER_RANGE"></a>

```c
LIRC_SET_REC_CARRIER_RANGE
```

`int ioctl(int fd, LIRC_SET_REC_CARRIER_RANGE, __u32 *frequency)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`frequency`**

  Frequency of the carrier that modulates PWM data, in Hz.

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

## Description

This ioctl sets the upper range of carrier frequency that will be recognized by the IR receiver.

> [!NOTE]
>
> To set a range use [LIRC_SET_REC_CARRIER_RANGE](<#rst-lirc-set-rec-carrier-range>) with the lower bound first and later call [LIRC_SET_REC_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier.md#rst-lirc-set-rec-carrier>) with the upper bound.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_REC_CARRIER

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_REC_CARRIER - Set carrier used to modulate IR receive.

<a id="rst-ioctl-lirc-set-rec-carrier"></a>
<a id="rst-lirc-set-rec-carrier"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_SET_REC_CARRIER - Set carrier used to modulate IR receive.

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

## Synopsis





<a id="c-LIRC_SET_REC_CARRIER"></a>

```c
LIRC_SET_REC_CARRIER
```

`int ioctl(int fd, LIRC_SET_REC_CARRIER, __u32 *frequency)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`frequency`**

  Frequency of the carrier that modulates PWM data, in Hz.

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

## Description

Set receive carrier used to modulate IR PWM pulses and spaces.

> [!NOTE]
>
> If called together with [ioctl LIRC_SET_REC_CARRIER_RANGE](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier-range.md#rst-lirc-set-rec-carrier-range>), this ioctl sets the upper bound frequency that will be recognized by the device.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_REC_TIMEOUT/LIRC_SET_REC_TIMEOUT - Get/set the integer value for IR inactivity timeout.

<a id="rst-ioctl-lirc-get-rec-timeout-and-lirc-set-rec-timeout"></a>
<a id="rst-lirc-get-rec-timeout"></a>
<a id="rst-lirc-set-rec-timeout"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_GET_REC_TIMEOUT/LIRC_SET_REC_TIMEOUT - Get/set the integer value for IR inactivity timeout.

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

## Synopsis





<a id="c-LIRC_GET_REC_TIMEOUT"></a>

```c
LIRC_GET_REC_TIMEOUT
```

`int ioctl(int fd, LIRC_GET_REC_TIMEOUT, __u32 *timeout)`





<a id="c-LIRC_SET_REC_TIMEOUT"></a>

```c
LIRC_SET_REC_TIMEOUT
```

`int ioctl(int fd, LIRC_SET_REC_TIMEOUT, __u32 *timeout)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`timeout`**

  Timeout, in microseconds.

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

## Description

Get and set the integer value for IR inactivity timeout.

If supported by the hardware, setting it to 0  disables all hardware timeouts and data should be reported as soon as possible. If the exact value cannot be set, then the next possible value \_greater\_ than the given value should be set.

> [!NOTE]
>
> The range of supported timeout is given by [ioctls LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-get-timeout.md#rst-lirc-get-min-timeout>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_SEND_CARRIER

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_SEND_CARRIER - Set send carrier used to modulate IR TX.

<a id="rst-ioctl-lirc-set-send-carrier"></a>
<a id="rst-lirc-set-send-carrier"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_SET_SEND_CARRIER - Set send carrier used to modulate IR TX.

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

## Synopsis





<a id="c-LIRC_SET_SEND_CARRIER"></a>

```c
LIRC_SET_SEND_CARRIER
```

`int ioctl(int fd, LIRC_SET_SEND_CARRIER, __u32 *frequency)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`frequency`**

  Frequency of the carrier to be modulated, in Hz.

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

## Description

Set send carrier used to modulate IR PWM pulses and spaces.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_SEND_DUTY_CYCLE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_SEND_DUTY_CYCLE - Set the duty cycle of the carrier signal for IR transmit.

<a id="rst-ioctl-lirc-set-send-duty-cycle"></a>
<a id="rst-lirc-set-send-duty-cycle"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_SET_SEND_DUTY_CYCLE - Set the duty cycle of the carrier signal for IR transmit.

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

## Synopsis





<a id="c-LIRC_SET_SEND_DUTY_CYCLE"></a>

```c
LIRC_SET_SEND_DUTY_CYCLE
```

`int ioctl(int fd, LIRC_SET_SEND_DUTY_CYCLE, __u32 *duty_cycle)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`duty_cycle`**

  Duty cycle, describing the pulse width in percent (from 1 to 99) of the total cycle. Values 0 and 100 are reserved.

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

## Description

Get/set the duty cycle of the carrier signal for IR transmit.

Currently, no special meaning is defined for 0 or 100, but this could be used to switch off carrier generation in the future, so these values should be reserved.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_TRANSMITTER_MASK

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_TRANSMITTER_MASK - Enables send codes on a given set of transmitters

<a id="rst-ioctl-lirc-set-transmitter-mask"></a>
<a id="rst-lirc-set-transmitter-mask"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_SET_TRANSMITTER_MASK - Enables send codes on a given set of transmitters

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

## Synopsis





<a id="c-LIRC_SET_TRANSMITTER_MASK"></a>

```c
LIRC_SET_TRANSMITTER_MASK
```

`int ioctl(int fd, LIRC_SET_TRANSMITTER_MASK, __u32 *mask)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`mask`**

  Mask with channels to enable tx. Channel 0 is the least significant bit.

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

## Description

Some IR TX devices have multiple output channels, in such case, [LIRC_CAN_SET_TRANSMITTER_MASK](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-transmitter-mask>) is returned via [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) and this ioctl sets what channels will send IR codes.

This ioctl enables the given set of transmitters. The first transmitter is encoded by the least significant bit and so on.

When an invalid bit mask is given, i.e. a bit is set, even though the device does not have so many transitters, then this ioctl returns the number of available transitters and does nothing otherwise.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_WIDEBAND_RECEIVER

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_WIDEBAND_RECEIVER - enable wide band receiver.

<a id="rst-ioctl-lirc-set-wideband-receiver"></a>
<a id="rst-lirc-set-wideband-receiver"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

LIRC_SET_WIDEBAND_RECEIVER - enable wide band receiver.

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

## Synopsis





<a id="c-LIRC_SET_WIDEBAND_RECEIVER"></a>

```c
LIRC_SET_WIDEBAND_RECEIVER
```

`int ioctl(int fd, LIRC_SET_WIDEBAND_RECEIVER, __u32 *enable)`

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

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`enable`**

  enable = 1 means enable wideband receiver, enable = 0 means disable wideband receiver.

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

## Description

Some receivers are equipped with special wide band receiver which is intended to be used to learn output of existing remote. This ioctl allows enabling or disabling it.

This might be useful of receivers that have otherwise narrow band receiver that prevents them to be used with some remotes. Wide band receiver might also be more precise. On the other hand its disadvantage it usually reduced range of reception.

> [!NOTE]
>
> Wide band receiver might be implicitly enabled if you enable carrier reports. In that case it will be disabled as soon as you disable carrier reports. Trying to disable wide band receiver while carrier reports are active will do nothing.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# LIRC write()

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> lirc-write - Write to a LIRC device

<a id="rst-lirc-write-1"></a>
<a id="rst-lirc-write"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

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

## Name

lirc-write - Write to a LIRC device

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-write"></a>

```c
ssize_t write( int fd, void *buf, size_t count )
```

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`buf`**

  Buffer with data to be written

- **`count`**

  Number of bytes at the buffer

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

## Description

`write()` writes up to `count` bytes to the device referenced by the file descriptor `fd` from the buffer starting at `buf`.

The exact format of the data depends on what mode a driver is in, use [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) to get the supported modes and use [ioctls LIRC_GET_SEND_MODE and LIRC_SET_SEND_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md#rst-lirc-set-send-mode>) set the mode.

When in [LIRC_MODE_PULSE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse>) mode, the data written to the chardev is a pulse/space sequence of integer values. Pulses and spaces are only marked implicitly by their position. The data must start and end with a pulse, therefore, the data must always include an uneven number of samples. The write function blocks until the data has been transmitted by the hardware. If more data is provided than the hardware can send, the driver returns `EINVAL`.

When in [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) mode, one `struct lirc_scancode` must be written to the chardev at a time, else `EINVAL` is returned. Set the desired scancode in the `scancode` member, and the [IR protocol](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>) in the `rc_proto`: member. All other members must be set to 0, else `EINVAL` is returned. If there is no protocol encoder for the protocol or the scancode is not valid for the specified protocol, `EINVAL` is returned. The write function blocks until the scancode is transmitted by the hardware.

<a id="rst-return-value"></a>

## Return Value

On success, the number of bytes written is returned. It is not an error if this number is smaller than the number of bytes requested, or the amount of data required for one frame.  On error, -1 is returned, and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Currently, most analog and digital devices have a Infrared input for remote controllers. Each manufacturer has their own type of control. It is not rare for the same manufacturer to ship different types of controls, depending on the device.

<a id="rst-introduction"></a>
<a id="rst-remote-controllers-intro"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

Currently, most analog and digital devices have a Infrared input for remote controllers. Each manufacturer has their own type of control. It is not rare for the same manufacturer to ship different types of controls, depending on the device.

A Remote Controller interface is mapped as a normal evdev/input interface, just like a keyboard or a mouse. So, it uses all ioctls already defined for any other input devices.

However, remove controllers are more flexible than a normal input device, as the IR receiver (and/or transmitter) can be used in conjunction with a wide variety of different IR remotes.

In order to allow flexibility, the Remote Controller subsystem allows controlling the RC-specific attributes via [the sysfs class nodes](</kernel/userspace/userspace-api/media-rc/rc-sysfs-nodes.md#rst-remote-controllers-sysfs-nodes>).

---

# Remote Controller Protocols and Scancodes

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> IR is encoded as a series of pulses and spaces, using a protocol. These protocols can encode e.g. an address (which device should respond) and a command: what it should do. The values for these are not always consistent across different…

<a id="rst-remote-controller-protocols-and-scancodes"></a>
<a id="rst-remote-controllers-protocols"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

IR is encoded as a series of pulses and spaces, using a protocol. These protocols can encode e.g. an address (which device should respond) and a command: what it should do. The values for these are not always consistent across different devices for a given protocol.

Therefore out the output of the IR decoder is a scancode; a single u32 value. Using keymap tables this can be mapped to linux key codes.

Other things can be encoded too. Some IR protocols encode a toggle bit; this is to distinguish whether the same button is being held down, or has been released and pressed again. If has been released and pressed again, the toggle bit will invert from one IR message to the next.

Some remotes have a pointer-type device which can used to control the mouse; some air conditioning systems can have their target temperature target set in IR.

The following are the protocols the kernel knows about and also lists how scancodes are encoded for each protocol.

<a id="rst-rc-5-rc-proto-rc5"></a>

## rc-5 (RC_PROTO_RC5)

This IR protocol uses manchester encoding to encode 14 bits. There is a detailed description here [https://www.sbprojects.net/knowledge/ir/rc5.php](<https://www.sbprojects.net/knowledge/ir/rc5.php>).

The scancode encoding is *not* consistent with the lirc daemon (lircd) rc5 protocol, or the manchester BPF decoder.


<table>
<caption>rc5 bits scancode mapping</caption>
<tbody>
<tr>
<td>


rc-5 bit

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Start bit, always set

</td>
</tr>
<tr>
<td>


1

</td>
<td>


6 (inverted)

</td>
<td>


2nd start bit in rc5,  re-used as 6th command bit

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Toggle bit

</td>
</tr>
<tr>
<td>


5

</td>
<td>


8 to 13

</td>
<td>


Address

</td>
</tr>
<tr>
<td>


6

</td>
<td>


0 to 5

</td>
<td>


Command

</td>
</tr>
</tbody>
</table>

There is a variant of rc5 called either rc5x or extended rc5 where there the second stop bit is the 6th command bit, but inverted. This is done so it the scancodes and encoding is compatible with existing schemes. This bit is stored in bit 6 of the scancode, inverted. This is done to keep it compatible with plain rc-5 where there are two start bits.

<a id="rst-rc-5-sz-rc-proto-rc5-sz"></a>

## rc-5-sz (RC_PROTO_RC5_SZ)

This is much like rc-5 but one bit longer. The scancode is encoded differently.


<table>
<caption>rc-5-sz bits scancode mapping</caption>
<tbody>
<tr>
<td>


rc-5-sz bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Start bit, always set

</td>
</tr>
<tr>
<td>


1

</td>
<td>


13

</td>
<td>


Address bit

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Toggle bit

</td>
</tr>
<tr>
<td>


6

</td>
<td>


6 to 11

</td>
<td>


Address

</td>
</tr>
<tr>
<td>


6

</td>
<td>


0 to 5

</td>
<td>


Command

</td>
</tr>
</tbody>
</table>

<a id="rst-rc-5x-20-rc-proto-rc5x-20"></a>

## rc-5x-20 (RC_PROTO_RC5X_20)

This rc-5 extended to encoded 20 bits. The is a 3555 microseconds space after the 8th bit.


<table>
<caption>rc-5x-20 bits scancode mapping</caption>
<tbody>
<tr>
<td>


rc-5-sz bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Start bit, always set

</td>
</tr>
<tr>
<td>


1

</td>
<td>


14

</td>
<td>


Address bit

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Toggle bit

</td>
</tr>
<tr>
<td>


5

</td>
<td>


16 to 20

</td>
<td>


Address

</td>
</tr>
<tr>
<td>


6

</td>
<td>


8 to 13

</td>
<td>


Address

</td>
</tr>
<tr>
<td>


6

</td>
<td>


0 to 5

</td>
<td>


Command

</td>
</tr>
</tbody>
</table>

<a id="rst-jvc-rc-proto-jvc"></a>

## jvc (RC_PROTO_JVC)

The jvc protocol is much like nec, without the inverted values. It is described here [https://www.sbprojects.net/knowledge/ir/jvc.php](<https://www.sbprojects.net/knowledge/ir/jvc.php>).

The scancode is a 16 bits value, where the address is the lower 8 bits and the command the higher 8 bits; this is reversed from IR order.

<a id="rst-sony-12-rc-proto-sony12"></a>

## sony-12 (RC_PROTO_SONY12)

The sony protocol is a pulse-width encoding. There are three variants, which just differ in number of bits and scancode encoding.


<table>
<caption>sony-12 bits scancode mapping</caption>
<tbody>
<tr>
<td>


sony-12 bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


5

</td>
<td>


16 to 20

</td>
<td>


device

</td>
</tr>
<tr>
<td>


7

</td>
<td>


0 to 6

</td>
<td>


function

</td>
</tr>
</tbody>
</table>

<a id="rst-sony-15-rc-proto-sony15"></a>

## sony-15 (RC_PROTO_SONY15)

The sony protocol is a pulse-width encoding. There are three variants, which just differ in number of bits and scancode encoding.


<table>
<caption>sony-12 bits scancode mapping</caption>
<tbody>
<tr>
<td>


sony-12 bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


8

</td>
<td>


16 to 23

</td>
<td>


device

</td>
</tr>
<tr>
<td>


7

</td>
<td>


0 to 6

</td>
<td>


function

</td>
</tr>
</tbody>
</table>

<a id="rst-sony-20-rc-proto-sony20"></a>

## sony-20 (RC_PROTO_SONY20)

The sony protocol is a pulse-width encoding. There are three variants, which just differ in number of bits and scancode encoding.


<table>
<caption>sony-20 bits scancode mapping</caption>
<tbody>
<tr>
<td>


sony-20 bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


5

</td>
<td>


16 to 20

</td>
<td>


device

</td>
</tr>
<tr>
<td>


7

</td>
<td>


0 to 7

</td>
<td>


device

</td>
</tr>
<tr>
<td>


8

</td>
<td>


8 to 15

</td>
<td>


extended bits

</td>
</tr>
</tbody>
</table>

<a id="rst-nec-rc-proto-nec"></a>

## nec (RC_PROTO_NEC)

The nec protocol encodes an 8 bit address and an 8 bit command. It is described here [https://www.sbprojects.net/knowledge/ir/nec.php](<https://www.sbprojects.net/knowledge/ir/nec.php>). Note that the protocol sends least significant bit first.

As a check, the nec protocol sends the address and command twice; the second time it is inverted. This is done for verification.

A plain nec IR message has 16 bits; the high 8 bits are the address and the low 8 bits are the command.

<a id="rst-nec-x-rc-proto-necx"></a>

## nec-x (RC_PROTO_NECX)

Extended nec has a 16 bit address and a 8 bit command. This is encoded as a 24 bit value as you would expect, with the lower 8 bits the command and the upper 16 bits the address.

<a id="rst-nec-32-rc-proto-nec32"></a>

## nec-32 (RC_PROTO_NEC32)

nec-32 does not send an inverted address or an inverted command; the entire message, all 32 bits, are used.

For this to be decoded correctly, the second 8 bits must not be the inverted value of the first, and also the last 8 bits must not be the inverted value of the third 8 bit value.

The scancode has a somewhat unusual encoding.


<table>
<caption>nec-32 bits scancode mapping</caption>
<tbody>
<tr>
<td>


nec-32 bits

</td>
<td>


scancode bit

</td>
</tr>
<tr>
<td>


First 8 bits

</td>
<td>


16 to 23

</td>
</tr>
<tr>
<td>


Second 8 bits

</td>
<td>


24 to 31

</td>
</tr>
<tr>
<td>


Third 8 bits

</td>
<td>


0 to 7

</td>
</tr>
<tr>
<td>


Fourth 8 bits

</td>
<td>


8 to 15

</td>
</tr>
</tbody>
</table>

<a id="rst-sanyo-rc-proto-sanyo"></a>

## sanyo (RC_PROTO_SANYO)

The sanyo protocol is like the nec protocol, but with 13 bits address rather than 8 bits. Both the address and the command are followed by their inverted versions, but these are not present in the scancodes.

Bis 8 to 20 of the scancode is the 13 bits address, and the lower 8 bits are the command.

<a id="rst-mcir2-kbd-rc-proto-mcir2-kbd"></a>

## mcir2-kbd (RC_PROTO_MCIR2_KBD)

This protocol is generated by the Microsoft MCE keyboard for keyboard events. Refer to the ir-mce_kbd-decoder.c to see how it is encoded.

<a id="rst-mcir2-mse-rc-proto-mcir2-mse"></a>

## mcir2-mse (RC_PROTO_MCIR2_MSE)

This protocol is generated by the Microsoft MCE keyboard for pointer events. Refer to the ir-mce_kbd-decoder.c to see how it is encoded.

<a id="rst-rc-6-0-rc-proto-rc6-0"></a>

## rc-6-0 (RC_PROTO_RC6_0)

This is the rc-6 in mode 0. rc-6 is described here [https://www.sbprojects.net/knowledge/ir/rc6.php](<https://www.sbprojects.net/knowledge/ir/rc6.php>). The scancode is the exact 16 bits as in the protocol. There is also a toggle bit.

<a id="rst-rc-6-6a-20-rc-proto-rc6-6a-20"></a>

## rc-6-6a-20 (RC_PROTO_RC6_6A_20)

This is the rc-6 in mode 6a, 20 bits. rc-6 is described here [https://www.sbprojects.net/knowledge/ir/rc6.php](<https://www.sbprojects.net/knowledge/ir/rc6.php>). The scancode is the exact 20 bits as in the protocol. There is also a toggle bit.

<a id="rst-rc-6-6a-24-rc-proto-rc6-6a-24"></a>

## rc-6-6a-24 (RC_PROTO_RC6_6A_24)

This is the rc-6 in mode 6a, 24 bits. rc-6 is described here [https://www.sbprojects.net/knowledge/ir/rc6.php](<https://www.sbprojects.net/knowledge/ir/rc6.php>). The scancode is the exact 24 bits as in the protocol. There is also a toggle bit.

<a id="rst-rc-6-6a-32-rc-proto-rc6-6a-32"></a>

## rc-6-6a-32 (RC_PROTO_RC6_6A_32)

This is the rc-6 in mode 6a, 32 bits. rc-6 is described here [https://www.sbprojects.net/knowledge/ir/rc6.php](<https://www.sbprojects.net/knowledge/ir/rc6.php>). The upper 16 bits are the vendor, and the lower 16 bits are the vendor-specific bits. This protocol is for the non-Microsoft MCE variant (vendor \!= 0x800f).

<a id="rst-rc-6-mce-rc-proto-rc6-mce"></a>

## rc-6-mce (RC_PROTO_RC6_MCE)

This is the rc-6 in mode 6a, 32 bits. The upper 16 bits are the vendor, and the lower 16 bits are the vendor-specific bits. This protocol is for the Microsoft MCE variant (vendor = 0x800f). The toggle bit in the protocol itself is ignored, and the 16th bit should be takes as the toggle bit.

<a id="rst-sharp-rc-proto-sharp"></a>

## sharp (RC_PROTO_SHARP)

This is a protocol used by Sharp VCRs, is described here [https://www.sbprojects.net/knowledge/ir/sharp.php](<https://www.sbprojects.net/knowledge/ir/sharp.php>). There is a very long (40ms) space between the normal and inverted values, and some IR receivers cannot decode this.

There is a 5 bit address and a 8 bit command. In the scancode the address is in bits 8 to 12, and the command in bits 0 to 7.

<a id="rst-xmp-rc-proto-xmp"></a>

## xmp (RC_PROTO_XMP)

This protocol has several versions and only version 1 is supported. Refer to the decoder (ir-xmp-decoder.c) to see how it is encoded.

<a id="rst-cec-rc-proto-cec"></a>

## cec (RC_PROTO_CEC)

This is not an IR protocol, this is a protocol over CEC. The CEC infrastructure uses rc-core for handling CEC commands, so that they can easily be remapped.

<a id="rst-imon-rc-proto-imon"></a>

## imon (RC_PROTO_IMON)

This protocol is used by Antec Veris/SoundGraph iMON remotes.

The protocol describes both button presses and pointer movements. The protocol encodes 31 bits, and the scancode is simply the 31 bits with the top bit always 0.

<a id="rst-rc-mm-12-rc-proto-rcmm12"></a>

## rc-mm-12 (RC_PROTO_RCMM12)

The rc-mm protocol is described here [https://www.sbprojects.net/knowledge/ir/rcmm.php](<https://www.sbprojects.net/knowledge/ir/rcmm.php>). The scancode is simply the 12 bits.

<a id="rst-rc-mm-24-rc-proto-rcmm24"></a>

## rc-mm-24 (RC_PROTO_RCMM24)

The rc-mm protocol is described here [https://www.sbprojects.net/knowledge/ir/rcmm.php](<https://www.sbprojects.net/knowledge/ir/rcmm.php>). The scancode is simply the 24 bits.

<a id="rst-rc-mm-32-rc-proto-rcmm32"></a>

## rc-mm-32 (RC_PROTO_RCMM32)

The rc-mm protocol is described here [https://www.sbprojects.net/knowledge/ir/rcmm.php](<https://www.sbprojects.net/knowledge/ir/rcmm.php>). The scancode is simply the 32 bits.

<a id="rst-xbox-dvd-rc-proto-xbox-dvd"></a>

## xbox-dvd (RC_PROTO_XBOX_DVD)

This protocol is used by Xbox DVD Remote, which was made for the original Xbox. There is no in-kernel decoder or encoder for this protocol. The usb device decodes the protocol. There is a BPF decoder available in v4l-utils.

---

# Remote Controller's sysfs nodes

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> As defined at Documentation/ABI/testing/sysfs-class-rc, those are the sysfs nodes that control the Remote Controllers:

<a id="rst-remote-controller-s-sysfs-nodes"></a>
<a id="rst-remote-controllers-sysfs-nodes"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

As defined at Documentation/ABI/testing/sysfs-class-rc, those are the sysfs nodes that control the Remote Controllers:

<a id="rst-sys-class-rc-1"></a>
<a id="rst-sys-class-rc"></a>

## /sys/class/rc/

The `/sys/class/rc/` class sub-directory belongs to the Remote Controller core and provides a sysfs interface for configuring infrared remote controller receivers.

<a id="rst-sys-class-rc-rcn-1"></a>
<a id="rst-sys-class-rc-rcn"></a>

## /sys/class/rc/rcN/

A `/sys/class/rc/rcN` directory is created for each remote control receiver device where N is the number of the receiver.

<a id="rst-sys-class-rc-rcn-protocols-1"></a>
<a id="rst-sys-class-rc-rcn-protocols"></a>

## /sys/class/rc/rcN/protocols

Reading this file returns a list of available protocols, something like:



```text
rc5 [rc6] nec jvc [sony]
```

Enabled protocols are shown in \[\] brackets.

Writing "+proto" will add a protocol to the list of enabled protocols.

Writing "-proto" will remove a protocol from the list of enabled protocols.

Writing "proto" will enable only "proto".

Writing "none" will disable all protocols.

Write fails with `EINVAL` if an invalid protocol combination or unknown protocol name is used.

<a id="rst-sys-class-rc-rcn-filter-1"></a>
<a id="rst-sys-class-rc-rcn-filter"></a>

## /sys/class/rc/rcN/filter

Sets the scancode filter expected value.

Use in combination with `/sys/class/rc/rcN/filter_mask` to set the expected value of the bits set in the filter mask. If the hardware supports it then scancodes which do not match the filter will be ignored. Otherwise the write will fail with an error.

This value may be reset to 0 if the current protocol is altered.

<a id="rst-sys-class-rc-rcn-filter-mask-1"></a>
<a id="rst-sys-class-rc-rcn-filter-mask"></a>

## /sys/class/rc/rcN/filter_mask

Sets the scancode filter mask of bits to compare. Use in combination with `/sys/class/rc/rcN/filter` to set the bits of the scancode which should be compared against the expected value. A value of 0 disables the filter to allow all valid scancodes to be processed.

If the hardware supports it then scancodes which do not match the filter will be ignored. Otherwise the write will fail with an error.

This value may be reset to 0 if the current protocol is altered.

<a id="rst-sys-class-rc-rcn-wakeup-protocols-1"></a>
<a id="rst-sys-class-rc-rcn-wakeup-protocols"></a>

## /sys/class/rc/rcN/wakeup_protocols

Reading this file returns a list of available protocols to use for the wakeup filter, something like:



```text
rc-5 nec nec-x rc-6-0 rc-6-6a-24 [rc-6-6a-32] rc-6-mce
```

Note that protocol variants are listed, so `nec`, `sony`, `rc-5`, `rc-6` have their different bit length encodings listed if available.

Note that all protocol variants are listed.

The enabled wakeup protocol is shown in \[\] brackets.

Only one protocol can be selected at a time.

Writing "proto" will use "proto" for wakeup events.

Writing "none" will disable wakeup.

Write fails with `EINVAL` if an invalid protocol combination or unknown protocol name is used, or if wakeup is not supported by the hardware.

<a id="rst-sys-class-rc-rcn-wakeup-filter-1"></a>
<a id="rst-sys-class-rc-rcn-wakeup-filter"></a>

## /sys/class/rc/rcN/wakeup_filter

Sets the scancode wakeup filter expected value. Use in combination with `/sys/class/rc/rcN/wakeup_filter_mask` to set the expected value of the bits set in the wakeup filter mask to trigger a system wake event.

If the hardware supports it and wakeup_filter_mask is not 0 then scancodes which match the filter will wake the system from e.g. suspend to RAM or power off. Otherwise the write will fail with an error.

This value may be reset to 0 if the wakeup protocol is altered.

<a id="rst-sys-class-rc-rcn-wakeup-filter-mask-1"></a>
<a id="rst-sys-class-rc-rcn-wakeup-filter-mask"></a>

## /sys/class/rc/rcN/wakeup_filter_mask

Sets the scancode wakeup filter mask of bits to compare. Use in combination with `/sys/class/rc/rcN/wakeup_filter` to set the bits of the scancode which should be compared against the expected value to trigger a system wake event.

If the hardware supports it and wakeup_filter_mask is not 0 then scancodes which match the filter will wake the system from e.g. suspend to RAM or power off. Otherwise the write will fail with an error.

This value may be reset to 0 if the wakeup protocol is altered.

---

# Changing default Remote Controller mappings

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> The event interface provides two ioctls to be used against the /dev/input/event device, to allow changing the default keymapping.

<a id="rst-changing-default-remote-controller-mappings"></a>
<a id="rst-remote-controllers-table-change"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

The event interface provides two ioctls to be used against the /dev/input/event device, to allow changing the default keymapping.

This program demonstrates how to replace the keymap tables.

- [file: uapi/v4l/keytable.c](</kernel/userspace/userspace-api/media-rc/keytable-c.md>)

---

# Remote controller tables

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Unfortunately, for several years, there was no effort to create uniform IR keycodes for different devices. This caused the same IR keyname to be mapped completely differently on different IR devices. This resulted that the same IR keyname…

<a id="rst-remote-controller-tables"></a>
<a id="rst-remote-controllers-tables"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

Unfortunately, for several years, there was no effort to create uniform IR keycodes for different devices. This caused the same IR keyname to be mapped completely differently on different IR devices. This resulted that the same IR keyname to be mapped completely different on different IR's. Due to that, V4L2 API now specifies a standard for mapping Media keys on IR.

This standard should be used by both V4L/DVB drivers and userspace applications

The modules register the remote as keyboard within the linux input layer. This means that the IR key strokes will look like normal keyboard key strokes (if CONFIG\_INPUT\_KEYBOARD is enabled). Using the event devices (CONFIG\_INPUT\_EVDEV) it is possible for applications to access the remote via /dev/input/event devices.

<a id="rst-rc-standard-keymap"></a>



<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>

IR default keymapping

</caption>
<tbody>
<tr>
<td>



Key code

</td>
<td>



Meaning

</td>
<td>



Key examples on IR

</td>
</tr>
<tr>
<td colspan="3">



<strong>Numeric keys</strong>

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_0`

</td>
<td>



Keyboard digit 0

</td>
<td>



0

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_1`

</td>
<td>



Keyboard digit 1

</td>
<td>



1

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_2`

</td>
<td>



Keyboard digit 2

</td>
<td>



2

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_3`

</td>
<td>



Keyboard digit 3

</td>
<td>



3

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_4`

</td>
<td>



Keyboard digit 4

</td>
<td>



4

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_5`

</td>
<td>



Keyboard digit 5

</td>
<td>



5

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_6`

</td>
<td>



Keyboard digit 6

</td>
<td>



6

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_7`

</td>
<td>



Keyboard digit 7

</td>
<td>



7

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_8`

</td>
<td>



Keyboard digit 8

</td>
<td>



8

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_9`

</td>
<td>



Keyboard digit 9

</td>
<td>



9

</td>
</tr>
<tr>
<td colspan="3">



<strong>Movie play control</strong>

</td>
</tr>
<tr>
<td>



`KEY_FORWARD`

</td>
<td>



Instantly advance in time

</td>
<td>



&gt;&gt; / FORWARD

</td>
</tr>
<tr>
<td>



`KEY_BACK`

</td>
<td>



Instantly go back in time

</td>
<td>



&lt;&lt;&lt; / BACK

</td>
</tr>
<tr>
<td>



`KEY_FASTFORWARD`

</td>
<td>



Play movie faster

</td>
<td>



```pycon
>>> / FORWARD
```

</td>
</tr>
<tr>
<td>



`KEY_REWIND`

</td>
<td>



Play movie back

</td>
<td>



REWIND / BACKWARD

</td>
</tr>
<tr>
<td>



`KEY_NEXT`

</td>
<td>



Select next chapter / sub-chapter / interval

</td>
<td>



NEXT / SKIP

</td>
</tr>
<tr>
<td>



`KEY_PREVIOUS`

</td>
<td>



Select previous chapter / sub-chapter / interval

</td>
<td>



&lt;&lt; / PREV / PREVIOUS

</td>
</tr>
<tr>
<td>



`KEY_AGAIN`

</td>
<td>



Repeat the video or a video interval

</td>
<td>



REPEAT / LOOP / RECALL

</td>
</tr>
<tr>
<td>



`KEY_PAUSE`

</td>
<td>



Pause stream

</td>
<td>



PAUSE / FREEZE

</td>
</tr>
<tr>
<td>



`KEY_PLAY`

</td>
<td>



Play movie at the normal timeshift

</td>
<td>



NORMAL TIMESHIFT / LIVE / &gt;

</td>
</tr>
<tr>
<td>



`KEY_PLAYPAUSE`

</td>
<td>



Alternate between play and pause

</td>
<td>



PLAY / PAUSE

</td>
</tr>
<tr>
<td>



`KEY_STOP`

</td>
<td>



Stop stream

</td>
<td>



STOP

</td>
</tr>
<tr>
<td>



`KEY_RECORD`

</td>
<td>



Start/stop recording stream

</td>
<td>



CAPTURE / REC / RECORD/PAUSE

</td>
</tr>
<tr>
<td>



`KEY_CAMERA`

</td>
<td>



Take a picture of the image

</td>
<td>



CAMERA ICON / CAPTURE / SNAPSHOT

</td>
</tr>
<tr>
<td>



`KEY_SHUFFLE`

</td>
<td>



Enable shuffle mode

</td>
<td>



SHUFFLE

</td>
</tr>
<tr>
<td>



`KEY_TIME`

</td>
<td>



Activate time shift mode

</td>
<td>



TIME SHIFT

</td>
</tr>
<tr>
<td>



`KEY_TITLE`

</td>
<td>



Allow changing the chapter

</td>
<td>



CHAPTER

</td>
</tr>
<tr>
<td>



`KEY_SUBTITLE`

</td>
<td>



Allow changing the subtitle

</td>
<td>



SUBTITLE

</td>
</tr>
<tr>
<td colspan="3">



<strong>Image control</strong>

</td>
</tr>
<tr>
<td>



`KEY_BRIGHTNESSDOWN`

</td>
<td>



Decrease Brightness

</td>
<td>



BRIGHTNESS DECREASE

</td>
</tr>
<tr>
<td>



`KEY_BRIGHTNESSUP`

</td>
<td>



Increase Brightness

</td>
<td>



BRIGHTNESS INCREASE

</td>
</tr>
<tr>
<td>



`KEY_ANGLE`

</td>
<td>



Switch video camera angle (on videos with more than one angle stored)

</td>
<td>



ANGLE / SWAP

</td>
</tr>
<tr>
<td>



`KEY_EPG`

</td>
<td>



Open the Elecrowonic Play Guide (EPG)

</td>
<td>



EPG / GUIDE

</td>
</tr>
<tr>
<td>



`KEY_TEXT`

</td>
<td>



Activate/change closed caption mode

</td>
<td>



CLOSED CAPTION/TELETEXT / DVD TEXT / TELETEXT / TTX

</td>
</tr>
<tr>
<td colspan="3">



<strong>Audio control</strong>

</td>
</tr>
<tr>
<td>



`KEY_AUDIO`

</td>
<td>



Change audio source

</td>
<td>



AUDIO SOURCE / AUDIO / MUSIC

</td>
</tr>
<tr>
<td>



`KEY_MUTE`

</td>
<td>



Mute/unmute audio

</td>
<td>



MUTE / DEMUTE / UNMUTE

</td>
</tr>
<tr>
<td>



`KEY_VOLUMEDOWN`

</td>
<td>



Decrease volume

</td>
<td>



VOLUME- / VOLUME DOWN

</td>
</tr>
<tr>
<td>



`KEY_VOLUMEUP`

</td>
<td>



Increase volume

</td>
<td>



VOLUME+ / VOLUME UP

</td>
</tr>
<tr>
<td>



`KEY_MODE`

</td>
<td>



Change sound mode

</td>
<td>



MONO/STEREO

</td>
</tr>
<tr>
<td>



`KEY_LANGUAGE`

</td>
<td>



Select Language

</td>
<td>



1ST / 2ND LANGUAGE / DVD LANG / MTS/SAP / MTS SEL

</td>
</tr>
<tr>
<td colspan="3">



<strong>Channel control</strong>

</td>
</tr>
<tr>
<td>



`KEY_CHANNEL`

</td>
<td>



Go to the next favorite channel

</td>
<td>



ALT / CHANNEL / CH SURFING / SURF / FAV

</td>
</tr>
<tr>
<td>



`KEY_CHANNELDOWN`

</td>
<td>



Decrease channel sequentially

</td>
<td>



CHANNEL - / CHANNEL DOWN / DOWN

</td>
</tr>
<tr>
<td>



`KEY_CHANNELUP`

</td>
<td>



Increase channel sequentially

</td>
<td>



CHANNEL + / CHANNEL UP / UP

</td>
</tr>
<tr>
<td>



`KEY_DIGITS`

</td>
<td>



Use more than one digit for channel

</td>
<td>



PLUS / 100/ 1xx / xxx / -/-- / Single Double Triple Digit

</td>
</tr>
<tr>
<td>



`KEY_SEARCH`

</td>
<td>



Start channel autoscan

</td>
<td>



SCAN / AUTOSCAN

</td>
</tr>
<tr>
<td colspan="3">



<strong>Colored keys</strong>

</td>
</tr>
<tr>
<td>



`KEY_BLUE`

</td>
<td>



IR Blue key

</td>
<td>



BLUE

</td>
</tr>
<tr>
<td>



`KEY_GREEN`

</td>
<td>



IR Green Key

</td>
<td>



GREEN

</td>
</tr>
<tr>
<td>



`KEY_RED`

</td>
<td>



IR Red key

</td>
<td>



RED

</td>
</tr>
<tr>
<td>



`KEY_YELLOW`

</td>
<td>



IR Yellow key

</td>
<td>



YELLOW

</td>
</tr>
<tr>
<td colspan="3">



<strong>Media selection</strong>

</td>
</tr>
<tr>
<td>



`KEY_CD`

</td>
<td>



Change input source to Compact Disc

</td>
<td>



CD

</td>
</tr>
<tr>
<td>



`KEY_DVD`

</td>
<td>



Change input to DVD

</td>
<td>



DVD / DVD MENU

</td>
</tr>
<tr>
<td>



`KEY_EJECTCLOSECD`

</td>
<td>



Open/close the CD/DVD player

</td>
<td>



-&gt; ) / CLOSE / OPEN

</td>
</tr>
<tr>
<td>



`KEY_MEDIA`

</td>
<td>



Turn on/off Media application

</td>
<td>



PC/TV / TURN ON/OFF APP

</td>
</tr>
<tr>
<td>



`KEY_PC`

</td>
<td>



Selects from TV to PC

</td>
<td>



PC

</td>
</tr>
<tr>
<td>



`KEY_RADIO`

</td>
<td>



Put into AM/FM radio mode

</td>
<td>



RADIO / TV/FM / TV/RADIO / FM / FM/RADIO

</td>
</tr>
<tr>
<td>



`KEY_TV`

</td>
<td>



Select tv mode

</td>
<td>



TV / LIVE TV

</td>
</tr>
<tr>
<td>



`KEY_TV2`

</td>
<td>



Select Cable mode

</td>
<td>



AIR/CBL

</td>
</tr>
<tr>
<td>



`KEY_VCR`

</td>
<td>



Select VCR mode

</td>
<td>



VCR MODE / DTR

</td>
</tr>
<tr>
<td>



`KEY_VIDEO`

</td>
<td>



Alternate between input modes

</td>
<td>



SOURCE / SELECT / DISPLAY / SWITCH INPUTS / VIDEO

</td>
</tr>
<tr>
<td colspan="3">



<strong>Power control</strong>

</td>
</tr>
<tr>
<td>



`KEY_POWER`

</td>
<td>



Turn on/off computer

</td>
<td>



SYSTEM POWER / COMPUTER POWER

</td>
</tr>
<tr>
<td>



`KEY_POWER2`

</td>
<td>



Turn on/off application

</td>
<td>



TV ON/OFF / POWER

</td>
</tr>
<tr>
<td>



`KEY_SLEEP`

</td>
<td>



Activate sleep timer

</td>
<td>



SLEEP / SLEEP TIMER

</td>
</tr>
<tr>
<td>



`KEY_SUSPEND`

</td>
<td>



Put computer into suspend mode

</td>
<td>



STANDBY / SUSPEND

</td>
</tr>
<tr>
<td colspan="3">



<strong>Window control</strong>

</td>
</tr>
<tr>
<td>



`KEY_CLEAR`

</td>
<td>



Stop stream and return to default input video/audio

</td>
<td>



CLEAR / RESET / BOSS KEY

</td>
</tr>
<tr>
<td>



`KEY_CYCLEWINDOWS`

</td>
<td>



Minimize windows and move to the next one

</td>
<td>



ALT-TAB / MINIMIZE / DESKTOP

</td>
</tr>
<tr>
<td>



`KEY_FAVORITES`

</td>
<td>



Open the favorites stream window

</td>
<td>



TV WALL / Favorites

</td>
</tr>
<tr>
<td>



`KEY_MENU`

</td>
<td>



Call application menu

</td>
<td>



2ND CONTROLS (USA: MENU) / DVD/MENU / SHOW/HIDE CTRL

</td>
</tr>
<tr>
<td>



`KEY_NEW`

</td>
<td>



Open/Close Picture in Picture

</td>
<td>



PIP

</td>
</tr>
<tr>
<td>



`KEY_OK`

</td>
<td>



Send a confirmation code to application

</td>
<td>



OK / ENTER / RETURN

</td>
</tr>
<tr>
<td>



`KEY_ASPECT_RATIO`

</td>
<td>



Select screen aspect ratio

</td>
<td>



4:3 16:9 SELECT

</td>
</tr>
<tr>
<td>



`KEY_FULL_SCREEN`

</td>
<td>



Put device into zoom/full screen mode

</td>
<td>



ZOOM / FULL SCREEN / ZOOM+ / HIDE PANEL / SWITCH

</td>
</tr>
<tr>
<td colspan="3">



<strong>Navigation keys</strong>

</td>
</tr>
<tr>
<td>



`KEY_ESC`

</td>
<td>



Cancel current operation

</td>
<td>



CANCEL / BACK

</td>
</tr>
<tr>
<td>



`KEY_HELP`

</td>
<td>



Open a Help window

</td>
<td>



HELP

</td>
</tr>
<tr>
<td>



`KEY_HOMEPAGE`

</td>
<td>



Navigate to Homepage

</td>
<td>



HOME

</td>
</tr>
<tr>
<td>



`KEY_INFO`

</td>
<td>



Open On Screen Display

</td>
<td>



DISPLAY INFORMATION / OSD

</td>
</tr>
<tr>
<td>



`KEY_WWW`

</td>
<td>



Open the default browser

</td>
<td>



WEB

</td>
</tr>
<tr>
<td>



`KEY_UP`

</td>
<td>



Up key

</td>
<td>



UP

</td>
</tr>
<tr>
<td>



`KEY_DOWN`

</td>
<td>



Down key

</td>
<td>



DOWN

</td>
</tr>
<tr>
<td>



`KEY_LEFT`

</td>
<td>



Left key

</td>
<td>



LEFT

</td>
</tr>
<tr>
<td>



`KEY_RIGHT`

</td>
<td>



Right key

</td>
<td>



RIGHT

</td>
</tr>
<tr>
<td colspan="3">



<strong>Miscellaneous keys</strong>

</td>
</tr>
<tr>
<td>



`KEY_DOT`

</td>
<td>



Return a dot

</td>
<td>



.

</td>
</tr>
<tr>
<td>



`KEY_FN`

</td>
<td>



Select a function

</td>
<td>



FUNCTION

</td>
</tr>
</tbody>
</table>

It should be noted that, sometimes, there some fundamental missing keys at some cheaper IR's. Due to that, it is recommended to:

<a id="rst-rc-keymap-notes"></a>


<table>
<caption>

Notes

</caption>
<tbody>
<tr>
<td>



On simpler IR's, without separate channel keys, you need to map UP as `KEY_CHANNELUP`

</td>
</tr>
<tr>
<td>



On simpler IR's, without separate channel keys, you need to map DOWN as `KEY_CHANNELDOWN`

</td>
</tr>
<tr>
<td>



On simpler IR's, without separate volume keys, you need to map LEFT as `KEY_VOLUMEDOWN`

</td>
</tr>
<tr>
<td>



On simpler IR's, without separate volume keys, you need to map RIGHT as `KEY_VOLUMEUP`

</td>
</tr>
</tbody>
</table>

---

# Part III - Remote Controller API

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Authors:

<a id="rst-part-iii-remote-controller-api"></a>
<a id="rst-remote-controllers"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

**Table of Contents**

1. [Introduction](</kernel/userspace/userspace-api/media-rc/rc-intro.md>)
2. [Remote Controller's sysfs nodes](</kernel/userspace/userspace-api/media-rc/rc-sysfs-nodes.md>)
3. [Remote Controller Protocols and Scancodes](</kernel/userspace/userspace-api/media-rc/rc-protos.md>)
4. [Remote controller tables](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/rc/rc-tables.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
5. [Changing default Remote Controller mappings](</kernel/userspace/userspace-api/media-rc/rc-table-change.md>)
6. [LIRC Device Interface](</kernel/userspace/userspace-api/media-rc/lirc-dev.md>)

<a id="rst-revision-and-copyright"></a>

## Revision and Copyright

Authors:

- Carvalho Chehab, Mauro &lt;[mchehab@kernel.org](<mailto:mchehab@kernel.org>)&gt;

> - Initial version.

**Copyright** © 2009-2016 : Mauro Carvalho Chehab

<a id="rst-revision-history"></a>

## Revision History

**revision:** 3.15 / 2014-02-06 (*mcc*)

Added the interface description and the RC sysfs class description.

**revision:** 1.0 / 2009-09-06 (*mcc*)

Initial revision

---

# Application Priority

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> When multiple applications share a device it may be desirable to assign them different priorities. Contrary to the traditional "rm -rf /" school of thought, a video recording application could for example block other applications from…

<a id="rst-application-priority"></a>
<a id="rst-app-pri"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

When multiple applications share a device it may be desirable to assign them different priorities. Contrary to the traditional "rm -rf /" school of thought, a video recording application could for example block other applications from changing video controls or switching the current TV channel. Another objective is to permit low priority applications working in background, which can be preempted by user controlled applications and automatically regain control of the device at a later time.

Since these features cannot be implemented entirely in user space V4L2 defines the [VIDIOC_G_PRIORITY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#rst-vidioc-g-priority>) and [VIDIOC_S_PRIORITY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#rst-vidioc-g-priority>) ioctls to request and query the access priority associate with a file descriptor. Opening a device assigns a medium priority, compatible with earlier versions of V4L2 and drivers not supporting these ioctls. Applications requiring a different priority will usually call [VIDIOC_S_PRIORITY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#rst-vidioc-g-priority>) after verifying the device with the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl.

Ioctls changing driver properties, such as [VIDIOC_S_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input>), return an `EBUSY` error code after another application obtained higher priority.

---

# Audio Inputs and Outputs

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Audio inputs and outputs are physical connectors of a device. Video capture devices have inputs, output devices have outputs, zero or more each. Radio devices have no audio inputs or outputs. They have exactly one tuner which in fact is an…

<a id="rst-audio-inputs-and-outputs"></a>
<a id="rst-audio"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Audio inputs and outputs are physical connectors of a device. Video capture devices have inputs, output devices have outputs, zero or more each. Radio devices have no audio inputs or outputs. They have exactly one tuner which in fact *is* an audio source, but this API associates tuners with video inputs or outputs only, and radio devices have none of these. <a id="rst-footnote-reference-1"></a>[1](#rst-f1) A connector on a TV card to loop back the received audio signal to a sound card is not considered an audio output.

Audio and video inputs and outputs are associated. Selecting a video source also selects an audio source. This is most evident when the video and audio source is a tuner. Further audio connectors can combine with more than one video input or output. Assumed two composite video inputs and two audio inputs exist, there may be up to four valid combinations. The relation of video and audio connectors is defined in the `audioset` field of the respective struct `v4l2_input` or struct `v4l2_output`, where each bit represents the index number, starting at zero, of one audio input or output.

To learn about the number and attributes of the available inputs and outputs applications can enumerate them with the [ioctl VIDIOC_ENUMAUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudio.md#rst-vidioc-enumaudio>) and [VIDIOC_ENUMAUDOUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudioout.md#rst-vidioc-enumaudout>) ioctl, respectively. The struct `v4l2_audio` returned by the [ioctl VIDIOC_ENUMAUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudio.md#rst-vidioc-enumaudio>) ioctl also contains signal status information applicable when the current audio input is queried.

The [VIDIOC_G_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) and [VIDIOC_G_AUDOUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audioout.md#rst-vidioc-g-audout>) ioctls report the current audio input and output, respectively.

> [!NOTE]
>
> Note that, unlike [VIDIOC_G_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input>) and [VIDIOC_G_OUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-output.md#rst-vidioc-g-output>) these ioctls return a structure as [ioctl VIDIOC_ENUMAUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudio.md#rst-vidioc-enumaudio>) and [VIDIOC_ENUMAUDOUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudioout.md#rst-vidioc-enumaudout>) do, not just an index.

To select an audio input and change its properties applications call the [VIDIOC_S_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) ioctl. To select an audio output (which presently has no changeable properties) applications call the [VIDIOC_S_AUDOUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audioout.md#rst-vidioc-g-audout>) ioctl.

Drivers must implement all audio input ioctls when the device has multiple selectable audio inputs, all audio output ioctls when the device has multiple selectable audio outputs. When the device has any audio inputs or outputs the driver must set the `V4L2_CAP_AUDIO` flag in the struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl.

<a id="rst-example-information-about-the-current-audio-input"></a>

## Example: Information about the current audio input



```c
struct v4l2_audio audio;

memset(&audio, 0, sizeof(audio));

if (-1 == ioctl(fd, VIDIOC_G_AUDIO, &audio)) {
    perror("VIDIOC_G_AUDIO");
    exit(EXIT_FAILURE);
}

printf("Current input: %s\\n", audio.name);
```

<a id="rst-example-switching-to-the-first-audio-input"></a>

## Example: Switching to the first audio input



```c
struct v4l2_audio audio;

memset(&audio, 0, sizeof(audio)); /* clear audio.mode, audio.reserved */

audio.index = 0;

if (-1 == ioctl(fd, VIDIOC_S_AUDIO, &audio)) {
    perror("VIDIOC_S_AUDIO");
    exit(EXIT_FAILURE);
}
```

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



**[1]** Actually struct `v4l2_audio` ought to have a `tuner` field like struct `v4l2_input`, not only making the API more consistent but also permitting radio devices with multiple tuners.

---

# References

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Duplicate implicit target name: "jfif".

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

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-cea-608-e"></a>
<a id="rst-cea608"></a>

## CEA 608-E

**title:** CEA-608-E R-2014 "Line 21 Data Services"

**author:** Consumer Electronics Association ([http://www.ce.org](<http://www.ce.org>))

<a id="rst-en-300-294"></a>
<a id="rst-en300294"></a>

## EN 300 294

**title:** EN 300 294 "625-line television Wide Screen Signalling (WSS)"

**author:** European Telecommunication Standards Institute ([http://www.etsi.org](<http://www.etsi.org>))

<a id="rst-ets-300-231"></a>
<a id="rst-ets300231"></a>

## ETS 300 231

**title:** ETS 300 231 "Specification of the domestic video Programme Delivery Control system (PDC)"

**author:** European Telecommunication Standards Institute ([http://www.etsi.org](<http://www.etsi.org>))

<a id="rst-ets-300-706"></a>
<a id="rst-ets300706"></a>

## ETS 300 706

**title:** ETS 300 706 "Enhanced Teletext specification"

**author:** European Telecommunication Standards Institute ([http://www.etsi.org](<http://www.etsi.org>))

<a id="rst-iso-13818-1"></a>
<a id="rst-mpeg2part1"></a>

## ISO 13818-1

**title:** ITU-T Rec. H.222.0 \| ISO/IEC 13818-1 "Information technology --- Generic coding of moving pictures and associated audio information: Systems"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>)), International Organisation for Standardisation ([http://www.iso.ch](<http://www.iso.ch>))

<a id="rst-iso-13818-2"></a>
<a id="rst-mpeg2part2"></a>

## ISO 13818-2

**title:** ITU-T Rec. H.262 \| ISO/IEC 13818-2 "Information technology --- Generic coding of moving pictures and associated audio information: Video"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>)), International Organisation for Standardisation ([http://www.iso.ch](<http://www.iso.ch>))

<a id="rst-itu-bt-470"></a>
<a id="rst-itu470"></a>

## ITU BT.470

**title:** ITU-R Recommendation BT.470-6 "Conventional Television Systems"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>))

<a id="rst-itu-bt-601"></a>
<a id="rst-itu601"></a>

## ITU BT.601

**title:** ITU-R Recommendation BT.601-5 "Studio Encoding Parameters of Digital Television for Standard 4:3 and Wide-Screen 16:9 Aspect Ratios"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>))

<a id="rst-itu-bt-653"></a>
<a id="rst-itu653"></a>

## ITU BT.653

**title:** ITU-R Recommendation BT.653-3 "Teletext systems"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>))

<a id="rst-itu-bt-709"></a>
<a id="rst-itu709"></a>

## ITU BT.709

**title:** ITU-R Recommendation BT.709-5 "Parameter values for the HDTV standards for production and international programme exchange"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>))

<a id="rst-itu-bt-1119"></a>
<a id="rst-itu1119"></a>

## ITU BT.1119

**title:** ITU-R Recommendation BT.1119 "625-line television Wide Screen Signalling (WSS)"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>))

<a id="rst-itu-t-rec-h-264-specification-04-2017-edition"></a>
<a id="rst-h264"></a>

## ITU-T Rec. H.264 Specification (04/2017 Edition)

**title:** ITU-T Recommendation H.264 "Advanced Video Coding for Generic Audiovisual Services"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>))

<a id="rst-itu-h-265-hevc"></a>
<a id="rst-hevc"></a>

## ITU H.265/HEVC

**title:** ITU-T Rec. H.265 \| ISO/IEC 23008-2 "High Efficiency Video Coding"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>)), International Organisation for Standardisation ([http://www.iso.ch](<http://www.iso.ch>))

<a id="rst-jfif-1"></a>
<a id="rst-jfif"></a>

## JFIF

**title:** JPEG File Interchange Format

**subtitle:** Version 1.02

**author:** Independent JPEG Group ([http://www.ijg.org](<http://www.ijg.org>))

<a id="rst-itu-t-81"></a>
<a id="rst-itu-t81"></a>

## ITU-T.81

**title:** ITU-T Recommendation T.81 "Information Technology --- Digital Compression and Coding of Continuous-Tone Still Images --- Requirements and Guidelines"

**author:** International Telecommunication Union ([http://www.itu.int](<http://www.itu.int>))

<a id="rst-w3c-jpeg-jfif-1"></a>
<a id="rst-w3c-jpeg-jfif"></a>

## W3C JPEG JFIF

**title:** JPEG JFIF

**author:** The World Wide Web Consortium ([http://www.w3.org](<http://www.w3.org>))

<a id="rst-smpte-12m"></a>
<a id="rst-smpte12m"></a>

## SMPTE 12M

**title:** SMPTE 12M-1999 "Television, Audio and Film - Time and Control Code"

**author:** Society of Motion Picture and Television Engineers ([http://www.smpte.org](<http://www.smpte.org>))

<a id="rst-smpte-170m"></a>
<a id="rst-smpte170m"></a>

## SMPTE 170M

**title:** SMPTE 170M-1999 "Television - Composite Analog Video Signal - NTSC for Studio Applications"

**author:** Society of Motion Picture and Television Engineers ([http://www.smpte.org](<http://www.smpte.org>))

<a id="rst-smpte-240m"></a>
<a id="rst-smpte240m"></a>

## SMPTE 240M

**title:** SMPTE 240M-1999 "Television - Signal Parameters - 1125-Line High-Definition Production"

**author:** Society of Motion Picture and Television Engineers ([http://www.smpte.org](<http://www.smpte.org>))

<a id="rst-smpte-rp-431-2"></a>
<a id="rst-smpte431"></a>

## SMPTE RP 431-2

**title:** SMPTE RP 431-2:2011 "D-Cinema Quality - Reference Projector and Environment"

**author:** Society of Motion Picture and Television Engineers ([http://www.smpte.org](<http://www.smpte.org>))

<a id="rst-smpte-st-2084"></a>
<a id="rst-smpte2084"></a>

## SMPTE ST 2084

**title:** SMPTE ST 2084:2014 "High Dynamic Range Electro-Optical Transfer Function of Master Reference Displays"

**author:** Society of Motion Picture and Television Engineers ([http://www.smpte.org](<http://www.smpte.org>))

<a id="rst-srgb-1"></a>
<a id="rst-srgb"></a>

## sRGB

**title:** IEC 61966-2-1 ed1.0 "Multimedia systems and equipment - Colour measurement and management - Part 2-1: Colour management - Default RGB colour space - sRGB"

**author:** International Electrotechnical Commission ([http://www.iec.ch](<http://www.iec.ch>))

<a id="rst-sycc-1"></a>
<a id="rst-sycc"></a>

## sYCC

**title:** IEC 61966-2-1-am1 ed1.0 "Amendment 1 - Multimedia systems and equipment - Colour measurement and management - Part 2-1: Colour management - Default RGB colour space - sRGB"

**author:** International Electrotechnical Commission ([http://www.iec.ch](<http://www.iec.ch>))

<a id="rst-xvycc-1"></a>
<a id="rst-xvycc"></a>

## xvYCC

**title:** IEC 61966-2-4 ed1.0 "Multimedia systems and equipment - Colour measurement and management - Part 2-4: Colour management - Extended-gamut YCC colour space for video applications - xvYCC"

**author:** International Electrotechnical Commission ([http://www.iec.ch](<http://www.iec.ch>))

<a id="rst-oprgb-1"></a>
<a id="rst-oprgb"></a>

## opRGB

**title:** IEC 61966-2-5 "Multimedia systems and equipment - Colour measurement and management - Part 2-5: Colour management - Optional RGB colour space - opRGB"

**author:** International Electrotechnical Commission ([http://www.iec.ch](<http://www.iec.ch>))

<a id="rst-itu-bt-2020"></a>
<a id="rst-itu2020"></a>

## ITU BT.2020

**title:** ITU-R Recommendation BT.2020 (08/2012) "Parameter values for ultra-high definition television systems for production and international programme exchange"

**author:** International Telecommunication Union ([http://www.itu.ch](<http://www.itu.ch>))

<a id="rst-ebu-tech-3213"></a>
<a id="rst-tech3213"></a>

## EBU Tech 3213

**title:** E.B.U. Standard for Chromaticity Tolerances for Studio Monitors

**author:** European Broadcast Union ([http://www.ebu.ch](<http://www.ebu.ch>))

<a id="rst-ebu-tech-3321"></a>
<a id="rst-tech3321"></a>

## EBU Tech 3321

**title:** E.B.U. guidelines for Consumer Flat Panel Displays (FPDs)

**author:** European Broadcast Union ([http://www.ebu.ch](<http://www.ebu.ch>))

<a id="rst-iec-62106"></a>
<a id="rst-iec62106"></a>

## IEC 62106

**title:** Specification of the radio data system (RDS) for VHF/FM sound broadcasting in the frequency range from 87,5 to 108,0 MHz

**author:** International Electrotechnical Commission ([http://www.iec.ch](<http://www.iec.ch>))

<a id="rst-nrsc-4-b"></a>
<a id="rst-nrsc4"></a>

## NRSC-4-B

**title:** NRSC-4-B: United States RBDS Standard

**author:** National Radio Systems Committee ([http://www.nrscstandards.org](<http://www.nrscstandards.org>))

<a id="rst-iso-12232-2006"></a>
<a id="rst-iso12232"></a>

## ISO 12232:2006

**title:** Photography --- Digital still cameras --- Determination of exposure index, ISO speed ratings, standard output sensitivity, and recommended exposure index

**author:** International Organization for Standardization ([http://www.iso.org](<http://www.iso.org>))

<a id="rst-cea-861-e"></a>
<a id="rst-cea861"></a>

## CEA-861-E

**title:** A DTV Profile for Uncompressed High Speed Digital Interfaces

**author:** Consumer Electronics Association ([http://www.ce.org](<http://www.ce.org>))

<a id="rst-vesa-dmt"></a>
<a id="rst-vesadmt"></a>

## VESA DMT

**title:** VESA and Industry Standards and Guidelines for Computer Display Monitor Timing (DMT)

**author:** Video Electronics Standards Association ([http://www.vesa.org](<http://www.vesa.org>))

<a id="rst-e-ddc"></a>
<a id="rst-vesaeddc"></a>

## E-DDC

**title:** VESA Enhanced Display Data Channel (E-DDC) Standard

**subtitle:** Version 1.3

**author:** Video Electronics Standards Association ([http://www.vesa.org](<http://www.vesa.org>))

<a id="rst-edid"></a>
<a id="rst-vesaedid"></a>

## EDID

**title:** VESA Enhanced Extended Display Identification Data Standard

**subtitle:** Release A, Revision 2

**author:** Video Electronics Standards Association ([http://www.vesa.org](<http://www.vesa.org>))

<a id="rst-hdcp-1"></a>
<a id="rst-hdcp"></a>

## HDCP

**title:** High-bandwidth Digital Content Protection System

**subtitle:** Revision 1.3

**author:** Digital Content Protection LLC ([http://www.digital-cp.com](<http://www.digital-cp.com>))

<a id="rst-hdmi-1"></a>
<a id="rst-hdmi"></a>

## HDMI

**title:** High-Definition Multimedia Interface

**subtitle:** Specification Version 1.4a

**author:** HDMI Licensing LLC ([http://www.hdmi.org](<http://www.hdmi.org>))

<a id="rst-hdmi2-1"></a>
<a id="rst-hdmi2"></a>

## HDMI2

**title:** High-Definition Multimedia Interface

**subtitle:** Specification Version 2.0

**author:** HDMI Licensing LLC ([http://www.hdmi.org](<http://www.hdmi.org>))

<a id="rst-dp-1"></a>
<a id="rst-dp"></a>

## DP

**title:** VESA DisplayPort Standard

**subtitle:** Version 1, Revision 2

**author:** Video Electronics Standards Association ([http://www.vesa.org](<http://www.vesa.org>))

<a id="rst-poynton-1"></a>
<a id="rst-poynton"></a>

## poynton

**title:** Digital Video and HDTV, Algorithms and Interfaces

**author:** Charles Poynton

<a id="rst-colimg-1"></a>
<a id="rst-colimg"></a>

## colimg

**title:** Color Imaging: Fundamentals and Applications

**author:** Erik Reinhard et al.

<a id="rst-vp8-1"></a>
<a id="rst-vp8"></a>

## VP8

**title:** RFC 6386: "VP8 Data Format and Decoding Guide"

**author:** - **J.** Bankoski et al.

<a id="rst-vp9-1"></a>
<a id="rst-vp9"></a>

## VP9

**title:** VP9 Bitstream &amp; Decoding Process Specification

**author:** Adrian Grange (Google), Peter de Rivaz (Argon Design), Jonathan Hunt (Argon Design)

<a id="rst-av1-1"></a>
<a id="rst-av1"></a>

## AV1

**title:** AV1 Bitstream &amp; Decoding Process Specification

**author:** Peter de Rivaz, Argon Design Ltd, Jack Haughton, Argon Design Ltd

---

# Buffers

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> A buffer contains data exchanged by application and driver using one of the Streaming I/O methods. In the multi-planar API, the data is held in planes, while the buffer structure acts as a container for the planes. Only pointers to buffers…

<a id="rst-buffers"></a>
<a id="rst-buffer"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

A buffer contains data exchanged by application and driver using one of the Streaming I/O methods. In the multi-planar API, the data is held in planes, while the buffer structure acts as a container for the planes. Only pointers to buffers (planes) are exchanged, the data itself is not copied. These pointers, together with meta-information like timestamps or field parity, are stored in a struct `v4l2_buffer`, argument to the [vidioc\_querybuf](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>), [VIDIOC\_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) and [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. In the multi-planar API, some plane-specific members of struct `v4l2_buffer`, such as pointers and sizes for each plane, are stored in struct `v4l2_plane` instead. In that case, struct `v4l2_buffer` contains an array of plane structures.

Dequeued video buffers come with timestamps. The driver decides at which part of the frame and with which clock the timestamp is taken. Please see flags in the masks `V4L2_BUF_FLAG_TIMESTAMP_MASK` and `V4L2_BUF_FLAG_TSTAMP_SRC_MASK` in [Buffer Flags](<#rst-buffer-flags>). These flags are always valid and constant across all buffers during the whole video stream. Changes in these flags may take place as a side effect of [VIDIOC\_S\_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input>) or [VIDIOC\_S\_OUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-output.md#rst-vidioc-g-output>) however. The `V4L2_BUF_FLAG_TIMESTAMP_COPY` timestamp type which is used by e.g. on mem-to-mem devices is an exception to the rule: the timestamp source flags are copied from the OUTPUT video buffer to the CAPTURE video buffer.

<a id="rst-interactions-between-formats-controls-and-buffers"></a>

## Interactions between formats, controls and buffers

V4L2 exposes parameters that influence the buffer size, or the way data is laid out in the buffer. Those parameters are exposed through both formats and controls. One example of such a control is the `V4L2_CID_ROTATE` control that modifies the direction in which pixels are stored in the buffer, as well as the buffer size when the selected format includes padding at the end of lines.

The set of information needed to interpret the content of a buffer (e.g. the pixel format, the line stride, the tiling orientation or the rotation) is collectively referred to in the rest of this section as the buffer layout.

Controls that can modify the buffer layout shall set the `V4L2_CTRL_FLAG_MODIFY_LAYOUT` flag.

Modifying formats or controls that influence the buffer size or layout require the stream to be stopped. Any attempt at such a modification while the stream is active shall cause the ioctl setting the format or the control to return the `EBUSY` error code. In that case drivers shall also set the `V4L2_CTRL_FLAG_GRABBED` flag when calling `VIDIOC_QUERYCTRL()` or `VIDIOC_QUERY_EXT_CTRL()` for such a control while the stream is active.

> [!NOTE]
>
> The `VIDIOC_S_SELECTION()` ioctl can, depending on the hardware (for instance if the device doesn't include a scaler), modify the format in addition to the selection rectangle. Similarly, the `VIDIOC_S_INPUT()`, `VIDIOC_S_OUTPUT()`, `VIDIOC_S_STD()` and `VIDIOC_S_DV_TIMINGS()` ioctls can also modify the format and selection rectangles. When those ioctls result in a buffer size or layout change, drivers shall handle that condition as they would handle it in the `VIDIOC_S_FMT()` ioctl in all cases described in this section.

Controls that only influence the buffer layout can be modified at any time when the stream is stopped. As they don't influence the buffer size, no special handling is needed to synchronize those controls with buffer allocation and the `V4L2_CTRL_FLAG_GRABBED` flag is cleared once the stream is stopped.

Formats and controls that influence the buffer size interact with buffer allocation. The simplest way to handle this is for drivers to always require buffers to be reallocated in order to change those formats or controls. In that case, to perform such changes, userspace applications shall first stop the video stream with the `VIDIOC_STREAMOFF()` ioctl if it is running and free all buffers with the `VIDIOC_REQBUFS()` ioctl if they are allocated. After freeing all buffers the `V4L2_CTRL_FLAG_GRABBED` flag for controls is cleared. The format or controls can then be modified, and buffers shall then be reallocated and the stream restarted. A typical ioctl sequence is

> 1. VIDIOC\_STREAMOFF
>
> 2. VIDIOC\_REQBUFS(0)
>
> 3. VIDIOC\_S\_EXT\_CTRLS
>
> 4. VIDIOC\_S\_FMT
>
> 5. VIDIOC\_REQBUFS(n)
>
> 6. VIDIOC\_QBUF
>
> 7. VIDIOC\_STREAMON

The second `VIDIOC_REQBUFS()` call will take the new format and control value into account to compute the buffer size to allocate. Applications can also retrieve the size by calling the `VIDIOC_G_FMT()` ioctl if needed.

> [!NOTE]
>
> The API doesn't mandate the above order for control (3.) and format (4.) changes. Format and controls can be set in a different order, or even interleaved, depending on the device and use case. For instance some controls might behave differently for different pixel formats, in which case the format might need to be set first.

When reallocation is required, any attempt to modify format or controls that influences the buffer size while buffers are allocated shall cause the format or control set ioctl to return the `EBUSY` error. Any attempt to queue a buffer too small for the current format or controls shall cause the `VIDIOC_QBUF()` ioctl to return a `EINVAL` error.

Buffer reallocation is an expensive operation. To avoid that cost, drivers can (and are encouraged to) allow format or controls that influence the buffer size to be changed with buffers allocated. In that case, a typical ioctl sequence to modify format and controls is

> 1. VIDIOC\_STREAMOFF
>
> 2. VIDIOC\_S\_EXT\_CTRLS
>
> 3. VIDIOC\_S\_FMT
>
> 4. VIDIOC\_QBUF
>
> 5. VIDIOC\_STREAMON

For this sequence to operate correctly, queued buffers need to be large enough for the new format or controls. Drivers shall return a `ENOSPC` error in response to format change (`VIDIOC_S_FMT()`) or control changes (`VIDIOC_S_CTRL()` or `VIDIOC_S_EXT_CTRLS()`) if buffers too small for the new format are currently queued. As a simplification, drivers are allowed to return a `EBUSY` error from these ioctls if any buffer is currently queued, without checking the queued buffers sizes.

Additionally, drivers shall return a `EINVAL` error from the `VIDIOC_QBUF()` ioctl if the buffer being queued is too small for the current format or controls. Together, these requirements ensure that queued buffers will always be large enough for the configured format and controls.

Userspace applications can query the buffer size required for a given format and controls by first setting the desired control values and then trying the desired format. The `VIDIOC_TRY_FMT()` ioctl will return the required buffer size.

> 1. VIDIOC\_S\_EXT\_CTRLS(x)
>
> 2. VIDIOC\_TRY\_FMT()
>
> 3. VIDIOC\_S\_EXT\_CTRLS(y)
>
> 4. VIDIOC\_TRY\_FMT()

The `VIDIOC_CREATE_BUFS()` ioctl can then be used to allocate buffers based on the queried sizes (for instance by allocating a set of buffers large enough for all the desired formats and controls, or by allocating separate set of appropriately sized buffers for each use case).

<a id="c-v4l2_buffer"></a>



```c
v4l2_buffer
```

<a id="rst-struct-v4l2-buffer"></a>

## struct v4l2\_buffer

<!-- tabularcolumns: |p{2.9cm}|p{2.4cm}|p{12.0cm}| -->


<table>
<caption>

struct v4l2\_buffer

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`index`

</td>
<td>



Number of the buffer, set by the application except when calling [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), then it is set by the driver. This field can range from zero to the number of buffers allocated with the [ioctl VIDIOC\_REQBUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-vidioc-reqbufs>) ioctl (struct `v4l2_requestbuffers` `count`), plus any buffers allocated with [vidioc\_create\_bufs](</kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md#rst-vidioc-create-bufs>) minus one.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`type`

</td>
<td>



Type of the buffer, same as struct `v4l2_format` `type` or struct `v4l2_requestbuffers` `type`, set by the application. See `v4l2_buf_type`

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`bytesused`

</td>
<td>



The number of bytes occupied by the data in the buffer. It depends on the negotiated data format and may change with each buffer for compressed variable size data like JPEG images. Drivers must set this field when `type` refers to a capture stream, applications when it refers to an output stream. For multiplanar formats this field is ignored and the `planes` pointer is used instead.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



Flags set by the application or driver, see [Buffer Flags](<#rst-buffer-flags>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`field`

</td>
<td>



Indicates the field order of the image in the buffer, see `v4l2_field`. This field is not used when the buffer contains VBI data. Drivers must set it when `type` refers to a capture stream, applications when it refers to an output stream.

</td>
</tr>
<tr>
<td>



struct timeval

</td>
<td>



`timestamp`

</td>
<td>



For capture streams this is time when the first data byte was captured, as returned by the `clock_gettime()` function for the relevant clock id; see `V4L2_BUF_FLAG_TIMESTAMP_*` in [Buffer Flags](<#rst-buffer-flags>). For output streams the driver stores the time at which the last data byte was actually sent out in the `timestamp` field. This permits applications to monitor the drift between the video and system clock. For output streams that use `V4L2_BUF_FLAG_TIMESTAMP_COPY` the application has to fill in the timestamp which will be copied by the driver to the capture stream.

</td>
</tr>
<tr>
<td>



struct `v4l2_timecode`

</td>
<td>



`timecode`

</td>
<td>



When the `V4L2_BUF_FLAG_TIMECODE` flag is set in `flags`, this structure contains a frame timecode. In `V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and bottom field contain the same timecode. Timecodes are intended to help video editing and are typically recorded on video tapes, but also embedded in compressed formats like MPEG. This field is independent of the `timestamp` and `sequence` fields.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`sequence`

</td>
<td>



Set by the driver, counting the frames (not fields\!) in sequence. This field is set for both input and output devices.

</td>
</tr>
<tr>
<td colspan="3">



In `V4L2_FIELD_ALTERNATE <v4l2_field>` mode the top and bottom field have the same sequence number. The count starts at zero and includes dropped or repeated frames. A dropped frame was received by an input device but could not be stored due to lack of free buffer space. A repeated frame was displayed again by an output device because the application did not pass new data in time.

> [!NOTE]
>
> This may count the frames received e.g. over USB, without taking into account the frames dropped by the remote hardware due to limited compression throughput or bus bandwidth. These devices identify by not enumerating any video standards, see [standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`memory`

</td>
<td>



This field must be set by applications and/or drivers in accordance with the selected I/O method. See `v4l2_memory`

</td>
</tr>
<tr>
<td>



union \{

</td>
<td colspan="2">



`m`

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`offset`

</td>
<td>



For the single-planar API and when `memory` is `V4L2_MEMORY_MMAP` this is the offset of the buffer from the start of the device memory. The value is returned by the driver and apart of serving as parameter to the `mmap()` function not useful for applications. See [mmap](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) for details

</td>
</tr>
<tr>
<td>



unsigned long

</td>
<td>



`userptr`

</td>
<td>



For the single-planar API and when `memory` is `V4L2_MEMORY_USERPTR` this is a pointer to the buffer (casted to unsigned long type) in virtual memory, set by the application. See [userp](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>) for details.

</td>
</tr>
<tr>
<td>



struct v4l2\_plane

</td>
<td>



`*planes`

</td>
<td>



When using the multi-planar API, contains a userspace pointer to an array of struct `v4l2_plane`. The size of the array should be put in the `length` field of this struct `v4l2_buffer` structure.

</td>
</tr>
<tr>
<td>



int

</td>
<td>



`fd`

</td>
<td>



For the single-plane API and when `memory` is `V4L2_MEMORY_DMABUF` this is the file descriptor associated with a DMABUF buffer.

</td>
</tr>
<tr>
<td>



\}

</td>
<td colspan="2">





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`length`

</td>
<td>



Size of the buffer (not the payload) in bytes for the single-planar API. This is set by the driver based on the calls to [ioctl VIDIOC\_REQBUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-vidioc-reqbufs>) and/or [vidioc\_create\_bufs](</kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md#rst-vidioc-create-bufs>). For the multi-planar API the application sets this to the number of elements in the `planes` array. The driver will fill in the actual number of valid elements in that array.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved2`

</td>
<td>



A place holder for future extensions. Drivers and applications must set this to 0.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`request_fd`

</td>
<td>



The file descriptor of the request to queue the buffer to. If the flag `V4L2_BUF_FLAG_REQUEST_FD` is set, then the buffer will be queued to this request. If the flag is not set, then this field will be ignored.

The `V4L2_BUF_FLAG_REQUEST_FD` flag and this field are only used by [ioctl VIDIOC\_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) and ignored by other ioctls that take a `v4l2_buffer` as argument.

Applications should not set `V4L2_BUF_FLAG_REQUEST_FD` for any ioctls other than [VIDIOC\_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>).

If the device does not support requests, then `EBADR` will be returned. If requests are supported but an invalid request file descriptor is given, then `EINVAL` will be returned.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_plane"></a>



```c
v4l2_plane
```

<a id="rst-struct-v4l2-plane"></a>

## struct v4l2\_plane

<!-- tabularcolumns: |p{3.5cm}|p{3.5cm}|p{10.3cm}| -->


<table>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`bytesused`

</td>
<td>



The number of bytes occupied by data in the plane (its payload). Drivers must set this field when `type` refers to a capture stream, applications when it refers to an output stream.

> [!NOTE]
>
> Note that the actual image data starts at `data_offset` which may not be 0.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`length`

</td>
<td>



Size in bytes of the plane (not its payload). This is set by the driver based on the calls to [ioctl VIDIOC\_REQBUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-vidioc-reqbufs>) and/or [vidioc\_create\_bufs](</kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md#rst-vidioc-create-bufs>).

</td>
</tr>
<tr>
<td>



union \{

</td>
<td colspan="2">



`m`

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`mem_offset`

</td>
<td>



When the memory type in the containing struct `v4l2_buffer` is `V4L2_MEMORY_MMAP`, this is the value that should be passed to `mmap()`, similar to the `offset` field in struct `v4l2_buffer`.

</td>
</tr>
<tr>
<td>



unsigned long

</td>
<td>



`userptr`

</td>
<td>



When the memory type in the containing struct `v4l2_buffer` is `V4L2_MEMORY_USERPTR`, this is a userspace pointer to the memory allocated for this plane by an application.

</td>
</tr>
<tr>
<td>



int

</td>
<td>



`fd`

</td>
<td>



When the memory type in the containing struct `v4l2_buffer` is `V4L2_MEMORY_DMABUF`, this is a file descriptor associated with a DMABUF buffer, similar to the `fd` field in struct `v4l2_buffer`.

</td>
</tr>
<tr>
<td>



\}

</td>
<td colspan="2">





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`data_offset`

</td>
<td>



Offset in bytes to video data in the plane. Drivers must set this field when `type` refers to a capture stream, applications when it refers to an output stream.

> [!NOTE]
>
> That data\_offset is included  in `bytesused`. So the size of the image in the plane is `bytesused`-`data_offset` at offset `data_offset` from the start of the plane.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved[11]`

</td>
<td>



Reserved for future use. Should be zeroed by drivers and applications.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_buf_type"></a>



```c
v4l2_buf_type
```

<a id="rst-enum-v4l2-buf-type"></a>

## enum v4l2\_buf\_type

<!-- tabularcolumns: |p{7.8cm}|p{0.6cm}|p{8.9cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_BUF_TYPE_VIDEO_CAPTURE`

</td>
<td>



1

</td>
<td>



Buffer of a single-planar video capture stream, see [capture](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`

</td>
<td>



9

</td>
<td>



Buffer of a multi-planar video capture stream, see [capture](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_VIDEO_OUTPUT`

</td>
<td>



2

</td>
<td>



Buffer of a single-planar video output stream, see [output](</kernel/userspace/userspace-api/media-v4l/dev-output.md#rst-output>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`

</td>
<td>



10

</td>
<td>



Buffer of a multi-planar video output stream, see [output](</kernel/userspace/userspace-api/media-v4l/dev-output.md#rst-output>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_VIDEO_OVERLAY`

</td>
<td>



3

</td>
<td>



Buffer for video overlay, see [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_VBI_CAPTURE`

</td>
<td>



4

</td>
<td>



Buffer of a raw VBI capture stream, see [raw-vbi](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_VBI_OUTPUT`

</td>
<td>



5

</td>
<td>



Buffer of a raw VBI output stream, see [raw-vbi](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_SLICED_VBI_CAPTURE`

</td>
<td>



6

</td>
<td>



Buffer of a sliced VBI capture stream, see [Sliced VBI Data Interface](</kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-sliced>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_SLICED_VBI_OUTPUT`

</td>
<td>



7

</td>
<td>



Buffer of a sliced VBI output stream, see [Sliced VBI Data Interface](</kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-sliced>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY`

</td>
<td>



8

</td>
<td>



Buffer for video output overlay (OSD), see [osd](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_SDR_CAPTURE`

</td>
<td>



11

</td>
<td>



Buffer for Software Defined Radio (SDR) capture stream, see [sdr](</kernel/userspace/userspace-api/media-v4l/dev-sdr.md#rst-sdr>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_SDR_OUTPUT`

</td>
<td>



12

</td>
<td>



Buffer for Software Defined Radio (SDR) output stream, see [sdr](</kernel/userspace/userspace-api/media-v4l/dev-sdr.md#rst-sdr>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_META_CAPTURE`

</td>
<td>



13

</td>
<td>



Buffer for metadata capture, see [metadata](</kernel/userspace/userspace-api/media-v4l/dev-meta.md#rst-metadata>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_TYPE_META_OUTPUT`

</td>
<td>



14

</td>
<td>



Buffer for metadata output, see [metadata](</kernel/userspace/userspace-api/media-v4l/dev-meta.md#rst-metadata>).

</td>
</tr>
</tbody>
</table>

<a id="rst-buffer-flags-1"></a>
<a id="rst-buffer-flags"></a>

## Buffer Flags

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{6.5cm}|p{1.8cm}|p{9.0cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_BUF_FLAG_MAPPED`

</td>
<td>



0x00000001

</td>
<td>



<a id="rst-v4l2-buf-flag-mapped"></a>

The buffer resides in device memory and has been mapped into the application's address space, see [mmap](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) for details. Drivers set or clear this flag when the [vidioc\_querybuf](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>), [vidioc\_qbuf](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) or [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl is called. Set by the driver.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_QUEUED`

</td>
<td>



0x00000002

</td>
<td>



<a id="rst-v4l2-buf-flag-queued"></a>

Internally drivers maintain two buffer queues, an incoming and outgoing queue. When this flag is set, the buffer is currently on the incoming queue. It automatically moves to the outgoing queue after the buffer has been filled (capture devices) or displayed (output devices). Drivers set or clear this flag when the `VIDIOC_QUERYBUF` ioctl is called. After (successful) calling the `VIDIOC_QBUF`ioctl it is always set and after `VIDIOC_DQBUF` always cleared.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_DONE`

</td>
<td>



0x00000004

</td>
<td>



<a id="rst-v4l2-buf-flag-done"></a>

When this flag is set, the buffer is currently on the outgoing queue, ready to be dequeued from the driver. Drivers set or clear this flag when the `VIDIOC_QUERYBUF` ioctl is called. After calling the `VIDIOC_QBUF` or `VIDIOC_DQBUF` it is always cleared. Of course a buffer cannot be on both queues at the same time, the `V4L2_BUF_FLAG_QUEUED` and `V4L2_BUF_FLAG_DONE` flag are mutually exclusive. They can be both cleared however, then the buffer is in "dequeued" state, in the application domain so to say.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_ERROR`

</td>
<td>



0x00000040

</td>
<td>



<a id="rst-v4l2-buf-flag-error"></a>

When this flag is set, the buffer has been dequeued successfully, although the data might have been corrupted. This is recoverable, streaming may continue as normal and the buffer may be reused normally. Drivers set this flag when the `VIDIOC_DQBUF` ioctl is called.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_IN_REQUEST`

</td>
<td>



0x00000080

</td>
<td>



<a id="rst-v4l2-buf-flag-in-request"></a>

This buffer is part of a request that hasn't been queued yet.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_KEYFRAME`

</td>
<td>



0x00000008

</td>
<td>



<a id="rst-v4l2-buf-flag-keyframe"></a>

Drivers set or clear this flag when calling the `VIDIOC_DQBUF` ioctl. It may be set by video capture devices when the buffer contains a compressed image which is a key frame (or field), i. e. can be decompressed on its own. Also known as an I-frame. Applications can set this bit when `type` refers to an output stream.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_PFRAME`

</td>
<td>



0x00000010

</td>
<td>



<a id="rst-v4l2-buf-flag-pframe"></a>

Similar to `V4L2_BUF_FLAG_KEYFRAME` this flags predicted frames or fields which contain only differences to a previous key frame. Applications can set this bit when `type` refers to an output stream.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_BFRAME`

</td>
<td>



0x00000020

</td>
<td>



<a id="rst-v4l2-buf-flag-bframe"></a>

Similar to `V4L2_BUF_FLAG_KEYFRAME` this flags a bi-directional predicted frame or field which contains only the differences between the current frame and both the preceding and following key frames to specify its content. Applications can set this bit when `type` refers to an output stream.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_TIMECODE`

</td>
<td>



0x00000100

</td>
<td>



<a id="rst-v4l2-buf-flag-timecode"></a>

The `timecode` field is valid. Drivers set or clear this flag when the `VIDIOC_DQBUF` ioctl is called. Applications can set this bit and the corresponding `timecode` structure when `type` refers to an output stream.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_PREPARED`

</td>
<td>



0x00000400

</td>
<td>



<a id="rst-v4l2-buf-flag-prepared"></a>

The buffer has been prepared for I/O and can be queued by the application. Drivers set or clear this flag when the [VIDIOC\_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>), [VIDIOC\_PREPARE\_BUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC\_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) or [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl is called.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE`

</td>
<td>



0x00000800

</td>
<td>



<a id="rst-v4l2-buf-flag-no-cache-invalidate"></a>

Caches do not have to be invalidated for this buffer. Typically applications shall use this flag if the data captured in the buffer is not going to be touched by the CPU, instead the buffer will, probably, be passed on to a DMA-capable hardware unit for further processing or output. This flag is ignored unless the queue is used for [memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) streaming I/O and reports [V4L2\_BUF\_CAP\_SUPPORTS\_MMAP\_CACHE\_HINTS](</kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-mmap-cache-hints>) capability.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_NO_CACHE_CLEAN`

</td>
<td>



0x00001000

</td>
<td>



<a id="rst-v4l2-buf-flag-no-cache-clean"></a>

Caches do not have to be cleaned for this buffer. Typically applications shall use this flag for output buffers if the data in this buffer has not been created by the CPU but by some DMA-capable unit, in which case caches have not been used. This flag is ignored unless the queue is used for [memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) streaming I/O and reports [V4L2\_BUF\_CAP\_SUPPORTS\_MMAP\_CACHE\_HINTS](</kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-mmap-cache-hints>) capability.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`

</td>
<td>



0x00000200

</td>
<td>



<a id="rst-v4l2-buf-flag-m2m-hold-capture-buf"></a>

Only valid if struct `v4l2_requestbuffers` flag `V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF` is set. It is typically used with stateless decoders where multiple output buffers each decode to a slice of the decoded frame. Applications can set this flag when queueing the output buffer to prevent the driver from dequeueing the capture buffer after the output buffer has been decoded (i.e. the capture buffer is 'held'). If the timestamp of this output buffer differs from that of the previous output buffer, then that indicates the start of a new frame and the previously held capture buffer is dequeued.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_LAST`

</td>
<td>



0x00100000

</td>
<td>



<a id="rst-v4l2-buf-flag-last"></a>

Last buffer produced by the hardware. mem2mem codec drivers set this flag on the capture queue for the last buffer when the [vidioc\_querybuf](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>) or [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl is called. Due to hardware limitations, the last buffer may be empty. In this case the driver will set the `bytesused` field to 0, regardless of the format. Any subsequent call to the [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl will not block anymore, but return an `EPIPE` error code.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_REQUEST_FD`

</td>
<td>



0x00800000

</td>
<td>



<a id="rst-v4l2-buf-flag-request-fd"></a>

The `request_fd` field contains a valid file descriptor.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_TIMESTAMP_MASK`

</td>
<td>



0x0000e000

</td>
<td>



<a id="rst-v4l2-buf-flag-timestamp-mask"></a>

Mask for timestamp types below. To test the timestamp type, mask out bits not belonging to timestamp type by performing a logical and operation with buffer flags and timestamp mask.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN`

</td>
<td>



0x00000000

</td>
<td>



<a id="rst-v4l2-buf-flag-timestamp-unknown"></a>

Unknown timestamp type. This type is used by drivers before Linux 3.9 and may be either monotonic (see below) or realtime (wall clock). Monotonic clock has been favoured in embedded systems whereas most of the drivers use the realtime clock. Either kinds of timestamps are available in user space via `clock_gettime()` using clock IDs `CLOCK_MONOTONIC` and `CLOCK_REALTIME`, respectively.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC`

</td>
<td>



0x00002000

</td>
<td>



<a id="rst-v4l2-buf-flag-timestamp-monotonic"></a>

The buffer timestamp has been taken from the `CLOCK_MONOTONIC` clock. To access the same clock outside V4L2, use `clock_gettime()`.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_TIMESTAMP_COPY`

</td>
<td>



0x00004000

</td>
<td>



<a id="rst-v4l2-buf-flag-timestamp-copy"></a>

The CAPTURE buffer timestamp has been taken from the corresponding OUTPUT buffer. This flag applies only to mem2mem devices.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_TSTAMP_SRC_MASK`

</td>
<td>



0x00070000

</td>
<td>



<a id="rst-v4l2-buf-flag-tstamp-src-mask"></a>

Mask for timestamp sources below. The timestamp source defines the point of time the timestamp is taken in relation to the frame. Logical 'and' operation between the `flags` field and `V4L2_BUF_FLAG_TSTAMP_SRC_MASK` produces the value of the timestamp source. Applications must set the timestamp source when `type` refers to an output stream and `V4L2_BUF_FLAG_TIMESTAMP_COPY` is set.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_TSTAMP_SRC_EOF`

</td>
<td>



0x00000000

</td>
<td>



<a id="rst-v4l2-buf-flag-tstamp-src-eof"></a>

End Of Frame. The buffer timestamp has been taken when the last pixel of the frame has been received or the last pixel of the frame has been transmitted. In practice, software generated timestamps will typically be read from the clock a small amount of time after the last pixel has been received or transmitten, depending on the system and other activity in it.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_FLAG_TSTAMP_SRC_SOE`

</td>
<td>



0x00010000

</td>
<td>



<a id="rst-v4l2-buf-flag-tstamp-src-soe"></a>

Start Of Exposure. The buffer timestamp has been taken when the exposure of the frame has begun. This is only valid for the `V4L2_BUF_TYPE_VIDEO_CAPTURE` buffer type.

</td>
</tr>
</tbody>
</table>

<a id="c-enum-v4l2_memory"></a>



```c
v4l2_memory
```

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-enum-v4l2-memory"></a>

## enum v4l2\_memory

<!-- tabularcolumns: |p{5.0cm}|p{0.8cm}|p{11.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MEMORY_MMAP`

</td>
<td>



1

</td>
<td>



The buffer is used for [memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) I/O.

</td>
</tr>
<tr>
<td>



`V4L2_MEMORY_USERPTR`

</td>
<td>



2

</td>
<td>



The buffer is used for [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>) I/O.

</td>
</tr>
<tr>
<td>



`V4L2_MEMORY_OVERLAY`

</td>
<td>



3

</td>
<td>



\[to do\]

</td>
</tr>
<tr>
<td>



`V4L2_MEMORY_DMABUF`

</td>
<td>



4

</td>
<td>



The buffer is used for [DMA shared buffer](</kernel/userspace/userspace-api/media-v4l/dmabuf.md#rst-dmabuf>) I/O.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

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

## Timecodes

The `v4l2_buffer_timecode` structure is designed to hold a [smpte12m](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-smpte12m>) or similar timecode. (struct `timeval` timestamps are stored in the struct `v4l2_buffer` `timestamp` field.)

<a id="c-v4l2_timecode"></a>



```c
v4l2_timecode
```

<a id="rst-struct-v4l2-timecode"></a>

### struct v4l2\_timecode

<!-- tabularcolumns: |p{1.4cm}|p{2.8cm}|p{13.1cm}| -->


<table>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`type`

</td>
<td>



Frame rate the timecodes are based on, see [Timecode Types](<#rst-timecode-type>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



Timecode flags, see [Timecode Flags](<#rst-timecode-flags>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`frames`

</td>
<td>



Frame count, 0 ... 23/24/29/49/59, depending on the type of timecode.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`seconds`

</td>
<td>



Seconds count, 0 ... 59. This is a binary, not BCD number.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`minutes`

</td>
<td>



Minutes count, 0 ... 59. This is a binary, not BCD number.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`hours`

</td>
<td>



Hours count, 0 ... 29. This is a binary, not BCD number.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`userbits`\[4\]

</td>
<td>



The "user group" bits from the timecode.

</td>
</tr>
</tbody>
</table>

<a id="rst-timecode-types"></a>
<a id="rst-timecode-type"></a>

### Timecode Types


<table>
<tbody>
<tr>
<td>



`V4L2_TC_TYPE_24FPS`

</td>
<td>



1

</td>
<td>



24 frames per second, i. e. film.

</td>
</tr>
<tr>
<td>



`V4L2_TC_TYPE_25FPS`

</td>
<td>



2

</td>
<td>



25 frames per second, i. e. PAL or SECAM video.

</td>
</tr>
<tr>
<td>



`V4L2_TC_TYPE_30FPS`

</td>
<td>



3

</td>
<td>



30 frames per second, i. e. NTSC video.

</td>
</tr>
<tr>
<td>



`V4L2_TC_TYPE_50FPS`

</td>
<td>



4

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_TC_TYPE_60FPS`

</td>
<td>



5

</td>
<td>





</td>
</tr>
</tbody>
</table>

<a id="rst-timecode-flags-1"></a>
<a id="rst-timecode-flags"></a>

### Timecode Flags

<!-- tabularcolumns: |p{6.6cm}|p{1.4cm}|p{9.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_TC_FLAG_DROPFRAME`

</td>
<td>



0x0001

</td>
<td>



Indicates "drop frame" semantics for counting frames in 29.97 fps material. When set, frame numbers 0 and 1 at the start of each minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the count.

</td>
</tr>
<tr>
<td>



`V4L2_TC_FLAG_COLORFRAME`

</td>
<td>



0x0002

</td>
<td>



The "color frame" flag.

</td>
</tr>
<tr>
<td>



`V4L2_TC_USERBITS_field`

</td>
<td>



0x000C

</td>
<td>



Field mask for the "binary group flags".

</td>
</tr>
<tr>
<td>



`V4L2_TC_USERBITS_USERDEFINED`

</td>
<td>



0x0000

</td>
<td>



Unspecified format.

</td>
</tr>
<tr>
<td>



`V4L2_TC_USERBITS_8BITCHARS`

</td>
<td>



0x0008

</td>
<td>



8-bit ISO characters.

</td>
</tr>
</tbody>
</table>

---

# Video Capture Example

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Video Capture Example.

<a id="rst-video-capture-example"></a>
<a id="rst-capture-example"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

- [file: media/v4l/capture.c](</kernel/userspace/userspace-api/media-v4l/capture-c.md>)

---

# file: media/v4l/capture.c

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for file: media/v4l/capture.c.

<a id="rst-file-media-v4l-capture-c"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->



```c
/*
 *  V4L2 video capture example
 *
 *  This program can be used and distributed without restrictions.
 *
 *      This program is provided with the V4L2 API
 * see https://linuxtv.org/docs.php for more information
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include <getopt.h>             /* getopt_long() */

#include <fcntl.h>              /* low-level i/o */
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>

#include <linux/videodev2.h>

#define CLEAR(x) memset(&(x), 0, sizeof(x))

enum io_method {
        IO_METHOD_READ,
        IO_METHOD_MMAP,
        IO_METHOD_USERPTR,
};

struct buffer {
        void   *start;
        size_t  length;
};

static char            *dev_name;
static enum io_method   io = IO_METHOD_MMAP;
static int              fd = -1;
struct buffer          *buffers;
static unsigned int     n_buffers;
static int              out_buf;
static int              force_format;
static int              frame_count = 70;

static void errno_exit(const char *s)
{
        fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno));
        exit(EXIT_FAILURE);
}

static int xioctl(int fh, int request, void *arg)
{
        int r;

        do {
                r = ioctl(fh, request, arg);
        } while (-1 == r && EINTR == errno);

        return r;
}

static void process_image(const void *p, int size)
{
        if (out_buf)
                fwrite(p, size, 1, stdout);

        fflush(stderr);
        fprintf(stderr, ".");
        fflush(stdout);
}

static int read_frame(void)
{
        struct v4l2_buffer buf;
        unsigned int i;

        switch (io) {
        case IO_METHOD_READ:
                if (-1 == read(fd, buffers[0].start, buffers[0].length)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;

                        case EIO:
                                /* Could ignore EIO, see spec. */

                                /* fall through */

                        default:
                                errno_exit("read");
                        }
                }

                process_image(buffers[0].start, buffers[0].length);
                break;

        case IO_METHOD_MMAP:
                CLEAR(buf);

                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_MMAP;

                if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;

                        case EIO:
                                /* Could ignore EIO, see spec. */

                                /* fall through */

                        default:
                                errno_exit("VIDIOC_DQBUF");
                        }
                }

                assert(buf.index < n_buffers);

                process_image(buffers[buf.index].start, buf.bytesused);

                if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                        errno_exit("VIDIOC_QBUF");
                break;

        case IO_METHOD_USERPTR:
                CLEAR(buf);

                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_USERPTR;

                if (-1 == xioctl(fd, VIDIOC_DQBUF, &buf)) {
                        switch (errno) {
                        case EAGAIN:
                                return 0;

                        case EIO:
                                /* Could ignore EIO, see spec. */

                                /* fall through */

                        default:
                                errno_exit("VIDIOC_DQBUF");
                        }
                }

                for (i = 0; i < n_buffers; ++i)
                        if (buf.m.userptr == (unsigned long)buffers[i].start
                            && buf.length == buffers[i].length)
                                break;

                assert(i < n_buffers);

                process_image((void *)buf.m.userptr, buf.bytesused);

                if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                        errno_exit("VIDIOC_QBUF");
                break;
        }

        return 1;
}

static void mainloop(void)
{
        unsigned int count;

        count = frame_count;

        while (count-- > 0) {
                for (;;) {
                        fd_set fds;
                        struct timeval tv;
                        int r;

                        FD_ZERO(&fds);
                        FD_SET(fd, &fds);

                        /* Timeout. */
                        tv.tv_sec = 2;
                        tv.tv_usec = 0;

                        r = select(fd + 1, &fds, NULL, NULL, &tv);

                        if (-1 == r) {
                                if (EINTR == errno)
                                        continue;
                                errno_exit("select");
                        }

                        if (0 == r) {
                                fprintf(stderr, "select timeout\n");
                                exit(EXIT_FAILURE);
                        }

                        if (read_frame())
                                break;
                        /* EAGAIN - continue select loop. */
                }
        }
}

static void stop_capturing(void)
{
        enum v4l2_buf_type type;

        switch (io) {
        case IO_METHOD_READ:
                /* Nothing to do. */
                break;

        case IO_METHOD_MMAP:
        case IO_METHOD_USERPTR:
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                if (-1 == xioctl(fd, VIDIOC_STREAMOFF, &type))
                        errno_exit("VIDIOC_STREAMOFF");
                break;
        }
}

static void start_capturing(void)
{
        unsigned int i;
        enum v4l2_buf_type type;

        switch (io) {
        case IO_METHOD_READ:
                /* Nothing to do. */
                break;

        case IO_METHOD_MMAP:
                for (i = 0; i < n_buffers; ++i) {
                        struct v4l2_buffer buf;

                        CLEAR(buf);
                        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                        buf.memory = V4L2_MEMORY_MMAP;
                        buf.index = i;

                        if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                                errno_exit("VIDIOC_QBUF");
                }
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
                        errno_exit("VIDIOC_STREAMON");
                break;

        case IO_METHOD_USERPTR:
                for (i = 0; i < n_buffers; ++i) {
                        struct v4l2_buffer buf;

                        CLEAR(buf);
                        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                        buf.memory = V4L2_MEMORY_USERPTR;
                        buf.index = i;
                        buf.m.userptr = (unsigned long)buffers[i].start;
                        buf.length = buffers[i].length;

                        if (-1 == xioctl(fd, VIDIOC_QBUF, &buf))
                                errno_exit("VIDIOC_QBUF");
                }
                type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                if (-1 == xioctl(fd, VIDIOC_STREAMON, &type))
                        errno_exit("VIDIOC_STREAMON");
                break;
        }
}

static void uninit_device(void)
{
        unsigned int i;

        switch (io) {
        case IO_METHOD_READ:
                free(buffers[0].start);
                break;

        case IO_METHOD_MMAP:
                for (i = 0; i < n_buffers; ++i)
                        if (-1 == munmap(buffers[i].start, buffers[i].length))
                                errno_exit("munmap");
                break;

        case IO_METHOD_USERPTR:
                for (i = 0; i < n_buffers; ++i)
                        free(buffers[i].start);
                break;
        }

        free(buffers);
}

static void init_read(unsigned int buffer_size)
{
        buffers = calloc(1, sizeof(*buffers));

        if (!buffers) {
                fprintf(stderr, "Out of memory\n");
                exit(EXIT_FAILURE);
        }

        buffers[0].length = buffer_size;
        buffers[0].start = malloc(buffer_size);

        if (!buffers[0].start) {
                fprintf(stderr, "Out of memory\n");
                exit(EXIT_FAILURE);
        }
}

static void init_mmap(void)
{
        struct v4l2_requestbuffers req;

        CLEAR(req);

        req.count = 4;
        req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        req.memory = V4L2_MEMORY_MMAP;

        if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s does not support "
                                 "memory mapping\n", dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_REQBUFS");
                }
        }

        if (req.count < 2) {
                fprintf(stderr, "Insufficient buffer memory on %s\n",
                         dev_name);
                exit(EXIT_FAILURE);
        }

        buffers = calloc(req.count, sizeof(*buffers));

        if (!buffers) {
                fprintf(stderr, "Out of memory\n");
                exit(EXIT_FAILURE);
        }

        for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
                struct v4l2_buffer buf;

                CLEAR(buf);

                buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory      = V4L2_MEMORY_MMAP;
                buf.index       = n_buffers;

                if (-1 == xioctl(fd, VIDIOC_QUERYBUF, &buf))
                        errno_exit("VIDIOC_QUERYBUF");

                buffers[n_buffers].length = buf.length;
                buffers[n_buffers].start =
                        mmap(NULL /* start anywhere */,
                              buf.length,
                              PROT_READ | PROT_WRITE /* required */,
                              MAP_SHARED /* recommended */,
                              fd, buf.m.offset);

                if (MAP_FAILED == buffers[n_buffers].start)
                        errno_exit("mmap");
        }
}

static void init_userp(unsigned int buffer_size)
{
        struct v4l2_requestbuffers req;

        CLEAR(req);

        req.count  = 4;
        req.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        req.memory = V4L2_MEMORY_USERPTR;

        if (-1 == xioctl(fd, VIDIOC_REQBUFS, &req)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s does not support "
                                 "user pointer i/o\n", dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_REQBUFS");
                }
        }

        buffers = calloc(4, sizeof(*buffers));

        if (!buffers) {
                fprintf(stderr, "Out of memory\n");
                exit(EXIT_FAILURE);
        }

        for (n_buffers = 0; n_buffers < 4; ++n_buffers) {
                buffers[n_buffers].length = buffer_size;
                buffers[n_buffers].start = malloc(buffer_size);

                if (!buffers[n_buffers].start) {
                        fprintf(stderr, "Out of memory\n");
                        exit(EXIT_FAILURE);
                }
        }
}

static void init_device(void)
{
        struct v4l2_capability cap;
        struct v4l2_cropcap cropcap;
        struct v4l2_crop crop;
        struct v4l2_format fmt;
        unsigned int min;

        if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
                if (EINVAL == errno) {
                        fprintf(stderr, "%s is no V4L2 device\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                } else {
                        errno_exit("VIDIOC_QUERYCAP");
                }
        }

        if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
                fprintf(stderr, "%s is no video capture device\n",
                         dev_name);
                exit(EXIT_FAILURE);
        }

        switch (io) {
        case IO_METHOD_READ:
                if (!(cap.capabilities & V4L2_CAP_READWRITE)) {
                        fprintf(stderr, "%s does not support read i/o\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                }
                break;

        case IO_METHOD_MMAP:
        case IO_METHOD_USERPTR:
                if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
                        fprintf(stderr, "%s does not support streaming i/o\n",
                                 dev_name);
                        exit(EXIT_FAILURE);
                }
                break;
        }


        /* Select video input, video standard and tune here. */


        CLEAR(cropcap);

        cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

        if (0 == xioctl(fd, VIDIOC_CROPCAP, &cropcap)) {
                crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                crop.c = cropcap.defrect; /* reset to default */

                if (-1 == xioctl(fd, VIDIOC_S_CROP, &crop)) {
                        switch (errno) {
                        case EINVAL:
                                /* Cropping not supported. */
                                break;
                        default:
                                /* Errors ignored. */
                                break;
                        }
                }
        } else {
                /* Errors ignored. */
        }


        CLEAR(fmt);

        fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (force_format) {
                fmt.fmt.pix.width       = 640;
                fmt.fmt.pix.height      = 480;
                fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
                fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;

                if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
                        errno_exit("VIDIOC_S_FMT");

                /* Note VIDIOC_S_FMT may change width and height. */
        } else {
                /* Preserve original settings as set by v4l2-ctl for example */
                if (-1 == xioctl(fd, VIDIOC_G_FMT, &fmt))
                        errno_exit("VIDIOC_G_FMT");
        }

        /* Buggy driver paranoia. */
        min = fmt.fmt.pix.width * 2;
        if (fmt.fmt.pix.bytesperline < min)
                fmt.fmt.pix.bytesperline = min;
        min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
        if (fmt.fmt.pix.sizeimage < min)
                fmt.fmt.pix.sizeimage = min;

        switch (io) {
        case IO_METHOD_READ:
                init_read(fmt.fmt.pix.sizeimage);
                break;

        case IO_METHOD_MMAP:
                init_mmap();
                break;

        case IO_METHOD_USERPTR:
                init_userp(fmt.fmt.pix.sizeimage);
                break;
        }
}

static void close_device(void)
{
        if (-1 == close(fd))
                errno_exit("close");

        fd = -1;
}

static void open_device(void)
{
        struct stat st;

        if (-1 == stat(dev_name, &st)) {
                fprintf(stderr, "Cannot identify '%s': %d, %s\n",
                         dev_name, errno, strerror(errno));
                exit(EXIT_FAILURE);
        }

        if (!S_ISCHR(st.st_mode)) {
                fprintf(stderr, "%s is no device\n", dev_name);
                exit(EXIT_FAILURE);
        }

        fd = open(dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);

        if (-1 == fd) {
                fprintf(stderr, "Cannot open '%s': %d, %s\n",
                         dev_name, errno, strerror(errno));
                exit(EXIT_FAILURE);
        }
}

static void usage(FILE *fp, int argc, char **argv)
{
        fprintf(fp,
                 "Usage: %s [options]\n\n"
                 "Version 1.3\n"
                 "Options:\n"
                 "-d | --device name   Video device name [%s]\n"
                 "-h | --help          Print this message\n"
                 "-m | --mmap          Use memory mapped buffers [default]\n"
                 "-r | --read          Use read() calls\n"
                 "-u | --userp         Use application allocated buffers\n"
                 "-o | --output        Outputs stream to stdout\n"
                 "-f | --format        Force format to 640x480 YUYV\n"
                 "-c | --count         Number of frames to grab [%i]\n"
                 "",
                 argv[0], dev_name, frame_count);
}

static const char short_options[] = "d:hmruofc:";

static const struct option
long_options[] = {
        { "device", required_argument, NULL, 'd' },
        { "help",   no_argument,       NULL, 'h' },
        { "mmap",   no_argument,       NULL, 'm' },
        { "read",   no_argument,       NULL, 'r' },
        { "userp",  no_argument,       NULL, 'u' },
        { "output", no_argument,       NULL, 'o' },
        { "format", no_argument,       NULL, 'f' },
        { "count",  required_argument, NULL, 'c' },
        { 0, 0, 0, 0 }
};

int main(int argc, char **argv)
{
        dev_name = "/dev/video0";

        for (;;) {
                int idx;
                int c;

                c = getopt_long(argc, argv,
                                short_options, long_options, &idx);

                if (-1 == c)
                        break;

                switch (c) {
                case 0: /* getopt_long() flag */
                        break;

                case 'd':
                        dev_name = optarg;
                        break;

                case 'h':
                        usage(stdout, argc, argv);
                        exit(EXIT_SUCCESS);

                case 'm':
                        io = IO_METHOD_MMAP;
                        break;

                case 'r':
                        io = IO_METHOD_READ;
                        break;

                case 'u':
                        io = IO_METHOD_USERPTR;
                        break;

                case 'o':
                        out_buf++;
                        break;

                case 'f':
                        force_format++;
                        break;

                case 'c':
                        errno = 0;
                        frame_count = strtol(optarg, NULL, 0);
                        if (errno)
                                errno_exit(optarg);
                        break;

                default:
                        usage(stderr, argc, argv);
                        exit(EXIT_FAILURE);
                }
        }

        open_device();
        init_device();
        start_capturing();
        mainloop();
        stop_capturing();
        uninit_device();
        close_device();
        fprintf(stderr, "\n");
        return 0;
}
```

---

# Defining Colorspaces in V4L2

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> In V4L2 colorspaces are defined by four values. The first is the colorspace identifier (enum v4l2_colorspace) which defines the chromaticities, the default transfer function, the default Y'CbCr encoding and the default quantization method.…

<a id="rst-defining-colorspaces-in-v4l2"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

In V4L2 colorspaces are defined by four values. The first is the colorspace identifier (enum `v4l2_colorspace`) which defines the chromaticities, the default transfer function, the default Y'CbCr encoding and the default quantization method. The second is the transfer function identifier (enum `v4l2_xfer_func`) to specify non-standard transfer functions. The third is the Y'CbCr encoding identifier (enum `v4l2_ycbcr_encoding`) to specify non-standard Y'CbCr encodings and the fourth is the quantization identifier (enum `v4l2_quantization`) to specify non-standard quantization methods. Most of the time only the colorspace field of struct `v4l2_pix_format` or struct `v4l2_pix_format_mplane` needs to be filled in.

<a id="rst-hsv-colorspace"></a>

On [HSV formats](</kernel/userspace/userspace-api/media-v4l/hsv-formats.md#rst-hsv-formats>) the *Hue* is defined as the angle on the cylindrical color representation. Usually this angle is measured in degrees, i.e. 0-360. When we map this angle value into 8 bits, there are two basic ways to do it: Divide the angular value by 2 (0-179), or use the whole range, 0-255, dividing the angular value by 1.41. The enum `v4l2_hsv_encoding` specifies which encoding is used.

> [!NOTE]
>
> The default R'G'B' quantization is full range for all colorspaces. HSV formats are always full range.

<!-- tabularcolumns: |p{6.7cm}|p{10.8cm}| -->





<a id="c-v4l2_colorspace"></a>

```c
v4l2_colorspace
```


<table>
<caption>V4L2 Colorspaces</caption>
<thead>
<tr>
<th>


Identifier

</th>
<th>


Details

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`V4L2_COLORSPACE_DEFAULT`

</td>
<td>


The default colorspace. This can be used by applications to let the driver fill in the colorspace.

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_SMPTE170M`

</td>
<td>


See [col-smpte-170m](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_REC709`

</td>
<td>


See [col-rec709](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_SRGB`

</td>
<td>


See [col-srgb](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_OPRGB`

</td>
<td>


See [col-oprgb](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_BT2020`

</td>
<td>


See [col-bt2020](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_DCI_P3`

</td>
<td>


See [col-dcip3](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_SMPTE240M`

</td>
<td>


See [col-smpte-240m](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_470_SYSTEM_M`

</td>
<td>


See [col-sysm](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_470_SYSTEM_BG`

</td>
<td>


See [col-sysbg](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_JPEG`

</td>
<td>


See [col-jpeg](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


`V4L2_COLORSPACE_RAW`

</td>
<td>


The raw colorspace. This is used for raw image capture where the image is minimally processed and is using the internal colorspace of the device. The software that processes an image using this 'colorspace' will have to know the internals of the capture device.

</td>
</tr>
</tbody>
</table>





<a id="c-v4l2_xfer_func"></a>

```c
v4l2_xfer_func
```

<!-- tabularcolumns: |p{5.5cm}|p{12.0cm}| -->


<table>
<caption>V4L2 Transfer Function</caption>
<thead>
<tr>
<th>


Identifier

</th>
<th>


Details

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`V4L2_XFER_FUNC_DEFAULT`

</td>
<td>


Use the default transfer function as defined by the colorspace.

</td>
</tr>
<tr>
<td>


`V4L2_XFER_FUNC_709`

</td>
<td>


Use the Rec. 709 transfer function.

</td>
</tr>
<tr>
<td>


`V4L2_XFER_FUNC_SRGB`

</td>
<td>


Use the sRGB transfer function.

</td>
</tr>
<tr>
<td>


`V4L2_XFER_FUNC_OPRGB`

</td>
<td>


Use the opRGB transfer function.

</td>
</tr>
<tr>
<td>


`V4L2_XFER_FUNC_SMPTE240M`

</td>
<td>


Use the SMPTE 240M transfer function.

</td>
</tr>
<tr>
<td>


`V4L2_XFER_FUNC_NONE`

</td>
<td>


Do not use a transfer function (i.e. use linear RGB values).

</td>
</tr>
<tr>
<td>


`V4L2_XFER_FUNC_DCI_P3`

</td>
<td>


Use the DCI-P3 transfer function.

</td>
</tr>
<tr>
<td>


`V4L2_XFER_FUNC_SMPTE2084`

</td>
<td>


Use the SMPTE 2084 transfer function. See [xf-smpte-2084](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
</tbody>
</table>





<a id="c-v4l2_ycbcr_encoding"></a>

```c
v4l2_ycbcr_encoding
```

<!-- tabularcolumns: |p{7.2cm}|p{10.3cm}| -->


<table>
<caption>V4L2 Y&#x27;CbCr Encodings</caption>
<thead>
<tr>
<th>


Identifier

</th>
<th>


Details

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`V4L2_YCBCR_ENC_DEFAULT`

</td>
<td>


Use the default Y'CbCr encoding as defined by the colorspace.

</td>
</tr>
<tr>
<td>


`V4L2_YCBCR_ENC_601`

</td>
<td>


Use the BT.601 Y'CbCr encoding.

</td>
</tr>
<tr>
<td>


`V4L2_YCBCR_ENC_709`

</td>
<td>


Use the Rec. 709 Y'CbCr encoding.

</td>
</tr>
<tr>
<td>


`V4L2_YCBCR_ENC_XV601`

</td>
<td>


Use the extended gamut xvYCC BT.601 encoding.

</td>
</tr>
<tr>
<td>


`V4L2_YCBCR_ENC_XV709`

</td>
<td>


Use the extended gamut xvYCC Rec. 709 encoding.

</td>
</tr>
<tr>
<td>


`V4L2_YCBCR_ENC_BT2020`

</td>
<td>


Use the default non-constant luminance BT.2020 Y'CbCr encoding.

</td>
</tr>
<tr>
<td>


`V4L2_YCBCR_ENC_BT2020_CONST_LUM`

</td>
<td>


Use the constant luminance BT.2020 Yc'CbcCrc encoding.

</td>
</tr>
<tr>
<td>


`V4L2_YCBCR_ENC_SMPTE_240M`

</td>
<td>


Use the SMPTE 240M Y'CbCr encoding.

</td>
</tr>
</tbody>
</table>





<a id="c-v4l2_hsv_encoding"></a>

```c
v4l2_hsv_encoding
```

<!-- tabularcolumns: |p{6.5cm}|p{11.0cm}| -->


<table>
<caption>V4L2 HSV Encodings</caption>
<thead>
<tr>
<th>


Identifier

</th>
<th>


Details

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`V4L2_HSV_ENC_180`

</td>
<td>


For the Hue, each LSB is two degrees.

</td>
</tr>
<tr>
<td>


`V4L2_HSV_ENC_256`

</td>
<td>


For the Hue, the 360 degrees are mapped into 8 bits, i.e. each LSB is roughly 1.41 degrees.

</td>
</tr>
</tbody>
</table>





<a id="c-v4l2_quantization"></a>

```c
v4l2_quantization
```

<!-- tabularcolumns: |p{6.5cm}|p{11.0cm}| -->


<table>
<caption>V4L2 Quantization Methods</caption>
<thead>
<tr>
<th>


Identifier

</th>
<th>


Details

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`V4L2_QUANTIZATION_DEFAULT`

</td>
<td>


Use the default quantization encoding as defined by the colorspace. This is always full range for R'G'B' and HSV. It is usually limited range for Y'CbCr.

</td>
</tr>
<tr>
<td>


`V4L2_QUANTIZATION_FULL_RANGE`

</td>
<td>


Use the full range quantization encoding. I.e. the range \[0…1\] is mapped to \[0…255\] (with possible clipping to \[1…254\] to avoid the 0x00 and 0xff values). Cb and Cr are mapped from \[-0.5…0.5\] to \[0…255\] (with possible clipping to \[1…254\] to avoid the 0x00 and 0xff values).

</td>
</tr>
<tr>
<td>


`V4L2_QUANTIZATION_LIM_RANGE`

</td>
<td>


Use the limited range quantization encoding. I.e. the range \[0…1\] is mapped to \[16…235\]. Cb and Cr are mapped from \[-0.5…0.5\] to \[16…240\]. Limited Range cannot be used with HSV.

</td>
</tr>
</tbody>
</table>

---

# Detailed Colorspace Descriptions

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The smpte170m standard defines the colorspace used by NTSC and PAL and by SDTV in general. The default transfer function is V4L2_XFER_FUNC_709. The default Y'CbCr encoding is V4L2_YCBCR_ENC_601. The default Y'CbCr quantization is limited…

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-detailed-colorspace-descriptions"></a>

## Detailed Colorspace Descriptions

<a id="rst-colorspace-smpte-170m-v4l2-colorspace-smpte170m"></a>
<a id="rst-col-smpte-170m"></a>

### Colorspace SMPTE 170M (V4L2\_COLORSPACE\_SMPTE170M)

The [smpte170m](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-smpte170m>) standard defines the colorspace used by NTSC and PAL and by SDTV in general. The default transfer function is `V4L2_XFER_FUNC_709`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_601`. The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the white reference are:


<table>
<caption>

SMPTE 170M Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.630

</td>
<td>



0.340

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.310

</td>
<td>



0.595

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.155

</td>
<td>



0.070

</td>
</tr>
<tr>
<td>



White Reference (D65)

</td>
<td>



0.3127

</td>
<td>



0.3290

</td>
</tr>
</tbody>
</table>

The red, green and blue chromaticities are also often referred to as the SMPTE C set, so this colorspace is sometimes called SMPTE C as well.

The transfer function defined for SMPTE 170M is the same as the one defined in Rec. 709.

```math
L' = -1.099(-L)^{0.45} + 0.099 \text{, for } L \le-0.018
```

```math
L' = 4.5L \text{, for } -0.018 < L < 0.018
```

```math
L' = 1.099L^{0.45} - 0.099 \text{, for } L \ge 0.018
```

Inverse Transfer function:

```math
L = -\left( \frac{L' - 0.099}{-1.099} \right) ^{\frac{1}{0.45}} \text{, for } L' \le -0.081
```

```math
L = \frac{L'}{4.5} \text{, for } -0.081 < L' < 0.081
```

```math
L = \left(\frac{L' + 0.099}{1.099}\right)^{\frac{1}{0.45} } \text{, for } L' \ge 0.081
```

The luminance (Y') and color difference (Cb and Cr) are obtained with the following `V4L2_YCBCR_ENC_601` encoding:

```math
Y' = 0.2990R' + 0.5870G' + 0.1140B'
```

```math
Cb = -0.1687R' - 0.3313G' + 0.5B'
```

```math
Cr = 0.5R' - 0.4187G' - 0.0813B'
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\]. This conversion to Y'CbCr is identical to the one defined in the [itu601](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu601>) standard and this colorspace is sometimes called BT.601 as well, even though BT.601 does not mention any color primaries.

The default quantization is limited range, but full range is possible although rarely seen.

<a id="rst-colorspace-rec-709-v4l2-colorspace-rec709"></a>
<a id="rst-col-rec709"></a>

### Colorspace Rec. 709 (V4L2\_COLORSPACE\_REC709)

The [itu709](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu709>) standard defines the colorspace used by HDTV in general. The default transfer function is `V4L2_XFER_FUNC_709`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_709`. The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the white reference are:


<table>
<caption>

Rec. 709 Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.640

</td>
<td>



0.330

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.300

</td>
<td>



0.600

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.150

</td>
<td>



0.060

</td>
</tr>
<tr>
<td>



White Reference (D65)

</td>
<td>



0.3127

</td>
<td>



0.3290

</td>
</tr>
</tbody>
</table>

The full name of this standard is Rec. ITU-R BT.709-5.

Transfer function. Normally L is in the range \[0…1\], but for the extended gamut xvYCC encoding values outside that range are allowed.

```math
L' = -1.099(-L)^{0.45} + 0.099 \text{, for } L \le -0.018
```

```math
L' = 4.5L \text{, for } -0.018 < L < 0.018
```

```math
L' = 1.099L^{0.45} - 0.099 \text{, for } L \ge 0.018
```

Inverse Transfer function:

```math
L = -\left( \frac{L' - 0.099}{-1.099} \right)^\frac{1}{0.45} \text{, for } L' \le -0.081
```

```math
L = \frac{L'}{4.5}\text{, for } -0.081 < L' < 0.081
```

```math
L = \left(\frac{L' + 0.099}{1.099}\right)^{\frac{1}{0.45} } \text{, for } L' \ge 0.081
```

The luminance (Y') and color difference (Cb and Cr) are obtained with the following `V4L2_YCBCR_ENC_709` encoding:

```math
Y' = 0.2126R' + 0.7152G' + 0.0722B'
```

```math
Cb = -0.1146R' - 0.3854G' + 0.5B'
```

```math
Cr = 0.5R' - 0.4542G' - 0.0458B'
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\].

The default quantization is limited range, but full range is possible although rarely seen.

The `V4L2_YCBCR_ENC_709` encoding described above is the default for this colorspace, but it can be overridden with `V4L2_YCBCR_ENC_601`, in which case the BT.601 Y'CbCr encoding is used.

Two additional extended gamut Y'CbCr encodings are also possible with this colorspace:

The xvYCC 709 encoding (`V4L2_YCBCR_ENC_XV709`, [xvycc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-xvycc-1>)) is similar to the Rec. 709 encoding, but it allows for R', G' and B' values that are outside the range \[0…1\]. The resulting Y', Cb and Cr values are scaled and offset according to the limited range formula:

```math
Y' = \frac{219}{256} * (0.2126R' + 0.7152G' + 0.0722B') + \frac{16}{256}
```

```math
Cb = \frac{224}{256} * (-0.1146R' - 0.3854G' + 0.5B')
```

```math
Cr = \frac{224}{256} * (0.5R' - 0.4542G' - 0.0458B')
```

The xvYCC 601 encoding (`V4L2_YCBCR_ENC_XV601`, [xvycc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-xvycc-1>)) is similar to the BT.601 encoding, but it allows for R', G' and B' values that are outside the range \[0…1\]. The resulting Y', Cb and Cr values are scaled and offset according to the limited range formula:

```math
Y' = \frac{219}{256} * (0.2990R' + 0.5870G' + 0.1140B') + \frac{16}{256}
```

```math
Cb = \frac{224}{256} * (-0.1687R' - 0.3313G' + 0.5B')
```

```math
Cr = \frac{224}{256} * (0.5R' - 0.4187G' - 0.0813B')
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\] and quantized without further scaling or offsets. The non-standard xvYCC 709 or xvYCC 601 encodings can be used by selecting `V4L2_YCBCR_ENC_XV709` or `V4L2_YCBCR_ENC_XV601`. As seen by the xvYCC formulas these encodings always use limited range quantization, there is no full range variant. The whole point of these extended gamut encodings is that values outside the limited range are still valid, although they map to R', G' and B' values outside the \[0…1\] range and are therefore outside the Rec. 709 colorspace gamut.

<a id="rst-colorspace-srgb-v4l2-colorspace-srgb"></a>
<a id="rst-col-srgb"></a>

### Colorspace sRGB (V4L2\_COLORSPACE\_SRGB)

The [srgb](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-srgb-1>) standard defines the colorspace used by most webcams and computer graphics. The default transfer function is `V4L2_XFER_FUNC_SRGB`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_601`. The default Y'CbCr quantization is limited range.

Note that the [sycc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-sycc-1>) standard specifies full range quantization, however all current capture hardware supported by the kernel convert R'G'B' to limited range Y'CbCr. So choosing full range as the default would break how applications interpret the quantization range.

The chromaticities of the primary colors and the white reference are:


<table>
<caption>

sRGB Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.640

</td>
<td>



0.330

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.300

</td>
<td>



0.600

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.150

</td>
<td>



0.060

</td>
</tr>
<tr>
<td>



White Reference (D65)

</td>
<td>



0.3127

</td>
<td>



0.3290

</td>
</tr>
</tbody>
</table>

These chromaticities are identical to the Rec. 709 colorspace.

Transfer function. Note that negative values for L are only used by the Y'CbCr conversion.

```math
L' = -1.055(-L)^{\frac{1}{2.4} } + 0.055\text{, for }L < -0.0031308
```

```math
L' = 12.92L\text{, for }-0.0031308 \le L \le 0.0031308
```

```math
L' = 1.055L ^{\frac{1}{2.4} } - 0.055\text{, for }0.0031308 < L \le 1
```

Inverse Transfer function:

```math
L = -((-L' + 0.055) / 1.055) ^{2.4}\text{, for }L' < -0.04045
```

```math
L = L' / 12.92\text{, for }-0.04045 \le L' \le 0.04045
```

```math
L = ((L' + 0.055) / 1.055) ^{2.4}\text{, for }L' > 0.04045
```

The luminance (Y') and color difference (Cb and Cr) are obtained with the following `V4L2_YCBCR_ENC_601` encoding as defined by [sycc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-sycc-1>):

```math
Y' = 0.2990R' + 0.5870G' + 0.1140B'
```

```math
Cb = -0.1687R' - 0.3313G' + 0.5B'
```

```math
Cr = 0.5R' - 0.4187G' - 0.0813B'
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\]. This transform is identical to one defined in SMPTE 170M/BT.601. The Y'CbCr quantization is limited range.

<a id="rst-colorspace-oprgb-v4l2-colorspace-oprgb"></a>
<a id="rst-col-oprgb"></a>

### Colorspace opRGB (V4L2\_COLORSPACE\_OPRGB)

The [oprgb](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-oprgb-1>) standard defines the colorspace used by computer graphics that use the opRGB colorspace. The default transfer function is `V4L2_XFER_FUNC_OPRGB`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_601`. The default Y'CbCr quantization is limited range.

Note that the [oprgb](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-oprgb-1>) standard specifies full range quantization, however all current capture hardware supported by the kernel convert R'G'B' to limited range Y'CbCr. So choosing full range as the default would break how applications interpret the quantization range.

The chromaticities of the primary colors and the white reference are:


<table>
<caption>

opRGB Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.6400

</td>
<td>



0.3300

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.2100

</td>
<td>



0.7100

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.1500

</td>
<td>



0.0600

</td>
</tr>
<tr>
<td>



White Reference (D65)

</td>
<td>



0.3127

</td>
<td>



0.3290

</td>
</tr>
</tbody>
</table>

Transfer function:

```math
L' = L ^{\frac{1}{2.19921875}}
```

Inverse Transfer function:

```math
L = L'^{(2.19921875)}
```

The luminance (Y') and color difference (Cb and Cr) are obtained with the following `V4L2_YCBCR_ENC_601` encoding:

```math
Y' = 0.2990R' + 0.5870G' + 0.1140B'
```

```math
Cb = -0.1687R' - 0.3313G' + 0.5B'
```

```math
Cr = 0.5R' - 0.4187G' - 0.0813B'
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\]. This transform is identical to one defined in SMPTE 170M/BT.601. The Y'CbCr quantization is limited range.

<a id="rst-colorspace-bt-2020-v4l2-colorspace-bt2020"></a>
<a id="rst-col-bt2020"></a>

### Colorspace BT.2020 (V4L2\_COLORSPACE\_BT2020)

The [itu2020](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu2020>) standard defines the colorspace used by Ultra-high definition television (UHDTV). The default transfer function is `V4L2_XFER_FUNC_709`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_BT2020`. The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the white reference are:


<table>
<caption>

BT.2020 Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.708

</td>
<td>



0.292

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.170

</td>
<td>



0.797

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.131

</td>
<td>



0.046

</td>
</tr>
<tr>
<td>



White Reference (D65)

</td>
<td>



0.3127

</td>
<td>



0.3290

</td>
</tr>
</tbody>
</table>

Transfer function (same as Rec. 709):

```math
L' = 4.5L\text{, for }0 \le L < 0.018
```

```math
L' = 1.099L ^{0.45} - 0.099\text{, for } 0.018 \le L \le 1
```

Inverse Transfer function:

```math
L = L' / 4.5\text{, for } L' < 0.081
```

```math
L = \left( \frac{L' + 0.099}{1.099}\right) ^{\frac{1}{0.45} }\text{, for } L' \ge 0.081
```

Please note that while Rec. 709 is defined as the default transfer function by the [itu2020](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu2020>) standard, in practice this colorspace is often used with the [Transfer Function SMPTE 2084 (V4L2\_XFER\_FUNC\_SMPTE2084)](<#rst-xf-smpte-2084>). In particular Ultra HD Blu-ray discs use this combination.

The luminance (Y') and color difference (Cb and Cr) are obtained with the following `V4L2_YCBCR_ENC_BT2020` encoding:

```math
Y' = 0.2627R' + 0.6780G' + 0.0593B'
```

```math
Cb = -0.1396R' - 0.3604G' + 0.5B'
```

```math
Cr = 0.5R' - 0.4598G' - 0.0402B'
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\]. The Y'CbCr quantization is limited range.

There is also an alternate constant luminance R'G'B' to Yc'CbcCrc (`V4L2_YCBCR_ENC_BT2020_CONST_LUM`) encoding:

Luma:

```math
\begin{align*}
Yc' = (0.2627R + 0.6780G + 0.0593B)'& \\
B' - Yc' \le 0:& \\
    &Cbc = (B' - Yc') / 1.9404 \\
B' - Yc' > 0: & \\
    &Cbc = (B' - Yc') / 1.5816 \\
R' - Yc' \le 0:& \\
    &Crc = (R' - Y') / 1.7184 \\
R' - Yc' > 0:& \\
    &Crc = (R' - Y') / 0.9936
\end{align*}
```

Yc' is clamped to the range \[0…1\] and Cbc and Crc are clamped to the range \[-0.5…0.5\]. The Yc'CbcCrc quantization is limited range.

<a id="rst-colorspace-dci-p3-v4l2-colorspace-dci-p3"></a>
<a id="rst-col-dcip3"></a>

### Colorspace DCI-P3 (V4L2\_COLORSPACE\_DCI\_P3)

The [smpte431](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-smpte431>) standard defines the colorspace used by cinema projectors that use the DCI-P3 colorspace. The default transfer function is `V4L2_XFER_FUNC_DCI_P3`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_709`. The default Y'CbCr quantization is limited range.

> [!NOTE]
>
> Note that this colorspace standard does not specify a Y'CbCr encoding since it is not meant to be encoded to Y'CbCr. So this default Y'CbCr encoding was picked because it is the HDTV encoding.

The chromaticities of the primary colors and the white reference are:


<table>
<caption>

DCI-P3 Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.6800

</td>
<td>



0.3200

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.2650

</td>
<td>



0.6900

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.1500

</td>
<td>



0.0600

</td>
</tr>
<tr>
<td>



White Reference

</td>
<td>



0.3140

</td>
<td>



0.3510

</td>
</tr>
</tbody>
</table>

Transfer function:

```math
L' = L^{\frac{1}{2.6}}
```

Inverse Transfer function:

```math
L = L'^{(2.6)}
```

Y'CbCr encoding is not specified. V4L2 defaults to Rec. 709.

<a id="rst-colorspace-smpte-240m-v4l2-colorspace-smpte240m"></a>
<a id="rst-col-smpte-240m"></a>

### Colorspace SMPTE 240M (V4L2\_COLORSPACE\_SMPTE240M)

The [smpte240m](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-smpte240m>) standard was an interim standard used during the early days of HDTV (1988-1998). It has been superseded by Rec. 709. The default transfer function is `V4L2_XFER_FUNC_SMPTE240M`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_SMPTE240M`. The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the white reference are:


<table>
<caption>

SMPTE 240M Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.630

</td>
<td>



0.340

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.310

</td>
<td>



0.595

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.155

</td>
<td>



0.070

</td>
</tr>
<tr>
<td>



White Reference (D65)

</td>
<td>



0.3127

</td>
<td>



0.3290

</td>
</tr>
</tbody>
</table>

These chromaticities are identical to the SMPTE 170M colorspace.

Transfer function:

```math
L' = 4L\text{, for } 0 \le L < 0.0228
```

```math
L' = 1.1115L ^{0.45} - 0.1115\text{, for } 0.0228 \le L \le 1
```

Inverse Transfer function:

```math
L = \frac{L'}{4}\text{, for } 0 \le L' < 0.0913
```

```math
L = \left( \frac{L' + 0.1115}{1.1115}\right) ^{\frac{1}{0.45} }\text{, for } L' \ge 0.0913
```

The luminance (Y') and color difference (Cb and Cr) are obtained with the following `V4L2_YCBCR_ENC_SMPTE240M` encoding:

```math
Y' = 0.2122R' + 0.7013G' + 0.0865B'
```

```math
Cb = -0.1161R' - 0.3839G' + 0.5B'
```

```math
Cr = 0.5R' - 0.4451G' - 0.0549B'
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\]. The Y'CbCr quantization is limited range.

<a id="rst-colorspace-ntsc-1953-v4l2-colorspace-470-system-m"></a>
<a id="rst-col-sysm"></a>

### Colorspace NTSC 1953 (V4L2\_COLORSPACE\_470\_SYSTEM\_M)

This standard defines the colorspace used by NTSC in 1953. In practice this colorspace is obsolete and SMPTE 170M should be used instead. The default transfer function is `V4L2_XFER_FUNC_709`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_601`. The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the white reference are:


<table>
<caption>

NTSC 1953 Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.67

</td>
<td>



0.33

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.21

</td>
<td>



0.71

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.14

</td>
<td>



0.08

</td>
</tr>
<tr>
<td>



White Reference (C)

</td>
<td>



0.310

</td>
<td>



0.316

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> This colorspace uses Illuminant C instead of D65 as the white reference. To correctly convert an image in this colorspace to another that uses D65 you need to apply a chromatic adaptation algorithm such as the Bradford method.

The transfer function was never properly defined for NTSC 1953. The Rec. 709 transfer function is recommended in the literature:

```math
L' = 4.5L\text{, for } 0 \le L < 0.018
```

```math
L' = 1.099L ^{0.45} - 0.099\text{, for } 0.018 \le L \le 1
```

Inverse Transfer function:

```math
L = \frac{L'}{4.5} \text{, for } L' < 0.081
```

```math
L = \left( \frac{L' + 0.099}{1.099}\right) ^{\frac{1}{0.45} }\text{, for } L' \ge 0.081
```

The luminance (Y') and color difference (Cb and Cr) are obtained with the following `V4L2_YCBCR_ENC_601` encoding:

```math
Y' = 0.2990R' + 0.5870G' + 0.1140B'
```

```math
Cb = -0.1687R' - 0.3313G' + 0.5B'
```

```math
Cr = 0.5R' - 0.4187G' - 0.0813B'
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\]. The Y'CbCr quantization is limited range. This transform is identical to one defined in SMPTE 170M/BT.601.

<a id="rst-colorspace-ebu-tech-3213-v4l2-colorspace-470-system-bg"></a>
<a id="rst-col-sysbg"></a>

### Colorspace EBU Tech. 3213 (V4L2\_COLORSPACE\_470\_SYSTEM\_BG)

The [tech3213](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-tech3213>) standard defines the colorspace used by PAL/SECAM in 1975. Note that this colorspace is not supported by the HDMI interface. Instead [tech3321](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-tech3321>) recommends that Rec. 709 is used instead for HDMI. The default transfer function is `V4L2_XFER_FUNC_709`. The default Y'CbCr encoding is `V4L2_YCBCR_ENC_601`. The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the white reference are:


<table>
<caption>

EBU Tech. 3213 Chromaticities

</caption>
<thead>
<tr>
<th>



Color

</th>
<th>



x

</th>
<th>



y

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Red

</td>
<td>



0.64

</td>
<td>



0.33

</td>
</tr>
<tr>
<td>



Green

</td>
<td>



0.29

</td>
<td>



0.60

</td>
</tr>
<tr>
<td>



Blue

</td>
<td>



0.15

</td>
<td>



0.06

</td>
</tr>
<tr>
<td>



White Reference (D65)

</td>
<td>



0.3127

</td>
<td>



0.3290

</td>
</tr>
</tbody>
</table>

The transfer function was never properly defined for this colorspace. The Rec. 709 transfer function is recommended in the literature:

```math
L' = 4.5L\text{, for } 0 \le L < 0.018
```

```math
L' = 1.099L ^{0.45} - 0.099\text{, for } 0.018 \le L \le 1
```

Inverse Transfer function:

```math
L = \frac{L'}{4.5} \text{, for } L' < 0.081
```

```math
L = \left(\frac{L' + 0.099}{1.099} \right) ^{\frac{1}{0.45} }\text{, for } L' \ge 0.081
```

The luminance (Y') and color difference (Cb and Cr) are obtained with the following `V4L2_YCBCR_ENC_601` encoding:

```math
Y' = 0.2990R' + 0.5870G' + 0.1140B'
```

```math
Cb = -0.1687R' - 0.3313G' + 0.5B'
```

```math
Cr = 0.5R' - 0.4187G' - 0.0813B'
```

Y' is clamped to the range \[0…1\] and Cb and Cr are clamped to the range \[-0.5…0.5\]. The Y'CbCr quantization is limited range. This transform is identical to one defined in SMPTE 170M/BT.601.

<a id="rst-colorspace-jpeg-v4l2-colorspace-jpeg"></a>
<a id="rst-col-jpeg"></a>

### Colorspace JPEG (V4L2\_COLORSPACE\_JPEG)

This colorspace defines the colorspace used by most (Motion-)JPEG formats. The chromaticities of the primary colors and the white reference are identical to sRGB. The transfer function use is `V4L2_XFER_FUNC_SRGB`. The Y'CbCr encoding is `V4L2_YCBCR_ENC_601` with full range quantization where Y' is scaled to \[0…255\] and Cb/Cr are scaled to \[-128…128\] and then clipped to \[-128…127\].

> [!NOTE]
>
> The JPEG standard does not actually store colorspace information. So if something other than sRGB is used, then the driver will have to set that information explicitly. Effectively `V4L2_COLORSPACE_JPEG` can be considered to be an abbreviation for `V4L2_COLORSPACE_SRGB`, `V4L2_XFER_FUNC_SRGB`, `V4L2_YCBCR_ENC_601` and `V4L2_QUANTIZATION_FULL_RANGE`.

<a id="rst-detailed-transfer-function-descriptions"></a>

## Detailed Transfer Function Descriptions

<a id="rst-transfer-function-smpte-2084-v4l2-xfer-func-smpte2084"></a>
<a id="rst-xf-smpte-2084"></a>

### Transfer Function SMPTE 2084 (V4L2\_XFER\_FUNC\_SMPTE2084)

The [smpte2084](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-smpte2084>) standard defines the transfer function used by High Dynamic Range content.

- **Constants:**

  m1 = (2610 / 4096) / 4

  m2 = (2523 / 4096) \* 128

  c1 = 3424 / 4096

  c2 = (2413 / 4096) \* 32

  c3 = (2392 / 4096) \* 32

- **Transfer function:**

  L' = ((c1 + c2 \* L<sup>m1</sup>) / (1 + c3 \* L<sup>m1</sup>))<sup>m2</sup>

- **Inverse Transfer function:**

  L = (max(L'<sup>1/m2</sup> - c1, 0) / (c2 - c3 \* L'<sup>1/m2</sup>))<sup>1/m1</sup>

Take care when converting between this transfer function and non-HDR transfer functions: the linear RGB values \[0…1\] of HDR content map to a luminance range of 0 to 10000 cd/m<sup>2</sup> whereas the linear RGB values of non-HDR (aka Standard Dynamic Range or SDR) map to a luminance range of 0 to 100 cd/m<sup>2</sup>.

To go from SDR to HDR you will have to divide L by 100 first. To go in the other direction you will have to multiply L by 100. Of course, this clamps all luminance values over 100 cd/m<sup>2</sup> to 100 cd/m<sup>2</sup>.

There are better methods, see e.g. [colimg](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-colimg-1>) for more in-depth information about this.

---

# Colorspaces

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Duplicate implicit target name: "colorspaces".

<a id="rst-colorspaces-1"></a>
<a id="rst-colorspaces"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

'Color' is a very complex concept and depends on physics, chemistry and biology. Just because you have three numbers that describe the 'red', 'green' and 'blue' components of the color of a pixel does not mean that you can accurately display that color. A colorspace defines what it actually *means* to have an RGB value of e.g. (255, 0, 0). That is, which color should be reproduced on the screen in a perfectly calibrated environment.

In order to do that we first need to have a good definition of color, i.e. some way to uniquely and unambiguously define a color so that someone else can reproduce it. Human color vision is trichromatic since the human eye has color receptors that are sensitive to three different wavelengths of light. Hence the need to use three numbers to describe color. Be glad you are not a mantis shrimp as those are sensitive to 12 different wavelengths, so instead of RGB we would be using the ABCDEFGHIJKL colorspace...

Color exists only in the eye and brain and is the result of how strongly color receptors are stimulated. This is based on the Spectral Power Distribution (SPD) which is a graph showing the intensity (radiant power) of the light at wavelengths covering the visible spectrum as it enters the eye. The science of colorimetry is about the relationship between the SPD and color as perceived by the human brain.

Since the human eye has only three color receptors it is perfectly possible that different SPDs will result in the same stimulation of those receptors and are perceived as the same color, even though the SPD of the light is different.

In the 1920s experiments were devised to determine the relationship between SPDs and the perceived color and that resulted in the CIE 1931 standard that defines spectral weighting functions that model the perception of color. Specifically that standard defines functions that can take an SPD and calculate the stimulus for each color receptor. After some further mathematical transforms these stimuli are known as the *CIE XYZ tristimulus* values and these X, Y and Z values describe a color as perceived by a human unambiguously. These X, Y and Z values are all in the range \[0…1\].

The Y value in the CIE XYZ colorspace corresponds to luminance. Often the CIE XYZ colorspace is transformed to the normalized CIE xyY colorspace:

> x = X / (X + Y + Z)
>
> y = Y / (X + Y + Z)

The x and y values are the chromaticity coordinates and can be used to define a color without the luminance component Y. It is very confusing to have such similar names for these colorspaces. Just be aware that if colors are specified with lower case 'x' and 'y', then the CIE xyY colorspace is used. Upper case 'X' and 'Y' refer to the CIE XYZ colorspace. Also, y has nothing to do with luminance. Together x and y specify a color, and Y the luminance. That is really all you need to remember from a practical point of view. At the end of this section you will find reading resources that go into much more detail if you are interested.

A monitor or TV will reproduce colors by emitting light at three different wavelengths, the combination of which will stimulate the color receptors in the eye and thus cause the perception of color. Historically these wavelengths were defined by the red, green and blue phosphors used in the displays. These *color primaries* are part of what defines a colorspace.

Different display devices will have different primaries and some primaries are more suitable for some display technologies than others. This has resulted in a variety of colorspaces that are used for different display technologies or uses. To define a colorspace you need to define the three color primaries (these are typically defined as x, y chromaticity coordinates from the CIE xyY colorspace) but also the white reference: that is the color obtained when all three primaries are at maximum power. This determines the relative power or energy of the primaries. This is usually chosen to be close to daylight which has been defined as the CIE D65 Illuminant.

To recapitulate: the CIE XYZ colorspace uniquely identifies colors. Other colorspaces are defined by three chromaticity coordinates defined in the CIE xyY colorspace. Based on those a 3x3 matrix can be constructed that transforms CIE XYZ colors to colors in the new colorspace.

Both the CIE XYZ and the RGB colorspace that are derived from the specific chromaticity primaries are linear colorspaces. But neither the eye, nor display technology is linear. Doubling the values of all components in the linear colorspace will not be perceived as twice the intensity of the color. So each colorspace also defines a transfer function that takes a linear color component value and transforms it to the non-linear component value, which is a closer match to the non-linear performance of both the eye and displays. Linear component values are denoted RGB, non-linear are denoted as R'G'B'. In general colors used in graphics are all R'G'B', except in openGL which uses linear RGB. Special care should be taken when dealing with openGL to provide linear RGB colors or to use the built-in openGL support to apply the inverse transfer function.

The final piece that defines a colorspace is a function that transforms non-linear R'G'B' to non-linear Y'CbCr. This function is determined by the so-called luma coefficients. There may be multiple possible Y'CbCr encodings allowed for the same colorspace. Many encodings of color prefer to use luma (Y') and chroma (CbCr) instead of R'G'B'. Since the human eye is more sensitive to differences in luminance than in color this encoding allows one to reduce the amount of color information compared to the luma data. Note that the luma (Y') is unrelated to the Y in the CIE XYZ colorspace. Also note that Y'CbCr is often called YCbCr or YUV even though these are strictly speaking wrong.

Sometimes people confuse Y'CbCr as being a colorspace. This is not correct, it is just an encoding of an R'G'B' color into luma and chroma values. The underlying colorspace that is associated with the R'G'B' color is also associated with the Y'CbCr color.

The final step is how the RGB, R'G'B' or Y'CbCr values are quantized. The CIE XYZ colorspace where X, Y and Z are in the range \[0…1\] describes all colors that humans can perceive, but the transform to another colorspace will produce colors that are outside the \[0…1\] range. Once clamped to the \[0…1\] range those colors can no longer be reproduced in that colorspace. This clamping is what reduces the extent or gamut of the colorspace. How the range of \[0…1\] is translated to integer values in the range of \[0…255\] (or higher, depending on the color depth) is called the quantization. This is *not* part of the colorspace definition. In practice RGB or R'G'B' values are full range, i.e. they use the full \[0…255\] range. Y'CbCr values on the other hand are limited range with Y' using \[16…235\] and Cb and Cr using \[16…240\].

Unfortunately, in some cases limited range RGB is also used where the components use the range \[16…235\]. And full range Y'CbCr also exists using the \[0…255\] range.

In order to correctly interpret a color you need to know the quantization range, whether it is R'G'B' or Y'CbCr, the used Y'CbCr encoding and the colorspace. From that information you can calculate the corresponding CIE XYZ color and map that again to whatever colorspace your display device uses.

The colorspace definition itself consists of the three chromaticity primaries, the white reference chromaticity, a transfer function and the luma coefficients needed to transform R'G'B' to Y'CbCr. While some colorspace standards correctly define all four, quite often the colorspace standard only defines some, and you have to rely on other standards for the missing pieces. The fact that colorspaces are often a mix of different standards also led to very confusing naming conventions where the name of a standard was used to name a colorspace when in fact that standard was part of various other colorspaces as well.

If you want to read more about colors and colorspaces, then the following resources are useful: [poynton](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-poynton-1>) is a good practical book for video engineers, [colimg](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-colimg-1>) has a much broader scope and describes many more aspects of color (physics, chemistry, biology, etc.). The [http://www.brucelindbloom.com](<http://www.brucelindbloom.com>) website is an excellent resource, especially with respect to the mathematics behind colorspace conversions. The wikipedia [CIE 1931 colorspace](<http://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space>) article is also very useful.

---

# Common definitions for V4L2 and V4L2 subdev interfaces

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Common definitions for V4L2 and V4L2 subdev interfaces.

<a id="rst-common-definitions-for-v4l2-and-v4l2-subdev-interfaces"></a>
<a id="rst-common-defs"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

- [Common selection definitions](</kernel/userspace/userspace-api/media-v4l/selections-common.md>)

---

# Common API Elements

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Programming a V4L2 device consists of these steps:

<a id="rst-common-api-elements"></a>
<a id="rst-common"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Programming a V4L2 device consists of these steps:

- Opening the device

- Changing device properties, selecting a video and audio input, video standard, picture brightness a. o.

- Negotiating a data format

- Negotiating an input/output method

- The actual input/output loop

- Closing the device

In practice most steps are optional and can be executed out of order. It depends on the V4L2 device type, you can read about the details in [Interfaces](</kernel/userspace/userspace-api/media-v4l/devices.md#rst-devices>). In this chapter we will discuss the basic concepts applicable to all devices.

- [Opening and Closing Devices](</kernel/userspace/userspace-api/media-v4l/open.md>)
- [Querying Capabilities](</kernel/userspace/userspace-api/media-v4l/querycap.md>)
- [Application Priority](</kernel/userspace/userspace-api/media-v4l/app-pri.md>)
- [Video Inputs and Outputs](</kernel/userspace/userspace-api/media-v4l/video.md>)
- [Audio Inputs and Outputs](</kernel/userspace/userspace-api/media-v4l/audio.md>)
- [Tuners and Modulators](</kernel/userspace/userspace-api/media-v4l/tuner.md>)
- [Video Standards](</kernel/userspace/userspace-api/media-v4l/standard.md>)
- [Digital Video (DV) Timings](</kernel/userspace/userspace-api/media-v4l/dv-timings.md>)
- [User Controls](</kernel/userspace/userspace-api/media-v4l/control.md>)
- [Extended Controls API](</kernel/userspace/userspace-api/media-v4l/extended-controls.md>)
- [ext-ctrls-camera](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/ext-ctrls-camera.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Flash Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-flash.md>)
- [Image Source Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-image-source.md>)
- [Image Process Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-image-process.md>)
- [ext-ctrls-codec](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ext-ctrls-codec-stateless](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/ext-ctrls-codec-stateless.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [JPEG Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-jpeg.md>)
- [Digital Video Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-dv.md>)
- [RF Tuner Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-rf-tuner.md>)
- [FM Transmitter Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-fm-tx.md>)
- [FM Receiver Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-fm-rx.md>)
- [Detect Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-detect.md>)
- [Colorimetry Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-colorimetry.md>)
- [Guidelines for Video4Linux pixel format 4CCs](</kernel/userspace/userspace-api/media-v4l/fourcc.md>)
- [Data Formats](</kernel/userspace/userspace-api/media-v4l/format.md>)
- [Single- and multi-planar APIs](</kernel/userspace/userspace-api/media-v4l/planar-apis.md>)
- [Cropping, composing and scaling -- the SELECTION API](</kernel/userspace/userspace-api/media-v4l/selection-api.md>)
- [Image Cropping, Insertion and Scaling -- the CROP API](</kernel/userspace/userspace-api/media-v4l/crop.md>)
- [Streaming Parameters](</kernel/userspace/userspace-api/media-v4l/streaming-par.md>)

---

# Changes

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The following chapters document the evolution of the V4L2 API, errata or extensions. They are also intended to help application and driver writers to port or update their code.

<a id="rst-changes"></a>
<a id="rst-compat"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The following chapters document the evolution of the V4L2 API, errata or extensions. They are also intended to help application and driver writers to port or update their code.

- [diff-v4l](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/diff-v4l.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Changes of the V4L2 API](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/hist-v4l2.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

---

# User Controls

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Devices typically have a number of user-settable controls such as brightness, saturation and so on, which would be presented to the user on a graphical user interface. But, different devices will have different controls available, and…

<a id="rst-user-controls"></a>
<a id="rst-control"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Devices typically have a number of user-settable controls such as brightness, saturation and so on, which would be presented to the user on a graphical user interface. But, different devices will have different controls available, and furthermore, the range of possible values, and the default value will vary from device to device. The control ioctls provide the information and a mechanism to create a nice user interface for these controls that will work correctly with any device.

All controls are accessed using an ID value. V4L2 defines several IDs for specific purposes. Drivers can also implement their own custom controls using `V4L2_CID_PRIVATE_BASE`  <a id="rst-footnote-reference-1"></a>[1](#rst-f1) and higher values. The pre-defined control IDs have the prefix `V4L2_CID_`, and are listed in [Control IDs](<#rst-control-id>). The ID is used when querying the attributes of a control, and when getting or setting the current value.

Generally applications should present controls to the user without assumptions about their purpose. Each control comes with a name string the user is supposed to understand. When the purpose is non-intuitive the driver writer should provide a user manual, a user interface plug-in or a driver specific panel application. Predefined IDs were introduced to change a few controls programmatically, for example to mute a device during a channel switch.

Drivers may enumerate different controls after switching the current video input or output, tuner or modulator, or audio input or output. Different in the sense of other bounds, another default and current value, step size or other menu items. A control with a certain *custom* ID can also change name and type.

If a control is not applicable to the current configuration of the device (for example, it doesn't apply to the current video input) drivers set the `V4L2_CTRL_FLAG_INACTIVE` flag.

Control values are stored globally, they do not change when switching except to stay within the reported bounds. They also do not change e. g. when the device is opened or closed, when the tuner radio frequency is changed or generally never without application request.

V4L2 specifies an event mechanism to notify applications when controls change value (see [ioctl VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md#rst-vidioc-subscribe-event>), event `V4L2_EVENT_CTRL`), panel applications might want to make use of that in order to always reflect the correct control value.

All controls use machine endianness.

<a id="rst-control-ids"></a>
<a id="rst-control-id"></a>

## Control IDs

- **`V4L2_CID_BASE`**

  First predefined ID, equal to `V4L2_CID_BRIGHTNESS`.

- **`V4L2_CID_USER_BASE`**

  Synonym of `V4L2_CID_BASE`.

- **`V4L2_CID_BRIGHTNESS` `(integer)`**

  Picture brightness, or more precisely, the black level.

- **`V4L2_CID_CONTRAST` `(integer)`**

  Picture contrast or luma gain.

- **`V4L2_CID_SATURATION` `(integer)`**

  Picture color saturation or chroma gain.

- **`V4L2_CID_HUE` `(integer)`**

  Hue or color balance.

- **`V4L2_CID_AUDIO_VOLUME` `(integer)`**

  Overall audio volume. Note some drivers also provide an OSS or ALSA mixer interface.

- **`V4L2_CID_AUDIO_BALANCE` `(integer)`**

  Audio stereo balance. Minimum corresponds to all the way left, maximum to right.

- **`V4L2_CID_AUDIO_BASS` `(integer)`**

  Audio bass adjustment.

- **`V4L2_CID_AUDIO_TREBLE` `(integer)`**

  Audio treble adjustment.

- **`V4L2_CID_AUDIO_MUTE` `(boolean)`**

  Mute audio, i. e. set the volume to zero, however without affecting `V4L2_CID_AUDIO_VOLUME`. Like ALSA drivers, V4L2 drivers must mute at load time to avoid excessive noise. Actually the entire device should be reset to a low power consumption state.

- **`V4L2_CID_AUDIO_LOUDNESS` `(boolean)`**

  Loudness mode (bass boost).

- **`V4L2_CID_BLACK_LEVEL` `(integer)`**

  Another name for brightness (not a synonym of `V4L2_CID_BRIGHTNESS`). This control is deprecated and should not be used in new drivers and applications.

- **`V4L2_CID_AUTO_WHITE_BALANCE` `(boolean)`**

  Automatic white balance (cameras).

- **`V4L2_CID_DO_WHITE_BALANCE` `(button)`**

  This is an action control. When set (the value is ignored), the device will do a white balance and then hold the current setting. Contrast this with the boolean `V4L2_CID_AUTO_WHITE_BALANCE`, which, when activated, keeps adjusting the white balance.

- **`V4L2_CID_RED_BALANCE` `(integer)`**

  Red chroma balance.

- **`V4L2_CID_BLUE_BALANCE` `(integer)`**

  Blue chroma balance.

- **`V4L2_CID_GAMMA` `(integer)`**

  Gamma adjust.

- **`V4L2_CID_WHITENESS` `(integer)`**

  Whiteness for grey-scale devices. This is a synonym for `V4L2_CID_GAMMA`. This control is deprecated and should not be used in new drivers and applications.

- **`V4L2_CID_EXPOSURE` `(integer)`**

  Exposure (cameras). \[Unit?\]

- **`V4L2_CID_AUTOGAIN` `(boolean)`**

  Automatic gain/exposure control.

- **`V4L2_CID_GAIN` `(integer)`**

  Gain control.

  Primarily used to control gain on e.g. TV tuners but also on webcams. Most devices control only digital gain with this control but on some this could include analogue gain as well. Devices that recognise the difference between digital and analogue gain use controls `V4L2_CID_DIGITAL_GAIN` and `V4L2_CID_ANALOGUE_GAIN`.

<a id="rst-v4l2-cid-hflip"></a>

- **`V4L2_CID_HFLIP` `(boolean)`**

  Mirror the picture horizontally.

<a id="rst-v4l2-cid-vflip"></a>

- **`V4L2_CID_VFLIP` `(boolean)`**

  Mirror the picture vertically.

<a id="rst-v4l2-power-line-frequency"></a>

- **`V4L2_CID_POWER_LINE_FREQUENCY` `(enum)`**

  Enables a power line frequency filter to avoid flicker. Possible values for `enum v4l2_power_line_frequency` are:


  <table>
  <tbody>
  <tr>
  <td>


  `V4L2_CID_POWER_LINE_FREQUENCY_DISABLED`

  </td>
  <td>


  0

  </td>
  </tr>
  <tr>
  <td>


  `V4L2_CID_POWER_LINE_FREQUENCY_50HZ`

  </td>
  <td>


  1

  </td>
  </tr>
  <tr>
  <td>


  `V4L2_CID_POWER_LINE_FREQUENCY_60HZ`

  </td>
  <td>


  2

  </td>
  </tr>
  <tr>
  <td>


  `V4L2_CID_POWER_LINE_FREQUENCY_AUTO`

  </td>
  <td>


  3

  </td>
  </tr>
  </tbody>
  </table>

- **`V4L2_CID_HUE_AUTO` `(boolean)`**

  Enables automatic hue control by the device. The effect of setting `V4L2_CID_HUE` while automatic hue control is enabled is undefined, drivers should ignore such request.

- **`V4L2_CID_WHITE_BALANCE_TEMPERATURE` `(integer)`**

  This control specifies the white balance settings as a color temperature in Kelvin. A driver should have a minimum of 2800 (incandescent) to 6500 (daylight). For more information about color temperature see [Wikipedia](<http://en.wikipedia.org/wiki/Color_temperature>).

- **`V4L2_CID_SHARPNESS` `(integer)`**

  Adjusts the sharpness filters in a camera. The minimum value disables the filters, higher values give a sharper picture.

- **`V4L2_CID_BACKLIGHT_COMPENSATION` `(integer)`**

  Adjusts the backlight compensation in a camera. The minimum value disables backlight compensation.

- **`V4L2_CID_CHROMA_AGC` `(boolean)`**

  Chroma automatic gain control.

- **`V4L2_CID_CHROMA_GAIN` `(integer)`**

  Adjusts the Chroma gain control (for use when chroma AGC is disabled).

- **`V4L2_CID_COLOR_KILLER` `(boolean)`**

  Enable the color killer (i. e. force a black &amp; white image in case of a weak video signal).

<a id="rst-v4l2-colorfx"></a>

- **`V4L2_CID_COLORFX` `(enum)`**

  Selects a color effect. The following values are defined:

<!-- tabularcolumns: |p{5.7cm}|p{11.8cm}| -->


<table>
<tbody>
<tr>
<td>


`V4L2_COLORFX_NONE`

</td>
<td>


Color effect is disabled.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_ANTIQUE`

</td>
<td>


An aging (old photo) effect.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_ART_FREEZE`

</td>
<td>


Frost color effect.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_AQUA`

</td>
<td>


Water color, cool tone.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_BW`

</td>
<td>


Black and white.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_EMBOSS`

</td>
<td>


Emboss, the highlights and shadows replace light/dark boundaries and low contrast areas are set to a gray background.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_GRASS_GREEN`

</td>
<td>


Grass green.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_NEGATIVE`

</td>
<td>


Negative.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_SEPIA`

</td>
<td>


Sepia tone.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_SKETCH`

</td>
<td>


Sketch.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_SKIN_WHITEN`

</td>
<td>


Skin whiten.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_SKY_BLUE`

</td>
<td>


Sky blue.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_SOLARIZATION`

</td>
<td>


Solarization, the image is partially reversed in tone, only color values above or below a certain threshold are inverted.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_SILHOUETTE`

</td>
<td>


Silhouette (outline).

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_VIVID`

</td>
<td>


Vivid colors.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_SET_CBCR`

</td>
<td>


The Cb and Cr chroma components are replaced by fixed coefficients determined by `V4L2_CID_COLORFX_CBCR` control.

</td>
</tr>
<tr>
<td>


`V4L2_COLORFX_SET_RGB`

</td>
<td>


The RGB components are replaced by the fixed RGB components determined by `V4L2_CID_COLORFX_RGB` control.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_COLORFX_RGB` `(integer)`**

  Determines the Red, Green, and Blue coefficients for `V4L2_COLORFX_SET_RGB` color effect. Bits \[7:0\] of the supplied 32 bit value are interpreted as Blue component, bits \[15:8\] as Green component, bits \[23:16\] as Red component, and bits \[31:24\] must be zero.

- **`V4L2_CID_COLORFX_CBCR` `(integer)`**

  Determines the Cb and Cr coefficients for `V4L2_COLORFX_SET_CBCR` color effect. Bits \[7:0\] of the supplied 32 bit value are interpreted as Cr component, bits \[15:8\] as Cb component and bits \[31:16\] must be zero.

- **`V4L2_CID_AUTOBRIGHTNESS` `(boolean)`**

  Enable Automatic Brightness.

- **`V4L2_CID_ROTATE` `(integer)`**

  Rotates the image by specified angle. Common angles are 90, 270 and 180. Rotating the image to 90 and 270 will reverse the height and width of the display window. It is necessary to set the new height and width of the picture using the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl according to the rotation angle selected.

- **`V4L2_CID_BG_COLOR` `(integer)`**

  Sets the background color on the current output device. Background color needs to be specified in the RGB24 format. The supplied 32 bit value is interpreted as bits 0-7 Red color information, bits 8-15 Green color information, bits 16-23 Blue color information and bits 24-31 must be zero.

- **`V4L2_CID_ILLUMINATORS_1 V4L2_CID_ILLUMINATORS_2` `(boolean)`**

  Switch on or off the illuminator 1 or 2 of the device (usually a microscope).

- **`V4L2_CID_MIN_BUFFERS_FOR_CAPTURE` `(integer)`**

  This is a read-only control that can be read by the application and used as a hint to determine the number of CAPTURE buffers to pass to REQBUFS. The value is the minimum number of CAPTURE buffers that is necessary for hardware to work. This control is required for stateful decoders.

- **`V4L2_CID_MIN_BUFFERS_FOR_OUTPUT` `(integer)`**

  This is a read-only control that can be read by the application and used as a hint to determine the number of OUTPUT buffers to pass to REQBUFS. The value is the minimum number of OUTPUT buffers that is necessary for hardware to work. This control is required for stateful encoders.

<a id="rst-v4l2-alpha-component"></a>

- **`V4L2_CID_ALPHA_COMPONENT` `(integer)`**

  Sets the alpha color component. When a capture device (or capture queue of a mem-to-mem device) produces a frame format that includes an alpha component (e.g. [packed RGB image formats](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-rgb.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)) and the alpha value is not defined by the device or the mem-to-mem input data this control lets you select the alpha component value of all pixels. When an output device (or output queue of a mem-to-mem device) consumes a frame format that doesn't include an alpha component and the device supports alpha channel processing this control lets you set the alpha component value of all pixels for further processing in the device.

- **`V4L2_CID_LASTP1`**

  End of the predefined control IDs (currently `V4L2_CID_ALPHA_COMPONENT` + 1).

- **`V4L2_CID_PRIVATE_BASE`**

  ID of the first custom (driver specific) control. Applications depending on particular custom controls should check the driver name and version, see [Querying Capabilities](</kernel/userspace/userspace-api/media-v4l/querycap.md#rst-querycap>).

Applications can enumerate the available controls with the [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and [VIDIOC_QUERYMENU](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctls, get and set a control value with the [VIDIOC_G_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) and [VIDIOC_S_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) ioctls. Drivers must implement `VIDIOC_QUERYCTRL`, `VIDIOC_G_CTRL` and `VIDIOC_S_CTRL` when the device has one or more controls, `VIDIOC_QUERYMENU` when it has one or more menu type controls.

<a id="rst-example-enumerating-all-controls"></a>
<a id="rst-enum-all-controls"></a>

## Example: Enumerating all controls



```c
struct v4l2_queryctrl queryctrl;
struct v4l2_querymenu querymenu;

static void enumerate_menu(__u32 id)
{
    printf("  Menu items:\\n");

    memset(&querymenu, 0, sizeof(querymenu));
    querymenu.id = id;

    for (querymenu.index = queryctrl.minimum;
         querymenu.index <= queryctrl.maximum;
         querymenu.index++) {
        if (0 == ioctl(fd, VIDIOC_QUERYMENU, &querymenu)) {
            printf("  %s\\n", querymenu.name);
        }
    }
}

memset(&queryctrl, 0, sizeof(queryctrl));

queryctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
while (0 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if (!(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)) {
        printf("Control %s\\n", queryctrl.name);

        if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
            enumerate_menu(queryctrl.id);
    }

    queryctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
}
if (errno != EINVAL) {
    perror("VIDIOC_QUERYCTRL");
    exit(EXIT_FAILURE);
}
```

<a id="rst-example-enumerating-all-controls-including-compound-controls"></a>

## Example: Enumerating all controls including compound controls



```c
struct v4l2_query_ext_ctrl query_ext_ctrl;

memset(&query_ext_ctrl, 0, sizeof(query_ext_ctrl));

query_ext_ctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND;
while (0 == ioctl(fd, VIDIOC_QUERY_EXT_CTRL, &query_ext_ctrl)) {
    if (!(query_ext_ctrl.flags & V4L2_CTRL_FLAG_DISABLED)) {
        printf("Control %s\\n", query_ext_ctrl.name);

        if (query_ext_ctrl.type == V4L2_CTRL_TYPE_MENU)
            enumerate_menu(query_ext_ctrl.id);
    }

    query_ext_ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND;
}
if (errno != EINVAL) {
    perror("VIDIOC_QUERY_EXT_CTRL");
    exit(EXIT_FAILURE);
}
```

<a id="rst-example-enumerating-all-user-controls-old-style"></a>

## Example: Enumerating all user controls (old style)



```c
memset(&queryctrl, 0, sizeof(queryctrl));

for (queryctrl.id = V4L2_CID_BASE;
     queryctrl.id < V4L2_CID_LASTP1;
     queryctrl.id++) {
    if (0 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
        if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
            continue;

        printf("Control %s\\n", queryctrl.name);

        if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
            enumerate_menu(queryctrl.id);
    } else {
        if (errno == EINVAL)
            continue;

        perror("VIDIOC_QUERYCTRL");
        exit(EXIT_FAILURE);
    }
}

for (queryctrl.id = V4L2_CID_PRIVATE_BASE;;
     queryctrl.id++) {
    if (0 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
        if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
            continue;

        printf("Control %s\\n", queryctrl.name);

        if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
            enumerate_menu(queryctrl.id);
    } else {
        if (errno == EINVAL)
            break;

        perror("VIDIOC_QUERYCTRL");
        exit(EXIT_FAILURE);
    }
}
```

<a id="rst-example-changing-controls"></a>

## Example: Changing controls



```c
struct v4l2_queryctrl queryctrl;
struct v4l2_control control;

memset(&queryctrl, 0, sizeof(queryctrl));
queryctrl.id = V4L2_CID_BRIGHTNESS;

if (-1 == ioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
    if (errno != EINVAL) {
        perror("VIDIOC_QUERYCTRL");
        exit(EXIT_FAILURE);
    } else {
        printf("V4L2_CID_BRIGHTNESS is not supported\n");
    }
} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    printf("V4L2_CID_BRIGHTNESS is not supported\n");
} else {
    memset(&control, 0, sizeof (control));
    control.id = V4L2_CID_BRIGHTNESS;
    control.value = queryctrl.default_value;

    if (-1 == ioctl(fd, VIDIOC_S_CTRL, &control)) {
        perror("VIDIOC_S_CTRL");
        exit(EXIT_FAILURE);
    }
}

memset(&control, 0, sizeof(control));
control.id = V4L2_CID_CONTRAST;

if (0 == ioctl(fd, VIDIOC_G_CTRL, &control)) {
    control.value += 1;

    /* The driver may clamp the value or return ERANGE, ignored here */

    if (-1 == ioctl(fd, VIDIOC_S_CTRL, &control)
        && errno != ERANGE) {
        perror("VIDIOC_S_CTRL");
        exit(EXIT_FAILURE);
    }
/* Ignore if V4L2_CID_CONTRAST is unsupported */
} else if (errno != EINVAL) {
    perror("VIDIOC_G_CTRL");
    exit(EXIT_FAILURE);
}

control.id = V4L2_CID_AUDIO_MUTE;
control.value = 1; /* silence */

/* Errors ignored */
ioctl(fd, VIDIOC_S_CTRL, &control);
```

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



**[1]** The use of `V4L2_CID_PRIVATE_BASE` is problematic because different drivers may use the same `V4L2_CID_PRIVATE_BASE` ID for different controls. This makes it hard to programmatically set such controls since the meaning of the control with that ID is driver dependent. In order to resolve this drivers use unique IDs and the `V4L2_CID_PRIVATE_BASE` IDs are mapped to those unique IDs by the kernel. Consider these `V4L2_CID_PRIVATE_BASE` IDs as aliases to the real IDs.

Many applications today still use the `V4L2_CID_PRIVATE_BASE` IDs instead of using [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) with the `V4L2_CTRL_FLAG_NEXT_CTRL` flag to enumerate all IDs, so support for `V4L2_CID_PRIVATE_BASE` is still around.

---

# Image Cropping, Insertion and Scaling -- the CROP API

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Some video capture devices can sample a subsection of the picture and shrink or enlarge it to an image of arbitrary size. We call these abilities cropping and scaling. Some video output devices can scale an image up or down and insert it…

<a id="rst-image-cropping-insertion-and-scaling-the-crop-api"></a>
<a id="rst-crop"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

> [!NOTE]
>
> The CROP API is mostly superseded by the newer [SELECTION API](</kernel/userspace/userspace-api/media-v4l/selection-api.md#rst-selection-api>). The new API should be preferred in most cases, with the exception of pixel aspect ratio detection, which is implemented by [VIDIOC_CROPCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#rst-vidioc-cropcap>) and has no equivalent in the SELECTION API. See [Comparison with old cropping API](</kernel/userspace/userspace-api/media-v4l/selection-api-vs-crop-api.md#rst-selection-vs-crop>) for a comparison of the two APIs.

Some video capture devices can sample a subsection of the picture and shrink or enlarge it to an image of arbitrary size. We call these abilities cropping and scaling. Some video output devices can scale an image up or down and insert it at an arbitrary scan line and horizontal offset into a video signal.

Applications can use the following API to select an area in the video signal, query the default area and the hardware limits.

> [!NOTE]
>
> Despite their name, the [VIDIOC_CROPCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#rst-vidioc-cropcap>), [VIDIOC_G_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) and [VIDIOC_S_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) ioctls apply to input as well as output devices.

Scaling requires a source and a target. On a video capture or overlay device the source is the video signal, and the cropping ioctls determine the area actually sampled. The target are images read by the application or overlaid onto the graphics screen. Their size (and position for an overlay) is negotiated with the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls.

On a video output device the source are the images passed in by the application, and their size is again negotiated with the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls, or may be encoded in a compressed video stream. The target is the video signal, and the cropping ioctls determine the area where the images are inserted.

Source and target rectangles are defined even if the device does not support scaling or the [VIDIOC_G_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) and [VIDIOC_S_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) ioctls. Their size (and position where applicable) will be fixed in this case.

> [!NOTE]
>
> All capture and output devices that support the CROP or SELECTION API will also support the [VIDIOC_CROPCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#rst-vidioc-cropcap>) ioctl.

<a id="rst-cropping-structures"></a>

## Cropping Structures

<a id="rst-crop-scale"></a>

![crop.svg](/kernel/userspace/userspace-api/media-v4l/asset-c2f9d4021552-crop.svg)

Image Cropping, Insertion and Scaling

The cropping, insertion and scaling process

For capture devices the coordinates of the top left corner, width and height of the area which can be sampled is given by the `bounds` substructure of the struct `v4l2_cropcap` returned by the [VIDIOC_CROPCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#rst-vidioc-cropcap>) ioctl. To support a wide range of hardware this specification does not define an origin or units. However by convention drivers should horizontally count unscaled samples relative to 0H (the leading edge of the horizontal sync pulse, see [vbi-hsync](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-hsync>)). Vertically ITU-R line numbers of the first field (see ITU R-525 line numbering for [525 lines](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-525>) and for [625 lines](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-625>)), multiplied by two if the driver can capture both fields.

The top left corner, width and height of the source rectangle, that is the area actually sampled, is given by struct `v4l2_crop` using the same coordinate system as struct `v4l2_cropcap`. Applications can use the [VIDIOC_G_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) and [VIDIOC_S_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) ioctls to get and set this rectangle. It must lie completely within the capture boundaries and the driver may further adjust the requested size and/or position according to hardware limitations.

Each capture device has a default source rectangle, given by the `defrect` substructure of struct `v4l2_cropcap`. The center of this rectangle shall align with the center of the active picture area of the video signal, and cover what the driver writer considers the complete picture. Drivers shall reset the source rectangle to the default when the driver is first loaded, but not later.

For output devices these structures and ioctls are used accordingly, defining the *target* rectangle where the images will be inserted into the video signal.

<a id="rst-scaling-adjustments"></a>

## Scaling Adjustments

Video hardware can have various cropping, insertion and scaling limitations. It may only scale up or down, support only discrete scaling factors, or have different scaling abilities in horizontal and vertical direction. Also it may not support scaling at all. At the same time the struct `v4l2_crop` rectangle may have to be aligned, and both the source and target rectangles may have arbitrary upper and lower size limits. In particular the maximum `width` and `height` in struct `v4l2_crop` may be smaller than the struct `v4l2_cropcap`. `bounds` area. Therefore, as usual, drivers are expected to adjust the requested parameters and return the actual values selected.

Applications can change the source or the target rectangle first, as they may prefer a particular image size or a certain area in the video signal. If the driver has to adjust both to satisfy hardware limitations, the last requested rectangle shall take priority, and the driver should preferably adjust the opposite one. The [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl however shall not change the driver state and therefore only adjust the requested rectangle.

Suppose scaling on a video capture device is restricted to a factor 1:1 or 2:1 in either direction and the target image size must be a multiple of 16 × 16 pixels. The source cropping rectangle is set to defaults, which are also the upper limit in this example, of 640 × 400 pixels at offset 0, 0. An application requests an image size of 300 × 225 pixels, assuming video will be scaled down from the "full picture" accordingly. The driver sets the image size to the closest possible values 304 × 224, then chooses the cropping rectangle closest to the requested size, that is 608 × 224 (224 × 2:1 would exceed the limit 400). The offset 0, 0 is still valid, thus unmodified. Given the default cropping rectangle reported by [VIDIOC_CROPCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#rst-vidioc-cropcap>) the application can easily propose another offset to center the cropping rectangle.

Now the application may insist on covering an area using a picture aspect ratio closer to the original request, so it asks for a cropping rectangle of 608 × 456 pixels. The present scaling factors limit cropping to 640 × 384, so the driver returns the cropping size 608 × 384 and adjusts the image size to closest possible 304 × 192.

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

## Examples

Source and target rectangles shall remain unchanged across closing and reopening a device, such that piping data into or out of a device will work without special preparations. More advanced applications should ensure the parameters are suitable before starting I/O.

> [!NOTE]
>
> On the next two examples, a video capture device is assumed; change `V4L2_BUF_TYPE_VIDEO_CAPTURE` for other types of device.

<a id="rst-example-resetting-the-cropping-parameters"></a>

## Example: Resetting the cropping parameters



```c
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;

memset (&cropcap, 0, sizeof (cropcap));
cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) {
    perror ("VIDIOC_CROPCAP");
    exit (EXIT_FAILURE);
}

memset (&crop, 0, sizeof (crop));
crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
crop.c = cropcap.defrect;

/* Ignore if cropping is not supported (EINVAL). */

if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop)
    && errno != EINVAL) {
    perror ("VIDIOC_S_CROP");
    exit (EXIT_FAILURE);
}
```

<a id="rst-example-simple-downscaling"></a>

## Example: Simple downscaling



```c
struct v4l2_cropcap cropcap;
struct v4l2_format format;

reset_cropping_parameters ();

/* Scale down to 1/4 size of full picture. */

memset (&format, 0, sizeof (format)); /* defaults */

format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

format.fmt.pix.width = cropcap.defrect.width >> 1;
format.fmt.pix.height = cropcap.defrect.height >> 1;
format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;

if (-1 == ioctl (fd, VIDIOC_S_FMT, &format)) {
    perror ("VIDIOC_S_FORMAT");
    exit (EXIT_FAILURE);
}

/* We could check the actual image size now, the actual scaling factor
   or if the driver can scale at all. */
```

<a id="rst-example-selecting-an-output-area"></a>

## Example: Selecting an output area

> [!NOTE]
>
> This example assumes an output device.



```c
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;

memset (&cropcap, 0, sizeof (cropcap));
cropcap.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;

if (-1 == ioctl (fd, VIDIOC_CROPCAP;, &cropcap)) {
    perror ("VIDIOC_CROPCAP");
    exit (EXIT_FAILURE);
}

memset (&crop, 0, sizeof (crop));

crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
crop.c = cropcap.defrect;

/* Scale the width and height to 50 % of their original size
   and center the output. */

crop.c.width /= 2;
crop.c.height /= 2;
crop.c.left += crop.c.width / 2;
crop.c.top += crop.c.height / 2;

/* Ignore if cropping is not supported (EINVAL). */

if (-1 == ioctl (fd, VIDIOC_S_CROP, &crop)
    && errno != EINVAL) {
    perror ("VIDIOC_S_CROP");
    exit (EXIT_FAILURE);
}
```

<a id="rst-example-current-scaling-factor-and-pixel-aspect"></a>

## Example: Current scaling factor and pixel aspect

> [!NOTE]
>
> This example assumes a video capture device.



```c
struct v4l2_cropcap cropcap;
struct v4l2_crop crop;
struct v4l2_format format;
double hscale, vscale;
double aspect;
int dwidth, dheight;

memset (&cropcap, 0, sizeof (cropcap));
cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

if (-1 == ioctl (fd, VIDIOC_CROPCAP, &cropcap)) {
    perror ("VIDIOC_CROPCAP");
    exit (EXIT_FAILURE);
}

memset (&crop, 0, sizeof (crop));
crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

if (-1 == ioctl (fd, VIDIOC_G_CROP, &crop)) {
    if (errno != EINVAL) {
        perror ("VIDIOC_G_CROP");
        exit (EXIT_FAILURE);
    }

    /* Cropping not supported. */
    crop.c = cropcap.defrect;
}

memset (&format, 0, sizeof (format));
format.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

if (-1 == ioctl (fd, VIDIOC_G_FMT, &format)) {
    perror ("VIDIOC_G_FMT");
    exit (EXIT_FAILURE);
}

/* The scaling applied by the driver. */

hscale = format.fmt.pix.width / (double) crop.c.width;
vscale = format.fmt.pix.height / (double) crop.c.height;

aspect = cropcap.pixelaspect.numerator /
     (double) cropcap.pixelaspect.denominator;
aspect = aspect * hscale / vscale;

/* Devices following ITU-R BT.601 do not capture
   square pixels. For playback on a computer monitor
   we should scale the images to this size. */

dwidth = format.fmt.pix.width / aspect;
dheight = format.fmt.pix.height;
```

---

# Depth Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Depth data provides distance to points, mapped onto the image plane

<a id="rst-depth-formats-1"></a>
<a id="rst-depth-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Depth data provides distance to points, mapped onto the image plane

- [pixfmt-inzi](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-inzi.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [V4L2_PIX_FMT_Z16 ('Z16 ')](</kernel/userspace/userspace-api/media-v4l/pixfmt-z16.md>)
- [V4L2_PIX_FMT_CNF4 ('CNF4')](</kernel/userspace/userspace-api/media-v4l/pixfmt-cnf4.md>)

---

# Video Capture Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Video capture devices sample an analog video signal and store the digitized images in memory. Today nearly all devices can capture at full 25 or 30 frames/second. With this interface applications can control the capture process and move…

<a id="rst-video-capture-interface"></a>
<a id="rst-capture"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Video capture devices sample an analog video signal and store the digitized images in memory. Today nearly all devices can capture at full 25 or 30 frames/second. With this interface applications can control the capture process and move images from the driver into user space.

Conventionally V4L2 video capture devices are accessed through character device special files named `/dev/video` and `/dev/video0` to `/dev/video63` with major number 81 and minor numbers 0 to 63. `/dev/video` is typically a symbolic link to the preferred video device.

> [!NOTE]
>
> The same device file names are used for video output devices.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the video capture interface set the `V4L2_CAP_VIDEO_CAPTURE` or `V4L2_CAP_VIDEO_CAPTURE_MPLANE` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. As secondary device functions they may also support the [video overlay](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) (`V4L2_CAP_VIDEO_OVERLAY`) and the [raw VBI capture](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>) (`V4L2_CAP_VBI_CAPTURE`) interface. At least one of the read/write or streaming I/O methods must be supported. Tuners and audio inputs are optional.

<a id="rst-supplemental-functions"></a>

## Supplemental Functions

Video capture devices shall support [audio input](</kernel/userspace/userspace-api/media-v4l/audio.md#rst-audio>), [Tuners and Modulators](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>), [controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>), [cropping and scaling](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>) and [streaming parameter](</kernel/userspace/userspace-api/media-v4l/streaming-par.md#rst-streaming-par>) ioctls as needed. The [video input](</kernel/userspace/userspace-api/media-v4l/video.md#rst-video>) ioctls must be supported by all video capture devices.

<a id="rst-image-format-negotiation"></a>

## Image Format Negotiation

The result of a capture operation is determined by cropping and image format parameters. The former select an area of the video picture to capture, the latter how images are stored in memory, i. e. in RGB or YUV format, the number of bits per pixel or width and height. Together they also define how images are scaled in the process.

As usual these parameters are *not* reset at `open()` time to permit Unix tool chains, programming a device and then reading from it as if it was a plain file. Well written V4L2 applications ensure they really get what they want, including cropping and scaling.

Cropping initialization at minimum requires to reset the parameters to defaults. An example is given in [Image Cropping, Insertion and Scaling -- the CROP API](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>).

To query the current image format applications set the `type` field of a struct `v4l2_format` to `V4L2_BUF_TYPE_VIDEO_CAPTURE` or `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE` and call the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with a pointer to this structure. Drivers fill the struct `v4l2_pix_format` `pix` or the struct `v4l2_pix_format_mplane` `pix_mp` member of the `fmt` union.

To request different parameters applications set the `type` field of a struct `v4l2_format` as above and initialize all fields of the struct `v4l2_pix_format` `vbi` member of the `fmt` union, or better just modify the results of [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), and call the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with a pointer to this structure. Drivers may adjust the parameters and finally return the actual parameters as [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) does.

Like [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) the [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl can be used to learn about hardware limitations without disabling I/O or possibly time consuming hardware preparations.

The contents of struct `v4l2_pix_format` and struct `v4l2_pix_format_mplane` are discussed in [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>). See also the specification of the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls for details. Video capture devices must implement both the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, even if [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ignores all requests and always returns default parameters as [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) does. [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) is optional.

<a id="rst-reading-images"></a>

## Reading Images

A video capture device may support the [read() function](</kernel/userspace/userspace-api/media-v4l/func-read.md#rst-func-read>) and/or streaming ([memory mapping](</kernel/userspace/userspace-api/media-v4l/func-mmap.md#rst-func-mmap>) or [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>)) I/O. See [Input/Output](</kernel/userspace/userspace-api/media-v4l/io.md#rst-io>) for details.

---

# Memory-to-Memory Stateful Video Decoder Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> A stateful video decoder takes complete chunks of the bytestream (e.g. Annex-B H.264/HEVC stream, raw VP8/9 stream) and decodes them into raw video frames in display order. The decoder is expected not to require any additional information…

<a id="rst-memory-to-memory-stateful-video-decoder-interface"></a>
<a id="rst-decoder"></a>

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

<!-- c:namespace: V4L -->

A stateful video decoder takes complete chunks of the bytestream (e.g. Annex-B H.264/HEVC stream, raw VP8/9 stream) and decodes them into raw video frames in display order. The decoder is expected not to require any additional information from the client to process these buffers.

Performing software parsing, processing etc. of the stream in the driver in order to support this interface is strongly discouraged. In case such operations are needed, use of the Stateless Video Decoder Interface (in development) is strongly advised.

<a id="rst-conventions-and-notations-used-in-this-document"></a>

## Conventions and Notations Used in This Document

1. The general V4L2 API rules apply if not specified in this document otherwise.

2. The meaning of words "must", "may", "should", etc. is as per [RFC 2119](<https://tools.ietf.org/html/rfc2119>)<a id="rst-rfc-2119"></a>.

3. All steps not marked "optional" are required.

4. `VIDIOC_G_EXT_CTRLS()` and `VIDIOC_S_EXT_CTRLS()` may be used interchangeably with `VIDIOC_G_CTRL()` and `VIDIOC_S_CTRL()`, unless specified otherwise.

5. Single-planar API (see [Single- and multi-planar APIs](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>)) and applicable structures may be used interchangeably with multi-planar API, unless specified otherwise, depending on decoder capabilities and following the general V4L2 guidelines.

6. i = \[a..b\]: sequence of integers from a to b, inclusive, i.e. i = \[0..2\]: i = 0, 1, 2.

7. Given an `OUTPUT` buffer A, then A' represents a buffer on the `CAPTURE` queue containing data that resulted from processing buffer A.

<a id="rst-glossary"></a>
<a id="rst-decoder-glossary"></a>

## Glossary

- **CAPTURE**

  the destination buffer queue; for decoders, the queue of buffers containing decoded frames; for encoders, the queue of buffers containing an encoded bytestream; `V4L2_BUF_TYPE_VIDEO_CAPTURE` or `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`; data is captured from the hardware into `CAPTURE` buffers.

- **client**

  the application communicating with the decoder or encoder implementing this interface.

- **coded format**

  encoded/compressed video bytestream format (e.g. H.264, VP8, etc.); see also: raw format.

- **coded height**

  height for given coded resolution.

- **coded resolution**

  stream resolution in pixels aligned to codec and hardware requirements; typically visible resolution rounded up to full macroblocks; see also: visible resolution.

- **coded width**

  width for given coded resolution.

- **coding tree unit**

  processing unit of the HEVC codec (corresponds to macroblock units in H.264, VP8, VP9), can use block structures of up to 64×64 pixels. Good at sub-partitioning the picture into variable sized structures.

- **decode order**

  the order in which frames are decoded; may differ from display order if the coded format includes a feature of frame reordering; for decoders, `OUTPUT` buffers must be queued by the client in decode order; for encoders `CAPTURE` buffers must be returned by the encoder in decode order.

- **destination**

  data resulting from the decode process; see `CAPTURE`.

- **display order**

  the order in which frames must be displayed; for encoders, `OUTPUT` buffers must be queued by the client in display order; for decoders, `CAPTURE` buffers must be returned by the decoder in display order.

- **DPB**

  Decoded Picture Buffer; an H.264/HEVC term for a buffer that stores a decoded raw frame available for reference in further decoding steps.

- **EOS**

  end of stream.

- **IDR**

  Instantaneous Decoder Refresh; a type of a keyframe in an H.264/HEVC-encoded stream, which clears the list of earlier reference frames (DPBs).

- **keyframe**

  an encoded frame that does not reference frames decoded earlier, i.e. can be decoded fully on its own.

- **macroblock**

  a processing unit in image and video compression formats based on linear block transforms (e.g. H.264, VP8, VP9); codec-specific, but for most of popular codecs the size is 16x16 samples (pixels). The HEVC codec uses a slightly more flexible processing unit called coding tree unit (CTU).

- **OUTPUT**

  the source buffer queue; for decoders, the queue of buffers containing an encoded bytestream; for encoders, the queue of buffers containing raw frames; `V4L2_BUF_TYPE_VIDEO_OUTPUT` or `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`; the hardware is fed with data from `OUTPUT` buffers.

- **PPS**

  Picture Parameter Set; a type of metadata entity in an H.264/HEVC bytestream.

- **raw format**

  uncompressed format containing raw pixel data (e.g. YUV, RGB formats).

- **resume point**

  a point in the bytestream from which decoding may start/continue, without any previous state/data present, e.g.: a keyframe (VP8/VP9) or SPS/PPS/IDR sequence (H.264/HEVC); a resume point is required to start decode of a new stream, or to resume decoding after a seek.

- **source**

  data fed to the decoder or encoder; see `OUTPUT`.

- **source height**

  height in pixels for given source resolution; relevant to encoders only.

- **source resolution**

  resolution in pixels of source frames being source to the encoder and subject to further cropping to the bounds of visible resolution; relevant to encoders only.

- **source width**

  width in pixels for given source resolution; relevant to encoders only.

- **SPS**

  Sequence Parameter Set; a type of metadata entity in an H.264/HEVC bytestream.

- **stream metadata**

  additional (non-visual) information contained inside encoded bytestream; for example: coded resolution, visible resolution, codec profile.

- **visible height**

  height for given visible resolution; display height.

- **visible resolution**

  stream resolution of the visible picture, in pixels, to be used for display purposes; must be smaller or equal to coded resolution; display resolution.

- **visible width**

  width for given visible resolution; display width.

<a id="rst-state-machine"></a>

## State Machine

```mermaid
flowchart TB
  n0((("Decoding")))
  n1(("Initialization"))
  n2(("Capture<br/>setup"))
  n3(("Dynamic<br/>Resolution<br/>Change"))
  n4(("Stopped"))
  n5(("Drain"))
  n6(("Seek"))
  n7(("End of Stream"))
  n8(("#160;"))
  n8 -->|"open()"| n1
  n1 -->|"CAPTURE<br/>format<br/>established"| n2
  n2 -->|"CAPTURE<br/>buffers<br/>ready"| n4
  n0 -->|"Stream<br/>resolution<br/>change"| n3
  n0 -->|"V4L2_DEC_CMD_STOP"| n5
  n0 -->|"EoS mark<br/>in the stream"| n7
  n0 -->|"VIDIOC_STREAMOFF(OUTPUT)"| n6
  n0 -->|"VIDIOC_STREAMOFF(CAPTURE)"| n4
  n0 --> n0
  n3 -->|"CAPTURE<br/>format<br/>established"| n2
  n3 -->|"VIDIOC_STREAMOFF(OUTPUT)"| n6
  n7 -->|"Implicit<br/>drain"| n5
  n5 -->|"All CAPTURE<br/>buffers dequeued<br/>or<br/>VIDIOC_STREAMOFF(CAPTURE)"| n4
  n5 -->|"VIDIOC_STREAMOFF(OUTPUT)"| n6
  n6 -->|"VIDIOC_STREAMON(OUTPUT)"| n0
  n6 -->|"VIDIOC_REQBUFS(OUTPUT, 0)"| n1
  n4 -->|"V4L2_DEC_CMD_START<br/>or<br/>VIDIOC_STREAMON(CAPTURE)"| n0
  n4 -->|"VIDIOC_STREAMOFF(OUTPUT)"| n6
  style n8 fill:#333,stroke:#333
```

Decoder State Machine

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

1. To enumerate the set of coded formats supported by the decoder, the client may call `VIDIOC_ENUM_FMT()` on `OUTPUT`.

   - The full set of supported formats will be returned, regardless of the format set on `CAPTURE`.

   - Check the flags field of `v4l2_fmtdesc` for more information about the decoder's capabilities with respect to each coded format. In particular whether or not the decoder has a full-fledged bytestream parser and if the decoder supports dynamic resolution changes.

2. To enumerate the set of supported raw formats, the client may call `VIDIOC_ENUM_FMT()` on `CAPTURE`.

   - Only the formats supported for the format currently active on `OUTPUT` will be returned.

   - In order to enumerate raw formats supported by a given coded format, the client must first set that coded format on `OUTPUT` and then enumerate formats on `CAPTURE`.

3. The client may use `VIDIOC_ENUM_FRAMESIZES()` to detect supported resolutions for a given format, passing desired pixel format in `v4l2_frmsizeenum` `pixel_format`.

   - Values returned by `VIDIOC_ENUM_FRAMESIZES()` for a coded pixel format will include all possible coded resolutions supported by the decoder for given coded pixel format.

   - Values returned by `VIDIOC_ENUM_FRAMESIZES()` for a raw pixel format will include all possible frame buffer resolutions supported by the decoder for given raw pixel format and the coded format currently set on `OUTPUT`.

4. Supported profiles and levels for the coded format currently set on `OUTPUT`, if applicable, may be queried using their respective controls via `VIDIOC_QUERYCTRL()`.

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

## Initialization

1. Set the coded format on `OUTPUT` via `VIDIOC_S_FMT()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **`pixelformat`**

       a coded pixel format.

     - **`width`, `height`**

       coded resolution of the stream; required only if it cannot be parsed from the stream for the given coded format; otherwise the decoder will use this resolution as a placeholder resolution that will likely change as soon as it can parse the actual coded resolution from the stream.

     - **`sizeimage`**

       desired size of `OUTPUT` buffers; the decoder may adjust it to match hardware requirements.

     - **other fields**

       follow standard semantics.

   - **Returned fields:**

     - **`sizeimage`**

       adjusted size of `OUTPUT` buffers.

   - The `CAPTURE` format will be updated with an appropriate frame buffer resolution instantly based on the width and height returned by `VIDIOC_S_FMT()`. However, for coded formats that include stream resolution information, after the decoder is done parsing the information from the stream, it will update the `CAPTURE` format with new values and signal a source change event, regardless of whether they match the values set by the client or not.

   > [!IMPORTANT]
   >
   > Changing the `OUTPUT` format may change the currently set `CAPTURE` format. How the new `CAPTURE` format is determined is up to the decoder and the client must ensure it matches its needs afterwards.

2. Allocate source (bytestream) buffers via `VIDIOC_REQBUFS()` on `OUTPUT`.

   - **Required fields:**

     - **`count`**

       requested number of buffers to allocate; greater than zero.

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **`memory`**

       follows standard semantics.

   - **Returned fields:**

     - **`count`**

       the actual number of buffers allocated.

   > [!WARNING]
   >
   > The actual number of allocated buffers may differ from the `count` given. The client must check the updated value of `count` after the call returns.

   Alternatively, `VIDIOC_CREATE_BUFS()` on the `OUTPUT` queue can be used to have more control over buffer allocation.

   - **Required fields:**

     - **`count`**

       requested number of buffers to allocate; greater than zero.

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **`memory`**

       follows standard semantics.

     - **`format`**

       follows standard semantics.

   - **Returned fields:**

     - **`count`**

       adjusted to the number of allocated buffers.

   > [!WARNING]
   >
   > The actual number of allocated buffers may differ from the `count` given. The client must check the updated value of `count` after the call returns.

3. Start streaming on the `OUTPUT` queue via `VIDIOC_STREAMON()`.

4. **This step only applies to coded formats that contain resolution information in the stream.** Continue queuing/dequeuing bytestream buffers to/from the `OUTPUT` queue via `VIDIOC_QBUF()` and `VIDIOC_DQBUF()`. The buffers will be processed and returned to the client in order, until required metadata to configure the `CAPTURE` queue are found. This is indicated by the decoder sending a `V4L2_EVENT_SOURCE_CHANGE` event with `changes` set to `V4L2_EVENT_SRC_CH_RESOLUTION`.

   - It is not an error if the first buffer does not contain enough data for this to occur. Processing of the buffers will continue as long as more data is needed.

   - If data in a buffer that triggers the event is required to decode the first frame, it will not be returned to the client, until the initialization sequence completes and the frame is decoded.

   - If the client has not set the coded resolution of the stream on its own, calling `VIDIOC_G_FMT()`, `VIDIOC_S_FMT()`, `VIDIOC_TRY_FMT()` or `VIDIOC_REQBUFS()` on the `CAPTURE` queue will not return the real values for the stream until a `V4L2_EVENT_SOURCE_CHANGE` event with `changes` set to `V4L2_EVENT_SRC_CH_RESOLUTION` is signaled.

   > [!IMPORTANT]
   >
   > Any client query issued after the decoder queues the event will return values applying to the just parsed stream, including queue formats, selection rectangles and controls.

   > [!NOTE]
   >
   > A client capable of acquiring stream parameters from the bytestream on its own may attempt to set the width and height of the `OUTPUT` format to non-zero values matching the coded size of the stream, skip this step and continue with the `Capture Setup` sequence. However, it must not rely on any driver queries regarding stream parameters, such as selection rectangles and controls, since the decoder has not parsed them from the stream yet. If the values configured by the client do not match those parsed by the decoder, a `Dynamic Resolution Change` will be triggered to reconfigure them.

   > [!NOTE]
   >
   > No decoded frames are produced during this phase.

5. Continue with the `Capture Setup` sequence.

<a id="rst-capture-setup"></a>

## Capture Setup

1. Call `VIDIOC_G_FMT()` on the `CAPTURE` queue to get format for the destination buffers parsed/decoded from the bytestream.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

   - **Returned fields:**

     - **`width`, `height`**

       frame buffer resolution for the decoded frames.

     - **`pixelformat`**

       pixel format for decoded frames.

     - **`num_planes` (for \_MPLANE `type` only)**

       number of planes for pixelformat.

     - **`sizeimage`, `bytesperline`**

       as per standard semantics; matching frame buffer format.

   > [!NOTE]
   >
   > The value of `pixelformat` may be any pixel format supported by the decoder for the current stream. The decoder should choose a preferred/optimal format for the default configuration. For example, a YUV format may be preferred over an RGB format if an additional conversion step would be required for the latter.

2. **Optional.** Acquire the visible resolution via `VIDIOC_G_SELECTION()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

     - **`target`**

       set to `V4L2_SEL_TGT_COMPOSE`.

   - **Returned fields:**

     - **`r.left`, `r.top`, `r.width`, `r.height`**

       the visible rectangle; it must fit within the frame buffer resolution returned by `VIDIOC_G_FMT()` on `CAPTURE`.

   - The following selection targets are supported on `CAPTURE`:

     - **`V4L2_SEL_TGT_CROP_BOUNDS`**

       corresponds to the coded resolution of the stream.

     - **`V4L2_SEL_TGT_CROP_DEFAULT`**

       the rectangle covering the part of the `CAPTURE` buffer that contains meaningful picture data (visible area); width and height will be equal to the visible resolution of the stream.

     - **`V4L2_SEL_TGT_CROP`**

       the rectangle within the coded resolution to be output to `CAPTURE`; defaults to `V4L2_SEL_TGT_CROP_DEFAULT`; read-only on hardware without additional compose/scaling capabilities.

     - **`V4L2_SEL_TGT_COMPOSE_BOUNDS`**

       the maximum rectangle within a `CAPTURE` buffer, which the cropped frame can be composed into; equal to `V4L2_SEL_TGT_CROP` if the hardware does not support compose/scaling.

     - **`V4L2_SEL_TGT_COMPOSE_DEFAULT`**

       equal to `V4L2_SEL_TGT_CROP`.

     - **`V4L2_SEL_TGT_COMPOSE`**

       the rectangle inside a `CAPTURE` buffer into which the cropped frame is written; defaults to `V4L2_SEL_TGT_COMPOSE_DEFAULT`; read-only on hardware without additional compose/scaling capabilities.

     - **`V4L2_SEL_TGT_COMPOSE_PADDED`**

       the rectangle inside a `CAPTURE` buffer which is overwritten by the hardware; equal to `V4L2_SEL_TGT_COMPOSE` if the hardware does not write padding pixels.

   > [!WARNING]
   >
   > The values are guaranteed to be meaningful only after the decoder successfully parses the stream metadata. The client must not rely on the query before that happens.

3. **Optional.** Enumerate `CAPTURE` formats via `VIDIOC_ENUM_FMT()` on the `CAPTURE` queue. Once the stream information is parsed and known, the client may use this ioctl to discover which raw formats are supported for given stream and select one of them via `VIDIOC_S_FMT()`.

   > [!IMPORTANT]
   >
   > The decoder will return only formats supported for the currently established coded format, as per the `OUTPUT` format and/or stream metadata parsed in this initialization sequence, even if more formats may be supported by the decoder in general. In other words, the set returned will be a subset of the initial query mentioned in the `Querying Capabilities` section.
   >
   > For example, a decoder may support YUV and RGB formats for resolutions 1920x1088 and lower, but only YUV for higher resolutions (due to hardware limitations). After parsing a resolution of 1920x1088 or lower, `VIDIOC_ENUM_FMT()` may return a set of YUV and RGB pixel formats, but after parsing resolution higher than 1920x1088, the decoder will not return RGB, unsupported for this resolution.
   >
   > However, subsequent resolution change event triggered after discovering a resolution change within the same stream may switch the stream into a lower resolution and `VIDIOC_ENUM_FMT()` would return RGB formats again in that case.

4. **Optional.** Set the `CAPTURE` format via `VIDIOC_S_FMT()` on the `CAPTURE` queue. The client may choose a different format than selected/suggested by the decoder in `VIDIOC_G_FMT()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

     - **`pixelformat`**

       a raw pixel format.

     - **`width`, `height`**

       frame buffer resolution of the decoded stream; typically unchanged from what was returned with `VIDIOC_G_FMT()`, but it may be different if the hardware supports composition and/or scaling.

> - Setting the `CAPTURE` format will reset the compose selection rectangles to their default values, based on the new resolution, as described in the previous step.

5. **Optional.** Set the compose rectangle via `VIDIOC_S_SELECTION()` on the `CAPTURE` queue if it is desired and if the decoder has compose and/or scaling capabilities.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

     - **`target`**

       set to `V4L2_SEL_TGT_COMPOSE`.

     - **`r.left`, `r.top`, `r.width`, `r.height`**

       the rectangle inside a `CAPTURE` buffer into which the cropped frame is written; defaults to `V4L2_SEL_TGT_COMPOSE_DEFAULT`; read-only on hardware without additional compose/scaling capabilities.

   - **Returned fields:**

     - **`r.left`, `r.top`, `r.width`, `r.height`**

       the visible rectangle; it must fit within the frame buffer resolution returned by `VIDIOC_G_FMT()` on `CAPTURE`.

   > [!WARNING]
   >
   > The decoder may adjust the compose rectangle to the nearest supported one to meet codec and hardware requirements. The client needs to check the adjusted rectangle returned by `VIDIOC_S_SELECTION()`.

6. If all the following conditions are met, the client may resume the decoding instantly:

   - `sizeimage` of the new format (determined in previous steps) is less than or equal to the size of currently allocated buffers,

   - the number of buffers currently allocated is greater than or equal to the minimum number of buffers acquired in previous steps. To fulfill this requirement, the client may use `VIDIOC_CREATE_BUFS()` to add new buffers.

   In that case, the remaining steps do not apply and the client may resume the decoding by one of the following actions:

   - if the `CAPTURE` queue is streaming, call `VIDIOC_DECODER_CMD()` with the `V4L2_DEC_CMD_START` command,

   - if the `CAPTURE` queue is not streaming, call `VIDIOC_STREAMON()` on the `CAPTURE` queue.

   However, if the client intends to change the buffer set, to lower memory usage or for any other reasons, it may be achieved by following the steps below.

7. **If the** `CAPTURE` **queue is streaming,** keep queuing and dequeuing buffers on the `CAPTURE` queue until a buffer marked with the `V4L2_BUF_FLAG_LAST` flag is dequeued.

8. **If the** `CAPTURE` **queue is streaming,** call `VIDIOC_STREAMOFF()` on the `CAPTURE` queue to stop streaming.

   > [!WARNING]
   >
   > The `OUTPUT` queue must remain streaming. Calling `VIDIOC_STREAMOFF()` on it would abort the sequence and trigger a seek.

9. **If the** `CAPTURE` **queue has buffers allocated,** free the `CAPTURE` buffers using `VIDIOC_REQBUFS()`.

   - **Required fields:**

     - **`count`**

       set to 0.

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

     - **`memory`**

       follows standard semantics.

10. Allocate `CAPTURE` buffers via `VIDIOC_REQBUFS()` on the `CAPTURE` queue.

    - **Required fields:**

      - **`count`**

        requested number of buffers to allocate; greater than zero.

      - **`type`**

        a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

      - **`memory`**

        follows standard semantics.

    - **Returned fields:**

      - **`count`**

        actual number of buffers allocated.

    > [!WARNING]
    >
    > The actual number of allocated buffers may differ from the `count` given. The client must check the updated value of `count` after the call returns.

    > [!NOTE]
    >
    > To allocate more than the minimum number of buffers (for pipeline depth), the client may query the `V4L2_CID_MIN_BUFFERS_FOR_CAPTURE` control to get the minimum number of buffers required, and pass the obtained value plus the number of additional buffers needed in the `count` field to `VIDIOC_REQBUFS()`.

    Alternatively, `VIDIOC_CREATE_BUFS()` on the `CAPTURE` queue can be used to have more control over buffer allocation. For example, by allocating buffers larger than the current `CAPTURE` format, future resolution changes can be accommodated.

    - **Required fields:**

      - **`count`**

        requested number of buffers to allocate; greater than zero.

      - **`type`**

        a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

      - **`memory`**

        follows standard semantics.

      - **`format`**

        a format representing the maximum framebuffer resolution to be accommodated by newly allocated buffers.

    - **Returned fields:**

      - **`count`**

        adjusted to the number of allocated buffers.

    > [!WARNING]
    >
    > The actual number of allocated buffers may differ from the `count` given. The client must check the updated value of `count` after the call returns.

    > [!NOTE]
    >
    > To allocate buffers for a format different than parsed from the stream metadata, the client must proceed as follows, before the metadata parsing is initiated:
    >
    > - set width and height of the `OUTPUT` format to desired coded resolution to let the decoder configure the `CAPTURE` format appropriately,
    >
    > - query the `CAPTURE` format using `VIDIOC_G_FMT()` and save it until this step.
    >
    > The format obtained in the query may be then used with `VIDIOC_CREATE_BUFS()` in this step to allocate the buffers.

11. Call `VIDIOC_STREAMON()` on the `CAPTURE` queue to start decoding frames.

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

## Decoding

This state is reached after the `Capture Setup` sequence finishes successfully. In this state, the client queues and dequeues buffers to both queues via `VIDIOC_QBUF()` and `VIDIOC_DQBUF()`, following the standard semantics.

The content of the source `OUTPUT` buffers depends on the active coded pixel format and may be affected by codec-specific extended controls, as stated in the documentation of each format.

Both queues operate independently, following the standard behavior of V4L2 buffer queues and memory-to-memory devices. In addition, the order of decoded frames dequeued from the `CAPTURE` queue may differ from the order of queuing coded frames to the `OUTPUT` queue, due to properties of the selected coded format, e.g. frame reordering.

The client must not assume any direct relationship between `CAPTURE` and `OUTPUT` buffers and any specific timing of buffers becoming available to dequeue. Specifically:

- a buffer queued to `OUTPUT` may result in no buffers being produced on `CAPTURE` (e.g. if it does not contain encoded data, or if only metadata syntax structures are present in it),

- a buffer queued to `OUTPUT` may result in more than one buffer produced on `CAPTURE` (if the encoded data contained more than one frame, or if returning a decoded frame allowed the decoder to return a frame that preceded it in decode, but succeeded it in the display order),

- a buffer queued to `OUTPUT` may result in a buffer being produced on `CAPTURE` later into decode process, and/or after processing further `OUTPUT` buffers, or be returned out of order, e.g. if display reordering is used,

- buffers may become available on the `CAPTURE` queue without additional buffers queued to `OUTPUT` (e.g. during drain or `EOS`), because of the `OUTPUT` buffers queued in the past whose decoding results are only available at later time, due to specifics of the decoding process.

> [!NOTE]
>
> To allow matching decoded `CAPTURE` buffers with `OUTPUT` buffers they originated from, the client can set the `timestamp` field of the `v4l2_buffer` struct when queuing an `OUTPUT` buffer. The `CAPTURE` buffer(s), which resulted from decoding that `OUTPUT` buffer will have their `timestamp` field set to the same value when dequeued.
>
> In addition to the straightforward case of one `OUTPUT` buffer producing one `CAPTURE` buffer, the following cases are defined:
>
> - one `OUTPUT` buffer generates multiple `CAPTURE` buffers: the same `OUTPUT` timestamp will be copied to multiple `CAPTURE` buffers.
>
> - multiple `OUTPUT` buffers generate one `CAPTURE` buffer: timestamp of the `OUTPUT` buffer queued first will be copied.
>
> - the decoding order differs from the display order (i.e. the `CAPTURE` buffers are out-of-order compared to the `OUTPUT` buffers): `CAPTURE` timestamps will not retain the order of `OUTPUT` timestamps.

> [!NOTE]
>
> The backing memory of `CAPTURE` buffers that are used as reference frames by the stream may be read by the hardware even after they are dequeued. Consequently, the client should avoid writing into this memory while the `CAPTURE` queue is streaming. Failure to observe this may result in corruption of decoded frames.
>
> Similarly, when using a memory type other than `V4L2_MEMORY_MMAP`, the client should make sure that each `CAPTURE` buffer is always queued with the same backing memory for as long as the `CAPTURE` queue is streaming. The reason for this is that V4L2 buffer indices can be used by drivers to identify frames. Thus, if the backing memory of a reference frame is submitted under a different buffer ID, the driver may misidentify it and decode a new frame into it while it is still in use, resulting in corruption of the following frames.

During the decoding, the decoder may initiate one of the special sequences, as listed below. The sequences will result in the decoder returning all the `CAPTURE` buffers that originated from all the `OUTPUT` buffers processed before the sequence started. Last of the buffers will have the `V4L2_BUF_FLAG_LAST` flag set. To determine the sequence to follow, the client must check if there is any pending event and:

- if a `V4L2_EVENT_SOURCE_CHANGE` event with `changes` set to `V4L2_EVENT_SRC_CH_RESOLUTION` is pending, the `Dynamic Resolution Change` sequence needs to be followed,

- if a `V4L2_EVENT_EOS` event is pending, the `End of Stream` sequence needs to be followed.

Some of the sequences can be intermixed with each other and need to be handled as they happen. The exact operation is documented for each sequence.

Should a decoding error occur, it will be reported to the client with the level of details depending on the decoder capabilities. Specifically:

- the CAPTURE buffer that contains the results of the failed decode operation will be returned with the V4L2_BUF_FLAG_ERROR flag set,

- if the decoder is able to precisely report the OUTPUT buffer that triggered the error, such buffer will be returned with the V4L2_BUF_FLAG_ERROR flag set.

In case of a fatal failure that does not allow the decoding to continue, any further operations on corresponding decoder file handle will return the -EIO error code. The client may close the file handle and open a new one, or alternatively reinitialize the instance by stopping streaming on both queues, releasing all buffers and performing the Initialization sequence again.

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

## Seek

Seek is controlled by the `OUTPUT` queue, as it is the source of coded data. The seek does not require any specific operation on the `CAPTURE` queue, but it may be affected as per normal decoder operation.

1. Stop the `OUTPUT` queue to begin the seek sequence via `VIDIOC_STREAMOFF()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

   - The decoder will drop all the pending `OUTPUT` buffers and they must be treated as returned to the client (following standard semantics).

2. Restart the `OUTPUT` queue via `VIDIOC_STREAMON()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

   - The decoder will start accepting new source bytestream buffers after the call returns.

3. Start queuing buffers containing coded data after the seek to the `OUTPUT` queue until a suitable resume point is found.

   > [!NOTE]
   >
   > There is no requirement to begin queuing coded data starting exactly from a resume point (e.g. SPS or a keyframe). Any queued `OUTPUT` buffers will be processed and returned to the client until a suitable resume point is found.  While looking for a resume point, the decoder should not produce any decoded frames into `CAPTURE` buffers.
   >
   > Some hardware is known to mishandle seeks to a non-resume point. Such an operation may result in an unspecified number of corrupted decoded frames being made available on the `CAPTURE` queue. Drivers must ensure that no fatal decoding errors or crashes occur, and implement any necessary handling and workarounds for hardware issues related to seek operations.

   > [!WARNING]
   >
   > In case of the H.264/HEVC codec, the client must take care not to seek over a change of SPS/PPS. Even though the target frame could be a keyframe, the stale SPS/PPS inside decoder state would lead to undefined results when decoding. Although the decoder must handle that case without a crash or a fatal decode error, the client must not expect a sensible decode output.
   >
   > If the hardware can detect such corrupted decoded frames, then corresponding buffers will be returned to the client with the V4L2_BUF_FLAG_ERROR set. See the `Decoding` section for further description of decode error reporting.

4. After a resume point is found, the decoder will start returning `CAPTURE` buffers containing decoded frames.

> [!IMPORTANT]
>
> A seek may result in the `Dynamic Resolution Change` sequence being initiated, due to the seek target having decoding parameters different from the part of the stream decoded before the seek. The sequence must be handled as per normal decoder operation.

> [!WARNING]
>
> It is not specified when the `CAPTURE` queue starts producing buffers containing decoded data from the `OUTPUT` buffers queued after the seek, as it operates independently from the `OUTPUT` queue.
>
> The decoder may return a number of remaining `CAPTURE` buffers containing decoded frames originating from the `OUTPUT` buffers queued before the seek sequence is performed.
>
> The `VIDIOC_STREAMOFF` operation discards any remaining queued `OUTPUT` buffers, which means that not all of the `OUTPUT` buffers queued before the seek sequence may have matching `CAPTURE` buffers produced.  For example, given the sequence of operations on the `OUTPUT` queue:
>
> > QBUF(A), QBUF(B), STREAMOFF(), STREAMON(), QBUF(G), QBUF(H),
>
> any of the following results on the `CAPTURE` queue is allowed:
>
> > \{A', B', G', H'\}, \{A', G', H'\}, \{G', H'\}.
>
> To determine the CAPTURE buffer containing the first decoded frame after the seek, the client may observe the timestamps to match the CAPTURE and OUTPUT buffers or use V4L2_DEC_CMD_STOP and V4L2_DEC_CMD_START to drain the decoder.

> [!NOTE]
>
> To achieve instantaneous seek, the client may restart streaming on the `CAPTURE` queue too to discard decoded, but not yet dequeued buffers.

<a id="rst-dynamic-resolution-change"></a>

## Dynamic Resolution Change

Streams that include resolution metadata in the bytestream may require switching to a different resolution during the decoding.

> [!NOTE]
>
> Not all decoders can detect resolution changes. Those that do set the `V4L2_FMT_FLAG_DYN_RESOLUTION` flag for the coded format when `VIDIOC_ENUM_FMT()` is called.

The sequence starts when the decoder detects a coded frame with one or more of the following parameters different from those previously established (and reflected by corresponding queries):

- coded resolution (`OUTPUT` width and height),

- visible resolution (selection rectangles),

- the minimum number of buffers needed for decoding,

- bit-depth of the bitstream has been changed,

- colorspace of the bitstream has been changed, but it doesn't require buffer reallocation.

Whenever that happens, the decoder must proceed as follows:

1. After encountering a resolution change in the stream, the decoder sends a `V4L2_EVENT_SOURCE_CHANGE` event with `changes` set to `V4L2_EVENT_SRC_CH_RESOLUTION`.

   > [!IMPORTANT]
   >
   > Any client query issued after the decoder queues the event will return values applying to the stream after the resolution change, including queue formats, selection rectangles and controls.

2. The decoder will then process and decode all remaining buffers from before the resolution change point.

   - The last buffer from before the change must be marked with the `V4L2_BUF_FLAG_LAST` flag, similarly to the `Drain` sequence above.

   > [!WARNING]
   >
   > The last buffer may be empty (with `v4l2_buffer` `bytesused` = 0) and in that case it must be ignored by the client, as it does not contain a decoded frame.

   > [!NOTE]
   >
   > Any attempt to dequeue more `CAPTURE` buffers beyond the buffer marked with `V4L2_BUF_FLAG_LAST` will result in a -EPIPE error from `VIDIOC_DQBUF()`.

The client must continue the sequence as described below to continue the decoding process.

1. Dequeue the source change event.

   > [!IMPORTANT]
   >
   > A source change triggers an implicit decoder drain, similar to the explicit `Drain` sequence. The decoder is stopped after it completes. The decoding process must be resumed with either a pair of calls to `VIDIOC_STREAMOFF()` and `VIDIOC_STREAMON()` on the `CAPTURE` queue, or a call to `VIDIOC_DECODER_CMD()` with the `V4L2_DEC_CMD_START` command.

2. Continue with the `Capture Setup` sequence.

> [!NOTE]
>
> During the resolution change sequence, the `OUTPUT` queue must remain streaming. Calling `VIDIOC_STREAMOFF()` on the `OUTPUT` queue would abort the sequence and initiate a seek.
>
> In principle, the `OUTPUT` queue operates separately from the `CAPTURE` queue and this remains true for the duration of the entire resolution change sequence as well.
>
> The client should, for best performance and simplicity, keep queuing/dequeuing buffers to/from the `OUTPUT` queue even while processing this sequence.

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

## Drain

To ensure that all queued `OUTPUT` buffers have been processed and related `CAPTURE` buffers are given to the client, the client must follow the drain sequence described below. After the drain sequence ends, the client has received all decoded frames for all `OUTPUT` buffers queued before the sequence was started.

1. Begin drain by issuing `VIDIOC_DECODER_CMD()`.

   - **Required fields:**

     - **`cmd`**

       set to `V4L2_DEC_CMD_STOP`.

     - **`flags`**

       set to 0.

     - **`pts`**

       set to 0.

   > [!WARNING]
   >
   > The sequence can be only initiated if both `OUTPUT` and `CAPTURE` queues are streaming. For compatibility reasons, the call to `VIDIOC_DECODER_CMD()` will not fail even if any of the queues is not streaming, but at the same time it will not initiate the `Drain` sequence and so the steps described below would not be applicable.

2. Any `OUTPUT` buffers queued by the client before the `VIDIOC_DECODER_CMD()` was issued will be processed and decoded as normal. The client must continue to handle both queues independently, similarly to normal decode operation. This includes:

   - handling any operations triggered as a result of processing those buffers, such as the `Dynamic Resolution Change` sequence, before continuing with the drain sequence,

   - queuing and dequeuing `CAPTURE` buffers, until a buffer marked with the `V4L2_BUF_FLAG_LAST` flag is dequeued,

     > [!WARNING]
     >
     > The last buffer may be empty (with `v4l2_buffer` `bytesused` = 0) and in that case it must be ignored by the client, as it does not contain a decoded frame.

     > [!NOTE]
     >
     > Any attempt to dequeue more `CAPTURE` buffers beyond the buffer marked with `V4L2_BUF_FLAG_LAST` will result in a -EPIPE error from `VIDIOC_DQBUF()`.

   - dequeuing processed `OUTPUT` buffers, until all the buffers queued before the `V4L2_DEC_CMD_STOP` command are dequeued,

   - dequeuing the `V4L2_EVENT_EOS` event, if the client subscribed to it.

   > [!NOTE]
   >
   > For backwards compatibility, the decoder will signal a `V4L2_EVENT_EOS` event when the last frame has been decoded and all frames are ready to be dequeued. It is a deprecated behavior and the client must not rely on it. The `V4L2_BUF_FLAG_LAST` buffer flag should be used instead.

3. Once all the `OUTPUT` buffers queued before the `V4L2_DEC_CMD_STOP` call are dequeued and the last `CAPTURE` buffer is dequeued, the decoder is stopped and it will accept, but not process, any newly queued `OUTPUT` buffers until the client issues any of the following operations:

   - `V4L2_DEC_CMD_START` - the decoder will not be reset and will resume operation normally, with all the state from before the drain,

   - a pair of `VIDIOC_STREAMOFF()` and `VIDIOC_STREAMON()` on the `CAPTURE` queue - the decoder will resume the operation normally, however any `CAPTURE` buffers still in the queue will be returned to the client,

   - a pair of `VIDIOC_STREAMOFF()` and `VIDIOC_STREAMON()` on the `OUTPUT` queue - any pending source buffers will be returned to the client and the `Seek` sequence will be triggered.

> [!NOTE]
>
> Once the drain sequence is initiated, the client needs to drive it to completion, as described by the steps above, unless it aborts the process by issuing `VIDIOC_STREAMOFF()` on any of the `OUTPUT` or `CAPTURE` queues.  The client is not allowed to issue `V4L2_DEC_CMD_START` or `V4L2_DEC_CMD_STOP` again while the drain sequence is in progress and they will fail with -EBUSY error code if attempted.
>
> Although not mandatory, the availability of decoder commands may be queried using `VIDIOC_TRY_DECODER_CMD()`.

<a id="rst-end-of-stream"></a>

## End of Stream

If the decoder encounters an end of stream marking in the stream, the decoder will initiate the `Drain` sequence, which the client must handle as described above, skipping the initial `VIDIOC_DECODER_CMD()`.

<a id="rst-commit-points"></a>

## Commit Points

Setting formats and allocating buffers trigger changes in the behavior of the decoder.

1. Setting the format on the `OUTPUT` queue may change the set of formats supported/advertised on the `CAPTURE` queue. In particular, it also means that the `CAPTURE` format may be reset and the client must not rely on the previously set format being preserved.

2. Enumerating formats on the `CAPTURE` queue always returns only formats supported for the current `OUTPUT` format.

3. Setting the format on the `CAPTURE` queue does not change the list of formats available on the `OUTPUT` queue. An attempt to set a `CAPTURE` format that is not supported for the currently selected `OUTPUT` format will result in the decoder adjusting the requested `CAPTURE` format to a supported one.

4. Enumerating formats on the `OUTPUT` queue always returns the full set of supported coded formats, irrespectively of the current `CAPTURE` format.

5. While buffers are allocated on any of the `OUTPUT` or `CAPTURE` queues, the client must not change the format on the `OUTPUT` queue. Drivers will return the -EBUSY error code for any such format change attempt.

To summarize, setting formats and allocation must always start with the `OUTPUT` queue and the `OUTPUT` queue is the master that governs the set of supported formats for the `CAPTURE` queue.

---

# Memory-to-Memory Stateful Video Encoder Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> A stateful video encoder takes raw video frames in display order and encodes them into a bytestream. It generates complete chunks of the bytestream, including all metadata, headers, etc. The resulting bytestream does not require any…

<a id="rst-memory-to-memory-stateful-video-encoder-interface"></a>
<a id="rst-encoder"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

A stateful video encoder takes raw video frames in display order and encodes them into a bytestream. It generates complete chunks of the bytestream, including all metadata, headers, etc. The resulting bytestream does not require any further post-processing by the client.

Performing software stream processing, header generation etc. in the driver in order to support this interface is strongly discouraged. In case such operations are needed, use of the Stateless Video Encoder Interface (in development) is strongly advised.

<a id="rst-conventions-and-notations-used-in-this-document"></a>

## Conventions and Notations Used in This Document

1. The general V4L2 API rules apply if not specified in this document otherwise.

2. The meaning of words "must", "may", "should", etc. is as per [RFC 2119](<https://tools.ietf.org/html/rfc2119>)<a id="rst-rfc-2119"></a>.

3. All steps not marked "optional" are required.

4. `VIDIOC_G_EXT_CTRLS()` and `VIDIOC_S_EXT_CTRLS()` may be used interchangeably with `VIDIOC_G_CTRL()` and `VIDIOC_S_CTRL()`, unless specified otherwise.

5. Single-planar API (see [Single- and multi-planar APIs](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>)) and applicable structures may be used interchangeably with multi-planar API, unless specified otherwise, depending on encoder capabilities and following the general V4L2 guidelines.

6. i = \[a..b\]: sequence of integers from a to b, inclusive, i.e. i = \[0..2\]: i = 0, 1, 2.

7. Given an `OUTPUT` buffer A, then A' represents a buffer on the `CAPTURE` queue containing data that resulted from processing buffer A.

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

## Glossary

Refer to [Glossary](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder-glossary>).

<a id="rst-state-machine"></a>

## State Machine

```mermaid
flowchart TB
  n0((("Encoding")))
  n1(("Initialization"))
  n2(("Stopped"))
  n3(("Drain"))
  n4(("Reset"))
  n5(("#160;"))
  n5 -->|"open()"| n1
  n1 -->|"Both queues streaming"| n0
  n0 -->|"V4L2_ENC_CMD_STOP"| n3
  n0 -->|"VIDIOC_STREAMOFF(CAPTURE)"| n4
  n0 -->|"VIDIOC_STREAMOFF(OUTPUT)"| n2
  n0 --> n0
  n3 -->|"All CAPTURE<br/>buffers dequeued<br/>or<br/>VIDIOC_STREAMOFF(OUTPUT)"| n2
  n3 -->|"VIDIOC_STREAMOFF(CAPTURE)"| n4
  n4 -->|"VIDIOC_STREAMON(CAPTURE)"| n0
  n4 -->|"VIDIOC_REQBUFS(OUTPUT, 0)"| n1
  n2 -->|"V4L2_ENC_CMD_START<br/>or<br/>VIDIOC_STREAMON(OUTPUT)"| n0
  n2 -->|"VIDIOC_STREAMOFF(CAPTURE)"| n4
  style n5 fill:#333,stroke:#333
```

Encoder State Machine

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

1. To enumerate the set of coded formats supported by the encoder, the client may call `VIDIOC_ENUM_FMT()` on `CAPTURE`.

   - The full set of supported formats will be returned, regardless of the format set on `OUTPUT`.

2. To enumerate the set of supported raw formats, the client may call `VIDIOC_ENUM_FMT()` on `OUTPUT`.

   - Only the formats supported for the format currently active on `CAPTURE` will be returned.

   - In order to enumerate raw formats supported by a given coded format, the client must first set that coded format on `CAPTURE` and then enumerate the formats on `OUTPUT`.

3. The client may use `VIDIOC_ENUM_FRAMESIZES()` to detect supported resolutions for a given format, passing the desired pixel format in `v4l2_frmsizeenum` `pixel_format`.

   - Values returned by `VIDIOC_ENUM_FRAMESIZES()` for a coded pixel format will include all possible coded resolutions supported by the encoder for the given coded pixel format.

   - Values returned by `VIDIOC_ENUM_FRAMESIZES()` for a raw pixel format will include all possible frame buffer resolutions supported by the encoder for the given raw pixel format and coded format currently set on `CAPTURE`.

4. The client may use `VIDIOC_ENUM_FRAMEINTERVALS()` to detect supported frame intervals for a given format and resolution, passing the desired pixel format in `v4l2_frmivalenum` `pixel_format` and the resolution in `v4l2_frmivalenum` `width` and `v4l2_frmivalenum` `height`.

   - Values returned by `VIDIOC_ENUM_FRAMEINTERVALS()` for a coded pixel format and coded resolution will include all possible frame intervals supported by the encoder for the given coded pixel format and resolution.

   - Values returned by `VIDIOC_ENUM_FRAMEINTERVALS()` for a raw pixel format and resolution will include all possible frame intervals supported by the encoder for the given raw pixel format and resolution and for the coded format, coded resolution and coded frame interval currently set on `CAPTURE`.

   - Support for `VIDIOC_ENUM_FRAMEINTERVALS()` is optional. If it is not implemented, then there are no special restrictions other than the limits of the codec itself.

5. Supported profiles and levels for the coded format currently set on `CAPTURE`, if applicable, may be queried using their respective controls via `VIDIOC_QUERYCTRL()`.

6. Any additional encoder capabilities may be discovered by querying their respective controls.

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

## Initialization

1. Set the coded format on the `CAPTURE` queue via `VIDIOC_S_FMT()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

     - **`pixelformat`**

       the coded format to be produced.

     - **`sizeimage`**

       desired size of `CAPTURE` buffers; the encoder may adjust it to match hardware requirements.

     - **`width`, `height`**

       ignored (read-only).

     - **other fields**

       follow standard semantics.

   - **Returned fields:**

     - **`sizeimage`**

       adjusted size of `CAPTURE` buffers.

     - **`width`, `height`**

       the coded size selected by the encoder based on current state, e.g. `OUTPUT` format, selection rectangles, etc. (read-only).

   > [!IMPORTANT]
   >
   > Changing the `CAPTURE` format may change the currently set `OUTPUT` format. How the new `OUTPUT` format is determined is up to the encoder and the client must ensure it matches its needs afterwards.

2. **Optional.** Enumerate supported `OUTPUT` formats (raw formats for source) for the selected coded format via `VIDIOC_ENUM_FMT()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **other fields**

       follow standard semantics.

   - **Returned fields:**

     - **`pixelformat`**

       raw format supported for the coded format currently selected on the `CAPTURE` queue.

     - **other fields**

       follow standard semantics.

3. Set the raw source format on the `OUTPUT` queue via `VIDIOC_S_FMT()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **`pixelformat`**

       raw format of the source.

     - **`width`, `height`**

       source resolution.

     - **other fields**

       follow standard semantics.

   - **Returned fields:**

     - **`width`, `height`**

       may be adjusted to match encoder minimums, maximums and alignment requirements, as required by the currently selected formats, as reported by `VIDIOC_ENUM_FRAMESIZES()`.

     - **other fields**

       follow standard semantics.

   - Setting the `OUTPUT` format will reset the selection rectangles to their default values, based on the new resolution, as described in the next step.

4. Set the raw frame interval on the `OUTPUT` queue via `VIDIOC_S_PARM()`. This also sets the coded frame interval on the `CAPTURE` queue to the same value.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **`parm.output`**

       set all fields except `parm.output.timeperframe` to 0.

     - **`parm.output.timeperframe`**

       the desired frame interval; the encoder may adjust it to match hardware requirements.

   - **Returned fields:**

     - **`parm.output.timeperframe`**

       the adjusted frame interval.

   > [!IMPORTANT]
   >
   > Changing the `OUTPUT` frame interval *also* sets the framerate that the encoder uses to encode the video. So setting the frame interval to 1/24 (or 24 frames per second) will produce a coded video stream that can be played back at that speed. The frame interval for the `OUTPUT` queue is just a hint, the application may provide raw frames at a different rate. It can be used by the driver to help schedule multiple encoders running in parallel.
   >
   > In the next step the `CAPTURE` frame interval can optionally be changed to a different value. This is useful for off-line encoding were the coded frame interval can be different from the rate at which raw frames are supplied.

   > [!IMPORTANT]
   >
   > `timeperframe` deals with *frames*, not fields. So for interlaced formats this is the time per two fields, since a frame consists of a top and a bottom field.

   > [!NOTE]
   >
   > It is due to historical reasons that changing the `OUTPUT` frame interval also changes the coded frame interval on the `CAPTURE` queue. Ideally these would be independent settings, but that would break the existing API.

5. **Optional** Set the coded frame interval on the `CAPTURE` queue via `VIDIOC_S_PARM()`. This is only necessary if the coded frame interval is different from the raw frame interval, which is typically the case for off-line encoding. Support for this feature is signalled by the [V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags>) format flag.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

     - **`parm.capture`**

       set all fields except `parm.capture.timeperframe` to 0.

     - **`parm.capture.timeperframe`**

       the desired coded frame interval; the encoder may adjust it to match hardware requirements.

   - **Returned fields:**

     - **`parm.capture.timeperframe`**

       the adjusted frame interval.

   > [!IMPORTANT]
   >
   > Changing the `CAPTURE` frame interval sets the framerate for the coded video. It does *not* set the rate at which buffers arrive on the `CAPTURE` queue, that depends on how fast the encoder is and how fast raw frames are queued on the `OUTPUT` queue.

   > [!IMPORTANT]
   >
   > `timeperframe` deals with *frames*, not fields. So for interlaced formats this is the time per two fields, since a frame consists of a top and a bottom field.

   > [!NOTE]
   >
   > Not all drivers support this functionality, in that case just set the desired coded frame interval for the `OUTPUT` queue.
   >
   > However, drivers that can schedule multiple encoders based on the `OUTPUT` frame interval must support this optional feature.

6. **Optional.** Set the visible resolution for the stream metadata via `VIDIOC_S_SELECTION()` on the `OUTPUT` queue if it is desired to be different than the full OUTPUT resolution.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **`target`**

       set to `V4L2_SEL_TGT_CROP`.

     - **`r.left`, `r.top`, `r.width`, `r.height`**

       visible rectangle; this must fit within the `V4L2_SEL_TGT_CROP_BOUNDS` rectangle and may be subject to adjustment to match codec and hardware constraints.

   - **Returned fields:**

     - **`r.left`, `r.top`, `r.width`, `r.height`**

       visible rectangle adjusted by the encoder.

   - The following selection targets are supported on `OUTPUT`:

     - **`V4L2_SEL_TGT_CROP_BOUNDS`**

       equal to the full source frame, matching the active `OUTPUT` format.

     - **`V4L2_SEL_TGT_CROP_DEFAULT`**

       equal to `V4L2_SEL_TGT_CROP_BOUNDS`.

     - **`V4L2_SEL_TGT_CROP`**

       rectangle within the source buffer to be encoded into the `CAPTURE` stream; defaults to `V4L2_SEL_TGT_CROP_DEFAULT`.

       > [!NOTE]
       >
       > A common use case for this selection target is encoding a source video with a resolution that is not a multiple of a macroblock, e.g.  the common 1920x1080 resolution may require the source buffers to be aligned to 1920x1088 for codecs with 16x16 macroblock size. To avoid encoding the padding, the client needs to explicitly configure this selection target to 1920x1080.

   > [!WARNING]
   >
   > The encoder may adjust the crop/compose rectangles to the nearest supported ones to meet codec and hardware requirements. The client needs to check the adjusted rectangle returned by `VIDIOC_S_SELECTION()`.

7. Allocate buffers for both `OUTPUT` and `CAPTURE` via `VIDIOC_REQBUFS()`. This may be performed in any order.

   - **Required fields:**

     - **`count`**

       requested number of buffers to allocate; greater than zero.

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT` or `CAPTURE`.

     - **other fields**

       follow standard semantics.

   - **Returned fields:**

     - **`count`**

       actual number of buffers allocated.

   > [!WARNING]
   >
   > The actual number of allocated buffers may differ from the `count` given. The client must check the updated value of `count` after the call returns.

   > [!NOTE]
   >
   > To allocate more than the minimum number of OUTPUT buffers (for pipeline depth), the client may query the `V4L2_CID_MIN_BUFFERS_FOR_OUTPUT` control to get the minimum number of buffers required, and pass the obtained value plus the number of additional buffers needed in the `count` field to `VIDIOC_REQBUFS()`.

   Alternatively, `VIDIOC_CREATE_BUFS()` can be used to have more control over buffer allocation.

   - **Required fields:**

     - **`count`**

       requested number of buffers to allocate; greater than zero.

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **other fields**

       follow standard semantics.

   - **Returned fields:**

     - **`count`**

       adjusted to the number of allocated buffers.

8. Begin streaming on both `OUTPUT` and `CAPTURE` queues via `VIDIOC_STREAMON()`. This may be performed in any order. The actual encoding process starts when both queues start streaming.

> [!NOTE]
>
> If the client stops the `CAPTURE` queue during the encode process and then restarts it again, the encoder will begin generating a stream independent from the stream generated before the stop. The exact constraints depend on the coded format, but may include the following implications:
>
> - encoded frames produced after the restart must not reference any frames produced before the stop, e.g. no long term references for H.264/HEVC,
>
> - any headers that must be included in a standalone stream must be produced again, e.g. SPS and PPS for H.264/HEVC.

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

## Encoding

This state is reached after the `Initialization` sequence finishes successfully.  In this state, the client queues and dequeues buffers to both queues via `VIDIOC_QBUF()` and `VIDIOC_DQBUF()`, following the standard semantics.

The content of encoded `CAPTURE` buffers depends on the active coded pixel format and may be affected by codec-specific extended controls, as stated in the documentation of each format.

Both queues operate independently, following standard behavior of V4L2 buffer queues and memory-to-memory devices. In addition, the order of encoded frames dequeued from the `CAPTURE` queue may differ from the order of queuing raw frames to the `OUTPUT` queue, due to properties of the selected coded format, e.g. frame reordering.

The client must not assume any direct relationship between `CAPTURE` and `OUTPUT` buffers and any specific timing of buffers becoming available to dequeue. Specifically:

- a buffer queued to `OUTPUT` may result in more than one buffer produced on `CAPTURE` (for example, if returning an encoded frame allowed the encoder to return a frame that preceded it in display, but succeeded it in the decode order; however, there may be other reasons for this as well),

- a buffer queued to `OUTPUT` may result in a buffer being produced on `CAPTURE` later into encode process, and/or after processing further `OUTPUT` buffers, or be returned out of order, e.g. if display reordering is used,

- buffers may become available on the `CAPTURE` queue without additional buffers queued to `OUTPUT` (e.g. during drain or `EOS`), because of the `OUTPUT` buffers queued in the past whose encoding results are only available at later time, due to specifics of the encoding process,

- buffers queued to `OUTPUT` may not become available to dequeue instantly after being encoded into a corresponding `CAPTURE` buffer, e.g. if the encoder needs to use the frame as a reference for encoding further frames.

> [!NOTE]
>
> To allow matching encoded `CAPTURE` buffers with `OUTPUT` buffers they originated from, the client can set the `timestamp` field of the `v4l2_buffer` struct when queuing an `OUTPUT` buffer. The `CAPTURE` buffer(s), which resulted from encoding that `OUTPUT` buffer will have their `timestamp` field set to the same value when dequeued.
>
> In addition to the straightforward case of one `OUTPUT` buffer producing one `CAPTURE` buffer, the following cases are defined:
>
> - one `OUTPUT` buffer generates multiple `CAPTURE` buffers: the same `OUTPUT` timestamp will be copied to multiple `CAPTURE` buffers,
>
> - the encoding order differs from the presentation order (i.e. the `CAPTURE` buffers are out-of-order compared to the `OUTPUT` buffers): `CAPTURE` timestamps will not retain the order of `OUTPUT` timestamps.

> [!NOTE]
>
> To let the client distinguish between frame types (keyframes, intermediate frames; the exact list of types depends on the coded format), the `CAPTURE` buffers will have corresponding flag bits set in their `v4l2_buffer` struct when dequeued. See the documentation of `v4l2_buffer` and each coded pixel format for exact list of flags and their meanings.

Should an encoding error occur, it will be reported to the client with the level of details depending on the encoder capabilities. Specifically:

- the `CAPTURE` buffer (if any) that contains the results of the failed encode operation will be returned with the `V4L2_BUF_FLAG_ERROR` flag set,

- if the encoder is able to precisely report the `OUTPUT` buffer(s) that triggered the error, such buffer(s) will be returned with the `V4L2_BUF_FLAG_ERROR` flag set.

> [!NOTE]
>
> If a `CAPTURE` buffer is too small then it is just returned with the `V4L2_BUF_FLAG_ERROR` flag set. More work is needed to detect that this error occurred because the buffer was too small, and to provide support to free existing buffers that were too small.

In case of a fatal failure that does not allow the encoding to continue, any further operations on corresponding encoder file handle will return the -EIO error code. The client may close the file handle and open a new one, or alternatively reinitialize the instance by stopping streaming on both queues, releasing all buffers and performing the Initialization sequence again.

<a id="rst-encoding-parameter-changes"></a>

## Encoding Parameter Changes

The client is allowed to use `VIDIOC_S_CTRL()` to change encoder parameters at any time. The availability of parameters is encoder-specific and the client must query the encoder to find the set of available controls.

The ability to change each parameter during encoding is encoder-specific, as per the standard semantics of the V4L2 control interface. The client may attempt to set a control during encoding and if the operation fails with the -EBUSY error code, the `CAPTURE` queue needs to be stopped for the configuration change to be allowed. To do this, it may follow the `Drain` sequence to avoid losing the already queued/encoded frames.

The timing of parameter updates is encoder-specific, as per the standard semantics of the V4L2 control interface. If the client needs to apply the parameters exactly at specific frame, using the Request API ([Request API](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>)) should be considered, if supported by the encoder.

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

## Drain

To ensure that all the queued `OUTPUT` buffers have been processed and the related `CAPTURE` buffers are given to the client, the client must follow the drain sequence described below. After the drain sequence ends, the client has received all encoded frames for all `OUTPUT` buffers queued before the sequence was started.

1. Begin the drain sequence by issuing `VIDIOC_ENCODER_CMD()`.

   - **Required fields:**

     - **`cmd`**

       set to `V4L2_ENC_CMD_STOP`.

     - **`flags`**

       set to 0.

     - **`pts`**

       set to 0.

   > [!WARNING]
   >
   > The sequence can be only initiated if both `OUTPUT` and `CAPTURE` queues are streaming. For compatibility reasons, the call to `VIDIOC_ENCODER_CMD()` will not fail even if any of the queues is not streaming, but at the same time it will not initiate the `Drain` sequence and so the steps described below would not be applicable.

2. Any `OUTPUT` buffers queued by the client before the `VIDIOC_ENCODER_CMD()` was issued will be processed and encoded as normal. The client must continue to handle both queues independently, similarly to normal encode operation. This includes:

   - queuing and dequeuing `CAPTURE` buffers, until a buffer marked with the `V4L2_BUF_FLAG_LAST` flag is dequeued,

     > [!WARNING]
     >
     > The last buffer may be empty (with `v4l2_buffer` `bytesused` = 0) and in that case it must be ignored by the client, as it does not contain an encoded frame.

     > [!NOTE]
     >
     > Any attempt to dequeue more `CAPTURE` buffers beyond the buffer marked with `V4L2_BUF_FLAG_LAST` will result in a -EPIPE error from `VIDIOC_DQBUF()`.

   - dequeuing processed `OUTPUT` buffers, until all the buffers queued before the `V4L2_ENC_CMD_STOP` command are dequeued,

   - dequeuing the `V4L2_EVENT_EOS` event, if the client subscribes to it.

   > [!NOTE]
   >
   > For backwards compatibility, the encoder will signal a `V4L2_EVENT_EOS` event when the last frame has been encoded and all frames are ready to be dequeued. It is deprecated behavior and the client must not rely on it. The `V4L2_BUF_FLAG_LAST` buffer flag should be used instead.

3. Once all `OUTPUT` buffers queued before the `V4L2_ENC_CMD_STOP` call are dequeued and the last `CAPTURE` buffer is dequeued, the encoder is stopped and it will accept, but not process any newly queued `OUTPUT` buffers until the client issues any of the following operations:

   - `V4L2_ENC_CMD_START` - the encoder will not be reset and will resume operation normally, with all the state from before the drain,

   - a pair of `VIDIOC_STREAMOFF()` and `VIDIOC_STREAMON()` on the `CAPTURE` queue - the encoder will be reset (see the `Reset` sequence) and then resume encoding,

   - a pair of `VIDIOC_STREAMOFF()` and `VIDIOC_STREAMON()` on the `OUTPUT` queue - the encoder will resume operation normally, however any source frames queued to the `OUTPUT` queue between `V4L2_ENC_CMD_STOP` and `VIDIOC_STREAMOFF()` will be discarded.

> [!NOTE]
>
> Once the drain sequence is initiated, the client needs to drive it to completion, as described by the steps above, unless it aborts the process by issuing `VIDIOC_STREAMOFF()` on any of the `OUTPUT` or `CAPTURE` queues.  The client is not allowed to issue `V4L2_ENC_CMD_START` or `V4L2_ENC_CMD_STOP` again while the drain sequence is in progress and they will fail with -EBUSY error code if attempted.
>
> For reference, handling of various corner cases is described below:
>
> - In case of no buffer in the `OUTPUT` queue at the time the `V4L2_ENC_CMD_STOP` command was issued, the drain sequence completes immediately and the encoder returns an empty `CAPTURE` buffer with the `V4L2_BUF_FLAG_LAST` flag set.
>
> - In case of no buffer in the `CAPTURE` queue at the time the drain sequence completes, the next time the client queues a `CAPTURE` buffer it is returned at once as an empty buffer with the `V4L2_BUF_FLAG_LAST` flag set.
>
> - If `VIDIOC_STREAMOFF()` is called on the `CAPTURE` queue in the middle of the drain sequence, the drain sequence is canceled and all `CAPTURE` buffers are implicitly returned to the client.
>
> - If `VIDIOC_STREAMOFF()` is called on the `OUTPUT` queue in the middle of the drain sequence, the drain sequence completes immediately and next `CAPTURE` buffer will be returned empty with the `V4L2_BUF_FLAG_LAST` flag set.
>
> Although not mandatory, the availability of encoder commands may be queried using `VIDIOC_TRY_ENCODER_CMD()`.

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

## Reset

The client may want to request the encoder to reinitialize the encoding, so that the following stream data becomes independent from the stream data generated before. Depending on the coded format, that may imply that:

- encoded frames produced after the restart must not reference any frames produced before the stop, e.g. no long term references for H.264/HEVC,

- any headers that must be included in a standalone stream must be produced again, e.g. SPS and PPS for H.264/HEVC.

This can be achieved by performing the reset sequence.

1. Perform the `Drain` sequence to ensure all the in-flight encoding finishes and respective buffers are dequeued.

2. Stop streaming on the `CAPTURE` queue via `VIDIOC_STREAMOFF()`. This will return all currently queued `CAPTURE` buffers to the client, without valid frame data.

3. Start streaming on the `CAPTURE` queue via `VIDIOC_STREAMON()` and continue with regular encoding sequence. The encoded frames produced into `CAPTURE` buffers from now on will contain a standalone stream that can be decoded without the need for frames encoded before the reset sequence, starting at the first `OUTPUT` buffer queued after issuing the `V4L2_ENC_CMD_STOP` of the `Drain` sequence.

This sequence may be also used to change encoding parameters for encoders without the ability to change the parameters on the fly.

<a id="rst-commit-points"></a>

## Commit Points

Setting formats and allocating buffers triggers changes in the behavior of the encoder.

1. Setting the format on the `CAPTURE` queue may change the set of formats supported/advertised on the `OUTPUT` queue. In particular, it also means that the `OUTPUT` format may be reset and the client must not rely on the previously set format being preserved.

2. Enumerating formats on the `OUTPUT` queue always returns only formats supported for the current `CAPTURE` format.

3. Setting the format on the `OUTPUT` queue does not change the list of formats available on the `CAPTURE` queue. An attempt to set the `OUTPUT` format that is not supported for the currently selected `CAPTURE` format will result in the encoder adjusting the requested `OUTPUT` format to a supported one.

4. Enumerating formats on the `CAPTURE` queue always returns the full set of supported coded formats, irrespective of the current `OUTPUT` format.

5. While buffers are allocated on any of the `OUTPUT` or `CAPTURE` queues, the client must not change the format on the `CAPTURE` queue. Drivers will return the -EBUSY error code for any such format change attempt.

To summarize, setting formats and allocation must always start with the `CAPTURE` queue and the `CAPTURE` queue is the master that governs the set of supported formats for the `OUTPUT` queue.

---

# Event Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The V4L2 event interface provides a means for a user to get immediately notified on certain conditions taking place on a device. This might include start of frame or loss of signal events, for example. Changes in the value or state of a…

<a id="rst-event-interface"></a>
<a id="rst-event"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The V4L2 event interface provides a means for a user to get immediately notified on certain conditions taking place on a device. This might include start of frame or loss of signal events, for example. Changes in the value or state of a V4L2 control can also be reported through events.

To receive events, the events the user is interested in first must be subscribed using the [ioctl VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md#rst-vidioc-subscribe-event>) ioctl. Once an event is subscribed, the events of subscribed types are dequeueable using the [ioctl VIDIOC_DQEVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-vidioc-dqevent>) ioctl. Events may be unsubscribed using VIDIOC_UNSUBSCRIBE_EVENT ioctl. The special event type V4L2_EVENT_ALL may be used to unsubscribe all the events the driver supports.

The event subscriptions and event queues are specific to file handles. Subscribing an event on one file handle does not affect other file handles.

The information on dequeueable events is obtained by using select or poll system calls on video devices. The V4L2 events use POLLPRI events on poll system call and exceptions on select system call.

Starting with kernel 3.1 certain guarantees can be given with regards to events:

1. Each subscribed event has its own internal dedicated event queue. This means that flooding of one event type will not interfere with other event types.

2. If the internal event queue for a particular subscribed event becomes full, then the oldest event in that queue will be dropped.

3. Where applicable, certain event types can ensure that the payload of the oldest event that is about to be dropped will be merged with the payload of the next oldest event. Thus ensuring that no information is lost, but only an intermediate step leading up to that information. See the documentation for the event you want to subscribe to whether this is applicable for that event or not.

---

# Video Memory-To-Memory Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> A V4L2 memory-to-memory device can compress, decompress, transform, or otherwise convert video data from one format into another format, in memory. Such memory-to-memory devices set the V4L2_CAP_VIDEO_M2M or V4L2_CAP_VIDEO_M2M_MPLANE…

<a id="rst-video-memory-to-memory-interface"></a>
<a id="rst-mem2mem"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

A V4L2 memory-to-memory device can compress, decompress, transform, or otherwise convert video data from one format into another format, in memory. Such memory-to-memory devices set the `V4L2_CAP_VIDEO_M2M` or `V4L2_CAP_VIDEO_M2M_MPLANE` capability. Examples of memory-to-memory devices are codecs, scalers, deinterlacers or format converters (i.e. converting from YUV to RGB).

A memory-to-memory video node acts just like a normal video node, but it supports both output (sending frames from memory to the hardware) and capture (receiving the processed frames from the hardware into memory) stream I/O. An application will have to setup the stream I/O for both sides and finally call [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) for both capture and output to start the hardware.

Memory-to-memory devices function as a shared resource: you can open the video node multiple times, each application setting up their own properties that are local to the file handle, and each can use it independently from the others. The driver will arbitrate access to the hardware and reprogram it whenever another file handler gets access. This is different from the usual video node behavior where the video properties are global to the device (i.e. changing something through one file handle is visible through another file handle).

One of the most common memory-to-memory device is the codec. Codecs are more complicated than most and require additional setup for their codec parameters. This is done through codec controls. See [codec-controls](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>). More details on how to use codec memory-to-memory devices are given in the following sections.

- [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md>)
- [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md>)
- [Memory-to-memory Stateless Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-stateless-decoder.md>)

---

# Metadata Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Metadata refers to any non-image data that supplements video frames with additional information. This may include statistics computed over the image, frame capture parameters supplied by the image source or device specific parameters for…

<a id="rst-metadata-interface"></a>
<a id="rst-metadata"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Metadata refers to any non-image data that supplements video frames with additional information. This may include statistics computed over the image, frame capture parameters supplied by the image source or device specific parameters for specifying how the device processes images. This interface is intended for transfer of metadata between the userspace and the hardware and control of that operation.

The metadata interface is implemented on video device nodes. The device can be dedicated to metadata or can support both video and metadata as specified in its reported capabilities.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Device nodes supporting the metadata capture interface set the `V4L2_CAP_META_CAPTURE` flag in the `device_caps` field of the `v4l2_capability` structure returned by the `VIDIOC_QUERYCAP()` ioctl. That flag means the device can capture metadata to memory. Similarly, device nodes supporting metadata output interface set the `V4L2_CAP_META_OUTPUT` flag in the `device_caps` field of `v4l2_capability` structure. That flag means the device can read metadata from memory.

At least one of the read/write or streaming I/O methods must be supported.

<a id="rst-data-format-negotiation"></a>

## Data Format Negotiation

The metadata device uses the [Data Formats](</kernel/userspace/userspace-api/media-v4l/format.md#rst-format>) ioctls to select the capture format. The metadata buffer content format is bound to that selected format. In addition to the basic [Data Formats](</kernel/userspace/userspace-api/media-v4l/format.md#rst-format>) ioctls, the `VIDIOC_ENUM_FMT()` ioctl must be supported as well.

To use the [Data Formats](</kernel/userspace/userspace-api/media-v4l/format.md#rst-format>) ioctls applications set the `type` field of the `v4l2_format` structure to `V4L2_BUF_TYPE_META_CAPTURE` or to `V4L2_BUF_TYPE_META_OUTPUT` and use the `v4l2_meta_format` `meta` member of the `fmt` union as needed per the desired operation. Both drivers and applications must set the remainder of the `v4l2_format` structure to 0.

Devices that capture metadata by line have the struct v4l2_fmtdesc `V4L2_FMT_FLAG_META_LINE_BASED` flag set for `VIDIOC_ENUM_FMT()`. Such devices can typically also [capture image data](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>). This primarily involves devices that receive the data from a different devices such as a camera sensor.





<a id="c-v4l2_meta_format"></a>

```c
v4l2_meta_format
```

<!-- tabularcolumns: |p{1.4cm}|p{2.4cm}|p{13.5cm}| -->


<table>
<caption>struct v4l2_meta_format</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`dataformat`

</td>
<td>


The data format, set by the application. This is a little endian [four character code](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-v4l2-fourcc>). V4L2 defines metadata formats in [Metadata Formats](</kernel/userspace/userspace-api/media-v4l/meta-formats.md#rst-meta-formats>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`buffersize`

</td>
<td>


Maximum buffer size in bytes required for data. The value is set by the driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`width`

</td>
<td>


Width of a line of metadata in Data Units. Valid when :c:type\`v4l2_fmtdesc\` flag `V4L2_FMT_FLAG_META_LINE_BASED` is set, otherwise zero. See `VIDIOC_ENUM_FMT()`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`height`

</td>
<td>


Number of rows of metadata. Valid when :c:type\`v4l2_fmtdesc\` flag `V4L2_FMT_FLAG_META_LINE_BASED` is set, otherwise zero. See `VIDIOC_ENUM_FMT()`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`bytesperline`

</td>
<td>


Offset in bytes between the beginning of two consecutive lines. Valid when :c:type\`v4l2_fmtdesc\` flag `V4L2_FMT_FLAG_META_LINE_BASED` is set, otherwise zero. See `VIDIOC_ENUM_FMT()`.

</td>
</tr>
</tbody>
</table>

---

# Video Output Overlay Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Also known as On-Screen Display (OSD)

<a id="rst-video-output-overlay-interface"></a>
<a id="rst-osd"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

**Also known as On-Screen Display (OSD)**

Some video output devices can overlay a framebuffer image onto the outgoing video signal. Applications can set up such an overlay using this interface, which borrows structures and ioctls of the [Video Overlay](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) interface.

The OSD function is accessible through the same character special file as the [Video Output](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>) function.

> [!NOTE]
>
> The default function of such a `/dev/video` device is video capturing or output. The OSD function is only available after calling the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the *Video Output Overlay* interface set the `V4L2_CAP_VIDEO_OUTPUT_OVERLAY` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl.

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

## Framebuffer

Contrary to the *Video Overlay* interface the framebuffer is normally implemented on the TV card and not the graphics card. On Linux it is accessible as a framebuffer device (`/dev/fbN`). Given a V4L2 device, applications can find the corresponding framebuffer device by calling the [VIDIOC_G_FBUF](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-fbuf.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl. It returns, amongst other information, the physical address of the framebuffer in the `base` field of struct `v4l2_framebuffer`. The framebuffer device ioctl `FBIOGET_FSCREENINFO` returns the same address in the `smem_start` field of struct `fb_fix_screeninfo`. The `FBIOGET_FSCREENINFO` ioctl and struct `fb_fix_screeninfo` are defined in the `linux/fb.h` header file.

The width and height of the framebuffer depends on the current video standard. A V4L2 driver may reject attempts to change the video standard (or any other ioctl which would imply a framebuffer size change) with an `EBUSY` error code until all applications closed the framebuffer device.

<a id="rst-example-finding-a-framebuffer-device-for-osd"></a>

### Example: Finding a framebuffer device for OSD



```c
#include <linux/fb.h>

struct v4l2_framebuffer fbuf;
unsigned int i;
int fb_fd;

if (-1 == ioctl(fd, VIDIOC_G_FBUF, &fbuf)) {
    perror("VIDIOC_G_FBUF");
    exit(EXIT_FAILURE);
}

for (i = 0; i < 30; i++) {
    char dev_name[16];
    struct fb_fix_screeninfo si;

    snprintf(dev_name, sizeof(dev_name), "/dev/fb%u", i);

    fb_fd = open(dev_name, O_RDWR);
    if (-1 == fb_fd) {
        switch (errno) {
        case ENOENT: /* no such file */
        case ENXIO:  /* no driver */
            continue;

        default:
            perror("open");
            exit(EXIT_FAILURE);
        }
    }

    if (0 == ioctl(fb_fd, FBIOGET_FSCREENINFO, &si)) {
        if (si.smem_start == (unsigned long)fbuf.base)
            break;
    } else {
        /* Apparently not a framebuffer device. */
    }

    close(fb_fd);
    fb_fd = -1;
}

/* fb_fd is the file descriptor of the framebuffer device
   for the video output overlay, or -1 if no device was found. */
```

<a id="rst-overlay-window-and-scaling"></a>

## Overlay Window and Scaling

The overlay is controlled by source and target rectangles. The source rectangle selects a subsection of the framebuffer image to be overlaid, the target rectangle an area in the outgoing video signal where the image will appear. Drivers may or may not support scaling, and arbitrary sizes and positions of these rectangles. Further drivers may support any (or none) of the clipping/blending methods defined for the [Video Overlay](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) interface.

A struct `v4l2_window` defines the size of the source rectangle, its position in the framebuffer and the clipping/blending method to be used for the overlay. To get the current parameters applications set the `type` field of a struct `v4l2_format` to `V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY` and call the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. The driver fills the struct `v4l2_window` substructure named `win`. It is not possible to retrieve a previously programmed clipping list or bitmap.

To program the source rectangle applications set the `type` field of a struct `v4l2_format` to `V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY`, initialize the `win` substructure and call the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. The driver adjusts the parameters against hardware limits and returns the actual parameters as [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) does. Like [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), the [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl can be used to learn about driver capabilities without actually changing driver state. Unlike [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) this also works after the overlay has been enabled.

A struct `v4l2_crop` defines the size and position of the target rectangle. The scaling factor of the overlay is implied by the width and height given in struct `v4l2_window` and struct `v4l2_crop`. The cropping API applies to *Video Output* and *Video Output Overlay* devices in the same way as to *Video Capture* and *Video Overlay* devices, merely reversing the direction of the data flow. For more information see [Image Cropping, Insertion and Scaling -- the CROP API](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>).

<a id="rst-enabling-overlay"></a>

## Enabling Overlay

There is no V4L2 ioctl to enable or disable the overlay, however the framebuffer interface of the driver may support the `FBIOBLANK` ioctl.

---

# Video Output Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Video output devices encode stills or image sequences as analog video signal. With this interface applications can control the encoding process and move images from user space to the driver.

<a id="rst-video-output-interface"></a>
<a id="rst-output"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Video output devices encode stills or image sequences as analog video signal. With this interface applications can control the encoding process and move images from user space to the driver.

Conventionally V4L2 video output devices are accessed through character device special files named `/dev/video` and `/dev/video0` to `/dev/video63` with major number 81 and minor numbers 0 to 63. `/dev/video` is typically a symbolic link to the preferred video device.

> [!NOTE]
>
> The same device file names are used also for video capture devices.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the video output interface set the `V4L2_CAP_VIDEO_OUTPUT` or `V4L2_CAP_VIDEO_OUTPUT_MPLANE` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. As secondary device functions they may also support the [raw VBI output](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>) (`V4L2_CAP_VBI_OUTPUT`) interface. At least one of the read/write or streaming I/O methods must be supported. Modulators and audio outputs are optional.

<a id="rst-supplemental-functions"></a>

## Supplemental Functions

Video output devices shall support [audio output](</kernel/userspace/userspace-api/media-v4l/audio.md#rst-audio>), [modulator](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>), [controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>), [cropping and scaling](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>) and [streaming parameter](</kernel/userspace/userspace-api/media-v4l/streaming-par.md#rst-streaming-par>) ioctls as needed. The [video output](</kernel/userspace/userspace-api/media-v4l/video.md#rst-video>) ioctls must be supported by all video output devices.

<a id="rst-image-format-negotiation"></a>

## Image Format Negotiation

The output is determined by cropping and image format parameters. The former select an area of the video picture where the image will appear, the latter how images are stored in memory, i. e. in RGB or YUV format, the number of bits per pixel or width and height. Together they also define how images are scaled in the process.

As usual these parameters are *not* reset at `open()` time to permit Unix tool chains, programming a device and then writing to it as if it was a plain file. Well written V4L2 applications ensure they really get what they want, including cropping and scaling.

Cropping initialization at minimum requires to reset the parameters to defaults. An example is given in [Image Cropping, Insertion and Scaling -- the CROP API](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>).

To query the current image format applications set the `type` field of a struct `v4l2_format` to `V4L2_BUF_TYPE_VIDEO_OUTPUT` or `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE` and call the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with a pointer to this structure. Drivers fill the struct `v4l2_pix_format` `pix` or the struct `v4l2_pix_format_mplane` `pix_mp` member of the `fmt` union.

To request different parameters applications set the `type` field of a struct `v4l2_format` as above and initialize all fields of the struct `v4l2_pix_format` `vbi` member of the `fmt` union, or better just modify the results of [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), and call the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with a pointer to this structure. Drivers may adjust the parameters and finally return the actual parameters as [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) does.

Like [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) the [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl can be used to learn about hardware limitations without disabling I/O or possibly time consuming hardware preparations.

The contents of struct `v4l2_pix_format` and struct `v4l2_pix_format_mplane` are discussed in [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>). See also the specification of the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls for details. Video output devices must implement both the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, even if [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ignores all requests and always returns default parameters as [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) does. [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) is optional.

<a id="rst-writing-images"></a>

## Writing Images

A video output device may support the [write() function](</kernel/userspace/userspace-api/media-v4l/rw.md#rst-rw>) and/or streaming ([memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) or [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>)) I/O. See [Input/Output](</kernel/userspace/userspace-api/media-v4l/io.md#rst-io>) for details.

---

# Video Overlay Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Also known as Framebuffer Overlay or Previewing.

<a id="rst-video-overlay-interface"></a>
<a id="rst-overlay"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<strong>Also known as Framebuffer Overlay or Previewing.</strong>

Video overlay devices have the ability to genlock (TV-)video into the (VGA-)video signal of a graphics card, or to store captured images directly in video memory of a graphics card, typically with clipping. This can be considerable more efficient than capturing images and displaying them by other means. In the old days when only nuclear power plants needed cooling towers this used to be the only way to put live video into a window.

Video overlay devices are accessed through the same character special files as [video capture](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>) devices.

> [!NOTE]
>
> The default function of a `/dev/video` device is video capturing. The overlay function is only available after calling the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl.

The driver may support simultaneous overlay and capturing using the read/write and streaming I/O methods. If so, operation at the nominal frame rate of the video standard is not guaranteed. Frames may be directed away from overlay to capture, or one field may be used for overlay and the other for capture if the capture parameters permit this.

Applications should use different file descriptors for capturing and overlay. This must be supported by all drivers capable of simultaneous capturing and overlay. Optionally these drivers may also permit capturing and overlay with a single file descriptor for compatibility with V4L and earlier versions of V4L2. <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

A common application of two file descriptors is the X11 [Xv/V4L](</kernel/userspace/userspace-api/media-v4l/hist-v4l2.md#rst-xvideo>) interface driver and a V4L2 application. While the X server controls video overlay, the application can take advantage of memory mapping and DMA.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the video overlay interface set the `V4L2_CAP_VIDEO_OVERLAY` flag in the `capabilities` field of struct `v4l2_capability` returned by the [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. The overlay I/O method specified below must be supported. Tuners and audio inputs are optional.

<a id="rst-supplemental-functions"></a>

## Supplemental Functions

Video overlay devices shall support [audio input](</kernel/userspace/userspace-api/media-v4l/audio.md#rst-audio>), [tuner](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>), [controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>), [cropping and scaling](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>) and [streaming parameter](</kernel/userspace/userspace-api/media-v4l/streaming-par.md#rst-streaming-par>) ioctls as needed. The [video input](</kernel/userspace/userspace-api/media-v4l/video.md#rst-video>) and [video standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>) ioctls must be supported by all video overlay devices.

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

## Setup

<em>Note: support for this has been removed.</em> Before overlay can commence applications must program the driver with frame buffer parameters, namely the address and size of the frame buffer and the image format, for example RGB 5:6:5. The [VIDIOC\_G\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) and [VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) ioctls are available to get and set these parameters, respectively. The [VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) ioctl is privileged because it allows to set up DMA into physical memory, bypassing the memory protection mechanisms of the kernel. Only the superuser can change the frame buffer address and size. Users are not supposed to run TV applications as root or with SUID bit set. A small helper application with suitable privileges should query the graphics system and program the V4L2 driver at the appropriate time.

Some devices add the video overlay to the output signal of the graphics card. In this case the frame buffer is not modified by the video device, and the frame buffer address and pixel format are not needed by the driver. The [VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) ioctl is not privileged. An application can check for this type of device by calling the [VIDIOC\_G\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) ioctl.

A driver may support any (or none) of five clipping/blending methods:

1. Chroma-keying displays the overlaid image only where pixels in the primary graphics surface assume a certain color.

2. <em>Note: support for this has been removed.</em> A bitmap can be specified where each bit corresponds to a pixel in the overlaid image. When the bit is set, the corresponding video pixel is displayed, otherwise a pixel of the graphics surface.

3. <em>Note: support for this has been removed.</em> A list of clipping rectangles can be specified. In these regions <em>no</em> video is displayed, so the graphics surface can be seen here.

4. The framebuffer has an alpha channel that can be used to clip or blend the framebuffer with the video.

5. A global alpha value can be specified to blend the framebuffer contents with video images.

When simultaneous capturing and overlay is supported and the hardware prohibits different image and frame buffer formats, the format requested first takes precedence. The attempt to capture ([VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>)) or overlay ([VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>)) may fail with an `EBUSY` error code or return accordingly modified parameters..

<a id="rst-overlay-window"></a>

## Overlay Window

The overlaid image is determined by cropping and overlay window parameters. The former select an area of the video picture to capture, the latter how images are overlaid and clipped. Cropping initialization at minimum requires to reset the parameters to defaults. An example is given in [crop](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>).

The overlay window is described by a struct `v4l2_window`. It defines the size of the image, its position over the graphics surface and the clipping to be applied. To get the current parameters applications set the `type` field of a struct `v4l2_format` to `V4L2_BUF_TYPE_VIDEO_OVERLAY` and call the [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. The driver fills the struct `v4l2_window` substructure named `win`. It is not possible to retrieve a previously programmed clipping list or bitmap.

To program the overlay window applications set the `type` field of a struct `v4l2_format` to `V4L2_BUF_TYPE_VIDEO_OVERLAY`, initialize the `win` substructure and call the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. The driver adjusts the parameters against hardware limits and returns the actual parameters as [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) does. Like [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), the [VIDIOC\_TRY\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl can be used to learn about driver capabilities without actually changing driver state. Unlike [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) this also works after the overlay has been enabled.

The scaling factor of the overlaid image is implied by the width and height given in struct `v4l2_window` and the size of the cropping rectangle. For more information see [crop](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>).

When simultaneous capturing and overlay is supported and the hardware prohibits different image and window sizes, the size requested first takes precedence. The attempt to capture or overlay as well ([VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>)) may fail with an `EBUSY` error code or return accordingly modified parameters.

<a id="c-v4l2_window"></a>



```c
v4l2_window
```

<a id="rst-struct-v4l2-window"></a>

### struct v4l2\_window

- **`struct v4l2_rect w`**

  Size and position of the window relative to the top, left corner of the frame buffer defined with [VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>). The window can extend the frame buffer width and height, the `x` and `y` coordinates can be negative, and it can lie completely outside the frame buffer. The driver clips the window accordingly, or if that is not possible, modifies its size and/or position.

- **`enum v4l2_field field`**

  Applications set this field to determine which video field shall be overlaid, typically one of `V4L2_FIELD_ANY` (0), `V4L2_FIELD_TOP`, `V4L2_FIELD_BOTTOM` or `V4L2_FIELD_INTERLACED`. Drivers may have to choose a different field order and return the actual setting here.

- **`__u32 chromakey`**

  When chroma-keying has been negotiated with [VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) applications set this field to the desired pixel value for the chroma key. The format is the same as the pixel format of the framebuffer (struct `v4l2_framebuffer` `fmt.pixelformat` field), with bytes in host order. E. g. for [V4L2\_PIX\_FMT\_BGR24](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgr32>) the value should be 0xRRGGBB on a little endian, 0xBBGGRR on a big endian host.

- **`struct v4l2_clip * clips`**

  <em>Note: support for this has been removed.</em> When chroma-keying has <em>not</em> been negotiated and [VIDIOC\_G\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) indicated this capability, applications can set this field to point to an array of clipping rectangles.

  Like the window coordinates w, clipping rectangles are defined relative to the top, left corner of the frame buffer. However clipping rectangles must not extend the frame buffer width and height, and they must not overlap. If possible applications should merge adjacent rectangles. Whether this must create x-y or y-x bands, or the order of rectangles, is not defined. When clip lists are not supported the driver ignores this field. Its contents after calling [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) are undefined.

- **`__u32 clipcount`**

  <em>Note: support for this has been removed.</em> When the application set the `clips` field, this field must contain the number of clipping rectangles in the list. When clip lists are not supported the driver ignores this field, its contents after calling [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) are undefined. When clip lists are supported but no clipping is desired this field must be set to zero.

- **`void * bitmap`**

  <em>Note: support for this has been removed.</em> When chroma-keying has <em>not</em> been negotiated and [VIDIOC\_G\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) indicated this capability, applications can set this field to point to a clipping bit mask.

It must be of the same size as the window, `w.width` and `w.height`. Each bit corresponds to a pixel in the overlaid image, which is displayed only when the bit is <em>set</em>. Pixel coordinates translate to bits like:



```c
((__u8 *) bitmap)[w.width * y + x / 8] & (1 << (x & 7))
```

where `0` ≤ x &lt; `w.width` and `0` ≤ y &lt;`w.height`. <a id="rst-footnote-reference-2"></a>[2](#rst-f2)

When a clipping bit mask is not supported the driver ignores this field, its contents after calling [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) are undefined. When a bit mask is supported but no clipping is desired this field must be set to `NULL`.

Applications need not create a clip list or bit mask. When they pass both, or despite negotiating chroma-keying, the results are undefined. Regardless of the chosen method, the clipping abilities of the hardware may be limited in quantity or quality. The results when these limits are exceeded are undefined. <a id="rst-footnote-reference-3"></a>[3](#rst-f3)

- **`__u8 global_alpha`**

  The global alpha value used to blend the framebuffer with video images, if global alpha blending has been negotiated (`V4L2_FBUF_FLAG_GLOBAL_ALPHA`, see [VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>), [framebuffer-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-flags>)).

> [!NOTE]
>
> This field was added in Linux 2.6.23, extending the structure. However the [VIDIOC\_\[G\|S\|TRY\]\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls, which take a pointer to a `v4l2_format` parent structure with padding bytes at the end, are not affected.

<a id="c-v4l2_clip"></a>



```c
v4l2_clip
```

<a id="rst-struct-v4l2-clip"></a>

### struct v4l2\_clip <a id="rst-footnote-reference-4"></a>[4](#rst-f4)

- **`struct v4l2_rect c`**

  Coordinates of the clipping rectangle, relative to the top, left corner of the frame buffer. Only window pixels <em>outside</em> all clipping rectangles are displayed.

- **`struct v4l2_clip * next`**

  Pointer to the next clipping rectangle, `NULL` when this is the last rectangle. Drivers ignore this field, it cannot be used to pass a linked list of clipping rectangles.

<a id="c-v4l2_rect"></a>



```c
v4l2_rect
```

<a id="rst-struct-v4l2-rect"></a>

### struct v4l2\_rect

- **`__s32 left`**

  Horizontal offset of the top, left corner of the rectangle, in pixels.

- **`__s32 top`**

  Vertical offset of the top, left corner of the rectangle, in pixels. Offsets increase to the right and down.

- **`__u32 width`**

  Width of the rectangle, in pixels.

- **`__u32 height`**

  Height of the rectangle, in pixels.

<a id="rst-enabling-overlay"></a>

## Enabling Overlay

To start or stop the frame buffer overlay applications call the [vidioc\_overlay](</kernel/userspace/userspace-api/media-v4l/vidioc-overlay.md#rst-vidioc-overlay>) ioctl.

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



**[1]** In the opinion of the designers of this API, no driver writer taking the efforts to support simultaneous capturing and overlay will restrict this ability by requiring a single file descriptor, as in V4L and earlier versions of V4L2. Making this optional means applications depending on two file descriptors need backup routines to be compatible with all drivers, which is considerable more work than using two fds in applications which do not. Also two fd's fit the general concept of one file descriptor for each logical stream. Hence as a complexity trade-off drivers <em>must</em> support two file descriptors and <em>may</em> support single fd operation.

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



**[2]** Should we require `w.width` to be a multiple of eight?

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



**[3]** When the image is written into frame buffer memory it will be undesirable if the driver clips out less pixels than expected, because the application and graphics system are not aware these regions need to be refreshed. The driver should clip out more pixels or not write the image at all.

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



**[4]** The X Window system defines "regions" which are vectors of `struct BoxRec { short x1, y1, x2, y2; }` with `width = x2 - x1` and `height = y2 - y1`, so one cannot pass X11 clip lists directly.

---

# Radio Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> This interface is intended for AM and FM (analog) radio receivers and transmitters.

<a id="rst-radio-interface"></a>
<a id="rst-radio"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

This interface is intended for AM and FM (analog) radio receivers and transmitters.

Conventionally V4L2 radio devices are accessed through character device special files named `/dev/radio` and `/dev/radio0` to `/dev/radio63` with major number 81 and minor numbers 64 to 127.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the radio interface set the `V4L2_CAP_RADIO` and `V4L2_CAP_TUNER` or `V4L2_CAP_MODULATOR` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. Other combinations of capability flags are reserved for future extensions.

<a id="rst-supplemental-functions"></a>

## Supplemental Functions

Radio devices can support [controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>), and must support the [tuner or modulator](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>) ioctls.

They do not support the video input or output, audio input or output, video standard, cropping and scaling, compression and streaming parameter, or overlay ioctls. All other ioctls and I/O methods are reserved for future extensions.

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

## Programming

Radio devices may have a couple audio controls (as discussed in [User Controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>)) such as a volume control, possibly custom controls. Further all radio devices have one tuner or modulator (these are discussed in [Tuners and Modulators](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>)) with index number zero to select the radio frequency and to determine if a monaural or FM stereo program is received/emitted. Drivers switch automatically between AM and FM depending on the selected frequency. The [VIDIOC_G_TUNER](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-tuner.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) or [VIDIOC_G_MODULATOR](</kernel/userspace/userspace-api/media-v4l/vidioc-g-modulator.md#rst-vidioc-g-modulator>) ioctl reports the supported frequency range.

---

# Raw VBI Data Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VBI is an abbreviation of Vertical Blanking Interval, a gap in the sequence of lines of an analog video signal. During VBI no picture information is transmitted, allowing some time while the electron beam of a cathode ray tube TV returns…

<a id="rst-raw-vbi-data-interface"></a>
<a id="rst-raw-vbi"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

VBI is an abbreviation of Vertical Blanking Interval, a gap in the sequence of lines of an analog video signal. During VBI no picture information is transmitted, allowing some time while the electron beam of a cathode ray tube TV returns to the top of the screen. Using an oscilloscope you will find here the vertical synchronization pulses and short data packages ASK modulated <a id="rst-footnote-reference-1"></a>[1](#rst-f1) onto the video signal. These are transmissions of services such as Teletext or Closed Caption.

Subject of this interface type is raw VBI data, as sampled off a video signal, or to be added to a signal for output. The data format is similar to uncompressed video images, a number of lines times a number of samples per line, we call this a VBI image.

Conventionally V4L2 VBI devices are accessed through character device special files named `/dev/vbi` and `/dev/vbi0` to `/dev/vbi31` with major number 81 and minor numbers 224 to 255. `/dev/vbi` is typically a symbolic link to the preferred VBI device. This convention applies to both input and output devices.

To address the problems of finding related video and VBI devices VBI capturing and output is also available as device function under `/dev/video`. To capture or output raw VBI data with these devices applications must call the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. Accessed as `/dev/vbi`, raw VBI capturing or output is the default device function.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the raw VBI capturing or output API set the `V4L2_CAP_VBI_CAPTURE` or `V4L2_CAP_VBI_OUTPUT` flags, respectively, in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. At least one of the read/write or streaming I/O methods must be supported. VBI devices may or may not have a tuner or modulator.

<a id="rst-supplemental-functions"></a>

## Supplemental Functions

VBI devices shall support [video input or output](</kernel/userspace/userspace-api/media-v4l/video.md#rst-video>), [tuner or modulator](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>), and [controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>) ioctls as needed. The [video standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>) ioctls provide information vital to program a VBI device, therefore must be supported.

<a id="rst-raw-vbi-format-negotiation"></a>

## Raw VBI Format Negotiation

Raw VBI sampling abilities can vary, in particular the sampling frequency. To properly interpret the data V4L2 specifies an ioctl to query the sampling parameters. Moreover, to allow for some flexibility applications can also suggest different parameters.

As usual these parameters are *not* reset at `open()` time to permit Unix tool chains, programming a device and then reading from it as if it was a plain file. Well written V4L2 applications should always ensure they really get what they want, requesting reasonable parameters and then checking if the actual parameters are suitable.

To query the current raw VBI capture parameters applications set the `type` field of a struct `v4l2_format` to `V4L2_BUF_TYPE_VBI_CAPTURE` or `V4L2_BUF_TYPE_VBI_OUTPUT`, and call the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with a pointer to this structure. Drivers fill the struct `v4l2_vbi_format` `vbi` member of the `fmt` union.

To request different parameters applications set the `type` field of a struct `v4l2_format` as above and initialize all fields of the struct `v4l2_vbi_format` `vbi` member of the `fmt` union, or better just modify the results of [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), and call the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with a pointer to this structure. Drivers return an `EINVAL` error code only when the given parameters are ambiguous, otherwise they modify the parameters according to the hardware capabilities and return the actual parameters. When the driver allocates resources at this point, it may return an `EBUSY` error code to indicate the returned parameters are valid but the required resources are currently not available. That may happen for instance when the video and VBI areas to capture would overlap, or when the driver supports multiple opens and another process already requested VBI capturing or output. Anyway, applications must expect other resource allocation points which may return `EBUSY`, at the [ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctl and the first `read()` , `write()` and `select()` calls.

VBI devices must implement both the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, even if [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ignores all requests and always returns default parameters as [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) does. [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) is optional.

<!-- tabularcolumns: |p{1.6cm}|p{4.2cm}|p{11.5cm}| -->





<a id="c-v4l2_vbi_format"></a>

```c
v4l2_vbi_format
```


<table>
<caption>struct v4l2_vbi_format</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`sampling_rate`

</td>
<td>


Samples per second, i. e. unit 1 Hz.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`offset`

</td>
<td>


Horizontal offset of the VBI image, relative to the leading edge of the line synchronization pulse and counted in samples: The first sample in the VBI image will be located `offset` / `sampling_rate` seconds following the leading edge. See also [vbi-hsync](<#rst-vbi-hsync>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`samples_per_line`

</td>
<td>




</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`sample_format`

</td>
<td>


Defines the sample format as in [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>), a four-character-code. <a id="rst-footnote-reference-2"></a>[2](#rst-f2) Usually this is `V4L2_PIX_FMT_GREY`, i. e. each sample consists of 8 bits with lower values oriented towards the black level. Do not assume any other correlation of values with the signal level. For example, the MSB does not necessarily indicate if the signal is 'high' or 'low' because 128 may not be the mean value of the signal. Drivers shall not convert the sample format by software.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`start`<a id="rst-footnote-reference-3"></a>[2](#rst-f2)

</td>
<td>


This is the scanning system line number associated with the first line of the VBI image, of the first and the second field respectively. See [vbi-525](<#rst-vbi-525>) and [vbi-625](<#rst-vbi-625>) for valid values. The `V4L2_VBI_ITU_525_F1_START`, `V4L2_VBI_ITU_525_F2_START`, `V4L2_VBI_ITU_625_F1_START` and `V4L2_VBI_ITU_625_F2_START` defines give the start line numbers for each field for each 525 or 625 line format as a convenience. Don't forget that ITU line numbering starts at 1, not 0. VBI input drivers can return start values 0 if the hardware cannot reliable identify scanning lines, VBI acquisition may not require this information.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`count`<a id="rst-footnote-reference-4"></a>[2](#rst-f2)

</td>
<td>


The number of lines in the first and second field image, respectively.

</td>
</tr>
<tr>
<td colspan="3">


Drivers should be as flexibility as possible. For example, it may be possible to extend or move the VBI capture window down to the picture area, implementing a 'full field mode' to capture data service transmissions embedded in the picture.

An application can set the first or second `count` value to zero if no data is required from the respective field; `count`\[1\] if the scanning system is progressive, i. e. not interlaced. The corresponding start value shall be ignored by the application and driver. Anyway, drivers may not support single field capturing and return both count values non-zero.

Both `count` values set to zero, or line numbers are outside the bounds depicted<a id="rst-footnote-reference-5"></a>[4](#rst-f4), or a field image covering lines of two fields, are invalid and shall not be returned by the driver.

To initialize the `start` and `count` fields, applications must first determine the current video standard selection. The [v4l2_std_id](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) or the `framelines` field of struct `v4l2_standard` can be evaluated for this purpose.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


See [vbifmt-flags](<#rst-vbifmt-flags>) below. Currently only drivers set flags, applications must set this field to zero.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`<a id="rst-footnote-reference-6"></a>[2](#rst-f2)

</td>
<td>


This array is reserved for future extensions. Drivers and applications must set it to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{1.5cm}|p{11.4cm}| -->

<a id="rst-vbifmt-flags"></a>


<table>
<caption>Raw VBI Format Flags</caption>
<tbody>
<tr>
<td>


`V4L2_VBI_UNSYNC`

</td>
<td>


0x0001

</td>
<td>


This flag indicates hardware which does not properly distinguish between fields. Normally the VBI image stores the first field (lower scanning line numbers) first in memory. This may be a top or bottom field depending on the video standard. When this flag is set the first or second field may be stored first, however the fields are still in correct temporal order with the older field first in memory. <a id="rst-footnote-reference-7"></a>[3](#rst-f3)

</td>
</tr>
<tr>
<td>


`V4L2_VBI_INTERLACED`

</td>
<td>


0x0002

</td>
<td>


By default the two field images will be passed sequentially; all lines of the first field followed by all lines of the second field (compare [Field Order](</kernel/userspace/userspace-api/media-v4l/field-order.md#rst-field-order>) `V4L2_FIELD_SEQ_TB` and `V4L2_FIELD_SEQ_BT`, whether the top or bottom field is first in memory depends on the video standard). When this flag is set, the two fields are interlaced (cf. `V4L2_FIELD_INTERLACED`). The first line of the first field followed by the first line of the second field, then the two second lines, and so on. Such a layout may be necessary when the hardware has been programmed to capture or output interlaced video images and is unable to separate the fields for VBI capturing at the same time. For simplicity setting this flag implies that both `count` values are equal and non-zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-vbi-hsync"></a>

![vbi_hsync.svg](/kernel/userspace/userspace-api/media-v4l/asset-dc390d3e02a4-vbi-hsync.svg)

Line synchronization

<a id="rst-vbi-525"></a>

![vbi_525.svg](/kernel/userspace/userspace-api/media-v4l/asset-91e44684f98a-vbi-525.svg)

ITU-R 525 line numbering (M/NTSC and M/PAL)

<a id="rst-vbi-625"></a>

![vbi_625.svg](/kernel/userspace/userspace-api/media-v4l/asset-38b141cc6b75-vbi-625.svg)

ITU-R 625 line numbering

Remember the VBI image format depends on the selected video standard, therefore the application must choose a new standard or query the current standard first. Attempts to read or write data ahead of format negotiation, or after switching the video standard which may invalidate the negotiated VBI parameters, should be refused by the driver. A format change during active I/O is not permitted.

<a id="rst-reading-and-writing-vbi-images"></a>

## Reading and writing VBI images

To assure synchronization with the field number and easier implementation, the smallest unit of data passed at a time is one frame, consisting of two fields of VBI images immediately following in memory.

The total size of a frame computes as follows:



```c
(count[0] + count[1]) * samples_per_line * sample size in bytes
```

The sample size is most likely always one byte, applications must check the `sample_format` field though, to function properly with other drivers.

A VBI device may support [read/write](</kernel/userspace/userspace-api/media-v4l/rw.md#rst-rw>) and/or streaming ([memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) or [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>)) I/O. The latter bears the possibility of synchronizing video and VBI data by using buffer timestamps.

Remember the [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctl and the first `read()`, `write()` and `select()` call can be resource allocation points returning an `EBUSY` error code if the required hardware resources are temporarily unavailable, for example the device is already in use by another process.

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



**[1]** ASK: Amplitude-Shift Keying. A high signal level represents a '1' bit, a low level a '0' bit.

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



**[2]** A few devices may be unable to sample VBI data at all but can extend the video capture window to the VBI region.

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



**[3]** Most VBI services transmit on both fields, but some have different semantics depending on the field number. These cannot be reliable decoded or encoded when `V4L2_VBI_UNSYNC` is set.

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



**[4]** The valid values ar shown at [vbi-525](<#rst-vbi-525>) and [vbi-625](<#rst-vbi-625>).

---

# RDS Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Radio Data System transmits supplementary information in binary format, for example the station name or travel information, on an inaudible audio subcarrier of a radio program. This interface is aimed at devices capable of receiving…

<a id="rst-rds-interface"></a>
<a id="rst-rds"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Radio Data System transmits supplementary information in binary format, for example the station name or travel information, on an inaudible audio subcarrier of a radio program. This interface is aimed at devices capable of receiving and/or transmitting RDS information.

For more information see the core RDS standard [IEC 62106](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-iec62106>) and the RBDS standard [NRSC-4-B](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-nrsc4>).

> [!NOTE]
>
> Note that the RBDS standard as is used in the USA is almost identical to the RDS standard. Any RDS decoder/encoder can also handle RBDS. Only some of the fields have slightly different meanings. See the RBDS standard for more information.

The RBDS standard also specifies support for MMBS (Modified Mobile Search). This is a proprietary format which seems to be discontinued. The RDS interface does not support this format. Should support for MMBS (or the so-called 'E blocks' in general) be needed, then please contact the linux-media mailing list: [https://linuxtv.org/lists.php](<https://linuxtv.org/lists.php>).

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the RDS capturing API set the `V4L2_CAP_RDS_CAPTURE` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. Any tuner that supports RDS will set the `V4L2_TUNER_CAP_RDS` flag in the `capability` field of struct `v4l2_tuner`. If the driver only passes RDS blocks without interpreting the data the `V4L2_TUNER_CAP_RDS_BLOCK_IO` flag has to be set, see [Reading RDS data](<#rst-reading-rds-data>). For future use the flag `V4L2_TUNER_CAP_RDS_CONTROLS` has also been defined. However, a driver for a radio tuner with this capability does not yet exist, so if you are planning to write such a driver you should discuss this on the linux-media mailing list: [https://linuxtv.org/lists.php](<https://linuxtv.org/lists.php>).

Whether an RDS signal is present can be detected by looking at the `rxsubchans` field of struct `v4l2_tuner`: the `V4L2_TUNER_SUB_RDS` will be set if RDS data was detected.

Devices supporting the RDS output API set the `V4L2_CAP_RDS_OUTPUT` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. Any modulator that supports RDS will set the `V4L2_TUNER_CAP_RDS` flag in the `capability` field of struct `v4l2_modulator`. In order to enable the RDS transmission one must set the `V4L2_TUNER_SUB_RDS` bit in the `txsubchans` field of struct `v4l2_modulator`. If the driver only passes RDS blocks without interpreting the data the `V4L2_TUNER_CAP_RDS_BLOCK_IO` flag has to be set. If the tuner is capable of handling RDS entities like program identification codes and radio text, the flag `V4L2_TUNER_CAP_RDS_CONTROLS` should be set, see [Writing RDS data](<#rst-writing-rds-data>) and [FM Transmitter Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-fm-tx.md#rst-fm-tx-controls>).

<a id="rst-reading-rds-data-1"></a>
<a id="rst-reading-rds-data"></a>

## Reading RDS data

RDS data can be read from the radio device with the `read()` function. The data is packed in groups of three bytes.

<a id="rst-writing-rds-data-1"></a>
<a id="rst-writing-rds-data"></a>

## Writing RDS data

RDS data can be written to the radio device with the `write()` function. The data is packed in groups of three bytes, as follows:

<a id="rst-rds-datastructures"></a>

## RDS datastructures





<a id="c-v4l2_rds_data"></a>

```c
v4l2_rds_data
```


<table>
<caption>struct v4l2_rds_data</caption>
<tbody>
<tr>
<td>


\__u8

</td>
<td>


`lsb`

</td>
<td>


Least Significant Byte of RDS Block

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`msb`

</td>
<td>


Most Significant Byte of RDS Block

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`block`

</td>
<td>


Block description

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-rds-block"></a>



<!-- tabularcolumns: |p{2.9cm}|p{14.6cm}| -->


<table>
<caption>Block description</caption>
<tbody>
<tr>
<td>


Bits 0-2

</td>
<td>


Block (aka offset) of the received data.

</td>
</tr>
<tr>
<td>


Bits 3-5

</td>
<td>


Deprecated. Currently identical to bits 0-2. Do not use these bits.

</td>
</tr>
<tr>
<td>


Bit 6

</td>
<td>


Corrected bit. Indicates that an error was corrected for this data block.

</td>
</tr>
<tr>
<td>


Bit 7

</td>
<td>


Error bit. Indicates that an uncorrectable error occurred during reception of this block.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-rds-block-codes"></a>



<!-- tabularcolumns: |p{6.4cm}|p{2.0cm}|p{1.2cm}|p{7.0cm}| -->


<table>
<caption>Block defines</caption>
<tbody>
<tr>
<td>


V4L2_RDS_BLOCK_MSK

</td>
<td>




</td>
<td>


7

</td>
<td>


Mask for bits 0-2 to get the block ID.

</td>
</tr>
<tr>
<td>


V4L2_RDS_BLOCK_A

</td>
<td>




</td>
<td>


0

</td>
<td>


Block A.

</td>
</tr>
<tr>
<td>


V4L2_RDS_BLOCK_B

</td>
<td>




</td>
<td>


1

</td>
<td>


Block B.

</td>
</tr>
<tr>
<td>


V4L2_RDS_BLOCK_C

</td>
<td>




</td>
<td>


2

</td>
<td>


Block C.

</td>
</tr>
<tr>
<td>


V4L2_RDS_BLOCK_D

</td>
<td>




</td>
<td>


3

</td>
<td>


Block D.

</td>
</tr>
<tr>
<td>


V4L2_RDS_BLOCK_C_ALT

</td>
<td>




</td>
<td>


4

</td>
<td>


Block C'.

</td>
</tr>
<tr>
<td>


V4L2_RDS_BLOCK_INVALID

</td>
<td>


read-only

</td>
<td>


7

</td>
<td>


An invalid block.

</td>
</tr>
<tr>
<td>


V4L2_RDS_BLOCK_CORRECTED

</td>
<td>


read-only

</td>
<td>


0x40

</td>
<td>


A bit error was detected but corrected.

</td>
</tr>
<tr>
<td>


V4L2_RDS_BLOCK_ERROR

</td>
<td>


read-only

</td>
<td>


0x80

</td>
<td>


An uncorrectable error occurred.

</td>
</tr>
</tbody>
</table>

---

# Software Defined Radio Interface (SDR)

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> SDR is an abbreviation of Software Defined Radio, the radio device which uses application software for modulation or demodulation. This interface is intended for controlling and data streaming of such devices.

<a id="rst-software-defined-radio-interface-sdr"></a>
<a id="rst-sdr"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

SDR is an abbreviation of Software Defined Radio, the radio device which uses application software for modulation or demodulation. This interface is intended for controlling and data streaming of such devices.

SDR devices are accessed through character device special files named `/dev/swradio0` to `/dev/swradio255` with major number 81 and dynamically allocated minor numbers 0 to 255.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the SDR receiver interface set the `V4L2_CAP_SDR_CAPTURE` and `V4L2_CAP_TUNER` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. That flag means the device has an Analog to Digital Converter (ADC), which is a mandatory element for the SDR receiver.

Devices supporting the SDR transmitter interface set the `V4L2_CAP_SDR_OUTPUT` and `V4L2_CAP_MODULATOR` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. That flag means the device has an Digital to Analog Converter (DAC), which is a mandatory element for the SDR transmitter.

At least one of the read/write or streaming I/O methods must be supported.

<a id="rst-supplemental-functions"></a>

## Supplemental Functions

SDR devices can support [controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>), and must support the [Tuners and Modulators](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>) ioctls. Tuner ioctls are used for setting the ADC/DAC sampling rate (sampling frequency) and the possible radio frequency (RF).

The `V4L2_TUNER_SDR` tuner type is used for setting SDR device ADC/DAC frequency, and the `V4L2_TUNER_RF` tuner type is used for setting radio frequency. The tuner index of the RF tuner (if any) must always follow the SDR tuner index. Normally the SDR tuner is \#0 and the RF tuner is \#1.

The [ioctl VIDIOC_S_HW_FREQ_SEEK](</kernel/userspace/userspace-api/media-v4l/vidioc-s-hw-freq-seek.md#rst-vidioc-s-hw-freq-seek>) ioctl is not supported.

<a id="rst-data-format-negotiation"></a>

## Data Format Negotiation

The SDR device uses the [Data Formats](</kernel/userspace/userspace-api/media-v4l/format.md#rst-format>) ioctls to select the capture and output format. Both the sampling resolution and the data streaming format are bound to that selectable format. In addition to the basic [Data Formats](</kernel/userspace/userspace-api/media-v4l/format.md#rst-format>) ioctls, the [ioctl VIDIOC_ENUM_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) ioctl must be supported as well.

To use the [Data Formats](</kernel/userspace/userspace-api/media-v4l/format.md#rst-format>) ioctls applications set the `type` field of a struct `v4l2_format` to `V4L2_BUF_TYPE_SDR_CAPTURE` or `V4L2_BUF_TYPE_SDR_OUTPUT` and use the struct `v4l2_sdr_format` `sdr` member of the `fmt` union as needed per the desired operation. Currently there are two fields, `pixelformat` and `buffersize`, of struct `v4l2_sdr_format` which are used. Content of the `pixelformat` is V4L2 FourCC code of the data format. The `buffersize` field is maximum buffer size in bytes required for data transfer, set by the driver in order to inform application.





<a id="c-v4l2_sdr_format"></a>

```c
v4l2_sdr_format
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_sdr_format</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`pixelformat`

</td>
<td>


The data format or type of compression, set by the application. This is a little endian [four character code](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-v4l2-fourcc>). V4L2 defines SDR formats in [SDR Formats](</kernel/userspace/userspace-api/media-v4l/sdr-formats.md#rst-sdr-formats>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`buffersize`

</td>
<td>


Maximum size in bytes required for data. Value is set by the driver.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`reserved[24]`

</td>
<td>


This array is reserved for future extensions. Drivers and applications must set it to zero.

</td>
</tr>
</tbody>
</table>

An SDR device may support [read/write](</kernel/userspace/userspace-api/media-v4l/rw.md#rst-rw>) and/or streaming ([memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) or [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>)) I/O.

---

# Sliced VBI Data Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VBI stands for Vertical Blanking Interval, a gap in the sequence of lines of an analog video signal. During VBI no picture information is transmitted, allowing some time while the electron beam of a cathode ray tube TV returns to the top…

<a id="rst-sliced-vbi-data-interface"></a>
<a id="rst-sliced"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

VBI stands for Vertical Blanking Interval, a gap in the sequence of lines of an analog video signal. During VBI no picture information is transmitted, allowing some time while the electron beam of a cathode ray tube TV returns to the top of the screen.

Sliced VBI devices use hardware to demodulate data transmitted in the VBI. V4L2 drivers shall <em>not</em> do this by software, see also the [raw VBI interface](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>). The data is passed as short packets of fixed size, covering one scan line each. The number of packets per video frame is variable.

Sliced VBI capture and output devices are accessed through the same character special files as raw VBI devices. When a driver supports both interfaces, the default function of a `/dev/vbi` device is <em>raw</em> VBI capturing or output, and the sliced VBI function is only available after calling the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl as defined below. Likewise a `/dev/video` device may support the sliced VBI API, however the default function here is video capturing or output. Different file descriptors must be used to pass raw and sliced VBI data simultaneously, if this is supported by the driver.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the sliced VBI capturing or output API set the `V4L2_CAP_SLICED_VBI_CAPTURE` or `V4L2_CAP_SLICED_VBI_OUTPUT` flag respectively, in the `capabilities` field of struct `v4l2_capability` returned by the [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. At least one of the read/write or streaming [I/O methods](</kernel/userspace/userspace-api/media-v4l/io.md#rst-io>) must be supported. Sliced VBI devices may have a tuner or modulator.

<a id="rst-supplemental-functions"></a>

## Supplemental Functions

Sliced VBI devices shall support [video input or output](</kernel/userspace/userspace-api/media-v4l/video.md#rst-video>) and [tuner or modulator](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>) ioctls if they have these capabilities, and they may support [control](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>) ioctls. The [video standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>) ioctls provide information vital to program a sliced VBI device, therefore must be supported.

<a id="rst-sliced-vbi-format-negotiation-1"></a>
<a id="rst-sliced-vbi-format-negotiation"></a>

## Sliced VBI Format Negotiation

To find out which data services are supported by the hardware applications can call the [VIDIOC\_G\_SLICED\_VBI\_CAP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vidioc-g-sliced-vbi-cap>) ioctl. All drivers implementing the sliced VBI interface must support this ioctl. The results may differ from those of the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl when the number of VBI lines the hardware can capture or output per frame, or the number of services it can identify on a given line are limited. For example on PAL line 16 the hardware may be able to look for a VPS or Teletext signal, but not both at the same time.

To determine the currently selected services applications set the `type` field of struct `v4l2_format` to `V4L2_BUF_TYPE_SLICED_VBI_CAPTURE` or `V4L2_BUF_TYPE_SLICED_VBI_OUTPUT`, and the [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl fills the `fmt.sliced` member, a struct `v4l2_sliced_vbi_format`.

Applications can request different parameters by initializing or modifying the `fmt.sliced` member and calling the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with a pointer to the struct `v4l2_format` structure.

The sliced VBI API is more complicated than the raw VBI API because the hardware must be told which VBI service to expect on each scan line. Not all services may be supported by the hardware on all lines (this is especially true for VBI output where Teletext is often unsupported and other services can only be inserted in one specific line). In many cases, however, it is sufficient to just set the `service_set` field to the required services and let the driver fill the `service_lines` array according to hardware capabilities. Only if more precise control is needed should the programmer set the `service_lines` array explicitly.

The [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl modifies the parameters according to hardware capabilities. When the driver allocates resources at this point, it may return an `EBUSY` error code if the required resources are temporarily unavailable. Other resource allocation points which may return `EBUSY` can be the [vidioc\_streamon](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctl and the first `read()`, `write()` and `select()` call.

<a id="c-v4l2_sliced_vbi_format"></a>



```c
v4l2_sliced_vbi_format
```

<a id="rst-struct-v4l2-sliced-vbi-format"></a>

### struct v4l2\_sliced\_vbi\_format

<!-- Source LaTeX layout: \begingroup
\scriptsize
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{.85cm}|p{3.3cm}|p{4.45cm}|p{4.45cm}|p{4.45cm}| -->


<table>
<tbody>
<tr>
<td>



\_\_u16

</td>
<td>



`service_set`

</td>
<td colspan="3">



If `service_set` is non-zero when passed with [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) or [VIDIOC\_TRY\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), the `service_lines` array will be filled by the driver according to the services specified in this field. For example, if `service_set` is initialized with `V4L2_SLICED_TELETEXT_B | V4L2_SLICED_WSS_625`, a driver for the cx25840 video decoder sets lines 7-22 of both fields <a id="rst-footnote-reference-1"></a>[1](#rst-f1) to `V4L2_SLICED_TELETEXT_B` and line 23 of the first field to `V4L2_SLICED_WSS_625`. If `service_set` is set to zero, then the values of `service_lines` will be used instead.

On return the driver sets this field to the union of all elements of the returned `service_lines` array. It may contain less services than requested, perhaps just one, if the hardware cannot handle more services simultaneously. It may be empty (zero) if none of the requested services are supported by the hardware.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`service_lines`\[2\]\[24\]

</td>
<td colspan="3">



Applications initialize this array with sets of data services the driver shall look for or insert on the respective scan line. Subject to hardware capabilities drivers return the requested set, a subset, which may be just a single service, or an empty set. When the hardware cannot handle multiple services on the same line the driver shall choose one. No assumptions can be made on which service the driver chooses.

Data services are defined in [Sliced VBI services](<#rst-vbi-services2>). Array indices map to ITU-R line numbers<a id="rst-footnote-reference-2"></a>[2](#rst-f2) as follows:

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



Element

</td>
<td>



525 line systems

</td>
<td>



625 line systems

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`service_lines`\[0\]\[1\]

</td>
<td>



1

</td>
<td>



1

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`service_lines`\[0\]\[23\]

</td>
<td>



23

</td>
<td>



23

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`service_lines`\[1\]\[1\]

</td>
<td>



264

</td>
<td>



314

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`service_lines`\[1\]\[23\]

</td>
<td>



286

</td>
<td>



336

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td colspan="3">



 Drivers must set `service_lines` \[0\]\[0\] and `service_lines`\[1\]\[0\] to zero. The `V4L2_VBI_ITU_525_F1_START`, `V4L2_VBI_ITU_525_F2_START`, `V4L2_VBI_ITU_625_F1_START` and `V4L2_VBI_ITU_625_F2_START` defines give the start line numbers for each field for each 525 or 625 line format as a convenience. Don't forget that ITU line numbering starts at 1, not 0.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`io_size`

</td>
<td colspan="3">



 Maximum number of bytes passed by one `read()` or `write()` call, and the buffer size in bytes for the [vidioc\_qbuf](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) and [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. Drivers set this field to the size of struct `v4l2_sliced_vbi_data` times the number of non-zero elements in the returned `service_lines` array (that is the number of lines potentially carrying data).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`\[2\]

</td>
<td colspan="3">



 This array is reserved for future extensions.

Applications and drivers must set it to zero.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

<a id="rst-sliced-vbi-services"></a>
<a id="rst-vbi-services2"></a>

### Sliced VBI services

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{4.2cm}|p{1.1cm}|p{2.1cm}|p{2.0cm}|p{6.5cm}| -->


<table>
<thead>
<tr>
<th>



Symbol

</th>
<th>



Value

</th>
<th>



Reference

</th>
<th>



Lines, usually

</th>
<th>



Payload

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_SLICED_TELETEXT_B` (Teletext System B)

</td>
<td>



0x0001

</td>
<td>



[ets300706](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-ets300706>),

[itu653](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu653>)

</td>
<td>



PAL/SECAM line 7-22, 320-335 (second field 7-22)

</td>
<td>



Last 42 of the 45 byte Teletext packet, that is without clock run-in and framing code, lsb first transmitted.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_VPS`

</td>
<td>



0x0400

</td>
<td>



[ets300231](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-ets300231>)

</td>
<td>



PAL line 16

</td>
<td>



Byte number 3 to 15 according to Figure 9 of ETS 300 231, lsb first transmitted.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_CAPTION_525`

</td>
<td>



0x1000

</td>
<td>



[cea608](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-cea608>)

</td>
<td>



NTSC line 21, 284 (second field 21)

</td>
<td>



Two bytes in transmission order, including parity bit, lsb first transmitted.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_WSS_625`

</td>
<td>



0x4000

</td>
<td>



[itu1119](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu1119>),

[en300294](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-en300294>)

</td>
<td>



PAL/SECAM line 23

</td>
<td>



See [V4L2\_SLICED\_WSS\_625 payload](<#rst-v4l2-sliced-wss-625-payload>) below.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_VBI_525`

</td>
<td>



0x1000

</td>
<td colspan="3">



 Set of services applicable to 525 line systems.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_VBI_625`

</td>
<td>



0x4401

</td>
<td colspan="3">



 Set of services applicable to 625 line systems.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

Drivers may return an `EINVAL` error code when applications attempt to read or write data without prior format negotiation, after switching the video standard (which may invalidate the negotiated VBI parameters) and after switching the video input (which may change the video standard as a side effect). The [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl may return an `EBUSY` error code when applications attempt to change the format while i/o is in progress (between a [vidioc\_streamon](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) and [VIDIOC\_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) call, and after the first `read()` or `write()` call).

<a id="rst-v4l2-sliced-wss-625-payload-1"></a>
<a id="rst-v4l2-sliced-wss-625-payload"></a>

#### V4L2\_SLICED\_WSS\_625 payload

The payload for `V4L2_SLICED_WSS_625` is:

>
> <table>
> <tbody>
> <tr>
> <td>
>
>
>
> Byte
>
> </td>
> <td colspan="8">
>
>
>
> 0
>
> </td>
> <td colspan="8">
>
>
>
> 1
>
> </td>
> </tr>
> <tr>
> <td rowspan="2">
>
>
>
> Bit
>
> </td>
> <td colspan="4">
>
>
>
> msb
>
> </td>
> <td colspan="4">
>
>
>
> lsb
>
> </td>
> <td colspan="4">
>
>
>
> msb
>
> </td>
> <td colspan="4">
>
>
>
> lsb
>
> </td>
> </tr>
> <tr>
> <td>
>
>
>
> 7
>
> </td>
> <td>
>
>
>
> 6
>
> </td>
> <td>
>
>
>
> 5
>
> </td>
> <td>
>
>
>
> 4
>
> </td>
> <td>
>
>
>
> 3
>
> </td>
> <td>
>
>
>
> 2
>
> </td>
> <td>
>
>
>
> 1
>
> </td>
> <td>
>
>
>
> 0
>
> </td>
> <td>
>
>
>
> x
>
> </td>
> <td>
>
>
>
> x
>
> </td>
> <td>
>
>
>
> 13
>
> </td>
> <td>
>
>
>
> 12
>
> </td>
> <td>
>
>
>
> 11
>
> </td>
> <td>
>
>
>
> 10
>
> </td>
> <td>
>
>
>
> 9
>
> </td>
> <td>
>
>
>
> 8
>
> </td>
> </tr>
> </tbody>
> </table>

<a id="rst-reading-and-writing-sliced-vbi-data"></a>

## Reading and writing sliced VBI data

A single `read()` or `write()` call must pass all data belonging to one video frame. That is an array of struct `v4l2_sliced_vbi_data` structures with one or more elements and a total size not exceeding `io_size` bytes. Likewise in streaming I/O mode one buffer of `io_size` bytes must contain data of one video frame. The `id` of unused struct `v4l2_sliced_vbi_data` elements must be zero.

<a id="c-v4l2_sliced_vbi_data"></a>



```c
v4l2_sliced_vbi_data
```

<a id="rst-struct-v4l2-sliced-vbi-data"></a>

### struct v4l2\_sliced\_vbi\_data

<!-- tabularcolumns: |p{1.2cm}|p{2.2cm}|p{13.9cm}| -->


<table>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`id`

</td>
<td>



A flag from [vbi-services](</kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vbi-services>) identifying the type of data in this packet. Only a single bit must be set. When the `id` of a captured packet is zero, the packet is empty and the contents of other fields are undefined. Applications shall ignore empty packets. When the `id` of a packet for output is zero the contents of the `data` field are undefined and the driver must no longer insert data on the requested `field` and `line`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`field`

</td>
<td>



The video field number this data has been captured from, or shall be inserted at. `0` for the first field, `1` for the second field.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`line`

</td>
<td>



The field (as opposed to frame) line number this data has been captured from, or shall be inserted at. See [vbi-525](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-525>) and [vbi-625](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-625>) for valid values. Sliced VBI capture devices can set the line number of all packets to `0` if the hardware cannot reliably identify scan lines. The field number must always be valid.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`

</td>
<td>



This field is reserved for future extensions. Applications and drivers must set it to zero.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`data`\[48\]

</td>
<td>



The packet payload. See [vbi-services](</kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vbi-services>) for the contents and number of bytes passed for each data type. The contents of padding bytes at the end of this array are undefined, drivers and applications shall ignore them.

</td>
</tr>
</tbody>
</table>

Packets are always passed in ascending line number order, without duplicate line numbers. The `write()` function and the [vidioc\_qbuf](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl must return an `EINVAL` error code when applications violate this rule. They must also return an EINVAL error code when applications pass an incorrect field or line number, or a combination of `field`, `line` and `id` which has not been negotiated with the [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) or [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. When the line numbers are unknown the driver must pass the packets in transmitted order. The driver can insert empty packets with `id` set to zero anywhere in the packet array.

To assure synchronization and to distinguish from frame dropping, when a captured frame does not carry any of the requested data services drivers must pass one or more empty packets. When an application fails to pass VBI data in time for output, the driver must output the last VPS and WSS packet again, and disable the output of Closed Caption and Teletext data, or output data which is ignored by Closed Caption and Teletext decoders.

A sliced VBI device may support [read/write](</kernel/userspace/userspace-api/media-v4l/rw.md#rst-rw>) and/or streaming ([memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) and/or [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>)) I/O. The latter bears the possibility of synchronizing video and VBI data by using buffer timestamps.

<a id="rst-sliced-vbi-data-in-mpeg-streams"></a>

## Sliced VBI Data in MPEG Streams

If a device can produce an MPEG output stream, it may be capable of providing [negotiated sliced VBI services](<#rst-sliced-vbi-format-negotiation>) as data embedded in the MPEG stream. Users or applications control this sliced VBI data insertion with the [V4L2\_CID\_MPEG\_STREAM\_VBI\_FMT](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-v4l2-mpeg-stream-vbi-fmt>) control.

If the driver does not provide the [V4L2\_CID\_MPEG\_STREAM\_VBI\_FMT](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-v4l2-mpeg-stream-vbi-fmt>) control, or only allows that control to be set to [V4L2\_MPEG\_STREAM\_VBI\_FMT\_NONE](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-v4l2-mpeg-stream-vbi-fmt>), then the device cannot embed sliced VBI data in the MPEG stream.

The [V4L2\_CID\_MPEG\_STREAM\_VBI\_FMT](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-v4l2-mpeg-stream-vbi-fmt>) control does not implicitly set the device driver to capture nor cease capturing sliced VBI data. The control only indicates to embed sliced VBI data in the MPEG stream, if an application has negotiated sliced VBI service be captured.

It may also be the case that a device can embed sliced VBI data in only certain types of MPEG streams: for example in an MPEG-2 PS but not an MPEG-2 TS. In this situation, if sliced VBI data insertion is requested, the sliced VBI data will be embedded in MPEG stream types when supported, and silently omitted from MPEG stream types where sliced VBI data insertion is not supported by the device.

The following subsections specify the format of the embedded sliced VBI data.

<a id="rst-mpeg-stream-embedded-sliced-vbi-data-format-none"></a>

### MPEG Stream Embedded, Sliced VBI Data Format: NONE

The [V4L2\_MPEG\_STREAM\_VBI\_FMT\_NONE](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-v4l2-mpeg-stream-vbi-fmt>) embedded sliced VBI format shall be interpreted by drivers as a control to cease embedding sliced VBI data in MPEG streams. Neither the device nor driver shall insert "empty" embedded sliced VBI data packets in the MPEG stream when this format is set. No MPEG stream data structures are specified for this format.

<a id="rst-mpeg-stream-embedded-sliced-vbi-data-format-ivtv"></a>

### MPEG Stream Embedded, Sliced VBI Data Format: IVTV

The [V4L2\_MPEG\_STREAM\_VBI\_FMT\_IVTV](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-v4l2-mpeg-stream-vbi-fmt>) embedded sliced VBI format, when supported, indicates to the driver to embed up to 36 lines of sliced VBI data per frame in an MPEG-2 <em>Private Stream 1 PES</em> packet encapsulated in an MPEG-2 <em>Program Pack</em> in the MPEG stream.

<em>Historical context</em>: This format specification originates from a custom, embedded, sliced VBI data format used by the `ivtv` driver. This format has already been informally specified in the kernel sources in the file `Documentation/userspace-api/media/drivers/cx2341x-uapi.rst` . The maximum size of the payload and other aspects of this format are driven by the CX23415 MPEG decoder's capabilities and limitations with respect to extracting, decoding, and displaying sliced VBI data embedded within an MPEG stream.

This format's use is <em>not</em> exclusive to the `ivtv` driver <em>nor</em> exclusive to CX2341x devices, as the sliced VBI data packet insertion into the MPEG stream is implemented in driver software. At least the `cx18` driver provides sliced VBI data insertion into an MPEG-2 PS in this format as well.

The following definitions specify the payload of the MPEG-2 <em>Private Stream 1 PES</em> packets that contain sliced VBI data when [V4L2\_MPEG\_STREAM\_VBI\_FMT\_IVTV](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-v4l2-mpeg-stream-vbi-fmt>) is set. (The MPEG-2 <em>Private Stream 1 PES</em> packet header and encapsulating MPEG-2 <em>Program Pack</em> header are not detailed here. Please refer to the MPEG-2 specifications for details on those packet headers.)

The payload of the MPEG-2 <em>Private Stream 1 PES</em> packets that contain sliced VBI data is specified by struct `v4l2_mpeg_vbi_fmt_ivtv`. The payload is variable length, depending on the actual number of lines of sliced VBI data present in a video frame. The payload may be padded at the end with unspecified fill bytes to align the end of the payload to a 4-byte boundary. The payload shall never exceed 1552 bytes (2 fields with 18 lines/field with 43 bytes of data/line and a 4 byte magic number).

<a id="c-v4l2_mpeg_vbi_fmt_ivtv"></a>



```c
v4l2_mpeg_vbi_fmt_ivtv
```

<a id="rst-struct-v4l2-mpeg-vbi-fmt-ivtv"></a>

### struct v4l2\_mpeg\_vbi\_fmt\_ivtv

<!-- tabularcolumns: |p{4.2cm}|p{2.0cm}|p{11.1cm}| -->


<table>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`magic`\[4\]

</td>
<td>



A "magic" constant from [Magic Constants for struct v4l2\_mpeg\_vbi\_fmt\_ivtv magic field](<#rst-v4l2-mpeg-vbi-fmt-ivtv-magic>) that indicates this is a valid sliced VBI data payload and also indicates which member of the anonymous union, `itv0` or `ITV0`, to use for the payload data.

</td>
</tr>
<tr>
<td>



union \{

</td>
<td colspan="2">



(anonymous)

</td>
</tr>
<tr>
<td>



struct `v4l2_mpeg_vbi_itv0`

</td>
<td>



`itv0`

</td>
<td>



The primary form of the sliced VBI data payload that contains anywhere from 1 to 35 lines of sliced VBI data. Line masks are provided in this form of the payload indicating which VBI lines are provided.

</td>
</tr>
<tr>
<td>



struct [v4l2\_mpeg\_vbi\_ITV0](<#rst-v4l2-mpeg-vbi-itv0-1>)

</td>
<td>



`ITV0`

</td>
<td>



An alternate form of the sliced VBI data payload used when 36 lines of sliced VBI data are present. No line masks are provided in this form of the payload; all valid line mask bits are implicitly set.

</td>
</tr>
<tr>
<td>



\}

</td>
<td colspan="2">





</td>
</tr>
</tbody>
</table>

<a id="rst-magic-constants-for-struct-v4l2-mpeg-vbi-fmt-ivtv-magic-field"></a>
<a id="rst-v4l2-mpeg-vbi-fmt-ivtv-magic"></a>

### Magic Constants for struct v4l2\_mpeg\_vbi\_fmt\_ivtv magic field

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->


<table>
<thead>
<tr>
<th>



Defined Symbol

</th>
<th>



Value

</th>
<th>



Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_MPEG_VBI_IVTV_MAGIC0`

</td>
<td>



"itv0"

</td>
<td>



Indicates the `itv0` member of the union in struct `v4l2_mpeg_vbi_fmt_ivtv` is valid.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VBI_IVTV_MAGIC1`

</td>
<td>



"ITV0"

</td>
<td>



Indicates the `ITV0` member of the union in struct `v4l2_mpeg_vbi_fmt_ivtv` is valid and that 36 lines of sliced VBI data are present.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_mpeg_vbi_itv0"></a>



```c
v4l2_mpeg_vbi_itv0
```

<a id="c-v4l2_mpeg_vbi_ITV0"></a>



```c
v4l2_mpeg_vbi_ITV0
```

<a id="rst-structs-v4l2-mpeg-vbi-itv0-and-v4l2-mpeg-vbi-itv0"></a>

### structs v4l2\_mpeg\_vbi\_itv0 and v4l2\_mpeg\_vbi\_ITV0

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{4.6cm}|p{2.0cm}|p{10.7cm}| -->


<table>
<tbody>
<tr>
<td>



\_\_le32

</td>
<td>



`linemask`\[2\]

</td>
<td>



Bitmasks indicating the VBI service lines present. These `linemask` values are stored in little endian byte order in the MPEG stream. Some reference `linemask` bit positions with their corresponding VBI line number and video field are given below. b<sub>0</sub> indicates the least significant bit of a `linemask` value:



```text
linemask[0] b0:     line  6  first field
linemask[0] b17:    line 23  first field
linemask[0] b18:    line  6  second field
linemask[0] b31:    line 19  second field
linemask[1] b0:     line 20  second field
linemask[1] b3:     line 23  second field
linemask[1] b4-b31: unused and set to 0
```

</td>
</tr>
<tr>
<td>



struct `v4l2_mpeg_vbi_itv0_line`

</td>
<td>



`line`\[35\]

</td>
<td>



This is a variable length array that holds from 1 to 35 lines of sliced VBI data. The sliced VBI data lines present correspond to the bits set in the `linemask` array, starting from b<sub>0</sub> of `linemask`\[0\] up through b<sub>31</sub> of `linemask`\[0\], and from b<sub>0</sub> of `linemask`\[1\] up through b<sub>3</sub> of `linemask`\[1\]. `line`\[0\] corresponds to the first bit found set in the `linemask` array, `line`\[1\] corresponds to the second bit found set in the `linemask` array, etc. If no `linemask` array bits are set, then `line`\[0\] may contain one line of unspecified data that should be ignored by applications.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-struct-v4l2-mpeg-vbi-itv0"></a>
<a id="rst-v4l2-mpeg-vbi-itv0-1"></a>

### struct v4l2\_mpeg\_vbi\_ITV0

<!-- tabularcolumns: |p{5.2cm}|p{2.4cm}|p{9.7cm}| -->


<table>
<tbody>
<tr>
<td>



struct `v4l2_mpeg_vbi_itv0_line`

</td>
<td>



`line`\[36\]

</td>
<td>



A fixed length array of 36 lines of sliced VBI data. `line`\[0\] through `line`\[17\] correspond to lines 6 through 23 of the first field. `line`\[18\] through `line`\[35\] corresponds to lines 6 through 23 of the second field.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_mpeg_vbi_itv0_line"></a>



```c
v4l2_mpeg_vbi_itv0_line
```

<a id="rst-struct-v4l2-mpeg-vbi-itv0-line"></a>

### struct v4l2\_mpeg\_vbi\_itv0\_line

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`id`

</td>
<td>



A line identifier value from [Line Identifiers for struct v4l2\_mpeg\_vbi\_itv0\_line id field](<#rst-itv0-line-identifier-constants>) that indicates the type of sliced VBI data stored on this line.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`data`\[42\]

</td>
<td>



The sliced VBI data for the line.

</td>
</tr>
</tbody>
</table>

<a id="rst-line-identifiers-for-struct-v4l2-mpeg-vbi-itv0-line-id-field"></a>
<a id="rst-itv0-line-identifier-constants"></a>

### Line Identifiers for struct v4l2\_mpeg\_vbi\_itv0\_line id field

<!-- tabularcolumns: |p{7.0cm}|p{1.8cm}|p{8.5cm}| -->


<table>
<thead>
<tr>
<th>



Defined Symbol

</th>
<th>



Value

</th>
<th>



Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_MPEG_VBI_IVTV_TELETEXT_B`

</td>
<td>



1

</td>
<td>



Refer to [Sliced VBI services](<#rst-vbi-services2>) for a description of the line payload.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VBI_IVTV_CAPTION_525`

</td>
<td>



4

</td>
<td>



Refer to [Sliced VBI services](<#rst-vbi-services2>) for a description of the line payload.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VBI_IVTV_WSS_625`

</td>
<td>



5

</td>
<td>



Refer to [Sliced VBI services](<#rst-vbi-services2>) for a description of the line payload.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VBI_IVTV_VPS`

</td>
<td>



7

</td>
<td>



Refer to [Sliced VBI services](<#rst-vbi-services2>) for a description of the line payload.

</td>
</tr>
</tbody>
</table>

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



**[1]** According to [ETS 300 706](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-ets300706>) lines 6-22 of the first field and lines 5-22 of the second field may carry Teletext data.

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



**[2]** See also [vbi-525](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-525>) and [vbi-625](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-625>).

---

# Memory-to-memory Stateless Video Decoder Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> A stateless decoder is a decoder that works without retaining any kind of state between processed frames. This means that each frame is decoded independently of any previous and future frames, and that the client is responsible for…

<a id="rst-memory-to-memory-stateless-video-decoder-interface"></a>
<a id="rst-stateless-decoder"></a>

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

<!-- c:namespace: V4L -->

A stateless decoder is a decoder that works without retaining any kind of state between processed frames. This means that each frame is decoded independently of any previous and future frames, and that the client is responsible for maintaining the decoding state and providing it to the decoder with each decoding request. This is in contrast to the stateful video decoder interface, where the hardware and driver maintain the decoding state and all the client has to do is to provide the raw encoded stream and dequeue decoded frames in display order.

This section describes how user-space ("the client") is expected to communicate with stateless decoders in order to successfully decode an encoded stream. Compared to stateful codecs, the decoder/client sequence is simpler, but the cost of this simplicity is extra complexity in the client which is responsible for maintaining a consistent decoding state.

Stateless decoders make use of the [Request API](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>). A stateless decoder must expose the `V4L2_BUF_CAP_SUPPORTS_REQUESTS` capability on its `OUTPUT` queue when `VIDIOC_REQBUFS()` or `VIDIOC_CREATE_BUFS()` are invoked.

Depending on the encoded formats supported by the decoder, a single decoded frame may be the result of several decode requests (for instance, H.264 streams with multiple slices per frame). Decoders that support such formats must also expose the `V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF` capability on their `OUTPUT` queue.

<a id="rst-querying-capabilities"></a>

## Querying capabilities

1. To enumerate the set of coded formats supported by the decoder, the client calls `VIDIOC_ENUM_FMT()` on the `OUTPUT` queue.

   - The driver must always return the full set of supported `OUTPUT` formats, irrespective of the format currently set on the `CAPTURE` queue.

   - Simultaneously, the driver must restrain the set of values returned by codec-specific capability controls (such as H.264 profiles) to the set actually supported by the hardware.

2. To enumerate the set of supported raw formats, the client calls `VIDIOC_ENUM_FMT()` on the `CAPTURE` queue.

   - The driver must return only the formats supported for the format currently active on the `OUTPUT` queue.

   - Depending on the currently set `OUTPUT` format, the set of supported raw formats may depend on the value of some codec-dependent controls. The client is responsible for making sure that these controls are set before querying the `CAPTURE` queue. Failure to do so will result in the default values for these controls being used, and a returned set of formats that may not be usable for the media the client is trying to decode.

3. The client may use `VIDIOC_ENUM_FRAMESIZES()` to detect supported resolutions for a given format, passing desired pixel format in `v4l2_frmsizeenum`'s `pixel_format`.

4. Supported profiles and levels for the current `OUTPUT` format, if applicable, may be queried using their respective controls via `VIDIOC_QUERYCTRL()`.

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

## Initialization

1. Set the coded format on the `OUTPUT` queue via `VIDIOC_S_FMT()`.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.

     - **`pixelformat`**

       a coded pixel format.

     - **`width`, `height`**

       coded width and height parsed from the stream.

     - **other fields**

       follow standard semantics.

   > [!NOTE]
   >
   > Changing the `OUTPUT` format may change the currently set `CAPTURE` format. The driver will derive a new `CAPTURE` format from the `OUTPUT` format being set, including resolution, colorimetry parameters, etc. If the client needs a specific `CAPTURE` format, it must adjust it afterwards.

2. Call `VIDIOC_S_EXT_CTRLS()` to set all the controls (parsed headers, etc.) required by the `OUTPUT` format to enumerate the `CAPTURE` formats.

3. Call `VIDIOC_G_FMT()` for `CAPTURE` queue to get the format for the destination buffers parsed/decoded from the bytestream.

   - **Required fields:**

     - **`type`**

       a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.

   - **Returned fields:**

     - **`width`, `height`**

       frame buffer resolution for the decoded frames.

     - **`pixelformat`**

       pixel format for decoded frames.

     - **`num_planes` (for \_MPLANE `type` only)**

       number of planes for pixelformat.

     - **`sizeimage`, `bytesperline`**

       as per standard semantics; matching frame buffer format.

   > [!NOTE]
   >
   > The value of `pixelformat` may be any pixel format supported for the `OUTPUT` format, based on the hardware capabilities. It is suggested that the driver chooses the preferred/optimal format for the current configuration. For example, a YUV format may be preferred over an RGB format, if an additional conversion step would be required for RGB.

4. *\[optional\]* Enumerate `CAPTURE` formats via `VIDIOC_ENUM_FMT()` on the `CAPTURE` queue. The client may use this ioctl to discover which alternative raw formats are supported for the current `OUTPUT` format and select one of them via `VIDIOC_S_FMT()`.

   > [!NOTE]
   >
   > The driver will return only formats supported for the currently selected `OUTPUT` format and currently set controls, even if more formats may be supported by the decoder in general.
   >
   > For example, a decoder may support YUV and RGB formats for resolutions 1920x1088 and lower, but only YUV for higher resolutions (due to hardware limitations). After setting a resolution of 1920x1088 or lower as the `OUTPUT` format, `VIDIOC_ENUM_FMT()` may return a set of YUV and RGB pixel formats, but after setting a resolution higher than 1920x1088, the driver will not return RGB pixel formats, since they are unsupported for this resolution.

5. *\[optional\]* Choose a different `CAPTURE` format than suggested via `VIDIOC_S_FMT()` on `CAPTURE` queue. It is possible for the client to choose a different format than selected/suggested by the driver in `VIDIOC_G_FMT()`.

   > - **Required fields:**
   >
   >   - **`type`**
   >
   >     a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.
   >
   >   - **`pixelformat`**
   >
   >     a raw pixel format.
   >
   >   - **`width`, `height`**
   >
   >     frame buffer resolution of the decoded stream; typically unchanged from what was returned with `VIDIOC_G_FMT()`, but it may be different if the hardware supports composition and/or scaling.

   After performing this step, the client must perform step 3 again in order to obtain up-to-date information about the buffers size and layout.

6. Allocate source (bytestream) buffers via `VIDIOC_REQBUFS()` on `OUTPUT` queue.

   > - **Required fields:**
   >
   >   - **`count`**
   >
   >     requested number of buffers to allocate; greater than zero.
   >
   >   - **`type`**
   >
   >     a `V4L2_BUF_TYPE_*` enum appropriate for `OUTPUT`.
   >
   >   - **`memory`**
   >
   >     follows standard semantics.
   >
   > - **Returned fields:**
   >
   >   - **`count`**
   >
   >     actual number of buffers allocated.
   >
   > - If required, the driver will adjust `count` to be equal or bigger to the minimum of required number of `OUTPUT` buffers for the given format and requested count. The client must check this value after the ioctl returns to get the actual number of buffers allocated.

7. Allocate destination (raw format) buffers via `VIDIOC_REQBUFS()` on the `CAPTURE` queue.

   > - **Required fields:**
   >
   >   - **`count`**
   >
   >     requested number of buffers to allocate; greater than zero. The client is responsible for deducing the minimum number of buffers required for the stream to be properly decoded (taking e.g. reference frames into account) and pass an equal or bigger number.
   >
   >   - **`type`**
   >
   >     a `V4L2_BUF_TYPE_*` enum appropriate for `CAPTURE`.
   >
   >   - **`memory`**
   >
   >     follows standard semantics. `V4L2_MEMORY_USERPTR` is not supported for `CAPTURE` buffers.
   >
   > - **Returned fields:**
   >
   >   - **`count`**
   >
   >     adjusted to allocated number of buffers, in case the codec requires more buffers than requested.
   >
   > - The driver must adjust count to the minimum of required number of `CAPTURE` buffers for the current format, stream configuration and requested count. The client must check this value after the ioctl returns to get the number of buffers allocated.

8. - **Allocate requests (likely one per `OUTPUT` buffer) via**

     `MEDIA_IOC_REQUEST_ALLOC()` on the media device.

9. - **Start streaming on both `OUTPUT` and `CAPTURE` queues via**

     `VIDIOC_STREAMON()`.

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

## Decoding

For each frame, the client is responsible for submitting at least one request to which the following is attached:

- The amount of encoded data expected by the codec for its current configuration, as a buffer submitted to the `OUTPUT` queue. Typically, this corresponds to one frame worth of encoded data, but some formats may allow (or require) different amounts per unit.

- All the metadata needed to decode the submitted encoded data, in the form of controls relevant to the format being decoded.

The amount of data and contents of the source `OUTPUT` buffer, as well as the controls that must be set on the request, depend on the active coded pixel format and might be affected by codec-specific extended controls, as stated in documentation of each format.

If there is a possibility that the decoded frame will require one or more decode requests after the current one in order to be produced, then the client must set the `V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF` flag on the `OUTPUT` buffer. This will result in the (potentially partially) decoded `CAPTURE` buffer not being made available for dequeueing, and reused for the next decode request if the timestamp of the next `OUTPUT` buffer has not changed.

A typical frame would thus be decoded using the following sequence:

1. Queue an `OUTPUT` buffer containing one unit of encoded bytestream data for the decoding request, using `VIDIOC_QBUF()`.

   > - **Required fields:**
   >
   >   - **`index`**
   >
   >     index of the buffer being queued.
   >
   >   - **`type`**
   >
   >     type of the buffer.
   >
   >   - **`bytesused`**
   >
   >     number of bytes taken by the encoded data frame in the buffer.
   >
   >   - **`flags`**
   >
   >     the `V4L2_BUF_FLAG_REQUEST_FD` flag must be set. Additionally, if we are not sure that the current decode request is the last one needed to produce a fully decoded frame, then `V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF` must also be set.
   >
   >   - **`request_fd`**
   >
   >     must be set to the file descriptor of the decoding request.
   >
   >   - **`timestamp`**
   >
   >     must be set to a unique value per frame. This value will be propagated into the decoded frame's buffer and can also be used to use this frame as the reference of another. If using multiple decode requests per frame, then the timestamps of all the `OUTPUT` buffers for a given frame must be identical. If the timestamp changes, then the currently held `CAPTURE` buffer will be made available for dequeuing and the current request will work on a new `CAPTURE` buffer.

2. Set the codec-specific controls for the decoding request, using `VIDIOC_S_EXT_CTRLS()`.

   > - **Required fields:**
   >
   >   - **`which`**
   >
   >     must be `V4L2_CTRL_WHICH_REQUEST_VAL`.
   >
   >   - **`request_fd`**
   >
   >     must be set to the file descriptor of the decoding request.
   >
   >   - **other fields**
   >
   >     other fields are set as usual when setting controls. The `controls` array must contain all the codec-specific controls required to decode a frame.

   > [!NOTE]
   >
   > It is possible to specify the controls in different invocations of `VIDIOC_S_EXT_CTRLS()`, or to overwrite a previously set control, as long as `request_fd` and `which` are properly set. The controls state at the moment of request submission is the one that will be considered.

   > [!NOTE]
   >
   > The order in which steps 1 and 2 take place is interchangeable.

3. Submit the request by invoking `MEDIA_REQUEST_IOC_QUEUE()` on the request FD.

   > If the request is submitted without an `OUTPUT` buffer, or if some of the required controls are missing from the request, then `MEDIA_REQUEST_IOC_QUEUE()` will return `-ENOENT`. If more than one `OUTPUT` buffer is queued, then it will return `-EINVAL`. `MEDIA_REQUEST_IOC_QUEUE()` returning non-zero means that no `CAPTURE` buffer will be produced for this request.

`CAPTURE` buffers must not be part of the request, and are queued independently. They are returned in decode order (i.e. the same order as coded frames were submitted to the `OUTPUT` queue).

Runtime decoding errors are signaled by the dequeued `CAPTURE` buffers carrying the `V4L2_BUF_FLAG_ERROR` flag. If a decoded reference frame has an error, then all following decoded frames that refer to it also have the `V4L2_BUF_FLAG_ERROR` flag set, although the decoder will still try to produce (likely corrupted) frames.

<a id="rst-buffer-management-while-decoding"></a>

## Buffer management while decoding

Contrary to stateful decoders, a stateless decoder does not perform any kind of buffer management: it only guarantees that dequeued `CAPTURE` buffers can be used by the client for as long as they are not queued again. "Used" here encompasses using the buffer for compositing or display.

A dequeued capture buffer can also be used as the reference frame of another buffer.

A frame is specified as reference by converting its timestamp into nanoseconds, and storing it into the relevant member of a codec-dependent control structure. The `v4l2_timeval_to_ns()` function must be used to perform that conversion. The timestamp of a frame can be used to reference it as soon as all its units of encoded data are successfully submitted to the `OUTPUT` queue.

A decoded buffer containing a reference frame must not be reused as a decoding target until all the frames referencing it have been decoded. The safest way to achieve this is to refrain from queueing a reference buffer until all the decoded frames referencing it have been dequeued. However, if the driver can guarantee that buffers queued to the `CAPTURE` queue are processed in queued order, then user-space can take advantage of this guarantee and queue a reference buffer when the following conditions are met:

1. All the requests for frames affected by the reference frame have been queued, and

2. A sufficient number of `CAPTURE` buffers to cover all the decoded referencing frames have been queued.

When queuing a decoding request, the driver will increase the reference count of all the resources associated with reference frames. This means that the client can e.g. close the DMABUF file descriptors of reference frame buffers if it won't need them afterwards.

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

## Seeking

In order to seek, the client just needs to submit requests using input buffers corresponding to the new stream position. It must however be aware that resolution may have changed and follow the dynamic resolution change sequence in that case. Also depending on the codec used, picture parameters (e.g. SPS/PPS for H.264) may have changed and the client is responsible for making sure that a valid state is sent to the decoder.

The client is then free to ignore any returned `CAPTURE` buffer that comes from the pre-seek position.

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

## Pausing

In order to pause, the client can just cease queuing buffers onto the `OUTPUT` queue. Without source bytestream data, there is no data to process and the codec will remain idle.

<a id="rst-dynamic-resolution-change"></a>

## Dynamic resolution change

If the client detects a resolution change in the stream, it will need to perform the initialization sequence again with the new resolution:

1. If the last submitted request resulted in a `CAPTURE` buffer being held by the use of the `V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF` flag, then the last frame is not available on the `CAPTURE` queue. In this case, a `V4L2_DEC_CMD_FLUSH` command shall be sent. This will make the driver dequeue the held `CAPTURE` buffer.

2. Wait until all submitted requests have completed and dequeue the corresponding output buffers.

3. Call `VIDIOC_STREAMOFF()` on both the `OUTPUT` and `CAPTURE` queues.

4. Free all `CAPTURE` buffers by calling `VIDIOC_REQBUFS()` on the `CAPTURE` queue with a buffer count of zero.

5. Perform the initialization sequence again (minus the allocation of `OUTPUT` buffers), with the new resolution set on the `OUTPUT` queue. Note that due to resolution constraints, a different format may need to be picked on the `CAPTURE` queue.

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

## Drain

If the last submitted request resulted in a `CAPTURE` buffer being held by the use of the `V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF` flag, then the last frame is not available on the `CAPTURE` queue. In this case, a `V4L2_DEC_CMD_FLUSH` command shall be sent. This will make the driver dequeue the held `CAPTURE` buffer.

After that, in order to drain the stream on a stateless decoder, the client just needs to wait until all the submitted requests are completed.

---

# Sub-device Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The complex nature of V4L2 devices, where hardware is often made of several integrated circuits that need to interact with each other in a controlled way, leads to complex V4L2 drivers. The drivers usually reflect the hardware model in…

<a id="rst-sub-device-interface"></a>
<a id="rst-subdev"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The complex nature of V4L2 devices, where hardware is often made of several integrated circuits that need to interact with each other in a controlled way, leads to complex V4L2 drivers. The drivers usually reflect the hardware model in software, and model the different hardware components as software blocks called sub-devices.

V4L2 sub-devices are usually kernel-only objects. If the V4L2 driver implements the media device API, they will automatically inherit from media entities. Applications will be able to enumerate the sub-devices and discover the hardware topology using the media entities, pads and links enumeration API.

In addition to make sub-devices discoverable, drivers can also choose to make them directly configurable by applications. When both the sub-device driver and the V4L2 device driver support this, sub-devices will feature a character device node on which ioctls can be called to

- query, read and write sub-devices controls

- subscribe and unsubscribe to events and retrieve them

- negotiate image formats on individual pads

- inspect and modify internal data routing between pads of the same entity

Sub-device character device nodes, conventionally named `/dev/v4l-subdev*`, use major number 81.

Drivers may opt to limit the sub-device character devices to only expose operations that do not modify the device state. In such a case the sub-devices are referred to as `read-only` in the rest of this documentation, and the related restrictions are documented in individual ioctls.

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

## Controls

Most V4L2 controls are implemented by sub-device hardware. Drivers usually merge all controls and expose them through video device nodes. Applications can control all sub-devices through a single interface.

Complex devices sometimes implement the same control in different pieces of hardware. This situation is common in embedded platforms, where both sensors and image processing hardware implement identical functions, such as contrast adjustment, white balance or faulty pixels correction. As the V4L2 controls API doesn't support several identical controls in a single device, all but one of the identical controls are hidden.

Applications can access those hidden controls through the sub-device node with the V4L2 control API described in [control](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>). The ioctls behave identically as when issued on V4L2 device nodes, with the exception that they deal only with controls implemented in the sub-device.

Depending on the driver, those controls might also be exposed through one (or several) V4L2 device nodes.

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

## Events

V4L2 sub-devices can notify applications of events as described in [event](</kernel/userspace/userspace-api/media-v4l/dev-event.md#rst-event>). The API behaves identically as when used on V4L2 device nodes, with the exception that it only deals with events generated by the sub-device. Depending on the driver, those events might also be reported on one (or several) V4L2 device nodes.

<a id="rst-pad-level-formats-1"></a>
<a id="rst-pad-level-formats"></a>

## Pad-level Formats

> [!WARNING]
>
> Pad-level formats are only applicable to very complex devices that need to expose low-level format configuration to user space. Generic V4L2 applications do <em>not</em> need to use the API described in this section.

> [!NOTE]
>
> For the purpose of this section, the term <em>format</em> means the combination of media bus data format, frame width and frame height.

Image formats are typically negotiated on video capture and output devices using the format and [selection](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-selection.md#rst-vidioc-subdev-g-selection>) ioctls. The driver is responsible for configuring every block in the video pipeline according to the requested format at the pipeline input and/or output.

For complex devices, such as often found in embedded systems, identical image sizes at the output of a pipeline can be achieved using different hardware configurations. One such example is shown on [pipeline-scaling](<#rst-pipeline-scaling>), where image scaling can be performed on both the video sensor and the host image processing hardware.

<a id="rst-pipeline-scaling"></a>

```mermaid
flowchart TB
  n0["pad 0<br/>Host<br/>Scaler<br/>pad 1"]
  n1["pad 0<br/>Host<br/>Frontend<br/>pad 1"]
  n2["Sensor<br/>pad 0"]
  n3["pad 0<br/>V4L I/O"]
  n2 -->|"HQ: 2592x1968<br/>HS: 1296x984<br/>pad 0 → pad 0"| n1
  n1 -->|"HQ: 2592x1968<br/>HS: 1296x984<br/>pad 1 → pad 0"| n0
  n0 -->|"HQ: 1280x720<br/>HS: 1280x720<br/>pad 1 → pad 0"| n3
  style n0 fill:lightblue,color:#111
  style n1 fill:lightblue,color:#111
  style n2 fill:aquamarine,color:#111
  style n3 fill:aquamarine,color:#111
  linkStyle 0 stroke:blue
  linkStyle 1 stroke:blue
  linkStyle 2 stroke:blue
```

pipeline.dot

Image Format Negotiation on Pipelines

High quality and high speed pipeline configuration

The sensor scaler is usually of less quality than the host scaler, but scaling on the sensor is required to achieve higher frame rates. Depending on the use case (quality vs. speed), the pipeline must be configured differently. Applications need to configure the formats at every point in the pipeline explicitly.

Drivers that implement the [media API](</kernel/userspace/userspace-api/media-mediactl/media-controller-intro.md#rst-media-controller-intro>) can expose pad-level image format configuration to applications. When they do, applications can use the [VIDIOC\_SUBDEV\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) and [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctls. to negotiate formats on a per-pad basis.

Applications are responsible for configuring coherent parameters on the whole pipeline and making sure that connected pads have compatible formats. The pipeline is checked for formats mismatch at [VIDIOC\_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) time, and an `EPIPE` error code is then returned if the configuration is invalid.

Pad-level image format configuration support can be tested by calling the [vidioc\_subdev\_g\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctl on pad 0. If the driver returns an `EINVAL` error code pad-level format configuration is not supported by the sub-device.

<a id="rst-format-negotiation"></a>

### Format Negotiation

Acceptable formats on pads can (and usually do) depend on a number of external parameters, such as formats on other pads, active links, or even controls. Finding a combination of formats on all pads in a video pipeline, acceptable to both application and driver, can't rely on formats enumeration only. A format negotiation mechanism is required.

Central to the format negotiation mechanism are the get/set format operations. When called with the `which` argument set to [V4L2\_SUBDEV\_FORMAT\_TRY](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>), the [VIDIOC\_SUBDEV\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) and [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctls operate on a set of formats parameters that are not connected to the hardware configuration. Modifying those 'try' formats leaves the device state untouched (this applies to both the software state stored in the driver and the hardware state stored in the device itself).

While not kept as part of the device state, try formats are stored in the sub-device file handles. A [VIDIOC\_SUBDEV\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) call will return the last try format set <em>on the same sub-device file handle</em>. Several applications querying the same sub-device at the same time will thus not interact with each other.

To find out whether a particular format is supported by the device, applications use the [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctl. Drivers verify and, if needed, change the requested `format` based on device requirements and return the possibly modified value. Applications can then choose to try a different format or accept the returned value and continue.

Formats returned by the driver during a negotiation iteration are guaranteed to be supported by the device. In particular, drivers guarantee that a returned format will not be further changed if passed to an [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) call as-is (as long as external parameters, such as formats on other pads or links' configuration are not changed).

Drivers automatically propagate formats inside sub-devices. When a try or active format is set on a pad, corresponding formats on other pads of the same sub-device can be modified by the driver. Drivers are free to modify formats as required by the device. However, they should comply with the following rules when possible:

- Formats should be propagated from sink pads to source pads. Modifying a format on a source pad should not modify the format on any sink pad.

- Sub-devices that scale frames using variable scaling factors should reset the scale factors to default values when sink pads formats are modified. If the 1:1 scaling ratio is supported, this means that source pads formats should be reset to the sink pads formats.

Formats are not propagated across links, as that would involve propagating them from one sub-device file handle to another. Applications must then take care to configure both ends of every link explicitly with compatible formats. Identical formats on the two ends of a link are guaranteed to be compatible. Drivers are free to accept different formats matching device requirements as being compatible.

[sample-pipeline-config](<#rst-sample-pipeline-config>) shows a sample configuration sequence for the pipeline described in [pipeline-scaling](<#rst-pipeline-scaling>) (table columns list entity names and pad numbers).

<!-- Source LaTeX layout: \begingroup
\scriptsize
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{2.0cm}|p{2.1cm}|p{2.1cm}|p{2.1cm}|p{2.1cm}|p{2.1cm}|p{2.1cm}| -->

<a id="rst-sample-pipeline-config"></a>


<table>
<caption>

Sample Pipeline Configuration

</caption>
<thead>
<tr>
<th>





</th>
<th>



Sensor/0

format

</th>
<th>



Frontend/0

format

</th>
<th>



Frontend/1

format

</th>
<th>



Scaler/0

format

</th>
<th>



Scaler/0

compose selection rectangle

</th>
<th>



Scaler/1

format

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Initial state

</td>
<td>



2048x1536

SGRBG8\_1X8

</td>
<td>



(default)

</td>
<td>



(default)

</td>
<td>



(default)

</td>
<td>



(default)

</td>
<td>



(default)

</td>
</tr>
<tr>
<td>



Configure frontend sink format

</td>
<td>



2048x1536

SGRBG8\_1X8

</td>
<td>



<em>2048x1536</em>

<em>SGRBG8\_1X8</em>

</td>
<td>



<em>2046x1534</em>

<em>SGRBG8\_1X8</em>

</td>
<td>



(default)

</td>
<td>



(default)

</td>
<td>



(default)

</td>
</tr>
<tr>
<td>



Configure scaler sink format

</td>
<td>



2048x1536

SGRBG8\_1X8

</td>
<td>



2048x1536

SGRBG8\_1X8

</td>
<td>



2046x1534

SGRBG8\_1X8

</td>
<td>



<em>2046x1534</em>

<em>SGRBG8\_1X8</em>

</td>
<td>



<em>0,0/2046x1534</em>

</td>
<td>



<em>2046x1534</em>

<em>SGRBG8\_1X8</em>

</td>
</tr>
<tr>
<td>



Configure scaler sink compose selection

</td>
<td>



2048x1536

SGRBG8\_1X8

</td>
<td>



2048x1536

SGRBG8\_1X8

</td>
<td>



2046x1534

SGRBG8\_1X8

</td>
<td>



2046x1534

SGRBG8\_1X8

</td>
<td>



<em>0,0/1280x960</em>

</td>
<td>



<em>1280x960</em>

<em>SGRBG8\_1X8</em>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

1. Initial state. The sensor source pad format is set to its native 3MP size and V4L2\_MBUS\_FMT\_SGRBG8\_1X8 media bus code. Formats on the host frontend and scaler sink and source pads have the default values, as well as the compose rectangle on the scaler's sink pad.

2. The application configures the frontend sink pad format's size to 2048x1536 and its media bus code to V4L2\_MBUS\_FMT\_SGRBG\_1X8. The driver propagates the format to the frontend source pad.

3. The application configures the scaler sink pad format's size to 2046x1534 and the media bus code to V4L2\_MBUS\_FMT\_SGRBG\_1X8 to match the frontend source size and media bus code. The media bus code on the sink pad is set to V4L2\_MBUS\_FMT\_SGRBG\_1X8. The driver propagates the size to the compose selection rectangle on the scaler's sink pad, and the format to the scaler source pad.

4. The application configures the size of the compose selection rectangle of the scaler's sink pad 1280x960. The driver propagates the size to the scaler's source pad format.

When satisfied with the try results, applications can set the active formats by setting the `which` argument to `V4L2_SUBDEV_FORMAT_ACTIVE`. Active formats are changed exactly as try formats by drivers. To avoid modifying the hardware state during format negotiation, applications should negotiate try formats first and then modify the active settings using the try formats returned during the last negotiation iteration. This guarantees that the active format will be applied as-is by the driver without being modified.

<a id="rst-selections-cropping-scaling-and-composition"></a>
<a id="rst-v4l2-subdev-selections"></a>

### Selections: cropping, scaling and composition

Many sub-devices support cropping frames on their input or output pads (or possible even on both). Cropping is used to select the area of interest in an image, typically on an image sensor or a video decoder. It can also be used as part of digital zoom implementations to select the area of the image that will be scaled up.

Crop settings are defined by a crop rectangle and represented in a struct `v4l2_rect` by the coordinates of the top left corner and the rectangle size. Both the coordinates and sizes are expressed in pixels.

As for pad formats, drivers store try and active rectangles for the selection targets [v4l2-selections-common](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>).

On sink pads, cropping is applied relative to the current pad format. The pad format represents the image size as received by the sub-device from the previous block in the pipeline, and the crop rectangle represents the sub-image that will be transmitted further inside the sub-device for processing.

The scaling operation changes the size of the image by scaling it to new dimensions. The scaling ratio isn't specified explicitly, but is implied from the original and scaled image sizes. Both sizes are represented by struct `v4l2_rect`.

Scaling support is optional. When supported by a subdev, the crop rectangle on the subdev's sink pad is scaled to the size configured using the [VIDIOC\_SUBDEV\_S\_SELECTION](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-selection.md#rst-vidioc-subdev-g-selection>) IOCTL using `V4L2_SEL_TGT_COMPOSE` selection target on the same pad. If the subdev supports scaling but not composing, the top and left values are not used and must always be set to zero.

On source pads, cropping is similar to sink pads, with the exception that the source size from which the cropping is performed, is the COMPOSE rectangle on the sink pad. In both sink and source pads, the crop rectangle must be entirely contained inside the source image size for the crop operation.

The drivers should always use the closest possible rectangle the user requests on all selection targets, unless specifically told otherwise. `V4L2_SEL_FLAG_GE` and `V4L2_SEL_FLAG_LE` flags may be used to round the image size either up or down. [Selection flags](</kernel/userspace/userspace-api/media-v4l/v4l2-selection-flags.md#rst-v4l2-selection-flags>)

<a id="rst-types-of-selection-targets"></a>

### Types of selection targets

<a id="rst-actual-targets"></a>

#### Actual targets

Actual targets (without a postfix) reflect the actual hardware configuration at any point of time. There is a BOUNDS target corresponding to every actual target.

<a id="rst-bounds-targets"></a>

#### BOUNDS targets

BOUNDS targets is the smallest rectangle that contains all valid actual rectangles. It may not be possible to set the actual rectangle as large as the BOUNDS rectangle, however. This may be because e.g. a sensor's pixel array is not rectangular but cross-shaped or round. The maximum size may also be smaller than the BOUNDS rectangle.

<a id="rst-order-of-configuration-and-format-propagation"></a>
<a id="rst-format-propagation"></a>

### Order of configuration and format propagation

Inside subdevs, the order of image processing steps will always be from the sink pad towards the source pad. This is also reflected in the order in which the configuration must be performed by the user: the changes made will be propagated to any subsequent stages. If this behaviour is not desired, the user must set `V4L2_SEL_FLAG_KEEP_CONFIG` flag. This flag causes no propagation of the changes are allowed in any circumstances. This may also cause the accessed rectangle to be adjusted by the driver, depending on the properties of the underlying hardware.

The coordinates to a step always refer to the actual size of the previous step. The exception to this rule is the sink compose rectangle, which refers to the sink compose bounds rectangle --- if it is supported by the hardware.

1. Sink pad format. The user configures the sink pad format. This format defines the parameters of the image the entity receives through the pad for further processing.

2. Sink pad actual crop selection. The sink pad crop defines the crop performed to the sink pad format.

3. Sink pad actual compose selection. The size of the sink pad compose rectangle defines the scaling ratio compared to the size of the sink pad crop rectangle. The location of the compose rectangle specifies the location of the actual sink compose rectangle in the sink compose bounds rectangle.

4. Source pad actual crop selection. Crop on the source pad defines crop performed to the image in the sink compose bounds rectangle.

5. Source pad format. The source pad format defines the output pixel format of the subdev, as well as the other parameters with the exception of the image width and height. Width and height are defined by the size of the source pad actual crop selection.

Accessing any of the above rectangles not supported by the subdev will return `EINVAL`. Any rectangle referring to a previous unsupported rectangle coordinates will instead refer to the previous supported rectangle. For example, if sink crop is not supported, the compose selection will refer to the sink pad format dimensions instead.

<a id="rst-subdev-image-processing-crop"></a>

![subdev-image-processing-crop.svg](/kernel/userspace/userspace-api/media-v4l/asset-df7d14f7afb6-subdev-image-processing-crop.svg)

Image processing in subdevs: simple crop example

In the above example, the subdev supports cropping on its sink pad. To configure it, the user sets the media bus format on the subdev's sink pad. Now the actual crop rectangle can be set on the sink pad --- the location and size of this rectangle reflect the location and size of a rectangle to be cropped from the sink format. The size of the sink crop rectangle will also be the size of the format of the subdev's source pad.

<a id="rst-subdev-image-processing-scaling-multi-source"></a>

![subdev-image-processing-scaling-multi-source.svg](/kernel/userspace/userspace-api/media-v4l/asset-40a17a6adb87-subdev-image-processing-scaling-multi-source.svg)

Image processing in subdevs: scaling with multiple sources

In this example, the subdev is capable of first cropping, then scaling and finally cropping for two source pads individually from the resulting scaled image. The location of the scaled image in the cropped image is ignored in sink compose target. Both of the locations of the source crop rectangles refer to the sink scaling rectangle, independently cropping an area at location specified by the source crop rectangle from it.

<a id="rst-subdev-image-processing-full"></a>

![subdev-image-processing-full.svg](/kernel/userspace/userspace-api/media-v4l/asset-38416db9b00f-subdev-image-processing-full.svg)

Image processing in subdevs: scaling and composition with multiple sinks and sources

The subdev driver supports two sink pads and two source pads. The images from both of the sink pads are individually cropped, then scaled and further composed on the composition bounds rectangle. From that, two independent streams are cropped and sent out of the subdev from the source pads.

- [Media Bus Formats](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md>)

<a id="rst-streams-multiplexed-media-pads-and-internal-routing"></a>
<a id="rst-subdev-routing"></a>

## Streams, multiplexed media pads and internal routing

Simple V4L2 sub-devices do not support multiple, unrelated video streams, and only a single stream can pass through a media link and a media pad. Thus each pad contains a format and selection configuration for that single stream. A subdev can do stream processing and split a stream into two or compose two streams into one, but the inputs and outputs for the subdev are still a single stream per pad.

Some hardware, e.g. MIPI CSI-2, support multiplexed streams, that is, multiple data streams are transmitted on the same bus, which is represented by a media link connecting a transmitter source pad with a sink pad on the receiver. For example, a camera sensor can produce two distinct streams, a pixel stream and a metadata stream, which are transmitted on the multiplexed data bus, represented by a media link which connects the single sensor's source pad with the receiver sink pad. The stream-aware receiver will de-multiplex the streams received on the its sink pad and allows to route them individually to one of its source pads.

Subdevice drivers that support multiplexed streams are compatible with non-multiplexed subdev drivers. However, if the driver at the sink end of a link does not support streams, then only stream 0 of source end may be captured. There may be additional limitations specific to the sink device.

<a id="rst-understanding-streams"></a>

### Understanding streams

A stream is a stream of content (e.g. pixel data or metadata) flowing through the media pipeline from a source (e.g. a sensor) towards the final sink (e.g. a receiver and demultiplexer in a SoC). Each media link carries all the enabled streams from one end of the link to the other, and sub-devices have routing tables which describe how the incoming streams from sink pads are routed to the source pads.

A stream ID is a media pad-local identifier for a stream. Streams IDs of the same stream must be equal on both ends of a link. In other words, a particular stream ID must exist on both sides of a media link, but another stream ID can be used for the same stream at the other side of the sub-device.

A stream at a specific point in the media pipeline is identified by the sub-device and a (pad, stream) pair. For sub-devices that do not support multiplexed streams the 'stream' field is always 0.

<a id="rst-interaction-between-routes-streams-formats-and-selections"></a>

### Interaction between routes, streams, formats and selections

The addition of streams to the V4L2 sub-device interface moves the sub-device formats and selections from pads to (pad, stream) pairs. Besides the usual pad, also the stream ID needs to be provided for setting formats and selections. The order of configuring formats and selections along a stream is the same as without streams (see [Order of configuration and format propagation](<#rst-format-propagation>)).

Instead of the sub-device wide merging of streams from all sink pads towards all source pads, data flows for each route are separate from each other. Any number of routes from streams on sink pads towards streams on source pads is allowed, to the extent supported by drivers. For every stream on a source pad, however, only a single route is allowed.

Any configurations of a stream within a pad, such as format or selections, are independent of similar configurations on other streams. This is subject to change in the future.

<a id="rst-device-types-and-routing-setup"></a>

### Device types and routing setup

Different kinds of sub-devices have differing behaviour for route activation, depending on the hardware. In all cases, however, only routes that have the `V4L2_SUBDEV_ROUTE_FL_ACTIVE` flag set are active.

Devices generating the streams may allow enabling and disabling some of the routes or have a fixed routing configuration. If the routes can be disabled, not declaring the routes (or declaring them without `V4L2_SUBDEV_ROUTE_FL_ACTIVE` flag set) in `VIDIOC_SUBDEV_S_ROUTING` will disable the routes. `VIDIOC_SUBDEV_S_ROUTING` will still return such routes back to the user in the routes array, with the `V4L2_SUBDEV_ROUTE_FL_ACTIVE` flag unset.

Devices transporting the streams almost always have more configurability with respect to routing. Typically any route between the sub-device's sink and source pads is possible, and multiple routes (usually up to certain limited number) may be active simultaneously. For such devices, no routes are created by the driver and user-created routes are fully replaced when `VIDIOC_SUBDEV_S_ROUTING` is called on the sub-device. Such newly created routes have the device's default configuration for format and selection rectangles.

<a id="rst-configuring-streams"></a>

### Configuring streams

The configuration of the streams is done individually for each sub-device and the validity of the streams between sub-devices is validated when the pipeline is started.

There are three steps in configuring the streams:

1. Set up links. Connect the pads between sub-devices using the [Media Controller API](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>)

2. Streams. Streams are declared and their routing is configured by setting the routing table for the sub-device using [VIDIOC\_SUBDEV\_S\_ROUTING](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-routing.md#rst-vidioc-subdev-g-routing>) ioctl. Note that setting the routing table will reset formats and selections in the sub-device to default values.

3. Configure formats and selections. Formats and selections of each stream are configured separately as documented for plain sub-devices in [Order of configuration and format propagation](<#rst-format-propagation>). The stream ID is set to the same stream ID associated with either sink or source pads of routes configured using the [VIDIOC\_SUBDEV\_S\_ROUTING](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-routing.md#rst-vidioc-subdev-g-routing>) ioctl.

<a id="rst-multiplexed-streams-setup-example"></a>

### Multiplexed streams setup example

A simple example of a multiplexed stream setup might be as follows:

- Two identical sensors (Sensor A and Sensor B). Each sensor has a single source pad (pad 0) which carries a pixel data stream.

- Multiplexer bridge (Bridge). The bridge has two sink pads, connected to the sensors (pads 0, 1), and one source pad (pad 2), which outputs two streams.

- Receiver in the SoC (Receiver). The receiver has a single sink pad (pad 0), connected to the bridge, and two source pads (pads 1-2), going to the DMA engine. The receiver demultiplexes the incoming streams to the source pads.

- DMA Engines in the SoC (DMA Engine), one for each stream. Each DMA engine is connected to a single source pad in the receiver.

The sensors, the bridge and the receiver are modeled as V4L2 sub-devices, exposed to userspace via /dev/v4l-subdevX device nodes. The DMA engines are modeled as V4L2 devices, exposed to userspace via /dev/videoX nodes.

To configure this pipeline, the userspace must take the following steps:

1. Set up media links between entities: connect the sensors to the bridge, bridge to the receiver, and the receiver to the DMA engines. This step does not differ from normal non-multiplexed media controller setup.

2. Configure routing


<table>
<caption>

Bridge routing table

</caption>
<thead>
<tr>
<th>



Sink Pad/Stream

</th>
<th>



Source Pad/Stream

</th>
<th>



Routing Flags

</th>
<th>



Comments

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



0/0

</td>
<td>



2/0

</td>
<td>



V4L2\_SUBDEV\_ROUTE\_FL\_ACTIVE

</td>
<td>



Pixel data stream from Sensor A

</td>
</tr>
<tr>
<td>



1/0

</td>
<td>



2/1

</td>
<td>



V4L2\_SUBDEV\_ROUTE\_FL\_ACTIVE

</td>
<td>



Pixel data stream from Sensor B

</td>
</tr>
</tbody>
</table>


<table>
<caption>

Receiver routing table

</caption>
<thead>
<tr>
<th>



Sink Pad/Stream

</th>
<th>



Source Pad/Stream

</th>
<th>



Routing Flags

</th>
<th>



Comments

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



0/0

</td>
<td>



1/0

</td>
<td>



V4L2\_SUBDEV\_ROUTE\_FL\_ACTIVE

</td>
<td>



Pixel data stream from Sensor A

</td>
</tr>
<tr>
<td>



0/1

</td>
<td>



2/0

</td>
<td>



V4L2\_SUBDEV\_ROUTE\_FL\_ACTIVE

</td>
<td>



Pixel data stream from Sensor B

</td>
</tr>
</tbody>
</table>

3. Configure formats and selections

   After configuring routing, the next step is configuring the formats and selections for the streams. This is similar to performing this step without streams, with just one exception: the `stream` field needs to be assigned to the value of the stream ID.

   A common way to accomplish this is to start from the sensors and propagate the configurations along the stream towards the receiver, using [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctls to configure each stream endpoint in each sub-device.

---

# Touch Devices

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Touch devices are accessed through character device special files named /dev/v4l-touch0 to /dev/v4l-touch255 with major number 81 and dynamically allocated minor numbers 0 to 255.

<a id="rst-touch-devices"></a>
<a id="rst-touch"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Touch devices are accessed through character device special files named `/dev/v4l-touch0` to `/dev/v4l-touch255` with major number 81 and dynamically allocated minor numbers 0 to 255.

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

## Overview

Sensors may be Optical, or Projected Capacitive touch (PCT).

Processing is required to analyse the raw data and produce input events. In some systems, this may be performed on the ASIC and the raw data is purely a side-channel for diagnostics or tuning. In other systems, the ASIC is a simple analogue front end device which delivers touch data at high rate, and any touch processing must be done on the host.

For capacitive touch sensing, the touchscreen is composed of an array of horizontal and vertical conductors (alternatively called rows/columns, X/Y lines, or tx/rx). Mutual Capacitance measured is at the nodes where the conductors cross. Alternatively, Self Capacitance measures the signal from each column and row independently.

A touch input may be determined by comparing the raw capacitance measurement to a no-touch reference (or "baseline") measurement:

Delta = Raw - Reference

The reference measurement takes account of variations in the capacitance across the touch sensor matrix, for example manufacturing irregularities, environmental or edge effects.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

Devices supporting the touch interface set the `V4L2_CAP_VIDEO_CAPTURE` flag and the `V4L2_CAP_TOUCH` flag in the `capabilities` field of `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl.

At least one of the read/write or streaming I/O methods must be supported.

The formats supported by touch devices are documented in [Touch Formats](</kernel/userspace/userspace-api/media-v4l/tch-formats.md#rst-tch-formats>).

<a id="rst-data-format-negotiation"></a>

## Data Format Negotiation

A touch device may support any I/O method.

---

# Interfaces

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Interfaces.

<a id="rst-interfaces"></a>
<a id="rst-devices"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

- [Video Capture Interface](</kernel/userspace/userspace-api/media-v4l/dev-capture.md>)
- [Video Overlay Interface](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Video Output Interface](</kernel/userspace/userspace-api/media-v4l/dev-output.md>)
- [Video Output Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-osd.md>)
- [Video Memory-To-Memory Interface](</kernel/userspace/userspace-api/media-v4l/dev-mem2mem.md>)
- [Raw VBI Data Interface](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md>)
- [dev-sliced-vbi](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-sliced-vbi.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Radio Interface](</kernel/userspace/userspace-api/media-v4l/dev-radio.md>)
- [RDS Interface](</kernel/userspace/userspace-api/media-v4l/dev-rds.md>)
- [Software Defined Radio Interface (SDR)](</kernel/userspace/userspace-api/media-v4l/dev-sdr.md>)
- [Touch Devices](</kernel/userspace/userspace-api/media-v4l/dev-touch.md>)
- [Event Interface](</kernel/userspace/userspace-api/media-v4l/dev-event.md>)
- [dev-subdev](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-subdev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Metadata Interface](</kernel/userspace/userspace-api/media-v4l/dev-meta.md>)

---

# Differences between V4L and V4L2

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Video For Linux API was first introduced in Linux 2.1 to unify and replace various TV and radio device related interfaces, developed independently by driver writers in prior years. Starting with Linux 2.5 the much improved V4L2 API…

<a id="rst-differences-between-v4l-and-v4l2"></a>
<a id="rst-diff-v4l"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Video For Linux API was first introduced in Linux 2.1 to unify and replace various TV and radio device related interfaces, developed independently by driver writers in prior years. Starting with Linux 2.5 the much improved V4L2 API replaces the V4L API. The support for the old V4L calls were removed from Kernel, but the library [libv4l](</kernel/userspace/userspace-api/media-v4l/libv4l.md#rst-libv4l>) supports the conversion of a V4L API system call into a V4L2 one.

<a id="rst-opening-and-closing-devices"></a>

## Opening and Closing Devices

For compatibility reasons the character device file names recommended for V4L2 video capture, overlay, radio and raw vbi capture devices did not change from those used by V4L. They are listed in [devices](</kernel/userspace/userspace-api/media-v4l/devices.md#rst-devices>) and below in [v4l-dev](<#rst-v4l-dev>).

The teletext devices (minor range 192-223) have been removed in V4L2 and no longer exist. There is no hardware available anymore for handling pure teletext. Instead raw or sliced VBI is used.

The V4L `videodev` module automatically assigns minor numbers to drivers in load order, depending on the registered device type. We recommend that V4L2 drivers by default register devices with the same numbers, but the system administrator can assign arbitrary minor numbers using driver module options. The major device number remains 81.

<a id="rst-v4l-dev"></a>


<table>
<caption>

V4L Device Types, Names and Numbers

</caption>
<thead>
<tr>
<th>



Device Type

</th>
<th>



File Name

</th>
<th>



Minor Numbers

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Video capture and overlay

</td>
<td>



`/dev/video` and `/dev/bttv0` <a id="rst-footnote-reference-1"></a>[1](#rst-f1), `/dev/video0` to `/dev/video63`

</td>
<td>



0-63

</td>
</tr>
<tr>
<td>



Radio receiver

</td>
<td>



`/dev/radio` <a id="rst-footnote-reference-2"></a>[2](#rst-f2), `/dev/radio0` to `/dev/radio63`

</td>
<td>



64-127

</td>
</tr>
<tr>
<td>



Raw VBI capture

</td>
<td>



`/dev/vbi`, `/dev/vbi0` to `/dev/vbi31`

</td>
<td>



224-255

</td>
</tr>
</tbody>
</table>

V4L prohibits (or used to prohibit) multiple opens of a device file. V4L2 drivers <em>may</em> support multiple opens, see [open](</kernel/userspace/userspace-api/media-v4l/open.md#rst-open>) for details and consequences.

V4L drivers respond to V4L2 ioctls with an `EINVAL` error code.

<a id="rst-querying-capabilities"></a>

## Querying Capabilities

The V4L `VIDIOCGCAP` ioctl is equivalent to V4L2's [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>).

The `name` field in struct `video_capability` became `card` in struct `v4l2_capability`, `type` was replaced by `capabilities`. Note V4L2 does not distinguish between device types like this, better think of basic video input, video output and radio devices supporting a set of related functions like video capturing, video overlay and VBI capturing. See [open](</kernel/userspace/userspace-api/media-v4l/open.md#rst-open>) for an introduction.

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{5.3cm}|p{6.7cm}|p{5.3cm}| -->


<table>
<thead>
<tr>
<th>



`struct video_capability` `type`

</th>
<th>



struct `v4l2_capability` `capabilities` flags

</th>
<th>



Purpose

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`VID_TYPE_CAPTURE`

</td>
<td>



`V4L2_CAP_VIDEO_CAPTURE`

</td>
<td>



The [video capture](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>) interface is supported.

</td>
</tr>
<tr>
<td>



`VID_TYPE_TUNER`

</td>
<td>



`V4L2_CAP_TUNER`

</td>
<td>



The device has a [tuner or modulator](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>).

</td>
</tr>
<tr>
<td>



`VID_TYPE_TELETEXT`

</td>
<td>



`V4L2_CAP_VBI_CAPTURE`

</td>
<td>



The [raw VBI capture](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>) interface is supported.

</td>
</tr>
<tr>
<td>



`VID_TYPE_OVERLAY`

</td>
<td>



`V4L2_CAP_VIDEO_OVERLAY`

</td>
<td>



The [video overlay](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) interface is supported.

</td>
</tr>
<tr>
<td>



`VID_TYPE_CHROMAKEY`

</td>
<td>



`V4L2_FBUF_CAP_CHROMAKEY` in field `capability` of struct `v4l2_framebuffer`

</td>
<td>



Whether chromakey overlay is supported. For more information on overlay see [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>).

</td>
</tr>
<tr>
<td>



`VID_TYPE_CLIPPING`

</td>
<td>



`V4L2_FBUF_CAP_LIST_CLIPPING` and `V4L2_FBUF_CAP_BITMAP_CLIPPING` in field `capability` of struct `v4l2_framebuffer`

</td>
<td>



Whether clipping the overlaid image is supported, see [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>).

</td>
</tr>
<tr>
<td>



`VID_TYPE_FRAMERAM`

</td>
<td>



`V4L2_FBUF_CAP_EXTERNOVERLAY` <em>not set</em> in field `capability` of struct `v4l2_framebuffer`

</td>
<td>



Whether overlay overwrites frame buffer memory, see [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>).

</td>
</tr>
<tr>
<td>



`VID_TYPE_SCALES`

</td>
<td>



`-`

</td>
<td>



This flag indicates if the hardware can scale images. The V4L2 API implies the scale factor by setting the cropping dimensions and image size with the [VIDIOC\_S\_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) and [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, respectively. The driver returns the closest sizes possible. For more information on cropping and scaling see [crop](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>).

</td>
</tr>
<tr>
<td>



`VID_TYPE_MONOCHROME`

</td>
<td>



`-`

</td>
<td>



Applications can enumerate the supported image formats with the [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) ioctl to determine if the device supports grey scale capturing only. For more information on image formats see [pixfmt](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>).

</td>
</tr>
<tr>
<td>



`VID_TYPE_SUBCAPTURE`

</td>
<td>



`-`

</td>
<td>



Applications can call the [VIDIOC\_G\_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) ioctl to determine if the device supports capturing a subsection of the full picture ("cropping" in V4L2). If not, the ioctl returns the `EINVAL` error code. For more information on cropping and scaling see [crop](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>).

</td>
</tr>
<tr>
<td>



`VID_TYPE_MPEG_DECODER`

</td>
<td>



`-`

</td>
<td>



Applications can enumerate the supported image formats with the [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) ioctl to determine if the device supports MPEG streams.

</td>
</tr>
<tr>
<td>



`VID_TYPE_MPEG_ENCODER`

</td>
<td>



`-`

</td>
<td>



See above.

</td>
</tr>
<tr>
<td>



`VID_TYPE_MJPEG_DECODER`

</td>
<td>



`-`

</td>
<td>



See above.

</td>
</tr>
<tr>
<td>



`VID_TYPE_MJPEG_ENCODER`

</td>
<td>



`-`

</td>
<td>



See above.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

The `audios` field was replaced by `capabilities` flag `V4L2_CAP_AUDIO`, indicating <em>if</em> the device has any audio inputs or outputs. To determine their number applications can enumerate audio inputs with the [VIDIOC\_G\_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) ioctl. The audio ioctls are described in [Audio](<#rst-audio>).

The `maxwidth`, `maxheight`, `minwidth` and `minheight` fields were removed. Calling the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) or [VIDIOC\_TRY\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with the desired dimensions returns the closest size possible, taking into account the current video standard, cropping and scaling limitations.

<a id="rst-video-sources"></a>

## Video Sources

V4L provides the `VIDIOCGCHAN` and `VIDIOCSCHAN` ioctl using struct `video_channel` to enumerate the video inputs of a V4L device. The equivalent V4L2 ioctls are [vidioc\_enuminput](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>), [VIDIOC\_G\_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input>) and [VIDIOC\_S\_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input>) using struct `v4l2_input` as discussed in [video](</kernel/userspace/userspace-api/media-v4l/video.md#rst-video>).

The `channel` field counting inputs was renamed to `index`, the video input types were renamed as follows:


<table>
<thead>
<tr>
<th>



struct `video_channel` `type`

</th>
<th>



struct `v4l2_input` `type`

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`VIDEO_TYPE_TV`

</td>
<td>



`V4L2_INPUT_TYPE_TUNER`

</td>
</tr>
<tr>
<td>



`VIDEO_TYPE_CAMERA`

</td>
<td>



`V4L2_INPUT_TYPE_CAMERA`

</td>
</tr>
</tbody>
</table>

Unlike the `tuners` field expressing the number of tuners of this input, V4L2 assumes each video input is connected to at most one tuner. However a tuner can have more than one input, i. e. RF connectors, and a device can have multiple tuners. The index number of the tuner associated with the input, if any, is stored in field `tuner` of struct `v4l2_input`. Enumeration of tuners is discussed in [tuner](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>).

The redundant `VIDEO_VC_TUNER` flag was dropped. Video inputs associated with a tuner are of type `V4L2_INPUT_TYPE_TUNER`. The `VIDEO_VC_AUDIO` flag was replaced by the `audioset` field. V4L2 considers devices with up to 32 audio inputs. Each set bit in the `audioset` field represents one audio input this video input combines with. For information about audio inputs and how to switch between them see [Audio](<#rst-audio>).

The `norm` field describing the supported video standards was replaced by `std`. The V4L specification mentions a flag `VIDEO_VC_NORM` indicating whether the standard can be changed. This flag was a later addition together with the `norm` field and has been removed in the meantime. V4L2 has a similar, albeit more comprehensive approach to video standards, see [standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>) for more information.

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

## Tuning

The V4L `VIDIOCGTUNER` and `VIDIOCSTUNER` ioctl and struct `video_tuner` can be used to enumerate the tuners of a V4L TV or radio device. The equivalent V4L2 ioctls are [VIDIOC\_G\_TUNER](</kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-vidioc-g-tuner>) and [VIDIOC\_S\_TUNER](</kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-vidioc-g-tuner>) using struct `v4l2_tuner`. Tuners are covered in [tuner](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>).

The `tuner` field counting tuners was renamed to `index`. The fields `name`, `rangelow` and `rangehigh` remained unchanged.

The `VIDEO_TUNER_PAL`, `VIDEO_TUNER_NTSC` and `VIDEO_TUNER_SECAM` flags indicating the supported video standards were dropped. This information is now contained in the associated struct `v4l2_input`. No replacement exists for the `VIDEO_TUNER_NORM` flag indicating whether the video standard can be switched. The `mode` field to select a different video standard was replaced by a whole new set of ioctls and structures described in [standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>). Due to its ubiquity it should be mentioned the BTTV driver supports several standards in addition to the regular `VIDEO_MODE_PAL` (0), `VIDEO_MODE_NTSC`, `VIDEO_MODE_SECAM` and `VIDEO_MODE_AUTO` (3). Namely N/PAL Argentina, M/PAL, N/PAL, and NTSC Japan with numbers 3-6 (sic).

The `VIDEO_TUNER_STEREO_ON` flag indicating stereo reception became `V4L2_TUNER_SUB_STEREO` in field `rxsubchans`. This field also permits the detection of monaural and bilingual audio, see the definition of struct `v4l2_tuner` for details. Presently no replacement exists for the `VIDEO_TUNER_RDS_ON` and `VIDEO_TUNER_MBS_ON` flags.

The `VIDEO_TUNER_LOW` flag was renamed to `V4L2_TUNER_CAP_LOW` in the struct `v4l2_tuner` `capability` field.

The `VIDIOCGFREQ` and `VIDIOCSFREQ` ioctl to change the tuner frequency where renamed to [VIDIOC\_G\_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) and [VIDIOC\_S\_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>). They take a pointer to a struct `v4l2_frequency` instead of an unsigned long integer.

<a id="rst-image-properties"></a>
<a id="rst-v4l-image-properties"></a>

## Image Properties

V4L2 has no equivalent of the `VIDIOCGPICT` and `VIDIOCSPICT` ioctl and struct `video_picture`. The following fields where replaced by V4L2 controls accessible with the [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>), [VIDIOC\_G\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) and [VIDIOC\_S\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) ioctls:


<table>
<thead>
<tr>
<th>



struct `video_picture`

</th>
<th>



V4L2 Control ID

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`brightness`

</td>
<td>



`V4L2_CID_BRIGHTNESS`

</td>
</tr>
<tr>
<td>



`hue`

</td>
<td>



`V4L2_CID_HUE`

</td>
</tr>
<tr>
<td>



`colour`

</td>
<td>



`V4L2_CID_SATURATION`

</td>
</tr>
<tr>
<td>



`contrast`

</td>
<td>



`V4L2_CID_CONTRAST`

</td>
</tr>
<tr>
<td>



`whiteness`

</td>
<td>



`V4L2_CID_WHITENESS`

</td>
</tr>
</tbody>
</table>

The V4L picture controls are assumed to range from 0 to 65535 with no particular reset value. The V4L2 API permits arbitrary limits and defaults which can be queried with the [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>) ioctl. For general information about controls see [control](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>).

The `depth` (average number of bits per pixel) of a video image is implied by the selected image format. V4L2 does not explicitly provide such information assuming applications recognizing the format are aware of the image depth and others need not know. The `palette` field moved into the struct `v4l2_pix_format`:


<table>
<thead>
<tr>
<th>



struct `video_picture` `palette`

</th>
<th>



struct `v4l2_pix_format` `pixfmt`

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`VIDEO_PALETTE_GREY`

</td>
<td>



[V4L2\_PIX\_FMT\_GREY](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-grey>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_HI240`

</td>
<td>



[V4L2\_PIX\_FMT\_HI240](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-pixfmt-reserved>) <a id="rst-footnote-reference-3"></a>[3](#rst-f3)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_RGB565`

</td>
<td>



[V4L2\_PIX\_FMT\_RGB565](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_RGB555`

</td>
<td>



[V4L2\_PIX\_FMT\_RGB555](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_RGB24`

</td>
<td>



[V4L2\_PIX\_FMT\_BGR24](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_RGB32`

</td>
<td>



[V4L2\_PIX\_FMT\_BGR32](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>) <a id="rst-footnote-reference-4"></a>[4](#rst-f4)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_YUV422`

</td>
<td>



[V4L2\_PIX\_FMT\_YUYV](</kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuyv>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_YUYV` <a id="rst-footnote-reference-5"></a>[5](#rst-f5)

</td>
<td>



[V4L2\_PIX\_FMT\_YUYV](</kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuyv>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_UYVY`

</td>
<td>



[V4L2\_PIX\_FMT\_UYVY](</kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-uyvy>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_YUV420`

</td>
<td>



None

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_YUV411`

</td>
<td>



[V4L2\_PIX\_FMT\_Y41P](</kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-y41p>) <a id="rst-footnote-reference-6"></a>[6](#rst-f6)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_RAW`

</td>
<td>



None <a id="rst-footnote-reference-7"></a>[7](#rst-f7)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_YUV422P`

</td>
<td>



[V4L2\_PIX\_FMT\_YUV422P](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv422p>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_YUV411P`

</td>
<td>



[V4L2\_PIX\_FMT\_YUV411P](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv411p>) <a id="rst-footnote-reference-8"></a>[8](#rst-f8)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_YUV420P`

</td>
<td>



[V4L2\_PIX\_FMT\_YVU420](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu420>)

</td>
</tr>
<tr>
<td>



`VIDEO_PALETTE_YUV410P`

</td>
<td>



[V4L2\_PIX\_FMT\_YVU410](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu410>)

</td>
</tr>
</tbody>
</table>

V4L2 image formats are defined in [pixfmt](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>). The image format can be selected with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl.

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

## Audio

The `VIDIOCGAUDIO` and `VIDIOCSAUDIO` ioctl and struct `video_audio` are used to enumerate the audio inputs of a V4L device. The equivalent V4L2 ioctls are [VIDIOC\_G\_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) and [VIDIOC\_S\_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) using struct `v4l2_audio` as discussed in [Audio](<#rst-audio>).

The `audio` "channel number" field counting audio inputs was renamed to `index`.

On `VIDIOCSAUDIO` the `mode` field selects <em>one</em> of the `VIDEO_SOUND_MONO`, `VIDEO_SOUND_STEREO`, `VIDEO_SOUND_LANG1` or `VIDEO_SOUND_LANG2` audio demodulation modes. When the current audio standard is BTSC `VIDEO_SOUND_LANG2` refers to SAP and `VIDEO_SOUND_LANG1` is meaningless. Also undocumented in the V4L specification, there is no way to query the selected mode. On `VIDIOCGAUDIO` the driver returns the <em>actually received</em> audio programmes in this field. In the V4L2 API this information is stored in the struct `v4l2_tuner` `rxsubchans` and `audmode` fields, respectively. See [tuner](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>) for more information on tuners. Related to audio modes struct `v4l2_audio` also reports if this is a mono or stereo input, regardless if the source is a tuner.

The following fields where replaced by V4L2 controls accessible with the [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>), [VIDIOC\_G\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) and [VIDIOC\_S\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) ioctls:


<table>
<thead>
<tr>
<th>



struct `video_audio`

</th>
<th>



V4L2 Control ID

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`volume`

</td>
<td>



`V4L2_CID_AUDIO_VOLUME`

</td>
</tr>
<tr>
<td>



`bass`

</td>
<td>



`V4L2_CID_AUDIO_BASS`

</td>
</tr>
<tr>
<td>



`treble`

</td>
<td>



`V4L2_CID_AUDIO_TREBLE`

</td>
</tr>
<tr>
<td>



`balance`

</td>
<td>



`V4L2_CID_AUDIO_BALANCE`

</td>
</tr>
</tbody>
</table>

To determine which of these controls are supported by a driver V4L provides the `flags` `VIDEO_AUDIO_VOLUME`, `VIDEO_AUDIO_BASS`, `VIDEO_AUDIO_TREBLE` and `VIDEO_AUDIO_BALANCE`. In the V4L2 API the [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>) ioctl reports if the respective control is supported. Accordingly the `VIDEO_AUDIO_MUTABLE` and `VIDEO_AUDIO_MUTE` flags where replaced by the boolean `V4L2_CID_AUDIO_MUTE` control.

All V4L2 controls have a `step` attribute replacing the struct `video_audio` `step` field. The V4L audio controls are assumed to range from 0 to 65535 with no particular reset value. The V4L2 API permits arbitrary limits and defaults which can be queried with the [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>) ioctl. For general information about controls see [control](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>).

<a id="rst-frame-buffer-overlay"></a>

## Frame Buffer Overlay

The V4L2 ioctls equivalent to `VIDIOCGFBUF` and `VIDIOCSFBUF` are [VIDIOC\_G\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) and [VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>). The `base` field of struct `video_buffer` remained unchanged, except V4L2 defines a flag to indicate non-destructive overlays instead of a `NULL` pointer. All other fields moved into the struct `v4l2_pix_format` `fmt` substructure of struct `v4l2_framebuffer`. The `depth` field was replaced by `pixelformat`. See [RGB Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>) for a list of RGB formats and their respective color depths.

Instead of the special ioctls `VIDIOCGWIN` and `VIDIOCSWIN` V4L2 uses the general-purpose data format negotiation ioctls [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>). They take a pointer to a struct `v4l2_format` as argument. Here the `win` member of the `fmt` union is used, a struct `v4l2_window`.

The `x`, `y`, `width` and `height` fields of struct `video_window` moved into struct `v4l2_rect` substructure `w` of struct `v4l2_window`. The `chromakey`, `clips`, and `clipcount` fields remained unchanged. Struct `video_clip` was renamed to struct `v4l2_clip`, also containing a struct `v4l2_rect`, but the semantics are still the same.

The `VIDEO_WINDOW_INTERLACE` flag was dropped. Instead applications must set the `field` field to `V4L2_FIELD_ANY` or `V4L2_FIELD_INTERLACED`. The `VIDEO_WINDOW_CHROMAKEY` flag moved into struct `v4l2_framebuffer`, under the new name `V4L2_FBUF_FLAG_CHROMAKEY`.

In V4L, storing a bitmap pointer in `clips` and setting `clipcount` to `VIDEO_CLIP_BITMAP` (-1) requests bitmap clipping, using a fixed size bitmap of 1024 × 625 bits. Struct `v4l2_window` has a separate `bitmap` pointer field for this purpose and the bitmap size is determined by `w.width` and `w.height`.

The `VIDIOCCAPTURE` ioctl to enable or disable overlay was renamed to [vidioc\_overlay](</kernel/userspace/userspace-api/media-v4l/vidioc-overlay.md#rst-vidioc-overlay>).

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

## Cropping

To capture only a subsection of the full picture V4L defines the `VIDIOCGCAPTURE` and `VIDIOCSCAPTURE` ioctls using struct `video_capture`. The equivalent V4L2 ioctls are [VIDIOC\_G\_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) and [VIDIOC\_S\_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) using struct `v4l2_crop`, and the related [vidioc\_cropcap](</kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#rst-vidioc-cropcap>) ioctl. This is a rather complex matter, see [crop](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>) for details.

The `x`, `y`, `width` and `height` fields moved into struct `v4l2_rect` substructure `c` of struct `v4l2_crop`. The `decimation` field was dropped. In the V4L2 API the scaling factor is implied by the size of the cropping rectangle and the size of the captured or overlaid image.

The `VIDEO_CAPTURE_ODD` and `VIDEO_CAPTURE_EVEN` flags to capture only the odd or even field, respectively, were replaced by `V4L2_FIELD_TOP` and `V4L2_FIELD_BOTTOM` in the field named `field` of struct `v4l2_pix_format` and struct `v4l2_window`. These structures are used to select a capture or overlay format with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl.

<a id="rst-reading-images-memory-mapping"></a>

## Reading Images, Memory Mapping

<a id="rst-capturing-using-the-read-method"></a>

### Capturing using the read method

There is no essential difference between reading images from a V4L or V4L2 device using the `read()` function, however V4L2 drivers are not required to support this I/O method. Applications can determine if the function is available with the [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. All V4L2 devices exchanging data with applications must support the `select()` and `poll()` functions.

To select an image format and size, V4L provides the `VIDIOCSPICT` and `VIDIOCSWIN` ioctls. V4L2 uses the general-purpose data format negotiation ioctls [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>). They take a pointer to a struct `v4l2_format` as argument, here the struct `v4l2_pix_format` named `pix` of its `fmt` union is used.

For more information about the V4L2 read interface see [rw](</kernel/userspace/userspace-api/media-v4l/rw.md#rst-rw>).

<a id="rst-capturing-using-memory-mapping"></a>

### Capturing using memory mapping

Applications can read from V4L devices by mapping buffers in device memory, or more often just buffers allocated in DMA-able system memory, into their address space. This avoids the data copying overhead of the read method. V4L2 supports memory mapping as well, with a few differences.


<table>
<thead>
<tr>
<th>



V4L

</th>
<th>



V4L2

</th>
</tr>
</thead>
<tbody>
<tr>
<td>





</td>
<td>



The image format must be selected before buffers are allocated, with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. When no format is selected the driver may use the last, possibly by another application requested format.

</td>
</tr>
<tr>
<td>



Applications cannot change the number of buffers. The it is built into the driver, unless it has a module option to change the number when the driver module is loaded.

</td>
<td>



The [ioctl VIDIOC\_REQBUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-vidioc-reqbufs>) ioctl allocates the desired number of buffers, this is a required step in the initialization sequence.

</td>
</tr>
<tr>
<td>



Drivers map all buffers as one contiguous range of memory. The `VIDIOCGMBUF` ioctl is available to query the number of buffers, the offset of each buffer from the start of the virtual file, and the overall amount of memory used, which can be used as arguments for the `mmap()` function.

</td>
<td>



Buffers are individually mapped. The offset and size of each buffer can be determined with the [vidioc\_querybuf](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>) ioctl.

</td>
</tr>
<tr>
<td>



The `VIDIOCMCAPTURE` ioctl prepares a buffer for capturing. It also determines the image format for this buffer. The ioctl returns immediately, eventually with an `EAGAIN` error code if no video signal had been detected. When the driver supports more than one buffer applications can call the ioctl multiple times and thus have multiple outstanding capture requests.

The `VIDIOCSYNC` ioctl suspends execution until a particular buffer has been filled.

</td>
<td>



Drivers maintain an incoming and outgoing queue. [vidioc\_qbuf](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) enqueues any empty buffer into the incoming queue. Filled buffers are dequeued from the outgoing queue with the [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. To wait until filled buffers become available this function, `select()` or `poll()` can be used. The [vidioc\_streamon](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctl must be called once after enqueuing one or more buffers to start capturing. Its counterpart [VIDIOC\_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) stops capturing and dequeues all buffers from both queues. Applications can query the signal status, if known, with the [vidioc\_enuminput](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) ioctl.

</td>
</tr>
</tbody>
</table>

For a more in-depth discussion of memory mapping and examples, see [mmap](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>).

<a id="rst-reading-raw-vbi-data"></a>

## Reading Raw VBI Data

Originally the V4L API did not specify a raw VBI capture interface, only the device file `/dev/vbi` was reserved for this purpose. The only driver supporting this interface was the BTTV driver, de-facto defining the V4L VBI interface. Reading from the device yields a raw VBI image with the following parameters:


<table>
<thead>
<tr>
<th>



struct `v4l2_vbi_format`

</th>
<th>



V4L, BTTV driver

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



sampling\_rate

</td>
<td>



28636363 Hz NTSC (or any other 525-line standard); 35468950 Hz PAL and SECAM (625-line standards)

</td>
</tr>
<tr>
<td>



offset

</td>
<td>



?

</td>
</tr>
<tr>
<td>



samples\_per\_line

</td>
<td>



2048

</td>
</tr>
<tr>
<td>



sample\_format

</td>
<td>



V4L2\_PIX\_FMT\_GREY. The last four bytes (a machine endianness integer) contain a frame counter.

</td>
</tr>
<tr>
<td>



start\[\]

</td>
<td>



10, 273 NTSC; 22, 335 PAL and SECAM

</td>
</tr>
<tr>
<td>



count\[\]

</td>
<td>



16, 16 <a id="rst-footnote-reference-9"></a>[9](#rst-f9)

</td>
</tr>
<tr>
<td>



flags

</td>
<td>



0

</td>
</tr>
</tbody>
</table>

Undocumented in the V4L specification, in Linux 2.3 the `VIDIOCGVBIFMT` and `VIDIOCSVBIFMT` ioctls using struct `vbi_format` were added to determine the VBI image parameters. These ioctls are only partially compatible with the V4L2 VBI interface specified in [raw-vbi](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>).

An `offset` field does not exist, `sample_format` is supposed to be `VIDEO_PALETTE_RAW`, equivalent to `V4L2_PIX_FMT_GREY`. The remaining fields are probably equivalent to struct `v4l2_vbi_format`.

Apparently only the Zoran (ZR 36120) driver implements these ioctls. The semantics differ from those specified for V4L2 in two ways. The parameters are reset on `open()` and `VIDIOCSVBIFMT` always returns an `EINVAL` error code if the parameters are invalid.

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

## Miscellaneous

V4L2 has no equivalent of the `VIDIOCGUNIT` ioctl. Applications can find the VBI device associated with a video capture device (or vice versa) by reopening the device and requesting VBI data. For details see [open](</kernel/userspace/userspace-api/media-v4l/open.md#rst-open>).

No replacement exists for `VIDIOCKEY`, and the V4L functions for microcode programming. A new interface for MPEG compression and playback devices is documented in [extended-controls](</kernel/userspace/userspace-api/media-v4l/extended-controls.md#rst-extended-controls>).

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



**[1]** According to [Documentation/admin-guide/devices.rst](/kernel/administration/admin-guide/overview/devices.md) these should be symbolic links to `/dev/video0`. Note the original bttv interface is not compatible with V4L or V4L2.

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



**[2]** According to `Documentation/admin-guide/devices.rst` a symbolic link to `/dev/radio0`.

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



**[3]** This is a custom format used by the BTTV driver, not one of the V4L2 standard formats.

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



**[4]** Presumably all V4L RGB formats are little-endian, although some drivers might interpret them according to machine endianness. V4L2 defines little-endian, big-endian and red/blue swapped variants. For details see [RGB Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>).

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



**[5]** `VIDEO_PALETTE_YUV422` and `VIDEO_PALETTE_YUYV` are the same formats. Some V4L drivers respond to one, some to the other.

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



**[6]** Not to be confused with `V4L2_PIX_FMT_YUV411P`, which is a planar format.

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



**[7]** V4L explains this as: "RAW capture (BT848)"

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



**[8]** Not to be confused with `V4L2_PIX_FMT_Y41P`, which is a packed format.

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



**[9]** Old driver versions used different values, eventually the custom `BTTV_VBISIZE` ioctl was added to query the correct values.

---

# Streaming I/O (DMA buffer importing)

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The DMABUF framework provides a generic method for sharing buffers between multiple devices. Device drivers that support DMABUF can export a DMA buffer to userspace as a file descriptor (known as the exporter role), import a DMA buffer…

<a id="rst-streaming-i-o-dma-buffer-importing"></a>
<a id="rst-dmabuf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The DMABUF framework provides a generic method for sharing buffers between multiple devices. Device drivers that support DMABUF can export a DMA buffer to userspace as a file descriptor (known as the exporter role), import a DMA buffer from userspace using a file descriptor previously exported for a different or the same device (known as the importer role), or both. This section describes the DMABUF importer role API in V4L2.

Refer to [DMABUF exporting](</kernel/userspace/userspace-api/media-v4l/vidioc-expbuf.md#rst-vidioc-expbuf>) for details about exporting V4L2 buffers as DMABUF file descriptors.

Input and output devices support the streaming I/O method when the `V4L2_CAP_STREAMING` flag in the `capabilities` field of struct `v4l2_capability` returned by the [VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl is set. Whether importing DMA buffers through DMABUF file descriptors is supported is determined by calling the [VIDIOC_REQBUFS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl with the memory type set to `V4L2_MEMORY_DMABUF`.

This I/O method is dedicated to sharing DMA buffers between different devices, which may be V4L devices or other video-related devices (e.g. DRM). Buffers (planes) are allocated by a driver on behalf of an application. Next, these buffers are exported to the application as file descriptors using an API which is specific for an allocator driver. Only such file descriptor are exchanged. The descriptors and meta-information are passed in struct `v4l2_buffer` (or in struct `v4l2_plane` in the multi-planar API case). The driver must be switched into DMABUF I/O mode by calling the [VIDIOC_REQBUFS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) with the desired buffer type.

<a id="rst-example-initiating-streaming-i-o-with-dmabuf-file-descriptors"></a>

## Example: Initiating streaming I/O with DMABUF file descriptors



```c
struct v4l2_requestbuffers reqbuf;

memset(&reqbuf, 0, sizeof (reqbuf));
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
reqbuf.memory = V4L2_MEMORY_DMABUF;
reqbuf.count = 1;

if (ioctl(fd, VIDIOC_REQBUFS, &reqbuf) == -1) {
    if (errno == EINVAL)
        printf("Video capturing or DMABUF streaming is not supported\\n");
    else
        perror("VIDIOC_REQBUFS");

    exit(EXIT_FAILURE);
}
```

The buffer (plane) file descriptor is passed on the fly with the [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. In case of multiplanar buffers, every plane can be associated with a different DMABUF descriptor. Although buffers are commonly cycled, applications can pass a different DMABUF descriptor at each [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) call.

<a id="rst-example-queueing-dmabuf-using-single-plane-api"></a>

## Example: Queueing DMABUF using single plane API



```c
int buffer_queue(int v4lfd, int index, int dmafd)
{
    struct v4l2_buffer buf;

    memset(&buf, 0, sizeof buf);
    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    buf.memory = V4L2_MEMORY_DMABUF;
    buf.index = index;
    buf.m.fd = dmafd;

    if (ioctl(v4lfd, VIDIOC_QBUF, &buf) == -1) {
        perror("VIDIOC_QBUF");
        return -1;
    }

    return 0;
}
```

<a id="rst-example-3-6-queueing-dmabuf-using-multi-plane-api"></a>

## Example 3.6. Queueing DMABUF using multi plane API



```c
int buffer_queue_mp(int v4lfd, int index, int dmafd[], int n_planes)
{
    struct v4l2_buffer buf;
    struct v4l2_plane planes[VIDEO_MAX_PLANES];
    int i;

    memset(&buf, 0, sizeof buf);
    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
    buf.memory = V4L2_MEMORY_DMABUF;
    buf.index = index;
    buf.m.planes = planes;
    buf.length = n_planes;

    memset(&planes, 0, sizeof planes);

    for (i = 0; i < n_planes; ++i)
        buf.m.planes[i].m.fd = dmafd[i];

    if (ioctl(v4lfd, VIDIOC_QBUF, &buf) == -1) {
        perror("VIDIOC_QBUF");
        return -1;
    }

    return 0;
}
```

Captured or displayed buffers are dequeued with the [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. The driver can unlock the buffer at any time between the completion of the DMA and this ioctl. The memory is also unlocked when [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) is called, [VIDIOC_REQBUFS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), or when the device is closed.

For capturing applications it is customary to enqueue a number of empty buffers, to start capturing and enter the read loop. Here the application waits until a filled buffer can be dequeued, and re-enqueues the buffer when the data is no longer needed. Output applications fill and enqueue buffers, when enough buffers are stacked up output is started. In the write loop, when the application runs out of free buffers it must wait until an empty buffer can be dequeued and reused. Two methods exist to suspend execution of the application until one or more buffers can be dequeued. By default [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) blocks when no buffer is in the outgoing queue. When the `O_NONBLOCK` flag was given to the `open()` function, [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) returns immediately with an `EAGAIN` error code when no buffer is available. The `select()` and `poll()` functions are always available.

To start and stop capturing or displaying applications call the [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) and [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctls.

> [!NOTE]
>
> [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) removes all buffers from both queues and unlocks all buffers as a side effect. Since there is no notion of doing anything "now" on a multitasking system, if an application needs to synchronize with another event it should examine the struct `v4l2_buffer` `timestamp` of captured or outputted buffers.

Drivers implementing DMABUF importing I/O must support the [VIDIOC_REQBUFS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) and [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctls, and the `select()` and `poll()` functions.

---

# Digital Video (DV) Timings

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The video standards discussed so far have been dealing with Analog TV and the corresponding video timings. Today there are many more different hardware interfaces such as High Definition TV interfaces (HDMI), VGA, DVI connectors etc., that…

<a id="rst-digital-video-dv-timings"></a>
<a id="rst-dv-timings"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The video standards discussed so far have been dealing with Analog TV and the corresponding video timings. Today there are many more different hardware interfaces such as High Definition TV interfaces (HDMI), VGA, DVI connectors etc., that carry video signals and there is a need to extend the API to select the video timings for these interfaces. Since it is not possible to extend the [v4l2_std_id](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) due to the limited bits available, a new set of ioctls was added to set/get video timings at the input and output.

These ioctls deal with the detailed digital video timings that define each video format. This includes parameters such as the active video width and height, signal polarities, frontporches, backporches, sync widths etc. The `linux/v4l2-dv-timings.h` header can be used to get the timings of the formats in the [CEA-861-E](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-cea861>) and [VESA DMT](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vesadmt>) standards.

To enumerate and query the attributes of the DV timings supported by a device applications use the [ioctl VIDIOC_ENUM_DV_TIMINGS, VIDIOC_SUBDEV_ENUM_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-dv-timings.md#rst-vidioc-enum-dv-timings>) and [ioctl VIDIOC_DV_TIMINGS_CAP, VIDIOC_SUBDEV_DV_TIMINGS_CAP](</kernel/userspace/userspace-api/media-v4l/vidioc-dv-timings-cap.md#rst-vidioc-dv-timings-cap>) ioctls. To set DV timings for the device applications use the [VIDIOC_S_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-vidioc-g-dv-timings>) ioctl and to get current DV timings they use the [VIDIOC_G_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-vidioc-g-dv-timings>) ioctl. To detect the DV timings as seen by the video receiver applications use the [ioctl VIDIOC_QUERY_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-query-dv-timings.md#rst-vidioc-query-dv-timings>) ioctl.

When the hardware detects a video source change (e.g. the video signal appears or disappears, or the video resolution changes), then it will issue a `V4L2_EVENT_SOURCE_CHANGE` event. Use the [ioctl VIDIOC_SUBSCRIBE_EVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md#rst-vidioc-subscribe-event>) and the [ioctl VIDIOC_DQEVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-vidioc-dqevent>) to check if this event was reported.

If the video signal changed, then the application has to stop streaming, free all buffers, and call the [ioctl VIDIOC_QUERY_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-query-dv-timings.md#rst-vidioc-query-dv-timings>) to obtain the new video timings, and if they are valid, it can set those by calling the [ioctl VIDIOC_S_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-vidioc-g-dv-timings>). This will also update the format, so use the [ioctl VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) to obtain the new format. Now the application can allocate new buffers and start streaming again.

The [ioctl VIDIOC_QUERY_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-query-dv-timings.md#rst-vidioc-query-dv-timings>) will just report what the hardware detects, it will never change the configuration. If the currently set timings and the actually detected timings differ, then typically this will mean that you will not be able to capture any video. The correct approach is to rely on the `V4L2_EVENT_SOURCE_CHANGE` event so you know when something changed.

Applications can make use of the [input-capabilities](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-capabilities>) and [output-capabilities](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-output-capabilities>) flags to determine whether the digital video ioctls can be used with the given input or output.

---

# Camera Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Camera class includes controls for mechanical (or equivalent digital) features of a device such as controllable lenses or sensors.

<a id="rst-camera-control-reference"></a>
<a id="rst-camera-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Camera class includes controls for mechanical (or equivalent digital) features of a device such as controllable lenses or sensors.

<a id="rst-camera-control-ids"></a>
<a id="rst-camera-control-id"></a>

## Camera Control IDs

- **`V4L2_CID_CAMERA_CLASS (class)`**

  The Camera class descriptor. Calling [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>) for this control will return a description of this control class.

<a id="rst-v4l2-exposure-auto-type"></a>

- **`V4L2_CID_EXPOSURE_AUTO`**

  (enum)

- **enum v4l2\_exposure\_auto\_type -**

  Enables automatic adjustments of the exposure time and/or iris aperture. The effect of manual changes of the exposure time or iris aperture while these features are enabled is undefined, drivers should ignore such requests. Possible values are:

<!-- tabularcolumns: |p{7.1cm}|p{10.4cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_EXPOSURE_AUTO`

</td>
<td>



Automatic exposure time, automatic iris aperture.

</td>
</tr>
<tr>
<td>



`V4L2_EXPOSURE_MANUAL`

</td>
<td>



Manual exposure time, manual iris.

</td>
</tr>
<tr>
<td>



`V4L2_EXPOSURE_SHUTTER_PRIORITY`

</td>
<td>



Manual exposure time, auto iris.

</td>
</tr>
<tr>
<td>



`V4L2_EXPOSURE_APERTURE_PRIORITY`

</td>
<td>



Auto exposure time, manual iris.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_EXPOSURE_ABSOLUTE (integer)`**

  Determines the exposure time of the camera sensor. The exposure time is limited by the frame interval. Drivers should interpret the values as 100 µs units, where the value 1 stands for 1/10000th of a second, 10000 for 1 second and 100000 for 10 seconds.

- **`V4L2_CID_EXPOSURE_AUTO_PRIORITY (boolean)`**

  When `V4L2_CID_EXPOSURE_AUTO` is set to `AUTO` or `APERTURE_PRIORITY`, this control determines if the device may dynamically vary the frame rate. By default this feature is disabled (0) and the frame rate must remain constant.

- **`V4L2_CID_AUTO_EXPOSURE_BIAS (integer menu)`**

  Determines the automatic exposure compensation, it is effective only when `V4L2_CID_EXPOSURE_AUTO` control is set to `AUTO`, `SHUTTER_PRIORITY` or `APERTURE_PRIORITY`. It is expressed in terms of EV, drivers should interpret the values as 0.001 EV units, where the value 1000 stands for +1 EV.

  Increasing the exposure compensation value is equivalent to decreasing the exposure value (EV) and will increase the amount of light at the image sensor. The camera performs the exposure compensation by adjusting absolute exposure time and/or aperture.

<a id="rst-v4l2-exposure-metering"></a>

- **`V4L2_CID_EXPOSURE_METERING`**

  (enum)

- **enum v4l2\_exposure\_metering -**

  Determines how the camera measures the amount of light available for the frame exposure. Possible values are:

<!-- tabularcolumns: |p{8.7cm}|p{8.7cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_EXPOSURE_METERING_AVERAGE`

</td>
<td>



Use the light information coming from the entire frame and average giving no weighting to any particular portion of the metered area.

</td>
</tr>
<tr>
<td>



`V4L2_EXPOSURE_METERING_CENTER_WEIGHTED`

</td>
<td>



Average the light information coming from the entire frame giving priority to the center of the metered area.

</td>
</tr>
<tr>
<td>



`V4L2_EXPOSURE_METERING_SPOT`

</td>
<td>



Measure only very small area at the center of the frame.

</td>
</tr>
<tr>
<td>



`V4L2_EXPOSURE_METERING_MATRIX`

</td>
<td>



A multi-zone metering. The light intensity is measured in several points of the frame and the results are combined. The algorithm of the zones selection and their significance in calculating the final value is device dependent.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_PAN_RELATIVE (integer)`**

  This control turns the camera horizontally by the specified amount. The unit is undefined. A positive value moves the camera to the right (clockwise when viewed from above), a negative value to the left. A value of zero does not cause motion. This is a write-only control.

- **`V4L2_CID_TILT_RELATIVE (integer)`**

  This control turns the camera vertically by the specified amount. The unit is undefined. A positive value moves the camera up, a negative value down. A value of zero does not cause motion. This is a write-only control.

- **`V4L2_CID_PAN_RESET (button)`**

  When this control is set, the camera moves horizontally to the default position.

- **`V4L2_CID_TILT_RESET (button)`**

  When this control is set, the camera moves vertically to the default position.

- **`V4L2_CID_PAN_ABSOLUTE (integer)`**

  This control turns the camera horizontally to the specified position. Positive values move the camera to the right (clockwise when viewed from above), negative values to the left. Drivers should interpret the values as arc seconds, with valid values between -180 \* 3600 and +180 \* 3600 inclusive.

- **`V4L2_CID_TILT_ABSOLUTE (integer)`**

  This control turns the camera vertically to the specified position. Positive values move the camera up, negative values down. Drivers should interpret the values as arc seconds, with valid values between -180 \* 3600 and +180 \* 3600 inclusive.

- **`V4L2_CID_FOCUS_ABSOLUTE (integer)`**

  This control sets the focal point of the camera to the specified position. The unit is undefined. Positive values set the focus closer to the camera, negative values towards infinity.

- **`V4L2_CID_FOCUS_RELATIVE (integer)`**

  This control moves the focal point of the camera by the specified amount. The unit is undefined. Positive values move the focus closer to the camera, negative values towards infinity. This is a write-only control.

- **`V4L2_CID_FOCUS_AUTO (boolean)`**

  Enables continuous automatic focus adjustments. The effect of manual focus adjustments while this feature is enabled is undefined, drivers should ignore such requests.

- **`V4L2_CID_AUTO_FOCUS_START (button)`**

  Starts single auto focus process. The effect of setting this control when `V4L2_CID_FOCUS_AUTO` is set to `TRUE` (1) is undefined, drivers should ignore such requests.

- **`V4L2_CID_AUTO_FOCUS_STOP (button)`**

  Aborts automatic focusing started with `V4L2_CID_AUTO_FOCUS_START` control. It is effective only when the continuous autofocus is disabled, that is when `V4L2_CID_FOCUS_AUTO` control is set to `FALSE` (0).

<a id="rst-v4l2-auto-focus-status"></a>

- **`V4L2_CID_AUTO_FOCUS_STATUS (bitmask)`**

  The automatic focus status. This is a read-only control.

  Setting `V4L2_LOCK_FOCUS` lock bit of the `V4L2_CID_3A_LOCK` control may stop updates of the `V4L2_CID_AUTO_FOCUS_STATUS` control value.

<!-- tabularcolumns: |p{6.8cm}|p{10.7cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AUTO_FOCUS_STATUS_IDLE`

</td>
<td>



Automatic focus is not active.

</td>
</tr>
<tr>
<td>



`V4L2_AUTO_FOCUS_STATUS_BUSY`

</td>
<td>



Automatic focusing is in progress.

</td>
</tr>
<tr>
<td>



`V4L2_AUTO_FOCUS_STATUS_REACHED`

</td>
<td>



Focus has been reached.

</td>
</tr>
<tr>
<td>



`V4L2_AUTO_FOCUS_STATUS_FAILED`

</td>
<td>



Automatic focus has failed, the driver will not transition from this state until another action is performed by an application.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-auto-focus-range"></a>

- **`V4L2_CID_AUTO_FOCUS_RANGE`**

  (enum)

- **enum v4l2\_auto\_focus\_range -**

  Determines auto focus distance range for which lens may be adjusted.

<!-- tabularcolumns: |p{6.9cm}|p{10.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AUTO_FOCUS_RANGE_AUTO`

</td>
<td>



The camera automatically selects the focus range.

</td>
</tr>
<tr>
<td>



`V4L2_AUTO_FOCUS_RANGE_NORMAL`

</td>
<td>



Normal distance range, limited for best automatic focus performance.

</td>
</tr>
<tr>
<td>



`V4L2_AUTO_FOCUS_RANGE_MACRO`

</td>
<td>



Macro (close-up) auto focus. The camera will use its minimum possible distance for auto focus.

</td>
</tr>
<tr>
<td>



`V4L2_AUTO_FOCUS_RANGE_INFINITY`

</td>
<td>



The lens is set to focus on an object at infinite distance.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_ZOOM_ABSOLUTE (integer)`**

  Specify the objective lens focal length as an absolute value. The zoom unit is driver-specific and its value should be a positive integer.

- **`V4L2_CID_ZOOM_RELATIVE (integer)`**

  Specify the objective lens focal length relatively to the current value. Positive values move the zoom lens group towards the telephoto direction, negative values towards the wide-angle direction. The zoom unit is driver-specific. This is a write-only control.

- **`V4L2_CID_ZOOM_CONTINUOUS (integer)`**

  Move the objective lens group at the specified speed until it reaches physical device limits or until an explicit request to stop the movement. A positive value moves the zoom lens group towards the telephoto direction. A value of zero stops the zoom lens group movement. A negative value moves the zoom lens group towards the wide-angle direction. The zoom speed unit is driver-specific.

- **`V4L2_CID_IRIS_ABSOLUTE (integer)`**

  This control sets the camera's aperture to the specified value. The unit is undefined. Larger values open the iris wider, smaller values close it.

- **`V4L2_CID_IRIS_RELATIVE (integer)`**

  This control modifies the camera's aperture by the specified amount. The unit is undefined. Positive values open the iris one step further, negative values close it one step further. This is a write-only control.

- **`V4L2_CID_PRIVACY (boolean)`**

  Prevent video from being acquired by the camera. When this control is set to `TRUE` (1), no image can be captured by the camera. Common means to enforce privacy are mechanical obturation of the sensor and firmware image processing, but the device is not restricted to these methods. Devices that implement the privacy control must support read access and may support write access.

- **`V4L2_CID_BAND_STOP_FILTER (integer)`**

  Switch the band-stop filter of a camera sensor on or off, or specify its strength. Such band-stop filters can be used, for example, to filter out the fluorescent light component.

<a id="rst-v4l2-auto-n-preset-white-balance"></a>

- **`V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE`**

  (enum)

- **enum v4l2\_auto\_n\_preset\_white\_balance -**

  Sets white balance to automatic, manual or a preset. The presets determine color temperature of the light as a hint to the camera for white balance adjustments resulting in most accurate color representation. The following white balance presets are listed in order of increasing color temperature.

<!-- tabularcolumns: |p{7.4cm}|p{10.1cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_WHITE_BALANCE_MANUAL`

</td>
<td>



Manual white balance.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_AUTO`

</td>
<td>



Automatic white balance adjustments.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_INCANDESCENT`

</td>
<td>



White balance setting for incandescent (tungsten) lighting. It generally cools down the colors and corresponds approximately to 2500...3500 K color temperature range.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_FLUORESCENT`

</td>
<td>



White balance preset for fluorescent lighting. It corresponds approximately to 4000...5000 K color temperature.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_FLUORESCENT_H`

</td>
<td>



With this setting the camera will compensate for fluorescent H lighting.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_HORIZON`

</td>
<td>



White balance setting for horizon daylight. It corresponds approximately to 5000 K color temperature.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_DAYLIGHT`

</td>
<td>



White balance preset for daylight (with clear sky). It corresponds approximately to 5000...6500 K color temperature.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_FLASH`

</td>
<td>



With this setting the camera will compensate for the flash light. It slightly warms up the colors and corresponds roughly to 5000...5500 K color temperature.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_CLOUDY`

</td>
<td>



White balance preset for moderately overcast sky. This option corresponds approximately to 6500...8000 K color temperature range.

</td>
</tr>
<tr>
<td>



`V4L2_WHITE_BALANCE_SHADE`

</td>
<td>



White balance preset for shade or heavily overcast sky. It corresponds approximately to 9000...10000 K color temperature.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-wide-dynamic-range"></a>

- **`V4L2_CID_WIDE_DYNAMIC_RANGE (boolean)`**

  Enables or disables the camera's wide dynamic range feature. This feature allows to obtain clear images in situations where intensity of the illumination varies significantly throughout the scene, i.e. there are simultaneously very dark and very bright areas. It is most commonly realized in cameras by combining two subsequent frames with different exposure times.  <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

<a id="rst-v4l2-image-stabilization"></a>

- **`V4L2_CID_IMAGE_STABILIZATION (boolean)`**

  Enables or disables image stabilization.

- **`V4L2_CID_ISO_SENSITIVITY (integer menu)`**

  Determines ISO equivalent of an image sensor indicating the sensor's sensitivity to light. The numbers are expressed in arithmetic scale, as per [iso12232](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-iso12232>) standard, where doubling the sensor sensitivity is represented by doubling the numerical ISO value. Applications should interpret the values as standard ISO values multiplied by 1000, e.g. control value 800 stands for ISO 0.8. Drivers will usually support only a subset of standard ISO values. The effect of setting this control while the `V4L2_CID_ISO_SENSITIVITY_AUTO` control is set to a value other than `V4L2_CID_ISO_SENSITIVITY_MANUAL` is undefined, drivers should ignore such requests.

<a id="rst-v4l2-iso-sensitivity-auto-type"></a>

- **`V4L2_CID_ISO_SENSITIVITY_AUTO`**

  (enum)

- **enum v4l2\_iso\_sensitivity\_type -**

  Enables or disables automatic ISO sensitivity adjustments.


<table>
<tbody>
<tr>
<td>



`V4L2_CID_ISO_SENSITIVITY_MANUAL`

</td>
<td>



Manual ISO sensitivity.

</td>
</tr>
<tr>
<td>



`V4L2_CID_ISO_SENSITIVITY_AUTO`

</td>
<td>



Automatic ISO sensitivity adjustments.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-scene-mode"></a>

- **`V4L2_CID_SCENE_MODE`**

  (enum)

- **enum v4l2\_scene\_mode -**

  This control allows to select scene programs as the camera automatic modes optimized for common shooting scenes. Within these modes the camera determines best exposure, aperture, focusing, light metering, white balance and equivalent sensitivity. The controls of those parameters are influenced by the scene mode control. An exact behavior in each mode is subject to the camera specification.

  When the scene mode feature is not used, this control should be set to `V4L2_SCENE_MODE_NONE` to make sure the other possibly related controls are accessible. The following scene programs are defined:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{5.9cm}|p{11.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_SCENE_MODE_NONE`

</td>
<td>



The scene mode feature is disabled.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_BACKLIGHT`

</td>
<td>



Backlight. Compensates for dark shadows when light is coming from behind a subject, also by automatically turning on the flash.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_BEACH_SNOW`

</td>
<td>



Beach and snow. This mode compensates for all-white or bright scenes, which tend to look gray and low contrast, when camera's automatic exposure is based on an average scene brightness. To compensate, this mode automatically slightly overexposes the frames. The white balance may also be adjusted to compensate for the fact that reflected snow looks bluish rather than white.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_CANDLELIGHT`

</td>
<td>



Candle light. The camera generally raises the ISO sensitivity and lowers the shutter speed. This mode compensates for relatively close subject in the scene. The flash is disabled in order to preserve the ambiance of the light.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_DAWN_DUSK`

</td>
<td>



Dawn and dusk. Preserves the colors seen in low natural light before dusk and after down. The camera may turn off the flash, and automatically focus at infinity. It will usually boost saturation and lower the shutter speed.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_FALL_COLORS`

</td>
<td>



Fall colors. Increases saturation and adjusts white balance for color enhancement. Pictures of autumn leaves get saturated reds and yellows.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_FIREWORKS`

</td>
<td>



Fireworks. Long exposure times are used to capture the expanding burst of light from a firework. The camera may invoke image stabilization.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_LANDSCAPE`

</td>
<td>



Landscape. The camera may choose a small aperture to provide deep depth of field and long exposure duration to help capture detail in dim light conditions. The focus is fixed at infinity. Suitable for distant and wide scenery.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_NIGHT`

</td>
<td>



Night, also known as Night Landscape. Designed for low light conditions, it preserves detail in the dark areas without blowing out bright objects. The camera generally sets itself to a medium-to-high ISO sensitivity, with a relatively long exposure time, and turns flash off. As such, there will be increased image noise and the possibility of blurred image.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_PARTY_INDOOR`

</td>
<td>



Party and indoor. Designed to capture indoor scenes that are lit by indoor background lighting as well as the flash. The camera usually increases ISO sensitivity, and adjusts exposure for the low light conditions.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_PORTRAIT`

</td>
<td>



Portrait. The camera adjusts the aperture so that the depth of field is reduced, which helps to isolate the subject against a smooth background. Most cameras recognize the presence of faces in the scene and focus on them. The color hue is adjusted to enhance skin tones. The intensity of the flash is often reduced.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_SPORTS`

</td>
<td>



Sports. Significantly increases ISO and uses a fast shutter speed to freeze motion of rapidly-moving subjects. Increased image noise may be seen in this mode.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_SUNSET`

</td>
<td>



Sunset. Preserves deep hues seen in sunsets and sunrises. It bumps up the saturation.

</td>
</tr>
<tr>
<td>



`V4L2_SCENE_MODE_TEXT`

</td>
<td>



Text. It applies extra contrast and sharpness, it is typically a black-and-white mode optimized for readability. Automatic focus may be switched to close-up mode and this setting may also involve some lens-distortion correction.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_3A_LOCK (bitmask)`**

  This control locks or unlocks the automatic focus, exposure and white balance. The automatic adjustments can be paused independently by setting the corresponding lock bit to 1. The camera then retains the settings until the lock bit is cleared. The following lock bits are defined:

  When a given algorithm is not enabled, drivers should ignore requests to lock it and should return no error. An example might be an application setting bit `V4L2_LOCK_WHITE_BALANCE` when the `V4L2_CID_AUTO_WHITE_BALANCE` control is set to `FALSE`. The value of this control may be changed by exposure, white balance or focus controls.


<table>
<tbody>
<tr>
<td>



`V4L2_LOCK_EXPOSURE`

</td>
<td>



Automatic exposure adjustments lock.

</td>
</tr>
<tr>
<td>



`V4L2_LOCK_WHITE_BALANCE`

</td>
<td>



Automatic white balance adjustments lock.

</td>
</tr>
<tr>
<td>



`V4L2_LOCK_FOCUS`

</td>
<td>



Automatic focus lock.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_PAN_SPEED (integer)`**

  This control turns the camera horizontally at the specific speed. The unit is undefined. A positive value moves the camera to the right (clockwise when viewed from above), a negative value to the left. A value of zero stops the motion if one is in progress and has no effect otherwise.

- **`V4L2_CID_TILT_SPEED (integer)`**

  This control turns the camera vertically at the specified speed. The unit is undefined. A positive value moves the camera up, a negative value down. A value of zero stops the motion if one is in progress and has no effect otherwise.

<a id="rst-v4l2-camera-sensor-orientation"></a>

- **`V4L2_CID_CAMERA_ORIENTATION (menu)`**

  This read-only control describes the camera orientation by reporting its mounting position on the device where the camera is installed. The control value is constant and not modifiable by software. This control is particularly meaningful for devices which have a well defined orientation, such as phones, laptops and portable devices since the control is expressed as a position relative to the device's intended usage orientation. For example, a camera installed on the user-facing side of a phone, a tablet or a laptop device is said to be have `V4L2_CAMERA_ORIENTATION_FRONT` orientation, while a camera installed on the opposite side of the front one is said to be have `V4L2_CAMERA_ORIENTATION_BACK` orientation. Camera sensors not directly attached to the device, or attached in a way that allows them to move freely, such as webcams and digital cameras, are said to have the `V4L2_CAMERA_ORIENTATION_EXTERNAL` orientation.

<!-- tabularcolumns: |p{7.7cm}|p{9.8cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_CAMERA_ORIENTATION_FRONT`

</td>
<td>



The camera is oriented towards the user facing side of the device.

</td>
</tr>
<tr>
<td>



`V4L2_CAMERA_ORIENTATION_BACK`

</td>
<td>



The camera is oriented towards the back facing side of the device.

</td>
</tr>
<tr>
<td>



`V4L2_CAMERA_ORIENTATION_EXTERNAL`

</td>
<td>



The camera is not directly attached to the device and is freely movable.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-camera-sensor-rotation"></a>

- **`V4L2_CID_CAMERA_SENSOR_ROTATION (integer)`**

  This read-only control describes the rotation correction in degrees in the counter-clockwise direction to be applied to the captured images once captured to memory to compensate for the camera sensor mounting rotation.

  For a precise definition of the sensor mounting rotation refer to the extensive description of the 'rotation' properties in the device tree bindings file 'video-interfaces.txt'.

  A few examples are below reported, using a shark swimming from left to right in front of the user as the example scene to capture.



  ```text
    0               X-axis
  0 +------------------------------------->
    !
    !
    !
    !           |\____)\___
    !           ) _____  __`<
    !           |/     )/
    !
    !
    !
    V
  Y-axis
  ```

  Example one - Webcam

  Assuming you can bring your laptop with you while swimming with sharks, the camera module of the laptop is installed on the user facing part of a laptop screen casing, and is typically used for video calls. The captured images are meant to be displayed in landscape mode (width &gt; height) on the laptop screen.

  The camera is typically mounted upside-down to compensate the lens optical inversion effect. In this case the value of the V4L2\_CID\_CAMERA\_SENSOR\_ROTATION control is 0, no rotation is required to display images correctly to the user.

  If the camera sensor is not mounted upside-down it is required to compensate the lens optical inversion effect and the value of the V4L2\_CID\_CAMERA\_SENSOR\_ROTATION control is 180 degrees, as images will result rotated when captured to memory.



  ```text
  +--------------------------------------+
  !                                      !
  !                                      !
  !                                      !
  !              __/(_____/|             !
  !            >.___  ____ (             !
  !                 \(    \|             !
  !                                      !
  !                                      !
  !                                      !
  +--------------------------------------+
  ```

  A software rotation correction of 180 degrees has to be applied to correctly display the image on the user screen.



  ```text
  +--------------------------------------+
  !                                      !
  !                                      !
  !                                      !
  !             |\____)\___              !
  !             ) _____  __`<            !
  !             |/     )/                !
  !                                      !
  !                                      !
  !                                      !
  +--------------------------------------+
  ```

  Example two - Phone camera

  It is more handy to go and swim with sharks with only your mobile phone with you and take pictures with the camera that is installed on the back side of the device, facing away from the user. The captured images are meant to be displayed in portrait mode (height &gt; width) to match the device screen orientation and the device usage orientation used when taking the picture.

  The camera sensor is typically mounted with its pixel array longer side aligned to the device longer side, upside-down mounted to compensate for the lens optical inversion effect.

  The images once captured to memory will be rotated and the value of the V4L2\_CID\_CAMERA\_SENSOR\_ROTATION will report a 90 degree rotation.



  ```text
  +-------------------------------------+
  |                 _ _                 |
  |                \   /                |
  |                 | |                 |
  |                 | |                 |
  |                 |  >                |
  |                <  |                 |
  |                 | |                 |
  |                   .                 |
  |                  V                  |
  +-------------------------------------+
  ```

  A correction of 90 degrees in counter-clockwise direction has to be applied to correctly display the image in portrait mode on the device screen.



  ```text
  +--------------------+
  |                    |
  |                    |
  |                    |
  |                    |
  |                    |
  |                    |
  |   |\____)\___      |
  |   ) _____  __`<    |
  |   |/     )/        |
  |                    |
  |                    |
  |                    |
  |                    |
  |                    |
  +--------------------+
  ```

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



**[1]** This control may be changed to a menu control in the future, if more options are required.

- **`V4L2_CID_HDR_SENSOR_MODE (menu)`**

  Change the sensor HDR mode. A HDR picture is obtained by merging two captures of the same scene using two different exposure periods. HDR mode describes the way these two captures are merged in the sensor.

  As modes differ for each sensor, menu items are not standardized by this control and are left to the programmer.

---

# Stateless Codec Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Stateless Codec control class is intended to support stateless decoder and encoders (i.e. hardware accelerators).

<a id="rst-stateless-codec-control-reference"></a>
<a id="rst-codec-stateless-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Stateless Codec control class is intended to support stateless decoder and encoders (i.e. hardware accelerators).

These drivers are typically supported by the [stateless\_decoder](</kernel/userspace/userspace-api/media-v4l/dev-stateless-decoder.md#rst-stateless-decoder>), and deal with parsed pixel formats such as V4L2\_PIX\_FMT\_H264\_SLICE.

<a id="rst-stateless-codec-control-id"></a>

## Stateless Codec Control ID

<a id="rst-codec-stateless-control-id"></a>

- **`V4L2_CID_CODEC_STATELESS_CLASS (class)`**

  The Stateless Codec class descriptor.

<a id="rst-v4l2-codec-stateless-h264"></a>

- **`V4L2_CID_STATELESS_H264_SPS (struct)`**

  Specifies the sequence parameter set (as extracted from the bitstream) for the associated H264 slice data. This includes the necessary parameters for configuring a stateless hardware decoding pipeline for H264. The bitstream parameters are defined according to [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>), section 7.4.2.1.1 "Sequence Parameter Set Data Semantics". For further documentation, refer to the above specification, unless there is an explicit comment stating otherwise.

<a id="c-v4l2_ctrl_h264_sps"></a>



```c
v4l2_ctrl_h264_sps
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{1.2cm}|p{8.6cm}|p{7.5cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_h264\_sps

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`profile_idc`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`constraint_set_flags`

</td>
<td>



See [Sequence Parameter Set Constraints Set Flags](<#rst-h264-sps-constraints-set-flags>)

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`level_idc`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`seq_parameter_set_id`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`chroma_format_idc`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`bit_depth_luma_minus8`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`bit_depth_chroma_minus8`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_max_frame_num_minus4`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`pic_order_cnt_type`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_max_pic_order_cnt_lsb_minus4`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`max_num_ref_frames`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_frames_in_pic_order_cnt_cycle`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`offset_for_ref_frame[255]`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`offset_for_non_ref_pic`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`offset_for_top_to_bottom_field`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`pic_width_in_mbs_minus1`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`pic_height_in_map_units_minus1`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [Sequence Parameter Set Flags](<#rst-h264-sps-flags>)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-h264-sps-constraints-set-flags"></a>

`Sequence Parameter Set Constraints Set Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_H264_SPS_CONSTRAINT_SET0_FLAG`

</td>
<td>



0x00000001

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_CONSTRAINT_SET1_FLAG`

</td>
<td>



0x00000002

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_CONSTRAINT_SET2_FLAG`

</td>
<td>



0x00000004

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_CONSTRAINT_SET3_FLAG`

</td>
<td>



0x00000008

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_CONSTRAINT_SET4_FLAG`

</td>
<td>



0x00000010

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_CONSTRAINT_SET5_FLAG`

</td>
<td>



0x00000020

</td>
<td>





</td>
</tr>
</tbody>
</table>

<a id="rst-h264-sps-flags"></a>

`Sequence Parameter Set Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE`

</td>
<td>



0x00000001

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS`

</td>
<td>



0x00000002

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO`

</td>
<td>



0x00000004

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_FLAG_GAPS_IN_FRAME_NUM_VALUE_ALLOWED`

</td>
<td>



0x00000008

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY`

</td>
<td>



0x00000010

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD`

</td>
<td>



0x00000020

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE`

</td>
<td>



0x00000040

</td>
<td>





</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_STATELESS_H264_PPS (struct)`**

  Specifies the picture parameter set (as extracted from the bitstream) for the associated H264 slice data. This includes the necessary parameters for configuring a stateless hardware decoding pipeline for H264.  The bitstream parameters are defined according to [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>), section 7.4.2.2 "Picture Parameter Set RBSP Semantics". For further documentation, refer to the above specification, unless there is an explicit comment stating otherwise.

<a id="c-v4l2_ctrl_h264_pps"></a>



```c
v4l2_ctrl_h264_pps
```

<!-- Source LaTeX layout: \small -->


<table>
<caption>

struct v4l2\_ctrl\_h264\_pps

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`pic_parameter_set_id`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`seq_parameter_set_id`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_slice_groups_minus1`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_idx_l0_default_active_minus1`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_idx_l1_default_active_minus1`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`weighted_bipred_idc`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`pic_init_qp_minus26`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`pic_init_qs_minus26`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`chroma_qp_index_offset`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`second_chroma_qp_index_offset`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`flags`

</td>
<td>



See [Picture Parameter Set Flags](<#rst-h264-pps-flags>)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-h264-pps-flags"></a>

`Picture Parameter Set Flags`

<!-- Source LaTeX layout: \begingroup
\scriptsize
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{9.8cm}|p{1.0cm}|p{6.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE`

</td>
<td>



0x0001

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT`

</td>
<td>



0x0002

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_PPS_FLAG_WEIGHTED_PRED`

</td>
<td>



0x0004

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT`

</td>
<td>



0x0008

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_PPS_FLAG_CONSTRAINED_INTRA_PRED`

</td>
<td>



0x0010

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_PPS_FLAG_REDUNDANT_PIC_CNT_PRESENT`

</td>
<td>



0x0020

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE`

</td>
<td>



0x0040

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT`

</td>
<td>



0x0080

</td>
<td>



`V4L2_CID_STATELESS_H264_SCALING_MATRIX` must be used for this picture.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

- **`V4L2_CID_STATELESS_H264_SCALING_MATRIX (struct)`**

  Specifies the scaling matrix (as extracted from the bitstream) for the associated H264 slice data. The bitstream parameters are defined according to [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>), section 7.4.2.1.1.1 "Scaling List Semantics". For further documentation, refer to the above specification, unless there is an explicit comment stating otherwise.

<a id="c-v4l2_ctrl_h264_scaling_matrix"></a>



```c
v4l2_ctrl_h264_scaling_matrix
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{0.6cm}|p{4.8cm}|p{11.9cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_h264\_scaling\_matrix

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`scaling_list_4x4[6][16]`

</td>
<td>



Scaling matrix after applying the inverse scanning process. Expected list order is Intra Y, Intra Cb, Intra Cr, Inter Y, Inter Cb, Inter Cr. The values on each scaling list are expected in raster scan order.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`scaling_list_8x8[6][64]`

</td>
<td>



Scaling matrix after applying the inverse scanning process. Expected list order is Intra Y, Inter Y, Intra Cb, Inter Cb, Intra Cr, Inter Cr. The values on each scaling list are expected in raster scan order.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_STATELESS_H264_SLICE_PARAMS (struct)`**

  Specifies the slice parameters (as extracted from the bitstream) for the associated H264 slice data. This includes the necessary parameters for configuring a stateless hardware decoding pipeline for H264.  The bitstream parameters are defined according to [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>), section 7.4.3 "Slice Header Semantics". For further documentation, refer to the above specification, unless there is an explicit comment stating otherwise.

<a id="c-v4l2_ctrl_h264_slice_params"></a>



```c
v4l2_ctrl_h264_slice_params
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{4.0cm}|p{5.9cm}|p{7.4cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_h264\_slice\_params

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`header_bit_size`

</td>
<td>



Offset in bits to slice\_data() from the beginning of this slice.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`first_mb_in_slice`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`slice_type`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`colour_plane_id`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`redundant_pic_cnt`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`cabac_init_idc`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_qp_delta`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_qs_delta`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`disable_deblocking_filter_idc`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_alpha_c0_offset_div2`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_beta_offset_div2`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_idx_l0_active_minus1`

</td>
<td>



If num\_ref\_idx\_active\_override\_flag is not set, this field must be set to the value of num\_ref\_idx\_l0\_default\_active\_minus1

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_idx_l1_active_minus1`

</td>
<td>



If num\_ref\_idx\_active\_override\_flag is not set, this field must be set to the value of num\_ref\_idx\_l1\_default\_active\_minus1

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



struct `v4l2_h264_reference`

</td>
<td>



`ref_pic_list0[32]`

</td>
<td>



Reference picture list after applying the per-slice modifications

</td>
</tr>
<tr>
<td>



struct `v4l2_h264_reference`

</td>
<td>



`ref_pic_list1[32]`

</td>
<td>



Reference picture list after applying the per-slice modifications

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [Slice Parameter Flags](<#rst-h264-slice-flags>)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-h264-slice-flags"></a>

`Slice Parameter Set Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED`

</td>
<td>



0x00000001

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_SLICE_FLAG_SP_FOR_SWITCH`

</td>
<td>



0x00000002

</td>
<td>





</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_STATELESS_H264_PRED_WEIGHTS (struct)`**

  Prediction weight table defined according to [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>), section 7.4.3.2 "Prediction Weight Table Semantics". The prediction weight table must be passed by applications under the conditions explained in section 7.3.3 "Slice header syntax".

<a id="c-v4l2_ctrl_h264_pred_weights"></a>



```c
v4l2_ctrl_h264_pred_weights
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{4.9cm}|p{4.9cm}|p{7.5cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_h264\_pred\_weights

</caption>
<tbody>
<tr>
<td>



\_\_u16

</td>
<td>



`luma_log2_weight_denom`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`chroma_log2_weight_denom`

</td>
<td>





</td>
</tr>
<tr>
<td>



struct `v4l2_h264_weight_factors`

</td>
<td>



`weight_factors[2]`

</td>
<td>



The weight factors at index 0 are the weight factors for the reference list 0, the one at index 1 for the reference list 1.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="c-v4l2_h264_weight_factors"></a>



```c
v4l2_h264_weight_factors
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{1.0cm}|p{4.5cm}|p{11.8cm}| -->


<table>
<caption>

struct v4l2\_h264\_weight\_factors

</caption>
<tbody>
<tr>
<td>



\_\_s16

</td>
<td>



`luma_weight[32]`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s16

</td>
<td>



`luma_offset[32]`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s16

</td>
<td>



`chroma_weight[32][2]`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s16

</td>
<td>



`chroma_offset[32][2]`

</td>
<td>





</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

`Picture Reference`

<a id="c-v4l2_h264_reference"></a>



```c
v4l2_h264_reference
```


<table>
<caption>

struct v4l2\_h264\_reference

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`fields`

</td>
<td>



Specifies how the picture is referenced. See [Reference Fields](<#rst-h264-ref-fields>)

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`index`

</td>
<td>



Index into the `v4l2_ctrl_h264_decode_params`.dpb array.

</td>
</tr>
</tbody>
</table>

<a id="rst-h264-ref-fields"></a>

`Reference Fields`

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{5.4cm}|p{0.8cm}|p{11.1cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_H264_TOP_FIELD_REF`

</td>
<td>



0x1

</td>
<td>



The top field in field pair is used for short-term reference.

</td>
</tr>
<tr>
<td>



`V4L2_H264_BOTTOM_FIELD_REF`

</td>
<td>



0x2

</td>
<td>



The bottom field in field pair is used for short-term reference.

</td>
</tr>
<tr>
<td>



`V4L2_H264_FRAME_REF`

</td>
<td>



0x3

</td>
<td>



The frame (or the top/bottom fields, if it's a field pair) is used for short-term reference.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_H264_DECODE_PARAMS (struct)`**

  Specifies the decode parameters (as extracted from the bitstream) for the associated H264 slice data. This includes the necessary parameters for configuring a stateless hardware decoding pipeline for H264. The bitstream parameters are defined according to [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>). For further documentation, refer to the above specification, unless there is an explicit comment stating otherwise.

<a id="c-v4l2_ctrl_h264_decode_params"></a>



```c
v4l2_ctrl_h264_decode_params
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{4.0cm}|p{5.9cm}|p{7.4cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_h264\_decode\_params

</caption>
<tbody>
<tr>
<td>



struct `v4l2_h264_dpb_entry`

</td>
<td>



`dpb[16]`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`nal_ref_idc`

</td>
<td>



NAL reference ID value coming from the NAL Unit header

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`frame_num`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`top_field_order_cnt`

</td>
<td>



Picture Order Count for the coded top field

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`bottom_field_order_cnt`

</td>
<td>



Picture Order Count for the coded bottom field

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`idr_pic_id`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`pic_order_cnt_lsb`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`delta_pic_order_cnt_bottom`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`delta_pic_order_cnt0`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`delta_pic_order_cnt1`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`dec_ref_pic_marking_bit_size`

</td>
<td>



Size in bits of the dec\_ref\_pic\_marking() syntax element.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`pic_order_cnt_bit_size`

</td>
<td>



Combined size in bits of the picture order count related syntax elements: pic\_order\_cnt\_lsb, delta\_pic\_order\_cnt\_bottom, delta\_pic\_order\_cnt0, and delta\_pic\_order\_cnt1.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`slice_group_change_cycle`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [Decode Parameters Flags](<#rst-h264-decode-params-flags>)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-h264-decode-params-flags"></a>

`Decode Parameters Flags`

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{8.3cm}|p{2.1cm}|p{6.9cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_H264_DECODE_PARAM_FLAG_IDR_PIC`

</td>
<td>



0x00000001

</td>
<td>



That picture is an IDR picture

</td>
</tr>
<tr>
<td>



`V4L2_H264_DECODE_PARAM_FLAG_FIELD_PIC`

</td>
<td>



0x00000002

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_DECODE_PARAM_FLAG_BOTTOM_FIELD`

</td>
<td>



0x00000004

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_DECODE_PARAM_FLAG_PFRAME`

</td>
<td>



0x00000008

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_H264_DECODE_PARAM_FLAG_BFRAME`

</td>
<td>



0x00000010

</td>
<td>





</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="c-v4l2_h264_dpb_entry"></a>



```c
v4l2_h264_dpb_entry
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{1.0cm}|p{4.9cm}|p{11.4cm}| -->


<table>
<caption>

struct v4l2\_h264\_dpb\_entry

</caption>
<tbody>
<tr>
<td>



\_\_u64

</td>
<td>



`reference_ts`

</td>
<td>



Timestamp of the V4L2 capture buffer to use as reference, used with B-coded and P-coded frames. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`pic_num`

</td>
<td>



For short term references, this must match the derived value PicNum (8-28) and for long term references it must match the derived value LongTermPicNum (8-29). When decoding frames (as opposed to fields) pic\_num is the same as FrameNumWrap.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`frame_num`

</td>
<td>



For short term references, this must match the frame\_num value from the slice header syntax (the driver will wrap the value if needed). For long term references, this must be set to the value of long\_term\_frame\_idx described in the dec\_ref\_pic\_marking() syntax.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`fields`

</td>
<td>



Specifies how the DPB entry is referenced. See [Reference Fields](<#rst-h264-ref-fields>)

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[5]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`top_field_order_cnt`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`bottom_field_order_cnt`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [DPB Entry Flags](<#rst-h264-dpb-flags>)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-h264-dpb-flags"></a>

`DPB Entries Flags`

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{7.7cm}|p{2.1cm}|p{7.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_H264_DPB_ENTRY_FLAG_VALID`

</td>
<td>



0x00000001

</td>
<td>



The DPB entry is valid (non-empty) and should be considered.

</td>
</tr>
<tr>
<td>



`V4L2_H264_DPB_ENTRY_FLAG_ACTIVE`

</td>
<td>



0x00000002

</td>
<td>



The DPB entry is used for reference.

</td>
</tr>
<tr>
<td>



`V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM`

</td>
<td>



0x00000004

</td>
<td>



The DPB entry is used for long-term reference.

</td>
</tr>
<tr>
<td>



`V4L2_H264_DPB_ENTRY_FLAG_FIELD`

</td>
<td>



0x00000008

</td>
<td>



The DPB entry is a single field or a complementary field pair.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_H264_DECODE_MODE (enum)`**

  Specifies the decoding mode to use. Currently exposes slice-based and frame-based decoding but new modes might be added later on. This control is used as a modifier for V4L2\_PIX\_FMT\_H264\_SLICE pixel format. Applications that support V4L2\_PIX\_FMT\_H264\_SLICE are required to set this control in order to specify the decoding mode that is expected for the buffer. Drivers may expose a single or multiple decoding modes, depending on what they can support.

<a id="c-v4l2_stateless_h264_decode_mode"></a>



```c
v4l2_stateless_h264_decode_mode
```

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{7.4cm}|p{0.3cm}|p{9.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_STATELESS_H264_DECODE_MODE_SLICE_BASED`

</td>
<td>



0

</td>
<td>



Decoding is done at the slice granularity. The OUTPUT buffer must contain a single slice. When this mode is selected, the `V4L2_CID_STATELESS_H264_SLICE_PARAMS` control shall be set. When multiple slices compose a frame, use of `V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF` flag is required.

</td>
</tr>
<tr>
<td>



`V4L2_STATELESS_H264_DECODE_MODE_FRAME_BASED`

</td>
<td>



1

</td>
<td>



Decoding is done at the frame granularity, The OUTPUT buffer must contain all slices needed to decode the frame. The OUTPUT buffer must also contain both fields. This mode will be supported by devices that parse the slice(s) header(s) in hardware. When this mode is selected, the `V4L2_CID_STATELESS_H264_SLICE_PARAMS` control shall not be set.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_H264_START_CODE (enum)`**

  Specifies the H264 slice start code expected for each slice. This control is used as a modifier for V4L2\_PIX\_FMT\_H264\_SLICE pixel format. Applications that support V4L2\_PIX\_FMT\_H264\_SLICE are required to set this control in order to specify the start code that is expected for the buffer. Drivers may expose a single or multiple start codes, depending on what they can support.

<a id="c-v4l2_stateless_h264_start_code"></a>



```c
v4l2_stateless_h264_start_code
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{7.9cm}|p{0.4cm}|p{9.0cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_STATELESS_H264_START_CODE_NONE`

</td>
<td>



0

</td>
<td>



Selecting this value specifies that H264 slices are passed to the driver without any start code. The bitstream data should be according to [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>) 7.3.1 NAL unit syntax, hence contains emulation prevention bytes when required.

</td>
</tr>
<tr>
<td>



`V4L2_STATELESS_H264_START_CODE_ANNEX_B`

</td>
<td>



1

</td>
<td>



Selecting this value specifies that H264 slices are expected to be prefixed by Annex B start codes. According to [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>) valid start codes can be 3-bytes 0x000001 or 4-bytes 0x00000001.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-codec-stateless-fwht"></a>

- **`V4L2_CID_STATELESS_FWHT_PARAMS (struct)`**

  Specifies the FWHT (Fast Walsh Hadamard Transform) parameters (as extracted from the bitstream) for the associated FWHT data. This includes the necessary parameters for configuring a stateless hardware decoding pipeline for FWHT. This codec is specific to the vicodec test driver.

<a id="c-v4l2_ctrl_fwht_params"></a>



```c
v4l2_ctrl_fwht_params
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{1.4cm}|p{3.9cm}|p{12.0cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_fwht\_params

</caption>
<tbody>
<tr>
<td>



\_\_u64

</td>
<td>



`backward_ref_ts`

</td>
<td>



Timestamp of the V4L2 capture buffer to use as backward reference, used with P-coded frames. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`version`

</td>
<td>



The version of the codec. Set to `V4L2_FWHT_VERSION`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`width`

</td>
<td>



The width of the frame.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`height`

</td>
<td>



The height of the frame.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



The flags of the frame, see [FWHT Flags](<#rst-fwht-flags>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`colorspace`

</td>
<td>



The colorspace of the frame, from enum `v4l2_colorspace`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`xfer_func`

</td>
<td>



The transfer function, from enum `v4l2_xfer_func`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`ycbcr_enc`

</td>
<td>



The Y'CbCr encoding, from enum `v4l2_ycbcr_encoding`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`quantization`

</td>
<td>



The quantization range, from enum `v4l2_quantization`.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-fwht-flags-1"></a>
<a id="rst-fwht-flags"></a>

## FWHT Flags

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{7.0cm}|p{2.3cm}|p{8.0cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_FWHT_FL_IS_INTERLACED`

</td>
<td>



0x00000001

</td>
<td>



Set if this is an interlaced format.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_IS_BOTTOM_FIRST`

</td>
<td>



0x00000002

</td>
<td>



Set if this is a bottom-first (NTSC) interlaced format.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_IS_ALTERNATE`

</td>
<td>



0x00000004

</td>
<td>



Set if each 'frame' contains just one field.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_IS_BOTTOM_FIELD`

</td>
<td>



0x00000008

</td>
<td>



If V4L2\_FWHT\_FL\_IS\_ALTERNATE was set, then this is set if this 'frame' is the bottom field, else it is the top field.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_LUMA_IS_UNCOMPRESSED`

</td>
<td>



0x00000010

</td>
<td>



Set if the Y' (luma) plane is uncompressed.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_CB_IS_UNCOMPRESSED`

</td>
<td>



0x00000020

</td>
<td>



Set if the Cb plane is uncompressed.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_CR_IS_UNCOMPRESSED`

</td>
<td>



0x00000040

</td>
<td>



Set if the Cr plane is uncompressed.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_CHROMA_FULL_HEIGHT`

</td>
<td>



0x00000080

</td>
<td>



Set if the chroma plane has the same height as the luma plane, else the chroma plane is half the height of the luma plane.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_CHROMA_FULL_WIDTH`

</td>
<td>



0x00000100

</td>
<td>



Set if the chroma plane has the same width as the luma plane, else the chroma plane is half the width of the luma plane.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_ALPHA_IS_UNCOMPRESSED`

</td>
<td>



0x00000200

</td>
<td>



Set if the alpha plane is uncompressed.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_I_FRAME`

</td>
<td>



0x00000400

</td>
<td>



Set if this is an I-frame.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_COMPONENTS_NUM_MSK`

</td>
<td>



0x00070000

</td>
<td>



The number of color components minus one.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_PIXENC_MSK`

</td>
<td>



0x00180000

</td>
<td>



The mask for the pixel encoding.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_PIXENC_YUV`

</td>
<td>



0x00080000

</td>
<td>



Set if the pixel encoding is YUV.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_PIXENC_RGB`

</td>
<td>



0x00100000

</td>
<td>



Set if the pixel encoding is RGB.

</td>
</tr>
<tr>
<td>



`V4L2_FWHT_FL_PIXENC_HSV`

</td>
<td>



0x00180000

</td>
<td>



Set if the pixel encoding is HSV.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-v4l2-codec-stateless-vp8"></a>

- **`V4L2_CID_STATELESS_VP8_FRAME (struct)`**

  Specifies the frame parameters for the associated VP8 parsed frame data. This includes the necessary parameters for configuring a stateless hardware decoding pipeline for VP8. The bitstream parameters are defined according to [vp8](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp8-1>).

<a id="c-v4l2_ctrl_vp8_frame"></a>



```c
v4l2_ctrl_vp8_frame
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{7.0cm}|p{4.6cm}|p{5.7cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_vp8\_frame

</caption>
<tbody>
<tr>
<td>



struct `v4l2_vp8_segment`

</td>
<td>



`segment`

</td>
<td>



Structure with segment-based adjustments metadata.

</td>
</tr>
<tr>
<td>



struct `v4l2_vp8_loop_filter`

</td>
<td>



`lf`

</td>
<td>



Structure with loop filter level adjustments metadata.

</td>
</tr>
<tr>
<td>



struct `v4l2_vp8_quantization`

</td>
<td>



`quant`

</td>
<td>



Structure with VP8 dequantization indices metadata.

</td>
</tr>
<tr>
<td>



struct `v4l2_vp8_entropy`

</td>
<td>



`entropy`

</td>
<td>



Structure with VP8 entropy coder probabilities metadata.

</td>
</tr>
<tr>
<td>



struct `v4l2_vp8_entropy_coder_state`

</td>
<td>



`coder_state`

</td>
<td>



Structure with VP8 entropy coder state.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`width`

</td>
<td>



The width of the frame. Must be set for all frames.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`height`

</td>
<td>



The height of the frame. Must be set for all frames.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`horizontal_scale`

</td>
<td>



Horizontal scaling factor.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`vertical_scale`

</td>
<td>



Vertical scaling factor.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`version`

</td>
<td>



Bitstream version.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`prob_skip_false`

</td>
<td>



Indicates the probability that the macroblock is not skipped.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`prob_intra`

</td>
<td>



Indicates the probability that a macroblock is intra-predicted.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`prob_last`

</td>
<td>



Indicates the probability that the last reference frame is used for inter-prediction

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`prob_gf`

</td>
<td>



Indicates the probability that the golden reference frame is used for inter-prediction

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_dct_parts`

</td>
<td>



Number of DCT coefficients partitions. Must be one of: 1, 2, 4, or 8.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`first_part_size`

</td>
<td>



Size of the first partition, i.e. the control partition.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`first_part_header_bits`

</td>
<td>



Size in bits of the first partition header portion.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`dct_part_sizes[8]`

</td>
<td>



DCT coefficients sizes.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`last_frame_ts`

</td>
<td>



Timestamp for the V4L2 capture buffer to use as last reference frame, used with inter-coded frames. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`golden_frame_ts`

</td>
<td>



Timestamp for the V4L2 capture buffer to use as last reference frame, used with inter-coded frames. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`alt_frame_ts`

</td>
<td>



Timestamp for the V4L2 capture buffer to use as alternate reference frame, used with inter-coded frames. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`flags`

</td>
<td>



See [Frame Flags](<#rst-vp8-frame-flags>)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-vp8-frame-flags"></a>

`Frame Flags`

<!-- tabularcolumns: |p{9.8cm}|p{0.8cm}|p{6.7cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP8_FRAME_FLAG_KEY_FRAME`

</td>
<td>



0x01

</td>
<td>



Indicates if the frame is a key frame.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_FRAME_FLAG_EXPERIMENTAL`

</td>
<td>



0x02

</td>
<td>



Experimental bitstream.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_FRAME_FLAG_SHOW_FRAME`

</td>
<td>



0x04

</td>
<td>



Show frame flag, indicates if the frame is for display.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_FRAME_FLAG_MB_NO_SKIP_COEFF`

</td>
<td>



0x08

</td>
<td>



Enable/disable skipping of macroblocks with no non-zero coefficients.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_FRAME_FLAG_SIGN_BIAS_GOLDEN`

</td>
<td>



0x10

</td>
<td>



Sign of motion vectors when the golden frame is referenced.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_FRAME_FLAG_SIGN_BIAS_ALT`

</td>
<td>



0x20

</td>
<td>



Sign of motion vectors when the alt frame is referenced.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_vp8_entropy_coder_state"></a>



```c
v4l2_vp8_entropy_coder_state
```

<!-- tabularcolumns: |p{1.0cm}|p{2.0cm}|p{14.3cm}| -->


<table>
<caption>

struct v4l2\_vp8\_entropy\_coder\_state

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`range`

</td>
<td>



coder state value for "Range"

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`value`

</td>
<td>



coder state value for "Value"-

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`bit_count`

</td>
<td>



number of bits left.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`padding`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_vp8_segment"></a>



```c
v4l2_vp8_segment
```

<!-- tabularcolumns: |p{1.2cm}|p{4.0cm}|p{12.1cm}| -->


<table>
<caption>

struct v4l2\_vp8\_segment

</caption>
<tbody>
<tr>
<td>



\_\_s8

</td>
<td>



`quant_update[4]`

</td>
<td>



Signed quantizer value update.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`lf_update[4]`

</td>
<td>



Signed loop filter level value update.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`segment_probs[3]`

</td>
<td>



Segment probabilities.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`padding`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [Segment Flags](<#rst-vp8-segment-flags>)

</td>
</tr>
</tbody>
</table>

<a id="rst-vp8-segment-flags"></a>

`Segment Flags`

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{10cm}|p{1.0cm}|p{6.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP8_SEGMENT_FLAG_ENABLED`

</td>
<td>



0x01

</td>
<td>



Enable/disable segment-based adjustments.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_SEGMENT_FLAG_UPDATE_MAP`

</td>
<td>



0x02

</td>
<td>



Indicates if the macroblock segmentation map is updated in this frame.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_SEGMENT_FLAG_UPDATE_FEATURE_DATA`

</td>
<td>



0x04

</td>
<td>



Indicates if the segment feature data is updated in this frame.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_SEGMENT_FLAG_DELTA_VALUE_MODE`

</td>
<td>



0x08

</td>
<td>



If is set, the segment feature data mode is delta-value. If cleared, it's absolute-value.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="c-v4l2_vp8_loop_filter"></a>



```c
v4l2_vp8_loop_filter
```

<!-- tabularcolumns: |p{1.5cm}|p{3.9cm}|p{11.9cm}| -->


<table>
<caption>

struct v4l2\_vp8\_loop\_filter

</caption>
<tbody>
<tr>
<td>



\_\_s8

</td>
<td>



`ref_frm_delta[4]`

</td>
<td>



Reference adjustment (signed) delta value.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`mb_mode_delta[4]`

</td>
<td>



Macroblock prediction mode adjustment (signed) delta value.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`sharpness_level`

</td>
<td>



Sharpness level

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`level`

</td>
<td>



Filter level

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`padding`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [Loop Filter Flags](<#rst-vp8-loop-filter-flags>)

</td>
</tr>
</tbody>
</table>

<a id="rst-vp8-loop-filter-flags"></a>

`Loop Filter Flags`

<!-- tabularcolumns: |p{7.0cm}|p{1.2cm}|p{9.1cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP8_LF_ADJ_ENABLE`

</td>
<td>



0x01

</td>
<td>



Enable/disable macroblock-level loop filter adjustment.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_LF_DELTA_UPDATE`

</td>
<td>



0x02

</td>
<td>



Indicates if the delta values used in an adjustment are updated.

</td>
</tr>
<tr>
<td>



`V4L2_VP8_LF_FILTER_TYPE_SIMPLE`

</td>
<td>



0x04

</td>
<td>



If set, indicates the filter type is simple. If cleared, the filter type is normal.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_vp8_quantization"></a>



```c
v4l2_vp8_quantization
```

<!-- tabularcolumns: |p{1.5cm}|p{3.5cm}|p{12.3cm}| -->


<table>
<caption>

struct v4l2\_vp8\_quantization

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`y_ac_qi`

</td>
<td>



Luma AC coefficient table index.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`y_dc_delta`

</td>
<td>



Luma DC delta value.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`y2_dc_delta`

</td>
<td>



Y2 block DC delta value.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`y2_ac_delta`

</td>
<td>



Y2 block AC delta value.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`uv_dc_delta`

</td>
<td>



Chroma DC delta value.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`uv_ac_delta`

</td>
<td>



Chroma AC delta value.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`padding`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_vp8_entropy"></a>



```c
v4l2_vp8_entropy
```

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_vp8\_entropy

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`coeff_probs[4][8][3][11]`

</td>
<td>



Coefficient update probabilities.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`y_mode_probs[4]`

</td>
<td>



Luma mode update probabilities.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`uv_mode_probs[3]`

</td>
<td>



Chroma mode update probabilities.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv_probs[2][19]`

</td>
<td>



MV decoding update probabilities.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`padding[3]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-codec-stateless-mpeg2"></a>

- **`V4L2_CID_STATELESS_MPEG2_SEQUENCE (struct)`**

  Specifies the sequence parameters (as extracted from the bitstream) for the associated MPEG-2 slice data. This includes fields matching the syntax elements from the sequence header and sequence extension parts of the bitstream as specified by [mpeg2part2](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-mpeg2part2>).

<a id="c-v4l2_ctrl_mpeg2_sequence"></a>



```c
v4l2_ctrl_mpeg2_sequence
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{1.4cm}|p{6.5cm}|p{9.4cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_mpeg2\_sequence

</caption>
<tbody>
<tr>
<td>



\_\_u16

</td>
<td>



`horizontal_size`

</td>
<td>



The width of the displayable part of the frame's luminance component.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`vertical_size`

</td>
<td>



The height of the displayable part of the frame's luminance component.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`vbv_buffer_size`

</td>
<td>



Used to calculate the required size of the video buffering verifier, defined (in bits) as: 16 \* 1024 \* vbv\_buffer\_size.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`profile_and_level_indication`

</td>
<td>



The current profile and level indication as extracted from the bitstream.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`chroma_format`

</td>
<td>



The chrominance sub-sampling format (1: 4:2:0, 2: 4:2:2, 3: 4:4:4).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



See [MPEG-2 Sequence Flags](<#rst-mpeg2-sequence-flags>).

</td>
</tr>
</tbody>
</table>

<a id="rst-mpeg2-sequence-flags"></a>

`MPEG-2 Sequence Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG2_SEQ_FLAG_PROGRESSIVE`

</td>
<td>



0x01

</td>
<td>



Indication that all the frames for the sequence are progressive instead of interlaced.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_MPEG2_PICTURE (struct)`**

  Specifies the picture parameters (as extracted from the bitstream) for the associated MPEG-2 slice data. This includes fields matching the syntax elements from the picture header and picture coding extension parts of the bitstream as specified by [mpeg2part2](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-mpeg2part2>).

<a id="c-v4l2_ctrl_mpeg2_picture"></a>



```c
v4l2_ctrl_mpeg2_picture
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{1.0cm}|p{5.6cm}|p{10.7cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_mpeg2\_picture

</caption>
<tbody>
<tr>
<td>



\_\_u64

</td>
<td>



`backward_ref_ts`

</td>
<td>



Timestamp of the V4L2 capture buffer to use as backward reference, used with B-coded and P-coded frames. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`forward_ref_ts`

</td>
<td>



Timestamp for the V4L2 capture buffer to use as forward reference, used with B-coded frames. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [MPEG-2 Picture Flags](<#rst-mpeg2-picture-flags>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`f_code[2][2]`

</td>
<td>



Motion vector codes.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`picture_coding_type`

</td>
<td>



Picture coding type for the frame covered by the current slice (V4L2\_MPEG2\_PIC\_CODING\_TYPE\_I, V4L2\_MPEG2\_PIC\_CODING\_TYPE\_P or V4L2\_MPEG2\_PIC\_CODING\_TYPE\_B).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`picture_structure`

</td>
<td>



Picture structure (1: interlaced top field, 2: interlaced bottom field, 3: progressive frame).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`intra_dc_precision`

</td>
<td>



Precision of Discrete Cosine transform (0: 8 bits precision, 1: 9 bits precision, 2: 10 bits precision, 3: 11 bits precision).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[5]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-mpeg2-picture-flags"></a>

`MPEG-2 Picture Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG2_PIC_FLAG_TOP_FIELD_FIRST`

</td>
<td>



0x00000001

</td>
<td>



If set and it's an interlaced stream, top field is output first.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG2_PIC_FLAG_FRAME_PRED_DCT`

</td>
<td>



0x00000002

</td>
<td>



If set only frame-DCT and frame prediction are used.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG2_PIC_FLAG_CONCEALMENT_MV`

</td>
<td>



0x00000004

</td>
<td>



If set motion vectors are coded for intra macroblocks.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG2_PIC_FLAG_Q_SCALE_TYPE`

</td>
<td>



0x00000008

</td>
<td>



This flag affects the inverse quantization process.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG2_PIC_FLAG_INTRA_VLC`

</td>
<td>



0x00000010

</td>
<td>



This flag affects the decoding of transform coefficient data.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG2_PIC_FLAG_ALT_SCAN`

</td>
<td>



0x00000020

</td>
<td>



This flag affects the decoding of transform coefficient data.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG2_PIC_FLAG_REPEAT_FIRST`

</td>
<td>



0x00000040

</td>
<td>



This flag affects the decoding process of progressive frames.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG2_PIC_FLAG_PROGRESSIVE`

</td>
<td>



0x00000080

</td>
<td>



Indicates whether the current frame is progressive.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_MPEG2_QUANTISATION (struct)`**

  Specifies quantisation matrices, in zigzag scanning order, for the associated MPEG-2 slice data. This control is initialized by the kernel to the matrices default values. If a bitstream transmits a user-defined quantisation matrices load, applications are expected to use this control. Applications are also expected to set the control loading the default values, if the quantisation matrices need to be reset, for instance on a sequence header. This process is specified by section 6.3.7. "Quant matrix extension" of the specification.

<a id="c-v4l2_ctrl_mpeg2_quantisation"></a>



```c
v4l2_ctrl_mpeg2_quantisation
```

<!-- tabularcolumns: |p{0.8cm}|p{8.0cm}|p{8.5cm}| -->

<!-- Source LaTeX layout: \small -->


<table>
<caption>

struct v4l2\_ctrl\_mpeg2\_quantisation

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`intra_quantiser_matrix[64]`

</td>
<td>



The quantisation matrix coefficients for intra-coded frames, in zigzag scanning order. It is relevant for both luma and chroma components, although it can be superseded by the chroma-specific matrix for non-4:2:0 YUV formats.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`non_intra_quantiser_matrix[64]`

</td>
<td>



The quantisation matrix coefficients for non-intra-coded frames, in zigzag scanning order. It is relevant for both luma and chroma components, although it can be superseded by the chroma-specific matrix for non-4:2:0 YUV formats.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`chroma_intra_quantiser_matrix[64]`

</td>
<td>



The quantisation matrix coefficients for the chominance component of intra-coded frames, in zigzag scanning order. Only relevant for non-4:2:0 YUV formats.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`chroma_non_intra_quantiser_matrix[64]`

</td>
<td>



The quantisation matrix coefficients for the chrominance component of non-intra-coded frames, in zigzag scanning order. Only relevant for non-4:2:0 YUV formats.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-v4l2-codec-stateless-vp9"></a>

- **`V4L2_CID_STATELESS_VP9_COMPRESSED_HDR (struct)`**

  Stores VP9 probabilities updates as parsed from the current compressed frame header. A value of zero in an array element means no update of the relevant probability. Motion vector-related updates contain a new value or zero. All other updates contain values translated with inv\_map\_table\[\] (see 6.3.5 in [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>)).

<a id="c-v4l2_ctrl_vp9_compressed_hdr"></a>



```c
v4l2_ctrl_vp9_compressed_hdr
```

<!-- tabularcolumns: |p{1cm}|p{4.8cm}|p{11.4cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_vp9\_compressed\_hdr

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`tx_mode`

</td>
<td>



Specifies the TX mode. See [TX Mode](<#rst-vp9-tx-mode>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tx8[2][1]`

</td>
<td>



TX 8x8 probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tx16[2][2]`

</td>
<td>



TX 16x16 probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tx32[2][3]`

</td>
<td>



TX 32x32 probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`coef[4][2][2][6][6][3]`

</td>
<td>



Coefficient probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`skip[3]`

</td>
<td>



Skip probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`inter_mode[7][3]`

</td>
<td>



Inter prediction mode probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`interp_filter[4][2]`

</td>
<td>



Interpolation filter probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`is_inter[4]`

</td>
<td>



Is inter-block probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`comp_mode[5]`

</td>
<td>



Compound prediction mode probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`single_ref[5][2]`

</td>
<td>



Single reference probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`comp_ref[5]`

</td>
<td>



Compound reference probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`y_mode[4][9]`

</td>
<td>



Y prediction mode probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`uv_mode[10][9]`

</td>
<td>



UV prediction mode probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`partition[16][3]`

</td>
<td>



Partition probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.joint[3]`

</td>
<td>



Motion vector joint probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.sign[2]`

</td>
<td>



Motion vector sign probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.classes[2][10]`

</td>
<td>



Motion vector class probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.class0_bit[2]`

</td>
<td>



Motion vector class0 bit probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.bits[2][10]`

</td>
<td>



Motion vector bits probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.class0_fr[2][2][3]`

</td>
<td>



Motion vector class0 fractional bit probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.fr[2][3]`

</td>
<td>



Motion vector fractional bit probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.class0_hp[2]`

</td>
<td>



Motion vector class0 high precision fractional bit probabilities delta.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mv.hp[2]`

</td>
<td>



Motion vector high precision fractional bit probabilities delta.

</td>
</tr>
</tbody>
</table>

<a id="rst-vp9-tx-mode"></a>

`TX Mode`

<!-- tabularcolumns: |p{6.5cm}|p{0.5cm}|p{10.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_TX_MODE_ONLY_4X4`

</td>
<td>



0

</td>
<td>



Transform size is 4x4.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_TX_MODE_ALLOW_8X8`

</td>
<td>



1

</td>
<td>



Transform size can be up to 8x8.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_TX_MODE_ALLOW_16X16`

</td>
<td>



2

</td>
<td>



Transform size can be up to 16x16.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_TX_MODE_ALLOW_32X32`

</td>
<td>



3

</td>
<td>



transform size can be up to 32x32.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_TX_MODE_SELECT`

</td>
<td>



4

</td>
<td>



Bitstream contains the transform size for each block.

</td>
</tr>
</tbody>
</table>

See section '7.3.1 Tx mode semantics' of the [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>) specification for more details.

- **`V4L2_CID_STATELESS_VP9_FRAME (struct)`**

  Specifies the frame parameters for the associated VP9 frame decode request. This includes the necessary parameters for configuring a stateless hardware decoding pipeline for VP9. The bitstream parameters are defined according to [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>).

<a id="c-v4l2_ctrl_vp9_frame"></a>



```c
v4l2_ctrl_vp9_frame
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{4.7cm}|p{5.5cm}|p{7.1cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_vp9\_frame

</caption>
<tbody>
<tr>
<td>



struct `v4l2_vp9_loop_filter`

</td>
<td>



`lf`

</td>
<td>



Loop filter parameters. See struct `v4l2_vp9_loop_filter` for more details.

</td>
</tr>
<tr>
<td>



struct `v4l2_vp9_quantization`

</td>
<td>



`quant`

</td>
<td>



Quantization parameters. See `v4l2_vp9_quantization` for more details.

</td>
</tr>
<tr>
<td>



struct `v4l2_vp9_segmentation`

</td>
<td>



`seg`

</td>
<td>



Segmentation parameters. See `v4l2_vp9_segmentation` for more details.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



Combination of V4L2\_VP9\_FRAME\_FLAG\_\* flags. See [Frame Flags](<#rst-vp9-frame-flags>).

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`compressed_header_size`

</td>
<td>



Compressed header size in bytes.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`uncompressed_header_size`

</td>
<td>



Uncompressed header size in bytes.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`frame_width_minus_1`

</td>
<td>



Add 1 to get the frame width expressed in pixels. See section 7.2.3 in [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>).

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`frame_height_minus_1`

</td>
<td>



Add 1 to get the frame height expressed in pixels. See section 7.2.3 in [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>).

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`render_width_minus_1`

</td>
<td>



Add 1 to get the expected render width expressed in pixels. This is not used during the decoding process but might be used by HW scalers to prepare a frame that's ready for scanout. See section 7.2.4 in [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>).

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



render\_height\_minus\_1

</td>
<td>



Add 1 to get the expected render height expressed in pixels. This is not used during the decoding process but might be used by HW scalers to prepare a frame that's ready for scanout. See section 7.2.4 in [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>).

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`last_frame_ts`

</td>
<td>



"last" reference buffer timestamp. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`golden_frame_ts`

</td>
<td>



"golden" reference buffer timestamp. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`alt_frame_ts`

</td>
<td>



"alt" reference buffer timestamp. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ref_frame_sign_bias`

</td>
<td>



a bitfield specifying whether the sign bias is set for a given reference frame. See [Reference Frame Sign Bias](<#rst-vp9-ref-frame-sign-bias>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reset_frame_context`

</td>
<td>



specifies whether the frame context should be reset to default values. See [Reset Frame Context](<#rst-vp9-reset-frame-context>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`frame_context_idx`

</td>
<td>



Frame context that should be used/updated.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`profile`

</td>
<td>



VP9 profile. Can be 0, 1, 2 or 3.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`bit_depth`

</td>
<td>



Component depth in bits. Can be 8, 10 or 12. Note that not all profiles support 10 and/or 12 bits depths.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`interpolation_filter`

</td>
<td>



Specifies the filter selection used for performing inter prediction. See [Interpolation Filter](<#rst-vp9-interpolation-filter>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tile_cols_log2`

</td>
<td>



Specifies the base 2 logarithm of the width of each tile (where the width is measured in units of 8x8 blocks). Shall be less than or equal to 6.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tile_rows_log2`

</td>
<td>



Specifies the base 2 logarithm of the height of each tile (where the height is measured in units of 8x8 blocks).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reference_mode`

</td>
<td>



Specifies the type of inter prediction to be used. See [Reference Mode](<#rst-vp9-reference-mode>) for more details. Note that this is derived as part of the compressed header parsing process and for this reason should have been part of :c:type: `v4l2_ctrl_vp9_compressed_hdr` optional control. It is safe to set this value to zero if the driver does not require compressed headers.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[7]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-vp9-frame-flags"></a>

`Frame Flags`

<!-- tabularcolumns: |p{10.0cm}|p{1.2cm}|p{6.1cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_KEY_FRAME`

</td>
<td>



0x001

</td>
<td>



The frame is a key frame.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_SHOW_FRAME`

</td>
<td>



0x002

</td>
<td>



The frame should be displayed.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_ERROR_RESILIENT`

</td>
<td>



0x004

</td>
<td>



The decoding should be error resilient.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_INTRA_ONLY`

</td>
<td>



0x008

</td>
<td>



The frame does not reference other frames.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_ALLOW_HIGH_PREC_MV`

</td>
<td>



0x010

</td>
<td>



The frame can use high precision motion vectors.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_REFRESH_FRAME_CTX`

</td>
<td>



0x020

</td>
<td>



Frame context should be updated after decoding.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_PARALLEL_DEC_MODE`

</td>
<td>



0x040

</td>
<td>



Parallel decoding is used.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING`

</td>
<td>



0x080

</td>
<td>



Vertical subsampling is enabled.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING`

</td>
<td>



0x100

</td>
<td>



Horizontal subsampling is enabled.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_FRAME_FLAG_COLOR_RANGE_FULL_SWING`

</td>
<td>



0x200

</td>
<td>



The full UV range is used.

</td>
</tr>
</tbody>
</table>

<a id="rst-vp9-ref-frame-sign-bias"></a>

`Reference Frame Sign Bias`

<!-- tabularcolumns: |p{7.0cm}|p{1.2cm}|p{9.1cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_SIGN_BIAS_LAST`

</td>
<td>



0x1

</td>
<td>



Sign bias is set for the last reference frame.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SIGN_BIAS_GOLDEN`

</td>
<td>



0x2

</td>
<td>



Sign bias is set for the golden reference frame.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SIGN_BIAS_ALT`

</td>
<td>



0x2

</td>
<td>



Sign bias is set for the alt reference frame.

</td>
</tr>
</tbody>
</table>

<a id="rst-vp9-reset-frame-context"></a>

`Reset Frame Context`

<!-- tabularcolumns: |p{7.0cm}|p{1.2cm}|p{9.1cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_RESET_FRAME_CTX_NONE`

</td>
<td>



0

</td>
<td>



Do not reset any frame context.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_RESET_FRAME_CTX_SPEC`

</td>
<td>



1

</td>
<td>



Reset the frame context pointed to by `v4l2_ctrl_vp9_frame`.frame\_context\_idx.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_RESET_FRAME_CTX_ALL`

</td>
<td>



2

</td>
<td>



Reset all frame contexts.

</td>
</tr>
</tbody>
</table>

See section '7.2 Uncompressed header semantics' of the [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>) specification for more details.

<a id="rst-vp9-interpolation-filter"></a>

`Interpolation Filter`

<!-- tabularcolumns: |p{9.0cm}|p{1.2cm}|p{7.1cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_INTERP_FILTER_EIGHTTAP`

</td>
<td>



0

</td>
<td>



Eight tap filter.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_INTERP_FILTER_EIGHTTAP_SMOOTH`

</td>
<td>



1

</td>
<td>



Eight tap smooth filter.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_INTERP_FILTER_EIGHTTAP_SHARP`

</td>
<td>



2

</td>
<td>



Eeight tap sharp filter.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_INTERP_FILTER_BILINEAR`

</td>
<td>



3

</td>
<td>



Bilinear filter.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_INTERP_FILTER_SWITCHABLE`

</td>
<td>



4

</td>
<td>



Filter selection is signaled at the block level.

</td>
</tr>
</tbody>
</table>

See section '7.2.7 Interpolation filter semantics' of the [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>) specification for more details.

<a id="rst-vp9-reference-mode"></a>

`Reference Mode`

<!-- tabularcolumns: |p{9.6cm}|p{0.5cm}|p{7.2cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_REFERENCE_MODE_SINGLE_REFERENCE`

</td>
<td>



0

</td>
<td>



Indicates that all the inter blocks use only a single reference frame to generate motion compensated prediction.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_REFERENCE_MODE_COMPOUND_REFERENCE`

</td>
<td>



1

</td>
<td>



Requires all the inter blocks to use compound mode. Single reference frame prediction is not allowed.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_REFERENCE_MODE_SELECT`

</td>
<td>



2

</td>
<td>



Allows each individual inter block to select between single and compound prediction modes.

</td>
</tr>
</tbody>
</table>

See section '7.3.6 Frame reference mode semantics' of the [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>) specification for more details.

<a id="c-v4l2_vp9_segmentation"></a>



```c
v4l2_vp9_segmentation
```

Encodes the quantization parameters. See section '7.2.10 Segmentation params syntax' of the [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>) specification for more details.

<!-- tabularcolumns: |p{0.8cm}|p{5cm}|p{11.4cm}| -->


<table>
<caption>

struct v4l2\_vp9\_segmentation

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`feature_data[8][4]`

</td>
<td>



Data attached to each feature. Data entry is only valid if the feature is enabled. The array shall be indexed with segment number as the first dimension (0..7) and one of V4L2\_VP9\_SEG\_\* as the second dimension. See [Segment Feature IDs](<#rst-vp9-segment-feature>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`feature_enabled[8]`

</td>
<td>



Bitmask defining which features are enabled in each segment. The value for each segment is a combination of V4L2\_VP9\_SEGMENT\_FEATURE\_ENABLED(id) values where id is one of V4L2\_VP9\_SEG\_\*. See [Segment Feature IDs](<#rst-vp9-segment-feature>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tree_probs[7]`

</td>
<td>



Specifies the probability values to be used when decoding a Segment-ID. See '5.15 Segmentation map' section of [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`pred_probs[3]`

</td>
<td>



Specifies the probability values to be used when decoding a Predicted-Segment-ID. See '6.4.14 Get segment id syntax' section of [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



Combination of V4L2\_VP9\_SEGMENTATION\_FLAG\_\* flags. See [Segmentation Flags](<#rst-vp9-segmentation-flags>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[5]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-vp9-segment-feature"></a>

`Segment feature IDs`

<!-- tabularcolumns: |p{6.0cm}|p{1cm}|p{10.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_SEG_LVL_ALT_Q`

</td>
<td>



0

</td>
<td>



Quantizer segment feature.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SEG_LVL_ALT_L`

</td>
<td>



1

</td>
<td>



Loop filter segment feature.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SEG_LVL_REF_FRAME`

</td>
<td>



2

</td>
<td>



Reference frame segment feature.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SEG_LVL_SKIP`

</td>
<td>



3

</td>
<td>



Skip segment feature.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SEG_LVL_MAX`

</td>
<td>



4

</td>
<td>



Number of segment features.

</td>
</tr>
</tbody>
</table>

<a id="rst-vp9-segmentation-flags"></a>

`Segmentation Flags`

<!-- tabularcolumns: |p{10.6cm}|p{0.8cm}|p{5.9cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_SEGMENTATION_FLAG_ENABLED`

</td>
<td>



0x01

</td>
<td>



Indicates that this frame makes use of the segmentation tool.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SEGMENTATION_FLAG_UPDATE_MAP`

</td>
<td>



0x02

</td>
<td>



Indicates that the segmentation map should be updated during the decoding of this frame.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SEGMENTATION_FLAG_TEMPORAL_UPDATE`

</td>
<td>



0x04

</td>
<td>



Indicates that the updates to the segmentation map are coded relative to the existing segmentation map.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SEGMENTATION_FLAG_UPDATE_DATA`

</td>
<td>



0x08

</td>
<td>



Indicates that new parameters are about to be specified for each segment.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_SEGMENTATION_FLAG_ABS_OR_DELTA_UPDATE`

</td>
<td>



0x10

</td>
<td>



Indicates that the segmentation parameters represent the actual values to be used.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_vp9_quantization"></a>



```c
v4l2_vp9_quantization
```

Encodes the quantization parameters. See section '7.2.9 Quantization params syntax' of the VP9 specification for more details.

<!-- tabularcolumns: |p{0.8cm}|p{4cm}|p{12.4cm}| -->


<table>
<caption>

struct v4l2\_vp9\_quantization

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`base_q_idx`

</td>
<td>



Indicates the base frame qindex.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`delta_q_y_dc`

</td>
<td>



Indicates the Y DC quantizer relative to base\_q\_idx.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`delta_q_uv_dc`

</td>
<td>



Indicates the UV DC quantizer relative to base\_q\_idx.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`delta_q_uv_ac`

</td>
<td>



Indicates the UV AC quantizer relative to base\_q\_idx.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[4]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_vp9_loop_filter"></a>



```c
v4l2_vp9_loop_filter
```

This structure contains all loop filter related parameters. See sections '7.2.8 Loop filter semantics' of the [vp9](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vp9-1>) specification for more details.

<!-- tabularcolumns: |p{0.8cm}|p{4cm}|p{12.4cm}| -->


<table>
<caption>

struct v4l2\_vp9\_loop\_filter

</caption>
<tbody>
<tr>
<td>



\_\_s8

</td>
<td>



`ref_deltas[4]`

</td>
<td>



Contains the adjustment needed for the filter level based on the chosen reference frame.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`mode_deltas[2]`

</td>
<td>



Contains the adjustment needed for the filter level based on the chosen mode.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`level`

</td>
<td>



Indicates the loop filter strength.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`sharpness`

</td>
<td>



Indicates the sharpness level.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



Combination of V4L2\_VP9\_LOOP\_FILTER\_FLAG\_\* flags. See [Loop Filter Flags](<#rst-vp9-loop-filter-flags>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[7]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-vp9-loop-filter-flags"></a>

`Loop Filter Flags`

<!-- tabularcolumns: |p{9.6cm}|p{0.5cm}|p{7.2cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_VP9_LOOP_FILTER_FLAG_DELTA_ENABLED`

</td>
<td>



0x1

</td>
<td>



When set, the filter level depends on the mode and reference frame used to predict a block.

</td>
</tr>
<tr>
<td>



`V4L2_VP9_LOOP_FILTER_FLAG_DELTA_UPDATE`

</td>
<td>



0x2

</td>
<td>



When set, the bitstream contains additional syntax elements that specify which mode and reference frame deltas are to be updated.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-codec-stateless-hevc"></a>

- **`V4L2_CID_STATELESS_HEVC_SPS (struct)`**

  Specifies the Sequence Parameter Set fields (as extracted from the bitstream) for the associated HEVC slice data. These bitstream parameters are defined according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>). They are described in section 7.4.3.2 "Sequence parameter set RBSP semantics" of the specification.

<a id="c-v4l2_ctrl_hevc_sps"></a>



```c
v4l2_ctrl_hevc_sps
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{1.2cm}|p{9.2cm}|p{6.9cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_hevc\_sps

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`video_parameter_set_id`

</td>
<td>



Specifies the value of the vps\_video\_parameter\_set\_id of the active VPS as described in section "7.4.3.2.1 General sequence parameter set RBSP semantics" of H.265 specifications.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`seq_parameter_set_id`

</td>
<td>



Provides an identifier for the SPS for reference by other syntax elements as described in section "7.4.3.2.1 General sequence parameter set RBSP semantics" of H.265 specifications.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`pic_width_in_luma_samples`

</td>
<td>



Specifies the width of each decoded picture in units of luma samples.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`pic_height_in_luma_samples`

</td>
<td>



Specifies the height of each decoded picture in units of luma samples.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`bit_depth_luma_minus8`

</td>
<td>



This value plus 8 specifies the bit depth of the samples of the luma array.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`bit_depth_chroma_minus8`

</td>
<td>



This value plus 8 specifies the bit depth of the samples of the chroma arrays.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_max_pic_order_cnt_lsb_minus4`

</td>
<td>



Specifies the value of the variable MaxPicOrderCntLsb.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`sps_max_dec_pic_buffering_minus1`

</td>
<td>



This value plus 1 specifies the maximum required size of the decoded picture buffer for the coded video sequence (CVS).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`sps_max_num_reorder_pics`

</td>
<td>



Indicates the maximum allowed number of pictures.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`sps_max_latency_increase_plus1`

</td>
<td>



Used to signal MaxLatencyPictures, which indicates the maximum number of pictures that can precede any picture in output order and follow that picture in decoding order.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_min_luma_coding_block_size_minus3`

</td>
<td>



This value plus 3 specifies the minimum luma coding block size.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_diff_max_min_luma_coding_block_size`

</td>
<td>



Specifies the difference between the maximum and minimum luma coding block size.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_min_luma_transform_block_size_minus2`

</td>
<td>



This value plus 2 specifies the minimum luma transform block size.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_diff_max_min_luma_transform_block_size`

</td>
<td>



Specifies the difference between the maximum and minimum luma transform block size.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`max_transform_hierarchy_depth_inter`

</td>
<td>



Specifies the maximum hierarchy depth for transform units of coding units coded in inter prediction mode.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`max_transform_hierarchy_depth_intra`

</td>
<td>



Specifies the maximum hierarchy depth for transform units of coding units coded in intra prediction mode.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`pcm_sample_bit_depth_luma_minus1`

</td>
<td>



This value plus 1 specifies the number of bits used to represent each of PCM sample values of the luma component.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`pcm_sample_bit_depth_chroma_minus1`

</td>
<td>



Specifies the number of bits used to represent each of PCM sample values of the chroma components.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_min_pcm_luma_coding_block_size_minus3`

</td>
<td>



Plus 3 specifies the minimum size of coding blocks.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_diff_max_min_pcm_luma_coding_block_size`

</td>
<td>



Specifies the difference between the maximum and minimum size of coding blocks.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_short_term_ref_pic_sets`

</td>
<td>



Specifies the number of st\_ref\_pic\_set() syntax structures included in the SPS.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_long_term_ref_pics_sps`

</td>
<td>



Specifies the number of candidate long-term reference pictures that are specified in the SPS.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`chroma_format_idc`

</td>
<td>



Specifies the chroma sampling.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`sps_max_sub_layers_minus1`

</td>
<td>



This value plus 1 specifies the maximum number of temporal sub-layers.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`flags`

</td>
<td>



See [Sequence Parameter Set Flags](<#rst-hevc-sps-flags>)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-hevc-sps-flags"></a>

`Sequence Parameter Set Flags`

<!-- Source LaTeX layout: \small -->


<table>
<tbody>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_SEPARATE_COLOUR_PLANE`

</td>
<td>



0x00000001

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED`

</td>
<td>



0x00000002

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_AMP_ENABLED`

</td>
<td>



0x00000004

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_SAMPLE_ADAPTIVE_OFFSET`

</td>
<td>



0x00000008

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_PCM_ENABLED`

</td>
<td>



0x00000010

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_PCM_LOOP_FILTER_DISABLED`

</td>
<td>



0x00000020

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT`

</td>
<td>



0x00000040

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED`

</td>
<td>



0x00000080

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SPS_FLAG_STRONG_INTRA_SMOOTHING_ENABLED`

</td>
<td>



0x00000100

</td>
<td>





</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_HEVC_PPS (struct)`**

  Specifies the Picture Parameter Set fields (as extracted from the bitstream) for the associated HEVC slice data. These bitstream parameters are defined according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>). They are described in section 7.4.3.3 "Picture parameter set RBSP semantics" of the specification.

<a id="c-v4l2_ctrl_hevc_pps"></a>



```c
v4l2_ctrl_hevc_pps
```

<!-- tabularcolumns: |p{1.2cm}|p{8.6cm}|p{7.5cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_hevc\_pps

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`pic_parameter_set_id`

</td>
<td>



Identifies the PPS for reference by other syntax elements.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_extra_slice_header_bits`

</td>
<td>



Specifies the number of extra slice header bits that are present in the slice header RBSP for coded pictures referring to the PPS.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_idx_l0_default_active_minus1`

</td>
<td>



This value plus 1 specifies the inferred value of num\_ref\_idx\_l0\_active\_minus1.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_idx_l1_default_active_minus1`

</td>
<td>



This value plus 1 specifies the inferred value of num\_ref\_idx\_l1\_active\_minus1.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`init_qp_minus26`

</td>
<td>



This value plus 26 specifies the initial value of SliceQp Y for each slice referring to the PPS.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`diff_cu_qp_delta_depth`

</td>
<td>



Specifies the difference between the luma coding tree block size and the minimum luma coding block size of coding units that convey cu\_qp\_delta\_abs and cu\_qp\_delta\_sign\_flag.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`pps_cb_qp_offset`

</td>
<td>



Specifies the offsets to the luma quantization parameter Cb.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`pps_cr_qp_offset`

</td>
<td>



Specifies the offsets to the luma quantization parameter Cr.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_tile_columns_minus1`

</td>
<td>



This value plus 1 specifies the number of tile columns partitioning the picture.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_tile_rows_minus1`

</td>
<td>



This value plus 1 specifies the number of tile rows partitioning the picture.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`column_width_minus1[20]`

</td>
<td>



This value plus 1 specifies the width of the i-th tile column in units of coding tree blocks.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`row_height_minus1[22]`

</td>
<td>



This value plus 1 specifies the height of the i-th tile row in units of coding tree blocks.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`pps_beta_offset_div2`

</td>
<td>



Specifies the default deblocking parameter offsets for beta divided by 2.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`pps_tc_offset_div2`

</td>
<td>



Specifies the default deblocking parameter offsets for tC divided by 2.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`log2_parallel_merge_level_minus2`

</td>
<td>



This value plus 2 specifies the value of the variable Log2ParMrgLevel.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`padding[4]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`flags`

</td>
<td>



See [Picture Parameter Set Flags](<#rst-hevc-pps-flags>)

</td>
</tr>
</tbody>
</table>

<a id="rst-hevc-pps-flags"></a>

`Picture Parameter Set Flags`

<!-- Source LaTeX layout: \small -->


<table>
<tbody>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT_ENABLED`

</td>
<td>



0x00000001

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_OUTPUT_FLAG_PRESENT`

</td>
<td>



0x00000002

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_SIGN_DATA_HIDING_ENABLED`

</td>
<td>



0x00000004

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_CABAC_INIT_PRESENT`

</td>
<td>



0x00000008

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_CONSTRAINED_INTRA_PRED`

</td>
<td>



0x00000010

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_TRANSFORM_SKIP_ENABLED`

</td>
<td>



0x00000020

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED`

</td>
<td>



0x00000040

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_PPS_SLICE_CHROMA_QP_OFFSETS_PRESENT`

</td>
<td>



0x00000080

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_WEIGHTED_PRED`

</td>
<td>



0x00000100

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_WEIGHTED_BIPRED`

</td>
<td>



0x00000200

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_TRANSQUANT_BYPASS_ENABLED`

</td>
<td>



0x00000400

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_TILES_ENABLED`

</td>
<td>



0x00000800

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_ENTROPY_CODING_SYNC_ENABLED`

</td>
<td>



0x00001000

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED`

</td>
<td>



0x00002000

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_PPS_LOOP_FILTER_ACROSS_SLICES_ENABLED`

</td>
<td>



0x00004000

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_OVERRIDE_ENABLED`

</td>
<td>



0x00008000

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER`

</td>
<td>



0x00010000

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT`

</td>
<td>



0x00020000

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT`

</td>
<td>



0x00040000

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT`

</td>
<td>



0x00080000

</td>
<td>



Specifies the presence of deblocking filter control syntax elements in the PPS

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING`

</td>
<td>



0x00100000

</td>
<td>



Specifies that tile column boundaries and likewise tile row boundaries are distributed uniformly across the picture

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_HEVC_SLICE_PARAMS (struct)`**

  Specifies various slice-specific parameters, especially from the NAL unit header, general slice segment header and weighted prediction parameter parts of the bitstream. These bitstream parameters are defined according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>). They are described in section 7.4.7 "General slice segment header semantics" of the specification. This control is a dynamically sized 1-dimensional array, V4L2\_CTRL\_FLAG\_DYNAMIC\_ARRAY flag must be set when using it.

<a id="c-v4l2_ctrl_hevc_slice_params"></a>



```c
v4l2_ctrl_hevc_slice_params
```

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{5.4cm}|p{6.8cm}|p{5.1cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_hevc\_slice\_params

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`bit_size`

</td>
<td>



Size (in bits) of the current slice data.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`data_byte_offset`

</td>
<td>



Offset (in byte) to the video data in the current slice data.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`num_entry_point_offsets`

</td>
<td>



Specifies the number of entry point offset syntax elements in the slice header. When the driver supports it, the `V4L2_CID_STATELESS_HEVC_ENTRY_POINT_OFFSETS` must be set.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`nal_unit_type`

</td>
<td>



Specifies the coding type of the slice (B, P or I).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`nuh_temporal_id_plus1`

</td>
<td>



Minus 1 specifies a temporal identifier for the NAL unit.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`slice_type`

</td>
<td>



(V4L2\_HEVC\_SLICE\_TYPE\_I, V4L2\_HEVC\_SLICE\_TYPE\_P or V4L2\_HEVC\_SLICE\_TYPE\_B).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`colour_plane_id`

</td>
<td>



Specifies the colour plane associated with the current slice.

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`slice_pic_order_cnt`

</td>
<td>



Specifies the picture order count.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_idx_l0_active_minus1`

</td>
<td>



This value plus 1 specifies the maximum reference index for reference picture list 0 that may be used to decode the slice.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_ref_idx_l1_active_minus1`

</td>
<td>



This value plus 1 specifies the maximum reference index for reference picture list 1 that may be used to decode the slice.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`collocated_ref_idx`

</td>
<td>



Specifies the reference index of the collocated picture used for temporal motion vector prediction.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`five_minus_max_num_merge_cand`

</td>
<td>



Specifies the maximum number of merging motion vector prediction candidates supported in the slice subtracted from 5.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_qp_delta`

</td>
<td>



Specifies the initial value of QpY to be used for the coding blocks in the slice.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_cb_qp_offset`

</td>
<td>



Specifies a difference to be added to the value of pps\_cb\_qp\_offset.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_cr_qp_offset`

</td>
<td>



Specifies a difference to be added to the value of pps\_cr\_qp\_offset.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_act_y_qp_offset`

</td>
<td>



Specifies the offset to the luma of quantization parameter qP derived in section 8.6.2

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_act_cb_qp_offset`

</td>
<td>



Specifies the offset to the cb of quantization parameter qP derived in section 8.6.2

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_act_cr_qp_offset`

</td>
<td>



Specifies the offset to the cr of quantization parameter qP derived in section 8.6.2

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_beta_offset_div2`

</td>
<td>



Specifies the deblocking parameter offsets for beta divided by 2.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`slice_tc_offset_div2`

</td>
<td>



Specifies the deblocking parameter offsets for tC divided by 2.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`pic_struct`

</td>
<td>



Indicates whether a picture should be displayed as a frame or as one or more fields.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`slice_segment_addr`

</td>
<td>



Specifies the address of the first coding tree block in the slice segment.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



The list of L0 reference elements as indices in the DPB.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



The list of L1 reference elements as indices in the DPB.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`short_term_ref_pic_set_size`

</td>
<td>



Specifies the size, in bits, of the short-term reference picture set, described as st\_ref\_pic\_set() in the specification, included in the slice header or SPS (section 7.3.6.1).

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`long_term_ref_pic_set_size`

</td>
<td>



Specifies the size, in bits, of the long-term reference picture set include in the slice header or SPS. It is the number of bits in the conditional block if(long\_term\_ref\_pics\_present\_flag) in section 7.3.6.1 of the specification.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`padding`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



struct `v4l2_hevc_pred_weight_table`

</td>
<td>



`pred_weight_table`

</td>
<td>



The prediction weight coefficients for inter-picture prediction.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`flags`

</td>
<td>



See [Slice Parameters Flags](<#rst-hevc-slice-params-flags>)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-hevc-slice-params-flags"></a>

`Slice Parameters Flags`

<!-- Source LaTeX layout: \scriptsize -->


<table>
<tbody>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_LUMA`

</td>
<td>



0x00000001

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_CHROMA`

</td>
<td>



0x00000002

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED`

</td>
<td>



0x00000004

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_MVD_L1_ZERO`

</td>
<td>



0x00000008

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_CABAC_INIT`

</td>
<td>



0x00000010

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_COLLOCATED_FROM_L0`

</td>
<td>



0x00000020

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_USE_INTEGER_MV`

</td>
<td>



0x00000040

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_DEBLOCKING_FILTER_DISABLED`

</td>
<td>



0x00000080

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED`

</td>
<td>



0x00000100

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT`

</td>
<td>



0x00000200

</td>
<td>





</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_HEVC_ENTRY_POINT_OFFSETS (integer)`**

  Specifies entry point offsets in bytes. This control is a dynamically sized array. The number of entry point offsets is reported by the `elems` field. This bitstream parameter is defined according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>). They are described in section 7.4.7.1 "General slice segment header semantics" of the specification. When multiple slices are submitted in a request, the length of this array must be the sum of num\_entry\_point\_offsets of all the slices in the request.

- **`V4L2_CID_STATELESS_HEVC_SCALING_MATRIX (struct)`**

  Specifies the HEVC scaling matrix parameters used for the scaling process for transform coefficients. These matrix and parameters are defined according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>). They are described in section 7.4.5 "Scaling list data semantics" of the specification.

<a id="c-v4l2_ctrl_hevc_scaling_matrix"></a>



```c
v4l2_ctrl_hevc_scaling_matrix
```

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{5.4cm}|p{6.8cm}|p{5.1cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_hevc\_scaling\_matrix

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`scaling_list_4x4[6][16]`

</td>
<td>



Scaling list is used for the scaling process for transform coefficients. The values on each scaling list are expected in raster scan order.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`scaling_list_8x8[6][64]`

</td>
<td>



Scaling list is used for the scaling process for transform coefficients. The values on each scaling list are expected in raster scan order.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`scaling_list_16x16[6][64]`

</td>
<td>



Scaling list is used for the scaling process for transform coefficients. The values on each scaling list are expected in raster scan order.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`scaling_list_32x32[2][64]`

</td>
<td>



Scaling list is used for the scaling process for transform coefficients. The values on each scaling list are expected in raster scan order.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`scaling_list_dc_coef_16x16[6]`

</td>
<td>



Scaling list is used for the scaling process for transform coefficients. The values on each scaling list are expected in raster scan order.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`scaling_list_dc_coef_32x32[2]`

</td>
<td>



Scaling list is used for the scaling process for transform coefficients. The values on each scaling list are expected in raster scan order.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="c-v4l2_hevc_dpb_entry"></a>



```c
v4l2_hevc_dpb_entry
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{1.0cm}|p{4.2cm}|p{12.1cm}| -->


<table>
<caption>

struct v4l2\_hevc\_dpb\_entry

</caption>
<tbody>
<tr>
<td>



\_\_u64

</td>
<td>



`timestamp`

</td>
<td>



Timestamp of the V4L2 capture buffer to use as reference, used with B-coded and P-coded frames. The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



Long term flag for the reference frame (V4L2\_HEVC\_DPB\_ENTRY\_LONG\_TERM\_REFERENCE). The flag is set as described in the ITU HEVC specification chapter "8.3.2 Decoding process for reference picture set".

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`field_pic`

</td>
<td>



Whether the reference is a field picture or a frame. See [HEVC dpb field pic Flags](<#rst-hevc-dpb-field-pic-flags>)

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`pic_order_cnt_val`

</td>
<td>



The picture order count of the current picture.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`padding[2]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-hevc-dpb-field-pic-flags"></a>

`HEVC dpb field pic Flags`

<!-- Source LaTeX layout: \scriptsize -->


<table>
<tbody>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_FRAME`

</td>
<td>



0

</td>
<td>



(progressive) Frame

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_TOP_FIELD`

</td>
<td>



1

</td>
<td>



Top field

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_FIELD`

</td>
<td>



2

</td>
<td>



Bottom field

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_TOP_BOTTOM`

</td>
<td>



3

</td>
<td>



Top field, bottom field, in that order

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_TOP`

</td>
<td>



4

</td>
<td>



Bottom field, top field, in that order

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_TOP_BOTTOM_TOP`

</td>
<td>



5

</td>
<td>



Top field, bottom field, top field repeated, in that order

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM`

</td>
<td>



6

</td>
<td>



Bottom field, top field, bottom field repeated, in that order

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_FRAME_DOUBLING`

</td>
<td>



7

</td>
<td>



Frame doubling

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_FRAME_TRIPLING`

</td>
<td>



8

</td>
<td>



Frame tripling

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_TOP_PAIRED_PREVIOUS_BOTTOM`

</td>
<td>



9

</td>
<td>



Top field paired with previous bottom field in output order

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_PAIRED_PREVIOUS_TOP`

</td>
<td>



10

</td>
<td>



Bottom field paired with previous top field in output order

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_TOP_PAIRED_NEXT_BOTTOM`

</td>
<td>



11

</td>
<td>



Top field paired with next bottom field in output order

</td>
</tr>
<tr>
<td>



`V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_PAIRED_NEXT_TOP`

</td>
<td>



12

</td>
<td>



Bottom field paired with next top field in output order

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_hevc_pred_weight_table"></a>



```c
v4l2_hevc_pred_weight_table
```

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{0.8cm}|p{10.6cm}|p{5.9cm}| -->


<table>
<caption>

struct v4l2\_hevc\_pred\_weight\_table

</caption>
<tbody>
<tr>
<td>



\_\_s8

</td>
<td>



`delta_luma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



The difference of the weighting factor applied to the luma prediction value for list 0.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`luma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



The additive offset applied to the luma prediction value for list 0.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`delta_chroma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]`

</td>
<td>



The difference of the weighting factor applied to the chroma prediction value for list 0.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`chroma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]`

</td>
<td>



The difference of the additive offset applied to the chroma prediction values for list 0.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`delta_luma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



The difference of the weighting factor applied to the luma prediction value for list 1.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`luma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



The additive offset applied to the luma prediction value for list 1.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`delta_chroma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]`

</td>
<td>



The difference of the weighting factor applied to the chroma prediction value for list 1.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`chroma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]`

</td>
<td>



The difference of the additive offset applied to the chroma prediction values for list 1.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`luma_log2_weight_denom`

</td>
<td>



The base 2 logarithm of the denominator for all luma weighting factors.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`delta_chroma_log2_weight_denom`

</td>
<td>



The difference of the base 2 logarithm of the denominator for all chroma weighting factors.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`padding[6]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_HEVC_DECODE_MODE (enum)`**

  Specifies the decoding mode to use. Currently exposes slice-based and frame-based decoding but new modes might be added later on. This control is used as a modifier for V4L2\_PIX\_FMT\_HEVC\_SLICE pixel format. Applications that support V4L2\_PIX\_FMT\_HEVC\_SLICE are required to set this control in order to specify the decoding mode that is expected for the buffer. Drivers may expose a single or multiple decoding modes, depending on what they can support.

<a id="c-v4l2_stateless_hevc_decode_mode"></a>



```c
v4l2_stateless_hevc_decode_mode
```

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{9.4cm}|p{0.6cm}|p{7.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_STATELESS_HEVC_DECODE_MODE_SLICE_BASED`

</td>
<td>



0

</td>
<td>



Decoding is done at the slice granularity. The OUTPUT buffer must contain a single slice.

</td>
</tr>
<tr>
<td>



`V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED`

</td>
<td>



1

</td>
<td>



Decoding is done at the frame granularity. The OUTPUT buffer must contain all slices needed to decode the frame.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_STATELESS_HEVC_START_CODE (enum)`**

  Specifies the HEVC slice start code expected for each slice. This control is used as a modifier for V4L2\_PIX\_FMT\_HEVC\_SLICE pixel format. Applications that support V4L2\_PIX\_FMT\_HEVC\_SLICE are required to set this control in order to specify the start code that is expected for the buffer. Drivers may expose a single or multiple start codes, depending on what they can support.

<a id="c-v4l2_stateless_hevc_start_code"></a>



```c
v4l2_stateless_hevc_start_code
```

<!-- tabularcolumns: |p{9.2cm}|p{0.6cm}|p{7.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_STATELESS_HEVC_START_CODE_NONE`

</td>
<td>



0

</td>
<td>



Selecting this value specifies that HEVC slices are passed to the driver without any start code. The bitstream data should be according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>) 7.3.1.1 General NAL unit syntax, hence contains emulation prevention bytes when required.

</td>
</tr>
<tr>
<td>



`V4L2_STATELESS_HEVC_START_CODE_ANNEX_B`

</td>
<td>



1

</td>
<td>



Selecting this value specifies that HEVC slices are expected to be prefixed by Annex B start codes. According to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>) valid start codes can be 3-bytes 0x000001 or 4-bytes 0x00000001.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_BASELAYER_PRIORITY_ID (integer)`**

  Specifies a priority identifier for the NAL unit, which will be applied to the base layer. By default this value is set to 0 for the base layer, and the next layer will have the priority ID assigned as 1, 2, 3 and so on. The video encoder can't decide the priority id to be applied to a layer, so this has to come from client. This is applicable to H264 and valid Range is from 0 to 63. Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.

- **`V4L2_CID_MPEG_VIDEO_LTR_COUNT (integer)`**

  Specifies the maximum number of Long Term Reference (LTR) frames at any given time that the encoder can keep. This is applicable to the H264 and HEVC encoders.

- **`V4L2_CID_MPEG_VIDEO_FRAME_LTR_INDEX (integer)`**

  After setting this control the frame that will be queued next will be marked as a Long Term Reference (LTR) frame and given this LTR index which ranges from 0 to LTR\_COUNT-1. This is applicable to the H264 and HEVC encoders. Source Rec. ITU-T H.264 (06/2019); Table 7.9

- **`V4L2_CID_MPEG_VIDEO_USE_LTR_FRAMES (bitmask)`**

  Specifies the Long Term Reference (LTR) frame(s) to be used for encoding the next frame queued after setting this control. This provides a bitmask which consists of bits \[0, LTR\_COUNT-1\]. This is applicable to the H264 and HEVC encoders.

- **`V4L2_CID_STATELESS_HEVC_DECODE_PARAMS (struct)`**

  Specifies various decode parameters, especially the references picture order count (POC) for all the lists (short, long, before, current, after) and the number of entries for each of them. These parameters are defined according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>). They are described in section 8.3 "Slice decoding process" of the specification.

<a id="c-v4l2_ctrl_hevc_decode_params"></a>



```c
v4l2_ctrl_hevc_decode_params
```


<table>
<caption>

struct v4l2\_ctrl\_hevc\_decode\_params

</caption>
<tbody>
<tr>
<td>



\_\_s32

</td>
<td>



`pic_order_cnt_val`

</td>
<td>



PicOrderCntVal as described in section 8.3.1 "Decoding process for picture order count" of the specification.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`short_term_ref_pic_set_size`

</td>
<td>



Specifies the size, in bits, of the short-term reference picture set, of the first slice described as st\_ref\_pic\_set() in the specification, included in the slice header or SPS (section 7.3.6.1).

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`long_term_ref_pic_set_size`

</td>
<td>



Specifies the size, in bits, of the long-term reference picture set, of the first slice included in the slice header or SPS. It is the number of bits in the conditional block if(long\_term\_ref\_pics\_present\_flag) in section 7.3.6.1 of the specification.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_active_dpb_entries`

</td>
<td>



The number of entries in `dpb`.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_poc_st_curr_before`

</td>
<td>



The number of reference pictures in the short-term set that come before the current frame.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_poc_st_curr_after`

</td>
<td>



The number of reference pictures in the short-term set that come after the current frame.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_poc_lt_curr`

</td>
<td>



The number of reference pictures in the long-term set.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



PocStCurrBefore as described in section 8.3.2 "Decoding process for reference picture set": provides the index of the short term before references in DPB array.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



PocStCurrAfter as described in section 8.3.2 "Decoding process for reference picture set": provides the index of the short term after references in DPB array.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



PocLtCurr as described in section 8.3.2 "Decoding process for reference picture set": provides the index of the long term references in DPB array.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_delta_pocs_of_ref_rps_idx`

</td>
<td>



When the short\_term\_ref\_pic\_set\_sps\_flag in the slice header is equal to 0, it is the same as the derived value NumDeltaPocs\[RefRpsIdx\]. It can be used to parse the RPS data in slice headers instead of skipping it with @short\_term\_ref\_pic\_set\_size. When the value of short\_term\_ref\_pic\_set\_sps\_flag in the slice header is equal to 1, num\_delta\_pocs\_of\_ref\_rps\_idx shall be set to 0.

</td>
</tr>
<tr>
<td>



struct `v4l2_hevc_dpb_entry`

</td>
<td>



`dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`

</td>
<td>



The decoded picture buffer, for meta-data about reference frames.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`flags`

</td>
<td>



See [Decode Parameters Flags](<#rst-hevc-decode-params-flags>)

</td>
</tr>
</tbody>
</table>

<a id="rst-hevc-decode-params-flags"></a>

`Decode Parameters Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_HEVC_DECODE_PARAM_FLAG_IRAP_PIC`

</td>
<td>



0x00000001

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC`

</td>
<td>



0x00000002

</td>
<td>





</td>
</tr>
<tr>
<td>



`V4L2_HEVC_DECODE_PARAM_FLAG_NO_OUTPUT_OF_PRIOR`

</td>
<td>



0x00000004

</td>
<td>





</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_STATELESS_HEVC_EXT_SPS_LT_RPS (struct)`**

  Subset of the `v4l2_ctrl_hevc_sps` control. It extends it with the list of Long-term reference sets parameters. These parameters are defined according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>). They are described in section 7.4.3.2.1 "General sequence parameter set RBSP semantics" of the specification. This control is a dynamically sized 1-dimensional array. The values in the array should be ignored when either num\_long\_term\_ref\_pics\_sps is 0 or the V4L2\_HEVC\_SPS\_FLAG\_LONG\_TERM\_REF\_PICS\_PRESENT flag is not set in `v4l2_ctrl_hevc_sps`.

<a id="c-v4l2_ctrl_hevc_ext_sps_lt_rps"></a>



```c
v4l2_ctrl_hevc_ext_sps_lt_rps
```


<table>
<caption>

struct v4l2\_ctrl\_hevc\_ext\_sps\_lt\_rps

</caption>
<tbody>
<tr>
<td>



\_\_u16

</td>
<td>



`lt_ref_pic_poc_lsb_sps`

</td>
<td>



Long term reference picture order count as described in section 7.4.3.2.1 "General sequence parameter set RBSP semantics" of the specification.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`flags`

</td>
<td>



See [Extended Long-Term RPS Flags](<#rst-hevc-ext-sps-lt-rps-flags>)

</td>
</tr>
</tbody>
</table>

<a id="rst-hevc-ext-sps-lt-rps-flags"></a>

`Extended SPS Long-Term RPS Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_HEVC_EXT_SPS_LT_RPS_FLAG_USED_LT`

</td>
<td>



0x00000001

</td>
<td>



Specifies if the long-term reference picture is used 7.4.3.2.1 "General sequence parameter set RBSP semantics" of the specification.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_STATELESS_HEVC_EXT_SPS_ST_RPS (struct)`**

  Subset of the `v4l2_ctrl_hevc_sps` control. It extends it with the list of Short-term reference sets parameters. These parameters are defined according to [hevc](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hevc>). They are described in section 7.4.8 "Short-term reference picture set semantics" of the specification. This control is a dynamically sized 1-dimensional array. The values in the array should be ignored when num\_short\_term\_ref\_pic\_sets is 0.

<a id="c-v4l2_ctrl_hevc_ext_sps_st_rps"></a>



```c
v4l2_ctrl_hevc_ext_sps_st_rps
```


<table>
<caption>

struct v4l2\_ctrl\_hevc\_ext\_sps\_st\_rps

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_idx_minus1`

</td>
<td>



Specifies the delta compare to the index. See details in section 7.4.8 "Short-term reference picture set semantics" of the specification.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_rps_sign`

</td>
<td>



Sign of the delta as specified in section 7.4.8 "Short-term reference picture set semantics" of the specification.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_negative_pics`

</td>
<td>



Number of short-term RPS entries that have picture order count values less than the picture order count value of the current picture.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_positive_pics`

</td>
<td>



Number of short-term RPS entries that have picture order count values greater than the picture order count value of the current picture.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`used_by_curr_pic`

</td>
<td>



Bit i specifies if short-term RPS i is used by the current picture.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`use_delta_flag`

</td>
<td>



Bit i specifies if short-term RPS i is included in the short-term RPS entries.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`abs_delta_rps_minus1`

</td>
<td>



Absolute delta RPS as specified in section 7.4.8 "Short-term reference picture set semantics" of the specification.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`delta_poc_s0_minus1[16]`

</td>
<td>



Specifies the negative picture order count delta for the i-th entry in the short-term RPS. See details in section 7.4.8 "Short-term reference picture set semantics" of the specification.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`delta_poc_s1_minus1[16]`

</td>
<td>



Specifies the positive picture order count delta for the i-th entry in the short-term RPS. See details in section 7.4.8 "Short-term reference picture set semantics" of the specification.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`flags`

</td>
<td>



See [Extended Short-Term RPS Flags](<#rst-hevc-ext-sps-st-rps-flags>)

</td>
</tr>
</tbody>
</table>

<a id="rst-hevc-ext-sps-st-rps-flags"></a>

`Extended SPS Short-Term RPS Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_HEVC_EXT_SPS_ST_RPS_FLAG_INTER_REF_PIC_SET_PRED`

</td>
<td>



0x00000001

</td>
<td>



Specifies if the short-term RPS is predicted from another short term RPS. See details in section 7.4.8 "Short-term reference picture set semantics" of the specification.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-codec-stateless-av1"></a>

- **`V4L2_CID_STATELESS_AV1_SEQUENCE (struct)`**

  Represents an AV1 Sequence OBU (Open Bitstream Unit). See section 5.5 "Sequence header OBU syntax" in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>) for more details.

<a id="c-v4l2_ctrl_av1_sequence"></a>



```c
v4l2_ctrl_av1_sequence
```

<!-- tabularcolumns: |p{5.8cm}|p{4.8cm}|p{6.6cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_av1\_sequence

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [AV1 Sequence Flags](<#rst-av1-sequence-flags>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`seq_profile`

</td>
<td>



Specifies the features that can be used in the coded video sequence.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`order_hint_bits`

</td>
<td>



Specifies the number of bits used for the order\_hint field at each frame.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`bit_depth`

</td>
<td>



the bit depth to use for the sequence as described in section 5.5.2 "Color config syntax" in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`max_frame_width_minus_1`

</td>
<td>



Specifies the maximum frame width minus 1 for the frames represented by this sequence header.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`max_frame_height_minus_1`

</td>
<td>



Specifies the maximum frame height minus 1 for the frames represented by this sequence header.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-sequence-flags"></a>

`AV1 Sequence Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_STILL_PICTURE`

</td>
<td>



0x00000001

</td>
<td>



If set, specifies that the coded video sequence contains only one coded frame. If not set, specifies that the coded video sequence contains one or more coded frames.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_USE_128X128_SUPERBLOCK`

</td>
<td>



0x00000002

</td>
<td>



If set, indicates that superblocks contain 128x128 luma samples. When equal to 0, it indicates that superblocks contain 64x64 luma samples. The number of contained chroma samples depends on subsampling\_x and subsampling\_y.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_FILTER_INTRA`

</td>
<td>



0x00000004

</td>
<td>



If set, specifies that the use\_filter\_intra syntax element may be present. If not set, specifies that the use\_filter\_intra syntax element will not be present.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_INTRA_EDGE_FILTER`

</td>
<td>



0x00000008

</td>
<td>



Specifies whether the intra edge filtering process should be enabled.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_INTERINTRA_COMPOUND`

</td>
<td>



0x00000010

</td>
<td>



If set, specifies that the mode info for inter blocks may contain the syntax element interintra. If not set, specifies that the syntax element interintra will not be present.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_MASKED_COMPOUND`

</td>
<td>



0x00000020

</td>
<td>



If set, specifies that the mode info for inter blocks may contain the syntax element compound\_type. If not set, specifies that the syntax element compound\_type will not be present.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_WARPED_MOTION`

</td>
<td>



0x00000040

</td>
<td>



If set, indicates that the allow\_warped\_motion syntax element may be present. If not set, indicates that the allow\_warped\_motion syntax element will not be present.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_DUAL_FILTER`

</td>
<td>



0x00000080

</td>
<td>



If set, indicates that the inter prediction filter type may be specified independently in the horizontal and vertical directions. If the flag is equal to 0, only one filter type may be specified, which is then used in both directions.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_ORDER_HINT`

</td>
<td>



0x00000100

</td>
<td>



If set, indicates that tools based on the values of order hints may be used. If not set, indicates that tools based on order hints are disabled.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_JNT_COMP`

</td>
<td>



0x00000200

</td>
<td>



If set, indicates that the distance weights process may be used for inter prediction.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_REF_FRAME_MVS`

</td>
<td>



0x00000400

</td>
<td>



If set, indicates that the use\_ref\_frame\_mvs syntax element may be present. If not set, indicates that the use\_ref\_frame\_mvs syntax element will not be present.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_SUPERRES`

</td>
<td>



0x00000800

</td>
<td>



If set, specifies that the use\_superres syntax element will be present in the uncompressed header. If not set, specifies that the use\_superres syntax element will not be present (instead use\_superres will be set to 0 in the uncompressed header without being read).

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_CDEF`

</td>
<td>



0x00001000

</td>
<td>



If set, specifies that cdef filtering may be enabled. If not set, specifies that cdef filtering is disabled.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_ENABLE_RESTORATION`

</td>
<td>



0x00002000

</td>
<td>



If set, specifies that loop restoration filtering may be enabled. If not set, specifies that loop restoration filtering is disabled.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_MONO_CHROME`

</td>
<td>



0x00004000

</td>
<td>



If set, indicates that the video does not contain U and V color planes. If not set, indicates that the video contains Y, U, and V color planes.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_COLOR_RANGE`

</td>
<td>



0x00008000

</td>
<td>



If set, signals full swing representation, i.e. "Full Range Quantization". If not set, signals studio swing representation, i.e. "Limited Range Quantization".

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_SUBSAMPLING_X`

</td>
<td>



0x00010000

</td>
<td>



Specify the chroma subsampling format.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_SUBSAMPLING_Y`

</td>
<td>



0x00020000

</td>
<td>



Specify the chroma subsampling format.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_FILM_GRAIN_PARAMS_PRESENT`

</td>
<td>



0x00040000

</td>
<td>



Specifies whether film grain parameters are present in the coded video sequence.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEQUENCE_FLAG_SEPARATE_UV_DELTA_Q`

</td>
<td>



0x00080000

</td>
<td>



If set, indicates that the U and V planes may have separate delta quantizer values. If not set, indicates that the U and V planes will share the same delta quantizer value.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY (struct)`**

  Represents a single AV1 tile inside an AV1 Tile Group. Note that MiRowStart, MiRowEnd, MiColStart and MiColEnd can be retrieved from struct v4l2\_av1\_tile\_info in struct v4l2\_ctrl\_av1\_frame using tile\_row and tile\_col. See section 6.10.1 "General tile group OBU semantics" in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>) for more details.

<a id="c-v4l2_ctrl_av1_tile_group_entry"></a>



```c
v4l2_ctrl_av1_tile_group_entry
```

<!-- tabularcolumns: |p{5.8cm}|p{4.8cm}|p{6.6cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_av1\_tile\_group\_entry

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`tile_offset`

</td>
<td>



Offset from the OBU data, i.e. where the coded tile data actually starts.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`tile_size`

</td>
<td>



Specifies the size in bytes of the coded tile. Equivalent to "TileSize" in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`tile_row`

</td>
<td>



Specifies the row of the current tile. Equivalent to "TileRow" in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`tile_col`

</td>
<td>



Specifies the column of the current tile. Equivalent to "TileColumn" in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_warp_model"></a>



```c
v4l2_av1_warp_model
```

AV1 Warp Model as described in section 3 "Symbols and abbreviated terms" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{7.4cm}|p{0.3cm}|p{9.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_WARP_MODEL_IDENTITY`

</td>
<td>



0

</td>
<td>



Warp model is just an identity transform.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_WARP_MODEL_TRANSLATION`

</td>
<td>



1

</td>
<td>



Warp model is a pure translation.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_WARP_MODEL_ROTZOOM`

</td>
<td>



2

</td>
<td>



Warp model is a rotation + symmetric zoom + translation.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_WARP_MODEL_AFFINE`

</td>
<td>



3

</td>
<td>



Warp model is a general affine transform.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_reference_frame"></a>



```c
v4l2_av1_reference_frame
```

AV1 Reference Frames as described in section 6.10.24 "Ref frames semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{7.4cm}|p{0.3cm}|p{9.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_REF_INTRA_FRAME`

</td>
<td>



0

</td>
<td>



Intra Frame Reference.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_REF_LAST_FRAME`

</td>
<td>



1

</td>
<td>



Last Frame Reference.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_REF_LAST2_FRAME`

</td>
<td>



2

</td>
<td>



Last2 Frame Reference.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_REF_LAST3_FRAME`

</td>
<td>



3

</td>
<td>



Last3 Frame Reference.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_REF_GOLDEN_FRAME`

</td>
<td>



4

</td>
<td>



Golden Frame Reference.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_REF_BWDREF_FRAME`

</td>
<td>



5

</td>
<td>



BWD Frame Reference.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_REF_ALTREF2_FRAME`

</td>
<td>



6

</td>
<td>



ALTREF2 Frame Reference.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_REF_ALTREF_FRAME`

</td>
<td>



7

</td>
<td>



ALTREF Frame Reference.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_global_motion"></a>



```c
v4l2_av1_global_motion
```

AV1 Global Motion parameters as described in section 6.8.17 "Global motion params semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_av1\_global\_motion

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`flags[V4L2_AV1_TOTAL_REFS_PER_FRAME]`

</td>
<td>



A bitfield containing the flags per reference frame. See [AV1 Global Motion Flags](<#rst-av1-global-motion-flags>) for more details.

</td>
</tr>
<tr>
<td>



enum `v4l2_av1_warp_model`

</td>
<td>



`type[V4L2_AV1_TOTAL_REFS_PER_FRAME]`

</td>
<td>



The type of global motion transform used.

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`params[V4L2_AV1_TOTAL_REFS_PER_FRAME][6]`

</td>
<td>



This field has the same meaning as "gm\_params" in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`invalid`

</td>
<td>



Bitfield indicating whether the global motion params are invalid for a given reference frame. See section 7.11.3.6 Setup shear process and the variable "warpValid". Use V4L2\_AV1\_GLOBAL\_MOTION\_IS\_INVALID(ref) to create a suitable mask.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[3]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-global-motion-flags"></a>

`AV1 Global Motion Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_GLOBAL_MOTION_FLAG_IS_GLOBAL`

</td>
<td>



0x00000001

</td>
<td>



Specifies whether global motion parameters are present for a particular reference frame.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_GLOBAL_MOTION_FLAG_IS_ROT_ZOOM`

</td>
<td>



0x00000002

</td>
<td>



Specifies whether a particular reference frame uses rotation and zoom global motion.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_GLOBAL_MOTION_FLAG_IS_TRANSLATION`

</td>
<td>



0x00000004

</td>
<td>



Specifies whether a particular reference frame uses translation global motion

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_frame_restoration_type"></a>



```c
v4l2_av1_frame_restoration_type
```

AV1 Frame Restoration Type.

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{7.4cm}|p{0.3cm}|p{9.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_FRAME_RESTORE_NONE`

</td>
<td>



0

</td>
<td>



No filtering is applied.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_RESTORE_WIENER`

</td>
<td>



1

</td>
<td>



Wiener filter process is invoked.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_RESTORE_SGRPROJ`

</td>
<td>



2

</td>
<td>



Self guided filter process is invoked.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_RESTORE_SWITCHABLE`

</td>
<td>



3

</td>
<td>



Restoration filter is swichtable.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_loop_restoration"></a>



```c
v4l2_av1_loop_restoration
```

AV1 Loop Restoration as described in section 6.10.15 "Loop restoration params semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_av1\_loop\_restoration

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



See [AV1 Loop Restoration Flags](<#rst-av1-loop-restoration-flags>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`lr_unit_shift`

</td>
<td>



Specifies if the luma restoration size should be halved.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`lr_uv_shift`

</td>
<td>



Specifies if the chroma size should be half the luma size.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



`v4l2_av1_frame_restoration_type`

</td>
<td>



`frame_restoration_type[V4L2_AV1_NUM_PLANES_MAX]`

</td>
<td>



Specifies the type of restoration used for each plane.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`loop_restoration_size[V4L2_AV1_MAX_NUM_PLANES]`

</td>
<td>



Specifies the size of loop restoration units in units of samples in the current plane.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-loop-restoration-flags"></a>

`AV1 Loop Restoration Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_LOOP_RESTORATION_FLAG_USES_LR`

</td>
<td>



0x00000001

</td>
<td>



Retains the same meaning as UsesLr in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

</td>
</tr>
<tr>
<td>



`V4L2_AV1_LOOP_RESTORATION_FLAG_USES_CHROMA_LR`

</td>
<td>



0x00000002

</td>
<td>



Retains the same meaning as UsesChromaLr in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_cdef"></a>



```c
v4l2_av1_cdef
```

AV1 CDEF params semantics as described in section 6.10.14 "CDEF params semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_av1\_cdef

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`damping_minus_3`

</td>
<td>



Controls the amount of damping in the deringing filter.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`bits`

</td>
<td>



Specifies the number of bits needed to specify which CDEF filter to apply.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`y_pri_strength[V4L2_AV1_CDEF_MAX]`

</td>
<td>



Specifies the strength of the primary filter.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`y_sec_strength[V4L2_AV1_CDEF_MAX]`

</td>
<td>



Specifies the strength of the secondary filter.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`uv_pri_strength[V4L2_AV1_CDEF_MAX]`

</td>
<td>



Specifies the strength of the primary filter.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`uv_sec_strength[V4L2_AV1_CDEF_MAX]`

</td>
<td>



Specifies the strength of the secondary filter.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_segment_feature"></a>



```c
v4l2_av1_segment_feature
```

AV1 segment features as described in section 3 "Symbols and abbreviated terms" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{7.4cm}|p{0.3cm}|p{9.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_SEG_LVL_ALT_Q`

</td>
<td>



0

</td>
<td>



Index for quantizer segment feature.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEG_LVL_ALT_LF_Y_V`

</td>
<td>



1

</td>
<td>



Index for vertical luma loop filter segment feature.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEG_LVL_REF_FRAME`

</td>
<td>



5

</td>
<td>



Index for reference frame segment feature.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEG_LVL_REF_SKIP`

</td>
<td>



6

</td>
<td>



Index for skip segment feature.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEG_LVL_REF_GLOBALMV`

</td>
<td>



7

</td>
<td>



Index for global mv feature.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEG_LVL_MAX`

</td>
<td>



8

</td>
<td>



Number of segment features.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_segmentation"></a>



```c
v4l2_av1_segmentation
```

AV1 Segmentation params as defined in section 6.8.13 "Segmentation params semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_av1\_segmentation

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



See [AV1 Segmentation Flags](<#rst-av1-segmentation-flags>)

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`last_active_seg_id`

</td>
<td>



Indicates the highest numbered segment id that has some enabled feature. This is used when decoding the segment id to only decode choices corresponding to used segments.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`feature_enabled[V4L2_AV1_MAX_SEGMENTS]`

</td>
<td>



Bitmask defining which features are enabled in each segment. Use V4L2\_AV1\_SEGMENT\_FEATURE\_ENABLED to build a suitable mask.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`feature_data[V4L2_AV1_MAX_SEGMENTS][V4L2_AV1_SEG_LVL_MAX]`

</td>
<td>



Data attached to each feature. Data entry is only valid if the feature is enabled.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-segmentation-flags"></a>

`AV1 Segmentation Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_SEGMENTATION_FLAG_ENABLED`

</td>
<td>



0x00000001

</td>
<td>



If set, indicates that this frame makes use of the segmentation tool. If not set, indicates that the frame does not use segmentation.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEGMENTATION_FLAG_UPDATE_MAP`

</td>
<td>



0x00000002

</td>
<td>



If set, indicates that the segmentation map are updated during the decoding of this frame. If not set, indicates that the segmentation map from the previous frame is used.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEGMENTATION_FLAG_TEMPORAL_UPDATE`

</td>
<td>



0x00000004

</td>
<td>



If set, indicates that the updates to the segmentation map are coded relative to the existing segmentation map. If not set, indicates that the new segmentation map is coded without reference to the existing segmentation map.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEGMENTATION_FLAG_UPDATE_DATA`

</td>
<td>



0x00000008

</td>
<td>



If set, indicates that the updates to the segmentation map are coded relative to the existing segmentation map. If not set, indicates that the new segmentation map is coded without reference to the existing segmentation map.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SEGMENTATION_FLAG_SEG_ID_PRE_SKIP`

</td>
<td>



0x00000010

</td>
<td>



If set, indicates that the segment id will be read before the skip syntax element. If not set, indicates that the skip syntax element will be read first.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_loop_filter"></a>



```c
v4l2_av1_loop_filter
```

AV1 Loop filter params as defined in section 6.8.10 "Loop filter semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_av1\_loop\_filter

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



See [AV1 Loop Filter flags](<#rst-av1-loop-filter-flags>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`level[4]`

</td>
<td>



An array containing loop filter strength values. Different loop filter strength values from the array are used depending on the image plane being filtered, and the edge direction (vertical or horizontal) being filtered.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`sharpness`

</td>
<td>



indicates the sharpness level. The loop\_filter\_level and loop\_filter\_sharpness together determine when a block edge is filtered, and by how much the filtering can change the sample values. The loop filter process is described in section 7.14 of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ref_deltas[V4L2_AV1_TOTAL_REFS_PER_FRAME]`

</td>
<td>



contains the adjustment needed for the filter level based on the chosen reference frame. If this syntax element is not present, it maintains its previous value.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`mode_deltas[2]`

</td>
<td>



contains the adjustment needed for the filter level based on the chosen mode. If this syntax element is not present, it maintains its previous value.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_lf_res`

</td>
<td>



specifies the left shift which should be applied to decoded loop filter delta values.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-loop-filter-flags"></a>

`AV1 Loop Filter Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_LOOP_FILTER_FLAG_DELTA_ENABLED`

</td>
<td>



0x00000001

</td>
<td>



If set, means that the filter level depends on the mode and reference frame used to predict a block. If not set, means that the filter level does not depend on the mode and reference frame.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_LOOP_FILTER_FLAG_DELTA_UPDATE`

</td>
<td>



0x00000002

</td>
<td>



If set, means that additional syntax elements are present that specify which mode and reference frame deltas are to be updated. If not set, means that these syntax elements are not present.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_LOOP_FILTER_FLAG_DELTA_LF_PRESENT`

</td>
<td>



0x00000004

</td>
<td>



Specifies whether loop filter delta values are present

</td>
</tr>
<tr>
<td>



`V4L2_AV1_LOOP_FILTER_FLAG_DELTA_LF_MULTI`

</td>
<td>



0x00000008

</td>
<td>



A value equal to 1 specifies that separate loop filter deltas are sent for horizontal luma edges, vertical luma edges, the U edges, and the V edges. A value of delta\_lf\_multi equal to 0 specifies that the same loop filter delta is used for all edges.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_quantization"></a>



```c
v4l2_av1_quantization
```

AV1 Quantization params as defined in section 6.8.11 "Quantization params semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_av1\_quantization

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



See [AV1 Loop Filter flags](<#rst-av1-quantization-flags>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`base_q_idx`

</td>
<td>



Indicates the base frame qindex. This is used for Y AC coefficients and as the base value for the other quantizers.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_q_y_dc`

</td>
<td>



Indicates the Y DC quantizer relative to base\_q\_idx.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_q_u_dc`

</td>
<td>



Indicates the U DC quantizer relative to base\_q\_idx.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_q_u_ac`

</td>
<td>



Indicates the U AC quantizer relative to base\_q\_idx.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_q_v_dc`

</td>
<td>



Indicates the V DC quantizer relative to base\_q\_idx.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_q_v_ac`

</td>
<td>



Indicates the V AC quantizer relative to base\_q\_idx.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`qm_y`

</td>
<td>



Specifies the level in the quantizer matrix that should be used for luma plane decoding.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`qm_u`

</td>
<td>



Specifies the level in the quantizer matrix that should be used for chroma U plane decoding.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`qm_v`

</td>
<td>



Specifies the level in the quantizer matrix that should be used for chroma V plane decoding.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`delta_q_res`

</td>
<td>



Specifies the left shift which should be applied to decoded quantizer index delta values.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-quantization-flags"></a>

`AV1 Quantization Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_QUANTIZATION_FLAG_DIFF_UV_DELTA`

</td>
<td>



0x00000001

</td>
<td>



If set, indicates that the U and V delta quantizer values are coded separately. If not set, indicates that the U and V delta quantizer values share a common value.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_QUANTIZATION_FLAG_USING_QMATRIX`

</td>
<td>



0x00000002

</td>
<td>



If set, specifies that the quantizer matrix will be used to compute quantizers.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_QUANTIZATION_FLAG_DELTA_Q_PRESENT`

</td>
<td>



0x00000004

</td>
<td>



Specifies whether quantizer index delta values are present.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_tile_info"></a>



```c
v4l2_av1_tile_info
```

AV1 Tile info as defined in section 6.8.14 "Tile info semantics" of ref:`av1`.

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_av1\_tile\_info

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



See [AV1 Tile Info flags](<#rst-av1-tile-info-flags>) for more details.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`context_update_tile_id`

</td>
<td>



Specifies which tile to use for the CDF update.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tile_cols`

</td>
<td>



Specifies the number of tiles across the frame.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tile_rows`

</td>
<td>



Specifies the number of tiles down the frame.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`mi_col_starts[V4L2_AV1_MAX_TILE_COLS + 1]`

</td>
<td>



An array specifying the start column (in units of 4x4 luma samples) for each tile across the image.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`mi_row_starts[V4L2_AV1_MAX_TILE_ROWS + 1]`

</td>
<td>



An array specifying the start row (in units of 4x4 luma samples) for each tile across the image.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`width_in_sbs_minus_1[V4L2_AV1_MAX_TILE_COLS]`

</td>
<td>



Specifies the width of a tile minus 1 in units of superblocks.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`height_in_sbs_minus_1[V4L2_AV1_MAX_TILE_ROWS]`

</td>
<td>



Specifies the height of a tile minus 1 in units of superblocks.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`tile_size_bytes`

</td>
<td>



Specifies the number of bytes needed to code each tile size.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[3]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-tile-info-flags"></a>

`AV1 Tile Info Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING`

</td>
<td>



0x00000001

</td>
<td>



If set, means that the tiles are uniformly spaced across the frame. (In other words, all tiles are the same size except for the ones at the right and bottom edge which can be smaller). If not set means that the tile sizes are coded.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_frame_type"></a>



```c
v4l2_av1_frame_type
```

AV1 Frame Type

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{7.4cm}|p{0.3cm}|p{9.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_KEY_FRAME`

</td>
<td>



0

</td>
<td>



Key frame.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_INTER_FRAME`

</td>
<td>



1

</td>
<td>



Inter frame.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_INTRA_ONLY_FRAME`

</td>
<td>



2

</td>
<td>



Intra-only frame.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_SWITCH_FRAME`

</td>
<td>



3

</td>
<td>



Switch frame.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_interpolation_filter"></a>



```c
v4l2_av1_interpolation_filter
```

AV1 Interpolation Filter

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{7.4cm}|p{0.3cm}|p{9.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP`

</td>
<td>



0

</td>
<td>



Eight tap filter.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH`

</td>
<td>



1

</td>
<td>



Eight tap smooth filter.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_INTERPOLATION_FILTER_EIGHTTAP_SHARP`

</td>
<td>



2

</td>
<td>



Eight tap sharp filter.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_INTERPOLATION_FILTER_BILINEAR`

</td>
<td>



3

</td>
<td>



Bilinear filter.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_INTERPOLATION_FILTER_SWITCHABLE`

</td>
<td>



4

</td>
<td>



Filter selection is signaled at the block level.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_av1_tx_mode"></a>



```c
v4l2_av1_tx_mode
```

AV1 Tx mode as described in section 6.8.21 "TX mode semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{7.4cm}|p{0.3cm}|p{9.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_TX_MODE_ONLY_4X4`

</td>
<td>



0

</td>
<td>



The inverse transform will use only 4x4 transforms.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_TX_MODE_LARGEST`

</td>
<td>



1

</td>
<td>



The inverse transform will use the largest transform size that fits inside the block.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_TX_MODE_SELECT`

</td>
<td>



2

</td>
<td>



The choice of transform size is specified explicitly for each block.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_STATELESS_AV1_FRAME (struct)`**

  Represents a Frame Header OBU. See 6.8 "Frame Header OBU semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>) for more details.

<a id="c-v4l2_ctrl_av1_frame"></a>



```c
v4l2_ctrl_av1_frame
```

<!-- tabularcolumns: |p{5.8cm}|p{4.8cm}|p{6.6cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_av1\_frame

</caption>
<tbody>
<tr>
<td>



struct `v4l2_av1_tile_info`

</td>
<td>



`tile_info`

</td>
<td>



Tile info

</td>
</tr>
<tr>
<td>



struct `v4l2_av1_quantization`

</td>
<td>



`quantization`

</td>
<td>



Quantization parameters.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`superres_denom`

</td>
<td>



The denominator for the upscaling ratio.

</td>
</tr>
<tr>
<td>



struct `v4l2_av1_segmentation`

</td>
<td>



`segmentation`

</td>
<td>



Segmentation parameters.

</td>
</tr>
<tr>
<td>



struct `v4l2_av1_loop_filter`

</td>
<td>



`loop_filter`

</td>
<td>



Loop filter params

</td>
</tr>
<tr>
<td>



struct `v4l2_av1_cdef`

</td>
<td>



`cdef`

</td>
<td>



CDEF params

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`skip_mode_frame[2]`

</td>
<td>



Specifies the frames to use for compound prediction when skip\_mode is equal to 1.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`primary_ref_frame`

</td>
<td>



Specifies which reference frame contains the CDF values and other state that should be loaded at the start of the frame.

</td>
</tr>
<tr>
<td>



struct `v4l2_av1_loop_restoration`

</td>
<td>



`loop_restoration`

</td>
<td>



Loop restoration parameters.

</td>
</tr>
<tr>
<td>



struct `v4l2_av1_global_motion`

</td>
<td>



`global_motion`

</td>
<td>



Global motion parameters.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [AV1 Frame flags](<#rst-av1-frame-flags>) for more details.

</td>
</tr>
<tr>
<td>



enum `v4l2_av1_frame_type`

</td>
<td>



`frame_type`

</td>
<td>



Specifies the AV1 frame type

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`order_hint`

</td>
<td>



Specifies OrderHintBits least significant bits of the expected output order for this frame.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`upscaled_width`

</td>
<td>



The upscaled width.

</td>
</tr>
<tr>
<td>



enum `v4l2_av1_interpolation_filter`

</td>
<td>



`interpolation_filter`

</td>
<td>



Specifies the filter selection used for performing inter prediction.

</td>
</tr>
<tr>
<td>



enum `v4l2_av1_tx_mode`

</td>
<td>



`tx_mode`

</td>
<td>



Specifies how the transform size is determined.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`frame_width_minus_1`

</td>
<td>



Add 1 to get the frame's width.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`frame_height_minus_1`

</td>
<td>



Add 1 to get the frame's height.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`render_width_minus_1`

</td>
<td>



Add 1 to get the render width of the frame in luma samples.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`render_height_minus_1`

</td>
<td>



Add 1 to get the render height of the frame in luma samples.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`current_frame_id`

</td>
<td>



Specifies the frame id number for the current frame. Frame id numbers are additional information that do not affect the decoding process, but provide decoders with a way of detecting missing reference frames so that appropriate action can be taken.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`buffer_removal_time[V4L2_AV1_MAX_OPERATING_POINTS]`

</td>
<td>



Specifies the frame removal time in units of DecCT clock ticks counted from the removal time of the last random access point for operating point opNum.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[4]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`order_hints[V4L2_AV1_TOTAL_REFS_PER_FRAME]`

</td>
<td>



Specifies the expected output order hint for each reference frame. This field corresponds to the OrderHints variable from the specification (section 5.9.2  "Uncompressed header syntax"). As such, this is only used for non-intra frames and ignored otherwise. order\_hints\[0\] is always ignored.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`reference_frame_ts[V4L2_AV1_TOTAL_REFS_PER_FRAME]`

</td>
<td>



The V4L2 timestamp for each of the reference frames enumerated in enum `v4l2_av1_reference_frame` starting at `V4L2_AV1_REF_LAST_FRAME`. This represents the state of reference slot as described in the spec and updated by userland through the "Reference frame update process" in section 7.20 The timestamp refers to the `timestamp` field in struct `v4l2_buffer`. Use the `v4l2_timeval_to_ns()` function to convert the struct `timeval` in struct `v4l2_buffer` to a \_\_u64.

</td>
</tr>
<tr>
<td>



\_\_s8

</td>
<td>



`ref_frame_idx[V4L2_AV1_REFS_PER_FRAME]`

</td>
<td>



An index into `reference_frame_ts` representing the ordered list of references used by inter-frame. Matches the bitstream syntax element of the same name.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`refresh_frame_flags`

</td>
<td>



Contains a bitmask that specifies which reference frame slots will be updated with the current frame after it is decoded.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-frame-flags"></a>

`AV1 Frame Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_SHOW_FRAME`

</td>
<td>



0x00000001

</td>
<td>



If set, specifies that this frame should be immediately output once decoded. If not set, specifies that this frame should not be immediately output; it may be output later if a later uncompressed header uses show\_existing\_frame equal to 1.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_SHOWABLE_FRAME`

</td>
<td>



0x00000002

</td>
<td>



If set, specifies that the frame may be output using the show\_existing\_frame mechanism. If not set, specifies that this frame will not be output using the show\_existing\_frame mechanism.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_ERROR_RESILIENT_MODE`

</td>
<td>



0x00000004

</td>
<td>



Specifies whether error resilient mode is enabled.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_DISABLE_CDF_UPDATE`

</td>
<td>



0x00000008

</td>
<td>



Specifies whether the CDF update in the symbol decoding process should be disabled.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_ALLOW_SCREEN_CONTENT_TOOLS`

</td>
<td>



0x00000010

</td>
<td>



If set, indicates that intra blocks may use palette encoding. If not set, indicates that palette encoding is never used.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_FORCE_INTEGER_MV`

</td>
<td>



0x00000020

</td>
<td>



If set, specifies that motion vectors will always be integers. If not set, specifies that motion vectors can contain fractional bits.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_ALLOW_INTRABC`

</td>
<td>



0x00000040

</td>
<td>



If set, indicates that intra block copy may be used in this frame. If not set, indicates that intra block copy is not allowed in this frame.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_USE_SUPERRES`

</td>
<td>



0x00000080

</td>
<td>



If set, indicates that upscaling is needed.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_ALLOW_HIGH_PRECISION_MV`

</td>
<td>



0x00000100

</td>
<td>



If set, specifies that motion vectors are specified to eighth pel precision. If not set, specifies that motion vectors are specified to quarter pel precision;

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_IS_MOTION_MODE_SWITCHABLE`

</td>
<td>



0x00000200

</td>
<td>



If not set, specifies that only the SIMPLE motion mode will be used.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_USE_REF_FRAME_MVS`

</td>
<td>



0x00000400

</td>
<td>



If set specifies that motion vector information from a previous frame can be used when decoding the current frame. If not set, specifies that this information will not be used.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_DISABLE_FRAME_END_UPDATE_CDF`

</td>
<td>



0x00000800

</td>
<td>



If set indicates that the end of frame CDF update is disabled. If not set, indicates that the end of frame CDF update is enabled

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_ALLOW_WARPED_MOTION`

</td>
<td>



0x00001000

</td>
<td>



If set, indicates that the syntax element motion\_mode may be present, if not set, indicates that the syntax element motion\_mode will not be present.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_REFERENCE_SELECT`

</td>
<td>



0x00002000

</td>
<td>



If set, specifies that the mode info for inter blocks contains the syntax element comp\_mode that indicates whether to use single or compound reference prediction. If not set, specifies that all inter blocks will use single prediction.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_REDUCED_TX_SET`

</td>
<td>



0x00004000

</td>
<td>



If set, specifies that the frame is restricted to a reduced subset of the full set of transform types.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_SKIP_MODE_ALLOWED`

</td>
<td>



0x00008000

</td>
<td>



This flag retains the same meaning as SkipModeAllowed in [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>).

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_SKIP_MODE_PRESENT`

</td>
<td>



0x00010000

</td>
<td>



If set, specifies that the syntax element skip\_mode will be present, if not set, specifies that skip\_mode will not be used for this frame.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_FRAME_SIZE_OVERRIDE`

</td>
<td>



0x00020000

</td>
<td>



If set, specifies that the frame size will either be specified as the size of one of the reference frames, or computed from the frame\_width\_minus\_1 and frame\_height\_minus\_1 syntax elements. If not set, specifies that the frame size is equal to the size in the sequence header.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_BUFFER_REMOVAL_TIME_PRESENT`

</td>
<td>



0x00040000

</td>
<td>



If set, specifies that buffer\_removal\_time is present. If not set, specifies that buffer\_removal\_time is not present.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FRAME_FLAG_FRAME_REFS_SHORT_SIGNALING`

</td>
<td>



0x00080000

</td>
<td>



If set, indicates that only two reference frames are explicitly signaled. If not set, indicates that all reference frames are explicitly signaled.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_STATELESS_AV1_FILM_GRAIN (struct)`**

  Represents the optional film grain parameters. See section 6.8.20 "Film grain params semantics" of [av1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-av1-1>) for more details.

<a id="c-v4l2_ctrl_av1_film_grain"></a>



```c
v4l2_ctrl_av1_film_grain
```

<!-- tabularcolumns: |p{1.5cm}|p{5.8cm}|p{10.0cm}| -->


<table>
<caption>

struct v4l2\_ctrl\_av1\_film\_grain

</caption>
<tbody>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



See [AV1 Film Grain Flags](<#rst-av1-film-grain-flags>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`cr_mult`

</td>
<td>



Represents a multiplier for the cr component used in derivation of the input index to the cr component scaling function.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`grain_seed`

</td>
<td>



Specifies the starting value for the pseudo-random numbers used during film grain synthesis.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`film_grain_params_ref_idx`

</td>
<td>



Indicates which reference frame contains the film grain parameters to be used for this frame.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_y_points`

</td>
<td>



Specifies the number of points for the piece-wise linear scaling function of the luma component.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`point_y_value[V4L2_AV1_MAX_NUM_Y_POINTS]`

</td>
<td>



Represents the x (luma value) coordinate for the i-th point of the piecewise linear scaling function for luma component. The values are signaled on the scale of 0..255. In case of 10 bit video, these values correspond to luma values divided by 4. In case of 12 bit video, these values correspond to luma values divided by 16.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`point_y_scaling[V4L2_AV1_MAX_NUM_Y_POINTS]`

</td>
<td>



Represents the scaling (output) value for the i-th point of the piecewise linear scaling function for luma component.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_cb_points`

</td>
<td>



Specifies the number of points for the piece-wise linear scaling function of the cb component.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`point_cb_value[V4L2_AV1_MAX_NUM_CB_POINTS]`

</td>
<td>



Represents the x coordinate for the i-th point of the piece-wise linear scaling function for cb component. The values are signaled on the scale of 0..255.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`point_cb_scaling[V4L2_AV1_MAX_NUM_CB_POINTS]`

</td>
<td>



Represents the scaling (output) value for the i-th point of the piecewise linear scaling function for cb component.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_cr_points`

</td>
<td>



Represents the number of points for the piece-wise linear scaling function of the cr component.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`point_cr_value[V4L2_AV1_MAX_NUM_CR_POINTS]`

</td>
<td>



Represents the x coordinate for the i-th point of the piece-wise linear scaling function for cr component. The values are signaled on the scale of 0..255.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`point_cr_scaling[V4L2_AV1_MAX_NUM_CR_POINTS]`

</td>
<td>



Represents the scaling (output) value for the i-th point of the piecewise linear scaling function for cr component.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`grain_scaling_minus_8`

</td>
<td>



Represents the shift - 8 applied to the values of the chroma component. The grain\_scaling\_minus\_8 can take values of 0..3 and determines the range and quantization step of the standard deviation of film grain.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ar_coeff_lag`

</td>
<td>



Specifies the number of auto-regressive coefficients for luma and chroma.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ar_coeffs_y_plus_128[V4L2_AV1_AR_COEFFS_SIZE]`

</td>
<td>



Specifies auto-regressive coefficients used for the Y plane.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ar_coeffs_cb_plus_128[V4L2_AV1_AR_COEFFS_SIZE]`

</td>
<td>



Specifies auto-regressive coefficients used for the U plane.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ar_coeffs_cr_plus_128[V4L2_AV1_AR_COEFFS_SIZE]`

</td>
<td>



Specifies auto-regressive coefficients used for the V plane.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ar_coeff_shift_minus_6`

</td>
<td>



Specifies the range of the auto-regressive coefficients. Values of 0, 1, 2, and 3 correspond to the ranges for auto-regressive coefficients of \[-2, 2), \[-1, 1), \[-0.5, 0.5) and \[-0.25, 0.25) respectively.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`grain_scale_shift`

</td>
<td>



Specifies how much the Gaussian random numbers should be scaled down during the grain synthesis process.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`cb_mult`

</td>
<td>



Represents a multiplier for the cb component used in derivation of the input index to the cb component scaling function.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`cb_luma_mult`

</td>
<td>



Represents a multiplier for the average luma component used in derivation of the input index to the cb component scaling function..

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`cr_luma_mult`

</td>
<td>



Represents a multiplier for the average luma component used in derivation of the input index to the cr component scaling function.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`cb_offset`

</td>
<td>



Represents an offset used in derivation of the input index to the cb component scaling function.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`cr_offset`

</td>
<td>



Represents an offset used in derivation of the input index to the cr component scaling function.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[4]`

</td>
<td>



Applications and drivers must set this to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-av1-film-grain-flags"></a>

`AV1 Film Grain Flags`


<table>
<tbody>
<tr>
<td>



`V4L2_AV1_FILM_GRAIN_FLAG_APPLY_GRAIN`

</td>
<td>



0x00000001

</td>
<td>



If set, specifies that film grain should be added to this frame. If not set, specifies that film grain should not be added.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FILM_GRAIN_FLAG_UPDATE_GRAIN`

</td>
<td>



0x00000002

</td>
<td>



If set, means that a new set of parameters should be sent. If not set, specifies that the previous set of parameters should be used.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FILM_GRAIN_FLAG_CHROMA_SCALING_FROM_LUMA`

</td>
<td>



0x00000004

</td>
<td>



If set, specifies that the chroma scaling is inferred from the luma scaling.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FILM_GRAIN_FLAG_OVERLAP`

</td>
<td>



0x00000008

</td>
<td>



If set, indicates that the overlap between film grain blocks shall be applied. If not set, indicates that the overlap between film grain blocks shall not be applied.

</td>
</tr>
<tr>
<td>



`V4L2_AV1_FILM_GRAIN_FLAG_CLIP_TO_RESTRICTED_RANGE`

</td>
<td>



0x00000010

</td>
<td>



If set, indicates that clipping to the restricted (studio, i.e. limited) range shall be applied to the sample values after adding the film grain (see the semantics for color\_range for an explanation of studio swing). If not set, indicates that clipping to the full range shall be applied to the sample values after adding the film grain.

</td>
</tr>
</tbody>
</table>

---

# Codec Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Below all controls within the Codec control class are described. First the generic controls, then controls specific for certain hardware.

<a id="rst-codec-control-reference"></a>
<a id="rst-codec-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Below all controls within the Codec control class are described. First the generic controls, then controls specific for certain hardware.

> [!NOTE]
>
> These controls are applicable to all codecs and not just MPEG. The defines are prefixed with V4L2\_CID\_MPEG/V4L2\_MPEG as the controls were originally made for MPEG codecs and later extended to cover all encoding formats.

<a id="rst-generic-codec-controls"></a>

## Generic Codec Controls

<a id="rst-codec-control-ids"></a>
<a id="rst-mpeg-control-id"></a>

### Codec Control IDs

- **`V4L2_CID_CODEC_CLASS (class)`**

  The Codec class descriptor. Calling [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>) for this control will return a description of this control class. This description can be used as the caption of a Tab page in a GUI, for example.

<a id="rst-v4l2-mpeg-stream-type"></a>

- **`V4L2_CID_MPEG_STREAM_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_stream\_type -**

  The MPEG-1, -2 or -4 output stream type. One cannot assume anything here. Each hardware MPEG encoder tends to support different subsets of the available MPEG stream types. This control is specific to multiplexed MPEG streams. The currently defined stream types are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_STREAM_TYPE_MPEG2_PS`

</td>
<td>



MPEG-2 program stream

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_STREAM_TYPE_MPEG2_TS`

</td>
<td>



MPEG-2 transport stream

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_STREAM_TYPE_MPEG1_SS`

</td>
<td>



MPEG-1 system stream

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_STREAM_TYPE_MPEG2_DVD`

</td>
<td>



MPEG-2 DVD-compatible stream

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_STREAM_TYPE_MPEG1_VCD`

</td>
<td>



MPEG-1 VCD-compatible stream

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD`

</td>
<td>



MPEG-2 SVCD-compatible stream

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_STREAM_PID_PMT (integer)`**

  Program Map Table Packet ID for the MPEG transport stream (default 16)

- **`V4L2_CID_MPEG_STREAM_PID_AUDIO (integer)`**

  Audio Packet ID for the MPEG transport stream (default 256)

- **`V4L2_CID_MPEG_STREAM_PID_VIDEO (integer)`**

  Video Packet ID for the MPEG transport stream (default 260)

- **`V4L2_CID_MPEG_STREAM_PID_PCR (integer)`**

  Packet ID for the MPEG transport stream carrying PCR fields (default 259)

- **`V4L2_CID_MPEG_STREAM_PES_ID_AUDIO (integer)`**

  Audio ID for MPEG PES

- **`V4L2_CID_MPEG_STREAM_PES_ID_VIDEO (integer)`**

  Video ID for MPEG PES

<a id="rst-v4l2-mpeg-stream-vbi-fmt"></a>

- **`V4L2_CID_MPEG_STREAM_VBI_FMT`**

  (enum)

- **enum v4l2\_mpeg\_stream\_vbi\_fmt -**

  Some cards can embed VBI data (e. g. Closed Caption, Teletext) into the MPEG stream. This control selects whether VBI data should be embedded, and if so, what embedding method should be used. The list of possible VBI formats depends on the driver. The currently defined VBI format types are:

<!-- tabularcolumns: |p{6.6 cm}|p{10.9cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_STREAM_VBI_FMT_NONE`

</td>
<td>



No VBI in the MPEG stream

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_STREAM_VBI_FMT_IVTV`

</td>
<td>



VBI in private packets, IVTV format (documented in the kernel sources in the file `Documentation/userspace-api/media/drivers/cx2341x-uapi.rst`)

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-sampling-freq"></a>

- **`V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ`**

  (enum)

- **enum v4l2\_mpeg\_audio\_sampling\_freq -**

  MPEG Audio sampling frequency. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100`

</td>
<td>



44.1 kHz

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000`

</td>
<td>



48 kHz

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000`

</td>
<td>



32 kHz

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-encoding"></a>

- **`V4L2_CID_MPEG_AUDIO_ENCODING`**

  (enum)

- **enum v4l2\_mpeg\_audio\_encoding -**

  MPEG Audio encoding. This control is specific to multiplexed MPEG streams. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_ENCODING_LAYER_1`

</td>
<td>



MPEG-1/2 Layer I encoding

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_ENCODING_LAYER_2`

</td>
<td>



MPEG-1/2 Layer II encoding

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_ENCODING_LAYER_3`

</td>
<td>



MPEG-1/2 Layer III encoding

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_ENCODING_AAC`

</td>
<td>



MPEG-2/4 AAC (Advanced Audio Coding)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_ENCODING_AC3`

</td>
<td>



AC-3 aka ATSC A/52 encoding

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-l1-bitrate"></a>

- **`V4L2_CID_MPEG_AUDIO_L1_BITRATE`**

  (enum)

- **enum v4l2\_mpeg\_audio\_l1\_bitrate -**

  MPEG-1/2 Layer I bitrate. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_32K`

</td>
<td>



32 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_64K`

</td>
<td>



64 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_96K`

</td>
<td>



96 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_128K`

</td>
<td>



128 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_160K`

</td>
<td>



160 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_192K`

</td>
<td>



192 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_224K`

</td>
<td>



224 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_256K`

</td>
<td>



256 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_288K`

</td>
<td>



288 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_320K`

</td>
<td>



320 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_352K`

</td>
<td>



352 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_384K`

</td>
<td>



384 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_416K`

</td>
<td>



416 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L1_BITRATE_448K`

</td>
<td>



448 kbit/s

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-l2-bitrate"></a>

- **`V4L2_CID_MPEG_AUDIO_L2_BITRATE`**

  (enum)

- **enum v4l2\_mpeg\_audio\_l2\_bitrate -**

  MPEG-1/2 Layer II bitrate. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_32K`

</td>
<td>



32 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_48K`

</td>
<td>



48 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_56K`

</td>
<td>



56 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_64K`

</td>
<td>



64 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_80K`

</td>
<td>



80 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_96K`

</td>
<td>



96 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_112K`

</td>
<td>



112 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_128K`

</td>
<td>



128 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_160K`

</td>
<td>



160 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_192K`

</td>
<td>



192 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_224K`

</td>
<td>



224 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_256K`

</td>
<td>



256 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_320K`

</td>
<td>



320 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L2_BITRATE_384K`

</td>
<td>



384 kbit/s

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-l3-bitrate"></a>

- **`V4L2_CID_MPEG_AUDIO_L3_BITRATE`**

  (enum)

- **enum v4l2\_mpeg\_audio\_l3\_bitrate -**

  MPEG-1/2 Layer III bitrate. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_32K`

</td>
<td>



32 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_40K`

</td>
<td>



40 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_48K`

</td>
<td>



48 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_56K`

</td>
<td>



56 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_64K`

</td>
<td>



64 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_80K`

</td>
<td>



80 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_96K`

</td>
<td>



96 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_112K`

</td>
<td>



112 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_128K`

</td>
<td>



128 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_160K`

</td>
<td>



160 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_192K`

</td>
<td>



192 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_224K`

</td>
<td>



224 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_256K`

</td>
<td>



256 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_L3_BITRATE_320K`

</td>
<td>



320 kbit/s

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_AUDIO_AAC_BITRATE (integer)`**

  AAC bitrate in bits per second.

<a id="rst-v4l2-mpeg-audio-ac3-bitrate"></a>

- **`V4L2_CID_MPEG_AUDIO_AC3_BITRATE`**

  (enum)

- **enum v4l2\_mpeg\_audio\_ac3\_bitrate -**

  AC-3 bitrate. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_32K`

</td>
<td>



32 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_40K`

</td>
<td>



40 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_48K`

</td>
<td>



48 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_56K`

</td>
<td>



56 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_64K`

</td>
<td>



64 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_80K`

</td>
<td>



80 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_96K`

</td>
<td>



96 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_112K`

</td>
<td>



112 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_128K`

</td>
<td>



128 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_160K`

</td>
<td>



160 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_192K`

</td>
<td>



192 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_224K`

</td>
<td>



224 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_256K`

</td>
<td>



256 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_320K`

</td>
<td>



320 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_384K`

</td>
<td>



384 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_448K`

</td>
<td>



448 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_512K`

</td>
<td>



512 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_576K`

</td>
<td>



576 kbit/s

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_AC3_BITRATE_640K`

</td>
<td>



640 kbit/s

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-mode"></a>

- **`V4L2_CID_MPEG_AUDIO_MODE`**

  (enum)

- **enum v4l2\_mpeg\_audio\_mode -**

  MPEG Audio mode. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_MODE_STEREO`

</td>
<td>



Stereo

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_MODE_JOINT_STEREO`

</td>
<td>



Joint Stereo

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_MODE_DUAL`

</td>
<td>



Bilingual

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_MODE_MONO`

</td>
<td>



Mono

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-mode-extension"></a>

- **`V4L2_CID_MPEG_AUDIO_MODE_EXTENSION`**

  (enum)

- **enum v4l2\_mpeg\_audio\_mode\_extension -**

  Joint Stereo audio mode extension. In Layer I and II they indicate which subbands are in intensity stereo. All other subbands are coded in stereo. Layer III is not (yet) supported. Possible values are:

<!-- tabularcolumns: |p{9.1cm}|p{8.4cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4`

</td>
<td>



Subbands 4-31 in intensity stereo

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8`

</td>
<td>



Subbands 8-31 in intensity stereo

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12`

</td>
<td>



Subbands 12-31 in intensity stereo

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16`

</td>
<td>



Subbands 16-31 in intensity stereo

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-emphasis"></a>

- **`V4L2_CID_MPEG_AUDIO_EMPHASIS`**

  (enum)

- **enum v4l2\_mpeg\_audio\_emphasis -**

  Audio Emphasis. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_EMPHASIS_NONE`

</td>
<td>



None

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS`

</td>
<td>



50/15 microsecond emphasis

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17`

</td>
<td>



CCITT J.17

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-crc"></a>

- **`V4L2_CID_MPEG_AUDIO_CRC`**

  (enum)

- **enum v4l2\_mpeg\_audio\_crc -**

  CRC method. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_CRC_NONE`

</td>
<td>



None

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_CRC_CRC16`

</td>
<td>



16 bit parity check

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_AUDIO_MUTE (boolean)`**

  Mutes the audio when capturing. This is not done by muting audio hardware, which can still produce a slight hiss, but in the encoder itself, guaranteeing a fixed and reproducible audio bitstream. 0 = unmuted, 1 = muted.

<a id="rst-v4l2-mpeg-audio-dec-playback"></a>

- **`V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK`**

  (enum)

- **enum v4l2\_mpeg\_audio\_dec\_playback -**

  Determines how monolingual audio should be played back. Possible values are:

<!-- tabularcolumns: |p{9.8cm}|p{7.7cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO`

</td>
<td>



Automatically determines the best playback mode.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_DEC_PLAYBACK_STEREO`

</td>
<td>



Stereo playback.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_DEC_PLAYBACK_LEFT`

</td>
<td>



Left channel playback.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_DEC_PLAYBACK_RIGHT`

</td>
<td>



Right channel playback.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_DEC_PLAYBACK_MONO`

</td>
<td>



Mono playback.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_AUDIO_DEC_PLAYBACK_SWAPPED_STEREO`

</td>
<td>



Stereo playback with swapped left and right channels.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-audio-dec-multilingual-playback"></a>

- **`V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK`**

  (enum)

- **enum v4l2\_mpeg\_audio\_dec\_playback -**

  Determines how multilingual audio should be played back.

<a id="rst-v4l2-mpeg-video-encoding"></a>

- **`V4L2_CID_MPEG_VIDEO_ENCODING`**

  (enum)

- **enum v4l2\_mpeg\_video\_encoding -**

  MPEG Video encoding method. This control is specific to multiplexed MPEG streams. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_ENCODING_MPEG_1`

</td>
<td>



MPEG-1 Video encoding

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_ENCODING_MPEG_2`

</td>
<td>



MPEG-2 Video encoding

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC`

</td>
<td>



MPEG-4 AVC (H.264) Video encoding

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-video-aspect"></a>

- **`V4L2_CID_MPEG_VIDEO_ASPECT`**

  (enum)

- **enum v4l2\_mpeg\_video\_aspect -**

  Video aspect. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_ASPECT_1x1`

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_ASPECT_4x3`

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_ASPECT_16x9`

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_ASPECT_221x100`

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_B_FRAMES (integer)`**

  Number of B-Frames (default 2)

- **`V4L2_CID_MPEG_VIDEO_GOP_SIZE (integer)`**

  GOP size (default 12)

- **`V4L2_CID_MPEG_VIDEO_GOP_CLOSURE (boolean)`**

  GOP closure (default 1)

- **`V4L2_CID_MPEG_VIDEO_PULLDOWN (boolean)`**

  Enable 3:2 pulldown (default 0)

<a id="rst-v4l2-mpeg-video-bitrate-mode"></a>

- **`V4L2_CID_MPEG_VIDEO_BITRATE_MODE`**

  (enum)

- **enum v4l2\_mpeg\_video\_bitrate\_mode -**

  Video bitrate mode. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_BITRATE_MODE_VBR`

</td>
<td>



Variable bitrate

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_BITRATE_MODE_CBR`

</td>
<td>



Constant bitrate

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_BITRATE_MODE_CQ`

</td>
<td>



Constant quality

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_BITRATE (integer)`**

  Average video bitrate in bits per second.

- **`V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (integer)`**

  Peak video bitrate in bits per second. Must be larger or equal to the average video bitrate. It is ignored if the video bitrate mode is set to constant bitrate.

- **`V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY (integer)`**

  Constant quality level control. This control is applicable when `V4L2_CID_MPEG_VIDEO_BITRATE_MODE` value is `V4L2_MPEG_VIDEO_BITRATE_MODE_CQ`. Valid range is 1 to 100 where 1 indicates lowest quality and 100 indicates highest quality. Encoder will decide the appropriate quantization parameter and bitrate to produce requested frame quality.

`V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE (enum)`

- **enum v4l2\_mpeg\_video\_frame\_skip\_mode -**

  Indicates in what conditions the encoder should skip frames. If encoding a frame would cause the encoded stream to be larger then a chosen data limit then the frame will be skipped. Possible values are:

<!-- tabularcolumns: |p{8.2cm}|p{9.3cm}| -->

<!-- Source LaTeX layout: \small -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_DISABLED`

</td>
<td>



Frame skip mode is disabled.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_LEVEL_LIMIT`

</td>
<td>



Frame skip mode enabled and buffer limit is set by the chosen level and is defined by the standard.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT`

</td>
<td>



Frame skip mode enabled and buffer limit is set by the [VBV (MPEG1/2/4)](<#rst-v4l2-mpeg-video-vbv-size>) or [CPB (H264) buffer size](<#rst-v4l2-mpeg-video-h264-cpb-size>) control.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (integer)`**

  For every captured frame, skip this many subsequent frames (default 0).

- **`V4L2_CID_MPEG_VIDEO_MUTE (boolean)`**

  "Mutes" the video to a fixed color when capturing. This is useful for testing, to produce a fixed video bitstream. 0 = unmuted, 1 = muted.

- **`V4L2_CID_MPEG_VIDEO_MUTE_YUV (integer)`**

  Sets the "mute" color of the video. The supplied 32-bit integer is interpreted as follows (bit 0 = least significant bit):


<table>
<tbody>
<tr>
<td>



Bit 0:7

</td>
<td>



V chrominance information

</td>
</tr>
<tr>
<td>



Bit 8:15

</td>
<td>



U chrominance information

</td>
</tr>
<tr>
<td>



Bit 16:23

</td>
<td>



Y luminance information

</td>
</tr>
<tr>
<td>



Bit 24:31

</td>
<td>



Must be zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-video-dec-pts"></a>

- **`V4L2_CID_MPEG_VIDEO_DEC_PTS (integer64)`**

  This read-only control returns the 33-bit video Presentation Time Stamp as defined in ITU T-REC-H.222.0 and ISO/IEC 13818-1 of the currently displayed frame. This is the same PTS as is used in [vidioc\_decoder\_cmd](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd>).

<a id="rst-v4l2-mpeg-video-dec-frame"></a>

- **`V4L2_CID_MPEG_VIDEO_DEC_FRAME (integer64)`**

  This read-only control returns the frame counter of the frame that is currently displayed (decoded). This value is reset to 0 whenever the decoder is started.

- **`V4L2_CID_MPEG_VIDEO_DEC_CONCEAL_COLOR (integer64)`**

  This control sets the conceal color in YUV color space. It describes the client preference of the error conceal color in case of an error where the reference frame is missing. The decoder should fill the reference buffer with the preferred color and use it for future decoding. The control is using 16 bits per channel. Applicable to decoders.


<table>
<tbody>
<tr>
<td>





</td>
<td>



8bit  format

</td>
<td>



10bit format

</td>
<td>



12bit format

</td>
</tr>
<tr>
<td>



Y luminance

</td>
<td>



Bit 0:7

</td>
<td>



Bit 0:9

</td>
<td>



Bit 0:11

</td>
</tr>
<tr>
<td>



Cb chrominance

</td>
<td>



Bit 16:23

</td>
<td>



Bit 16:25

</td>
<td>



Bit 16:27

</td>
</tr>
<tr>
<td>



Cr chrominance

</td>
<td>



Bit 32:39

</td>
<td>



Bit 32:41

</td>
<td>



Bit 32:43

</td>
</tr>
<tr>
<td>



Must be zero

</td>
<td>



Bit 48:63

</td>
<td>



Bit 48:63

</td>
<td>



Bit 48:63

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE (boolean)`**

  If enabled the decoder expects to receive a single slice per buffer, otherwise the decoder expects a single frame in per buffer. Applicable to the decoder, all codecs.

- **`V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE (boolean)`**

  If the display delay is enabled then the decoder is forced to return a CAPTURE buffer (decoded frame) after processing a certain number of OUTPUT buffers. The delay can be set through `V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY`. This feature can be used for example for generating thumbnails of videos. Applicable to the decoder.

- **`V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY (integer)`**

  Display delay value for decoder. The decoder is forced to return a decoded frame after the set 'display delay' number of frames. If this number is low it may result in frames returned out of display order, in addition the hardware may still be using the returned buffer as a reference picture for subsequent frames.

- **`V4L2_CID_MPEG_VIDEO_AU_DELIMITER (boolean)`**

  If enabled then, AUD (Access Unit Delimiter) NALUs will be generated. That could be useful to find the start of a frame without having to fully parse each NALU. Applicable to the H264 and HEVC encoders.

- **`V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE (boolean)`**

  Enable writing sample aspect ratio in the Video Usability Information. Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-video-h264-vui-sar-idc"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_vui\_sar\_idc -**

  VUI sample aspect ratio indicator for H.264 encoding. The value is defined in the table E-1 in the standard. Applicable to the H264 encoder.


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED`

</td>
<td>



Unspecified

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_1x1`

</td>
<td>



1x1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_12x11`

</td>
<td>



12x11

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_10x11`

</td>
<td>



10x11

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_16x11`

</td>
<td>



16x11

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_40x33`

</td>
<td>



40x33

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_24x11`

</td>
<td>



24x11

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_20x11`

</td>
<td>



20x11

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_32x11`

</td>
<td>



32x11

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_80x33`

</td>
<td>



80x33

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_18x11`

</td>
<td>



18x11

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_15x11`

</td>
<td>



15x11

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_64x33`

</td>
<td>



64x33

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_160x99`

</td>
<td>



160x99

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_4x3`

</td>
<td>



4x3

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_3x2`

</td>
<td>



3x2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_2x1`

</td>
<td>



2x1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED`

</td>
<td>



Extended SAR

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH (integer)`**

  Extended sample aspect ratio width for H.264 VUI encoding. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT (integer)`**

  Extended sample aspect ratio height for H.264 VUI encoding. Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-video-h264-level"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_LEVEL`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_level -**

  The level information for the H264 video elementary stream. Applicable to the H264 encoder. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_1_0`

</td>
<td>



Level 1.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_1B`

</td>
<td>



Level 1B

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_1_1`

</td>
<td>



Level 1.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_1_2`

</td>
<td>



Level 1.2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_1_3`

</td>
<td>



Level 1.3

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_2_0`

</td>
<td>



Level 2.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_2_1`

</td>
<td>



Level 2.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_2_2`

</td>
<td>



Level 2.2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_3_0`

</td>
<td>



Level 3.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_3_1`

</td>
<td>



Level 3.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_3_2`

</td>
<td>



Level 3.2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_4_0`

</td>
<td>



Level 4.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_4_1`

</td>
<td>



Level 4.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_4_2`

</td>
<td>



Level 4.2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_5_0`

</td>
<td>



Level 5.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_5_1`

</td>
<td>



Level 5.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_5_2`

</td>
<td>



Level 5.2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_6_0`

</td>
<td>



Level 6.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_6_1`

</td>
<td>



Level 6.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LEVEL_6_2`

</td>
<td>



Level 6.2

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-video-mpeg2-level"></a>

- **`V4L2_CID_MPEG_VIDEO_MPEG2_LEVEL`**

  (enum)

- **enum v4l2\_mpeg\_video\_mpeg2\_level -**

  The level information for the MPEG2 elementary stream. Applicable to MPEG2 codecs. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_LEVEL_LOW`

</td>
<td>



Low Level (LL)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_LEVEL_MAIN`

</td>
<td>



Main Level (ML)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH_1440`

</td>
<td>



High-1440 Level (H-14)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_LEVEL_HIGH`

</td>
<td>



High Level (HL)

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-video-mpeg4-level"></a>

- **`V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL`**

  (enum)

- **enum v4l2\_mpeg\_video\_mpeg4\_level -**

  The level information for the MPEG4 elementary stream. Applicable to the MPEG4 encoder. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_LEVEL_0`

</td>
<td>



Level 0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B`

</td>
<td>



Level 0b

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_LEVEL_1`

</td>
<td>



Level 1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_LEVEL_2`

</td>
<td>



Level 2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_LEVEL_3`

</td>
<td>



Level 3

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B`

</td>
<td>



Level 3b

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_LEVEL_4`

</td>
<td>



Level 4

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_LEVEL_5`

</td>
<td>



Level 5

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-video-h264-profile"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_PROFILE`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_profile -**

  The profile information for H264. Applicable to the H264 encoder. Possible values are:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{10.2cm}|p{7.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE`

</td>
<td>



Baseline profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE`

</td>
<td>



Constrained Baseline profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_MAIN`

</td>
<td>



Main profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED`

</td>
<td>



Extended profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_HIGH`

</td>
<td>



High profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10`

</td>
<td>



High 10 profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422`

</td>
<td>



High 422 profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE`

</td>
<td>



High 444 Predictive profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10_INTRA`

</td>
<td>



High 10 Intra profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422_INTRA`

</td>
<td>



High 422 Intra profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_INTRA`

</td>
<td>



High 444 Intra profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_CAVLC_444_INTRA`

</td>
<td>



CAVLC 444 Intra profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_BASELINE`

</td>
<td>



Scalable Baseline profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH`

</td>
<td>



Scalable High profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH_INTRA`

</td>
<td>



Scalable High Intra profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH`

</td>
<td>



Stereo High profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH`

</td>
<td>



Multiview High profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_HIGH`

</td>
<td>



Constrained High profile

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-v4l2-mpeg-video-mpeg2-profile"></a>

- **`V4L2_CID_MPEG_VIDEO_MPEG2_PROFILE`**

  (enum)

- **enum v4l2\_mpeg\_video\_mpeg2\_profile -**

  The profile information for MPEG2. Applicable to MPEG2 codecs. Possible values are:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{10.2cm}|p{7.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_PROFILE_SIMPLE`

</td>
<td>



Simple profile (SP)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_PROFILE_MAIN`

</td>
<td>



Main profile (MP)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_PROFILE_SNR_SCALABLE`

</td>
<td>



SNR Scalable profile (SNR)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_PROFILE_SPATIALLY_SCALABLE`

</td>
<td>



Spatially Scalable profile (Spt)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_PROFILE_HIGH`

</td>
<td>



High profile (HP)

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG2_PROFILE_MULTIVIEW`

</td>
<td>



Multi-view profile (MVP)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-v4l2-mpeg-video-mpeg4-profile"></a>

- **`V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE`**

  (enum)

- **enum v4l2\_mpeg\_video\_mpeg4\_profile -**

  The profile information for MPEG4. Applicable to the MPEG4 encoder. Possible values are:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{11.8cm}|p{5.7cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE`

</td>
<td>



Simple profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE`

</td>
<td>



Advanced Simple profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE`

</td>
<td>



Core profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE`

</td>
<td>



Simple Scalable profile

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY`

</td>
<td>



Advanced Coding Efficiency profile

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_MAX_REF_PIC (integer)`**

  The maximum number of reference pictures used for encoding. Applicable to the encoder.

<a id="rst-v4l2-mpeg-video-multi-slice-mode"></a>

- **`V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE`**

  (enum)

- **enum v4l2\_mpeg\_video\_multi\_slice\_mode -**

  Determines how the encoder should handle division of frame into slices. Applicable to the encoder. Possible values are:

<!-- tabularcolumns: |p{9.6cm}|p{7.9cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE`

</td>
<td>



Single slice per frame.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_MB`

</td>
<td>



Multiple slices with set maximum number of macroblocks per slice.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES`

</td>
<td>



Multiple slice with set maximum size in bytes per slice.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB (integer)`**

  The maximum number of macroblocks in a slice. Used when `V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE` is set to `V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_MB`. Applicable to the encoder.

- **`V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES (integer)`**

  The maximum size of a slice in bytes. Used when `V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE` is set to `V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_MAX_BYTES`. Applicable to the encoder.

<a id="rst-v4l2-mpeg-video-h264-loop-filter-mode"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_loop\_filter\_mode -**

  Loop filter mode for H264 encoder. Possible values are:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{13.5cm}|p{4.0cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED`

</td>
<td>



Loop filter is enabled.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED`

</td>
<td>



Loop filter is disabled.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY`

</td>
<td>



Loop filter is disabled at the slice boundary.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA (integer)`**

  Loop filter alpha coefficient, defined in the H264 standard. This value corresponds to the slice\_alpha\_c0\_offset\_div2 slice header field, and should be in the range of -6 to +6, inclusive. The actual alpha offset FilterOffsetA is twice this value. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA (integer)`**

  Loop filter beta coefficient, defined in the H264 standard. This corresponds to the slice\_beta\_offset\_div2 slice header field, and should be in the range of -6 to +6, inclusive. The actual beta offset FilterOffsetB is twice this value. Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-video-h264-entropy-mode"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_entropy\_mode -**

  Entropy coding mode for H264 - CABAC/CAVALC. Applicable to the H264 encoder. Possible values are:

<!-- tabularcolumns: |p{9.0cm}|p{8.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC`

</td>
<td>



Use CAVLC entropy coding.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC`

</td>
<td>



Use CABAC entropy coding.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM (boolean)`**

  Enable 8X8 transform for H264. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_CONSTRAINED_INTRA_PREDICTION (boolean)`**

  Enable constrained intra prediction for H264. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_CHROMA_QP_INDEX_OFFSET (integer)`**

  Specify the offset that should be added to the luma quantization parameter to determine the chroma quantization parameter. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB (integer)`**

  Cyclic intra macroblock refresh. This is the number of continuous macroblocks refreshed every frame. Each frame a successive set of macroblocks is refreshed until the cycle completes and starts from the top of the frame. Setting this control to zero means that macroblocks will not be refreshed.  Note that this control will not take effect when `V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD` control is set to non zero value. Applicable to H264, H263 and MPEG4 encoder.

`V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE (enum)`

- **enum v4l2\_mpeg\_video\_intra\_refresh\_period\_type -**

  Sets the type of intra refresh. The period to refresh the whole frame is specified by V4L2\_CID\_MPEG\_VIDEO\_INTRA\_REFRESH\_PERIOD. Note that if this control is not present, then it is undefined what refresh type is used and it is up to the driver to decide. Applicable to H264 and HEVC encoders. Possible values are:

<!-- tabularcolumns: |p{9.6cm}|p{7.9cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_RANDOM`

</td>
<td>



The whole frame is completely refreshed randomly after the specified period.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_INTRA_REFRESH_PERIOD_TYPE_CYCLIC`

</td>
<td>



The whole frame MBs are completely refreshed in cyclic order after the specified period.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_INTRA_REFRESH_PERIOD (integer)`**

  Intra macroblock refresh period. This sets the period to refresh the whole frame. In other words, this defines the number of frames for which the whole frame will be intra-refreshed.  An example: setting period to 1 means that the whole frame will be refreshed, setting period to 2 means that the half of macroblocks will be intra-refreshed on frameX and the other half of macroblocks will be refreshed in frameX + 1 and so on. Setting the period to zero means no period is specified. Note that if the client sets this control to non zero value the `V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB` control shall be ignored. Applicable to H264 and HEVC encoders.

- **`V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE (boolean)`**

  Frame level rate control enable. If this control is disabled then the quantization parameter for each frame type is constant and set with appropriate controls (e.g. `V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP`). If frame rate control is enabled then quantization parameter is adjusted to meet the chosen bitrate. Minimum and maximum value for the quantization parameter can be set with appropriate controls (e.g. `V4L2_CID_MPEG_VIDEO_H263_MIN_QP`). Applicable to encoders.

- **`V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE (boolean)`**

  Macroblock level rate control enable. Applicable to the MPEG4 and H264 encoders.

- **`V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (boolean)`**

  Quarter pixel motion estimation for MPEG4. Applicable to the MPEG4 encoder.

- **`V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP (integer)`**

  Quantization parameter for an I frame for H263. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_H263_MIN_QP (integer)`**

  Minimum quantization parameter for H263. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_H263_MAX_QP (integer)`**

  Maximum quantization parameter for H263. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP (integer)`**

  Quantization parameter for an P frame for H263. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP (integer)`**

  Quantization parameter for an B frame for H263. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP (integer)`**

  Quantization parameter for an I frame for H264. Valid range: from 0 to 51.

- **`V4L2_CID_MPEG_VIDEO_H264_MIN_QP (integer)`**

  Minimum quantization parameter for H264. Valid range: from 0 to 51.

- **`V4L2_CID_MPEG_VIDEO_H264_MAX_QP (integer)`**

  Maximum quantization parameter for H264. Valid range: from 0 to 51.

- **`V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP (integer)`**

  Quantization parameter for an P frame for H264. Valid range: from 0 to 51.

- **`V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP (integer)`**

  Quantization parameter for an B frame for H264. Valid range: from 0 to 51.

- **`V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MIN_QP (integer)`**

  Minimum quantization parameter for the H264 I frame to limit I frame quality to a range. Valid range: from 0 to 51. If V4L2\_CID\_MPEG\_VIDEO\_H264\_MIN\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_H264_I_FRAME_MAX_QP (integer)`**

  Maximum quantization parameter for the H264 I frame to limit I frame quality to a range. Valid range: from 0 to 51. If V4L2\_CID\_MPEG\_VIDEO\_H264\_MAX\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MIN_QP (integer)`**

  Minimum quantization parameter for the H264 P frame to limit P frame quality to a range. Valid range: from 0 to 51. If V4L2\_CID\_MPEG\_VIDEO\_H264\_MIN\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_H264_P_FRAME_MAX_QP (integer)`**

  Maximum quantization parameter for the H264 P frame to limit P frame quality to a range. Valid range: from 0 to 51. If V4L2\_CID\_MPEG\_VIDEO\_H264\_MAX\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MIN_QP (integer)`**

  Minimum quantization parameter for the H264 B frame to limit B frame quality to a range. Valid range: from 0 to 51. If V4L2\_CID\_MPEG\_VIDEO\_H264\_MIN\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_H264_B_FRAME_MAX_QP (integer)`**

  Maximum quantization parameter for the H264 B frame to limit B frame quality to a range. Valid range: from 0 to 51. If V4L2\_CID\_MPEG\_VIDEO\_H264\_MAX\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP (integer)`**

  Quantization parameter for an I frame for MPEG4. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP (integer)`**

  Minimum quantization parameter for MPEG4. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP (integer)`**

  Maximum quantization parameter for MPEG4. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP (integer)`**

  Quantization parameter for an P frame for MPEG4. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP (integer)`**

  Quantization parameter for an B frame for MPEG4. Valid range: from 1 to 31.

<a id="rst-v4l2-mpeg-video-vbv-size"></a>

- **`V4L2_CID_MPEG_VIDEO_VBV_SIZE (integer)`**

  The Video Buffer Verifier size in kilobytes, it is used as a limitation of frame skip. The VBV is defined in the standard as a mean to verify that the produced stream will be successfully decoded. The standard describes it as "Part of a hypothetical decoder that is conceptually connected to the output of the encoder. Its purpose is to provide a constraint on the variability of the data rate that an encoder or editing process may produce.". Applicable to the MPEG1, MPEG2, MPEG4 encoders.

<a id="rst-v4l2-mpeg-video-vbv-delay"></a>

- **`V4L2_CID_MPEG_VIDEO_VBV_DELAY (integer)`**

  Sets the initial delay in milliseconds for VBV buffer control.

<a id="rst-v4l2-mpeg-video-hor-search-range"></a>

- **`V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE (integer)`**

  Horizontal search range defines maximum horizontal search area in pixels to search and match for the present Macroblock (MB) in the reference picture. This V4L2 control macro is used to set horizontal search range for motion estimation module in video encoder.

<a id="rst-v4l2-mpeg-video-vert-search-range"></a>

- **`V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE (integer)`**

  Vertical search range defines maximum vertical search area in pixels to search and match for the present Macroblock (MB) in the reference picture. This V4L2 control macro is used to set vertical search range for motion estimation module in video encoder.

<a id="rst-v4l2-mpeg-video-force-key-frame"></a>

- **`V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME (button)`**

  Force a key frame for the next queued buffer. Applicable to encoders. This is a general, codec-agnostic keyframe control.

<a id="rst-v4l2-mpeg-video-h264-cpb-size"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE (integer)`**

  The Coded Picture Buffer size in kilobytes, it is used as a limitation of frame skip. The CPB is defined in the H264 standard as a mean to verify that the produced stream will be successfully decoded. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_I_PERIOD (integer)`**

  Period between I-frames in the open GOP for H264. In case of an open GOP this is the period between two I-frames. The period between IDR (Instantaneous Decoding Refresh) frames is taken from the GOP\_SIZE control. An IDR frame, which stands for Instantaneous Decoding Refresh is an I-frame after which no prior frames are referenced. This means that a stream can be restarted from an IDR frame without the need to store or decode any previous frames. Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-video-header-mode"></a>

- **`V4L2_CID_MPEG_VIDEO_HEADER_MODE`**

  (enum)

- **enum v4l2\_mpeg\_video\_header\_mode -**

  Determines whether the header is returned as the first buffer or is it returned together with the first frame. Applicable to encoders. Possible values are:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{10.3cm}|p{7.2cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE`

</td>
<td>



The stream header is returned separately in the first buffer.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME`

</td>
<td>



The stream header is returned together with the first encoded frame.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER (boolean)`**

  Repeat the video sequence headers. Repeating these headers makes random access to the video stream easier. Applicable to the MPEG1, 2 and 4 encoder.

- **`V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER (boolean)`**

  Enabled the deblocking post processing filter for MPEG4 decoder. Applicable to the MPEG4 decoder.

- **`V4L2_CID_MPEG_VIDEO_MPEG4_VOP_TIME_RES (integer)`**

  vop\_time\_increment\_resolution value for MPEG4. Applicable to the MPEG4 encoder.

- **`V4L2_CID_MPEG_VIDEO_MPEG4_VOP_TIME_INC (integer)`**

  vop\_time\_increment value for MPEG4. Applicable to the MPEG4 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_SEI_FRAME_PACKING (boolean)`**

  Enable generation of frame packing supplemental enhancement information in the encoded bitstream. The frame packing SEI message contains the arrangement of L and R planes for 3D viewing. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0 (boolean)`**

  Sets current frame as frame0 in frame packing SEI. Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-video-h264-sei-fp-arrangement-type"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_sei\_fp\_arrangement\_type -**

  Frame packing arrangement type for H264 SEI. Applicable to the H264 encoder. Possible values are:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{12cm}|p{5.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_CHEKERBOARD`

</td>
<td>



Pixels are alternatively from L and R.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_COLUMN`

</td>
<td>



L and R are interlaced by column.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_ROW`

</td>
<td>



L and R are interlaced by row.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_SIDE_BY_SIDE`

</td>
<td>



L is on the left, R on the right.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TOP_BOTTOM`

</td>
<td>



L is on top, R on bottom.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TEMPORAL`

</td>
<td>



One view per frame.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_H264_FMO (boolean)`**

  Enables flexible macroblock ordering in the encoded bitstream. It is a technique used for restructuring the ordering of macroblocks in pictures. Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-video-h264-fmo-map-type"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_fmo\_map\_type -**

  When using FMO, the map type divides the image in different scan patterns of macroblocks. Applicable to the H264 encoder. Possible values are:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{12.5cm}|p{5.0cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES`

</td>
<td>



Slices are interleaved one after other with macroblocks in run length order.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES`

</td>
<td>



Scatters the macroblocks based on a mathematical function known to both encoder and decoder.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_FOREGROUND_WITH_LEFT_OVER`

</td>
<td>



Macroblocks arranged in rectangular areas or regions of interest.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_BOX_OUT`

</td>
<td>



Slice groups grow in a cyclic way from centre to outwards.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN`

</td>
<td>



Slice groups grow in raster scan pattern from left to right.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN`

</td>
<td>



Slice groups grow in wipe scan pattern from top to bottom.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_EXPLICIT`

</td>
<td>



User defined map type.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_H264_FMO_SLICE_GROUP (integer)`**

  Number of slice groups in FMO. Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-video-h264-fmo-change-direction"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_fmo\_change\_dir -**

  Specifies a direction of the slice group change for raster and wipe maps. Applicable to the H264 encoder. Possible values are:

<!-- tabularcolumns: |p{9.6cm}|p{7.9cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_RIGHT`

</td>
<td>



Raster scan or wipe right.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_LEFT`

</td>
<td>



Reverse raster scan or wipe left.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_RATE (integer)`**

  Specifies the size of the first slice group for raster and wipe map. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_FMO_RUN_LENGTH (integer)`**

  Specifies the number of consecutive macroblocks for the interleaved map. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_ASO (boolean)`**

  Enables arbitrary slice ordering in encoded bitstream. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_ASO_SLICE_ORDER (integer)`**

  Specifies the slice order in ASO. Applicable to the H264 encoder. The supplied 32-bit integer is interpreted as follows (bit 0 = least significant bit):


<table>
<tbody>
<tr>
<td>



Bit 0:15

</td>
<td>



Slice ID

</td>
</tr>
<tr>
<td>



Bit 16:32

</td>
<td>



Slice position or order

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING (boolean)`**

  Enables H264 hierarchical coding. Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-video-h264-hierarchical-coding-type"></a>

- **`V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_video\_h264\_hierarchical\_coding\_type -**

  Specifies the hierarchical coding type. Applicable to the H264 encoder. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B`

</td>
<td>



Hierarchical B coding.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P`

</td>
<td>



Hierarchical P coding.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER (integer)`**

  Specifies the number of hierarchical coding layers. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP (integer)`**

  Specifies a user defined QP for each layer. Applicable to the H264 encoder. The supplied 32-bit integer is interpreted as follows (bit 0 = least significant bit):


<table>
<tbody>
<tr>
<td>



Bit 0:15

</td>
<td>



QP value

</td>
</tr>
<tr>
<td>



Bit 16:32

</td>
<td>



Layer number

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L0_BR (integer)`**

  Indicates bit rate (bps) for hierarchical coding layer 0 for H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L1_BR (integer)`**

  Indicates bit rate (bps) for hierarchical coding layer 1 for H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L2_BR (integer)`**

  Indicates bit rate (bps) for hierarchical coding layer 2 for H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L3_BR (integer)`**

  Indicates bit rate (bps) for hierarchical coding layer 3 for H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L4_BR (integer)`**

  Indicates bit rate (bps) for hierarchical coding layer 4 for H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L5_BR (integer)`**

  Indicates bit rate (bps) for hierarchical coding layer 5 for H264 encoder.

- **`V4L2_CID_MPEG_VIDEO_H264_HIER_CODING_L6_BR (integer)`**

  Indicates bit rate (bps) for hierarchical coding layer 6 for H264 encoder.

- **`V4L2_CID_FWHT_I_FRAME_QP (integer)`**

  Quantization parameter for an I frame for FWHT. Valid range: from 1 to 31.

- **`V4L2_CID_FWHT_P_FRAME_QP (integer)`**

  Quantization parameter for a P frame for FWHT. Valid range: from 1 to 31.

- **`V4L2_CID_MPEG_VIDEO_AVERAGE_QP (integer)`**

  This read-only control returns the average QP value of the currently encoded frame. The value applies to the last dequeued capture buffer (VIDIOC\_DQBUF). Its valid range depends on the encoding format and parameters. For H264, its valid range is from 0 to 51. For HEVC, its valid range is from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. For H263 and MPEG4, its valid range is from 1 to 31. For VP8, its valid range is from 0 to 127. For VP9, its valid range is from 0 to 255. If the codec's MIN\_QP and MAX\_QP are set, then the QP will meet both requirements. Codecs need to always use the specified range, rather then a HW custom range. Applicable to encoders

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-mfc-5-1-mpeg-controls"></a>

## MFC 5.1 MPEG Controls

The following MPEG class controls deal with MPEG decoding and encoding settings that are specific to the Multi Format Codec 5.1 device present in the S5P family of SoCs by Samsung.

<a id="rst-mfc-5-1-control-ids"></a>
<a id="rst-mfc51-control-id"></a>

### MFC 5.1 Control IDs

- **`V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE (boolean)`**

  If the display delay is enabled then the decoder is forced to return a CAPTURE buffer (decoded frame) after processing a certain number of OUTPUT buffers. The delay can be set through `V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY`. This feature can be used for example for generating thumbnails of videos. Applicable to the H264 decoder.

  > [!NOTE]
  >
  > This control is deprecated. Use the standard `V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE` control instead.

- **`V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY (integer)`**

  Display delay value for H264 decoder. The decoder is forced to return a decoded frame after the set 'display delay' number of frames. If this number is low it may result in frames returned out of display order, in addition the hardware may still be using the returned buffer as a reference picture for subsequent frames.

  > [!NOTE]
  >
  > This control is deprecated. Use the standard `V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY` control instead.

- **`V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P (integer)`**

  The number of reference pictures used for encoding a P picture. Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_MFC51_VIDEO_PADDING (boolean)`**

  Padding enable in the encoder - use a color instead of repeating border pixels. Applicable to encoders.

- **`V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV (integer)`**

  Padding color in the encoder. Applicable to encoders. The supplied 32-bit integer is interpreted as follows (bit 0 = least significant bit):


<table>
<tbody>
<tr>
<td>



Bit 0:7

</td>
<td>



V chrominance information

</td>
</tr>
<tr>
<td>



Bit 8:15

</td>
<td>



U chrominance information

</td>
</tr>
<tr>
<td>



Bit 16:23

</td>
<td>



Y luminance information

</td>
</tr>
<tr>
<td>



Bit 24:31

</td>
<td>



Must be zero.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF (integer)`**

  Reaction coefficient for MFC rate control. Applicable to encoders.

  > [!NOTE]
  >
  > 1. Valid only when the frame level RC is enabled.
  >
  > 2. For tight CBR, this field must be small (ex. 2 \~ 10). For VBR, this field must be large (ex. 100 \~ 1000).
  >
  > 3. It is not recommended to use the greater number than FRAME\_RATE \* (10^9 / BIT\_RATE).

- **`V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK (boolean)`**

  Adaptive rate control for dark region. Valid only when H.264 and macroblock level RC is enabled (`V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE`). Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH (boolean)`**

  Adaptive rate control for smooth region. Valid only when H.264 and macroblock level RC is enabled (`V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE`). Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC (boolean)`**

  Adaptive rate control for static region. Valid only when H.264 and macroblock level RC is enabled (`V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE`). Applicable to the H264 encoder.

- **`V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY (boolean)`**

  Adaptive rate control for activity region. Valid only when H.264 and macroblock level RC is enabled (`V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE`). Applicable to the H264 encoder.

<a id="rst-v4l2-mpeg-mfc51-video-frame-skip-mode"></a>

- **`V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE`**

  (enum)

  > [!NOTE]
  >
  > This control is deprecated. Use the standard `V4L2_CID_MPEG_VIDEO_FRAME_SKIP_MODE` control instead.

- **enum v4l2\_mpeg\_mfc51\_video\_frame\_skip\_mode -**

  Indicates in what conditions the encoder should skip frames. If encoding a frame would cause the encoded stream to be larger then a chosen data limit then the frame will be skipped. Possible values are:

<!-- tabularcolumns: |p{9.4cm}|p{8.1cm}| -->

<!-- Source LaTeX layout: \small -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED`

</td>
<td>



Frame skip mode is disabled.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_LEVEL_LIMIT`

</td>
<td>



Frame skip mode enabled and buffer limit is set by the chosen level and is defined by the standard.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT`

</td>
<td>



Frame skip mode enabled and buffer limit is set by the VBV (MPEG1/2/4) or CPB (H264) buffer size control.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT (integer)`**

  Enable rate-control with fixed target bit. If this setting is enabled, then the rate control logic of the encoder will calculate the average bitrate for a GOP and keep it below or equal the set bitrate target. Otherwise the rate control logic calculates the overall average bitrate for the stream and keeps it below or equal to the set bitrate. In the first case the average bitrate for the whole stream will be smaller then the set bitrate. This is caused because the average is calculated for smaller number of frames, on the other hand enabling this setting will ensure that the stream will meet tight bandwidth constraints. Applicable to encoders.

<a id="rst-v4l2-mpeg-mfc51-video-force-frame-type"></a>

- **`V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_mfc51\_video\_force\_frame\_type -**

  Force a frame type for the next queued buffer. Applicable to encoders. Possible values are:

<!-- tabularcolumns: |p{9.9cm}|p{7.6cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_MFC51_FORCE_FRAME_TYPE_DISABLED`

</td>
<td>



Forcing a specific frame type disabled.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_MFC51_FORCE_FRAME_TYPE_I_FRAME`

</td>
<td>



Force an I-frame.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_MFC51_FORCE_FRAME_TYPE_NOT_CODED`

</td>
<td>



Force a non-coded frame.

</td>
</tr>
</tbody>
</table>

<a id="rst-cx2341x-mpeg-controls"></a>

## CX2341x MPEG Controls

The following MPEG class controls deal with MPEG encoding settings that are specific to the Conexant CX23415 and CX23416 MPEG encoding chips.

<a id="rst-cx2341x-control-ids"></a>
<a id="rst-cx2341x-control-id"></a>

### CX2341x Control IDs

<a id="rst-v4l2-mpeg-cx2341x-video-spatial-filter-mode"></a>

- **`V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE`**

  (enum)

- **enum v4l2\_mpeg\_cx2341x\_video\_spatial\_filter\_mode -**

  Sets the Spatial Filter mode (default `MANUAL`). Possible values are:

<!-- tabularcolumns: |p{11.5cm}|p{6.0cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL`

</td>
<td>



Choose the filter manually

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO`

</td>
<td>



Choose the filter automatically

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER (integer (0-15))`**

  The setting for the Spatial Filter. 0 = off, 15 = maximum. (Default is 0.)

<a id="rst-luma-spatial-filter-type"></a>

- **`V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_cx2341x\_video\_luma\_spatial\_filter\_type -**

  Select the algorithm to use for the Luma Spatial Filter (default `1D_HOR`). Possible values:

<!-- tabularcolumns: |p{13.1cm}|p{4.4cm}| -->

<!-- Source LaTeX layout: \footnotesize -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF`

</td>
<td>



No filter

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR`

</td>
<td>



One-dimensional horizontal

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT`

</td>
<td>



One-dimensional vertical

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE`

</td>
<td>



Two-dimensional separable

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE`

</td>
<td>



Two-dimensional symmetrical non-separable

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-chroma-spatial-filter-type"></a>

- **`V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_cx2341x\_video\_chroma\_spatial\_filter\_type -**

  Select the algorithm for the Chroma Spatial Filter (default `1D_HOR`). Possible values are:

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{11.0cm}|p{6.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF`

</td>
<td>



No filter

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR`

</td>
<td>



One-dimensional horizontal

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-v4l2-mpeg-cx2341x-video-temporal-filter-mode"></a>

- **`V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE`**

  (enum)

- **enum v4l2\_mpeg\_cx2341x\_video\_temporal\_filter\_mode -**

  Sets the Temporal Filter mode (default `MANUAL`). Possible values are:

<!-- Source LaTeX layout: \footnotesize -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL`

</td>
<td>



Choose the filter manually

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO`

</td>
<td>



Choose the filter automatically

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER (integer (0-31))`**

  The setting for the Temporal Filter. 0 = off, 31 = maximum. (Default is 8 for full-scale capturing and 0 for scaled capturing.)

<a id="rst-v4l2-mpeg-cx2341x-video-median-filter-type"></a>

- **`V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_cx2341x\_video\_median\_filter\_type -**

  Median Filter Type (default `OFF`). Possible values are:

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{11.0cm}|p{6.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF`

</td>
<td>



No filter

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR`

</td>
<td>



Horizontal filter

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT`

</td>
<td>



Vertical filter

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT`

</td>
<td>



Horizontal and vertical filter

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG`

</td>
<td>



Diagonal filter

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM (integer (0-255))`**

  Threshold above which the luminance median filter is enabled (default 0)

- **`V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (integer (0-255))`**

  Threshold below which the luminance median filter is enabled (default 255)

- **`V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM (integer (0-255))`**

  Threshold above which the chroma median filter is enabled (default 0)

- **`V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (integer (0-255))`**

  Threshold below which the chroma median filter is enabled (default 255)

- **`V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (boolean)`**

  The CX2341X MPEG encoder can insert one empty MPEG-2 PES packet into the stream between every four video frames. The packet size is 2048 bytes, including the packet\_start\_code\_prefix and stream\_id fields. The stream\_id is 0xBF (private stream 2). The payload consists of 0x00 bytes, to be filled in by the application. 0 = do not insert, 1 = insert packets.

<a id="rst-vpx-control-reference"></a>

## VPX Control Reference

The VPX controls include controls for encoding parameters of VPx video codec.

<a id="rst-vpx-control-ids"></a>
<a id="rst-vpx-control-id"></a>

### VPX Control IDs

<a id="rst-v4l2-vpx-num-partitions"></a>

- **`V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS`**

  (enum)

- **enum v4l2\_vp8\_num\_partitions -**

  The number of token partitions to use in VP8 encoder. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION`

</td>
<td>



1 coefficient partition

</td>
</tr>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS`

</td>
<td>



2 coefficient partitions

</td>
</tr>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS`

</td>
<td>



4 coefficient partitions

</td>
</tr>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS`

</td>
<td>



8 coefficient partitions

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4 (boolean)`**

  Setting this prevents intra 4x4 mode in the intra mode decision.

<a id="rst-v4l2-vpx-num-ref-frames"></a>

- **`V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES`**

  (enum)

- **enum v4l2\_vp8\_num\_ref\_frames -**

  The number of reference pictures for encoding P frames. Possible values are:

<!-- tabularcolumns: |p{7.5cm}|p{7.5cm}| -->

<!-- Source LaTeX layout: \small -->


<table>
<tbody>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME`

</td>
<td>



Last encoded frame will be searched

</td>
</tr>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME`

</td>
<td>



Two frames will be searched among the last encoded frame, the golden frame and the alternate reference (altref) frame. The encoder implementation will decide which two are chosen.

</td>
</tr>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_3_REF_FRAME`

</td>
<td>



The last encoded frame, the golden frame and the altref frame will be searched.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL (integer)`**

  Indicates the loop filter level. The adjustment of the loop filter level is done via a delta value against a baseline loop filter value.

- **`V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS (integer)`**

  This parameter affects the loop filter. Anything above zero weakens the deblocking effect on the loop filter.

- **`V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD (integer)`**

  Sets the refresh period for the golden frame. The period is defined in number of frames. For a value of 'n', every nth frame starting from the first key frame will be taken as a golden frame. For eg. for encoding sequence of 0, 1, 2, 3, 4, 5, 6, 7 where the golden frame refresh period is set as 4, the frames 0, 4, 8 etc will be taken as the golden frames as frame 0 is always a key frame.

<a id="rst-v4l2-vpx-golden-frame-sel"></a>

- **`V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL`**

  (enum)

- **enum v4l2\_vp8\_golden\_frame\_sel -**

  Selects the golden frame for encoding. Possible values are:

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{8.6cm}|p{8.9cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV`

</td>
<td>



Use the (n-2)th frame as a golden frame, current frame index being 'n'.

</td>
</tr>
<tr>
<td>



`V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD`

</td>
<td>



Use the previous specific frame indicated by `V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD` as a golden frame.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_VPX_MIN_QP (integer)`**

  Minimum quantization parameter for VP8.

- **`V4L2_CID_MPEG_VIDEO_VPX_MAX_QP (integer)`**

  Maximum quantization parameter for VP8.

- **`V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP (integer)`**

  Quantization parameter for an I frame for VP8.

- **`V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP (integer)`**

  Quantization parameter for a P frame for VP8.

<a id="rst-v4l2-mpeg-video-vp8-profile"></a>

- **`V4L2_CID_MPEG_VIDEO_VP8_PROFILE`**

  (enum)

- **enum v4l2\_mpeg\_video\_vp8\_profile -**

  This control allows selecting the profile for VP8 encoder. This is also used to enumerate supported profiles by VP8 encoder or decoder. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP8_PROFILE_0`

</td>
<td>



Profile 0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP8_PROFILE_1`

</td>
<td>



Profile 1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP8_PROFILE_2`

</td>
<td>



Profile 2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP8_PROFILE_3`

</td>
<td>



Profile 3

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-video-vp9-profile"></a>

- **`V4L2_CID_MPEG_VIDEO_VP9_PROFILE`**

  (enum)

- **enum v4l2\_mpeg\_video\_vp9\_profile -**

  This control allows selecting the profile for VP9 encoder. This is also used to enumerate supported profiles by VP9 encoder or decoder. Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_PROFILE_0`

</td>
<td>



Profile 0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_PROFILE_1`

</td>
<td>



Profile 1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_PROFILE_2`

</td>
<td>



Profile 2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_PROFILE_3`

</td>
<td>



Profile 3

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mpeg-video-vp9-level"></a>

`V4L2_CID_MPEG_VIDEO_VP9_LEVEL (enum)`

- **enum v4l2\_mpeg\_video\_vp9\_level -**

  This control allows selecting the level for VP9 encoder. This is also used to enumerate supported levels by VP9 encoder or decoder. More information can be found at [webmproject](<https://www.webmproject.org/vp9/levels/>). Possible values are:


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_1_0`

</td>
<td>



Level 1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_1_1`

</td>
<td>



Level 1.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_2_0`

</td>
<td>



Level 2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_2_1`

</td>
<td>



Level 2.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_3_0`

</td>
<td>



Level 3

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_3_1`

</td>
<td>



Level 3.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_4_0`

</td>
<td>



Level 4

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_4_1`

</td>
<td>



Level 4.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_5_0`

</td>
<td>



Level 5

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_5_1`

</td>
<td>



Level 5.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_5_2`

</td>
<td>



Level 5.2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_6_0`

</td>
<td>



Level 6

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_6_1`

</td>
<td>



Level 6.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_VP9_LEVEL_6_2`

</td>
<td>



Level 6.2

</td>
</tr>
</tbody>
</table>

<a id="rst-high-efficiency-video-coding-hevc-h-265-control-reference"></a>

## High Efficiency Video Coding (HEVC/H.265) Control Reference

The HEVC/H.265 controls include controls for encoding parameters of HEVC/H.265 video codec.

<a id="rst-hevc-h-265-control-ids"></a>
<a id="rst-hevc-control-id"></a>

### HEVC/H.265 Control IDs

- **`V4L2_CID_MPEG_VIDEO_HEVC_MIN_QP (integer)`**

  Minimum quantization parameter for HEVC. Valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit.

- **`V4L2_CID_MPEG_VIDEO_HEVC_MAX_QP (integer)`**

  Maximum quantization parameter for HEVC. Valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit.

- **`V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_QP (integer)`**

  Quantization parameter for an I frame for HEVC. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_QP (integer)`**

  Quantization parameter for a P frame for HEVC. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_QP (integer)`**

  Quantization parameter for a B frame for HEVC. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MIN_QP (integer)`**

  Minimum quantization parameter for the HEVC I frame to limit I frame quality to a range. Valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. If V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_HEVC_I_FRAME_MAX_QP (integer)`**

  Maximum quantization parameter for the HEVC I frame to limit I frame quality to a range. Valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. If V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MIN_QP (integer)`**

  Minimum quantization parameter for the HEVC P frame to limit P frame quality to a range. Valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. If V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_HEVC_P_FRAME_MAX_QP (integer)`**

  Maximum quantization parameter for the HEVC P frame to limit P frame quality to a range. Valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. If V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MIN_QP (integer)`**

  Minimum quantization parameter for the HEVC B frame to limit B frame quality to a range. Valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. If V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_HEVC_B_FRAME_MAX_QP (integer)`**

  Maximum quantization parameter for the HEVC B frame to limit B frame quality to a range. Valid range: from 0 to 51 for 8 bit and from 0 to 63 for 10 bit. If V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP is also set, the quantization parameter should be chosen to meet both requirements.

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_QP (boolean)`**

  HIERARCHICAL\_QP allows the host to specify the quantization parameter values for each temporal layer through HIERARCHICAL\_QP\_LAYER. This is valid only if HIERARCHICAL\_CODING\_LAYER is greater than 1. Setting the control value to 1 enables setting of the QP values for the layers.

<a id="rst-v4l2-hevc-hier-coding-type"></a>

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_video\_hevc\_hier\_coding\_type -**

  Selects the hierarchical coding type for encoding. Possible values are:

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{8.2cm}|p{9.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_B`

</td>
<td>



Use the B frame for hierarchical coding.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_HIERARCHICAL_CODING_P`

</td>
<td>



Use the P frame for hierarchical coding.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_LAYER (integer)`**

  Selects the hierarchical coding layer. In normal encoding (non-hierarchial coding), it should be zero. Possible values are \[0, 6\]. 0 indicates HIERARCHICAL CODING LAYER 0, 1 indicates HIERARCHICAL CODING LAYER 1 and so on.

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_QP (integer)`**

  Indicates quantization parameter for hierarchical coding layer 0. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_QP (integer)`**

  Indicates quantization parameter for hierarchical coding layer 1. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_QP (integer)`**

  Indicates quantization parameter for hierarchical coding layer 2. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_QP (integer)`**

  Indicates quantization parameter for hierarchical coding layer 3. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_QP (integer)`**

  Indicates quantization parameter for hierarchical coding layer 4. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_QP (integer)`**

  Indicates quantization parameter for hierarchical coding layer 5. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_QP (integer)`**

  Indicates quantization parameter for hierarchical coding layer 6. Valid range: \[V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MIN\_QP, V4L2\_CID\_MPEG\_VIDEO\_HEVC\_MAX\_QP\].

<a id="rst-v4l2-hevc-profile"></a>

- **`V4L2_CID_MPEG_VIDEO_HEVC_PROFILE`**

  (enum)

- **enum v4l2\_mpeg\_video\_hevc\_profile -**

  Select the desired profile for HEVC encoder.

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{9.0cm}|p{8.5cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN`

</td>
<td>



Main profile.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_STILL_PICTURE`

</td>
<td>



Main still picture profile.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10`

</td>
<td>



Main 10 profile.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-v4l2-hevc-level"></a>

- **`V4L2_CID_MPEG_VIDEO_HEVC_LEVEL`**

  (enum)

- **enum v4l2\_mpeg\_video\_hevc\_level -**

  Selects the desired level for HEVC encoder.


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_1`

</td>
<td>



Level 1.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_2`

</td>
<td>



Level 2.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_2_1`

</td>
<td>



Level 2.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_3`

</td>
<td>



Level 3.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_3_1`

</td>
<td>



Level 3.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_4`

</td>
<td>



Level 4.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_4_1`

</td>
<td>



Level 4.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_5`

</td>
<td>



Level 5.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1`

</td>
<td>



Level 5.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_5_2`

</td>
<td>



Level 5.2

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_6`

</td>
<td>



Level 6.0

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_6_1`

</td>
<td>



Level 6.1

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LEVEL_6_2`

</td>
<td>



Level 6.2

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_HEVC_FRAME_RATE_RESOLUTION (integer)`**

  Indicates the number of evenly spaced subintervals, called ticks, within one second. This is a 16 bit unsigned integer and has a maximum value up to 0xffff and a minimum value of 1.

<a id="rst-v4l2-hevc-tier"></a>

- **`V4L2_CID_MPEG_VIDEO_HEVC_TIER`**

  (enum)

- **enum v4l2\_mpeg\_video\_hevc\_tier -**

  TIER\_FLAG specifies tiers information of the HEVC encoded picture. Tier were made to deal with applications that differ in terms of maximum bit rate. Setting the flag to 0 selects HEVC tier as Main tier and setting this flag to 1 indicates High tier. High tier is for applications requiring high bit rates.


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_TIER_MAIN`

</td>
<td>



Main tier.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_TIER_HIGH`

</td>
<td>



High tier.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_MPEG_VIDEO_HEVC_MAX_PARTITION_DEPTH (integer)`**

  Selects HEVC maximum coding unit depth.

<a id="rst-v4l2-hevc-loop-filter-mode"></a>

- **`V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE`**

  (enum)

- **enum v4l2\_mpeg\_video\_hevc\_loop\_filter\_mode -**

  Loop filter mode for HEVC encoder. Possible values are:

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{12.1cm}|p{5.4cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED`

</td>
<td>



Loop filter is disabled.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_ENABLED`

</td>
<td>



Loop filter is enabled.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY`

</td>
<td>



Loop filter is disabled at the slice boundary.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_HEVC_LF_BETA_OFFSET_DIV2 (integer)`**

  Selects HEVC loop filter beta offset. The valid range is \[-6, +6\].

- **`V4L2_CID_MPEG_VIDEO_HEVC_LF_TC_OFFSET_DIV2 (integer)`**

  Selects HEVC loop filter tc offset. The valid range is \[-6, +6\].

<a id="rst-v4l2-hevc-refresh-type"></a>

- **`V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_TYPE`**

  (enum)

- **enum v4l2\_mpeg\_video\_hevc\_hier\_refresh\_type -**

  Selects refresh type for HEVC encoder. Host has to specify the period into V4L2\_CID\_MPEG\_VIDEO\_HEVC\_REFRESH\_PERIOD.

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{6.2cm}|p{11.3cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_REFRESH_NONE`

</td>
<td>



Use the B frame for hierarchical coding.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_REFRESH_CRA`

</td>
<td>



Use CRA (Clean Random Access Unit) picture encoding.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_REFRESH_IDR`

</td>
<td>



Use IDR (Instantaneous Decoding Refresh) picture encoding.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_HEVC_REFRESH_PERIOD (integer)`**

  Selects the refresh period for HEVC encoder. This specifies the number of I pictures between two CRA/IDR pictures. This is valid only if REFRESH\_TYPE is not 0.

- **`V4L2_CID_MPEG_VIDEO_HEVC_LOSSLESS_CU (boolean)`**

  Indicates HEVC lossless encoding. Setting it to 0 disables lossless encoding. Setting it to 1 enables lossless encoding.

- **`V4L2_CID_MPEG_VIDEO_HEVC_CONST_INTRA_PRED (boolean)`**

  Indicates constant intra prediction for HEVC encoder. Specifies the constrained intra prediction in which intra largest coding unit (LCU) prediction is performed by using residual data and decoded samples of neighboring intra LCU only. Setting the value to 1 enables constant intra prediction and setting the value to 0 disables constant intra prediction.

- **`V4L2_CID_MPEG_VIDEO_HEVC_WAVEFRONT (boolean)`**

  Indicates wavefront parallel processing for HEVC encoder. Setting it to 0 disables the feature and setting it to 1 enables the wavefront parallel processing.

- **`V4L2_CID_MPEG_VIDEO_HEVC_GENERAL_PB (boolean)`**

  Setting the value to 1 enables combination of P and B frame for HEVC encoder.

- **`V4L2_CID_MPEG_VIDEO_HEVC_TEMPORAL_ID (boolean)`**

  Indicates temporal identifier for HEVC encoder which is enabled by setting the value to 1.

- **`V4L2_CID_MPEG_VIDEO_HEVC_STRONG_SMOOTHING (boolean)`**

  Indicates bi-linear interpolation is conditionally used in the intra prediction filtering process in the CVS when set to 1. Indicates bi-linear interpolation is not used in the CVS when set to 0.

- **`V4L2_CID_MPEG_VIDEO_HEVC_MAX_NUM_MERGE_MV_MINUS1 (integer)`**

  Indicates maximum number of merge candidate motion vectors. Values are from 0 to 4.

- **`V4L2_CID_MPEG_VIDEO_HEVC_TMV_PREDICTION (boolean)`**

  Indicates temporal motion vector prediction for HEVC encoder. Setting it to 1 enables the prediction. Setting it to 0 disables the prediction.

- **`V4L2_CID_MPEG_VIDEO_HEVC_WITHOUT_STARTCODE (boolean)`**

  Specifies if HEVC generates a stream with a size of the length field instead of start code pattern. The size of the length field is configurable through the V4L2\_CID\_MPEG\_VIDEO\_HEVC\_SIZE\_OF\_LENGTH\_FIELD control. Setting the value to 0 disables encoding without startcode pattern. Setting the value to 1 will enables encoding without startcode pattern.

<a id="rst-v4l2-hevc-size-of-length-field"></a>

`V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD` (enum)

- **enum v4l2\_mpeg\_video\_hevc\_size\_of\_length\_field -**

  Indicates the size of length field. This is valid when encoding WITHOUT\_STARTCODE\_ENABLE is enabled.

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{5.5cm}|p{12.0cm}| -->


<table>
<tbody>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_SIZE_0`

</td>
<td>



Generate start code pattern (Normal).

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_SIZE_1`

</td>
<td>



Generate size of length field instead of start code pattern and length is 1.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_SIZE_2`

</td>
<td>



Generate size of length field instead of start code pattern and length is 2.

</td>
</tr>
<tr>
<td>



`V4L2_MPEG_VIDEO_HEVC_SIZE_4`

</td>
<td>



Generate size of length field instead of start code pattern and length is 4.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L0_BR (integer)`**

  Indicates bit rate for hierarchical coding layer 0 for HEVC encoder.

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L1_BR (integer)`**

  Indicates bit rate for hierarchical coding layer 1 for HEVC encoder.

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L2_BR (integer)`**

  Indicates bit rate for hierarchical coding layer 2 for HEVC encoder.

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L3_BR (integer)`**

  Indicates bit rate for hierarchical coding layer 3 for HEVC encoder.

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L4_BR (integer)`**

  Indicates bit rate for hierarchical coding layer 4 for HEVC encoder.

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L5_BR (integer)`**

  Indicates bit rate for hierarchical coding layer 5 for HEVC encoder.

- **`V4L2_CID_MPEG_VIDEO_HEVC_HIER_CODING_L6_BR (integer)`**

  Indicates bit rate for hierarchical coding layer 6 for HEVC encoder.

- **`V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES (integer)`**

  Selects number of P reference pictures required for HEVC encoder. P-Frame can use 1 or 2 frames for reference.

- **`V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR (integer)`**

  Indicates whether to generate SPS and PPS at every IDR. Setting it to 0 disables generating SPS and PPS at every IDR. Setting it to one enables generating SPS and PPS at every IDR.

---

# Colorimetry Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Colorimetry class includes controls for High Dynamic Range imaging for representing colors in digital images and video. The controls should be used for video and image encoding and decoding as well as in HDMI receivers and transmitters.

<a id="rst-colorimetry-control-reference"></a>
<a id="rst-colorimetry-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Colorimetry class includes controls for High Dynamic Range imaging for representing colors in digital images and video. The controls should be used for video and image encoding and decoding as well as in HDMI receivers and transmitters.

<a id="rst-colorimetry-control-ids"></a>

## Colorimetry Control IDs

<a id="rst-colorimetry-control-id"></a>

- **`V4L2_CID_COLORIMETRY_CLASS (class)`**

  The Colorimetry class descriptor. Calling [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for this control will return a description of this control class.

- **`V4L2_CID_COLORIMETRY_HDR10_CLL_INFO (struct)`**

  The Content Light Level defines upper bounds for the nominal target brightness light level of the pictures.





<a id="c-v4l2_ctrl_hdr10_cll_info"></a>

```c
v4l2_ctrl_hdr10_cll_info
```


<table>
<caption>struct v4l2_ctrl_hdr10_cll_info</caption>
<tbody>
<tr>
<td>


\__u16

</td>
<td>


`max_content_light_level`

</td>
<td>


The upper bound for the maximum light level among all individual samples for the pictures of a video sequence, cd/m<sup>2</sup>. When equal to 0 no such upper bound is present.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`max_pic_average_light_level`

</td>
<td>


The upper bound for the maximum average light level among the samples for any individual picture of a video sequence, cd/m<sup>2</sup>. When equal to 0 no such upper bound is present.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY (struct)`**

  The mastering display defines the color volume (the color primaries, white point and luminance range) of a display considered to be the mastering display for the current video content.





<a id="c-v4l2_ctrl_hdr10_mastering_display"></a>

```c
v4l2_ctrl_hdr10_mastering_display
```


<table>
<caption>struct v4l2_ctrl_hdr10_mastering_display</caption>
<tbody>
<tr>
<td>


\__u16

</td>
<td>


`display_primaries_x[3]`

</td>
<td>


Specifies the normalized x chromaticity coordinate of the color primary component c of the mastering display in increments of 0.00002. For describing the mastering display that uses Red, Green and Blue color primaries, index value c equal to 0 corresponds to the Green primary, c equal to 1 corresponds to Blue primary and c equal to 2 corresponds to the Red color primary.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`display_primaries_y[3]`

</td>
<td>


Specifies the normalized y chromaticity coordinate of the color primary component c of the mastering display in increments of 0.00002. For describing the mastering display that uses Red, Green and Blue color primaries, index value c equal to 0 corresponds to the Green primary, c equal to 1 corresponds to Blue primary and c equal to 2 corresponds to Red color primary.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`white_point_x`

</td>
<td>


Specifies the normalized x chromaticity coordinate of the white point of the mastering display in increments of 0.00002.

</td>
</tr>
<tr>
<td>


\__u16

</td>
<td>


`white_point_y`

</td>
<td>


Specifies the normalized y chromaticity coordinate of the white point of the mastering display in increments of 0.00002.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`max_luminance`

</td>
<td>


Specifies the nominal maximum display luminance of the mastering display in units of 0.0001 cd/m<sup>2</sup>.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`min_luminance`

</td>
<td>


specifies the nominal minimum display luminance of the mastering display in units of 0.0001 cd/m<sup>2</sup>.

</td>
</tr>
</tbody>
</table>

---

# Detect Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Detect class includes controls for common features of various motion or object detection capable devices.

<a id="rst-detect-control-reference"></a>
<a id="rst-detect-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Detect class includes controls for common features of various motion or object detection capable devices.

<a id="rst-detect-control-ids"></a>
<a id="rst-detect-control-id"></a>

## Detect Control IDs

- **`V4L2_CID_DETECT_CLASS (class)`**

  The Detect class descriptor. Calling [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for this control will return a description of this control class.

- **`V4L2_CID_DETECT_MD_MODE (menu)`**

  Sets the motion detection mode.

<!-- tabularcolumns: |p{7.7cm}|p{9.8cm}| -->


<table>
<tbody>
<tr>
<td>


`V4L2_DETECT_MD_MODE_DISABLED`

</td>
<td>


Disable motion detection.

</td>
</tr>
<tr>
<td>


`V4L2_DETECT_MD_MODE_GLOBAL`

</td>
<td>


Use a single motion detection threshold.

</td>
</tr>
<tr>
<td>


`V4L2_DETECT_MD_MODE_THRESHOLD_GRID`

</td>
<td>


The image is divided into a grid, each cell with its own motion detection threshold. These thresholds are set through the `V4L2_CID_DETECT_MD_THRESHOLD_GRID` matrix control.

</td>
</tr>
<tr>
<td>


`V4L2_DETECT_MD_MODE_REGION_GRID`

</td>
<td>


The image is divided into a grid, each cell with its own region value that specifies which per-region motion detection thresholds should be used. Each region has its own thresholds. How these per-region thresholds are set up is driver-specific. The region values for the grid are set through the `V4L2_CID_DETECT_MD_REGION_GRID` matrix control.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_DETECT_MD_GLOBAL_THRESHOLD (integer)`**

  Sets the global motion detection threshold to be used with the `V4L2_DETECT_MD_MODE_GLOBAL` motion detection mode.

- **`V4L2_CID_DETECT_MD_THRESHOLD_GRID (__u16 matrix)`**

  Sets the motion detection thresholds for each cell in the grid. To be used with the `V4L2_DETECT_MD_MODE_THRESHOLD_GRID` motion detection mode. Matrix element (0, 0) represents the cell at the top-left of the grid.

- **`V4L2_CID_DETECT_MD_REGION_GRID (__u8 matrix)`**

  Sets the motion detection region value for each cell in the grid. To be used with the `V4L2_DETECT_MD_MODE_REGION_GRID` motion detection mode. Matrix element (0, 0) represents the cell at the top-left of the grid.

---

# Digital Video Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Digital Video control class is intended to control receivers and transmitters for VGA, DVI (Digital Visual Interface), HDMI (hdmi) and DisplayPort (dp). These controls are generally expected to be private to the receiver or transmitter…

<a id="rst-digital-video-control-reference"></a>
<a id="rst-dv-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Digital Video control class is intended to control receivers and transmitters for [VGA](<http://en.wikipedia.org/wiki/Vga>), [DVI](<http://en.wikipedia.org/wiki/Digital_Visual_Interface>) (Digital Visual Interface), HDMI ([HDMI](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hdmi-1>)) and DisplayPort ([DP](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-dp-1>)). These controls are generally expected to be private to the receiver or transmitter subdevice that implements them, so they are only exposed on the `/dev/v4l-subdev*` device node.

> [!NOTE]
>
> Note that these devices can have multiple input or output pads which are hooked up to e.g. HDMI connectors. Even though the subdevice will receive or transmit video from/to only one of those pads, the other pads can still be active when it comes to EDID (Extended Display Identification Data, [EDID](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vesaedid>)) and HDCP (High-bandwidth Digital Content Protection System, [HDCP](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-hdcp-1>)) processing, allowing the device to do the fairly slow EDID/HDCP handling in advance. This allows for quick switching between connectors.

These pads appear in several of the controls in this section as bitmasks, one bit for each pad. Bit 0 corresponds to pad 0, bit 1 to pad 1, etc. The maximum value of the control is the set of valid pads.

<a id="rst-digital-video-control-ids"></a>
<a id="rst-dv-control-id"></a>

## Digital Video Control IDs

- **`V4L2_CID_DV_CLASS (class)`**

  The Digital Video class descriptor.

- **`V4L2_CID_DV_TX_HOTPLUG (bitmask)`**

  Many connectors have a hotplug pin which is high if EDID information is available from the source. This control shows the state of the hotplug pin as seen by the transmitter. Each bit corresponds to an output pad on the transmitter. If an output pad does not have an associated hotplug pin, then the bit for that pad will be 0. This read-only control is applicable to DVI-D, HDMI and DisplayPort connectors.

- **`V4L2_CID_DV_TX_RXSENSE (bitmask)`**

  Rx Sense is the detection of pull-ups on the TMDS clock lines. This normally means that the sink has left/entered standby (i.e. the transmitter can sense that the receiver is ready to receive video). Each bit corresponds to an output pad on the transmitter. If an output pad does not have an associated Rx Sense, then the bit for that pad will be 0. This read-only control is applicable to DVI-D and HDMI devices.

- **`V4L2_CID_DV_TX_EDID_PRESENT (bitmask)`**

  When the transmitter sees the hotplug signal from the receiver it will attempt to read the EDID. If set, then the transmitter has read at least the first block (= 128 bytes). Each bit corresponds to an output pad on the transmitter. If an output pad does not support EDIDs, then the bit for that pad will be 0. This read-only control is applicable to VGA, DVI-A/D, HDMI and DisplayPort connectors.

- **`V4L2_CID_DV_TX_MODE`**

  (enum)

- **enum v4l2_dv_tx_mode -**

  HDMI transmitters can transmit in DVI-D mode (just video) or in HDMI mode (video + audio + auxiliary data). This control selects which mode to use: V4L2_DV_TX_MODE_DVI_D or V4L2_DV_TX_MODE_HDMI. This control is applicable to HDMI connectors.

- **`V4L2_CID_DV_TX_RGB_RANGE`**

  (enum)

- **enum v4l2_dv_rgb_range -**

  Select the quantization range for RGB output. V4L2_DV_RANGE_AUTO follows the RGB quantization range specified in the standard for the video interface (ie. [CEA-861-E](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-cea861>) for HDMI). V4L2_DV_RANGE_LIMITED and V4L2_DV_RANGE_FULL override the standard to be compatible with sinks that have not implemented the standard correctly (unfortunately quite common for HDMI and DVI-D). Full range allows all possible values to be used whereas limited range sets the range to (16 &lt;&lt; (N-8)) - (235 &lt;&lt; (N-8)) where N is the number of bits per component. This control is applicable to VGA, DVI-A/D, HDMI and DisplayPort connectors.

- **`V4L2_CID_DV_TX_IT_CONTENT_TYPE`**

  (enum)

- **enum v4l2_dv_it_content_type -**

  Configures the IT Content Type of the transmitted video. This information is sent over HDMI and DisplayPort connectors as part of the AVI InfoFrame. The term 'IT Content' is used for content that originates from a computer as opposed to content from a TV broadcast or an analog source. The enum v4l2_dv_it_content_type defines the possible content types:

<!-- tabularcolumns: |p{7.3cm}|p{10.2cm}| -->


<table>
<tbody>
<tr>
<td>


`V4L2_DV_IT_CONTENT_TYPE_GRAPHICS`

</td>
<td>


Graphics content. Pixel data should be passed unfiltered and without analog reconstruction.

</td>
</tr>
<tr>
<td>


`V4L2_DV_IT_CONTENT_TYPE_PHOTO`

</td>
<td>


Photo content. The content is derived from digital still pictures. The content should be passed through with minimal scaling and picture enhancements.

</td>
</tr>
<tr>
<td>


`V4L2_DV_IT_CONTENT_TYPE_CINEMA`

</td>
<td>


Cinema content.

</td>
</tr>
<tr>
<td>


`V4L2_DV_IT_CONTENT_TYPE_GAME`

</td>
<td>


Game content. Audio and video latency should be minimized.

</td>
</tr>
<tr>
<td>


`V4L2_DV_IT_CONTENT_TYPE_NO_ITC`

</td>
<td>


No IT Content information is available and the ITC bit in the AVI InfoFrame is set to 0.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_DV_RX_POWER_PRESENT (bitmask)`**

  Detects whether the receiver receives power from the source (e.g. HDMI carries 5V on one of the pins). This is often used to power an eeprom which contains EDID information, such that the source can read the EDID even if the sink is in standby/power off. Each bit corresponds to an input pad on the receiver. If an input pad cannot detect whether power is present, then the bit for that pad will be 0. This read-only control is applicable to DVI-D, HDMI and DisplayPort connectors.

- **`V4L2_CID_DV_RX_RGB_RANGE`**

  (enum)

- **enum v4l2_dv_rgb_range -**

  Select the quantization range for RGB input. V4L2_DV_RANGE_AUTO follows the RGB quantization range specified in the standard for the video interface (ie. [CEA-861-E](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-cea861>) for HDMI). V4L2_DV_RANGE_LIMITED and V4L2_DV_RANGE_FULL override the standard to be compatible with sources that have not implemented the standard correctly (unfortunately quite common for HDMI and DVI-D). Full range allows all possible values to be used whereas limited range sets the range to (16 &lt;&lt; (N-8)) - (235 &lt;&lt; (N-8)) where N is the number of bits per component. This control is applicable to VGA, DVI-A/D, HDMI and DisplayPort connectors.

- **`V4L2_CID_DV_RX_IT_CONTENT_TYPE`**

  (enum)

- **enum v4l2_dv_it_content_type -**

  Reads the IT Content Type of the received video. This information is sent over HDMI and DisplayPort connectors as part of the AVI InfoFrame. The term 'IT Content' is used for content that originates from a computer as opposed to content from a TV broadcast or an analog source. See `V4L2_CID_DV_TX_IT_CONTENT_TYPE` for the available content types.

---

# Flash Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The V4L2 flash controls are intended to provide generic access to flash controller devices. Flash controller devices are typically used in digital cameras.

<a id="rst-flash-control-reference"></a>
<a id="rst-flash-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The V4L2 flash controls are intended to provide generic access to flash controller devices. Flash controller devices are typically used in digital cameras.

The interface can support both LED and xenon flash devices. As of writing this, there is no xenon flash driver using this interface.

<a id="rst-supported-use-cases"></a>
<a id="rst-flash-controls-use-cases"></a>

## Supported use cases

<a id="rst-unsynchronised-led-flash-software-strobe"></a>

### Unsynchronised LED flash (software strobe)

Unsynchronised LED flash is controlled directly by the host as the sensor. The flash must be enabled by the host before the exposure of the image starts and disabled once it ends. The host is fully responsible for the timing of the flash.

Example of such device: Nokia N900.

<a id="rst-synchronised-led-flash-hardware-strobe"></a>

### Synchronised LED flash (hardware strobe)

The synchronised LED flash is pre-programmed by the host (power and timeout) but controlled by the sensor through a strobe signal from the sensor to the flash.

The sensor controls the flash duration and timing. This information typically must be made available to the sensor.

<a id="rst-led-flash-as-torch"></a>

### LED flash as torch

LED flash may be used as torch in conjunction with another use case involving camera or individually.

<a id="rst-flash-control-ids"></a>
<a id="rst-flash-control-id"></a>

### Flash Control IDs

- **`V4L2_CID_FLASH_CLASS (class)`**

  The FLASH class descriptor.

<a id="rst-v4l2-cid-flash-led-mode"></a>

- **`V4L2_CID_FLASH_LED_MODE (menu)`**

  Defines the mode of the flash LED, the high-power white LED attached to the flash controller. Setting this control may not be possible in presence of some faults. See V4L2_CID_FLASH_FAULT.

<!-- tabularcolumns: |p{5.7cm}|p{11.8cm}| -->


<table>
<tbody>
<tr>
<td>


`V4L2_FLASH_LED_MODE_NONE`

</td>
<td>


Off.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_LED_MODE_FLASH`

</td>
<td>


Flash mode.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_LED_MODE_TORCH`

</td>
<td>


Torch mode.

See V4L2_CID_FLASH_TORCH_INTENSITY.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-cid-flash-strobe-source"></a>

- **`V4L2_CID_FLASH_STROBE_SOURCE (menu)`**

  Defines the source of the flash LED strobe.

<!-- tabularcolumns: |p{7.5cm}|p{7.5cm}| -->


<table>
<tbody>
<tr>
<td>


`V4L2_FLASH_STROBE_SOURCE_SOFTWARE`

</td>
<td>


The flash strobe is triggered by using the V4L2_CID_FLASH_STROBE control.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_STROBE_SOURCE_EXTERNAL`

</td>
<td>


The flash strobe is triggered by an external source. Typically this is a sensor, which makes it possible to synchronise the flash strobe start to exposure start. This method of controlling flash LED strobe has two additional prerequisites: the strobe source's [strobe output](<#rst-v4l2-cid-flash-strobe-oe>) must be enabled (if available) and the flash controller's [flash LED mode](<#rst-v4l2-cid-flash-led-mode>) must be set to `V4L2_FLASH_LED_MODE_FLASH`.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_FLASH_STROBE (button)`**

  Strobe flash. Valid when V4L2_CID_FLASH_LED_MODE is set to V4L2_FLASH_LED_MODE_FLASH and V4L2_CID_FLASH_STROBE_SOURCE is set to V4L2_FLASH_STROBE_SOURCE_SOFTWARE. Setting this control may not be possible in presence of some faults. See V4L2_CID_FLASH_FAULT.

- **`V4L2_CID_FLASH_STROBE_STOP (button)`**

  Stop flash strobe immediately.

- **`V4L2_CID_FLASH_STROBE_STATUS (boolean)`**

  Strobe status: whether the flash is strobing at the moment or not. This is a read-only control.

- **`V4L2_CID_FLASH_TIMEOUT (integer)`**

  Hardware timeout for flash. The flash strobe is stopped after this period of time has passed from the start of the strobe.

- **`V4L2_CID_FLASH_INTENSITY (integer)`**

  Intensity of the flash strobe when the flash LED is in flash mode (V4L2_FLASH_LED_MODE_FLASH). The unit should be milliamps (mA) if possible.

- **`V4L2_CID_FLASH_TORCH_INTENSITY (integer)`**

  Intensity of the flash LED in torch mode (V4L2_FLASH_LED_MODE_TORCH). The unit should be milliamps (mA) if possible. Setting this control may not be possible in presence of some faults. See V4L2_CID_FLASH_FAULT.

- **`V4L2_CID_FLASH_INDICATOR_INTENSITY (integer)`**

  Intensity of the indicator LED. The indicator LED may be fully independent of the flash LED. The unit should be microamps (uA) if possible.

- **`V4L2_CID_FLASH_FAULT (bitmask)`**

  Faults related to the flash. The faults tell about specific problems in the flash chip itself or the LEDs attached to it. Faults may prevent further use of some of the flash controls. In particular, V4L2_CID_FLASH_LED_MODE is set to V4L2_FLASH_LED_MODE_NONE if the fault affects the flash LED. Exactly which faults have such an effect is chip dependent. Reading the faults resets the control and returns the chip to a usable state if possible.

<!-- tabularcolumns: |p{8.4cm}|p{9.1cm}| -->


<table>
<tbody>
<tr>
<td>


`V4L2_FLASH_FAULT_OVER_VOLTAGE`

</td>
<td>


Flash controller voltage to the flash LED has exceeded the limit specific to the flash controller.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_FAULT_TIMEOUT`

</td>
<td>


The flash strobe was still on when the timeout set by the user --- V4L2_CID_FLASH_TIMEOUT control --- has expired. Not all flash controllers may set this in all such conditions.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_FAULT_OVER_TEMPERATURE`

</td>
<td>


The flash controller has overheated.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_FAULT_SHORT_CIRCUIT`

</td>
<td>


The short circuit protection of the flash controller has been triggered.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_FAULT_OVER_CURRENT`

</td>
<td>


Current in the LED power supply has exceeded the limit specific to the flash controller.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_FAULT_INDICATOR`

</td>
<td>


The flash controller has detected a short or open circuit condition on the indicator LED.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_FAULT_UNDER_VOLTAGE`

</td>
<td>


Flash controller voltage to the flash LED has been below the minimum limit specific to the flash controller.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_FAULT_INPUT_VOLTAGE`

</td>
<td>


The input voltage of the flash controller is below the limit under which strobing the flash at full current will not be possible.The condition persists until this flag is no longer set.

</td>
</tr>
<tr>
<td>


`V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE`

</td>
<td>


The temperature of the LED has exceeded its allowed upper limit.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_FLASH_CHARGE (boolean)`**

  Enable or disable charging of the xenon flash capacitor.

- **`V4L2_CID_FLASH_READY (boolean)`**

  Is the flash ready to strobe? Xenon flashes require their capacitors charged before strobing. LED flashes often require a cooldown period after strobe during which another strobe will not be possible. This is a read-only control.

<a id="rst-v4l2-cid-flash-duration"></a>

- **`V4L2_CID_FLASH_DURATION (integer)`**

  Duration of the flash strobe pulse generated by the strobe source, when using external strobe. This control shall be implemented by the device generating the hardware flash strobe signal, typically a camera sensor, connected to a flash controller.

  The flash controllers [strobe source](<#rst-v4l2-cid-flash-strobe-source>) must be configured to `V4L2_FLASH_STROBE_SOURCE_EXTERNAL` for this mode of operation. For more details please also take a look at the documentation there.

  The unit should be microseconds (µs) if possible.

<a id="rst-v4l2-cid-flash-strobe-oe"></a>

- **`V4L2_CID_FLASH_STROBE_OE (boolean)`**

  Enables the output of a hardware strobe signal from the strobe source, when using external strobe. This control shall be implemented by the device generating the hardware flash strobe signal, typically a camera sensor, connected to a flash controller.

  Provided the signal generating device driver supports it, the length of the strobe signal can be configured by adjusting its [flash duration](<#rst-v4l2-cid-flash-duration>).

  The flash controllers [strobe source](<#rst-v4l2-cid-flash-strobe-source>) must be configured to `V4L2_FLASH_STROBE_SOURCE_EXTERNAL` for this mode of operation. For more details please also take a look at the documentation there.

---

# FM Receiver Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The FM Receiver (FM_RX) class includes controls for common features of FM Reception capable devices.

<a id="rst-fm-receiver-control-reference"></a>
<a id="rst-fm-rx-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The FM Receiver (FM_RX) class includes controls for common features of FM Reception capable devices.

<a id="rst-fm-rx-control-ids"></a>
<a id="rst-fm-rx-control-id"></a>

## FM_RX Control IDs

- **`V4L2_CID_FM_RX_CLASS (class)`**

  The FM_RX class descriptor. Calling [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for this control will return a description of this control class.

- **`V4L2_CID_RDS_RECEPTION (boolean)`**

  Enables/disables RDS reception by the radio tuner

- **`V4L2_CID_RDS_RX_PTY (integer)`**

  Gets RDS Programme Type field. This encodes up to 31 pre-defined programme types.

- **`V4L2_CID_RDS_RX_PS_NAME (string)`**

  Gets the Programme Service name (PS_NAME). It is intended for static display on a receiver. It is the primary aid to listeners in programme service identification and selection. In Annex E of [IEC 62106](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-iec62106>), the RDS specification, there is a full description of the correct character encoding for Programme Service name strings. Also from RDS specification, PS is usually a single eight character text. However, it is also possible to find receivers which can scroll strings sized as 8 x N characters. So, this control must be configured with steps of 8 characters. The result is it must always contain a string with size multiple of 8.

- **`V4L2_CID_RDS_RX_RADIO_TEXT (string)`**

  Gets the Radio Text info. It is a textual description of what is being broadcasted. RDS Radio Text can be applied when broadcaster wishes to transmit longer PS names, programme-related information or any other text. In these cases, RadioText can be used in addition to `V4L2_CID_RDS_RX_PS_NAME`. The encoding for Radio Text strings is also fully described in Annex E of [IEC 62106](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-iec62106>). The length of Radio Text strings depends on which RDS Block is being used to transmit it, either 32 (2A block) or 64 (2B block). However, it is also possible to find receivers which can scroll strings sized as 32 x N or 64 x N characters. So, this control must be configured with steps of 32 or 64 characters. The result is it must always contain a string with size multiple of 32 or 64.

- **`V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT (boolean)`**

  If set, then a traffic announcement is in progress.

- **`V4L2_CID_RDS_RX_TRAFFIC_PROGRAM (boolean)`**

  If set, then the tuned programme carries traffic announcements.

- **`V4L2_CID_RDS_RX_MUSIC_SPEECH (boolean)`**

  If set, then this channel broadcasts music. If cleared, then it broadcasts speech. If the transmitter doesn't make this distinction, then it will be set.

- **`V4L2_CID_TUNE_DEEMPHASIS (enum)`**

  Configures the de-emphasis value for reception. A de-emphasis filter is applied to the broadcast to accentuate the high audio frequencies. Depending on the region, a time constant of either 50 or 75 microseconds is used. The enum v4l2_deemphasis defines possible values for de-emphasis. They are:


<table>
<tbody>
<tr>
<td>


`V4L2_DEEMPHASIS_DISABLED`

</td>
<td>


No de-emphasis is applied.

</td>
</tr>
<tr>
<td>


`V4L2_DEEMPHASIS_50_uS`

</td>
<td>


A de-emphasis of 50 uS is used.

</td>
</tr>
<tr>
<td>


`V4L2_DEEMPHASIS_75_uS`

</td>
<td>


A de-emphasis of 75 uS is used.

</td>
</tr>
</tbody>
</table>

---

# FM Transmitter Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The FM Transmitter (FM_TX) class includes controls for common features of FM transmissions capable devices. Currently this class includes parameters for audio compression, pilot tone generation, audio deviation limiter, RDS transmission…

<a id="rst-fm-transmitter-control-reference"></a>
<a id="rst-fm-tx-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The FM Transmitter (FM_TX) class includes controls for common features of FM transmissions capable devices. Currently this class includes parameters for audio compression, pilot tone generation, audio deviation limiter, RDS transmission and tuning power features.

<a id="rst-fm-tx-control-ids"></a>
<a id="rst-fm-tx-control-id"></a>

## FM_TX Control IDs

- **`V4L2_CID_FM_TX_CLASS (class)`**

  The FM_TX class descriptor. Calling [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for this control will return a description of this control class.

- **`V4L2_CID_RDS_TX_DEVIATION (integer)`**

  Configures RDS signal frequency deviation level in Hz. The range and step are driver-specific.

- **`V4L2_CID_RDS_TX_PI (integer)`**

  Sets the RDS Programme Identification field for transmission.

- **`V4L2_CID_RDS_TX_PTY (integer)`**

  Sets the RDS Programme Type field for transmission. This encodes up to 31 pre-defined programme types.

- **`V4L2_CID_RDS_TX_PS_NAME (string)`**

  Sets the Programme Service name (PS_NAME) for transmission. It is intended for static display on a receiver. It is the primary aid to listeners in programme service identification and selection. In Annex E of [IEC 62106](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-iec62106>), the RDS specification, there is a full description of the correct character encoding for Programme Service name strings. Also from RDS specification, PS is usually a single eight character text. However, it is also possible to find receivers which can scroll strings sized as 8 x N characters. So, this control must be configured with steps of 8 characters. The result is it must always contain a string with size multiple of 8.

- **`V4L2_CID_RDS_TX_RADIO_TEXT (string)`**

  Sets the Radio Text info for transmission. It is a textual description of what is being broadcasted. RDS Radio Text can be applied when broadcaster wishes to transmit longer PS names, programme-related information or any other text. In these cases, RadioText should be used in addition to `V4L2_CID_RDS_TX_PS_NAME`. The encoding for Radio Text strings is also fully described in Annex E of [IEC 62106](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-iec62106>). The length of Radio Text strings depends on which RDS Block is being used to transmit it, either 32 (2A block) or 64 (2B block). However, it is also possible to find receivers which can scroll strings sized as 32 x N or 64 x N characters. So, this control must be configured with steps of 32 or 64 characters. The result is it must always contain a string with size multiple of 32 or 64.

- **`V4L2_CID_RDS_TX_MONO_STEREO (boolean)`**

  Sets the Mono/Stereo bit of the Decoder Identification code. If set, then the audio was recorded as stereo.

- **`V4L2_CID_RDS_TX_ARTIFICIAL_HEAD (boolean)`**

  Sets the [Artificial Head](<http://en.wikipedia.org/wiki/Artificial_head>) bit of the Decoder Identification code. If set, then the audio was recorded using an artificial head.

- **`V4L2_CID_RDS_TX_COMPRESSED (boolean)`**

  Sets the Compressed bit of the Decoder Identification code. If set, then the audio is compressed.

- **`V4L2_CID_RDS_TX_DYNAMIC_PTY (boolean)`**

  Sets the Dynamic PTY bit of the Decoder Identification code. If set, then the PTY code is dynamically switched.

- **`V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT (boolean)`**

  If set, then a traffic announcement is in progress.

- **`V4L2_CID_RDS_TX_TRAFFIC_PROGRAM (boolean)`**

  If set, then the tuned programme carries traffic announcements.

- **`V4L2_CID_RDS_TX_MUSIC_SPEECH (boolean)`**

  If set, then this channel broadcasts music. If cleared, then it broadcasts speech. If the transmitter doesn't make this distinction, then it should be set.

- **`V4L2_CID_RDS_TX_ALT_FREQS_ENABLE (boolean)`**

  If set, then transmit alternate frequencies.

- **`V4L2_CID_RDS_TX_ALT_FREQS (__u32 array)`**

  The alternate frequencies in kHz units. The RDS standard allows for up to 25 frequencies to be defined. Drivers may support fewer frequencies so check the array size.

- **`V4L2_CID_AUDIO_LIMITER_ENABLED (boolean)`**

  Enables or disables the audio deviation limiter feature. The limiter is useful when trying to maximize the audio volume, minimize receiver-generated distortion and prevent overmodulation.

- **`V4L2_CID_AUDIO_LIMITER_RELEASE_TIME (integer)`**

  Sets the audio deviation limiter feature release time. Unit is in microseconds. Step and range are driver-specific.

- **`V4L2_CID_AUDIO_LIMITER_DEVIATION (integer)`**

  Configures audio frequency deviation level in Hz. The range and step are driver-specific.

- **`V4L2_CID_AUDIO_COMPRESSION_ENABLED (boolean)`**

  Enables or disables the audio compression feature. This feature amplifies signals below the threshold by a fixed gain and compresses audio signals above the threshold by the ratio of Threshold/(Gain + Threshold).

- **`V4L2_CID_AUDIO_COMPRESSION_GAIN (integer)`**

  Sets the gain for audio compression feature. It is a dB value. The range and step are driver-specific.

- **`V4L2_CID_AUDIO_COMPRESSION_THRESHOLD (integer)`**

  Sets the threshold level for audio compression feature. It is a dB value. The range and step are driver-specific.

- **`V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME (integer)`**

  Sets the attack time for audio compression feature. It is a microseconds value. The range and step are driver-specific.

- **`V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME (integer)`**

  Sets the release time for audio compression feature. It is a microseconds value. The range and step are driver-specific.

- **`V4L2_CID_PILOT_TONE_ENABLED (boolean)`**

  Enables or disables the pilot tone generation feature.

- **`V4L2_CID_PILOT_TONE_DEVIATION (integer)`**

  Configures pilot tone frequency deviation level. Unit is in Hz. The range and step are driver-specific.

- **`V4L2_CID_PILOT_TONE_FREQUENCY (integer)`**

  Configures pilot tone frequency value. Unit is in Hz. The range and step are driver-specific.

- **`V4L2_CID_TUNE_PREEMPHASIS (enum)`**

  Configures the pre-emphasis value for broadcasting. A pre-emphasis filter is applied to the broadcast to accentuate the high audio frequencies. Depending on the region, a time constant of either 50 or 75 microseconds is used. The enum v4l2_preemphasis defines possible values for pre-emphasis. They are:


<table>
<tbody>
<tr>
<td>


`V4L2_PREEMPHASIS_DISABLED`

</td>
<td>


No pre-emphasis is applied.

</td>
</tr>
<tr>
<td>


`V4L2_PREEMPHASIS_50_uS`

</td>
<td>


A pre-emphasis of 50 uS is used.

</td>
</tr>
<tr>
<td>


`V4L2_PREEMPHASIS_75_uS`

</td>
<td>


A pre-emphasis of 75 uS is used.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_TUNE_POWER_LEVEL (integer)`**

  Sets the output power level for signal transmission. Unit is in dBuV. Range and step are driver-specific.

- **`V4L2_CID_TUNE_ANTENNA_CAPACITOR (integer)`**

  This selects the value of antenna tuning capacitor manually or automatically if set to zero. Unit, range and step are driver-specific.

For more details about RDS specification, refer to [IEC 62106](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-iec62106>) document, from CENELEC.

---

# Image Process Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Image Process control class is intended for low-level control of image processing functions. Unlike V4L2_CID_IMAGE_SOURCE_CLASS, the controls in this class affect processing the image, and do not control capturing of it.

<a id="rst-image-process-control-reference"></a>
<a id="rst-image-process-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Image Process control class is intended for low-level control of image processing functions. Unlike `V4L2_CID_IMAGE_SOURCE_CLASS`, the controls in this class affect processing the image, and do not control capturing of it.

<a id="rst-image-process-control-ids"></a>
<a id="rst-image-process-control-id"></a>

## Image Process Control IDs

- **`V4L2_CID_IMAGE_PROC_CLASS (class)`**

  The IMAGE_PROC class descriptor.

<a id="rst-v4l2-cid-link-freq"></a>

- **`V4L2_CID_LINK_FREQ (integer menu)`**

  The frequency of the data bus (e.g. parallel or CSI-2).

<a id="rst-v4l2-cid-pixel-rate"></a>

- **`V4L2_CID_PIXEL_RATE (64-bit integer)`**

  Pixel sampling rate in the device's pixel array. This control is read-only and its unit is pixels / second.

  Some devices use horizontal and vertical blanking to configure the frame rate. The frame rate can be calculated from the pixel rate, analogue crop rectangle as well as horizontal and vertical blanking. The pixel rate control may be present in a different sub-device than the blanking controls and the analogue crop rectangle configuration.

  The configuration of the frame rate is performed by selecting the desired horizontal and vertical blanking. The unit of this control is Hz.

- **`V4L2_CID_TEST_PATTERN (menu)`**

  Some capture/display/sensor devices have the capability to generate test pattern images. These hardware specific test patterns can be used to test if a device is working properly.

- **`V4L2_CID_DEINTERLACING_MODE (menu)`**

  The video deinterlacing mode (such as Bob, Weave, ...). The menu items are driver specific and are documented in [Video4Linux (V4L) driver-specific documentation](</kernel/administration/admin-guide/media/v4l-drivers.md#rst-uapi-v4l-drivers>).

- **`V4L2_CID_DIGITAL_GAIN (integer)`**

  Digital gain is the value by which all colour components are multiplied by. Typically the digital gain applied is the control value divided by e.g. 0x100, meaning that to get no digital gain the control value needs to be 0x100. The no-gain configuration is also typically the default.

---

# Image Source Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Image Source control class is intended for low-level control of image source devices such as image sensors. The devices feature an analogue to digital converter and a bus transmitter to transmit the image data out of the device.

<a id="rst-image-source-control-reference"></a>
<a id="rst-image-source-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The Image Source control class is intended for low-level control of image source devices such as image sensors. The devices feature an analogue to digital converter and a bus transmitter to transmit the image data out of the device.

<a id="rst-image-source-control-ids"></a>
<a id="rst-image-source-control-id"></a>

## Image Source Control IDs

- **`V4L2_CID_IMAGE_SOURCE_CLASS (class)`**

  The IMAGE_SOURCE class descriptor.

- **`V4L2_CID_VBLANK (integer)`**

  Vertical blanking. The idle period after every frame during which no image data is produced. The unit of vertical blanking is a line. Every line has length of the image width plus horizontal blanking at the pixel rate defined by `V4L2_CID_PIXEL_RATE` control in the same sub-device.

- **`V4L2_CID_HBLANK (integer)`**

  Horizontal blanking. The idle period after every line of image data during which no image data is produced. The unit of horizontal blanking is pixels.

- **`V4L2_CID_ANALOGUE_GAIN (integer)`**

  Analogue gain is gain affecting all colour components in the pixel matrix. The gain operation is performed in the analogue domain before A/D conversion.

- **`V4L2_CID_TEST_PATTERN_RED (integer)`**

  Test pattern red colour component.

- **`V4L2_CID_TEST_PATTERN_GREENR (integer)`**

  Test pattern green (next to red) colour component.

- **`V4L2_CID_TEST_PATTERN_BLUE (integer)`**

  Test pattern blue colour component.

- **`V4L2_CID_TEST_PATTERN_GREENB (integer)`**

  Test pattern green (next to blue) colour component.

- **`V4L2_CID_UNIT_CELL_SIZE (struct)`**

  This control returns the unit cell size in nanometers. The struct `v4l2_area` provides the width and the height in separate fields to take into consideration asymmetric pixels. This control does not take into consideration any possible hardware binning. The unit cell consists of the whole area of the pixel, sensitive and non-sensitive. This control is required for automatic calibration of sensors/cameras.





<a id="c-v4l2_area"></a>

```c
v4l2_area
```


<table>
<caption>struct v4l2_area</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`width`

</td>
<td>


Width of the area.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`height`

</td>
<td>


Height of the area.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_NOTIFY_GAINS (integer array)`**

  The sensor is notified what gains will be applied to the different colour channels by subsequent processing (such as by an ISP). The sensor is merely informed of these values in case it performs processing that requires them, but it does not apply them itself to the output pixels.

  Currently it is defined only for Bayer sensors, and is an array control taking 4 gain values, being the gains for each of the Bayer channels. The gains are always in the order B, Gb, Gr and R, irrespective of the exact Bayer order of the sensor itself.

  The use of an array allows this control to be extended to sensors with, for example, non-Bayer CFAs (colour filter arrays).

  The units for the gain values are linear, with the default value representing a gain of exactly 1.0. For example, if this default value is reported as being (say) 128, then a value of 192 would represent a gain of exactly 1.5.

---

# JPEG Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The JPEG class includes controls for common features of JPEG encoders and decoders. Currently it includes features for codecs implementing progressive baseline DCT compression process with Huffman entropy coding.

<a id="rst-jpeg-control-reference"></a>
<a id="rst-jpeg-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The JPEG class includes controls for common features of JPEG encoders and decoders. Currently it includes features for codecs implementing progressive baseline DCT compression process with Huffman entropy coding.

<a id="rst-jpeg-control-ids"></a>
<a id="rst-jpeg-control-id"></a>

## JPEG Control IDs

- **`V4L2_CID_JPEG_CLASS (class)`**

  The JPEG class descriptor. Calling [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for this control will return a description of this control class.

- **`V4L2_CID_JPEG_CHROMA_SUBSAMPLING (menu)`**

  The chroma subsampling factors describe how each component of an input image is sampled, in respect to maximum sample rate in each spatial dimension. See [ITU-T.81](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu-t81>), clause A.1.1. for more details. The `V4L2_CID_JPEG_CHROMA_SUBSAMPLING` control determines how Cb and Cr components are downsampled after converting an input image from RGB to Y'CbCr color space.

<!-- tabularcolumns: |p{7.5cm}|p{10.0cm}| -->


<table>
<tbody>
<tr>
<td>


`V4L2_JPEG_CHROMA_SUBSAMPLING_444`

</td>
<td>


No chroma subsampling, each pixel has Y, Cr and Cb values.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_CHROMA_SUBSAMPLING_422`

</td>
<td>


Horizontally subsample Cr, Cb components by a factor of 2.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_CHROMA_SUBSAMPLING_420`

</td>
<td>


Subsample Cr, Cb components horizontally and vertically by 2.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_CHROMA_SUBSAMPLING_411`

</td>
<td>


Horizontally subsample Cr, Cb components by a factor of 4.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_CHROMA_SUBSAMPLING_410`

</td>
<td>


Subsample Cr, Cb components horizontally by 4 and vertically by 2.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY`

</td>
<td>


Use only luminance component.

</td>
</tr>
</tbody>
</table>

- **`V4L2_CID_JPEG_RESTART_INTERVAL (integer)`**

  The restart interval determines an interval of inserting RSTm markers (m = 0..7). The purpose of these markers is to additionally reinitialize the encoder process, in order to process blocks of an image independently. For the lossy compression processes the restart interval unit is MCU (Minimum Coded Unit) and its value is contained in DRI (Define Restart Interval) marker. If `V4L2_CID_JPEG_RESTART_INTERVAL` control is set to 0, DRI and RSTm markers will not be inserted.

<a id="rst-jpeg-quality-control"></a>

- **`V4L2_CID_JPEG_COMPRESSION_QUALITY (integer)`**

  Determines trade-off between image quality and size. It provides simpler method for applications to control image quality, without a need for direct reconfiguration of luminance and chrominance quantization tables. In cases where a driver uses quantization tables configured directly by an application, using interfaces defined elsewhere, `V4L2_CID_JPEG_COMPRESSION_QUALITY` control should be set by driver to 0.

  The value range of this control is driver-specific. Only positive, non-zero values are meaningful. The recommended range is 1 - 100, where larger values correspond to better image quality.

<a id="rst-jpeg-active-marker-control"></a>

- **`V4L2_CID_JPEG_ACTIVE_MARKER (bitmask)`**

  Specify which JPEG markers are included in compressed stream. This control is valid only for encoders.


<table>
<tbody>
<tr>
<td>


`V4L2_JPEG_ACTIVE_MARKER_APP0`

</td>
<td>


Application data segment APP<sub>0</sub>.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_ACTIVE_MARKER_APP1`

</td>
<td>


Application data segment APP<sub>1</sub>.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_ACTIVE_MARKER_COM`

</td>
<td>


Comment segment.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_ACTIVE_MARKER_DQT`

</td>
<td>


Quantization tables segment.

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_ACTIVE_MARKER_DHT`

</td>
<td>


Huffman tables segment.

</td>
</tr>
</tbody>
</table>

For more details about JPEG specification, refer to [ITU-T.81](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu-t81>), [JFIF](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-jfif-1>), [W3C JPEG JFIF](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-w3c-jpeg-jfif>).

---

# RF Tuner Control Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The RF Tuner (RF_TUNER) class includes controls for common features of devices having RF tuner.

<a id="rst-rf-tuner-control-reference"></a>
<a id="rst-rf-tuner-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The RF Tuner (RF_TUNER) class includes controls for common features of devices having RF tuner.

In this context, RF tuner is radio receiver circuit between antenna and demodulator. It receives radio frequency (RF) from the antenna and converts that received signal to lower intermediate frequency (IF) or baseband frequency (BB). Tuners that could do baseband output are often called Zero-IF tuners. Older tuners were typically simple PLL tuners inside a metal box, while newer ones are highly integrated chips without a metal box "silicon tuners". These controls are mostly applicable for new feature rich silicon tuners, just because older tuners does not have much adjustable features.

For more information about RF tuners see [Tuner (radio)](<http://en.wikipedia.org/wiki/Tuner_%28radio%29>) and [RF front end](<http://en.wikipedia.org/wiki/RF_front_end>) from Wikipedia.

<a id="rst-rf-tuner-control-ids"></a>
<a id="rst-rf-tuner-control-id"></a>

## RF_TUNER Control IDs

- **`V4L2_CID_RF_TUNER_CLASS (class)`**

  The RF_TUNER class descriptor. Calling [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for this control will return a description of this control class.

- **`V4L2_CID_RF_TUNER_BANDWIDTH_AUTO (boolean)`**

  Enables/disables tuner radio channel bandwidth configuration. In automatic mode bandwidth configuration is performed by the driver.

- **`V4L2_CID_RF_TUNER_BANDWIDTH (integer)`**

  Filter(s) on tuner signal path are used to filter signal according to receiving party needs. Driver configures filters to fulfill desired bandwidth requirement. Used when V4L2_CID_RF_TUNER_BANDWIDTH_AUTO is not set. Unit is in Hz. The range and step are driver-specific.

- **`V4L2_CID_RF_TUNER_LNA_GAIN_AUTO (boolean)`**

  Enables/disables LNA automatic gain control (AGC)

- **`V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO (boolean)`**

  Enables/disables mixer automatic gain control (AGC)

- **`V4L2_CID_RF_TUNER_IF_GAIN_AUTO (boolean)`**

  Enables/disables IF automatic gain control (AGC)

- **`V4L2_CID_RF_TUNER_RF_GAIN (integer)`**

  The RF amplifier is the very first amplifier on the receiver signal path, just right after the antenna input. The difference between the LNA gain and the RF gain in this document is that the LNA gain is integrated in the tuner chip while the RF gain is a separate chip. There may be both RF and LNA gain controls in the same device. The range and step are driver-specific.

- **`V4L2_CID_RF_TUNER_LNA_GAIN (integer)`**

  LNA (low noise amplifier) gain is first gain stage on the RF tuner signal path. It is located very close to tuner antenna input. Used when `V4L2_CID_RF_TUNER_LNA_GAIN_AUTO` is not set. See `V4L2_CID_RF_TUNER_RF_GAIN` to understand how RF gain and LNA gain differs from the each others. The range and step are driver-specific.

- **`V4L2_CID_RF_TUNER_MIXER_GAIN (integer)`**

  Mixer gain is second gain stage on the RF tuner signal path. It is located inside mixer block, where RF signal is down-converted by the mixer. Used when `V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO` is not set. The range and step are driver-specific.

- **`V4L2_CID_RF_TUNER_IF_GAIN (integer)`**

  IF gain is last gain stage on the RF tuner signal path. It is located on output of RF tuner. It controls signal level of intermediate frequency output or baseband output. Used when `V4L2_CID_RF_TUNER_IF_GAIN_AUTO` is not set. The range and step are driver-specific.

- **`V4L2_CID_RF_TUNER_PLL_LOCK (boolean)`**

  Is synthesizer PLL locked? RF tuner is receiving given frequency when that control is set. This is a read-only control.

---

# Extended Controls API

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The control mechanism as originally designed was meant to be used for user settings (brightness, saturation, etc). However, it turned out to be a very useful model for implementing more complicated driver APIs where each driver implements…

<a id="rst-extended-controls-api"></a>
<a id="rst-extended-controls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Introduction

The control mechanism as originally designed was meant to be used for user settings (brightness, saturation, etc). However, it turned out to be a very useful model for implementing more complicated driver APIs where each driver implements only a subset of a larger API.

The MPEG encoding API was the driving force behind designing and implementing this extended control mechanism: the MPEG standard is quite large and the currently supported hardware MPEG encoders each only implement a subset of this standard. Further more, many parameters relating to how the video is encoded into an MPEG stream are specific to the MPEG encoding chip since the MPEG standard only defines the format of the resulting MPEG stream, not how the video is actually encoded into that format.

Unfortunately, the original control API lacked some features needed for these new uses and so it was extended into the (not terribly originally named) extended control API.

Even though the MPEG encoding API was the first effort to use the Extended Control API, nowadays there are also other classes of Extended Controls, such as Camera Controls and FM Transmitter Controls. The Extended Controls API as well as all Extended Controls classes are described in the following text.

<a id="rst-the-extended-control-api"></a>

## The Extended Control API

Three new ioctls are available: [VIDIOC_G_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), [VIDIOC_S_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and [VIDIOC_TRY_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>). These ioctls act on arrays of controls (as opposed to the [VIDIOC_G_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) and [VIDIOC_S_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) ioctls that act on a single control). This is needed since it is often required to atomically change several controls at once.

Each of the new ioctls expects a pointer to a struct `v4l2_ext_controls`. This structure contains a pointer to the control array, a count of the number of controls in that array and a control class. Control classes are used to group similar controls into a single class. For example, control class `V4L2_CTRL_CLASS_USER` contains all user controls (i. e. all controls that can also be set using the old [VIDIOC_S_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) ioctl). Control class `V4L2_CTRL_CLASS_CODEC` contains controls relating to codecs.

All controls in the control array must belong to the specified control class. An error is returned if this is not the case.

It is also possible to use an empty control array (`count` == 0) to check whether the specified control class is supported.

The control array is a struct `v4l2_ext_control` array. The struct `v4l2_ext_control` is very similar to struct `v4l2_control`, except for the fact that it also allows for 64-bit values and pointers to be passed.

Since the struct `v4l2_ext_control` supports pointers it is now also possible to have controls with compound types such as N-dimensional arrays and/or structures. You need to specify the `V4L2_CTRL_FLAG_NEXT_COMPOUND` when enumerating controls to actually be able to see such compound controls. In other words, these controls with compound types should only be used programmatically.

Since such compound controls need to expose more information about themselves than is possible with [VIDIOC_QUERYCTRL](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) the [VIDIOC_QUERY_EXT_CTRL](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl was added. In particular, this ioctl gives the dimensions of the N-dimensional array if this control consists of more than one element.

> [!NOTE]
>
> 1. It is important to realize that due to the flexibility of controls it is necessary to check whether the control you want to set actually is supported in the driver and what the valid range of values is. So use [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) to check this.
>
> 2. It is possible that some of the menu indices in a control of type `V4L2_CTRL_TYPE_MENU` may not be supported (`VIDIOC_QUERYMENU` will return an error). A good example is the list of supported MPEG audio bitrates. Some drivers only support one or two bitrates, others support a wider range.

All controls use machine endianness.

<a id="rst-enumerating-extended-controls"></a>

## Enumerating Extended Controls

The recommended way to enumerate over the extended controls is by using [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) in combination with the `V4L2_CTRL_FLAG_NEXT_CTRL` flag:



```c
struct v4l2_queryctrl qctrl;

qctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
while (0 == ioctl (fd, VIDIOC_QUERYCTRL, &qctrl)) {
    /* ... */
    qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
}
```

The initial control ID is set to 0 ORed with the `V4L2_CTRL_FLAG_NEXT_CTRL` flag. The `VIDIOC_QUERYCTRL` ioctl will return the first control with a higher ID than the specified one. When no such controls are found an error is returned.

If you want to get all controls within a specific control class, then you can set the initial `qctrl.id` value to the control class and add an extra check to break out of the loop when a control of another control class is found:



```c
qctrl.id = V4L2_CTRL_CLASS_CODEC | V4L2_CTRL_FLAG_NEXT_CTRL;
while (0 == ioctl(fd, VIDIOC_QUERYCTRL, &qctrl)) {
    if (V4L2_CTRL_ID2CLASS(qctrl.id) != V4L2_CTRL_CLASS_CODEC)
        break;
    /* ... */
    qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
}
```

The 32-bit `qctrl.id` value is subdivided into three bit ranges: the top 4 bits are reserved for flags (e. g. `V4L2_CTRL_FLAG_NEXT_CTRL`) and are not actually part of the ID. The remaining 28 bits form the control ID, of which the most significant 12 bits define the control class and the least significant 16 bits identify the control within the control class. It is guaranteed that these last 16 bits are always non-zero for controls. The range of 0x1000 and up are reserved for driver-specific controls. The macro `V4L2_CTRL_ID2CLASS(id)` returns the control class ID based on a control ID.

If the driver does not support extended controls, then `VIDIOC_QUERYCTRL` will fail when used in combination with `V4L2_CTRL_FLAG_NEXT_CTRL`. In that case the old method of enumerating control should be used (see [Example: Enumerating all controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-enum-all-controls>)). But if it is supported, then it is guaranteed to enumerate over all controls, including driver-private controls.

<a id="rst-creating-control-panels"></a>

## Creating Control Panels

It is possible to create control panels for a graphical user interface where the user can select the various controls. Basically you will have to iterate over all controls using the method described above. Each control class starts with a control of type `V4L2_CTRL_TYPE_CTRL_CLASS`. `VIDIOC_QUERYCTRL` will return the name of this control class which can be used as the title of a tab page within a control panel.

The flags field of struct [v4l2_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) also contains hints on the behavior of the control. See the [vidioc_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) documentation for more details.

---

# Field Order

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> We have to distinguish between progressive and interlaced video. Progressive video transmits all lines of a video image sequentially. Interlaced video divides an image into two fields, containing only the odd and even lines of the image,…

<a id="rst-field-order-1"></a>
<a id="rst-field-order"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

We have to distinguish between progressive and interlaced video. Progressive video transmits all lines of a video image sequentially. Interlaced video divides an image into two fields, containing only the odd and even lines of the image, respectively. Alternating the so called odd and even field are transmitted, and due to a small delay between fields a cathode ray TV displays the lines interleaved, yielding the original frame. This curious technique was invented because at refresh rates similar to film the image would fade out too quickly. Transmitting fields reduces the flicker without the necessity of doubling the frame rate and with it the bandwidth required for each channel.

It is important to understand a video camera does not expose one frame at a time, merely transmitting the frames separated into fields. The fields are in fact captured at two different instances in time. An object on screen may well move between one field and the next. For applications analysing motion it is of paramount importance to recognize which field of a frame is older, the *temporal order*.

When the driver provides or accepts images field by field rather than interleaved, it is also important applications understand how the fields combine to frames. We distinguish between top (aka odd) and bottom (aka even) fields, the *spatial order*: The first line of the top field is the first line of an interlaced frame, the first line of the bottom field is the second line of that frame.

However because fields were captured one after the other, arguing whether a frame commences with the top or bottom field is pointless. Any two successive top and bottom, or bottom and top fields yield a valid frame. Only when the source was progressive to begin with, e. g. when transferring film to video, two fields may come from the same frame, creating a natural order.

Counter to intuition the top field is not necessarily the older field. Whether the older field contains the top or bottom lines is a convention determined by the video standard. Hence the distinction between temporal and spatial order of fields. The diagrams below should make this clearer.

In V4L it is assumed that all video cameras transmit fields on the media bus in the same order they were captured, so if the top field was captured first (is the older field), the top field is also transmitted first on the bus.

All video capture and output devices must report the current field order. Some drivers may permit the selection of a different order, to this end applications initialize the `field` field of struct `v4l2_pix_format` before calling the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. If this is not desired it should have the value `V4L2_FIELD_ANY` (0).

<a id="rst-enum-v4l2-field"></a>

## enum v4l2_field





<a id="c-v4l2_field"></a>

```c
v4l2_field
```

<!-- tabularcolumns: |p{5.8cm}|p{0.6cm}|p{10.9cm}| -->


<table>
<tbody>
<tr>
<td>


`V4L2_FIELD_ANY`

</td>
<td>


0

</td>
<td>


Applications request this field order when any field format is acceptable. Drivers choose depending on hardware capabilities or e.g. the requested image size, and return the actual field order. Drivers must never return `V4L2_FIELD_ANY`. If multiple field orders are possible the driver must choose one of the possible field orders during [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) or [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>). struct `v4l2_buffer` `field` can never be `V4L2_FIELD_ANY`.

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_NONE`

</td>
<td>


1

</td>
<td>


Images are in progressive (frame-based) format, not interlaced (field-based).

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_TOP`

</td>
<td>


2

</td>
<td>


Images consist of the top (aka odd) field only.

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_BOTTOM`

</td>
<td>


3

</td>
<td>


Images consist of the bottom (aka even) field only. Applications may wish to prevent a device from capturing interlaced images because they will have "comb" or "feathering" artefacts around moving objects.

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_INTERLACED`

</td>
<td>


4

</td>
<td>


Images contain both fields, interleaved line by line. The temporal order of the fields (whether the top or bottom field is older) depends on the current video standard. In M/NTSC the bottom field is the older field. In all other standards the top field is the older field.

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_SEQ_TB`

</td>
<td>


5

</td>
<td>


Images contain both fields, the top field lines are stored first in memory, immediately followed by the bottom field lines. Fields are always stored in temporal order, the older one first in memory. Image sizes refer to the frame, not fields.

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_SEQ_BT`

</td>
<td>


6

</td>
<td>


Images contain both fields, the bottom field lines are stored first in memory, immediately followed by the top field lines. Fields are always stored in temporal order, the older one first in memory. Image sizes refer to the frame, not fields.

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_ALTERNATE`

</td>
<td>


7

</td>
<td>


The two fields of a frame are passed in separate buffers, in temporal order, i. e. the older one first. To indicate the field parity (whether the current field is a top or bottom field) the driver or application, depending on data direction, must set struct `v4l2_buffer` `field` to `V4L2_FIELD_TOP` or `V4L2_FIELD_BOTTOM`. Any two successive fields pair to build a frame. If fields are successive, without any dropped fields between them (fields can drop individually), can be determined from the struct `v4l2_buffer` `sequence` field. This format cannot be selected when using the read/write I/O method since there is no way to communicate if a field was a top or bottom field.

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_INTERLACED_TB`

</td>
<td>


8

</td>
<td>


Images contain both fields, interleaved line by line, top field first. The top field is the older field.

</td>
</tr>
<tr>
<td>


`V4L2_FIELD_INTERLACED_BT`

</td>
<td>


9

</td>
<td>


Images contain both fields, interleaved line by line, top field first. The bottom field is the older field.

</td>
</tr>
</tbody>
</table>

<a id="rst-field-order-top-field-first-transmitted"></a>
<a id="rst-fieldseq-tb"></a>

## Field Order, Top Field First Transmitted

![fieldseq_tb.svg](/kernel/userspace/userspace-api/media-v4l/asset-802fc3a73b90-fieldseq-tb.svg)

Field Order, Top Field First Transmitted

<a id="rst-field-order-bottom-field-first-transmitted"></a>
<a id="rst-fieldseq-bt"></a>

## Field Order, Bottom Field First Transmitted

![fieldseq_bt.svg](/kernel/userspace/userspace-api/media-v4l/asset-62d1192065f5-fieldseq-bt.svg)

Field Order, Bottom Field First Transmitted

---

# Data Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Different devices exchange different kinds of data with applications, for example video images, raw or sliced VBI data, RDS datagrams. Even within one kind many different formats are possible, in particular there is an abundance of image…

<a id="rst-data-formats"></a>
<a id="rst-format"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-data-format-negotiation"></a>

## Data Format Negotiation

Different devices exchange different kinds of data with applications, for example video images, raw or sliced VBI data, RDS datagrams. Even within one kind many different formats are possible, in particular there is an abundance of image formats. Although drivers must provide a default and the selection persists across closing and reopening a device, applications should always negotiate a data format before engaging in data exchange. Negotiation means the application asks for a particular format and the driver selects and reports the best the hardware can do to satisfy the request. Of course applications can also just query the current selection.

A single mechanism exists to negotiate all data formats using the aggregate struct `v4l2_format` and the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls. Additionally the [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl can be used to examine what the hardware *could* do, without actually selecting a new data format. The data formats supported by the V4L2 API are covered in the respective device section in [Interfaces](</kernel/userspace/userspace-api/media-v4l/devices.md#rst-devices>). For a closer look at image formats see [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>).

The [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl is a major turning-point in the initialization sequence. Prior to this point multiple panel applications can access the same device concurrently to select the current input, change controls or modify other properties. The first [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) assigns a logical stream (video data, VBI data etc.) exclusively to one file descriptor.

Exclusive means no other application, more precisely no other file descriptor, can grab this stream or change device properties inconsistent with the negotiated parameters. A video standard change for example, when the new standard uses a different number of scan lines, can invalidate the selected image format. Therefore only the file descriptor owning the stream can make invalidating changes. Accordingly multiple file descriptors which grabbed different logical streams prevent each other from interfering with their settings. When for example video overlay is about to start or already in progress, simultaneous video capturing may be restricted to the same cropping and image size.

When applications omit the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl its locking side effects are implied by the next step, the selection of an I/O method with the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl or implicit with the first `read()` or `write()` call.

Generally only one logical stream can be assigned to a file descriptor, the exception being drivers permitting simultaneous video capturing and overlay using the same file descriptor for compatibility with V4L and earlier versions of V4L2. Switching the logical stream or returning into "panel mode" is possible by closing and reopening the device. Drivers *may* support a switch using [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>).

All drivers exchanging data with applications must support the [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. Implementation of the [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) is highly recommended but optional.

<a id="rst-image-format-enumeration"></a>

## Image Format Enumeration

Apart of the generic format negotiation functions a special ioctl to enumerate all image formats supported by video capture, overlay or output devices is available. <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

The [ioctl VIDIOC_ENUM_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) ioctl must be supported by all drivers exchanging image data with applications.

> [!IMPORTANT]
>
> Drivers are not supposed to convert image formats in kernel space. They must enumerate only formats directly supported by the hardware. If necessary driver writers should publish an example conversion routine or library for integration into applications.

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



**[1]** Enumerating formats an application has no a-priori knowledge of (otherwise it could explicitly ask for them and need not enumerate) seems useless, but there are applications serving as proxy between drivers and the actual video applications for which this is useful.

---

# Guidelines for Video4Linux pixel format 4CCs

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Guidelines for Video4Linux 4CC codes defined using v4l2_fourcc() are specified in this document. First of the characters defines the nature of the pixel format, compression and colour space. The interpretation of the other three characters…

<a id="rst-guidelines-for-video4linux-pixel-format-4ccs"></a>

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

<!-- c:namespace: V4L -->

Guidelines for Video4Linux 4CC codes defined using v4l2_fourcc() are specified in this document. First of the characters defines the nature of the pixel format, compression and colour space. The interpretation of the other three characters depends on the first one.

Existing 4CCs may not obey these guidelines.

<a id="rst-raw-bayer"></a>

## Raw bayer

The following first characters are used by raw bayer formats:

- B: raw bayer, uncompressed

- b: raw bayer, DPCM compressed

- a: A-law compressed

- u: u-law compressed

2nd character: pixel order

- B: BGGR

- G: GBRG

- g: GRBG

- R: RGGB

3rd character: uncompressed bits-per-pixel 0--9, A--

4th character: compressed bits-per-pixel 0--9, A--

---

# V4L2 close()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-close - Close a V4L2 device

<a id="rst-v4l2-close"></a>
<a id="rst-func-close"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-close - Close a V4L2 device

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-close"></a>

```c
int close( int fd )
```

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

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

## Description

Closes the device. Any I/O in progress is terminated and resources associated with the file descriptor are freed. However data format parameters, current input or output, control values or other properties remain unchanged.

<a id="rst-return-value"></a>

## Return Value

The function returns 0 on success, -1 on failure and the `errno` is set appropriately. Possible error codes:

- **EBADF**

  `fd` is not a valid open file descriptor.

---

# V4L2 ioctl()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-ioctl - Program a V4L2 device

<a id="rst-v4l2-ioctl"></a>
<a id="rst-func-ioctl"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-ioctl - Program a V4L2 device

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

## Synopsis



```c
#include <sys/ioctl.h>
```

`int ioctl(int fd, int request, void *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`request`**

  V4L2 ioctl request code as defined in the `videodev2.h` header file, for example VIDIOC_QUERYCAP.

- **`argp`**

  Pointer to a function parameter, usually a structure.

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

## Description

The [ioctl()](<#rst-func-ioctl>) function is used to program V4L2 devices. The argument `fd` must be an open file descriptor. An ioctl `request` has encoded in it whether the argument is an input, output or read/write parameter, and the size of the argument `argp` in bytes. Macros and defines specifying V4L2 ioctl requests are located in the `videodev2.h` header file. Applications should use their own copy, not include the version in the kernel sources on the system they compile on. All V4L2 ioctl requests, their respective function and parameters are specified in [Function Reference](</kernel/userspace/userspace-api/media-v4l/user-func.md#rst-user-func>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

When an ioctl that takes an output or read/write parameter fails, the parameter remains unmodified.

---

# V4L2 mmap()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-mmap - Map device memory into application address space

<a id="rst-v4l2-mmap"></a>
<a id="rst-func-mmap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-mmap - Map device memory into application address space

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

## Synopsis



```c
#include <unistd.h>
#include <sys/mman.h>
```





<a id="c-mmap"></a>

```c
void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset )
```

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

## Arguments

- **`start`**

  Map the buffer to this address in the application's address space. When the `MAP_FIXED` flag is specified, `start` must be a multiple of the pagesize and mmap will fail when the specified address cannot be used. Use of this option is discouraged; applications should just specify a `NULL` pointer here.

- **`length`**

  Length of the memory area to map. This must be the same value as returned by the driver in the struct `v4l2_buffer` `length` field for the single-planar API, and the same value as returned by the driver in the struct `v4l2_plane` `length` field for the multi-planar API.

- **`prot`**

  The `prot` argument describes the desired memory protection. Regardless of the device type and the direction of data exchange it should be set to `PROT_READ` \| `PROT_WRITE`, permitting read and write access to image buffers. Drivers should support at least this combination of flags.

  > [!NOTE]
  >
  > 1. The Linux `videobuf` kernel module, which is used by some drivers supports only `PROT_READ` \| `PROT_WRITE`. When the driver does not support the desired protection, the `mmap()` function fails.
  >
  > 2. Device memory accesses (e. g. the memory on a graphics card with video capturing hardware) may incur a performance penalty compared to main memory accesses, or reads may be significantly slower than writes or vice versa. Other I/O methods may be more efficient in such case.

- **`flags`**

  The `flags` parameter specifies the type of the mapped object, mapping options and whether modifications made to the mapped copy of the page are private to the process or are to be shared with other references.

  `MAP_FIXED` requests that the driver selects no other address than the one specified. If the specified address cannot be used, `mmap()` will fail. If `MAP_FIXED` is specified, `start` must be a multiple of the pagesize. Use of this option is discouraged.

  One of the `MAP_SHARED` or `MAP_PRIVATE` flags must be set. `MAP_SHARED` allows applications to share the mapped memory with other (e. g. child-) processes.

  > [!NOTE]
  >
  > The Linux `videobuf` module  which is used by some drivers supports only `MAP_SHARED`. `MAP_PRIVATE` requests copy-on-write semantics. V4L2 applications should not set the `MAP_PRIVATE`, `MAP_DENYWRITE`, `MAP_EXECUTABLE` or `MAP_ANON` flags.

- **`fd`**

  File descriptor returned by `open()`.

- **`offset`**

  Offset of the buffer in device memory. This must be the same value as returned by the driver in the struct `v4l2_buffer` `m` union `offset` field for the single-planar API, and the same value as returned by the driver in the struct `v4l2_plane` `m` union `mem_offset` field for the multi-planar API.

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

## Description

The `mmap()` function asks to map `length` bytes starting at `offset` in the memory of the device specified by `fd` into the application address space, preferably at address `start`. This latter address is a hint only, and is usually specified as 0.

Suitable length and offset parameters are queried with the [ioctl VIDIOC_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>) ioctl. Buffers must be allocated with the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl before they can be queried.

To unmap buffers the `munmap()` function is used.

<a id="rst-return-value"></a>

## Return Value

On success `mmap()` returns a pointer to the mapped buffer. On error `MAP_FAILED` (-1) is returned, and the `errno` variable is set appropriately. Possible error codes are:

- **EBADF**

  `fd` is not a valid file descriptor.

- **EACCES**

  `fd` is not open for reading and writing.

- **EINVAL**

  The `start` or `length` or `offset` are not suitable. (E. g. they are too large, or not aligned on a `PAGESIZE` boundary.)

  The `flags` or `prot` value is not supported.

  No buffers have been allocated with the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl.

- **ENOMEM**

  Not enough physical or virtual memory was available to complete the request.

---

# V4L2 munmap()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-munmap - Unmap device memory

<a id="rst-v4l2-munmap"></a>
<a id="rst-func-munmap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-munmap - Unmap device memory

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

## Synopsis



```c
#include <unistd.h>
#include <sys/mman.h>
```





<a id="c-munmap"></a>

```c
int munmap( void *start, size_t length )
```

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

## Arguments

- **`start`**

  Address of the mapped buffer as returned by the `mmap()` function.

- **`length`**

  Length of the mapped buffer. This must be the same value as given to `mmap()` and returned by the driver in the struct `v4l2_buffer` `length` field for the single-planar API and in the struct `v4l2_plane` `length` field for the multi-planar API.

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

## Description

Unmaps a previously with the `mmap()` function mapped buffer and frees it, if possible.

<a id="rst-return-value"></a>

## Return Value

On success `munmap()` returns 0, on failure -1 and the `errno` variable is set appropriately:

- **EINVAL**

  The `start` or `length` is incorrect, or no buffers have been mapped yet.

---

# V4L2 open()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-open - Open a V4L2 device

<a id="rst-v4l2-open"></a>
<a id="rst-func-open"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-open - Open a V4L2 device

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

## Synopsis



```c
#include <fcntl.h>
```





<a id="c-open"></a>

```c
int open( const char *device_name, int flags )
```

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

## Arguments

- **`device_name`**

  Device to be opened.

- **`flags`**

  Open flags. Access mode must be `O_RDWR`. This is just a technicality, input devices still support only reading and output devices only writing.

  When the `O_NONBLOCK` flag is given, the `read()` function and the [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl will return the `EAGAIN` error code when no data is available or no buffer is in the driver outgoing queue, otherwise these functions block until data becomes available. All V4L2 drivers exchanging data with applications must support the `O_NONBLOCK` flag.

  Other flags have no effect.

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

## Description

To open a V4L2 device applications call `open()` with the desired device name. This function has no side effects; all data format parameters, current input or output, control values or other properties remain unchanged. At the first `open()` call after loading the driver they will be reset to default values, drivers are never in an undefined state.

<a id="rst-return-value"></a>

## Return Value

On success `open()` returns the new file descriptor. On error -1 is returned, and the `errno` variable is set appropriately. Possible error codes are:

- **EACCES**

  The caller has no permission to access the device.

- **EBUSY**

  The driver does not support multiple opens and the device is already in use.

- **ENODEV**

  Device not found or was removed.

- **ENOMEM**

  Not enough kernel memory was available to complete the request.

- **EMFILE**

  The process already has the maximum number of files open.

- **ENFILE**

  The limit on the total number of files open on the system has been reached.

---

# V4L2 poll()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-poll - Wait for some event on a file descriptor

<a id="rst-v4l2-poll"></a>
<a id="rst-func-poll"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-poll - Wait for some event on a file descriptor

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

## Synopsis



```c
#include <sys/poll.h>
```





<a id="c-poll"></a>

```c
int poll( struct pollfd *ufds, unsigned int nfds, int timeout )
```

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

## Arguments

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

## Description

With the `poll()` function applications can suspend execution until the driver has captured data or is ready to accept data for output.

When streaming I/O has been negotiated this function waits until a buffer has been filled by the capture device and can be dequeued with the [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. For output devices this function waits until the device is ready to accept a new buffer to be queued up with the [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl for display. When buffers are already in the outgoing queue of the driver (capture) or the incoming queue isn't full (display) the function returns immediately.

On success `poll()` returns the number of file descriptors that have been selected (that is, file descriptors for which the `revents` field of the respective `struct pollfd` structure is non-zero). Capture devices set the `POLLIN` and `POLLRDNORM` flags in the `revents` field, output devices the `POLLOUT` and `POLLWRNORM` flags. When the function timed out it returns a value of zero, on failure it returns -1 and the `errno` variable is set appropriately. When the application did not call [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) the `poll()` function succeeds, but sets the `POLLERR` flag in the `revents` field. When the application has called [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) for a capture device but hasn't yet called [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), the `poll()` function succeeds and sets the `POLLERR` flag in the `revents` field. For output devices this same situation will cause `poll()` to succeed as well, but it sets the `POLLOUT` and `POLLWRNORM` flags in the `revents` field.

If an event occurred (see [ioctl VIDIOC_DQEVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-vidioc-dqevent>)) then `POLLPRI` will be set in the `revents` field and `poll()` will return.

When use of the `read()` function has been negotiated and the driver does not capture yet, the `poll()` function starts capturing. When that fails it returns a `POLLERR` as above. Otherwise it waits until data has been captured and can be read. When the driver captures continuously (as opposed to, for example, still images) the function may return immediately.

When use of the `write()` function has been negotiated and the driver does not stream yet, the `poll()` function starts streaming. When that fails it returns a `POLLERR` as above. Otherwise it waits until the driver is ready for a non-blocking `write()` call.

If the caller is only interested in events (just `POLLPRI` is set in the `events` field), then `poll()` will *not* start streaming if the driver does not stream yet. This makes it possible to just poll for events and not for buffers.

All drivers implementing the `read()` or `write()` function or streaming I/O must also support the `poll()` function.

For more details see the `poll()` manual page.

<a id="rst-return-value"></a>

## Return Value

On success, `poll()` returns the number structures which have non-zero `revents` fields, or zero if the call timed out. On error -1 is returned, and the `errno` variable is set appropriately:

- **EBADF**

  One or more of the `ufds` members specify an invalid file descriptor.

- **EBUSY**

  The driver does not support multiple read or write streams and the device is already in use.

- **EFAULT**

  `ufds` references an inaccessible memory area.

- **EINTR**

  The call was interrupted by a signal.

- **EINVAL**

  The `nfds` value exceeds the `RLIMIT_NOFILE` value. Use `getrlimit()` to obtain this value.

---

# V4L2 read()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-read - Read from a V4L2 device

<a id="rst-v4l2-read"></a>
<a id="rst-func-read"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-read - Read from a V4L2 device

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-read"></a>

```c
ssize_t read( int fd, void *buf, size_t count )
```

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`buf`**

  Buffer to be filled

- **`count`**

  Max number of bytes to read

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

## Description

`read()` attempts to read up to `count` bytes from file descriptor `fd` into the buffer starting at `buf`. The layout of the data in the buffer is discussed in the respective device interface section, see \#\#. If `count` is zero, `read()` returns zero and has no other results. If `count` is greater than `SSIZE_MAX`, the result is unspecified. Regardless of the `count` value each `read()` call will provide at most one frame (two fields) worth of data.

By default `read()` blocks until data becomes available. When the `O_NONBLOCK` flag was given to the `open()` function it returns immediately with an `EAGAIN` error code when no data is available. The `select()` or `poll()` functions can always be used to suspend execution until data becomes available. All drivers supporting the `read()` function must also support `select()` and `poll()`.

Drivers can implement read functionality in different ways, using a single or multiple buffers and discarding the oldest or newest frames once the internal buffers are filled.

`read()` never returns a "snapshot" of a buffer being filled. Using a single buffer the driver will stop capturing when the application starts reading the buffer until the read is finished. Thus only the period of the vertical blanking interval is available for reading, or the capture rate must fall below the nominal frame rate of the video standard.

The behavior of `read()` when called during the active picture period or the vertical blanking separating the top and bottom field depends on the discarding policy. A driver discarding the oldest frames keeps capturing into an internal buffer, continuously overwriting the previously, not read frame, and returns the frame being received at the time of the `read()` call as soon as it is complete.

A driver discarding the newest frames stops capturing until the next `read()` call. The frame being received at `read()` time is discarded, returning the following frame instead. Again this implies a reduction of the capture rate to one half or less of the nominal frame rate. An example of this model is the video read mode of the bttv driver, initiating a DMA to user memory when `read()` is called and returning when the DMA finished.

In the multiple buffer model drivers maintain a ring of internal buffers, automatically advancing to the next free buffer. This allows continuous capturing when the application can empty the buffers fast enough. Again, the behavior when the driver runs out of free buffers depends on the discarding policy.

Applications can get and set the number of buffers used internally by the driver with the [VIDIOC_G_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm>) and [VIDIOC_S_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm>) ioctls. They are optional, however. The discarding policy is not reported and cannot be changed. For minimum requirements see [Interfaces](</kernel/userspace/userspace-api/media-v4l/devices.md#rst-devices>).

<a id="rst-return-value"></a>

## Return Value

On success, the number of bytes read is returned. It is not an error if this number is smaller than the number of bytes requested, or the amount of data required for one frame. This may happen for example because `read()` was interrupted by a signal. On error, -1 is returned, and the `errno` variable is set appropriately. In this case the next read will start at the beginning of a new frame. Possible error codes are:

- **EAGAIN**

  Non-blocking I/O has been selected using O_NONBLOCK and no data was immediately available for reading.

- **EBADF**

  `fd` is not a valid file descriptor or is not open for reading, or the process already has the maximum number of files open.

- **EBUSY**

  The driver does not support multiple read streams and the device is already in use.

- **EFAULT**

  `buf` references an inaccessible memory area.

- **EINTR**

  The call was interrupted by a signal before any data was read.

- **EIO**

  I/O error. This indicates some hardware problem or a failure to communicate with a remote device (USB camera etc.).

- **EINVAL**

  The `read()` function is not supported by this driver, not on this device, or generally not on this type of device.

---

# V4L2 select()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-select - Synchronous I/O multiplexing

<a id="rst-v4l2-select"></a>
<a id="rst-func-select"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-select - Synchronous I/O multiplexing

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

## Synopsis



```c
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
```





<a id="c-select"></a>

```c
int select( int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout )
```

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

## Arguments

- **`nfds`**

  The highest-numbered file descriptor in any of the three sets, plus 1.

- **`readfds`**

  File descriptions to be watched if a read() call won't block.

- **`writefds`**

  File descriptions to be watched if a write() won't block.

- **`exceptfds`**

  File descriptions to be watched for V4L2 events.

- **`timeout`**

  Maximum time to wait.

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

## Description

With the `select()` function applications can suspend execution until the driver has captured data or is ready to accept data for output.

When streaming I/O has been negotiated this function waits until a buffer has been filled or displayed and can be dequeued with the [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. When buffers are already in the outgoing queue of the driver the function returns immediately.

On success `select()` returns the total number of bits set in `fd_set`. When the function timed out it returns a value of zero. On failure it returns -1 and the `errno` variable is set appropriately. When the application did not call [ioctl VIDIOC_QBUF, VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) or [ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) yet the `select()` function succeeds, setting the bit of the file descriptor in `readfds` or `writefds`, but subsequent [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) calls will fail. <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

When use of the `read()` function has been negotiated and the driver does not capture yet, the `select()` function starts capturing. When that fails, `select()` returns successful and a subsequent `read()` call, which also attempts to start capturing, will return an appropriate error code. When the driver captures continuously (as opposed to, for example, still images) and data is already available the `select()` function returns immediately.

When use of the `write()` function has been negotiated the `select()` function just waits until the driver is ready for a non-blocking `write()` call.

All drivers implementing the `read()` or `write()` function or streaming I/O must also support the `select()` function.

For more details see the `select()` manual page.

<a id="rst-return-value"></a>

## Return Value

On success, `select()` returns the number of descriptors contained in the three returned descriptor sets, which will be zero if the timeout expired. On error -1 is returned, and the `errno` variable is set appropriately; the sets and `timeout` are undefined. Possible error codes are:

- **EBADF**

  One or more of the file descriptor sets specified a file descriptor that is not open.

- **EBUSY**

  The driver does not support multiple read or write streams and the device is already in use.

- **EFAULT**

  The `readfds`, `writefds`, `exceptfds` or `timeout` pointer references an inaccessible memory area.

- **EINTR**

  The call was interrupted by a signal.

- **EINVAL**

  The `nfds` argument is less than zero or greater than `FD_SETSIZE`.

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



**[1]** The Linux kernel implements `select()` like the `poll()` function, but `select()` cannot return a `POLLERR`.

---

# V4L2 write()

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> v4l2-write - Write to a V4L2 device

<a id="rst-v4l2-write"></a>
<a id="rst-func-write"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

v4l2-write - Write to a V4L2 device

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

## Synopsis



```c
#include <unistd.h>
```





<a id="c-write"></a>

```c
ssize_t write( int fd, void *buf, size_t count )
```

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`buf`**

  Buffer with data to be written

- **`count`**

  Number of bytes at the buffer

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

## Description

`write()` writes up to `count` bytes to the device referenced by the file descriptor `fd` from the buffer starting at `buf`. When the hardware outputs are not active yet, this function enables them. When `count` is zero, `write()` returns 0 without any other effect.

When the application does not provide more data in time, the previous video frame, raw VBI image, sliced VPS or WSS data is displayed again. Sliced Teletext or Closed Caption data is not repeated, the driver inserts a blank line instead.

<a id="rst-return-value"></a>

## Return Value

On success, the number of bytes written are returned. Zero indicates nothing was written. On error, -1 is returned, and the `errno` variable is set appropriately. In this case the next write will start at the beginning of a new frame. Possible error codes are:

- **EAGAIN**

  Non-blocking I/O has been selected using the [O_NONBLOCK](</kernel/userspace/userspace-api/media-v4l/func-open.md#rst-func-open>) flag and no buffer space was available to write the data immediately.

- **EBADF**

  `fd` is not a valid file descriptor or is not open for writing.

- **EBUSY**

  The driver does not support multiple write streams and the device is already in use.

- **EFAULT**

  `buf` references an inaccessible memory area.

- **EINTR**

  The call was interrupted by a signal before any data was written.

- **EIO**

  I/O error. This indicates some hardware problem.

- **EINVAL**

  The `write()` function is not supported by this driver, not on this device, or generally not on this type of device.

---

# Changes of the V4L2 API

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Soon after the V4L API was added to the kernel it was criticised as too inflexible. In August 1998 Bill Dirks proposed a number of improvements and began to work on documentation, example drivers and applications. With the help of other…

<a id="rst-changes-of-the-v4l2-api"></a>
<a id="rst-hist-v4l2"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Soon after the V4L API was added to the kernel it was criticised as too inflexible. In August 1998 Bill Dirks proposed a number of improvements and began to work on documentation, example drivers and applications. With the help of other volunteers this eventually became the V4L2 API, not just an extension but a replacement for the V4L API. However it took another four years and two stable kernel releases until the new API was finally accepted for inclusion into the kernel in its present form.

<a id="rst-early-versions"></a>

## Early Versions

1998-08-20: First version.

1998-08-27: The `select()` function was introduced.

1998-09-10: New video standard interface.

1998-09-18: The `VIDIOC_NONCAP` ioctl was replaced by the otherwise meaningless `O_TRUNC` `open()` flag, and the aliases `O_NONCAP` and `O_NOIO` were defined. Applications can set this flag if they intend to access controls only, as opposed to capture applications which need exclusive access. The `VIDEO_STD_XXX` identifiers are now ordinals instead of flags, and the `video_std_construct()` helper function takes id and transmission arguments.

1998-09-28: Revamped video standard. Made video controls individually enumerable.

1998-10-02: The `id` field was removed from struct `video_standard` and the color subcarrier fields were renamed. The [vidioc\_querystd](</kernel/userspace/userspace-api/media-v4l/vidioc-querystd.md#rst-vidioc-querystd>) ioctl was renamed to [ioctl VIDIOC\_ENUMSTD, VIDIOC\_SUBDEV\_ENUMSTD](</kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-vidioc-enumstd>), [VIDIOC\_G\_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input>) to [vidioc\_enuminput](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>). A first draft of the Codec API was released.

1998-11-08: Many minor changes. Most symbols have been renamed. Some material changes to struct v4l2\_capability.

1998-11-12: The read/write direction of some ioctls was misdefined.

1998-11-14: `V4L2_PIX_FMT_RGB24` changed to `V4L2_PIX_FMT_BGR24`, and `V4L2_PIX_FMT_RGB32` changed to `V4L2_PIX_FMT_BGR32`. Audio controls are now accessible with the [VIDIOC\_G\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) and [VIDIOC\_S\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) ioctls under names starting with `V4L2_CID_AUDIO`. The `V4L2_MAJOR` define was removed from `videodev.h` since it was only used once in the `videodev` kernel module. The `YUV422` and `YUV411` planar image formats were added.

1998-11-28: A few ioctl symbols changed. Interfaces for codecs and video output devices were added.

1999-01-14: A raw VBI capture interface was added.

1999-01-19: The `VIDIOC_NEXTBUF` ioctl was removed.

<a id="rst-v4l2-version-0-16-1999-01-31"></a>

## V4L2 Version 0.16 1999-01-31

1999-01-27: There is now one QBUF ioctl, VIDIOC\_QWBUF and VIDIOC\_QRBUF are gone. VIDIOC\_QBUF takes a v4l2\_buffer as a parameter. Added digital zoom (cropping) controls.

<a id="rst-v4l2-version-0-18-1999-03-16"></a>

## V4L2 Version 0.18 1999-03-16

Added a v4l to V4L2 ioctl compatibility layer to videodev.c. Driver writers, this changes how you implement your ioctl handler. See the Driver Writer's Guide. Added some more control id codes.

<a id="rst-v4l2-version-0-19-1999-06-05"></a>

## V4L2 Version 0.19 1999-06-05

1999-03-18: Fill in the category and catname fields of v4l2\_queryctrl objects before passing them to the driver. Required a minor change to the VIDIOC\_QUERYCTRL handlers in the sample drivers.

1999-03-31: Better compatibility for v4l memory capture ioctls. Requires changes to drivers to fully support new compatibility features, see Driver Writer's Guide and v4l2cap.c. Added new control IDs: V4L2\_CID\_HFLIP, \_VFLIP. Changed V4L2\_PIX\_FMT\_YUV422P to \_YUV422P, and \_YUV411P to \_YUV411P.

1999-04-04: Added a few more control IDs.

1999-04-07: Added the button control type.

1999-05-02: Fixed a typo in videodev.h, and added the V4L2\_CTRL\_FLAG\_GRAYED (later V4L2\_CTRL\_FLAG\_GRABBED) flag.

1999-05-20: Definition of VIDIOC\_G\_CTRL was wrong causing a malfunction of this ioctl.

1999-06-05: Changed the value of V4L2\_CID\_WHITENESS.

<a id="rst-v4l2-version-0-20-1999-09-10"></a>

## V4L2 Version 0.20 (1999-09-10)

Version 0.20 introduced a number of changes which were <em>not backward compatible</em> with 0.19 and earlier versions. Purpose of these changes was to simplify the API, while making it more extensible and following common Linux driver API conventions.

1. Some typos in `V4L2_FMT_FLAG` symbols were fixed. struct v4l2\_clip was changed for compatibility with v4l. (1999-08-30)

2. `V4L2_TUNER_SUB_LANG1` was added. (1999-09-05)

3. All ioctl() commands that used an integer argument now take a pointer to an integer. Where it makes sense, ioctls will return the actual new value in the integer pointed to by the argument, a common convention in the V4L2 API. The affected ioctls are: VIDIOC\_PREVIEW, VIDIOC\_STREAMON, VIDIOC\_STREAMOFF, VIDIOC\_S\_FREQ, VIDIOC\_S\_INPUT, VIDIOC\_S\_OUTPUT, VIDIOC\_S\_EFFECT. For example



   ```c
   err = ioctl (fd, VIDIOC_XXX, V4L2_XXX);
   ```

   becomes



   ```c
   int a = V4L2_XXX; err = ioctl(fd, VIDIOC_XXX, &a);
   ```

4. All the different get- and set-format commands were swept into one [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl taking a union and a type field selecting the union member as parameter. Purpose is to simplify the API by eliminating several ioctls and to allow new and driver private data streams without adding new ioctls.

   This change obsoletes the following ioctls: `VIDIOC_S_INFMT`, `VIDIOC_G_INFMT`, `VIDIOC_S_OUTFMT`, `VIDIOC_G_OUTFMT`, `VIDIOC_S_VBIFMT` and `VIDIOC_G_VBIFMT`. The image format struct v4l2\_format was renamed to struct v4l2\_pix\_format, while struct v4l2\_format is now the enveloping structure for all format negotiations.

5. Similar to the changes above, the `VIDIOC_G_PARM` and `VIDIOC_S_PARM` ioctls were merged with `VIDIOC_G_OUTPARM` and `VIDIOC_S_OUTPARM`. A `type` field in the new struct v4l2\_streamparm selects the respective union member.

   This change obsoletes the `VIDIOC_G_OUTPARM` and `VIDIOC_S_OUTPARM` ioctls.

6. Control enumeration was simplified, and two new control flags were introduced and one dropped. The `catname` field was replaced by a `group` field.

   Drivers can now flag unsupported and temporarily unavailable controls with `V4L2_CTRL_FLAG_DISABLED` and `V4L2_CTRL_FLAG_GRABBED` respectively. The `group` name indicates a possibly narrower classification than the `category`. In other words, there may be multiple groups within a category. Controls within a group would typically be drawn within a group box. Controls in different categories might have a greater separation, or may even appear in separate windows.

7. The struct v4l2\_buffer `timestamp` was changed to a 64 bit integer, containing the sampling or output time of the frame in nanoseconds. Additionally timestamps will be in absolute system time, not starting from zero at the beginning of a stream. The data type name for timestamps is stamp\_t, defined as a signed 64-bit integer. Output devices should not send a buffer out until the time in the timestamp field has arrived. I would like to follow SGI's lead, and adopt a multimedia timestamping system like their UST (Unadjusted System Time). See [http://web.archive.org/web/\*/http://reality.sgi.com](<http://web.archive.org/web/*/http://reality.sgi.com>) /cpirazzi\_engr/lg/time/intro.html. UST uses timestamps that are 64-bit signed integers (not struct timeval's) and given in nanosecond units. The UST clock starts at zero when the system is booted and runs continuously and uniformly. It takes a little over 292 years for UST to overflow. There is no way to set the UST clock. The regular Linux time-of-day clock can be changed periodically, which would cause errors if it were being used for timestamping a multimedia stream. A real UST style clock will require some support in the kernel that is not there yet. But in anticipation, I will change the timestamp field to a 64-bit integer, and I will change the v4l2\_masterclock\_gettime() function (used only by drivers) to return a 64-bit integer.

8. A `sequence` field was added to struct v4l2\_buffer. The `sequence` field counts captured frames, it is ignored by output devices. When a capture driver drops a frame, the sequence number of that frame is skipped.

<a id="rst-v4l2-version-0-20-incremental-changes"></a>

## V4L2 Version 0.20 incremental changes

1999-12-23: In struct v4l2\_vbi\_format the `reserved1` field became `offset`. Previously drivers were required to clear the `reserved1` field.

2000-01-13: The `V4L2_FMT_FLAG_NOT_INTERLACED` flag was added.

2000-07-31: The `linux/poll.h` header is now included by `videodev.h` for compatibility with the original `videodev.h` file.

2000-11-20: `V4L2_TYPE_VBI_OUTPUT` and `V4L2_PIX_FMT_Y41P` were added.

2000-11-25: `V4L2_TYPE_VBI_INPUT` was added.

2000-12-04: A couple typos in symbol names were fixed.

2001-01-18: To avoid namespace conflicts the `fourcc` macro defined in the `videodev.h` header file was renamed to `v4l2_fourcc`.

2001-01-25: A possible driver-level compatibility problem between the `videodev.h` file in Linux 2.4.0 and the `videodev.h` file included in the `videodevX` patch was fixed. Users of an earlier version of `videodevX` on Linux 2.4.0 should recompile their V4L and V4L2 drivers.

2001-01-26: A possible kernel-level incompatibility between the `videodev.h` file in the `videodevX` patch and the `videodev.h` file in Linux 2.2.x with devfs patches applied was fixed.

2001-03-02: Certain V4L ioctls which pass data in both direction although they are defined with read-only parameter, did not work correctly through the backward compatibility layer. \[Solution?\]

2001-04-13: Big endian 16-bit RGB formats were added.

2001-09-17: New YUV formats and the [VIDIOC\_G\_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) and [VIDIOC\_S\_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) ioctls were added. (The old `VIDIOC_G_FREQ` and `VIDIOC_S_FREQ` ioctls did not take multiple tuners into account.)

2000-09-18: `V4L2_BUF_TYPE_VBI` was added. This may <em>break compatibility</em> as the [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls may fail now if the struct `v4l2_fmt` `type` field does not contain `V4L2_BUF_TYPE_VBI`. In the documentation of the struct v4l2\_vbi\_format\`, the `offset` field the ambiguous phrase "rising edge" was changed to "leading edge".

<a id="rst-v4l2-version-0-20-2000-11-23"></a>

## V4L2 Version 0.20 2000-11-23

A number of changes were made to the raw VBI interface.

1. Figures clarifying the line numbering scheme were added to the V4L2 API specification. The `start`\[0\] and `start`\[1\] fields no longer count line numbers beginning at zero. Rationale: a) The previous definition was unclear. b) The `start`\[\] values are ordinal numbers. c) There is no point in inventing a new line numbering scheme. We now use line number as defined by ITU-R, period. Compatibility: Add one to the start values. Applications depending on the previous semantics may not function correctly.

2. The restriction "count\[0\] &gt; 0 and count\[1\] &gt; 0" has been relaxed to "(count\[0\] + count\[1\]) &gt; 0". Rationale: Drivers may allocate resources at scan line granularity and some data services are transmitted only on the first field. The comment that both `count` values will usually be equal is misleading and pointless and has been removed. This change <em>breaks compatibility</em> with earlier versions: Drivers may return `EINVAL`, applications may not function correctly.

3. Drivers are again permitted to return negative (unknown) start values as proposed earlier. Why this feature was dropped is unclear. This change may <em>break compatibility</em> with applications depending on the start values being positive. The use of `EBUSY` and `EINVAL` error codes with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl was clarified. The `EBUSY` error code was finally documented, and the `reserved2` field which was previously mentioned only in the `videodev.h` header file.

4. New buffer types `V4L2_TYPE_VBI_INPUT` and `V4L2_TYPE_VBI_OUTPUT` were added. The former is an alias for the old `V4L2_TYPE_VBI`, the latter was missing in the `videodev.h` file.

<a id="rst-v4l2-version-0-20-2002-07-25"></a>

## V4L2 Version 0.20 2002-07-25

Added sliced VBI interface proposal.

<a id="rst-v4l2-in-linux-2-5-46-2002-10"></a>

## V4L2 in Linux 2.5.46, 2002-10

Around October-November 2002, prior to an announced feature freeze of Linux 2.5, the API was revised, drawing from experience with V4L2 0.20. This unnamed version was finally merged into Linux 2.5.46.

1. As specified in [related](</kernel/userspace/userspace-api/media-v4l/open.md#rst-related>), drivers must make related device functions available under all minor device numbers.

2. The `open()` function requires access mode `O_RDWR` regardless of the device type. All V4L2 drivers exchanging data with applications must support the `O_NONBLOCK` flag. The `O_NOIO` flag, a V4L2 symbol which aliased the meaningless `O_TRUNC` to indicate accesses without data exchange (panel applications) was dropped. Drivers must stay in "panel mode" until the application attempts to initiate a data exchange, see [open](</kernel/userspace/userspace-api/media-v4l/open.md#rst-open>).

3. The struct v4l2\_capability changed dramatically. Note that also the size of the structure changed, which is encoded in the ioctl request code, thus older V4L2 devices will respond with an `EINVAL` error code to the new [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl.

   There are new fields to identify the driver, a new RDS device function `V4L2_CAP_RDS_CAPTURE`, the `V4L2_CAP_AUDIO` flag indicates if the device has any audio connectors, another I/O capability V4L2\_CAP\_ASYNCIO can be flagged. In response to these changes the `type` field became a bit set and was merged into the `flags` field. `V4L2_FLAG_TUNER` was renamed to `V4L2_CAP_TUNER`, `V4L2_CAP_VIDEO_OVERLAY` replaced `V4L2_FLAG_PREVIEW` and `V4L2_CAP_VBI_CAPTURE` and `V4L2_CAP_VBI_OUTPUT` replaced `V4L2_FLAG_DATA_SERVICE`. `V4L2_FLAG_READ` and `V4L2_FLAG_WRITE` were merged into `V4L2_CAP_READWRITE`.

   The redundant fields `inputs`, `outputs` and `audios` were removed. These properties can be determined as described in [video](</kernel/userspace/userspace-api/media-v4l/video.md#rst-video>) and [audio](</kernel/userspace/userspace-api/media-v4l/audio.md#rst-audio>).

   The somewhat volatile and therefore barely useful fields `maxwidth`, `maxheight`, `minwidth`, `minheight`, `maxframerate` were removed. This information is available as described in [format](</kernel/userspace/userspace-api/media-v4l/format.md#rst-format>) and [standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>).

   `V4L2_FLAG_SELECT` was removed. We believe the select() function is important enough to require support of it in all V4L2 drivers exchanging data with applications. The redundant `V4L2_FLAG_MONOCHROME` flag was removed, this information is available as described in [format](</kernel/userspace/userspace-api/media-v4l/format.md#rst-format>).

4. In struct v4l2\_input the `assoc_audio` field and the `capability` field and its only flag `V4L2_INPUT_CAP_AUDIO` was replaced by the new `audioset` field. Instead of linking one video input to one audio input this field reports all audio inputs this video input combines with.

   New fields are `tuner` (reversing the former link from tuners to video inputs), `std` and `status`.

   Accordingly struct v4l2\_output lost its `capability` and `assoc_audio` fields. `audioset`, `modulator` and `std` where added instead.

5. The struct v4l2\_audio field `audio` was renamed to `index`, for consistency with other structures. A new capability flag `V4L2_AUDCAP_STEREO` was added to indicated if the audio input in question supports stereo sound. `V4L2_AUDCAP_EFFECTS` and the corresponding `V4L2_AUDMODE` flags where removed. This can be easily implemented using controls. (However the same applies to AVL which is still there.)

   Again for consistency the struct v4l2\_audioout field `audio` was renamed to `index`.

6. The struct v4l2\_tuner `input` field was replaced by an `index` field, permitting devices with multiple tuners. The link between video inputs and tuners is now reversed, inputs point to their tuner. The `std` substructure became a simple set (more about this below) and moved into struct v4l2\_input. A `type` field was added.

   Accordingly in struct v4l2\_modulator the `output` was replaced by an `index` field.

   In struct v4l2\_frequency the `port` field was replaced by a `tuner` field containing the respective tuner or modulator index number. A tuner `type` field was added and the `reserved` field became larger for future extensions (satellite tuners in particular).

7. The idea of completely transparent video standards was dropped. Experience showed that applications must be able to work with video standards beyond presenting the user a menu. Instead of enumerating supported standards with an ioctl applications can now refer to standards by [v4l2\_std\_id](</kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id>) and symbols defined in the `videodev2.h` header file. For details see [standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>). The [VIDIOC\_G\_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std>) and [VIDIOC\_S\_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std>) now take a pointer to this type as argument. [vidioc\_querystd](</kernel/userspace/userspace-api/media-v4l/vidioc-querystd.md#rst-vidioc-querystd>) was added to autodetect the received standard, if the hardware has this capability. In struct v4l2\_standard an `index` field was added for [ioctl VIDIOC\_ENUMSTD, VIDIOC\_SUBDEV\_ENUMSTD](</kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-vidioc-enumstd>). A [v4l2\_std\_id](</kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id>) field named `id` was added as machine readable identifier, also replacing the `transmission` field. The misleading `framerate` field was renamed to `frameperiod`. The now obsolete `colorstandard` information, originally needed to distguish between variations of standards, were removed.

   Struct `v4l2_enumstd` ceased to be. [ioctl VIDIOC\_ENUMSTD, VIDIOC\_SUBDEV\_ENUMSTD](</kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-vidioc-enumstd>) now takes a pointer to a struct v4l2\_standard directly. The information which standards are supported by a particular video input or output moved into struct v4l2\_input and struct v4l2\_output fields named `std`, respectively.

8. The struct [v4l2\_queryctrl](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-v4l2-queryctrl>) fields `category` and `group` did not catch on and/or were not implemented as expected and therefore removed.

9. The [VIDIOC\_TRY\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl was added to negotiate data formats as with [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), but without the overhead of programming the hardware and regardless of I/O in progress.

   In struct v4l2\_format the `fmt` union was extended to contain struct v4l2\_window. All image format negotiations are now possible with `VIDIOC_G_FMT`, `VIDIOC_S_FMT` and `VIDIOC_TRY_FMT`; ioctl. The `VIDIOC_G_WIN` and `VIDIOC_S_WIN` ioctls to prepare for a video overlay were removed. The `type` field changed to type enum v4l2\_buf\_type and the buffer type names changed as follows.


   <table>
   <thead>
   <tr>
   <th>



   Old defines

   </th>
   <th>



   enum v4l2\_buf\_type

   </th>
   </tr>
   </thead>
   <tbody>
   <tr>
   <td>



   `V4L2_BUF_TYPE_CAPTURE`

   </td>
   <td>



   `V4L2_BUF_TYPE_VIDEO_CAPTURE`

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_BUF_TYPE_CODECIN`

   </td>
   <td>



   Omitted for now

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_BUF_TYPE_CODECOUT`

   </td>
   <td>



   Omitted for now

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_BUF_TYPE_EFFECTSIN`

   </td>
   <td>



   Omitted for now

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_BUF_TYPE_EFFECTSIN2`

   </td>
   <td>



   Omitted for now

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_BUF_TYPE_EFFECTSOUT`

   </td>
   <td>



   Omitted for now

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_BUF_TYPE_VIDEOOUT`

   </td>
   <td>



   `V4L2_BUF_TYPE_VIDEO_OUTPUT`

   </td>
   </tr>
   <tr>
   <td>



   `-`

   </td>
   <td>



   `V4L2_BUF_TYPE_VIDEO_OVERLAY`

   </td>
   </tr>
   <tr>
   <td>



   `-`

   </td>
   <td>



   `V4L2_BUF_TYPE_VBI_CAPTURE`

   </td>
   </tr>
   <tr>
   <td>



   `-`

   </td>
   <td>



   `V4L2_BUF_TYPE_VBI_OUTPUT`

   </td>
   </tr>
   <tr>
   <td>



   `-`

   </td>
   <td>



   `V4L2_BUF_TYPE_SLICED_VBI_CAPTURE`

   </td>
   </tr>
   <tr>
   <td>



   `-`

   </td>
   <td>



   `V4L2_BUF_TYPE_SLICED_VBI_OUTPUT`

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_BUF_TYPE_PRIVATE_BASE`

   </td>
   <td>



   `V4L2_BUF_TYPE_PRIVATE` (but this is deprecated)

   </td>
   </tr>
   </tbody>
   </table>

10. In struct v4l2\_fmtdesc a enum v4l2\_buf\_type field named `type` was added as in struct v4l2\_format. The `VIDIOC_ENUM_FBUFFMT` ioctl is no longer needed and was removed. These calls can be replaced by [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) with type `V4L2_BUF_TYPE_VIDEO_OVERLAY`.

11. In struct v4l2\_pix\_format the `depth` field was removed, assuming applications which recognize the format by its four-character-code already know the color depth, and others do not care about it. The same rationale lead to the removal of the `V4L2_FMT_FLAG_COMPRESSED` flag. The `V4L2_FMT_FLAG_SWCONVECOMPRESSED` flag was removed because drivers are not supposed to convert images in kernel space. A user library of conversion functions should be provided instead. The `V4L2_FMT_FLAG_BYTESPERLINE` flag was redundant. Applications can set the `bytesperline` field to zero to get a reasonable default. Since the remaining flags were replaced as well, the `flags` field itself was removed.

    The interlace flags were replaced by a enum v4l2\_field value in a newly added `field` field.


    <table>
    <thead>
    <tr>
    <th>



    Old flag

    </th>
    <th>



    enum v4l2\_field

    </th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>



    `V4L2_FMT_FLAG_NOT_INTERLACED`

    </td>
    <td>



    ?

    </td>
    </tr>
    <tr>
    <td>



    `V4L2_FMT_FLAG_INTERLACED` = `V4L2_FMT_FLAG_COMBINED`

    </td>
    <td>



    `V4L2_FIELD_INTERLACED`

    </td>
    </tr>
    <tr>
    <td>



    `V4L2_FMT_FLAG_TOPFIELD` = `V4L2_FMT_FLAG_ODDFIELD`

    </td>
    <td>



    `V4L2_FIELD_TOP`

    </td>
    </tr>
    <tr>
    <td>



    `V4L2_FMT_FLAG_BOTFIELD` = `V4L2_FMT_FLAG_EVENFIELD`

    </td>
    <td>



    `V4L2_FIELD_BOTTOM`

    </td>
    </tr>
    <tr>
    <td>



    `-`

    </td>
    <td>



    `V4L2_FIELD_SEQ_TB`

    </td>
    </tr>
    <tr>
    <td>



    `-`

    </td>
    <td>



    `V4L2_FIELD_SEQ_BT`

    </td>
    </tr>
    <tr>
    <td>



    `-`

    </td>
    <td>



    `V4L2_FIELD_ALTERNATE`

    </td>
    </tr>
    </tbody>
    </table>

    The color space flags were replaced by a enum v4l2\_colorspace value in a newly added `colorspace` field, where one of `V4L2_COLORSPACE_SMPTE170M`, `V4L2_COLORSPACE_BT878`, `V4L2_COLORSPACE_470_SYSTEM_M` or `V4L2_COLORSPACE_470_SYSTEM_BG` replaces `V4L2_FMT_CS_601YUV`.

12. In struct v4l2\_requestbuffers the `type` field was properly defined as enum v4l2\_buf\_type. Buffer types changed as mentioned above. A new `memory` field of type enum v4l2\_memory was added to distinguish between I/O methods using buffers allocated by the driver or the application. See [io](</kernel/userspace/userspace-api/media-v4l/io.md#rst-io>) for details.

13. In struct v4l2\_buffer the `type` field was properly defined as enum v4l2\_buf\_type. Buffer types changed as mentioned above. A `field` field of type enum v4l2\_field was added to indicate if a buffer contains a top or bottom field. The old field flags were removed. Since no unadjusted system time clock was added to the kernel as planned, the `timestamp` field changed back from type stamp\_t, an unsigned 64 bit integer expressing the sample time in nanoseconds, to struct timeval. With the addition of a second memory mapping method the `offset` field moved into union `m`, and a new `memory` field of type enum v4l2\_memory was added to distinguish between I/O methods. See [io](</kernel/userspace/userspace-api/media-v4l/io.md#rst-io>) for details.

    The `V4L2_BUF_REQ_CONTIG` flag was used by the V4L compatibility layer, after changes to this code it was no longer needed. The `V4L2_BUF_ATTR_DEVICEMEM` flag would indicate if the buffer was indeed allocated in device memory rather than DMA-able system memory. It was barely useful and so was removed.

14. In struct v4l2\_framebuffer the `base[3]` array anticipating double- and triple-buffering in off-screen video memory, however without defining a synchronization mechanism, was replaced by a single pointer. The `V4L2_FBUF_CAP_SCALEUP` and `V4L2_FBUF_CAP_SCALEDOWN` flags were removed. Applications can determine this capability more accurately using the new cropping and scaling interface. The `V4L2_FBUF_CAP_CLIPPING` flag was replaced by `V4L2_FBUF_CAP_LIST_CLIPPING` and `V4L2_FBUF_CAP_BITMAP_CLIPPING`.

15. In struct v4l2\_clip the `x`, `y`, `width` and `height` field moved into a `c` substructure of type struct v4l2\_rect. The `x` and `y` fields were renamed to `left` and `top`, i. e. offsets to a context dependent origin.

16. In struct v4l2\_window the `x`, `y`, `width` and `height` field moved into a `w` substructure as above. A `field` field of type enum v4l2\_field was added to distinguish between field and frame (interlaced) overlay.

17. The digital zoom interface, including struct `v4l2_zoomcap`, struct `v4l2_zoom`, `V4L2_ZOOM_NONCAP` and `V4L2_ZOOM_WHILESTREAMING` was replaced by a new cropping and scaling interface. The previously unused struct v4l2\_cropcap and struct v4l2\_crop where redefined for this purpose. See [crop](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>) for details.

18. In struct v4l2\_vbi\_format the `SAMPLE_FORMAT` field now contains a four-character-code as used to identify video image formats and `V4L2_PIX_FMT_GREY` replaces the `V4L2_VBI_SF_UBYTE` define. The `reserved` field was extended.

19. In struct v4l2\_captureparm the type of the `timeperframe` field changed from unsigned long to struct v4l2\_fract. This allows the accurate expression of multiples of the NTSC-M frame rate 30000 / 1001. A new field `readbuffers` was added to control the driver behaviour in read I/O mode.

    Similar changes were made to struct v4l2\_outputparm.

20. The struct `v4l2_performance` and `VIDIOC_G_PERF` ioctl were dropped. Except when using the [read/write I/O method](</kernel/userspace/userspace-api/media-v4l/rw.md#rst-rw>), which is limited anyway, this information is already available to applications.

21. The example transformation from RGB to YCbCr color space in the old V4L2 documentation was inaccurate, this has been corrected in [pixfmt](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>).

<a id="rst-v4l2-2003-06-19"></a>

## V4L2 2003-06-19

1. A new capability flag `V4L2_CAP_RADIO` was added for radio devices. Prior to this change radio devices would identify solely by having exactly one tuner whose type field reads `V4L2_TUNER_RADIO`.

2. An optional driver access priority mechanism was added, see [app-pri](</kernel/userspace/userspace-api/media-v4l/app-pri.md#rst-app-pri>) for details.

3. The audio input and output interface was found to be incomplete.

   Previously the [VIDIOC\_G\_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) ioctl would enumerate the available audio inputs. An ioctl to determine the current audio input, if more than one combines with the current video input, did not exist. So `VIDIOC_G_AUDIO` was renamed to `VIDIOC_G_AUDIO_OLD`, this ioctl was removed on Kernel 2.6.39. The [vidioc\_enumaudio](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudio.md#rst-vidioc-enumaudio>) ioctl was added to enumerate audio inputs, while [VIDIOC\_G\_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) now reports the current audio input.

   The same changes were made to [VIDIOC\_G\_AUDOUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audioout.md#rst-vidioc-g-audout>) and [VIDIOC\_ENUMAUDOUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudioout.md#rst-vidioc-enumaudout>).

   Until further the "videodev" module will automatically translate between the old and new ioctls, but drivers and applications must be updated to successfully compile again.

4. The [vidioc\_overlay](</kernel/userspace/userspace-api/media-v4l/vidioc-overlay.md#rst-vidioc-overlay>) ioctl was incorrectly defined with write-read parameter. It was changed to write-only, while the write-read version was renamed to `VIDIOC_OVERLAY_OLD`. The old ioctl was removed on Kernel 2.6.39. Until further the "videodev" kernel module will automatically translate to the new version, so drivers must be recompiled, but not applications.

5. [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) incorrectly stated that clipping rectangles define regions where the video can be seen. Correct is that clipping rectangles define regions where <em>no</em> video shall be displayed and so the graphics surface can be seen.

6. The [VIDIOC\_S\_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm>) and [VIDIOC\_S\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) ioctls were defined with write-only parameter, inconsistent with other ioctls modifying their argument. They were changed to write-read, while a `_OLD` suffix was added to the write-only versions. The old ioctls were removed on Kernel 2.6.39. Drivers and applications assuming a constant parameter need an update.

<a id="rst-v4l2-2003-11-05"></a>

## V4L2 2003-11-05

1. In [RGB Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>) the following pixel formats were incorrectly transferred from Bill Dirks' V4L2 specification. Descriptions below refer to bytes in memory, in ascending address order.


   <table>
   <thead>
   <tr>
   <th>



   Symbol

   </th>
   <th>



   In this document prior to revision 0.5

   </th>
   <th>



   Corrected

   </th>
   </tr>
   </thead>
   <tbody>
   <tr>
   <td>



   `V4L2_PIX_FMT_RGB24`

   </td>
   <td>



   B, G, R

   </td>
   <td>



   R, G, B

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_PIX_FMT_BGR24`

   </td>
   <td>



   R, G, B

   </td>
   <td>



   B, G, R

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_PIX_FMT_RGB32`

   </td>
   <td>



   B, G, R, X

   </td>
   <td>



   R, G, B, X

   </td>
   </tr>
   <tr>
   <td>



   `V4L2_PIX_FMT_BGR32`

   </td>
   <td>



   R, G, B, X

   </td>
   <td>



   B, G, R, X

   </td>
   </tr>
   </tbody>
   </table>

   The `V4L2_PIX_FMT_BGR24` example was always correct.

   In [Image Properties](</kernel/userspace/userspace-api/media-v4l/diff-v4l.md#rst-v4l-image-properties>) the mapping of the V4L `VIDEO_PALETTE_RGB24` and `VIDEO_PALETTE_RGB32` formats to V4L2 pixel formats was accordingly corrected.

2. Unrelated to the fixes above, drivers may still interpret some V4L2 RGB pixel formats differently. These issues have yet to be addressed, for details see [RGB Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>).

<a id="rst-v4l2-in-linux-2-6-6-2004-05-09"></a>

## V4L2 in Linux 2.6.6, 2004-05-09

1. The [vidioc\_cropcap](</kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#rst-vidioc-cropcap>) ioctl was incorrectly defined with read-only parameter. It is now defined as write-read ioctl, while the read-only version was renamed to `VIDIOC_CROPCAP_OLD`. The old ioctl was removed on Kernel 2.6.39.

<a id="rst-v4l2-in-linux-2-6-8"></a>

## V4L2 in Linux 2.6.8

1. A new field `input` (former `reserved[0]`) was added to the struct v4l2\_buffer. Purpose of this field is to alternate between video inputs (e. g. cameras) in step with the video capturing process. This function must be enabled with the new `V4L2_BUF_FLAG_INPUT` flag. The `flags` field is no longer read-only.

<a id="rst-v4l2-spec-erratum-2004-08-01"></a>

## V4L2 spec erratum 2004-08-01

1. The return value of the [func-open](</kernel/userspace/userspace-api/media-v4l/func-open.md#rst-func-open>) function was incorrectly documented.

2. Audio output ioctls end in -AUDOUT, not -AUDIOOUT.

3. In the Current Audio Input example the `VIDIOC_G_AUDIO` ioctl took the wrong argument.

4. The documentation of the [vidioc\_qbuf](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) and [VIDIOC\_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctls did not mention the struct v4l2\_buffer `memory` field. It was also missing from examples. Also on the `VIDIOC_DQBUF` page the `EIO` error code was not documented.

<a id="rst-v4l2-in-linux-2-6-14"></a>

## V4L2 in Linux 2.6.14

1. A new sliced VBI interface was added. It is documented in [Sliced VBI Data Interface](</kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-sliced>) and replaces the interface first proposed in V4L2 specification 0.8.

<a id="rst-v4l2-in-linux-2-6-15"></a>

## V4L2 in Linux 2.6.15

1. The [vidioc\_log\_status](</kernel/userspace/userspace-api/media-v4l/vidioc-log-status.md#rst-vidioc-log-status>) ioctl was added.

2. New video standards `V4L2_STD_NTSC_443`, `V4L2_STD_SECAM_LC`, `V4L2_STD_SECAM_DK` (a set of SECAM D, K and K1), and `V4L2_STD_ATSC` (a set of `V4L2_STD_ATSC_8_VSB` and `V4L2_STD_ATSC_16_VSB`) were defined. Note the `V4L2_STD_525_60` set now includes `V4L2_STD_NTSC_443`. See also [v4l2-std-id](</kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id>).

3. The `VIDIOC_G_COMP` and `VIDIOC_S_COMP` ioctl were renamed to `VIDIOC_G_MPEGCOMP` and `VIDIOC_S_MPEGCOMP` respectively. Their argument was replaced by a struct `v4l2_mpeg_compression` pointer. (The `VIDIOC_G_MPEGCOMP` and `VIDIOC_S_MPEGCOMP` ioctls where removed in Linux 2.6.25.)

<a id="rst-v4l2-spec-erratum-2005-11-27"></a>

## V4L2 spec erratum 2005-11-27

The capture example in [capture-example](</kernel/userspace/userspace-api/media-v4l/capture-example.md#rst-capture-example>) called the [VIDIOC\_S\_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop>) ioctl without checking if cropping is supported. In the video standard selection example in [standard](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>) the [VIDIOC\_S\_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std>) call used the wrong argument type.

<a id="rst-v4l2-spec-erratum-2006-01-10"></a>

## V4L2 spec erratum 2006-01-10

1. The `V4L2_IN_ST_COLOR_KILL` flag in struct v4l2\_input not only indicates if the color killer is enabled, but also if it is active. (The color killer disables color decoding when it detects no color in the video signal to improve the image quality.)

2. [VIDIOC\_S\_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm>) is a write-read ioctl, not write-only as stated on its reference page. The ioctl changed in 2003 as noted above.

<a id="rst-v4l2-spec-erratum-2006-02-03"></a>

## V4L2 spec erratum 2006-02-03

1. In struct v4l2\_captureparm and struct v4l2\_outputparm the `timeperframe` field gives the time in seconds, not microseconds.

<a id="rst-v4l2-spec-erratum-2006-02-04"></a>

## V4L2 spec erratum 2006-02-04

1. The `clips` field in struct v4l2\_window must point to an array of struct v4l2\_clip, not a linked list, because drivers ignore the struct v4l2\_clip. `next` pointer.

<a id="rst-v4l2-in-linux-2-6-17"></a>

## V4L2 in Linux 2.6.17

1. New video standard macros were added: `V4L2_STD_NTSC_M_KR` (NTSC M South Korea), and the sets `V4L2_STD_MN`, `V4L2_STD_B`, `V4L2_STD_GH` and `V4L2_STD_DK`. The `V4L2_STD_NTSC` and `V4L2_STD_SECAM` sets now include `V4L2_STD_NTSC_M_KR` and `V4L2_STD_SECAM_LC` respectively.

2. A new `V4L2_TUNER_MODE_LANG1_LANG2` was defined to record both languages of a bilingual program. The use of `V4L2_TUNER_MODE_STEREO` for this purpose is deprecated now. See the [VIDIOC\_G\_TUNER](</kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-vidioc-g-tuner>) section for details.

<a id="rst-v4l2-spec-erratum-2006-09-23-draft-0-15"></a>

## V4L2 spec erratum 2006-09-23 (Draft 0.15)

1. In various places `V4L2_BUF_TYPE_SLICED_VBI_CAPTURE` and `V4L2_BUF_TYPE_SLICED_VBI_OUTPUT` of the sliced VBI interface were not mentioned along with other buffer types.

2. In [VIDIOC\_G\_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) it was clarified that the struct v4l2\_audio `mode` field is a flags field.

3. [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) did not mention the sliced VBI and radio capability flags.

4. In [VIDIOC\_G\_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) it was clarified that applications must initialize the tuner `type` field of struct v4l2\_frequency before calling [VIDIOC\_S\_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>).

5. The `reserved` array in struct v4l2\_requestbuffers has 2 elements, not 32.

6. In [output](</kernel/userspace/userspace-api/media-v4l/dev-output.md#rst-output>) and [raw-vbi](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>) the device file names `/dev/vout` which never caught on were replaced by `/dev/video`.

7. With Linux 2.6.15 the possible range for VBI device minor numbers was extended from 224-239 to 224-255. Accordingly device file names `/dev/vbi0` to `/dev/vbi31` are possible now.

<a id="rst-v4l2-in-linux-2-6-18"></a>

## V4L2 in Linux 2.6.18

1. New ioctls [VIDIOC\_G\_EXT\_CTRLS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-vidioc-g-ext-ctrls>), [VIDIOC\_S\_EXT\_CTRLS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-vidioc-g-ext-ctrls>) and [VIDIOC\_TRY\_EXT\_CTRLS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-vidioc-g-ext-ctrls>) were added, a flag to skip unsupported controls with [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>), new control types `V4L2_CTRL_TYPE_INTEGER64` and `V4L2_CTRL_TYPE_CTRL_CLASS` (enum v4l2\_ctrl\_type), and new control flags `V4L2_CTRL_FLAG_READ_ONLY`, `V4L2_CTRL_FLAG_UPDATE`, `V4L2_CTRL_FLAG_INACTIVE` and `V4L2_CTRL_FLAG_SLIDER` ([control-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags>)). See [extended-controls](</kernel/userspace/userspace-api/media-v4l/extended-controls.md#rst-extended-controls>) for details.

<a id="rst-v4l2-in-linux-2-6-19"></a>

## V4L2 in Linux 2.6.19

1. In struct v4l2\_sliced\_vbi\_cap a buffer type field was added replacing a reserved field. Note on architectures where the size of enum types differs from int types the size of the structure changed. The [VIDIOC\_G\_SLICED\_VBI\_CAP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vidioc-g-sliced-vbi-cap>) ioctl was redefined from being read-only to write-read. Applications must initialize the type field and clear the reserved fields now. These changes may <em>break the compatibility</em> with older drivers and applications.

2. The ioctls [vidioc\_enum\_framesizes](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#rst-vidioc-enum-framesizes>) and [vidioc\_enum\_frameintervals](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#rst-vidioc-enum-frameintervals>) were added.

3. A new pixel format `V4L2_PIX_FMT_RGB444` ([RGB Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-pixfmt-rgb>)) was added.

<a id="rst-v4l2-spec-erratum-2006-10-12-draft-0-17"></a>

## V4L2 spec erratum 2006-10-12 (Draft 0.17)

1. `V4L2_PIX_FMT_HM12` ([reserved-formats](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-reserved-formats>)) is a YUV 4:2:0, not 4:2:2 format.

<a id="rst-v4l2-in-linux-2-6-21"></a>

## V4L2 in Linux 2.6.21

1. The `videodev2.h` header file is now dual licensed under GNU General Public License version two or later, and under a 3-clause BSD-style license.

<a id="rst-v4l2-in-linux-2-6-22"></a>

## V4L2 in Linux 2.6.22

1. Two new field orders `V4L2_FIELD_INTERLACED_TB` and `V4L2_FIELD_INTERLACED_BT` were added. See enum v4l2\_field for details.

2. Three new clipping/blending methods with a global or straight or inverted local alpha value were added to the video overlay interface. See the description of the [VIDIOC\_G\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) and [VIDIOC\_S\_FBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf>) ioctls for details.

   A new `global_alpha` field was added to struct v4l2\_window, extending the structure. This may <strong>break compatibility</strong> with applications using a struct v4l2\_window directly. However the [VIDIOC\_G/S/TRY\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls, which take a pointer to a struct v4l2\_format parent structure with padding bytes at the end, are not affected.

3. The format of the `chromakey` field in struct v4l2\_window changed from "host order RGB32" to a pixel value in the same format as the framebuffer. This may <strong>break compatibility</strong> with existing applications. Drivers supporting the "host order RGB32" format are not known.

<a id="rst-v4l2-in-linux-2-6-24"></a>

## V4L2 in Linux 2.6.24

1. The pixel formats `V4L2_PIX_FMT_PAL8`, `V4L2_PIX_FMT_YUV444`, `V4L2_PIX_FMT_YUV555`, `V4L2_PIX_FMT_YUV565` and `V4L2_PIX_FMT_YUV32` were added.

<a id="rst-v4l2-in-linux-2-6-25"></a>

## V4L2 in Linux 2.6.25

1. The pixel formats [V4L2\_PIX\_FMT\_Y16](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y16>) and [V4L2\_PIX\_FMT\_SBGGR16](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb16.md#rst-v4l2-pix-fmt-sbggr16>) were added.

2. New [controls](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>) `V4L2_CID_POWER_LINE_FREQUENCY`, `V4L2_CID_HUE_AUTO`, `V4L2_CID_WHITE_BALANCE_TEMPERATURE`, `V4L2_CID_SHARPNESS` and `V4L2_CID_BACKLIGHT_COMPENSATION` were added. The controls `V4L2_CID_BLACK_LEVEL`, `V4L2_CID_WHITENESS`, `V4L2_CID_HCENTER` and `V4L2_CID_VCENTER` were deprecated.

3. A [Camera controls class](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-camera.md#rst-camera-controls>) was added, with the new controls `V4L2_CID_EXPOSURE_AUTO`, `V4L2_CID_EXPOSURE_ABSOLUTE`, `V4L2_CID_EXPOSURE_AUTO_PRIORITY`, `V4L2_CID_PAN_RELATIVE`, `V4L2_CID_TILT_RELATIVE`, `V4L2_CID_PAN_RESET`, `V4L2_CID_TILT_RESET`, `V4L2_CID_PAN_ABSOLUTE`, `V4L2_CID_TILT_ABSOLUTE`, `V4L2_CID_FOCUS_ABSOLUTE`, `V4L2_CID_FOCUS_RELATIVE` and `V4L2_CID_FOCUS_AUTO`.

4. The `VIDIOC_G_MPEGCOMP` and `VIDIOC_S_MPEGCOMP` ioctls, which were superseded by the [extended controls](</kernel/userspace/userspace-api/media-v4l/extended-controls.md#rst-extended-controls>) interface in Linux 2.6.18, where finally removed from the `videodev2.h` header file.

<a id="rst-v4l2-in-linux-2-6-26"></a>

## V4L2 in Linux 2.6.26

1. The pixel formats `V4L2_PIX_FMT_Y16` and `V4L2_PIX_FMT_SBGGR16` were added.

2. Added user controls `V4L2_CID_CHROMA_AGC` and `V4L2_CID_COLOR_KILLER`.

<a id="rst-v4l2-in-linux-2-6-27"></a>

## V4L2 in Linux 2.6.27

1. The [vidioc\_s\_hw\_freq\_seek](</kernel/userspace/userspace-api/media-v4l/vidioc-s-hw-freq-seek.md#rst-vidioc-s-hw-freq-seek>) ioctl and the `V4L2_CAP_HW_FREQ_SEEK` capability were added.

2. The pixel formats `V4L2_PIX_FMT_YVYU`, `V4L2_PIX_FMT_PCA501`, `V4L2_PIX_FMT_PCA505`, `V4L2_PIX_FMT_PCA508`, `V4L2_PIX_FMT_PCA561`, `V4L2_PIX_FMT_SGBRG8`, `V4L2_PIX_FMT_PAC207` and `V4L2_PIX_FMT_PJPG` were added.

<a id="rst-v4l2-in-linux-2-6-28"></a>

## V4L2 in Linux 2.6.28

1. Added `V4L2_MPEG_AUDIO_ENCODING_AAC` and `V4L2_MPEG_AUDIO_ENCODING_AC3` MPEG audio encodings.

2. Added `V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC` MPEG video encoding.

3. The pixel formats `V4L2_PIX_FMT_SGRBG10` and `V4L2_PIX_FMT_SGRBG10DPCM8` were added.

<a id="rst-v4l2-in-linux-2-6-29"></a>

## V4L2 in Linux 2.6.29

1. The `VIDIOC_G_CHIP_IDENT` ioctl was renamed to `VIDIOC_G_CHIP_IDENT_OLD` and `VIDIOC_DBG_G_CHIP_IDENT` was introduced in its place. The old struct `v4l2_chip_ident` was renamed to struct `v4l2_chip_ident_old`.

2. The pixel formats `V4L2_PIX_FMT_VYUY`, `V4L2_PIX_FMT_NV16` and `V4L2_PIX_FMT_NV61` were added.

3. Added camera controls `V4L2_CID_ZOOM_ABSOLUTE`, `V4L2_CID_ZOOM_RELATIVE`, `V4L2_CID_ZOOM_CONTINUOUS` and `V4L2_CID_PRIVACY`.

<a id="rst-v4l2-in-linux-2-6-30"></a>

## V4L2 in Linux 2.6.30

1. New control flag `V4L2_CTRL_FLAG_WRITE_ONLY` was added.

2. New control `V4L2_CID_COLORFX` was added.

<a id="rst-v4l2-in-linux-2-6-32"></a>

## V4L2 in Linux 2.6.32

1. In order to be easier to compare a V4L2 API and a kernel version, now V4L2 API is numbered using the Linux Kernel version numeration.

2. Finalized the RDS capture API. See [rds](</kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-rds>) for more information.

3. Added new capabilities for modulators and RDS encoders.

4. Add description for libv4l API.

5. Added support for string controls via new type `V4L2_CTRL_TYPE_STRING`.

6. Added `V4L2_CID_BAND_STOP_FILTER` documentation.

7. Added FM Modulator (FM TX) Extended Control Class: `V4L2_CTRL_CLASS_FM_TX` and their Control IDs.

8. Added FM Receiver (FM RX) Extended Control Class: `V4L2_CTRL_CLASS_FM_RX` and their Control IDs.

9. Added Remote Controller chapter, describing the default Remote Controller mapping for media devices.

<a id="rst-v4l2-in-linux-2-6-33"></a>

## V4L2 in Linux 2.6.33

1. Added support for Digital Video timings in order to support HDTV receivers and transmitters.

<a id="rst-v4l2-in-linux-2-6-34"></a>

## V4L2 in Linux 2.6.34

1. Added `V4L2_CID_IRIS_ABSOLUTE` and `V4L2_CID_IRIS_RELATIVE` controls to the [Camera controls class](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-camera.md#rst-camera-controls>).

<a id="rst-v4l2-in-linux-2-6-37"></a>

## V4L2 in Linux 2.6.37

1. Remove the vtx (videotext/teletext) API. This API was no longer used and no hardware exists to verify the API. Nor were any userspace applications found that used it. It was originally scheduled for removal in 2.6.35.

<a id="rst-v4l2-in-linux-2-6-39"></a>

## V4L2 in Linux 2.6.39

1. The old VIDIOC\_\*\_OLD symbols and V4L1 support were removed.

2. Multi-planar API added. Does not affect the compatibility of current drivers and applications. See [multi-planar API](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>) for details.

<a id="rst-v4l2-in-linux-3-1"></a>

## V4L2 in Linux 3.1

1. VIDIOC\_QUERYCAP now returns a per-subsystem version instead of a per-driver one.

   Standardize an error code for invalid ioctl.

   Added V4L2\_CTRL\_TYPE\_BITMASK.

<a id="rst-v4l2-in-linux-3-2"></a>

## V4L2 in Linux 3.2

1. V4L2\_CTRL\_FLAG\_VOLATILE was added to signal volatile controls to userspace.

2. Add selection API for extended control over cropping and composing. Does not affect the compatibility of current drivers and applications. See [selection API](</kernel/userspace/userspace-api/media-v4l/selection-api.md#rst-selection-api>) for details.

<a id="rst-v4l2-in-linux-3-3"></a>

## V4L2 in Linux 3.3

1. Added `V4L2_CID_ALPHA_COMPONENT` control to the [User controls class](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>).

2. Added the device\_caps field to struct v4l2\_capabilities and added the new V4L2\_CAP\_DEVICE\_CAPS capability.

<a id="rst-v4l2-in-linux-3-4"></a>

## V4L2 in Linux 3.4

1. Added [JPEG compression control class](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-jpeg.md#rst-jpeg-controls>).

2. Extended the DV Timings API: [vidioc\_enum\_dv\_timings](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-dv-timings.md#rst-vidioc-enum-dv-timings>), [vidioc\_query\_dv\_timings](</kernel/userspace/userspace-api/media-v4l/vidioc-query-dv-timings.md#rst-vidioc-query-dv-timings>) and [vidioc\_dv\_timings\_cap](</kernel/userspace/userspace-api/media-v4l/vidioc-dv-timings-cap.md#rst-vidioc-dv-timings-cap>).

<a id="rst-v4l2-in-linux-3-5"></a>

## V4L2 in Linux 3.5

1. Added integer menus, the new type will be V4L2\_CTRL\_TYPE\_INTEGER\_MENU.

2. Added selection API for V4L2 subdev interface: [vidioc\_subdev\_g\_selection](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-selection.md#rst-vidioc-subdev-g-selection>) and [VIDIOC\_SUBDEV\_S\_SELECTION](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-selection.md#rst-vidioc-subdev-g-selection>).

3. Added `V4L2_COLORFX_ANTIQUE`, `V4L2_COLORFX_ART_FREEZE`, `V4L2_COLORFX_AQUA`, `V4L2_COLORFX_SILHOUETTE`, `V4L2_COLORFX_SOLARIZATION`, `V4L2_COLORFX_VIVID` and `V4L2_COLORFX_ARBITRARY_CBCR` menu items to the `V4L2_CID_COLORFX` control.

4. Added `V4L2_CID_COLORFX_CBCR` control.

5. Added camera controls `V4L2_CID_AUTO_EXPOSURE_BIAS`, `V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE`, `V4L2_CID_IMAGE_STABILIZATION`, `V4L2_CID_ISO_SENSITIVITY`, `V4L2_CID_ISO_SENSITIVITY_AUTO`, `V4L2_CID_EXPOSURE_METERING`, `V4L2_CID_SCENE_MODE`, `V4L2_CID_3A_LOCK`, `V4L2_CID_AUTO_FOCUS_START`, `V4L2_CID_AUTO_FOCUS_STOP`, `V4L2_CID_AUTO_FOCUS_STATUS` and `V4L2_CID_AUTO_FOCUS_RANGE`.

<a id="rst-v4l2-in-linux-3-6"></a>

## V4L2 in Linux 3.6

1. Replaced `input` in struct v4l2\_buffer by `reserved2` and removed `V4L2_BUF_FLAG_INPUT`.

2. Added V4L2\_CAP\_VIDEO\_M2M and V4L2\_CAP\_VIDEO\_M2M\_MPLANE capabilities.

3. Added support for frequency band enumerations: [vidioc\_enum\_freq\_bands](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#rst-vidioc-enum-freq-bands>).

<a id="rst-v4l2-in-linux-3-9"></a>

## V4L2 in Linux 3.9

1. Added timestamp types to `flags` field in struct v4l2\_buffer. See [Buffer Flags](</kernel/userspace/userspace-api/media-v4l/buffer.md#rst-buffer-flags>).

2. Added `V4L2_EVENT_CTRL_CH_RANGE` control event changes flag. See [ctrl-changes-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-ctrl-changes-flags>).

<a id="rst-v4l2-in-linux-3-10"></a>

## V4L2 in Linux 3.10

1. Removed obsolete and unused DV\_PRESET ioctls VIDIOC\_G\_DV\_PRESET, VIDIOC\_S\_DV\_PRESET, VIDIOC\_QUERY\_DV\_PRESET and VIDIOC\_ENUM\_DV\_PRESET. Remove the related v4l2\_input/output capability flags V4L2\_IN\_CAP\_PRESETS and V4L2\_OUT\_CAP\_PRESETS.

2. Added new debugging ioctl [vidioc\_dbg\_g\_chip\_info](</kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-chip-info.md#rst-vidioc-dbg-g-chip-info>).

<a id="rst-v4l2-in-linux-3-11"></a>

## V4L2 in Linux 3.11

1. Remove obsolete `VIDIOC_DBG_G_CHIP_IDENT` ioctl.

<a id="rst-v4l2-in-linux-3-14"></a>

## V4L2 in Linux 3.14

1. In struct v4l2\_rect, the type of `width` and `height` fields changed from \_s32 to \_u32.

<a id="rst-v4l2-in-linux-3-15"></a>

## V4L2 in Linux 3.15

1. Added Software Defined Radio (SDR) Interface.

<a id="rst-v4l2-in-linux-3-16"></a>

## V4L2 in Linux 3.16

1. Added event V4L2\_EVENT\_SOURCE\_CHANGE.

<a id="rst-v4l2-in-linux-3-17"></a>

## V4L2 in Linux 3.17

1. Extended struct v4l2\_pix\_format. Added format flags.

2. Added compound control types and [VIDIOC\_QUERY\_EXT\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>).

<a id="rst-v4l2-in-linux-3-18"></a>

## V4L2 in Linux 3.18

1. Added `V4L2_CID_PAN_SPEED` and `V4L2_CID_TILT_SPEED` camera controls.

<a id="rst-v4l2-in-linux-3-19"></a>

## V4L2 in Linux 3.19

1. Rewrote Colorspace chapter, added new enum v4l2\_ycbcr\_encoding and enum v4l2\_quantization fields to struct v4l2\_pix\_format, struct v4l2\_pix\_format\_mplane and struct v4l2\_mbus\_framefmt.

<a id="rst-v4l2-in-linux-4-4"></a>

## V4L2 in Linux 4.4

1. Renamed `V4L2_TUNER_ADC` to `V4L2_TUNER_SDR`. The use of `V4L2_TUNER_ADC` is deprecated now.

2. Added `V4L2_CID_RF_TUNER_RF_GAIN` RF Tuner control.

3. Added transmitter support for Software Defined Radio (SDR) Interface.

<a id="rst-relation-of-v4l2-to-other-linux-multimedia-apis"></a>
<a id="rst-other"></a>

## Relation of V4L2 to other Linux multimedia APIs

<a id="rst-x-video-extension"></a>
<a id="rst-xvideo"></a>

### X Video Extension

The X Video Extension (abbreviated XVideo or just Xv) is an extension of the X Window system, implemented for example by the XFree86 project. Its scope is similar to V4L2, an API to video capture and output devices for X clients. Xv allows applications to display live video in a window, send window contents to a TV output, and capture or output still images in XPixmaps <a id="rst-footnote-reference-1"></a>[1](#rst-f1). With their implementation XFree86 makes the extension available across many operating systems and architectures.

Because the driver is embedded into the X server Xv has a number of advantages over the V4L2 [video overlay interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>). The driver can easily determine the overlay target, i. e. visible graphics memory or off-screen buffers for a destructive overlay. It can program the RAMDAC for a non-destructive overlay, scaling or color-keying, or the clipping functions of the video capture hardware, always in sync with drawing operations or windows moving or changing their stacking order.

To combine the advantages of Xv and V4L a special Xv driver exists in XFree86 and XOrg, just programming any overlay capable Video4Linux device it finds. To enable it `/etc/X11/XF86Config` must contain these lines:



```text
Section "Module"
    Load "v4l"
EndSection
```

As of XFree86 4.2 this driver still supports only V4L ioctls, however it should work just fine with all V4L2 devices through the V4L2 backward-compatibility layer. Since V4L2 permits multiple opens it is possible (if supported by the V4L2 driver) to capture video while an X client requested video overlay. Restrictions of simultaneous capturing and overlay are discussed in [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) apply.

Only marginally related to V4L2, XFree86 extended Xv to support hardware YUV to RGB conversion and scaling for faster video playback, and added an interface to MPEG-2 decoding hardware. This API is useful to display images captured with V4L2 devices.

<a id="rst-digital-video"></a>

### Digital Video

V4L2 does not support digital terrestrial, cable or satellite broadcast. A separate project aiming at digital receivers exists. You can find its homepage at [https://linuxtv.org](<https://linuxtv.org>). The Linux DVB API has no connection to the V4L2 API except that drivers for hybrid hardware may support both.

<a id="rst-audio-interfaces"></a>

### Audio Interfaces

\[to do - OSS/ALSA\]

<a id="rst-experimental-api-elements"></a>
<a id="rst-experimental"></a>

## Experimental API Elements

The following V4L2 API elements are currently experimental and may change in the future.

- [vidioc\_dbg\_g\_register](</kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register>) and [VIDIOC\_DBG\_S\_REGISTER](</kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register>) ioctls.

- [vidioc\_dbg\_g\_chip\_info](</kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-chip-info.md#rst-vidioc-dbg-g-chip-info>) ioctl.

<a id="rst-obsolete-api-elements"></a>
<a id="rst-obsolete"></a>

## Obsolete API Elements

The following V4L2 API elements were superseded by new interfaces and should not be implemented in new drivers.

- `VIDIOC_G_MPEGCOMP` and `VIDIOC_S_MPEGCOMP` ioctls. Use Extended Controls, [extended-controls](</kernel/userspace/userspace-api/media-v4l/extended-controls.md#rst-extended-controls>).

- VIDIOC\_G\_DV\_PRESET, VIDIOC\_S\_DV\_PRESET, VIDIOC\_ENUM\_DV\_PRESETS and VIDIOC\_QUERY\_DV\_PRESET ioctls. Use the DV Timings API ([dv-timings](</kernel/userspace/userspace-api/media-v4l/dv-timings.md#rst-dv-timings>)).

- `VIDIOC_SUBDEV_G_CROP` and `VIDIOC_SUBDEV_S_CROP` ioctls. Use `VIDIOC_SUBDEV_G_SELECTION` and `VIDIOC_SUBDEV_S_SELECTION`, [vidioc\_subdev\_g\_selection](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-selection.md#rst-vidioc-subdev-g-selection>).

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



**[1]** This is not implemented in XFree86.

---

# HSV Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These formats store the color information of the image in a geometrical representation. The colors are mapped into a cylinder, where the angle is the HUE, the height is the VALUE and the distance to the center is the SATURATION. This is a…

<a id="rst-hsv-formats-1"></a>
<a id="rst-hsv-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

These formats store the color information of the image in a geometrical representation. The colors are mapped into a cylinder, where the angle is the HUE, the height is the VALUE and the distance to the center is the SATURATION. This is a very useful format for image segmentation algorithms.

- [pixfmt-packed-hsv](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-packed-hsv.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

---

# Input/Output

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The V4L2 API defines several different methods to read from or write to a device. All drivers exchanging data with applications must support at least one of them.

<a id="rst-input-output"></a>
<a id="rst-io"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The V4L2 API defines several different methods to read from or write to a device. All drivers exchanging data with applications must support at least one of them.

The classic I/O method using the `read()` and `write()` function is automatically selected after opening a V4L2 device. When the driver does not support this method attempts to read or write will fail at any time.

Other methods must be negotiated. To select the streaming I/O method with memory mapped or user buffers applications call the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl.

Video overlay can be considered another I/O method, although the application does not directly receive the image data. It is selected by initiating video overlay with the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. For more information see [Video Overlay Interface](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

Generally exactly one I/O method, including overlay, is associated with each file descriptor. The only exceptions are applications not exchanging data with a driver ("panel applications", see [Opening and Closing Devices](</kernel/userspace/userspace-api/media-v4l/open.md#rst-open>)) and drivers permitting simultaneous video capturing and overlay using the same file descriptor, for compatibility with V4L and earlier versions of V4L2.

[VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) and [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) would permit this to some degree, but for simplicity drivers need not support switching the I/O method (after first switching away from read/write) other than by closing and reopening the device.

The following sections describe the various I/O methods in more detail.

- [Read/Write](</kernel/userspace/userspace-api/media-v4l/rw.md>)
- [Streaming I/O (Memory Mapping)](</kernel/userspace/userspace-api/media-v4l/mmap.md>)
- [Streaming I/O (User Pointers)](</kernel/userspace/userspace-api/media-v4l/userp.md>)
- [Streaming I/O (DMA buffer importing)](</kernel/userspace/userspace-api/media-v4l/dmabuf.md>)
- [buffer](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/buffer.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Field Order](</kernel/userspace/userspace-api/media-v4l/field-order.md>)

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> libv4l is a collection of libraries which adds a thin abstraction layer on top of video4linux2 devices. The purpose of this (thin) layer is to make it easy for application writers to support a wide variety of devices without having to…

<a id="rst-introduction"></a>
<a id="rst-libv4l-introduction"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

libv4l is a collection of libraries which adds a thin abstraction layer on top of video4linux2 devices. The purpose of this (thin) layer is to make it easy for application writers to support a wide variety of devices without having to write separate code for different devices in the same class.

An example of using libv4l is provided by [v4l2grab](</kernel/userspace/userspace-api/media-v4l/v4l2grab-example.md#rst-v4l2grab-example>).

libv4l consists of 3 different libraries:

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

## libv4lconvert

libv4lconvert is a library that converts several different pixelformats found in V4L2 drivers into a few common RGB and YUY formats.

It currently accepts the following V4L2 driver formats: [V4L2\_PIX\_FMT\_BGR24](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgr24>), [V4L2\_PIX\_FMT\_NV12\_16L16](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12-16l16>), [V4L2\_PIX\_FMT\_JPEG](</kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-jpeg>), [V4L2\_PIX\_FMT\_MJPEG](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-mjpeg>), [V4L2\_PIX\_FMT\_MR97310A](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-mr97310a>), [V4L2\_PIX\_FMT\_OV511](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-ov511>), [V4L2\_PIX\_FMT\_OV518](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-ov518>), [V4L2\_PIX\_FMT\_PAC207](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-pac207>), [V4L2\_PIX\_FMT\_PJPG](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-pjpg>), [V4L2\_PIX\_FMT\_RGB24](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb24>), [V4L2\_PIX\_FMT\_SBGGR8](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-sbggr8>), [V4L2\_PIX\_FMT\_SGBRG8](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-sgbrg8>), [V4L2\_PIX\_FMT\_SGRBG8](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-sgrbg8>), [V4L2\_PIX\_FMT\_SN9C10X](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-sn9c10x>), [V4L2\_PIX\_FMT\_SN9C20X\_I420](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-sn9c20x-i420>), [V4L2\_PIX\_FMT\_SPCA501](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-spca501>), [V4L2\_PIX\_FMT\_SPCA505](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-spca505>), [V4L2\_PIX\_FMT\_SPCA508](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-spca508>), [V4L2\_PIX\_FMT\_SPCA561](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-spca561>), [V4L2\_PIX\_FMT\_SQ905C](</kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-sq905c>), [V4L2\_PIX\_FMT\_SRGGB8](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-srggb8>), [V4L2\_PIX\_FMT\_UYVY](</kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-uyvy>), [V4L2\_PIX\_FMT\_YUV420](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv420>), [V4L2\_PIX\_FMT\_YUYV](</kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuyv>), [V4L2\_PIX\_FMT\_YVU420](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu420>), and [V4L2\_PIX\_FMT\_YVYU](</kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yvyu>).

Later on libv4lconvert was expanded to also be able to do various video processing functions to improve webcam video quality. The video processing is split in to 2 parts: libv4lconvert/control and libv4lconvert/processing.

The control part is used to offer video controls which can be used to control the video processing functions made available by libv4lconvert/processing. These controls are stored application wide (until reboot) by using a persistent shared memory object.

libv4lconvert/processing offers the actual video processing functionality.

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

## libv4l1

This library offers functions that can be used to quickly make v4l1 applications work with v4l2 devices. These functions work exactly like the normal open/close/etc, except that libv4l1 does full emulation of the v4l1 api on top of v4l2 drivers, in case of v4l1 drivers it will just pass calls through.

Since those functions are emulations of the old V4L1 API, it shouldn't be used for new applications.

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

## libv4l2

This library should be used for all modern V4L2 applications.

It provides handles to call V4L2 open/ioctl/close/poll methods. Instead of just providing the raw output of the device, it enhances the calls in the sense that it will use libv4lconvert to provide more video formats and to enhance the image quality.

In most cases, libv4l2 just passes the calls directly through to the v4l2 driver, intercepting the calls to [VIDIOC\_TRY\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), [VIDIOC\_G\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), [VIDIOC\_ENUM\_FRAMESIZES](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#rst-vidioc-enum-framesizes>) and [VIDIOC\_ENUM\_FRAMEINTERVALS](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#rst-vidioc-enum-frameintervals>) in order to emulate the formats [V4L2\_PIX\_FMT\_BGR24](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgr24>), [V4L2\_PIX\_FMT\_RGB24](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb24>), [V4L2\_PIX\_FMT\_YUV420](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv420>), and [V4L2\_PIX\_FMT\_YVU420](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu420>), if they aren't available in the driver. [VIDIOC\_ENUM\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) keeps enumerating the hardware supported formats, plus the emulated formats offered by libv4l at the end.

<a id="rst-libv4l-device-control-functions"></a>
<a id="rst-libv4l-ops"></a>

### Libv4l device control functions

The common file operation methods are provided by libv4l.

Those functions operate just like the gcc function `dup()` and V4L2 functions `open()`, `close()`, `ioctl()`, `read()`, `mmap()` and `munmap()`:

<a id="c-v4l2_open"></a>



```c
int v4l2_open(const char *file, int oflag, ...)
```

operates like the `open()` function.

<a id="c-v4l2_close"></a>



```c
int v4l2_close(int fd)
```

operates like the `close()` function.

<a id="c-v4l2_dup"></a>



```c
int v4l2_dup(int fd)
```

operates like the libc `dup()` function, duplicating a file handler.

<a id="c-v4l2_ioctl"></a>



```c
int v4l2_ioctl (int fd, unsigned long int request, ...)
```

operates like the `ioctl()` function.

<a id="c-v4l2_read"></a>



```c
int v4l2_read (int fd, void* buffer, size_t n)
```

operates like the `read()` function.

<a id="c-v4l2_mmap"></a>



```c
void *v4l2_mmap(void *start, size_t length, int prot, int flags, int fd, int64_t offset);
```

operates like the `mmap()` function.

<a id="c-v4l2_munmap"></a>



```c
int v4l2_munmap(void *_start, size_t length);
```

operates like the `munmap()` function.

Those functions provide additional control:

<a id="c-v4l2_fd_open"></a>



```c
int v4l2_fd_open(int fd, int v4l2_flags)
```

opens an already opened fd for further use through v4l2lib and possibly modify libv4l2's default behavior through the `v4l2_flags` argument. Currently, `v4l2_flags` can be `V4L2_DISABLE_CONVERSION`, to disable format conversion.

<a id="c-v4l2_set_control"></a>



```c
int v4l2_set_control(int fd, int cid, int value)
```

This function takes a value of 0 - 65535, and then scales that range to the actual range of the given v4l control id, and then if the cid exists and is not locked sets the cid to the scaled value.

<a id="c-v4l2_get_control"></a>



```c
int v4l2_get_control(int fd, int cid)
```

This function returns a value of 0 - 65535, scaled to from the actual range of the given v4l control id. when the cid does not exist, could not be accessed for some reason, or some error occurred 0 is returned.

<a id="rst-v4l1compat-so-wrapper-library"></a>

## v4l1compat.so wrapper library

This library intercepts calls to `open()`, `close()`, `ioctl()`, `mmap()` and `munmap()` operations and redirects them to the libv4l counterparts, by using `LD_PRELOAD=/usr/lib/v4l1compat.so`. It also emulates V4L1 calls via V4L2 API.

It allows usage of binary legacy applications that still don't use libv4l.

---

# Libv4l Userspace Library

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Libv4l Userspace Library.

<a id="rst-libv4l-userspace-library"></a>
<a id="rst-libv4l"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

- [Introduction](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/libv4l-introduction.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

---

# Metadata Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These formats are used for the metadata interface only.

<a id="rst-metadata-formats"></a>
<a id="rst-meta-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

These formats are used for the [Metadata Interface](</kernel/userspace/userspace-api/media-v4l/dev-meta.md#rst-metadata>) interface only.

- [V4L2_META_FMT_MALI_C55_STATS ('C55S'), V4L2_META_FMT_MALI_C55_PARAMS ('C55P')](</kernel/userspace/userspace-api/media-v4l/metafmt-arm-mali-c55.md>)
- [V4L2_META_FMT_C3ISP_STATS ('C3ST'), V4L2_META_FMT_C3ISP_PARAMS ('C3PM')](</kernel/userspace/userspace-api/media-v4l/metafmt-c3-isp.md>)
- [V4L2_META_FMT_D4XX ('D4XX')](</kernel/userspace/userspace-api/media-v4l/metafmt-d4xx.md>)
- [metafmt-generic](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/metafmt-generic.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A ('ip3s')](</kernel/userspace/userspace-api/media-v4l/metafmt-intel-ipu3.md>)
- [V4L2_META_FMT_RPI_BE_CFG](</kernel/userspace/userspace-api/media-v4l/metafmt-pisp-be.md>)
- [V4L2_META_FMT_RPI_FE_CFG](</kernel/userspace/userspace-api/media-v4l/metafmt-pisp-fe.md>)
- [V4L2_META_FMT_RK_ISP1_PARAMS ('rk1p'), V4L2_META_FMT_RK_ISP1_STAT_3A ('rk1s'), V4L2_META_FMT_RK_ISP1_EXT_PARAMS ('rk1e')](</kernel/userspace/userspace-api/media-v4l/metafmt-rkisp1.md>)
- [V4L2_META_FMT_UVC ('UVCH')](</kernel/userspace/userspace-api/media-v4l/metafmt-uvc.md>)
- [V4L2_META_FMT_UVC_MSXU_1_5 ('UVCM')](</kernel/userspace/userspace-api/media-v4l/metafmt-uvc-msxu-1-5.md>)
- [V4L2_META_FMT_VIVID ('VIVD')](</kernel/userspace/userspace-api/media-v4l/metafmt-vivid.md>)
- [V4L2_META_FMT_VSP1_HGO ('VSPH')](</kernel/userspace/userspace-api/media-v4l/metafmt-vsp1-hgo.md>)
- [metafmt-vsp1-hgt](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/metafmt-vsp1-hgt.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Generic V4L2 ISP formats](</kernel/userspace/userspace-api/media-v4l/v4l2-isp.md>)

---

# V4L2_META_FMT_MALI_C55_STATS ('C55S'), V4L2_META_FMT_MALI_C55_PARAMS ('C55P')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The ISP device collects different statistics over an input bayer frame. Those statistics can be obtained by userspace from the mali-c55 3a stats <mali-c55-3a-stats> metadata capture video node, using the v4l2_meta_format interface. The…

<a id="rst-v4l2-meta-fmt-mali-c55-stats-c55s-v4l2-meta-fmt-mali-c55-params-c55p"></a>
<a id="rst-v4l2-meta-fmt-mali-c55-stats"></a>
<a id="rst-v4l2-meta-fmt-mali-c55-params"></a>

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

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

## 3A Statistics

The ISP device collects different statistics over an input bayer frame. Those statistics can be obtained by userspace from the [mali-c55 3a stats](</kernel/administration/admin-guide/media/mali-c55.md#rst-mali-c55-3a-stats>) metadata capture video node, using the `v4l2_meta_format` interface. The buffer contains a single instance of the C structure `mali_c55_stats_buffer` defined in `mali-c55-config.h`, so the structure can be obtained from the buffer by:



```C
struct mali_c55_stats_buffer *stats =
        (struct mali_c55_stats_buffer *)buf;
```

For details of the statistics see `mali_c55_stats_buffer`.

<a id="rst-configuration-parameters"></a>

## Configuration Parameters

The configuration parameters are passed to the [mali-c55 3a params](</kernel/administration/admin-guide/media/mali-c55.md#rst-mali-c55-3a-params>) metadata output video node, using the `v4l2_meta_format` interface. Rather than a single struct containing sub-structs for each configurable area of the ISP, parameters for the Mali-C55 use the v4l2-isp parameters system, through which groups of parameters are defined as distinct structs or "blocks" which may be added to the data member of `v4l2_isp_params_buffer`. Userspace is responsible for populating the data member with the blocks that need to be configured by the driver.  Each block-specific struct embeds `v4l2_isp_params_block_header` as its first member and userspace must populate the type member with a value from `mali_c55_param_block_type`.



```c
struct v4l2_isp_params_buffer *params =
        (struct v4l2_isp_params_buffer *)buffer;

params->version = V4L2_ISP_PARAMS_VERSION_V1;
params->data_size = 0;

void *data = (void *)params->data;

struct mali_c55_params_awb_gains *gains =
        (struct mali_c55_params_awb_gains *)data;

gains->header.type = MALI_C55_PARAM_BLOCK_AWB_GAINS;
gains->header.flags |= V4L2_ISP_PARAMS_FL_BLOCK_ENABLE;
gains->header.size = sizeof(struct mali_c55_params_awb_gains);

gains->gain00 = 256;
gains->gain00 = 256;
gains->gain00 = 256;
gains->gain00 = 256;

data += sizeof(struct mali_c55_params_awb_gains);
params->data_size += sizeof(struct mali_c55_params_awb_gains);

struct mali_c55_params_sensor_off_preshading *blc =
        (struct mali_c55_params_sensor_off_preshading *)data;

blc->header.type = MALI_C55_PARAM_BLOCK_SENSOR_OFFS;
blc->header.flags |= V4L2_ISP_PARAMS_FL_BLOCK_ENABLE;
blc->header.size = sizeof(struct mali_c55_params_sensor_off_preshading);

blc->chan00 = 51200;
blc->chan01 = 51200;
blc->chan10 = 51200;
blc->chan11 = 51200;

params->data_size += sizeof(struct mali_c55_params_sensor_off_preshading);
```

<a id="rst-arm-mali-c55-uapi-data-types"></a>

## Arm Mali-C55 uAPI data types


#### <a id="c-struct-mali_c55_ae_1024bin_hist"></a>`struct mali_c55_ae_1024bin_hist`

Auto Exposure 1024-bin histogram statistics

**Definition**

```c
struct mali_c55_ae_1024bin_hist {
    __u16 bins[1024];
};
```

**Members**

- `bins`: 1024 element array of 16-bit pixel counts.

**Description**

The 1024-bin histogram module collects image-global but zone-weighted
intensity distributions of pixels in fixed-width bins. The modules can be
configured into different "plane modes" which affect the contents of the
collected statistics. In plane mode 0, pixel intensities are taken regardless
of colour plane into a single 1024-bin histogram with a bin width of 4. In
plane mode 1, four 256-bin histograms with a bin width of 16 are collected -
one for each CFA colour plane. In plane modes 4, 5, 6 and 7 two 512-bin
histograms with a bin width of 8 are collected - in each mode one of the
colour planes is collected into the first histogram and all the others are
combined into the second. The histograms are stored consecutively in the bins
array.

The 16-bit pixel counts are stored as a 4-bit exponent in the most
significant bits followed by a 12-bit mantissa. Conversion to a usable
format can be done according to the following pseudo-code:

```text
if (e == 0) {
        bin = m * 2;
} else {
        bin = (m + 4096) * 2^e
}
```

- where:
  e is the exponent value in range 0..15
  m is the mantissa value in range 0..4095

The pixels used in calculating the statistics can be masked using three
methods:

1. Pixels can be skipped in X and Y directions independently.
2. Minimum/Maximum intensities can be configured
3. Zones can be differentially weighted, including 0 weighted to mask them

The data for this histogram can be collected from different tap points in the
ISP depending on configuration - after the white balance or digital gain
blocks, or immediately after the input crossbar.

#### <a id="c-struct-mali_c55_ae_5bin_hist"></a>`struct mali_c55_ae_5bin_hist`

Auto Exposure 5-bin histogram statistics

**Definition**

```c
struct mali_c55_ae_5bin_hist {
    __u16 hist0;
    __u16 hist1;
    __u16 hist3;
    __u16 hist4;
};
```

**Members**

- `hist0`: 16-bit normalised pixel count for the 0th intensity bin
- `hist1`: 16-bit normalised pixel count for the 1st intensity bin
- `hist3`: 16-bit normalised pixel count for the 3rd intensity bin
- `hist4`: 16-bit normalised pixel count for the 4th intensity bin

**Description**

The ISP generates a 5-bin histogram of normalised pixel counts within bins of
pixel intensity for each of 225 possible zones within a frame. The centre bin
of the histogram for each zone is not available from the hardware and must be
calculated by subtracting the values of hist0, hist1, hist3 and hist4 from
0xffff as in the following equation:

hist2 = 0xffff - (hist0 + hist1 + hist3 + hist4)

#### <a id="c-struct-mali_c55_awb_average_ratios"></a>`struct mali_c55_awb_average_ratios`

Auto White Balance colour ratios

**Definition**

```c
struct mali_c55_awb_average_ratios {
    __u16 avg_rg_gr;
    __u16 avg_bg_br;
    __u32 num_pixels;
};
```

**Members**

- `avg_rg_gr`: Average R/G or G/R ratio in Q4.8 format.
- `avg_bg_br`: Average B/G or B/R ratio in Q4.8 format.
- `num_pixels`: The number of pixels used in the AWB calculation

**Description**

The ISP calculates and collects average colour ratios for each zone in an
image and stores them in Q4.8 format (the lowest 8 bits are fractional, with
bits \[11:8\] representing the integer). The exact ratios collected (either
R/G, B/G or G/R, B/R) are configurable through the parameters buffer. The
value of the 4 high bits is undefined.

#### <a id="c-struct-mali_c55_af_statistics"></a>`struct mali_c55_af_statistics`

Auto Focus edge and intensity statistics

**Definition**

```c
struct mali_c55_af_statistics {
    __u16 intensity_stats;
    __u16 edge_stats;
};
```

**Members**

- `intensity_stats`: Packed mantissa and exponent value for pixel intensity
- `edge_stats`: Packed mantissa and exponent values for edge intensity

**Description**

The ISP collects the squared sum of pixel intensities for each zone within a
configurable Region of Interest on the frame. Additionally, the same data are
collected after being passed through a bandpass filter which removes high and
low frequency components - these are referred to as the edge statistics.

The intensity and edge statistics for a zone can be used to calculate the
contrast information for a zone

C = E2 / I2

Where I2 is the intensity statistic for a zone and E2 is the edge statistic
for that zone. Optimum focus is reached when C is at its maximum.

The intensity and edge statistics are stored packed into a non-standard 16
bit floating point format, where the 7 most significant bits represent the
exponent and the 9 least significant bits the mantissa. This format can be
unpacked with the following pseudocode:

```text
if (e == 0) {
        x = m;
} else {
        x = 2^e-1 * (m + 2^9)
}
```

- where:
  e is the exponent value in range 0..127
  m is the mantissa value in range 0..511

#### <a id="c-struct-mali_c55_stats_buffer"></a>`struct mali_c55_stats_buffer`

3A statistics for the mali-c55 ISP

**Definition**

```c
struct mali_c55_stats_buffer {
    struct mali_c55_ae_1024bin_hist ae_1024bin_hist;
    struct mali_c55_ae_1024bin_hist iridix_1024bin_hist;
    struct mali_c55_ae_5bin_hist ae_5bin_hists[MALI_C55_MAX_ZONES];
    __u32 reserved1[14];
    struct mali_c55_awb_average_ratios awb_ratios[MALI_C55_MAX_ZONES];
    __u32 reserved2[14];
    struct mali_c55_af_statistics af_statistics[MALI_C55_MAX_ZONES];
    __u32 reserved3[15];
};
```

**Members**

- `ae_1024bin_hist`: 1024-bin frame-global pixel intensity histogram
- `iridix_1024bin_hist`: Post-Iridix block 1024-bin histogram
- `ae_5bin_hists`: 5-bin pixel intensity histograms for AEC
- `reserved1`: Undefined buffer space
- `awb_ratios`: Color balance ratios for Auto White Balance
- `reserved2`: Undefined buffer space
- `af_statistics`: Pixel intensity statistics for Auto Focus
- `reserved3`: Undefined buffer space

**Description**

This struct describes the metering statistics space in the Mali-C55 ISP's
hardware in its entirety. The space between each defined area is marked as
"unknown" and may not be 0, but should not be used. The **ae_5bin_hists**,
**awb_ratios** and **af_statistics** members are arrays of statistics per-zone.
The zones are arranged in the array in raster order starting from the top
left corner of the image.

#### <a id="c-enum-mali_c55_param_block_type"></a>`enum mali_c55_param_block_type`

Enumeration of Mali-C55 parameter blocks

**Constants**

- `MALI_C55_PARAM_BLOCK_SENSOR_OFFS`: Sensor pre-shading black level offset
- `MALI_C55_PARAM_BLOCK_AEXP_HIST`: Auto-exposure 1024-bin histogram
  configuration
- `MALI_C55_PARAM_BLOCK_AEXP_IHIST`: Post-Iridix auto-exposure 1024-bin
  histogram configuration
- `MALI_C55_PARAM_BLOCK_AEXP_HIST_WEIGHTS`: Auto-exposure 1024-bin histogram
  weighting
- `MALI_C55_PARAM_BLOCK_AEXP_IHIST_WEIGHTS`: Post-Iridix auto-exposure 1024-bin
  histogram weighting
- `MALI_C55_PARAM_BLOCK_DIGITAL_GAIN`: Digital gain
- `MALI_C55_PARAM_BLOCK_AWB_GAINS`: Auto-white balance gains
- `MALI_C55_PARAM_BLOCK_AWB_CONFIG`: Auto-white balance statistics config
- `MALI_C55_PARAM_BLOCK_AWB_GAINS_AEXP`: Auto-white balance gains for AEXP-0 tap
- `MALI_C55_PARAM_MESH_SHADING_CONFIG`: Mesh shading tables configuration
- `MALI_C55_PARAM_MESH_SHADING_SELECTION`: Mesh shading table selection

**Description**

This enumeration defines the types of Mali-C55 parameters block. Each block
configures a specific processing block of the Mali-C55 ISP. The block
type allows the driver to correctly interpret the parameters block data.

It is the responsibility of userspace to correctly set the type of each
parameters block.

#### <a id="c-struct-mali_c55_params_sensor_off_preshading"></a>`struct mali_c55_params_sensor_off_preshading`

offset subtraction for each color channel

**Definition**

```c
struct mali_c55_params_sensor_off_preshading {
    struct v4l2_isp_params_block_header header;
    __u32 chan00;
    __u32 chan01;
    __u32 chan10;
    __u32 chan11;
};
```

**Members**

- `header`: The Mali-C55 parameters block header
- `chan00`: Offset for color channel 00 (default: R)
- `chan01`: Offset for color channel 01 (default: Gr)
- `chan10`: Offset for color channel 10 (default: Gb)
- `chan11`: Offset for color channel 11 (default: B)

**Description**

Provides removal of the sensor black level from the sensor data. Separate
offsets are provided for each of the four Bayer component color channels
which are defaulted to R, Gr, Gb, B.

header.type should be set to MALI_C55_PARAM_BLOCK_SENSOR_OFFS from
[`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type) for this block.

#### <a id="c-enum-mali_c55_aexp_hist_tap_points"></a>`enum mali_c55_aexp_hist_tap_points`

Tap points for the AEXP histogram

**Constants**

- `MALI_C55_AEXP_HIST_TAP_WB`: After static white balance
- `MALI_C55_AEXP_HIST_TAP_FS`: After WDR Frame Stitch
- `MALI_C55_AEXP_HIST_TAP_TPG`: After the test pattern generator

#### <a id="c-enum-mali_c55_aexp_skip_x"></a>`enum mali_c55_aexp_skip_x`

Horizontal pixel skipping

**Constants**

- `MALI_C55_AEXP_SKIP_X_EVERY_2ND`: Collect every 2nd pixel horizontally
- `MALI_C55_AEXP_SKIP_X_EVERY_3RD`: Collect every 3rd pixel horizontally
- `MALI_C55_AEXP_SKIP_X_EVERY_4TH`: Collect every 4th pixel horizontally
- `MALI_C55_AEXP_SKIP_X_EVERY_5TH`: Collect every 5th pixel horizontally
- `MALI_C55_AEXP_SKIP_X_EVERY_8TH`: Collect every 8th pixel horizontally
- `MALI_C55_AEXP_SKIP_X_EVERY_9TH`: Collect every 9th pixel horizontally

#### <a id="c-enum-mali_c55_aexp_skip_y"></a>`enum mali_c55_aexp_skip_y`

Vertical pixel skipping

**Constants**

- `MALI_C55_AEXP_SKIP_Y_ALL`: Collect every single pixel vertically
- `MALI_C55_AEXP_SKIP_Y_EVERY_2ND`: Collect every 2nd pixel vertically
- `MALI_C55_AEXP_SKIP_Y_EVERY_3RD`: Collect every 3rd pixel vertically
- `MALI_C55_AEXP_SKIP_Y_EVERY_4TH`: Collect every 4th pixel vertically
- `MALI_C55_AEXP_SKIP_Y_EVERY_5TH`: Collect every 5th pixel vertically
- `MALI_C55_AEXP_SKIP_Y_EVERY_8TH`: Collect every 8th pixel vertically
- `MALI_C55_AEXP_SKIP_Y_EVERY_9TH`: Collect every 9th pixel vertically

#### <a id="c-enum-mali_c55_aexp_row_column_offset"></a>`enum mali_c55_aexp_row_column_offset`

Start from the first or second row or column

**Constants**

- `MALI_C55_AEXP_FIRST_ROW_OR_COL`: Start from the first row / column
- `MALI_C55_AEXP_SECOND_ROW_OR_COL`: Start from the second row / column

#### <a id="c-enum-mali_c55_aexp_hist_plane_mode"></a>`enum mali_c55_aexp_hist_plane_mode`

Mode for the AEXP Histograms

**Constants**

- `MALI_C55_AEXP_HIST_COMBINED`: All color planes in one 1024-bin histogram
- `MALI_C55_AEXP_HIST_SEPARATE`: Each color plane in one 256-bin histogram with a bin width of 16
- `MALI_C55_AEXP_HIST_FOCUS_00`: Top left plane in the first bank, rest in second bank
- `MALI_C55_AEXP_HIST_FOCUS_01`: Top right plane in the first bank, rest in second bank
- `MALI_C55_AEXP_HIST_FOCUS_10`: Bottom left plane in the first bank, rest in second bank
- `MALI_C55_AEXP_HIST_FOCUS_11`: Bottom right plane in the first bank, rest in second bank

**Description**

In the "focus" modes statistics are collected into two 512-bin histograms
with a bin width of 8. One colour plane is in the first histogram with the
remainder combined into the second. The four options represent which of the
four positions in a bayer pattern are the focused plane.

#### <a id="c-struct-mali_c55_params_aexp_hist"></a>`struct mali_c55_params_aexp_hist`

configuration for AEXP metering hists

**Definition**

```c
struct mali_c55_params_aexp_hist {
    struct v4l2_isp_params_block_header header;
    __u8 skip_x;
    __u8 offset_x;
    __u8 skip_y;
    __u8 offset_y;
    __u8 scale_bottom;
    __u8 scale_top;
    __u8 plane_mode;
    __u8 tap_point;
};
```

**Members**

- `header`: The Mali-C55 parameters block header
- `skip_x`: Horizontal decimation. See enum mali_c55_aexp_skip_x
- `offset_x`: Skip the first column, or not. See enum mali_c55_aexp_row_column_offset
- `skip_y`: Vertical decimation. See enum mali_c55_aexp_skip_y
- `offset_y`: Skip the first row, or not. See enum mali_c55_aexp_row_column_offset
- `scale_bottom`: Scale pixels in bottom half of intensity range: 0=1x ,1=2x, 2=4x, 4=8x, 4=16x
- `scale_top`: scale pixels in top half of intensity range: 0=1x ,1=2x, 2=4x, 4=8x, 4=16x
- `plane_mode`: Plane separation mode. See enum mali_c55_aexp_hist_plane_mode
- `tap_point`: Tap point for histogram from enum mali_c55_aexp_hist_tap_points.
  This parameter is unused for the post-Iridix Histogram

**Description**

This struct allows users to configure the 1024-bin AEXP histograms. Broadly
speaking the parameters allow you to mask particular regions of the image and
to select different kinds of histogram.

The skip_x, offset_x, skip_y and offset_y fields allow users to ignore or
mask pixels in the frame by their position relative to the top left pixel.
First, the skip_y, offset_x and offset_y fields define which of the pixels
within each 2x2 region will be counted in the statistics.

If skip_y == 0 then two pixels from each covered region will be counted. If
both offset_x and offset_y are zero, then the two left-most pixels in each
2x2 pixel region will be counted. Setting offset_x = 1 will discount the top
left pixel and count the top right pixel. Setting offset_y = 1 will discount
the bottom left pixel and count the bottom right pixel.

If skip_y != 0 then only a single pixel from each region covered by the
pattern will be counted. In this case offset_x controls whether the pixel
that's counted is in the left (if offset_x == 0) or right (if offset_x == 1)
column and offset_y controls whether the pixel that's counted is in the top
(if offset_y == 0) or bottom (if offset_y == 1) row.

The skip_x and skip_y fields control how the 2x2 pixel region is repeated
across the image data. The first instance of the region is always in the top
left of the image data. The skip_x field controls how many pixels are ignored
in the x direction before the pixel masking region is repeated. The skip_y
field controls how many pixels are ignored in the y direction before the
pixel masking region is repeated.

These fields can be used to reduce the number of pixels counted for the
statistics, but it's important to be careful to configure them correctly.
Some combinations of values will result in colour components from the input
data being ignored entirely, for example in the following configuration:

skip_x = 0
offset_x = 0
skip_y = 0
offset_y = 0

Only the R and Gb components of RGGB data that was input would be collected.
Similarly in the following configuration:

skip_x = 0
offset_x = 0
skip_y = 1
offset_y = 1

Only the Gb component of RGGB data that was input would be collected. To
correct things such that all 4 colour components were included it would be
necessary to set the skip_x and skip_y fields in a way that resulted in all
four colour components being collected:

skip_x = 1
offset_x = 0
skip_y = 1
offset_y = 1

header.type should be set to one of either MALI_C55_PARAM_BLOCK_AEXP_HIST or
MALI_C55_PARAM_BLOCK_AEXP_IHIST from [`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type).

#### <a id="c-struct-mali_c55_params_aexp_weights"></a>`struct mali_c55_params_aexp_weights`

Array of weights for AEXP metering

**Definition**

```c
struct mali_c55_params_aexp_weights {
    struct v4l2_isp_params_block_header header;
    __u8 nodes_used_horiz;
    __u8 nodes_used_vert;
    __u8 zone_weights[MALI_C55_MAX_ZONES];
};
```

**Members**

- `header`: The Mali-C55 parameters block header
- `nodes_used_horiz`: Number of active zones horizontally \[0..15\]
- `nodes_used_vert`: Number of active zones vertically \[0..15\]
- `zone_weights`: Zone weighting. Index is row*col where 0,0 is the top
  left zone continuing in raster order. Each zone can be
  weighted in the range \[0..15\]. The number of rows and
  columns is defined by **nodes_used_vert** and
  **nodes_used_horiz**

**Description**

This struct allows users to configure the weighting for both of the 1024-bin
AEXP histograms. The pixel data collected for each zone is multiplied by the
corresponding weight from this array, which may be zero if the intention is
to mask off the zone entirely.

header.type should be set to one of either MALI_C55_PARAM_BLOCK_AEXP_HIST_WEIGHTS
or MALI_C55_PARAM_BLOCK_AEXP_IHIST_WEIGHTS from [`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type).

#### <a id="c-struct-mali_c55_params_digital_gain"></a>`struct mali_c55_params_digital_gain`

Digital gain value

**Definition**

```c
struct mali_c55_params_digital_gain {
    struct v4l2_isp_params_block_header header;
    __u16 gain;
};
```

**Members**

- `header`: The Mali-C55 parameters block header
- `gain`: The digital gain value to apply, in Q5.8 format.

**Description**

This struct carries a digital gain value to set in the ISP.

header.type should be set to MALI_C55_PARAM_BLOCK_DIGITAL_GAIN from
[`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type) for this block.

#### <a id="c-enum-mali_c55_awb_stats_mode"></a>`enum mali_c55_awb_stats_mode`

Statistics mode for AWB

**Constants**

- `MALI_C55_AWB_MODE_GRBR`: Statistics collected as Green/Red and Blue/Red ratios
- `MALI_C55_AWB_MODE_RGBG`: Statistics collected as Red/Green and Blue/Green ratios

#### <a id="c-struct-mali_c55_params_awb_gains"></a>`struct mali_c55_params_awb_gains`

Gain settings for auto white balance

**Definition**

```c
struct mali_c55_params_awb_gains {
    struct v4l2_isp_params_block_header header;
    __u16 gain00;
    __u16 gain01;
    __u16 gain10;
    __u16 gain11;
};
```

**Members**

- `header`: The Mali-C55 parameters block header
- `gain00`: Multiplier for colour channel 00
- `gain01`: Multiplier for colour channel 01
- `gain10`: Multiplier for colour channel 10
- `gain11`: Multiplier for colour channel 11

**Description**

This struct allows users to configure the gains for auto-white balance. There
are four gain settings corresponding to each colour channel in the bayer
domain. Although named generically, the association between the gain applied
and the colour channel is done automatically within the ISP depending on the
input format, and so the following mapping always holds true:

```text
gain00 = R
gain01 = Gr
gain10 = Gb
gain11 = B
```

All of the gains are stored in Q4.8 format.

header.type should be set to one of either MALI_C55_PARAM_BLOCK_AWB_GAINS or
MALI_C55_PARAM_BLOCK_AWB_GAINS_AEXP from [`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type).

#### <a id="c-enum-mali_c55_params_awb_tap_points"></a>`enum mali_c55_params_awb_tap_points`

Tap points for the AWB statistics

**Constants**

- `MALI_C55_AWB_STATS_TAP_PF`: Immediately after the Purple Fringe block
- `MALI_C55_AWB_STATS_TAP_CNR`: Immediately after the CNR block

#### <a id="c-struct-mali_c55_params_awb_config"></a>`struct mali_c55_params_awb_config`

Stats settings for auto-white balance

**Definition**

```c
struct mali_c55_params_awb_config {
    struct v4l2_isp_params_block_header header;
    __u8 tap_point;
    __u8 stats_mode;
    __u16 white_level;
    __u16 black_level;
    __u16 cr_max;
    __u16 cr_min;
    __u16 cb_max;
    __u16 cb_min;
    __u8 nodes_used_horiz;
    __u8 nodes_used_vert;
    __u16 cr_high;
    __u16 cr_low;
    __u16 cb_high;
    __u16 cb_low;
};
```

**Members**

- `header`: The Mali-C55 parameters block header
- `tap_point`: The tap point from enum mali_c55_params_awb_tap_points
- `stats_mode`: AWB statistics collection mode, see [`mali_c55_awb_stats_mode`](#c-enum-mali_c55_awb_stats_mode)
- `white_level`: Upper pixel intensity (I.E. raw pixel values) limit
- `black_level`: Lower pixel intensity (I.E. raw pixel values) limit
- `cr_max`: Maximum R/G ratio (Q4.8 format)
- `cr_min`: Minimum R/G ratio (Q4.8 format)
- `cb_max`: Maximum B/G ratio (Q4.8 format)
- `cb_min`: Minimum B/G ratio (Q4.8 format)
- `nodes_used_horiz`: Number of active zones horizontally \[0..15\]
- `nodes_used_vert`: Number of active zones vertically \[0..15\]
- `cr_high`: R/G ratio trim high (Q4.8 format)
- `cr_low`: R/G ratio trim low (Q4.8 format)
- `cb_high`: B/G ratio trim high (Q4.8 format)
- `cb_low`: B/G ratio trim low (Q4.8 format)

**Description**

This struct allows the configuration of the statistics generated for auto
white balance. Pixel intensity limits can be set to exclude overly bright or
dark regions of an image from the statistics entirely. Colour ratio minima
and maxima can be set to discount pixels who's ratios fall outside the
defined boundaries; there are two sets of registers to do this - the
"min/max" ratios which bound a region and the "high/low" ratios which further
trim the upper and lower ratios. For example with the boundaries configured
as follows, only pixels whos colour ratios falls into the region marked "A"
would be counted:

```text
                                                         cr_high
   2.0 |                                                   |
       |               cb_max --> _________________________v_____
   1.8 |                         |                         \    |
       |                         |                          \   |
   1.6 |                         |                           \  |
       |                         |                            \ |
c  1.4 |               cb_low -->|\              A             \|<--  cb_high
b      |                         | \                            |
   1.2 |                         |  \                           |
r      |                         |   \                          |
a  1.0 |              cb_min --> |____\_________________________|
t      |                         ^    ^                         ^
i  0.8 |                         |    |                         |
o      |                      cr_min  |                       cr_max
s  0.6 |                              |
       |                             cr_low
   0.4 |
       |
   0.2 |
       |
   0.0 |_______________________________________________________________
       0.0   0.2   0.4   0.6   0.8   1.0   1.2   1.4   1.6   1.8   2.0
                                  cr ratios
```

header.type should be set to MALI_C55_PARAM_BLOCK_AWB_CONFIG from
[`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type) for this block.

#### <a id="c-struct-mali_c55_params_mesh_shading_config"></a>`struct mali_c55_params_mesh_shading_config`

Mesh shading configuration

**Definition**

```c
struct mali_c55_params_mesh_shading_config {
    struct v4l2_isp_params_block_header header;
    __u8 mesh_show;
    __u8 mesh_scale;
    __u8 mesh_page_r;
    __u8 mesh_page_g;
    __u8 mesh_page_b;
    __u8 mesh_width;
    __u8 mesh_height;
    __u32 mesh[MALI_C55_NUM_MESH_SHADING_ELEMENTS];
};
```

**Members**

- `header`: The Mali-C55 parameters block header
- `mesh_show`: Output the mesh data rather than image data
- `mesh_scale`: Set the precision and maximum gain range of mesh shading
  - 0 = 0-2x gain
  - 1 = 0-4x gain
  - 2 = 0-8x gain
  - 3 = 0-16x gain
  - 4 = 1-2x gain
  - 5 = 1-3x gain
  - 6 = 1-5x gain
  - 7 = 1-9x gain
- `mesh_page_r`: Mesh page select for red colour plane \[0..2\]
- `mesh_page_g`: Mesh page select for green colour plane \[0..2\]
- `mesh_page_b`: Mesh page select for blue colour plane \[0..2\]
- `mesh_width`: Number of horizontal nodes minus 1 \[15,31\]
- `mesh_height`: Number of vertical nodes minus 1 \[15,31\]
- `mesh`: Mesh shading correction tables

**Description**

The mesh shading correction module allows programming a separate table of
either 16x16 or 32x32 node coefficients for 3 different light sources. The
final correction coefficients applied are computed by blending the
coefficients from two tables together.

A page of 1024 32-bit integers is associated to each colour channel, with
pages stored consecutively in memory. Each 32-bit integer packs 3 8-bit
correction coefficients for a single node, one for each of the three light
sources. The 8 most significant bits are unused. The following table
describes the layout:

```text
+----------- Page (Colour Plane) 0 -------------+
| @mesh[i]  | Mesh Point | Bits  | Light Source |
+-----------+------------+-------+--------------+
|         0 |        0,0 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+-----------+------------+-------+--------------+
|         1 |        0,1 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+-----------+------------+-------+--------------+
|       ... |        ... | ...   | ...          |
+-----------+------------+-------+--------------+
|      1023 |      31,31 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+----------- Page (Colour Plane) 1 -------------+
| @mesh[i]  | Mesh Point | Bits  | Light Source |
+-----------+------------+-------+--------------+
|      1024 |        0,0 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+-----------+------------+-------+--------------+
|      1025 |        0,1 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+-----------+------------+-------+--------------+
|       ... |        ... | ...   | ...          |
+-----------+------------+-------+--------------+
|      2047 |      31,31 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+----------- Page (Colour Plane) 2 -------------+
| @mesh[i]  | Mesh Point | Bits  | Light Source |
+-----------+------------+-------+--------------+
|      2048 |        0,0 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+-----------+------------+-------+--------------+
|      2049 |        0,1 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+-----------+------------+-------+--------------+
|       ... |        ... | ...   | ...          |
+-----------+------------+-------+--------------+
|      3071 |      31,31 | 16,23 | LS2          |
|           |            | 08-15 | LS1          |
|           |            | 00-07 | LS0          |
+-----------+------------+-------+--------------+
```

The **mesh_scale** member determines the precision and minimum and maximum gain.
For example if **mesh_scale** is 0 and therefore selects 0 - 2x gain, a value of
0 in a coefficient means 0.0 gain, a value of 128 means 1.0 gain and 255
means 2.0 gain.

header.type should be set to MALI_C55_PARAM_MESH_SHADING_CONFIG from
[`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type) for this block.

#### <a id="c-struct-mali_c55_params_mesh_shading_selection"></a>`struct mali_c55_params_mesh_shading_selection`

Mesh table selection

**Definition**

```c
struct mali_c55_params_mesh_shading_selection {
    struct v4l2_isp_params_block_header header;
    __u8 mesh_alpha_bank_r;
    __u8 mesh_alpha_bank_g;
    __u8 mesh_alpha_bank_b;
    __u8 mesh_alpha_r;
    __u8 mesh_alpha_g;
    __u8 mesh_alpha_b;
    __u16 mesh_strength;
};
```

**Members**

- `header`: The Mali-C55 parameters block header
- `mesh_alpha_bank_r`: Red mesh table select (cenum mali_c55_params_mesh_alpha_bank)
- `mesh_alpha_bank_g`: Green mesh table select (cenum mali_c55_params_mesh_alpha_bank)
- `mesh_alpha_bank_b`: Blue mesh table select (cenum mali_c55_params_mesh_alpha_bank)
- `mesh_alpha_r`: Blend coefficient for R \[0..255\]
- `mesh_alpha_g`: Blend coefficient for G \[0..255\]
- `mesh_alpha_b`: Blend coefficient for B \[0..255\]
- `mesh_strength`: Mesh strength in Q4.12 format \[0..4096\]

**Description**

The module computes the final correction coefficients by blending the ones
from two light source tables, which are selected (independently for each
colour channel) by the **mesh_alpha_bank_r**/g/b fields.

The final blended coefficients for each node are calculated using the
following equation:

Final coefficient = (a * LS\ b\ + (256 - a) * LS\ a\) / 256

Where a is the **mesh_alpha_r**/g/b value, and LS\ a\ and LS\ b\
are the node cofficients for the two tables selected by the
**mesh_alpha_bank_r**/g/b value.

The scale of the applied correction may also be controlled by tuning the
**mesh_strength** member. This is a modifier to the final coefficients which can
be used to globally reduce the gains applied.

header.type should be set to MALI_C55_PARAM_MESH_SHADING_SELECTION from
[`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type) for this block.

#### <a id="c-MALI_C55_PARAMS_MAX_SIZE"></a>`MALI_C55_PARAMS_MAX_SIZE`

```c
MALI_C55_PARAMS_MAX_SIZE
```

Maximum size of all Mali C55 Parameters

**Description**

Though the parameters for the Mali-C55 are passed as optional blocks, the
driver still needs to know the absolute maximum size so that it can allocate
a buffer sized appropriately to accommodate userspace attempting to set all
possible parameters in a single frame.

Some structs are in this list multiple times. Where that's the case, it just
reflects the fact that the same struct can be used with multiple different
header types from [`mali_c55_param_block_type`](#c-enum-mali_c55_param_block_type).

---

# V4L2_META_FMT_C3ISP_STATS ('C3ST'), V4L2_META_FMT_C3ISP_PARAMS ('C3PM')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The C3 ISP can collect different statistics over an input Bayer frame. Those statistics are obtained from the "c3-isp-stats" metadata capture video nodes, using the v4l2_meta_format interface. They are formatted as described by the…

<a id="rst-v4l2-meta-fmt-c3isp-stats-c3st-v4l2-meta-fmt-c3isp-params-c3pm"></a>
<a id="rst-v4l2-meta-fmt-c3isp-params"></a>
<a id="rst-v4l2-meta-fmt-c3isp-stats"></a>

<!-- SPDX-License-Identifier: (GPL-2.0-only OR MIT) -->

<!-- c:namespace: V4L -->

<!-- c3_isp_stats_info -->

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

## 3A Statistics

The C3 ISP can collect different statistics over an input Bayer frame. Those statistics are obtained from the "c3-isp-stats" metadata capture video nodes, using the `v4l2_meta_format` interface. They are formatted as described by the `c3_isp_stats_info` structure.

The statistics collected are  Auto-white balance, Auto-exposure and Auto-focus information.

<!-- c3_isp_params_cfg -->

<a id="rst-configuration-parameters"></a>

## Configuration Parameters

The configuration parameters are passed to the c3-isp-params metadata output video node, using the `v4l2_meta_format` interface. Rather than a single struct containing sub-structs for each configurable area of the ISP, parameters for the C3-ISP are defined as distinct structs or "blocks" which may be added to the data member of `c3_isp_params_cfg`. Userspace is responsible for populating the data member with the blocks that need to be configured by the driver, but need not populate it with **all** the blocks, or indeed with any at all if there are no configuration changes to make. Populated blocks **must** be consecutive in the buffer. To assist both userspace and the driver in identifying the blocks each block-specific struct embeds `c3_isp_params_block_header` as its first member and userspace must populate the type member with a value from `c3_isp_params_block_type`. Once the blocks have been populated into the data buffer, the combined size of all populated blocks shall be set in the data_size member of `c3_isp_params_cfg`. For example:



```c
struct c3_isp_params_cfg *params =
        (struct c3_isp_params_cfg *)buffer;

params->version = C3_ISP_PARAM_BUFFER_V0;
params->data_size = 0;

void *data = (void *)params->data;

struct c3_isp_params_awb_gains *gains =
        (struct c3_isp_params_awb_gains *)data;

gains->header.type = C3_ISP_PARAMS_BLOCK_AWB_GAINS;
gains->header.flags = C3_ISP_PARAMS_BLOCK_FL_ENABLE;
gains->header.size = sizeof(struct c3_isp_params_awb_gains);

gains->gr_gain = 256;
gains->r_gain = 256;
gains->b_gain = 256;
gains->gb_gain = 256;

data += sizeof(struct c3_isp__params_awb_gains);
params->data_size += sizeof(struct c3_isp_params_awb_gains);

struct c3_isp_params_awb_config *awb_cfg =
        (struct c3_isp_params_awb_config *)data;

awb_cfg->header.type = C3_ISP_PARAMS_BLOCK_AWB_CONFIG;
awb_cfg->header.flags = C3_ISP_PARAMS_BLOCK_FL_ENABLE;
awb_cfg->header.size = sizeof(struct c3_isp_params_awb_config);

awb_cfg->tap_point = C3_ISP_AWB_STATS_TAP_BEFORE_WB;
awb_cfg->satur = 1;
awb_cfg->horiz_zones_num = 32;
awb_cfg->vert_zones_num = 24;

params->data_size += sizeof(struct c3_isp_params_awb_config);
```

<a id="rst-amlogic-c3-isp-uapi-data-types"></a>

## Amlogic C3 ISP uAPI data types


#### <a id="c-struct-c3_isp_awb_zone_stats"></a>`struct c3_isp_awb_zone_stats`

AWB statistics of a zone

**Definition**

```c
struct c3_isp_awb_zone_stats {
    __u16 rg;
    __u16 bg;
    __u32 pixel_sum;
};
```

**Members**

- `rg`: the ratio of R / G in a zone
- `bg`: the ratio of B / G in a zone
- `pixel_sum`: the total number of pixels used in a zone

**Description**

AWB zone stats is aligned with 8 bytes

#### <a id="c-struct-c3_isp_awb_stats"></a>`struct c3_isp_awb_stats`

Auto white balance statistics information.

**Definition**

```c
struct c3_isp_awb_stats {
    struct c3_isp_awb_zone_stats stats[C3_ISP_AWB_MAX_ZONES];
};
```

**Members**

- `stats`: array of auto white balance statistics

**Description**

AWB statistical information of all zones.

#### <a id="c-struct-c3_isp_ae_zone_stats"></a>`struct c3_isp_ae_zone_stats`

AE statistics of a zone

**Definition**

```c
struct c3_isp_ae_zone_stats {
    __u16 hist0;
    __u16 hist1;
    __u16 hist3;
    __u16 hist4;
};
```

**Members**

- `hist0`: the global normalized pixel count for bin 0
- `hist1`: the global normalized pixel count for bin 1
- `hist3`: the global normalized pixel count for bin 3
- `hist4`: the global normalized pixel count for bin 4

**Description**

AE zone stats is aligned with 8 bytes.
This is a 5-bin histogram and the total sum is normalized to 0xffff.
So hist2 = 0xffff - (hist0 + hist1 + hist3 + hist4)

#### <a id="c-struct-c3_isp_ae_stats"></a>`struct c3_isp_ae_stats`

Exposure statistics information

**Definition**

```c
struct c3_isp_ae_stats {
    struct c3_isp_ae_zone_stats stats[C3_ISP_AE_MAX_ZONES];
    __u32 reserved[2];
    __u32 hist[1024];
};
```

**Members**

- `stats`: array of auto exposure block statistics
- `reserved`: undefined buffer space
- `hist`: a 1024-bin histogram for the entire image

**Description**

AE statistical information consists of all blocks information and a 1024-bin
histogram.

#### <a id="c-struct-c3_isp_af_zone_stats"></a>`struct c3_isp_af_zone_stats`

AF statistics of a zone

**Definition**

```c
struct c3_isp_af_zone_stats {
    __u16 i2_mat;
    __u16 i4_mat;
    __u16 e4_mat;
    __u16 e4_exp : 5;
    __u16 i2_exp : 5;
    __u16 i4_exp : 6;
};
```

**Members**

- `i2_mat`: the mantissa of zonal squared image pixel sum
- `i4_mat`: the mantissa of zonal quartic image pixel sum
- `e4_mat`: the mantissa of zonal multi-directional quartic edge sum
- `e4_exp`: the exponent of zonal multi-directional quartic edge sum
- `i2_exp`: the exponent of zonal squared image pixel sum
- `i4_exp`: the exponent of zonal quartic image pixel sum

**Description**

AF zone stats is aligned with 8 bytes.
The zonal accumulated contrast metrics are stored in floating point format
with 16 bits mantissa and 5 or 6 bits exponent. Apart from contrast metrics
we accumulate squared image and quartic image data over the zone.

#### <a id="c-struct-c3_isp_af_stats"></a>`struct c3_isp_af_stats`

Auto Focus statistics information

**Definition**

```c
struct c3_isp_af_stats {
    struct c3_isp_af_zone_stats stats[C3_ISP_AF_MAX_ZONES];
    __u32 reserved[2];
};
```

**Members**

- `stats`: array of auto focus block statistics
- `reserved`: undefined buffer space

**Description**

AF statistical information of each zone

#### <a id="c-struct-c3_isp_stats_info"></a>`struct c3_isp_stats_info`

V4L2_META_FMT_C3ISP_STATS

**Definition**

```c
struct c3_isp_stats_info {
    struct c3_isp_awb_stats awb;
    struct c3_isp_ae_stats ae;
    struct c3_isp_af_stats af;
};
```

**Members**

- `awb`: auto white balance stats
- `ae`: auto exposure stats
- `af`: auto focus stats

**Description**

Contains ISP statistics

#### <a id="c-enum-c3_isp_params_buffer_version"></a>`enum c3_isp_params_buffer_version`

C3 ISP parameters block versioning

**Constants**

- `C3_ISP_PARAMS_BUFFER_V0`: First version of C3 ISP parameters block

#### <a id="c-enum-c3_isp_params_block_type"></a>`enum c3_isp_params_block_type`

Enumeration of C3 ISP parameter blocks

**Constants**

- `C3_ISP_PARAMS_BLOCK_AWB_GAINS`: White balance gains
- `C3_ISP_PARAMS_BLOCK_AWB_CONFIG`: AWB statistic format configuration for all
  blocks that control how stats are generated
- `C3_ISP_PARAMS_BLOCK_AE_CONFIG`: AE statistic format configuration for all
  blocks that control how stats are generated
- `C3_ISP_PARAMS_BLOCK_AF_CONFIG`: AF statistic format configuration for all
  blocks that control how stats are generated
- `C3_ISP_PARAMS_BLOCK_PST_GAMMA`: post gamma parameters
- `C3_ISP_PARAMS_BLOCK_CCM`: Color correction matrix parameters
- `C3_ISP_PARAMS_BLOCK_CSC`: Color space conversion parameters
- `C3_ISP_PARAMS_BLOCK_BLC`: Black level correction parameters
- `C3_ISP_PARAMS_BLOCK_SENTINEL`: First non-valid block index

**Description**

Each block configures a specific processing block of the C3 ISP.
The block type allows the driver to correctly interpret the parameters block
data.

#### <a id="c-c3_isp_params_block_header"></a>`c3_isp_params_block_header`

```c
c3_isp_params_block_header
```

C3 ISP parameter block header

**Description**

This structure represents the common part of all the ISP configuration
blocks and is identical to [`v4l2_isp_params_block_header`](/kernel/userspace/userspace-api/media-v4l/v4l2-isp.md#c-struct-v4l2_isp_params_block_header).

The type field is one of the values enumerated by
[`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type) and specifies how the data should be
interpreted by the driver.

The flags field is a bitmask of per-block flags C3_ISP_PARAMS_FL_*.

#### <a id="c-struct-c3_isp_params_awb_gains"></a>`struct c3_isp_params_awb_gains`

Gains for auto-white balance

**Definition**

```c
struct c3_isp_params_awb_gains {
    struct c3_isp_params_block_header header;
    __u16 gr_gain;
    __u16 r_gain;
    __u16 b_gain;
    __u16 gb_gain;
};
```

**Members**

- `header`: The C3 ISP parameters block header
- `gr_gain`: Multiplier for Gr channel (Q4.8 format)
- `r_gain`: Multiplier for R channel (Q4.8 format)
- `b_gain`: Multiplier for B channel (Q4.8 format)
- `gb_gain`: Multiplier for Gb channel (Q4.8 format)

**Description**

This struct allows users to configure the gains for white balance.
There are four gain settings corresponding to each colour channel in
the bayer domain. All of the gains are stored in Q4.8 format.

header.type should be set to C3_ISP_PARAMS_BLOCK_AWB_GAINS
from [`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type)

#### <a id="c-enum-c3_isp_params_awb_tap_points"></a>`enum c3_isp_params_awb_tap_points`

Tap points for the AWB statistics

**Constants**

- `C3_ISP_AWB_STATS_TAP_OFE`: immediately after the optical frontend block
- `C3_ISP_AWB_STATS_TAP_GE`: immediately after the green equal block
- `C3_ISP_AWB_STATS_TAP_BEFORE_WB`: immediately before the white balance block
- `C3_ISP_AWB_STATS_TAP_AFTER_WB`: immediately after the white balance block

#### <a id="c-struct-c3_isp_params_awb_config"></a>`struct c3_isp_params_awb_config`

Stats settings for auto-white balance

**Definition**

```c
struct c3_isp_params_awb_config {
    struct c3_isp_params_block_header header;
    __u8 tap_point;
    __u8 satur_vald;
    __u8 horiz_zones_num;
    __u8 vert_zones_num;
    __u16 rg_min;
    __u16 rg_max;
    __u16 bg_min;
    __u16 bg_max;
    __u16 rg_low;
    __u16 rg_high;
    __u16 bg_low;
    __u16 bg_high;
    __u8 zone_weight[C3_ISP_AWB_MAX_ZONES];
    __u16 horiz_coord[C3_ISP_AWB_MAX_PT_NUM];
    __u16 vert_coord[C3_ISP_AWB_MAX_PT_NUM];
};
```

**Members**

- `header`: the C3 ISP parameters block header
- `tap_point`: the tap point from enum c3_isp_params_awb_tap_point
- `satur_vald`: AWB statistic over saturation control
  value: 0: disable, 1: enable
- `horiz_zones_num`: active number of hotizontal zones \[0..32\]
- `vert_zones_num`: active number of vertical zones \[0..24\]
- `rg_min`: minimum R/G ratio (Q4.8 format)
- `rg_max`: maximum R/G ratio (Q4.8 format)
- `bg_min`: minimum B/G ratio (Q4.8 format)
- `bg_max`: maximum B/G ratio (Q4.8 format)
- `rg_low`: R/G ratio trim low (Q4.8 format)
- `rg_high`: R/G ratio trim hight (Q4.8 format)
- `bg_low`: B/G ratio trim low (Q4.8 format)
- `bg_high`: B/G ratio trim high (Q4.8 format)
- `zone_weight`: array of weights for AWB statistics zones \[0..15\]
- `horiz_coord`: the horizontal coordinate of points on the diagonal \[0..2888\]
- `vert_coord`: the vertical coordinate of points on the diagonal \[0..2240\]

**Description**

This struct allows the configuration of the statistics generated for auto
white balance.

header.type should be set to C3_ISP_PARAMS_BLOCK_AWB_CONFIG
from [`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type)

#### <a id="c-enum-c3_isp_params_ae_tap_points"></a>`enum c3_isp_params_ae_tap_points`

Tap points for the AE statistics

**Constants**

- `C3_ISP_AE_STATS_TAP_GE`: immediately after the green equal block
- `C3_ISP_AE_STATS_TAP_MLS`: immediately after the mesh lens shading block

#### <a id="c-struct-c3_isp_params_ae_config"></a>`struct c3_isp_params_ae_config`

Stats settings for auto-exposure

**Definition**

```c
struct c3_isp_params_ae_config {
    struct c3_isp_params_block_header header;
    __u8 tap_point;
    __u8 horiz_zones_num;
    __u8 vert_zones_num;
    __u8 zone_weight[C3_ISP_AE_MAX_ZONES];
    __u16 horiz_coord[C3_ISP_AE_MAX_PT_NUM];
    __u16 vert_coord[C3_ISP_AE_MAX_PT_NUM];
    __u16 reserved[3];
};
```

**Members**

- `header`: the C3 ISP parameters block header
- `tap_point`: the tap point from enum c3_isp_params_ae_tap_point
- `horiz_zones_num`: active number of horizontal zones \[0..17\]
- `vert_zones_num`: active number of vertical zones \[0..15\]
- `zone_weight`: array of weights for AE statistics zones \[0..15\]
- `horiz_coord`: the horizontal coordinate of points on the diagonal \[0..2888\]
- `vert_coord`: the vertical coordinate of points on the diagonal \[0..2240\]
- `reserved`: applications must zero this array

**Description**

This struct allows the configuration of the statistics generated for
auto exposure.

header.type should be set to C3_ISP_PARAMS_BLOCK_AE_CONFIG
from [`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type)

#### <a id="c-enum-c3_isp_params_af_tap_points"></a>`enum c3_isp_params_af_tap_points`

Tap points for the AF statistics

**Constants**

- `C3_ISP_AF_STATS_TAP_SNR`: immediately after the spatial noise reduce block
- `C3_ISP_AF_STATS_TAP_DMS`: immediately after the demosaic block

#### <a id="c-struct-c3_isp_params_af_config"></a>`struct c3_isp_params_af_config`

Stats settings for auto-focus

**Definition**

```c
struct c3_isp_params_af_config {
    struct c3_isp_params_block_header header;
    __u8 tap_point;
    __u8 horiz_zones_num;
    __u8 vert_zones_num;
    __u8 reserved[5];
    __u16 horiz_coord[C3_ISP_AF_MAX_PT_NUM];
    __u16 vert_coord[C3_ISP_AF_MAX_PT_NUM];
};
```

**Members**

- `header`: the C3 ISP parameters block header
- `tap_point`: the tap point from enum c3_isp_params_af_tap_point
- `horiz_zones_num`: active number of hotizontal zones \[0..17\]
- `vert_zones_num`: active number of vertical zones \[0..15\]
- `reserved`: applications must zero this array
- `horiz_coord`: the horizontal coordinate of points on the diagonal \[0..2888\]
- `vert_coord`: the vertical coordinate of points on the diagonal \[0..2240\]

**Description**

This struct allows the configuration of the statistics generated for
auto focus.

header.type should be set to C3_ISP_PARAMS_BLOCK_AF_CONFIG
from [`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type)

#### <a id="c-struct-c3_isp_params_pst_gamma"></a>`struct c3_isp_params_pst_gamma`

Post gamma configuration

**Definition**

```c
struct c3_isp_params_pst_gamma {
    struct c3_isp_params_block_header header;
    __u16 lut[129];
    __u16 reserved[3];
};
```

**Members**

- `header`: the C3 ISP parameters block header
- `lut`: lookup table for P-Stitch gamma \[0..1023\]
- `reserved`: applications must zero this array

**Description**

This struct allows the configuration of the look up table for
post gamma. The gamma curve consists of 129 points, so need to
set lut\[129\].

header.type should be set to C3_ISP_PARAMS_BLOCK_PST_GAMMA
from [`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type)

#### <a id="c-struct-c3_isp_params_ccm"></a>`struct c3_isp_params_ccm`

ISP CCM configuration

**Definition**

```c
struct c3_isp_params_ccm {
    struct c3_isp_params_block_header header;
    __s16 matrix[3][3];
    __u16 reserved[3];
};
```

**Members**

- `header`: the C3 ISP parameters block header
- `matrix`: a 3 x 3 matrix used for color correction,
  the value of matrix\[x\]\[y\] is orig_value x 256. \[-4096..4095\]
- `reserved`: applications must zero this array

**Description**

This struct allows the configuration of the matrix for
color correction. The matrix consists of 3 x 3 points,
so need to set matrix\[3\]\[3\].

header.type should be set to C3_ISP_PARAMS_BLOCK_CCM
from [`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type)

#### <a id="c-struct-c3_isp_params_csc"></a>`struct c3_isp_params_csc`

ISP Color Space Conversion configuration

**Definition**

```c
struct c3_isp_params_csc {
    struct c3_isp_params_block_header header;
    __s16 matrix[3][3];
    __u16 reserved[3];
};
```

**Members**

- `header`: the C3 ISP parameters block header
- `matrix`: a 3x3 matrix used for the color space conversion,
  the value of matrix\[x\]\[y\] is orig_value x 256. \[-4096..4095\]
- `reserved`: applications must zero this array

**Description**

This struct allows the configuration of the matrix for color space
conversion. The matrix consists of 3 x 3 points, so need to set matrix\[3\]\[3\].

header.type should be set to C3_ISP_PARAMS_BLOCK_CSC
from [`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type)

#### <a id="c-struct-c3_isp_params_blc"></a>`struct c3_isp_params_blc`

ISP Black Level Correction configuration

**Definition**

```c
struct c3_isp_params_blc {
    struct c3_isp_params_block_header header;
    __u16 gr_ofst;
    __u16 r_ofst;
    __u16 b_ofst;
    __u16 gb_ofst;
};
```

**Members**

- `header`: the C3 ISP parameters block header
- `gr_ofst`: Gr blc offset (Q4.12 format)
- `r_ofst`: R blc offset (Q4.12 format)
- `b_ofst`: B blc offset (Q4.12 format)
- `gb_ofst`: Gb blc offset(Q4.12 format)

**Description**

This struct allows the configuration of the block level offset for each
color channel.

header.type should be set to C3_ISP_PARAMS_BLOCK_BLC
from [`c3_isp_params_block_type`](#c-enum-c3_isp_params_block_type)

#### <a id="c-C3_ISP_PARAMS_MAX_SIZE"></a>`C3_ISP_PARAMS_MAX_SIZE`

```c
C3_ISP_PARAMS_MAX_SIZE
```

Maximum size of all C3 ISP Parameters

**Description**

Though the parameters for the C3 ISP are passed as optional blocks, the
driver still needs to know the absolute maximum size so that it can allocate
a buffer sized appropriately to accommodate userspace attempting to set all
possible parameters in a single frame.

#### <a id="c-struct-c3_isp_params_cfg"></a>`struct c3_isp_params_cfg`

C3 ISP configuration parameters

**Definition**

```c
struct c3_isp_params_cfg {
    __u32 version;
    __u32 data_size;
    __u8 data[C3_ISP_PARAMS_MAX_SIZE];
};
```

**Members**

- `version`: The C3 ISP parameters buffer version
- `data_size`: The C3 ISP configuration data effective size, excluding this
  header
- `data`: The C3 ISP configuration blocks data

**Description**

This is the driver-specific implementation of
[`v4l2_isp_params_buffer`](/kernel/userspace/userspace-api/media-v4l/v4l2-isp.md#c-struct-v4l2_isp_params_buffer).

Currently only C3_ISP_PARAM_BUFFER_V0 is supported.

The expected memory layout of the parameters buffer is:

```text
+-------------------- struct c3_isp_params_cfg ---- ------------------+
| version = C3_ISP_PARAM_BUFFER_V0;                                   |
| data_size = sizeof(struct c3_isp_params_awb_gains) +                |
|              sizeof(struct c3_isp_params_awb_config);       |
| +------------------------- data  ---------------------------------+ |
| | +------------ struct c3_isp_params_awb_gains) ------------------+ |
| | | +---------  struct c3_isp_params_block_header header -----+ | | |
| | | | type = C3_ISP_PARAMS_BLOCK_AWB_GAINS;                   | | | |
| | | | flags = C3_ISP_PARAMS_BLOCK_FL_NONE;                    | | | |
| | | | size = sizeof(struct c3_isp_params_awb_gains);          | | | |
| | | +---------------------------------------------------------+ | | |
| | | gr_gain = ...;                                              | | |
| | | r_gain = ...;                                               | | |
| | | b_gain = ...;                                               | | |
| | | gb_gain = ...;                                              | | |
| | +------------------ struct c3_isp_params_awb_config ----------+ | |
| | | +---------- struct c3_isp_param_block_header header ------+ | | |
| | | | type = C3_ISP_PARAMS_BLOCK_AWB_CONFIG;                  | | | |
| | | | flags = C3_ISP_PARAMS_BLOCK_FL_NONE;                    | | | |
| | | | size = sizeof(struct c3_isp_params_awb_config)          | | | |
| | | +---------------------------------------------------------+ | | |
| | | tap_point = ...;                                            | | |
| | | satur_vald = ...;                                           | | |
| | | horiz_zones_num = ...;                                      | | |
| | | vert_zones_num = ...;                                       | | |
| | +-------------------------------------------------------------+ | |
| +-----------------------------------------------------------------+ |
+---------------------------------------------------------------------+
```

---

# V4L2_META_FMT_D4XX ('D4XX')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Intel D4xx UVC Cameras Metadata

<a id="rst-v4l2-meta-fmt-d4xx-d4xx"></a>
<a id="rst-v4l2-meta-fmt-d4xx"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Intel D4xx UVC Cameras Metadata

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

## Description

Intel D4xx (D435, D455 and others) cameras include per-frame metadata in their UVC payload headers, following the Microsoft(R) UVC extension proposal \[[1](<#rst-target-1>)\]. That means, that the private D4XX metadata, following the standard UVC header, is organised in blocks. D4XX cameras implement several standard block types, proposed by Microsoft, and several proprietary ones. Supported standard metadata types are MetadataId_CaptureStats (ID 3), MetadataId_CameraExtrinsics (ID 4), and MetadataId_CameraIntrinsics (ID 5). For their description see \[[1](<#rst-target-1>)\]. This document describes proprietary metadata types, used by D4xx cameras.

V4L2_META_FMT_D4XX buffers follow the metadata buffer layout of V4L2_META_FMT_UVC with the only difference, that it also includes proprietary payload header data. D4xx cameras use bulk transfers and only send one payload per frame, therefore their headers cannot be larger than 255 bytes.

This document implements Intel Configuration version 3 \[[9](<#rst-target-9>)\].

Below are proprietary Microsoft style metadata types, used by D4xx cameras, where all fields are in little endian order:

<!-- tabularcolumns: |p{5.0cm}|p{12.5cm}| -->


<table>
<caption>D4xx metadata</caption>
<thead>
<tr>
<th>


**Field**

</th>
<th>


**Description**

</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">


 *Depth Control*

</td>
</tr>
<tr>
<td>


\__u32 ID

</td>
<td>


0x80000000

</td>
</tr>
<tr>
<td>


\__u32 Size

</td>
<td>


Size in bytes, include ID (all protocol versions: 60)

</td>
</tr>
<tr>
<td>


\__u32 Version

</td>
<td>


Version of this structure. The documentation herein covers versions 1, 2 and 3. The version number will be incremented when new fields are added.

</td>
</tr>
<tr>
<td>


\__u32 Flags

</td>
<td>


A bitmask of flags: see \[[2](<#rst-target-2>)\] below

</td>
</tr>
<tr>
<td>


\__u32 Gain

</td>
<td>


Gain value in internal units, same as the V4L2_CID_GAIN control, used to capture the frame

</td>
</tr>
<tr>
<td>


\__u32 Exposure

</td>
<td>


Exposure time (in microseconds) used to capture the frame

</td>
</tr>
<tr>
<td>


\__u32 Laser power

</td>
<td>


Power of the laser LED 0-360, used for depth measurement

</td>
</tr>
<tr>
<td>


\__u32 AE mode

</td>
<td>


0: manual; 1: automatic exposure

</td>
</tr>
<tr>
<td>


\__u32 Exposure priority

</td>
<td>


Exposure priority value: 0 - constant frame rate

</td>
</tr>
<tr>
<td>


\__u32 AE ROI left

</td>
<td>


Left border of the AE Region of Interest (all ROI values are in pixels and lie between 0 and maximum width or height respectively)

</td>
</tr>
<tr>
<td>


\__u32 AE ROI right

</td>
<td>


Right border of the AE Region of Interest

</td>
</tr>
<tr>
<td>


\__u32 AE ROI top

</td>
<td>


Top border of the AE Region of Interest

</td>
</tr>
<tr>
<td>


\__u32 AE ROI bottom

</td>
<td>


Bottom border of the AE Region of Interest

</td>
</tr>
<tr>
<td>


\__u32 Preset

</td>
<td>


Preset selector value, default: 0, unless changed by the user

</td>
</tr>
<tr>
<td>


\__u8 Emitter mode (v3 only) (\__u32 Laser mode for v1) \[[8](<#rst-target-8>)\]

</td>
<td>


0: off, 1: on, same as \__u32 Laser mode for v1

</td>
</tr>
<tr>
<td>


\__u8 RFU byte (v3 only)

</td>
<td>


Spare byte for future use

</td>
</tr>
<tr>
<td>


\__u16 LED Power (v3 only)

</td>
<td>


Led power value 0-360 (F416 SKU)

</td>
</tr>
<tr>
<td colspan="2">


 *Capture Timing*

</td>
</tr>
<tr>
<td>


\__u32 ID

</td>
<td>


0x80000001

</td>
</tr>
<tr>
<td>


\__u32 Size

</td>
<td>


Size in bytes, include ID (all protocol versions: 40)

</td>
</tr>
<tr>
<td>


\__u32 Version

</td>
<td>


Version of this structure. The documentation herein corresponds to version xxx. The version number will be incremented when new fields are added.

</td>
</tr>
<tr>
<td>


\__u32 Flags

</td>
<td>


A bitmask of flags: see \[[3](<#rst-target-3>)\] below

</td>
</tr>
<tr>
<td>


\__u32 Frame counter

</td>
<td>


Monotonically increasing counter

</td>
</tr>
<tr>
<td>


\__u32 Optical time

</td>
<td>


Time in microseconds from the beginning of a frame till its middle

</td>
</tr>
<tr>
<td>


\__u32 Readout time

</td>
<td>


Time, used to read out a frame in microseconds

</td>
</tr>
<tr>
<td>


\__u32 Exposure time

</td>
<td>


Frame exposure time in microseconds

</td>
</tr>
<tr>
<td>


\__u32 Frame interval

</td>
<td>


In microseconds = 1000000 / framerate

</td>
</tr>
<tr>
<td>


\__u32 Pipe latency

</td>
<td>


Time in microseconds from start of frame to data in USB buffer

</td>
</tr>
<tr>
<td colspan="2">


 *Configuration*

</td>
</tr>
<tr>
<td>


\__u32 ID

</td>
<td>


0x80000002

</td>
</tr>
<tr>
<td>


\__u32 Size

</td>
<td>


Size in bytes, include ID (v1:36, v3:40)

</td>
</tr>
<tr>
<td>


\__u32 Version

</td>
<td>


Version of this structure. The documentation herein corresponds to version xxx. The version number will be incremented when new fields are added.

</td>
</tr>
<tr>
<td>


\__u32 Flags

</td>
<td>


A bitmask of flags: see \[[4](<#rst-target-4>)\] below

</td>
</tr>
<tr>
<td>


\__u8 Hardware type

</td>
<td>


Camera hardware version \[[5](<#rst-target-5>)\]

</td>
</tr>
<tr>
<td>


\__u8 SKU ID

</td>
<td>


Camera hardware configuration \[[6](<#rst-target-6>)\]

</td>
</tr>
<tr>
<td>


\__u32 Cookie

</td>
<td>


Internal synchronisation

</td>
</tr>
<tr>
<td>


\__u16 Format

</td>
<td>


Image format code \[[7](<#rst-target-7>)\]

</td>
</tr>
<tr>
<td>


\__u16 Width

</td>
<td>


Width in pixels

</td>
</tr>
<tr>
<td>


\__u16 Height

</td>
<td>


Height in pixels

</td>
</tr>
<tr>
<td>


\__u16 Framerate

</td>
<td>


Requested frame rate per second

</td>
</tr>
<tr>
<td>


\__u16 Trigger

</td>
<td>


Byte 0: bit 0: depth and RGB are synchronised, bit 1: external trigger

</td>
</tr>
<tr>
<td>


\__u16 Calibration count (v3 only)

</td>
<td>


Calibration counter, see \[[4](<#rst-target-4>)\] below

</td>
</tr>
<tr>
<td>


\__u8 GPIO input data (v3 only)

</td>
<td>


GPIO readout, see \[[4](<#rst-target-4>)\] below (Supported from FW 5.12.7.0)

</td>
</tr>
<tr>
<td>


\__u32 Sub-preset info (v3 only)

</td>
<td>


Sub-preset choice information, see \[[4](<#rst-target-4>)\] below

</td>
</tr>
<tr>
<td>


\__u8 reserved (v3 only)

</td>
<td>


RFU byte.

</td>
</tr>
</tbody>
</table>

<a id="rst-target-1"></a>

\[1\] [https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/uvc-extensions-1-5](<https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/uvc-extensions-1-5>)

<a id="rst-target-2"></a>

\[2\] Depth Control flags specify which fields are valid:



```text
0x00000001 Gain
0x00000002 Exposure
0x00000004 Laser power
0x00000008 AE mode
0x00000010 Exposure priority
0x00000020 AE ROI
0x00000040 Preset
0x00000080 Emitter mode
0x00000100 LED Power
```

<a id="rst-target-3"></a>

\[3\] Capture Timing flags specify which fields are valid:



```text
0x00000001 Frame counter
0x00000002 Optical time
0x00000004 Readout time
0x00000008 Exposure time
0x00000010 Frame interval
0x00000020 Pipe latency
```

<a id="rst-target-4"></a>

\[4\] Configuration flags specify which fields are valid:



```text
0x00000001 Hardware type
0x00000002 SKU ID
0x00000004 Cookie
0x00000008 Format
0x00000010 Width
0x00000020 Height
0x00000040 Framerate
0x00000080 Trigger
0x00000100 Cal count
0x00000200 GPIO Input Data
0x00000400 Sub-preset Info
```

<a id="rst-target-5"></a>

\[5\] Camera model:



```text
0 DS5
1 IVCAM2
```

<a id="rst-target-6"></a>

\[6\] 8-bit camera hardware configuration bitfield:



```text
[1:0] depthCamera
      00: no depth
      01: standard depth
      10: wide depth
      11: reserved
[2]   depthIsActive - has a laser projector
[3]   RGB presence
[4]   Inertial Measurement Unit (IMU) presence
[5]   projectorType
      0: HPTG
      1: Princeton
[6]   0: a projector, 1: an LED
[7]   reserved
```

<a id="rst-target-7"></a>

\[7\] Image format codes per video streaming interface:

Depth:



```text
1 Z16
2 Z
```

Left sensor:



```text
1 Y8
2 UYVY
3 R8L8
4 Calibration
5 W10
```

Fish Eye sensor:



```text
1 RAW8
```

<a id="rst-target-8"></a>

\[8\] The "Laser mode" has been replaced in version 3 by three different fields. "Laser" has been renamed to "Emitter" as there are multiple technologies for camera projectors. As we have another field for "Laser Power" we introduced "LED Power" for extra emitter.

- **The "Laser mode" \__u32 fields has been split into: ::**

  1 \__u8 Emitter mode 2 \__u8 RFU byte 3 \__u16 LED Power

This is a change between versions 1 and 3. All versions 1, 2 and 3 are backward compatible with the same data format and they are supported. See \[[2](<#rst-target-2>)\] for which attributes are valid.

<a id="rst-target-9"></a>

\[9\] LibRealSense SDK metadata source: [https://github.com/IntelRealSense/librealsense/blob/master/src/metadata.h](<https://github.com/IntelRealSense/librealsense/blob/master/src/metadata.h>)

---

# V4L2_META_FMT_GENERIC_8 ('MET8'), V4L2_META_FMT_GENERIC_CSI2_10 ('MC1A'), V4L2_META_FMT_GENERIC_CSI2_12 ('MC1C'), V4L2_META_FMT_GENERIC_CSI2_14 ('MC1E'), V4L2_META_FMT_GENERIC_CSI2_16 ('MC1G'), V4L2_META_FMT_GENERIC_CSI2_20 ('MC1K'), V4L2_META_FMT_GENERIC_CSI2_24 ('MC1O')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Generic line-based metadata formats

<a id="rst-v4l2-meta-fmt-generic-8-met8-v4l2-meta-fmt-generic-csi2-10-mc1a-v4l2-meta-fmt-generic-csi2-12-mc1c-v4l2-meta-fmt-generic-csi2-14-mc1e-v4l2-meta-fmt-generic-csi2-16-mc1g-v4l2-meta-fmt-generic-csi2-20-mc1k-v4l2-meta-fmt-generic-csi2-24-mc1o"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Generic line-based metadata formats

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

## Description

These generic line-based metadata formats define the memory layout of the data without defining the format or meaning of the metadata itself.

<a id="rst-v4l2-meta-fmt-generic-8-1"></a>
<a id="rst-v4l2-meta-fmt-generic-8"></a>

### V4L2\_META\_FMT\_GENERIC\_8

The V4L2\_META\_FMT\_GENERIC\_8 format is a plain 8-bit metadata format. This format is used on CSI-2 for 8 bits per [Data Unit](</kernel/userspace/userspace-api/media/glossary.md#rst-term-data-unit>).

Additionally it is used for 16 bits per Data Unit when two bytes of metadata are packed into one 16-bit Data Unit. Otherwise the 16 bits per pixel dataformat is [V4L2\_META\_FMT\_GENERIC\_CSI2\_16](<#rst-v4l2-meta-fmt-generic-csi2-16>).

<strong>Byte Order Of V4L2\_META\_FMT\_GENERIC\_8.</strong> Each cell is one byte. "M" denotes a byte of metadata.

<!-- tabularcolumns: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}| -->


<table>
<caption>

Sample 4x2 Metadata Frame

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



M<sub>00</sub>

</td>
<td>



M<sub>10</sub>

</td>
<td>



M<sub>20</sub>

</td>
<td>



M<sub>30</sub>

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



M<sub>01</sub>

</td>
<td>



M<sub>11</sub>

</td>
<td>



M<sub>21</sub>

</td>
<td>



M<sub>31</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-meta-fmt-generic-csi2-10-1"></a>
<a id="rst-v4l2-meta-fmt-generic-csi2-10"></a>

### V4L2\_META\_FMT\_GENERIC\_CSI2\_10

V4L2\_META\_FMT\_GENERIC\_CSI2\_10 contains 8-bit generic metadata packed in 10-bit Data Units, with one padding byte after every four bytes of metadata. This format is typically used by CSI-2 receivers with a source that transmits MEDIA\_BUS\_FMT\_META\_10 and the CSI-2 receiver writes the received data to memory as-is.

The packing of the data follows the MIPI CSI-2 specification and the padding of the data is defined in the MIPI CCS specification.

This format is also used in conjunction with 20 bits per [Data Unit](</kernel/userspace/userspace-api/media/glossary.md#rst-term-data-unit>) formats that pack two bytes of metadata into one Data Unit. Otherwise the 20 bits per pixel dataformat is [V4L2\_META\_FMT\_GENERIC\_CSI2\_20](<#rst-v4l2-meta-fmt-generic-csi2-20>).

This format is little endian.

<strong>Byte Order Of V4L2\_META\_FMT\_GENERIC\_CSI2\_10.</strong> Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding.

<!-- tabularcolumns: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.8cm}| -->


<table>
<caption>

Sample 4x2 Metadata Frame

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



M<sub>00</sub>

</td>
<td>



M<sub>10</sub>

</td>
<td>



M<sub>20</sub>

</td>
<td>



M<sub>30</sub>

</td>
<td>



x

</td>
</tr>
<tr>
<td>



start + 5:

</td>
<td>



M<sub>01</sub>

</td>
<td>



M<sub>11</sub>

</td>
<td>



M<sub>21</sub>

</td>
<td>



M<sub>31</sub>

</td>
<td>



x

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-meta-fmt-generic-csi2-12-1"></a>
<a id="rst-v4l2-meta-fmt-generic-csi2-12"></a>

### V4L2\_META\_FMT\_GENERIC\_CSI2\_12

V4L2\_META\_FMT\_GENERIC\_CSI2\_12 contains 8-bit generic metadata packed in 12-bit Data Units, with one padding byte after every two bytes of metadata. This format is typically used by CSI-2 receivers with a source that transmits MEDIA\_BUS\_FMT\_META\_12 and the CSI-2 receiver writes the received data to memory as-is.

The packing of the data follows the MIPI CSI-2 specification and the padding of the data is defined in the MIPI CCS specification.

This format is also used in conjunction with 24 bits per [Data Unit](</kernel/userspace/userspace-api/media/glossary.md#rst-term-data-unit>) formats that pack two bytes of metadata into one Data Unit. Otherwise the 24 bits per pixel dataformat is [V4L2\_META\_FMT\_GENERIC\_CSI2\_24](<#rst-v4l2-meta-fmt-generic-csi2-24>).

This format is little endian.

<strong>Byte Order Of V4L2\_META\_FMT\_GENERIC\_CSI2\_12.</strong> Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding.

<!-- tabularcolumns: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.8cm}|p{1.2cm}|p{1.2cm}|p{1.8cm}| -->


<table>
<caption>

Sample 4x2 Metadata Frame

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



M<sub>00</sub>

</td>
<td>



M<sub>10</sub>

</td>
<td>



x

</td>
<td>



M<sub>20</sub>

</td>
<td>



M<sub>30</sub>

</td>
<td>



x

</td>
</tr>
<tr>
<td>



start + 6:

</td>
<td>



M<sub>01</sub>

</td>
<td>



M<sub>11</sub>

</td>
<td>



x

</td>
<td>



M<sub>21</sub>

</td>
<td>



M<sub>31</sub>

</td>
<td>



x

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-meta-fmt-generic-csi2-14-1"></a>
<a id="rst-v4l2-meta-fmt-generic-csi2-14"></a>

### V4L2\_META\_FMT\_GENERIC\_CSI2\_14

V4L2\_META\_FMT\_GENERIC\_CSI2\_14 contains 8-bit generic metadata packed in 14-bit Data Units, with three padding bytes after every four bytes of metadata. This format is typically used by CSI-2 receivers with a source that transmits MEDIA\_BUS\_FMT\_META\_14 and the CSI-2 receiver writes the received data to memory as-is.

The packing of the data follows the MIPI CSI-2 specification and the padding of the data is defined in the MIPI CCS specification.

This format is little endian.

<strong>Byte Order Of V4L2\_META\_FMT\_GENERIC\_CSI2\_14.</strong> Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding.

<!-- tabularcolumns: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.8cm}|p{1.8cm}|p{1.8cm}| -->


<table>
<caption>

Sample 4x2 Metadata Frame

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



M<sub>00</sub>

</td>
<td>



M<sub>10</sub>

</td>
<td>



M<sub>20</sub>

</td>
<td>



M<sub>30</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
</tr>
<tr>
<td>



start + 7:

</td>
<td>



M<sub>01</sub>

</td>
<td>



M<sub>11</sub>

</td>
<td>



M<sub>21</sub>

</td>
<td>



M<sub>31</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-meta-fmt-generic-csi2-16-1"></a>
<a id="rst-v4l2-meta-fmt-generic-csi2-16"></a>

### V4L2\_META\_FMT\_GENERIC\_CSI2\_16

V4L2\_META\_FMT\_GENERIC\_CSI2\_16 contains 8-bit generic metadata packed in 16-bit Data Units, with one padding byte after every byte of metadata. This format is typically used by CSI-2 receivers with a source that transmits MEDIA\_BUS\_FMT\_META\_16 and the CSI-2 receiver writes the received data to memory as-is.

The packing of the data follows the MIPI CSI-2 specification and the padding of the data is defined in the MIPI CCS specification.

Some devices support more efficient packing of metadata in conjunction with 16-bit image data. In that case the dataformat is [V4L2\_META\_FMT\_GENERIC\_8](<#rst-v4l2-meta-fmt-generic-8>).

This format is little endian.

<strong>Byte Order Of V4L2\_META\_FMT\_GENERIC\_CSI2\_16.</strong> Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding.

<!-- tabularcolumns: |p{2.4cm}|p{1.2cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{1.2cm}|p{.8cm}| -->


<table>
<caption>

Sample 4x2 Metadata Frame

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



M<sub>00</sub>

</td>
<td>



x

</td>
<td>



M<sub>10</sub>

</td>
<td>



x

</td>
<td>



M<sub>20</sub>

</td>
<td>



x

</td>
<td>



M<sub>30</sub>

</td>
<td>



x

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



M<sub>01</sub>

</td>
<td>



x

</td>
<td>



M<sub>11</sub>

</td>
<td>



x

</td>
<td>



M<sub>21</sub>

</td>
<td>



x

</td>
<td>



M<sub>31</sub>

</td>
<td>



x

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-meta-fmt-generic-csi2-20-1"></a>
<a id="rst-v4l2-meta-fmt-generic-csi2-20"></a>

### V4L2\_META\_FMT\_GENERIC\_CSI2\_20

V4L2\_META\_FMT\_GENERIC\_CSI2\_20 contains 8-bit generic metadata packed in 20-bit Data Units, with alternating one or two padding bytes after every byte of metadata. This format is typically used by CSI-2 receivers with a source that transmits MEDIA\_BUS\_FMT\_META\_20 and the CSI-2 receiver writes the received data to memory as-is.

The packing of the data follows the MIPI CSI-2 specification and the padding of the data is defined in the MIPI CCS specification.

Some devices support more efficient packing of metadata in conjunction with 16-bit image data. In that case the dataformat is [V4L2\_META\_FMT\_GENERIC\_CSI2\_10](<#rst-v4l2-meta-fmt-generic-csi2-10>).

This format is little endian.

<strong>Byte Order Of V4L2\_META\_FMT\_GENERIC\_CSI2\_20.</strong> Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding.

<!-- tabularcolumns: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.8cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.8cm} -->


<table>
<caption>

Sample 4x2 Metadata Frame

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



M<sub>00</sub>

</td>
<td>



x

</td>
<td>



M<sub>10</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



M<sub>20</sub>

</td>
<td>



x

</td>
<td>



M<sub>30</sub>

</td>
<td>



x

</td>
<td>



x

</td>
</tr>
<tr>
<td>



start + 10:

</td>
<td>



M<sub>01</sub>

</td>
<td>



x

</td>
<td>



M<sub>11</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



M<sub>21</sub>

</td>
<td>



x

</td>
<td>



M<sub>31</sub>

</td>
<td>



x

</td>
<td>



x

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-meta-fmt-generic-csi2-24-1"></a>
<a id="rst-v4l2-meta-fmt-generic-csi2-24"></a>

### V4L2\_META\_FMT\_GENERIC\_CSI2\_24

V4L2\_META\_FMT\_GENERIC\_CSI2\_24 contains 8-bit generic metadata packed in 24-bit Data Units, with two padding bytes after every byte of metadata. This format is typically used by CSI-2 receivers with a source that transmits MEDIA\_BUS\_FMT\_META\_24 and the CSI-2 receiver writes the received data to memory as-is.

The packing of the data follows the MIPI CSI-2 specification and the padding of the data is defined in the MIPI CCS specification.

Some devices support more efficient packing of metadata in conjunction with 16-bit image data. In that case the dataformat is [V4L2\_META\_FMT\_GENERIC\_CSI2\_12](<#rst-v4l2-meta-fmt-generic-csi2-12>).

This format is little endian.

<strong>Byte Order Of V4L2\_META\_FMT\_GENERIC\_CSI2\_24.</strong> Each cell is one byte. "M" denotes a byte of metadata and "x" a byte of padding.

<!-- tabularcolumns: |p{2.4cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}| -->


<table>
<caption>

Sample 4x2 Metadata Frame

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



M<sub>00</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



M<sub>10</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



M<sub>20</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



M<sub>30</sub>

</td>
<td>



x

</td>
<td>



x

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



M<sub>01</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



M<sub>11</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



M<sub>21</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



M<sub>31</sub>

</td>
<td>



x

</td>
<td>



x

</td>
</tr>
</tbody>
</table>

---

# V4L2_META_FMT_IPU3_PARAMS ('ip3p'), V4L2_META_FMT_IPU3_3A ('ip3s')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The IPU3 ImgU 3A statistics accelerators collect different statistics over an input Bayer frame. Those statistics are obtained from the "ipu3-imgu [01] 3a stat" metadata capture video nodes, using the v4l2_meta_format interface. They are…

<a id="rst-v4l2-meta-fmt-ipu3-params-ip3p-v4l2-meta-fmt-ipu3-3a-ip3s"></a>
<a id="rst-v4l2-meta-fmt-stat-3a"></a>
<a id="rst-v4l2-meta-fmt-params"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<!-- ipu3_uapi_stats_3a -->

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

## 3A statistics

The IPU3 ImgU 3A statistics accelerators collect different statistics over an input Bayer frame. Those statistics are obtained from the "ipu3-imgu \[01\] 3a stat" metadata capture video nodes, using the `v4l2_meta_format` interface. They are formatted as described by the `ipu3_uapi_stats_3a` structure.

The statistics collected are AWB (Auto-white balance) RGBS (Red, Green, Blue and Saturation measure) cells, AWB filter response, AF (Auto-focus) filter response, and AE (Auto-exposure) histogram.

The struct `ipu3_uapi_4a_config` saves all configurable parameters.



```c
struct ipu3_uapi_stats_3a {
        struct ipu3_uapi_awb_raw_buffer awb_raw_buffer;
        struct ipu3_uapi_ae_raw_buffer_aligned ae_raw_buffer[IPU3_UAPI_MAX_STRIPES];
        struct ipu3_uapi_af_raw_buffer af_raw_buffer;
        struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer;
        struct ipu3_uapi_4a_config stats_4a_config;
        __u32 ae_join_buffers;
        __u8 padding[28];
        struct ipu3_uapi_stats_3a_bubble_info_per_stripe stats_3a_bubble_per_stripe;
        struct ipu3_uapi_ff_status stats_3a_status;
};
```

<!-- ipu3_uapi_params -->

<a id="rst-pipeline-parameters"></a>

## Pipeline parameters

The pipeline parameters are passed to the "ipu3-imgu \[01\] parameters" metadata output video nodes, using the `v4l2_meta_format` interface. They are formatted as described by the `ipu3_uapi_params` structure.

Both 3A statistics and pipeline parameters described here are closely tied to the underlying camera sub-system (CSS) APIs. They are usually consumed and produced by dedicated user space libraries that comprise the important tuning tools, thus freeing the developers from being bothered with the low level hardware and algorithm details.



```c
struct ipu3_uapi_params {
        /* Flags which of the settings below are to be applied */
        struct ipu3_uapi_flags use;

        /* Accelerator cluster parameters */
        struct ipu3_uapi_acc_param acc_param;

        /* ISP vector address space parameters */
        struct ipu3_uapi_isp_lin_vmem_params lin_vmem_params;
        struct ipu3_uapi_isp_tnr3_vmem_params tnr3_vmem_params;
        struct ipu3_uapi_isp_xnr3_vmem_params xnr3_vmem_params;

        /* ISP data memory (DMEM) parameters */
        struct ipu3_uapi_isp_tnr3_params tnr3_dmem_params;
        struct ipu3_uapi_isp_xnr3_params xnr3_dmem_params;

        /* Optical black level compensation */
        struct ipu3_uapi_obgrid_param obgrid_param;
};
```

<a id="rst-intel-ipu3-imgu-uapi-data-types"></a>

## Intel IPU3 ImgU uAPI data types


#### <a id="c-struct-ipu3_uapi_grid_config"></a>`struct ipu3_uapi_grid_config`

Grid plane config

**Definition**

```c
struct ipu3_uapi_grid_config {
    __u8 width;
    __u8 height;
    __u16 block_width_log2:3;
    __u16 block_height_log2:3;
    __u16 height_per_slice:8;
    __u16 x_start;
    __u16 y_start;
    __u16 x_end;
    __u16 y_end;
};
```

**Members**

- `width`: Grid horizontal dimensions, in number of grid blocks(cells).
  For AWB, the range is (16, 80).
  For AF/AE, the range is (16, 32).
- `height`: Grid vertical dimensions, in number of grid cells.
  For AWB, the range is (16, 60).
  For AF/AE, the range is (16, 24).
- `block_width_log2`: Log2 of the width of each cell in pixels.
  For AWB, the range is \[3, 6\].
  For AF/AE, the range is \[3, 7\].
- `block_height_log2`: Log2 of the height of each cell in pixels.
  For AWB, the range is \[3, 6\].
  For AF/AE, the range is \[3, 7\].
- `height_per_slice`: The number of blocks in vertical axis per slice.
  Default 2.
- `x_start`: X value of top left corner of Region of Interest(ROI).
- `y_start`: Y value of top left corner of ROI
- `x_end`: X value of bottom right corner of ROI
- `y_end`: Y value of bottom right corner of ROI

**Description**

Due to the size of total amount of collected data, most statistics
create a grid-based output, and the data is then divided into "slices".

#### <a id="c-struct-ipu3_uapi_awb_set_item"></a>`struct ipu3_uapi_awb_set_item`

Memory layout for each cell in AWB

**Definition**

```c
struct ipu3_uapi_awb_set_item {
    __u8 Gr_avg;
    __u8 R_avg;
    __u8 B_avg;
    __u8 Gb_avg;
    __u8 sat_ratio;
    __u8 padding0;
    __u8 padding1;
    __u8 padding2;
};
```

**Members**

- `Gr_avg`: Green average for red lines in the cell.
- `R_avg`: Red average in the cell.
- `B_avg`: Blue average in the cell.
- `Gb_avg`: Green average for blue lines in the cell.
- `sat_ratio`: Percentage of pixels over the thresholds specified in
  ipu3_uapi_awb_config_s, coded from 0 to 255.
- `padding0`: Unused byte for padding.
- `padding1`: Unused byte for padding.
- `padding2`: Unused byte for padding.

#### <a id="c-struct-ipu3_uapi_awb_raw_buffer"></a>`struct ipu3_uapi_awb_raw_buffer`

AWB raw buffer

**Definition**

```c
struct ipu3_uapi_awb_raw_buffer {
    struct ipu3_uapi_awb_set_item meta_data[IPU3_UAPI_AWB_MAX_BUFFER_SIZE]  ;
};
```

**Members**

- `meta_data`: buffer to hold auto white balance meta data which is
  the average values for each color channel.

#### <a id="c-struct-ipu3_uapi_awb_config_s"></a>`struct ipu3_uapi_awb_config_s`

AWB config

**Definition**

```c
struct ipu3_uapi_awb_config_s {
    __u16 rgbs_thr_gr;
    __u16 rgbs_thr_r;
    __u16 rgbs_thr_gb;
    __u16 rgbs_thr_b;
    struct ipu3_uapi_grid_config grid;
};
```

**Members**

- `rgbs_thr_gr`: gr threshold value.
- `rgbs_thr_r`: Red threshold value.
- `rgbs_thr_gb`: gb threshold value.
- `rgbs_thr_b`: Blue threshold value.
- `grid`: [`ipu3_uapi_grid_config`](#c-struct-ipu3_uapi_grid_config), the default grid resolution is 16x16 cells.

**Description**

The threshold is a saturation measure range \[0, 8191\], 8191 is default.
Values over threshold may be optionally rejected for averaging.

#### <a id="c-struct-ipu3_uapi_awb_config"></a>`struct ipu3_uapi_awb_config`

AWB config wrapper

**Definition**

```c
struct ipu3_uapi_awb_config {
    struct ipu3_uapi_awb_config_s config  ;
};
```

**Members**

- `config`: config for auto white balance as defined by [`ipu3_uapi_awb_config_s`](#c-struct-ipu3_uapi_awb_config_s)

#### <a id="c-struct-ipu3_uapi_ae_raw_buffer"></a>`struct ipu3_uapi_ae_raw_buffer`

AE global weighted histogram

**Definition**

```c
struct ipu3_uapi_ae_raw_buffer {
    __u32 vals[IPU3_UAPI_AE_BINS * IPU3_UAPI_AE_COLORS];
};
```

**Members**

- `vals`: Sum of IPU3_UAPI_AE_COLORS in cell

**Description**

Each histogram contains IPU3_UAPI_AE_BINS bins. Each bin has 24 bit unsigned
for counting the number of the pixel.

#### <a id="c-struct-ipu3_uapi_ae_raw_buffer_aligned"></a>`struct ipu3_uapi_ae_raw_buffer_aligned`

AE raw buffer

**Definition**

```c
struct ipu3_uapi_ae_raw_buffer_aligned {
    struct ipu3_uapi_ae_raw_buffer buff  ;
};
```

**Members**

- `buff`: [`ipu3_uapi_ae_raw_buffer`](#c-struct-ipu3_uapi_ae_raw_buffer) to hold full frame meta data.

#### <a id="c-struct-ipu3_uapi_ae_grid_config"></a>`struct ipu3_uapi_ae_grid_config`

AE weight grid

**Definition**

```c
struct ipu3_uapi_ae_grid_config {
    __u8 width;
    __u8 height;
    __u8 block_width_log2:4;
    __u8 block_height_log2:4;
    __u8 reserved0:5;
    __u8 ae_en:1;
    __u8 rst_hist_array:1;
    __u8 done_rst_hist_array:1;
    __u16 x_start;
    __u16 y_start;
    __u16 x_end;
    __u16 y_end;
};
```

**Members**

- `width`: Grid horizontal dimensions. Value: \[16, 32\], default 16.
- `height`: Grid vertical dimensions. Value: \[16, 24\], default 16.
- `block_width_log2`: Log2 of the width of the grid cell, value: \[3, 7\].
- `block_height_log2`: Log2 of the height of the grid cell, value: \[3, 7\].
  default is 3 (cell size 8x8), 4 cell per grid.
- `reserved0`: reserved
- `ae_en`: 0: does not write to [`ipu3_uapi_ae_raw_buffer_aligned`](#c-struct-ipu3_uapi_ae_raw_buffer_aligned) array,
  1: write normally.
- `rst_hist_array`: write 1 to trigger histogram array reset.
- `done_rst_hist_array`: flag for histogram array reset done.
- `x_start`: X value of top left corner of ROI, default 0.
- `y_start`: Y value of top left corner of ROI, default 0.
- `x_end`: X value of bottom right corner of ROI
- `y_end`: Y value of bottom right corner of ROI

**Description**

The AE block accumulates 4 global weighted histograms(R, G, B, Y) over
a defined ROI within the frame. The contribution of each pixel into the
histogram, defined by [`ipu3_uapi_ae_weight_elem`](#c-struct-ipu3_uapi_ae_weight_elem) LUT, is indexed by a grid.

#### <a id="c-struct-ipu3_uapi_ae_weight_elem"></a>`struct ipu3_uapi_ae_weight_elem`

AE weights LUT

**Definition**

```c
struct ipu3_uapi_ae_weight_elem {
    __u32 cell0:4;
    __u32 cell1:4;
    __u32 cell2:4;
    __u32 cell3:4;
    __u32 cell4:4;
    __u32 cell5:4;
    __u32 cell6:4;
    __u32 cell7:4;
};
```

**Members**

- `cell0`: weighted histogram grid value.
- `cell1`: weighted histogram grid value.
- `cell2`: weighted histogram grid value.
- `cell3`: weighted histogram grid value.
- `cell4`: weighted histogram grid value.
- `cell5`: weighted histogram grid value.
- `cell6`: weighted histogram grid value.
- `cell7`: weighted histogram grid value.

**Description**

Use weighted grid value to give a different contribution factor to each cell.
Precision u4, range \[0, 15\].

#### <a id="c-struct-ipu3_uapi_ae_ccm"></a>`struct ipu3_uapi_ae_ccm`

AE coefficients for WB and CCM

**Definition**

```c
struct ipu3_uapi_ae_ccm {
    __u16 gain_gr;
    __u16 gain_r;
    __u16 gain_b;
    __u16 gain_gb;
    __s16 mat[16];
};
```

**Members**

- `gain_gr`: WB gain factor for the gr channels. Default 256.
- `gain_r`: WB gain factor for the r channel. Default 256.
- `gain_b`: WB gain factor for the b channel. Default 256.
- `gain_gb`: WB gain factor for the gb channels. Default 256.
- `mat`: 4x4 matrix that transforms Bayer quad output from WB to RGB+Y.

**Description**

- Default:
  128, 0, 0, 0,
  0, 128, 0, 0,
  0, 0, 128, 0,
  0, 0, 0, 128,

As part of the raw frame pre-process stage, the WB and color conversion need
to be applied to expose the impact of these gain operations.

#### <a id="c-struct-ipu3_uapi_ae_config"></a>`struct ipu3_uapi_ae_config`

AE config

**Definition**

```c
struct ipu3_uapi_ae_config {
    struct ipu3_uapi_ae_grid_config grid_cfg  ;
    struct ipu3_uapi_ae_weight_elem weights[IPU3_UAPI_AE_WEIGHTS]  ;
    struct ipu3_uapi_ae_ccm ae_ccm  ;
};
```

**Members**

- `grid_cfg`: config for auto exposure statistics grid. See struct
  [`ipu3_uapi_ae_grid_config`](#c-struct-ipu3_uapi_ae_grid_config), as Imgu did not support output
  auto exposure statistics, so user can ignore this configuration
  and use the RGB table in auto-whitebalance statistics instead.
- `weights`: `IPU3_UAPI_AE_WEIGHTS` is based on 32x24 blocks in the grid.
  Each grid cell has a corresponding value in weights LUT called
  grid value, global histogram is updated based on grid value and
  pixel value.
- `ae_ccm`: Color convert matrix pre-processing block.

**Description**

Calculate AE grid from image resolution, resample ae weights.

#### <a id="c-struct-ipu3_uapi_af_filter_config"></a>`struct ipu3_uapi_af_filter_config`

AF 2D filter for contrast measurements

**Definition**

```c
struct ipu3_uapi_af_filter_config {
    struct {
        __u8 a1;
        __u8 a2;
        __u8 a3;
        __u8 a4;
    } y1_coeff_0;
    struct {
        __u8 a5;
        __u8 a6;
        __u8 a7;
        __u8 a8;
    } y1_coeff_1;
    struct {
        __u8 a9;
        __u8 a10;
        __u8 a11;
        __u8 a12;
    } y1_coeff_2;
    __u32 y1_sign_vec;
    struct {
        __u8 a1;
        __u8 a2;
        __u8 a3;
        __u8 a4;
    } y2_coeff_0;
    struct {
        __u8 a5;
        __u8 a6;
        __u8 a7;
        __u8 a8;
    } y2_coeff_1;
    struct {
        __u8 a9;
        __u8 a10;
        __u8 a11;
        __u8 a12;
    } y2_coeff_2;
    __u32 y2_sign_vec;
    struct {
        __u8 y_gen_rate_gr;
        __u8 y_gen_rate_r;
        __u8 y_gen_rate_b;
        __u8 y_gen_rate_gb;
    } y_calc;
    struct {
        __u32 reserved0:8;
        __u32 y1_nf:4;
        __u32 reserved1:4;
        __u32 y2_nf:4;
        __u32 reserved2:12;
    } nf;
};
```

**Members**

- `y1_coeff_0`: filter Y1, structure: 3x11, support both symmetry and
  anti-symmetry type. A12 is center, A1-A11 are neighbours.
  for analyzing low frequency content, used to calculate sum
  of gradients in x direction.
- `y1_coeff_0.a1`: filter1 coefficients A1, u8, default 0.
- `y1_coeff_0.a2`: filter1 coefficients A2, u8, default 0.
- `y1_coeff_0.a3`: filter1 coefficients A3, u8, default 0.
- `y1_coeff_0.a4`: filter1 coefficients A4, u8, default 0.
- `y1_coeff_1`: Struct
- `y1_coeff_1.a5`: filter1 coefficients A5, u8, default 0.
- `y1_coeff_1.a6`: filter1 coefficients A6, u8, default 0.
- `y1_coeff_1.a7`: filter1 coefficients A7, u8, default 0.
- `y1_coeff_1.a8`: filter1 coefficients A8, u8, default 0.
- `y1_coeff_2`: Struct
- `y1_coeff_2.a9`: filter1 coefficients A9, u8, default 0.
- `y1_coeff_2.a10`: filter1 coefficients A10, u8, default 0.
- `y1_coeff_2.a11`: filter1 coefficients A11, u8, default 0.
- `y1_coeff_2.a12`: filter1 coefficients A12, u8, default 128.
- `y1_sign_vec`: Each bit corresponds to one coefficient sign bit,
  0: positive, 1: negative, default 0.
- `y2_coeff_0`: Y2, same structure as Y1. For analyzing high frequency content.
- `y2_coeff_0.a1`: filter2 coefficients A1, u8, default 0.
- `y2_coeff_0.a2`: filter2 coefficients A2, u8, default 0.
- `y2_coeff_0.a3`: filter2 coefficients A3, u8, default 0.
- `y2_coeff_0.a4`: filter2 coefficients A4, u8, default 0.
- `y2_coeff_1`: Struct
- `y2_coeff_1.a5`: filter2 coefficients A5, u8, default 0.
- `y2_coeff_1.a6`: filter2 coefficients A6, u8, default 0.
- `y2_coeff_1.a7`: filter2 coefficients A7, u8, default 0.
- `y2_coeff_1.a8`: filter2 coefficients A8, u8, default 0.
- `y2_coeff_2`: Struct
- `y2_coeff_2.a9`: filter1 coefficients A9, u8, default 0.
- `y2_coeff_2.a10`: filter1 coefficients A10, u8, default 0.
- `y2_coeff_2.a11`: filter1 coefficients A11, u8, default 0.
- `y2_coeff_2.a12`: filter1 coefficients A12, u8, default 128.
- `y2_sign_vec`: Each bit corresponds to one coefficient sign bit,
  0: positive, 1: negative, default 0.
- `y_calc`: Pre-processing that converts Bayer quad to RGB+Y values to be
  used for building histogram. Range \[0, 32\], default 8.
- `y_calc.y_gen_rate_gr`: Contribution ratio Gr for Y
- `y_calc.y_gen_rate_r`: Contribution ratio R for Y
- `y_calc.y_gen_rate_b`: Contribution ratio B for Y
- `y_calc.y_gen_rate_gb`: Contribution ratio Gb for Y
- `nf`: The shift right value that should be applied during the Y1/Y2 filter to
  make sure the total memory needed is 2 bytes per grid cell.
- `nf.reserved0`: reserved
- `nf.y1_nf`: Normalization factor for the convolution coeffs of y1,
  should be log2 of the sum of the abs values of the filter
  coeffs, default 7 (2^7 = 128).
- `nf.reserved1`: reserved
- `nf.y2_nf`: Normalization factor for y2, should be log2 of the sum of the
  abs values of the filter coeffs.
- `nf.reserved2`: reserved

**Description**

Rule:
y_gen_rate_gr + y_gen_rate_r + y_gen_rate_b + y_gen_rate_gb = 32
A single Y is calculated based on sum of Gr/R/B/Gb based on
their contribution ratio.

#### <a id="c-struct-ipu3_uapi_af_raw_buffer"></a>`struct ipu3_uapi_af_raw_buffer`

AF meta data

**Definition**

```c
struct ipu3_uapi_af_raw_buffer {
    __u8 y_table[IPU3_UAPI_AF_Y_TABLE_MAX_SIZE]  ;
};
```

**Members**

- `y_table`: Each color component will be convolved separately with filter1
  and filter2 and the result will be summed out and averaged for
  each cell.

#### <a id="c-struct-ipu3_uapi_af_config_s"></a>`struct ipu3_uapi_af_config_s`

AF config

**Definition**

```c
struct ipu3_uapi_af_config_s {
    struct ipu3_uapi_af_filter_config filter_config  ;
    __u8 padding[4];
    struct ipu3_uapi_grid_config grid_cfg  ;
};
```

**Members**

- `filter_config`: AF uses Y1 and Y2 filters as configured in
  [`ipu3_uapi_af_filter_config`](#c-struct-ipu3_uapi_af_filter_config)
- `padding`: paddings
- `grid_cfg`: See [`ipu3_uapi_grid_config`](#c-struct-ipu3_uapi_grid_config), default resolution 16x16. Use large
  grid size for large image and vice versa.

#### <a id="c-struct-ipu3_uapi_awb_fr_raw_buffer"></a>`struct ipu3_uapi_awb_fr_raw_buffer`

AWB filter response meta data

**Definition**

```c
struct ipu3_uapi_awb_fr_raw_buffer {
    __u8 meta_data[IPU3_UAPI_AWB_FR_BAYER_TABLE_MAX_SIZE]  ;
};
```

**Members**

- `meta_data`: Statistics output on the grid after convolving with 1D filter.

#### <a id="c-struct-ipu3_uapi_awb_fr_config_s"></a>`struct ipu3_uapi_awb_fr_config_s`

AWB filter response config

**Definition**

```c
struct ipu3_uapi_awb_fr_config_s {
    struct ipu3_uapi_grid_config grid_cfg;
    __u8 bayer_coeff[6];
    __u16 reserved1;
    __u32 bayer_sign;
    __u8 bayer_nf;
    __u8 reserved2[7];
};
```

**Members**

- `grid_cfg`: grid config, default 16x16.
- `bayer_coeff`: 1D Filter 1x11 center symmetry/anti-symmetry.
  coefficients defaults { 0, 0, 0, 0, 0, 128 }.
  Applied on whole image for each Bayer channel separately
  by a weighted sum of its 11x1 neighbors.
- `reserved1`: reserved
- `bayer_sign`: sign of filter coefficients, default 0.
- `bayer_nf`: normalization factor for the convolution coeffs, to make sure
  total memory needed is within pre-determined range.
  NF should be the log2 of the sum of the abs values of the
  filter coeffs, range \[7, 14\], default 7.
- `reserved2`: reserved

#### <a id="c-struct-ipu3_uapi_4a_config"></a>`struct ipu3_uapi_4a_config`

4A config

**Definition**

```c
struct ipu3_uapi_4a_config {
    struct ipu3_uapi_awb_config_s awb_config  ;
    struct ipu3_uapi_ae_grid_config ae_grd_config;
    __u8 padding[20];
    struct ipu3_uapi_af_config_s af_config;
    struct ipu3_uapi_awb_fr_config_s awb_fr_config  ;
};
```

**Members**

- `awb_config`: [`ipu3_uapi_awb_config_s`](#c-struct-ipu3_uapi_awb_config_s), default resolution 16x16
- `ae_grd_config`: auto exposure statistics [`ipu3_uapi_ae_grid_config`](#c-struct-ipu3_uapi_ae_grid_config)
- `padding`: paddings
- `af_config`: auto focus config [`ipu3_uapi_af_config_s`](#c-struct-ipu3_uapi_af_config_s)
- `awb_fr_config`: [`ipu3_uapi_awb_fr_config_s`](#c-struct-ipu3_uapi_awb_fr_config_s), default resolution 16x16

#### <a id="c-struct-ipu3_uapi_bubble_info"></a>`struct ipu3_uapi_bubble_info`

Bubble info for host side debugging

**Definition**

```c
struct ipu3_uapi_bubble_info {
    __u32 num_of_stripes  ;
    __u8 padding[28];
    __u32 num_sets;
    __u8 padding1[28];
    __u32 size_of_set;
    __u8 padding2[28];
    __u32 bubble_size;
    __u8 padding3[28];
};
```

**Members**

- `num_of_stripes`: A single frame is divided into several parts called stripes
  due to limitation on line buffer memory.
  The separation between the stripes is vertical. Each such
  stripe is processed as a single frame by the ISP pipe.
- `padding`: padding bytes.
- `num_sets`: number of sets.
- `padding1`: padding bytes.
- `size_of_set`: set size.
- `padding2`: padding bytes.
- `bubble_size`: is the amount of padding in the bubble expressed in "sets".
- `padding3`: padding bytes.

#### <a id="c-struct-ipu3_uapi_ff_status"></a>`struct ipu3_uapi_ff_status`

Enable bits for each 3A fixed function

**Definition**

```c
struct ipu3_uapi_ff_status {
    __u32 awb_en  ;
    __u8 padding[28];
    __u32 ae_en;
    __u8 padding1[28];
    __u32 af_en;
    __u8 padding2[28];
    __u32 awb_fr_en;
    __u8 padding3[28];
};
```

**Members**

- `awb_en`: auto white balance enable
- `padding`: padding config
- `ae_en`: auto exposure enable
- `padding1`: padding config
- `af_en`: auto focus enable
- `padding2`: padding config
- `awb_fr_en`: awb filter response enable bit
- `padding3`: padding config

#### <a id="c-struct-ipu3_uapi_stats_3a"></a>`struct ipu3_uapi_stats_3a`

3A statistics

**Definition**

```c
struct ipu3_uapi_stats_3a {
    struct ipu3_uapi_awb_raw_buffer awb_raw_buffer;
    struct ipu3_uapi_ae_raw_buffer_aligned ae_raw_buffer[IPU3_UAPI_MAX_STRIPES];
    struct ipu3_uapi_af_raw_buffer af_raw_buffer;
    struct ipu3_uapi_awb_fr_raw_buffer awb_fr_raw_buffer;
    struct ipu3_uapi_4a_config stats_4a_config;
    __u32 ae_join_buffers;
    __u8 padding[28];
    struct ipu3_uapi_stats_3a_bubble_info_per_stripe stats_3a_bubble_per_stripe;
    struct ipu3_uapi_ff_status stats_3a_status;
};
```

**Members**

- `awb_raw_buffer`: auto white balance meta data [`ipu3_uapi_awb_raw_buffer`](#c-struct-ipu3_uapi_awb_raw_buffer)
- `ae_raw_buffer`: auto exposure raw data [`ipu3_uapi_ae_raw_buffer_aligned`](#c-struct-ipu3_uapi_ae_raw_buffer_aligned)
  current Imgu does not output the auto exposure statistics
  to ae_raw_buffer, the user such as 3A algorithm can use the
  RGB table in [`ipu3_uapi_awb_raw_buffer`](#c-struct-ipu3_uapi_awb_raw_buffer) to do auto-exposure.
- `af_raw_buffer`: [`ipu3_uapi_af_raw_buffer`](#c-struct-ipu3_uapi_af_raw_buffer) for auto focus meta data
- `awb_fr_raw_buffer`: value as specified by [`ipu3_uapi_awb_fr_raw_buffer`](#c-struct-ipu3_uapi_awb_fr_raw_buffer)
- `stats_4a_config`: 4a statistics config as defined by [`ipu3_uapi_4a_config`](#c-struct-ipu3_uapi_4a_config).
- `ae_join_buffers`: 1 to use ae_raw_buffer.
- `padding`: padding config
- `stats_3a_bubble_per_stripe`: a `ipu3_uapi_stats_3a_bubble_info_per_stripe`
- `stats_3a_status`: 3a statistics status set in [`ipu3_uapi_ff_status`](#c-struct-ipu3_uapi_ff_status)

#### <a id="c-struct-ipu3_uapi_bnr_static_config_wb_gains_config"></a>`struct ipu3_uapi_bnr_static_config_wb_gains_config`

White balance gains

**Definition**

```c
struct ipu3_uapi_bnr_static_config_wb_gains_config {
    __u16 gr;
    __u16 r;
    __u16 b;
    __u16 gb;
};
```

**Members**

- `gr`: white balance gain for Gr channel.
- `r`: white balance gain for R channel.
- `b`: white balance gain for B channel.
- `gb`: white balance gain for Gb channel.

**Description**

For BNR parameters WB gain factor for the three channels \[Ggr, Ggb, Gb, Gr\].
Their precision is U3.13 and the range is (0, 8) and the actual gain is
Gx + 1, it is typically Gx = 1.

Pout = {Pin * (1 + Gx)}.

#### <a id="c-struct-ipu3_uapi_bnr_static_config_wb_gains_thr_config"></a>`struct ipu3_uapi_bnr_static_config_wb_gains_thr_config`

Threshold config

**Definition**

```c
struct ipu3_uapi_bnr_static_config_wb_gains_thr_config {
    __u8 gr;
    __u8 r;
    __u8 b;
    __u8 gb;
};
```

**Members**

- `gr`: white balance threshold gain for Gr channel.
- `r`: white balance threshold gain for R channel.
- `b`: white balance threshold gain for B channel.
- `gb`: white balance threshold gain for Gb channel.

**Description**

Defines the threshold that specifies how different a defect pixel can be from
its neighbors.(used by dynamic defect pixel correction sub block)
Precision u4.4 range \[0, 8\].

#### <a id="c-struct-ipu3_uapi_bnr_static_config_thr_coeffs_config"></a>`struct ipu3_uapi_bnr_static_config_thr_coeffs_config`

Noise model coefficients that controls noise threshold

**Definition**

```c
struct ipu3_uapi_bnr_static_config_thr_coeffs_config {
    __u32 cf:13;
    __u32 reserved0:3;
    __u32 cg:5;
    __u32 ci:5;
    __u32 reserved1:1;
    __u32 r_nf:5;
};
```

**Members**

- `cf`: Free coefficient for threshold calculation, range \[0, 8191\], default 0.
- `reserved0`: reserved
- `cg`: Gain coefficient for threshold calculation, \[0, 31\], default 8.
- `ci`: Intensity coefficient for threshold calculation. range \[0, 0x1f\]
  default 6.
  format: u3.2 (3 most significant bits represent whole number,
  2 least significant bits represent the fractional part
  with each count representing 0.25)
  e.g. 6 in binary format is 00110, that translates to 1.5
- `reserved1`: reserved
- `r_nf`: Normalization shift value for r^2 calculation, range \[12, 20\]
  where r is a radius of pixel \[row, col\] from centor of sensor.
  default 14.

**Description**

Threshold used to distinguish between noise and details.

#### <a id="c-struct-ipu3_uapi_bnr_static_config_thr_ctrl_shd_config"></a>`struct ipu3_uapi_bnr_static_config_thr_ctrl_shd_config`

Shading config

**Definition**

```c
struct ipu3_uapi_bnr_static_config_thr_ctrl_shd_config {
    __u8 gr;
    __u8 r;
    __u8 b;
    __u8 gb;
};
```

**Members**

- `gr`: Coefficient defines lens shading gain approximation for gr channel
- `r`: Coefficient defines lens shading gain approximation for r channel
- `b`: Coefficient defines lens shading gain approximation for b channel
- `gb`: Coefficient defines lens shading gain approximation for gb channel

**Description**

Parameters for noise model (NM) adaptation of BNR due to shading correction.
All above have precision of u3.3, default to 0.

#### <a id="c-struct-ipu3_uapi_bnr_static_config_opt_center_config"></a>`struct ipu3_uapi_bnr_static_config_opt_center_config`

Optical center config

**Definition**

```c
struct ipu3_uapi_bnr_static_config_opt_center_config {
    __s32 x_reset:13;
    __u32 reserved0:3;
    __s32 y_reset:13;
    __u32 reserved2:3;
};
```

**Members**

- `x_reset`: Reset value of X (col start - X center). Precision s12.0.
- `reserved0`: reserved
- `y_reset`: Reset value of Y (row start - Y center). Precision s12.0.
- `reserved2`: reserved

**Description**

Distance from corner to optical center for NM adaptation due to shading
correction (should be calculated based on shading tables)

#### <a id="c-struct-ipu3_uapi_bnr_static_config_lut_config"></a>`struct ipu3_uapi_bnr_static_config_lut_config`

BNR square root lookup table

**Definition**

```c
struct ipu3_uapi_bnr_static_config_lut_config {
    __u8 values[IPU3_UAPI_BNR_LUT_SIZE];
};
```

**Members**

- `values`: pre-calculated values of square root function.

**Description**

LUT implementation of square root operation.

#### <a id="c-struct-ipu3_uapi_bnr_static_config_bp_ctrl_config"></a>`struct ipu3_uapi_bnr_static_config_bp_ctrl_config`

Detect bad pixels (bp)

**Definition**

```c
struct ipu3_uapi_bnr_static_config_bp_ctrl_config {
    __u32 bp_thr_gain:5;
    __u32 reserved0:2;
    __u32 defect_mode:1;
    __u32 bp_gain:6;
    __u32 reserved1:18;
    __u32 w0_coeff:4;
    __u32 reserved2:4;
    __u32 w1_coeff:4;
    __u32 reserved3:20;
};
```

**Members**

- `bp_thr_gain`: Defines the threshold that specifies how different a
  defect pixel can be from its neighbors. Threshold is
  dependent on de-noise threshold calculated by algorithm.
  Range \[4, 31\], default 4.
- `reserved0`: reserved
- `defect_mode`: Mode of addressed defect pixels,
  0 - single defect pixel is expected,
  1 - 2 adjacent defect pixels are expected, default 1.
- `bp_gain`: Defines how 2nd derivation that passes through a defect pixel
  is different from 2nd derivations that pass through
  neighbor pixels. u4.2, range \[0, 256\], default 8.
- `reserved1`: reserved
- `w0_coeff`: Blending coefficient of defect pixel correction.
  Precision u4, range \[0, 8\], default 8.
- `reserved2`: reserved
- `w1_coeff`: Enable influence of incorrect defect pixel correction to be
  avoided. Precision u4, range \[1, 8\], default 8.
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_bnr_static_config_dn_detect_ctrl_config"></a>`struct ipu3_uapi_bnr_static_config_dn_detect_ctrl_config`

Denoising config

**Definition**

```c
struct ipu3_uapi_bnr_static_config_dn_detect_ctrl_config {
    __u32 alpha:4;
    __u32 beta:4;
    __u32 gamma:4;
    __u32 reserved0:4;
    __u32 max_inf:4;
    __u32 reserved1:7;
    __u32 gd_enable:1;
    __u32 bpc_enable:1;
    __u32 bnr_enable:1;
    __u32 ff_enable:1;
    __u32 reserved2:1;
};
```

**Members**

- `alpha`: Weight of central element of smoothing filter.
- `beta`: Weight of peripheral elements of smoothing filter, default 4.
- `gamma`: Weight of diagonal elements of smoothing filter, default 4.
- `reserved0`: reserved
- `max_inf`: Maximum increase of peripheral or diagonal element influence
  relative to the pre-defined value range: \[0x5, 0xa\]
- `reserved1`: reserved
- `gd_enable`: Green disparity enable control, 0 - disable, 1 - enable.
- `bpc_enable`: Bad pixel correction enable control, 0 - disable, 1 - enable.
- `bnr_enable`: Bayer noise removal enable control, 0 - disable, 1 - enable.
- `ff_enable`: Fixed function enable, 0 - disable, 1 - enable.
- `reserved2`: reserved

**Description**

- beta and gamma parameter define the strength of the noise removal filter.

  All above has precision u0.4, range \[0, 0xf\]
  format: u0.4 (no / zero bits represent whole number,
  4 bits represent the fractional part
  with each count representing 0.0625)
  e.g. 0xf translates to 0.0625x15 = 0.9375

#### <a id="c-struct-ipu3_uapi_bnr_static_config_opt_center_sqr_config"></a>`struct ipu3_uapi_bnr_static_config_opt_center_sqr_config`

BNR optical square

**Definition**

```c
struct ipu3_uapi_bnr_static_config_opt_center_sqr_config {
    __u32 x_sqr_reset;
    __u32 y_sqr_reset;
};
```

**Members**

- `x_sqr_reset`: Reset value of X^2.
- `y_sqr_reset`: Reset value of Y^2.

**Description**

Please note:

1. X and Y ref to
   [`ipu3_uapi_bnr_static_config_opt_center_config`](#c-struct-ipu3_uapi_bnr_static_config_opt_center_config)
1. Both structs are used in threshold formula to calculate r^2, where r
   is a radius of pixel \[row, col\] from centor of sensor.

#### <a id="c-struct-ipu3_uapi_bnr_static_config"></a>`struct ipu3_uapi_bnr_static_config`

BNR static config

**Definition**

```c
struct ipu3_uapi_bnr_static_config {
    struct ipu3_uapi_bnr_static_config_wb_gains_config wb_gains;
    struct ipu3_uapi_bnr_static_config_wb_gains_thr_config wb_gains_thr;
    struct ipu3_uapi_bnr_static_config_thr_coeffs_config thr_coeffs;
    struct ipu3_uapi_bnr_static_config_thr_ctrl_shd_config thr_ctrl_shd;
    struct ipu3_uapi_bnr_static_config_opt_center_config opt_center;
    struct ipu3_uapi_bnr_static_config_lut_config lut;
    struct ipu3_uapi_bnr_static_config_bp_ctrl_config bp_ctrl;
    struct ipu3_uapi_bnr_static_config_dn_detect_ctrl_config dn_detect_ctrl;
    __u32 column_size;
    struct ipu3_uapi_bnr_static_config_opt_center_sqr_config opt_center_sqr;
};
```

**Members**

- `wb_gains`: white balance gains [`ipu3_uapi_bnr_static_config_wb_gains_config`](#c-struct-ipu3_uapi_bnr_static_config_wb_gains_config)
- `wb_gains_thr`: white balance gains threshold as defined by
  [`ipu3_uapi_bnr_static_config_wb_gains_thr_config`](#c-struct-ipu3_uapi_bnr_static_config_wb_gains_thr_config)
- `thr_coeffs`: coefficients of threshold
  [`ipu3_uapi_bnr_static_config_thr_coeffs_config`](#c-struct-ipu3_uapi_bnr_static_config_thr_coeffs_config)
- `thr_ctrl_shd`: control of shading threshold
  [`ipu3_uapi_bnr_static_config_thr_ctrl_shd_config`](#c-struct-ipu3_uapi_bnr_static_config_thr_ctrl_shd_config)
- `opt_center`: optical center [`ipu3_uapi_bnr_static_config_opt_center_config`](#c-struct-ipu3_uapi_bnr_static_config_opt_center_config)
- `lut`: lookup table [`ipu3_uapi_bnr_static_config_lut_config`](#c-struct-ipu3_uapi_bnr_static_config_lut_config)
- `bp_ctrl`: detect and remove bad pixels as defined in struct
  [`ipu3_uapi_bnr_static_config_bp_ctrl_config`](#c-struct-ipu3_uapi_bnr_static_config_bp_ctrl_config)
- `dn_detect_ctrl`: detect and remove noise.
  [`ipu3_uapi_bnr_static_config_dn_detect_ctrl_config`](#c-struct-ipu3_uapi_bnr_static_config_dn_detect_ctrl_config)
- `column_size`: The number of pixels in column.
- `opt_center_sqr`: Reset value of r^2 to optical center, see
  [`ipu3_uapi_bnr_static_config_opt_center_sqr_config`](#c-struct-ipu3_uapi_bnr_static_config_opt_center_sqr_config).

**Description**

Above parameters and opt_center_sqr are used for white balance and shading.

#### <a id="c-struct-ipu3_uapi_bnr_static_config_green_disparity"></a>`struct ipu3_uapi_bnr_static_config_green_disparity`

Correct green disparity

**Definition**

```c
struct ipu3_uapi_bnr_static_config_green_disparity {
    __u32 gd_red:6;
    __u32 reserved0:2;
    __u32 gd_green:6;
    __u32 reserved1:2;
    __u32 gd_blue:6;
    __u32 reserved2:10;
    __u32 gd_black:14;
    __u32 reserved3:2;
    __u32 gd_shading:7;
    __u32 reserved4:1;
    __u32 gd_support:2;
    __u32 reserved5:1;
    __u32 gd_clip:1;
    __u32 gd_central_weight:4;
};
```

**Members**

- `gd_red`: Shading gain coeff for gr disparity level in bright red region.
  Precision u0.6, default 4(0.0625).
- `reserved0`: reserved
- `gd_green`: Shading gain coeff for gr disparity level in bright green
  region. Precision u0.6, default 4(0.0625).
- `reserved1`: reserved
- `gd_blue`: Shading gain coeff for gr disparity level in bright blue region.
  Precision u0.6, default 4(0.0625).
- `reserved2`: reserved
- `gd_black`: Maximal green disparity level in dark region (stronger disparity
  assumed to be image detail). Precision u14, default 80.
- `reserved3`: reserved
- `gd_shading`: Change maximal green disparity level according to square
  distance from image center.
- `reserved4`: reserved
- `gd_support`: Lower bound for the number of second green color pixels in
  current pixel neighborhood with less than threshold difference
  from it.
- `reserved5`: reserved
- `gd_clip`: Turn green disparity clip on/off, \[0, 1\], default 1.
- `gd_central_weight`: Central pixel weight in 9 pixels weighted sum.

**Description**

The shading gain coeff of red, green, blue and black are used to calculate
threshold given a pixel's color value and its coordinates in the image.

#### <a id="c-struct-ipu3_uapi_dm_config"></a>`struct ipu3_uapi_dm_config`

De-mosaic parameters

**Definition**

```c
struct ipu3_uapi_dm_config {
    __u32 dm_en:1;
    __u32 ch_ar_en:1;
    __u32 fcc_en:1;
    __u32 reserved0:13;
    __u32 frame_width:16;
    __u32 gamma_sc:5;
    __u32 reserved1:3;
    __u32 lc_ctrl:5;
    __u32 reserved2:3;
    __u32 cr_param1:5;
    __u32 reserved3:3;
    __u32 cr_param2:5;
    __u32 reserved4:3;
    __u32 coring_param:5;
    __u32 reserved5:27;
};
```

**Members**

- `dm_en`: de-mosaic enable.
- `ch_ar_en`: Checker artifacts removal enable flag. Default 0.
- `fcc_en`: False color correction (FCC) enable flag. Default 0.
- `reserved0`: reserved
- `frame_width`: do not care
- `gamma_sc`: Sharpening coefficient (coefficient of 2-d derivation of
  complementary color in Hamilton-Adams interpolation).
  u5, range \[0, 31\], default 8.
- `reserved1`: reserved
- `lc_ctrl`: Parameter that controls weights of Chroma Homogeneity metric
  in calculation of final homogeneity metric.
  u5, range \[0, 31\], default 7.
- `reserved2`: reserved
- `cr_param1`: First parameter that defines Checker artifact removal
  feature gain. Precision u5, range \[0, 31\], default 8.
- `reserved3`: reserved
- `cr_param2`: Second parameter that defines Checker artifact removal
  feature gain. Precision u5, range \[0, 31\], default 8.
- `reserved4`: reserved
- `coring_param`: Defines power of false color correction operation.
  low for preserving edge colors, high for preserving gray
  edge artifacts.
  Precision u1.4, range \[0, 1.9375\], default 4 (0.25).
- `reserved5`: reserved

**Description**

The demosaic fixed function block is responsible to covert Bayer(mosaiced)
images into color images based on demosaicing algorithm.

#### <a id="c-struct-ipu3_uapi_ccm_mat_config"></a>`struct ipu3_uapi_ccm_mat_config`

Color correction matrix

**Definition**

```c
struct ipu3_uapi_ccm_mat_config {
    __s16 coeff_m11;
    __s16 coeff_m12;
    __s16 coeff_m13;
    __s16 coeff_o_r;
    __s16 coeff_m21;
    __s16 coeff_m22;
    __s16 coeff_m23;
    __s16 coeff_o_g;
    __s16 coeff_m31;
    __s16 coeff_m32;
    __s16 coeff_m33;
    __s16 coeff_o_b;
};
```

**Members**

- `coeff_m11`: CCM 3x3 coefficient, range \[-65536, 65535\]
- `coeff_m12`: CCM 3x3 coefficient, range \[-8192, 8191\]
- `coeff_m13`: CCM 3x3 coefficient, range \[-32768, 32767\]
- `coeff_o_r`: Bias 3x1 coefficient, range \[-8191, 8181\]
- `coeff_m21`: CCM 3x3 coefficient, range \[-32767, 32767\]
- `coeff_m22`: CCM 3x3 coefficient, range \[-8192, 8191\]
- `coeff_m23`: CCM 3x3 coefficient, range \[-32768, 32767\]
- `coeff_o_g`: Bias 3x1 coefficient, range \[-8191, 8181\]
- `coeff_m31`: CCM 3x3 coefficient, range \[-32768, 32767\]
- `coeff_m32`: CCM 3x3 coefficient, range \[-8192, 8191\]
- `coeff_m33`: CCM 3x3 coefficient, range \[-32768, 32767\]
- `coeff_o_b`: Bias 3x1 coefficient, range \[-8191, 8181\]

**Description**

Transform sensor specific color space to standard sRGB by applying 3x3 matrix
and adding a bias vector O. The transformation is basically a rotation and
translation in the 3-dimensional color spaces. Here are the defaults:

9775,   -2671,  1087,   0
-1071,  8303,   815,    0
-23,    -7887,  16103,  0

#### <a id="c-struct-ipu3_uapi_gamma_corr_ctrl"></a>`struct ipu3_uapi_gamma_corr_ctrl`

Gamma correction

**Definition**

```c
struct ipu3_uapi_gamma_corr_ctrl {
    __u32 enable:1;
    __u32 reserved:31;
};
```

**Members**

- `enable`: gamma correction enable.
- `reserved`: reserved

#### <a id="c-struct-ipu3_uapi_gamma_corr_lut"></a>`struct ipu3_uapi_gamma_corr_lut`

Per-pixel tone mapping implemented as LUT.

**Definition**

```c
struct ipu3_uapi_gamma_corr_lut {
    __u16 lut[IPU3_UAPI_GAMMA_CORR_LUT_ENTRIES];
};
```

**Members**

- `lut`: 256 tabulated values of the gamma function. LUT\[1\].. LUT\[256\]
  format u13.0, range \[0, 8191\].

**Description**

The tone mapping operation is done by a Piece wise linear graph
that is implemented as a lookup table(LUT). The pixel component input
intensity is the X-axis of the graph which is the table entry.

#### <a id="c-struct-ipu3_uapi_gamma_config"></a>`struct ipu3_uapi_gamma_config`

Gamma config

**Definition**

```c
struct ipu3_uapi_gamma_config {
    struct ipu3_uapi_gamma_corr_ctrl gc_ctrl  ;
    struct ipu3_uapi_gamma_corr_lut gc_lut  ;
};
```

**Members**

- `gc_ctrl`: control of gamma correction [`ipu3_uapi_gamma_corr_ctrl`](#c-struct-ipu3_uapi_gamma_corr_ctrl)
- `gc_lut`: lookup table of gamma correction [`ipu3_uapi_gamma_corr_lut`](#c-struct-ipu3_uapi_gamma_corr_lut)

#### <a id="c-struct-ipu3_uapi_csc_mat_config"></a>`struct ipu3_uapi_csc_mat_config`

Color space conversion matrix config

**Definition**

```c
struct ipu3_uapi_csc_mat_config {
    __s16 coeff_c11;
    __s16 coeff_c12;
    __s16 coeff_c13;
    __s16 coeff_b1;
    __s16 coeff_c21;
    __s16 coeff_c22;
    __s16 coeff_c23;
    __s16 coeff_b2;
    __s16 coeff_c31;
    __s16 coeff_c32;
    __s16 coeff_c33;
    __s16 coeff_b3;
};
```

**Members**

- `coeff_c11`: Conversion matrix value, format s0.14, range \[-16384, 16383\].
- `coeff_c12`: Conversion matrix value, format s0.14, range \[-8192, 8191\].
- `coeff_c13`: Conversion matrix value, format s0.14, range \[-16384, 16383\].
- `coeff_b1`: Bias 3x1 coefficient, s13.0 range \[-8192, 8191\].
- `coeff_c21`: Conversion matrix value, format s0.14, range \[-16384, 16383\].
- `coeff_c22`: Conversion matrix value, format s0.14, range \[-8192, 8191\].
- `coeff_c23`: Conversion matrix value, format s0.14, range \[-16384, 16383\].
- `coeff_b2`: Bias 3x1 coefficient, s13.0 range \[-8192, 8191\].
- `coeff_c31`: Conversion matrix value, format s0.14, range \[-16384, 16383\].
- `coeff_c32`: Conversion matrix value, format s0.14, range \[-8192, 8191\].
- `coeff_c33`: Conversion matrix value, format s0.14, range \[-16384, 16383\].
- `coeff_b3`: Bias 3x1 coefficient, s13.0 range \[-8192, 8191\].

**Description**

To transform each pixel from RGB to YUV (Y - brightness/luminance,
UV -chroma) by applying the pixel's values by a 3x3 matrix and adding an
optional bias 3x1 vector. Here are the default values for the matrix:

4898,   9617,  1867, 0,
-2410, -4732,  7143, 0,
10076, -8437, -1638, 0,

(i.e. for real number 0.299, 0.299 * 2^14 becomes 4898.)

#### <a id="c-struct-ipu3_uapi_cds_params"></a>`struct ipu3_uapi_cds_params`

Chroma down-scaling

**Definition**

```c
struct ipu3_uapi_cds_params {
    __u32 ds_c00:2;
    __u32 ds_c01:2;
    __u32 ds_c02:2;
    __u32 ds_c03:2;
    __u32 ds_c10:2;
    __u32 ds_c11:2;
    __u32 ds_c12:2;
    __u32 ds_c13:2;
    __u32 ds_nf:5;
    __u32 reserved0:3;
    __u32 csc_en:1;
    __u32 uv_bin_output:1;
    __u32 reserved1:6;
};
```

**Members**

- `ds_c00`: range \[0, 3\]
- `ds_c01`: range \[0, 3\]
- `ds_c02`: range \[0, 3\]
- `ds_c03`: range \[0, 3\]
- `ds_c10`: range \[0, 3\]
- `ds_c11`: range \[0, 3\]
- `ds_c12`: range \[0, 3\]
- `ds_c13`: range \[0, 3\]
- `ds_nf`: Normalization factor for Chroma output downscaling filter,
  range 0,4, default 2.
- `reserved0`: reserved
- `csc_en`: Color space conversion enable
- `uv_bin_output`: 0: output YUV 4.2.0, 1: output YUV 4.2.2(default).
- `reserved1`: reserved

**Description**

- In case user does not provide, above 4x2 filter will use following defaults:
  1, 3, 3, 1,
  1, 3, 3, 1,

#### <a id="c-struct-ipu3_uapi_shd_grid_config"></a>`struct ipu3_uapi_shd_grid_config`

Bayer shading(darkening) correction

**Definition**

```c
struct ipu3_uapi_shd_grid_config {
    __u8 width;
    __u8 height;
    __u8 block_width_log2:3;
    __u8 reserved0:1;
    __u8 block_height_log2:3;
    __u8 reserved1:1;
    __u8 grid_height_per_slice;
    __s16 x_start;
    __s16 y_start;
};
```

**Members**

- `width`: Grid horizontal dimensions, u8, \[8, 128\], default 73
- `height`: Grid vertical dimensions, u8, \[8, 128\], default 56
- `block_width_log2`: Log2 of the width of the grid cell in pixel count
  u4, \[0, 15\], default value 5.
- `reserved0`: reserved
- `block_height_log2`: Log2 of the height of the grid cell in pixel count
  u4, \[0, 15\], default value 6.
- `reserved1`: reserved
- `grid_height_per_slice`: SHD_MAX_CELLS_PER_SET/width.
  (with SHD_MAX_CELLS_PER_SET = 146).
- `x_start`: X value of top left corner of sensor relative to ROI
  s13, \[-4096, 0\], default 0, only negative values.
- `y_start`: Y value of top left corner of sensor relative to ROI
  s13, \[-4096, 0\], default 0, only negative values.

#### <a id="c-struct-ipu3_uapi_shd_general_config"></a>`struct ipu3_uapi_shd_general_config`

Shading general config

**Definition**

```c
struct ipu3_uapi_shd_general_config {
    __u32 init_set_vrt_offst_ul:8;
    __u32 shd_enable:1;
    __u32 gain_factor:2;
    __u32 reserved:21;
};
```

**Members**

- `init_set_vrt_offst_ul`: set vertical offset,
  y_start >> block_height_log2 % grid_height_per_slice.
- `shd_enable`: shading enable.
- `gain_factor`: Gain factor. Shift calculated anti shading value. Precision u2.
  0x0 - gain factor \[1, 5\], means no shift interpolated value.
  0x1 - gain factor \[1, 9\], means shift interpolated by 1.
  0x2 - gain factor \[1, 17\], means shift interpolated by 2.
- `reserved`: reserved

**Description**

Correction is performed by multiplying a gain factor for each of the 4 Bayer
channels as a function of the pixel location in the sensor.

#### <a id="c-struct-ipu3_uapi_shd_black_level_config"></a>`struct ipu3_uapi_shd_black_level_config`

Black level correction

**Definition**

```c
struct ipu3_uapi_shd_black_level_config {
    __s16 bl_r;
    __s16 bl_gr;
    __s16 bl_gb;
    __s16 bl_b;
};
```

**Members**

- `bl_r`: Bios values for green red. s11 range \[-2048, 2047\].
- `bl_gr`: Bios values for green blue. s11 range \[-2048, 2047\].
- `bl_gb`: Bios values for red. s11 range \[-2048, 2047\].
- `bl_b`: Bios values for blue. s11 range \[-2048, 2047\].

#### <a id="c-struct-ipu3_uapi_shd_config_static"></a>`struct ipu3_uapi_shd_config_static`

Shading config static

**Definition**

```c
struct ipu3_uapi_shd_config_static {
    struct ipu3_uapi_shd_grid_config grid;
    struct ipu3_uapi_shd_general_config general;
    struct ipu3_uapi_shd_black_level_config black_level;
};
```

**Members**

- `grid`: shading grid config [`ipu3_uapi_shd_grid_config`](#c-struct-ipu3_uapi_shd_grid_config)
- `general`: shading general config [`ipu3_uapi_shd_general_config`](#c-struct-ipu3_uapi_shd_general_config)
- `black_level`: black level config for shading correction as defined by
  [`ipu3_uapi_shd_black_level_config`](#c-struct-ipu3_uapi_shd_black_level_config)

#### <a id="c-struct-ipu3_uapi_shd_lut"></a>`struct ipu3_uapi_shd_lut`

Shading gain factor lookup table.

**Definition**

```c
struct ipu3_uapi_shd_lut {
    struct {
        struct {
            __u16 r;
            __u16 gr;
        } r_and_gr[IPU3_UAPI_SHD_MAX_CELLS_PER_SET];
        __u8 reserved1[24];
        struct {
            __u16 gb;
            __u16 b;
        } gb_and_b[IPU3_UAPI_SHD_MAX_CELLS_PER_SET];
        __u8 reserved2[24];
    } sets[IPU3_UAPI_SHD_MAX_CFG_SETS];
};
```

**Members**

- `sets`: array
- `sets.r_and_gr`: Red and GreenR Lookup table.
- `sets.r_and_gr.r`: Red shading factor.
- `sets.r_and_gr.gr`: GreenR shading factor.
- `sets.reserved1`: reserved
- `sets.gb_and_b`: GreenB and Blue Lookup table.
- `sets.gb_and_b.gb`: GreenB shading factor.
- `sets.gb_and_b.b`: Blue shading factor.
- `sets.reserved2`: reserved

**Description**

Map to shading correction LUT register set.

#### <a id="c-struct-ipu3_uapi_shd_config"></a>`struct ipu3_uapi_shd_config`

Shading config

**Definition**

```c
struct ipu3_uapi_shd_config {
    struct ipu3_uapi_shd_config_static shd  ;
    struct ipu3_uapi_shd_lut shd_lut  ;
};
```

**Members**

- `shd`: shading static config, see [`ipu3_uapi_shd_config_static`](#c-struct-ipu3_uapi_shd_config_static)
- `shd_lut`: shading lookup table [`ipu3_uapi_shd_lut`](#c-struct-ipu3_uapi_shd_lut)

#### <a id="c-struct-ipu3_uapi_iefd_cux2"></a>`struct ipu3_uapi_iefd_cux2`

IEFd Config Unit 2 parameters

**Definition**

```c
struct ipu3_uapi_iefd_cux2 {
    __u32 x0:9;
    __u32 x1:9;
    __u32 a01:9;
    __u32 b01:5;
};
```

**Members**

- `x0`: X0 point of Config Unit, u9.0, default 0.
- `x1`: X1 point of Config Unit, u9.0, default 0.
- `a01`: Slope A of Config Unit, s4.4, default 0.
- `b01`: Slope B, always 0.

**Description**

Calculate weight for blending directed and non-directed denoise elements

**Note**

Each instance of Config Unit needs X coordinate of n points and
slope A factor between points calculated by driver based on calibration
parameters.

All CU inputs are unsigned, they will be converted to signed when written
to register, i.e. a01 will be written to 9 bit register in s4.4 format.
The data precision s4.4 means 4 bits for integer parts and 4 bits for the
fractional part, the first bit indicates positive or negative value.
For userspace software (commonly the imaging library), the computation for
the CU slope values should be based on the slope resolution 1/16 (binary
0.0001 - the minimal interval value), the slope value range is \[-256, +255\].
This applies to [`ipu3_uapi_iefd_cux6_ed`](#c-struct-ipu3_uapi_iefd_cux6_ed), [`ipu3_uapi_iefd_cux2_1`](#c-struct-ipu3_uapi_iefd_cux2_1),
[`ipu3_uapi_iefd_cux2_1`](#c-struct-ipu3_uapi_iefd_cux2_1), [`ipu3_uapi_iefd_cux4`](#c-struct-ipu3_uapi_iefd_cux4) and [`ipu3_uapi_iefd_cux6_rad`](#c-struct-ipu3_uapi_iefd_cux6_rad).

#### <a id="c-struct-ipu3_uapi_iefd_cux6_ed"></a>`struct ipu3_uapi_iefd_cux6_ed`

Calculate power of non-directed sharpening element, Config Unit 6 for edge detail (ED).

**Definition**

```c
struct ipu3_uapi_iefd_cux6_ed {
    __u32 x0:9;
    __u32 x1:9;
    __u32 x2:9;
    __u32 reserved0:5;
    __u32 x3:9;
    __u32 x4:9;
    __u32 x5:9;
    __u32 reserved1:5;
    __u32 a01:9;
    __u32 a12:9;
    __u32 a23:9;
    __u32 reserved2:5;
    __u32 a34:9;
    __u32 a45:9;
    __u32 reserved3:14;
    __u32 b01:9;
    __u32 b12:9;
    __u32 b23:9;
    __u32 reserved4:5;
    __u32 b34:9;
    __u32 b45:9;
    __u32 reserved5:14;
};
```

**Members**

- `x0`: X coordinate of point 0, u9.0, default 0.
- `x1`: X coordinate of point 1, u9.0, default 0.
- `x2`: X coordinate of point 2, u9.0, default 0.
- `reserved0`: reserved
- `x3`: X coordinate of point 3, u9.0, default 0.
- `x4`: X coordinate of point 4, u9.0, default 0.
- `x5`: X coordinate of point 5, u9.0, default 0.
- `reserved1`: reserved
- `a01`: slope A points 01, s4.4, default 0.
- `a12`: slope A points 12, s4.4, default 0.
- `a23`: slope A points 23, s4.4, default 0.
- `reserved2`: reserved
- `a34`: slope A points 34, s4.4, default 0.
- `a45`: slope A points 45, s4.4, default 0.
- `reserved3`: reserved
- `b01`: slope B points 01, s4.4, default 0.
- `b12`: slope B points 12, s4.4, default 0.
- `b23`: slope B points 23, s4.4, default 0.
- `reserved4`: reserved
- `b34`: slope B points 34, s4.4, default 0.
- `b45`: slope B points 45, s4.4, default 0.
- `reserved5`: reserved.

#### <a id="c-struct-ipu3_uapi_iefd_cux2_1"></a>`struct ipu3_uapi_iefd_cux2_1`

Calculate power of non-directed denoise element apply.

**Definition**

```c
struct ipu3_uapi_iefd_cux2_1 {
    __u32 x0:9;
    __u32 x1:9;
    __u32 a01:9;
    __u32 reserved1:5;
    __u32 b01:8;
    __u32 reserved2:24;
};
```

**Members**

- `x0`: X0 point of Config Unit, u9.0, default 0.
- `x1`: X1 point of Config Unit, u9.0, default 0.
- `a01`: Slope A of Config Unit, s4.4, default 0.
- `reserved1`: reserved
- `b01`: offset B0 of Config Unit, u7.0, default 0.
- `reserved2`: reserved

#### <a id="c-struct-ipu3_uapi_iefd_cux4"></a>`struct ipu3_uapi_iefd_cux4`

Calculate power of non-directed sharpening element.

**Definition**

```c
struct ipu3_uapi_iefd_cux4 {
    __u32 x0:9;
    __u32 x1:9;
    __u32 x2:9;
    __u32 reserved0:5;
    __u32 x3:9;
    __u32 a01:9;
    __u32 a12:9;
    __u32 reserved1:5;
    __u32 a23:9;
    __u32 b01:8;
    __u32 b12:8;
    __u32 reserved2:7;
    __u32 b23:8;
    __u32 reserved3:24;
};
```

**Members**

- `x0`: X0 point of Config Unit, u9.0, default 0.
- `x1`: X1 point of Config Unit, u9.0, default 0.
- `x2`: X2 point of Config Unit, u9.0, default 0.
- `reserved0`: reserved
- `x3`: X3 point of Config Unit, u9.0, default 0.
- `a01`: Slope A0 of Config Unit, s4.4, default 0.
- `a12`: Slope A1 of Config Unit, s4.4, default 0.
- `reserved1`: reserved
- `a23`: Slope A2 of Config Unit, s4.4, default 0.
- `b01`: Offset B0 of Config Unit, s7.0, default 0.
- `b12`: Offset B1 of Config Unit, s7.0, default 0.
- `reserved2`: reserved
- `b23`: Offset B2 of Config Unit, s7.0, default 0.
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_iefd_cux6_rad"></a>`struct ipu3_uapi_iefd_cux6_rad`

Radial Config Unit (CU)

**Definition**

```c
struct ipu3_uapi_iefd_cux6_rad {
    __u32 x0:8;
    __u32 x1:8;
    __u32 x2:8;
    __u32 x3:8;
    __u32 x4:8;
    __u32 x5:8;
    __u32 reserved1:16;
    __u32 a01:16;
    __u32 a12:16;
    __u32 a23:16;
    __u32 a34:16;
    __u32 a45:16;
    __u32 reserved2:16;
    __u32 b01:10;
    __u32 b12:10;
    __u32 b23:10;
    __u32 reserved4:2;
    __u32 b34:10;
    __u32 b45:10;
    __u32 reserved5:12;
};
```

**Members**

- `x0`: x0 points of Config Unit radial, u8.0
- `x1`: x1 points of Config Unit radial, u8.0
- `x2`: x2 points of Config Unit radial, u8.0
- `x3`: x3 points of Config Unit radial, u8.0
- `x4`: x4 points of Config Unit radial, u8.0
- `x5`: x5 points of Config Unit radial, u8.0
- `reserved1`: reserved
- `a01`: Slope A of Config Unit radial, s7.8
- `a12`: Slope A of Config Unit radial, s7.8
- `a23`: Slope A of Config Unit radial, s7.8
- `a34`: Slope A of Config Unit radial, s7.8
- `a45`: Slope A of Config Unit radial, s7.8
- `reserved2`: reserved
- `b01`: Slope B of Config Unit radial, s9.0
- `b12`: Slope B of Config Unit radial, s9.0
- `b23`: Slope B of Config Unit radial, s9.0
- `reserved4`: reserved
- `b34`: Slope B of Config Unit radial, s9.0
- `b45`: Slope B of Config Unit radial, s9.0
- `reserved5`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_iefd_cfg_units"></a>`struct ipu3_uapi_yuvp1_iefd_cfg_units`

IEFd Config Units parameters

**Definition**

```c
struct ipu3_uapi_yuvp1_iefd_cfg_units {
    struct ipu3_uapi_iefd_cux2 cu_1;
    struct ipu3_uapi_iefd_cux6_ed cu_ed;
    struct ipu3_uapi_iefd_cux2 cu_3;
    struct ipu3_uapi_iefd_cux2_1 cu_5;
    struct ipu3_uapi_iefd_cux4 cu_6;
    struct ipu3_uapi_iefd_cux2 cu_7;
    struct ipu3_uapi_iefd_cux4 cu_unsharp;
    struct ipu3_uapi_iefd_cux6_rad cu_radial;
    struct ipu3_uapi_iefd_cux2 cu_vssnlm;
};
```

**Members**

- `cu_1`: calculate weight for blending directed and
  non-directed denoise elements. See [`ipu3_uapi_iefd_cux2`](#c-struct-ipu3_uapi_iefd_cux2)
- `cu_ed`: calculate power of non-directed sharpening element, see
  [`ipu3_uapi_iefd_cux6_ed`](#c-struct-ipu3_uapi_iefd_cux6_ed)
- `cu_3`: calculate weight for blending directed and
  non-directed denoise elements. A [`ipu3_uapi_iefd_cux2`](#c-struct-ipu3_uapi_iefd_cux2)
- `cu_5`: calculate power of non-directed denoise element apply, use
  [`ipu3_uapi_iefd_cux2_1`](#c-struct-ipu3_uapi_iefd_cux2_1)
- `cu_6`: calculate power of non-directed sharpening element. See
  [`ipu3_uapi_iefd_cux4`](#c-struct-ipu3_uapi_iefd_cux4)
- `cu_7`: calculate weight for blending directed and
  non-directed denoise elements. Use [`ipu3_uapi_iefd_cux2`](#c-struct-ipu3_uapi_iefd_cux2)
- `cu_unsharp`: Config Unit of unsharp [`ipu3_uapi_iefd_cux4`](#c-struct-ipu3_uapi_iefd_cux4)
- `cu_radial`: Config Unit of radial [`ipu3_uapi_iefd_cux6_rad`](#c-struct-ipu3_uapi_iefd_cux6_rad)
- `cu_vssnlm`: Config Unit of vssnlm [`ipu3_uapi_iefd_cux2`](#c-struct-ipu3_uapi_iefd_cux2)

#### <a id="c-struct-ipu3_uapi_yuvp1_iefd_config_s"></a>`struct ipu3_uapi_yuvp1_iefd_config_s`

IEFd config

**Definition**

```c
struct ipu3_uapi_yuvp1_iefd_config_s {
    __u32 horver_diag_coeff:7;
    __u32 reserved0:1;
    __u32 clamp_stitch:6;
    __u32 reserved1:2;
    __u32 direct_metric_update:5;
    __u32 reserved2:3;
    __u32 ed_horver_diag_coeff:7;
    __u32 reserved3:1;
};
```

**Members**

- `horver_diag_coeff`: Gradient compensation. Compared with vertical /
  horizontal (0 / 90 degree), coefficient of diagonal (45 /
  135 degree) direction should be corrected by approx.
  1/sqrt(2).
- `reserved0`: reserved
- `clamp_stitch`: Slope to stitch between clamped and unclamped edge values
- `reserved1`: reserved
- `direct_metric_update`: Update coeff for direction metric
- `reserved2`: reserved
- `ed_horver_diag_coeff`: Radial Coefficient that compensates for
  different distance for vertical/horizontal and
  diagonal gradient calculation (approx. 1/sqrt(2))
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_iefd_control"></a>`struct ipu3_uapi_yuvp1_iefd_control`

IEFd control

**Definition**

```c
struct ipu3_uapi_yuvp1_iefd_control {
    __u32 iefd_en:1;
    __u32 denoise_en:1;
    __u32 direct_smooth_en:1;
    __u32 rad_en:1;
    __u32 vssnlm_en:1;
    __u32 reserved:27;
};
```

**Members**

- `iefd_en`: Enable IEFd
- `denoise_en`: Enable denoise
- `direct_smooth_en`: Enable directional smooth
- `rad_en`: Enable radial update
- `vssnlm_en`: Enable VSSNLM output filter
- `reserved`: reserved

#### <a id="c-struct-ipu3_uapi_sharp_cfg"></a>`struct ipu3_uapi_sharp_cfg`

Sharpening config

**Definition**

```c
struct ipu3_uapi_sharp_cfg {
    __u32 nega_lmt_txt:13;
    __u32 reserved0:19;
    __u32 posi_lmt_txt:13;
    __u32 reserved1:19;
    __u32 nega_lmt_dir:13;
    __u32 reserved2:19;
    __u32 posi_lmt_dir:13;
    __u32 reserved3:19;
};
```

**Members**

- `nega_lmt_txt`: Sharpening limit for negative overshoots for texture.
- `reserved0`: reserved
- `posi_lmt_txt`: Sharpening limit for positive overshoots for texture.
- `reserved1`: reserved
- `nega_lmt_dir`: Sharpening limit for negative overshoots for direction (edge).
- `reserved2`: reserved
- `posi_lmt_dir`: Sharpening limit for positive overshoots for direction (edge).
- `reserved3`: reserved

**Description**

Fixed point type u13.0, range \[0, 8191\].

#### <a id="c-struct-ipu3_uapi_far_w"></a>`struct ipu3_uapi_far_w`

Sharpening config for far sub-group

**Definition**

```c
struct ipu3_uapi_far_w {
    __u32 dir_shrp:7;
    __u32 reserved0:1;
    __u32 dir_dns:7;
    __u32 reserved1:1;
    __u32 ndir_dns_powr:7;
    __u32 reserved2:9;
};
```

**Members**

- `dir_shrp`: Weight of wide direct sharpening, u1.6, range \[0, 64\], default 64.
- `reserved0`: reserved
- `dir_dns`: Weight of wide direct denoising, u1.6, range \[0, 64\], default 0.
- `reserved1`: reserved
- `ndir_dns_powr`: Power of non-direct denoising,
  Precision u1.6, range \[0, 64\], default 64.
- `reserved2`: reserved

#### <a id="c-struct-ipu3_uapi_unsharp_cfg"></a>`struct ipu3_uapi_unsharp_cfg`

Unsharp config

**Definition**

```c
struct ipu3_uapi_unsharp_cfg {
    __u32 unsharp_weight:7;
    __u32 reserved0:1;
    __u32 unsharp_amount:9;
    __u32 reserved1:15;
};
```

**Members**

- `unsharp_weight`: Unsharp mask blending weight.
  u1.6, range \[0, 64\], default 16.
  0 - disabled, 64 - use only unsharp.
- `reserved0`: reserved
- `unsharp_amount`: Unsharp mask amount, u4.5, range \[0, 511\], default 0.
- `reserved1`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_iefd_shrp_cfg"></a>`struct ipu3_uapi_yuvp1_iefd_shrp_cfg`

IEFd sharpness config

**Definition**

```c
struct ipu3_uapi_yuvp1_iefd_shrp_cfg {
    struct ipu3_uapi_sharp_cfg cfg;
    struct ipu3_uapi_far_w far_w;
    struct ipu3_uapi_unsharp_cfg unshrp_cfg;
};
```

**Members**

- `cfg`: sharpness config [`ipu3_uapi_sharp_cfg`](#c-struct-ipu3_uapi_sharp_cfg)
- `far_w`: wide range config, value as specified by [`ipu3_uapi_far_w`](#c-struct-ipu3_uapi_far_w):
  The 5x5 environment is separated into 2 sub-groups, the 3x3 nearest
  neighbors (8 pixels called Near), and the second order neighborhood
  around them (16 pixels called Far).
- `unshrp_cfg`: unsharpness config. [`ipu3_uapi_unsharp_cfg`](#c-struct-ipu3_uapi_unsharp_cfg)

#### <a id="c-struct-ipu3_uapi_unsharp_coef0"></a>`struct ipu3_uapi_unsharp_coef0`

Unsharp mask coefficients

**Definition**

```c
struct ipu3_uapi_unsharp_coef0 {
    __u32 c00:9;
    __u32 c01:9;
    __u32 c02:9;
    __u32 reserved:5;
};
```

**Members**

- `c00`: Coeff11, s0.8, range \[-255, 255\], default 1.
- `c01`: Coeff12, s0.8, range \[-255, 255\], default 5.
- `c02`: Coeff13, s0.8, range \[-255, 255\], default 9.
- `reserved`: reserved

**Description**

Configurable registers for common sharpening support.

#### <a id="c-struct-ipu3_uapi_unsharp_coef1"></a>`struct ipu3_uapi_unsharp_coef1`

Unsharp mask coefficients

**Definition**

```c
struct ipu3_uapi_unsharp_coef1 {
    __u32 c11:9;
    __u32 c12:9;
    __u32 c22:9;
    __u32 reserved:5;
};
```

**Members**

- `c11`: Coeff22, s0.8, range \[-255, 255\], default 29.
- `c12`: Coeff23, s0.8, range \[-255, 255\], default 55.
- `c22`: Coeff33, s0.8, range \[-255, 255\], default 96.
- `reserved`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_iefd_unshrp_cfg"></a>`struct ipu3_uapi_yuvp1_iefd_unshrp_cfg`

Unsharp mask config

**Definition**

```c
struct ipu3_uapi_yuvp1_iefd_unshrp_cfg {
    struct ipu3_uapi_unsharp_coef0 unsharp_coef0;
    struct ipu3_uapi_unsharp_coef1 unsharp_coef1;
};
```

**Members**

- `unsharp_coef0`: unsharp coefficient 0 config. See [`ipu3_uapi_unsharp_coef0`](#c-struct-ipu3_uapi_unsharp_coef0)
- `unsharp_coef1`: unsharp coefficient 1 config. See [`ipu3_uapi_unsharp_coef1`](#c-struct-ipu3_uapi_unsharp_coef1)

#### <a id="c-struct-ipu3_uapi_radial_reset_xy"></a>`struct ipu3_uapi_radial_reset_xy`

Radial coordinate reset

**Definition**

```c
struct ipu3_uapi_radial_reset_xy {
    __s32 x:13;
    __u32 reserved0:3;
    __s32 y:13;
    __u32 reserved1:3;
};
```

**Members**

- `x`: Radial reset of x coordinate. Precision s12, \[-4095, 4095\], default 0.
- `reserved0`: reserved
- `y`: Radial center y coordinate. Precision s12, \[-4095, 4095\], default 0.
- `reserved1`: reserved

#### <a id="c-struct-ipu3_uapi_radial_reset_x2"></a>`struct ipu3_uapi_radial_reset_x2`

Radial X^2 reset

**Definition**

```c
struct ipu3_uapi_radial_reset_x2 {
    __u32 x2:24;
    __u32 reserved:8;
};
```

**Members**

- `x2`: Radial reset of x^2 coordinate. Precision u24, default 0.
- `reserved`: reserved

#### <a id="c-struct-ipu3_uapi_radial_reset_y2"></a>`struct ipu3_uapi_radial_reset_y2`

Radial Y^2 reset

**Definition**

```c
struct ipu3_uapi_radial_reset_y2 {
    __u32 y2:24;
    __u32 reserved:8;
};
```

**Members**

- `y2`: Radial reset of y^2 coordinate. Precision u24, default 0.
- `reserved`: reserved

#### <a id="c-struct-ipu3_uapi_radial_cfg"></a>`struct ipu3_uapi_radial_cfg`

Radial config

**Definition**

```c
struct ipu3_uapi_radial_cfg {
    __u32 rad_nf:4;
    __u32 reserved0:4;
    __u32 rad_inv_r2:7;
    __u32 reserved1:17;
};
```

**Members**

- `rad_nf`: Radial. R^2 normalization factor is scale down by 2^ - (15 + scale)
- `reserved0`: reserved
- `rad_inv_r2`: Radial R^-2 normelized to (0.5..1).
  Precision u7, range \[0, 127\].
- `reserved1`: reserved

#### <a id="c-struct-ipu3_uapi_rad_far_w"></a>`struct ipu3_uapi_rad_far_w`

Radial FAR sub-group

**Definition**

```c
struct ipu3_uapi_rad_far_w {
    __u32 rad_dir_far_sharp_w:8;
    __u32 rad_dir_far_dns_w:8;
    __u32 rad_ndir_far_dns_power:8;
    __u32 reserved:8;
};
```

**Members**

- `rad_dir_far_sharp_w`: Weight of wide direct sharpening, u1.6, range \[0, 64\],
  default 64.
- `rad_dir_far_dns_w`: Weight of wide direct denoising, u1.6, range \[0, 64\],
  default 0.
- `rad_ndir_far_dns_power`: power of non-direct sharpening, u1.6, range \[0, 64\],
  default 0.
- `reserved`: reserved

#### <a id="c-struct-ipu3_uapi_cu_cfg0"></a>`struct ipu3_uapi_cu_cfg0`

Radius Config Unit cfg0 register

**Definition**

```c
struct ipu3_uapi_cu_cfg0 {
    __u32 cu6_pow:7;
    __u32 reserved0:1;
    __u32 cu_unsharp_pow:7;
    __u32 reserved1:1;
    __u32 rad_cu6_pow:7;
    __u32 reserved2:1;
    __u32 rad_cu_unsharp_pow:6;
    __u32 reserved3:2;
};
```

**Members**

- `cu6_pow`: Power of CU6. Power of non-direct sharpening, u3.4.
- `reserved0`: reserved
- `cu_unsharp_pow`: Power of unsharp mask, u2.4.
- `reserved1`: reserved
- `rad_cu6_pow`: Radial/corner CU6. Directed sharpening power, u3.4.
- `reserved2`: reserved
- `rad_cu_unsharp_pow`: Radial power of unsharp mask, u2.4.
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_cu_cfg1"></a>`struct ipu3_uapi_cu_cfg1`

Radius Config Unit cfg1 register

**Definition**

```c
struct ipu3_uapi_cu_cfg1 {
    __u32 rad_cu6_x1:9;
    __u32 reserved0:1;
    __u32 rad_cu_unsharp_x1:9;
    __u32 reserved1:13;
};
```

**Members**

- `rad_cu6_x1`: X1 point of Config Unit 6, precision u9.0.
- `reserved0`: reserved
- `rad_cu_unsharp_x1`: X1 point for Config Unit unsharp for radial/corner point
  precision u9.0.
- `reserved1`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_iefd_rad_cfg"></a>`struct ipu3_uapi_yuvp1_iefd_rad_cfg`

IEFd parameters changed radially over the picture plane.

**Definition**

```c
struct ipu3_uapi_yuvp1_iefd_rad_cfg {
    struct ipu3_uapi_radial_reset_xy reset_xy;
    struct ipu3_uapi_radial_reset_x2 reset_x2;
    struct ipu3_uapi_radial_reset_y2 reset_y2;
    struct ipu3_uapi_radial_cfg cfg;
    struct ipu3_uapi_rad_far_w rad_far_w;
    struct ipu3_uapi_cu_cfg0 cu_cfg0;
    struct ipu3_uapi_cu_cfg1 cu_cfg1;
};
```

**Members**

- `reset_xy`: reset xy value in radial calculation. [`ipu3_uapi_radial_reset_xy`](#c-struct-ipu3_uapi_radial_reset_xy)
- `reset_x2`: reset x square value in radial calculation. See struct
  [`ipu3_uapi_radial_reset_x2`](#c-struct-ipu3_uapi_radial_reset_x2)
- `reset_y2`: reset y square value in radial calculation. See struct
  [`ipu3_uapi_radial_reset_y2`](#c-struct-ipu3_uapi_radial_reset_y2)
- `cfg`: radial config defined in [`ipu3_uapi_radial_cfg`](#c-struct-ipu3_uapi_radial_cfg)
- `rad_far_w`: weight for wide range radial. [`ipu3_uapi_rad_far_w`](#c-struct-ipu3_uapi_rad_far_w)
- `cu_cfg0`: configuration unit 0. See [`ipu3_uapi_cu_cfg0`](#c-struct-ipu3_uapi_cu_cfg0)
- `cu_cfg1`: configuration unit 1. See [`ipu3_uapi_cu_cfg1`](#c-struct-ipu3_uapi_cu_cfg1)

#### <a id="c-struct-ipu3_uapi_vss_lut_x"></a>`struct ipu3_uapi_vss_lut_x`

Vssnlm LUT x0/x1/x2

**Definition**

```c
struct ipu3_uapi_vss_lut_x {
    __u32 vs_x0:8;
    __u32 vs_x1:8;
    __u32 vs_x2:8;
    __u32 reserved2:8;
};
```

**Members**

- `vs_x0`: Vssnlm LUT x0, precision u8, range \[0, 255\], default 16.
- `vs_x1`: Vssnlm LUT x1, precision u8, range \[0, 255\], default 32.
- `vs_x2`: Vssnlm LUT x2, precision u8, range \[0, 255\], default 64.
- `reserved2`: reserved

#### <a id="c-struct-ipu3_uapi_vss_lut_y"></a>`struct ipu3_uapi_vss_lut_y`

Vssnlm LUT y0/y1/y2

**Definition**

```c
struct ipu3_uapi_vss_lut_y {
    __u32 vs_y1:4;
    __u32 reserved0:4;
    __u32 vs_y2:4;
    __u32 reserved1:4;
    __u32 vs_y3:4;
    __u32 reserved2:12;
};
```

**Members**

- `vs_y1`: Vssnlm LUT y1, precision u4, range \[0, 8\], default 1.
- `reserved0`: reserved
- `vs_y2`: Vssnlm LUT y2, precision u4, range \[0, 8\], default 3.
- `reserved1`: reserved
- `vs_y3`: Vssnlm LUT y3, precision u4, range \[0, 8\], default 8.
- `reserved2`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_iefd_vssnlm_cfg"></a>`struct ipu3_uapi_yuvp1_iefd_vssnlm_cfg`

IEFd Vssnlm Lookup table

**Definition**

```c
struct ipu3_uapi_yuvp1_iefd_vssnlm_cfg {
    struct ipu3_uapi_vss_lut_x vss_lut_x;
    struct ipu3_uapi_vss_lut_y vss_lut_y;
};
```

**Members**

- `vss_lut_x`: vss lookup table. See [`ipu3_uapi_vss_lut_x`](#c-struct-ipu3_uapi_vss_lut_x) description
- `vss_lut_y`: vss lookup table. See [`ipu3_uapi_vss_lut_y`](#c-struct-ipu3_uapi_vss_lut_y) description

#### <a id="c-struct-ipu3_uapi_yuvp1_iefd_config"></a>`struct ipu3_uapi_yuvp1_iefd_config`

IEFd config

**Definition**

```c
struct ipu3_uapi_yuvp1_iefd_config {
    struct ipu3_uapi_yuvp1_iefd_cfg_units units;
    struct ipu3_uapi_yuvp1_iefd_config_s config;
    struct ipu3_uapi_yuvp1_iefd_control control;
    struct ipu3_uapi_yuvp1_iefd_shrp_cfg sharp;
    struct ipu3_uapi_yuvp1_iefd_unshrp_cfg unsharp;
    struct ipu3_uapi_yuvp1_iefd_rad_cfg rad;
    struct ipu3_uapi_yuvp1_iefd_vssnlm_cfg vsslnm;
};
```

**Members**

- `units`: configuration unit setting, [`ipu3_uapi_yuvp1_iefd_cfg_units`](#c-struct-ipu3_uapi_yuvp1_iefd_cfg_units)
- `config`: configuration, as defined by [`ipu3_uapi_yuvp1_iefd_config_s`](#c-struct-ipu3_uapi_yuvp1_iefd_config_s)
- `control`: control setting, as defined by [`ipu3_uapi_yuvp1_iefd_control`](#c-struct-ipu3_uapi_yuvp1_iefd_control)
- `sharp`: sharpness setting, as defined by [`ipu3_uapi_yuvp1_iefd_shrp_cfg`](#c-struct-ipu3_uapi_yuvp1_iefd_shrp_cfg)
- `unsharp`: unsharpness setting, as defined by [`ipu3_uapi_yuvp1_iefd_unshrp_cfg`](#c-struct-ipu3_uapi_yuvp1_iefd_unshrp_cfg)
- `rad`: radial setting, as defined by [`ipu3_uapi_yuvp1_iefd_rad_cfg`](#c-struct-ipu3_uapi_yuvp1_iefd_rad_cfg)
- `vsslnm`: vsslnm setting, as defined by [`ipu3_uapi_yuvp1_iefd_vssnlm_cfg`](#c-struct-ipu3_uapi_yuvp1_iefd_vssnlm_cfg)

#### <a id="c-struct-ipu3_uapi_yuvp1_yds_config"></a>`struct ipu3_uapi_yuvp1_yds_config`

Y Down-Sampling config

**Definition**

```c
struct ipu3_uapi_yuvp1_yds_config {
    __u32 c00:2;
    __u32 c01:2;
    __u32 c02:2;
    __u32 c03:2;
    __u32 c10:2;
    __u32 c11:2;
    __u32 c12:2;
    __u32 c13:2;
    __u32 norm_factor:5;
    __u32 reserved0:4;
    __u32 bin_output:1;
    __u32 reserved1:6;
};
```

**Members**

- `c00`: range \[0, 3\], default 0x0
- `c01`: range \[0, 3\], default 0x1
- `c02`: range \[0, 3\], default 0x1
- `c03`: range \[0, 3\], default 0x0
- `c10`: range \[0, 3\], default 0x0
- `c11`: range \[0, 3\], default 0x1
- `c12`: range \[0, 3\], default 0x1
- `c13`: range \[0, 3\], default 0x0
- `norm_factor`: Normalization factor, range \[0, 4\], default 2
  0 - divide by 1
  1 - divide by 2
  2 - divide by 4
  3 - divide by 8
  4 - divide by 16
- `reserved0`: reserved
- `bin_output`: Down sampling on Luma channel in two optional modes
  0 - Bin output 4.2.0 (default), 1 output 4.2.2.
- `reserved1`: reserved

**Description**

Above are 4x2 filter coefficients for chroma output downscaling.

#### <a id="c-struct-ipu3_uapi_yuvp1_chnr_enable_config"></a>`struct ipu3_uapi_yuvp1_chnr_enable_config`

Chroma noise reduction enable

**Definition**

```c
struct ipu3_uapi_yuvp1_chnr_enable_config {
    __u32 enable:1;
    __u32 yuv_mode:1;
    __u32 reserved0:14;
    __u32 col_size:12;
    __u32 reserved1:4;
};
```

**Members**

- `enable`: enable/disable chroma noise reduction
- `yuv_mode`: 0 - YUV420, 1 - YUV422
- `reserved0`: reserved
- `col_size`: number of columns in the frame, max width is 2560
- `reserved1`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_chnr_coring_config"></a>`struct ipu3_uapi_yuvp1_chnr_coring_config`

Coring thresholds for UV

**Definition**

```c
struct ipu3_uapi_yuvp1_chnr_coring_config {
    __u32 u:13;
    __u32 reserved0:3;
    __u32 v:13;
    __u32 reserved1:3;
};
```

**Members**

- `u`: U coring level, u0.13, range \[0.0, 1.0\], default 0.0
- `reserved0`: reserved
- `v`: V coring level, u0.13, range \[0.0, 1.0\], default 0.0
- `reserved1`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_chnr_sense_gain_config"></a>`struct ipu3_uapi_yuvp1_chnr_sense_gain_config`

Chroma noise reduction gains

**Definition**

```c
struct ipu3_uapi_yuvp1_chnr_sense_gain_config {
    __u32 vy:8;
    __u32 vu:8;
    __u32 vv:8;
    __u32 reserved0:8;
    __u32 hy:8;
    __u32 hu:8;
    __u32 hv:8;
    __u32 reserved1:8;
};
```

**Members**

- `vy`: Sensitivity of horizontal edge of Y, default 100
- `vu`: Sensitivity of horizontal edge of U, default 100
- `vv`: Sensitivity of horizontal edge of V, default 100
- `reserved0`: reserved
- `hy`: Sensitivity of vertical edge of Y, default 50
- `hu`: Sensitivity of vertical edge of U, default 50
- `hv`: Sensitivity of vertical edge of V, default 50
- `reserved1`: reserved

**Description**

All sensitivity gain parameters have precision u13.0, range \[0, 8191\].

#### <a id="c-struct-ipu3_uapi_yuvp1_chnr_iir_fir_config"></a>`struct ipu3_uapi_yuvp1_chnr_iir_fir_config`

Chroma IIR/FIR filter config

**Definition**

```c
struct ipu3_uapi_yuvp1_chnr_iir_fir_config {
    __u32 fir_0h:6;
    __u32 reserved0:2;
    __u32 fir_1h:6;
    __u32 reserved1:2;
    __u32 fir_2h:6;
    __u32 dalpha_clip_val:9;
    __u32 reserved2:1;
};
```

**Members**

- `fir_0h`: Value of center tap in horizontal FIR, range \[0, 32\], default 8.
- `reserved0`: reserved
- `fir_1h`: Value of distance 1 in horizontal FIR, range \[0, 32\], default 12.
- `reserved1`: reserved
- `fir_2h`: Value of distance 2 tap in horizontal FIR, range \[0, 32\], default 0.
- `dalpha_clip_val`: weight for previous row in IIR, range \[1, 256\], default 0.
- `reserved2`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_chnr_config"></a>`struct ipu3_uapi_yuvp1_chnr_config`

Chroma noise reduction config

**Definition**

```c
struct ipu3_uapi_yuvp1_chnr_config {
    struct ipu3_uapi_yuvp1_chnr_enable_config enable;
    struct ipu3_uapi_yuvp1_chnr_coring_config coring;
    struct ipu3_uapi_yuvp1_chnr_sense_gain_config sense_gain;
    struct ipu3_uapi_yuvp1_chnr_iir_fir_config iir_fir;
};
```

**Members**

- `enable`: chroma noise reduction enable, see
  [`ipu3_uapi_yuvp1_chnr_enable_config`](#c-struct-ipu3_uapi_yuvp1_chnr_enable_config)
- `coring`: coring config for chroma noise reduction, see
  [`ipu3_uapi_yuvp1_chnr_coring_config`](#c-struct-ipu3_uapi_yuvp1_chnr_coring_config)
- `sense_gain`: sensitivity config for chroma noise reduction, see
  ipu3_uapi_yuvp1_chnr_sense_gain_config
- `iir_fir`: iir and fir config for chroma noise reduction, see
  ipu3_uapi_yuvp1_chnr_iir_fir_config

#### <a id="c-struct-ipu3_uapi_yuvp1_y_ee_nr_lpf_config"></a>`struct ipu3_uapi_yuvp1_y_ee_nr_lpf_config`

Luma(Y) edge enhancement low-pass filter coefficients

**Definition**

```c
struct ipu3_uapi_yuvp1_y_ee_nr_lpf_config {
    __u32 a_diag:5;
    __u32 reserved0:3;
    __u32 a_periph:5;
    __u32 reserved1:3;
    __u32 a_cent:5;
    __u32 reserved2:9;
    __u32 enable:1;
};
```

**Members**

- `a_diag`: Smoothing diagonal coefficient, u5.0.
- `reserved0`: reserved
- `a_periph`: Image smoothing perpherial, u5.0.
- `reserved1`: reserved
- `a_cent`: Image Smoothing center coefficient, u5.0.
- `reserved2`: reserved
- `enable`: 0: Y_EE_NR disabled, output = input; 1: Y_EE_NR enabled.

#### <a id="c-struct-ipu3_uapi_yuvp1_y_ee_nr_sense_config"></a>`struct ipu3_uapi_yuvp1_y_ee_nr_sense_config`

Luma(Y) edge enhancement noise reduction sensitivity gains

**Definition**

```c
struct ipu3_uapi_yuvp1_y_ee_nr_sense_config {
    __u32 edge_sense_0:13;
    __u32 reserved0:3;
    __u32 delta_edge_sense:13;
    __u32 reserved1:3;
    __u32 corner_sense_0:13;
    __u32 reserved2:3;
    __u32 delta_corner_sense:13;
    __u32 reserved3:3;
};
```

**Members**

- `edge_sense_0`: Sensitivity of edge in dark area. u13.0, default 8191.
- `reserved0`: reserved
- `delta_edge_sense`: Difference in the sensitivity of edges between
  the bright and dark areas. u13.0, default 0.
- `reserved1`: reserved
- `corner_sense_0`: Sensitivity of corner in dark area. u13.0, default 0.
- `reserved2`: reserved
- `delta_corner_sense`: Difference in the sensitivity of corners between
  the bright and dark areas. u13.0, default 8191.
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_y_ee_nr_gain_config"></a>`struct ipu3_uapi_yuvp1_y_ee_nr_gain_config`

Luma(Y) edge enhancement noise reduction gain config

**Definition**

```c
struct ipu3_uapi_yuvp1_y_ee_nr_gain_config {
    __u32 gain_pos_0:5;
    __u32 reserved0:3;
    __u32 delta_gain_posi:5;
    __u32 reserved1:3;
    __u32 gain_neg_0:5;
    __u32 reserved2:3;
    __u32 delta_gain_neg:5;
    __u32 reserved3:3;
};
```

**Members**

- `gain_pos_0`: Gain for positive edge in dark area. u5.0, \[0, 16\], default 2.
- `reserved0`: reserved
- `delta_gain_posi`: Difference in the gain of edges between the bright and
  dark areas for positive edges. u5.0, \[0, 16\], default 0.
- `reserved1`: reserved
- `gain_neg_0`: Gain for negative edge in dark area. u5.0, \[0, 16\], default 8.
- `reserved2`: reserved
- `delta_gain_neg`: Difference in the gain of edges between the bright and
  dark areas for negative edges. u5.0, \[0, 16\], default 0.
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_y_ee_nr_clip_config"></a>`struct ipu3_uapi_yuvp1_y_ee_nr_clip_config`

Luma(Y) edge enhancement noise reduction clipping config

**Definition**

```c
struct ipu3_uapi_yuvp1_y_ee_nr_clip_config {
    __u32 clip_pos_0:5;
    __u32 reserved0:3;
    __u32 delta_clip_posi:5;
    __u32 reserved1:3;
    __u32 clip_neg_0:5;
    __u32 reserved2:3;
    __u32 delta_clip_neg:5;
    __u32 reserved3:3;
};
```

**Members**

- `clip_pos_0`: Limit of positive edge in dark area
  u5, value \[0, 16\], default 8.
- `reserved0`: reserved
- `delta_clip_posi`: Difference in the limit of edges between the bright
  and dark areas for positive edges.
  u5, value \[0, 16\], default 8.
- `reserved1`: reserved
- `clip_neg_0`: Limit of negative edge in dark area
  u5, value \[0, 16\], default 8.
- `reserved2`: reserved
- `delta_clip_neg`: Difference in the limit of edges between the bright
  and dark areas for negative edges.
  u5, value \[0, 16\], default 8.
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_y_ee_nr_frng_config"></a>`struct ipu3_uapi_yuvp1_y_ee_nr_frng_config`

Luma(Y) edge enhancement noise reduction fringe config

**Definition**

```c
struct ipu3_uapi_yuvp1_y_ee_nr_frng_config {
    __u32 gain_exp:4;
    __u32 reserved0:28;
    __u32 min_edge:13;
    __u32 reserved1:3;
    __u32 lin_seg_param:4;
    __u32 reserved2:4;
    __u32 t1:1;
    __u32 t2:1;
    __u32 reserved3:6;
};
```

**Members**

- `gain_exp`: Common exponent of gains, u4, \[0, 8\], default 2.
- `reserved0`: reserved
- `min_edge`: Threshold for edge and smooth stitching, u13.
- `reserved1`: reserved
- `lin_seg_param`: Power of LinSeg, u4.
- `reserved2`: reserved
- `t1`: Parameter for enabling/disabling the edge enhancement, u1.0, \[0, 1\],
  default 1.
- `t2`: Parameter for enabling/disabling the smoothing, u1.0, \[0, 1\],
  default 1.
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_y_ee_nr_diag_config"></a>`struct ipu3_uapi_yuvp1_y_ee_nr_diag_config`

Luma(Y) edge enhancement noise reduction diagonal config

**Definition**

```c
struct ipu3_uapi_yuvp1_y_ee_nr_diag_config {
    __u32 diag_disc_g:4;
    __u32 reserved0:4;
    __u32 hvw_hor:4;
    __u32 dw_hor:4;
    __u32 hvw_diag:4;
    __u32 dw_diag:4;
    __u32 reserved1:8;
};
```

**Members**

- `diag_disc_g`: Coefficient that prioritize diagonal edge direction on
  horizontal or vertical for final enhancement.
  u4.0, \[1, 15\], default 1.
- `reserved0`: reserved
- `hvw_hor`: Weight of horizontal/vertical edge enhancement for hv edge.
  u2.2, \[1, 15\], default 4.
- `dw_hor`: Weight of diagonal edge enhancement for hv edge.
  u2.2, \[1, 15\], default 1.
- `hvw_diag`: Weight of horizontal/vertical edge enhancement for diagonal edge.
  u2.2, \[1, 15\], default 1.
- `dw_diag`: Weight of diagonal edge enhancement for diagonal edge.
  u2.2, \[1, 15\], default 4.
- `reserved1`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp1_y_ee_nr_fc_coring_config"></a>`struct ipu3_uapi_yuvp1_y_ee_nr_fc_coring_config`

Luma(Y) edge enhancement noise reduction false color correction (FCC) coring config

**Definition**

```c
struct ipu3_uapi_yuvp1_y_ee_nr_fc_coring_config {
    __u32 pos_0:13;
    __u32 reserved0:3;
    __u32 pos_delta:13;
    __u32 reserved1:3;
    __u32 neg_0:13;
    __u32 reserved2:3;
    __u32 neg_delta:13;
    __u32 reserved3:3;
};
```

**Members**

- `pos_0`: Gain for positive edge in dark, u13.0, \[0, 16\], default 0.
- `reserved0`: reserved
- `pos_delta`: Gain for positive edge in bright, value: pos_0 + pos_delta \<=16
  u13.0, default 0.
- `reserved1`: reserved
- `neg_0`: Gain for negative edge in dark area, u13.0, range \[0, 16\], default 0.
- `reserved2`: reserved
- `neg_delta`: Gain for negative edge in bright area. neg_0 + neg_delta \<=16
  u13.0, default 0.
- `reserved3`: reserved

**Description**

Coring is a simple soft thresholding technique.

#### <a id="c-struct-ipu3_uapi_yuvp1_y_ee_nr_config"></a>`struct ipu3_uapi_yuvp1_y_ee_nr_config`

Edge enhancement and noise reduction

**Definition**

```c
struct ipu3_uapi_yuvp1_y_ee_nr_config {
    struct ipu3_uapi_yuvp1_y_ee_nr_lpf_config lpf;
    struct ipu3_uapi_yuvp1_y_ee_nr_sense_config sense;
    struct ipu3_uapi_yuvp1_y_ee_nr_gain_config gain;
    struct ipu3_uapi_yuvp1_y_ee_nr_clip_config clip;
    struct ipu3_uapi_yuvp1_y_ee_nr_frng_config frng;
    struct ipu3_uapi_yuvp1_y_ee_nr_diag_config diag;
    struct ipu3_uapi_yuvp1_y_ee_nr_fc_coring_config fc_coring;
};
```

**Members**

- `lpf`: low-pass filter config. See [`ipu3_uapi_yuvp1_y_ee_nr_lpf_config`](#c-struct-ipu3_uapi_yuvp1_y_ee_nr_lpf_config)
- `sense`: sensitivity config. See [`ipu3_uapi_yuvp1_y_ee_nr_sense_config`](#c-struct-ipu3_uapi_yuvp1_y_ee_nr_sense_config)
- `gain`: gain config as defined in [`ipu3_uapi_yuvp1_y_ee_nr_gain_config`](#c-struct-ipu3_uapi_yuvp1_y_ee_nr_gain_config)
- `clip`: clip config as defined in [`ipu3_uapi_yuvp1_y_ee_nr_clip_config`](#c-struct-ipu3_uapi_yuvp1_y_ee_nr_clip_config)
- `frng`: fringe config as defined in [`ipu3_uapi_yuvp1_y_ee_nr_frng_config`](#c-struct-ipu3_uapi_yuvp1_y_ee_nr_frng_config)
- `diag`: diagonal edge config. See [`ipu3_uapi_yuvp1_y_ee_nr_diag_config`](#c-struct-ipu3_uapi_yuvp1_y_ee_nr_diag_config)
- `fc_coring`: coring config for fringe control. See
  [`ipu3_uapi_yuvp1_y_ee_nr_fc_coring_config`](#c-struct-ipu3_uapi_yuvp1_y_ee_nr_fc_coring_config)

#### <a id="c-struct-ipu3_uapi_yuvp2_tcc_gen_control_static_config"></a>`struct ipu3_uapi_yuvp2_tcc_gen_control_static_config`

Total color correction general control config

**Definition**

```c
struct ipu3_uapi_yuvp2_tcc_gen_control_static_config {
    __u32 en:1;
    __u32 blend_shift:3;
    __u32 gain_according_to_y_only:1;
    __u32 reserved0:11;
    __s32 gamma:5;
    __u32 reserved1:3;
    __s32 delta:5;
    __u32 reserved2:3;
};
```

**Members**

- `en`: 0 - TCC disabled. Output = input 1 - TCC enabled.
- `blend_shift`: blend shift, Range\[3, 4\], default NA.
- `gain_according_to_y_only`: 0: Gain is calculated according to YUV,
  1: Gain is calculated according to Y only
- `reserved0`: reserved
- `gamma`: Final blending coefficients. Values\[-16, 16\], default NA.
- `reserved1`: reserved
- `delta`: Final blending coefficients. Values\[-16, 16\], default NA.
- `reserved2`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp2_tcc_macc_elem_static_config"></a>`struct ipu3_uapi_yuvp2_tcc_macc_elem_static_config`

Total color correction multi-axis color control (MACC) config

**Definition**

```c
struct ipu3_uapi_yuvp2_tcc_macc_elem_static_config {
    __s32 a:12;
    __u32 reserved0:4;
    __s32 b:12;
    __u32 reserved1:4;
    __s32 c:12;
    __u32 reserved2:4;
    __s32 d:12;
    __u32 reserved3:4;
};
```

**Members**

- `a`: a coefficient for 2x2 MACC conversion matrix.
- `reserved0`: reserved
- `b`: b coefficient  2x2 MACC conversion matrix.
- `reserved1`: reserved
- `c`: c coefficient for 2x2 MACC conversion matrix.
- `reserved2`: reserved
- `d`: d coefficient for 2x2 MACC conversion matrix.
- `reserved3`: reserved

#### <a id="c-struct-ipu3_uapi_yuvp2_tcc_macc_table_static_config"></a>`struct ipu3_uapi_yuvp2_tcc_macc_table_static_config`

Total color correction multi-axis color control (MACC) table array

**Definition**

```c
struct ipu3_uapi_yuvp2_tcc_macc_table_static_config {
    struct ipu3_uapi_yuvp2_tcc_macc_elem_static_config entries[IPU3_UAPI_YUVP2_TCC_MACC_TABLE_ELEMENTS];
};
```

**Members**

- `entries`: config for multi axis color correction, as specified by
  [`ipu3_uapi_yuvp2_tcc_macc_elem_static_config`](#c-struct-ipu3_uapi_yuvp2_tcc_macc_elem_static_config)

#### <a id="c-struct-ipu3_uapi_yuvp2_tcc_inv_y_lut_static_config"></a>`struct ipu3_uapi_yuvp2_tcc_inv_y_lut_static_config`

Total color correction inverse y lookup table

**Definition**

```c
struct ipu3_uapi_yuvp2_tcc_inv_y_lut_static_config {
    __u16 entries[IPU3_UAPI_YUVP2_TCC_INV_Y_LUT_ELEMENTS];
};
```

**Members**

- `entries`: lookup table for inverse y estimation, and use it to estimate the
  ratio between luma and chroma. Chroma by approximate the absolute
  value of the radius on the chroma plane (R = sqrt(u^2+v^2) ) and
  luma by approximate by 1/Y.

#### <a id="c-struct-ipu3_uapi_yuvp2_tcc_gain_pcwl_lut_static_config"></a>`struct ipu3_uapi_yuvp2_tcc_gain_pcwl_lut_static_config`

Total color correction lookup table for PCWL

**Definition**

```c
struct ipu3_uapi_yuvp2_tcc_gain_pcwl_lut_static_config {
    __u16 entries[IPU3_UAPI_YUVP2_TCC_GAIN_PCWL_LUT_ELEMENTS];
};
```

**Members**

- `entries`: lookup table for gain piece wise linear transformation (PCWL)

#### <a id="c-struct-ipu3_uapi_yuvp2_tcc_r_sqr_lut_static_config"></a>`struct ipu3_uapi_yuvp2_tcc_r_sqr_lut_static_config`

Total color correction lookup table for r square root

**Definition**

```c
struct ipu3_uapi_yuvp2_tcc_r_sqr_lut_static_config {
    __s16 entries[IPU3_UAPI_YUVP2_TCC_R_SQR_LUT_ELEMENTS];
};
```

**Members**

- `entries`: lookup table for r square root estimation

#### <a id="c-struct-ipu3_uapi_yuvp2_tcc_static_config"></a>`struct ipu3_uapi_yuvp2_tcc_static_config`

Total color correction static

**Definition**

```c
struct ipu3_uapi_yuvp2_tcc_static_config {
    struct ipu3_uapi_yuvp2_tcc_gen_control_static_config gen_control;
    struct ipu3_uapi_yuvp2_tcc_macc_table_static_config macc_table;
    struct ipu3_uapi_yuvp2_tcc_inv_y_lut_static_config inv_y_lut;
    struct ipu3_uapi_yuvp2_tcc_gain_pcwl_lut_static_config gain_pcwl;
    struct ipu3_uapi_yuvp2_tcc_r_sqr_lut_static_config r_sqr_lut;
};
```

**Members**

- `gen_control`: general config for Total Color Correction
- `macc_table`: config for multi axis color correction
- `inv_y_lut`: lookup table for inverse y estimation
- `gain_pcwl`: lookup table for gain PCWL
- `r_sqr_lut`: lookup table for r square root estimation.

#### <a id="c-struct-ipu3_uapi_anr_transform_config"></a>`struct ipu3_uapi_anr_transform_config`

Advanced noise reduction transform

**Definition**

```c
struct ipu3_uapi_anr_transform_config {
    __u32 enable:1;
    __u32 adaptive_treshhold_en:1;
    __u32 reserved1:30;
    __u8 reserved2[44];
    struct ipu3_uapi_anr_alpha alpha[3];
    struct ipu3_uapi_anr_beta beta[3];
    struct ipu3_uapi_anr_plane_color color[3];
    __u16 sqrt_lut[IPU3_UAPI_ANR_LUT_SIZE];
    __s16 xreset:13;
    __u16 reserved3:3;
    __s16 yreset:13;
    __u16 reserved4:3;
    __u32 x_sqr_reset:24;
    __u32 r_normfactor:5;
    __u32 reserved5:3;
    __u32 y_sqr_reset:24;
    __u32 gain_scale:8;
};
```

**Members**

- `enable`: advanced noise reduction enabled.
- `adaptive_treshhold_en`: On IPU3, adaptive threshold is always enabled.
- `reserved1`: reserved
- `reserved2`: reserved
- `alpha`: using following defaults:
  13, 13, 13, 13, 0, 0, 0, 0
  11, 11, 11, 11, 0, 0, 0, 0
  14,  14, 14, 14, 0, 0, 0, 0
- `beta`: use following defaults:
  24, 24, 24, 24
  21, 20, 20, 21
  25, 25, 25, 25
- `color`: use defaults defined in driver/media/pci/intel/ipu3-tables.c
- `sqrt_lut`: 11 bits per element, values =
  \[724 768 810 849 887
  923 958 991 1024 1056
  1116 1145 1173 1201 1086
  1228 1254 1280 1305 1330
  1355 1379 1402 1425 1448\]
- `xreset`: Reset value of X for r^2 calculation Value: col_start-X_center
  Constraint: Xreset + FrameWdith=4095 Xreset= -4095, default -1632.
- `reserved3`: reserved
- `yreset`: Reset value of Y for r^2 calculation Value: row_start-Y_center
  Constraint: Yreset + FrameHeight=4095 Yreset= -4095, default -1224.
- `reserved4`: reserved
- `x_sqr_reset`: Reset value of X^2 for r^2 calculation Value = (Xreset)^2
- `r_normfactor`: Normalization factor for R. Default 14.
- `reserved5`: reserved
- `y_sqr_reset`: Reset value of Y^2 for r^2 calculation Value = (Yreset)^2
- `gain_scale`: Parameter describing shading gain as a function of distance
  from the image center.
  A single value per frame, loaded by the driver. Default 115.

#### <a id="c-struct-ipu3_uapi_anr_stitch_pyramid"></a>`struct ipu3_uapi_anr_stitch_pyramid`

ANR stitch pyramid

**Definition**

```c
struct ipu3_uapi_anr_stitch_pyramid {
    __u32 entry0:6;
    __u32 entry1:6;
    __u32 entry2:6;
    __u32 reserved:14;
};
```

**Members**

- `entry0`: pyramid LUT entry0, range \[0x0, 0x3f\]
- `entry1`: pyramid LUT entry1, range \[0x0, 0x3f\]
- `entry2`: pyramid LUT entry2, range \[0x0, 0x3f\]
- `reserved`: reserved

#### <a id="c-struct-ipu3_uapi_anr_stitch_config"></a>`struct ipu3_uapi_anr_stitch_config`

ANR stitch config

**Definition**

```c
struct ipu3_uapi_anr_stitch_config {
    __u32 anr_stitch_en;
    __u8 reserved[44];
    struct ipu3_uapi_anr_stitch_pyramid pyramid[IPU3_UAPI_ANR_PYRAMID_SIZE];
};
```

**Members**

- `anr_stitch_en`: enable stitch. Enabled with 1.
- `reserved`: reserved
- `pyramid`: pyramid table as defined by [`ipu3_uapi_anr_stitch_pyramid`](#c-struct-ipu3_uapi_anr_stitch_pyramid)
  default values:
  { 1, 3, 5 }, { 7, 7, 5 }, { 3, 1, 3 },
  { 9, 15, 21 }, { 21, 15, 9 }, { 3, 5, 15 },
  { 25, 35, 35 }, { 25, 15, 5 }, { 7, 21, 35 },
  { 49, 49, 35 }, { 21, 7, 7 }, { 21, 35, 49 },
  { 49, 35, 21 }, { 7, 5, 15 }, { 25, 35, 35 },
  { 25, 15, 5 }, { 3, 9, 15 }, { 21, 21, 15 },
  { 9, 3, 1 }, { 3, 5, 7 }, { 7, 5, 3}, { 1 }

#### <a id="c-struct-ipu3_uapi_anr_config"></a>`struct ipu3_uapi_anr_config`

ANR config

**Definition**

```c
struct ipu3_uapi_anr_config {
    struct ipu3_uapi_anr_transform_config transform  ;
    struct ipu3_uapi_anr_stitch_config stitch  ;
};
```

**Members**

- `transform`: advanced noise reduction transform config as specified by
  [`ipu3_uapi_anr_transform_config`](#c-struct-ipu3_uapi_anr_transform_config)
- `stitch`: create 4x4 patch from 4 surrounding 8x8 patches.

#### <a id="c-struct-ipu3_uapi_acc_param"></a>`struct ipu3_uapi_acc_param`

Accelerator cluster parameters

**Definition**

```c
struct ipu3_uapi_acc_param {
    struct ipu3_uapi_bnr_static_config bnr;
    struct ipu3_uapi_bnr_static_config_green_disparity green_disparity  ;
    struct ipu3_uapi_dm_config dm  ;
    struct ipu3_uapi_ccm_mat_config ccm  ;
    struct ipu3_uapi_gamma_config gamma  ;
    struct ipu3_uapi_csc_mat_config csc  ;
    struct ipu3_uapi_cds_params cds  ;
    struct ipu3_uapi_shd_config shd  ;
    struct ipu3_uapi_yuvp1_iefd_config iefd  ;
    struct ipu3_uapi_yuvp1_yds_config yds_c0  ;
    struct ipu3_uapi_yuvp1_chnr_config chnr_c0  ;
    struct ipu3_uapi_yuvp1_y_ee_nr_config y_ee_nr  ;
    struct ipu3_uapi_yuvp1_yds_config yds  ;
    struct ipu3_uapi_yuvp1_chnr_config chnr  ;
    struct ipu3_uapi_yuvp1_yds_config yds2  ;
    struct ipu3_uapi_yuvp2_tcc_static_config tcc  ;
    struct ipu3_uapi_anr_config anr;
    struct ipu3_uapi_awb_fr_config_s awb_fr;
    struct ipu3_uapi_ae_config ae;
    struct ipu3_uapi_af_config_s af;
    struct ipu3_uapi_awb_config awb;
};
```

**Members**

- `bnr`: parameters for bayer noise reduction static config. See
  [`ipu3_uapi_bnr_static_config`](#c-struct-ipu3_uapi_bnr_static_config)
- `green_disparity`: disparity static config between gr and gb channel.
  See [`ipu3_uapi_bnr_static_config_green_disparity`](#c-struct-ipu3_uapi_bnr_static_config_green_disparity)
- `dm`: de-mosaic config. See [`ipu3_uapi_dm_config`](#c-struct-ipu3_uapi_dm_config)
- `ccm`: color correction matrix. See [`ipu3_uapi_ccm_mat_config`](#c-struct-ipu3_uapi_ccm_mat_config)
- `gamma`: gamma correction config. See [`ipu3_uapi_gamma_config`](#c-struct-ipu3_uapi_gamma_config)
- `csc`: color space conversion matrix. See [`ipu3_uapi_csc_mat_config`](#c-struct-ipu3_uapi_csc_mat_config)
- `cds`: color down sample config. See [`ipu3_uapi_cds_params`](#c-struct-ipu3_uapi_cds_params)
- `shd`: lens shading correction config. See [`ipu3_uapi_shd_config`](#c-struct-ipu3_uapi_shd_config)
- `iefd`: Image enhancement filter and denoise config.
  [`ipu3_uapi_yuvp1_iefd_config`](#c-struct-ipu3_uapi_yuvp1_iefd_config)
- `yds_c0`: y down scaler config. [`ipu3_uapi_yuvp1_yds_config`](#c-struct-ipu3_uapi_yuvp1_yds_config)
- `chnr_c0`: chroma noise reduction config. [`ipu3_uapi_yuvp1_chnr_config`](#c-struct-ipu3_uapi_yuvp1_chnr_config)
- `y_ee_nr`: y edge enhancement and noise reduction config.
  [`ipu3_uapi_yuvp1_y_ee_nr_config`](#c-struct-ipu3_uapi_yuvp1_y_ee_nr_config)
- `yds`: y down scaler config. See [`ipu3_uapi_yuvp1_yds_config`](#c-struct-ipu3_uapi_yuvp1_yds_config)
- `chnr`: chroma noise reduction config. See [`ipu3_uapi_yuvp1_chnr_config`](#c-struct-ipu3_uapi_yuvp1_chnr_config)
- `yds2`: y channel down scaler config. See [`ipu3_uapi_yuvp1_yds_config`](#c-struct-ipu3_uapi_yuvp1_yds_config)
- `tcc`: total color correction config as defined in struct
  [`ipu3_uapi_yuvp2_tcc_static_config`](#c-struct-ipu3_uapi_yuvp2_tcc_static_config)
- `anr`: advanced noise reduction config.See [`ipu3_uapi_anr_config`](#c-struct-ipu3_uapi_anr_config)
- `awb_fr`: AWB filter response config. See ipu3_uapi_awb_fr_config
- `ae`: auto exposure config  As specified by [`ipu3_uapi_ae_config`](#c-struct-ipu3_uapi_ae_config)
- `af`: auto focus config. As specified by `ipu3_uapi_af_config`
- `awb`: auto white balance config. As specified by [`ipu3_uapi_awb_config`](#c-struct-ipu3_uapi_awb_config)

**Description**

ACC refers to the HW cluster containing all Fixed Functions (FFs). Each FF
implements a specific algorithm.

#### <a id="c-struct-ipu3_uapi_isp_lin_vmem_params"></a>`struct ipu3_uapi_isp_lin_vmem_params`

Linearization parameters

**Definition**

```c
struct ipu3_uapi_isp_lin_vmem_params {
    __s16 lin_lutlow_gr[IPU3_UAPI_LIN_LUT_SIZE];
    __s16 lin_lutlow_r[IPU3_UAPI_LIN_LUT_SIZE];
    __s16 lin_lutlow_b[IPU3_UAPI_LIN_LUT_SIZE];
    __s16 lin_lutlow_gb[IPU3_UAPI_LIN_LUT_SIZE];
    __s16 lin_lutdif_gr[IPU3_UAPI_LIN_LUT_SIZE];
    __s16 lin_lutdif_r[IPU3_UAPI_LIN_LUT_SIZE];
    __s16 lin_lutdif_b[IPU3_UAPI_LIN_LUT_SIZE];
    __s16 lin_lutdif_gb[IPU3_UAPI_LIN_LUT_SIZE];
};
```

**Members**

- `lin_lutlow_gr`: linearization look-up table for GR channel interpolation.
- `lin_lutlow_r`: linearization look-up table for R channel interpolation.
- `lin_lutlow_b`: linearization look-up table for B channel interpolation.
- `lin_lutlow_gb`: linearization look-up table for GB channel interpolation.
  lin_lutlow_gr / lin_lutlow_r / lin_lutlow_b /
  lin_lutlow_gb \<= LIN_MAX_VALUE - 1.
- `lin_lutdif_gr`: lin_lutlow_gr\[i+1\] - lin_lutlow_gr\[i\].
- `lin_lutdif_r`: lin_lutlow_r\[i+1\] - lin_lutlow_r\[i\].
- `lin_lutdif_b`: lin_lutlow_b\[i+1\] - lin_lutlow_b\[i\].
- `lin_lutdif_gb`: lin_lutlow_gb\[i+1\] - lin_lutlow_gb\[i\].

#### <a id="c-struct-ipu3_uapi_isp_tnr3_vmem_params"></a>`struct ipu3_uapi_isp_tnr3_vmem_params`

Temporal noise reduction vector memory parameters

**Definition**

```c
struct ipu3_uapi_isp_tnr3_vmem_params {
    __u16 slope[IPU3_UAPI_ISP_TNR3_VMEM_LEN];
    __u16 reserved1[IPU3_UAPI_ISP_VEC_ELEMS - IPU3_UAPI_ISP_TNR3_VMEM_LEN];
    __u16 sigma[IPU3_UAPI_ISP_TNR3_VMEM_LEN];
    __u16 reserved2[IPU3_UAPI_ISP_VEC_ELEMS - IPU3_UAPI_ISP_TNR3_VMEM_LEN];
};
```

**Members**

- `slope`: slope setting in interpolation curve for temporal noise reduction.
- `reserved1`: reserved
- `sigma`: knee point setting in interpolation curve for temporal
  noise reduction.
- `reserved2`: reserved

#### <a id="c-struct-ipu3_uapi_isp_tnr3_params"></a>`struct ipu3_uapi_isp_tnr3_params`

Temporal noise reduction v3 parameters

**Definition**

```c
struct ipu3_uapi_isp_tnr3_params {
    __u32 knee_y1;
    __u32 knee_y2;
    __u32 maxfb_y;
    __u32 maxfb_u;
    __u32 maxfb_v;
    __u32 round_adj_y;
    __u32 round_adj_u;
    __u32 round_adj_v;
    __u32 ref_buf_select;
};
```

**Members**

- `knee_y1`: Knee point TNR3 assumes standard deviation of Y,U and
  V at Y1 are TnrY1_Sigma_Y, U and V.
- `knee_y2`: Knee point TNR3 assumes standard deviation of Y,U and
  V at Y2 are TnrY2_Sigma_Y, U and V.
- `maxfb_y`: Max feedback gain for Y
- `maxfb_u`: Max feedback gain for U
- `maxfb_v`: Max feedback gain for V
- `round_adj_y`: rounding Adjust for Y
- `round_adj_u`: rounding Adjust for U
- `round_adj_v`: rounding Adjust for V
- `ref_buf_select`: selection of the reference frame buffer to be used.

#### <a id="c-struct-ipu3_uapi_isp_xnr3_vmem_params"></a>`struct ipu3_uapi_isp_xnr3_vmem_params`

Extreme noise reduction v3 vector memory parameters

**Definition**

```c
struct ipu3_uapi_isp_xnr3_vmem_params {
    __u16 x[IPU3_UAPI_ISP_VEC_ELEMS];
    __u16 a[IPU3_UAPI_ISP_VEC_ELEMS];
    __u16 b[IPU3_UAPI_ISP_VEC_ELEMS];
    __u16 c[IPU3_UAPI_ISP_VEC_ELEMS];
};
```

**Members**

- `x`: xnr3 parameters.
- `a`: xnr3 parameters.
- `b`: xnr3 parameters.
- `c`: xnr3 parameters.

#### <a id="c-struct-ipu3_uapi_xnr3_alpha_params"></a>`struct ipu3_uapi_xnr3_alpha_params`

Extreme noise reduction v3 alpha tuning parameters

**Definition**

```c
struct ipu3_uapi_xnr3_alpha_params {
    __u32 y0;
    __u32 u0;
    __u32 v0;
    __u32 ydiff;
    __u32 udiff;
    __u32 vdiff;
};
```

**Members**

- `y0`: Sigma for Y range similarity in dark area.
- `u0`: Sigma for U range similarity in dark area.
- `v0`: Sigma for V range similarity in dark area.
- `ydiff`: Sigma difference for Y between bright area and dark area.
- `udiff`: Sigma difference for U between bright area and dark area.
- `vdiff`: Sigma difference for V between bright area and dark area.

#### <a id="c-struct-ipu3_uapi_xnr3_coring_params"></a>`struct ipu3_uapi_xnr3_coring_params`

Extreme noise reduction v3 coring parameters

**Definition**

```c
struct ipu3_uapi_xnr3_coring_params {
    __u32 u0;
    __u32 v0;
    __u32 udiff;
    __u32 vdiff;
};
```

**Members**

- `u0`: Coring Threshold of U channel in dark area.
- `v0`: Coring Threshold of V channel in dark area.
- `udiff`: Threshold difference of U channel between bright and dark area.
- `vdiff`: Threshold difference of V channel between bright and dark area.

#### <a id="c-struct-ipu3_uapi_xnr3_blending_params"></a>`struct ipu3_uapi_xnr3_blending_params`

Blending factor

**Definition**

```c
struct ipu3_uapi_xnr3_blending_params {
    __u32 strength;
};
```

**Members**

- `strength`: The factor for blending output with input. This is tuning
  parameterHigher values lead to more aggressive XNR operation.

#### <a id="c-struct-ipu3_uapi_isp_xnr3_params"></a>`struct ipu3_uapi_isp_xnr3_params`

Extreme noise reduction v3 parameters

**Definition**

```c
struct ipu3_uapi_isp_xnr3_params {
    struct ipu3_uapi_xnr3_alpha_params alpha;
    struct ipu3_uapi_xnr3_coring_params coring;
    struct ipu3_uapi_xnr3_blending_params blending;
};
```

**Members**

- `alpha`: parameters for xnr3 alpha. See [`ipu3_uapi_xnr3_alpha_params`](#c-struct-ipu3_uapi_xnr3_alpha_params)
- `coring`: parameters for xnr3 coring. See [`ipu3_uapi_xnr3_coring_params`](#c-struct-ipu3_uapi_xnr3_coring_params)
- `blending`: parameters for xnr3 blending. See [`ipu3_uapi_xnr3_blending_params`](#c-struct-ipu3_uapi_xnr3_blending_params)

#### <a id="c-struct-ipu3_uapi_obgrid_param"></a>`struct ipu3_uapi_obgrid_param`

Optical black level compensation parameters

**Definition**

```c
struct ipu3_uapi_obgrid_param {
    __u16 gr;
    __u16 r;
    __u16 b;
    __u16 gb;
};
```

**Members**

- `gr`: Grid table values for color GR
- `r`: Grid table values for color R
- `b`: Grid table values for color B
- `gb`: Grid table values for color GB

**Description**

Black level is different for red, green, and blue channels. So black level
compensation is different per channel.

#### <a id="c-struct-ipu3_uapi_flags"></a>`struct ipu3_uapi_flags`

bits to indicate which pipeline needs update

**Definition**

```c
struct ipu3_uapi_flags {
    __u32 gdc:1;
    __u32 obgrid:1;
    __u32 reserved1:30;
    __u32 acc_bnr:1;
    __u32 acc_green_disparity:1;
    __u32 acc_dm:1;
    __u32 acc_ccm:1;
    __u32 acc_gamma:1;
    __u32 acc_csc:1;
    __u32 acc_cds:1;
    __u32 acc_shd:1;
    __u32 reserved2:2;
    __u32 acc_iefd:1;
    __u32 acc_yds_c0:1;
    __u32 acc_chnr_c0:1;
    __u32 acc_y_ee_nr:1;
    __u32 acc_yds:1;
    __u32 acc_chnr:1;
    __u32 acc_ytm:1;
    __u32 acc_yds2:1;
    __u32 acc_tcc:1;
    __u32 acc_dpc:1;
    __u32 acc_bds:1;
    __u32 acc_anr:1;
    __u32 acc_awb_fr:1;
    __u32 acc_ae:1;
    __u32 acc_af:1;
    __u32 acc_awb:1;
    __u32 reserved3:4;
    __u32 lin_vmem_params:1;
    __u32 tnr3_vmem_params:1;
    __u32 xnr3_vmem_params:1;
    __u32 tnr3_dmem_params:1;
    __u32 xnr3_dmem_params:1;
    __u32 reserved4:1;
    __u32 obgrid_param:1;
    __u32 reserved5:25;
};
```

**Members**

- `gdc`: 0 = no update, 1 = update.
- `obgrid`: 0 = no update, 1 = update.
- `reserved1`: Not used.
- `acc_bnr`: 0 = no update, 1 = update.
- `acc_green_disparity`: 0 = no update, 1 = update.
- `acc_dm`: 0 = no update, 1 = update.
- `acc_ccm`: 0 = no update, 1 = update.
- `acc_gamma`: 0 = no update, 1 = update.
- `acc_csc`: 0 = no update, 1 = update.
- `acc_cds`: 0 = no update, 1 = update.
- `acc_shd`: 0 = no update, 1 = update.
- `reserved2`: Not used.
- `acc_iefd`: 0 = no update, 1 = update.
- `acc_yds_c0`: 0 = no update, 1 = update.
- `acc_chnr_c0`: 0 = no update, 1 = update.
- `acc_y_ee_nr`: 0 = no update, 1 = update.
- `acc_yds`: 0 = no update, 1 = update.
- `acc_chnr`: 0 = no update, 1 = update.
- `acc_ytm`: 0 = no update, 1 = update.
- `acc_yds2`: 0 = no update, 1 = update.
- `acc_tcc`: 0 = no update, 1 = update.
- `acc_dpc`: 0 = no update, 1 = update.
- `acc_bds`: 0 = no update, 1 = update.
- `acc_anr`: 0 = no update, 1 = update.
- `acc_awb_fr`: 0 = no update, 1 = update.
- `acc_ae`: 0 = no update, 1 = update.
- `acc_af`: 0 = no update, 1 = update.
- `acc_awb`: 0 = no update, 1 = update.
- `reserved3`: Not used.
- `lin_vmem_params`: 0 = no update, 1 = update.
- `tnr3_vmem_params`: 0 = no update, 1 = update.
- `xnr3_vmem_params`: 0 = no update, 1 = update.
- `tnr3_dmem_params`: 0 = no update, 1 = update.
- `xnr3_dmem_params`: 0 = no update, 1 = update.
- `reserved4`: Not used.
- `obgrid_param`: 0 = no update, 1 = update.
- `reserved5`: Not used.

#### <a id="c-struct-ipu3_uapi_params"></a>`struct ipu3_uapi_params`

V4L2_META_FMT_IPU3_PARAMS

**Definition**

```c
struct ipu3_uapi_params {
    struct ipu3_uapi_flags use  ;
    struct ipu3_uapi_acc_param acc_param;
    struct ipu3_uapi_isp_lin_vmem_params lin_vmem_params;
    struct ipu3_uapi_isp_tnr3_vmem_params tnr3_vmem_params;
    struct ipu3_uapi_isp_xnr3_vmem_params xnr3_vmem_params;
    struct ipu3_uapi_isp_tnr3_params tnr3_dmem_params;
    struct ipu3_uapi_isp_xnr3_params xnr3_dmem_params;
    struct ipu3_uapi_obgrid_param obgrid_param;
};
```

**Members**

- `use`: select which parameters to apply, see [`ipu3_uapi_flags`](#c-struct-ipu3_uapi_flags)
- `acc_param`: ACC parameters, as specified by [`ipu3_uapi_acc_param`](#c-struct-ipu3_uapi_acc_param)
- `lin_vmem_params`: linearization VMEM, as specified by
  [`ipu3_uapi_isp_lin_vmem_params`](#c-struct-ipu3_uapi_isp_lin_vmem_params)
- `tnr3_vmem_params`: tnr3 VMEM as specified by
  [`ipu3_uapi_isp_tnr3_vmem_params`](#c-struct-ipu3_uapi_isp_tnr3_vmem_params)
- `xnr3_vmem_params`: xnr3 VMEM as specified by
  [`ipu3_uapi_isp_xnr3_vmem_params`](#c-struct-ipu3_uapi_isp_xnr3_vmem_params)
- `tnr3_dmem_params`: tnr3 DMEM as specified by [`ipu3_uapi_isp_tnr3_params`](#c-struct-ipu3_uapi_isp_tnr3_params)
- `xnr3_dmem_params`: xnr3 DMEM as specified by [`ipu3_uapi_isp_xnr3_params`](#c-struct-ipu3_uapi_isp_xnr3_params)
- `obgrid_param`: obgrid parameters as specified by
  [`ipu3_uapi_obgrid_param`](#c-struct-ipu3_uapi_obgrid_param)

**Description**

The video queue "parameters" is of format V4L2_META_FMT_IPU3_PARAMS.
This is a "single plane" v4l2_meta_format using V4L2_BUF_TYPE_META_OUTPUT.

struct ipu3_uapi_params as defined below contains a lot of parameters and
ipu3_uapi_flags selects which parameters to apply.

---

# V4L2_META_FMT_RPI_BE_CFG

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Raspberry Pi PiSP Back End memory-to-memory image signal processor is configured by userspace by providing a buffer of configuration parameters to the pispbe-config output video device node using the v4l2_meta_format interface.

<a id="rst-v4l2-meta-fmt-rpi-be-cfg-1"></a>
<a id="rst-v4l2-meta-fmt-rpi-be-cfg"></a>

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

<!-- c:namespace: V4L -->

<a id="rst-raspberry-pi-pisp-back-end-configuration-format"></a>

## Raspberry Pi PiSP Back End configuration format

The Raspberry Pi PiSP Back End memory-to-memory image signal processor is configured by userspace by providing a buffer of configuration parameters to the `pispbe-config` output video device node using the `v4l2_meta_format` interface.

The PiSP Back End processes images in tiles, and its configuration requires specifying two different sets of parameters by populating the members of `pisp_be_tiles_config` defined in the `pisp_be_config.h` header file.

The [Raspberry Pi PiSP technical specification](<https://datasheets.raspberrypi.com/camera/raspberry-pi-image-signal-processor-specification.pdf>)<a id="rst-raspberry-pi-pisp-technical-specification"></a> provide detailed description of the ISP back end configuration and programming model.

<a id="rst-global-configuration-data"></a>

### Global configuration data

The global configuration data describe how the pixels in a particular image are to be processed and is therefore shared across all the tiles of the image. So for example, LSC (Lens Shading Correction) or Denoise parameters would be common across all tiles from the same frame.

Global configuration data are passed to the ISP by populating the member of `pisp_be_config`.

<a id="rst-tile-parameters"></a>

### Tile parameters

As the ISP processes images in tiles, each set of tiles parameters describe how a single tile in an image is going to be processed. A single set of tile parameters consist of 160 bytes of data and to process a batch of tiles several sets of tiles parameters are required.

Tiles parameters are passed to the ISP by populating the member of `pisp_tile` and the `num_tiles` fields of `pisp_be_tiles_config`.

<a id="rst-raspberry-pi-pisp-back-end-uapi-data-types"></a>

## Raspberry Pi PiSP Back End uAPI data types

This section describes the data types exposed to userspace by the Raspberry Pi PiSP Back End. The section is informative only, for a detailed description of each field refer to the [Raspberry Pi PiSP technical specification](<https://datasheets.raspberrypi.com/camera/raspberry-pi-image-signal-processor-specification.pdf>)<a id="rst-raspberry-pi-pisp-technical-specification-1"></a>.


#### <a id="c-struct-pisp_be_global_config"></a>`struct pisp_be_global_config`

PiSP global enable bitmaps

**Definition**

```c
struct pisp_be_global_config {
    __u32 bayer_enables;
    __u32 rgb_enables;
    __u8 bayer_order;
    __u8 pad[3];
};
```

**Members**

- `bayer_enables`: Bayer input enable flags
- `rgb_enables`: RGB output enable flags
- `bayer_order`: Bayer input format ordering
- `pad`: Padding bytes

#### <a id="c-struct-pisp_be_input_buffer_config"></a>`struct pisp_be_input_buffer_config`

PiSP Back End input buffer

**Definition**

```c
struct pisp_be_input_buffer_config {
    __u32 addr[3][2];
};
```

**Members**

- `addr`: Input buffer address

#### <a id="c-struct-pisp_be_dpc_config"></a>`struct pisp_be_dpc_config`

PiSP Back End DPC config

**Definition**

```c
struct pisp_be_dpc_config {
        __u8 coeff_level;
        __u8 coeff_range;
        __u8 pad;
    #define PISP_BE_DPC_FLAG_FOLDBACK 1;
        __u8 flags;
};
```

**Members**

- `coeff_level`: Coefficient for the darkest neighbouring pixel value
- `coeff_range`: Coefficient for the range of pixels for this Bayer channel
- `pad`: Padding byte
- `flags`: DPC configuration flags

**Description**

Defective Pixel Correction configuration

#### <a id="c-struct-pisp_be_geq_config"></a>`struct pisp_be_geq_config`

PiSP Back End GEQ config

**Definition**

```c
struct pisp_be_geq_config {
        __u16 offset;
    #define PISP_BE_GEQ_SHARPER (1U << 15);
    #define PISP_BE_GEQ_SLOPE ((1 << 10) - 1);
        __u16 slope_sharper;
        __u16 min;
        __u16 max;
};
```

**Members**

- `offset`: Offset value for threshold calculation
- `slope_sharper`: Slope/Sharper configuration
- `min`: Minimum value the threshold may have
- `max`: Maximum value the threshold may have

**Description**

Green Equalisation configuration

#### <a id="c-struct-pisp_be_tdn_input_buffer_config"></a>`struct pisp_be_tdn_input_buffer_config`

PiSP Back End TDN input buffer

**Definition**

```c
struct pisp_be_tdn_input_buffer_config {
    __u32 addr[2];
};
```

**Members**

- `addr`: TDN input buffer address

#### <a id="c-struct-pisp_be_tdn_config"></a>`struct pisp_be_tdn_config`

PiSP Back End TDN config

**Definition**

```c
struct pisp_be_tdn_config {
    __u16 black_level;
    __u16 ratio;
    __u16 noise_constant;
    __u16 noise_slope;
    __u16 threshold;
    __u8 reset;
    __u8 pad;
};
```

**Members**

- `black_level`: Black level value subtracted from pixels
- `ratio`: Multiplier for the LTA input frame
- `noise_constant`: Constant offset value used in noise estimation
- `noise_slope`: Noise estimation multiplier
- `threshold`: Threshold for TDN operations
- `reset`: Disable TDN operations
- `pad`: Padding byte

**Description**

Temporal Denoise configuration

#### <a id="c-struct-pisp_be_tdn_output_buffer_config"></a>`struct pisp_be_tdn_output_buffer_config`

PiSP Back End TDN output buffer

**Definition**

```c
struct pisp_be_tdn_output_buffer_config {
    __u32 addr[2];
};
```

**Members**

- `addr`: TDN output buffer address

#### <a id="c-struct-pisp_be_sdn_config"></a>`struct pisp_be_sdn_config`

PiSP Back End SDN config

**Definition**

```c
struct pisp_be_sdn_config {
    __u16 black_level;
    __u8 leakage;
    __u8 pad;
    __u16 noise_constant;
    __u16 noise_slope;
    __u16 noise_constant2;
    __u16 noise_slope2;
};
```

**Members**

- `black_level`: Black level subtracted from pixel for noise estimation
- `leakage`: Proportion of the original undenoised value to mix in
  denoised output
- `pad`: Padding byte
- `noise_constant`: Noise constant used for noise estimation
- `noise_slope`: Noise slope value used for noise estimation
- `noise_constant2`: Second noise constant used for noise estimation
- `noise_slope2`: Second slope value used for noise estimation

**Description**

Spatial Denoise configuration

#### <a id="c-struct-pisp_be_stitch_input_buffer_config"></a>`struct pisp_be_stitch_input_buffer_config`

PiSP Back End Stitch input

**Definition**

```c
struct pisp_be_stitch_input_buffer_config {
    __u32 addr[2];
};
```

**Members**

- `addr`: Stitch input buffer address

#### <a id="c-struct-pisp_be_stitch_config"></a>`struct pisp_be_stitch_config`

PiSP Back End Stitch config

**Definition**

```c
struct pisp_be_stitch_config {
    __u16 threshold_lo;
    __u8 threshold_diff_power;
    __u8 pad;
    __u16 exposure_ratio;
    __u8 motion_threshold_256;
    __u8 motion_threshold_recip;
};
```

**Members**

- `threshold_lo`: Low threshold value
- `threshold_diff_power`: Low and high threshold difference
- `pad`: Padding bytes
- `exposure_ratio`: Multiplier to convert long exposure pixels into
  short exposure pixels
- `motion_threshold_256`: Motion threshold above which short exposure
  pixels are used
- `motion_threshold_recip`: Reciprocal of motion_threshold_256 value

**Description**

Stitch block configuration

#### <a id="c-struct-pisp_be_stitch_output_buffer_config"></a>`struct pisp_be_stitch_output_buffer_config`

PiSP Back End Stitch output

**Definition**

```c
struct pisp_be_stitch_output_buffer_config {
    __u32 addr[2];
};
```

**Members**

- `addr`: Stitch input buffer address

#### <a id="c-struct-pisp_be_cdn_config"></a>`struct pisp_be_cdn_config`

PiSP Back End CDN config

**Definition**

```c
struct pisp_be_cdn_config {
    __u16 thresh;
    __u8 iir_strength;
    __u8 g_adjust;
};
```

**Members**

- `thresh`: Constant for noise estimation
- `iir_strength`: Relative strength of the IIR part of the filter
- `g_adjust`: Proportion of the change assigned to the G channel

**Description**

Colour Denoise configuration

#### <a id="c-struct-pisp_be_lsc_config"></a>`struct pisp_be_lsc_config`

PiSP Back End LSC config

**Definition**

```c
struct pisp_be_lsc_config {
        __u16 grid_step_x;
        __u16 grid_step_y;
    #define PISP_BE_LSC_LUT_SIZE    (PISP_BE_LSC_GRID_SIZE + 1);
        __u32 lut_packed[PISP_BE_LSC_LUT_SIZE][PISP_BE_LSC_LUT_SIZE];
};
```

**Members**

- `grid_step_x`: Reciprocal of cell size width
- `grid_step_y`: Reciprocal of cell size height
- `lut_packed`: Jointly-coded RGB gains for each LSC grid

**Description**

Lens Shading Correction configuration

#### <a id="c-struct-pisp_be_lsc_extra"></a>`struct pisp_be_lsc_extra`

PiSP Back End LSC Extra config

**Definition**

```c
struct pisp_be_lsc_extra {
    __u16 offset_x;
    __u16 offset_y;
};
```

**Members**

- `offset_x`: Horizontal offset into the LSC table of this tile
- `offset_y`: Vertical offset into the LSC table of this tile

#### <a id="c-struct-pisp_be_cac_config"></a>`struct pisp_be_cac_config`

PiSP Back End CAC config

**Definition**

```c
struct pisp_be_cac_config {
        __u16 grid_step_x;
        __u16 grid_step_y;
    #define PISP_BE_CAC_LUT_SIZE            (PISP_BE_CAC_GRID_SIZE + 1);
        __s8 lut[PISP_BE_CAC_LUT_SIZE][PISP_BE_CAC_LUT_SIZE][2][2];
};
```

**Members**

- `grid_step_x`: Reciprocal of cell size width
- `grid_step_y`: Reciprocal of cell size height
- `lut`: Pixel shift for the CAC grid

**Description**

Chromatic Aberration Correction config

#### <a id="c-struct-pisp_be_cac_extra"></a>`struct pisp_be_cac_extra`

PiSP Back End CAC extra config

**Definition**

```c
struct pisp_be_cac_extra {
    __u16 offset_x;
    __u16 offset_y;
};
```

**Members**

- `offset_x`: Horizontal offset into the CAC table of this tile
- `offset_y`: Horizontal offset into the CAC table of this tile

#### <a id="c-struct-pisp_be_debin_config"></a>`struct pisp_be_debin_config`

PiSP Back End Debin config

**Definition**

```c
struct pisp_be_debin_config {
    __s8 coeffs[PISP_BE_DEBIN_NUM_COEFFS];
    __s8 h_enable;
    __s8 v_enable;
    __s8 pad[2];
};
```

**Members**

- `coeffs`: Filter coefficients for debinning
- `h_enable`: Horizontal debinning enable
- `v_enable`: Vertical debinning enable
- `pad`: Padding bytes

**Description**

Debinning configuration

#### <a id="c-struct-pisp_be_tonemap_config"></a>`struct pisp_be_tonemap_config`

PiSP Back End Tonemap config

**Definition**

```c
struct pisp_be_tonemap_config {
    __u16 detail_constant;
    __u16 detail_slope;
    __u16 iir_strength;
    __u16 strength;
    __u32 lut[PISP_BE_TONEMAP_LUT_SIZE];
};
```

**Members**

- `detail_constant`: Constant value for threshold calculation
- `detail_slope`: Slope value for threshold calculation
- `iir_strength`: Relative strength of the IIR fiter
- `strength`: Strength factor
- `lut`: Look-up table for tonemap curve

**Description**

Tonemapping configuration

#### <a id="c-struct-pisp_be_demosaic_config"></a>`struct pisp_be_demosaic_config`

PiSP Back End Demosaic config

**Definition**

```c
struct pisp_be_demosaic_config {
    __u8 sharper;
    __u8 fc_mode;
    __u8 pad[2];
};
```

**Members**

- `sharper`: Use other Bayer channels to increase sharpness
- `fc_mode`: Built-in false colour suppression mode
- `pad`: Padding bytes

**Description**

Demosaic configuration

#### <a id="c-struct-pisp_be_ccm_config"></a>`struct pisp_be_ccm_config`

PiSP Back End CCM config

**Definition**

```c
struct pisp_be_ccm_config {
    __s16 coeffs[9];
    __u8 pad[2];
    __s32 offsets[3];
};
```

**Members**

- `coeffs`: Matrix coefficients
- `pad`: Padding bytes
- `offsets`: Offsets triplet

**Description**

Colour Correction Matrix configuration

#### <a id="c-struct-pisp_be_sat_control_config"></a>`struct pisp_be_sat_control_config`

PiSP Back End SAT config

**Definition**

```c
struct pisp_be_sat_control_config {
    __u8 shift_r;
    __u8 shift_g;
    __u8 shift_b;
    __u8 pad;
};
```

**Members**

- `shift_r`: Left shift for Red colour channel
- `shift_g`: Left shift for Green colour channel
- `shift_b`: Left shift for Blue colour channel
- `pad`: Padding byte

**Description**

Saturation Control configuration

#### <a id="c-struct-pisp_be_false_colour_config"></a>`struct pisp_be_false_colour_config`

PiSP Back End False Colour config

**Definition**

```c
struct pisp_be_false_colour_config {
    __u8 distance;
    __u8 pad[3];
};
```

**Members**

- `distance`: Distance of neighbouring pixels, either 1 or 2
- `pad`: Padding bytes

**Description**

False Colour configuration

#### <a id="c-struct-pisp_be_sharpen_config"></a>`struct pisp_be_sharpen_config`

PiSP Back End Sharpening config

**Definition**

```c
struct pisp_be_sharpen_config {
    __s8 kernel0[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
    __s8 pad0[3];
    __s8 kernel1[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
    __s8 pad1[3];
    __s8 kernel2[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
    __s8 pad2[3];
    __s8 kernel3[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
    __s8 pad3[3];
    __s8 kernel4[PISP_BE_SHARPEN_SIZE * PISP_BE_SHARPEN_SIZE];
    __s8 pad4[3];
    __u16 threshold_offset0;
    __u16 threshold_slope0;
    __u16 scale0;
    __u16 pad5;
    __u16 threshold_offset1;
    __u16 threshold_slope1;
    __u16 scale1;
    __u16 pad6;
    __u16 threshold_offset2;
    __u16 threshold_slope2;
    __u16 scale2;
    __u16 pad7;
    __u16 threshold_offset3;
    __u16 threshold_slope3;
    __u16 scale3;
    __u16 pad8;
    __u16 threshold_offset4;
    __u16 threshold_slope4;
    __u16 scale4;
    __u16 pad9;
    __u16 positive_strength;
    __u16 positive_pre_limit;
    __u16 positive_func[PISP_BE_SHARPEN_FUNC_NUM_POINTS];
    __u16 positive_limit;
    __u16 negative_strength;
    __u16 negative_pre_limit;
    __u16 negative_func[PISP_BE_SHARPEN_FUNC_NUM_POINTS];
    __u16 negative_limit;
    __u8 enables;
    __u8 white;
    __u8 black;
    __u8 grey;
};
```

**Members**

- `kernel0`: Coefficient for filter 0
- `pad0`: Padding byte
- `kernel1`: Coefficient for filter 1
- `pad1`: Padding byte
- `kernel2`: Coefficient for filter 2
- `pad2`: Padding byte
- `kernel3`: Coefficient for filter 3
- `pad3`: Padding byte
- `kernel4`: Coefficient for filter 4
- `pad4`: Padding byte
- `threshold_offset0`: Offset for filter 0 response calculation
- `threshold_slope0`: Slope multiplier for the filter 0 response calculation
- `scale0`: Scale factor for filter 0 response calculation
- `pad5`: Padding byte
- `threshold_offset1`: Offset for filter 0 response calculation
- `threshold_slope1`: Slope multiplier for the filter 0 response calculation
- `scale1`: Scale factor for filter 0 response calculation
- `pad6`: Padding byte
- `threshold_offset2`: Offset for filter 0 response calculation
- `threshold_slope2`: Slope multiplier for the filter 0 response calculation
- `scale2`: Scale factor for filter 0 response calculation
- `pad7`: Padding byte
- `threshold_offset3`: Offset for filter 0 response calculation
- `threshold_slope3`: Slope multiplier for the filter 0 response calculation
- `scale3`: Scale factor for filter 0 response calculation
- `pad8`: Padding byte
- `threshold_offset4`: Offset for filter 0 response calculation
- `threshold_slope4`: Slope multiplier for the filter 0 response calculation
- `scale4`: Scale factor for filter 0 response calculation
- `pad9`: Padding byte
- `positive_strength`: Factor to scale the positive sharpening strength
- `positive_pre_limit`: Maximum allowed possible positive sharpening value
- `positive_func`: Gain factor applied to positive sharpening response
- `positive_limit`: Final gain factor applied to positive sharpening
- `negative_strength`: Factor to scale the negative sharpening strength
- `negative_pre_limit`: Maximum allowed possible negative sharpening value
- `negative_func`: Gain factor applied to negative sharpening response
- `negative_limit`: Final gain factor applied to negative sharpening
- `enables`: Filter enable mask
- `white`: White output pixel filter mask
- `black`: Black output pixel filter mask
- `grey`: Grey output pixel filter mask

**Description**

Sharpening configuration

#### <a id="c-struct-pisp_be_sh_fc_combine_config"></a>`struct pisp_be_sh_fc_combine_config`

PiSP Back End Sharpening and False Colour config

**Definition**

```c
struct pisp_be_sh_fc_combine_config {
    __u8 y_factor;
    __u8 c1_factor;
    __u8 c2_factor;
    __u8 pad;
};
```

**Members**

- `y_factor`: Control amount of desaturation of pixels being darkened
- `c1_factor`: Control amount of brightening of a pixel for the Cb
  channel
- `c2_factor`: Control amount of brightening of a pixel for the Cr
  channel
- `pad`: Padding byte

**Description**

Sharpening and False Colour configuration

#### <a id="c-struct-pisp_be_gamma_config"></a>`struct pisp_be_gamma_config`

PiSP Back End Gamma configuration

**Definition**

```c
struct pisp_be_gamma_config {
    __u32 lut[PISP_BE_GAMMA_LUT_SIZE];
};
```

**Members**

- `lut`: Gamma curve look-up table

#### <a id="c-struct-pisp_be_crop_config"></a>`struct pisp_be_crop_config`

PiSP Back End Crop config

**Definition**

```c
struct pisp_be_crop_config {
    __u16 offset_x, offset_y;
    __u16 width, height;
};
```

**Members**

- `offset_x`: Number of pixels cropped from the left of the tile
- `offset_y`: Number of pixels cropped from the top of the tile
- `width`: Width of the cropped tile output
- `height`: Height of the cropped tile output

**Description**

Crop configuration

#### <a id="c-struct-pisp_be_resample_config"></a>`struct pisp_be_resample_config`

PiSP Back End Resampling config

**Definition**

```c
struct pisp_be_resample_config {
    __u16 scale_factor_h, scale_factor_v;
    __s16 coef[PISP_BE_RESAMPLE_FILTER_SIZE];
};
```

**Members**

- `scale_factor_h`: Horizontal scale factor
- `scale_factor_v`: Vertical scale factor
- `coef`: Resample coefficients

**Description**

Resample configuration

#### <a id="c-struct-pisp_be_resample_extra"></a>`struct pisp_be_resample_extra`

PiSP Back End Resample config

**Definition**

```c
struct pisp_be_resample_extra {
    __u16 scaled_width;
    __u16 scaled_height;
    __s16 initial_phase_h[3];
    __s16 initial_phase_v[3];
};
```

**Members**

- `scaled_width`: Width in pixels of the scaled output
- `scaled_height`: Height in pixels of the scaled output
- `initial_phase_h`: Initial horizontal phase
- `initial_phase_v`: Initial vertical phase

**Description**

Resample configuration

#### <a id="c-struct-pisp_be_downscale_config"></a>`struct pisp_be_downscale_config`

PiSP Back End Downscale config

**Definition**

```c
struct pisp_be_downscale_config {
    __u16 scale_factor_h;
    __u16 scale_factor_v;
    __u16 scale_recip_h;
    __u16 scale_recip_v;
};
```

**Members**

- `scale_factor_h`: Horizontal scale factor
- `scale_factor_v`: Vertical scale factor
- `scale_recip_h`: Horizontal reciprocal factor
- `scale_recip_v`: Vertical reciprocal factor

**Description**

Downscale configuration

#### <a id="c-struct-pisp_be_downscale_extra"></a>`struct pisp_be_downscale_extra`

PiSP Back End Downscale Extra config

**Definition**

```c
struct pisp_be_downscale_extra {
    __u16 scaled_width;
    __u16 scaled_height;
};
```

**Members**

- `scaled_width`: Scaled image width
- `scaled_height`: Scaled image height

#### <a id="c-struct-pisp_be_hog_config"></a>`struct pisp_be_hog_config`

PiSP Back End HOG config

**Definition**

```c
struct pisp_be_hog_config {
    __u8 compute_signed;
    __u8 channel_mix[3];
    __u32 stride;
};
```

**Members**

- `compute_signed`: Set 0 for unsigned gradients, 1 for signed
- `channel_mix`: Channels proportions to use
- `stride`: Stride in bytes between blocks directly below

**Description**

Histogram of Oriented Gradients configuration

#### <a id="c-enum-pisp_be_transform"></a>`enum pisp_be_transform`

PiSP Back End Transform flags

**Constants**

- `PISP_BE_TRANSFORM_NONE`: No transform
- `PISP_BE_TRANSFORM_HFLIP`: Horizontal flip
- `PISP_BE_TRANSFORM_VFLIP`: Vertical flip
- `PISP_BE_TRANSFORM_ROT180`: 180 degress rotation

#### <a id="c-struct-pisp_be_output_buffer_config"></a>`struct pisp_be_output_buffer_config`

PiSP Back End Output buffer

**Definition**

```c
struct pisp_be_output_buffer_config {
    __u32 addr[3][2];
};
```

**Members**

- `addr`: Output buffer address

#### <a id="c-struct-pisp_be_hog_buffer_config"></a>`struct pisp_be_hog_buffer_config`

PiSP Back End HOG buffer

**Definition**

```c
struct pisp_be_hog_buffer_config {
    __u32 addr[2];
};
```

**Members**

- `addr`: HOG buffer address

#### <a id="c-struct-pisp_be_config"></a>`struct pisp_be_config`

RaspberryPi PiSP Back End Processing configuration

**Definition**

```c
struct pisp_be_config {
    struct pisp_be_input_buffer_config input_buffer;
    struct pisp_be_tdn_input_buffer_config tdn_input_buffer;
    struct pisp_be_stitch_input_buffer_config stitch_input_buffer;
    struct pisp_be_tdn_output_buffer_config tdn_output_buffer;
    struct pisp_be_stitch_output_buffer_config stitch_output_buffer;
    struct pisp_be_output_buffer_config output_buffer[PISP_BACK_END_NUM_OUTPUTS];
    struct pisp_be_hog_buffer_config hog_buffer;
    struct pisp_be_global_config global;
    struct pisp_image_format_config input_format;
    struct pisp_decompress_config decompress;
    struct pisp_be_dpc_config dpc;
    struct pisp_be_geq_config geq;
    struct pisp_image_format_config tdn_input_format;
    struct pisp_decompress_config tdn_decompress;
    struct pisp_be_tdn_config tdn;
    struct pisp_compress_config tdn_compress;
    struct pisp_image_format_config tdn_output_format;
    struct pisp_be_sdn_config sdn;
    struct pisp_bla_config blc;
    struct pisp_compress_config stitch_compress;
    struct pisp_image_format_config stitch_output_format;
    struct pisp_image_format_config stitch_input_format;
    struct pisp_decompress_config stitch_decompress;
    struct pisp_be_stitch_config stitch;
    struct pisp_be_lsc_config lsc;
    struct pisp_wbg_config wbg;
    struct pisp_be_cdn_config cdn;
    struct pisp_be_cac_config cac;
    struct pisp_be_debin_config debin;
    struct pisp_be_tonemap_config tonemap;
    struct pisp_be_demosaic_config demosaic;
    struct pisp_be_ccm_config ccm;
    struct pisp_be_sat_control_config sat_control;
    struct pisp_be_ccm_config ycbcr;
    struct pisp_be_sharpen_config sharpen;
    struct pisp_be_false_colour_config false_colour;
    struct pisp_be_sh_fc_combine_config sh_fc_combine;
    struct pisp_be_ccm_config ycbcr_inverse;
    struct pisp_be_gamma_config gamma;
    struct pisp_be_ccm_config csc[PISP_BACK_END_NUM_OUTPUTS];
    struct pisp_be_downscale_config downscale[PISP_BACK_END_NUM_OUTPUTS];
    struct pisp_be_resample_config resample[PISP_BACK_END_NUM_OUTPUTS];
    struct pisp_be_output_format_config output_format[PISP_BACK_END_NUM_OUTPUTS];
    struct pisp_be_hog_config hog;
    struct pisp_be_axi_config axi;
    struct pisp_be_lsc_extra lsc_extra;
    struct pisp_be_cac_extra cac_extra;
    struct pisp_be_downscale_extra downscale_extra[PISP_BACK_END_NUM_OUTPUTS];
    struct pisp_be_resample_extra resample_extra[PISP_BACK_END_NUM_OUTPUTS];
    struct pisp_be_crop_config crop;
    struct pisp_image_format_config hog_format;
    __u32 dirty_flags_bayer;
    __u32 dirty_flags_rgb;
    __u32 dirty_flags_extra;
};
```

**Members**

- `input_buffer`: Input buffer addresses
- `tdn_input_buffer`: TDN input buffer addresses
- `stitch_input_buffer`: Stitch input buffer addresses
- `tdn_output_buffer`: TDN output buffer addresses
- `stitch_output_buffer`: Stitch output buffer addresses
- `output_buffer`: Output buffers addresses
- `hog_buffer`: HOG buffer addresses
- `global`: Global PiSP configuration
- `input_format`: Input image format
- `decompress`: Decompress configuration
- `dpc`: Defective Pixel Correction configuration
- `geq`: Green Equalisation configuration
- `tdn_input_format`: Temporal Denoise input format
- `tdn_decompress`: Temporal Denoise decompress configuration
- `tdn`: Temporal Denoise configuration
- `tdn_compress`: Temporal Denoise compress configuration
- `tdn_output_format`: Temporal Denoise output format
- `sdn`: Spatial Denoise configuration
- `blc`: Black Level Correction configuration
- `stitch_compress`: Stitch compress configuration
- `stitch_output_format`: Stitch output format
- `stitch_input_format`: Stitch input format
- `stitch_decompress`: Stitch decompress configuration
- `stitch`: Stitch configuration
- `lsc`: Lens Shading Correction configuration
- `wbg`: White Balance Gain configuration
- `cdn`: Colour Denoise configuration
- `cac`: Colour Aberration Correction configuration
- `debin`: Debinning configuration
- `tonemap`: Tonemapping configuration
- `demosaic`: Demosaicing configuration
- `ccm`: Colour Correction Matrix configuration
- `sat_control`: Saturation Control configuration
- `ycbcr`: YCbCr colour correction configuration
- `sharpen`: Sharpening configuration
- `false_colour`: False colour correction
- `sh_fc_combine`: Sharpening and False Colour correction
- `ycbcr_inverse`: Inverse YCbCr colour correction
- `gamma`: Gamma curve configuration
- `csc`: Color Space Conversion configuration
- `downscale`: Downscale configuration
- `resample`: Resampling configuration
- `output_format`: Output format configuration
- `hog`: HOG configuration
- `axi`: AXI bus configuration
- `lsc_extra`: LSC extra info
- `cac_extra`: CAC extra info
- `downscale_extra`: Downscaler extra info
- `resample_extra`: Resample extra info
- `crop`: Crop configuration
- `hog_format`: HOG format info
- `dirty_flags_bayer`: Bayer enable dirty flags
  (`pisp_be_bayer_enable`)
- `dirty_flags_rgb`: RGB enable dirty flags
  (`pisp_be_rgb_enable`)
- `dirty_flags_extra`: Extra dirty flags

#### <a id="c-enum-pisp_tile_edge"></a>`enum pisp_tile_edge`

PiSP Back End Tile position

**Constants**

- `PISP_LEFT_EDGE`: Left edge tile
- `PISP_RIGHT_EDGE`: Right edge tile
- `PISP_TOP_EDGE`: Top edge tile
- `PISP_BOTTOM_EDGE`: Bottom edge tile

#### <a id="c-struct-pisp_tile"></a>`struct pisp_tile`

Raspberry Pi PiSP Back End tile configuration

**Definition**

```c
struct pisp_tile {
    __u8 edge;
    __u8 pad0[3];
    __u32 input_addr_offset;
    __u32 input_addr_offset2;
    __u16 input_offset_x;
    __u16 input_offset_y;
    __u16 input_width;
    __u16 input_height;
    __u32 tdn_input_addr_offset;
    __u32 tdn_output_addr_offset;
    __u32 stitch_input_addr_offset;
    __u32 stitch_output_addr_offset;
    __u32 lsc_grid_offset_x;
    __u32 lsc_grid_offset_y;
    __u32 cac_grid_offset_x;
    __u32 cac_grid_offset_y;
    __u16 crop_x_start[PISP_BACK_END_NUM_OUTPUTS];
    __u16 crop_x_end[PISP_BACK_END_NUM_OUTPUTS];
    __u16 crop_y_start[PISP_BACK_END_NUM_OUTPUTS];
    __u16 crop_y_end[PISP_BACK_END_NUM_OUTPUTS];
    __u16 downscale_phase_x[3 * PISP_BACK_END_NUM_OUTPUTS];
    __u16 downscale_phase_y[3 * PISP_BACK_END_NUM_OUTPUTS];
    __u16 resample_in_width[PISP_BACK_END_NUM_OUTPUTS];
    __u16 resample_in_height[PISP_BACK_END_NUM_OUTPUTS];
    __u16 resample_phase_x[3 * PISP_BACK_END_NUM_OUTPUTS];
    __u16 resample_phase_y[3 * PISP_BACK_END_NUM_OUTPUTS];
    __u16 output_offset_x[PISP_BACK_END_NUM_OUTPUTS];
    __u16 output_offset_y[PISP_BACK_END_NUM_OUTPUTS];
    __u16 output_width[PISP_BACK_END_NUM_OUTPUTS];
    __u16 output_height[PISP_BACK_END_NUM_OUTPUTS];
    __u32 output_addr_offset[PISP_BACK_END_NUM_OUTPUTS];
    __u32 output_addr_offset2[PISP_BACK_END_NUM_OUTPUTS];
    __u32 output_hog_addr_offset;
};
```

**Members**

- `edge`: Edge tile flag
- `pad0`: Padding bytes
- `input_addr_offset`: Top-left pixel offset, in bytes
- `input_addr_offset2`: Top-left pixel offset, in bytes for the second/
  third image planes
- `input_offset_x`: Horizontal offset in pixels of this tile in the
  input image
- `input_offset_y`: Vertical offset in pixels of this tile in the
  input image
- `input_width`: Width in pixels of this tile
- `input_height`: Height in pixels of the this tile
- `tdn_input_addr_offset`: TDN input image offset, in bytes
- `tdn_output_addr_offset`: TDN output image offset, in bytes
- `stitch_input_addr_offset`: Stitch input image offset, in bytes
- `stitch_output_addr_offset`: Stitch output image offset, in bytes
- `lsc_grid_offset_x`: Horizontal offset in the LSC table for this tile
- `lsc_grid_offset_y`: Vertical offset in the LSC table for this tile
- `cac_grid_offset_x`: Horizontal offset in the CAC table for this tile
- `cac_grid_offset_y`: Horizontal offset in the CAC table for this tile
- `crop_x_start`: Number of pixels cropped from the left of the
  tile
- `crop_x_end`: Number of pixels cropped from the right of the
  tile
- `crop_y_start`: Number of pixels cropped from the top of the
  tile
- `crop_y_end`: Number of pixels cropped from the bottom of the
  tile
- `downscale_phase_x`: Initial horizontal phase in pixels
- `downscale_phase_y`: Initial vertical phase in pixels
- `resample_in_width`: Width in pixels of the tile entering the
  Resample block
- `resample_in_height`: Height in pixels of the tile entering the
  Resample block
- `resample_phase_x`: Initial horizontal phase for the Resample block
- `resample_phase_y`: Initial vertical phase for the Resample block
- `output_offset_x`: Horizontal offset in pixels where the tile will
  be written into the output image
- `output_offset_y`: Vertical offset in pixels where the tile will be
  written into the output image
- `output_width`: Width in pixels in the output image of this tile
- `output_height`: Height in pixels in the output image of this tile
- `output_addr_offset`: Offset in bytes into the output buffer
- `output_addr_offset2`: Offset in bytes into the output buffer for the
  second and third plane
- `output_hog_addr_offset`: Offset in bytes into the HOG buffer where
  results of this tile are to be written

**Description**

Tile parameters: each set of tile parameters is a 160-bytes block of data
which contains the tile processing parameters.

#### <a id="c-struct-pisp_be_tiles_config"></a>`struct pisp_be_tiles_config`

Raspberry Pi PiSP Back End configuration

**Definition**

```c
struct pisp_be_tiles_config {
    struct pisp_be_config config;
    struct pisp_tile tiles[PISP_BACK_END_NUM_TILES];
    __u32 num_tiles;
};
```

**Members**

- `config`: PiSP Back End configuration
- `tiles`: Tile descriptors
- `num_tiles`: Number of tiles

---

# V4L2_META_FMT_RPI_FE_CFG

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Raspberry Pi PiSP Front End image signal processor is configured by userspace by providing a buffer of configuration parameters to the rp1-cfe-fe-config output video device node using the v4l2_meta_format interface.

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

<!-- c:namespace: V4L -->

<a id="rst-v4l2-meta-fmt-rpi-fe-cfg-1"></a>
<a id="rst-v4l2-meta-fmt-rpi-fe-cfg"></a>

## V4L2_META_FMT_RPI_FE_CFG

<a id="rst-raspberry-pi-pisp-front-end-configuration-format"></a>

### Raspberry Pi PiSP Front End configuration format

The Raspberry Pi PiSP Front End image signal processor is configured by userspace by providing a buffer of configuration parameters to the `rp1-cfe-fe-config` output video device node using the `v4l2_meta_format` interface.

The [Raspberry Pi PiSP technical specification](<https://datasheets.raspberrypi.com/camera/raspberry-pi-image-signal-processor-specification.pdf>)<a id="rst-raspberry-pi-pisp-technical-specification"></a> provide detailed description of the Front End configuration and programming model.

<a id="rst-v4l2-meta-fmt-rpi-fe-stats-1"></a>
<a id="rst-v4l2-meta-fmt-rpi-fe-stats"></a>

## V4L2_META_FMT_RPI_FE_STATS

<a id="rst-raspberry-pi-pisp-front-end-statistics-format"></a>

### Raspberry Pi PiSP Front End statistics format

The Raspberry Pi PiSP Front End image signal processor provides statistics data by writing to a buffer provided via the `rp1-cfe-fe-stats` capture video device node using the `v4l2_meta_format` interface.

The [Raspberry Pi PiSP technical specification](<https://datasheets.raspberrypi.com/camera/raspberry-pi-image-signal-processor-specification.pdf>)<a id="rst-raspberry-pi-pisp-technical-specification-1"></a> provide detailed description of the Front End configuration and programming model.

---

# V4L2_META_FMT_RK_ISP1_PARAMS ('rk1p'), V4L2_META_FMT_RK_ISP1_STAT_3A ('rk1s'), V4L2_META_FMT_RK_ISP1_EXT_PARAMS ('rk1e')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The configuration of the RkISP1 ISP is performed by userspace by providing parameters for the ISP to the driver using the v4l2_meta_format interface.

<a id="rst-v4l2-meta-fmt-rk-isp1-params-rk1p-v4l2-meta-fmt-rk-isp1-stat-3a-rk1s-v4l2-meta-fmt-rk-isp1-ext-params-rk1e"></a>
<a id="rst-v4l2-meta-fmt-rk-isp1-stat-3a"></a>

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

<!-- c:namespace: V4L -->

<a id="rst-configuration-parameters"></a>

## Configuration parameters

The configuration of the RkISP1 ISP is performed by userspace by providing parameters for the ISP to the driver using the `v4l2_meta_format` interface.

There are two methods that allow to configure the ISP, the `fixed parameters` configuration format and the `extensible parameters` configuration format.

<a id="rst-fixed-parameters-configuration-format"></a>
<a id="rst-v4l2-meta-fmt-rk-isp1-params"></a>

### Fixed parameters configuration format

When using the fixed configuration format, parameters are passed to the [rkisp1_params](</kernel/administration/admin-guide/media/rkisp1.md#rst-rkisp1-params>) metadata output video node, using the `V4L2_META_FMT_RK_ISP1_PARAMS` meta format.

The buffer contains a single instance of the C structure `rkisp1_params_cfg` defined in `rkisp1-config.h`. So the structure can be obtained from the buffer by:



```c
struct rkisp1_params_cfg *params = (struct rkisp1_params_cfg*) buffer;
```

This method supports a subset of the ISP features only, new applications should use the extensible parameters method.

<a id="rst-extensible-parameters-configuration-format"></a>
<a id="rst-v4l2-meta-fmt-rk-isp1-ext-params"></a>

### Extensible parameters configuration format

When using the extensible configuration format, parameters are passed to the [rkisp1_params](</kernel/administration/admin-guide/media/rkisp1.md#rst-rkisp1-params>) metadata output video node, using the `V4L2_META_FMT_RK_ISP1_EXT_PARAMS` meta format.

The buffer contains a single instance of the C structure `rkisp1_ext_params_cfg` defined in `rkisp1-config.h`. The `rkisp1_ext_params_cfg` structure is designed to allow userspace to populate the data buffer with only the configuration data for the ISP blocks it intends to configure. The extensible parameters format design allows developers to define new block types to support new configuration parameters, and defines a versioning scheme so that it can be extended and versioned without breaking compatibility with existing applications.

For these reasons, this configuration method is preferred over the `fixed parameters` format alternative.

<!-- rkisp1_stat_buffer -->

<a id="rst-a-and-histogram-statistics"></a>

## 3A and histogram statistics

The ISP1 device collects different statistics over an input Bayer frame. Those statistics are obtained from the [rkisp1_stats](</kernel/administration/admin-guide/media/rkisp1.md#rst-rkisp1-stats>) metadata capture video node, using the `v4l2_meta_format` interface. The buffer contains a single instance of the C structure `rkisp1_stat_buffer` defined in `rkisp1-config.h`. So the structure can be obtained from the buffer by:



```c
struct rkisp1_stat_buffer *stats = (struct rkisp1_stat_buffer*) buffer;
```

The statistics collected are Exposure, AWB (Auto-white balance), Histogram and AF (Auto-focus). See `rkisp1_stat_buffer` for details of the statistics.

The 3A statistics and configuration parameters described here are usually consumed and produced by dedicated user space libraries that comprise the important tuning tools using software control loop.

<a id="rst-rkisp1-uapi-data-types"></a>

### rkisp1 uAPI data types


#### <a id="c-enum-rkisp1_cif_isp_version"></a>`enum rkisp1_cif_isp_version`

ISP variants

**Constants**

- `RKISP1_V10`: Used at least in RK3288 and RK3399.
- `RKISP1_V11`: Declared in the original vendor code, but not used. Same number
  of entries in grids and histogram as v10.
- `RKISP1_V12`: Used at least in RK3326 and PX30.
- `RKISP1_V13`: Used at least in RK1808. Same number of entries in grids and
  histogram as v12.
- `RKISP1_V_IMX8MP`: Used in at least i.MX8MP. Same number of entries in grids
  and histogram as v10.

#### <a id="c-enum-rkisp1_cif_isp_exp_ctrl_autostop"></a>`enum rkisp1_cif_isp_exp_ctrl_autostop`

stop modes

**Constants**

- `RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_0`: continuous measurement
- `RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_1`: stop measuring after a complete frame

#### <a id="c-enum-rkisp1_cif_isp_exp_meas_mode"></a>`enum rkisp1_cif_isp_exp_meas_mode`

Exposure measure mode

**Constants**

- `RKISP1_CIF_ISP_EXP_MEASURING_MODE_0`: Y = 16 + 0.25R + 0.5G + 0.1094B
- `RKISP1_CIF_ISP_EXP_MEASURING_MODE_1`: Y = (R + G + B) x (85/256)

#### <a id="c-struct-rkisp1_cif_isp_window"></a>`struct rkisp1_cif_isp_window`

measurement window.

**Definition**

```c
struct rkisp1_cif_isp_window {
    __u16 h_offs;
    __u16 v_offs;
    __u16 h_size;
    __u16 v_size;
};
```

**Members**

- `h_offs`: the horizontal offset of the window from the left of the frame in pixels.
- `v_offs`: the vertical offset of the window from the top of the frame in pixels.
- `h_size`: the horizontal size of the window in pixels
- `v_size`: the vertical size of the window in pixels.

**Description**

Measurements are calculated per window inside the frame.
This struct represents a window for a measurement.

#### <a id="c-struct-rkisp1_cif_isp_bls_fixed_val"></a>`struct rkisp1_cif_isp_bls_fixed_val`

BLS fixed subtraction values

**Definition**

```c
struct rkisp1_cif_isp_bls_fixed_val {
    __s16 r;
    __s16 gr;
    __s16 gb;
    __s16 b;
};
```

**Members**

- `r`: Fixed (signed!) subtraction value for Bayer pattern R
- `gr`: Fixed (signed!) subtraction value for Bayer pattern Gr
- `gb`: Fixed (signed!) subtraction value for Bayer pattern Gb
- `b`: Fixed (signed!) subtraction value for Bayer pattern B

**Description**

The values will be subtracted from the sensor
values. Therefore a negative value means addition instead of subtraction!

#### <a id="c-struct-rkisp1_cif_isp_bls_config"></a>`struct rkisp1_cif_isp_bls_config`

Configuration used by black level subtraction

**Definition**

```c
struct rkisp1_cif_isp_bls_config {
    __u8 enable_auto;
    __u8 en_windows;
    struct rkisp1_cif_isp_window bls_window1;
    struct rkisp1_cif_isp_window bls_window2;
    __u8 bls_samples;
    struct rkisp1_cif_isp_bls_fixed_val fixed_val;
};
```

**Members**

- `enable_auto`: Automatic mode activated means that the measured values
  are subtracted. Otherwise the fixed subtraction
  values will be subtracted.
- `en_windows`: enabled window
- `bls_window1`: Measurement window 1 size
- `bls_window2`: Measurement window 2 size
- `bls_samples`: Set amount of measured pixels for each Bayer position
  (A, B,C and D) to 2^bls_samples.
- `fixed_val`: Fixed subtraction values

#### <a id="c-struct-rkisp1_cif_isp_dpcc_methods_config"></a>`struct rkisp1_cif_isp_dpcc_methods_config`

DPCC methods set configuration

**Definition**

```c
struct rkisp1_cif_isp_dpcc_methods_config {
    __u32 method;
    __u32 line_thresh;
    __u32 line_mad_fac;
    __u32 pg_fac;
    __u32 rnd_thresh;
    __u32 rg_fac;
};
```

**Members**

- `method`: Method enable bits (RKISP1_CIF_ISP_DPCC_METHODS_SET_*)
- `line_thresh`: Line threshold (RKISP1_CIF_ISP_DPCC_LINE_THRESH_*)
- `line_mad_fac`: Line Mean Absolute Difference factor (RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_*)
- `pg_fac`: Peak gradient factor (RKISP1_CIF_ISP_DPCC_PG_FAC_*)
- `rnd_thresh`: Rank Neighbor Difference threshold (RKISP1_CIF_ISP_DPCC_RND_THRESH_*)
- `rg_fac`: Rank gradient factor (RKISP1_CIF_ISP_DPCC_RG_FAC_*)

**Description**

This structure stores the configuration of one set of methods for the DPCC
algorithm. Multiple methods can be selected in each set (independently for
the Green and Red/Blue components) through the **method** field, the result is
the logical AND of all enabled methods. The remaining fields set thresholds
and factors for each method.

#### <a id="c-struct-rkisp1_cif_isp_dpcc_config"></a>`struct rkisp1_cif_isp_dpcc_config`

Configuration used by DPCC

**Definition**

```c
struct rkisp1_cif_isp_dpcc_config {
    __u32 mode;
    __u32 output_mode;
    __u32 set_use;
    struct rkisp1_cif_isp_dpcc_methods_config methods[RKISP1_CIF_ISP_DPCC_METHODS_MAX];
    __u32 ro_limits;
    __u32 rnd_offs;
};
```

**Members**

- `mode`: DPCC mode (RKISP1_CIF_ISP_DPCC_MODE_*)
- `output_mode`: Interpolation output mode (RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_*)
- `set_use`: Methods sets selection (RKISP1_CIF_ISP_DPCC_SET_USE_*)
- `methods`: Methods sets configuration
- `ro_limits`: Rank order limits (RKISP1_CIF_ISP_DPCC_RO_LIMITS_*)
- `rnd_offs`: Differential rank offsets for rank neighbor difference (RKISP1_CIF_ISP_DPCC_RND_OFFS_*)

**Description**

Configuration used by Defect Pixel Cluster Correction. Three sets of methods
can be configured and selected through the **set_use** field. The result is the
logical OR of all enabled sets.

#### <a id="c-struct-rkisp1_cif_isp_gamma_corr_curve"></a>`struct rkisp1_cif_isp_gamma_corr_curve`

gamma curve point definition y-axis (output).

**Definition**

```c
struct rkisp1_cif_isp_gamma_corr_curve {
    __u16 gamma_y[RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE];
};
```

**Members**

- `gamma_y`: the values for the y-axis of gamma curve points. Each value is 12 bit.

**Description**

The reset values define a linear curve which has the same effect as bypass. Reset values are:
gamma_y\[0\] = 0x0000, gamma_y\[1\] = 0x0100, ... gamma_y\[15\] = 0x0f00, gamma_y\[16\] = 0xfff

#### <a id="c-struct-rkisp1_cif_isp_gamma_curve_x_axis_pnts"></a>`struct rkisp1_cif_isp_gamma_curve_x_axis_pnts`

De-Gamma Curve definition x increments (sampling points). gamma_dx0 is for the lower samples (1-8), gamma_dx1 is for the higher samples (9-16). The reset values for both fields is 0x44444444. This means that each sample is 4 units away from the previous one on the x-axis.

**Definition**

```c
struct rkisp1_cif_isp_gamma_curve_x_axis_pnts {
    __u32 gamma_dx0;
    __u32 gamma_dx1;
};
```

**Members**

- `gamma_dx0`: gamma curve sample points definitions. Bits 0:2 for sample 1. Bit 3 unused.
  Bits 4:6 for sample 2. bit 7 unused ... Bits 28:30 for sample 8. Bit 31 unused
- `gamma_dx1`: gamma curve sample points definitions. Bits 0:2 for sample 9. Bit 3 unused.
  Bits 4:6 for sample 10. bit 7 unused ... Bits 28:30 for sample 16. Bit 31 unused

#### <a id="c-struct-rkisp1_cif_isp_sdg_config"></a>`struct rkisp1_cif_isp_sdg_config`

Configuration used by sensor degamma

**Definition**

```c
struct rkisp1_cif_isp_sdg_config {
    struct rkisp1_cif_isp_gamma_corr_curve curve_r;
    struct rkisp1_cif_isp_gamma_corr_curve curve_g;
    struct rkisp1_cif_isp_gamma_corr_curve curve_b;
    struct rkisp1_cif_isp_gamma_curve_x_axis_pnts xa_pnts;
};
```

**Members**

- `curve_r`: gamma curve point definition axis for red
- `curve_g`: gamma curve point definition axis for green
- `curve_b`: gamma curve point definition axis for blue
- `xa_pnts`: x axis increments

#### <a id="c-struct-rkisp1_cif_isp_lsc_config"></a>`struct rkisp1_cif_isp_lsc_config`

Configuration used by Lens shading correction

**Definition**

```c
struct rkisp1_cif_isp_lsc_config {
    __u16 r_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
    __u16 gr_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
    __u16 gb_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
    __u16 b_data_tbl[RKISP1_CIF_ISP_LSC_SAMPLES_MAX][RKISP1_CIF_ISP_LSC_SAMPLES_MAX];
    __u16 x_grad_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
    __u16 y_grad_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
    __u16 x_size_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
    __u16 y_size_tbl[RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE];
    __u16 config_width;
    __u16 config_height;
};
```

**Members**

- `r_data_tbl`: sample table red
- `gr_data_tbl`: sample table green (red)
- `gb_data_tbl`: sample table green (blue)
- `b_data_tbl`: sample table blue
- `x_grad_tbl`: gradient table x
- `y_grad_tbl`: gradient table y
- `x_size_tbl`: size table x
- `y_size_tbl`: size table y
- `config_width`: not used at the moment
- `config_height`: not used at the moment

#### <a id="c-struct-rkisp1_cif_isp_ie_config"></a>`struct rkisp1_cif_isp_ie_config`

Configuration used by image effects

**Definition**

```c
struct rkisp1_cif_isp_ie_config {
    __u16 effect;
    __u16 color_sel;
    __u16 eff_mat_1;
    __u16 eff_mat_2;
    __u16 eff_mat_3;
    __u16 eff_mat_4;
    __u16 eff_mat_5;
    __u16 eff_tint;
};
```

**Members**

- `effect`: values from 'enum v4l2_colorfx'. Possible values are: V4L2_COLORFX_SEPIA,
  V4L2_COLORFX_SET_CBCR, V4L2_COLORFX_AQUA, V4L2_COLORFX_EMBOSS,
  V4L2_COLORFX_SKETCH,   V4L2_COLORFX_BW,   V4L2_COLORFX_NEGATIVE
- `color_sel`: bits 0:2 - colors bitmask (001 - blue, 010 - green, 100 - red).
  bits 8:15 - Threshold value of the RGB colors for the color selection effect.
- `eff_mat_1`: 3x3 Matrix Coefficients for Emboss Effect 1
- `eff_mat_2`: 3x3 Matrix Coefficients for Emboss Effect 2
- `eff_mat_3`: 3x3 Matrix Coefficients for Emboss 3/Sketch 1
- `eff_mat_4`: 3x3 Matrix Coefficients for Sketch Effect 2
- `eff_mat_5`: 3x3 Matrix Coefficients for Sketch Effect 3
- `eff_tint`: Chrominance increment values of tint (used for sepia effect)

#### <a id="c-struct-rkisp1_cif_isp_cproc_config"></a>`struct rkisp1_cif_isp_cproc_config`

Configuration used by Color Processing

**Definition**

```c
struct rkisp1_cif_isp_cproc_config {
    __u8 c_out_range;
    __u8 y_in_range;
    __u8 y_out_range;
    __u8 contrast;
    __u8 brightness;
    __u8 sat;
    __u8 hue;
};
```

**Members**

- `c_out_range`: Chrominance pixel clipping range at output.
  (0 for limit, 1 for full)
- `y_in_range`: Luminance pixel clipping range at output.
- `y_out_range`: Luminance pixel clipping range at output.
- `contrast`: 00~ff, 0.0~1.992
- `brightness`: 80~7F, -128~+127
- `sat`: saturation, 00~FF, 0.0~1.992
- `hue`: 80~7F, -90~+87.188

#### <a id="c-struct-rkisp1_cif_isp_awb_meas_config"></a>`struct rkisp1_cif_isp_awb_meas_config`

Configuration for the AWB statistics

**Definition**

```c
struct rkisp1_cif_isp_awb_meas_config {
    struct rkisp1_cif_isp_window awb_wnd;
    __u32 awb_mode;
    __u8 max_y;
    __u8 min_y;
    __u8 max_csum;
    __u8 min_c;
    __u8 frames;
    __u8 awb_ref_cr;
    __u8 awb_ref_cb;
    __u8 enable_ymax_cmp;
};
```

**Members**

- `awb_wnd`: white balance measurement window (in pixels)
- `awb_mode`: the awb meas mode. From enum rkisp1_cif_isp_awb_mode_type.
- `max_y`: only pixels values \< max_y contribute to awb measurement, set to 0
  to disable this feature
- `min_y`: only pixels values > min_y contribute to awb measurement
- `max_csum`: Chrominance sum maximum value, only consider pixels with Cb+Cr,
  smaller than threshold for awb measurements
- `min_c`: Chrominance minimum value, only consider pixels with Cb/Cr
  each greater than threshold value for awb measurements
- `frames`: number of frames - 1 used for mean value calculation
  (ucFrames=0 means 1 Frame)
- `awb_ref_cr`: reference Cr value for AWB regulation, target for AWB
- `awb_ref_cb`: reference Cb value for AWB regulation, target for AWB
- `enable_ymax_cmp`: enable Y_MAX compare (Not valid in RGB measurement mode.)

#### <a id="c-struct-rkisp1_cif_isp_awb_gain_config"></a>`struct rkisp1_cif_isp_awb_gain_config`

Configuration used by auto white balance gain

**Definition**

```c
struct rkisp1_cif_isp_awb_gain_config {
    __u16 gain_red;
    __u16 gain_green_r;
    __u16 gain_blue;
    __u16 gain_green_b;
};
```

**Members**

- `gain_red`: gain value for red component.
- `gain_green_r`: gain value for green component in red line.
- `gain_blue`: gain value for blue component.
- `gain_green_b`: gain value for green component in blue line.

**Description**

All fields in this struct are 10 bit, where:
0x100h = 1, unsigned integer value, range 0 to 4 with 8 bit fractional part.

out_data_x = ( AWB_GAIN_X * in_data + 128) >> 8

#### <a id="c-struct-rkisp1_cif_isp_flt_config"></a>`struct rkisp1_cif_isp_flt_config`

Configuration used by ISP filtering

**Definition**

```c
struct rkisp1_cif_isp_flt_config {
    __u32 mode;
    __u8 grn_stage1;
    __u8 chr_h_mode;
    __u8 chr_v_mode;
    __u32 thresh_bl0;
    __u32 thresh_bl1;
    __u32 thresh_sh0;
    __u32 thresh_sh1;
    __u32 lum_weight;
    __u32 fac_sh1;
    __u32 fac_sh0;
    __u32 fac_mid;
    __u32 fac_bl0;
    __u32 fac_bl1;
};
```

**Members**

- `mode`: ISP_FILT_MODE register fields (from enum rkisp1_cif_isp_flt_mode)
- `grn_stage1`: Green filter stage 1 select (range 0x0...0x8)
- `chr_h_mode`: Chroma filter horizontal mode
- `chr_v_mode`: Chroma filter vertical mode
- `thresh_bl0`: If thresh_bl1 \< sum_grad \< thresh_bl0 then fac_bl0 is selected (blurring th)
- `thresh_bl1`: If sum_grad \< thresh_bl1 then fac_bl1 is selected (blurring th)
- `thresh_sh0`: If thresh_sh0 \< sum_grad \< thresh_sh1 then thresh_sh0 is selected (sharpening th)
- `thresh_sh1`: If thresh_sh1 \< sum_grad then thresh_sh1 is selected (sharpening th)
- `lum_weight`: Parameters for luminance weight function.
- `fac_sh1`: filter factor for sharp1 level
- `fac_sh0`: filter factor for sharp0 level
- `fac_mid`: filter factor for mid level and for static filter mode
- `fac_bl0`: filter factor for blur 0 level
- `fac_bl1`: filter factor for blur 1 level (max blur)

**Description**

All 4 threshold fields (thresh_*) are 10 bits.
All 6 factor fields (fac_*) are 6 bits.

#### <a id="c-struct-rkisp1_cif_isp_bdm_config"></a>`struct rkisp1_cif_isp_bdm_config`

Configuration used by Bayer DeMosaic

**Definition**

```c
struct rkisp1_cif_isp_bdm_config {
    __u8 demosaic_th;
};
```

**Members**

- `demosaic_th`: threshold for bayer demosaicing texture detection

#### <a id="c-struct-rkisp1_cif_isp_ctk_config"></a>`struct rkisp1_cif_isp_ctk_config`

Configuration used by Cross Talk correction

**Definition**

```c
struct rkisp1_cif_isp_ctk_config {
    __u16 coeff[3][3];
    __u16 ct_offset[3];
};
```

**Members**

- `coeff`: color correction matrix. Values are 11-bit signed fixed-point numbers with 4 bit integer
  and 7 bit fractional part, ranging from -8 (0x400) to +7.992 (0x3FF). 0 is
  represented by 0x000 and a coefficient value of 1 as 0x080.
- `ct_offset`: Red, Green, Blue offsets for the crosstalk correction matrix

#### <a id="c-struct-rkisp1_cif_isp_goc_config"></a>`struct rkisp1_cif_isp_goc_config`

Configuration used by Gamma Out correction

**Definition**

```c
struct rkisp1_cif_isp_goc_config {
    __u32 mode;
    __u16 gamma_y[RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES];
};
```

**Members**

- `mode`: goc mode (from enum rkisp1_cif_isp_goc_mode)
- `gamma_y`: gamma out curve y-axis for all color components

**Description**

The number of entries of **gamma_y** depends on the hardware revision
as is reported by the hw_revision field of the struct media_device_info
that is returned by ioctl MEDIA_IOC_DEVICE_INFO.

V10 has RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10 entries, V12 has
RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V12 entries.
RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES is equal to the maximum of the two.

#### <a id="c-struct-rkisp1_cif_isp_hst_config"></a>`struct rkisp1_cif_isp_hst_config`

Configuration for Histogram statistics

**Definition**

```c
struct rkisp1_cif_isp_hst_config {
    __u32 mode;
    __u8 histogram_predivider;
    struct rkisp1_cif_isp_window meas_window;
    __u8 hist_weight[RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE];
};
```

**Members**

- `mode`: histogram mode (from enum rkisp1_cif_isp_histogram_mode)
- `histogram_predivider`: process every stepsize pixel, all other pixels are
  skipped
- `meas_window`: coordinates of the measure window
- `hist_weight`: weighting factor for sub-windows

**Description**

The number of entries of **hist_weight** depends on the hardware revision
as is reported by the hw_revision field of the struct media_device_info
that is returned by ioctl MEDIA_IOC_DEVICE_INFO.

V10 has RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V10 entries, V12 has
RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE_V12 entries.
RKISP1_CIF_ISP_HISTOGRAM_WEIGHT_GRIDS_SIZE is equal to the maximum of the
two.

#### <a id="c-struct-rkisp1_cif_isp_aec_config"></a>`struct rkisp1_cif_isp_aec_config`

Configuration for Auto Exposure statistics

**Definition**

```c
struct rkisp1_cif_isp_aec_config {
    __u32 mode;
    __u32 autostop;
    struct rkisp1_cif_isp_window meas_window;
};
```

**Members**

- `mode`: Exposure measure mode (from enum rkisp1_cif_isp_exp_meas_mode)
- `autostop`: stop mode (from enum rkisp1_cif_isp_exp_ctrl_autostop)
- `meas_window`: coordinates of the measure window

#### <a id="c-struct-rkisp1_cif_isp_afc_config"></a>`struct rkisp1_cif_isp_afc_config`

Configuration for the Auto Focus statistics

**Definition**

```c
struct rkisp1_cif_isp_afc_config {
    __u8 num_afm_win;
    struct rkisp1_cif_isp_window afm_win[RKISP1_CIF_ISP_AFM_MAX_WINDOWS];
    __u32 thres;
    __u32 var_shift;
};
```

**Members**

- `num_afm_win`: max RKISP1_CIF_ISP_AFM_MAX_WINDOWS
- `afm_win`: coordinates of the meas window
- `thres`: threshold used for minimizing the influence of noise
- `var_shift`: the number of bits for the shift operation at the end of the
  calculation chain.

#### <a id="c-enum-rkisp1_cif_isp_dpf_gain_usage"></a>`enum rkisp1_cif_isp_dpf_gain_usage`

dpf gain usage

**Constants**

- `RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED`: don't use any gains in preprocessing stage
- `RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_GAINS`: use only the noise function gains from
  registers DPF_NF_GAIN_R, ...
- `RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS`: use only the gains from LSC module
- `RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_LSC_GAINS`: use the noise function gains and the
  gains from LSC module
- `RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS`: use only the gains from AWB module
- `RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS`: use the gains from AWB and LSC module
- `RKISP1_CIF_ISP_DPF_GAIN_USAGE_MAX`: upper border (only for an internal evaluation)

#### <a id="c-enum-rkisp1_cif_isp_dpf_rb_filtersize"></a>`enum rkisp1_cif_isp_dpf_rb_filtersize`

Red and blue filter sizes

**Constants**

- `RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9`: red and blue filter kernel size 13x9
  (means 7x5 active pixel)
- `RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9`: red and blue filter kernel size 9x9
  (means 5x5 active pixel)

#### <a id="c-enum-rkisp1_cif_isp_dpf_nll_scale_mode"></a>`enum rkisp1_cif_isp_dpf_nll_scale_mode`

dpf noise level scale mode

**Constants**

- `RKISP1_CIF_ISP_NLL_SCALE_LINEAR`: use a linear scaling
- `RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC`: use a logarithmic scaling

#### <a id="c-struct-rkisp1_cif_isp_dpf_nll"></a>`struct rkisp1_cif_isp_dpf_nll`

Noise level lookup

**Definition**

```c
struct rkisp1_cif_isp_dpf_nll {
    __u16 coeff[RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS];
    __u32 scale_mode;
};
```

**Members**

- `coeff`: Noise level Lookup coefficient
- `scale_mode`: dpf noise level scale mode (from enum rkisp1_cif_isp_dpf_nll_scale_mode)

#### <a id="c-struct-rkisp1_cif_isp_dpf_rb_flt"></a>`struct rkisp1_cif_isp_dpf_rb_flt`

Red blue filter config

**Definition**

```c
struct rkisp1_cif_isp_dpf_rb_flt {
    __u32 fltsize;
    __u8 spatial_coeff[RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS];
    __u8 r_enable;
    __u8 b_enable;
};
```

**Members**

- `fltsize`: The filter size for the red and blue pixels
  (from enum rkisp1_cif_isp_dpf_rb_filtersize)
- `spatial_coeff`: Spatial weights
- `r_enable`: enable filter processing for red pixels
- `b_enable`: enable filter processing for blue pixels

#### <a id="c-struct-rkisp1_cif_isp_dpf_g_flt"></a>`struct rkisp1_cif_isp_dpf_g_flt`

Green filter Configuration

**Definition**

```c
struct rkisp1_cif_isp_dpf_g_flt {
    __u8 spatial_coeff[RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS];
    __u8 gr_enable;
    __u8 gb_enable;
};
```

**Members**

- `spatial_coeff`: Spatial weights
- `gr_enable`: enable filter processing for green pixels in green/red lines
- `gb_enable`: enable filter processing for green pixels in green/blue lines

#### <a id="c-struct-rkisp1_cif_isp_dpf_gain"></a>`struct rkisp1_cif_isp_dpf_gain`

Noise function Configuration

**Definition**

```c
struct rkisp1_cif_isp_dpf_gain {
    __u32 mode;
    __u16 nf_r_gain;
    __u16 nf_b_gain;
    __u16 nf_gr_gain;
    __u16 nf_gb_gain;
};
```

**Members**

- `mode`: dpf gain usage  (from enum rkisp1_cif_isp_dpf_gain_usage)
- `nf_r_gain`: Noise function Gain that replaces the AWB gain for red pixels
- `nf_b_gain`: Noise function Gain that replaces the AWB gain for blue pixels
- `nf_gr_gain`: Noise function Gain that replaces the AWB gain
  for green pixels in a red line
- `nf_gb_gain`: Noise function Gain that replaces the AWB gain
  for green pixels in a blue line

#### <a id="c-struct-rkisp1_cif_isp_dpf_config"></a>`struct rkisp1_cif_isp_dpf_config`

Configuration used by De-noising pre-filter

**Definition**

```c
struct rkisp1_cif_isp_dpf_config {
    struct rkisp1_cif_isp_dpf_gain gain;
    struct rkisp1_cif_isp_dpf_g_flt g_flt;
    struct rkisp1_cif_isp_dpf_rb_flt rb_flt;
    struct rkisp1_cif_isp_dpf_nll nll;
};
```

**Members**

- `gain`: noise function gain
- `g_flt`: green filter config
- `rb_flt`: red blue filter config
- `nll`: noise level lookup

#### <a id="c-struct-rkisp1_cif_isp_dpf_strength_config"></a>`struct rkisp1_cif_isp_dpf_strength_config`

strength of the filter

**Definition**

```c
struct rkisp1_cif_isp_dpf_strength_config {
    __u8 r;
    __u8 g;
    __u8 b;
};
```

**Members**

- `r`: filter strength of the RED filter
- `g`: filter strength of the GREEN filter
- `b`: filter strength of the BLUE filter

#### <a id="c-struct-rkisp1_cif_isp_isp_other_cfg"></a>`struct rkisp1_cif_isp_isp_other_cfg`

Parameters for some blocks in rockchip isp1

**Definition**

```c
struct rkisp1_cif_isp_isp_other_cfg {
    struct rkisp1_cif_isp_dpcc_config dpcc_config;
    struct rkisp1_cif_isp_bls_config bls_config;
    struct rkisp1_cif_isp_sdg_config sdg_config;
    struct rkisp1_cif_isp_lsc_config lsc_config;
    struct rkisp1_cif_isp_awb_gain_config awb_gain_config;
    struct rkisp1_cif_isp_flt_config flt_config;
    struct rkisp1_cif_isp_bdm_config bdm_config;
    struct rkisp1_cif_isp_ctk_config ctk_config;
    struct rkisp1_cif_isp_goc_config goc_config;
    struct rkisp1_cif_isp_dpf_config dpf_config;
    struct rkisp1_cif_isp_dpf_strength_config dpf_strength_config;
    struct rkisp1_cif_isp_cproc_config cproc_config;
    struct rkisp1_cif_isp_ie_config ie_config;
};
```

**Members**

- `dpcc_config`: Defect Pixel Cluster Correction config
- `bls_config`: black level subtraction config
- `sdg_config`: sensor degamma config
- `lsc_config`: Lens Shade config
- `awb_gain_config`: Auto White balance gain config
- `flt_config`: filter config
- `bdm_config`: demosaic config
- `ctk_config`: cross talk config
- `goc_config`: gamma out config
- `dpf_config`: De-noising pre-filter config
- `dpf_strength_config`: dpf strength config
- `cproc_config`: color process config
- `ie_config`: image effects config

#### <a id="c-struct-rkisp1_cif_isp_isp_meas_cfg"></a>`struct rkisp1_cif_isp_isp_meas_cfg`

Rockchip ISP1 Measure Parameters

**Definition**

```c
struct rkisp1_cif_isp_isp_meas_cfg {
    struct rkisp1_cif_isp_awb_meas_config awb_meas_config;
    struct rkisp1_cif_isp_hst_config hst_config;
    struct rkisp1_cif_isp_aec_config aec_config;
    struct rkisp1_cif_isp_afc_config afc_config;
};
```

**Members**

- `awb_meas_config`: auto white balance config
- `hst_config`: histogram config
- `aec_config`: auto exposure config
- `afc_config`: auto focus config

#### <a id="c-struct-rkisp1_params_cfg"></a>`struct rkisp1_params_cfg`

Rockchip ISP1 Input Parameters Meta Data

**Definition**

```c
struct rkisp1_params_cfg {
    __u32 module_en_update;
    __u32 module_ens;
    __u32 module_cfg_update;
    struct rkisp1_cif_isp_isp_meas_cfg meas;
    struct rkisp1_cif_isp_isp_other_cfg others;
};
```

**Members**

- `module_en_update`: mask the enable bits of which module should be updated
- `module_ens`: mask the enable value of each module, only update the module
  which correspond bit was set in module_en_update
- `module_cfg_update`: mask the config bits of which module should be updated
- `meas`: measurement config
- `others`: other config

#### <a id="c-struct-rkisp1_cif_isp_compand_bls_config"></a>`struct rkisp1_cif_isp_compand_bls_config`

Rockchip ISP1 Companding parameters (BLS)

**Definition**

```c
struct rkisp1_cif_isp_compand_bls_config {
    __u32 r;
    __u32 gr;
    __u32 gb;
    __u32 b;
};
```

**Members**

- `r`: Fixed subtraction value for Bayer pattern R
- `gr`: Fixed subtraction value for Bayer pattern Gr
- `gb`: Fixed subtraction value for Bayer pattern Gb
- `b`: Fixed subtraction value for Bayer pattern B

**Description**

The values will be subtracted from the sensor values. Note that unlike the
dedicated BLS block, the BLS values in the compander are 20-bit unsigned.

#### <a id="c-struct-rkisp1_cif_isp_compand_curve_config"></a>`struct rkisp1_cif_isp_compand_curve_config`

Rockchip ISP1 Companding parameters (expand and compression curves)

**Definition**

```c
struct rkisp1_cif_isp_compand_curve_config {
    __u8 px[RKISP1_CIF_ISP_COMPAND_NUM_POINTS];
    __u32 x[RKISP1_CIF_ISP_COMPAND_NUM_POINTS];
    __u32 y[RKISP1_CIF_ISP_COMPAND_NUM_POINTS];
};
```

**Members**

- `px`: Compand curve x-values. Each value stores the distance from the
  previous x-value, expressed as log2 of the distance on 5 bits.
- `x`: Compand curve x-values. The functionality of these parameters are
  unknown due to do a lack of hardware documentation, but these are left
  here for future compatibility purposes.
- `y`: Compand curve y-values

#### <a id="c-struct-rkisp1_cif_isp_wdr_tone_curve"></a>`struct rkisp1_cif_isp_wdr_tone_curve`

Tone mapping curve definition for WDR.

**Definition**

```c
struct rkisp1_cif_isp_wdr_tone_curve {
    __u32 dY[RKISP1_CIF_ISP_WDR_CURVE_NUM_DY_REGS];
    __u16 ym[RKISP1_CIF_ISP_WDR_CURVE_NUM_COEFF];
};
```

**Members**

- `dY`: the dYn increments for horizontal (input) axis of the tone curve.
  each 3-bit dY value represents an increment of 2**(value+3).
  dY\[0\] bits 0:2 is increment dY1, bit 3 unused
  dY\[0\] bits 4:6 is increment dY2, bit 7 unused
  \...
  dY\[0\] bits 28:30 is increment dY8, bit 31 unused
  ... and so on till dY\[3\] bits 28:30 is increment dY32, bit 31 unused.
- `ym`: the Ym values for the vertical (output) axis of the tone curve.
  each value is 13 bit.

#### <a id="c-struct-rkisp1_cif_isp_wdr_iref_config"></a>`struct rkisp1_cif_isp_wdr_iref_config`

Illumination reference config for WDR.

**Definition**

```c
struct rkisp1_cif_isp_wdr_iref_config {
    __u8 rgb_factor;
    __u8 use_y9_8;
    __u8 use_rgb7_8;
    __u8 disable_transient;
};
```

**Members**

- `rgb_factor`: defines how much influence the RGBmax approach has in
  comparison to Y (valid values are 0..8).
- `use_y9_8`: use Y*9/8 for maximum value calculation along with the
  default of R, G, B for noise reduction.
- `use_rgb7_8`: decrease RGBMax by 7/8 for noise reduction.
- `disable_transient`: disable transient calculation between Y and RGBY_max.

**Description**

Use illumination reference value as described below, instead of only the
luminance (Y) value for tone mapping and gain calculations:
IRef = (rgb_factor * RGBMax_tr + (8 - rgb_factor) * Y)/8

#### <a id="c-struct-rkisp1_cif_isp_wdr_config"></a>`struct rkisp1_cif_isp_wdr_config`

Configuration for wide dynamic range.

**Definition**

```c
struct rkisp1_cif_isp_wdr_config {
    struct rkisp1_cif_isp_wdr_tone_curve tone_curve;
    struct rkisp1_cif_isp_wdr_iref_config iref_config;
    __u16 rgb_offset;
    __u16 luma_offset;
    __u16 dmin_thresh;
    __u8 dmin_strength;
    __u8 use_rgb_colorspace;
    __u8 bypass_chroma_mapping;
    __u8 use_iref;
};
```

**Members**

- `tone_curve`: tone mapping curve.
- `iref_config`: illumination reference configuration. (when use_iref is true)
- `rgb_offset`: RGB offset value for RGB operation mode. (12 bits)
- `luma_offset`: luminance offset value for RGB operation mode. (12 bits)
- `dmin_thresh`: lower threshold for deltaMin value. (12 bits)
- `dmin_strength`: strength factor for deltaMin. (valid range is 0x00..0x10)
- `use_rgb_colorspace`: use RGB instead of luminance/chrominance colorspace.
- `bypass_chroma_mapping`: disable chrominance mapping (only valid if
  use_rgb_colorspace = 0)
- `use_iref`: use illumination reference instead of Y for tone mapping
  and gain calculations.

#### <a id="c-struct-rkisp1_cif_isp_awb_meas"></a>`struct rkisp1_cif_isp_awb_meas`

AWB measured values

**Definition**

```c
struct rkisp1_cif_isp_awb_meas {
    __u32 cnt;
    __u8 mean_y_or_g;
    __u8 mean_cb_or_b;
    __u8 mean_cr_or_r;
};
```

**Members**

- `cnt`: White pixel count, number of "white pixels" found during last
  measurement
- `mean_y_or_g`: Mean value of Y within window and frames,
  Green if RGB is selected.
- `mean_cb_or_b`: Mean value of Cb within window and frames,
  Blue if RGB is selected.
- `mean_cr_or_r`: Mean value of Cr within window and frames,
  Red if RGB is selected.

#### <a id="c-struct-rkisp1_cif_isp_awb_stat"></a>`struct rkisp1_cif_isp_awb_stat`

statistics automatic white balance data

**Definition**

```c
struct rkisp1_cif_isp_awb_stat {
    struct rkisp1_cif_isp_awb_meas awb_mean[RKISP1_CIF_ISP_AWB_MAX_GRID];
};
```

**Members**

- `awb_mean`: Mean measured data

#### <a id="c-struct-rkisp1_cif_isp_bls_meas_val"></a>`struct rkisp1_cif_isp_bls_meas_val`

BLS measured values

**Definition**

```c
struct rkisp1_cif_isp_bls_meas_val {
    __u16 meas_r;
    __u16 meas_gr;
    __u16 meas_gb;
    __u16 meas_b;
};
```

**Members**

- `meas_r`: Mean measured value for Bayer pattern R
- `meas_gr`: Mean measured value for Bayer pattern Gr
- `meas_gb`: Mean measured value for Bayer pattern Gb
- `meas_b`: Mean measured value for Bayer pattern B

#### <a id="c-struct-rkisp1_cif_isp_ae_stat"></a>`struct rkisp1_cif_isp_ae_stat`

statistics auto exposure data

**Definition**

```c
struct rkisp1_cif_isp_ae_stat {
    __u8 exp_mean[RKISP1_CIF_ISP_AE_MEAN_MAX];
    struct rkisp1_cif_isp_bls_meas_val bls_val;
};
```

**Members**

- `exp_mean`: Mean luminance value of block xx
- `bls_val`: BLS measured values

**Description**

The number of entries of **exp_mean** depends on the hardware revision
as is reported by the hw_revision field of the struct media_device_info
that is returned by ioctl MEDIA_IOC_DEVICE_INFO.

V10 has RKISP1_CIF_ISP_AE_MEAN_MAX_V10 entries, V12 has
RKISP1_CIF_ISP_AE_MEAN_MAX_V12 entries. RKISP1_CIF_ISP_AE_MEAN_MAX is equal
to the maximum of the two.

Image is divided into 5x5 blocks on V10 and 9x9 blocks on V12.

#### <a id="c-struct-rkisp1_cif_isp_af_meas_val"></a>`struct rkisp1_cif_isp_af_meas_val`

AF measured values

**Definition**

```c
struct rkisp1_cif_isp_af_meas_val {
    __u32 sum;
    __u32 lum;
};
```

**Members**

- `sum`: sharpness value
- `lum`: luminance value

#### <a id="c-struct-rkisp1_cif_isp_af_stat"></a>`struct rkisp1_cif_isp_af_stat`

statistics auto focus data

**Definition**

```c
struct rkisp1_cif_isp_af_stat {
    struct rkisp1_cif_isp_af_meas_val window[RKISP1_CIF_ISP_AFM_MAX_WINDOWS];
};
```

**Members**

- `window`: AF measured value of window x

**Description**

The module measures the sharpness in 3 windows of selectable size via
register settings(ISP_AFM_*_A/B/C)

#### <a id="c-struct-rkisp1_cif_isp_hist_stat"></a>`struct rkisp1_cif_isp_hist_stat`

statistics histogram data

**Definition**

```c
struct rkisp1_cif_isp_hist_stat {
    __u32 hist_bins[RKISP1_CIF_ISP_HIST_BIN_N_MAX];
};
```

**Members**

- `hist_bins`: measured bin counters. Each bin is a 20 bits unsigned fixed point
  type. Bits 0-4 are the fractional part and bits 5-19 are the
  integer part.

**Description**

The window of the measurements area is divided to 5x5 sub-windows for
V10 and to 9x9 sub-windows for V12. The histogram is then computed for each
sub-window independently and the final result is a weighted average of the
histogram measurements on all sub-windows. The window of the measurements
area and the weight of each sub-window are configurable using
struct **rkisp1_cif_isp_hst_config**.

The histogram contains 16 bins in V10 and 32 bins in V12.

The number of entries of **hist_bins** depends on the hardware revision
as is reported by the hw_revision field of the struct media_device_info
that is returned by ioctl MEDIA_IOC_DEVICE_INFO.

V10 has RKISP1_CIF_ISP_HIST_BIN_N_MAX_V10 entries, V12 has
RKISP1_CIF_ISP_HIST_BIN_N_MAX_V12 entries. RKISP1_CIF_ISP_HIST_BIN_N_MAX is
equal to the maximum of the two.

#### <a id="c-struct-rkisp1_cif_isp_stat"></a>`struct rkisp1_cif_isp_stat`

Rockchip ISP1 Statistics Data

**Definition**

```c
struct rkisp1_cif_isp_stat {
    struct rkisp1_cif_isp_awb_stat awb;
    struct rkisp1_cif_isp_ae_stat ae;
    struct rkisp1_cif_isp_af_stat af;
    struct rkisp1_cif_isp_hist_stat hist;
};
```

**Members**

- `awb`: statistics data for automatic white balance
- `ae`: statistics data for auto exposure
- `af`: statistics data for auto focus
- `hist`: statistics histogram data

#### <a id="c-struct-rkisp1_stat_buffer"></a>`struct rkisp1_stat_buffer`

Rockchip ISP1 Statistics Meta Data

**Definition**

```c
struct rkisp1_stat_buffer {
    __u32 meas_type;
    __u32 frame_id;
    struct rkisp1_cif_isp_stat params;
};
```

**Members**

- `meas_type`: measurement types (RKISP1_CIF_ISP_STAT_* definitions)
- `frame_id`: frame ID for sync
- `params`: statistics data

#### <a id="c-enum-rkisp1_ext_params_block_type"></a>`enum rkisp1_ext_params_block_type`

RkISP1 extensible params block type

**Constants**

- `RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`: Black level subtraction
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`: Defect pixel cluster correction
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`: Sensor de-gamma
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`: Auto white balance gains
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`: ISP filtering
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`: Bayer de-mosaic
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`: Cross-talk correction
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`: Gamma out correction
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`: De-noise pre-filter
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`: De-noise pre-filter strength
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`: Color processing
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`: Image effects
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`: Lens shading correction
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`: Auto white balance statistics
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`: Histogram statistics
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`: Auto exposure statistics
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`: Auto-focus statistics
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS`: BLS in the compand block
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND`: Companding expand curve
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS`: Companding compress curve
- `RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR`: Wide dynamic range

#### <a id="c-rkisp1_ext_params_block_header"></a>`rkisp1_ext_params_block_header`

```c
rkisp1_ext_params_block_header
```

RkISP1 extensible parameters block header

**Description**

This structure represents the common part of all the ISP configuration
blocks and is identical to [`v4l2_isp_params_block_header`](/kernel/userspace/userspace-api/media-v4l/v4l2-isp.md#c-struct-v4l2_isp_params_block_header).

The type field is one of the values enumerated by
[`rkisp1_ext_params_block_type`](#c-enum-rkisp1_ext_params_block_type) and specifies how the data should be
interpreted by the driver.

The flags field is a bitmask of per-block flags RKISP1_EXT_PARAMS_FL_*.

#### <a id="c-struct-rkisp1_ext_params_bls_config"></a>`struct rkisp1_ext_params_bls_config`

RkISP1 extensible params BLS config

**Definition**

```c
struct rkisp1_ext_params_bls_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_bls_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Black Level Subtraction configuration, see
  [`rkisp1_cif_isp_bls_config`](#c-struct-rkisp1_cif_isp_bls_config)

**Description**

RkISP1 extensible parameters Black Level Subtraction configuration block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS`.

#### <a id="c-struct-rkisp1_ext_params_dpcc_config"></a>`struct rkisp1_ext_params_dpcc_config`

RkISP1 extensible params DPCC config

**Definition**

```c
struct rkisp1_ext_params_dpcc_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_dpcc_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Defective Pixel Cluster Correction configuration, see
  [`rkisp1_cif_isp_dpcc_config`](#c-struct-rkisp1_cif_isp_dpcc_config)

**Description**

RkISP1 extensible parameters Defective Pixel Cluster Correction configuration
block. Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC`.

#### <a id="c-struct-rkisp1_ext_params_sdg_config"></a>`struct rkisp1_ext_params_sdg_config`

RkISP1 extensible params SDG config

**Definition**

```c
struct rkisp1_ext_params_sdg_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_sdg_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Sensor Degamma configuration, see
  [`rkisp1_cif_isp_sdg_config`](#c-struct-rkisp1_cif_isp_sdg_config)

**Description**

RkISP1 extensible parameters Sensor Degamma configuration block. Identified
by `RKISP1_EXT_PARAMS_BLOCK_TYPE_SDG`.

#### <a id="c-struct-rkisp1_ext_params_lsc_config"></a>`struct rkisp1_ext_params_lsc_config`

RkISP1 extensible params LSC config

**Definition**

```c
struct rkisp1_ext_params_lsc_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_lsc_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Lens Shading Correction configuration, see
  [`rkisp1_cif_isp_lsc_config`](#c-struct-rkisp1_cif_isp_lsc_config)

**Description**

RkISP1 extensible parameters Lens Shading Correction configuration block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_LSC`.

#### <a id="c-struct-rkisp1_ext_params_awb_gain_config"></a>`struct rkisp1_ext_params_awb_gain_config`

RkISP1 extensible params AWB gain config

**Definition**

```c
struct rkisp1_ext_params_awb_gain_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_awb_gain_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Auto-White Balance Gains configuration, see
  [`rkisp1_cif_isp_awb_gain_config`](#c-struct-rkisp1_cif_isp_awb_gain_config)

**Description**

RkISP1 extensible parameters Auto-White Balance Gains configuration block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_GAIN`.

#### <a id="c-struct-rkisp1_ext_params_flt_config"></a>`struct rkisp1_ext_params_flt_config`

RkISP1 extensible params FLT config

**Definition**

```c
struct rkisp1_ext_params_flt_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_flt_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Filter configuration, see [`rkisp1_cif_isp_flt_config`](#c-struct-rkisp1_cif_isp_flt_config)

**Description**

RkISP1 extensible parameters Filter configuration block. Identified by
`RKISP1_EXT_PARAMS_BLOCK_TYPE_FLT`.

#### <a id="c-struct-rkisp1_ext_params_bdm_config"></a>`struct rkisp1_ext_params_bdm_config`

RkISP1 extensible params BDM config

**Definition**

```c
struct rkisp1_ext_params_bdm_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_bdm_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Demosaicing configuration, see [`rkisp1_cif_isp_bdm_config`](#c-struct-rkisp1_cif_isp_bdm_config)

**Description**

RkISP1 extensible parameters Demosaicing configuration block. Identified by
`RKISP1_EXT_PARAMS_BLOCK_TYPE_BDM`.

#### <a id="c-struct-rkisp1_ext_params_ctk_config"></a>`struct rkisp1_ext_params_ctk_config`

RkISP1 extensible params CTK config

**Definition**

```c
struct rkisp1_ext_params_ctk_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_ctk_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Cross-Talk configuration, see [`rkisp1_cif_isp_ctk_config`](#c-struct-rkisp1_cif_isp_ctk_config)

**Description**

RkISP1 extensible parameters Cross-Talk configuration block. Identified by
`RKISP1_EXT_PARAMS_BLOCK_TYPE_CTK`.

#### <a id="c-struct-rkisp1_ext_params_goc_config"></a>`struct rkisp1_ext_params_goc_config`

RkISP1 extensible params GOC config

**Definition**

```c
struct rkisp1_ext_params_goc_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_goc_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Gamma-Out configuration, see [`rkisp1_cif_isp_goc_config`](#c-struct-rkisp1_cif_isp_goc_config)

**Description**

RkISP1 extensible parameters Gamma-Out configuration block. Identified by
`RKISP1_EXT_PARAMS_BLOCK_TYPE_GOC`.

#### <a id="c-struct-rkisp1_ext_params_dpf_config"></a>`struct rkisp1_ext_params_dpf_config`

RkISP1 extensible params DPF config

**Definition**

```c
struct rkisp1_ext_params_dpf_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_dpf_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: De-noise Pre-Filter configuration, see
  [`rkisp1_cif_isp_dpf_config`](#c-struct-rkisp1_cif_isp_dpf_config)

**Description**

RkISP1 extensible parameters De-noise Pre-Filter configuration block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF`.

#### <a id="c-struct-rkisp1_ext_params_dpf_strength_config"></a>`struct rkisp1_ext_params_dpf_strength_config`

RkISP1 extensible params DPF strength config

**Definition**

```c
struct rkisp1_ext_params_dpf_strength_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_dpf_strength_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: De-noise Pre-Filter strength configuration, see
  [`rkisp1_cif_isp_dpf_strength_config`](#c-struct-rkisp1_cif_isp_dpf_strength_config)

**Description**

RkISP1 extensible parameters De-noise Pre-Filter strength configuration
block. Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_DPF_STRENGTH`.

#### <a id="c-struct-rkisp1_ext_params_cproc_config"></a>`struct rkisp1_ext_params_cproc_config`

RkISP1 extensible params CPROC config

**Definition**

```c
struct rkisp1_ext_params_cproc_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_cproc_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Color processing configuration, see
  [`rkisp1_cif_isp_cproc_config`](#c-struct-rkisp1_cif_isp_cproc_config)

**Description**

RkISP1 extensible parameters Color Processing configuration block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_CPROC`.

#### <a id="c-struct-rkisp1_ext_params_ie_config"></a>`struct rkisp1_ext_params_ie_config`

RkISP1 extensible params IE config

**Definition**

```c
struct rkisp1_ext_params_ie_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_ie_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Image Effect configuration, see [`rkisp1_cif_isp_ie_config`](#c-struct-rkisp1_cif_isp_ie_config)

**Description**

RkISP1 extensible parameters Image Effect configuration block. Identified by
`RKISP1_EXT_PARAMS_BLOCK_TYPE_IE`.

#### <a id="c-struct-rkisp1_ext_params_awb_meas_config"></a>`struct rkisp1_ext_params_awb_meas_config`

RkISP1 extensible params AWB Meas config

**Definition**

```c
struct rkisp1_ext_params_awb_meas_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_awb_meas_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Auto-White Balance measure configuration, see
  [`rkisp1_cif_isp_awb_meas_config`](#c-struct-rkisp1_cif_isp_awb_meas_config)

**Description**

RkISP1 extensible parameters Auto-White Balance Measurement configuration
block. Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_AWB_MEAS`.

#### <a id="c-struct-rkisp1_ext_params_hst_config"></a>`struct rkisp1_ext_params_hst_config`

RkISP1 extensible params Histogram config

**Definition**

```c
struct rkisp1_ext_params_hst_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_hst_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Histogram statistics configuration, see
  [`rkisp1_cif_isp_hst_config`](#c-struct-rkisp1_cif_isp_hst_config)

**Description**

RkISP1 extensible parameters Histogram statistics configuration block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_HST_MEAS`.

#### <a id="c-struct-rkisp1_ext_params_aec_config"></a>`struct rkisp1_ext_params_aec_config`

RkISP1 extensible params AEC config

**Definition**

```c
struct rkisp1_ext_params_aec_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_aec_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Auto-Exposure statistics configuration, see
  [`rkisp1_cif_isp_aec_config`](#c-struct-rkisp1_cif_isp_aec_config)

**Description**

RkISP1 extensible parameters Auto-Exposure statistics configuration block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_AEC_MEAS`.

#### <a id="c-struct-rkisp1_ext_params_afc_config"></a>`struct rkisp1_ext_params_afc_config`

RkISP1 extensible params AFC config

**Definition**

```c
struct rkisp1_ext_params_afc_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_afc_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Auto-Focus statistics configuration, see
  [`rkisp1_cif_isp_afc_config`](#c-struct-rkisp1_cif_isp_afc_config)

**Description**

RkISP1 extensible parameters Auto-Focus statistics configuration block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_AFC_MEAS`.

#### <a id="c-struct-rkisp1_ext_params_compand_bls_config"></a>`struct rkisp1_ext_params_compand_bls_config`

RkISP1 extensible params Compand BLS config

**Definition**

```c
struct rkisp1_ext_params_compand_bls_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_compand_bls_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Companding BLS configuration, see
  [`rkisp1_cif_isp_compand_bls_config`](#c-struct-rkisp1_cif_isp_compand_bls_config)

**Description**

RkISP1 extensible parameters Companding configuration block (black level
subtraction). Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_BLS`.

#### <a id="c-struct-rkisp1_ext_params_compand_curve_config"></a>`struct rkisp1_ext_params_compand_curve_config`

RkISP1 extensible params Compand curve config

**Definition**

```c
struct rkisp1_ext_params_compand_curve_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_compand_curve_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: Companding curve configuration, see
  [`rkisp1_cif_isp_compand_curve_config`](#c-struct-rkisp1_cif_isp_compand_curve_config)

**Description**

RkISP1 extensible parameters Companding configuration block (expand and
compression curves). Identified by
`RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_EXPAND` or
`RKISP1_EXT_PARAMS_BLOCK_TYPE_COMPAND_COMPRESS`.

#### <a id="c-struct-rkisp1_ext_params_wdr_config"></a>`struct rkisp1_ext_params_wdr_config`

RkISP1 extensible params Wide dynamic range config

**Definition**

```c
struct rkisp1_ext_params_wdr_config {
    struct rkisp1_ext_params_block_header header;
    struct rkisp1_cif_isp_wdr_config config;
};
```

**Members**

- `header`: The RkISP1 extensible parameters header, see
  [`rkisp1_ext_params_block_header`](#c-rkisp1_ext_params_block_header)
- `config`: WDR configuration, see
  [`rkisp1_cif_isp_wdr_config`](#c-struct-rkisp1_cif_isp_wdr_config)

**Description**

RkISP1 extensible parameters WDR block.
Identified by `RKISP1_EXT_PARAMS_BLOCK_TYPE_WDR`

#### <a id="c-enum-rksip1_ext_param_buffer_version"></a>`enum rksip1_ext_param_buffer_version`

RkISP1 extensible parameters version

**Constants**

- `RKISP1_EXT_PARAM_BUFFER_V1`: First version of RkISP1 extensible parameters

#### <a id="c-struct-rkisp1_ext_params_cfg"></a>`struct rkisp1_ext_params_cfg`

RkISP1 extensible parameters configuration

**Definition**

```c
struct rkisp1_ext_params_cfg {
    __u32 version;
    __u32 data_size;
    __u8 data[RKISP1_EXT_PARAMS_MAX_SIZE];
};
```

**Members**

- `version`: The RkISP1 extensible parameters buffer version, see
  [`rksip1_ext_param_buffer_version`](#c-enum-rksip1_ext_param_buffer_version)
- `data_size`: The RkISP1 configuration data effective size, excluding this
  header
- `data`: The RkISP1 extensible configuration data blocks

**Description**

This is the driver-specific implementation of
[`v4l2_isp_params_buffer`](/kernel/userspace/userspace-api/media-v4l/v4l2-isp.md#c-struct-v4l2_isp_params_buffer).

Currently the single RKISP1_EXT_PARAM_BUFFER_V1 version is supported.
When a new format version will be added, a mechanism for userspace to query
the supported format versions will be implemented in the form of a read-only
V4L2 control. If such control is not available, userspace should assume only
RKISP1_EXT_PARAM_BUFFER_V1 is supported by the driver.

The read-only V4L2 control `RKISP1_CID_SUPPORTED_PARAMS_BLOCKS` can be used
to query the blocks supported by the device. It contains a bitmask where each
bit represents the availability of the corresponding entry from the
[`rkisp1_ext_params_block_type`](#c-enum-rkisp1_ext_params_block_type) enum. The current and default values
of the control represents the blocks supported by the device instance, while
the maximum value represents the blocks supported by the kernel driver,
independently of the device instance.

The expected memory layout of the parameters buffer is:

```text
+-------------------- struct rkisp1_ext_params_cfg -------------------+
| version = RKISP1_EXT_PARAM_BUFFER_V1;                               |
| data_size = sizeof(struct rkisp1_ext_params_bls_config)             |
|           + sizeof(struct rkisp1_ext_params_dpcc_config);           |
| +------------------------- data  ---------------------------------+ |
| | +------------- struct rkisp1_ext_params_bls_config -----------+ | |
| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_BLS;                | | | |
| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
| | | | size = sizeof(struct rkisp1_ext_params_bls_config);     | | | |
| | | +---------------------------------------------------------+ | | |
| | | +---------- struct rkisp1_cif_isp_bls_config -------------+ | | |
| | | | enable_auto = 0;                                        | | | |
| | | | fixed_val.r = 256;                                      | | | |
| | | | fixed_val.gr = 256;                                     | | | |
| | | | fixed_val.gb = 256;                                     | | | |
| | | | fixed_val.b = 256;                                      | | | |
| | | +---------------------------------------------------------+ | | |
| | +------------ struct rkisp1_ext_params_dpcc_config -----------+ | |
| | | +-------- struct rkisp1_ext_params_block_header  ---------+ | | |
| | | | type = RKISP1_EXT_PARAMS_BLOCK_TYPE_DPCC;               | | | |
| | | | flags = RKISP1_EXT_PARAMS_FL_BLOCK_ENABLE;              | | | |
| | | | size = sizeof(struct rkisp1_ext_params_dpcc_config);    | | | |
| | | +---------------------------------------------------------+ | | |
| | | +---------- struct rkisp1_cif_isp_dpcc_config ------------+ | | |
| | | | mode = RKISP1_CIF_ISP_DPCC_MODE_STAGE1_ENABLE;          | | | |
| | | | output_mode =                                           | | | |
| | | |   RKISP1_CIF_ISP_DPCC_OUTPUT_MODE_STAGE1_INCL_G_CENTER; | | | |
| | | | set_use = ... ;                                         | | | |
| | | | ...  = ... ;                                            | | | |
| | | +---------------------------------------------------------+ | | |
| | +-------------------------------------------------------------+ | |
| +-----------------------------------------------------------------+ |
+---------------------------------------------------------------------+
```

---

# V4L2_META_FMT_UVC_MSXU_1_5 ('UVCM')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Microsoft(R)'s UVC Payload Metadata.

<a id="rst-v4l2-meta-fmt-uvc-msxu-1-5-uvcm"></a>
<a id="rst-v4l2-meta-fmt-uvc-msxu-1-5"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

Microsoft(R)'s UVC Payload Metadata.

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

## Description

V4L2_META_FMT_UVC_MSXU_1_5 buffers follow the metadata buffer layout of V4L2_META_FMT_UVC with the only difference that it includes all the UVC metadata in the `buffer[]` field, not just the first 2-12 bytes.

The metadata format follows the specification from Microsoft(R) \[1\].

<a id="rst-target-1"></a>

\[1\] [https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/uvc-extensions-1-5](<https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/uvc-extensions-1-5>)

---

# V4L2_META_FMT_UVC ('UVCH')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> UVC Payload Header Data

<a id="rst-v4l2-meta-fmt-uvc-uvch"></a>
<a id="rst-v4l2-meta-fmt-uvc"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

UVC Payload Header Data

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

## Description

This format describes standard UVC metadata, extracted from UVC packet headers and provided by the UVC driver through metadata video nodes. That data includes exact copies of the standard part of UVC Payload Header contents and auxiliary timing information, required for precise interpretation of timestamps, contained in those headers. See section "2.4.3.3 Video and Still Image Payload Headers" of the "UVC 1.5 Class specification" for details.

Each UVC payload header can be between 2 and 12 bytes large. Buffers can contain multiple headers, if multiple such headers have been transmitted by the camera for the respective frame. However, the driver may drop headers when the buffer is full, when they contain no useful information (e.g. those without the SCR field or with that field identical to the previous header), or generally to perform rate limiting when the device sends a large number of headers.

Each individual block contains the following fields:


<table>
<caption>UVC Metadata Block</caption>
<thead>
<tr>
<th>


Field

</th>
<th>


Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


\__u64 ts;

</td>
<td>


system timestamp in host byte order, measured by the driver upon reception of the payload

</td>
</tr>
<tr>
<td>


\__u16 sof;

</td>
<td>


USB Frame Number in host byte order, also obtained by the driver as close as possible to the above timestamp to enable correlation between them

</td>
</tr>
<tr>
<td colspan="2">


 *The rest is an exact copy of the UVC payload header:*

</td>
</tr>
<tr>
<td>


\__u8 length;

</td>
<td>


length of the rest of the block, including this field. Please note that regardless of this value, for V4L2_META_FMT_UVC the kernel will never copy more than 2-12 bytes.

</td>
</tr>
<tr>
<td>


\__u8 flags;

</td>
<td>


Flags, indicating presence of other standard UVC fields

</td>
</tr>
<tr>
<td>


\__u8 buf\[\];

</td>
<td>


The rest of the header, possibly including UVC PTS and SCR fields

</td>
</tr>
</tbody>
</table>

---

# V4L2_META_FMT_VIVID ('VIVD')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIVID Metadata Format

<a id="rst-v4l2-meta-fmt-vivid-vivd"></a>
<a id="rst-v4l2-meta-fmt-vivid"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

VIVID Metadata Format

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

## Description

This describes metadata format used by the vivid driver.

It sets Brightness, Saturation, Contrast and Hue, each of which maps to corresponding controls of the vivid driver with respect to the range and default values.

It contains the following fields:


<table>
<caption>VIVID Metadata</caption>
<thead>
<tr>
<th>


Field

</th>
<th>


Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


u16 brightness;

</td>
<td>


Image brightness, the value is in the range 0 to 255, with the default value as 128.

</td>
</tr>
<tr>
<td>


u16 contrast;

</td>
<td>


Image contrast, the value is in the range 0 to 255, with the default value as 128.

</td>
</tr>
<tr>
<td>


u16 saturation;

</td>
<td>


Image color saturation, the value is in the range 0 to 255, with the default value as 128.

</td>
</tr>
<tr>
<td>


s16 hue;

</td>
<td>


Image color balance, the value is in the range -128 to 128, with the default value as 0.

</td>
</tr>
</tbody>
</table>

---

# V4L2_META_FMT_VSP1_HGO ('VSPH')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Renesas R-Car VSP1 1-D Histogram Data

<a id="rst-v4l2-meta-fmt-vsp1-hgo-vsph"></a>
<a id="rst-v4l2-meta-fmt-vsp1-hgo"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Renesas R-Car VSP1 1-D Histogram Data

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

## Description

This format describes histogram data generated by the Renesas R-Car VSP1 1-D Histogram (HGO) engine.

The VSP1 HGO is a histogram computation engine that can operate on RGB, YCrCb or HSV data. It operates on a possibly cropped and subsampled input image and computes the minimum, maximum and sum of all pixels as well as per-channel histograms.

The HGO can compute histograms independently per channel, on the maximum of the three channels (RGB data only) or on the Y channel only (YCbCr only). It can additionally output the histogram with 64 or 256 bins, resulting in four possible modes of operation.

- In *64 bins normal mode*, the HGO operates on the three channels independently to compute three 64-bins histograms. RGB, YCbCr and HSV image formats are supported.

- In *64 bins maximum mode*, the HGO operates on the maximum of the (R, G, B) channels to compute a single 64-bins histogram. Only the RGB image format is supported.

- In *256 bins normal mode*, the HGO operates on the Y channel to compute a single 256-bins histogram. Only the YCbCr image format is supported.

- In *256 bins maximum mode*, the HGO operates on the maximum of the (R, G, B) channels to compute a single 256-bins histogram. Only the RGB image format is supported.

**Byte Order.** All data is stored in memory in little endian format. Each cell in the tables contains one byte.


<table>
<caption>VSP1 HGO Data - 64 Bins, Normal Mode (792 bytes)</caption>
<thead>
<tr>
<th>


Offset

</th>
<th colspan="5">


 Memory

</th>
</tr>
<tr>
<th>




</th>
<th>


\[31:24\]

</th>
<th>


\[23:16\]

</th>
<th>


\[15:8\]

</th>
<th colspan="2">


\[7:0\]

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0

</td>
<td>




</td>
<td>


R/Cr/H max \[7:0\]

</td>
<td>




</td>
<td colspan="2">


R/Cr/H min \[7:0\]

</td>
</tr>
<tr>
<td>


4

</td>
<td>




</td>
<td>


G/Y/S max \[7:0\]

</td>
<td>




</td>
<td colspan="2">


G/Y/S min \[7:0\]

</td>
</tr>
<tr>
<td>


8

</td>
<td>




</td>
<td>


B/Cb/V max \[7:0\]

</td>
<td>




</td>
<td colspan="2">


B/Cb/V min \[7:0\]

</td>
</tr>
<tr>
<td>


12

</td>
<td colspan="5">


 R/Cr/H sum \[31:0\]

</td>
</tr>
<tr>
<td>


16

</td>
<td colspan="5">


 G/Y/S sum \[31:0\]

</td>
</tr>
<tr>
<td>


20

</td>
<td colspan="5">


 B/Cb/V sum \[31:0\]

</td>
</tr>
<tr>
<td>


24

</td>
<td colspan="5">


 R/Cr/H bin 0 \[31:0\]

</td>
</tr>
<tr>
<td>




</td>
<td colspan="5">


 ...

</td>
</tr>
<tr>
<td>


276

</td>
<td colspan="5">


 R/Cr/H bin 63 \[31:0\]

</td>
</tr>
<tr>
<td>


280

</td>
<td colspan="5">


 G/Y/S bin 0 \[31:0\]

</td>
</tr>
<tr>
<td>




</td>
<td colspan="5">


 ...

</td>
</tr>
<tr>
<td>


532

</td>
<td colspan="5">


 G/Y/S bin 63 \[31:0\]

</td>
</tr>
<tr>
<td>


536

</td>
<td colspan="5">


 B/Cb/V bin 0 \[31:0\]

</td>
</tr>
<tr>
<td>




</td>
<td colspan="5">


 ...

</td>
</tr>
<tr>
<td>


788

</td>
<td colspan="5">


 B/Cb/V bin 63 \[31:0\]

</td>
</tr>
</tbody>
</table>


<table>
<caption>VSP1 HGO Data - 64 Bins, Max Mode (264 bytes)</caption>
<thead>
<tr>
<th>


Offset

</th>
<th colspan="5">


 Memory

</th>
</tr>
<tr>
<th>




</th>
<th>


\[31:24\]

</th>
<th>


\[23:16\]

</th>
<th>


\[15:8\]

</th>
<th colspan="2">


\[7:0\]

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0

</td>
<td>




</td>
<td>


max(R,G,B) max \[7:0\]

</td>
<td>




</td>
<td colspan="2">


max(R,G,B) min \[7:0\]

</td>
</tr>
<tr>
<td>


4

</td>
<td colspan="5">


 max(R,G,B) sum \[31:0\]

</td>
</tr>
<tr>
<td>


8

</td>
<td colspan="5">


 max(R,G,B) bin 0 \[31:0\]

</td>
</tr>
<tr>
<td>




</td>
<td colspan="5">


 ...

</td>
</tr>
<tr>
<td>


260

</td>
<td colspan="5">


 max(R,G,B) bin 63 \[31:0\]

</td>
</tr>
</tbody>
</table>


<table>
<caption>VSP1 HGO Data - 256 Bins, Normal Mode (1032 bytes)</caption>
<thead>
<tr>
<th>


Offset

</th>
<th colspan="5">


 Memory

</th>
</tr>
<tr>
<th>




</th>
<th>


\[31:24\]

</th>
<th>


\[23:16\]

</th>
<th>


\[15:8\]

</th>
<th colspan="2">


\[7:0\]

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0

</td>
<td>




</td>
<td>


Y max \[7:0\]

</td>
<td>




</td>
<td colspan="2">


Y min \[7:0\]

</td>
</tr>
<tr>
<td>


4

</td>
<td colspan="5">


 Y sum \[31:0\]

</td>
</tr>
<tr>
<td>


8

</td>
<td colspan="5">


 Y bin 0 \[31:0\]

</td>
</tr>
<tr>
<td>




</td>
<td colspan="5">


 ...

</td>
</tr>
<tr>
<td>


1028

</td>
<td colspan="5">


 Y bin 255 \[31:0\]

</td>
</tr>
</tbody>
</table>


<table>
<caption>VSP1 HGO Data - 256 Bins, Max Mode (1032 bytes)</caption>
<thead>
<tr>
<th>


Offset

</th>
<th colspan="5">


 Memory

</th>
</tr>
<tr>
<th>




</th>
<th>


\[31:24\]

</th>
<th>


\[23:16\]

</th>
<th>


\[15:8\]

</th>
<th colspan="2">


\[7:0\]

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


0

</td>
<td>




</td>
<td>


max(R,G,B) max \[7:0\]

</td>
<td>




</td>
<td colspan="2">


max(R,G,B) min \[7:0\]

</td>
</tr>
<tr>
<td>


4

</td>
<td colspan="5">


 max(R,G,B) sum \[31:0\]

</td>
</tr>
<tr>
<td>


8

</td>
<td colspan="5">


 max(R,G,B) bin 0 \[31:0\]

</td>
</tr>
<tr>
<td>




</td>
<td colspan="5">


 ...

</td>
</tr>
<tr>
<td>


1028

</td>
<td colspan="5">


 max(R,G,B) bin 255 \[31:0\]

</td>
</tr>
</tbody>
</table>

---

# V4L2_META_FMT_VSP1_HGT ('VSPT')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Renesas R-Car VSP1 2-D Histogram Data

<a id="rst-v4l2-meta-fmt-vsp1-hgt-vspt"></a>
<a id="rst-v4l2-meta-fmt-vsp1-hgt"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Renesas R-Car VSP1 2-D Histogram Data

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

## Description

This format describes histogram data generated by the Renesas R-Car VSP1 2-D Histogram (HGT) engine.

The VSP1 HGT is a histogram computation engine that operates on HSV data. It operates on a possibly cropped and subsampled input image and computes the sum, maximum and minimum of the S component as well as a weighted frequency histogram based on the H and S components.

The histogram is a matrix of 6 Hue and 32 Saturation buckets, 192 in total. Each HSV value is added to one or more buckets with a weight between 1 and 16 depending on the Hue areas configuration. Finding the corresponding buckets is done by inspecting the H and S value independently.

The Saturation position <strong>n</strong> (0 - 31) of the bucket in the matrix is found by the expression:

> n = S / 8

The Hue position <strong>m</strong> (0 - 5) of the bucket in the matrix depends on how the HGT Hue areas are configured. There are 6 user configurable Hue Areas which can be configured to cover overlapping Hue values:

<!-- Source LaTeX layout: \small -->



```text
       Area 0       Area 1       Area 2       Area 3       Area 4       Area 5
      ________     ________     ________     ________     ________     ________
 \   /|      |\   /|      |\   /|      |\   /|      |\   /|      |\   /|      |\   /
  \ / |      | \ / |      | \ / |      | \ / |      | \ / |      | \ / |      | \ /
   X  |      |  X  |      |  X  |      |  X  |      |  X  |      |  X  |      |  X
  / \ |      | / \ |      | / \ |      | / \ |      | / \ |      | / \ |      | / \
 /   \|      |/   \|      |/   \|      |/   \|      |/   \|      |/   \|      |/   \
5U   0L      0U   1L      1U   2L      2U   3L      3U   4L      4U   5L      5U   0L
      <0..............................Hue Value............................255>
```

<!-- Source LaTeX layout: \normalsize -->

When two consecutive areas don't overlap (n+1L is equal to nU) the boundary value is considered as part of the lower area.

Pixels with a hue value included in the centre of an area (between nL and nU included) are attributed to that single area and given a weight of 16. Pixels with a hue value included in the overlapping region between two areas (between n+1L and nU excluded) are attributed to both areas and given a weight for each of these areas proportional to their position along the diagonal lines (rounded down).

The Hue area setup must match one of the following constrains:



```text
0L <= 0U <= 1L <= 1U <= 2L <= 2U <= 3L <= 3U <= 4L <= 4U <= 5L <= 5U
```



```text
0U <= 1L <= 1U <= 2L <= 2U <= 3L <= 3U <= 4L <= 4U <= 5L <= 5U <= 0L
```

<strong>Byte Order.</strong> All data is stored in memory in little endian format. Each cell in the tables contains one byte.


<table>
<caption>

VSP1 HGT Data - (776 bytes)

</caption>
<thead>
<tr>
<th>



Offset

</th>
<th colspan="5">



 Memory

</th>
</tr>
<tr>
<th>





</th>
<th>



\[31:24\]

</th>
<th>



\[23:16\]

</th>
<th>



\[15:8\]

</th>
<th colspan="2">



\[7:0\]

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



0

</td>
<td>



- <!-- empty source list item -->

</td>
<td>



S max \[7:0\]

</td>
<td>



- <!-- empty source list item -->

</td>
<td colspan="2">



S min \[7:0\]

</td>
</tr>
<tr>
<td>



4

</td>
<td colspan="5">



 S sum \[31:0\]

</td>
</tr>
<tr>
<td>



8

</td>
<td colspan="5">



 Histogram bucket (m=0, n=0) \[31:0\]

</td>
</tr>
<tr>
<td>



12

</td>
<td colspan="5">



 Histogram bucket (m=0, n=1) \[31:0\]

</td>
</tr>
<tr>
<td>





</td>
<td colspan="5">



 ...

</td>
</tr>
<tr>
<td>



132

</td>
<td colspan="5">



 Histogram bucket (m=0, n=31) \[31:0\]

</td>
</tr>
<tr>
<td>



136

</td>
<td colspan="5">



 Histogram bucket (m=1, n=0) \[31:0\]

</td>
</tr>
<tr>
<td>





</td>
<td colspan="5">



 ...

</td>
</tr>
<tr>
<td>



264

</td>
<td colspan="5">



 Histogram bucket (m=2, n=0) \[31:0\]

</td>
</tr>
<tr>
<td>





</td>
<td colspan="5">



 ...

</td>
</tr>
<tr>
<td>



392

</td>
<td colspan="5">



 Histogram bucket (m=3, n=0) \[31:0\]

</td>
</tr>
<tr>
<td>





</td>
<td colspan="5">



 ...

</td>
</tr>
<tr>
<td>



520

</td>
<td colspan="5">



 Histogram bucket (m=4, n=0) \[31:0\]

</td>
</tr>
<tr>
<td>





</td>
<td colspan="5">



 ...

</td>
</tr>
<tr>
<td>



648

</td>
<td colspan="5">



 Histogram bucket (m=5, n=0) \[31:0\]

</td>
</tr>
<tr>
<td>





</td>
<td colspan="5">



 ...

</td>
</tr>
<tr>
<td>



772

</td>
<td colspan="5">



 Histogram bucket (m=5, n=31) \[31:0\]

</td>
</tr>
</tbody>
</table>

---

# Streaming I/O (Memory Mapping)

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Input and output devices support this I/O method when the V4L2_CAP_STREAMING flag in the capabilities field of struct v4l2_capability returned by the VIDIOC_QUERYCAP ioctl is set. There are two streaming methods, to determine if the memory…

<a id="rst-streaming-i-o-memory-mapping"></a>
<a id="rst-mmap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Input and output devices support this I/O method when the `V4L2_CAP_STREAMING` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl is set. There are two streaming methods, to determine if the memory mapping flavor is supported applications must call the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl with the memory type set to `V4L2_MEMORY_MMAP`.

Streaming is an I/O method where only pointers to buffers are exchanged between application and driver, the data itself is not copied. Memory mapping is primarily intended to map buffers in device memory into the application's address space. Device memory can be for example the video memory on a graphics card with a video capture add-on. However, being the most efficient I/O method available for a long time, many other drivers support streaming as well, allocating buffers in DMA-able main memory.

A driver can support many sets of buffers. Each set is identified by a unique buffer type value. The sets are independent and each set can hold a different type of data. To access different sets at the same time different file descriptors must be used. <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

To allocate device buffers applications call the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl with the desired number of buffers and buffer type, for example `V4L2_BUF_TYPE_VIDEO_CAPTURE`. This ioctl can also be used to change the number of buffers or to free the allocated memory, provided none of the buffers are still mapped.

Before applications can access the buffers they must map them into their address space with the `mmap()` function. The location of the buffers in device memory can be determined with the [ioctl VIDIOC_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>) ioctl. In the single-planar API case, the `m.offset` and `length` returned in a struct `v4l2_buffer` are passed as sixth and second parameter to the `mmap()` function. When using the multi-planar API, struct `v4l2_buffer` contains an array of struct `v4l2_plane` structures, each containing its own `m.offset` and `length`. When using the multi-planar API, every plane of every buffer has to be mapped separately, so the number of calls to `mmap()` should be equal to number of buffers times number of planes in each buffer. The offset and length values must not be modified. Remember, the buffers are allocated in physical memory, as opposed to virtual memory, which can be swapped out to disk. Applications should free the buffers as soon as possible with the `munmap()` function.

<a id="rst-example-mapping-buffers-in-the-single-planar-api"></a>

## Example: Mapping buffers in the single-planar API



```c
struct v4l2_requestbuffers reqbuf;
struct {
    void *start;
    size_t length;
} *buffers;
unsigned int i;

memset(&reqbuf, 0, sizeof(reqbuf));
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
reqbuf.memory = V4L2_MEMORY_MMAP;
reqbuf.count = 20;

if (-1 == ioctl (fd, VIDIOC_REQBUFS, &reqbuf)) {
    if (errno == EINVAL)
        printf("Video capturing or mmap-streaming is not supported\\n");
    else
        perror("VIDIOC_REQBUFS");

    exit(EXIT_FAILURE);
}

/* We want at least five buffers. */

if (reqbuf.count < 5) {
    /* You may need to free the buffers here. */
    printf("Not enough buffer memory\\n");
    exit(EXIT_FAILURE);
}

buffers = calloc(reqbuf.count, sizeof(*buffers));
assert(buffers != NULL);

for (i = 0; i < reqbuf.count; i++) {
    struct v4l2_buffer buffer;

    memset(&buffer, 0, sizeof(buffer));
    buffer.type = reqbuf.type;
    buffer.memory = V4L2_MEMORY_MMAP;
    buffer.index = i;

    if (-1 == ioctl (fd, VIDIOC_QUERYBUF, &buffer)) {
        perror("VIDIOC_QUERYBUF");
        exit(EXIT_FAILURE);
    }

    buffers[i].length = buffer.length; /* remember for munmap() */

    buffers[i].start = mmap(NULL, buffer.length,
                PROT_READ | PROT_WRITE, /* recommended */
                MAP_SHARED,             /* recommended */
                fd, buffer.m.offset);

    if (MAP_FAILED == buffers[i].start) {
        /* If you do not exit here you should unmap() and free()
           the buffers mapped so far. */
        perror("mmap");
        exit(EXIT_FAILURE);
    }
}

/* Cleanup. */

for (i = 0; i < reqbuf.count; i++)
    munmap(buffers[i].start, buffers[i].length);
```

<a id="rst-example-mapping-buffers-in-the-multi-planar-api"></a>

## Example: Mapping buffers in the multi-planar API



```c
struct v4l2_requestbuffers reqbuf;
/* Our current format uses 3 planes per buffer */
#define FMT_NUM_PLANES = 3

struct {
    void *start[FMT_NUM_PLANES];
    size_t length[FMT_NUM_PLANES];
} *buffers;
unsigned int i, j;

memset(&reqbuf, 0, sizeof(reqbuf));
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
reqbuf.memory = V4L2_MEMORY_MMAP;
reqbuf.count = 20;

if (ioctl(fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
    if (errno == EINVAL)
        printf("Video capturing or mmap-streaming is not supported\\n");
    else
        perror("VIDIOC_REQBUFS");

    exit(EXIT_FAILURE);
}

/* We want at least five buffers. */

if (reqbuf.count < 5) {
    /* You may need to free the buffers here. */
    printf("Not enough buffer memory\\n");
    exit(EXIT_FAILURE);
}

buffers = calloc(reqbuf.count, sizeof(*buffers));
assert(buffers != NULL);

for (i = 0; i < reqbuf.count; i++) {
    struct v4l2_buffer buffer;
    struct v4l2_plane planes[FMT_NUM_PLANES];

    memset(&buffer, 0, sizeof(buffer));
    buffer.type = reqbuf.type;
    buffer.memory = V4L2_MEMORY_MMAP;
    buffer.index = i;
    /* length in struct v4l2_buffer in multi-planar API stores the size
     * of planes array. */
    buffer.length = FMT_NUM_PLANES;
    buffer.m.planes = planes;

    if (ioctl(fd, VIDIOC_QUERYBUF, &buffer) < 0) {
        perror("VIDIOC_QUERYBUF");
        exit(EXIT_FAILURE);
    }

    /* Every plane has to be mapped separately */
    for (j = 0; j < FMT_NUM_PLANES; j++) {
        buffers[i].length[j] = buffer.m.planes[j].length; /* remember for munmap() */

        buffers[i].start[j] = mmap(NULL, buffer.m.planes[j].length,
                 PROT_READ | PROT_WRITE, /* recommended */
                 MAP_SHARED,             /* recommended */
                 fd, buffer.m.planes[j].m.mem_offset);

        if (MAP_FAILED == buffers[i].start[j]) {
            /* If you do not exit here you should unmap() and free()
               the buffers and planes mapped so far. */
            perror("mmap");
            exit(EXIT_FAILURE);
        }
    }
}

/* Cleanup. */

for (i = 0; i < reqbuf.count; i++)
    for (j = 0; j < FMT_NUM_PLANES; j++)
        munmap(buffers[i].start[j], buffers[i].length[j]);
```

Conceptually streaming drivers maintain two buffer queues, an incoming and an outgoing queue. They separate the synchronous capture or output operation locked to a video clock from the application which is subject to random disk or network delays and preemption by other processes, thereby reducing the probability of data loss. The queues are organized as FIFOs, buffers will be output in the order enqueued in the incoming FIFO, and were captured in the order dequeued from the outgoing FIFO.

The driver may require a minimum number of buffers enqueued at all times to function, apart of this no limit exists on the number of buffers applications can enqueue in advance, or dequeue and process. They can also enqueue in a different order than buffers have been dequeued, and the driver can *fill* enqueued *empty* buffers in any order.  <a id="rst-footnote-reference-2"></a>[2](#rst-f2) The index number of a buffer (struct `v4l2_buffer` `index`) plays no role here, it only identifies the buffer.

Initially all mapped buffers are in dequeued state, inaccessible by the driver. For capturing applications it is customary to first enqueue all mapped buffers, then to start capturing and enter the read loop. Here the application waits until a filled buffer can be dequeued, and re-enqueues the buffer when the data is no longer needed. Output applications fill and enqueue buffers, when enough buffers are stacked up the output is started with [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>). In the write loop, when the application runs out of free buffers, it must wait until an empty buffer can be dequeued and reused.

To enqueue and dequeue a buffer applications use the [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) and [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. The status of a buffer being mapped, enqueued, full or empty can be determined at any time using the [ioctl VIDIOC_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>) ioctl. Two methods exist to suspend execution of the application until one or more buffers can be dequeued.  By default [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) blocks when no buffer is in the outgoing queue. When the `O_NONBLOCK` flag was given to the `open()` function, [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) returns immediately with an `EAGAIN` error code when no buffer is available. The `select()` or `poll()` functions are always available.

To start and stop capturing or output applications call the [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) and [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctl.

<!-- note:::ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`
removes all buffers from both queues as a side effect. Since there is
no notion of doing anything "now" on a multitasking system, if an
application needs to synchronize with another event it should examine
the struct ::c:type:`v4l2_buffer` ``timestamp`` of captured
or outputted buffers. -->

Drivers implementing memory mapping I/O must support the [VIDIOC_REQBUFS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), [VIDIOC_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>), [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) and [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctls, the [mmap()](</kernel/userspace/userspace-api/media-v4l/func-mmap.md#rst-func-mmap>), `munmap()`, [select()](</kernel/userspace/userspace-api/media-v4l/func-select.md#rst-func-select>) and `poll()` function. <a id="rst-footnote-reference-3"></a>[3](#rst-f3)

\[capture example\]

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



**[1]** One could use one file descriptor and set the buffer type field accordingly when calling [ioctl VIDIOC_QBUF, VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) etc., but it makes the `select()` function ambiguous. We also like the clean approach of one file descriptor per logical stream. Video overlay for example is also a logical stream, although the CPU is not needed for continuous operation.

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



**[2]** Random enqueue order permits applications processing images out of order (such as video codecs) to return buffers earlier, reducing the probability of data loss. Random fill order allows drivers to reuse buffers on a LIFO-basis, taking advantage of caches holding scatter-gather lists and the like.

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



**[3]** At the driver level `select()` and `poll()` are the same, and `select()` is too important to be optional. The rest should be evident.

---

# Opening and Closing Devices

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Hardware that is supported using the V4L2 uAPI often consists of multiple devices or peripherals, each of which have their own driver.

<a id="rst-opening-and-closing-devices"></a>
<a id="rst-open"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-controlling-a-hardware-peripheral-via-v4l2"></a>
<a id="rst-v4l2-hardware-control"></a>

## Controlling a hardware peripheral via V4L2

Hardware that is supported using the V4L2 uAPI often consists of multiple devices or peripherals, each of which have their own driver.

The bridge driver exposes one or more V4L2 device nodes (see [V4L2 Device Node Naming](<#rst-v4l2-device-naming>)).

There are other drivers providing support for other components of the hardware, which may also expose device nodes, called V4L2 sub-devices.

When such V4L2 sub-devices are exposed, they allow controlling those other hardware components - usually connected via a serial bus (like I²C, SMBus or SPI). Depending on the bridge driver, those sub-devices can be controlled indirectly via the bridge driver or explicitly via the [Media Controller](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>) and via the [V4L2 sub-devices](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-subdev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

The devices that require the use of the [Media Controller](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>) are called **MC-centric** devices. The devices that are fully controlled via V4L2 device nodes are called **video-node-centric**.

Userspace can check if a V4L2 hardware peripheral is MC-centric by calling [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) and checking the [device_caps field](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities>).

If the device returns `V4L2_CAP_IO_MC` flag at `device_caps`, then it is MC-centric, otherwise, it is video-node-centric.

It is required for MC-centric drivers to identify the V4L2 sub-devices and to configure the pipelines via the [media controller API](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>) before using the peripheral. Also, the sub-devices' configuration shall be controlled via the [sub-device API](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-subdev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

> [!NOTE]
>
> > A video-node-centric may still provide media-controller and sub-device interfaces as well.
>
> However, in that case the media-controller and the sub-device interfaces are read-only and just provide information about the device. The actual configuration is done via the video nodes.

<a id="rst-v4l2-device-node-naming"></a>
<a id="rst-v4l2-device-naming"></a>

## V4L2 Device Node Naming

V4L2 drivers are implemented as kernel modules, loaded manually by the system administrator or automatically when a device is first discovered. The driver modules plug into the `videodev` kernel module. It provides helper functions and a common application interface specified in this document.

Each driver thus loaded registers one or more device nodes with major number 81. Minor numbers are allocated dynamically unless the kernel is compiled with the kernel option CONFIG_VIDEO_FIXED_MINOR_RANGES. In that case minor numbers are allocated in ranges depending on the device node type.

The device nodes supported by the Video4Linux subsystem are:


<table>
<thead>
<tr>
<th>


Default device node name

</th>
<th>


Usage

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`/dev/videoX`

</td>
<td>


Video and metadata for capture/output devices

</td>
</tr>
<tr>
<td>


`/dev/vbiX`

</td>
<td>


Vertical blank data (i.e. closed captions, teletext)

</td>
</tr>
<tr>
<td>


`/dev/radioX`

</td>
<td>


Radio tuners and modulators

</td>
</tr>
<tr>
<td>


`/dev/swradioX`

</td>
<td>


Software Defined Radio tuners and modulators

</td>
</tr>
<tr>
<td>


`/dev/v4l-touchX`

</td>
<td>


Touch sensors

</td>
</tr>
<tr>
<td>


`/dev/v4l-subdevX`

</td>
<td>


Video sub-devices (used by sensors and other components of the hardware peripheral)<a id="rst-footnote-reference-1"></a>[1](#rst-footnote-1)

</td>
</tr>
</tbody>
</table>

Where `X` is a non-negative integer.

> [!NOTE]
>
> 1. The actual device node name is system-dependent, as udev rules may apply.
>
> 2. There is no guarantee that `X` will remain the same for the same device, as the number depends on the device driver's probe order. If you need an unique name, udev default rules produce `/dev/v4l/by-id/` and `/dev/v4l/by-path/` directories containing links that can be used uniquely to identify a V4L2 device node:
>
>
>
>    ```text
>    $ tree /dev/v4l
>    /dev/v4l
>    ├── by-id
>    │   └── usb-OmniVision._USB_Camera-B4.04.27.1-video-index0 -> ../../video0
>    └── by-path
>        └── pci-0000:00:14.0-usb-0:2:1.0-video-index0 -> ../../video0
>    ```

<a id="rst-footnote-1"></a>



**[1]** **V4L2 sub-device nodes** (e. g. `/dev/v4l-subdevX`) use a different set of system calls, as covered at [subdev](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-subdev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

Many drivers support "video_nr", "radio_nr" or "vbi_nr" module options to select specific video/radio/vbi node numbers. This allows the user to request that the device node is named e.g. /dev/video5 instead of leaving it to chance. When the driver supports multiple devices of the same type more than one device node number can be assigned, separated by commas:



```none
# modprobe mydriver video_nr=0,1 radio_nr=0,1
```

In `/etc/modules.conf` this may be written as:



```text
options mydriver video_nr=0,1 radio_nr=0,1
```

When no device node number is given as module option the driver supplies a default.

Normally udev will create the device nodes in /dev automatically for you. If udev is not installed, then you need to enable the CONFIG_VIDEO_FIXED_MINOR_RANGES kernel option in order to be able to correctly relate a minor number to a device node number. I.e., you need to be certain that minor number 5 maps to device node name video5. With this kernel option different device types have different minor number ranges. These ranges are listed in [Interfaces](</kernel/userspace/userspace-api/media-v4l/devices.md#rst-devices>).

The creation of character special files (with mknod) is a privileged operation and devices cannot be opened by major and minor number. That means applications cannot *reliably* scan for loaded or installed drivers. The user must enter a device name, or the application can try the conventional device names.

<a id="rst-related-devices"></a>
<a id="rst-related"></a>

## Related Devices

Devices can support several functions. For example video capturing, VBI capturing and radio support.

The V4L2 API creates different V4L2 device nodes for each of these functions.

The V4L2 API was designed with the idea that one device node could support all functions. However, in practice this never worked: this 'feature' was never used by applications and many drivers did not support it and if they did it was certainly never tested. In addition, switching a device node between different functions only works when using the streaming I/O API, not with the `read()`/`write()` API.

Today each V4L2 device node supports just one function.

Besides video input or output the hardware may also support audio sampling or playback. If so, these functions are implemented as ALSA PCM devices with optional ALSA audio mixer devices.

One problem with all these devices is that the V4L2 API makes no provisions to find these related V4L2 device nodes. Some really complex hardware use the Media Controller (see [Part IV - Media Controller API](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>)) which can be used for this purpose. But several drivers do not use it, and while some code exists that uses sysfs to discover related V4L2 device nodes (see libmedia_dev in the [v4l-utils](<http://git.linuxtv.org/cgit.cgi/v4l-utils.git/>) git repository), there is no library yet that can provide a single API towards both Media Controller-based devices and devices that do not use the Media Controller. If you want to work on this please write to the linux-media mailing list: [https://linuxtv.org/lists.php](<https://linuxtv.org/lists.php>).

<a id="rst-multiple-opens"></a>

## Multiple Opens

V4L2 devices can be opened more than once. <a id="rst-footnote-reference-2"></a>[2](#rst-f1) When this is supported by the driver, users can for example start a "panel" application to change controls like brightness or audio volume, while another application captures video and audio. In other words, panel applications are comparable to an ALSA audio mixer application. Just opening a V4L2 device should not change the state of the device. <a id="rst-footnote-reference-3"></a>[3](#rst-f2)

Once an application has allocated the memory buffers needed for streaming data (by calling the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) or [ioctl VIDIOC_CREATE_BUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md#rst-vidioc-create-bufs>) ioctls, or implicitly by calling the `read()` or `write()` functions) that application (filehandle) becomes the owner of the device. It is no longer allowed to make changes that would affect the buffer sizes (e.g. by calling the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl) and other applications are no longer allowed to allocate buffers or start or stop streaming. The EBUSY error code will be returned instead.

Merely opening a V4L2 device does not grant exclusive access. <a id="rst-footnote-reference-4"></a>[4](#rst-f3) Initiating data exchange however assigns the right to read or write the requested type of data, and to change related properties, to this file descriptor. Applications can request additional access privileges using the priority mechanism described in [Application Priority](</kernel/userspace/userspace-api/media-v4l/app-pri.md#rst-app-pri>).

<a id="rst-shared-data-streams"></a>

## Shared Data Streams

V4L2 drivers should not support multiple applications reading or writing the same data stream on a device by copying buffers, time multiplexing or similar means. This is better handled by a proxy application in user space.

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

## Functions

To open and close V4L2 devices applications use the `open()` and `close()` function, respectively. Devices are programmed using the [ioctl()](</kernel/userspace/userspace-api/media-v4l/func-ioctl.md#rst-func-ioctl>) function as explained in the following sections.

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



**[2]** There are still some old and obscure drivers that have not been updated to allow for multiple opens. This implies that for such drivers `open()` can return an `EBUSY` error code when the device is already in use.

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



**[3]** Unfortunately, opening a radio device often switches the state of the device to radio mode in many drivers. This behavior should be fixed eventually as it violates the V4L2 specification.

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



**[4]** Drivers could recognize the `O_EXCL` open flag. Presently this is not required, so applications cannot know if it really works.

---

# Raw Bayer Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The raw Bayer formats are used by image sensors before much if any processing is performed on the image. The formats contain green, red and blue components, with alternating lines of red and green, and blue and green pixels in different…

<a id="rst-raw-bayer-formats"></a>
<a id="rst-pixfmt-bayer"></a>

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

## Description

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The raw Bayer formats are used by image sensors before much if any processing is performed on the image. The formats contain green, red and blue components, with alternating lines of red and green, and blue and green pixels in different orders. See also [the Wikipedia article on Bayer filter](<https://en.wikipedia.org/wiki/Bayer_filter>).

- [V4L2_PIX_FMT_RAW_CRU10 ('CR10'), V4L2_PIX_FMT_RAW_CRU12 ('CR12'), V4L2_PIX_FMT_RAW_CRU14 ('CR14'), V4L2_PIX_FMT_RAW_CRU20 ('CR20')](</kernel/userspace/userspace-api/media-v4l/pixfmt-rawnn-cru.md>)
- [V4L2_PIX_FMT_SRGGB8 ('RGGB'), V4L2_PIX_FMT_SGRBG8 ('GRBG'), V4L2_PIX_FMT_SGBRG8 ('GBRG'), V4L2_PIX_FMT_SBGGR8 ('BA81'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md>)
- [V4L2_PIX_FMT_PISP_COMP1_RGGB ('PC1R'), V4L2_PIX_FMT_PISP_COMP1_GRBG ('PC1G'), V4L2_PIX_FMT_PISP_COMP1_GBRG ('PC1g'), V4L2_PIX_FMT_PISP_COMP1_BGGR ('PC1B), V4L2_PIX_FMT_PISP_COMP1_MONO ('PC1M'), V4L2_PIX_FMT_PISP_COMP2_RGGB ('PC2R'), V4L2_PIX_FMT_PISP_COMP2_GRBG ('PC2G'), V4L2_PIX_FMT_PISP_COMP2_GBRG ('PC2g'), V4L2_PIX_FMT_PISP_COMP2_BGGR ('PC2B), V4L2_PIX_FMT_PISP_COMP2_MONO ('PC2M')](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md>)
- [V4L2_PIX_FMT_SRGGB10 ('RG10'), V4L2_PIX_FMT_SGRBG10 ('BA10'), V4L2_PIX_FMT_SGBRG10 ('GB10'), V4L2_PIX_FMT_SBGGR10 ('BG10'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10.md>)
- [V4L2_PIX_FMT_SRGGB10P ('pRAA'), V4L2_PIX_FMT_SGRBG10P ('pgAA'), V4L2_PIX_FMT_SGBRG10P ('pGAA'), V4L2_PIX_FMT_SBGGR10P ('pBAA'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10p.md>)
- [V4L2_PIX_FMT_SBGGR10ALAW8 ('aBA8'), V4L2_PIX_FMT_SGBRG10ALAW8 ('aGA8'), V4L2_PIX_FMT_SGRBG10ALAW8 ('agA8'), V4L2_PIX_FMT_SRGGB10ALAW8 ('aRA8'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10alaw8.md>)
- [V4L2_PIX_FMT_SBGGR10DPCM8 ('bBA8'), V4L2_PIX_FMT_SGBRG10DPCM8 ('bGA8'), V4L2_PIX_FMT_SGRBG10DPCM8 ('BD10'), V4L2_PIX_FMT_SRGGB10DPCM8 ('bRA8'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10dpcm8.md>)
- [pixfmt-srggb10-ipu3](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-srggb10-ipu3.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [V4L2_PIX_FMT_SRGGB12 ('RG12'), V4L2_PIX_FMT_SGRBG12 ('BA12'), V4L2_PIX_FMT_SGBRG12 ('GB12'), V4L2_PIX_FMT_SBGGR12 ('BG12'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12.md>)
- [V4L2_PIX_FMT_SRGGB12P ('pRCC'), V4L2_PIX_FMT_SGRBG12P ('pgCC'), V4L2_PIX_FMT_SGBRG12P ('pGCC'), V4L2_PIX_FMT_SBGGR12P ('pBCC')](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12p.md>)
- [V4L2_PIX_FMT_SRGGB14 ('RG14'), V4L2_PIX_FMT_SGRBG14 ('GR14'), V4L2_PIX_FMT_SGBRG14 ('GB14'), V4L2_PIX_FMT_SBGGR14 ('BG14'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14.md>)
- [pixfmt-srggb14p](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-srggb14p.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [V4L2_PIX_FMT_SRGGB16 ('RG16'), V4L2_PIX_FMT_SGRBG16 ('GR16'), V4L2_PIX_FMT_SGBRG16 ('GB16'), V4L2_PIX_FMT_SBGGR16 ('BYR2'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb16.md>)

---

# V4L2_PIX_FMT_CNF4 ('CNF4')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Depth sensor confidence information as a 4 bits per pixel packed array

<a id="rst-v4l2-pix-fmt-cnf4-cnf4"></a>
<a id="rst-v4l2-pix-fmt-cnf4"></a>

<!-- -*- coding: utf-8; mode: rst -*- -->

<!-- c:namespace: V4L -->

Depth sensor confidence information as a 4 bits per pixel packed array

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

## Description

Proprietary format used by Intel RealSense Depth cameras containing depth confidence information in range 0-15 with 0 indicating that the sensor was unable to resolve any signal and 15 indicating maximum level of confidence for the specific sensor (actual error margins might change from sensor to sensor).

Every two consecutive pixels are packed into a single byte. Bits 0-3 of byte n refer to confidence value of depth pixel 2\*n, bits 4-7 to confidence value of depth pixel 2\*n+1.

**Bit-packed representation.**


<table>
<tbody>
<tr>
<td>


Y'<sub>01[3:0]</sub>(bits 7--4) Y'<sub>00[3:0]</sub>(bits 3--0)

</td>
<td>


Y'<sub>03[3:0]</sub>(bits 7--4) Y'<sub>02[3:0]</sub>(bits 3--0)

</td>
</tr>
</tbody>
</table>

---

# Compressed Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Compressed Formats.

<a id="rst-compressed-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-compressed-formats-1"></a>



<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{5.8cm}|p{1.2cm}|p{10.3cm}| -->


<table>
<caption>

Compressed Image Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Details

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_JPEG`

</td>
<td>



'JPEG'

</td>
<td>



<a id="rst-v4l2-pix-fmt-jpeg"></a>

TBD. See also [VIDIOC\_G\_JPEGCOMP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-vidioc-g-jpegcomp>), [VIDIOC\_S\_JPEGCOMP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-vidioc-g-jpegcomp>).

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_MPEG`

</td>
<td>



'MPEG'

</td>
<td>



<a id="rst-v4l2-pix-fmt-mpeg"></a>

MPEG multiplexed stream. The actual format is determined by extended control `V4L2_CID_MPEG_STREAM_TYPE`, see [Codec Control IDs](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-mpeg-control-id>).

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_H264`

</td>
<td>



'H264'

</td>
<td>



<a id="rst-v4l2-pix-fmt-h264"></a>

H264 Access Unit. The decoder expects one Access Unit per buffer. The encoder generates one Access Unit per buffer. If [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) reports `V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM` then the decoder has no requirements since it can parse all the information from the raw bytestream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_H264_NO_SC`

</td>
<td>



'AVC1'

</td>
<td>



<a id="rst-v4l2-pix-fmt-h264-no-sc"></a>

H264 video elementary stream without start codes.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_H264_MVC`

</td>
<td>



'M264'

</td>
<td>



<a id="rst-v4l2-pix-fmt-h264-mvc"></a>

H264 MVC video elementary stream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_H264_SLICE`

</td>
<td>



'S264'

</td>
<td>



<a id="rst-v4l2-pix-fmt-h264-slice"></a>

H264 parsed slice data, including slice headers, either with or without the start code, as extracted from the H264 bitstream. This format is adapted for stateless video decoders that implement an H264 pipeline with the [stateless\_decoder](</kernel/userspace/userspace-api/media-v4l/dev-stateless-decoder.md#rst-stateless-decoder>). This pixelformat has two modifiers that must be set at least once through the `V4L2_CID_STATELESS_H264_DECODE_MODE` and `V4L2_CID_STATELESS_H264_START_CODE` controls. In addition, metadata associated with the frame to decode are required to be passed through the `V4L2_CID_STATELESS_H264_SPS`, `V4L2_CID_STATELESS_H264_PPS`, `V4L2_CID_STATELESS_H264_SCALING_MATRIX`, `V4L2_CID_STATELESS_H264_SLICE_PARAMS` and `V4L2_CID_STATELESS_H264_DECODE_PARAMS` controls.  See the [associated Codec Control IDs](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec-stateless.md#rst-v4l2-codec-stateless-h264>). Exactly one output and one capture buffer must be provided for use with this pixel format. The output buffer must contain the appropriate number of macroblocks to decode a full corresponding frame to the matching capture buffer.

The syntax for this format is documented in [h264](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-h264>), section 7.3.2.8 "Slice layer without partitioning RBSP syntax" and the following sections.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_H263`

</td>
<td>



'H263'

</td>
<td>



<a id="rst-v4l2-pix-fmt-h263"></a>

H263 video elementary stream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SPK`

</td>
<td>



'SPK0'

</td>
<td>



<a id="rst-v4l2-pix-fmt-spk"></a>

Sorenson Spark is an implementation of H.263 for use in Flash Video and Adobe Flash files

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_MPEG1`

</td>
<td>



'MPG1'

</td>
<td>



<a id="rst-v4l2-pix-fmt-mpeg1"></a>

MPEG1 Picture. Each buffer starts with a Picture header, followed by other headers as needed and ending with the Picture data. If [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) reports `V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM` then the decoder has no requirements since it can parse all the information from the raw bytestream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_MPEG2`

</td>
<td>



'MPG2'

</td>
<td>



<a id="rst-v4l2-pix-fmt-mpeg2"></a>

MPEG2 Picture. Each buffer starts with a Picture header, followed by other headers as needed and ending with the Picture data. If [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) reports `V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM` then the decoder has no requirements since it can parse all the information from the raw bytestream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_MPEG2_SLICE`

</td>
<td>



'MG2S'

</td>
<td>



<a id="rst-v4l2-pix-fmt-mpeg2-slice"></a>

MPEG-2 parsed slice data, as extracted from the MPEG-2 bitstream. This format is adapted for stateless video decoders that implement a MPEG-2 pipeline with the [stateless\_decoder](</kernel/userspace/userspace-api/media-v4l/dev-stateless-decoder.md#rst-stateless-decoder>). Metadata associated with the frame to decode is required to be passed through the `V4L2_CID_STATELESS_MPEG2_SEQUENCE` and `V4L2_CID_STATELESS_MPEG2_PICTURE` controls. Quantisation matrices can optionally be specified through the `V4L2_CID_STATELESS_MPEG2_QUANTISATION` control. See the [associated Codec Control IDs](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec-stateless.md#rst-v4l2-codec-stateless-mpeg2>). Exactly one output and one capture buffer must be provided for use with this pixel format. The output buffer must contain the appropriate number of macroblocks to decode a full corresponding frame to the matching capture buffer.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_MPEG4`

</td>
<td>



'MPG4'

</td>
<td>



<a id="rst-v4l2-pix-fmt-mpeg4"></a>

MPEG4 video elementary stream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_XVID`

</td>
<td>



'XVID'

</td>
<td>



<a id="rst-v4l2-pix-fmt-xvid"></a>

Xvid video elementary stream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VC1_ANNEX_G`

</td>
<td>



'VC1G'

</td>
<td>



<a id="rst-v4l2-pix-fmt-vc1-annex-g"></a>

VC1, SMPTE 421M Annex G compliant stream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VC1_ANNEX_L`

</td>
<td>



'VC1L'

</td>
<td>



<a id="rst-v4l2-pix-fmt-vc1-annex-l"></a>

VC1, SMPTE 421M Annex L compliant stream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VP8`

</td>
<td>



'VP80'

</td>
<td>



<a id="rst-v4l2-pix-fmt-vp8"></a>

VP8 compressed video frame. The encoder generates one compressed frame per buffer, and the decoder requires one compressed frame per buffer.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VP8_FRAME`

</td>
<td>



'VP8F'

</td>
<td>



<a id="rst-v4l2-pix-fmt-vp8-frame"></a>

VP8 parsed frame, including the frame header, as extracted from the container. This format is adapted for stateless video decoders that implement an VP8 pipeline with the [stateless\_decoder](</kernel/userspace/userspace-api/media-v4l/dev-stateless-decoder.md#rst-stateless-decoder>). Metadata associated with the frame to decode is required to be passed through the `V4L2_CID_STATELESS_VP8_FRAME` control. See the [associated Codec Control IDs](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec-stateless.md#rst-v4l2-codec-stateless-vp8>). Exactly one output and one capture buffer must be provided for use with this pixel format. The output buffer must contain the appropriate number of macroblocks to decode a full corresponding frame to the matching capture buffer.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VP9`

</td>
<td>



'VP90'

</td>
<td>



<a id="rst-v4l2-pix-fmt-vp9"></a>

VP9 compressed video frame. The encoder generates one compressed frame per buffer, and the decoder requires one compressed frame per buffer.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VP9_FRAME`

</td>
<td>



'VP9F'

</td>
<td>



<a id="rst-v4l2-pix-fmt-vp9-frame"></a>

VP9 parsed frame, including the frame header, as extracted from the container. This format is adapted for stateless video decoders that implement a VP9 pipeline with the [stateless\_decoder](</kernel/userspace/userspace-api/media-v4l/dev-stateless-decoder.md#rst-stateless-decoder>). Metadata associated with the frame to decode is required to be passed through the `V4L2_CID_STATELESS_VP9_FRAME` and the `V4L2_CID_STATELESS_VP9_COMPRESSED_HDR` controls. See the [associated Codec Control IDs](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec-stateless.md#rst-v4l2-codec-stateless-vp9>). Exactly one output and one capture buffer must be provided for use with this pixel format. The output buffer must contain the appropriate number of macroblocks to decode a full corresponding frame to the matching capture buffer.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_HEVC`

</td>
<td>



'HEVC'

</td>
<td>



<a id="rst-v4l2-pix-fmt-hevc"></a>

HEVC/H.265 Access Unit. The decoder expects one Access Unit per buffer. The encoder generates one Access Unit per buffer. If [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) reports `V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM` then the decoder has no requirements since it can parse all the information from the raw bytestream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_HEVC_SLICE`

</td>
<td>



'S265'

</td>
<td>



<a id="rst-v4l2-pix-fmt-hevc-slice"></a>

HEVC parsed slice data, as extracted from the HEVC bitstream. This format is adapted for stateless video decoders that implement a HEVC pipeline (using the [mem2mem](</kernel/userspace/userspace-api/media-v4l/dev-mem2mem.md#rst-mem2mem>) and [media-request-api](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>)). This pixelformat has two modifiers that must be set at least once through the `V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE` and `V4L2_CID_MPEG_VIDEO_HEVC_START_CODE` controls. Metadata associated with the frame to decode is required to be passed through the following controls: `V4L2_CID_MPEG_VIDEO_HEVC_SPS`, `V4L2_CID_MPEG_VIDEO_HEVC_PPS`, and `V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS`. See the [associated Codec Control IDs](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec-stateless.md#rst-v4l2-codec-stateless-hevc>). Buffers associated with this pixel format must contain the appropriate number of macroblocks to decode a full corresponding frame.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_FWHT`

</td>
<td>



'FWHT'

</td>
<td>



<a id="rst-v4l2-pix-fmt-fwht"></a>

Video elementary stream using a codec based on the Fast Walsh Hadamard Transform. This codec is implemented by the vicodec ('Virtual Codec') driver. See the codec-fwht.h header for more details. [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) reports `V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM` since the decoder can parse all the information from the raw bytestream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_FWHT_STATELESS`

</td>
<td>



'SFWH'

</td>
<td>



<a id="rst-v4l2-pix-fmt-fwht-stateless"></a>

Same format as V4L2\_PIX\_FMT\_FWHT but requires stateless codec implementation. Metadata associated with the frame to decode is required to be passed through the `V4L2_CID_STATELESS_FWHT_PARAMS` control. See the [associated Codec Control ID](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec-stateless.md#rst-codec-stateless-fwht>).

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_RV30`

</td>
<td>



'RV30'

</td>
<td>



<a id="rst-v4l2-pix-fmt-rv30"></a>

RealVideo, or also spelled as Real Video, is a suite of proprietary video compression formats developed by RealNetworks - the specific format changes with the version. RealVideo codecs are identified by four-character codes. RV30 corresponds to RealVideo 8, suspected to be based largely on an early draft of H.264

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_RV40`

</td>
<td>



'RV40'

</td>
<td>



<a id="rst-v4l2-pix-fmt-rv40"></a>

RV40 represents RealVideo 9 and RealVideo 10. RealVideo 9, suspected to be based on H.264. RealVideo 10, aka RV9 EHQ, This refers to an improved encoder for the RV9 format that is fully backwards compatible with RV9 players - the format and decoder did not change, only the encoder did. As a result, it uses the same FourCC.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_AV1_FRAME`

</td>
<td>



'AV1F'

</td>
<td>



<a id="rst-v4l2-pix-fmt-av1-frame"></a>

AV1 parsed frame, including the frame header, as extracted from the container. This format is adapted for stateless video decoders that implement a AV1 pipeline with the [stateless\_decoder](</kernel/userspace/userspace-api/media-v4l/dev-stateless-decoder.md#rst-stateless-decoder>). Metadata associated with the frame to decode is required to be passed through the `V4L2_CID_STATELESS_AV1_SEQUENCE`, `V4L2_CID_STATELESS_AV1_FRAME`, and `V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY` controls. See the [associated Codec Control IDs](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec-stateless.md#rst-v4l2-codec-stateless-av1>). Exactly one output and one capture buffer must be provided for use with this pixel format. The output buffer must contain the appropriate number of macroblocks to decode a full corresponding frame to the matching capture buffer.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_AV1`

</td>
<td>



'AV01'

</td>
<td>



<a id="rst-v4l2-pix-fmt-av1"></a>

AV1 compressed video frame. This format is adapted for implementing AV1 pipeline. The decoder implements stateful video decoder and expects one temporal unit per buffer in OBU stream format. The encoder generates one Temporal Unit per buffer.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

---

# Indexed Format

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> In this format each pixel is represented by an 8 bit index into a 256 entry ARGB palette. It is intended for Video Output Overlays <osd> only. There are no ioctls to access the palette, this must be done with ioctls of the Linux…

<a id="rst-indexed-format"></a>
<a id="rst-pixfmt-indexed"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

In this format each pixel is represented by an 8 bit index into a 256 entry ARGB palette. It is intended for [Video Output Overlays](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>) only. There are no ioctls to access the palette, this must be done with ioctls of the Linux framebuffer API.


<table>
<caption>Indexed Image Format</caption>
<thead>
<tr>
<th>


Identifier

</th>
<th>


Code

</th>
<th>




</th>
<th colspan="8">


 Byte 0

</th>
</tr>
<tr>
<th>




</th>
<th>




</th>
<th>


Bit

</th>
<th>


7

</th>
<th>


6

</th>
<th>


5

</th>
<th>


4

</th>
<th>


3

</th>
<th>


2

</th>
<th>


1

</th>
<th>


0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`V4L2_PIX_FMT_PAL8`

</td>
<td>


'PAL8'

</td>
<td>




</td>
<td>


i<sub>7</sub>

</td>
<td>


i<sub>6</sub>

</td>
<td>


i<sub>5</sub>

</td>
<td>


i<sub>4</sub>

</td>
<td>


i<sub>3</sub>

</td>
<td>


i<sub>2</sub>

</td>
<td>


i<sub>1</sub>

</td>
<td>


<a id="rst-v4l2-pix-fmt-pal8"></a>

i<sub>0</sub>

</td>
</tr>
</tbody>
</table>

---

# Standard Image Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> In order to exchange images between drivers and applications, it is necessary to have standard image data formats which both sides will interpret the same way. V4L2 includes several such formats, and this section is intended to be an…

<a id="rst-standard-image-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

In order to exchange images between drivers and applications, it is necessary to have standard image data formats which both sides will interpret the same way. V4L2 includes several such formats, and this section is intended to be an unambiguous specification of the standard image data formats in V4L2.

V4L2 drivers are not limited to these formats, however. Driver-specific formats are possible. In that case the application may depend on a codec to convert images to one of the standard formats when needed. But the data can still be stored and retrieved in the proprietary format. For example, a device may support a proprietary compressed format. Applications can still capture and save the data in the compressed format, saving much disk space, and later use a codec to convert the images to the X Windows screen format when the video is to be displayed.

Even so, ultimately, some standard formats are needed, so the V4L2 specification would not be complete without well-defined standard formats.

The V4L2 standard formats are mainly uncompressed formats. The pixels are always arranged in memory from left to right, and from top to bottom. The first byte of data in the image buffer is always for the leftmost pixel of the topmost row. Following that is the pixel immediately to its right, and so on until the end of the top row of pixels. Following the rightmost pixel of the row there may be zero or more bytes of padding to guarantee that each row of pixel data has a certain alignment. Following the pad bytes, if any, is data for the leftmost pixel of the second row from the top, and so on. The last row has just as many pad bytes after it as the other rows.

In V4L2 each format has an identifier which looks like `PIX_FMT_XXX`, defined in the [videodev2.h](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/videodev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) header file. These identifiers represent [four character (FourCC) codes](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-v4l2-fourcc>) which are also listed below, however they are not the same as those used in the Windows world.

For some formats, data is stored in separate, discontiguous memory buffers. Those formats are identified by a separate set of FourCC codes and are referred to as "multi-planar formats". For example, a [YUV422](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-yuv-planar.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) frame is normally stored in one memory buffer, but it can also be placed in two or three separate buffers, with Y component in one buffer and CbCr components in another in the 2-planar version or with each component in its own buffer in the 3-planar case. Those sub-buffers are referred to as "*planes*".

---

# V4L2_PIX_FMT_INZI ('INZI')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Infrared 10-bit linked with Depth 16-bit images

<a id="rst-v4l2-pix-fmt-inzi-inzi"></a>
<a id="rst-v4l2-pix-fmt-inzi"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Infrared 10-bit linked with Depth 16-bit images

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

## Description

Proprietary multi-planar format used by Intel SR300 Depth cameras, comprise of Infrared image followed by Depth data. The pixel definition is 32-bpp, with the Depth and Infrared Data split into separate continuous planes of identical dimensions.

The first plane - Infrared data - is stored according to [V4L2\_PIX\_FMT\_Y10](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y10>) greyscale format. Each pixel is 16-bit cell, with actual data stored in the 10 LSBs with values in range 0 to 1023. The six remaining MSBs are padded with zeros.

The second plane provides 16-bit per-pixel Depth data arranged in [V4L2-PIX-FMT-Z16](</kernel/userspace/userspace-api/media-v4l/pixfmt-z16.md#rst-v4l2-pix-fmt-z16>) format.

<strong>Frame Structure.</strong> Each cell is a 16-bit word with more significant data stored at higher memory address (byte order is little-endian).

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}| -->


<table>
<tbody>
<tr>
<th scope="row">



Ir<sub>0,0</sub>

</th>
<td>



Ir<sub>0,1</sub>

</td>
<td>



Ir<sub>0,2</sub>

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
</tr>
<tr>
<th colspan="6" scope="row">



 ...

</th>
</tr>
<tr>
<th colspan="6" scope="row">



 Infrared Data

</th>
</tr>
<tr>
<th colspan="6" scope="row">



 ...

</th>
</tr>
<tr>
<th scope="row">



...

</th>
<td>



...

</td>
<td>



...

</td>
<td>



Ir<sub>n-1,n-3</sub>

</td>
<td>



Ir<sub>n-1,n-2</sub>

</td>
<td>



Ir<sub>n-1,n-1</sub>

</td>
</tr>
<tr>
<th scope="row">



Depth<sub>0,0</sub>

</th>
<td>



Depth<sub>0,1</sub>

</td>
<td>



Depth<sub>0,2</sub>

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
</tr>
<tr>
<th colspan="6" scope="row">



 ...

</th>
</tr>
<tr>
<th colspan="6" scope="row">



 Depth Data

</th>
</tr>
<tr>
<th colspan="6" scope="row">



 ...

</th>
</tr>
<tr>
<th scope="row">



...

</th>
<td>



...

</td>
<td>



...

</td>
<td>



Depth<sub>n-1,n-3</sub>

</td>
<td>



Depth<sub>n-1,n-2</sub>

</td>
<td>



Depth<sub>n-1,n-1</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

---

# V4L2_PIX_FMT_M420 ('M420')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Format with ½ horizontal and vertical chroma resolution, also known as YUV 4:2:0. Hybrid plane line-interleaved layout.

<a id="rst-v4l2-pix-fmt-m420-m420"></a>
<a id="rst-v4l2-pix-fmt-m420"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Format with ½ horizontal and vertical chroma resolution, also known as YUV 4:2:0. Hybrid plane line-interleaved layout.

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

## Description

M420 is a YUV format with ½ horizontal and vertical chroma subsampling (YUV 4:2:0). Pixels are organized as interleaved luma and chroma planes. Two lines of luma data are followed by one line of chroma data.

The luma plane has one byte per pixel. The chroma plane contains interleaved CbCr pixels subsampled by ½ in the horizontal and vertical directions. Each CbCr pair belongs to four pixels. For example, Cb<sub>0</sub>/Cr<sub>0</sub> belongs to Y'<sub>00</sub>, Y'<sub>01</sub>, Y'<sub>10</sub>, Y'<sub>11</sub>.

All line lengths are identical: if the Y lines include pad bytes so do the CbCr lines.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


Y'<sub>00</sub>

</td>
<td>


Y'<sub>01</sub>

</td>
<td>


Y'<sub>02</sub>

</td>
<td>


Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>


start + 4:

</td>
<td>


Y'<sub>10</sub>

</td>
<td>


Y'<sub>11</sub>

</td>
<td>


Y'<sub>12</sub>

</td>
<td>


Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


Cb<sub>00</sub>

</td>
<td>


Cr<sub>00</sub>

</td>
<td>


Cb<sub>01</sub>

</td>
<td>


Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


Y'<sub>20</sub>

</td>
<td>


Y'<sub>21</sub>

</td>
<td>


Y'<sub>22</sub>

</td>
<td>


Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>


start + 20:

</td>
<td>


Y'<sub>30</sub>

</td>
<td>


Y'<sub>31</sub>

</td>
<td>


Y'<sub>32</sub>

</td>
<td>


Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


Cb<sub>10</sub>

</td>
<td>


Cr<sub>10</sub>

</td>
<td>


Cb<sub>11</sub>

</td>
<td>


Cr<sub>11</sub>

</td>
</tr>
</tbody>
</table>

**Color Sample Location:** Chroma samples are [interstitially sited](</kernel/userspace/userspace-api/media-v4l/yuv-formats.md#rst-yuv-chroma-centered>) horizontally and vertically.

---

# Packed HSV formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The hue (h) is measured in degrees, the equivalence between degrees and LSBs depends on the hsv-encoding used, see colorspaces. The saturation (s) and the value (v) are measured in percentage of the cylinder: 0 being the smallest value and…

<a id="rst-packed-hsv-formats"></a>
<a id="rst-packed-hsv"></a>

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

## Description

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The <em>hue</em> (h) is measured in degrees, the equivalence between degrees and LSBs depends on the hsv-encoding used, see [colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). The <em>saturation</em> (s) and the <em>value</em> (v) are measured in percentage of the cylinder: 0 being the smallest value and 255 the maximum.

The values are packed in 24 or 32 bit formats.

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{2.6cm}|p{0.8cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-packed-hsv-formats-1"></a>


<table>
<caption>

Packed HSV Image Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="8">



 Byte 0 in memory

</th>
<th colspan="8">



 Byte 1

</th>
<th colspan="8">



 Byte 2

</th>
<th colspan="8">



 Byte 3

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_HSV32`

</td>
<td>



'HSV4'

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



h<sub>7</sub>

</td>
<td>



h<sub>6</sub>

</td>
<td>



h<sub>5</sub>

</td>
<td>



h<sub>4</sub>

</td>
<td>



h<sub>3</sub>

</td>
<td>



h<sub>2</sub>

</td>
<td>



h<sub>1</sub>

</td>
<td>



h<sub>0</sub>

</td>
<td>



s<sub>7</sub>

</td>
<td>



s<sub>6</sub>

</td>
<td>



s<sub>5</sub>

</td>
<td>



s<sub>4</sub>

</td>
<td>



s<sub>3</sub>

</td>
<td>



s<sub>2</sub>

</td>
<td>



s<sub>1</sub>

</td>
<td>



s<sub>0</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-hsv32"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>



<a id="rst-v4l2-pix-fmt-hsv24"></a>



`V4L2_PIX_FMT_HSV24`

</td>
<td>



'HSV3'

</td>
<td>





</td>
<td>



h<sub>7</sub>

</td>
<td>



h<sub>6</sub>

</td>
<td>



h<sub>5</sub>

</td>
<td>



h<sub>4</sub>

</td>
<td>



h<sub>3</sub>

</td>
<td>



h<sub>2</sub>

</td>
<td>



h<sub>1</sub>

</td>
<td>



h<sub>0</sub>

</td>
<td>



s<sub>7</sub>

</td>
<td>



s<sub>6</sub>

</td>
<td>



s<sub>5</sub>

</td>
<td>



s<sub>4</sub>

</td>
<td>



s<sub>3</sub>

</td>
<td>



s<sub>2</sub>

</td>
<td>



s<sub>1</sub>

</td>
<td>



s<sub>0</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td colspan="8">





</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

Bit 7 is the most significant bit.

---

# Packed YUV formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Similarly to the packed RGB formats, the packed YUV formats store the Y, Cb and Cr components consecutively in memory. They may apply subsampling to the chroma components and thus differ in how they interlave the three components.

<a id="rst-packed-yuv-formats"></a>
<a id="rst-packed-yuv"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Similarly to the packed RGB formats, the packed YUV formats store the Y, Cb and Cr components consecutively in memory. They may apply subsampling to the chroma components and thus differ in how they interlave the three components.

> [!NOTE]
>
> - In all the tables that follow, bit 7 is the most significant bit in a byte.
>
> - 'Y', 'Cb' and 'Cr' denote bits of the luma, blue chroma (also known as 'U') and red chroma (also known as 'V') components respectively. 'A' denotes bits of the alpha component (if supported by the format), and 'X' denotes padding bits.

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

## 4:4:4 Subsampling

These formats do not subsample the chroma components and store each pixels as a full triplet of Y, Cb and Cr values.

The next table lists the packed YUV 4:4:4 formats with less than 8 bits per component. They are named based on the order of the Y, Cb and Cr components as seen in a 16-bit word, which is then stored in memory in little endian byte order, and on the number of bits for each component. For instance the YUV565 format stores a pixel in a 16-bit word \[15:0\] laid out at as \[Y'<sub>4-0</sub> Cb<sub>5-0</sub> Cr<sub>4-0</sub>\], and stored in memory in two bytes, \[Cb<sub>2-0</sub> Cr<sub>4-0</sub>\] followed by \[Y'<sub>4-0</sub> Cb<sub>5-3</sub>\].

<!-- Source LaTeX layout: \begingroup
\scriptsize
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{3.5cm}|p{0.96cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}| -->


<table>
<caption>

Packed YUV 4:4:4 Image Formats (less than 8bpc)

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th colspan="8">



 Byte 0 in memory

</th>
<th colspan="8">



 Byte 1

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_YUV444`

</td>
<td>



'Y444'

</td>
<td>



Cb<sub>3</sub>

</td>
<td>



Cb<sub>2</sub>

</td>
<td>



Cb<sub>1</sub>

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Cr<sub>3</sub>

</td>
<td>



Cr<sub>2</sub>

</td>
<td>



Cr<sub>1</sub>

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



Y'<sub>3</sub>

</td>
<td>



Y'<sub>2</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuv444"></a>

Y'<sub>0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_YUV555`

</td>
<td>



'YUVO'

</td>
<td>



Cb<sub>2</sub>

</td>
<td>



Cb<sub>1</sub>

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Cr<sub>4</sub>

</td>
<td>



Cr<sub>3</sub>

</td>
<td>



Cr<sub>2</sub>

</td>
<td>



Cr<sub>1</sub>

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



a

</td>
<td>



Y'<sub>4</sub>

</td>
<td>



Y'<sub>3</sub>

</td>
<td>



Y'<sub>2</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



Y'<sub>0</sub>

</td>
<td>



Cb<sub>4</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuv555"></a>

Cb<sub>3</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_YUV565`

</td>
<td>



'YUVP'

</td>
<td>



Cb<sub>2</sub>

</td>
<td>



Cb<sub>1</sub>

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Cr<sub>4</sub>

</td>
<td>



Cr<sub>3</sub>

</td>
<td>



Cr<sub>2</sub>

</td>
<td>



Cr<sub>1</sub>

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



Y'<sub>4</sub>

</td>
<td>



Y'<sub>3</sub>

</td>
<td>



Y'<sub>2</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



Y'<sub>0</sub>

</td>
<td>



Cb<sub>5</sub>

</td>
<td>



Cb<sub>4</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuv565"></a>

Cb<sub>3</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

> [!NOTE]
>
> For the YUV444 and YUV555 formats, the value of alpha bits is undefined when reading from the driver, ignored when writing to the driver, except when alpha blending has been negotiated for a [Video Overlay](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) or [Video Output Overlay](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>).

The next table lists the packed YUV 4:4:4 formats with 8 bits per component. They are named based on the order of the Y, Cb and Cr components as stored in memory, and on the total number of bits per pixel. For instance, the VUYX32 format stores a pixel with Cr<sub>7-0</sub> in the first byte, Cb<sub>7-0</sub> in the second byte and Y'<sub>7-0</sub> in the third byte.


<table>
<caption>

Packed YUV Image Formats (8bpc)

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Byte 0

</th>
<th>



Byte 1

</th>
<th>



Byte 2

</th>
<th>



Byte 3

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_YUV32`

</td>
<td>



'YUV4'

</td>
<td>



A<sub>7-0</sub>

</td>
<td>



Y'<sub>7-0</sub>

</td>
<td>



Cb<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuv32"></a>

Cr<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_AYUV32`

</td>
<td>



'AYUV'

</td>
<td>



A<sub>7-0</sub>

</td>
<td>



Y'<sub>7-0</sub>

</td>
<td>



Cb<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-ayuv32"></a>

Cr<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_XYUV32`

</td>
<td>



'XYUV'

</td>
<td>



X<sub>7-0</sub>

</td>
<td>



Y'<sub>7-0</sub>

</td>
<td>



Cb<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-xyuv32"></a>

Cr<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VUYA32`

</td>
<td>



'VUYA'

</td>
<td>



Cr<sub>7-0</sub>

</td>
<td>



Cb<sub>7-0</sub>

</td>
<td>



Y'<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-vuya32"></a>

A<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VUYX32`

</td>
<td>



'VUYX'

</td>
<td>



Cr<sub>7-0</sub>

</td>
<td>



Cb<sub>7-0</sub>

</td>
<td>



Y'<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-vuyx32"></a>

X<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_YUVA32`

</td>
<td>



'YUVA'

</td>
<td>



Y'<sub>7-0</sub>

</td>
<td>



Cb<sub>7-0</sub>

</td>
<td>



Cr<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuva32"></a>

A<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_YUVX32`

</td>
<td>



'YUVX'

</td>
<td>



Y'<sub>7-0</sub>

</td>
<td>



Cb<sub>7-0</sub>

</td>
<td>



Cr<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuvx32"></a>

X<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_YUV24`

</td>
<td>



'YUV3'

</td>
<td>



Y'<sub>7-0</sub>

</td>
<td>



Cb<sub>7-0</sub>

</td>
<td>



Cr<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuv24"></a>

\-

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> - The alpha component is expected to contain a meaningful value that can be used by drivers and applications.
>
> - The padding bits contain undefined values that must be ignored by all applications and drivers.

The next table lists the packed YUV 4:4:4 formats with 12 bits per component. Expand the bits per component to 16 bits, data in the high bits, zeros in the low bits, arranged in little endian order, storing 1 pixel in 6 bytes.


<table>
<caption>

Packed YUV 4:4:4 Image Formats (12bpc)

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Byte 1-0

</th>
<th>



Byte 3-2

</th>
<th>



Byte 5-4

</th>
<th>



Byte 7-6

</th>
<th>



Byte 9-8

</th>
<th>



Byte 11-10

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_YUV48_12`

</td>
<td>



'Y312'

</td>
<td>



Y'<sub>0</sub>

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



Cb<sub>1</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuv48-12"></a>

Cr<sub>1</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-subsampling-1"></a>

## 4:2:2 Subsampling

These formats, commonly referred to as YUYV or YUY2, subsample the chroma components horizontally by 2, storing 2 pixels in a container. The container is 32-bits for 8-bit formats, and 64-bits for 10+-bit formats.

The packed YUYV formats with more than 8 bits per component are stored as four 16-bit little-endian words. Each word's most significant bits contain one component, and the least significant bits are zero padding.

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{3.4cm}|p{1.2cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}| -->


<table>
<caption>

Packed YUV 4:2:2 Formats in 32-bit container

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Byte 0

</th>
<th>



Byte 1

</th>
<th>



Byte 2

</th>
<th>



Byte 3

</th>
<th>



Byte 4

</th>
<th>



Byte 5

</th>
<th>



Byte 6

</th>
<th>



Byte 7

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_UYVY`

</td>
<td>



'UYVY'

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Y'<sub>0</sub>

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



Cb<sub>2</sub>

</td>
<td>



Y'<sub>2</sub>

</td>
<td>



Cr<sub>2</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-uyvy"></a>

Y'<sub>3</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_VYUY`

</td>
<td>



'VYUY'

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



Y'<sub>0</sub>

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



Cr<sub>2</sub>

</td>
<td>



Y'<sub>2</sub>

</td>
<td>



Cb<sub>2</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-vyuy"></a>

Y'<sub>3</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_YUYV`

</td>
<td>



'YUYV'

</td>
<td>



Y'<sub>0</sub>

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



Y'<sub>2</sub>

</td>
<td>



Cb<sub>2</sub>

</td>
<td>



Y'<sub>3</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yuyv"></a>

Cr<sub>2</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_YVYU`

</td>
<td>



'YVYU'

</td>
<td>



Y'<sub>0</sub>

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Y'<sub>2</sub>

</td>
<td>



Cr<sub>2</sub>

</td>
<td>



Y'<sub>3</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-yvyu"></a>

Cb<sub>2</sub>

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{3.4cm}|p{1.2cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}| -->


<table>
<caption>

Packed YUV 4:2:2 Formats in 64-bit container

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Word 0

</th>
<th>



Word 1

</th>
<th>



Word 2

</th>
<th>



Word 3

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_Y210`

</td>
<td>



'Y210'

</td>
<td>



Y'<sub>0</sub> (bits 15-6)

</td>
<td>



Cb<sub>0</sub> (bits 15-6)

</td>
<td>



Y'<sub>1</sub> (bits 15-6)

</td>
<td>



<a id="rst-v4l2-pix-fmt-y210"></a>

Cr<sub>0</sub> (bits 15-6)

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y212`

</td>
<td>



'Y212'

</td>
<td>



Y'<sub>0</sub> (bits 15-4)

</td>
<td>



Cb<sub>0</sub> (bits 15-4)

</td>
<td>



Y'<sub>1</sub> (bits 15-4)

</td>
<td>



<a id="rst-v4l2-pix-fmt-y212"></a>

Cr<sub>0</sub> (bits 15-4)

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y216`

</td>
<td>



'Y216'

</td>
<td>



Y'<sub>0</sub> (bits 15-0)

</td>
<td>



Cb<sub>0</sub> (bits 15-0)

</td>
<td>



Y'<sub>1</sub> (bits 15-0)

</td>
<td>



<a id="rst-v4l2-pix-fmt-y216"></a>

Cr<sub>0</sub> (bits 15-0)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<strong>Color Sample Location:</strong> Chroma samples are [interstitially sited](</kernel/userspace/userspace-api/media-v4l/yuv-formats.md#rst-yuv-chroma-centered>) horizontally.

<a id="rst-subsampling-2"></a>

## 4:1:1 Subsampling

This format subsamples the chroma components horizontally by 4, storing 8 pixels in 12 bytes.

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{2.9cm}|p{0.8cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}| -->


<table>
<caption>

Packed YUV 4:1:1 Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Byte 0

</th>
<th>



Byte 1

</th>
<th>



Byte 2

</th>
<th>



Byte 3

</th>
<th>



Byte 4

</th>
<th>



Byte 5

</th>
<th>



Byte 6

</th>
<th>



Byte 7

</th>
<th>



Byte 8

</th>
<th>



Byte 9

</th>
<th>



Byte 10

</th>
<th>



Byte 11

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_Y41P`

</td>
<td>



'Y41P'

</td>
<td>



Cb<sub>0</sub>

</td>
<td>



Y'<sub>0</sub>

</td>
<td>



Cr<sub>0</sub>

</td>
<td>



Y'<sub>1</sub>

</td>
<td>



Cb<sub>4</sub>

</td>
<td>



Y'<sub>2</sub>

</td>
<td>



Cr<sub>4</sub>

</td>
<td>



Y'<sub>3</sub>

</td>
<td>



Y'<sub>4</sub>

</td>
<td>



Y'<sub>5</sub>

</td>
<td>



Y'<sub>6</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-y41p"></a>

Y'<sub>7</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

> [!NOTE]
>
> Do not confuse `V4L2_PIX_FMT_Y41P` with [V4L2\_PIX\_FMT\_YUV411P](</kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv411p>). Y41P is derived from "YUV 4:1:1 <strong>packed</strong>", while YUV411P stands for "YUV 4:1:1 <strong>planar</strong>".

<strong>Color Sample Location:</strong> Chroma samples are [interstitially sited](</kernel/userspace/userspace-api/media-v4l/yuv-formats.md#rst-yuv-chroma-centered>) horizontally.

---

# V4L2_PIX_FMT_RAW_CRU10 ('CR10'), V4L2_PIX_FMT_RAW_CRU12 ('CR12'), V4L2_PIX_FMT_RAW_CRU14 ('CR14'), V4L2_PIX_FMT_RAW_CRU20 ('CR20')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These pixel formats are some of the RAW outputs for the Camera Receiver Unit in the Renesas RZ/V2H SoC. They are raw formats which pack pixels contiguously into 64-bit units, with the 4 or 8 most significant bits padded.

<a id="rst-v4l2-pix-fmt-raw-cru10-cr10-v4l2-pix-fmt-raw-cru12-cr12-v4l2-pix-fmt-raw-cru14-cr14-v4l2-pix-fmt-raw-cru20-cr20"></a>
<a id="rst-v4l2-pix-fmt-raw-cru20"></a>
<a id="rst-v4l2-pix-fmt-raw-cru14"></a>
<a id="rst-v4l2-pix-fmt-raw-cru12"></a>
<a id="rst-v4l2-pix-fmt-raw-cru10"></a>

<a id="rst-renesas-rz-v2h-camera-receiver-unit-64-bit-packed-pixel-formats"></a>

## Renesas RZ/V2H Camera Receiver Unit 64-bit packed pixel formats

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

V4L2_PIX_FMT_RAW_CRU10 (CR10)  
V4L2_PIX_FMT_RAW_CRU12 (CR12)  
V4L2_PIX_FMT_RAW_CRU14 (CR14)  
V4L2_PIX_FMT_RAW_CRU20 (CR20)

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

## Description

These pixel formats are some of the RAW outputs for the Camera Receiver Unit in the Renesas RZ/V2H SoC. They are raw formats which pack pixels contiguously into 64-bit units, with the 4 or 8 most significant bits padded.

**Byte Order**


<table>
<caption>RAW formats</caption>
<thead>
<tr>
<th rowspan="2">


 Pixel Format Code

</th>
<th colspan="64">


 Data organization

</th>
</tr>
<tr>
<th>


63

</th>
<th>


62

</th>
<th>


61

</th>
<th>


60

</th>
<th>


59

</th>
<th>


58

</th>
<th>


57

</th>
<th>


56

</th>
<th>


55

</th>
<th>


54

</th>
<th>


53

</th>
<th>


52

</th>
<th>


51

</th>
<th>


50

</th>
<th>


49

</th>
<th>


48

</th>
<th>


47

</th>
<th>


46

</th>
<th>


45

</th>
<th>


44

</th>
<th>


43

</th>
<th>


42

</th>
<th>


41

</th>
<th>


40

</th>
<th>


39

</th>
<th>


38

</th>
<th>


37

</th>
<th>


36

</th>
<th>


35

</th>
<th>


34

</th>
<th>


33

</th>
<th>


32

</th>
<th>


31

</th>
<th>


30

</th>
<th>


29

</th>
<th>


28

</th>
<th>


27

</th>
<th>


26

</th>
<th>


25

</th>
<th>


24

</th>
<th>


23

</th>
<th>


22

</th>
<th>


21

</th>
<th>


20

</th>
<th>


19

</th>
<th>


18

</th>
<th>


17

</th>
<th>


16

</th>
<th>


15

</th>
<th>


14

</th>
<th>


13

</th>
<th>


12

</th>
<th>


11

</th>
<th>


10

</th>
<th>


9

</th>
<th>


8

</th>
<th>


7

</th>
<th>


6

</th>
<th>


5

</th>
<th>


4

</th>
<th>


3

</th>
<th>


2

</th>
<th>


1

</th>
<th>


0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


V4L2_PIX_FMT_RAW_CRU10

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td colspan="10">


 P5

</td>
<td colspan="10">


 P4

</td>
<td colspan="10">


 P3

</td>
<td colspan="10">


 P2

</td>
<td colspan="10">


 P1

</td>
<td colspan="10">


 P0

</td>
</tr>
<tr>
<td>


V4L2_PIX_FMT_RAW_CRU12

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td colspan="12">


 P4

</td>
<td colspan="12">


 P3

</td>
<td colspan="12">


 P2

</td>
<td colspan="12">


 P1

</td>
<td colspan="12">


 P0

</td>
</tr>
<tr>
<td>


V4L2_PIX_FMT_RAW_CRU14

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td colspan="14">


 P3

</td>
<td colspan="14">


 P2

</td>
<td colspan="14">


 P1

</td>
<td colspan="14">


 P0

</td>
</tr>
<tr>
<td>


V4L2_PIX_FMT_RAW_CRU20

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td>


0

</td>
<td colspan="20">


 P2

</td>
<td colspan="20">


 P1

</td>
<td colspan="20">


 P0

</td>
</tr>
</tbody>
</table>

---

# Reserved Format Identifiers

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These formats are not defined by this specification, they are just listed for reference and to avoid naming conflicts. If you want to register your own format, send an e-mail to the linux-media mailing list https://linuxtv.org/lists.php…

<a id="rst-reserved-format-identifiers"></a>
<a id="rst-pixfmt-reserved"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

These formats are not defined by this specification, they are just listed for reference and to avoid naming conflicts. If you want to register your own format, send an e-mail to the linux-media mailing list [https://linuxtv.org/lists.php](<https://linuxtv.org/lists.php>) for inclusion in the `videodev2.h` file. If you want to share your format with other developers add a link to your documentation and send a copy to the linux-media mailing list for inclusion in this section. If you think your format should be listed in a standard format section please make a proposal on the linux-media mailing list.

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<!-- Source LaTeX layout: \small -->

<a id="rst-reserved-formats"></a>


<table>
<caption>

Reserved Image Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Details

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_DV`

</td>
<td>



'dvsd'

</td>
<td>



<a id="rst-v4l2-pix-fmt-dv"></a>

unknown

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_ET61X251`

</td>
<td>



'E625'

</td>
<td>



<a id="rst-v4l2-pix-fmt-et61x251"></a>

Compressed format of the ET61X251 driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_HI240`

</td>
<td>



'HI24'

</td>
<td>



<a id="rst-v4l2-pix-fmt-hi240"></a>

8 bit RGB format used by the BTTV driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_CPIA1`

</td>
<td>



'CPIA'

</td>
<td>



<a id="rst-v4l2-pix-fmt-cpia1"></a>

YUV format used by the gspca cpia1 driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_JPGL`

</td>
<td>



'JPGL'

</td>
<td>



<a id="rst-v4l2-pix-fmt-jpgl"></a>

JPEG-Light format (Pegasus Lossless JPEG) used in Divio webcams NW 80x.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SPCA501`

</td>
<td>



'S501'

</td>
<td>



<a id="rst-v4l2-pix-fmt-spca501"></a>

YUYV per line used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SPCA505`

</td>
<td>



'S505'

</td>
<td>



<a id="rst-v4l2-pix-fmt-spca505"></a>

YYUV per line used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SPCA508`

</td>
<td>



'S508'

</td>
<td>



<a id="rst-v4l2-pix-fmt-spca508"></a>

YUVY per line used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SPCA561`

</td>
<td>



'S561'

</td>
<td>



<a id="rst-v4l2-pix-fmt-spca561"></a>

Compressed GBRG Bayer format used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_PAC207`

</td>
<td>



'P207'

</td>
<td>



<a id="rst-v4l2-pix-fmt-pac207"></a>

Compressed BGGR Bayer format used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_MR97310A`

</td>
<td>



'M310'

</td>
<td>



<a id="rst-v4l2-pix-fmt-mr97310a"></a>

Compressed BGGR Bayer format used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_JL2005BCD`

</td>
<td>



'JL20'

</td>
<td>



<a id="rst-v4l2-pix-fmt-jl2005bcd"></a>

JPEG compressed RGGB Bayer format used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_OV511`

</td>
<td>



'O511'

</td>
<td>



<a id="rst-v4l2-pix-fmt-ov511"></a>

OV511 JPEG format used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_OV518`

</td>
<td>



'O518'

</td>
<td>



<a id="rst-v4l2-pix-fmt-ov518"></a>

OV518 JPEG format used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_PJPG`

</td>
<td>



'PJPG'

</td>
<td>



<a id="rst-v4l2-pix-fmt-pjpg"></a>

Pixart 73xx JPEG format used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SE401`

</td>
<td>



'S401'

</td>
<td>



<a id="rst-v4l2-pix-fmt-se401"></a>

Compressed RGB format used by the gspca se401 driver

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SQ905C`

</td>
<td>



'905C'

</td>
<td>



<a id="rst-v4l2-pix-fmt-sq905c"></a>

Compressed RGGB bayer format used by the gspca driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_MJPEG`

</td>
<td>



'MJPG'

</td>
<td>



<a id="rst-v4l2-pix-fmt-mjpeg"></a>

Compressed format used by the Zoran driver

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_PWC1`

</td>
<td>



'PWC1'

</td>
<td>



<a id="rst-v4l2-pix-fmt-pwc1"></a>

Compressed format of the PWC driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_PWC2`

</td>
<td>



'PWC2'

</td>
<td>



<a id="rst-v4l2-pix-fmt-pwc2"></a>

Compressed format of the PWC driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SN9C10X`

</td>
<td>



'S910'

</td>
<td>



<a id="rst-v4l2-pix-fmt-sn9c10x"></a>

Compressed format of the SN9C102 driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SN9C20X_I420`

</td>
<td>



'S920'

</td>
<td>



<a id="rst-v4l2-pix-fmt-sn9c20x-i420"></a>

YUV 4:2:0 format of the gspca sn9c20x driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_SN9C2028`

</td>
<td>



'SONX'

</td>
<td>



<a id="rst-v4l2-pix-fmt-sn9c2028"></a>

Compressed GBRG bayer format of the gspca sn9c2028 driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_STV0680`

</td>
<td>



'S680'

</td>
<td>



<a id="rst-v4l2-pix-fmt-stv0680"></a>

Bayer format of the gspca stv0680 driver.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_WNVA`

</td>
<td>



'WNVA'

</td>
<td>



<a id="rst-v4l2-pix-fmt-wnva"></a>

Used by the Winnov Videum driver, [http://www.thedirks.org/winnov/](<http://www.thedirks.org/winnov/>)

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_TM6000`

</td>
<td>



'TM60'

</td>
<td>



<a id="rst-v4l2-pix-fmt-tm6000"></a>

Used by Trident tm6000

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_CIT_YYVYUY`

</td>
<td>



'CITV'

</td>
<td>



<a id="rst-v4l2-pix-fmt-cit-yyvyuy"></a>

Used by xirlink CIT, found at IBM webcams.

Uses one line of Y then 1 line of VYUY

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_KONICA420`

</td>
<td>



'KONI'

</td>
<td>



<a id="rst-v4l2-pix-fmt-konica420"></a>

Used by Konica webcams.

YUV420 planar in blocks of 256 pixels.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_YYUV`

</td>
<td>



'YYUV'

</td>
<td>



<a id="rst-v4l2-pix-fmt-yyuv"></a>

unknown

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y4`

</td>
<td>



'Y04 '

</td>
<td>



<a id="rst-v4l2-pix-fmt-y4"></a>

Old 4-bit greyscale format. Only the most significant 4 bits of each byte are used, the other bits are set to 0.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y6`

</td>
<td>



'Y06 '

</td>
<td>



<a id="rst-v4l2-pix-fmt-y6"></a>

Old 6-bit greyscale format. Only the most significant 6 bits of each byte are used, the other bits are set to 0.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_S5C_UYVY_JPG`

</td>
<td>



'S5CI'

</td>
<td>



<a id="rst-v4l2-pix-fmt-s5c-uyvy-jpg"></a>

Two-planar format used by Samsung S5C73MX cameras. The first plane contains interleaved JPEG and UYVY image data, followed by meta data in form of an array of offsets to the UYVY data blocks. The actual pointer array follows immediately the interleaved JPEG/UYVY data, the number of entries in this array equals the height of the UYVY image. Each entry is a 4-byte unsigned integer in big endian order and it's an offset to a single pixel line of the UYVY image. The first plane can start either with JPEG or UYVY data chunk. The size of a single UYVY block equals the UYVY image's width multiplied by 2. The size of a JPEG chunk depends on the image and can vary with each line.

The second plane, at an offset of 4084 bytes, contains a 4-byte offset to the pointer array in the first plane. This offset is followed by a 4-byte value indicating size of the pointer array. All numbers in the second plane are also in big endian order. Remaining data in the second plane is undefined. The information in the second plane allows to easily find location of the pointer array, which can be different for each frame. The size of the pointer array is constant for given UYVY image height.

In order to extract UYVY and JPEG frames an application can initially set a data pointer to the start of first plane and then add an offset from the first entry of the pointers table. Such a pointer indicates start of an UYVY image pixel line. Whole UYVY line can be copied to a separate buffer. These steps should be repeated for each line, i.e. the number of entries in the pointer array. Anything what's in between the UYVY lines is JPEG data and should be concatenated to form the JPEG stream.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_MT21C`

</td>
<td>



'MT21'

</td>
<td>



<a id="rst-v4l2-pix-fmt-mt21c"></a>

Compressed two-planar YVU420 format used by Mediatek MT8173, MT8192, MT8195 and more. The compression is lossless. This format have similitude with `V4L2_PIX_FMT_MM21` in term of alignment and tiling. It remains an opaque intermediate format and the MDP hardware must be used to convert `V4L2_PIX_FMT_MT21C` to `V4L2_PIX_FMT_NV12M`, `V4L2_PIX_FMT_YUV420M` or `V4L2_PIX_FMT_YVU420`.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_QC08C`

</td>
<td>



'QC08C'

</td>
<td>



<a id="rst-v4l2-pix-fmt-qc08c"></a>

Compressed Macro-tile 8-Bit YUV420 format used by Qualcomm platforms. It is an opaque intermediate format. The used compression is lossless and it is used by various multimedia hardware blocks like GPU, display controllers, ISP and video accelerators. It contains four planes for progressive video and eight planes for interlaced video.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_QC10C`

</td>
<td>



'QC10C'

</td>
<td>



<a id="rst-v4l2-pix-fmt-qc10c"></a>

Compressed Macro-tile 10-Bit YUV420 format used by Qualcomm platforms. It is an opaque intermediate format. The used compression is lossless and it is used by various multimedia hardware blocks like GPU, display controllers, ISP and video accelerators. It contains four planes for progressive video.

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_AJPG`

</td>
<td>



'AJPG'

</td>
<td>



<a id="rst-v4l2-pix-fmt-ajpg"></a>

ASPEED JPEG format used by the aspeed-video driver on Aspeed platforms, which is generally adapted for remote KVM. On each frame compression, I will compare the new frame with previous one to decide which macroblock's data is changed, and only the changed macroblocks will be compressed.

The implementation is based on AST2600 A3 datasheet, revision 0.9, which is not publicly available. Or you can reference Video stream data format – ASPEED mode compression of SDK\_User\_Guide which available on [github](<https://github.com/AspeedTech-BMC/openbmc/releases/>).

Decoder's implementation can be found here, [aspeed\_codec](<https://github.com/AspeedTech-BMC/aspeed_codec/>)

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_HEXTILE`

</td>
<td>



'HXTL'

</td>
<td>



<a id="rst-v4l2-pix-fmt-hextile"></a>

Compressed format used by Nuvoton NPCM video driver. This format is defined in Remote Framebuffer Protocol (RFC 6143, chapter 7.7.4 Hextile Encoding).

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

---

# RGB Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These formats encode each pixel as a triplet of RGB values. They are packed formats, meaning that the RGB values for one pixel are stored consecutively in memory and each pixel consumes an integer number of bytes. When the number of bits…

<a id="rst-rgb-formats"></a>
<a id="rst-pixfmt-rgb"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

These formats encode each pixel as a triplet of RGB values. They are packed formats, meaning that the RGB values for one pixel are stored consecutively in memory and each pixel consumes an integer number of bytes. When the number of bits required to store a pixel is not aligned to a byte boundary, the data is padded with additional bits to fill the remaining byte.

The formats differ by the number of bits per RGB component (typically but not always the same for all components), the order of components in memory, and the presence of an alpha component or additional padding bits.

The usage and value of the alpha bits in formats that support them (named ARGB or a permutation thereof, collectively referred to as alpha formats) depend on the device type and hardware operation. [Capture](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>) devices (including capture queues of mem-to-mem devices) fill the alpha component in memory. When the device captures an alpha channel the alpha component will have a meaningful value. Otherwise, when the device doesn't capture an alpha channel but can set the alpha bit to a user-configurable value, the [V4L2\_CID\_ALPHA\_COMPONENT](</kernel/userspace/userspace-api/media-v4l/control.md#rst-v4l2-alpha-component>) control is used to specify that alpha value, and the alpha component of all pixels will be set to the value specified by that control. Otherwise a corresponding format without an alpha component (XRGB or XBGR) must be used instead of an alpha format.

[Output](</kernel/userspace/userspace-api/media-v4l/dev-output.md#rst-output>) devices (including output queues of mem-to-mem devices and [video output overlay](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>) devices) read the alpha component from memory. When the device processes the alpha channel the alpha component must be filled with meaningful values by applications. Otherwise a corresponding format without an alpha component (XRGB or XBGR) must be used instead of an alpha format.

Formats that contain padding bits are named XRGB (or a permutation thereof). The padding bits contain undefined values and must be ignored by applications, devices and drivers, for both [capture](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>) and [output](</kernel/userspace/userspace-api/media-v4l/dev-output.md#rst-output>) devices.

> [!NOTE]
>
> - In all the tables that follow, bit 7 is the most significant bit in a byte.
>
> - 'r', 'g' and 'b' denote bits of the red, green and blue components respectively. 'a' denotes bits of the alpha component (if supported by the format), and 'x' denotes padding bits.

<a id="rst-less-than-8-bits-per-component"></a>

## Less Than 8 Bits Per Component

These formats store an RGB triplet in one, two or four bytes. They are named based on the order of the RGB components as seen in a 8-, 16- or 32-bit word, which is then stored in memory in little endian byte order (unless otherwise noted by the presence of bit 31 in the 4CC value), and on the number of bits for each component. For instance, the RGB565 format stores a pixel in a 16-bit word \[15:0\] laid out at as \[R<sub>4</sub> R<sub>3</sub> R<sub>2</sub> R<sub>1</sub> R<sub>0</sub> G<sub>5</sub> G<sub>4</sub> G<sub>3</sub> G<sub>2</sub> G<sub>1</sub> G<sub>0</sub> B<sub>4</sub> B<sub>3</sub> B<sub>2</sub> B<sub>1</sub> B<sub>0</sub>\], and stored in memory in two bytes, \[R<sub>4</sub> R<sub>3</sub> R<sub>2</sub> R<sub>1</sub> R<sub>0</sub> G<sub>5</sub> G<sub>4</sub> G<sub>3</sub>\] followed by \[G<sub>2</sub> G<sub>1</sub> G<sub>0</sub> B<sub>4</sub> B<sub>3</sub> B<sub>2</sub> B<sub>1</sub> B<sub>0</sub>\].

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{2.8cm}|p{2.0cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->


<table>
<caption>

RGB Formats With Less Than 8 Bits Per Component

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th colspan="8">



 Byte 0 in memory

</th>
<th colspan="8">



 Byte 1

</th>
<th colspan="8">



 Byte 2

</th>
<th colspan="8">



 Byte 3

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_RGB332`

</td>
<td>



'RGB1'

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td colspan="24">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgb332"></a>

`V4L2_PIX_FMT_ARGB444`

</td>
<td>



'AR12'

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-argb444"></a>

`V4L2_PIX_FMT_XRGB444`

</td>
<td>



'XR12'

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-xrgb444"></a>

`V4L2_PIX_FMT_RGBA444`

</td>
<td>



'RA12'

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgba444"></a>

`V4L2_PIX_FMT_RGBX444`

</td>
<td>



'RX12'

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgbx444"></a>

`V4L2_PIX_FMT_ABGR444`

</td>
<td>



'AB12'

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-abgr444"></a>

`V4L2_PIX_FMT_XBGR444`

</td>
<td>



'XB12'

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-xbgr444"></a>

`V4L2_PIX_FMT_BGRA444`

</td>
<td>



'BA12'

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-bgra444"></a>

`V4L2_PIX_FMT_BGRX444`

</td>
<td>



'BX12'

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-bgrx444"></a>

`V4L2_PIX_FMT_ARGB555`

</td>
<td>



'AR15'

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



a

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-argb555"></a>

`V4L2_PIX_FMT_XRGB555`

</td>
<td>



'XR15'

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



x

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-xrgb555"></a>

`V4L2_PIX_FMT_RGBA555`

</td>
<td>



'RA15'

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



a

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgba555"></a>

`V4L2_PIX_FMT_RGBX555`

</td>
<td>



'RX15'

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



x

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgbx555"></a>

`V4L2_PIX_FMT_ABGR555`

</td>
<td>



'AB15'

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



a

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-abgr555"></a>

`V4L2_PIX_FMT_XBGR555`

</td>
<td>



'XB15'

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



x

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-xbgr555"></a>

`V4L2_PIX_FMT_BGRA555`

</td>
<td>



'BA15'

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



a

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-bgra555"></a>

`V4L2_PIX_FMT_BGRX555`

</td>
<td>



'BX15'

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



x

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-bgrx555"></a>

`V4L2_PIX_FMT_RGB565`

</td>
<td>



'RGBP'

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgb565"></a>

`V4L2_PIX_FMT_ARGB555X`

</td>
<td>



'AR15' \| (1 &lt;&lt; 31)

</td>
<td>



a

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-argb555x"></a>

`V4L2_PIX_FMT_XRGB555X`

</td>
<td>



'XR15' \| (1 &lt;&lt; 31)

</td>
<td>



x

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-xrgb555x"></a>

`V4L2_PIX_FMT_RGB565X`

</td>
<td>



'RGBR'

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgb565x"></a>

`V4L2_PIX_FMT_BGR666`

</td>
<td>



'BGRH'

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



<a id="rst-v4l2-pix-fmt-bgr666"></a>

x

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

<a id="rst-bits-per-component"></a>

## 8 Bits Per Component

These formats store an RGB triplet in three or four bytes. They are named based on the order of the RGB components as stored in memory, and on the total number of bits per pixel. For instance, RGB24 format stores a pixel with \[R<sub>7</sub> R<sub>6</sub> R<sub>5</sub> R<sub>4</sub> R<sub>3</sub> R<sub>2</sub> R<sub>1</sub> R<sub>0</sub>\] in the first byte, \[G<sub>7</sub> G<sub>6</sub> G<sub>5</sub> G<sub>4</sub> G<sub>3</sub> G<sub>2</sub> G<sub>1</sub> G<sub>0</sub>\] in the second byte and \[B<sub>7</sub> B<sub>6</sub> B<sub>5</sub> B<sub>4</sub> B<sub>3</sub> B<sub>2</sub> B<sub>1</sub> B<sub>0</sub>\] in the third byte. This differs from the DRM format nomenclature that instead use the order of components as seen in a 24- or 32-bit little endian word.

<!-- Source LaTeX layout: \small -->


<table>
<caption>

RGB Formats With 8 Bits Per Component

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Byte 0 in memory

</th>
<th>



Byte 1

</th>
<th>



Byte 2

</th>
<th>



Byte 3

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_BGR24`

</td>
<td>



'BGR3'

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



R<sub>7-0</sub>

</td>
<td>





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-bgr24"></a>

`V4L2_PIX_FMT_RGB24`

</td>
<td>



'RGB3'

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



B<sub>7-0</sub>

</td>
<td>





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgb24"></a>

`V4L2_PIX_FMT_ABGR32`

</td>
<td>



'AR24'

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-abgr32"></a>

A<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_XBGR32`

</td>
<td>



'XR24'

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-xbgr32"></a>

X<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_BGRA32`

</td>
<td>



'RA24'

</td>
<td>



A<sub>7-0</sub>

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-bgra32"></a>

R<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_BGRX32`

</td>
<td>



'RX24'

</td>
<td>



X<sub>7-0</sub>

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-bgrx32"></a>

R<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_RGBA32`

</td>
<td>



'AB24'

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-rgba32"></a>

A<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_RGBX32`

</td>
<td>



'XB24'

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-rgbx32"></a>

X<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_ARGB32`

</td>
<td>



'BA24'

</td>
<td>



A<sub>7-0</sub>

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-argb32"></a>

B<sub>7-0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_XRGB32`

</td>
<td>



'BX24'

</td>
<td>



X<sub>7-0</sub>

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-xrgb32"></a>

B<sub>7-0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-bits-per-component-1"></a>

## 10 Bits Per Component

These formats store a 30-bit RGB triplet with an optional 2 bit alpha in four bytes. They are named based on the order of the RGB components as seen in a 32-bit word, which is then stored in memory in little endian byte order (unless otherwise noted by the presence of bit 31 in the 4CC value), and on the number of bits for each component.

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{3.2cm}|p{0.8cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->


<table>
<caption>

RGB Formats 10 Bits Per Color Component

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th colspan="8">



 Byte 0 in memory

</th>
<th colspan="8">



 Byte 1

</th>
<th colspan="8">



 Byte 2

</th>
<th colspan="8">



 Byte 3

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_RGBX1010102`

</td>
<td>



'RX30'

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-rgbx1010102"></a>

r<sub>2</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_RGBA1010102`

</td>
<td>



'RA30'

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-rgba1010102"></a>

r<sub>2</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_ARGB2101010`

</td>
<td>



'AR30'

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-argb2101010"></a>

r<sub>4</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

<a id="rst-bits-per-component-2"></a>

## 12 Bits Per Component

These formats store an RGB triplet in six or eight bytes, with 12 bits per component. Expand the bits per component to 16 bits, data in the high bits, zeros in the low bits, arranged in little endian order.

<!-- Source LaTeX layout: \small -->


<table>
<caption>

RGB Formats With 12 Bits Per Component

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Byte 1-0

</th>
<th>



Byte 3-2

</th>
<th>



Byte 5-4

</th>
<th>



Byte 7-6

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_BGR48_12`

</td>
<td>



'B312'

</td>
<td>



B<sub>15-4</sub>

</td>
<td>



G<sub>15-4</sub>

</td>
<td>



R<sub>15-4</sub>

</td>
<td>





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-bgr48-12"></a>

`V4L2_PIX_FMT_ABGR64_12`

</td>
<td>



'B412'

</td>
<td>



B<sub>15-4</sub>

</td>
<td>



G<sub>15-4</sub>

</td>
<td>



R<sub>15-4</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-abgr64-12"></a>

A<sub>15-4</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-bits-per-component-3"></a>

## 16 Bits Per Component

These formats store an RGB triplet in six bytes, with 16 bits per component stored in memory in little endian byte order. They are named based on the order of the RGB components as stored in memory. For instance, RGB48 stores R<sub>7:0</sub> and R<sub>15:8</sub> in bytes 0 and 1 respectively. This differs from the DRM format nomenclature that instead uses the order of components as seen in the 48-bits little endian word.

<!-- Source LaTeX layout: \small -->


<table>
<caption>

RGB Formats With 16 Bits Per Component

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Byte 0

</th>
<th>



Byte 1

</th>
<th>



Byte 2

</th>
<th>



Byte 3

</th>
<th>



Byte 4

</th>
<th>



Byte 5

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_BGR48`

</td>
<td>



'BGR6'

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



B<sub>15-8</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



G<sub>15-8</sub>

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-bgr48"></a>

R<sub>15-8</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_RGB48`

</td>
<td>



'RGB6'

</td>
<td>



R<sub>7-0</sub>

</td>
<td>



R<sub>15-8</sub>

</td>
<td>



G<sub>7-0</sub>

</td>
<td>



G<sub>15-8</sub>

</td>
<td>



B<sub>7-0</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-rgb48"></a>

B<sub>15-8</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-deprecated-rgb-formats"></a>

## Deprecated RGB Formats

Formats defined in [pixfmt-rgb-deprecated](<#rst-pixfmt-rgb-deprecated>) are deprecated and must not be used by new drivers. They are documented here for reference. The meaning of their alpha bits `(a)` is ill-defined and they are interpreted as in either the corresponding ARGB or XRGB format, depending on the driver.

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{2.6cm}|p{0.70cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-pixfmt-rgb-deprecated"></a>


<table>
<caption>

Deprecated Packed RGB Image Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th colspan="8">



 Byte 0 in memory

</th>
<th colspan="8">



 Byte 1

</th>
<th colspan="8">



 Byte 2

</th>
<th colspan="8">



 Byte 3

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_RGB444`

</td>
<td>



'R444'

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgb444"></a>

`V4L2_PIX_FMT_RGB555`

</td>
<td>



'RGBO'

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



a

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgb555"></a>

`V4L2_PIX_FMT_RGB555X`

</td>
<td>



'RGBQ'

</td>
<td>



a

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td colspan="16">





</td>
</tr>
<tr>
<td>

<a id="rst-v4l2-pix-fmt-rgb555x"></a>

`V4L2_PIX_FMT_BGR32`

</td>
<td>



'BGR4'

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



a<sub>7</sub>

</td>
<td>



a<sub>6</sub>

</td>
<td>



a<sub>5</sub>

</td>
<td>



a<sub>4</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-bgr32"></a>

a<sub>0</sub>

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_RGB32`

</td>
<td>



'RGB4'

</td>
<td>



a<sub>7</sub>

</td>
<td>



a<sub>6</sub>

</td>
<td>



a<sub>5</sub>

</td>
<td>



a<sub>4</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-v4l2-pix-fmt-rgb32"></a>

b<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

A test utility to determine which RGB formats a driver actually supports is available from the LinuxTV v4l-dvb repository. See [https://linuxtv.org/repo/](<https://linuxtv.org/repo/>) for access instructions.

---

# V4L2_SDR_FMT_CS8 ('CS08')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Complex signed 8-bit IQ sample

<a id="rst-v4l2-sdr-fmt-cs8-cs08"></a>
<a id="rst-v4l2-sdr-fmt-cs8"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Complex signed 8-bit IQ sample

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

## Description

This format contains sequence of complex number samples. Each complex number consist two parts, called In-phase and Quadrature (IQ). Both I and Q are represented as a 8 bit signed number. I value comes first and Q value after that.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


I'<sub>0</sub>

</td>
</tr>
<tr>
<td>


start + 1:

</td>
<td>


Q'<sub>0</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_SDR_FMT_CS14LE ('CS14')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Complex signed 14-bit little endian IQ sample

<a id="rst-v4l2-sdr-fmt-cs14le-cs14"></a>
<a id="rst-v4l2-sdr-fmt-cs14le"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Complex signed 14-bit little endian IQ sample

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

## Description

This format contains sequence of complex number samples. Each complex number consist two parts, called In-phase and Quadrature (IQ). Both I and Q are represented as a 14 bit signed little endian number. I value comes first and Q value after that. 14 bit value is stored in 16 bit space with unused high bits padded with 0.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


I'<sub>0[7:0]</sub>

</td>
<td>


I'<sub>0[13:8]</sub>

</td>
</tr>
<tr>
<td>


start + 2:

</td>
<td>


Q'<sub>0[7:0]</sub>

</td>
<td>


Q'<sub>0[13:8]</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_SDR_FMT_CU8 ('CU08')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Complex unsigned 8-bit IQ sample

<a id="rst-v4l2-sdr-fmt-cu8-cu08"></a>
<a id="rst-v4l2-sdr-fmt-cu8"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Complex unsigned 8-bit IQ sample

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

## Description

This format contains sequence of complex number samples. Each complex number consist two parts, called In-phase and Quadrature (IQ). Both I and Q are represented as a 8 bit unsigned number. I value comes first and Q value after that.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


I'<sub>0</sub>

</td>
</tr>
<tr>
<td>


start + 1:

</td>
<td>


Q'<sub>0</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_SDR_FMT_CU16LE ('CU16')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Complex unsigned 16-bit little endian IQ sample

<a id="rst-v4l2-sdr-fmt-cu16le-cu16"></a>
<a id="rst-v4l2-sdr-fmt-cu16le"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Complex unsigned 16-bit little endian IQ sample

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

## Description

This format contains sequence of complex number samples. Each complex number consist two parts, called In-phase and Quadrature (IQ). Both I and Q are represented as a 16 bit unsigned little endian number. I value comes first and Q value after that.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


I'<sub>0[7:0]</sub>

</td>
<td>


I'<sub>0[15:8]</sub>

</td>
</tr>
<tr>
<td>


start + 2:

</td>
<td>


Q'<sub>0[7:0]</sub>

</td>
<td>


Q'<sub>0[15:8]</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_SDR_FMT_PCU16BE ('PC16')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Planar complex unsigned 16-bit big endian IQ sample

<a id="rst-v4l2-sdr-fmt-pcu16be-pc16"></a>
<a id="rst-v4l2-sdr-fmt-pcu16be"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Planar complex unsigned 16-bit big endian IQ sample

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

## Description

This format contains a sequence of complex number samples. Each complex number consist of two parts called In-phase and Quadrature (IQ). Both I and Q are represented as a 16 bit unsigned big endian number stored in 32 bit space. The remaining unused bits within the 32 bit space will be padded with 0. I value starts first and Q value starts at an offset equalling half of the buffer size (i.e.) offset = buffersize/2. Out of the 16 bits, bit 15:2 (14 bit) is data and bit 1:0 (2 bit) can be any value.

**Byte Order.** Each cell is one byte.


<table>
<thead>
<tr>
<th>


Offset:

</th>
<th>


Byte B0

</th>
<th>


Byte B1

</th>
<th>


Byte B2

</th>
<th>


Byte B3

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


I'<sub>0[13:6]</sub>

</td>
<td>


I'<sub>0[5:0]; B1[1:0]=pad</sub>

</td>
<td>


pad

</td>
<td>


pad

</td>
</tr>
<tr>
<td>


start + 4:

</td>
<td>


I'<sub>1[13:6]</sub>

</td>
<td>


I'<sub>1[5:0]; B1[1:0]=pad</sub>

</td>
<td>


pad

</td>
<td>


pad

</td>
</tr>
<tr>
<td colspan="5">


...

</td>
</tr>
<tr>
<td>


start + offset:

</td>
<td>


Q'<sub>0[13:6]</sub>

</td>
<td>


Q'<sub>0[5:0]; B1[1:0]=pad</sub>

</td>
<td>


pad

</td>
<td>


pad

</td>
</tr>
<tr>
<td>


start + offset + 4:

</td>
<td>


Q'<sub>1[13:6]</sub>

</td>
<td>


Q'<sub>1[5:0]; B1[1:0]=pad</sub>

</td>
<td>


pad

</td>
<td>


pad

</td>
</tr>
</tbody>
</table>

---

# V4L2_SDR_FMT_PCU18BE ('PC18')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Planar complex unsigned 18-bit big endian IQ sample

<a id="rst-v4l2-sdr-fmt-pcu18be-pc18"></a>
<a id="rst-v4l2-sdr-fmt-pcu18be"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Planar complex unsigned 18-bit big endian IQ sample

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

## Description

This format contains a sequence of complex number samples. Each complex number consist of two parts called In-phase and Quadrature (IQ). Both I and Q are represented as a 18 bit unsigned big endian number stored in 32 bit space. The remaining unused bits within the 32 bit space will be padded with 0. I value starts first and Q value starts at an offset equalling half of the buffer size (i.e.) offset = buffersize/2. Out of the 18 bits, bit 17:2 (16 bit) is data and bit 1:0 (2 bit) can be any value.

**Byte Order.** Each cell is one byte.


<table>
<thead>
<tr>
<th>


Offset:

</th>
<th>


Byte B0

</th>
<th>


Byte B1

</th>
<th>


Byte B2

</th>
<th>


Byte B3

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


I'<sub>0[17:10]</sub>

</td>
<td>


I'<sub>0[9:2]</sub>

</td>
<td>


I'<sub>0[1:0]; B2[5:0]=pad</sub>

</td>
<td>


pad

</td>
</tr>
<tr>
<td>


start + 4:

</td>
<td>


I'<sub>1[17:10]</sub>

</td>
<td>


I'<sub>1[9:2]</sub>

</td>
<td>


I'<sub>1[1:0]; B2[5:0]=pad</sub>

</td>
<td>


pad

</td>
</tr>
<tr>
<td colspan="5">


...

</td>
</tr>
<tr>
<td>


start + offset:

</td>
<td>


Q'<sub>0[17:10]</sub>

</td>
<td>


Q'<sub>0[9:2]</sub>

</td>
<td>


Q'<sub>0[1:0]; B2[5:0]=pad</sub>

</td>
<td>


pad

</td>
</tr>
<tr>
<td>


start + offset + 4:

</td>
<td>


Q'<sub>1[17:10]</sub>

</td>
<td>


Q'<sub>1[9:2]</sub>

</td>
<td>


Q'<sub>1[1:0]; B2[5:0]=pad</sub>

</td>
<td>


pad

</td>
</tr>
</tbody>
</table>

---

# V4L2_SDR_FMT_PCU20BE ('PC20')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Planar complex unsigned 20-bit big endian IQ sample

<a id="rst-v4l2-sdr-fmt-pcu20be-pc20"></a>
<a id="rst-v4l2-sdr-fmt-pcu20be"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Planar complex unsigned 20-bit big endian IQ sample

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

## Description

This format contains a sequence of complex number samples. Each complex number consist of two parts called In-phase and Quadrature (IQ). Both I and Q are represented as a 20 bit unsigned big endian number stored in 32 bit space. The remaining unused bits within the 32 bit space will be padded with 0. I value starts first and Q value starts at an offset equalling half of the buffer size (i.e.) offset = buffersize/2. Out of the 20 bits, bit 19:2 (18 bit) is data and bit 1:0 (2 bit) can be any value.

**Byte Order.** Each cell is one byte.


<table>
<thead>
<tr>
<th>


Offset:

</th>
<th>


Byte B0

</th>
<th>


Byte B1

</th>
<th>


Byte B2

</th>
<th>


Byte B3

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


I'<sub>0[19:12]</sub>

</td>
<td>


I'<sub>0[11:4]</sub>

</td>
<td>


I'<sub>0[3:0]; B2[3:0]=pad</sub>

</td>
<td>


pad

</td>
</tr>
<tr>
<td>


start + 4:

</td>
<td>


I'<sub>1[19:12]</sub>

</td>
<td>


I'<sub>1[11:4]</sub>

</td>
<td>


I'<sub>1[3:0]; B2[3:0]=pad</sub>

</td>
<td>


pad

</td>
</tr>
<tr>
<td colspan="5">


...

</td>
</tr>
<tr>
<td>


start + offset:

</td>
<td>


Q'<sub>0[19:12]</sub>

</td>
<td>


Q'<sub>0[11:4]</sub>

</td>
<td>


Q'<sub>0[3:0]; B2[3:0]=pad</sub>

</td>
<td>


pad

</td>
</tr>
<tr>
<td>


start + offset + 4:

</td>
<td>


Q'<sub>1[19:12]</sub>

</td>
<td>


Q'<sub>1[11:4]</sub>

</td>
<td>


Q'<sub>1[3:0]; B2[3:0]=pad</sub>

</td>
<td>


pad

</td>
</tr>
</tbody>
</table>

---

# V4L2_SDR_FMT_RU12LE ('RU12')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Real unsigned 12-bit little endian sample

<a id="rst-v4l2-sdr-fmt-ru12le-ru12"></a>
<a id="rst-v4l2-sdr-fmt-ru12le"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Real unsigned 12-bit little endian sample

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

## Description

This format contains sequence of real number samples. Each sample is represented as a 12 bit unsigned little endian number. Sample is stored in 16 bit space with unused high bits padded with 0.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


I'<sub>0[7:0]</sub>

</td>
<td>


I'<sub>0[11:8]</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_IPU3_SBGGR10 ('ip3b'), V4L2_PIX_FMT_IPU3_SGBRG10 ('ip3g'), V4L2_PIX_FMT_IPU3_SGRBG10 ('ip3G'), V4L2_PIX_FMT_IPU3_SRGGB10 ('ip3r')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These four pixel formats are used by Intel IPU3 driver, they are raw sRGB / Bayer formats with 10 bits per sample with every 25 pixels packed to 32 bytes leaving 6 most significant bits padding in the last byte. The format is little endian.

<a id="rst-v4l2-pix-fmt-ipu3-sbggr10-ip3b-v4l2-pix-fmt-ipu3-sgbrg10-ip3g-v4l2-pix-fmt-ipu3-sgrbg10-ip3g-v4l2-pix-fmt-ipu3-srggb10-ip3r"></a>
<a id="rst-v4l2-pix-fmt-ipu3-srggb10"></a>
<a id="rst-v4l2-pix-fmt-ipu3-sgrbg10"></a>
<a id="rst-v4l2-pix-fmt-ipu3-sgbrg10"></a>
<a id="rst-v4l2-pix-fmt-ipu3-sbggr10"></a>

<a id="rst-bit-bayer-formats"></a>

## 10-bit Bayer formats

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Description

These four pixel formats are used by Intel IPU3 driver, they are raw sRGB / Bayer formats with 10 bits per sample with every 25 pixels packed to 32 bytes leaving 6 most significant bits padding in the last byte. The format is little endian.

In other respects this format is similar to [v4l2-pix-fmt-srggb10](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10.md#rst-v4l2-pix-fmt-srggb10>). Below is an example of a small image in V4L2\_PIX\_FMT\_IPU3\_SBGGR10 format.

<strong>Byte Order.</strong> Each cell is one byte.

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{0.8cm}|p{3.3cm}|p{3.3cm}|p{3.3cm}|p{3.3cm}| -->


<table>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



B<sub>0000low</sub>

</td>
<td>



G<sub>0001low</sub>(bits 7--2)

B<sub>0000high</sub>(bits 1--0)

</td>
<td>



B<sub>0002low</sub>(bits 7--4)

G<sub>0001high</sub>(bits 3--0)

</td>
<td>



G<sub>0003low</sub>(bits 7--6)

B<sub>0002high</sub>(bits 5--0)

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



G<sub>0003high</sub>

</td>
<td>



B<sub>0004low</sub>

</td>
<td>



G<sub>0005low</sub>(bits 7--2)

B<sub>0004high</sub>(bits 1--0)

</td>
<td>



B<sub>0006low</sub>(bits 7--4)

G<sub>0005high</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



G<sub>0007low</sub>(bits 7--6)

B<sub>0006high</sub>(bits 5--0)

</td>
<td>



G<sub>0007high</sub>

</td>
<td>



B<sub>0008low</sub>

</td>
<td>



G<sub>0009low</sub>(bits 7--2)

B<sub>0008high</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



B<sub>0010low</sub>(bits 7--4)

G<sub>0009high</sub>(bits 3--0)

</td>
<td>



G<sub>0011low</sub>(bits 7--6)

B<sub>0010high</sub>(bits 5--0)

</td>
<td>



G<sub>0011high</sub>

</td>
<td>



B<sub>0012low</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td>



G<sub>0013low</sub>(bits 7--2)

B<sub>0012high</sub>(bits 1--0)

</td>
<td>



B<sub>0014low</sub>(bits 7--4)

G<sub>0013high</sub>(bits 3--0)

</td>
<td>



G<sub>0015low</sub>(bits 7--6)

B<sub>0014high</sub>(bits 5--0)

</td>
<td>



G<sub>0015high</sub>

</td>
</tr>
<tr>
<td>



start + 20

</td>
<td>



B<sub>0016low</sub>

</td>
<td>



G<sub>0017low</sub>(bits 7--2)

B<sub>0016high</sub>(bits 1--0)

</td>
<td>



B<sub>0018low</sub>(bits 7--4)

G<sub>0017high</sub>(bits 3--0)

</td>
<td>



G<sub>0019low</sub>(bits 7--6)

B<sub>0018high</sub>(bits 5--0)

</td>
</tr>
<tr>
<td>



start + 24:

</td>
<td>



G<sub>0019high</sub>

</td>
<td>



B<sub>0020low</sub>

</td>
<td>



G<sub>0021low</sub>(bits 7--2)

B<sub>0020high</sub>(bits 1--0)

</td>
<td>



B<sub>0022low</sub>(bits 7--4)

G<sub>0021high</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>



start + 28:

</td>
<td>



G<sub>0023low</sub>(bits 7--6)

B<sub>0022high</sub>(bits 5--0)

</td>
<td>



G<sub>0023high</sub>

</td>
<td>



B<sub>0024low</sub>

</td>
<td>



B<sub>0024high</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 32:

</td>
<td>



G<sub>0100low</sub>

</td>
<td>



R<sub>0101low</sub>(bits 7--2)

G<sub>0100high</sub>(bits 1--0)

</td>
<td>



G<sub>0102low</sub>(bits 7--4)

R<sub>0101high</sub>(bits 3--0)

</td>
<td>



R<sub>0103low</sub>(bits 7--6)

G<sub>0102high</sub>(bits 5--0)

</td>
</tr>
<tr>
<td>



start + 36:

</td>
<td>



R<sub>0103high</sub>

</td>
<td>



G<sub>0104low</sub>

</td>
<td>



R<sub>0105low</sub>(bits 7--2)

G<sub>0104high</sub>(bits 1--0)

</td>
<td>



G<sub>0106low</sub>(bits 7--4)

R<sub>0105high</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>



start + 40:

</td>
<td>



R<sub>0107low</sub>(bits 7--6)

G<sub>0106high</sub>(bits 5--0)

</td>
<td>



R<sub>0107high</sub>

</td>
<td>



G<sub>0108low</sub>

</td>
<td>



R<sub>0109low</sub>(bits 7--2)

G<sub>0108high</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 44:

</td>
<td>



G<sub>0110low</sub>(bits 7--4)

R<sub>0109high</sub>(bits 3--0)

</td>
<td>



R<sub>0111low</sub>(bits 7--6)

G<sub>0110high</sub>(bits 5--0)

</td>
<td>



R<sub>0111high</sub>

</td>
<td>



G<sub>0112low</sub>

</td>
</tr>
<tr>
<td>



start + 48:

</td>
<td>



R<sub>0113low</sub>(bits 7--2)

G<sub>0112high</sub>(bits 1--0)

</td>
<td>



G<sub>0114low</sub>(bits 7--4)

R<sub>0113high</sub>(bits 3--0)

</td>
<td>



R<sub>0115low</sub>(bits 7--6)

G<sub>0114high</sub>(bits 5--0)

</td>
<td>



R<sub>0115high</sub>

</td>
</tr>
<tr>
<td>



start + 52:

</td>
<td>



G<sub>0116low</sub>

</td>
<td>



R<sub>0117low</sub>(bits 7--2)

G<sub>0116high</sub>(bits 1--0)

</td>
<td>



G<sub>0118low</sub>(bits 7--4)

R<sub>0117high</sub>(bits 3--0)

</td>
<td>



R<sub>0119low</sub>(bits 7--6)

G<sub>0118high</sub>(bits 5--0)

</td>
</tr>
<tr>
<td>



start + 56:

</td>
<td>



R<sub>0119high</sub>

</td>
<td>



G<sub>0120low</sub>

</td>
<td>



R<sub>0121low</sub>(bits 7--2)

G<sub>0120high</sub>(bits 1--0)

</td>
<td>



G<sub>0122low</sub>(bits 7--4)

R<sub>0121high</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>



start + 60:

</td>
<td>



R<sub>0123low</sub>(bits 7--6)

G<sub>0122high</sub>(bits 5--0)

</td>
<td>



R<sub>0123high</sub>

</td>
<td>



G<sub>0124low</sub>

</td>
<td>



G<sub>0124high</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 64:

</td>
<td>



B<sub>0200low</sub>

</td>
<td>



G<sub>0201low</sub>(bits 7--2)

B<sub>0200high</sub>(bits 1--0)

</td>
<td>



B<sub>0202low</sub>(bits 7--4)

G<sub>0201high</sub>(bits 3--0)

</td>
<td>



G<sub>0203low</sub>(bits 7--6)

B<sub>0202high</sub>(bits 5--0)

</td>
</tr>
<tr>
<td>



start + 68:

</td>
<td>



G<sub>0203high</sub>

</td>
<td>



B<sub>0204low</sub>

</td>
<td>



G<sub>0205low</sub>(bits 7--2)

B<sub>0204high</sub>(bits 1--0)

</td>
<td>



B<sub>0206low</sub>(bits 7--4)

G<sub>0205high</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>



start + 72:

</td>
<td>



G<sub>0207low</sub>(bits 7--6)

B<sub>0206high</sub>(bits 5--0)

</td>
<td>



G<sub>0207high</sub>

</td>
<td>



B<sub>0208low</sub>

</td>
<td>



G<sub>0209low</sub>(bits 7--2)

B<sub>0208high</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 76:

</td>
<td>



B<sub>0210low</sub>(bits 7--4)

G<sub>0209high</sub>(bits 3--0)

</td>
<td>



G<sub>0211low</sub>(bits 7--6)

B<sub>0210high</sub>(bits 5--0)

</td>
<td>



G<sub>0211high</sub>

</td>
<td>



B<sub>0212low</sub>

</td>
</tr>
<tr>
<td>



start + 80:

</td>
<td>



G<sub>0213low</sub>(bits 7--2)

B<sub>0212high</sub>(bits 1--0)

</td>
<td>



B<sub>0214low</sub>(bits 7--4)

G<sub>0213high</sub>(bits 3--0)

</td>
<td>



G<sub>0215low</sub>(bits 7--6)

B<sub>0214high</sub>(bits 5--0)

</td>
<td>



G<sub>0215high</sub>

</td>
</tr>
<tr>
<td>



start + 84:

</td>
<td>



B<sub>0216low</sub>

</td>
<td>



G<sub>0217low</sub>(bits 7--2)

B<sub>0216high</sub>(bits 1--0)

</td>
<td>



B<sub>0218low</sub>(bits 7--4)

G<sub>0217high</sub>(bits 3--0)

</td>
<td>



G<sub>0219low</sub>(bits 7--6)

B<sub>0218high</sub>(bits 5--0)

</td>
</tr>
<tr>
<td>



start + 88:

</td>
<td>



G<sub>0219high</sub>

</td>
<td>



B<sub>0220low</sub>

</td>
<td>



G<sub>0221low</sub>(bits 7--2)

B<sub>0220high</sub>(bits 1--0)

</td>
<td>



B<sub>0222low</sub>(bits 7--4)

G<sub>0221high</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>



start + 92:

</td>
<td>



G<sub>0223low</sub>(bits 7--6)

B<sub>0222high</sub>(bits 5--0)

</td>
<td>



G<sub>0223high</sub>

</td>
<td>



B<sub>0224low</sub>

</td>
<td>



B<sub>0224high</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 96:

</td>
<td>



G<sub>0300low</sub>

</td>
<td>



R<sub>0301low</sub>(bits 7--2)

G<sub>0300high</sub>(bits 1--0)

</td>
<td>



G<sub>0302low</sub>(bits 7--4)

R<sub>0301high</sub>(bits 3--0)

</td>
<td>



R<sub>0303low</sub>(bits 7--6)

G<sub>0302high</sub>(bits 5--0)

</td>
</tr>
<tr>
<td>



start + 100:

</td>
<td>



R<sub>0303high</sub>

</td>
<td>



G<sub>0304low</sub>

</td>
<td>



R<sub>0305low</sub>(bits 7--2)

G<sub>0304high</sub>(bits 1--0)

</td>
<td>



G<sub>0306low</sub>(bits 7--4)

R<sub>0305high</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>



start + 104:

</td>
<td>



R<sub>0307low</sub>(bits 7--6)

G<sub>0306high</sub>(bits 5--0)

</td>
<td>



R<sub>0307high</sub>

</td>
<td>



G<sub>0308low</sub>

</td>
<td>



R<sub>0309low</sub>(bits 7--2)

G<sub>0308high</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 108:

</td>
<td>



G<sub>0310low</sub>(bits 7--4)

R<sub>0309high</sub>(bits 3--0)

</td>
<td>



R<sub>0311low</sub>(bits 7--6)

G<sub>0310high</sub>(bits 5--0)

</td>
<td>



R<sub>0311high</sub>

</td>
<td>



G<sub>0312low</sub>

</td>
</tr>
<tr>
<td>



start + 112:

</td>
<td>



R<sub>0313low</sub>(bits 7--2)

G<sub>0312high</sub>(bits 1--0)

</td>
<td>



G<sub>0314low</sub>(bits 7--4)

R<sub>0313high</sub>(bits 3--0)

</td>
<td>



R<sub>0315low</sub>(bits 7--6)

G<sub>0314high</sub>(bits 5--0)

</td>
<td>



R<sub>0315high</sub>

</td>
</tr>
<tr>
<td>



start + 116:

</td>
<td>



G<sub>0316low</sub>

</td>
<td>



R<sub>0317low</sub>(bits 7--2)

G<sub>0316high</sub>(bits 1--0)

</td>
<td>



G<sub>0318low</sub>(bits 7--4)

R<sub>0317high</sub>(bits 3--0)

</td>
<td>



R<sub>0319low</sub>(bits 7--6)

G<sub>0318high</sub>(bits 5--0)

</td>
</tr>
<tr>
<td>



start + 120:

</td>
<td>



R<sub>0319high</sub>

</td>
<td>



G<sub>0320low</sub>

</td>
<td>



R<sub>0321low</sub>(bits 7--2)

G<sub>0320high</sub>(bits 1--0)

</td>
<td>



G<sub>0322low</sub>(bits 7--4)

R<sub>0321high</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>



start + 124:

</td>
<td>



R<sub>0323low</sub>(bits 7--6)

G<sub>0322high</sub>(bits 5--0)

</td>
<td>



R<sub>0323high</sub>

</td>
<td>



G<sub>0324low</sub>

</td>
<td>



G<sub>0324high</sub>(bits 1--0)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

---

# V4L2_PIX_FMT_SRGGB10 ('RG10'), V4L2_PIX_FMT_SGRBG10 ('BA10'), V4L2_PIX_FMT_SGBRG10 ('GB10'), V4L2_PIX_FMT_SBGGR10 ('BG10'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> V4L2_PIX_FMT_SGRBG10 V4L2_PIX_FMT_SGBRG10 V4L2_PIX_FMT_SBGGR10 10-bit Bayer formats expanded to 16 bits

<a id="rst-v4l2-pix-fmt-srggb10-rg10-v4l2-pix-fmt-sgrbg10-ba10-v4l2-pix-fmt-sgbrg10-gb10-v4l2-pix-fmt-sbggr10-bg10"></a>
<a id="rst-v4l2-pix-fmt-sgrbg10"></a>
<a id="rst-v4l2-pix-fmt-sgbrg10"></a>
<a id="rst-v4l2-pix-fmt-sbggr10"></a>
<a id="rst-v4l2-pix-fmt-srggb10"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

V4L2_PIX_FMT_SGRBG10 V4L2_PIX_FMT_SGBRG10 V4L2_PIX_FMT_SBGGR10 10-bit Bayer formats expanded to 16 bits

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

## Description

These four pixel formats are raw sRGB / Bayer formats with 10 bits per sample. Each sample is stored in a 16-bit word, with 6 unused high bits filled with zeros. Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating red and blue rows. Bytes are stored in memory in little endian order. They are conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example of one of these formats:

**Byte Order.** Each cell is one byte, the 6 most significant bits in the high bytes are 0.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


B<sub>00low</sub>

</td>
<td>


B<sub>00high</sub>

</td>
<td>


G<sub>01low</sub>

</td>
<td>


G<sub>01high</sub>

</td>
<td>


B<sub>02low</sub>

</td>
<td>


B<sub>02high</sub>

</td>
<td>


G<sub>03low</sub>

</td>
<td>


G<sub>03high</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


G<sub>10low</sub>

</td>
<td>


G<sub>10high</sub>

</td>
<td>


R<sub>11low</sub>

</td>
<td>


R<sub>11high</sub>

</td>
<td>


G<sub>12low</sub>

</td>
<td>


G<sub>12high</sub>

</td>
<td>


R<sub>13low</sub>

</td>
<td>


R<sub>13high</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


B<sub>20low</sub>

</td>
<td>


B<sub>20high</sub>

</td>
<td>


G<sub>21low</sub>

</td>
<td>


G<sub>21high</sub>

</td>
<td>


B<sub>22low</sub>

</td>
<td>


B<sub>22high</sub>

</td>
<td>


G<sub>23low</sub>

</td>
<td>


G<sub>23high</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


G<sub>30low</sub>

</td>
<td>


G<sub>30high</sub>

</td>
<td>


R<sub>31low</sub>

</td>
<td>


R<sub>31high</sub>

</td>
<td>


G<sub>32low</sub>

</td>
<td>


G<sub>32high</sub>

</td>
<td>


R<sub>33low</sub>

</td>
<td>


R<sub>33high</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_SBGGR10ALAW8 ('aBA8'), V4L2_PIX_FMT_SGBRG10ALAW8 ('aGA8'), V4L2_PIX_FMT_SGRBG10ALAW8 ('agA8'), V4L2_PIX_FMT_SRGGB10ALAW8 ('aRA8'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> V4L2_PIX_FMT_SGBRG10ALAW8 V4L2_PIX_FMT_SGRBG10ALAW8 V4L2_PIX_FMT_SRGGB10ALAW8 10-bit Bayer formats compressed to 8 bits

<a id="rst-v4l2-pix-fmt-sbggr10alaw8-aba8-v4l2-pix-fmt-sgbrg10alaw8-aga8-v4l2-pix-fmt-sgrbg10alaw8-aga8-v4l2-pix-fmt-srggb10alaw8-ara8"></a>
<a id="rst-v4l2-pix-fmt-srggb10alaw8"></a>
<a id="rst-v4l2-pix-fmt-sgrbg10alaw8"></a>
<a id="rst-v4l2-pix-fmt-sgbrg10alaw8"></a>
<a id="rst-v4l2-pix-fmt-sbggr10alaw8"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

V4L2_PIX_FMT_SGBRG10ALAW8 V4L2_PIX_FMT_SGRBG10ALAW8 V4L2_PIX_FMT_SRGGB10ALAW8 10-bit Bayer formats compressed to 8 bits

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

## Description

These four pixel formats are raw sRGB / Bayer formats with 10 bits per color compressed to 8 bits each, using the A-LAW algorithm. Each color component consumes 8 bits of memory. In other respects this format is similar to [V4L2_PIX_FMT_SRGGB8 ('RGGB'), V4L2_PIX_FMT_SGRBG8 ('GRBG'), V4L2_PIX_FMT_SGBRG8 ('GBRG'), V4L2_PIX_FMT_SBGGR8 ('BA81'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-srggb8>).

---

# V4L2_PIX_FMT_SBGGR10DPCM8 ('bBA8'), V4L2_PIX_FMT_SGBRG10DPCM8 ('bGA8'), V4L2_PIX_FMT_SGRBG10DPCM8 ('BD10'), V4L2_PIX_FMT_SRGGB10DPCM8 ('bRA8'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> man V4L2_PIX_FMT_SBGGR10DPCM8(2)

<a id="rst-v4l2-pix-fmt-sbggr10dpcm8-bba8-v4l2-pix-fmt-sgbrg10dpcm8-bga8-v4l2-pix-fmt-sgrbg10dpcm8-bd10-v4l2-pix-fmt-srggb10dpcm8-bra8"></a>
<a id="rst-v4l2-pix-fmt-srggb10dpcm8"></a>
<a id="rst-v4l2-pix-fmt-sgrbg10dpcm8"></a>
<a id="rst-v4l2-pix-fmt-sgbrg10dpcm8"></a>
<a id="rst-v4l2-pix-fmt-sbggr10dpcm8"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

*man V4L2_PIX_FMT_SBGGR10DPCM8(2)*

V4L2_PIX_FMT_SGBRG10DPCM8 V4L2_PIX_FMT_SGRBG10DPCM8 V4L2_PIX_FMT_SRGGB10DPCM8 10-bit Bayer formats compressed to 8 bits

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

## Description

These four pixel formats are raw sRGB / Bayer formats with 10 bits per colour compressed to 8 bits each, using DPCM compression. DPCM, differential pulse-code modulation, is lossy. Each colour component consumes 8 bits of memory. In other respects this format is similar to [V4L2_PIX_FMT_SRGGB10 ('RG10'), V4L2_PIX_FMT_SGRBG10 ('BA10'), V4L2_PIX_FMT_SGBRG10 ('GB10'), V4L2_PIX_FMT_SBGGR10 ('BG10'),](</kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10.md#rst-v4l2-pix-fmt-srggb10>).

---

# V4L2_PIX_FMT_SRGGB10P ('pRAA'), V4L2_PIX_FMT_SGRBG10P ('pgAA'), V4L2_PIX_FMT_SGBRG10P ('pGAA'), V4L2_PIX_FMT_SBGGR10P ('pBAA'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> V4L2_PIX_FMT_SGRBG10P V4L2_PIX_FMT_SGBRG10P V4L2_PIX_FMT_SBGGR10P 10-bit packed Bayer formats

<a id="rst-v4l2-pix-fmt-srggb10p-praa-v4l2-pix-fmt-sgrbg10p-pgaa-v4l2-pix-fmt-sgbrg10p-pgaa-v4l2-pix-fmt-sbggr10p-pbaa"></a>
<a id="rst-v4l2-pix-fmt-sgrbg10p"></a>
<a id="rst-v4l2-pix-fmt-sgbrg10p"></a>
<a id="rst-v4l2-pix-fmt-sbggr10p"></a>
<a id="rst-v4l2-pix-fmt-srggb10p"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

V4L2_PIX_FMT_SGRBG10P V4L2_PIX_FMT_SGBRG10P V4L2_PIX_FMT_SBGGR10P 10-bit packed Bayer formats

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

## Description

These four pixel formats are packed raw sRGB / Bayer formats with 10 bits per sample. Every four consecutive samples are packed into 5 bytes. Each of the first 4 bytes contain the 8 high order bits of the pixels, and the 5th byte contains the 2 least significants bits of each pixel, in the same order.

Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating green-red and green-blue rows. They are conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example of a small V4L2_PIX_FMT_SBGGR10P image:

**Byte Order.** Each cell is one byte.

<!-- tabularcolumns: |p{2.4cm}|p{1.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{9.3cm}| -->


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


B<sub>00high</sub>

</td>
<td>


G<sub>01high</sub>

</td>
<td>


B<sub>02high</sub>

</td>
<td>


G<sub>03high</sub>

</td>
<td>


G<sub>03low</sub>(bits 7--6) B<sub>02low</sub>(bits 5--4)

G<sub>01low</sub>(bits 3--2) B<sub>00low</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>


start + 5:

</td>
<td>


G<sub>10high</sub>

</td>
<td>


R<sub>11high</sub>

</td>
<td>


G<sub>12high</sub>

</td>
<td>


R<sub>13high</sub>

</td>
<td>


R<sub>13low</sub>(bits 7--6) G<sub>12low</sub>(bits 5--4)

R<sub>11low</sub>(bits 3--2) G<sub>10low</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>


start + 10:

</td>
<td>


B<sub>20high</sub>

</td>
<td>


G<sub>21high</sub>

</td>
<td>


B<sub>22high</sub>

</td>
<td>


G<sub>23high</sub>

</td>
<td>


G<sub>23low</sub>(bits 7--6) B<sub>22low</sub>(bits 5--4)

G<sub>21low</sub>(bits 3--2) B<sub>20low</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>


start + 15:

</td>
<td>


G<sub>30high</sub>

</td>
<td>


R<sub>31high</sub>

</td>
<td>


G<sub>32high</sub>

</td>
<td>


R<sub>33high</sub>

</td>
<td>


R<sub>33low</sub>(bits 7--6) G<sub>32low</sub>(bits 5--4)

R<sub>31low</sub>(bits 3--2) G<sub>30low</sub>(bits 1--0)

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_SRGGB12 ('RG12'), V4L2_PIX_FMT_SGRBG12 ('BA12'), V4L2_PIX_FMT_SGBRG12 ('GB12'), V4L2_PIX_FMT_SBGGR12 ('BG12'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> V4L2_PIX_FMT_SGRBG12 V4L2_PIX_FMT_SGBRG12 V4L2_PIX_FMT_SBGGR12 12-bit Bayer formats expanded to 16 bits

<a id="rst-v4l2-pix-fmt-srggb12-rg12-v4l2-pix-fmt-sgrbg12-ba12-v4l2-pix-fmt-sgbrg12-gb12-v4l2-pix-fmt-sbggr12-bg12"></a>
<a id="rst-v4l2-pix-fmt-sgrbg12"></a>
<a id="rst-v4l2-pix-fmt-sgbrg12"></a>
<a id="rst-v4l2-pix-fmt-sbggr12"></a>
<a id="rst-v4l2-pix-fmt-srggb12"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

V4L2_PIX_FMT_SGRBG12 V4L2_PIX_FMT_SGBRG12 V4L2_PIX_FMT_SBGGR12 12-bit Bayer formats expanded to 16 bits

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

## Description

These four pixel formats are raw sRGB / Bayer formats with 12 bits per colour. Each colour component is stored in a 16-bit word, with 4 unused high bits filled with zeros. Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating red and blue rows. Bytes are stored in memory in little endian order. They are conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example of a small V4L2_PIX_FMT_SBGGR12 image:

**Byte Order.** Each cell is one byte, the 4 most significant bits in the high bytes are 0.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


B<sub>00low</sub>

</td>
<td>


B<sub>00high</sub>

</td>
<td>


G<sub>01low</sub>

</td>
<td>


G<sub>01high</sub>

</td>
<td>


B<sub>02low</sub>

</td>
<td>


B<sub>02high</sub>

</td>
<td>


G<sub>03low</sub>

</td>
<td>


G<sub>03high</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


G<sub>10low</sub>

</td>
<td>


G<sub>10high</sub>

</td>
<td>


R<sub>11low</sub>

</td>
<td>


R<sub>11high</sub>

</td>
<td>


G<sub>12low</sub>

</td>
<td>


G<sub>12high</sub>

</td>
<td>


R<sub>13low</sub>

</td>
<td>


R<sub>13high</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


B<sub>20low</sub>

</td>
<td>


B<sub>20high</sub>

</td>
<td>


G<sub>21low</sub>

</td>
<td>


G<sub>21high</sub>

</td>
<td>


B<sub>22low</sub>

</td>
<td>


B<sub>22high</sub>

</td>
<td>


G<sub>23low</sub>

</td>
<td>


G<sub>23high</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


G<sub>30low</sub>

</td>
<td>


G<sub>30high</sub>

</td>
<td>


R<sub>31low</sub>

</td>
<td>


R<sub>31high</sub>

</td>
<td>


G<sub>32low</sub>

</td>
<td>


G<sub>32high</sub>

</td>
<td>


R<sub>33low</sub>

</td>
<td>


R<sub>33high</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_SRGGB12P ('pRCC'), V4L2_PIX_FMT_SGRBG12P ('pgCC'), V4L2_PIX_FMT_SGBRG12P ('pGCC'), V4L2_PIX_FMT_SBGGR12P ('pBCC')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These four pixel formats are packed raw sRGB / Bayer formats with 12 bits per colour. Every two consecutive samples are packed into three bytes. Each of the first two bytes contain the 8 high order bits of the pixels, and the third byte…

<a id="rst-v4l2-pix-fmt-srggb12p-prcc-v4l2-pix-fmt-sgrbg12p-pgcc-v4l2-pix-fmt-sgbrg12p-pgcc-v4l2-pix-fmt-sbggr12p-pbcc"></a>
<a id="rst-v4l2-pix-fmt-sgrbg12p"></a>
<a id="rst-v4l2-pix-fmt-sgbrg12p"></a>
<a id="rst-v4l2-pix-fmt-sbggr12p"></a>
<a id="rst-v4l2-pix-fmt-srggb12p"></a>

<a id="rst-bit-packed-bayer-formats"></a>

## 12-bit packed Bayer formats

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Description

These four pixel formats are packed raw sRGB / Bayer formats with 12 bits per colour. Every two consecutive samples are packed into three bytes. Each of the first two bytes contain the 8 high order bits of the pixels, and the third byte contains the four least significant bits of each pixel, in the same order.

Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating green-red and green-blue rows. They are conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example of a small V4L2_PIX_FMT_SBGGR12P image:

**Byte Order.** Each cell is one byte.

<!-- tabularcolumns: |p{2.2cm}|p{1.2cm}|p{1.2cm}|p{3.1cm}|p{1.2cm}|p{1.2cm}|p{6.4cm}| -->


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


B<sub>00high</sub>

</td>
<td>


G<sub>01high</sub>

</td>
<td>


G<sub>01low</sub>(bits 7--4)

B<sub>00low</sub>(bits 3--0)

</td>
<td>


B<sub>02high</sub>

</td>
<td>


G<sub>03high</sub>

</td>
<td>


G<sub>03low</sub>(bits 7--4)

B<sub>02low</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>


start + 6:

</td>
<td>


G<sub>10high</sub>

</td>
<td>


R<sub>11high</sub>

</td>
<td>


R<sub>11low</sub>(bits 7--4)

G<sub>10low</sub>(bits 3--0)

</td>
<td>


G<sub>12high</sub>

</td>
<td>


R<sub>13high</sub>

</td>
<td>


R<sub>13low</sub>(bits 7--4)

G<sub>12low</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>


start + 12:

</td>
<td>


B<sub>20high</sub>

</td>
<td>


G<sub>21high</sub>

</td>
<td>


G<sub>21low</sub>(bits 7--4)

B<sub>20low</sub>(bits 3--0)

</td>
<td>


B<sub>22high</sub>

</td>
<td>


G<sub>23high</sub>

</td>
<td>


G<sub>23low</sub>(bits 7--4)

B<sub>22low</sub>(bits 3--0)

</td>
</tr>
<tr>
<td>


start + 18:

</td>
<td>


G<sub>30high</sub>

</td>
<td>


R<sub>31high</sub>

</td>
<td>


R<sub>31low</sub>(bits 7--4)

G<sub>30low</sub>(bits 3--0)

</td>
<td>


G<sub>32high</sub>

</td>
<td>


R<sub>33high</sub>

</td>
<td>


R<sub>33low</sub>(bits 7--4)

G<sub>32low</sub>(bits 3--0)

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_SRGGB14 ('RG14'), V4L2_PIX_FMT_SGRBG14 ('GR14'), V4L2_PIX_FMT_SGBRG14 ('GB14'), V4L2_PIX_FMT_SBGGR14 ('BG14'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These four pixel formats are raw sRGB / Bayer formats with 14 bits per colour. Each sample is stored in a 16-bit word, with two unused high bits filled with zeros. Each n-pixel row contains n/2 green samples and n/2 blue or red samples,…

<a id="rst-v4l2-pix-fmt-srggb14-rg14-v4l2-pix-fmt-sgrbg14-gr14-v4l2-pix-fmt-sgbrg14-gb14-v4l2-pix-fmt-sbggr14-bg14"></a>
<a id="rst-v4l2-pix-fmt-sgrbg14"></a>
<a id="rst-v4l2-pix-fmt-sgbrg14"></a>
<a id="rst-v4l2-pix-fmt-sbggr14"></a>
<a id="rst-v4l2-pix-fmt-srggb14"></a>

<a id="rst-bit-bayer-formats-expanded-to-16-bits"></a>

## 14-bit Bayer formats expanded to 16 bits

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Description

These four pixel formats are raw sRGB / Bayer formats with 14 bits per colour. Each sample is stored in a 16-bit word, with two unused high bits filled with zeros. Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating red and blue rows. Bytes are stored in memory in little endian order. They are conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example of a small V4L2_PIX_FMT_SBGGR14 image:

**Byte Order.** Each cell is one byte, the two most significant bits in the high bytes are zero.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


B<sub>00low</sub>

</td>
<td>


B<sub>00high</sub>

</td>
<td>


G<sub>01low</sub>

</td>
<td>


G<sub>01high</sub>

</td>
<td>


B<sub>02low</sub>

</td>
<td>


B<sub>02high</sub>

</td>
<td>


G<sub>03low</sub>

</td>
<td>


G<sub>03high</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


G<sub>10low</sub>

</td>
<td>


G<sub>10high</sub>

</td>
<td>


R<sub>11low</sub>

</td>
<td>


R<sub>11high</sub>

</td>
<td>


G<sub>12low</sub>

</td>
<td>


G<sub>12high</sub>

</td>
<td>


R<sub>13low</sub>

</td>
<td>


R<sub>13high</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


B<sub>20low</sub>

</td>
<td>


B<sub>20high</sub>

</td>
<td>


G<sub>21low</sub>

</td>
<td>


G<sub>21high</sub>

</td>
<td>


B<sub>22low</sub>

</td>
<td>


B<sub>22high</sub>

</td>
<td>


G<sub>23low</sub>

</td>
<td>


G<sub>23high</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


G<sub>30low</sub>

</td>
<td>


G<sub>30high</sub>

</td>
<td>


R<sub>31low</sub>

</td>
<td>


R<sub>31high</sub>

</td>
<td>


G<sub>32low</sub>

</td>
<td>


G<sub>32high</sub>

</td>
<td>


R<sub>33low</sub>

</td>
<td>


R<sub>33high</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_SRGGB14P ('pREE'), V4L2_PIX_FMT_SGRBG14P ('pgEE'), V4L2_PIX_FMT_SGBRG14P ('pGEE'), V4L2_PIX_FMT_SBGGR14P ('pBEE'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> man V4L2_PIX_FMT_SRGGB14P(2)

<a id="rst-v4l2-pix-fmt-srggb14p-pree-v4l2-pix-fmt-sgrbg14p-pgee-v4l2-pix-fmt-sgbrg14p-pgee-v4l2-pix-fmt-sbggr14p-pbee"></a>
<a id="rst-v4l2-pix-fmt-sgrbg14p"></a>
<a id="rst-v4l2-pix-fmt-sgbrg14p"></a>
<a id="rst-v4l2-pix-fmt-sbggr14p"></a>
<a id="rst-v4l2-pix-fmt-srggb14p"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<em>man V4L2\_PIX\_FMT\_SRGGB14P(2)</em>

V4L2\_PIX\_FMT\_SGRBG14P V4L2\_PIX\_FMT\_SGBRG14P V4L2\_PIX\_FMT\_SBGGR14P 14-bit packed Bayer formats

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

## Description

These four pixel formats are packed raw sRGB / Bayer formats with 14 bits per colour. Every four consecutive samples are packed into seven bytes. Each of the first four bytes contain the eight high order bits of the pixels, and the three following bytes contains the six least significant bits of each pixel, in the same order.

Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating green-red and green-blue rows. They are conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example of one of these formats:

<strong>Byte Order.</strong> Each cell is one byte.

<!-- Source LaTeX layout: \begingroup
\footnotesize
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{1.6cm}|p{1.0cm}|p{1.0cm}|p{1.0cm}|p{1.0cm}|p{3.5cm}|p{3.5cm}|p{3.5cm}| -->


<table>
<tbody>
<tr>
<td>



start + 0

</td>
<td>



B<sub>00high</sub>

</td>
<td>



G<sub>01high</sub>

</td>
<td>



B<sub>02high</sub>

</td>
<td>



G<sub>03high</sub>

</td>
<td>



G<sub>01low bits 1--0</sub>(bits 7--6)

B<sub>00low bits 5--0</sub>(bits 5--0)

</td>
<td>



B<sub>02low bits 3--0</sub>(bits 7--4)

G<sub>01low bits 5--2</sub>(bits 3--0)

</td>
<td>



G<sub>03low bits 5--0</sub>(bits 7--2)

B<sub>02low bits 5--4</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 7

</td>
<td>



G<sub>10high</sub>

</td>
<td>



R<sub>11high</sub>

</td>
<td>



G<sub>12high</sub>

</td>
<td>



R<sub>13high</sub>

</td>
<td>



R<sub>11low bits 1--0</sub>(bits 7--6)

G<sub>10low bits 5--0</sub>(bits 5--0)

</td>
<td>



G<sub>12low bits 3--0</sub>(bits 7--4)

R<sub>11low bits 5--2</sub>(bits 3--0)

</td>
<td>



R<sub>13low bits 5--0</sub>(bits 7--2)

G<sub>12low bits 5--4</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 14

</td>
<td>



B<sub>20high</sub>

</td>
<td>



G<sub>21high</sub>

</td>
<td>



B<sub>22high</sub>

</td>
<td>



G<sub>23high</sub>

</td>
<td>



G<sub>21low bits 1--0</sub>(bits 7--6)

B<sub>20low bits 5--0</sub>(bits 5--0)

</td>
<td>



B<sub>22low bits 3--0</sub>(bits 7--4)

G<sub>21low bits 5--2</sub>(bits 3--0)

</td>
<td>



G<sub>23low bits 5--0</sub>(bits 7--2)

B<sub>22low bits 5--4</sub>(bits 1--0)

</td>
</tr>
<tr>
<td>



start + 21

</td>
<td>



G<sub>30high</sub>

</td>
<td>



R<sub>31high</sub>

</td>
<td>



G<sub>32high</sub>

</td>
<td>



R<sub>33high</sub>

</td>
<td>



R<sub>31low bits 1--0</sub>(bits 7--6) G<sub>30low bits 5--0</sub>(bits 5--0)

</td>
<td>



G<sub>32low bits 3--0</sub>(bits 7--4) R<sub>31low bits 5--2</sub>(bits 3--0)

</td>
<td>



R<sub>33low bits 5--0</sub>(bits 7--2) G<sub>32low bits 5--4</sub>(bits 1--0)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

---

# V4L2_PIX_FMT_SRGGB16 ('RG16'), V4L2_PIX_FMT_SGRBG16 ('GR16'), V4L2_PIX_FMT_SGBRG16 ('GB16'), V4L2_PIX_FMT_SBGGR16 ('BYR2'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These four pixel formats are raw sRGB / Bayer formats with 16 bits per sample. Each sample is stored in a 16-bit word. Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating red and blue rows. Bytes are…

<a id="rst-v4l2-pix-fmt-srggb16-rg16-v4l2-pix-fmt-sgrbg16-gr16-v4l2-pix-fmt-sgbrg16-gb16-v4l2-pix-fmt-sbggr16-byr2"></a>
<a id="rst-v4l2-pix-fmt-sgrbg16"></a>
<a id="rst-v4l2-pix-fmt-sgbrg16"></a>
<a id="rst-v4l2-pix-fmt-sbggr16"></a>
<a id="rst-v4l2-pix-fmt-srggb16"></a>

<a id="rst-bit-bayer-formats"></a>

## 16-bit Bayer formats

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Description

These four pixel formats are raw sRGB / Bayer formats with 16 bits per sample. Each sample is stored in a 16-bit word. Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating red and blue rows. Bytes are stored in memory in little endian order. They are conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example of a small V4L2_PIX_FMT_SBGGR16 image:

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


B<sub>00low</sub>

</td>
<td>


B<sub>00high</sub>

</td>
<td>


G<sub>01low</sub>

</td>
<td>


G<sub>01high</sub>

</td>
<td>


B<sub>02low</sub>

</td>
<td>


B<sub>02high</sub>

</td>
<td>


G<sub>03low</sub>

</td>
<td>


G<sub>03high</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


G<sub>10low</sub>

</td>
<td>


G<sub>10high</sub>

</td>
<td>


R<sub>11low</sub>

</td>
<td>


R<sub>11high</sub>

</td>
<td>


G<sub>12low</sub>

</td>
<td>


G<sub>12high</sub>

</td>
<td>


R<sub>13low</sub>

</td>
<td>


R<sub>13high</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


B<sub>20low</sub>

</td>
<td>


B<sub>20high</sub>

</td>
<td>


G<sub>21low</sub>

</td>
<td>


G<sub>21high</sub>

</td>
<td>


B<sub>22low</sub>

</td>
<td>


B<sub>22high</sub>

</td>
<td>


G<sub>23low</sub>

</td>
<td>


G<sub>23high</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


G<sub>30low</sub>

</td>
<td>


G<sub>30high</sub>

</td>
<td>


R<sub>31low</sub>

</td>
<td>


R<sub>31high</sub>

</td>
<td>


G<sub>32low</sub>

</td>
<td>


G<sub>32high</sub>

</td>
<td>


R<sub>33low</sub>

</td>
<td>


R<sub>33high</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_PISP_COMP1_RGGB ('PC1R'), V4L2_PIX_FMT_PISP_COMP1_GRBG ('PC1G'), V4L2_PIX_FMT_PISP_COMP1_GBRG ('PC1g'), V4L2_PIX_FMT_PISP_COMP1_BGGR ('PC1B), V4L2_PIX_FMT_PISP_COMP1_MONO ('PC1M'), V4L2_PIX_FMT_PISP_COMP2_RGGB ('PC2R'), V4L2_PIX_FMT_PISP_COMP2_GRBG ('PC2G'), V4L2_PIX_FMT_PISP_COMP2_GBRG ('PC2g'), V4L2_PIX_FMT_PISP_COMP2_BGGR ('PC2B), V4L2_PIX_FMT_PISP_COMP2_MONO ('PC2M')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The Raspberry Pi ISP (PiSP) uses a family of three fixed-rate compressed Bayer formats. A black-level offset may be subtracted to improve compression efficiency; the nominal black level and amount of offset must be signalled out of band.…

<a id="rst-v4l2-pix-fmt-pisp-comp1-rggb-pc1r-v4l2-pix-fmt-pisp-comp1-grbg-pc1g-v4l2-pix-fmt-pisp-comp1-gbrg-pc1g-v4l2-pix-fmt-pisp-comp1-bggr-pc1b-v4l2-pix-fmt-pisp-comp1-mono-pc1m-v4l2-pix-fmt-pisp-comp2-rggb-pc2r-v4l2-pix-fmt-pisp-comp2-grbg-pc2g-v4l2-pix-fmt-pisp-comp2-gbrg-pc2g-v4l2-pix-fmt-pisp-comp2-bggr-pc2b-v4l2-pix-fmt-pisp-comp2-mono-pc2m"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp2-mono"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp2-bggr"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp2-gbrg"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp2-grbg"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp2-rggb"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp1-mono"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp1-bggr"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp1-gbrg"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp1-grbg"></a>
<a id="rst-v4l2-pix-fmt-pisp-comp1-rggb"></a>

<a id="rst-raspberry-pi-pisp-compressed-8-bit-bayer-formats"></a>

## Raspberry Pi PiSP compressed 8-bit Bayer formats

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Description

The Raspberry Pi ISP (PiSP) uses a family of three fixed-rate compressed Bayer formats. A black-level offset may be subtracted to improve compression efficiency; the nominal black level and amount of offset must be signalled out of band. Each scanline is padded to a multiple of 8 pixels wide, and each block of 8 horizontally-contiguous pixels is coded using 8 bytes.

Mode 1 uses a quantization and delta-based coding scheme which preserves up to 12 significant bits. Mode 2 is a simple sqrt-like companding scheme with 6 PWL chords, preserving up to 12 significant bits. Mode 3 combines both companding (with 4 chords) and the delta scheme, preserving up to 14 significant bits.

The remainder of this description applies to Modes 1 and 3.

Each block of 8 pixels is separated into even and odd phases of 4 pixels, coded independently by 32-bit words at successive locations in memory. The two LS bits of each 32-bit word give its "quantization mode".

In quantization mode 0, the lowest 321 quantization levels are multiples of FSD/4096 and the remaining levels are successive multiples of FSD/2048. Quantization modes 1 and 2 use linear quantization with step sizes of FSD/1024 and FSD/512 respectively. Each of the four pixels is quantized independently, with rounding to the nearest level. In quantization mode 2 where the middle two samples have quantized values (q1,q2) both in the range \[384..511\], they are coded using 9 bits for q1 followed by 7 bits for (q2 &amp; 127). Otherwise, for quantization modes 0, 1 and 2: a 9-bit field encodes MIN(q1,q2) which must be in the range \[0..511\] and a 7-bit field encodes (q2-q1+64) which must be in \[0..127\].

Each of the outer samples (q0,q3) is encoded using a 7-bit field based on its inner neighbour q1 or q2. In quantization mode 2 where the inner sample has a quantized value in the range \[448..511\], the field value is (q0-384). Otherwise for quantization modes 0, 1 and 2: The outer sample is encoded as (q0-MAX(0,q1-64)). q3 is likewise coded based on q2. Each of these values must be in the range \[0..127\]. All these fields of 2, 9, 7, 7, 7 bits respectively are packed in little-endian order to give a 32-bit word with LE byte order.

Quantization mode 3 has a "7.5-bit" escape, used when none of the above encodings will fit. Each pixel value is quantized to the nearest of 176 levels, where the lowest 95 levels are multiples of FSD/256 and the remaining levels are multiples of FSD/128 (level 175 represents values very close to FSD and may require saturating arithmetic to decode).

Each pair of quantized pixels (q0,q1) or (q2,q3) is jointly coded by a 15-bit field: 2816\*(q0&gt;&gt;4) + 16\*q1 + (q0&amp;15). Three fields of 2, 15, 15 bits are packed in LE order \{15,15,2\}.

An implementation of a software decoder of compressed formats is available in [Raspberry Pi camera applications code base](<https://github.com/raspberrypi/rpicam-apps/blob/main/image/dng.cpp>)<a id="rst-raspberry-pi-camera-applications-code-base"></a>.

---

# V4L2_PIX_FMT_SRGGB8 ('RGGB'), V4L2_PIX_FMT_SGRBG8 ('GRBG'), V4L2_PIX_FMT_SGBRG8 ('GBRG'), V4L2_PIX_FMT_SBGGR8 ('BA81'),

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These four pixel formats are raw sRGB / Bayer formats with 8 bits per sample. Each sample is stored in a byte. Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating red and blue rows. They are…

<a id="rst-v4l2-pix-fmt-srggb8-rggb-v4l2-pix-fmt-sgrbg8-grbg-v4l2-pix-fmt-sgbrg8-gbrg-v4l2-pix-fmt-sbggr8-ba81"></a>
<a id="rst-v4l2-pix-fmt-sgrbg8"></a>
<a id="rst-v4l2-pix-fmt-sgbrg8"></a>
<a id="rst-v4l2-pix-fmt-sbggr8"></a>
<a id="rst-v4l2-pix-fmt-srggb8"></a>

<a id="rst-bit-bayer-formats"></a>

## 8-bit Bayer formats

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Description

These four pixel formats are raw sRGB / Bayer formats with 8 bits per sample. Each sample is stored in a byte. Each n-pixel row contains n/2 green samples and n/2 blue or red samples, with alternating red and blue rows. They are conventionally described as GRGR... BGBG..., RGRG... GBGB..., etc. Below is an example of a small V4L2_PIX_FMT_SBGGR8 image:

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


B<sub>00</sub>

</td>
<td>


G<sub>01</sub>

</td>
<td>


B<sub>02</sub>

</td>
<td>


G<sub>03</sub>

</td>
</tr>
<tr>
<td>


start + 4:

</td>
<td>


G<sub>10</sub>

</td>
<td>


R<sub>11</sub>

</td>
<td>


G<sub>12</sub>

</td>
<td>


R<sub>13</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


B<sub>20</sub>

</td>
<td>


G<sub>21</sub>

</td>
<td>


B<sub>22</sub>

</td>
<td>


G<sub>23</sub>

</td>
</tr>
<tr>
<td>


start + 12:

</td>
<td>


G<sub>30</sub>

</td>
<td>


R<sub>31</sub>

</td>
<td>


G<sub>32</sub>

</td>
<td>


R<sub>33</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_TCH_FMT_DELTA_TD08 ('TD08')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> man V4L2_TCH_FMT_DELTA_TD08(2)

<a id="rst-v4l2-tch-fmt-delta-td08-td08"></a>
<a id="rst-v4l2-tch-fmt-delta-td08"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

*man V4L2_TCH_FMT_DELTA_TD08(2)*

8-bit signed Touch Delta

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

## Description

This format represents delta data from a touch controller.

Delta values may range from -128 to 127. Typically the values will vary through a small range depending on whether the sensor is touched or not. The full value may be seen if one of the touchscreen nodes has a fault or the line is not connected.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


D'<sub>00</sub>

</td>
<td>


D'<sub>01</sub>

</td>
<td>


D'<sub>02</sub>

</td>
<td>


D'<sub>03</sub>

</td>
</tr>
<tr>
<td>


start + 4:

</td>
<td>


D'<sub>10</sub>

</td>
<td>


D'<sub>11</sub>

</td>
<td>


D'<sub>12</sub>

</td>
<td>


D'<sub>13</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


D'<sub>20</sub>

</td>
<td>


D'<sub>21</sub>

</td>
<td>


D'<sub>22</sub>

</td>
<td>


D'<sub>23</sub>

</td>
</tr>
<tr>
<td>


start + 12:

</td>
<td>


D'<sub>30</sub>

</td>
<td>


D'<sub>31</sub>

</td>
<td>


D'<sub>32</sub>

</td>
<td>


D'<sub>33</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_TCH_FMT_DELTA_TD16 ('TD16')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> man V4L2_TCH_FMT_DELTA_TD16(2)

<a id="rst-v4l2-tch-fmt-delta-td16-td16"></a>
<a id="rst-v4l2-tch-fmt-delta-td16"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

*man V4L2_TCH_FMT_DELTA_TD16(2)*

16-bit signed little endian Touch Delta

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

## Description

This format represents delta data from a touch controller.

Delta values may range from -32768 to 32767. Typically the values will vary through a small range depending on whether the sensor is touched or not. The full value may be seen if one of the touchscreen nodes has a fault or the line is not connected.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


D'<sub>00low</sub>

</td>
<td>


D'<sub>00high</sub>

</td>
<td>


D'<sub>01low</sub>

</td>
<td>


D'<sub>01high</sub>

</td>
<td>


D'<sub>02low</sub>

</td>
<td>


D'<sub>02high</sub>

</td>
<td>


D'<sub>03low</sub>

</td>
<td>


D'<sub>03high</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


D'<sub>10low</sub>

</td>
<td>


D'<sub>10high</sub>

</td>
<td>


D'<sub>11low</sub>

</td>
<td>


D'<sub>11high</sub>

</td>
<td>


D'<sub>12low</sub>

</td>
<td>


D'<sub>12high</sub>

</td>
<td>


D'<sub>13low</sub>

</td>
<td>


D'<sub>13high</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


D'<sub>20low</sub>

</td>
<td>


D'<sub>20high</sub>

</td>
<td>


D'<sub>21low</sub>

</td>
<td>


D'<sub>21high</sub>

</td>
<td>


D'<sub>22low</sub>

</td>
<td>


D'<sub>22high</sub>

</td>
<td>


D'<sub>23low</sub>

</td>
<td>


D'<sub>23high</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


D'<sub>30low</sub>

</td>
<td>


D'<sub>30high</sub>

</td>
<td>


D'<sub>31low</sub>

</td>
<td>


D'<sub>31high</sub>

</td>
<td>


D'<sub>32low</sub>

</td>
<td>


D'<sub>32high</sub>

</td>
<td>


D'<sub>33low</sub>

</td>
<td>


D'<sub>33high</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_TCH_FMT_TU08 ('TU08')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> man V4L2_TCH_FMT_TU08(2)

<a id="rst-v4l2-tch-fmt-tu08-tu08"></a>
<a id="rst-v4l2-tch-fmt-tu08"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

*man V4L2_TCH_FMT_TU08(2)*

8-bit unsigned raw touch data

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

## Description

This format represents unsigned 8-bit data from a touch controller.

This may be used for output for raw and reference data. Values may range from 0 to 255.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


R'<sub>00</sub>

</td>
<td>


R'<sub>01</sub>

</td>
<td>


R'<sub>02</sub>

</td>
<td>


R'<sub>03</sub>

</td>
</tr>
<tr>
<td>


start + 4:

</td>
<td>


R'<sub>10</sub>

</td>
<td>


R'<sub>11</sub>

</td>
<td>


R'<sub>12</sub>

</td>
<td>


R'<sub>13</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


R'<sub>20</sub>

</td>
<td>


R'<sub>21</sub>

</td>
<td>


R'<sub>22</sub>

</td>
<td>


R'<sub>23</sub>

</td>
</tr>
<tr>
<td>


start + 12:

</td>
<td>


R'<sub>30</sub>

</td>
<td>


R'<sub>31</sub>

</td>
<td>


R'<sub>32</sub>

</td>
<td>


R'<sub>33</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_TCH_FMT_TU16 ('TU16')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> man V4L2_TCH_FMT_TU16(2)

<a id="rst-v4l2-tch-fmt-tu16-tu16"></a>
<a id="rst-v4l2-tch-fmt-tu16"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

*man V4L2_TCH_FMT_TU16(2)*

16-bit unsigned little endian raw touch data

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

## Description

This format represents unsigned 16-bit data from a touch controller.

This may be used for output for raw and reference data. Values may range from 0 to 65535.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


R'<sub>00low</sub>

</td>
<td>


R'<sub>00high</sub>

</td>
<td>


R'<sub>01low</sub>

</td>
<td>


R'<sub>01high</sub>

</td>
<td>


R'<sub>02low</sub>

</td>
<td>


R'<sub>02high</sub>

</td>
<td>


R'<sub>03low</sub>

</td>
<td>


R'<sub>03high</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


R'<sub>10low</sub>

</td>
<td>


R'<sub>10high</sub>

</td>
<td>


R'<sub>11low</sub>

</td>
<td>


R'<sub>11high</sub>

</td>
<td>


R'<sub>12low</sub>

</td>
<td>


R'<sub>12high</sub>

</td>
<td>


R'<sub>13low</sub>

</td>
<td>


R'<sub>13high</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


R'<sub>20low</sub>

</td>
<td>


R'<sub>20high</sub>

</td>
<td>


R'<sub>21low</sub>

</td>
<td>


R'<sub>21high</sub>

</td>
<td>


R'<sub>22low</sub>

</td>
<td>


R'<sub>22high</sub>

</td>
<td>


R'<sub>23low</sub>

</td>
<td>


R'<sub>23high</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


R'<sub>30low</sub>

</td>
<td>


R'<sub>30high</sub>

</td>
<td>


R'<sub>31low</sub>

</td>
<td>


R'<sub>31high</sub>

</td>
<td>


R'<sub>32low</sub>

</td>
<td>


R'<sub>32high</sub>

</td>
<td>


R'<sub>33low</sub>

</td>
<td>


R'<sub>33high</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_UV8 ('UV8')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> UV plane interleaved

<a id="rst-v4l2-pix-fmt-uv8-uv8"></a>
<a id="rst-v4l2-pix-fmt-uv8"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

UV plane interleaved

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

## Description

In this format there is no Y plane, Only CbCr plane. ie (UV interleaved)

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


Cb<sub>00</sub>

</td>
<td>


Cr<sub>00</sub>

</td>
<td>


Cb<sub>01</sub>

</td>
<td>


Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>


start + 4:

</td>
<td>


Cb<sub>10</sub>

</td>
<td>


Cr<sub>10</sub>

</td>
<td>


Cb<sub>11</sub>

</td>
<td>


Cr<sub>11</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


Cb<sub>20</sub>

</td>
<td>


Cr<sub>20</sub>

</td>
<td>


Cb<sub>21</sub>

</td>
<td>


Cr<sub>21</sub>

</td>
</tr>
<tr>
<td>


start + 12:

</td>
<td>


Cb<sub>30</sub>

</td>
<td>


Cr<sub>30</sub>

</td>
<td>


Cb<sub>31</sub>

</td>
<td>


Cr<sub>31</sub>

</td>
</tr>
</tbody>
</table>

---

# Multi-planar format structures

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The struct v4l2_plane_pix_format structures define size and layout for each of the planes in a multi-planar format. The struct v4l2_pix_format_mplane structure contains information common to all planes (such as image width and height) and…

<a id="rst-multi-planar-format-structures"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The struct `v4l2_plane_pix_format` structures define size and layout for each of the planes in a multi-planar format. The struct `v4l2_pix_format_mplane` structure contains information common to all planes (such as image width and height) and an array of struct `v4l2_plane_pix_format` structures, describing all planes of that format.

<!-- tabularcolumns: |p{1.4cm}|p{4.0cm}|p{11.9cm}| -->

<a id="c-v4l2_plane_pix_format"></a>



```c
v4l2_plane_pix_format
```


<table>
<caption>

struct v4l2\_plane\_pix\_format

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`sizeimage`

</td>
<td>



Maximum size in bytes required for image data in this plane, set by the driver. When the image consists of variable length compressed data this is the number of bytes required by the codec to support the worst-case compression scenario.

The driver will set the value for uncompressed images.

Clients are allowed to set the sizeimage field for variable length compressed data flagged with `V4L2_FMT_FLAG_COMPRESSED` at [vidioc\_enum\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>), but the driver may ignore it and set the value itself, or it may modify the provided value based on alignment requirements or minimum/maximum size requirements. If the client wants to leave this to the driver, then it should set sizeimage to 0.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`bytesperline`

</td>
<td>



Distance in bytes between the leftmost pixels in two adjacent lines. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`reserved[6]`

</td>
<td>



Reserved for future extensions. Should be zeroed by drivers and applications.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{4.4cm}|p{5.6cm}|p{7.3cm}| -->

<a id="c-v4l2_pix_format_mplane"></a>



```c
v4l2_pix_format_mplane
```


<table>
<caption>

struct v4l2\_pix\_format\_mplane

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`width`

</td>
<td>



Image width in pixels. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`height`

</td>
<td>



Image height in pixels. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`pixelformat`

</td>
<td>



The pixel format. Both single- and multi-planar four character codes can be used.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`field`

</td>
<td>



Field order, from enum `v4l2_field`. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`colorspace`

</td>
<td>



Colorspace encoding, from enum `v4l2_colorspace`. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



struct `v4l2_plane_pix_format`

</td>
<td>



`plane_fmt[VIDEO_MAX_PLANES]`

</td>
<td>



An array of structures describing format of each plane this pixel format consists of. The number of valid entries in this array has to be put in the `num_planes` field.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`num_planes`

</td>
<td>



Number of planes (i.e. separate memory buffers) for this format and the number of valid entries in the `plane_fmt` array.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



Flags set by the application or driver, see [format-flags](</kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#rst-format-flags>).

</td>
</tr>
<tr>
<td>



union \{

</td>
<td colspan="2">



(anonymous)

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`ycbcr_enc`

</td>
<td>



Y'CbCr encoding, from enum `v4l2_ycbcr_encoding`. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`hsv_enc`

</td>
<td>



HSV encoding, from enum `v4l2_hsv_encoding`. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



\}

</td>
<td colspan="2">





</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`quantization`

</td>
<td>



Quantization range, from enum `v4l2_quantization`. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`xfer_func`

</td>
<td>



Transfer function, from enum `v4l2_xfer_func`. See struct `v4l2_pix_format`.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved[7]`

</td>
<td>



Reserved for future extensions. Should be zeroed by drivers and applications.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

---

# Single-planar format structure

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Single-planar format structure.

<a id="rst-single-planar-format-structure"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<!-- tabularcolumns: |p{4.0cm}|p{2.6cm}|p{10.7cm}| -->





<a id="c-v4l2_pix_format"></a>

```c
v4l2_pix_format
```


<table>
<caption>struct v4l2_pix_format</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`width`

</td>
<td>


Image width in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`height`

</td>
<td>


Image height in pixels. If `field` is one of `V4L2_FIELD_TOP`, `V4L2_FIELD_BOTTOM` or `V4L2_FIELD_ALTERNATE` then height refers to the number of lines in the field, otherwise it refers to the number of lines in the frame (which is twice the field height for interlaced formats).

</td>
</tr>
<tr>
<td colspan="3">


 Applications set these fields to request an image size, drivers return the closest possible values. In case of planar formats the `width` and `height` applies to the largest plane. To avoid ambiguities drivers must return values rounded up to a multiple of the scale factor of any smaller planes. For example when the image format is YUV 4:2:0, `width` and `height` must be multiples of two.

For compressed formats that contain the resolution information encoded inside the stream, when fed to a stateful mem2mem decoder, the fields may be zero to rely on the decoder to detect the right values. For more details see [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder>) and format descriptions.

For compressed formats on the CAPTURE side of a stateful mem2mem encoder, the fields must be zero, since the coded size is expected to be calculated internally by the encoder itself, based on the OUTPUT side. For more details see [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>) and format descriptions.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pixelformat`

</td>
<td>


The pixel format or type of compression, set by the application. This is a little endian [four character code](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-v4l2-fourcc>). V4L2 defines standard RGB formats in [pixfmt-rgb](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-rgb.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), YUV formats in [YUV Formats](</kernel/userspace/userspace-api/media-v4l/yuv-formats.md#rst-yuv-formats>), and reserved codes in [reserved-formats](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`field`

</td>
<td>


Field order, from enum `v4l2_field`. Video images are typically interlaced. Applications can request to capture or output only the top or bottom field, or both fields interlaced or sequentially stored in one buffer or alternating in separate buffers. Drivers return the actual field order selected. For more details on fields see [Field Order](</kernel/userspace/userspace-api/media-v4l/field-order.md#rst-field-order>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`bytesperline`

</td>
<td>


Distance in bytes between the leftmost pixels in two adjacent lines.

</td>
</tr>
<tr>
<td colspan="3">


Both applications and drivers can set this field to request padding bytes at the end of each line. Drivers however may ignore the value requested by the application, returning `width` times bytes per pixel or a larger value required by the hardware. That implies applications can just set this field to zero to get a reasonable default.

Video hardware may access padding bytes, therefore they must reside in accessible memory. Consider cases where padding bytes after the last line of an image cross a system page boundary. Input devices may write padding bytes, the value is undefined. Output devices ignore the contents of padding bytes.

When the image format is planar the `bytesperline` value applies to the first plane and is divided by the same factor as the `width` field for the other planes. For example the Cb and Cr planes of a YUV 4:2:0 image have half as many padding bytes following each line as the Y plane. To avoid ambiguities drivers must return a `bytesperline` value rounded up to a multiple of the scale factor.

For compressed formats the `bytesperline` value makes no sense. Applications and drivers must set this to 0 in that case.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`sizeimage`

</td>
<td>


Size in bytes of the buffer to hold a complete image, set by the driver. Usually this is `bytesperline` times `height`. When the image consists of variable length compressed data this is the number of bytes required by the codec to support the worst-case compression scenario.

The driver will set the value for uncompressed images.

Clients are allowed to set the sizeimage field for variable length compressed data flagged with `V4L2_FMT_FLAG_COMPRESSED` at [ioctl VIDIOC_ENUM_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>), but the driver may ignore it and set the value itself, or it may modify the provided value based on alignment requirements or minimum/maximum size requirements. If the client wants to leave this to the driver, then it should set sizeimage to 0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`colorspace`

</td>
<td>


Image colorspace, from enum `v4l2_colorspace`. This information supplements the `pixelformat` and must be set by the driver for capture streams and by the application for output streams, see [Colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_PIX_FMT_FLAG_SET_CSC` then the application can set this field for a capture stream to request a specific colorspace for the captured image data. If the driver cannot handle requested conversion, it will return another supported colorspace. The driver indicates that colorspace conversion is supported by setting the flag V4L2_FMT_FLAG_CSC_COLORSPACE in the corresponding struct `v4l2_fmtdesc` during enumeration. See [fmtdesc-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`priv`

</td>
<td>


This field indicates whether the remaining fields of the struct `v4l2_pix_format`, also called the extended fields, are valid. When set to `V4L2_PIX_FMT_PRIV_MAGIC`, it indicates that the extended fields have been correctly initialized. When set to any other value it indicates that the extended fields contain undefined values.

Applications that wish to use the pixel format extended fields must first ensure that the feature is supported by querying the device for the [V4L2_CAP_EXT_PIX_FORMAT](</kernel/userspace/userspace-api/media-v4l/querycap.md#rst-querycap>) capability. If the capability isn't set the pixel format extended fields are not supported and using the extended fields will lead to undefined results.

To use the extended fields, applications must set the `priv` field to `V4L2_PIX_FMT_PRIV_MAGIC`, initialize all the extended fields and zero the unused bytes of the struct `v4l2_format` `raw_data` field.

When the `priv` field isn't set to `V4L2_PIX_FMT_PRIV_MAGIC` drivers must act as if all the extended fields were set to zero. On return drivers must set the `priv` field to `V4L2_PIX_FMT_PRIV_MAGIC` and all the extended fields to applicable values.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags set by the application or driver, see [format-flags](<#rst-format-flags>).

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


(anonymous)

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`ycbcr_enc`

</td>
<td>


Y'CbCr encoding, from enum `v4l2_ycbcr_encoding`. This information supplements the `colorspace` and must be set by the driver for capture streams and by the application for output streams, see [Colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_PIX_FMT_FLAG_SET_CSC` then the application can set this field for a capture stream to request a specific Y'CbCr encoding for the captured image data. If the driver cannot handle requested conversion, it will return another supported encoding. This field is ignored for HSV pixelformats. The driver indicates that ycbcr_enc conversion is supported by setting the flag V4L2_FMT_FLAG_CSC_YCBCR_ENC in the corresponding struct `v4l2_fmtdesc` during enumeration. See [fmtdesc-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`hsv_enc`

</td>
<td>


HSV encoding, from enum `v4l2_hsv_encoding`. This information supplements the `colorspace` and must be set by the driver for capture streams and by the application for output streams, see [Colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_PIX_FMT_FLAG_SET_CSC` then the application can set this field for a capture stream to request a specific HSV encoding for the captured image data. If the driver cannot handle requested conversion, it will return another supported encoding. This field is ignored for non-HSV pixelformats. The driver indicates that hsv_enc conversion is supported by setting the flag V4L2_FMT_FLAG_CSC_HSV_ENC in the corresponding struct `v4l2_fmtdesc` during enumeration. See [fmtdesc-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags>).

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`quantization`

</td>
<td>


Quantization range, from enum `v4l2_quantization`. This information supplements the `colorspace` and must be set by the driver for capture streams and by the application for output streams, see [Colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_PIX_FMT_FLAG_SET_CSC` then the application can set this field for a capture stream to request a specific quantization range for the captured image data. If the driver cannot handle requested conversion, it will return another supported quantization. The driver indicates that quantization conversion is supported by setting the flag V4L2_FMT_FLAG_CSC_QUANTIZATION in the corresponding struct `v4l2_fmtdesc` during enumeration. See [fmtdesc-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`xfer_func`

</td>
<td>


Transfer function, from enum `v4l2_xfer_func`. This information supplements the `colorspace` and must be set by the driver for capture streams and by the application for output streams, see [Colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_PIX_FMT_FLAG_SET_CSC` then the application can set this field for a capture stream to request a specific transfer function for the captured image data. If the driver cannot handle requested conversion, it will return another supported transfer function. The driver indicates that xfer_func conversion is supported by setting the flag V4L2_FMT_FLAG_CSC_XFER_FUNC in the corresponding struct `v4l2_fmtdesc` during enumeration. See [fmtdesc-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags>).

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.8cm}|p{2.3cm}|p{8.2cm}| -->

<a id="rst-format-flags"></a>


<table>
<caption>Format Flags</caption>
<tbody>
<tr>
<td>


`V4L2_PIX_FMT_FLAG_PREMUL_ALPHA`

</td>
<td>


0x00000001

</td>
<td>


The color values are premultiplied by the alpha channel value. For example, if a light blue pixel with 50% transparency was described by RGBA values (128, 192, 255, 128), the same pixel described with premultiplied colors would be described by RGBA values (64, 96, 128, 128)

</td>
</tr>
<tr>
<td>


`V4L2_PIX_FMT_FLAG_SET_CSC`

</td>
<td>


0x00000002

</td>
<td>


<a id="rst-v4l2-pix-fmt-flag-set-csc"></a>

Set by the application. It is only used for capture and is ignored for output streams. If set, then request the device to do colorspace conversion from the received colorspace to the requested colorspace values. If the colorimetry field (`colorspace`, `xfer_func`, `ycbcr_enc`, `hsv_enc` or `quantization`) is set to `*_DEFAULT`, then that colorimetry setting will remain unchanged from what was received. So in order to change the quantization, only the `quantization` field shall be set to non default value (`V4L2_QUANTIZATION_FULL_RANGE` or `V4L2_QUANTIZATION_LIM_RANGE`) and all other colorimetry fields shall be set to `*_DEFAULT`.

To check which conversions are supported by the hardware for the current pixel format, see [fmtdesc-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags>).

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_Y12I ('Y12I')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Interleaved grey-scale image, e.g. from a stereo-pair

<a id="rst-v4l2-pix-fmt-y12i-y12i"></a>
<a id="rst-v4l2-pix-fmt-y12i"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Interleaved grey-scale image, e.g. from a stereo-pair

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

## Description

This is a grey-scale image with a depth of 12 bits per pixel, but with pixels from 2 sources interleaved and bit-packed. Each pixel is stored in a 24-bit word in the little-endian order. On a little-endian machine these pixels can be deinterlaced using



```c
__u8 *buf;
left0 = 0xfff & *(__u16 *)buf;
right0 = *(__u16 *)(buf + 1) >> 4;
```

**Bit-packed representation.** pixels cross the byte boundary and have a ratio of 3 bytes for each interleaved pixel.


<table>
<tbody>
<tr>
<td>


Y'<sub>0left[7:0]</sub>

</td>
<td>


Y'<sub>0right[3:0]</sub>Y'<sub>0left[11:8]</sub>

</td>
<td>


Y'<sub>0right[11:4]</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_Y16I ('Y16I')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Interleaved grey-scale image, e.g. from a stereo-pair

<a id="rst-v4l2-pix-fmt-y16i-y16i"></a>
<a id="rst-v4l2-pix-fmt-y16i"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Interleaved grey-scale image, e.g. from a stereo-pair

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

## Description

This is a grey-scale image with a depth of 16 bits per pixel, but with pixels from 2 sources interleaved and unpacked. Each pixel is stored in a 16-bit word in the little-endian order. The first pixel is from the left source.

**Pixel unpacked representation.** Left/Right pixels 16-bit unpacked - 16-bit for each interleaved pixel.


<table>
<tbody>
<tr>
<td>


Y'<sub>0L[7:0]</sub>

</td>
<td>


Y'<sub>0L[15:8]</sub>

</td>
<td>


Y'<sub>0R[7:0]</sub>

</td>
<td>


Y'<sub>0R[15:8]</sub>

</td>
</tr>
</tbody>
</table>

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


Y'<sub>00Llow</sub>

</td>
<td>


Y'<sub>00Lhigh</sub>

</td>
<td>


Y'<sub>00Rlow</sub>

</td>
<td>


Y'<sub>00Rhigh</sub>

</td>
<td>


Y'<sub>01Llow</sub>

</td>
<td>


Y'<sub>01Lhigh</sub>

</td>
<td>


Y'<sub>01Rlow</sub>

</td>
<td>


Y'<sub>01Rhigh</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


Y'<sub>10Llow</sub>

</td>
<td>


Y'<sub>10Lhigh</sub>

</td>
<td>


Y'<sub>10Rlow</sub>

</td>
<td>


Y'<sub>10Rhigh</sub>

</td>
<td>


Y'<sub>11Llow</sub>

</td>
<td>


Y'<sub>11Lhigh</sub>

</td>
<td>


Y'<sub>11Rlow</sub>

</td>
<td>


Y'<sub>11Rhigh</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


Y'<sub>20Llow</sub>

</td>
<td>


Y'<sub>20Lhigh</sub>

</td>
<td>


Y'<sub>20Rlow</sub>

</td>
<td>


Y'<sub>20Rhigh</sub>

</td>
<td>


Y'<sub>21Llow</sub>

</td>
<td>


Y'<sub>21Lhigh</sub>

</td>
<td>


Y'<sub>21Rlow</sub>

</td>
<td>


Y'<sub>21Rhigh</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


Y'<sub>30Llow</sub>

</td>
<td>


Y'<sub>30Lhigh</sub>

</td>
<td>


Y'<sub>30Rlow</sub>

</td>
<td>


Y'<sub>30Rhigh</sub>

</td>
<td>


Y'<sub>31Llow</sub>

</td>
<td>


Y'<sub>31Lhigh</sub>

</td>
<td>


Y'<sub>31Rlow</sub>

</td>
<td>


Y'<sub>31Rhigh</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_Y8I ('Y8I ')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Interleaved grey-scale image, e.g. from a stereo-pair

<a id="rst-v4l2-pix-fmt-y8i-y8i"></a>
<a id="rst-v4l2-pix-fmt-y8i"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Interleaved grey-scale image, e.g. from a stereo-pair

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

## Description

This is a grey-scale image with a depth of 8 bits per pixel, but with pixels from 2 sources interleaved. Each pixel is stored in a 16-bit word. E.g. the R200 RealSense camera stores pixel from the left sensor in lower and from the right sensor in the higher 8 bits.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


Y'<sub>00left</sub>

</td>
<td>


Y'<sub>00right</sub>

</td>
<td>


Y'<sub>01left</sub>

</td>
<td>


Y'<sub>01right</sub>

</td>
<td>


Y'<sub>02left</sub>

</td>
<td>


Y'<sub>02right</sub>

</td>
<td>


Y'<sub>03left</sub>

</td>
<td>


Y'<sub>03right</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


Y'<sub>10left</sub>

</td>
<td>


Y'<sub>10right</sub>

</td>
<td>


Y'<sub>11left</sub>

</td>
<td>


Y'<sub>11right</sub>

</td>
<td>


Y'<sub>12left</sub>

</td>
<td>


Y'<sub>12right</sub>

</td>
<td>


Y'<sub>13left</sub>

</td>
<td>


Y'<sub>13right</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


Y'<sub>20left</sub>

</td>
<td>


Y'<sub>20right</sub>

</td>
<td>


Y'<sub>21left</sub>

</td>
<td>


Y'<sub>21right</sub>

</td>
<td>


Y'<sub>22left</sub>

</td>
<td>


Y'<sub>22right</sub>

</td>
<td>


Y'<sub>23left</sub>

</td>
<td>


Y'<sub>23right</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


Y'<sub>30left</sub>

</td>
<td>


Y'<sub>30right</sub>

</td>
<td>


Y'<sub>31left</sub>

</td>
<td>


Y'<sub>31right</sub>

</td>
<td>


Y'<sub>32left</sub>

</td>
<td>


Y'<sub>32right</sub>

</td>
<td>


Y'<sub>33left</sub>

</td>
<td>


Y'<sub>33right</sub>

</td>
</tr>
</tbody>
</table>

---

# Luma-Only Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> This family of formats only store the luma component of a Y'CbCr image. They are often referred to as greyscale formats.

<a id="rst-luma-only-formats"></a>
<a id="rst-yuv-luma-only"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

This family of formats only store the luma component of a Y'CbCr image. They are often referred to as greyscale formats.

> [!NOTE]
>
> - In all the tables that follow, bit 7 is the most significant bit in a byte.
>
> - Formats are described with the minimum number of pixels needed to create a byte-aligned repeating pattern. `...` indicates repetition of the pattern.
>
> - Y'<sub>x</sub>\[9:2\] denotes bits 9 to 2 of the Y' value for pixel at column `x`.
>
> - `0` denotes padding bits set to 0.

<!-- Source LaTeX layout: \tiny -->

<!-- tabularcolumns: |p{3.6cm}|p{2.4cm}|p{1.3cm}|p{1.3cm}|p{1.3cm}|p{1.3cm}|p{1.3cm}|p{1.3cm}|p{1.3cm}| -->


<table>
<caption>

Luma-Only Image Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Byte 0

</th>
<th>



Byte 1

</th>
<th>



Byte 2

</th>
<th>



Byte 3

</th>
<th>



Byte 4

</th>
<th>



Byte 5

</th>
<th>



Byte 6

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_PIX_FMT_GREY`

</td>
<td>



'GREY'

</td>
<td>



Y'<sub>0</sub>\[7:0\]

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-grey"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_IPU3_Y10`

</td>
<td>



'ip3y'

</td>
<td>



Y'<sub>0</sub>\[7:0\]

</td>
<td>



Y'<sub>1</sub>\[5:0\] Y'<sub>0</sub>\[9:8\]

</td>
<td>



Y'<sub>2</sub>\[3:0\] Y'<sub>1</sub>\[9:6\]

</td>
<td>



Y'<sub>3</sub>\[1:0\] Y'<sub>2</sub>\[9:4\]

</td>
<td>



Y'<sub>3</sub>\[9:2\]

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-ipu3-y10"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y10`

</td>
<td>



'Y10 '

</td>
<td>



Y'<sub>0</sub>\[7:0\]

</td>
<td>



`000000` Y'<sub>0</sub>\[9:8\]

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y10"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y10BPACK`

</td>
<td>



'Y10B'

</td>
<td>



Y'<sub>0</sub>\[9:2\]

</td>
<td>



Y'<sub>0</sub>\[1:0\] Y'<sub>1</sub>\[9:4\]

</td>
<td>



Y'<sub>1</sub>\[3:0\] Y'<sub>2</sub>\[9:6\]

</td>
<td>



Y'<sub>2</sub>\[5:0\] Y'<sub>3</sub>\[9:8\]

</td>
<td>



Y'<sub>3</sub>\[7:0\]

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y10bpack"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y10P`

</td>
<td>



'Y10P'

</td>
<td>



Y'<sub>0</sub>\[9:2\]

</td>
<td>



Y'<sub>1</sub>\[9:2\]

</td>
<td>



Y'<sub>2</sub>\[9:2\]

</td>
<td>



Y'<sub>3</sub>\[9:2\]

</td>
<td>



Y'<sub>3</sub>\[1:0\] Y'<sub>2</sub>\[1:0\] Y'<sub>1</sub>\[1:0\] Y'<sub>0</sub>\[1:0\]

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y10p"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y12`

</td>
<td>



'Y12 '

</td>
<td>



Y'<sub>0</sub>\[7:0\]

</td>
<td>



`0000` Y'<sub>0</sub>\[11:8\]

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y12"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y012`

</td>
<td>



'Y012'

</td>
<td>



Y'<sub>0</sub>\[3:0\] `0000`

</td>
<td>



Y'<sub>0</sub>\[11:4\]

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y012"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y12P`

</td>
<td>



'Y12P'

</td>
<td>



Y'<sub>0</sub>\[11:4\]

</td>
<td>



Y'<sub>1</sub>\[11:4\]

</td>
<td>



Y'<sub>1</sub>\[3:0\] Y'<sub>0</sub>\[3:0\]

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y12p"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y14`

</td>
<td>



'Y14 '

</td>
<td>



Y'<sub>0</sub>\[7:0\]

</td>
<td>



`00` Y'<sub>0</sub>\[13:8\]

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y14"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y14P`

</td>
<td>



'Y14P'

</td>
<td>



Y'<sub>0</sub>\[13:6\]

</td>
<td>



Y'<sub>1</sub>\[13:6\]

</td>
<td>



Y'<sub>2</sub>\[13:6\]

</td>
<td>



Y'<sub>3</sub>\[13:6\]

</td>
<td>



Y'<sub>1</sub>\[1:0\] Y'<sub>0</sub>\[5:0\]

</td>
<td>



Y'<sub>2</sub>\[3:0\] Y'<sub>1</sub>\[5:2\]

</td>
<td>



<a id="rst-v4l2-pix-fmt-y14p"></a>

Y'<sub>3</sub>\[5:0\] Y'<sub>2</sub>\[5:4\]

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y16`

</td>
<td>



'Y16 '

</td>
<td>



Y'<sub>0</sub>\[7:0\]

</td>
<td>



Y'<sub>0</sub>\[15:8\]

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y16"></a>

...

</td>
</tr>
<tr>
<td>



`V4L2_PIX_FMT_Y16_BE`

</td>
<td>



'Y16 ' \| (1U &lt;&lt; 31)

</td>
<td>



Y'<sub>0</sub>\[15:8\]

</td>
<td>



Y'<sub>0</sub>\[7:0\]

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



...

</td>
<td>



<a id="rst-v4l2-pix-fmt-y16-be"></a>

...

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

> [!NOTE]
>
> For the Y16 and Y16\_BE formats, the actual sampling precision may be lower than 16 bits. For example, 10 bits per pixel uses values in the range 0 to 1023. For the IPU3\_Y10 format 25 pixels are packed into 32 bytes, which leaves the 6 most significant bits of the last byte padded with 0.
>
> For Y012 and Y12 formats, Y012 places its data in the 12 high bits, with padding zeros in the 4 low bits, in contrast to the Y12 format, which has its padding located in the most significant bits of the 16 bit word.
>
> The 'P' variations of the Y10, Y12 and Y14 formats are packed according to the RAW10, RAW12 and RAW14 packing scheme as defined by the MIPI CSI-2 specification.

---

# Planar YUV formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Planar formats split luma and chroma data in separate memory regions. They exist in two variants:

<a id="rst-planar-yuv-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<!-- planar-yuv: -->

Planar formats split luma and chroma data in separate memory regions. They exist in two variants:

- Semi-planar formats use two planes. The first plane is the luma plane and stores the Y components. The second plane is the chroma plane and stores the Cb and Cr components interleaved.

- Fully planar formats use three planes to store the Y, Cb and Cr components separately.

Within a plane, components are stored in pixel order, which may be linear or tiled. Padding may be supported at the end of the lines, and the line stride of the chroma planes may be constrained by the line stride of the luma plane.

Some planar formats allow planes to be placed in independent memory locations. They are identified by an 'M' suffix in their name (such as in `V4L2_PIX_FMT_NV12M`). Those formats are intended to be used only in drivers and applications that support the multi-planar API, described in [planar-apis](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>). Unless explicitly documented as supporting non-contiguous planes, formats require the planes to follow each other immediately in memory.

<a id="rst-semi-planar-yuv-formats"></a>

## Semi-Planar YUV Formats

These formats are commonly referred to as NV formats (NV12, NV16, ...). They use two planes, and store the luma components in the first plane and the chroma components in the second plane. The Cb and Cr components are interleaved in the chroma plane, with Cb and Cr always stored in pairs. The chroma order is exposed as different formats.

For memory contiguous formats, the number of padding pixels at the end of the chroma lines is identical to the padding of the luma lines. Without horizontal subsampling, the chroma line stride (in bytes) is thus equal to twice the luma line stride. With horizontal subsampling by 2, the chroma line stride is equal to the luma line stride. Vertical subsampling doesn't affect the line stride.

For non-contiguous formats, no constraints are enforced by the format on the relationship between the luma and chroma line padding and stride.

All components are stored with the same number of bits per component.

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{5.2cm}|p{1.0cm}|p{1.5cm}|p{1.9cm}|p{1.2cm}|p{1.8cm}|p{2.7cm}| -->


<table>
<caption>

Overview of Semi-Planar YUV Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Bits per component

</th>
<th>



Subsampling

</th>
<th>



Chroma order <a id="rst-footnote-reference-1"></a>[1](#rst-footnote-1)

</th>
<th>



Contiguous <a id="rst-footnote-reference-2"></a>[2](#rst-footnote-2)

</th>
<th>



Tiling <a id="rst-footnote-reference-3"></a>[3](#rst-footnote-3)

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



V4L2\_PIX\_FMT\_NV12

</td>
<td>



'NV12'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV21

</td>
<td>



'NV21'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Cr, Cb

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV12M

</td>
<td>



'NM12'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



No

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV21M

</td>
<td>



'NM21'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Cr, Cb

</td>
<td>



No

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV12MT

</td>
<td>



'TM12'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



No

</td>
<td>



64x32 tiles

Horizontal Z order

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV12MT\_16X16

</td>
<td>



'VM12'

</td>
<td>



8

</td>
<td>



4:2:2

</td>
<td>



Cb, Cr

</td>
<td>



No

</td>
<td>



16x16 tiles

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_P010

</td>
<td>



'P010'

</td>
<td>



10

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_P010\_4L4

</td>
<td>



'T010'

</td>
<td>



10

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



4x4 tiles

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_P012

</td>
<td>



'P012'

</td>
<td>



12

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_P012M

</td>
<td>



'PM12'

</td>
<td>



12

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



No

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV15

</td>
<td>



'NV15'

</td>
<td>



10

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV15\_4L4

</td>
<td>



'VT15'

</td>
<td>



15

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



4x4 tiles

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_MT2110T

</td>
<td>



'MT2T'

</td>
<td>



15

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



No

</td>
<td>



16x32 / 16x16 tiles tiled low bits

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_MT2110R

</td>
<td>



'MT2R'

</td>
<td>



15

</td>
<td>



4:2:0

</td>
<td>



Cb, Cr

</td>
<td>



No

</td>
<td>



16x32 / 16x16 tiles raster low bits

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV16

</td>
<td>



'NV16'

</td>
<td>



8

</td>
<td>



4:2:2

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV61

</td>
<td>



'NV61'

</td>
<td>



8

</td>
<td>



4:2:2

</td>
<td>



Cr, Cb

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV16M

</td>
<td>



'NM16'

</td>
<td>



8

</td>
<td>



4:2:2

</td>
<td>



Cb, Cr

</td>
<td>



No

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV61M

</td>
<td>



'NM61'

</td>
<td>



8

</td>
<td>



4:2:2

</td>
<td>



Cr, Cb

</td>
<td>



No

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV20

</td>
<td>



'NV20'

</td>
<td>



10

</td>
<td>



4:2:2

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV24

</td>
<td>



'NV24'

</td>
<td>



8

</td>
<td>



4:4:4

</td>
<td>



Cb, Cr

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_NV42

</td>
<td>



'NV42'

</td>
<td>



8

</td>
<td>



4:4:4

</td>
<td>



Cr, Cb

</td>
<td>



Yes

</td>
<td>



Linear

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-footnote-1"></a>



**[1]** Order of chroma samples in the second plane

<a id="rst-footnote-2"></a>



**[2]** Indicates if planes have to be contiguous in memory or can be disjoint

<a id="rst-footnote-3"></a>



**[3]** Macroblock size in pixels

<strong>Color Sample Location:</strong> Chroma samples are [interstitially sited](</kernel/userspace/userspace-api/media-v4l/yuv-formats.md#rst-yuv-chroma-centered>) horizontally.

<a id="rst-nv12-nv21-nv12m-and-nv21m"></a>
<a id="rst-v4l2-pix-fmt-p010"></a>
<a id="rst-v4l2-pix-fmt-nv21m"></a>
<a id="rst-v4l2-pix-fmt-nv12m"></a>
<a id="rst-v4l2-pix-fmt-nv21"></a>
<a id="rst-v4l2-pix-fmt-nv12"></a>

### NV12, NV21, NV12M and NV21M

Semi-planar YUV 4:2:0 formats. The chroma plane is subsampled by 2 in each direction. Chroma lines contain half the number of pixels and the same number of bytes as luma lines, and the chroma plane contains half the number of lines of the luma plane.


<table>
<caption>

Sample 4x4 NV12 Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cb<sub>01</sub>

</td>
<td>



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start + 20:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cb<sub>11</sub>

</td>
<td>



Cr<sub>11</sub>

</td>
</tr>
</tbody>
</table>


<table>
<caption>

Sample 4x4 NV12M Image

</caption>
<tbody>
<tr>
<td>



start0 + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start0 + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start0 + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start0 + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start1 + 0:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cb<sub>01</sub>

</td>
<td>



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start1 + 4:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cb<sub>11</sub>

</td>
<td>



Cr<sub>11</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-nv15"></a>
<a id="rst-v4l2-pix-fmt-nv15"></a>

### NV15

Semi-planar 10-bit YUV 4:2:0 format similar to NV12, using 10-bit components with no padding between each component. A group of 4 components are stored over 5 bytes in little endian order.


<table>
<caption>

Sample 4x4 NV15 Image (1 byte per cell)

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00[7:0]</sub>

</td>
<td>



Y'<sub>01[5:0]</sub>Y'<sub>00[9:8]</sub>

</td>
<td>



Y'<sub>02[3:0]</sub>Y'<sub>01[9:6]</sub>

</td>
<td>



Y'<sub>03[1:0]</sub>Y'<sub>02[9:4]</sub>

</td>
<td>



Y'<sub>03[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 5:

</td>
<td>



Y'<sub>10[7:0]</sub>

</td>
<td>



Y'<sub>11[5:0]</sub>Y'<sub>10[9:8]</sub>

</td>
<td>



Y'<sub>12[3:0]</sub>Y'<sub>11[9:6]</sub>

</td>
<td>



Y'<sub>13[1:0]</sub>Y'<sub>12[9:4]</sub>

</td>
<td>



Y'<sub>13[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 10:

</td>
<td>



Y'<sub>20[7:0]</sub>

</td>
<td>



Y'<sub>21[5:0]</sub>Y'<sub>20[9:8]</sub>

</td>
<td>



Y'<sub>22[3:0]</sub>Y'<sub>21[9:6]</sub>

</td>
<td>



Y'<sub>23[1:0]</sub>Y'<sub>22[9:4]</sub>

</td>
<td>



Y'<sub>23[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 15:

</td>
<td>



Y'<sub>30[7:0]</sub>

</td>
<td>



Y'<sub>31[5:0]</sub>Y'<sub>30[9:8]</sub>

</td>
<td>



Y'<sub>32[3:0]</sub>Y'<sub>31[9:6]</sub>

</td>
<td>



Y'<sub>33[1:0]</sub>Y'<sub>32[9:4]</sub>

</td>
<td>



Y'<sub>33[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 20:

</td>
<td>



Cb<sub>00[7:0]</sub>

</td>
<td>



Cr<sub>00[5:0]</sub>Cb<sub>00[9:8]</sub>

</td>
<td>



Cb<sub>01[3:0]</sub>Cr<sub>00[9:6]</sub>

</td>
<td>



Cr<sub>01[1:0]</sub>Cb<sub>01[9:4]</sub>

</td>
<td>



Cr<sub>01[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 25:

</td>
<td>



Cb<sub>10[7:0]</sub>

</td>
<td>



Cr<sub>10[5:0]</sub>Cb<sub>10[9:8]</sub>

</td>
<td>



Cb<sub>11[3:0]</sub>Cr<sub>10[9:6]</sub>

</td>
<td>



Cr<sub>11[1:0]</sub>Cb<sub>11[9:4]</sub>

</td>
<td>



Cr<sub>11[9:2]</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-tiled-nv12"></a>
<a id="rst-v4l2-pix-fmt-mm21"></a>
<a id="rst-v4l2-pix-fmt-nv12-8l128"></a>
<a id="rst-v4l2-pix-fmt-nv12m-8l128"></a>
<a id="rst-v4l2-pix-fmt-nv12-32l32"></a>
<a id="rst-v4l2-pix-fmt-nv12-16l16"></a>
<a id="rst-v4l2-pix-fmt-nv12-4l4"></a>
<a id="rst-v4l2-pix-fmt-nv12mt-16x16"></a>
<a id="rst-v4l2-pix-fmt-nv12mt"></a>

### Tiled NV12

Semi-planar YUV 4:2:0 formats, using macroblock tiling. The chroma plane is subsampled by 2 in each direction. Chroma lines contain half the number of pixels and the same number of bytes as luma lines, and the chroma plane contains half the number of lines of the luma plane. Each tile follows the previous one linearly in memory (from left to right, top to bottom).

`V4L2_PIX_FMT_NV12MT_16X16` is similar to `V4L2_PIX_FMT_NV12M` but stores pixels in 2D 16x16 tiles, and stores tiles linearly in memory. The line stride and image height must be aligned to a multiple of 16. The layouts of the luma and chroma planes are identical.

`V4L2_PIX_FMT_NV12MT` is similar to `V4L2_PIX_FMT_NV12M` but stores pixels in 2D 64x32 tiles, and stores 2x2 groups of tiles in Z-order in memory, alternating Z and mirrored Z shapes horizontally. The line stride must be a multiple of 128 pixels to ensure an integer number of Z shapes. The image height must be a multiple of 32 pixels. If the vertical resolution is an odd number of tiles, the last row of tiles is stored in linear order. The layouts of the luma and chroma planes are identical.

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

![nv12mt.svg](/kernel/userspace/userspace-api/media-v4l/asset-70ffa23a98d5-nv12mt.svg)

V4L2\_PIX\_FMT\_NV12MT macroblock Z shape memory layout

<a id="rst-nv12mt-ex"></a>

![nv12mt\_example.svg](/kernel/userspace/userspace-api/media-v4l/asset-50c764b8e1f0-nv12mt-example.svg)

Example V4L2\_PIX\_FMT\_NV12MT memory layout of tiles

`V4L2_PIX_FMT_NV12_4L4` stores pixels in 4x4 tiles, and stores tiles linearly in memory. The line stride and image height must be aligned to a multiple of 4. The layouts of the luma and chroma planes are identical.

`V4L2_PIX_FMT_NV12_16L16` stores pixels in 16x16 tiles, and stores tiles linearly in memory. The line stride and image height must be aligned to a multiple of 16. The layouts of the luma and chroma planes are identical.

`V4L2_PIX_FMT_NV12_32L32` stores pixels in 32x32 tiles, and stores tiles linearly in memory. The line stride and image height must be aligned to a multiple of 32. The layouts of the luma and chroma planes are identical.

`V4L2_PIX_FMT_NV12M_8L128` is similar to `V4L2_PIX_FMT_NV12M` but stores pixels in 2D 8x128 tiles, and stores tiles linearly in memory. The image height must be aligned to a multiple of 128. The layouts of the luma and chroma planes are identical.

`V4L2_PIX_FMT_NV12_8L128` is similar to `V4L2_PIX_FMT_NV12M_8L128` but stores two planes in one memory.

`V4L2_PIX_FMT_MM21` store luma pixel in 16x32 tiles, and chroma pixels in 16x16 tiles. The line stride must be aligned to a multiple of 16 and the image height must be aligned to a multiple of 32. The number of luma and chroma tiles are identical, even though the tile size differ. The image is formed of two non-contiguous planes.

<a id="rst-tiled-nv15"></a>
<a id="rst-v4l2-pix-fmt-mt2110r"></a>
<a id="rst-v4l2-pix-fmt-mt2110t"></a>
<a id="rst-v4l2-pix-fmt-nv12-10be-8l128"></a>
<a id="rst-v4l2-pix-fmt-nv12m-10be-8l128"></a>
<a id="rst-v4l2-pix-fmt-nv15-4l4"></a>

### Tiled NV15

`V4L2_PIX_FMT_NV15_4L4` Semi-planar 10-bit YUV 4:2:0 formats, using 4x4 tiling. All components are packed without any padding between each other. As a side-effect, each group of 4 components are stored over 5 bytes (YYYY or UVUV = 4 \* 10 bits = 40 bits = 5 bytes).

`V4L2_PIX_FMT_NV12M_10BE_8L128` is similar to `V4L2_PIX_FMT_NV12M` but stores 10 bits pixels in 2D 8x128 tiles, and stores tiles linearly in memory. the data is arranged in big endian order. The image height must be aligned to a multiple of 128. The layouts of the luma and chroma planes are identical. Note the tile size is 8bytes multiplied by 128 bytes, it means that the low bits and high bits of one pixel may be in different tiles. The 10 bit pixels are packed, so 5 bytes contain 4 10-bit pixels layout like this (for luma): byte 0: Y0(bits 9-2) byte 1: Y0(bits 1-0) Y1(bits 9-4) byte 2: Y1(bits 3-0) Y2(bits 9-6) byte 3: Y2(bits 5-0) Y3(bits 9-8) byte 4: Y3(bits 7-0)

`V4L2_PIX_FMT_NV12_10BE_8L128` is similar to `V4L2_PIX_FMT_NV12M_10BE_8L128` but stores two planes in one memory.

`V4L2_PIX_FMT_MT2110T` is one of Mediatek packed 10bit YUV 4:2:0 formats. It is fully packed 10bit 4:2:0 format like NV15 (15 bits per pixel), except that the lower two bits data is stored in separate partitions. The format is composed of 16x32 luma tiles, and 16x16 chroma tiles. Each tiles is 640 bytes long, divided into 8 partitions of 80 bytes.  The first 16 bytes of the partition represent the 2 least significant bits of pixel data. The remaining 64 bytes represent the 8 most significant bits of pixel data.

![mt2110t.svg](/kernel/userspace/userspace-api/media-v4l/asset-1ad1dc24475e-mt2110t.svg)

Layout of MT2110T Chroma Tile

Filtering out the upper part of each partitions results in a valid `V4L2_PIX_FMT_MM21` frame. A partition is a sub-tile of size 16 x 4. The lower two bits is said to be tiled since each bytes contains the lower two bits of the column of for pixel matching the same index. The chroma tiles only have 4 partitions.


<table>
<caption>

MT2110T LSB bits layout

</caption>
<thead>
<tr>
<th>





</th>
<th>



start + 0:

</th>
<th>



start + 1:

</th>
<th>



. . .

</th>
<th>



start+15:

</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">



Bits 1:0

</th>
<td>



Y'<sub>0:0</sub>

</td>
<td>



Y'<sub>0:1</sub>

</td>
<td>



. . .

</td>
<td>



Y'<sub>0:15</sub>

</td>
</tr>
<tr>
<th scope="row">



Bit 3:2

</th>
<td>



Y'<sub>1:0</sub>

</td>
<td>



Y'<sub>1:1</sub>

</td>
<td>



. . .

</td>
<td>



Y'<sub>1:15</sub>

</td>
</tr>
<tr>
<th scope="row">



Bits 5:4

</th>
<td>



Y'<sub>2:0</sub>

</td>
<td>



Y'<sub>2:1</sub>

</td>
<td>



. . .

</td>
<td>



Y'<sub>2:15</sub>

</td>
</tr>
<tr>
<th scope="row">



Bits 7:6

</th>
<td>



Y'<sub>3:0</sub>

</td>
<td>



Y'<sub>3:1</sub>

</td>
<td>



. . .

</td>
<td>



Y'<sub>3:15</sub>

</td>
</tr>
</tbody>
</table>

`V4L2_PIX_FMT_MT2110R` is identical to `V4L2_PIX_FMT_MT2110T` except that the least significant two bits layout is in raster order. This means the first byte contains 4 pixels of the first row, with 4 bytes per line.


<table>
<caption>

MT2110R LSB bits layout

</caption>
<thead>
<tr>
<th>





</th>
<th colspan="4">



 Byte 0

</th>
<th>



...

</th>
<th colspan="4">



 Byte 3

</th>
</tr>
<tr>
<th>





</th>
<th>



7:6

</th>
<th>



5:4

</th>
<th>



3:2

</th>
<th>



1:0

</th>
<th>



...

</th>
<th>



7:6

</th>
<th>



5:4

</th>
<th>



3:2

</th>
<th>



1:0

</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">



start + 0:

</th>
<td>



Y'<sub>0:3</sub>

</td>
<td>



Y'<sub>0:2</sub>

</td>
<td>



Y'<sub>0:1</sub>

</td>
<td>



Y'<sub>0:0</sub>

</td>
<td>



...

</td>
<td>



Y'<sub>0:15</sub>

</td>
<td>



Y'<sub>0:14</sub>

</td>
<td>



Y'<sub>0:13</sub>

</td>
<td>



Y'<sub>0:12</sub>

</td>
</tr>
<tr>
<th scope="row">



start + 4:

</th>
<td>



Y'<sub>1:3</sub>

</td>
<td>



Y'<sub>1:2</sub>

</td>
<td>



Y'<sub>1:1</sub>

</td>
<td>



Y'<sub>1:0</sub>

</td>
<td>



...

</td>
<td>



Y'<sub>1:15</sub>

</td>
<td>



Y'<sub>1:14</sub>

</td>
<td>



Y'<sub>1:13</sub>

</td>
<td>



Y'<sub>1:12</sub>

</td>
</tr>
<tr>
<th scope="row">



start + 8:

</th>
<td>



Y'<sub>2:3</sub>

</td>
<td>



Y'<sub>2:2</sub>

</td>
<td>



Y'<sub>2:1</sub>

</td>
<td>



Y'<sub>2:0</sub>

</td>
<td>



...

</td>
<td>



Y'<sub>2:15</sub>

</td>
<td>



Y'<sub>2:14</sub>

</td>
<td>



Y'<sub>2:13</sub>

</td>
<td>



Y'<sub>2:12</sub>

</td>
</tr>
<tr>
<th scope="row">



start+12:

</th>
<td>



Y'<sub>3:3</sub>

</td>
<td>



Y'<sub>3:2</sub>

</td>
<td>



Y'<sub>3:1</sub>

</td>
<td>



Y'<sub>3:0</sub>

</td>
<td>



...

</td>
<td>



Y'<sub>3:15</sub>

</td>
<td>



Y'<sub>3:14</sub>

</td>
<td>



Y'<sub>3:13</sub>

</td>
<td>



Y'<sub>3:12</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-nv16-nv61-nv16m-and-nv61m"></a>
<a id="rst-v4l2-pix-fmt-nv61m"></a>
<a id="rst-v4l2-pix-fmt-nv16m"></a>
<a id="rst-v4l2-pix-fmt-nv61"></a>
<a id="rst-v4l2-pix-fmt-nv16"></a>

### NV16, NV61, NV16M and NV61M

Semi-planar YUV 4:2:2 formats. The chroma plane is subsampled by 2 in the horizontal direction. Chroma lines contain half the number of pixels and the same number of bytes as luma lines, and the chroma plane contains the same number of lines as the luma plane.


<table>
<caption>

Sample 4x4 NV16 Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cb<sub>01</sub>

</td>
<td>



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start + 20:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cb<sub>11</sub>

</td>
<td>



Cr<sub>11</sub>

</td>
</tr>
<tr>
<td>



start + 24:

</td>
<td>



Cb<sub>20</sub>

</td>
<td>



Cr<sub>20</sub>

</td>
<td>



Cb<sub>21</sub>

</td>
<td>



Cr<sub>21</sub>

</td>
</tr>
<tr>
<td>



start + 28:

</td>
<td>



Cb<sub>30</sub>

</td>
<td>



Cr<sub>30</sub>

</td>
<td>



Cb<sub>31</sub>

</td>
<td>



Cr<sub>31</sub>

</td>
</tr>
</tbody>
</table>


<table>
<caption>

Sample 4x4 NV16M Image

</caption>
<tbody>
<tr>
<td>



start0 + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start0 + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start0 + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start0 + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start1 + 0:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cb<sub>02</sub>

</td>
<td>



Cr<sub>02</sub>

</td>
</tr>
<tr>
<td>



start1 + 4:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cb<sub>12</sub>

</td>
<td>



Cr<sub>12</sub>

</td>
</tr>
<tr>
<td>



start1 + 8:

</td>
<td>



Cb<sub>20</sub>

</td>
<td>



Cr<sub>20</sub>

</td>
<td>



Cb<sub>22</sub>

</td>
<td>



Cr<sub>22</sub>

</td>
</tr>
<tr>
<td>



start1 + 12:

</td>
<td>



Cb<sub>30</sub>

</td>
<td>



Cr<sub>30</sub>

</td>
<td>



Cb<sub>32</sub>

</td>
<td>



Cr<sub>32</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-nv20"></a>
<a id="rst-v4l2-pix-fmt-nv20"></a>

### NV20

Semi-planar 10-bit YUV 4:2:2 format similar to NV16, using 10-bit components with no padding between each component. A group of 4 components are stored over 5 bytes in little endian order.


<table>
<caption>

Sample 4x4 NV20 Image (1 byte per cell)

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00[7:0]</sub>

</td>
<td>



Y'<sub>01[5:0]</sub>Y'<sub>00[9:8]</sub>

</td>
<td>



Y'<sub>02[3:0]</sub>Y'<sub>01[9:6]</sub>

</td>
<td>



Y'<sub>03[1:0]</sub>Y'<sub>02[9:4]</sub>

</td>
<td>



Y'<sub>03[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 5:

</td>
<td>



Y'<sub>10[7:0]</sub>

</td>
<td>



Y'<sub>11[5:0]</sub>Y'<sub>10[9:8]</sub>

</td>
<td>



Y'<sub>12[3:0]</sub>Y'<sub>11[9:6]</sub>

</td>
<td>



Y'<sub>13[1:0]</sub>Y'<sub>12[9:4]</sub>

</td>
<td>



Y'<sub>13[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 10:

</td>
<td>



Y'<sub>20[7:0]</sub>

</td>
<td>



Y'<sub>21[5:0]</sub>Y'<sub>20[9:8]</sub>

</td>
<td>



Y'<sub>22[3:0]</sub>Y'<sub>21[9:6]</sub>

</td>
<td>



Y'<sub>23[1:0]</sub>Y'<sub>22[9:4]</sub>

</td>
<td>



Y'<sub>23[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 15:

</td>
<td>



Y'<sub>30[7:0]</sub>

</td>
<td>



Y'<sub>31[5:0]</sub>Y'<sub>30[9:8]</sub>

</td>
<td>



Y'<sub>32[3:0]</sub>Y'<sub>31[9:6]</sub>

</td>
<td>



Y'<sub>33[1:0]</sub>Y'<sub>32[9:4]</sub>

</td>
<td>



Y'<sub>33[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 20:

</td>
<td>



Cb<sub>00[7:0]</sub>

</td>
<td>



Cr<sub>00[5:0]</sub>Cb<sub>00[9:8]</sub>

</td>
<td>



Cb<sub>01[3:0]</sub>Cr<sub>00[9:6]</sub>

</td>
<td>



Cr<sub>01[1:0]</sub>Cb<sub>01[9:4]</sub>

</td>
<td>



Cr<sub>01[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 25:

</td>
<td>



Cb<sub>10[7:0]</sub>

</td>
<td>



Cr<sub>10[5:0]</sub>Cb<sub>10[9:8]</sub>

</td>
<td>



Cb<sub>11[3:0]</sub>Cr<sub>10[9:6]</sub>

</td>
<td>



Cr<sub>11[1:0]</sub>Cb<sub>11[9:4]</sub>

</td>
<td>



Cr<sub>11[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 30:

</td>
<td>



Cb<sub>20[7:0]</sub>

</td>
<td>



Cr<sub>20[5:0]</sub>Cb<sub>20[9:8]</sub>

</td>
<td>



Cb<sub>21[3:0]</sub>Cr<sub>20[9:6]</sub>

</td>
<td>



Cr<sub>21[1:0]</sub>Cb<sub>21[9:4]</sub>

</td>
<td>



Cr<sub>21[9:2]</sub>

</td>
</tr>
<tr>
<td>



start + 35:

</td>
<td>



Cb<sub>30[7:0]</sub>

</td>
<td>



Cr<sub>30[5:0]</sub>Cb<sub>30[9:8]</sub>

</td>
<td>



Cb<sub>31[3:0]</sub>Cr<sub>30[9:6]</sub>

</td>
<td>



Cr<sub>31[1:0]</sub>Cb<sub>31[9:4]</sub>

</td>
<td>



Cr<sub>31[9:2]</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-nv24-and-nv42"></a>
<a id="rst-v4l2-pix-fmt-nv42"></a>
<a id="rst-v4l2-pix-fmt-nv24"></a>

### NV24 and NV42

Semi-planar YUV 4:4:4 formats. The chroma plane is not subsampled. Chroma lines contain the same number of pixels and twice the number of bytes as luma lines, and the chroma plane contains the same number of lines as the luma plane.


<table>
<caption>

Sample 4x4 NV24 Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td colspan="5">



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td colspan="5">



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td colspan="5">



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td colspan="5">



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cb<sub>01</sub>

</td>
<td>



Cr<sub>01</sub>

</td>
<td>



Cb<sub>02</sub>

</td>
<td>



Cr<sub>02</sub>

</td>
<td>



Cb<sub>03</sub>

</td>
<td>



Cr<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 24:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cb<sub>11</sub>

</td>
<td>



Cr<sub>11</sub>

</td>
<td>



Cb<sub>12</sub>

</td>
<td>



Cr<sub>12</sub>

</td>
<td>



Cb<sub>13</sub>

</td>
<td>



Cr<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 32:

</td>
<td>



Cb<sub>20</sub>

</td>
<td>



Cr<sub>20</sub>

</td>
<td>



Cb<sub>21</sub>

</td>
<td>



Cr<sub>21</sub>

</td>
<td>



Cb<sub>22</sub>

</td>
<td>



Cr<sub>22</sub>

</td>
<td>



Cb<sub>23</sub>

</td>
<td>



Cr<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 40:

</td>
<td>



Cb<sub>30</sub>

</td>
<td>



Cr<sub>30</sub>

</td>
<td>



Cb<sub>31</sub>

</td>
<td>



Cr<sub>31</sub>

</td>
<td>



Cb<sub>32</sub>

</td>
<td>



Cr<sub>32</sub>

</td>
<td>



Cb<sub>33</sub>

</td>
<td>



Cr<sub>33</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-p010-and-tiled-p010"></a>
<a id="rst-v4l2-pix-fmt-p010-4l4"></a>
<a id="rst-v4l2-pix-fmt-p010-1"></a>

### P010 and tiled P010

P010 is like NV12 with 10 bits per component, expanded to 16 bits. Data in the 10 high bits, zeros in the 6 low bits, arranged in little endian order.


<table>
<caption>

Sample 4x4 P010 Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 24:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 32:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cb<sub>01</sub>

</td>
<td>



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start + 40:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cb<sub>11</sub>

</td>
<td>



Cr<sub>11</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-p012-and-p012m"></a>
<a id="rst-v4l2-pix-fmt-p012m"></a>
<a id="rst-v4l2-pix-fmt-p012"></a>

### P012 and P012M

P012 is like NV12 with 12 bits per component, expanded to 16 bits. Data in the 12 high bits, zeros in the 4 low bits, arranged in little endian order.


<table>
<caption>

Sample 4x4 P012 Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 24:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 32:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cb<sub>01</sub>

</td>
<td>



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start + 40:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cb<sub>11</sub>

</td>
<td>



Cr<sub>11</sub>

</td>
</tr>
</tbody>
</table>


<table>
<caption>

Sample 4x4 P012M Image

</caption>
<tbody>
<tr>
<td>



start0 + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start0 + 8:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start0 + 16:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start0 + 24:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start1 + 0:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cb<sub>01</sub>

</td>
<td>



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start1 + 8:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cb<sub>11</sub>

</td>
<td>



Cr<sub>11</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-fully-planar-yuv-formats"></a>

## Fully Planar YUV Formats

These formats store the Y, Cb and Cr components in three separate planes. The luma plane comes first, and the order of the two chroma planes varies between formats. The two chroma planes always use the same subsampling.

For memory contiguous formats, the number of padding pixels at the end of the chroma lines is identical to the padding of the luma lines. The chroma line stride (in bytes) is thus equal to the luma line stride divided by the horizontal subsampling factor. Vertical subsampling doesn't affect the line stride.

For non-contiguous formats, no constraints are enforced by the format on the relationship between the luma and chroma line padding and stride.

All components are stored with the same number of bits per component.

`V4L2_PIX_FMT_P010_4L4` stores pixels in 4x4 tiles, and stores tiles linearly in memory. The line stride must be aligned to multiple of 8 and image height to a multiple of 4. The layouts of the luma and chroma planes are identical.

<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{5.0cm}|p{1.1cm}|p{1.5cm}|p{2.2cm}|p{1.2cm}|p{3.7cm}| -->


<table>
<caption>

Overview of Fully Planar YUV Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Bits per component

</th>
<th>



Subsampling

</th>
<th>



Planes order <a id="rst-footnote-reference-4"></a>[4](#rst-footnote-4)

</th>
<th>



Contiguous <a id="rst-footnote-reference-5"></a>[5](#rst-footnote-5)

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



V4L2\_PIX\_FMT\_YUV410

</td>
<td>



'YUV9'

</td>
<td>



8

</td>
<td>



4:1:0

</td>
<td>



Y, Cb, Cr

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YVU410

</td>
<td>



'YVU9'

</td>
<td>



8

</td>
<td>



4:1:0

</td>
<td>



Y, Cr, Cb

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YUV411P

</td>
<td>



'411P'

</td>
<td>



8

</td>
<td>



4:1:1

</td>
<td>



Y, Cb, Cr

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YUV420M

</td>
<td>



'YM12'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Y, Cb, Cr

</td>
<td>



No

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YVU420M

</td>
<td>



'YM21'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Y, Cr, Cb

</td>
<td>



No

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YUV420

</td>
<td>



'YU12'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Y, Cb, Cr

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YVU420

</td>
<td>



'YV12'

</td>
<td>



8

</td>
<td>



4:2:0

</td>
<td>



Y, Cr, Cb

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YUV422P

</td>
<td>



'422P'

</td>
<td>



8

</td>
<td>



4:2:2

</td>
<td>



Y, Cb, Cr

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YUV422M

</td>
<td>



'YM16'

</td>
<td>



8

</td>
<td>



4:2:2

</td>
<td>



Y, Cb, Cr

</td>
<td>



No

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YVU422M

</td>
<td>



'YM61'

</td>
<td>



8

</td>
<td>



4:2:2

</td>
<td>



Y, Cr, Cb

</td>
<td>



No

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YUV444M

</td>
<td>



'YM24'

</td>
<td>



8

</td>
<td>



4:4:4

</td>
<td>



Y, Cb, Cr

</td>
<td>



No

</td>
</tr>
<tr>
<td>



V4L2\_PIX\_FMT\_YVU444M

</td>
<td>



'YM42'

</td>
<td>



8

</td>
<td>



4:4:4

</td>
<td>



Y, Cr, Cb

</td>
<td>



No

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-footnote-4"></a>



**[4]** Order of luma and chroma planes

<a id="rst-footnote-5"></a>



**[5]** Indicates if planes have to be contiguous in memory or can be disjoint

<strong>Color Sample Location:</strong> Chroma samples are [interstitially sited](</kernel/userspace/userspace-api/media-v4l/yuv-formats.md#rst-yuv-chroma-centered>) horizontally.

<a id="rst-yuv410-and-yvu410"></a>
<a id="rst-v4l2-pix-fmt-yvu410"></a>
<a id="rst-v4l2-pix-fmt-yuv410"></a>

### YUV410 and YVU410

Planar YUV 4:1:0 formats. The chroma planes are subsampled by 4 in each direction. Chroma lines contain a quarter of the number of pixels and bytes of the luma lines, and the chroma planes contain a quarter of the number of lines of the luma plane.


<table>
<caption>

Sample 4x4 YUV410 Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td colspan="4">



Cr<sub>00</sub>

</td>
</tr>
<tr>
<td>



start + 17:

</td>
<td colspan="4">



Cb<sub>00</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-yuv411p"></a>
<a id="rst-v4l2-pix-fmt-yuv411p"></a>

### YUV411P

Planar YUV 4:1:1 formats. The chroma planes are subsampled by 4 in the horizontal direction. Chroma lines contain a quarter of the number of pixels and bytes of the luma lines, and the chroma planes contain the same number of lines as the luma plane.


<table>
<caption>

Sample 4x4 YUV411P Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td colspan="4">



Cb<sub>00</sub>

</td>
</tr>
<tr>
<td>



start + 17:

</td>
<td colspan="4">



Cb<sub>10</sub>

</td>
</tr>
<tr>
<td>



start + 18:

</td>
<td colspan="4">



Cb<sub>20</sub>

</td>
</tr>
<tr>
<td>



start + 19:

</td>
<td colspan="4">



Cb<sub>30</sub>

</td>
</tr>
<tr>
<td>



start + 20:

</td>
<td colspan="4">



Cr<sub>00</sub>

</td>
</tr>
<tr>
<td>



start + 21:

</td>
<td colspan="4">



Cr<sub>10</sub>

</td>
</tr>
<tr>
<td>



start + 22:

</td>
<td colspan="4">



Cr<sub>20</sub>

</td>
</tr>
<tr>
<td>



start + 23:

</td>
<td colspan="4">



Cr<sub>30</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-yuv420-yvu420-yuv420m-and-yvu420m"></a>
<a id="rst-v4l2-pix-fmt-yvu420m"></a>
<a id="rst-v4l2-pix-fmt-yuv420m"></a>
<a id="rst-v4l2-pix-fmt-yvu420"></a>
<a id="rst-v4l2-pix-fmt-yuv420"></a>

### YUV420, YVU420, YUV420M and YVU420M

Planar YUV 4:2:0 formats. The chroma planes are subsampled by 2 in each direction. Chroma lines contain half of the number of pixels and bytes of the luma lines, and the chroma planes contain half of the number of lines of the luma plane.


<table>
<caption>

Sample 4x4 YUV420 Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td>



Cr<sub>00</sub>

</td>
<td colspan="3">



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start + 18:

</td>
<td>



Cr<sub>10</sub>

</td>
<td colspan="3">



Cr<sub>11</sub>

</td>
</tr>
<tr>
<td>



start + 20:

</td>
<td>



Cb<sub>00</sub>

</td>
<td colspan="3">



Cb<sub>01</sub>

</td>
</tr>
<tr>
<td>



start + 22:

</td>
<td>



Cb<sub>10</sub>

</td>
<td colspan="3">



Cb<sub>11</sub>

</td>
</tr>
</tbody>
</table>


<table>
<caption>

Sample 4x4 YUV420M Image

</caption>
<tbody>
<tr>
<td>



start0 + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start0 + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start0 + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start0 + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start1 + 0:

</td>
<td>



Cb<sub>00</sub>

</td>
<td colspan="3">



Cb<sub>01</sub>

</td>
</tr>
<tr>
<td>



start1 + 2:

</td>
<td>



Cb<sub>10</sub>

</td>
<td colspan="3">



Cb<sub>11</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start2 + 0:

</td>
<td>



Cr<sub>00</sub>

</td>
<td colspan="3">



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start2 + 2:

</td>
<td>



Cr<sub>10</sub>

</td>
<td colspan="3">



Cr<sub>11</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-yuv422p-yuv422m-and-yvu422m"></a>
<a id="rst-v4l2-pix-fmt-yvu422m"></a>
<a id="rst-v4l2-pix-fmt-yuv422m"></a>
<a id="rst-v4l2-pix-fmt-yuv422p"></a>

### YUV422P, YUV422M and YVU422M

Planar YUV 4:2:2 formats. The chroma planes are subsampled by 2 in the horizontal direction. Chroma lines contain half of the number of pixels and bytes of the luma lines, and the chroma planes contain the same number of lines as the luma plane.


<table>
<caption>

Sample 4x4 YUV422P Image

</caption>
<tbody>
<tr>
<td>



start + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td>



start + 16:

</td>
<td>



Cb<sub>00</sub>

</td>
<td colspan="3">



Cb<sub>01</sub>

</td>
</tr>
<tr>
<td>



start + 18:

</td>
<td>



Cb<sub>10</sub>

</td>
<td colspan="3">



Cb<sub>11</sub>

</td>
</tr>
<tr>
<td>



start + 20:

</td>
<td>



Cb<sub>20</sub>

</td>
<td colspan="3">



Cb<sub>21</sub>

</td>
</tr>
<tr>
<td>



start + 22:

</td>
<td>



Cb<sub>30</sub>

</td>
<td colspan="3">



Cb<sub>31</sub>

</td>
</tr>
<tr>
<td>



start + 24:

</td>
<td>



Cr<sub>00</sub>

</td>
<td colspan="3">



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start + 26:

</td>
<td>



Cr<sub>10</sub>

</td>
<td colspan="3">



Cr<sub>11</sub>

</td>
</tr>
<tr>
<td>



start + 28:

</td>
<td>



Cr<sub>20</sub>

</td>
<td colspan="3">



Cr<sub>21</sub>

</td>
</tr>
<tr>
<td>



start + 30:

</td>
<td>



Cr<sub>30</sub>

</td>
<td colspan="3">



Cr<sub>31</sub>

</td>
</tr>
</tbody>
</table>


<table>
<caption>

Sample 4x4 YUV422M Image

</caption>
<tbody>
<tr>
<td>



start0 + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start0 + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start0 + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start0 + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start1 + 0:

</td>
<td>



Cb<sub>00</sub>

</td>
<td colspan="3">



Cb<sub>01</sub>

</td>
</tr>
<tr>
<td>



start1 + 2:

</td>
<td>



Cb<sub>10</sub>

</td>
<td colspan="3">



Cb<sub>11</sub>

</td>
</tr>
<tr>
<td>



start1 + 4:

</td>
<td>



Cb<sub>20</sub>

</td>
<td colspan="3">



Cb<sub>21</sub>

</td>
</tr>
<tr>
<td>



start1 + 6:

</td>
<td>



Cb<sub>30</sub>

</td>
<td colspan="3">



Cb<sub>31</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start2 + 0:

</td>
<td>



Cr<sub>00</sub>

</td>
<td colspan="3">



Cr<sub>01</sub>

</td>
</tr>
<tr>
<td>



start2 + 2:

</td>
<td>



Cr<sub>10</sub>

</td>
<td colspan="3">



Cr<sub>11</sub>

</td>
</tr>
<tr>
<td>



start2 + 4:

</td>
<td>



Cr<sub>20</sub>

</td>
<td colspan="3">



Cr<sub>21</sub>

</td>
</tr>
<tr>
<td>



start2 + 6:

</td>
<td>



Cr<sub>30</sub>

</td>
<td colspan="3">



Cr<sub>31</sub>

</td>
</tr>
</tbody>
</table>

<a id="rst-yuv444m-and-yvu444m"></a>
<a id="rst-v4l2-pix-fmt-yvu444m"></a>
<a id="rst-v4l2-pix-fmt-yuv444m"></a>

### YUV444M and YVU444M

Planar YUV 4:4:4 formats. The chroma planes are no subsampled. Chroma lines contain the same number of pixels and bytes of the luma lines, and the chroma planes contain the same number of lines as the luma plane.


<table>
<caption>

Sample 4x4 YUV444M Image

</caption>
<tbody>
<tr>
<td>



start0 + 0:

</td>
<td>



Y'<sub>00</sub>

</td>
<td>



Y'<sub>01</sub>

</td>
<td>



Y'<sub>02</sub>

</td>
<td>



Y'<sub>03</sub>

</td>
</tr>
<tr>
<td>



start0 + 4:

</td>
<td>



Y'<sub>10</sub>

</td>
<td>



Y'<sub>11</sub>

</td>
<td>



Y'<sub>12</sub>

</td>
<td>



Y'<sub>13</sub>

</td>
</tr>
<tr>
<td>



start0 + 8:

</td>
<td>



Y'<sub>20</sub>

</td>
<td>



Y'<sub>21</sub>

</td>
<td>



Y'<sub>22</sub>

</td>
<td>



Y'<sub>23</sub>

</td>
</tr>
<tr>
<td>



start0 + 12:

</td>
<td>



Y'<sub>30</sub>

</td>
<td>



Y'<sub>31</sub>

</td>
<td>



Y'<sub>32</sub>

</td>
<td>



Y'<sub>33</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start1 + 0:

</td>
<td>



Cb<sub>00</sub>

</td>
<td>



Cb<sub>01</sub>

</td>
<td>



Cb<sub>02</sub>

</td>
<td>



Cb<sub>03</sub>

</td>
</tr>
<tr>
<td>



start1 + 4:

</td>
<td>



Cb<sub>10</sub>

</td>
<td>



Cb<sub>11</sub>

</td>
<td>



Cb<sub>12</sub>

</td>
<td>



Cb<sub>13</sub>

</td>
</tr>
<tr>
<td>



start1 + 8:

</td>
<td>



Cb<sub>20</sub>

</td>
<td>



Cb<sub>21</sub>

</td>
<td>



Cb<sub>22</sub>

</td>
<td>



Cb<sub>23</sub>

</td>
</tr>
<tr>
<td>



start1 + 12:

</td>
<td>



Cb<sub>20</sub>

</td>
<td>



Cb<sub>21</sub>

</td>
<td>



Cb<sub>32</sub>

</td>
<td>



Cb<sub>33</sub>

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>



start2 + 0:

</td>
<td>



Cr<sub>00</sub>

</td>
<td>



Cr<sub>01</sub>

</td>
<td>



Cr<sub>02</sub>

</td>
<td>



Cr<sub>03</sub>

</td>
</tr>
<tr>
<td>



start2 + 4:

</td>
<td>



Cr<sub>10</sub>

</td>
<td>



Cr<sub>11</sub>

</td>
<td>



Cr<sub>12</sub>

</td>
<td>



Cr<sub>13</sub>

</td>
</tr>
<tr>
<td>



start2 + 8:

</td>
<td>



Cr<sub>20</sub>

</td>
<td>



Cr<sub>21</sub>

</td>
<td>



Cr<sub>22</sub>

</td>
<td>



Cr<sub>23</sub>

</td>
</tr>
<tr>
<td>



start2 + 12:

</td>
<td>



Cr<sub>30</sub>

</td>
<td>



Cr<sub>31</sub>

</td>
<td>



Cr<sub>32</sub>

</td>
<td>



Cr<sub>33</sub>

</td>
</tr>
</tbody>
</table>

---

# V4L2_PIX_FMT_Z16 ('Z16 ')

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> 16-bit depth data with distance values at each pixel

<a id="rst-v4l2-pix-fmt-z16-z16"></a>
<a id="rst-v4l2-pix-fmt-z16"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

16-bit depth data with distance values at each pixel

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

## Description

This is a 16-bit format, representing depth data. Each pixel is a distance to the respective point in the image coordinates. Distance unit can vary and has to be negotiated with the device separately. Each pixel is stored in a 16-bit word in the little endian byte order.

**Byte Order.** Each cell is one byte.


<table>
<tbody>
<tr>
<td>


start + 0:

</td>
<td>


Z<sub>00low</sub>

</td>
<td>


Z<sub>00high</sub>

</td>
<td>


Z<sub>01low</sub>

</td>
<td>


Z<sub>01high</sub>

</td>
<td>


Z<sub>02low</sub>

</td>
<td>


Z<sub>02high</sub>

</td>
<td>


Z<sub>03low</sub>

</td>
<td>


Z<sub>03high</sub>

</td>
</tr>
<tr>
<td>


start + 8:

</td>
<td>


Z<sub>10low</sub>

</td>
<td>


Z<sub>10high</sub>

</td>
<td>


Z<sub>11low</sub>

</td>
<td>


Z<sub>11high</sub>

</td>
<td>


Z<sub>12low</sub>

</td>
<td>


Z<sub>12high</sub>

</td>
<td>


Z<sub>13low</sub>

</td>
<td>


Z<sub>13high</sub>

</td>
</tr>
<tr>
<td>


start + 16:

</td>
<td>


Z<sub>20low</sub>

</td>
<td>


Z<sub>20high</sub>

</td>
<td>


Z<sub>21low</sub>

</td>
<td>


Z<sub>21high</sub>

</td>
<td>


Z<sub>22low</sub>

</td>
<td>


Z<sub>22high</sub>

</td>
<td>


Z<sub>23low</sub>

</td>
<td>


Z<sub>23high</sub>

</td>
</tr>
<tr>
<td>


start + 24:

</td>
<td>


Z<sub>30low</sub>

</td>
<td>


Z<sub>30high</sub>

</td>
<td>


Z<sub>31low</sub>

</td>
<td>


Z<sub>31high</sub>

</td>
<td>


Z<sub>32low</sub>

</td>
<td>


Z<sub>32high</sub>

</td>
<td>


Z<sub>33low</sub>

</td>
<td>


Z<sub>33high</sub>

</td>
</tr>
</tbody>
</table>

---

# Image Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The V4L2 API was primarily designed for devices exchanging image data with applications. The struct v4l2_pix_format and struct v4l2_pix_format_mplane structures define the format and layout of an image in memory. The former is used with…

<a id="rst-image-formats"></a>
<a id="rst-pixfmt"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The V4L2 API was primarily designed for devices exchanging image data with applications. The struct `v4l2_pix_format` and struct `v4l2_pix_format_mplane` structures define the format and layout of an image in memory. The former is used with the single-planar API, while the latter is used with the multi-planar version (see [Single- and multi-planar APIs](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>)). Image formats are negotiated with the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl. (The explanations here focus on video capturing and output, for overlay frame buffer formats see also [VIDIOC_G_FBUF](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-fbuf.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).)

- [Single-planar format structure](</kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md>)
- [pixfmt-v4l2-mplane](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-v4l2-mplane.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Standard Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt-intro.md>)
- [Indexed Format](</kernel/userspace/userspace-api/media-v4l/pixfmt-indexed.md>)
- [pixfmt-rgb](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-rgb.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Raw Bayer Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt-bayer.md>)
- [YUV Formats](</kernel/userspace/userspace-api/media-v4l/yuv-formats.md>)
- [HSV Formats](</kernel/userspace/userspace-api/media-v4l/hsv-formats.md>)
- [Depth Formats](</kernel/userspace/userspace-api/media-v4l/depth-formats.md>)
- [pixfmt-compressed](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-compressed.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [SDR Formats](</kernel/userspace/userspace-api/media-v4l/sdr-formats.md>)
- [Touch Formats](</kernel/userspace/userspace-api/media-v4l/tch-formats.md>)
- [Metadata Formats](</kernel/userspace/userspace-api/media-v4l/meta-formats.md>)
- [pixfmt-reserved](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [Colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md>)
- [Defining Colorspaces in V4L2](</kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md>)
- [colorspaces-details](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/colorspaces-details.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

---

# Single- and multi-planar APIs

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Some devices require data for each input or output video frame to be placed in discontiguous memory buffers. In such cases, one video frame has to be addressed using more than one memory address, i.e. one pointer per "plane". A plane is a…

<a id="rst-single-and-multi-planar-apis"></a>
<a id="rst-planar-apis"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Some devices require data for each input or output video frame to be placed in discontiguous memory buffers. In such cases, one video frame has to be addressed using more than one memory address, i.e. one pointer per "plane". A plane is a sub-buffer of the current frame. For examples of such formats see [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>).

Initially, V4L2 API did not support multi-planar buffers and a set of extensions has been introduced to handle them. Those extensions constitute what is being referred to as the "multi-planar API".

Some of the V4L2 API calls and structures are interpreted differently, depending on whether single- or multi-planar API is being used. An application can choose whether to use one or the other by passing a corresponding buffer type to its ioctl calls. Multi-planar versions of buffer types are suffixed with an `_MPLANE` string. For a list of available multi-planar buffer types see enum `v4l2_buf_type`.

<a id="rst-multi-planar-formats"></a>

## Multi-planar formats

Multi-planar API introduces new multi-planar formats. Those formats use a separate set of FourCC codes. It is important to distinguish between the multi-planar API and a multi-planar format. Multi-planar API calls can handle all single-planar formats as well (as long as they are passed in multi-planar API structures), while the single-planar API cannot handle multi-planar formats.

<a id="rst-calls-that-distinguish-between-single-and-multi-planar-apis"></a>

## Calls that distinguish between single and multi-planar APIs

- **[VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>)**

  Two additional multi-planar capabilities are added. They can be set together with non-multi-planar ones for devices that handle both single- and multi-planar formats.

- **[VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>), [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>)**

  New structures for describing multi-planar formats are added: struct `v4l2_pix_format_mplane` and struct `v4l2_plane_pix_format`. Drivers may define new multi-planar formats, which have distinct FourCC codes from the existing single-planar ones.

- **[VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>)**

  A new struct `v4l2_plane` structure for describing planes is added. Arrays of this structure are passed in the new `m.planes` field of struct `v4l2_buffer`.

- **[VIDIOC_REQBUFS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)**

  Will allocate multi-planar buffers as requested.

---

# Querying Capabilities

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Because V4L2 covers a wide variety of devices not all aspects of the API are equally applicable to all types of devices. Furthermore devices of the same type have different capabilities and this specification permits the omission of a few…

<a id="rst-querying-capabilities"></a>
<a id="rst-querycap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Because V4L2 covers a wide variety of devices not all aspects of the API are equally applicable to all types of devices. Furthermore devices of the same type have different capabilities and this specification permits the omission of a few complicated and less important parts of the API.

The [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl is available to check if the kernel device is compatible with this specification, and to query the [functions](</kernel/userspace/userspace-api/media-v4l/devices.md#rst-devices>) and [I/O methods](</kernel/userspace/userspace-api/media-v4l/io.md#rst-io>) supported by the device.

Starting with kernel version 3.1, [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) will return the V4L2 API version used by the driver, with generally matches the Kernel version. There's no need of using [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) to check if a specific ioctl is supported, the V4L2 core now returns `ENOTTY` if a driver doesn't provide support for an ioctl.

Other features can be queried by calling the respective ioctl, for example [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) to learn about the number, types and names of video connectors on the device. Although abstraction is a major objective of this API, the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl also allows driver specific applications to reliably identify the driver.

All V4L2 drivers must support [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>). Applications should always call this ioctl after opening the device.

---

# Read/Write

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Input and output devices support the read() and write() function, respectively, when the V4L2_CAP_READWRITE flag in the capabilities field of struct v4l2_capability returned by the VIDIOC_QUERYCAP ioctl is set.

<a id="rst-read-write"></a>
<a id="rst-rw"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Input and output devices support the `read()` and `write()` function, respectively, when the `V4L2_CAP_READWRITE` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl is set.

Drivers may need the CPU to copy the data, but they may also support DMA to or from user memory, so this I/O method is not necessarily less efficient than other methods merely exchanging buffer pointers. It is considered inferior though because no meta-information like frame counters or timestamps are passed. This information is necessary to recognize frame dropping and to synchronize with other data streams. However this is also the simplest I/O method, requiring little or no setup to exchange data. It permits command line stunts like this (the vidctrl tool is fictitious):



```none
$ vidctrl /dev/video --input=0 --format=YUYV --size=352x288
$ dd if=/dev/video of=myimage.422 bs=202752 count=1
```

To read from the device applications use the `read()` function, to write the `write()` function. Drivers must implement one I/O method if they exchange data with applications, but it need not be this. <a id="rst-footnote-reference-1"></a>[1](#rst-f1) When reading or writing is supported, the driver must also support the `select()` and `poll()` function. <a id="rst-footnote-reference-2"></a>[2](#rst-f2)

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



**[1]** It would be desirable if applications could depend on drivers supporting all I/O interfaces, but as much as the complex memory mapping I/O can be inadequate for some devices we have no reason to require this interface, which is most useful for simple applications capturing still images.

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



**[2]** At the driver level `select()` and `poll()` are the same, and `select()` is too important to be optional.

---

# SDR Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These formats are used for SDR <sdr> interface only.

<a id="rst-sdr-formats-1"></a>
<a id="rst-sdr-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

These formats are used for [SDR](</kernel/userspace/userspace-api/media-v4l/dev-sdr.md#rst-sdr>) interface only.

- [V4L2_SDR_FMT_CU8 ('CU08')](</kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-cu08.md>)
- [V4L2_SDR_FMT_CU16LE ('CU16')](</kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-cu16le.md>)
- [V4L2_SDR_FMT_CS8 ('CS08')](</kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-cs08.md>)
- [V4L2_SDR_FMT_CS14LE ('CS14')](</kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-cs14le.md>)
- [V4L2_SDR_FMT_RU12LE ('RU12')](</kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-ru12le.md>)
- [V4L2_SDR_FMT_PCU16BE ('PC16')](</kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-pcu16be.md>)
- [V4L2_SDR_FMT_PCU18BE ('PC18')](</kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-pcu18be.md>)
- [V4L2_SDR_FMT_PCU20BE ('PC20')](</kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-pcu20be.md>)

---

# Configuration

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Applications can use the selection API <VIDIOC_G_SELECTION> to select an area in a video signal or a buffer, and to query for default settings and hardware limits.

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

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Applications can use the [selection API](</kernel/userspace/userspace-api/media-v4l/vidioc-g-selection.md#rst-vidioc-g-selection>) to select an area in a video signal or a buffer, and to query for default settings and hardware limits.

Video hardware can have various cropping, composing and scaling limitations. It may only scale up or down, support only discrete scaling factors, or have different scaling abilities in the horizontal and vertical directions. Also it may not support scaling at all. At the same time the cropping/composing rectangles may have to be aligned, and both the source and the sink may have arbitrary upper and lower size limits. Therefore, as usual, drivers are expected to adjust the requested parameters and return the actual values selected. An application can control the rounding behaviour using [constraint flags](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

<a id="rst-configuration-of-video-capture"></a>

## Configuration of video capture

See figure [sel-targets-capture](</kernel/userspace/userspace-api/media-v4l/selection-api-targets.md#rst-sel-targets-capture>) for examples of the selection targets available for a video capture device. It is recommended to configure the cropping targets before to the composing targets.

The range of coordinates of the top left corner, width and height of areas that can be sampled is given by the `V4L2_SEL_TGT_CROP_BOUNDS` target. It is recommended for the driver developers to put the top/left corner at position `(0,0)`. The rectangle's coordinates are expressed in pixels.

The top left corner, width and height of the source rectangle, that is the area actually sampled, is given by the `V4L2_SEL_TGT_CROP` target. It uses the same coordinate system as `V4L2_SEL_TGT_CROP_BOUNDS`. The active cropping area must lie completely inside the capture boundaries. The driver may further adjust the requested size and/or position according to hardware limitations.

Each capture device has a default source rectangle, given by the `V4L2_SEL_TGT_CROP_DEFAULT` target. This rectangle shall cover what the driver writer considers the complete picture. Drivers shall set the active crop rectangle to the default when the driver is first loaded, but not later.

The composing targets refer to a memory buffer. The limits of composing coordinates are obtained using `V4L2_SEL_TGT_COMPOSE_BOUNDS`. All coordinates are expressed in pixels. The rectangle's top/left corner must be located at position `(0,0)`. The width and height are equal to the image size set by [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>).

The part of a buffer into which the image is inserted by the hardware is controlled by the `V4L2_SEL_TGT_COMPOSE` target. The rectangle's coordinates are also expressed in the same coordinate system as the bounds rectangle. The composing rectangle must lie completely inside bounds rectangle. The driver must adjust the composing rectangle to fit to the bounding limits. Moreover, the driver can perform other adjustments according to hardware limitations. The application can control rounding behaviour using [constraint flags](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

For capture devices the default composing rectangle is queried using `V4L2_SEL_TGT_COMPOSE_DEFAULT`. It is usually equal to the bounding rectangle.

The part of a buffer that is modified by the hardware is given by `V4L2_SEL_TGT_COMPOSE_PADDED`. It contains all pixels defined using `V4L2_SEL_TGT_COMPOSE` plus all padding data modified by hardware during insertion process. All pixels outside this rectangle *must not* be changed by the hardware. The content of pixels that lie inside the padded area but outside active area is undefined. The application can use the padded and active rectangles to detect where the rubbish pixels are located and remove them if needed.

<a id="rst-configuration-of-video-output"></a>

## Configuration of video output

For output devices targets and ioctls are used similarly to the video capture case. The *composing* rectangle refers to the insertion of an image into a video signal. The cropping rectangles refer to a memory buffer. It is recommended to configure the composing targets before to the cropping targets.

The cropping targets refer to the memory buffer that contains an image to be inserted into a video signal or graphical screen. The limits of cropping coordinates are obtained using `V4L2_SEL_TGT_CROP_BOUNDS`. All coordinates are expressed in pixels. The top/left corner is always point `(0,0)`. The width and height is equal to the image size specified using [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl.

The top left corner, width and height of the source rectangle, that is the area from which image date are processed by the hardware, is given by the `V4L2_SEL_TGT_CROP`. Its coordinates are expressed in the same coordinate system as the bounds rectangle. The active cropping area must lie completely inside the crop boundaries and the driver may further adjust the requested size and/or position according to hardware limitations.

For output devices the default cropping rectangle is queried using `V4L2_SEL_TGT_CROP_DEFAULT`. It is usually equal to the bounding rectangle.

The part of a video signal or graphics display where the image is inserted by the hardware is controlled by `V4L2_SEL_TGT_COMPOSE` target. The rectangle's coordinates are expressed in pixels. The composing rectangle must lie completely inside the bounds rectangle. The driver must adjust the area to fit to the bounding limits. Moreover, the driver can perform other adjustments according to hardware limitations.

The device has a default composing rectangle, given by the `V4L2_SEL_TGT_COMPOSE_DEFAULT` target. This rectangle shall cover what the driver writer considers the complete picture. It is recommended for the driver developers to put the top/left corner at position `(0,0)`. Drivers shall set the active composing rectangle to the default one when the driver is first loaded.

The devices may introduce additional content to video signal other than an image from memory buffers. It includes borders around an image. However, such a padded area is driver-dependent feature not covered by this document. Driver developers are encouraged to keep padded rectangle equal to active one. The padded target is accessed by the `V4L2_SEL_TGT_COMPOSE_PADDED` identifier. It must contain all pixels from the `V4L2_SEL_TGT_COMPOSE` target.

<a id="rst-scaling-control"></a>

## Scaling control

An application can detect if scaling is performed by comparing the width and the height of rectangles obtained using `V4L2_SEL_TGT_CROP` and `V4L2_SEL_TGT_COMPOSE` targets. If these are not equal then the scaling is applied. The application can compute the scaling ratios using these values.

---

# Examples

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> (A video capture device is assumed; change V4L2_BUF_TYPE_VIDEO_CAPTURE for other devices; change target to V4L2_SEL_TGT_COMPOSE_* family to configure composing area)

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

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

(A video capture device is assumed; change `V4L2_BUF_TYPE_VIDEO_CAPTURE` for other devices; change target to `V4L2_SEL_TGT_COMPOSE_*` family to configure composing area)

<a id="rst-example-resetting-the-cropping-parameters"></a>

## Example: Resetting the cropping parameters



```c
struct v4l2_selection sel = {
    .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
    .target = V4L2_SEL_TGT_CROP_DEFAULT,
};
ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
if (ret)
    exit(-1);
sel.target = V4L2_SEL_TGT_CROP;
ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
if (ret)
    exit(-1);
```

Setting a composing area on output of size of *at most* half of limit placed at a center of a display.

<a id="rst-example-simple-downscaling"></a>

## Example: Simple downscaling



```c
struct v4l2_selection sel = {
    .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
    .target = V4L2_SEL_TGT_COMPOSE_BOUNDS,
};
struct v4l2_rect r;

ret = ioctl(fd, VIDIOC_G_SELECTION, &sel);
if (ret)
    exit(-1);
/* setting smaller compose rectangle */
r.width = sel.r.width / 2;
r.height = sel.r.height / 2;
r.left = sel.r.width / 4;
r.top = sel.r.height / 4;
sel.r = r;
sel.target = V4L2_SEL_TGT_COMPOSE;
sel.flags = V4L2_SEL_FLAG_LE;
ret = ioctl(fd, VIDIOC_S_SELECTION, &sel);
if (ret)
    exit(-1);
```

A video output device is assumed; change `V4L2_BUF_TYPE_VIDEO_OUTPUT` for other devices

<a id="rst-example-querying-for-scaling-factors"></a>

## Example: Querying for scaling factors



```c
struct v4l2_selection compose = {
    .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
    .target = V4L2_SEL_TGT_COMPOSE,
};
struct v4l2_selection crop = {
    .type = V4L2_BUF_TYPE_VIDEO_OUTPUT,
    .target = V4L2_SEL_TGT_CROP,
};
double hscale, vscale;

ret = ioctl(fd, VIDIOC_G_SELECTION, &compose);
if (ret)
    exit(-1);
ret = ioctl(fd, VIDIOC_G_SELECTION, &crop);
if (ret)
    exit(-1);

/* computing scaling factors */
hscale = (double)compose.r.width / crop.r.width;
vscale = (double)compose.r.height / crop.r.height;
```

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Some video capture devices can sample a subsection of a picture and shrink or enlarge it to an image of arbitrary size. Next, the devices can insert the image into larger one. Some video output devices can crop part of an input image,…

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

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Some video capture devices can sample a subsection of a picture and shrink or enlarge it to an image of arbitrary size. Next, the devices can insert the image into larger one. Some video output devices can crop part of an input image, scale it up or down and insert it at an arbitrary scan line and horizontal offset into a video signal. We call these abilities cropping, scaling and composing.

On a video *capture* device the source is a video signal, and the cropping target determine the area actually sampled. The sink is an image stored in a memory buffer. The composing area specifies which part of the buffer is actually written to by the hardware.

On a video *output* device the source is an image in a memory buffer, and the cropping target is a part of an image to be shown on a display. The sink is the display or the graphics screen. The application may select the part of display where the image should be displayed. The size and position of such a window is controlled by the compose target.

Rectangles for all cropping and composing targets are defined even if the device does supports neither cropping nor composing. Their size and position will be fixed in such a case. If the device does not support scaling then the cropping and composing rectangles have the same size.

---

# Selection targets

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Targets used by a cropping, composing and scaling process

<a id="rst-selection-targets"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-sel-targets-capture"></a>

![selection.svg](/kernel/userspace/userspace-api/media-v4l/asset-2930bf87f08e-selection.svg)

Cropping and composing targets

Targets used by a cropping, composing and scaling process

See [v4l2-selection-targets](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for more information.

---

# Comparison with old cropping API

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The selection API was introduced to cope with deficiencies of the older CROP API <crop>, that was designed to control simple capture devices. Later the cropping API was adopted by video output drivers. The ioctls are used to select a part…

<a id="rst-comparison-with-old-cropping-api"></a>
<a id="rst-selection-vs-crop"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The selection API was introduced to cope with deficiencies of the older [CROP API](</kernel/userspace/userspace-api/media-v4l/crop.md#rst-crop>), that was designed to control simple capture devices. Later the cropping API was adopted by video output drivers. The ioctls are used to select a part of the display were the video signal is inserted. It should be considered as an API abuse because the described operation is actually the composing. The selection API makes a clear distinction between composing and cropping operations by setting the appropriate targets.

The CROP API lacks any support for composing to and cropping from an image inside a memory buffer. The application could configure a capture device to fill only a part of an image by abusing V4L2 API. Cropping a smaller image from a larger one is achieved by setting the field `bytesperline` at struct `v4l2_pix_format`. Introducing an image offsets could be done by modifying field `m_userptr` at struct `v4l2_buffer` before calling [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>). Those operations should be avoided because they are not portable (endianness), and do not work for macroblock and Bayer formats and mmap buffers.

The selection API deals with configuration of buffer cropping/composing in a clear, intuitive and portable way. Next, with the selection API the concepts of the padded target and constraints flags are introduced. Finally, struct `v4l2_crop` and struct `v4l2_cropcap` have no reserved fields. Therefore there is no way to extend their functionality. The new struct `v4l2_selection` provides a lot of place for future extensions.

Driver developers are encouraged to implement only selection API. The former cropping API would be simulated using the new one.

---

# Cropping, composing and scaling -- the SELECTION API

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Cropping, composing and scaling -- the SELECTION API.

<a id="rst-cropping-composing-and-scaling-the-selection-api"></a>
<a id="rst-selection-api"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

- [Introduction](</kernel/userspace/userspace-api/media-v4l/selection-api-intro.md>)
- [Selection targets](</kernel/userspace/userspace-api/media-v4l/selection-api-targets.md>)
- [Configuration](</kernel/userspace/userspace-api/media-v4l/selection-api-configuration.md>)
- [Comparison with old cropping API](</kernel/userspace/userspace-api/media-v4l/selection-api-vs-crop-api.md>)
- [Examples](</kernel/userspace/userspace-api/media-v4l/selection-api-examples.md>)

---

# Common selection definitions

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> While the V4L2 selection API <selection-api> and V4L2 subdev selection APIs <v4l2-subdev-selections> are very similar, there's one fundamental difference between the two. On sub-device API, the selection rectangle refers to the media bus…

<a id="rst-common-selection-definitions"></a>
<a id="rst-v4l2-selections-common"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

While the [V4L2 selection API](</kernel/userspace/userspace-api/media-v4l/selection-api.md#rst-selection-api>) and [V4L2 subdev selection APIs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-subdev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) are very similar, there's one fundamental difference between the two. On sub-device API, the selection rectangle refers to the media bus format, and is bound to a sub-device's pad. On the V4L2 interface the selection rectangles refer to the in-memory pixel format.

This section defines the common definitions of the selection interfaces on the two APIs.

- [v4l2-selection-targets](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/v4l2-selection-targets.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [v4l2-selection-flags](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

---

# Video Standards

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Video devices typically support one or more different video standards or variations of standards. Each video input and output may support another set of standards. This set is reported by the std field of struct v4l2_input and struct…

<a id="rst-video-standards"></a>
<a id="rst-standard"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Video devices typically support one or more different video standards or variations of standards. Each video input and output may support another set of standards. This set is reported by the `std` field of struct `v4l2_input` and struct `v4l2_output` returned by the [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) and [ioctl VIDIOC_ENUMOUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-vidioc-enumoutput>) ioctls, respectively.

V4L2 defines one bit for each analog video standard currently in use worldwide, and sets aside bits for driver defined standards, e. g. hybrid standards to watch NTSC video tapes on PAL TVs and vice versa. Applications can use the predefined bits to select a particular standard, although presenting the user a menu of supported standards is preferred. To enumerate and query the attributes of the supported standards applications use the [vidioc_enumstd](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl.

Many of the defined standards are actually just variations of a few major standards. The hardware may in fact not distinguish between them, or do so internal and switch automatically. Therefore enumerated standards also contain sets of one or more standard bits.

Assume a hypothetic tuner capable of demodulating B/PAL, G/PAL and I/PAL signals. The first enumerated standard is a set of B and G/PAL, switched automatically depending on the selected radio frequency in UHF or VHF band. Enumeration gives a "PAL-B/G" or "PAL-I" choice. Similar a Composite input may collapse standards, enumerating "PAL-B/G/H/I", "NTSC-M" and "SECAM-D/K". <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

To query and select the standard used by the current video input or output applications call the [VIDIOC_G_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std>) and [VIDIOC_S_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std>) ioctl, respectively. The *received* standard can be sensed with the [ioctl VIDIOC_QUERYSTD, VIDIOC_SUBDEV_QUERYSTD](</kernel/userspace/userspace-api/media-v4l/vidioc-querystd.md#rst-vidioc-querystd>) ioctl.

> [!NOTE]
>
> The parameter of all these ioctls is a pointer to a [v4l2_std_id](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) type (a standard set), *not* an index into the standard enumeration. Drivers must implement all video standard ioctls when the device has one or more video inputs or outputs.

Special rules apply to devices such as USB cameras where the notion of video standards makes little sense. More generally for any capture or output device which is:

- incapable of capturing fields or frames at the nominal rate of the video standard, or

- that does not support the video standard formats at all.

Here the driver shall set the `std` field of struct `v4l2_input` and struct `v4l2_output` to zero and the [VIDIOC_G_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std>), [VIDIOC_S_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std>), [ioctl VIDIOC_QUERYSTD, VIDIOC_SUBDEV_QUERYSTD](</kernel/userspace/userspace-api/media-v4l/vidioc-querystd.md#rst-vidioc-querystd>) and [vidioc_enumstd](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctls shall return the `ENOTTY` error code or the `EINVAL` error code.

Applications can make use of the [input-capabilities](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-capabilities>) and [output-capabilities](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-output-capabilities>) flags to determine whether the video standard ioctls can be used with the given input or output.

<a id="rst-example-information-about-the-current-video-standard"></a>

## Example: Information about the current video standard



```c
v4l2_std_id std_id;
struct v4l2_standard standard;

if (-1 == ioctl(fd, VIDIOC_G_STD, &std_id)) {
    /* Note when VIDIOC_ENUMSTD always returns ENOTTY this
       is no video device or it falls under the USB exception,
       and VIDIOC_G_STD returning ENOTTY is no error. */

    perror("VIDIOC_G_STD");
    exit(EXIT_FAILURE);
}

memset(&standard, 0, sizeof(standard));
standard.index = 0;

while (0 == ioctl(fd, VIDIOC_ENUMSTD, &standard)) {
    if (standard.id & std_id) {
           printf("Current video standard: %s\\n", standard.name);
           exit(EXIT_SUCCESS);
    }

    standard.index++;
}

/* EINVAL indicates the end of the enumeration, which cannot be
   empty unless this device falls under the USB exception. */

if (errno == EINVAL || standard.index == 0) {
    perror("VIDIOC_ENUMSTD");
    exit(EXIT_FAILURE);
}
```

<a id="rst-example-listing-the-video-standards-supported-by-the-current-input"></a>

## Example: Listing the video standards supported by the current input



```c
struct v4l2_input input;
struct v4l2_standard standard;

memset(&input, 0, sizeof(input));

if (-1 == ioctl(fd, VIDIOC_G_INPUT, &input.index)) {
    perror("VIDIOC_G_INPUT");
    exit(EXIT_FAILURE);
}

if (-1 == ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
    perror("VIDIOC_ENUM_INPUT");
    exit(EXIT_FAILURE);
}

printf("Current input %s supports:\\n", input.name);

memset(&standard, 0, sizeof(standard));
standard.index = 0;

while (0 == ioctl(fd, VIDIOC_ENUMSTD, &standard)) {
    if (standard.id & input.std)
        printf("%s\\n", standard.name);

    standard.index++;
}

/* EINVAL indicates the end of the enumeration, which cannot be
   empty unless this device falls under the USB exception. */

if (errno != EINVAL || standard.index == 0) {
    perror("VIDIOC_ENUMSTD");
    exit(EXIT_FAILURE);
}
```

<a id="rst-example-selecting-a-new-video-standard"></a>

## Example: Selecting a new video standard



```c
struct v4l2_input input;
v4l2_std_id std_id;

memset(&input, 0, sizeof(input));

if (-1 == ioctl(fd, VIDIOC_G_INPUT, &input.index)) {
    perror("VIDIOC_G_INPUT");
    exit(EXIT_FAILURE);
}

if (-1 == ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
    perror("VIDIOC_ENUM_INPUT");
    exit(EXIT_FAILURE);
}

if (0 == (input.std & V4L2_STD_PAL_BG)) {
    fprintf(stderr, "Oops. B/G PAL is not supported.\\n");
    exit(EXIT_FAILURE);
}

/* Note this is also supposed to work when only B
   or G/PAL is supported. */

std_id = V4L2_STD_PAL_BG;

if (-1 == ioctl(fd, VIDIOC_S_STD, &std_id)) {
    perror("VIDIOC_S_STD");
    exit(EXIT_FAILURE);
}
```

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



**[1]** Some users are already confused by technical terms PAL, NTSC and SECAM. There is no point asking them to distinguish between B, G, D, or K when the software or hardware can do that automatically.

---

# Streaming Parameters

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Streaming parameters are intended to optimize the video capture process as well as I/O. Presently applications can request a high quality capture mode with the VIDIOC_S_PARM <VIDIOC_G_PARM> ioctl.

<a id="rst-streaming-parameters"></a>
<a id="rst-streaming-par"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Streaming parameters are intended to optimize the video capture process as well as I/O. Presently applications can request a high quality capture mode with the [VIDIOC_S_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm>) ioctl.

The current video standard determines a nominal number of frames per second. If less than this number of frames is to be captured or output, applications can request frame skipping or duplicating on the driver side. This is especially useful when using the `read()` or `write()`, which are not augmented by timestamps or sequence counters, and to avoid unnecessary data copying.

Finally these ioctls can be used to determine the number of buffers used internally by a driver in read/write mode. For implications see the section discussing the `read()` function.

To get and set the streaming parameters applications call the [VIDIOC_G_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm>) and [VIDIOC_S_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm>) ioctl, respectively. They take a pointer to a struct `v4l2_streamparm`, which contains a union holding separate parameters for input and output devices.

These ioctls are optional, drivers need not implement them. If so, they return the `EINVAL` error code.

---

# Media Bus Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The media bus pixel codes describe image formats as flowing over physical buses (both between separate physical components and inside SoC devices). This should not be confused with the V4L2 pixel formats that describe, using four character…

<a id="rst-media-bus-formats"></a>
<a id="rst-v4l2-mbus-format"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="c-v4l2_mbus_framefmt"></a>



```c
v4l2_mbus_framefmt
```

<!-- tabularcolumns: |p{2.0cm}|p{4.0cm}|p{11.3cm}| -->


<table>
<caption>

struct v4l2\_mbus\_framefmt

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`width`

</td>
<td>



Image width in pixels.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`height`

</td>
<td>



Image height in pixels. If `field` is one of `V4L2_FIELD_TOP`, `V4L2_FIELD_BOTTOM` or `V4L2_FIELD_ALTERNATE` then height refers to the number of lines in the field, otherwise it refers to the number of lines in the frame (which is twice the field height for interlaced formats).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`code`

</td>
<td>



Format code, from enum [v4l2\_mbus\_pixelcode](<#rst-v4l2-mbus-pixelcode>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`field`

</td>
<td>



Field order, from enum `v4l2_field`. See [field-order](</kernel/userspace/userspace-api/media-v4l/field-order.md#rst-field-order>) for details. Zero for metadata mbus codes.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`colorspace`

</td>
<td>



Image colorspace, from enum `v4l2_colorspace`. Must be set by the driver for subdevices. If the application sets the flag `V4L2_MBUS_FRAMEFMT_SET_CSC` then the application can set this field on the source pad to request a specific colorspace for the media bus data. If the driver cannot handle the requested conversion, it will return another supported colorspace. The driver indicates that colorspace conversion is supported by setting the flag V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_COLORSPACE in the corresponding struct `v4l2_subdev_mbus_code_enum` during enumeration. See [v4l2-subdev-mbus-code-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-enum-mbus-code.md#rst-v4l2-subdev-mbus-code-flags>). Zero for metadata mbus codes.

</td>
</tr>
<tr>
<td>



union \{

</td>
<td colspan="2">



(anonymous)

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`ycbcr_enc`

</td>
<td>



Y'CbCr encoding, from enum `v4l2_ycbcr_encoding`. This information supplements the `colorspace` and must be set by the driver for subdevices, see [colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_MBUS_FRAMEFMT_SET_CSC` then the application can set this field on a source pad to request a specific Y'CbCr encoding for the media bus data. If the driver cannot handle the requested conversion, it will return another supported encoding. This field is ignored for HSV media bus formats. The driver indicates that ycbcr\_enc conversion is supported by setting the flag V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_YCBCR\_ENC in the corresponding struct `v4l2_subdev_mbus_code_enum` during enumeration. See [v4l2-subdev-mbus-code-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-enum-mbus-code.md#rst-v4l2-subdev-mbus-code-flags>). Zero for metadata mbus codes.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`hsv_enc`

</td>
<td>



HSV encoding, from enum `v4l2_hsv_encoding`. This information supplements the `colorspace` and must be set by the driver for subdevices, see [colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_MBUS_FRAMEFMT_SET_CSC` then the application can set this field on a source pad to request a specific HSV encoding for the media bus data. If the driver cannot handle the requested conversion, it will return another supported encoding. This field is ignored for Y'CbCr media bus formats. The driver indicates that hsv\_enc conversion is supported by setting the flag V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_HSV\_ENC in the corresponding struct `v4l2_subdev_mbus_code_enum` during enumeration. See [v4l2-subdev-mbus-code-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-enum-mbus-code.md#rst-v4l2-subdev-mbus-code-flags>). Zero for metadata mbus codes.

</td>
</tr>
<tr>
<td>



\}

</td>
<td colspan="2">





</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`quantization`

</td>
<td>



Quantization range, from enum `v4l2_quantization`. This information supplements the `colorspace` and must be set by the driver for subdevices, see [colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_MBUS_FRAMEFMT_SET_CSC` then the application can set this field on a source pad to request a specific quantization for the media bus data. If the driver cannot handle the requested conversion, it will return another supported quantization. The driver indicates that quantization conversion is supported by setting the flag V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_QUANTIZATION in the corresponding struct `v4l2_subdev_mbus_code_enum` during enumeration. See [v4l2-subdev-mbus-code-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-enum-mbus-code.md#rst-v4l2-subdev-mbus-code-flags>). Zero for metadata mbus codes.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`xfer_func`

</td>
<td>



Transfer function, from enum `v4l2_xfer_func`. This information supplements the `colorspace` and must be set by the driver for subdevices, see [colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>). If the application sets the flag `V4L2_MBUS_FRAMEFMT_SET_CSC` then the application can set this field on a source pad to request a specific transfer function for the media bus data. If the driver cannot handle the requested conversion, it will return another supported transfer function. The driver indicates that the transfer function conversion is supported by setting the flag V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_XFER\_FUNC in the corresponding struct `v4l2_subdev_mbus_code_enum` during enumeration. See [v4l2-subdev-mbus-code-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-enum-mbus-code.md#rst-v4l2-subdev-mbus-code-flags>). Zero for metadata mbus codes.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`flags`

</td>
<td>



flags See:  :ref:v4l2-mbus-framefmt-flags

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`reserved`\[10\]

</td>
<td>



Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-mbus-framefmt-flags"></a>



<!-- tabularcolumns: |p{6.5cm}|p{1.6cm}|p{9.2cm}| -->


<table>
<caption>

v4l2\_mbus\_framefmt Flags

</caption>
<tbody>
<tr>
<td>



`V4L2_MBUS_FRAMEFMT_SET_CSC`

</td>
<td>



0x0001

</td>
<td>



<a id="rst-mbus-framefmt-set-csc"></a>

Set by the application. It is only used for source pads and is ignored for sink pads. If set, then request the subdevice to do colorspace conversion from the received colorspace to the requested colorspace values. If the colorimetry field (`colorspace`, `xfer_func`, `ycbcr_enc`, `hsv_enc` or `quantization`) is set to `*_DEFAULT`, then that colorimetry setting will remain unchanged from what was received. So in order to change the quantization, only the `quantization` field shall be set to non default value (`V4L2_QUANTIZATION_FULL_RANGE` or `V4L2_QUANTIZATION_LIM_RANGE`) and all other colorimetry fields shall be set to `*_DEFAULT`.

To check which conversions are supported by the hardware for the current media bus frame format, see [v4l2-subdev-mbus-code-flags](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-enum-mbus-code.md#rst-v4l2-subdev-mbus-code-flags>).

</td>
</tr>
</tbody>
</table>

<a id="rst-media-bus-pixel-codes"></a>
<a id="rst-v4l2-mbus-pixelcode"></a>

## Media Bus Pixel Codes

The media bus pixel codes describe image formats as flowing over physical buses (both between separate physical components and inside SoC devices). This should not be confused with the V4L2 pixel formats that describe, using four character codes, image formats as stored in memory.

While there is a relationship between image formats on buses and image formats in memory (a raw Bayer image won't be magically converted to JPEG just by storing it to memory), there is no one-to-one correspondence between them.

The media bus pixel codes document parallel formats. Should the pixel data be transported over a serial bus, the media bus pixel code that describes a parallel format that transfers a sample on a single clock cycle is used. For instance, both MEDIA\_BUS\_FMT\_BGR888\_1X24 and MEDIA\_BUS\_FMT\_BGR888\_3X8 are used on parallel busses for transferring an 8 bits per sample BGR data, whereas on serial busses the data in this format is only referred to using MEDIA\_BUS\_FMT\_BGR888\_1X24. This is because there is effectively only a single way to transport that format on the serial busses.

<a id="rst-packed-rgb-formats"></a>

### Packed RGB Formats

Those formats transfer pixel data as red, green and blue components. The format code is made of the following information.

- The red, green and blue components order code, as encoded in a pixel sample. Possible values are RGB and BGR.

- The number of bits per component, for each component. The values can be different for all components. Common values are 555 and 565.

- The number of bus samples per pixel. Pixels that are wider than the bus width must be transferred in multiple samples. Common values are 1 and 2.

- The bus width.

- For formats where the total number of bits per pixel is smaller than the number of bus samples per pixel times the bus width, a padding value stating if the bytes are padded in their most high order bits (PADHI) or low order bits (PADLO). A "C" prefix is used for component-wise padding in the most high order bits (CPADHI) or low order bits (CPADLO) of each separate component.

- For formats where the number of bus samples per pixel is larger than 1, an endianness value stating if the pixel is transferred MSB first (BE) or LSB first (LE).

For instance, a format where pixels are encoded as 5-bits red, 5-bits green and 5-bit blue values padded on the high bit, transferred as 2 8-bit samples per pixel with the most significant bits (padding, red and half of the green value) transferred first will be named `MEDIA_BUS_FMT_RGB555_2X8_PADHI_BE`.

The following tables list existing packed RGB formats.

<!-- HACK: ideally, we would be using adjustbox here. However, Sphinx -->

<!-- is a very bad behaviored guy: if the table has more than 30 cols, -->

<!-- it switches to long table, and there's no way to override it. -->

<!-- tabularcolumns: |p{5.0cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-rgb"></a>



<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->


<table>
<caption>

RGB formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="32">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>



31

</th>
<th>



30

</th>
<th>



29

</th>
<th>



28

</th>
<th>



27

</th>
<th>



26

</th>
<th>



25

</th>
<th>



24

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



20

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB444\_1X12

</td>
<td>



0x1016

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb444-1x12"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB444\_2X8\_PADHI\_BE

</td>
<td>



0x1001

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb444-2x8-padhi-be"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB444\_2X8\_PADHI\_LE

</td>
<td>



0x1002

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb444-2x8-padhi-le"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB555\_2X8\_PADHI\_BE

</td>
<td>



0x1003

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb555-2x8-padhi-be"></a>

g<sub>3</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB555\_2X8\_PADHI\_LE

</td>
<td>



0x1004

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb555-2x8-padhi-le"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB565\_1X16

</td>
<td>



0x1017

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb565-1x16"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_BGR565\_2X8\_BE

</td>
<td>



0x1005

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



<a id="rst-media-bus-fmt-bgr565-2x8-be"></a>

g<sub>3</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_BGR565\_2X8\_LE

</td>
<td>



0x1006

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-bgr565-2x8-le"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB565\_2X8\_BE

</td>
<td>



0x1007

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb565-2x8-be"></a>

g<sub>3</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB565\_2X8\_LE

</td>
<td>



0x1008

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb565-2x8-le"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB666\_1X18

</td>
<td>



0x1009

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb666-1x18"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB666\_2X9\_BE

</td>
<td>



0x1025

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb666-2x9-be"></a>

g<sub>3</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_BGR666\_1X18

</td>
<td>



0x1023

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-bgr666-1x18"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RBG888\_1X24

</td>
<td>



0x100e

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rbg888-1x24"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB666\_1X24\_CPADHI

</td>
<td>



0x1015

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb666-1x24-cpadhi"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_BGR666\_1X24\_CPADHI

</td>
<td>



0x1024

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-bgr666-1x24-cpadhi"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB565\_1X24\_CPADHI

</td>
<td>



0x1022

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb565-1x24-cpadhi"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_BGR888\_1X24

</td>
<td>



0x1013

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-bgr888-1x24"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_BGR888\_3X8

</td>
<td>



0x101b

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-bgr888-3x8"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_GBR888\_1X24

</td>
<td>



0x1014

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-gbr888-1x24"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_1X24

</td>
<td>



0x100a

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-1x24"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_2X12\_BE

</td>
<td>



0x100b

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-2x12-be"></a>

g<sub>4</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_2X12\_LE

</td>
<td>



0x100c

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-2x12-le"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_3X8

</td>
<td>



0x101c

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-3x8"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB666\_1X30-CPADLO

</td>
<td>



0x101e

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



<a id="rst-media-bus-fmt-rgb666-1x30-cpadlo"></a>

0

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_1X30-CPADLO

</td>
<td>



0x101f

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



0

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-1x30-cpadlo"></a>

0

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_ARGB888\_1X32

</td>
<td>



0x100d

</td>
<td>





</td>
<td>



a<sub>7</sub>

</td>
<td>



a<sub>6</sub>

</td>
<td>



a<sub>5</sub>

</td>
<td>



a<sub>4</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-argb888-1x32"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_1X32\_PADHI

</td>
<td>



0x100f

</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-1x32-padhi"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB101010\_1X30

</td>
<td>



0x1018

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb101010-1x30"></a>

b<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

The following table list existing packed 36bit wide RGB formats.

<!-- tabularcolumns: |p{4.0cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-rgb-36"></a>



<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->


<table>
<caption>

36bit RGB formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="36">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>



35

</th>
<th>



34

</th>
<th>



33

</th>
<th>



32

</th>
<th>



31

</th>
<th>



30

</th>
<th>



29

</th>
<th>



28

</th>
<th>



27

</th>
<th>



26

</th>
<th>



25

</th>
<th>



24

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



20

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB666\_1X36\_CPADLO

</td>
<td>



0x1020

</td>
<td>





</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



<a id="rst-media-bus-fmt-rgb666-1x36-cpadlo"></a>

0

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_1X36\_CPADLO

</td>
<td>



0x1021

</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-1x36-cpadlo"></a>

0

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB121212\_1X36

</td>
<td>



0x1019

</td>
<td>





</td>
<td>



r<sub>11</sub>

</td>
<td>



r<sub>10</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>11</sub>

</td>
<td>



b<sub>10</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb121212-1x36"></a>

b<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

The following table list existing packed 48bit wide RGB formats.

<!-- tabularcolumns: |p{4.0cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-rgb-48"></a>



<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->


<table>
<caption>

48bit RGB formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="32">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>



47

</th>
<th>



46

</th>
<th>



45

</th>
<th>



44

</th>
<th>



43

</th>
<th>



42

</th>
<th>



41

</th>
<th>



40

</th>
<th>



39

</th>
<th>



38

</th>
<th>



37

</th>
<th>



36

</th>
<th>



35

</th>
<th>



34

</th>
<th>



33

</th>
<th>



32

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>





</th>
<th>



31

</th>
<th>



30

</th>
<th>



29

</th>
<th>



28

</th>
<th>



27

</th>
<th>



26

</th>
<th>



25

</th>
<th>



24

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



20

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB161616\_1X48

</td>
<td>



0x101a

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>15</sub>

</td>
<td>



r<sub>14</sub>

</td>
<td>



r<sub>13</sub>

</td>
<td>



r<sub>12</sub>

</td>
<td>



r<sub>11</sub>

</td>
<td>



r<sub>10</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb161616-1x48"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>15</sub>

</td>
<td>



g<sub>14</sub>

</td>
<td>



g<sub>13</sub>

</td>
<td>



g<sub>12</sub>

</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>15</sub>

</td>
<td>



b<sub>14</sub>

</td>
<td>



b<sub>13</sub>

</td>
<td>



b<sub>12</sub>

</td>
<td>



b<sub>11</sub>

</td>
<td>



b<sub>10</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

The following table list existing packed 60bit wide RGB formats.

<!-- tabularcolumns: |p{4.0cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-rgb-60"></a>



<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->


<table>
<caption>

60bit RGB formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="32">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>



59

</th>
<th>



58

</th>
<th>



57

</th>
<th>



56

</th>
<th>



55

</th>
<th>



54

</th>
<th>



53

</th>
<th>



52

</th>
<th>



51

</th>
<th>



50

</th>
<th>



49

</th>
<th>



48

</th>
<th>



47

</th>
<th>



46

</th>
<th>



45

</th>
<th>



44

</th>
<th>



43

</th>
<th>



42

</th>
<th>



41

</th>
<th>



40

</th>
<th>



39

</th>
<th>



38

</th>
<th>



37

</th>
<th>



36

</th>
<th>



35

</th>
<th>



34

</th>
<th>



33

</th>
<th>



32

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>





</th>
<th>



31

</th>
<th>



30

</th>
<th>



29

</th>
<th>



28

</th>
<th>



27

</th>
<th>



26

</th>
<th>



25

</th>
<th>



24

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



20

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB202020\_1X60

</td>
<td>



0x1026

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>19</sub>

</td>
<td>



r<sub>18</sub>

</td>
<td>



r<sub>17</sub>

</td>
<td>



r<sub>16</sub>

</td>
<td>



r<sub>15</sub>

</td>
<td>



r<sub>14</sub>

</td>
<td>



r<sub>13</sub>

</td>
<td>



r<sub>12</sub>

</td>
<td>



r<sub>11</sub>

</td>
<td>



r<sub>10</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
<td>



g<sub>19</sub>

</td>
<td>



g<sub>18</sub>

</td>
<td>



g<sub>17</sub>

</td>
<td>



g<sub>16</sub>

</td>
<td>



g<sub>15</sub>

</td>
<td>



g<sub>14</sub>

</td>
<td>



g<sub>13</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb202020-1x60"></a>

g<sub>12</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>19</sub>

</td>
<td>



b<sub>18</sub>

</td>
<td>



b<sub>17</sub>

</td>
<td>



b<sub>16</sub>

</td>
<td>



b<sub>15</sub>

</td>
<td>



b<sub>14</sub>

</td>
<td>



b<sub>13</sub>

</td>
<td>



b<sub>12</sub>

</td>
<td>



b<sub>11</sub>

</td>
<td>



b<sub>10</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

On LVDS buses, usually each sample is transferred serialized in seven time slots per pixel clock, on three (18-bit) or four (24-bit) or five (30-bit) differential data pairs at the same time. The remaining bits are used for control signals as defined by SPWG/PSWG/VESA or JEIDA standards. The 24-bit RGB format serialized in seven time slots on four lanes using JEIDA defined bit mapping will be named `MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA`, for example.

<!-- Source LaTeX layout: \small -->

<a id="rst-v4l2-mbus-pixelcode-rgb-lvds"></a>


<table>
<caption>

LVDS RGB formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th>





</th>
<th colspan="5">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Timeslot

</th>
<th>



Lane

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB666\_1X7X3\_SPWG

</td>
<td>



0x1010

</td>
<td>



0

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



d

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb666-1x7x3-spwg"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



1

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



d

</td>
<td>



b<sub>0</sub>

</td>
<td>



r<sub>5</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



2

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



d

</td>
<td>



g<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



3

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



4

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



5

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



6

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_1X7X4\_SPWG

</td>
<td>



0x1011

</td>
<td>



0

</td>
<td>





</td>
<td>





</td>
<td>



d

</td>
<td>



d

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-1x7x4-spwg"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



1

</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



d

</td>
<td>



b<sub>0</sub>

</td>
<td>



r<sub>5</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



2

</td>
<td>





</td>
<td>





</td>
<td>



b<sub>6</sub>

</td>
<td>



d

</td>
<td>



g<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



3

</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



4

</td>
<td>





</td>
<td>





</td>
<td>



g<sub>6</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



5

</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



6

</td>
<td>





</td>
<td>





</td>
<td>



r<sub>6</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB888\_1X7X4\_JEIDA

</td>
<td>



0x1012

</td>
<td>



0

</td>
<td>





</td>
<td>





</td>
<td>



d

</td>
<td>



d

</td>
<td>



b<sub>3</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb888-1x7x4-jeida"></a>

g<sub>2</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



1

</td>
<td>





</td>
<td>





</td>
<td>



b<sub>1</sub>

</td>
<td>



d

</td>
<td>



b<sub>2</sub>

</td>
<td>



r<sub>7</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



2

</td>
<td>





</td>
<td>





</td>
<td>



b<sub>0</sub>

</td>
<td>



d

</td>
<td>



g<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



3

</td>
<td>





</td>
<td>





</td>
<td>



g<sub>1</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



4

</td>
<td>





</td>
<td>





</td>
<td>



g<sub>0</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



5

</td>
<td>





</td>
<td>





</td>
<td>



r<sub>1</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



6

</td>
<td>





</td>
<td>





</td>
<td>



r<sub>0</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB101010\_1X7X5\_SPWG

</td>
<td>



0x1026

</td>
<td>



0

</td>
<td>





</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb101010-1x7x5-spwg"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



1

</td>
<td>





</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



d

</td>
<td>



b<sub>0</sub>

</td>
<td>



r<sub>5</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



2

</td>
<td>





</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



d

</td>
<td>



g<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



3

</td>
<td>





</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



4

</td>
<td>





</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



5

</td>
<td>





</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



6

</td>
<td>





</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_RGB101010\_1X7X5\_JEIDA

</td>
<td>



0x1027

</td>
<td>



0

</td>
<td>





</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



b<sub>5</sub>

</td>
<td>



<a id="rst-media-bus-fmt-rgb101010-1x7x5-jeida"></a>

g<sub>4</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



1

</td>
<td>





</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



d

</td>
<td>



b<sub>4</sub>

</td>
<td>



r<sub>9</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



2

</td>
<td>





</td>
<td>



b<sub>0</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



d

</td>
<td>



g<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



3

</td>
<td>





</td>
<td>



g<sub>1</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



4

</td>
<td>





</td>
<td>



g<sub>0</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



5

</td>
<td>





</td>
<td>



r<sub>1</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



6

</td>
<td>





</td>
<td>



r<sub>0</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-bayer-formats"></a>

### Bayer Formats

Those formats transfer pixel data as red, green and blue components. The format code is made of the following information.

- The red, green and blue components order code, as encoded in a pixel sample. The possible values are shown in [bayer-patterns](<#rst-bayer-patterns>).

- The number of bits per pixel component. All components are transferred on the same number of bits. Common values are 8, 10 and 12.

- The compression (optional). If the pixel components are ALAW- or DPCM-compressed, a mention of the compression scheme and the number of bits per compressed pixel component.

- The number of bus samples per pixel. Pixels that are wider than the bus width must be transferred in multiple samples. Common values are 1 and 2.

- The bus width.

- For formats where the total number of bits per pixel is smaller than the number of bus samples per pixel times the bus width, a padding value stating if the bytes are padded in their most high order bits (PADHI) or low order bits (PADLO).

- For formats where the number of bus samples per pixel is larger than 1, an endianness value stating if the pixel is transferred MSB first (BE) or LSB first (LE).

For instance, a format with uncompressed 10-bit Bayer components arranged in a red, green, green, blue pattern transferred as 2 8-bit samples per pixel with the least significant bits transferred first will be named `MEDIA_BUS_FMT_SRGGB10_2X8_PADHI_LE`.

<a id="rst-bayer-patterns"></a>

![bayer.svg](/kernel/userspace/userspace-api/media-v4l/asset-5ac95564f76f-bayer.svg)

Bayer Patterns

The following table lists existing packed Bayer formats. The data organization is given as an example for the first pixel only.

<!-- HACK: ideally, we would be using adjustbox here. However, Sphinx -->

<!-- is a very bad behaviored guy: if the table has more than 30 cols, -->

<!-- it switches to long table, and there's no way to override it. -->

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{6.0cm}|p{0.7cm}|p{0.3cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-bayer"></a>



<!-- cssclass: longtable -->


<table>
<caption>

Bayer Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="20">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR8\_1X8

</td>
<td>



0x3001

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr8-1x8"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGBRG8\_1X8

</td>
<td>



0x3013

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgbrg8-1x8"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGRBG8\_1X8

</td>
<td>



0x3002

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgrbg8-1x8"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SRGGB8\_1X8

</td>
<td>



0x3014

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-srggb8-1x8"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR10\_ALAW8\_1X8

</td>
<td>



0x3015

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr10-alaw8-1x8"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGBRG10\_ALAW8\_1X8

</td>
<td>



0x3016

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgbrg10-alaw8-1x8"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGRBG10\_ALAW8\_1X8

</td>
<td>



0x3017

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgrbg10-alaw8-1x8"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SRGGB10\_ALAW8\_1X8

</td>
<td>



0x3018

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-srggb10-alaw8-1x8"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR10\_DPCM8\_1X8

</td>
<td>



0x300b

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr10-dpcm8-1x8"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGBRG10\_DPCM8\_1X8

</td>
<td>



0x300c

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgbrg10-dpcm8-1x8"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGRBG10\_DPCM8\_1X8

</td>
<td>



0x3009

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgrbg10-dpcm8-1x8"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SRGGB10\_DPCM8\_1X8

</td>
<td>



0x300d

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-srggb10-dpcm8-1x8"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR10\_2X8\_PADHI\_BE

</td>
<td>



0x3003

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>9</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr10-2x8-padhi-be"></a>

b<sub>8</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR10\_2X8\_PADHI\_LE

</td>
<td>



0x3004

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr10-2x8-padhi-le"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR10\_2X8\_PADLO\_BE

</td>
<td>



0x3005

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr10-2x8-padlo-be"></a>

b<sub>2</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR10\_2X8\_PADLO\_LE

</td>
<td>



0x3006

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>1</sub>

</td>
<td>



b<sub>0</sub>

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



<a id="rst-media-bus-fmt-sbggr10-2x8-padlo-le"></a>

0

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR10\_1X10

</td>
<td>



0x3007

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr10-1x10"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGBRG10\_1X10

</td>
<td>



0x300e

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgbrg10-1x10"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGRBG10\_1X10

</td>
<td>



0x300a

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgrbg10-1x10"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SRGGB10\_1X10

</td>
<td>



0x300f

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-srggb10-1x10"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR12\_1X12

</td>
<td>



0x3008

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>11</sub>

</td>
<td>



b<sub>10</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr12-1x12"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGBRG12\_1X12

</td>
<td>



0x3010

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgbrg12-1x12"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGRBG12\_1X12

</td>
<td>



0x3011

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgrbg12-1x12"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SRGGB12\_1X12

</td>
<td>



0x3012

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>11</sub>

</td>
<td>



r<sub>10</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-srggb12-1x12"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR14\_1X14

</td>
<td>



0x3019

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>13</sub>

</td>
<td>



b<sub>12</sub>

</td>
<td>



b<sub>11</sub>

</td>
<td>



b<sub>10</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr14-1x14"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGBRG14\_1X14

</td>
<td>



0x301a

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>13</sub>

</td>
<td>



g<sub>12</sub>

</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgbrg14-1x14"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGRBG14\_1X14

</td>
<td>



0x301b

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>13</sub>

</td>
<td>



g<sub>12</sub>

</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgrbg14-1x14"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SRGGB14\_1X14

</td>
<td>



0x301c

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>13</sub>

</td>
<td>



r<sub>12</sub>

</td>
<td>



r<sub>11</sub>

</td>
<td>



r<sub>10</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-srggb14-1x14"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR16\_1X16

</td>
<td>



0x301d

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b<sub>15</sub>

</td>
<td>



b<sub>14</sub>

</td>
<td>



b<sub>13</sub>

</td>
<td>



b<sub>12</sub>

</td>
<td>



b<sub>11</sub>

</td>
<td>



b<sub>10</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr16-1x16"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGBRG16\_1X16

</td>
<td>



0x301e

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>15</sub>

</td>
<td>



g<sub>14</sub>

</td>
<td>



g<sub>13</sub>

</td>
<td>



g<sub>12</sub>

</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgbrg16-1x16"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGRBG16\_1X16

</td>
<td>



0x301f

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



g<sub>15</sub>

</td>
<td>



g<sub>14</sub>

</td>
<td>



g<sub>13</sub>

</td>
<td>



g<sub>12</sub>

</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgrbg16-1x16"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SRGGB16\_1X16

</td>
<td>



0x3020

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



r<sub>15</sub>

</td>
<td>



r<sub>14</sub>

</td>
<td>



r<sub>13</sub>

</td>
<td>



r<sub>12</sub>

</td>
<td>



r<sub>11</sub>

</td>
<td>



r<sub>10</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-srggb16-1x16"></a>

r<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SBGGR20\_1X20

</td>
<td>



0x3021

</td>
<td>





</td>
<td>



b<sub>19</sub>

</td>
<td>



b<sub>18</sub>

</td>
<td>



b<sub>17</sub>

</td>
<td>



b<sub>16</sub>

</td>
<td>



b<sub>15</sub>

</td>
<td>



b<sub>14</sub>

</td>
<td>



b<sub>13</sub>

</td>
<td>



b<sub>12</sub>

</td>
<td>



b<sub>11</sub>

</td>
<td>



b<sub>10</sub>

</td>
<td>



b<sub>9</sub>

</td>
<td>



b<sub>8</sub>

</td>
<td>



b<sub>7</sub>

</td>
<td>



b<sub>6</sub>

</td>
<td>



b<sub>5</sub>

</td>
<td>



b<sub>4</sub>

</td>
<td>



b<sub>3</sub>

</td>
<td>



b<sub>2</sub>

</td>
<td>



b<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sbggr20-1x20"></a>

b<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGBRG20\_1X20

</td>
<td>



0x3022

</td>
<td>





</td>
<td>



g<sub>19</sub>

</td>
<td>



g<sub>18</sub>

</td>
<td>



g<sub>17</sub>

</td>
<td>



g<sub>16</sub>

</td>
<td>



g<sub>15</sub>

</td>
<td>



g<sub>14</sub>

</td>
<td>



g<sub>13</sub>

</td>
<td>



g<sub>12</sub>

</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgbrg20-1x20"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SGRBG20\_1X20

</td>
<td>



0x3023

</td>
<td>





</td>
<td>



g<sub>19</sub>

</td>
<td>



g<sub>18</sub>

</td>
<td>



g<sub>17</sub>

</td>
<td>



g<sub>16</sub>

</td>
<td>



g<sub>15</sub>

</td>
<td>



g<sub>14</sub>

</td>
<td>



g<sub>13</sub>

</td>
<td>



g<sub>12</sub>

</td>
<td>



g<sub>11</sub>

</td>
<td>



g<sub>10</sub>

</td>
<td>



g<sub>9</sub>

</td>
<td>



g<sub>8</sub>

</td>
<td>



g<sub>7</sub>

</td>
<td>



g<sub>6</sub>

</td>
<td>



g<sub>5</sub>

</td>
<td>



g<sub>4</sub>

</td>
<td>



g<sub>3</sub>

</td>
<td>



g<sub>2</sub>

</td>
<td>



g<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-sgrbg20-1x20"></a>

g<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_SRGGB20\_1X20

</td>
<td>



0x3024

</td>
<td>





</td>
<td>



r<sub>19</sub>

</td>
<td>



r<sub>18</sub>

</td>
<td>



r<sub>17</sub>

</td>
<td>



r<sub>16</sub>

</td>
<td>



r<sub>15</sub>

</td>
<td>



r<sub>14</sub>

</td>
<td>



r<sub>13</sub>

</td>
<td>



r<sub>12</sub>

</td>
<td>



r<sub>11</sub>

</td>
<td>



r<sub>10</sub>

</td>
<td>



r<sub>9</sub>

</td>
<td>



r<sub>8</sub>

</td>
<td>



r<sub>7</sub>

</td>
<td>



r<sub>6</sub>

</td>
<td>



r<sub>5</sub>

</td>
<td>



r<sub>4</sub>

</td>
<td>



r<sub>3</sub>

</td>
<td>



r<sub>2</sub>

</td>
<td>



r<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-srggb20-1x20"></a>

r<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

<a id="rst-packed-yuv-formats"></a>

### Packed YUV Formats

Those data formats transfer pixel data as (possibly downsampled) Y, U and V components. Some formats include dummy bits in some of their samples and are collectively referred to as "YDYC" (Y-Dummy-Y-Chroma) formats. One cannot rely on the values of these dummy bits as those are undefined.

The format code is made of the following information.

- The Y, U and V components order code, as transferred on the bus. Possible values are YUYV, UYVY, YVYU and VYUY for formats with no dummy bit, and YDYUYDYV, YDYVYDYU, YUYDYVYD and YVYDYUYD for YDYC formats.

- The number of bits per pixel component. All components are transferred on the same number of bits. Common values are 8, 10 and 12.

- The number of bus samples per pixel. Pixels that are wider than the bus width must be transferred in multiple samples. Common values are 0.5 (encoded as 0\_5; in this case two pixels are transferred per bus sample), 1, 1.5 (encoded as 1\_5) and 2.

- The bus width. When the bus width is larger than the number of bits per pixel component, several components are packed in a single bus sample. The components are ordered as specified by the order code, with components on the left of the code transferred in the high order bits. Common values are 8 and 16.

For instance, a format where pixels are encoded as 8-bit YUV values downsampled to 4:2:2 and transferred as 2 8-bit bus samples per pixel in the U, Y, V, Y order will be named `MEDIA_BUS_FMT_UYVY8_2X8`.

[v4l2-mbus-pixelcode-yuv8](<#rst-v4l2-mbus-pixelcode-yuv8>) lists existing packed YUV formats and describes the organization of each pixel data in each sample. When a format pattern is split across multiple samples each of the samples in the pattern is described.

The role of each bit transferred over the bus is identified by one of the following codes.

- y<sub>x</sub> for luma component bit number x

- u<sub>x</sub> for blue chroma component bit number x

- v<sub>x</sub> for red chroma component bit number x

- a<sub>x</sub> for alpha component bit number x

- for non-available bits (for positions higher than the bus width)

- d for dummy bits

<!-- HACK: ideally, we would be using adjustbox here. However, this -->

<!-- will never work for this table, as, even with tiny font, it is -->

<!-- to big for a single page. So, we need to manually adjust the -->

<!-- size. -->

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{5.0cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-yuv8"></a>


<table>
<caption>

YUV Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="32">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>



31

</th>
<th>



30

</th>
<th>



29

</th>
<th>



28

</th>
<th>



27

</th>
<th>



26

</th>
<th>



25

</th>
<th>



24

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



10

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_Y8\_1X8

</td>
<td>



0x2001

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-y8-1x8"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UV8\_1X8

</td>
<td>



0x2015

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uv8-1x8"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYVY8\_1\_5X8

</td>
<td>



0x2002

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyvy8-1-5x8"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_VYUY8\_1\_5X8

</td>
<td>



0x2003

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-vyuy8-1-5x8"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUYV8\_1\_5X8

</td>
<td>



0x2004

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuyv8-1-5x8"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YVYU8\_1\_5X8

</td>
<td>



0x2005

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yvyu8-1-5x8"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYVY8\_2X8

</td>
<td>



0x2006

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyvy8-2x8"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_VYUY8\_2X8

</td>
<td>



0x2007

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-vyuy8-2x8"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUYV8\_2X8

</td>
<td>



0x2008

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuyv8-2x8"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YVYU8\_2X8

</td>
<td>



0x2009

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yvyu8-2x8"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_Y10\_1X10

</td>
<td>



0x200a

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-y10-1x10"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_Y10\_2X8\_PADHI\_LE

</td>
<td>



0x202c

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-y10-2x8-padhi-le"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYVY10\_2X10

</td>
<td>



0x2018

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyvy10-2x10"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_VYUY10\_2X10

</td>
<td>



0x2019

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-vyuy10-2x10"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUYV10\_2X10

</td>
<td>



0x200b

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuyv10-2x10"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YVYU10\_2X10

</td>
<td>



0x200c

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yvyu10-2x10"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_Y12\_1X12

</td>
<td>



0x2013

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-y12-1x12"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYVY12\_2X12

</td>
<td>



0x201c

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyvy12-2x12"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_VYUY12\_2X12

</td>
<td>



0x201d

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-vyuy12-2x12"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUYV12\_2X12

</td>
<td>



0x201e

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuyv12-2x12"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YVYU12\_2X12

</td>
<td>



0x201f

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yvyu12-2x12"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_Y14\_1X14

</td>
<td>



0x202d

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>13</sub>

</td>
<td>



y<sub>12</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-y14-1x14"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_Y16\_1X16

</td>
<td>



0x202e

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>15</sub>

</td>
<td>



y<sub>14</sub>

</td>
<td>



y<sub>13</sub>

</td>
<td>



y<sub>12</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-y16-1x16"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYVY8\_1X16

</td>
<td>



0x200f

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyvy8-1x16"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_VYUY8\_1X16

</td>
<td>



0x2010

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-vyuy8-1x16"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUYV8\_1X16

</td>
<td>



0x2011

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuyv8-1x16"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YVYU8\_1X16

</td>
<td>



0x2012

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yvyu8-1x16"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YDYUYDYV8\_1X16

</td>
<td>



0x2014

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



<a id="rst-media-bus-fmt-ydyuydyv8-1x16"></a>

d

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
<td>



d

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYVY10\_1X20

</td>
<td>



0x201a

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyvy10-1x20"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_VYUY10\_1X20

</td>
<td>



0x201b

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-vyuy10-1x20"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUYV10\_1X20

</td>
<td>



0x200d

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuyv10-1x20"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YVYU10\_1X20

</td>
<td>



0x200e

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yvyu10-1x20"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_VUY8\_1X24

</td>
<td>



0x201a

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-vuy8-1x24"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUV8\_1X24

</td>
<td>



0x2025

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuv8-1x24"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYYVYY8\_0\_5X24

</td>
<td>



0x2026

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyyvyy8-0-5x24"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYVY12\_1X24

</td>
<td>



0x2020

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyvy12-1x24"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_VYUY12\_1X24

</td>
<td>



0x2021

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-vyuy12-1x24"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUYV12\_1X24

</td>
<td>



0x2022

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuyv12-1x24"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YVYU12\_1X24

</td>
<td>



0x2023

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yvyu12-1x24"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUV10\_1X30

</td>
<td>



0x2016

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuv10-1x30"></a>

v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYYVYY10\_0\_5X30

</td>
<td>



0x2027

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyyvyy10-0-5x30"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_AYUV8\_1X32

</td>
<td>



0x2017

</td>
<td>





</td>
<td>



a<sub>7</sub>

</td>
<td>



a<sub>6</sub>

</td>
<td>



a<sub>5</sub>

</td>
<td>



a<sub>4</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-ayuv8-1x32"></a>

v<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

The following table list existing packed 36bit wide YUV formats.

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{4.1cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-yuv8-36bit"></a>


<table>
<caption>

36bit YUV Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="36">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>



35

</th>
<th>



34

</th>
<th>



33

</th>
<th>



32

</th>
<th>



31

</th>
<th>



30

</th>
<th>



29

</th>
<th>



28

</th>
<th>



27

</th>
<th>



26

</th>
<th>



25

</th>
<th>



24

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



10

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYYVYY12\_0\_5X36

</td>
<td>



0x2028

</td>
<td>





</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyyvyy12-0-5x36"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUV12\_1X36

</td>
<td>



0x2029

</td>
<td>





</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuv12-1x36"></a>

v<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

The following table list existing packed 48bit wide YUV formats.

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{5.6cm}|p{0.7cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-yuv8-48bit"></a>


<table>
<caption>

48bit YUV Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="32">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>





</th>
<th>



47

</th>
<th>



46

</th>
<th>



45

</th>
<th>



44

</th>
<th>



43

</th>
<th>



42

</th>
<th>



41

</th>
<th>



40

</th>
<th>



39

</th>
<th>



38

</th>
<th>



37

</th>
<th>



36

</th>
<th>



35

</th>
<th>



34

</th>
<th>



33

</th>
<th>



32

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>





</th>
<th>



31

</th>
<th>



30

</th>
<th>



29

</th>
<th>



28

</th>
<th>



27

</th>
<th>



26

</th>
<th>



25

</th>
<th>



24

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



10

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_YUV16\_1X48

</td>
<td>



0x202a

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>15</sub>

</td>
<td>



y<sub>14</sub>

</td>
<td>



y<sub>13</sub>

</td>
<td>



y<sub>12</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-yuv16-1x48"></a>

y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>15</sub>

</td>
<td>



u<sub>14</sub>

</td>
<td>



u<sub>13</sub>

</td>
<td>



u<sub>12</sub>

</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



u<sub>0</sub>

</td>
<td>



v<sub>15</sub>

</td>
<td>



v<sub>14</sub>

</td>
<td>



v<sub>13</sub>

</td>
<td>



v<sub>12</sub>

</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_UYYVYY16\_0\_5X48

</td>
<td>



0x202b

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



u<sub>15</sub>

</td>
<td>



u<sub>14</sub>

</td>
<td>



u<sub>13</sub>

</td>
<td>



u<sub>12</sub>

</td>
<td>



u<sub>11</sub>

</td>
<td>



u<sub>10</sub>

</td>
<td>



u<sub>9</sub>

</td>
<td>



u<sub>8</sub>

</td>
<td>



u<sub>7</sub>

</td>
<td>



u<sub>6</sub>

</td>
<td>



u<sub>5</sub>

</td>
<td>



u<sub>4</sub>

</td>
<td>



u<sub>3</sub>

</td>
<td>



u<sub>2</sub>

</td>
<td>



u<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-uyyvyy16-0-5x48"></a>

u<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>15</sub>

</td>
<td>



y<sub>14</sub>

</td>
<td>



y<sub>13</sub>

</td>
<td>



y<sub>12</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



y<sub>15</sub>

</td>
<td>



y<sub>14</sub>

</td>
<td>



y<sub>13</sub>

</td>
<td>



y<sub>12</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



v<sub>15</sub>

</td>
<td>



v<sub>14</sub>

</td>
<td>



v<sub>13</sub>

</td>
<td>



v<sub>12</sub>

</td>
<td>



v<sub>11</sub>

</td>
<td>



v<sub>10</sub>

</td>
<td>



v<sub>9</sub>

</td>
<td>



v<sub>8</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



v<sub>0</sub>

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



y<sub>15</sub>

</td>
<td>



y<sub>14</sub>

</td>
<td>



y<sub>13</sub>

</td>
<td>



y<sub>12</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>9</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
<td>



y<sub>15</sub>

</td>
<td>



y<sub>14</sub>

</td>
<td>



y<sub>13</sub>

</td>
<td>



y<sub>12</sub>

</td>
<td>



y<sub>11</sub>

</td>
<td>



y<sub>10</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>8</sub>

</td>
<td>



y<sub>7</sub>

</td>
<td>



y<sub>6</sub>

</td>
<td>



y<sub>5</sub>

</td>
<td>



y<sub>4</sub>

</td>
<td>



y<sub>3</sub>

</td>
<td>



y<sub>2</sub>

</td>
<td>



y<sub>1</sub>

</td>
<td>



y<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

<a id="rst-hsv-hsl-formats"></a>

### HSV/HSL Formats

Those formats transfer pixel data as RGB values in a cylindrical-coordinate system using Hue-Saturation-Value or Hue-Saturation-Lightness components. The format code is made of the following information.

- The hue, saturation, value or lightness and optional alpha components order code, as encoded in a pixel sample. The only currently supported value is AHSV.

- The number of bits per component, for each component. The values can be different for all components. The only currently supported value is 8888.

- The number of bus samples per pixel. Pixels that are wider than the bus width must be transferred in multiple samples. The only currently supported value is 1.

- The bus width.

- For formats where the total number of bits per pixel is smaller than the number of bus samples per pixel times the bus width, a padding value stating if the bytes are padded in their most high order bits (PADHI) or low order bits (PADLO).

- For formats where the number of bus samples per pixel is larger than 1, an endianness value stating if the pixel is transferred MSB first (BE) or LSB first (LE).

The following table lists existing HSV/HSL formats.

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- tabularcolumns: |p{3.9cm}|p{0.73cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}|p{0.22cm}| -->

<a id="rst-v4l2-mbus-pixelcode-hsv"></a>


<table>
<caption>

HSV/HSL formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="32">



 Data organization

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>



31

</th>
<th>



30

</th>
<th>



29

</th>
<th>



28

</th>
<th>



27

</th>
<th>



26

</th>
<th>



25

</th>
<th>



24

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



20

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_AHSV8888\_1X32

</td>
<td>



0x6001

</td>
<td>





</td>
<td>



a<sub>7</sub>

</td>
<td>



a<sub>6</sub>

</td>
<td>



a<sub>5</sub>

</td>
<td>



a<sub>4</sub>

</td>
<td>



a<sub>3</sub>

</td>
<td>



a<sub>2</sub>

</td>
<td>



a<sub>1</sub>

</td>
<td>



a<sub>0</sub>

</td>
<td>



h<sub>7</sub>

</td>
<td>



h<sub>6</sub>

</td>
<td>



h<sub>5</sub>

</td>
<td>



h<sub>4</sub>

</td>
<td>



h<sub>3</sub>

</td>
<td>



h<sub>2</sub>

</td>
<td>



h<sub>1</sub>

</td>
<td>



h<sub>0</sub>

</td>
<td>



s<sub>7</sub>

</td>
<td>



s<sub>6</sub>

</td>
<td>



s<sub>5</sub>

</td>
<td>



s<sub>4</sub>

</td>
<td>



s<sub>3</sub>

</td>
<td>



s<sub>2</sub>

</td>
<td>



s<sub>1</sub>

</td>
<td>



s<sub>0</sub>

</td>
<td>



v<sub>7</sub>

</td>
<td>



v<sub>6</sub>

</td>
<td>



v<sub>5</sub>

</td>
<td>



v<sub>4</sub>

</td>
<td>



v<sub>3</sub>

</td>
<td>



v<sub>2</sub>

</td>
<td>



v<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-ahsv8888-1x32"></a>

v<sub>0</sub>

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

<a id="rst-jpeg-compressed-formats"></a>

### JPEG Compressed Formats

Those data formats consist of an ordered sequence of 8-bit bytes obtained from JPEG compression process. Additionally to the `_JPEG` postfix the format code is made of the following information.

- The number of bus samples per entropy encoded byte.

- The bus width.

For instance, for a JPEG baseline process and an 8-bit bus width the format will be named `MEDIA_BUS_FMT_JPEG_1X8`.

The following table lists existing JPEG compressed formats.

<a id="rst-v4l2-mbus-pixelcode-jpeg"></a>



<!-- tabularcolumns: |p{6.0cm}|p{1.4cm}|p{9.9cm}| -->


<table>
<caption>

JPEG Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Remarks

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_JPEG\_1X8

</td>
<td>



0x4001

</td>
<td>



<a id="rst-media-bus-fmt-jpeg-1x8"></a>

Besides of its usage for the parallel bus this format is recommended for transmission of JPEG data over MIPI CSI bus using the User Defined 8-bit Data types.

</td>
</tr>
</tbody>
</table>

<a id="rst-vendor-and-device-specific-formats"></a>
<a id="rst-v4l2-mbus-vendor-spec-fmts"></a>

### Vendor and Device Specific Formats

This section lists complex data formats that are either vendor or device specific.

The following table lists the existing vendor and device specific formats.

<a id="rst-v4l2-mbus-pixelcode-vendor-specific"></a>



<!-- tabularcolumns: |p{8.0cm}|p{1.4cm}|p{7.9cm}| -->


<table>
<caption>

Vendor and device specific formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Comments

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_S5C\_UYVY\_JPEG\_1X8

</td>
<td>



0x5001

</td>
<td>



<a id="rst-media-bus-fmt-s5c-uyvy-jpeg-1x8"></a>

Interleaved raw UYVY and JPEG image format with embedded meta-data used by Samsung S3C73MX camera sensors.

</td>
</tr>
</tbody>
</table>

<a id="rst-metadata-formats"></a>
<a id="rst-v4l2-mbus-metadata-fmts"></a>

### Metadata Formats

This section lists all metadata formats.

The following table lists the existing metadata formats.

<!-- tabularcolumns: |p{8.0cm}|p{1.4cm}|p{7.9cm}| -->


<table>
<caption>

Metadata formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>



Comments

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_METADATA\_FIXED

</td>
<td>



0x7001

</td>
<td>



<a id="rst-media-bus-fmt-metadata-fixed"></a>

This format should be used when the same driver handles both sides of the link and the bus format is a fixed metadata format that is not configurable from userspace. Width and height will be set to 0 for this format.

</td>
</tr>
</tbody>
</table>

<a id="rst-generic-serial-metadata-formats"></a>

### Generic Serial Metadata Formats

Generic serial metadata formats are used on serial buses where the actual data content is more or less device specific but the data is transmitted and received by multiple devices that do not process the data in any way, simply writing it to system memory for processing in software at the end of the pipeline.

"b" in an array cell signifies a byte of data, followed by the number of the bit and finally the bit number in subscript. "x" indicates a padding bit.

<a id="rst-media-bus-format-generic-meta"></a>



<!-- cssclass: longtable -->


<table>
<caption>

Generic Serial Metadata Formats

</caption>
<thead>
<tr>
<th>



Identifier

</th>
<th>



Code

</th>
<th>





</th>
<th colspan="24">



 Data organization within bus [Data Unit](</kernel/userspace/userspace-api/media/glossary.md#rst-term-data-unit>)

</th>
</tr>
<tr>
<th>





</th>
<th>





</th>
<th>



Bit

</th>
<th>



23

</th>
<th>



22

</th>
<th>



21

</th>
<th>



20

</th>
<th>



19

</th>
<th>



18

</th>
<th>



17

</th>
<th>



16

</th>
<th>



15

</th>
<th>



14

</th>
<th>



13

</th>
<th>



12

</th>
<th>



11

</th>
<th>



10

</th>
<th>



9

</th>
<th>



8

</th>
<th>



7

</th>
<th>



6

</th>
<th>



5

</th>
<th>



4

</th>
<th>



3

</th>
<th>



2

</th>
<th>



1

</th>
<th>



0

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



MEDIA\_BUS\_FMT\_META\_8

</td>
<td>



0x8001

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b0<sub>7</sub>

</td>
<td>



b0<sub>6</sub>

</td>
<td>



b0<sub>5</sub>

</td>
<td>



b0<sub>4</sub>

</td>
<td>



b0<sub>3</sub>

</td>
<td>



b0<sub>2</sub>

</td>
<td>



b0<sub>1</sub>

</td>
<td>



<a id="rst-media-bus-fmt-meta-8"></a>

b0<sub>0</sub>

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_META\_10

</td>
<td>



0x8002

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b0<sub>7</sub>

</td>
<td>



b0<sub>6</sub>

</td>
<td>



b0<sub>5</sub>

</td>
<td>



b0<sub>4</sub>

</td>
<td>



b0<sub>3</sub>

</td>
<td>



b0<sub>2</sub>

</td>
<td>



b0<sub>1</sub>

</td>
<td>



b0<sub>0</sub>

</td>
<td>



x

</td>
<td>



<a id="rst-media-bus-fmt-meta-10"></a>

x

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_META\_12

</td>
<td>



0x8003

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b0<sub>7</sub>

</td>
<td>



b0<sub>6</sub>

</td>
<td>



b0<sub>5</sub>

</td>
<td>



b0<sub>4</sub>

</td>
<td>



b0<sub>3</sub>

</td>
<td>



b0<sub>2</sub>

</td>
<td>



b0<sub>1</sub>

</td>
<td>



b0<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



<a id="rst-media-bus-fmt-meta-12"></a>

x

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_META\_14

</td>
<td>



0x8004

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b0<sub>7</sub>

</td>
<td>



b0<sub>6</sub>

</td>
<td>



b0<sub>5</sub>

</td>
<td>



b0<sub>4</sub>

</td>
<td>



b0<sub>3</sub>

</td>
<td>



b0<sub>2</sub>

</td>
<td>



b0<sub>1</sub>

</td>
<td>



b0<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



<a id="rst-media-bus-fmt-meta-14"></a>

x

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_META\_16

</td>
<td>



0x8005

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b0<sub>7</sub>

</td>
<td>



b0<sub>6</sub>

</td>
<td>



b0<sub>5</sub>

</td>
<td>



b0<sub>4</sub>

</td>
<td>



b0<sub>3</sub>

</td>
<td>



b0<sub>2</sub>

</td>
<td>



b0<sub>1</sub>

</td>
<td>



b0<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



<a id="rst-media-bus-fmt-meta-16"></a>

x

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_META\_20

</td>
<td>



0x8006

</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



b0<sub>7</sub>

</td>
<td>



b0<sub>6</sub>

</td>
<td>



b0<sub>5</sub>

</td>
<td>



b0<sub>4</sub>

</td>
<td>



b0<sub>3</sub>

</td>
<td>



b0<sub>2</sub>

</td>
<td>



b0<sub>1</sub>

</td>
<td>



b0<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



<a id="rst-media-bus-fmt-meta-20"></a>

x

</td>
</tr>
<tr>
<td>



MEDIA\_BUS\_FMT\_META\_24

</td>
<td>



0x8007

</td>
<td>





</td>
<td>



b0<sub>7</sub>

</td>
<td>



b0<sub>6</sub>

</td>
<td>



b0<sub>5</sub>

</td>
<td>



b0<sub>4</sub>

</td>
<td>



b0<sub>3</sub>

</td>
<td>



b0<sub>2</sub>

</td>
<td>



b0<sub>1</sub>

</td>
<td>



b0<sub>0</sub>

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



x

</td>
<td>



<a id="rst-media-bus-fmt-meta-24"></a>

x

</td>
</tr>
</tbody>
</table>

---

# Touch Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> These formats are used for touch interface only.

<a id="rst-touch-formats"></a>
<a id="rst-tch-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

These formats are used for [Touch Devices](</kernel/userspace/userspace-api/media-v4l/dev-touch.md#rst-touch>) interface only.

- [V4L2_TCH_FMT_DELTA_TD16 ('TD16')](</kernel/userspace/userspace-api/media-v4l/pixfmt-tch-td16.md>)
- [V4L2_TCH_FMT_DELTA_TD08 ('TD08')](</kernel/userspace/userspace-api/media-v4l/pixfmt-tch-td08.md>)
- [V4L2_TCH_FMT_TU16 ('TU16')](</kernel/userspace/userspace-api/media-v4l/pixfmt-tch-tu16.md>)
- [V4L2_TCH_FMT_TU08 ('TU08')](</kernel/userspace/userspace-api/media-v4l/pixfmt-tch-tu08.md>)

---

# Tuners and Modulators

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Video input devices can have one or more tuners demodulating a RF signal. Each tuner is associated with one or more video inputs, depending on the number of RF connectors on the tuner. The type field of the respective struct v4l2_input…

<a id="rst-tuners-and-modulators"></a>
<a id="rst-tuner"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Tuners

Video input devices can have one or more tuners demodulating a RF signal. Each tuner is associated with one or more video inputs, depending on the number of RF connectors on the tuner. The `type` field of the respective struct `v4l2_input` returned by the [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) ioctl is set to `V4L2_INPUT_TYPE_TUNER` and its `tuner` field contains the index number of the tuner.

Radio input devices have exactly one tuner with index zero, no video inputs.

To query and change tuner properties applications use the [VIDIOC_G_TUNER](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-tuner.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and [VIDIOC_S_TUNER](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-tuner.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctls, respectively. The struct `v4l2_tuner` returned by [VIDIOC_G_TUNER](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-tuner.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) also contains signal status information applicable when the tuner of the current video or radio input is queried.

> [!NOTE]
>
> [VIDIOC_S_TUNER](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-tuner.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) does not switch the current tuner, when there is more than one. The tuner is solely determined by the current video input. Drivers must support both ioctls and set the `V4L2_CAP_TUNER` flag in the struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl when the device has one or more tuners.

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

## Modulators

Video output devices can have one or more modulators, that modulate a video signal for radiation or connection to the antenna input of a TV set or video recorder. Each modulator is associated with one or more video outputs, depending on the number of RF connectors on the modulator. The `type` field of the respective struct `v4l2_output` returned by the [ioctl VIDIOC_ENUMOUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-vidioc-enumoutput>) ioctl is set to `V4L2_OUTPUT_TYPE_MODULATOR` and its `modulator` field contains the index number of the modulator.

Radio output devices have exactly one modulator with index zero, no video outputs.

A video or radio device cannot support both a tuner and a modulator. Two separate device nodes will have to be used for such hardware, one that supports the tuner functionality and one that supports the modulator functionality. The reason is a limitation with the [VIDIOC_S_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) ioctl where you cannot specify whether the frequency is for a tuner or a modulator.

To query and change modulator properties applications use the [VIDIOC_G_MODULATOR](</kernel/userspace/userspace-api/media-v4l/vidioc-g-modulator.md#rst-vidioc-g-modulator>) and [VIDIOC_S_MODULATOR](</kernel/userspace/userspace-api/media-v4l/vidioc-g-modulator.md#rst-vidioc-g-modulator>) ioctl. Note that [VIDIOC_S_MODULATOR](</kernel/userspace/userspace-api/media-v4l/vidioc-g-modulator.md#rst-vidioc-g-modulator>) does not switch the current modulator, when there is more than one at all. The modulator is solely determined by the current video output. Drivers must support both ioctls and set the `V4L2_CAP_MODULATOR` flag in the struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl when the device has one or more modulators.

<a id="rst-radio-frequency"></a>

## Radio Frequency

To get and set the tuner or modulator radio frequency applications use the [VIDIOC_G_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) and [VIDIOC_S_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) ioctl which both take a pointer to a struct `v4l2_frequency`. These ioctls are used for TV and radio devices alike. Drivers must support both ioctls when the tuner or modulator ioctls are supported, or when the device is a radio device.

---

# Function Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Function Reference.

<a id="rst-function-reference"></a>
<a id="rst-user-func"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

- [V4L2 close()](</kernel/userspace/userspace-api/media-v4l/func-close.md>)
- [V4L2 ioctl()](</kernel/userspace/userspace-api/media-v4l/func-ioctl.md>)
- [ioctl VIDIOC_CREATE_BUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md>)
- [ioctl VIDIOC_CROPCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md>)
- [ioctl VIDIOC_DBG_G_CHIP_INFO](</kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-chip-info.md>)
- [ioctl VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER](</kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md>)
- [ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md>)
- [ioctl VIDIOC_DQEVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md>)
- [ioctl VIDIOC_DV_TIMINGS_CAP, VIDIOC_SUBDEV_DV_TIMINGS_CAP](</kernel/userspace/userspace-api/media-v4l/vidioc-dv-timings-cap.md>)
- [ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD](</kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md>)
- [ioctl VIDIOC_ENUMAUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudio.md>)
- [ioctl VIDIOC_ENUMAUDOUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumaudioout.md>)
- [ioctl VIDIOC_ENUM_DV_TIMINGS, VIDIOC_SUBDEV_ENUM_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-dv-timings.md>)
- [ioctl VIDIOC_ENUM_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md>)
- [ioctl VIDIOC_ENUM_FRAMESIZES](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md>)
- [ioctl VIDIOC_ENUM_FRAMEINTERVALS](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md>)
- [ioctl VIDIOC_ENUM_FREQ_BANDS](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md>)
- [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md>)
- [ioctl VIDIOC_ENUMOUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md>)
- [vidioc-enumstd](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ioctl VIDIOC_EXPBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-expbuf.md>)
- [ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md>)
- [ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audioout.md>)
- [ioctl VIDIOC_G_CROP, VIDIOC_S_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md>)
- [ioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md>)
- [ioctl VIDIOC_G_DV_TIMINGS, VIDIOC_S_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md>)
- [ioctl VIDIOC_G_EDID, VIDIOC_S_EDID, VIDIOC_SUBDEV_G_EDID, VIDIOC_SUBDEV_S_EDID](</kernel/userspace/userspace-api/media-v4l/vidioc-g-edid.md>)
- [ioctl VIDIOC_G_ENC_INDEX](</kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md>)
- [vidioc-g-ext-ctrls](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-fbuf.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md>)
- [ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md>)
- [ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md>)
- [ioctl VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP](</kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md>)
- [ioctl VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR](</kernel/userspace/userspace-api/media-v4l/vidioc-g-modulator.md>)
- [ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-output.md>)
- [ioctl VIDIOC_G_PARM, VIDIOC_S_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md>)
- [ioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md>)
- [ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION](</kernel/userspace/userspace-api/media-v4l/vidioc-g-selection.md>)
- [vidioc-g-sliced-vbi-cap](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-sliced-vbi-cap.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ioctl VIDIOC_G_STD, VIDIOC_S_STD, VIDIOC_SUBDEV_G_STD, VIDIOC_SUBDEV_S_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md>)
- [vidioc-g-tuner](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-tuner.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ioctl VIDIOC_LOG_STATUS](</kernel/userspace/userspace-api/media-v4l/vidioc-log-status.md>)
- [ioctl VIDIOC_OVERLAY](</kernel/userspace/userspace-api/media-v4l/vidioc-overlay.md>)
- [ioctl VIDIOC_PREPARE_BUF](</kernel/userspace/userspace-api/media-v4l/vidioc-prepare-buf.md>)
- [ioctl VIDIOC_QBUF, VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md>)
- [ioctl VIDIOC_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md>)
- [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md>)
- [vidioc-queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ioctl VIDIOC_QUERY_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-query-dv-timings.md>)
- [ioctl VIDIOC_QUERYSTD, VIDIOC_SUBDEV_QUERYSTD](</kernel/userspace/userspace-api/media-v4l/vidioc-querystd.md>)
- [vidioc-reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ioctl VIDIOC_REMOVE_BUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-remove-bufs.md>)
- [ioctl VIDIOC_S_HW_FREQ_SEEK](</kernel/userspace/userspace-api/media-v4l/vidioc-s-hw-freq-seek.md>)
- [ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md>)
- [ioctl VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-enum-frame-interval.md>)
- [ioctl VIDIOC_SUBDEV_ENUM_FRAME_SIZE](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-enum-frame-size.md>)
- [vidioc-subdev-enum-mbus-code](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-subdev-enum-mbus-code.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [ioctl VIDIOC_SUBDEV_G_CROP, VIDIOC_SUBDEV_S_CROP](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-crop.md>)
- [ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md>)
- [ioctl VIDIOC_SUBDEV_G_FRAME_INTERVAL, VIDIOC_SUBDEV_S_FRAME_INTERVAL](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-frame-interval.md>)
- [ioctl VIDIOC_SUBDEV_G_ROUTING, VIDIOC_SUBDEV_S_ROUTING](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-routing.md>)
- [ioctl VIDIOC_SUBDEV_G_SELECTION, VIDIOC_SUBDEV_S_SELECTION](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-selection.md>)
- [ioctl VIDIOC_SUBDEV_G_CLIENT_CAP, VIDIOC_SUBDEV_S_CLIENT_CAP](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-client-cap.md>)
- [ioctl VIDIOC_SUBDEV_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-querycap.md>)
- [ioctl VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md>)
- [V4L2 mmap()](</kernel/userspace/userspace-api/media-v4l/func-mmap.md>)
- [V4L2 munmap()](</kernel/userspace/userspace-api/media-v4l/func-munmap.md>)
- [V4L2 open()](</kernel/userspace/userspace-api/media-v4l/func-open.md>)
- [V4L2 poll()](</kernel/userspace/userspace-api/media-v4l/func-poll.md>)
- [V4L2 read()](</kernel/userspace/userspace-api/media-v4l/func-read.md>)
- [V4L2 select()](</kernel/userspace/userspace-api/media-v4l/func-select.md>)
- [V4L2 write()](</kernel/userspace/userspace-api/media-v4l/func-write.md>)

---

# Streaming I/O (User Pointers)

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Input and output devices support this I/O method when the V4L2_CAP_STREAMING flag in the capabilities field of struct v4l2_capability returned by the VIDIOC_QUERYCAP ioctl is set. If the particular user pointer method (not only memory…

<a id="rst-streaming-i-o-user-pointers"></a>
<a id="rst-userp"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Input and output devices support this I/O method when the `V4L2_CAP_STREAMING` flag in the `capabilities` field of struct `v4l2_capability` returned by the [ioctl VIDIOC_QUERYCAP](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl is set. If the particular user pointer method (not only memory mapping) is supported must be determined by calling the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl with the memory type set to `V4L2_MEMORY_USERPTR`.

This I/O method combines advantages of the read/write and memory mapping methods. Buffers (planes) are allocated by the application itself, and can reside for example in virtual or shared memory. Only pointers to data are exchanged, these pointers and meta-information are passed in struct `v4l2_buffer` (or in struct `v4l2_plane` in the multi-planar API case). The driver must be switched into user pointer I/O mode by calling the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) with the desired buffer type. No buffers (planes) are allocated beforehand, consequently they are not indexed and cannot be queried like mapped buffers with the [VIDIOC_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>) ioctl.

<a id="rst-example-initiating-streaming-i-o-with-user-pointers"></a>

## Example: Initiating streaming I/O with user pointers



```c
struct v4l2_requestbuffers reqbuf;

memset (&reqbuf, 0, sizeof (reqbuf));
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
reqbuf.memory = V4L2_MEMORY_USERPTR;

if (ioctl (fd, VIDIOC_REQBUFS, &reqbuf) == -1) {
    if (errno == EINVAL)
        printf ("Video capturing or user pointer streaming is not supported\\n");
    else
        perror ("VIDIOC_REQBUFS");

    exit (EXIT_FAILURE);
}
```

Buffer (plane) addresses and sizes are passed on the fly with the [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. Although buffers are commonly cycled, applications can pass different addresses and sizes at each [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) call. If required by the hardware the driver swaps memory pages within physical memory to create a continuous area of memory. This happens transparently to the application in the virtual memory subsystem of the kernel. When buffer pages have been swapped out to disk they are brought back and finally locked in physical memory for DMA. <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

Filled or displayed buffers are dequeued with the [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl. The driver can unlock the memory pages at any time between the completion of the DMA and this ioctl. The memory is also unlocked when [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) is called, [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), or when the device is closed. Applications must take care not to free buffers without dequeuing. Firstly, the buffers remain locked for longer, wasting physical memory. Secondly the driver will not be notified when the memory is returned to the application's free list and subsequently reused for other purposes, possibly completing the requested DMA and overwriting valuable data.

For capturing applications it is customary to enqueue a number of empty buffers, to start capturing and enter the read loop. Here the application waits until a filled buffer can be dequeued, and re-enqueues the buffer when the data is no longer needed. Output applications fill and enqueue buffers, when enough buffers are stacked up output is started. In the write loop, when the application runs out of free buffers it must wait until an empty buffer can be dequeued and reused. Two methods exist to suspend execution of the application until one or more buffers can be dequeued. By default [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) blocks when no buffer is in the outgoing queue. When the `O_NONBLOCK` flag was given to the `open()` function, [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) returns immediately with an `EAGAIN` error code when no buffer is available. The [select()](</kernel/userspace/userspace-api/media-v4l/func-select.md#rst-func-select>) or `poll()` function are always available.

To start and stop capturing or output applications call the [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) and [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctl.

> [!NOTE]
>
> [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) removes all buffers from both queues and unlocks all buffers as a side effect. Since there is no notion of doing anything "now" on a multitasking system, if an application needs to synchronize with another event it should examine the struct `v4l2_buffer` `timestamp` of captured or outputted buffers.

Drivers implementing user pointer I/O must support the [VIDIOC_REQBUFS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>), [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) and [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) ioctls, the `select()` and `poll()` function. <a id="rst-footnote-reference-2"></a>[2](#rst-f2)

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



**[1]** We expect that frequently used buffers are typically not swapped out. Anyway, the process of swapping, locking or generating scatter-gather lists may be time consuming. The delay can be masked by the depth of the incoming buffer queue, and perhaps by maintaining caches assuming a buffer will be soon enqueued again. On the other hand, to optimize memory usage drivers can limit the number of buffers locked in advance and recycle the most recently used buffers first. Of course, the pages of empty buffers in the incoming queue need not be saved to disk. Output buffers must be saved on the incoming and outgoing queue because an application may share them with other processes.

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



**[2]** At the driver level `select()` and `poll()` are the same, and `select()` is too important to be optional. The rest should be evident.

---

# Generic V4L2 ISP formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Generic ISP formats are metadata formats that define a mechanism to pass ISP parameters and statistics between userspace and drivers in V4L2 buffers. They are designed to allow extending them in a backward-compatible way.

<a id="rst-generic-v4l2-isp-formats"></a>
<a id="rst-v4l2-isp"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

Generic ISP formats are metadata formats that define a mechanism to pass ISP parameters and statistics between userspace and drivers in V4L2 buffers. They are designed to allow extending them in a backward-compatible way.

<a id="rst-isp-parameters"></a>

## ISP parameters

The generic ISP configuration parameters format is realized by a defining a single C structure that contains a header, followed by a binary buffer where userspace programs a variable number of ISP configuration data block, one for each supported ISP feature.

The `v4l2_isp_params_buffer` structure defines the buffer header which is followed by a binary buffer of ISP configuration data. Userspace shall correctly populate the buffer header with the generic parameters format version and with the size (in bytes) of the binary data buffer where it will store the ISP blocks configuration.

Each *ISP configuration block* is preceded by an header implemented by the `v4l2_isp_params_block_header` structure, followed by the configuration parameters for that specific block, defined by the ISP driver specific data types.

Userspace applications are responsible for correctly populating each block's header fields (type, flags and size) and the block-specific parameters.

<a id="rst-isp-block-enabling-disabling-and-configuration"></a>

### ISP block enabling, disabling and configuration

When userspace wants to configure and enable an ISP block it shall fully populate the block configuration and set the V4L2_ISP_PARAMS_FL_BLOCK_ENABLE bit in the block header's `flags` field.

When userspace simply wants to disable an ISP block the V4L2_ISP_PARAMS_FL_BLOCK_DISABLE bit should be set in block header's `flags` field. Drivers accept a configuration parameters block with no additional data after the header in this case.

If the configuration of an already active ISP block has to be updated, userspace shall fully populate the ISP block parameters and omit setting the V4L2_ISP_PARAMS_FL_BLOCK_ENABLE and V4L2_ISP_PARAMS_FL_BLOCK_DISABLE bits in the header's `flags` field.

Setting both the V4L2_ISP_PARAMS_FL_BLOCK_ENABLE and V4L2_ISP_PARAMS_FL_BLOCK_DISABLE bits in the flags field is not allowed and returns an error.

Extension to the parameters format can be implemented by adding new blocks definition without invalidating the existing ones.

<a id="rst-isp-statistics"></a>

## ISP statistics

Support for generic statistics format is not yet implemented in Video4Linux2.

<a id="rst-v4l2-isp-uapi-data-types"></a>

## V4L2 ISP uAPI data types


#### <a id="c-enum-v4l2_isp_params_version"></a>`enum v4l2_isp_params_version`

V4L2 ISP parameters versioning

**Constants**

- `V4L2_ISP_PARAMS_VERSION_V0`: First version of the V4L2 ISP parameters format
  (for compatibility)
- `V4L2_ISP_PARAMS_VERSION_V1`: First version of the V4L2 ISP parameters format

**Description**

V0 and V1 are identical in order to support drivers compatible with the V4L2
ISP parameters format already upstreamed which use either 0 or 1 as their
versioning identifier. Both V0 and V1 refers to the first version of the
V4L2 ISP parameters format.

Future revisions of the V4L2 ISP parameters format should start from the
value of 2.

#### <a id="c-struct-v4l2_isp_params_block_header"></a>`struct v4l2_isp_params_block_header`

V4L2 extensible parameters block header

**Definition**

```c
struct v4l2_isp_params_block_header {
    __u16 type;
    __u16 flags;
    __u32 size;
};
```

**Members**

- `type`: The parameters block type (driver-specific)
- `flags`: A bitmask of block flags (driver-specific)
- `size`: Size (in bytes) of the parameters block, including this header

**Description**

This structure represents the common part of all the ISP configuration
blocks. Each parameters block shall embed an instance of this structure type
as its first member, followed by the block-specific configuration data.

The **type** field is an ISP driver-specific value that identifies the block
type. The **size** field specifies the size of the parameters block.

The **flags** field is a bitmask of per-block flags V4L2_PARAMS_ISP_FL_* and
driver-specific flags specified by the driver header.

#### <a id="c-struct-v4l2_isp_params_buffer"></a>`struct v4l2_isp_params_buffer`

V4L2 extensible parameters configuration

**Definition**

```c
struct v4l2_isp_params_buffer {
    __u32 version;
    __u32 data_size;
    __u8 data[] ;
};
```

**Members**

- `version`: The parameters buffer version (driver-specific)
- `data_size`: The configuration data effective size, excluding this header
- `data`: The configuration data

**Description**

This structure contains the configuration parameters of the ISP algorithms,
serialized by userspace into a data buffer. Each configuration parameter
block is represented by a block-specific structure which contains a
[`v4l2_isp_params_block_header`](#c-struct-v4l2_isp_params_block_header) entry as first member. Userspace
populates the **data** buffer with configuration parameters for the blocks that
it intends to configure. As a consequence, the data buffer effective size
changes according to the number of ISP blocks that userspace intends to
configure and is set by userspace in the **data_size** field.

The parameters buffer is versioned by the **version** field to allow modifying
and extending its definition. Userspace shall populate the **version** field to
inform the driver about the version it intends to use. The driver will parse
and handle the **data** buffer according to the data layout specific to the
indicated version and return an error if the desired version is not
supported.

For each ISP block that userspace wants to configure, a block-specific
structure is appended to the **data** buffer, one after the other without gaps
in between. Userspace shall populate the **data_size** field with the effective
size, in bytes, of the **data** buffer.

---

# Selection flags

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Selection flags.

<a id="rst-selection-flags"></a>
<a id="rst-v4l2-selection-flags"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-v4l2-selection-flags-table"></a>



<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{5.6cm}|p{2.0cm}|p{6.5cm}|p{1.2cm}|p{1.2cm}| -->


<table>
<caption>

Selection flag definitions

</caption>
<thead>
<tr>
<th>



Flag name

</th>
<th>



id

</th>
<th>



Definition

</th>
<th>



Valid for V4L2

</th>
<th>



Valid for V4L2 subdev

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_SEL_FLAG_GE`

</td>
<td>



(1 &lt;&lt; 0)

</td>
<td>



Suggest the driver it should choose greater or equal rectangle (in size) than was requested. Albeit the driver may choose a lesser size, it will only do so due to hardware limitations. Without this flag (and `V4L2_SEL_FLAG_LE`) the behaviour is to choose the closest possible rectangle.

</td>
<td>



Yes

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



`V4L2_SEL_FLAG_LE`

</td>
<td>



(1 &lt;&lt; 1)

</td>
<td>



Suggest the driver it should choose lesser or equal rectangle (in size) than was requested. Albeit the driver may choose a greater size, it will only do so due to hardware limitations.

</td>
<td>



Yes

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



`V4L2_SEL_FLAG_KEEP_CONFIG`

</td>
<td>



(1 &lt;&lt; 2)

</td>
<td>



The configuration must not be propagated to any further processing steps. If this flag is not given, the configuration is propagated inside the subdevice to all further processing steps.

</td>
<td>



No

</td>
<td>



Yes

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

---

# Selection targets

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> The precise meaning of the selection targets may be dependent on which of the two interfaces they are used.

<a id="rst-selection-targets"></a>
<a id="rst-v4l2-selection-targets"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

The precise meaning of the selection targets may be dependent on which of the two interfaces they are used.

<a id="rst-v4l2-selection-targets-table"></a>



<!-- Source LaTeX layout: \small -->

<!-- tabularcolumns: |p{6.2cm}|p{1.4cm}|p{7.3cm}|p{1.2cm}|p{0.8cm}| -->


<table>
<caption>

Selection target definitions

</caption>
<thead>
<tr>
<th>



Target name

</th>
<th>



id

</th>
<th>



Definition

</th>
<th>



Valid for V4L2

</th>
<th>



Valid for V4L2 subdev

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_SEL_TGT_CROP`

</td>
<td>



0x0000

</td>
<td>



Crop rectangle. Defines the cropped area.

</td>
<td>



Yes

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



`V4L2_SEL_TGT_CROP_DEFAULT`

</td>
<td>



0x0001

</td>
<td>



Suggested cropping rectangle that covers the "whole picture". This includes only active pixels and excludes other non-active pixels such as black pixels.

</td>
<td>



Yes

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



`V4L2_SEL_TGT_CROP_BOUNDS`

</td>
<td>



0x0002

</td>
<td>



Bounds of the crop rectangle. All valid crop rectangles fit inside the crop bounds rectangle.

</td>
<td>



Yes

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



`V4L2_SEL_TGT_NATIVE_SIZE`

</td>
<td>



0x0003

</td>
<td>



The native size of the device, e.g. a sensor's pixel array. `left` and `top` fields are zero for this target.

</td>
<td>



Yes

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



`V4L2_SEL_TGT_COMPOSE`

</td>
<td>



0x0100

</td>
<td>



Compose rectangle. Used to configure scaling and composition.

</td>
<td>



Yes

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



`V4L2_SEL_TGT_COMPOSE_DEFAULT`

</td>
<td>



0x0101

</td>
<td>



Suggested composition rectangle that covers the "whole picture".

</td>
<td>



Yes

</td>
<td>



No

</td>
</tr>
<tr>
<td>



`V4L2_SEL_TGT_COMPOSE_BOUNDS`

</td>
<td>



0x0102

</td>
<td>



Bounds of the compose rectangle. All valid compose rectangles fit inside the compose bounds rectangle.

</td>
<td>



Yes

</td>
<td>



Yes

</td>
</tr>
<tr>
<td>



`V4L2_SEL_TGT_COMPOSE_PADDED`

</td>
<td>



0x0103

</td>
<td>



The active area and all padding pixels that are inserted or modified by hardware.

</td>
<td>



Yes

</td>
<td>



No

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

---

# Part I - Video for Linux API

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> This part describes the Video for Linux API version 2 (V4L2 API) specification.

<a id="rst-part-i-video-for-linux-api"></a>
<a id="rst-v4l2spec"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

This part describes the Video for Linux API version 2 (V4L2 API) specification.

**Revision 4.5**

**Table of Contents**

1. [Common API Elements](</kernel/userspace/userspace-api/media-v4l/common.md>)
2. [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md>)
3. [Input/Output](</kernel/userspace/userspace-api/media-v4l/io.md>)
4. [Interfaces](</kernel/userspace/userspace-api/media-v4l/devices.md>)
5. [Libv4l Userspace Library](</kernel/userspace/userspace-api/media-v4l/libv4l.md>)
6. [Changes](</kernel/userspace/userspace-api/media-v4l/compat.md>)
7. [Function Reference](</kernel/userspace/userspace-api/media-v4l/user-func.md>)
8. [Common definitions for V4L2 and V4L2 subdev interfaces](</kernel/userspace/userspace-api/media-v4l/common-defs.md>)
9. [videodev](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/videodev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
10. [Video Capture Example](</kernel/userspace/userspace-api/media-v4l/capture-example.md>)
11. [Video Grabber example using libv4l](</kernel/userspace/userspace-api/media-v4l/v4l2grab-example.md>)
12. [References](</kernel/userspace/userspace-api/media-v4l/biblio.md>)

<a id="rst-revision-and-copyright"></a>

## Revision and Copyright

Authors, in alphabetical order:

- Ailus, Sakari &lt;[sakari.ailus@iki.fi](<mailto:sakari.ailus@iki.fi>)&gt;

  - Subdev selections API.

- Carvalho Chehab, Mauro &lt;[mchehab+samsung@kernel.org](<mailto:mchehab+samsung@kernel.org>)&gt;

  - Documented libv4l, designed and added v4l2grab example, Remote Controller chapter.

- Dirks, Bill

  - Original author of the V4L2 API and documentation.

- Figa, Tomasz &lt;[tfiga@chromium.org](<mailto:tfiga@chromium.org>)&gt;

  - Documented the memory-to-memory decoder interface.

  - Documented the memory-to-memory encoder interface.

- H Schimek, Michael &lt;[mschimek@gmx.at](<mailto:mschimek@gmx.at>)&gt;

  - Original author of the V4L2 API and documentation.

- Karicheri, Muralidharan &lt;[m-karicheri2@ti.com](<mailto:m-karicheri2@ti.com>)&gt;

  - Documented the Digital Video timings API.

- Osciak, Pawel &lt;[posciak@chromium.org](<mailto:posciak@chromium.org>)&gt;

  - Documented the memory-to-memory decoder interface.

  - Documented the memory-to-memory encoder interface.

- Osciak, Pawel &lt;[pawel@osciak.com](<mailto:pawel@osciak.com>)&gt;

  - Designed and documented the multi-planar API.

- Palosaari, Antti &lt;[crope@iki.fi](<mailto:crope@iki.fi>)&gt;

  - SDR API.

- Ribalda, Ricardo

  - Introduce HSV formats and other minor changes.

- Rubli, Martin

  - Designed and documented the VIDIOC_ENUM_FRAMESIZES and VIDIOC_ENUM_FRAMEINTERVALS ioctls.

- Walls, Andy &lt;[awalls@md.metrocast.net](<mailto:awalls@md.metrocast.net>)&gt;

  - Documented the fielded V4L2_MPEG_STREAM_VBI_FMT_IVTV MPEG stream embedded, sliced VBI data format in this specification.

- Verkuil, Hans &lt;[hverkuil@kernel.org](<mailto:hverkuil@kernel.org>)&gt;

  - Designed and documented the VIDIOC_LOG_STATUS ioctl, the extended control ioctls, major parts of the sliced VBI API, the MPEG encoder and decoder APIs and the DV Timings API.

**Copyright** © 1999-2018: Bill Dirks, Michael H. Schimek, Hans Verkuil, Martin Rubli, Andy Walls, Muralidharan Karicheri, Mauro Carvalho Chehab, Pawel Osciak, Sakari Ailus &amp; Antti Palosaari, Tomasz Figa

Except when explicitly stated as GPL, programming examples within this part can be used and distributed without restrictions.

<a id="rst-revision-history"></a>

## Revision History

**revision:** 4.10 / 2016-07-15 (*rr*)

Introduce HSV formats.

**revision:** 4.5 / 2015-10-29 (*rr*)

Extend VIDIOC_G_EXT_CTRLS;. Replace ctrl_class with a new union with ctrl_class and which. Which is used to select the current value of the control or the default value.

**revision:** 4.4 / 2015-05-26 (*ap*)

Renamed V4L2_TUNER_ADC to V4L2_TUNER_SDR. Added V4L2_CID_RF_TUNER_RF_GAIN control. Added transmitter support for Software Defined Radio (SDR) Interface.

**revision:** 4.1 / 2015-02-13 (*mcc*)

Fix documentation for media controller device nodes and add support for DVB device nodes. Add support for Tuner sub-device.

**revision:** 3.19 / 2014-12-05 (*hv*)

Rewrote Colorspace chapter, added new enum `v4l2_ycbcr_encoding` and enum `v4l2_quantization` fields to struct `v4l2_pix_format`, struct `v4l2_pix_format_mplane` and struct `v4l2_mbus_framefmt`.

**revision:** 3.17 / 2014-08-04 (*lp, hv*)

Extended struct `v4l2_pix_format`. Added format flags. Added compound control types and VIDIOC_QUERY_EXT_CTRL.

**revision:** 3.15 / 2014-02-03 (*hv, ap*)

Update several sections of "Common API Elements": "Opening and Closing Devices" "Querying Capabilities", "Application Priority", "Video Inputs and Outputs", "Audio Inputs and Outputs" "Tuners and Modulators", "Video Standards" and "Digital Video (DV) Timings". Added SDR API.

**revision:** 3.14 / 2013-11-25 (*rr*)

Set width and height as unsigned on v4l2_rect.

**revision:** 3.11 / 2013-05-26 (*hv*)

Remove obsolete VIDIOC_DBG_G_CHIP_IDENT ioctl.

**revision:** 3.10 / 2013-03-25 (*hv*)

Remove obsolete and unused DV_PRESET ioctls: VIDIOC_G_DV_PRESET, VIDIOC_S_DV_PRESET, VIDIOC_QUERY_DV_PRESET and VIDIOC_ENUM_DV_PRESET. Remove the related v4l2_input/output capability flags V4L2_IN_CAP_PRESETS and V4L2_OUT_CAP_PRESETS. Added VIDIOC_DBG_G_CHIP_INFO.

**revision:** 3.9 / 2012-12-03 (*sa, sn*)

Added timestamp types to v4l2_buffer. Added V4L2_EVENT_CTRL_CH_RANGE control event changes flag.

**revision:** 3.6 / 2012-07-02 (*hv*)

Added VIDIOC_ENUM_FREQ_BANDS.

**revision:** 3.5 / 2012-05-07 (*sa, sn, hv*)

Added V4L2_CTRL_TYPE_INTEGER_MENU and V4L2 subdev selections API. Improved the description of V4L2_CID_COLORFX control, added V4L2_CID_COLORFX_CBCR control. Added camera controls V4L2_CID_AUTO_EXPOSURE_BIAS, V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE, V4L2_CID_IMAGE_STABILIZATION, V4L2_CID_ISO_SENSITIVITY, V4L2_CID_ISO_SENSITIVITY_AUTO, V4L2_CID_EXPOSURE_METERING, V4L2_CID_SCENE_MODE, V4L2_CID_3A_LOCK, V4L2_CID_AUTO_FOCUS_START, V4L2_CID_AUTO_FOCUS_STOP, V4L2_CID_AUTO_FOCUS_STATUS and V4L2_CID_AUTO_FOCUS_RANGE. Added VIDIOC_ENUM_DV_TIMINGS, VIDIOC_QUERY_DV_TIMINGS and VIDIOC_DV_TIMINGS_CAP.

**revision:** 3.4 / 2012-01-25 (*sn*)

Added [JPEG compression control class.](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-jpeg.md#rst-jpeg-controls>)

**revision:** 3.3 / 2012-01-11 (*hv*)

Added device_caps field to struct v4l2_capabilities.

**revision:** 3.2 / 2011-08-26 (*hv*)

Added V4L2_CTRL_FLAG_VOLATILE.

**revision:** 3.1 / 2011-06-27 (*mcc, po, hv*)

Documented that VIDIOC_QUERYCAP now returns a per-subsystem version instead of a per-driver one. Standardize an error code for invalid ioctl. Added V4L2_CTRL_TYPE_BITMASK.

**revision:** 2.6.39 / 2011-03-01 (*mcc, po*)

Removed VIDIOC\_\*\_OLD from videodev2.h header and update it to reflect latest changes. Added the [multi-planar API](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>).

**revision:** 2.6.37 / 2010-08-06 (*hv*)

Removed obsolete vtx (videotext) API.

**revision:** 2.6.33 / 2009-12-03 (*mk*)

Added documentation for the Digital Video timings API.

**revision:** 2.6.32 / 2009-08-31 (*mcc*)

Now, revisions will match the kernel version where the V4L2 API changes will be used by the Linux Kernel. Also added Remote Controller chapter.

**revision:** 0.29 / 2009-08-26 (*ev*)

Added documentation for string controls and for FM Transmitter controls.

**revision:** 0.28 / 2009-08-26 (*gl*)

Added V4L2_CID_BAND_STOP_FILTER documentation.

**revision:** 0.27 / 2009-08-15 (*mcc*)

Added libv4l and Remote Controller documentation; added v4l2grab and keytable application examples.

**revision:** 0.26 / 2009-07-23 (*hv*)

Finalized the RDS capture API. Added modulator and RDS encoder capabilities. Added support for string controls.

**revision:** 0.25 / 2009-01-18 (*hv*)

Added pixel formats VYUY, NV16 and NV61, and changed the debug ioctls VIDIOC_DBG_G/S_REGISTER and VIDIOC_DBG_G_CHIP_IDENT. Added camera controls V4L2_CID_ZOOM_ABSOLUTE, V4L2_CID_ZOOM_RELATIVE, V4L2_CID_ZOOM_CONTINUOUS and V4L2_CID_PRIVACY.

**revision:** 0.24 / 2008-03-04 (*mhs*)

Added pixel formats Y16 and SBGGR16, new controls and a camera controls class. Removed VIDIOC_G/S_MPEGCOMP.

**revision:** 0.23 / 2007-08-30 (*mhs*)

Fixed a typo in VIDIOC_DBG_G/S_REGISTER. Clarified the byte order of packed pixel formats.

**revision:** 0.22 / 2007-08-29 (*mhs*)

Added the Video Output Overlay interface, new MPEG controls, V4L2_FIELD_INTERLACED_TB and V4L2_FIELD_INTERLACED_BT, VIDIOC_DBG_G/S_REGISTER, VIDIOC\_(TRY\_)ENCODER_CMD, VIDIOC_G_CHIP_IDENT, VIDIOC_G_ENC_INDEX, new pixel formats. Clarifications in the cropping chapter, about RGB pixel formats, the mmap(), poll(), select(), read() and write() functions. Typographical fixes.

**revision:** 0.21 / 2006-12-19 (*mhs*)

Fixed a link in the VIDIOC_G_EXT_CTRLS section.

**revision:** 0.20 / 2006-11-24 (*mhs*)

Clarified the purpose of the audioset field in struct v4l2_input and v4l2_output.

**revision:** 0.19 / 2006-10-19 (*mhs*)

Documented V4L2_PIX_FMT_RGB444.

**revision:** 0.18 / 2006-10-18 (*mhs*)

Added the description of extended controls by Hans Verkuil. Linked V4L2_PIX_FMT_MPEG to V4L2_CID_MPEG_STREAM_TYPE.

**revision:** 0.17 / 2006-10-12 (*mhs*)

Corrected V4L2_PIX_FMT_HM12 description.

**revision:** 0.16 / 2006-10-08 (*mhs*)

VIDIOC_ENUM_FRAMESIZES and VIDIOC_ENUM_FRAMEINTERVALS are now part of the API.

**revision:** 0.15 / 2006-09-23 (*mhs*)

Cleaned up the bibliography, added BT.653 and BT.1119. capture.c/start_capturing() for user pointer I/O did not initialize the buffer index. Documented the V4L MPEG and MJPEG VID_TYPEs and V4L2_PIX_FMT_SBGGR8. Updated the list of reserved pixel formats. See the history chapter for API changes.

**revision:** 0.14 / 2006-09-14 (*mr*)

Added VIDIOC_ENUM_FRAMESIZES and VIDIOC_ENUM_FRAMEINTERVALS proposal for frame format enumeration of digital devices.

**revision:** 0.13 / 2006-04-07 (*mhs*)

Corrected the description of struct v4l2_window clips. New V4L2_STD\_ and V4L2_TUNER_MODE_LANG1_LANG2 defines.

**revision:** 0.12 / 2006-02-03 (*mhs*)

Corrected the description of struct v4l2_captureparm and v4l2_outputparm.

**revision:** 0.11 / 2006-01-27 (*mhs*)

Improved the description of struct v4l2_tuner.

**revision:** 0.10 / 2006-01-10 (*mhs*)

VIDIOC_G_INPUT and VIDIOC_S_PARM clarifications.

**revision:** 0.9 / 2005-11-27 (*mhs*)

Improved the 525 line numbering diagram. Hans Verkuil and I rewrote the sliced VBI section. He also contributed a VIDIOC_LOG_STATUS page. Fixed VIDIOC_S_STD call in the video standard selection example. Various updates.

**revision:** 0.8 / 2004-10-04 (*mhs*)

Somehow a piece of junk slipped into the capture example, removed.

**revision:** 0.7 / 2004-09-19 (*mhs*)

Fixed video standard selection, control enumeration, downscaling and aspect example. Added read and user pointer i/o to video capture example.

**revision:** 0.6 / 2004-08-01 (*mhs*)

v4l2_buffer changes, added video capture example, various corrections.

**revision:** 0.5 / 2003-11-05 (*mhs*)

Pixel format erratum.

**revision:** 0.4 / 2003-09-17 (*mhs*)

Corrected source and Makefile to generate a PDF. SGML fixes. Added latest API changes. Closed gaps in the history chapter.

**revision:** 0.3 / 2003-02-05 (*mhs*)

Another draft, more corrections.

**revision:** 0.2 / 2003-01-15 (*mhs*)

Second draft, with corrections pointed out by Gerd Knorr.

**revision:** 0.1 / 2002-12-01 (*mhs*)

First draft, based on documentation by Bill Dirks and discussions on the V4L mailing list.

---

# Video Grabber example using libv4l

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> This program demonstrates how to grab V4L2 images in ppm format by using libv4l handlers. The advantage is that this grabber can potentially work with any V4L2 driver.

<a id="rst-video-grabber-example-using-libv4l"></a>
<a id="rst-v4l2grab-example"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

This program demonstrates how to grab V4L2 images in ppm format by using libv4l handlers. The advantage is that this grabber can potentially work with any V4L2 driver.

- [file: media/v4l/v4l2grab.c](</kernel/userspace/userspace-api/media-v4l/v4l2grab-c.md>)

---

# file: media/v4l/v4l2grab.c

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for file: media/v4l/v4l2grab.c.

<a id="rst-file-media-v4l-v4l2grab-c"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->



```c
/* V4L2 video picture grabber
   Copyright (C) 2009 Mauro Carvalho Chehab <mchehab@kernel.org>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include "../libv4l/include/libv4l2.h"

#define CLEAR(x) memset(&(x), 0, sizeof(x))

struct buffer {
        void   *start;
        size_t length;
};

static void xioctl(int fh, int request, void *arg)
{
        int r;

        do {
                r = v4l2_ioctl(fh, request, arg);
        } while (r == -1 && ((errno == EINTR) || (errno == EAGAIN)));

        if (r == -1) {
                fprintf(stderr, "error %d, %s\n", errno, strerror(errno));
                exit(EXIT_FAILURE);
        }
}

int main(int argc, char **argv)
{
        struct v4l2_format              fmt;
        struct v4l2_buffer              buf;
        struct v4l2_requestbuffers      req;
        enum v4l2_buf_type              type;
        fd_set                          fds;
        struct timeval                  tv;
        int                             r, fd = -1;
        unsigned int                    i, n_buffers;
        char                            *dev_name = "/dev/video0";
        char                            out_name[256];
        FILE                            *fout;
        struct buffer                   *buffers;

        fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0);
        if (fd < 0) {
                perror("Cannot open device");
                exit(EXIT_FAILURE);
        }

        CLEAR(fmt);
        fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        fmt.fmt.pix.width       = 640;
        fmt.fmt.pix.height      = 480;
        fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
        fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
        xioctl(fd, VIDIOC_S_FMT, &fmt);
        if (fmt.fmt.pix.pixelformat != V4L2_PIX_FMT_RGB24) {
                printf("Libv4l didn't accept RGB24 format. Can't proceed.\n");
                exit(EXIT_FAILURE);
        }
        if ((fmt.fmt.pix.width != 640) || (fmt.fmt.pix.height != 480))
                printf("Warning: driver is sending image at %dx%d\n",
                        fmt.fmt.pix.width, fmt.fmt.pix.height);

        CLEAR(req);
        req.count = 2;
        req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        req.memory = V4L2_MEMORY_MMAP;
        xioctl(fd, VIDIOC_REQBUFS, &req);

        buffers = calloc(req.count, sizeof(*buffers));
        for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
                CLEAR(buf);

                buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory      = V4L2_MEMORY_MMAP;
                buf.index       = n_buffers;

                xioctl(fd, VIDIOC_QUERYBUF, &buf);

                buffers[n_buffers].length = buf.length;
                buffers[n_buffers].start = v4l2_mmap(NULL, buf.length,
                              PROT_READ | PROT_WRITE, MAP_SHARED,
                              fd, buf.m.offset);

                if (MAP_FAILED == buffers[n_buffers].start) {
                        perror("mmap");
                        exit(EXIT_FAILURE);
                }
        }

        for (i = 0; i < n_buffers; ++i) {
                CLEAR(buf);
                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_MMAP;
                buf.index = i;
                xioctl(fd, VIDIOC_QBUF, &buf);
        }
        type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

        xioctl(fd, VIDIOC_STREAMON, &type);
        for (i = 0; i < 20; i++) {
                do {
                        FD_ZERO(&fds);
                        FD_SET(fd, &fds);

                        /* Timeout. */
                        tv.tv_sec = 2;
                        tv.tv_usec = 0;

                        r = select(fd + 1, &fds, NULL, NULL, &tv);
                } while ((r == -1 && (errno == EINTR)));
                if (r == -1) {
                        perror("select");
                        return errno;
                }

                CLEAR(buf);
                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_MMAP;
                xioctl(fd, VIDIOC_DQBUF, &buf);

                sprintf(out_name, "out%03d.ppm", i);
                fout = fopen(out_name, "w");
                if (!fout) {
                        perror("Cannot open image");
                        exit(EXIT_FAILURE);
                }
                fprintf(fout, "P6\n%d %d 255\n",
                        fmt.fmt.pix.width, fmt.fmt.pix.height);
                fwrite(buffers[buf.index].start, buf.bytesused, 1, fout);
                fclose(fout);

                xioctl(fd, VIDIOC_QBUF, &buf);
        }

        type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        xioctl(fd, VIDIOC_STREAMOFF, &type);
        for (i = 0; i < n_buffers; ++i)
                v4l2_munmap(buffers[i].start, buffers[i].length);
        v4l2_close(fd);

        return 0;
}
```

---

# Video Inputs and Outputs

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Video inputs and outputs are physical connectors of a device. These can be for example: RF connectors (antenna/cable), CVBS a.k.a. Composite Video, S-Video and RGB connectors. Camera sensors are also considered to be a video input. Video…

<a id="rst-video-inputs-and-outputs"></a>
<a id="rst-video"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

Video inputs and outputs are physical connectors of a device. These can be for example: RF connectors (antenna/cable), CVBS a.k.a. Composite Video, S-Video and RGB connectors. Camera sensors are also considered to be a video input. Video and VBI capture devices have inputs. Video and VBI output devices have outputs, at least one each. Radio devices have no video inputs or outputs.

To learn about the number and attributes of the available inputs and outputs applications can enumerate them with the [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) and [ioctl VIDIOC_ENUMOUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-vidioc-enumoutput>) ioctl, respectively. The struct `v4l2_input` returned by the [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) ioctl also contains signal status information applicable when the current video input is queried.

The [VIDIOC_G_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input>) and [VIDIOC_G_OUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-output.md#rst-vidioc-g-output>) ioctls return the index of the current video input or output. To select a different input or output applications call the [VIDIOC_S_INPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input>) and [VIDIOC_S_OUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-output.md#rst-vidioc-g-output>) ioctls. Drivers must implement all the input ioctls when the device has one or more inputs, all the output ioctls when the device has one or more outputs.

<a id="rst-example-information-about-the-current-video-input"></a>

## Example: Information about the current video input



```c
struct v4l2_input input;
int index;

if (-1 == ioctl(fd, VIDIOC_G_INPUT, &index)) {
    perror("VIDIOC_G_INPUT");
    exit(EXIT_FAILURE);
}

memset(&input, 0, sizeof(input));
input.index = index;

if (-1 == ioctl(fd, VIDIOC_ENUMINPUT, &input)) {
    perror("VIDIOC_ENUMINPUT");
    exit(EXIT_FAILURE);
}

printf("Current input: %s\\n", input.name);
```

<a id="rst-example-switching-to-the-first-video-input"></a>

## Example: Switching to the first video input



```c
int index;

index = 0;

if (-1 == ioctl(fd, VIDIOC_S_INPUT, &index)) {
    perror("VIDIOC_S_INPUT");
    exit(EXIT_FAILURE);
}
```

---

# Video For Linux Two Header uAPI Symbols

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> Reference for Video For Linux Two Header uAPI Symbols.

<a id="rst-video-for-linux-two-header-uapi-symbols"></a>
<a id="rst-videodev"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->


## Enumeration values

- [`V4L2_BUF_TYPE_META_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 154
- [`V4L2_BUF_TYPE_META_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 155
- [`V4L2_BUF_TYPE_SDR_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 152
- [`V4L2_BUF_TYPE_SDR_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 153
- [`V4L2_BUF_TYPE_SLICED_VBI_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 147
- [`V4L2_BUF_TYPE_SLICED_VBI_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 148
- [`V4L2_BUF_TYPE_VBI_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 145
- [`V4L2_BUF_TYPE_VBI_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 146
- [`V4L2_BUF_TYPE_VIDEO_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 142
- [`V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 150
- [`V4L2_BUF_TYPE_VIDEO_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 143
- [`V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 151
- [`V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 149
- [`V4L2_BUF_TYPE_VIDEO_OVERLAY`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 144
- [`V4L2_COLORSPACE_470_SYSTEM_BG`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 234
- [`V4L2_COLORSPACE_470_SYSTEM_M`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 229
- [`V4L2_COLORSPACE_BT2020`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 249
- [`V4L2_COLORSPACE_DCI_P3`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 255
- [`V4L2_COLORSPACE_DEFAULT`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 208
- [`V4L2_COLORSPACE_JPEG`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 240
- [`V4L2_COLORSPACE_LAST`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 262
- [`V4L2_COLORSPACE_OPRGB`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 246
- [`V4L2_COLORSPACE_RAW`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 252
- [`V4L2_COLORSPACE_REC709`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 217
- [`V4L2_COLORSPACE_SMPTE170M`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 211
- [`V4L2_COLORSPACE_SMPTE240M`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 214
- [`V4L2_COLORSPACE_SRGB`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 243
- [`V4L2_CTRL_COMPOUND_TYPES`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl): `include/uapi/linux/videodev2.h`, line 1956
- [`V4L2_CTRL_TYPE_AREA`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1960
- [`V4L2_CTRL_TYPE_AV1_FILM_GRAIN`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1995
- [`V4L2_CTRL_TYPE_AV1_FRAME`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1994
- [`V4L2_CTRL_TYPE_AV1_SEQUENCE`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1992
- [`V4L2_CTRL_TYPE_AV1_TILE_GROUP_ENTRY`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1993
- [`V4L2_CTRL_TYPE_BITMASK`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1952
- [`V4L2_CTRL_TYPE_BOOLEAN`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1946
- [`V4L2_CTRL_TYPE_BUTTON`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1948
- [`V4L2_CTRL_TYPE_CTRL_CLASS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1950
- [`V4L2_CTRL_TYPE_FWHT_PARAMS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1973
- [`V4L2_CTRL_TYPE_H264_DECODE_PARAMS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1970
- [`V4L2_CTRL_TYPE_H264_PPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1967
- [`V4L2_CTRL_TYPE_H264_PRED_WEIGHTS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1971
- [`V4L2_CTRL_TYPE_H264_SCALING_MATRIX`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1968
- [`V4L2_CTRL_TYPE_H264_SLICE_PARAMS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1969
- [`V4L2_CTRL_TYPE_H264_SPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1966
- [`V4L2_CTRL_TYPE_HDR10_CLL_INFO`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1963
- [`V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1964
- [`V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1988
- [`V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1990
- [`V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1989
- [`V4L2_CTRL_TYPE_HEVC_PPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1985
- [`V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1987
- [`V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1986
- [`V4L2_CTRL_TYPE_HEVC_SPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1984
- [`V4L2_CTRL_TYPE_INTEGER`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1945
- [`V4L2_CTRL_TYPE_INTEGER64`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1949
- [`V4L2_CTRL_TYPE_INTEGER_MENU`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1953
- [`V4L2_CTRL_TYPE_MENU`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1947
- [`V4L2_CTRL_TYPE_MPEG2_PICTURE`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1979
- [`V4L2_CTRL_TYPE_MPEG2_QUANTISATION`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1977
- [`V4L2_CTRL_TYPE_MPEG2_SEQUENCE`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1978
- [`V4L2_CTRL_TYPE_RECT`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1961
- [`V4L2_CTRL_TYPE_STRING`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1951
- [`V4L2_CTRL_TYPE_U16`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1958
- [`V4L2_CTRL_TYPE_U32`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1959
- [`V4L2_CTRL_TYPE_U8`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1957
- [`V4L2_CTRL_TYPE_VP8_FRAME`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1975
- [`V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1981
- [`V4L2_CTRL_TYPE_VP9_FRAME`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1982
- [`V4L2_FIELD_ALTERNATE`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 101
- [`V4L2_FIELD_ANY`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 92
- [`V4L2_FIELD_BOTTOM`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 95
- [`V4L2_FIELD_INTERLACED`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 96
- [`V4L2_FIELD_INTERLACED_BT`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 107
- [`V4L2_FIELD_INTERLACED_TB`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 104
- [`V4L2_FIELD_NONE`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 93
- [`V4L2_FIELD_SEQ_BT`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 99
- [`V4L2_FIELD_SEQ_TB`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 98
- [`V4L2_FIELD_TOP`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 94
- [`V4L2_FRMIVAL_TYPE_CONTINUOUS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#c-v4l2_frmivaltypes): `include/uapi/linux/videodev2.h`, line 983
- [`V4L2_FRMIVAL_TYPE_DISCRETE`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#c-v4l2_frmivaltypes): `include/uapi/linux/videodev2.h`, line 982
- [`V4L2_FRMIVAL_TYPE_STEPWISE`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#c-v4l2_frmivaltypes): `include/uapi/linux/videodev2.h`, line 984
- [`V4L2_FRMSIZE_TYPE_CONTINUOUS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#c-v4l2_frmsizetypes): `include/uapi/linux/videodev2.h`, line 947
- [`V4L2_FRMSIZE_TYPE_DISCRETE`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#c-v4l2_frmsizetypes): `include/uapi/linux/videodev2.h`, line 946
- [`V4L2_FRMSIZE_TYPE_STEPWISE`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#c-v4l2_frmsizetypes): `include/uapi/linux/videodev2.h`, line 948
- [`V4L2_HSV_ENC_180`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_hsv_encoding): `include/uapi/linux/videodev2.h`, line 385
- [`V4L2_HSV_ENC_256`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_hsv_encoding): `include/uapi/linux/videodev2.h`, line 388
- [`V4L2_MEMORY_DMABUF`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-enum-v4l2_memory): `include/uapi/linux/videodev2.h`, line 199
- [`V4L2_MEMORY_MMAP`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-enum-v4l2_memory): `include/uapi/linux/videodev2.h`, line 196
- [`V4L2_MEMORY_OVERLAY`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-enum-v4l2_memory): `include/uapi/linux/videodev2.h`, line 198
- [`V4L2_MEMORY_USERPTR`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-enum-v4l2_memory): `include/uapi/linux/videodev2.h`, line 197
- [`V4L2_PRIORITY_BACKGROUND`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#c-v4l2_priority): `include/uapi/linux/videodev2.h`, line 436
- [`V4L2_PRIORITY_DEFAULT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#c-v4l2_priority): `include/uapi/linux/videodev2.h`, line 439
- [`V4L2_PRIORITY_INTERACTIVE`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#c-v4l2_priority): `include/uapi/linux/videodev2.h`, line 437
- [`V4L2_PRIORITY_RECORD`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#c-v4l2_priority): `include/uapi/linux/videodev2.h`, line 438
- [`V4L2_PRIORITY_UNSET`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#c-v4l2_priority): `include/uapi/linux/videodev2.h`, line 435
- [`V4L2_QUANTIZATION_DEFAULT`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_quantization): `include/uapi/linux/videodev2.h`, line 408
- [`V4L2_QUANTIZATION_FULL_RANGE`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_quantization): `include/uapi/linux/videodev2.h`, line 409
- [`V4L2_QUANTIZATION_LIM_RANGE`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_quantization): `include/uapi/linux/videodev2.h`, line 410
- [`V4L2_TUNER_ANALOG_TV`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#c-v4l2_tuner_type): `include/uapi/linux/videodev2.h`, line 186
- [`V4L2_TUNER_RADIO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#c-v4l2_tuner_type): `include/uapi/linux/videodev2.h`, line 185
- [`V4L2_TUNER_RF`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#c-v4l2_tuner_type): `include/uapi/linux/videodev2.h`, line 189
- [`V4L2_TUNER_SDR`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#c-v4l2_tuner_type): `include/uapi/linux/videodev2.h`, line 188
- [`V4L2_XFER_FUNC_709`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 295
- [`V4L2_XFER_FUNC_DCI_P3`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 300
- [`V4L2_XFER_FUNC_DEFAULT`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 294
- [`V4L2_XFER_FUNC_LAST`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 307
- [`V4L2_XFER_FUNC_NONE`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 299
- [`V4L2_XFER_FUNC_OPRGB`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 297
- [`V4L2_XFER_FUNC_SMPTE2084`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 301
- [`V4L2_XFER_FUNC_SMPTE240M`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 298
- [`V4L2_XFER_FUNC_SRGB`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 296
- [`V4L2_YCBCR_ENC_601`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 341
- [`V4L2_YCBCR_ENC_709`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 344
- [`V4L2_YCBCR_ENC_BT2020`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 362
- [`V4L2_YCBCR_ENC_BT2020_CONST_LUM`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 365
- [`V4L2_YCBCR_ENC_DEFAULT`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 338
- [`V4L2_YCBCR_ENC_LAST`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 374
- [`V4L2_YCBCR_ENC_SMPTE240M`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 368
- [`V4L2_YCBCR_ENC_SYCC`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 358
- [`V4L2_YCBCR_ENC_XV601`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 347
- [`V4L2_YCBCR_ENC_XV709`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 350

## Enumerations

- [`v4l2_buf_type`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buf_type): `include/uapi/linux/videodev2.h`, line 141
- [`v4l2_colorspace`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 203
- [`v4l2_ctrl_type`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#c-v4l2_ctrl_type): `include/uapi/linux/videodev2.h`, line 1944
- [`v4l2_field`](/kernel/userspace/userspace-api/media-v4l/field-order.md#c-v4l2_field): `include/uapi/linux/videodev2.h`, line 88
- [`v4l2_frmivaltypes`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#c-v4l2_frmivaltypes): `include/uapi/linux/videodev2.h`, line 981
- [`v4l2_frmsizetypes`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#c-v4l2_frmsizetypes): `include/uapi/linux/videodev2.h`, line 945
- [`v4l2_hsv_encoding`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_hsv_encoding): `include/uapi/linux/videodev2.h`, line 382
- [`v4l2_memory`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-enum-v4l2_memory): `include/uapi/linux/videodev2.h`, line 195
- [`v4l2_priority`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#c-v4l2_priority): `include/uapi/linux/videodev2.h`, line 434
- [`v4l2_quantization`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_quantization): `include/uapi/linux/videodev2.h`, line 402
- [`v4l2_tuner_type`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#c-v4l2_tuner_type): `include/uapi/linux/videodev2.h`, line 184
- [`v4l2_xfer_func`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 275
- [`v4l2_ycbcr_encoding`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_ycbcr_encoding): `include/uapi/linux/videodev2.h`, line 323

## IOCTL Commands

- [`VIDIOC_CREATE_BUFS`](/kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md#rst-vidioc-create-bufs): `include/uapi/linux/videodev2.h`, line 2807
- [`VIDIOC_CROPCAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#rst-vidioc-cropcap): `include/uapi/linux/videodev2.h`, line 2771
- [`VIDIOC_DBG_G_CHIP_INFO`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-chip-info.md#rst-vidioc-dbg-g-chip-info): `include/uapi/linux/videodev2.h`, line 2822
- [`VIDIOC_DBG_G_REGISTER`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2799
- [`VIDIOC_DBG_S_REGISTER`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2798
- [`VIDIOC_DECODER_CMD`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd): `include/uapi/linux/videodev2.h`, line 2811
- [`VIDIOC_DQBUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf): `include/uapi/linux/videodev2.h`, line 2741
- [`VIDIOC_DQEVENT`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-vidioc-dqevent): `include/uapi/linux/videodev2.h`, line 2804
- [`VIDIOC_DV_TIMINGS_CAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-dv-timings-cap.md#rst-vidioc-dv-timings-cap): `include/uapi/linux/videodev2.h`, line 2815
- [`VIDIOC_ENCODER_CMD`](/kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md#rst-vidioc-encoder-cmd): `include/uapi/linux/videodev2.h`, line 2790
- [`VIDIOC_ENUMAUDIO`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumaudio.md#rst-vidioc-enumaudio): `include/uapi/linux/videodev2.h`, line 2778
- [`VIDIOC_ENUMAUDOUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumaudioout.md#rst-vidioc-enumaudout): `include/uapi/linux/videodev2.h`, line 2779
- [`VIDIOC_ENUMINPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput): `include/uapi/linux/videodev2.h`, line 2749
- [`VIDIOC_ENUMOUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-vidioc-enumoutput): `include/uapi/linux/videodev2.h`, line 2764
- [`VIDIOC_ENUMSTD`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-vidioc-enumstd): `include/uapi/linux/videodev2.h`, line 2748
- [`VIDIOC_ENUM_DV_TIMINGS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-dv-timings.md#rst-vidioc-enum-dv-timings): `include/uapi/linux/videodev2.h`, line 2813
- [`VIDIOC_ENUM_FMT`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt): `include/uapi/linux/videodev2.h`, line 2731
- [`VIDIOC_ENUM_FRAMEINTERVALS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#rst-vidioc-enum-frameintervals): `include/uapi/linux/videodev2.h`, line 2788
- [`VIDIOC_ENUM_FRAMESIZES`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#rst-vidioc-enum-framesizes): `include/uapi/linux/videodev2.h`, line 2787
- [`VIDIOC_ENUM_FREQ_BANDS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#rst-vidioc-enum-freq-bands): `include/uapi/linux/videodev2.h`, line 2816
- [`VIDIOC_EXPBUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-expbuf.md#rst-vidioc-expbuf): `include/uapi/linux/videodev2.h`, line 2740
- [`VIDIOC_G_AUDIO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio): `include/uapi/linux/videodev2.h`, line 2754
- [`VIDIOC_G_AUDOUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audioout.md#rst-vidioc-g-audout): `include/uapi/linux/videodev2.h`, line 2765
- [`VIDIOC_G_CROP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop): `include/uapi/linux/videodev2.h`, line 2772
- [`VIDIOC_G_CTRL`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl): `include/uapi/linux/videodev2.h`, line 2750
- [`VIDIOC_G_DV_TIMINGS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-vidioc-g-dv-timings): `include/uapi/linux/videodev2.h`, line 2803
- [`VIDIOC_G_EDID`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-edid.md#rst-vidioc-g-edid): `include/uapi/linux/videodev2.h`, line 2760
- [`VIDIOC_G_ENC_INDEX`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md#rst-vidioc-g-enc-index): `include/uapi/linux/videodev2.h`, line 2789
- [`VIDIOC_G_EXT_CTRLS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-vidioc-g-ext-ctrls): `include/uapi/linux/videodev2.h`, line 2784
- [`VIDIOC_G_FBUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf): `include/uapi/linux/videodev2.h`, line 2736
- [`VIDIOC_G_FMT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt): `include/uapi/linux/videodev2.h`, line 2732
- [`VIDIOC_G_FREQUENCY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency): `include/uapi/linux/videodev2.h`, line 2769
- [`VIDIOC_G_INPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input): `include/uapi/linux/videodev2.h`, line 2758
- [`VIDIOC_G_JPEGCOMP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-vidioc-g-jpegcomp): `include/uapi/linux/videodev2.h`, line 2774
- [`VIDIOC_G_MODULATOR`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-modulator.md#rst-vidioc-g-modulator): `include/uapi/linux/videodev2.h`, line 2767
- [`VIDIOC_G_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-output.md#rst-vidioc-g-output): `include/uapi/linux/videodev2.h`, line 2762
- [`VIDIOC_G_PARM`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm): `include/uapi/linux/videodev2.h`, line 2744
- [`VIDIOC_G_PRIORITY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#rst-vidioc-g-priority): `include/uapi/linux/videodev2.h`, line 2780
- [`VIDIOC_G_SELECTION`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-selection.md#rst-vidioc-g-selection): `include/uapi/linux/videodev2.h`, line 2809
- [`VIDIOC_G_SLICED_VBI_CAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vidioc-g-sliced-vbi-cap): `include/uapi/linux/videodev2.h`, line 2782
- [`VIDIOC_G_STD`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std): `include/uapi/linux/videodev2.h`, line 2746
- [`VIDIOC_G_TUNER`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-vidioc-g-tuner): `include/uapi/linux/videodev2.h`, line 2752
- [`VIDIOC_LOG_STATUS`](/kernel/userspace/userspace-api/media-v4l/vidioc-log-status.md#rst-vidioc-log-status): `include/uapi/linux/videodev2.h`, line 2783
- [`VIDIOC_OVERLAY`](/kernel/userspace/userspace-api/media-v4l/vidioc-overlay.md#rst-vidioc-overlay): `include/uapi/linux/videodev2.h`, line 2738
- [`VIDIOC_PREPARE_BUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-prepare-buf.md#rst-vidioc-prepare-buf): `include/uapi/linux/videodev2.h`, line 2808
- [`VIDIOC_QBUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf): `include/uapi/linux/videodev2.h`, line 2739
- [`VIDIOC_QUERYBUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf): `include/uapi/linux/videodev2.h`, line 2735
- [`VIDIOC_QUERYCAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap): `include/uapi/linux/videodev2.h`, line 2730
- [`VIDIOC_QUERYCTRL`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl): `include/uapi/linux/videodev2.h`, line 2756
- [`VIDIOC_QUERYMENU`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl): `include/uapi/linux/videodev2.h`, line 2757
- [`VIDIOC_QUERYSTD`](/kernel/userspace/userspace-api/media-v4l/vidioc-querystd.md#rst-vidioc-querystd): `include/uapi/linux/videodev2.h`, line 2776
- [`VIDIOC_QUERY_DV_TIMINGS`](/kernel/userspace/userspace-api/media-v4l/vidioc-query-dv-timings.md#rst-vidioc-query-dv-timings): `include/uapi/linux/videodev2.h`, line 2814
- [`VIDIOC_QUERY_EXT_CTRL`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl): `include/uapi/linux/videodev2.h`, line 2824
- [`VIDIOC_REMOVE_BUFS`](/kernel/userspace/userspace-api/media-v4l/vidioc-remove-bufs.md#rst-vidioc-remove-bufs): `include/uapi/linux/videodev2.h`, line 2825
- [`VIDIOC_REQBUFS`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-vidioc-reqbufs): `include/uapi/linux/videodev2.h`, line 2734
- [`VIDIOC_STREAMOFF`](/kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon): `include/uapi/linux/videodev2.h`, line 2743
- [`VIDIOC_STREAMON`](/kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon): `include/uapi/linux/videodev2.h`, line 2742
- [`VIDIOC_SUBSCRIBE_EVENT`](/kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md#rst-vidioc-subscribe-event): `include/uapi/linux/videodev2.h`, line 2805
- [`VIDIOC_S_AUDIO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio): `include/uapi/linux/videodev2.h`, line 2755
- [`VIDIOC_S_AUDOUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audioout.md#rst-vidioc-g-audout): `include/uapi/linux/videodev2.h`, line 2766
- [`VIDIOC_S_CROP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#rst-vidioc-g-crop): `include/uapi/linux/videodev2.h`, line 2773
- [`VIDIOC_S_CTRL`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl): `include/uapi/linux/videodev2.h`, line 2751
- [`VIDIOC_S_DV_TIMINGS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-vidioc-g-dv-timings): `include/uapi/linux/videodev2.h`, line 2802
- [`VIDIOC_S_EDID`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-edid.md#rst-vidioc-g-edid): `include/uapi/linux/videodev2.h`, line 2761
- [`VIDIOC_S_EXT_CTRLS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-vidioc-g-ext-ctrls): `include/uapi/linux/videodev2.h`, line 2785
- [`VIDIOC_S_FBUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-vidioc-g-fbuf): `include/uapi/linux/videodev2.h`, line 2737
- [`VIDIOC_S_FMT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt): `include/uapi/linux/videodev2.h`, line 2733
- [`VIDIOC_S_FREQUENCY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency): `include/uapi/linux/videodev2.h`, line 2770
- [`VIDIOC_S_HW_FREQ_SEEK`](/kernel/userspace/userspace-api/media-v4l/vidioc-s-hw-freq-seek.md#rst-vidioc-s-hw-freq-seek): `include/uapi/linux/videodev2.h`, line 2801
- [`VIDIOC_S_INPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-input.md#rst-vidioc-g-input): `include/uapi/linux/videodev2.h`, line 2759
- [`VIDIOC_S_JPEGCOMP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-vidioc-g-jpegcomp): `include/uapi/linux/videodev2.h`, line 2775
- [`VIDIOC_S_MODULATOR`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-modulator.md#rst-vidioc-g-modulator): `include/uapi/linux/videodev2.h`, line 2768
- [`VIDIOC_S_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-output.md#rst-vidioc-g-output): `include/uapi/linux/videodev2.h`, line 2763
- [`VIDIOC_S_PARM`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm): `include/uapi/linux/videodev2.h`, line 2745
- [`VIDIOC_S_PRIORITY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-priority.md#rst-vidioc-g-priority): `include/uapi/linux/videodev2.h`, line 2781
- [`VIDIOC_S_SELECTION`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-selection.md#rst-vidioc-g-selection): `include/uapi/linux/videodev2.h`, line 2810
- [`VIDIOC_S_STD`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std): `include/uapi/linux/videodev2.h`, line 2747
- [`VIDIOC_S_TUNER`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-vidioc-g-tuner): `include/uapi/linux/videodev2.h`, line 2753
- [`VIDIOC_TRY_DECODER_CMD`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-vidioc-decoder-cmd): `include/uapi/linux/videodev2.h`, line 2812
- [`VIDIOC_TRY_ENCODER_CMD`](/kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md#rst-vidioc-encoder-cmd): `include/uapi/linux/videodev2.h`, line 2791
- [`VIDIOC_TRY_EXT_CTRLS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-vidioc-g-ext-ctrls): `include/uapi/linux/videodev2.h`, line 2786
- [`VIDIOC_TRY_FMT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt): `include/uapi/linux/videodev2.h`, line 2777
- [`VIDIOC_UNSUBSCRIBE_EVENT`](/kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md#rst-vidioc-unsubscribe-event): `include/uapi/linux/videodev2.h`, line 2806

## Macros and Definitions

- [`V4L2_AUDCAP_AVL`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-audio-capability): `include/uapi/linux/videodev2.h`, line 2191
- [`V4L2_AUDCAP_STEREO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-audio-capability): `include/uapi/linux/videodev2.h`, line 2190
- [`V4L2_AUDMODE_AVL`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-audio-mode): `include/uapi/linux/videodev2.h`, line 2194
- [`V4L2_BAND_MODULATION_AM`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#rst-band-modulation): `include/uapi/linux/videodev2.h`, line 2133
- [`V4L2_BAND_MODULATION_FM`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#rst-band-modulation): `include/uapi/linux/videodev2.h`, line 2132
- [`V4L2_BAND_MODULATION_VSB`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#rst-band-modulation): `include/uapi/linux/videodev2.h`, line 2131
- [`V4L2_BUF_CAP_SUPPORTS_DMABUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-dmabuf): `include/uapi/linux/videodev2.h`, line 1101
- [`V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-m2m-hold-capture-buf): `include/uapi/linux/videodev2.h`, line 1104
- [`V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-max-num-buffers): `include/uapi/linux/videodev2.h`, line 1106
- [`V4L2_BUF_CAP_SUPPORTS_MMAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-mmap): `include/uapi/linux/videodev2.h`, line 1099
- [`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-mmap-cache-hints): `include/uapi/linux/videodev2.h`, line 1105
- [`V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-orphaned-bufs): `include/uapi/linux/videodev2.h`, line 1103
- [`V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-remove-bufs): `include/uapi/linux/videodev2.h`, line 1107
- [`V4L2_BUF_CAP_SUPPORTS_REQUESTS`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-requests): `include/uapi/linux/videodev2.h`, line 1102
- [`V4L2_BUF_CAP_SUPPORTS_USERPTR`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-buf-cap-supports-userptr): `include/uapi/linux/videodev2.h`, line 1100
- [`V4L2_BUF_FLAG_BFRAME`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-bframe): `include/uapi/linux/videodev2.h`, line 1234
- [`V4L2_BUF_FLAG_DONE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-done): `include/uapi/linux/videodev2.h`, line 1228
- [`V4L2_BUF_FLAG_ERROR`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-error): `include/uapi/linux/videodev2.h`, line 1236
- [`V4L2_BUF_FLAG_IN_REQUEST`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-in-request): `include/uapi/linux/videodev2.h`, line 1238
- [`V4L2_BUF_FLAG_KEYFRAME`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-keyframe): `include/uapi/linux/videodev2.h`, line 1230
- [`V4L2_BUF_FLAG_LAST`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-last): `include/uapi/linux/videodev2.h`, line 1258
- [`V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-m2m-hold-capture-buf): `include/uapi/linux/videodev2.h`, line 1242
- [`V4L2_BUF_FLAG_MAPPED`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-mapped): `include/uapi/linux/videodev2.h`, line 1224
- [`V4L2_BUF_FLAG_NO_CACHE_CLEAN`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-no-cache-clean): `include/uapi/linux/videodev2.h`, line 1247
- [`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-no-cache-invalidate): `include/uapi/linux/videodev2.h`, line 1246
- [`V4L2_BUF_FLAG_PFRAME`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-pframe): `include/uapi/linux/videodev2.h`, line 1232
- [`V4L2_BUF_FLAG_PREPARED`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-prepared): `include/uapi/linux/videodev2.h`, line 1244
- [`V4L2_BUF_FLAG_QUEUED`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-queued): `include/uapi/linux/videodev2.h`, line 1226
- [`V4L2_BUF_FLAG_REQUEST_FD`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-request-fd): `include/uapi/linux/videodev2.h`, line 1260
- [`V4L2_BUF_FLAG_TIMECODE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-timecode): `include/uapi/linux/videodev2.h`, line 1240
- [`V4L2_BUF_FLAG_TIMESTAMP_COPY`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-timestamp-copy): `include/uapi/linux/videodev2.h`, line 1252
- [`V4L2_BUF_FLAG_TIMESTAMP_MASK`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-timestamp-mask): `include/uapi/linux/videodev2.h`, line 1249
- [`V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-timestamp-monotonic): `include/uapi/linux/videodev2.h`, line 1251
- [`V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-timestamp-unknown): `include/uapi/linux/videodev2.h`, line 1250
- [`V4L2_BUF_FLAG_TSTAMP_SRC_EOF`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-tstamp-src-eof): `include/uapi/linux/videodev2.h`, line 1255
- [`V4L2_BUF_FLAG_TSTAMP_SRC_MASK`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-tstamp-src-mask): `include/uapi/linux/videodev2.h`, line 1254
- [`V4L2_BUF_FLAG_TSTAMP_SRC_SOE`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-tstamp-src-soe): `include/uapi/linux/videodev2.h`, line 1256
- [`V4L2_CAP_ASYNCIO`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 2841
- [`V4L2_CAP_AUDIO`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 503
- [`V4L2_CAP_DEVICE_CAPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 521
- [`V4L2_CAP_EDID`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 513
- [`V4L2_CAP_EXT_PIX_FORMAT`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 508
- [`V4L2_CAP_HW_FREQ_SEEK`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 490
- [`V4L2_CAP_IO_MC`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 519
- [`V4L2_CAP_META_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 510
- [`V4L2_CAP_META_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 515
- [`V4L2_CAP_MODULATOR`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 505
- [`V4L2_CAP_RADIO`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 504
- [`V4L2_CAP_RDS_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 488
- [`V4L2_CAP_RDS_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 491
- [`V4L2_CAP_READWRITE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 512
- [`V4L2_CAP_SDR_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 507
- [`V4L2_CAP_SDR_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 509
- [`V4L2_CAP_SLICED_VBI_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 486
- [`V4L2_CAP_SLICED_VBI_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 487
- [`V4L2_CAP_STREAMING`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 514
- [`V4L2_CAP_TIMEPERFRAME`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#c-v4l2_captureparm): `include/uapi/linux/videodev2.h`, line 1359
- [`V4L2_CAP_TOUCH`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 517
- [`V4L2_CAP_TUNER`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 502
- [`V4L2_CAP_VBI_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 484
- [`V4L2_CAP_VBI_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 485
- [`V4L2_CAP_VIDEO_CAPTURE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 481
- [`V4L2_CAP_VIDEO_CAPTURE_MPLANE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 494
- [`V4L2_CAP_VIDEO_M2M`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 500
- [`V4L2_CAP_VIDEO_M2M_MPLANE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 498
- [`V4L2_CAP_VIDEO_OUTPUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 482
- [`V4L2_CAP_VIDEO_OUTPUT_MPLANE`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 496
- [`V4L2_CAP_VIDEO_OUTPUT_OVERLAY`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 489
- [`V4L2_CAP_VIDEO_OVERLAY`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities): `include/uapi/linux/videodev2.h`, line 483
- [`V4L2_CHIP_FL_READABLE`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2674
- [`V4L2_CHIP_FL_WRITABLE`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2675
- [`V4L2_CHIP_MATCH_AC97`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2657
- [`V4L2_CHIP_MATCH_BRIDGE`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2650
- [`V4L2_CHIP_MATCH_HOST`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2654
- [`V4L2_CHIP_MATCH_I2C_ADDR`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2656
- [`V4L2_CHIP_MATCH_I2C_DRIVER`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2655
- [`V4L2_CHIP_MATCH_SUBDEV`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#rst-vidioc-dbg-g-register): `include/uapi/linux/videodev2.h`, line 2651
- [`V4L2_CID_PRIVATE_BASE`](/kernel/userspace/userspace-api/media-v4l/control.md#rst-control): `include/uapi/linux/videodev2.h`, line 2061
- [`V4L2_COLORSPACE_ADOBERGB`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_colorspace): `include/uapi/linux/videodev2.h`, line 430
- [`V4L2_CTRL_FLAG_DISABLED`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2040
- [`V4L2_CTRL_FLAG_DYNAMIC_ARRAY`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2051
- [`V4L2_CTRL_FLAG_EXECUTE_ON_WRITE`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2049
- [`V4L2_CTRL_FLAG_GRABBED`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2041
- [`V4L2_CTRL_FLAG_HAS_PAYLOAD`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2048
- [`V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2052
- [`V4L2_CTRL_FLAG_INACTIVE`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2044
- [`V4L2_CTRL_FLAG_MODIFY_LAYOUT`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2050
- [`V4L2_CTRL_FLAG_NEXT_COMPOUND`](/kernel/userspace/userspace-api/media-v4l/control.md#rst-control): `include/uapi/linux/videodev2.h`, line 2056
- [`V4L2_CTRL_FLAG_NEXT_CTRL`](/kernel/userspace/userspace-api/media-v4l/control.md#rst-control): `include/uapi/linux/videodev2.h`, line 2055
- [`V4L2_CTRL_FLAG_READ_ONLY`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2042
- [`V4L2_CTRL_FLAG_SLIDER`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2045
- [`V4L2_CTRL_FLAG_UPDATE`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2043
- [`V4L2_CTRL_FLAG_VOLATILE`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2047
- [`V4L2_CTRL_FLAG_WRITE_ONLY`](/kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-control-flags): `include/uapi/linux/videodev2.h`, line 2046
- [`V4L2_DEC_CMD_FLUSH`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2253
- [`V4L2_DEC_CMD_PAUSE`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2251
- [`V4L2_DEC_CMD_PAUSE_TO_BLACK`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2259
- [`V4L2_DEC_CMD_RESUME`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2252
- [`V4L2_DEC_CMD_START`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2249
- [`V4L2_DEC_CMD_START_MUTE_AUDIO`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2256
- [`V4L2_DEC_CMD_STOP`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2250
- [`V4L2_DEC_CMD_STOP_IMMEDIATELY`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2263
- [`V4L2_DEC_CMD_STOP_TO_BLACK`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2262
- [`V4L2_DEC_START_FMT_GOP`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2270
- [`V4L2_DEC_START_FMT_NONE`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#rst-decoder-cmds): `include/uapi/linux/videodev2.h`, line 2268
- [`V4L2_DV_BT_656_1120`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-timing-types): `include/uapi/linux/videodev2.h`, line 1724
- [`V4L2_DV_BT_CAP_CUSTOM`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1771
- [`V4L2_DV_BT_CAP_INTERLACED`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1765
- [`V4L2_DV_BT_CAP_PROGRESSIVE`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1767
- [`V4L2_DV_BT_CAP_REDUCED_BLANKING`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1769
- [`V4L2_DV_BT_STD_CEA861`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1623
- [`V4L2_DV_BT_STD_CVT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1625
- [`V4L2_DV_BT_STD_DMT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1624
- [`V4L2_DV_BT_STD_GTF`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1626
- [`V4L2_DV_BT_STD_SDI`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1627
- [`V4L2_DV_FL_CAN_DETECT_REDUCED_FPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1697
- [`V4L2_DV_FL_CAN_REDUCE_FPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1643
- [`V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1673
- [`V4L2_DV_FL_HALF_LINE`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1660
- [`V4L2_DV_FL_HAS_CEA861_VIC`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1684
- [`V4L2_DV_FL_HAS_HDMI_VIC`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1690
- [`V4L2_DV_FL_HAS_PICTURE_ASPECT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1679
- [`V4L2_DV_FL_IS_CE_VIDEO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1668
- [`V4L2_DV_FL_REDUCED_BLANKING`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1637
- [`V4L2_DV_FL_REDUCED_FPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards): `include/uapi/linux/videodev2.h`, line 1653
- [`V4L2_DV_HSYNC_POS_POL`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#c-v4l2_bt_timings): `include/uapi/linux/videodev2.h`, line 1620
- [`V4L2_DV_INTERLACED`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#c-v4l2_bt_timings): `include/uapi/linux/videodev2.h`, line 1616
- [`V4L2_DV_PROGRESSIVE`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#c-v4l2_bt_timings): `include/uapi/linux/videodev2.h`, line 1615
- [`V4L2_DV_VSYNC_POS_POL`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#c-v4l2_bt_timings): `include/uapi/linux/videodev2.h`, line 1619
- [`V4L2_ENC_CMD_PAUSE`](/kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md#rst-encoder-cmds): `include/uapi/linux/videodev2.h`, line 2232
- [`V4L2_ENC_CMD_RESUME`](/kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md#rst-encoder-cmds): `include/uapi/linux/videodev2.h`, line 2233
- [`V4L2_ENC_CMD_START`](/kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md#rst-encoder-cmds): `include/uapi/linux/videodev2.h`, line 2230
- [`V4L2_ENC_CMD_STOP`](/kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md#rst-encoder-cmds): `include/uapi/linux/videodev2.h`, line 2231
- [`V4L2_ENC_CMD_STOP_AT_GOP_END`](/kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md#rst-encoder-flags): `include/uapi/linux/videodev2.h`, line 2236
- [`V4L2_ENC_IDX_ENTRIES`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md#c-v4l2_enc_idx): `include/uapi/linux/videodev2.h`, line 2221
- [`V4L2_ENC_IDX_FRAME_B`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md#c-v4l2_enc_idx): `include/uapi/linux/videodev2.h`, line 2210
- [`V4L2_ENC_IDX_FRAME_I`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md#c-v4l2_enc_idx): `include/uapi/linux/videodev2.h`, line 2208
- [`V4L2_ENC_IDX_FRAME_MASK`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md#c-v4l2_enc_idx): `include/uapi/linux/videodev2.h`, line 2211
- [`V4L2_ENC_IDX_FRAME_P`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md#c-v4l2_enc_idx): `include/uapi/linux/videodev2.h`, line 2209
- [`V4L2_EVENT_ALL`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type): `include/uapi/linux/videodev2.h`, line 2550
- [`V4L2_EVENT_CTRL`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type): `include/uapi/linux/videodev2.h`, line 2553
- [`V4L2_EVENT_CTRL_CH_DIMENSIONS`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-ctrl-changes-flags): `include/uapi/linux/videodev2.h`, line 2569
- [`V4L2_EVENT_CTRL_CH_FLAGS`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-ctrl-changes-flags): `include/uapi/linux/videodev2.h`, line 2567
- [`V4L2_EVENT_CTRL_CH_RANGE`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-ctrl-changes-flags): `include/uapi/linux/videodev2.h`, line 2568
- [`V4L2_EVENT_CTRL_CH_VALUE`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-ctrl-changes-flags): `include/uapi/linux/videodev2.h`, line 2566
- [`V4L2_EVENT_EOS`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type): `include/uapi/linux/videodev2.h`, line 2552
- [`V4L2_EVENT_FRAME_SYNC`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type): `include/uapi/linux/videodev2.h`, line 2554
- [`V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#c-v4l2_event_motion_det): `include/uapi/linux/videodev2.h`, line 2595
- [`V4L2_EVENT_MOTION_DET`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type): `include/uapi/linux/videodev2.h`, line 2556
- [`V4L2_EVENT_PRIVATE_START`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type): `include/uapi/linux/videodev2.h`, line 2557
- [`V4L2_EVENT_SOURCE_CHANGE`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type): `include/uapi/linux/videodev2.h`, line 2555
- [`V4L2_EVENT_SRC_CH_RESOLUTION`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-src-changes-flags): `include/uapi/linux/videodev2.h`, line 2589
- [`V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK`](/kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md#rst-event-flags): `include/uapi/linux/videodev2.h`, line 2632
- [`V4L2_EVENT_SUB_FL_SEND_INITIAL`](/kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md#rst-event-flags): `include/uapi/linux/videodev2.h`, line 2631
- [`V4L2_EVENT_VSYNC`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type): `include/uapi/linux/videodev2.h`, line 2551
- [`V4L2_FBUF_CAP_BITMAP_CLIPPING`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1315
- [`V4L2_FBUF_CAP_CHROMAKEY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1312
- [`V4L2_FBUF_CAP_EXTERNOVERLAY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1311
- [`V4L2_FBUF_CAP_GLOBAL_ALPHA`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1318
- [`V4L2_FBUF_CAP_LIST_CLIPPING`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1314
- [`V4L2_FBUF_CAP_LOCAL_ALPHA`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1317
- [`V4L2_FBUF_CAP_LOCAL_INV_ALPHA`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1319
- [`V4L2_FBUF_CAP_SRC_CHROMAKEY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-cap): `include/uapi/linux/videodev2.h`, line 1320
- [`V4L2_FBUF_FLAG_CHROMAKEY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-flags): `include/uapi/linux/videodev2.h`, line 1324
- [`V4L2_FBUF_FLAG_GLOBAL_ALPHA`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-flags): `include/uapi/linux/videodev2.h`, line 1326
- [`V4L2_FBUF_FLAG_LOCAL_ALPHA`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-flags): `include/uapi/linux/videodev2.h`, line 1325
- [`V4L2_FBUF_FLAG_LOCAL_INV_ALPHA`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-flags): `include/uapi/linux/videodev2.h`, line 1327
- [`V4L2_FBUF_FLAG_OVERLAY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-flags): `include/uapi/linux/videodev2.h`, line 1323
- [`V4L2_FBUF_FLAG_PRIMARY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-flags): `include/uapi/linux/videodev2.h`, line 1322
- [`V4L2_FBUF_FLAG_SRC_CHROMAKEY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#rst-framebuffer-flags): `include/uapi/linux/videodev2.h`, line 1328
- [`V4L2_FMTDESC_FLAG_ENUM_ALL`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 939
- [`V4L2_FMT_FLAG_COMPRESSED`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 926
- [`V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 928
- [`V4L2_FMT_FLAG_CSC_COLORSPACE`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 931
- [`V4L2_FMT_FLAG_CSC_HSV_ENC`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 934
- [`V4L2_FMT_FLAG_CSC_QUANTIZATION`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 935
- [`V4L2_FMT_FLAG_CSC_XFER_FUNC`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 932
- [`V4L2_FMT_FLAG_CSC_YCBCR_ENC`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 933
- [`V4L2_FMT_FLAG_DYN_RESOLUTION`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 929
- [`V4L2_FMT_FLAG_EMULATED`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 927
- [`V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 930
- [`V4L2_FMT_FLAG_META_LINE_BASED`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-fmtdesc-flags): `include/uapi/linux/videodev2.h`, line 936
- [`V4L2_INPUT_TYPE_CAMERA`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-type): `include/uapi/linux/videodev2.h`, line 1807
- [`V4L2_INPUT_TYPE_TOUCH`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-type): `include/uapi/linux/videodev2.h`, line 1808
- [`V4L2_INPUT_TYPE_TUNER`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-type): `include/uapi/linux/videodev2.h`, line 1806
- [`V4L2_IN_CAP_DV_TIMINGS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-capabilities): `include/uapi/linux/videodev2.h`, line 1837
- [`V4L2_IN_CAP_NATIVE_SIZE`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-capabilities): `include/uapi/linux/videodev2.h`, line 1840
- [`V4L2_IN_CAP_STD`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-capabilities): `include/uapi/linux/videodev2.h`, line 1839
- [`V4L2_IN_ST_COLOR_KILL`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1822
- [`V4L2_IN_ST_HFLIP`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1817
- [`V4L2_IN_ST_MACROVISION`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1832
- [`V4L2_IN_ST_NO_ACCESS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1833
- [`V4L2_IN_ST_NO_CARRIER`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1829
- [`V4L2_IN_ST_NO_COLOR`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1813
- [`V4L2_IN_ST_NO_EQU`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1828
- [`V4L2_IN_ST_NO_H_LOCK`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1821
- [`V4L2_IN_ST_NO_POWER`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1811
- [`V4L2_IN_ST_NO_SIGNAL`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1812
- [`V4L2_IN_ST_NO_STD_LOCK`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1824
- [`V4L2_IN_ST_NO_SYNC`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1827
- [`V4L2_IN_ST_NO_V_LOCK`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1823
- [`V4L2_IN_ST_VFLIP`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1818
- [`V4L2_IN_ST_VTR`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-input-status): `include/uapi/linux/videodev2.h`, line 1834
- [`V4L2_JPEG_MARKER_APP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-jpeg-markers): `include/uapi/linux/videodev2.h`, line 1062
- [`V4L2_JPEG_MARKER_COM`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-jpeg-markers): `include/uapi/linux/videodev2.h`, line 1060
- [`V4L2_JPEG_MARKER_DHT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-jpeg-markers): `include/uapi/linux/videodev2.h`, line 1057
- [`V4L2_JPEG_MARKER_DQT`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-jpeg-markers): `include/uapi/linux/videodev2.h`, line 1058
- [`V4L2_JPEG_MARKER_DRI`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#rst-jpeg-markers): `include/uapi/linux/videodev2.h`, line 1059
- [`V4L2_MEMORY_FLAG_NON_COHERENT`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#rst-v4l2-memory-flag-non-coherent): `include/uapi/linux/videodev2.h`, line 1096
- [`V4L2_META_FMT_C3ISP_PARAMS`](/kernel/userspace/userspace-api/media-v4l/metafmt-c3-isp.md#rst-v4l2-meta-fmt-c3isp-params): `include/uapi/linux/videodev2.h`, line 880
- [`V4L2_META_FMT_C3ISP_STATS`](/kernel/userspace/userspace-api/media-v4l/metafmt-c3-isp.md#rst-v4l2-meta-fmt-c3isp-stats): `include/uapi/linux/videodev2.h`, line 881
- [`V4L2_META_FMT_D4XX`](/kernel/userspace/userspace-api/media-v4l/metafmt-d4xx.md#rst-v4l2-meta-fmt-d4xx): `include/uapi/linux/videodev2.h`, line 870
- [`V4L2_META_FMT_GENERIC_8`](/kernel/userspace/userspace-api/media-v4l/metafmt-generic.md#rst-v4l2-meta-fmt-generic-8): `include/uapi/linux/videodev2.h`, line 897
- [`V4L2_META_FMT_GENERIC_CSI2_10`](/kernel/userspace/userspace-api/media-v4l/metafmt-generic.md#rst-v4l2-meta-fmt-generic-csi2-10): `include/uapi/linux/videodev2.h`, line 898
- [`V4L2_META_FMT_GENERIC_CSI2_12`](/kernel/userspace/userspace-api/media-v4l/metafmt-generic.md#rst-v4l2-meta-fmt-generic-csi2-12): `include/uapi/linux/videodev2.h`, line 899
- [`V4L2_META_FMT_GENERIC_CSI2_14`](/kernel/userspace/userspace-api/media-v4l/metafmt-generic.md#rst-v4l2-meta-fmt-generic-csi2-14): `include/uapi/linux/videodev2.h`, line 900
- [`V4L2_META_FMT_GENERIC_CSI2_16`](/kernel/userspace/userspace-api/media-v4l/metafmt-generic.md#rst-v4l2-meta-fmt-generic-csi2-16): `include/uapi/linux/videodev2.h`, line 901
- [`V4L2_META_FMT_GENERIC_CSI2_20`](/kernel/userspace/userspace-api/media-v4l/metafmt-generic.md#rst-v4l2-meta-fmt-generic-csi2-20): `include/uapi/linux/videodev2.h`, line 902
- [`V4L2_META_FMT_GENERIC_CSI2_24`](/kernel/userspace/userspace-api/media-v4l/metafmt-generic.md#rst-v4l2-meta-fmt-generic-csi2-24): `include/uapi/linux/videodev2.h`, line 903
- [`V4L2_META_FMT_MALI_C55_PARAMS`](/kernel/userspace/userspace-api/media-v4l/metafmt-arm-mali-c55.md#rst-v4l2-meta-fmt-mali-c55-params): `include/uapi/linux/videodev2.h`, line 889
- [`V4L2_META_FMT_MALI_C55_STATS`](/kernel/userspace/userspace-api/media-v4l/metafmt-arm-mali-c55.md#rst-v4l2-meta-fmt-mali-c55-stats): `include/uapi/linux/videodev2.h`, line 890
- [`V4L2_META_FMT_RK_ISP1_EXT_PARAMS`](/kernel/userspace/userspace-api/media-v4l/metafmt-rkisp1.md#rst-v4l2-meta-fmt-rk-isp1-ext-params): `include/uapi/linux/videodev2.h`, line 877
- [`V4L2_META_FMT_RK_ISP1_PARAMS`](/kernel/userspace/userspace-api/media-v4l/metafmt-rkisp1.md#rst-v4l2-meta-fmt-rk-isp1-params): `include/uapi/linux/videodev2.h`, line 875
- [`V4L2_META_FMT_RK_ISP1_STAT_3A`](/kernel/userspace/userspace-api/media-v4l/metafmt-rkisp1.md#rst-v4l2-meta-fmt-rk-isp1-stat-3a): `include/uapi/linux/videodev2.h`, line 876
- [`V4L2_META_FMT_RPI_BE_CFG`](/kernel/userspace/userspace-api/media-v4l/metafmt-pisp-be.md#rst-v4l2-meta-fmt-rpi-be-cfg): `include/uapi/linux/videodev2.h`, line 884
- [`V4L2_META_FMT_RPI_FE_CFG`](/kernel/userspace/userspace-api/media-v4l/metafmt-pisp-fe.md#rst-v4l2-meta-fmt-rpi-fe-cfg): `include/uapi/linux/videodev2.h`, line 885
- [`V4L2_META_FMT_RPI_FE_STATS`](/kernel/userspace/userspace-api/media-v4l/metafmt-pisp-fe.md#rst-v4l2-meta-fmt-rpi-fe-stats): `include/uapi/linux/videodev2.h`, line 886
- [`V4L2_META_FMT_UVC`](/kernel/userspace/userspace-api/media-v4l/metafmt-uvc.md#rst-v4l2-meta-fmt-uvc): `include/uapi/linux/videodev2.h`, line 869
- [`V4L2_META_FMT_UVC_MSXU_1_5`](/kernel/userspace/userspace-api/media-v4l/metafmt-uvc-msxu-1-5.md#rst-v4l2-meta-fmt-uvc-msxu-1-5): `include/uapi/linux/videodev2.h`, line 871
- [`V4L2_META_FMT_VIVID`](/kernel/userspace/userspace-api/media-v4l/metafmt-vivid.md#rst-v4l2-meta-fmt-vivid): `include/uapi/linux/videodev2.h`, line 872
- [`V4L2_META_FMT_VSP1_HGO`](/kernel/userspace/userspace-api/media-v4l/metafmt-vsp1-hgo.md#rst-v4l2-meta-fmt-vsp1-hgo): `include/uapi/linux/videodev2.h`, line 867
- [`V4L2_META_FMT_VSP1_HGT`](/kernel/userspace/userspace-api/media-v4l/metafmt-vsp1-hgt.md#rst-v4l2-meta-fmt-vsp1-hgt): `include/uapi/linux/videodev2.h`, line 868
- [`V4L2_MODE_HIGHQUALITY`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-parm-flags): `include/uapi/linux/videodev2.h`, line 1358
- [`V4L2_MPEG_VBI_IVTV_CAPTION_525`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-itv0-line-identifier-constants): `include/uapi/linux/videodev2.h`, line 2396
- [`V4L2_MPEG_VBI_IVTV_MAGIC0`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-v4l2-mpeg-vbi-fmt-ivtv-magic): `include/uapi/linux/videodev2.h`, line 2414
- [`V4L2_MPEG_VBI_IVTV_MAGIC1`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-v4l2-mpeg-vbi-fmt-ivtv-magic): `include/uapi/linux/videodev2.h`, line 2415
- [`V4L2_MPEG_VBI_IVTV_TELETEXT_B`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-itv0-line-identifier-constants): `include/uapi/linux/videodev2.h`, line 2395
- [`V4L2_MPEG_VBI_IVTV_VPS`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-itv0-line-identifier-constants): `include/uapi/linux/videodev2.h`, line 2398
- [`V4L2_MPEG_VBI_IVTV_WSS_625`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-itv0-line-identifier-constants): `include/uapi/linux/videodev2.h`, line 2397
- [`V4L2_OUTPUT_TYPE_ANALOG`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-output-type): `include/uapi/linux/videodev2.h`, line 1857
- [`V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-output-type): `include/uapi/linux/videodev2.h`, line 1858
- [`V4L2_OUTPUT_TYPE_MODULATOR`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-output-type): `include/uapi/linux/videodev2.h`, line 1856
- [`V4L2_OUT_CAP_DV_TIMINGS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-output-capabilities): `include/uapi/linux/videodev2.h`, line 1861
- [`V4L2_OUT_CAP_NATIVE_SIZE`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-output-capabilities): `include/uapi/linux/videodev2.h`, line 1864
- [`V4L2_OUT_CAP_STD`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-output-capabilities): `include/uapi/linux/videodev2.h`, line 1863
- [`V4L2_PIX_FMT_ABGR32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-abgr32): `include/uapi/linux/videodev2.h`, line 579
- [`V4L2_PIX_FMT_ABGR444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-abgr444): `include/uapi/linux/videodev2.h`, line 555
- [`V4L2_PIX_FMT_ABGR555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-abgr555): `include/uapi/linux/videodev2.h`, line 564
- [`V4L2_PIX_FMT_ABGR64_12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-abgr64-12): `include/uapi/linux/videodev2.h`, line 596
- [`V4L2_PIX_FMT_AJPG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-ajpg): `include/uapi/linux/videodev2.h`, line 823
- [`V4L2_PIX_FMT_ARGB2101010`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-argb2101010): `include/uapi/linux/videodev2.h`, line 590
- [`V4L2_PIX_FMT_ARGB32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-argb32): `include/uapi/linux/videodev2.h`, line 586
- [`V4L2_PIX_FMT_ARGB444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-argb444): `include/uapi/linux/videodev2.h`, line 551
- [`V4L2_PIX_FMT_ARGB555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-argb555): `include/uapi/linux/videodev2.h`, line 560
- [`V4L2_PIX_FMT_ARGB555X`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-argb555x): `include/uapi/linux/videodev2.h`, line 570
- [`V4L2_PIX_FMT_AV1`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-av1): `include/uapi/linux/videodev2.h`, line 778
- [`V4L2_PIX_FMT_AV1_FRAME`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-av1-frame): `include/uapi/linux/videodev2.h`, line 777
- [`V4L2_PIX_FMT_AYUV32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-ayuv32): `include/uapi/linux/videodev2.h`, line 634
- [`V4L2_PIX_FMT_BGR24`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgr24): `include/uapi/linux/videodev2.h`, line 576
- [`V4L2_PIX_FMT_BGR32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgr32): `include/uapi/linux/videodev2.h`, line 578
- [`V4L2_PIX_FMT_BGR48`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgr48): `include/uapi/linux/videodev2.h`, line 594
- [`V4L2_PIX_FMT_BGR48_12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgr48-12): `include/uapi/linux/videodev2.h`, line 593
- [`V4L2_PIX_FMT_BGR666`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgr666): `include/uapi/linux/videodev2.h`, line 575
- [`V4L2_PIX_FMT_BGRA32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgra32): `include/uapi/linux/videodev2.h`, line 581
- [`V4L2_PIX_FMT_BGRA444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgra444): `include/uapi/linux/videodev2.h`, line 557
- [`V4L2_PIX_FMT_BGRA555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgra555): `include/uapi/linux/videodev2.h`, line 566
- [`V4L2_PIX_FMT_BGRX32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgrx32): `include/uapi/linux/videodev2.h`, line 582
- [`V4L2_PIX_FMT_BGRX444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgrx444): `include/uapi/linux/videodev2.h`, line 558
- [`V4L2_PIX_FMT_BGRX555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-bgrx555): `include/uapi/linux/videodev2.h`, line 567
- [`V4L2_PIX_FMT_CIT_YYVYUY`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-cit-yyvyuy): `include/uapi/linux/videodev2.h`, line 805
- [`V4L2_PIX_FMT_CNF4`](/kernel/userspace/userspace-api/media-v4l/pixfmt-cnf4.md#rst-v4l2-pix-fmt-cnf4): `include/uapi/linux/videodev2.h`, line 819
- [`V4L2_PIX_FMT_CPIA1`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-cpia1): `include/uapi/linux/videodev2.h`, line 784
- [`V4L2_PIX_FMT_DV`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-dv): `include/uapi/linux/videodev2.h`, line 755
- [`V4L2_PIX_FMT_ET61X251`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-et61x251): `include/uapi/linux/videodev2.h`, line 790
- [`V4L2_PIX_FMT_FLAG_PREMUL_ALPHA`](/kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#rst-format-flags): `include/uapi/linux/videodev2.h`, line 910
- [`V4L2_PIX_FMT_FLAG_SET_CSC`](/kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#rst-v4l2-pix-fmt-flag-set-csc): `include/uapi/linux/videodev2.h`, line 911
- [`V4L2_PIX_FMT_FWHT`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-fwht): `include/uapi/linux/videodev2.h`, line 773
- [`V4L2_PIX_FMT_FWHT_STATELESS`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-fwht-stateless): `include/uapi/linux/videodev2.h`, line 774
- [`V4L2_PIX_FMT_GREY`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-grey): `include/uapi/linux/videodev2.h`, line 599
- [`V4L2_PIX_FMT_H263`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-h263): `include/uapi/linux/videodev2.h`, line 760
- [`V4L2_PIX_FMT_H264`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-h264): `include/uapi/linux/videodev2.h`, line 757
- [`V4L2_PIX_FMT_H264_MVC`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-h264-mvc): `include/uapi/linux/videodev2.h`, line 759
- [`V4L2_PIX_FMT_H264_NO_SC`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-h264-no-sc): `include/uapi/linux/videodev2.h`, line 758
- [`V4L2_PIX_FMT_H264_SLICE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-h264-slice): `include/uapi/linux/videodev2.h`, line 775
- [`V4L2_PIX_FMT_HEVC`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-hevc): `include/uapi/linux/videodev2.h`, line 772
- [`V4L2_PIX_FMT_HEVC_SLICE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-hevc-slice): `include/uapi/linux/videodev2.h`, line 776
- [`V4L2_PIX_FMT_HEXTILE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-hextile): `include/uapi/linux/videodev2.h`, line 824
- [`V4L2_PIX_FMT_HI240`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-hi240): `include/uapi/linux/videodev2.h`, line 820
- [`V4L2_PIX_FMT_HM12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#c-v4l2_pix_format): `include/uapi/linux/videodev2.h`, line 2835
- [`V4L2_PIX_FMT_HSV24`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-hsv.md#rst-v4l2-pix-fmt-hsv24): `include/uapi/linux/videodev2.h`, line 749
- [`V4L2_PIX_FMT_HSV32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-hsv.md#rst-v4l2-pix-fmt-hsv32): `include/uapi/linux/videodev2.h`, line 750
- [`V4L2_PIX_FMT_INZI`](/kernel/userspace/userspace-api/media-v4l/pixfmt-inzi.md#rst-v4l2-pix-fmt-inzi): `include/uapi/linux/videodev2.h`, line 818
- [`V4L2_PIX_FMT_IPU3_SBGGR10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10-ipu3.md#rst-v4l2-pix-fmt-ipu3-sbggr10): `include/uapi/linux/videodev2.h`, line 827
- [`V4L2_PIX_FMT_IPU3_SGBRG10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10-ipu3.md#rst-v4l2-pix-fmt-ipu3-sgbrg10): `include/uapi/linux/videodev2.h`, line 828
- [`V4L2_PIX_FMT_IPU3_SGRBG10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10-ipu3.md#rst-v4l2-pix-fmt-ipu3-sgrbg10): `include/uapi/linux/videodev2.h`, line 829
- [`V4L2_PIX_FMT_IPU3_SRGGB10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10-ipu3.md#rst-v4l2-pix-fmt-ipu3-srggb10): `include/uapi/linux/videodev2.h`, line 830
- [`V4L2_PIX_FMT_IPU3_Y10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-ipu3-y10): `include/uapi/linux/videodev2.h`, line 612
- [`V4L2_PIX_FMT_JL2005BCD`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-jl2005bcd): `include/uapi/linux/videodev2.h`, line 797
- [`V4L2_PIX_FMT_JPEG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-jpeg): `include/uapi/linux/videodev2.h`, line 754
- [`V4L2_PIX_FMT_JPGL`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-jpgl): `include/uapi/linux/videodev2.h`, line 807
- [`V4L2_PIX_FMT_KONICA420`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-konica420): `include/uapi/linux/videodev2.h`, line 806
- [`V4L2_PIX_FMT_M420`](/kernel/userspace/userspace-api/media-v4l/pixfmt-m420.md#rst-v4l2-pix-fmt-m420): `include/uapi/linux/videodev2.h`, line 640
- [`V4L2_PIX_FMT_MJPEG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-mjpeg): `include/uapi/linux/videodev2.h`, line 753
- [`V4L2_PIX_FMT_MM21`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-mm21): `include/uapi/linux/videodev2.h`, line 815
- [`V4L2_PIX_FMT_MPEG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-mpeg): `include/uapi/linux/videodev2.h`, line 756
- [`V4L2_PIX_FMT_MPEG1`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-mpeg1): `include/uapi/linux/videodev2.h`, line 761
- [`V4L2_PIX_FMT_MPEG2`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-mpeg2): `include/uapi/linux/videodev2.h`, line 762
- [`V4L2_PIX_FMT_MPEG2_SLICE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-mpeg2-slice): `include/uapi/linux/videodev2.h`, line 763
- [`V4L2_PIX_FMT_MPEG4`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-mpeg4): `include/uapi/linux/videodev2.h`, line 764
- [`V4L2_PIX_FMT_MR97310A`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-mr97310a): `include/uapi/linux/videodev2.h`, line 796
- [`V4L2_PIX_FMT_MT2110R`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-mt2110r): `include/uapi/linux/videodev2.h`, line 817
- [`V4L2_PIX_FMT_MT2110T`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-mt2110t): `include/uapi/linux/videodev2.h`, line 816
- [`V4L2_PIX_FMT_MT21C`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-mt21c): `include/uapi/linux/videodev2.h`, line 814
- [`V4L2_PIX_FMT_NV12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12): `include/uapi/linux/videodev2.h`, line 652
- [`V4L2_PIX_FMT_NV12M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12m): `include/uapi/linux/videodev2.h`, line 664
- [`V4L2_PIX_FMT_NV12MT`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12mt): `include/uapi/linux/videodev2.h`, line 696
- [`V4L2_PIX_FMT_NV12MT_16X16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12mt-16x16): `include/uapi/linux/videodev2.h`, line 697
- [`V4L2_PIX_FMT_NV12M_10BE_8L128`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12m-10be-8l128): `include/uapi/linux/videodev2.h`, line 699
- [`V4L2_PIX_FMT_NV12M_8L128`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12m-8l128): `include/uapi/linux/videodev2.h`, line 698
- [`V4L2_PIX_FMT_NV12_10BE_8L128`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12-10be-8l128): `include/uapi/linux/videodev2.h`, line 693
- [`V4L2_PIX_FMT_NV12_16L16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12-16l16): `include/uapi/linux/videodev2.h`, line 688
- [`V4L2_PIX_FMT_NV12_32L32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12-32l32): `include/uapi/linux/videodev2.h`, line 689
- [`V4L2_PIX_FMT_NV12_4L4`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12-4l4): `include/uapi/linux/videodev2.h`, line 687
- [`V4L2_PIX_FMT_NV12_8L128`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv12-8l128): `include/uapi/linux/videodev2.h`, line 692
- [`V4L2_PIX_FMT_NV15`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv15): `include/uapi/linux/videodev2.h`, line 654
- [`V4L2_PIX_FMT_NV15_4L4`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv15-4l4): `include/uapi/linux/videodev2.h`, line 690
- [`V4L2_PIX_FMT_NV16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv16): `include/uapi/linux/videodev2.h`, line 655
- [`V4L2_PIX_FMT_NV16M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv16m): `include/uapi/linux/videodev2.h`, line 666
- [`V4L2_PIX_FMT_NV20`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv20): `include/uapi/linux/videodev2.h`, line 657
- [`V4L2_PIX_FMT_NV21`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv21): `include/uapi/linux/videodev2.h`, line 653
- [`V4L2_PIX_FMT_NV21M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv21m): `include/uapi/linux/videodev2.h`, line 665
- [`V4L2_PIX_FMT_NV24`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv24): `include/uapi/linux/videodev2.h`, line 658
- [`V4L2_PIX_FMT_NV42`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv42): `include/uapi/linux/videodev2.h`, line 659
- [`V4L2_PIX_FMT_NV61`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv61): `include/uapi/linux/videodev2.h`, line 656
- [`V4L2_PIX_FMT_NV61M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-nv61m): `include/uapi/linux/videodev2.h`, line 667
- [`V4L2_PIX_FMT_OV511`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-ov511): `include/uapi/linux/videodev2.h`, line 801
- [`V4L2_PIX_FMT_OV518`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-ov518): `include/uapi/linux/videodev2.h`, line 802
- [`V4L2_PIX_FMT_P010`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-p010): `include/uapi/linux/videodev2.h`, line 660
- [`V4L2_PIX_FMT_P010_4L4`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-p010-4l4): `include/uapi/linux/videodev2.h`, line 691
- [`V4L2_PIX_FMT_P012`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-p012): `include/uapi/linux/videodev2.h`, line 661
- [`V4L2_PIX_FMT_P012M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-p012m): `include/uapi/linux/videodev2.h`, line 668
- [`V4L2_PIX_FMT_PAC207`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-pac207): `include/uapi/linux/videodev2.h`, line 795
- [`V4L2_PIX_FMT_PAL8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-indexed.md#rst-v4l2-pix-fmt-pal8): `include/uapi/linux/videodev2.h`, line 617
- [`V4L2_PIX_FMT_PISP_COMP1_BGGR`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp1-bggr): `include/uapi/linux/videodev2.h`, line 836
- [`V4L2_PIX_FMT_PISP_COMP1_GBRG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp1-gbrg): `include/uapi/linux/videodev2.h`, line 835
- [`V4L2_PIX_FMT_PISP_COMP1_GRBG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp1-grbg): `include/uapi/linux/videodev2.h`, line 834
- [`V4L2_PIX_FMT_PISP_COMP1_MONO`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp1-mono): `include/uapi/linux/videodev2.h`, line 837
- [`V4L2_PIX_FMT_PISP_COMP1_RGGB`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp1-rggb): `include/uapi/linux/videodev2.h`, line 833
- [`V4L2_PIX_FMT_PISP_COMP2_BGGR`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp2-bggr): `include/uapi/linux/videodev2.h`, line 841
- [`V4L2_PIX_FMT_PISP_COMP2_GBRG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp2-gbrg): `include/uapi/linux/videodev2.h`, line 840
- [`V4L2_PIX_FMT_PISP_COMP2_GRBG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp2-grbg): `include/uapi/linux/videodev2.h`, line 839
- [`V4L2_PIX_FMT_PISP_COMP2_MONO`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp2-mono): `include/uapi/linux/videodev2.h`, line 842
- [`V4L2_PIX_FMT_PISP_COMP2_RGGB`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8-pisp-comp.md#rst-v4l2-pix-fmt-pisp-comp2-rggb): `include/uapi/linux/videodev2.h`, line 838
- [`V4L2_PIX_FMT_PJPG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-pjpg): `include/uapi/linux/videodev2.h`, line 800
- [`V4L2_PIX_FMT_PRIV_MAGIC`](/kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#c-v4l2_pix_format): `include/uapi/linux/videodev2.h`, line 907
- [`V4L2_PIX_FMT_PWC1`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-pwc1): `include/uapi/linux/videodev2.h`, line 788
- [`V4L2_PIX_FMT_PWC2`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-pwc2): `include/uapi/linux/videodev2.h`, line 789
- [`V4L2_PIX_FMT_QC08C`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-qc08c): `include/uapi/linux/videodev2.h`, line 821
- [`V4L2_PIX_FMT_QC10C`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-qc10c): `include/uapi/linux/videodev2.h`, line 822
- [`V4L2_PIX_FMT_RAW_CRU10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rawnn-cru.md#rst-v4l2-pix-fmt-raw-cru10): `include/uapi/linux/videodev2.h`, line 845
- [`V4L2_PIX_FMT_RAW_CRU12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rawnn-cru.md#rst-v4l2-pix-fmt-raw-cru12): `include/uapi/linux/videodev2.h`, line 846
- [`V4L2_PIX_FMT_RAW_CRU14`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rawnn-cru.md#rst-v4l2-pix-fmt-raw-cru14): `include/uapi/linux/videodev2.h`, line 847
- [`V4L2_PIX_FMT_RAW_CRU20`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rawnn-cru.md#rst-v4l2-pix-fmt-raw-cru20): `include/uapi/linux/videodev2.h`, line 848
- [`V4L2_PIX_FMT_RGB24`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb24): `include/uapi/linux/videodev2.h`, line 577
- [`V4L2_PIX_FMT_RGB32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb32): `include/uapi/linux/videodev2.h`, line 583
- [`V4L2_PIX_FMT_RGB332`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb332): `include/uapi/linux/videodev2.h`, line 549
- [`V4L2_PIX_FMT_RGB444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb444): `include/uapi/linux/videodev2.h`, line 550
- [`V4L2_PIX_FMT_RGB48`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb48): `include/uapi/linux/videodev2.h`, line 595
- [`V4L2_PIX_FMT_RGB555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb555): `include/uapi/linux/videodev2.h`, line 559
- [`V4L2_PIX_FMT_RGB555X`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb555x): `include/uapi/linux/videodev2.h`, line 569
- [`V4L2_PIX_FMT_RGB565`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb565): `include/uapi/linux/videodev2.h`, line 568
- [`V4L2_PIX_FMT_RGB565X`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb565x): `include/uapi/linux/videodev2.h`, line 572
- [`V4L2_PIX_FMT_RGBA1010102`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgba1010102): `include/uapi/linux/videodev2.h`, line 589
- [`V4L2_PIX_FMT_RGBA32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgba32): `include/uapi/linux/videodev2.h`, line 584
- [`V4L2_PIX_FMT_RGBA444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgba444): `include/uapi/linux/videodev2.h`, line 553
- [`V4L2_PIX_FMT_RGBA555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgba555): `include/uapi/linux/videodev2.h`, line 562
- [`V4L2_PIX_FMT_RGBX1010102`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgbx1010102): `include/uapi/linux/videodev2.h`, line 588
- [`V4L2_PIX_FMT_RGBX32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgbx32): `include/uapi/linux/videodev2.h`, line 585
- [`V4L2_PIX_FMT_RGBX444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgbx444): `include/uapi/linux/videodev2.h`, line 554
- [`V4L2_PIX_FMT_RGBX555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgbx555): `include/uapi/linux/videodev2.h`, line 563
- [`V4L2_PIX_FMT_RV30`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-rv30): `include/uapi/linux/videodev2.h`, line 780
- [`V4L2_PIX_FMT_RV40`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-rv40): `include/uapi/linux/videodev2.h`, line 781
- [`V4L2_PIX_FMT_S5C_UYVY_JPG`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-s5c-uyvy-jpg): `include/uapi/linux/videodev2.h`, line 809
- [`V4L2_PIX_FMT_SBGGR10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10.md#rst-v4l2-pix-fmt-sbggr10): `include/uapi/linux/videodev2.h`, line 706
- [`V4L2_PIX_FMT_SBGGR10ALAW8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10alaw8.md#rst-v4l2-pix-fmt-sbggr10alaw8): `include/uapi/linux/videodev2.h`, line 716
- [`V4L2_PIX_FMT_SBGGR10DPCM8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10dpcm8.md#rst-v4l2-pix-fmt-sbggr10dpcm8): `include/uapi/linux/videodev2.h`, line 721
- [`V4L2_PIX_FMT_SBGGR10P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10p.md#rst-v4l2-pix-fmt-sbggr10p): `include/uapi/linux/videodev2.h`, line 711
- [`V4L2_PIX_FMT_SBGGR12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12.md#rst-v4l2-pix-fmt-sbggr12): `include/uapi/linux/videodev2.h`, line 725
- [`V4L2_PIX_FMT_SBGGR12P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12p.md#rst-v4l2-pix-fmt-sbggr12p): `include/uapi/linux/videodev2.h`, line 730
- [`V4L2_PIX_FMT_SBGGR14`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14.md#rst-v4l2-pix-fmt-sbggr14): `include/uapi/linux/videodev2.h`, line 734
- [`V4L2_PIX_FMT_SBGGR14P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14p.md#rst-v4l2-pix-fmt-sbggr14p): `include/uapi/linux/videodev2.h`, line 739
- [`V4L2_PIX_FMT_SBGGR16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb16.md#rst-v4l2-pix-fmt-sbggr16): `include/uapi/linux/videodev2.h`, line 743
- [`V4L2_PIX_FMT_SBGGR8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-sbggr8): `include/uapi/linux/videodev2.h`, line 702
- [`V4L2_PIX_FMT_SE401`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-se401): `include/uapi/linux/videodev2.h`, line 808
- [`V4L2_PIX_FMT_SGBRG10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10.md#rst-v4l2-pix-fmt-sgbrg10): `include/uapi/linux/videodev2.h`, line 707
- [`V4L2_PIX_FMT_SGBRG10ALAW8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10alaw8.md#rst-v4l2-pix-fmt-sgbrg10alaw8): `include/uapi/linux/videodev2.h`, line 717
- [`V4L2_PIX_FMT_SGBRG10DPCM8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10dpcm8.md#rst-v4l2-pix-fmt-sgbrg10dpcm8): `include/uapi/linux/videodev2.h`, line 722
- [`V4L2_PIX_FMT_SGBRG10P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10p.md#rst-v4l2-pix-fmt-sgbrg10p): `include/uapi/linux/videodev2.h`, line 712
- [`V4L2_PIX_FMT_SGBRG12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12.md#rst-v4l2-pix-fmt-sgbrg12): `include/uapi/linux/videodev2.h`, line 726
- [`V4L2_PIX_FMT_SGBRG12P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12p.md#rst-v4l2-pix-fmt-sgbrg12p): `include/uapi/linux/videodev2.h`, line 731
- [`V4L2_PIX_FMT_SGBRG14`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14.md#rst-v4l2-pix-fmt-sgbrg14): `include/uapi/linux/videodev2.h`, line 735
- [`V4L2_PIX_FMT_SGBRG14P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14p.md#rst-v4l2-pix-fmt-sgbrg14p): `include/uapi/linux/videodev2.h`, line 740
- [`V4L2_PIX_FMT_SGBRG16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb16.md#rst-v4l2-pix-fmt-sgbrg16): `include/uapi/linux/videodev2.h`, line 744
- [`V4L2_PIX_FMT_SGBRG8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-sgbrg8): `include/uapi/linux/videodev2.h`, line 703
- [`V4L2_PIX_FMT_SGRBG10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10.md#rst-v4l2-pix-fmt-sgrbg10): `include/uapi/linux/videodev2.h`, line 708
- [`V4L2_PIX_FMT_SGRBG10ALAW8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10alaw8.md#rst-v4l2-pix-fmt-sgrbg10alaw8): `include/uapi/linux/videodev2.h`, line 718
- [`V4L2_PIX_FMT_SGRBG10DPCM8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10dpcm8.md#rst-v4l2-pix-fmt-sgrbg10dpcm8): `include/uapi/linux/videodev2.h`, line 723
- [`V4L2_PIX_FMT_SGRBG10P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10p.md#rst-v4l2-pix-fmt-sgrbg10p): `include/uapi/linux/videodev2.h`, line 713
- [`V4L2_PIX_FMT_SGRBG12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12.md#rst-v4l2-pix-fmt-sgrbg12): `include/uapi/linux/videodev2.h`, line 727
- [`V4L2_PIX_FMT_SGRBG12P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12p.md#rst-v4l2-pix-fmt-sgrbg12p): `include/uapi/linux/videodev2.h`, line 732
- [`V4L2_PIX_FMT_SGRBG14`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14.md#rst-v4l2-pix-fmt-sgrbg14): `include/uapi/linux/videodev2.h`, line 736
- [`V4L2_PIX_FMT_SGRBG14P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14p.md#rst-v4l2-pix-fmt-sgrbg14p): `include/uapi/linux/videodev2.h`, line 741
- [`V4L2_PIX_FMT_SGRBG16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb16.md#rst-v4l2-pix-fmt-sgrbg16): `include/uapi/linux/videodev2.h`, line 745
- [`V4L2_PIX_FMT_SGRBG8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-sgrbg8): `include/uapi/linux/videodev2.h`, line 704
- [`V4L2_PIX_FMT_SN9C10X`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-sn9c10x): `include/uapi/linux/videodev2.h`, line 786
- [`V4L2_PIX_FMT_SN9C2028`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-sn9c2028): `include/uapi/linux/videodev2.h`, line 798
- [`V4L2_PIX_FMT_SN9C20X_I420`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-sn9c20x-i420): `include/uapi/linux/videodev2.h`, line 787
- [`V4L2_PIX_FMT_SPCA501`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-spca501): `include/uapi/linux/videodev2.h`, line 791
- [`V4L2_PIX_FMT_SPCA505`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-spca505): `include/uapi/linux/videodev2.h`, line 792
- [`V4L2_PIX_FMT_SPCA508`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-spca508): `include/uapi/linux/videodev2.h`, line 793
- [`V4L2_PIX_FMT_SPCA561`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-spca561): `include/uapi/linux/videodev2.h`, line 794
- [`V4L2_PIX_FMT_SPK`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-spk): `include/uapi/linux/videodev2.h`, line 779
- [`V4L2_PIX_FMT_SQ905C`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-sq905c): `include/uapi/linux/videodev2.h`, line 799
- [`V4L2_PIX_FMT_SRGGB10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10.md#rst-v4l2-pix-fmt-srggb10): `include/uapi/linux/videodev2.h`, line 709
- [`V4L2_PIX_FMT_SRGGB10ALAW8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10alaw8.md#rst-v4l2-pix-fmt-srggb10alaw8): `include/uapi/linux/videodev2.h`, line 719
- [`V4L2_PIX_FMT_SRGGB10DPCM8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10dpcm8.md#rst-v4l2-pix-fmt-srggb10dpcm8): `include/uapi/linux/videodev2.h`, line 724
- [`V4L2_PIX_FMT_SRGGB10P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb10p.md#rst-v4l2-pix-fmt-srggb10p): `include/uapi/linux/videodev2.h`, line 714
- [`V4L2_PIX_FMT_SRGGB12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12.md#rst-v4l2-pix-fmt-srggb12): `include/uapi/linux/videodev2.h`, line 728
- [`V4L2_PIX_FMT_SRGGB12P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb12p.md#rst-v4l2-pix-fmt-srggb12p): `include/uapi/linux/videodev2.h`, line 733
- [`V4L2_PIX_FMT_SRGGB14`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14.md#rst-v4l2-pix-fmt-srggb14): `include/uapi/linux/videodev2.h`, line 737
- [`V4L2_PIX_FMT_SRGGB14P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb14p.md#rst-v4l2-pix-fmt-srggb14p): `include/uapi/linux/videodev2.h`, line 742
- [`V4L2_PIX_FMT_SRGGB16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb16.md#rst-v4l2-pix-fmt-srggb16): `include/uapi/linux/videodev2.h`, line 746
- [`V4L2_PIX_FMT_SRGGB8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-srggb8.md#rst-v4l2-pix-fmt-srggb8): `include/uapi/linux/videodev2.h`, line 705
- [`V4L2_PIX_FMT_STV0680`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-stv0680): `include/uapi/linux/videodev2.h`, line 803
- [`V4L2_PIX_FMT_SUNXI_TILED_NV12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#c-v4l2_pix_format): `include/uapi/linux/videodev2.h`, line 2836
- [`V4L2_PIX_FMT_TM6000`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-tm6000): `include/uapi/linux/videodev2.h`, line 804
- [`V4L2_PIX_FMT_UV8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-uv8.md#rst-v4l2-pix-fmt-uv8): `include/uapi/linux/videodev2.h`, line 620
- [`V4L2_PIX_FMT_UYVY`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-uyvy): `include/uapi/linux/videodev2.h`, line 626
- [`V4L2_PIX_FMT_VC1_ANNEX_G`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-vc1-annex-g): `include/uapi/linux/videodev2.h`, line 766
- [`V4L2_PIX_FMT_VC1_ANNEX_L`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-vc1-annex-l): `include/uapi/linux/videodev2.h`, line 767
- [`V4L2_PIX_FMT_VP8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-vp8): `include/uapi/linux/videodev2.h`, line 768
- [`V4L2_PIX_FMT_VP8_FRAME`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-vp8-frame): `include/uapi/linux/videodev2.h`, line 769
- [`V4L2_PIX_FMT_VP9`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-vp9): `include/uapi/linux/videodev2.h`, line 770
- [`V4L2_PIX_FMT_VP9_FRAME`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-vp9-frame): `include/uapi/linux/videodev2.h`, line 771
- [`V4L2_PIX_FMT_VUYA32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-vuya32): `include/uapi/linux/videodev2.h`, line 636
- [`V4L2_PIX_FMT_VUYX32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-vuyx32): `include/uapi/linux/videodev2.h`, line 637
- [`V4L2_PIX_FMT_VYUY`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-vyuy): `include/uapi/linux/videodev2.h`, line 627
- [`V4L2_PIX_FMT_WNVA`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-wnva): `include/uapi/linux/videodev2.h`, line 785
- [`V4L2_PIX_FMT_XBGR32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-xbgr32): `include/uapi/linux/videodev2.h`, line 580
- [`V4L2_PIX_FMT_XBGR444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-xbgr444): `include/uapi/linux/videodev2.h`, line 556
- [`V4L2_PIX_FMT_XBGR555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-xbgr555): `include/uapi/linux/videodev2.h`, line 565
- [`V4L2_PIX_FMT_XRGB32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-xrgb32): `include/uapi/linux/videodev2.h`, line 587
- [`V4L2_PIX_FMT_XRGB444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-xrgb444): `include/uapi/linux/videodev2.h`, line 552
- [`V4L2_PIX_FMT_XRGB555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-xrgb555): `include/uapi/linux/videodev2.h`, line 561
- [`V4L2_PIX_FMT_XRGB555X`](/kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-xrgb555x): `include/uapi/linux/videodev2.h`, line 571
- [`V4L2_PIX_FMT_XVID`](/kernel/userspace/userspace-api/media-v4l/pixfmt-compressed.md#rst-v4l2-pix-fmt-xvid): `include/uapi/linux/videodev2.h`, line 765
- [`V4L2_PIX_FMT_XYUV32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-xyuv32): `include/uapi/linux/videodev2.h`, line 635
- [`V4L2_PIX_FMT_Y012`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y012): `include/uapi/linux/videodev2.h`, line 604
- [`V4L2_PIX_FMT_Y10`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y10): `include/uapi/linux/videodev2.h`, line 602
- [`V4L2_PIX_FMT_Y10BPACK`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y10bpack): `include/uapi/linux/videodev2.h`, line 610
- [`V4L2_PIX_FMT_Y10P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y10p): `include/uapi/linux/videodev2.h`, line 611
- [`V4L2_PIX_FMT_Y12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y12): `include/uapi/linux/videodev2.h`, line 603
- [`V4L2_PIX_FMT_Y12I`](/kernel/userspace/userspace-api/media-v4l/pixfmt-y12i.md#rst-v4l2-pix-fmt-y12i): `include/uapi/linux/videodev2.h`, line 811
- [`V4L2_PIX_FMT_Y12P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y12p): `include/uapi/linux/videodev2.h`, line 613
- [`V4L2_PIX_FMT_Y14`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y14): `include/uapi/linux/videodev2.h`, line 605
- [`V4L2_PIX_FMT_Y14P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y14p): `include/uapi/linux/videodev2.h`, line 614
- [`V4L2_PIX_FMT_Y16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y16): `include/uapi/linux/videodev2.h`, line 606
- [`V4L2_PIX_FMT_Y16I`](/kernel/userspace/userspace-api/media-v4l/pixfmt-y16i.md#rst-v4l2-pix-fmt-y16i): `include/uapi/linux/videodev2.h`, line 812
- [`V4L2_PIX_FMT_Y16_BE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-luma.md#rst-v4l2-pix-fmt-y16-be): `include/uapi/linux/videodev2.h`, line 607
- [`V4L2_PIX_FMT_Y210`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-y210): `include/uapi/linux/videodev2.h`, line 647
- [`V4L2_PIX_FMT_Y212`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-y212): `include/uapi/linux/videodev2.h`, line 648
- [`V4L2_PIX_FMT_Y216`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-y216): `include/uapi/linux/videodev2.h`, line 649
- [`V4L2_PIX_FMT_Y4`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-y4): `include/uapi/linux/videodev2.h`, line 600
- [`V4L2_PIX_FMT_Y41P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-y41p): `include/uapi/linux/videodev2.h`, line 628
- [`V4L2_PIX_FMT_Y6`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-y6): `include/uapi/linux/videodev2.h`, line 601
- [`V4L2_PIX_FMT_Y8I`](/kernel/userspace/userspace-api/media-v4l/pixfmt-y8i.md#rst-v4l2-pix-fmt-y8i): `include/uapi/linux/videodev2.h`, line 810
- [`V4L2_PIX_FMT_YUV24`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuv24): `include/uapi/linux/videodev2.h`, line 632
- [`V4L2_PIX_FMT_YUV32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuv32): `include/uapi/linux/videodev2.h`, line 633
- [`V4L2_PIX_FMT_YUV410`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv410): `include/uapi/linux/videodev2.h`, line 671
- [`V4L2_PIX_FMT_YUV411P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv411p): `include/uapi/linux/videodev2.h`, line 673
- [`V4L2_PIX_FMT_YUV420`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv420): `include/uapi/linux/videodev2.h`, line 674
- [`V4L2_PIX_FMT_YUV420M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv420m): `include/uapi/linux/videodev2.h`, line 679
- [`V4L2_PIX_FMT_YUV422M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv422m): `include/uapi/linux/videodev2.h`, line 681
- [`V4L2_PIX_FMT_YUV422P`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv422p): `include/uapi/linux/videodev2.h`, line 676
- [`V4L2_PIX_FMT_YUV444`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuv444): `include/uapi/linux/videodev2.h`, line 629
- [`V4L2_PIX_FMT_YUV444M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yuv444m): `include/uapi/linux/videodev2.h`, line 683
- [`V4L2_PIX_FMT_YUV48_12`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuv48-12): `include/uapi/linux/videodev2.h`, line 641
- [`V4L2_PIX_FMT_YUV555`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuv555): `include/uapi/linux/videodev2.h`, line 630
- [`V4L2_PIX_FMT_YUV565`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuv565): `include/uapi/linux/videodev2.h`, line 631
- [`V4L2_PIX_FMT_YUVA32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuva32): `include/uapi/linux/videodev2.h`, line 638
- [`V4L2_PIX_FMT_YUVX32`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuvx32): `include/uapi/linux/videodev2.h`, line 639
- [`V4L2_PIX_FMT_YUYV`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yuyv): `include/uapi/linux/videodev2.h`, line 623
- [`V4L2_PIX_FMT_YVU410`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu410): `include/uapi/linux/videodev2.h`, line 672
- [`V4L2_PIX_FMT_YVU420`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu420): `include/uapi/linux/videodev2.h`, line 675
- [`V4L2_PIX_FMT_YVU420M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu420m): `include/uapi/linux/videodev2.h`, line 680
- [`V4L2_PIX_FMT_YVU422M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu422m): `include/uapi/linux/videodev2.h`, line 682
- [`V4L2_PIX_FMT_YVU444M`](/kernel/userspace/userspace-api/media-v4l/pixfmt-yuv-planar.md#rst-v4l2-pix-fmt-yvu444m): `include/uapi/linux/videodev2.h`, line 684
- [`V4L2_PIX_FMT_YVYU`](/kernel/userspace/userspace-api/media-v4l/pixfmt-packed-yuv.md#rst-v4l2-pix-fmt-yvyu): `include/uapi/linux/videodev2.h`, line 625
- [`V4L2_PIX_FMT_YYUV`](/kernel/userspace/userspace-api/media-v4l/pixfmt-reserved.md#rst-v4l2-pix-fmt-yyuv): `include/uapi/linux/videodev2.h`, line 624
- [`V4L2_PIX_FMT_Z16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-z16.md#rst-v4l2-pix-fmt-z16): `include/uapi/linux/videodev2.h`, line 813
- [`V4L2_RDS_BLOCK_A`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2168
- [`V4L2_RDS_BLOCK_B`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2169
- [`V4L2_RDS_BLOCK_C`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2170
- [`V4L2_RDS_BLOCK_CORRECTED`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2175
- [`V4L2_RDS_BLOCK_C_ALT`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2172
- [`V4L2_RDS_BLOCK_D`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2171
- [`V4L2_RDS_BLOCK_ERROR`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2176
- [`V4L2_RDS_BLOCK_INVALID`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2173
- [`V4L2_RDS_BLOCK_MSK`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-v4l2-rds-block): `include/uapi/linux/videodev2.h`, line 2167
- [`V4L2_SDR_FMT_CS14LE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-cs14le.md#rst-v4l2-sdr-fmt-cs14le): `include/uapi/linux/videodev2.h`, line 854
- [`V4L2_SDR_FMT_CS8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-cs08.md#rst-v4l2-sdr-fmt-cs8): `include/uapi/linux/videodev2.h`, line 853
- [`V4L2_SDR_FMT_CU16LE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-cu16le.md#rst-v4l2-sdr-fmt-cu16le): `include/uapi/linux/videodev2.h`, line 852
- [`V4L2_SDR_FMT_CU8`](/kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-cu08.md#rst-v4l2-sdr-fmt-cu8): `include/uapi/linux/videodev2.h`, line 851
- [`V4L2_SDR_FMT_PCU16BE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-pcu16be.md#rst-v4l2-sdr-fmt-pcu16be): `include/uapi/linux/videodev2.h`, line 856
- [`V4L2_SDR_FMT_PCU18BE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-pcu18be.md#rst-v4l2-sdr-fmt-pcu18be): `include/uapi/linux/videodev2.h`, line 857
- [`V4L2_SDR_FMT_PCU20BE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-pcu20be.md#rst-v4l2-sdr-fmt-pcu20be): `include/uapi/linux/videodev2.h`, line 858
- [`V4L2_SDR_FMT_RU12LE`](/kernel/userspace/userspace-api/media-v4l/pixfmt-sdr-ru12le.md#rst-v4l2-sdr-fmt-ru12le): `include/uapi/linux/videodev2.h`, line 855
- [`V4L2_SLICED_CAPTION_525`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vbi-services): `include/uapi/linux/videodev2.h`, line 2352
- [`V4L2_SLICED_TELETEXT_B`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vbi-services): `include/uapi/linux/videodev2.h`, line 2348
- [`V4L2_SLICED_VBI_525`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vbi-services): `include/uapi/linux/videodev2.h`, line 2356
- [`V4L2_SLICED_VBI_625`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vbi-services): `include/uapi/linux/videodev2.h`, line 2357
- [`V4L2_SLICED_VPS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vbi-services): `include/uapi/linux/videodev2.h`, line 2350
- [`V4L2_SLICED_WSS_625`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#rst-vbi-services): `include/uapi/linux/videodev2.h`, line 2354
- [`V4L2_STD_525_60`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1526
- [`V4L2_STD_625_50`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1531
- [`V4L2_STD_ALL`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1540
- [`V4L2_STD_ATSC`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1536
- [`V4L2_STD_ATSC_16_VSB`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1448
- [`V4L2_STD_ATSC_8_VSB`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1447
- [`V4L2_STD_B`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1499
- [`V4L2_STD_BG`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1512
- [`V4L2_STD_DK`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1510
- [`V4L2_STD_G`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1502
- [`V4L2_STD_GH`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1508
- [`V4L2_STD_H`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1504
- [`V4L2_STD_L`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1506
- [`V4L2_STD_MN`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1514
- [`V4L2_STD_MTS`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1520
- [`V4L2_STD_NTSC`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1468
- [`V4L2_STD_NTSC_443`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1434
- [`V4L2_STD_NTSC_M`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1432
- [`V4L2_STD_NTSC_M_JP`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1433
- [`V4L2_STD_NTSC_M_KR`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1435
- [`V4L2_STD_PAL`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1494
- [`V4L2_STD_PAL_60`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1430
- [`V4L2_STD_PAL_B`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1418
- [`V4L2_STD_PAL_B1`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1419
- [`V4L2_STD_PAL_BG`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1483
- [`V4L2_STD_PAL_D`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1423
- [`V4L2_STD_PAL_D1`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1424
- [`V4L2_STD_PAL_DK`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1486
- [`V4L2_STD_PAL_G`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1420
- [`V4L2_STD_PAL_H`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1421
- [`V4L2_STD_PAL_I`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1422
- [`V4L2_STD_PAL_K`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1425
- [`V4L2_STD_PAL_M`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1427
- [`V4L2_STD_PAL_N`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1428
- [`V4L2_STD_PAL_Nc`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1429
- [`V4L2_STD_SECAM`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1476
- [`V4L2_STD_SECAM_B`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1437
- [`V4L2_STD_SECAM_D`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1438
- [`V4L2_STD_SECAM_DK`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1472
- [`V4L2_STD_SECAM_G`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1439
- [`V4L2_STD_SECAM_H`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1440
- [`V4L2_STD_SECAM_K`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1441
- [`V4L2_STD_SECAM_K1`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1442
- [`V4L2_STD_SECAM_L`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1443
- [`V4L2_STD_SECAM_LC`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1444
- [`V4L2_STD_UNKNOWN`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#rst-v4l2-std-id): `include/uapi/linux/videodev2.h`, line 1539
- [`V4L2_TCH_FMT_DELTA_TD08`](/kernel/userspace/userspace-api/media-v4l/pixfmt-tch-td08.md#rst-v4l2-tch-fmt-delta-td08): `include/uapi/linux/videodev2.h`, line 862
- [`V4L2_TCH_FMT_DELTA_TD16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-tch-td16.md#rst-v4l2-tch-fmt-delta-td16): `include/uapi/linux/videodev2.h`, line 861
- [`V4L2_TCH_FMT_TU08`](/kernel/userspace/userspace-api/media-v4l/pixfmt-tch-tu08.md#rst-v4l2-tch-fmt-tu08): `include/uapi/linux/videodev2.h`, line 864
- [`V4L2_TCH_FMT_TU16`](/kernel/userspace/userspace-api/media-v4l/pixfmt-tch-tu16.md#rst-v4l2-tch-fmt-tu16): `include/uapi/linux/videodev2.h`, line 863
- [`V4L2_TC_FLAG_COLORFRAME`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-flags): `include/uapi/linux/videodev2.h`, line 1030
- [`V4L2_TC_FLAG_DROPFRAME`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-flags): `include/uapi/linux/videodev2.h`, line 1029
- [`V4L2_TC_TYPE_24FPS`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-type): `include/uapi/linux/videodev2.h`, line 1022
- [`V4L2_TC_TYPE_25FPS`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-type): `include/uapi/linux/videodev2.h`, line 1023
- [`V4L2_TC_TYPE_30FPS`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-type): `include/uapi/linux/videodev2.h`, line 1024
- [`V4L2_TC_TYPE_50FPS`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-type): `include/uapi/linux/videodev2.h`, line 1025
- [`V4L2_TC_TYPE_60FPS`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-type): `include/uapi/linux/videodev2.h`, line 1026
- [`V4L2_TC_USERBITS_8BITCHARS`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-flags): `include/uapi/linux/videodev2.h`, line 1033
- [`V4L2_TC_USERBITS_USERDEFINED`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-flags): `include/uapi/linux/videodev2.h`, line 1032
- [`V4L2_TC_USERBITS_field`](/kernel/userspace/userspace-api/media-v4l/buffer.md#rst-timecode-flags): `include/uapi/linux/videodev2.h`, line 1031
- [`V4L2_TUNER_CAP_1HZ`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2106
- [`V4L2_TUNER_CAP_FREQ_BANDS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2104
- [`V4L2_TUNER_CAP_HWSEEK_BOUNDED`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2095
- [`V4L2_TUNER_CAP_HWSEEK_PROG_LIM`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2105
- [`V4L2_TUNER_CAP_HWSEEK_WRAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2096
- [`V4L2_TUNER_CAP_LANG1`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2100
- [`V4L2_TUNER_CAP_LANG2`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2098
- [`V4L2_TUNER_CAP_LOW`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2093
- [`V4L2_TUNER_CAP_NORM`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2094
- [`V4L2_TUNER_CAP_RDS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2101
- [`V4L2_TUNER_CAP_RDS_BLOCK_IO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2102
- [`V4L2_TUNER_CAP_RDS_CONTROLS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2103
- [`V4L2_TUNER_CAP_SAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2099
- [`V4L2_TUNER_CAP_STEREO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-capability): `include/uapi/linux/videodev2.h`, line 2097
- [`V4L2_TUNER_MODE_LANG1`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-audmode): `include/uapi/linux/videodev2.h`, line 2121
- [`V4L2_TUNER_MODE_LANG1_LANG2`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-audmode): `include/uapi/linux/videodev2.h`, line 2122
- [`V4L2_TUNER_MODE_LANG2`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-audmode): `include/uapi/linux/videodev2.h`, line 2119
- [`V4L2_TUNER_MODE_MONO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-audmode): `include/uapi/linux/videodev2.h`, line 2117
- [`V4L2_TUNER_MODE_SAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-audmode): `include/uapi/linux/videodev2.h`, line 2120
- [`V4L2_TUNER_MODE_STEREO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-audmode): `include/uapi/linux/videodev2.h`, line 2118
- [`V4L2_TUNER_SUB_LANG1`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-rxsubchans): `include/uapi/linux/videodev2.h`, line 2113
- [`V4L2_TUNER_SUB_LANG2`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-rxsubchans): `include/uapi/linux/videodev2.h`, line 2111
- [`V4L2_TUNER_SUB_MONO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-rxsubchans): `include/uapi/linux/videodev2.h`, line 2109
- [`V4L2_TUNER_SUB_RDS`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-rxsubchans): `include/uapi/linux/videodev2.h`, line 2114
- [`V4L2_TUNER_SUB_SAP`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-rxsubchans): `include/uapi/linux/videodev2.h`, line 2112
- [`V4L2_TUNER_SUB_STEREO`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#rst-tuner-rxsubchans): `include/uapi/linux/videodev2.h`, line 2110
- [`V4L2_VBI_INTERLACED`](/kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbifmt-flags): `include/uapi/linux/videodev2.h`, line 2320
- [`V4L2_VBI_ITU_525_F1_START`](/kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#c-v4l2_vbi_format): `include/uapi/linux/videodev2.h`, line 2323
- [`V4L2_VBI_ITU_525_F2_START`](/kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#c-v4l2_vbi_format): `include/uapi/linux/videodev2.h`, line 2324
- [`V4L2_VBI_ITU_625_F1_START`](/kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#c-v4l2_vbi_format): `include/uapi/linux/videodev2.h`, line 2325
- [`V4L2_VBI_ITU_625_F2_START`](/kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#c-v4l2_vbi_format): `include/uapi/linux/videodev2.h`, line 2326
- [`V4L2_VBI_UNSYNC`](/kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbifmt-flags): `include/uapi/linux/videodev2.h`, line 2319
- [`V4L2_XFER_FUNC_ADOBERGB`](/kernel/userspace/userspace-api/media-v4l/colorspaces-defs.md#c-v4l2_xfer_func): `include/uapi/linux/videodev2.h`, line 431

## Structures

- [`v4l2_area`](/kernel/userspace/userspace-api/media-v4l/ext-ctrls-image-source.md#c-v4l2_area): `include/uapi/linux/videodev2.h`, line 454
- [`v4l2_audio`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#c-v4l2_audio): `include/uapi/linux/videodev2.h`, line 2181
- [`v4l2_audioout`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-audioout.md#c-v4l2_audioout): `include/uapi/linux/videodev2.h`, line 2196
- [`v4l2_bt_timings`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#c-v4l2_bt_timings): `include/uapi/linux/videodev2.h`, line 1591
- [`v4l2_bt_timings_cap`](/kernel/userspace/userspace-api/media-v4l/vidioc-dv-timings-cap.md#c-v4l2_bt_timings_cap): `include/uapi/linux/videodev2.h`, line 1752
- [`v4l2_buffer`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_buffer): `include/uapi/linux/videodev2.h`, line 1178
- [`v4l2_capability`](/kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#c-v4l2_capability): `include/uapi/linux/videodev2.h`, line 470
- [`v4l2_captureparm`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#c-v4l2_captureparm): `include/uapi/linux/videodev2.h`, line 1348
- [`v4l2_clip`](/kernel/userspace/userspace-api/media-v4l/dev-overlay.md#c-v4l2_clip): `include/uapi/linux/videodev2.h`, line 1330
- [`v4l2_control`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#c-v4l2_control): `include/uapi/linux/videodev2.h`, line 1869
- [`v4l2_create_buffers`](/kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md#c-v4l2_create_buffers): `include/uapi/linux/videodev2.h`, line 2701
- [`v4l2_crop`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-crop.md#c-v4l2_crop): `include/uapi/linux/videodev2.h`, line 1380
- [`v4l2_cropcap`](/kernel/userspace/userspace-api/media-v4l/vidioc-cropcap.md#c-v4l2_cropcap): `include/uapi/linux/videodev2.h`, line 1373
- [`v4l2_dbg_chip_info`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-chip-info.md#c-v4l2_dbg_chip_info): `include/uapi/linux/videodev2.h`, line 2678
- [`v4l2_dbg_match`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#c-v4l2_dbg_match): `include/uapi/linux/videodev2.h`, line 2659
- [`v4l2_dbg_register`](/kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-register.md#c-v4l2_dbg_register): `include/uapi/linux/videodev2.h`, line 2667
- [`v4l2_decoder_cmd`](/kernel/userspace/userspace-api/media-v4l/vidioc-decoder-cmd.md#c-v4l2_decoder_cmd): `include/uapi/linux/videodev2.h`, line 2274
- [`v4l2_dv_timings`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#c-v4l2_dv_timings): `include/uapi/linux/videodev2.h`, line 1715
- [`v4l2_dv_timings_cap`](/kernel/userspace/userspace-api/media-v4l/vidioc-dv-timings-cap.md#c-v4l2_dv_timings_cap): `include/uapi/linux/videodev2.h`, line 1779
- [`v4l2_enc_idx`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md#c-v4l2_enc_idx): `include/uapi/linux/videodev2.h`, line 2222
- [`v4l2_enc_idx_entry`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-enc-index.md#c-v4l2_enc_idx_entry): `include/uapi/linux/videodev2.h`, line 2213
- [`v4l2_encoder_cmd`](/kernel/userspace/userspace-api/media-v4l/vidioc-encoder-cmd.md#c-v4l2_encoder_cmd): `include/uapi/linux/videodev2.h`, line 2238
- [`v4l2_enum_dv_timings`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-dv-timings.md#c-v4l2_enum_dv_timings): `include/uapi/linux/videodev2.h`, line 1734
- [`v4l2_event`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#c-v4l2_event): `include/uapi/linux/videodev2.h`, line 2610
- [`v4l2_event_ctrl`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#c-v4l2_event_ctrl): `include/uapi/linux/videodev2.h`, line 2571
- [`v4l2_event_frame_sync`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#c-v4l2_event_frame_sync): `include/uapi/linux/videodev2.h`, line 2585
- [`v4l2_event_motion_det`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#c-v4l2_event_motion_det): `include/uapi/linux/videodev2.h`, line 2604
- [`v4l2_event_src_change`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#c-v4l2_event_src_change): `include/uapi/linux/videodev2.h`, line 2591
- [`v4l2_event_subscription`](/kernel/userspace/userspace-api/media-v4l/vidioc-subscribe-event.md#c-v4l2_event_subscription): `include/uapi/linux/videodev2.h`, line 2634
- [`v4l2_event_vsync`](/kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#c-v4l2_event_vsync): `include/uapi/linux/videodev2.h`, line 2560
- [`v4l2_exportbuffer`](/kernel/userspace/userspace-api/media-v4l/vidioc-expbuf.md#c-v4l2_exportbuffer): `include/uapi/linux/videodev2.h`, line 1281
- [`v4l2_ext_control`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#c-v4l2_ext_control): `include/uapi/linux/videodev2.h`, line 1874
- [`v4l2_ext_controls`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#c-v4l2_ext_controls): `include/uapi/linux/videodev2.h`, line 1917
- [`v4l2_fmtdesc`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#c-v4l2_fmtdesc): `include/uapi/linux/videodev2.h`, line 916
- [`v4l2_format`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#c-v4l2_format): `include/uapi/linux/videodev2.h`, line 2521
- [`v4l2_fract`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#c-v4l2_fract): `include/uapi/linux/videodev2.h`, line 449
- [`v4l2_framebuffer`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-fbuf.md#c-v4l2_framebuffer): `include/uapi/linux/videodev2.h`, line 1293
- [`v4l2_frequency`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#c-v4l2_frequency): `include/uapi/linux/videodev2.h`, line 2124
- [`v4l2_frequency_band`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#c-v4l2_frequency_band): `include/uapi/linux/videodev2.h`, line 2135
- [`v4l2_frmival_stepwise`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#c-v4l2_frmival_stepwise): `include/uapi/linux/videodev2.h`, line 987
- [`v4l2_frmivalenum`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-frameintervals.md#c-v4l2_frmivalenum): `include/uapi/linux/videodev2.h`, line 993
- [`v4l2_frmsize_discrete`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#c-v4l2_frmsize_discrete): `include/uapi/linux/videodev2.h`, line 951
- [`v4l2_frmsize_stepwise`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#c-v4l2_frmsize_stepwise): `include/uapi/linux/videodev2.h`, line 956
- [`v4l2_frmsizeenum`](/kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#c-v4l2_frmsizeenum): `include/uapi/linux/videodev2.h`, line 965
- [`v4l2_hw_freq_seek`](/kernel/userspace/userspace-api/media-v4l/vidioc-s-hw-freq-seek.md#c-v4l2_hw_freq_seek): `include/uapi/linux/videodev2.h`, line 2146
- [`v4l2_input`](/kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#c-v4l2_input): `include/uapi/linux/videodev2.h`, line 1793
- [`v4l2_jpegcompression`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-jpegcomp.md#c-v4l2_jpegcompression): `include/uapi/linux/videodev2.h`, line 1036
- [`v4l2_meta_format`](/kernel/userspace/userspace-api/media-v4l/dev-meta.md#c-v4l2_meta_format): `include/uapi/linux/videodev2.h`, line 2501
- [`v4l2_modulator`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-modulator.md#c-v4l2_modulator): `include/uapi/linux/videodev2.h`, line 2081
- [`v4l2_mpeg_vbi_ITV0`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#c-v4l2_mpeg_vbi_itv0): `include/uapi/linux/videodev2.h`, line 2410
- [`v4l2_mpeg_vbi_fmt_ivtv`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#c-v4l2_mpeg_vbi_fmt_ivtv): `include/uapi/linux/videodev2.h`, line 2417
- [`v4l2_mpeg_vbi_itv0`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#c-v4l2_mpeg_vbi_itv0): `include/uapi/linux/videodev2.h`, line 2405
- [`v4l2_mpeg_vbi_itv0_line`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#c-v4l2_mpeg_vbi_itv0_line): `include/uapi/linux/videodev2.h`, line 2400
- [`v4l2_output`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#c-v4l2_output): `include/uapi/linux/videodev2.h`, line 1845
- [`v4l2_outputparm`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#c-v4l2_outputparm): `include/uapi/linux/videodev2.h`, line 1361
- [`v4l2_pix_format`](/kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#c-v4l2_pix_format): `include/uapi/linux/videodev2.h`, line 526
- [`v4l2_pix_format_mplane`](/kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2-mplane.md#c-v4l2_pix_format_mplane): `include/uapi/linux/videodev2.h`, line 2459
- [`v4l2_plane`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_plane): `include/uapi/linux/videodev2.h`, line 1131
- [`v4l2_plane_pix_format`](/kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2-mplane.md#c-v4l2_plane_pix_format): `include/uapi/linux/videodev2.h`, line 2437
- [`v4l2_query_ext_ctrl`](/kernel/hardware/driver-api/media/v4l2-controls.md#c-v4l2_query_ext_ctrl): `include/uapi/linux/videodev2.h`, line 2012
- [`v4l2_queryctrl`](/kernel/hardware/driver-api/media/v4l2-controls.md#c-v4l2_queryctrl): `include/uapi/linux/videodev2.h`, line 1999
- [`v4l2_querymenu`](/kernel/hardware/driver-api/media/v4l2-controls.md#c-v4l2_querymenu): `include/uapi/linux/videodev2.h`, line 2029
- [`v4l2_rds_data`](/kernel/userspace/userspace-api/media-v4l/dev-rds.md#c-v4l2_rds_data): `include/uapi/linux/videodev2.h`, line 2161
- [`v4l2_rect`](/kernel/userspace/userspace-api/media-v4l/dev-overlay.md#c-v4l2_rect): `include/uapi/linux/videodev2.h`, line 442
- [`v4l2_remove_buffers`](/kernel/userspace/userspace-api/media-v4l/vidioc-remove-bufs.md#c-v4l2_remove_buffers): `include/uapi/linux/videodev2.h`, line 2719
- [`v4l2_requestbuffers`](/kernel/userspace/userspace-api/media-v4l/vidioc-reqbufs.md#c-v4l2_requestbuffers): `include/uapi/linux/videodev2.h`, line 1087
- [`v4l2_sdr_format`](/kernel/userspace/userspace-api/media-v4l/dev-sdr.md#c-v4l2_sdr_format): `include/uapi/linux/videodev2.h`, line 2484
- [`v4l2_selection`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-selection.md#c-v4l2_selection): `include/uapi/linux/videodev2.h`, line 1398
- [`v4l2_sliced_vbi_cap`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-sliced-vbi-cap.md#c-v4l2_sliced_vbi_cap): `include/uapi/linux/videodev2.h`, line 2359
- [`v4l2_sliced_vbi_data`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#c-v4l2_sliced_vbi_data): `include/uapi/linux/videodev2.h`, line 2370
- [`v4l2_sliced_vbi_format`](/kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#c-v4l2_sliced_vbi_format): `include/uapi/linux/videodev2.h`, line 2335
- [`v4l2_standard`](/kernel/userspace/userspace-api/media-v4l/vidioc-enumstd.md#c-v4l2_standard): `include/uapi/linux/videodev2.h`, line 1543
- [`v4l2_streamparm`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#c-v4l2_streamparm): `include/uapi/linux/videodev2.h`, line 2537
- [`v4l2_timecode`](/kernel/userspace/userspace-api/media-v4l/buffer.md#c-v4l2_timecode): `include/uapi/linux/videodev2.h`, line 1011
- [`v4l2_tuner`](/kernel/userspace/userspace-api/media-v4l/vidioc-g-tuner.md#c-v4l2_tuner): `include/uapi/linux/videodev2.h`, line 2067
- [`v4l2_vbi_format`](/kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#c-v4l2_vbi_format): `include/uapi/linux/videodev2.h`, line 2307
- [`v4l2_window`](/kernel/userspace/userspace-api/media-v4l/dev-overlay.md#c-v4l2_window): `include/uapi/linux/videodev2.h`, line 1335

---

# ioctl VIDIOC_CREATE_BUFS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_CREATE_BUFS - Create buffers for Memory Mapped or User Pointer or DMA Buffer I/O

<a id="rst-ioctl-vidioc-create-bufs"></a>
<a id="rst-vidioc-create-bufs"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

VIDIOC_CREATE_BUFS - Create buffers for Memory Mapped or User Pointer or DMA Buffer I/O

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

## Synopsis





<a id="c-VIDIOC_CREATE_BUFS"></a>

```c
VIDIOC_CREATE_BUFS
```

`int ioctl(int fd, VIDIOC_CREATE_BUFS, struct v4l2_create_buffers *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_create_buffers`.

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

## Description

This ioctl is used to create buffers for [memory mapped](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) or [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>) or [DMA buffer](</kernel/userspace/userspace-api/media-v4l/dmabuf.md#rst-dmabuf>) I/O. It can be used as an alternative or in addition to the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl, when a tighter control over buffers is required. This ioctl can be called multiple times to create buffers of different sizes.

To allocate the device buffers applications must initialize the relevant fields of the struct `v4l2_create_buffers` structure. The `count` field must be set to the number of requested buffers, the `memory` field specifies the requested I/O method and the `reserved` array must be zeroed.

The `format` field specifies the image format that the buffers must be able to handle. The application has to fill in this struct `v4l2_format`. Usually this will be done using the [VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) or [VIDIOC_G_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctls to ensure that the requested format is supported by the driver. Based on the format's `type` field the requested buffer size (for single-planar) or plane sizes (for multi-planar formats) will be used for the allocated buffers. The driver may return an error if the size(s) are not supported by the hardware (usually because they are too small).

The buffers created by this ioctl will have as minimum size the size defined by the `format.pix.sizeimage` field (or the corresponding fields for other format types). Usually if the `format.pix.sizeimage` field is less than the minimum required for the given format, then an error will be returned since drivers will typically not allow this. If it is larger, then the value will be used as-is. In other words, the driver may reject the requested size, but if it is accepted the driver will use it unchanged.

When the ioctl is called with a pointer to this structure the driver will attempt to allocate up to the requested number of buffers and store the actual number allocated and the starting index in the `count` and the `index` fields respectively. On return `count` can be smaller than the number requested.





<a id="c-v4l2_create_buffers"></a>

```c
v4l2_create_buffers
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_create_buffers</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


The starting buffer index, returned by the driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`count`

</td>
<td>


The number of buffers requested or granted. If count == 0, then [ioctl VIDIOC_CREATE_BUFS](<#rst-vidioc-create-bufs>) will set `index` to the current number of created buffers, and it will check the validity of `memory` and `format.type`. If those are invalid -1 is returned and errno is set to `EINVAL` error code, otherwise [ioctl VIDIOC_CREATE_BUFS](<#rst-vidioc-create-bufs>) returns 0. It will never set errno to `EBUSY` error code in this particular case.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`memory`

</td>
<td>


Applications set this field to `V4L2_MEMORY_MMAP`, `V4L2_MEMORY_DMABUF` or `V4L2_MEMORY_USERPTR`. See `v4l2_memory`

</td>
</tr>
<tr>
<td>


struct `v4l2_format`

</td>
<td>


`format`

</td>
<td>


Filled in by the application, preserved by the driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capabilities`

</td>
<td>


Set by the driver. If 0, then the driver doesn't support capabilities. In that case all you know is that the driver is guaranteed to support `V4L2_MEMORY_MMAP` and *might* support other `v4l2_memory` types. It will not support any other capabilities. See [here](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for a list of the capabilities.

If you want to just query the capabilities without making any other changes, then set `count` to 0, `memory` to `V4L2_MEMORY_MMAP` and `format.type` to the buffer type.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Specifies additional buffer management attributes. See [memory-flags](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`max_num_buffers`

</td>
<td>


If the V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set this field indicates the maximum possible number of buffers for this queue.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[5\]

</td>
<td>


A place holder for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **ENOMEM**

  No memory to allocate buffers for [memory mapped](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) I/O.

- **EINVAL**

  The buffer type (`format.type` field), requested I/O method (`memory`) or format (`format` field) is not valid.

---

# ioctl VIDIOC_CROPCAP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_CROPCAP - Information about the video cropping and scaling abilities

<a id="rst-ioctl-vidioc-cropcap"></a>
<a id="rst-vidioc-cropcap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

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

## Name

VIDIOC_CROPCAP - Information about the video cropping and scaling abilities

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

## Synopsis





<a id="c-VIDIOC_CROPCAP"></a>

```c
VIDIOC_CROPCAP
```

`int ioctl(int fd, VIDIOC_CROPCAP, struct v4l2_cropcap *argp)`

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

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_cropcap`.

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

## Description

Applications use this function to query the cropping limits, the pixel aspect of images and to calculate scale factors. They set the `type` field of a v4l2_cropcap structure to the respective buffer (stream) type and call the [ioctl VIDIOC_CROPCAP](<#rst-vidioc-cropcap>) ioctl with a pointer to this structure. Drivers fill the rest of the structure. The results are constant except when switching the video standard. Remember this switch can occur implicit when switching the video input or output.

This ioctl must be implemented for video capture or output devices that support cropping and/or scaling and/or have non-square pixels, and for overlay devices.





<a id="c-v4l2_cropcap"></a>

```c
v4l2_cropcap
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_cropcap</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the data stream, set by the application. Only these types are valid here: `V4L2_BUF_TYPE_VIDEO_CAPTURE`, `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`, `V4L2_BUF_TYPE_VIDEO_OUTPUT`, `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE` and `V4L2_BUF_TYPE_VIDEO_OVERLAY`. See `v4l2_buf_type` and the note below.

</td>
</tr>
<tr>
<td>


struct [v4l2_rect](<#rst-v4l2-rect-crop>)

</td>
<td>


`bounds`

</td>
<td>


Defines the window within capturing or output is possible, this may exclude for example the horizontal and vertical blanking areas. The cropping rectangle cannot exceed these limits. Width and height are defined in pixels, the driver writer is free to choose origin and units of the coordinate system in the analog domain.

</td>
</tr>
<tr>
<td>


struct [v4l2_rect](<#rst-v4l2-rect-crop>)

</td>
<td>


`defrect`

</td>
<td>


Default cropping rectangle, it shall cover the "whole picture". Assuming pixel aspect 1/1 this could be for example a 640 × 480 rectangle for NTSC, a 768 × 576 rectangle for PAL and SECAM centered over the active picture area. The same coordinate system as for `bounds` is used.

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`pixelaspect`

</td>
<td>


This is the pixel aspect (y / x) when no scaling is applied, the ratio of the actual sampling frequency and the frequency required to get square pixels.

When cropping coordinates refer to square pixels, the driver sets `pixelaspect` to 1/1. Other common values are 54/59 for PAL and SECAM, 11/10 for NTSC sampled according to \[[ITU BT.601](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu601>)\].

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> Unfortunately in the case of multiplanar buffer types (`V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE` and `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`) this API was messed up with regards to how the `v4l2_cropcap` `type` field should be filled in. Some drivers only accepted the `_MPLANE` buffer type while other drivers only accepted a non-multiplanar buffer type (i.e. without the `_MPLANE` at the end).
>
> Starting with kernel 4.13 both variations are allowed.

<a id="rst-v4l2-rect-crop"></a>



<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_rect</caption>
<tbody>
<tr>
<td>


\__s32

</td>
<td>


`left`

</td>
<td>


Horizontal offset of the top, left corner of the rectangle, in pixels.

</td>
</tr>
<tr>
<td>


\__s32

</td>
<td>


`top`

</td>
<td>


Vertical offset of the top, left corner of the rectangle, in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`width`

</td>
<td>


Width of the rectangle, in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`height`

</td>
<td>


Height of the rectangle, in pixels.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_cropcap` `type` is invalid.

- **ENODATA**

  Cropping is not supported for this input or output.

---

# ioctl VIDIOC_DBG_G_CHIP_INFO

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_DBG_G_CHIP_INFO - Identify the chips on a TV card

<a id="rst-ioctl-vidioc-dbg-g-chip-info"></a>
<a id="rst-vidioc-dbg-g-chip-info"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_DBG_G_CHIP_INFO - Identify the chips on a TV card

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_DBG_G_CHIP_INFO"></a>

```c
VIDIOC_DBG_G_CHIP_INFO
```

`int ioctl(int fd, VIDIOC_DBG_G_CHIP_INFO, struct v4l2_dbg_chip_info *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_dbg_chip_info`.

<a id="rst-description"></a>

## Description

> [!NOTE]
>
> This is an [Experimental API Elements](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/hist-v4l2.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) interface and may change in the future.

For driver debugging purposes this ioctl allows test applications to query the driver about the chips present on the TV card. Regular applications must not use it. When you found a chip specific bug, please contact the linux-media mailing list ([https://linuxtv.org/lists.php](<https://linuxtv.org/lists.php>)) so it can be fixed.

Additionally the Linux kernel must be compiled with the `CONFIG_VIDEO_ADV_DEBUG` option to enable this ioctl.

To query the driver applications must initialize the `match.type` and `match.addr` or `match.name` fields of a struct `v4l2_dbg_chip_info` and call [ioctl VIDIOC_DBG_G_CHIP_INFO](<#rst-vidioc-dbg-g-chip-info>) with a pointer to this structure. On success the driver stores information about the selected chip in the `name` and `flags` fields.

When `match.type` is `V4L2_CHIP_MATCH_BRIDGE`, `match.addr` selects the nth bridge 'chip' on the TV card. You can enumerate all chips by starting at zero and incrementing `match.addr` by one until [ioctl VIDIOC_DBG_G_CHIP_INFO](<#rst-vidioc-dbg-g-chip-info>) fails with an `EINVAL` error code. The number zero always selects the bridge chip itself, e. g. the chip connected to the PCI or USB bus. Non-zero numbers identify specific parts of the bridge chip such as an AC97 register block.

When `match.type` is `V4L2_CHIP_MATCH_SUBDEV`, `match.addr` selects the nth sub-device. This allows you to enumerate over all sub-devices.

On success, the `name` field will contain a chip name and the `flags` field will contain `V4L2_CHIP_FL_READABLE` if the driver supports reading registers from the device or `V4L2_CHIP_FL_WRITABLE` if the driver supports writing registers to the device.

We recommended the v4l2-dbg utility over calling this ioctl directly. It is available from the LinuxTV v4l-dvb repository; see [https://linuxtv.org/repo/](<https://linuxtv.org/repo/>) for access instructions.

<!-- tabularcolumns: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{6.6cm}| -->

<a id="rst-name-v4l2-dbg-match"></a>


<table>
<caption>struct v4l2_dbg_match</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


See [name-chip-match-types](<#rst-name-chip-match-types>) for a list of possible types.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


(anonymous)

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`addr`

</td>
<td>


Match a chip by this number, interpreted according to the `type` field.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`name[32]`

</td>
<td>


Match a chip by this name, interpreted according to the `type` field. Currently unused.

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_dbg_chip_info"></a>

```c
v4l2_dbg_chip_info
```


<table>
<caption>struct v4l2_dbg_chip_info</caption>
<tbody>
<tr>
<td>


struct v4l2_dbg_match

</td>
<td>


`match`

</td>
<td>


How to match the chip, see [name-v4l2-dbg-match](<#rst-name-v4l2-dbg-match>).

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`name[32]`

</td>
<td>


The name of the chip.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Set by the driver. If `V4L2_CHIP_FL_READABLE` is set, then the driver supports reading registers from the device. If `V4L2_CHIP_FL_WRITABLE` is set, then it supports writing registers.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[8]`

</td>
<td>


Reserved fields, both application and driver must set these to 0.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-name-chip-match-types"></a>


<table>
<caption>Chip Match Types</caption>
<tbody>
<tr>
<td>


`V4L2_CHIP_MATCH_BRIDGE`

</td>
<td>


0

</td>
<td>


Match the nth chip on the card, zero for the bridge chip. Does not match sub-devices.

</td>
</tr>
<tr>
<td>


`V4L2_CHIP_MATCH_SUBDEV`

</td>
<td>


4

</td>
<td>


Match the nth sub-device.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The `match_type` is invalid or no device could be matched.

---

# ioctl VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_DBG_G_REGISTER - VIDIOC_DBG_S_REGISTER - Read or write hardware registers

> **Peios:** Linux capability names in this interface retain their API meaning, but KACS evaluates them through native token privileges or compatibility rules. UID 0, `setcap` and Unix mode bits do not independently grant native authority. Object access and PIP checks remain additional constraints where applicable. See [Peios kernel behaviour](</kernel/introduction/peios-behaviour.md>) for the mapping and exceptions.


<a id="rst-ioctl-vidioc-dbg-g-register-vidioc-dbg-s-register"></a>
<a id="rst-vidioc-dbg-g-register"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_DBG_G_REGISTER - VIDIOC_DBG_S_REGISTER - Read or write hardware registers

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_DBG_G_REGISTER"></a>

```c
VIDIOC_DBG_G_REGISTER
```

`int ioctl(int fd, VIDIOC_DBG_G_REGISTER, struct v4l2_dbg_register *argp)`





<a id="c-VIDIOC_DBG_S_REGISTER"></a>

```c
VIDIOC_DBG_S_REGISTER
```

`int ioctl(int fd, VIDIOC_DBG_S_REGISTER, const struct v4l2_dbg_register *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_dbg_register`.

<a id="rst-description"></a>

## Description

> [!NOTE]
>
> This is an [Experimental API Elements](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/hist-v4l2.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) interface and may change in the future.

For driver debugging purposes these ioctls allow test applications to access hardware registers directly. Regular applications must not use them.

Since writing or even reading registers can jeopardize the system security, its stability and damage the hardware, both ioctls require superuser privileges. Additionally the Linux kernel must be compiled with the `CONFIG_VIDEO_ADV_DEBUG` option to enable these ioctls.

To write a register applications must initialize all fields of a struct `v4l2_dbg_register` except for `size` and call `VIDIOC_DBG_S_REGISTER` with a pointer to this structure. The `match.type` and `match.addr` or `match.name` fields select a chip on the TV card, the `reg` field specifies a register number and the `val` field the value to be written into the register.

To read a register applications must initialize the `match.type`, `match.addr` or `match.name` and `reg` fields, and call `VIDIOC_DBG_G_REGISTER` with a pointer to this structure. On success the driver stores the register value in the `val` field and the size (in bytes) of the value in `size`.

When `match.type` is `V4L2_CHIP_MATCH_BRIDGE`, `match.addr` selects the nth non-sub-device chip on the TV card. The number zero always selects the host chip, e. g. the chip connected to the PCI or USB bus. You can find out which chips are present with the [ioctl VIDIOC_DBG_G_CHIP_INFO](</kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-chip-info.md#rst-vidioc-dbg-g-chip-info>) ioctl.

When `match.type` is `V4L2_CHIP_MATCH_SUBDEV`, `match.addr` selects the nth sub-device.

These ioctls are optional, not all drivers may support them. However when a driver supports these ioctls it must also support [ioctl VIDIOC_DBG_G_CHIP_INFO](</kernel/userspace/userspace-api/media-v4l/vidioc-dbg-g-chip-info.md#rst-vidioc-dbg-g-chip-info>). Conversely it may support `VIDIOC_DBG_G_CHIP_INFO` but not these ioctls.

`VIDIOC_DBG_G_REGISTER` and `VIDIOC_DBG_S_REGISTER` were introduced in Linux 2.6.21, but their API was changed to the one described here in kernel 2.6.29.

We recommended the v4l2-dbg utility over calling these ioctls directly. It is available from the LinuxTV v4l-dvb repository; see [https://linuxtv.org/repo/](<https://linuxtv.org/repo/>) for access instructions.

<!-- tabularcolumns: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{6.6cm}| -->





<a id="c-v4l2_dbg_match"></a>

```c
v4l2_dbg_match
```


<table>
<caption>struct v4l2_dbg_match</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


See [chip-match-types](<#rst-chip-match-types>) for a list of possible types.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


(anonymous)

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`addr`

</td>
<td>


Match a chip by this number, interpreted according to the `type` field.

</td>
</tr>
<tr>
<td>


char

</td>
<td>


`name[32]`

</td>
<td>


Match a chip by this name, interpreted according to the `type` field. Currently unused.

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>





<a id="c-v4l2_dbg_register"></a>

```c
v4l2_dbg_register
```


<table>
<caption>struct v4l2_dbg_register</caption>
<tbody>
<tr>
<td>


struct v4l2_dbg_match

</td>
<td>


`match`

</td>
<td>


How to match the chip, see `v4l2_dbg_match`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`size`

</td>
<td>


The register size in bytes.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`reg`

</td>
<td>


A register number.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`val`

</td>
<td>


The value read from, or to be written into the register.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-chip-match-types"></a>


<table>
<caption>Chip Match Types</caption>
<tbody>
<tr>
<td>


`V4L2_CHIP_MATCH_BRIDGE`

</td>
<td>


0

</td>
<td>


Match the nth chip on the card, zero for the bridge chip. Does not match sub-devices.

</td>
</tr>
<tr>
<td>


`V4L2_CHIP_MATCH_SUBDEV`

</td>
<td>


4

</td>
<td>


Match the nth sub-device.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EPERM**

  Insufficient permissions. Root privileges are required to execute these ioctls.

---

# ioctl VIDIOC_DECODER_CMD, VIDIOC_TRY_DECODER_CMD

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_DECODER_CMD - VIDIOC_TRY_DECODER_CMD - Execute an decoder command

<a id="rst-ioctl-vidioc-decoder-cmd-vidioc-try-decoder-cmd"></a>
<a id="rst-vidioc-decoder-cmd"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_DECODER_CMD - VIDIOC_TRY_DECODER_CMD - Execute an decoder command

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_DECODER_CMD"></a>

```c
VIDIOC_DECODER_CMD
```

`int ioctl(int fd, VIDIOC_DECODER_CMD, struct v4l2_decoder_cmd *argp)`





<a id="c-VIDIOC_TRY_DECODER_CMD"></a>

```c
VIDIOC_TRY_DECODER_CMD
```

`int ioctl(int fd, VIDIOC_TRY_DECODER_CMD, struct v4l2_decoder_cmd *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  pointer to struct `v4l2_decoder_cmd`.

<a id="rst-description"></a>

## Description

These ioctls control an audio/video (usually MPEG-) decoder. `VIDIOC_DECODER_CMD` sends a command to the decoder, `VIDIOC_TRY_DECODER_CMD` can be used to try a command without actually executing it. To send a command applications must initialize all fields of a struct `v4l2_decoder_cmd` and call `VIDIOC_DECODER_CMD` or `VIDIOC_TRY_DECODER_CMD` with a pointer to this structure.

The `cmd` field must contain the command code. Some commands use the `flags` field for additional information.

A `write()` or [ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) call sends an implicit START command to the decoder if it has not been started yet. Applies to both queues of mem2mem decoders.

A `close()` or [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) call of a streaming file descriptor sends an implicit immediate STOP command to the decoder, and all buffered data is discarded. Applies to both queues of mem2mem decoders.

In principle, these ioctls are optional, not all drivers may support them. They were introduced in Linux 3.3. They are, however, mandatory for stateful mem2mem decoders (as further documented in [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder>)).

<!-- tabularcolumns: |p{2.0cm}|p{1.1cm}|p{2.2cm}|p{11.8cm}| -->





<a id="c-v4l2_decoder_cmd"></a>

```c
v4l2_decoder_cmd
```


<table>
<caption>struct v4l2_decoder_cmd</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`cmd`

</td>
<td>




</td>
<td>


The decoder command, see [decoder-cmds](<#rst-decoder-cmds>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>




</td>
<td>


Flags to go with the command. If no flags are defined for this command, drivers and applications must set this field to zero.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="3">


(anonymous)

</td>
</tr>
<tr>
<td>


struct

</td>
<td>


`start`

</td>
<td>




</td>
<td>


Structure containing additional data for the `V4L2_DEC_CMD_START` command.

</td>
</tr>
<tr>
<td>




</td>
<td>


\__s32

</td>
<td>


`speed`

</td>
<td>


Playback speed and direction. The playback speed is defined as `speed`/1000 of the normal speed. So 1000 is normal playback. Negative numbers denote reverse playback, so -1000 does reverse playback at normal speed. Speeds -1, 0 and 1 have special meanings: speed 0 is shorthand for 1000 (normal playback). A speed of 1 steps just one frame forward, a speed of -1 steps just one frame back.

</td>
</tr>
<tr>
<td>




</td>
<td>


\__u32

</td>
<td>


`format`

</td>
<td>


Format restrictions. This field is set by the driver, not the application. Possible values are `V4L2_DEC_START_FMT_NONE` if there are no format restrictions or `V4L2_DEC_START_FMT_GOP` if the decoder operates on full GOPs (*Group Of Pictures*). This is usually the case for reverse playback: the decoder needs full GOPs, which it can then play in reverse order. So to implement reverse playback the application must feed the decoder the last GOP in the video file, then the GOP before that, etc. etc.

</td>
</tr>
<tr>
<td>


struct

</td>
<td>


`stop`

</td>
<td>




</td>
<td>


Structure containing additional data for the `V4L2_DEC_CMD_STOP` command.

</td>
</tr>
<tr>
<td>




</td>
<td>


\__u64

</td>
<td>


`pts`

</td>
<td>


Stop playback at this `pts` or immediately if the playback is already past that timestamp. Leave to 0 if you want to stop after the last frame was decoded.

</td>
</tr>
<tr>
<td>


struct

</td>
<td colspan="3">


`raw`

</td>
</tr>
<tr>
<td>




</td>
<td>


\__u32

</td>
<td>


`data`\[16\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="3">




</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.6cm}|p{0.6cm}|p{11.1cm}| -->

<a id="rst-decoder-cmds"></a>


<table>
<caption>Decoder Commands</caption>
<tbody>
<tr>
<td>


`V4L2_DEC_CMD_START`

</td>
<td>


0

</td>
<td>


Start the decoder. When the decoder is already running or paused, this command will just change the playback speed. That means that calling `V4L2_DEC_CMD_START` when the decoder was paused will *not* resume the decoder. You have to explicitly call `V4L2_DEC_CMD_RESUME` for that. This command has one flag: `V4L2_DEC_CMD_START_MUTE_AUDIO`. If set, then audio will be muted when playing back at a non-standard speed.

For a device implementing the [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder>), once the drain sequence is initiated with the `V4L2_DEC_CMD_STOP` command, it must be driven to completion before this command can be invoked.  Any attempt to invoke the command while the drain sequence is in progress will trigger an `EBUSY` error code.  The command may be also used to restart the decoder in case of an implicit stop initiated by the decoder itself, without the `V4L2_DEC_CMD_STOP` being called explicitly. See [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder>) for more details.

</td>
</tr>
<tr>
<td>


`V4L2_DEC_CMD_STOP`

</td>
<td>


1

</td>
<td>


Stop the decoder. When the decoder is already stopped, this command does nothing. This command has two flags: if `V4L2_DEC_CMD_STOP_TO_BLACK` is set, then the decoder will set the picture to black after it stopped decoding. Otherwise the last image will repeat. If `V4L2_DEC_CMD_STOP_IMMEDIATELY` is set, then the decoder stops immediately (ignoring the `pts` value), otherwise it will keep decoding until timestamp &gt;= pts or until the last of the pending data from its internal buffers was decoded.

For a device implementing the [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder>), the command will initiate the drain sequence as documented in [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder>).  No flags or other arguments are accepted in this case. Any attempt to invoke the command again before the sequence completes will trigger an `EBUSY` error code.

</td>
</tr>
<tr>
<td>


`V4L2_DEC_CMD_PAUSE`

</td>
<td>


2

</td>
<td>


Pause the decoder. When the decoder has not been started yet, the driver will return an `EPERM` error code. When the decoder is already paused, this command does nothing. This command has one flag: if `V4L2_DEC_CMD_PAUSE_TO_BLACK` is set, then set the decoder output to black when paused.

</td>
</tr>
<tr>
<td>


`V4L2_DEC_CMD_RESUME`

</td>
<td>


3

</td>
<td>


Resume decoding after a PAUSE command. When the decoder has not been started yet, the driver will return an `EPERM` error code. When the decoder is already running, this command does nothing. No flags are defined for this command.

</td>
</tr>
<tr>
<td>


`V4L2_DEC_CMD_FLUSH`

</td>
<td>


4

</td>
<td>


Flush any held capture buffers. Only valid for stateless decoders. This command is typically used when the application reached the end of the stream and the last output buffer had the `V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF` flag set. This would prevent dequeueing the capture buffer containing the last decoded frame. So this command can be used to explicitly flush that final decoded frame. This command does nothing if there are no held capture buffers.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EBUSY**

  A drain sequence of a device implementing the [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder>) is still in progress. It is not allowed to issue another decoder command until it completes.

- **EINVAL**

  The `cmd` field is invalid.

- **EPERM**

  The application sent a PAUSE or RESUME command when the decoder was not running.

---

# ioctl VIDIOC_DQEVENT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_DQEVENT - Dequeue event

<a id="rst-ioctl-vidioc-dqevent"></a>
<a id="rst-vidioc-dqevent"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_DQEVENT - Dequeue event

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_DQEVENT"></a>

```c
VIDIOC_DQEVENT
```

`int ioctl(int fd, VIDIOC_DQEVENT, struct v4l2_event *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_event`.

<a id="rst-description"></a>

## Description

Dequeue an event from a video device. No input is required for this ioctl. All the fields of the struct `v4l2_event` structure are filled by the driver. The file handle will also receive exceptions which the application may get by e.g. using the select system call.





<a id="c-v4l2_event"></a>

```c
v4l2_event
```

<!-- tabularcolumns: |p{3.0cm}|p{3.4cm}|p{10.9cm}| -->


<table>
<caption>struct v4l2_event</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the event, see [event-type](<#rst-event-type>).

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


`u`

</td>
</tr>
<tr>
<td>


struct `v4l2_event_vsync`

</td>
<td>


`vsync`

</td>
<td>


Event data for event `V4L2_EVENT_VSYNC`.

</td>
</tr>
<tr>
<td>


struct `v4l2_event_ctrl`

</td>
<td>


`ctrl`

</td>
<td>


Event data for event `V4L2_EVENT_CTRL`.

</td>
</tr>
<tr>
<td>


struct `v4l2_event_frame_sync`

</td>
<td>


`frame_sync`

</td>
<td>


Event data for event `V4L2_EVENT_FRAME_SYNC`.

</td>
</tr>
<tr>
<td>


struct `v4l2_event_motion_det`

</td>
<td>


`motion_det`

</td>
<td>


Event data for event V4L2_EVENT_MOTION_DET.

</td>
</tr>
<tr>
<td>


struct `v4l2_event_src_change`

</td>
<td>


`src_change`

</td>
<td>


Event data for event V4L2_EVENT_SOURCE_CHANGE.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`data`\[64\]

</td>
<td>


Event data. Defined by the event type. The union should be used to define easily accessible type for events.

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pending`

</td>
<td>


Number of pending events excluding this one.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`sequence`

</td>
<td>


Event sequence number. The sequence number is incremented for every subscribed event that takes place. If sequence numbers are not contiguous it means that events have been lost.

</td>
</tr>
<tr>
<td>


struct timespec

</td>
<td>


`timestamp`

</td>
<td>


Event timestamp. The timestamp has been taken from the `CLOCK_MONOTONIC` clock. To access the same clock outside V4L2, use `clock_gettime()`.

</td>
</tr>
<tr>
<td>


u32

</td>
<td>


`id`

</td>
<td>


The ID associated with the event source. If the event does not have an associated ID (this depends on the event type), then this is 0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[8\]

</td>
<td>


Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.2cm}|p{2.6cm}|p{8.5cm}| -->

<a id="rst-event-type"></a>


<table>
<caption>Event Types</caption>
<tbody>
<tr>
<td>


`V4L2_EVENT_ALL`

</td>
<td>


0

</td>
<td>


All events. V4L2_EVENT_ALL is valid only for VIDIOC_UNSUBSCRIBE_EVENT for unsubscribing all events at once.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_VSYNC`

</td>
<td>


1

</td>
<td>


This event is triggered on the vertical sync. This event has a struct `v4l2_event_vsync` associated with it.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_EOS`

</td>
<td>


2

</td>
<td>


This event is triggered when the end of a stream is reached. This is typically used with MPEG decoders to report to the application when the last of the MPEG stream has been decoded.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_CTRL`

</td>
<td>


3

</td>
<td>


This event requires that the `id` matches the control ID from which you want to receive events. This event is triggered if the control's value changes, if a button control is pressed or if the control's flags change. This event has a struct `v4l2_event_ctrl` associated with it. This struct contains much of the same information as struct [v4l2_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and struct `v4l2_control`.

If the event is generated due to a call to [VIDIOC_S_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) or [VIDIOC_S_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), then the event will *not* be sent to the file handle that called the ioctl function. This prevents nasty feedback loops. If you *do* want to get the event, then set the `V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK` flag.

This event type will ensure that no information is lost when more events are raised than there is room internally. In that case the struct `v4l2_event_ctrl` of the second-oldest event is kept, but the `changes` field of the second-oldest event is ORed with the `changes` field of the oldest event.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_FRAME_SYNC`

</td>
<td>


4

</td>
<td>


Triggered immediately when the reception of a frame has begun. This event has a struct `v4l2_event_frame_sync` associated with it.

If the hardware needs to be stopped in the case of a buffer underrun it might not be able to generate this event. In such cases the `frame_sequence` field in struct `v4l2_event_frame_sync` will not be incremented. This causes two consecutive frame sequence numbers to have n times frame interval in between them.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_SOURCE_CHANGE`

</td>
<td>


5

</td>
<td>


This event is triggered when a source parameter change is detected during runtime by the video device. It can be a runtime resolution change triggered by a video decoder or the format change happening on an input connector. This event requires that the `id` matches the input index (when used with a video device node) or the pad index (when used with a subdevice node) from which you want to receive events.

This event has a struct `v4l2_event_src_change` associated with it. The `changes` bitfield denotes what has changed for the subscribed pad. If multiple events occurred before application could dequeue them, then the changes will have the ORed value of all the events generated.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_MOTION_DET`

</td>
<td>


6

</td>
<td>


Triggered whenever the motion detection state for one or more of the regions changes. This event has a struct `v4l2_event_motion_det` associated with it.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_PRIVATE_START`

</td>
<td>


0x08000000

</td>
<td>


Base event number for driver-private events.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_event_vsync"></a>

```c
v4l2_event_vsync
```


<table>
<caption>struct v4l2_event_vsync</caption>
<tbody>
<tr>
<td>


\__u8

</td>
<td>


`field`

</td>
<td>


The upcoming field. See enum `v4l2_field`.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{3.5cm}|p{3.0cm}|p{10.8cm}| -->





<a id="c-v4l2_event_ctrl"></a>

```c
v4l2_event_ctrl
```


<table>
<caption>struct v4l2_event_ctrl</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`changes`

</td>
<td>


A bitmask that tells what has changed. See [ctrl-changes-flags](<#rst-ctrl-changes-flags>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


The type of the control. See enum `v4l2_ctrl_type`.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


(anonymous)

</td>
</tr>
<tr>
<td>


\__s32

</td>
<td>


`value`

</td>
<td>


The 32-bit value of the control for 32-bit control types. This is 0 for string controls since the value of a string cannot be passed using [ioctl VIDIOC_DQEVENT](<#rst-vidioc-dqevent>).

</td>
</tr>
<tr>
<td>


\__s64

</td>
<td>


`value64`

</td>
<td>


The 64-bit value of the control for 64-bit control types.

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


The control flags. See [control-flags](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


\__s32

</td>
<td>


`minimum`

</td>
<td>


The minimum value of the control. See struct [v4l2_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


\__s32

</td>
<td>


`maximum`

</td>
<td>


The maximum value of the control. See struct [v4l2_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


\__s32

</td>
<td>


`step`

</td>
<td>


The step value of the control. See struct [v4l2_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


\__s32

</td>
<td>


`default_value`

</td>
<td>


The default value of the control. See struct [v4l2_queryctrl](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_event_frame_sync"></a>

```c
v4l2_event_frame_sync
```


<table>
<caption>struct v4l2_event_frame_sync</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`frame_sequence`

</td>
<td>


The sequence number of the frame being received.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_event_src_change"></a>

```c
v4l2_event_src_change
```


<table>
<caption>struct v4l2_event_src_change</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`changes`

</td>
<td>


A bitmask that tells what has changed. See [src-changes-flags](<#rst-src-changes-flags>).

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_event_motion_det"></a>

```c
v4l2_event_motion_det
```


<table>
<caption>struct v4l2_event_motion_det</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Currently only one flag is available: if `V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ` is set, then the `frame_sequence` field is valid, otherwise that field should be ignored.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`frame_sequence`

</td>
<td>


The sequence number of the frame being received. Only valid if the `V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ` flag was set.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`region_mask`

</td>
<td>


The bitmask of the regions that reported motion. There is at least one region. If this field is 0, then no motion was detected at all. If there is no `V4L2_CID_DETECT_MD_REGION_GRID` control (see [Detect Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-detect.md#rst-detect-controls>)) to assign a different region to each cell in the motion detection grid, then that all cells are automatically assigned to the default region 0.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-ctrl-changes-flags"></a>


<table>
<caption>Control Changes</caption>
<tbody>
<tr>
<td>


`V4L2_EVENT_CTRL_CH_VALUE`

</td>
<td>


0x0001

</td>
<td>


This control event was triggered because the value of the control changed. Special cases: Volatile controls do no generate this event; If a control has the `V4L2_CTRL_FLAG_EXECUTE_ON_WRITE` flag set, then this event is sent as well, regardless its value.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_CTRL_CH_FLAGS`

</td>
<td>


0x0002

</td>
<td>


This control event was triggered because the control flags changed.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_CTRL_CH_RANGE`

</td>
<td>


0x0004

</td>
<td>


This control event was triggered because the minimum, maximum, step or the default value of the control changed.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_CTRL_CH_DIMENSIONS`

</td>
<td>


0x0008

</td>
<td>


This control event was triggered because the dimensions of the control changed. Note that the number of dimensions remains the same.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-src-changes-flags"></a>


<table>
<caption>Source Changes</caption>
<tbody>
<tr>
<td>


`V4L2_EVENT_SRC_CH_RESOLUTION`

</td>
<td>


0x0001

</td>
<td>


This event gets triggered when a resolution change is detected at an input. This can come from an input connector or from a video decoder. Applications will have to query the new resolution (if any, the signal may also have been lost).

For stateful decoders follow the guidelines in [Memory-to-Memory Stateful Video Decoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-decoder.md#rst-decoder>). Video Capture devices have to query the new timings using [ioctl VIDIOC_QUERY_DV_TIMINGS](</kernel/userspace/userspace-api/media-v4l/vidioc-query-dv-timings.md#rst-vidioc-query-dv-timings>) or [VIDIOC_QUERYSTD](</kernel/userspace/userspace-api/media-v4l/vidioc-querystd.md#rst-vidioc-querystd>).

*Important*: even if the new video timings appear identical to the old ones, receiving this event indicates that there was an issue with the video signal and you must stop and restart streaming ([VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) followed by [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>)). The reason is that many Video Capture devices are not able to recover from a temporary loss of signal and so restarting streaming I/O is required in order for the hardware to synchronize to the video signal.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_DV_TIMINGS_CAP, VIDIOC_SUBDEV_DV_TIMINGS_CAP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_DV_TIMINGS_CAP - VIDIOC_SUBDEV_DV_TIMINGS_CAP - The capabilities of the Digital Video receiver/transmitter

<a id="rst-ioctl-vidioc-dv-timings-cap-vidioc-subdev-dv-timings-cap"></a>
<a id="rst-vidioc-dv-timings-cap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_DV_TIMINGS_CAP - VIDIOC_SUBDEV_DV_TIMINGS_CAP - The capabilities of the Digital Video receiver/transmitter

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_DV_TIMINGS_CAP"></a>

```c
VIDIOC_DV_TIMINGS_CAP
```

`int ioctl(int fd, VIDIOC_DV_TIMINGS_CAP, struct v4l2_dv_timings_cap *argp)`





<a id="c-VIDIOC_SUBDEV_DV_TIMINGS_CAP"></a>

```c
VIDIOC_SUBDEV_DV_TIMINGS_CAP
```

`int ioctl(int fd, VIDIOC_SUBDEV_DV_TIMINGS_CAP, struct v4l2_dv_timings_cap *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_dv_timings_cap`.

<a id="rst-description"></a>

## Description

To query the capabilities of the DV receiver/transmitter applications initialize the `pad` field to 0, zero the reserved array of struct `v4l2_dv_timings_cap` and call the `VIDIOC_DV_TIMINGS_CAP` ioctl on a video node and the driver will fill in the structure.

> [!NOTE]
>
> Drivers may return different values after switching the video input or output.

When implemented by the driver DV capabilities of subdevices can be queried by calling the `VIDIOC_SUBDEV_DV_TIMINGS_CAP` ioctl directly on a subdevice node. The capabilities are specific to inputs (for DV receivers) or outputs (for DV transmitters), applications must specify the desired pad number in the struct `v4l2_dv_timings_cap` `pad` field and zero the `reserved` array. Attempts to query capabilities on a pad that doesn't support them will return an `EINVAL` error code.

<!-- tabularcolumns: |p{1.2cm}|p{3.2cm}|p{12.9cm}| -->





<a id="c-v4l2_bt_timings_cap"></a>

```c
v4l2_bt_timings_cap
```


<table>
<caption>struct v4l2_bt_timings_cap</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`min_width`

</td>
<td>


Minimum width of the active video in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`max_width`

</td>
<td>


Maximum width of the active video in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`min_height`

</td>
<td>


Minimum height of the active video in lines.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`max_height`

</td>
<td>


Maximum height of the active video in lines.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`min_pixelclock`

</td>
<td>


Minimum pixelclock frequency in Hz.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`max_pixelclock`

</td>
<td>


Maximum pixelclock frequency in Hz.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`standards`

</td>
<td>


The video standard(s) supported by the hardware. See [dv-bt-standards](</kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-bt-standards>) for a list of standards.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capabilities`

</td>
<td>


Several flags giving more information about the capabilities. See [dv-bt-cap-capabilities](<#rst-dv-bt-cap-capabilities>) for a description of the flags.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[16\]

</td>
<td>


Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{3.6cm}|p{9.3cm}| -->





<a id="c-v4l2_dv_timings_cap"></a>

```c
v4l2_dv_timings_cap
```


<table>
<caption>struct v4l2_dv_timings_cap</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of DV timings as listed in [dv-timing-types](</kernel/userspace/userspace-api/media-v4l/vidioc-g-dv-timings.md#rst-dv-timing-types>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad number as reported by the media controller API. This field is only used when operating on a subdevice node. When operating on a video node applications must set this field to zero.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[2\]

</td>
<td>


Reserved for future extensions.

Drivers and applications must set the array to zero.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


(anonymous)

</td>
</tr>
<tr>
<td>


struct `v4l2_bt_timings_cap`

</td>
<td>


`bt`

</td>
<td>


BT.656/1120 timings capabilities of the hardware.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td colspan="2">


`raw_data`\[32\]

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.2cm}|p{10.3cm}| -->

<a id="rst-dv-bt-cap-capabilities"></a>


<table>
<caption>DV BT Timing capabilities</caption>
<tbody>
<tr>
<td>


Flag

</td>
<td>


Description

</td>
</tr>
<tr>
<td>




</td>
<td>




</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_CAP_INTERLACED`

</td>
<td>


Interlaced formats are supported.

</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_CAP_PROGRESSIVE`

</td>
<td>


Progressive formats are supported.

</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_CAP_REDUCED_BLANKING`

</td>
<td>


CVT/GTF specific: the timings can make use of reduced blanking (CVT) or the 'Secondary GTF' curve (GTF).

</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_CAP_CUSTOM`

</td>
<td>


Can support non-standard timings, i.e. timings not belonging to the standards set in the `standards` field.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_ENCODER_CMD, VIDIOC_TRY_ENCODER_CMD

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command

<a id="rst-ioctl-vidioc-encoder-cmd-vidioc-try-encoder-cmd"></a>
<a id="rst-vidioc-encoder-cmd"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENCODER_CMD - VIDIOC_TRY_ENCODER_CMD - Execute an encoder command

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENCODER_CMD"></a>

```c
VIDIOC_ENCODER_CMD
```

`int ioctl(int fd, VIDIOC_ENCODER_CMD, struct v4l2_encoder_cmd *argp)`





<a id="c-VIDIOC_TRY_ENCODER_CMD"></a>

```c
VIDIOC_TRY_ENCODER_CMD
```

`int ioctl(int fd, VIDIOC_TRY_ENCODER_CMD, struct v4l2_encoder_cmd *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_encoder_cmd`.

<a id="rst-description"></a>

## Description

These ioctls control an audio/video (usually MPEG-) encoder. `VIDIOC_ENCODER_CMD` sends a command to the encoder, `VIDIOC_TRY_ENCODER_CMD` can be used to try a command without actually executing it.

To send a command applications must initialize all fields of a struct `v4l2_encoder_cmd` and call `VIDIOC_ENCODER_CMD` or `VIDIOC_TRY_ENCODER_CMD` with a pointer to this structure.

The `cmd` field must contain the command code. Some commands use the `flags` field for additional information.

After a STOP command, `read()` calls will read the remaining data buffered by the driver. When the buffer is empty, `read()` will return zero and the next `read()` call will restart the encoder.

A `read()` or [VIDIOC_STREAMON](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) call sends an implicit START command to the encoder if it has not been started yet. Applies to both queues of mem2mem encoders.

A `close()` or [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) call of a streaming file descriptor sends an implicit immediate STOP to the encoder, and all buffered data is discarded. Applies to both queues of mem2mem encoders.

These ioctls are optional, not all drivers may support them. They were introduced in Linux 2.6.21. They are, however, mandatory for stateful mem2mem encoders (as further documented in [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>)).

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_encoder_cmd"></a>

```c
v4l2_encoder_cmd
```


<table>
<caption>struct v4l2_encoder_cmd</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`cmd`

</td>
<td>


The encoder command, see [encoder-cmds](<#rst-encoder-cmds>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags to go with the command, see [encoder-flags](<#rst-encoder-flags>). If no flags are defined for this command, drivers and applications must set this field to zero.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`data`\[8\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-encoder-cmds"></a>


<table>
<caption>Encoder Commands</caption>
<tbody>
<tr>
<td>


`V4L2_ENC_CMD_START`

</td>
<td>


0

</td>
<td>


Start the encoder. When the encoder is already running or paused, this command does nothing. No flags are defined for this command.

For a device implementing the [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>), once the drain sequence is initiated with the `V4L2_ENC_CMD_STOP` command, it must be driven to completion before this command can be invoked.  Any attempt to invoke the command while the drain sequence is in progress will trigger an `EBUSY` error code. See [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>) for more details.

</td>
</tr>
<tr>
<td>


`V4L2_ENC_CMD_STOP`

</td>
<td>


1

</td>
<td>


Stop the encoder. When the `V4L2_ENC_CMD_STOP_AT_GOP_END` flag is set, encoding will continue until the end of the current *Group Of Pictures*, otherwise encoding will stop immediately. When the encoder is already stopped, this command does nothing.

For a device implementing the [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>), the command will initiate the drain sequence as documented in [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>). No flags or other arguments are accepted in this case. Any attempt to invoke the command again before the sequence completes will trigger an `EBUSY` error code.

</td>
</tr>
<tr>
<td>


`V4L2_ENC_CMD_PAUSE`

</td>
<td>


2

</td>
<td>


Pause the encoder. When the encoder has not been started yet, the driver will return an `EPERM` error code. When the encoder is already paused, this command does nothing. No flags are defined for this command.

</td>
</tr>
<tr>
<td>


`V4L2_ENC_CMD_RESUME`

</td>
<td>


3

</td>
<td>


Resume encoding after a PAUSE command. When the encoder has not been started yet, the driver will return an `EPERM` error code. When the encoder is already running, this command does nothing. No flags are defined for this command.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-encoder-flags"></a>


<table>
<caption>Encoder Command Flags</caption>
<tbody>
<tr>
<td>


`V4L2_ENC_CMD_STOP_AT_GOP_END`

</td>
<td>


0x0001

</td>
<td>


Stop encoding at the end of the current *Group Of Pictures*, rather than immediately.

Does not apply to [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>).

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EBUSY**

  A drain sequence of a device implementing the [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>) is still in progress. It is not allowed to issue another encoder command until it completes.

- **EINVAL**

  The `cmd` field is invalid.

- **EPERM**

  The application sent a PAUSE or RESUME command when the encoder was not running.

---

# ioctl VIDIOC_ENUM_DV_TIMINGS, VIDIOC_SUBDEV_ENUM_DV_TIMINGS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUM_DV_TIMINGS - VIDIOC_SUBDEV_ENUM_DV_TIMINGS - Enumerate supported Digital Video timings

<a id="rst-ioctl-vidioc-enum-dv-timings-vidioc-subdev-enum-dv-timings"></a>
<a id="rst-vidioc-enum-dv-timings"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUM_DV_TIMINGS - VIDIOC_SUBDEV_ENUM_DV_TIMINGS - Enumerate supported Digital Video timings

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUM_DV_TIMINGS"></a>

```c
VIDIOC_ENUM_DV_TIMINGS
```

`int ioctl(int fd, VIDIOC_ENUM_DV_TIMINGS, struct v4l2_enum_dv_timings *argp)`





<a id="c-VIDIOC_SUBDEV_ENUM_DV_TIMINGS"></a>

```c
VIDIOC_SUBDEV_ENUM_DV_TIMINGS
```

`int ioctl(int fd, VIDIOC_SUBDEV_ENUM_DV_TIMINGS, struct v4l2_enum_dv_timings *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_enum_dv_timings`.

<a id="rst-description"></a>

## Description

While some DV receivers or transmitters support a wide range of timings, others support only a limited number of timings. With this ioctl applications can enumerate a list of known supported timings. Call [ioctl VIDIOC_DV_TIMINGS_CAP, VIDIOC_SUBDEV_DV_TIMINGS_CAP](</kernel/userspace/userspace-api/media-v4l/vidioc-dv-timings-cap.md#rst-vidioc-dv-timings-cap>) to check if it also supports other standards or even custom timings that are not in this list.

To query the available timings, applications initialize the `index` field, set the `pad` field to 0, zero the reserved array of struct `v4l2_enum_dv_timings` and call the `VIDIOC_ENUM_DV_TIMINGS` ioctl on a video node with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the index is out of bounds. To enumerate all supported DV timings, applications shall begin at index zero, incrementing by one until the driver returns `EINVAL`.

> [!NOTE]
>
> Drivers may enumerate a different set of DV timings after switching the video input or output.

When implemented by the driver DV timings of subdevices can be queried by calling the `VIDIOC_SUBDEV_ENUM_DV_TIMINGS` ioctl directly on a subdevice node. The DV timings are specific to inputs (for DV receivers) or outputs (for DV transmitters), applications must specify the desired pad number in the struct `v4l2_enum_dv_timings` `pad` field. Attempts to enumerate timings on a pad that doesn't support them will return an `EINVAL` error code.





<a id="c-v4l2_enum_dv_timings"></a>

```c
v4l2_enum_dv_timings
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_enum_dv_timings</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Number of the DV timings, set by the application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad number as reported by the media controller API. This field is only used when operating on a subdevice node. When operating on a video node applications must set this field to zero.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[2\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
<tr>
<td>


struct `v4l2_dv_timings`

</td>
<td>


`timings`

</td>
<td>


The timings.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_enum_dv_timings` `index` is out of bounds or the `pad` number is invalid.

- **ENODATA**

  Digital video presets are not supported for this input or output.

---

# ioctl VIDIOC_ENUM_FMT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUM_FMT - Enumerate image formats

<a id="rst-ioctl-vidioc-enum-fmt"></a>
<a id="rst-vidioc-enum-fmt"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUM_FMT - Enumerate image formats

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUM_FMT"></a>

```c
VIDIOC_ENUM_FMT
```

`int ioctl(int fd, VIDIOC_ENUM_FMT, struct v4l2_fmtdesc *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_fmtdesc`.

<a id="rst-description"></a>

## Description

To enumerate image formats applications initialize the `type`, `mbus_code` and `index` fields of struct `v4l2_fmtdesc` and call the [ioctl VIDIOC_ENUM_FMT](<#rst-vidioc-enum-fmt>) ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code. All formats are enumerable by beginning at index zero and incrementing by one until `EINVAL` is returned. If applicable, drivers shall return formats in preference order, where preferred formats are returned before (that is, with lower `index` value) less-preferred formats.

Depending on the `V4L2_CAP_IO_MC` [capability](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities>), the `mbus_code` field is handled differently:

1. `V4L2_CAP_IO_MC` is not set (also known as a 'video-node-centric' driver)

   Applications shall initialize the `mbus_code` field to zero and drivers shall ignore the value of the field.

   Drivers shall enumerate all image formats.

   > [!NOTE]
   >
   > After switching the input or output the list of enumerated image formats may be different.

2. `V4L2_CAP_IO_MC` is set (also known as an 'MC-centric' driver)

   If the `mbus_code` field is zero, then all image formats shall be enumerated.

   If the `mbus_code` field is initialized to a valid (non-zero) [media bus format code](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/subdev-formats.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), then drivers shall restrict enumeration to only the image formats that can produce (for video output devices) or be produced from (for video capture devices) that media bus code. If the `mbus_code` is unsupported by the driver, then `EINVAL` shall be returned.

   Regardless of the value of the `mbus_code` field, the enumerated image formats shall not depend on the active configuration of the video device or device pipeline.





<a id="c-v4l2_fmtdesc"></a>

```c
v4l2_fmtdesc
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_fmtdesc</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Number of the format in the enumeration, set by the application. This is in no way related to the `pixelformat` field. When the index is ORed with `V4L2_FMTDESC_FLAG_ENUM_ALL` the driver clears the flag and enumerates all the possible formats, ignoring any limitations from the current configuration. Drivers which do not support this flag always return an `EINVAL` error code without clearing this flag. Formats enumerated when using `V4L2_FMTDESC_FLAG_ENUM_ALL` flag shouldn't be used when calling `VIDIOC_ENUM_FRAMESIZES()` or `VIDIOC_ENUM_FRAMEINTERVALS()`. `V4L2_FMTDESC_FLAG_ENUM_ALL` should only be used by drivers that can return different format list depending on this flag.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the data stream, set by the application. Only these types are valid here: `V4L2_BUF_TYPE_VIDEO_CAPTURE`, `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`, `V4L2_BUF_TYPE_VIDEO_OUTPUT`, `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`, `V4L2_BUF_TYPE_VIDEO_OVERLAY`, `V4L2_BUF_TYPE_SDR_CAPTURE`, `V4L2_BUF_TYPE_SDR_OUTPUT`, `V4L2_BUF_TYPE_META_CAPTURE` and `V4L2_BUF_TYPE_META_OUTPUT`. See `v4l2_buf_type`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


See [fmtdesc-flags](<#rst-fmtdesc-flags>)

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`description`\[32\]

</td>
<td>


Description of the format, a NUL-terminated ASCII string. This information is intended for the user, for example: "YUV 4:2:2".

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pixelformat`

</td>
<td>


The image format identifier. This is a four character code as computed by the v4l2_fourcc() macro:

</td>
</tr>
<tr>
<td colspan="3">


<a id="rst-v4l2-fourcc"></a>

`#define v4l2_fourcc(a,b,c,d)`

`(((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))`

Several image formats are already defined by this specification in [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>).

> [!NOTE]
>
> These codes are not the same as those used in the Windows world.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`mbus_code`

</td>
<td>


Media bus code restricting the enumerated formats, set by the application. Only applicable to drivers that advertise the `V4L2_CAP_IO_MC` [capability](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-device-capabilities>), shall be 0 otherwise.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[3\]

</td>
<td>


Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{8.4cm}|p{1.8cm}|p{7.1cm}| -->

<a id="rst-fmtdesc-flags"></a>


<table>
<caption>Image Format Description Flags</caption>
<tbody>
<tr>
<td>


`V4L2_FMT_FLAG_COMPRESSED`

</td>
<td>


0x0001

</td>
<td>


This is a compressed format.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_EMULATED`

</td>
<td>


0x0002

</td>
<td>


This format is not native to the device but emulated through software (usually libv4l2), where possible try to use a native format instead for better performance.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_CONTINUOUS_BYTESTREAM`

</td>
<td>


0x0004

</td>
<td>


The hardware decoder for this compressed bytestream format (aka coded format) is capable of parsing a continuous bytestream. Applications do not need to parse the bytestream themselves to find the boundaries between frames/fields.

This flag can only be used in combination with the `V4L2_FMT_FLAG_COMPRESSED` flag, since this applies to compressed formats only. This flag is valid for stateful decoders only.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_DYN_RESOLUTION`

</td>
<td>


0x0008

</td>
<td>


Dynamic resolution switching is supported by the device for this compressed bytestream format (aka coded format). It will notify the user via the event `V4L2_EVENT_SOURCE_CHANGE` when changes in the video parameters are detected.

This flag can only be used in combination with the `V4L2_FMT_FLAG_COMPRESSED` flag, since this applies to compressed formats only. This flag is valid for stateful codecs only.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_ENC_CAP_FRAME_INTERVAL`

</td>
<td>


0x0010

</td>
<td>


The hardware encoder supports setting the `CAPTURE` coded frame interval separately from the `OUTPUT` raw frame interval. Setting the `OUTPUT` raw frame interval with [VIDIOC_S_PARM](</kernel/userspace/userspace-api/media-v4l/vidioc-g-parm.md#rst-vidioc-g-parm>) also sets the `CAPTURE` coded frame interval to the same value. If this flag is set, then the `CAPTURE` coded frame interval can be set to a different value afterwards. This is typically used for offline encoding where the `OUTPUT` raw frame interval is used as a hint for reserving hardware encoder resources and the `CAPTURE` coded frame interval is the actual frame rate embedded in the encoded video stream.

This flag can only be used in combination with the `V4L2_FMT_FLAG_COMPRESSED` flag, since this applies to compressed formats only. This flag is valid for stateful encoders only.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_CSC_COLORSPACE`

</td>
<td>


0x0020

</td>
<td>


The driver allows the application to try to change the default colorspace. This flag is relevant only for capture devices. The application can ask to configure the colorspace of the capture device when calling the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with [V4L2_PIX_FMT_FLAG_SET_CSC](</kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#rst-v4l2-pix-fmt-flag-set-csc>) set.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_CSC_XFER_FUNC`

</td>
<td>


0x0040

</td>
<td>


The driver allows the application to try to change the default transfer function. This flag is relevant only for capture devices. The application can ask to configure the transfer function of the capture device when calling the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with [V4L2_PIX_FMT_FLAG_SET_CSC](</kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#rst-v4l2-pix-fmt-flag-set-csc>) set.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_CSC_YCBCR_ENC`

</td>
<td>


0x0080

</td>
<td>


The driver allows the application to try to change the default Y'CbCr encoding. This flag is relevant only for capture devices. The application can ask to configure the Y'CbCr encoding of the capture device when calling the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with [V4L2_PIX_FMT_FLAG_SET_CSC](</kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#rst-v4l2-pix-fmt-flag-set-csc>) set.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_CSC_HSV_ENC`

</td>
<td>


0x0080

</td>
<td>


The driver allows the application to try to change the default HSV encoding. This flag is relevant only for capture devices. The application can ask to configure the HSV encoding of the capture device when calling the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with [V4L2_PIX_FMT_FLAG_SET_CSC](</kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#rst-v4l2-pix-fmt-flag-set-csc>) set.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_CSC_QUANTIZATION`

</td>
<td>


0x0100

</td>
<td>


The driver allows the application to try to change the default quantization. This flag is relevant only for capture devices. The application can ask to configure the quantization of the capture device when calling the [VIDIOC_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl with [V4L2_PIX_FMT_FLAG_SET_CSC](</kernel/userspace/userspace-api/media-v4l/pixfmt-v4l2.md#rst-v4l2-pix-fmt-flag-set-csc>) set.

</td>
</tr>
<tr>
<td>


`V4L2_FMT_FLAG_META_LINE_BASED`

</td>
<td>


0x0200

</td>
<td>


The metadata format is line-based. In this case the `width`, `height` and `bytesperline` fields of `v4l2_meta_format` are valid. The buffer consists of `height` lines, each having `width` Data Units of data and the offset (in bytes) between the beginning of each two consecutive lines is `bytesperline`.

</td>
</tr>
<tr>
<td>


`V4L2_FMTDESC_FLAG_ENUM_ALL`

</td>
<td>


0x80000000

</td>
<td>


When the applications ORs `index` with `V4L2_FMTDESC_FLAG_ENUM_ALL` flag the driver enumerates all the possible pixel formats without taking care of any already set configuration. Drivers which do not support this flag, always return `EINVAL` without clearing this flag.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_fmtdesc` `type` is not supported or the `index` is out of bounds.

  If `V4L2_CAP_IO_MC` is set and the specified `mbus_code` is unsupported, then also return this error code.

---

# ioctl VIDIOC_ENUM_FRAMEINTERVALS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUM_FRAMEINTERVALS - Enumerate frame intervals

<a id="rst-ioctl-vidioc-enum-frameintervals"></a>
<a id="rst-vidioc-enum-frameintervals"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUM_FRAMEINTERVALS - Enumerate frame intervals

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUM_FRAMEINTERVALS"></a>

```c
VIDIOC_ENUM_FRAMEINTERVALS
```

`int ioctl(int fd, VIDIOC_ENUM_FRAMEINTERVALS, struct v4l2_frmivalenum *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_frmivalenum` that contains a pixel format and size and receives a frame interval.

<a id="rst-description"></a>

## Description

This ioctl allows applications to enumerate all frame intervals that the device supports for the given pixel format and frame size.

The supported pixel formats and frame sizes can be obtained by using the [ioctl VIDIOC_ENUM_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) and [ioctl VIDIOC_ENUM_FRAMESIZES](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-framesizes.md#rst-vidioc-enum-framesizes>) functions.

The return value and the content of the `v4l2_frmivalenum.type` field depend on the type of frame intervals the device supports. Here are the semantics of the function for the different cases:

- **Discrete:** The function returns success if the given index value (zero-based) is valid. The application should increase the index by one for each call until `EINVAL` is returned. The `v4l2_frmivalenum.type` field is set to `V4L2_FRMIVAL_TYPE_DISCRETE` by the driver. Of the union only the `discrete` member is valid.

- **Step-wise:** The function returns success if the given index value is zero and `EINVAL` for any other index value. The `v4l2_frmivalenum.type` field is set to `V4L2_FRMIVAL_TYPE_STEPWISE` by the driver. Of the union only the `stepwise` member is valid.

- **Continuous:** This is a special case of the step-wise type above. The function returns success if the given index value is zero and `EINVAL` for any other index value. The `v4l2_frmivalenum.type` field is set to `V4L2_FRMIVAL_TYPE_CONTINUOUS` by the driver. Of the union only the `stepwise` member is valid and the `step` value is set to 1.

When the application calls the function with index zero, it must check the `type` field to determine the type of frame interval enumeration the device supports. Only for the `V4L2_FRMIVAL_TYPE_DISCRETE` type does it make sense to increase the index value to receive more frame intervals.

> [!NOTE]
>
> The order in which the frame intervals are returned has no special meaning. In particular does it not say anything about potential default frame intervals.

Applications can assume that the enumeration data does not change without any interaction from the application itself. This means that the enumeration data is consistent if the application does not perform any other ioctl calls while it runs the frame interval enumeration.

> [!NOTE]
>
> **Frame intervals and frame rates:** The V4L2 API uses frame intervals instead of frame rates. Given the frame interval the frame rate can be computed as follows:
>
>
>
> ```text
> frame_rate = 1 / frame_interval
> ```

<a id="rst-structs"></a>

## Structs

In the structs below, *IN* denotes a value that has to be filled in by the application, *OUT* denotes values that the driver fills in. The application should zero out all members except for the *IN* fields.





<a id="c-v4l2_frmival_stepwise"></a>

```c
v4l2_frmival_stepwise
```


<table>
<caption>struct v4l2_frmival_stepwise</caption>
<tbody>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`min`

</td>
<td>


Minimum frame interval \[s\].

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`max`

</td>
<td>


Maximum frame interval \[s\].

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`step`

</td>
<td>


Frame interval step size \[s\].

</td>
</tr>
</tbody>
</table>





<a id="c-v4l2_frmivalenum"></a>

```c
v4l2_frmivalenum
```

<!-- tabularcolumns: |p{4.9cm}|p{3.3cm}|p{9.1cm}| -->


<table>
<caption>struct v4l2_frmivalenum</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


IN: Index of the given frame interval in the enumeration.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pixel_format`

</td>
<td>


IN: Pixel format for which the frame intervals are enumerated.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`width`

</td>
<td>


IN: Frame width for which the frame intervals are enumerated.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`height`

</td>
<td>


IN: Frame height for which the frame intervals are enumerated.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


OUT: Frame interval type the device supports.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td>


(anonymous)

</td>
<td>


OUT: Frame interval with the given index.

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`discrete`

</td>
<td>


Frame interval \[s\].

</td>
</tr>
<tr>
<td>


struct `v4l2_frmival_stepwise`

</td>
<td>


`stepwise`

</td>
<td>




</td>
</tr>
<tr>
<td>


\}

</td>
<td>




</td>
<td>




</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[2]`

</td>
<td>


Reserved space for future use. Must be zeroed by drivers and applications.

</td>
</tr>
</tbody>
</table>

<a id="rst-enums"></a>

## Enums





<a id="c-v4l2_frmivaltypes"></a>

```c
v4l2_frmivaltypes
```

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->


<table>
<caption>enum v4l2_frmivaltypes</caption>
<tbody>
<tr>
<td>


`V4L2_FRMIVAL_TYPE_DISCRETE`

</td>
<td>


1

</td>
<td>


Discrete frame interval.

</td>
</tr>
<tr>
<td>


`V4L2_FRMIVAL_TYPE_CONTINUOUS`

</td>
<td>


2

</td>
<td>


Continuous frame interval.

</td>
</tr>
<tr>
<td>


`V4L2_FRMIVAL_TYPE_STEPWISE`

</td>
<td>


3

</td>
<td>


Step-wise defined frame interval.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_ENUM_FRAMESIZES

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUM_FRAMESIZES - Enumerate frame sizes

<a id="rst-ioctl-vidioc-enum-framesizes"></a>
<a id="rst-vidioc-enum-framesizes"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUM_FRAMESIZES - Enumerate frame sizes

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUM_FRAMESIZES"></a>

```c
VIDIOC_ENUM_FRAMESIZES
```

`int ioctl(int fd, VIDIOC_ENUM_FRAMESIZES, struct v4l2_frmsizeenum *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_frmsizeenum` that contains an index and pixel format and receives a frame width and height.

<a id="rst-description"></a>

## Description

This ioctl allows applications to enumerate all frame sizes (i. e. width and height in pixels) that the device supports for the given pixel format.

The supported pixel formats can be obtained by using the [ioctl VIDIOC_ENUM_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-fmt.md#rst-vidioc-enum-fmt>) function.

The return value and the content of the `v4l2_frmsizeenum.type` field depend on the type of frame sizes the device supports. Here are the semantics of the function for the different cases:

- **Discrete:** The function returns success if the given index value (zero-based) is valid. The application should increase the index by one for each call until `EINVAL` is returned. The `v4l2_frmsizeenum.type` field is set to `V4L2_FRMSIZE_TYPE_DISCRETE` by the driver. Of the union only the `discrete` member is valid.

- **Step-wise:** The function returns success if the given index value is zero and `EINVAL` for any other index value. The `v4l2_frmsizeenum.type` field is set to `V4L2_FRMSIZE_TYPE_STEPWISE` by the driver. Of the union only the `stepwise` member is valid.

- **Continuous:** This is a special case of the step-wise type above. The function returns success if the given index value is zero and `EINVAL` for any other index value. The `v4l2_frmsizeenum.type` field is set to `V4L2_FRMSIZE_TYPE_CONTINUOUS` by the driver. Of the union only the `stepwise` member is valid and the `step_width` and `step_height` values are set to 1.

When the application calls the function with index zero, it must check the `type` field to determine the type of frame size enumeration the device supports. Only for the `V4L2_FRMSIZE_TYPE_DISCRETE` type does it make sense to increase the index value to receive more frame sizes.

> [!NOTE]
>
> The order in which the frame sizes are returned has no special meaning. In particular does it not say anything about potential default format sizes.

Applications can assume that the enumeration data does not change without any interaction from the application itself. This means that the enumeration data is consistent if the application does not perform any other ioctl calls while it runs the frame size enumeration.

<a id="rst-structs"></a>

## Structs

In the structs below, *IN* denotes a value that has to be filled in by the application, *OUT* denotes values that the driver fills in. The application should zero out all members except for the *IN* fields.





<a id="c-v4l2_frmsize_discrete"></a>

```c
v4l2_frmsize_discrete
```


<table>
<caption>struct v4l2_frmsize_discrete</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`width`

</td>
<td>


Width of the frame \[pixel\].

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`height`

</td>
<td>


Height of the frame \[pixel\].

</td>
</tr>
</tbody>
</table>





<a id="c-v4l2_frmsize_stepwise"></a>

```c
v4l2_frmsize_stepwise
```


<table>
<caption>struct v4l2_frmsize_stepwise</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`min_width`

</td>
<td>


Minimum frame width \[pixel\].

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`max_width`

</td>
<td>


Maximum frame width \[pixel\].

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`step_width`

</td>
<td>


Frame width step size \[pixel\].

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`min_height`

</td>
<td>


Minimum frame height \[pixel\].

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`max_height`

</td>
<td>


Maximum frame height \[pixel\].

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`step_height`

</td>
<td>


Frame height step size \[pixel\].

</td>
</tr>
</tbody>
</table>





<a id="c-v4l2_frmsizeenum"></a>

```c
v4l2_frmsizeenum
```

<!-- tabularcolumns: |p{6.4cm}|p{2.8cm}|p{8.1cm}| -->


<table>
<caption>struct v4l2_frmsizeenum</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


IN: Index of the given frame size in the enumeration.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pixel_format`

</td>
<td>


IN: Pixel format for which the frame sizes are enumerated.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


OUT: Frame size type the device supports.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td>


(anonymous)

</td>
<td>


OUT: Frame size with the given index.

</td>
</tr>
<tr>
<td>


struct `v4l2_frmsize_discrete`

</td>
<td>


`discrete`

</td>
<td>




</td>
</tr>
<tr>
<td>


struct `v4l2_frmsize_stepwise`

</td>
<td>


`stepwise`

</td>
<td>




</td>
</tr>
<tr>
<td>


\}

</td>
<td>




</td>
<td>




</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[2]`

</td>
<td>


Reserved space for future use. Must be zeroed by drivers and applications.

</td>
</tr>
</tbody>
</table>

<a id="rst-enums"></a>

## Enums





<a id="c-v4l2_frmsizetypes"></a>

```c
v4l2_frmsizetypes
```

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->


<table>
<caption>enum v4l2_frmsizetypes</caption>
<tbody>
<tr>
<td>


`V4L2_FRMSIZE_TYPE_DISCRETE`

</td>
<td>


1

</td>
<td>


Discrete frame size.

</td>
</tr>
<tr>
<td>


`V4L2_FRMSIZE_TYPE_CONTINUOUS`

</td>
<td>


2

</td>
<td>


Continuous frame size.

</td>
</tr>
<tr>
<td>


`V4L2_FRMSIZE_TYPE_STEPWISE`

</td>
<td>


3

</td>
<td>


Step-wise defined frame size.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_ENUM_FREQ_BANDS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUM_FREQ_BANDS - Enumerate supported frequency bands

<a id="rst-ioctl-vidioc-enum-freq-bands"></a>
<a id="rst-vidioc-enum-freq-bands"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUM_FREQ_BANDS - Enumerate supported frequency bands

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUM_FREQ_BANDS"></a>

```c
VIDIOC_ENUM_FREQ_BANDS
```

`int ioctl(int fd, VIDIOC_ENUM_FREQ_BANDS, struct v4l2_frequency_band *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_frequency_band`.

<a id="rst-description"></a>

## Description

Enumerates the frequency bands that a tuner or modulator supports. To do this applications initialize the `tuner`, `type` and `index` fields, and zero out the `reserved` array of a struct `v4l2_frequency_band` and call the [ioctl VIDIOC_ENUM_FREQ_BANDS](<#rst-vidioc-enum-freq-bands>) ioctl with a pointer to this structure.

This ioctl is supported if the `V4L2_TUNER_CAP_FREQ_BANDS` capability of the corresponding tuner/modulator is set.

<!-- tabularcolumns: |p{2.9cm}|p{2.9cm}|p{5.8cm}|p{2.9cm}|p{2.4cm}| -->





<a id="c-v4l2_frequency_band"></a>

```c
v4l2_frequency_band
```


<table>
<caption>struct v4l2_frequency_band</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`tuner`

</td>
<td colspan="3">


The tuner or modulator index number. This is the same value as in the struct `v4l2_input` `tuner` field and the struct `v4l2_tuner` `index` field, or the struct `v4l2_output` `modulator` field and the struct `v4l2_modulator` `index` field.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td colspan="3">


The tuner type. This is the same value as in the struct `v4l2_tuner` `type` field. The type must be set to `V4L2_TUNER_RADIO` for `/dev/radioX` device nodes, and to `V4L2_TUNER_ANALOG_TV` for all others. Set this field to `V4L2_TUNER_RADIO` for modulators (currently only radio modulators are supported). See `v4l2_tuner_type`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td colspan="3">


Identifies the frequency band, set by the application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capability`

</td>
<td colspan="3">


 The tuner/modulator capability flags for this frequency band, see [tuner-capability](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-tuner.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>). The `V4L2_TUNER_CAP_LOW` or `V4L2_TUNER_CAP_1HZ` capability must be the same for all frequency bands of the selected tuner/modulator. So either all bands have that capability set, or none of them have that capability.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`rangelow`

</td>
<td colspan="3">


 The lowest tunable frequency in units of 62.5 kHz, or if the `capability` flag `V4L2_TUNER_CAP_LOW` is set, in units of 62.5 Hz, for this frequency band. A 1 Hz unit is used when the `capability` flag `V4L2_TUNER_CAP_1HZ` is set.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`rangehigh`

</td>
<td colspan="3">


 The highest tunable frequency in units of 62.5 kHz, or if the `capability` flag `V4L2_TUNER_CAP_LOW` is set, in units of 62.5 Hz, for this frequency band. A 1 Hz unit is used when the `capability` flag `V4L2_TUNER_CAP_1HZ` is set.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`modulation`

</td>
<td colspan="3">


 The supported modulation systems of this frequency band. See [band-modulation](<#rst-band-modulation>).

> [!NOTE]
>
> Currently only one modulation system per frequency band is supported. More work will need to be done if multiple modulation systems are possible. Contact the linux-media mailing list ([https://linuxtv.org/lists.php](<https://linuxtv.org/lists.php>)) if you need such functionality.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[9\]

</td>
<td colspan="3">


Reserved for future extensions.

Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-band-modulation"></a>


<table>
<caption>Band Modulation Systems</caption>
<tbody>
<tr>
<td>


`V4L2_BAND_MODULATION_VSB`

</td>
<td>


0x02

</td>
<td>


Vestigial Sideband modulation, used for analog TV.

</td>
</tr>
<tr>
<td>


`V4L2_BAND_MODULATION_FM`

</td>
<td>


0x04

</td>
<td>


Frequency Modulation, commonly used for analog radio.

</td>
</tr>
<tr>
<td>


`V4L2_BAND_MODULATION_AM`

</td>
<td>


0x08

</td>
<td>


Amplitude Modulation, commonly used for analog radio.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The `tuner` or `index` is out of bounds or the `type` field is wrong.

---

# ioctl VIDIOC_ENUMAUDIO

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUMAUDIO - Enumerate audio inputs

<a id="rst-ioctl-vidioc-enumaudio"></a>
<a id="rst-vidioc-enumaudio"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUMAUDIO - Enumerate audio inputs

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUMAUDIO"></a>

```c
VIDIOC_ENUMAUDIO
```

`int ioctl(int fd, VIDIOC_ENUMAUDIO, struct v4l2_audio *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_audio`.

<a id="rst-description"></a>

## Description

To query the attributes of an audio input applications initialize the `index` field and zero out the `reserved` array of a struct `v4l2_audio` and call the [ioctl VIDIOC_ENUMAUDIO](<#rst-vidioc-enumaudio>) ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the index is out of bounds. To enumerate all audio inputs applications shall begin at index zero, incrementing by one until the driver returns `EINVAL`.

See [VIDIOC_G_AUDIO](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audio.md#rst-vidioc-g-audio>) for a description of struct `v4l2_audio`.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The number of the audio input is out of bounds.

---

# ioctl VIDIOC_ENUMAUDOUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUMAUDOUT - Enumerate audio outputs

<a id="rst-ioctl-vidioc-enumaudout"></a>
<a id="rst-vidioc-enumaudout"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUMAUDOUT - Enumerate audio outputs

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUMAUDOUT"></a>

```c
VIDIOC_ENUMAUDOUT
```

`int ioctl(int fd, VIDIOC_ENUMAUDOUT, struct v4l2_audioout *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_audioout`.

<a id="rst-description"></a>

## Description

To query the attributes of an audio output applications initialize the `index` field and zero out the `reserved` array of a struct `v4l2_audioout` and call the `VIDIOC_G_AUDOUT` ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the index is out of bounds. To enumerate all audio outputs applications shall begin at index zero, incrementing by one until the driver returns `EINVAL`.

> [!NOTE]
>
> Connectors on a TV card to loop back the received audio signal to a sound card are not audio outputs in this sense.

See [VIDIOC_G_AUDIOout](</kernel/userspace/userspace-api/media-v4l/vidioc-g-audioout.md#rst-vidioc-g-audout>) for a description of struct `v4l2_audioout`.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The number of the audio output is out of bounds.

---

# ioctl VIDIOC_ENUMINPUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUMINPUT - Enumerate video inputs

<a id="rst-ioctl-vidioc-enuminput"></a>
<a id="rst-vidioc-enuminput"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUMINPUT - Enumerate video inputs

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUMINPUT"></a>

```c
VIDIOC_ENUMINPUT
```

`int ioctl(int fd, VIDIOC_ENUMINPUT, struct v4l2_input *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_input`.

<a id="rst-description"></a>

## Description

To query the attributes of a video input applications initialize the `index` field of struct `v4l2_input` and call the [ioctl VIDIOC_ENUMINPUT](<#rst-vidioc-enuminput>) with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the index is out of bounds. To enumerate all inputs applications shall begin at index zero, incrementing by one until the driver returns `EINVAL`.

<!-- tabularcolumns: |p{3.0cm}|p{3.5cm}|p{10.8cm}| -->





<a id="c-v4l2_input"></a>

```c
v4l2_input
```


<table>
<caption>struct v4l2_input</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Identifies the input, set by the application.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`name`\[32\]

</td>
<td>


Name of the video input, a NUL-terminated ASCII string, for example: "Vin (Composite 2)". This information is intended for the user, preferably the connector label on the device itself.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the input, see [input-type](<#rst-input-type>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`audioset`

</td>
<td>


Drivers can enumerate up to 32 video and audio inputs. This field shows which audio inputs were selectable as audio source if this was the currently selected video input. It is a bit mask. The LSB corresponds to audio input 0, the MSB to input 31. Any number of bits can be set, or none.

When the driver does not enumerate audio inputs no bits must be set. Applications shall not interpret this as lack of audio support. Some drivers automatically select audio sources and do not enumerate them since there is no choice anyway.

For details on audio inputs and how to select the current input see [Audio Inputs and Outputs](</kernel/userspace/userspace-api/media-v4l/audio.md#rst-audio>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`tuner`

</td>
<td>


Capture devices can have zero or more tuners (RF demodulators). When the `type` is set to `V4L2_INPUT_TYPE_TUNER` this is an RF connector and this field identifies the tuner. It corresponds to struct `v4l2_tuner` field `index`. For details on tuners see [Tuners and Modulators](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>).

</td>
</tr>
<tr>
<td>


[v4l2_std_id](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

</td>
<td>


`std`

</td>
<td>


Every video input supports one or more different video standards. This field is a set of all supported standards. For details on video standards and how to switch see [Video Standards](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`status`

</td>
<td>


This field provides status information about the input. See [input-status](<#rst-input-status>) for flags. With the exception of the sensor orientation bits `status` is only valid when this is the current input.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capabilities`

</td>
<td>


This field provides capabilities for the input. See [input-capabilities](<#rst-input-capabilities>) for flags.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[3\]

</td>
<td>


Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{1.0cm}|p{9.7cm}| -->

<a id="rst-input-type"></a>


<table>
<caption>Input Types</caption>
<tbody>
<tr>
<td>


`V4L2_INPUT_TYPE_TUNER`

</td>
<td>


1

</td>
<td>


This input uses a tuner (RF demodulator).

</td>
</tr>
<tr>
<td>


`V4L2_INPUT_TYPE_CAMERA`

</td>
<td>


2

</td>
<td>


Any non-tuner video input, for example Composite Video, S-Video, HDMI, camera sensor. The naming as `_TYPE_CAMERA` is historical, today we would have called it `_TYPE_VIDEO`.

</td>
</tr>
<tr>
<td>


`V4L2_INPUT_TYPE_TOUCH`

</td>
<td>


3

</td>
<td>


This input is a touch device for capturing raw touch data.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{5.6cm}|p{2.6cm}|p{9.1cm}| -->

<a id="rst-input-status"></a>


<table>
<caption>Input Status Flags</caption>
<tbody>
<tr>
<td colspan="3">


 General

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_POWER`

</td>
<td>


0x00000001

</td>
<td>


Attached device is off.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_SIGNAL`

</td>
<td>


0x00000002

</td>
<td>




</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_COLOR`

</td>
<td>


0x00000004

</td>
<td>


The hardware supports color decoding, but does not detect color modulation in the signal.

</td>
</tr>
<tr>
<td colspan="3">


 Sensor Orientation

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_HFLIP`

</td>
<td>


0x00000010

</td>
<td>


The input is connected to a device that produces a signal that is flipped horizontally and does not correct this before passing the signal to userspace.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_VFLIP`

</td>
<td>


0x00000020

</td>
<td>


The input is connected to a device that produces a signal that is flipped vertically and does not correct this before passing the signal to userspace. .. note:: A 180 degree rotation is the same as HFLIP \| VFLIP

</td>
</tr>
<tr>
<td colspan="3">


 Analog Video

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_H_LOCK`

</td>
<td>


0x00000100

</td>
<td>


No horizontal sync lock.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_COLOR_KILL`

</td>
<td>


0x00000200

</td>
<td>


A color killer circuit automatically disables color decoding when it detects no color modulation. When this flag is set the color killer is enabled *and* has shut off color decoding.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_V_LOCK`

</td>
<td>


0x00000400

</td>
<td>


No vertical sync lock.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_STD_LOCK`

</td>
<td>


0x00000800

</td>
<td>


No standard format lock in case of auto-detection format by the component.

</td>
</tr>
<tr>
<td colspan="3">


 Digital Video

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_SYNC`

</td>
<td>


0x00010000

</td>
<td>


No synchronization lock.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_EQU`

</td>
<td>


0x00020000

</td>
<td>


No equalizer lock.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_CARRIER`

</td>
<td>


0x00040000

</td>
<td>


Carrier recovery failed.

</td>
</tr>
<tr>
<td colspan="3">


 VCR and Set-Top Box

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_MACROVISION`

</td>
<td>


0x01000000

</td>
<td>


Macrovision is an analog copy prevention system mangling the video signal to confuse video recorders. When this flag is set Macrovision has been detected.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_NO_ACCESS`

</td>
<td>


0x02000000

</td>
<td>


Conditional access denied.

</td>
</tr>
<tr>
<td>


`V4L2_IN_ST_VTR`

</td>
<td>


0x04000000

</td>
<td>


VTR time constant. \[?\]

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.4cm}|p{8.3cm}| -->

<a id="rst-input-capabilities"></a>


<table>
<caption>Input capabilities</caption>
<tbody>
<tr>
<td>


`V4L2_IN_CAP_DV_TIMINGS`

</td>
<td>


0x00000002

</td>
<td>


This input supports setting video timings by using `VIDIOC_S_DV_TIMINGS`.

</td>
</tr>
<tr>
<td>


`V4L2_IN_CAP_STD`

</td>
<td>


0x00000004

</td>
<td>


This input supports setting the TV standard by using `VIDIOC_S_STD`.

</td>
</tr>
<tr>
<td>


`V4L2_IN_CAP_NATIVE_SIZE`

</td>
<td>


0x00000008

</td>
<td>


This input supports setting the native size using the `V4L2_SEL_TGT_NATIVE_SIZE` selection target, see [Common selection definitions](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>).

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_input` `index` is out of bounds.

---

# ioctl VIDIOC_ENUMOUTPUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUMOUTPUT - Enumerate video outputs

<a id="rst-ioctl-vidioc-enumoutput"></a>
<a id="rst-vidioc-enumoutput"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_ENUMOUTPUT - Enumerate video outputs

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_ENUMOUTPUT"></a>

```c
VIDIOC_ENUMOUTPUT
```

`int ioctl(int fd, VIDIOC_ENUMOUTPUT, struct v4l2_output *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_output`.

<a id="rst-description"></a>

## Description

To query the attributes of a video outputs applications initialize the `index` field of struct `v4l2_output` and call the [ioctl VIDIOC_ENUMOUTPUT](<#rst-vidioc-enumoutput>) with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the index is out of bounds. To enumerate all outputs applications shall begin at index zero, incrementing by one until the driver returns `EINVAL`.

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_output"></a>

```c
v4l2_output
```


<table>
<caption>struct v4l2_output</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Identifies the output, set by the application.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`name`\[32\]

</td>
<td>


Name of the video output, a NUL-terminated ASCII string, for example: "Vout". This information is intended for the user, preferably the connector label on the device itself.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the output, see [output-type](<#rst-output-type>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`audioset`

</td>
<td>


Drivers can enumerate up to 32 video and audio outputs. This field shows which audio outputs were selectable as the current output if this was the currently selected video output. It is a bit mask. The LSB corresponds to audio output 0, the MSB to output 31. Any number of bits can be set, or none.

When the driver does not enumerate audio outputs no bits must be set. Applications shall not interpret this as lack of audio support. Drivers may automatically select audio outputs without enumerating them.

For details on audio outputs and how to select the current output see [Audio Inputs and Outputs](</kernel/userspace/userspace-api/media-v4l/audio.md#rst-audio>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`modulator`

</td>
<td>


Output devices can have zero or more RF modulators. When the `type` is `V4L2_OUTPUT_TYPE_MODULATOR` this is an RF connector and this field identifies the modulator. It corresponds to struct `v4l2_modulator` field `index`. For details on modulators see [Tuners and Modulators](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>).

</td>
</tr>
<tr>
<td>


[v4l2_std_id](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

</td>
<td>


`std`

</td>
<td>


Every video output supports one or more different video standards. This field is a set of all supported standards. For details on video standards and how to switch see [Video Standards](</kernel/userspace/userspace-api/media-v4l/standard.md#rst-standard>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capabilities`

</td>
<td>


This field provides capabilities for the output. See [output-capabilities](<#rst-output-capabilities>) for flags.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[3\]

</td>
<td>


Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.5cm}|p{0.6cm}|p{9.2cm}| -->

<a id="rst-output-type"></a>


<table>
<caption>Output Type</caption>
<tbody>
<tr>
<td>


`V4L2_OUTPUT_TYPE_MODULATOR`

</td>
<td>


1

</td>
<td>


This output is an analog TV modulator.

</td>
</tr>
<tr>
<td>


`V4L2_OUTPUT_TYPE_ANALOG`

</td>
<td>


2

</td>
<td>


Any non-modulator video output, for example Composite Video, S-Video, HDMI. The naming as `_TYPE_ANALOG` is historical, today we would have called it `_TYPE_VIDEO`.

</td>
</tr>
<tr>
<td>


`V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY`

</td>
<td>


3

</td>
<td>


The video output will be copied to a [video overlay](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.4cm}|p{2.4cm}|p{8.5cm}| -->

<a id="rst-output-capabilities"></a>


<table>
<caption>Output capabilities</caption>
<tbody>
<tr>
<td>


`V4L2_OUT_CAP_DV_TIMINGS`

</td>
<td>


0x00000002

</td>
<td>


This output supports setting video timings by using `VIDIOC_S_DV_TIMINGS`.

</td>
</tr>
<tr>
<td>


`V4L2_OUT_CAP_STD`

</td>
<td>


0x00000004

</td>
<td>


This output supports setting the TV standard by using `VIDIOC_S_STD`.

</td>
</tr>
<tr>
<td>


`V4L2_OUT_CAP_NATIVE_SIZE`

</td>
<td>


0x00000008

</td>
<td>


This output supports setting the native size using the `V4L2_SEL_TGT_NATIVE_SIZE` selection target, see [Common selection definitions](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>).

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_output` `index` is out of bounds.

---

# ioctl VIDIOC_ENUMSTD, VIDIOC_SUBDEV_ENUMSTD

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_ENUMSTD - VIDIOC_SUBDEV_ENUMSTD - Enumerate supported video standards

<a id="rst-ioctl-vidioc-enumstd-vidioc-subdev-enumstd"></a>
<a id="rst-vidioc-enumstd"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC\_ENUMSTD - VIDIOC\_SUBDEV\_ENUMSTD - Enumerate supported video standards

<a id="rst-synopsis"></a>

## Synopsis

<a id="c-VIDIOC_ENUMSTD"></a>



```c
VIDIOC_ENUMSTD
```

`int ioctl(int fd, VIDIOC_ENUMSTD, struct v4l2_standard *argp)`

<a id="c-VIDIOC_SUBDEV_ENUMSTD"></a>



```c
VIDIOC_SUBDEV_ENUMSTD
```

`int ioctl(int fd, VIDIOC_SUBDEV_ENUMSTD, struct v4l2_standard *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_standard`.

<a id="rst-description"></a>

## Description

To query the attributes of a video standard, especially a custom (driver defined) one, applications initialize the `index` field of struct `v4l2_standard` and call the [ioctl VIDIOC\_ENUMSTD, VIDIOC\_SUBDEV\_ENUMSTD](<#rst-vidioc-enumstd>) ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the index is out of bounds. To enumerate all standards applications shall begin at index zero, incrementing by one until the driver returns `EINVAL`. Drivers may enumerate a different set of standards after switching the video input or output. <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

<a id="c-v4l2_standard"></a>



```c
v4l2_standard
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>

struct v4l2\_standard

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`index`

</td>
<td>



Number of the video standard, set by the application.

</td>
</tr>
<tr>
<td>



[v4l2\_std\_id](<#rst-v4l2-std-id>)

</td>
<td>



`id`

</td>
<td>



The bits in this field identify the standard as one of the common standards listed in [v4l2-std-id](<#rst-v4l2-std-id>), or if bits 32 to 63 are set as custom standards. Multiple bits can be set if the hardware does not distinguish between these standards, however separate indices do not indicate the opposite. The `id` must be unique. No other enumerated struct `v4l2_standard` structure, for this input or output anyway, can contain the same set of bits.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`name`\[24\]

</td>
<td>



Name of the standard, a NUL-terminated ASCII string, for example: "PAL-B/G", "NTSC Japan". This information is intended for the user.

</td>
</tr>
<tr>
<td>



struct `v4l2_fract`

</td>
<td>



`frameperiod`

</td>
<td>



The frame period (not field period) is numerator / denominator. For example M/NTSC has a frame period of 1001 / 30000 seconds.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`framelines`

</td>
<td>



Total lines per frame including blanking, e. g. 625 for B/PAL.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`\[4\]

</td>
<td>



Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_fract"></a>



```c
v4l2_fract
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>

struct v4l2\_fract

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`numerator`

</td>
<td>





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`denominator`

</td>
<td>





</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->

<a id="rst-v4l2-std-id"></a>


<table>
<caption>

typedef v4l2\_std\_id

</caption>
<tbody>
<tr>
<td>



\_\_u64

</td>
<td>



`v4l2_std_id`

</td>
<td>



This type is a set, each bit representing another video standard as listed below and in [video-standards](<#rst-video-standards>). The 32 most significant bits are reserved for custom (driver defined) video standards.

</td>
</tr>
</tbody>
</table>



```c
#define V4L2_STD_PAL_B          ((v4l2_std_id)0x00000001)
#define V4L2_STD_PAL_B1         ((v4l2_std_id)0x00000002)
#define V4L2_STD_PAL_G          ((v4l2_std_id)0x00000004)
#define V4L2_STD_PAL_H          ((v4l2_std_id)0x00000008)
#define V4L2_STD_PAL_I          ((v4l2_std_id)0x00000010)
#define V4L2_STD_PAL_D          ((v4l2_std_id)0x00000020)
#define V4L2_STD_PAL_D1         ((v4l2_std_id)0x00000040)
#define V4L2_STD_PAL_K          ((v4l2_std_id)0x00000080)

#define V4L2_STD_PAL_M          ((v4l2_std_id)0x00000100)
#define V4L2_STD_PAL_N          ((v4l2_std_id)0x00000200)
#define V4L2_STD_PAL_Nc         ((v4l2_std_id)0x00000400)
#define V4L2_STD_PAL_60         ((v4l2_std_id)0x00000800)
```

`V4L2_STD_PAL_60` is a hybrid standard with 525 lines, 60 Hz refresh rate, and PAL color modulation with a 4.43 MHz color subcarrier. Some PAL video recorders can play back NTSC tapes in this mode for display on a 50/60 Hz agnostic PAL TV.



```c
#define V4L2_STD_NTSC_M         ((v4l2_std_id)0x00001000)
#define V4L2_STD_NTSC_M_JP      ((v4l2_std_id)0x00002000)
#define V4L2_STD_NTSC_443       ((v4l2_std_id)0x00004000)
```

`V4L2_STD_NTSC_443` is a hybrid standard with 525 lines, 60 Hz refresh rate, and NTSC color modulation with a 4.43 MHz color subcarrier.



```c
#define V4L2_STD_NTSC_M_KR      ((v4l2_std_id)0x00008000)

#define V4L2_STD_SECAM_B        ((v4l2_std_id)0x00010000)
#define V4L2_STD_SECAM_D        ((v4l2_std_id)0x00020000)
#define V4L2_STD_SECAM_G        ((v4l2_std_id)0x00040000)
#define V4L2_STD_SECAM_H        ((v4l2_std_id)0x00080000)
#define V4L2_STD_SECAM_K        ((v4l2_std_id)0x00100000)
#define V4L2_STD_SECAM_K1       ((v4l2_std_id)0x00200000)
#define V4L2_STD_SECAM_L        ((v4l2_std_id)0x00400000)
#define V4L2_STD_SECAM_LC       ((v4l2_std_id)0x00800000)

/* ATSC/HDTV */
#define V4L2_STD_ATSC_8_VSB     ((v4l2_std_id)0x01000000)
#define V4L2_STD_ATSC_16_VSB    ((v4l2_std_id)0x02000000)
```

`V4L2_STD_ATSC_8_VSB` and `V4L2_STD_ATSC_16_VSB` are U.S. terrestrial digital TV standards. Presently the V4L2 API does not support digital TV. See also the Linux DVB API at [https://linuxtv.org](<https://linuxtv.org>).



```c
#define V4L2_STD_PAL_BG         (V4L2_STD_PAL_B         |
                 V4L2_STD_PAL_B1        |
                 V4L2_STD_PAL_G)
#define V4L2_STD_B              (V4L2_STD_PAL_B         |
                 V4L2_STD_PAL_B1        |
                 V4L2_STD_SECAM_B)
#define V4L2_STD_GH             (V4L2_STD_PAL_G         |
                 V4L2_STD_PAL_H         |
                 V4L2_STD_SECAM_G       |
                 V4L2_STD_SECAM_H)
#define V4L2_STD_PAL_DK         (V4L2_STD_PAL_D         |
                 V4L2_STD_PAL_D1        |
                 V4L2_STD_PAL_K)
#define V4L2_STD_PAL            (V4L2_STD_PAL_BG        |
                 V4L2_STD_PAL_DK        |
                 V4L2_STD_PAL_H         |
                 V4L2_STD_PAL_I)
#define V4L2_STD_NTSC           (V4L2_STD_NTSC_M        |
                 V4L2_STD_NTSC_M_JP     |
                 V4L2_STD_NTSC_M_KR)
#define V4L2_STD_MN             (V4L2_STD_PAL_M         |
                 V4L2_STD_PAL_N         |
                 V4L2_STD_PAL_Nc        |
                 V4L2_STD_NTSC)
#define V4L2_STD_SECAM_DK       (V4L2_STD_SECAM_D       |
                 V4L2_STD_SECAM_K       |
                 V4L2_STD_SECAM_K1)
#define V4L2_STD_DK             (V4L2_STD_PAL_DK        |
                 V4L2_STD_SECAM_DK)

#define V4L2_STD_SECAM          (V4L2_STD_SECAM_B       |
                 V4L2_STD_SECAM_G       |
                 V4L2_STD_SECAM_H       |
                 V4L2_STD_SECAM_DK      |
                 V4L2_STD_SECAM_L       |
                 V4L2_STD_SECAM_LC)

#define V4L2_STD_525_60         (V4L2_STD_PAL_M         |
                 V4L2_STD_PAL_60        |
                 V4L2_STD_NTSC          |
                 V4L2_STD_NTSC_443)
#define V4L2_STD_625_50         (V4L2_STD_PAL           |
                 V4L2_STD_PAL_N         |
                 V4L2_STD_PAL_Nc        |
                 V4L2_STD_SECAM)

#define V4L2_STD_UNKNOWN        0
#define V4L2_STD_ALL            (V4L2_STD_525_60        |
                 V4L2_STD_625_50)
```

<!-- Source LaTeX layout: \begingroup
\tiny
\setlength{\tabcolsep}{2pt} -->

<!-- NTSC/M   PAL/M    /N       /B       /D       /H       /I        SECAM/B    /D       /K1     /L -->

<!-- tabularcolumns: |p{1.43cm}|p{1.38cm}|p{1.59cm}|p{1.7cm}|p{1.7cm}|p{1.17cm}|p{0.64cm}|p{1.71cm}|p{1.6cm}|p{1.07cm}|p{1.07cm}|p{1.07cm}| -->

<a id="rst-video-standards"></a>


<table>
<caption>

Video Standards (based on [itu470](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu470>))

</caption>
<thead>
<tr>
<th>



Characteristics

</th>
<th>



M/NTSC <a id="rst-footnote-reference-2"></a>[2](#rst-f2)

</th>
<th>



M/PAL

</th>
<th>



N/PAL <a id="rst-footnote-reference-3"></a>[3](#rst-f3)

</th>
<th>



B, B1, G/PAL

</th>
<th>



D, D1, K/PAL

</th>
<th>



H/PAL

</th>
<th>



I/PAL

</th>
<th>



B, G/SECAM

</th>
<th>



D, K/SECAM

</th>
<th>



K1/SECAM

</th>
<th>



L/SECAM

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



Frame lines

</td>
<td colspan="2">



 525

</td>
<td colspan="9">



 625

</td>
</tr>
<tr>
<td>



Frame period (s)

</td>
<td colspan="2">



 1001/30000

</td>
<td colspan="9">



 1/25

</td>
</tr>
<tr>
<td>



Chrominance sub-carrier frequency (Hz)

</td>
<td>



3579545 ± 10

</td>
<td>



3579611.49 ± 10

</td>
<td>



4433618.75 ± 5

(3582056.25 ± 5)

</td>
<td colspan="4">



 4433618.75 ± 5

</td>
<td>



4433618.75 ± 1

</td>
<td colspan="3">



 f<sub>OR</sub> = 4406250 ± 2000,

f<sub>OB</sub> = 4250000 ± 2000

</td>
</tr>
<tr>
<td>



Nominal radio-frequency channel bandwidth (MHz)

</td>
<td>



6

</td>
<td>



6

</td>
<td>



6

</td>
<td>



B: 7; B1, G: 8

</td>
<td>



8

</td>
<td>



8

</td>
<td>



8

</td>
<td>



8

</td>
<td>



8

</td>
<td>



8

</td>
<td>



8

</td>
</tr>
<tr>
<td>



Sound carrier relative to vision carrier (MHz)

</td>
<td>



4.5

</td>
<td>



4.5

</td>
<td>



4.5

</td>
<td>



5.5 ± 0.001  <a id="rst-footnote-reference-4"></a>[4](#rst-f4)  <a id="rst-footnote-reference-5"></a>[5](#rst-f5)  <a id="rst-footnote-reference-6"></a>[6](#rst-f6)  <a id="rst-footnote-reference-7"></a>[7](#rst-f7)

</td>
<td>



6.5 ± 0.001

</td>
<td>



5.5

</td>
<td>



5.9996 ± 0.0005

</td>
<td>



5.5 ± 0.001

</td>
<td>



6.5 ± 0.001

</td>
<td>



6.5

</td>
<td>



6.5 <a id="rst-footnote-reference-8"></a>[8](#rst-f8)

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \endgroup -->

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_standard` `index` is out of bounds.

- **ENODATA**

  Standard video timings are not supported for this input or output.

<a id="rst-f1"></a>



**[1]** The supported standards may overlap and we need an unambiguous set to find the current standard returned by [VIDIOC\_G\_STD](</kernel/userspace/userspace-api/media-v4l/vidioc-g-std.md#rst-vidioc-g-std>).

<a id="rst-f2"></a>



**[2]** Japan uses a standard similar to M/NTSC (V4L2\_STD\_NTSC\_M\_JP).

<a id="rst-f3"></a>



**[3]** The values in brackets apply to the combination N/PAL a.k.a. N<sub>C</sub> used in Argentina (V4L2\_STD\_PAL\_Nc).

<a id="rst-f4"></a>



**[4]** In the Federal Republic of Germany, Austria, Italy, the Netherlands, Slovakia and Switzerland a system of two sound carriers is used, the frequency of the second carrier being 242.1875 kHz above the frequency of the first sound carrier. For stereophonic sound transmissions a similar system is used in Australia.

<a id="rst-f5"></a>



**[5]** New Zealand uses a sound carrier displaced 5.4996 ± 0.0005 MHz from the vision carrier.

<a id="rst-f6"></a>



**[6]** In Denmark, Finland, New Zealand, Sweden and Spain a system of two sound carriers is used. In Iceland, Norway and Poland the same system is being introduced. The second carrier is 5.85 MHz above the vision carrier and is DQPSK modulated with 728 kbit/s sound and data multiplex. (NICAM system)

<a id="rst-f7"></a>



**[7]** In the United Kingdom, a system of two sound carriers is used. The second sound carrier is 6.552 MHz above the vision carrier and is DQPSK modulated with a 728 kbit/s sound and data multiplex able to carry two sound channels. (NICAM system)

<a id="rst-f8"></a>



**[8]** In France, a digital carrier 5.85 MHz away from the vision carrier may be used in addition to the main sound carrier. It is modulated in differentially encoded QPSK with a 728 kbit/s sound and data multiplexer capable of carrying two sound channels. (NICAM system)

---

# ioctl VIDIOC_EXPBUF

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_EXPBUF - Export a buffer as a DMABUF file descriptor.

<a id="rst-ioctl-vidioc-expbuf"></a>
<a id="rst-vidioc-expbuf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_EXPBUF - Export a buffer as a DMABUF file descriptor.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_EXPBUF"></a>

```c
VIDIOC_EXPBUF
```

`int ioctl(int fd, VIDIOC_EXPBUF, struct v4l2_exportbuffer *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_exportbuffer`.

<a id="rst-description"></a>

## Description

This ioctl is an extension to the [memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) I/O method, therefore it is available only for `V4L2_MEMORY_MMAP` buffers. It can be used to export a buffer as a DMABUF file at any time after buffers have been allocated with the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl.

To export a buffer, applications fill struct `v4l2_exportbuffer`. The `type` field is set to the same buffer type as was previously used with struct `v4l2_requestbuffers` `type`. Applications must also set the `index` field. Valid index numbers range from zero to the number of buffers allocated with [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) (struct `v4l2_requestbuffers` `count`) minus one. For the multi-planar API, applications set the `plane` field to the index of the plane to be exported. Valid planes range from zero to the maximal number of valid planes for the currently active format. For the single-planar API, applications must set `plane` to zero. Additional flags may be posted in the `flags` field. Refer to a manual for open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, and O_RDWR are supported. All other fields must be set to zero. In the case of multi-planar API, every plane is exported separately using multiple [ioctl VIDIOC_EXPBUF](<#rst-vidioc-expbuf>) calls.

After calling [ioctl VIDIOC_EXPBUF](<#rst-vidioc-expbuf>) the `fd` field will be set by a driver. This is a DMABUF file descriptor. The application may pass it to other DMABUF-aware devices. Refer to [DMABUF importing](</kernel/userspace/userspace-api/media-v4l/dmabuf.md#rst-dmabuf>) for details about importing DMABUF files into V4L2 nodes. It is recommended to close a DMABUF file when it is no longer used to allow the associated memory to be reclaimed.

<a id="rst-examples"></a>

## Examples



```c
int buffer_export(int v4lfd, enum v4l2_buf_type bt, int index, int *dmafd)
{
    struct v4l2_exportbuffer expbuf;

    memset(&expbuf, 0, sizeof(expbuf));
    expbuf.type = bt;
    expbuf.index = index;
    if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) {
        perror("VIDIOC_EXPBUF");
        return -1;
    }

    *dmafd = expbuf.fd;

    return 0;
}
```



```c
int buffer_export_mp(int v4lfd, enum v4l2_buf_type bt, int index,
    int dmafd[], int n_planes)
{
    int i;

    for (i = 0; i < n_planes; ++i) {
        struct v4l2_exportbuffer expbuf;

        memset(&expbuf, 0, sizeof(expbuf));
        expbuf.type = bt;
        expbuf.index = index;
        expbuf.plane = i;
        if (ioctl(v4lfd, VIDIOC_EXPBUF, &expbuf) == -1) {
            perror("VIDIOC_EXPBUF");
            while (i)
                close(dmafd[--i]);
            return -1;
        }
        dmafd[i] = expbuf.fd;
    }

    return 0;
}
```





<a id="c-v4l2_exportbuffer"></a>

```c
v4l2_exportbuffer
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_exportbuffer</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the buffer, same as struct `v4l2_format` `type` or struct `v4l2_requestbuffers` `type`, set by the application. See `v4l2_buf_type`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Number of the buffer, set by the application. This field is only used for [memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) I/O and can range from zero to the number of buffers allocated with the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and/or [ioctl VIDIOC_CREATE_BUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md#rst-vidioc-create-bufs>) ioctls.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`plane`

</td>
<td>


Index of the plane to be exported when using the multi-planar API. Otherwise this value must be set to zero.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags for the newly created file, currently only `O_CLOEXEC`, `O_RDONLY`, `O_WRONLY`, and `O_RDWR` are supported, refer to the manual of open() for more details.

</td>
</tr>
<tr>
<td>


\__s32

</td>
<td>


`fd`

</td>
<td>


The DMABUF file descriptor associated with a buffer. Set by the driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[11]`

</td>
<td>


Reserved field for future use. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  A queue is not in MMAP mode or DMABUF exporting is not supported or `flags` or `type` or `index` or `plane` fields are invalid.

---

# ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_AUDIO - VIDIOC_S_AUDIO - Query or select the current audio input and its attributes

<a id="rst-ioctl-vidioc-g-audio-vidioc-s-audio"></a>
<a id="rst-vidioc-g-audio"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_AUDIO - VIDIOC_S_AUDIO - Query or select the current audio input and its attributes

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_AUDIO"></a>

```c
VIDIOC_G_AUDIO
```

`int ioctl(int fd, VIDIOC_G_AUDIO, struct v4l2_audio *argp)`





<a id="c-VIDIOC_S_AUDIO"></a>

```c
VIDIOC_S_AUDIO
```

`int ioctl(int fd, VIDIOC_S_AUDIO, const struct v4l2_audio *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_audio`.

<a id="rst-description"></a>

## Description

To query the current audio input applications zero out the `reserved` array of a struct `v4l2_audio` and call the [VIDIOC_G_AUDIO](<#rst-vidioc-g-audio>) ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the device has no audio inputs, or none which combine with the current video input.

Audio inputs have one writable property, the audio mode. To select the current audio input *and* change the audio mode, applications initialize the `index` and `mode` fields, and the `reserved` array of a struct `v4l2_audio` structure and call the [VIDIOC_S_AUDIO](<#rst-vidioc-g-audio>) ioctl. Drivers may switch to a different audio mode if the request cannot be satisfied. However, this is a write-only ioctl, it does not return the actual new audio mode.

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_audio"></a>

```c
v4l2_audio
```


<table>
<caption>struct v4l2_audio</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Identifies the audio input, set by the driver or application.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`name`\[32\]

</td>
<td>


Name of the audio input, a NUL-terminated ASCII string, for example: "Line In". This information is intended for the user, preferably the connector label on the device itself.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capability`

</td>
<td>


Audio capability flags, see [audio-capability](<#rst-audio-capability>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`mode`

</td>
<td>


Audio mode flags set by drivers and applications (on [VIDIOC_S_AUDIO](<#rst-vidioc-g-audio>) ioctl), see [audio-mode](<#rst-audio-mode>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[2\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-audio-capability"></a>


<table>
<caption>Audio Capability Flags</caption>
<tbody>
<tr>
<td>


`V4L2_AUDCAP_STEREO`

</td>
<td>


0x00001

</td>
<td>


This is a stereo input. The flag is intended to automatically disable stereo recording etc. when the signal is always monaural. The API provides no means to detect if stereo is *received*, unless the audio input belongs to a tuner.

</td>
</tr>
<tr>
<td>


`V4L2_AUDCAP_AVL`

</td>
<td>


0x00002

</td>
<td>


Automatic Volume Level mode is supported.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-audio-mode"></a>


<table>
<caption>Audio Mode Flags</caption>
<tbody>
<tr>
<td>


`V4L2_AUDMODE_AVL`

</td>
<td>


0x00001

</td>
<td>


AVL mode is on.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  No audio inputs combine with the current video input, or the number of the selected audio input is out of bounds or it does not combine.

---

# ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_AUDOUT - VIDIOC_S_AUDOUT - Query or select the current audio output

<a id="rst-ioctl-vidioc-g-audout-vidioc-s-audout"></a>
<a id="rst-vidioc-g-audout"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_AUDOUT - VIDIOC_S_AUDOUT - Query or select the current audio output

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_AUDOUT"></a>

```c
VIDIOC_G_AUDOUT
```

`int ioctl(int fd, VIDIOC_G_AUDOUT, struct v4l2_audioout *argp)`





<a id="c-VIDIOC_S_AUDOUT"></a>

```c
VIDIOC_S_AUDOUT
```

`int ioctl(int fd, VIDIOC_S_AUDOUT, const struct v4l2_audioout *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_audioout`.

<a id="rst-description"></a>

## Description

To query the current audio output applications zero out the `reserved` array of a struct `v4l2_audioout` and call the `VIDIOC_G_AUDOUT` ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the device has no audio inputs, or none which combine with the current video output.

Audio outputs have no writable properties. Nevertheless, to select the current audio output applications can initialize the `index` field and `reserved` array (which in the future may contain writable properties) of a struct `v4l2_audioout` structure and call the `VIDIOC_S_AUDOUT` ioctl. Drivers switch to the requested output or return the `EINVAL` error code when the index is out of bounds. This is a write-only ioctl, it does not return the current audio output attributes as `VIDIOC_G_AUDOUT` does.

> [!NOTE]
>
> Connectors on a TV card to loop back the received audio signal to a sound card are not audio outputs in this sense.





<a id="c-v4l2_audioout"></a>

```c
v4l2_audioout
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_audioout</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Identifies the audio output, set by the driver or application.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`name`\[32\]

</td>
<td>


Name of the audio output, a NUL-terminated ASCII string, for example: "Line Out". This information is intended for the user, preferably the connector label on the device itself.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capability`

</td>
<td>


Audio capability flags, none defined yet. Drivers must set this field to zero.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`mode`

</td>
<td>


Audio mode, none defined yet. Drivers and applications (on `VIDIOC_S_AUDOUT`) must set this field to zero.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[2\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  No audio outputs combine with the current video output, or the number of the selected audio output is out of bounds or it does not combine.

---

# ioctl VIDIOC_G_CROP, VIDIOC_S_CROP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_CROP - VIDIOC_S_CROP - Get or set the current cropping rectangle

<a id="rst-ioctl-vidioc-g-crop-vidioc-s-crop"></a>
<a id="rst-vidioc-g-crop"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_CROP - VIDIOC_S_CROP - Get or set the current cropping rectangle

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_CROP"></a>

```c
VIDIOC_G_CROP
```

`int ioctl(int fd, VIDIOC_G_CROP, struct v4l2_crop *argp)`





<a id="c-VIDIOC_S_CROP"></a>

```c
VIDIOC_S_CROP
```

`int ioctl(int fd, VIDIOC_S_CROP, const struct v4l2_crop *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_crop`.

<a id="rst-description"></a>

## Description

To query the cropping rectangle size and position applications set the `type` field of a struct `v4l2_crop` structure to the respective buffer (stream) type and call the [VIDIOC_G_CROP](<#rst-vidioc-g-crop>) ioctl with a pointer to this structure. The driver fills the rest of the structure or returns the `EINVAL` error code if cropping is not supported.

To change the cropping rectangle applications initialize the `type` and struct `v4l2_rect` substructure named `c` of a v4l2_crop structure and call the [VIDIOC_S_CROP](<#rst-vidioc-g-crop>) ioctl with a pointer to this structure.

The driver first adjusts the requested dimensions against hardware limits, i. e. the bounds given by the capture/output window, and it rounds to the closest possible values of horizontal and vertical offset, width and height. In particular the driver must round the vertical offset of the cropping rectangle to frame lines modulo two, such that the field order cannot be confused.

Second the driver adjusts the image size (the opposite rectangle of the scaling process, source or target depending on the data direction) to the closest size possible while maintaining the current horizontal and vertical scaling factor.

Finally the driver programs the hardware with the actual cropping and image parameters. [VIDIOC_S_CROP](<#rst-vidioc-g-crop>) is a write-only ioctl, it does not return the actual parameters. To query them applications must call [VIDIOC_G_CROP](<#rst-vidioc-g-crop>) and [ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>). When the parameters are unsuitable the application may modify the cropping or image parameters and repeat the cycle until satisfactory parameters have been negotiated.

When cropping is not supported then no parameters are changed and [VIDIOC_S_CROP](<#rst-vidioc-g-crop>) returns the `EINVAL` error code.





<a id="c-v4l2_crop"></a>

```c
v4l2_crop
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_crop</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the data stream, set by the application. Only these types are valid here: `V4L2_BUF_TYPE_VIDEO_CAPTURE`, `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`, `V4L2_BUF_TYPE_VIDEO_OUTPUT`, `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE` and `V4L2_BUF_TYPE_VIDEO_OVERLAY`. See `v4l2_buf_type` and the note below.

</td>
</tr>
<tr>
<td>


struct `v4l2_rect`

</td>
<td>


`c`

</td>
<td>


Cropping rectangle. The same co-ordinate system as for struct `v4l2_cropcap` `bounds` is used.

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> Unfortunately in the case of multiplanar buffer types (`V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE` and `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`) this API was messed up with regards to how the `v4l2_crop` `type` field should be filled in. Some drivers only accepted the `_MPLANE` buffer type while other drivers only accepted a non-multiplanar buffer type (i.e. without the `_MPLANE` at the end).
>
> Starting with kernel 4.13 both variations are allowed.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **ENODATA**

  Cropping is not supported for this input or output.

---

# ioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_CTRL - VIDIOC_S_CTRL - Get or set the value of a control

<a id="rst-ioctl-vidioc-g-ctrl-vidioc-s-ctrl"></a>
<a id="rst-vidioc-g-ctrl"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_CTRL - VIDIOC_S_CTRL - Get or set the value of a control

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_CTRL"></a>

```c
VIDIOC_G_CTRL
```

`int ioctl(int fd, VIDIOC_G_CTRL, struct v4l2_control *argp)`





<a id="c-VIDIOC_S_CTRL"></a>

```c
VIDIOC_S_CTRL
```

`int ioctl(int fd, VIDIOC_S_CTRL, struct v4l2_control *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_control`.

<a id="rst-description"></a>

## Description

To get the current value of a control applications initialize the `id` field of a struct `v4l2_control` and call the [VIDIOC_G_CTRL](<#rst-vidioc-g-ctrl>) ioctl with a pointer to this structure. To change the value of a control applications initialize the `id` and `value` fields of a struct `v4l2_control` and call the [VIDIOC_S_CTRL](<#rst-vidioc-g-ctrl>) ioctl.

When the `id` is invalid drivers return an `EINVAL` error code. When the `value` is out of bounds drivers can choose to take the closest valid value or return an `ERANGE` error code, whatever seems more appropriate. However, [VIDIOC_S_CTRL](<#rst-vidioc-g-ctrl>) is a write-only ioctl, it does not return the actual new value. If the `value` is inappropriate for the control (e.g. if it refers to an unsupported menu index of a menu control), then EINVAL error code is returned as well.

These ioctls work only with user controls. For other control classes the [VIDIOC_G_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), [VIDIOC_S_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) or [VIDIOC_TRY_EXT_CTRLS](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-g-ext-ctrls.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) must be used.





<a id="c-v4l2_control"></a>

```c
v4l2_control
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_control</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`id`

</td>
<td>


Identifies the control, set by the application.

</td>
</tr>
<tr>
<td>


\__s32

</td>
<td>


`value`

</td>
<td>


New value or current value.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_control` `id` is invalid or the `value` is inappropriate for the given control (i.e. if a menu item is selected that is not supported by the driver according to [VIDIOC_QUERYMENU](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)).

- **ERANGE**

  The struct `v4l2_control` `value` is out of bounds.

- **EBUSY**

  The control is temporarily not changeable, possibly because another applications took over control of the device function this control belongs to.

- **EACCES**

  Attempt to set a read-only control or to get a write-only control.

  Or if there is an attempt to set an inactive control and the driver is not capable of caching the new value until the control is active again.

---

# ioctl VIDIOC_G_DV_TIMINGS, VIDIOC_S_DV_TIMINGS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_DV_TIMINGS - VIDIOC_S_DV_TIMINGS - VIDIOC_SUBDEV_G_DV_TIMINGS - VIDIOC_SUBDEV_S_DV_TIMINGS - Get or set DV timings for input or output

<a id="rst-ioctl-vidioc-g-dv-timings-vidioc-s-dv-timings"></a>
<a id="rst-vidioc-g-dv-timings"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_DV_TIMINGS - VIDIOC_S_DV_TIMINGS - VIDIOC_SUBDEV_G_DV_TIMINGS - VIDIOC_SUBDEV_S_DV_TIMINGS - Get or set DV timings for input or output

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_DV_TIMINGS"></a>

```c
VIDIOC_G_DV_TIMINGS
```

`int ioctl(int fd, VIDIOC_G_DV_TIMINGS, struct v4l2_dv_timings *argp)`





<a id="c-VIDIOC_S_DV_TIMINGS"></a>

```c
VIDIOC_S_DV_TIMINGS
```

`int ioctl(int fd, VIDIOC_S_DV_TIMINGS, struct v4l2_dv_timings *argp)`





<a id="c-VIDIOC_SUBDEV_G_DV_TIMINGS"></a>

```c
VIDIOC_SUBDEV_G_DV_TIMINGS
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_DV_TIMINGS, struct v4l2_dv_timings *argp)`





<a id="c-VIDIOC_SUBDEV_S_DV_TIMINGS"></a>

```c
VIDIOC_SUBDEV_S_DV_TIMINGS
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_DV_TIMINGS, struct v4l2_dv_timings *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_dv_timings`.

<a id="rst-description"></a>

## Description

To set DV timings for the input or output, applications use the [VIDIOC_S_DV_TIMINGS](<#rst-vidioc-g-dv-timings>) ioctl and to get the current timings, applications use the [VIDIOC_G_DV_TIMINGS](<#rst-vidioc-g-dv-timings>) ioctl. The detailed timing information is filled in using the structure struct `v4l2_dv_timings`. These ioctls take a pointer to the struct `v4l2_dv_timings` structure as argument. If the ioctl is not supported or the timing values are not correct, the driver returns `EINVAL` error code.

Calling `VIDIOC_SUBDEV_S_DV_TIMINGS` on a subdev device node that has been registered in read-only mode is not allowed. An error is returned and the errno variable is set to `-EPERM`.

The `linux/v4l2-dv-timings.h` header can be used to get the timings of the formats in the [CEA-861-E](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-cea861>) and [VESA DMT](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vesadmt>) standards. If the current input or output does not support DV timings (e.g. if [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) does not set the `V4L2_IN_CAP_DV_TIMINGS` flag), then `ENODATA` error code is returned.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  This ioctl is not supported, or the [VIDIOC_S_DV_TIMINGS](<#rst-vidioc-g-dv-timings>) parameter was unsuitable.

- **ENODATA**

  Digital video timings are not supported for this input or output.

- **EBUSY**

  The device is busy and therefore can not change the timings.

- **EPERM**

  `VIDIOC_SUBDEV_S_DV_TIMINGS` has been called on a read-only subdevice.





<a id="c-v4l2_bt_timings"></a>

```c
v4l2_bt_timings
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_bt_timings</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`width`

</td>
<td>


Width of the active video in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`height`

</td>
<td>


Height of the active video frame in lines. So for interlaced formats the height of the active video in each field is `height`/2.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`interlaced`

</td>
<td>


Progressive (`V4L2_DV_PROGRESSIVE`) or interlaced (`V4L2_DV_INTERLACED`).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`polarities`

</td>
<td>


This is a bit mask that defines polarities of sync signals. bit 0 (`V4L2_DV_VSYNC_POS_POL`) is for vertical sync polarity and bit 1 (`V4L2_DV_HSYNC_POS_POL`) is for horizontal sync polarity. If the bit is set (1) it is positive polarity and if is cleared (0), it is negative polarity.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`pixelclock`

</td>
<td>


Pixel clock in Hz. Ex. 74.25MHz-&gt;74250000

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`hfrontporch`

</td>
<td>


Horizontal front porch in pixels

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`hsync`

</td>
<td>


Horizontal sync length in pixels

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`hbackporch`

</td>
<td>


Horizontal back porch in pixels

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`vfrontporch`

</td>
<td>


Vertical front porch in lines. For interlaced formats this refers to the odd field (aka field 1).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`vsync`

</td>
<td>


Vertical sync length in lines. For interlaced formats this refers to the odd field (aka field 1).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`vbackporch`

</td>
<td>


Vertical back porch in lines. For interlaced formats this refers to the odd field (aka field 1).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`il_vfrontporch`

</td>
<td>


Vertical front porch in lines for the even field (aka field 2) of interlaced field formats. Must be 0 for progressive formats.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`il_vsync`

</td>
<td>


Vertical sync length in lines for the even field (aka field 2) of interlaced field formats. Must be 0 for progressive formats.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`il_vbackporch`

</td>
<td>


Vertical back porch in lines for the even field (aka field 2) of interlaced field formats. Must be 0 for progressive formats.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`standards`

</td>
<td>


The video standard(s) this format belongs to. This will be filled in by the driver. Applications must set this to 0. See [dv-bt-standards](<#rst-dv-bt-standards>) for a list of standards.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Several flags giving more information about the format. See [dv-bt-flags](<#rst-dv-bt-flags>) for a description of the flags.

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`picture_aspect`

</td>
<td>


The picture aspect if the pixels are not square. Only valid if the `V4L2_DV_FL_HAS_PICTURE_ASPECT` flag is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`cea861_vic`

</td>
<td>


The Video Identification Code according to the CEA-861 standard. Only valid if the `V4L2_DV_FL_HAS_CEA861_VIC` flag is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`hdmi_vic`

</td>
<td>


The Video Identification Code according to the HDMI standard. Only valid if the `V4L2_DV_FL_HAS_HDMI_VIC` flag is set.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`reserved[46]`

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{3.5cm}|p{3.5cm}|p{7.0cm}|p{3.1cm}| -->





<a id="c-v4l2_dv_timings"></a>

```c
v4l2_dv_timings
```


<table>
<caption>struct v4l2_dv_timings</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of DV timings as listed in [dv-timing-types](<#rst-dv-timing-types>).

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


(anonymous)

</td>
</tr>
<tr>
<td>


struct `v4l2_bt_timings`

</td>
<td>


`bt`

</td>
<td>


Timings defined by BT.656/1120 specifications

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[32\]

</td>
<td>




</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->

<a id="rst-dv-timing-types"></a>


<table>
<caption>DV Timing types</caption>
<tbody>
<tr>
<td>


Timing type

</td>
<td>


value

</td>
<td>


Description

</td>
</tr>
<tr>
<td>




</td>
<td>




</td>
<td>




</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_656_1120`

</td>
<td>


0

</td>
<td>


BT.656/1120 timings

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.5cm}|p{11.0cm}| -->

<a id="rst-dv-bt-standards"></a>


<table>
<caption>DV BT Timing standards</caption>
<tbody>
<tr>
<td>


Timing standard

</td>
<td>


Description

</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_STD_CEA861`

</td>
<td>


The timings follow the CEA-861 Digital TV Profile standard

</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_STD_DMT`

</td>
<td>


The timings follow the VESA Discrete Monitor Timings standard

</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_STD_CVT`

</td>
<td>


The timings follow the VESA Coordinated Video Timings standard

</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_STD_GTF`

</td>
<td>


The timings follow the VESA Generalized Timings Formula standard

</td>
</tr>
<tr>
<td>


`V4L2_DV_BT_STD_SDI`

</td>
<td>


The timings follow the SDI Timings standard. There are no horizontal syncs/porches at all in this format. Total blanking timings must be set in hsync or vsync fields only.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.7cm}|p{9.8cm}| -->

<a id="rst-dv-bt-flags"></a>


<table>
<caption>DV BT Timing flags</caption>
<tbody>
<tr>
<td>


Flag

</td>
<td>


Description

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_REDUCED_BLANKING`

</td>
<td>


CVT/GTF specific: the timings use reduced blanking (CVT) or the 'Secondary GTF' curve (GTF). In both cases the horizontal and/or vertical blanking intervals are reduced, allowing a higher resolution over the same bandwidth. This is a read-only flag, applications must not set this.

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_CAN_REDUCE_FPS`

</td>
<td>


CEA-861 specific: set for CEA-861 formats with a framerate that is a multiple of six. These formats can be optionally played at 1 / 1.001 speed to be compatible with 60 Hz based standards such as NTSC and PAL-M that use a framerate of 29.97 frames per second. If the transmitter can't generate such frequencies, then the flag will also be cleared. This is a read-only flag, applications must not set this.

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_REDUCED_FPS`

</td>
<td>


CEA-861 specific: only valid for video transmitters or video receivers that have the `V4L2_DV_FL_CAN_DETECT_REDUCED_FPS` set. This flag is cleared otherwise. It is also only valid for formats with the `V4L2_DV_FL_CAN_REDUCE_FPS` flag set, for other formats the flag will be cleared by the driver.

If the application sets this flag for a transmitter, then the pixelclock used to set up the transmitter is divided by 1.001 to make it compatible with NTSC framerates. If the transmitter can't generate such frequencies, then the flag will be cleared.

If a video receiver detects that the format uses a reduced framerate, then it will set this flag to signal this to the application.

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_HALF_LINE`

</td>
<td>


Specific to interlaced formats: if set, then the vertical frontporch of field 1 (aka the odd field) is really one half-line longer and the vertical backporch of field 2 (aka the even field) is really one half-line shorter, so each field has exactly the same number of half-lines. Whether half-lines can be detected or used depends on the hardware.

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_IS_CE_VIDEO`

</td>
<td>


If set, then this is a Consumer Electronics (CE) video format. Such formats differ from other formats (commonly called IT formats) in that if R'G'B' encoding is used then by default the R'G'B' values use limited range (i.e. 16-235) as opposed to full range (i.e. 0-255). All formats defined in CEA-861 except for the 640x480p59.94 format are CE formats.

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE`

</td>
<td>


Some formats like SMPTE-125M have an interlaced signal with a odd total height. For these formats, if this flag is set, the first field has the extra line. Else, it is the second field.

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_HAS_PICTURE_ASPECT`

</td>
<td>


If set, then the picture_aspect field is valid. Otherwise assume that the pixels are square, so the picture aspect ratio is the same as the width to height ratio.

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_HAS_CEA861_VIC`

</td>
<td>


If set, then the cea861_vic field is valid and contains the Video Identification Code as per the CEA-861 standard.

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_HAS_HDMI_VIC`

</td>
<td>


If set, then the hdmi_vic field is valid and contains the Video Identification Code as per the HDMI standard (HDMI Vendor Specific InfoFrame).

</td>
</tr>
<tr>
<td>


`V4L2_DV_FL_CAN_DETECT_REDUCED_FPS`

</td>
<td>


CEA-861 specific: only valid for video receivers, the flag is cleared by transmitters. If set, then the hardware can detect the difference between regular framerates and framerates reduced by 1000/1001. E.g.: 60 vs 59.94 Hz, 30 vs 29.97 Hz or 24 vs 23.976 Hz.

</td>
</tr>
</tbody>
</table>

---

# ioctl VIDIOC_G_EDID, VIDIOC_S_EDID, VIDIOC_SUBDEV_G_EDID, VIDIOC_SUBDEV_S_EDID

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_EDID - VIDIOC_S_EDID - VIDIOC_SUBDEV_G_EDID - VIDIOC_SUBDEV_S_EDID - Get or set the EDID of a video receiver/transmitter

<a id="rst-ioctl-vidioc-g-edid-vidioc-s-edid-vidioc-subdev-g-edid-vidioc-subdev-s-edid"></a>
<a id="rst-vidioc-g-edid"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_EDID - VIDIOC_S_EDID - VIDIOC_SUBDEV_G_EDID - VIDIOC_SUBDEV_S_EDID - Get or set the EDID of a video receiver/transmitter

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_EDID"></a>

```c
VIDIOC_G_EDID
```

`int ioctl(int fd, VIDIOC_G_EDID, struct v4l2_edid *argp)`





<a id="c-VIDIOC_S_EDID"></a>

```c
VIDIOC_S_EDID
```

`int ioctl(int fd, VIDIOC_S_EDID, struct v4l2_edid *argp)`





<a id="c-VIDIOC_SUBDEV_G_EDID"></a>

```c
VIDIOC_SUBDEV_G_EDID
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_EDID, struct v4l2_edid *argp)`





<a id="c-VIDIOC_SUBDEV_S_EDID"></a>

```c
VIDIOC_SUBDEV_S_EDID
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_EDID, struct v4l2_edid *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_edid`.

<a id="rst-description"></a>

## Description

These ioctls can be used to get or set an EDID associated with an input from a receiver or an output of a transmitter device. They can be used with subdevice nodes (/dev/v4l-subdevX) or with video nodes (/dev/videoX).

When used with video nodes the `pad` field represents the input (for video capture devices) or output (for video output devices) index as is returned by [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) and [ioctl VIDIOC_ENUMOUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-vidioc-enumoutput>) respectively. When used with subdevice nodes the `pad` field represents the input or output pad of the subdevice. If there is no EDID support for the given `pad` value, then the `EINVAL` error code will be returned.

To get the EDID data the application has to fill in the `pad`, `start_block`, `blocks` and `edid` fields, zero the `reserved` array and call [VIDIOC_G_EDID](<#rst-vidioc-g-edid>). The current EDID from block `start_block` and of size `blocks` will be placed in the memory `edid` points to. The `edid` pointer must point to memory at least `blocks` \* 128 bytes large (the size of one block is 128 bytes).

If there are fewer blocks than specified, then the driver will set `blocks` to the actual number of blocks. If there are no EDID blocks available at all, then the error code `ENODATA` is set.

If blocks have to be retrieved from the sink, then this call will block until they have been read.

If `start_block` and `blocks` are both set to 0 when [VIDIOC_G_EDID](<#rst-vidioc-g-edid>) is called, then the driver will set `blocks` to the total number of available EDID blocks and it will return 0 without copying any data. This is an easy way to discover how many EDID blocks there are.

> [!NOTE]
>
> If there are no EDID blocks available at all, then the driver will set `blocks` to 0 and it returns 0.

To set the EDID blocks of a receiver the application has to fill in the `pad`, `blocks` and `edid` fields, set `start_block` to 0 and zero the `reserved` array. It is not possible to set part of an EDID, it is always all or nothing. Setting the EDID data is only valid for receivers as it makes no sense for a transmitter.

The driver assumes that the full EDID is passed in. If there are more EDID blocks than the hardware can handle then the EDID is not written, but instead the error code `E2BIG` is set and `blocks` is set to the maximum that the hardware supports. If `start_block` is any value other than 0 then the error code `EINVAL` is set.

To disable an EDID you set `blocks` to 0. Depending on the hardware this will drive the hotplug pin low and/or block the source from reading the EDID data in some way. In any case, the end result is the same: the EDID is no longer available.





<a id="c-v4l2_edid"></a>

```c
v4l2_edid
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_edid</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad for which to get/set the EDID blocks. When used with a video device node the pad represents the input or output index as returned by [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) and [ioctl VIDIOC_ENUMOUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-vidioc-enumoutput>) respectively.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`start_block`

</td>
<td>


Read the EDID from starting with this block. Must be 0 when setting the EDID.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`blocks`

</td>
<td>


The number of blocks to get or set. Must be less or equal to 256 (the maximum number of blocks as defined by the standard). When you set the EDID and `blocks` is 0, then the EDID is disabled or erased.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[5\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
<tr>
<td>


\__u8 \*

</td>
<td>


`edid`

</td>
<td>


Pointer to memory that contains the EDID. The minimum size is `blocks` \* 128.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **`ENODATA`**

  The EDID data is not available.

- **`E2BIG`**

  The EDID data you provided is more than the hardware can handle.

---

# ioctl VIDIOC_G_ENC_INDEX

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_ENC_INDEX - Get meta data about a compressed video stream

<a id="rst-ioctl-vidioc-g-enc-index"></a>
<a id="rst-vidioc-g-enc-index"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_ENC_INDEX - Get meta data about a compressed video stream

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_ENC_INDEX"></a>

```c
VIDIOC_G_ENC_INDEX
```

`int ioctl(int fd, VIDIOC_G_ENC_INDEX, struct v4l2_enc_idx *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_enc_idx`.

<a id="rst-description"></a>

## Description

The [VIDIOC_G_ENC_INDEX](<#rst-vidioc-g-enc-index>) ioctl provides meta data about a compressed video stream the same or another application currently reads from the driver, which is useful for random access into the stream without decoding it.

To read the data applications must call [VIDIOC_G_ENC_INDEX](<#rst-vidioc-g-enc-index>) with a pointer to a struct `v4l2_enc_idx`. On success the driver fills the `entry` array, stores the number of elements written in the `entries` field, and initializes the `entries_cap` field.

Each element of the `entry` array contains meta data about one picture. A [VIDIOC_G_ENC_INDEX](<#rst-vidioc-g-enc-index>) call reads up to `V4L2_ENC_IDX_ENTRIES` entries from a driver buffer, which can hold up to `entries_cap` entries. This number can be lower or higher than `V4L2_ENC_IDX_ENTRIES`, but not zero. When the application fails to read the meta data in time the oldest entries will be lost. When the buffer is empty or no capturing/encoding is in progress, `entries` will be zero.

Currently this ioctl is only defined for MPEG-2 program streams and video elementary streams.

<!-- tabularcolumns: |p{4.2cm}|p{6.2cm}|p{6.9cm}| -->





<a id="c-v4l2_enc_idx"></a>

```c
v4l2_enc_idx
```


<table>
<caption>struct v4l2_enc_idx</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`entries`

</td>
<td>


The number of entries the driver stored in the `entry` array.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`entries_cap`

</td>
<td>


The number of entries the driver can buffer. Must be greater than zero.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[4\]

</td>
<td>


Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
<tr>
<td>


struct `v4l2_enc_idx_entry`

</td>
<td>


`entry`\[`V4L2_ENC_IDX_ENTRIES`\]

</td>
<td>


Meta data about a compressed video stream. Each element of the array corresponds to one picture, sorted in ascending order by their `offset`.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_enc_idx_entry"></a>

```c
v4l2_enc_idx_entry
```


<table>
<caption>struct v4l2_enc_idx_entry</caption>
<tbody>
<tr>
<td>


\__u64

</td>
<td>


`offset`

</td>
<td>


The offset in bytes from the beginning of the compressed video stream to the beginning of this picture, that is a *PES packet header* as defined in [ISO 13818-1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-mpeg2part1>) or a *picture header* as defined in [ISO 13818-2](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-mpeg2part2>). When the encoder is stopped, the driver resets the offset to zero.

</td>
</tr>
<tr>
<td>


\__u64

</td>
<td>


`pts`

</td>
<td>


The 33 bit *Presentation Time Stamp* of this picture as defined in [ISO 13818-1](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-mpeg2part1>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`length`

</td>
<td>


The length of this picture in bytes.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags containing the coding type of this picture, see [enc-idx-flags](<#rst-enc-idx-flags>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[2\]

</td>
<td>


Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-enc-idx-flags"></a>


<table>
<caption>Index Entry Flags</caption>
<tbody>
<tr>
<td>


`V4L2_ENC_IDX_FRAME_I`

</td>
<td>


0x00

</td>
<td>


This is an Intra-coded picture.

</td>
</tr>
<tr>
<td>


`V4L2_ENC_IDX_FRAME_P`

</td>
<td>


0x01

</td>
<td>


This is a Predictive-coded picture.

</td>
</tr>
<tr>
<td>


`V4L2_ENC_IDX_FRAME_B`

</td>
<td>


0x02

</td>
<td>


This is a Bidirectionally predictive-coded picture.

</td>
</tr>
<tr>
<td>


`V4L2_ENC_IDX_FRAME_MASK`

</td>
<td>


0x0F

</td>
<td>


*AND* the flags field with this mask to obtain the picture coding type.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_G_EXT_CTRLS, VIDIOC_S_EXT_CTRLS, VIDIOC_TRY_EXT_CTRLS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_EXT_CTRLS - VIDIOC_S_EXT_CTRLS - VIDIOC_TRY_EXT_CTRLS - Get or set the value of several controls, try control values

<a id="rst-ioctl-vidioc-g-ext-ctrls-vidioc-s-ext-ctrls-vidioc-try-ext-ctrls"></a>
<a id="rst-vidioc-g-ext-ctrls"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC\_G\_EXT\_CTRLS - VIDIOC\_S\_EXT\_CTRLS - VIDIOC\_TRY\_EXT\_CTRLS - Get or set the value of several controls, try control values

<a id="rst-synopsis"></a>

## Synopsis

<a id="c-VIDIOC_G_EXT_CTRLS"></a>



```c
VIDIOC_G_EXT_CTRLS
```

`int ioctl(int fd, VIDIOC_G_EXT_CTRLS, struct v4l2_ext_controls *argp)`

<a id="c-VIDIOC_S_EXT_CTRLS"></a>



```c
VIDIOC_S_EXT_CTRLS
```

`int ioctl(int fd, VIDIOC_S_EXT_CTRLS, struct v4l2_ext_controls *argp)`

<a id="c-VIDIOC_TRY_EXT_CTRLS"></a>



```c
VIDIOC_TRY_EXT_CTRLS
```

`int ioctl(int fd, VIDIOC_TRY_EXT_CTRLS, struct v4l2_ext_controls *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_ext_controls`.

<a id="rst-description"></a>

## Description

These ioctls allow the caller to get or set multiple controls atomically. Control IDs are grouped into control classes (see [ctrl-class](<#rst-ctrl-class>)) and all controls in the control array must belong to the same control class.

Applications must always fill in the `count`, `which`, `controls` and `reserved` fields of struct `v4l2_ext_controls`, and initialize the struct `v4l2_ext_control` array pointed to by the `controls` fields.

To get the current value of a set of controls applications initialize the `id`, `size` and `reserved2` fields of each struct `v4l2_ext_control` and call the [VIDIOC\_G\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) ioctl. String controls must also set the `string` field. Controls of compound types (`V4L2_CTRL_FLAG_HAS_PAYLOAD` is set) must set the `ptr` field.

If the `size` is too small to receive the control result (only relevant for pointer-type controls like strings), then the driver will set `size` to a valid value and return an `ENOSPC` error code. You should re-allocate the memory to this new size and try again. For the string type it is possible that the same issue occurs again if the string has grown in the meantime. It is recommended to call [ioctls VIDIOC\_QUERYCTRL, VIDIOC\_QUERY\_EXT\_CTRL and VIDIOC\_QUERYMENU](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>) first and use `maximum`+1 as the new `size` value. It is guaranteed that that is sufficient memory.

N-dimensional arrays are set and retrieved row-by-row. You cannot set a partial array, all elements have to be set or retrieved. The total size is calculated as `elems` \* `elem_size`. These values can be obtained by calling [VIDIOC\_QUERY\_EXT\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-queryctrl.md#rst-vidioc-queryctrl>).

To change the value of a set of controls applications initialize the `id`, `size`, `reserved2` and `value/value64/string/ptr` fields of each struct `v4l2_ext_control` and call the [VIDIOC\_S\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) ioctl. The controls will only be set if <em>all</em> control values are valid.

To check if a set of controls have correct values applications initialize the `id`, `size`, `reserved2` and `value/value64/string/ptr` fields of each struct `v4l2_ext_control` and call the [VIDIOC\_TRY\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) ioctl. It is up to the driver whether wrong values are automatically adjusted to a valid value or if an error is returned.

When the `id` or `which` is invalid drivers return an `EINVAL` error code. When the value is out of bounds drivers can choose to take the closest valid value or return an `ERANGE` error code, whatever seems more appropriate. In the first case the new value is set in struct `v4l2_ext_control`. If the new control value is inappropriate (e.g. the given menu index is not supported by the menu control), then this will also result in an `EINVAL` error code error.

If `request_fd` is set to a not-yet-queued [request](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>) file descriptor and `which` is set to `V4L2_CTRL_WHICH_REQUEST_VAL`, then the controls are not applied immediately when calling [VIDIOC\_S\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>), but instead are applied by the driver for the buffer associated with the same request. If the device does not support requests, then `EACCES` will be returned. If requests are supported but an invalid request file descriptor is given, then `EINVAL` will be returned.

An attempt to call [VIDIOC\_S\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) for a request that has already been queued will result in an `EBUSY` error.

If `request_fd` is specified and `which` is set to `V4L2_CTRL_WHICH_REQUEST_VAL` during a call to [VIDIOC\_G\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>), then it will return the values of the controls at the time of request completion. If the request is not yet completed, then this will result in an `EACCES` error.

The driver will only set/get these controls if all control values are correct. This prevents the situation where only some of the controls were set/get. Only low-level errors (e. g. a failed i2c command) can still cause this situation.

<!-- tabularcolumns: |p{6.8cm}|p{4.0cm}|p{6.5cm}| -->

<a id="c-v4l2_ext_control"></a>



```c
v4l2_ext_control
```

<!-- Source LaTeX layout: \footnotesize -->


<table>
<caption>

struct v4l2\_ext\_control

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`id`

</td>
<td>



Identifies the control, set by the application.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`size`

</td>
<td>



The total size in bytes of the payload of this control.

</td>
</tr>
<tr>
<td colspan="3">



 The `size` field is normally 0, but for pointer controls this should be set to the size of the memory that contains the payload or that will receive the payload. If [VIDIOC\_G\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) finds that this value is less than is required to store the payload result, then it is set to a value large enough to store the payload result and `ENOSPC` is returned.

> [!NOTE]
>
> For string controls, this `size` field should not be confused with the length of the string. This field refers to the size of the memory that contains the string. The actual <em>length</em> of the string may well be much smaller.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved2`\[1\]

</td>
<td>



Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
<tr>
<td>



union \{

</td>
<td colspan="2">



(anonymous)

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`value`

</td>
<td>



New value or current value. Valid if this control is not of type `V4L2_CTRL_TYPE_INTEGER64` and `V4L2_CTRL_FLAG_HAS_PAYLOAD` is not set.

</td>
</tr>
<tr>
<td>



\_\_s64

</td>
<td>



`value64`

</td>
<td>



New value or current value. Valid if this control is of type `V4L2_CTRL_TYPE_INTEGER64` and `V4L2_CTRL_FLAG_HAS_PAYLOAD` is not set.

</td>
</tr>
<tr>
<td>



char \*

</td>
<td>



`string`

</td>
<td>



A pointer to a string. Valid if this control is of type `V4L2_CTRL_TYPE_STRING`.

</td>
</tr>
<tr>
<td>



\_\_u8 \*

</td>
<td>



`p_u8`

</td>
<td>



A pointer to a matrix control of unsigned 8-bit values. Valid if this control is of type `V4L2_CTRL_TYPE_U8`.

</td>
</tr>
<tr>
<td>



\_\_u16 \*

</td>
<td>



`p_u16`

</td>
<td>



A pointer to a matrix control of unsigned 16-bit values. Valid if this control is of type `V4L2_CTRL_TYPE_U16`.

</td>
</tr>
<tr>
<td>



\_\_u32 \*

</td>
<td>



`p_u32`

</td>
<td>



A pointer to a matrix control of unsigned 32-bit values. Valid if this control is of type `V4L2_CTRL_TYPE_U32`.

</td>
</tr>
<tr>
<td>



\_\_s32 \*

</td>
<td>



`p_s32`

</td>
<td>



A pointer to a matrix control of signed 32-bit values. Valid if this control is of type `V4L2_CTRL_TYPE_INTEGER` and `V4L2_CTRL_FLAG_HAS_PAYLOAD` is set.

</td>
</tr>
<tr>
<td>



\_\_s64 \*

</td>
<td>



`p_s64`

</td>
<td>



A pointer to a matrix control of signed 64-bit values. Valid if this control is of type `V4L2_CTRL_TYPE_INTEGER64` and `V4L2_CTRL_FLAG_HAS_PAYLOAD` is set.

</td>
</tr>
<tr>
<td>



struct `v4l2_area` \*

</td>
<td>



`p_area`

</td>
<td>



A pointer to a struct `v4l2_area`. Valid if this control is of type `V4L2_CTRL_TYPE_AREA`.

</td>
</tr>
<tr>
<td>



struct `v4l2_rect` \*

</td>
<td>



`p_rect`

</td>
<td>



A pointer to a struct `v4l2_rect`. Valid if this control is of type `V4L2_CTRL_TYPE_RECT`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_h264_sps` \*

</td>
<td>



`p_h264_sps`

</td>
<td>



A pointer to a struct `v4l2_ctrl_h264_sps`. Valid if this control is of type `V4L2_CTRL_TYPE_H264_SPS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_h264_pps` \*

</td>
<td>



`p_h264_pps`

</td>
<td>



A pointer to a struct `v4l2_ctrl_h264_pps`. Valid if this control is of type `V4L2_CTRL_TYPE_H264_PPS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_h264_scaling_matrix` \*

</td>
<td>



`p_h264_scaling_matrix`

</td>
<td>



A pointer to a struct `v4l2_ctrl_h264_scaling_matrix`. Valid if this control is of type `V4L2_CTRL_TYPE_H264_SCALING_MATRIX`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_h264_pred_weights` \*

</td>
<td>



`p_h264_pred_weights`

</td>
<td>



A pointer to a struct `v4l2_ctrl_h264_pred_weights`. Valid if this control is of type `V4L2_CTRL_TYPE_H264_PRED_WEIGHTS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_h264_slice_params` \*

</td>
<td>



`p_h264_slice_params`

</td>
<td>



A pointer to a struct `v4l2_ctrl_h264_slice_params`. Valid if this control is of type `V4L2_CTRL_TYPE_H264_SLICE_PARAMS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_h264_decode_params` \*

</td>
<td>



`p_h264_decode_params`

</td>
<td>



A pointer to a struct `v4l2_ctrl_h264_decode_params`. Valid if this control is of type `V4L2_CTRL_TYPE_H264_DECODE_PARAMS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_fwht_params` \*

</td>
<td>



`p_fwht_params`

</td>
<td>



A pointer to a struct `v4l2_ctrl_fwht_params`. Valid if this control is of type `V4L2_CTRL_TYPE_FWHT_PARAMS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_vp8_frame` \*

</td>
<td>



`p_vp8_frame`

</td>
<td>



A pointer to a struct `v4l2_ctrl_vp8_frame`. Valid if this control is of type `V4L2_CTRL_TYPE_VP8_FRAME`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_mpeg2_sequence` \*

</td>
<td>



`p_mpeg2_sequence`

</td>
<td>



A pointer to a struct `v4l2_ctrl_mpeg2_sequence`. Valid if this control is of type `V4L2_CTRL_TYPE_MPEG2_SEQUENCE`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_mpeg2_picture` \*

</td>
<td>



`p_mpeg2_picture`

</td>
<td>



A pointer to a struct `v4l2_ctrl_mpeg2_picture`. Valid if this control is of type `V4L2_CTRL_TYPE_MPEG2_PICTURE`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_mpeg2_quantisation` \*

</td>
<td>



`p_mpeg2_quantisation`

</td>
<td>



A pointer to a struct `v4l2_ctrl_mpeg2_quantisation`. Valid if this control is of type `V4L2_CTRL_TYPE_MPEG2_QUANTISATION`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_vp9_compressed_hdr` \*

</td>
<td>



`p_vp9_compressed_hdr_probs`

</td>
<td>



A pointer to a struct `v4l2_ctrl_vp9_compressed_hdr`. Valid if this control is of type `V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_vp9_frame` \*

</td>
<td>



`p_vp9_frame`

</td>
<td>



A pointer to a struct `v4l2_ctrl_vp9_frame`. Valid if this control is of type `V4L2_CTRL_TYPE_VP9_FRAME`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hdr10_cll_info` \*

</td>
<td>



`p_hdr10_cll`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hdr10_cll_info`. Valid if this control is of type `V4L2_CTRL_TYPE_HDR10_CLL_INFO`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hdr10_mastering_display` \*

</td>
<td>



`p_hdr10_mastering`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hdr10_mastering_display`. Valid if this control is of type `V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hevc_sps` \*

</td>
<td>



`p_hevc_sps`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hevc_sps`. Valid if this control is of type `V4L2_CTRL_TYPE_HEVC_SPS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hevc_pps` \*

</td>
<td>



`p_hevc_pps`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hevc_pps`. Valid if this control is of type `V4L2_CTRL_TYPE_HEVC_PPS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hevc_slice_params` \*

</td>
<td>



`p_hevc_slice_params`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hevc_slice_params`. Valid if this control is of type `V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hevc_scaling_matrix` \*

</td>
<td>



`p_hevc_scaling_matrix`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hevc_scaling_matrix`. Valid if this control is of type `V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hevc_decode_params` \*

</td>
<td>



`p_hevc_decode_params`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hevc_decode_params`. Valid if this control is of type `V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_av1_sequence` \*

</td>
<td>



`p_av1_sequence`

</td>
<td>



A pointer to a struct `v4l2_ctrl_av1_sequence`. Valid if this control is of type `V4L2_CTRL_TYPE_AV1_SEQUENCE`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_av1_tile_group_entry` \*

</td>
<td>



`p_av1_tile_group_entry`

</td>
<td>



A pointer to a struct `v4l2_ctrl_av1_tile_group_entry`. Valid if this control is of type `V4L2_CTRL_TYPE_AV1_TILE_GROUP_ENTRY`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_av1_frame` \*

</td>
<td>



`p_av1_frame`

</td>
<td>



A pointer to a struct `v4l2_ctrl_av1_frame`. Valid if this control is of type `V4L2_CTRL_TYPE_AV1_FRAME`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_av1_film_grain` \*

</td>
<td>



`p_av1_film_grain`

</td>
<td>



A pointer to a struct `v4l2_ctrl_av1_film_grain`. Valid if this control is of type `V4L2_CTRL_TYPE_AV1_FILM_GRAIN`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hdr10_cll_info` \*

</td>
<td>



`p_hdr10_cll_info`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hdr10_cll_info`. Valid if this control is of type `V4L2_CTRL_TYPE_HDR10_CLL_INFO`.

</td>
</tr>
<tr>
<td>



struct `v4l2_ctrl_hdr10_mastering_display` \*

</td>
<td>



`p_hdr10_mastering_display`

</td>
<td>



A pointer to a struct `v4l2_ctrl_hdr10_mastering_display`. Valid if this control is of type `V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY`.

</td>
</tr>
<tr>
<td>



void \*

</td>
<td>



`ptr`

</td>
<td>



A pointer to a compound type which can be an N-dimensional array and/or a compound type (the control's type is &gt;= `V4L2_CTRL_COMPOUND_TYPES`). Valid if `V4L2_CTRL_FLAG_HAS_PAYLOAD` is set for this control.

</td>
</tr>
<tr>
<td>



\}

</td>
<td colspan="2">





</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<!-- tabularcolumns: |p{4.0cm}|p{2.5cm}|p{10.8cm}| -->

<a id="c-v4l2_ext_controls"></a>



```c
v4l2_ext_controls
```


<table>
<caption>

struct v4l2\_ext\_controls

</caption>
<tbody>
<tr>
<td>



union \{

</td>
<td colspan="2">



(anonymous)

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`which`

</td>
<td>



Which value of the control to get/set/try.

</td>
</tr>
<tr>
<td colspan="3">



 `V4L2_CTRL_WHICH_CUR_VAL` will return the current value of the control, `V4L2_CTRL_WHICH_DEF_VAL` will return the default value of the control, `V4L2_CTRL_WHICH_MIN_VAL` will return the minimum value of the control, and `V4L2_CTRL_WHICH_MAX_VAL` will return the maximum value of the control. `V4L2_CTRL_WHICH_REQUEST_VAL` indicates that the control value has to be retrieved from a request or tried/set for a request. In that case the `request_fd` field contains the file descriptor of the request that should be used. If the device does not support requests, then `EACCES` will be returned.

When using `V4L2_CTRL_WHICH_DEF_VAL`, `V4L2_CTRL_WHICH_MIN_VAL` or `V4L2_CTRL_WHICH_MAX_VAL` be aware that you can only get the default/minimum/maximum value of the control, you cannot set or try it.

Whether a control supports querying the minimum and maximum values using `V4L2_CTRL_WHICH_MIN_VAL` and `V4L2_CTRL_WHICH_MAX_VAL` is indicated by the `V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX` flag. Most non-compound control types support this. For controls with compound types, the definition of minimum/maximum values are provided by the control documentation. If a compound control does not document the meaning of minimum/maximum value, then querying the minimum or maximum value will result in the error code -EINVAL.

For backwards compatibility you can also use a control class here (see [ctrl-class](<#rst-ctrl-class>)). In that case all controls have to belong to that control class. This usage is deprecated, instead just use `V4L2_CTRL_WHICH_CUR_VAL`. There are some very old drivers that do not yet support `V4L2_CTRL_WHICH_CUR_VAL` and that require a control class here. You can test for such drivers by setting `which` to `V4L2_CTRL_WHICH_CUR_VAL` and calling [VIDIOC\_TRY\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) with a count of 0. If that fails, then the driver does not support `V4L2_CTRL_WHICH_CUR_VAL`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`ctrl_class`

</td>
<td>



Deprecated name kept for backwards compatibility. Use `which` instead.

</td>
</tr>
<tr>
<td>



\}

</td>
<td colspan="2">





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`count`

</td>
<td>



The number of controls in the controls array. May also be zero.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`error_idx`

</td>
<td>



Index of the failing control. Set by the driver in case of an error.

</td>
</tr>
<tr>
<td colspan="3">



 If the error is associated with a particular control, then `error_idx` is set to the index of that control. If the error is not related to a specific control, or the validation step failed (see below), then `error_idx` is set to `count`. The value is undefined if the ioctl returned 0 (success).

Before controls are read from/written to hardware a validation step takes place: this checks if all controls in the list are valid controls, if no attempt is made to write to a read-only control or read from a write-only control, and any other up-front checks that can be done without accessing the hardware. The exact validations done during this step are driver dependent since some checks might require hardware access for some devices, thus making it impossible to do those checks up-front. However, drivers should make a best-effort to do as many up-front checks as possible.

This check is done to avoid leaving the hardware in an inconsistent state due to easy-to-avoid problems. But it leads to another problem: the application needs to know whether an error came from the validation step (meaning that the hardware was not touched) or from an error during the actual reading from/writing to hardware.

The, in hindsight quite poor, solution for that is to set `error_idx` to `count` if the validation failed. This has the unfortunate side-effect that it is not possible to see which control failed the validation. If the validation was successful and the error happened while accessing the hardware, then `error_idx` is less than `count` and only the controls up to `error_idx-1` were read or written correctly, and the state of the remaining controls is undefined.

Since [VIDIOC\_TRY\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) does not access hardware there is also no need to handle the validation step in this special way, so `error_idx` will just be set to the control that failed the validation step instead of to `count`. This means that if [VIDIOC\_S\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) fails with `error_idx` set to `count`, then you can call [VIDIOC\_TRY\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) to try to discover the actual control that failed the validation step. Unfortunately, there is no `TRY` equivalent for [VIDIOC\_G\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>).

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`request_fd`

</td>
<td>



File descriptor of the request to be used by this operation. Only valid if `which` is set to `V4L2_CTRL_WHICH_REQUEST_VAL`. If the device does not support requests, then `EACCES` will be returned. If requests are supported but an invalid request file descriptor is given, then `EINVAL` will be returned.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`\[1\]

</td>
<td>



Reserved for future extensions.

Drivers and applications must set the array to zero.

</td>
</tr>
<tr>
<td>



struct `v4l2_ext_control` \*

</td>
<td>



`controls`

</td>
<td>



Pointer to an array of `count` v4l2\_ext\_control structures.

Ignored if `count` equals zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.3cm}|p{2.0cm}|p{8.0cm}| -->

<a id="rst-ctrl-class"></a>


<table>
<caption>

Control classes

</caption>
<tbody>
<tr>
<td>



`V4L2_CTRL_CLASS_USER`

</td>
<td>



0x980000

</td>
<td>



The class containing user controls. These controls are described in [control](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>). All controls that can be set using the [VIDIOC\_S\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) and [VIDIOC\_G\_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) ioctl belong to this class.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_CODEC`

</td>
<td>



0x990000

</td>
<td>



The class containing stateful codec controls. These controls are described in [Codec Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec.md#rst-codec-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_CAMERA`

</td>
<td>



0x9a0000

</td>
<td>



The class containing camera controls. These controls are described in [Camera Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-camera.md#rst-camera-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_FM_TX`

</td>
<td>



0x9b0000

</td>
<td>



The class containing FM Transmitter (FM TX) controls. These controls are described in [fm-tx-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-fm-tx.md#rst-fm-tx-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_FLASH`

</td>
<td>



0x9c0000

</td>
<td>



The class containing flash device controls. These controls are described in [flash-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-flash.md#rst-flash-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_JPEG`

</td>
<td>



0x9d0000

</td>
<td>



The class containing JPEG compression controls. These controls are described in [jpeg-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-jpeg.md#rst-jpeg-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_IMAGE_SOURCE`

</td>
<td>



0x9e0000

</td>
<td>



The class containing image source controls. These controls are described in [image-source-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-image-source.md#rst-image-source-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_IMAGE_PROC`

</td>
<td>



0x9f0000

</td>
<td>



The class containing image processing controls. These controls are described in [image-process-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-image-process.md#rst-image-process-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_FM_RX`

</td>
<td>



0xa10000

</td>
<td>



The class containing FM Receiver (FM RX) controls. These controls are described in [fm-rx-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-fm-rx.md#rst-fm-rx-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_RF_TUNER`

</td>
<td>



0xa20000

</td>
<td>



The class containing RF tuner controls. These controls are described in [rf-tuner-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-rf-tuner.md#rst-rf-tuner-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_DETECT`

</td>
<td>



0xa30000

</td>
<td>



The class containing motion or object detection controls. These controls are described in [detect-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-detect.md#rst-detect-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_CODEC_STATELESS`

</td>
<td>



0xa40000

</td>
<td>



The class containing stateless codec controls. These controls are described in [Stateless Codec Control Reference](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-codec-stateless.md#rst-codec-stateless-controls>).

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_CLASS_COLORIMETRY`

</td>
<td>



0xa50000

</td>
<td>



The class containing colorimetry controls. These controls are described in [colorimetry-controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-colorimetry.md#rst-colorimetry-controls>).

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_ext_control` `id` is invalid, or the struct `v4l2_ext_controls` `which` is invalid, or the struct `v4l2_ext_control` `value` was inappropriate (e.g. the given menu index is not supported by the driver), or the `which` field was set to `V4L2_CTRL_WHICH_REQUEST_VAL` but the given `request_fd` was invalid or `V4L2_CTRL_WHICH_REQUEST_VAL` is not supported by the kernel. This error code is also returned by the [VIDIOC\_S\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) and [VIDIOC\_TRY\_EXT\_CTRLS](<#rst-vidioc-g-ext-ctrls>) ioctls if two or more control values are in conflict.

- **ERANGE**

  The struct `v4l2_ext_control` `value` is out of bounds.

- **EBUSY**

  The control is temporarily not changeable, possibly because another applications took over control of the device function this control belongs to, or (if the `which` field was set to `V4L2_CTRL_WHICH_REQUEST_VAL`) the request was queued but not yet completed.

- **ENOSPC**

  The space reserved for the control's payload is insufficient. The field `size` is set to a value that is enough to store the payload and this error code is returned.

- **EACCES**

  Attempt to try or set a read-only control, or to get a write-only control, or to get a control from a request that has not yet been completed.

  Or the `which` field was set to `V4L2_CTRL_WHICH_REQUEST_VAL` but the device does not support requests.

  Or if there is an attempt to set an inactive control and the driver is not capable of caching the new value until the control is active again.

---

# ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_FBUF - VIDIOC_S_FBUF - Get or set frame buffer overlay parameters

<a id="rst-ioctl-vidioc-g-fbuf-vidioc-s-fbuf"></a>
<a id="rst-vidioc-g-fbuf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC\_G\_FBUF - VIDIOC\_S\_FBUF - Get or set frame buffer overlay parameters

<a id="rst-synopsis"></a>

## Synopsis

<a id="c-VIDIOC_G_FBUF"></a>



```c
VIDIOC_G_FBUF
```

`int ioctl(int fd, VIDIOC_G_FBUF, struct v4l2_framebuffer *argp)`

<a id="c-VIDIOC_S_FBUF"></a>



```c
VIDIOC_S_FBUF
```

`int ioctl(int fd, VIDIOC_S_FBUF, const struct v4l2_framebuffer *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_framebuffer`.

<a id="rst-description"></a>

## Description

Applications can use the [VIDIOC\_G\_FBUF](<#rst-vidioc-g-fbuf>) and [VIDIOC\_S\_FBUF](<#rst-vidioc-g-fbuf>) ioctl to get and set the framebuffer parameters for a [Video Overlay](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) or [Video Output Overlay](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>) (OSD). The type of overlay is implied by the device type (capture or output device) and can be determined with the [vidioc\_querycap](</kernel/userspace/userspace-api/media-v4l/vidioc-querycap.md#rst-vidioc-querycap>) ioctl. One `/dev/videoN` device must not support both kinds of overlay.

The V4L2 API distinguishes destructive and non-destructive overlays. A destructive overlay copies captured video images into the video memory of a graphics card. A non-destructive overlay blends video images into a VGA signal or graphics into a video signal. <em>Video Output Overlays</em> are always non-destructive.

Destructive overlay support has been removed: with modern GPUs and CPUs this is no longer needed, and it was always a very dangerous feature.

To get the current parameters applications call the [VIDIOC\_G\_FBUF](<#rst-vidioc-g-fbuf>) ioctl with a pointer to a struct `v4l2_framebuffer` structure. The driver fills all fields of the structure or returns an EINVAL error code when overlays are not supported.

To set the parameters for a <em>Video Output Overlay</em>, applications must initialize the `flags` field of a struct `v4l2_framebuffer`. Since the framebuffer is implemented on the TV card all other parameters are determined by the driver. When an application calls [VIDIOC\_S\_FBUF](<#rst-vidioc-g-fbuf>) with a pointer to this structure, the driver prepares for the overlay and returns the framebuffer parameters as [VIDIOC\_G\_FBUF](<#rst-vidioc-g-fbuf>) does, or it returns an error code.

To set the parameters for a <em>Video Capture Overlay</em> applications must initialize the `flags` field, the `fmt` substructure, and call [VIDIOC\_S\_FBUF](<#rst-vidioc-g-fbuf>). Again the driver prepares for the overlay and returns the framebuffer parameters as [VIDIOC\_G\_FBUF](<#rst-vidioc-g-fbuf>) does, or it returns an error code.

<!-- tabularcolumns: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{6.6cm}| -->

<a id="c-v4l2_framebuffer"></a>



```c
v4l2_framebuffer
```


<table>
<caption>

struct v4l2\_framebuffer

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`capability`

</td>
<td>





</td>
<td>



Overlay capability flags set by the driver, see [framebuffer-cap](<#rst-framebuffer-cap>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>





</td>
<td>



Overlay control flags set by application and driver, see [framebuffer-flags](<#rst-framebuffer-flags>)

</td>
</tr>
<tr>
<td>



void \*

</td>
<td>



`base`

</td>
<td>





</td>
<td>



Physical base address of the framebuffer, that is the address of the pixel in the top left corner of the framebuffer. For [VIDIOC\_S\_FBUF](<#rst-vidioc-g-fbuf>) this field is no longer supported and the kernel will always set this to NULL. For <em>Video Output Overlays</em> the driver will return a valid base address, so applications can find the corresponding Linux framebuffer device (see [osd](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>)). For <em>Video Capture Overlays</em> this field will always be NULL.

</td>
</tr>
<tr>
<td>



struct

</td>
<td>



`fmt`

</td>
<td>





</td>
<td>



Layout of the frame buffer.

</td>
</tr>
<tr>
<td>





</td>
<td>



\_\_u32

</td>
<td>



`width`

</td>
<td>



Width of the frame buffer in pixels.

</td>
</tr>
<tr>
<td>





</td>
<td>



\_\_u32

</td>
<td>



`height`

</td>
<td>



Height of the frame buffer in pixels.

</td>
</tr>
<tr>
<td>





</td>
<td>



\_\_u32

</td>
<td>



`pixelformat`

</td>
<td>



The pixel format of the framebuffer.

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



For <em>non-destructive Video Overlays</em> this field only defines a format for the struct `v4l2_window` `chromakey` field.

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



For <em>Video Output Overlays</em> the driver must return a valid format.

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>





</td>
<td>



Usually this is an RGB format (for example [V4L2\_PIX\_FMT\_RGB565](</kernel/userspace/userspace-api/media-v4l/pixfmt-rgb.md#rst-v4l2-pix-fmt-rgb565>)) but YUV formats (only packed YUV formats when chroma keying is used, not including `V4L2_PIX_FMT_YUYV` and `V4L2_PIX_FMT_UYVY`) and the `V4L2_PIX_FMT_PAL8` format are also permitted. The behavior of the driver when an application requests a compressed format is undefined. See [pixfmt](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>) for information on pixel formats.

</td>
</tr>
<tr>
<td>





</td>
<td>



enum `v4l2_field`

</td>
<td>



`field`

</td>
<td>



Drivers and applications shall ignore this field. If applicable, the field order is selected with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, using the `field` field of struct `v4l2_window`.

</td>
</tr>
<tr>
<td>





</td>
<td>



\_\_u32

</td>
<td>



`bytesperline`

</td>
<td>



Distance in bytes between the leftmost pixels in two adjacent lines.

</td>
</tr>
<tr>
<td colspan="4">



This field is irrelevant to <em>non-destructive Video Overlays</em>.

For <em>Video Output Overlays</em> the driver must return a valid value.

Video hardware may access padding bytes, therefore they must reside in accessible memory. Consider for example the case where padding bytes after the last line of an image cross a system page boundary. Capture devices may write padding bytes, the value is undefined. Output devices ignore the contents of padding bytes.

When the image format is planar the `bytesperline` value applies to the first plane and is divided by the same factor as the `width` field for the other planes. For example the Cb and Cr planes of a YUV 4:2:0 image have half as many padding bytes following each line as the Y plane. To avoid ambiguities drivers must return a `bytesperline` value rounded up to a multiple of the scale factor.

</td>
</tr>
<tr>
<td>





</td>
<td>



\_\_u32

</td>
<td>



`sizeimage`

</td>
<td>



This field is irrelevant to <em>non-destructive Video Overlays</em>. For <em>Video Output Overlays</em> the driver must return a valid format.

Together with `base` it defines the framebuffer memory accessible by the driver.

</td>
</tr>
<tr>
<td>





</td>
<td>



enum `v4l2_colorspace`

</td>
<td>



`colorspace`

</td>
<td>



This information supplements the `pixelformat` and must be set by the driver, see [colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>).

</td>
</tr>
<tr>
<td>





</td>
<td>



\_\_u32

</td>
<td>



`priv`

</td>
<td>



Reserved. Drivers and applications must set this field to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.4cm}|p{1.6cm}|p{8.3cm}| -->

<a id="rst-framebuffer-cap"></a>


<table>
<caption>

Frame Buffer Capability Flags

</caption>
<tbody>
<tr>
<td>



`V4L2_FBUF_CAP_EXTERNOVERLAY`

</td>
<td>



0x0001

</td>
<td>



The device is capable of non-destructive overlays. When the driver clears this flag, only destructive overlays are supported. There are no drivers yet which support both destructive and non-destructive overlays. Video Output Overlays are in practice always non-destructive.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_CAP_CHROMAKEY`

</td>
<td>



0x0002

</td>
<td>



The device supports clipping by chroma-keying the images. That is, image pixels replace pixels in the VGA or video signal only where the latter assume a certain color. Chroma-keying makes no sense for destructive overlays.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_CAP_LIST_CLIPPING`

</td>
<td>



0x0004

</td>
<td>



The device supports clipping using a list of clip rectangles. Note that this is no longer supported.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_CAP_BITMAP_CLIPPING`

</td>
<td>



0x0008

</td>
<td>



The device supports clipping using a bit mask. Note that this is no longer supported.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_CAP_LOCAL_ALPHA`

</td>
<td>



0x0010

</td>
<td>



The device supports clipping/blending using the alpha channel of the framebuffer or VGA signal. Alpha blending makes no sense for destructive overlays.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_CAP_GLOBAL_ALPHA`

</td>
<td>



0x0020

</td>
<td>



The device supports alpha blending using a global alpha value. Alpha blending makes no sense for destructive overlays.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_CAP_LOCAL_INV_ALPHA`

</td>
<td>



0x0040

</td>
<td>



The device supports clipping/blending using the inverted alpha channel of the framebuffer or VGA signal. Alpha blending makes no sense for destructive overlays.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_CAP_SRC_CHROMAKEY`

</td>
<td>



0x0080

</td>
<td>



The device supports Source Chroma-keying. Video pixels with the chroma-key colors are replaced by framebuffer pixels, which is exactly opposite of `V4L2_FBUF_CAP_CHROMAKEY`

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.4cm}|p{1.6cm}|p{8.3cm}| -->

<a id="rst-framebuffer-flags"></a>


<table>
<caption>

Frame Buffer Flags

</caption>
<tbody>
<tr>
<td>



`V4L2_FBUF_FLAG_PRIMARY`

</td>
<td>



0x0001

</td>
<td>



The framebuffer is the primary graphics surface. In other words, the overlay is destructive. This flag is typically set by any driver that doesn't have the `V4L2_FBUF_CAP_EXTERNOVERLAY` capability and it is cleared otherwise.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_FLAG_OVERLAY`

</td>
<td>



0x0002

</td>
<td>



If this flag is set for a video capture device, then the driver will set the initial overlay size to cover the full framebuffer size, otherwise the existing overlay size (as set by [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>)) will be used. Only one video capture driver (bttv) supports this flag. The use of this flag for capture devices is deprecated. There is no way to detect which drivers support this flag, so the only reliable method of setting the overlay size is through [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>). If this flag is set for a video output device, then the video output overlay window is relative to the top-left corner of the framebuffer and restricted to the size of the framebuffer. If it is cleared, then the video output overlay window is relative to the video output display.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_FLAG_CHROMAKEY`

</td>
<td>



0x0004

</td>
<td>



Use chroma-keying. The chroma-key color is determined by the `chromakey` field of struct `v4l2_window` and negotiated with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, see [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) and [osd](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>).

</td>
</tr>
<tr>
<td colspan="3">



 There are no flags to enable clipping using a list of clip rectangles or a bitmap. These methods are negotiated with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, see [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) and [osd](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>).

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_FLAG_LOCAL_ALPHA`

</td>
<td>



0x0008

</td>
<td>



Use the alpha channel of the framebuffer to clip or blend framebuffer pixels with video images. The blend function is: output = framebuffer pixel \* alpha + video pixel \* (1 - alpha). The actual alpha depth depends on the framebuffer pixel format.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_FLAG_GLOBAL_ALPHA`

</td>
<td>



0x0010

</td>
<td>



Use a global alpha value to blend the framebuffer with video images. The blend function is: output = (framebuffer pixel \* alpha + video pixel \* (255 - alpha)) / 255. The alpha value is determined by the `global_alpha` field of struct `v4l2_window` and negotiated with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, see [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) and [osd](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>).

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_FLAG_LOCAL_INV_ALPHA`

</td>
<td>



0x0020

</td>
<td>



Like `V4L2_FBUF_FLAG_LOCAL_ALPHA`, use the alpha channel of the framebuffer to clip or blend framebuffer pixels with video images, but with an inverted alpha value. The blend function is: output = framebuffer pixel \* (1 - alpha) + video pixel \* alpha. The actual alpha depth depends on the framebuffer pixel format.

</td>
</tr>
<tr>
<td>



`V4L2_FBUF_FLAG_SRC_CHROMAKEY`

</td>
<td>



0x0040

</td>
<td>



Use source chroma-keying. The source chroma-key color is determined by the `chromakey` field of struct `v4l2_window` and negotiated with the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl, see [Video Overlay Interface](</kernel/userspace/userspace-api/media-v4l/dev-overlay.md#rst-overlay>) and [osd](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>). Both chroma-keying are mutual exclusive to each other, so same `chromakey` field of struct `v4l2_window` is being used.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EPERM**

  [VIDIOC\_S\_FBUF](<#rst-vidioc-g-fbuf>) can only be called by a privileged user to negotiate the parameters for a destructive overlay.

- **EINVAL**

  The [VIDIOC\_S\_FBUF](<#rst-vidioc-g-fbuf>) parameters are unsuitable.

---

# ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_FMT - VIDIOC_S_FMT - VIDIOC_TRY_FMT - Get or set the data format, try a format

<a id="rst-ioctl-vidioc-g-fmt-vidioc-s-fmt-vidioc-try-fmt"></a>
<a id="rst-vidioc-g-fmt"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_FMT - VIDIOC_S_FMT - VIDIOC_TRY_FMT - Get or set the data format, try a format

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_FMT"></a>

```c
VIDIOC_G_FMT
```

`int ioctl(int fd, VIDIOC_G_FMT, struct v4l2_format *argp)`





<a id="c-VIDIOC_S_FMT"></a>

```c
VIDIOC_S_FMT
```

`int ioctl(int fd, VIDIOC_S_FMT, struct v4l2_format *argp)`





<a id="c-VIDIOC_TRY_FMT"></a>

```c
VIDIOC_TRY_FMT
```

`int ioctl(int fd, VIDIOC_TRY_FMT, struct v4l2_format *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_format`.

<a id="rst-description"></a>

## Description

These ioctls are used to negotiate the format of data (typically image format) exchanged between driver and application.

To query the current parameters applications set the `type` field of a struct `v4l2_format` to the respective buffer (stream) type. For example video capture devices use `V4L2_BUF_TYPE_VIDEO_CAPTURE` or `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`. When the application calls the [VIDIOC_G_FMT](<#rst-vidioc-g-fmt>) ioctl with a pointer to this structure the driver fills the respective member of the `fmt` union. In case of video capture devices that is either the struct `v4l2_pix_format` `pix` or the struct `v4l2_pix_format_mplane` `pix_mp` member. When the requested buffer type is not supported drivers return an `EINVAL` error code.

To change the current format parameters applications initialize the `type` field and all fields of the respective `fmt` union member. For details see the documentation of the various devices types in [Interfaces](</kernel/userspace/userspace-api/media-v4l/devices.md#rst-devices>). Good practice is to query the current parameters first, and to modify only those parameters not suitable for the application. When the application calls the [VIDIOC_S_FMT](<#rst-vidioc-g-fmt>) ioctl with a pointer to a struct `v4l2_format` structure the driver checks and adjusts the parameters against hardware abilities. Drivers should not return an error code unless the `type` field is invalid, this is a mechanism to fathom device capabilities and to approach parameters acceptable for both the application and driver. On success the driver may program the hardware, allocate resources and generally prepare for data exchange. Finally the [VIDIOC_S_FMT](<#rst-vidioc-g-fmt>) ioctl returns the current format parameters as [VIDIOC_G_FMT](<#rst-vidioc-g-fmt>) does. Very simple, inflexible devices may even ignore all input and always return the default parameters. However all V4L2 devices exchanging data with the application must implement the [VIDIOC_G_FMT](<#rst-vidioc-g-fmt>) and [VIDIOC_S_FMT](<#rst-vidioc-g-fmt>) ioctl. When the requested buffer type is not supported drivers return an EINVAL error code on a [VIDIOC_S_FMT](<#rst-vidioc-g-fmt>) attempt. When I/O is already in progress or the resource is not available for other reasons drivers return the `EBUSY` error code.

The [VIDIOC_TRY_FMT](<#rst-vidioc-g-fmt>) ioctl is equivalent to [VIDIOC_S_FMT](<#rst-vidioc-g-fmt>) with one exception: it does not change driver state. It can also be called at any time, never returning `EBUSY`. This function is provided to negotiate parameters, to learn about hardware limitations, without disabling I/O or possibly time consuming hardware preparations. Although strongly recommended drivers are not required to implement this ioctl.

The format as returned by [VIDIOC_TRY_FMT](<#rst-vidioc-g-fmt>) must be identical to what [VIDIOC_S_FMT](<#rst-vidioc-g-fmt>) returns for the same input or output.





<a id="c-v4l2_format"></a>

```c
v4l2_format
```

<!-- tabularcolumns: |p{7.4cm}|p{4.4cm}|p{5.5cm}| -->


<table>
<caption>struct v4l2_format</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the data stream, see `v4l2_buf_type`.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


`fmt`

</td>
</tr>
<tr>
<td>


struct `v4l2_pix_format`

</td>
<td>


`pix`

</td>
<td>


Definition of an image format, see [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>), used by video capture and output devices.

</td>
</tr>
<tr>
<td>


struct `v4l2_pix_format_mplane`

</td>
<td>


`pix_mp`

</td>
<td>


Definition of an image format, see [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>), used by video capture and output devices that support the [multi-planar version of the API](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>).

</td>
</tr>
<tr>
<td>


struct `v4l2_window`

</td>
<td>


`win`

</td>
<td>


Definition of an overlaid image, see [Video Overlay Interface](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>), used by video overlay devices.

</td>
</tr>
<tr>
<td>


struct `v4l2_vbi_format`

</td>
<td>


`vbi`

</td>
<td>


Raw VBI capture or output parameters. This is discussed in more detail in [Raw VBI Data Interface](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>). Used by raw VBI capture and output devices.

</td>
</tr>
<tr>
<td>


struct `v4l2_sliced_vbi_format`

</td>
<td>


`sliced`

</td>
<td>


Sliced VBI capture or output parameters. See [sliced](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-sliced-vbi.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for details. Used by sliced VBI capture and output devices.

</td>
</tr>
<tr>
<td>


struct `v4l2_sdr_format`

</td>
<td>


`sdr`

</td>
<td>


Definition of a data format, see [Image Formats](</kernel/userspace/userspace-api/media-v4l/pixfmt.md#rst-pixfmt>), used by SDR capture and output devices.

</td>
</tr>
<tr>
<td>


struct `v4l2_meta_format`

</td>
<td>


`meta`

</td>
<td>


Definition of a metadata format, see [Metadata Formats](</kernel/userspace/userspace-api/media-v4l/meta-formats.md#rst-meta-formats>), used by metadata capture devices.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`raw_data`\[200\]

</td>
<td>


Place holder for future extensions.

</td>
</tr>
<tr>
<td>


\}

</td>
<td colspan="2">




</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_format` `type` field is invalid or the requested buffer type not supported.

- **EBUSY**

  The device is busy and cannot change the format. This could be because or the device is streaming or buffers are allocated or queued to the driver. Relevant for [VIDIOC_S_FMT](<#rst-vidioc-g-fmt>) only.

---

# ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_FREQUENCY - VIDIOC_S_FREQUENCY - Get or set tuner or modulator radio frequency

<a id="rst-ioctl-vidioc-g-frequency-vidioc-s-frequency"></a>
<a id="rst-vidioc-g-frequency"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_FREQUENCY - VIDIOC_S_FREQUENCY - Get or set tuner or modulator radio frequency

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_FREQUENCY"></a>

```c
VIDIOC_G_FREQUENCY
```

`int ioctl(int fd, VIDIOC_G_FREQUENCY, struct v4l2_frequency *argp)`





<a id="c-VIDIOC_S_FREQUENCY"></a>

```c
VIDIOC_S_FREQUENCY
```

`int ioctl(int fd, VIDIOC_S_FREQUENCY, const struct v4l2_frequency *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_frequency`.

<a id="rst-description"></a>

## Description

To get the current tuner or modulator radio frequency applications set the `tuner` field of a struct `v4l2_frequency` to the respective tuner or modulator number (only input devices have tuners, only output devices have modulators), zero out the `reserved` array and call the [VIDIOC_G_FREQUENCY](<#rst-vidioc-g-frequency>) ioctl with a pointer to this structure. The driver stores the current frequency in the `frequency` field.

To change the current tuner or modulator radio frequency applications initialize the `tuner`, `type` and `frequency` fields, and the `reserved` array of a struct `v4l2_frequency` and call the [VIDIOC_S_FREQUENCY](<#rst-vidioc-g-frequency>) ioctl with a pointer to this structure. When the requested frequency is not possible the driver assumes the closest possible value. However [VIDIOC_S_FREQUENCY](<#rst-vidioc-g-frequency>) is a write-only ioctl, it does not return the actual new frequency.

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_frequency"></a>

```c
v4l2_frequency
```


<table>
<caption>struct v4l2_frequency</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`tuner`

</td>
<td>


The tuner or modulator index number. This is the same value as in the struct `v4l2_input` `tuner` field and the struct `v4l2_tuner` `index` field, or the struct `v4l2_output` `modulator` field and the struct `v4l2_modulator` `index` field.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


The tuner type. This is the same value as in the struct `v4l2_tuner` `type` field. The type must be set to `V4L2_TUNER_RADIO` for `/dev/radioX` device nodes, and to `V4L2_TUNER_ANALOG_TV` for all others. Set this field to `V4L2_TUNER_RADIO` for modulators (currently only radio modulators are supported). See `v4l2_tuner_type`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`frequency`

</td>
<td>


Tuning frequency in units of 62.5 kHz, or if the struct `v4l2_tuner` or struct `v4l2_modulator` `capability` flag `V4L2_TUNER_CAP_LOW` is set, in units of 62.5 Hz. A 1 Hz unit is used when the `capability` flag `V4L2_TUNER_CAP_1HZ` is set.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[8\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The `tuner` index is out of bounds or the value in the `type` field is wrong.

- **EBUSY**

  A hardware seek is in progress.

---

# ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_INPUT - VIDIOC_S_INPUT - Query or select the current video input

<a id="rst-ioctl-vidioc-g-input-vidioc-s-input"></a>
<a id="rst-vidioc-g-input"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_INPUT - VIDIOC_S_INPUT - Query or select the current video input

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_INPUT"></a>

```c
VIDIOC_G_INPUT
```

`int ioctl(int fd, VIDIOC_G_INPUT, int *argp)`





<a id="c-VIDIOC_S_INPUT"></a>

```c
VIDIOC_S_INPUT
```

`int ioctl(int fd, VIDIOC_S_INPUT, int *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer an integer with input index.

<a id="rst-description"></a>

## Description

To query the current video input applications call the [VIDIOC_G_INPUT](<#rst-vidioc-g-input>) ioctl with a pointer to an integer where the driver stores the number of the input, as in the struct `v4l2_input` `index` field. This ioctl will fail only when there are no video inputs, returning `EINVAL`.

To select a video input applications store the number of the desired input in an integer and call the [VIDIOC_S_INPUT](<#rst-vidioc-g-input>) ioctl with a pointer to this integer. Side effects are possible. For example inputs may support different video standards, so the driver may implicitly switch the current standard. Because of these possible side effects applications must select an input before querying or negotiating any other parameters.

Information about video inputs is available using the [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) ioctl.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The number of the video input is out of bounds.

---

# ioctl VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_JPEGCOMP - VIDIOC_S_JPEGCOMP

<a id="rst-ioctl-vidioc-g-jpegcomp-vidioc-s-jpegcomp"></a>
<a id="rst-vidioc-g-jpegcomp"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_JPEGCOMP - VIDIOC_S_JPEGCOMP

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_JPEGCOMP"></a>

```c
VIDIOC_G_JPEGCOMP
```

`int ioctl(int fd, VIDIOC_G_JPEGCOMP, v4l2_jpegcompression *argp)`





<a id="c-VIDIOC_S_JPEGCOMP"></a>

```c
VIDIOC_S_JPEGCOMP
```

`int ioctl(int fd, VIDIOC_S_JPEGCOMP, const v4l2_jpegcompression *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_jpegcompression`.

<a id="rst-description"></a>

## Description

These ioctls are **deprecated**. New drivers and applications should use [JPEG class controls](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-jpeg.md#rst-jpeg-controls>) for image quality and JPEG markers control.

\[to do\]

Ronald Bultje elaborates:

APP is some application-specific information. The application can set it itself, and it'll be stored in the JPEG-encoded fields (eg; interlacing information for in an AVI or so). COM is the same, but it's comments, like 'encoded by me' or so.

jpeg_markers describes whether the huffman tables, quantization tables and the restart interval information (all JPEG-specific stuff) should be stored in the JPEG-encoded fields. These define how the JPEG field is encoded. If you omit them, applications assume you've used standard encoding. You usually do want to add them.

<!-- tabularcolumns: |p{1.2cm}|p{3.0cm}|p{13.1cm}| -->





<a id="c-v4l2_jpegcompression"></a>

```c
v4l2_jpegcompression
```


<table>
<caption>struct v4l2_jpegcompression</caption>
<tbody>
<tr>
<td>


int

</td>
<td>


`quality`

</td>
<td>


Deprecated. If [V4L2_CID_JPEG_COMPRESSION_QUALITY](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-jpeg.md#rst-jpeg-quality-control>) control is exposed by a driver applications should use it instead and ignore this field.

</td>
</tr>
<tr>
<td>


int

</td>
<td>


`APPn`

</td>
<td>




</td>
</tr>
<tr>
<td>


int

</td>
<td>


`APP_len`

</td>
<td>




</td>
</tr>
<tr>
<td>


char

</td>
<td>


`APP_data`\[60\]

</td>
<td>




</td>
</tr>
<tr>
<td>


int

</td>
<td>


`COM_len`

</td>
<td>




</td>
</tr>
<tr>
<td>


char

</td>
<td>


`COM_data`\[60\]

</td>
<td>




</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`jpeg_markers`

</td>
<td>


See [jpeg-markers](<#rst-jpeg-markers>). Deprecated. If [V4L2_CID_JPEG_ACTIVE_MARKER](</kernel/userspace/userspace-api/media-v4l/ext-ctrls-jpeg.md#rst-jpeg-active-marker-control>) control is exposed by a driver applications should use it instead and ignore this field.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-jpeg-markers"></a>


<table>
<caption>JPEG Markers Flags</caption>
<tbody>
<tr>
<td>


`V4L2_JPEG_MARKER_DHT`

</td>
<td>


(1&lt;&lt;3)

</td>
<td>


Define Huffman Tables

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_MARKER_DQT`

</td>
<td>


(1&lt;&lt;4)

</td>
<td>


Define Quantization Tables

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_MARKER_DRI`

</td>
<td>


(1&lt;&lt;5)

</td>
<td>


Define Restart Interval

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_MARKER_COM`

</td>
<td>


(1&lt;&lt;6)

</td>
<td>


Comment segment

</td>
</tr>
<tr>
<td>


`V4L2_JPEG_MARKER_APP`

</td>
<td>


(1&lt;&lt;7)

</td>
<td>


App segment, driver will always use APP0

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_MODULATOR - VIDIOC_S_MODULATOR - Get or set modulator attributes

<a id="rst-ioctl-vidioc-g-modulator-vidioc-s-modulator"></a>
<a id="rst-vidioc-g-modulator"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_MODULATOR - VIDIOC_S_MODULATOR - Get or set modulator attributes

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_MODULATOR"></a>

```c
VIDIOC_G_MODULATOR
```

`int ioctl(int fd, VIDIOC_G_MODULATOR, struct v4l2_modulator *argp)`





<a id="c-VIDIOC_S_MODULATOR"></a>

```c
VIDIOC_S_MODULATOR
```

`int ioctl(int fd, VIDIOC_S_MODULATOR, const struct v4l2_modulator *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_modulator`.

<a id="rst-description"></a>

## Description

To query the attributes of a modulator applications initialize the `index` field and zero out the `reserved` array of a struct `v4l2_modulator` and call the [VIDIOC_G_MODULATOR](<#rst-vidioc-g-modulator>) ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the index is out of bounds. To enumerate all modulators applications shall begin at index zero, incrementing by one until the driver returns EINVAL.

Modulators have two writable properties, an audio modulation set and the radio frequency. To change the modulated audio subprograms, applications initialize the `index` and `txsubchans` fields and the `reserved` array and call the [VIDIOC_S_MODULATOR](<#rst-vidioc-g-modulator>) ioctl. Drivers may choose a different audio modulation if the request cannot be satisfied. However this is a write-only ioctl, it does not return the actual audio modulation selected.

[SDR](</kernel/userspace/userspace-api/media-v4l/dev-sdr.md#rst-sdr>) specific modulator types are `V4L2_TUNER_SDR` and `V4L2_TUNER_RF`. For SDR devices `txsubchans` field must be initialized to zero. The term 'modulator' means SDR transmitter in this context.

To change the radio frequency the [VIDIOC_S_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) ioctl is available.

<!-- tabularcolumns: |p{2.9cm}|p{2.9cm}|p{5.8cm}|p{2.9cm}|p{2.4cm}| -->





<a id="c-v4l2_modulator"></a>

```c
v4l2_modulator
```


<table>
<caption>struct v4l2_modulator</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td colspan="3">


Identifies the modulator, set by the application.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`name`\[32\]

</td>
<td colspan="3">


Name of the modulator, a NUL-terminated ASCII string.

This information is intended for the user.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capability`

</td>
<td colspan="3">


Modulator capability flags. No flags are defined for this field, the tuner flags in struct `v4l2_tuner` are used accordingly. The audio flags indicate the ability to encode audio subprograms. They will *not* change for example with the current video standard.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`rangelow`

</td>
<td colspan="3">


The lowest tunable frequency in units of 62.5 KHz, or if the `capability` flag `V4L2_TUNER_CAP_LOW` is set, in units of 62.5 Hz, or if the `capability` flag `V4L2_TUNER_CAP_1HZ` is set, in units of 1 Hz.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`rangehigh`

</td>
<td colspan="3">


The highest tunable frequency in units of 62.5 KHz, or if the `capability` flag `V4L2_TUNER_CAP_LOW` is set, in units of 62.5 Hz, or if the `capability` flag `V4L2_TUNER_CAP_1HZ` is set, in units of 1 Hz.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`txsubchans`

</td>
<td colspan="3">


With this field applications can determine how audio sub-carriers shall be modulated. It contains a set of flags as defined in [modulator-txsubchans](<#rst-modulator-txsubchans>).

> [!NOTE]
>
> The tuner `rxsubchans` flags  are reused, but the semantics are different. Video output devices are assumed to have an analog or PCM audio input with 1-3 channels. The `txsubchans` flags select one or more channels for modulation, together with some audio subprogram indicator, for example, a stereo pilot tone.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td colspan="3">


 Type of the modulator, see `v4l2_tuner_type`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[3\]

</td>
<td colspan="3">


Reserved for future extensions.

Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.0cm}|p{2.0cm}|p{9.3cm}| -->

<a id="rst-modulator-txsubchans"></a>


<table>
<caption>Modulator Audio Transmission Flags</caption>
<tbody>
<tr>
<td>


`V4L2_TUNER_SUB_MONO`

</td>
<td>


0x0001

</td>
<td>


Modulate channel 1 as mono audio, when the input has more channels, a down-mix of channel 1 and 2. This flag does not combine with `V4L2_TUNER_SUB_STEREO` or `V4L2_TUNER_SUB_LANG1`.

</td>
</tr>
<tr>
<td>


`V4L2_TUNER_SUB_STEREO`

</td>
<td>


0x0002

</td>
<td>


Modulate channel 1 and 2 as left and right channel of a stereo audio signal. When the input has only one channel or two channels and `V4L2_TUNER_SUB_SAP` is also set, channel 1 is encoded as left and right channel. This flag does not combine with `V4L2_TUNER_SUB_MONO` or `V4L2_TUNER_SUB_LANG1`. When the driver does not support stereo audio it shall fall back to mono.

</td>
</tr>
<tr>
<td>


`V4L2_TUNER_SUB_LANG1`

</td>
<td>


0x0008

</td>
<td>


Modulate channel 1 and 2 as primary and secondary language of a bilingual audio signal. When the input has only one channel it is used for both languages. It is not possible to encode the primary or secondary language only. This flag does not combine with `V4L2_TUNER_SUB_MONO`, `V4L2_TUNER_SUB_STEREO` or `V4L2_TUNER_SUB_SAP`. If the hardware does not support the respective audio matrix, or the current video standard does not permit bilingual audio the [VIDIOC_S_MODULATOR](<#rst-vidioc-g-modulator>) ioctl shall return an `EINVAL` error code and the driver shall fall back to mono or stereo mode.

</td>
</tr>
<tr>
<td>


`V4L2_TUNER_SUB_LANG2`

</td>
<td>


0x0004

</td>
<td>


Same effect as `V4L2_TUNER_SUB_SAP`.

</td>
</tr>
<tr>
<td>


`V4L2_TUNER_SUB_SAP`

</td>
<td>


0x0004

</td>
<td>


When combined with `V4L2_TUNER_SUB_MONO` the first channel is encoded as mono audio, the last channel as Second Audio Program. When the input has only one channel it is used for both audio tracks. When the input has three channels the mono track is a down-mix of channel 1 and 2. When combined with `V4L2_TUNER_SUB_STEREO` channel 1 and 2 are encoded as left and right stereo audio, channel 3 as Second Audio Program. When the input has only two channels, the first is encoded as left and right channel and the second as SAP. When the input has only one channel it is used for all audio tracks. It is not possible to encode a Second Audio Program only. This flag must combine with `V4L2_TUNER_SUB_MONO` or `V4L2_TUNER_SUB_STEREO`. If the hardware does not support the respective audio matrix, or the current video standard does not permit SAP the [VIDIOC_S_MODULATOR](<#rst-vidioc-g-modulator>) ioctl shall return an `EINVAL` error code and driver shall fall back to mono or stereo mode.

</td>
</tr>
<tr>
<td>


`V4L2_TUNER_SUB_RDS`

</td>
<td>


0x0010

</td>
<td>


Enable the RDS encoder for a radio FM transmitter.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_modulator` `index` is out of bounds.

---

# ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_OUTPUT - VIDIOC_S_OUTPUT - Query or select the current video output

<a id="rst-ioctl-vidioc-g-output-vidioc-s-output"></a>
<a id="rst-vidioc-g-output"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_OUTPUT - VIDIOC_S_OUTPUT - Query or select the current video output

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_OUTPUT"></a>

```c
VIDIOC_G_OUTPUT
```

`int ioctl(int fd, VIDIOC_G_OUTPUT, int *argp)`





<a id="c-VIDIOC_S_OUTPUT"></a>

```c
VIDIOC_S_OUTPUT
```

`int ioctl(int fd, VIDIOC_S_OUTPUT, int *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to an integer with output index.

<a id="rst-description"></a>

## Description

To query the current video output applications call the [VIDIOC_G_OUTPUT](<#rst-vidioc-g-output>) ioctl with a pointer to an integer where the driver stores the number of the output, as in the struct `v4l2_output` `index` field. This ioctl will fail only when there are no video outputs, returning the `EINVAL` error code.

To select a video output applications store the number of the desired output in an integer and call the [VIDIOC_S_OUTPUT](<#rst-vidioc-g-output>) ioctl with a pointer to this integer. Side effects are possible. For example outputs may support different video standards, so the driver may implicitly switch the current standard. Because of these possible side effects applications must select an output before querying or negotiating any other parameters.

Information about video outputs is available using the [ioctl VIDIOC_ENUMOUTPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enumoutput.md#rst-vidioc-enumoutput>) ioctl.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The number of the video output is out of bounds, or there are no video outputs at all.

---

# ioctl VIDIOC_G_PARM, VIDIOC_S_PARM

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_PARM - VIDIOC_S_PARM - Get or set streaming parameters

<a id="rst-ioctl-vidioc-g-parm-vidioc-s-parm"></a>
<a id="rst-vidioc-g-parm"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_PARM - VIDIOC_S_PARM - Get or set streaming parameters

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_PARM"></a>

```c
VIDIOC_G_PARM
```

`int ioctl(int fd, VIDIOC_G_PARM, v4l2_streamparm *argp)`





<a id="c-VIDIOC_S_PARM"></a>

```c
VIDIOC_S_PARM
```

`int ioctl(int fd, VIDIOC_S_PARM, v4l2_streamparm *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_streamparm`.

<a id="rst-description"></a>

## Description

Applications can request a different frame interval. The capture or output device will be reconfigured to support the requested frame interval if possible. Optionally drivers may choose to skip or repeat frames to achieve the requested frame interval.

For stateful encoders (see [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>)) this represents the frame interval that is typically embedded in the encoded video stream.

Changing the frame interval shall never change the format. Changing the format, on the other hand, may change the frame interval.

Further these ioctls can be used to determine the number of buffers used internally by a driver in read/write mode. For implications see the section discussing the `read()` function.

To get and set the streaming parameters applications call the [VIDIOC_G_PARM](<#rst-vidioc-g-parm>) and [VIDIOC_S_PARM](<#rst-vidioc-g-parm>) ioctl, respectively. They take a pointer to a struct `v4l2_streamparm` which contains a union holding separate parameters for input and output devices.

<!-- tabularcolumns: |p{3.7cm}|p{3.5cm}|p{10.1cm}| -->





<a id="c-v4l2_streamparm"></a>

```c
v4l2_streamparm
```


<table>
<caption>struct v4l2_streamparm</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


The buffer (stream) type, same as struct `v4l2_format` `type`, set by the application. See `v4l2_buf_type`.

</td>
</tr>
<tr>
<td>


union \{

</td>
<td colspan="2">


`parm`

</td>
</tr>
<tr>
<td>


struct `v4l2_captureparm`

</td>
<td>


`capture`

</td>
<td>


Parameters for capture devices, used when `type` is `V4L2_BUF_TYPE_VIDEO_CAPTURE` or `V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`.

</td>
</tr>
<tr>
<td>


struct `v4l2_outputparm`

</td>
<td>


`output`

</td>
<td>


Parameters for output devices, used when `type` is `V4L2_BUF_TYPE_VIDEO_OUTPUT` or `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`raw_data`\[200\]

</td>
<td>


A place holder for future extensions.

</td>
</tr>
<tr>
<td colspan="3">


\}

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_captureparm"></a>

```c
v4l2_captureparm
```


<table>
<caption>struct v4l2_captureparm</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`capability`

</td>
<td>


See [parm-caps](<#rst-parm-caps>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capturemode`

</td>
<td>


Set by drivers and applications, see [parm-flags](<#rst-parm-flags>).

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`timeperframe`

</td>
<td>


This is the desired period between successive frames captured by the driver, in seconds.

</td>
</tr>
<tr>
<td colspan="3">


This will configure the speed at which the video source (e.g. a sensor) generates video frames. If the speed is fixed, then the driver may choose to skip or repeat frames in order to achieve the requested frame rate.

For stateful encoders (see [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>)) this represents the frame interval that is typically embedded in the encoded video stream.

Applications store here the desired frame period, drivers return the actual frame period.

Changing the video standard (also implicitly by switching the video input) may reset this parameter to the nominal frame period. To reset manually applications can just set this field to zero.

Drivers support this function only when they set the `V4L2_CAP_TIMEPERFRAME` flag in the `capability` field.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`extendedmode`

</td>
<td>


Custom (driver specific) streaming parameters. When unused, applications and drivers must set this field to zero. Applications using this field should check the driver name and version, see [Querying Capabilities](</kernel/userspace/userspace-api/media-v4l/querycap.md#rst-querycap>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`readbuffers`

</td>
<td>


Applications set this field to the desired number of buffers used internally by the driver in `read()` mode. Drivers return the actual number of buffers. When an application requests zero buffers, drivers should just return the current setting rather than the minimum or an error code. For details see [Read/Write](</kernel/userspace/userspace-api/media-v4l/rw.md#rst-rw>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[4\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_outputparm"></a>

```c
v4l2_outputparm
```


<table>
<caption>struct v4l2_outputparm</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`capability`

</td>
<td>


See [parm-caps](<#rst-parm-caps>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`outputmode`

</td>
<td>


Set by drivers and applications, see [parm-flags](<#rst-parm-flags>).

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`timeperframe`

</td>
<td>


This is the desired period between successive frames output by the driver, in seconds.

</td>
</tr>
<tr>
<td colspan="3">


The field is intended to repeat frames on the driver side in `write()` mode (in streaming mode timestamps can be used to throttle the output), saving I/O bandwidth.

For stateful encoders (see [Memory-to-Memory Stateful Video Encoder Interface](</kernel/userspace/userspace-api/media-v4l/dev-encoder.md#rst-encoder>)) this represents the frame interval that is typically embedded in the encoded video stream and it provides a hint to the encoder of the speed at which raw frames are queued up to the encoder.

Applications store here the desired frame period, drivers return the actual frame period.

Changing the video standard (also implicitly by switching the video output) may reset this parameter to the nominal frame period. To reset manually applications can just set this field to zero.

Drivers support this function only when they set the `V4L2_CAP_TIMEPERFRAME` flag in the `capability` field.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`extendedmode`

</td>
<td>


Custom (driver specific) streaming parameters. When unused, applications and drivers must set this field to zero. Applications using this field should check the driver name and version, see [Querying Capabilities](</kernel/userspace/userspace-api/media-v4l/querycap.md#rst-querycap>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`writebuffers`

</td>
<td>


Applications set this field to the desired number of buffers used internally by the driver in `write()` mode. Drivers return the actual number of buffers. When an application requests zero buffers, drivers should just return the current setting rather than the minimum or an error code. For details see [Read/Write](</kernel/userspace/userspace-api/media-v4l/rw.md#rst-rw>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[4\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-parm-caps"></a>


<table>
<caption>Streaming Parameters Capabilities</caption>
<tbody>
<tr>
<td>


`V4L2_CAP_TIMEPERFRAME`

</td>
<td>


0x1000

</td>
<td>


The frame period can be modified by setting the `timeperframe` field.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-parm-flags"></a>


<table>
<caption>Capture Parameters Flags</caption>
<tbody>
<tr>
<td>


`V4L2_MODE_HIGHQUALITY`

</td>
<td>


0x0001

</td>
<td>


High quality imaging mode. High quality mode is intended for still imaging applications. The idea is to get the best possible image quality that the hardware can deliver. It is not defined how the driver writer may achieve that; it will depend on the hardware and the ingenuity of the driver writer. High quality mode is a different mode from the regular motion video capture modes. In high quality mode:

- The driver may be able to capture higher resolutions than for motion capture.

- The driver may support fewer pixel formats than motion capture (eg; true color).

- The driver may capture and arithmetically combine multiple successive fields or frames to remove color edge artifacts and reduce the noise in the video data.

- The driver may capture images in slices like a scanner in order to handle larger format images than would otherwise be possible.

- An image capture operation may be significantly slower than motion capture.

- Moving objects in the image might have excessive motion blur.

- Capture might only work through the `read()` call.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_PRIORITY - VIDIOC_S_PRIORITY - Query or request the access priority associated with a file descriptor

<a id="rst-ioctl-vidioc-g-priority-vidioc-s-priority"></a>
<a id="rst-vidioc-g-priority"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_PRIORITY - VIDIOC_S_PRIORITY - Query or request the access priority associated with a file descriptor

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_PRIORITY"></a>

```c
VIDIOC_G_PRIORITY
```

`int ioctl(int fd, VIDIOC_G_PRIORITY, enum v4l2_priority *argp)`





<a id="c-VIDIOC_S_PRIORITY"></a>

```c
VIDIOC_S_PRIORITY
```

`int ioctl(int fd, VIDIOC_S_PRIORITY, const enum v4l2_priority *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to an enum `v4l2_priority` type.

<a id="rst-description"></a>

## Description

To query the current access priority applications call the [VIDIOC_G_PRIORITY](<#rst-vidioc-g-priority>) ioctl with a pointer to an enum v4l2_priority variable where the driver stores the current priority.

To request an access priority applications store the desired priority in an enum v4l2_priority variable and call [VIDIOC_S_PRIORITY](<#rst-vidioc-g-priority>) ioctl with a pointer to this variable.





<a id="c-v4l2_priority"></a>

```c
v4l2_priority
```

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->


<table>
<caption>enum v4l2_priority</caption>
<tbody>
<tr>
<td>


`V4L2_PRIORITY_UNSET`

</td>
<td>


0

</td>
<td>




</td>
</tr>
<tr>
<td>


`V4L2_PRIORITY_BACKGROUND`

</td>
<td>


1

</td>
<td>


Lowest priority, usually applications running in background, for example monitoring VBI transmissions. A proxy application running in user space will be necessary if multiple applications want to read from a device at this priority.

</td>
</tr>
<tr>
<td>


`V4L2_PRIORITY_INTERACTIVE`

</td>
<td>


2

</td>
<td>




</td>
</tr>
<tr>
<td>


`V4L2_PRIORITY_DEFAULT`

</td>
<td>


2

</td>
<td>


Medium priority, usually applications started and interactively controlled by the user. For example TV viewers, Teletext browsers, or just "panel" applications to change the channel or video controls. This is the default priority unless an application requests another.

</td>
</tr>
<tr>
<td>


`V4L2_PRIORITY_RECORD`

</td>
<td>


3

</td>
<td>


Highest priority. Only one file descriptor can have this priority, it blocks any other fd from changing device properties. Usually applications which must not be interrupted, like video recording.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The requested priority value is invalid.

- **EBUSY**

  Another application already requested higher priority.

---

# ioctl VIDIOC_G_SELECTION, VIDIOC_S_SELECTION

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles

<a id="rst-ioctl-vidioc-g-selection-vidioc-s-selection"></a>
<a id="rst-vidioc-g-selection"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_SELECTION - VIDIOC_S_SELECTION - Get or set one of the selection rectangles

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_SELECTION"></a>

```c
VIDIOC_G_SELECTION
```

`int ioctl(int fd, VIDIOC_G_SELECTION, struct v4l2_selection *argp)`





<a id="c-VIDIOC_S_SELECTION"></a>

```c
VIDIOC_S_SELECTION
```

`int ioctl(int fd, VIDIOC_S_SELECTION, struct v4l2_selection *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_selection`.

<a id="rst-description"></a>

## Description

The ioctls are used to query and configure selection rectangles.

To query the cropping (composing) rectangle set struct `v4l2_selection` `type` field to the respective buffer type. The next step is setting the value of struct `v4l2_selection` `target` field to `V4L2_SEL_TGT_CROP` (`V4L2_SEL_TGT_COMPOSE`). Please refer to table [Common selection definitions](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>) or [Cropping, composing and scaling -- the SELECTION API](</kernel/userspace/userspace-api/media-v4l/selection-api.md#rst-selection-api>) for additional targets. The `flags` and `reserved` fields of struct `v4l2_selection` are ignored and they must be filled with zeros. The driver fills the rest of the structure or returns EINVAL error code if incorrect buffer type or target was used. If cropping (composing) is not supported then the active rectangle is not mutable and it is always equal to the bounds rectangle. Finally, the struct `v4l2_rect` `r` rectangle is filled with the current cropping (composing) coordinates. The coordinates are expressed in driver-dependent units. The only exception are rectangles for images in raw formats, whose coordinates are always expressed in pixels.

To change the cropping (composing) rectangle set the struct `v4l2_selection` `type` field to the respective buffer type. The next step is setting the value of struct `v4l2_selection` `target` to `V4L2_SEL_TGT_CROP` (`V4L2_SEL_TGT_COMPOSE`). Please refer to table [Common selection definitions](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>) or [Cropping, composing and scaling -- the SELECTION API](</kernel/userspace/userspace-api/media-v4l/selection-api.md#rst-selection-api>) for additional targets. The struct `v4l2_rect` `r` rectangle need to be set to the desired active area. Field struct `v4l2_selection` `reserved` is ignored and must be filled with zeros. The driver may adjust coordinates of the requested rectangle. An application may introduce constraints to control rounding behaviour. The struct `v4l2_selection` `flags` field must be set to one of the following:

- `0` - The driver can adjust the rectangle size freely and shall choose a crop/compose rectangle as close as possible to the requested one.

- `V4L2_SEL_FLAG_GE` - The driver is not allowed to shrink the rectangle. The original rectangle must lay inside the adjusted one.

- `V4L2_SEL_FLAG_LE` - The driver is not allowed to enlarge the rectangle. The adjusted rectangle must lay inside the original one.

- `V4L2_SEL_FLAG_GE | V4L2_SEL_FLAG_LE` - The driver must choose the size exactly the same as in the requested rectangle.

Please refer to [sel-const-adjust](<#rst-sel-const-adjust>).

The driver may have to adjusts the requested dimensions against hardware limits and other parts as the pipeline, i.e. the bounds given by the capture/output window or TV display. The closest possible values of horizontal and vertical offset and sizes are chosen according to following priority:

1. Satisfy constraints from struct `v4l2_selection` `flags`.

2. Adjust width, height, left, and top to hardware limits and alignments.

3. Keep center of adjusted rectangle as close as possible to the original one.

4. Keep width and height as close as possible to original ones.

5. Keep horizontal and vertical offset as close as possible to original ones.

On success the struct `v4l2_rect` `r` field contains the adjusted rectangle. When the parameters are unsuitable the application may modify the cropping (composing) or image parameters and repeat the cycle until satisfactory parameters have been negotiated. If constraints flags have to be violated at then `ERANGE` is returned. The error indicates that *there exist no rectangle* that satisfies the constraints.

Selection targets and flags are documented in [Common selection definitions](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>).

<a id="rst-sel-const-adjust"></a>

![constraints.svg](/kernel/userspace/userspace-api/media-v4l/asset-734abe80c221-constraints.svg)

Size adjustments with constraint flags.

Behaviour of rectangle adjustment for different constraint flags.





<a id="c-v4l2_selection"></a>

```c
v4l2_selection
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_selection</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the buffer (from enum `v4l2_buf_type`).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`target`

</td>
<td>


Used to select between [cropping and composing rectangles](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags controlling the selection rectangle adjustments, refer to [selection flags](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


struct `v4l2_rect`

</td>
<td>


`r`

</td>
<td>


The selection rectangle.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved[9]`

</td>
<td>


Reserved fields for future use. Drivers and applications must zero this array.

</td>
</tr>
</tbody>
</table>

> [!NOTE]
>
> Unfortunately in the case of multiplanar buffer types (`V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE` and `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`) this API was messed up with regards to how the `v4l2_selection` `type` field should be filled in. Some drivers only accepted the `_MPLANE` buffer type while other drivers only accepted a non-multiplanar buffer type (i.e. without the `_MPLANE` at the end).
>
> Starting with kernel 4.13 both variations are allowed.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  Given buffer type `type` or the selection target `target` is not supported, or the `flags` argument is not valid.

- **ERANGE**

  It is not possible to adjust struct `v4l2_rect` `r` rectangle to satisfy all constraints given in the `flags` argument.

- **ENODATA**

  Selection is not supported for this input or output.

- **EBUSY**

  It is not possible to apply change of the selection rectangle at the moment. Usually because streaming is in progress.

---

# ioctl VIDIOC_G_SLICED_VBI_CAP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_SLICED_VBI_CAP - Query sliced VBI capabilities

<a id="rst-ioctl-vidioc-g-sliced-vbi-cap"></a>
<a id="rst-vidioc-g-sliced-vbi-cap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC\_G\_SLICED\_VBI\_CAP - Query sliced VBI capabilities

<a id="rst-synopsis"></a>

## Synopsis

<a id="c-VIDIOC_G_SLICED_VBI_CAP"></a>



```c
VIDIOC_G_SLICED_VBI_CAP
```

`int ioctl(int fd, VIDIOC_G_SLICED_VBI_CAP, struct v4l2_sliced_vbi_cap *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_sliced_vbi_cap`.

<a id="rst-description"></a>

## Description

To find out which data services are supported by a sliced VBI capture or output device, applications initialize the `type` field of a struct `v4l2_sliced_vbi_cap`, clear the `reserved` array and call the [VIDIOC\_G\_SLICED\_VBI\_CAP](<#rst-vidioc-g-sliced-vbi-cap>) ioctl. The driver fills in the remaining fields or returns an `EINVAL` error code if the sliced VBI API is unsupported or `type` is invalid.

> [!NOTE]
>
> The `type` field was added, and the ioctl changed from read-only to write-read, in Linux 2.6.19.

<a id="c-v4l2_sliced_vbi_cap"></a>



```c
v4l2_sliced_vbi_cap
```

<!-- tabularcolumns: |p{1.4cm}|p{4.4cm}|p{4.5cm}|p{3.6cm}|p{3.6cm}| -->


<table>
<caption>

struct v4l2\_sliced\_vbi\_cap

</caption>
<tbody>
<tr>
<td>



\_\_u16

</td>
<td>



`service_set`

</td>
<td colspan="3">



 A set of all data services supported by the driver.

Equal to the union of all elements of the `service_lines` array.

</td>
</tr>
<tr>
<td>



\_\_u16

</td>
<td>



`service_lines`\[2\]\[24\]

</td>
<td colspan="3">



 Each element of this array contains a set of data services the hardware can look for or insert into a particular scan line. Data services are defined in [vbi-services](<#rst-vbi-services>). Array indices map to ITU-R line numbers<a id="rst-footnote-reference-1"></a>[1](#rst-f1) as follows:

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



Element

</td>
<td>



525 line systems

</td>
<td>



625 line systems

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`service_lines`\[0\]\[1\]

</td>
<td>



1

</td>
<td>



1

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`service_lines`\[0\]\[23\]

</td>
<td>



23

</td>
<td>



23

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`service_lines`\[1\]\[1\]

</td>
<td>



264

</td>
<td>



314

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`service_lines`\[1\]\[23\]

</td>
<td>



286

</td>
<td>



336

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td colspan="3">



 The number of VBI lines the hardware can capture or output per frame, or the number of services it can identify on a given line may be limited. For example on PAL line 16 the hardware may be able to look for a VPS or Teletext signal, but not both at the same time. Applications can learn about these limits using the [VIDIOC\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-g-fmt.md#rst-vidioc-g-fmt>) ioctl as described in [Sliced VBI Data Interface](</kernel/userspace/userspace-api/media-v4l/dev-sliced-vbi.md#rst-sliced>).

</td>
</tr>
<tr>
<td colspan="5">





</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td colspan="3">



 Drivers must set `service_lines` \[0\]\[0\] and `service_lines`\[1\]\[0\] to zero.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`type`

</td>
<td colspan="3">



Type of the data stream, see `v4l2_buf_type`. Should be `V4L2_BUF_TYPE_SLICED_VBI_CAPTURE` or `V4L2_BUF_TYPE_SLICED_VBI_OUTPUT`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`\[3\]

</td>
<td colspan="3">



 This array is reserved for future extensions.

Applications and drivers must set it to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-f1"></a>



**[1]** See also [vbi-525](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-525>) and [vbi-625](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-vbi-625>).

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{3.9cm}|p{1.0cm}|p{2.0cm}|p{3.0cm}|p{7.0cm}| -->

<a id="rst-vbi-services"></a>


<table>
<caption>

Sliced VBI services

</caption>
<thead>
<tr>
<th>



Symbol

</th>
<th>



Value

</th>
<th>



Reference

</th>
<th>



Lines, usually

</th>
<th>



Payload

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_SLICED_TELETEXT_B` (Teletext System B)

</td>
<td>



0x0001

</td>
<td>



[ets300706](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-ets300706>),

[itu653](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu653>)

</td>
<td>



PAL/SECAM line 7-22, 320-335 (second field 7-22)

</td>
<td>



Last 42 of the 45 byte Teletext packet, that is without clock run-in and framing code, lsb first transmitted.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_VPS`

</td>
<td>



0x0400

</td>
<td>



[ets300231](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-ets300231>)

</td>
<td>



PAL line 16

</td>
<td>



Byte number 3 to 15 according to Figure 9 of ETS 300 231, lsb first transmitted.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_CAPTION_525`

</td>
<td>



0x1000

</td>
<td>



[cea608](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-cea608>)

</td>
<td>



NTSC line 21, 284 (second field 21)

</td>
<td>



Two bytes in transmission order, including parity bit, lsb first transmitted.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_WSS_625`

</td>
<td>



0x4000

</td>
<td>



[en300294](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-en300294>),

[itu1119](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-itu1119>)

</td>
<td>



PAL/SECAM line 23

</td>
<td>



See [V4L2\_SLICED\_VBI\_CAP WSS\_625 payload](<#rst-v4l2-sliced-vbi-cap-wss-625-payload>) below.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_VBI_525`

</td>
<td>



0x1000

</td>
<td colspan="3">



 Set of services applicable to 525 line systems.

</td>
</tr>
<tr>
<td>



`V4L2_SLICED_VBI_625`

</td>
<td>



0x4401

</td>
<td colspan="3">



 Set of services applicable to 625 line systems.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-v4l2-sliced-vbi-cap-wss-625-payload-1"></a>
<a id="rst-v4l2-sliced-vbi-cap-wss-625-payload"></a>

### V4L2\_SLICED\_VBI\_CAP WSS\_625 payload

The payload for `V4L2_SLICED_WSS_625` is:

>
> <table>
> <tbody>
> <tr>
> <td>
>
>
>
> Byte
>
> </td>
> <td colspan="8">
>
>
>
> 0
>
> </td>
> <td colspan="8">
>
>
>
> 1
>
> </td>
> </tr>
> <tr>
> <td rowspan="2">
>
>
>
> Bit
>
> </td>
> <td colspan="4">
>
>
>
> msb
>
> </td>
> <td colspan="4">
>
>
>
> lsb
>
> </td>
> <td colspan="4">
>
>
>
> msb
>
> </td>
> <td colspan="4">
>
>
>
> lsb
>
> </td>
> </tr>
> <tr>
> <td>
>
>
>
> 7
>
> </td>
> <td>
>
>
>
> 6
>
> </td>
> <td>
>
>
>
> 5
>
> </td>
> <td>
>
>
>
> 4
>
> </td>
> <td>
>
>
>
> 3
>
> </td>
> <td>
>
>
>
> 2
>
> </td>
> <td>
>
>
>
> 1
>
> </td>
> <td>
>
>
>
> 0
>
> </td>
> <td>
>
>
>
> x
>
> </td>
> <td>
>
>
>
> x
>
> </td>
> <td>
>
>
>
> 13
>
> </td>
> <td>
>
>
>
> 12
>
> </td>
> <td>
>
>
>
> 11
>
> </td>
> <td>
>
>
>
> 10
>
> </td>
> <td>
>
>
>
> 9
>
> </td>
> <td>
>
>
>
> 8
>
> </td>
> </tr>
> </tbody>
> </table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The value in the `type` field is wrong.

---

# ioctl VIDIOC_G_STD, VIDIOC_S_STD, VIDIOC_SUBDEV_G_STD, VIDIOC_SUBDEV_S_STD

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_STD - VIDIOC_S_STD - VIDIOC_SUBDEV_G_STD - VIDIOC_SUBDEV_S_STD - Query or select the video standard of the current input

<a id="rst-ioctl-vidioc-g-std-vidioc-s-std-vidioc-subdev-g-std-vidioc-subdev-s-std"></a>
<a id="rst-vidioc-g-std"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_G_STD - VIDIOC_S_STD - VIDIOC_SUBDEV_G_STD - VIDIOC_SUBDEV_S_STD - Query or select the video standard of the current input

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_G_STD"></a>

```c
VIDIOC_G_STD
```

`int ioctl(int fd, VIDIOC_G_STD, v4l2_std_id *argp)`





<a id="c-VIDIOC_S_STD"></a>

```c
VIDIOC_S_STD
```

`int ioctl(int fd, VIDIOC_S_STD, const v4l2_std_id *argp)`





<a id="c-VIDIOC_SUBDEV_G_STD"></a>

```c
VIDIOC_SUBDEV_G_STD
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_STD, v4l2_std_id *argp)`





<a id="c-VIDIOC_SUBDEV_S_STD"></a>

```c
VIDIOC_SUBDEV_S_STD
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_STD, const v4l2_std_id *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to `v4l2_std_id`.

<a id="rst-description"></a>

## Description

To query and select the current video standard applications use the [VIDIOC_G_STD](<#rst-vidioc-g-std>) and [VIDIOC_S_STD](<#rst-vidioc-g-std>) ioctls which take a pointer to a [v4l2_std_id](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) type as argument. [VIDIOC_G_STD](<#rst-vidioc-g-std>) can return a single flag or a set of flags as in struct `v4l2_standard` field `id`. The flags must be unambiguous such that they appear in only one enumerated struct `v4l2_standard` structure.

[VIDIOC_S_STD](<#rst-vidioc-g-std>) accepts one or more flags, being a write-only ioctl it does not return the actual new standard as [VIDIOC_G_STD](<#rst-vidioc-g-std>) does. When no flags are given or the current input does not support the requested standard the driver returns an `EINVAL` error code. When the standard set is ambiguous drivers may return `EINVAL` or choose any of the requested standards. If the current input or output does not support standard video timings (e.g. if [ioctl VIDIOC_ENUMINPUT](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) does not set the `V4L2_IN_CAP_STD` flag), then `ENODATA` error code is returned.

Calling `VIDIOC_SUBDEV_S_STD` on a subdev device node that has been registered in read-only mode is not allowed. An error is returned and the errno variable is set to `-EPERM`.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The [VIDIOC_S_STD](<#rst-vidioc-g-std>) parameter was unsuitable.

- **ENODATA**

  Standard video timings are not supported for this input or output.

- **EPERM**

  `VIDIOC_SUBDEV_S_STD` has been called on a read-only subdevice.

---

# ioctl VIDIOC_G_TUNER, VIDIOC_S_TUNER

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_G_TUNER - VIDIOC_S_TUNER - Get or set tuner attributes

<a id="rst-ioctl-vidioc-g-tuner-vidioc-s-tuner"></a>
<a id="rst-vidioc-g-tuner"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC\_G\_TUNER - VIDIOC\_S\_TUNER - Get or set tuner attributes

<a id="rst-synopsis"></a>

## Synopsis

<a id="c-VIDIOC_G_TUNER"></a>



```c
VIDIOC_G_TUNER
```

`int ioctl(int fd, VIDIOC_G_TUNER, struct v4l2_tuner *argp)`

<a id="c-VIDIOC_S_TUNER"></a>



```c
VIDIOC_S_TUNER
```

`int ioctl(int fd, VIDIOC_S_TUNER, const struct v4l2_tuner *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_tuner`.

<a id="rst-description"></a>

## Description

To query the attributes of a tuner applications initialize the `index` field and zero out the `reserved` array of a struct `v4l2_tuner` and call the `VIDIOC_G_TUNER` ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an `EINVAL` error code when the index is out of bounds. To enumerate all tuners applications shall begin at index zero, incrementing by one until the driver returns `EINVAL`.

Tuners have two writable properties, the audio mode and the radio frequency. To change the audio mode, applications initialize the `index`, `audmode` and `reserved` fields and call the `VIDIOC_S_TUNER` ioctl. This will <em>not</em> change the current tuner, which is determined by the current video input. Drivers may choose a different audio mode if the requested mode is invalid or unsupported. Since this is a write-only ioctl, it does not return the actually selected audio mode.

[SDR](</kernel/userspace/userspace-api/media-v4l/dev-sdr.md#rst-sdr>) specific tuner types are `V4L2_TUNER_SDR` and `V4L2_TUNER_RF`. For SDR devices `audmode` field must be initialized to zero. The term 'tuner' means SDR receiver in this context.

To change the radio frequency the [VIDIOC\_S\_FREQUENCY](</kernel/userspace/userspace-api/media-v4l/vidioc-g-frequency.md#rst-vidioc-g-frequency>) ioctl is available.

> <!-- tabularcolumns: |p{1.3cm}|p{3.0cm}|p{7.0cm}|p{5.8cm}| -->

<a id="c-v4l2_tuner"></a>



```c
v4l2_tuner
```


<table>
<caption>

struct v4l2\_tuner

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`index`

</td>
<td colspan="2">



 Identifies the tuner, set by the application.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`name`\[32\]

</td>
<td colspan="2">



Name of the tuner, a NUL-terminated ASCII string.

This information is intended for the user.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`type`

</td>
<td colspan="2">



 Type of the tuner, see `v4l2_tuner_type`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`capability`

</td>
<td colspan="2">



Tuner capability flags, see [tuner-capability](<#rst-tuner-capability>). Audio flags indicate the ability to decode audio subprograms. They will <em>not</em> change, for example with the current video standard.

When the structure refers to a radio tuner the `V4L2_TUNER_CAP_LANG1`, `V4L2_TUNER_CAP_LANG2` and `V4L2_TUNER_CAP_NORM` flags can't be used.

If multiple frequency bands are supported, then `capability` is the union of all `capability` fields of each struct `v4l2_frequency_band`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`rangelow`

</td>
<td colspan="2">



 The lowest tunable frequency in units of 62.5 kHz, or if the `capability` flag `V4L2_TUNER_CAP_LOW` is set, in units of 62.5 Hz, or if the `capability` flag `V4L2_TUNER_CAP_1HZ` is set, in units of 1 Hz. If multiple frequency bands are supported, then `rangelow` is the lowest frequency of all the frequency bands.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`rangehigh`

</td>
<td colspan="2">



 The highest tunable frequency in units of 62.5 kHz, or if the `capability` flag `V4L2_TUNER_CAP_LOW` is set, in units of 62.5 Hz, or if the `capability` flag `V4L2_TUNER_CAP_1HZ` is set, in units of 1 Hz. If multiple frequency bands are supported, then `rangehigh` is the highest frequency of all the frequency bands.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`rxsubchans`

</td>
<td colspan="2">



Some tuners or audio decoders can determine the received audio subprograms by analyzing audio carriers, pilot tones or other indicators. To pass this information drivers set flags defined in [tuner-rxsubchans](<#rst-tuner-rxsubchans>) in this field. For example:

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`V4L2_TUNER_SUB_MONO`

</td>
<td>



receiving mono audio

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`STEREO | SAP`

</td>
<td>



receiving stereo audio and a secondary audio program

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`MONO | STEREO`

</td>
<td>



receiving mono or stereo audio, the hardware cannot distinguish

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`LANG1 | LANG2`

</td>
<td>



receiving bilingual audio

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td>



`MONO | STEREO | LANG1 | LANG2`

</td>
<td>



receiving mono, stereo or bilingual audio

</td>
</tr>
<tr>
<td>





</td>
<td>





</td>
<td colspan="2">



When the `V4L2_TUNER_CAP_STEREO`, `_LANG1`, `_LANG2` or `_SAP` flag is cleared in the `capability` field, the corresponding `V4L2_TUNER_SUB_` flag must not be set here.

This field is valid only if this is the tuner of the current video input, or when the structure refers to a radio tuner.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`audmode`

</td>
<td colspan="2">



The selected audio mode, see [tuner-audmode](<#rst-tuner-audmode>) for valid values. The audio mode does not affect audio subprogram detection, and like a [control](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>) it does not automatically change unless the requested mode is invalid or unsupported. See [tuner-matrix](<#rst-tuner-matrix>) for possible results when the selected and received audio programs do not match.

Currently this is the only field of struct struct `v4l2_tuner` applications can change.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`signal`

</td>
<td colspan="2">



 The signal strength if known.

Ranging from 0 to 65535. Higher values indicate a better signal.

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`afc`

</td>
<td colspan="2">



 Automatic frequency control.

When the `afc` value is negative, the frequency is too low, when positive too high.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`\[4\]

</td>
<td colspan="2">



 Reserved for future extensions.

Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="c-v4l2_tuner_type"></a>



```c
v4l2_tuner_type
```


<table>
<caption>

enum v4l2\_tuner\_type

</caption>
<tbody>
<tr>
<td>



`V4L2_TUNER_RADIO`

</td>
<td>



1

</td>
<td>



Tuner supports radio

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_ANALOG_TV`

</td>
<td>



2

</td>
<td>



Tuner supports analog TV

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_SDR`

</td>
<td>



4

</td>
<td>



Tuner controls the A/D and/or D/A block of a Software Digital Radio (SDR)

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_RF`

</td>
<td>



5

</td>
<td>



Tuner controls the RF part of a Software Digital Radio (SDR)

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.0cm}|p{2.2cm}|p{8.1cm}| -->

<a id="rst-tuner-capability"></a>


<table>
<caption>

Tuner and Modulator Capability Flags

</caption>
<tbody>
<tr>
<td>



`V4L2_TUNER_CAP_LOW`

</td>
<td>



0x0001

</td>
<td>



When set, tuning frequencies are expressed in units of 62.5 Hz instead of 62.5 kHz.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_NORM`

</td>
<td>



0x0002

</td>
<td>



This is a multi-standard tuner; the video standard can or must be switched. (B/G PAL tuners for example are typically not considered multi-standard because the video standard is automatically determined from the frequency band.) The set of supported video standards is available from the struct `v4l2_input` pointing to this tuner, see the description of ioctl [vidioc\_enuminput](</kernel/userspace/userspace-api/media-v4l/vidioc-enuminput.md#rst-vidioc-enuminput>) for details. Only `V4L2_TUNER_ANALOG_TV` tuners can have this capability.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_HWSEEK_BOUNDED`

</td>
<td>



0x0004

</td>
<td>



If set, then this tuner supports the hardware seek functionality where the seek stops when it reaches the end of the frequency range.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_HWSEEK_WRAP`

</td>
<td>



0x0008

</td>
<td>



If set, then this tuner supports the hardware seek functionality where the seek wraps around when it reaches the end of the frequency range.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_STEREO`

</td>
<td>



0x0010

</td>
<td>



Stereo audio reception is supported.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_LANG1`

</td>
<td>



0x0040

</td>
<td>



Reception of the primary language of a bilingual audio program is supported. Bilingual audio is a feature of two-channel systems, transmitting the primary language monaural on the main audio carrier and a secondary language monaural on a second carrier. Only `V4L2_TUNER_ANALOG_TV` tuners can have this capability.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_LANG2`

</td>
<td>



0x0020

</td>
<td>



Reception of the secondary language of a bilingual audio program is supported. Only `V4L2_TUNER_ANALOG_TV` tuners can have this capability.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_SAP`

</td>
<td>



0x0020

</td>
<td>



Reception of a secondary audio program is supported. This is a feature of the BTSC system which accompanies the NTSC video standard. Two audio carriers are available for mono or stereo transmissions of a primary language, and an independent third carrier for a monaural secondary language. Only `V4L2_TUNER_ANALOG_TV` tuners can have this capability.

> [!NOTE]
>
> The `V4L2_TUNER_CAP_LANG2` and `V4L2_TUNER_CAP_SAP` flags are synonyms. `V4L2_TUNER_CAP_SAP` applies when the tuner supports the `V4L2_STD_NTSC_M` video standard.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_RDS`

</td>
<td>



0x0080

</td>
<td>



RDS capture is supported. This capability is only valid for radio tuners.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_RDS_BLOCK_IO`

</td>
<td>



0x0100

</td>
<td>



The RDS data is passed as unparsed RDS blocks.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_RDS_CONTROLS`

</td>
<td>



0x0200

</td>
<td>



The RDS data is parsed by the hardware and set via controls.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_FREQ_BANDS`

</td>
<td>



0x0400

</td>
<td>



The [vidioc\_enum\_freq\_bands](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#rst-vidioc-enum-freq-bands>) ioctl can be used to enumerate the available frequency bands.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_HWSEEK_PROG_LIM`

</td>
<td>



0x0800

</td>
<td>



The range to search when using the hardware seek functionality is programmable, see [vidioc\_s\_hw\_freq\_seek](</kernel/userspace/userspace-api/media-v4l/vidioc-s-hw-freq-seek.md#rst-vidioc-s-hw-freq-seek>) for details.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_CAP_1HZ`

</td>
<td>



0x1000

</td>
<td>



When set, tuning frequencies are expressed in units of 1 Hz instead of 62.5 kHz.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-tuner-rxsubchans"></a>


<table>
<caption>

Tuner Audio Reception Flags

</caption>
<tbody>
<tr>
<td>



`V4L2_TUNER_SUB_MONO`

</td>
<td>



0x0001

</td>
<td>



The tuner receives a mono audio signal.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_SUB_STEREO`

</td>
<td>



0x0002

</td>
<td>



The tuner receives a stereo audio signal.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_SUB_LANG1`

</td>
<td>



0x0008

</td>
<td>



The tuner receives the primary language of a bilingual audio signal. Drivers must clear this flag when the current video standard is `V4L2_STD_NTSC_M`.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_SUB_LANG2`

</td>
<td>



0x0004

</td>
<td>



The tuner receives the secondary language of a bilingual audio signal (or a second audio program).

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_SUB_SAP`

</td>
<td>



0x0004

</td>
<td>



The tuner receives a Second Audio Program.

> [!NOTE]
>
> The `V4L2_TUNER_SUB_LANG2` and `V4L2_TUNER_SUB_SAP` flags are synonyms. The `V4L2_TUNER_SUB_SAP` flag applies when the current video standard is `V4L2_STD_NTSC_M`.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_SUB_RDS`

</td>
<td>



0x0010

</td>
<td>



The tuner receives an RDS channel.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-tuner-audmode"></a>


<table>
<caption>

Tuner Audio Modes

</caption>
<tbody>
<tr>
<td>



`V4L2_TUNER_MODE_MONO`

</td>
<td>



0

</td>
<td>



Play mono audio. When the tuner receives a stereo signal this a down-mix of the left and right channel. When the tuner receives a bilingual or SAP signal this mode selects the primary language.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_MODE_STEREO`

</td>
<td>



1

</td>
<td>



Play stereo audio. When the tuner receives bilingual audio it may play different languages on the left and right channel or the primary language is played on both channels.

Playing different languages in this mode is deprecated. New drivers should do this only in `MODE_LANG1_LANG2`.

When the tuner receives no stereo signal or does not support stereo reception the driver shall fall back to `MODE_MONO`.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_MODE_LANG1`

</td>
<td>



3

</td>
<td>



Play the primary language, mono or stereo. Only `V4L2_TUNER_ANALOG_TV` tuners support this mode.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_MODE_LANG2`

</td>
<td>



2

</td>
<td>



Play the secondary language, mono. When the tuner receives no bilingual audio or SAP, or their reception is not supported the driver shall fall back to mono or stereo mode. Only `V4L2_TUNER_ANALOG_TV` tuners support this mode.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_MODE_SAP`

</td>
<td>



2

</td>
<td>



Play the Second Audio Program. When the tuner receives no bilingual audio or SAP, or their reception is not supported the driver shall fall back to mono or stereo mode. Only `V4L2_TUNER_ANALOG_TV` tuners support this mode.

> [!NOTE]
>
> The `V4L2_TUNER_MODE_LANG2` and `V4L2_TUNER_MODE_SAP` are synonyms.

</td>
</tr>
<tr>
<td>



`V4L2_TUNER_MODE_LANG1_LANG2`

</td>
<td>



4

</td>
<td>



Play the primary language on the left channel, the secondary language on the right channel. When the tuner receives no bilingual audio or SAP, it shall fall back to `MODE_LANG1` or `MODE_MONO`. Only `V4L2_TUNER_ANALOG_TV` tuners support this mode.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \scriptsize -->

<!-- tabularcolumns: |p{1.5cm}|p{1.5cm}|p{2.9cm}|p{2.9cm}|p{2.9cm}|p{2.9cm}| -->

<a id="rst-tuner-matrix"></a>


<table>
<caption>

Tuner Audio Matrix

</caption>
<thead>
<tr>
<th>





</th>
<th colspan="5">



 Selected `V4L2_TUNER_MODE_`

</th>
</tr>
<tr>
<th>



Received `V4L2_TUNER_SUB_`

</th>
<th>



`MONO`

</th>
<th>



`STEREO`

</th>
<th>



`LANG1`

</th>
<th>



`LANG2 = SAP`

</th>
<th>



`LANG1_LANG2`<a id="rst-footnote-reference-1"></a>[1](#rst-f1)

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`MONO`

</td>
<td>



Mono

</td>
<td>



Mono/Mono

</td>
<td>



Mono

</td>
<td>



Mono

</td>
<td>



Mono/Mono

</td>
</tr>
<tr>
<td>



`MONO | SAP`

</td>
<td>



Mono

</td>
<td>



Mono/Mono

</td>
<td>



Mono

</td>
<td>



SAP

</td>
<td>



Mono/SAP (preferred) or Mono/Mono

</td>
</tr>
<tr>
<td>



`STEREO`

</td>
<td>



L+R

</td>
<td>



L/R

</td>
<td>



Stereo L/R (preferred) or Mono L+R

</td>
<td>



Stereo L/R (preferred) or Mono L+R

</td>
<td>



L/R (preferred) or L+R/L+R

</td>
</tr>
<tr>
<td>



`STEREO | SAP`

</td>
<td>



L+R

</td>
<td>



L/R

</td>
<td>



Stereo L/R (preferred) or Mono L+R

</td>
<td>



SAP

</td>
<td>



L+R/SAP (preferred) or L/R or L+R/L+R

</td>
</tr>
<tr>
<td>



`LANG1 | LANG2`

</td>
<td>



Language 1

</td>
<td>



Lang1/Lang2 (deprecated<a id="rst-footnote-reference-2"></a>[2](#rst-f2)) or Lang1/Lang1

</td>
<td>



Language 1

</td>
<td>



Language 2

</td>
<td>



Lang1/Lang2 (preferred) or Lang1/Lang1

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_tuner` `index` is out of bounds.

<a id="rst-f1"></a>



**[1]** This mode has been added in Linux 2.6.17 and may not be supported by older drivers.

<a id="rst-f2"></a>



**[2]** Playback of both languages in `MODE_STEREO` is deprecated. In the future drivers should produce only the primary language in this mode. Applications should request `MODE_LANG1_LANG2` to record both languages or a stereo signal.

---

# ioctl VIDIOC_LOG_STATUS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_LOG_STATUS - Log driver status information

<a id="rst-ioctl-vidioc-log-status"></a>
<a id="rst-vidioc-log-status"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_LOG_STATUS - Log driver status information

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_LOG_STATUS"></a>

```c
VIDIOC_LOG_STATUS
```

`int ioctl(int fd, VIDIOC_LOG_STATUS)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

<a id="rst-description"></a>

## Description

As the video/audio devices become more complicated it becomes harder to debug problems. When this ioctl is called the driver will output the current device status to the kernel log. This is particular useful when dealing with problems like no sound, no video and incorrectly tuned channels. Also many modern devices autodetect video and audio standards and this ioctl will report what the device thinks what the standard is. Mismatches may give an indication where the problem is.

This ioctl is optional and not all drivers support it. It was introduced in Linux 2.6.15.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_OVERLAY

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_OVERLAY - Start or stop video overlay

<a id="rst-ioctl-vidioc-overlay"></a>
<a id="rst-vidioc-overlay"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_OVERLAY - Start or stop video overlay

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_OVERLAY"></a>

```c
VIDIOC_OVERLAY
```

`int ioctl(int fd, VIDIOC_OVERLAY, const int *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to an integer.

<a id="rst-description"></a>

## Description

This ioctl is part of the [video overlay](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) I/O method. Applications call [ioctl VIDIOC_OVERLAY](<#rst-vidioc-overlay>) to start or stop the overlay. It takes a pointer to an integer which must be set to zero by the application to stop overlay, to one to start.

Drivers do not support [ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) or [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) with `V4L2_BUF_TYPE_VIDEO_OVERLAY`.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The overlay parameters have not been set up. See [Video Overlay Interface](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for the necessary steps.

---

# ioctl VIDIOC_PREPARE_BUF

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_PREPARE_BUF - Prepare a buffer for I/O

<a id="rst-ioctl-vidioc-prepare-buf"></a>
<a id="rst-vidioc-prepare-buf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_PREPARE_BUF - Prepare a buffer for I/O

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_PREPARE_BUF"></a>

```c
VIDIOC_PREPARE_BUF
```

`int ioctl(int fd, VIDIOC_PREPARE_BUF, struct v4l2_buffer *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_buffer`.

<a id="rst-description"></a>

## Description

Applications can optionally call the [ioctl VIDIOC_PREPARE_BUF](<#rst-vidioc-prepare-buf>) ioctl to pass ownership of the buffer to the driver before actually enqueuing it, using the [VIDIOC_QBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) ioctl, and to prepare it for future I/O. Such preparations may include cache invalidation or cleaning. Performing them in advance saves time during the actual I/O.

The struct `v4l2_buffer` structure is specified in [buffer](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/buffer.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EBUSY**

  File I/O is in progress.

- **EINVAL**

  The buffer `type` is not supported, or the `index` is out of bounds, or no buffers have been allocated yet, or the `userptr` or `length` are invalid.

---

# ioctl VIDIOC_QBUF, VIDIOC_DQBUF

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_QBUF - VIDIOC_DQBUF - Exchange a buffer with the driver

<a id="rst-ioctl-vidioc-qbuf-vidioc-dqbuf"></a>
<a id="rst-vidioc-qbuf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_QBUF - VIDIOC_DQBUF - Exchange a buffer with the driver

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_QBUF"></a>

```c
VIDIOC_QBUF
```

`int ioctl(int fd, VIDIOC_QBUF, struct v4l2_buffer *argp)`





<a id="c-VIDIOC_DQBUF"></a>

```c
VIDIOC_DQBUF
```

`int ioctl(int fd, VIDIOC_DQBUF, struct v4l2_buffer *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_buffer`.

<a id="rst-description"></a>

## Description

Applications call the `VIDIOC_QBUF` ioctl to enqueue an empty (capturing) or filled (output) buffer in the driver's incoming queue. The semantics depend on the selected I/O method.

To enqueue a buffer applications set the `type` field of a struct `v4l2_buffer` to the same buffer type as was previously used with struct `v4l2_format` `type` and struct `v4l2_requestbuffers` `type`. Applications must also set the `index` field. Valid index numbers range from zero to the number of buffers allocated with [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) (struct `v4l2_requestbuffers` `count`) minus one. The contents of the struct `v4l2_buffer` returned by a [ioctl VIDIOC_QUERYBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-querybuf.md#rst-vidioc-querybuf>) ioctl will do as well. When the buffer is intended for output (`type` is `V4L2_BUF_TYPE_VIDEO_OUTPUT`, `V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE`, or `V4L2_BUF_TYPE_VBI_OUTPUT`) applications must also initialize the `bytesused`, `field` and `timestamp` fields, see [buffer](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/buffer.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for details. Applications must also set `flags` to 0. The `reserved2` and `reserved` fields must be set to 0. When using the [multi-planar API](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>), the `m.planes` field must contain a userspace pointer to a filled-in array of struct `v4l2_plane` and the `length` field must be set to the number of elements in that array.

To enqueue a [memory mapped](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) buffer applications set the `memory` field to `V4L2_MEMORY_MMAP`. When `VIDIOC_QBUF` is called with a pointer to this structure the driver sets the `V4L2_BUF_FLAG_MAPPED` and `V4L2_BUF_FLAG_QUEUED` flags and clears the `V4L2_BUF_FLAG_DONE` flag in the `flags` field, or it returns an `EINVAL` error code.

To enqueue a [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>) buffer applications set the `memory` field to `V4L2_MEMORY_USERPTR`, the `m.userptr` field to the address of the buffer and `length` to its size. When the multi-planar API is used, `m.userptr` and `length` members of the passed array of struct `v4l2_plane` have to be used instead. When `VIDIOC_QBUF` is called with a pointer to this structure the driver sets the `V4L2_BUF_FLAG_QUEUED` flag and clears the `V4L2_BUF_FLAG_MAPPED` and `V4L2_BUF_FLAG_DONE` flags in the `flags` field, or it returns an error code. This ioctl locks the memory pages of the buffer in physical memory, they cannot be swapped out to disk. Buffers remain locked until dequeued, until the [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) or [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl is called, or until the device is closed.

To enqueue a [DMABUF](</kernel/userspace/userspace-api/media-v4l/dmabuf.md#rst-dmabuf>) buffer applications set the `memory` field to `V4L2_MEMORY_DMABUF` and the `m.fd` field to a file descriptor associated with a DMABUF buffer. When the multi-planar API is used the `m.fd` fields of the passed array of struct `v4l2_plane` have to be used instead. When `VIDIOC_QBUF` is called with a pointer to this structure the driver sets the `V4L2_BUF_FLAG_QUEUED` flag and clears the `V4L2_BUF_FLAG_MAPPED` and `V4L2_BUF_FLAG_DONE` flags in the `flags` field, or it returns an error code. This ioctl locks the buffer. Locking a buffer means passing it to a driver for a hardware access (usually DMA). If an application accesses (reads/writes) a locked buffer then the result is undefined. Buffers remain locked until dequeued, until the [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) or [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl is called, or until the device is closed.

The `request_fd` field can be used with the `VIDIOC_QBUF` ioctl to specify the file descriptor of a [request](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>), if requests are in use. Setting it means that the buffer will not be passed to the driver until the request itself is queued. Also, the driver will apply any settings associated with the request for this buffer. This field will be ignored unless the `V4L2_BUF_FLAG_REQUEST_FD` flag is set. If the device does not support requests, then `EBADR` will be returned. If requests are supported but an invalid request file descriptor is given, then `EINVAL` will be returned.

> [!CAUTION]
>
> It is not allowed to mix queuing requests with queuing buffers directly. `EBUSY` will be returned if the first buffer was queued directly and then the application tries to queue a request, or vice versa. After closing the file descriptor, calling [VIDIOC_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>) or calling [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) the check for this will be reset.
>
> For [memory-to-memory devices](</kernel/userspace/userspace-api/media-v4l/dev-mem2mem.md#rst-mem2mem>) you can specify the `request_fd` only for output buffers, not for capture buffers. Attempting to specify this for a capture buffer will result in an `EBADR` error.

Applications call the `VIDIOC_DQBUF` ioctl to dequeue a filled (capturing) or displayed (output) buffer from the driver's outgoing queue. They just set the `type`, `memory` and `reserved` fields of a struct `v4l2_buffer` as above, when `VIDIOC_DQBUF` is called with a pointer to this structure the driver fills all remaining fields or returns an error code. The driver may also set `V4L2_BUF_FLAG_ERROR` in the `flags` field. It indicates a non-critical (recoverable) streaming error. In such case the application may continue as normal, but should be aware that data in the dequeued buffer might be corrupted. When using the multi-planar API, the planes array must be passed in as well.

If the application sets the `memory` field to `V4L2_MEMORY_DMABUF` to dequeue a [DMABUF](</kernel/userspace/userspace-api/media-v4l/dmabuf.md#rst-dmabuf>) buffer, the driver fills the `m.fd` field with a file descriptor numerically the same as the one given to `VIDIOC_QBUF` when the buffer was enqueued. No new file descriptor is created at dequeue time and the value is only for the application convenience. When the multi-planar API is used the `m.fd` fields of the passed array of struct `v4l2_plane` are filled instead.

By default `VIDIOC_DQBUF` blocks when no buffer is in the outgoing queue. When the `O_NONBLOCK` flag was given to the `open()` function, `VIDIOC_DQBUF` returns immediately with an `EAGAIN` error code when no buffer is available.

The struct `v4l2_buffer` structure is specified in [buffer](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/buffer.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EAGAIN**

  Non-blocking I/O has been selected using `O_NONBLOCK` and no buffer was in the outgoing queue.

- **EINVAL**

  The buffer `type` is not supported, or the `index` is out of bounds, or no buffers have been allocated yet, or the `userptr` or `length` are invalid, or the `V4L2_BUF_FLAG_REQUEST_FD` flag was set but the given `request_fd` was invalid, or `m.fd` was an invalid DMABUF file descriptor.

- **EIO**

  `VIDIOC_DQBUF` failed due to an internal error. Can also indicate temporary problems like signal loss.

  > [!NOTE]
  >
  > The driver might dequeue an (empty) buffer despite returning an error, or even stop capturing. Reusing such buffer may be unsafe though and its details (e.g. `index`) may not be returned either. It is recommended that drivers indicate recoverable errors by setting the `V4L2_BUF_FLAG_ERROR` and returning 0 instead. In that case the application should be able to safely reuse the buffer and continue streaming.

- **EPIPE**

  `VIDIOC_DQBUF` returns this on an empty capture queue for mem2mem codecs if a buffer with the `V4L2_BUF_FLAG_LAST` was already dequeued and no new buffers are expected to become available.

- **EBADR**

  The `V4L2_BUF_FLAG_REQUEST_FD` flag was set but the device does not support requests for the given buffer type, or the `V4L2_BUF_FLAG_REQUEST_FD` flag was not set but the device requires that the buffer is part of a request.

- **EBUSY**

  The first buffer was queued via a request, but the application now tries to queue it directly, or vice versa (it is not permitted to mix the two APIs).

---

# ioctl VIDIOC_QUERY_DV_TIMINGS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_QUERY_DV_TIMINGS - VIDIOC_SUBDEV_QUERY_DV_TIMINGS - Sense the DV preset received by the current input

<a id="rst-ioctl-vidioc-query-dv-timings"></a>
<a id="rst-vidioc-query-dv-timings"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_QUERY_DV_TIMINGS - VIDIOC_SUBDEV_QUERY_DV_TIMINGS - Sense the DV preset received by the current input

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_QUERY_DV_TIMINGS"></a>

```c
VIDIOC_QUERY_DV_TIMINGS
```

`int ioctl(int fd, VIDIOC_QUERY_DV_TIMINGS, struct v4l2_dv_timings *argp)`





<a id="c-VIDIOC_SUBDEV_QUERY_DV_TIMINGS"></a>

```c
VIDIOC_SUBDEV_QUERY_DV_TIMINGS
```

`int ioctl(int fd, VIDIOC_SUBDEV_QUERY_DV_TIMINGS, struct v4l2_dv_timings *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_dv_timings`.

<a id="rst-description"></a>

## Description

The hardware may be able to detect the current DV timings automatically, similar to sensing the video standard. To do so, applications call [ioctl VIDIOC_QUERY_DV_TIMINGS](<#rst-vidioc-query-dv-timings>) with a pointer to a struct `v4l2_dv_timings`. Once the hardware detects the timings, it will fill in the timings structure.

> [!NOTE]
>
> Drivers shall *not* switch timings automatically if new timings are detected. Instead, drivers should send the `V4L2_EVENT_SOURCE_CHANGE` event (if they support this) and expect that userspace will take action by calling [ioctl VIDIOC_QUERY_DV_TIMINGS](<#rst-vidioc-query-dv-timings>). The reason is that new timings usually mean different buffer sizes as well, and you cannot change buffer sizes on the fly. In general, applications that receive the Source Change event will have to call [ioctl VIDIOC_QUERY_DV_TIMINGS](<#rst-vidioc-query-dv-timings>), and if the detected timings are valid they will have to stop streaming, set the new timings, allocate new buffers and start streaming again.

If the timings could not be detected because there was no signal, then ENOLINK is returned. If a signal was detected, but it was unstable and the receiver could not lock to the signal, then `ENOLCK` is returned. If the receiver could lock to the signal, but the format is unsupported (e.g. because the pixelclock is out of range of the hardware capabilities), then the driver fills in whatever timings it could find and returns `ERANGE`. In that case the application can call [ioctl VIDIOC_DV_TIMINGS_CAP, VIDIOC_SUBDEV_DV_TIMINGS_CAP](</kernel/userspace/userspace-api/media-v4l/vidioc-dv-timings-cap.md#rst-vidioc-dv-timings-cap>) to compare the found timings with the hardware's capabilities in order to give more precise feedback to the user.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **ENODATA**

  Digital video timings are not supported for this input or output.

- **ENOLINK**

  No timings could be detected because no signal was found.

- **ENOLCK**

  The signal was unstable and the hardware could not lock on to it.

- **ERANGE**

  Timings were found, but they are out of range of the hardware capabilities.

---

# ioctl VIDIOC_QUERYBUF

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_QUERYBUF - Query the status of a buffer

<a id="rst-ioctl-vidioc-querybuf"></a>
<a id="rst-vidioc-querybuf"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_QUERYBUF - Query the status of a buffer

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_QUERYBUF"></a>

```c
VIDIOC_QUERYBUF
```

`int ioctl(int fd, VIDIOC_QUERYBUF, struct v4l2_buffer *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_buffer`.

<a id="rst-description"></a>

## Description

This ioctl is part of the [streaming](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) I/O method. It can be used to query the status of a buffer at any time after buffers have been allocated with the [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl.

Applications set the `type` field of a struct `v4l2_buffer` to the same buffer type as was previously used with struct `v4l2_format` `type` and struct `v4l2_requestbuffers` `type`, and the `index` field. Valid index numbers range from zero to the number of buffers allocated with [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) (struct `v4l2_requestbuffers` `count`) minus one. The `reserved` and `reserved2` fields must be set to 0. When using the [multi-planar API](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>), the `m.planes` field must contain a userspace pointer to an array of struct `v4l2_plane` and the `length` field has to be set to the number of elements in that array. After calling [ioctl VIDIOC_QUERYBUF](<#rst-vidioc-querybuf>) with a pointer to this structure drivers return an error code or fill the rest of the structure.

In the `flags` field the `V4L2_BUF_FLAG_MAPPED`, `V4L2_BUF_FLAG_PREPARED`, `V4L2_BUF_FLAG_QUEUED` and `V4L2_BUF_FLAG_DONE` flags will be valid. The `memory` field will be set to the current I/O method. For the single-planar API, the `m.offset` contains the offset of the buffer from the start of the device memory, the `length` field its size. For the multi-planar API, fields `m.mem_offset` and `length` in the `m.planes` array elements will be used instead and the `length` field of struct `v4l2_buffer` is set to the number of filled-in array elements. The driver may or may not set the remaining fields and flags, they are meaningless in this context.

The struct `v4l2_buffer` structure is specified in [buffer](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/buffer.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The buffer `type` is not supported, or the `index` is out of bounds.

---

# ioctl VIDIOC_QUERYCAP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_QUERYCAP - Query device capabilities

<a id="rst-ioctl-vidioc-querycap"></a>
<a id="rst-vidioc-querycap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_QUERYCAP - Query device capabilities

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_QUERYCAP"></a>

```c
VIDIOC_QUERYCAP
```

`int ioctl(int fd, VIDIOC_QUERYCAP, struct v4l2_capability *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_capability`.

<a id="rst-description"></a>

## Description

All V4L2 devices support the `VIDIOC_QUERYCAP` ioctl. It is used to identify kernel devices compatible with this specification and to obtain information about driver and hardware capabilities. The ioctl takes a pointer to a struct `v4l2_capability` which is filled by the driver. When the driver is not compatible with this specification the ioctl returns an `EINVAL` error code.





<a id="c-v4l2_capability"></a>

```c
v4l2_capability
```

<!-- tabularcolumns: |p{1.4cm}|p{2.8cm}|p{13.1cm}| -->


<table>
<caption>struct v4l2_capability</caption>
<tbody>
<tr>
<td>


\__u8

</td>
<td>


`driver`\[16\]

</td>
<td>


Name of the driver, a unique NUL-terminated ASCII string. For example: "bttv". Driver specific applications can use this information to verify the driver identity. It is also useful to work around known bugs, or to identify drivers in error reports.

Storing strings in fixed sized arrays is bad practice but unavoidable here. Drivers and applications should take precautions to never read or write beyond the end of the array and to make sure the strings are properly NUL-terminated.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`card`\[32\]

</td>
<td>


Name of the device, a NUL-terminated UTF-8 string. For example: "Yoyodyne TV/FM". One driver may support different brands or models of video hardware. This information is intended for users, for example in a menu of available devices. Since multiple TV cards of the same brand may be installed which are supported by the same driver, this name should be combined with the character device file name (e. g. `/dev/video2`) or the `bus_info` string to avoid ambiguities.

</td>
</tr>
<tr>
<td>


\__u8

</td>
<td>


`bus_info`\[32\]

</td>
<td>


Location of the device in the system, a NUL-terminated ASCII string. For example: "PCI:0000:05:06.0". This information is intended for users, to distinguish multiple identical devices. If no such information is available the field must simply count the devices controlled by the driver ("platform:vivid-000"). The bus_info must start with "PCI:" for PCI boards, "PCIe:" for PCI Express boards, "usb-" for USB devices, "I2C:" for i2c devices, "ISA:" for ISA devices, "parport" for parallel port devices and "platform:" for platform devices.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`version`

</td>
<td>


Version number of the driver.

Starting with kernel 3.1, the version reported is provided by the V4L2 subsystem following the kernel numbering scheme. However, it may not always return the same version as the kernel if, for example, a stable or distribution-modified kernel uses the V4L2 stack from a newer kernel.

The version number is formatted using the `KERNEL_VERSION()` macro. For example if the media stack corresponds to the V4L2 version shipped with Kernel 4.14, it would be equivalent to:

</td>
</tr>
<tr>
<td colspan="3">


`#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))`

`__u32 version = KERNEL_VERSION(4, 14, 0);`

`printf ("Version: %u.%u.%u\\n",`

`(version >> 16) & 0xFF, (version >> 8) & 0xFF, version & 0xFF);`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capabilities`

</td>
<td>


Available capabilities of the physical device as a whole, see [device-capabilities](<#rst-device-capabilities>). The same physical device can export multiple devices in /dev (e.g. /dev/videoX, /dev/vbiY and /dev/radioZ). The `capabilities` field should contain a union of all capabilities available around the several V4L2 devices exported to userspace. For all those devices the `capabilities` field returns the same set of capabilities. This allows applications to open just one of the devices (typically the video device) and discover whether video, vbi and/or radio are also supported.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`device_caps`

</td>
<td>


Device capabilities of the opened device, see [device-capabilities](<#rst-device-capabilities>). Should contain the available capabilities of that specific device node. So, for example, `device_caps` of a radio device will only contain radio related capabilities and no video or vbi capabilities. This field is only set if the `capabilities` field contains the `V4L2_CAP_DEVICE_CAPS` capability. Only the `capabilities` field can have the `V4L2_CAP_DEVICE_CAPS` capability, `device_caps` will never set `V4L2_CAP_DEVICE_CAPS`.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[3\]

</td>
<td>


Reserved for future extensions. Drivers must set this array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.0cm}|p{2.6cm}|p{7.7cm}| -->

<a id="rst-device-capabilities"></a>


<table>
<caption>Device Capabilities Flags</caption>
<tbody>
<tr>
<td>


`V4L2_CAP_VIDEO_CAPTURE`

</td>
<td>


0x00000001

</td>
<td>


The device supports the single-planar API through the [Video Capture](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VIDEO_CAPTURE_MPLANE`

</td>
<td>


0x00001000

</td>
<td>


The device supports the [multi-planar API](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>) through the [Video Capture](</kernel/userspace/userspace-api/media-v4l/dev-capture.md#rst-capture>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VIDEO_OUTPUT`

</td>
<td>


0x00000002

</td>
<td>


The device supports the single-planar API through the [Video Output](</kernel/userspace/userspace-api/media-v4l/dev-output.md#rst-output>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VIDEO_OUTPUT_MPLANE`

</td>
<td>


0x00002000

</td>
<td>


The device supports the [multi-planar API](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>) through the [Video Output](</kernel/userspace/userspace-api/media-v4l/dev-output.md#rst-output>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VIDEO_M2M`

</td>
<td>


0x00008000

</td>
<td>


The device supports the single-planar API through the Video Memory-To-Memory interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VIDEO_M2M_MPLANE`

</td>
<td>


0x00004000

</td>
<td>


The device supports the [multi-planar API](</kernel/userspace/userspace-api/media-v4l/planar-apis.md#rst-planar-apis>) through the Video Memory-To-Memory interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VIDEO_OVERLAY`

</td>
<td>


0x00000004

</td>
<td>


The device supports the [Video Overlay](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-overlay.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) interface. A video overlay device typically stores captured images directly in the video memory of a graphics card, with hardware clipping and scaling.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VBI_CAPTURE`

</td>
<td>


0x00000010

</td>
<td>


The device supports the [Raw VBI Capture](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>) interface, providing Teletext and Closed Caption data.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VBI_OUTPUT`

</td>
<td>


0x00000020

</td>
<td>


The device supports the [Raw VBI Output](</kernel/userspace/userspace-api/media-v4l/dev-raw-vbi.md#rst-raw-vbi>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_SLICED_VBI_CAPTURE`

</td>
<td>


0x00000040

</td>
<td>


The device supports the [Sliced VBI Capture](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-sliced-vbi.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_SLICED_VBI_OUTPUT`

</td>
<td>


0x00000080

</td>
<td>


The device supports the [Sliced VBI Output](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-sliced-vbi.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_RDS_CAPTURE`

</td>
<td>


0x00000100

</td>
<td>


The device supports the [RDS](</kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-rds>) capture interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_VIDEO_OUTPUT_OVERLAY`

</td>
<td>


0x00000200

</td>
<td>


The device supports the [Video Output Overlay](</kernel/userspace/userspace-api/media-v4l/dev-osd.md#rst-osd>) (OSD) interface. Unlike the *Video Overlay* interface, this is a secondary function of video output devices and overlays an image onto an outgoing video signal. When the driver sets this flag, it must clear the `V4L2_CAP_VIDEO_OVERLAY` flag and vice versa. <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

</td>
</tr>
<tr>
<td>


`V4L2_CAP_HW_FREQ_SEEK`

</td>
<td>


0x00000400

</td>
<td>


The device supports the [ioctl VIDIOC_S_HW_FREQ_SEEK](</kernel/userspace/userspace-api/media-v4l/vidioc-s-hw-freq-seek.md#rst-vidioc-s-hw-freq-seek>) ioctl for hardware frequency seeking.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_RDS_OUTPUT`

</td>
<td>


0x00000800

</td>
<td>


The device supports the [RDS](</kernel/userspace/userspace-api/media-v4l/dev-rds.md#rst-rds>) output interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_TUNER`

</td>
<td>


0x00010000

</td>
<td>


The device has some sort of tuner to receive RF-modulated video signals. For more information about tuner programming see [Tuners and Modulators](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>).

</td>
</tr>
<tr>
<td>


`V4L2_CAP_AUDIO`

</td>
<td>


0x00020000

</td>
<td>


The device has audio inputs or outputs. It may or may not support audio recording or playback, in PCM or compressed formats. PCM audio support must be implemented as ALSA or OSS interface. For more information on audio inputs and outputs see [Audio Inputs and Outputs](</kernel/userspace/userspace-api/media-v4l/audio.md#rst-audio>).

</td>
</tr>
<tr>
<td>


`V4L2_CAP_RADIO`

</td>
<td>


0x00040000

</td>
<td>


This is a radio receiver.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_MODULATOR`

</td>
<td>


0x00080000

</td>
<td>


The device has some sort of modulator to emit RF-modulated video/audio signals. For more information about modulator programming see [Tuners and Modulators](</kernel/userspace/userspace-api/media-v4l/tuner.md#rst-tuner>).

</td>
</tr>
<tr>
<td>


`V4L2_CAP_SDR_CAPTURE`

</td>
<td>


0x00100000

</td>
<td>


The device supports the [SDR Capture](</kernel/userspace/userspace-api/media-v4l/dev-sdr.md#rst-sdr>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_EXT_PIX_FORMAT`

</td>
<td>


0x00200000

</td>
<td>


The device supports the struct `v4l2_pix_format` extended fields.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_SDR_OUTPUT`

</td>
<td>


0x00400000

</td>
<td>


The device supports the [SDR Output](</kernel/userspace/userspace-api/media-v4l/dev-sdr.md#rst-sdr>) interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_META_CAPTURE`

</td>
<td>


0x00800000

</td>
<td>


The device supports the [Metadata Interface](</kernel/userspace/userspace-api/media-v4l/dev-meta.md#rst-metadata>) capture interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_READWRITE`

</td>
<td>


0x01000000

</td>
<td>


The device supports the `read()` and/or `write()` I/O methods.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_EDID`

</td>
<td>


0x02000000

</td>
<td>


The device stores the EDID for a video input, or retrieves the EDID for a video output. It is a standalone EDID device, so no video streaming etc. will take place.

For a video input this is typically an eeprom that supports the [VESA Enhanced Display Data Channel Standard](</kernel/userspace/userspace-api/media-v4l/biblio.md#rst-vesaeddc>). It can be something else as well, for example a micro controller.

For a video output this is typically read from an external device such as an HDMI splitter accessed by a serial port.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_STREAMING`

</td>
<td>


0x04000000

</td>
<td>


The device supports the [streaming](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) I/O method.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_META_OUTPUT`

</td>
<td>


0x08000000

</td>
<td>


The device supports the [Metadata Interface](</kernel/userspace/userspace-api/media-v4l/dev-meta.md#rst-metadata>) output interface.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_TOUCH`

</td>
<td>


0x10000000

</td>
<td>


This is a touch device.

</td>
</tr>
<tr>
<td>


`V4L2_CAP_IO_MC`

</td>
<td>


0x20000000

</td>
<td>


There is only one input and/or output seen from userspace. The whole video topology configuration, including which I/O entity is routed to the input/output, is configured by userspace via the Media Controller. See [Part IV - Media Controller API](</kernel/userspace/userspace-api/media-mediactl/media-controller.md#rst-media-controller>).

</td>
</tr>
<tr>
<td>


`V4L2_CAP_DEVICE_CAPS`

</td>
<td>


0x80000000

</td>
<td>


The driver fills the `device_caps` field. This capability can only appear in the `capabilities` field and never in the `device_caps` field.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

<a id="rst-f1"></a>



**[1]** The struct `v4l2_framebuffer` lacks an enum `v4l2_buf_type` field, therefore the type of overlay is implied by the driver capabilities.

---

# ioctls VIDIOC_QUERYCTRL, VIDIOC_QUERY_EXT_CTRL and VIDIOC_QUERYMENU

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_QUERYCTRL - VIDIOC_QUERY_EXT_CTRL - VIDIOC_QUERYMENU - Enumerate controls and menu control items

<a id="rst-ioctls-vidioc-queryctrl-vidioc-query-ext-ctrl-and-vidioc-querymenu"></a>
<a id="rst-vidioc-queryctrl"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC\_QUERYCTRL - VIDIOC\_QUERY\_EXT\_CTRL - VIDIOC\_QUERYMENU - Enumerate controls and menu control items

<a id="rst-synopsis"></a>

## Synopsis

<a id="c-VIDIOC_QUERY_CTRL"></a>



```c
VIDIOC_QUERY_CTRL
```

`int ioctl(int fd, int VIDIOC_QUERYCTRL, struct v4l2_queryctrl *argp)`

<a id="c-VIDIOC_QUERY_EXT_CTRL"></a>



```c
VIDIOC_QUERY_EXT_CTRL
```

`int ioctl(int fd, VIDIOC_QUERY_EXT_CTRL, struct v4l2_query_ext_ctrl *argp)`

<a id="c-VIDIOC_QUERYMENU"></a>



```c
VIDIOC_QUERYMENU
```

`int ioctl(int fd, VIDIOC_QUERYMENU, struct v4l2_querymenu *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_queryctrl`, `v4l2_query_ext_ctrl` or `v4l2_querymenu` (depending on the ioctl).

<a id="rst-description"></a>

## Description

To query the attributes of a control applications set the `id` field of a struct [v4l2\_queryctrl](<#rst-v4l2-queryctrl>) and call the `VIDIOC_QUERYCTRL` ioctl with a pointer to this structure. The driver fills the rest of the structure or returns an `EINVAL` error code when the `id` is invalid.

It is possible to enumerate controls by calling `VIDIOC_QUERYCTRL` with successive `id` values starting from `V4L2_CID_BASE` up to and exclusive `V4L2_CID_LASTP1`. Drivers may return `EINVAL` if a control in this range is not supported. Further applications can enumerate private controls, which are not defined in this specification, by starting at `V4L2_CID_PRIVATE_BASE` and incrementing `id` until the driver returns `EINVAL`.

In both cases, when the driver sets the `V4L2_CTRL_FLAG_DISABLED` flag in the `flags` field this control is permanently disabled and should be ignored by the application. <a id="rst-footnote-reference-1"></a>[1](#rst-f1)

When the application ORs `id` with `V4L2_CTRL_FLAG_NEXT_CTRL` the driver returns the next supported non-compound control, or `EINVAL` if there is none. In addition, the `V4L2_CTRL_FLAG_NEXT_COMPOUND` flag can be specified to enumerate all compound controls (i.e. controls with type ≥ `V4L2_CTRL_COMPOUND_TYPES` and/or array control, in other words controls that contain more than one value). Specify both `V4L2_CTRL_FLAG_NEXT_CTRL` and `V4L2_CTRL_FLAG_NEXT_COMPOUND` in order to enumerate all controls, compound or not. Drivers which do not support these flags yet always return `EINVAL`.

The `VIDIOC_QUERY_EXT_CTRL` ioctl was introduced in order to better support controls that can use compound types, and to expose additional control information that cannot be returned in struct [v4l2\_queryctrl](<#rst-v4l2-queryctrl>) since that structure is full.

`VIDIOC_QUERY_EXT_CTRL` is used in the same way as `VIDIOC_QUERYCTRL`, except that the `reserved` array must be zeroed as well.

Additional information is required for menu controls: the names of the menu items. To query them applications set the `id` and `index` fields of struct [v4l2\_querymenu](<#rst-v4l2-querymenu>) and call the `VIDIOC_QUERYMENU` ioctl with a pointer to this structure. The driver fills the rest of the structure or returns an `EINVAL` error code when the `id` or `index` is invalid. Menu items are enumerated by calling `VIDIOC_QUERYMENU` with successive `index` values from struct [v4l2\_queryctrl](<#rst-v4l2-queryctrl>) `minimum` to `maximum`, inclusive.

> [!NOTE]
>
> It is possible for `VIDIOC_QUERYMENU` to return an `EINVAL` error code for some indices between `minimum` and `maximum`. In that case that particular menu item is not supported by this driver. Also note that the `minimum` value is not necessarily 0.

See also the examples in [control](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control>).

<!-- tabularcolumns: |p{1.2cm}|p{3.6cm}|p{12.5cm}| -->

<a id="rst-v4l2-queryctrl"></a>

<a id="c-struct-v4l2_queryctrl"></a>



```c
v4l2_queryctrl
```


<table>
<caption>

struct v4l2\_queryctrl

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`id`

</td>
<td>



Identifies the control, set by the application. See [control-id](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control-id>) for predefined IDs. When the ID is ORed with V4L2\_CTRL\_FLAG\_NEXT\_CTRL the driver clears the flag and returns the first control with a higher ID. Drivers which do not support this flag yet always return an `EINVAL` error code.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`type`

</td>
<td>



Type of control, see `v4l2_ctrl_type`.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`name`\[32\]

</td>
<td>



Name of the control, a NUL-terminated ASCII string. This information is intended for the user.

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`minimum`

</td>
<td>



Minimum value, inclusive. This field gives a lower bound for the control. See enum `v4l2_ctrl_type` how the minimum value is to be used for each possible control type. Note that this a signed 32-bit value.

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`maximum`

</td>
<td>



Maximum value, inclusive. This field gives an upper bound for the control. See enum `v4l2_ctrl_type` how the maximum value is to be used for each possible control type. Note that this a signed 32-bit value.

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`step`

</td>
<td>



This field gives a step size for the control. See enum `v4l2_ctrl_type` how the step value is to be used for each possible control type. Note that this an unsigned 32-bit value.

Generally drivers should not scale hardware control values. It may be necessary for example when the `name` or `id` imply a particular unit and the hardware actually accepts only multiples of said unit. If so, drivers must take care values are properly rounded when scaling, such that errors will not accumulate on repeated read-write cycles.

This field gives the smallest change of an integer control actually affecting hardware. Often the information is needed when the user can change controls by keyboard or GUI buttons, rather than a slider. When for example a hardware register accepts values 0-511 and the driver reports 0-65535, step should be 128.

Note that although signed, the step value is supposed to be always positive.

</td>
</tr>
<tr>
<td>



\_\_s32

</td>
<td>



`default_value`

</td>
<td>



The default value of a `V4L2_CTRL_TYPE_INTEGER`, `_BOOLEAN`, `_BITMASK`, `_MENU` or `_INTEGER_MENU` control. Not valid for other types of controls.

> [!NOTE]
>
> Drivers reset controls to their default value only when the driver is first loaded, never afterwards.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



Control flags, see [control-flags](<#rst-control-flags>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`\[2\]

</td>
<td>



Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.2cm}|p{5.5cm}|p{10.6cm}| -->

<a id="rst-v4l2-query-ext-ctrl"></a>

<a id="c-struct-v4l2_query_ext_ctrl"></a>



```c
v4l2_query_ext_ctrl
```


<table>
<caption>

struct v4l2\_query\_ext\_ctrl

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`id`

</td>
<td>



Identifies the control, set by the application. See [control-id](</kernel/userspace/userspace-api/media-v4l/control.md#rst-control-id>) for predefined IDs. When the ID is ORed with `V4L2_CTRL_FLAG_NEXT_CTRL` the driver clears the flag and returns the first non-compound control with a higher ID. When the ID is ORed with `V4L2_CTRL_FLAG_NEXT_COMPOUND` the driver clears the flag and returns the first compound control with a higher ID. Set both to get the first control (compound or not) with a higher ID.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`type`

</td>
<td>



Type of control, see `v4l2_ctrl_type`.

</td>
</tr>
<tr>
<td>



char

</td>
<td>



`name`\[32\]

</td>
<td>



Name of the control, a NUL-terminated ASCII string. This information is intended for the user.

</td>
</tr>
<tr>
<td>



\_\_s64

</td>
<td>



`minimum`

</td>
<td>



Minimum value, inclusive. This field gives a lower bound for the control. See enum `v4l2_ctrl_type` how the minimum value is to be used for each possible control type. Note that this a signed 64-bit value.

</td>
</tr>
<tr>
<td>



\_\_s64

</td>
<td>



`maximum`

</td>
<td>



Maximum value, inclusive. This field gives an upper bound for the control. See enum `v4l2_ctrl_type` how the maximum value is to be used for each possible control type. Note that this a signed 64-bit value.

</td>
</tr>
<tr>
<td>



\_\_u64

</td>
<td>



`step`

</td>
<td>



This field gives a step size for the control. See enum `v4l2_ctrl_type` how the step value is to be used for each possible control type. Note that this an unsigned 64-bit value.

Generally drivers should not scale hardware control values. It may be necessary for example when the `name` or `id` imply a particular unit and the hardware actually accepts only multiples of said unit. If so, drivers must take care values are properly rounded when scaling, such that errors will not accumulate on repeated read-write cycles.

This field gives the smallest change of an integer control actually affecting hardware. Often the information is needed when the user can change controls by keyboard or GUI buttons, rather than a slider. When for example a hardware register accepts values 0-511 and the driver reports 0-65535, step should be 128.

</td>
</tr>
<tr>
<td>



\_\_s64

</td>
<td>



`default_value`

</td>
<td>



The default value of a `V4L2_CTRL_TYPE_INTEGER`, `_INTEGER64`, `_BOOLEAN`, `_BITMASK`, `_MENU`, `_INTEGER_MENU`, `_U8` or `_U16` control. Not valid for other types of controls.

> [!NOTE]
>
> Drivers reset controls to their default value only when the driver is first loaded, never afterwards.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



Control flags, see [control-flags](<#rst-control-flags>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`elem_size`

</td>
<td>



The size in bytes of a single element of the array. Given a char pointer `p` to a 3-dimensional array you can find the position of cell `(z, y, x)` as follows: `p + ((z * dims[1] + y) * dims[0] + x) * elem_size`. `elem_size` is always valid, also when the control isn't an array. For string controls `elem_size` is equal to `maximum + 1`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`elems`

</td>
<td>



The number of elements in the N-dimensional array. If this control is not an array, then `elems` is 1. The `elems` field can never be 0.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`nr_of_dims`

</td>
<td>



The number of dimension in the N-dimensional array. If this control is not an array, then this field is 0.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`dims[V4L2_CTRL_MAX_DIMS]`

</td>
<td>



The size of each dimension. The first `nr_of_dims` elements of this array must be non-zero, all remaining elements must be zero.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`\[32\]

</td>
<td>



Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{1.2cm}|p{3.0cm}|p{13.1cm}| -->

<a id="rst-v4l2-querymenu"></a>

<a id="c-struct-v4l2_querymenu"></a>



```c
v4l2_querymenu
```


<table>
<caption>

struct v4l2\_querymenu

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`id`

</td>
<td>



Identifies the control, set by the application from the respective struct [v4l2\_queryctrl](<#rst-v4l2-queryctrl>) `id`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`index`

</td>
<td>



Index of the menu item, starting at zero, set by the application.

</td>
</tr>
<tr>
<td>



union \{

</td>
<td colspan="2">



(anonymous)

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`name`\[32\]

</td>
<td>



Name of the menu item, a NUL-terminated ASCII string. This information is intended for the user. This field is valid for `V4L2_CTRL_TYPE_MENU` type controls.

</td>
</tr>
<tr>
<td>



\_\_s64

</td>
<td>



`value`

</td>
<td>



Value of the integer menu item. This field is valid for `V4L2_CTRL_TYPE_INTEGER_MENU` type controls.

</td>
</tr>
<tr>
<td>



\}

</td>
<td colspan="2">





</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`

</td>
<td>



Reserved for future extensions. Drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="c-v4l2_ctrl_type"></a>



```c
v4l2_ctrl_type
```

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{6.5cm}|p{1.5cm}|p{1.1cm}|p{1.5cm}|p{6.8cm}| -->


<table>
<caption>

enum v4l2\_ctrl\_type

</caption>
<thead>
<tr>
<th>



Type

</th>
<th>



`minimum`

</th>
<th>



`step`

</th>
<th>



`maximum`

</th>
<th>



Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>



`V4L2_CTRL_TYPE_INTEGER`

</td>
<td>



any

</td>
<td>



any

</td>
<td>



any

</td>
<td>



An integer-valued control ranging from minimum to maximum inclusive. The step value indicates the increment between values.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_BOOLEAN`

</td>
<td>



0

</td>
<td>



1

</td>
<td>



1

</td>
<td>



A boolean-valued control. Zero corresponds to "disabled", and one means "enabled".

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_MENU`

</td>
<td>



≥ 0

</td>
<td>



1

</td>
<td>



N-1

</td>
<td>



The control has a menu of N choices. The names of the menu items can be enumerated with the `VIDIOC_QUERYMENU` ioctl.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_INTEGER_MENU`

</td>
<td>



≥ 0

</td>
<td>



1

</td>
<td>



N-1

</td>
<td>



The control has a menu of N choices. The values of the menu items can be enumerated with the `VIDIOC_QUERYMENU` ioctl. This is similar to `V4L2_CTRL_TYPE_MENU` except that instead of strings, the menu items are signed 64-bit integers.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_BITMASK`

</td>
<td>



0

</td>
<td>



n/a

</td>
<td>



any

</td>
<td>



A bitmask field. The maximum value is the set of bits that can be used, all other bits are to be 0. The maximum value is interpreted as a \_\_u32, allowing the use of bit 31 in the bitmask.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_BUTTON`

</td>
<td>



0

</td>
<td>



0

</td>
<td>



0

</td>
<td>



A control which performs an action when set. Drivers must ignore the value passed with `VIDIOC_S_CTRL` and return an `EACCES` error code on a `VIDIOC_G_CTRL` attempt.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_INTEGER64`

</td>
<td>



any

</td>
<td>



any

</td>
<td>



any

</td>
<td>



A 64-bit integer valued control. Minimum, maximum and step size cannot be queried using `VIDIOC_QUERYCTRL`. Only `VIDIOC_QUERY_EXT_CTRL` can retrieve the 64-bit min/max/step values, they should be interpreted as n/a when using `VIDIOC_QUERYCTRL`.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_STRING`

</td>
<td>



≥ 0

</td>
<td>



≥ 1

</td>
<td>



≥ 0

</td>
<td>



The minimum and maximum string lengths. The step size means that the string must be (minimum + N \* step) characters long for N ≥ 0. These lengths do not include the terminating zero, so in order to pass a string of length 8 to [VIDIOC\_S\_EXT\_CTRLS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-vidioc-g-ext-ctrls>) you need to set the `size` field of struct `v4l2_ext_control` to 9. For [VIDIOC\_G\_EXT\_CTRLS](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-vidioc-g-ext-ctrls>) you can set the `size` field to `maximum` + 1. Which character encoding is used will depend on the string control itself and should be part of the control documentation.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_CTRL_CLASS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



This is not a control. When `VIDIOC_QUERYCTRL` is called with a control ID equal to a control class code (see [ctrl-class](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ext-ctrls.md#rst-ctrl-class>)) + 1, the ioctl returns the name of the control class and this control type. Older drivers which do not support this feature return an `EINVAL` error code.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_U8`

</td>
<td>



any

</td>
<td>



any

</td>
<td>



any

</td>
<td>



An unsigned 8-bit valued control ranging from minimum to maximum inclusive. The step value indicates the increment between values.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_U16`

</td>
<td>



any

</td>
<td>



any

</td>
<td>



any

</td>
<td>



An unsigned 16-bit valued control ranging from minimum to maximum inclusive. The step value indicates the increment between values.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_U32`

</td>
<td>



any

</td>
<td>



any

</td>
<td>



any

</td>
<td>



An unsigned 32-bit valued control ranging from minimum to maximum inclusive. The step value indicates the increment between values.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_MPEG2_QUANTISATION`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_mpeg2_quantisation`, containing MPEG-2 quantisation matrices for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_MPEG2_SEQUENCE`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_mpeg2_sequence`, containing MPEG-2 sequence parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_MPEG2_PICTURE`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_mpeg2_picture`, containing MPEG-2 picture parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_AREA`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_area`, containing the width and the height of a rectangular area. Units depend on the use case.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_RECT`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_rect`, containing a rectangle described by the position of its top-left corner, the width and the height. Units depend on the use case. Support for `V4L2_CTRL_WHICH_MIN_VAL` and `V4L2_CTRL_WHICH_MAX_VAL` is optional and depends on the `V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX` flag. See the documentation of the specific control on how to interpret the minimum and maximum values.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_H264_SPS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_h264_sps`, containing H264 sequence parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_H264_PPS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_h264_pps`, containing H264 picture parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_H264_SCALING_MATRIX`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_h264_scaling_matrix`, containing H264 scaling matrices for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_H264_SLICE_PARAMS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_h264_slice_params`, containing H264 slice parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_H264_DECODE_PARAMS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_h264_decode_params`, containing H264 decode parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_FWHT_PARAMS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_fwht_params`, containing FWHT parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_HEVC_SPS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_hevc_sps`, containing HEVC Sequence Parameter Set for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_HEVC_PPS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_hevc_pps`, containing HEVC Picture Parameter Set for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_hevc_slice_params`, containing HEVC slice parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_hevc_scaling_matrix`, containing HEVC scaling matrix for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_VP8_FRAME`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_vp8_frame`, containing VP8 frame parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_hevc_decode_params`, containing HEVC decoding parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_HEVC_EXT_SPS_LT_RPS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_hevc_ext_sps_lt_rps`, containing HEVC extended Long-Term RPS for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_HEVC_EXT_SPS_ST_RPS`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_hevc_ext_sps_st_rps`, containing HEVC extended Short-Term RPS for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_VP9_COMPRESSED_HDR`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_vp9_compressed_hdr`, containing VP9 probabilities updates for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_VP9_FRAME`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_vp9_frame`, containing VP9 frame decode parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_AV1_SEQUENCE`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_av1_sequence`, containing AV1 Sequence OBU decoding parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_AV1_TILE_GROUP_ENTRY`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_av1_tile_group_entry`, containing AV1 Tile Group OBU decoding parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_AV1_FRAME`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_av1_frame`, containing AV1 Frame/Frame Header OBU decoding parameters for stateless video decoders.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_TYPE_AV1_FILM_GRAIN`

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



n/a

</td>
<td>



A struct `v4l2_ctrl_av1_film_grain`, containing AV1 Film Grain parameters for stateless video decoders.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<!-- tabularcolumns: |p{7.3cm}|p{1.8cm}|p{8.2cm}| -->

<a id="rst-control-flags"></a>


<table>
<caption>

Control Flags

</caption>
<tbody>
<tr>
<td>



`V4L2_CTRL_FLAG_DISABLED`

</td>
<td>



0x0001

</td>
<td>



This control is permanently disabled and should be ignored by the application. Any attempt to change the control will result in an `EINVAL` error code.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_GRABBED`

</td>
<td>



0x0002

</td>
<td>



This control is temporarily unchangeable, for example because another application took over control of the respective resource. Such controls may be displayed specially in a user interface. Attempts to change the control may result in an `EBUSY` error code.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_READ_ONLY`

</td>
<td>



0x0004

</td>
<td>



This control is permanently readable only. Any attempt to change the control will result in an `EINVAL` error code.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_UPDATE`

</td>
<td>



0x0008

</td>
<td>



A hint that changing this control may affect the value of other controls within the same control class. Applications should update their user interface accordingly.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_INACTIVE`

</td>
<td>



0x0010

</td>
<td>



This control is not applicable to the current configuration and should be displayed accordingly in a user interface. For example the flag may be set on a MPEG audio level 2 bitrate control when MPEG audio encoding level 1 was selected with another control.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_SLIDER`

</td>
<td>



0x0020

</td>
<td>



A hint that this control is best represented as a slider-like element in a user interface.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_WRITE_ONLY`

</td>
<td>



0x0040

</td>
<td>



This control is permanently writable only. Any attempt to read the control will result in an `EACCES` error code error code. This flag is typically present for relative controls or action controls where writing a value will cause the device to carry out a given action (e. g. motor control) but no meaningful value can be returned.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_VOLATILE`

</td>
<td>



0x0080

</td>
<td>



This control is volatile, which means that the value of the control changes continuously. A typical example would be the current gain value if the device is in auto-gain mode. In such a case the hardware calculates the gain value based on the lighting conditions which can change over time.

> [!NOTE]
>
> Setting a new value for a volatile control will be ignored unless [V4L2\_CTRL\_FLAG\_EXECUTE\_ON\_WRITE](<#rst-flag-execute-on-write>) is also set. Setting a new value for a volatile control will <em>never</em> trigger a [V4L2\_EVENT\_CTRL\_CH\_VALUE](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-ctrl-changes-flags>) event.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_HAS_PAYLOAD`

</td>
<td>



0x0100

</td>
<td>



This control has a pointer type, so its value has to be accessed using one of the pointer fields of struct `v4l2_ext_control`. This flag is set for controls that are an array, string, or have a compound type. In all cases you have to set a pointer to memory containing the payload of the control.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_EXECUTE_ON_WRITE`

</td>
<td>



0x0200

</td>
<td>



<a id="rst-flag-execute-on-write"></a>

The value provided to the control will be propagated to the driver even if it remains constant. This is required when the control represents an action on the hardware. For example: clearing an error flag or triggering the flash. All the controls of the type `V4L2_CTRL_TYPE_BUTTON` have this flag set.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_MODIFY_LAYOUT`

</td>
<td>



0x0400

</td>
<td>



<a id="rst-flag-modify-layout"></a>

Changing this control value may modify the layout of the buffer (for video devices) or the media bus format (for sub-devices).

A typical example would be the `V4L2_CID_ROTATE` control.

Note that typically controls with this flag will also set the `V4L2_CTRL_FLAG_GRABBED` flag when buffers are allocated or streaming is in progress since most drivers do not support changing the format in that case.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_DYNAMIC_ARRAY`

</td>
<td>



0x0800

</td>
<td>



This control is a dynamically sized 1-dimensional array. It behaves the same as a regular array, except that the number of elements as reported by the `elems` field is between 1 and `dims[0]`. So setting the control with a differently sized array will change the `elems` field when the control is queried afterwards.

</td>
</tr>
<tr>
<td>



`V4L2_CTRL_FLAG_HAS_WHICH_MIN_MAX`

</td>
<td>



0x1000

</td>
<td>



This control supports getting minimum and maximum values using vidioc\_g\_ext\_ctrls with V4L2\_CTRL\_WHICH\_MIN/MAX\_VAL.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct [v4l2\_queryctrl](<#rst-v4l2-queryctrl>) `id` is invalid. The struct [v4l2\_querymenu](<#rst-v4l2-querymenu>) `id` is invalid or `index` is out of range (less than `minimum` or greater than `maximum`) or this particular menu item is not supported by the driver.

- **EACCES**

  An attempt was made to read a write-only control.

<a id="rst-f1"></a>



**[1]** `V4L2_CTRL_FLAG_DISABLED` was intended for two purposes: Drivers can skip predefined controls not supported by the hardware (although returning `EINVAL` would do as well), or disable predefined and private controls after hardware detection without the trouble of reordering control arrays and indices (`EINVAL` cannot be used to skip private controls because it would prematurely end the enumeration).

---

# ioctl VIDIOC_QUERYSTD, VIDIOC_SUBDEV_QUERYSTD

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_QUERYSTD - VIDIOC_SUBDEV_QUERYSTD - Sense the video standard received by the current input

<a id="rst-ioctl-vidioc-querystd-vidioc-subdev-querystd"></a>
<a id="rst-vidioc-querystd"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_QUERYSTD - VIDIOC_SUBDEV_QUERYSTD - Sense the video standard received by the current input

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_QUERYSTD"></a>

```c
VIDIOC_QUERYSTD
```

`int ioctl(int fd, VIDIOC_QUERYSTD, v4l2_std_id *argp)`





<a id="c-VIDIOC_SUBDEV_QUERYSTD"></a>

```c
VIDIOC_SUBDEV_QUERYSTD
```

`int ioctl(int fd, VIDIOC_SUBDEV_QUERYSTD, v4l2_std_id *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to `v4l2_std_id`.

<a id="rst-description"></a>

## Description

The hardware may be able to detect the current video standard automatically. To do so, applications call [ioctl VIDIOC_QUERYSTD, VIDIOC_SUBDEV_QUERYSTD](<#rst-vidioc-querystd>) with a pointer to a [v4l2_std_id](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-enumstd.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) type. The driver stores here a set of candidates, this can be a single flag or a set of supported standards if for example the hardware can only distinguish between 50 and 60 Hz systems. If no signal was detected, then the driver will return V4L2_STD_UNKNOWN. When detection is not possible or fails, the set must contain all standards supported by the current video input or output.

> [!NOTE]
>
> Drivers shall *not* switch the video standard automatically if a new video standard is detected. Instead, drivers should send the `V4L2_EVENT_SOURCE_CHANGE` event (if they support this) and expect that userspace will take action by calling [ioctl VIDIOC_QUERYSTD, VIDIOC_SUBDEV_QUERYSTD](<#rst-vidioc-querystd>). The reason is that a new video standard can mean different buffer sizes as well, and you cannot change buffer sizes on the fly. In general, applications that receive the Source Change event will have to call [ioctl VIDIOC_QUERYSTD, VIDIOC_SUBDEV_QUERYSTD](<#rst-vidioc-querystd>), and if the detected video standard is valid they will have to stop streaming, set the new standard, allocate new buffers and start streaming again.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **ENODATA**

  Standard video timings are not supported for this input or output.

---

# ioctl VIDIOC_REMOVE_BUFS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_REMOVE_BUFS - Removes buffers from a queue

<a id="rst-ioctl-vidioc-remove-bufs"></a>
<a id="rst-vidioc-remove-bufs"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_REMOVE_BUFS - Removes buffers from a queue

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_REMOVE_BUFS"></a>

```c
VIDIOC_REMOVE_BUFS
```

`int ioctl(int fd, VIDIOC_REMOVE_BUFS, struct v4l2_remove_buffers *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_remove_buffers`.

<a id="rst-description"></a>

## Description

Applications can optionally call the [ioctl VIDIOC_REMOVE_BUFS](<#rst-vidioc-remove-bufs>) ioctl to remove buffers from a queue. [ioctl VIDIOC_CREATE_BUFS](</kernel/userspace/userspace-api/media-v4l/vidioc-create-bufs.md#rst-vidioc-create-bufs>) ioctl support is mandatory to enable [ioctl VIDIOC_REMOVE_BUFS](<#rst-vidioc-remove-bufs>). This ioctl is available if the `V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS` capability is set on the queue when `VIDIOC_REQBUFS()` or `VIDIOC_CREATE_BUFS()` are invoked.





<a id="c-v4l2_remove_buffers"></a>

```c
v4l2_remove_buffers
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_remove_buffers</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


The starting buffer index to remove. This field is ignored if count == 0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`count`

</td>
<td>


The number of buffers to be removed with indices 'index' until 'index + count - 1'. All buffers in this range must be valid and in DEQUEUED state. [ioctl VIDIOC_REMOVE_BUFS](<#rst-vidioc-remove-bufs>) will always check the validity of `type`, if it is invalid it returns `EINVAL` error code. If count is set to 0 [ioctl VIDIOC_REMOVE_BUFS](<#rst-vidioc-remove-bufs>) will do nothing and return 0.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the stream or buffers, this is the same as the struct `v4l2_format` `type` field. See `v4l2_buf_type` for valid values.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[13\]

</td>
<td>


A place holder for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter. If an error occurs, no buffers will be freed and one of the error codes below will be returned:

- **EBUSY**

  File I/O is in progress. One or more of the buffers in the range `index` to `index + count - 1` are not in DEQUEUED state.

- **EINVAL**

  One or more of the buffers in the range `index` to `index + count - 1` do not exist in the queue. The buffer type (`type` field) is not valid.

---

# ioctl VIDIOC_REQBUFS

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_REQBUFS - Initiate Memory Mapping, User Pointer I/O or DMA buffer I/O

<a id="rst-ioctl-vidioc-reqbufs"></a>
<a id="rst-vidioc-reqbufs"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC\_REQBUFS - Initiate Memory Mapping, User Pointer I/O or DMA buffer I/O

<a id="rst-synopsis"></a>

## Synopsis

<a id="c-VIDIOC_REQBUFS"></a>



```c
VIDIOC_REQBUFS
```

`int ioctl(int fd, VIDIOC_REQBUFS, struct v4l2_requestbuffers *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_requestbuffers`.

<a id="rst-description"></a>

## Description

This ioctl is used to initiate [memory mapped](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>), [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>) or [DMABUF](</kernel/userspace/userspace-api/media-v4l/dmabuf.md#rst-dmabuf>) based I/O. Memory mapped buffers are located in device memory and must be allocated with this ioctl before they can be mapped into the application's address space. User buffers are allocated by applications themselves, and this ioctl is merely used to switch the driver into user pointer I/O mode and to setup some internal structures. Similarly, DMABUF buffers are allocated by applications through a device driver, and this ioctl only configures the driver into DMABUF I/O mode without performing any direct allocation.

To allocate device buffers applications initialize all fields of the struct `v4l2_requestbuffers` structure. They set the `type` field to the respective stream or buffer type, the `count` field to the desired number of buffers, `memory` must be set to the requested I/O method and the `reserved` array must be zeroed. When the ioctl is called with a pointer to this structure the driver will attempt to allocate the requested number of buffers and it stores the actual number allocated in the `count` field. It can be smaller than the number requested, even zero, when the driver runs out of free memory. A larger number is also possible when the driver requires more buffers to function correctly. For example video output requires at least two buffers, one displayed and one filled by the application.

When the I/O method is not supported the ioctl returns an `EINVAL` error code.

Applications can call [ioctl VIDIOC\_REQBUFS](<#rst-vidioc-reqbufs>) again to change the number of buffers. Note that if any buffers are still mapped or exported via DMABUF, then [ioctl VIDIOC\_REQBUFS](<#rst-vidioc-reqbufs>) can only succeed if the `V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS` capability is set. Otherwise [ioctl VIDIOC\_REQBUFS](<#rst-vidioc-reqbufs>) will return the `EBUSY` error code. If `V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS` is set, then these buffers are orphaned and will be freed when they are unmapped or when the exported DMABUF fds are closed. A `count` value of zero frees or orphans all buffers, after aborting or finishing any DMA in progress, an implicit [VIDIOC\_STREAMOFF](</kernel/userspace/userspace-api/media-v4l/vidioc-streamon.md#rst-vidioc-streamon>).

<a id="c-v4l2_requestbuffers"></a>



```c
v4l2_requestbuffers
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>

struct v4l2\_requestbuffers

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`count`

</td>
<td>



The number of buffers requested or granted.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`type`

</td>
<td>



Type of the stream or buffers, this is the same as the struct `v4l2_format` `type` field. See `v4l2_buf_type` for valid values.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`memory`

</td>
<td>



Applications set this field to `V4L2_MEMORY_MMAP`, `V4L2_MEMORY_DMABUF` or `V4L2_MEMORY_USERPTR`. See `v4l2_memory`.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`capabilities`

</td>
<td>



Set by the driver. If 0, then the driver doesn't support capabilities. In that case all you know is that the driver is guaranteed to support `V4L2_MEMORY_MMAP` and <em>might</em> support other `v4l2_memory` types. It will not support any other capabilities.

If you want to query the capabilities with a minimum of side-effects, then this can be called with `count` set to 0, `memory` set to `V4L2_MEMORY_MMAP` and `type` set to the buffer type. This will free any previously allocated buffers, so this is typically something that will be done at the start of the application.

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`flags`

</td>
<td>



Specifies additional buffer management attributes. See [memory-flags](<#rst-memory-flags>).

</td>
</tr>
<tr>
<td>



\_\_u8

</td>
<td>



`reserved`\[3\]

</td>
<td>



Reserved for future extensions.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-buf-cap-supports-remove-bufs"></a>
<a id="rst-v4l2-buf-cap-supports-max-num-buffers"></a>
<a id="rst-v4l2-buf-cap-supports-mmap-cache-hints"></a>
<a id="rst-v4l2-buf-cap-supports-m2m-hold-capture-buf"></a>
<a id="rst-v4l2-buf-cap-supports-orphaned-bufs"></a>
<a id="rst-v4l2-buf-cap-supports-requests"></a>
<a id="rst-v4l2-buf-cap-supports-dmabuf"></a>
<a id="rst-v4l2-buf-cap-supports-userptr"></a>
<a id="rst-v4l2-buf-cap-supports-mmap"></a>
<a id="rst-v4l2-buf-capabilities"></a>


<table>
<caption>

V4L2 Buffer Capabilities Flags

</caption>
<tbody>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_MMAP`

</td>
<td>



0x00000001

</td>
<td>



This buffer type supports the `V4L2_MEMORY_MMAP` streaming mode.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_USERPTR`

</td>
<td>



0x00000002

</td>
<td>



This buffer type supports the `V4L2_MEMORY_USERPTR` streaming mode.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_DMABUF`

</td>
<td>



0x00000004

</td>
<td>



This buffer type supports the `V4L2_MEMORY_DMABUF` streaming mode.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_REQUESTS`

</td>
<td>



0x00000008

</td>
<td>



This buffer type supports [requests](</kernel/userspace/userspace-api/media-mediactl/request-api.md#rst-media-request-api>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`

</td>
<td>



0x00000010

</td>
<td>



The kernel allows calling [ioctl VIDIOC\_REQBUFS](<#rst-vidioc-reqbufs>) while buffers are still mapped or exported via DMABUF. These orphaned buffers will be freed when they are unmapped or when the exported DMABUF fds are closed.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF`

</td>
<td>



0x00000020

</td>
<td>



Only valid for stateless decoders. If set, then userspace can set the `V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF` flag to hold off on returning the capture buffer until the OUTPUT timestamp changes.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS`

</td>
<td>



0x00000040

</td>
<td>



This capability is set by the driver to indicate that the queue supports cache and memory management hints. However, it's only valid when the queue is used for [memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) streaming I/O. See [V4L2\_BUF\_FLAG\_NO\_CACHE\_INVALIDATE](</kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-no-cache-invalidate>), [V4L2\_BUF\_FLAG\_NO\_CACHE\_CLEAN](</kernel/userspace/userspace-api/media-v4l/buffer.md#rst-v4l2-buf-flag-no-cache-clean>) and [V4L2\_MEMORY\_FLAG\_NON\_COHERENT](<#rst-v4l2-memory-flag-non-coherent>).

</td>
</tr>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS`

</td>
<td>



0x00000080

</td>
<td>



If set, then the `max_num_buffers` field in `struct v4l2_create_buffers` is valid. If not set, then the maximum is `VIDEO_MAX_FRAME` buffers.

</td>
</tr>
<tr>
<td>



`V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS`

</td>
<td>



0x00000100

</td>
<td>



If set, then `VIDIOC_REMOVE_BUFS` is supported.

</td>
</tr>
</tbody>
</table>

<a id="rst-v4l2-memory-flag-non-coherent"></a>
<a id="rst-memory-flags"></a>


<table>
<caption>

Memory Consistency Flags

</caption>
<tbody>
<tr>
<td>



`V4L2_MEMORY_FLAG_NON_COHERENT`

</td>
<td>



0x00000001

</td>
<td>



A buffer is allocated either in coherent (it will be automatically coherent between the CPU and the bus) or non-coherent memory. The latter can provide performance gains, for instance the CPU cache sync/flush operations can be avoided if the buffer is accessed by the corresponding device only and the CPU does not read/write to/from that buffer. However, this requires extra care from the driver -- it must guarantee memory consistency by issuing a cache flush/sync when consistency is needed. If this flag is set V4L2 will attempt to allocate the buffer in non-coherent memory. The flag takes effect only if the buffer is used for [memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>) I/O and the queue reports the [V4L2\_BUF\_CAP\_SUPPORTS\_MMAP\_CACHE\_HINTS](<#rst-v4l2-buf-cap-supports-mmap-cache-hints>) capability.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The buffer type (`type` field) or the requested I/O method (`memory`) is not supported.

---

# ioctl VIDIOC_S_HW_FREQ_SEEK

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_S_HW_FREQ_SEEK - Perform a hardware frequency seek

<a id="rst-ioctl-vidioc-s-hw-freq-seek"></a>
<a id="rst-vidioc-s-hw-freq-seek"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_S_HW_FREQ_SEEK - Perform a hardware frequency seek

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_S_HW_FREQ_SEEK"></a>

```c
VIDIOC_S_HW_FREQ_SEEK
```

`int ioctl(int fd, VIDIOC_S_HW_FREQ_SEEK, struct v4l2_hw_freq_seek *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_hw_freq_seek`.

<a id="rst-description"></a>

## Description

Start a hardware frequency seek from the current frequency. To do this applications initialize the `tuner`, `type`, `seek_upward`, `wrap_around`, `spacing`, `rangelow` and `rangehigh` fields, and zero out the `reserved` array of a struct `v4l2_hw_freq_seek` and call the `VIDIOC_S_HW_FREQ_SEEK` ioctl with a pointer to this structure.

The `rangelow` and `rangehigh` fields can be set to a non-zero value to tell the driver to search a specific band. If the struct `v4l2_tuner` `capability` field has the `V4L2_TUNER_CAP_HWSEEK_PROG_LIM` flag set, these values must fall within one of the bands returned by [ioctl VIDIOC_ENUM_FREQ_BANDS](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#rst-vidioc-enum-freq-bands>). If the `V4L2_TUNER_CAP_HWSEEK_PROG_LIM` flag is not set, then these values must exactly match those of one of the bands returned by [ioctl VIDIOC_ENUM_FREQ_BANDS](</kernel/userspace/userspace-api/media-v4l/vidioc-enum-freq-bands.md#rst-vidioc-enum-freq-bands>). If the current frequency of the tuner does not fall within the selected band it will be clamped to fit in the band before the seek is started.

If an error is returned, then the original frequency will be restored.

This ioctl is supported if the `V4L2_CAP_HW_FREQ_SEEK` capability is set.

If this ioctl is called from a non-blocking filehandle, then `EAGAIN` error code is returned and no seek takes place.

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_hw_freq_seek"></a>

```c
v4l2_hw_freq_seek
```


<table>
<caption>struct v4l2_hw_freq_seek</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`tuner`

</td>
<td>


The tuner index number. This is the same value as in the struct `v4l2_input` `tuner` field and the struct `v4l2_tuner` `index` field.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


The tuner type. This is the same value as in the struct `v4l2_tuner` `type` field. See `v4l2_tuner_type`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`seek_upward`

</td>
<td>


If non-zero, seek upward from the current frequency, else seek downward.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`wrap_around`

</td>
<td>


If non-zero, wrap around when at the end of the frequency range, else stop seeking. The struct `v4l2_tuner` `capability` field will tell you what the hardware supports.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`spacing`

</td>
<td>


If non-zero, defines the hardware seek resolution in Hz. The driver selects the nearest value that is supported by the device. If spacing is zero a reasonable default value is used.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`rangelow`

</td>
<td>


If non-zero, the lowest tunable frequency of the band to search in units of 62.5 kHz, or if the struct `v4l2_tuner` `capability` field has the `V4L2_TUNER_CAP_LOW` flag set, in units of 62.5 Hz or if the struct `v4l2_tuner` `capability` field has the `V4L2_TUNER_CAP_1HZ` flag set, in units of 1 Hz. If `rangelow` is zero a reasonable default value is used.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`rangehigh`

</td>
<td>


If non-zero, the highest tunable frequency of the band to search in units of 62.5 kHz, or if the struct `v4l2_tuner` `capability` field has the `V4L2_TUNER_CAP_LOW` flag set, in units of 62.5 Hz or if the struct `v4l2_tuner` `capability` field has the `V4L2_TUNER_CAP_1HZ` flag set, in units of 1 Hz. If `rangehigh` is zero a reasonable default value is used.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[5\]

</td>
<td>


Reserved for future extensions. Applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The `tuner` index is out of bounds, the `wrap_around` value is not supported or one of the values in the `type`, `rangelow` or `rangehigh` fields is wrong.

- **EAGAIN**

  Attempted to call `VIDIOC_S_HW_FREQ_SEEK` with the filehandle in non-blocking mode.

- **ENODATA**

  The hardware seek found no channels.

- **EBUSY**

  Another hardware seek is already in progress.

---

# ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_STREAMON - VIDIOC_STREAMOFF - Start or stop streaming I/O

<a id="rst-ioctl-vidioc-streamon-vidioc-streamoff"></a>
<a id="rst-vidioc-streamon"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_STREAMON - VIDIOC_STREAMOFF - Start or stop streaming I/O

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_STREAMON"></a>

```c
VIDIOC_STREAMON
```

`int ioctl(int fd, VIDIOC_STREAMON, const int *argp)`





<a id="c-VIDIOC_STREAMOFF"></a>

```c
VIDIOC_STREAMOFF
```

`int ioctl(int fd, VIDIOC_STREAMOFF, const int *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to an integer.

<a id="rst-description"></a>

## Description

The `VIDIOC_STREAMON` and `VIDIOC_STREAMOFF` ioctl start and stop the capture or output process during streaming ([memory mapping](</kernel/userspace/userspace-api/media-v4l/mmap.md#rst-mmap>), [user pointer](</kernel/userspace/userspace-api/media-v4l/userp.md#rst-userp>) or [DMABUF](</kernel/userspace/userspace-api/media-v4l/dmabuf.md#rst-dmabuf>)) I/O.

Capture hardware is disabled and no input buffers are filled (if there are any empty buffers in the incoming queue) until `VIDIOC_STREAMON` has been called. Output hardware is disabled and no video signal is produced until `VIDIOC_STREAMON` has been called.

Memory-to-memory devices will not start until `VIDIOC_STREAMON` has been called for both the capture and output stream types.

If `VIDIOC_STREAMON` fails then any already queued buffers will remain queued.

The `VIDIOC_STREAMOFF` ioctl, apart of aborting or finishing any DMA in progress, unlocks any user pointer buffers locked in physical memory, and it removes all buffers from the incoming and outgoing queues. That means all images captured but not dequeued yet will be lost, likewise all images enqueued for output but not transmitted yet. I/O returns to the same state as after calling [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and can be restarted accordingly.

If buffers have been queued with [ioctl VIDIOC_QBUF, VIDIOC_DQBUF](</kernel/userspace/userspace-api/media-v4l/vidioc-qbuf.md#rst-vidioc-qbuf>) and `VIDIOC_STREAMOFF` is called without ever having called `VIDIOC_STREAMON`, then those queued buffers will also be removed from the incoming queue and all are returned to the same state as after calling [vidioc_reqbufs](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and can be restarted accordingly.

Both ioctls take a pointer to an integer, the desired buffer or stream type. This is the same as struct `v4l2_requestbuffers` `type`.

If `VIDIOC_STREAMON` is called when streaming is already in progress, or if `VIDIOC_STREAMOFF` is called when streaming is already stopped, then 0 is returned. Nothing happens in the case of `VIDIOC_STREAMON`, but `VIDIOC_STREAMOFF` will return queued buffers to their starting state as mentioned above.

> [!NOTE]
>
> Applications can be preempted for unknown periods right before or after the `VIDIOC_STREAMON` or `VIDIOC_STREAMOFF` calls, there is no notion of starting or stopping "now". Buffer timestamps can be used to synchronize with other events.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The buffer `type` is not supported, or no buffers have been allocated (memory mapping) or enqueued (output) yet.

- **EPIPE**

  The driver implements [pad-level format configuration](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-subdev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) and the pipeline configuration is invalid.

- **ENOLINK**

  The driver implements Media Controller interface and the pipeline link configuration is invalid.

---

# ioctl VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL - Enumerate frame intervals

<a id="rst-ioctl-vidioc-subdev-enum-frame-interval"></a>
<a id="rst-vidioc-subdev-enum-frame-interval"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL - Enumerate frame intervals

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL"></a>

```c
VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL
```

`int ioctl(int fd, VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL, struct v4l2_subdev_frame_interval_enum * argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_subdev_frame_interval_enum`.

<a id="rst-description"></a>

## Description

This ioctl lets applications enumerate available frame intervals on a given sub-device pad. Frame intervals only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners.

For the common use case of image sensors, the frame intervals available on the sub-device output pad depend on the frame format and size on the same pad. Applications must thus specify the desired format and size when enumerating frame intervals.

To enumerate frame intervals applications initialize the `index`, `pad`, `which`, `code`, `width` and `height` fields of struct `v4l2_subdev_frame_interval_enum` and call the [ioctl VIDIOC_SUBDEV_ENUM_FRAME_INTERVAL](<#rst-vidioc-subdev-enum-frame-interval>) ioctl with a pointer to this structure. Drivers fill the rest of the structure or return an EINVAL error code if one of the input fields is invalid. All frame intervals are enumerable by beginning at index zero and incrementing by one until `EINVAL` is returned.

Available frame intervals may depend on the current 'try' formats at other pads of the sub-device, as well as on the current active links. See [ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) for more information about the try formats.

Sub-devices that support the frame interval enumeration ioctl should implemented it on a single pad only. Its behaviour when supported on multiple pads of the same sub-device is not defined.





<a id="c-v4l2_subdev_frame_interval_enum"></a>

```c
v4l2_subdev_frame_interval_enum
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_subdev_frame_interval_enum</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Number of the format in the enumeration, set by the application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad number as reported by the media controller API.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`code`

</td>
<td>


The media bus format code, as defined in [v4l2-mbus-format](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/subdev-formats.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`width`

</td>
<td>


Frame width, in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`height`

</td>
<td>


Frame height, in pixels.

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`interval`

</td>
<td>


Period, in seconds, between consecutive video frames.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`which`

</td>
<td>


Frame intervals to be enumerated, from enum [v4l2_subdev_format_whence](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-v4l2-subdev-format-whence>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`stream`

</td>
<td>


Stream identifier.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[7\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_subdev_frame_interval_enum` `pad` references a non-existing pad, the `which` field has an unsupported value, one of the `code`, `width` or `height` fields are invalid for the given pad, or the `index` field is out of bounds.

---

# ioctl VIDIOC_SUBDEV_ENUM_FRAME_SIZE

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_ENUM_FRAME_SIZE - Enumerate media bus frame sizes

<a id="rst-ioctl-vidioc-subdev-enum-frame-size"></a>
<a id="rst-vidioc-subdev-enum-frame-size"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_ENUM_FRAME_SIZE - Enumerate media bus frame sizes

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_ENUM_FRAME_SIZE"></a>

```c
VIDIOC_SUBDEV_ENUM_FRAME_SIZE
```

`int ioctl(int fd, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, struct v4l2_subdev_frame_size_enum * argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_subdev_frame_size_enum`.

<a id="rst-description"></a>

## Description

This ioctl allows applications to access the enumeration of frame sizes supported by a sub-device on the specified pad for the specified media bus format. Supported formats can be retrieved with the [vidioc_subdev_enum_mbus_code](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/vidioc-subdev-enum-mbus-code.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) ioctl.

The enumerations are defined by the driver, and indexed using the `index` field of the struct `v4l2_subdev_frame_size_enum`. Each pair of `pad` and `code` correspond to a separate enumeration. Each enumeration starts with the `index` of 0, and the lowest invalid index marks the end of the enumeration.

Therefore, to enumerate frame sizes allowed on the specified pad and using the specified mbus format, initialize the `pad`, `which`, and `code` fields to desired values, and set `index` to 0. Then call the [ioctl VIDIOC_SUBDEV_ENUM_FRAME_SIZE](<#rst-vidioc-subdev-enum-frame-size>) ioctl with a pointer to the structure.

A successful call will return with minimum and maximum frame sizes filled in. Repeat with increasing `index` until `EINVAL` is received. `EINVAL` means that either no more entries are available in the enumeration, or that an input parameter was invalid.

Sub-devices that only support discrete frame sizes (such as most sensors) will return one or more frame sizes with identical minimum and maximum values.

Not all possible sizes in given \[minimum, maximum\] ranges need to be supported. For instance, a scaler that uses a fixed-point scaling ratio might not be able to produce every frame size between the minimum and maximum values. Applications must use the [VIDIOC_SUBDEV_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctl to try the sub-device for an exact supported frame size.

Available frame sizes may depend on the current 'try' formats at other pads of the sub-device, as well as on the current active links and the current values of V4L2 controls. See [ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) for more information about try formats.





<a id="c-v4l2_subdev_frame_size_enum"></a>

```c
v4l2_subdev_frame_size_enum
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_subdev_frame_size_enum</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`index`

</td>
<td>


Index of the frame size in the enumeration belonging to the given pad and format. Filled in by the application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad number as reported by the media controller API. Filled in by the application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`code`

</td>
<td>


The media bus format code, as defined in [v4l2-mbus-format](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/subdev-formats.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>). Filled in by the application.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`min_width`

</td>
<td>


Minimum frame width, in pixels. Filled in by the driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`max_width`

</td>
<td>


Maximum frame width, in pixels. Filled in by the driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`min_height`

</td>
<td>


Minimum frame height, in pixels. Filled in by the driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`max_height`

</td>
<td>


Maximum frame height, in pixels. Filled in by the driver.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`which`

</td>
<td>


Frame sizes to be enumerated, from enum [v4l2_subdev_format_whence](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-v4l2-subdev-format-whence>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`stream`

</td>
<td>


Stream identifier.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[7\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_subdev_frame_size_enum` `pad` references a non-existing pad, the `which` field has an unsupported value, the `code` is invalid for the given pad, or the `index` field is out of bounds.

---

# ioctl VIDIOC_SUBDEV_ENUM_MBUS_CODE

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_ENUM_MBUS_CODE - Enumerate media bus formats

<a id="rst-ioctl-vidioc-subdev-enum-mbus-code"></a>
<a id="rst-vidioc-subdev-enum-mbus-code"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC\_SUBDEV\_ENUM\_MBUS\_CODE - Enumerate media bus formats

<a id="rst-synopsis"></a>

## Synopsis

<a id="c-VIDIOC_SUBDEV_ENUM_MBUS_CODE"></a>



```c
VIDIOC_SUBDEV_ENUM_MBUS_CODE
```

`int ioctl(int fd, VIDIOC_SUBDEV_ENUM_MBUS_CODE, struct v4l2_subdev_mbus_code_enum * argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_subdev_mbus_code_enum`.

<a id="rst-description"></a>

## Description

This call is used by the application to access the enumeration of media bus formats for the selected pad.

The enumerations are defined by the driver, and indexed using the `index` field of struct `v4l2_subdev_mbus_code_enum`. Each enumeration starts with the `index` of 0, and the lowest invalid index marks the end of enumeration.

Therefore, to enumerate media bus formats available at a given sub-device pad, initialize the `pad`, and `which` fields to desired values, and set `index` to 0. Then call the [ioctl VIDIOC\_SUBDEV\_ENUM\_MBUS\_CODE](<#rst-vidioc-subdev-enum-mbus-code>) ioctl with a pointer to this structure.

A successful call will return with the `code` field filled in with a mbus code value. Repeat with increasing `index` until `EINVAL` is received. `EINVAL` means that either `pad` is invalid, or that there are no more codes available at this pad.

The driver must not return the same value of `code` for different indices at the same pad.

Available media bus formats may depend on the current 'try' formats at other pads of the sub-device, as well as on the current active links. See [vidioc\_subdev\_g\_fmt](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) for more information about the try formats.

<a id="c-v4l2_subdev_mbus_code_enum"></a>



```c
v4l2_subdev_mbus_code_enum
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>

struct v4l2\_subdev\_mbus\_code\_enum

</caption>
<tbody>
<tr>
<td>



\_\_u32

</td>
<td>



`pad`

</td>
<td>



Pad number as reported by the media controller API. Filled in by the application.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`index`

</td>
<td>



Index of the mbus code in the enumeration belonging to the given pad. Filled in by the application.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`code`

</td>
<td>



The media bus format code, as defined in [Media Bus Formats](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-v4l2-mbus-format>). Filled in by the driver.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`which`

</td>
<td>



Media bus format codes to be enumerated, from enum [v4l2\_subdev\_format\_whence](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-v4l2-subdev-format-whence>).

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`flags`

</td>
<td>



See [v4l2-subdev-mbus-code-flags](<#rst-v4l2-subdev-mbus-code-flags>)

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`stream`

</td>
<td>



Stream identifier.

</td>
</tr>
<tr>
<td>



\_\_u32

</td>
<td>



`reserved`\[6\]

</td>
<td>



Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \footnotesize -->

<!-- tabularcolumns: |p{8.8cm}|p{2.2cm}|p{6.3cm}| -->

<a id="rst-v4l2-subdev-mbus-code-flags"></a>


<table>
<caption>

Subdev Media Bus Code Enumerate Flags

</caption>
<tbody>
<tr>
<td>



V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_COLORSPACE

</td>
<td>



0x00000001

</td>
<td>



The driver allows the application to try to change the default colorspace encoding. The application can ask to configure the colorspace of the subdevice when calling the [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctl with [V4L2\_MBUS\_FRAMEFMT\_SET\_CSC](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-mbus-framefmt-set-csc>) set. See [Media Bus Formats](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-v4l2-mbus-format>) on how to do this.

</td>
</tr>
<tr>
<td>



V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_XFER\_FUNC

</td>
<td>



0x00000002

</td>
<td>



The driver allows the application to try to change the default transform function. The application can ask to configure the transform function of the subdevice when calling the [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctl with [V4L2\_MBUS\_FRAMEFMT\_SET\_CSC](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-mbus-framefmt-set-csc>) set. See [Media Bus Formats](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-v4l2-mbus-format>) on how to do this.

</td>
</tr>
<tr>
<td>



V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_YCBCR\_ENC

</td>
<td>



0x00000004

</td>
<td>



The driver allows the application to try to change the default Y'CbCr encoding. The application can ask to configure the Y'CbCr encoding of the subdevice when calling the [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctl with [V4L2\_MBUS\_FRAMEFMT\_SET\_CSC](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-mbus-framefmt-set-csc>) set. See [Media Bus Formats](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-v4l2-mbus-format>) on how to do this.

</td>
</tr>
<tr>
<td>



V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_HSV\_ENC

</td>
<td>



0x00000004

</td>
<td>



The driver allows the application to try to change the default HSV encoding. The application can ask to configure the HSV encoding of the subdevice when calling the [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctl with [V4L2\_MBUS\_FRAMEFMT\_SET\_CSC](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-mbus-framefmt-set-csc>) set. See [Media Bus Formats](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-v4l2-mbus-format>) on how to do this.

</td>
</tr>
<tr>
<td>



V4L2\_SUBDEV\_MBUS\_CODE\_CSC\_QUANTIZATION

</td>
<td>



0x00000008

</td>
<td>



The driver allows the application to try to change the default quantization. The application can ask to configure the quantization of the subdevice when calling the [VIDIOC\_SUBDEV\_S\_FMT](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-vidioc-subdev-g-fmt>) ioctl with [V4L2\_MBUS\_FRAMEFMT\_SET\_CSC](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-mbus-framefmt-set-csc>) set. See [Media Bus Formats](</kernel/userspace/userspace-api/media-v4l/subdev-formats.md#rst-v4l2-mbus-format>) on how to do this.

</td>
</tr>
</tbody>
</table>

<!-- Source LaTeX layout: \normalsize -->

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The struct `v4l2_subdev_mbus_code_enum` `pad` references a non-existing pad, the `which` field has an unsupported value, or the `index` field is out of bounds.

---

# ioctl VIDIOC_SUBDEV_G_CLIENT_CAP, VIDIOC_SUBDEV_S_CLIENT_CAP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_G_CLIENT_CAP - VIDIOC_SUBDEV_S_CLIENT_CAP - Get or set client capabilities.

<a id="rst-ioctl-vidioc-subdev-g-client-cap-vidioc-subdev-s-client-cap"></a>
<a id="rst-vidioc-subdev-g-client-cap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_G_CLIENT_CAP - VIDIOC_SUBDEV_S_CLIENT_CAP - Get or set client capabilities.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_G_CLIENT_CAP"></a>

```c
VIDIOC_SUBDEV_G_CLIENT_CAP
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_CLIENT_CAP, struct v4l2_subdev_client_capability *argp)`





<a id="c-VIDIOC_SUBDEV_S_CLIENT_CAP"></a>

```c
VIDIOC_SUBDEV_S_CLIENT_CAP
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_CLIENT_CAP, struct v4l2_subdev_client_capability *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by [open()](</kernel/userspace/userspace-api/media-v4l/func-open.md#rst-func-open>).

- **`argp`**

  Pointer to struct `v4l2_subdev_client_capability`.

<a id="rst-description"></a>

## Description

These ioctls are used to get and set the client (the application using the subdevice ioctls) capabilities. The client capabilities are stored in the file handle of the opened subdev device node, and the client must set the capabilities for each opened subdev separately.

By default no client capabilities are set when a subdev device node is opened.

The purpose of the client capabilities are to inform the kernel of the behavior of the client, mainly related to maintaining compatibility with different kernel and userspace versions.

The `VIDIOC_SUBDEV_G_CLIENT_CAP` ioctl returns the current client capabilities associated with the file handle `fd`.

The `VIDIOC_SUBDEV_S_CLIENT_CAP` ioctl sets client capabilities for the file handle `fd`. The new capabilities fully replace the current capabilities, the ioctl can therefore also be used to remove capabilities that have previously been set.

`VIDIOC_SUBDEV_S_CLIENT_CAP` modifies the struct `v4l2_subdev_client_capability` to reflect the capabilities that have been accepted. A common case for the kernel not accepting a capability is that the kernel is older than the headers the userspace uses, and thus the capability is unknown to the kernel.

<!-- tabularcolumns: |p{1.5cm}|p{2.9cm}|p{12.9cm}| -->





<a id="c-v4l2_subdev_client_capability"></a>

```c
v4l2_subdev_client_capability
```


<table>
<caption>struct v4l2_subdev_client_capability</caption>
<tbody>
<tr>
<td>


\__u64

</td>
<td>


`capabilities`

</td>
<td>


Sub-device client capabilities of the opened device.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.8cm}|p{2.4cm}|p{8.1cm}| -->


<table>
<caption>Client Capabilities</caption>
<thead>
<tr>
<th>


Capability

</th>
<th>


Description

</th>
</tr>
</thead>
<tbody>
<tr>
<td>


`V4L2_SUBDEV_CLIENT_CAP_STREAMS`

</td>
<td>


The client is aware of streams. Setting this flag enables the use of 'stream' fields (referring to the stream number) with various ioctls. If this is not set (which is the default), the 'stream' fields will be forced to 0 by the kernel.

</td>
</tr>
<tr>
<td>


`V4L2_SUBDEV_CLIENT_CAP_INTERVAL_USES_WHICH`

</td>
<td>


The client is aware of the `v4l2_subdev_frame_interval` `which` field. If this is not set (which is the default), the `which` field is forced to `V4L2_SUBDEV_FORMAT_ACTIVE` by the kernel.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **ENOIOCTLCMD**

  The kernel does not support this ioctl.

---

# ioctl VIDIOC_SUBDEV_G_CROP, VIDIOC_SUBDEV_S_CROP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_G_CROP - VIDIOC_SUBDEV_S_CROP - Get or set the crop rectangle on a subdev pad

<a id="rst-ioctl-vidioc-subdev-g-crop-vidioc-subdev-s-crop"></a>
<a id="rst-vidioc-subdev-g-crop"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_G_CROP - VIDIOC_SUBDEV_S_CROP - Get or set the crop rectangle on a subdev pad

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_G_CROP"></a>

```c
VIDIOC_SUBDEV_G_CROP
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_CROP, struct v4l2_subdev_crop *argp)`





<a id="c-VIDIOC_SUBDEV_S_CROP"></a>

```c
VIDIOC_SUBDEV_S_CROP
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_CROP, const struct v4l2_subdev_crop *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_subdev_crop`.

<a id="rst-description"></a>

## Description

> [!NOTE]
>
> This is an [Obsolete API Elements](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/hist-v4l2.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) interface and may be removed in the future. It is superseded by [the selection API](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-selection.md#rst-vidioc-subdev-g-selection>). No new extensions to the `v4l2_subdev_crop` structure will be accepted.

To retrieve the current crop rectangle applications set the `pad` field of a struct `v4l2_subdev_crop` to the desired pad number as reported by the media API and the `which` field to `V4L2_SUBDEV_FORMAT_ACTIVE`. They then call the `VIDIOC_SUBDEV_G_CROP` ioctl with a pointer to this structure. The driver fills the members of the `rect` field or returns `EINVAL` error code if the input arguments are invalid, or if cropping is not supported on the given pad.

To change the current crop rectangle applications set both the `pad` and `which` fields and all members of the `rect` field. They then call the `VIDIOC_SUBDEV_S_CROP` ioctl with a pointer to this structure. The driver verifies the requested crop rectangle, adjusts it based on the hardware capabilities and configures the device. Upon return the struct `v4l2_subdev_crop` contains the current format as would be returned by a `VIDIOC_SUBDEV_G_CROP` call.

Applications can query the device capabilities by setting the `which` to `V4L2_SUBDEV_FORMAT_TRY`. When set, 'try' crop rectangles are not applied to the device by the driver, but are mangled exactly as active crop rectangles and stored in the sub-device file handle. Two applications querying the same sub-device would thus not interact with each other.

If the subdev device node has been registered in read-only mode, calls to `VIDIOC_SUBDEV_S_CROP` are only valid if the `which` field is set to `V4L2_SUBDEV_FORMAT_TRY`, otherwise an error is returned and the errno variable is set to `-EPERM`.

Drivers must not return an error solely because the requested crop rectangle doesn't match the device capabilities. They must instead modify the rectangle to match what the hardware can provide. The modified format should be as close as possible to the original request.





<a id="c-v4l2_subdev_crop"></a>

```c
v4l2_subdev_crop
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_subdev_crop</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad number as reported by the media framework.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`which`

</td>
<td>


Crop rectangle to get or set, from enum [v4l2_subdev_format_whence](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-v4l2-subdev-format-whence>).

</td>
</tr>
<tr>
<td>


struct `v4l2_rect`

</td>
<td>


`rect`

</td>
<td>


Crop rectangle boundaries, in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`stream`

</td>
<td>


Stream identifier.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[7\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EBUSY**

  The crop rectangle can't be changed because the pad is currently busy. This can be caused, for instance, by an active video stream on the pad. The ioctl must not be retried without performing another action to fix the problem first. Only returned by `VIDIOC_SUBDEV_S_CROP`

- **EINVAL**

  The struct `v4l2_subdev_crop` `pad` references a non-existing pad, the `which` field has an unsupported value, or cropping is not supported on the given subdev pad.

- **EPERM**

  The `VIDIOC_SUBDEV_S_CROP` ioctl has been called on a read-only subdevice and the `which` field is set to `V4L2_SUBDEV_FORMAT_ACTIVE`.

---

# ioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad

<a id="rst-ioctl-vidioc-subdev-g-fmt-vidioc-subdev-s-fmt"></a>
<a id="rst-vidioc-subdev-g-fmt"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_G_FMT"></a>

```c
VIDIOC_SUBDEV_G_FMT
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_FMT, struct v4l2_subdev_format *argp)`





<a id="c-VIDIOC_SUBDEV_S_FMT"></a>

```c
VIDIOC_SUBDEV_S_FMT
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_FMT, struct v4l2_subdev_format *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_subdev_format`.

<a id="rst-description"></a>

## Description

These ioctls are used to negotiate the frame format at specific subdev pads in the image pipeline.

To retrieve the current format applications set the `pad` field of a struct `v4l2_subdev_format` to the desired pad number as reported by the media API and the `which` field to `V4L2_SUBDEV_FORMAT_ACTIVE`. When they call the `VIDIOC_SUBDEV_G_FMT` ioctl with a pointer to this structure the driver fills the members of the `format` field.

To change the current format applications set both the `pad` and `which` fields and all members of the `format` field. When they call the `VIDIOC_SUBDEV_S_FMT` ioctl with a pointer to this structure the driver verifies the requested format, adjusts it based on the hardware capabilities and configures the device. Upon return the struct `v4l2_subdev_format` contains the current format as would be returned by a `VIDIOC_SUBDEV_G_FMT` call.

Applications can query the device capabilities by setting the `which` to `V4L2_SUBDEV_FORMAT_TRY`. When set, 'try' formats are not applied to the device by the driver, but are changed exactly as active formats and stored in the sub-device file handle. Two applications querying the same sub-device would thus not interact with each other.

For instance, to try a format at the output pad of a sub-device, applications would first set the try format at the sub-device input with the `VIDIOC_SUBDEV_S_FMT` ioctl. They would then either retrieve the default format at the output pad with the `VIDIOC_SUBDEV_G_FMT` ioctl, or set the desired output pad format with the `VIDIOC_SUBDEV_S_FMT` ioctl and check the returned value.

Try formats do not depend on active formats, but can depend on the current links configuration or sub-device controls value. For instance, a low-pass noise filter might crop pixels at the frame boundaries, modifying its output frame size.

If the subdev device node has been registered in read-only mode, calls to `VIDIOC_SUBDEV_S_FMT` are only valid if the `which` field is set to `V4L2_SUBDEV_FORMAT_TRY`, otherwise an error is returned and the errno variable is set to `-EPERM`.

Drivers must not return an error solely because the requested format doesn't match the device capabilities. They must instead modify the format to match what the hardware can provide. The modified format should be as close as possible to the original request.

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->





<a id="c-v4l2_subdev_format"></a>

```c
v4l2_subdev_format
```


<table>
<caption>struct v4l2_subdev_format</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad number as reported by the media controller API.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`which`

</td>
<td>


Format to modified, from enum [v4l2_subdev_format_whence](<#rst-v4l2-subdev-format-whence>).

</td>
</tr>
<tr>
<td>


struct `v4l2_mbus_framefmt`

</td>
<td>


`format`

</td>
<td>


Definition of an image format, see `v4l2_mbus_framefmt` for details.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`stream`

</td>
<td>


Stream identifier.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[7\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.5cm}| -->

<a id="rst-v4l2-subdev-format-whence"></a>


<table>
<caption>enum v4l2_subdev_format_whence</caption>
<tbody>
<tr>
<td>


V4L2_SUBDEV_FORMAT_TRY

</td>
<td>


0

</td>
<td>


Try formats, used for querying device capabilities.

</td>
</tr>
<tr>
<td>


V4L2_SUBDEV_FORMAT_ACTIVE

</td>
<td>


1

</td>
<td>


Active formats, applied to the hardware.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EBUSY**

  The format can't be changed because the pad is currently busy. This can be caused, for instance, by an active video stream on the pad. The ioctl must not be retried without performing another action to fix the problem first. Only returned by `VIDIOC_SUBDEV_S_FMT`

- **EINVAL**

  The struct `v4l2_subdev_format` `pad` references a non-existing pad, or the `which` field has an unsupported value.

- **EPERM**

  The `VIDIOC_SUBDEV_S_FMT` ioctl has been called on a read-only subdevice and the `which` field is set to `V4L2_SUBDEV_FORMAT_ACTIVE`.

---

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl VIDIOC_SUBDEV_G_FRAME_INTERVAL, VIDIOC_SUBDEV_S_FRAME_INTERVAL

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_G_FRAME_INTERVAL - VIDIOC_SUBDEV_S_FRAME_INTERVAL - Get or set the frame interval on a subdev pad

<a id="rst-ioctl-vidioc-subdev-g-frame-interval-vidioc-subdev-s-frame-interval"></a>
<a id="rst-vidioc-subdev-g-frame-interval"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_G_FRAME_INTERVAL - VIDIOC_SUBDEV_S_FRAME_INTERVAL - Get or set the frame interval on a subdev pad

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_G_FRAME_INTERVAL"></a>

```c
VIDIOC_SUBDEV_G_FRAME_INTERVAL
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_FRAME_INTERVAL, struct v4l2_subdev_frame_interval *argp)`





<a id="c-VIDIOC_SUBDEV_S_FRAME_INTERVAL"></a>

```c
VIDIOC_SUBDEV_S_FRAME_INTERVAL
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_FRAME_INTERVAL, struct v4l2_subdev_frame_interval *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_subdev_frame_interval`.

<a id="rst-description"></a>

## Description

These ioctls are used to get and set the frame interval at specific subdev pads in the image pipeline. The frame interval only makes sense for sub-devices that can control the frame period on their own. This includes, for instance, image sensors and TV tuners. Sub-devices that don't support frame intervals must not implement these ioctls.

To retrieve the current frame interval applications set the `pad` field of a struct `v4l2_subdev_frame_interval` to the desired pad number as reported by the media controller API. When they call the `VIDIOC_SUBDEV_G_FRAME_INTERVAL` ioctl with a pointer to this structure the driver fills the members of the `interval` field.

To change the current frame interval applications set both the `pad` field and all members of the `interval` field. When they call the `VIDIOC_SUBDEV_S_FRAME_INTERVAL` ioctl with a pointer to this structure the driver verifies the requested interval, adjusts it based on the hardware capabilities and configures the device. Upon return the struct `v4l2_subdev_frame_interval` contains the current frame interval as would be returned by a `VIDIOC_SUBDEV_G_FRAME_INTERVAL` call.

If the subdev device node has been registered in read-only mode, calls to `VIDIOC_SUBDEV_S_FRAME_INTERVAL` are only valid if the `which` field is set to `V4L2_SUBDEV_FORMAT_TRY`, otherwise an error is returned and the errno variable is set to `-EPERM`.

Drivers must not return an error solely because the requested interval doesn't match the device capabilities. They must instead modify the interval to match what the hardware can provide. The modified interval should be as close as possible to the original request.

Changing the frame interval shall never change the format. Changing the format, on the other hand, may change the frame interval.

Sub-devices that support the frame interval ioctls should implement them on a single pad only. Their behaviour when supported on multiple pads of the same sub-device is not defined.





<a id="c-v4l2_subdev_frame_interval"></a>

```c
v4l2_subdev_frame_interval
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_subdev_frame_interval</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad number as reported by the media controller API.

</td>
</tr>
<tr>
<td>


struct `v4l2_fract`

</td>
<td>


`interval`

</td>
<td>


Period, in seconds, between consecutive video frames.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`stream`

</td>
<td>


Stream identifier.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`which`

</td>
<td>


Active or try frame interval, from enum [v4l2_subdev_format_whence](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-v4l2-subdev-format-whence>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[7\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EBUSY**

  The frame interval can't be changed because the pad is currently busy. This can be caused, for instance, by an active video stream on the pad. The ioctl must not be retried without performing another action to fix the problem first. Only returned by `VIDIOC_SUBDEV_S_FRAME_INTERVAL`

- **EINVAL**

  The struct `v4l2_subdev_frame_interval` `pad` references a non-existing pad, the `which` field has an unsupported value, or the pad doesn't support frame intervals.

- **EPERM**

  The `VIDIOC_SUBDEV_S_FRAME_INTERVAL` ioctl has been called on a read-only subdevice and the `which` field is set to `V4L2_SUBDEV_FORMAT_ACTIVE`.

---

# ioctl VIDIOC_SUBDEV_G_ROUTING, VIDIOC_SUBDEV_S_ROUTING

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_G_ROUTING - VIDIOC_SUBDEV_S_ROUTING - Get or set routing between streams of media pads in a media entity.

<a id="rst-ioctl-vidioc-subdev-g-routing-vidioc-subdev-s-routing"></a>
<a id="rst-vidioc-subdev-g-routing"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_G_ROUTING - VIDIOC_SUBDEV_S_ROUTING - Get or set routing between streams of media pads in a media entity.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_G_ROUTING"></a>

```c
VIDIOC_SUBDEV_G_ROUTING
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_ROUTING, struct v4l2_subdev_routing *argp)`





<a id="c-VIDIOC_SUBDEV_S_ROUTING"></a>

```c
VIDIOC_SUBDEV_S_ROUTING
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_ROUTING, struct v4l2_subdev_routing *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by [open()](</kernel/userspace/userspace-api/media-v4l/func-open.md#rst-func-open>).

- **`argp`**

  Pointer to struct `v4l2_subdev_routing`.

<a id="rst-description"></a>

## Description

These ioctls are used to get and set the routing in a media entity. The routing configuration determines the flows of data inside an entity.

Drivers report their current routing tables using the `VIDIOC_SUBDEV_G_ROUTING` ioctl and application may enable or disable routes with the `VIDIOC_SUBDEV_S_ROUTING` ioctl, by adding or removing routes and setting or clearing flags of the `flags` field of a struct `v4l2_subdev_route`. Similarly to `VIDIOC_SUBDEV_G_ROUTING`, also `VIDIOC_SUBDEV_S_ROUTING` returns the routes back to the user.

All stream configurations are reset when `VIDIOC_SUBDEV_S_ROUTING` is called. This means that the userspace must reconfigure all stream formats and selections after calling the ioctl with e.g. `VIDIOC_SUBDEV_S_FMT`.

Only subdevices which have both sink and source pads can support routing.

The `len_routes` field indicates the number of routes that can fit in the `routes` array allocated by userspace. It is set by applications for both ioctls to indicate how many routes the kernel can return, and is never modified by the kernel.

The `num_routes` field indicates the number of routes in the routing table. For `VIDIOC_SUBDEV_S_ROUTING`, it is set by userspace to the number of routes that the application stored in the `routes` array. For both ioctls, it is returned by the kernel and indicates how many routes are stored in the subdevice routing table. This may be smaller or larger than the value of `num_routes` set by the application for `VIDIOC_SUBDEV_S_ROUTING`, as drivers may adjust the requested routing table.

The kernel can return a `num_routes` value larger than `len_routes` from both ioctls. This indicates thare are more routes in the routing table than fits the `routes` array. In this case, the `routes` array is filled by the kernel with the first `len_routes` entries of the subdevice routing table. This is not considered to be an error, and the ioctl call succeeds. If the applications wants to retrieve the missing routes, it can issue a new `VIDIOC_SUBDEV_G_ROUTING` call with a large enough `routes` array.

`VIDIOC_SUBDEV_S_ROUTING` may return more routes than the user provided in `num_routes` field due to e.g. hardware properties.

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.7cm}| -->





<a id="c-v4l2_subdev_routing"></a>

```c
v4l2_subdev_routing
```


<table>
<caption>struct v4l2_subdev_routing</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`which`

</td>
<td>


Routing table to be accessed, from enum [v4l2_subdev_format_whence](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-v4l2-subdev-format-whence>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`len_routes`

</td>
<td>


The length of the array (as in memory reserved for the array)

</td>
</tr>
<tr>
<td>


struct `v4l2_subdev_route`

</td>
<td>


`routes[]`

</td>
<td>


Array of struct `v4l2_subdev_route` entries

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`num_routes`

</td>
<td>


Number of entries of the routes array

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[11\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.7cm}| -->





<a id="c-v4l2_subdev_route"></a>

```c
v4l2_subdev_route
```


<table>
<caption>struct v4l2_subdev_route</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`sink_pad`

</td>
<td>


Sink pad number.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`sink_stream`

</td>
<td>


Sink pad stream number.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`source_pad`

</td>
<td>


Source pad number.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`source_stream`

</td>
<td>


Source pad stream number.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Route enable/disable flags [v4l2_subdev_routing_flags](<#rst-v4l2-subdev-routing-flags>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[5\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.6cm}|p{2.2cm}|p{8.7cm}| -->

<a id="rst-v4l2-subdev-routing-flags"></a>


<table>
<caption>enum v4l2_subdev_routing_flags</caption>
<tbody>
<tr>
<td>


V4L2_SUBDEV_ROUTE_FL_ACTIVE

</td>
<td>


0x0001

</td>
<td>


The route is enabled. Set by applications.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EINVAL**

  The sink or source pad identifiers reference a non-existing pad or reference pads of different types (ie. the sink_pad identifiers refers to a source pad), the `which` field has an unsupported value, or, for `VIDIOC_SUBDEV_S_ROUTING`, the num_routes field set by the application is larger than the len_routes field value.

- **ENXIO**

  The application requested routes cannot be created or the state of the specified routes cannot be modified. Only returned for `VIDIOC_SUBDEV_S_ROUTING`.

- **E2BIG**

  The application provided `num_routes` for `VIDIOC_SUBDEV_S_ROUTING` is larger than the number of routes the driver can handle.

---

# ioctl VIDIOC_SUBDEV_G_SELECTION, VIDIOC_SUBDEV_S_SELECTION

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_G_SELECTION - VIDIOC_SUBDEV_S_SELECTION - Get or set selection rectangles on a subdev pad

<a id="rst-ioctl-vidioc-subdev-g-selection-vidioc-subdev-s-selection"></a>
<a id="rst-vidioc-subdev-g-selection"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_G_SELECTION - VIDIOC_SUBDEV_S_SELECTION - Get or set selection rectangles on a subdev pad

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_G_SELECTION"></a>

```c
VIDIOC_SUBDEV_G_SELECTION
```

`int ioctl(int fd, VIDIOC_SUBDEV_G_SELECTION, struct v4l2_subdev_selection *argp)`





<a id="c-VIDIOC_SUBDEV_S_SELECTION"></a>

```c
VIDIOC_SUBDEV_S_SELECTION
```

`int ioctl(int fd, VIDIOC_SUBDEV_S_SELECTION, struct v4l2_subdev_selection *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_subdev_selection`.

<a id="rst-description"></a>

## Description

The selections are used to configure various image processing functionality performed by the subdevs which affect the image size. This currently includes cropping, scaling and composition.

The selection API replaces [the old subdev crop API](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-crop.md#rst-vidioc-subdev-g-crop>). All the function of the crop API, and more, are supported by the selections API.

See [subdev](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/dev-subdev.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>) for more information on how each selection target affects the image processing pipeline inside the subdevice.

If the subdev device node has been registered in read-only mode, calls to `VIDIOC_SUBDEV_S_SELECTION` are only valid if the `which` field is set to `V4L2_SUBDEV_FORMAT_TRY`, otherwise an error is returned and the errno variable is set to `-EPERM`.

<a id="rst-types-of-selection-targets"></a>

### Types of selection targets

There are two types of selection targets: actual and bounds. The actual targets are the targets which configure the hardware. The BOUNDS target will return a rectangle that contain all possible actual rectangles.

<a id="rst-discovering-supported-features"></a>

### Discovering supported features

To discover which targets are supported, the user can perform `VIDIOC_SUBDEV_G_SELECTION` on them. Any unsupported target will return `EINVAL`.

Selection targets and flags are documented in [Common selection definitions](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>).





<a id="c-v4l2_subdev_selection"></a>

```c
v4l2_subdev_selection
```

<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>struct v4l2_subdev_selection</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`which`

</td>
<td>


Active or try selection, from enum [v4l2_subdev_format_whence](</kernel/userspace/userspace-api/media-v4l/vidioc-subdev-g-fmt.md#rst-v4l2-subdev-format-whence>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`pad`

</td>
<td>


Pad number as reported by the media framework.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`target`

</td>
<td>


Target selection rectangle. See [Common selection definitions](</kernel/userspace/userspace-api/media-v4l/selections-common.md#rst-v4l2-selections-common>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Flags. See [v4l2-selection-flags](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/v4l2-selection-flags.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>).

</td>
</tr>
<tr>
<td>


struct `v4l2_rect`

</td>
<td>


`r`

</td>
<td>


Selection rectangle, in pixels.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`stream`

</td>
<td>


Stream identifier.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[7\]

</td>
<td>


Reserved for future extensions. Applications and drivers must set the array to zero.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **EBUSY**

  The selection rectangle can't be changed because the pad is currently busy. This can be caused, for instance, by an active video stream on the pad. The ioctl must not be retried without performing another action to fix the problem first. Only returned by `VIDIOC_SUBDEV_S_SELECTION`

- **EINVAL**

  The struct `v4l2_subdev_selection` `pad` references a non-existing pad, the `which` field has an unsupported value, or the selection target is not supported on the given subdev pad.

- **EPERM**

  The `VIDIOC_SUBDEV_S_SELECTION` ioctl has been called on a read-only subdevice and the `which` field is set to `V4L2_SUBDEV_FORMAT_ACTIVE`.

---

# ioctl VIDIOC_SUBDEV_QUERYCAP

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBDEV_QUERYCAP - Query sub-device capabilities

<a id="rst-ioctl-vidioc-subdev-querycap"></a>
<a id="rst-vidioc-subdev-querycap"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBDEV_QUERYCAP - Query sub-device capabilities

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBDEV_QUERYCAP"></a>

```c
VIDIOC_SUBDEV_QUERYCAP
```

`int ioctl(int fd, VIDIOC_SUBDEV_QUERYCAP, struct v4l2_subdev_capability *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_subdev_capability`.

<a id="rst-description"></a>

## Description

All V4L2 sub-devices support the `VIDIOC_SUBDEV_QUERYCAP` ioctl. It is used to identify kernel devices compatible with this specification and to obtain information about driver and hardware capabilities. The ioctl takes a pointer to a struct `v4l2_subdev_capability` which is filled by the driver. When the driver is not compatible with this specification the ioctl returns `ENOTTY` error code.

<!-- tabularcolumns: |p{1.5cm}|p{2.9cm}|p{12.9cm}| -->





<a id="c-v4l2_subdev_capability"></a>

```c
v4l2_subdev_capability
```


<table>
<caption>struct v4l2_subdev_capability</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`version`

</td>
<td>


Version number of the driver.

The version reported is provided by the V4L2 subsystem following the kernel numbering scheme. However, it may not always return the same version as the kernel if, for example, a stable or distribution-modified kernel uses the V4L2 stack from a newer kernel.

The version number is formatted using the `KERNEL_VERSION()` macro:

</td>
</tr>
<tr>
<td colspan="3">


`#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))`

`__u32 version = KERNEL_VERSION(0, 8, 1);`

`printf ("Version: %u.%u.%u\\n",`

`(version >> 16) & 0xFF, (version >> 8) & 0xFF, version & 0xFF);`

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`capabilities`

</td>
<td>


Sub-device capabilities of the opened device, see [subdevice-capabilities](<#rst-subdevice-capabilities>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[14\]

</td>
<td>


Reserved for future extensions. Set to 0 by the V4L2 core.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{6.8cm}|p{2.4cm}|p{8.1cm}| -->

<a id="rst-subdevice-capabilities"></a>


<table>
<caption>Sub-Device Capabilities Flags</caption>
<tbody>
<tr>
<td>


V4L2_SUBDEV_CAP_RO_SUBDEV

</td>
<td>


0x00000001

</td>
<td>


The sub-device device node is registered in read-only mode. Access to the sub-device ioctls that modify the device state is restricted. Refer to each individual subdevice ioctl documentation for a description of which restrictions apply to a read-only sub-device.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

- **ENOTTY**

  The device node is not a V4L2 sub-device.

---

# ioctl VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> VIDIOC_SUBSCRIBE_EVENT - VIDIOC_UNSUBSCRIBE_EVENT - Subscribe or unsubscribe event

<a id="rst-ioctl-vidioc-subscribe-event-vidioc-unsubscribe-event"></a>
<a id="rst-vidioc-unsubscribe-event"></a>
<a id="rst-vidioc-subscribe-event"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

<a id="rst-name"></a>

## Name

VIDIOC_SUBSCRIBE_EVENT - VIDIOC_UNSUBSCRIBE_EVENT - Subscribe or unsubscribe event

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-VIDIOC_SUBSCRIBE_EVENT"></a>

```c
VIDIOC_SUBSCRIBE_EVENT
```

`int ioctl(int fd, VIDIOC_SUBSCRIBE_EVENT, struct v4l2_event_subscription *argp)`





<a id="c-VIDIOC_UNSUBSCRIBE_EVENT"></a>

```c
VIDIOC_UNSUBSCRIBE_EVENT
```

`int ioctl(int fd, VIDIOC_UNSUBSCRIBE_EVENT, struct v4l2_event_subscription *argp)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`argp`**

  Pointer to struct `v4l2_event_subscription`.

<a id="rst-description"></a>

## Description

Subscribe or unsubscribe V4L2 event. Subscribed events are dequeued by using the [ioctl VIDIOC_DQEVENT](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-vidioc-dqevent>) ioctl.

<!-- tabularcolumns: |p{2.6cm}|p{4.4cm}|p{10.3cm}| -->





<a id="c-v4l2_event_subscription"></a>

```c
v4l2_event_subscription
```


<table>
<caption>struct v4l2_event_subscription</caption>
<tbody>
<tr>
<td>


\__u32

</td>
<td>


`type`

</td>
<td>


Type of the event, see [event-type](</kernel/userspace/userspace-api/media-v4l/vidioc-dqevent.md#rst-event-type>).

> [!NOTE]
>
> `V4L2_EVENT_ALL` can be used with [VIDIOC_UNSUBSCRIBE_EVENT](<#rst-vidioc-subscribe-event>) for unsubscribing all events at once.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`id`

</td>
<td>


ID of the event source. If there is no ID associated with the event source, then set this to 0. Whether or not an event needs an ID depends on the event type.

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`flags`

</td>
<td>


Event flags, see [event-flags](<#rst-event-flags>).

</td>
</tr>
<tr>
<td>


\__u32

</td>
<td>


`reserved`\[5\]

</td>
<td>


Reserved for future extensions. Drivers and applications must set the array to zero.

</td>
</tr>
</tbody>
</table>

<!-- tabularcolumns: |p{7.5cm}|p{2.0cm}|p{7.8cm}| -->

<a id="rst-event-flags"></a>


<table>
<caption>Event Flags</caption>
<tbody>
<tr>
<td>


`V4L2_EVENT_SUB_FL_SEND_INITIAL`

</td>
<td>


0x0001

</td>
<td>


When this event is subscribed an initial event will be sent containing the current status. This only makes sense for events that are triggered by a status change such as `V4L2_EVENT_CTRL`. Other events will ignore this flag.

</td>
</tr>
<tr>
<td>


`V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK`

</td>
<td>


0x0002

</td>
<td>


If set, then events directly caused by an ioctl will also be sent to the filehandle that called that ioctl. For example, changing a control using [VIDIOC_S_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) will cause a V4L2_EVENT_CTRL to be sent back to that same filehandle. Normally such events are suppressed to prevent feedback loops where an application changes a control to a one value and then another, and then receives an event telling it that that control has changed to the first value.

Since it can't tell whether that event was caused by another application or by the [VIDIOC_S_CTRL](</kernel/userspace/userspace-api/media-v4l/vidioc-g-ctrl.md#rst-vidioc-g-ctrl>) call it is hard to decide whether to set the control to the value in the event, or ignore it.

Think carefully when you set this flag so you won't get into situations like that.

</td>
</tr>
</tbody>
</table>

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# YUV Formats

_Peios Kernel / Userspace interfaces / System and device interfaces / Video4Linux_

> YUV is the format native to TV broadcast and composite video signals. It separates the brightness information (Y) from the color information (U and V or Cb and Cr). The color information consists of red and blue color difference signals,…

<a id="rst-yuv-formats-1"></a>
<a id="rst-yuv-formats"></a>

<!-- SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: V4L -->

YUV is the format native to TV broadcast and composite video signals. It separates the brightness information (Y) from the color information (U and V or Cb and Cr). The color information consists of red and blue *color difference* signals, this way the green component can be reconstructed by subtracting from the brightness component. See [Colorspaces](</kernel/userspace/userspace-api/media-v4l/colorspaces.md#rst-colorspaces-1>) for conversion examples. YUV was chosen because early television would only transmit brightness information. To add color in a way compatible with existing receivers a new signal carrier was added to transmit the color difference signals.

<a id="rst-subsampling"></a>

## Subsampling

YUV formats commonly encode images with a lower resolution for the chroma components than for the luma component. This compression technique, taking advantage of the human eye being more sensitive to luminance than color differences, is called chroma subsampling.

While many combinations of subsampling factors in the horizontal and vertical direction are possible, common factors are 1 (no subsampling), 2 and 4, with horizontal subsampling always larger than or equal to vertical subsampling. Common combinations are named as follows.

- `4:4:4`: No subsampling

- `4:2:2`: Horizontal subsampling by 2, no vertical subsampling

- `4:2:0`: Horizontal subsampling by 2, vertical subsampling by 2

- `4:1:1`: Horizontal subsampling by 4, no vertical subsampling

- `4:1:0`: Horizontal subsampling by 4, vertical subsampling by 4

Subsampling the chroma component effectively creates chroma values that can be located in different spatial locations:

- <a id="rst-yuv-chroma-centered"></a>

  The subsampled chroma value may be calculated by simply averaging the chroma value of two consecutive pixels. It effectively models the chroma of a pixel sited between the two original pixels. This is referred to as centered or interstitially sited chroma.

- <a id="rst-yuv-chroma-cosited"></a>

  The other option is to subsample chroma values in a way that place them in the same spatial sites as the pixels. This may be performed by skipping every other chroma sample (creating aliasing artifacts), or with filters using an odd number of taps. This is referred to as co-sited chroma.

The following examples show different combination of chroma siting in a 4x4 image.


<table>
<caption>4:2:2 subsampling, interstitially sited</caption>
<thead>
<tr>
<th>




</th>
<th>


0

</th>
<th>




</th>
<th>


1

</th>
<th>




</th>
<th>


2

</th>
<th>




</th>
<th>


3

</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">


0

</th>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


1

</th>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


2

</th>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


3

</th>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
</tr>
</tbody>
</table>


<table>
<caption>4:2:2 subsampling, co-sited</caption>
<thead>
<tr>
<th>




</th>
<th>


0

</th>
<th>




</th>
<th>


1

</th>
<th>




</th>
<th>


2

</th>
<th>




</th>
<th>


3

</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">


0

</th>
<td>


Y/C

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y/C

</td>
<td>




</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


1

</th>
<td>


Y/C

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y/C

</td>
<td>




</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


2

</th>
<td>


Y/C

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y/C

</td>
<td>




</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


3

</th>
<td>


Y/C

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y/C

</td>
<td>




</td>
<td>


Y

</td>
</tr>
</tbody>
</table>


<table>
<caption>4:2:0 subsampling, horizontally interstitially sited, vertically co-sited</caption>
<thead>
<tr>
<th>




</th>
<th>


0

</th>
<th>




</th>
<th>


1

</th>
<th>




</th>
<th>


2

</th>
<th>




</th>
<th>


3

</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">


0

</th>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


1

</th>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


2

</th>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>


C

</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">


3

</th>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
</tr>
</tbody>
</table>


<table>
<caption>4:1:0 subsampling, horizontally and vertically interstitially sited</caption>
<thead>
<tr>
<th>




</th>
<th>


0

</th>
<th>




</th>
<th>


1

</th>
<th>




</th>
<th>


2

</th>
<th>




</th>
<th>


3

</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">


0

</th>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">




</th>
<td>




</td>
<td>




</td>
<td>




</td>
<td>




</td>
<td>




</td>
<td>




</td>
<td>




</td>
</tr>
<tr>
<th scope="row">


1

</th>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">




</th>
<td>




</td>
<td>




</td>
<td>




</td>
<td>


C

</td>
<td>




</td>
<td>




</td>
<td>




</td>
</tr>
<tr>
<th scope="row">


2

</th>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
</tr>
<tr>
<th scope="row">




</th>
<td>




</td>
<td>




</td>
<td>




</td>
<td>




</td>
<td>




</td>
<td>




</td>
<td>




</td>
</tr>
<tr>
<th scope="row">


3

</th>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
<td>




</td>
<td>


Y

</td>
</tr>
</tbody>
</table>

- [pixfmt-packed-yuv](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-packed-yuv.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [pixfmt-yuv-planar](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-yuv-planar.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [pixfmt-yuv-luma](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
- [V4L2_PIX_FMT_Y8I ('Y8I ')](</kernel/userspace/userspace-api/media-v4l/pixfmt-y8i.md>)
- [V4L2_PIX_FMT_Y12I ('Y12I')](</kernel/userspace/userspace-api/media-v4l/pixfmt-y12i.md>)
- [V4L2_PIX_FMT_Y16I ('Y16I')](</kernel/userspace/userspace-api/media-v4l/pixfmt-y16i.md>)
- [V4L2_PIX_FMT_UV8 ('UV8')](</kernel/userspace/userspace-api/media-v4l/pixfmt-uv8.md>)
- [V4L2_PIX_FMT_M420 ('M420')](</kernel/userspace/userspace-api/media-v4l/pixfmt-m420.md>)
