refactor[hal_jpegd]: init devices at hal_jpegd_api

Calling mpp_dev_init at hal_jpegd_api before calling each device init
function. Client type can be and should be specified before calling each
device init function. There is no need to re-initialize MppDev when
PP should be used. This fix also avoid lossing format information after
re-initialize MppDev, which result in extra_info storing at higher bits of
bitstream base address register instead of appending after registers datas.

Change-Id: I2edd8f91f29d04a151c94e9d342f153f42118eb1
Signed-off-by: Johnson Ding <johnson.ding@rock-chips.com>
This commit is contained in:
Johnson Ding
2024-05-11 18:25:51 +08:00
committed by dinghaiqiang
parent 45f2fcbcf0
commit be45576b34
7 changed files with 20 additions and 82 deletions

View File

@@ -74,6 +74,7 @@ static MPP_RET hal_jpegd_deinit(void *hal)
static MPP_RET hal_jpegd_init(void *hal, MppHalCfg *cfg)
{
MPP_RET ret = MPP_ERR_UNKNOW;
JpegdHalCtx *self = (JpegdHalCtx *)hal;
MppHalApi *p_api = NULL;
MppClientType client_type = VPU_CLIENT_BUTT;
@@ -155,20 +156,24 @@ static MPP_RET hal_jpegd_init(void *hal, MppHalCfg *cfg)
} break;
}
{
// report hw_info to parser
const MppSocInfo *info = mpp_get_soc_info();
RK_U32 i;
for (i = 0; i < MPP_ARRAY_ELEMS(info->dec_caps); i++) {
if (info->dec_caps[i] && info->dec_caps[i]->type == client_type) {
cfg->hw_info = info->dec_caps[i];
break;
}
}
ret = mpp_dev_init(&cfg->dev, client_type);
if (ret) {
mpp_err("mpp_dev_init failed ret: %d\n", ret);
goto __RETURN;
}
return p_api->init(hal, cfg);
cfg->hw_info = mpp_get_dec_hw_info_by_client_type(client_type);
self->hw_info = cfg->hw_info;
self->dev = cfg->dev;
ret = p_api->init(hal, cfg);
if (ret) {
mpp_err("init device with client_type %d failed!\n", client_type);
mpp_dev_deinit(cfg->dev);
}
__RETURN:
return ret;
}
const MppHalApi hal_api_jpegd = {

View File

@@ -38,8 +38,6 @@ typedef struct JpegdHalCtx {
MppBufSlots packet_slots;
MppBufSlots frame_slots;
MppDev dev;
MppClientType dev_type;
RK_U32 codec_type;
void *regs;
MppBufferGroup group;
MppBuffer pTableBase;
@@ -58,7 +56,7 @@ typedef struct JpegdHalCtx {
RK_U32 have_pp;
PPInfo pp_info;
RK_U32 hw_id;
const MppDecHwCap *hw_info;
} JpegdHalCtx;
#endif /* __HAL_JPEGD_COMMON_H__ */

View File

@@ -432,22 +432,12 @@ void jpegd_write_qp_ac_dc_table(JpegdHalCtx *ctx,
return;
}
void jpegd_check_have_pp(JpegdHalCtx *ctx)
{
ctx->codec_type = mpp_get_vcodec_type();
ctx->have_pp = ((ctx->dev_type == VPU_CLIENT_VDPU1) &&
(ctx->codec_type & (1 << VPU_CLIENT_VDPU1_PP))) ||
((ctx->dev_type == VPU_CLIENT_VDPU2) &&
(ctx->codec_type & (1 << VPU_CLIENT_VDPU2_PP)));
}
MPP_RET jpegd_setup_output_fmt(JpegdHalCtx *ctx, JpegdSyntax *s, RK_S32 output)
{
jpegd_dbg_func("enter\n");
RK_U32 pp_in_fmt = 0;
RK_U32 stride = 0;
PPInfo *pp_info = &ctx->pp_info;
MppClientType dev_type = ctx->dev_type;
MppFrame frm = NULL;
MPP_RET ret = MPP_OK;
@@ -513,40 +503,10 @@ MPP_RET jpegd_setup_output_fmt(JpegdHalCtx *ctx, JpegdSyntax *s, RK_S32 output)
jpegd_dbg_hal("Post Process! pp_in_fmt:%d, pp_out_fmt:%d",
pp_in_fmt, pp_info->pp_out_fmt);
/* check and switch to dev with pp */
if (ctx->dev_type == VPU_CLIENT_VDPU1)
dev_type = VPU_CLIENT_VDPU1_PP;
else if (ctx->dev_type == VPU_CLIENT_VDPU2)
dev_type = VPU_CLIENT_VDPU2_PP;
} else {
/* keep original output format */
ctx->output_fmt = s->output_fmt;
pp_info->pp_enable = 0;
/* check and switch to dev without pp */
if (ctx->dev_type == VPU_CLIENT_VDPU1_PP)
dev_type = VPU_CLIENT_VDPU1;
else if (ctx->dev_type == VPU_CLIENT_VDPU2_PP)
dev_type = VPU_CLIENT_VDPU2;
}
mpp_assert(ctx->dev);
if (ctx->dev_type != dev_type && ctx->dev) {
MppDev dev = NULL;
ret = mpp_dev_init(&dev, dev_type);
if (ret) {
mpp_err_f("dev type %x -> %x switch failed ret %d\n",
ctx->dev_type, dev_type, ret);
return ret;
}
mpp_dev_deinit(ctx->dev);
ctx->dev = dev;
ctx->dev_type = dev_type;
jpegd_dbg_hal("mpp_dev_init success.\n");
}
mpp_buf_slot_get_prop(ctx->frame_slots, output,

View File

@@ -75,7 +75,6 @@ RK_U32 jpegd_vdpu_tail_0xFF_patch(MppBuffer stream, RK_U32 length);
void jpegd_write_qp_ac_dc_table(JpegdHalCtx *ctx,
JpegdSyntax*syntax);
void jpegd_check_have_pp(JpegdHalCtx *ctx);
MPP_RET jpegd_setup_output_fmt(JpegdHalCtx *ctx, JpegdSyntax *syntax,
RK_S32 output);

View File

@@ -255,15 +255,6 @@ MPP_RET hal_jpegd_rkv_init(void *hal, MppHalCfg *cfg)
ctx->dec_cb = cfg->dec_cb;
ctx->packet_slots = cfg->packet_slots;
ctx->frame_slots = cfg->frame_slots;
ctx->dev_type = VPU_CLIENT_JPEG_DEC;
ret = mpp_dev_init(&ctx->dev, ctx->dev_type);
if (ret) {
mpp_err("mpp_dev_init failed. ret: %d\n", ret);
return ret;
}
ctx->hw_id = mpp_get_client_hw_id(VPU_CLIENT_JPEG_DEC);
/* allocate regs buffer */
if (ctx->regs == NULL) {

View File

@@ -740,14 +740,7 @@ MPP_RET hal_jpegd_vdpu1_init(void *hal, MppHalCfg *cfg)
JpegHalCtx->dec_cb = cfg->dec_cb;
JpegHalCtx->packet_slots = cfg->packet_slots;
JpegHalCtx->frame_slots = cfg->frame_slots;
JpegHalCtx->dev_type = VPU_CLIENT_VDPU1;
ret = mpp_dev_init(&JpegHalCtx->dev, JpegHalCtx->dev_type);
if (ret) {
mpp_err_f("mpp_dev_init failed. ret: %d\n", ret);
return ret;
}
cfg->dev = JpegHalCtx->dev;
JpegHalCtx->have_pp = cfg->hw_info->cap_jpg_pp_out;
/* allocate regs buffer */
if (JpegHalCtx->regs == NULL) {
@@ -784,7 +777,6 @@ MPP_RET hal_jpegd_vdpu1_init(void *hal, MppHalCfg *cfg)
pp_info->pp_enable = 0;
pp_info->pp_in_fmt = PP_IN_FORMAT_YUV420SEMI;
pp_info->pp_out_fmt = PP_OUT_FORMAT_YUV420INTERLAVE;
jpegd_check_have_pp(JpegHalCtx);
JpegHalCtx->output_fmt = MPP_FMT_YUV420SP;
JpegHalCtx->set_output_fmt_flag = 0;

View File

@@ -729,14 +729,8 @@ MPP_RET hal_jpegd_vdpu2_init(void *hal, MppHalCfg *cfg)
JpegHalCtx->dec_cb = cfg->dec_cb;
JpegHalCtx->packet_slots = cfg->packet_slots;
JpegHalCtx->frame_slots = cfg->frame_slots;
JpegHalCtx->dev_type = VPU_CLIENT_VDPU2;
JpegHalCtx->have_pp = cfg->hw_info->cap_jpg_pp_out;
ret = mpp_dev_init(&JpegHalCtx->dev, JpegHalCtx->dev_type);
if (ret) {
mpp_err_f("mpp_dev_init failed. ret: %d\n", ret);
return ret;
}
cfg->dev = JpegHalCtx->dev;
//init regs
JpegdIocRegInfo *info = NULL;
info = mpp_calloc(JpegdIocRegInfo, 1);
@@ -769,7 +763,6 @@ MPP_RET hal_jpegd_vdpu2_init(void *hal, MppHalCfg *cfg)
pp_info->pp_enable = 0;
pp_info->pp_in_fmt = PP_IN_FORMAT_YUV420SEMI;
pp_info->pp_out_fmt = PP_OUT_FORMAT_YUV420INTERLAVE;
jpegd_check_have_pp(JpegHalCtx);
JpegHalCtx->output_fmt = MPP_FMT_YUV420SP;
JpegHalCtx->set_output_fmt_flag = 0;