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