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.

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