Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /*!\file |
| 13 | * \brief Describes the decoder algorithm interface for algorithm |
| 14 | * implementations. |
| 15 | * |
| 16 | * This file defines the private structures and data types that are only |
| 17 | * relevant to implementing an algorithm, as opposed to using it. |
| 18 | * |
| 19 | * To create a decoder algorithm class, an interface structure is put |
| 20 | * into the global namespace: |
| 21 | * <pre> |
| 22 | * my_codec.c: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 23 | * aom_codec_iface_t my_codec = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | * "My Codec v1.0", |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 25 | * AOM_CODEC_ALG_ABI_VERSION, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 26 | * ... |
| 27 | * }; |
| 28 | * </pre> |
| 29 | * |
| 30 | * An application instantiates a specific decoder instance by using |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 31 | * aom_codec_init() and a pointer to the algorithm's interface structure: |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 32 | * <pre> |
| 33 | * my_app.c: |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 34 | * extern aom_codec_iface_t my_codec; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 35 | * { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 36 | * aom_codec_ctx_t algo; |
| 37 | * res = aom_codec_init(&algo, &my_codec); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | * } |
| 39 | * </pre> |
| 40 | * |
| 41 | * Once initialized, the instance is manged using other functions from |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 42 | * the aom_codec_* family. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 44 | #ifndef AOM_INTERNAL_AOM_CODEC_INTERNAL_H_ |
| 45 | #define AOM_INTERNAL_AOM_CODEC_INTERNAL_H_ |
Alex Converse | f555073 | 2016-06-08 16:14:57 -0700 | [diff] [blame] | 46 | #include "./aom_config.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 47 | #include "../aom_decoder.h" |
| 48 | #include "../aom_encoder.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 49 | #include <stdarg.h> |
| 50 | |
| 51 | #ifdef __cplusplus |
| 52 | extern "C" { |
| 53 | #endif |
| 54 | |
| 55 | /*!\brief Current ABI version number |
| 56 | * |
| 57 | * \internal |
| 58 | * If this file is altered in any way that changes the ABI, this value |
| 59 | * must be bumped. Examples include, but are not limited to, changing |
| 60 | * types, removing or reassigning enums, adding/removing/rearranging |
| 61 | * fields to structures |
| 62 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 63 | #define AOM_CODEC_INTERNAL_ABI_VERSION (5) /**<\hideinitializer*/ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 65 | typedef struct aom_codec_alg_priv aom_codec_alg_priv_t; |
| 66 | typedef struct aom_codec_priv_enc_mr_cfg aom_codec_priv_enc_mr_cfg_t; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 67 | |
| 68 | /*!\brief init function pointer prototype |
| 69 | * |
| 70 | * Performs algorithm-specific initialization of the decoder context. This |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | * function is called by the generic aom_codec_init() wrapper function, so |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | * plugins implementing this interface may trust the input parameters to be |
| 73 | * properly initialized. |
| 74 | * |
| 75 | * \param[in] ctx Pointer to this instance's context |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 76 | * \retval #AOM_CODEC_OK |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | * The input stream was recognized and decoder initialized. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 78 | * \retval #AOM_CODEC_MEM_ERROR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | * Memory operation failed. |
| 80 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 81 | typedef aom_codec_err_t (*aom_codec_init_fn_t)( |
| 82 | aom_codec_ctx_t *ctx, aom_codec_priv_enc_mr_cfg_t *data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 83 | |
| 84 | /*!\brief destroy function pointer prototype |
| 85 | * |
| 86 | * Performs algorithm-specific destruction of the decoder context. This |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 87 | * function is called by the generic aom_codec_destroy() wrapper function, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 88 | * so plugins implementing this interface may trust the input parameters |
| 89 | * to be properly initialized. |
| 90 | * |
| 91 | * \param[in] ctx Pointer to this instance's context |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 92 | * \retval #AOM_CODEC_OK |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 93 | * The input stream was recognized and decoder initialized. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 94 | * \retval #AOM_CODEC_MEM_ERROR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 95 | * Memory operation failed. |
| 96 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 97 | typedef aom_codec_err_t (*aom_codec_destroy_fn_t)(aom_codec_alg_priv_t *ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 98 | |
| 99 | /*!\brief parse stream info function pointer prototype |
| 100 | * |
| 101 | * Performs high level parsing of the bitstream. This function is called by the |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 102 | * generic aom_codec_peek_stream_info() wrapper function, so plugins |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 103 | * implementing this interface may trust the input parameters to be properly |
| 104 | * initialized. |
| 105 | * |
| 106 | * \param[in] data Pointer to a block of data to parse |
| 107 | * \param[in] data_sz Size of the data buffer |
| 108 | * \param[in,out] si Pointer to stream info to update. The size member |
| 109 | * \ref MUST be properly initialized, but \ref MAY be |
| 110 | * clobbered by the algorithm. This parameter \ref MAY |
| 111 | * be NULL. |
| 112 | * |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | * \retval #AOM_CODEC_OK |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 114 | * Bitstream is parsable and stream information updated |
| 115 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 116 | typedef aom_codec_err_t (*aom_codec_peek_si_fn_t)(const uint8_t *data, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 117 | unsigned int data_sz, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 118 | aom_codec_stream_info_t *si); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 119 | |
| 120 | /*!\brief Return information about the current stream. |
| 121 | * |
| 122 | * Returns information about the stream that has been parsed during decoding. |
| 123 | * |
| 124 | * \param[in] ctx Pointer to this instance's context |
| 125 | * \param[in,out] si Pointer to stream info to update. The size member |
| 126 | * \ref MUST be properly initialized, but \ref MAY be |
| 127 | * clobbered by the algorithm. This parameter \ref MAY |
| 128 | * be NULL. |
| 129 | * |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 130 | * \retval #AOM_CODEC_OK |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 131 | * Bitstream is parsable and stream information updated |
| 132 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 133 | typedef aom_codec_err_t (*aom_codec_get_si_fn_t)(aom_codec_alg_priv_t *ctx, |
| 134 | aom_codec_stream_info_t *si); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 135 | |
| 136 | /*!\brief control function pointer prototype |
| 137 | * |
| 138 | * This function is used to exchange algorithm specific data with the decoder |
| 139 | * instance. This can be used to implement features specific to a particular |
| 140 | * algorithm. |
| 141 | * |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 142 | * This function is called by the generic aom_codec_control() wrapper |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 143 | * function, so plugins implementing this interface may trust the input |
| 144 | * parameters to be properly initialized. However, this interface does not |
| 145 | * provide type safety for the exchanged data or assign meanings to the |
| 146 | * control codes. Those details should be specified in the algorithm's |
| 147 | * header file. In particular, the ctrl_id parameter is guaranteed to exist |
| 148 | * in the algorithm's control mapping table, and the data parameter may be NULL. |
| 149 | * |
| 150 | * |
| 151 | * \param[in] ctx Pointer to this instance's context |
| 152 | * \param[in] ctrl_id Algorithm specific control identifier |
| 153 | * \param[in,out] data Data to exchange with algorithm instance. |
| 154 | * |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 155 | * \retval #AOM_CODEC_OK |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 156 | * The internal state data was deserialized. |
| 157 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 158 | typedef aom_codec_err_t (*aom_codec_control_fn_t)(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 159 | va_list ap); |
| 160 | |
| 161 | /*!\brief control function pointer mapping |
| 162 | * |
| 163 | * This structure stores the mapping between control identifiers and |
| 164 | * implementing functions. Each algorithm provides a list of these |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 165 | * mappings. This list is searched by the aom_codec_control() wrapper |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 166 | * function to determine which function to invoke. The special |
| 167 | * value {0, NULL} is used to indicate end-of-list, and must be |
| 168 | * present. The special value {0, <non-null>} can be used as a catch-all |
| 169 | * mapping. This implies that ctrl_id values chosen by the algorithm |
| 170 | * \ref MUST be non-zero. |
| 171 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 172 | typedef const struct aom_codec_ctrl_fn_map { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 173 | int ctrl_id; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 174 | aom_codec_control_fn_t fn; |
| 175 | } aom_codec_ctrl_fn_map_t; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 176 | |
| 177 | /*!\brief decode data function pointer prototype |
| 178 | * |
| 179 | * Processes a buffer of coded data. If the processing results in a new |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 180 | * decoded frame becoming available, #AOM_CODEC_CB_PUT_SLICE and |
| 181 | * #AOM_CODEC_CB_PUT_FRAME events are generated as appropriate. This |
| 182 | * function is called by the generic aom_codec_decode() wrapper function, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 183 | * so plugins implementing this interface may trust the input parameters |
| 184 | * to be properly initialized. |
| 185 | * |
| 186 | * \param[in] ctx Pointer to this instance's context |
| 187 | * \param[in] data Pointer to this block of new coded data. If |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 188 | * NULL, a #AOM_CODEC_CB_PUT_FRAME event is posted |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 189 | * for the previously decoded frame. |
| 190 | * \param[in] data_sz Size of the coded data, in bytes. |
| 191 | * |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 192 | * \return Returns #AOM_CODEC_OK if the coded data was processed completely |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 193 | * and future pictures can be decoded without error. Otherwise, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 194 | * see the descriptions of the other error codes in ::aom_codec_err_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 195 | * for recoverability capabilities. |
| 196 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 197 | typedef aom_codec_err_t (*aom_codec_decode_fn_t)(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 198 | const uint8_t *data, |
| 199 | unsigned int data_sz, |
| 200 | void *user_priv, |
| 201 | long deadline); |
| 202 | |
| 203 | /*!\brief Decoded frames iterator |
| 204 | * |
| 205 | * Iterates over a list of the frames available for display. The iterator |
| 206 | * storage should be initialized to NULL to start the iteration. Iteration is |
| 207 | * complete when this function returns NULL. |
| 208 | * |
| 209 | * The list of available frames becomes valid upon completion of the |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 210 | * aom_codec_decode call, and remains valid until the next call to |
| 211 | * aom_codec_decode. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 212 | * |
| 213 | * \param[in] ctx Pointer to this instance's context |
| 214 | * \param[in out] iter Iterator storage, initialized to NULL |
| 215 | * |
| 216 | * \return Returns a pointer to an image, if one is ready for display. Frames |
| 217 | * produced will always be in PTS (presentation time stamp) order. |
| 218 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 219 | typedef aom_image_t *(*aom_codec_get_frame_fn_t)(aom_codec_alg_priv_t *ctx, |
| 220 | aom_codec_iter_t *iter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 221 | |
| 222 | /*!\brief Pass in external frame buffers for the decoder to use. |
| 223 | * |
| 224 | * Registers functions to be called when libaom needs a frame buffer |
| 225 | * to decode the current frame and a function to be called when libaom does |
| 226 | * not internally reference the frame buffer. This set function must |
| 227 | * be called before the first call to decode or libaom will assume the |
| 228 | * default behavior of allocating frame buffers internally. |
| 229 | * |
| 230 | * \param[in] ctx Pointer to this instance's context |
| 231 | * \param[in] cb_get Pointer to the get callback function |
| 232 | * \param[in] cb_release Pointer to the release callback function |
| 233 | * \param[in] cb_priv Callback's private data |
| 234 | * |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 235 | * \retval #AOM_CODEC_OK |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 236 | * External frame buffers will be used by libaom. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 237 | * \retval #AOM_CODEC_INVALID_PARAM |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 238 | * One or more of the callbacks were NULL. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 239 | * \retval #AOM_CODEC_ERROR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 240 | * Decoder context not initialized, or algorithm not capable of |
| 241 | * using external frame buffers. |
| 242 | * |
| 243 | * \note |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 244 | * When decoding AV1, the application may be required to pass in at least |
| 245 | * #AOM_MAXIMUM_WORK_BUFFERS external frame |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 246 | * buffers. |
| 247 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 248 | typedef aom_codec_err_t (*aom_codec_set_fb_fn_t)( |
| 249 | aom_codec_alg_priv_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get, |
| 250 | aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 251 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 252 | typedef aom_codec_err_t (*aom_codec_encode_fn_t)(aom_codec_alg_priv_t *ctx, |
| 253 | const aom_image_t *img, |
| 254 | aom_codec_pts_t pts, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 255 | unsigned long duration, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 256 | aom_enc_frame_flags_t flags, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 257 | unsigned long deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 258 | typedef const aom_codec_cx_pkt_t *(*aom_codec_get_cx_data_fn_t)( |
| 259 | aom_codec_alg_priv_t *ctx, aom_codec_iter_t *iter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 260 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 261 | typedef aom_codec_err_t (*aom_codec_enc_config_set_fn_t)( |
| 262 | aom_codec_alg_priv_t *ctx, const aom_codec_enc_cfg_t *cfg); |
| 263 | typedef aom_fixed_buf_t *(*aom_codec_get_global_headers_fn_t)( |
| 264 | aom_codec_alg_priv_t *ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 265 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 266 | typedef aom_image_t *(*aom_codec_get_preview_frame_fn_t)( |
| 267 | aom_codec_alg_priv_t *ctx); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 268 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 269 | typedef aom_codec_err_t (*aom_codec_enc_mr_get_mem_loc_fn_t)( |
| 270 | const aom_codec_enc_cfg_t *cfg, void **mem_loc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 271 | |
| 272 | /*!\brief usage configuration mapping |
| 273 | * |
| 274 | * This structure stores the mapping between usage identifiers and |
| 275 | * configuration structures. Each algorithm provides a list of these |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 276 | * mappings. This list is searched by the aom_codec_enc_config_default() |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 277 | * wrapper function to determine which config to return. The special value |
| 278 | * {-1, {0}} is used to indicate end-of-list, and must be present. At least |
| 279 | * one mapping must be present, in addition to the end-of-list. |
| 280 | * |
| 281 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 282 | typedef const struct aom_codec_enc_cfg_map { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 283 | int usage; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 284 | aom_codec_enc_cfg_t cfg; |
| 285 | } aom_codec_enc_cfg_map_t; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 286 | |
| 287 | /*!\brief Decoder algorithm interface interface |
| 288 | * |
| 289 | * All decoders \ref MUST expose a variable of this type. |
| 290 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 291 | struct aom_codec_iface { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 292 | const char *name; /**< Identification String */ |
| 293 | int abi_version; /**< Implemented ABI version */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 294 | aom_codec_caps_t caps; /**< Decoder capabilities */ |
| 295 | aom_codec_init_fn_t init; /**< \copydoc ::aom_codec_init_fn_t */ |
| 296 | aom_codec_destroy_fn_t destroy; /**< \copydoc ::aom_codec_destroy_fn_t */ |
| 297 | aom_codec_ctrl_fn_map_t *ctrl_maps; /**< \copydoc ::aom_codec_ctrl_fn_map_t */ |
| 298 | struct aom_codec_dec_iface { |
| 299 | aom_codec_peek_si_fn_t peek_si; /**< \copydoc ::aom_codec_peek_si_fn_t */ |
| 300 | aom_codec_get_si_fn_t get_si; /**< \copydoc ::aom_codec_get_si_fn_t */ |
| 301 | aom_codec_decode_fn_t decode; /**< \copydoc ::aom_codec_decode_fn_t */ |
| 302 | aom_codec_get_frame_fn_t |
| 303 | get_frame; /**< \copydoc ::aom_codec_get_frame_fn_t */ |
| 304 | aom_codec_set_fb_fn_t set_fb_fn; /**< \copydoc ::aom_codec_set_fb_fn_t */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 305 | } dec; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 306 | struct aom_codec_enc_iface { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 307 | int cfg_map_count; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 308 | aom_codec_enc_cfg_map_t |
| 309 | *cfg_maps; /**< \copydoc ::aom_codec_enc_cfg_map_t */ |
| 310 | aom_codec_encode_fn_t encode; /**< \copydoc ::aom_codec_encode_fn_t */ |
| 311 | aom_codec_get_cx_data_fn_t |
| 312 | get_cx_data; /**< \copydoc ::aom_codec_get_cx_data_fn_t */ |
| 313 | aom_codec_enc_config_set_fn_t |
| 314 | cfg_set; /**< \copydoc ::aom_codec_enc_config_set_fn_t */ |
| 315 | aom_codec_get_global_headers_fn_t |
| 316 | get_glob_hdrs; /**< \copydoc ::aom_codec_get_global_headers_fn_t */ |
| 317 | aom_codec_get_preview_frame_fn_t |
| 318 | get_preview; /**< \copydoc ::aom_codec_get_preview_frame_fn_t */ |
| 319 | aom_codec_enc_mr_get_mem_loc_fn_t |
| 320 | mr_get_mem_loc; /**< \copydoc ::aom_codec_enc_mr_get_mem_loc_fn_t */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 321 | } enc; |
| 322 | }; |
| 323 | |
| 324 | /*!\brief Callback function pointer / user data pair storage */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 325 | typedef struct aom_codec_priv_cb_pair { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 326 | union { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 327 | aom_codec_put_frame_cb_fn_t put_frame; |
| 328 | aom_codec_put_slice_cb_fn_t put_slice; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 329 | } u; |
| 330 | void *user_priv; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 331 | } aom_codec_priv_cb_pair_t; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 332 | |
| 333 | /*!\brief Instance private storage |
| 334 | * |
| 335 | * This structure is allocated by the algorithm's init function. It can be |
| 336 | * extended in one of two ways. First, a second, algorithm specific structure |
| 337 | * can be allocated and the priv member pointed to it. Alternatively, this |
| 338 | * structure can be made the first member of the algorithm specific structure, |
| 339 | * and the pointer cast to the proper type. |
| 340 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 341 | struct aom_codec_priv { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 342 | const char *err_detail; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 343 | aom_codec_flags_t init_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 344 | struct { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 345 | aom_codec_priv_cb_pair_t put_frame_cb; |
| 346 | aom_codec_priv_cb_pair_t put_slice_cb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 347 | } dec; |
| 348 | struct { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 349 | aom_fixed_buf_t cx_data_dst_buf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 350 | unsigned int cx_data_pad_before; |
| 351 | unsigned int cx_data_pad_after; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 352 | aom_codec_cx_pkt_t cx_data_pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 353 | unsigned int total_encoders; |
| 354 | } enc; |
| 355 | }; |
| 356 | |
| 357 | /* |
| 358 | * Multi-resolution encoding internal configuration |
| 359 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 360 | struct aom_codec_priv_enc_mr_cfg { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 361 | unsigned int mr_total_resolutions; |
| 362 | unsigned int mr_encoder_id; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 363 | struct aom_rational mr_down_sampling_factor; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 364 | void *mr_low_res_mode_info; |
| 365 | }; |
| 366 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 367 | #undef AOM_CTRL_USE_TYPE |
| 368 | #define AOM_CTRL_USE_TYPE(id, typ) \ |
| 369 | static AOM_INLINE typ id##__value(va_list args) { return va_arg(args, typ); } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 370 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 371 | #undef AOM_CTRL_USE_TYPE_DEPRECATED |
| 372 | #define AOM_CTRL_USE_TYPE_DEPRECATED(id, typ) \ |
| 373 | static AOM_INLINE typ id##__value(va_list args) { return va_arg(args, typ); } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 374 | |
| 375 | #define CAST(id, arg) id##__value(arg) |
| 376 | |
| 377 | /* CODEC_INTERFACE convenience macro |
| 378 | * |
| 379 | * By convention, each codec interface is a struct with extern linkage, where |
| 380 | * the symbol is suffixed with _algo. A getter function is also defined to |
| 381 | * return a pointer to the struct, since in some cases it's easier to work |
| 382 | * with text symbols than data symbols (see issue #169). This function has |
| 383 | * the same name as the struct, less the _algo suffix. The CODEC_INTERFACE |
| 384 | * macro is provided to define this getter function automatically. |
| 385 | */ |
| 386 | #define CODEC_INTERFACE(id) \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 387 | aom_codec_iface_t *id(void) { return &id##_algo; } \ |
| 388 | aom_codec_iface_t id##_algo |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 389 | |
| 390 | /* Internal Utility Functions |
| 391 | * |
| 392 | * The following functions are intended to be used inside algorithms as |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 393 | * utilities for manipulating aom_codec_* data structures. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 394 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 395 | struct aom_codec_pkt_list { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 396 | unsigned int cnt; |
| 397 | unsigned int max; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 398 | struct aom_codec_cx_pkt pkts[1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 399 | }; |
| 400 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 401 | #define aom_codec_pkt_list_decl(n) \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 402 | union { \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 403 | struct aom_codec_pkt_list head; \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 404 | struct { \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 405 | struct aom_codec_pkt_list head; \ |
| 406 | struct aom_codec_cx_pkt pkts[n]; \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 407 | } alloc; \ |
| 408 | } |
| 409 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 410 | #define aom_codec_pkt_list_init(m) \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 411 | (m)->alloc.head.cnt = 0, \ |
| 412 | (m)->alloc.head.max = sizeof((m)->alloc.pkts) / sizeof((m)->alloc.pkts[0]) |
| 413 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 414 | int aom_codec_pkt_list_add(struct aom_codec_pkt_list *, |
| 415 | const struct aom_codec_cx_pkt *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 416 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 417 | const aom_codec_cx_pkt_t *aom_codec_pkt_list_get( |
| 418 | struct aom_codec_pkt_list *list, aom_codec_iter_t *iter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 419 | |
| 420 | #include <stdio.h> |
| 421 | #include <setjmp.h> |
| 422 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 423 | struct aom_internal_error_info { |
| 424 | aom_codec_err_t error_code; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 425 | int has_detail; |
| 426 | char detail[80]; |
| 427 | int setjmp; |
| 428 | jmp_buf jmp; |
| 429 | }; |
| 430 | |
| 431 | #define CLANG_ANALYZER_NORETURN |
| 432 | #if defined(__has_feature) |
| 433 | #if __has_feature(attribute_analyzer_noreturn) |
| 434 | #undef CLANG_ANALYZER_NORETURN |
| 435 | #define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) |
| 436 | #endif |
| 437 | #endif |
| 438 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 439 | void aom_internal_error(struct aom_internal_error_info *info, |
| 440 | aom_codec_err_t error, const char *fmt, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 441 | ...) CLANG_ANALYZER_NORETURN; |
| 442 | |
Alex Converse | f555073 | 2016-06-08 16:14:57 -0700 | [diff] [blame] | 443 | #if CONFIG_DEBUG |
| 444 | #define AOM_CHECK_MEM_ERROR(error_info, lval, expr) \ |
| 445 | do { \ |
| 446 | lval = (expr); \ |
| 447 | if (!lval) \ |
| 448 | aom_internal_error(error_info, AOM_CODEC_MEM_ERROR, \ |
| 449 | "Failed to allocate " #lval " at %s:%d", __FILE__, \ |
| 450 | __LINE__); \ |
| 451 | } while (0) |
| 452 | #else |
| 453 | #define AOM_CHECK_MEM_ERROR(error_info, lval, expr) \ |
| 454 | do { \ |
| 455 | lval = (expr); \ |
| 456 | if (!lval) \ |
| 457 | aom_internal_error(error_info, AOM_CODEC_MEM_ERROR, \ |
| 458 | "Failed to allocate " #lval); \ |
| 459 | } while (0) |
| 460 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 461 | #ifdef __cplusplus |
| 462 | } // extern "C" |
| 463 | #endif |
| 464 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 465 | #endif // AOM_INTERNAL_AOM_CODEC_INTERNAL_H_ |