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