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.
This commit is contained in:
Arttu Ylä-Outinen 2017-06-15 11:17:56 +03:00
parent b74e0458fd
commit f54a25f112

View file

@ -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);
}