[vepu580]: encoder parameter fine tuning

Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Change-Id: I28011fa75dd0e8c7bc17164515272ed3a6d1c6dd
This commit is contained in:
Herman Chen
2022-01-12 20:05:09 +08:00
parent ee3b958d9c
commit b9ae7d8535
4 changed files with 219 additions and 0 deletions

View File

@@ -74,10 +74,15 @@ typedef struct HalH264eVepu580Ctx_t {
/* osd */
Vepu541OsdCfg osd_cfg;
/* finetune */
void *tune;
/* register */
HalVepu580RegSet regs_set;
} HalH264eVepu580Ctx;
#include "hal_h264e_vepu580_tune.c"
#define CHROMA_KLUT_TAB_SIZE (24 * sizeof(RK_U32))
static RK_U32 h264e_klut_weight[30] = {
@@ -141,6 +146,11 @@ static MPP_RET hal_h264e_vepu580_deinit(void *hal)
p->hw_recn = NULL;
}
if (p->tune) {
vepu580_h264e_tune_deinit(p->tune);
p->tune = NULL;
}
hal_h264e_dbg_func("leave %p\n", p);
return MPP_OK;
@@ -188,6 +198,8 @@ static MPP_RET hal_h264e_vepu580_init(void *hal, MppEncHalCfg *cfg)
memcpy(hw->aq_step_p, h264_P_aq_step_default, sizeof(hw->aq_step_p));
}
p->tune = vepu580_h264e_tune_init(p);
DONE:
if (ret)
hal_h264e_vepu580_deinit(hal);
@@ -1665,6 +1677,7 @@ static MPP_RET hal_h264e_vepu580_gen_regs(void *hal, HalEncTask *task)
vepu580_set_osd(&ctx->osd_cfg);
setup_vepu580_l2(&ctx->regs_set, slice, &cfg->hw);
setup_vepu580_ext_line_buf(regs, ctx);
vepu580_h264e_tune_reg_patch(ctx->tune);
mpp_env_get_u32("dump_l1_reg", &dump_l1_reg, 0);
@@ -1885,6 +1898,8 @@ static MPP_RET hal_h264e_vepu580_ret_task(void *hal, HalEncTask *task)
task->hal_ret.data = &ctx->hal_rc_cfg;
task->hal_ret.number = 1;
vepu580_h264e_tune_stat_update(ctx->tune);
hal_h264e_dbg_func("leave %p\n", hal);
return MPP_OK;

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2021 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define HAL_H264E_DBG_CONTENT (0x00000200)
#define hal_h264e_dbg_content(fmt, ...) hal_h264e_dbg_f(HAL_H264E_DBG_CONTENT, fmt, ## __VA_ARGS__)
/*
* Please follow the configuration below:
*
* FRAME_CONTENT_ANALYSIS_NUM >= 5
* MD_WIN_LEN >= 3
* MD_SHOW_LEN == 4
*/
#define FRAME_CONTENT_ANALYSIS_NUM 5
#define MD_WIN_LEN 5
#define MD_SHOW_LEN 4
typedef struct HalH264eVepu580Tune_t {
HalH264eVepu580Ctx *ctx;
/* motion and texture statistic of previous frames */
RK_S32 curr_scene_motion_flag;
// level: 0~2: 0 <--> static, 1 <-->medium motion, 2 <--> large motion
RK_S32 md_madp[MD_WIN_LEN];
// level: 0~2: 0 <--> simple texture, 1 <--> medium texture, 2 <--> complex texture
RK_S32 txtr_madi[FRAME_CONTENT_ANALYSIS_NUM];
RK_S32 md_flag_matrix[MD_SHOW_LEN];
RK_S32 pre_madp[2];
RK_S32 pre_madi[2];
} HalH264eVepu580Tune;
static HalH264eVepu580Tune *vepu580_h264e_tune_init(HalH264eVepu580Ctx *ctx)
{
HalH264eVepu580Tune *tune = mpp_malloc(HalH264eVepu580Tune, 1);
if (NULL == tune)
return tune;
tune->ctx = ctx;
tune->curr_scene_motion_flag = 0;
memset(tune->md_madp, 0, sizeof(tune->md_madp));
memset(tune->txtr_madi, 0, sizeof(tune->txtr_madi));
memset(tune->md_flag_matrix, 0, sizeof(tune->md_flag_matrix));
tune->pre_madi[0] = tune->pre_madi[1] = -1;
tune->pre_madp[0] = tune->pre_madp[1] = -1;
return tune;
}
static void vepu580_h264e_tune_deinit(void *tune)
{
MPP_FREE(tune);
}
static void vepu580_h264e_tune_reg_patch(void *p)
{
HalH264eVepu580Tune *tune = (HalH264eVepu580Tune *)p;
HalH264eVepu580Ctx *ctx = NULL;
if (NULL == tune)
return;
ctx = tune->ctx;
(void)ctx;
/* modify register here */
}
static void vepu580_h264e_tune_stat_update(void *p)
{
HalH264eVepu580Tune *tune = (HalH264eVepu580Tune *)p;
HalH264eVepu580Ctx *ctx = NULL;
if (NULL == tune)
return;
ctx = tune->ctx;
(void)ctx;
/* update statistic info here */
}

