1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vpx/src/vpx_decoder.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,228 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 + 1.15 +/*!\file 1.16 + * \brief Provides the high level interface to wrap decoder algorithms. 1.17 + * 1.18 + */ 1.19 +#include <string.h> 1.20 +#include "vpx/internal/vpx_codec_internal.h" 1.21 + 1.22 +#define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var) 1.23 + 1.24 +vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx, 1.25 + vpx_codec_iface_t *iface, 1.26 + vpx_codec_dec_cfg_t *cfg, 1.27 + vpx_codec_flags_t flags, 1.28 + int ver) { 1.29 + vpx_codec_err_t res; 1.30 + 1.31 + if (ver != VPX_DECODER_ABI_VERSION) 1.32 + res = VPX_CODEC_ABI_MISMATCH; 1.33 + else if (!ctx || !iface) 1.34 + res = VPX_CODEC_INVALID_PARAM; 1.35 + else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) 1.36 + res = VPX_CODEC_ABI_MISMATCH; 1.37 + else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA)) 1.38 + res = VPX_CODEC_INCAPABLE; 1.39 + else if ((flags & VPX_CODEC_USE_POSTPROC) && !(iface->caps & VPX_CODEC_CAP_POSTPROC)) 1.40 + res = VPX_CODEC_INCAPABLE; 1.41 + else if ((flags & VPX_CODEC_USE_ERROR_CONCEALMENT) && 1.42 + !(iface->caps & VPX_CODEC_CAP_ERROR_CONCEALMENT)) 1.43 + res = VPX_CODEC_INCAPABLE; 1.44 + else if ((flags & VPX_CODEC_USE_INPUT_FRAGMENTS) && 1.45 + !(iface->caps & VPX_CODEC_CAP_INPUT_FRAGMENTS)) 1.46 + res = VPX_CODEC_INCAPABLE; 1.47 + else if (!(iface->caps & VPX_CODEC_CAP_DECODER)) 1.48 + res = VPX_CODEC_INCAPABLE; 1.49 + else { 1.50 + memset(ctx, 0, sizeof(*ctx)); 1.51 + ctx->iface = iface; 1.52 + ctx->name = iface->name; 1.53 + ctx->priv = NULL; 1.54 + ctx->init_flags = flags; 1.55 + ctx->config.dec = cfg; 1.56 + res = VPX_CODEC_OK; 1.57 + 1.58 + if (!(flags & VPX_CODEC_USE_XMA)) { 1.59 + res = ctx->iface->init(ctx, NULL); 1.60 + 1.61 + if (res) { 1.62 + ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL; 1.63 + vpx_codec_destroy(ctx); 1.64 + } 1.65 + 1.66 + if (ctx->priv) 1.67 + ctx->priv->iface = ctx->iface; 1.68 + } 1.69 + } 1.70 + 1.71 + return SAVE_STATUS(ctx, res); 1.72 +} 1.73 + 1.74 + 1.75 +vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface, 1.76 + const uint8_t *data, 1.77 + unsigned int data_sz, 1.78 + vpx_codec_stream_info_t *si) { 1.79 + vpx_codec_err_t res; 1.80 + 1.81 + if (!iface || !data || !data_sz || !si 1.82 + || si->sz < sizeof(vpx_codec_stream_info_t)) 1.83 + res = VPX_CODEC_INVALID_PARAM; 1.84 + else { 1.85 + /* Set default/unknown values */ 1.86 + si->w = 0; 1.87 + si->h = 0; 1.88 + 1.89 + res = iface->dec.peek_si(data, data_sz, si); 1.90 + } 1.91 + 1.92 + return res; 1.93 +} 1.94 + 1.95 + 1.96 +vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx, 1.97 + vpx_codec_stream_info_t *si) { 1.98 + vpx_codec_err_t res; 1.99 + 1.100 + if (!ctx || !si || si->sz < sizeof(vpx_codec_stream_info_t)) 1.101 + res = VPX_CODEC_INVALID_PARAM; 1.102 + else if (!ctx->iface || !ctx->priv) 1.103 + res = VPX_CODEC_ERROR; 1.104 + else { 1.105 + /* Set default/unknown values */ 1.106 + si->w = 0; 1.107 + si->h = 0; 1.108 + 1.109 + res = ctx->iface->dec.get_si(ctx->priv->alg_priv, si); 1.110 + } 1.111 + 1.112 + return SAVE_STATUS(ctx, res); 1.113 +} 1.114 + 1.115 + 1.116 +vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, 1.117 + const uint8_t *data, 1.118 + unsigned int data_sz, 1.119 + void *user_priv, 1.120 + long deadline) { 1.121 + vpx_codec_err_t res; 1.122 + 1.123 + /* Sanity checks */ 1.124 + /* NULL data ptr allowed if data_sz is 0 too */ 1.125 + if (!ctx || (!data && data_sz)) 1.126 + res = VPX_CODEC_INVALID_PARAM; 1.127 + else if (!ctx->iface || !ctx->priv) 1.128 + res = VPX_CODEC_ERROR; 1.129 + else { 1.130 + res = ctx->iface->dec.decode(ctx->priv->alg_priv, data, data_sz, 1.131 + user_priv, deadline); 1.132 + } 1.133 + 1.134 + return SAVE_STATUS(ctx, res); 1.135 +} 1.136 + 1.137 +vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx, 1.138 + vpx_codec_iter_t *iter) { 1.139 + vpx_image_t *img; 1.140 + 1.141 + if (!ctx || !iter || !ctx->iface || !ctx->priv) 1.142 + img = NULL; 1.143 + else 1.144 + img = ctx->iface->dec.get_frame(ctx->priv->alg_priv, iter); 1.145 + 1.146 + return img; 1.147 +} 1.148 + 1.149 + 1.150 +vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx, 1.151 + vpx_codec_put_frame_cb_fn_t cb, 1.152 + void *user_priv) { 1.153 + vpx_codec_err_t res; 1.154 + 1.155 + if (!ctx || !cb) 1.156 + res = VPX_CODEC_INVALID_PARAM; 1.157 + else if (!ctx->iface || !ctx->priv 1.158 + || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME)) 1.159 + res = VPX_CODEC_ERROR; 1.160 + else { 1.161 + ctx->priv->dec.put_frame_cb.u.put_frame = cb; 1.162 + ctx->priv->dec.put_frame_cb.user_priv = user_priv; 1.163 + res = VPX_CODEC_OK; 1.164 + } 1.165 + 1.166 + return SAVE_STATUS(ctx, res); 1.167 +} 1.168 + 1.169 + 1.170 +vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx, 1.171 + vpx_codec_put_slice_cb_fn_t cb, 1.172 + void *user_priv) { 1.173 + vpx_codec_err_t res; 1.174 + 1.175 + if (!ctx || !cb) 1.176 + res = VPX_CODEC_INVALID_PARAM; 1.177 + else if (!ctx->iface || !ctx->priv 1.178 + || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME)) 1.179 + res = VPX_CODEC_ERROR; 1.180 + else { 1.181 + ctx->priv->dec.put_slice_cb.u.put_slice = cb; 1.182 + ctx->priv->dec.put_slice_cb.user_priv = user_priv; 1.183 + res = VPX_CODEC_OK; 1.184 + } 1.185 + 1.186 + return SAVE_STATUS(ctx, res); 1.187 +} 1.188 + 1.189 + 1.190 +vpx_codec_err_t vpx_codec_get_mem_map(vpx_codec_ctx_t *ctx, 1.191 + vpx_codec_mmap_t *mmap, 1.192 + vpx_codec_iter_t *iter) { 1.193 + vpx_codec_err_t res = VPX_CODEC_OK; 1.194 + 1.195 + if (!ctx || !mmap || !iter || !ctx->iface) 1.196 + res = VPX_CODEC_INVALID_PARAM; 1.197 + else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA)) 1.198 + res = VPX_CODEC_ERROR; 1.199 + else 1.200 + res = ctx->iface->get_mmap(ctx, mmap, iter); 1.201 + 1.202 + return SAVE_STATUS(ctx, res); 1.203 +} 1.204 + 1.205 + 1.206 +vpx_codec_err_t vpx_codec_set_mem_map(vpx_codec_ctx_t *ctx, 1.207 + vpx_codec_mmap_t *mmap, 1.208 + unsigned int num_maps) { 1.209 + vpx_codec_err_t res = VPX_CODEC_MEM_ERROR; 1.210 + 1.211 + if (!ctx || !mmap || !ctx->iface) 1.212 + res = VPX_CODEC_INVALID_PARAM; 1.213 + else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA)) 1.214 + res = VPX_CODEC_ERROR; 1.215 + else { 1.216 + unsigned int i; 1.217 + 1.218 + for (i = 0; i < num_maps; i++, mmap++) { 1.219 + if (!mmap->base) 1.220 + break; 1.221 + 1.222 + /* Everything look ok, set the mmap in the decoder */ 1.223 + res = ctx->iface->set_mmap(ctx, mmap); 1.224 + 1.225 + if (res) 1.226 + break; 1.227 + } 1.228 + } 1.229 + 1.230 + return SAVE_STATUS(ctx, res); 1.231 +}