2 * Copyright 1993-2008 NVIDIA Corporation. All rights reserved.
6 * This source code is subject to NVIDIA ownership rights under U.S. and
7 * international Copyright laws. Users and possessors of this source code
8 * are hereby granted a nonexclusive, royalty-free license to use this code
9 * in individual and commercial software.
11 * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
12 * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
13 * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
14 * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
16 * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
17 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
18 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
19 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
20 * OR PERFORMANCE OF THIS SOURCE CODE.
22 * U.S. Government End Users. This source code is a "commercial item" as
23 * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
24 * "commercial computer software" and "commercial computer software
25 * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
26 * and is provided to the U.S. Government only as a commercial end item.
27 * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
28 * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
29 * source code with only those rights set forth herein.
31 * Any use of this source code in individual and commercial software must
32 * include, in the user documentation and internal comments to the code,
33 * the above Disclaimer and U.S. Government End Users Notice.
36 #if !defined(__NVCUVID_H__)
41 #if defined(__cplusplus)
43 #endif /* __cplusplus */
45 ////////////////////////////////////////////////////////////////////////////////////////////////
47 // High-level helper APIs for video sources
50 typedef void *CUvideosource;
51 typedef void *CUvideoparser;
52 typedef long long CUvideotimestamp;
54 ////////////////////////////////////////////////////////////////////////////////////////////////
56 // video data structures
61 cudaVideoState_Error = -1, // Error state (invalid source)
62 cudaVideoState_Stopped = 0, // Source is stopped (or reached end-of-stream)
63 cudaVideoState_Started = 1 // Source is running and delivering data
68 cudaAudioCodec_MPEG1=0, // MPEG-1 Audio
69 cudaAudioCodec_MPEG2, // MPEG-2 Audio
70 cudaAudioCodec_MP3, // MPEG-1 Layer III Audio
71 cudaAudioCodec_AC3, // Dolby Digital (AC3) Audio
72 cudaAudioCodec_LPCM // PCM Audio
79 cudaVideoCodec codec; // Compression format
81 unsigned int numerator; // frame rate numerator (0 = unspecified or variable frame rate)
82 unsigned int denominator; // frame rate denominator (0 = unspecified or variable frame rate)
83 } frame_rate; // frame rate = numerator / denominator (for example: 30000/1001)
84 int progressive_sequence; // 0=interlaced, 1=progressive
85 unsigned int coded_width; // coded frame width
86 unsigned int coded_height; // coded frame height
87 struct { // area of the frame that should be displayed
88 int left; // typical example:
89 int top; // coded_width = 1920, coded_height = 1088
90 int right; // display_area = { 0,0,1920,1080 }
93 cudaVideoChromaFormat chroma_format; // Chroma format
94 unsigned int bitrate; // video bitrate (bps, 0=unknown)
95 struct { // Display Aspect Ratio = x:y (4:3, 16:9, etc)
98 } display_aspect_ratio;
100 unsigned char video_format;
101 unsigned char color_primaries;
102 unsigned char transfer_characteristics;
103 unsigned char matrix_coefficients;
104 } video_signal_description;
105 unsigned int seqhdr_data_length; // Additional bytes following (CUVIDEOFORMATEX)
108 // Video format including raw sequence header information
111 CUVIDEOFORMAT format;
112 unsigned char raw_seqhdr_data[1024];
119 cudaAudioCodec codec; // Compression format
120 unsigned int channels; // number of audio channels
121 unsigned int samplespersec; // sampling frequency
122 unsigned int bitrate; // For uncompressed, can also be used to determine bits per sample
123 unsigned int reserved1;
124 unsigned int reserved2;
129 ////////////////////////////////////////////////////////////////////////////////////////////////
136 CUVID_PKT_ENDOFSTREAM = 0x01, // Set when this is the last packet for this stream
137 CUVID_PKT_TIMESTAMP = 0x02, // Timestamp is valid
138 CUVID_PKT_DISCONTINUITY = 0x04 // Set when a discontinuity has to be signalled
139 } CUvideopacketflags;
141 typedef struct _CUVIDSOURCEDATAPACKET
143 unsigned long flags; // Combination of CUVID_PKT_XXX flags
144 unsigned long payload_size; // number of bytes in the payload (may be zero if EOS flag is set)
145 const unsigned char *payload; // Pointer to packet payload data (may be NULL if EOS flag is set)
146 CUvideotimestamp timestamp; // Presentation timestamp (10MHz clock), only valid if CUVID_PKT_TIMESTAMP flag is set
147 } CUVIDSOURCEDATAPACKET;
149 // Callback for packet delivery
150 typedef int (CUDAAPI *PFNVIDSOURCECALLBACK)(void *, CUVIDSOURCEDATAPACKET *);
152 typedef struct _CUVIDSOURCEPARAMS
154 unsigned int ulClockRate; // Timestamp units in Hz (0=default=10000000Hz)
155 unsigned int uReserved1[7]; // Reserved for future use - set to zero
156 void *pUserData; // Parameter passed in to the data handlers
157 PFNVIDSOURCECALLBACK pfnVideoDataHandler; // Called to deliver audio packets
158 PFNVIDSOURCECALLBACK pfnAudioDataHandler; // Called to deliver video packets
159 void *pvReserved2[8]; // Reserved for future use - set to NULL
163 CUVID_FMT_EXTFORMATINFO = 0x100 // Return extended format structure (CUVIDEOFORMATEX)
164 } CUvideosourceformat_flags;
166 #if !defined(__APPLE__)
168 CUresult CUDAAPI cuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams);
169 CUresult CUDAAPI cuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams);
170 CUresult CUDAAPI cuvidDestroyVideoSource(CUvideosource obj);
171 CUresult CUDAAPI cuvidSetVideoSourceState(CUvideosource obj, cudaVideoState state);
172 cudaVideoState CUDAAPI cuvidGetVideoSourceState(CUvideosource obj);
173 CUresult CUDAAPI cuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags);
174 CUresult CUDAAPI cuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags);
177 ////////////////////////////////////////////////////////////////////////////////////////////////
182 typedef struct _CUVIDPARSERDISPINFO
185 int progressive_frame;
187 int repeat_first_field; // Number of additional fields (1=ivtc, 2=frame doubling, 4=frame tripling, -1=unpaired field)
188 CUvideotimestamp timestamp;
189 } CUVIDPARSERDISPINFO;
193 // The parser will call these synchronously from within cuvidParseVideoData(), whenever a picture is ready to
194 // be decoded and/or displayed.
196 typedef int (CUDAAPI *PFNVIDSEQUENCECALLBACK)(void *, CUVIDEOFORMAT *);
197 typedef int (CUDAAPI *PFNVIDDECODECALLBACK)(void *, CUVIDPICPARAMS *);
198 typedef int (CUDAAPI *PFNVIDDISPLAYCALLBACK)(void *, CUVIDPARSERDISPINFO *);
200 typedef struct _CUVIDPARSERPARAMS
202 cudaVideoCodec CodecType; // cudaVideoCodec_XXX
203 unsigned int ulMaxNumDecodeSurfaces; // Max # of decode surfaces (parser will cycle through these)
204 unsigned int ulClockRate; // Timestamp units in Hz (0=default=10000000Hz)
205 unsigned int ulErrorThreshold; // % Error threshold (0-100) for calling pfnDecodePicture (100=always call pfnDecodePicture even if picture bitstream is fully corrupted)
206 unsigned int ulMaxDisplayDelay; // Max display queue delay (improves pipelining of decode with display) - 0=no delay (recommended values: 2..4)
207 unsigned int uReserved1[5]; // Reserved for future use - set to 0
208 void *pUserData; // User data for callbacks
209 PFNVIDSEQUENCECALLBACK pfnSequenceCallback; // Called before decoding frames and/or whenever there is a format change
210 PFNVIDDECODECALLBACK pfnDecodePicture; // Called when a picture is ready to be decoded (decode order)
211 PFNVIDDISPLAYCALLBACK pfnDisplayPicture; // Called whenever a picture is ready to be displayed (display order)
212 void *pvReserved2[7]; // Reserved for future use - set to NULL
213 CUVIDEOFORMATEX *pExtVideoInfo; // [Optional] sequence header data from system layer
217 CUresult CUDAAPI cuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams);
218 CUresult CUDAAPI cuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket);
219 CUresult CUDAAPI cuvidDestroyVideoParser(CUvideoparser obj);
222 ////////////////////////////////////////////////////////////////////////////////////////////////
224 #if defined(__cplusplus)
226 #endif /* __cplusplus */
228 #endif // __NVCUVID_H__