From c31e7ada4a7470afc97b0512e223a76d46225e47 Mon Sep 17 00:00:00 2001 From: ChenHengming Date: Thu, 16 Jun 2016 11:34:13 +0000 Subject: [PATCH] [mpp]: change mpi_get_frame return value meaning: return MPP_NOK means flow error return MPP_OK does not mean there is available frame, need to check the MppFrame pointer [mpp_dec_test]: reduce buffer size on reading to avoid one packet multiple frame input. git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@930 6e48237b-75ef-9749-8fc9-41990f28c85a --- mpp/legacy/vpu_api_legacy.cpp | 32 ++++++++++++++++++++------------ mpp/mpp.cpp | 5 ++--- test/mpi_dec_test.c | 9 ++++++--- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/mpp/legacy/vpu_api_legacy.cpp b/mpp/legacy/vpu_api_legacy.cpp index e3db3b19..709f3e5e 100644 --- a/mpp/legacy/vpu_api_legacy.cpp +++ b/mpp/legacy/vpu_api_legacy.cpp @@ -128,28 +128,35 @@ RK_S32 VpuApi::decode(VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *aD RK_S32 VpuApi::decode_sendstream(VideoPacket_t *pkt) { - //mpp_log_f("in\n"); + RK_S32 ret; MppPacket mpkt = NULL; + mpp_packet_init(&mpkt, pkt->data, pkt->size); mpp_packet_set_pts(mpkt, pkt->pts); if (pkt->nFlags & OMX_BUFFERFLAG_EOS) { - mpp_err("decode_sendstream set eos"); + mpp_log("decode_sendstream set eos"); mpp_packet_set_eos(mpkt); } - if (mpi->decode_put_packet(mpp_ctx, mpkt) == MPP_OK) { + + ret = mpi->decode_put_packet(mpp_ctx, mpkt); + + if (ret == MPP_OK) { pkt->size = 0; + } else { + mpp_err("decode_put_packet ret %d\n", ret); } mpp_packet_deinit(&mpkt); - // mpp_log_f("ok\n"); - return 0; + return ret; } RK_S32 VpuApi:: decode_getoutframe(DecoderOut_t *aDecOut) { - // mpp_log_f("in\n"); + RK_S32 ret = 0; VPU_FRAME *vframe = (VPU_FRAME *)aDecOut->data; - memset(vframe, 0, sizeof(VPU_FRAME)); MppFrame mframe = NULL; + + memset(vframe, 0, sizeof(VPU_FRAME)); + if (NULL == mpi) { aDecOut->size = 0; return 0; @@ -158,7 +165,11 @@ RK_S32 VpuApi:: decode_getoutframe(DecoderOut_t *aDecOut) aDecOut->size = 0; return VPU_API_EOS_STREAM_REACHED; } - if (MPP_OK == mpi->decode_get_frame(mpp_ctx, &mframe)) { + + ret = mpi->decode_get_frame(mpp_ctx, &mframe); + if (ret || NULL == mframe) { + aDecOut->size = 0; + } else { MppBuffer buf = NULL; RK_U64 pts = 0; RK_U32 fd = 0; @@ -268,12 +279,9 @@ RK_S32 VpuApi:: decode_getoutframe(DecoderOut_t *aDecOut) */ mpp_frame_set_buffer(mframe, NULL); mpp_frame_deinit(&mframe); - } else { - aDecOut->size = 0; } - // mpp_log_f("ok\n"); - return 0; + return ret; } RK_S32 VpuApi::encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut) diff --git a/mpp/mpp.cpp b/mpp/mpp.cpp index 4e398221..74e81be3 100644 --- a/mpp/mpp.cpp +++ b/mpp/mpp.cpp @@ -226,10 +226,9 @@ MPP_RET Mpp::get_frame(MppFrame *frame) prev = next; } } - *frame = first; - return MPP_OK; } - return MPP_NOK; + *frame = first; + return MPP_OK; } MPP_RET Mpp::put_frame(MppFrame frame) diff --git a/test/mpi_dec_test.c b/test/mpi_dec_test.c index 8cf7a97f..94447226 100644 --- a/test/mpi_dec_test.c +++ b/test/mpi_dec_test.c @@ -31,7 +31,7 @@ #include "utils.h" #define MPI_DEC_LOOP_COUNT 4 -#define MPI_STREAM_SIZE (SZ_512K) +#define MPI_DEC_STREAM_SIZE (SZ_64K) #define MAX_FILE_NAME_LENGTH 256 typedef struct { @@ -81,8 +81,9 @@ int mpi_dec_test(MpiDecTestCmd *cmd) // resources char *buf = NULL; - size_t packet_size = MPI_STREAM_SIZE; + size_t packet_size = MPI_DEC_STREAM_SIZE; size_t read_size = 0; + RK_U32 frame_count = 0; mpp_log("mpi_dec_test start\n"); @@ -141,7 +142,6 @@ int mpi_dec_test(MpiDecTestCmd *cmd) while (!found_eos) { read_size = fread(buf, 1, packet_size, fp_input); - mpp_log("read packet length %u\n", read_size); if (read_size != packet_size || feof(fp_input)) { mpp_log("found last packet\n"); found_eos = 1; @@ -157,6 +157,7 @@ int mpi_dec_test(MpiDecTestCmd *cmd) ret = mpi->decode_put_packet(ctx, packet); if (MPP_OK != ret) { + mpp_err("decode_put_packet failed ret %d\n", ret); goto MPP_TEST_OUT; } @@ -164,6 +165,7 @@ int mpi_dec_test(MpiDecTestCmd *cmd) ret = mpi->decode_get_frame(ctx, &frame); if (MPP_OK != ret) { + mpp_err("decode_get_frame failed ret %d\n", ret); goto MPP_TEST_OUT; } @@ -172,6 +174,7 @@ int mpi_dec_test(MpiDecTestCmd *cmd) mpp_log("decode_get_frame get info changed found\n"); mpi->control(ctx, MPP_CODEC_SET_INFO_CHANGE_READY, NULL); } else { + mpp_log("decode_get_frame get frame %d\n", frame_count++); if (fp_output) dump_mpp_frame_to_file(frame, fp_output); }