aom_decoder.h 14.6 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar's avatar
John Koleszar committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
John Koleszar's avatar
John Koleszar committed
10
 */
Adrian Grange's avatar
Adrian Grange committed
11 12
#ifndef AOM_AOM_DECODER_H_
#define AOM_AOM_DECODER_H_
John Koleszar's avatar
John Koleszar committed
13 14 15 16 17 18 19 20 21

/*!\defgroup decoder Decoder Algorithm Interface
 * \ingroup codec
 * This abstraction allows applications using this decoder to easily support
 * multiple video formats with minimal code duplication. This section describes
 * the interface common to all decoders.
 * @{
 */

James Zern's avatar
James Zern committed
22
/*!\file
John Koleszar's avatar
John Koleszar committed
23 24 25 26 27 28 29 30 31 32
 * \brief Describes the decoder algorithm interface to applications.
 *
 * This file describes the interface between an application and a
 * video decoder algorithm.
 *
 */
#ifdef __cplusplus
extern "C" {
#endif

Adrian Grange's avatar
Adrian Grange committed
33 34
#include "./aom_codec.h"
#include "./aom_frame_buffer.h"
John Koleszar's avatar
John Koleszar committed
35

clang-format's avatar
clang-format committed
36 37 38 39 40 41 42 43
/*!\brief Current ABI version number
 *
 * \internal
 * If this file is altered in any way that changes the ABI, this value
 * must be bumped.  Examples include, but are not limited to, changing
 * types, removing or reassigning enums, adding/removing/rearranging
 * fields to structures
 */
Adrian Grange's avatar
Adrian Grange committed
44 45
#define AOM_DECODER_ABI_VERSION \
  (3 + AOM_CODEC_ABI_VERSION) /**<\hideinitializer*/
John Koleszar's avatar
John Koleszar committed
46

clang-format's avatar
clang-format committed
47 48 49
/*! \brief Decoder capabilities bitfield
 *
 *  Each decoder advertises the capabilities it supports as part of its
Adrian Grange's avatar
Adrian Grange committed
50
 *  ::aom_codec_iface_t interface structure. Capabilities are extra interfaces
clang-format's avatar
clang-format committed
51 52
 *  or functionality, and are not required to be supported by a decoder.
 *
Adrian Grange's avatar
Adrian Grange committed
53
 *  The available flags are specified by AOM_CODEC_CAP_* defines.
clang-format's avatar
clang-format committed
54
 */
Adrian Grange's avatar
Adrian Grange committed
55 56 57 58
#define AOM_CODEC_CAP_PUT_SLICE 0x10000 /**< Will issue put_slice callbacks */
#define AOM_CODEC_CAP_PUT_FRAME 0x20000 /**< Will issue put_frame callbacks */
#define AOM_CODEC_CAP_POSTPROC 0x40000  /**< Can postprocess decoded frame */
#define AOM_CODEC_CAP_ERROR_CONCEALMENT 0x80000
clang-format's avatar
clang-format committed
59
/**< Can conceal errors due to packet loss */
Adrian Grange's avatar
Adrian Grange committed
60
#define AOM_CODEC_CAP_INPUT_FRAGMENTS 0x100000
clang-format's avatar
clang-format committed
61 62 63 64 65 66 67
/**< Can receive encoded frames one fragment at a time */

/*! \brief Initialization-time Feature Enabling
 *
 *  Certain codec features must be known at initialization time, to allow for
 *  proper memory allocation.
 *
Adrian Grange's avatar
Adrian Grange committed
68
 *  The available flags are specified by AOM_CODEC_USE_* defines.
clang-format's avatar
clang-format committed
69
 */
Adrian Grange's avatar
Adrian Grange committed
70
#define AOM_CODEC_CAP_FRAME_THREADING 0x200000
clang-format's avatar
clang-format committed
71
/**< Can support frame-based multi-threading */
Adrian Grange's avatar
Adrian Grange committed
72
#define AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER 0x400000
clang-format's avatar
clang-format committed
73 74
/**< Can support external frame buffers */

Adrian Grange's avatar
Adrian Grange committed
75 76
#define AOM_CODEC_USE_POSTPROC 0x10000 /**< Postprocess decoded frame */
#define AOM_CODEC_USE_ERROR_CONCEALMENT 0x20000
clang-format's avatar
clang-format committed
77
/**< Conceal errors in decoded frames */
Adrian Grange's avatar
Adrian Grange committed
78
#define AOM_CODEC_USE_INPUT_FRAGMENTS 0x40000
clang-format's avatar
clang-format committed
79
/**< The input frame should be passed to the decoder one fragment at a time */
Adrian Grange's avatar
Adrian Grange committed
80
#define AOM_CODEC_USE_FRAME_THREADING 0x80000
clang-format's avatar
clang-format committed
81 82 83 84 85 86 87 88
/**< Enable frame-based multi-threading */

/*!\brief Stream properties
 *
 * This structure is used to query or set properties of the decoded
 * stream. Algorithms may extend this structure with data specific
 * to their bitstream by setting the sz member appropriately.
 */
Adrian Grange's avatar
Adrian Grange committed
89
typedef struct aom_codec_stream_info {
clang-format's avatar
clang-format committed
90 91 92 93
  unsigned int sz;    /**< Size of this structure */
  unsigned int w;     /**< Width (or 0 for unknown/default) */
  unsigned int h;     /**< Height (or 0 for unknown/default) */
  unsigned int is_kf; /**< Current frame is a keyframe */
Adrian Grange's avatar
Adrian Grange committed
94
} aom_codec_stream_info_t;
clang-format's avatar
clang-format committed
95 96 97 98 99 100

/* REQUIRED FUNCTIONS
 *
 * The following functions are required to be implemented for all decoders.
 * They represent the base case functionality expected of all decoders.
 */
John Koleszar's avatar
John Koleszar committed
101

clang-format's avatar
clang-format committed
102 103 104 105 106
/*!\brief Initialization Configurations
 *
 * This structure is used to pass init time configuration options to the
 * decoder.
 */
Adrian Grange's avatar
Adrian Grange committed
107
typedef struct aom_codec_dec_cfg {
clang-format's avatar
clang-format committed
108 109 110
  unsigned int threads; /**< Maximum number of threads to use, default 1 */
  unsigned int w;       /**< Width */
  unsigned int h;       /**< Height */
Adrian Grange's avatar
Adrian Grange committed
111
} aom_codec_dec_cfg_t;  /**< alias for struct aom_codec_dec_cfg */
John Koleszar's avatar
John Koleszar committed
112

clang-format's avatar
clang-format committed
113 114 115
/*!\brief Initialize a decoder instance
 *
 * Initializes a decoder context using the given interface. Applications
Adrian Grange's avatar
Adrian Grange committed
116
 * should call the aom_codec_dec_init convenience macro instead of this
clang-format's avatar
clang-format committed
117 118 119 120 121 122 123 124 125 126
 * function directly, to ensure that the ABI version number parameter
 * is properly initialized.
 *
 * If the library was configured with --disable-multithread, this call
 * is not thread safe and should be guarded with a lock if being used
 * in a multithreaded context.
 *
 * \param[in]    ctx     Pointer to this instance's context.
 * \param[in]    iface   Pointer to the algorithm interface to use.
 * \param[in]    cfg     Configuration to use, if known. May be NULL.
Adrian Grange's avatar
Adrian Grange committed
127
 * \param[in]    flags   Bitfield of AOM_CODEC_USE_* flags
clang-format's avatar
clang-format committed
128
 * \param[in]    ver     ABI version number. Must be set to
Adrian Grange's avatar
Adrian Grange committed
129 130
 *                       AOM_DECODER_ABI_VERSION
 * \retval #AOM_CODEC_OK
clang-format's avatar
clang-format committed
131
 *     The decoder algorithm initialized.
Adrian Grange's avatar
Adrian Grange committed
132
 * \retval #AOM_CODEC_MEM_ERROR
clang-format's avatar
clang-format committed
133 134
 *     Memory allocation failed.
 */
Adrian Grange's avatar
Adrian Grange committed
135 136 137 138
aom_codec_err_t aom_codec_dec_init_ver(aom_codec_ctx_t *ctx,
                                       aom_codec_iface_t *iface,
                                       const aom_codec_dec_cfg_t *cfg,
                                       aom_codec_flags_t flags, int ver);
John Koleszar's avatar
John Koleszar committed
139

Adrian Grange's avatar
Adrian Grange committed
140
/*!\brief Convenience macro for aom_codec_dec_init_ver()
clang-format's avatar
clang-format committed
141 142 143
 *
 * Ensures the ABI version parameter is properly set.
 */
Adrian Grange's avatar
Adrian Grange committed
144
#define aom_codec_dec_init(ctx, iface, cfg, flags) \
Adrian Grange's avatar
Adrian Grange committed
145
  aom_codec_dec_init_ver(ctx, iface, cfg, flags, AOM_DECODER_ABI_VERSION)
John Koleszar's avatar
John Koleszar committed
146

clang-format's avatar
clang-format committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160
/*!\brief Parse stream info from a buffer
 *
 * Performs high level parsing of the bitstream. Construction of a decoder
 * context is not necessary. Can be used to determine if the bitstream is
 * of the proper format, and to extract information from the stream.
 *
 * \param[in]      iface   Pointer to the algorithm interface
 * \param[in]      data    Pointer to a block of data to parse
 * \param[in]      data_sz Size of the data buffer
 * \param[in,out]  si      Pointer to stream info to update. The size member
 *                         \ref MUST be properly initialized, but \ref MAY be
 *                         clobbered by the algorithm. This parameter \ref MAY
 *                         be NULL.
 *
Adrian Grange's avatar
Adrian Grange committed
161
 * \retval #AOM_CODEC_OK
clang-format's avatar
clang-format committed
162 163
 *     Bitstream is parsable and stream information updated
 */
Adrian Grange's avatar
Adrian Grange committed
164
aom_codec_err_t aom_codec_peek_stream_info(aom_codec_iface_t *iface,
clang-format's avatar
clang-format committed
165 166
                                           const uint8_t *data,
                                           unsigned int data_sz,
Adrian Grange's avatar
Adrian Grange committed
167
                                           aom_codec_stream_info_t *si);
John Koleszar's avatar
John Koleszar committed
168

clang-format's avatar
clang-format committed
169 170 171 172 173 174 175 176 177 178
/*!\brief Return information about the current stream.
 *
 * Returns information about the stream that has been parsed during decoding.
 *
 * \param[in]      ctx     Pointer to this instance's context
 * \param[in,out]  si      Pointer to stream info to update. The size member
 *                         \ref MUST be properly initialized, but \ref MAY be
 *                         clobbered by the algorithm. This parameter \ref MAY
 *                         be NULL.
 *
Adrian Grange's avatar
Adrian Grange committed
179
 * \retval #AOM_CODEC_OK
clang-format's avatar
clang-format committed
180 181
 *     Bitstream is parsable and stream information updated
 */
Adrian Grange's avatar
Adrian Grange committed
182 183
aom_codec_err_t aom_codec_get_stream_info(aom_codec_ctx_t *ctx,
                                          aom_codec_stream_info_t *si);
John Koleszar's avatar
John Koleszar committed
184

clang-format's avatar
clang-format committed
185 186 187 188 189 190 191
/*!\brief Decode data
 *
 * Processes a buffer of coded data. If the processing results in a new
 * decoded frame becoming available, PUT_SLICE and PUT_FRAME events may be
 * generated, as appropriate. Encoded data \ref MUST be passed in DTS (decode
 * time stamp) order. Frames produced will always be in PTS (presentation
 * time stamp) order.
Adrian Grange's avatar
Adrian Grange committed
192
 * If the decoder is configured with AOM_CODEC_USE_INPUT_FRAGMENTS enabled,
clang-format's avatar
clang-format committed
193 194 195 196 197 198 199 200 201
 * data and data_sz can contain a fragment of the encoded frame. Fragment
 * \#n must contain at least partition \#n, but can also contain subsequent
 * partitions (\#n+1 - \#n+i), and if so, fragments \#n+1, .., \#n+i must
 * be empty. When no more data is available, this function should be called
 * with NULL as data and 0 as data_sz. The memory passed to this function
 * must be available until the frame has been decoded.
 *
 * \param[in] ctx          Pointer to this instance's context
 * \param[in] data         Pointer to this block of new coded data. If
Adrian Grange's avatar
Adrian Grange committed
202
 *                         NULL, a AOM_CODEC_CB_PUT_FRAME event is posted
clang-format's avatar
clang-format committed
203 204 205 206 207 208 209
 *                         for the previously decoded frame.
 * \param[in] data_sz      Size of the coded data, in bytes.
 * \param[in] user_priv    Application specific data to associate with
 *                         this frame.
 * \param[in] deadline     Soft deadline the decoder should attempt to meet,
 *                         in us. Set to zero for unlimited.
 *
Adrian Grange's avatar
Adrian Grange committed
210
 * \return Returns #AOM_CODEC_OK if the coded data was processed completely
clang-format's avatar
clang-format committed
211
 *         and future pictures can be decoded without error. Otherwise,
Adrian Grange's avatar
Adrian Grange committed
212
 *         see the descriptions of the other error codes in ::aom_codec_err_t
clang-format's avatar
clang-format committed
213 214
 *         for recoverability capabilities.
 */
Adrian Grange's avatar
Adrian Grange committed
215
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data,
clang-format's avatar
clang-format committed
216 217
                                 unsigned int data_sz, void *user_priv,
                                 long deadline);
