FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvcuvid.h
Go to the documentation of this file.
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 nvcuvid.h
30  * NvCuvid API provides Video Decoding interface to NVIDIA GPU devices.
31  * \date 2015-2015
32  * This file contains the interface constants, structure definitions and function prototypes.
33  */
34 
35 #if !defined(__NVCUVID_H__)
36 #define __NVCUVID_H__
37 
38 #include "compat/cuda/cuviddec.h"
39 
40 #if defined(__cplusplus)
41 extern "C" {
42 #endif /* __cplusplus */
43 
44 /*********************************
45 ** Initialization
46 *********************************/
47 CUresult CUDAAPI cuvidInit(unsigned int Flags);
48 
49 ////////////////////////////////////////////////////////////////////////////////////////////////
50 //
51 // High-level helper APIs for video sources
52 //
53 
54 typedef void *CUvideosource;
55 typedef void *CUvideoparser;
56 typedef long long CUvideotimestamp;
57 
58 /**
59  * \addtogroup VIDEO_PARSER Video Parser
60  * @{
61  */
62 
63 /*!
64  * \enum cudaVideoState
65  * Video Source State
66  */
67 typedef enum {
68  cudaVideoState_Error = -1, /**< Error state (invalid source) */
69  cudaVideoState_Stopped = 0, /**< Source is stopped (or reached end-of-stream) */
70  cudaVideoState_Started = 1 /**< Source is running and delivering data */
72 
73 /*!
74  * \enum cudaAudioCodec
75  * Audio compression
76  */
77 typedef enum {
78  cudaAudioCodec_MPEG1=0, /**< MPEG-1 Audio */
79  cudaAudioCodec_MPEG2, /**< MPEG-2 Audio */
80  cudaAudioCodec_MP3, /**< MPEG-1 Layer III Audio */
81  cudaAudioCodec_AC3, /**< Dolby Digital (AC3) Audio */
82  cudaAudioCodec_LPCM /**< PCM Audio */
84 
85 /*!
86  * \struct CUVIDEOFORMAT
87  * Video format
88  */
89 typedef struct
90 {
91  cudaVideoCodec codec; /**< Compression format */
92  /**
93  * frame rate = numerator / denominator (for example: 30000/1001)
94  */
95  struct {
96  unsigned int numerator; /**< frame rate numerator (0 = unspecified or variable frame rate) */
97  unsigned int denominator; /**< frame rate denominator (0 = unspecified or variable frame rate) */
98  } frame_rate;
99  unsigned char progressive_sequence; /**< 0=interlaced, 1=progressive */
100  unsigned char bit_depth_luma_minus8; /**< high bit depth Luma */
101  unsigned char bit_depth_chroma_minus8; /**< high bit depth Chroma */
102  unsigned char reserved1; /**< Reserved for future use */
103  unsigned int coded_width; /**< coded frame width */
104  unsigned int coded_height; /**< coded frame height */
105  /**
106  * area of the frame that should be displayed
107  * typical example:
108  * coded_width = 1920, coded_height = 1088
109  * display_area = { 0,0,1920,1080 }
110  */
111  struct {
112  int left; /**< left position of display rect */
113  int top; /**< top position of display rect */
114  int right; /**< right position of display rect */
115  int bottom; /**< bottom position of display rect */
116  } display_area;
117  cudaVideoChromaFormat chroma_format; /**< Chroma format */
118  unsigned int bitrate; /**< video bitrate (bps, 0=unknown) */
119  /**
120  * Display Aspect Ratio = x:y (4:3, 16:9, etc)
121  */
122  struct {
123  int x;
124  int y;
125  } display_aspect_ratio;
126  /**
127  * Video Signal Description
128  */
129  struct {
130  unsigned char video_format : 3;
131  unsigned char video_full_range_flag : 1;
132  unsigned char reserved_zero_bits : 4;
133  unsigned char color_primaries;
135  unsigned char matrix_coefficients;
136  } video_signal_description;
137  unsigned int seqhdr_data_length; /**< Additional bytes following (CUVIDEOFORMATEX) */
138 } CUVIDEOFORMAT;
139 
140 /*!
141  * \struct CUVIDEOFORMATEX
142  * Video format including raw sequence header information
143  */
144 typedef struct
145 {
147  unsigned char raw_seqhdr_data[1024];
149 
150 /*!
151  * \struct CUAUDIOFORMAT
152  * Audio Formats
153  */
154 typedef struct
155 {
156  cudaAudioCodec codec; /**< Compression format */
157  unsigned int channels; /**< number of audio channels */
158  unsigned int samplespersec; /**< sampling frequency */
159  unsigned int bitrate; /**< For uncompressed, can also be used to determine bits per sample */
160  unsigned int reserved1; /**< Reserved for future use */
161  unsigned int reserved2; /**< Reserved for future use */
162 } CUAUDIOFORMAT;
163 
164 
165 /*!
166  * \enum CUvideopacketflags
167  * Data packet flags
168  */
169 typedef enum {
170  CUVID_PKT_ENDOFSTREAM = 0x01, /**< Set when this is the last packet for this stream */
171  CUVID_PKT_TIMESTAMP = 0x02, /**< Timestamp is valid */
172  CUVID_PKT_DISCONTINUITY = 0x04 /**< Set when a discontinuity has to be signalled */
174 
175 /*!
176  * \struct CUVIDSOURCEDATAPACKET
177  * Data Packet
178  */
179 typedef struct _CUVIDSOURCEDATAPACKET
180 {
181  unsigned long flags; /**< Combination of CUVID_PKT_XXX flags */
182  unsigned long payload_size; /**< number of bytes in the payload (may be zero if EOS flag is set) */
183  const unsigned char *payload; /**< Pointer to packet payload data (may be NULL if EOS flag is set) */
184  CUvideotimestamp timestamp; /**< Presentation timestamp (10MHz clock), only valid if CUVID_PKT_TIMESTAMP flag is set */
186 
187 // Callback for packet delivery
189 
190 /*!
191  * \struct CUVIDSOURCEPARAMS
192  * Source Params
193  */
194 typedef struct _CUVIDSOURCEPARAMS
195 {
196  unsigned int ulClockRate; /**< Timestamp units in Hz (0=default=10000000Hz) */
197  unsigned int uReserved1[7]; /**< Reserved for future use - set to zero */
198  void *pUserData; /**< Parameter passed in to the data handlers */
199  PFNVIDSOURCECALLBACK pfnVideoDataHandler; /**< Called to deliver audio packets */
200  PFNVIDSOURCECALLBACK pfnAudioDataHandler; /**< Called to deliver video packets */
201  void *pvReserved2[8]; /**< Reserved for future use - set to NULL */
203 
204 /*!
205  * \enum CUvideosourceformat_flags
206  * CUvideosourceformat_flags
207  */
208 typedef enum {
209  CUVID_FMT_EXTFORMATINFO = 0x100 /**< Return extended format structure (CUVIDEOFORMATEX) */
211 
212 #if !defined(__APPLE__)
213 /**
214  * \fn CUresult CUDAAPI cuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams)
215  * Create Video Source
216  */
217 CUresult CUDAAPI cuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams);
218 
219 /**
220  * \fn CUresult CUDAAPI cuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams)
221  * Create Video Source
222  */
223 CUresult CUDAAPI cuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams);
224 
225 /**
226  * \fn CUresult CUDAAPI cuvidDestroyVideoSource(CUvideosource obj)
227  * Destroy Video Source
228  */
229 CUresult CUDAAPI cuvidDestroyVideoSource(CUvideosource obj);
230 
231 /**
232  * \fn CUresult CUDAAPI cuvidSetVideoSourceState(CUvideosource obj, cudaVideoState state)
233  * Set Video Source state
234  */
236 
237 /**
238  * \fn cudaVideoState CUDAAPI cuvidGetVideoSourceState(CUvideosource obj)
239  * Get Video Source state
240  */
242 
243 /**
244  * \fn CUresult CUDAAPI cuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags)
245  * Get Video Source Format
246  */
247 CUresult CUDAAPI cuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags);
248 
249 /**
250  * \fn CUresult CUDAAPI cuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags)
251  * Set Video Source state
252  */
253 CUresult CUDAAPI cuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags);
254 
255 #endif
256 
257 /**
258  * \struct CUVIDPARSERDISPINFO
259  */
260 typedef struct _CUVIDPARSERDISPINFO
261 {
262  int picture_index; /**< */
263  int progressive_frame; /**< */
264  int top_field_first; /**< */
265  int repeat_first_field; /**< Number of additional fields (1=ivtc, 2=frame doubling, 4=frame tripling, -1=unpaired field) */
266  CUvideotimestamp timestamp; /**< */
268 
269 //
270 // Parser callbacks
271 // The parser will call these synchronously from within cuvidParseVideoData(), whenever a picture is ready to
272 // be decoded and/or displayed.
273 //
274 typedef int (CUDAAPI *PFNVIDSEQUENCECALLBACK)(void *, CUVIDEOFORMAT *);
275 typedef int (CUDAAPI *PFNVIDDECODECALLBACK)(void *, CUVIDPICPARAMS *);
277 
278 /**
279  * \struct CUVIDPARSERPARAMS
280  */
281 typedef struct _CUVIDPARSERPARAMS
282 {
283  cudaVideoCodec CodecType; /**< cudaVideoCodec_XXX */
284  unsigned int ulMaxNumDecodeSurfaces; /**< Max # of decode surfaces (parser will cycle through these) */
285  unsigned int ulClockRate; /**< Timestamp units in Hz (0=default=10000000Hz) */
286  unsigned int ulErrorThreshold; /**< % Error threshold (0-100) for calling pfnDecodePicture (100=always call pfnDecodePicture even if picture bitstream is fully corrupted) */
287  unsigned int ulMaxDisplayDelay; /**< Max display queue delay (improves pipelining of decode with display) - 0=no delay (recommended values: 2..4) */
288  unsigned int uReserved1[5]; /**< Reserved for future use - set to 0 */
289  void *pUserData; /**< User data for callbacks */
290  PFNVIDSEQUENCECALLBACK pfnSequenceCallback; /**< Called before decoding frames and/or whenever there is a format change */
291  PFNVIDDECODECALLBACK pfnDecodePicture; /**< Called when a picture is ready to be decoded (decode order) */
292  PFNVIDDISPLAYCALLBACK pfnDisplayPicture; /**< Called whenever a picture is ready to be displayed (display order) */
293  void *pvReserved2[7]; /**< Reserved for future use - set to NULL */
294  CUVIDEOFORMATEX *pExtVideoInfo; /**< [Optional] sequence header data from system layer */
296 
297 /**
298  * \fn CUresult CUDAAPI cuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams)
299  */
300 CUresult CUDAAPI cuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams);
301 
302 /**
303  * \fn CUresult CUDAAPI cuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket)
304  */
305 CUresult CUDAAPI cuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket);
306 
307 /**
308  * \fn CUresult CUDAAPI cuvidDestroyVideoParser(CUvideoparser obj)
309  */
310 CUresult CUDAAPI cuvidDestroyVideoParser(CUvideoparser obj);
311 
312 /** @} */ /* END VIDEO_PARSER */
313 ////////////////////////////////////////////////////////////////////////////////////////////////
314 
315 #if defined(__cplusplus)
316 }
317 #endif /* __cplusplus */
318 
319 #endif // __NVCUVID_H__
320 
321 
MPEG-2 Audio.
Definition: nvcuvid.h:79
int top
top position of display rect
Definition: nvcuvid.h:113
CUresult CUDAAPI cuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams)
Create Video Source.
CUvideopacketflags
Definition: nvcuvid.h:169
unsigned char reserved1
Reserved for future use.
Definition: nvcuvid.h:102
int right
right position of display rect
Definition: nvcuvid.h:114
unsigned char bit_depth_chroma_minus8
high bit depth Chroma
Definition: nvcuvid.h:101
unsigned int reserved2
Reserved for future use.
Definition: nvcuvid.h:161
CUresult CUDAAPI cuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags)
Get Video Source Format.
unsigned int seqhdr_data_length
Additional bytes following (CUVIDEOFORMATEX)
Definition: nvcuvid.h:137
CUresult CUDAAPI cuvidDestroyVideoParser(CUvideoparser obj)
void * pUserData
Parameter passed in to the data handlers.
Definition: nvcuvid.h:198
PFNVIDSOURCECALLBACK pfnAudioDataHandler
Called to deliver video packets.
Definition: nvcuvid.h:200
Set when this is the last packet for this stream.
Definition: nvcuvid.h:170
unsigned int samplespersec
sampling frequency
Definition: nvcuvid.h:158
CUresult CUDAAPI cuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags)
Set Video Source state.
CUvideosourceformat_flags
Definition: nvcuvid.h:208
long long CUvideotimestamp
Definition: nvcuvid.h:56
unsigned int numerator
frame rate numerator (0 = unspecified or variable frame rate)
Definition: nvcuvid.h:96
cudaVideoState
Definition: nvcuvid.h:67
unsigned char color_primaries
Definition: nvcuvid.h:133
CUresult CUDAAPI cuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams)
Create Video Source.
unsigned int bitrate
For uncompressed, can also be used to determine bits per sample.
Definition: nvcuvid.h:159
CUresult CUDAAPI cuvidSetVideoSourceState(CUvideosource obj, cudaVideoState state)
Set Video Source state.
CUVIDEOFORMATEX * pExtVideoInfo
[Optional] sequence header data from system layer
Definition: nvcuvid.h:294
int left
left position of display rect
Definition: nvcuvid.h:112
cudaVideoChromaFormat
Definition: cuviddec.h:107
#define CUDAAPI
Definition: nvenc.h:38
unsigned char transfer_characteristics
Definition: nvcuvid.h:134
unsigned char bit_depth_luma_minus8
high bit depth Luma
Definition: nvcuvid.h:100
unsigned int reserved1
Reserved for future use.
Definition: nvcuvid.h:160
Source is running and delivering data.
Definition: nvcuvid.h:70
int(CUDAAPI * PFNVIDDECODECALLBACK)(void *, CUVIDPICPARAMS *)
Definition: nvcuvid.h:275
Set when a discontinuity has to be signalled.
Definition: nvcuvid.h:172
Source is stopped (or reached end-of-stream)
Definition: nvcuvid.h:69
unsigned long payload_size
number of bytes in the payload (may be zero if EOS flag is set)
Definition: nvcuvid.h:182
int bottom
bottom position of display rect
Definition: nvcuvid.h:115
cudaAudioCodec
Definition: nvcuvid.h:77
unsigned int ulClockRate
Timestamp units in Hz (0=default=10000000Hz)
Definition: nvcuvid.h:285
cudaVideoCodec codec
Compression format.
Definition: nvcuvid.h:91
void * CUvideoparser
Definition: nvcuvid.h:55
unsigned int coded_width
coded frame width
Definition: nvcuvid.h:103
unsigned int denominator
frame rate denominator (0 = unspecified or variable frame rate)
Definition: nvcuvid.h:97
CUresult
Definition: nvenc.h:41
MPEG-1 Audio.
Definition: nvcuvid.h:78
Return extended format structure (CUVIDEOFORMATEX)
Definition: nvcuvid.h:209
CUresult CUDAAPI cuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams)
int(CUDAAPI * PFNVIDSOURCECALLBACK)(void *, CUVIDSOURCEDATAPACKET *)
Definition: nvcuvid.h:188
unsigned int ulClockRate
Timestamp units in Hz (0=default=10000000Hz)
Definition: nvcuvid.h:196
unsigned char progressive_sequence
0=interlaced, 1=progressive
Definition: nvcuvid.h:99
unsigned char matrix_coefficients
Definition: nvcuvid.h:135
PFNVIDSEQUENCECALLBACK pfnSequenceCallback
Called before decoding frames and/or whenever there is a format change.
Definition: nvcuvid.h:290
static struct @246 state
PFNVIDSOURCECALLBACK pfnVideoDataHandler
Called to deliver audio packets.
Definition: nvcuvid.h:199
int(CUDAAPI * PFNVIDDISPLAYCALLBACK)(void *, CUVIDPARSERDISPINFO *)
Definition: nvcuvid.h:276
const unsigned char * payload
Pointer to packet payload data (may be NULL if EOS flag is set)
Definition: nvcuvid.h:183
CUvideotimestamp timestamp
Definition: nvcuvid.h:266
unsigned int coded_height
coded frame height
Definition: nvcuvid.h:104
CUresult CUDAAPI cuvidDestroyVideoSource(CUvideosource obj)
Destroy Video Source.
cudaVideoCodec CodecType
cudaVideoCodec_XXX
Definition: nvcuvid.h:283
PCM Audio.
Definition: nvcuvid.h:82
cudaVideoState CUDAAPI cuvidGetVideoSourceState(CUvideosource obj)
Get Video Source state.
CUvideotimestamp timestamp
Presentation timestamp (10MHz clock), only valid if CUVID_PKT_TIMESTAMP flag is set.
Definition: nvcuvid.h:184
static int flags
Definition: cpu.c:47
unsigned int channels
number of audio channels
Definition: nvcuvid.h:157
cudaAudioCodec codec
Compression format.
Definition: nvcuvid.h:156
PFNVIDDECODECALLBACK pfnDecodePicture
Called when a picture is ready to be decoded (decode order)
Definition: nvcuvid.h:291
void * pUserData
User data for callbacks.
Definition: nvcuvid.h:289
unsigned long flags
Combination of CUVID_PKT_XXX flags.
Definition: nvcuvid.h:181
CUVIDEOFORMAT format
Definition: nvcuvid.h:146
unsigned int ulMaxNumDecodeSurfaces
Max # of decode surfaces (parser will cycle through these)
Definition: nvcuvid.h:284
void * CUvideosource
Definition: nvcuvid.h:54
unsigned int bitrate
video bitrate (bps, 0=unknown)
Definition: nvcuvid.h:118
int repeat_first_field
Number of additional fields (1=ivtc, 2=frame doubling, 4=frame tripling, -1=unpaired field) ...
Definition: nvcuvid.h:265
CUresult CUDAAPI cuvidInit(unsigned int Flags)
PFNVIDDISPLAYCALLBACK pfnDisplayPicture
Called whenever a picture is ready to be displayed (display order)
Definition: nvcuvid.h:292
unsigned int ulErrorThreshold
% Error threshold (0-100) for calling pfnDecodePicture (100=always call pfnDecodePicture even if pict...
Definition: nvcuvid.h:286
int(CUDAAPI * PFNVIDSEQUENCECALLBACK)(void *, CUVIDEOFORMAT *)
Definition: nvcuvid.h:274
cudaVideoCodec
Definition: cuviddec.h:64
Error state (invalid source)
Definition: nvcuvid.h:68
unsigned int ulMaxDisplayDelay
Max display queue delay (improves pipelining of decode with display) - 0=no delay (recommended values...
Definition: nvcuvid.h:287
NvCuvid API provides Video Decoding interface to NVIDIA GPU devices.
Dolby Digital (AC3) Audio.
Definition: nvcuvid.h:81
cudaVideoChromaFormat chroma_format
Chroma format.
Definition: nvcuvid.h:117
Timestamp is valid.
Definition: nvcuvid.h:171
CUresult CUDAAPI cuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket)
MPEG-1 Layer III Audio.
Definition: nvcuvid.h:80