L4T Multimedia API Reference

28.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NvDrmRenderer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
3  * NVIDIA CORPORATION and its licensors retain all intellectual property
4  * and proprietary rights in and to this software, related documentation
5  * and any modifications thereto. Any use, reproduction, disclosure or
6  * distribution of this software and related documentation without an express
7  * license agreement from NVIDIA CORPORATION is strictly prohibited.
8  */
9 
17 #ifndef __NV_DRM_RENDERER_H__
18 #define __NV_DRM_RENDERER_H__
19 
20 #include "NvElement.h"
21 #include <stdint.h>
22 #include <pthread.h>
23 #include <queue>
24 #include <unordered_map>
25 
35 typedef struct _NvDrmBO {
36  uint32_t bo_handle;
37  int width;
38  int height;
39  int pitch;
40  uint8_t* data;
41 } NvDrmBO;
42 
44 typedef struct _NvDrmFB {
45  uint32_t fb_id;
46  int width;
47  int height;
48  int format;
51  NvDrmBO bo[4];
53 } NvDrmFB;
54 
55 
67 {
68 public:
82  static NvDrmRenderer *createDrmRenderer(const char *name, uint32_t width,
83  uint32_t height, uint32_t w_x, uint32_t w_y,
84  uint32_t connector, uint32_t crtc);
86 
98  int enqueBuffer(int fd);
99 
111  int dequeBuffer();
112 
121  int setFPS(float fps);
122 
130  bool enableUniversalPlanes(int enable);
131 
146  uint32_t createDumbFB(uint32_t width, uint32_t height, uint32_t drm_format, NvDrmFB *fb);
147 
157  int removeFB(uint32_t fb_id);
158 
185  int setPlane(uint32_t pl_index,
186  uint32_t fb_id,
187  uint32_t crtc_x,
188  uint32_t crtc_y,
189  uint32_t crtc_w,
190  uint32_t crtc_h,
191  uint32_t src_x,
192  uint32_t src_y,
193  uint32_t src_w,
194  uint32_t src_h);
195 
206  int getPlaneCount();
207 
213  int getCrtcCount();
214 
220  int getEncoderCount();
221 
222 private:
223 
224  struct timespec last_render_time;
226  int drm_fd;
227  int conn, crtc;
228  uint32_t width, height;
229  uint32_t drm_conn_id;
230  uint32_t drm_enc_id;
231  uint32_t drm_crtc_id;
232  uint32_t last_fb;
233  int activeFd;
234  int flippedFd;
235  bool flipPending;
236  bool renderingStarted;
237 
238  std::queue<int> freeBuffers;
239  std::queue<int> pendingBuffers;
240  std::unordered_map <int, int> map_list;
241 
242  bool stop_thread;
244  pthread_t render_thread;
246  pthread_mutex_t render_lock;
247  pthread_cond_t render_cond;
248  pthread_mutex_t enqueue_lock;
249  pthread_cond_t enqueue_cond;
250  pthread_mutex_t dequeue_lock;
251  pthread_cond_t dequeue_cond;
253  float fps;
254  uint64_t render_time_sec;
256  uint64_t render_time_nsec;
261  NvDrmRenderer(const char *name, uint32_t width, uint32_t height,
262  uint32_t w_x, uint32_t w_y,
263  uint32_t connector, uint32_t crtc);
264 
272  static void * renderThread(void *arg);
273 
278  static void page_flip_handler(int fd, unsigned int frame,
279  unsigned int sec, unsigned int usec, void *data);
280 
285  int renderInternal(int fd);
286 
287  /*
288  * Returns a DRM buffer_object handle allocated of size (w,h)
289  */
290  int createDumbBO(int w, int h, int bpp, NvDrmBO *bo);
291 };
292 
294 #endif
Helper class for rendering using LibDRM.
Definition: NvDrmRenderer.h:66
int setFPS(float fps)
Sets the rendering rate in terms of frames per second.
uint32_t createDumbFB(uint32_t width, uint32_t height, uint32_t drm_format, NvDrmFB *fb)
Allocates a framebuffer of size (w, h).
static NvDrmRenderer * createDrmRenderer(const char *name, uint32_t width, uint32_t height, uint32_t w_x, uint32_t w_y, uint32_t connector, uint32_t crtc)
Creates a new DRM based renderer named name.
Holds information about the frame.
Definition: NvDrmRenderer.h:44
Holds a buffer object handle.
Definition: NvDrmRenderer.h:35
int format
Frame format, such as DRM_FORMAT_RGB332.
Definition: NvDrmRenderer.h:48
int getCrtcCount()
Gets count of available crtcs.
int getEncoderCount()
Gets count of available encoders.
int setPlane(uint32_t pl_index, uint32_t fb_id, uint32_t crtc_x, uint32_t crtc_y, uint32_t crtc_w, uint32_t crtc_h, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h)
Changes a plane's framebuffer and position.
NVIDIA Multimedia API: NvElement Base Class
uint32_t bo_handle
DRM buffer index.
Definition: NvDrmRenderer.h:36
int getPlaneCount()
Gets total number of planes available.
uint32_t fb_id
Frame ID.
Definition: NvDrmRenderer.h:45
Every element has a unique name that can be used for identifying the element in debug logs...
Definition: NvElement.h:63
struct _NvDrmFB NvDrmFB
Holds information about the frame.
int removeFB(uint32_t fb_id)
Destroys a framebuffer.
bool enableUniversalPlanes(int enable)
Enables/disables DRM universal planes client caps, such as DRM_CLIENT_CAP_UNIVERSAL_PLANES.
int pitch
Memory layout of the DRM buffer.
Definition: NvDrmRenderer.h:39
int enqueBuffer(int fd)
Enqueues a buffer fd for rendering.
int width
Width of the DRM buffer, in pixels.
Definition: NvDrmRenderer.h:37
struct _NvDrmBO NvDrmBO
Holds a buffer object handle.
int height
Height of the frame, in pixels.
Definition: NvDrmRenderer.h:47
int num_buffers
Number of DRM buffers, which depends on the buffer format.
Definition: NvDrmRenderer.h:52
uint8_t * data
Mapped CPU accessible address.
Definition: NvDrmRenderer.h:40
int width
Width of the frame, in pixels.
Definition: NvDrmRenderer.h:46
NvDrmBO bo[4]
DRM buffer handles.
Definition: NvDrmRenderer.h:51
int height
Heigth of the DRM buffer, in pixels.
Definition: NvDrmRenderer.h:38
int dequeBuffer()
Dequeues a previously rendered buffer.