aom_decoder.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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_DECODER_H_
  12. #define 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"
  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. (3 + 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. #define AOM_CODEC_CAP_PUT_SLICE 0x10000 /**< Will issue put_slice callbacks */
  51. #define AOM_CODEC_CAP_PUT_FRAME 0x20000 /**< Will issue put_frame callbacks */
  52. #define AOM_CODEC_CAP_POSTPROC 0x40000 /**< Can postprocess decoded frame */
  53. /*!\brief Can receive encoded frames one fragment at a time */
  54. #define AOM_CODEC_CAP_INPUT_FRAGMENTS 0x100000
  55. /*! \brief Initialization-time Feature Enabling
  56. *
  57. * Certain codec features must be known at initialization time, to allow for
  58. * proper memory allocation.
  59. *
  60. * The available flags are specified by AOM_CODEC_USE_* defines.
  61. */
  62. /*!\brief Can support frame-based multi-threading */
  63. #define AOM_CODEC_CAP_FRAME_THREADING 0x200000
  64. /*!brief Can support external frame buffers */
  65. #define AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER 0x400000
  66. #define AOM_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */
  67. /*!\brief The input frame should be passed to the decoder one fragment at a
  68. * time */
  69. #define AOM_CODEC_USE_INPUT_FRAGMENTS 0x40000
  70. /*!\brief Stream properties
  71. *
  72. * This structure is used to query or set properties of the decoded
  73. * stream.
  74. */
  75. typedef struct aom_codec_stream_info {
  76. unsigned int w; /**< Width (or 0 for unknown/default) */
  77. unsigned int h; /**< Height (or 0 for unknown/default) */
  78. unsigned int is_kf; /**< Current frame is a keyframe */
  79. unsigned int number_spatial_layers; /**< Number of spatial layers */
  80. unsigned int number_temporal_layers; /**< Number of temporal layers */
  81. unsigned int is_annexb; /**< Is Bitstream in Annex-B format */
  82. } aom_codec_stream_info_t;
  83. /* REQUIRED FUNCTIONS
  84. *
  85. * The following functions are required to be implemented for all decoders.
  86. * They represent the base case functionality expected of all decoders.
  87. */
  88. /*!\brief Initialization Configurations
  89. *
  90. * This structure is used to pass init time configuration options to the
  91. * decoder.
  92. */
  93. typedef struct aom_codec_dec_cfg {
  94. unsigned int threads; /**< Maximum number of threads to use, default 1 */
  95. unsigned int w; /**< Width */
  96. unsigned int h; /**< Height */
  97. unsigned int allow_lowbitdepth; /**< Allow use of low-bitdepth coding path */
  98. cfg_options_t cfg; /**< Options defined per config attributes */
  99. } aom_codec_dec_cfg_t; /**< alias for struct aom_codec_dec_cfg */
  100. /*!\brief Initialize a decoder instance
  101. *
  102. * Initializes a decoder context using the given interface. Applications
  103. * should call the aom_codec_dec_init convenience macro instead of this
  104. * function directly, to ensure that the ABI version number parameter
  105. * is properly initialized.
  106. *
  107. * If the library was configured with --disable-multithread, this call
  108. * is not thread safe and should be guarded with a lock if being used
  109. * in a multithreaded context.
  110. *
  111. * \param[in] ctx Pointer to this instance's context.
  112. * \param[in] iface Pointer to the algorithm interface to use.
  113. * \param[in] cfg Configuration to use, if known. May be NULL.
  114. * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
  115. * \param[in] ver ABI version number. Must be set to
  116. * AOM_DECODER_ABI_VERSION
  117. * \retval #AOM_CODEC_OK
  118. * The decoder algorithm initialized.
  119. * \retval #AOM_CODEC_MEM_ERROR
  120. * Memory allocation failed.
  121. */
  122. aom_codec_err_t aom_codec_dec_init_ver(aom_codec_ctx_t *ctx,
  123. aom_codec_iface_t *iface,
  124. const aom_codec_dec_cfg_t *cfg,
  125. aom_codec_flags_t flags, int ver);
  126. /*!\brief Convenience macro for aom_codec_dec_init_ver()
  127. *
  128. * Ensures the ABI version parameter is properly set.
  129. */
  130. #define aom_codec_dec_init(ctx, iface, cfg, flags) \
  131. aom_codec_dec_init_ver(ctx, iface, cfg, flags, AOM_DECODER_ABI_VERSION)
  132. /*!\brief Parse stream info from a buffer
  133. *
  134. * Performs high level parsing of the bitstream. Construction of a decoder
  135. * context is not necessary. Can be used to determine if the bitstream is
  136. * of the proper format, and to extract information from the stream.
  137. *
  138. * \param[in] iface Pointer to the algorithm interface
  139. * \param[in] data Pointer to a block of data to parse
  140. * \param[in] data_sz Size of the data buffer
  141. * \param[in,out] si Pointer to stream info to update. The is_annexb
  142. * member \ref MUST be properly initialized. This
  143. * function sets the rest of the members.
  144. *
  145. * \retval #AOM_CODEC_OK
  146. * Bitstream is parsable and stream information updated.
  147. * \retval #AOM_CODEC_INVALID_PARAM
  148. * One of the arguments is invalid, for example a NULL pointer.
  149. * \retval #AOM_CODEC_UNSUP_BITSTREAM
  150. * The decoder didn't recognize the coded data, or the
  151. * buffer was too short.
  152. */
  153. aom_codec_err_t aom_codec_peek_stream_info(aom_codec_iface_t *iface,
  154. const uint8_t *data, size_t data_sz,
  155. aom_codec_stream_info_t *si);
  156. /*!\brief Return information about the current stream.
  157. *
  158. * Returns information about the stream that has been parsed during decoding.
  159. *
  160. * \param[in] ctx Pointer to this instance's context
  161. * \param[in,out] si Pointer to stream info to update.
  162. *
  163. * \retval #AOM_CODEC_OK
  164. * Bitstream is parsable and stream information updated.
  165. * \retval #AOM_CODEC_INVALID_PARAM
  166. * One of the arguments is invalid, for example a NULL pointer.
  167. * \retval #AOM_CODEC_UNSUP_BITSTREAM
  168. * The decoder couldn't parse the submitted data.
  169. */
  170. aom_codec_err_t aom_codec_get_stream_info(aom_codec_ctx_t *ctx,
  171. aom_codec_stream_info_t *si);
  172. /*!\brief Decode data
  173. *
  174. * Processes a buffer of coded data. If the processing results in a new
  175. * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be
  176. * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode
  177. * time stamp) order. Frames produced will always be in PTS (presentation
  178. * time stamp) order.
  179. * If the decoder is configured with AOM_CODEC_USE_INPUT_FRAGMENTS enabled,
  180. * data and data_sz can contain a fragment of the encoded frame. Fragment
  181. * \#n must contain at least partition \#n, but can also contain subsequent
  182. * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must
  183. * be empty. When no more data is available, this function should be called
  184. * with NULL as data and 0 as data_sz. The memory passed to this function
  185. * must be available until the frame has been decoded.
  186. *
  187. * \param[in] ctx Pointer to this instance's context
  188. * \param[in] data Pointer to this block of new coded data. If
  189. * NULL, a AOM_CODEC_CB_PUT_FRAME event is posted
  190. * for the previously decoded frame.
  191. * \param[in] data_sz Size of the coded data, in bytes.
  192. * \param[in] user_priv Application specific data to associate with
  193. * this frame.
  194. *
  195. * \return Returns #AOM_CODEC_OK if the coded data was processed completely
  196. * and future pictures can be decoded without error. Otherwise,
  197. * see the descriptions of the other error codes in ::aom_codec_err_t
  198. * for recoverability capabilities.
  199. */
  200. aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data,
  201. size_t data_sz, void *user_priv);
  202. /*!\brief Decoded frames iterator
  203. *
  204. * Iterates over a list of the frames available for display. The iterator
  205. * storage should be initialized to NULL to start the iteration. Iteration is
  206. * complete when this function returns NULL.
  207. *
  208. * The list of available frames becomes valid upon completion of the
  209. * aom_codec_decode call, and remains valid until the next call to
  210. * aom_codec_decode.
  211. *
  212. * \param[in] ctx Pointer to this instance's context
  213. * \param[in,out] iter Iterator storage, initialized to NULL
  214. *
  215. * \return Returns a pointer to an image, if one is ready for display. Frames
  216. * produced will always be in PTS (presentation time stamp) order.
  217. */
  218. aom_image_t *aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter);
  219. /*!\defgroup cap_put_frame Frame-Based Decoding Functions
  220. *
  221. * The following functions are required to be implemented for all decoders
  222. * that advertise the AOM_CODEC_CAP_PUT_FRAME capability. Calling these
  223. * functions
  224. * for codecs that don't advertise this capability will result in an error
  225. * code being returned, usually AOM_CODEC_ERROR
  226. * @{
  227. */
  228. /*!\brief put frame callback prototype
  229. *
  230. * This callback is invoked by the decoder to notify the application of
  231. * the availability of decoded image data.
  232. */
  233. typedef void (*aom_codec_put_frame_cb_fn_t)(void *user_priv,
  234. const aom_image_t *img);
  235. /*!\brief Register for notification of frame completion.
  236. *
  237. * Registers a given function to be called when a decoded frame is
  238. * available.
  239. *
  240. * \param[in] ctx Pointer to this instance's context
  241. * \param[in] cb Pointer to the callback function
  242. * \param[in] user_priv User's private data
  243. *
  244. * \retval #AOM_CODEC_OK
  245. * Callback successfully registered.
  246. * \retval #AOM_CODEC_ERROR
  247. * Decoder context not initialized, or algorithm not capable of
  248. * posting slice completion.
  249. */
  250. aom_codec_err_t aom_codec_register_put_frame_cb(aom_codec_ctx_t *ctx,
  251. aom_codec_put_frame_cb_fn_t cb,
  252. void *user_priv);
  253. /*!@} - end defgroup cap_put_frame */
  254. /*!\defgroup cap_put_slice Slice-Based Decoding Functions
  255. *
  256. * The following functions are required to be implemented for all decoders
  257. * that advertise the AOM_CODEC_CAP_PUT_SLICE capability. Calling these
  258. * functions
  259. * for codecs that don't advertise this capability will result in an error
  260. * code being returned, usually AOM_CODEC_ERROR
  261. * @{
  262. */
  263. /*!\brief put slice callback prototype
  264. *
  265. * This callback is invoked by the decoder to notify the application of
  266. * the availability of partially decoded image data. The
  267. */
  268. typedef void (*aom_codec_put_slice_cb_fn_t)(void *user_priv,
  269. const aom_image_t *img,
  270. const aom_image_rect_t *valid,
  271. const aom_image_rect_t *update);
  272. /*!\brief Register for notification of slice completion.
  273. *
  274. * Registers a given function to be called when a decoded slice is
  275. * available.
  276. *
  277. * \param[in] ctx Pointer to this instance's context
  278. * \param[in] cb Pointer to the callback function
  279. * \param[in] user_priv User's private data
  280. *
  281. * \retval #AOM_CODEC_OK
  282. * Callback successfully registered.
  283. * \retval #AOM_CODEC_ERROR
  284. * Decoder context not initialized, or algorithm not capable of
  285. * posting slice completion.
  286. */
  287. aom_codec_err_t aom_codec_register_put_slice_cb(aom_codec_ctx_t *ctx,
  288. aom_codec_put_slice_cb_fn_t cb,
  289. void *user_priv);
  290. /*!@} - end defgroup cap_put_slice*/
  291. /*!\defgroup cap_external_frame_buffer External Frame Buffer Functions
  292. *
  293. * The following section is required to be implemented for all decoders
  294. * that advertise the AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER capability.
  295. * Calling this function for codecs that don't advertise this capability
  296. * will result in an error code being returned, usually AOM_CODEC_ERROR.
  297. *
  298. * \note
  299. * Currently this only works with AV1.
  300. * @{
  301. */
  302. /*!\brief Pass in external frame buffers for the decoder to use.
  303. *
  304. * Registers functions to be called when libaom needs a frame buffer
  305. * to decode the current frame and a function to be called when libaom does
  306. * not internally reference the frame buffer. This set function must
  307. * be called before the first call to decode or libaom will assume the
  308. * default behavior of allocating frame buffers internally.
  309. *
  310. * \param[in] ctx Pointer to this instance's context
  311. * \param[in] cb_get Pointer to the get callback function
  312. * \param[in] cb_release Pointer to the release callback function
  313. * \param[in] cb_priv Callback's private data
  314. *
  315. * \retval #AOM_CODEC_OK
  316. * External frame buffers will be used by libaom.
  317. * \retval #AOM_CODEC_INVALID_PARAM
  318. * One or more of the callbacks were NULL.
  319. * \retval #AOM_CODEC_ERROR
  320. * Decoder context not initialized, or algorithm not capable of
  321. * using external frame buffers.
  322. *
  323. * \note
  324. * When decoding AV1, the application may be required to pass in at least
  325. * #AOM_MAXIMUM_WORK_BUFFERS external frame
  326. * buffers.
  327. */
  328. aom_codec_err_t aom_codec_set_frame_buffer_functions(
  329. aom_codec_ctx_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
  330. aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv);
  331. /*!@} - end defgroup cap_external_frame_buffer */
  332. /*!@} - end defgroup decoder*/
  333. #ifdef __cplusplus
  334. }
  335. #endif
  336. #endif // AOM_AOM_DECODER_H_