From fb718f33fc2b730c294f0c2e10b4d5dead699f0f Mon Sep 17 00:00:00 2001 From: "leo.ding" Date: Thu, 1 Dec 2016 10:20:59 +0800 Subject: [PATCH] [h264d]: add split mode 1. add split mode prepare branch 2. modify h264d_test for verify split mode Change-Id: I387a78b45ef2417a118d03cb4b171557cf8534aa Signed-off-by: leo.ding --- mpp/codec/dec/h264/h264d_api.c | 6 ++++- mpp/codec/dec/h264/h264d_rwfile.c | 35 +++++++++++++++------------- mpp/codec/dec/h264/h264d_rwfile.h | 6 ++--- mpp/test/h264d_test.c | 38 ++++++++++++++++++++++--------- 4 files changed, 54 insertions(+), 31 deletions(-) diff --git a/mpp/codec/dec/h264/h264d_api.c b/mpp/codec/dec/h264/h264d_api.c index ecd64b07..ce6c9c0b 100644 --- a/mpp/codec/dec/h264/h264d_api.c +++ b/mpp/codec/dec/h264/h264d_api.c @@ -668,7 +668,11 @@ MPP_RET h264d_prepare(void *decoder, MppPacket pkt, HalDecTask *task) } else { fwrite_stream_to_file(p_Inp, p_Inp->in_buf, (RK_U32)p_Inp->in_length); do { - (ret = parse_prepare_fast(p_Inp, p_Dec->p_Cur)); + if (p_Inp->init.need_split) { + ret = parse_prepare(p_Inp, p_Dec->p_Cur); + } else { + ret = parse_prepare_fast(p_Inp, p_Dec->p_Cur); + } task->valid = p_Inp->task_valid; //!< prepare valid flag } while (mpp_packet_get_length(pkt) && !task->valid); } diff --git a/mpp/codec/dec/h264/h264d_rwfile.c b/mpp/codec/dec/h264/h264d_rwfile.c index 51f6f1b4..db953341 100644 --- a/mpp/codec/dec/h264/h264d_rwfile.c +++ b/mpp/codec/dec/h264/h264d_rwfile.c @@ -685,7 +685,7 @@ MPP_RET h264d_open_files(InputParams *p_in) char *outpath_dir = NULL; mpp_env_get_str(logenv_name.outpath, &outpath_dir, NULL); FLE_CHECK(ret, p_in->fp_bitstream = fopen(p_in->infile_name, "rb")); - p_in->fp_yuv_data = open_file(outpath_dir, p_in->infile_name, ".yuv", "wb"); + p_in->fp_yuv_data = fopen("out.yuv", "wb"); return MPP_OK; __FAILED: h264d_close_files(p_in); @@ -741,22 +741,25 @@ __FAILED: */ MPP_RET h264d_read_one_frame(InputParams *p_in) { - p_in->strm.strmbytes = 0; - p_in->is_new_frame = 0; - //-- copy first nalu - if (!p_in->is_fist_frame) { - write_nalu_prefix(p_in); - memcpy(&p_in->strm.pbuf[p_in->strm.strmbytes], p_in->IO.pNALU, p_in->IO.nalubytes); - p_in->strm.strmbytes += p_in->IO.nalubytes; + if (0) { + p_in->strm.strmbytes = 0; + p_in->is_new_frame = 0; + //-- copy first nalu + if (!p_in->is_fist_frame) { + write_nalu_prefix(p_in); + memcpy(&p_in->strm.pbuf[p_in->strm.strmbytes], p_in->IO.pNALU, p_in->IO.nalubytes); + p_in->strm.strmbytes += p_in->IO.nalubytes; + } + //-- read one nalu and copy to stream buffer + do { + find_next_nalu(p_in); + read_next_nalu(p_in); + } while (!p_in->is_new_frame && !p_in->is_eof); + } else { + RK_U32 read_len = 512; + p_in->strm.strmbytes = fread(p_in->strm.pbuf, 1, read_len, p_in->fp_bitstream); + p_in->is_eof = p_in->strm.strmbytes ? 0 : 1; } - //-- read one nalu and copy to stream buffer - do { - find_next_nalu(p_in); - read_next_nalu(p_in); - } while (!p_in->is_new_frame && !p_in->is_eof); - //if (first_mb_in_slice == 0) { - //FPRINT(g_debug_file0, "--- new frame ---- \n"); - //} return MPP_OK; } diff --git a/mpp/codec/dec/h264/h264d_rwfile.h b/mpp/codec/dec/h264/h264d_rwfile.h index 208c21cb..bec1b6b8 100644 --- a/mpp/codec/dec/h264/h264d_rwfile.h +++ b/mpp/codec/dec/h264/h264d_rwfile.h @@ -66,9 +66,9 @@ extern RK_U32 rkv_h264d_test_debug; #define H264D_TEST_TRACE (0x00000001) #define H264D_TEST_TIME (0x00000002) -#define H264D_TEST_MUTI_THREAD (0x00000004) -#define H264D_TEST_DUMPYUV (0x00000008) -#define H264D_TEST_FPGA (0x00000010) +#define H264D_TEST_DUMPYUV (0x00000004) +#define H264D_TEST_FPGA (0x00000008) +#define H264D_TEST_MUTI_THREAD (0x00000010) #define H264D_TEST_LOG(level, fmt, ...)\ diff --git a/mpp/test/h264d_test.c b/mpp/test/h264d_test.c index ae25aeda..bec42463 100644 --- a/mpp/test/h264d_test.c +++ b/mpp/test/h264d_test.c @@ -110,17 +110,21 @@ static MPP_RET decoder_deinit(H264dTestCtx_t *pctx) } if (pctx->m_dec_pkt_buf) { mpp_buffer_put(pctx->m_dec_pkt_buf); + pctx->m_dec_pkt_buf = NULL; } if (pctx->m_dec_pic_buf) { mpp_buffer_put(pctx->m_dec_pic_buf); + pctx->m_dec_pic_buf = NULL; } - if (pctx->mFrameGroup != NULL) { + if (pctx->mFrameGroup) { mpp_err("mFrameGroup deInit"); mpp_buffer_group_put(pctx->mFrameGroup); + pctx->mFrameGroup = NULL; } - if (pctx->mStreamGroup != NULL) { + if (pctx->mStreamGroup) { mpp_err("mStreamGroup deInit"); mpp_buffer_group_put(pctx->mStreamGroup); + pctx->mStreamGroup = NULL; } return MPP_OK; } @@ -138,14 +142,24 @@ static MPP_RET decoder_init(H264dTestCtx_t *pctx) mpp_env_get_u32("rkv_h264d_test_debug", &rkv_h264d_test_debug, 0); if (pctx->mFrameGroup == NULL) { - ret = mpp_buffer_group_get_internal(&pctx->mFrameGroup, MPP_BUFFER_TYPE_ION); +#ifdef RKPLATFORM + mpp_log_f("mFrameGroup used ion In"); + FUN_CHECK(ret = mpp_buffer_group_get_internal(&pctx->mFrameGroup, MPP_BUFFER_TYPE_ION)); +#else + FUN_CHECK(ret = mpp_buffer_group_get_internal(&pctx->mFrameGroup, MPP_BUFFER_TYPE_NORMAL)); +#endif if (MPP_OK != ret) { mpp_err("h264d mpp_buffer_group_get failed\n"); goto __FAILED; } } if (pctx->mStreamGroup == NULL) { - ret = mpp_buffer_group_get_internal(&pctx->mStreamGroup, MPP_BUFFER_TYPE_ION); +#ifdef RKPLATFORM + mpp_log_f("mStreamGroup used ion In"); + FUN_CHECK(ret = mpp_buffer_group_get_internal(&pctx->mStreamGroup, MPP_BUFFER_TYPE_ION)); +#else + FUN_CHECK(ret = mpp_buffer_group_get_internal(&pctx->mStreamGroup, MPP_BUFFER_TYPE_NORMAL)); +#endif if (MPP_OK != ret) { mpp_err("h264d mpp_buffer_group_get failed\n"); goto __FAILED; @@ -209,7 +223,7 @@ static MPP_RET flush_decoded_frames(MppDec *pApi, FILE *fp) stride_h = mpp_frame_get_ver_stride(out_frame); framebuf = mpp_frame_get_buffer(out_frame); ptr = mpp_buffer_get_ptr(framebuf); - if ((rkv_h264d_test_debug & H264D_TEST_DUMPYUV) && fp) { + if (fp) { fwrite(ptr, 1, stride_w * stride_h * 3 / 2, fp); fflush(fp); } @@ -246,8 +260,6 @@ static MPP_RET decoder_single_test(H264dTestCtx_t *pctx) FUN_CHECK(ret = h264d_read_one_frame(pIn)); mpp_packet_init(&pkt, pIn->strm.pbuf, pIn->strm.strmbytes); } - H264D_TEST_LOG(H264D_TEST_TRACE, "[H264D_TEST] ---- decoder, read_one_frame Frame_no = %d", pIn->iFrmdecoded); - pIn->iFrmdecoded++; } //!< prepare FUN_CHECK(ret = parser_prepare(pApi->parser, pkt, &task->dec)); @@ -277,10 +289,12 @@ static MPP_RET decoder_single_test(H264dTestCtx_t *pctx) //!< deinit packet if (mpp_packet_get_length(pkt) == 0) { if (mpp_packet_get_eos(pkt)) { + if (task->dec.valid) { + mpp_buf_slot_clr_flag(pApi->packet_slots, task->dec.input, SLOT_HAL_INPUT); + mpp_buf_slot_clr_flag(pApi->frame_slots, task->dec.output, SLOT_HAL_OUTPUT); + task->dec.valid = 0; + } end_of_flag = 1; //!< end of stream - task->dec.valid = 0; - mpp_buf_slot_clr_flag(pApi->packet_slots, task->dec.input, SLOT_HAL_INPUT); - mpp_buf_slot_clr_flag(pApi->frame_slots, task->dec.output, SLOT_HAL_OUTPUT); } mpp_packet_deinit(&pkt); pkt = NULL; @@ -322,6 +336,8 @@ static MPP_RET decoder_single_test(H264dTestCtx_t *pctx) memset(task, 0, sizeof(HalTaskInfo)); memset(task->dec.refer, -1, sizeof(task->dec.refer)); task->dec.input = -1; + H264D_TEST_LOG(H264D_TEST_TRACE, "[H264D_TEST] ---- had decode frame_no = %d", pIn->iFrmdecoded); + pIn->iFrmdecoded++; } } while (!end_of_flag); @@ -615,6 +631,6 @@ __FAILED: MPP_FREE(pctx); H264D_TEST_LOG(H264D_TEST_TRACE, "[H264D_TEST] decoder_deinit over."); - return ret; + return 0; }