# V4L2 Video Decoder

NVIDIA Tegra V4L2 Video Decoder Description and Extensions. More...

## Classes

struct | v4l2_ctrl_videodec_statusmetadata_
| Holds the decoder error status metadata for the frame. More...
struct | v4l2_ctrl_videodec_refframe_metadata_
| Holds the the frame specific metadata for a reference frame. More...
struct | v4l2_ctrl_videodec_currentframe_metadata_
| Holds the the frame specific metadata for the current frame. More...
struct | v4l2_ctrl_videodec_dpbinfometadata_
| Holds the decoder DPB info metadata. More...
struct | v4l2_ctrl_h264dec_bufmetadata_
| Holds H.264 specific decoder metadata for the frame. More...
struct | v4l2_ctrl_hevcdec_bufmetadata_
| Holds H.265 specific decoder metadata for the frame. More...
struct | v4l2_ctrl_videodec_outputbuf_metadata_
| Holds the video decoder output metadata for a frame. More...

## Defines

#define | V4L2_CID_MPEG_VIDEO_DISABLE_COMPLETE_FRAME_INPUT (V4L2_CID_MPEG_BASE+515)
| Control ID to indicate to the decoder that the input buffers will not contain complete buffers.
#define | V4L2_CID_MPEG_VIDEO_DISABLE_DPB (V4L2_CID_MPEG_BASE+516)
| Control ID to disable decoder DPB management.
#define | V4L2_CID_MPEG_VIDEO_ERROR_REPORTING (V4L2_CID_MPEG_BASE+517)
| Control ID to enable decoder error and metadata reporting.
#define | V4L2_CID_MPEG_VIDEO_SKIP_FRAMES (V4L2_CID_MPEG_BASE+518)
| Control ID to set the skip frames property of the decoder.
#define | V4L2_CID_MPEG_VIDEODEC_METADATA (V4L2_CID_MPEG_BASE+519)
| Control ID to get the decoder output metadata.

## Typedefs

typedef struct v4l2_ctrl_videodec_statusmetadata_ | v4l2_ctrl_videodec_statusmetadata
| Holds the decoder error status metadata for the frame.
typedef struct v4l2_ctrl_videodec_refframe_metadata_ | v4l2_ctrl_videodec_refframe_metadata
| Holds the the frame specific metadata for a reference frame.
typedef struct v4l2_ctrl_videodec_currentframe_metadata_ | v4l2_ctrl_videodec_currentframe_metadata
| Holds the the frame specific metadata for the current frame.
typedef struct v4l2_ctrl_videodec_dpbinfometadata_ | v4l2_ctrl_videodec_dpbinfometadata
| Holds the decoder DPB info metadata.
typedef struct v4l2_ctrl_h264dec_bufmetadata_ | v4l2_ctrl_h264dec_bufmetadata
| Holds H.264 specific decoder metadata for the frame.
typedef struct v4l2_ctrl_hevcdec_bufmetadata_ | v4l2_ctrl_hevcdec_bufmetadata
| Holds H.265 specific decoder metadata for the frame.
typedef struct v4l2_ctrl_videodec_outputbuf_metadata_ | v4l2_ctrl_videodec_outputbuf_metadata
| Holds the video decoder output metadata for a frame.

## Enumerations

enum | v4l2_skip_frames_type { V4L2_SKIP_FRAMES_TYPE_NONE = 0, V4L2_SKIP_FRAMES_TYPE_NONREF = 1, V4L2_SKIP_FRAMES_TYPE_DECODE_IDR_ONLY = 2 }
| Enum v4l2_skip_frames_type, possible methods for decoder skip frames. More...

## Detailed Description

NVIDIA Tegra V4L2 Video Decoder Description and Extensions.

The video decoder device node is "/dev/nvhost-nvdec".

### Supported pixelformats: OUTPUT PLANE | CAPTURE PLANE :----------------: | :----------------: V4L2_PIX_FMT_H264 | V4L2_PIX_FMT_NV12M V4L2_PIX_FMT_H265 | V4L2_PIX_FMT_NV12M

### Supported memory types: MEMORY | OUTPUT PLANE | CAPTURE PLANE :------------------: | :----------: | :-----------: V4L2_MEMORY_MMAP | Y | Y V4L2_MEMORY_DMABUF | N | N V4L2_MEMORY_USERPTR | N | N

### Supported controls:

- V4L2_CID_MPEG_VIDEO_DISABLE_COMPLETE_FRAME_INPUT
- V4L2_CID_MPEG_VIDEO_DISABLE_DPB
- V4L2_CID_MPEG_VIDEO_ERROR_REPORTING
- V4L2_CID_MPEG_VIDEO_SKIP_FRAMES
- V4L2_CID_MIN_BUFFERS_FOR_CAPTURE (Get the minimum buffers to be allocated on capture plane. Read only. Valid after V4L2_EVENT_RESOLUTION_CHANGE)
- V4L2_CID_MPEG_VIDEODEC_METADATA

### Supported events: Event | Purpose ----------------------------- | :----------------------------: V4L2_EVENT_RESOLUTION_CHANGE | Resolution of the stream has changed.

