You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

887 lines
44KB

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