From 0e97fba40e796d0302b4ce89f0ddb2cc8427f683 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 3 Jan 2024 14:36:41 +0100 Subject: [PATCH] lavc video: fixed crash when reinit fails Fixed a crash in situation where compressing stream with properties A, then B but init fails and then again A. This can occur when using switcher for 1->2->1 when compress reconf fails for 2. But because `saved_desc` is set if reconf succeeds and was already set on first configure, the state is inconsistent because partially de/configured for 2 but it looks like it is still correctly configured to input 1 because `saved_desc` was not cleared. refers to GH-365 --- src/video_compress/libavcodec.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index 207d66bdb..9e65d4a02 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -3,7 +3,7 @@ * @author Martin Pulec */ /* - * Copyright (c) 2013-2023 CESNET, z. s. p. o. + * Copyright (c) 2013-2024 CESNET, z. s. p. o. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -253,7 +253,7 @@ struct state_video_compress_libav { struct module module_data; struct video_desc saved_desc{}; - struct to_lavc_vid_conv *pixfmt_conversion = nullptr;; + struct to_lavc_vid_conv *pixfmt_conversion = nullptr; AVPacket *pkt = av_packet_alloc(); // for every core - parts of the above AVCodecContext *codec_ctx = nullptr; @@ -1057,6 +1057,7 @@ try_open_remaining_pixfmts(state_video_compress_libav *s, video_desc desc, static bool configure_with(struct state_video_compress_libav *s, struct video_desc desc) { + s->saved_desc = {}; codec_t ug_codec = s->requested_codec_id == VIDEO_CODEC_NONE ? DEFAULT_CODEC : s->requested_codec_id; AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; const AVCodec *codec = nullptr;