media/libvpx/vpx/src/vpx_codec.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vpx/src/vpx_codec.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,184 @@
     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 <stdarg.h>
    1.20 +#include <stdlib.h>
    1.21 +#include "vpx/vpx_integer.h"
    1.22 +#include "vpx/internal/vpx_codec_internal.h"
    1.23 +#include "vpx_version.h"
    1.24 +
    1.25 +#define SAVE_STATUS(ctx,var) (ctx?(ctx->err = var):var)
    1.26 +
    1.27 +int vpx_codec_version(void) {
    1.28 +  return VERSION_PACKED;
    1.29 +}
    1.30 +
    1.31 +
    1.32 +const char *vpx_codec_version_str(void) {
    1.33 +  return VERSION_STRING_NOSP;
    1.34 +}
    1.35 +
    1.36 +
    1.37 +const char *vpx_codec_version_extra_str(void) {
    1.38 +  return VERSION_EXTRA;
    1.39 +}
    1.40 +
    1.41 +
    1.42 +const char *vpx_codec_iface_name(vpx_codec_iface_t *iface) {
    1.43 +  return iface ? iface->name : "<invalid interface>";
    1.44 +}
    1.45 +
    1.46 +const char *vpx_codec_err_to_string(vpx_codec_err_t  err) {
    1.47 +  switch (err) {
    1.48 +    case VPX_CODEC_OK:
    1.49 +      return "Success";
    1.50 +    case VPX_CODEC_ERROR:
    1.51 +      return "Unspecified internal error";
    1.52 +    case VPX_CODEC_MEM_ERROR:
    1.53 +      return "Memory allocation error";
    1.54 +    case VPX_CODEC_ABI_MISMATCH:
    1.55 +      return "ABI version mismatch";
    1.56 +    case VPX_CODEC_INCAPABLE:
    1.57 +      return "Codec does not implement requested capability";
    1.58 +    case VPX_CODEC_UNSUP_BITSTREAM:
    1.59 +      return "Bitstream not supported by this decoder";
    1.60 +    case VPX_CODEC_UNSUP_FEATURE:
    1.61 +      return "Bitstream required feature not supported by this decoder";
    1.62 +    case VPX_CODEC_CORRUPT_FRAME:
    1.63 +      return "Corrupt frame detected";
    1.64 +    case  VPX_CODEC_INVALID_PARAM:
    1.65 +      return "Invalid parameter";
    1.66 +    case VPX_CODEC_LIST_END:
    1.67 +      return "End of iterated list";
    1.68 +  }
    1.69 +
    1.70 +  return "Unrecognized error code";
    1.71 +}
    1.72 +
    1.73 +const char *vpx_codec_error(vpx_codec_ctx_t  *ctx) {
    1.74 +  return (ctx) ? vpx_codec_err_to_string(ctx->err)
    1.75 +         : vpx_codec_err_to_string(VPX_CODEC_INVALID_PARAM);
    1.76 +}
    1.77 +
    1.78 +const char *vpx_codec_error_detail(vpx_codec_ctx_t  *ctx) {
    1.79 +  if (ctx && ctx->err)
    1.80 +    return ctx->priv ? ctx->priv->err_detail : ctx->err_detail;
    1.81 +
    1.82 +  return NULL;
    1.83 +}
    1.84 +
    1.85 +
    1.86 +vpx_codec_err_t vpx_codec_destroy(vpx_codec_ctx_t *ctx) {
    1.87 +  vpx_codec_err_t res;
    1.88 +
    1.89 +  if (!ctx)
    1.90 +    res = VPX_CODEC_INVALID_PARAM;
    1.91 +  else if (!ctx->iface || !ctx->priv)
    1.92 +    res = VPX_CODEC_ERROR;
    1.93 +  else {
    1.94 +    if (ctx->priv->alg_priv)
    1.95 +      ctx->iface->destroy(ctx->priv->alg_priv);
    1.96 +
    1.97 +    ctx->iface = NULL;
    1.98 +    ctx->name = NULL;
    1.99 +    ctx->priv = NULL;
   1.100 +    res = VPX_CODEC_OK;
   1.101 +  }
   1.102 +
   1.103 +  return SAVE_STATUS(ctx, res);
   1.104 +}
   1.105 +
   1.106 +
   1.107 +vpx_codec_caps_t vpx_codec_get_caps(vpx_codec_iface_t *iface) {
   1.108 +  return (iface) ? iface->caps : 0;
   1.109 +}
   1.110 +
   1.111 +
   1.112 +vpx_codec_err_t vpx_codec_control_(vpx_codec_ctx_t  *ctx,
   1.113 +                                   int               ctrl_id,
   1.114 +                                   ...) {
   1.115 +  vpx_codec_err_t res;
   1.116 +
   1.117 +  if (!ctx || !ctrl_id)
   1.118 +    res = VPX_CODEC_INVALID_PARAM;
   1.119 +  else if (!ctx->iface || !ctx->priv || !ctx->iface->ctrl_maps)
   1.120 +    res = VPX_CODEC_ERROR;
   1.121 +  else {
   1.122 +    vpx_codec_ctrl_fn_map_t *entry;
   1.123 +
   1.124 +    res = VPX_CODEC_ERROR;
   1.125 +
   1.126 +    for (entry = ctx->iface->ctrl_maps; entry && entry->fn; entry++) {
   1.127 +      if (!entry->ctrl_id || entry->ctrl_id == ctrl_id) {
   1.128 +        va_list  ap;
   1.129 +
   1.130 +        va_start(ap, ctrl_id);
   1.131 +        res = entry->fn(ctx->priv->alg_priv, ctrl_id, ap);
   1.132 +        va_end(ap);
   1.133 +        break;
   1.134 +      }
   1.135 +    }
   1.136 +  }
   1.137 +
   1.138 +  return SAVE_STATUS(ctx, res);
   1.139 +}
   1.140 +
   1.141 +//------------------------------------------------------------------------------
   1.142 +// mmap interface
   1.143 +
   1.144 +vpx_codec_err_t vpx_mmap_alloc(vpx_codec_mmap_t *mmap) {
   1.145 +  unsigned int align = mmap->align ? mmap->align - 1 : 0;
   1.146 +
   1.147 +  if (mmap->flags & VPX_CODEC_MEM_ZERO)
   1.148 +    mmap->priv = calloc(1, mmap->sz + align);
   1.149 +  else
   1.150 +    mmap->priv = malloc(mmap->sz + align);
   1.151 +
   1.152 +  if (mmap->priv == NULL) return VPX_CODEC_MEM_ERROR;
   1.153 +  mmap->base = (void *)((((uintptr_t)mmap->priv) + align) & ~(uintptr_t)align);
   1.154 +  mmap->dtor = vpx_mmap_dtor;
   1.155 +  return VPX_CODEC_OK;
   1.156 +}
   1.157 +
   1.158 +void vpx_mmap_dtor(vpx_codec_mmap_t *mmap) {
   1.159 +  free(mmap->priv);
   1.160 +}
   1.161 +
   1.162 +vpx_codec_err_t vpx_validate_mmaps(const vpx_codec_stream_info_t *si,
   1.163 +                                   const vpx_codec_mmap_t *mmaps,
   1.164 +                                   const mem_req_t *mem_reqs, int nreqs,
   1.165 +                                   vpx_codec_flags_t init_flags) {
   1.166 +  int i;
   1.167 +
   1.168 +  for (i = 0; i < nreqs - 1; ++i) {
   1.169 +    /* Ensure the segment has been allocated */
   1.170 +    if (mmaps[i].base == NULL) {
   1.171 +      return VPX_CODEC_MEM_ERROR;
   1.172 +    }
   1.173 +
   1.174 +    /* Verify variable size segment is big enough for the current si. */
   1.175 +    if (mem_reqs[i].calc_sz != NULL) {
   1.176 +      vpx_codec_dec_cfg_t cfg;
   1.177 +
   1.178 +      cfg.w = si->w;
   1.179 +      cfg.h = si->h;
   1.180 +
   1.181 +      if (mmaps[i].sz < mem_reqs[i].calc_sz(&cfg, init_flags)) {
   1.182 +        return VPX_CODEC_MEM_ERROR;
   1.183 +      }
   1.184 +    }
   1.185 +  }
   1.186 +  return VPX_CODEC_OK;
   1.187 +}

mercurial