blob: 439927940e021472c7160b9bd76b121559b66bb4 [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 */
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 Xuf883b422016-08-30 14:01:10 -070023 * aom_codec_iface_t my_codec = {
Yaowu Xuc27fc142016-08-22 16:08:15 -070024 * "My Codec v1.0",
Yaowu Xuf883b422016-08-30 14:01:10 -070025 * AOM_CODEC_ALG_ABI_VERSION,
Yaowu Xuc27fc142016-08-22 16:08:15 -070026 * ...
27 * };
28 * </pre>
29 *
30 * An application instantiates a specific decoder instance by using
Yaowu Xuf883b422016-08-30 14:01:10 -070031 * aom_codec_init() and a pointer to the algorithm's interface structure:
Yaowu Xuc27fc142016-08-22 16:08:15 -070032 * <pre>
33 * my_app.c:
Yaowu Xuf883b422016-08-30 14:01:10 -070034 * extern aom_codec_iface_t my_codec;
Yaowu Xuc27fc142016-08-22 16:08:15 -070035 * {
Yaowu Xuf883b422016-08-30 14:01:10 -070036 * aom_codec_ctx_t algo;
37 * res = aom_codec_init(&algo, &my_codec);
Yaowu Xuc27fc142016-08-22 16:08:15 -070038 * }
39 * </pre>
40 *
41 * Once initialized, the instance is manged using other functions from
Yaowu Xuf883b422016-08-30 14:01:10 -070042 * the aom_codec_* family.
Yaowu Xuc27fc142016-08-22 16:08:15 -070043 */
Yaowu Xuf883b422016-08-30 14:01:10 -070044#ifndef AOM_INTERNAL_AOM_CODEC_INTERNAL_H_
45#define AOM_INTERNAL_AOM_CODEC_INTERNAL_H_
Alex Conversef5550732016-06-08 16:14:57 -070046#include "./aom_config.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070047#include "../aom_decoder.h"
48#include "../aom_encoder.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070049#include <stdarg.h>
50
51#ifdef __cplusplus
52extern "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 Xuf883b422016-08-30 14:01:10 -070063#define AOM_CODEC_INTERNAL_ABI_VERSION (5) /**<\hideinitializer*/
Yaowu Xuc27fc142016-08-22 16:08:15 -070064
Yaowu Xuf883b422016-08-30 14:01:10 -070065typedef struct aom_codec_alg_priv aom_codec_alg_priv_t;
66typedef struct aom_codec_priv_enc_mr_cfg aom_codec_priv_enc_mr_cfg_t;
Yaowu Xuc27fc142016-08-22 16:08:15 -070067
68/*!\brief init function pointer prototype
69 *
70 * Performs algorithm-specific initialization of the decoder context. This
Yaowu Xuf883b422016-08-30 14:01:10 -070071 * function is called by the generic aom_codec_init() wrapper function, so
Yaowu Xuc27fc142016-08-22 16:08:15 -070072 * 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 Xuf883b422016-08-30 14:01:10 -070076 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -070077 * The input stream was recognized and decoder initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -070078 * \retval #AOM_CODEC_MEM_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -070079 * Memory operation failed.
80 */
Yaowu Xuf883b422016-08-30 14:01:10 -070081typedef aom_codec_err_t (*aom_codec_init_fn_t)(
82 aom_codec_ctx_t *ctx, aom_codec_priv_enc_mr_cfg_t *data);
Yaowu Xuc27fc142016-08-22 16:08:15 -070083
84/*!\brief destroy function pointer prototype
85 *
86 * Performs algorithm-specific destruction of the decoder context. This
Yaowu Xuf883b422016-08-30 14:01:10 -070087 * function is called by the generic aom_codec_destroy() wrapper function,
Yaowu Xuc27fc142016-08-22 16:08:15 -070088 * 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 Xuf883b422016-08-30 14:01:10 -070092 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -070093 * The input stream was recognized and decoder initialized.
Yaowu Xuf883b422016-08-30 14:01:10 -070094 * \retval #AOM_CODEC_MEM_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -070095 * Memory operation failed.
96 */
Yaowu Xuf883b422016-08-30 14:01:10 -070097typedef aom_codec_err_t (*aom_codec_destroy_fn_t)(aom_codec_alg_priv_t *ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -070098
99/*!\brief parse stream info function pointer prototype
100 *
101 * Performs high level parsing of the bitstream. This function is called by the
Yaowu Xuf883b422016-08-30 14:01:10 -0700102 * generic aom_codec_peek_stream_info() wrapper function, so plugins
Yaowu Xuc27fc142016-08-22 16:08:15 -0700103 * 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 Xuf883b422016-08-30 14:01:10 -0700113 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114 * Bitstream is parsable and stream information updated
115 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700116typedef aom_codec_err_t (*aom_codec_peek_si_fn_t)(const uint8_t *data,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700117 unsigned int data_sz,
Yaowu Xuf883b422016-08-30 14:01:10 -0700118 aom_codec_stream_info_t *si);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700119
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 Xuf883b422016-08-30 14:01:10 -0700130 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -0700131 * Bitstream is parsable and stream information updated
132 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700133typedef aom_codec_err_t (*aom_codec_get_si_fn_t)(aom_codec_alg_priv_t *ctx,
134 aom_codec_stream_info_t *si);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700135
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 Xuf883b422016-08-30 14:01:10 -0700142 * This function is called by the generic aom_codec_control() wrapper
Yaowu Xuc27fc142016-08-22 16:08:15 -0700143 * 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 Xuf883b422016-08-30 14:01:10 -0700155 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -0700156 * The internal state data was deserialized.
157 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700158typedef aom_codec_err_t (*aom_codec_control_fn_t)(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700159 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 Xuf883b422016-08-30 14:01:10 -0700165 * mappings. This list is searched by the aom_codec_control() wrapper
Yaowu Xuc27fc142016-08-22 16:08:15 -0700166 * 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 Xuf883b422016-08-30 14:01:10 -0700172typedef const struct aom_codec_ctrl_fn_map {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700173 int ctrl_id;
Yaowu Xuf883b422016-08-30 14:01:10 -0700174 aom_codec_control_fn_t fn;
175} aom_codec_ctrl_fn_map_t;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700176
177/*!\brief decode data function pointer prototype
178 *
179 * Processes a buffer of coded data. If the processing results in a new
Yaowu Xuf883b422016-08-30 14:01:10 -0700180 * 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 Xuc27fc142016-08-22 16:08:15 -0700183 * 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 Xuf883b422016-08-30 14:01:10 -0700188 * NULL, a #AOM_CODEC_CB_PUT_FRAME event is posted
Yaowu Xuc27fc142016-08-22 16:08:15 -0700189 * for the previously decoded frame.
190 * \param[in] data_sz Size of the coded data, in bytes.
191 *
Yaowu Xuf883b422016-08-30 14:01:10 -0700192 * \return Returns #AOM_CODEC_OK if the coded data was processed completely
Yaowu Xuc27fc142016-08-22 16:08:15 -0700193 * and future pictures can be decoded without error. Otherwise,
Yaowu Xuf883b422016-08-30 14:01:10 -0700194 * see the descriptions of the other error codes in ::aom_codec_err_t
Yaowu Xuc27fc142016-08-22 16:08:15 -0700195 * for recoverability capabilities.
196 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700197typedef aom_codec_err_t (*aom_codec_decode_fn_t)(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700198 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 Xuf883b422016-08-30 14:01:10 -0700210 * aom_codec_decode call, and remains valid until the next call to
211 * aom_codec_decode.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700212 *
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 Xuf883b422016-08-30 14:01:10 -0700219typedef aom_image_t *(*aom_codec_get_frame_fn_t)(aom_codec_alg_priv_t *ctx,
220 aom_codec_iter_t *iter);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700221
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 Xuf883b422016-08-30 14:01:10 -0700235 * \retval #AOM_CODEC_OK
Yaowu Xuc27fc142016-08-22 16:08:15 -0700236 * External frame buffers will be used by libaom.
Yaowu Xuf883b422016-08-30 14:01:10 -0700237 * \retval #AOM_CODEC_INVALID_PARAM
Yaowu Xuc27fc142016-08-22 16:08:15 -0700238 * One or more of the callbacks were NULL.
Yaowu Xuf883b422016-08-30 14:01:10 -0700239 * \retval #AOM_CODEC_ERROR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700240 * Decoder context not initialized, or algorithm not capable of
241 * using external frame buffers.
242 *
243 * \note
Yaowu Xuf883b422016-08-30 14:01:10 -0700244 * When decoding AV1, the application may be required to pass in at least
245 * #AOM_MAXIMUM_WORK_BUFFERS external frame
Yaowu Xuc27fc142016-08-22 16:08:15 -0700246 * buffers.
247 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700248typedef 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 Xuc27fc142016-08-22 16:08:15 -0700251
Yaowu Xuf883b422016-08-30 14:01:10 -0700252typedef 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 Xuc27fc142016-08-22 16:08:15 -0700255 unsigned long duration,
Yaowu Xuf883b422016-08-30 14:01:10 -0700256 aom_enc_frame_flags_t flags,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700257 unsigned long deadline);
Yaowu Xuf883b422016-08-30 14:01:10 -0700258typedef 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 Xuc27fc142016-08-22 16:08:15 -0700260
Yaowu Xuf883b422016-08-30 14:01:10 -0700261typedef 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);
263typedef aom_fixed_buf_t *(*aom_codec_get_global_headers_fn_t)(
264 aom_codec_alg_priv_t *ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700265
Yaowu Xuf883b422016-08-30 14:01:10 -0700266typedef aom_image_t *(*aom_codec_get_preview_frame_fn_t)(
267 aom_codec_alg_priv_t *ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700268
Yaowu Xuf883b422016-08-30 14:01:10 -0700269typedef 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 Xuc27fc142016-08-22 16:08:15 -0700271
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 Xuf883b422016-08-30 14:01:10 -0700276 * mappings. This list is searched by the aom_codec_enc_config_default()
Yaowu Xuc27fc142016-08-22 16:08:15 -0700277 * 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 Xuf883b422016-08-30 14:01:10 -0700282typedef const struct aom_codec_enc_cfg_map {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700283 int usage;
Yaowu Xuf883b422016-08-30 14:01:10 -0700284 aom_codec_enc_cfg_t cfg;
285} aom_codec_enc_cfg_map_t;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700286
287/*!\brief Decoder algorithm interface interface
288 *
289 * All decoders \ref MUST expose a variable of this type.
290 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700291struct aom_codec_iface {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700292 const char *name; /**< Identification String */
293 int abi_version; /**< Implemented ABI version */
Yaowu Xuf883b422016-08-30 14:01:10 -0700294 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 Xuc27fc142016-08-22 16:08:15 -0700305 } dec;
Yaowu Xuf883b422016-08-30 14:01:10 -0700306 struct aom_codec_enc_iface {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700307 int cfg_map_count;
Yaowu Xuf883b422016-08-30 14:01:10 -0700308 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 Xuc27fc142016-08-22 16:08:15 -0700321 } enc;
322};
323
324/*!\brief Callback function pointer / user data pair storage */
Yaowu Xuf883b422016-08-30 14:01:10 -0700325typedef struct aom_codec_priv_cb_pair {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700326 union {
Yaowu Xuf883b422016-08-30 14:01:10 -0700327 aom_codec_put_frame_cb_fn_t put_frame;
328 aom_codec_put_slice_cb_fn_t put_slice;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700329 } u;
330 void *user_priv;
Yaowu Xuf883b422016-08-30 14:01:10 -0700331} aom_codec_priv_cb_pair_t;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700332
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 Xuf883b422016-08-30 14:01:10 -0700341struct aom_codec_priv {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700342 const char *err_detail;
Yaowu Xuf883b422016-08-30 14:01:10 -0700343 aom_codec_flags_t init_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700344 struct {
Yaowu Xuf883b422016-08-30 14:01:10 -0700345 aom_codec_priv_cb_pair_t put_frame_cb;
346 aom_codec_priv_cb_pair_t put_slice_cb;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700347 } dec;
348 struct {
Yaowu Xuf883b422016-08-30 14:01:10 -0700349 aom_fixed_buf_t cx_data_dst_buf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700350 unsigned int cx_data_pad_before;
351 unsigned int cx_data_pad_after;
Yaowu Xuf883b422016-08-30 14:01:10 -0700352 aom_codec_cx_pkt_t cx_data_pkt;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700353 unsigned int total_encoders;
354 } enc;
355};
356
357/*
358 * Multi-resolution encoding internal configuration
359 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700360struct aom_codec_priv_enc_mr_cfg {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700361 unsigned int mr_total_resolutions;
362 unsigned int mr_encoder_id;
Yaowu Xuf883b422016-08-30 14:01:10 -0700363 struct aom_rational mr_down_sampling_factor;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700364 void *mr_low_res_mode_info;
365};
366
Yaowu Xuf883b422016-08-30 14:01:10 -0700367#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 Xuc27fc142016-08-22 16:08:15 -0700370
Yaowu Xuf883b422016-08-30 14:01:10 -0700371#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 Xuc27fc142016-08-22 16:08:15 -0700374
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 Xuf883b422016-08-30 14:01:10 -0700387 aom_codec_iface_t *id(void) { return &id##_algo; } \
388 aom_codec_iface_t id##_algo
Yaowu Xuc27fc142016-08-22 16:08:15 -0700389
390/* Internal Utility Functions
391 *
392 * The following functions are intended to be used inside algorithms as
Yaowu Xuf883b422016-08-30 14:01:10 -0700393 * utilities for manipulating aom_codec_* data structures.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700394 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700395struct aom_codec_pkt_list {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700396 unsigned int cnt;
397 unsigned int max;
Yaowu Xuf883b422016-08-30 14:01:10 -0700398 struct aom_codec_cx_pkt pkts[1];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700399};
400
Yaowu Xuf883b422016-08-30 14:01:10 -0700401#define aom_codec_pkt_list_decl(n) \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700402 union { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700403 struct aom_codec_pkt_list head; \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700404 struct { \
Yaowu Xuf883b422016-08-30 14:01:10 -0700405 struct aom_codec_pkt_list head; \
406 struct aom_codec_cx_pkt pkts[n]; \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700407 } alloc; \
408 }
409
Yaowu Xuf883b422016-08-30 14:01:10 -0700410#define aom_codec_pkt_list_init(m) \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700411 (m)->alloc.head.cnt = 0, \
412 (m)->alloc.head.max = sizeof((m)->alloc.pkts) / sizeof((m)->alloc.pkts[0])
413
Yaowu Xuf883b422016-08-30 14:01:10 -0700414int aom_codec_pkt_list_add(struct aom_codec_pkt_list *,
415 const struct aom_codec_cx_pkt *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700416
Yaowu Xuf883b422016-08-30 14:01:10 -0700417const aom_codec_cx_pkt_t *aom_codec_pkt_list_get(
418 struct aom_codec_pkt_list *list, aom_codec_iter_t *iter);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700419
420#include <stdio.h>
421#include <setjmp.h>
422
Yaowu Xuf883b422016-08-30 14:01:10 -0700423struct aom_internal_error_info {
424 aom_codec_err_t error_code;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700425 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 Xuf883b422016-08-30 14:01:10 -0700439void aom_internal_error(struct aom_internal_error_info *info,
440 aom_codec_err_t error, const char *fmt,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700441 ...) CLANG_ANALYZER_NORETURN;
442
Alex Conversef5550732016-06-08 16:14:57 -0700443#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 Xuc27fc142016-08-22 16:08:15 -0700461#ifdef __cplusplus
462} // extern "C"
463#endif
464
Yaowu Xuf883b422016-08-30 14:01:10 -0700465#endif // AOM_INTERNAL_AOM_CODEC_INTERNAL_H_