s/gst_element_install_std_props/gst_element_class_install_std_props/ -- it just makes...
[platform/upstream/gstreamer.git] / gst / gstpad.c
index fbf2d8a..9ac7a1b 100644 (file)
@@ -2009,6 +2009,41 @@ gst_padtemplate_init (GstPadTemplate *templ)
 {
 }
 
+/* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
+ * sense.
+ * SOMETIMES padtemplates can do whatever they want, they are provided by the
+ * element.
+ * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
+ * 'sink%d' template is automatically selected), so we need to restrict their
+ * naming.
+ */
+static gboolean
+name_is_valid (const gchar *name, GstPadPresence presence)
+{
+  const gchar *str;
+  
+  if (presence == GST_PAD_ALWAYS) {
+    if (strchr (name, '%')) {
+      g_warning ("invalid name template %s: conversion specifications are not"
+                 " allowed for GST_PAD_ALWAYS padtemplates", name);
+      return FALSE;
+    }
+  } else if (presence == GST_PAD_REQUEST) {
+    if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
+      g_warning ("invalid name template %s: only one conversion specification"
+                 " allowed in GST_PAD_REQUEST padtemplate", name);
+      return FALSE;
+    }
+    if (str && (*(str+1) != 's' && *(str+1) != 'd')) {
+      g_warning ("invalid name template %s: conversion specification must be of"
+                 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
+      return FALSE;
+    }
+  }
+  
+  return TRUE;
+}
+
 /**
  * gst_padtemplate_new:
  * @name_template: the name template
@@ -2032,6 +2067,9 @@ gst_padtemplate_new (gchar *name_template,
 
   g_return_val_if_fail (name_template != NULL, NULL);
 
+  if (!name_is_valid (name_template, presence))
+    return NULL;
+
   new = g_object_new(gst_padtemplate_get_type () ,NULL);
 
   GST_PADTEMPLATE_NAME_TEMPLATE (new) = name_template;