diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-period.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-period.c index 35925cfccc..429b9ece83 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-period.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-period.c @@ -212,6 +212,33 @@ gst_adaptive_demux_period_transfer_selection (GstAdaptiveDemux * demux, } } +/* called with TRACKS_LOCK taken. Takes ownership of the stream */ +gboolean +gst_adaptive_demux_period_add_stream (GstAdaptiveDemuxPeriod * period, + GstAdaptiveDemux2Stream * stream) +{ + GST_LOG ("period %d stream: %" GST_PTR_FORMAT, period->period_num, stream); + + /* Set the stream's period */ + stream->period = period; + period->streams = g_list_append (period->streams, stream); + + /* Add any pre-existing stream tracks to our set */ + if (stream->tracks) { + GList *iter; + for (iter = stream->tracks; iter; iter = iter->next) { + GstAdaptiveDemuxTrack *track = (GstAdaptiveDemuxTrack *) iter->data; + if (!gst_adaptive_demux_period_add_track (period, track)) { + GST_ERROR_OBJECT (period->demux, "period %d failed to add track %p", + period->period_num, track); + return FALSE; + } + } + } + + return TRUE; +} + /* called with TRACKS_LOCK taken */ gboolean gst_adaptive_demux_period_add_track (GstAdaptiveDemuxPeriod * period, diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h index d5809ac414..3fa120626d 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux-private.h @@ -234,6 +234,8 @@ GstAdaptiveDemuxPeriod * gst_adaptive_demux_period_new (GstAdaptiveDemux * demux GstAdaptiveDemuxPeriod * gst_adaptive_demux_period_ref (GstAdaptiveDemuxPeriod * period); void gst_adaptive_demux_period_unref (GstAdaptiveDemuxPeriod * period); +gboolean gst_adaptive_demux_period_add_stream (GstAdaptiveDemuxPeriod * period, + GstAdaptiveDemux2Stream * stream); gboolean gst_adaptive_demux_period_add_track (GstAdaptiveDemuxPeriod * period, GstAdaptiveDemuxTrack * track); gboolean gst_adaptive_demux_track_add_elements (GstAdaptiveDemuxTrack * track, diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c index f9fa8f9f17..aa517e9414 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c @@ -3854,20 +3854,14 @@ gst_adaptive_demux2_add_stream (GstAdaptiveDemux * demux, return FALSE; } stream->demux = demux; - stream->period = demux->input_period; - demux->input_period->streams = - g_list_append (demux->input_period->streams, stream); - if (stream->tracks) { - GList *iter; - for (iter = stream->tracks; iter; iter = iter->next) - if (!gst_adaptive_demux_period_add_track (demux->input_period, - (GstAdaptiveDemuxTrack *) iter->data)) { - GST_ERROR_OBJECT (demux, "Failed to add track elements"); - TRACKS_UNLOCK (demux); - return FALSE; - } + /* Takes ownership of the stream and adds the tracks */ + if (!gst_adaptive_demux_period_add_stream (demux->input_period, stream)) { + GST_ERROR_OBJECT (demux, "Failed to add stream to period"); + TRACKS_UNLOCK (demux); + return FALSE; } + TRACKS_UNLOCK (demux); return TRUE; }