LCOV - code coverage report
Current view: directory - media/libvpx/vp8 - vp8_dx_iface.c (source / functions) Found Hit Coverage
Test: app.info Lines: 271 0 0.0 %
Date: 2012-06-02 Functions: 25 0 0.0 %

       1                 : /*
       2                 :  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
       3                 :  *
       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.
       9                 :  */
      10                 : 
      11                 : 
      12                 : #include <stdlib.h>
      13                 : #include <string.h>
      14                 : #include "vpx/vpx_decoder.h"
      15                 : #include "vpx/vp8dx.h"
      16                 : #include "vpx/internal/vpx_codec_internal.h"
      17                 : #include "vpx_version.h"
      18                 : #include "common/onyxd.h"
      19                 : #include "decoder/onyxd_int.h"
      20                 : 
      21                 : #define VP8_CAP_POSTPROC (CONFIG_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
      22                 : #define VP8_CAP_ERROR_CONCEALMENT (CONFIG_ERROR_CONCEALMENT ? \
      23                 :                                     VPX_CODEC_CAP_ERROR_CONCEALMENT : 0)
      24                 : 
      25                 : typedef vpx_codec_stream_info_t  vp8_stream_info_t;
      26                 : 
      27                 : /* Structures for handling memory allocations */
      28                 : typedef enum
      29                 : {
      30                 :     VP8_SEG_ALG_PRIV     = 256,
      31                 :     VP8_SEG_MAX
      32                 : } mem_seg_id_t;
      33                 : #define NELEMENTS(x) ((int)(sizeof(x)/sizeof(x[0])))
      34                 : 
      35                 : static unsigned long vp8_priv_sz(const vpx_codec_dec_cfg_t *si, vpx_codec_flags_t);
      36                 : 
      37                 : typedef struct
      38                 : {
      39                 :     unsigned int   id;
      40                 :     unsigned long  sz;
      41                 :     unsigned int   align;
      42                 :     unsigned int   flags;
      43                 :     unsigned long(*calc_sz)(const vpx_codec_dec_cfg_t *, vpx_codec_flags_t);
      44                 : } mem_req_t;
      45                 : 
      46                 : static const mem_req_t vp8_mem_req_segs[] =
      47                 : {
      48                 :     {VP8_SEG_ALG_PRIV,    0, 8, VPX_CODEC_MEM_ZERO, vp8_priv_sz},
      49                 :     {VP8_SEG_MAX, 0, 0, 0, NULL}
      50                 : };
      51                 : 
      52                 : struct vpx_codec_alg_priv
      53                 : {
      54                 :     vpx_codec_priv_t        base;
      55                 :     vpx_codec_mmap_t        mmaps[NELEMENTS(vp8_mem_req_segs)-1];
      56                 :     vpx_codec_dec_cfg_t     cfg;
      57                 :     vp8_stream_info_t       si;
      58                 :     int                     defer_alloc;
      59                 :     int                     decoder_init;
      60                 :     VP8D_PTR                pbi;
      61                 :     int                     postproc_cfg_set;
      62                 :     vp8_postproc_cfg_t      postproc_cfg;
      63                 : #if CONFIG_POSTPROC_VISUALIZER
      64                 :     unsigned int            dbg_postproc_flag;
      65                 :     int                     dbg_color_ref_frame_flag;
      66                 :     int                     dbg_color_mb_modes_flag;
      67                 :     int                     dbg_color_b_modes_flag;
      68                 :     int                     dbg_display_mv_flag;
      69                 : #endif
      70                 :     vpx_image_t             img;
      71                 :     int                     img_setup;
      72                 :     int                     img_avail;
      73                 : };
      74                 : 
      75               0 : static unsigned long vp8_priv_sz(const vpx_codec_dec_cfg_t *si, vpx_codec_flags_t flags)
      76                 : {
      77                 :     /* Although this declaration is constant, we can't use it in the requested
      78                 :      * segments list because we want to define the requested segments list
      79                 :      * before defining the private type (so that the number of memory maps is
      80                 :      * known)
      81                 :      */
      82                 :     (void)si;
      83               0 :     return sizeof(vpx_codec_alg_priv_t);
      84                 : }
      85                 : 
      86                 : 
      87               0 : static void vp8_mmap_dtor(vpx_codec_mmap_t *mmap)
      88                 : {
      89               0 :     free(mmap->priv);
      90               0 : }
      91                 : 
      92               0 : static vpx_codec_err_t vp8_mmap_alloc(vpx_codec_mmap_t *mmap)
      93                 : {
      94                 :     vpx_codec_err_t  res;
      95                 :     unsigned int   align;
      96                 : 
      97               0 :     align = mmap->align ? mmap->align - 1 : 0;
      98                 : 
      99               0 :     if (mmap->flags & VPX_CODEC_MEM_ZERO)
     100               0 :         mmap->priv = calloc(1, mmap->sz + align);
     101                 :     else
     102               0 :         mmap->priv = malloc(mmap->sz + align);
     103                 : 
     104               0 :     res = (mmap->priv) ? VPX_CODEC_OK : VPX_CODEC_MEM_ERROR;
     105               0 :     mmap->base = (void *)((((uintptr_t)mmap->priv) + align) & ~(uintptr_t)align);
     106               0 :     mmap->dtor = vp8_mmap_dtor;
     107               0 :     return res;
     108                 : }
     109                 : 
     110               0 : static vpx_codec_err_t vp8_validate_mmaps(const vp8_stream_info_t *si,
     111                 :         const vpx_codec_mmap_t        *mmaps,
     112                 :         vpx_codec_flags_t              init_flags)
     113                 : {
     114                 :     int i;
     115               0 :     vpx_codec_err_t res = VPX_CODEC_OK;
     116                 : 
     117               0 :     for (i = 0; i < NELEMENTS(vp8_mem_req_segs) - 1; i++)
     118                 :     {
     119                 :         /* Ensure the segment has been allocated */
     120               0 :         if (!mmaps[i].base)
     121                 :         {
     122               0 :             res = VPX_CODEC_MEM_ERROR;
     123               0 :             break;
     124                 :         }
     125                 : 
     126                 :         /* Verify variable size segment is big enough for the current si. */
     127               0 :         if (vp8_mem_req_segs[i].calc_sz)
     128                 :         {
     129                 :             vpx_codec_dec_cfg_t cfg;
     130                 : 
     131               0 :             cfg.w = si->w;
     132               0 :             cfg.h = si->h;
     133                 : 
     134               0 :             if (mmaps[i].sz < vp8_mem_req_segs[i].calc_sz(&cfg, init_flags))
     135                 :             {
     136               0 :                 res = VPX_CODEC_MEM_ERROR;
     137               0 :                 break;
     138                 :             }
     139                 :         }
     140                 :     }
     141                 : 
     142               0 :     return res;
     143                 : }
     144                 : 
     145               0 : static void vp8_init_ctx(vpx_codec_ctx_t *ctx, const vpx_codec_mmap_t *mmap)
     146                 : {
     147                 :     int i;
     148                 : 
     149               0 :     ctx->priv = mmap->base;
     150               0 :     ctx->priv->sz = sizeof(*ctx->priv);
     151               0 :     ctx->priv->iface = ctx->iface;
     152               0 :     ctx->priv->alg_priv = mmap->base;
     153                 : 
     154               0 :     for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++)
     155               0 :         ctx->priv->alg_priv->mmaps[i].id = vp8_mem_req_segs[i].id;
     156                 : 
     157               0 :     ctx->priv->alg_priv->mmaps[0] = *mmap;
     158               0 :     ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si);
     159               0 :     ctx->priv->init_flags = ctx->init_flags;
     160                 : 
     161               0 :     if (ctx->config.dec)
     162                 :     {
     163                 :         /* Update the reference to the config structure to an internal copy. */
     164               0 :         ctx->priv->alg_priv->cfg = *ctx->config.dec;
     165               0 :         ctx->config.dec = &ctx->priv->alg_priv->cfg;
     166                 :     }
     167               0 : }
     168                 : 
     169               0 : static void *mmap_lkup(vpx_codec_alg_priv_t *ctx, unsigned int id)
     170                 : {
     171                 :     int i;
     172                 : 
     173               0 :     for (i = 0; i < NELEMENTS(ctx->mmaps); i++)
     174               0 :         if (ctx->mmaps[i].id == id)
     175               0 :             return ctx->mmaps[i].base;
     176                 : 
     177               0 :     return NULL;
     178                 : }
     179               0 : static void vp8_finalize_mmaps(vpx_codec_alg_priv_t *ctx)
     180                 : {
     181                 :     /* nothing to clean up */
     182               0 : }
     183                 : 
     184               0 : static vpx_codec_err_t vp8_init(vpx_codec_ctx_t *ctx)
     185                 : {
     186               0 :     vpx_codec_err_t        res = VPX_CODEC_OK;
     187                 : 
     188                 :     /* This function only allocates space for the vpx_codec_alg_priv_t
     189                 :      * structure. More memory may be required at the time the stream
     190                 :      * information becomes known.
     191                 :      */
     192               0 :     if (!ctx->priv)
     193                 :     {
     194                 :         vpx_codec_mmap_t mmap;
     195                 : 
     196               0 :         mmap.id = vp8_mem_req_segs[0].id;
     197               0 :         mmap.sz = sizeof(vpx_codec_alg_priv_t);
     198               0 :         mmap.align = vp8_mem_req_segs[0].align;
     199               0 :         mmap.flags = vp8_mem_req_segs[0].flags;
     200                 : 
     201               0 :         res = vp8_mmap_alloc(&mmap);
     202                 : 
     203               0 :         if (!res)
     204                 :         {
     205               0 :             vp8_init_ctx(ctx, &mmap);
     206                 : 
     207               0 :             ctx->priv->alg_priv->defer_alloc = 1;
     208                 :             /*post processing level initialized to do nothing */
     209                 :         }
     210                 :     }
     211                 : 
     212               0 :     return res;
     213                 : }
     214                 : 
     215               0 : static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx)
     216                 : {
     217                 :     int i;
     218                 : 
     219               0 :     vp8dx_remove_decompressor(ctx->pbi);
     220                 : 
     221               0 :     for (i = NELEMENTS(ctx->mmaps) - 1; i >= 0; i--)
     222                 :     {
     223               0 :         if (ctx->mmaps[i].dtor)
     224               0 :             ctx->mmaps[i].dtor(&ctx->mmaps[i]);
     225                 :     }
     226                 : 
     227               0 :     return VPX_CODEC_OK;
     228                 : }
     229                 : 
     230               0 : static vpx_codec_err_t vp8_peek_si(const uint8_t         *data,
     231                 :                                    unsigned int           data_sz,
     232                 :                                    vpx_codec_stream_info_t *si)
     233                 : {
     234               0 :     vpx_codec_err_t res = VPX_CODEC_OK;
     235                 : 
     236               0 :     if(data + data_sz <= data)
     237               0 :         res = VPX_CODEC_INVALID_PARAM;
     238                 :     else
     239                 :     {
     240                 :         /* Parse uncompresssed part of key frame header.
     241                 :          * 3 bytes:- including version, frame type and an offset
     242                 :          * 3 bytes:- sync code (0x9d, 0x01, 0x2a)
     243                 :          * 4 bytes:- including image width and height in the lowest 14 bits
     244                 :          *           of each 2-byte value.
     245                 :          */
     246               0 :         si->is_kf = 0;
     247                 : 
     248               0 :         if (data_sz >= 10 && !(data[0] & 0x01))  /* I-Frame */
     249               0 :         {
     250               0 :             const uint8_t *c = data + 3;
     251               0 :             si->is_kf = 1;
     252                 : 
     253                 :             /* vet via sync code */
     254               0 :             if (c[0] != 0x9d || c[1] != 0x01 || c[2] != 0x2a)
     255               0 :                 res = VPX_CODEC_UNSUP_BITSTREAM;
     256                 : 
     257               0 :             si->w = (c[3] | (c[4] << 8)) & 0x3fff;
     258               0 :             si->h = (c[5] | (c[6] << 8)) & 0x3fff;
     259                 : 
     260                 :             /*printf("w=%d, h=%d\n", si->w, si->h);*/
     261               0 :             if (!(si->h | si->w))
     262               0 :                 res = VPX_CODEC_UNSUP_BITSTREAM;
     263                 :         }
     264                 :         else
     265               0 :             res = VPX_CODEC_UNSUP_BITSTREAM;
     266                 :     }
     267                 : 
     268               0 :     return res;
     269                 : 
     270                 : }
     271                 : 
     272               0 : static vpx_codec_err_t vp8_get_si(vpx_codec_alg_priv_t    *ctx,
     273                 :                                   vpx_codec_stream_info_t *si)
     274                 : {
     275                 : 
     276                 :     unsigned int sz;
     277                 : 
     278               0 :     if (si->sz >= sizeof(vp8_stream_info_t))
     279               0 :         sz = sizeof(vp8_stream_info_t);
     280                 :     else
     281               0 :         sz = sizeof(vpx_codec_stream_info_t);
     282                 : 
     283               0 :     memcpy(si, &ctx->si, sz);
     284               0 :     si->sz = sz;
     285                 : 
     286               0 :     return VPX_CODEC_OK;
     287                 : }
     288                 : 
     289                 : 
     290                 : static vpx_codec_err_t
     291               0 : update_error_state(vpx_codec_alg_priv_t                 *ctx,
     292                 :                    const struct vpx_internal_error_info *error)
     293                 : {
     294                 :     vpx_codec_err_t res;
     295                 : 
     296               0 :     if ((res = error->error_code))
     297               0 :         ctx->base.err_detail = error->has_detail
     298                 :                                ? error->detail
     299               0 :                                : NULL;
     300                 : 
     301               0 :     return res;
     302                 : }
     303                 : 
     304               0 : static void yuvconfig2image(vpx_image_t               *img,
     305                 :                             const YV12_BUFFER_CONFIG  *yv12,
     306                 :                             void                      *user_priv)
     307                 : {
     308                 :     /** vpx_img_wrap() doesn't allow specifying independent strides for
     309                 :       * the Y, U, and V planes, nor other alignment adjustments that
     310                 :       * might be representable by a YV12_BUFFER_CONFIG, so we just
     311                 :       * initialize all the fields.*/
     312               0 :     img->fmt = yv12->clrtype == REG_YUV ?
     313                 :         VPX_IMG_FMT_I420 : VPX_IMG_FMT_VPXI420;
     314               0 :     img->w = yv12->y_stride;
     315               0 :     img->h = (yv12->y_height + 2 * VP8BORDERINPIXELS + 15) & ~15;
     316               0 :     img->d_w = yv12->y_width;
     317               0 :     img->d_h = yv12->y_height;
     318               0 :     img->x_chroma_shift = 1;
     319               0 :     img->y_chroma_shift = 1;
     320               0 :     img->planes[VPX_PLANE_Y] = yv12->y_buffer;
     321               0 :     img->planes[VPX_PLANE_U] = yv12->u_buffer;
     322               0 :     img->planes[VPX_PLANE_V] = yv12->v_buffer;
     323               0 :     img->planes[VPX_PLANE_ALPHA] = NULL;
     324               0 :     img->stride[VPX_PLANE_Y] = yv12->y_stride;
     325               0 :     img->stride[VPX_PLANE_U] = yv12->uv_stride;
     326               0 :     img->stride[VPX_PLANE_V] = yv12->uv_stride;
     327               0 :     img->stride[VPX_PLANE_ALPHA] = yv12->y_stride;
     328               0 :     img->bps = 12;
     329               0 :     img->user_priv = user_priv;
     330               0 :     img->img_data = yv12->buffer_alloc;
     331               0 :     img->img_data_owner = 0;
     332               0 :     img->self_allocd = 0;
     333               0 : }
     334                 : 
     335               0 : static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t  *ctx,
     336                 :                                   const uint8_t         *data,
     337                 :                                   unsigned int            data_sz,
     338                 :                                   void                    *user_priv,
     339                 :                                   long                    deadline)
     340                 : {
     341               0 :     vpx_codec_err_t res = VPX_CODEC_OK;
     342                 : 
     343               0 :     ctx->img_avail = 0;
     344                 : 
     345                 :     /* Determine the stream parameters. Note that we rely on peek_si to
     346                 :      * validate that we have a buffer that does not wrap around the top
     347                 :      * of the heap.
     348                 :      */
     349               0 :     if (!ctx->si.h)
     350               0 :         res = ctx->base.iface->dec.peek_si(data, data_sz, &ctx->si);
     351                 : 
     352                 : 
     353                 :     /* Perform deferred allocations, if required */
     354               0 :     if (!res && ctx->defer_alloc)
     355                 :     {
     356                 :         int i;
     357                 : 
     358               0 :         for (i = 1; !res && i < NELEMENTS(ctx->mmaps); i++)
     359                 :         {
     360                 :             vpx_codec_dec_cfg_t cfg;
     361                 : 
     362               0 :             cfg.w = ctx->si.w;
     363               0 :             cfg.h = ctx->si.h;
     364               0 :             ctx->mmaps[i].id = vp8_mem_req_segs[i].id;
     365               0 :             ctx->mmaps[i].sz = vp8_mem_req_segs[i].sz;
     366               0 :             ctx->mmaps[i].align = vp8_mem_req_segs[i].align;
     367               0 :             ctx->mmaps[i].flags = vp8_mem_req_segs[i].flags;
     368                 : 
     369               0 :             if (!ctx->mmaps[i].sz)
     370               0 :                 ctx->mmaps[i].sz = vp8_mem_req_segs[i].calc_sz(&cfg,
     371                 :                                    ctx->base.init_flags);
     372                 : 
     373               0 :             res = vp8_mmap_alloc(&ctx->mmaps[i]);
     374                 :         }
     375                 : 
     376               0 :         if (!res)
     377               0 :             vp8_finalize_mmaps(ctx);
     378                 : 
     379               0 :         ctx->defer_alloc = 0;
     380                 :     }
     381                 : 
     382                 :     /* Initialize the decoder instance on the first frame*/
     383               0 :     if (!res && !ctx->decoder_init)
     384                 :     {
     385               0 :         res = vp8_validate_mmaps(&ctx->si, ctx->mmaps, ctx->base.init_flags);
     386                 : 
     387               0 :         if (!res)
     388                 :         {
     389                 :             VP8D_CONFIG oxcf;
     390                 :             VP8D_PTR optr;
     391                 : 
     392               0 :             vp8dx_initialize();
     393                 : 
     394               0 :             oxcf.Width = ctx->si.w;
     395               0 :             oxcf.Height = ctx->si.h;
     396               0 :             oxcf.Version = 9;
     397               0 :             oxcf.postprocess = 0;
     398               0 :             oxcf.max_threads = ctx->cfg.threads;
     399               0 :             oxcf.error_concealment =
     400               0 :                     (ctx->base.init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT);
     401               0 :             oxcf.input_partition =
     402               0 :                     (ctx->base.init_flags & VPX_CODEC_USE_INPUT_PARTITION);
     403                 : 
     404               0 :             optr = vp8dx_create_decompressor(&oxcf);
     405                 : 
     406                 :             /* If postprocessing was enabled by the application and a
     407                 :              * configuration has not been provided, default it.
     408                 :              */
     409               0 :             if (!ctx->postproc_cfg_set
     410               0 :                 && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC))
     411                 :             {
     412               0 :                 ctx->postproc_cfg.post_proc_flag =
     413                 :                     VP8_DEBLOCK | VP8_DEMACROBLOCK;
     414               0 :                 ctx->postproc_cfg.deblocking_level = 4;
     415               0 :                 ctx->postproc_cfg.noise_level = 0;
     416                 :             }
     417                 : 
     418               0 :             if (!optr)
     419               0 :                 res = VPX_CODEC_ERROR;
     420                 :             else
     421               0 :                 ctx->pbi = optr;
     422                 :         }
     423                 : 
     424               0 :         ctx->decoder_init = 1;
     425                 :     }
     426                 : 
     427               0 :     if (!res && ctx->pbi)
     428                 :     {
     429                 :         YV12_BUFFER_CONFIG sd;
     430               0 :         int64_t time_stamp = 0, time_end_stamp = 0;
     431               0 :         vp8_ppflags_t flags = {0};
     432                 : 
     433               0 :         if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)
     434                 :         {
     435               0 :             flags.post_proc_flag= ctx->postproc_cfg.post_proc_flag
     436                 : #if CONFIG_POSTPROC_VISUALIZER
     437                 : 
     438                 :                                 | ((ctx->dbg_color_ref_frame_flag != 0) ? VP8D_DEBUG_CLR_FRM_REF_BLKS : 0)
     439                 :                                 | ((ctx->dbg_color_mb_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
     440                 :                                 | ((ctx->dbg_color_b_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
     441                 :                                 | ((ctx->dbg_display_mv_flag != 0) ? VP8D_DEBUG_DRAW_MV : 0)
     442                 : #endif
     443                 :                                 ;
     444               0 :             flags.deblocking_level      = ctx->postproc_cfg.deblocking_level;
     445               0 :             flags.noise_level           = ctx->postproc_cfg.noise_level;
     446                 : #if CONFIG_POSTPROC_VISUALIZER
     447                 :             flags.display_ref_frame_flag= ctx->dbg_color_ref_frame_flag;
     448                 :             flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag;
     449                 :             flags.display_b_modes_flag  = ctx->dbg_color_b_modes_flag;
     450                 :             flags.display_mv_flag       = ctx->dbg_display_mv_flag;
     451                 : #endif
     452                 :         }
     453                 : 
     454               0 :         if (vp8dx_receive_compressed_data(ctx->pbi, data_sz, data, deadline))
     455                 :         {
     456               0 :             VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
     457               0 :             res = update_error_state(ctx, &pbi->common.error);
     458                 :         }
     459                 : 
     460               0 :         if (!res && 0 == vp8dx_get_raw_frame(ctx->pbi, &sd, &time_stamp, &time_end_stamp, &flags))
     461                 :         {
     462               0 :             yuvconfig2image(&ctx->img, &sd, user_priv);
     463               0 :             ctx->img_avail = 1;
     464                 :         }
     465                 :     }
     466                 : 
     467               0 :     return res;
     468                 : }
     469                 : 
     470               0 : static vpx_image_t *vp8_get_frame(vpx_codec_alg_priv_t  *ctx,
     471                 :                                   vpx_codec_iter_t      *iter)
     472                 : {
     473               0 :     vpx_image_t *img = NULL;
     474                 : 
     475               0 :     if (ctx->img_avail)
     476                 :     {
     477                 :         /* iter acts as a flip flop, so an image is only returned on the first
     478                 :          * call to get_frame.
     479                 :          */
     480               0 :         if (!(*iter))
     481                 :         {
     482               0 :             img = &ctx->img;
     483               0 :             *iter = img;
     484                 :         }
     485                 :     }
     486                 : 
     487               0 :     return img;
     488                 : }
     489                 : 
     490                 : 
     491                 : static
     492               0 : vpx_codec_err_t vp8_xma_get_mmap(const vpx_codec_ctx_t      *ctx,
     493                 :                                  vpx_codec_mmap_t           *mmap,
     494                 :                                  vpx_codec_iter_t           *iter)
     495                 : {
     496                 :     vpx_codec_err_t     res;
     497               0 :     const mem_req_t  *seg_iter = *iter;
     498                 : 
     499                 :     /* Get address of next segment request */
     500                 :     do
     501                 :     {
     502               0 :         if (!seg_iter)
     503               0 :             seg_iter = vp8_mem_req_segs;
     504               0 :         else if (seg_iter->id != VP8_SEG_MAX)
     505               0 :             seg_iter++;
     506                 : 
     507               0 :         *iter = (vpx_codec_iter_t)seg_iter;
     508                 : 
     509               0 :         if (seg_iter->id != VP8_SEG_MAX)
     510                 :         {
     511               0 :             mmap->id = seg_iter->id;
     512               0 :             mmap->sz = seg_iter->sz;
     513               0 :             mmap->align = seg_iter->align;
     514               0 :             mmap->flags = seg_iter->flags;
     515                 : 
     516               0 :             if (!seg_iter->sz)
     517               0 :                 mmap->sz = seg_iter->calc_sz(ctx->config.dec, ctx->init_flags);
     518                 : 
     519               0 :             res = VPX_CODEC_OK;
     520                 :         }
     521                 :         else
     522               0 :             res = VPX_CODEC_LIST_END;
     523                 :     }
     524               0 :     while (!mmap->sz && res != VPX_CODEC_LIST_END);
     525                 : 
     526               0 :     return res;
     527                 : }
     528                 : 
     529               0 : static vpx_codec_err_t vp8_xma_set_mmap(vpx_codec_ctx_t         *ctx,
     530                 :                                         const vpx_codec_mmap_t  *mmap)
     531                 : {
     532               0 :     vpx_codec_err_t res = VPX_CODEC_MEM_ERROR;
     533                 :     int i, done;
     534                 : 
     535               0 :     if (!ctx->priv)
     536                 :     {
     537               0 :         if (mmap->id == VP8_SEG_ALG_PRIV)
     538                 :         {
     539               0 :             if (!ctx->priv)
     540                 :             {
     541               0 :                 vp8_init_ctx(ctx, mmap);
     542               0 :                 res = VPX_CODEC_OK;
     543                 :             }
     544                 :         }
     545                 :     }
     546                 : 
     547               0 :     done = 1;
     548                 : 
     549               0 :     if (!res && ctx->priv->alg_priv)
     550                 :     {
     551               0 :         for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++)
     552                 :         {
     553               0 :             if (ctx->priv->alg_priv->mmaps[i].id == mmap->id)
     554               0 :                 if (!ctx->priv->alg_priv->mmaps[i].base)
     555                 :                 {
     556               0 :                     ctx->priv->alg_priv->mmaps[i] = *mmap;
     557               0 :                     res = VPX_CODEC_OK;
     558                 :                 }
     559                 : 
     560               0 :             done &= (ctx->priv->alg_priv->mmaps[i].base != NULL);
     561                 :         }
     562                 :     }
     563                 : 
     564               0 :     if (done && !res)
     565                 :     {
     566               0 :         vp8_finalize_mmaps(ctx->priv->alg_priv);
     567               0 :         res = ctx->iface->init(ctx);
     568                 :     }
     569                 : 
     570               0 :     return res;
     571                 : }
     572                 : 
     573               0 : static vpx_codec_err_t image2yuvconfig(const vpx_image_t   *img,
     574                 :                                        YV12_BUFFER_CONFIG  *yv12)
     575                 : {
     576               0 :     vpx_codec_err_t        res = VPX_CODEC_OK;
     577               0 :     yv12->y_buffer = img->planes[VPX_PLANE_Y];
     578               0 :     yv12->u_buffer = img->planes[VPX_PLANE_U];
     579               0 :     yv12->v_buffer = img->planes[VPX_PLANE_V];
     580                 : 
     581               0 :     yv12->y_width  = img->d_w;
     582               0 :     yv12->y_height = img->d_h;
     583               0 :     yv12->uv_width = yv12->y_width / 2;
     584               0 :     yv12->uv_height = yv12->y_height / 2;
     585                 : 
     586               0 :     yv12->y_stride = img->stride[VPX_PLANE_Y];
     587               0 :     yv12->uv_stride = img->stride[VPX_PLANE_U];
     588                 : 
     589               0 :     yv12->border  = (img->stride[VPX_PLANE_Y] - img->d_w) / 2;
     590               0 :     yv12->clrtype = (img->fmt == VPX_IMG_FMT_VPXI420 || img->fmt == VPX_IMG_FMT_VPXYV12);
     591                 : 
     592               0 :     return res;
     593                 : }
     594                 : 
     595                 : 
     596               0 : static vpx_codec_err_t vp8_set_reference(vpx_codec_alg_priv_t *ctx,
     597                 :         int ctr_id,
     598                 :         va_list args)
     599                 : {
     600                 : 
     601               0 :     vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
     602                 : 
     603               0 :     if (data)
     604                 :     {
     605               0 :         vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
     606                 :         YV12_BUFFER_CONFIG sd;
     607                 : 
     608               0 :         image2yuvconfig(&frame->img, &sd);
     609                 : 
     610               0 :         return vp8dx_set_reference(ctx->pbi, frame->frame_type, &sd);
     611                 :     }
     612                 :     else
     613               0 :         return VPX_CODEC_INVALID_PARAM;
     614                 : 
     615                 : }
     616                 : 
     617               0 : static vpx_codec_err_t vp8_get_reference(vpx_codec_alg_priv_t *ctx,
     618                 :         int ctr_id,
     619                 :         va_list args)
     620                 : {
     621                 : 
     622               0 :     vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
     623                 : 
     624               0 :     if (data)
     625                 :     {
     626               0 :         vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
     627                 :         YV12_BUFFER_CONFIG sd;
     628                 : 
     629               0 :         image2yuvconfig(&frame->img, &sd);
     630                 : 
     631               0 :         return vp8dx_get_reference(ctx->pbi, frame->frame_type, &sd);
     632                 :     }
     633                 :     else
     634               0 :         return VPX_CODEC_INVALID_PARAM;
     635                 : 
     636                 : }
     637                 : 
     638               0 : static vpx_codec_err_t vp8_set_postproc(vpx_codec_alg_priv_t *ctx,
     639                 :                                         int ctr_id,
     640                 :                                         va_list args)
     641                 : {
     642                 : #if CONFIG_POSTPROC
     643               0 :     vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
     644                 : 
     645               0 :     if (data)
     646                 :     {
     647               0 :         ctx->postproc_cfg_set = 1;
     648               0 :         ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data);
     649               0 :         return VPX_CODEC_OK;
     650                 :     }
     651                 :     else
     652               0 :         return VPX_CODEC_INVALID_PARAM;
     653                 : 
     654                 : #else
     655                 :     return VPX_CODEC_INCAPABLE;
     656                 : #endif
     657                 : }
     658                 : 
     659               0 : static vpx_codec_err_t vp8_set_dbg_options(vpx_codec_alg_priv_t *ctx,
     660                 :                                         int ctrl_id,
     661                 :                                         va_list args)
     662                 : {
     663                 : #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
     664                 :     int data = va_arg(args, int);
     665                 : 
     666                 : #define MAP(id, var) case id: var = data; break;
     667                 : 
     668                 :     switch (ctrl_id)
     669                 :     {
     670                 :         MAP (VP8_SET_DBG_COLOR_REF_FRAME,   ctx->dbg_color_ref_frame_flag);
     671                 :         MAP (VP8_SET_DBG_COLOR_MB_MODES,    ctx->dbg_color_mb_modes_flag);
     672                 :         MAP (VP8_SET_DBG_COLOR_B_MODES,     ctx->dbg_color_b_modes_flag);
     673                 :         MAP (VP8_SET_DBG_DISPLAY_MV,        ctx->dbg_display_mv_flag);
     674                 :     }
     675                 : 
     676                 :     return VPX_CODEC_OK;
     677                 : #else
     678               0 :     return VPX_CODEC_INCAPABLE;
     679                 : #endif
     680                 : }
     681                 : 
     682               0 : static vpx_codec_err_t vp8_get_last_ref_updates(vpx_codec_alg_priv_t *ctx,
     683                 :                                                 int ctrl_id,
     684                 :                                                 va_list args)
     685                 : {
     686               0 :     int *update_info = va_arg(args, int *);
     687               0 :     VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
     688                 : 
     689               0 :     if (update_info)
     690                 :     {
     691               0 :         *update_info = pbi->common.refresh_alt_ref_frame * (int) VP8_ALTR_FRAME
     692               0 :             + pbi->common.refresh_golden_frame * (int) VP8_GOLD_FRAME
     693               0 :             + pbi->common.refresh_last_frame * (int) VP8_LAST_FRAME;
     694                 : 
     695               0 :         return VPX_CODEC_OK;
     696                 :     }
     697                 :     else
     698               0 :         return VPX_CODEC_INVALID_PARAM;
     699                 : }
     700                 : 
     701                 : 
     702               0 : static vpx_codec_err_t vp8_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
     703                 :                                                int ctrl_id,
     704                 :                                                va_list args)
     705                 : {
     706                 : 
     707               0 :     int *corrupted = va_arg(args, int *);
     708                 : 
     709               0 :     if (corrupted)
     710                 :     {
     711               0 :         VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
     712               0 :         *corrupted = pbi->common.frame_to_show->corrupted;
     713                 : 
     714               0 :         return VPX_CODEC_OK;
     715                 :     }
     716                 :     else
     717               0 :         return VPX_CODEC_INVALID_PARAM;
     718                 : 
     719                 : }
     720                 : 
     721                 : vpx_codec_ctrl_fn_map_t vp8_ctf_maps[] =
     722                 : {
     723                 :     {VP8_SET_REFERENCE,             vp8_set_reference},
     724                 :     {VP8_COPY_REFERENCE,            vp8_get_reference},
     725                 :     {VP8_SET_POSTPROC,              vp8_set_postproc},
     726                 :     {VP8_SET_DBG_COLOR_REF_FRAME,   vp8_set_dbg_options},
     727                 :     {VP8_SET_DBG_COLOR_MB_MODES,    vp8_set_dbg_options},
     728                 :     {VP8_SET_DBG_COLOR_B_MODES,     vp8_set_dbg_options},
     729                 :     {VP8_SET_DBG_DISPLAY_MV,        vp8_set_dbg_options},
     730                 :     {VP8D_GET_LAST_REF_UPDATES,     vp8_get_last_ref_updates},
     731                 :     {VP8D_GET_FRAME_CORRUPTED,      vp8_get_frame_corrupted},
     732                 :     { -1, NULL},
     733                 : };
     734                 : 
     735                 : 
     736                 : #ifndef VERSION_STRING
     737                 : #define VERSION_STRING
     738                 : #endif
     739               0 : CODEC_INTERFACE(vpx_codec_vp8_dx) =
     740                 : {
     741                 :     "WebM Project VP8 Decoder" VERSION_STRING,
     742                 :     VPX_CODEC_INTERNAL_ABI_VERSION,
     743                 :     VPX_CODEC_CAP_DECODER | VP8_CAP_POSTPROC | VP8_CAP_ERROR_CONCEALMENT |
     744                 :     VPX_CODEC_CAP_INPUT_PARTITION,
     745                 :     /* vpx_codec_caps_t          caps; */
     746                 :     vp8_init,         /* vpx_codec_init_fn_t       init; */
     747                 :     vp8_destroy,      /* vpx_codec_destroy_fn_t    destroy; */
     748                 :     vp8_ctf_maps,     /* vpx_codec_ctrl_fn_map_t  *ctrl_maps; */
     749                 :     vp8_xma_get_mmap, /* vpx_codec_get_mmap_fn_t   get_mmap; */
     750                 :     vp8_xma_set_mmap, /* vpx_codec_set_mmap_fn_t   set_mmap; */
     751                 :     {
     752                 :         vp8_peek_si,      /* vpx_codec_peek_si_fn_t    peek_si; */
     753                 :         vp8_get_si,       /* vpx_codec_get_si_fn_t     get_si; */
     754                 :         vp8_decode,       /* vpx_codec_decode_fn_t     decode; */
     755                 :         vp8_get_frame,    /* vpx_codec_frame_get_fn_t  frame_get; */
     756                 :     },
     757                 :     { /* encoder functions */
     758                 :         NOT_IMPLEMENTED,
     759                 :         NOT_IMPLEMENTED,
     760                 :         NOT_IMPLEMENTED,
     761                 :         NOT_IMPLEMENTED,
     762                 :         NOT_IMPLEMENTED,
     763                 :         NOT_IMPLEMENTED
     764                 :     }
     765                 : };
     766                 : 
     767                 : /*
     768                 :  * BEGIN BACKWARDS COMPATIBILITY SHIM.
     769                 :  */
     770                 : vpx_codec_iface_t vpx_codec_vp8_algo =
     771                 : {
     772                 :     "WebM Project VP8 Decoder (Deprecated API)" VERSION_STRING,
     773                 :     VPX_CODEC_INTERNAL_ABI_VERSION,
     774                 :     VPX_CODEC_CAP_DECODER | VP8_CAP_POSTPROC | VP8_CAP_ERROR_CONCEALMENT,
     775                 :     /* vpx_codec_caps_t          caps; */
     776                 :     vp8_init,         /* vpx_codec_init_fn_t       init; */
     777                 :     vp8_destroy,      /* vpx_codec_destroy_fn_t    destroy; */
     778                 :     vp8_ctf_maps,     /* vpx_codec_ctrl_fn_map_t  *ctrl_maps; */
     779                 :     vp8_xma_get_mmap, /* vpx_codec_get_mmap_fn_t   get_mmap; */
     780                 :     vp8_xma_set_mmap, /* vpx_codec_set_mmap_fn_t   set_mmap; */
     781                 :     {
     782                 :         vp8_peek_si,      /* vpx_codec_peek_si_fn_t    peek_si; */
     783                 :         vp8_get_si,       /* vpx_codec_get_si_fn_t     get_si; */
     784                 :         vp8_decode,       /* vpx_codec_decode_fn_t     decode; */
     785                 :         vp8_get_frame,    /* vpx_codec_frame_get_fn_t  frame_get; */
     786                 :     },
     787                 :     { /* encoder functions */
     788                 :         NOT_IMPLEMENTED,
     789                 :         NOT_IMPLEMENTED,
     790                 :         NOT_IMPLEMENTED,
     791                 :         NOT_IMPLEMENTED,
     792                 :         NOT_IMPLEMENTED,
     793                 :         NOT_IMPLEMENTED
     794                 :     }
     795                 : };

Generated by: LCOV version 1.7