From a426f4078e0ddba7f7da149645213bbd61c17a03 Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Thu, 12 Dec 2024 14:38:34 +0800 Subject: [PATCH] feat[dec_nt_test]: Support jpeg decoding on decode Signed-off-by: Herman Chen Change-Id: I36196906fe5a5cf4f0a1ebd1aa1fa69dd94f88bc --- mpp/codec/mpp_dec_no_thread.cpp | 38 ++++++++++++++----- mpp/hal/inc/hal_dec_task.h | 1 + test/mpi_dec_nt_test.c | 67 +++++++++++++-------------------- 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/mpp/codec/mpp_dec_no_thread.cpp b/mpp/codec/mpp_dec_no_thread.cpp index 69e96989..75857bdd 100644 --- a/mpp/codec/mpp_dec_no_thread.cpp +++ b/mpp/codec/mpp_dec_no_thread.cpp @@ -107,14 +107,23 @@ MPP_RET mpp_dec_decode(MppDec ctx, MppPacket packet) */ dec_dbg_detail("detail: %p hal_pkt_buf_in %p\n", dec, task->hal_pkt_buf_in); if (!task->hal_pkt_buf_in) { - MppBuffer hal_buf_in = NULL; + MppBuffer hal_buf_in = mpp_packet_get_buffer(task_dec->input_packet); RK_S32 slot_pkt = -1; mpp_buf_slot_get_unused(packet_slots, &slot_pkt); mpp_assert(slot_pkt >= 0); stream_size = mpp_packet_get_size(task_dec->input_packet); - mpp_buf_slot_get_prop(packet_slots, slot_pkt, SLOT_BUFFER, &hal_buf_in); + if (NULL == hal_buf_in) { + mpp_buf_slot_get_prop(packet_slots, slot_pkt, SLOT_BUFFER, &hal_buf_in); + } else { + /* use external buffer and set to slot */ + task_dec->input_no_copy = 1; + + mpp_buf_slot_set_prop(packet_slots, slot_pkt, SLOT_BUFFER, hal_buf_in); + mpp_buffer_attach_dev(hal_buf_in, dec->dev); + } + if (NULL == hal_buf_in) { mpp_buffer_get(mpp->mPacketGroup, &hal_buf_in, stream_size); if (hal_buf_in) { @@ -138,18 +147,22 @@ MPP_RET mpp_dec_decode(MppDec ctx, MppPacket packet) * 6. copy data to hardware buffer */ if (!status->dec_pkt_copy_rdy) { - void *src = mpp_packet_get_data(task_dec->input_packet); - size_t length = mpp_packet_get_length(task_dec->input_packet); + if (!task_dec->input_no_copy) { + void *src = mpp_packet_get_data(task_dec->input_packet); + size_t length = mpp_packet_get_length(task_dec->input_packet); - mpp_assert(task->hal_pkt_buf_in); - mpp_assert(task_dec->input_packet); + mpp_assert(task->hal_pkt_buf_in); + mpp_assert(task_dec->input_packet); - dec_dbg_detail("detail: %p copy to hw length %d\n", dec, length); - mpp_buffer_write(task->hal_pkt_buf_in, 0, src, length); - mpp_buffer_sync_partial_end(task->hal_pkt_buf_in, 0, length); + dec_dbg_detail("detail: %p copy to hw length %d\n", dec, length); + mpp_buffer_write(task->hal_pkt_buf_in, 0, src, length); + mpp_buffer_sync_partial_end(task->hal_pkt_buf_in, 0, length); + + } mpp_buf_slot_set_flag(packet_slots, task_dec->input, SLOT_CODEC_READY); mpp_buf_slot_set_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT); + status->dec_pkt_copy_rdy = 1; } @@ -161,6 +174,12 @@ MPP_RET mpp_dec_decode(MppDec ctx, MppPacket packet) mpp_parser_parse(dec->parser, task_dec); mpp_clock_pause(dec->clocks[DEC_PRS_PARSE]); status->task_parsed_rdy = 1; + + /* add extra output slot operaton for jpeg decoding */ + if (task_dec->input_no_copy && task_dec->output >= 0) { + mpp_buf_slot_set_flag(frame_slots, task_dec->output, SLOT_QUEUE_USE); + mpp_buf_slot_enqueue(frame_slots, task_dec->output, QUEUE_DISPLAY); + } } dec_dbg_detail("detail: %p parse output slot %d valid %d\n", dec, @@ -292,6 +311,7 @@ MPP_RET mpp_dec_decode(MppDec ctx, MppPacket packet) mpp_hal_hw_start(dec->hal, &task->info); mpp_hal_hw_wait(dec->hal, &task->info); dec->dec_hw_run_count++; + /* * when hardware decoding is done: * 1. clear decoding flag (mark buffer is ready) diff --git a/mpp/hal/inc/hal_dec_task.h b/mpp/hal/inc/hal_dec_task.h index ca55d886..148338e9 100644 --- a/mpp/hal/inc/hal_dec_task.h +++ b/mpp/hal/inc/hal_dec_task.h @@ -81,6 +81,7 @@ typedef struct HalDecTask_t { // packet need to be copied to hardware buffer // parser will create this packet and mpp_dec will copy it to hardware bufffer MppPacket input_packet; + RK_S32 input_no_copy; // current task input slot index RK_S32 input; diff --git a/test/mpi_dec_nt_test.c b/test/mpi_dec_nt_test.c index daf16c9b..75406808 100644 --- a/test/mpi_dec_nt_test.c +++ b/test/mpi_dec_nt_test.c @@ -91,10 +91,24 @@ static int dec_loop(MpiDecLoopData *data) } } - mpp_packet_set_data(packet, slot->data); - mpp_packet_set_size(packet, slot->size); - mpp_packet_set_pos(packet, slot->data); - mpp_packet_set_length(packet, slot->size); + if (!slot->buf) { + /* non-jpeg decoding */ + mpp_packet_set_data(packet, slot->data); + mpp_packet_set_size(packet, slot->size); + mpp_packet_set_pos(packet, slot->data); + mpp_packet_set_length(packet, slot->size); + } else { + /* jpeg decoding */ + void *buf = mpp_buffer_get_ptr(slot->buf); + size_t size = mpp_buffer_get_size(slot->buf); + + mpp_packet_set_data(packet, buf); + mpp_packet_set_size(packet, size); + mpp_packet_set_pos(packet, buf); + mpp_packet_set_length(packet, size); + mpp_packet_set_buffer(packet, slot->buf); + } + // setup eos flag if (pkt_eos) mpp_packet_set_eos(packet); @@ -142,6 +156,9 @@ static int dec_loop(MpiDecLoopData *data) mpp_err("%p info change ready failed ret %d\n", ctx, ret); break; } + + mpp_frame_deinit(&frame); + continue; } else { char log_buf[256]; RK_S32 log_size = sizeof(log_buf) - 1; @@ -331,43 +348,11 @@ int dec_nt_decode(MpiDecTestCmd *cmd) goto MPP_TEST_OUT; } - if (cmd->simple) { - ret = mpp_packet_init(&packet, NULL, 0); - mpp_err_f("mpp_packet_init get %p\n", packet); - if (ret) { - mpp_err("mpp_packet_init failed\n"); - goto MPP_TEST_OUT; - } - } else { - RK_U32 hor_stride = MPP_ALIGN(width, 16); - RK_U32 ver_stride = MPP_ALIGN(height, 16); - - ret = mpp_frame_init(&frame); /* output frame */ - if (ret) { - mpp_err("mpp_frame_init failed\n"); - goto MPP_TEST_OUT; - } - - data.frm_grp = dec_buf_mgr_setup(data.buf_mgr, hor_stride * ver_stride * 4, 4, cmd->buf_mode); - if (!data.frm_grp) { - mpp_err("failed to get buffer group for input frame ret %d\n", ret); - goto MPP_TEST_OUT; - } - - /* - * NOTE: For jpeg could have YUV420 and YUV422 the buffer should be - * larger for output. And the buffer dimension should align to 16. - * YUV420 buffer is 3/2 times of w*h. - * YUV422 buffer is 2 times of w*h. - * So create larger buffer with 2 times w*h. - */ - ret = mpp_buffer_get(data.frm_grp, &frm_buf, hor_stride * ver_stride * 4); - if (ret) { - mpp_err("failed to get buffer for input frame ret %d\n", ret); - goto MPP_TEST_OUT; - } - - mpp_frame_set_buffer(frame, frm_buf); + ret = mpp_packet_init(&packet, NULL, 0); + mpp_err_f("mpp_packet_init get %p\n", packet); + if (ret) { + mpp_err("mpp_packet_init failed\n"); + goto MPP_TEST_OUT; } // decoder demo