vpx_decoder.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. /*!\defgroup decoder Decoder Algorithm Interface
  11. * \ingroup codec
  12. * This abstraction allows applications using this decoder to easily support
  13. * multiple video formats with minimal code duplication. This section describes
  14. * the interface common to all decoders.
  15. * @{
  16. */
  17. /*!\file
  18. * \brief Describes the decoder algorithm interface to applications.
  19. *
  20. * This file describes the interface between an application and a
  21. * video decoder algorithm.
  22. *
  23. */
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifndef VPX_DECODER_H
  28. #define VPX_DECODER_H
  29. #include "vpx_codec.h"
  30. /*!\brief Current ABI version number
  31. *
  32. * \internal
  33. * If this file is altered in any way that changes the ABI, this value
  34. * must be bumped. Examples include, but are not limited to, changing
  35. * types, removing or reassigning enums, adding/removing/rearranging
  36. * fields to structures
  37. */
  38. #define VPX_DECODER_ABI_VERSION (2 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/
  39. /*! \brief Decoder capabilities bitfield
  40. *
  41. * Each decoder advertises the capabilities it supports as part of its
  42. * ::vpx_codec_iface_t interface structure. Capabilities are extra interfaces
  43. * or functionality, and are not required to be supported by a decoder.
  44. *
  45. * The available flags are specified by VPX_CODEC_CAP_* defines.
  46. */
  47. #define VPX_CODEC_CAP_PUT_SLICE 0x10000 /**< Will issue put_slice callbacks */
  48. #define VPX_CODEC_CAP_PUT_FRAME 0x20000 /**< Will issue put_frame callbacks */
  49. #define VPX_CODEC_CAP_POSTPROC 0x40000 /**< Can postprocess decoded frame */
  50. #define VPX_CODEC_CAP_ERROR_CONCEALMENT 0x80000 /**< Can conceal errors due to
  51. packet loss */
  52. #define VPX_CODEC_CAP_INPUT_FRAGMENTS 0x100000 /**< Can receive encoded frames
  53. one fragment at a time */
  54. /*! \brief Initialization-time Feature Enabling
  55. *
  56. * Certain codec features must be known at initialization time, to allow for
  57. * proper memory allocation.
  58. *
  59. * The available flags are specified by VPX_CODEC_USE_* defines.
  60. */
  61. #define VPX_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */
  62. #define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 /**< Conceal errors in decoded
  63. frames */
  64. #define VPX_CODEC_USE_INPUT_FRAGMENTS 0x40000 /**< The input frame should be
  65. passed to the decoder one
  66. fragment at a time */
  67. /*!\brief Stream properties
  68. *
  69. * This structure is used to query or set properties of the decoded
  70. * stream. Algorithms may extend this structure with data specific
  71. * to their bitstream by setting the sz member appropriately.
  72. */
  73. typedef struct vpx_codec_stream_info {
  74. unsigned int sz; /**< Size of this structure */
  75. unsigned int w; /**< Width (or 0 for unknown/default) */
  76. unsigned int h; /**< Height (or 0 for unknown/default) */
  77. unsigned int is_kf; /**< Current frame is a keyframe */
  78. } vpx_codec_stream_info_t;
  79. /* REQUIRED FUNCTIONS
  80. *
  81. * The following functions are required to be implemented for all decoders.
  82. * They represent the base case functionality expected of all decoders.
  83. */
  84. /*!\brief Initialization Configurations
  85. *
  86. * This structure is used to pass init time configuration options to the
  87. * decoder.
  88. */
  89. typedef struct vpx_codec_dec_cfg {
  90. unsigned int threads; /**< Maximum number of threads to use, default 1 */
  91. unsigned int w; /**< Width */
  92. unsigned int h; /**< Height */
  93. } vpx_codec_dec_cfg_t; /**< alias for struct vpx_codec_dec_cfg */
  94. /*!\brief Initialize a decoder instance
  95. *
  96. * Initializes a decoder context using the given interface. Applications
  97. * should call the vpx_codec_dec_init convenience macro instead of this
  98. * function directly, to ensure that the ABI version number parameter
  99. * is properly initialized.
  100. *
  101. * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
  102. * parameter), the storage pointed to by the cfg parameter must be
  103. * kept readable and stable until all memory maps have been set.
  104. *
  105. * \param[in] ctx Pointer to this instance's context.
  106. * \param[in] iface Pointer to the algorithm interface to use.
  107. * \param[in] cfg Configuration to use, if known. May be NULL.
  108. * \param[in] flags Bitfield of VPX_CODEC_USE_* flags
  109. * \param[in] ver ABI version number. Must be set to
  110. * VPX_DECODER_ABI_VERSION
  111. * \retval #VPX_CODEC_OK
  112. * The decoder algorithm initialized.
  113. * \retval #VPX_CODEC_MEM_ERROR
  114. * Memory allocation failed.
  115. */
  116. vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
  117. vpx_codec_iface_t *iface,
  118. vpx_codec_dec_cfg_t *cfg,
  119. vpx_codec_flags_t flags,
  120. int ver);
  121. /*!\brief Convenience macro for vpx_codec_dec_init_ver()
  122. *
  123. * Ensures the ABI version parameter is properly set.
  124. */
  125. #define vpx_codec_dec_init(ctx, iface, cfg, flags) \
  126. vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION)
  127. /*!\brief Parse stream info from a buffer
  128. *
  129. * Performs high level parsing of the bitstream. Construction of a decoder
  130. * context is not necessary. Can be used to determine if the bitstream is
  131. * of the proper format, and to extract information from the stream.
  132. *
  133. * \param[in] iface Pointer to the algorithm interface
  134. * \param[in] data Pointer to a block of data to parse
  135. * \param[in] data_sz Size of the data buffer
  136. * \param[in,out] si Pointer to stream info to update. The size member
  137. * \ref MUST be properly initialized, but \ref MAY be
  138. * clobbered by the algorithm. This parameter \ref MAY
  139. * be NULL.
  140. *
  141. * \retval #VPX_CODEC_OK
  142. * Bitstream is parsable and stream information updated
  143. */
  144. vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
  145. const uint8_t *data,
  146. unsigned int data_sz,
  147. vpx_codec_stream_info_t *si);
  148. /*!\brief Return information about the current stream.
  149. *
  150. * Returns information about the stream that has been parsed during decoding.
  151. *
  152. * \param[in] ctx Pointer to this instance's context
  153. * \param[in,out] si Pointer to stream info to update. The size member
  154. * \ref MUST be properly initialized, but \ref MAY be
  155. * clobbered by the algorithm. This parameter \ref MAY
  156. * be NULL.
  157. *
  158. * \retval #VPX_CODEC_OK
  159. * Bitstream is parsable and stream information updated
  160. */
  161. vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
  162. vpx_codec_stream_info_t *si);
  163. /*!\brief Decode data
  164. *
  165. * Processes a buffer of coded data. If the processing results in a new
  166. * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be
  167. * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode
  168. * time stamp) order. Frames produced will always be in PTS (presentation
  169. * time stamp) order.
  170. * If the decoder is configured with VPX_CODEC_USE_INPUT_FRAGMENTS enabled,
  171. * data and data_sz can contain a fragment of the encoded frame. Fragment
  172. * \#n must contain at least partition \#n, but can also contain subsequent
  173. * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must
  174. * be empty. When no more data is available, this function should be called
  175. * with NULL as data and 0 as data_sz. The memory passed to this function
  176. * must be available until the frame has been decoded.
  177. *
  178. * \param[in] ctx Pointer to this instance's context
  179. * \param[in] data Pointer to this block of new coded data. If
  180. * NULL, a VPX_CODEC_CB_PUT_FRAME event is posted
  181. * for the previously decoded frame.
  182. * \param[in] data_sz Size of the coded data, in bytes.
  183. * \param[in] user_priv Application specific data to associate with
  184. * this frame.
  185. * \param[in] deadline Soft deadline the decoder should attempt to meet,
  186. * in us. Set to zero for unlimited.
  187. *
  188. * \return Returns #VPX_CODEC_OK if the coded data was processed completely
  189. * and future pictures can be decoded without error. Otherwise,
  190. * see the descriptions of the other error codes in ::vpx_codec_err_t
  191. * for recoverability capabilities.
  192. */
  193. vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx,
  194. const uint8_t *data,
  195. unsigned int data_sz,
  196. void *user_priv,
  197. long deadline);
  198. /*!\brief Decoded frames iterator
  199. *
  200. * Iterates over a list of the frames available for display. The iterator
  201. * storage should be initialized to NULL to start the iteration. Iteration is
  202. * complete when this function returns NULL.
  203. *
  204. * The list of available frames becomes valid upon completion of the
  205. * vpx_codec_decode call, and remains valid until the next call to vpx_codec_decode.
  206. *
  207. * \param[in] ctx Pointer to this instance's context
  208. * \param[in,out] iter Iterator storage, initialized to NULL
  209. *
  210. * \return Returns a pointer to an image, if one is ready for display. Frames
  211. * produced will always be in PTS (presentation time stamp) order.
  212. */
  213. vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx,
  214. vpx_codec_iter_t *iter);
  215. /*!\defgroup cap_put_frame Frame-Based Decoding Functions
  216. *
  217. * The following functions are required to be implemented for all decoders
  218. * that advertise the VPX_CODEC_CAP_PUT_FRAME capability. Calling these functions
  219. * for codecs that don't advertise this capability will result in an error
  220. * code being returned, usually VPX_CODEC_ERROR
  221. * @{
  222. */
  223. /*!\brief put frame callback prototype
  224. *
  225. * This callback is invoked by the decoder to notify the application of
  226. * the availability of decoded image data.
  227. */
  228. typedef void (*vpx_codec_put_frame_cb_fn_t)(void *user_priv,
  229. const vpx_image_t *img);
  230. /*!\brief Register for notification of frame completion.
  231. *
  232. * Registers a given function to be called when a decoded frame is
  233. * available.
  234. *
  235. * \param[in] ctx Pointer to this instance's context
  236. * \param[in] cb Pointer to the callback function
  237. * \param[in] user_priv User's private data
  238. *
  239. * \retval #VPX_CODEC_OK
  240. * Callback successfully registered.
  241. * \retval #VPX_CODEC_ERROR
  242. * Decoder context not initialized, or algorithm not capable of
  243. * posting slice completion.
  244. */
  245. vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx,
  246. vpx_codec_put_frame_cb_fn_t cb,
  247. void *user_priv);
  248. /*!@} - end defgroup cap_put_frame */
  249. /*!\defgroup cap_put_slice Slice-Based Decoding Functions
  250. *
  251. * The following functions are required to be implemented for all decoders
  252. * that advertise the VPX_CODEC_CAP_PUT_SLICE capability. Calling these functions
  253. * for codecs that don't advertise this capability will result in an error
  254. * code being returned, usually VPX_CODEC_ERROR
  255. * @{
  256. */
  257. /*!\brief put slice callback prototype
  258. *
  259. * This callback is invoked by the decoder to notify the application of
  260. * the availability of partially decoded image data. The
  261. */
  262. typedef void (*vpx_codec_put_slice_cb_fn_t)(void *user_priv,
  263. const vpx_image_t *img,
  264. const vpx_image_rect_t *valid,
  265. const vpx_image_rect_t *update);
  266. /*!\brief Register for notification of slice completion.
  267. *
  268. * Registers a given function to be called when a decoded slice is
  269. * available.
  270. *
  271. * \param[in] ctx Pointer to this instance's context
  272. * \param[in] cb Pointer to the callback function
  273. * \param[in] user_priv User's private data
  274. *
  275. * \retval #VPX_CODEC_OK
  276. * Callback successfully registered.
  277. * \retval #VPX_CODEC_ERROR
  278. * Decoder context not initialized, or algorithm not capable of
  279. * posting slice completion.
  280. */
  281. vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx,
  282. vpx_codec_put_slice_cb_fn_t cb,
  283. void *user_priv);
  284. /*!@} - end defgroup cap_put_slice*/
  285. /*!@} - end defgroup decoder*/
  286. #endif
  287. #ifdef __cplusplus
  288. }
  289. #endif