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