tsmux: When selecting random PIDs, name the pads according to those PIDs
authorSebastian Dröge <sebastian@centricular.com>
Thu, 10 Jun 2021 08:42:24 +0000 (11:42 +0300)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 23 Jun 2021 14:59:43 +0000 (14:59 +0000)
Some elements will make use of the automatically generated names to
create new pads in future muxer instances, for example splitmuxsink.

Previously we would've created a pad with a random pid that would become
"sink_0", and then on a new muxer instance a pad "sink_0" and tsmux
would've then failed because 0 is not a valid PID.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2318>

gst/mpegtsmux/gstbasetsmux.c

index 50009af..5fc5ee0 100644 (file)
@@ -1353,6 +1353,7 @@ gst_base_ts_mux_request_new_pad (GstElement * element, GstPadTemplate * templ,
   GstBaseTsMux *mux = GST_BASE_TS_MUX (element);
   gint pid = -1;
   GstPad *pad = NULL;
+  gchar *free_name = NULL;
 
   if (name != NULL && sscanf (name, "sink_%d", &pid) == 1) {
     if (tsmux_find_stream (mux->tsmux, pid))
@@ -1365,6 +1366,9 @@ gst_base_ts_mux_request_new_pad (GstElement * element, GstPadTemplate * templ,
     do {
       pid = tsmux_get_new_pid (mux->tsmux);
     } while (gst_base_ts_mux_has_pad_with_pid (mux, pid));
+
+    /* Name the pad correctly after the selected pid */
+    name = free_name = g_strdup_printf ("sink_%d", pid);
   }
 
   pad = (GstPad *)
@@ -1374,6 +1378,8 @@ gst_base_ts_mux_request_new_pad (GstElement * element, GstPadTemplate * templ,
   gst_base_ts_mux_pad_reset (GST_BASE_TS_MUX_PAD (pad));
   GST_BASE_TS_MUX_PAD (pad)->pid = pid;
 
+  g_free (free_name);
+
   return pad;
 
   /* ERRORS */
@@ -1387,7 +1393,7 @@ stream_exists:
 invalid_stream_pid:
   {
     GST_ELEMENT_ERROR (element, STREAM, MUX,
-        ("Invalid Elementary stream PID (< 0x40)"), (NULL));
+        ("Invalid Elementary stream PID (0x%02u < 0x40)", pid), (NULL));
     return NULL;
   }
 }