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