From f54a25f1127cbcd001a1ab14290266fe48b78705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Thu, 15 Jun 2017 11:17:56 +0300 Subject: [PATCH] Fix crash when immediately closing encoder When closing the encoder, the pictures stored in the input frame buffer are freed by repeatedly calling kvz_encoder_feed_frame. If the encoder was closed immediately after opening it, kvz_encoder_feed_frame would be called with an unprepared encoder state. This would trigger an assert. Fixed by changing kvz_encoder_feed_frame so that it does not require the encoder state to be prepared. --- src/input_frame_buffer.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/input_frame_buffer.c b/src/input_frame_buffer.c index 5c4f7c28..3b23b6c5 100644 --- a/src/input_frame_buffer.c +++ b/src/input_frame_buffer.c @@ -58,8 +58,6 @@ kvz_picture* kvz_encoder_feed_frame(input_frame_buffer_t *buf, const int gop_buf_size = 3 * cfg->gop_len; - assert(state->frame->num >= 0); - if (cfg->gop_len == 0 || cfg->gop_lowdelay) { // No reordering of output pictures necessary. @@ -69,12 +67,10 @@ kvz_picture* kvz_encoder_feed_frame(input_frame_buffer_t *buf, state->frame->gop_offset = 0; if (cfg->gop_len > 0) { // Using a low delay GOP structure. - state->frame->gop_offset = (state->frame->num - 1) % cfg->gop_len; - if (state->frame->gop_offset < 0) { - // Set gop_offset of IDR as the highest quality picture. - state->frame->gop_offset += cfg->gop_len; - } + state->frame->gop_offset = (buf->num_out + cfg->gop_len - 1) % cfg->gop_len; } + buf->num_in++; + buf->num_out++; return kvz_image_copy_ref(img_in); }