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