nvbuf_utils.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. /*
  2. * Copyright (c) 2016-2022, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * NVIDIA Corporation and its licensors retain all intellectual property
  5. * and proprietary rights in and to this software, related documentation
  6. * and any modifications thereto. Any use, reproduction, disclosure or
  7. * distribution of this software and related documentation without an express
  8. * license agreement from NVIDIA Corporation is strictly prohibited.
  9. */
  10. /**
  11. * @file
  12. * <b>NVIDIA Multimedia Utilities: Buffering and Transform/Composition/Blending</b>
  13. *
  14. */
  15. /**
  16. * @defgroup ee_nvbuffering_group NvBufUtils API (Deprecated)
  17. * @ingroup ds_nvbuf_api
  18. * NVIDIA buffering utility library for use by applications.
  19. * The utility also transforms, composits, and blends.
  20. * @{
  21. */
  22. #ifndef _NVBUF_UTILS_H_
  23. #define _NVBUF_UTILS_H_
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. #include <EGL/egl.h>
  29. #include <EGL/eglext.h>
  30. #include <errno.h>
  31. #include <stdbool.h>
  32. /**
  33. * Defines the maximum number of planes for a video frame.
  34. */
  35. #define MAX_NUM_PLANES 4
  36. /**
  37. * Defines the maximum number of input video frames that can be used for composition.
  38. */
  39. #define MAX_COMPOSITE_FRAME 16
  40. /**
  41. * Defines the default values for chroma subsampling.
  42. * The default value matches JPEG/MPEG use cases.
  43. */
  44. #define NVBUF_CHROMA_SUBSAMPLING_HORIZ_DEFAULT 0
  45. #define NVBUF_CHROMA_SUBSAMPLING_VERT_DEFAULT 1
  46. /**
  47. * Defines the maximum number of sync object parameters.
  48. */
  49. #define NVBUF_MAX_SYNCOBJ_PARAMS 5
  50. /**
  51. * Use this value to represent an infinite wait interval.
  52. * A value of zero should not be interpreted as infinite,
  53. * it should be interpreted as "time out immediately" and
  54. * simply check whether the event has already happened.
  55. */
  56. #define NVBUFFER_SYNCPOINT_WAIT_INFINITE 0xFFFFFFFF
  57. /**
  58. * Defines Payload types for NvBuffer.
  59. */
  60. typedef enum
  61. {
  62. /** buffer payload with hardware memory handle for set of planes. */
  63. NvBufferPayload_SurfArray,
  64. /** buffer payload with hardware memory handle for specific memory size. */
  65. NvBufferPayload_MemHandle,
  66. } NvBufferPayloadType;
  67. /**
  68. * Defines display scan formats for NvBuffer video planes.
  69. */
  70. typedef enum
  71. {
  72. /** Progessive scan formats. */
  73. NvBufferDisplayScanFormat_Progressive = 0,
  74. /** Interlaced scan formats. */
  75. NvBufferDisplayScanFormat_Interlaced,
  76. } NvBufferDisplayScanFormat;
  77. /**
  78. * Defines Layout formats for NvBuffer video planes.
  79. */
  80. typedef enum
  81. {
  82. /** Pitch Layout. */
  83. NvBufferLayout_Pitch,
  84. /** BlockLinear Layout. */
  85. NvBufferLayout_BlockLinear,
  86. } NvBufferLayout;
  87. /**
  88. * Defines memory access flags for NvBuffer.
  89. */
  90. typedef enum
  91. {
  92. /** Memory read. */
  93. NvBufferMem_Read,
  94. /** Memory write. */
  95. NvBufferMem_Write,
  96. /** Memory read & write. */
  97. NvBufferMem_Read_Write,
  98. } NvBufferMemFlags;
  99. /**
  100. * Defines tags that identify the components requesting a memory allocation.
  101. * The tags can be used later to identify the total memory allocated to
  102. * particular types of components.
  103. */
  104. typedef enum
  105. {
  106. /** tag None. */
  107. NvBufferTag_NONE = 0x0,
  108. /** tag for Camera. */
  109. NvBufferTag_CAMERA = 0x200,
  110. /** tag for Jpeg Encoder/Decoder. */
  111. NvBufferTag_JPEG = 0x1500,
  112. /** tag for VPR Buffers. */
  113. NvBufferTag_PROTECTED = 0x1504,
  114. /** tag for H264/H265 Video Encoder. */
  115. NvBufferTag_VIDEO_ENC = 0x1200,
  116. /** tag for H264/H265/VP9 Video Decoder. */
  117. NvBufferTag_VIDEO_DEC = 0x1400,
  118. /** tag for Video Transform/Composite. */
  119. NvBufferTag_VIDEO_CONVERT = 0xf01,
  120. } NvBufferTag;
  121. /**
  122. * Defines color formats for NvBuffer.
  123. */
  124. typedef enum
  125. {
  126. /** BT.601 colorspace - YUV420 multi-planar. */
  127. NvBufferColorFormat_YUV420,
  128. /** BT.601 colorspace - YUV420 multi-planar. */
  129. NvBufferColorFormat_YVU420,
  130. /** BT.601 colorspace - YUV422 multi-planar. */
  131. NvBufferColorFormat_YUV422,
  132. /** BT.601 colorspace - YUV420 ER multi-planar. */
  133. NvBufferColorFormat_YUV420_ER,
  134. /** BT.601 colorspace - YVU420 ER multi-planar. */
  135. NvBufferColorFormat_YVU420_ER,
  136. /** BT.601 colorspace - Y/CbCr 4:2:0 multi-planar. */
  137. NvBufferColorFormat_NV12,
  138. /** BT.601 colorspace - Y/CbCr ER 4:2:0 multi-planar. */
  139. NvBufferColorFormat_NV12_ER,
  140. /** BT.601 colorspace - Y/CbCr 4:2:0 multi-planar. */
  141. NvBufferColorFormat_NV21,
  142. /** BT.601 colorspace - Y/CbCr ER 4:2:0 multi-planar. */
  143. NvBufferColorFormat_NV21_ER,
  144. /** BT.601 colorspace - YUV 4:2:2 planar. */
  145. NvBufferColorFormat_UYVY,
  146. /** BT.601 colorspace - YUV ER 4:2:2 planar. */
  147. NvBufferColorFormat_UYVY_ER,
  148. /** BT.601 colorspace - YUV 4:2:2 planar. */
  149. NvBufferColorFormat_VYUY,
  150. /** BT.601 colorspace - YUV ER 4:2:2 planar. */
  151. NvBufferColorFormat_VYUY_ER,
  152. /** BT.601 colorspace - YUV 4:2:2 planar. */
  153. NvBufferColorFormat_YUYV,
  154. /** BT.601 colorspace - YUV ER 4:2:2 planar. */
  155. NvBufferColorFormat_YUYV_ER,
  156. /** BT.601 colorspace - YUV 4:2:2 planar. */
  157. NvBufferColorFormat_YVYU,
  158. /** BT.601 colorspace - YUV ER 4:2:2 planar. */
  159. NvBufferColorFormat_YVYU_ER,
  160. /** LegacyRGBA colorspace - BGRA-8-8-8-8 planar. */
  161. NvBufferColorFormat_ABGR32,
  162. /** LegacyRGBA colorspace - XRGB-8-8-8-8 planar. */
  163. NvBufferColorFormat_XRGB32,
  164. /** LegacyRGBA colorspace - ARGB-8-8-8-8 planar. */
  165. NvBufferColorFormat_ARGB32,
  166. /** BT.601 colorspace - Y/CbCr 4:2:0 10-bit multi-planar. */
  167. NvBufferColorFormat_NV12_10LE,
  168. /** BT.709 colorspace - Y/CbCr 4:2:0 10-bit multi-planar. */
  169. NvBufferColorFormat_NV12_10LE_709,
  170. /** BT.709_ER colorspace - Y/CbCr 4:2:0 10-bit multi-planar. */
  171. NvBufferColorFormat_NV12_10LE_709_ER,
  172. /** BT.2020 colorspace - Y/CbCr 4:2:0 10-bit multi-planar. */
  173. NvBufferColorFormat_NV12_10LE_2020,
  174. /** BT.601 colorspace - Y/CrCb 4:2:0 10-bit multi-planar. */
  175. NvBufferColorFormat_NV21_10LE,
  176. /** BT.601 colorspace - Y/CbCr 4:2:0 12-bit multi-planar. */
  177. NvBufferColorFormat_NV12_12LE,
  178. /** BT.2020 colorspace - Y/CbCr 4:2:0 12-bit multi-planar. */
  179. NvBufferColorFormat_NV12_12LE_2020,
  180. /** BT.601 colorspace - Y/CrCb 4:2:0 12-bit multi-planar. */
  181. NvBufferColorFormat_NV21_12LE,
  182. /** BT.709 colorspace - YUV420 multi-planar. */
  183. NvBufferColorFormat_YUV420_709,
  184. /** BT.709 colorspace - YUV420 ER multi-planar. */
  185. NvBufferColorFormat_YUV420_709_ER,
  186. /** BT.709 colorspace - Y/CbCr 4:2:0 multi-planar. */
  187. NvBufferColorFormat_NV12_709,
  188. /** BT.709 colorspace - Y/CbCr ER 4:2:0 multi-planar. */
  189. NvBufferColorFormat_NV12_709_ER,
  190. /** BT.2020 colorspace - YUV420 multi-planar. */
  191. NvBufferColorFormat_YUV420_2020,
  192. /** BT.2020 colorspace - Y/CbCr 4:2:0 multi-planar. */
  193. NvBufferColorFormat_NV12_2020,
  194. /** BT.601 colorspace - YUV444 multi-planar. */
  195. NvBufferColorFormat_YUV444,
  196. /** Optical flow */
  197. NvBufferColorFormat_SignedR16G16,
  198. /** Optical flow SAD calculation Buffer format */
  199. NvBufferColorFormat_A32,
  200. /** 8-bit grayscale. */
  201. NvBufferColorFormat_GRAY8,
  202. /** BT.601 colorspace - Y/CbCr 4:2:2 multi-planar. */
  203. NvBufferColorFormat_NV16,
  204. /** BT.601 colorspace - Y/CbCr 4:2:2 10-bit semi-planar. */
  205. NvBufferColorFormat_NV16_10LE,
  206. /** BT.601 colorspace - Y/CbCr 4:4:4 multi-planar. */
  207. NvBufferColorFormat_NV24,
  208. /** BT.601 colorspace - Y/CrCb 4:4:4 10-bit multi-planar. */
  209. NvBufferColorFormat_NV24_10LE,
  210. /** BT.601_ER colorspace - Y/CbCr 4:2:2 multi-planar. */
  211. NvBufferColorFormat_NV16_ER,
  212. /** BT.601_ER colorspace - Y/CbCr 4:4:4 multi-planar. */
  213. NvBufferColorFormat_NV24_ER,
  214. /** BT.709 colorspace - Y/CbCr 4:2:2 multi-planar. */
  215. NvBufferColorFormat_NV16_709,
  216. /** BT.709 colorspace - Y/CbCr 4:4:4 multi-planar. */
  217. NvBufferColorFormat_NV24_709,
  218. /** BT.709_ER colorspace - Y/CbCr 4:2:2 multi-planar. */
  219. NvBufferColorFormat_NV16_709_ER,
  220. /** BT.709_ER colorspace - Y/CbCr 4:4:4 multi-planar. */
  221. NvBufferColorFormat_NV24_709_ER,
  222. /** BT.709 colorspace - Y/CbCr 10 bit 4:4:4 multi-planar. */
  223. NvBufferColorFormat_NV24_10LE_709,
  224. /** BT.709 ER colorspace - Y/CbCr 10 bit 4:4:4 multi-planar. */
  225. NvBufferColorFormat_NV24_10LE_709_ER,
  226. /** BT.2020 colorspace - Y/CbCr 10 bit 4:4:4 multi-planar. */
  227. NvBufferColorFormat_NV24_10LE_2020,
  228. /** BT.2020 colorspace - Y/CbCr 12 bit 4:4:4 multi-planar. */
  229. NvBufferColorFormat_NV24_12LE_2020,
  230. /** Non-linear RGB BT.709 colorspace - RGBA-10-10-10-2 planar. */
  231. NvBufferColorFormat_RGBA_10_10_10_2_709,
  232. /** Non-linear RGB BT.2020 colorspace - RGBA-10-10-10-2 planar. */
  233. NvBufferColorFormat_RGBA_10_10_10_2_2020,
  234. /** Non-linear RGB BT.709 colorspace - BGRA-10-10-10-2 planar. */
  235. NvBufferColorFormat_BGRA_10_10_10_2_709,
  236. /** Non-linear RGB BT.2020 colorspace - BGRA-10-10-10-2 planar. */
  237. NvBufferColorFormat_BGRA_10_10_10_2_2020,
  238. /** Invalid color format. */
  239. NvBufferColorFormat_Invalid,
  240. } NvBufferColorFormat;
  241. /**
  242. * Defines video flip methods.
  243. */
  244. typedef enum
  245. {
  246. /** Video flip none. */
  247. NvBufferTransform_None,
  248. /** Video flip rotate 90 degree counter-clockwise. */
  249. NvBufferTransform_Rotate90,
  250. /** Video flip rotate 180 degree. */
  251. NvBufferTransform_Rotate180,
  252. /** Video flip rotate 270 degree counter-clockwise. */
  253. NvBufferTransform_Rotate270,
  254. /** Video flip with respect to X-axis. */
  255. NvBufferTransform_FlipX,
  256. /** Video flip with respect to Y-axis. */
  257. NvBufferTransform_FlipY,
  258. /** Video flip transpose. */
  259. NvBufferTransform_Transpose,
  260. /** Video flip inverse transpode. */
  261. NvBufferTransform_InvTranspose,
  262. } NvBufferTransform_Flip;
  263. /**
  264. * Defines transform video filter types.
  265. */
  266. typedef enum
  267. {
  268. /** transform filter nearest. */
  269. NvBufferTransform_Filter_Nearest,
  270. /** transform filter bilinear. */
  271. NvBufferTransform_Filter_Bilinear,
  272. /** transform filter 5 tap. */
  273. NvBufferTransform_Filter_5_Tap,
  274. /** transform filter 10 tap. */
  275. NvBufferTransform_Filter_10_Tap,
  276. /** transform filter smart. */
  277. NvBufferTransform_Filter_Smart,
  278. /** transform filter nicest. */
  279. NvBufferTransform_Filter_Nicest,
  280. } NvBufferTransform_Filter;
  281. /**
  282. * Defines flags to indicate for valid transform.
  283. */
  284. typedef enum {
  285. /** transform flag to crop source rectangle. */
  286. NVBUFFER_TRANSFORM_CROP_SRC = 1,
  287. /** transform flag to crop destination rectangle. */
  288. NVBUFFER_TRANSFORM_CROP_DST = 1 << 1,
  289. /** transform flag to set filter type. */
  290. NVBUFFER_TRANSFORM_FILTER = 1 << 2,
  291. /** transform flag to set flip method. */
  292. NVBUFFER_TRANSFORM_FLIP = 1 << 3,
  293. } NvBufferTransform_Flag;
  294. /**
  295. * Defines flags that specify valid composition/blending operations.
  296. */
  297. typedef enum {
  298. /** flag to set for composition. */
  299. NVBUFFER_COMPOSITE = 1,
  300. /** flag to set for blending. */
  301. NVBUFFER_BLEND = 1 << 1,
  302. /** composition flag to set filter type. */
  303. NVBUFFER_COMPOSITE_FILTER = 1 << 2,
  304. } NvBufferComposite_Flag;
  305. /**
  306. * Holds parameters for buffer sync point object.
  307. * sync object params is simply a data structure containing [sync point ID,value] pair.
  308. * This can be used by clients to describe an event that might want to wait for.
  309. */
  310. typedef struct _NvBufferSyncObjParams
  311. {
  312. uint32_t syncpointID;
  313. uint32_t value;
  314. }NvBufferSyncObjParams;
  315. /**
  316. * buffer sync point object.
  317. */
  318. typedef struct _NvBufferSyncObjRec
  319. {
  320. NvBufferSyncObjParams insyncobj[NVBUF_MAX_SYNCOBJ_PARAMS];
  321. uint32_t num_insyncobj;
  322. NvBufferSyncObjParams outsyncobj;
  323. uint32_t use_outsyncobj;
  324. }NvBufferSyncObj;
  325. /**
  326. * Holds composition background r,g,b colors.
  327. */
  328. typedef struct
  329. {
  330. /** background color value for r. */
  331. float r;
  332. /** background color value for g. */
  333. float g;
  334. /** background color value for b. */
  335. float b;
  336. }NvBufferCompositeBackground;
  337. /**
  338. * Holds coordinates for a rectangle.
  339. */
  340. typedef struct
  341. {
  342. /** rectangle top. */
  343. uint32_t top;
  344. /** rectangle left. */
  345. uint32_t left;
  346. /** rectangle width. */
  347. uint32_t width;
  348. /** rectangle height. */
  349. uint32_t height;
  350. }NvBufferRect;
  351. /**
  352. * Holds an opaque NvBuffer session type required for parallel buffer
  353. * tranformations and compositions. Operations using a single session are
  354. * scheduled sequentially, after the previous operation finishes. Operations for
  355. * multiple sessions are scheduled in parallel.
  356. */
  357. typedef struct _NvBufferSession * NvBufferSession;
  358. /**
  359. * Holds Chroma Subsampling parameters.
  360. */
  361. typedef struct _NvBufferChromaSubSamplingParams
  362. {
  363. /** location settings */
  364. uint8_t chromaLocHoriz;
  365. uint8_t chromaLocVert;
  366. }NvBufferChromaSubsamplingParams;
  367. #define NVBUF_CHROMA_SUBSAMPLING_PARAMS_DEFAULT \
  368. { \
  369. NVBUF_CHROMA_SUBSAMPLING_HORIZ_DEFAULT, \
  370. NVBUF_CHROMA_SUBSAMPLING_VERT_DEFAULT \
  371. }
  372. /**
  373. * Holds the input parameters for hardware buffer creation.
  374. */
  375. typedef struct _NvBufferCreateParams
  376. {
  377. /** width of the buffer. */
  378. int32_t width;
  379. /** height of the buffer. */
  380. int32_t height;
  381. /** payload type of the buffer. */
  382. NvBufferPayloadType payloadType;
  383. /** size of the memory.(Applicale for NvBufferPayload_MemHandle) */
  384. int32_t memsize;
  385. /** layout of the buffer. */
  386. NvBufferLayout layout;
  387. /** colorformat of the buffer. */
  388. NvBufferColorFormat colorFormat;
  389. /** tag to associate with the buffer. */
  390. NvBufferTag nvbuf_tag;
  391. }NvBufferCreateParams;
  392. /**
  393. * Holds parameters for a hardware buffer.
  394. */
  395. typedef struct _NvBufferParams
  396. {
  397. /** Holds the DMABUF FD of the hardware buffer. */
  398. uint32_t dmabuf_fd;
  399. /** pointer to hardware buffer memory. */
  400. void *nv_buffer;
  401. /** payload type of the buffer. */
  402. NvBufferPayloadType payloadType;
  403. /** size of the memory.(Applicale for NvBufferPayload_MemHandle) */
  404. int32_t memsize;
  405. /** size of hardware buffer. */
  406. uint32_t nv_buffer_size;
  407. /** video format type of hardware buffer. */
  408. NvBufferColorFormat pixel_format;
  409. /** number of planes of hardware buffer. */
  410. uint32_t num_planes;
  411. /** width of each planes of hardware buffer. */
  412. uint32_t width[MAX_NUM_PLANES];
  413. /** height of each planes of hardware buffer. */
  414. uint32_t height[MAX_NUM_PLANES];
  415. /** pitch of each planes of hardware buffer. */
  416. uint32_t pitch[MAX_NUM_PLANES];
  417. /** memory offset values of each video planes of hardware buffer. */
  418. uint32_t offset[MAX_NUM_PLANES];
  419. /** size of each vodeo planes of hardware buffer. */
  420. uint32_t psize[MAX_NUM_PLANES];
  421. /** layout type of each planes of hardware buffer. */
  422. uint32_t layout[MAX_NUM_PLANES];
  423. }NvBufferParams;
  424. /**
  425. * Holds extended parameters for a hardware buffer.
  426. */
  427. typedef struct _NvBufferParamsEx
  428. {
  429. /** nvbuffer basic parameters. */
  430. NvBufferParams params;
  431. /** offset in bytes from the start of the buffer to the first valid byte.
  432. (Applicale for NvBufferPayload_MemHandle) */
  433. int32_t startofvaliddata;
  434. /** size of the valid data from the first to the last valid byte.
  435. (Applicale for NvBufferPayload_MemHandle) */
  436. int32_t sizeofvaliddatainbytes;
  437. /** display scan format - progressive/interlaced. */
  438. NvBufferDisplayScanFormat scanformat[MAX_NUM_PLANES];
  439. /** offset of the second field for interlaced buffer. */
  440. uint32_t secondfieldoffset[MAX_NUM_PLANES];
  441. /** block height of the planes for blockLinear layout hardware buffer. */
  442. uint32_t blockheightlog2[MAX_NUM_PLANES];
  443. /** physical address of allocated planes. */
  444. uint32_t physicaladdress[MAX_NUM_PLANES];
  445. /** flags associated with planes */
  446. uint64_t flags[MAX_NUM_PLANES];
  447. /** metadata associated with the hardware buffer. */
  448. void *payloadmetaInfo;
  449. /** chroma subsampling parameters */
  450. NvBufferChromaSubsamplingParams chromaSubsampling;
  451. /** get buffer vpr information. */
  452. bool is_protected;
  453. /** buffer sync point object parameters */
  454. NvBufferSyncObj syncobj;
  455. /** reserved field. */
  456. void *reserved;
  457. }NvBufferParamsEx;
  458. /**
  459. * Holds parameters related to compositing/blending.
  460. */
  461. typedef struct _NvBufferCompositeParams
  462. {
  463. /** flag to indicate which of the composition/blending parameters are valid. */
  464. uint32_t composite_flag;
  465. /** number of the input buffers to be composited. */
  466. uint32_t input_buf_count;
  467. /** filters to use for composition. */
  468. NvBufferTransform_Filter composite_filter[MAX_COMPOSITE_FRAME];
  469. /** alpha values of input buffers for the blending. */
  470. float dst_comp_rect_alpha[MAX_COMPOSITE_FRAME];
  471. /** source rectangle coordinates of input buffers for composition. */
  472. NvBufferRect src_comp_rect[MAX_COMPOSITE_FRAME];
  473. /** destination rectangle coordinates of input buffers for composition. */
  474. NvBufferRect dst_comp_rect[MAX_COMPOSITE_FRAME];
  475. /** background color values for composition. */
  476. NvBufferCompositeBackground composite_bgcolor;
  477. /** NvBufferSession to be used for composition. If NULL, the default session
  478. * is used. */
  479. NvBufferSession session;
  480. }NvBufferCompositeParams;
  481. /**
  482. * Holds parameters for buffer transform functions.
  483. */
  484. typedef struct _NvBufferTransformParams
  485. {
  486. /** flag to indicate which of the transform parameters are valid. */
  487. uint32_t transform_flag;
  488. /** flip method. */
  489. NvBufferTransform_Flip transform_flip;
  490. /** transform filter. */
  491. NvBufferTransform_Filter transform_filter;
  492. /** source rectangle coordinates for crop opeartion. */
  493. NvBufferRect src_rect;
  494. /** destination rectangle coordinates for crop opeartion. */
  495. NvBufferRect dst_rect;
  496. /** NvBufferSession to be used for transform. If NULL, the default session
  497. * is used. */
  498. NvBufferSession session;
  499. }NvBufferTransformParams;
  500. /**
  501. * This method can be used to wait on sync point ID.
  502. *
  503. * @param[in] syncobj_params sync point object parameters.
  504. * @param[in] timeout sync point wait timeout value.
  505. *
  506. * @returns 0 for success, -1 for failure
  507. */
  508. int NvBufferSyncObjWait (NvBufferSyncObjParams *syncobj_params, unsigned int timeout);
  509. /**
  510. * This method can be used to get hardware Buffer struct size.
  511. *
  512. * @returns hardware Buffer struct size.
  513. */
  514. int NvBufferGetSize (void);
  515. /**
  516. * Creates an instance of EGLImage from a DMABUF FD.
  517. *
  518. * @param[in] display An EGLDisplay object used during the creation
  519. * of the EGLImage. If NULL, nvbuf_utils() uses
  520. * its own instance of EGLDisplay.
  521. * @param[in] dmabuf_fd DMABUF FD of the buffer from which the EGLImage
  522. * is to be created.
  523. *
  524. * @returns `EGLImageKHR` for success, `NULL` for failure
  525. */
  526. EGLImageKHR NvEGLImageFromFd (EGLDisplay display, int dmabuf_fd);
  527. /**
  528. * Destroys an EGLImage object.
  529. *
  530. * @param[in] display An EGLDisplay object used to destroy the EGLImage.
  531. * If NULL, nvbuf_utils() uses its own instance of
  532. * EGLDisplay.
  533. * @param[in] eglImage The EGLImageKHR object to be destroyed.
  534. *
  535. * @returns 0 for success, -1 for failure
  536. */
  537. int NvDestroyEGLImage (EGLDisplay display, EGLImageKHR eglImage);
  538. /**
  539. * Allocates a hardware buffer (deprecated).
  540. *
  541. * @deprecated Use NvBufferCreateEx() instead.
  542. * @param[out] dmabuf_fd Returns the DMABUF FD of the hardware buffer.
  543. * @param[in] width Buffer width, in bytes.
  544. * @param[in] height Buffer height, in bytes.
  545. * @param[in] layout Layout of the buffer.
  546. * @param[in] colorFormat Color format of the buffer.
  547. *
  548. * @return 0 if successful, or -1 otherwise.
  549. */
  550. int NvBufferCreate (int *dmabuf_fd, int width, int height,
  551. NvBufferLayout layout, NvBufferColorFormat colorFormat);
  552. /**
  553. * Allocates a hardware buffer.
  554. *
  555. * @param[out] dmabuf_fd Returns the DMABUF FD of the hardware buffer.
  556. * @param[in] input_params Input parameters for hardware buffer creation.
  557. *
  558. * @returns 0 for success, -1 for failure
  559. */
  560. int NvBufferCreateEx (int *dmabuf_fd, NvBufferCreateParams *input_params);
  561. /**
  562. * Allocates a hardware buffer for interlace scan format.
  563. *
  564. * @param[out] dmabuf_fd Returns the DMABUF FD of the hardware buffer.
  565. * @param[in] input_params Input parameters for hardware buffer creation.
  566. *
  567. * @returns 0 for success, -1 for failure
  568. */
  569. int NvBufferCreateInterlace (int *dmabuf_fd, NvBufferCreateParams *input_params);
  570. /**
  571. * Allocates a hardware buffer with a given chroma subsampling location.
  572. *
  573. * @param[in] dmabuf_fd DMABUF FD of the buffer.
  574. * @param[in] input_params Input parameters for hardware buffer creation.
  575. * @param[in] chromaSubsampling Chroma location parameters.
  576. *
  577. * @returns 0 for success, -1 for failure
  578. */
  579. int NvBufferCreateWithChromaLoc (int *dmabuf_fd, NvBufferCreateParams *input_params, NvBufferChromaSubsamplingParams *chromaSubsampling);
  580. /**
  581. * Gets buffer parameters.
  582. * @param[in] dmabuf_fd `DMABUF FD` of buffer.
  583. * @param[out] params A pointer to the structure to fill with parameters.
  584. *
  585. * @returns 0 for success, -1 for failure.
  586. */
  587. int NvBufferGetParams (int dmabuf_fd, NvBufferParams *params);
  588. /**
  589. * Gets buffer extended parameters.
  590. * @param[in] dmabuf_fd `DMABUF FD` of buffer.
  591. * @param[out] exparams A pointer to the structure to fill with extended parameters.
  592. *
  593. * @returns 0 for success, -1 for failure.
  594. */
  595. int NvBufferGetParamsEx (int dmabuf_fd, NvBufferParamsEx *exparams);
  596. /**
  597. * Destroys a hardware buffer.
  598. * @param[in] dmabuf_fd Specifies the `dmabuf_fd` `hw_buffer` to destroy.
  599. *
  600. * @returns 0 for success, -1 for failure.
  601. */
  602. int NvBufferDestroy (int dmabuf_fd);
  603. /**
  604. * Extracts the `dmabuf_fd` from the hardware buffer.
  605. * @param[in] nvbuf Specifies the `hw_buffer`.
  606. * @param[out] dmabuf_fd Returns DMABUF FD of `hw_buffer`.
  607. *
  608. * @returns 0 for success, -1 for failure.
  609. */
  610. int ExtractFdFromNvBuffer (void *nvbuf, int *dmabuf_fd);
  611. /**
  612. * Releases the `dmabuf_fd` buffer.
  613. * @see ExtractfdFromNvBuffer()
  614. * @param[in] dmabuf_fd Specifies the `dmabuf_fd` to release.
  615. *
  616. * @returns 0 for success, -1 for failure.
  617. */
  618. int NvReleaseFd (int dmabuf_fd);
  619. /**
  620. * Syncs the hardware memory cache for the CPU.
  621. *
  622. * \sa NvBufferMemMap for the purpose of the function
  623. *
  624. * @param[in] dmabuf_fd DMABUF FD of buffer.
  625. * @param[in] plane video frame plane.
  626. * @param[in] pVirtAddr Virtual Address pointer of the memory-mapped plane.
  627. *
  628. * @returns 0 for success, -1 for failure.
  629. */
  630. int NvBufferMemSyncForCpu (int dmabuf_fd, unsigned int plane, void **pVirtAddr);
  631. /**
  632. * Syncs the hardware memory cache for the CPU, API to be used for another process.
  633. *
  634. * \sa NvBufferMemMapEx for the purpose of the function
  635. *
  636. * @param[in] dmabuf_fd DMABUF FD of buffer.
  637. * @param[in] exparams extended parameters for a hardware buffer.
  638. * @param[in] plane video frame plane.
  639. * @param[in] pVirtAddr Virtual Address pointer of the memory-mapped plane.
  640. *
  641. * @returns 0 for success, -1 for failure.
  642. */
  643. int NvBufferMemSyncForCpuEx (int dmabuf_fd, NvBufferParamsEx *exparams, unsigned int plane, void **pVirtAddr);
  644. /**
  645. * Syncs the hardware memory cache for the device.
  646. *
  647. * \sa NvBufferMemMap for the purpose of the function
  648. *
  649. * @param[in] dmabuf_fd DMABUF FD of buffer.
  650. * @param[in] plane video frame plane.
  651. * @param[in] pVirtAddr Virtual Address pointer of the memory-mapped plane.
  652. *
  653. * @returns 0 for success, -1 for failure.
  654. */
  655. int NvBufferMemSyncForDevice (int dmabuf_fd, unsigned int plane, void **pVirtAddr);
  656. /**
  657. * Syncs the hardware memory cache for the device, API to be used for another process.
  658. *
  659. * \sa NvBufferMemMapEx for the purpose of the function
  660. *
  661. * @param[in] dmabuf_fd DMABUF FD of buffer.
  662. * @param[in] exparams extended parameters for a hardware buffer.
  663. * @param[in] plane video frame plane.
  664. * @param[in] pVirtAddr Virtual Address pointer of the memory-mapped plane.
  665. *
  666. * @returns 0 for success, -1 for failure.
  667. */
  668. int NvBufferMemSyncForDeviceEx (int dmabuf_fd, NvBufferParamsEx *exparams, unsigned int plane, void **pVirtAddr);
  669. /**
  670. * Gets the memory-mapped virtual address of the plane.
  671. *
  672. * The client must call NvBufferMemSyncForCpu() with the virtual address returned
  673. * by this function before accessing the mapped memory in CPU.
  674. *
  675. * After memory mapping is complete, mapped memory modification
  676. * must be coordinated between the CPU and hardware device as
  677. * follows:
  678. * - CPU: If the CPU modifies any mapped memory, the client must call
  679. * NvBufferMemSyncForDevice() before any hardware device accesses the memory.
  680. * - Hardware device: If the mapped memory is modified by any hardware device,
  681. * the client must call NvBufferMemSyncForCpu() before CPU accesses the memory.
  682. *
  683. * @param[in] dmabuf_fd DMABUF FD of buffer.
  684. * @param[in] plane video frame plane.(Applies to @ref NvBufferPayload_SurfArray.)
  685. * @param[in] memflag NvBuffer memory flag.
  686. * @param[out] pVirtAddr Virtual Address pointer of the memory-mapped plane.
  687. *
  688. * @returns 0 for success, -1 for failure.
  689. */
  690. int NvBufferMemMap (int dmabuf_fd, unsigned int plane, NvBufferMemFlags memflag, void **pVirtAddr);
  691. /**
  692. * Gets the memory-mapped virtual address of the plane, API to be used for another process.
  693. *
  694. * The client must call NvBufferMemSyncForCpuEx() with the virtual address returned
  695. * by this function before accessing the mapped memory in CPU in another process.
  696. *
  697. * After memory mapping is complete, mapped memory modification
  698. * must be coordinated between the CPU and hardware device as
  699. * follows:
  700. * - CPU: If the CPU modifies any mapped memory, the client must call
  701. * NvBufferMemSyncForDeviceEx() before any hardware device accesses the memory.
  702. * - Hardware device: If the mapped memory is modified by any hardware device,
  703. * the client must call NvBufferMemSyncForCpuEx() before CPU accesses the memory.
  704. *
  705. * @param[in] dmabuf_fd DMABUF FD of buffer.
  706. * @param[in] exparams extended parameters for a hardware buffer.
  707. * @param[in] plane video frame plane.(Applies to @ref NvBufferPayload_SurfArray.)
  708. * @param[in] memflag NvBuffer memory flag.
  709. * @param[out] pVirtAddr Virtual Address pointer of the memory-mapped plane.
  710. *
  711. * @returns 0 for success, -1 for failure.
  712. */
  713. int NvBufferMemMapEx (int dmabuf_fd, NvBufferParamsEx *exparams, unsigned int plane, NvBufferMemFlags memflag, void **pVirtAddr);
  714. /**
  715. * Unmaps the mapped virtual address of the plane.
  716. *
  717. * If the following conditions are both true, the client must call
  718. * NvBufferMemSyncForDevice() before unmapping the memory:
  719. * - Mapped memory was modified by the CPU.
  720. * - Mapped memory will be accessed by a hardware device.
  721. *
  722. * @param[in] dmabuf_fd DMABUF FD of the buffer.
  723. * @param[in] plane Video frame plane. Applies to
  724. * @ref NvBufferPayload_SurfArray.
  725. * @param[in] pVirtAddr Virtual address pointer to the memory-mapped plane.
  726. *
  727. * @returns 0 for success, -1 for failure.
  728. */
  729. int NvBufferMemUnMap (int dmabuf_fd, unsigned int plane, void **pVirtAddr);
  730. /**
  731. * Unmaps the mapped virtual address of the plane, API to be used for another process.
  732. *
  733. * If the following conditions are both true, the client must call
  734. * NvBufferMemSyncForDeviceEx() before unmapping the memory in another process:
  735. * - Mapped memory was modified by the CPU.
  736. * - Mapped memory will be accessed by a hardware device.
  737. *
  738. * @param[in] dmabuf_fd DMABUF FD of the buffer.
  739. * @param[in] exparams extended parameters for a hardware buffer.
  740. * @param[in] plane Video frame plane. Applies to
  741. * @ref NvBufferPayload_SurfArray.
  742. * @param[in] pVirtAddr Virtual address pointer to the memory-mapped plane.
  743. *
  744. * @returns 0 for success, -1 for failure.
  745. */
  746. int NvBufferMemUnMapEx (int dmabuf_fd, NvBufferParamsEx *exparams, unsigned int plane, void **pVirtAddr);
  747. /**
  748. * Copies the NvBuffer plane contents to a raw buffer plane.
  749. * @param[in] dmabuf_fd DMABUF FD of NvBuffer.
  750. * @param[in] plane video frame plane.
  751. * @param[in] out_width aligned width of the raw data plane.
  752. * @param[in] out_height aligned height of the raw data plane.
  753. * @param[in] ptr pointer to the output raw plane data.
  754. *
  755. * @returns 0 for success, -1 for failure.
  756. */
  757. int NvBuffer2Raw (int dmabuf_fd, unsigned int plane, unsigned int out_width, unsigned int out_height, unsigned char *ptr);
  758. /**
  759. * Copies raw buffer plane contents to an NvBuffer plane.
  760. * @param[in] ptr pointer to the input raw plane data.
  761. * @param[in] plane video frame plane.
  762. * @param[in] in_width aligned width of the raw data plane.
  763. * @param[in] in_height aligned height of the raw data plane.
  764. * @param[in] dmabuf_fd DMABUF FD of NvBuffer.
  765. *
  766. * @returns 0 for success, -1 for failure.
  767. */
  768. int Raw2NvBuffer (unsigned char *ptr, unsigned int plane, unsigned int in_width, unsigned int in_height, int dmabuf_fd);
  769. /**
  770. * Creates a new NvBufferSession for parallel scheduling of
  771. * buffer transformations and compositions.
  772. *
  773. * @returns A session pointer, NULL for failure.
  774. */
  775. NvBufferSession NvBufferSessionCreate(void);
  776. /**
  777. * Destroys an existing \ref NvBufferSession.
  778. * @param[in] session An existing NvBufferSession.
  779. */
  780. void NvBufferSessionDestroy(NvBufferSession session);
  781. /**
  782. * Transforms one DMA buffer to another DMA buffer.
  783. * This function can support transforms for copying, scaling, fliping, rotating, and cropping.
  784. * @param[in] src_dmabuf_fd DMABUF FD of source buffer
  785. * @param[in] dst_dmabuf_fd DMABUF FD of destination buffer
  786. * @param[in] transform_params transform parameters
  787. *
  788. * @return 0 for sucess, -1 for failure.
  789. */
  790. int NvBufferTransform (int src_dmabuf_fd, int dst_dmabuf_fd, NvBufferTransformParams *transform_params);
  791. /**
  792. * Transforms one DMA buffer to another DMA buffer, API to be used for another process.
  793. * This function can support transforms for copying, scaling, fliping, rotating, and cropping.
  794. * @param[in] src_dmabuf_fd DMABUF FD of source buffer
  795. * @param[in] input_params extended input parameters for a hardware buffer.
  796. * @param[in] dst_dmabuf_fd DMABUF FD of destination buffer
  797. * @param[in] output_params extended output parameters for a hardware buffer.
  798. * @param[in] transform_params transform parameters
  799. *
  800. * @return 0 for sucess, -1 for failure.
  801. */
  802. int NvBufferTransformEx (int src_dmabuf_fd, NvBufferParamsEx *input_params, int dst_dmabuf_fd, NvBufferParamsEx *output_params, NvBufferTransformParams *transform_params);
  803. /**
  804. * Transforms one DMA buffer to another DMA buffer asyncroniously (non-blocking).
  805. * This function can support transforms for copying, scaling, fliping, rotating, and cropping.
  806. * @param[in] src_dmabuf_fd DMABUF FD of source buffer
  807. * @param[in] dst_dmabuf_fd DMABUF FD of destination buffer
  808. * @param[in] transform_params transform parameters
  809. * @param[in] syncobj nvbuffer sync point object
  810. *
  811. * @return 0 for sucess, -1 for failure.
  812. */
  813. int NvBufferTransformAsync (int src_dmabuf_fd, int dst_dmabuf_fd, NvBufferTransformParams *transform_params, NvBufferSyncObj *syncobj);
  814. /**
  815. * \brief Composites multiple input DMA buffers to one output DMA buffer.
  816. *
  817. * This function can composite multiple input frames to one output.
  818. *
  819. * @param[in] src_dmabuf_fds An array of DMABUF FDs of source buffers.
  820. * These buffers are composited together. Output
  821. * is copied to the output buffer referenced by
  822. * @a dst_dmabuf_fd.
  823. * @param[in] dst_dmabuf_fd DMABUF FD of the compositing destination buffer.
  824. * @param[in] composite_params Compositing parameters.
  825. */
  826. int NvBufferComposite (int *src_dmabuf_fds, int dst_dmabuf_fd, NvBufferCompositeParams *composite_params);
  827. #ifdef __cplusplus
  828. }
  829. #endif
  830. /** @} */
  831. #endif