From 5b940db9585b752f23da345c65ea796bbe6ab3cf Mon Sep 17 00:00:00 2001 From: Yandong Lin Date: Mon, 30 Dec 2024 21:51:13 +0800 Subject: [PATCH] feat[mpi_enc_test]: Support enc for kmpp flow Add param -kmpp to enable kmpp. Change-Id: Id0e0dd64cca8f4da29fa7048f22beb3918162bd6 Signed-off-by: Yandong Lin --- test/mpi_enc_test.c | 45 +++++++++++++++++++++++++++++++++++++++++++ utils/mpi_enc_utils.c | 22 ++++++++++++++++++++- utils/mpi_enc_utils.h | 1 + 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/test/mpi_enc_test.c b/test/mpi_enc_test.c index 2d4228b8..a129ab2d 100644 --- a/test/mpi_enc_test.c +++ b/test/mpi_enc_test.c @@ -23,6 +23,7 @@ #include #include #include "rk_mpi.h" +#include "rk_venc_kcfg.h" #include "mpp_env.h" #include "mpp_mem.h" @@ -99,6 +100,8 @@ typedef struct { CamSource *cam_ctx; MppEncRoiCtx roi_ctx; + MppVencKcfg init_kcfg; + // resources size_t header_size; size_t frame_size; @@ -199,6 +202,43 @@ static RK_S32 get_mdinfo_size(MpiEncTestData *p, MppCodingType type) return md_size; } +static MPP_RET kmpp_cfg_init(MpiEncMultiCtxInfo *info) +{ + MppVencKcfg init_kcfg = NULL; + MpiEncTestData *p = &info->ctx; + MPP_RET ret = MPP_NOK; + + mpp_venc_kcfg_init(&init_kcfg, MPP_VENC_KCFG_TYPE_INIT); + if (!init_kcfg) { + mpp_err_f("kmpp_venc_init_cfg_init failed\n"); + return ret; + } + + p->init_kcfg = init_kcfg; + + mpp_venc_kcfg_set_u32(init_kcfg, "type", MPP_CTX_ENC); + mpp_venc_kcfg_set_u32(init_kcfg, "coding", p->type); + mpp_venc_kcfg_set_s32(init_kcfg, "chan_id", 0); + mpp_venc_kcfg_set_s32(init_kcfg, "online", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "buf_size", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "max_strm_cnt", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "shared_buf_en", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "smart_en", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "max_width", p->width); + mpp_venc_kcfg_set_u32(init_kcfg, "max_height", p->height); + mpp_venc_kcfg_set_u32(init_kcfg, "max_lt_cnt", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "qpmap_en", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "chan_dup", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "tmvp_enable", 0); + mpp_venc_kcfg_set_u32(init_kcfg, "only_smartp", 0); + + ret = p->mpi->control(p->ctx, MPP_SET_VENC_INIT_KCFG, init_kcfg); + if (ret) + mpp_err_f("mpi control set kmpp enc cfg failed ret %d\n", ret); + + return ret; +} + MPP_RET test_ctx_init(MpiEncMultiCtxInfo *info) { MpiEncTestArgs *cmd = info->cmd; @@ -1049,6 +1089,9 @@ void *enc_test(void *arg) goto MPP_TEST_OUT; } + if (cmd->kmpp_en) + kmpp_cfg_init(info); + ret = mpp_init(p->ctx, MPP_CTX_ENC, p->type); if (ret) { mpp_err("mpp_init failed ret %d\n", ret); @@ -1134,6 +1177,8 @@ MPP_TEST_OUT: mpp_enc_roi_deinit(p->roi_ctx); p->roi_ctx = NULL; } + if (p->init_kcfg) + mpp_venc_kcfg_deinit(p->init_kcfg); test_ctx_deinit(p); diff --git a/utils/mpi_enc_utils.c b/utils/mpi_enc_utils.c index af5e8ea1..e308c1c3 100644 --- a/utils/mpi_enc_utils.c +++ b/utils/mpi_enc_utils.c @@ -652,6 +652,25 @@ RK_S32 mpi_enc_opt_bias_p(void *ctx, const char *next) return 0; } +RK_S32 mpi_enc_opt_kmpp(void *ctx, const char *next) +{ + MpiEncTestArgs *cmd = (MpiEncTestArgs *)ctx; + + if (next) { + cmd->kmpp_en = atoi(next); + if (cmd->kmpp_en) { + if (access("/dev/vcodec", F_OK | R_OK | W_OK)) { + mpp_err("failed to access /dev/vcodec, check kmpp devices\n"); + return -1; + } + } + return 1; + } + + mpp_err("invalid kmpp enable\n"); + return 0; +} + static MppOptInfo enc_opts[] = { {"i", "input_file", "input frame file", mpi_enc_opt_i}, {"o", "output_file", "output encoded bitstream file", mpi_enc_opt_o}, @@ -686,7 +705,8 @@ static MppOptInfo enc_opts[] = { {"sao_p", "sao_str_p", "sao_str_p, 0:off 1 2 3", mpi_enc_opt_sao_p}, {"bc", "bitrate container", "rc_container, 0:off 1:weak 2:strong", mpi_enc_opt_bc}, {"ibias", "bias i", "bias_i", mpi_enc_opt_bias_i}, - {"pbias", "bias p", "bias_p", mpi_enc_opt_bias_p} + {"pbias", "bias p", "bias_p", mpi_enc_opt_bias_p}, + {"kmpp", "kmpp path enable", "kmpp path enable", mpi_enc_opt_kmpp} }; static RK_U32 enc_opt_cnt = MPP_ARRAY_ELEMS(enc_opts); diff --git a/utils/mpi_enc_utils.h b/utils/mpi_enc_utils.h index 7169bc37..6eeb118d 100644 --- a/utils/mpi_enc_utils.h +++ b/utils/mpi_enc_utils.h @@ -103,6 +103,7 @@ typedef struct MpiEncTestArgs_t { RK_U32 psnr_en; RK_U32 ssim_en; char *file_slt; + RK_U32 kmpp_en; } MpiEncTestArgs; #ifdef __cplusplus