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.
13 * \brief Provides the high level interface to wrap decoder algorithms.
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,
28 if (ver != VPX_DECODER_ABI_VERSION)
29 res = VPX_CODEC_ABI_MISMATCH;
30 else if (!ctx || !iface)
31 res = VPX_CODEC_INVALID_PARAM;
32 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION)
33 res = VPX_CODEC_ABI_MISMATCH;
34 else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA))
35 res = VPX_CODEC_INCAPABLE;
36 else if ((flags & VPX_CODEC_USE_POSTPROC) && !(iface->caps & VPX_CODEC_CAP_POSTPROC))
37 res = VPX_CODEC_INCAPABLE;
38 else if ((flags & VPX_CODEC_USE_ERROR_CONCEALMENT) &&
39 !(iface->caps & VPX_CODEC_CAP_ERROR_CONCEALMENT))
40 res = VPX_CODEC_INCAPABLE;
41 else if ((flags & VPX_CODEC_USE_INPUT_FRAGMENTS) &&
42 !(iface->caps & VPX_CODEC_CAP_INPUT_FRAGMENTS))
43 res = VPX_CODEC_INCAPABLE;
44 else if (!(iface->caps & VPX_CODEC_CAP_DECODER))
45 res = VPX_CODEC_INCAPABLE;
47 memset(ctx, 0, sizeof(*ctx));
49 ctx->name = iface->name;
51 ctx->init_flags = flags;
52 ctx->config.dec = cfg;
55 if (!(flags & VPX_CODEC_USE_XMA)) {
56 res = ctx->iface->init(ctx, NULL);
59 ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL;
60 vpx_codec_destroy(ctx);
64 ctx->priv->iface = ctx->iface;
68 return SAVE_STATUS(ctx, res);
72 vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface,
75 vpx_codec_stream_info_t *si) {
78 if (!iface || !data || !data_sz || !si
79 || si->sz < sizeof(vpx_codec_stream_info_t))
80 res = VPX_CODEC_INVALID_PARAM;
82 /* Set default/unknown values */
86 res = iface->dec.peek_si(data, data_sz, si);
93 vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx,
94 vpx_codec_stream_info_t *si) {
97 if (!ctx || !si || si->sz < sizeof(vpx_codec_stream_info_t))
98 res = VPX_CODEC_INVALID_PARAM;
99 else if (!ctx->iface || !ctx->priv)
100 res = VPX_CODEC_ERROR;
102 /* Set default/unknown values */
106 res = ctx->iface->dec.get_si(ctx->priv->alg_priv, si);
109 return SAVE_STATUS(ctx, res);
113 vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx,
115 unsigned int data_sz,
121 /* NULL data ptr allowed if data_sz is 0 too */
122 if (!ctx || (!data && data_sz))
123 res = VPX_CODEC_INVALID_PARAM;
124 else if (!ctx->iface || !ctx->priv)
125 res = VPX_CODEC_ERROR;
127 res = ctx->iface->dec.decode(ctx->priv->alg_priv, data, data_sz,
128 user_priv, deadline);
131 return SAVE_STATUS(ctx, res);
134 vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx,
135 vpx_codec_iter_t *iter) {
138 if (!ctx || !iter || !ctx->iface || !ctx->priv)
141 img = ctx->iface->dec.get_frame(ctx->priv->alg_priv, iter);
147 vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx,
148 vpx_codec_put_frame_cb_fn_t cb,
153 res = VPX_CODEC_INVALID_PARAM;
154 else if (!ctx->iface || !ctx->priv
155 || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME))
156 res = VPX_CODEC_ERROR;
158 ctx->priv->dec.put_frame_cb.u.put_frame = cb;
159 ctx->priv->dec.put_frame_cb.user_priv = user_priv;
163 return SAVE_STATUS(ctx, res);
167 vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx,
168 vpx_codec_put_slice_cb_fn_t cb,
173 res = VPX_CODEC_INVALID_PARAM;
174 else if (!ctx->iface || !ctx->priv
175 || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_SLICE))
176 res = VPX_CODEC_ERROR;
178 ctx->priv->dec.put_slice_cb.u.put_slice = cb;
179 ctx->priv->dec.put_slice_cb.user_priv = user_priv;
183 return SAVE_STATUS(ctx, res);
187 vpx_codec_err_t vpx_codec_get_mem_map(vpx_codec_ctx_t *ctx,
188 vpx_codec_mmap_t *mmap,
189 vpx_codec_iter_t *iter) {
190 vpx_codec_err_t res = VPX_CODEC_OK;
192 if (!ctx || !mmap || !iter || !ctx->iface)
193 res = VPX_CODEC_INVALID_PARAM;
194 else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA))
195 res = VPX_CODEC_ERROR;
197 res = ctx->iface->get_mmap(ctx, mmap, iter);
199 return SAVE_STATUS(ctx, res);
203 vpx_codec_err_t vpx_codec_set_mem_map(vpx_codec_ctx_t *ctx,
204 vpx_codec_mmap_t *mmap,
205 unsigned int num_maps) {
206 vpx_codec_err_t res = VPX_CODEC_MEM_ERROR;
208 if (!ctx || !mmap || !ctx->iface)
209 res = VPX_CODEC_INVALID_PARAM;
210 else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA))
211 res = VPX_CODEC_ERROR;
215 for (i = 0; i < num_maps; i++, mmap++) {
219 /* Everything look ok, set the mmap in the decoder */
220 res = ctx->iface->set_mmap(ctx, mmap);
227 return SAVE_STATUS(ctx, res);
230 vpx_codec_err_t vpx_codec_set_frame_buffer_functions(
231 vpx_codec_ctx_t *ctx, vpx_get_frame_buffer_cb_fn_t cb_get,
232 vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
235 if (!ctx || !cb_get || !cb_release) {
236 res = VPX_CODEC_INVALID_PARAM;
237 } else if (!ctx->iface || !ctx->priv ||
238 !(ctx->iface->caps & VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER)) {
239 res = VPX_CODEC_ERROR;
241 res = ctx->iface->dec.set_fb_fn(ctx->priv->alg_priv, cb_get, cb_release,
245 return SAVE_STATUS(ctx, res);