nvbufsurface.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. /*
  2. * Copyright (c) 2019-2023, 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 nvbufsurface.h
  12. * <b>NvBufSurface Interface </b>
  13. *
  14. * This file specifies the NvBufSurface management API.
  15. *
  16. * The NvBufSurface API provides methods to allocate / deallocate, map / unmap
  17. * and copy batched buffers.
  18. */
  19. /**
  20. * @defgroup ds_nvbuf_api Buffer Management API module
  21. *
  22. * This section describes types and functions of NvBufSurface application
  23. * programming interface.
  24. *
  25. */
  26. #ifndef NVBUFSURFACE_H_
  27. #define NVBUFSURFACE_H_
  28. #include <stdint.h>
  29. #include <stdbool.h>
  30. #ifdef __cplusplus
  31. extern "C"
  32. {
  33. #endif
  34. /** @defgroup ds_aaa NvBufSurface Types and Functions
  35. * Defines types and functions of \ref NvBufSurface application
  36. * programming interface.
  37. * @ingroup ds_nvbuf_api
  38. * @{ */
  39. /** Defines the default padding length for reserved fields of structures. */
  40. #define STRUCTURE_PADDING 4
  41. /** Defines the maximum number of planes. */
  42. #define NVBUF_MAX_PLANES 4
  43. /**
  44. * Defines the default values for chroma subsampling.
  45. * The default value matches JPEG/MPEG use cases.
  46. */
  47. #define NVBUFSURFACE_CHROMA_SUBSAMPLING_HORIZ_DEFAULT 0
  48. #define NVBUFSURFACE_CHROMA_SUBSAMPLING_VERT_DEFAULT 1
  49. #define NVBUFSURFACE_CHROMA_SUBSAMPLING_PARAMS_DEFAULT \
  50. { \
  51. NVBUFSURFACE_CHROMA_SUBSAMPLING_HORIZ_DEFAULT, \
  52. NVBUFSURFACE_CHROMA_SUBSAMPLING_VERT_DEFAULT \
  53. }
  54. /**
  55. * Defines mapping types of NvBufSurface.
  56. */
  57. typedef enum
  58. {
  59. NVBUF_MAP_READ, /**< Specifies \ref NvBufSurface mapping type "read." */
  60. NVBUF_MAP_WRITE, /**< Specifies \ref NvBufSurface mapping type
  61. "write." */
  62. NVBUF_MAP_READ_WRITE, /**< Specifies \ref NvBufSurface mapping type
  63. "read/write." */
  64. } NvBufSurfaceMemMapFlags;
  65. /**
  66. * Defines tags that identify the components requesting a memory allocation.
  67. * The tags can be used later to identify the total memory allocated to
  68. * particular types of components.
  69. * TODO: Check if DeepStream require more tags to be defined.
  70. */
  71. typedef enum
  72. {
  73. /** tag None. */
  74. NvBufSurfaceTag_NONE = 0x0,
  75. /** tag for Camera. */
  76. NvBufSurfaceTag_CAMERA = 0x200,
  77. /** tag for Jpeg Encoder/Decoder. */
  78. NvBufSurfaceTag_JPEG = 0x1500,
  79. /** tag for VPR Buffers. */
  80. NvBufSurfaceTag_PROTECTED = 0x1504,
  81. /** tag for H264/H265 Video Encoder. */
  82. NvBufSurfaceTag_VIDEO_ENC = 0x1200,
  83. /** tag for H264/H265/VP9 Video Decoder. */
  84. NvBufSurfaceTag_VIDEO_DEC = 0x1400,
  85. /** tag for Video Transform/Composite/Blend. */
  86. NvBufSurfaceTag_VIDEO_CONVERT = 0xf01,
  87. } NvBufSurfaceTag;
  88. /**
  89. * Defines color formats for NvBufSurface.
  90. */
  91. typedef enum
  92. {
  93. /** Specifies an invalid color format. */
  94. NVBUF_COLOR_FORMAT_INVALID,
  95. /** Specifies 8 bit GRAY scale - single plane */
  96. NVBUF_COLOR_FORMAT_GRAY8,
  97. /** Specifies BT.601 colorspace - YUV420 multi-planar. */
  98. NVBUF_COLOR_FORMAT_YUV420,
  99. /** Specifies BT.601 colorspace - YUV420 multi-planar. */
  100. NVBUF_COLOR_FORMAT_YVU420,
  101. /** Specifies BT.601 colorspace - YUV420 ER multi-planar. */
  102. NVBUF_COLOR_FORMAT_YUV420_ER,
  103. /** Specifies BT.601 colorspace - YVU420 ER multi-planar. */
  104. NVBUF_COLOR_FORMAT_YVU420_ER,
  105. /** Specifies BT.601 colorspace - Y/CbCr 4:2:0 multi-planar. */
  106. NVBUF_COLOR_FORMAT_NV12,
  107. /** Specifies BT.601 colorspace - Y/CbCr ER 4:2:0 multi-planar. */
  108. NVBUF_COLOR_FORMAT_NV12_ER,
  109. /** Specifies BT.601 colorspace - Y/CbCr 4:2:0 multi-planar. */
  110. NVBUF_COLOR_FORMAT_NV21,
  111. /** Specifies BT.601 colorspace - Y/CbCr ER 4:2:0 multi-planar. */
  112. NVBUF_COLOR_FORMAT_NV21_ER,
  113. /** Specifies BT.601 colorspace - YUV 4:2:2 planar. */
  114. NVBUF_COLOR_FORMAT_UYVY,
  115. /** Specifies BT.601 colorspace - YUV ER 4:2:2 planar. */
  116. NVBUF_COLOR_FORMAT_UYVY_ER,
  117. /** Specifies BT.601 colorspace - YUV 4:2:2 planar. */
  118. NVBUF_COLOR_FORMAT_VYUY,
  119. /** Specifies BT.601 colorspace - YUV ER 4:2:2 planar. */
  120. NVBUF_COLOR_FORMAT_VYUY_ER,
  121. /** Specifies BT.601 colorspace - YUV 4:2:2 planar. */
  122. NVBUF_COLOR_FORMAT_YUYV,
  123. /** Specifies BT.601 colorspace - YUV ER 4:2:2 planar. */
  124. NVBUF_COLOR_FORMAT_YUYV_ER,
  125. /** Specifies BT.601 colorspace - YUV 4:2:2 planar. */
  126. NVBUF_COLOR_FORMAT_YVYU,
  127. /** Specifies BT.601 colorspace - YUV ER 4:2:2 planar. */
  128. NVBUF_COLOR_FORMAT_YVYU_ER,
  129. /** Specifies BT.601 colorspace - YUV444 multi-planar. */
  130. NVBUF_COLOR_FORMAT_YUV444,
  131. /** Specifies RGBA-8-8-8-8 single plane. */
  132. NVBUF_COLOR_FORMAT_RGBA,
  133. /** Specifies BGRA-8-8-8-8 single plane. */
  134. NVBUF_COLOR_FORMAT_BGRA,
  135. /** Specifies ARGB-8-8-8-8 single plane. */
  136. NVBUF_COLOR_FORMAT_ARGB,
  137. /** Specifies ABGR-8-8-8-8 single plane. */
  138. NVBUF_COLOR_FORMAT_ABGR,
  139. /** Specifies RGBx-8-8-8-8 single plane. */
  140. NVBUF_COLOR_FORMAT_RGBx,
  141. /** Specifies BGRx-8-8-8-8 single plane. */
  142. NVBUF_COLOR_FORMAT_BGRx,
  143. /** Specifies xRGB-8-8-8-8 single plane. */
  144. NVBUF_COLOR_FORMAT_xRGB,
  145. /** Specifies xBGR-8-8-8-8 single plane. */
  146. NVBUF_COLOR_FORMAT_xBGR,
  147. /** Specifies RGB-8-8-8 single plane. */
  148. NVBUF_COLOR_FORMAT_RGB,
  149. /** Specifies BGR-8-8-8 single plane. */
  150. NVBUF_COLOR_FORMAT_BGR,
  151. /** Specifies BT.601 colorspace - Y/CbCr 4:2:0 10-bit multi-planar. */
  152. NVBUF_COLOR_FORMAT_NV12_10LE,
  153. /** Specifies BT.601 colorspace - Y/CbCr 4:2:0 12-bit multi-planar. */
  154. NVBUF_COLOR_FORMAT_NV12_12LE,
  155. /** Specifies BT.709 colorspace - YUV420 multi-planar. */
  156. NVBUF_COLOR_FORMAT_YUV420_709,
  157. /** Specifies BT.709 colorspace - YUV420 ER multi-planar. */
  158. NVBUF_COLOR_FORMAT_YUV420_709_ER,
  159. /** Specifies BT.709 colorspace - Y/CbCr 4:2:0 multi-planar. */
  160. NVBUF_COLOR_FORMAT_NV12_709,
  161. /** Specifies BT.709 colorspace - Y/CbCr ER 4:2:0 multi-planar. */
  162. NVBUF_COLOR_FORMAT_NV12_709_ER,
  163. /** Specifies BT.2020 colorspace - YUV420 multi-planar. */
  164. NVBUF_COLOR_FORMAT_YUV420_2020,
  165. /** Specifies BT.2020 colorspace - Y/CbCr 4:2:0 multi-planar. */
  166. NVBUF_COLOR_FORMAT_NV12_2020,
  167. /** Specifies BT.601 colorspace - Y/CbCr ER 4:2:0 10-bit multi-planar. */
  168. NVBUF_COLOR_FORMAT_NV12_10LE_ER,
  169. /** Specifies BT.709 colorspace - Y/CbCr 4:2:0 10-bit multi-planar. */
  170. NVBUF_COLOR_FORMAT_NV12_10LE_709,
  171. /** Specifies BT.709 colorspace - Y/CbCr ER 4:2:0 10-bit multi-planar. */
  172. NVBUF_COLOR_FORMAT_NV12_10LE_709_ER,
  173. /** Specifies BT.2020 colorspace - Y/CbCr 4:2:0 10-bit multi-planar. */
  174. NVBUF_COLOR_FORMAT_NV12_10LE_2020,
  175. /** Specifies color format for packed 2 signed shorts */
  176. NVBUF_COLOR_FORMAT_SIGNED_R16G16,
  177. /** Specifies RGB- unsigned 8 bit multiplanar plane. */
  178. NVBUF_COLOR_FORMAT_R8_G8_B8,
  179. /** Specifies BGR- unsigned 8 bit multiplanar plane. */
  180. NVBUF_COLOR_FORMAT_B8_G8_R8,
  181. /** Specifies RGB-32bit Floating point multiplanar plane. */
  182. NVBUF_COLOR_FORMAT_R32F_G32F_B32F,
  183. /** Specifies BGR-32bit Floating point multiplanar plane. */
  184. NVBUF_COLOR_FORMAT_B32F_G32F_R32F,
  185. /** Specifies BT.601 colorspace - YUV422 multi-planar. */
  186. NVBUF_COLOR_FORMAT_YUV422,
  187. /** Specifies BT.601 colorspace - Y/CrCb 4:2:0 10-bit multi-planar. */
  188. NVBUF_COLOR_FORMAT_NV21_10LE,
  189. /** Specifies BT.601 colorspace - Y/CrCb 4:2:0 12-bit multi-planar. */
  190. NVBUF_COLOR_FORMAT_NV21_12LE,
  191. /** Specifies BT.2020 colorspace - Y/CbCr 4:2:0 12-bit multi-planar. */
  192. NVBUF_COLOR_FORMAT_NV12_12LE_2020,
  193. /** Specifies BT.601 colorspace - Y/CbCr 4:2:2 multi-planar. */
  194. NVBUF_COLOR_FORMAT_NV16,
  195. /** Specifies BT.601 colorspace - Y/CbCr 4:2:2 10-bit semi-planar. */
  196. NVBUF_COLOR_FORMAT_NV16_10LE,
  197. /** Specifies BT.601 colorspace - Y/CbCr 4:4:4 multi-planar. */
  198. NVBUF_COLOR_FORMAT_NV24,
  199. /** Specifies BT.601 colorspace - Y/CrCb 4:4:4 10-bit multi-planar. */
  200. NVBUF_COLOR_FORMAT_NV24_10LE,
  201. /** Specifies BT.601_ER colorspace - Y/CbCr 4:2:2 multi-planar. */
  202. NVBUF_COLOR_FORMAT_NV16_ER,
  203. /** Specifies BT.601_ER colorspace - Y/CbCr 4:4:4 multi-planar. */
  204. NVBUF_COLOR_FORMAT_NV24_ER,
  205. /** Specifies BT.709 colorspace - Y/CbCr 4:2:2 multi-planar. */
  206. NVBUF_COLOR_FORMAT_NV16_709,
  207. /** Specifies BT.709 colorspace - Y/CbCr 4:4:4 multi-planar. */
  208. NVBUF_COLOR_FORMAT_NV24_709,
  209. /** Specifies BT.709_ER colorspace - Y/CbCr 4:2:2 multi-planar. */
  210. NVBUF_COLOR_FORMAT_NV16_709_ER,
  211. /** Specifies BT.709_ER colorspace - Y/CbCr 4:4:4 multi-planar. */
  212. NVBUF_COLOR_FORMAT_NV24_709_ER,
  213. /** Specifies BT.709 colorspace - Y/CbCr 10 bit 4:4:4 multi-planar. */
  214. NVBUF_COLOR_FORMAT_NV24_10LE_709,
  215. /** Specifies BT.709 ER colorspace - Y/CbCr 10 bit 4:4:4 multi-planar. */
  216. NVBUF_COLOR_FORMAT_NV24_10LE_709_ER,
  217. /** Specifies BT.2020 colorspace - Y/CbCr 10 bit 4:4:4 multi-planar. */
  218. NVBUF_COLOR_FORMAT_NV24_10LE_2020,
  219. /** Specifies BT.2020 colorspace - Y/CbCr 12 bit 4:4:4 multi-planar. */
  220. NVBUF_COLOR_FORMAT_NV24_12LE_2020,
  221. /** Specifies Non-linear RGB BT.709 colorspace - RGBA-10-10-10-2 planar. */
  222. NVBUF_COLOR_FORMAT_RGBA_10_10_10_2_709,
  223. /** Specifies Non-linear RGB BT.2020 colorspace - RGBA-10-10-10-2 planar. */
  224. NVBUF_COLOR_FORMAT_RGBA_10_10_10_2_2020,
  225. /** Specifies Non-linear RGB BT.709 colorspace - BGRA-10-10-10-2 planar. */
  226. NVBUF_COLOR_FORMAT_BGRA_10_10_10_2_709,
  227. /** Specifies Non-linear RGB BT.2020 colorspace - BGRA-10-10-10-2 planar. */
  228. NVBUF_COLOR_FORMAT_BGRA_10_10_10_2_2020,
  229. /** Specifies Optical flow SAD calculation Buffer format */
  230. NVBUF_COLOR_FORMAT_A32,
  231. /** Specifies BT.601 colorspace - 10 bit YUV 4:2:2 interleaved. */
  232. NVBUF_COLOR_FORMAT_UYVP,
  233. /** Specifies BT.601 colorspace - 10 bit YUV ER 4:2:2 interleaved. */
  234. NVBUF_COLOR_FORMAT_UYVP_ER,
  235. /** Specifies BT.601 colorspace - Y/CbCr ER 4:4:4 multi-planar. */
  236. NVBUF_COLOR_FORMAT_YUV444_ER,
  237. /** Specifies BT.709 colorspace - Y/CbCr 4:4:4 multi-planar. */
  238. NVBUF_COLOR_FORMAT_YUV444_709,
  239. /** Specifies BT.709 colorspace - Y/CbCr ER 4:4:4 multi-planar. */
  240. NVBUF_COLOR_FORMAT_YUV444_709_ER,
  241. /** Specifies BT.2020 colorspace - Y/CbCr 4:4:4 multi-planar. */
  242. NVBUF_COLOR_FORMAT_YUV444_2020,
  243. /** Specifies BT.601 colorspace - Y/CbCr 4:4:4 10-bit multi-planar. */
  244. NVBUF_COLOR_FORMAT_YUV444_10LE,
  245. /** Specifies BT.601 colorspace - Y/CbCr ER 4:4:4 10-bit multi-planar. */
  246. NVBUF_COLOR_FORMAT_YUV444_10LE_ER,
  247. /** Specifies BT.709 colorspace - Y/CbCr 4:4:4 10-bit multi-planar. */
  248. NVBUF_COLOR_FORMAT_YUV444_10LE_709,
  249. /** Specifies BT.709 colorspace - Y/CbCr ER 4:4:4 10-bit multi-planar. */
  250. NVBUF_COLOR_FORMAT_YUV444_10LE_709_ER,
  251. /** Specifies BT.2020 colorspace - Y/CbCr 4:4:4 10-bit multi-planar. */
  252. NVBUF_COLOR_FORMAT_YUV444_10LE_2020,
  253. /** Specifies BT.601 colorspace - Y/CbCr 4:4:4 12-bit multi-planar. */
  254. NVBUF_COLOR_FORMAT_YUV444_12LE,
  255. /** Specifies BT.601 colorspace - Y/CbCr ER 4:4:4 12-bit multi-planar. */
  256. NVBUF_COLOR_FORMAT_YUV444_12LE_ER,
  257. /** Specifies BT.709 colorspace - Y/CbCr 4:4:4 12-bit multi-planar. */
  258. NVBUF_COLOR_FORMAT_YUV444_12LE_709,
  259. /** Specifies BT.709 colorspace - Y/CbCr ER 4:4:4 12-bit multi-planar. */
  260. NVBUF_COLOR_FORMAT_YUV444_12LE_709_ER,
  261. /** Specifies BT.2020 colorspace - Y/CbCr 4:4:4 12-bit multi-planar. */
  262. NVBUF_COLOR_FORMAT_YUV444_12LE_2020,
  263. /** Specifies BT.601 colorspace - Y/CbCr ER 4:2:0 12-bit multi-planar. */
  264. NVBUF_COLOR_FORMAT_NV12_12LE_ER,
  265. /** Specifies BT.709 colorspace - Y/CbCr 4:2:0 12-bit multi-planar. */
  266. NVBUF_COLOR_FORMAT_NV12_12LE_709,
  267. /** Specifies BT.709 colorspace - Y/CbCr ER 4:2:0 12-bit multi-planar. */
  268. NVBUF_COLOR_FORMAT_NV12_12LE_709_ER,
  269. NVBUF_COLOR_FORMAT_LAST
  270. } NvBufSurfaceColorFormat;
  271. /**
  272. * Specifies layout formats for \ref NvBufSurface video planes.
  273. */
  274. typedef enum
  275. {
  276. /** Specifies pitch layout. */
  277. NVBUF_LAYOUT_PITCH,
  278. /** Specifies block linear layout. */
  279. NVBUF_LAYOUT_BLOCK_LINEAR,
  280. } NvBufSurfaceLayout;
  281. /**
  282. * Specifies memory types for \ref NvBufSurface.
  283. */
  284. typedef enum
  285. {
  286. /** Specifies the default memory type, i.e. \ref NVBUF_MEM_CUDA_DEVICE
  287. for dGPU, \ref NVBUF_MEM_SURFACE_ARRAY for Jetson. Use \ref NVBUF_MEM_DEFAULT
  288. to allocate whichever type of memory is appropriate for the platform. */
  289. NVBUF_MEM_DEFAULT,
  290. /** Specifies CUDA Host memory type. */
  291. NVBUF_MEM_CUDA_PINNED,
  292. /** Specifies CUDA Device memory type. */
  293. NVBUF_MEM_CUDA_DEVICE,
  294. /** Specifies CUDA Unified memory type. */
  295. NVBUF_MEM_CUDA_UNIFIED,
  296. /** Specifies NVRM Surface Array type. Valid only for Jetson. */
  297. NVBUF_MEM_SURFACE_ARRAY,
  298. /** Specifies NVRM Handle type. Valid only for Jetson. */
  299. NVBUF_MEM_HANDLE,
  300. /** Specifies memory allocated by malloc(). */
  301. NVBUF_MEM_SYSTEM,
  302. } NvBufSurfaceMemType;
  303. /**
  304. * Defines display scan formats for NvBufSurface video planes.
  305. */
  306. typedef enum
  307. {
  308. /** Progessive scan formats. */
  309. NVBUF_DISPLAYSCANFORMAT_PROGRESSIVE,
  310. /** Interlaced scan formats. */
  311. NVBUF_DISPLAYSCANFORMAT_INTERLACED,
  312. } NvBufSurfaceDisplayScanFormat;
  313. /**
  314. * Holds plane wise parameters(extended) of a buffer.
  315. */
  316. typedef struct NvBufSurfacePlaneParamsEx
  317. {
  318. /** display scan format - progressive/interlaced. */
  319. NvBufSurfaceDisplayScanFormat scanformat[NVBUF_MAX_PLANES];
  320. /** offset of the second field for interlaced buffer. */
  321. uint32_t secondfieldoffset[NVBUF_MAX_PLANES];
  322. /** block height of the planes for blockLinear layout buffer. */
  323. uint32_t blockheightlog2[NVBUF_MAX_PLANES];
  324. /** physical address of allocated planes. */
  325. uint32_t physicaladdress[NVBUF_MAX_PLANES];
  326. /** flags associated with planes */
  327. uint64_t flags[NVBUF_MAX_PLANES];
  328. void * _reserved[STRUCTURE_PADDING * NVBUF_MAX_PLANES];
  329. } NvBufSurfacePlaneParamsEx;
  330. /**
  331. * Holds plane wise parameters of a buffer.
  332. */
  333. typedef struct NvBufSurfacePlaneParams
  334. {
  335. /** Holds the number of planes. */
  336. uint32_t num_planes;
  337. /** Holds the widths of planes. */
  338. uint32_t width[NVBUF_MAX_PLANES];
  339. /** Holds the heights of planes. */
  340. uint32_t height[NVBUF_MAX_PLANES];
  341. /** Holds the pitches of planes in bytes. */
  342. uint32_t pitch[NVBUF_MAX_PLANES];
  343. /** Holds the offsets of planes in bytes. */
  344. uint32_t offset[NVBUF_MAX_PLANES];
  345. /** Holds the sizes of planes in bytes. */
  346. uint32_t psize[NVBUF_MAX_PLANES];
  347. /** Holds the number of bytes occupied by a pixel in each plane. */
  348. uint32_t bytesPerPix[NVBUF_MAX_PLANES];
  349. void * _reserved[STRUCTURE_PADDING * NVBUF_MAX_PLANES];
  350. } NvBufSurfacePlaneParams;
  351. /**
  352. * Holds Chroma Subsampling parameters for NvBufSurface allocation.
  353. */
  354. typedef struct NvBufSurfaceChromaSubsamplingParams
  355. {
  356. /** location settings */
  357. uint8_t chromaLocHoriz;
  358. uint8_t chromaLocVert;
  359. } NvBufSurfaceChromaSubsamplingParams;
  360. /**
  361. * Holds parameters required to allocate an \ref NvBufSurface.
  362. */
  363. typedef struct NvBufSurfaceCreateParams {
  364. /** Holds the GPU ID. Valid only for a multi-GPU system. */
  365. uint32_t gpuId;
  366. /** Holds the width of the buffer. */
  367. uint32_t width;
  368. /** Holds the height of the buffer. */
  369. uint32_t height;
  370. /** Holds the amount of memory to be allocated. Optional; if set, all other
  371. parameters (width, height, etc.) are ignored. */
  372. uint32_t size;
  373. /** Holds a "contiguous memory" flag. If set, contiguous memory is allocated
  374. for the batch. Valid only for CUDA memory types. */
  375. bool isContiguous;
  376. /** Holds the color format of the buffer. */
  377. NvBufSurfaceColorFormat colorFormat;
  378. /** Holds the surface layout. May be Block Linear (BL) or Pitch Linear (PL).
  379. For a dGPU, only PL is valid. */
  380. NvBufSurfaceLayout layout;
  381. /** Holds the type of memory to be allocated. */
  382. NvBufSurfaceMemType memType;
  383. } NvBufSurfaceCreateParams;
  384. /**
  385. * Hold extended parameters required to allocate NvBufSurface.
  386. * (Applicable for NvBufSurfaceAllocate API)
  387. */
  388. typedef struct NvBufSurfaceAllocateParams {
  389. /** Hold legacy NvBufSurface creation parameters */
  390. NvBufSurfaceCreateParams params;
  391. /** Display scan format */
  392. NvBufSurfaceDisplayScanFormat displayscanformat;
  393. /** Chroma Subsampling parameters */
  394. NvBufSurfaceChromaSubsamplingParams chromaSubsampling;
  395. /** components tag to be used for memory allocation */
  396. NvBufSurfaceTag memtag;
  397. /** disable pitch padding allocation only applicable for cuda and system memory allocation
  398. pitch would be width times bytes per pixel for the plane, for odd width it would be
  399. multiple of 2, also note for some non standard video resolution cuda kernels may fail
  400. due to unaligned pitch
  401. */
  402. bool disablePitchPadding;
  403. /** Used void* from custom param for 64 bit machine, using other uint32_t param */
  404. uint32_t _reservedParam;
  405. void * _reserved[STRUCTURE_PADDING-1];
  406. } NvBufSurfaceAllocateParams;
  407. /**
  408. * Hold the pointers of mapped buffer.
  409. */
  410. typedef struct NvBufSurfaceMappedAddr {
  411. /** Holds planewise pointers to a CPU mapped buffer. */
  412. void * addr[NVBUF_MAX_PLANES];
  413. /** Holds a pointer to a mapped EGLImage. */
  414. void *eglImage;
  415. void * _reserved[STRUCTURE_PADDING];
  416. } NvBufSurfaceMappedAddr;
  417. /**
  418. * Hold the information(extended) of single buffer in the batch.
  419. */
  420. typedef struct NvBufSurfaceParamsEx {
  421. /** offset in bytes from the start of the buffer to the first valid byte.
  422. (Applicable for NVBUF_MEM_HANDLE) */
  423. int32_t startofvaliddata;
  424. /** size of the valid data from the first to the last valid byte.
  425. (Applicable for NVBUF_MEM_HANDLE) */
  426. int32_t sizeofvaliddatainbytes;
  427. /** chroma subsampling parameters.
  428. (Applicable for NVBUF_MEM_SURFACE_ARRAY) */
  429. NvBufSurfaceChromaSubsamplingParams chromaSubsampling;
  430. /** get buffer vpr information. */
  431. bool is_protected;
  432. /** plane wise extended info */
  433. NvBufSurfacePlaneParamsEx planeParamsex;
  434. void * _reserved[STRUCTURE_PADDING];
  435. } NvBufSurfaceParamsEx;
  436. /**
  437. * Hold the information of single buffer in the batch.
  438. */
  439. typedef struct NvBufSurfaceParams {
  440. /** Holds the width of the buffer. */
  441. uint32_t width;
  442. /** Holds the height of the buffer. */
  443. uint32_t height;
  444. /** Holds the pitch of the buffer. */
  445. uint32_t pitch;
  446. /** Holds the color format of the buffer. */
  447. NvBufSurfaceColorFormat colorFormat;
  448. /** Holds BL or PL. For dGPU, only PL is valid. */
  449. NvBufSurfaceLayout layout;
  450. /** Holds a DMABUF FD. Valid only for \ref NVBUF_MEM_SURFACE_ARRAY and
  451. \ref NVBUF_MEM_HANDLE type memory. */
  452. uint64_t bufferDesc;
  453. /** Holds the amount of allocated memory. */
  454. uint32_t dataSize;
  455. /** Holds a pointer to allocated memory. Not valid for
  456. \ref NVBUF_MEM_SURFACE_ARRAY or \ref NVBUF_MEM_HANDLE. */
  457. void * dataPtr;
  458. /** Holds planewise information (width, height, pitch, offset, etc.). */
  459. NvBufSurfacePlaneParams planeParams;
  460. /** Holds pointers to mapped buffers. Initialized to NULL
  461. when the structure is created. */
  462. NvBufSurfaceMappedAddr mappedAddr;
  463. /** pointers of extended parameters of single buffer in the batch.*/
  464. NvBufSurfaceParamsEx *paramex;
  465. void * _reserved[STRUCTURE_PADDING - 1];
  466. } NvBufSurfaceParams;
  467. /**
  468. * Holds information about batched buffers.
  469. */
  470. typedef struct NvBufSurface {
  471. /** Holds a GPU ID. Valid only for a multi-GPU system. */
  472. uint32_t gpuId;
  473. /** Holds the batch size. */
  474. uint32_t batchSize;
  475. /** Holds the number valid and filled buffers. Initialized to zero when
  476. an instance of the structure is created. */
  477. uint32_t numFilled;
  478. /** Holds an "is contiguous" flag. If set, memory allocated for the batch
  479. is contiguous. */
  480. bool isContiguous;
  481. /** Holds type of memory for buffers in the batch. */
  482. NvBufSurfaceMemType memType;
  483. /** Holds a pointer to an array of batched buffers. */
  484. NvBufSurfaceParams *surfaceList;
  485. void * _reserved[STRUCTURE_PADDING];
  486. } NvBufSurface;
  487. /**
  488. * Holds plane parameters to map the buffer received from another process.
  489. */
  490. typedef struct NvBufSurfaceMapPlaneParams
  491. {
  492. /** Holds the widths of planes */
  493. uint32_t width;
  494. /** Holds the heights of planes */
  495. uint32_t height;
  496. /** Holds the pitches of planes in bytes */
  497. uint32_t pitch;
  498. /** Holds the offsets of planes in bytes */
  499. uint32_t offset;
  500. /** Holds the sizes of planes in bytes */
  501. uint32_t psize;
  502. /** Holds offset of the second field for interlaced buffer */
  503. uint32_t secondfieldoffset;
  504. /** Holds block height of the planes for blockLinear layout buffer */
  505. uint32_t blockheightlog2;
  506. /** Holds flags associated with the planes */
  507. uint64_t flags;
  508. /** Reserved */
  509. uint8_t reserved[64];
  510. } NvBufSurfaceMapPlaneParams;
  511. /**
  512. * Holds buffer parameters to map the buffer received from another process.
  513. */
  514. typedef struct NvBufSurfaceMapParams {
  515. /** Holds the number of planes. */
  516. uint32_t num_planes;
  517. /** Holds a GPU ID */
  518. uint32_t gpuId;
  519. /** Holds a DMABUF FD */
  520. uint64_t fd;
  521. /** Holds the total size of allocated memory */
  522. uint32_t totalSize;
  523. /** Holds type of memory */
  524. NvBufSurfaceMemType memType;
  525. /** Holds BL or PL layout */
  526. NvBufSurfaceLayout layout;
  527. /** Holds display scan format */
  528. NvBufSurfaceDisplayScanFormat scanformat;
  529. /** Holds the color format */
  530. NvBufSurfaceColorFormat colorFormat;
  531. /** Holds chroma subsampling parameters */
  532. NvBufSurfaceChromaSubsamplingParams chromaSubsampling;
  533. /** Holds plane parameters */
  534. NvBufSurfaceMapPlaneParams planes[NVBUF_MAX_PLANES];
  535. /** Reserved */
  536. uint8_t reserved[64];
  537. } NvBufSurfaceMapParams;
  538. /**
  539. * \brief Allocates a batch of buffers.
  540. *
  541. * Allocates memory for \a batchSize buffers and returns a pointer to an
  542. * allocated \ref NvBufSurface. The \a params structure must have
  543. * the allocation parameters of a single buffer. If \a params.size
  544. * is set, a buffer of that size is allocated, and all other
  545. * parameters (width, height, color format, etc.) are ignored.
  546. *
  547. * Call NvBufSurfaceDestroy() to free resources allocated by this function.
  548. *
  549. * @param[out] surf An indirect pointer to the allocated batched
  550. * buffers.
  551. * @param[in] batchSize Batch size of buffers.
  552. * @param[in] params A pointer to an \ref NvBufSurfaceCreateParams
  553. * structure.
  554. *
  555. * @return 0 if successful, or -1 otherwise.
  556. */
  557. int NvBufSurfaceCreate (NvBufSurface **surf, uint32_t batchSize,
  558. NvBufSurfaceCreateParams *params);
  559. /**
  560. * \brief Allocate batch of buffers. (Using extended buffer allocation parameters)
  561. *
  562. * Allocates memory for batchSize buffers and returns in *surf a pointer to allocated NvBufSurface.
  563. * params structure should have allocation parameters of single buffer. If size field in
  564. * params is set, buffer of that size will be allocated and all other
  565. * parameters (w, h, color format etc.) will be ignored.
  566. *
  567. * Use NvBufSurfaceDestroy to free all the resources.
  568. *
  569. * @param[out] surf pointer to allocated batched buffers.
  570. * @param[in] batchSize batch size of buffers.
  571. * @param[in] paramsext pointer to NvBufSurfaceAllocateParams structure.
  572. *
  573. * @return 0 for success, -1 for failure.
  574. */
  575. int NvBufSurfaceAllocate (NvBufSurface **surf, uint32_t batchSize,
  576. NvBufSurfaceAllocateParams *paramsext);
  577. /**
  578. * Free the batched buffers previously allocated through NvBufSurfaceCreate.
  579. *
  580. * @param[in] surf A pointer to an \ref NvBufSurface to be freed.
  581. *
  582. * @return 0 if successful, or -1 otherwise.
  583. */
  584. int NvBufSurfaceDestroy (NvBufSurface *surf);
  585. /**
  586. * \brief Maps hardware batched buffers to the HOST or CPU address space.
  587. *
  588. * Valid for \ref NVBUF_MEM_CUDA_UNIFIED type memory for dGPU and
  589. * \ref NVBUF_MEM_SURFACE_ARRAY and \ref NVBUF_MEM_HANDLE type memory for
  590. * Jetson.
  591. *
  592. * This function fills an array of pointers at
  593. * \a surf->surfaceList->mappedAddr->addr.
  594. * \a surf is a pointer to an \ref NvBufSurface.
  595. * \a surfaceList is a pointer to an \ref NvBufSurfaceParams.
  596. * \a mappedAddr is a pointer to an \ref NvBufSurfaceMappedAddr.
  597. * \a addr is declared as an array of pointers to void, and holds pointers
  598. * to the buffers.
  599. *
  600. * The client must call NvBufSurfaceSyncForCpu() with the virtual address
  601. * populated by this function before accessing mapped memory in the CPU.
  602. *
  603. * After memory mapping is complete, mapped memory modification
  604. * must be coordinated between the CPU and the hardware device as
  605. * follows:
  606. * - CPU: If the CPU modifies mapped memory, the client must call
  607. * NvBufSurfaceSyncForDevice() before any hardware device accesses the memory.
  608. * - Hardware device: If a hardware device modifies mapped memory, the client
  609. * must call NvBufSurfaceSyncForCpu() before the CPU accesses the memory.
  610. *
  611. * Use NvBufSurfaceUnMap() to unmap buffer(s) and release any resource.
  612. *
  613. * @param[in,out] surf A pointer to an NvBufSurface structure. The function
  614. * stores pointers to the buffers in a descendant of this
  615. * structure; see the notes above.
  616. * @param[in] index Index of a buffer in the batch. -1 refers to all buffers
  617. * in the batch.
  618. * @param[in] plane Index of a plane in buffer. -1 refers to all planes
  619. * in the buffer.
  620. * @param[in] type A flag for mapping type.
  621. *
  622. * @return 0 if successful, or -1 otherwise.
  623. */
  624. int NvBufSurfaceMap (NvBufSurface *surf, int index, int plane, NvBufSurfaceMemMapFlags type);
  625. /**
  626. * \brief Unmaps previously mapped buffer(s).
  627. *
  628. * @param[in] surf A pointer to an \ref NvBufSurface structure.
  629. * @param[in] index Index of a buffer in the batch. -1 indicates
  630. * all buffers in the batch.
  631. * @param[in] plane Index of a plane in the buffer. -1 indicates
  632. * all planes in the buffer.
  633. *
  634. * @return 0 if successful, or -1 otherwise.
  635. */
  636. int NvBufSurfaceUnMap (NvBufSurface *surf, int index, int plane);
  637. /**
  638. * \brief Copies the content of source batched buffer(s) to destination
  639. * batched buffer(s).
  640. *
  641. * You can use this function to copy source buffer(s) of one memory type
  642. * to destination buffer(s) of another memory type,
  643. * e.g. CUDA host to CUDA device, malloc'ed memory to CUDA device, etc.
  644. *
  645. * The source and destination \ref NvBufSurface objects must have same
  646. * buffer and batch size.
  647. *
  648. * @param[in] srcSurf A pointer to the source NvBufSurface structure.
  649. * @param[in] dstSurf A pointer to the destination NvBufSurface structure.
  650. *
  651. * @return 0 if successful, or -1 otherwise.
  652. */
  653. int NvBufSurfaceCopy (NvBufSurface *srcSurf, NvBufSurface *dstSurf);
  654. /**
  655. * \brief Copies the NvBufSurface plane memory content to a raw buffer plane for a specific
  656. * batched buffer.
  657. *
  658. * This function can be used to copy plane memory content from source raw buffer pointer
  659. * to specific destination batch buffer of supported memory type.
  660. *
  661. * @param[in] surf pointer to NvBufSurface structure.
  662. * @param[in] index index of buffer in the batch.
  663. * @param[in] plane index of plane in buffer.
  664. * @param[in] out_width aligned width of the raw data plane.
  665. * @param[in] out_height aligned height of the raw data plane.
  666. * @param[in] ptr pointer to the output raw plane data.
  667. *
  668. * @return 0 for success, -1 for failure.
  669. */
  670. int NvBufSurface2Raw (NvBufSurface *Surf, unsigned int index, unsigned int plane, unsigned int outwidth, unsigned int outheight, unsigned char *ptr);
  671. /**
  672. * \brief Copies the raw buffer plane memory content to the NvBufSurface plane memory of a specific
  673. * batched buffer.
  674. *
  675. * This function can be used to copy plane memory content from batch buffer
  676. * to specific destination raw buffer pointer.
  677. *
  678. * @param[in] ptr pointer to the input raw plane data.
  679. * @param[in] index index of buffer in the batch.
  680. * @param[in] plane index of plane in buffer.
  681. * @param[in] in_width aligned width of the raw data plane.
  682. * @param[in] in_height aligned height of the raw data plane.
  683. * @param[in] surf pointer to NvBufSurface structure.
  684. *
  685. * @return 0 for success, -1 for failure.
  686. */
  687. int Raw2NvBufSurface (unsigned char *ptr, unsigned int index, unsigned int plane, unsigned int inwidth, unsigned int inheight, NvBufSurface *Surf);
  688. /**
  689. * Syncs the HW memory cache for the CPU.
  690. *
  691. * Valid only for memory types \ref NVBUF_MEM_SURFACE_ARRAY and
  692. * \ref NVBUF_MEM_HANDLE.
  693. *
  694. * @param[in] surf A pointer to an \ref NvBufSurface structure.
  695. * @param[in] index Index of the buffer in the batch. -1 refers to
  696. * all buffers in the batch.
  697. * @param[in] plane Index of a plane in the buffer. -1 refers to all planes
  698. * in the buffer.
  699. *
  700. * @return 0 if successful, or -1 otherwise.
  701. */
  702. int NvBufSurfaceSyncForCpu (NvBufSurface *surf, int index, int plane);
  703. /**
  704. * \brief Syncs the hardware memory cache for the device.
  705. *
  706. * Valid only for memory types \ref NVBUF_MEM_SURFACE_ARRAY and
  707. * \ref NVBUF_MEM_HANDLE.
  708. *
  709. * @param[in] surf A pointer to an \ref NvBufSurface structure.
  710. * @param[in] index Index of a buffer in the batch. -1 refers to all buffers
  711. * in the batch.
  712. * @param[in] plane Index of a plane in the buffer. -1 refers to all planes
  713. * in the buffer.
  714. *
  715. * @return 0 if successful, or -1 otherwise.
  716. */
  717. int NvBufSurfaceSyncForDevice (NvBufSurface *surf, int index, int plane);
  718. /**
  719. * \brief Gets the \ref NvBufSurface from the DMABUF FD.
  720. *
  721. * @param[in] dmabuf_fd DMABUF FD of the buffer.
  722. * @param[out] buffer A pointer to the NvBufSurface.
  723. *
  724. * @return 0 for success, or -1 otherwise.
  725. */
  726. int NvBufSurfaceFromFd (int dmabuf_fd, void **buffer);
  727. /**
  728. * \brief Fills each byte of the buffer(s) in an \ref NvBufSurface with a
  729. * provided value.
  730. *
  731. * You can also use this function to reset the buffer(s) in the batch.
  732. *
  733. * @param[in] surf A pointer to the NvBufSurface structure.
  734. * @param[in] index Index of a buffer in the batch. -1 refers to all buffers
  735. * in the batch.
  736. * @param[in] plane Index of a plane in the buffer. -1 refers to all planes
  737. * in the buffer.
  738. * @param[in] value The value to be used as fill.
  739. *
  740. * @return 0 if successful, or -1 otherwise.
  741. */
  742. int NvBufSurfaceMemSet (NvBufSurface *surf, int index, int plane, uint8_t value);
  743. /**
  744. * \brief Creates an EGLImage from the memory of one or more
  745. * \ref NvBufSurface buffers.
  746. *
  747. * Only memory type \ref NVBUF_MEM_SURFACE_ARRAY is supported.
  748. *
  749. * This function returns the created EGLImage by storing its address at
  750. * \a surf->surfaceList->mappedAddr->eglImage. (\a surf is a pointer to
  751. * an NvBufSurface. \a surfaceList is a pointer to an \ref NvBufSurfaceParams.
  752. * \a mappedAddr is a pointer to an \ref NvBufSurfaceMappedAddr.
  753. * \a eglImage is declared as a pointer to void, and holds an
  754. * EGLImageKHR.)
  755. *
  756. * You can use this function in scenarios where a CUDA operation on Jetson
  757. * hardware memory (identified by \ref NVBUF_MEM_SURFACE_ARRAY) is required.
  758. * The EGLImageKHR struct provided by this function can then be registered
  759. * with CUDA for further CUDA operations.
  760. *
  761. * @param[in,out] surf A pointer to an NvBufSurface structure. The function
  762. * stores a pointer to the created EGLImage in
  763. * a descendant of this structure; see the notes above.
  764. * @param[in] index Index of a buffer in the batch. -1 specifies all buffers
  765. * in the batch.
  766. *
  767. * @return 0 for success, or -1 otherwise.
  768. */
  769. int NvBufSurfaceMapEglImage (NvBufSurface *surf, int index);
  770. /**
  771. * \brief Destroys the previously created EGLImage object(s).
  772. *
  773. * @param[in] surf A pointer to an \ref NvBufSurface structure.
  774. * @param[in] index The index of a buffer in the batch. -1 specifies all
  775. * buffers in the batch.
  776. *
  777. * @return 0 if successful, or -1 otherwise.
  778. */
  779. int NvBufSurfaceUnMapEglImage (NvBufSurface *surf, int index);
  780. /**
  781. * \brief Import parameters received from another process and create hardware buffer.
  782. *
  783. * Calling process must need to call NvBufferDestroy() to remove reference count for
  784. * hardware buffer handle of the imported DMA buffer.
  785. *
  786. * @param[out] out_nvbuf_surf Pointer to hardware buffer.
  787. * @param[in] in_params Parameters to create hardware buffer.
  788. *
  789. * @return 0 for success, -1 for failure.
  790. */
  791. int NvBufSurfaceImport (NvBufSurface **out_nvbuf_surf, const NvBufSurfaceMapParams *in_params);
  792. /**
  793. * \brief Get buffer information to map the buffer in another process.
  794. *
  795. * @param[in] surf Pointer to NvBufSurface structure.
  796. * @param[in] index Index of a buffer in the batch.
  797. * @param[out] params Pointer to NvBufSurfaceMapParams information of the buffer.
  798. *
  799. * @return 0 for success, -1 for failure.
  800. */
  801. int NvBufSurfaceGetMapParams (const NvBufSurface *surf, int index, NvBufSurfaceMapParams *params);
  802. /** @} */
  803. #ifdef __cplusplus
  804. }
  805. #endif
  806. #endif /* NVBUFSURFACE_H_ */