John Koleszar's avatar
John Koleszar committed
218

clang-format's avatar
clang-format committed
219 220 221 222 223 224 225
/*!\brief Decoded frames iterator
 *
 * Iterates over a list of the frames available for display. The iterator
 * storage should be initialized to NULL to start the iteration. Iteration is
 * complete when this function returns NULL.
 *
 * The list of available frames becomes valid upon completion of the
Adrian Grange's avatar
Adrian Grange committed
226 227
 * aom_codec_decode call, and remains valid until the next call to
 * aom_codec_decode.
clang-format's avatar
clang-format committed
228 229 230 231 232 233 234
 *
 * \param[in]     ctx      Pointer to this instance's context
 * \param[in,out] iter     Iterator storage, initialized to NULL
 *
 * \return Returns a pointer to an image, if one is ready for display. Frames
 *         produced will always be in PTS (presentation time stamp) order.
 */
Adrian Grange's avatar
Adrian Grange committed
235
aom_image_t *aom_codec_get_frame(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter);
John Koleszar's avatar
John Koleszar committed
236

clang-format's avatar
clang-format committed
237 238 239
/*!\defgroup cap_put_frame Frame-Based Decoding Functions
 *
 * The following functions are required to be implemented for all decoders
Adrian Grange's avatar
Adrian Grange committed
240
 * that advertise the AOM_CODEC_CAP_PUT_FRAME capability. Calling these
clang-format's avatar
clang-format committed
241 242
 * functions
 * for codecs that don't advertise this capability will result in an error
Adrian Grange's avatar
Adrian Grange committed
243
 * code being returned, usually AOM_CODEC_ERROR
clang-format's avatar
clang-format committed
244 245
 * @{
 */
