From 31eb29683390a80eb026c1431906145a4651f0e8 Mon Sep 17 00:00:00 2001 From: DingWei Date: Tue, 26 Jan 2016 01:22:07 +0000 Subject: [PATCH] [h264d]1.correct bug: clear error context for every frame; 2. Add function to clear frame slot status which in flush and reset functions. git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@548 6e48237b-75ef-9749-8fc9-41990f28c85a --- mpp/codec/dec/h264/h264d_api.c | 53 ++++++++++++++++------- mpp/codec/dec/h264/h264d_dpb.c | 15 +------ mpp/codec/dec/h264/h264d_global.h | 24 +++++----- mpp/codec/dec/h264/h264d_init.c | 36 ++++----------- mpp/codec/dec/h264/h264d_sei.c | 2 +- mpp/codec/dec/h265/h265d_parser2_syntax.c | 12 ++--- 6 files changed, 64 insertions(+), 78 deletions(-) diff --git a/mpp/codec/dec/h264/h264d_api.c b/mpp/codec/dec/h264/h264d_api.c index 09e3d655..457c1544 100644 --- a/mpp/codec/dec/h264/h264d_api.c +++ b/mpp/codec/dec/h264/h264d_api.c @@ -34,7 +34,6 @@ #include "h264d_dpb.h" - static void close_log_files(LogEnv_t *env) { FCLOSE(env->fp_syn_parse); @@ -275,6 +274,9 @@ static MPP_RET init_vid_ctx(H264dVideoCtx_t *p_Vid) p_Vid->subspsSet[i].num_level_values_signalled_minus1 = -1; } p_Vid->iframe_cnt = 0; + //!< memset error context + memset(&p_Vid->err_ctx, 0, sizeof(H264dErrCtx_t)); + FunctionOut(p_Vid->p_Dec->logctx.parr[RUN_PARSE]); __RETURN: return ret = MPP_OK; @@ -376,8 +378,6 @@ static MPP_RET init_dec_ctx(H264_DecCtx_t *p_Dec) //!< malloc mpp packet mpp_packet_init(&p_Dec->task_pkt, p_Dec->dxva_ctx->bitstream, p_Dec->dxva_ctx->max_strm_size); MEM_CHECK(ret, p_Dec->task_pkt); - //!< memset error context - memset(&p_Dec->err_ctx, 0, sizeof(H264dErrCtx_t)); //!< set Dec support decoder method p_Dec->spt_decode_mtds = MPP_DEC_BY_FRAME; p_Dec->next_state = SliceSTATE_ResetSlice; @@ -394,6 +394,21 @@ __FAILED: return ret; } +static void flush_dpb_buffer_slot(H264_DecCtx_t *p_Dec) +{ + RK_U32 i = 0; + H264_DpbMark_t *p_mark = NULL; + //!< clear buffer slots + for(i = 0; i < MAX_MARK_SIZE; i++){ + p_mark = &p_Dec->dpb_mark[i]; + if (p_mark->out_flag) { + mpp_buf_slot_clr_flag(p_Dec->frame_slots, p_mark->slot_idx, SLOT_CODEC_USE); + p_mark->out_flag = 0; + } + } +} + + static MPP_RET set_frame_errinfo(H264_DecCtx_t *p_Dec, H264dErrCtx_t *err_ctx) { MPP_RET ret = MPP_ERR_UNKNOW; @@ -421,6 +436,9 @@ static MPP_RET set_frame_errinfo(H264_DecCtx_t *p_Dec, H264dErrCtx_t *err_ctx) if (m_frame) { mpp_frame_set_errinfo(m_frame, err_ctx->err_flag); } + //!< memset error context + memset(&p_Dec->p_Vid->err_ctx, 0, sizeof(H264dErrCtx_t)); + __RETURN: FunctionOut(p_Dec->logctx.parr[RUN_PARSE]); return ret = MPP_OK; @@ -546,6 +564,7 @@ MPP_RET h264d_reset(void *decoder) FUN_CHECK(ret = init_dpb(p_Dec->p_Vid, p_Dec->p_Vid->p_Dpb_layer[1], 2)); flush_muti_view_output(p_Dec->frame_slots, p_Dec->p_Vid->outlist, p_Dec->p_Vid); } + flush_dpb_buffer_slot(p_Dec); //!< reset input parameter p_Dec->p_Inp->in_buf = NULL; p_Dec->p_Inp->pkt_eos = 0; @@ -559,7 +578,9 @@ MPP_RET h264d_reset(void *decoder) p_Dec->p_Vid->g_framecnt = 0; p_Dec->p_Vid->last_outputpoc[0] = -1; p_Dec->p_Vid->last_outputpoc[1] = -1; - p_Dec->p_Vid->iframe_cnt = 0; + p_Dec->p_Vid->iframe_cnt = 0; + memset(&p_Dec->p_Vid->err_ctx, 0, sizeof(H264dErrCtx_t)); + //!< reset current time stamp p_Dec->p_Cur->last_dts = 0; p_Dec->p_Cur->last_pts = 0; @@ -599,8 +620,6 @@ MPP_RET h264d_reset(void *decoder) p_Dec->dpb_mark[i].slot_idx = -1; p_Dec->dpb_mark[i].pic = NULL; } - set_frame_errinfo(p_Dec, &p_Dec->err_ctx); - FunctionOut(p_Dec->logctx.parr[RUN_PARSE]); __RETURN: @@ -617,7 +636,7 @@ __FAILED: */ MPP_RET h264d_flush(void *decoder) { - MPP_RET ret = MPP_ERR_UNKNOW; + MPP_RET ret = MPP_ERR_UNKNOW; H264_DecCtx_t *p_Dec = (H264_DecCtx_t *)decoder; //MppFrame m_frame; INP_CHECK(ret, !decoder); @@ -634,12 +653,13 @@ MPP_RET h264d_flush(void *decoder) //free_dpb(p_Dec->p_Vid->p_Dpb_layer[1]); flush_muti_view_output(p_Dec->frame_slots, p_Dec->p_Vid->outlist, p_Dec->p_Vid); } + flush_dpb_buffer_slot(p_Dec); H264D_LOG("[FLUSH] -------- flush over.------, task_eos=%d, last_slot_idx=%d", p_Dec->p_Inp->task_eos, p_Dec->last_frame_slot_idx); //mpp_buf_slot_get_prop(p_Dec->frame_slots, p_Dec->last_frame_slot_idx, SLOT_FRAME_PTR, &m_frame); mpp_buf_slot_set_prop(p_Dec->frame_slots, p_Dec->last_frame_slot_idx, SLOT_EOS, &p_Dec->p_Inp->task_eos); - set_frame_errinfo(p_Dec, &p_Dec->err_ctx); + set_frame_errinfo(p_Dec, &p_Dec->p_Vid->err_ctx); FPRINT(g_debug_file0, "[FLUSH] -------- flush over.------\n"); FunctionOut(p_Dec->logctx.parr[RUN_PARSE]); __RETURN: @@ -793,18 +813,19 @@ MPP_RET h264d_parse(void *decoder, HalDecTask *in_task) (ret = parse_loop(p_Dec)); - if (p_Dec->is_parser_end) { + if (p_Dec->is_parser_end) { p_Dec->is_parser_end = 0; - in_task->valid = 1; // register valid flag - in_task->syntax.number = p_Dec->dxva_ctx->syn.num; - in_task->syntax.data = (void *)p_Dec->dxva_ctx->syn.buf; + //!< output task info + in_task->valid = 1; // register valid flag + in_task->syntax.number = p_Dec->dxva_ctx->syn.num; + in_task->syntax.data = (void *)p_Dec->dxva_ctx->syn.buf; (ret = update_dpb(p_Dec)); - if (in_task->flags.eos) { h264d_flush(decoder); - } - set_frame_errinfo(p_Dec, &p_Dec->err_ctx); - p_Dec->p_Vid->g_framecnt++; + } + set_frame_errinfo(p_Dec, &p_Dec->p_Vid->err_ctx); + + p_Dec->p_Vid->g_framecnt++; } __RETURN: diff --git a/mpp/codec/dec/h264/h264d_dpb.c b/mpp/codec/dec/h264/h264d_dpb.c index 184a899e..fa79e35b 100644 --- a/mpp/codec/dec/h264/h264d_dpb.c +++ b/mpp/codec/dec/h264/h264d_dpb.c @@ -1832,19 +1832,6 @@ MPP_RET flush_dpb(H264_DpbBuf_t *p_Dpb, RK_S32 type) VAL_CHECK(ret, p_Dpb->fs[i]->layer_id == p_Dpb->layer_id); unmark_for_reference(p_Dpb->p_Vid->p_Dec, p_Dpb->fs[i]); } - //!< mark all inter-view reference unsed - //if (type == 2) - //{ - // //!< free - // free_frame_store(p_Dpb->p_Vid->p_Dec, p_Dpb->fs_ilref[0]); - // //!< malloc - // p_Dpb->fs_ilref[0] = alloc_frame_store(); - // MEM_CHECK(ret, p_Dpb->fs_ilref[0]); - // //!< These may need some cleanups - // p_Dpb->fs_ilref[0]->view_id = -1; - // p_Dpb->fs_ilref[0]->inter_view_flag[0] = p_Dpb->fs_ilref[0]->inter_view_flag[1] = 0; - // p_Dpb->fs_ilref[0]->anchor_pic_flag[0] = p_Dpb->fs_ilref[0]->anchor_pic_flag[1] = 0; - //} while (!remove_unused_frame_from_dpb(p_Dpb)); //!< output frames in POC order while (p_Dpb->used_size) { @@ -2386,7 +2373,7 @@ MPP_RET update_dpb(H264_DecCtx_t *p_Dec) p_Dec->p_Vid->have_outpicture_flag = 1; ret = exit_picture(p_Dec->p_Vid, &p_Dec->p_Vid->dec_pic); if(MPP_OK != ret) { - p_Dec->err_ctx.err_flag |= VPU_FRAME_ERR_UNKNOW; + p_Dec->p_Vid->err_ctx.err_flag |= VPU_FRAME_ERR_UNKNOW; } p_Dec->p_Vid->iNumOfSlicesDecoded = 0; p_Dec->p_Vid->exit_picture_flag = 0; diff --git a/mpp/codec/dec/h264/h264d_global.h b/mpp/codec/dec/h264/h264d_global.h index c8b689a0..54a83256 100644 --- a/mpp/codec/dec/h264/h264d_global.h +++ b/mpp/codec/dec/h264/h264d_global.h @@ -292,6 +292,7 @@ typedef struct h264_store_pic_t { RK_S32 poc_mmco5; RK_S32 top_poc_mmco5; RK_S32 bot_poc_mmco5; + RK_S32 combine_flag; // top && bottom field combined flag H264_Mem_type mem_malloc_type; struct h264_dpb_mark_t *mem_mark; } H264_StorePic_t; @@ -913,13 +914,19 @@ typedef struct h264d_cur_ctx_t { RK_S64 curr_dts; } H264dCurCtx_t; +//!< decoder video parameter +typedef struct h264_err_ctx_t { + RK_U32 err_flag; + void *data; + RK_U32 length; +} H264dErrCtx_t; +//!< output list marking typedef struct h264d_outlist_t { RK_U32 begin; RK_U32 end; RK_U32 max_size; H264_DpbMark_t *list[MAX_MARK_SIZE]; } H264dOutList_t; - //!< parameters for video decoder typedef struct h264d_video_ctx_t { struct h264_sps_t spsSet[MAXSPS]; //!< MAXSPS, all sps storage @@ -937,7 +944,6 @@ typedef struct h264d_video_ctx_t { struct h264_frame_store_t out_buffer; struct h264_dpb_mark_t *active_dpb_mark[MAX_NUM_DPB_LAYERS]; //!< acitve_dpb_memory - struct h264_old_slice_par_t old_slice; RK_S32 *qmatrix[12]; //!< scanlist pointer RK_U32 stream_size; @@ -990,9 +996,11 @@ typedef struct h264d_video_ctx_t { //!< for error tolerance RK_U32 g_framecnt; RK_U32 dpb_size[MAX_NUM_DPB_LAYERS]; - struct h264d_outlist_t outlist[MAX_NUM_DPB_LAYERS]; + RK_S32 last_outputpoc[MAX_NUM_DPB_LAYERS]; RK_U32 iframe_cnt; + struct h264_err_ctx_t err_ctx; + struct h264d_outlist_t outlist[MAX_NUM_DPB_LAYERS]; } H264dVideoCtx_t; typedef struct h264d_mem_t { @@ -1046,15 +1054,6 @@ typedef enum slice_state_type { } SLICE_STATUS; - -//!< decoder video parameter -typedef struct h264_err_ctx_t { - RK_U32 err_flag; - void *data; - RK_U32 length; -} H264dErrCtx_t; - - //!< decoder video parameter typedef struct h264_dec_ctx_t { struct h264d_mem_t *mem; @@ -1088,7 +1087,6 @@ typedef struct h264_dec_ctx_t { RK_U32 task_eos; HalDecTask *in_task; RK_S32 last_frame_slot_idx; - struct h264_err_ctx_t err_ctx; } H264_DecCtx_t; diff --git a/mpp/codec/dec/h264/h264d_init.c b/mpp/codec/dec/h264/h264d_init.c index 46808061..cfbdd07a 100644 --- a/mpp/codec/dec/h264/h264d_init.c +++ b/mpp/codec/dec/h264/h264d_init.c @@ -378,7 +378,7 @@ __FAILED: return ret; } -static void dpb_mark_malloc(H264dVideoCtx_t *p_Vid, H264_StorePic_t *dec_pic, RK_U8 combine_flag, RK_S32 layer_id) +static void dpb_mark_malloc(H264dVideoCtx_t *p_Vid, H264_StorePic_t *dec_pic) { RK_U8 idx = 1; H264_DpbMark_t *cur_mark = NULL; @@ -386,28 +386,20 @@ static void dpb_mark_malloc(H264dVideoCtx_t *p_Vid, H264_StorePic_t *dec_pic, R H264_DecCtx_t *p_Dec = p_Vid->p_Dec; H264_DpbMark_t *p_mark = p_Vid->p_Dec->dpb_mark; RK_S32 structure = dec_pic->structure; - - //!< malloc - if (!combine_flag) { + RK_S32 layer_id = dec_pic->layer_id; + if (!dec_pic->combine_flag) { while (p_mark[idx].out_flag || p_mark[idx].top_used || p_mark[idx].bot_used) { idx++; } ASSERT(idx <= MAX_MARK_SIZE); mpp_buf_slot_get_unused(p_Vid->p_Dec->frame_slots, &p_mark[idx].slot_idx); cur_mark = &p_mark[idx]; - cur_mark->out_flag = 1; if (p_Vid->g_framecnt == 255) { idx = idx; } - //LogInfo(p_Vid->p_Dec->logctx.parr[RUN_PARSE], "[MALLOC] g_frame_no=%d, mark_idx=%d, slot_idx=%d \n", p_Vid->g_framecnt, cur_mark->mark_idx, cur_mark->slot_idx); - //mpp_print_slot_flag_info(g_debug_file1, p_Dec->frame_slots, cur_mark->slot_idx); H264D_LOG("[extra_data][Malloc] lay_id=%d, g_framecnt=%d, mark_idx=%d, slot_idx=%d, pts=%lld \n", layer_id, p_Vid->g_framecnt, cur_mark->mark_idx, cur_mark->slot_idx, p_Vid->p_Inp->in_pts); - - //FPRINT(g_debug_file1, "[MALLOC] g_frame_no=%d, mark_idx=%d, slot_idx=%d \n", p_Vid->g_framecnt, cur_mark->mark_idx, cur_mark->slot_idx); - - if ((YUV420 == p_Vid->yuv_format) && (8 == p_Vid->bit_depth_luma)) { mpp_frame_set_fmt(cur_mark->frame, MPP_FMT_YUV420SP); } else if ((YUV420 == p_Vid->yuv_format) && (10 == p_Vid->bit_depth_luma)) { @@ -418,48 +410,38 @@ static void dpb_mark_malloc(H264dVideoCtx_t *p_Vid, H264_StorePic_t *dec_pic, R } else if ((YUV422 == p_Vid->yuv_format) && (10 == p_Vid->bit_depth_luma)) { mpp_frame_set_fmt(cur_mark->frame, MPP_FMT_YUV422SP_10BIT); } - hor_stride = ((p_Vid->width * p_Vid->bit_depth_luma + 127) & (~127)) / 8; ver_stride = p_Vid->height; hor_stride = MPP_ALIGN(hor_stride, 256) | 256; ver_stride = MPP_ALIGN(ver_stride, 16); - mpp_frame_set_hor_stride(cur_mark->frame, hor_stride); // before crop mpp_frame_set_ver_stride(cur_mark->frame, ver_stride); - mpp_frame_set_width(cur_mark->frame, p_Vid->width_after_crop); // after crop mpp_frame_set_height(cur_mark->frame, p_Vid->height_after_crop); H264D_LOG("hor_stride=%d, ver_stride=%d, width=%d, height=%d, crop_width=%d, crop_height =%d \n", hor_stride, ver_stride, p_Vid->width, p_Vid->height, p_Vid->width_after_crop, p_Vid->height_after_crop); - mpp_frame_set_pts(cur_mark->frame, p_Vid->p_Cur->last_pts); mpp_frame_set_dts(cur_mark->frame, p_Vid->p_Cur->last_dts); - //mpp_log("[ timeUs ] alloc_pts=%lld, input_pts=%lld \n", p_Vid->p_Cur->last_pts, p_Vid->p_Inp->in_pts); - mpp_buf_slot_set_prop(p_Dec->frame_slots, cur_mark->slot_idx, SLOT_FRAME, cur_mark->frame); FPRINT(g_debug_file0, "[Malloc] g_framecnt=%d, mark_idx=%d, slot_idx=%d, lay_id=%d, pts=%lld \n", p_Vid->g_framecnt, cur_mark->mark_idx, cur_mark->slot_idx, layer_id, p_Vid->p_Inp->in_pts); - p_Vid->active_dpb_mark[layer_id] = cur_mark; } cur_mark = p_Vid->active_dpb_mark[layer_id]; - //!< index add if (structure == FRAME || structure == TOP_FIELD) { cur_mark->top_used += 1; } if (structure == FRAME || structure == BOTTOM_FIELD) { cur_mark->bot_used += 1; } - - p_Vid->p_Dec->in_task->output = cur_mark->slot_idx; mpp_buf_slot_set_flag(p_Dec->frame_slots, cur_mark->slot_idx, SLOT_HAL_OUTPUT); + dec_pic->mem_mark = p_Vid->active_dpb_mark[layer_id]; + dec_pic->mem_mark->pic = dec_pic; } - static MPP_RET alloc_decpic(H264_SLICE_t *currSlice) { - MPP_RET ret = MPP_ERR_UNKNOW; - RK_S32 combine_flag = 0; + MPP_RET ret = MPP_ERR_UNKNOW; H264_StorePic_t *dec_pic = NULL; H264dVideoCtx_t *p_Vid = currSlice->p_Vid; @@ -546,11 +528,9 @@ static MPP_RET alloc_decpic(H264_SLICE_t *currSlice) dec_pic->height_after_crop = p_Vid->height_after_crop; - combine_flag = get_filed_dpb_combine_flag(p_Dpb, dec_pic); + dec_pic->combine_flag = get_filed_dpb_combine_flag(p_Dpb, dec_pic); dec_pic->mem_malloc_type = Mem_Malloc; - dpb_mark_malloc(p_Vid, dec_pic, combine_flag, dec_pic->layer_id); // malloc dpb_memory - dec_pic->mem_mark = p_Vid->active_dpb_mark[currSlice->layer_id]; - dec_pic->mem_mark->pic = dec_pic; + dpb_mark_malloc(p_Vid, dec_pic); // malloc dpb_memory dec_pic->colmv_no_used_flag = 0; p_Vid->last_pic_structure = dec_pic->structure; p_Vid->dec_pic = dec_pic; diff --git a/mpp/codec/dec/h264/h264d_sei.c b/mpp/codec/dec/h264/h264d_sei.c index 49133da2..beac50d1 100644 --- a/mpp/codec/dec/h264/h264d_sei.c +++ b/mpp/codec/dec/h264/h264d_sei.c @@ -89,7 +89,7 @@ static MPP_RET interpret_user_data_unregistered_info(RK_U8 *payload, RK_S32 size sei_msg->user_data_DivX_flag = strstr(_strupr((char *)&payload[16]), "DIVX") ? 1 : 0; if (sei_msg->user_data_DivX_flag) { H264D_ERR("DivX is not supported. \n"); - sei_msg->p_Dec->err_ctx.err_flag |= VPU_FRAME_ERR_UNSUPPORT; + sei_msg->p_Dec->p_Vid->err_ctx.err_flag |= VPU_FRAME_ERR_UNSUPPORT; ret = MPP_NOK; goto __FAILED; } diff --git a/mpp/codec/dec/h265/h265d_parser2_syntax.c b/mpp/codec/dec/h265/h265d_parser2_syntax.c index a54e47bf..3631c466 100644 --- a/mpp/codec/dec/h265/h265d_parser2_syntax.c +++ b/mpp/codec/dec/h265/h265d_parser2_syntax.c @@ -57,7 +57,7 @@ static void fill_picture_parameters(const HEVCContext *h, const HEVCPPS *pps = (HEVCPPS *)h->pps_list[h->sh.pps_id]; const HEVCSPS *sps = (HEVCSPS *)h->sps_list[pps->sps_id]; - RK_S32 i, j; + RK_U32 i, j; RK_U32 rps_used[16]; RK_U32 nb_rps_used; @@ -146,10 +146,10 @@ static void fill_picture_parameters(const HEVCContext *h, pp->num_tile_rows_minus1 = pps->num_tile_rows - 1; if (!pps->uniform_spacing_flag) { - for (i = 0; i < pps->num_tile_columns; i++) + for (i = 0; i < (RK_U32)pps->num_tile_columns; i++) pp->column_width_minus1[i] = pps->column_width[i] - 1; - for (i = 0; i < pps->num_tile_rows; i++) + for (i = 0; i < (RK_U32)pps->num_tile_rows; i++) pp->row_height_minus1[i] = pps->row_height[i] - 1; } } @@ -162,7 +162,7 @@ static void fill_picture_parameters(const HEVCContext *h, nb_rps_used = 0; for (i = 0; i < NB_RPS_TYPE; i++) { - for (j = 0; j < h->rps[i].nb_refs; j++) { + for (j = 0; j < (RK_U32)h->rps[i].nb_refs; j++) { if ((i == ST_FOLL) || (i == LT_FOLL)) { ; } else { @@ -179,7 +179,7 @@ static void fill_picture_parameters(const HEVCContext *h, (h->DPB[j].flags & (HEVC_FRAME_FLAG_LONG_REF | HEVC_FRAME_FLAG_SHORT_REF))) { RK_U32 k = 0; for (k = 0; k < nb_rps_used; k++) { /*skip fill RefPicList no used in rps*/ - if (rps_used[k] == h->DPB[j].poc) { + if (rps_used[k] == (RK_U32)h->DPB[j].poc) { frame = &h->DPB[j]; } } @@ -204,7 +204,7 @@ static void fill_picture_parameters(const HEVCContext *h, const RefPicList *rpl = &h->rps[ref_idx]; \ for (i = 0, j = 0; i < MPP_ARRAY_ELEMS(pp->ref_list); i++) { \ const HEVCFrame *frame = NULL; \ - while (!frame && j < rpl->nb_refs) \ + while (!frame && j < (RK_U32)rpl->nb_refs) \ frame = rpl->ref[j++]; \ if (frame) \ pp->ref_list[i] = get_refpic_index(pp, frame->slot_index); \