Merge "Copy macroblock data to a buffer before encoding it"
[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     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 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 {
186     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     if (!ctx->priv)
193     {
194         vpx_codec_mmap_t mmap;
195
196         mmap.id = vp8_mem_req_segs[0].id;
197         mmap.sz = sizeof(vpx_codec_alg_priv_t);
198         mmap.align = vp8_mem_req_segs[0].align;
199         mmap.flags = vp8_mem_req_segs[0].flags;
200
201         res = vp8_mmap_alloc(&mmap);
202
203         if (!res)
204         {
205             vp8_init_ctx(ctx, &mmap);
206
207             ctx->priv->alg_priv->defer_alloc = 1;
208             /*post processing level initialized to do nothing */
209         }
210     }
211
212     return res;
213 }
214
215 static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx)
216 {
217     int i;
218
219     vp8dx_remove_decompressor(ctx->pbi);
220
221     for (i = NELEMENTS(ctx->mmaps) - 1; i >= 0; i--)
222     {
223         if (ctx->mmaps[i].dtor)
224             ctx->mmaps[i].dtor(&ctx->mmaps[i]);
225     }
226
227     return VPX_CODEC_OK;
228 }
229
230 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     vpx_codec_err_t res = VPX_CODEC_OK;
235
236     if(data + data_sz <= data)
237         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         si->is_kf = 0;
247
248         if (data_sz >= 10 && !(data[0] & 0x01))  /* I-Frame */
249         {
250             const uint8_t *c = data + 3;
251             si->is_kf = 1;
252
253             /* vet via sync code */
254             if (c[0] != 0x9d || c[1] != 0x01 || c[2] != 0x2a)
255                 res = VPX_CODEC_UNSUP_BITSTREAM;
256
257             si->w = (c[3] | (c[4] << 8)) & 0x3fff;
258             si->h = (c[5] | (c[6] << 8)) & 0x3fff;
259
260             /*printf("w=%d, h=%d\n", si->w, si->h);*/
261             if (!(si->h | si->w))
262                 res = VPX_CODEC_UNSUP_BITSTREAM;
263         }
264         else
265             res = VPX_CODEC_UNSUP_BITSTREAM;
266     }
267
268     return res;
269
270 }
271
272 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     if (si->sz >= sizeof(vp8_stream_info_t))
279         sz = sizeof(vp8_stream_info_t);
280     else
281         sz = sizeof(vpx_codec_stream_info_t);
282
283     memcpy(si, &ctx->si, sz);
284     si->sz = sz;
285
286     return VPX_CODEC_OK;
287 }
288
289
290 static vpx_codec_err_t
291 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     if ((res = error->error_code))
297         ctx->base.err_detail = error->has_detail
298                                ? error->detail
299                                : NULL;
300
301     return res;
302 }
303
304
305 static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t  *ctx,
306                                   const uint8_t         *data,
307                                   unsigned int            data_sz,
308                                   void                    *user_priv,
309                                   long                    deadline)
310 {
311     vpx_codec_err_t res = VPX_CODEC_OK;
312
313     ctx->img_avail = 0;
314
315     /* Determine the stream parameters. Note that we rely on peek_si to
316      * validate that we have a buffer that does not wrap around the top
317      * of the heap.
318      */
319     if (!ctx->si.h)
320         res = ctx->base.iface->dec.peek_si(data, data_sz, &ctx->si);
321
322
323     /* Perform deferred allocations, if required */
324     if (!res && ctx->defer_alloc)
325     {
326         int i;
327
328         for (i = 1; !res && i < NELEMENTS(ctx->mmaps); i++)
329         {
330             vpx_codec_dec_cfg_t cfg;
331
332             cfg.w = ctx->si.w;
333             cfg.h = ctx->si.h;
334             ctx->mmaps[i].id = vp8_mem_req_segs[i].id;
335             ctx->mmaps[i].sz = vp8_mem_req_segs[i].sz;
336             ctx->mmaps[i].align = vp8_mem_req_segs[i].align;
337             ctx->mmaps[i].flags = vp8_mem_req_segs[i].flags;
338
339             if (!ctx->mmaps[i].sz)
340                 ctx->mmaps[i].sz = vp8_mem_req_segs[i].calc_sz(&cfg,
341                                    ctx->base.init_flags);
342
343             res = vp8_mmap_alloc(&ctx->mmaps[i]);
344         }
345
346         if (!res)
347             vp8_finalize_mmaps(ctx);
348
349         ctx->defer_alloc = 0;
350     }
351
352     /* Initialize the decoder instance on the first frame*/
353     if (!res && !ctx->decoder_init)
354     {
355         res = vp8_validate_mmaps(&ctx->si, ctx->mmaps, ctx->base.init_flags);
356
357         if (!res)
358         {
359             VP8D_CONFIG oxcf;
360             VP8D_PTR optr;
361
362             vp8dx_initialize();
363
364             oxcf.Width = ctx->si.w;
365             oxcf.Height = ctx->si.h;
366             oxcf.Version = 9;
367             oxcf.postprocess = 0;
368             oxcf.max_threads = ctx->cfg.threads;
369             oxcf.error_concealment =
370                     (ctx->base.init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT);
371             oxcf.input_partition =
372                     (ctx->base.init_flags & VPX_CODEC_USE_INPUT_PARTITION);
373
374             optr = vp8dx_create_decompressor(&oxcf);
375
376             /* If postprocessing was enabled by the application and a
377              * configuration has not been provided, default it.
378              */
379             if (!ctx->postproc_cfg_set
380                 && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC))
381             {
382                 ctx->postproc_cfg.post_proc_flag =
383                     VP8_DEBLOCK | VP8_DEMACROBLOCK;
384                 ctx->postproc_cfg.deblocking_level = 4;
385                 ctx->postproc_cfg.noise_level = 0;
386             }
387
388             if (!optr)
389                 res = VPX_CODEC_ERROR;
390             else
391                 ctx->pbi = optr;
392         }
393
394         ctx->decoder_init = 1;
395     }
396
397     if (!res && ctx->pbi)
398     {
399         YV12_BUFFER_CONFIG sd;
400         INT64 time_stamp = 0, time_end_stamp = 0;
401         vp8_ppflags_t flags = {0};
402
403         if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)
404         {
405             flags.post_proc_flag= ctx->postproc_cfg.post_proc_flag
406 #if CONFIG_POSTPROC_VISUALIZER
407
408                                 | ((ctx->dbg_color_ref_frame_flag != 0) ? VP8D_DEBUG_CLR_FRM_REF_BLKS : 0)
409                                 | ((ctx->dbg_color_mb_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
410                                 | ((ctx->dbg_color_b_modes_flag != 0) ? VP8D_DEBUG_CLR_BLK_MODES : 0)
411                                 | ((ctx->dbg_display_mv_flag != 0) ? VP8D_DEBUG_DRAW_MV : 0)
412 #endif
413                                 ;
414             flags.deblocking_level      = ctx->postproc_cfg.deblocking_level;
415             flags.noise_level           = ctx->postproc_cfg.noise_level;
416 #if CONFIG_POSTPROC_VISUALIZER
417             flags.display_ref_frame_flag= ctx->dbg_color_ref_frame_flag;
418             flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag;
419             flags.display_b_modes_flag  = ctx->dbg_color_b_modes_flag;
420             flags.display_mv_flag       = ctx->dbg_display_mv_flag;
421 #endif
422         }
423
424         if (vp8dx_receive_compressed_data(ctx->pbi, data_sz, data, deadline))
425         {
426             VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
427             res = update_error_state(ctx, &pbi->common.error);
428         }
429
430         if (!res && 0 == vp8dx_get_raw_frame(ctx->pbi, &sd, &time_stamp, &time_end_stamp, &flags))
431         {
432             /* Align width/height */
433             unsigned int a_w = (sd.y_width + 15) & ~15;
434             unsigned int a_h = (sd.y_height + 15) & ~15;
435
436             vpx_img_wrap(&ctx->img, VPX_IMG_FMT_I420,
437                          a_w + 2 * VP8BORDERINPIXELS,
438                          a_h + 2 * VP8BORDERINPIXELS,
439                          1,
440                          sd.buffer_alloc);
441             vpx_img_set_rect(&ctx->img,
442                              VP8BORDERINPIXELS, VP8BORDERINPIXELS,
443                              sd.y_width, sd.y_height);
444             ctx->img.user_priv = user_priv;
445             ctx->img_avail = 1;
446
447         }
448     }
449
450     return res;
451 }
452
453 static vpx_image_t *vp8_get_frame(vpx_codec_alg_priv_t  *ctx,
454                                   vpx_codec_iter_t      *iter)
455 {
456     vpx_image_t *img = NULL;
457
458     if (ctx->img_avail)
459     {
460         /* iter acts as a flip flop, so an image is only returned on the first
461          * call to get_frame.
462          */
463         if (!(*iter))
464         {
465             img = &ctx->img;
466             *iter = img;
467         }
468     }
469
470     return img;
471 }
472
473
474 static
475 vpx_codec_err_t vp8_xma_get_mmap(const vpx_codec_ctx_t      *ctx,
476                                  vpx_codec_mmap_t           *mmap,
477                                  vpx_codec_iter_t           *iter)
478 {
479     vpx_codec_err_t     res;
480     const mem_req_t  *seg_iter = *iter;
481
482     /* Get address of next segment request */
483     do
484     {
485         if (!seg_iter)
486             seg_iter = vp8_mem_req_segs;
487         else if (seg_iter->id != VP8_SEG_MAX)
488             seg_iter++;
489
490         *iter = (vpx_codec_iter_t)seg_iter;
491
492         if (seg_iter->id != VP8_SEG_MAX)
493         {
494             mmap->id = seg_iter->id;
495             mmap->sz = seg_iter->sz;
496             mmap->align = seg_iter->align;
497             mmap->flags = seg_iter->flags;
498
499             if (!seg_iter->sz)
500                 mmap->sz = seg_iter->calc_sz(ctx->config.dec, ctx->init_flags);
501
502             res = VPX_CODEC_OK;
503         }
504         else
505             res = VPX_CODEC_LIST_END;
506     }
507     while (!mmap->sz && res != VPX_CODEC_LIST_END);
508
509     return res;
510 }
511
512 static vpx_codec_err_t vp8_xma_set_mmap(vpx_codec_ctx_t         *ctx,
513                                         const vpx_codec_mmap_t  *mmap)
514 {
515     vpx_codec_err_t res = VPX_CODEC_MEM_ERROR;
516     int i, done;
517
518     if (!ctx->priv)
519     {
520         if (mmap->id == VP8_SEG_ALG_PRIV)
521         {
522             if (!ctx->priv)
523             {
524                 vp8_init_ctx(ctx, mmap);
525                 res = VPX_CODEC_OK;
526             }
527         }
528     }
529
530     done = 1;
531
532     if (!res && ctx->priv->alg_priv)
533     {
534         for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++)
535         {
536             if (ctx->priv->alg_priv->mmaps[i].id == mmap->id)
537                 if (!ctx->priv->alg_priv->mmaps[i].base)
538                 {
539                     ctx->priv->alg_priv->mmaps[i] = *mmap;
540                     res = VPX_CODEC_OK;
541                 }
542
543             done &= (ctx->priv->alg_priv->mmaps[i].base != NULL);
544         }
545     }
546
547     if (done && !res)
548     {
549         vp8_finalize_mmaps(ctx->priv->alg_priv);
550         res = ctx->iface->init(ctx);
551     }
552
553     return res;
554 }
555
556 static vpx_codec_err_t image2yuvconfig(const vpx_image_t   *img,
557                                        YV12_BUFFER_CONFIG  *yv12)
558 {
559     vpx_codec_err_t        res = VPX_CODEC_OK;
560     yv12->y_buffer = img->planes[VPX_PLANE_Y];
561     yv12->u_buffer = img->planes[VPX_PLANE_U];
562     yv12->v_buffer = img->planes[VPX_PLANE_V];
563
564     yv12->y_width  = img->d_w;
565     yv12->y_height = img->d_h;
566     yv12->uv_width = yv12->y_width / 2;
567     yv12->uv_height = yv12->y_height / 2;
568
569     yv12->y_stride = img->stride[VPX_PLANE_Y];
570     yv12->uv_stride = img->stride[VPX_PLANE_U];
571
572     yv12->border  = (img->stride[VPX_PLANE_Y] - img->d_w) / 2;
573     yv12->clrtype = (img->fmt == VPX_IMG_FMT_VPXI420 || img->fmt == VPX_IMG_FMT_VPXYV12);
574
575     return res;
576 }
577
578
579 static vpx_codec_err_t vp8_set_reference(vpx_codec_alg_priv_t *ctx,
580         int ctr_id,
581         va_list args)
582 {
583
584     vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
585
586     if (data)
587     {
588         vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
589         YV12_BUFFER_CONFIG sd;
590
591         image2yuvconfig(&frame->img, &sd);
592
593         return vp8dx_set_reference(ctx->pbi, frame->frame_type, &sd);
594     }
595     else
596         return VPX_CODEC_INVALID_PARAM;
597
598 }
599
600 static vpx_codec_err_t vp8_get_reference(vpx_codec_alg_priv_t *ctx,
601         int ctr_id,
602         va_list args)
603 {
604
605     vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
606
607     if (data)
608     {
609         vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
610         YV12_BUFFER_CONFIG sd;
611
612         image2yuvconfig(&frame->img, &sd);
613
614         return vp8dx_get_reference(ctx->pbi, frame->frame_type, &sd);
615     }
616     else
617         return VPX_CODEC_INVALID_PARAM;
618
619 }
620
621 static vpx_codec_err_t vp8_set_postproc(vpx_codec_alg_priv_t *ctx,
622                                         int ctr_id,
623                                         va_list args)
624 {
625 #if CONFIG_POSTPROC
626     vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
627
628     if (data)
629     {
630         ctx->postproc_cfg_set = 1;
631         ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data);
632         return VPX_CODEC_OK;
633     }
634     else
635         return VPX_CODEC_INVALID_PARAM;
636
637 #else
638     return VPX_CODEC_INCAPABLE;
639 #endif
640 }
641
642 static vpx_codec_err_t vp8_set_dbg_options(vpx_codec_alg_priv_t *ctx,
643                                         int ctrl_id,
644                                         va_list args)
645 {
646 #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC
647     int data = va_arg(args, int);
648
649 #define MAP(id, var) case id: var = data; break;
650
651     switch (ctrl_id)
652     {
653         MAP (VP8_SET_DBG_COLOR_REF_FRAME,   ctx->dbg_color_ref_frame_flag);
654         MAP (VP8_SET_DBG_COLOR_MB_MODES,    ctx->dbg_color_mb_modes_flag);
655         MAP (VP8_SET_DBG_COLOR_B_MODES,     ctx->dbg_color_b_modes_flag);
656         MAP (VP8_SET_DBG_DISPLAY_MV,        ctx->dbg_display_mv_flag);
657     }
658
659     return VPX_CODEC_OK;
660 #else
661     return VPX_CODEC_INCAPABLE;
662 #endif
663 }
664
665 static vpx_codec_err_t vp8_get_last_ref_updates(vpx_codec_alg_priv_t *ctx,
666                                                 int ctrl_id,
667                                                 va_list args)
668 {
669     int *update_info = va_arg(args, int *);
670     VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
671
672     if (update_info)
673     {
674         *update_info = pbi->common.refresh_alt_ref_frame * (int) VP8_ALTR_FRAME
675             + pbi->common.refresh_golden_frame * (int) VP8_GOLD_FRAME
676             + pbi->common.refresh_last_frame * (int) VP8_LAST_FRAME;
677
678         return VPX_CODEC_OK;
679     }
680     else
681         return VPX_CODEC_INVALID_PARAM;
682 }
683
684
685 static vpx_codec_err_t vp8_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
686                                                int ctrl_id,
687                                                va_list args)
688 {
689
690     int *corrupted = va_arg(args, int *);
691
692     if (corrupted)
693     {
694         VP8D_COMP *pbi = (VP8D_COMP *)ctx->pbi;
695         *corrupted = pbi->common.frame_to_show->corrupted;
696
697         return VPX_CODEC_OK;
698     }
699     else
700         return VPX_CODEC_INVALID_PARAM;
701
702 }
703
704 vpx_codec_ctrl_fn_map_t vp8_ctf_maps[] =
705 {
706     {VP8_SET_REFERENCE,             vp8_set_reference},
707     {VP8_COPY_REFERENCE,            vp8_get_reference},
708     {VP8_SET_POSTPROC,              vp8_set_postproc},
709     {VP8_SET_DBG_COLOR_REF_FRAME,   vp8_set_dbg_options},
710     {VP8_SET_DBG_COLOR_MB_MODES,    vp8_set_dbg_options},
711     {VP8_SET_DBG_COLOR_B_MODES,     vp8_set_dbg_options},
712     {VP8_SET_DBG_DISPLAY_MV,        vp8_set_dbg_options},
713     {VP8D_GET_LAST_REF_UPDATES,     vp8_get_last_ref_updates},
714     {VP8D_GET_FRAME_CORRUPTED,      vp8_get_frame_corrupted},
715     { -1, NULL},
716 };
717
718
719 #ifndef VERSION_STRING
720 #define VERSION_STRING
721 #endif
722 CODEC_INTERFACE(vpx_codec_vp8_dx) =
723 {
724     "WebM Project VP8 Decoder" VERSION_STRING,
725     VPX_CODEC_INTERNAL_ABI_VERSION,
726     VPX_CODEC_CAP_DECODER | VP8_CAP_POSTPROC | VP8_CAP_ERROR_CONCEALMENT |
727     VPX_CODEC_CAP_INPUT_PARTITION,
728     /* vpx_codec_caps_t          caps; */
729     vp8_init,         /* vpx_codec_init_fn_t       init; */
730     vp8_destroy,      /* vpx_codec_destroy_fn_t    destroy; */
731     vp8_ctf_maps,     /* vpx_codec_ctrl_fn_map_t  *ctrl_maps; */
732     vp8_xma_get_mmap, /* vpx_codec_get_mmap_fn_t   get_mmap; */
733     vp8_xma_set_mmap, /* vpx_codec_set_mmap_fn_t   set_mmap; */
734     {
735         vp8_peek_si,      /* vpx_codec_peek_si_fn_t    peek_si; */
736         vp8_get_si,       /* vpx_codec_get_si_fn_t     get_si; */
737         vp8_decode,       /* vpx_codec_decode_fn_t     decode; */
738         vp8_get_frame,    /* vpx_codec_frame_get_fn_t  frame_get; */
739     },
740     { /* encoder functions */
741         NOT_IMPLEMENTED,
742         NOT_IMPLEMENTED,
743         NOT_IMPLEMENTED,
744         NOT_IMPLEMENTED,
745         NOT_IMPLEMENTED,
746         NOT_IMPLEMENTED
747     }
748 };
749
750 /*
751  * BEGIN BACKWARDS COMPATIBILITY SHIM.
752  */
753 vpx_codec_iface_t vpx_codec_vp8_algo =
754 {
755     "WebM Project VP8 Decoder (Deprecated API)" VERSION_STRING,
756     VPX_CODEC_INTERNAL_ABI_VERSION,
757     VPX_CODEC_CAP_DECODER | VP8_CAP_POSTPROC | VP8_CAP_ERROR_CONCEALMENT,
758     /* vpx_codec_caps_t          caps; */
759     vp8_init,         /* vpx_codec_init_fn_t       init; */
760     vp8_destroy,      /* vpx_codec_destroy_fn_t    destroy; */
761     vp8_ctf_maps,     /* vpx_codec_ctrl_fn_map_t  *ctrl_maps; */
762     vp8_xma_get_mmap, /* vpx_codec_get_mmap_fn_t   get_mmap; */
763     vp8_xma_set_mmap, /* vpx_codec_set_mmap_fn_t   set_mmap; */
764     {
765         vp8_peek_si,      /* vpx_codec_peek_si_fn_t    peek_si; */
766         vp8_get_si,       /* vpx_codec_get_si_fn_t     get_si; */
767         vp8_decode,       /* vpx_codec_decode_fn_t     decode; */
768         vp8_get_frame,    /* vpx_codec_frame_get_fn_t  frame_get; */
769     },
770     { /* encoder functions */
771         NOT_IMPLEMENTED,
772         NOT_IMPLEMENTED,
773         NOT_IMPLEMENTED,
774         NOT_IMPLEMENTED,
775         NOT_IMPLEMENTED,
776         NOT_IMPLEMENTED
777     }
778 };