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