L4T Multimedia API Reference

28.2 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
multimedia_api/ll_samples/docs/l4t_mm_backend.md
Go to the documentation of this file.
1 Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
2 <!-- Sample is in the backend dir. -->
3 
4 @page nvvid_backend_group Backend
5 @{
6 
7  - [Overview](#overview)
8  - [Building and Running](#build_and_run)
9  - [Flow](#flow)
10  - [Command Line Options](#options)
11  - [Key Structure and Classes](#key)
12 
13 - - - - - - - - - - - - - - -
14 <a name="overview">
15 ## Overview ##
16 
17 This application implements a typical appliance performing intelligent video analytics.
18 Application areas include public safety, smart cities, and autonomous machines. This example demonstrates
19 four (4) concurrent video streams going through a decoding process using the on-chip decoders, video scaling using on
20 chip scalar, and GPU compute. For simplicity of demonstration, only one of the channels uses
21 NVIDIA<sup>&reg;</sup> TensorRT<sup>&trade;</sup> to perform object identification
22 and generate bounding box around the identified object. This sample also uses video converter functions
23 for various format conversions. It also uses EGLImage to demonstrate buffer sharing and image display.
24 
25 In this sample, object detection is limited to identifying cars in video streams
26 of 960 x 540 resolution, running up to 14 FPS. The network is based on
27 GoogleNet. The inference is performed on a frame-by-frame basis and no object
28 tracking is involved. Note that this network is intended to be an example
29 that shows how to use TensorRT to quickly build the compute pipeline. The sample
30 includes trained GoogleNet, which was trained with NVIDIA Deep Learning GPU
31 Training System (DIGITS). The training was done with roughly
32 3000 frames taken from 5-10 feet elevation. Varying levels of detection accuracy
33 are expected based on the video samples fed in. Given that this sample is locked
34 to perform at half-HD resolutions under 10 FPS, video feeds with higher FPS for
35 inference will show stuttering during playback.
36 
37 This sample does not require a camera.
38 
39 <a name="build_and_run">
40 ## Building and Running ##
41 
42 #### Prerequisites ####
43 * You have followed Steps 1-3 in @ref mmapi_build.
44 * You have installed:
45  * CUDA Toolkit
46  * OpenCV
47 * Optionally, you have installed NVIDIA<sup>&reg;</sup>
48  TensorRT<sup>&trade;</sup> (previously known as GPU Inference Engine (GIE))
49 
50 ### To build
51 1. If you want to run the sample without TensorRT, set the following in the Makefile:
52 
53  ENABLETRT := 0
54  By default, TensorRT is enabled.
55 
56 2. Enter:
57 
58  $ cd backend
59  $ make
60 
61 ### To run
62 * Enter:
63 
64  $ ./backend 1 ../../data/Video/sample_outdoor_car_1080p_10fps.h264 H264 \
65  --trt-deployfile ../../data/Model/GoogleNet_one_class/GoogleNet_modified_oneClass_halfHD.prototxt \
66  --trt-modelfile ../../data/Model/GoogleNet_one_class/GoogleNet_modified_oneClass_halfHD.caffemodel \
67  --trt-forcefp32 0 --trt-proc-interval 1 -fps 10
68 
69  @note The TensorRT batch size can be configured from the third line of the following file:
70 
71  ../../data/Model/GoogleNet_one_class/GoogleNet_modified_oneClass_halfHD.prototxt
72  Where the valid values are 1(default), or 2, or 4.
73 
74 . <!-- leave this period alone. It forces Doxygen to stop indenting. -->
75 
76 ### To quit
77 * Enter `q`.
78 
79 ### To view command-line options
80 * Enter:
81 
82  $ cd backend
83  $ ./backend -h
84 
85 
86 <a name="flow">
87 - - - - - - - - - - - - - - -
88 ## Flow
89 
90 The following image shows the movement of data through the sample when TensorRT
91 is not enabled.
92 
93 ![ ](l4t_mm_backend_one.jpg)
94 
95 The following image shows data flow details for the channel using TensorRT.
96 
97 ![ ](l4t_mm_backend_two.jpg)
98 
99 `NvEGLImageFromFd` is an NVIDIA API that returns an `EGLImage` pointer from the file
100 descriptor buffer that is allocated via the Tegra mechanism. TensorRT then uses
101 the `EGLImage` buffer to render the bounding box to the image.
102 
103 ### X11 Details
104 For X11 technical details, see:
105 
106 http://www.x.org/docs/X11/xlib.pdf
107 
108 - - - - - - - - - - - - - - -
109 <a name="key">
110 ## Key Structure and Classes ##
111 
112 The `context_t structure` (backend/v4l2_backend_test.h) manages all resources in sample applications.
113 
114 |Element|Description|
115 |-------|-----------|
116 |[NvVideoDecoder](classNvVideoDecoder.html)|Contains all video decoding-related elements and functions.|
117 |[NvVideoConverter](classNvVideoConverter.html)|Contains elements and functions for video format conversion.|
118 |NvEglRenderer|Contains all EGL display rendering-related functions.|
119 |EGLImageKHR|The EGLImage used for CUDA processing. This type is from the EGL open source graphical library.|
120 
121 ### %NvVideoDecoder ###
122 
123 The [NvVideoDecoder](classNvVideoDecoder.html) class creates a new V4L2 Video Decoder.
124 The following table describes the key %NvVideoDecoder members that this sample uses.
125 
126 |Member|Description|
127 |-------------|---|
128 |NvV4l2Element::output_plane |Holds the V4L2 output plane.|
129 |NvV4l2Element::capture_plane |Holds the V4L2 capture plane.|
130 |NvVideoDecoder::createVideoDecoder |Static function to create video decode object.|
131 |NvV4l2Element::subscribeEvent |Subscribes event.|
132 |NvVideoDecoder::setExtControls |Sets external control to V4L2 device.|
133 |NvVideoDecoder::setOutputPlaneFormat |Sets output plane format.|
134 |NvVideoDecoder::setCapturePlaneFormat |Sets capture plane format.|
135 |NvV4l2Element::getControl |Gets the value of a control setting.|
136 |NvV4l2Element::dqEvent |Dequeues the devent reported by the V4L2 device.|
137 |NvV4l2Element::isInError |Checks if under error state.|
138 
139 ### %NvVideoConverter ###
140 
141 The NvVideoConverter class packages all video
142 converting related elements and functions. It performs color space conversion,
143 scaling and conversion between hardware buffer memory and software buffer
144 memory. The following table describes the key %NvVideoConverter members that
145 this sample uses.
146 
147 |Member|Description|
148 |-------------|---|
149 |NvV4l2Element::output_plane |Holds the output plane.|
150 |NvV4l2Element::capture_plane |Holds the capture plane.|
151 |NvVideoConverter::waitForIdle |Waits until all the buffers queued on the output plane are converted and dequeued from the capture plane. This is a blocking method.|
152 |NvVideoConverter::setCapturePlaneFormat |Sets the format on the converter capture plane.|
153 |NvVideoConverter::setOutputPlaneFormat |Sets the format on the converter output plane.|
154 
155 `NvVideoDecoder` and `NvVideoConverter` contain two key elements:
156 `output_plane` and `capture_plane`. These objects are instantiated from the
157 NvV4l2ElementPlane class type.
158 
159 ### %NvV4l2ElementPlane ###
160 
161 [NvV4l2ElementPlane](group__l4t_mm__nvv4lelementplane__group.html) creates an [NVv4l2Element](classNvV4l2Element.html) plane.
162 The following table describes the key %NvV4l2ElementPlane members used in this
163 sample. `v4l2_buf` is a local variable inside the NvV4l2ElementPlane::dqThreadCallback
164 function and, thus, the scope exists only inside the callback function. If other
165 functions of the sample must access this buffer, a prior copy of the buffer
166 inside callback function is required.
167 
168 |Member |Description|
169 |-------------------|---|
170 |NvV4l2ElementPlane::setupPlane |Sets up the plane of V4l2 element.|
171 |NvV4l2ElementPlane::deinitPlane |Destroys the plane of V4l2 element.|
172 |NvV4l2ElementPlane::setStreamStatus |Starts/Stops the stream.|
173 |NvV4l2ElementPlane::setDQThreadCallback |Sets the callback function of the `dqueue` buffer thread.|
174 |NvV4l2ElementPlane::startDQThread |Starts the thread of the `dqueue` buffer.|
175 |NvV4l2ElementPlane::stopDQThread |Stops the thread of the `dqueue` buffer.|
176 |NvV4l2ElementPlane::qBuffer |Queues a V4l2 buffer from the plane.|
177 |NvV4l2ElementPlane::dqBuffer |Dequeues a V4l2 buffer from the plane.|
178 |NvV4l2ElementPlane::getNumBuffers |Gets the number of the V4l2 buffer.|
179 |NvV4l2ElementPlane::getNumQueuedBuffers |Gets the number of the V4l2 buffer in the queue.|
180 |NvV4l2ElementPlane::getNthBuffer |Gets the \c %NvBuffer queue object at index N.|
181 
182 
183 ### %TRT_Context ###
184 
185 TRT_Context provides a
186 series of interfaces to load Caffe model and perform inference. The following
187 table describes the key %TRT_Context members used in this sample.
188 
189 |%TRT_Context|Description|
190 |-----------|-----------|
191 |TRT_Context::destroyTrtContext |Destroys the TRT_context.|
192 |TRT_Context::getNumTrtInstances |Gets the number of TRT_context instances.|
193 |TRT_Context::doInference |Interface for inference after TensorRT model is loaded.|
194 
195 ### Functions to Create/Destroy EGLImage ##
196 
197 The sample uses 2 global functions to create and destroy EGLImage from `dmabuf`
198 file descriptor. These functions are defined in nvbuf_utils.h.
199 
200 |Global Function|Description|
201 |---------------|-----------|
202 |NvEGLImageFromFd() |Creates EGLImage from dmabuf fd.|
203 |NvDestroyEGLImage() |Destroys the EGLImage.|
204 
static NvVideoDecoder * createVideoDecoder(const char *name, int flags=0)
Creates a new V4L2 Video Decoder object named name.
void destroyTrtContext(bool bUseCPUBuf=false)
void doInference(queue< vector< cv::Rect > > *rectList_queue, float *input=NULL)
Defines a helper class for V4L2 Video Decoder.
int dqEvent(struct v4l2_event &event, uint32_t max_wait_ms)
Dequeues an event from the element.
Defines a helper class for operations performed on a V4L2 Element plane.
int setCapturePlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height, enum v4l2_nv_buffer_layout type)
Sets the format on the converter output plane.
NvV4l2ElementPlane capture_plane
Sets the capture plane.
Class representing a buffer.
Definition: NvBuffer.h:85
NvV4l2ElementPlane output_plane
Sets the output plane.
int setOutputPlaneFormat(uint32_t pixfmt, uint32_t sizeimage)
Sets the format on the decoder output plane.
virtual int isInError()
EGLImageKHR NvEGLImageFromFd(EGLDisplay display, int dmabuf_fd)
This method must be used for getting EGLImage from dmabuf-fd.
int getControl(uint32_t id, int32_t &value)
Gets the value of a control.
Defines a helper class for V4L2 Video Converter.
int setCapturePlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height)
Sets the format on the decoder output plane.
int setExtControls(struct v4l2_ext_controls &ctl)
Sets the value of several controls.
uint32_t getNumTrtInstances() const
int waitForIdle(uint32_t max_wait_ms)
Waits until all buffers queued on the output plane are converted and dequeued from the capture plane...
NvEglRenderer is a helper class for rendering using EGL and OpenGL ES 2.0.
Definition: NvEglRenderer.h:74
int subscribeEvent(uint32_t type, uint32_t id, uint32_t flags)
Subscribes to an V4L2 event.
int setOutputPlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height, enum v4l2_nv_buffer_layout type)
Sets the format on the converter output plane.
int NvDestroyEGLImage(EGLDisplay display, EGLImageKHR eglImage)
This method must be used for destroying EGLImage object.