[test]: modify mpi_dec_test for mjpeg decoding

1. clear input packet length when packet is copied
2. modify mjpeg advanced decoding path in mpi_dec_test
3. add numerator and denominator set prop function
4. remove extra log on first info change
5. fix eos process and buffer size check in advanced decoding flow
6. fix jpegd stream length config error

Change-Id: Id6c26ebda090eb4076f27deaad4d61b4221f2653
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2016-10-09 16:34:09 +08:00
parent a76b30c9b1
commit 04b6a23ce2
6 changed files with 110 additions and 50 deletions

View File

@@ -231,6 +231,8 @@ MPP_RET mpp_buf_slot_get_prop(MppBufSlots slots, RK_S32 index, SlotPropType type
typedef enum SlotsPropType_e { typedef enum SlotsPropType_e {
SLOTS_EOS, SLOTS_EOS,
SLOTS_NUMERATOR, // numerator of buffer size scale ratio
SLOTS_DENOMINATOR, // denominator of buffer size scale ratio
SLOTS_HOR_ALIGN, // input must be buf_align function pointer SLOTS_HOR_ALIGN, // input must be buf_align function pointer
SLOTS_VER_ALIGN, // input must be buf_align function pointer SLOTS_VER_ALIGN, // input must be buf_align function pointer
SLOTS_LEN_ALIGN, SLOTS_LEN_ALIGN,

View File

@@ -815,9 +815,11 @@ MPP_RET mpp_buf_slot_set_prop(MppBufSlots slots, RK_S32 index, SlotPropType type
impl->info_changed = 1; impl->info_changed = 1;
#ifdef RKPLATFORM #ifdef RKPLATFORM
MppFrameImpl *old = (MppFrameImpl *)impl->info; MppFrameImpl *old = (MppFrameImpl *)impl->info;
mpp_log("info change found\n"); if (old->width || old->height) {
mpp_log("old width %4d height %4d stride hor %4d ver %4d fmt %4d\n", mpp_log("info change found\n");
old->width, old->height, old->hor_stride, old->ver_stride, old->fmt); mpp_log("old width %4d height %4d stride hor %4d ver %4d fmt %4d\n",
old->width, old->height, old->hor_stride, old->ver_stride, old->fmt);
}
mpp_log("new width %4d height %4d stride hor %4d ver %4d fmt %4d\n", mpp_log("new width %4d height %4d stride hor %4d ver %4d fmt %4d\n",
dst->width, dst->height, dst->hor_stride, dst->ver_stride, dst->fmt); dst->width, dst->height, dst->hor_stride, dst->ver_stride, dst->fmt);
#endif #endif
@@ -901,6 +903,12 @@ MPP_RET mpp_slots_set_prop(MppBufSlots slots, SlotsPropType type, void *val)
case SLOTS_EOS: { case SLOTS_EOS: {
impl->eos = value; impl->eos = value;
} break; } break;
case SLOTS_NUMERATOR : {
impl->numerator = value;
} break;
case SLOTS_DENOMINATOR : {
impl->denominator = value;
} break;
case SLOTS_HOR_ALIGN: { case SLOTS_HOR_ALIGN: {
impl->hal_hor_align = (AlignFunc)val; impl->hal_hor_align = (AlignFunc)val;
} break; } break;

View File

@@ -1125,22 +1125,22 @@ MPP_RET jpegd_prepare(void *ctx, MppPacket pkt, HalDecTask *task)
MPP_RET ret = MPP_OK; MPP_RET ret = MPP_OK;
JpegParserContext *JpegParserCtx = (JpegParserContext *)ctx; JpegParserContext *JpegParserCtx = (JpegParserContext *)ctx;
MppPacket input_packet = JpegParserCtx->input_packet; MppPacket input_packet = JpegParserCtx->input_packet;
RK_U32 pkt_length = 0;
RK_U32 copy_length = 0; RK_U32 copy_length = 0;
void *pPacket = NULL; void *base = mpp_packet_get_pos(pkt);
RK_U8 *pPos = NULL; RK_U8 *pos = base;
RK_U32 pkt_length = (RK_U32)mpp_packet_get_length(pkt);
task->valid = 0; RK_U32 eos = (pkt_length) ? (mpp_packet_get_eos(pkt)) : (1);
JpegParserCtx->pts = mpp_packet_get_pts(pkt); JpegParserCtx->pts = mpp_packet_get_pts(pkt);
JpegParserCtx->eos = mpp_packet_get_eos(pkt);
pkt_length = (RK_U32)mpp_packet_get_length(pkt);
pPacket = pPos = mpp_packet_get_pos(pkt);
if (JpegParserCtx->eos) { task->valid = 0;
task->flags.eos = eos;
JpegParserCtx->eos = eos;
JPEGD_INFO_LOG("pkt_length %d eos %d\n", pkt_length, eos);
if (!pkt_length) {
JPEGD_INFO_LOG("it is end of stream."); JPEGD_INFO_LOG("it is end of stream.");
task->flags.eos = 1;
return ret; return ret;
} }
@@ -1158,10 +1158,10 @@ MPP_RET jpegd_prepare(void *ctx, MppPacket pkt, HalDecTask *task)
JpegParserCtx->bufferSize = pkt_length + 1024; JpegParserCtx->bufferSize = pkt_length + 1024;
} }
jpegd_parser_split_frame(pPacket, pkt_length, JpegParserCtx->recv_buffer, &copy_length); jpegd_parser_split_frame(base, pkt_length, JpegParserCtx->recv_buffer, &copy_length);
pPos += pkt_length; pos += pkt_length;
mpp_packet_set_pos(pkt, pPos); mpp_packet_set_pos(pkt, pos);
if (copy_length != pkt_length) { if (copy_length != pkt_length) {
JPEGD_INFO_LOG("there seems to be something wrong with split_frame. pkt_length:%d, copy_length:%d", pkt_length, copy_length); JPEGD_INFO_LOG("there seems to be something wrong with split_frame. pkt_length:%d, copy_length:%d", pkt_length, copy_length);
} }
@@ -1175,7 +1175,7 @@ MPP_RET jpegd_prepare(void *ctx, MppPacket pkt, HalDecTask *task)
jpg_file = fopen(name, "wb+"); jpg_file = fopen(name, "wb+");
if (jpg_file) { if (jpg_file) {
JPEGD_INFO_LOG("input jpeg(%d Bytes) saving to %s\n", pkt_length, name); JPEGD_INFO_LOG("input jpeg(%d Bytes) saving to %s\n", pkt_length, name);
fwrite(pPacket, pkt_length, 1, jpg_file); fwrite(base, pkt_length, 1, jpg_file);
fclose(jpg_file); fclose(jpg_file);
JpegParserCtx->input_jpeg_count++; JpegParserCtx->input_jpeg_count++;
} }
@@ -2379,15 +2379,24 @@ MPP_RET jpegd_allocate_frame(JpegParserContext *ctx)
} }
if (pCtx->frame_slot_index == -1) { if (pCtx->frame_slot_index == -1) {
RK_U32 value;
mpp_frame_set_width(pCtx->output_frame, pCtx->pSyntax->frame.X); mpp_frame_set_width(pCtx->output_frame, pCtx->pSyntax->frame.X);
mpp_frame_set_height(pCtx->output_frame, pCtx->pSyntax->frame.Y); mpp_frame_set_height(pCtx->output_frame, pCtx->pSyntax->frame.Y);
mpp_frame_set_hor_stride(pCtx->output_frame, pCtx->pSyntax->frame.X); mpp_frame_set_hor_stride(pCtx->output_frame, pCtx->pSyntax->frame.X);
mpp_frame_set_ver_stride(pCtx->output_frame, pCtx->pSyntax->frame.Y); mpp_frame_set_ver_stride(pCtx->output_frame, pCtx->pSyntax->frame.Y);
mpp_frame_set_pts(pCtx->output_frame, pCtx->pts); mpp_frame_set_pts(pCtx->output_frame, pCtx->pts);
if (pCtx->eos)
mpp_frame_set_eos(pCtx->output_frame, 1);
mpp_buf_slot_get_unused(pCtx->frame_slots, &pCtx->frame_slot_index); mpp_buf_slot_get_unused(pCtx->frame_slots, &pCtx->frame_slot_index);
JPEGD_INFO_LOG("frame_slot_index:%d, X:%d, Y:%d", pCtx->frame_slot_index, pCtx->pSyntax->frame.X, pCtx->pSyntax->frame.Y); JPEGD_INFO_LOG("frame_slot_index:%d, X:%d, Y:%d", pCtx->frame_slot_index, pCtx->pSyntax->frame.X, pCtx->pSyntax->frame.Y);
value = 3;
mpp_slots_set_prop(pCtx->frame_slots, SLOTS_NUMERATOR, &value);
value = 2;
mpp_slots_set_prop(pCtx->frame_slots, SLOTS_DENOMINATOR, &value);
mpp_buf_slot_set_prop(pCtx->frame_slots, pCtx->frame_slot_index, SLOT_FRAME, pCtx->output_frame); mpp_buf_slot_set_prop(pCtx->frame_slots, pCtx->frame_slot_index, SLOT_FRAME, pCtx->output_frame);
mpp_buf_slot_set_flag(pCtx->frame_slots, pCtx->frame_slot_index, SLOT_CODEC_USE); mpp_buf_slot_set_flag(pCtx->frame_slots, pCtx->frame_slot_index, SLOT_CODEC_USE);
mpp_buf_slot_set_flag(pCtx->frame_slots, pCtx->frame_slot_index, SLOT_HAL_OUTPUT); mpp_buf_slot_set_flag(pCtx->frame_slots, pCtx->frame_slot_index, SLOT_HAL_OUTPUT);
@@ -2453,7 +2462,7 @@ MPP_RET jpegd_decode_frame(JpegParserContext *ctx)
if (!pSyntax->info.SliceReadyForPause && if (!pSyntax->info.SliceReadyForPause &&
!pSyntax->info.inputBufferEmpty && pCtx->bufferSize) { !pSyntax->info.inputBufferEmpty && pCtx->bufferSize) {
pSyntax->info.inputStreaming = 1; pSyntax->info.inputStreaming = 1;
pSyntax->info.inputBufferLen = pCtx->bufferSize; pSyntax->info.inputBufferLen = pCtx->streamLength;
pSyntax->info.decodedStreamLen += pSyntax->info.inputBufferLen; pSyntax->info.decodedStreamLen += pSyntax->info.inputBufferLen;
} }
@@ -2616,7 +2625,7 @@ MPP_RET jpegd_init(void *ctx, ParserCfg *parser_cfg)
JpegParserCtx->frame_slots = parser_cfg->frame_slots; JpegParserCtx->frame_slots = parser_cfg->frame_slots;
JpegParserCtx->packet_slots = parser_cfg->packet_slots; JpegParserCtx->packet_slots = parser_cfg->packet_slots;
JpegParserCtx->frame_slot_index = -1; JpegParserCtx->frame_slot_index = -1;
mpp_buf_slot_setup(JpegParserCtx->frame_slots, 16); mpp_buf_slot_setup(JpegParserCtx->frame_slots, 1);
JpegParserCtx->recv_buffer = mpp_calloc(RK_U8, JPEGD_STREAM_BUFF_SIZE); JpegParserCtx->recv_buffer = mpp_calloc(RK_U8, JPEGD_STREAM_BUFF_SIZE);
if (NULL == JpegParserCtx->recv_buffer) { if (NULL == JpegParserCtx->recv_buffer) {

View File

@@ -868,6 +868,17 @@ void *mpp_dec_advanced_thread(void *data)
parser_prepare(dec->parser, packet, task_dec); parser_prepare(dec->parser, packet, task_dec);
/*
* We may find eos in prepare step and there will be no anymore vaild task generated.
* So here we try push eos task to hal, hal will push all frame to display then
* push a eos frame to tell all frame decoded
*/
if (task_dec->flags.eos && !task_dec->valid) {
mpp_frame_init(&frame);
mpp_frame_set_eos(frame, 1);
goto DEC_OUT;
}
/* /*
* look for a unused packet slot index * look for a unused packet slot index
*/ */
@@ -886,6 +897,17 @@ void *mpp_dec_advanced_thread(void *data)
goto DEC_OUT; goto DEC_OUT;
} }
if (mpp_buf_slot_is_changed(frame_slots)) {
size_t slot_size = mpp_buf_slot_get_size(frame_slots);
size_t buffer_size = mpp_buffer_get_size(output_buffer);
if (slot_size == buffer_size) {
mpp_buf_slot_ready(frame_slots);
}
mpp_assert(slot_size == buffer_size);
}
mpp_buf_slot_set_prop(frame_slots, task_dec->output, SLOT_BUFFER, output_buffer); mpp_buf_slot_set_prop(frame_slots, task_dec->output, SLOT_BUFFER, output_buffer);
// register genertation // register genertation

View File

@@ -252,6 +252,9 @@ MPP_RET Mpp::put_packet(MppPacket packet)
mPackets->add_at_tail(&pkt, sizeof(pkt)); mPackets->add_at_tail(&pkt, sizeof(pkt));
mPacketPutCount++; mPacketPutCount++;
mThreadCodec->signal(); mThreadCodec->signal();
// when packet has been send clear the length
mpp_packet_set_length(pkt, 0);
return MPP_OK; return MPP_OK;
} }

