summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2021-06-10 11:36:43 +0300
committerTim-Philipp Müller <tim@centricular.com>2021-06-24 15:07:45 +0100
commitf88b4df4331bbd85cc2d76fd71763515fb173684 (patch)
tree7a8df539f0f93103f9a7dadd6c04aba6258457c6
parent13ef98406abd96e2e0b79300006eecb8f35251c5 (diff)
downloadgstreamer-plugins-bad-f88b4df4331bbd85cc2d76fd71763515fb173684.tar.gz
tsmux: Recheck existing pad PIDs when requesting a new pad with a random pid
Previously pads might have been requested already (e.g. in NULL state), then reset was called (e.g. because changing state) and then a new pad was requested. Resetting is re-creating the internal muxer object and as such resetting the pid counter, so the next requested pad would get the same pid as the first requested pad which then leads to collisions. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2357>
-rw-r--r--gst/mpegtsmux/gstbasetsmux.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/gst/mpegtsmux/gstbasetsmux.c b/gst/mpegtsmux/gstbasetsmux.c
index 6e66f4d87..79c890d02 100644
--- a/gst/mpegtsmux/gstbasetsmux.c
+++ b/gst/mpegtsmux/gstbasetsmux.c
@@ -1263,6 +1263,26 @@ write_fail:
}
/* GstElement implementation */
+static gboolean
+gst_base_ts_mux_has_pad_with_pid (GstBaseTsMux * mux, guint16 pid)
+{
+ GList *l;
+ gboolean res = FALSE;
+
+ GST_OBJECT_LOCK (mux);
+
+ for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
+ GstBaseTsMuxPad *tpad = GST_BASE_TS_MUX_PAD (l->data);
+
+ if (tpad->pid == pid) {
+ res = TRUE;
+ break;
+ }
+ }
+
+ GST_OBJECT_UNLOCK (mux);
+ return res;
+}
static GstPad *
gst_base_ts_mux_request_new_pad (GstElement * element, GstPadTemplate * templ,
@@ -1280,7 +1300,9 @@ gst_base_ts_mux_request_new_pad (GstElement * element, GstPadTemplate * templ,
if (pid < TSMUX_START_ES_PID)
goto invalid_stream_pid;
} else {
- pid = tsmux_get_new_pid (mux->tsmux);
+ do {
+ pid = tsmux_get_new_pid (mux->tsmux);
+ } while (gst_base_ts_mux_has_pad_with_pid (mux, pid));
}
pad = (GstPad *)