### Handling resolution change events: When the decoder generates a V4L2_EVENT_RESOLUTION_CHANGE event, the application should call STREAMOFF on the capture plane, tell decoder to deallocate the current buffers by calling REQBUF with count zero, get the new capture plane format, and then proceed with setting up the buffers for the capture plane.

In case of decoder, the buffer format might differ from the Display resolution. The application should use VIDIOC_G_CROP to get the display resolution.

### EOS Handling: Following sequence should be followed for sending EOS and recieving EOS from the decoder.

1. Send EOS to decoder by queueing on the output plane a buffer with bytesused = 0 for the 0th plane (`v4l2_buffer.m.planes[0].bytesused = 0`).
2. Dequeue buffers on the output plane, till it gets a buffer with bytesused = 0 for the 0th plane (`v4l2_buffer.m.planes[0].bytesused == 0`)
3. Dequeue buffers on the capture plane, till it gets a buffer with bytesused = 0 for the 0th plane.

### Decoder output frame metadata: Decoder supports reporting frame related metadata including error reports and DPB info. See V4L2_CID_MPEG_VIDEO_ERROR_REPORTING, V4L2_CID_MPEG_VIDEODEC_METADATA and v4l2_ctrl_video_metadata for more information.

## Define Documentation

#define V4L2_CID_MPEG_VIDEO_DISABLE_COMPLETE_FRAME_INPUT (V4L2_CID_MPEG_BASE+515)

Control ID to indicate to the decoder that the input buffers will not contain complete buffers.

Note:
  This control should be set in case of frames containing multiple slices when the input buffers do not contain all the slices of the frame.

A boolean value should be supplied with this control.

Attention:
  This control should be set before setting formats on either plane.

Definition at line 426 of file v4l2_nv_extensions.h.

#define V4L2_CID_MPEG_VIDEO_DISABLE_DPB (V4L2_CID_MPEG_BASE+516)

Control ID to disable decoder DPB management.

Note:
  This will only work for streams having a single reference frame.

A boolean value should be supplied with this control.

Attention:
  This control should be set after setting formats on both the planes and before requesting buffers on either plane.

Definition at line 438 of file v4l2_nv_extensions.h.

#define V4L2_CID_MPEG_VIDEO_ERROR_REPORTING (V4L2_CID_MPEG_BASE+517)

Control ID to enable decoder error and metadata reporting.

A boolean value should be supplied with this control.

Attention:
  This control should be set after setting formats on both the planes and before requesting buffers on either plane.

Definition at line 448 of file v4l2_nv_extensions.h.

#define V4L2_CID_MPEG_VIDEO_SKIP_FRAMES (V4L2_CID_MPEG_BASE+518)

Control ID to set the skip frames property of the decoder.

Decoder can be configured to skip certain types of frames. One of v4l2_skip_frames_type should be passed.

Attention:
  This control should be set after setting formats on both the planes and before requesting buffers on either plane. This control ID is supported only for H264.

Definition at line 460 of file v4l2_nv_extensions.h.

#define V4L2_CID_MPEG_VIDEODEC_METADATA (V4L2_CID_MPEG_BASE+519)

Control ID to get the decoder output metadata.

Note:
  Metadata reporting should be enabled using V4L2_CID_MPEG_VIDEO_ERROR_REPORTING ioctl for this.

A pointer to a valid v4l2_ctrl_video_metadata structure should be supplied with this control.

Attention:
  This control should be read after dequeueing a buffer successfully from the capture plane. The values in the structure are valid till the buffer is queued again.

Definition at line 475 of file v4l2_nv_extensions.h.

## Typedef Documentation

typedef struct v4l2_ctrl_h264dec_bufmetadata_ v4l2_ctrl_h264dec_bufmetadata

Holds H.264 specific decoder metadata for the frame.

typedef struct v4l2_ctrl_hevcdec_bufmetadata_ v4l2_ctrl_hevcdec_bufmetadata

Holds H.265 specific decoder metadata for the frame.

typedef struct v4l2_ctrl_videodec_currentframe_metadata_ v4l2_ctrl_videodec_currentframe_metadata

Holds the the frame specific metadata for the current frame.

typedef struct v4l2_ctrl_videodec_dpbinfometadata_ v4l2_ctrl_videodec_dpbinfometadata

Holds the decoder DPB info metadata.

typedef struct v4l2_ctrl_videodec_outputbuf_metadata_ v4l2_ctrl_videodec_outputbuf_metadata

Holds the video decoder output metadata for a frame.

typedef struct v4l2_ctrl_videodec_refframe_metadata_ v4l2_ctrl_videodec_refframe_metadata

Holds the the frame specific metadata for a reference frame.

typedef struct v4l2_ctrl_videodec_statusmetadata_ v4l2_ctrl_videodec_statusmetadata

Holds the decoder error status metadata for the frame.

## Enumeration Type Documentation

enum v4l2_skip_frames_type

Enum v4l2_skip_frames_type, possible methods for decoder skip frames.

Enumerator:

  V4L2_SKIP_FRAMES_TYPE_NONE | Do not skip any frame.
  V4L2_SKIP_FRAMES_TYPE_NONREF | Skip all non-reference frames.
  V4L2_SKIP_FRAMES_TYPE_DECODE_IDR_ONLY | Skip all frames except IDR.

Definition at line 809 of file v4l2_nv_extensions.h.