L4T Multimedia API Reference

32.2 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
02_video_dec_cuda

Overview

This sample demonstrates how the buffer allocated by the libv4l2 component is used to decode H.265/H.264 video streams, and how CUDA is used aid in rendering images without extra memory copy operations.

Supported video formats:

  • H.264
  • H.265


Building and Running

Prerequisites

To build:

  • Enter:
     $ cd $HOME/tegra_multimedia_api/samples/02_video_dec_cuda
     $ make
    

To run

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

Example

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


Flow

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

Additional Details

The main flow of this sample is as follows:

Tegra provides pitch linear and block linear memory format support on input and output. Input and output memory formats do not need to match.

    ret = ctx->conv->setOutputPlaneFormat(format.fmt.pix_mp.pixelformat,
                                              format.fmt.pix_mp.width,
                                              format.fmt.pix_mp.height,
                                              NvVideoConverter::LAYOUT_BLOCK);

This call sets up libv4l2 output plane, i.e., for receiving input as YUV data for decoder, in block linear format. This is the format that complies with Tegra hardware.

    ret = ctx->conv->setCapturePlaneFormat(format.fmt.pix_mp.pixelformat,
                                               format.fmt.pix_mp.width,
                                               format.fmt.pix_mp.height,
                                               NvVideoConverter::LAYOUT_PITCH);

This call sets up the libv4l2 capture plane in pitch linear format. This is the format that is common to the software implementation.

NvEGLImageFromFd is syntax error that returns an EGLImage pointer from file descriptor buffer that is allocated by by the member function of NvVideoDecoder base class. An EGLImage buffer is then used by CUDA to render a black box on the display. This is implemented in a separate common routine using EGLImage.


Key Structure and Classes

This sample uses the following key structures and classes:

ElementDescription
NvVideoDecoderContains all video decoding-related elements and functions.
NvVideoConverterContains elements and functions for video format conversion.
NvEglRendererContains all EGL display rendering-related functions.
egl_imageThe EGLImage used for CUDA processing.
conv_output_plane_buf_queueOutput plane queue for video conversion.
dec_capture_loopThe thread handler for decoding capture loop.

NvVideoDecoder packages all video decoding-related elements and functions. Key members used in the sample are:

MemberDescription
output_planeV4l2 output plane.
capture_planeV4l2 capture plane.
createVideoDecoderStatic function to create video decode object.
subscribeEventSubscribe event.
setExtControlsSet external control to V4l2 device.
setOutputPlaneFormatSet output plane format.
setCapturePlaneFormatSet capture plane format.
getControlTBD
dqEventDqueue the event which report by V4l2 device.
isInErrorCheck if under error state.

NvVideoConverter packages all video converting-related elements and functions. Key members used in the sample are:

MemberDescription
output_planeThe output plane.
capture_planeThe capture plane.
waitForIdleTBD
setOutputPlaneFormatSet output plane format.
setCapturePlaneFormatSet capture plane format.

Both NvVideoDecoder and NvVideoConverter contain 2 key elements: output_plane and capture_plane. These 2 objects belong to the same class type NvV4l2ElementPlane. Key members used in the sample are:

ElementDescription
setupPlaneSetup the plane of V4l2 element.
deinitPlaneDestroy the plane of V4l2 element.
setStreamStatusStart/Stop the stream.
setDQThreadCallbackSet the callback function of dqueue buffer thread.
startDQThreadStart the thread of dqueue buffer.
stopDQThreadStop the thread of dqueue buffer.
qBufferQueue V4l2 buffer.
dqBufferDqueue V4l2 buffer.
getNumBuffersGet the number of V4l2 buffer.
getNumQueuedBuffersGet the number of V4l2 buffer which under queue.
getNthBufferTBD

Two global functions are used to create and destroy EGLImage from the dmabuf file descriptor:

FunctionDescription
NvEGLImageFromFdCreate EGLImage from dmabuf file descriptor.
NvDestroyEGLImageDestroy the EGLImage.