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 /*!\file 12 * \brief Provides the high level interface to wrap decoder algorithms. 13 * 14 */ 15 16 #define INLINE __inline 17 18 #if 0 19 #define SAVE_STATUS(ctx, var) (ctx ? (ctx->err = var) : var) 20 21 int vpx_codec_version(void) { return VERSION_PACKED; } 22 23 const char *vpx_codec_version_str(void) { return VERSION_STRING_NOSP; } 24 25 const char *vpx_codec_version_extra_str(void) { return VERSION_EXTRA; } 26 27 const char *vpx_codec_iface_name(vpx_codec_iface_t *iface) { 28 return iface ? iface->name : "<invalid interface>"; 29 } 30 31 const char *vpx_codec_err_to_string(vpx_codec_err_t err) { 32 switch (err) { 33 case VPX_CODEC_OK: return "Success"; 34 case VPX_CODEC_ERROR: return "Unspecified internal error"; 35 case VPX_CODEC_MEM_ERROR: return "Memory allocation error"; 36 case VPX_CODEC_ABI_MISMATCH: return "ABI version mismatch"; 37 case VPX_CODEC_INCAPABLE: 38 return "Codec does not implement requested capability"; 39 case VPX_CODEC_UNSUP_BITSTREAM: 40 return "Bitstream not supported by this decoder"; 41 case VPX_CODEC_UNSUP_FEATURE: 42 return "Bitstream required feature not supported by this decoder"; 43 case VPX_CODEC_CORRUPT_FRAME: return "Corrupt frame detected"; 44 case VPX_CODEC_INVALID_PARAM: return "Invalid parameter"; 45 case VPX_CODEC_LIST_END: return "End of iterated list"; 46 } 47 48 return "Unrecognized error code"; 49 } 50 51 const char *vpx_codec_error(vpx_codec_ctx_t *ctx) { 52 return (ctx) ? vpx_codec_err_to_string(ctx->err) 53 : vpx_codec_err_to_string(VPX_CODEC_INVALID_PARAM); 54 } 55 56 const char *vpx_codec_error_detail(vpx_codec_ctx_t *ctx) { 57 if (ctx && ctx->err) 58 return ctx->priv ? ctx->priv->err_detail : ctx->err_detail; 59 60 return NULL; 61 } 62 63 vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx) { 64 vpx_codec_err_t res; 65 66 if (!ctx) 67 res = VPX_CODEC_INVALID_PARAM; 68 else if (!ctx->iface || !ctx->priv) 69 res = VPX_CODEC_ERROR; 70 else { 71 ctx->iface->destroy((vpx_codec_alg_priv_t *)ctx->priv); 72 73 ctx->iface = NULL; 74 ctx->name = NULL; 75 ctx->priv = NULL; 76 res = VPX_CODEC_OK; 77 } 78 79 return SAVE_STATUS(ctx, res); 80 } 81 82 vpx_codec_caps_t vpx_codec_get_caps(vpx_codec_iface_t *iface) { 83 return (iface) ? iface->caps : 0; 84 } 85 86 vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t *ctx, int ctrl_id, ...) { 87 vpx_codec_err_t res; 88 89 if (!ctx || !ctrl_id) 90 res = VPX_CODEC_INVALID_PARAM; 91 else if (!ctx->iface || !ctx->priv || !ctx->iface->ctrl_maps) 92 res = VPX_CODEC_ERROR; 93 else { 94 vpx_codec_ctrl_fn_map_t *entry; 95 96 res = VPX_CODEC_INCAPABLE; 97 98 for (entry = ctx->iface->ctrl_maps; entry && entry->fn; entry++) { 99 if (!entry->ctrl_id || entry->ctrl_id == ctrl_id) { 100 va_list ap; 101 102 va_start(ap, ctrl_id); 103 res = entry->fn((vpx_codec_alg_priv_t *)ctx->priv, ap); 104 va_end(ap); 105 break; 106 } 107 } 108 } 109 110 return SAVE_STATUS(ctx, res); 111 } 112 113 void vpx_internal_error(struct vpx_internal_error_info *info, 114 vpx_codec_err_t error, const char *fmt, ...) { 115 va_list ap; 116 117 info->error_code = error; 118 info->has_detail = 0; 119 120 if (fmt) { 121 size_t sz = sizeof(info->detail); 122 123 info->has_detail = 1; 124 va_start(ap, fmt); 125 vsnprintf(info->detail, sz - 1, fmt, ap); 126 va_end(ap); 127 info->detail[sz - 1] = '\0'; 128 } 129 130 if (info->setjmp) longjmp(info->jmp, info->error_code); 131 } 132 #endif 133