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