Coverage Report

Created: 2026-03-31 06:59

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