From 92e4c28fdefa6eb043c8fdc5fa57eb8cd24739be Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 16 Feb 2018 12:43:13 -0500 Subject: [PATCH] fix recording-daemon segfault for libavcodec versions < 57 fixes #462 Change-Id: I62776c1c3d83ccbdc94990fd1f9db43bcf0b0eff --- recording-daemon/output.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/recording-daemon/output.c b/recording-daemon/output.c index 89a9ef7d0..a901cc726 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -84,6 +84,15 @@ int output_config(output_t *output, const format_t *requested_format, format_t * goto err; output->avst->time_base = output->encoder->u.avc.avcctx->time_base; +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 0, 0) + // move the avcctx to avst as we already have an initialized avcctx + if (output->avst->codec) { + avcodec_close(output->avst->codec); + avcodec_free_context(&output->avst->codec); + } + output->avst->codec = output->encoder->u.avc.avcctx; +#endif + #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 26, 0) // exact version? present in 57.56 avcodec_parameters_from_context(output->avst->codecpar, output->encoder->u.avc.avcctx); #endif @@ -134,6 +143,11 @@ static void output_shutdown(output_t *output) { } avformat_free_context(output->fmtctx); +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 0, 0) + // avoid double free - avcctx already freed + output->encoder->u.avc.avcctx = NULL; +#endif + encoder_close(output->encoder); output->fmtctx = NULL;