nvcuvid.h 12 KB

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