| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 | 11 |
| 12 /*!\file | 12 /*!\file |
| 13 * \brief Provides the high level interface to wrap decoder algorithms. | 13 * \brief Provides the high level interface to wrap decoder algorithms. |
| 14 * | 14 * |
| 15 */ | 15 */ |
| 16 #include <string.h> | 16 #include <string.h> |
| 17 #include "vpx/internal/vpx_codec_internal.h" | 17 #include "vpx/internal/vpx_codec_internal.h" |
| 18 | 18 |
| 19 #define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var) | 19 #define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var) |
| 20 | 20 |
| 21 vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx, | 21 vpx_codec_err_t vpx_codec_dec_init_ver(vpx_codec_ctx_t *ctx, |
| 22 vpx_codec_iface_t *iface, | 22 vpx_codec_iface_t *iface, |
| 23 vpx_codec_dec_cfg_t *cfg, | 23 vpx_codec_dec_cfg_t *cfg, |
| 24 vpx_codec_flags_t flags, | 24 vpx_codec_flags_t flags, |
| 25 int ver) | 25 int ver) { |
| 26 { | 26 vpx_codec_err_t res; |
| 27 vpx_codec_err_t res; | |
| 28 | 27 |
| 29 if (ver != VPX_DECODER_ABI_VERSION) | 28 if (ver != VPX_DECODER_ABI_VERSION) |
| 30 res = VPX_CODEC_ABI_MISMATCH; | 29 res = VPX_CODEC_ABI_MISMATCH; |
| 31 else if (!ctx || !iface) | 30 else if (!ctx || !iface) |
| 32 res = VPX_CODEC_INVALID_PARAM; | 31 res = VPX_CODEC_INVALID_PARAM; |
| 33 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) | 32 else if (iface->abi_version != VPX_CODEC_INTERNAL_ABI_VERSION) |
| 34 res = VPX_CODEC_ABI_MISMATCH; | 33 res = VPX_CODEC_ABI_MISMATCH; |
| 35 else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA)) | 34 else if ((flags & VPX_CODEC_USE_XMA) && !(iface->caps & VPX_CODEC_CAP_XMA)) |
| 36 res = VPX_CODEC_INCAPABLE; | 35 res = VPX_CODEC_INCAPABLE; |
| 37 else if ((flags & VPX_CODEC_USE_POSTPROC) && !(iface->caps & VPX_CODEC_CAP_P
OSTPROC)) | 36 else if ((flags & VPX_CODEC_USE_POSTPROC) && !(iface->caps & VPX_CODEC_CAP_POS
TPROC)) |
| 38 res = VPX_CODEC_INCAPABLE; | 37 res = VPX_CODEC_INCAPABLE; |
| 39 else if ((flags & VPX_CODEC_USE_ERROR_CONCEALMENT) && | 38 else if ((flags & VPX_CODEC_USE_ERROR_CONCEALMENT) && |
| 40 !(iface->caps & VPX_CODEC_CAP_ERROR_CONCEALMENT)) | 39 !(iface->caps & VPX_CODEC_CAP_ERROR_CONCEALMENT)) |
| 41 res = VPX_CODEC_INCAPABLE; | 40 res = VPX_CODEC_INCAPABLE; |
| 42 else if ((flags & VPX_CODEC_USE_INPUT_FRAGMENTS) && | 41 else if ((flags & VPX_CODEC_USE_INPUT_FRAGMENTS) && |
| 43 !(iface->caps & VPX_CODEC_CAP_INPUT_FRAGMENTS)) | 42 !(iface->caps & VPX_CODEC_CAP_INPUT_FRAGMENTS)) |
| 44 res = VPX_CODEC_INCAPABLE; | 43 res = VPX_CODEC_INCAPABLE; |
| 45 else if (!(iface->caps & VPX_CODEC_CAP_DECODER)) | 44 else if (!(iface->caps & VPX_CODEC_CAP_DECODER)) |
| 46 res = VPX_CODEC_INCAPABLE; | 45 res = VPX_CODEC_INCAPABLE; |
| 47 else | 46 else { |
| 48 { | 47 memset(ctx, 0, sizeof(*ctx)); |
| 49 memset(ctx, 0, sizeof(*ctx)); | 48 ctx->iface = iface; |
| 50 ctx->iface = iface; | 49 ctx->name = iface->name; |
| 51 ctx->name = iface->name; | 50 ctx->priv = NULL; |
| 52 ctx->priv = NULL; | 51 ctx->init_flags = flags; |
| 53 ctx->init_flags = flags; | 52 ctx->config.dec = cfg; |
| 54 ctx->config.dec = cfg; | 53 res = VPX_CODEC_OK; |
| 55 res = VPX_CODEC_OK; | |
| 56 | 54 |
| 57 if (!(flags & VPX_CODEC_USE_XMA)) | 55 if (!(flags & VPX_CODEC_USE_XMA)) { |
| 58 { | 56 res = ctx->iface->init(ctx, NULL); |
| 59 res = ctx->iface->init(ctx, NULL); | |
| 60 | 57 |
| 61 if (res) | 58 if (res) { |
| 62 { | 59 ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL; |
| 63 ctx->err_detail = ctx->priv ? ctx->priv->err_detail : NULL; | 60 vpx_codec_destroy(ctx); |
| 64 vpx_codec_destroy(ctx); | 61 } |
| 65 } | |
| 66 | 62 |
| 67 if (ctx->priv) | 63 if (ctx->priv) |
| 68 ctx->priv->iface = ctx->iface; | 64 ctx->priv->iface = ctx->iface; |
| 69 } | |
| 70 } | 65 } |
| 66 } |
| 71 | 67 |
| 72 return SAVE_STATUS(ctx, res); | 68 return SAVE_STATUS(ctx, res); |
| 73 } | 69 } |
| 74 | 70 |
| 75 | 71 |
| 76 vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface, | 72 vpx_codec_err_t vpx_codec_peek_stream_info(vpx_codec_iface_t *iface, |
| 77 const uint8_t *data, | 73 const uint8_t *data, |
| 78 unsigned int data_sz, | 74 unsigned int data_sz, |
| 79 vpx_codec_stream_info_t *si) | 75 vpx_codec_stream_info_t *si) { |
| 80 { | 76 vpx_codec_err_t res; |
| 81 vpx_codec_err_t res; | |
| 82 | 77 |
| 83 if (!iface || !data || !data_sz || !si | 78 if (!iface || !data || !data_sz || !si |
| 84 || si->sz < sizeof(vpx_codec_stream_info_t)) | 79 || si->sz < sizeof(vpx_codec_stream_info_t)) |
| 85 res = VPX_CODEC_INVALID_PARAM; | 80 res = VPX_CODEC_INVALID_PARAM; |
| 86 else | 81 else { |
| 87 { | 82 /* Set default/unknown values */ |
| 88 /* Set default/unknown values */ | 83 si->w = 0; |
| 89 si->w = 0; | 84 si->h = 0; |
| 90 si->h = 0; | |
| 91 | 85 |
| 92 res = iface->dec.peek_si(data, data_sz, si); | 86 res = iface->dec.peek_si(data, data_sz, si); |
| 93 } | 87 } |
| 94 | 88 |
| 95 return res; | 89 return res; |
| 96 } | 90 } |
| 97 | 91 |
| 98 | 92 |
| 99 vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx, | 93 vpx_codec_err_t vpx_codec_get_stream_info(vpx_codec_ctx_t *ctx, |
| 100 vpx_codec_stream_info_t *si) | 94 vpx_codec_stream_info_t *si) { |
| 101 { | 95 vpx_codec_err_t res; |
| 102 vpx_codec_err_t res; | |
| 103 | 96 |
| 104 if (!ctx || !si || si->sz < sizeof(vpx_codec_stream_info_t)) | 97 if (!ctx || !si || si->sz < sizeof(vpx_codec_stream_info_t)) |
| 105 res = VPX_CODEC_INVALID_PARAM; | 98 res = VPX_CODEC_INVALID_PARAM; |
| 106 else if (!ctx->iface || !ctx->priv) | 99 else if (!ctx->iface || !ctx->priv) |
| 107 res = VPX_CODEC_ERROR; | 100 res = VPX_CODEC_ERROR; |
| 108 else | 101 else { |
| 109 { | 102 /* Set default/unknown values */ |
| 110 /* Set default/unknown values */ | 103 si->w = 0; |
| 111 si->w = 0; | 104 si->h = 0; |
| 112 si->h = 0; | |
| 113 | 105 |
| 114 res = ctx->iface->dec.get_si(ctx->priv->alg_priv, si); | 106 res = ctx->iface->dec.get_si(ctx->priv->alg_priv, si); |
| 115 } | 107 } |
| 116 | 108 |
| 117 return SAVE_STATUS(ctx, res); | 109 return SAVE_STATUS(ctx, res); |
| 118 } | 110 } |
| 119 | 111 |
| 120 | 112 |
| 121 vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, | 113 vpx_codec_err_t vpx_codec_decode(vpx_codec_ctx_t *ctx, |
| 122 const uint8_t *data, | 114 const uint8_t *data, |
| 123 unsigned int data_sz, | 115 unsigned int data_sz, |
| 124 void *user_priv, | 116 void *user_priv, |
| 125 long deadline) | 117 long deadline) { |
| 126 { | 118 vpx_codec_err_t res; |
| 127 vpx_codec_err_t res; | |
| 128 | 119 |
| 129 /* Sanity checks */ | 120 /* Sanity checks */ |
| 130 /* NULL data ptr allowed if data_sz is 0 too */ | 121 /* NULL data ptr allowed if data_sz is 0 too */ |
| 131 if (!ctx || (!data && data_sz)) | 122 if (!ctx || (!data && data_sz)) |
| 132 res = VPX_CODEC_INVALID_PARAM; | 123 res = VPX_CODEC_INVALID_PARAM; |
| 133 else if (!ctx->iface || !ctx->priv) | 124 else if (!ctx->iface || !ctx->priv) |
| 134 res = VPX_CODEC_ERROR; | 125 res = VPX_CODEC_ERROR; |
| 135 else | 126 else { |
| 136 { | 127 res = ctx->iface->dec.decode(ctx->priv->alg_priv, data, data_sz, |
| 137 res = ctx->iface->dec.decode(ctx->priv->alg_priv, data, data_sz, | 128 user_priv, deadline); |
| 138 user_priv, deadline); | 129 } |
| 139 } | |
| 140 | 130 |
| 141 return SAVE_STATUS(ctx, res); | 131 return SAVE_STATUS(ctx, res); |
| 142 } | 132 } |
| 143 | 133 |
| 144 vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx, | 134 vpx_image_t *vpx_codec_get_frame(vpx_codec_ctx_t *ctx, |
| 145 vpx_codec_iter_t *iter) | 135 vpx_codec_iter_t *iter) { |
| 146 { | 136 vpx_image_t *img; |
| 147 vpx_image_t *img; | |
| 148 | 137 |
| 149 if (!ctx || !iter || !ctx->iface || !ctx->priv) | 138 if (!ctx || !iter || !ctx->iface || !ctx->priv) |
| 150 img = NULL; | 139 img = NULL; |
| 151 else | 140 else |
| 152 img = ctx->iface->dec.get_frame(ctx->priv->alg_priv, iter); | 141 img = ctx->iface->dec.get_frame(ctx->priv->alg_priv, iter); |
| 153 | 142 |
| 154 return img; | 143 return img; |
| 155 } | 144 } |
| 156 | 145 |
| 157 | 146 |
| 158 vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx
, | 147 vpx_codec_err_t vpx_codec_register_put_frame_cb(vpx_codec_ctx_t *ctx
, |
| 159 vpx_codec_put_frame_cb_fn_t cb, | 148 vpx_codec_put_frame_cb_fn_t cb, |
| 160 void *user_priv) | 149 void *user_
priv) { |
| 161 { | 150 vpx_codec_err_t res; |
| 162 vpx_codec_err_t res; | |
| 163 | 151 |
| 164 if (!ctx || !cb) | 152 if (!ctx || !cb) |
| 165 res = VPX_CODEC_INVALID_PARAM; | 153 res = VPX_CODEC_INVALID_PARAM; |
| 166 else if (!ctx->iface || !ctx->priv | 154 else if (!ctx->iface || !ctx->priv |
| 167 || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME)) | 155 || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME)) |
| 168 res = VPX_CODEC_ERROR; | 156 res = VPX_CODEC_ERROR; |
| 169 else | 157 else { |
| 170 { | 158 ctx->priv->dec.put_frame_cb.u.put_frame = cb; |
| 171 ctx->priv->dec.put_frame_cb.u.put_frame = cb; | 159 ctx->priv->dec.put_frame_cb.user_priv = user_priv; |
| 172 ctx->priv->dec.put_frame_cb.user_priv = user_priv; | 160 res = VPX_CODEC_OK; |
| 173 res = VPX_CODEC_OK; | 161 } |
| 174 } | |
| 175 | 162 |
| 176 return SAVE_STATUS(ctx, res); | 163 return SAVE_STATUS(ctx, res); |
| 177 } | 164 } |
| 178 | 165 |
| 179 | 166 |
| 180 vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx
, | 167 vpx_codec_err_t vpx_codec_register_put_slice_cb(vpx_codec_ctx_t *ctx
, |
| 181 vpx_codec_put_slice_cb_fn_t cb, | 168 vpx_codec_put_slice_cb_fn_t cb, |
| 182 void *user_priv) | 169 void *user_
priv) { |
| 183 { | 170 vpx_codec_err_t res; |
| 184 vpx_codec_err_t res; | |
| 185 | 171 |
| 186 if (!ctx || !cb) | 172 if (!ctx || !cb) |
| 187 res = VPX_CODEC_INVALID_PARAM; | 173 res = VPX_CODEC_INVALID_PARAM; |
| 188 else if (!ctx->iface || !ctx->priv | 174 else if (!ctx->iface || !ctx->priv |
| 189 || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME)) | 175 || !(ctx->iface->caps & VPX_CODEC_CAP_PUT_FRAME)) |
| 190 res = VPX_CODEC_ERROR; | 176 res = VPX_CODEC_ERROR; |
| 191 else | 177 else { |
| 192 { | 178 ctx->priv->dec.put_slice_cb.u.put_slice = cb; |
| 193 ctx->priv->dec.put_slice_cb.u.put_slice = cb; | 179 ctx->priv->dec.put_slice_cb.user_priv = user_priv; |
| 194 ctx->priv->dec.put_slice_cb.user_priv = user_priv; | 180 res = VPX_CODEC_OK; |
| 195 res = VPX_CODEC_OK; | 181 } |
| 196 } | |
| 197 | 182 |
| 198 return SAVE_STATUS(ctx, res); | 183 return SAVE_STATUS(ctx, res); |
| 199 } | 184 } |
| 200 | 185 |
| 201 | 186 |
| 202 vpx_codec_err_t vpx_codec_get_mem_map(vpx_codec_ctx_t *ctx, | 187 vpx_codec_err_t vpx_codec_get_mem_map(vpx_codec_ctx_t *ctx, |
| 203 vpx_codec_mmap_t *mmap, | 188 vpx_codec_mmap_t *mmap, |
| 204 vpx_codec_iter_t *iter) | 189 vpx_codec_iter_t *iter) { |
| 205 { | 190 vpx_codec_err_t res = VPX_CODEC_OK; |
| 206 vpx_codec_err_t res = VPX_CODEC_OK; | |
| 207 | 191 |
| 208 if (!ctx || !mmap || !iter || !ctx->iface) | 192 if (!ctx || !mmap || !iter || !ctx->iface) |
| 209 res = VPX_CODEC_INVALID_PARAM; | 193 res = VPX_CODEC_INVALID_PARAM; |
| 210 else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA)) | 194 else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA)) |
| 211 res = VPX_CODEC_ERROR; | 195 res = VPX_CODEC_ERROR; |
| 212 else | 196 else |
| 213 res = ctx->iface->get_mmap(ctx, mmap, iter); | 197 res = ctx->iface->get_mmap(ctx, mmap, iter); |
| 214 | 198 |
| 215 return SAVE_STATUS(ctx, res); | 199 return SAVE_STATUS(ctx, res); |
| 216 } | 200 } |
| 217 | 201 |
| 218 | 202 |
| 219 vpx_codec_err_t vpx_codec_set_mem_map(vpx_codec_ctx_t *ctx, | 203 vpx_codec_err_t vpx_codec_set_mem_map(vpx_codec_ctx_t *ctx, |
| 220 vpx_codec_mmap_t *mmap, | 204 vpx_codec_mmap_t *mmap, |
| 221 unsigned int num_maps) | 205 unsigned int num_maps) { |
| 222 { | 206 vpx_codec_err_t res = VPX_CODEC_MEM_ERROR; |
| 223 vpx_codec_err_t res = VPX_CODEC_MEM_ERROR; | |
| 224 | 207 |
| 225 if (!ctx || !mmap || !ctx->iface) | 208 if (!ctx || !mmap || !ctx->iface) |
| 226 res = VPX_CODEC_INVALID_PARAM; | 209 res = VPX_CODEC_INVALID_PARAM; |
| 227 else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA)) | 210 else if (!(ctx->iface->caps & VPX_CODEC_CAP_XMA)) |
| 228 res = VPX_CODEC_ERROR; | 211 res = VPX_CODEC_ERROR; |
| 229 else | 212 else { |
| 230 { | 213 unsigned int i; |
| 231 unsigned int i; | |
| 232 | 214 |
| 233 for (i = 0; i < num_maps; i++, mmap++) | 215 for (i = 0; i < num_maps; i++, mmap++) { |
| 234 { | 216 if (!mmap->base) |
| 235 if (!mmap->base) | 217 break; |
| 236 break; | |
| 237 | 218 |
| 238 /* Everything look ok, set the mmap in the decoder */ | 219 /* Everything look ok, set the mmap in the decoder */ |
| 239 res = ctx->iface->set_mmap(ctx, mmap); | 220 res = ctx->iface->set_mmap(ctx, mmap); |
| 240 | 221 |
| 241 if (res) | 222 if (res) |
| 242 break; | 223 break; |
| 243 } | |
| 244 } | 224 } |
| 225 } |
| 245 | 226 |
| 246 return SAVE_STATUS(ctx, res); | 227 return SAVE_STATUS(ctx, res); |
| 247 } | 228 } |
| OLD | NEW |