View File

@@ -96,8 +96,13 @@ typedef struct H265eV580HalContext_t {
HalBufs dpb_bufs;
RK_S32 fbc_header_len;
RK_U32 title_num;
/* finetune */
void *tune;
} H265eV580HalContext;
#include "hal_h265e_vepu580_tune.c"
#define TILE_BUF_SIZE MPP_ALIGN(128 * 1024, 256)
static RK_U32 klut_weight[24] = {
@@ -1050,6 +1055,8 @@ MPP_RET hal_h265e_v580_init(void *hal, MppEncHalCfg *cfg)
memcpy(hw->aq_step_p, aq_qp_dealt_default, sizeof(hw->aq_step_p));
}
ctx->tune = vepu580_h265e_tune_init(ctx);
hal_h265e_leave();
return ret;
}
@@ -1088,6 +1095,11 @@ MPP_RET hal_h265e_v580_deinit(void *hal)
mpp_dev_deinit(ctx->dev);
ctx->dev = NULL;
}
if (ctx->tune) {
vepu580_h265e_tune_deinit(ctx->tune);
ctx->tune = NULL;
}
hal_h265e_leave();
return MPP_OK;
}
@@ -1781,6 +1793,8 @@ MPP_RET hal_h265e_v580_gen_regs(void *hal, HalEncTask *task)
/*paramet cfg*/
vepu580_h265_global_cfg_set(ctx, regs);
vepu580_h265e_tune_reg_patch(ctx->tune);
ctx->frame_num++;
hal_h265e_leave();
@@ -2252,6 +2266,8 @@ MPP_RET hal_h265e_v580_ret_task(void *hal, HalEncTask *task)
enc_task->hw_length = fb->out_strm_size;
enc_task->length += fb->out_strm_size;
vepu580_h265e_tune_stat_update(ctx->tune);
hal_h265e_dbg_detail("output stream size %d\n", fb->out_strm_size);
hal_h265e_leave();

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2021 Rockchip Electronics Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define HAL_H265E_DBG_CONTENT (0x00200000)
#define hal_h264e_dbg_content(fmt, ...) hal_h264e_dbg_f(HAL_H264E_DBG_CONTENT, fmt, ## __VA_ARGS__)
/*
* Please follow the configuration below:
*
* FRAME_CONTENT_ANALYSIS_NUM >= 5
* MD_WIN_LEN >= 3
* MD_SHOW_LEN == 4
*/
#define FRAME_CONTENT_ANALYSIS_NUM 5
#define MD_WIN_LEN 5
#define MD_SHOW_LEN 4
typedef struct HalH265eVepu580Tune_t {
H265eV580HalContext *ctx;
/* motion and texture statistic of previous frames */
RK_S32 curr_scene_motion_flag;
// level: 0~2: 0 <--> static, 1 <-->medium motion, 2 <--> large motion
RK_S32 md_madp[MD_WIN_LEN];
// level: 0~2: 0 <--> simple texture, 1 <--> medium texture, 2 <--> complex texture
RK_S32 txtr_madi[FRAME_CONTENT_ANALYSIS_NUM];
RK_S32 md_flag_matrix[MD_SHOW_LEN];
RK_S32 pre_madp[2];
RK_S32 pre_madi[2];
} HalH265eVepu580Tune;
static HalH265eVepu580Tune *vepu580_h265e_tune_init(H265eV580HalContext *ctx)
{
HalH265eVepu580Tune *tune = mpp_malloc(HalH265eVepu580Tune, 1);
if (NULL == tune)
return tune;
tune->ctx = ctx;
tune->curr_scene_motion_flag = 0;
memset(tune->md_madp, 0, sizeof(tune->md_madp));
memset(tune->txtr_madi, 0, sizeof(tune->txtr_madi));
memset(tune->md_flag_matrix, 0, sizeof(tune->md_flag_matrix));
tune->pre_madi[0] = tune->pre_madi[1] = -1;
tune->pre_madp[0] = tune->pre_madp[1] = -1;
return tune;
}
static void vepu580_h265e_tune_deinit(void *tune)
{
MPP_FREE(tune);
}
static void vepu580_h265e_tune_reg_patch(void *p)
{
HalH265eVepu580Tune *tune = (HalH265eVepu580Tune *)p;
H265eV580HalContext *ctx = NULL;
if (NULL == tune)
return;
ctx = tune->ctx;
(void)ctx;
/* modify register here */
}
static void vepu580_h265e_tune_stat_update(void *p)
{
HalH265eVepu580Tune *tune = (HalH265eVepu580Tune *)p;
H265eV580HalContext *ctx = NULL;
if (NULL == tune)
return;
ctx = tune->ctx;
(void)ctx;
/* update statistic info here */
}