diff --git a/inc/rk_venc_cmd.h b/inc/rk_venc_cmd.h index e6e39d91..94026b07 100644 --- a/inc/rk_venc_cmd.h +++ b/inc/rk_venc_cmd.h @@ -480,8 +480,9 @@ typedef enum MppEncPrepCfgChange_e { MPP_ENC_PREP_CFG_CHANGE_INPUT = (1 << 0), /* change on input config */ MPP_ENC_PREP_CFG_CHANGE_FORMAT = (1 << 2), /* change on format */ /* transform parameter */ - MPP_ENC_PREP_CFG_CHANGE_ROTATION = (1 << 4), /* change on ration */ + MPP_ENC_PREP_CFG_CHANGE_ROTATION = (1 << 4), /* change on rotation */ MPP_ENC_PREP_CFG_CHANGE_MIRRORING = (1 << 5), /* change on mirroring */ + MPP_ENC_PREP_CFG_CHANGE_FLIP = (1 << 6), /* change on flip */ /* enhancement parameter */ MPP_ENC_PREP_CFG_CHANGE_DENOISE = (1 << 8), /* change on denoise */ MPP_ENC_PREP_CFG_CHANGE_SHARPEN = (1 << 9), /* change on denoise */ @@ -550,15 +551,24 @@ typedef struct MppEncPrepCfg_t { MppFrameColorTransferCharacteristic colortrc; MppFrameColorRange range; + /* suffix ext means the user set config externally */ MppEncRotationCfg rotation; + MppEncRotationCfg rotation_ext; /* * input frame mirroring parameter * 0 - disable mirroring * 1 - horizontal mirroring - * 2 - vertical mirroring */ RK_S32 mirroring; + RK_S32 mirroring_ext; + + /* + * input frame flip parameter + * 0 - disable flip + * 1 - flip, vertical mirror transformation + */ + RK_S32 flip; /* * TODO: diff --git a/mpp/base/mpp_enc_cfg.cpp b/mpp/base/mpp_enc_cfg.cpp index bd357cb5..7e839dc1 100644 --- a/mpp/base/mpp_enc_cfg.cpp +++ b/mpp/base/mpp_enc_cfg.cpp @@ -173,8 +173,9 @@ public: ENTRY(prep, colortrc, S32, MppFrameColorTransferCharacteristic, MPP_ENC_PREP_CFG_CHANGE_COLOR_TRC, prep, colortrc) \ ENTRY(prep, colorrange, S32, MppFrameColorRange,MPP_ENC_PREP_CFG_CHANGE_COLOR_RANGE, prep, range) \ ENTRY(prep, range, S32, MppFrameColorRange,MPP_ENC_PREP_CFG_CHANGE_COLOR_RANGE, prep, range) \ - ENTRY(prep, rotation, S32, MppEncRotationCfg, MPP_ENC_PREP_CFG_CHANGE_ROTATION, prep, rotation) \ - ENTRY(prep, mirroring, S32, RK_S32, MPP_ENC_PREP_CFG_CHANGE_MIRRORING, prep, mirroring) \ + ENTRY(prep, rotation, S32, MppEncRotationCfg, MPP_ENC_PREP_CFG_CHANGE_ROTATION, prep, rotation_ext) \ + ENTRY(prep, mirroring, S32, RK_S32, MPP_ENC_PREP_CFG_CHANGE_MIRRORING, prep, mirroring_ext) \ + ENTRY(prep, flip, S32, RK_S32, MPP_ENC_PREP_CFG_CHANGE_FLIP, prep, flip) \ /* codec coding config */ \ ENTRY(codec, type, S32, MppCodingType, 0, codec, coding) \ /* h264 config */ \ @@ -359,7 +360,7 @@ MppEncCfgService::MppEncCfgService() : MPP_RET ret; RK_S32 i; - ret = mpp_trie_init(&trie, 1639, cfg_cnt); + ret = mpp_trie_init(&trie, 1644, cfg_cnt); if (ret) { mpp_err_f("failed to init enc cfg set trie\n"); return ; diff --git a/mpp/codec/enc/h264/h264e_api_v2.c b/mpp/codec/enc/h264/h264e_api_v2.c index fa381926..38411f46 100644 --- a/mpp/codec/enc/h264/h264e_api_v2.c +++ b/mpp/codec/enc/h264/h264e_api_v2.c @@ -134,12 +134,15 @@ static void init_h264e_cfg_set(MppEncCfgSet *cfg, MppClientType type) prep->ver_stride = 720; prep->format = MPP_FMT_YUV420SP; prep->rotation = MPP_ENC_ROT_0; + prep->rotation_ext = MPP_ENC_ROT_0; prep->color = MPP_FRAME_SPC_UNSPECIFIED; prep->colorprim = MPP_FRAME_PRI_UNSPECIFIED; prep->colortrc = MPP_FRAME_TRC_UNSPECIFIED; prep->range = MPP_FRAME_RANGE_UNSPECIFIED; prep->mirroring = 0; + prep->mirroring_ext = 0; prep->denoise = 0; + prep->flip = 0; /* * default rc_cfg: @@ -236,6 +239,8 @@ static MPP_RET h264e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) mpp_assert(change); if (change) { + RK_S32 mirroring; + RK_S32 rotation; MppEncPrepCfg bak = *dst; if (change & MPP_ENC_PREP_CFG_CHANGE_FORMAT) @@ -254,10 +259,13 @@ static MPP_RET h264e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) dst->colortrc = src->colortrc; if (change & MPP_ENC_PREP_CFG_CHANGE_ROTATION) - dst->rotation = src->rotation; + dst->rotation_ext = src->rotation_ext; if (change & MPP_ENC_PREP_CFG_CHANGE_MIRRORING) - dst->mirroring = src->mirroring; + dst->mirroring_ext = src->mirroring_ext; + + if (change & MPP_ENC_PREP_CFG_CHANGE_FLIP) + dst->flip = src->flip; if (change & MPP_ENC_PREP_CFG_CHANGE_DENOISE) dst->denoise = src->denoise; @@ -265,6 +273,30 @@ static MPP_RET h264e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) if (change & MPP_ENC_PREP_CFG_CHANGE_SHARPEN) dst->sharpen = src->sharpen; + // parameter checking + if (dst->rotation_ext >= MPP_ENC_ROT_BUTT || dst->rotation_ext < 0 || + dst->mirroring_ext < 0 || dst->flip < 0) { + mpp_err("invalid trans: rotation %d, mirroring %d\n", dst->rotation_ext, dst->mirroring_ext); + ret = MPP_ERR_VALUE; + } + + /* For unifying the encoder's params used by CFG_SET and CFG_GET command, + * there is distinction between user's set and set in hal. + * User can externally set rotation_ext, mirroring_ext and flip, + * which should be transformed to mirroring and rotation in hal. + */ + mirroring = dst->mirroring_ext; + rotation = dst->rotation_ext; + + if (dst->flip) { + mirroring = !mirroring; + rotation += MPP_ENC_ROT_180; + rotation &= MPP_ENC_ROT_270; + } + + dst->mirroring = mirroring; + dst->rotation = rotation; + if ((change & MPP_ENC_PREP_CFG_CHANGE_INPUT) || (change & MPP_ENC_PREP_CFG_CHANGE_ROTATION)) { if (dst->rotation == MPP_ENC_ROT_90 || dst->rotation == MPP_ENC_ROT_270) { @@ -295,11 +327,11 @@ static MPP_RET h264e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) } } - if (MPP_FRAME_FMT_IS_FBC(dst->format) && (dst->mirroring || dst->rotation)) { + if (MPP_FRAME_FMT_IS_FBC(dst->format) && (dst->mirroring || dst->rotation || dst->flip)) { // rk3588 rkvenc support fbc with rotation if (!strstr(mpp_get_soc_name(), "rk3588")) { - mpp_err("invalid cfg fbc data no support mirror %d or rotaion", - dst->mirroring, dst->rotation); + mpp_err("invalid cfg fbc data no support mirror %d, rotation %d, or flip %d", + dst->mirroring, dst->rotation, dst->flip); ret = MPP_ERR_VALUE; } } diff --git a/mpp/codec/enc/h265/h265e_api.c b/mpp/codec/enc/h265/h265e_api.c index 66bfd744..34d7d3a0 100644 --- a/mpp/codec/enc/h265/h265e_api.c +++ b/mpp/codec/enc/h265/h265e_api.c @@ -119,8 +119,11 @@ static MPP_RET h265e_init(void *ctx, EncImplCfg *ctrlCfg) prep->colortrc = MPP_FRAME_TRC_UNSPECIFIED; prep->range = MPP_FRAME_RANGE_UNSPECIFIED; prep->rotation = MPP_ENC_ROT_0; + prep->rotation_ext = MPP_ENC_ROT_0; prep->mirroring = 0; + prep->mirroring_ext = 0; prep->denoise = 0; + prep->flip = 0; /* * default rc_cfg: @@ -307,6 +310,8 @@ static MPP_RET h265e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) { MPP_RET ret = MPP_OK; RK_U32 change = src->change; + RK_S32 mirroring; + RK_S32 rotation; mpp_assert(change); @@ -328,10 +333,13 @@ static MPP_RET h265e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) dst->colortrc = src->colortrc; if (change & MPP_ENC_PREP_CFG_CHANGE_ROTATION) - dst->rotation = src->rotation; + dst->rotation_ext = src->rotation_ext; if (change & MPP_ENC_PREP_CFG_CHANGE_MIRRORING) - dst->mirroring = src->mirroring; + dst->mirroring_ext = src->mirroring_ext; + + if (change & MPP_ENC_PREP_CFG_CHANGE_FLIP) + dst->flip = src->flip; if (change & MPP_ENC_PREP_CFG_CHANGE_DENOISE) dst->denoise = src->denoise; @@ -339,6 +347,30 @@ static MPP_RET h265e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) if (change & MPP_ENC_PREP_CFG_CHANGE_SHARPEN) dst->sharpen = src->sharpen; + // parameter checking + if (dst->rotation_ext >= MPP_ENC_ROT_BUTT || dst->rotation_ext < 0 || + dst->mirroring_ext < 0 || dst->flip < 0) { + mpp_err("invalid trans: rotation %d, mirroring %d\n", dst->rotation_ext, dst->mirroring_ext); + ret = MPP_ERR_VALUE; + } + + /* For unifying the encoder's params used by CFG_SET and CFG_GET command, + * there is distinction between user's set and set in hal. + * User can externally set rotation_ext, mirroring_ext and flip, + * which should be transformed to mirroring and rotation in hal. + */ + mirroring = dst->mirroring_ext; + rotation = dst->rotation_ext; + + if (dst->flip) { + mirroring = !mirroring; + rotation += MPP_ENC_ROT_180; + rotation &= MPP_ENC_ROT_270; + } + + dst->mirroring = mirroring; + dst->rotation = rotation; + if ((change & MPP_ENC_PREP_CFG_CHANGE_INPUT) || (change & MPP_ENC_PREP_CFG_CHANGE_ROTATION)) { if (dst->rotation == MPP_ENC_ROT_90 || dst->rotation == MPP_ENC_ROT_270) { @@ -369,11 +401,11 @@ static MPP_RET h265e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) } } - if (MPP_FRAME_FMT_IS_FBC(dst->format) && (dst->mirroring || dst->rotation)) { + if (MPP_FRAME_FMT_IS_FBC(dst->format) && (dst->mirroring || dst->rotation || dst->flip)) { // rk3588 rkvenc support fbc with rotation if (!strstr(mpp_get_soc_name(), "rk3588")) { - mpp_err("invalid cfg fbc data no support mirror %d or rotaion", - dst->mirroring, dst->rotation); + mpp_err("invalid cfg fbc data no support mirror %d, rotation %d, or flip %d", + dst->mirroring, dst->rotation, dst->flip); ret = MPP_ERR_VALUE; } } @@ -395,6 +427,7 @@ static MPP_RET h265e_proc_prep_cfg(MppEncPrepCfg *dst, MppEncPrepCfg *src) dst->width, dst->height, dst->hor_stride, dst->ver_stride); } + return ret; } diff --git a/mpp/hal/rkenc/h265e/hal_h265e_vepu541.c b/mpp/hal/rkenc/h265e/hal_h265e_vepu541.c index ff58320c..91a8f411 100644 --- a/mpp/hal/rkenc/h265e/hal_h265e_vepu541.c +++ b/mpp/hal/rkenc/h265e/hal_h265e_vepu541.c @@ -1005,7 +1005,9 @@ static MPP_RET vepu541_h265_set_pp_regs(H265eV541RegSet *regs, VepuFmtCfg *fmt, regs->src_fmt.alpha_swap = fmt->alpha_swap; regs->src_fmt.rbuv_swap = fmt->rbuv_swap; regs->src_fmt.src_range = fmt->src_range; + regs->src_proc.src_mirr = prep_cfg->mirroring > 0; regs->src_proc.src_rot = prep_cfg->rotation; + if (MPP_FRAME_FMT_IS_FBC(prep_cfg->format)) { stridey = mpp_frame_get_fbc_hdr_stride(task->frame); if (!stridey) diff --git a/test/mpi_enc_test.c b/test/mpi_enc_test.c index 93622f95..8f5fd9c8 100644 --- a/test/mpi_enc_test.c +++ b/test/mpi_enc_test.c @@ -292,6 +292,9 @@ MPP_RET test_mpp_enc_cfg_setup(MpiEncMultiCtxInfo *info) MppEncCfg cfg = p->cfg; RK_U32 quiet = cmd->quiet; MPP_RET ret; + RK_U32 rotation; + RK_U32 mirroring; + RK_U32 flip; /* setup default parameter */ if (p->fps_in_den == 0) @@ -456,6 +459,14 @@ MPP_RET test_mpp_enc_cfg_setup(MpiEncMultiCtxInfo *info) mpp_enc_cfg_set_s32(cfg, "split:out", p->split_out); } + mpp_env_get_u32("mirroring", &mirroring, 0); + mpp_env_get_u32("rotation", &rotation, 0); + mpp_env_get_u32("flip", &flip, 0); + + mpp_enc_cfg_set_s32(cfg, "prep:mirroring", mirroring); + mpp_enc_cfg_set_s32(cfg, "prep:rotation", rotation); + mpp_enc_cfg_set_s32(cfg, "prep:flip", flip); + ret = mpi->control(ctx, MPP_ENC_SET_CFG, cfg); if (ret) { mpp_err("mpi control enc set cfg failed ret %d\n", ret);