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