diff --git a/mpp/legacy/vpu_api_legacy.cpp b/mpp/legacy/vpu_api_legacy.cpp index ab6f02ff..43da0f5d 100644 --- a/mpp/legacy/vpu_api_legacy.cpp +++ b/mpp/legacy/vpu_api_legacy.cpp @@ -1167,8 +1167,6 @@ RK_S32 VpuApiLegacy::encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *a /* try import input buffer and output buffer */ MppFrame frame = NULL; - - ret = mpp_frame_init(&frame); if (MPP_OK != ret) { mpp_err_f("mpp_frame_init failed\n"); @@ -1181,6 +1179,18 @@ RK_S32 VpuApiLegacy::encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *a mpp_frame_set_ver_stride(frame, ver_stride); mpp_frame_set_pts(frame, pts); + if (aEncInStrm->nFlags) { + mpp_log_f("found eos true\n"); + mpp_frame_set_eos(frame, 1); + } + + if (size <= 0) { + mpp_frame_set_buffer(frame, NULL); + if (!aEncInStrm->nFlags) + mpp_err_f("found empty frame without eos flag set!\n"); + goto PUT_FRAME; + } + if (fd_input < 0) { fd_input = is_valid_dma_fd(fd); } @@ -1235,14 +1245,11 @@ RK_S32 VpuApiLegacy::encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *a } } +PUT_FRAME: + vpu_api_dbg_input("w %d h %d input fd %d size %d pts %lld, flag %d \n", width, height, fd, size, aEncInStrm->timeUs, aEncInStrm->nFlags); - if (aEncInStrm->nFlags) { - mpp_log_f("found eos true"); - mpp_frame_set_eos(frame, 1); - } - ret = mpi->encode_put_frame(mpp_ctx, frame); if (ret) mpp_err_f("encode_put_frame ret %d\n", ret); @@ -1293,7 +1300,7 @@ RK_S32 VpuApiLegacy::encoder_getstream(VpuCodecContext *ctx, EncoderOut_t *aEncO mpp_packet_deinit(&packet); } else { aEncOut->size = 0; - vpu_api_dbg_output("encode_get_packet get NULL packet\n"); + vpu_api_dbg_output("get NULL packet, eos %d\n", mEosSet); if (mEosSet) ret = -1; } diff --git a/test/mpi_enc_test.c b/test/mpi_enc_test.c index bf38462f..f9a7e000 100644 --- a/test/mpi_enc_test.c +++ b/test/mpi_enc_test.c @@ -364,7 +364,7 @@ MPP_RET test_mpp_run(MpiEncTestData *p) if (p->fp_input) { ret = read_yuv_image(buf, p->fp_input, p->width, p->height, p->hor_stride, p->ver_stride, p->fmt); - if (ret == MPP_NOK || feof(p->fp_input)) { + if (ret == MPP_NOK || feof(p->fp_input)) { mpp_log("found last frame. feof %d\n", feof(p->fp_input)); p->frm_eos = 1; } else if (ret == MPP_ERR_VALUE) @@ -387,9 +387,13 @@ MPP_RET test_mpp_run(MpiEncTestData *p) mpp_frame_set_hor_stride(frame, p->hor_stride); mpp_frame_set_ver_stride(frame, p->ver_stride); mpp_frame_set_fmt(frame, p->fmt); - mpp_frame_set_buffer(frame, p->frm_buf); mpp_frame_set_eos(frame, p->frm_eos); + if (p->fp_input && feof(p->fp_input)) + mpp_frame_set_buffer(frame, NULL); + else + mpp_frame_set_buffer(frame, p->frm_buf); + ret = mpi->encode_put_frame(ctx, frame); if (ret) { mpp_err("mpp encode put frame failed\n");