John Koleszar's avatar
John Koleszar committed
246

clang-format's avatar
clang-format committed
247 248 249 250 251
/*!\brief put frame callback prototype
 *
 * This callback is invoked by the decoder to notify the application of
 * the availability of decoded image data.
 */
Adrian Grange's avatar
Adrian Grange committed
252 253
typedef void (*aom_codec_put_frame_cb_fn_t)(void *user_priv,
                                            const aom_image_t *img);
John Koleszar's avatar
John Koleszar committed
254

clang-format's avatar
clang-format committed
255 256 257 258 259 260 261 262 263
/*!\brief Register for notification of frame completion.
 *
 * Registers a given function to be called when a decoded frame is
 * available.
 *
 * \param[in] ctx          Pointer to this instance's context
 * \param[in] cb           Pointer to the callback function
 * \param[in] user_priv    User's private data
 *
Adrian Grange's avatar
Adrian Grange committed
264
 * \retval #AOM_CODEC_OK
clang-format's avatar
clang-format committed
265
 *     Callback successfully registered.
Adrian Grange's avatar
Adrian Grange committed
266
 * \retval #AOM_CODEC_ERROR
clang-format's avatar
clang-format committed
267 268 269
 *     Decoder context not initialized, or algorithm not capable of
 *     posting slice completion.
 */
