vda.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * VDA HW acceleration
  3. *
  4. * copyright (c) 2011 Sebastien Zwickert
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_VDA_H
  23. #define AVCODEC_VDA_H
  24. /**
  25. * @file
  26. * @ingroup lavc_codec_hwaccel_vda
  27. * Public libavcodec VDA header.
  28. */
  29. #include "libavcodec/avcodec.h"
  30. #include <stdint.h>
  31. // emmintrin.h is unable to compile with -std=c99 -Werror=missing-prototypes
  32. // http://openradar.appspot.com/8026390
  33. #undef __GNUC_STDC_INLINE__
  34. #define Picture QuickdrawPicture
  35. #include <VideoDecodeAcceleration/VDADecoder.h>
  36. #undef Picture
  37. #include "libavcodec/version.h"
  38. // extra flags not defined in VDADecoder.h
  39. enum {
  40. kVDADecodeInfo_Asynchronous = 1UL << 0,
  41. kVDADecodeInfo_FrameDropped = 1UL << 1
  42. };
  43. /**
  44. * @defgroup lavc_codec_hwaccel_vda VDA
  45. * @ingroup lavc_codec_hwaccel
  46. *
  47. * @{
  48. */
  49. /**
  50. * This structure is used to provide the necessary configurations and data
  51. * to the VDA FFmpeg HWAccel implementation.
  52. *
  53. * The application must make it available as AVCodecContext.hwaccel_context.
  54. */
  55. struct vda_context {
  56. /**
  57. * VDA decoder object.
  58. *
  59. * - encoding: unused
  60. * - decoding: Set/Unset by libavcodec.
  61. */
  62. VDADecoder decoder;
  63. /**
  64. * The Core Video pixel buffer that contains the current image data.
  65. *
  66. * encoding: unused
  67. * decoding: Set by libavcodec. Unset by user.
  68. */
  69. CVPixelBufferRef cv_buffer;
  70. /**
  71. * Use the hardware decoder in synchronous mode.
  72. *
  73. * encoding: unused
  74. * decoding: Set by user.
  75. */
  76. int use_sync_decoding;
  77. /**
  78. * The frame width.
  79. *
  80. * - encoding: unused
  81. * - decoding: Set/Unset by user.
  82. */
  83. int width;
  84. /**
  85. * The frame height.
  86. *
  87. * - encoding: unused
  88. * - decoding: Set/Unset by user.
  89. */
  90. int height;
  91. /**
  92. * The frame format.
  93. *
  94. * - encoding: unused
  95. * - decoding: Set/Unset by user.
  96. */
  97. int format;
  98. /**
  99. * The pixel format for output image buffers.
  100. *
  101. * - encoding: unused
  102. * - decoding: Set/Unset by user.
  103. */
  104. OSType cv_pix_fmt_type;
  105. /**
  106. * unused
  107. */
  108. uint8_t *priv_bitstream;
  109. /**
  110. * unused
  111. */
  112. int priv_bitstream_size;
  113. /**
  114. * unused
  115. */
  116. int priv_allocated_size;
  117. /**
  118. * Use av_buffer to manage buffer.
  119. * When the flag is set, the CVPixelBuffers returned by the decoder will
  120. * be released automatically, so you have to retain them if necessary.
  121. * Not setting this flag may cause memory leak.
  122. *
  123. * encoding: unused
  124. * decoding: Set by user.
  125. */
  126. int use_ref_buffer;
  127. };
  128. /** Create the video decoder. */
  129. int ff_vda_create_decoder(struct vda_context *vda_ctx,
  130. uint8_t *extradata,
  131. int extradata_size);
  132. /** Destroy the video decoder. */
  133. int ff_vda_destroy_decoder(struct vda_context *vda_ctx);
  134. /**
  135. * This struct holds all the information that needs to be passed
  136. * between the caller and libavcodec for initializing VDA decoding.
  137. * Its size is not a part of the public ABI, it must be allocated with
  138. * av_vda_alloc_context() and freed with av_free().
  139. */
  140. typedef struct AVVDAContext {
  141. /**
  142. * VDA decoder object. Created and freed by the caller.
  143. */
  144. VDADecoder decoder;
  145. /**
  146. * The output callback that must be passed to VDADecoderCreate.
  147. * Set by av_vda_alloc_context().
  148. */
  149. VDADecoderOutputCallback output_callback;
  150. /**
  151. * CVPixelBuffer Format Type that VDA will use for decoded frames; set by
  152. * the caller.
  153. */
  154. OSType cv_pix_fmt_type;
  155. } AVVDAContext;
  156. /**
  157. * Allocate and initialize a VDA context.
  158. *
  159. * This function should be called from the get_format() callback when the caller
  160. * selects the AV_PIX_FMT_VDA format. The caller must then create the decoder
  161. * object (using the output callback provided by libavcodec) that will be used
  162. * for VDA-accelerated decoding.
  163. *
  164. * When decoding with VDA is finished, the caller must destroy the decoder
  165. * object and free the VDA context using av_free().
  166. *
  167. * @return the newly allocated context or NULL on failure
  168. */
  169. AVVDAContext *av_vda_alloc_context(void);
  170. /**
  171. * This is a convenience function that creates and sets up the VDA context using
  172. * an internal implementation.
  173. *
  174. * @param avctx the corresponding codec context
  175. *
  176. * @return >= 0 on success, a negative AVERROR code on failure
  177. */
  178. int av_vda_default_init(AVCodecContext *avctx);
  179. /**
  180. * This is a convenience function that creates and sets up the VDA context using
  181. * an internal implementation.
  182. *
  183. * @param avctx the corresponding codec context
  184. * @param vdactx the VDA context to use
  185. *
  186. * @return >= 0 on success, a negative AVERROR code on failure
  187. */
  188. int av_vda_default_init2(AVCodecContext *avctx, AVVDAContext *vdactx);
  189. /**
  190. * This function must be called to free the VDA context initialized with
  191. * av_vda_default_init().
  192. *
  193. * @param avctx the corresponding codec context
  194. */
  195. void av_vda_default_free(AVCodecContext *avctx);
  196. /**
  197. * @}
  198. */
  199. #endif /* AVCODEC_VDA_H */