cuviddec.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. /*
  2. * This copyright notice applies to this header file only:
  3. *
  4. * Copyright (c) 2010-2020 NVIDIA Corporation
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use,
  10. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the software, and to permit persons to whom the
  12. * software is furnished to do so, subject to the following
  13. * conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  20. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. /*****************************************************************************************************/
  28. //! \file cuviddec.h
  29. //! NVDECODE API provides video decoding interface to NVIDIA GPU devices.
  30. //! \date 2015-2019
  31. //! This file contains constants, structure definitions and function prototypes used for decoding.
  32. /*****************************************************************************************************/
  33. #if !defined(__CUDA_VIDEO_H__)
  34. #define __CUDA_VIDEO_H__
  35. #ifndef __cuda_cuda_h__
  36. #include <cuda.h>
  37. #endif // __cuda_cuda_h__
  38. #if defined(_WIN64) || defined(__LP64__) || defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
  39. #if (CUDA_VERSION >= 3020) && (!defined(CUDA_FORCE_API_VERSION) || (CUDA_FORCE_API_VERSION >= 3020))
  40. #define __CUVID_DEVPTR64
  41. #endif
  42. #endif
  43. #if defined(__cplusplus)
  44. extern "C" {
  45. #endif /* __cplusplus */
  46. typedef void *CUvideodecoder;
  47. typedef struct _CUcontextlock_st *CUvideoctxlock;
  48. /*********************************************************************************/
  49. //! \enum cudaVideoCodec
  50. //! Video codec enums
  51. //! These enums are used in CUVIDDECODECREATEINFO and CUVIDDECODECAPS structures
  52. /*********************************************************************************/
  53. typedef enum cudaVideoCodec_enum {
  54. cudaVideoCodec_MPEG1=0, /**< MPEG1 */
  55. cudaVideoCodec_MPEG2, /**< MPEG2 */
  56. cudaVideoCodec_MPEG4, /**< MPEG4 */
  57. cudaVideoCodec_VC1, /**< VC1 */
  58. cudaVideoCodec_H264, /**< H264 */
  59. cudaVideoCodec_JPEG, /**< JPEG */
  60. cudaVideoCodec_H264_SVC, /**< H264-SVC */
  61. cudaVideoCodec_H264_MVC, /**< H264-MVC */
  62. cudaVideoCodec_HEVC, /**< HEVC */
  63. cudaVideoCodec_VP8, /**< VP8 */
  64. cudaVideoCodec_VP9, /**< VP9 */
  65. cudaVideoCodec_NumCodecs, /**< Max codecs */
  66. // Uncompressed YUV
  67. cudaVideoCodec_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), /**< Y,U,V (4:2:0) */
  68. cudaVideoCodec_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), /**< Y,V,U (4:2:0) */
  69. cudaVideoCodec_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), /**< Y,UV (4:2:0) */
  70. cudaVideoCodec_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), /**< YUYV/YUY2 (4:2:2) */
  71. cudaVideoCodec_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')) /**< UYVY (4:2:2) */
  72. } cudaVideoCodec;
  73. /*********************************************************************************/
  74. //! \enum cudaVideoSurfaceFormat
  75. //! Video surface format enums used for output format of decoded output
  76. //! These enums are used in CUVIDDECODECREATEINFO structure
  77. /*********************************************************************************/
  78. typedef enum cudaVideoSurfaceFormat_enum {
  79. cudaVideoSurfaceFormat_NV12=0, /**< Semi-Planar YUV [Y plane followed by interleaved UV plane] */
  80. cudaVideoSurfaceFormat_P016=1, /**< 16 bit Semi-Planar YUV [Y plane followed by interleaved UV plane].
  81. Can be used for 10 bit(6LSB bits 0), 12 bit (4LSB bits 0) */
  82. cudaVideoSurfaceFormat_YUV444=2, /**< Planar YUV [Y plane followed by U and V planes] */
  83. cudaVideoSurfaceFormat_YUV444_16Bit=3, /**< 16 bit Planar YUV [Y plane followed by U and V planes].
  84. Can be used for 10 bit(6LSB bits 0), 12 bit (4LSB bits 0) */
  85. } cudaVideoSurfaceFormat;
  86. /******************************************************************************************************************/
  87. //! \enum cudaVideoDeinterlaceMode
  88. //! Deinterlacing mode enums
  89. //! These enums are used in CUVIDDECODECREATEINFO structure
  90. //! Use cudaVideoDeinterlaceMode_Weave for progressive content and for content that doesn't need deinterlacing
  91. //! cudaVideoDeinterlaceMode_Adaptive needs more video memory than other DImodes
  92. /******************************************************************************************************************/
  93. typedef enum cudaVideoDeinterlaceMode_enum {
  94. cudaVideoDeinterlaceMode_Weave=0, /**< Weave both fields (no deinterlacing) */
  95. cudaVideoDeinterlaceMode_Bob, /**< Drop one field */
  96. cudaVideoDeinterlaceMode_Adaptive /**< Adaptive deinterlacing */
  97. } cudaVideoDeinterlaceMode;
  98. /**************************************************************************************************************/
  99. //! \enum cudaVideoChromaFormat
  100. //! Chroma format enums
  101. //! These enums are used in CUVIDDECODECREATEINFO and CUVIDDECODECAPS structures
  102. /**************************************************************************************************************/
  103. typedef enum cudaVideoChromaFormat_enum {
  104. cudaVideoChromaFormat_Monochrome=0, /**< MonoChrome */
  105. cudaVideoChromaFormat_420, /**< YUV 4:2:0 */
  106. cudaVideoChromaFormat_422, /**< YUV 4:2:2 */
  107. cudaVideoChromaFormat_444 /**< YUV 4:4:4 */
  108. } cudaVideoChromaFormat;
  109. /*************************************************************************************************************/
  110. //! \enum cudaVideoCreateFlags
  111. //! Decoder flag enums to select preferred decode path
  112. //! cudaVideoCreate_Default and cudaVideoCreate_PreferCUVID are most optimized, use these whenever possible
  113. /*************************************************************************************************************/
  114. typedef enum cudaVideoCreateFlags_enum {
  115. cudaVideoCreate_Default = 0x00, /**< Default operation mode: use dedicated video engines */
  116. cudaVideoCreate_PreferCUDA = 0x01, /**< Use CUDA-based decoder (requires valid vidLock object for multi-threading) */
  117. cudaVideoCreate_PreferDXVA = 0x02, /**< Go through DXVA internally if possible (requires D3D9 interop) */
  118. cudaVideoCreate_PreferCUVID = 0x04 /**< Use dedicated video engines directly */
  119. } cudaVideoCreateFlags;
  120. /*************************************************************************/
  121. //! \enum cuvidDecodeStatus
  122. //! Decode status enums
  123. //! These enums are used in CUVIDGETDECODESTATUS structure
  124. /*************************************************************************/
  125. typedef enum cuvidDecodeStatus_enum
  126. {
  127. cuvidDecodeStatus_Invalid = 0, // Decode status is not valid
  128. cuvidDecodeStatus_InProgress = 1, // Decode is in progress
  129. cuvidDecodeStatus_Success = 2, // Decode is completed without any errors
  130. // 3 to 7 enums are reserved for future use
  131. cuvidDecodeStatus_Error = 8, // Decode is completed with an error (error is not concealed)
  132. cuvidDecodeStatus_Error_Concealed = 9, // Decode is completed with an error and error is concealed
  133. } cuvidDecodeStatus;
  134. /**************************************************************************************************************/
  135. //! \struct CUVIDDECODECAPS;
  136. //! This structure is used in cuvidGetDecoderCaps API
  137. /**************************************************************************************************************/
  138. typedef struct _CUVIDDECODECAPS
  139. {
  140. cudaVideoCodec eCodecType; /**< IN: cudaVideoCodec_XXX */
  141. cudaVideoChromaFormat eChromaFormat; /**< IN: cudaVideoChromaFormat_XXX */
  142. unsigned int nBitDepthMinus8; /**< IN: The Value "BitDepth minus 8" */
  143. unsigned int reserved1[3]; /**< Reserved for future use - set to zero */
  144. unsigned char bIsSupported; /**< OUT: 1 if codec supported, 0 if not supported */
  145. unsigned char reserved2; /**< Reserved for future use - set to zero */
  146. unsigned short nOutputFormatMask; /**< OUT: each bit represents corresponding cudaVideoSurfaceFormat enum */
  147. unsigned int nMaxWidth; /**< OUT: Max supported coded width in pixels */
  148. unsigned int nMaxHeight; /**< OUT: Max supported coded height in pixels */
  149. unsigned int nMaxMBCount; /**< OUT: Max supported macroblock count
  150. CodedWidth*CodedHeight/256 must be <= nMaxMBCount */
  151. unsigned short nMinWidth; /**< OUT: Min supported coded width in pixels */
  152. unsigned short nMinHeight; /**< OUT: Min supported coded height in pixels */
  153. unsigned int reserved3[11]; /**< Reserved for future use - set to zero */
  154. } CUVIDDECODECAPS;
  155. /**************************************************************************************************************/
  156. //! \struct CUVIDDECODECREATEINFO
  157. //! This structure is used in cuvidCreateDecoder API
  158. /**************************************************************************************************************/
  159. typedef struct _CUVIDDECODECREATEINFO
  160. {
  161. unsigned long ulWidth; /**< IN: Coded sequence width in pixels */
  162. unsigned long ulHeight; /**< IN: Coded sequence height in pixels */
  163. unsigned long ulNumDecodeSurfaces; /**< IN: Maximum number of internal decode surfaces */
  164. cudaVideoCodec CodecType; /**< IN: cudaVideoCodec_XXX */
  165. cudaVideoChromaFormat ChromaFormat; /**< IN: cudaVideoChromaFormat_XXX */
  166. unsigned long ulCreationFlags; /**< IN: Decoder creation flags (cudaVideoCreateFlags_XXX) */
  167. unsigned long bitDepthMinus8; /**< IN: The value "BitDepth minus 8" */
  168. unsigned long ulIntraDecodeOnly; /**< IN: Set 1 only if video has all intra frames (default value is 0). This will
  169. optimize video memory for Intra frames only decoding. The support is limited
  170. to specific codecs - H264, HEVC, VP9, the flag will be ignored for codecs which
  171. are not supported. However decoding might fail if the flag is enabled in case
  172. of supported codecs for regular bit streams having P and/or B frames. */
  173. unsigned long ulMaxWidth; /**< IN: Coded sequence max width in pixels used with reconfigure Decoder */
  174. unsigned long ulMaxHeight; /**< IN: Coded sequence max height in pixels used with reconfigure Decoder */
  175. unsigned long Reserved1; /**< Reserved for future use - set to zero */
  176. /**
  177. * IN: area of the frame that should be displayed
  178. */
  179. struct {
  180. short left;
  181. short top;
  182. short right;
  183. short bottom;
  184. } display_area;
  185. cudaVideoSurfaceFormat OutputFormat; /**< IN: cudaVideoSurfaceFormat_XXX */
  186. cudaVideoDeinterlaceMode DeinterlaceMode; /**< IN: cudaVideoDeinterlaceMode_XXX */
  187. unsigned long ulTargetWidth; /**< IN: Post-processed output width (Should be aligned to 2) */
  188. unsigned long ulTargetHeight; /**< IN: Post-processed output height (Should be aligned to 2) */
  189. unsigned long ulNumOutputSurfaces; /**< IN: Maximum number of output surfaces simultaneously mapped */
  190. CUvideoctxlock vidLock; /**< IN: If non-NULL, context lock used for synchronizing ownership of
  191. the cuda context. Needed for cudaVideoCreate_PreferCUDA decode */
  192. /**
  193. * IN: target rectangle in the output frame (for aspect ratio conversion)
  194. * if a null rectangle is specified, {0,0,ulTargetWidth,ulTargetHeight} will be used
  195. */
  196. struct {
  197. short left;
  198. short top;
  199. short right;
  200. short bottom;
  201. } target_rect;
  202. unsigned long Reserved2[5]; /**< Reserved for future use - set to zero */
  203. } CUVIDDECODECREATEINFO;
  204. /*********************************************************/
  205. //! \struct CUVIDH264DPBENTRY
  206. //! H.264 DPB entry
  207. //! This structure is used in CUVIDH264PICPARAMS structure
  208. /*********************************************************/
  209. typedef struct _CUVIDH264DPBENTRY
  210. {
  211. int PicIdx; /**< picture index of reference frame */
  212. int FrameIdx; /**< frame_num(short-term) or LongTermFrameIdx(long-term) */
  213. int is_long_term; /**< 0=short term reference, 1=long term reference */
  214. int not_existing; /**< non-existing reference frame (corresponding PicIdx should be set to -1) */
  215. int used_for_reference; /**< 0=unused, 1=top_field, 2=bottom_field, 3=both_fields */
  216. int FieldOrderCnt[2]; /**< field order count of top and bottom fields */
  217. } CUVIDH264DPBENTRY;
  218. /************************************************************/
  219. //! \struct CUVIDH264MVCEXT
  220. //! H.264 MVC picture parameters ext
  221. //! This structure is used in CUVIDH264PICPARAMS structure
  222. /************************************************************/
  223. typedef struct _CUVIDH264MVCEXT
  224. {
  225. int num_views_minus1; /**< Max number of coded views minus 1 in video : Range - 0 to 1023 */
  226. int view_id; /**< view identifier */
  227. unsigned char inter_view_flag; /**< 1 if used for inter-view prediction, 0 if not */
  228. unsigned char num_inter_view_refs_l0; /**< number of inter-view ref pics in RefPicList0 */
  229. unsigned char num_inter_view_refs_l1; /**< number of inter-view ref pics in RefPicList1 */
  230. unsigned char MVCReserved8Bits; /**< Reserved bits */
  231. int InterViewRefsL0[16]; /**< view id of the i-th view component for inter-view prediction in RefPicList0 */
  232. int InterViewRefsL1[16]; /**< view id of the i-th view component for inter-view prediction in RefPicList1 */
  233. } CUVIDH264MVCEXT;
  234. /*********************************************************/
  235. //! \struct CUVIDH264SVCEXT
  236. //! H.264 SVC picture parameters ext
  237. //! This structure is used in CUVIDH264PICPARAMS structure
  238. /*********************************************************/
  239. typedef struct _CUVIDH264SVCEXT
  240. {
  241. unsigned char profile_idc;
  242. unsigned char level_idc;
  243. unsigned char DQId;
  244. unsigned char DQIdMax;
  245. unsigned char disable_inter_layer_deblocking_filter_idc;
  246. unsigned char ref_layer_chroma_phase_y_plus1;
  247. signed char inter_layer_slice_alpha_c0_offset_div2;
  248. signed char inter_layer_slice_beta_offset_div2;
  249. unsigned short DPBEntryValidFlag;
  250. unsigned char inter_layer_deblocking_filter_control_present_flag;
  251. unsigned char extended_spatial_scalability_idc;
  252. unsigned char adaptive_tcoeff_level_prediction_flag;
  253. unsigned char slice_header_restriction_flag;
  254. unsigned char chroma_phase_x_plus1_flag;
  255. unsigned char chroma_phase_y_plus1;
  256. unsigned char tcoeff_level_prediction_flag;
  257. unsigned char constrained_intra_resampling_flag;
  258. unsigned char ref_layer_chroma_phase_x_plus1_flag;
  259. unsigned char store_ref_base_pic_flag;
  260. unsigned char Reserved8BitsA;
  261. unsigned char Reserved8BitsB;
  262. short scaled_ref_layer_left_offset;
  263. short scaled_ref_layer_top_offset;
  264. short scaled_ref_layer_right_offset;
  265. short scaled_ref_layer_bottom_offset;
  266. unsigned short Reserved16Bits;
  267. struct _CUVIDPICPARAMS *pNextLayer; /**< Points to the picparams for the next layer to be decoded.
  268. Linked list ends at the target layer. */
  269. int bRefBaseLayer; /**< whether to store ref base pic */
  270. } CUVIDH264SVCEXT;
  271. /******************************************************/
  272. //! \struct CUVIDH264PICPARAMS
  273. //! H.264 picture parameters
  274. //! This structure is used in CUVIDPICPARAMS structure
  275. /******************************************************/
  276. typedef struct _CUVIDH264PICPARAMS
  277. {
  278. // SPS
  279. int log2_max_frame_num_minus4;
  280. int pic_order_cnt_type;
  281. int log2_max_pic_order_cnt_lsb_minus4;
  282. int delta_pic_order_always_zero_flag;
  283. int frame_mbs_only_flag;
  284. int direct_8x8_inference_flag;
  285. int num_ref_frames; // NOTE: shall meet level 4.1 restrictions
  286. unsigned char residual_colour_transform_flag;
  287. unsigned char bit_depth_luma_minus8; // Must be 0 (only 8-bit supported)
  288. unsigned char bit_depth_chroma_minus8; // Must be 0 (only 8-bit supported)
  289. unsigned char qpprime_y_zero_transform_bypass_flag;
  290. // PPS
  291. int entropy_coding_mode_flag;
  292. int pic_order_present_flag;
  293. int num_ref_idx_l0_active_minus1;
  294. int num_ref_idx_l1_active_minus1;
  295. int weighted_pred_flag;
  296. int weighted_bipred_idc;
  297. int pic_init_qp_minus26;
  298. int deblocking_filter_control_present_flag;
  299. int redundant_pic_cnt_present_flag;
  300. int transform_8x8_mode_flag;
  301. int MbaffFrameFlag;
  302. int constrained_intra_pred_flag;
  303. int chroma_qp_index_offset;
  304. int second_chroma_qp_index_offset;
  305. int ref_pic_flag;
  306. int frame_num;
  307. int CurrFieldOrderCnt[2];
  308. // DPB
  309. CUVIDH264DPBENTRY dpb[16]; // List of reference frames within the DPB
  310. // Quantization Matrices (raster-order)
  311. unsigned char WeightScale4x4[6][16];
  312. unsigned char WeightScale8x8[2][64];
  313. // FMO/ASO
  314. unsigned char fmo_aso_enable;
  315. unsigned char num_slice_groups_minus1;
  316. unsigned char slice_group_map_type;
  317. signed char pic_init_qs_minus26;
  318. unsigned int slice_group_change_rate_minus1;
  319. union
  320. {
  321. unsigned long long slice_group_map_addr;
  322. const unsigned char *pMb2SliceGroupMap;
  323. } fmo;
  324. unsigned int Reserved[12];
  325. // SVC/MVC
  326. union
  327. {
  328. CUVIDH264MVCEXT mvcext;
  329. CUVIDH264SVCEXT svcext;
  330. };
  331. } CUVIDH264PICPARAMS;
  332. /********************************************************/
  333. //! \struct CUVIDMPEG2PICPARAMS
  334. //! MPEG-2 picture parameters
  335. //! This structure is used in CUVIDPICPARAMS structure
  336. /********************************************************/
  337. typedef struct _CUVIDMPEG2PICPARAMS
  338. {
  339. int ForwardRefIdx; // Picture index of forward reference (P/B-frames)
  340. int BackwardRefIdx; // Picture index of backward reference (B-frames)
  341. int picture_coding_type;
  342. int full_pel_forward_vector;
  343. int full_pel_backward_vector;
  344. int f_code[2][2];
  345. int intra_dc_precision;
  346. int frame_pred_frame_dct;
  347. int concealment_motion_vectors;
  348. int q_scale_type;
  349. int intra_vlc_format;
  350. int alternate_scan;
  351. int top_field_first;
  352. // Quantization matrices (raster order)
  353. unsigned char QuantMatrixIntra[64];
  354. unsigned char QuantMatrixInter[64];
  355. } CUVIDMPEG2PICPARAMS;
  356. // MPEG-4 has VOP types instead of Picture types
  357. #define I_VOP 0
  358. #define P_VOP 1
  359. #define B_VOP 2
  360. #define S_VOP 3
  361. /*******************************************************/
  362. //! \struct CUVIDMPEG4PICPARAMS
  363. //! MPEG-4 picture parameters
  364. //! This structure is used in CUVIDPICPARAMS structure
  365. /*******************************************************/
  366. typedef struct _CUVIDMPEG4PICPARAMS
  367. {
  368. int ForwardRefIdx; // Picture index of forward reference (P/B-frames)
  369. int BackwardRefIdx; // Picture index of backward reference (B-frames)
  370. // VOL
  371. int video_object_layer_width;
  372. int video_object_layer_height;
  373. int vop_time_increment_bitcount;
  374. int top_field_first;
  375. int resync_marker_disable;
  376. int quant_type;
  377. int quarter_sample;
  378. int short_video_header;
  379. int divx_flags;
  380. // VOP
  381. int vop_coding_type;
  382. int vop_coded;
  383. int vop_rounding_type;
  384. int alternate_vertical_scan_flag;
  385. int interlaced;
  386. int vop_fcode_forward;
  387. int vop_fcode_backward;
  388. int trd[2];
  389. int trb[2];
  390. // Quantization matrices (raster order)
  391. unsigned char QuantMatrixIntra[64];
  392. unsigned char QuantMatrixInter[64];
  393. int gmc_enabled;
  394. } CUVIDMPEG4PICPARAMS;
  395. /********************************************************/
  396. //! \struct CUVIDVC1PICPARAMS
  397. //! VC1 picture parameters
  398. //! This structure is used in CUVIDPICPARAMS structure
  399. /********************************************************/
  400. typedef struct _CUVIDVC1PICPARAMS
  401. {
  402. int ForwardRefIdx; /**< Picture index of forward reference (P/B-frames) */
  403. int BackwardRefIdx; /**< Picture index of backward reference (B-frames) */
  404. int FrameWidth; /**< Actual frame width */
  405. int FrameHeight; /**< Actual frame height */
  406. // PICTURE
  407. int intra_pic_flag; /**< Set to 1 for I,BI frames */
  408. int ref_pic_flag; /**< Set to 1 for I,P frames */
  409. int progressive_fcm; /**< Progressive frame */
  410. // SEQUENCE
  411. int profile;
  412. int postprocflag;
  413. int pulldown;
  414. int interlace;
  415. int tfcntrflag;
  416. int finterpflag;
  417. int psf;
  418. int multires;
  419. int syncmarker;
  420. int rangered;
  421. int maxbframes;
  422. // ENTRYPOINT
  423. int panscan_flag;
  424. int refdist_flag;
  425. int extended_mv;
  426. int dquant;
  427. int vstransform;
  428. int loopfilter;
  429. int fastuvmc;
  430. int overlap;
  431. int quantizer;
  432. int extended_dmv;
  433. int range_mapy_flag;
  434. int range_mapy;
  435. int range_mapuv_flag;
  436. int range_mapuv;
  437. int rangeredfrm; // range reduction state
  438. } CUVIDVC1PICPARAMS;
  439. /***********************************************************/
  440. //! \struct CUVIDJPEGPICPARAMS
  441. //! JPEG picture parameters
  442. //! This structure is used in CUVIDPICPARAMS structure
  443. /***********************************************************/
  444. typedef struct _CUVIDJPEGPICPARAMS
  445. {
  446. int Reserved;
  447. } CUVIDJPEGPICPARAMS;
  448. /*******************************************************/
  449. //! \struct CUVIDHEVCPICPARAMS
  450. //! HEVC picture parameters
  451. //! This structure is used in CUVIDPICPARAMS structure
  452. /*******************************************************/
  453. typedef struct _CUVIDHEVCPICPARAMS
  454. {
  455. // sps
  456. int pic_width_in_luma_samples;
  457. int pic_height_in_luma_samples;
  458. unsigned char log2_min_luma_coding_block_size_minus3;
  459. unsigned char log2_diff_max_min_luma_coding_block_size;
  460. unsigned char log2_min_transform_block_size_minus2;
  461. unsigned char log2_diff_max_min_transform_block_size;
  462. unsigned char pcm_enabled_flag;
  463. unsigned char log2_min_pcm_luma_coding_block_size_minus3;
  464. unsigned char log2_diff_max_min_pcm_luma_coding_block_size;
  465. unsigned char pcm_sample_bit_depth_luma_minus1;
  466. unsigned char pcm_sample_bit_depth_chroma_minus1;
  467. unsigned char pcm_loop_filter_disabled_flag;
  468. unsigned char strong_intra_smoothing_enabled_flag;
  469. unsigned char max_transform_hierarchy_depth_intra;
  470. unsigned char max_transform_hierarchy_depth_inter;
  471. unsigned char amp_enabled_flag;
  472. unsigned char separate_colour_plane_flag;
  473. unsigned char log2_max_pic_order_cnt_lsb_minus4;
  474. unsigned char num_short_term_ref_pic_sets;
  475. unsigned char long_term_ref_pics_present_flag;
  476. unsigned char num_long_term_ref_pics_sps;
  477. unsigned char sps_temporal_mvp_enabled_flag;
  478. unsigned char sample_adaptive_offset_enabled_flag;
  479. unsigned char scaling_list_enable_flag;
  480. unsigned char IrapPicFlag;
  481. unsigned char IdrPicFlag;
  482. unsigned char bit_depth_luma_minus8;
  483. unsigned char bit_depth_chroma_minus8;
  484. //sps/pps extension fields
  485. unsigned char log2_max_transform_skip_block_size_minus2;
  486. unsigned char log2_sao_offset_scale_luma;
  487. unsigned char log2_sao_offset_scale_chroma;
  488. unsigned char high_precision_offsets_enabled_flag;
  489. unsigned char reserved1[10];
  490. // pps
  491. unsigned char dependent_slice_segments_enabled_flag;
  492. unsigned char slice_segment_header_extension_present_flag;
  493. unsigned char sign_data_hiding_enabled_flag;
  494. unsigned char cu_qp_delta_enabled_flag;
  495. unsigned char diff_cu_qp_delta_depth;
  496. signed char init_qp_minus26;
  497. signed char pps_cb_qp_offset;
  498. signed char pps_cr_qp_offset;
  499. unsigned char constrained_intra_pred_flag;
  500. unsigned char weighted_pred_flag;
  501. unsigned char weighted_bipred_flag;
  502. unsigned char transform_skip_enabled_flag;
  503. unsigned char transquant_bypass_enabled_flag;
  504. unsigned char entropy_coding_sync_enabled_flag;
  505. unsigned char log2_parallel_merge_level_minus2;
  506. unsigned char num_extra_slice_header_bits;
  507. unsigned char loop_filter_across_tiles_enabled_flag;
  508. unsigned char loop_filter_across_slices_enabled_flag;
  509. unsigned char output_flag_present_flag;
  510. unsigned char num_ref_idx_l0_default_active_minus1;
  511. unsigned char num_ref_idx_l1_default_active_minus1;
  512. unsigned char lists_modification_present_flag;
  513. unsigned char cabac_init_present_flag;
  514. unsigned char pps_slice_chroma_qp_offsets_present_flag;
  515. unsigned char deblocking_filter_override_enabled_flag;
  516. unsigned char pps_deblocking_filter_disabled_flag;
  517. signed char pps_beta_offset_div2;
  518. signed char pps_tc_offset_div2;
  519. unsigned char tiles_enabled_flag;
  520. unsigned char uniform_spacing_flag;
  521. unsigned char num_tile_columns_minus1;
  522. unsigned char num_tile_rows_minus1;
  523. unsigned short column_width_minus1[21];
  524. unsigned short row_height_minus1[21];
  525. // sps and pps extension HEVC-main 444
  526. unsigned char sps_range_extension_flag;
  527. unsigned char transform_skip_rotation_enabled_flag;
  528. unsigned char transform_skip_context_enabled_flag;
  529. unsigned char implicit_rdpcm_enabled_flag;
  530. unsigned char explicit_rdpcm_enabled_flag;
  531. unsigned char extended_precision_processing_flag;
  532. unsigned char intra_smoothing_disabled_flag;
  533. unsigned char persistent_rice_adaptation_enabled_flag;
  534. unsigned char cabac_bypass_alignment_enabled_flag;
  535. unsigned char pps_range_extension_flag;
  536. unsigned char cross_component_prediction_enabled_flag;
  537. unsigned char chroma_qp_offset_list_enabled_flag;
  538. unsigned char diff_cu_chroma_qp_offset_depth;
  539. unsigned char chroma_qp_offset_list_len_minus1;
  540. signed char cb_qp_offset_list[6];
  541. signed char cr_qp_offset_list[6];
  542. unsigned char reserved2[2];
  543. unsigned int reserved3[8];
  544. // RefPicSets
  545. int NumBitsForShortTermRPSInSlice;
  546. int NumDeltaPocsOfRefRpsIdx;
  547. int NumPocTotalCurr;
  548. int NumPocStCurrBefore;
  549. int NumPocStCurrAfter;
  550. int NumPocLtCurr;
  551. int CurrPicOrderCntVal;
  552. int RefPicIdx[16]; // [refpic] Indices of valid reference pictures (-1 if unused for reference)
  553. int PicOrderCntVal[16]; // [refpic]
  554. unsigned char IsLongTerm[16]; // [refpic] 0=not a long-term reference, 1=long-term reference
  555. unsigned char RefPicSetStCurrBefore[8]; // [0..NumPocStCurrBefore-1] -> refpic (0..15)
  556. unsigned char RefPicSetStCurrAfter[8]; // [0..NumPocStCurrAfter-1] -> refpic (0..15)
  557. unsigned char RefPicSetLtCurr[8]; // [0..NumPocLtCurr-1] -> refpic (0..15)
  558. unsigned char RefPicSetInterLayer0[8];
  559. unsigned char RefPicSetInterLayer1[8];
  560. unsigned int reserved4[12];
  561. // scaling lists (diag order)
  562. unsigned char ScalingList4x4[6][16]; // [matrixId][i]
  563. unsigned char ScalingList8x8[6][64]; // [matrixId][i]
  564. unsigned char ScalingList16x16[6][64]; // [matrixId][i]
  565. unsigned char ScalingList32x32[2][64]; // [matrixId][i]
  566. unsigned char ScalingListDCCoeff16x16[6]; // [matrixId]
  567. unsigned char ScalingListDCCoeff32x32[2]; // [matrixId]
  568. } CUVIDHEVCPICPARAMS;
  569. /***********************************************************/
  570. //! \struct CUVIDVP8PICPARAMS
  571. //! VP8 picture parameters
  572. //! This structure is used in CUVIDPICPARAMS structure
  573. /***********************************************************/
  574. typedef struct _CUVIDVP8PICPARAMS
  575. {
  576. int width;
  577. int height;
  578. unsigned int first_partition_size;
  579. //Frame Indexes
  580. unsigned char LastRefIdx;
  581. unsigned char GoldenRefIdx;
  582. unsigned char AltRefIdx;
  583. union {
  584. struct {
  585. unsigned char frame_type : 1; /**< 0 = KEYFRAME, 1 = INTERFRAME */
  586. unsigned char version : 3;
  587. unsigned char show_frame : 1;
  588. unsigned char update_mb_segmentation_data : 1; /**< Must be 0 if segmentation is not enabled */
  589. unsigned char Reserved2Bits : 2;
  590. }vp8_frame_tag;
  591. unsigned char wFrameTagFlags;
  592. };
  593. unsigned char Reserved1[4];
  594. unsigned int Reserved2[3];
  595. } CUVIDVP8PICPARAMS;
  596. /***********************************************************/
  597. //! \struct CUVIDVP9PICPARAMS
  598. //! VP9 picture parameters
  599. //! This structure is used in CUVIDPICPARAMS structure
  600. /***********************************************************/
  601. typedef struct _CUVIDVP9PICPARAMS
  602. {
  603. unsigned int width;
  604. unsigned int height;
  605. //Frame Indices
  606. unsigned char LastRefIdx;
  607. unsigned char GoldenRefIdx;
  608. unsigned char AltRefIdx;
  609. unsigned char colorSpace;
  610. unsigned short profile : 3;
  611. unsigned short frameContextIdx : 2;
  612. unsigned short frameType : 1;
  613. unsigned short showFrame : 1;
  614. unsigned short errorResilient : 1;
  615. unsigned short frameParallelDecoding : 1;
  616. unsigned short subSamplingX : 1;
  617. unsigned short subSamplingY : 1;
  618. unsigned short intraOnly : 1;
  619. unsigned short allow_high_precision_mv : 1;
  620. unsigned short refreshEntropyProbs : 1;
  621. unsigned short reserved2Bits : 2;
  622. unsigned short reserved16Bits;
  623. unsigned char refFrameSignBias[4];
  624. unsigned char bitDepthMinus8Luma;
  625. unsigned char bitDepthMinus8Chroma;
  626. unsigned char loopFilterLevel;
  627. unsigned char loopFilterSharpness;
  628. unsigned char modeRefLfEnabled;
  629. unsigned char log2_tile_columns;
  630. unsigned char log2_tile_rows;
  631. unsigned char segmentEnabled : 1;
  632. unsigned char segmentMapUpdate : 1;
  633. unsigned char segmentMapTemporalUpdate : 1;
  634. unsigned char segmentFeatureMode : 1;
  635. unsigned char reserved4Bits : 4;
  636. unsigned char segmentFeatureEnable[8][4];
  637. short segmentFeatureData[8][4];
  638. unsigned char mb_segment_tree_probs[7];
  639. unsigned char segment_pred_probs[3];
  640. unsigned char reservedSegment16Bits[2];
  641. int qpYAc;
  642. int qpYDc;
  643. int qpChDc;
  644. int qpChAc;
  645. unsigned int activeRefIdx[3];
  646. unsigned int resetFrameContext;
  647. unsigned int mcomp_filter_type;
  648. unsigned int mbRefLfDelta[4];
  649. unsigned int mbModeLfDelta[2];
  650. unsigned int frameTagSize;
  651. unsigned int offsetToDctParts;
  652. unsigned int reserved128Bits[4];
  653. } CUVIDVP9PICPARAMS;
  654. /******************************************************************************************/
  655. //! \struct CUVIDPICPARAMS
  656. //! Picture parameters for decoding
  657. //! This structure is used in cuvidDecodePicture API
  658. //! IN for cuvidDecodePicture
  659. /******************************************************************************************/
  660. typedef struct _CUVIDPICPARAMS
  661. {
  662. int PicWidthInMbs; /**< IN: Coded frame size in macroblocks */
  663. int FrameHeightInMbs; /**< IN: Coded frame height in macroblocks */
  664. int CurrPicIdx; /**< IN: Output index of the current picture */
  665. int field_pic_flag; /**< IN: 0=frame picture, 1=field picture */
  666. int bottom_field_flag; /**< IN: 0=top field, 1=bottom field (ignored if field_pic_flag=0) */
  667. int second_field; /**< IN: Second field of a complementary field pair */
  668. // Bitstream data
  669. unsigned int nBitstreamDataLen; /**< IN: Number of bytes in bitstream data buffer */
  670. const unsigned char *pBitstreamData; /**< IN: Ptr to bitstream data for this picture (slice-layer) */
  671. unsigned int nNumSlices; /**< IN: Number of slices in this picture */
  672. const unsigned int *pSliceDataOffsets; /**< IN: nNumSlices entries, contains offset of each slice within
  673. the bitstream data buffer */
  674. int ref_pic_flag; /**< IN: This picture is a reference picture */
  675. int intra_pic_flag; /**< IN: This picture is entirely intra coded */
  676. unsigned int Reserved[30]; /**< Reserved for future use */
  677. // IN: Codec-specific data
  678. union {
  679. CUVIDMPEG2PICPARAMS mpeg2; /**< Also used for MPEG-1 */
  680. CUVIDH264PICPARAMS h264;
  681. CUVIDVC1PICPARAMS vc1;
  682. CUVIDMPEG4PICPARAMS mpeg4;
  683. CUVIDJPEGPICPARAMS jpeg;
  684. CUVIDHEVCPICPARAMS hevc;
  685. CUVIDVP8PICPARAMS vp8;
  686. CUVIDVP9PICPARAMS vp9;
  687. unsigned int CodecReserved[1024];
  688. } CodecSpecific;
  689. } CUVIDPICPARAMS;
  690. /******************************************************/
  691. //! \struct CUVIDPROCPARAMS
  692. //! Picture parameters for postprocessing
  693. //! This structure is used in cuvidMapVideoFrame API
  694. /******************************************************/
  695. typedef struct _CUVIDPROCPARAMS
  696. {
  697. int progressive_frame; /**< IN: Input is progressive (deinterlace_mode will be ignored) */
  698. int second_field; /**< IN: Output the second field (ignored if deinterlace mode is Weave) */
  699. int top_field_first; /**< IN: Input frame is top field first (1st field is top, 2nd field is bottom) */
  700. int unpaired_field; /**< IN: Input only contains one field (2nd field is invalid) */
  701. // The fields below are used for raw YUV input
  702. unsigned int reserved_flags; /**< Reserved for future use (set to zero) */
  703. unsigned int reserved_zero; /**< Reserved (set to zero) */
  704. unsigned long long raw_input_dptr; /**< IN: Input CUdeviceptr for raw YUV extensions */
  705. unsigned int raw_input_pitch; /**< IN: pitch in bytes of raw YUV input (should be aligned appropriately) */
  706. unsigned int raw_input_format; /**< IN: Input YUV format (cudaVideoCodec_enum) */
  707. unsigned long long raw_output_dptr; /**< IN: Output CUdeviceptr for raw YUV extensions */
  708. unsigned int raw_output_pitch; /**< IN: pitch in bytes of raw YUV output (should be aligned appropriately) */
  709. unsigned int Reserved1; /**< Reserved for future use (set to zero) */
  710. CUstream output_stream; /**< IN: stream object used by cuvidMapVideoFrame */
  711. unsigned int Reserved[46]; /**< Reserved for future use (set to zero) */
  712. void *Reserved2[2]; /**< Reserved for future use (set to zero) */
  713. } CUVIDPROCPARAMS;
  714. /*********************************************************************************************************/
  715. //! \struct CUVIDGETDECODESTATUS
  716. //! Struct for reporting decode status.
  717. //! This structure is used in cuvidGetDecodeStatus API.
  718. /*********************************************************************************************************/
  719. typedef struct _CUVIDGETDECODESTATUS
  720. {
  721. cuvidDecodeStatus decodeStatus;
  722. unsigned int reserved[31];
  723. void *pReserved[8];
  724. } CUVIDGETDECODESTATUS;
  725. /****************************************************/
  726. //! \struct CUVIDRECONFIGUREDECODERINFO
  727. //! Struct for decoder reset
  728. //! This structure is used in cuvidReconfigureDecoder() API
  729. /****************************************************/
  730. typedef struct _CUVIDRECONFIGUREDECODERINFO
  731. {
  732. unsigned int ulWidth; /**< IN: Coded sequence width in pixels, MUST be < = ulMaxWidth defined at CUVIDDECODECREATEINFO */
  733. unsigned int ulHeight; /**< IN: Coded sequence height in pixels, MUST be < = ulMaxHeight defined at CUVIDDECODECREATEINFO */
  734. unsigned int ulTargetWidth; /**< IN: Post processed output width */
  735. unsigned int ulTargetHeight; /**< IN: Post Processed output height */
  736. unsigned int ulNumDecodeSurfaces; /**< IN: Maximum number of internal decode surfaces */
  737. unsigned int reserved1[12]; /**< Reserved for future use. Set to Zero */
  738. /**
  739. * IN: Area of frame to be displayed. Use-case : Source Cropping
  740. */
  741. struct {
  742. short left;
  743. short top;
  744. short right;
  745. short bottom;
  746. } display_area;
  747. /**
  748. * IN: Target Rectangle in the OutputFrame. Use-case : Aspect ratio Conversion
  749. */
  750. struct {
  751. short left;
  752. short top;
  753. short right;
  754. short bottom;
  755. } target_rect;
  756. unsigned int reserved2[11]; /**< Reserved for future use. Set to Zero */
  757. } CUVIDRECONFIGUREDECODERINFO;
  758. /***********************************************************************************************************/
  759. //! VIDEO_DECODER
  760. //!
  761. //! In order to minimize decode latencies, there should be always at least 2 pictures in the decode
  762. //! queue at any time, in order to make sure that all decode engines are always busy.
  763. //!
  764. //! Overall data flow:
  765. //! - cuvidGetDecoderCaps(...)
  766. //! - cuvidCreateDecoder(...)
  767. //! - For each picture:
  768. //! + cuvidDecodePicture(N)
  769. //! + cuvidMapVideoFrame(N-4)
  770. //! + do some processing in cuda
  771. //! + cuvidUnmapVideoFrame(N-4)
  772. //! + cuvidDecodePicture(N+1)
  773. //! + cuvidMapVideoFrame(N-3)
  774. //! + ...
  775. //! - cuvidDestroyDecoder(...)
  776. //!
  777. //! NOTE:
  778. //! - When the cuda context is created from a D3D device, the D3D device must also be created
  779. //! with the D3DCREATE_MULTITHREADED flag.
  780. //! - There is a limit to how many pictures can be mapped simultaneously (ulNumOutputSurfaces)
  781. //! - cuvidDecodePicture may block the calling thread if there are too many pictures pending
  782. //! in the decode queue
  783. /***********************************************************************************************************/
  784. /**********************************************************************************************************************/
  785. //! \fn CUresult CUDAAPI cuvidGetDecoderCaps(CUVIDDECODECAPS *pdc)
  786. //! Queries decode capabilities of NVDEC-HW based on CodecType, ChromaFormat and BitDepthMinus8 parameters.
  787. //! 1. Application fills IN parameters CodecType, ChromaFormat and BitDepthMinus8 of CUVIDDECODECAPS structure
  788. //! 2. On calling cuvidGetDecoderCaps, driver fills OUT parameters if the IN parameters are supported
  789. //! If IN parameters passed to the driver are not supported by NVDEC-HW, then all OUT params are set to 0.
  790. //! E.g. on Geforce GTX 960:
  791. //! App fills - eCodecType = cudaVideoCodec_H264; eChromaFormat = cudaVideoChromaFormat_420; nBitDepthMinus8 = 0;
  792. //! Given IN parameters are supported, hence driver fills: bIsSupported = 1; nMinWidth = 48; nMinHeight = 16;
  793. //! nMaxWidth = 4096; nMaxHeight = 4096; nMaxMBCount = 65536;
  794. //! CodedWidth*CodedHeight/256 must be less than or equal to nMaxMBCount
  795. /**********************************************************************************************************************/
  796. extern CUresult CUDAAPI cuvidGetDecoderCaps(CUVIDDECODECAPS *pdc);
  797. /*****************************************************************************************************/
  798. //! \fn CUresult CUDAAPI cuvidCreateDecoder(CUvideodecoder *phDecoder, CUVIDDECODECREATEINFO *pdci)
  799. //! Create the decoder object based on pdci. A handle to the created decoder is returned
  800. /*****************************************************************************************************/
  801. extern CUresult CUDAAPI cuvidCreateDecoder(CUvideodecoder *phDecoder, CUVIDDECODECREATEINFO *pdci);
  802. /*****************************************************************************************************/
  803. //! \fn CUresult CUDAAPI cuvidDestroyDecoder(CUvideodecoder hDecoder)
  804. //! Destroy the decoder object
  805. /*****************************************************************************************************/
  806. extern CUresult CUDAAPI cuvidDestroyDecoder(CUvideodecoder hDecoder);
  807. /*****************************************************************************************************/
  808. //! \fn CUresult CUDAAPI cuvidDecodePicture(CUvideodecoder hDecoder, CUVIDPICPARAMS *pPicParams)
  809. //! Decode a single picture (field or frame)
  810. //! Kicks off HW decoding
  811. /*****************************************************************************************************/
  812. extern CUresult CUDAAPI cuvidDecodePicture(CUvideodecoder hDecoder, CUVIDPICPARAMS *pPicParams);
  813. /************************************************************************************************************/
  814. //! \fn CUresult CUDAAPI cuvidGetDecodeStatus(CUvideodecoder hDecoder, int nPicIdx);
  815. //! Get the decode status for frame corresponding to nPicIdx
  816. //! API is supported for Maxwell and above generation GPUs.
  817. //! API is currently supported for HEVC, H264 and JPEG codecs.
  818. //! API returns CUDA_ERROR_NOT_SUPPORTED error code for unsupported GPU or codec.
  819. /************************************************************************************************************/
  820. extern CUresult CUDAAPI cuvidGetDecodeStatus(CUvideodecoder hDecoder, int nPicIdx, CUVIDGETDECODESTATUS* pDecodeStatus);
  821. /*********************************************************************************************************/
  822. //! \fn CUresult CUDAAPI cuvidReconfigureDecoder(CUvideodecoder hDecoder, CUVIDRECONFIGUREDECODERINFO *pDecReconfigParams)
  823. //! Used to reuse single decoder for multiple clips. Currently supports resolution change, resize params, display area
  824. //! params, target area params change for same codec. Must be called during CUVIDPARSERPARAMS::pfnSequenceCallback
  825. /*********************************************************************************************************/
  826. extern CUresult CUDAAPI cuvidReconfigureDecoder(CUvideodecoder hDecoder, CUVIDRECONFIGUREDECODERINFO *pDecReconfigParams);
  827. #if !defined(__CUVID_DEVPTR64) || defined(__CUVID_INTERNAL)
  828. /************************************************************************************************************************/
  829. //! \fn CUresult CUDAAPI cuvidMapVideoFrame(CUvideodecoder hDecoder, int nPicIdx, unsigned int *pDevPtr,
  830. //! unsigned int *pPitch, CUVIDPROCPARAMS *pVPP);
  831. //! Post-process and map video frame corresponding to nPicIdx for use in cuda. Returns cuda device pointer and associated
  832. //! pitch of the video frame
  833. /************************************************************************************************************************/
  834. extern CUresult CUDAAPI cuvidMapVideoFrame(CUvideodecoder hDecoder, int nPicIdx,
  835. unsigned int *pDevPtr, unsigned int *pPitch,
  836. CUVIDPROCPARAMS *pVPP);
  837. /*****************************************************************************************************/
  838. //! \fn CUresult CUDAAPI cuvidUnmapVideoFrame(CUvideodecoder hDecoder, unsigned int DevPtr)
  839. //! Unmap a previously mapped video frame
  840. /*****************************************************************************************************/
  841. extern CUresult CUDAAPI cuvidUnmapVideoFrame(CUvideodecoder hDecoder, unsigned int DevPtr);
  842. #endif
  843. #if defined(_WIN64) || defined(__LP64__) || defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
  844. /****************************************************************************************************************************/
  845. //! \fn CUresult CUDAAPI cuvidMapVideoFrame64(CUvideodecoder hDecoder, int nPicIdx, unsigned long long *pDevPtr,
  846. //! unsigned int * pPitch, CUVIDPROCPARAMS *pVPP);
  847. //! Post-process and map video frame corresponding to nPicIdx for use in cuda. Returns cuda device pointer and associated
  848. //! pitch of the video frame
  849. /****************************************************************************************************************************/
  850. extern CUresult CUDAAPI cuvidMapVideoFrame64(CUvideodecoder hDecoder, int nPicIdx, unsigned long long *pDevPtr,
  851. unsigned int *pPitch, CUVIDPROCPARAMS *pVPP);
  852. /**************************************************************************************************/
  853. //! \fn CUresult CUDAAPI cuvidUnmapVideoFrame64(CUvideodecoder hDecoder, unsigned long long DevPtr);
  854. //! Unmap a previously mapped video frame
  855. /**************************************************************************************************/
  856. extern CUresult CUDAAPI cuvidUnmapVideoFrame64(CUvideodecoder hDecoder, unsigned long long DevPtr);
  857. #if defined(__CUVID_DEVPTR64) && !defined(__CUVID_INTERNAL)
  858. #define cuvidMapVideoFrame cuvidMapVideoFrame64
  859. #define cuvidUnmapVideoFrame cuvidUnmapVideoFrame64
  860. #endif
  861. #endif
  862. /********************************************************************************************************************/
  863. //!
  864. //! Context-locking: to facilitate multi-threaded implementations, the following 4 functions
  865. //! provide a simple mutex-style host synchronization. If a non-NULL context is specified
  866. //! in CUVIDDECODECREATEINFO, the codec library will acquire the mutex associated with the given
  867. //! context before making any cuda calls.
  868. //! A multi-threaded application could create a lock associated with a context handle so that
  869. //! multiple threads can safely share the same cuda context:
  870. //! - use cuCtxPopCurrent immediately after context creation in order to create a 'floating' context
  871. //! that can be passed to cuvidCtxLockCreate.
  872. //! - When using a floating context, all cuda calls should only be made within a cuvidCtxLock/cuvidCtxUnlock section.
  873. //!
  874. //! NOTE: This is a safer alternative to cuCtxPushCurrent and cuCtxPopCurrent, and is not related to video
  875. //! decoder in any way (implemented as a critical section associated with cuCtx{Push|Pop}Current calls).
  876. /********************************************************************************************************************/
  877. /********************************************************************************************************************/
  878. //! \fn CUresult CUDAAPI cuvidCtxLockCreate(CUvideoctxlock *pLock, CUcontext ctx)
  879. //! This API is used to create CtxLock object
  880. /********************************************************************************************************************/
  881. extern CUresult CUDAAPI cuvidCtxLockCreate(CUvideoctxlock *pLock, CUcontext ctx);
  882. /********************************************************************************************************************/
  883. //! \fn CUresult CUDAAPI cuvidCtxLockDestroy(CUvideoctxlock lck)
  884. //! This API is used to free CtxLock object
  885. /********************************************************************************************************************/
  886. extern CUresult CUDAAPI cuvidCtxLockDestroy(CUvideoctxlock lck);
  887. /********************************************************************************************************************/
  888. //! \fn CUresult CUDAAPI cuvidCtxLock(CUvideoctxlock lck, unsigned int reserved_flags)
  889. //! This API is used to acquire ctxlock
  890. /********************************************************************************************************************/
  891. extern CUresult CUDAAPI cuvidCtxLock(CUvideoctxlock lck, unsigned int reserved_flags);
  892. /********************************************************************************************************************/
  893. //! \fn CUresult CUDAAPI cuvidCtxUnlock(CUvideoctxlock lck, unsigned int reserved_flags)
  894. //! This API is used to release ctxlock
  895. /********************************************************************************************************************/
  896. extern CUresult CUDAAPI cuvidCtxUnlock(CUvideoctxlock lck, unsigned int reserved_flags);
  897. /**********************************************************************************************/
  898. #if defined(__cplusplus)
  899. }
  900. // Auto-lock helper for C++ applications
  901. class CCtxAutoLock
  902. {
  903. private:
  904. CUvideoctxlock m_ctx;
  905. public:
  906. CCtxAutoLock(CUvideoctxlock ctx):m_ctx(ctx) { cuvidCtxLock(m_ctx,0); }
  907. ~CCtxAutoLock() { cuvidCtxUnlock(m_ctx,0); }
  908. };
  909. #endif /* __cplusplus */
  910. #endif // __CUDA_VIDEO_H__