OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / nvcuvid.h
1 /*
2  * Copyright 1993-2008 NVIDIA Corporation.  All rights reserved.
3  *
4  * NOTICE TO USER:   
5  *
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.
10  *
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.  
21  *
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. 
30  *
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.
34  */
35
36 #if !defined(__NVCUVID_H__)
37 #define __NVCUVID_H__
38
39 #include "cuviddec.h"
40
41 #if defined(__cplusplus)
42 extern "C" {
43 #endif /* __cplusplus */
44
45 ////////////////////////////////////////////////////////////////////////////////////////////////
46 //
47 // High-level helper APIs for video sources
48 //
49
50 typedef void *CUvideosource;
51 typedef void *CUvideoparser;
52 typedef long long CUvideotimestamp;
53
54 ////////////////////////////////////////////////////////////////////////////////////////////////
55 //
56 // video data structures
57 //
58
59 // Video Source State
60 typedef enum {
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
64 } cudaVideoState;
65
66 // Audio compression
67 typedef enum {
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
73 } cudaAudioCodec;
74
75
76 // Video format
77 typedef struct
78 {
79     cudaVideoCodec codec;           // Compression format
80     struct {
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 }
91         int bottom;
92     } display_area;
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)
96         int x;
97         int y;
98     } display_aspect_ratio;
99     struct {
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)
106 } CUVIDEOFORMAT;
107
108 // Video format including raw sequence header information
109 typedef struct
110 {
111     CUVIDEOFORMAT format;
112     unsigned char raw_seqhdr_data[1024];
113 } CUVIDEOFORMATEX;
114
115
116 // Audio Format
117 typedef struct
118 {
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;
125 } CUAUDIOFORMAT;
126
127
128
129 ////////////////////////////////////////////////////////////////////////////////////////////////
130 //
131 // video source
132 //
133
134 // Data packet
135 typedef enum {
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;
140
141 typedef struct _CUVIDSOURCEDATAPACKET
142 {
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;
148
149 // Callback for packet delivery
150 typedef int (CUDAAPI *PFNVIDSOURCECALLBACK)(void *, CUVIDSOURCEDATAPACKET *);
151
152 typedef struct _CUVIDSOURCEPARAMS
153 {
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
160 } CUVIDSOURCEPARAMS;
161
162 typedef enum {
163     CUVID_FMT_EXTFORMATINFO = 0x100     // Return extended format structure (CUVIDEOFORMATEX)
164 } CUvideosourceformat_flags;
165
166 #if !defined(__APPLE__)
167 // Video file source
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);
175 #endif
176
177 ////////////////////////////////////////////////////////////////////////////////////////////////
178 //
179 // Video parser
180 //
181
182 typedef struct _CUVIDPARSERDISPINFO
183 {
184     int picture_index;
185     int progressive_frame;
186     int top_field_first;
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;
190
191 //
192 // Parser callbacks
193 // The parser will call these synchronously from within cuvidParseVideoData(), whenever a picture is ready to
194 // be decoded and/or displayed.
195 //
196 typedef int (CUDAAPI *PFNVIDSEQUENCECALLBACK)(void *, CUVIDEOFORMAT *);
197 typedef int (CUDAAPI *PFNVIDDECODECALLBACK)(void *, CUVIDPICPARAMS *);
198 typedef int (CUDAAPI *PFNVIDDISPLAYCALLBACK)(void *, CUVIDPARSERDISPINFO *);
199
200 typedef struct _CUVIDPARSERPARAMS
201 {
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
214 } CUVIDPARSERPARAMS;
215
216
217 CUresult CUDAAPI cuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams);
218 CUresult CUDAAPI cuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket);
219 CUresult CUDAAPI cuvidDestroyVideoParser(CUvideoparser obj);
220
221
222 ////////////////////////////////////////////////////////////////////////////////////////////////
223
224 #if defined(__cplusplus)
225 }
226 #endif /* __cplusplus */
227
228 #endif // __NVCUVID_H__
229