vdpau.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 <vdpau/vdpau_x11.h>
  49. #include "libavutil/avconfig.h"
  50. #include "libavutil/attributes.h"
  51. #include "avcodec.h"
  52. #include "version.h"
  53. #if FF_API_BUFS_VDPAU
  54. union AVVDPAUPictureInfo {
  55. VdpPictureInfoH264 h264;
  56. VdpPictureInfoMPEG1Or2 mpeg;
  57. VdpPictureInfoVC1 vc1;
  58. VdpPictureInfoMPEG4Part2 mpeg4;
  59. };
  60. #endif
  61. struct AVCodecContext;
  62. struct AVFrame;
  63. typedef int (*AVVDPAU_Render2)(struct AVCodecContext *, struct AVFrame *,
  64. const VdpPictureInfo *, uint32_t,
  65. const VdpBitstreamBuffer *);
  66. /**
  67. * This structure is used to share data between the libavcodec library and
  68. * the client video application.
  69. * The user shall allocate the structure via the av_alloc_vdpau_hwaccel
  70. * function and make it available as
  71. * AVCodecContext.hwaccel_context. Members can be set by the user once
  72. * during initialization or through each AVCodecContext.get_buffer()
  73. * function call. In any case, they must be valid prior to calling
  74. * decoding functions.
  75. *
  76. * The size of this structure is not a part of the public ABI and must not
  77. * be used outside of libavcodec. Use av_vdpau_alloc_context() to allocate an
  78. * AVVDPAUContext.
  79. */
  80. typedef struct AVVDPAUContext {
  81. /**
  82. * VDPAU decoder handle
  83. *
  84. * Set by user.
  85. */
  86. VdpDecoder decoder;
  87. /**
  88. * VDPAU decoder render callback
  89. *
  90. * Set by the user.
  91. */
  92. VdpDecoderRender *render;
  93. #if FF_API_BUFS_VDPAU
  94. /**
  95. * VDPAU picture information
  96. *
  97. * Set by libavcodec.
  98. */
  99. attribute_deprecated
  100. union AVVDPAUPictureInfo info;
  101. /**
  102. * Allocated size of the bitstream_buffers table.
  103. *
  104. * Set by libavcodec.
  105. */
  106. attribute_deprecated
  107. int bitstream_buffers_allocated;
  108. /**
  109. * Useful bitstream buffers in the bitstream buffers table.
  110. *
  111. * Set by libavcodec.
  112. */
  113. attribute_deprecated
  114. int bitstream_buffers_used;
  115. /**
  116. * Table of bitstream buffers.
  117. * The user is responsible for freeing this buffer using av_freep().
  118. *
  119. * Set by libavcodec.
  120. */
  121. attribute_deprecated
  122. VdpBitstreamBuffer *bitstream_buffers;
  123. #endif
  124. AVVDPAU_Render2 render2;
  125. } AVVDPAUContext;
  126. /**
  127. * @brief allocation function for AVVDPAUContext
  128. *
  129. * Allows extending the struct without breaking API/ABI
  130. */
  131. AVVDPAUContext *av_alloc_vdpaucontext(void);
  132. AVVDPAU_Render2 av_vdpau_hwaccel_get_render2(const AVVDPAUContext *);
  133. void av_vdpau_hwaccel_set_render2(AVVDPAUContext *, AVVDPAU_Render2);
  134. /**
  135. * Associate a VDPAU device with a codec context for hardware acceleration.
  136. * This function is meant to be called from the get_format() codec callback,
  137. * or earlier. It can also be called after avcodec_flush_buffers() to change
  138. * the underlying VDPAU device mid-stream (e.g. to recover from non-transparent
  139. * display preemption).
  140. *
  141. * @note get_format() must return AV_PIX_FMT_VDPAU if this function completes
  142. * successfully.
  143. *
  144. * @param avctx decoding context whose get_format() callback is invoked
  145. * @param device VDPAU device handle to use for hardware acceleration
  146. * @param get_proc_address VDPAU device driver
  147. * @param flags zero of more OR'd AV_HWACCEL_FLAG_* flags
  148. *
  149. * @return 0 on success, an AVERROR code on failure.
  150. */
  151. int av_vdpau_bind_context(AVCodecContext *avctx, VdpDevice device,
  152. VdpGetProcAddress *get_proc_address, unsigned flags);
  153. /**
  154. * Allocate an AVVDPAUContext.
  155. *
  156. * @return Newly-allocated AVVDPAUContext or NULL on failure.
  157. */
  158. AVVDPAUContext *av_vdpau_alloc_context(void);
  159. /**
  160. * Get a decoder profile that should be used for initializing a VDPAU decoder.
  161. * Should be called from the AVCodecContext.get_format() callback.
  162. *
  163. * @param avctx the codec context being used for decoding the stream
  164. * @param profile a pointer into which the result will be written on success.
  165. * The contents of profile are undefined if this function returns
  166. * an error.
  167. *
  168. * @return 0 on success (non-negative), a negative AVERROR on failure.
  169. */
  170. int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile);
  171. #if FF_API_CAP_VDPAU
  172. /** @brief The videoSurface is used for rendering. */
  173. #define FF_VDPAU_STATE_USED_FOR_RENDER 1
  174. /**
  175. * @brief The videoSurface is needed for reference/prediction.
  176. * The codec manipulates this.
  177. */
  178. #define FF_VDPAU_STATE_USED_FOR_REFERENCE 2
  179. /**
  180. * @brief This structure is used as a callback between the FFmpeg
  181. * decoder (vd_) and presentation (vo_) module.
  182. * This is used for defining a video frame containing surface,
  183. * picture parameter, bitstream information etc which are passed
  184. * between the FFmpeg decoder and its clients.
  185. */
  186. struct vdpau_render_state {
  187. VdpVideoSurface surface; ///< Used as rendered surface, never changed.
  188. int state; ///< Holds FF_VDPAU_STATE_* values.
  189. #if AV_HAVE_INCOMPATIBLE_LIBAV_ABI
  190. /** picture parameter information for all supported codecs */
  191. union AVVDPAUPictureInfo info;
  192. #endif
  193. /** Describe size/location of the compressed video data.
  194. Set to 0 when freeing bitstream_buffers. */
  195. int bitstream_buffers_allocated;
  196. int bitstream_buffers_used;
  197. /** The user is responsible for freeing this buffer using av_freep(). */
  198. VdpBitstreamBuffer *bitstream_buffers;
  199. #if !AV_HAVE_INCOMPATIBLE_LIBAV_ABI
  200. /** picture parameter information for all supported codecs */
  201. union AVVDPAUPictureInfo info;
  202. #endif
  203. };
  204. #endif
  205. /* @}*/
  206. #endif /* AVCODEC_VDPAU_H */