michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #include michael@0: #include michael@0: #include "vpx/vpx_decoder.h" michael@0: #include "vpx/vp8dx.h" michael@0: #include "vpx/internal/vpx_codec_internal.h" michael@0: #include "./vpx_version.h" michael@0: #include "vp9/decoder/vp9_onyxd.h" michael@0: #include "vp9/decoder/vp9_onyxd_int.h" michael@0: #include "vp9/decoder/vp9_read_bit_buffer.h" michael@0: #include "vp9/vp9_iface_common.h" michael@0: michael@0: #define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0) michael@0: typedef vpx_codec_stream_info_t vp9_stream_info_t; michael@0: michael@0: /* Structures for handling memory allocations */ michael@0: typedef enum { michael@0: VP9_SEG_ALG_PRIV = 256, michael@0: VP9_SEG_MAX michael@0: } mem_seg_id_t; michael@0: #define NELEMENTS(x) ((int)(sizeof(x)/sizeof(x[0]))) michael@0: michael@0: static unsigned long priv_sz(const vpx_codec_dec_cfg_t *si, michael@0: vpx_codec_flags_t flags); michael@0: michael@0: static const mem_req_t vp9_mem_req_segs[] = { michael@0: {VP9_SEG_ALG_PRIV, 0, 8, VPX_CODEC_MEM_ZERO, priv_sz}, michael@0: {VP9_SEG_MAX, 0, 0, 0, NULL} michael@0: }; michael@0: michael@0: struct vpx_codec_alg_priv { michael@0: vpx_codec_priv_t base; michael@0: vpx_codec_mmap_t mmaps[NELEMENTS(vp9_mem_req_segs) - 1]; michael@0: vpx_codec_dec_cfg_t cfg; michael@0: vp9_stream_info_t si; michael@0: int defer_alloc; michael@0: int decoder_init; michael@0: VP9D_PTR pbi; michael@0: int postproc_cfg_set; michael@0: vp8_postproc_cfg_t postproc_cfg; michael@0: #if CONFIG_POSTPROC_VISUALIZER michael@0: unsigned int dbg_postproc_flag; michael@0: int dbg_color_ref_frame_flag; michael@0: int dbg_color_mb_modes_flag; michael@0: int dbg_color_b_modes_flag; michael@0: int dbg_display_mv_flag; michael@0: #endif michael@0: vpx_image_t img; michael@0: int img_setup; michael@0: int img_avail; michael@0: int invert_tile_order; michael@0: }; michael@0: michael@0: static unsigned long priv_sz(const vpx_codec_dec_cfg_t *si, michael@0: vpx_codec_flags_t flags) { michael@0: /* Although this declaration is constant, we can't use it in the requested michael@0: * segments list because we want to define the requested segments list michael@0: * before defining the private type (so that the number of memory maps is michael@0: * known) michael@0: */ michael@0: (void)si; michael@0: return sizeof(vpx_codec_alg_priv_t); michael@0: } michael@0: michael@0: static void vp9_init_ctx(vpx_codec_ctx_t *ctx, const vpx_codec_mmap_t *mmap) { michael@0: int i; michael@0: michael@0: ctx->priv = mmap->base; michael@0: ctx->priv->sz = sizeof(*ctx->priv); michael@0: ctx->priv->iface = ctx->iface; michael@0: ctx->priv->alg_priv = mmap->base; michael@0: michael@0: for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++) michael@0: ctx->priv->alg_priv->mmaps[i].id = vp9_mem_req_segs[i].id; michael@0: michael@0: ctx->priv->alg_priv->mmaps[0] = *mmap; michael@0: ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si); michael@0: ctx->priv->init_flags = ctx->init_flags; michael@0: michael@0: if (ctx->config.dec) { michael@0: /* Update the reference to the config structure to an internal copy. */ michael@0: ctx->priv->alg_priv->cfg = *ctx->config.dec; michael@0: ctx->config.dec = &ctx->priv->alg_priv->cfg; michael@0: } michael@0: } michael@0: michael@0: static void vp9_finalize_mmaps(vpx_codec_alg_priv_t *ctx) { michael@0: /* nothing to clean up */ michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9_init(vpx_codec_ctx_t *ctx, michael@0: vpx_codec_priv_enc_mr_cfg_t *data) { michael@0: vpx_codec_err_t res = VPX_CODEC_OK; michael@0: michael@0: /* This function only allocates space for the vpx_codec_alg_priv_t michael@0: * structure. More memory may be required at the time the stream michael@0: * information becomes known. michael@0: */ michael@0: if (!ctx->priv) { michael@0: vpx_codec_mmap_t mmap; michael@0: michael@0: mmap.id = vp9_mem_req_segs[0].id; michael@0: mmap.sz = sizeof(vpx_codec_alg_priv_t); michael@0: mmap.align = vp9_mem_req_segs[0].align; michael@0: mmap.flags = vp9_mem_req_segs[0].flags; michael@0: michael@0: res = vpx_mmap_alloc(&mmap); michael@0: michael@0: if (!res) { michael@0: vp9_init_ctx(ctx, &mmap); michael@0: michael@0: ctx->priv->alg_priv->defer_alloc = 1; michael@0: /*post processing level initialized to do nothing */ michael@0: } michael@0: } michael@0: michael@0: return res; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9_destroy(vpx_codec_alg_priv_t *ctx) { michael@0: int i; michael@0: michael@0: vp9_remove_decompressor(ctx->pbi); michael@0: michael@0: for (i = NELEMENTS(ctx->mmaps) - 1; i >= 0; i--) { michael@0: if (ctx->mmaps[i].dtor) michael@0: ctx->mmaps[i].dtor(&ctx->mmaps[i]); michael@0: } michael@0: michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9_peek_si(const uint8_t *data, michael@0: unsigned int data_sz, michael@0: vpx_codec_stream_info_t *si) { michael@0: if (data_sz <= 8) return VPX_CODEC_UNSUP_BITSTREAM; michael@0: if (data + data_sz <= data) return VPX_CODEC_INVALID_PARAM; michael@0: michael@0: si->is_kf = 0; michael@0: si->w = si->h = 0; michael@0: michael@0: { michael@0: struct vp9_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL }; michael@0: const int frame_marker = vp9_rb_read_literal(&rb, 2); michael@0: const int version = vp9_rb_read_bit(&rb) | (vp9_rb_read_bit(&rb) << 1); michael@0: if (frame_marker != 0x2) return VPX_CODEC_UNSUP_BITSTREAM; michael@0: #if CONFIG_NON420 michael@0: if (version > 1) return VPX_CODEC_UNSUP_BITSTREAM; michael@0: #else michael@0: if (version != 0) return VPX_CODEC_UNSUP_BITSTREAM; michael@0: #endif michael@0: michael@0: if (vp9_rb_read_bit(&rb)) { // show an existing frame michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: si->is_kf = !vp9_rb_read_bit(&rb); michael@0: if (si->is_kf) { michael@0: const int sRGB = 7; michael@0: int colorspace; michael@0: michael@0: rb.bit_offset += 1; // show frame michael@0: rb.bit_offset += 1; // error resilient michael@0: michael@0: if (vp9_rb_read_literal(&rb, 8) != VP9_SYNC_CODE_0 || michael@0: vp9_rb_read_literal(&rb, 8) != VP9_SYNC_CODE_1 || michael@0: vp9_rb_read_literal(&rb, 8) != VP9_SYNC_CODE_2) { michael@0: return VPX_CODEC_UNSUP_BITSTREAM; michael@0: } michael@0: michael@0: colorspace = vp9_rb_read_literal(&rb, 3); michael@0: if (colorspace != sRGB) { michael@0: rb.bit_offset += 1; // [16,235] (including xvycc) vs [0,255] range michael@0: if (version == 1) { michael@0: rb.bit_offset += 2; // subsampling x/y michael@0: rb.bit_offset += 1; // has extra plane michael@0: } michael@0: } else { michael@0: if (version == 1) { michael@0: rb.bit_offset += 1; // has extra plane michael@0: } else { michael@0: // RGB is only available in version 1 michael@0: return VPX_CODEC_UNSUP_BITSTREAM; michael@0: } michael@0: } michael@0: michael@0: // TODO(jzern): these are available on non-keyframes in intra only mode. michael@0: si->w = vp9_rb_read_literal(&rb, 16) + 1; michael@0: si->h = vp9_rb_read_literal(&rb, 16) + 1; michael@0: } michael@0: } michael@0: michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9_get_si(vpx_codec_alg_priv_t *ctx, michael@0: vpx_codec_stream_info_t *si) { michael@0: unsigned int sz; michael@0: michael@0: if (si->sz >= sizeof(vp9_stream_info_t)) michael@0: sz = sizeof(vp9_stream_info_t); michael@0: else michael@0: sz = sizeof(vpx_codec_stream_info_t); michael@0: michael@0: memcpy(si, &ctx->si, sz); michael@0: si->sz = sz; michael@0: michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: michael@0: static vpx_codec_err_t michael@0: update_error_state(vpx_codec_alg_priv_t *ctx, michael@0: const struct vpx_internal_error_info *error) { michael@0: vpx_codec_err_t res; michael@0: michael@0: if ((res = error->error_code)) michael@0: ctx->base.err_detail = error->has_detail michael@0: ? error->detail michael@0: : NULL; michael@0: michael@0: return res; michael@0: } michael@0: michael@0: static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, michael@0: const uint8_t **data, michael@0: unsigned int data_sz, michael@0: void *user_priv, michael@0: long deadline) { michael@0: vpx_codec_err_t res = VPX_CODEC_OK; michael@0: michael@0: ctx->img_avail = 0; michael@0: michael@0: /* Determine the stream parameters. Note that we rely on peek_si to michael@0: * validate that we have a buffer that does not wrap around the top michael@0: * of the heap. michael@0: */ michael@0: if (!ctx->si.h) michael@0: res = ctx->base.iface->dec.peek_si(*data, data_sz, &ctx->si); michael@0: michael@0: michael@0: /* Perform deferred allocations, if required */ michael@0: if (!res && ctx->defer_alloc) { michael@0: int i; michael@0: michael@0: for (i = 1; !res && i < NELEMENTS(ctx->mmaps); i++) { michael@0: vpx_codec_dec_cfg_t cfg; michael@0: michael@0: cfg.w = ctx->si.w; michael@0: cfg.h = ctx->si.h; michael@0: ctx->mmaps[i].id = vp9_mem_req_segs[i].id; michael@0: ctx->mmaps[i].sz = vp9_mem_req_segs[i].sz; michael@0: ctx->mmaps[i].align = vp9_mem_req_segs[i].align; michael@0: ctx->mmaps[i].flags = vp9_mem_req_segs[i].flags; michael@0: michael@0: if (!ctx->mmaps[i].sz) michael@0: ctx->mmaps[i].sz = vp9_mem_req_segs[i].calc_sz(&cfg, michael@0: ctx->base.init_flags); michael@0: michael@0: res = vpx_mmap_alloc(&ctx->mmaps[i]); michael@0: } michael@0: michael@0: if (!res) michael@0: vp9_finalize_mmaps(ctx); michael@0: michael@0: ctx->defer_alloc = 0; michael@0: } michael@0: michael@0: /* Initialize the decoder instance on the first frame*/ michael@0: if (!res && !ctx->decoder_init) { michael@0: res = vpx_validate_mmaps(&ctx->si, ctx->mmaps, michael@0: vp9_mem_req_segs, NELEMENTS(vp9_mem_req_segs), michael@0: ctx->base.init_flags); michael@0: michael@0: if (!res) { michael@0: VP9D_CONFIG oxcf; michael@0: VP9D_PTR optr; michael@0: michael@0: vp9_initialize_dec(); michael@0: michael@0: oxcf.width = ctx->si.w; michael@0: oxcf.height = ctx->si.h; michael@0: oxcf.version = 9; michael@0: oxcf.postprocess = 0; michael@0: oxcf.max_threads = ctx->cfg.threads; michael@0: oxcf.inv_tile_order = ctx->invert_tile_order; michael@0: optr = vp9_create_decompressor(&oxcf); michael@0: michael@0: /* If postprocessing was enabled by the application and a michael@0: * configuration has not been provided, default it. michael@0: */ michael@0: if (!ctx->postproc_cfg_set michael@0: && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) { michael@0: ctx->postproc_cfg.post_proc_flag = michael@0: VP8_DEBLOCK | VP8_DEMACROBLOCK; michael@0: ctx->postproc_cfg.deblocking_level = 4; michael@0: ctx->postproc_cfg.noise_level = 0; michael@0: } michael@0: michael@0: if (!optr) michael@0: res = VPX_CODEC_ERROR; michael@0: else michael@0: ctx->pbi = optr; michael@0: } michael@0: michael@0: ctx->decoder_init = 1; michael@0: } michael@0: michael@0: if (!res && ctx->pbi) { michael@0: YV12_BUFFER_CONFIG sd; michael@0: int64_t time_stamp = 0, time_end_stamp = 0; michael@0: vp9_ppflags_t flags = {0}; michael@0: michael@0: if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) { michael@0: flags.post_proc_flag = michael@0: #if CONFIG_POSTPROC_VISUALIZER michael@0: ((ctx->dbg_color_ref_frame_flag != 0) ? michael@0: VP9D_DEBUG_CLR_FRM_REF_BLKS : 0) michael@0: | ((ctx->dbg_color_mb_modes_flag != 0) ? michael@0: VP9D_DEBUG_CLR_BLK_MODES : 0) michael@0: | ((ctx->dbg_color_b_modes_flag != 0) ? michael@0: VP9D_DEBUG_CLR_BLK_MODES : 0) michael@0: | ((ctx->dbg_display_mv_flag != 0) ? michael@0: VP9D_DEBUG_DRAW_MV : 0) michael@0: | michael@0: #endif michael@0: ctx->postproc_cfg.post_proc_flag; michael@0: michael@0: flags.deblocking_level = ctx->postproc_cfg.deblocking_level; michael@0: flags.noise_level = ctx->postproc_cfg.noise_level; michael@0: #if CONFIG_POSTPROC_VISUALIZER michael@0: flags.display_ref_frame_flag = ctx->dbg_color_ref_frame_flag; michael@0: flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag; michael@0: flags.display_b_modes_flag = ctx->dbg_color_b_modes_flag; michael@0: flags.display_mv_flag = ctx->dbg_display_mv_flag; michael@0: #endif michael@0: } michael@0: michael@0: if (vp9_receive_compressed_data(ctx->pbi, data_sz, data, deadline)) { michael@0: VP9D_COMP *pbi = (VP9D_COMP *)ctx->pbi; michael@0: res = update_error_state(ctx, &pbi->common.error); michael@0: } michael@0: michael@0: if (!res && 0 == vp9_get_raw_frame(ctx->pbi, &sd, &time_stamp, michael@0: &time_end_stamp, &flags)) { michael@0: yuvconfig2image(&ctx->img, &sd, user_priv); michael@0: ctx->img_avail = 1; michael@0: } michael@0: } michael@0: michael@0: return res; michael@0: } michael@0: michael@0: static void parse_superframe_index(const uint8_t *data, michael@0: size_t data_sz, michael@0: uint32_t sizes[8], michael@0: int *count) { michael@0: uint8_t marker; michael@0: michael@0: assert(data_sz); michael@0: marker = data[data_sz - 1]; michael@0: *count = 0; michael@0: michael@0: if ((marker & 0xe0) == 0xc0) { michael@0: const uint32_t frames = (marker & 0x7) + 1; michael@0: const uint32_t mag = ((marker >> 3) & 0x3) + 1; michael@0: const size_t index_sz = 2 + mag * frames; michael@0: michael@0: if (data_sz >= index_sz && data[data_sz - index_sz] == marker) { michael@0: // found a valid superframe index michael@0: uint32_t i, j; michael@0: const uint8_t *x = data + data_sz - index_sz + 1; michael@0: michael@0: for (i = 0; i < frames; i++) { michael@0: uint32_t this_sz = 0; michael@0: michael@0: for (j = 0; j < mag; j++) michael@0: this_sz |= (*x++) << (j * 8); michael@0: sizes[i] = this_sz; michael@0: } michael@0: michael@0: *count = frames; michael@0: } michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9_decode(vpx_codec_alg_priv_t *ctx, michael@0: const uint8_t *data, michael@0: unsigned int data_sz, michael@0: void *user_priv, michael@0: long deadline) { michael@0: const uint8_t *data_start = data; michael@0: const uint8_t *data_end = data + data_sz; michael@0: vpx_codec_err_t res = 0; michael@0: uint32_t sizes[8]; michael@0: int frames_this_pts, frame_count = 0; michael@0: michael@0: if (data == NULL || data_sz == 0) return VPX_CODEC_INVALID_PARAM; michael@0: michael@0: parse_superframe_index(data, data_sz, sizes, &frames_this_pts); michael@0: michael@0: do { michael@0: // Skip over the superframe index, if present michael@0: if (data_sz && (*data_start & 0xe0) == 0xc0) { michael@0: const uint8_t marker = *data_start; michael@0: const uint32_t frames = (marker & 0x7) + 1; michael@0: const uint32_t mag = ((marker >> 3) & 0x3) + 1; michael@0: const uint32_t index_sz = 2 + mag * frames; michael@0: michael@0: if (data_sz >= index_sz && data_start[index_sz - 1] == marker) { michael@0: data_start += index_sz; michael@0: data_sz -= index_sz; michael@0: if (data_start < data_end) michael@0: continue; michael@0: else michael@0: break; michael@0: } michael@0: } michael@0: michael@0: // Use the correct size for this frame, if an index is present. michael@0: if (frames_this_pts) { michael@0: uint32_t this_sz = sizes[frame_count]; michael@0: michael@0: if (data_sz < this_sz) { michael@0: ctx->base.err_detail = "Invalid frame size in index"; michael@0: return VPX_CODEC_CORRUPT_FRAME; michael@0: } michael@0: michael@0: data_sz = this_sz; michael@0: frame_count++; michael@0: } michael@0: michael@0: res = decode_one(ctx, &data_start, data_sz, user_priv, deadline); michael@0: assert(data_start >= data); michael@0: assert(data_start <= data_end); michael@0: michael@0: /* Early exit if there was a decode error */ michael@0: if (res) michael@0: break; michael@0: michael@0: /* Account for suboptimal termination by the encoder. */ michael@0: while (data_start < data_end && *data_start == 0) michael@0: data_start++; michael@0: michael@0: data_sz = data_end - data_start; michael@0: } while (data_start < data_end); michael@0: return res; michael@0: } michael@0: michael@0: static vpx_image_t *vp9_get_frame(vpx_codec_alg_priv_t *ctx, michael@0: vpx_codec_iter_t *iter) { michael@0: vpx_image_t *img = NULL; michael@0: michael@0: if (ctx->img_avail) { michael@0: /* iter acts as a flip flop, so an image is only returned on the first michael@0: * call to get_frame. michael@0: */ michael@0: if (!(*iter)) { michael@0: img = &ctx->img; michael@0: *iter = img; michael@0: } michael@0: } michael@0: ctx->img_avail = 0; michael@0: michael@0: return img; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9_xma_get_mmap(const vpx_codec_ctx_t *ctx, michael@0: vpx_codec_mmap_t *mmap, michael@0: vpx_codec_iter_t *iter) { michael@0: vpx_codec_err_t res; michael@0: const mem_req_t *seg_iter = *iter; michael@0: michael@0: /* Get address of next segment request */ michael@0: do { michael@0: if (!seg_iter) michael@0: seg_iter = vp9_mem_req_segs; michael@0: else if (seg_iter->id != VP9_SEG_MAX) michael@0: seg_iter++; michael@0: michael@0: *iter = (vpx_codec_iter_t)seg_iter; michael@0: michael@0: if (seg_iter->id != VP9_SEG_MAX) { michael@0: mmap->id = seg_iter->id; michael@0: mmap->sz = seg_iter->sz; michael@0: mmap->align = seg_iter->align; michael@0: mmap->flags = seg_iter->flags; michael@0: michael@0: if (!seg_iter->sz) michael@0: mmap->sz = seg_iter->calc_sz(ctx->config.dec, ctx->init_flags); michael@0: michael@0: res = VPX_CODEC_OK; michael@0: } else { michael@0: res = VPX_CODEC_LIST_END; michael@0: } michael@0: } while (!mmap->sz && res != VPX_CODEC_LIST_END); michael@0: michael@0: return res; michael@0: } michael@0: michael@0: static vpx_codec_err_t vp9_xma_set_mmap(vpx_codec_ctx_t *ctx, michael@0: const vpx_codec_mmap_t *mmap) { michael@0: vpx_codec_err_t res = VPX_CODEC_MEM_ERROR; michael@0: int i, done; michael@0: michael@0: if (!ctx->priv) { michael@0: if (mmap->id == VP9_SEG_ALG_PRIV) { michael@0: if (!ctx->priv) { michael@0: vp9_init_ctx(ctx, mmap); michael@0: res = VPX_CODEC_OK; michael@0: } michael@0: } michael@0: } michael@0: michael@0: done = 1; michael@0: michael@0: if (!res && ctx->priv->alg_priv) { michael@0: for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++) { michael@0: if (ctx->priv->alg_priv->mmaps[i].id == mmap->id) michael@0: if (!ctx->priv->alg_priv->mmaps[i].base) { michael@0: ctx->priv->alg_priv->mmaps[i] = *mmap; michael@0: res = VPX_CODEC_OK; michael@0: } michael@0: michael@0: done &= (ctx->priv->alg_priv->mmaps[i].base != NULL); michael@0: } michael@0: } michael@0: michael@0: if (done && !res) { michael@0: vp9_finalize_mmaps(ctx->priv->alg_priv); michael@0: res = ctx->iface->init(ctx, NULL); michael@0: } michael@0: michael@0: return res; michael@0: } michael@0: michael@0: static vpx_codec_err_t set_reference(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); michael@0: michael@0: if (data) { michael@0: vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; michael@0: YV12_BUFFER_CONFIG sd; michael@0: michael@0: image2yuvconfig(&frame->img, &sd); michael@0: michael@0: return vp9_set_reference_dec(ctx->pbi, michael@0: (VP9_REFFRAME)frame->frame_type, &sd); michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t copy_reference(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); michael@0: michael@0: if (data) { michael@0: vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; michael@0: YV12_BUFFER_CONFIG sd; michael@0: michael@0: image2yuvconfig(&frame->img, &sd); michael@0: michael@0: return vp9_copy_reference_dec(ctx->pbi, michael@0: (VP9_REFFRAME)frame->frame_type, &sd); michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t get_reference(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *); michael@0: michael@0: if (data) { michael@0: YV12_BUFFER_CONFIG* fb; michael@0: michael@0: vp9_get_reference_dec(ctx->pbi, data->idx, &fb); michael@0: yuvconfig2image(&data->img, fb, NULL); michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t set_postproc(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: #if CONFIG_VP9_POSTPROC michael@0: vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *); michael@0: michael@0: if (data) { michael@0: ctx->postproc_cfg_set = 1; michael@0: ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data); michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: #else michael@0: return VPX_CODEC_INCAPABLE; michael@0: #endif michael@0: } michael@0: michael@0: static vpx_codec_err_t set_dbg_options(vpx_codec_alg_priv_t *ctx, michael@0: int ctrl_id, michael@0: va_list args) { michael@0: #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC michael@0: int data = va_arg(args, int); michael@0: michael@0: #define MAP(id, var) case id: var = data; break; michael@0: michael@0: switch (ctrl_id) { michael@0: MAP(VP8_SET_DBG_COLOR_REF_FRAME, ctx->dbg_color_ref_frame_flag); michael@0: MAP(VP8_SET_DBG_COLOR_MB_MODES, ctx->dbg_color_mb_modes_flag); michael@0: MAP(VP8_SET_DBG_COLOR_B_MODES, ctx->dbg_color_b_modes_flag); michael@0: MAP(VP8_SET_DBG_DISPLAY_MV, ctx->dbg_display_mv_flag); michael@0: } michael@0: michael@0: return VPX_CODEC_OK; michael@0: #else michael@0: return VPX_CODEC_INCAPABLE; michael@0: #endif michael@0: } michael@0: michael@0: static vpx_codec_err_t get_last_ref_updates(vpx_codec_alg_priv_t *ctx, michael@0: int ctrl_id, michael@0: va_list args) { michael@0: int *update_info = va_arg(args, int *); michael@0: VP9D_COMP *pbi = (VP9D_COMP *)ctx->pbi; michael@0: michael@0: if (update_info) { michael@0: *update_info = pbi->refresh_frame_flags; michael@0: michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: michael@0: static vpx_codec_err_t get_frame_corrupted(vpx_codec_alg_priv_t *ctx, michael@0: int ctrl_id, michael@0: va_list args) { michael@0: int *corrupted = va_arg(args, int *); michael@0: michael@0: if (corrupted) { michael@0: VP9D_COMP *pbi = (VP9D_COMP *)ctx->pbi; michael@0: if (pbi) michael@0: *corrupted = pbi->common.frame_to_show->corrupted; michael@0: else michael@0: return VPX_CODEC_ERROR; michael@0: return VPX_CODEC_OK; michael@0: } else { michael@0: return VPX_CODEC_INVALID_PARAM; michael@0: } michael@0: } michael@0: michael@0: static vpx_codec_err_t set_invert_tile_order(vpx_codec_alg_priv_t *ctx, michael@0: int ctr_id, michael@0: va_list args) { michael@0: ctx->invert_tile_order = va_arg(args, int); michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: static vpx_codec_ctrl_fn_map_t ctf_maps[] = { michael@0: {VP8_SET_REFERENCE, set_reference}, michael@0: {VP8_COPY_REFERENCE, copy_reference}, michael@0: {VP8_SET_POSTPROC, set_postproc}, michael@0: {VP8_SET_DBG_COLOR_REF_FRAME, set_dbg_options}, michael@0: {VP8_SET_DBG_COLOR_MB_MODES, set_dbg_options}, michael@0: {VP8_SET_DBG_COLOR_B_MODES, set_dbg_options}, michael@0: {VP8_SET_DBG_DISPLAY_MV, set_dbg_options}, michael@0: {VP8D_GET_LAST_REF_UPDATES, get_last_ref_updates}, michael@0: {VP8D_GET_FRAME_CORRUPTED, get_frame_corrupted}, michael@0: {VP9_GET_REFERENCE, get_reference}, michael@0: {VP9_INVERT_TILE_DECODE_ORDER, set_invert_tile_order}, michael@0: { -1, NULL}, michael@0: }; michael@0: michael@0: michael@0: #ifndef VERSION_STRING michael@0: #define VERSION_STRING michael@0: #endif michael@0: CODEC_INTERFACE(vpx_codec_vp9_dx) = { michael@0: "WebM Project VP9 Decoder" VERSION_STRING, michael@0: VPX_CODEC_INTERNAL_ABI_VERSION, michael@0: VPX_CODEC_CAP_DECODER | VP9_CAP_POSTPROC, michael@0: /* vpx_codec_caps_t caps; */ michael@0: vp9_init, /* vpx_codec_init_fn_t init; */ michael@0: vp9_destroy, /* vpx_codec_destroy_fn_t destroy; */ michael@0: ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */ michael@0: vp9_xma_get_mmap, /* vpx_codec_get_mmap_fn_t get_mmap; */ michael@0: vp9_xma_set_mmap, /* vpx_codec_set_mmap_fn_t set_mmap; */ michael@0: { // NOLINT michael@0: vp9_peek_si, /* vpx_codec_peek_si_fn_t peek_si; */ michael@0: vp9_get_si, /* vpx_codec_get_si_fn_t get_si; */ michael@0: vp9_decode, /* vpx_codec_decode_fn_t decode; */ michael@0: vp9_get_frame, /* vpx_codec_frame_get_fn_t frame_get; */ michael@0: }, michael@0: { // NOLINT michael@0: /* encoder functions */ michael@0: NOT_IMPLEMENTED, michael@0: NOT_IMPLEMENTED, michael@0: NOT_IMPLEMENTED, michael@0: NOT_IMPLEMENTED, michael@0: NOT_IMPLEMENTED, michael@0: NOT_IMPLEMENTED michael@0: } michael@0: };