L4T Multimedia API Reference

31.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
08_video_dec_drm

Overview

This sample demonstrates how to render video stream or UI with the NVIDIA® Tegra® Direct Rendering Manager (DRM). This sample provides rendering support on non-X11 and lightweight display systems. The DRM is implemented in user-space and is compatible with DRM 2.0.

A DRM is a subsystem of the Linux kernel that interfaces with GPUs.

The sample supports two running modes, depending on the --disable-video option:

  • If specified, the sample draws only the UI on the screen. The UI is a static JPEG image and a moving color block.
  • Otherwise, it displays both the decoded video stream and the UI.

The sample demonstrates the supported DRM buffer allocation policies:

  • Allocated by user. UI stream uses this policy.
  • Allocated by other V4L2 components (decoder or converter), where memory is shared with DRM. Video stream uses this policy.

The sample supports these video formats:

  • H.264
  • H.265


Building and Running

Prerequisites

  • This sample must be run without desktop. Please open a console via SSH or serial connection.
  • You have followed Steps 1-3 in Building and Running.
  • If you are building from your host Linux PC (x86), you have followed Step 4 in Building and Running.

To build:

  • Enter:
     $ cd $HOME/multimedia_api/samples/08_video_dec_drm
     $ make
    

Ensure the Ubuntu desktop is disabled:

   $ sudo systemctl stop gdm
   $ sudo loginctl terminate-seat seat0

If there are two display outputs, unblank the second inactive display:

   $ sudo sh -c 'echo 0 > /sys/class/graphics/fb1/blank'

To run

  • Enter:
     $ ./video_dec_drm <in-file> <in-format> [options]
    

To view supported options

   $ ./video_dec_drm --help

Example: To render only the UI stream

   $ ./video_dec_drm --disable-video

Example: To render only the video stream

   $ ./video_dec_drm ../../data/Video/sample_outdoor_car_1080p_10fps.h264 H264 --disable-ui

Example: To render the UI and video streams

   $ ./video_dec_drm ../../data/Video/sample_outdoor_car_1080p_10fps.h264 H264

Enable the Ubuntu desktop after run

   $ sudo systemctl start gdm


Flow

The following diagram shows the flow of data through the sample.

Flow of Data Through the Sample

The following diagram shows the interactions between the separate threads in the sample.

Thread Processing

Main Thread

If the options include --disable-video, the sample does the following:

  1. Creates DRM renderer for drawing UI.

Otherwise:

  1. Creates the decoder and converter for conversion from YUV422/BL to NV12/PL.
  2. Sets up the decoder output plane.
  3. Feeds data into the decoder output plane, until the EOS is reached.

dec_capture_loop

  1. Sets up decoder capture plane and converter output/capture plane based on the modes user requested.
  2. Creates DRM renderer.
  3. Decodes and converts.
  4. Dequeues the buffer into the DRM for display.

ui_renderer_loop

  1. Draws a static Image on the second plane (the first plane is used for video streaming).
  2. Draws a moving color block on the third plane.

render_dequeue_loop:

  1. Dequeues the buffer from DRM and returns it to the converter capture plane.
    Note
    Because the DRM dequeue operation is a blocking call, you must make the call in separate thread from the enqueue operation.
  2. Detects whether EOS has been reached.

Key Structure and Classes

The following tables shows the key classes and functions that this sample uses.

Class Description
class NvDrmRenderer Contains elements and functions to render frames with tegra DRM.
class NvVideoDecoder Contains all video decoding-related elements and functions.
class NvVideoConverter Contains elements and functions for video format conversion.


FunctionDescription
ui_render_loop_fcn Thread function to render the UI image.
renderer_dequeue_loop_fcn Thread function to dequeue the flipped frame from NvDrmRenderer().
conv0_capture_dqbuf_thread_callback Callback function to enqueue a new frame into NvDrmRenderer.
conv0_output_dqbuf_thread_callback Callback function to receive a frame from decoder and process format conversion.