static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, const uint8_t **data, unsigned int data_sz, void *user_priv, int64_t deadline) { const VPxWorkerInterface *const winterface = vpx_get_worker_interface(); (void)deadline; // Determine the stream parameters. Note that we rely on peek_si to // validate that we have a buffer that does not wrap around the top // of the heap. if (!ctx->si.h) { int is_intra_only = 0; const vpx_codec_err_t res = decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only, ctx->decrypt_cb, ctx->decrypt_state); if (res != VPX_CODEC_OK) return res; if (!ctx->si.is_kf && !is_intra_only) return VPX_CODEC_ERROR; } if (!ctx->frame_parallel_decode) { VPxWorker *const worker = ctx->frame_workers; FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; frame_worker_data->data = *data; frame_worker_data->data_size = data_sz; frame_worker_data->user_priv = user_priv; frame_worker_data->received_frame = 1; // Set these even if already initialized. The caller may have changed the // decrypt config between frames. frame_worker_data->pbi->decrypt_cb = ctx->decrypt_cb; frame_worker_data->pbi->decrypt_state = ctx->decrypt_state; worker->had_error = 0; winterface->execute(worker); // Update data pointer after decode. *data = frame_worker_data->data_end; if (worker->had_error) return update_error_state(ctx, &frame_worker_data->pbi->common.error); check_resync(ctx, frame_worker_data->pbi); } else { VPxWorker *const worker = &ctx->frame_workers[ctx->next_submit_worker_id]; FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; // Copy context from last worker thread to next worker thread. if (ctx->next_submit_worker_id != ctx->last_submit_worker_id) vp10_frameworker_copy_context( &ctx->frame_workers[ctx->next_submit_worker_id], &ctx->frame_workers[ctx->last_submit_worker_id]); frame_worker_data->pbi->ready_for_new_data = 0; // Copy the compressed data into worker's internal buffer. // TODO(hkuang): Will all the workers allocate the same size // as the size of the first intra frame be better? This will // avoid too many deallocate and allocate. if (frame_worker_data->scratch_buffer_size < data_sz) { frame_worker_data->scratch_buffer = (uint8_t *)vpx_realloc(frame_worker_data->scratch_buffer, data_sz); if (frame_worker_data->scratch_buffer == NULL) { set_error_detail(ctx, "Failed to reallocate scratch buffer"); return VPX_CODEC_MEM_ERROR; } frame_worker_data->scratch_buffer_size = data_sz; } frame_worker_data->data_size = data_sz; memcpy(frame_worker_data->scratch_buffer, *data, data_sz); frame_worker_data->frame_decoded = 0; frame_worker_data->frame_context_ready = 0; frame_worker_data->received_frame = 1; frame_worker_data->data = frame_worker_data->scratch_buffer; frame_worker_data->user_priv = user_priv; if (ctx->next_submit_worker_id != ctx->last_submit_worker_id) ctx->last_submit_worker_id = (ctx->last_submit_worker_id + 1) % ctx->num_frame_workers; ctx->next_submit_worker_id = (ctx->next_submit_worker_id + 1) % ctx->num_frame_workers; --ctx->available_threads; worker->had_error = 0; winterface->launch(worker); } return VPX_CODEC_OK; }
static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, const uint8_t *data, unsigned int data_sz, void *user_priv, long deadline) { vpx_codec_err_t res = VPX_CODEC_OK; unsigned int resolution_change = 0; unsigned int w, h; if (!ctx->fragments.enabled && (data == NULL && data_sz == 0)) { return 0; } /* Update the input fragment data */ if (update_fragments(ctx, data, data_sz, &res) <= 0) return res; /* Determine the stream parameters. Note that we rely on peek_si to * validate that we have a buffer that does not wrap around the top * of the heap. */ w = ctx->si.w; h = ctx->si.h; res = vp8_peek_si_internal(ctx->fragments.ptrs[0], ctx->fragments.sizes[0], &ctx->si, ctx->decrypt_cb, ctx->decrypt_state); if ((res == VPX_CODEC_UNSUP_BITSTREAM) && !ctx->si.is_kf) { /* the peek function returns an error for non keyframes, however for * this case, it is not an error */ res = VPX_CODEC_OK; } if (!ctx->decoder_init && !ctx->si.is_kf) res = VPX_CODEC_UNSUP_BITSTREAM; if ((ctx->si.h != h) || (ctx->si.w != w)) resolution_change = 1; /* Initialize the decoder instance on the first frame*/ if (!res && !ctx->decoder_init) { VP8D_CONFIG oxcf; oxcf.Width = ctx->si.w; oxcf.Height = ctx->si.h; oxcf.Version = 9; oxcf.postprocess = 0; oxcf.max_threads = ctx->cfg.threads; oxcf.error_concealment = (ctx->base.init_flags & VPX_CODEC_USE_ERROR_CONCEALMENT); /* If postprocessing was enabled by the application and a * configuration has not been provided, default it. */ if (!ctx->postproc_cfg_set && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) { ctx->postproc_cfg.post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK | VP8_MFQE; ctx->postproc_cfg.deblocking_level = 4; ctx->postproc_cfg.noise_level = 0; } res = vp8_create_decoder_instances(&ctx->yv12_frame_buffers, &oxcf); ctx->decoder_init = 1; } /* Set these even if already initialized. The caller may have changed the * decrypt config between frames. */ if (ctx->decoder_init) { ctx->yv12_frame_buffers.pbi[0]->decrypt_cb = ctx->decrypt_cb; ctx->yv12_frame_buffers.pbi[0]->decrypt_state = ctx->decrypt_state; } if (!res) { VP8D_COMP *pbi = ctx->yv12_frame_buffers.pbi[0]; if (resolution_change) { VP8_COMMON *const pc = &pbi->common; MACROBLOCKD *const xd = &pbi->mb; #if CONFIG_MULTITHREAD int i; #endif pc->Width = ctx->si.w; pc->Height = ctx->si.h; { int prev_mb_rows = pc->mb_rows; if (setjmp(pbi->common.error.jmp)) { pbi->common.error.setjmp = 0; vp8_clear_system_state(); /* same return value as used in vp8dx_receive_compressed_data */ return -1; } pbi->common.error.setjmp = 1; if (pc->Width <= 0) { pc->Width = w; vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, "Invalid frame width"); } if (pc->Height <= 0) { pc->Height = h; vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, "Invalid frame height"); } if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height)) { vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, "Failed to allocate frame buffers"); } xd->pre = pc->yv12_fb[pc->lst_fb_idx]; xd->dst = pc->yv12_fb[pc->new_fb_idx]; #if CONFIG_MULTITHREAD for (i = 0; i < pbi->allocated_decoding_thread_count; ++i) { pbi->mb_row_di[i].mbd.dst = pc->yv12_fb[pc->new_fb_idx]; vp8_build_block_doffsets(&pbi->mb_row_di[i].mbd); } #endif vp8_build_block_doffsets(&pbi->mb); /* allocate memory for last frame MODE_INFO array */ #if CONFIG_ERROR_CONCEALMENT if (pbi->ec_enabled) { /* old prev_mip was released by vp8_de_alloc_frame_buffers() * called in vp8_alloc_frame_buffers() */ pc->prev_mip = vpx_calloc((pc->mb_cols + 1) * (pc->mb_rows + 1), sizeof(MODE_INFO)); if (!pc->prev_mip) { vp8_de_alloc_frame_buffers(pc); vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, "Failed to allocate" "last frame MODE_INFO array"); } pc->prev_mi = pc->prev_mip + pc->mode_info_stride + 1; if (vp8_alloc_overlap_lists(pbi)) vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, "Failed to allocate overlap lists " "for error concealment"); } #endif #if CONFIG_MULTITHREAD if (pbi->b_multithreaded_rd) { vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows); } #else (void)prev_mb_rows; #endif } pbi->common.error.setjmp = 0; /* required to get past the first get_free_fb() call */ pbi->common.fb_idx_ref_cnt[0] = 0; } /* update the pbi fragment data */ pbi->fragments = ctx->fragments; ctx->user_priv = user_priv; if (vp8dx_receive_compressed_data(pbi, data_sz, data, deadline)) { res = update_error_state(ctx, &pbi->common.error); } /* get ready for the next series of fragments */ ctx->fragments.count = 0; } return res; }
static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, const uint8_t **data, unsigned int data_sz, void *user_priv, long deadline) { vpx_codec_err_t res = VPX_CODEC_OK; ctx->img_avail = 0; /* Determine the stream parameters. Note that we rely on peek_si to * validate that we have a buffer that does not wrap around the top * of the heap. */ if (!ctx->si.h) res = ctx->base.iface->dec.peek_si(*data, data_sz, &ctx->si); /* Perform deferred allocations, if required */ if (!res && ctx->defer_alloc) { int i; for (i = 1; !res && i < NELEMENTS(ctx->mmaps); i++) { vpx_codec_dec_cfg_t cfg; cfg.w = ctx->si.w; cfg.h = ctx->si.h; ctx->mmaps[i].id = vp9_mem_req_segs[i].id; ctx->mmaps[i].sz = vp9_mem_req_segs[i].sz; ctx->mmaps[i].align = vp9_mem_req_segs[i].align; ctx->mmaps[i].flags = vp9_mem_req_segs[i].flags; if (!ctx->mmaps[i].sz) ctx->mmaps[i].sz = vp9_mem_req_segs[i].calc_sz(&cfg, ctx->base.init_flags); res = vpx_mmap_alloc(&ctx->mmaps[i]); } if (!res) vp9_finalize_mmaps(ctx); ctx->defer_alloc = 0; } /* Initialize the decoder instance on the first frame*/ if (!res && !ctx->decoder_init) { res = vpx_validate_mmaps(&ctx->si, ctx->mmaps, vp9_mem_req_segs, NELEMENTS(vp9_mem_req_segs), ctx->base.init_flags); if (!res) { VP9D_CONFIG oxcf; VP9D_PTR optr; vp9_initialize_dec(); oxcf.width = ctx->si.w; oxcf.height = ctx->si.h; oxcf.version = 9; oxcf.postprocess = 0; oxcf.max_threads = ctx->cfg.threads; oxcf.inv_tile_order = ctx->invert_tile_order; optr = vp9_create_decompressor(&oxcf); /* If postprocessing was enabled by the application and a * configuration has not been provided, default it. */ if (!ctx->postproc_cfg_set && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) { ctx->postproc_cfg.post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; ctx->postproc_cfg.deblocking_level = 4; ctx->postproc_cfg.noise_level = 0; } if (!optr) res = VPX_CODEC_ERROR; else ctx->pbi = optr; } ctx->decoder_init = 1; } if (!res && ctx->pbi) { YV12_BUFFER_CONFIG sd; int64_t time_stamp = 0, time_end_stamp = 0; vp9_ppflags_t flags = {0}; if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) { flags.post_proc_flag = ctx->postproc_cfg.post_proc_flag #if CONFIG_POSTPROC_VISUALIZER | ((ctx->dbg_color_ref_frame_flag != 0) ? VP9D_DEBUG_CLR_FRM_REF_BLKS : 0) | ((ctx->dbg_color_mb_modes_flag != 0) ? VP9D_DEBUG_CLR_BLK_MODES : 0) | ((ctx->dbg_color_b_modes_flag != 0) ? VP9D_DEBUG_CLR_BLK_MODES : 0) | ((ctx->dbg_display_mv_flag != 0) ? VP9D_DEBUG_DRAW_MV : 0) #endif ; flags.deblocking_level = ctx->postproc_cfg.deblocking_level; flags.noise_level = ctx->postproc_cfg.noise_level; #if CONFIG_POSTPROC_VISUALIZER flags.display_ref_frame_flag = ctx->dbg_color_ref_frame_flag; flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag; flags.display_b_modes_flag = ctx->dbg_color_b_modes_flag; flags.display_mv_flag = ctx->dbg_display_mv_flag; #endif } if (vp9_receive_compressed_data(ctx->pbi, data_sz, data, deadline)) { VP9D_COMP *pbi = (VP9D_COMP *)ctx->pbi; res = update_error_state(ctx, &pbi->common.error); } if (!res && 0 == vp9_get_raw_frame(ctx->pbi, &sd, &time_stamp, &time_end_stamp, &flags)) { yuvconfig2image(&ctx->img, &sd, user_priv); ctx->img_avail = 1; } } return res; }
static vpx_codec_err_t decode_one_recon_ex(vpx_codec_alg_priv_t *ctx, const uint8_t **data, unsigned int data_sz, void *user_priv, int64_t deadline, void *texture) { vpx_codec_err_t res = VPX_CODEC_OK; VP9D_COMP *pbi; VP9D_COMP *pbi_storage; VP9D_COMP *my_pbi; static int flag = 0; int i_is_last_frame = 0; int ret = -1; struct vpx_usec_timer timer; unsigned long yuv2rgb_time = 0; unsigned long decode_time = 0; // ctx->img_avail = 0; vpx_usec_timer_start(&timer); if (data_sz == 0) { pbi = (VP9D_COMP *)ctx->pbi; if (!pbi->l_bufpool_flag_output) { return 0; } } /* Determine the stream parameters. Note that we rely on peek_si to * validate that we have a buffer that does not wrap around the top * of the heap. */ if (!ctx->si.h) res = ctx->base.iface->dec.peek_si(*data, data_sz, &ctx->si); /* Perform deferred allocations, if required */ if (!res && ctx->defer_alloc) { int i; for (i = 1; !res && i < NELEMENTS(ctx->mmaps); i++) { vpx_codec_dec_cfg_t cfg; cfg.w = ctx->si.w; cfg.h = ctx->si.h; ctx->mmaps[i].id = vp9_mem_req_segs[i].id; ctx->mmaps[i].sz = vp9_mem_req_segs[i].sz; ctx->mmaps[i].align = vp9_mem_req_segs[i].align; ctx->mmaps[i].flags = vp9_mem_req_segs[i].flags; if (!ctx->mmaps[i].sz) ctx->mmaps[i].sz = vp9_mem_req_segs[i].calc_sz(&cfg, ctx->base.init_flags); res = vpx_mmap_alloc(&ctx->mmaps[i]); } if (!res) vp9_finalize_mmaps(ctx); ctx->defer_alloc = 0; } /* Initialize the decoder instance on the first frame*/ if (!res && !ctx->decoder_init) { res = vpx_validate_mmaps(&ctx->si, ctx->mmaps, vp9_mem_req_segs, NELEMENTS(vp9_mem_req_segs), ctx->base.init_flags); if (!res) { VP9D_CONFIG oxcf; VP9D_PTR optr; VP9D_COMP *const new_pbi = vpx_memalign(32, sizeof(VP9D_COMP)); VP9D_COMP *const new_pbi_two = vpx_memalign(32, sizeof(VP9D_COMP)); vp9_initialize_dec(); oxcf.width = ctx->si.w; oxcf.height = ctx->si.h; oxcf.version = 9; oxcf.postprocess = 0; oxcf.max_threads = ctx->cfg.threads; oxcf.inv_tile_order = ctx->invert_tile_order; optr = vp9_create_decompressor_recon(&oxcf); vp9_zero(*new_pbi); vp9_zero(*new_pbi_two); // If postprocessing was enabled by the application and a // configuration has not been provided, default it. if (!ctx->postproc_cfg_set && (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) { ctx->postproc_cfg.post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; ctx->postproc_cfg.deblocking_level = 4; ctx->postproc_cfg.noise_level = 0; } if (!optr) { res = VPX_CODEC_ERROR; } else { VP9D_COMP *const pbi = (VP9D_COMP*)optr; VP9_COMMON *const cm = &pbi->common; VP9_COMMON *const cm0 = &new_pbi->common; VP9_COMMON *const cm1 = &new_pbi_two->common; if (ctx->fb_list != NULL && ctx->realloc_fb_cb != NULL && ctx->fb_count > 0) { cm->fb_list = ctx->fb_list; cm->fb_count = ctx->fb_count; cm->realloc_fb_cb = ctx->realloc_fb_cb; cm->user_priv = ctx->user_priv; CpuFlag = 1; } else { CpuFlag = 0; cm->fb_count = FRAME_BUFFERS; } cm->fb_lru = ctx->fb_lru; CHECK_MEM_ERROR(cm, cm->yv12_fb, vpx_calloc(cm->fb_count, sizeof(*cm->yv12_fb))); CHECK_MEM_ERROR(cm, cm->fb_idx_ref_cnt, vpx_calloc(cm->fb_count, sizeof(*cm->fb_idx_ref_cnt))); if (cm->fb_lru) { CHECK_MEM_ERROR(cm, cm->fb_idx_ref_lru, vpx_calloc(cm->fb_count, sizeof(*cm->fb_idx_ref_lru))); } ctx->pbi = optr; ctx->storage_pbi[0] = new_pbi; ctx->storage_pbi[1] = new_pbi_two; // cm 0 if (ctx->fb_list != NULL && ctx->realloc_fb_cb != NULL && ctx->fb_count > 0) { cm0->fb_list = ctx->fb_list; cm0->fb_count = ctx->fb_count; cm0->realloc_fb_cb = ctx->realloc_fb_cb; cm0->user_priv = ctx->user_priv; } else { cm0->fb_count = FRAME_BUFFERS; } cm0->fb_lru = ctx->fb_lru; // CHECK_MEM_ERROR(cm, cm->yv12_fb, // vpx_calloc(cm->fb_count, sizeof(*cm->yv12_fb))); CHECK_MEM_ERROR(cm0, cm0->fb_idx_ref_cnt, vpx_calloc(cm0->fb_count, sizeof(*cm0->fb_idx_ref_cnt))); if (cm0->fb_lru) { CHECK_MEM_ERROR(cm0, cm0->fb_idx_ref_lru, vpx_calloc(cm0->fb_count, sizeof(*cm0->fb_idx_ref_lru))); } // cm 1 if (ctx->fb_list != NULL && ctx->realloc_fb_cb != NULL && ctx->fb_count > 0) { cm1->fb_list = ctx->fb_list; cm1->fb_count = ctx->fb_count; cm1->realloc_fb_cb = ctx->realloc_fb_cb; cm1->user_priv = ctx->user_priv; } else { cm1->fb_count = FRAME_BUFFERS; } cm1->fb_lru = ctx->fb_lru; // CHECK_MEM_ERROR(cm, cm->yv12_fb, // vpx_calloc(cm->fb_count, sizeof(*cm->yv12_fb))); CHECK_MEM_ERROR(cm1, cm1->fb_idx_ref_cnt, vpx_calloc(cm1->fb_count, sizeof(*cm1->fb_idx_ref_cnt))); if (cm1->fb_lru) { CHECK_MEM_ERROR(cm1, cm1->fb_idx_ref_lru, vpx_calloc(cm1->fb_count, sizeof(*cm1->fb_idx_ref_lru))); } } } ctx->decoder_init = 1; } if (!res && ctx->pbi) { YV12_BUFFER_CONFIG sd; int64_t time_stamp = 0, time_end_stamp = 0; vp9_ppflags_t flags = {0}; if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) { flags.post_proc_flag = #if CONFIG_POSTPROC_VISUALIZER (ctx->dbg_color_ref_frame_flag ? VP9D_DEBUG_CLR_FRM_REF_BLKS : 0) | (ctx->dbg_color_mb_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | (ctx->dbg_color_b_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | (ctx->dbg_display_mv_flag ? VP9D_DEBUG_DRAW_MV : 0) | #endif ctx->postproc_cfg.post_proc_flag; flags.deblocking_level = ctx->postproc_cfg.deblocking_level; flags.noise_level = ctx->postproc_cfg.noise_level; #if CONFIG_POSTPROC_VISUALIZER flags.display_ref_frame_flag = ctx->dbg_color_ref_frame_flag; flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag; flags.display_b_modes_flag = ctx->dbg_color_b_modes_flag; flags.display_mv_flag = ctx->dbg_display_mv_flag; #endif } #if 0 if (vp9_receive_compressed_data(ctx->pbi, data_sz, data, deadline)) { VP9D_COMP *pbi = (VP9D_COMP*)ctx->pbi; res = update_error_state(ctx, &pbi->common.error); } if (!res && 0 == vp9_get_raw_frame(ctx->pbi, &sd, &time_stamp, &time_end_stamp, &flags)) { yuvconfig2image(&ctx->img, &sd, user_priv); ctx->img_avail = 1; } #endif if (data_sz == 0) { i_is_last_frame = 1; } if (vp9_receive_compressed_data_recon(ctx->pbi, ctx->storage_pbi, data_sz, data, deadline, i_is_last_frame)) { pbi = (VP9D_COMP *)ctx->pbi; if (pbi->l_bufpool_flag_output == 0) pbi_storage = (VP9D_COMP *)ctx->storage_pbi[1]; else pbi_storage = (VP9D_COMP *)ctx->storage_pbi[pbi->l_bufpool_flag_output & 1]; res = update_error_state(ctx, &pbi_storage->common.error); } vpx_usec_timer_mark(&timer); decode_time = (unsigned int)vpx_usec_timer_elapsed(&timer); if (ctx->pbi) { pbi = (VP9D_COMP *)ctx->pbi; if (pbi->l_bufpool_flag_output) { ret = vp9_get_raw_frame(ctx->storage_pbi[pbi->l_bufpool_flag_output & 1], &sd, &time_stamp, &time_end_stamp, &flags); if (!pbi->res && 0 == ret ) { //for render my_pbi = (VP9D_COMP *)(ctx->storage_pbi[pbi->l_bufpool_flag_output & 1]); yuv2rgba_ocl_obj.y_plane_offset = my_pbi->common.frame_to_show->y_buffer - inter_ocl_obj.buffer_pool_map_ptr; yuv2rgba_ocl_obj.u_plane_offset = my_pbi->common.frame_to_show->u_buffer - inter_ocl_obj.buffer_pool_map_ptr; yuv2rgba_ocl_obj.v_plane_offset = my_pbi->common.frame_to_show->v_buffer - inter_ocl_obj.buffer_pool_map_ptr; yuv2rgba_ocl_obj.Y_stride = my_pbi->common.frame_to_show->y_stride; yuv2rgba_ocl_obj.UV_stride = my_pbi->common.frame_to_show->uv_stride; yuv2rgba_ocl_obj.globalThreads[0] = my_pbi->common.width >> 1; yuv2rgba_ocl_obj.globalThreads[1] = my_pbi->common.height >> 1; vpx_usec_timer_start(&timer); vp9_yuv2rgba(&yuv2rgba_ocl_obj, texture); vpx_usec_timer_mark(&timer); yuv2rgb_time = (unsigned int)vpx_usec_timer_elapsed(&timer); fprintf(pLog, "decode one frame time(without YUV to RGB): %lu us\n" "the whole time of YUV to RGB: %lu us\n", decode_time, yuv2rgb_time); // for render end yuvconfig2image(&ctx->img, &sd, user_priv); ctx->img_avail = 1; }