L4T Multimedia API Reference

28.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
multimedia_api/ll_samples/docs/l4t_mm_video_decode_cuda.md
Go to the documentation of this file.
1 Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
2 
3 @page l4t_mm_video_decode_cuda 02_video_dec_cuda
4 @{
5 
6  - [Overview](#overview)
7  - [Building and Running](#build_and_run)
8  - [Flow](#flow)
9  - [Key Structure and Classes](#key)
10 
11 - - - - - - - - - - - - - - -
12 <a name="overview">
13 ## Overview ##
14 
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.
18 
19 Supported video formats:
20 - H.264
21 - H.265
22 
23 <a name="build_and_run">
24 - - - - - - - - - - - - - - -
25 ## Building and Running ##
26 
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.
31 
32 ### To build:
33 * Enter:
34 
35  $ cd $HOME/tegra_multimedia_api/samples/02_video_dec_cuda
36  $ make
37 
38 ### To run
39 * Enter:
40 
41  $ ./video_dec_cuda <in-file> <in-format> [options]
42 
43 
44 <a name="flow">
45 - - - - - - - - - - - - - - -
46 ##Flow
47 The following diagram shows the flow of data through the sample.
48 
49 ![](l4t_mm_video_dec_cuda.jpg)
50 
51 #### Additional Details
52 
53 The main flow of this sample is as follows:
54 
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
57 match.
58 
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);
63 
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.
67 
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);
72 
73 This call sets up the libv4l2 capture plane in pitch linear
74 format. This is the format that is common to the software
75 implementation.
76 
77 `NvEGLImageFromFd` is syntax error that
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
82 EGLImage.
83 
84 - - - - - - - - - - - - - - -
85 <a name="key">
86 ## Key Structure and Classes ##
87 
88 This sample uses the following key structures and classes:
89 
90 |Element|Description|
91 |---|---|
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.|
98 
99 %NvVideoDecoder packages all video decoding-related elements and
100 functions. Key members used in the sample are:
101 
102 |Member|Description|
103 |---|---|
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.|
114 
115 %NvVideoConverter packages all video converting-related elements and
116 functions. Key members used in the sample are:
117 
118 |Member|Description|
119 |---|---|
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.|
125 
126 Both %NvVideoDecoder and %NvVideoConverter contain 2 key elements:
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:
129 
130 |Element|Description|
131 |---|---|
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|
143 
144 Two global functions are used to create and destroy EGLImage from the
145 dmabuf file descriptor:
146 
147 |Function|Description|
148 |---|---|
149 |NvEGLImageFromFd|Create EGLImage from dmabuf file descriptor.|
150 |NvDestroyEGLImage|Destroy the EGLImage.|
151 
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.
Definition: NvEglRenderer.h:74
int NvDestroyEGLImage(EGLDisplay display, EGLImageKHR eglImage)
This method must be used for destroying EGLImage object.