blob: ceab93453fcfdcae0a9316a23459455db8a83fbc [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
Yaowu Xuf883b422016-08-30 14:01:10 -070011#ifndef AOM_AOM_DECODER_H_
12#define AOM_AOM_DECODER_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070013
14/*!\defgroup decoder Decoder Algorithm Interface
15 * \ingroup codec
16 * This abstraction allows applications using this decoder to easily support
17 * multiple video formats with minimal code duplication. This section describes
18 * the interface common to all decoders.
19 * @{
20 */
21
22/*!\file
23 * \brief Describes the decoder algorithm interface to applications.
24 *
25 * This file describes the interface between an application and a
26 * video decoder algorithm.
27 *
28 */
29#ifdef __cplusplus
30extern "C" {
31#endif
32
Yaowu Xuf883b422016-08-30 14:01:10 -070033#include "./aom_codec.h"
34#include "./aom_frame_buffer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070035
36/*!\brief Current ABI version number
37 *
38 * \internal
39 * If this file is altered in any way that changes the ABI, this value
40 * must be bumped. Examples include, but are not limited to, changing
41 * types, removing or reassigning enums, adding/removing/rearranging
42 * fields to structures
43 */
Yaowu Xuf883b422016-08-30 14:01:10 -070044#define AOM_DECODER_ABI_VERSION \
45 (3 + AOM_CODEC_ABI_VERSION) /**<\hideinitializer*/
Yaowu Xuc27fc142016-08-22 16:08:15 -070046
47/*! \brief Decoder capabilities bitfield
48 *
49 * Each decoder advertises the capabilities it supports as part of its
Yaowu Xuf883b422016-08-30 14:01:10 -070050 * ::aom_codec_iface_t interface structure. Capabilities are extra interfaces
Yaowu Xuc27fc142016-08-22 16:08:15 -070051 * or functionality, and are not required to be supported by a decoder.
52 *
Yaowu Xuf883b422016-08-30 14:01:10 -070053 * The available flags are specified by AOM_CODEC_CAP_* defines.
Yaowu Xuc27fc142016-08-22 16:08:15 -070054 */
Yaowu Xuf883b422016-08-30 14:01:10 -070055#define AOM_CODEC_CAP_PUT_SLICE 0x10000 /**< Will issue put_slice callbacks */
56#define AOM_CODEC_CAP_PUT_FRAME 0x20000 /**< Will issue put_frame callbacks */
57#define AOM_CODEC_CAP_POSTPROC 0x40000 /**< Can postprocess decoded frame */
Yaowu Xuc27fc142016-08-22 16:08:15 -070058/*!\brief Can receive encoded frames one fragment at a time */
Yaowu Xuf883b422016-08-30 14:01:10 -070059#define AOM_CODEC_CAP_INPUT_FRAGMENTS 0x100000
Yaowu Xuc27fc142016-08-22 16:08:15 -070060
61/*! \brief Initialization-time Feature Enabling
62 *
63 * Certain codec features must be known at initialization time, to allow for
64 * proper memory allocation.
65 *
Yaowu Xuf883b422016-08-30 14:01:10 -070066 * The available flags are specified by AOM_CODEC_USE_* defines.
Yaowu Xuc27fc142016-08-22 16:08:15 -070067 */
68/*!\brief Can support frame-based multi-threading */
Yaowu Xuf883b422016-08-30 14:01:10 -070069#define AOM_CODEC_CAP_FRAME_THREADING 0x200000
Yaowu Xuc27fc142016-08-22 16:08:15 -070070/*!brief Can support external frame buffers */
Yaowu Xuf883b422016-08-30 14:01:10 -070071#define AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER 0x400000
Yaowu Xuc27fc142016-08-22 16:08:15 -070072
Yaowu Xuf883b422016-08-30 14:01:10 -070073#define AOM_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */
Yaowu Xuc27fc142016-08-22 16:08:15 -070074/*!\brief The input frame should be passed to the decoder one fragment at a
75 * time */
Yaowu Xuf883b422016-08-30 14:01:10 -070076#define AOM_CODEC_USE_INPUT_FRAGMENTS 0x40000
Yaowu Xuc27fc142016-08-22 16:08:15 -070077/*!\brief Enable frame-based multi-threading */
Yaowu Xuf883b422016-08-30 14:01:10 -070078#define AOM_CODEC_USE_FRAME_THREADING 0x80000
Yaowu Xuc27fc142016-08-22 16:08:15 -070079
80/*!\brief Stream properties
81 *
82 * This structure is used to query or set properties of the decoded
Ralph Gilesafe71d92017-05-03 13:18:57 -070083 * stream.
Yaowu Xuc27fc142016-08-22 16:08:15 -070084 */
Yaowu Xuf883b422016-08-30 14:01:10 -070085typedef struct aom_codec_stream_info {
Yaowu Xuc27fc142016-08-22 16:08:15 -070086 unsigned int w; /**< Width (or 0 for unknown/default) */
87 unsigned int h; /**< Height (or 0 for unknown/default) */
88 unsigned int is_kf; /**< Current frame is a keyframe */
Yaowu Xuf883b422016-08-30 14:01:10 -070089} aom_codec_stream_info_t;
Yaowu Xuc27fc142016-08-22 16:08:15 -070090
91/* REQUIRED FUNCTIONS
92 *
93 * The following functions are required to be implemented for all decoders.
94 * They represent the base case functionality expected of all decoders.
95 */
96
97/*!\brief Initialization Configurations
98 *
99 * This structure is used to pass init time configuration options to the
100 * decoder.
101 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700102typedef struct aom_codec_dec_cfg {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700103 unsigned int threads; /**< Maximum number of threads to use, default 1 */
104 unsigned int w; /**< Width */
105 unsigned int h; /**< Height */
Sebastien Alaiwan8b7a4e12017-06-13 11:25:57 +0200106 unsigned int allow_lowbitdepth; /**< Allow use of low-bitdepth coding path */
107} aom_codec_dec_cfg_t; /**< alias for struct aom_codec_dec_cfg */
Yaowu Xuc27fc142016-08-22 16:08:15 -0700108
109/*!\brief Initialize a decoder instance
110 *
111 * Initializes a decoder context using the given interface. Applications
Yaowu Xuf883b422016-08-30 14:01:10 -0700112 * should call the aom_codec_dec_init convenience macro instead of this
Yaowu Xuc27fc142016-08-22 16:08:15 -0700113 * function directly, to ensure that the ABI version number parameter
114 * is properly initialized.
115 *
116 * If the library was configured with --disable-multithread, this call
117 * is not thread safe and should be guarded with a lock if being used
118 * in a multithreaded context.
119 *
120 * \param[in] ctx Pointer to this instance's context.
121 * \param[in] iface Pointer to the algorithm interface to use.
122 * \param[in] cfg Configuration to use, if known. May be NULL.
Yaowu Xuf883b422016-08-30 14:01:10 -0700123 * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
Yaowu Xuc27fc142016-08-22 16:08:15 -0700124 * \param[in] ver ABI version number. Must be set to
Yaowu Xuf883b422016-08-30 14:01:10 -0700125 * AOM_DECODER_ABI_VERSION
126 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -0700127 * The decoder algorithm initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 * \retval #AOM_CODEC_MEM_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700129 * Memory allocation failed.
130 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700131aom_codec_err_t aom_codec_dec_init_ver(aom_codec_ctx_t *ctx,
132 aom_codec_iface_t *iface,
133 const aom_codec_dec_cfg_t *cfg,
134 aom_codec_flags_t flags, int ver);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700135
Yaowu Xuf883b422016-08-30 14:01:10 -0700136/*!\brief Convenience macro for aom_codec_dec_init_ver()
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137 *
138 * Ensures the ABI version parameter is properly set.
139 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700140#define aom_codec_dec_init(ctx, iface, cfg, flags) \
141 aom_codec_dec_init_ver(ctx, iface, cfg, flags, AOM_DECODER_ABI_VERSION)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700142
143/*!\brief Parse stream info from a buffer
144 *
145 * Performs high level parsing of the bitstream. Construction of a decoder
146 * context is not necessary. Can be used to determine if the bitstream is
147 * of the proper format, and to extract information from the stream.
148 *
149 * \param[in] iface Pointer to the algorithm interface
150 * \param[in] data Pointer to a block of data to parse
151 * \param[in] data_sz Size of the data buffer
Ralph Gilesafe71d92017-05-03 13:18:57 -0700152 * \param[in,out] si Pointer to stream info to update.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700153 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700154 * \retval #AOM_CODEC_OK
Ralph Gilesafe71d92017-05-03 13:18:57 -0700155 * Bitstream is parsable and stream information updated.
156 * \retval #AOM_CODEC_INVALID_PARAM
157 * One of the arguments is invalid, for example a NULL pointer.
158 * \retval #AOM_CODEC_UNSUP_BITSTREAM
159 * The decoder didn't recognize the coded data, or the
160 * buffer was too short.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700161 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700162aom_codec_err_t aom_codec_peek_stream_info(aom_codec_iface_t *iface,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700163 const uint8_t *data,
164 unsigned int data_sz,
Yaowu Xuf883b422016-08-30 14:01:10 -0700165 aom_codec_stream_info_t *si);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700166
167/*!\brief Return information about the current stream.
168 *
169 * Returns information about the stream that has been parsed during decoding.
170 *
171 * \param[in] ctx Pointer to this instance's context
Ralph Gilesafe71d92017-05-03 13:18:57 -0700172 * \param[in,out] si Pointer to stream info to update.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700173 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700174 * \retval #AOM_CODEC_OK
Ralph Gilesafe71d92017-05-03 13:18:57 -0700175 * Bitstream is parsable and stream information updated.
176 * \retval #AOM_CODEC_INVALID_PARAM
177 * One of the arguments is invalid, for example a NULL pointer.
178 * \retval #AOM_CODEC_UNSUP_BITSTREAM
179 * The decoder couldn't parse the submitted data.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700180 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700181aom_codec_err_t aom_codec_get_stream_info(aom_codec_ctx_t *ctx,
182 aom_codec_stream_info_t *si);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700183
184/*!\brief Decode data
185 *
186 * Processes a buffer of coded data. If the processing results in a new
187 * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be
188 * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode
189 * time stamp) order. Frames produced will always be in PTS (presentation
190 * time stamp) order.
Yaowu Xuf883b422016-08-30 14:01:10 -0700191 * If the decoder is configured with AOM_CODEC_USE_INPUT_FRAGMENTS enabled,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700192 * data and data_sz can contain a fragment of the encoded frame. Fragment
193 * \#n must contain at least partition \#n, but can also contain subsequent
194 * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must
195 * be empty. When no more data is available, this function should be called
196 * with NULL as data and 0 as data_sz. The memory passed to this function
197 * must be available until the frame has been decoded.
198 *
199 * \param[in] ctx Pointer to this instance's context
200 * \param[in] data Pointer to this block of new coded data. If
Yaowu Xuf883b422016-08-30 14:01:10 -0700201 * NULL, a AOM_CODEC_CB_PUT_FRAME event is posted
Yaowu Xuc27fc142016-08-22 16:08:15 -0700202 * for the previously decoded frame.
203 * \param[in] data_sz Size of the coded data, in bytes.
204 * \param[in] user_priv Application specific data to associate with
205 * this frame.
206 * \param[in] deadline Soft deadline the decoder should attempt to meet,
207 * in us. Set to zero for unlimited.
208 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700209 * \return Returns #AOM_CODEC_OK if the coded data was processed completely
Yaowu Xuc27fc142016-08-22 16:08:15 -0700210 * and future pictures can be decoded without error. Otherwise,
Yaowu Xuf883b422016-08-30 14:01:10 -0700211 * see the descriptions of the other error codes in ::aom_codec_err_t
Yaowu Xuc27fc142016-08-22 16:08:15 -0700212 * for recoverability capabilities.
213 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700214aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700215 unsigned int data_sz, void *user_priv,
216 long deadline);
217
218/*!\brief Decoded frames iterator
219 *
220 * Iterates over a list of the frames available for display. The iterator
221 * storage should be initialized to NULL to start the iteration. Iteration is
222 * complete when this function returns NULL.
223 *
224 * The list of available frames becomes valid upon completion of the
Yaowu Xuf883b422016-08-30 14:01:10 -0700225 * aom_codec_decode call, and remains valid until the next call to
226 * aom_codec_decode.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700227 *
228 * \param[in] ctx Pointer to this instance's context
229 * \param[in,out] iter Iterator storage, initialized to NULL
230 *
231 * \return Returns a pointer to an image, if one is ready for display. Frames
232 * produced will always be in PTS (presentation time stamp) order.
233 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700234aom_image_t *aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700235
236/*!\defgroup cap_put_frame Frame-Based Decoding Functions
237 *
238 * The following functions are required to be implemented for all decoders
Yaowu Xuf883b422016-08-30 14:01:10 -0700239 * that advertise the AOM_CODEC_CAP_PUT_FRAME capability. Calling these
Yaowu Xuc27fc142016-08-22 16:08:15 -0700240 * functions
241 * for codecs that don't advertise this capability will result in an error
Yaowu Xuf883b422016-08-30 14:01:10 -0700242 * code being returned, usually AOM_CODEC_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700243 * @{
244 */
245
246/*!\brief put frame callback prototype
247 *
248 * This callback is invoked by the decoder to notify the application of
249 * the availability of decoded image data.
250 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700251typedef void (*aom_codec_put_frame_cb_fn_t)(void *user_priv,
252 const aom_image_t *img);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700253
254/*!\brief Register for notification of frame completion.
255 *
256 * Registers a given function to be called when a decoded frame is
257 * available.
258 *
259 * \param[in] ctx Pointer to this instance's context
260 * \param[in] cb Pointer to the callback function
261 * \param[in] user_priv User's private data
262 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700263 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -0700264 * Callback successfully registered.
Yaowu Xuf883b422016-08-30 14:01:10 -0700265 * \retval #AOM_CODEC_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700266 * Decoder context not initialized, or algorithm not capable of
267 * posting slice completion.
268 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700269aom_codec_err_t aom_codec_register_put_frame_cb(aom_codec_ctx_t *ctx,
270 aom_codec_put_frame_cb_fn_t cb,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700271 void *user_priv);
272
273/*!@} - end defgroup cap_put_frame */
274
275/*!\defgroup cap_put_slice Slice-Based Decoding Functions
276 *
277 * The following functions are required to be implemented for all decoders
Yaowu Xuf883b422016-08-30 14:01:10 -0700278 * that advertise the AOM_CODEC_CAP_PUT_SLICE capability. Calling these
Yaowu Xuc27fc142016-08-22 16:08:15 -0700279 * functions
280 * for codecs that don't advertise this capability will result in an error
Yaowu Xuf883b422016-08-30 14:01:10 -0700281 * code being returned, usually AOM_CODEC_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700282 * @{
283 */
284
285/*!\brief put slice callback prototype
286 *
287 * This callback is invoked by the decoder to notify the application of
288 * the availability of partially decoded image data. The
289 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700290typedef void (*aom_codec_put_slice_cb_fn_t)(void *user_priv,
291 const aom_image_t *img,
292 const aom_image_rect_t *valid,
293 const aom_image_rect_t *update);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700294
295/*!\brief Register for notification of slice completion.
296 *
297 * Registers a given function to be called when a decoded slice is
298 * available.
299 *
300 * \param[in] ctx Pointer to this instance's context
301 * \param[in] cb Pointer to the callback function
302 * \param[in] user_priv User's private data
303 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700304 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -0700305 * Callback successfully registered.
Yaowu Xuf883b422016-08-30 14:01:10 -0700306 * \retval #AOM_CODEC_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700307 * Decoder context not initialized, or algorithm not capable of
308 * posting slice completion.
309 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700310aom_codec_err_t aom_codec_register_put_slice_cb(aom_codec_ctx_t *ctx,
311 aom_codec_put_slice_cb_fn_t cb,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700312 void *user_priv);
313
314/*!@} - end defgroup cap_put_slice*/
315
316/*!\defgroup cap_external_frame_buffer External Frame Buffer Functions
317 *
318 * The following section is required to be implemented for all decoders
Yaowu Xuf883b422016-08-30 14:01:10 -0700319 * that advertise the AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER capability.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700320 * Calling this function for codecs that don't advertise this capability
Yaowu Xuf883b422016-08-30 14:01:10 -0700321 * will result in an error code being returned, usually AOM_CODEC_ERROR.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700322 *
323 * \note
Yaowu Xuf883b422016-08-30 14:01:10 -0700324 * Currently this only works with AV1.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700325 * @{
326 */
327
328/*!\brief Pass in external frame buffers for the decoder to use.
329 *
330 * Registers functions to be called when libaom needs a frame buffer
331 * to decode the current frame and a function to be called when libaom does
332 * not internally reference the frame buffer. This set function must
333 * be called before the first call to decode or libaom will assume the
334 * default behavior of allocating frame buffers internally.
335 *
336 * \param[in] ctx Pointer to this instance's context
337 * \param[in] cb_get Pointer to the get callback function
338 * \param[in] cb_release Pointer to the release callback function
339 * \param[in] cb_priv Callback's private data
340 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700341 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -0700342 * External frame buffers will be used by libaom.
Yaowu Xuf883b422016-08-30 14:01:10 -0700343 * \retval #AOM_CODEC_INVALID_PARAM
Yaowu Xuc27fc142016-08-22 16:08:15 -0700344 * One or more of the callbacks were NULL.
Yaowu Xuf883b422016-08-30 14:01:10 -0700345 * \retval #AOM_CODEC_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700346 * Decoder context not initialized, or algorithm not capable of
347 * using external frame buffers.
348 *
349 * \note
Yaowu Xuf883b422016-08-30 14:01:10 -0700350 * When decoding AV1, the application may be required to pass in at least
351 * #AOM_MAXIMUM_WORK_BUFFERS external frame
Yaowu Xuc27fc142016-08-22 16:08:15 -0700352 * buffers.
353 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700354aom_codec_err_t aom_codec_set_frame_buffer_functions(
355 aom_codec_ctx_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
356 aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700357
358/*!@} - end defgroup cap_external_frame_buffer */
359
360/*!@} - end defgroup decoder*/
361#ifdef __cplusplus
362}
363#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700364#endif // AOM_AOM_DECODER_H_