You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
12KB

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