[mpp_enc]: Add motion dection output path

Signed-off-by: toby.zhang <toby.zhang@rock-chips.com>
Change-Id: Ie0ee26af50cef7f883cb3cd2c50f9121e4f87079
This commit is contained in:
toby.zhang
2022-03-02 08:36:51 +08:00
committed by Herman Chen
parent 881f05c7cf
commit b3edf0d22c
9 changed files with 44 additions and 13 deletions

View File

@@ -85,6 +85,7 @@ typedef struct MppEncImpl_t {
RK_S64 task_pts;
MppBuffer frm_buf;
MppBuffer pkt_buf;
MppBuffer md_info;
// internal status and protection
Mutex lock;

View File

@@ -1580,7 +1580,7 @@ static MPP_RET try_get_enc_task(MppEncImpl *enc, EncTask *task)
*/
mpp_task_meta_get_frame (enc->task_in, KEY_INPUT_FRAME, &enc->frame);
mpp_task_meta_get_packet(enc->task_in, KEY_OUTPUT_PACKET, &enc->packet);
mpp_task_meta_get_buffer(enc->task_in, KEY_MOTION_INFO, &hal_task->mv_info);
mpp_task_meta_get_buffer(enc->task_in, KEY_MOTION_INFO, &enc->md_info);
enc_dbg_detail("task dequeue done frm %p pkt %p\n", enc->frame, enc->packet);
@@ -1609,6 +1609,7 @@ static MPP_RET try_get_enc_task(MppEncImpl *enc, EncTask *task)
hal_task->input = enc->frm_buf;
hal_task->packet = enc->packet;
hal_task->output = enc->pkt_buf;
hal_task->md_info = enc->md_info;
hal_task->stopwatch = stopwatch;
frm->seq_idx = task->seq_idx++;
@@ -1974,8 +1975,8 @@ TASK_DONE:
{
MppMeta meta = mpp_packet_get_meta(enc->packet);
if (hal_task->mv_info)
mpp_meta_set_buffer(meta, KEY_MOTION_INFO, hal_task->mv_info);
if (hal_task->md_info)
mpp_meta_set_buffer(meta, KEY_MOTION_INFO, hal_task->md_info);
mpp_meta_set_s32(meta, KEY_OUTPUT_INTRA, frm->is_intra);
if (rc_task->info.quality_real)

View File

@@ -84,8 +84,8 @@ typedef struct HalEncTask_t {
// task stopwatch for timing
MppStopwatch stopwatch;
// current mv info output buffer (not used)
MppBuffer mv_info;
// current md info output buffer
MppBuffer md_info;
// low delay mode part output information
RK_U32 part_first;

View File

@@ -1450,7 +1450,7 @@ static MPP_RET hal_h264e_vepu541_gen_regs(void *hal, HalEncTask *task)
setup_vepu541_recn_refr(regs, ctx->dev, ctx->frms, ctx->hw_recn,
ctx->pixel_buf_fbc_hdr_size);
regs->reg082.meiw_addr = task->mv_info ? mpp_buffer_get_fd(task->mv_info) : 0;
regs->reg082.meiw_addr = task->md_info ? mpp_buffer_get_fd(task->md_info) : 0;
regs->reg068.pic_ofst_y = mpp_frame_get_offset_y(task->frame);
regs->reg068.pic_ofst_x = mpp_frame_get_offset_x(task->frame);

View File

@@ -1807,7 +1807,7 @@ static MPP_RET hal_h264e_vepu580_gen_regs(void *hal, HalEncTask *task)
setup_vepu580_roi(regs, ctx);
setup_vepu580_recn_refr(ctx, regs);
regs->reg_base.meiw_addr = task->mv_info ? mpp_buffer_get_fd(task->mv_info) : 0;
regs->reg_base.meiw_addr = task->md_info ? mpp_buffer_get_fd(task->md_info) : 0;
regs->reg_base.pic_ofst.pic_ofst_y = mpp_frame_get_offset_y(task->frame);
regs->reg_base.pic_ofst.pic_ofst_x = mpp_frame_get_offset_x(task->frame);

View File

@@ -1310,7 +1310,7 @@ void vepu54x_h265_set_hw_address(H265eV541HalContext *ctx, H265eV541RegSet *regs
{
HalEncTask *enc_task = task;
HalBuf *recon_buf, *ref_buf;
MppBuffer mv_info_buf = enc_task->mv_info;
MppBuffer md_info_buf = enc_task->md_info;
H265eSyntax_new *syn = (H265eSyntax_new *)enc_task->syntax.data;
MppDevRegOffsetCfg cfg_fd;
@@ -1360,9 +1360,9 @@ void vepu54x_h265_set_hw_address(H265eV541HalContext *ctx, H265eV541RegSet *regs
regs->lpfr_addr_hevc = mpp_buffer_get_fd(ctx->hw_tile_buf[1]);
}
if (mv_info_buf) {
if (md_info_buf) {
regs->enc_pic.mei_stor = 1;
regs->meiw_addr_hevc = mpp_buffer_get_fd(mv_info_buf);
regs->meiw_addr_hevc = mpp_buffer_get_fd(md_info_buf);
} else {
regs->enc_pic.mei_stor = 0;
regs->meiw_addr_hevc = 0;

View File

@@ -1840,7 +1840,7 @@ void vepu580_h265_set_hw_address(H265eV580HalContext *ctx, hevc_vepu580_base *re
{
HalEncTask *enc_task = task;
HalBuf *recon_buf, *ref_buf;
MppBuffer mv_info_buf = enc_task->mv_info;
MppBuffer md_info_buf = enc_task->md_info;
H265eSyntax_new *syn = (H265eSyntax_new *)enc_task->syntax.data;
hal_h265e_enter();
@@ -1889,9 +1889,9 @@ void vepu580_h265_set_hw_address(H265eV580HalContext *ctx, hevc_vepu580_base *re
regs->reg0177_lpfr_addr = mpp_buffer_get_fd(ctx->hw_tile_buf[1]);
}
if (mv_info_buf) {
if (md_info_buf) {
regs->reg0192_enc_pic.mei_stor = 1;
regs->reg0171_meiw_addr = mpp_buffer_get_fd(mv_info_buf);
regs->reg0171_meiw_addr = mpp_buffer_get_fd(md_info_buf);
} else {
regs->reg0192_enc_pic.mei_stor = 0;
regs->reg0171_meiw_addr = 0;

View File

@@ -567,6 +567,7 @@ MPP_RET Mpp::put_frame(MppFrame frame)
if (mpp_frame_has_meta(frame)) {
MppMeta meta = mpp_frame_get_meta(frame);
MppPacket packet = NULL;
MppBuffer md_info_buf = NULL;
mpp_meta_get_packet(meta, KEY_OUTPUT_PACKET, &packet);
if (packet) {
@@ -576,6 +577,15 @@ MPP_RET Mpp::put_frame(MppFrame frame)
goto RET;
}
}
mpp_meta_get_buffer(meta, KEY_MOTION_INFO, &md_info_buf);
if (md_info_buf) {
ret = mpp_task_meta_set_buffer(mInputTask, KEY_MOTION_INFO, md_info_buf);
if (ret) {
mpp_log_f("set output motion dection info ret %d\n", ret);
goto RET;
}
}
}
// dump input

View File

@@ -71,6 +71,7 @@ typedef struct {
MppBufferGroup buf_grp;
MppBuffer frm_buf;
MppBuffer pkt_buf;
MppBuffer md_info;
MppEncSeiMode sei_mode;
MppEncHeaderMode header_mode;
@@ -88,6 +89,7 @@ typedef struct {
// resources
size_t header_size;
size_t frame_size;
size_t mdinfo_size;
/* NOTE: packet buffer may overflow */
size_t packet_size;
@@ -172,6 +174,11 @@ MPP_RET test_ctx_init(MpiEncMultiCtxInfo *info)
p->fps_out_flex = cmd->fps_out_flex;
p->fps_out_den = cmd->fps_out_den;
p->fps_out_num = cmd->fps_out_num;
p->mdinfo_size = (MPP_VIDEO_CodingHEVC == cmd->type) ?
(MPP_ALIGN(p->hor_stride, 64) >> 6) *
(MPP_ALIGN(p->ver_stride, 64) >> 6) * 32 :
(MPP_ALIGN(p->hor_stride, 64) >> 6) *
(MPP_ALIGN(p->ver_stride, 16) >> 4) * 8;
if (cmd->file_input) {
if (!strncmp(cmd->file_input, "/dev/video", 10)) {
@@ -603,6 +610,7 @@ MPP_RET test_mpp_run(MpiEncMultiCtxInfo *info)
/* NOTE: It is important to clear output packet length!! */
mpp_packet_set_length(packet, 0);
mpp_meta_set_packet(meta, KEY_OUTPUT_PACKET, packet);
mpp_meta_set_buffer(meta, KEY_MOTION_INFO, p->md_info);
if (p->osd_enable || p->user_data_enable || p->roi_enable) {
if (p->user_data_enable) {
@@ -840,6 +848,12 @@ void *enc_test(void *arg)
goto MPP_TEST_OUT;
}
ret = mpp_buffer_get(p->buf_grp, &p->md_info, p->mdinfo_size);
if (ret) {
mpp_err_f("failed to get buffer for motion info output packet ret %d\n", ret);
goto MPP_TEST_OUT;
}
// encoder demo
ret = mpp_create(&p->ctx, &p->mpi);
if (ret) {
@@ -916,6 +930,11 @@ MPP_TEST_OUT:
p->pkt_buf = NULL;
}
if (p->md_info) {
mpp_buffer_put(p->md_info);
p->md_info = NULL;
}
if (p->osd_data.buf) {
mpp_buffer_put(p->osd_data.buf);
p->osd_data.buf = NULL;