cuviddec.h 65 KB

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