caps: add ANY and EMPTY singletons
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 20 Dec 2011 12:14:07 +0000 (13:14 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 20 Dec 2011 12:24:06 +0000 (13:24 +0100)
Add a singleton for ANY and EMPTY caps and make the GST_CAPS_ANY and
GST_CAPS_NONE point to them. This makes the API more consistent now
that the macro does not magically create a ref. It also solves some leaks in
places where the macro was used to register a padtemplate.

gst/gstcaps.c
gst/gstcaps.h

index 8efd341..a48520a 100644 (file)
@@ -114,6 +114,8 @@ static gboolean gst_caps_from_string_inplace (GstCaps * caps,
     const gchar * string);
 
 GType _gst_caps_type = 0;
+GstCaps *_gst_caps_any;
+GstCaps *_gst_caps_empty;
 
 GST_DEFINE_MINI_OBJECT_TYPE (GstCaps, gst_caps);
 
@@ -122,6 +124,9 @@ _priv_gst_caps_initialize (void)
 {
   _gst_caps_type = gst_caps_get_type ();
 
+  _gst_caps_any = gst_caps_new_any ();
+  _gst_caps_empty = gst_caps_new_empty ();
+
   g_value_register_transform_func (_gst_caps_type,
       G_TYPE_STRING, gst_caps_transform_to_string);
 }
index 5ba64be..194441f 100644 (file)
@@ -83,16 +83,18 @@ typedef enum {
  * GST_CAPS_ANY:
  *
  * Means that the element/pad can output 'anything'. Useful for elements
- * that output unknown media, such as filesrc.
+ * that output unknown media, such as filesrc. This macro returns a singleton and
+ * should not be unreffed.
  */
-#define GST_CAPS_ANY              gst_caps_new_any()
+#define GST_CAPS_ANY              _gst_caps_any
 /**
  * GST_CAPS_NONE:
  *
  * The opposite of %GST_CAPS_ANY: it means that the pad/element outputs an
- * undefined media type that can not be detected.
+ * undefined media type that can not be detected. This macro returns a singleton
+ * and should not be unreffed.
  */
-#define GST_CAPS_NONE             gst_caps_new_empty()
+#define GST_CAPS_NONE             _gst_caps_empty
 
 /**
  * GST_STATIC_CAPS_ANY:
@@ -136,6 +138,8 @@ typedef enum {
 typedef struct _GstCaps GstCaps;
 typedef struct _GstStaticCaps GstStaticCaps;
 
+extern GstCaps * _gst_caps_any;
+extern GstCaps * _gst_caps_empty;
 /**
  * GST_CAPS_FLAGS:
  * @caps: a #GstCaps.