aom_decoder.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
  3. *
  4. * This source code is subject to the terms of the BSD 2 Clause License and
  5. * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
  6. * was not distributed with this source code in the LICENSE file, you can
  7. * obtain it at www.aomedia.org/license/software. If the Alliance for Open
  8. * Media Patent License 1.0 was not distributed with this source code in the
  9. * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
  10. */
  11. #ifndef AOM_AOM_AOM_DECODER_H_
  12. #define AOM_AOM_AOM_DECODER_H_
  13. /*!\defgroup decoder Decoder Algorithm Interface
  14. * \ingroup codec
  15. * This abstraction allows applications using this decoder to easily support
  16. * multiple video formats with minimal code duplication. This section describes
  17. * the interface common to all decoders.
  18. * @{
  19. */
  20. /*!\file
  21. * \brief Describes the decoder algorithm interface to applications.
  22. *
  23. * This file describes the interface between an application and a
  24. * video decoder algorithm.
  25. *
  26. */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #include "aom/aom_codec.h" // IWYU pragma: export
  31. #include "aom/aom_frame_buffer.h"
  32. /*!\brief Current ABI version number
  33. *
  34. * \internal
  35. * If this file is altered in any way that changes the ABI, this value
  36. * must be bumped. Examples include, but are not limited to, changing
  37. * types, removing or reassigning enums, adding/removing/rearranging
  38. * fields to structures
  39. */
  40. #define AOM_DECODER_ABI_VERSION \
  41. (6 + AOM_CODEC_ABI_VERSION) /**<\hideinitializer*/
  42. /*! \brief Decoder capabilities bitfield
  43. *
  44. * Each decoder advertises the capabilities it supports as part of its
  45. * ::aom_codec_iface_t interface structure. Capabilities are extra interfaces
  46. * or functionality, and are not required to be supported by a decoder.
  47. *
  48. * The available flags are specified by AOM_CODEC_CAP_* defines.
  49. */
  50. /*!brief Can support external frame buffers */
  51. #define AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER 0x200000
  52. /*! \brief Initialization-time Feature Enabling
  53. *
  54. * Certain codec features must be known at initialization time, to allow for
  55. * proper memory allocation.
  56. *
  57. * The available flags are specified by AOM_CODEC_USE_* defines.
  58. */
  59. /*!\brief Stream properties
  60. *
  61. * This structure is used to query or set properties of the decoded
  62. * stream.
  63. */
  64. typedef struct aom_codec_stream_info {
  65. unsigned int w; /**< Width (or 0 for unknown/default) */
  66. unsigned int h; /**< Height (or 0 for unknown/default) */
  67. unsigned int is_kf; /**< Current frame is a keyframe */
  68. unsigned int number_spatial_layers; /**< Number of spatial layers */
  69. unsigned int number_temporal_layers; /**< Number of temporal layers */
  70. unsigned int is_annexb; /**< Is Bitstream in Annex-B format */
  71. } aom_codec_stream_info_t;
  72. /* REQUIRED FUNCTIONS
  73. *
  74. * The following functions are required to be implemented for all decoders.
  75. * They represent the base case functionality expected of all decoders.
  76. */
  77. /*!\brief Initialization Configurations
  78. *
  79. * This structure is used to pass init time configuration options to the
  80. * decoder.
  81. */
  82. typedef struct aom_codec_dec_cfg {
  83. unsigned int threads; /**< Maximum number of threads to use, default 1 */
  84. unsigned int w; /**< Width */
  85. unsigned int h; /**< Height */
  86. unsigned int allow_lowbitdepth; /**< Allow use of low-bitdepth coding path */
  87. } aom_codec_dec_cfg_t; /**< alias for struct aom_codec_dec_cfg */
  88. /*!\brief Initialize a decoder instance
  89. *
  90. * Initializes a decoder context using the given interface. Applications
  91. * should call the aom_codec_dec_init convenience macro instead of this
  92. * function directly, to ensure that the ABI version number parameter
  93. * is properly initialized.
  94. *
  95. * If the library was configured with cmake -DCONFIG_MULTITHREAD=0, this
  96. * call is not thread safe and should be guarded with a lock if being used
  97. * in a multithreaded context.
  98. *
  99. * \param[in] ctx Pointer to this instance's context.
  100. * \param[in] iface Pointer to the algorithm interface to use.
  101. * \param[in] cfg Configuration to use, if known. May be NULL.
  102. * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
  103. * \param[in] ver ABI version number. Must be set to
  104. * AOM_DECODER_ABI_VERSION
  105. * \retval #AOM_CODEC_OK
  106. * The decoder algorithm has been initialized.
  107. * \retval #AOM_CODEC_MEM_ERROR
  108. * Memory allocation failed.
  109. */
  110. aom_codec_err_t aom_codec_dec_init_ver(aom_codec_ctx_t *ctx,
  111. aom_codec_iface_t *iface,
  112. const aom_codec_dec_cfg_t *cfg,
  113. aom_codec_flags_t flags, int ver);
  114. /*!\brief Convenience macro for aom_codec_dec_init_ver()
  115. *
  116. * Ensures the ABI version parameter is properly set.
  117. */
  118. #define aom_codec_dec_init(ctx, iface, cfg, flags) \
  119. aom_codec_dec_init_ver(ctx, iface, cfg, flags, AOM_DECODER_ABI_VERSION)
  120. /*!\brief Parse stream info from a buffer
  121. *
  122. * Performs high level parsing of the bitstream. Construction of a decoder
  123. * context is not necessary. Can be used to determine if the bitstream is
  124. * of the proper format, and to extract information from the stream.
  125. *
  126. * \param[in] iface Pointer to the algorithm interface
  127. * \param[in] data Pointer to a block of data to parse
  128. * \param[in] data_sz Size of the data buffer
  129. * \param[in,out] si Pointer to stream info to update. The is_annexb
  130. * member \ref MUST be properly initialized. This
  131. * function sets the rest of the members.
  132. *
  133. * \retval #AOM_CODEC_OK
  134. * Bitstream is parsable and stream information updated.
  135. * \retval #AOM_CODEC_INVALID_PARAM
  136. * One of the arguments is invalid, for example a NULL pointer.
  137. * \retval #AOM_CODEC_UNSUP_BITSTREAM
  138. * The decoder didn't recognize the coded data, or the
  139. * buffer was too short.
  140. */
  141. aom_codec_err_t aom_codec_peek_stream_info(aom_codec_iface_t *iface,
  142. const uint8_t *data, size_t data_sz,
  143. aom_codec_stream_info_t *si);
  144. /*!\brief Return information about the current stream.
  145. *
  146. * Returns information about the stream that has been parsed during decoding.
  147. *
  148. * \param[in] ctx Pointer to this instance's context
  149. * \param[in,out] si Pointer to stream info to update.
  150. *
  151. * \retval #AOM_CODEC_OK
  152. * Bitstream is parsable and stream information updated.
  153. * \retval #AOM_CODEC_INVALID_PARAM
  154. * One of the arguments is invalid, for example a NULL pointer.
  155. * \retval #AOM_CODEC_UNSUP_BITSTREAM
  156. * The decoder couldn't parse the submitted data.
  157. */
  158. aom_codec_err_t aom_codec_get_stream_info(aom_codec_ctx_t *ctx,
  159. aom_codec_stream_info_t *si);
  160. /*!\brief Decode data
  161. *
  162. * Processes a buffer of coded data. Encoded data \ref MUST be passed in DTS
  163. * (decode time stamp) order. Frames produced will always be in PTS
  164. * (presentation time stamp) order.
  165. *
  166. * \param[in] ctx Pointer to this instance's context
  167. * \param[in] data Pointer to this block of new coded data.
  168. * \param[in] data_sz Size of the coded data, in bytes.
  169. * \param[in] user_priv Application specific data to associate with
  170. * this frame.
  171. *
  172. * \return Returns #AOM_CODEC_OK if the coded data was processed completely
  173. * and future pictures can be decoded without error. Otherwise,
  174. * see the descriptions of the other error codes in ::aom_codec_err_t
  175. * for recoverability capabilities.
  176. */
  177. aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data,
  178. size_t data_sz, void *user_priv);
  179. /*!\brief Decoded frames iterator
  180. *
  181. * Iterates over a list of the frames available for display. The iterator
  182. * storage should be initialized to NULL to start the iteration. Iteration is
  183. * complete when this function returns NULL.
  184. *
  185. * The list of available frames becomes valid upon completion of the
  186. * aom_codec_decode call, and remains valid until the next call to
  187. * aom_codec_decode.
  188. *
  189. * \param[in] ctx Pointer to this instance's context
  190. * \param[in,out] iter Iterator storage, initialized to NULL
  191. *
  192. * \return Returns a pointer to an image, if one is ready for display. Frames
  193. * produced will always be in PTS (presentation time stamp) order.
  194. */
  195. aom_image_t *aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter);
  196. /*!\defgroup cap_external_frame_buffer External Frame Buffer Functions
  197. *
  198. * The following function is required to be implemented for all decoders
  199. * that advertise the AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER capability.
  200. * Calling this function for codecs that don't advertise this capability
  201. * will result in an error code being returned, usually AOM_CODEC_INCAPABLE.
  202. * @{
  203. */
  204. /*!\brief Pass in external frame buffers for the decoder to use.
  205. *
  206. * Registers functions to be called when libaom needs a frame buffer
  207. * to decode the current frame and a function to be called when libaom does
  208. * not internally reference the frame buffer. This set function must
  209. * be called before the first call to decode or libaom will assume the
  210. * default behavior of allocating frame buffers internally.
  211. *
  212. * \param[in] ctx Pointer to this instance's context
  213. * \param[in] cb_get Pointer to the get callback function
  214. * \param[in] cb_release Pointer to the release callback function
  215. * \param[in] cb_priv Callback's private data
  216. *
  217. * \retval #AOM_CODEC_OK
  218. * External frame buffers will be used by libaom.
  219. * \retval #AOM_CODEC_INVALID_PARAM
  220. * One or more of the callbacks were NULL.
  221. * \retval #AOM_CODEC_ERROR
  222. * Decoder context not initialized.
  223. * \retval #AOM_CODEC_INCAPABLE
  224. * Algorithm not capable of using external frame buffers.
  225. *
  226. * \note
  227. * When decoding AV1, the application may be required to pass in at least
  228. * #AOM_MAXIMUM_WORK_BUFFERS external frame buffers.
  229. */
  230. aom_codec_err_t aom_codec_set_frame_buffer_functions(
  231. aom_codec_ctx_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
  232. aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv);
  233. /*!@} - end defgroup cap_external_frame_buffer */
  234. /*!@} - end defgroup decoder*/
  235. #ifdef __cplusplus
  236. }
  237. #endif
  238. #endif // AOM_AOM_AOM_DECODER_H_