media/libvpx/vpx/internal/vpx_codec_internal.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vpx/internal/vpx_codec_internal.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,503 @@
     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 Describes the decoder algorithm interface for algorithm
    1.17 + *        implementations.
    1.18 + *
    1.19 + * This file defines the private structures and data types that are only
    1.20 + * relevant to implementing an algorithm, as opposed to using it.
    1.21 + *
    1.22 + * To create a decoder algorithm class, an interface structure is put
    1.23 + * into the global namespace:
    1.24 + *     <pre>
    1.25 + *     my_codec.c:
    1.26 + *       vpx_codec_iface_t my_codec = {
    1.27 + *           "My Codec v1.0",
    1.28 + *           VPX_CODEC_ALG_ABI_VERSION,
    1.29 + *           ...
    1.30 + *       };
    1.31 + *     </pre>
    1.32 + *
    1.33 + * An application instantiates a specific decoder instance by using
    1.34 + * vpx_codec_init() and a pointer to the algorithm's interface structure:
    1.35 + *     <pre>
    1.36 + *     my_app.c:
    1.37 + *       extern vpx_codec_iface_t my_codec;
    1.38 + *       {
    1.39 + *           vpx_codec_ctx_t algo;
    1.40 + *           res = vpx_codec_init(&algo, &my_codec);
    1.41 + *       }
    1.42 + *     </pre>
    1.43 + *
    1.44 + * Once initialized, the instance is manged using other functions from
    1.45 + * the vpx_codec_* family.
    1.46 + */
    1.47 +#ifndef VPX_CODEC_INTERNAL_H
    1.48 +#define VPX_CODEC_INTERNAL_H
    1.49 +#include "../vpx_decoder.h"
    1.50 +#include "../vpx_encoder.h"
    1.51 +#include <stdarg.h>
    1.52 +
    1.53 +
    1.54 +/*!\brief Current ABI version number
    1.55 + *
    1.56 + * \internal
    1.57 + * If this file is altered in any way that changes the ABI, this value
    1.58 + * must be bumped.  Examples include, but are not limited to, changing
    1.59 + * types, removing or reassigning enums, adding/removing/rearranging
    1.60 + * fields to structures
    1.61 + */
    1.62 +#define VPX_CODEC_INTERNAL_ABI_VERSION (4) /**<\hideinitializer*/
    1.63 +
    1.64 +typedef struct vpx_codec_alg_priv  vpx_codec_alg_priv_t;
    1.65 +typedef struct vpx_codec_priv_enc_mr_cfg vpx_codec_priv_enc_mr_cfg_t;
    1.66 +
    1.67 +/*!\brief init function pointer prototype
    1.68 + *
    1.69 + * Performs algorithm-specific initialization of the decoder context. This
    1.70 + * function is called by the generic vpx_codec_init() wrapper function, so
    1.71 + * plugins implementing this interface may trust the input parameters to be
    1.72 + * properly initialized.
    1.73 + *
    1.74 + * \param[in] ctx   Pointer to this instance's context
    1.75 + * \retval #VPX_CODEC_OK
    1.76 + *     The input stream was recognized and decoder initialized.
    1.77 + * \retval #VPX_CODEC_MEM_ERROR
    1.78 + *     Memory operation failed.
    1.79 + */
    1.80 +typedef vpx_codec_err_t (*vpx_codec_init_fn_t)(vpx_codec_ctx_t *ctx,
    1.81 +                                               vpx_codec_priv_enc_mr_cfg_t *data);
    1.82 +
    1.83 +/*!\brief destroy function pointer prototype
    1.84 + *
    1.85 + * Performs algorithm-specific destruction of the decoder context. This
    1.86 + * function is called by the generic vpx_codec_destroy() wrapper function,
    1.87 + * so plugins implementing this interface may trust the input parameters
    1.88 + * to be properly initialized.
    1.89 + *
    1.90 + * \param[in] ctx   Pointer to this instance's context
    1.91 + * \retval #VPX_CODEC_OK
    1.92 + *     The input stream was recognized and decoder initialized.
    1.93 + * \retval #VPX_CODEC_MEM_ERROR
    1.94 + *     Memory operation failed.
    1.95 + */
    1.96 +typedef vpx_codec_err_t (*vpx_codec_destroy_fn_t)(vpx_codec_alg_priv_t *ctx);
    1.97 +
    1.98 +/*!\brief parse stream info function pointer prototype
    1.99 + *
   1.100 + * Performs high level parsing of the bitstream. This function is called by the
   1.101 + * generic vpx_codec_peek_stream_info() wrapper function, so plugins
   1.102 + * implementing this interface may trust the input parameters to be properly
   1.103 + * initialized.
   1.104 + *
   1.105 + * \param[in]      data    Pointer to a block of data to parse
   1.106 + * \param[in]      data_sz Size of the data buffer
   1.107 + * \param[in,out]  si      Pointer to stream info to update. The size member
   1.108 + *                         \ref MUST be properly initialized, but \ref MAY be
   1.109 + *                         clobbered by the algorithm. This parameter \ref MAY
   1.110 + *                         be NULL.
   1.111 + *
   1.112 + * \retval #VPX_CODEC_OK
   1.113 + *     Bitstream is parsable and stream information updated
   1.114 + */
   1.115 +typedef vpx_codec_err_t (*vpx_codec_peek_si_fn_t)(const uint8_t         *data,
   1.116 +                                                  unsigned int           data_sz,
   1.117 +                                                  vpx_codec_stream_info_t *si);
   1.118 +
   1.119 +/*!\brief Return information about the current stream.
   1.120 + *
   1.121 + * Returns information about the stream that has been parsed during decoding.
   1.122 + *
   1.123 + * \param[in]      ctx     Pointer to this instance's context
   1.124 + * \param[in,out]  si      Pointer to stream info to update. The size member
   1.125 + *                         \ref MUST be properly initialized, but \ref MAY be
   1.126 + *                         clobbered by the algorithm. This parameter \ref MAY
   1.127 + *                         be NULL.
   1.128 + *
   1.129 + * \retval #VPX_CODEC_OK
   1.130 + *     Bitstream is parsable and stream information updated
   1.131 + */
   1.132 +typedef vpx_codec_err_t (*vpx_codec_get_si_fn_t)(vpx_codec_alg_priv_t    *ctx,
   1.133 +                                                 vpx_codec_stream_info_t *si);
   1.134 +
   1.135 +/*!\brief control function pointer prototype
   1.136 + *
   1.137 + * This function is used to exchange algorithm specific data with the decoder
   1.138 + * instance. This can be used to implement features specific to a particular
   1.139 + * algorithm.
   1.140 + *
   1.141 + * This function is called by the generic vpx_codec_control() wrapper
   1.142 + * function, so plugins implementing this interface may trust the input
   1.143 + * parameters to be properly initialized. However,  this interface does not
   1.144 + * provide type safety for the exchanged data or assign meanings to the
   1.145 + * control codes. Those details should be specified in the algorithm's
   1.146 + * header file. In particular, the ctrl_id parameter is guaranteed to exist
   1.147 + * in the algorithm's control mapping table, and the data parameter may be NULL.
   1.148 + *
   1.149 + *
   1.150 + * \param[in]     ctx              Pointer to this instance's context
   1.151 + * \param[in]     ctrl_id          Algorithm specific control identifier
   1.152 + * \param[in,out] data             Data to exchange with algorithm instance.
   1.153 + *
   1.154 + * \retval #VPX_CODEC_OK
   1.155 + *     The internal state data was deserialized.
   1.156 + */
   1.157 +typedef vpx_codec_err_t (*vpx_codec_control_fn_t)(vpx_codec_alg_priv_t  *ctx,
   1.158 +                                                  int                  ctrl_id,
   1.159 +                                                  va_list              ap);
   1.160 +
   1.161 +/*!\brief control function pointer mapping
   1.162 + *
   1.163 + * This structure stores the mapping between control identifiers and
   1.164 + * implementing functions. Each algorithm provides a list of these
   1.165 + * mappings. This list is searched by the vpx_codec_control() wrapper
   1.166 + * function to determine which function to invoke. The special
   1.167 + * value {0, NULL} is used to indicate end-of-list, and must be
   1.168 + * present. The special value {0, <non-null>} can be used as a catch-all
   1.169 + * mapping. This implies that ctrl_id values chosen by the algorithm
   1.170 + * \ref MUST be non-zero.
   1.171 + */
   1.172 +typedef const struct vpx_codec_ctrl_fn_map {
   1.173 +  int                    ctrl_id;
   1.174 +  vpx_codec_control_fn_t   fn;
   1.175 +} vpx_codec_ctrl_fn_map_t;
   1.176 +
   1.177 +/*!\brief decode data function pointer prototype
   1.178 + *
   1.179 + * Processes a buffer of coded data. If the processing results in a new
   1.180 + * decoded frame becoming available, #VPX_CODEC_CB_PUT_SLICE and
   1.181 + * #VPX_CODEC_CB_PUT_FRAME events are generated as appropriate. This
   1.182 + * function is called by the generic vpx_codec_decode() wrapper function,
   1.183 + * so plugins implementing this interface may trust the input parameters
   1.184 + * to be properly initialized.
   1.185 + *
   1.186 + * \param[in] ctx          Pointer to this instance's context
   1.187 + * \param[in] data         Pointer to this block of new coded data. If
   1.188 + *                         NULL, a #VPX_CODEC_CB_PUT_FRAME event is posted
   1.189 + *                         for the previously decoded frame.
   1.190 + * \param[in] data_sz      Size of the coded data, in bytes.
   1.191 + *
   1.192 + * \return Returns #VPX_CODEC_OK if the coded data was processed completely
   1.193 + *         and future pictures can be decoded without error. Otherwise,
   1.194 + *         see the descriptions of the other error codes in ::vpx_codec_err_t
   1.195 + *         for recoverability capabilities.
   1.196 + */
   1.197 +typedef vpx_codec_err_t (*vpx_codec_decode_fn_t)(vpx_codec_alg_priv_t  *ctx,
   1.198 +                                                 const uint8_t         *data,
   1.199 +                                                 unsigned int     data_sz,
   1.200 +                                                 void        *user_priv,
   1.201 +                                                 long         deadline);
   1.202 +
   1.203 +/*!\brief Decoded frames iterator
   1.204 + *
   1.205 + * Iterates over a list of the frames available for display. The iterator
   1.206 + * storage should be initialized to NULL to start the iteration. Iteration is
   1.207 + * complete when this function returns NULL.
   1.208 + *
   1.209 + * The list of available frames becomes valid upon completion of the
   1.210 + * vpx_codec_decode call, and remains valid until the next call to vpx_codec_decode.
   1.211 + *
   1.212 + * \param[in]     ctx      Pointer to this instance's context
   1.213 + * \param[in out] iter     Iterator storage, initialized to NULL
   1.214 + *
   1.215 + * \return Returns a pointer to an image, if one is ready for display. Frames
   1.216 + *         produced will always be in PTS (presentation time stamp) order.
   1.217 + */
   1.218 +typedef vpx_image_t *(*vpx_codec_get_frame_fn_t)(vpx_codec_alg_priv_t *ctx,
   1.219 +                                                 vpx_codec_iter_t     *iter);
   1.220 +
   1.221 +
   1.222 +/*\brief eXternal Memory Allocation memory map get iterator
   1.223 + *
   1.224 + * Iterates over a list of the memory maps requested by the decoder. The
   1.225 + * iterator storage should be initialized to NULL to start the iteration.
   1.226 + * Iteration is complete when this function returns NULL.
   1.227 + *
   1.228 + * \param[in out] iter     Iterator storage, initialized to NULL
   1.229 + *
   1.230 + * \return Returns a pointer to an memory segment descriptor, or NULL to
   1.231 + *         indicate end-of-list.
   1.232 + */
   1.233 +typedef vpx_codec_err_t (*vpx_codec_get_mmap_fn_t)(const vpx_codec_ctx_t      *ctx,
   1.234 +                                                   vpx_codec_mmap_t           *mmap,
   1.235 +                                                   vpx_codec_iter_t           *iter);
   1.236 +
   1.237 +
   1.238 +/*\brief eXternal Memory Allocation memory map set iterator
   1.239 + *
   1.240 + * Sets a memory descriptor inside the decoder instance.
   1.241 + *
   1.242 + * \param[in] ctx      Pointer to this instance's context
   1.243 + * \param[in] mmap     Memory map to store.
   1.244 + *
   1.245 + * \retval #VPX_CODEC_OK
   1.246 + *     The memory map was accepted and stored.
   1.247 + * \retval #VPX_CODEC_MEM_ERROR
   1.248 + *     The memory map was rejected.
   1.249 + */
   1.250 +typedef vpx_codec_err_t (*vpx_codec_set_mmap_fn_t)(vpx_codec_ctx_t         *ctx,
   1.251 +                                                   const vpx_codec_mmap_t  *mmap);
   1.252 +
   1.253 +
   1.254 +typedef vpx_codec_err_t (*vpx_codec_encode_fn_t)(vpx_codec_alg_priv_t  *ctx,
   1.255 +                                                 const vpx_image_t     *img,
   1.256 +                                                 vpx_codec_pts_t        pts,
   1.257 +                                                 unsigned long          duration,
   1.258 +                                                 vpx_enc_frame_flags_t  flags,
   1.259 +                                                 unsigned long          deadline);
   1.260 +typedef const vpx_codec_cx_pkt_t *(*vpx_codec_get_cx_data_fn_t)(vpx_codec_alg_priv_t *ctx,
   1.261 +                                                                vpx_codec_iter_t     *iter);
   1.262 +
   1.263 +typedef vpx_codec_err_t
   1.264 +(*vpx_codec_enc_config_set_fn_t)(vpx_codec_alg_priv_t       *ctx,
   1.265 +                                 const vpx_codec_enc_cfg_t  *cfg);
   1.266 +typedef vpx_fixed_buf_t *
   1.267 +(*vpx_codec_get_global_headers_fn_t)(vpx_codec_alg_priv_t   *ctx);
   1.268 +
   1.269 +typedef vpx_image_t *
   1.270 +(*vpx_codec_get_preview_frame_fn_t)(vpx_codec_alg_priv_t   *ctx);
   1.271 +
   1.272 +typedef vpx_codec_err_t
   1.273 +(*vpx_codec_enc_mr_get_mem_loc_fn_t)(const vpx_codec_enc_cfg_t     *cfg,
   1.274 +                                     void **mem_loc);
   1.275 +
   1.276 +/*!\brief usage configuration mapping
   1.277 + *
   1.278 + * This structure stores the mapping between usage identifiers and
   1.279 + * configuration structures. Each algorithm provides a list of these
   1.280 + * mappings. This list is searched by the vpx_codec_enc_config_default()
   1.281 + * wrapper function to determine which config to return. The special value
   1.282 + * {-1, {0}} is used to indicate end-of-list, and must be present. At least
   1.283 + * one mapping must be present, in addition to the end-of-list.
   1.284 + *
   1.285 + */
   1.286 +typedef const struct vpx_codec_enc_cfg_map {
   1.287 +  int                 usage;
   1.288 +  vpx_codec_enc_cfg_t cfg;
   1.289 +} vpx_codec_enc_cfg_map_t;
   1.290 +
   1.291 +#define NOT_IMPLEMENTED 0
   1.292 +
   1.293 +/*!\brief Decoder algorithm interface interface
   1.294 + *
   1.295 + * All decoders \ref MUST expose a variable of this type.
   1.296 + */
   1.297 +struct vpx_codec_iface {
   1.298 +  const char               *name;        /**< Identification String  */
   1.299 +  int                       abi_version; /**< Implemented ABI version */
   1.300 +  vpx_codec_caps_t          caps;    /**< Decoder capabilities */
   1.301 +  vpx_codec_init_fn_t       init;    /**< \copydoc ::vpx_codec_init_fn_t */
   1.302 +  vpx_codec_destroy_fn_t    destroy;     /**< \copydoc ::vpx_codec_destroy_fn_t */
   1.303 +  vpx_codec_ctrl_fn_map_t  *ctrl_maps;   /**< \copydoc ::vpx_codec_ctrl_fn_map_t */
   1.304 +  vpx_codec_get_mmap_fn_t   get_mmap;    /**< \copydoc ::vpx_codec_get_mmap_fn_t */
   1.305 +  vpx_codec_set_mmap_fn_t   set_mmap;    /**< \copydoc ::vpx_codec_set_mmap_fn_t */
   1.306 +  struct vpx_codec_dec_iface {
   1.307 +    vpx_codec_peek_si_fn_t    peek_si;     /**< \copydoc ::vpx_codec_peek_si_fn_t */
   1.308 +    vpx_codec_get_si_fn_t     get_si;      /**< \copydoc ::vpx_codec_get_si_fn_t */
   1.309 +    vpx_codec_decode_fn_t     decode;      /**< \copydoc ::vpx_codec_decode_fn_t */
   1.310 +    vpx_codec_get_frame_fn_t  get_frame;   /**< \copydoc ::vpx_codec_get_frame_fn_t */
   1.311 +  } dec;
   1.312 +  struct vpx_codec_enc_iface {
   1.313 +    vpx_codec_enc_cfg_map_t           *cfg_maps;      /**< \copydoc ::vpx_codec_enc_cfg_map_t */
   1.314 +    vpx_codec_encode_fn_t              encode;        /**< \copydoc ::vpx_codec_encode_fn_t */
   1.315 +    vpx_codec_get_cx_data_fn_t         get_cx_data;   /**< \copydoc ::vpx_codec_get_cx_data_fn_t */
   1.316 +    vpx_codec_enc_config_set_fn_t      cfg_set;       /**< \copydoc ::vpx_codec_enc_config_set_fn_t */
   1.317 +    vpx_codec_get_global_headers_fn_t  get_glob_hdrs; /**< \copydoc ::vpx_codec_get_global_headers_fn_t */
   1.318 +    vpx_codec_get_preview_frame_fn_t   get_preview;   /**< \copydoc ::vpx_codec_get_preview_frame_fn_t */
   1.319 +    vpx_codec_enc_mr_get_mem_loc_fn_t  mr_get_mem_loc;   /**< \copydoc ::vpx_codec_enc_mr_get_mem_loc_fn_t */
   1.320 +  } enc;
   1.321 +};
   1.322 +
   1.323 +/*!\brief Callback function pointer / user data pair storage */
   1.324 +typedef struct vpx_codec_priv_cb_pair {
   1.325 +  union {
   1.326 +    vpx_codec_put_frame_cb_fn_t    put_frame;
   1.327 +    vpx_codec_put_slice_cb_fn_t    put_slice;
   1.328 +  } u;
   1.329 +  void                            *user_priv;
   1.330 +} vpx_codec_priv_cb_pair_t;
   1.331 +
   1.332 +
   1.333 +/*!\brief Instance private storage
   1.334 + *
   1.335 + * This structure is allocated by the algorithm's init function. It can be
   1.336 + * extended in one of two ways. First, a second, algorithm specific structure
   1.337 + * can be allocated and the priv member pointed to it. Alternatively, this
   1.338 + * structure can be made the first member of the algorithm specific structure,
   1.339 + * and the pointer cast to the proper type.
   1.340 + */
   1.341 +struct vpx_codec_priv {
   1.342 +  unsigned int                    sz;
   1.343 +  vpx_codec_iface_t              *iface;
   1.344 +  struct vpx_codec_alg_priv      *alg_priv;
   1.345 +  const char                     *err_detail;
   1.346 +  vpx_codec_flags_t               init_flags;
   1.347 +  struct {
   1.348 +    vpx_codec_priv_cb_pair_t    put_frame_cb;
   1.349 +    vpx_codec_priv_cb_pair_t    put_slice_cb;
   1.350 +  } dec;
   1.351 +  struct {
   1.352 +    int                         tbd;
   1.353 +    struct vpx_fixed_buf        cx_data_dst_buf;
   1.354 +    unsigned int                cx_data_pad_before;
   1.355 +    unsigned int                cx_data_pad_after;
   1.356 +    vpx_codec_cx_pkt_t          cx_data_pkt;
   1.357 +    unsigned int                total_encoders;
   1.358 +  } enc;
   1.359 +};
   1.360 +
   1.361 +/*
   1.362 + * Multi-resolution encoding internal configuration
   1.363 + */
   1.364 +struct vpx_codec_priv_enc_mr_cfg
   1.365 +{
   1.366 +    unsigned int           mr_total_resolutions;
   1.367 +    unsigned int           mr_encoder_id;
   1.368 +    struct vpx_rational    mr_down_sampling_factor;
   1.369 +    void*                  mr_low_res_mode_info;
   1.370 +};
   1.371 +
   1.372 +#undef VPX_CTRL_USE_TYPE
   1.373 +#define VPX_CTRL_USE_TYPE(id, typ) \
   1.374 +  static typ id##__value(va_list args) {return va_arg(args, typ);} \
   1.375 +  static typ id##__convert(void *x)\
   1.376 +  {\
   1.377 +    union\
   1.378 +    {\
   1.379 +      void *x;\
   1.380 +      typ   d;\
   1.381 +    } u;\
   1.382 +    u.x = x;\
   1.383 +    return u.d;\
   1.384 +  }
   1.385 +
   1.386 +
   1.387 +#undef VPX_CTRL_USE_TYPE_DEPRECATED
   1.388 +#define VPX_CTRL_USE_TYPE_DEPRECATED(id, typ) \
   1.389 +  static typ id##__value(va_list args) {return va_arg(args, typ);} \
   1.390 +  static typ id##__convert(void *x)\
   1.391 +  {\
   1.392 +    union\
   1.393 +    {\
   1.394 +      void *x;\
   1.395 +      typ   d;\
   1.396 +    } u;\
   1.397 +    u.x = x;\
   1.398 +    return u.d;\
   1.399 +  }
   1.400 +
   1.401 +#define CAST(id, arg) id##__value(arg)
   1.402 +#define RECAST(id, x) id##__convert(x)
   1.403 +
   1.404 +
   1.405 +/* CODEC_INTERFACE convenience macro
   1.406 + *
   1.407 + * By convention, each codec interface is a struct with extern linkage, where
   1.408 + * the symbol is suffixed with _algo. A getter function is also defined to
   1.409 + * return a pointer to the struct, since in some cases it's easier to work
   1.410 + * with text symbols than data symbols (see issue #169). This function has
   1.411 + * the same name as the struct, less the _algo suffix. The CODEC_INTERFACE
   1.412 + * macro is provided to define this getter function automatically.
   1.413 + */
   1.414 +#define CODEC_INTERFACE(id)\
   1.415 +  vpx_codec_iface_t* id(void) { return &id##_algo; }\
   1.416 +  vpx_codec_iface_t  id##_algo
   1.417 +
   1.418 +
   1.419 +/* Internal Utility Functions
   1.420 + *
   1.421 + * The following functions are intended to be used inside algorithms as
   1.422 + * utilities for manipulating vpx_codec_* data structures.
   1.423 + */
   1.424 +struct vpx_codec_pkt_list {
   1.425 +  unsigned int            cnt;
   1.426 +  unsigned int            max;
   1.427 +  struct vpx_codec_cx_pkt pkts[1];
   1.428 +};
   1.429 +
   1.430 +#define vpx_codec_pkt_list_decl(n)\
   1.431 +  union {struct vpx_codec_pkt_list head;\
   1.432 +    struct {struct vpx_codec_pkt_list head;\
   1.433 +      struct vpx_codec_cx_pkt    pkts[n];} alloc;}
   1.434 +
   1.435 +#define vpx_codec_pkt_list_init(m)\
   1.436 +  (m)->alloc.head.cnt = 0,\
   1.437 +                        (m)->alloc.head.max = sizeof((m)->alloc.pkts) / sizeof((m)->alloc.pkts[0])
   1.438 +
   1.439 +int
   1.440 +vpx_codec_pkt_list_add(struct vpx_codec_pkt_list *,
   1.441 +                       const struct vpx_codec_cx_pkt *);
   1.442 +
   1.443 +const vpx_codec_cx_pkt_t *
   1.444 +vpx_codec_pkt_list_get(struct vpx_codec_pkt_list *list,
   1.445 +                       vpx_codec_iter_t           *iter);
   1.446 +
   1.447 +
   1.448 +#include <stdio.h>
   1.449 +#include <setjmp.h>
   1.450 +struct vpx_internal_error_info {
   1.451 +  vpx_codec_err_t  error_code;
   1.452 +  int              has_detail;
   1.453 +  char             detail[80];
   1.454 +  int              setjmp;
   1.455 +  jmp_buf          jmp;
   1.456 +};
   1.457 +
   1.458 +static void vpx_internal_error(struct vpx_internal_error_info *info,
   1.459 +                               vpx_codec_err_t                 error,
   1.460 +                               const char                     *fmt,
   1.461 +                               ...) {
   1.462 +  va_list ap;
   1.463 +
   1.464 +  info->error_code = error;
   1.465 +  info->has_detail = 0;
   1.466 +
   1.467 +  if (fmt) {
   1.468 +    size_t  sz = sizeof(info->detail);
   1.469 +
   1.470 +    info->has_detail = 1;
   1.471 +    va_start(ap, fmt);
   1.472 +    vsnprintf(info->detail, sz - 1, fmt, ap);
   1.473 +    va_end(ap);
   1.474 +    info->detail[sz - 1] = '\0';
   1.475 +  }
   1.476 +
   1.477 +  if (info->setjmp)
   1.478 +    longjmp(info->jmp, info->error_code);
   1.479 +}
   1.480 +
   1.481 +//------------------------------------------------------------------------------
   1.482 +// mmap interface
   1.483 +
   1.484 +typedef struct {
   1.485 +  unsigned int   id;
   1.486 +  unsigned long  sz;
   1.487 +  unsigned int   align;
   1.488 +  unsigned int   flags;
   1.489 +  unsigned long (*calc_sz)(const vpx_codec_dec_cfg_t *, vpx_codec_flags_t);
   1.490 +} mem_req_t;
   1.491 +
   1.492 +// Allocates mmap.priv and sets mmap.base based on mmap.sz/align/flags
   1.493 +// requirements.
   1.494 +// Returns #VPX_CODEC_OK on success, #VPX_CODEC_MEM_ERROR otherwise.
   1.495 +vpx_codec_err_t vpx_mmap_alloc(vpx_codec_mmap_t *mmap);
   1.496 +
   1.497 +// Frees mmap.base allocated by a call to vpx_mmap_alloc().
   1.498 +void vpx_mmap_dtor(vpx_codec_mmap_t *mmap);
   1.499 +
   1.500 +// Checks each mmap has the size requirement specificied by mem_reqs.
   1.501 +// Returns #VPX_CODEC_OK on success, #VPX_CODEC_MEM_ERROR otherwise.
   1.502 +vpx_codec_err_t vpx_validate_mmaps(const vpx_codec_stream_info_t *si,
   1.503 +                                   const vpx_codec_mmap_t *mmaps,
   1.504 +                                   const mem_req_t *mem_reqs, int nreqs,
   1.505 +                                   vpx_codec_flags_t init_flags);
   1.506 +#endif

mercurial