| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 | |
| 12 #include <stdlib.h> | 11 #include <stdlib.h> |
| 13 #include <string.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" |
| 14 #include "vpx/vpx_decoder.h" | 18 #include "vpx/vpx_decoder.h" |
| 15 #include "vpx/vp8dx.h" | 19 |
| 16 #include "vpx/internal/vpx_codec_internal.h" | |
| 17 #include "./vpx_version.h" | |
| 18 #include "vp9/common/vp9_frame_buffers.h" | 20 #include "vp9/common/vp9_frame_buffers.h" |
| 19 #include "vp9/decoder/vp9_onyxd.h" | 21 |
| 20 #include "vp9/decoder/vp9_onyxd_int.h" | 22 #include "vp9/decoder/vp9_decoder.h" |
| 21 #include "vp9/decoder/vp9_read_bit_buffer.h" | 23 #include "vp9/decoder/vp9_read_bit_buffer.h" |
| 24 |
| 22 #include "vp9/vp9_iface_common.h" | 25 #include "vp9/vp9_iface_common.h" |
| 23 | 26 |
| 24 #define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0) | 27 #define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0) |
| 25 typedef vpx_codec_stream_info_t vp9_stream_info_t; | |
| 26 | 28 |
| 27 /* Structures for handling memory allocations */ | 29 typedef vpx_codec_stream_info_t vp9_stream_info_t; |
| 28 typedef enum { | |
| 29 VP9_SEG_ALG_PRIV = 256, | |
| 30 VP9_SEG_MAX | |
| 31 } mem_seg_id_t; | |
| 32 #define NELEMENTS(x) ((int)(sizeof(x)/sizeof(x[0]))) | |
| 33 | |
| 34 static unsigned long priv_sz(const vpx_codec_dec_cfg_t *si, | |
| 35 vpx_codec_flags_t flags); | |
| 36 | |
| 37 static const mem_req_t vp9_mem_req_segs[] = { | |
| 38 {VP9_SEG_ALG_PRIV, 0, 8, VPX_CODEC_MEM_ZERO, priv_sz}, | |
| 39 {VP9_SEG_MAX, 0, 0, 0, NULL} | |
| 40 }; | |
| 41 | 30 |
| 42 struct vpx_codec_alg_priv { | 31 struct vpx_codec_alg_priv { |
| 43 vpx_codec_priv_t base; | 32 vpx_codec_priv_t base; |
| 44 vpx_codec_mmap_t mmaps[NELEMENTS(vp9_mem_req_segs) - 1]; | |
| 45 vpx_codec_dec_cfg_t cfg; | 33 vpx_codec_dec_cfg_t cfg; |
| 46 vp9_stream_info_t si; | 34 vp9_stream_info_t si; |
| 47 int defer_alloc; | |
| 48 int decoder_init; | 35 int decoder_init; |
| 49 struct VP9Decompressor *pbi; | 36 struct VP9Decoder *pbi; |
| 50 int postproc_cfg_set; | 37 int postproc_cfg_set; |
| 51 vp8_postproc_cfg_t postproc_cfg; | 38 vp8_postproc_cfg_t postproc_cfg; |
| 52 #if CONFIG_POSTPROC_VISUALIZER | 39 #if CONFIG_POSTPROC_VISUALIZER |
| 53 unsigned int dbg_postproc_flag; | 40 unsigned int dbg_postproc_flag; |
| 54 int dbg_color_ref_frame_flag; | 41 int dbg_color_ref_frame_flag; |
| 55 int dbg_color_mb_modes_flag; | 42 int dbg_color_mb_modes_flag; |
| 56 int dbg_color_b_modes_flag; | 43 int dbg_color_b_modes_flag; |
| 57 int dbg_display_mv_flag; | 44 int dbg_display_mv_flag; |
| 58 #endif | 45 #endif |
| 59 vpx_image_t img; | 46 vpx_image_t img; |
| 60 int img_setup; | 47 int img_setup; |
| 61 int img_avail; | 48 int img_avail; |
| 62 int invert_tile_order; | 49 int invert_tile_order; |
| 63 | 50 |
| 64 // External frame buffer info to save for VP9 common. | 51 // External frame buffer info to save for VP9 common. |
| 65 void *ext_priv; // Private data associated with the external frame buffers. | 52 void *ext_priv; // Private data associated with the external frame buffers. |
| 66 vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb; | 53 vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb; |
| 67 vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb; | 54 vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb; |
| 68 }; | 55 }; |
| 69 | 56 |
| 70 static unsigned long priv_sz(const vpx_codec_dec_cfg_t *si, | 57 static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx, |
| 71 vpx_codec_flags_t flags) { | 58 vpx_codec_priv_enc_mr_cfg_t *data) { |
| 72 /* Although this declaration is constant, we can't use it in the requested | |
| 73 * segments list because we want to define the requested segments list | |
| 74 * before defining the private type (so that the number of memory maps is | |
| 75 * known) | |
| 76 */ | |
| 77 (void)si; | |
| 78 return sizeof(vpx_codec_alg_priv_t); | |
| 79 } | |
| 80 | |
| 81 static void vp9_init_ctx(vpx_codec_ctx_t *ctx, const vpx_codec_mmap_t *mmap) { | |
| 82 int i; | |
| 83 | |
| 84 ctx->priv = mmap->base; | |
| 85 ctx->priv->sz = sizeof(*ctx->priv); | |
| 86 ctx->priv->iface = ctx->iface; | |
| 87 ctx->priv->alg_priv = mmap->base; | |
| 88 | |
| 89 for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++) | |
| 90 ctx->priv->alg_priv->mmaps[i].id = vp9_mem_req_segs[i].id; | |
| 91 | |
| 92 ctx->priv->alg_priv->mmaps[0] = *mmap; | |
| 93 ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si); | |
| 94 ctx->priv->init_flags = ctx->init_flags; | |
| 95 | |
| 96 if (ctx->config.dec) { | |
| 97 /* Update the reference to the config structure to an internal copy. */ | |
| 98 ctx->priv->alg_priv->cfg = *ctx->config.dec; | |
| 99 ctx->config.dec = &ctx->priv->alg_priv->cfg; | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 static void vp9_finalize_mmaps(vpx_codec_alg_priv_t *ctx) { | |
| 104 /* nothing to clean up */ | |
| 105 } | |
| 106 | |
| 107 static vpx_codec_err_t vp9_init(vpx_codec_ctx_t *ctx, | |
| 108 vpx_codec_priv_enc_mr_cfg_t *data) { | |
| 109 vpx_codec_err_t res = VPX_CODEC_OK; | |
| 110 | |
| 111 // This function only allocates space for the vpx_codec_alg_priv_t | 59 // This function only allocates space for the vpx_codec_alg_priv_t |
| 112 // structure. More memory may be required at the time the stream | 60 // structure. More memory may be required at the time the stream |
| 113 // information becomes known. | 61 // information becomes known. |
| 114 if (!ctx->priv) { | 62 if (!ctx->priv) { |
| 115 vpx_codec_mmap_t mmap; | 63 vpx_codec_alg_priv_t *alg_priv = vpx_memalign(32, sizeof(*alg_priv)); |
| 64 if (alg_priv == NULL) |
| 65 return VPX_CODEC_MEM_ERROR; |
| 116 | 66 |
| 117 mmap.id = vp9_mem_req_segs[0].id; | 67 vp9_zero(*alg_priv); |
| 118 mmap.sz = sizeof(vpx_codec_alg_priv_t); | |
| 119 mmap.align = vp9_mem_req_segs[0].align; | |
| 120 mmap.flags = vp9_mem_req_segs[0].flags; | |
| 121 | 68 |
| 122 res = vpx_mmap_alloc(&mmap); | 69 ctx->priv = (vpx_codec_priv_t *)alg_priv; |
| 123 if (!res) { | 70 ctx->priv->sz = sizeof(*ctx->priv); |
| 124 vp9_init_ctx(ctx, &mmap); | 71 ctx->priv->iface = ctx->iface; |
| 72 ctx->priv->alg_priv = alg_priv; |
| 73 ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si); |
| 74 ctx->priv->init_flags = ctx->init_flags; |
| 125 | 75 |
| 126 ctx->priv->alg_priv->defer_alloc = 1; | 76 if (ctx->config.dec) { |
| 77 // Update the reference to the config structure to an internal copy. |
| 78 ctx->priv->alg_priv->cfg = *ctx->config.dec; |
| 79 ctx->config.dec = &ctx->priv->alg_priv->cfg; |
| 127 } | 80 } |
| 128 } | 81 } |
| 129 | 82 |
| 130 return res; | |
| 131 } | |
| 132 | |
| 133 static vpx_codec_err_t vp9_destroy(vpx_codec_alg_priv_t *ctx) { | |
| 134 int i; | |
| 135 | |
| 136 vp9_remove_decompressor(ctx->pbi); | |
| 137 | |
| 138 for (i = NELEMENTS(ctx->mmaps) - 1; i >= 0; i--) { | |
| 139 if (ctx->mmaps[i].dtor) | |
| 140 ctx->mmaps[i].dtor(&ctx->mmaps[i]); | |
| 141 } | |
| 142 | |
| 143 return VPX_CODEC_OK; | 83 return VPX_CODEC_OK; |
| 144 } | 84 } |
| 145 | 85 |
| 146 static vpx_codec_err_t vp9_peek_si(const uint8_t *data, unsigned int data_sz, | 86 static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) { |
| 147 vpx_codec_stream_info_t *si) { | 87 if (ctx->pbi) { |
| 148 if (data_sz <= 8) return VPX_CODEC_UNSUP_BITSTREAM; | 88 vp9_decoder_remove(ctx->pbi); |
| 149 if (data + data_sz <= data) return VPX_CODEC_INVALID_PARAM; | 89 ctx->pbi = NULL; |
| 90 } |
| 91 |
| 92 vpx_free(ctx); |
| 93 |
| 94 return VPX_CODEC_OK; |
| 95 } |
| 96 |
| 97 static vpx_codec_err_t decoder_peek_si(const uint8_t *data, |
| 98 unsigned int data_sz, |
| 99 vpx_codec_stream_info_t *si) { |
| 100 if (data_sz <= 8) |
| 101 return VPX_CODEC_UNSUP_BITSTREAM; |
| 102 |
| 103 if (data + data_sz <= data) |
| 104 return VPX_CODEC_INVALID_PARAM; |
| 150 | 105 |
| 151 si->is_kf = 0; | 106 si->is_kf = 0; |
| 152 si->w = si->h = 0; | 107 si->w = si->h = 0; |
| 153 | 108 |
| 154 { | 109 { |
| 155 struct vp9_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL }; | 110 struct vp9_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL }; |
| 156 const int frame_marker = vp9_rb_read_literal(&rb, 2); | 111 const int frame_marker = vp9_rb_read_literal(&rb, 2); |
| 157 const int version = vp9_rb_read_bit(&rb); | 112 const int version = vp9_rb_read_bit(&rb); |
| 158 (void) vp9_rb_read_bit(&rb); // unused version bit | 113 (void) vp9_rb_read_bit(&rb); // unused version bit |
| 159 | 114 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 152 |
| 198 // TODO(jzern): these are available on non-keyframes in intra only mode. | 153 // TODO(jzern): these are available on non-keyframes in intra only mode. |
| 199 si->w = vp9_rb_read_literal(&rb, 16) + 1; | 154 si->w = vp9_rb_read_literal(&rb, 16) + 1; |
| 200 si->h = vp9_rb_read_literal(&rb, 16) + 1; | 155 si->h = vp9_rb_read_literal(&rb, 16) + 1; |
| 201 } | 156 } |
| 202 } | 157 } |
| 203 | 158 |
| 204 return VPX_CODEC_OK; | 159 return VPX_CODEC_OK; |
| 205 } | 160 } |
| 206 | 161 |
| 207 static vpx_codec_err_t vp9_get_si(vpx_codec_alg_priv_t *ctx, | 162 static vpx_codec_err_t decoder_get_si(vpx_codec_alg_priv_t *ctx, |
| 208 vpx_codec_stream_info_t *si) { | 163 vpx_codec_stream_info_t *si) { |
| 209 const size_t sz = (si->sz >= sizeof(vp9_stream_info_t)) | 164 const size_t sz = (si->sz >= sizeof(vp9_stream_info_t)) |
| 210 ? sizeof(vp9_stream_info_t) | 165 ? sizeof(vp9_stream_info_t) |
| 211 : sizeof(vpx_codec_stream_info_t); | 166 : sizeof(vpx_codec_stream_info_t); |
| 212 memcpy(si, &ctx->si, sz); | 167 memcpy(si, &ctx->si, sz); |
| 213 si->sz = (unsigned int)sz; | 168 si->sz = (unsigned int)sz; |
| 214 | 169 |
| 215 return VPX_CODEC_OK; | 170 return VPX_CODEC_OK; |
| 216 } | 171 } |
| 217 | 172 |
| 218 | |
| 219 static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx, | 173 static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx, |
| 220 const struct vpx_internal_error_info *error) { | 174 const struct vpx_internal_error_info *error) { |
| 221 if (error->error_code) | 175 if (error->error_code) |
| 222 ctx->base.err_detail = error->has_detail ? error->detail : NULL; | 176 ctx->base.err_detail = error->has_detail ? error->detail : NULL; |
| 223 | 177 |
| 224 return error->error_code; | 178 return error->error_code; |
| 225 } | 179 } |
| 226 | 180 |
| 181 static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) { |
| 182 VP9_COMMON *const cm = &ctx->pbi->common; |
| 183 |
| 184 cm->new_fb_idx = -1; |
| 185 |
| 186 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { |
| 187 cm->get_fb_cb = ctx->get_ext_fb_cb; |
| 188 cm->release_fb_cb = ctx->release_ext_fb_cb; |
| 189 cm->cb_priv = ctx->ext_priv; |
| 190 } else { |
| 191 cm->get_fb_cb = vp9_get_frame_buffer; |
| 192 cm->release_fb_cb = vp9_release_frame_buffer; |
| 193 |
| 194 if (vp9_alloc_internal_frame_buffers(&cm->int_frame_buffers)) |
| 195 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 196 "Failed to initialize internal frame buffers"); |
| 197 |
| 198 cm->cb_priv = &cm->int_frame_buffers; |
| 199 } |
| 200 } |
| 201 |
| 202 static void set_default_ppflags(vp8_postproc_cfg_t *cfg) { |
| 203 cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; |
| 204 cfg->deblocking_level = 4; |
| 205 cfg->noise_level = 0; |
| 206 } |
| 207 |
| 208 static void set_ppflags(const vpx_codec_alg_priv_t *ctx, |
| 209 vp9_ppflags_t *flags) { |
| 210 flags->post_proc_flag = |
| 211 #if CONFIG_POSTPROC_VISUALIZER |
| 212 (ctx->dbg_color_ref_frame_flag ? VP9D_DEBUG_CLR_FRM_REF_BLKS : 0) | |
| 213 (ctx->dbg_color_mb_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | |
| 214 (ctx->dbg_color_b_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | |
| 215 (ctx->dbg_display_mv_flag ? VP9D_DEBUG_DRAW_MV : 0) | |
| 216 #endif |
| 217 ctx->postproc_cfg.post_proc_flag; |
| 218 |
| 219 flags->deblocking_level = ctx->postproc_cfg.deblocking_level; |
| 220 flags->noise_level = ctx->postproc_cfg.noise_level; |
| 221 #if CONFIG_POSTPROC_VISUALIZER |
| 222 flags->display_ref_frame_flag = ctx->dbg_color_ref_frame_flag; |
| 223 flags->display_mb_modes_flag = ctx->dbg_color_mb_modes_flag; |
| 224 flags->display_b_modes_flag = ctx->dbg_color_b_modes_flag; |
| 225 flags->display_mv_flag = ctx->dbg_display_mv_flag; |
| 226 #endif |
| 227 } |
| 228 |
| 229 static void init_decoder(vpx_codec_alg_priv_t *ctx) { |
| 230 VP9D_CONFIG oxcf; |
| 231 oxcf.width = ctx->si.w; |
| 232 oxcf.height = ctx->si.h; |
| 233 oxcf.version = 9; |
| 234 oxcf.max_threads = ctx->cfg.threads; |
| 235 oxcf.inv_tile_order = ctx->invert_tile_order; |
| 236 |
| 237 ctx->pbi = vp9_decoder_create(&oxcf); |
| 238 if (ctx->pbi == NULL) |
| 239 return; |
| 240 |
| 241 vp9_initialize_dec(); |
| 242 |
| 243 // If postprocessing was enabled by the application and a |
| 244 // configuration has not been provided, default it. |
| 245 if (!ctx->postproc_cfg_set && |
| 246 (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) |
| 247 set_default_ppflags(&ctx->postproc_cfg); |
| 248 |
| 249 init_buffer_callbacks(ctx); |
| 250 } |
| 251 |
| 227 static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, | 252 static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, |
| 228 const uint8_t **data, unsigned int data_sz, | 253 const uint8_t **data, unsigned int data_sz, |
| 229 void *user_priv, int64_t deadline) { | 254 void *user_priv, int64_t deadline) { |
| 230 vpx_codec_err_t res = VPX_CODEC_OK; | 255 YV12_BUFFER_CONFIG sd = { 0 }; |
| 256 int64_t time_stamp = 0, time_end_stamp = 0; |
| 257 vp9_ppflags_t flags = {0}; |
| 258 VP9_COMMON *cm = NULL; |
| 231 | 259 |
| 232 ctx->img_avail = 0; | 260 ctx->img_avail = 0; |
| 233 | 261 |
| 234 /* Determine the stream parameters. Note that we rely on peek_si to | 262 // Determine the stream parameters. Note that we rely on peek_si to |
| 235 * validate that we have a buffer that does not wrap around the top | 263 // validate that we have a buffer that does not wrap around the top |
| 236 * of the heap. | 264 // of the heap. |
| 237 */ | 265 if (!ctx->si.h) { |
| 238 if (!ctx->si.h) | 266 const vpx_codec_err_t res = |
| 239 res = ctx->base.iface->dec.peek_si(*data, data_sz, &ctx->si); | 267 ctx->base.iface->dec.peek_si(*data, data_sz, &ctx->si); |
| 240 | 268 if (res != VPX_CODEC_OK) |
| 241 | 269 return res; |
| 242 /* Perform deferred allocations, if required */ | |
| 243 if (!res && ctx->defer_alloc) { | |
| 244 int i; | |
| 245 | |
| 246 for (i = 1; !res && i < NELEMENTS(ctx->mmaps); i++) { | |
| 247 vpx_codec_dec_cfg_t cfg; | |
| 248 | |
| 249 cfg.w = ctx->si.w; | |
| 250 cfg.h = ctx->si.h; | |
| 251 ctx->mmaps[i].id = vp9_mem_req_segs[i].id; | |
| 252 ctx->mmaps[i].sz = vp9_mem_req_segs[i].sz; | |
| 253 ctx->mmaps[i].align = vp9_mem_req_segs[i].align; | |
| 254 ctx->mmaps[i].flags = vp9_mem_req_segs[i].flags; | |
| 255 | |
| 256 if (!ctx->mmaps[i].sz) | |
| 257 ctx->mmaps[i].sz = vp9_mem_req_segs[i].calc_sz(&cfg, | |
| 258 ctx->base.init_flags); | |
| 259 | |
| 260 res = vpx_mmap_alloc(&ctx->mmaps[i]); | |
| 261 } | |
| 262 | |
| 263 if (!res) | |
| 264 vp9_finalize_mmaps(ctx); | |
| 265 | |
| 266 ctx->defer_alloc = 0; | |
| 267 } | 270 } |
| 268 | 271 |
| 269 /* Initialize the decoder instance on the first frame*/ | 272 // Initialize the decoder instance on the first frame |
| 270 if (!res && !ctx->decoder_init) { | 273 if (!ctx->decoder_init) { |
| 271 res = vpx_validate_mmaps(&ctx->si, ctx->mmaps, | 274 init_decoder(ctx); |
| 272 vp9_mem_req_segs, NELEMENTS(vp9_mem_req_segs), | 275 if (ctx->pbi == NULL) |
| 273 ctx->base.init_flags); | 276 return VPX_CODEC_ERROR; |
| 274 | |
| 275 if (!res) { | |
| 276 VP9D_CONFIG oxcf; | |
| 277 struct VP9Decompressor *optr; | |
| 278 | |
| 279 vp9_initialize_dec(); | |
| 280 | |
| 281 oxcf.width = ctx->si.w; | |
| 282 oxcf.height = ctx->si.h; | |
| 283 oxcf.version = 9; | |
| 284 oxcf.postprocess = 0; | |
| 285 oxcf.max_threads = ctx->cfg.threads; | |
| 286 oxcf.inv_tile_order = ctx->invert_tile_order; | |
| 287 optr = vp9_create_decompressor(&oxcf); | |
| 288 | |
| 289 // If postprocessing was enabled by the application and a | |
| 290 // configuration has not been provided, default it. | |
| 291 if (!ctx->postproc_cfg_set && | |
| 292 (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) { | |
| 293 ctx->postproc_cfg.post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; | |
| 294 ctx->postproc_cfg.deblocking_level = 4; | |
| 295 ctx->postproc_cfg.noise_level = 0; | |
| 296 } | |
| 297 | |
| 298 if (!optr) { | |
| 299 res = VPX_CODEC_ERROR; | |
| 300 } else { | |
| 301 VP9D_COMP *const pbi = (VP9D_COMP*)optr; | |
| 302 VP9_COMMON *const cm = &pbi->common; | |
| 303 | |
| 304 // Set index to not initialized. | |
| 305 cm->new_fb_idx = -1; | |
| 306 | |
| 307 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { | |
| 308 cm->get_fb_cb = ctx->get_ext_fb_cb; | |
| 309 cm->release_fb_cb = ctx->release_ext_fb_cb; | |
| 310 cm->cb_priv = ctx->ext_priv; | |
| 311 } else { | |
| 312 cm->get_fb_cb = vp9_get_frame_buffer; | |
| 313 cm->release_fb_cb = vp9_release_frame_buffer; | |
| 314 | |
| 315 if (vp9_alloc_internal_frame_buffers(&cm->int_frame_buffers)) | |
| 316 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | |
| 317 "Failed to initialize internal frame buffers"); | |
| 318 cm->cb_priv = &cm->int_frame_buffers; | |
| 319 } | |
| 320 | |
| 321 ctx->pbi = optr; | |
| 322 } | |
| 323 } | |
| 324 | 277 |
| 325 ctx->decoder_init = 1; | 278 ctx->decoder_init = 1; |
| 326 } | 279 } |
| 327 | 280 |
| 328 if (!res && ctx->pbi) { | 281 cm = &ctx->pbi->common; |
| 329 YV12_BUFFER_CONFIG sd; | |
| 330 int64_t time_stamp = 0, time_end_stamp = 0; | |
| 331 vp9_ppflags_t flags = {0}; | |
| 332 | 282 |
| 333 if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) { | 283 if (vp9_receive_compressed_data(ctx->pbi, data_sz, data, deadline)) |
| 334 flags.post_proc_flag = | 284 return update_error_state(ctx, &cm->error); |
| 335 #if CONFIG_POSTPROC_VISUALIZER | |
| 336 (ctx->dbg_color_ref_frame_flag ? VP9D_DEBUG_CLR_FRM_REF_BLKS : 0) | | |
| 337 (ctx->dbg_color_mb_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | | |
| 338 (ctx->dbg_color_b_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | | |
| 339 (ctx->dbg_display_mv_flag ? VP9D_DEBUG_DRAW_MV : 0) | | |
| 340 #endif | |
| 341 ctx->postproc_cfg.post_proc_flag; | |
| 342 | 285 |
| 343 flags.deblocking_level = ctx->postproc_cfg.deblocking_level; | 286 if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) |
| 344 flags.noise_level = ctx->postproc_cfg.noise_level; | 287 set_ppflags(ctx, &flags); |
| 345 #if CONFIG_POSTPROC_VISUALIZER | |
| 346 flags.display_ref_frame_flag = ctx->dbg_color_ref_frame_flag; | |
| 347 flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag; | |
| 348 flags.display_b_modes_flag = ctx->dbg_color_b_modes_flag; | |
| 349 flags.display_mv_flag = ctx->dbg_display_mv_flag; | |
| 350 #endif | |
| 351 } | |
| 352 | 288 |
| 353 if (vp9_receive_compressed_data(ctx->pbi, data_sz, data, deadline)) { | 289 if (vp9_get_raw_frame(ctx->pbi, &sd, &time_stamp, &time_end_stamp, &flags)) |
| 354 VP9D_COMP *pbi = (VP9D_COMP*)ctx->pbi; | 290 return update_error_state(ctx, &cm->error); |
| 355 res = update_error_state(ctx, &pbi->common.error); | |
| 356 } | |
| 357 | 291 |
| 358 if (!res && 0 == vp9_get_raw_frame(ctx->pbi, &sd, &time_stamp, | 292 yuvconfig2image(&ctx->img, &sd, user_priv); |
| 359 &time_end_stamp, &flags)) { | 293 ctx->img.fb_priv = cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; |
| 360 VP9D_COMP *const pbi = (VP9D_COMP*)ctx->pbi; | 294 ctx->img_avail = 1; |
| 361 VP9_COMMON *const cm = &pbi->common; | |
| 362 yuvconfig2image(&ctx->img, &sd, user_priv); | |
| 363 | 295 |
| 364 ctx->img.fb_priv = cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; | 296 return VPX_CODEC_OK; |
| 365 ctx->img_avail = 1; | |
| 366 } | |
| 367 } | |
| 368 | |
| 369 return res; | |
| 370 } | 297 } |
| 371 | 298 |
| 372 static void parse_superframe_index(const uint8_t *data, size_t data_sz, | 299 static void parse_superframe_index(const uint8_t *data, size_t data_sz, |
| 373 uint32_t sizes[8], int *count) { | 300 uint32_t sizes[8], int *count) { |
| 374 uint8_t marker; | 301 uint8_t marker; |
| 375 | 302 |
| 376 assert(data_sz); | 303 assert(data_sz); |
| 377 marker = data[data_sz - 1]; | 304 marker = data[data_sz - 1]; |
| 378 *count = 0; | 305 *count = 0; |
| 379 | 306 |
| 380 if ((marker & 0xe0) == 0xc0) { | 307 if ((marker & 0xe0) == 0xc0) { |
| 381 const uint32_t frames = (marker & 0x7) + 1; | 308 const uint32_t frames = (marker & 0x7) + 1; |
| 382 const uint32_t mag = ((marker >> 3) & 0x3) + 1; | 309 const uint32_t mag = ((marker >> 3) & 0x3) + 1; |
| 383 const size_t index_sz = 2 + mag * frames; | 310 const size_t index_sz = 2 + mag * frames; |
| 384 | 311 |
| 385 if (data_sz >= index_sz && data[data_sz - index_sz] == marker) { | 312 if (data_sz >= index_sz && data[data_sz - index_sz] == marker) { |
| 386 // found a valid superframe index | 313 // found a valid superframe index |
| 387 uint32_t i, j; | 314 uint32_t i, j; |
| 388 const uint8_t *x = data + data_sz - index_sz + 1; | 315 const uint8_t *x = &data[data_sz - index_sz + 1]; |
| 389 | 316 |
| 390 for (i = 0; i < frames; i++) { | 317 for (i = 0; i < frames; i++) { |
| 391 uint32_t this_sz = 0; | 318 uint32_t this_sz = 0; |
| 392 | 319 |
| 393 for (j = 0; j < mag; j++) | 320 for (j = 0; j < mag; j++) |
| 394 this_sz |= (*x++) << (j * 8); | 321 this_sz |= (*x++) << (j * 8); |
| 395 sizes[i] = this_sz; | 322 sizes[i] = this_sz; |
| 396 } | 323 } |
| 397 | 324 |
| 398 *count = frames; | 325 *count = frames; |
| 399 } | 326 } |
| 400 } | 327 } |
| 401 } | 328 } |
| 402 | 329 |
| 403 static vpx_codec_err_t vp9_decode(vpx_codec_alg_priv_t *ctx, | 330 static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx, |
| 404 const uint8_t *data, | 331 const uint8_t *data, unsigned int data_sz, |
| 405 unsigned int data_sz, | 332 void *user_priv, long deadline) { |
| 406 void *user_priv, | |
| 407 long deadline) { | |
| 408 const uint8_t *data_start = data; | 333 const uint8_t *data_start = data; |
| 409 const uint8_t *data_end = data + data_sz; | 334 const uint8_t *data_end = data + data_sz; |
| 410 vpx_codec_err_t res = 0; | 335 vpx_codec_err_t res = VPX_CODEC_OK; |
| 411 uint32_t sizes[8]; | 336 uint32_t sizes[8]; |
| 412 int frames_this_pts, frame_count = 0; | 337 int frames_this_pts, frame_count = 0; |
| 413 | 338 |
| 414 if (data == NULL || data_sz == 0) return VPX_CODEC_INVALID_PARAM; | 339 if (data == NULL || data_sz == 0) |
| 340 return VPX_CODEC_INVALID_PARAM; |
| 415 | 341 |
| 416 parse_superframe_index(data, data_sz, sizes, &frames_this_pts); | 342 parse_superframe_index(data, data_sz, sizes, &frames_this_pts); |
| 417 | 343 |
| 418 do { | 344 do { |
| 419 // Skip over the superframe index, if present | 345 // Skip over the superframe index, if present |
| 420 if (data_sz && (*data_start & 0xe0) == 0xc0) { | 346 if (data_sz && (*data_start & 0xe0) == 0xc0) { |
| 421 const uint8_t marker = *data_start; | 347 const uint8_t marker = *data_start; |
| 422 const uint32_t frames = (marker & 0x7) + 1; | 348 const uint32_t frames = (marker & 0x7) + 1; |
| 423 const uint32_t mag = ((marker >> 3) & 0x3) + 1; | 349 const uint32_t mag = ((marker >> 3) & 0x3) + 1; |
| 424 const uint32_t index_sz = 2 + mag * frames; | 350 const uint32_t index_sz = 2 + mag * frames; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 443 } | 369 } |
| 444 | 370 |
| 445 data_sz = this_sz; | 371 data_sz = this_sz; |
| 446 frame_count++; | 372 frame_count++; |
| 447 } | 373 } |
| 448 | 374 |
| 449 res = decode_one(ctx, &data_start, data_sz, user_priv, deadline); | 375 res = decode_one(ctx, &data_start, data_sz, user_priv, deadline); |
| 450 assert(data_start >= data); | 376 assert(data_start >= data); |
| 451 assert(data_start <= data_end); | 377 assert(data_start <= data_end); |
| 452 | 378 |
| 453 /* Early exit if there was a decode error */ | 379 // Early exit if there was a decode error |
| 454 if (res) | 380 if (res) |
| 455 break; | 381 break; |
| 456 | 382 |
| 457 /* Account for suboptimal termination by the encoder. */ | 383 // Account for suboptimal termination by the encoder. |
| 458 while (data_start < data_end && *data_start == 0) | 384 while (data_start < data_end && *data_start == 0) |
| 459 data_start++; | 385 data_start++; |
| 460 | 386 |
| 461 data_sz = (unsigned int)(data_end - data_start); | 387 data_sz = (unsigned int)(data_end - data_start); |
| 462 } while (data_start < data_end); | 388 } while (data_start < data_end); |
| 389 |
| 463 return res; | 390 return res; |
| 464 } | 391 } |
| 465 | 392 |
| 466 static vpx_image_t *vp9_get_frame(vpx_codec_alg_priv_t *ctx, | 393 static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx, |
| 467 vpx_codec_iter_t *iter) { | 394 vpx_codec_iter_t *iter) { |
| 468 vpx_image_t *img = NULL; | 395 vpx_image_t *img = NULL; |
| 469 | 396 |
| 470 if (ctx->img_avail) { | 397 if (ctx->img_avail) { |
| 471 /* iter acts as a flip flop, so an image is only returned on the first | 398 // iter acts as a flip flop, so an image is only returned on the first |
| 472 * call to get_frame. | 399 // call to get_frame. |
| 473 */ | |
| 474 if (!(*iter)) { | 400 if (!(*iter)) { |
| 475 img = &ctx->img; | 401 img = &ctx->img; |
| 476 *iter = img; | 402 *iter = img; |
| 477 } | 403 } |
| 478 } | 404 } |
| 479 ctx->img_avail = 0; | 405 ctx->img_avail = 0; |
| 480 | 406 |
| 481 return img; | 407 return img; |
| 482 } | 408 } |
| 483 | 409 |
| 484 static vpx_codec_err_t vp9_set_fb_fn( | 410 static vpx_codec_err_t decoder_set_fb_fn( |
| 485 vpx_codec_alg_priv_t *ctx, | 411 vpx_codec_alg_priv_t *ctx, |
| 486 vpx_get_frame_buffer_cb_fn_t cb_get, | 412 vpx_get_frame_buffer_cb_fn_t cb_get, |
| 487 vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) { | 413 vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) { |
| 488 if (cb_get == NULL || cb_release == NULL) { | 414 if (cb_get == NULL || cb_release == NULL) { |
| 489 return VPX_CODEC_INVALID_PARAM; | 415 return VPX_CODEC_INVALID_PARAM; |
| 490 } else if (ctx->pbi == NULL) { | 416 } else if (ctx->pbi == NULL) { |
| 491 // If the decoder has already been initialized, do not accept changes to | 417 // If the decoder has already been initialized, do not accept changes to |
| 492 // the frame buffer functions. | 418 // the frame buffer functions. |
| 493 ctx->get_ext_fb_cb = cb_get; | 419 ctx->get_ext_fb_cb = cb_get; |
| 494 ctx->release_ext_fb_cb = cb_release; | 420 ctx->release_ext_fb_cb = cb_release; |
| 495 ctx->ext_priv = cb_priv; | 421 ctx->ext_priv = cb_priv; |
| 496 return VPX_CODEC_OK; | 422 return VPX_CODEC_OK; |
| 497 } | 423 } |
| 498 | 424 |
| 499 return VPX_CODEC_ERROR; | 425 return VPX_CODEC_ERROR; |
| 500 } | 426 } |
| 501 | 427 |
| 502 static vpx_codec_err_t vp9_xma_get_mmap(const vpx_codec_ctx_t *ctx, | 428 static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx, |
| 503 vpx_codec_mmap_t *mmap, | 429 int ctr_id, va_list args) { |
| 504 vpx_codec_iter_t *iter) { | 430 vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *); |
| 505 vpx_codec_err_t res; | |
| 506 const mem_req_t *seg_iter = *iter; | |
| 507 | |
| 508 /* Get address of next segment request */ | |
| 509 do { | |
| 510 if (!seg_iter) | |
| 511 seg_iter = vp9_mem_req_segs; | |
| 512 else if (seg_iter->id != VP9_SEG_MAX) | |
| 513 seg_iter++; | |
| 514 | |
| 515 *iter = (vpx_codec_iter_t)seg_iter; | |
| 516 | |
| 517 if (seg_iter->id != VP9_SEG_MAX) { | |
| 518 mmap->id = seg_iter->id; | |
| 519 mmap->sz = seg_iter->sz; | |
| 520 mmap->align = seg_iter->align; | |
| 521 mmap->flags = seg_iter->flags; | |
| 522 | |
| 523 if (!seg_iter->sz) | |
| 524 mmap->sz = seg_iter->calc_sz(ctx->config.dec, ctx->init_flags); | |
| 525 | |
| 526 res = VPX_CODEC_OK; | |
| 527 } else { | |
| 528 res = VPX_CODEC_LIST_END; | |
| 529 } | |
| 530 } while (!mmap->sz && res != VPX_CODEC_LIST_END); | |
| 531 | |
| 532 return res; | |
| 533 } | |
| 534 | |
| 535 static vpx_codec_err_t vp9_xma_set_mmap(vpx_codec_ctx_t *ctx, | |
| 536 const vpx_codec_mmap_t *mmap) { | |
| 537 vpx_codec_err_t res = VPX_CODEC_MEM_ERROR; | |
| 538 int i, done; | |
| 539 | |
| 540 if (!ctx->priv) { | |
| 541 if (mmap->id == VP9_SEG_ALG_PRIV) { | |
| 542 if (!ctx->priv) { | |
| 543 vp9_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 for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++) { | |
| 553 if (ctx->priv->alg_priv->mmaps[i].id == mmap->id) | |
| 554 if (!ctx->priv->alg_priv->mmaps[i].base) { | |
| 555 ctx->priv->alg_priv->mmaps[i] = *mmap; | |
| 556 res = VPX_CODEC_OK; | |
| 557 } | |
| 558 | |
| 559 done &= (ctx->priv->alg_priv->mmaps[i].base != NULL); | |
| 560 } | |
| 561 } | |
| 562 | |
| 563 if (done && !res) { | |
| 564 vp9_finalize_mmaps(ctx->priv->alg_priv); | |
| 565 res = ctx->iface->init(ctx, NULL); | |
| 566 } | |
| 567 | |
| 568 return res; | |
| 569 } | |
| 570 | |
| 571 static vpx_codec_err_t set_reference(vpx_codec_alg_priv_t *ctx, int ctr_id, | |
| 572 va_list args) { | |
| 573 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); | |
| 574 | 431 |
| 575 if (data) { | 432 if (data) { |
| 576 vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; | 433 vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data; |
| 577 YV12_BUFFER_CONFIG sd; | 434 YV12_BUFFER_CONFIG sd; |
| 578 | 435 |
| 579 image2yuvconfig(&frame->img, &sd); | 436 image2yuvconfig(&frame->img, &sd); |
| 580 return vp9_set_reference_dec(ctx->pbi, | 437 return vp9_set_reference_dec(&ctx->pbi->common, |
| 581 (VP9_REFFRAME)frame->frame_type, &sd); | 438 (VP9_REFFRAME)frame->frame_type, &sd); |
| 582 } else { | 439 } else { |
| 583 return VPX_CODEC_INVALID_PARAM; | 440 return VPX_CODEC_INVALID_PARAM; |
| 584 } | 441 } |
| 585 } | 442 } |
| 586 | 443 |
| 587 static vpx_codec_err_t copy_reference(vpx_codec_alg_priv_t *ctx, int ctr_id, | 444 static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx, |
| 588 va_list args) { | 445 int ctr_id, va_list args) { |
| 589 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); | 446 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); |
| 590 | 447 |
| 591 if (data) { | 448 if (data) { |
| 592 vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; | 449 vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; |
| 593 YV12_BUFFER_CONFIG sd; | 450 YV12_BUFFER_CONFIG sd; |
| 594 | 451 |
| 595 image2yuvconfig(&frame->img, &sd); | 452 image2yuvconfig(&frame->img, &sd); |
| 596 | 453 |
| 597 return vp9_copy_reference_dec(ctx->pbi, | 454 return vp9_copy_reference_dec(ctx->pbi, |
| 598 (VP9_REFFRAME)frame->frame_type, &sd); | 455 (VP9_REFFRAME)frame->frame_type, &sd); |
| 599 } else { | 456 } else { |
| 600 return VPX_CODEC_INVALID_PARAM; | 457 return VPX_CODEC_INVALID_PARAM; |
| 601 } | 458 } |
| 602 } | 459 } |
| 603 | 460 |
| 604 static vpx_codec_err_t get_reference(vpx_codec_alg_priv_t *ctx, int ctr_id, | 461 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx, |
| 605 va_list args) { | 462 int ctr_id, va_list args) { |
| 606 vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *); | 463 vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *); |
| 607 | 464 |
| 608 if (data) { | 465 if (data) { |
| 609 YV12_BUFFER_CONFIG* fb; | 466 YV12_BUFFER_CONFIG* fb; |
| 610 | 467 |
| 611 vp9_get_reference_dec(ctx->pbi, data->idx, &fb); | 468 vp9_get_reference_dec(ctx->pbi, data->idx, &fb); |
| 612 yuvconfig2image(&data->img, fb, NULL); | 469 yuvconfig2image(&data->img, fb, NULL); |
| 613 return VPX_CODEC_OK; | 470 return VPX_CODEC_OK; |
| 614 } else { | 471 } else { |
| 615 return VPX_CODEC_INVALID_PARAM; | 472 return VPX_CODEC_INVALID_PARAM; |
| 616 } | 473 } |
| 617 } | 474 } |
| 618 | 475 |
| 619 static vpx_codec_err_t set_postproc(vpx_codec_alg_priv_t *ctx, int ctr_id, | 476 static vpx_codec_err_t ctrl_set_postproc(vpx_codec_alg_priv_t *ctx, |
| 620 va_list args) { | 477 int ctr_id, va_list args) { |
| 621 #if CONFIG_VP9_POSTPROC | 478 #if CONFIG_VP9_POSTPROC |
| 622 vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *); | 479 vp8_postproc_cfg_t *data = va_arg(args, vp8_postproc_cfg_t *); |
| 623 | 480 |
| 624 if (data) { | 481 if (data) { |
| 625 ctx->postproc_cfg_set = 1; | 482 ctx->postproc_cfg_set = 1; |
| 626 ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data); | 483 ctx->postproc_cfg = *((vp8_postproc_cfg_t *)data); |
| 627 return VPX_CODEC_OK; | 484 return VPX_CODEC_OK; |
| 628 } else { | 485 } else { |
| 629 return VPX_CODEC_INVALID_PARAM; | 486 return VPX_CODEC_INVALID_PARAM; |
| 630 } | 487 } |
| 631 #else | 488 #else |
| 632 return VPX_CODEC_INCAPABLE; | 489 return VPX_CODEC_INCAPABLE; |
| 633 #endif | 490 #endif |
| 634 } | 491 } |
| 635 | 492 |
| 636 static vpx_codec_err_t set_dbg_options(vpx_codec_alg_priv_t *ctx, int ctrl_id, | 493 static vpx_codec_err_t ctrl_set_dbg_options(vpx_codec_alg_priv_t *ctx, |
| 637 va_list args) { | 494 int ctrl_id, va_list args) { |
| 638 #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC | 495 #if CONFIG_POSTPROC_VISUALIZER && CONFIG_POSTPROC |
| 639 int data = va_arg(args, int); | 496 int data = va_arg(args, int); |
| 640 | 497 |
| 641 #define MAP(id, var) case id: var = data; break; | 498 #define MAP(id, var) case id: var = data; break; |
| 642 | 499 |
| 643 switch (ctrl_id) { | 500 switch (ctrl_id) { |
| 644 MAP(VP8_SET_DBG_COLOR_REF_FRAME, ctx->dbg_color_ref_frame_flag); | 501 MAP(VP8_SET_DBG_COLOR_REF_FRAME, ctx->dbg_color_ref_frame_flag); |
| 645 MAP(VP8_SET_DBG_COLOR_MB_MODES, ctx->dbg_color_mb_modes_flag); | 502 MAP(VP8_SET_DBG_COLOR_MB_MODES, ctx->dbg_color_mb_modes_flag); |
| 646 MAP(VP8_SET_DBG_COLOR_B_MODES, ctx->dbg_color_b_modes_flag); | 503 MAP(VP8_SET_DBG_COLOR_B_MODES, ctx->dbg_color_b_modes_flag); |
| 647 MAP(VP8_SET_DBG_DISPLAY_MV, ctx->dbg_display_mv_flag); | 504 MAP(VP8_SET_DBG_DISPLAY_MV, ctx->dbg_display_mv_flag); |
| 648 } | 505 } |
| 649 | 506 |
| 650 return VPX_CODEC_OK; | 507 return VPX_CODEC_OK; |
| 651 #else | 508 #else |
| 652 return VPX_CODEC_INCAPABLE; | 509 return VPX_CODEC_INCAPABLE; |
| 653 #endif | 510 #endif |
| 654 } | 511 } |
| 655 | 512 |
| 656 static vpx_codec_err_t get_last_ref_updates(vpx_codec_alg_priv_t *ctx, | 513 static vpx_codec_err_t ctrl_get_last_ref_updates(vpx_codec_alg_priv_t *ctx, |
| 657 int ctrl_id, va_list args) { | 514 int ctrl_id, va_list args) { |
| 658 int *update_info = va_arg(args, int *); | 515 int *const update_info = va_arg(args, int *); |
| 659 VP9D_COMP *pbi = (VP9D_COMP*)ctx->pbi; | |
| 660 | 516 |
| 661 if (update_info) { | 517 if (update_info) { |
| 662 *update_info = pbi->refresh_frame_flags; | 518 if (ctx->pbi) |
| 663 | 519 *update_info = ctx->pbi->refresh_frame_flags; |
| 520 else |
| 521 return VPX_CODEC_ERROR; |
| 664 return VPX_CODEC_OK; | 522 return VPX_CODEC_OK; |
| 665 } else { | 523 } else { |
| 666 return VPX_CODEC_INVALID_PARAM; | 524 return VPX_CODEC_INVALID_PARAM; |
| 667 } | 525 } |
| 668 } | 526 } |
| 669 | 527 |
| 670 | 528 |
| 671 static vpx_codec_err_t get_frame_corrupted(vpx_codec_alg_priv_t *ctx, | 529 static vpx_codec_err_t ctrl_get_frame_corrupted(vpx_codec_alg_priv_t *ctx, |
| 672 int ctrl_id, va_list args) { | 530 int ctrl_id, va_list args) { |
| 673 int *corrupted = va_arg(args, int *); | 531 int *corrupted = va_arg(args, int *); |
| 674 | 532 |
| 675 if (corrupted) { | 533 if (corrupted) { |
| 676 VP9D_COMP *pbi = (VP9D_COMP*)ctx->pbi; | 534 if (ctx->pbi) |
| 677 if (pbi) | 535 *corrupted = ctx->pbi->common.frame_to_show->corrupted; |
| 678 *corrupted = pbi->common.frame_to_show->corrupted; | |
| 679 else | 536 else |
| 680 return VPX_CODEC_ERROR; | 537 return VPX_CODEC_ERROR; |
| 681 return VPX_CODEC_OK; | 538 return VPX_CODEC_OK; |
| 682 } else { | 539 } else { |
| 683 return VPX_CODEC_INVALID_PARAM; | 540 return VPX_CODEC_INVALID_PARAM; |
| 684 } | 541 } |
| 685 } | 542 } |
| 686 | 543 |
| 687 static vpx_codec_err_t get_display_size(vpx_codec_alg_priv_t *ctx, | 544 static vpx_codec_err_t ctrl_get_display_size(vpx_codec_alg_priv_t *ctx, |
| 688 int ctrl_id, va_list args) { | 545 int ctrl_id, va_list args) { |
| 689 int *const display_size = va_arg(args, int *); | 546 int *const display_size = va_arg(args, int *); |
| 690 | 547 |
| 691 if (display_size) { | 548 if (display_size) { |
| 692 const VP9D_COMP *const pbi = (VP9D_COMP*)ctx->pbi; | 549 if (ctx->pbi) { |
| 693 if (pbi) { | 550 const VP9_COMMON *const cm = &ctx->pbi->common; |
| 694 display_size[0] = pbi->common.display_width; | 551 display_size[0] = cm->display_width; |
| 695 display_size[1] = pbi->common.display_height; | 552 display_size[1] = cm->display_height; |
| 696 } else { | 553 } else { |
| 697 return VPX_CODEC_ERROR; | 554 return VPX_CODEC_ERROR; |
| 698 } | 555 } |
| 699 return VPX_CODEC_OK; | 556 return VPX_CODEC_OK; |
| 700 } else { | 557 } else { |
| 701 return VPX_CODEC_INVALID_PARAM; | 558 return VPX_CODEC_INVALID_PARAM; |
| 702 } | 559 } |
| 703 } | 560 } |
| 704 | 561 |
| 705 static vpx_codec_err_t set_invert_tile_order(vpx_codec_alg_priv_t *ctx, | 562 static vpx_codec_err_t ctrl_set_invert_tile_order(vpx_codec_alg_priv_t *ctx, |
| 706 int ctr_id, | 563 int ctr_id, va_list args) { |
| 707 va_list args) { | |
| 708 ctx->invert_tile_order = va_arg(args, int); | 564 ctx->invert_tile_order = va_arg(args, int); |
| 709 return VPX_CODEC_OK; | 565 return VPX_CODEC_OK; |
| 710 } | 566 } |
| 711 | 567 |
| 712 static vpx_codec_ctrl_fn_map_t ctf_maps[] = { | 568 static vpx_codec_ctrl_fn_map_t decoder_ctrl_maps[] = { |
| 713 {VP8_SET_REFERENCE, set_reference}, | 569 {VP8_COPY_REFERENCE, ctrl_copy_reference}, |
| 714 {VP8_COPY_REFERENCE, copy_reference}, | 570 |
| 715 {VP8_SET_POSTPROC, set_postproc}, | 571 // Setters |
| 716 {VP8_SET_DBG_COLOR_REF_FRAME, set_dbg_options}, | 572 {VP8_SET_REFERENCE, ctrl_set_reference}, |
| 717 {VP8_SET_DBG_COLOR_MB_MODES, set_dbg_options}, | 573 {VP8_SET_POSTPROC, ctrl_set_postproc}, |
| 718 {VP8_SET_DBG_COLOR_B_MODES, set_dbg_options}, | 574 {VP8_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options}, |
| 719 {VP8_SET_DBG_DISPLAY_MV, set_dbg_options}, | 575 {VP8_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options}, |
| 720 {VP8D_GET_LAST_REF_UPDATES, get_last_ref_updates}, | 576 {VP8_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options}, |
| 721 {VP8D_GET_FRAME_CORRUPTED, get_frame_corrupted}, | 577 {VP8_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options}, |
| 722 {VP9_GET_REFERENCE, get_reference}, | 578 {VP9_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order}, |
| 723 {VP9D_GET_DISPLAY_SIZE, get_display_size}, | 579 |
| 724 {VP9_INVERT_TILE_DECODE_ORDER, set_invert_tile_order}, | 580 // Getters |
| 581 {VP8D_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates}, |
| 582 {VP8D_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted}, |
| 583 {VP9_GET_REFERENCE, ctrl_get_reference}, |
| 584 {VP9D_GET_DISPLAY_SIZE, ctrl_get_display_size}, |
| 585 |
| 725 { -1, NULL}, | 586 { -1, NULL}, |
| 726 }; | 587 }; |
| 727 | 588 |
| 728 | |
| 729 #ifndef VERSION_STRING | 589 #ifndef VERSION_STRING |
| 730 #define VERSION_STRING | 590 #define VERSION_STRING |
| 731 #endif | 591 #endif |
| 732 CODEC_INTERFACE(vpx_codec_vp9_dx) = { | 592 CODEC_INTERFACE(vpx_codec_vp9_dx) = { |
| 733 "WebM Project VP9 Decoder" VERSION_STRING, | 593 "WebM Project VP9 Decoder" VERSION_STRING, |
| 734 VPX_CODEC_INTERNAL_ABI_VERSION, | 594 VPX_CODEC_INTERNAL_ABI_VERSION, |
| 735 VPX_CODEC_CAP_DECODER | VP9_CAP_POSTPROC | | 595 VPX_CODEC_CAP_DECODER | VP9_CAP_POSTPROC | |
| 736 VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER, | 596 VPX_CODEC_CAP_EXTERNAL_FRAME_BUFFER, // vpx_codec_caps_t |
| 737 /* vpx_codec_caps_t caps; */ | 597 decoder_init, // vpx_codec_init_fn_t |
| 738 vp9_init, /* vpx_codec_init_fn_t init; */ | 598 decoder_destroy, // vpx_codec_destroy_fn_t |
| 739 vp9_destroy, /* vpx_codec_destroy_fn_t destroy; */ | 599 decoder_ctrl_maps, // vpx_codec_ctrl_fn_map_t |
| 740 ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */ | 600 NOT_IMPLEMENTED, // vpx_codec_get_mmap_fn_t |
| 741 vp9_xma_get_mmap, /* vpx_codec_get_mmap_fn_t get_mmap; */ | 601 NOT_IMPLEMENTED, // vpx_codec_set_mmap_fn_t |
| 742 vp9_xma_set_mmap, /* vpx_codec_set_mmap_fn_t set_mmap; */ | |
| 743 { // NOLINT | 602 { // NOLINT |
| 744 vp9_peek_si, /* vpx_codec_peek_si_fn_t peek_si; */ | 603 decoder_peek_si, // vpx_codec_peek_si_fn_t |
| 745 vp9_get_si, /* vpx_codec_get_si_fn_t get_si; */ | 604 decoder_get_si, // vpx_codec_get_si_fn_t |
| 746 vp9_decode, /* vpx_codec_decode_fn_t decode; */ | 605 decoder_decode, // vpx_codec_decode_fn_t |
| 747 vp9_get_frame, /* vpx_codec_frame_get_fn_t frame_get; */ | 606 decoder_get_frame, // vpx_codec_frame_get_fn_t |
| 748 vp9_set_fb_fn, /* vpx_codec_set_fb_fn_t set_fb_fn; */ | 607 decoder_set_fb_fn, // vpx_codec_set_fb_fn_t |
| 749 }, | 608 }, |
| 750 { // NOLINT | 609 { // NOLINT |
| 751 /* encoder functions */ | |
| 752 NOT_IMPLEMENTED, | 610 NOT_IMPLEMENTED, |
| 753 NOT_IMPLEMENTED, | 611 NOT_IMPLEMENTED, |
| 754 NOT_IMPLEMENTED, | 612 NOT_IMPLEMENTED, |
| 755 NOT_IMPLEMENTED, | 613 NOT_IMPLEMENTED, |
| 756 NOT_IMPLEMENTED, | 614 NOT_IMPLEMENTED, |
| 757 NOT_IMPLEMENTED | 615 NOT_IMPLEMENTED |
| 758 } | 616 } |
| 759 }; | 617 }; |
| OLD | NEW |