aggregator: Don't try to be too smart while allocating pad names

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.
This commit is contained in:
Nirbheek Chauhan 2016-03-27 18:41:30 +05:30 committed by Tim-Philipp Müller
parent f42b7042d7
commit c18ef6d8a1

View 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;