Adrian Grange's avatar
Adrian Grange committed
270 271
aom_codec_err_t aom_codec_register_put_frame_cb(aom_codec_ctx_t *ctx,
                                                aom_codec_put_frame_cb_fn_t cb,
clang-format's avatar
clang-format committed
272
                                                void *user_priv);
John Koleszar's avatar
John Koleszar committed
273

clang-format's avatar
clang-format committed
274
/*!@} - end defgroup cap_put_frame */
John Koleszar's avatar
John Koleszar committed
275

clang-format's avatar
clang-format committed
276 277 278
/*!\defgroup cap_put_slice Slice-Based Decoding Functions
 *
 * The following functions are required to be implemented for all decoders
Adrian Grange's avatar
Adrian Grange committed
279
 * that advertise the AOM_CODEC_CAP_PUT_SLICE capability. Calling these
clang-format's avatar
clang-format committed
280 281
 * functions
 * for codecs that don't advertise this capability will result in an error
Adrian Grange's avatar
Adrian Grange committed
282
 * code being returned, usually AOM_CODEC_ERROR
clang-format's avatar
clang-format committed
283 284
 * @{
 */
John Koleszar's avatar
John Koleszar committed
285

clang-format's avatar
clang-format committed
286 287 288 289 290
/*!\brief put slice callback prototype
 *
 * This callback is invoked by the decoder to notify the application of
 * the availability of partially decoded image data. The
 */
Adrian Grange's avatar
Adrian Grange committed
291 292 293 294
typedef void (*aom_codec_put_slice_cb_fn_t)(void *user_priv,
                                            const aom_image_t *img,
                                            const aom_image_rect_t *valid,
                                            const aom_image_rect_t *update);
