2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
12 * \brief Provides the high level interface to wrap decoder algorithms.
17 #include "vpx/vpx_integer.h"
18 #include "vpx/internal/vpx_codec_internal.h"
19 #include "vpx_version.h"
21 #define SAVE_STATUS(ctx, var) (ctx ? (ctx->err = var) : var)
23 int vpx_codec_version(void) { return VERSION_PACKED; }
25 const char *vpx_codec_version_str(void) { return VERSION_STRING_NOSP; }
27 const char *vpx_codec_version_extra_str(void) { return VERSION_EXTRA; }
29 const char *vpx_codec_iface_name(vpx_codec_iface_t *iface) {
30 return iface ? iface->name : "<invalid interface>";
33 const char *vpx_codec_err_to_string(vpx_codec_err_t err) {
35 case VPX_CODEC_OK: return "Success";
36 case VPX_CODEC_ERROR: return "Unspecified internal error";
37 case VPX_CODEC_MEM_ERROR: return "Memory allocation error";
38 case VPX_CODEC_ABI_MISMATCH: return "ABI version mismatch";
39 case VPX_CODEC_INCAPABLE:
40 return "Codec does not implement requested capability";
41 case VPX_CODEC_UNSUP_BITSTREAM:
42 return "Bitstream not supported by this decoder";
43 case VPX_CODEC_UNSUP_FEATURE:
44 return "Bitstream required feature not supported by this decoder";
45 case VPX_CODEC_CORRUPT_FRAME: return "Corrupt frame detected";
46 case VPX_CODEC_INVALID_PARAM: return "Invalid parameter";
47 case VPX_CODEC_LIST_END: return "End of iterated list";
50 return "Unrecognized error code";
53 const char *vpx_codec_error(vpx_codec_ctx_t *ctx) {
54 return (ctx) ? vpx_codec_err_to_string(ctx->err)
55 : vpx_codec_err_to_string(VPX_CODEC_INVALID_PARAM);
58 const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx) {
60 return ctx->priv ? ctx->priv->err_detail : ctx->err_detail;
65 vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx) {
69 res = VPX_CODEC_INVALID_PARAM;
70 else if (!ctx->iface || !ctx->priv)
71 res = VPX_CODEC_ERROR;
73 ctx->iface->destroy((vpx_codec_alg_priv_t *)ctx->priv);
81 return SAVE_STATUS(ctx, res);
84 vpx_codec_caps_t vpx_codec_get_caps(vpx_codec_iface_t *iface) {
85 return (iface) ? iface->caps : 0;
88 vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx, int ctrl_id, ...) {
92 res = VPX_CODEC_INVALID_PARAM;
93 else if (!ctx->iface || !ctx->priv || !ctx->iface->ctrl_maps)
94 res = VPX_CODEC_ERROR;
96 vpx_codec_ctrl_fn_map_t *entry;
98 res = VPX_CODEC_INCAPABLE;
100 for (entry = ctx->iface->ctrl_maps; entry && entry->fn; entry++) {
101 if (!entry->ctrl_id || entry->ctrl_id == ctrl_id) {
104 va_start(ap, ctrl_id);
105 res = entry->fn((vpx_codec_alg_priv_t *)ctx->priv, ap);
112 return SAVE_STATUS(ctx, res);
115 void vpx_internal_error(struct vpx_internal_error_info *info,
116 vpx_codec_err_t error, const char *fmt, ...) {
119 info->error_code = error;
120 info->has_detail = 0;
123 size_t sz = sizeof(info->detail);
125 info->has_detail = 1;
127 vsnprintf(info->detail, sz - 1, fmt, ap);
129 info->detail[sz - 1] = '\0';
132 if (info->setjmp) longjmp(info->jmp, info->error_code);