| 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "vp9/vp9_iface_common.h" | 25 #include "vp9/vp9_iface_common.h" |
| 26 | 26 |
| 27 #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) |
| 28 | 28 |
| 29 typedef vpx_codec_stream_info_t vp9_stream_info_t; | 29 typedef vpx_codec_stream_info_t vp9_stream_info_t; |
| 30 | 30 |
| 31 struct vpx_codec_alg_priv { | 31 struct vpx_codec_alg_priv { |
| 32 vpx_codec_priv_t base; | 32 vpx_codec_priv_t base; |
| 33 vpx_codec_dec_cfg_t cfg; | 33 vpx_codec_dec_cfg_t cfg; |
| 34 vp9_stream_info_t si; | 34 vp9_stream_info_t si; |
| 35 struct VP9Decoder *pbi; |
| 35 int postproc_cfg_set; | 36 int postproc_cfg_set; |
| 36 vp8_postproc_cfg_t postproc_cfg; | 37 vp8_postproc_cfg_t postproc_cfg; |
| 37 vpx_decrypt_cb decrypt_cb; | 38 vpx_decrypt_cb decrypt_cb; |
| 38 void *decrypt_state; | 39 void *decrypt_state; |
| 39 vpx_image_t img; | 40 vpx_image_t img; |
| 41 int img_avail; |
| 40 int invert_tile_order; | 42 int invert_tile_order; |
| 41 int frame_parallel_decode; // frame-based threading. | 43 int frame_parallel_decode; // frame-based threading. |
| 42 int last_show_frame; // Index of last output frame. | |
| 43 | |
| 44 VP9Worker *frame_workers; | |
| 45 int num_frame_workers; | |
| 46 int next_submit_thread_id; | |
| 47 int next_output_thread_id; | |
| 48 | 44 |
| 49 // External frame buffer info to save for VP9 common. | 45 // External frame buffer info to save for VP9 common. |
| 50 void *ext_priv; // Private data associated with the external frame buffers. | 46 void *ext_priv; // Private data associated with the external frame buffers. |
| 51 vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb; | 47 vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb; |
| 52 vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb; | 48 vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb; |
| 53 }; | 49 }; |
| 54 | 50 |
| 55 static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx, | 51 static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx, |
| 56 vpx_codec_priv_enc_mr_cfg_t *data) { | 52 vpx_codec_priv_enc_mr_cfg_t *data) { |
| 57 // This function only allocates space for the vpx_codec_alg_priv_t | 53 // This function only allocates space for the vpx_codec_alg_priv_t |
| (...skipping 24 matching lines...) Expand all Loading... |
| 82 // Update the reference to the config structure to an internal copy. | 78 // Update the reference to the config structure to an internal copy. |
| 83 ctx->priv->alg_priv->cfg = *ctx->config.dec; | 79 ctx->priv->alg_priv->cfg = *ctx->config.dec; |
| 84 ctx->config.dec = &ctx->priv->alg_priv->cfg; | 80 ctx->config.dec = &ctx->priv->alg_priv->cfg; |
| 85 } | 81 } |
| 86 } | 82 } |
| 87 | 83 |
| 88 return VPX_CODEC_OK; | 84 return VPX_CODEC_OK; |
| 89 } | 85 } |
| 90 | 86 |
| 91 static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) { | 87 static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) { |
| 92 if (ctx->frame_workers != NULL) { | 88 if (ctx->pbi) { |
| 93 int i; | 89 vp9_decoder_remove(ctx->pbi); |
| 94 for (i = 0; i < ctx->num_frame_workers; ++i) { | 90 ctx->pbi = NULL; |
| 95 VP9Worker *const worker = &ctx->frame_workers[i]; | |
| 96 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | |
| 97 vp9_decoder_remove(worker_data->pbi); | |
| 98 vpx_free(worker_data); | |
| 99 } | |
| 100 } | 91 } |
| 101 | 92 |
| 102 vpx_free(ctx->frame_workers); | |
| 103 vpx_free(ctx); | 93 vpx_free(ctx); |
| 104 | 94 |
| 105 return VPX_CODEC_OK; | 95 return VPX_CODEC_OK; |
| 106 } | 96 } |
| 107 | 97 |
| 108 static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data, | 98 static vpx_codec_err_t decoder_peek_si_internal(const uint8_t *data, |
| 109 unsigned int data_sz, | 99 unsigned int data_sz, |
| 110 vpx_codec_stream_info_t *si, | 100 vpx_codec_stream_info_t *si, |
| 111 vpx_decrypt_cb decrypt_cb, | 101 vpx_decrypt_cb decrypt_cb, |
| 112 void *decrypt_state) { | 102 void *decrypt_state) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 vpx_codec_stream_info_t *si) { | 181 vpx_codec_stream_info_t *si) { |
| 192 const size_t sz = (si->sz >= sizeof(vp9_stream_info_t)) | 182 const size_t sz = (si->sz >= sizeof(vp9_stream_info_t)) |
| 193 ? sizeof(vp9_stream_info_t) | 183 ? sizeof(vp9_stream_info_t) |
| 194 : sizeof(vpx_codec_stream_info_t); | 184 : sizeof(vpx_codec_stream_info_t); |
| 195 memcpy(si, &ctx->si, sz); | 185 memcpy(si, &ctx->si, sz); |
| 196 si->sz = (unsigned int)sz; | 186 si->sz = (unsigned int)sz; |
| 197 | 187 |
| 198 return VPX_CODEC_OK; | 188 return VPX_CODEC_OK; |
| 199 } | 189 } |
| 200 | 190 |
| 201 static void set_error_detail(vpx_codec_alg_priv_t *ctx, | |
| 202 const char *const error) { | |
| 203 ctx->base.err_detail = error; | |
| 204 } | |
| 205 | |
| 206 static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx, | 191 static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx, |
| 207 const struct vpx_internal_error_info *error) { | 192 const struct vpx_internal_error_info *error) { |
| 208 if (error->error_code) | 193 if (error->error_code) |
| 209 set_error_detail(ctx, error->has_detail ? error->detail : NULL); | 194 ctx->base.err_detail = error->has_detail ? error->detail : NULL; |
| 210 | 195 |
| 211 return error->error_code; | 196 return error->error_code; |
| 212 } | 197 } |
| 213 | 198 |
| 214 static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) { | 199 static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) { |
| 215 int i; | 200 VP9_COMMON *const cm = &ctx->pbi->common; |
| 216 | 201 |
| 217 for (i = 0; i < ctx->num_frame_workers; ++i) { | 202 cm->new_fb_idx = -1; |
| 218 VP9Worker *const worker = &ctx->frame_workers[i]; | |
| 219 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | |
| 220 VP9_COMMON *const cm = &worker_data->pbi->common; | |
| 221 | 203 |
| 222 cm->new_fb_idx = -1; | 204 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { |
| 223 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { | 205 cm->get_fb_cb = ctx->get_ext_fb_cb; |
| 224 cm->get_fb_cb = ctx->get_ext_fb_cb; | 206 cm->release_fb_cb = ctx->release_ext_fb_cb; |
| 225 cm->release_fb_cb = ctx->release_ext_fb_cb; | 207 cm->cb_priv = ctx->ext_priv; |
| 226 cm->cb_priv = ctx->ext_priv; | 208 } else { |
| 227 } else { | 209 cm->get_fb_cb = vp9_get_frame_buffer; |
| 228 cm->get_fb_cb = vp9_get_frame_buffer; | 210 cm->release_fb_cb = vp9_release_frame_buffer; |
| 229 cm->release_fb_cb = vp9_release_frame_buffer; | |
| 230 | 211 |
| 231 if (vp9_alloc_internal_frame_buffers(&cm->int_frame_buffers)) | 212 if (vp9_alloc_internal_frame_buffers(&cm->int_frame_buffers)) |
| 232 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 213 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 233 "Failed to initialize internal frame buffers"); | 214 "Failed to initialize internal frame buffers"); |
| 234 | 215 |
| 235 cm->cb_priv = &cm->int_frame_buffers; | 216 cm->cb_priv = &cm->int_frame_buffers; |
| 236 } | |
| 237 } | 217 } |
| 238 } | 218 } |
| 239 | 219 |
| 240 static void set_default_ppflags(vp8_postproc_cfg_t *cfg) { | 220 static void set_default_ppflags(vp8_postproc_cfg_t *cfg) { |
| 241 cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; | 221 cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; |
| 242 cfg->deblocking_level = 4; | 222 cfg->deblocking_level = 4; |
| 243 cfg->noise_level = 0; | 223 cfg->noise_level = 0; |
| 244 } | 224 } |
| 245 | 225 |
| 246 static void set_ppflags(const vpx_codec_alg_priv_t *ctx, | 226 static void set_ppflags(const vpx_codec_alg_priv_t *ctx, |
| 247 vp9_ppflags_t *flags) { | 227 vp9_ppflags_t *flags) { |
| 248 flags->post_proc_flag = | 228 flags->post_proc_flag = |
| 249 ctx->postproc_cfg.post_proc_flag; | 229 ctx->postproc_cfg.post_proc_flag; |
| 250 | 230 |
| 251 flags->deblocking_level = ctx->postproc_cfg.deblocking_level; | 231 flags->deblocking_level = ctx->postproc_cfg.deblocking_level; |
| 252 flags->noise_level = ctx->postproc_cfg.noise_level; | 232 flags->noise_level = ctx->postproc_cfg.noise_level; |
| 253 } | 233 } |
| 254 | 234 |
| 255 static int frame_worker_hook(void *arg1, void *arg2) { | 235 static void init_decoder(vpx_codec_alg_priv_t *ctx) { |
| 256 FrameWorkerData *const worker_data = (FrameWorkerData *)arg1; | 236 ctx->pbi = vp9_decoder_create(); |
| 257 const uint8_t *data = worker_data->data; | 237 if (ctx->pbi == NULL) |
| 258 (void)arg2; | 238 return; |
| 259 worker_data->result = vp9_receive_compressed_data(worker_data->pbi, | |
| 260 worker_data->data_size, | |
| 261 &data); | |
| 262 worker_data->data_end = data; | |
| 263 return !worker_data->result; | |
| 264 } | |
| 265 | 239 |
| 266 static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) { | 240 ctx->pbi->max_threads = ctx->cfg.threads; |
| 267 int i; | 241 ctx->pbi->inv_tile_order = ctx->invert_tile_order; |
| 268 | 242 ctx->pbi->frame_parallel_decode = ctx->frame_parallel_decode; |
| 269 ctx->last_show_frame = -1; | |
| 270 ctx->next_submit_thread_id = 0; | |
| 271 ctx->next_output_thread_id = 0; | |
| 272 ctx->num_frame_workers = | |
| 273 (ctx->frame_parallel_decode == 1) ? ctx->cfg.threads: 1; | |
| 274 | |
| 275 ctx->frame_workers = (VP9Worker *) | |
| 276 vpx_malloc(ctx->num_frame_workers * sizeof(*ctx->frame_workers)); | |
| 277 if (ctx->frame_workers == NULL) { | |
| 278 set_error_detail(ctx, "Failed to allocate frame_workers"); | |
| 279 return VPX_CODEC_MEM_ERROR; | |
| 280 } | |
| 281 | |
| 282 for (i = 0; i < ctx->num_frame_workers; ++i) { | |
| 283 VP9Worker *const worker = &ctx->frame_workers[i]; | |
| 284 FrameWorkerData *worker_data = NULL; | |
| 285 vp9_worker_init(worker); | |
| 286 worker->data1 = vpx_memalign(32, sizeof(FrameWorkerData)); | |
| 287 if (worker->data1 == NULL) { | |
| 288 set_error_detail(ctx, "Failed to allocate worker_data"); | |
| 289 return VPX_CODEC_MEM_ERROR; | |
| 290 } | |
| 291 worker_data = (FrameWorkerData *)worker->data1; | |
| 292 worker_data->pbi = vp9_decoder_create(); | |
| 293 if (worker_data->pbi == NULL) { | |
| 294 set_error_detail(ctx, "Failed to allocate worker_data"); | |
| 295 return VPX_CODEC_MEM_ERROR; | |
| 296 } | |
| 297 | |
| 298 // If decoding in serial mode, FrameWorker thread could create tile worker | |
| 299 // thread or loopfilter thread. | |
| 300 worker_data->pbi->max_threads = | |
| 301 (ctx->frame_parallel_decode == 0) ? ctx->cfg.threads : 0; | |
| 302 | |
| 303 worker_data->pbi->inv_tile_order = ctx->invert_tile_order; | |
| 304 worker_data->pbi->frame_parallel_decode = ctx->frame_parallel_decode; | |
| 305 worker->hook = (VP9WorkerHook)frame_worker_hook; | |
| 306 } | |
| 307 | 243 |
| 308 // If postprocessing was enabled by the application and a | 244 // If postprocessing was enabled by the application and a |
| 309 // configuration has not been provided, default it. | 245 // configuration has not been provided, default it. |
| 310 if (!ctx->postproc_cfg_set && | 246 if (!ctx->postproc_cfg_set && |
| 311 (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) | 247 (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) |
| 312 set_default_ppflags(&ctx->postproc_cfg); | 248 set_default_ppflags(&ctx->postproc_cfg); |
| 313 | 249 |
| 314 init_buffer_callbacks(ctx); | 250 init_buffer_callbacks(ctx); |
| 315 | |
| 316 return VPX_CODEC_OK; | |
| 317 } | 251 } |
| 318 | 252 |
| 319 static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, | 253 static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, |
| 320 const uint8_t **data, unsigned int data_sz, | 254 const uint8_t **data, unsigned int data_sz, |
| 321 void *user_priv, int64_t deadline) { | 255 void *user_priv, int64_t deadline) { |
| 322 vp9_ppflags_t flags = {0}; | 256 YV12_BUFFER_CONFIG sd; |
| 257 vp9_ppflags_t flags = {0, 0, 0}; |
| 258 VP9_COMMON *cm = NULL; |
| 259 |
| 323 (void)deadline; | 260 (void)deadline; |
| 324 | 261 |
| 262 vp9_zero(sd); |
| 263 ctx->img_avail = 0; |
| 264 |
| 325 // Determine the stream parameters. Note that we rely on peek_si to | 265 // Determine the stream parameters. Note that we rely on peek_si to |
| 326 // validate that we have a buffer that does not wrap around the top | 266 // validate that we have a buffer that does not wrap around the top |
| 327 // of the heap. | 267 // of the heap. |
| 328 if (!ctx->si.h) { | 268 if (!ctx->si.h) { |
| 329 const vpx_codec_err_t res = | 269 const vpx_codec_err_t res = |
| 330 decoder_peek_si_internal(*data, data_sz, &ctx->si, ctx->decrypt_cb, | 270 decoder_peek_si_internal(*data, data_sz, &ctx->si, ctx->decrypt_cb, |
| 331 ctx->decrypt_state); | 271 ctx->decrypt_state); |
| 332 if (res != VPX_CODEC_OK) | 272 if (res != VPX_CODEC_OK) |
| 333 return res; | 273 return res; |
| 334 | 274 |
| 335 if (!ctx->si.is_kf) | 275 if (!ctx->si.is_kf) |
| 336 return VPX_CODEC_ERROR; | 276 return VPX_CODEC_ERROR; |
| 337 } | 277 } |
| 338 | 278 |
| 339 // Initialize the decoder workers on the first frame | 279 // Initialize the decoder instance on the first frame |
| 340 if (ctx->frame_workers == NULL) { | 280 if (ctx->pbi == NULL) { |
| 341 const vpx_codec_err_t res = init_decoder(ctx); | 281 init_decoder(ctx); |
| 342 if (res != VPX_CODEC_OK) | 282 if (ctx->pbi == NULL) |
| 343 return res; | 283 return VPX_CODEC_ERROR; |
| 344 } | 284 } |
| 345 | 285 |
| 346 if (!ctx->frame_parallel_decode) { | 286 // Set these even if already initialized. The caller may have changed the |
| 347 VP9Worker *const worker = ctx->frame_workers; | 287 // decrypt config between frames. |
| 348 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | 288 ctx->pbi->decrypt_cb = ctx->decrypt_cb; |
| 349 worker_data->data = *data; | 289 ctx->pbi->decrypt_state = ctx->decrypt_state; |
| 350 worker_data->data_size = data_sz; | |
| 351 | 290 |
| 352 // Set these even if already initialized. The caller may have changed the | 291 cm = &ctx->pbi->common; |
| 353 // decrypt config between frames. | |
| 354 worker_data->pbi->decrypt_cb = ctx->decrypt_cb; | |
| 355 worker_data->pbi->decrypt_state = ctx->decrypt_state; | |
| 356 | 292 |
| 357 vp9_worker_execute(worker); | 293 if (vp9_receive_compressed_data(ctx->pbi, data_sz, data)) |
| 358 if (worker->had_error) | 294 return update_error_state(ctx, &cm->error); |
| 359 return update_error_state(ctx, &worker_data->pbi->common.error); | |
| 360 | |
| 361 // Update data pointer after decode. | |
| 362 *data = worker_data->data_end; | |
| 363 } else { | |
| 364 // TODO(hkuang): Implement frame parallel decode. | |
| 365 return VPX_CODEC_INCAPABLE; | |
| 366 } | |
| 367 | 295 |
| 368 if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) | 296 if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) |
| 369 set_ppflags(ctx, &flags); | 297 set_ppflags(ctx, &flags); |
| 370 | 298 |
| 299 if (vp9_get_raw_frame(ctx->pbi, &sd, &flags)) |
| 300 return update_error_state(ctx, &cm->error); |
| 301 |
| 302 yuvconfig2image(&ctx->img, &sd, user_priv); |
| 303 ctx->img.fb_priv = cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; |
| 304 ctx->img_avail = 1; |
| 305 |
| 371 return VPX_CODEC_OK; | 306 return VPX_CODEC_OK; |
| 372 } | 307 } |
| 373 | 308 |
| 374 static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb, | 309 static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb, |
| 375 void *decrypt_state, | 310 void *decrypt_state, |
| 376 const uint8_t *data) { | 311 const uint8_t *data) { |
| 377 if (decrypt_cb) { | 312 if (decrypt_cb) { |
| 378 uint8_t marker; | 313 uint8_t marker; |
| 379 decrypt_cb(decrypt_state, data, &marker, 1); | 314 decrypt_cb(decrypt_state, data, &marker, 1); |
| 380 return marker; | 315 return marker; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 // in the superframe. | 385 // in the superframe. |
| 451 if (frame_count > 0) { | 386 if (frame_count > 0) { |
| 452 int i; | 387 int i; |
| 453 | 388 |
| 454 for (i = 0; i < frame_count; ++i) { | 389 for (i = 0; i < frame_count; ++i) { |
| 455 const uint8_t *data_start_copy = data_start; | 390 const uint8_t *data_start_copy = data_start; |
| 456 const uint32_t frame_size = frame_sizes[i]; | 391 const uint32_t frame_size = frame_sizes[i]; |
| 457 vpx_codec_err_t res; | 392 vpx_codec_err_t res; |
| 458 if (data_start < data | 393 if (data_start < data |
| 459 || frame_size > (uint32_t) (data_end - data_start)) { | 394 || frame_size > (uint32_t) (data_end - data_start)) { |
| 460 set_error_detail(ctx, "Invalid frame size in index"); | 395 ctx->base.err_detail = "Invalid frame size in index"; |
| 461 return VPX_CODEC_CORRUPT_FRAME; | 396 return VPX_CODEC_CORRUPT_FRAME; |
| 462 } | 397 } |
| 463 | 398 |
| 464 res = decode_one(ctx, &data_start_copy, frame_size, user_priv, | 399 res = decode_one(ctx, &data_start_copy, frame_size, user_priv, |
| 465 deadline); | 400 deadline); |
| 466 if (res != VPX_CODEC_OK) | 401 if (res != VPX_CODEC_OK) |
| 467 return res; | 402 return res; |
| 468 | 403 |
| 469 data_start += frame_size; | 404 data_start += frame_size; |
| 470 } | 405 } |
| 471 } else { | 406 } else { |
| 472 res = decode_one(ctx, &data_start, data_sz, user_priv, deadline); | 407 res = decode_one(ctx, &data_start, data_sz, user_priv, deadline); |
| 473 if (res != VPX_CODEC_OK) | 408 if (res != VPX_CODEC_OK) |
| 474 return res; | 409 return res; |
| 475 | 410 |
| 476 // Extra data detected after the frame. | 411 // Extra data detected after the frame. |
| 477 if (data_start < data_end - 1) { | 412 if (data_start < data_end - 1) { |
| 478 set_error_detail(ctx, "Fail to decode frame in parallel mode"); | 413 ctx->base.err_detail = "Fail to decode frame in parallel mode"; |
| 479 return VPX_CODEC_INCAPABLE; | 414 return VPX_CODEC_INCAPABLE; |
| 480 } | 415 } |
| 481 } | 416 } |
| 482 } else { | 417 } else { |
| 483 // Decode in serial mode. | 418 // Decode in serial mode. |
| 484 if (frame_count > 0) { | 419 if (frame_count > 0) { |
| 485 int i; | 420 int i; |
| 486 | 421 |
| 487 for (i = 0; i < frame_count; ++i) { | 422 for (i = 0; i < frame_count; ++i) { |
| 488 const uint8_t *data_start_copy = data_start; | 423 const uint8_t *data_start_copy = data_start; |
| 489 const uint32_t frame_size = frame_sizes[i]; | 424 const uint32_t frame_size = frame_sizes[i]; |
| 490 vpx_codec_err_t res; | 425 vpx_codec_err_t res; |
| 491 if (data_start < data | 426 if (data_start < data |
| 492 || frame_size > (uint32_t) (data_end - data_start)) { | 427 || frame_size > (uint32_t) (data_end - data_start)) { |
| 493 set_error_detail(ctx, "Invalid frame size in index"); | 428 ctx->base.err_detail = "Invalid frame size in index"; |
| 494 return VPX_CODEC_CORRUPT_FRAME; | 429 return VPX_CODEC_CORRUPT_FRAME; |
| 495 } | 430 } |
| 496 | 431 |
| 497 res = decode_one(ctx, &data_start_copy, frame_size, user_priv, | 432 res = decode_one(ctx, &data_start_copy, frame_size, user_priv, |
| 498 deadline); | 433 deadline); |
| 499 if (res != VPX_CODEC_OK) | 434 if (res != VPX_CODEC_OK) |
| 500 return res; | 435 return res; |
| 501 | 436 |
| 502 data_start += frame_size; | 437 data_start += frame_size; |
| 503 } | 438 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 521 } | 456 } |
| 522 } | 457 } |
| 523 | 458 |
| 524 return VPX_CODEC_OK; | 459 return VPX_CODEC_OK; |
| 525 } | 460 } |
| 526 | 461 |
| 527 static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx, | 462 static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx, |
| 528 vpx_codec_iter_t *iter) { | 463 vpx_codec_iter_t *iter) { |
| 529 vpx_image_t *img = NULL; | 464 vpx_image_t *img = NULL; |
| 530 | 465 |
| 531 // iter acts as a flip flop, so an image is only returned on the first | 466 if (ctx->img_avail) { |
| 532 // call to get_frame. | 467 // iter acts as a flip flop, so an image is only returned on the first |
| 533 if (*iter == NULL && ctx->frame_workers != NULL) { | 468 // call to get_frame. |
| 534 YV12_BUFFER_CONFIG sd; | 469 if (!(*iter)) { |
| 535 vp9_ppflags_t flags = {0, 0, 0}; | |
| 536 | |
| 537 VP9Worker *const worker = &ctx->frame_workers[ctx->next_output_thread_id]; | |
| 538 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | |
| 539 if (vp9_get_raw_frame(worker_data->pbi, &sd, &flags) == 0) { | |
| 540 VP9_COMMON *const cm = &worker_data->pbi->common; | |
| 541 yuvconfig2image(&ctx->img, &sd, NULL); | |
| 542 ctx->img.fb_priv = cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; | |
| 543 img = &ctx->img; | 470 img = &ctx->img; |
| 544 *iter = img; | 471 *iter = img; |
| 545 // Decrease reference count of last output frame in frame parallel mode. | |
| 546 if (ctx->frame_parallel_decode && ctx->last_show_frame >= 0) { | |
| 547 --cm->frame_bufs[ctx->last_show_frame].ref_count; | |
| 548 if (cm->frame_bufs[ctx->last_show_frame].ref_count == 0) { | |
| 549 cm->release_fb_cb(cm->cb_priv, | |
| 550 &cm->frame_bufs[ctx->last_show_frame].raw_frame_buffer); | |
| 551 } | |
| 552 } | |
| 553 ctx->last_show_frame = worker_data->pbi->common.new_fb_idx; | |
| 554 } | 472 } |
| 555 } | 473 } |
| 474 ctx->img_avail = 0; |
| 556 | 475 |
| 557 return img; | 476 return img; |
| 558 } | 477 } |
| 559 | 478 |
| 560 static vpx_codec_err_t decoder_set_fb_fn( | 479 static vpx_codec_err_t decoder_set_fb_fn( |
| 561 vpx_codec_alg_priv_t *ctx, | 480 vpx_codec_alg_priv_t *ctx, |
| 562 vpx_get_frame_buffer_cb_fn_t cb_get, | 481 vpx_get_frame_buffer_cb_fn_t cb_get, |
| 563 vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) { | 482 vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) { |
| 564 if (cb_get == NULL || cb_release == NULL) { | 483 if (cb_get == NULL || cb_release == NULL) { |
| 565 return VPX_CODEC_INVALID_PARAM; | 484 return VPX_CODEC_INVALID_PARAM; |
| 566 } else if (ctx->frame_workers == NULL) { | 485 } else if (ctx->pbi == NULL) { |
| 567 // If the decoder has already been initialized, do not accept changes to | 486 // If the decoder has already been initialized, do not accept changes to |
| 568 // the frame buffer functions. | 487 // the frame buffer functions. |
| 569 ctx->get_ext_fb_cb = cb_get; | 488 ctx->get_ext_fb_cb = cb_get; |
| 570 ctx->release_ext_fb_cb = cb_release; | 489 ctx->release_ext_fb_cb = cb_release; |
| 571 ctx->ext_priv = cb_priv; | 490 ctx->ext_priv = cb_priv; |
| 572 return VPX_CODEC_OK; | 491 return VPX_CODEC_OK; |
| 573 } | 492 } |
| 574 | 493 |
| 575 return VPX_CODEC_ERROR; | 494 return VPX_CODEC_ERROR; |
| 576 } | 495 } |
| 577 | 496 |
| 578 static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx, | 497 static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx, |
| 579 va_list args) { | 498 va_list args) { |
| 580 vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *); | 499 vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *); |
| 581 | 500 |
| 582 // Only support this function in serial decode. | |
| 583 if (ctx->frame_parallel_decode) { | |
| 584 set_error_detail(ctx, "Not supported in frame parallel decode"); | |
| 585 return VPX_CODEC_INCAPABLE; | |
| 586 } | |
| 587 | |
| 588 if (data) { | 501 if (data) { |
| 589 vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data; | 502 vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data; |
| 590 YV12_BUFFER_CONFIG sd; | 503 YV12_BUFFER_CONFIG sd; |
| 591 VP9Worker *const worker = ctx->frame_workers; | 504 |
| 592 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | |
| 593 image2yuvconfig(&frame->img, &sd); | 505 image2yuvconfig(&frame->img, &sd); |
| 594 return vp9_set_reference_dec(&worker_data->pbi->common, | 506 return vp9_set_reference_dec(&ctx->pbi->common, |
| 595 (VP9_REFFRAME)frame->frame_type, &sd); | 507 (VP9_REFFRAME)frame->frame_type, &sd); |
| 596 } else { | 508 } else { |
| 597 return VPX_CODEC_INVALID_PARAM; | 509 return VPX_CODEC_INVALID_PARAM; |
| 598 } | 510 } |
| 599 } | 511 } |
| 600 | 512 |
| 601 static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx, | 513 static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx, |
| 602 va_list args) { | 514 va_list args) { |
| 603 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); | 515 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); |
| 604 | 516 |
| 605 // Only support this function in serial decode. | 517 if (data) { |
| 606 if (ctx->frame_parallel_decode) { | 518 vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; |
| 607 set_error_detail(ctx, "Not supported in frame parallel decode"); | 519 YV12_BUFFER_CONFIG sd; |
| 608 return VPX_CODEC_INCAPABLE; | |
| 609 } | |
| 610 | 520 |
| 611 if (data) { | |
| 612 vpx_ref_frame_t *frame = (vpx_ref_frame_t *) data; | |
| 613 YV12_BUFFER_CONFIG sd; | |
| 614 VP9Worker *const worker = ctx->frame_workers; | |
| 615 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | |
| 616 image2yuvconfig(&frame->img, &sd); | 521 image2yuvconfig(&frame->img, &sd); |
| 617 return vp9_copy_reference_dec(worker_data->pbi, | 522 |
| 523 return vp9_copy_reference_dec(ctx->pbi, |
| 618 (VP9_REFFRAME)frame->frame_type, &sd); | 524 (VP9_REFFRAME)frame->frame_type, &sd); |
| 619 } else { | 525 } else { |
| 620 return VPX_CODEC_INVALID_PARAM; | 526 return VPX_CODEC_INVALID_PARAM; |
| 621 } | 527 } |
| 622 } | 528 } |
| 623 | 529 |
| 624 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx, | 530 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx, |
| 625 va_list args) { | 531 va_list args) { |
| 626 vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *); | 532 vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *); |
| 627 | 533 |
| 628 // Only support this function in serial decode. | |
| 629 if (ctx->frame_parallel_decode) { | |
| 630 set_error_detail(ctx, "Not supported in frame parallel decode"); | |
| 631 return VPX_CODEC_INCAPABLE; | |
| 632 } | |
| 633 | |
| 634 if (data) { | 534 if (data) { |
| 635 YV12_BUFFER_CONFIG* fb; | 535 YV12_BUFFER_CONFIG* fb; |
| 636 VP9Worker *const worker = ctx->frame_workers; | 536 |
| 637 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | 537 vp9_get_reference_dec(ctx->pbi, data->idx, &fb); |
| 638 vp9_get_reference_dec(worker_data->pbi, data->idx, &fb); | |
| 639 yuvconfig2image(&data->img, fb, NULL); | 538 yuvconfig2image(&data->img, fb, NULL); |
| 640 return VPX_CODEC_OK; | 539 return VPX_CODEC_OK; |
| 641 } else { | 540 } else { |
| 642 return VPX_CODEC_INVALID_PARAM; | 541 return VPX_CODEC_INVALID_PARAM; |
| 643 } | 542 } |
| 644 } | 543 } |
| 645 | 544 |
| 646 static vpx_codec_err_t ctrl_set_postproc(vpx_codec_alg_priv_t *ctx, | 545 static vpx_codec_err_t ctrl_set_postproc(vpx_codec_alg_priv_t *ctx, |
| 647 va_list args) { | 546 va_list args) { |
| 648 #if CONFIG_VP9_POSTPROC | 547 #if CONFIG_VP9_POSTPROC |
| (...skipping 17 matching lines...) Expand all Loading... |
| 666 va_list args) { | 565 va_list args) { |
| 667 (void)ctx; | 566 (void)ctx; |
| 668 (void)args; | 567 (void)args; |
| 669 return VPX_CODEC_INCAPABLE; | 568 return VPX_CODEC_INCAPABLE; |
| 670 } | 569 } |
| 671 | 570 |
| 672 static vpx_codec_err_t ctrl_get_last_ref_updates(vpx_codec_alg_priv_t *ctx, | 571 static vpx_codec_err_t ctrl_get_last_ref_updates(vpx_codec_alg_priv_t *ctx, |
| 673 va_list args) { | 572 va_list args) { |
| 674 int *const update_info = va_arg(args, int *); | 573 int *const update_info = va_arg(args, int *); |
| 675 | 574 |
| 676 // Only support this function in serial decode. | |
| 677 if (ctx->frame_parallel_decode) { | |
| 678 set_error_detail(ctx, "Not supported in frame parallel decode"); | |
| 679 return VPX_CODEC_INCAPABLE; | |
| 680 } | |
| 681 | |
| 682 if (update_info) { | 575 if (update_info) { |
| 683 if (ctx->frame_workers) { | 576 if (ctx->pbi) |
| 684 VP9Worker *const worker = ctx->frame_workers; | 577 *update_info = ctx->pbi->refresh_frame_flags; |
| 685 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | 578 else |
| 686 *update_info = worker_data->pbi->refresh_frame_flags; | |
| 687 } else { | |
| 688 return VPX_CODEC_ERROR; | 579 return VPX_CODEC_ERROR; |
| 689 } | |
| 690 return VPX_CODEC_OK; | 580 return VPX_CODEC_OK; |
| 691 } else { | 581 } else { |
| 692 return VPX_CODEC_INVALID_PARAM; | 582 return VPX_CODEC_INVALID_PARAM; |
| 693 } | 583 } |
| 694 } | 584 } |
| 695 | 585 |
| 696 | 586 |
| 697 static vpx_codec_err_t ctrl_get_frame_corrupted(vpx_codec_alg_priv_t *ctx, | 587 static vpx_codec_err_t ctrl_get_frame_corrupted(vpx_codec_alg_priv_t *ctx, |
| 698 va_list args) { | 588 va_list args) { |
| 699 int *corrupted = va_arg(args, int *); | 589 int *corrupted = va_arg(args, int *); |
| 700 | 590 |
| 701 // Only support this function in serial decode. | |
| 702 if (ctx->frame_parallel_decode) { | |
| 703 set_error_detail(ctx, "Not supported in frame parallel decode"); | |
| 704 return VPX_CODEC_INCAPABLE; | |
| 705 } | |
| 706 | |
| 707 if (corrupted) { | 591 if (corrupted) { |
| 708 if (ctx->frame_workers) { | 592 if (ctx->pbi) |
| 709 VP9Worker *const worker = ctx->frame_workers; | 593 *corrupted = ctx->pbi->common.frame_to_show->corrupted; |
| 710 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | 594 else |
| 711 *corrupted = worker_data->pbi->common.frame_to_show->corrupted; | |
| 712 } else { | |
| 713 return VPX_CODEC_ERROR; | 595 return VPX_CODEC_ERROR; |
| 714 } | |
| 715 return VPX_CODEC_OK; | 596 return VPX_CODEC_OK; |
| 716 } else { | 597 } else { |
| 717 return VPX_CODEC_INVALID_PARAM; | 598 return VPX_CODEC_INVALID_PARAM; |
| 718 } | 599 } |
| 719 } | 600 } |
| 720 | 601 |
| 721 static vpx_codec_err_t ctrl_get_display_size(vpx_codec_alg_priv_t *ctx, | 602 static vpx_codec_err_t ctrl_get_display_size(vpx_codec_alg_priv_t *ctx, |
| 722 va_list args) { | 603 va_list args) { |
| 723 int *const display_size = va_arg(args, int *); | 604 int *const display_size = va_arg(args, int *); |
| 724 | 605 |
| 725 // Only support this function in serial decode. | |
| 726 if (ctx->frame_parallel_decode) { | |
| 727 set_error_detail(ctx, "Not supported in frame parallel decode"); | |
| 728 return VPX_CODEC_INCAPABLE; | |
| 729 } | |
| 730 | |
| 731 if (display_size) { | 606 if (display_size) { |
| 732 if (ctx->frame_workers) { | 607 if (ctx->pbi) { |
| 733 VP9Worker *const worker = ctx->frame_workers; | 608 const VP9_COMMON *const cm = &ctx->pbi->common; |
| 734 FrameWorkerData *const worker_data = (FrameWorkerData *)worker->data1; | |
| 735 const VP9_COMMON *const cm = &worker_data->pbi->common; | |
| 736 display_size[0] = cm->display_width; | 609 display_size[0] = cm->display_width; |
| 737 display_size[1] = cm->display_height; | 610 display_size[1] = cm->display_height; |
| 738 } else { | 611 } else { |
| 739 return VPX_CODEC_ERROR; | 612 return VPX_CODEC_ERROR; |
| 740 } | 613 } |
| 741 return VPX_CODEC_OK; | 614 return VPX_CODEC_OK; |
| 742 } else { | 615 } else { |
| 743 return VPX_CODEC_INVALID_PARAM; | 616 return VPX_CODEC_INVALID_PARAM; |
| 744 } | 617 } |
| 745 } | 618 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 { // NOLINT | 676 { // NOLINT |
| 804 NOT_IMPLEMENTED, // vpx_codec_enc_cfg_map_t | 677 NOT_IMPLEMENTED, // vpx_codec_enc_cfg_map_t |
| 805 NOT_IMPLEMENTED, // vpx_codec_encode_fn_t | 678 NOT_IMPLEMENTED, // vpx_codec_encode_fn_t |
| 806 NOT_IMPLEMENTED, // vpx_codec_get_cx_data_fn_t | 679 NOT_IMPLEMENTED, // vpx_codec_get_cx_data_fn_t |
| 807 NOT_IMPLEMENTED, // vpx_codec_enc_config_set_fn_t | 680 NOT_IMPLEMENTED, // vpx_codec_enc_config_set_fn_t |
| 808 NOT_IMPLEMENTED, // vpx_codec_get_global_headers_fn_t | 681 NOT_IMPLEMENTED, // vpx_codec_get_global_headers_fn_t |
| 809 NOT_IMPLEMENTED, // vpx_codec_get_preview_frame_fn_t | 682 NOT_IMPLEMENTED, // vpx_codec_get_preview_frame_fn_t |
| 810 NOT_IMPLEMENTED // vpx_codec_enc_mr_get_mem_loc_fn_t | 683 NOT_IMPLEMENTED // vpx_codec_enc_mr_get_mem_loc_fn_t |
| 811 } | 684 } |
| 812 }; | 685 }; |
| OLD | NEW |