Coverage Report

Created: 2026-06-15 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/aom/aom/src/aom_codec.c
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 Provides the high level interface to wrap decoder algorithms.
14
 *
15
 */
16
#include <stdarg.h>
17
#include <stdlib.h>
18
19
#include "config/aom_config.h"
20
#include "config/aom_version.h"
21
22
#include "aom/aom_integer.h"
23
#include "aom/internal/aom_codec_internal.h"
24
25
1.58k
int aom_codec_version(void) { return VERSION_PACKED; }
26
27
0
const char *aom_codec_version_str(void) { return VERSION_STRING_NOSP; }
28
29
0
const char *aom_codec_version_extra_str(void) { return VERSION_EXTRA; }
30
31
0
const char *aom_codec_iface_name(aom_codec_iface_t *iface) {
32
0
  return iface ? iface->name : "<invalid interface>";
33
0
}
34
35
0
const char *aom_codec_err_to_string(aom_codec_err_t err) {
36
0
  switch (err) {
37
0
    case AOM_CODEC_OK: return "Success";
38
0
    case AOM_CODEC_ERROR: return "Unspecified internal error";
39
0
    case AOM_CODEC_MEM_ERROR: return "Memory allocation error";
40
0
    case AOM_CODEC_ABI_MISMATCH: return "ABI version mismatch";
41
0
    case AOM_CODEC_INCAPABLE:
42
0
      return "Codec does not implement requested capability";
43
0
    case AOM_CODEC_UNSUP_BITSTREAM:
44
0
      return "Bitstream not supported by this decoder";
45
0
    case AOM_CODEC_UNSUP_FEATURE:
46
0
      return "Bitstream required feature not supported by this decoder";
47
0
    case AOM_CODEC_CORRUPT_FRAME: return "Corrupt frame detected";
48
0
    case AOM_CODEC_INVALID_PARAM: return "Invalid parameter";
49
0
    case AOM_CODEC_LIST_END: return "End of iterated list";
50
0
  }
51
52
0
  return "Unrecognized error code";
53
0
}
54
55
0
const char *aom_codec_error(aom_codec_ctx_t *ctx) {
56
0
  return (ctx) ? aom_codec_err_to_string(ctx->err)
57
0
               : aom_codec_err_to_string(AOM_CODEC_INVALID_PARAM);
58
0
}
59
60
0
const char *aom_codec_error_detail(aom_codec_ctx_t *ctx) {
61
0
  if (ctx && ctx->err)
62
0
    return ctx->priv ? ctx->priv->err_detail : ctx->err_detail;
63
64
0
  return NULL;
65
0
}
66
67
1.57k
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx) {
68
1.57k
  if (!ctx) {
69
0
    return AOM_CODEC_INVALID_PARAM;
70
0
  }
71
1.57k
  if (!ctx->iface || !ctx->priv) {
72
793
    ctx->err = AOM_CODEC_ERROR;
73
793
    return AOM_CODEC_ERROR;
74
793
  }
75
786
  ctx->iface->destroy((aom_codec_alg_priv_t *)ctx->priv);
76
786
  ctx->iface = NULL;
77
786
  ctx->name = NULL;
78
786
  ctx->priv = NULL;
79
786
  ctx->err = AOM_CODEC_OK;
80
786
  return AOM_CODEC_OK;
81
1.57k
}
82
83
0
aom_codec_caps_t aom_codec_get_caps(aom_codec_iface_t *iface) {
84
0
  return (iface) ? iface->caps : 0;
85
0
}
86
87
5.71k
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id, ...) {
88
5.71k
  if (!ctx) {
89
0
    return AOM_CODEC_INVALID_PARAM;
90
0
  }
91
  // Control ID must be non-zero.
92
5.71k
  if (!ctrl_id) {
93
0
    ctx->err = AOM_CODEC_INVALID_PARAM;
94
0
    return AOM_CODEC_INVALID_PARAM;
95
0
  }
96
5.71k
  if (!ctx->iface || !ctx->priv || !ctx->iface->ctrl_maps) {
97
0
    ctx->err = AOM_CODEC_ERROR;
98
0
    return AOM_CODEC_ERROR;
99
0
  }
100
101
  // "ctrl_maps" is an array of (control ID, function pointer) elements,
102
  // with CTRL_MAP_END as a sentinel.
103
5.71k
  for (aom_codec_ctrl_fn_map_t *entry = ctx->iface->ctrl_maps;
104
279k
       !at_ctrl_map_end(entry); ++entry) {
105
279k
    if (entry->ctrl_id == ctrl_id) {
106
5.71k
      va_list ap;
107
5.71k
      va_start(ap, ctrl_id);
108
5.71k
      ctx->err = entry->fn((aom_codec_alg_priv_t *)ctx->priv, ap);
109
5.71k
      va_end(ap);
110
5.71k
      return ctx->err;
111
5.71k
    }
112
279k
  }
113
0
  ctx->err = AOM_CODEC_ERROR;
114
0
  return AOM_CODEC_ERROR;
115
5.71k
}
116
117
aom_codec_err_t aom_codec_set_option(aom_codec_ctx_t *ctx, const char *name,
118
0
                                     const char *value) {
119
0
  if (!ctx) {
120
0
    return AOM_CODEC_INVALID_PARAM;
121
0
  }
122
0
  if (!ctx->iface || !ctx->priv || !ctx->iface->set_option) {
123
0
    ctx->err = AOM_CODEC_ERROR;
124
0
    return AOM_CODEC_ERROR;
125
0
  }
126
0
  ctx->err =
127
0
      ctx->iface->set_option((aom_codec_alg_priv_t *)ctx->priv, name, value);
128
0
  return ctx->err;
129
0
}
130
131
void aom_internal_error(struct aom_internal_error_info *info,
132
0
                        aom_codec_err_t error, const char *fmt, ...) {
133
0
  va_list ap;
134
135
0
  info->error_code = error;
136
0
  info->has_detail = 0;
137
138
0
  if (fmt) {
139
0
    size_t sz = sizeof(info->detail);
140
141
0
    info->has_detail = 1;
142
0
    va_start(ap, fmt);
143
0
    vsnprintf(info->detail, sz - 1, fmt, ap);
144
0
    va_end(ap);
145
0
    info->detail[sz - 1] = '\0';
146
0
  }
147
148
0
  if (info->setjmp) longjmp(info->jmp, info->error_code);
149
0
}
150
151
0
void aom_merge_corrupted_flag(int *corrupted, int value) {
152
0
  *corrupted |= value;
153
0
}
154
155
0
const char *aom_obu_type_to_string(OBU_TYPE type) {
156
0
  switch (type) {
157
0
    case OBU_SEQUENCE_HEADER: return "OBU_SEQUENCE_HEADER";
158
0
    case OBU_TEMPORAL_DELIMITER: return "OBU_TEMPORAL_DELIMITER";
159
0
    case OBU_FRAME_HEADER: return "OBU_FRAME_HEADER";
160
0
    case OBU_REDUNDANT_FRAME_HEADER: return "OBU_REDUNDANT_FRAME_HEADER";
161
0
    case OBU_FRAME: return "OBU_FRAME";
162
0
    case OBU_TILE_GROUP: return "OBU_TILE_GROUP";
163
0
    case OBU_METADATA: return "OBU_METADATA";
164
0
    case OBU_TILE_LIST: return "OBU_TILE_LIST";
165
0
    case OBU_PADDING: return "OBU_PADDING";
166
0
    default: break;
167
0
  }
168
0
  return "<Invalid OBU Type>";
169
0
}