diff --git a/mpp/codec/dec/dummy/dummy_dec_api.c b/mpp/codec/dec/dummy/dummy_dec_api.c index a691e4a2..82073309 100644 --- a/mpp/codec/dec/dummy/dummy_dec_api.c +++ b/mpp/codec/dec/dummy/dummy_dec_api.c @@ -288,6 +288,12 @@ MPP_RET dummy_dec_parse(void *dec, HalDecTask *task) return MPP_OK; } +MPP_RET dummy_dec_callback(void *dec, void *err_info) +{ + (void)dec; + (void)err_info; + return MPP_OK; +} const ParserApi dummy_dec_parser = { "dummy_dec_parser", MPP_VIDEO_CodingUnused, @@ -300,5 +306,6 @@ const ParserApi dummy_dec_parser = { dummy_dec_reset, dummy_dec_flush, dummy_dec_control, + dummy_dec_callback, }; diff --git a/mpp/codec/dec/h264/h264d_api.c b/mpp/codec/dec/h264/h264d_api.c index f77eb3fa..f14dcc0f 100644 --- a/mpp/codec/dec/h264/h264d_api.c +++ b/mpp/codec/dec/h264/h264d_api.c @@ -783,6 +783,18 @@ __FAILED: return ret; } +/*! +*********************************************************************** +* \brief +* callback +*********************************************************************** +*/ +MPP_RET h264d_callback(void *decoder, void *err_info) +{ + (void) decoder; + (void) err_info; + return MPP_OK; +} /*! *********************************************************************** * \brief @@ -802,5 +814,6 @@ const ParserApi api_h264d_parser = { h264d_reset, h264d_flush, h264d_control, + h264d_callback, }; diff --git a/mpp/codec/dec/h265/h265d_parser.c b/mpp/codec/dec/h265/h265d_parser.c index 07c4ab79..b8db42ce 100644 --- a/mpp/codec/dec/h265/h265d_parser.c +++ b/mpp/codec/dec/h265/h265d_parser.c @@ -38,7 +38,9 @@ #define START_CODE 0x000001 ///< start_code_prefix_one_3bytes RK_U32 h265d_debug; -//FILE *fp = NULL; +#ifdef dump +FILE *fp = NULL; +#endif //static RK_U32 start_write = 0, value = 0; /** @@ -180,6 +182,8 @@ RK_S32 h265d_split_init(void **sc) return MPP_ERR_NOMEM; } } + s->buffer = mpp_malloc(RK_U8, MAX_FRAME_SIZE); + s->buffer_size = MAX_FRAME_SIZE; s->fetch_timestamp = 1; return MPP_OK; } @@ -273,6 +277,9 @@ RK_S32 h265d_split_reset(void *sc) RK_U8 *buf = NULL; RK_U32 size = 0; SplitContext_t *s = (SplitContext_t*)sc; + if (sc == NULL) { + return MPP_OK; + } buf = s->buffer; size = s->buffer_size; memset(s, 0, sizeof(SplitContext_t)); @@ -1521,9 +1528,9 @@ static RK_S32 split_nal_units(HEVCContext *s, RK_U8 *buf, RK_U32 length) } - if (s->nal_unit_type == NAL_EOB_NUT || - s->nal_unit_type == NAL_EOS_NUT) - s->eos = 1; + /* if (s->nal_unit_type == NAL_EOB_NUT || + s->nal_unit_type == NAL_EOS_NUT) + s->eos = 1;*/ buf += consumed; length -= consumed; @@ -1631,7 +1638,10 @@ MPP_RET h265d_prepare(void *ctx, MppPacket pkt, HalDecTask *task) RK_S32 length = 0; //task->valid = 0; - s->eos = sc->eos = mpp_packet_get_eos(pkt); + s->eos = mpp_packet_get_eos(pkt); + if (sc != NULL) { + sc->eos = s->eos; + } buf = (RK_U8 *)mpp_packet_get_pos(pkt); pts = mpp_packet_get_pts(pkt); dts = mpp_packet_get_dts(pkt); @@ -1680,6 +1690,11 @@ MPP_RET h265d_prepare(void *ctx, MppPacket pkt, HalDecTask *task) h265d_flush(ctx); } } +#ifdef dump + if (s->nb_frame < 10 && fp != NULL) { + fwrite(buf, 1, length, fp); + } +#endif ret = (MPP_RET)split_nal_units(s, buf, length); if (MPP_OK == ret) { @@ -1862,7 +1877,7 @@ MPP_RET h265d_init(void *ctx, ParserCfg *parser_cfg) h265dctx->priv_data = s; } - h265dctx->need_split = 1; + h265dctx->need_split = parser_cfg->need_split; if (sc == NULL && h265dctx->need_split) { h265d_split_init((void**)&sc); @@ -1906,7 +1921,9 @@ MPP_RET h265d_init(void *ctx, ParserCfg *parser_cfg) if (MPP_OK != mpp_packet_init(&s->input_packet, (void*)buf, size)) { return MPP_ERR_NOMEM; } -// fp = fopen("dump1.bin", "wb+"); +#ifdef dump + fp = fopen("/data/dump1.bin", "wb+"); +#endif return 0; } @@ -1949,6 +1966,17 @@ MPP_RET h265d_control(void *ctx, RK_S32 cmd, void *param) return MPP_OK; } +MPP_RET h265d_callback(void *ctx, void *err_info) +{ + + (void) err_info; + H265dContext_t *h265dctx = (H265dContext_t *)ctx; + HEVCContext *s = (HEVCContext *)h265dctx->priv_data; + s->max_ra = INT_MAX; + return MPP_OK; +} + + const ParserApi api_h265d_parser = { "h265d_parse", @@ -1962,6 +1990,7 @@ const ParserApi api_h265d_parser = { h265d_reset, h265d_flush, h265d_control, + h265d_callback, }; diff --git a/mpp/codec/dec/h265/test/h265d_parser_test.c b/mpp/codec/dec/h265/test/h265d_parser_test.c index a39c7735..25143cf5 100644 --- a/mpp/codec/dec/h265/test/h265d_parser_test.c +++ b/mpp/codec/dec/h265/test/h265d_parser_test.c @@ -367,6 +367,7 @@ RK_S32 hevc_parser_test(ParserDemoCmdContext_t *cmd) #endif parser_cfg.frame_slots = slots; parser_cfg.packet_slots = packet_slots; + parser_cfg.need_split = 1; hal_cfg.frame_slots = slots; hal_cfg.packet_slots = packet_slots; h265d_init(mpp_codex_ctx, &parser_cfg); diff --git a/mpp/codec/dec/vp9/vp9d_api.c b/mpp/codec/dec/vp9/vp9d_api.c index 312f7f8d..bab5cf32 100644 --- a/mpp/codec/dec/vp9/vp9d_api.c +++ b/mpp/codec/dec/vp9/vp9d_api.c @@ -138,6 +138,21 @@ MPP_RET vp9d_parse(void *decoder, HalDecTask *in_task) return ret = MPP_OK; } +/*! +*********************************************************************** +* \brief +* callback +*********************************************************************** +*/ +MPP_RET vp9d_callback(void *decoder, void *err_info) +{ + MPP_RET ret = MPP_ERR_UNKNOW; + + (void)decoder; + (void)err_info; + return ret = MPP_OK; +} + /*! *********************************************************************** * \brief @@ -157,5 +172,6 @@ const ParserApi api_vp9d_parser = { vp9d_reset, vp9d_flush, vp9d_control, + vp9d_callback, }; diff --git a/mpp/codec/inc/dummy_dec_api.h b/mpp/codec/inc/dummy_dec_api.h index a75e9273..c110dc14 100644 --- a/mpp/codec/inc/dummy_dec_api.h +++ b/mpp/codec/inc/dummy_dec_api.h @@ -32,6 +32,7 @@ MPP_RET dummy_dec_flush (void *dec); MPP_RET dummy_dec_control(void *dec, RK_S32 cmd_type, void *param); MPP_RET dummy_dec_prepare(void *dec, MppPacket pkt, HalDecTask *task); MPP_RET dummy_dec_parse (void *dec, HalDecTask *task); +MPP_RET dummy_dec_callback(void *dec, void *err_info); #ifdef __cplusplus } diff --git a/mpp/codec/inc/h264d_api.h b/mpp/codec/inc/h264d_api.h index 3631b98a..d449b514 100644 --- a/mpp/codec/inc/h264d_api.h +++ b/mpp/codec/inc/h264d_api.h @@ -42,6 +42,7 @@ MPP_RET h264d_flush (void *decoder); MPP_RET h264d_control(void *decoder, RK_S32 cmd_type, void *param); MPP_RET h264d_prepare(void *decoder, MppPacket pkt, HalDecTask *task); MPP_RET h264d_parse (void *decoder, HalDecTask *task); +MPP_RET h264d_callback(void *decoder, void *err_info); #ifdef __cplusplus } diff --git a/mpp/codec/inc/h265d_api.h b/mpp/codec/inc/h265d_api.h index f22c6e49..58d15363 100644 --- a/mpp/codec/inc/h265d_api.h +++ b/mpp/codec/inc/h265d_api.h @@ -31,6 +31,7 @@ MPP_RET h265d_deinit(void *ctx); MPP_RET h265d_flush(void *ctx); MPP_RET h265d_reset(void *ctx); MPP_RET h265d_control(void *ctx, RK_S32 cmd, void *param); +MPP_RET h265d_callback(void *ctx, void *err_info); RK_S32 mpp_hevc_split_frame(void *sc, const RK_U8 **poutbuf, RK_S32 *poutbuf_size, const RK_U8 *buf, RK_S32 buf_size); diff --git a/mpp/codec/inc/mpp_parser.h b/mpp/codec/inc/mpp_parser.h index cade25b3..d4be0da8 100644 --- a/mpp/codec/inc/mpp_parser.h +++ b/mpp/codec/inc/mpp_parser.h @@ -34,6 +34,7 @@ MPP_RET parser_parse(Parser prs, HalDecTask *task); MPP_RET parser_reset(Parser prs); MPP_RET parser_flush(Parser prs); MPP_RET parser_control(Parser prs, RK_S32 cmd, void *para); +MPP_RET hal_callback(void* prs, void *err_info); #ifdef __cplusplus } diff --git a/mpp/codec/inc/parser_api.h b/mpp/codec/inc/parser_api.h index d06433ee..95c01fbd 100644 --- a/mpp/codec/inc/parser_api.h +++ b/mpp/codec/inc/parser_api.h @@ -36,6 +36,7 @@ typedef struct DecParserInitCfg_t { // output RK_S32 task_count; + RK_S32 need_split; } ParserCfg; @@ -70,6 +71,7 @@ typedef struct ParserApi_t { MPP_RET (*reset)(void *ctx); MPP_RET (*flush)(void *ctx); MPP_RET (*control)(void *ctx, RK_S32 cmd, void *param); + MPP_RET (*callback)(void *ctx, void *err_info); } ParserApi; diff --git a/mpp/codec/inc/vp9d_api.h b/mpp/codec/inc/vp9d_api.h index 13a4f9ad..e8a898fb 100644 --- a/mpp/codec/inc/vp9d_api.h +++ b/mpp/codec/inc/vp9d_api.h @@ -34,6 +34,7 @@ MPP_RET vp9d_flush (void *decoder); MPP_RET vp9d_control(void *decoder, RK_S32 cmd_type, void *param); MPP_RET vp9d_prepare(void *decoder, MppPacket pkt, HalDecTask *task); MPP_RET vp9d_parse (void *decoder, HalDecTask *task); +MPP_RET vp9d_callback(void *decoder, void *err_info); #ifdef __cplusplus } diff --git a/mpp/codec/mpp_dec.cpp b/mpp/codec/mpp_dec.cpp index 46ef670a..316c8bc7 100644 --- a/mpp/codec/mpp_dec.cpp +++ b/mpp/codec/mpp_dec.cpp @@ -225,11 +225,6 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task) size_t stream_size = 0; HalDecTask *task_dec = &task->info.dec; - if (mpp->mFrameGroup) { - task->wait.dec_pic_buf = (mpp_buffer_group_unused(mpp->mFrameGroup) < 1); - if (task->wait.dec_pic_buf) - return MPP_NOK; - } /* * 1. get task handle from hal for parsing one frame @@ -363,6 +358,11 @@ static MPP_RET try_proc_dec_task(Mpp *mpp, DecTask *task) return MPP_NOK; } } + if (mpp->mFrameGroup) { + task->wait.dec_pic_buf = (mpp_buffer_group_unused(mpp->mFrameGroup) < 1); + if (task->wait.dec_pic_buf) + return MPP_NOK; + } if (task_dec->flags.eos && task_dec->valid == 0) { RK_S32 index; @@ -708,6 +708,7 @@ MPP_RET mpp_dec_init(MppDec **dec, MppCodingType coding) frame_slots, packet_slots, 2, + 0, }; ret = parser_init(&parser, &parser_cfg); @@ -715,7 +716,7 @@ MPP_RET mpp_dec_init(MppDec **dec, MppCodingType coding) mpp_err_f("could not init parser\n"); break; } - + HalIOInterruptCB cb = {.callBack = hal_callback, .opaque = parser}; // then init hal with task count from parser MppHalCfg hal_cfg = { MPP_CTX_DEC, @@ -726,6 +727,7 @@ MPP_RET mpp_dec_init(MppDec **dec, MppCodingType coding) packet_slots, NULL, parser_cfg.task_count, + cb, }; ret = mpp_hal_init(&hal, &hal_cfg); diff --git a/mpp/codec/mpp_parser.cpp b/mpp/codec/mpp_parser.cpp index 1992e6ff..aca3006a 100644 --- a/mpp/codec/mpp_parser.cpp +++ b/mpp/codec/mpp_parser.cpp @@ -131,6 +131,17 @@ MPP_RET parser_parse(Parser prs, HalDecTask *task) return p->api->parse(p->ctx, task); } +MPP_RET hal_callback(void *prs, void *err_info) +{ + if (NULL == prs) { + mpp_err_f("found NULL input\n"); + return MPP_ERR_NULL_PTR; + } + ParserImpl *p = (ParserImpl *)prs; + if (!p->api->callback) + return MPP_OK; + return p->api->callback(p->ctx, err_info); +} MPP_RET parser_reset(Parser prs) { if (NULL == prs) { diff --git a/mpp/hal/inc/mpp_hal.h b/mpp/hal/inc/mpp_hal.h index 259a21d6..fcb6ee21 100644 --- a/mpp/hal/inc/mpp_hal.h +++ b/mpp/hal/inc/mpp_hal.h @@ -37,6 +37,10 @@ typedef enum MppHalHardType_e { typedef void* MppHalCtx; +typedef struct HalIOInterruptCB { + MPP_RET (*callBack)(void*, void*); + void *opaque; +} HalIOInterruptCB; typedef struct MppHalCfg_t { // input MppCtxType type; @@ -49,6 +53,7 @@ typedef struct MppHalCfg_t { // output HalTaskGroup tasks; RK_S32 task_count; + HalIOInterruptCB hal_int_cb; } MppHalCfg; typedef struct MppHalApi_t { diff --git a/mpp/hal/rkdec/h265d/hal_h265d_reg.c b/mpp/hal/rkdec/h265d/hal_h265d_reg.c index 4be29c3b..471d5bc9 100644 --- a/mpp/hal/rkdec/h265d/hal_h265d_reg.c +++ b/mpp/hal/rkdec/h265d/hal_h265d_reg.c @@ -58,6 +58,7 @@ typedef struct h265d_reg_context { MppBuffer pps_data; MppBuffer rps_data; void* hw_regs; + HalIOInterruptCB int_cb; } h265d_reg_context_t; typedef struct ScalingList { @@ -267,6 +268,7 @@ MPP_RET hal_h265d_init(void *hal, MppHalCfg *cfg) } reg_cxt->slots = cfg->frame_slots; + reg_cxt->int_cb = cfg->hal_int_cb; mpp_slots_set_prop(reg_cxt->slots, SLOTS_HOR_ALIGN, hevc_ver_align_256_odd); mpp_slots_set_prop(reg_cxt->slots, SLOTS_VER_ALIGN, hevc_ver_align_8); @@ -1455,10 +1457,15 @@ MPP_RET hal_h265d_wait(void *hal, HalTaskInfo *task) #ifdef ANDROID h265d_reg_context_t *reg_cxt = (h265d_reg_context_t *)hal; RK_U8* p = (RK_U8*)reg_cxt->hw_regs; + H265d_REGS_t *hw_regs = ( H265d_REGS_t *)reg_cxt->hw_regs; RK_S32 i; VPU_CMD_TYPE cmd; RK_S32 len; ret = VPUClientWaitResult(reg_cxt->vpu_socket, (RK_U32*)reg_cxt->hw_regs, 68, &cmd, &len); + if ((hw_regs->sw_interrupt.sw_dec_error_sta || + hw_regs->sw_interrupt.sw_dec_empty_sta) && reg_cxt->int_cb.callBack) { + reg_cxt->int_cb.callBack(reg_cxt->int_cb.opaque, NULL); + } for (i = 0; i < 68; i++) { if (i == 1) { h265h_dbg(H265H_DBG_REG, "RK_HEVC_DEC: regs[%02d]=%08X\n", i, *((RK_U32*)p)); diff --git a/mpp/mpp.cpp b/mpp/mpp.cpp index 51cb669b..06852994 100644 --- a/mpp/mpp.cpp +++ b/mpp/mpp.cpp @@ -190,6 +190,7 @@ MPP_RET Mpp::get_frame(MppFrame *frame) mThreadCodec->signal(); if (mOutputBlock) mFrames->wait(); + usleep(1000); } if (mFrames->list_size()) {