1 Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
3 @page l4t_mm_video_decode_cuda 02_video_dec_cuda
6 - [Overview](#overview)
7 - [Building and Running](#build_and_run)
9 - [Key Structure and Classes](#key)
11 - - - - - - - - - - - - - - -
15 This sample demonstrates how the buffer allocated by the libv4l2
16 component is used to decode H.265/H.264 video streams, and how CUDA is
17 used aid in rendering images without extra memory copy operations.
19 Supported video formats:
23 <a name=
"build_and_run">
24 - - - - - - - - - - - - - - -
25 ## Building and Running ##
27 #### Prerequisites ####
28 * You have followed Steps 1-3 in @ref mmapi_build.
29 * If you are building from your host Linux PC (x86), you have
30 followed Step 4 in @ref mmapi_build.
35 $ cd $HOME/tegra_multimedia_api/samples/02_video_dec_cuda
41 $ ./video_dec_cuda <in-file> <in-format> [options]
45 - - - - - - - - - - - - - - -
47 The following diagram shows the flow of data through the sample.
49 
51 #### Additional Details
53 The main flow of
this sample is as follows:
55 Tegra provides pitch linear and block linear memory format support on
56 input and output. Input and output memory formats
do not need to
59 ret = ctx->conv->setOutputPlaneFormat(format.fmt.pix_mp.pixelformat,
60 format.fmt.pix_mp.width,
61 format.fmt.pix_mp.height,
62 NvVideoConverter::LAYOUT_BLOCK);
64 This call sets up libv4l2 output plane, i.e.,
for receiving input as
65 YUV data
for decoder, in block linear format. This is the format that
66 complies with Tegra hardware.
68 ret = ctx->conv->setCapturePlaneFormat(format.fmt.pix_mp.pixelformat,
69 format.fmt.pix_mp.width,
70 format.fmt.pix_mp.height,
71 NvVideoConverter::LAYOUT_PITCH);
73 This call sets up the libv4l2 capture plane in pitch linear
74 format. This is the format that is common to the software
78 returns an EGLImage pointer from file descriptor buffer that is
79 allocated by by the member
function of [
NvVideoDecoder](classNvVideoDecoder.html) base
class. An
80 EGLImage buffer is then used by CUDA to render a black box on
81 the display. This is implemented in a separate common routine
using
84 - - - - - - - - - - - - - - -
86 ## Key Structure and Classes ##
88 This sample uses the following key structures and classes:
92 |[
NvVideoDecoder](classNvVideoDecoder.html)|Contains all video decoding-related elements and functions.|
93 |[
NvVideoConverter](classNvVideoConverter.html)|Contains elements and functions
for video format conversion.|
94 |[
NvEglRenderer](classNvEglRenderer.html)|Contains all EGL display rendering-related functions.|
95 |egl_image|The EGLImage used
for CUDA processing.|
96 |conv_output_plane_buf_queue|Output plane queue
for video conversion.|
97 |dec_capture_loop|The thread handler
for decoding capture loop.|
100 functions. Key members used in the sample are:
104 |[output_plane](classNvV4l2Element.html#aaba251827cef1b23e7c42f776e95fee5)|V4l2 output plane.|
105 |[capture_plane](classNvV4l2Element.html#a91806d7ed13b4b2c48758e8a02f46c6d)|V4l2 capture plane.|
106 |[createVideoDecoder](classNvVideoDecoder.html#a47980b18e6f22f1a53c3af732321483d)|Static
function to create video decode
object.|
107 |[subscribeEvent](classNvV4l2Element.html#a7fd9f21268d5fdc979065b1b04b93220)|Subscribe
event.|
108 |[setExtControls](classNvV4l2Element.html#aaec1f40b777bb98870f18766690d7984)|Set external control to V4l2 device.|
109 |[setOutputPlaneFormat](classNvVideoDecoder.html#a7cacbe8afce830495c25514cbd7c8efe)|Set output plane format.|
110 |[setCapturePlaneFormat](classNvVideoDecoder.html#abc20773d70cfafed881238dfda6046ce)|Set capture plane format.|
111 |[getControl](classNvV4l2Element.html#a204f7b6d6f8a4540db8bdcdffe5621ad)|TBD|
112 |[dqEvent](classNvV4l2Element.html#aa475b35ff3fa8ac35b5619c35474f38c)|Dqueue the event which report by V4l2 device.|
113 |[isInError](classNvV4l2Element.html#aa60303288ff142ea08e53fa1dc7a72bf)|Check
if under error state.|
116 functions. Key members used in the sample are:
120 |[output_plane](classNvV4l2Element.html#aaba251827cef1b23e7c42f776e95fee5)|The output plane.|
121 |[capture_plane](classNvV4l2Element.html#a91806d7ed13b4b2c48758e8a02f46c6d)|The capture plane.|
122 |[waitForIdle](classNvVideoConverter.html#a2f5d1a234427862adf9cae7323b5e24c)|TBD|
123 |setOutputPlaneFormat|Set output plane format.|
124 |setCapturePlaneFormat|Set capture plane format.|
127 `output_plane` and `capture_plane`. These 2 objects belong to the same
128 class type [
NvV4l2ElementPlane](group__l4t_mm__nvv4lelementplane__group.html). Key members used in the sample are:
130 |Element|Description|
132 |[setupPlane](classNvV4l2ElementPlane.html#a89959f455e5222f686187cc826b1b345)|Setup the plane of V4l2 element.|
133 |[deinitPlane](classNvV4l2ElementPlane.html#af89cfe87d8f818beb0478bcf5b72574c)|Destroy the plane of V4l2 element.|
134 |[setStreamStatus](classNvV4l2ElementPlane.html#a03164dde4d7ab41f3e92b41e13059316)|Start/Stop the stream.|
135 |[setDQThreadCallback](classNvV4l2ElementPlane.html#a37f213325e0e4857180f5b2319317d6a)|Set the callback
function of dqueue buffer thread.|
136 |[startDQThread](classNvV4l2ElementPlane.html#a31f77f5e5ed1f320caa44a868a7cbedd)|Start the thread of dqueue buffer.|
137 |[stopDQThread](classNvV4l2ElementPlane.html#aa798d14493de321fa90aeab6d944ca87)|Stop the thread of dqueue buffer.|
138 |[qBuffer](classNvV4l2ElementPlane.html#af4d52964fcfd37082f47682e457f5e95)|Queue V4l2 buffer.|
139 |[dqBuffer](classNvV4l2ElementPlane.html#a8dfcbc666ee6f36a02abfb1170ae05cd)|Dqueue V4l2 buffer.|
140 |[getNumBuffers](classNvV4l2ElementPlane.html#ac5cd394a7e0a4afd69395759aeac8787)|Get the number of V4l2 buffer.|
141 |getNumQueuedBuffers|Get the number of V4l2 buffer which under queue.|
142 |[getNthBuffer](classNvV4l2ElementPlane.html#a868d438908f3d267dd4af1033133892f)|TBD|
144 Two global functions are used to create and destroy EGLImage from the
145 dmabuf file descriptor:
147 |Function|Description|
Defines a helper class for V4L2 Video Decoder.
Defines a helper class for operations performed on a V4L2 Element plane.
EGLImageKHR NvEGLImageFromFd(EGLDisplay display, int dmabuf_fd)
This method must be used for getting EGLImage from dmabuf-fd.
Defines a helper class for V4L2 Video Converter.
NvEglRenderer is a helper class for rendering using EGL and OpenGL ES 2.0.
int NvDestroyEGLImage(EGLDisplay display, EGLImageKHR eglImage)
This method must be used for destroying EGLImage object.