1 : /*
2 : * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 : *
4 : * Use of this source code is governed by a BSD-style license
5 : * that can be found in the LICENSE file in the root of the source
6 : * tree. An additional intellectual property rights grant can be found
7 : * in the file PATENTS. All contributing project authors may
8 : * be found in the AUTHORS file in the root of the source tree.
9 : */
10 :
11 :
12 : /*!\file
13 : * \brief Provides the high level interface to wrap decoder algorithms.
14 : *
15 : */
16 : #include <stdarg.h>
17 : #include "vpx/vpx_integer.h"
18 : #include "vpx/internal/vpx_codec_internal.h"
19 : #include "vpx_version.h"
20 :
21 : #define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var)
22 :
23 0 : int vpx_codec_version(void)
24 : {
25 0 : return VERSION_PACKED;
26 : }
27 :
28 :
29 0 : const char *vpx_codec_version_str(void)
30 : {
31 0 : return VERSION_STRING_NOSP;
32 : }
33 :
34 :
35 0 : const char *vpx_codec_version_extra_str(void)
36 : {
37 0 : return VERSION_EXTRA;
38 : }
39 :
40 :
41 0 : const char *vpx_codec_iface_name(vpx_codec_iface_t *iface)
42 : {
43 0 : return iface ? iface->name : "<invalid interface>";
44 : }
45 :
46 0 : const char *vpx_codec_err_to_string(vpx_codec_err_t err)
47 : {
48 0 : switch (err)
49 : {
50 : case VPX_CODEC_OK:
51 0 : return "Success";
52 : case VPX_CODEC_ERROR:
53 0 : return "Unspecified internal error";
54 : case VPX_CODEC_MEM_ERROR:
55 0 : return "Memory allocation error";
56 : case VPX_CODEC_ABI_MISMATCH:
57 0 : return "ABI version mismatch";
58 : case VPX_CODEC_INCAPABLE:
59 0 : return "Codec does not implement requested capability";
60 : case VPX_CODEC_UNSUP_BITSTREAM:
61 0 : return "Bitstream not supported by this decoder";
62 : case VPX_CODEC_UNSUP_FEATURE:
63 0 : return "Bitstream required feature not supported by this decoder";
64 : case VPX_CODEC_CORRUPT_FRAME:
65 0 : return "Corrupt frame detected";
66 : case VPX_CODEC_INVALID_PARAM:
67 0 : return "Invalid parameter";
68 : case VPX_CODEC_LIST_END:
69 0 : return "End of iterated list";
70 : }
71 :
72 0 : return "Unrecognized error code";
73 : }
74 :
75 0 : const char *vpx_codec_error(vpx_codec_ctx_t *ctx)
76 : {
77 0 : return (ctx) ? vpx_codec_err_to_string(ctx->err)
78 0 : : vpx_codec_err_to_string(VPX_CODEC_INVALID_PARAM);
79 : }
80 :
81 0 : const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx)
82 : {
83 0 : if (ctx && ctx->err)
84 0 : return ctx->priv ? ctx->priv->err_detail : ctx->err_detail;
85 :
86 0 : return NULL;
87 : }
88 :
89 :
90 0 : vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx)
91 : {
92 : vpx_codec_err_t res;
93 :
94 0 : if (!ctx)
95 0 : res = VPX_CODEC_INVALID_PARAM;
96 0 : else if (!ctx->iface || !ctx->priv)
97 0 : res = VPX_CODEC_ERROR;
98 : else
99 : {
100 0 : if (ctx->priv->alg_priv)
101 0 : ctx->iface->destroy(ctx->priv->alg_priv);
102 :
103 0 : ctx->iface = NULL;
104 0 : ctx->name = NULL;
105 0 : ctx->priv = NULL;
106 0 : res = VPX_CODEC_OK;
107 : }
108 :
109 0 : return SAVE_STATUS(ctx, res);
110 : }
111 :
112 :
113 0 : vpx_codec_caps_t vpx_codec_get_caps(vpx_codec_iface_t *iface)
114 : {
115 0 : return (iface) ? iface->caps : 0;
116 : }
117 :
118 :
119 0 : vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx,
120 : int ctrl_id,
121 : ...)
122 : {
123 : vpx_codec_err_t res;
124 :
125 0 : if (!ctx || !ctrl_id)
126 0 : res = VPX_CODEC_INVALID_PARAM;
127 0 : else if (!ctx->iface || !ctx->priv || !ctx->iface->ctrl_maps)
128 0 : res = VPX_CODEC_ERROR;
129 : else
130 : {
131 : vpx_codec_ctrl_fn_map_t *entry;
132 :
133 0 : res = VPX_CODEC_ERROR;
134 :
135 0 : for (entry = ctx->iface->ctrl_maps; entry && entry->fn; entry++)
136 : {
137 0 : if (!entry->ctrl_id || entry->ctrl_id == ctrl_id)
138 : {
139 : va_list ap;
140 :
141 0 : va_start(ap, ctrl_id);
142 0 : res = entry->fn(ctx->priv->alg_priv, ctrl_id, ap);
143 0 : va_end(ap);
144 0 : break;
145 : }
146 : }
147 : }
148 :
149 0 : return SAVE_STATUS(ctx, res);
150 : }
|