[enc_cfg]: Update mirror transformation.

1. constraint the range of input argument.
2. add flip config, equal to vertical mirror transformation.
3. add mirroring_ext and rotation_ext to config set, for supporting
GET_CFG control.

Signed-off-by: xueman.ruan <xueman.ruan@rock-chips.com>
Change-Id: I01c0b9187a18851354e81b5f08afc6dcaaba8365
This commit is contained in:
xueman.ruan
2022-09-16 15:20:23 +08:00
committed by Herman Chen
parent 8d905fe82e
commit 09de35e9b5
6 changed files with 104 additions and 15 deletions

View File

@@ -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:

View File

@@ -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 ;

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -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);