aggregator: Don't try to be too smart while allocating pad names
authorNirbheek Chauhan <nirbheek@centricular.com>
Sun, 27 Mar 2016 13:11:30 +0000 (18:41 +0530)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 2 Dec 2017 15:10:26 +0000 (15:10 +0000)
Previously, while allocating the pad number for a new pad, aggregator was
maintaining an interesting relationship between the pad count and the pad
number.

If you requested a sink pad called "sink_6", padcount (which is badly named and
actually means number-of-pads-minus-one) would be set to 6. Which means that if
you then requested a sink pad called "sink_0", it would be assigned the name
"sink_6" again, which fails the non-uniqueness test inside gstelement.c.

This can be fixed by instead setting padcount to be 7 in that case, but this
breaks manual management of pad names by the application since it then becomes
impossible to request a pad called "sink_2". Instead, we fix this by always
directly using the requested name as the sink pad name. Uniqueness of the pad
name is tested separately inside gstreamer core. If no name is requested, we use
the next available pad number.

Note that this is important since the sinkpad numbering in aggregator is not
meaningless. Videoaggregator uses it to decide the Z-order of video frames.

libs/gst/base/gstaggregator.c

index ec297df..ae56672 100644 (file)
@@ -270,7 +270,7 @@ static GstElementClass *aggregator_parent_class = NULL;
 
 struct _GstAggregatorPrivate
 {
-  gint padcount;
+  gint max_padserial;
 
   /* Our state is >= PAUSED */
   gboolean running;             /* protected by src_lock */
@@ -1323,15 +1323,15 @@ gst_aggregator_default_create_new_pad (GstAggregator * self,
   if (req_name == NULL || strlen (req_name) < 6
       || !g_str_has_prefix (req_name, "sink_")) {
     /* no name given when requesting the pad, use next available int */
-    priv->padcount++;
+    serial = ++priv->max_padserial;
   } else {
     /* parse serial number from requested padname */
     serial = g_ascii_strtoull (&req_name[5], NULL, 10);
-    if (serial >= priv->padcount)
-      priv->padcount = serial;
+    if (serial > priv->max_padserial)
+      priv->max_padserial = serial;
   }
 
-  name = g_strdup_printf ("sink_%u", priv->padcount);
+  name = g_strdup_printf ("sink_%u", serial);
   agg_pad = g_object_new (GST_AGGREGATOR_GET_CLASS (self)->sinkpads_type,
       "name", name, "direction", GST_PAD_SINK, "template", templ, NULL);
   g_free (name);
@@ -2011,7 +2011,7 @@ gst_aggregator_init (GstAggregator * self, GstAggregatorClass * klass)
       gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
   g_return_if_fail (pad_template != NULL);
 
-  priv->padcount = -1;
+  priv->max_padserial = -1;
   priv->tags_changed = FALSE;
 
   self->priv->peer_latency_live = FALSE;