mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-06 01:26:49 +08:00
feat[dec_nt_test]: Support jpeg decoding on decode
Signed-off-by: Herman Chen <herman.chen@rock-chips.com> Change-Id: I36196906fe5a5cf4f0a1ebd1aa1fa69dd94f88bc
This commit is contained in:
@@ -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);
|
dec_dbg_detail("detail: %p hal_pkt_buf_in %p\n", dec, task->hal_pkt_buf_in);
|
||||||
if (!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;
|
RK_S32 slot_pkt = -1;
|
||||||
|
|
||||||
mpp_buf_slot_get_unused(packet_slots, &slot_pkt);
|
mpp_buf_slot_get_unused(packet_slots, &slot_pkt);
|
||||||
mpp_assert(slot_pkt >= 0);
|
mpp_assert(slot_pkt >= 0);
|
||||||
stream_size = mpp_packet_get_size(task_dec->input_packet);
|
stream_size = mpp_packet_get_size(task_dec->input_packet);
|
||||||
|
|
||||||
|
if (NULL == hal_buf_in) {
|
||||||
mpp_buf_slot_get_prop(packet_slots, slot_pkt, SLOT_BUFFER, &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) {
|
if (NULL == hal_buf_in) {
|
||||||
mpp_buffer_get(mpp->mPacketGroup, &hal_buf_in, stream_size);
|
mpp_buffer_get(mpp->mPacketGroup, &hal_buf_in, stream_size);
|
||||||
if (hal_buf_in) {
|
if (hal_buf_in) {
|
||||||
@@ -138,6 +147,7 @@ MPP_RET mpp_dec_decode(MppDec ctx, MppPacket packet)
|
|||||||
* 6. copy data to hardware buffer
|
* 6. copy data to hardware buffer
|
||||||
*/
|
*/
|
||||||
if (!status->dec_pkt_copy_rdy) {
|
if (!status->dec_pkt_copy_rdy) {
|
||||||
|
if (!task_dec->input_no_copy) {
|
||||||
void *src = mpp_packet_get_data(task_dec->input_packet);
|
void *src = mpp_packet_get_data(task_dec->input_packet);
|
||||||
size_t length = mpp_packet_get_length(task_dec->input_packet);
|
size_t length = mpp_packet_get_length(task_dec->input_packet);
|
||||||
|
|
||||||
@@ -148,8 +158,11 @@ MPP_RET mpp_dec_decode(MppDec ctx, MppPacket packet)
|
|||||||
mpp_buffer_write(task->hal_pkt_buf_in, 0, src, 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_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_CODEC_READY);
|
||||||
mpp_buf_slot_set_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT);
|
mpp_buf_slot_set_flag(packet_slots, task_dec->input, SLOT_HAL_INPUT);
|
||||||
|
|
||||||
status->dec_pkt_copy_rdy = 1;
|
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_parser_parse(dec->parser, task_dec);
|
||||||
mpp_clock_pause(dec->clocks[DEC_PRS_PARSE]);
|
mpp_clock_pause(dec->clocks[DEC_PRS_PARSE]);
|
||||||
status->task_parsed_rdy = 1;
|
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,
|
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_start(dec->hal, &task->info);
|
||||||
mpp_hal_hw_wait(dec->hal, &task->info);
|
mpp_hal_hw_wait(dec->hal, &task->info);
|
||||||
dec->dec_hw_run_count++;
|
dec->dec_hw_run_count++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* when hardware decoding is done:
|
* when hardware decoding is done:
|
||||||
* 1. clear decoding flag (mark buffer is ready)
|
* 1. clear decoding flag (mark buffer is ready)
|
||||||
|
@@ -81,6 +81,7 @@ typedef struct HalDecTask_t {
|
|||||||
// packet need to be copied to hardware buffer
|
// packet need to be copied to hardware buffer
|
||||||
// parser will create this packet and mpp_dec will copy it to hardware bufffer
|
// parser will create this packet and mpp_dec will copy it to hardware bufffer
|
||||||
MppPacket input_packet;
|
MppPacket input_packet;
|
||||||
|
RK_S32 input_no_copy;
|
||||||
|
|
||||||
// current task input slot index
|
// current task input slot index
|
||||||
RK_S32 input;
|
RK_S32 input;
|
||||||
|
@@ -91,10 +91,24 @@ static int dec_loop(MpiDecLoopData *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!slot->buf) {
|
||||||
|
/* non-jpeg decoding */
|
||||||
mpp_packet_set_data(packet, slot->data);
|
mpp_packet_set_data(packet, slot->data);
|
||||||
mpp_packet_set_size(packet, slot->size);
|
mpp_packet_set_size(packet, slot->size);
|
||||||
mpp_packet_set_pos(packet, slot->data);
|
mpp_packet_set_pos(packet, slot->data);
|
||||||
mpp_packet_set_length(packet, slot->size);
|
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
|
// setup eos flag
|
||||||
if (pkt_eos)
|
if (pkt_eos)
|
||||||
mpp_packet_set_eos(packet);
|
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);
|
mpp_err("%p info change ready failed ret %d\n", ctx, ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mpp_frame_deinit(&frame);
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
char log_buf[256];
|
char log_buf[256];
|
||||||
RK_S32 log_size = sizeof(log_buf) - 1;
|
RK_S32 log_size = sizeof(log_buf) - 1;
|
||||||
@@ -331,44 +348,12 @@ int dec_nt_decode(MpiDecTestCmd *cmd)
|
|||||||
goto MPP_TEST_OUT;
|
goto MPP_TEST_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd->simple) {
|
|
||||||
ret = mpp_packet_init(&packet, NULL, 0);
|
ret = mpp_packet_init(&packet, NULL, 0);
|
||||||
mpp_err_f("mpp_packet_init get %p\n", packet);
|
mpp_err_f("mpp_packet_init get %p\n", packet);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
mpp_err("mpp_packet_init failed\n");
|
mpp_err("mpp_packet_init failed\n");
|
||||||
goto MPP_TEST_OUT;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// decoder demo
|
// decoder demo
|
||||||
ret = mpp_create(&ctx, &mpi);
|
ret = mpp_create(&ctx, &mpi);
|
||||||
|
Reference in New Issue
Block a user