caps: _do_simplify() -> _simplify()
[platform/upstream/gstreamer.git] / gst / gstpadtemplate.c
index 116cd77..ab516a9 100644 (file)
  * </example>
  *
  * The following example shows you how to add the padtemplate to an
- * element class, this is usually done in the base_init of the class:
+ * element class, this is usually done in the class_init of the class:
  * <informalexample>
  *   <programlisting>
  *   static void
- *   my_element_base_init (gpointer g_class)
+ *   my_element_class_init (GstMyElementClass *klass)
  *   {
- *     GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
+ *     GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
  *
  *     gst_element_class_add_pad_template (gstelement_class,
  *         gst_static_pad_template_get (&amp;my_template));
 #include "gstpad.h"
 #include "gstpadtemplate.h"
 #include "gstenumtypes.h"
-#include "gstmarshal.h"
 #include "gstutils.h"
 #include "gstinfo.h"
 #include "gsterror.h"
@@ -123,7 +122,6 @@ enum
   LAST_SIGNAL
 };
 
-static GstObject *parent_class = NULL;
 static guint gst_pad_template_signals[LAST_SIGNAL] = { 0 };
 
 static void gst_pad_template_dispose (GObject * object);
@@ -132,6 +130,7 @@ static void gst_pad_template_set_property (GObject * object, guint prop_id,
 static void gst_pad_template_get_property (GObject * object, guint prop_id,
     GValue * value, GParamSpec * pspec);
 
+#define gst_pad_template_parent_class parent_class
 G_DEFINE_TYPE (GstPadTemplate, gst_pad_template, GST_TYPE_OBJECT);
 
 static void
@@ -143,8 +142,6 @@ gst_pad_template_class_init (GstPadTemplateClass * klass)
   gobject_class = (GObjectClass *) klass;
   gstobject_class = (GstObjectClass *) klass;
 
-  parent_class = g_type_class_peek_parent (klass);
-
   /**
    * GstPadTemplate::pad-created:
    * @pad_template: the object which received the signal.
@@ -155,7 +152,7 @@ gst_pad_template_class_init (GstPadTemplateClass * klass)
   gst_pad_template_signals[TEMPL_PAD_CREATED] =
       g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
       G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
-      NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
+      NULL, NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
 
   gobject_class->dispose = gst_pad_template_dispose;
 
@@ -219,20 +216,6 @@ gst_pad_template_class_init (GstPadTemplateClass * klass)
 static void
 gst_pad_template_init (GstPadTemplate * templ)
 {
-  /* FIXME 0.11: Does anybody remember why this is here? If not, let's
-   * change it for 0.11 and let gst_element_class_add_pad_template() for
-   * example ref/sink the pad templates.
-   */
-  /* We ensure that the pad template we're creating has a sunken reference.
-   * Inconsistencies in pad templates being floating or sunken has caused
-   * problems in the past with leaks, etc.
-   *
-   * For consistency, then, we only produce them  with sunken references
-   * owned by the creator of the object
-   */
-  if (GST_OBJECT_IS_FLOATING (templ)) {
-    gst_object_ref_sink (templ);
-  }
 }
 
 static void
@@ -288,17 +271,7 @@ name_is_valid (const gchar * name, GstPadPresence presence)
   return TRUE;
 }
 
-GType
-gst_static_pad_template_get_type (void)
-{
-  static GType staticpadtemplate_type = 0;
-
-  if (G_UNLIKELY (staticpadtemplate_type == 0)) {
-    staticpadtemplate_type =
-        g_pointer_type_register_static ("GstStaticPadTemplate");
-  }
-  return staticpadtemplate_type;
-}
+G_DEFINE_POINTER_TYPE (GstStaticPadTemplate, gst_static_pad_template);
 
 /**
  * gst_static_pad_template_get:
@@ -336,14 +309,12 @@ gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
  * @name_template: the name template.
  * @direction: the #GstPadDirection of the template.
  * @presence: the #GstPadPresence of the pad.
- * @caps: (transfer full): a #GstCaps set for the template. The caps are
- *     taken ownership of.
+ * @caps: (transfer none): a #GstCaps set for the template.
  *
  * Creates a new pad template with a name according to the given template
- * and with the given arguments. This functions takes ownership of the provided
- * caps, so be sure to not use them afterwards.
+ * and with the given arguments.
  *
- * Returns: (transfer full): a new #GstPadTemplate.
+ * Returns: (transfer floating): a new #GstPadTemplate.
  */
 GstPadTemplate *
 gst_pad_template_new (const gchar * name_template,
@@ -359,7 +330,6 @@ gst_pad_template_new (const gchar * name_template,
       || presence == GST_PAD_SOMETIMES || presence == GST_PAD_REQUEST, NULL);
 
   if (!name_is_valid (name_template, presence)) {
-    gst_caps_unref (caps);
     return NULL;
   }
 
@@ -367,8 +337,6 @@ gst_pad_template_new (const gchar * name_template,
       "name", name_template, "name-template", name_template,
       "direction", direction, "presence", presence, "caps", caps, NULL);
 
-  gst_caps_unref (caps);
-
   return new;
 }
 
@@ -388,7 +356,7 @@ gst_static_pad_template_get_caps (GstStaticPadTemplate * templ)
 {
   g_return_val_if_fail (templ, NULL);
 
-  return (GstCaps *) gst_static_caps_get (&templ->static_caps);
+  return gst_static_caps_get (&templ->static_caps);
 }
 
 /**
@@ -397,15 +365,18 @@ gst_static_pad_template_get_caps (GstStaticPadTemplate * templ)
  *
  * Gets the capabilities of the pad template.
  *
- * Returns: (transfer none): the #GstCaps of the pad template. If you need to
- *     keep a reference to the caps, take a ref (see gst_caps_ref ()).
+ * Returns: (transfer full): the #GstCaps of the pad template.
+ * Unref after usage.
  */
 GstCaps *
 gst_pad_template_get_caps (GstPadTemplate * templ)
 {
+  GstCaps *caps;
   g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
 
-  return GST_PAD_TEMPLATE_CAPS (templ);
+  caps = GST_PAD_TEMPLATE_CAPS (templ);
+
+  return (caps ? gst_caps_ref (caps) : NULL);
 }
 
 /**
@@ -439,12 +410,7 @@ gst_pad_template_set_property (GObject * object, guint prop_id,
           (GstPadPresence) g_value_get_enum (value);
       break;
     case PROP_CAPS:
-      /* allow caps == NULL for backwards compatibility (ie. g_object_new()
-       * called without any of the new properties) (FIXME 0.11) */
-      if (g_value_get_boxed (value) != NULL) {
-        GST_PAD_TEMPLATE_CAPS (object) =
-            gst_caps_copy (g_value_get_boxed (value));
-      }
+      GST_PAD_TEMPLATE_CAPS (object) = g_value_dup_boxed (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);