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.

816 lines
29KB

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