Merge "configuration, support disabling any subset of ARM arch"
[libvpx.git] / vpx / src / vpx_decoder.c
blob42aedee7edbd59b79e9d58eab4f55c3677d81182
1 /*
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.
9 */
12 /*!\file
13 * \brief Provides the high level interface to wrap decoder algorithms.
16 #include <string.h>
17 #include "vpx/internal/vpx_codec_internal.h"
19 #define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var)
21 vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx,
22 vpx_codec_iface_t *iface,
23 vpx_codec_dec_cfg_t *cfg,
24 vpx_codec_flags_t flags,
25 int ver)
27 vpx_codec_err_t res;
29 if (ver != VPX_DECODER_ABI_VERSION)
30 res = VPX_CODEC_ABI_MISMATCH;
31 else if (!ctx || !iface)
32 res = VPX_CODEC_INVALID_PARAM;
33 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION)
34 res = VPX_CODEC_ABI_MISMATCH;
35 else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA))
36 res = VPX_CODEC_INCAPABLE;
37 else if ((flags & VPX_CODEC_USE_POSTPROC) && !(iface->caps & VPX_CODEC_CAP_POSTPROC))
38 res = VPX_CODEC_INCAPABLE;
39 else if ((flags & VPX_CODEC_USE_ERROR_CONCEALMENT) &&
40 !(iface->caps & VPX_CODEC_CAP_ERROR_CONCEALMENT))
41 res = VPX_CODEC_INCAPABLE;
42 else if (!(iface->caps & VPX_CODEC_CAP_DECODER))
43 res = VPX_CODEC_INCAPABLE;
44 else
46 memset(ctx, 0, sizeof(*ctx));
47 ctx->iface = iface;
48 ctx->name = iface->name;
49 ctx->priv = NULL;
50 ctx->init_flags = flags;
51 ctx->config.dec = cfg;
52 res = VPX_CODEC_OK;
54 if (!(flags & VPX_CODEC_USE_XMA))
56 res = ctx->iface->init(ctx);
58 if (res)
60 ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL;
61 vpx_codec_destroy(ctx);
64 if (ctx->priv)
65 ctx->priv->iface = ctx->iface;
69 return SAVE_STATUS(ctx, res);
73 vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
74 const uint8_t *data,
75 unsigned int data_sz,
76 vpx_codec_stream_info_t *si)
78 vpx_codec_err_t res;
80 if (!iface || !data || !data_sz || !si
81 || si->sz < sizeof(vpx_codec_stream_info_t))
82 res = VPX_CODEC_INVALID_PARAM;
83 else
85 /* Set default/unknown values */
86 si->w = 0;
87 si->h = 0;
89 res = iface->dec.peek_si(data, data_sz, si);
92 return res;
96 vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
97 vpx_codec_stream_info_t *si)
99 vpx_codec_err_t res;
101 if (!ctx || !si || si->sz < sizeof(vpx_codec_stream_info_t))
102 res = VPX_CODEC_INVALID_PARAM;
103 else if (!ctx->iface || !ctx->priv)
104 res = VPX_CODEC_ERROR;
105 else
107 /* Set default/unknown values */
108 si->w = 0;
109 si->h = 0;
111 res = ctx->iface->dec.get_si(ctx->priv->alg_priv, si);
114 return SAVE_STATUS(ctx, res);
118 vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx,
119 const uint8_t *data,
120 unsigned int data_sz,
121 void *user_priv,
122 long deadline)
124 vpx_codec_err_t res;
126 /* Sanity checks */
127 /* NULL data ptr allowed if data_sz is 0 too */
128 if (!ctx || (!data && data_sz))
129 res = VPX_CODEC_INVALID_PARAM;
130 else if (!ctx->iface || !ctx->priv)
131 res = VPX_CODEC_ERROR;
132 else
134 res = ctx->iface->dec.decode(ctx->priv->alg_priv, data, data_sz,
135 user_priv, deadline);
138 return SAVE_STATUS(ctx, res);
141 vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx,
142 vpx_codec_iter_t *iter)
144 vpx_image_t *img;
146 if (!ctx || !iter || !ctx->iface || !ctx->priv)
147 img = NULL;
148 else
149 img = ctx->iface->dec.get_frame(ctx->priv->alg_priv, iter);
151 return img;
155 vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx,
156 vpx_codec_put_frame_cb_fn_t cb,
157 void *user_priv)
159 vpx_codec_err_t res;
161 if (!ctx || !cb)
162 res = VPX_CODEC_INVALID_PARAM;
163 else if (!ctx->iface || !ctx->priv
164 || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME))
165 res = VPX_CODEC_ERROR;
166 else
168 ctx->priv->dec.put_frame_cb.u.put_frame = cb;
169 ctx->priv->dec.put_frame_cb.user_priv = user_priv;
170 res = VPX_CODEC_OK;
173 return SAVE_STATUS(ctx, res);
177 vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx,
178 vpx_codec_put_slice_cb_fn_t cb,
179 void *user_priv)
181 vpx_codec_err_t res;
183 if (!ctx || !cb)
184 res = VPX_CODEC_INVALID_PARAM;
185 else if (!ctx->iface || !ctx->priv
186 || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME))
187 res = VPX_CODEC_ERROR;
188 else
190 ctx->priv->dec.put_slice_cb.u.put_slice = cb;
191 ctx->priv->dec.put_slice_cb.user_priv = user_priv;
192 res = VPX_CODEC_OK;
195 return SAVE_STATUS(ctx, res);
199 vpx_codec_err_t vpx_codec_get_mem_map(vpx_codec_ctx_t *ctx,
200 vpx_codec_mmap_t *mmap,
201 vpx_codec_iter_t *iter)
203 vpx_codec_err_t res = VPX_CODEC_OK;
205 if (!ctx || !mmap || !iter || !ctx->iface)
206 res = VPX_CODEC_INVALID_PARAM;
207 else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA))
208 res = VPX_CODEC_ERROR;
209 else
210 res = ctx->iface->get_mmap(ctx, mmap, iter);
212 return SAVE_STATUS(ctx, res);
216 vpx_codec_err_t vpx_codec_set_mem_map(vpx_codec_ctx_t *ctx,
217 vpx_codec_mmap_t *mmap,
218 unsigned int num_maps)
220 vpx_codec_err_t res = VPX_CODEC_MEM_ERROR;
222 if (!ctx || !mmap || !ctx->iface)
223 res = VPX_CODEC_INVALID_PARAM;
224 else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA))
225 res = VPX_CODEC_ERROR;
226 else
228 unsigned int i;
230 for (i = 0; i < num_maps; i++, mmap++)
232 if (!mmap->base)
233 break;
235 /* Everything look ok, set the mmap in the decoder */
236 res = ctx->iface->set_mmap(ctx, mmap);
238 if (res)
239 break;
243 return SAVE_STATUS(ctx, res);