From b91093a2e66c765567a53362a2565f0d7d6cb0d3 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Wed, 25 May 2022 02:10:30 +0900 Subject: [PATCH] playbin3: Configure combiner on pad-added if needed When collection is updated, decodebin3 exposes pad first and then streams-selected message is posted. The condition can cause a situation where playbin3 links non-existing combiner/playsink pads (since streams-selected is not posted yet) with new decodebin output pad. This commit will re-check selected/active streams condition on pad-added and reconfigure output if needed. Part-of: --- .../gst/playback/gstplaybin3.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/subprojects/gst-plugins-base/gst/playback/gstplaybin3.c b/subprojects/gst-plugins-base/gst/playback/gstplaybin3.c index b727d163ad..1072705875 100644 --- a/subprojects/gst-plugins-base/gst/playback/gstplaybin3.c +++ b/subprojects/gst-plugins-base/gst/playback/gstplaybin3.c @@ -3021,6 +3021,7 @@ pad_added_cb (GstElement * uridecodebin, GstPad * pad, GstSourceGroup * group) gchar *pad_name; GstPlayBin3 *playbin = group->playbin; GstPad *combine_pad; + GstStreamType selected, active, cur; GST_PLAY_BIN3_SHUTDOWN_LOCK (playbin, shutdown); @@ -3033,10 +3034,13 @@ pad_added_cb (GstElement * uridecodebin, GstPad * pad, GstSourceGroup * group) try exact match first */ if (g_str_has_prefix (pad_name, "video")) { pb_stream_type = PLAYBIN_STREAM_VIDEO; + cur = GST_STREAM_TYPE_VIDEO; } else if (g_str_has_prefix (pad_name, "audio")) { pb_stream_type = PLAYBIN_STREAM_AUDIO; + cur = GST_STREAM_TYPE_AUDIO; } else if (g_str_has_prefix (pad_name, "text")) { pb_stream_type = PLAYBIN_STREAM_TEXT; + cur = GST_STREAM_TYPE_TEXT; } g_free (pad_name); @@ -3051,6 +3055,30 @@ pad_added_cb (GstElement * uridecodebin, GstPad * pad, GstSourceGroup * group) GST_PLAY_BIN3_LOCK (playbin); combine = &playbin->combiner[pb_stream_type]; + /* (uri)decodebin3 will post streams-selected once all pads are expose. + * Therefore this stream might not be marked as selected on pad-added, + * and associated combiner can be null here. + * Marks this stream as selected manually, exposed pad implies it's selected + * already */ + selected = playbin->selected_stream_types | cur; + active = playbin->active_stream_types; + + if (selected != active) { + GST_DEBUG_OBJECT (playbin, + "%s:%s added but not an active stream, marking active", + GST_DEBUG_PAD_NAME (pad)); + playbin->selected_stream_types = selected; + reconfigure_output (playbin); + + /* shutdown state can be changed meantime then combiner will not be + * configured */ + if (g_atomic_int_get (&playbin->shutdown)) { + GST_PLAY_BIN3_UNLOCK (playbin); + GST_PLAY_BIN3_SHUTDOWN_UNLOCK (playbin); + return; + } + } + combine_pad = combiner_control_pad (playbin, combine, pad); control_source_pad (group, pad, combine_pad, combine->stream_type);