vpx_decoder.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. #ifndef VPX_DECODER_H
  11. #define VPX_DECODER_H
  12. /*!\defgroup decoder Decoder Algorithm Interface
  13. * \ingroup codec
  14. * This abstraction allows applications using this decoder to easily support
  15. * multiple video formats with minimal code duplication. This section describes
  16. * the interface common to all decoders.
  17. * @{
  18. */
  19. /*!\file
  20. * \brief Describes the decoder algorithm interface to applications.
  21. *
  22. * This file describes the interface between an application and a
  23. * video decoder algorithm.
  24. *
  25. */
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  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_CAP_FRAME_THREADING 0x200000 /**< Can support frame-based
  62. multi-threading */
  63. #define VPX_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */
  64. #define VPX_CODEC_USE_ERROR_CONCEALMENT 0x20000 /**< Conceal errors in decoded
  65. frames */
  66. #define VPX_CODEC_USE_INPUT_FRAGMENTS 0x40000 /**< The input frame should be
  67. passed to the decoder one
  68. fragment at a time */
  69. #define VPX_CODEC_USE_FRAME_THREADING 0x80000 /**< Enable frame-based
  70. multi-threading */
  71. /*!\brief Stream properties
  72. *
  73. * This structure is used to query or set properties of the decoded
  74. * stream. Algorithms may extend this structure with data specific
  75. * to their bitstream by setting the sz member appropriately.
  76. */
  77. typedef struct vpx_codec_stream_info {
  78. unsigned int sz; /**< Size of this structure */
  79. unsigned int w; /**< Width (or 0 for unknown/default) */
  80. unsigned int h; /**< Height (or 0 for unknown/default) */
  81. unsigned int is_kf; /**< Current frame is a keyframe */
  82. } vpx_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 vpx_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. } vpx_codec_dec_cfg_t; /**< alias for struct vpx_codec_dec_cfg */
  98. /*!\brief Initialize a decoder instance
  99. *
  100. * Initializes a decoder context using the given interface. Applications
  101. * should call the vpx_codec_dec_init convenience macro instead of this
  102. * function directly, to ensure that the ABI version number parameter
  103. * is properly initialized.
  104. *
  105. * If the library was configured with --disable-multithread, this call
  106. * is not thread safe and should be guarded with a lock if being used
  107. * in a multithreaded context.
  108. *
  109. * In XMA mode (activated by setting VPX_CODEC_USE_XMA in the flags
  110. * parameter), the storage pointed to by the cfg parameter must be
  111. * kept readable and stable until all memory maps have been set.
  112. *
  113. * \param[in] ctx Pointer to this instance's context.
  114. * \param[in] iface Pointer to the algorithm interface to use.
  115. * \param[in] cfg Configuration to use, if known. May be NULL.
  116. * \param[in] flags Bitfield of VPX_CODEC_USE_* flags
  117. * \param[in] ver ABI version number. Must be set to
  118. * VPX_DECODER_ABI_VERSION
  119. * \retval #VPX_CODEC_OK
  120. * The decoder algorithm initialized.
  121. * \retval #VPX_CODEC_MEM_ERROR
  122. * Memory allocation failed.
  123. */
  124. vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
  125. vpx_codec_iface_t *iface,
  126. vpx_codec_dec_cfg_t *cfg,
  127. vpx_codec_flags_t flags,
  128. int ver);
  129. /*!\brief Convenience macro for vpx_codec_dec_init_ver()
  130. *
  131. * Ensures the ABI version parameter is properly set.
  132. */
  133. #define vpx_codec_dec_init(ctx, iface, cfg, flags) \
  134. vpx_codec_dec_init_ver(ctx, iface, cfg, flags, VPX_DECODER_ABI_VERSION)
  135. /*!\brief Parse stream info from a buffer
  136. *
  137. * Performs high level parsing of the bitstream. Construction of a decoder
  138. * context is not necessary. Can be used to determine if the bitstream is
  139. * of the proper format, and to extract information from the stream.
  140. *
  141. * \param[in] iface Pointer to the algorithm interface
  142. * \param[in] data Pointer to a block of data to parse
  143. * \param[in] data_sz Size of the data buffer
  144. * \param[in,out] si Pointer to stream info to update. The size member
  145. * \ref MUST be properly initialized, but \ref MAY be
  146. * clobbered by the algorithm. This parameter \ref MAY
  147. * be NULL.
  148. *
  149. * \retval #VPX_CODEC_OK
  150. * Bitstream is parsable and stream information updated
  151. */
  152. vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
  153. const uint8_t *data,
  154. unsigned int data_sz,
  155. vpx_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. The size member
  162. * \ref MUST be properly initialized, but \ref MAY be
  163. * clobbered by the algorithm. This parameter \ref MAY
  164. * be NULL.
  165. *
  166. * \retval #VPX_CODEC_OK
  167. * Bitstream is parsable and stream information updated
  168. */
  169. vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
  170. vpx_codec_stream_info_t *si);
  171. /*!\brief Decode data
  172. *
  173. * Processes a buffer of coded data. If the processing results in a new
  174. * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be
  175. * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode
  176. * time stamp) order. Frames produced will always be in PTS (presentation
  177. * time stamp) order.
  178. * If the decoder is configured with VPX_CODEC_USE_INPUT_FRAGMENTS enabled,
  179. * data and data_sz can contain a fragment of the encoded frame. Fragment
  180. * \#n must contain at least partition \#n, but can also contain subsequent
  181. * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must
  182. * be empty. When no more data is available, this function should be called
  183. * with NULL as data and 0 as data_sz. The memory passed to this function
  184. * must be available until the frame has been decoded.
  185. *
  186. * \param[in] ctx Pointer to this instance's context
  187. * \param[in] data Pointer to this block of new coded data. If
  188. * NULL, a VPX_CODEC_CB_PUT_FRAME event is posted
  189. * for the previously decoded frame.
  190. * \param[in] data_sz Size of the coded data, in bytes.
  191. * \param[in] user_priv Application specific data to associate with
  192. * this frame.
  193. * \param[in] deadline Soft deadline the decoder should attempt to meet,
  194. * in us. Set to zero for unlimited.
  195. *
  196. * \return Returns #VPX_CODEC_OK if the coded data was processed completely
  197. * and future pictures can be decoded without error. Otherwise,
  198. * see the descriptions of the other error codes in ::vpx_codec_err_t
  199. * for recoverability capabilities.
  200. */
  201. vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx,
  202. const uint8_t *data,
  203. unsigned int data_sz,
  204. void *user_priv,
  205. long deadline);
  206. /*!\brief Decoded frames iterator
  207. *
  208. * Iterates over a list of the frames available for display. The iterator
  209. * storage should be initialized to NULL to start the iteration. Iteration is
  210. * complete when this function returns NULL.
  211. *
  212. * The list of available frames becomes valid upon completion of the
  213. * vpx_codec_decode call, and remains valid until the next call to vpx_codec_decode.
  214. *
  215. * \param[in] ctx Pointer to this instance's context
  216. * \param[in,out] iter Iterator storage, initialized to NULL
  217. *
  218. * \return Returns a pointer to an image, if one is ready for display. Frames
  219. * produced will always be in PTS (presentation time stamp) order.
  220. */
  221. vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx,
  222. vpx_codec_iter_t *iter);
  223. /*!\defgroup cap_put_frame Frame-Based Decoding Functions
  224. *
  225. * The following functions are required to be implemented for all decoders
  226. * that advertise the VPX_CODEC_CAP_PUT_FRAME capability. Calling these functions
  227. * for codecs that don't advertise this capability will result in an error
  228. * code being returned, usually VPX_CODEC_ERROR
  229. * @{
  230. */
  231. /*!\brief put frame callback prototype
  232. *
  233. * This callback is invoked by the decoder to notify the application of
  234. * the availability of decoded image data.
  235. */
  236. typedef void (*vpx_codec_put_frame_cb_fn_t)(void *user_priv,
  237. const vpx_image_t *img);
  238. /*!\brief Register for notification of frame completion.
  239. *
  240. * Registers a given function to be called when a decoded frame is
  241. * available.
  242. *
  243. * \param[in] ctx Pointer to this instance's context
  244. * \param[in] cb Pointer to the callback function
  245. * \param[in] user_priv User's private data
  246. *
  247. * \retval #VPX_CODEC_OK
  248. * Callback successfully registered.
  249. * \retval #VPX_CODEC_ERROR
  250. * Decoder context not initialized, or algorithm not capable of
  251. * posting slice completion.
  252. */
  253. vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx,
  254. vpx_codec_put_frame_cb_fn_t cb,
  255. void *user_priv);
  256. /*!@} - end defgroup cap_put_frame */
  257. /*!\defgroup cap_put_slice Slice-Based Decoding Functions
  258. *
  259. * The following functions are required to be implemented for all decoders
  260. * that advertise the VPX_CODEC_CAP_PUT_SLICE capability. Calling these functions
  261. * for codecs that don't advertise this capability will result in an error
  262. * code being returned, usually VPX_CODEC_ERROR
  263. * @{
  264. */
  265. /*!\brief put slice callback prototype
  266. *
  267. * This callback is invoked by the decoder to notify the application of
  268. * the availability of partially decoded image data. The
  269. */
  270. typedef void (*vpx_codec_put_slice_cb_fn_t)(void *user_priv,
  271. const vpx_image_t *img,
  272. const vpx_image_rect_t *valid,
  273. const vpx_image_rect_t *update);
  274. /*!\brief Register for notification of slice completion.
  275. *
  276. * Registers a given function to be called when a decoded slice is
  277. * available.
  278. *
  279. * \param[in] ctx Pointer to this instance's context
  280. * \param[in] cb Pointer to the callback function
  281. * \param[in] user_priv User's private data
  282. *
  283. * \retval #VPX_CODEC_OK
  284. * Callback successfully registered.
  285. * \retval #VPX_CODEC_ERROR
  286. * Decoder context not initialized, or algorithm not capable of
  287. * posting slice completion.
  288. */
  289. vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx,
  290. vpx_codec_put_slice_cb_fn_t cb,
  291. void *user_priv);
  292. /*!@} - end defgroup cap_put_slice*/
  293. /*!@} - end defgroup decoder*/
  294. #ifdef __cplusplus
  295. }
  296. #endif
  297. #endif