vdpau.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * The Video Decode and Presentation API for UNIX (VDPAU) is used for
  3. * hardware-accelerated decoding of MPEG-1/2, H.264 and VC-1.
  4. *
  5. * Copyright (C) 2008 NVIDIA
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #ifndef AVCODEC_VDPAU_H
  24. #define AVCODEC_VDPAU_H
  25. /**
  26. * @file
  27. * @ingroup lavc_codec_hwaccel_vdpau
  28. * Public libavcodec VDPAU header.
  29. */
  30. /**
  31. * @defgroup lavc_codec_hwaccel_vdpau VDPAU Decoder and Renderer
  32. * @ingroup lavc_codec_hwaccel
  33. *
  34. * VDPAU hardware acceleration has two modules
  35. * - VDPAU decoding
  36. * - VDPAU presentation
  37. *
  38. * The VDPAU decoding module parses all headers using FFmpeg
  39. * parsing mechanisms and uses VDPAU for the actual decoding.
  40. *
  41. * As per the current implementation, the actual decoding
  42. * and rendering (API calls) are done as part of the VDPAU
  43. * presentation (vo_vdpau.c) module.
  44. *
  45. * @{
  46. */
  47. #include <vdpau/vdpau.h>
  48. #include "libavutil/avconfig.h"
  49. #include "libavutil/attributes.h"
  50. #include "avcodec.h"
  51. #include "version.h"
  52. #if FF_API_BUFS_VDPAU
  53. union AVVDPAUPictureInfo {
  54. VdpPictureInfoH264 h264;
  55. VdpPictureInfoMPEG1Or2 mpeg;
  56. VdpPictureInfoVC1 vc1;
  57. VdpPictureInfoMPEG4Part2 mpeg4;
  58. };
  59. #endif
  60. struct AVCodecContext;
  61. struct AVFrame;
  62. typedef int (*AVVDPAU_Render2)(struct AVCodecContext *, struct AVFrame *,
  63. const VdpPictureInfo *, uint32_t,
  64. const VdpBitstreamBuffer *);
  65. /**
  66. * This structure is used to share data between the libavcodec library and
  67. * the client video application.
  68. * The user shall allocate the structure via the av_alloc_vdpau_hwaccel
  69. * function and make it available as
  70. * AVCodecContext.hwaccel_context. Members can be set by the user once
  71. * during initialization or through each AVCodecContext.get_buffer()
  72. * function call. In any case, they must be valid prior to calling
  73. * decoding functions.
  74. *
  75. * The size of this structure is not a part of the public ABI and must not
  76. * be used outside of libavcodec. Use av_vdpau_alloc_context() to allocate an
  77. * AVVDPAUContext.
  78. */
  79. typedef struct AVVDPAUContext {
  80. /**
  81. * VDPAU decoder handle
  82. *
  83. * Set by user.
  84. */
  85. VdpDecoder decoder;
  86. /**
  87. * VDPAU decoder render callback
  88. *
  89. * Set by the user.
  90. */
  91. VdpDecoderRender *render;
  92. #if FF_API_BUFS_VDPAU
  93. /**
  94. * VDPAU picture information
  95. *
  96. * Set by libavcodec.
  97. */
  98. attribute_deprecated
  99. union AVVDPAUPictureInfo info;
  100. /**
  101. * Allocated size of the bitstream_buffers table.
  102. *
  103. * Set by libavcodec.
  104. */
  105. attribute_deprecated
  106. int bitstream_buffers_allocated;
  107. /**
  108. * Useful bitstream buffers in the bitstream buffers table.
  109. *
  110. * Set by libavcodec.
  111. */
  112. attribute_deprecated
  113. int bitstream_buffers_used;
  114. /**
  115. * Table of bitstream buffers.
  116. * The user is responsible for freeing this buffer using av_freep().
  117. *
  118. * Set by libavcodec.
  119. */
  120. attribute_deprecated
  121. VdpBitstreamBuffer *bitstream_buffers;
  122. #endif
  123. AVVDPAU_Render2 render2;
  124. } AVVDPAUContext;
  125. /**
  126. * @brief allocation function for AVVDPAUContext
  127. *
  128. * Allows extending the struct without breaking API/ABI
  129. */
  130. AVVDPAUContext *av_alloc_vdpaucontext(void);
  131. AVVDPAU_Render2 av_vdpau_hwaccel_get_render2(const AVVDPAUContext *);
  132. void av_vdpau_hwaccel_set_render2(AVVDPAUContext *, AVVDPAU_Render2);
  133. /**
  134. * Associate a VDPAU device with a codec context for hardware acceleration.
  135. * This function is meant to be called from the get_format() codec callback,
  136. * or earlier. It can also be called after avcodec_flush_buffers() to change
  137. * the underlying VDPAU device mid-stream (e.g. to recover from non-transparent
  138. * display preemption).
  139. *
  140. * @note get_format() must return AV_PIX_FMT_VDPAU if this function completes
  141. * successfully.
  142. *
  143. * @param avctx decoding context whose get_format() callback is invoked
  144. * @param device VDPAU device handle to use for hardware acceleration
  145. * @param get_proc_address VDPAU device driver
  146. * @param flags zero of more OR'd AV_HWACCEL_FLAG_* flags
  147. *
  148. * @return 0 on success, an AVERROR code on failure.
  149. */
  150. int av_vdpau_bind_context(AVCodecContext *avctx, VdpDevice device,
  151. VdpGetProcAddress *get_proc_address, unsigned flags);
  152. /**
  153. * Gets the parameters to create an adequate VDPAU video surface for the codec
  154. * context using VDPAU hardware decoding acceleration.
  155. *
  156. * @note Behavior is undefined if the context was not successfully bound to a
  157. * VDPAU device using av_vdpau_bind_context().
  158. *
  159. * @param avctx the codec context being used for decoding the stream
  160. * @param type storage space for the VDPAU video surface chroma type
  161. * (or NULL to ignore)
  162. * @param width storage space for the VDPAU video surface pixel width
  163. * (or NULL to ignore)
  164. * @param height storage space for the VDPAU video surface pixel height
  165. * (or NULL to ignore)
  166. *
  167. * @return 0 on success, a negative AVERROR code on failure.
  168. */
  169. int av_vdpau_get_surface_parameters(AVCodecContext *avctx, VdpChromaType *type,
  170. uint32_t *width, uint32_t *height);
  171. /**
  172. * Allocate an AVVDPAUContext.
  173. *
  174. * @return Newly-allocated AVVDPAUContext or NULL on failure.
  175. */
  176. AVVDPAUContext *av_vdpau_alloc_context(void);
  177. #if FF_API_VDPAU_PROFILE
  178. /**
  179. * Get a decoder profile that should be used for initializing a VDPAU decoder.
  180. * Should be called from the AVCodecContext.get_format() callback.
  181. *
  182. * @deprecated Use av_vdpau_bind_context() instead.
  183. *
  184. * @param avctx the codec context being used for decoding the stream
  185. * @param profile a pointer into which the result will be written on success.
  186. * The contents of profile are undefined if this function returns
  187. * an error.
  188. *
  189. * @return 0 on success (non-negative), a negative AVERROR on failure.
  190. */
  191. attribute_deprecated
  192. int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile);
  193. #endif
  194. #if FF_API_CAP_VDPAU
  195. /** @brief The videoSurface is used for rendering. */
  196. #define FF_VDPAU_STATE_USED_FOR_RENDER 1
  197. /**
  198. * @brief The videoSurface is needed for reference/prediction.
  199. * The codec manipulates this.
  200. */
  201. #define FF_VDPAU_STATE_USED_FOR_REFERENCE 2
  202. /**
  203. * @brief This structure is used as a callback between the FFmpeg
  204. * decoder (vd_) and presentation (vo_) module.
  205. * This is used for defining a video frame containing surface,
  206. * picture parameter, bitstream information etc which are passed
  207. * between the FFmpeg decoder and its clients.
  208. */
  209. struct vdpau_render_state {
  210. VdpVideoSurface surface; ///< Used as rendered surface, never changed.
  211. int state; ///< Holds FF_VDPAU_STATE_* values.
  212. /** picture parameter information for all supported codecs */
  213. union AVVDPAUPictureInfo info;
  214. /** Describe size/location of the compressed video data.
  215. Set to 0 when freeing bitstream_buffers. */
  216. int bitstream_buffers_allocated;
  217. int bitstream_buffers_used;
  218. /** The user is responsible for freeing this buffer using av_freep(). */
  219. VdpBitstreamBuffer *bitstream_buffers;
  220. };
  221. #endif
  222. /* @}*/
  223. #endif /* AVCODEC_VDPAU_H */