John Koleszar's avatar
John Koleszar committed
295

clang-format's avatar
clang-format committed
296 297 298 299 300 301 302 303 304
/*!\brief Register for notification of slice completion.
 *
 * Registers a given function to be called when a decoded slice is
 * available.
 *
 * \param[in] ctx          Pointer to this instance's context
 * \param[in] cb           Pointer to the callback function
 * \param[in] user_priv    User's private data
 *
Adrian Grange's avatar
Adrian Grange committed
305
 * \retval #AOM_CODEC_OK
clang-format's avatar
clang-format committed
306
 *     Callback successfully registered.
Adrian Grange's avatar
Adrian Grange committed
307
 * \retval #AOM_CODEC_ERROR
clang-format's avatar
clang-format committed
308 309 310
 *     Decoder context not initialized, or algorithm not capable of
 *     posting slice completion.
 */
Adrian Grange's avatar
Adrian Grange committed
311 312
aom_codec_err_t aom_codec_register_put_slice_cb(aom_codec_ctx_t *ctx,
                                                aom_codec_put_slice_cb_fn_t cb,
clang-format's avatar
clang-format committed
313
                                                void *user_priv);
John Koleszar's avatar
John Koleszar committed
314

clang-format's avatar
clang-format committed
315
/*!@} - end defgroup cap_put_slice*/
John Koleszar's avatar
John Koleszar committed
316

clang-format's avatar
clang-format committed
317 318 319
/*!\defgroup cap_external_frame_buffer External Frame Buffer Functions
 *
 * The following section is required to be implemented for all decoders
Adrian Grange's avatar
Adrian Grange committed
320
 * that advertise the AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER capability.
clang-format's avatar
clang-format committed
321
 * Calling this function for codecs that don't advertise this capability
Adrian Grange's avatar
Adrian Grange committed
322
 * will result in an error code being returned, usually AOM_CODEC_ERROR.
clang-format's avatar
clang-format committed
323 324
 *
 * \note
Adrian Grange's avatar
Adrian Grange committed
325
 * Currently this only works with AV1.
clang-format's avatar
clang-format committed
326 327
 * @{
 */
328

clang-format's avatar
clang-format committed
329 330
/*!\brief Pass in external frame buffers for the decoder to use.
 *
Yaowu Xu's avatar
Yaowu Xu committed
331 332
 * Registers functions to be called when libaom needs a frame buffer
 * to decode the current frame and a function to be called when libaom does
clang-format's avatar
clang-format committed
333
 * not internally reference the frame buffer. This set function must
Yaowu Xu's avatar
Yaowu Xu committed
334
 * be called before the first call to decode or libaom will assume the
clang-format's avatar
clang-format committed
335 336 337 338 339 340 341
 * default behavior of allocating frame buffers internally.
 *
 * \param[in] ctx          Pointer to this instance's context
 * \param[in] cb_get       Pointer to the get callback function
 * \param[in] cb_release   Pointer to the release callback function
 * \param[in] cb_priv      Callback's private data
 *
Adrian Grange's avatar
Adrian Grange committed
342
 * \retval #AOM_CODEC_OK
Yaowu Xu's avatar
Yaowu Xu committed
343
 *     External frame buffers will be used by libaom.
Adrian Grange's avatar
Adrian Grange committed
344
 * \retval #AOM_CODEC_INVALID_PARAM
clang-format's avatar
clang-format committed
345
 *     One or more of the callbacks were NULL.
Adrian Grange's avatar
Adrian Grange committed
346
 * \retval #AOM_CODEC_ERROR
clang-format's avatar
clang-format committed
347 348 349 350
 *     Decoder context not initialized, or algorithm not capable of
 *     using external frame buffers.
 *
 * \note
Adrian Grange's avatar
Adrian Grange committed
351
 * When decoding AV1, the application may be required to pass in at least
Adrian Grange's avatar
Adrian Grange committed
352
 * #AOM_MAXIMUM_WORK_BUFFERS external frame
clang-format's avatar
clang-format committed
353 354
 * buffers.
 */
Adrian Grange's avatar
Adrian Grange committed
355 356 357
aom_codec_err_t aom_codec_set_frame_buffer_functions(
    aom_codec_ctx_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
    aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv);
358

clang-format's avatar
clang-format committed
359
/*!@} - end defgroup cap_external_frame_buffer */
360

clang-format's avatar
clang-format committed
361
/*!@} - end defgroup decoder*/
John Koleszar's avatar
John Koleszar committed
362 363 364
#ifdef __cplusplus
}
#endif
Adrian Grange's avatar
Adrian Grange committed
365
#endif  // AOM_AOM_DECODER_H_