avdemux: Fix deadlock when serialized events are received from upstream while opening

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3657

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7362>
This commit is contained in:
Sebastian Dröge 2024-08-15 11:42:47 +03:00 committed by GStreamer Marge Bot
parent 132ef7eb11
commit 0db6ce0f11

View file

@ -67,6 +67,8 @@ struct _GstFFMpegDemux
guint group_id; guint group_id;
AVFormatContext *context; AVFormatContext *context;
/* set while avformat_open_input() is called */
gboolean opening;
GstFFStream *streams[MAX_STREAMS]; GstFFStream *streams[MAX_STREAMS];
@ -1261,7 +1263,9 @@ gst_ffmpegdemux_open (GstFFMpegDemux * demux)
demux->context = avformat_alloc_context (); demux->context = avformat_alloc_context ();
demux->context->pb = iocontext; demux->context->pb = iocontext;
demux->opening = TRUE;
res = avformat_open_input (&demux->context, uri, oclass->in_plugin, NULL); res = avformat_open_input (&demux->context, uri, oclass->in_plugin, NULL);
demux->opening = FALSE;
g_free (uri); g_free (uri);
@ -1724,10 +1728,12 @@ gst_ffmpegdemux_sink_event (GstPad * sinkpad, GstObject * parent,
/* for a serialized event, wait until an earlier data is gone, /* for a serialized event, wait until an earlier data is gone,
* though this is no guarantee as to when task is done with it. * though this is no guarantee as to when task is done with it.
* *
* If the demuxer isn't opened, push straight away, since we'll * If the demuxer isn't opened yet, i.e. this is called as part of opening
* be waiting against a cond that will never be signalled. */ * the demuxer, queue up the events for sending them at a later time since
* we'll otherwise be waiting against a cond that will never be signalled.
*/
if (GST_EVENT_IS_SERIALIZED (event)) { if (GST_EVENT_IS_SERIALIZED (event)) {
if (demux->context) { if (demux->context && !demux->opening) {
GST_FFMPEG_PIPE_MUTEX_LOCK (ffpipe); GST_FFMPEG_PIPE_MUTEX_LOCK (ffpipe);
while (!ffpipe->needed) while (!ffpipe->needed)
GST_FFMPEG_PIPE_WAIT (ffpipe); GST_FFMPEG_PIPE_WAIT (ffpipe);