mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-04 08:46:24 +08:00
[vpu]: Fix encoder's improper operation with eos
When encoder receives an empty frame with eos flag set, encoder will encode an unreasonable extra frame. Change-Id: I3bd1a2c84780f1b6212171117b67319b2f613b9f Signed-off-by: Johnson Ding <johnson.ding@rock-chips.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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");
|
||||
|
Reference in New Issue
Block a user