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