xref: /aosp_15_r20/external/libaom/aom/internal/aom_codec_internal.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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 
12*77c1e3ccSAndroid Build Coastguard Worker /*!\file
13*77c1e3ccSAndroid Build Coastguard Worker  * \brief Describes the decoder algorithm interface for algorithm
14*77c1e3ccSAndroid Build Coastguard Worker  *        implementations.
15*77c1e3ccSAndroid Build Coastguard Worker  *
16*77c1e3ccSAndroid Build Coastguard Worker  * This file defines the private structures and data types that are only
17*77c1e3ccSAndroid Build Coastguard Worker  * relevant to implementing an algorithm, as opposed to using it.
18*77c1e3ccSAndroid Build Coastguard Worker  *
19*77c1e3ccSAndroid Build Coastguard Worker  * To create a decoder algorithm class, an interface structure is put
20*77c1e3ccSAndroid Build Coastguard Worker  * into the global namespace:
21*77c1e3ccSAndroid Build Coastguard Worker  *     <pre>
22*77c1e3ccSAndroid Build Coastguard Worker  *     my_codec.c:
23*77c1e3ccSAndroid Build Coastguard Worker  *       aom_codec_iface_t my_codec = {
24*77c1e3ccSAndroid Build Coastguard Worker  *           "My Codec v1.0",
25*77c1e3ccSAndroid Build Coastguard Worker  *           AOM_CODEC_ALG_ABI_VERSION,
26*77c1e3ccSAndroid Build Coastguard Worker  *           ...
27*77c1e3ccSAndroid Build Coastguard Worker  *       };
28*77c1e3ccSAndroid Build Coastguard Worker  *     </pre>
29*77c1e3ccSAndroid Build Coastguard Worker  *
30*77c1e3ccSAndroid Build Coastguard Worker  * An application instantiates a specific decoder instance by using
31*77c1e3ccSAndroid Build Coastguard Worker  * aom_codec_dec_init() and a pointer to the algorithm's interface structure:
32*77c1e3ccSAndroid Build Coastguard Worker  *     <pre>
33*77c1e3ccSAndroid Build Coastguard Worker  *     my_app.c:
34*77c1e3ccSAndroid Build Coastguard Worker  *       extern aom_codec_iface_t my_codec;
35*77c1e3ccSAndroid Build Coastguard Worker  *       {
36*77c1e3ccSAndroid Build Coastguard Worker  *           aom_codec_ctx_t algo;
37*77c1e3ccSAndroid Build Coastguard Worker  *           int threads = 4;
38*77c1e3ccSAndroid Build Coastguard Worker  *           aom_codec_dec_cfg_t cfg = { threads, 0, 0, 1 };
39*77c1e3ccSAndroid Build Coastguard Worker  *           res = aom_codec_dec_init(&algo, &my_codec, &cfg, 0);
40*77c1e3ccSAndroid Build Coastguard Worker  *       }
41*77c1e3ccSAndroid Build Coastguard Worker  *     </pre>
42*77c1e3ccSAndroid Build Coastguard Worker  *
43*77c1e3ccSAndroid Build Coastguard Worker  * Once initialized, the instance is managed using other functions from
44*77c1e3ccSAndroid Build Coastguard Worker  * the aom_codec_* family.
45*77c1e3ccSAndroid Build Coastguard Worker  */
46*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AOM_INTERNAL_AOM_CODEC_INTERNAL_H_
47*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AOM_INTERNAL_AOM_CODEC_INTERNAL_H_
48*77c1e3ccSAndroid Build Coastguard Worker #include "../aom_decoder.h"
49*77c1e3ccSAndroid Build Coastguard Worker #include "../aom_encoder.h"
50*77c1e3ccSAndroid Build Coastguard Worker #include "common/args_helper.h"
51*77c1e3ccSAndroid Build Coastguard Worker #include <stdarg.h>
52*77c1e3ccSAndroid Build Coastguard Worker 
53*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
54*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
55*77c1e3ccSAndroid Build Coastguard Worker #endif
56*77c1e3ccSAndroid Build Coastguard Worker 
57*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Current ABI version number
58*77c1e3ccSAndroid Build Coastguard Worker  *
59*77c1e3ccSAndroid Build Coastguard Worker  * \internal
60*77c1e3ccSAndroid Build Coastguard Worker  * If this file is altered in any way that changes the ABI, this value
61*77c1e3ccSAndroid Build Coastguard Worker  * must be bumped.  Examples include, but are not limited to, changing
62*77c1e3ccSAndroid Build Coastguard Worker  * types, removing or reassigning enums, adding/removing/rearranging
63*77c1e3ccSAndroid Build Coastguard Worker  * fields to structures
64*77c1e3ccSAndroid Build Coastguard Worker  */
65*77c1e3ccSAndroid Build Coastguard Worker #define AOM_CODEC_INTERNAL_ABI_VERSION (7) /**<\hideinitializer*/
66*77c1e3ccSAndroid Build Coastguard Worker 
67*77c1e3ccSAndroid Build Coastguard Worker typedef struct aom_codec_alg_priv aom_codec_alg_priv_t;
68*77c1e3ccSAndroid Build Coastguard Worker 
69*77c1e3ccSAndroid Build Coastguard Worker /*!\brief init function pointer prototype
70*77c1e3ccSAndroid Build Coastguard Worker  *
71*77c1e3ccSAndroid Build Coastguard Worker  * Performs algorithm-specific initialization of the decoder context. This
72*77c1e3ccSAndroid Build Coastguard Worker  * function is called by aom_codec_dec_init() and aom_codec_enc_init(), so
73*77c1e3ccSAndroid Build Coastguard Worker  * plugins implementing this interface may trust the input parameters to be
74*77c1e3ccSAndroid Build Coastguard Worker  * properly initialized.
75*77c1e3ccSAndroid Build Coastguard Worker  *
76*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] ctx   Pointer to this instance's context
77*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_OK
78*77c1e3ccSAndroid Build Coastguard Worker  *     The input stream was recognized and decoder initialized.
79*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_MEM_ERROR
80*77c1e3ccSAndroid Build Coastguard Worker  *     Memory operation failed.
81*77c1e3ccSAndroid Build Coastguard Worker  */
82*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_init_fn_t)(aom_codec_ctx_t *ctx);
83*77c1e3ccSAndroid Build Coastguard Worker 
84*77c1e3ccSAndroid Build Coastguard Worker /*!\brief destroy function pointer prototype
85*77c1e3ccSAndroid Build Coastguard Worker  *
86*77c1e3ccSAndroid Build Coastguard Worker  * Performs algorithm-specific destruction of the decoder context. This
87*77c1e3ccSAndroid Build Coastguard Worker  * function is called by the generic aom_codec_destroy() wrapper function,
88*77c1e3ccSAndroid Build Coastguard Worker  * so plugins implementing this interface may trust the input parameters
89*77c1e3ccSAndroid Build Coastguard Worker  * to be properly initialized.
90*77c1e3ccSAndroid Build Coastguard Worker  *
91*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] ctx   Pointer to this instance's context
92*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_OK
93*77c1e3ccSAndroid Build Coastguard Worker  *     The input stream was recognized and decoder initialized.
94*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_MEM_ERROR
95*77c1e3ccSAndroid Build Coastguard Worker  *     Memory operation failed.
96*77c1e3ccSAndroid Build Coastguard Worker  */
97*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_destroy_fn_t)(aom_codec_alg_priv_t *ctx);
98*77c1e3ccSAndroid Build Coastguard Worker 
99*77c1e3ccSAndroid Build Coastguard Worker /*!\brief parse stream info function pointer prototype
100*77c1e3ccSAndroid Build Coastguard Worker  *
101*77c1e3ccSAndroid Build Coastguard Worker  * Performs high level parsing of the bitstream. This function is called by the
102*77c1e3ccSAndroid Build Coastguard Worker  * generic aom_codec_peek_stream_info() wrapper function, so plugins
103*77c1e3ccSAndroid Build Coastguard Worker  * implementing this interface may trust the input parameters to be properly
104*77c1e3ccSAndroid Build Coastguard Worker  * initialized.
105*77c1e3ccSAndroid Build Coastguard Worker  *
106*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]      data    Pointer to a block of data to parse
107*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]      data_sz Size of the data buffer
108*77c1e3ccSAndroid Build Coastguard Worker  * \param[in,out]  si      Pointer to stream info to update. The is_annexb
109*77c1e3ccSAndroid Build Coastguard Worker  *                         member \ref MUST be properly initialized. This
110*77c1e3ccSAndroid Build Coastguard Worker  *                         function sets the rest of the members.
111*77c1e3ccSAndroid Build Coastguard Worker  *
112*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_OK
113*77c1e3ccSAndroid Build Coastguard Worker  *     Bitstream is parsable and stream information updated
114*77c1e3ccSAndroid Build Coastguard Worker  */
115*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_peek_si_fn_t)(const uint8_t *data,
116*77c1e3ccSAndroid Build Coastguard Worker                                                   size_t data_sz,
117*77c1e3ccSAndroid Build Coastguard Worker                                                   aom_codec_stream_info_t *si);
118*77c1e3ccSAndroid Build Coastguard Worker 
119*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Return information about the current stream.
120*77c1e3ccSAndroid Build Coastguard Worker  *
121*77c1e3ccSAndroid Build Coastguard Worker  * Returns information about the stream that has been parsed during decoding.
122*77c1e3ccSAndroid Build Coastguard Worker  *
123*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]      ctx     Pointer to this instance's context
124*77c1e3ccSAndroid Build Coastguard Worker  * \param[in,out]  si      Pointer to stream info to update
125*77c1e3ccSAndroid Build Coastguard Worker  *
126*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_OK
127*77c1e3ccSAndroid Build Coastguard Worker  *     Bitstream is parsable and stream information updated
128*77c1e3ccSAndroid Build Coastguard Worker  */
129*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_get_si_fn_t)(aom_codec_alg_priv_t *ctx,
130*77c1e3ccSAndroid Build Coastguard Worker                                                  aom_codec_stream_info_t *si);
131*77c1e3ccSAndroid Build Coastguard Worker 
132*77c1e3ccSAndroid Build Coastguard Worker /*!\brief control function pointer prototype
133*77c1e3ccSAndroid Build Coastguard Worker  *
134*77c1e3ccSAndroid Build Coastguard Worker  * This function is used to exchange algorithm specific data with the decoder
135*77c1e3ccSAndroid Build Coastguard Worker  * instance. This can be used to implement features specific to a particular
136*77c1e3ccSAndroid Build Coastguard Worker  * algorithm.
137*77c1e3ccSAndroid Build Coastguard Worker  *
138*77c1e3ccSAndroid Build Coastguard Worker  * This function is called by the generic aom_codec_control() wrapper
139*77c1e3ccSAndroid Build Coastguard Worker  * function, so plugins implementing this interface may trust the input
140*77c1e3ccSAndroid Build Coastguard Worker  * parameters to be properly initialized. However,  this interface does not
141*77c1e3ccSAndroid Build Coastguard Worker  * provide type safety for the exchanged data or assign meanings to the
142*77c1e3ccSAndroid Build Coastguard Worker  * control IDs. Those details should be specified in the algorithm's
143*77c1e3ccSAndroid Build Coastguard Worker  * header file. In particular, the ctrl_id parameter is guaranteed to exist
144*77c1e3ccSAndroid Build Coastguard Worker  * in the algorithm's control mapping table, and the data parameter may be NULL.
145*77c1e3ccSAndroid Build Coastguard Worker  *
146*77c1e3ccSAndroid Build Coastguard Worker  *
147*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]     ctx              Pointer to this instance's context
148*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]     ctrl_id          Algorithm specific control identifier
149*77c1e3ccSAndroid Build Coastguard Worker  * \param[in,out] data             Data to exchange with algorithm instance.
150*77c1e3ccSAndroid Build Coastguard Worker  *
151*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_OK
152*77c1e3ccSAndroid Build Coastguard Worker  *     The internal state data was deserialized.
153*77c1e3ccSAndroid Build Coastguard Worker  */
154*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_control_fn_t)(aom_codec_alg_priv_t *ctx,
155*77c1e3ccSAndroid Build Coastguard Worker                                                   va_list ap);
156*77c1e3ccSAndroid Build Coastguard Worker 
157*77c1e3ccSAndroid Build Coastguard Worker /*!\brief codec option setter function pointer prototype
158*77c1e3ccSAndroid Build Coastguard Worker  * This function is used to set a codec option using a key (option name) & value
159*77c1e3ccSAndroid Build Coastguard Worker  * pair.
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]     name             A string of the option's name (key)
163*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]     value            A string of the value to be set to
164*77c1e3ccSAndroid Build Coastguard Worker  *
165*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_OK
166*77c1e3ccSAndroid Build Coastguard Worker  *     The option is successfully set to the value
167*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_INVALID_PARAM
168*77c1e3ccSAndroid Build Coastguard Worker  *     The data was not valid.
169*77c1e3ccSAndroid Build Coastguard Worker  */
170*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_set_option_fn_t)(aom_codec_alg_priv_t *ctx,
171*77c1e3ccSAndroid Build Coastguard Worker                                                      const char *name,
172*77c1e3ccSAndroid Build Coastguard Worker                                                      const char *value);
173*77c1e3ccSAndroid Build Coastguard Worker 
174*77c1e3ccSAndroid Build Coastguard Worker /*!\brief control function pointer mapping
175*77c1e3ccSAndroid Build Coastguard Worker  *
176*77c1e3ccSAndroid Build Coastguard Worker  * This structure stores the mapping between control identifiers and
177*77c1e3ccSAndroid Build Coastguard Worker  * implementing functions. Each algorithm provides a list of these
178*77c1e3ccSAndroid Build Coastguard Worker  * mappings. This list is searched by the aom_codec_control()
179*77c1e3ccSAndroid Build Coastguard Worker  * function to determine which function to invoke. The special
180*77c1e3ccSAndroid Build Coastguard Worker  * value defined by CTRL_MAP_END is used to indicate end-of-list, and must be
181*77c1e3ccSAndroid Build Coastguard Worker  * present. It can be tested with the at_ctrl_map_end function. Note that
182*77c1e3ccSAndroid Build Coastguard Worker  * ctrl_id values \ref MUST be non-zero.
183*77c1e3ccSAndroid Build Coastguard Worker  */
184*77c1e3ccSAndroid Build Coastguard Worker typedef const struct aom_codec_ctrl_fn_map {
185*77c1e3ccSAndroid Build Coastguard Worker   int ctrl_id;
186*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_control_fn_t fn;
187*77c1e3ccSAndroid Build Coastguard Worker } aom_codec_ctrl_fn_map_t;
188*77c1e3ccSAndroid Build Coastguard Worker 
189*77c1e3ccSAndroid Build Coastguard Worker #define CTRL_MAP_END \
190*77c1e3ccSAndroid Build Coastguard Worker   { 0, NULL }
191*77c1e3ccSAndroid Build Coastguard Worker 
at_ctrl_map_end(aom_codec_ctrl_fn_map_t * e)192*77c1e3ccSAndroid Build Coastguard Worker static inline int at_ctrl_map_end(aom_codec_ctrl_fn_map_t *e) {
193*77c1e3ccSAndroid Build Coastguard Worker   return e->ctrl_id == 0 && e->fn == NULL;
194*77c1e3ccSAndroid Build Coastguard Worker }
195*77c1e3ccSAndroid Build Coastguard Worker 
196*77c1e3ccSAndroid Build Coastguard Worker /*!\brief decode data function pointer prototype
197*77c1e3ccSAndroid Build Coastguard Worker  *
198*77c1e3ccSAndroid Build Coastguard Worker  * Processes a buffer of coded data. This function is called by the generic
199*77c1e3ccSAndroid Build Coastguard Worker  * aom_codec_decode() wrapper function, so plugins implementing this interface
200*77c1e3ccSAndroid Build Coastguard Worker  * may trust the input parameters to be properly initialized.
201*77c1e3ccSAndroid Build Coastguard Worker  *
202*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] ctx          Pointer to this instance's context
203*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] data         Pointer to this block of new coded data.
204*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] data_sz      Size of the coded data, in bytes.
205*77c1e3ccSAndroid Build Coastguard Worker  *
206*77c1e3ccSAndroid Build Coastguard Worker  * \return Returns #AOM_CODEC_OK if the coded data was processed completely
207*77c1e3ccSAndroid Build Coastguard Worker  *         and future pictures can be decoded without error. Otherwise,
208*77c1e3ccSAndroid Build Coastguard Worker  *         see the descriptions of the other error codes in ::aom_codec_err_t
209*77c1e3ccSAndroid Build Coastguard Worker  *         for recoverability capabilities.
210*77c1e3ccSAndroid Build Coastguard Worker  */
211*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_decode_fn_t)(aom_codec_alg_priv_t *ctx,
212*77c1e3ccSAndroid Build Coastguard Worker                                                  const uint8_t *data,
213*77c1e3ccSAndroid Build Coastguard Worker                                                  size_t data_sz,
214*77c1e3ccSAndroid Build Coastguard Worker                                                  void *user_priv);
215*77c1e3ccSAndroid Build Coastguard Worker 
216*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Decoded frames iterator
217*77c1e3ccSAndroid Build Coastguard Worker  *
218*77c1e3ccSAndroid Build Coastguard Worker  * Iterates over a list of the frames available for display. The iterator
219*77c1e3ccSAndroid Build Coastguard Worker  * storage should be initialized to NULL to start the iteration. Iteration is
220*77c1e3ccSAndroid Build Coastguard Worker  * complete when this function returns NULL.
221*77c1e3ccSAndroid Build Coastguard Worker  *
222*77c1e3ccSAndroid Build Coastguard Worker  * The list of available frames becomes valid upon completion of the
223*77c1e3ccSAndroid Build Coastguard Worker  * aom_codec_decode call, and remains valid until the next call to
224*77c1e3ccSAndroid Build Coastguard Worker  * aom_codec_decode.
225*77c1e3ccSAndroid Build Coastguard Worker  *
226*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]     ctx      Pointer to this instance's context
227*77c1e3ccSAndroid Build Coastguard Worker  * \param[in out] iter     Iterator storage, initialized to NULL
228*77c1e3ccSAndroid Build Coastguard Worker  *
229*77c1e3ccSAndroid Build Coastguard Worker  * \return Returns a pointer to an image, if one is ready for display. Frames
230*77c1e3ccSAndroid Build Coastguard Worker  *         produced will always be in PTS (presentation time stamp) order.
231*77c1e3ccSAndroid Build Coastguard Worker  */
232*77c1e3ccSAndroid Build Coastguard Worker typedef aom_image_t *(*aom_codec_get_frame_fn_t)(aom_codec_alg_priv_t *ctx,
233*77c1e3ccSAndroid Build Coastguard Worker                                                  aom_codec_iter_t *iter);
234*77c1e3ccSAndroid Build Coastguard Worker 
235*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Pass in external frame buffers for the decoder to use.
236*77c1e3ccSAndroid Build Coastguard Worker  *
237*77c1e3ccSAndroid Build Coastguard Worker  * Registers functions to be called when libaom needs a frame buffer
238*77c1e3ccSAndroid Build Coastguard Worker  * to decode the current frame and a function to be called when libaom does
239*77c1e3ccSAndroid Build Coastguard Worker  * not internally reference the frame buffer. This set function must
240*77c1e3ccSAndroid Build Coastguard Worker  * be called before the first call to decode or libaom will assume the
241*77c1e3ccSAndroid Build Coastguard Worker  * default behavior of allocating frame buffers internally.
242*77c1e3ccSAndroid Build Coastguard Worker  *
243*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] ctx          Pointer to this instance's context
244*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] cb_get       Pointer to the get callback function
245*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] cb_release   Pointer to the release callback function
246*77c1e3ccSAndroid Build Coastguard Worker  * \param[in] cb_priv      Callback's private data
247*77c1e3ccSAndroid Build Coastguard Worker  *
248*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_OK
249*77c1e3ccSAndroid Build Coastguard Worker  *     External frame buffers will be used by libaom.
250*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_INVALID_PARAM
251*77c1e3ccSAndroid Build Coastguard Worker  *     One or more of the callbacks were NULL.
252*77c1e3ccSAndroid Build Coastguard Worker  * \retval #AOM_CODEC_ERROR
253*77c1e3ccSAndroid Build Coastguard Worker  *     Decoder context not initialized, or algorithm not capable of
254*77c1e3ccSAndroid Build Coastguard Worker  *     using external frame buffers.
255*77c1e3ccSAndroid Build Coastguard Worker  *
256*77c1e3ccSAndroid Build Coastguard Worker  * \note
257*77c1e3ccSAndroid Build Coastguard Worker  * When decoding AV1, the application may be required to pass in at least
258*77c1e3ccSAndroid Build Coastguard Worker  * #AOM_MAXIMUM_WORK_BUFFERS external frame
259*77c1e3ccSAndroid Build Coastguard Worker  * buffers.
260*77c1e3ccSAndroid Build Coastguard Worker  */
261*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_set_fb_fn_t)(
262*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_alg_priv_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
263*77c1e3ccSAndroid Build Coastguard Worker     aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv);
264*77c1e3ccSAndroid Build Coastguard Worker 
265*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_encode_fn_t)(aom_codec_alg_priv_t *ctx,
266*77c1e3ccSAndroid Build Coastguard Worker                                                  const aom_image_t *img,
267*77c1e3ccSAndroid Build Coastguard Worker                                                  aom_codec_pts_t pts,
268*77c1e3ccSAndroid Build Coastguard Worker                                                  unsigned long duration,
269*77c1e3ccSAndroid Build Coastguard Worker                                                  aom_enc_frame_flags_t flags);
270*77c1e3ccSAndroid Build Coastguard Worker typedef const aom_codec_cx_pkt_t *(*aom_codec_get_cx_data_fn_t)(
271*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_alg_priv_t *ctx, aom_codec_iter_t *iter);
272*77c1e3ccSAndroid Build Coastguard Worker 
273*77c1e3ccSAndroid Build Coastguard Worker typedef aom_codec_err_t (*aom_codec_enc_config_set_fn_t)(
274*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_alg_priv_t *ctx, const aom_codec_enc_cfg_t *cfg);
275*77c1e3ccSAndroid Build Coastguard Worker typedef aom_fixed_buf_t *(*aom_codec_get_global_headers_fn_t)(
276*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_alg_priv_t *ctx);
277*77c1e3ccSAndroid Build Coastguard Worker 
278*77c1e3ccSAndroid Build Coastguard Worker typedef aom_image_t *(*aom_codec_get_preview_frame_fn_t)(
279*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_alg_priv_t *ctx);
280*77c1e3ccSAndroid Build Coastguard Worker 
281*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Decoder algorithm interface
282*77c1e3ccSAndroid Build Coastguard Worker  *
283*77c1e3ccSAndroid Build Coastguard Worker  * All decoders \ref MUST expose a variable of this type.
284*77c1e3ccSAndroid Build Coastguard Worker  */
285*77c1e3ccSAndroid Build Coastguard Worker struct aom_codec_iface {
286*77c1e3ccSAndroid Build Coastguard Worker   const char *name;                   /**< Identification String  */
287*77c1e3ccSAndroid Build Coastguard Worker   int abi_version;                    /**< Implemented ABI version */
288*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_caps_t caps;              /**< Decoder capabilities */
289*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_init_fn_t init;           /**< \copydoc ::aom_codec_init_fn_t */
290*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_destroy_fn_t destroy;     /**< \copydoc ::aom_codec_destroy_fn_t */
291*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_ctrl_fn_map_t *ctrl_maps; /**< \copydoc ::aom_codec_ctrl_fn_map_t */
292*77c1e3ccSAndroid Build Coastguard Worker   struct aom_codec_dec_iface {
293*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_peek_si_fn_t peek_si; /**< \copydoc ::aom_codec_peek_si_fn_t */
294*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_get_si_fn_t get_si;   /**< \copydoc ::aom_codec_get_si_fn_t */
295*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_decode_fn_t decode;   /**< \copydoc ::aom_codec_decode_fn_t */
296*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_get_frame_fn_t
297*77c1e3ccSAndroid Build Coastguard Worker         get_frame;                   /**< \copydoc ::aom_codec_get_frame_fn_t */
298*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_set_fb_fn_t set_fb_fn; /**< \copydoc ::aom_codec_set_fb_fn_t */
299*77c1e3ccSAndroid Build Coastguard Worker   } dec;
300*77c1e3ccSAndroid Build Coastguard Worker   struct aom_codec_enc_iface {
301*77c1e3ccSAndroid Build Coastguard Worker     int cfg_count;
302*77c1e3ccSAndroid Build Coastguard Worker     const aom_codec_enc_cfg_t *cfgs; /**< \copydoc ::aom_codec_enc_cfg_t */
303*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_encode_fn_t encode;    /**< \copydoc ::aom_codec_encode_fn_t */
304*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_get_cx_data_fn_t
305*77c1e3ccSAndroid Build Coastguard Worker         get_cx_data; /**< \copydoc ::aom_codec_get_cx_data_fn_t */
306*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_enc_config_set_fn_t
307*77c1e3ccSAndroid Build Coastguard Worker         cfg_set; /**< \copydoc ::aom_codec_enc_config_set_fn_t */
308*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_get_global_headers_fn_t
309*77c1e3ccSAndroid Build Coastguard Worker         get_glob_hdrs; /**< \copydoc ::aom_codec_get_global_headers_fn_t */
310*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_get_preview_frame_fn_t
311*77c1e3ccSAndroid Build Coastguard Worker         get_preview; /**< \copydoc ::aom_codec_get_preview_frame_fn_t */
312*77c1e3ccSAndroid Build Coastguard Worker   } enc;
313*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_set_option_fn_t set_option;
314*77c1e3ccSAndroid Build Coastguard Worker };
315*77c1e3ccSAndroid Build Coastguard Worker 
316*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Instance private storage
317*77c1e3ccSAndroid Build Coastguard Worker  *
318*77c1e3ccSAndroid Build Coastguard Worker  * This structure is allocated by the algorithm's init function. It can be
319*77c1e3ccSAndroid Build Coastguard Worker  * extended in one of two ways. First, a second, algorithm specific structure
320*77c1e3ccSAndroid Build Coastguard Worker  * can be allocated and the priv member pointed to it. Alternatively, this
321*77c1e3ccSAndroid Build Coastguard Worker  * structure can be made the first member of the algorithm specific structure,
322*77c1e3ccSAndroid Build Coastguard Worker  * and the pointer cast to the proper type.
323*77c1e3ccSAndroid Build Coastguard Worker  */
324*77c1e3ccSAndroid Build Coastguard Worker struct aom_codec_priv {
325*77c1e3ccSAndroid Build Coastguard Worker   const char *err_detail;
326*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_flags_t init_flags;
327*77c1e3ccSAndroid Build Coastguard Worker   struct {
328*77c1e3ccSAndroid Build Coastguard Worker     aom_fixed_buf_t cx_data_dst_buf;
329*77c1e3ccSAndroid Build Coastguard Worker     unsigned int cx_data_pad_before;
330*77c1e3ccSAndroid Build Coastguard Worker     unsigned int cx_data_pad_after;
331*77c1e3ccSAndroid Build Coastguard Worker     aom_codec_cx_pkt_t cx_data_pkt;
332*77c1e3ccSAndroid Build Coastguard Worker   } enc;
333*77c1e3ccSAndroid Build Coastguard Worker };
334*77c1e3ccSAndroid Build Coastguard Worker 
335*77c1e3ccSAndroid Build Coastguard Worker #define CAST(id, arg) va_arg((arg), aom_codec_control_type_##id)
336*77c1e3ccSAndroid Build Coastguard Worker 
337*77c1e3ccSAndroid Build Coastguard Worker /* Internal Utility Functions
338*77c1e3ccSAndroid Build Coastguard Worker  *
339*77c1e3ccSAndroid Build Coastguard Worker  * The following functions are intended to be used inside algorithms as
340*77c1e3ccSAndroid Build Coastguard Worker  * utilities for manipulating aom_codec_* data structures.
341*77c1e3ccSAndroid Build Coastguard Worker  */
342*77c1e3ccSAndroid Build Coastguard Worker struct aom_codec_pkt_list {
343*77c1e3ccSAndroid Build Coastguard Worker   unsigned int cnt;
344*77c1e3ccSAndroid Build Coastguard Worker   unsigned int max;
345*77c1e3ccSAndroid Build Coastguard Worker   struct aom_codec_cx_pkt pkts[1];
346*77c1e3ccSAndroid Build Coastguard Worker };
347*77c1e3ccSAndroid Build Coastguard Worker 
348*77c1e3ccSAndroid Build Coastguard Worker #define aom_codec_pkt_list_decl(n)     \
349*77c1e3ccSAndroid Build Coastguard Worker   union {                              \
350*77c1e3ccSAndroid Build Coastguard Worker     struct aom_codec_pkt_list head;    \
351*77c1e3ccSAndroid Build Coastguard Worker     struct {                           \
352*77c1e3ccSAndroid Build Coastguard Worker       struct aom_codec_pkt_list head;  \
353*77c1e3ccSAndroid Build Coastguard Worker       struct aom_codec_cx_pkt pkts[n]; \
354*77c1e3ccSAndroid Build Coastguard Worker     } alloc;                           \
355*77c1e3ccSAndroid Build Coastguard Worker   }
356*77c1e3ccSAndroid Build Coastguard Worker 
357*77c1e3ccSAndroid Build Coastguard Worker #define aom_codec_pkt_list_init(m) \
358*77c1e3ccSAndroid Build Coastguard Worker   (m)->alloc.head.cnt = 0,         \
359*77c1e3ccSAndroid Build Coastguard Worker   (m)->alloc.head.max = sizeof((m)->alloc.pkts) / sizeof((m)->alloc.pkts[0])
360*77c1e3ccSAndroid Build Coastguard Worker 
361*77c1e3ccSAndroid Build Coastguard Worker int aom_codec_pkt_list_add(struct aom_codec_pkt_list *,
362*77c1e3ccSAndroid Build Coastguard Worker                            const struct aom_codec_cx_pkt *);
363*77c1e3ccSAndroid Build Coastguard Worker 
364*77c1e3ccSAndroid Build Coastguard Worker const aom_codec_cx_pkt_t *aom_codec_pkt_list_get(
365*77c1e3ccSAndroid Build Coastguard Worker     struct aom_codec_pkt_list *list, aom_codec_iter_t *iter);
366*77c1e3ccSAndroid Build Coastguard Worker 
367*77c1e3ccSAndroid Build Coastguard Worker #include <stdio.h>
368*77c1e3ccSAndroid Build Coastguard Worker #include <setjmp.h>
369*77c1e3ccSAndroid Build Coastguard Worker 
370*77c1e3ccSAndroid Build Coastguard Worker struct aom_internal_error_info {
371*77c1e3ccSAndroid Build Coastguard Worker   aom_codec_err_t error_code;
372*77c1e3ccSAndroid Build Coastguard Worker   int has_detail;
373*77c1e3ccSAndroid Build Coastguard Worker   char detail[ARG_ERR_MSG_MAX_LEN];
374*77c1e3ccSAndroid Build Coastguard Worker   int setjmp;  // Boolean: whether 'jmp' is valid.
375*77c1e3ccSAndroid Build Coastguard Worker   jmp_buf jmp;
376*77c1e3ccSAndroid Build Coastguard Worker };
377*77c1e3ccSAndroid Build Coastguard Worker 
378*77c1e3ccSAndroid Build Coastguard Worker #define CLANG_ANALYZER_NORETURN
379*77c1e3ccSAndroid Build Coastguard Worker #if defined(__has_feature)
380*77c1e3ccSAndroid Build Coastguard Worker #if __has_feature(attribute_analyzer_noreturn)
381*77c1e3ccSAndroid Build Coastguard Worker #undef CLANG_ANALYZER_NORETURN
382*77c1e3ccSAndroid Build Coastguard Worker #define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
383*77c1e3ccSAndroid Build Coastguard Worker #endif
384*77c1e3ccSAndroid Build Coastguard Worker #endif
385*77c1e3ccSAndroid Build Coastguard Worker 
386*77c1e3ccSAndroid Build Coastguard Worker // Tells the compiler to perform `printf` format string checking if the
387*77c1e3ccSAndroid Build Coastguard Worker // compiler supports it; see the 'format' attribute in
388*77c1e3ccSAndroid Build Coastguard Worker // <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html>.
389*77c1e3ccSAndroid Build Coastguard Worker #define LIBAOM_FORMAT_PRINTF(string_index, first_to_check)
390*77c1e3ccSAndroid Build Coastguard Worker #if defined(__has_attribute)
391*77c1e3ccSAndroid Build Coastguard Worker #if __has_attribute(format)
392*77c1e3ccSAndroid Build Coastguard Worker #undef LIBAOM_FORMAT_PRINTF
393*77c1e3ccSAndroid Build Coastguard Worker #define LIBAOM_FORMAT_PRINTF(string_index, first_to_check) \
394*77c1e3ccSAndroid Build Coastguard Worker   __attribute__((__format__(__printf__, string_index, first_to_check)))
395*77c1e3ccSAndroid Build Coastguard Worker #endif
396*77c1e3ccSAndroid Build Coastguard Worker #endif
397*77c1e3ccSAndroid Build Coastguard Worker 
398*77c1e3ccSAndroid Build Coastguard Worker // Records the error code and error message. Does not call longjmp().
399*77c1e3ccSAndroid Build Coastguard Worker void aom_set_error(struct aom_internal_error_info *info, aom_codec_err_t error,
400*77c1e3ccSAndroid Build Coastguard Worker                    const char *fmt, ...) LIBAOM_FORMAT_PRINTF(3, 4);
401*77c1e3ccSAndroid Build Coastguard Worker 
402*77c1e3ccSAndroid Build Coastguard Worker void aom_internal_error(struct aom_internal_error_info *info,
403*77c1e3ccSAndroid Build Coastguard Worker                         aom_codec_err_t error, const char *fmt, ...)
404*77c1e3ccSAndroid Build Coastguard Worker     LIBAOM_FORMAT_PRINTF(3, 4) CLANG_ANALYZER_NORETURN;
405*77c1e3ccSAndroid Build Coastguard Worker 
406*77c1e3ccSAndroid Build Coastguard Worker // Calls aom_internal_error() with the error code and error message in `src`.
407*77c1e3ccSAndroid Build Coastguard Worker // `info` and `src` must not point to the same struct, i.e., self copy is
408*77c1e3ccSAndroid Build Coastguard Worker // prohibited.
409*77c1e3ccSAndroid Build Coastguard Worker void aom_internal_error_copy(struct aom_internal_error_info *info,
410*77c1e3ccSAndroid Build Coastguard Worker                              const struct aom_internal_error_info *src)
411*77c1e3ccSAndroid Build Coastguard Worker     CLANG_ANALYZER_NORETURN;
412*77c1e3ccSAndroid Build Coastguard Worker 
413*77c1e3ccSAndroid Build Coastguard Worker void aom_merge_corrupted_flag(int *corrupted, int value);
414*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
415*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
416*77c1e3ccSAndroid Build Coastguard Worker #endif
417*77c1e3ccSAndroid Build Coastguard Worker 
418*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AOM_INTERNAL_AOM_CODEC_INTERNAL_H_
419