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.

357 lines
20KB

  1. /*
  2. * This copyright notice applies to this header file only:
  3. *
  4. * Copyright (c) 2010-2017 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. //! NVDECODE API provides video decoding interface to NVIDIA GPU devices.
  30. //! \date 2015-2017
  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. ** Initialization
  41. *********************************/
  42. CUresult CUDAAPI cuvidInit(unsigned int Flags);
  43. /***********************************************/
  44. //!
  45. //! High-level helper APIs for video sources
  46. //!
  47. /***********************************************/
  48. typedef void *CUvideosource;
  49. typedef void *CUvideoparser;
  50. typedef long long CUvideotimestamp;
  51. /************************************************************************/
  52. //! \enum cudaVideoState
  53. //! Video source state enums
  54. //! Used in cuvidSetVideoSourceState and cuvidGetVideoSourceState APIs
  55. /************************************************************************/
  56. typedef enum {
  57. cudaVideoState_Error = -1, /**< Error state (invalid source) */
  58. cudaVideoState_Stopped = 0, /**< Source is stopped (or reached end-of-stream) */
  59. cudaVideoState_Started = 1 /**< Source is running and delivering data */
  60. } cudaVideoState;
  61. /************************************************************************/
  62. //! \enum cudaAudioCodec
  63. //! Audio compression enums
  64. //! Used in CUAUDIOFORMAT structure
  65. /************************************************************************/
  66. typedef enum {
  67. cudaAudioCodec_MPEG1=0, /**< MPEG-1 Audio */
  68. cudaAudioCodec_MPEG2, /**< MPEG-2 Audio */
  69. cudaAudioCodec_MP3, /**< MPEG-1 Layer III Audio */
  70. cudaAudioCodec_AC3, /**< Dolby Digital (AC3) Audio */
  71. cudaAudioCodec_LPCM, /**< PCM Audio */
  72. cudaAudioCodec_AAC, /**< AAC Audio */
  73. } cudaAudioCodec;
  74. /************************************************************************************************/
  75. //! \ingroup STRUCTS
  76. //! \struct CUVIDEOFORMAT
  77. //! Video format
  78. //! Used in cuvidGetSourceVideoFormat API
  79. /************************************************************************************************/
  80. typedef struct
  81. {
  82. cudaVideoCodec codec; /**< OUT: Compression format */
  83. /**
  84. * OUT: frame rate = numerator / denominator (for example: 30000/1001)
  85. */
  86. struct {
  87. /**< OUT: frame rate numerator (0 = unspecified or variable frame rate) */
  88. unsigned int numerator;
  89. /**< OUT: frame rate denominator (0 = unspecified or variable frame rate) */
  90. unsigned int denominator;
  91. } frame_rate;
  92. unsigned char progressive_sequence; /**< OUT: 0=interlaced, 1=progressive */
  93. unsigned char bit_depth_luma_minus8; /**< OUT: high bit depth luma. E.g, 2 for 10-bitdepth, 4 for 12-bitdepth */
  94. unsigned char bit_depth_chroma_minus8; /**< OUT: high bit depth chroma. E.g, 2 for 10-bitdepth, 4 for 12-bitdepth */
  95. unsigned char reserved1; /**< Reserved for future use */
  96. unsigned int coded_width; /**< OUT: coded frame width in pixels */
  97. unsigned int coded_height; /**< OUT: coded frame height in pixels */
  98. /**
  99. * area of the frame that should be displayed
  100. * typical example:
  101. * coded_width = 1920, coded_height = 1088
  102. * display_area = { 0,0,1920,1080 }
  103. */
  104. struct {
  105. int left; /**< OUT: left position of display rect */
  106. int top; /**< OUT: top position of display rect */
  107. int right; /**< OUT: right position of display rect */
  108. int bottom; /**< OUT: bottom position of display rect */
  109. } display_area;
  110. cudaVideoChromaFormat chroma_format; /**< OUT: Chroma format */
  111. unsigned int bitrate; /**< OUT: video bitrate (bps, 0=unknown) */
  112. /**
  113. * OUT: Display Aspect Ratio = x:y (4:3, 16:9, etc)
  114. */
  115. struct {
  116. int x;
  117. int y;
  118. } display_aspect_ratio;
  119. /**
  120. * Video Signal Description
  121. * Refer section E.2.1 (VUI parameters semantics) of H264 spec file
  122. */
  123. struct {
  124. unsigned char video_format : 3; /**< OUT: 0-Component, 1-PAL, 2-NTSC, 3-SECAM, 4-MAC, 5-Unspecified */
  125. unsigned char video_full_range_flag : 1; /**< OUT: indicates the black level and luma and chroma range */
  126. unsigned char reserved_zero_bits : 4; /**< Reserved bits */
  127. unsigned char color_primaries; /**< OUT: chromaticity coordinates of source primaries */
  128. unsigned char transfer_characteristics; /**< OUT: opto-electronic transfer characteristic of the source picture */
  129. unsigned char matrix_coefficients; /**< OUT: used in deriving luma and chroma signals from RGB primaries */
  130. } video_signal_description;
  131. unsigned int seqhdr_data_length; /**< OUT: Additional bytes following (CUVIDEOFORMATEX) */
  132. } CUVIDEOFORMAT;
  133. /****************************************************************/
  134. //! \ingroup STRUCTS
  135. //! \struct CUVIDEOFORMATEX
  136. //! Video format including raw sequence header information
  137. //! Used in cuvidGetSourceVideoFormat API
  138. /****************************************************************/
  139. typedef struct
  140. {
  141. CUVIDEOFORMAT format; /**< OUT: CUVIDEOFORMAT structure */
  142. unsigned char raw_seqhdr_data[1024]; /**< OUT: Sequence header data */
  143. } CUVIDEOFORMATEX;
  144. /****************************************************************/
  145. //! \ingroup STRUCTS
  146. //! \struct CUAUDIOFORMAT
  147. //! Audio formats
  148. //! Used in cuvidGetSourceAudioFormat API
  149. /****************************************************************/
  150. typedef struct
  151. {
  152. cudaAudioCodec codec; /**< OUT: Compression format */
  153. unsigned int channels; /**< OUT: number of audio channels */
  154. unsigned int samplespersec; /**< OUT: sampling frequency */
  155. unsigned int bitrate; /**< OUT: For uncompressed, can also be used to determine bits per sample */
  156. unsigned int reserved1; /**< Reserved for future use */
  157. unsigned int reserved2; /**< Reserved for future use */
  158. } CUAUDIOFORMAT;
  159. /***************************************************************/
  160. //! \enum CUvideopacketflags
  161. //! Data packet flags
  162. //! Used in CUVIDSOURCEDATAPACKET structure
  163. /***************************************************************/
  164. typedef enum {
  165. CUVID_PKT_ENDOFSTREAM = 0x01, /**< Set when this is the last packet for this stream */
  166. CUVID_PKT_TIMESTAMP = 0x02, /**< Timestamp is valid */
  167. CUVID_PKT_DISCONTINUITY = 0x04, /**< Set when a discontinuity has to be signalled */
  168. CUVID_PKT_ENDOFPICTURE = 0x08, /**< Set when the packet contains exactly one frame */
  169. } CUvideopacketflags;
  170. /*****************************************************************************/
  171. //! \ingroup STRUCTS
  172. //! \struct CUVIDSOURCEDATAPACKET
  173. //! Data Packet
  174. //! Used in cuvidParseVideoData API
  175. //! IN for cuvidParseVideoData
  176. /*****************************************************************************/
  177. typedef struct _CUVIDSOURCEDATAPACKET
  178. {
  179. tcu_ulong flags; /**< IN: Combination of CUVID_PKT_XXX flags */
  180. tcu_ulong payload_size; /**< IN: number of bytes in the payload (may be zero if EOS flag is set) */
  181. const unsigned char *payload; /**< IN: Pointer to packet payload data (may be NULL if EOS flag is set) */
  182. CUvideotimestamp timestamp; /**< IN: Presentation time stamp (10MHz clock), only valid if
  183. CUVID_PKT_TIMESTAMP flag is set */
  184. } CUVIDSOURCEDATAPACKET;
  185. // Callback for packet delivery
  186. typedef int (CUDAAPI *PFNVIDSOURCECALLBACK)(void *, CUVIDSOURCEDATAPACKET *);
  187. /**************************************************************************************************************************/
  188. //! \ingroup STRUCTS
  189. //! \struct CUVIDSOURCEPARAMS
  190. //! Describes parameters needed in cuvidCreateVideoSource API
  191. //! NVDECODE API is intended for HW accelerated video decoding so CUvideosource doesn't have audio demuxer for all supported
  192. //! containers. It's recommended to clients to use their own or third party demuxer if audio support is needed.
  193. /**************************************************************************************************************************/
  194. typedef struct _CUVIDSOURCEPARAMS
  195. {
  196. unsigned int ulClockRate; /**< IN: Time stamp units in Hz (0=default=10000000Hz) */
  197. unsigned int uReserved1[7]; /**< Reserved for future use - set to zero */
  198. void *pUserData; /**< IN: User private data passed in to the data handlers */
  199. PFNVIDSOURCECALLBACK pfnVideoDataHandler; /**< IN: Called to deliver video packets */
  200. PFNVIDSOURCECALLBACK pfnAudioDataHandler; /**< IN: Called to deliver audio packets. */
  201. void *pvReserved2[8]; /**< Reserved for future use - set to NULL */
  202. } CUVIDSOURCEPARAMS;
  203. /**********************************************/
  204. //! \ingroup ENUMS
  205. //! \enum CUvideosourceformat_flags
  206. //! CUvideosourceformat_flags
  207. //! Used in cuvidGetSourceVideoFormat API
  208. /**********************************************/
  209. typedef enum {
  210. CUVID_FMT_EXTFORMATINFO = 0x100 /**< Return extended format structure (CUVIDEOFORMATEX) */
  211. } CUvideosourceformat_flags;
  212. #if !defined(__APPLE__)
  213. /**************************************************************************************************************************/
  214. //! \fn CUresult CUDAAPI cuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams)
  215. //! Create CUvideosource object. CUvideosource spawns demultiplexer thread that provides two callbacks:
  216. //! pfnVideoDataHandler() and pfnAudioDataHandler()
  217. //! NVDECODE API is intended for HW accelerated video decoding so CUvideosource doesn't have audio demuxer for all supported
  218. //! containers. It's recommended to clients to use their own or third party demuxer if audio support is needed.
  219. /**************************************************************************************************************************/
  220. typedef CUresult CUDAAPI tcuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams);
  221. /****************************************************************************************************************************/
  222. //! \fn CUresult CUDAAPI cuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams)
  223. //! Create video source object and initialize
  224. /****************************************************************************************************************************/
  225. typedef CUresult CUDAAPI tcuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams);
  226. /*********************************************************************/
  227. //! \fn CUresult CUDAAPI cuvidDestroyVideoSource(CUvideosource obj)
  228. //! Destroy video source
  229. /*********************************************************************/
  230. typedef CUresult CUDAAPI tcuvidDestroyVideoSource(CUvideosource obj);
  231. /******************************************************************************************/
  232. //! \fn CUresult CUDAAPI cuvidSetVideoSourceState(CUvideosource obj, cudaVideoState state)
  233. //! Set video source state
  234. /******************************************************************************************/
  235. typedef CUresult CUDAAPI tcuvidSetVideoSourceState(CUvideosource obj, cudaVideoState state);
  236. /******************************************************************************************/
  237. //! \fn cudaVideoState CUDAAPI cuvidGetVideoSourceState(CUvideosource obj)
  238. //! Get video source state
  239. /******************************************************************************************/
  240. typedef cudaVideoState CUDAAPI tcuvidGetVideoSourceState(CUvideosource obj);
  241. /****************************************************************************************************************/
  242. //! \fn CUresult CUDAAPI cuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags)
  243. //! Gets details of video stream in pvidfmt
  244. /****************************************************************************************************************/
  245. typedef CUresult CUDAAPI tcuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags);
  246. /****************************************************************************************************************/
  247. //! \fn CUresult CUDAAPI cuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags)
  248. //! Get audio source format
  249. //! NVDECODE API is intended for HW accelarated video decoding so CUvideosource doesn't have audio demuxer for all suppported
  250. //! containers. It's recommended to clients to use their own or third party demuxer if audio support is needed.
  251. /****************************************************************************************************************/
  252. typedef CUresult CUDAAPI tcuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags);
  253. #endif
  254. /**********************************************************************************/
  255. //! \ingroup STRUCTS
  256. //! \struct CUVIDPARSERDISPINFO
  257. //! Used in cuvidParseVideoData API with PFNVIDDISPLAYCALLBACK pfnDisplayPicture
  258. /**********************************************************************************/
  259. typedef struct _CUVIDPARSERDISPINFO
  260. {
  261. int picture_index; /**< OUT: Index of the current picture */
  262. int progressive_frame; /**< OUT: 1 if progressive frame; 0 otherwise */
  263. int top_field_first; /**< OUT: 1 if top field is displayed first; 0 otherwise */
  264. int repeat_first_field; /**< OUT: Number of additional fields (1=ivtc, 2=frame doubling, 4=frame tripling,
  265. -1=unpaired field) */
  266. CUvideotimestamp timestamp; /**< OUT: Presentation time stamp */
  267. } CUVIDPARSERDISPINFO;
  268. /***********************************************************************************************************************/
  269. //! Parser callbacks
  270. //! The parser will call these synchronously from within cuvidParseVideoData(), whenever a picture is ready to
  271. //! be decoded and/or displayed. First argument in functions is "void *pUserData" member of structure CUVIDSOURCEPARAMS
  272. /***********************************************************************************************************************/
  273. typedef int (CUDAAPI *PFNVIDSEQUENCECALLBACK)(void *, CUVIDEOFORMAT *);
  274. typedef int (CUDAAPI *PFNVIDDECODECALLBACK)(void *, CUVIDPICPARAMS *);
  275. typedef int (CUDAAPI *PFNVIDDISPLAYCALLBACK)(void *, CUVIDPARSERDISPINFO *);
  276. /**************************************/
  277. //! \ingroup STRUCTS
  278. //! \struct CUVIDPARSERPARAMS
  279. //! Used in cuvidCreateVideoParser API
  280. /**************************************/
  281. typedef struct _CUVIDPARSERPARAMS
  282. {
  283. cudaVideoCodec CodecType; /**< IN: cudaVideoCodec_XXX */
  284. unsigned int ulMaxNumDecodeSurfaces; /**< IN: Max # of decode surfaces (parser will cycle through these) */
  285. unsigned int ulClockRate; /**< IN: Timestamp units in Hz (0=default=10000000Hz) */
  286. unsigned int ulErrorThreshold; /**< IN: % Error threshold (0-100) for calling pfnDecodePicture (100=always
  287. IN: call pfnDecodePicture even if picture bitstream is fully corrupted) */
  288. unsigned int ulMaxDisplayDelay; /**< IN: Max display queue delay (improves pipelining of decode with display)
  289. 0=no delay (recommended values: 2..4) */
  290. unsigned int uReserved1[5]; /**< IN: Reserved for future use - set to 0 */
  291. void *pUserData; /**< IN: User data for callbacks */
  292. PFNVIDSEQUENCECALLBACK pfnSequenceCallback; /**< IN: Called before decoding frames and/or whenever there is a fmt change */
  293. PFNVIDDECODECALLBACK pfnDecodePicture; /**< IN: Called when a picture is ready to be decoded (decode order) */
  294. PFNVIDDISPLAYCALLBACK pfnDisplayPicture; /**< IN: Called whenever a picture is ready to be displayed (display order) */
  295. void *pvReserved2[7]; /**< Reserved for future use - set to NULL */
  296. CUVIDEOFORMATEX *pExtVideoInfo; /**< IN: [Optional] sequence header data from system layer */
  297. } CUVIDPARSERPARAMS;
  298. /************************************************************************************************/
  299. //! \fn CUresult CUDAAPI cuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams)
  300. //! Create video parser object and initialize
  301. /************************************************************************************************/
  302. typedef CUresult CUDAAPI tcuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams);
  303. /************************************************************************************************/
  304. //! \fn CUresult CUDAAPI cuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket)
  305. //! Parse the video data from source data packet in pPacket
  306. //! Extracts parameter sets like SPS, PPS, bitstream etc. from pPacket and
  307. //! calls back pfnDecodePicture with CUVIDPICPARAMS data for kicking of HW decoding
  308. /************************************************************************************************/
  309. typedef CUresult CUDAAPI tcuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket);
  310. /*******************************************************************/
  311. //! \fn CUresult CUDAAPI cuvidDestroyVideoParser(CUvideoparser obj)
  312. /*******************************************************************/
  313. typedef CUresult CUDAAPI tcuvidDestroyVideoParser(CUvideoparser obj);
  314. /**********************************************************************************************/
  315. #if defined(__cplusplus)
  316. }
  317. #endif /* __cplusplus */
  318. #endif // __NVCUVID_H__