View File

@@ -153,6 +153,7 @@ int mpi_dec_test_decode_simple(MpiDecTestCmd *cmd)
mpp_packet_write(packet, 0, buf, read_size); mpp_packet_write(packet, 0, buf, read_size);
// reset pos // reset pos
mpp_packet_set_pos(packet, buf); mpp_packet_set_pos(packet, buf);
mpp_packet_set_length(packet, read_size);
// setup eos flag // setup eos flag
if (pkt_eos) if (pkt_eos)
mpp_packet_set_eos(packet); mpp_packet_set_eos(packet);
@@ -239,11 +240,6 @@ MPP_TEST_OUT:
fp_input = NULL; fp_input = NULL;
} }
if (MPP_OK == ret)
mpp_log("mpi_dec_test success\n");
else
mpp_err("mpi_dec_test failed ret %d\n", ret);
return ret; return ret;
} }
@@ -276,9 +272,9 @@ int mpi_dec_test_decode_advanced(MpiDecTestCmd *cmd)
MppBuffer frm_buf = NULL; MppBuffer frm_buf = NULL;
size_t packet_size = MPI_DEC_STREAM_SIZE; size_t packet_size = MPI_DEC_STREAM_SIZE;
size_t read_size = 0; size_t read_size = 0;
size_t file_size = 0;
RK_U32 frame_count = 0; RK_U32 frame_count = 0;
void *buf = NULL; void *buf = NULL;
(void)read_size;
MppBufferGroup frm_grp = NULL; MppBufferGroup frm_grp = NULL;
MppBufferGroup pkt_grp = NULL; MppBufferGroup pkt_grp = NULL;
@@ -291,6 +287,12 @@ int mpi_dec_test_decode_advanced(MpiDecTestCmd *cmd)
mpp_err("failed to open input file %s\n", cmd->file_input); mpp_err("failed to open input file %s\n", cmd->file_input);
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
// get file size for MJPEG
fseek(fp_input, 0L, SEEK_END);
file_size = ftell(fp_input);
rewind(fp_input);
mpp_log("input file size %ld\n", file_size);
} }
if (cmd->have_output) { if (cmd->have_output) {
@@ -313,10 +315,6 @@ int mpi_dec_test_decode_advanced(MpiDecTestCmd *cmd)
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
fseek(fp_input, 0L, SEEK_END);
packet_size = ftell(fp_input);
fseek(fp_input, 0L, SEEK_SET);
RK_U32 frm_size = width * height * 3 / 2; RK_U32 frm_size = width * height * 3 / 2;
ret = mpp_frame_init(&frame); /* output frame */ ret = mpp_frame_init(&frame); /* output frame */
if (MPP_OK != ret) { if (MPP_OK != ret) {
@@ -330,6 +328,11 @@ int mpi_dec_test_decode_advanced(MpiDecTestCmd *cmd)
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
// NOTE: for mjpeg decoding send the whole file
if (type == MPP_VIDEO_CodingMJPEG) {
packet_size = file_size;
}
ret = mpp_buffer_get(pkt_grp, &pkt_buf, packet_size); ret = mpp_buffer_get(pkt_grp, &pkt_buf, packet_size);
if (ret) { if (ret) {
mpp_err("failed to get buffer for input frame ret %d\n", ret); mpp_err("failed to get buffer for input frame ret %d\n", ret);
@@ -366,11 +369,17 @@ int mpi_dec_test_decode_advanced(MpiDecTestCmd *cmd)
while (!pkt_eos) { while (!pkt_eos) {
MppTask task = NULL; MppTask task = NULL;
read_size = fread(buf, 1, packet_size, fp_input); read_size = fread(buf, 1, packet_size, fp_input);
/* if (read_size != packet_size || feof(fp_input)) { if (read_size != packet_size || feof(fp_input)) {
mpp_log("found last packet\n"); mpp_log("found last packet\n");
pkt_eos = 1; pkt_eos = 1;
}*/ }
pkt_eos = 1;
// reset pos
mpp_packet_set_pos(packet, buf);
mpp_packet_set_length(packet, read_size);
// setup eos flag
if (pkt_eos)
mpp_packet_set_eos(packet);
do { do {
ret = mpi->dequeue(ctx, MPP_PORT_INPUT, &task); /* input queue */ ret = mpi->dequeue(ctx, MPP_PORT_INPUT, &task); /* input queue */
@@ -410,15 +419,22 @@ int mpi_dec_test_decode_advanced(MpiDecTestCmd *cmd)
mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out); mpp_task_meta_get_frame(task, KEY_OUTPUT_FRAME, &frame_out);
//mpp_assert(packet_out == packet); //mpp_assert(packet_out == packet);
if (frame) { /* write frame to file here */ if (frame) {
MppBuffer buf_out = mpp_frame_get_buffer(frame_out); /* write frame to file here */
void *ptr = mpp_buffer_get_ptr(buf_out); MppBuffer buf_out = mpp_frame_get_buffer(frame_out);
size_t len = mpp_buffer_get_size(buf_out);
if (fp_output) if (buf_out) {
fwrite(ptr, 1, len, fp_output); void *ptr = mpp_buffer_get_ptr(buf_out);
size_t len = mpp_buffer_get_size(buf_out);
mpp_log_f("decoded frame %d size %d\n", frame_count, len); if (fp_output)
fwrite(ptr, 1, len, fp_output);
mpp_log("decoded frame %d size %d\n", frame_count, len);
}
if (mpp_frame_get_eos(frame_out))
mpp_log("found eos frame\n");
} }
ret = mpi->enqueue(ctx, MPP_PORT_OUTPUT, task); /* output queue */ ret = mpi->enqueue(ctx, MPP_PORT_OUTPUT, task); /* output queue */
@@ -453,13 +469,13 @@ MPP_TEST_OUT:
ctx = NULL; ctx = NULL;
} }
if (buf) { if (pkt_buf) {
mpp_free(buf); mpp_buffer_put(pkt_buf);
buf = NULL; pkt_buf = NULL;
} }
if (frm_buf) { if (frm_buf) {
mpp_free(frm_buf); mpp_buffer_put(frm_buf);
frm_buf = NULL; frm_buf = NULL;
} }
@@ -473,11 +489,6 @@ MPP_TEST_OUT:
fp_input = NULL; fp_input = NULL;
} }
if (MPP_OK == ret)
mpp_log_f("success\n");
else
mpp_err_f("failed ret %d\n", ret);
return ret; return ret;
} }
@@ -628,11 +639,16 @@ int main(int argc, char **argv)
mpp_env_set_u32("mpi_debug", cmd->debug); mpp_env_set_u32("mpi_debug", cmd->debug);
if (cmd->type != MPP_VIDEO_CodingMJPEG) { if (cmd->type != MPP_VIDEO_CodingMJPEG) {
mpi_dec_test_decode_simple(cmd); ret = mpi_dec_test_decode_simple(cmd);
} else { } else {
mpi_dec_test_decode_advanced(cmd); ret = mpi_dec_test_decode_advanced(cmd);
} }
if (MPP_OK == ret)
mpp_log("test success\n");
else
mpp_err("test failed ret %d\n", ret);
mpp_env_set_u32("mpi_debug", 0x0); mpp_env_set_u32("mpi_debug", 0x0);
return 0; return 0;
} }