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.

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