]> granicus.if.org Git - libvpx/blob - vp9/vp9_dx_iface.c
99641f415000763b365772cf2af603fd313cf3a2
[libvpx] / vp9 / vp9_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 #include <stdlib.h>
12 #include <string.h>
13
14 #include "./vpx_version.h"
15
16 #include "vpx/internal/vpx_codec_internal.h"
17 #include "vpx/vp8dx.h"
18 #include "vpx/vpx_decoder.h"
19
20 #include "vp9/common/vp9_frame_buffers.h"
21
22 #include "vp9/decoder/vp9_decoder.h"
23 #include "vp9/decoder/vp9_read_bit_buffer.h"
24
25 #include "vp9/vp9_iface_common.h"
26
27 #define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
28
29 typedef vpx_codec_stream_info_t vp9_stream_info_t;
30
31 struct vpx_codec_alg_priv {
32   vpx_codec_priv_t        base;
33   vpx_codec_dec_cfg_t     cfg;
34   vp9_stream_info_t       si;
35   struct VP9Decoder *pbi;
36   int                     postproc_cfg_set;
37   vp8_postproc_cfg_t      postproc_cfg;
38   vpx_decrypt_cb          decrypt_cb;
39   void                   *decrypt_state;
40   vpx_image_t             img;
41   int                     invert_tile_order;
42   int                     frame_parallel_decode;  // frame-based threading.
43   int                     last_show_frame;  // Index of last output frame.
44
45   // External frame buffer info to save for VP9 common.
46   void *ext_priv;  // Private data associated with the external frame buffers.
47   vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb;
48   vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb;
49 };
50
51 static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx,
52                                     vpx_codec_priv_enc_mr_cfg_t *data) {
53   // This function only allocates space for the vpx_codec_alg_priv_t
54   // structure. More memory may be required at the time the stream
55   // information becomes known.
56   (void)data;
57
58   if (!ctx->priv) {
59     vpx_codec_alg_priv_t *alg_priv = vpx_memalign(32, sizeof(*alg_priv));
60     if (alg_priv == NULL)
61       return VPX_CODEC_MEM_ERROR;
62
63     vp9_zero(*alg_priv);
64
65     ctx->priv = (vpx_codec_priv_t *)alg_priv;
66     ctx->priv->sz = sizeof(*ctx->priv);
67     ctx->priv->iface = ctx->iface;
68     ctx->priv->alg_priv = alg_priv;
69     ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si);
70     ctx->priv->init_flags = ctx->init_flags;
71     ctx->priv->alg_priv->frame_parallel_decode =
72         (ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING);
73
74     // Disable frame parallel decoding for now.
75     ctx->priv->alg_priv->frame_parallel_decode = 0;
76
77     if (ctx->config.dec) {
78       // Update the reference to the config structure to an internal copy.
79       ctx->priv->alg_priv->cfg = *ctx->config.dec;
80       ctx->config.dec = &ctx->priv->alg_priv->cfg;
81     }
82   }
83
84   return VPX_CODEC_OK;
85 }
86
87 static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) {
88   if (ctx->pbi) {
89     vp9_decoder_remove(ctx->pbi);
90     ctx->pbi = NULL;
91   }
92
93   vpx_free(ctx);
94
95   return VPX_CODEC_OK;
96 }
97
98 static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data,
99                                                 unsigned int data_sz,
100                                                 vpx_codec_stream_info_t *si,
101                                                 vpx_decrypt_cb decrypt_cb,
102                                                 void *decrypt_state) {
103   uint8_t clear_buffer[9];
104
105   if (data_sz <= 8)
106     return VPX_CODEC_UNSUP_BITSTREAM;
107
108   if (data + data_sz <= data)
109     return VPX_CODEC_INVALID_PARAM;
110
111   si->is_kf = 0;
112   si->w = si->h = 0;
113
114   if (decrypt_cb) {
115     data_sz = MIN(sizeof(clear_buffer), data_sz);
116     decrypt_cb(decrypt_state, data, clear_buffer, data_sz);
117     data = clear_buffer;
118   }
119
120   {
121     struct vp9_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL };
122     const int frame_marker = vp9_rb_read_literal(&rb, 2);
123     const int version = vp9_rb_read_bit(&rb);
124     (void) vp9_rb_read_bit(&rb);  // unused version bit
125
126     if (frame_marker != VP9_FRAME_MARKER)
127       return VPX_CODEC_UNSUP_BITSTREAM;
128     if (version > 1) return VPX_CODEC_UNSUP_BITSTREAM;
129
130     if (vp9_rb_read_bit(&rb)) {  // show an existing frame
131       return VPX_CODEC_OK;
132     }
133
134     si->is_kf = !vp9_rb_read_bit(&rb);
135     if (si->is_kf) {
136       const int sRGB = 7;
137       int colorspace;
138
139       rb.bit_offset += 1;  // show frame
140       rb.bit_offset += 1;  // error resilient
141
142       if (vp9_rb_read_literal(&rb, 8) != VP9_SYNC_CODE_0 ||
143           vp9_rb_read_literal(&rb, 8) != VP9_SYNC_CODE_1 ||
144           vp9_rb_read_literal(&rb, 8) != VP9_SYNC_CODE_2) {
145         return VPX_CODEC_UNSUP_BITSTREAM;
146       }
147
148       colorspace = vp9_rb_read_literal(&rb, 3);
149       if (colorspace != sRGB) {
150         rb.bit_offset += 1;  // [16,235] (including xvycc) vs [0,255] range
151         if (version == 1) {
152           rb.bit_offset += 2;  // subsampling x/y
153           rb.bit_offset += 1;  // has extra plane
154         }
155       } else {
156         if (version == 1) {
157           rb.bit_offset += 1;  // has extra plane
158         } else {
159           // RGB is only available in version 1
160           return VPX_CODEC_UNSUP_BITSTREAM;
161         }
162       }
163
164       // TODO(jzern): these are available on non-keyframes in intra only mode.
165       si->w = vp9_rb_read_literal(&rb, 16) + 1;
166       si->h = vp9_rb_read_literal(&rb, 16) + 1;
167     }
168   }
169
170   return VPX_CODEC_OK;
171 }
172
173 static vpx_codec_err_t decoder_peek_si(const uint8_t *data,
174                                        unsigned int data_sz,
175                                        vpx_codec_stream_info_t *si) {
176   return decoder_peek_si_internal(data, data_sz, si, NULL, NULL);
177 }
178
179 static vpx_codec_err_t decoder_get_si(vpx_codec_alg_priv_t *ctx,
180                                       vpx_codec_stream_info_t *si) {
181   const size_t sz = (si->sz >= sizeof(vp9_stream_info_t))
182                        ? sizeof(vp9_stream_info_t)
183                        : sizeof(vpx_codec_stream_info_t);
184   memcpy(si, &ctx->si, sz);
185   si->sz = (unsigned int)sz;
186
187   return VPX_CODEC_OK;
188 }
189
190 static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx,
191                            const struct vpx_internal_error_info *error) {
192   if (error->error_code)
193     ctx->base.err_detail = error->has_detail ? error->detail : NULL;
194
195   return error->error_code;
196 }
197
198 static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) {
199   VP9_COMMON *const cm = &ctx->pbi->common;
200
201   cm->new_fb_idx = -1;
202
203   if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
204     cm->get_fb_cb = ctx->get_ext_fb_cb;
205     cm->release_fb_cb = ctx->release_ext_fb_cb;
206     cm->cb_priv = ctx->ext_priv;
207   } else {
208     cm->get_fb_cb = vp9_get_frame_buffer;
209     cm->release_fb_cb = vp9_release_frame_buffer;
210
211     if (vp9_alloc_internal_frame_buffers(&cm->int_frame_buffers))
212       vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
213                          "Failed to initialize internal frame buffers");
214
215     cm->cb_priv = &cm->int_frame_buffers;
216   }
217 }
218
219 static void set_default_ppflags(vp8_postproc_cfg_t *cfg) {
220   cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK;
221   cfg->deblocking_level = 4;
222   cfg->noise_level = 0;
223 }
224
225 static void set_ppflags(const vpx_codec_alg_priv_t *ctx,
226                         vp9_ppflags_t *flags) {
227   flags->post_proc_flag =
228       ctx->postproc_cfg.post_proc_flag;
229
230   flags->deblocking_level = ctx->postproc_cfg.deblocking_level;
231   flags->noise_level = ctx->postproc_cfg.noise_level;
232 }
233
234 static void init_decoder(vpx_codec_alg_priv_t *ctx) {
235   ctx->pbi = vp9_decoder_create();
236   if (ctx->pbi == NULL)
237     return;
238
239   ctx->pbi->max_threads = ctx->cfg.threads;
240   ctx->pbi->inv_tile_order = ctx->invert_tile_order;
241   ctx->pbi->frame_parallel_decode = ctx->frame_parallel_decode;
242   ctx->last_show_frame = -1;
243
244   // If postprocessing was enabled by the application and a
245   // configuration has not been provided, default it.
246   if (!ctx->postproc_cfg_set &&
247       (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC))
248     set_default_ppflags(&ctx->postproc_cfg);
249
250   init_buffer_callbacks(ctx);
251 }
252
253 static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx,
254                                   const uint8_t **data, unsigned int data_sz,
255                                   void *user_priv, int64_t deadline) {
256   vp9_ppflags_t flags = {0};
257   VP9_COMMON *cm = NULL;
258
259   (void)deadline;
260
261   // Determine the stream parameters. Note that we rely on peek_si to
262   // validate that we have a buffer that does not wrap around the top
263   // of the heap.
264   if (!ctx->si.h) {
265     const vpx_codec_err_t res =
266         decoder_peek_si_internal(*data, data_sz, &ctx->si, ctx->decrypt_cb,
267                                  ctx->decrypt_state);
268     if (res != VPX_CODEC_OK)
269       return res;
270
271     if (!ctx->si.is_kf)
272       return VPX_CODEC_ERROR;
273   }
274
275   // Initialize the decoder instance on the first frame
276   if (ctx->pbi == NULL) {
277     init_decoder(ctx);
278     if (ctx->pbi == NULL)
279       return VPX_CODEC_ERROR;
280   }
281
282   // Set these even if already initialized.  The caller may have changed the
283   // decrypt config between frames.
284   ctx->pbi->decrypt_cb = ctx->decrypt_cb;
285   ctx->pbi->decrypt_state = ctx->decrypt_state;
286
287   cm = &ctx->pbi->common;
288
289   if (vp9_receive_compressed_data(ctx->pbi, data_sz, data))
290     return update_error_state(ctx, &cm->error);
291
292   if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)
293     set_ppflags(ctx, &flags);
294
295   return VPX_CODEC_OK;
296 }
297
298 static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
299                                   void *decrypt_state,
300                                   const uint8_t *data) {
301   if (decrypt_cb) {
302     uint8_t marker;
303     decrypt_cb(decrypt_state, data, &marker, 1);
304     return marker;
305   }
306   return *data;
307 }
308
309 static void parse_superframe_index(const uint8_t *data, size_t data_sz,
310                                    uint32_t sizes[8], int *count,
311                                    vpx_decrypt_cb decrypt_cb,
312                                    void *decrypt_state) {
313   uint8_t marker;
314
315   assert(data_sz);
316   marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1);
317   *count = 0;
318
319   if ((marker & 0xe0) == 0xc0) {
320     const uint32_t frames = (marker & 0x7) + 1;
321     const uint32_t mag = ((marker >> 3) & 0x3) + 1;
322     const size_t index_sz = 2 + mag * frames;
323
324     if (data_sz >= index_sz) {
325       uint8_t marker2 = read_marker(decrypt_cb, decrypt_state,
326                                     data + data_sz - index_sz);
327
328       if (marker == marker2) {
329         // Found a valid superframe index.
330         uint32_t i, j;
331         const uint8_t *x = &data[data_sz - index_sz + 1];
332
333         // Frames has a maximum of 8 and mag has a maximum of 4.
334         uint8_t clear_buffer[32];
335         assert(sizeof(clear_buffer) >= frames * mag);
336         if (decrypt_cb) {
337           decrypt_cb(decrypt_state, x, clear_buffer, frames * mag);
338           x = clear_buffer;
339         }
340
341         for (i = 0; i < frames; ++i) {
342           uint32_t this_sz = 0;
343
344           for (j = 0; j < mag; ++j)
345             this_sz |= (*x++) << (j * 8);
346           sizes[i] = this_sz;
347         }
348
349         *count = frames;
350       }
351     }
352   }
353 }
354
355 static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
356                                       const uint8_t *data, unsigned int data_sz,
357                                       void *user_priv, long deadline) {
358   const uint8_t *data_start = data;
359   const uint8_t * const data_end = data + data_sz;
360   vpx_codec_err_t res;
361   uint32_t frame_sizes[8];
362   int frame_count;
363
364   if (data == NULL || data_sz == 0)
365     return VPX_CODEC_INVALID_PARAM;
366
367   parse_superframe_index(data, data_sz, frame_sizes, &frame_count,
368                          ctx->decrypt_cb, ctx->decrypt_state);
369
370   if (ctx->frame_parallel_decode) {
371     // Decode in frame parallel mode. When decoding in this mode, the frame
372     // passed to the decoder must be either a normal frame or a superframe with
373     // superframe index so the decoder could get each frame's start position
374     // in the superframe.
375     if (frame_count > 0) {
376       int i;
377
378       for (i = 0; i < frame_count; ++i) {
379         const uint8_t *data_start_copy = data_start;
380         const uint32_t frame_size = frame_sizes[i];
381         vpx_codec_err_t res;
382         if (data_start < data
383             || frame_size > (uint32_t) (data_end - data_start)) {
384           ctx->base.err_detail = "Invalid frame size in index";
385           return VPX_CODEC_CORRUPT_FRAME;
386         }
387
388         res = decode_one(ctx, &data_start_copy, frame_size, user_priv,
389                          deadline);
390         if (res != VPX_CODEC_OK)
391           return res;
392
393         data_start += frame_size;
394       }
395     } else {
396       res = decode_one(ctx, &data_start, data_sz, user_priv, deadline);
397       if (res != VPX_CODEC_OK)
398         return res;
399
400       // Extra data detected after the frame.
401       if (data_start < data_end - 1) {
402         ctx->base.err_detail = "Fail to decode frame in parallel mode";
403         return VPX_CODEC_INCAPABLE;
404       }
405     }
406   } else {
407     // Decode in serial mode.
408     if (frame_count > 0) {
409       int i;
410
411       for (i = 0; i < frame_count; ++i) {
412         const uint8_t *data_start_copy = data_start;
413         const uint32_t frame_size = frame_sizes[i];
414         vpx_codec_err_t res;
415         if (data_start < data
416             || frame_size > (uint32_t) (data_end - data_start)) {
417           ctx->base.err_detail = "Invalid frame size in index";
418           return VPX_CODEC_CORRUPT_FRAME;
419         }
420
421         res = decode_one(ctx, &data_start_copy, frame_size, user_priv,
422                          deadline);
423         if (res != VPX_CODEC_OK)
424           return res;
425
426         data_start += frame_size;
427       }
428     } else {
429       while (data_start < data_end) {
430         const uint32_t frame_size = (uint32_t) (data_end - data_start);
431         const vpx_codec_err_t res = decode_one(ctx, &data_start, frame_size,
432                                                user_priv, deadline);
433         if (res != VPX_CODEC_OK)
434           return res;
435
436         // Account for suboptimal termination by the encoder.
437         while (data_start < data_end) {
438           const uint8_t marker = read_marker(ctx->decrypt_cb,
439                                              ctx->decrypt_state, data_start);
440           if (marker)
441             break;
442           ++data_start;
443         }
444       }
445     }
446   }
447
448   return VPX_CODEC_OK;
449 }
450
451 static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx,
452                                       vpx_codec_iter_t *iter) {
453   vpx_image_t *img = NULL;
454
455   // iter acts as a flip flop, so an image is only returned on the first
456   // call to get_frame.
457   if (*iter == NULL && ctx->pbi != NULL) {
458     YV12_BUFFER_CONFIG sd;
459     vp9_ppflags_t flags = {0, 0, 0};
460
461     if (vp9_get_raw_frame(ctx->pbi, &sd, &flags) == 0) {
462       VP9_COMMON *cm = &ctx->pbi->common;
463       yuvconfig2image(&ctx->img, &sd, NULL);
464       ctx->img.fb_priv = cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
465       img = &ctx->img;
466       *iter = img;
467       // Decrease reference count of last output frame in frame parallel mode.
468       if (ctx->frame_parallel_decode && ctx->last_show_frame >= 0) {
469         --cm->frame_bufs[ctx->last_show_frame].ref_count;
470         if (cm->frame_bufs[ctx->last_show_frame].ref_count == 0) {
471           cm->release_fb_cb(cm->cb_priv,
472               &cm->frame_bufs[ctx->last_show_frame].raw_frame_buffer);
473         }
474       }
475       ctx->last_show_frame = ctx->pbi->common.new_fb_idx;
476     }
477   }
478
479   return img;
480 }
481
482 static vpx_codec_err_t decoder_set_fb_fn(
483     vpx_codec_alg_priv_t *ctx,
484     vpx_get_frame_buffer_cb_fn_t cb_get,
485     vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
486   if (cb_get == NULL || cb_release == NULL) {
487     return VPX_CODEC_INVALID_PARAM;
488   } else if (ctx->pbi == NULL) {
489     // If the decoder has already been initialized, do not accept changes to
490     // the frame buffer functions.
491     ctx->get_ext_fb_cb = cb_get;
492     ctx->release_ext_fb_cb = cb_release;
493     ctx->ext_priv = cb_priv;
494     return VPX_CODEC_OK;
495   }
496
497   return VPX_CODEC_ERROR;
498 }
499
500 static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx,
501                                           va_list args) {
502   vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *);
503
504   if (data) {
505     vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data;
506     YV12_BUFFER_CONFIG sd;
507
508     image2yuvconfig(&frame->img, &sd);
509     return vp9_set_reference_dec(&ctx->pbi->common,
510                                  (VP9_REFFRAME)frame->frame_type, &sd);
511   } else {
512     return VPX_CODEC_INVALID_PARAM;
513   }
514 }
515
516 static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx,
517                                            va_list args) {
518   vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *);
519
520   if (data) {
521     vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data;
522     YV12_BUFFER_CONFIG sd;
523
524     image2yuvconfig(&frame->img, &sd);
525
526     return vp9_copy_reference_dec(ctx->pbi,
527                                   (VP9_REFFRAME)frame->frame_type, &sd);
528   } else {
529     return VPX_CODEC_INVALID_PARAM;
530   }
531 }
532
533 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx,
534                                           va_list args) {
535   vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *);
536
537   if (data) {
538     YV12_BUFFER_CONFIG* fb;
539
540     vp9_get_reference_dec(ctx->pbi, data->idx, &fb);
541     yuvconfig2image(&data->img, fb, NULL);
542     return VPX_CODEC_OK;
543   } else {
544     return VPX_CODEC_INVALID_PARAM;
545   }
546 }
547
548 static vpx_codec_err_t ctrl_set_postproc(vpx_codec_alg_priv_t *ctx,
549                                          va_list args) {
550 #if CONFIG_VP9_POSTPROC
551   vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *);
552
553   if (data) {
554     ctx->postproc_cfg_set = 1;
555     ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data);
556     return VPX_CODEC_OK;
557   } else {
558     return VPX_CODEC_INVALID_PARAM;
559   }
560 #else
561   (void)ctx;
562   (void)args;
563   return VPX_CODEC_INCAPABLE;
564 #endif
565 }
566
567 static vpx_codec_err_t ctrl_set_dbg_options(vpx_codec_alg_priv_t *ctx,
568                                             va_list args) {
569   (void)ctx;
570   (void)args;
571   return VPX_CODEC_INCAPABLE;
572 }
573
574 static vpx_codec_err_t ctrl_get_last_ref_updates(vpx_codec_alg_priv_t *ctx,
575                                                  va_list args) {
576   int *const update_info = va_arg(args, int *);
577
578   if (update_info) {
579     if (ctx->pbi)
580       *update_info = ctx->pbi->refresh_frame_flags;
581     else
582       return VPX_CODEC_ERROR;
583     return VPX_CODEC_OK;
584   } else {
585     return VPX_CODEC_INVALID_PARAM;
586   }
587 }
588
589
590 static vpx_codec_err_t ctrl_get_frame_corrupted(vpx_codec_alg_priv_t *ctx,
591                                                 va_list args) {
592   int *corrupted = va_arg(args, int *);
593
594   if (corrupted) {
595     if (ctx->pbi)
596       *corrupted = ctx->pbi->common.frame_to_show->corrupted;
597     else
598       return VPX_CODEC_ERROR;
599     return VPX_CODEC_OK;
600   } else {
601     return VPX_CODEC_INVALID_PARAM;
602   }
603 }
604
605 static vpx_codec_err_t ctrl_get_display_size(vpx_codec_alg_priv_t *ctx,
606                                              va_list args) {
607   int *const display_size = va_arg(args, int *);
608
609   if (display_size) {
610     if (ctx->pbi) {
611       const VP9_COMMON *const cm = &ctx->pbi->common;
612       display_size[0] = cm->display_width;
613       display_size[1] = cm->display_height;
614     } else {
615       return VPX_CODEC_ERROR;
616     }
617     return VPX_CODEC_OK;
618   } else {
619     return VPX_CODEC_INVALID_PARAM;
620   }
621 }
622
623 static vpx_codec_err_t ctrl_set_invert_tile_order(vpx_codec_alg_priv_t *ctx,
624                                                   va_list args) {
625   ctx->invert_tile_order = va_arg(args, int);
626   return VPX_CODEC_OK;
627 }
628
629 static vpx_codec_err_t ctrl_set_decryptor(vpx_codec_alg_priv_t *ctx,
630                                           va_list args) {
631   vpx_decrypt_init *init = va_arg(args, vpx_decrypt_init *);
632   ctx->decrypt_cb = init ? init->decrypt_cb : NULL;
633   ctx->decrypt_state = init ? init->decrypt_state : NULL;
634   return VPX_CODEC_OK;
635 }
636
637 static vpx_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
638   {VP8_COPY_REFERENCE,            ctrl_copy_reference},
639
640   // Setters
641   {VP8_SET_REFERENCE,             ctrl_set_reference},
642   {VP8_SET_POSTPROC,              ctrl_set_postproc},
643   {VP8_SET_DBG_COLOR_REF_FRAME,   ctrl_set_dbg_options},
644   {VP8_SET_DBG_COLOR_MB_MODES,    ctrl_set_dbg_options},
645   {VP8_SET_DBG_COLOR_B_MODES,     ctrl_set_dbg_options},
646   {VP8_SET_DBG_DISPLAY_MV,        ctrl_set_dbg_options},
647   {VP9_INVERT_TILE_DECODE_ORDER,  ctrl_set_invert_tile_order},
648   {VPXD_SET_DECRYPTOR,            ctrl_set_decryptor},
649
650   // Getters
651   {VP8D_GET_LAST_REF_UPDATES,     ctrl_get_last_ref_updates},
652   {VP8D_GET_FRAME_CORRUPTED,      ctrl_get_frame_corrupted},
653   {VP9_GET_REFERENCE,             ctrl_get_reference},
654   {VP9D_GET_DISPLAY_SIZE,         ctrl_get_display_size},
655
656   { -1, NULL},
657 };
658
659 #ifndef VERSION_STRING
660 #define VERSION_STRING
661 #endif
662 CODEC_INTERFACE(vpx_codec_vp9_dx) = {
663   "WebM Project VP9 Decoder" VERSION_STRING,
664   VPX_CODEC_INTERNAL_ABI_VERSION,
665   VPX_CODEC_CAP_DECODER | VP9_CAP_POSTPROC |
666       VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER,  // vpx_codec_caps_t
667   decoder_init,       // vpx_codec_init_fn_t
668   decoder_destroy,    // vpx_codec_destroy_fn_t
669   decoder_ctrl_maps,  // vpx_codec_ctrl_fn_map_t
670   NOT_IMPLEMENTED,    // vpx_codec_get_mmap_fn_t
671   NOT_IMPLEMENTED,    // vpx_codec_set_mmap_fn_t
672   { // NOLINT
673     decoder_peek_si,    // vpx_codec_peek_si_fn_t
674     decoder_get_si,     // vpx_codec_get_si_fn_t
675     decoder_decode,     // vpx_codec_decode_fn_t
676     decoder_get_frame,  // vpx_codec_frame_get_fn_t
677     decoder_set_fb_fn,  // vpx_codec_set_fb_fn_t
678   },
679   { // NOLINT
680     NOT_IMPLEMENTED,  // vpx_codec_enc_cfg_map_t
681     NOT_IMPLEMENTED,  // vpx_codec_encode_fn_t
682     NOT_IMPLEMENTED,  // vpx_codec_get_cx_data_fn_t
683     NOT_IMPLEMENTED,  // vpx_codec_enc_config_set_fn_t
684     NOT_IMPLEMENTED,  // vpx_codec_get_global_headers_fn_t
685     NOT_IMPLEMENTED,  // vpx_codec_get_preview_frame_fn_t
686     NOT_IMPLEMENTED   // vpx_codec_enc_mr_get_mem_loc_fn_t
687   }
688 };