2006-07-03 Wim Taymans <wim@fluendo.com>
+ * gst/gstcaps.c: (gst_caps_new_empty), (_gst_caps_free),
+ (gst_caps_unref), (gst_static_caps_get),
+ (gst_caps_append_structure):
+ * gst/gstclock.c: (gst_clock_entry_new), (_gst_clock_id_free):
+ Use GSlice when the glib we build against is >= 2.10
+
+2006-07-03 Wim Taymans <wim@fluendo.com>
+
* gst/gstelement.c: (gst_element_pads_activate):
Small cleanup in pad activation code.
#define IS_WRITABLE(caps) \
(g_atomic_int_get (&(caps)->refcount) == 1)
+#if GLIB_CHECK_VERSION (2, 10, 0)
+#define ALLOC_CAPS() g_slice_new (GstCaps)
+#define FREE_CAPS(caps) g_slice_free (GstCaps, caps)
+#else
+#define ALLOC_CAPS() g_new (GstCaps, 1)
+#define FREE_CAPS(caps) g_free (caps)
+#endif
static void gst_caps_transform_to_string (const GValue * src_value,
GValue * dest_value);
GstCaps *
gst_caps_new_empty (void)
{
- GstCaps *caps = g_new0 (GstCaps, 1);
+ GstCaps *caps = ALLOC_CAPS ();
- g_atomic_int_inc (&caps->refcount);
caps->type = GST_TYPE_CAPS;
+ caps->refcount = 1;
+ caps->flags = 0;
caps->structs = g_ptr_array_new ();
#ifdef DEBUG_REFCOUNT
#ifdef USE_POISONING
memset (caps, 0xff, sizeof (GstCaps));
#endif
- g_free (caps);
+ FREE_CAPS (caps);
}
/**
g_return_if_fail (GST_CAPS_REFCOUNT_VALUE (caps) > 0);
/* if we ended up with the refcount at zero, free the caps */
- if (g_atomic_int_dec_and_test (&caps->refcount)) {
+ if (G_UNLIKELY (g_atomic_int_dec_and_test (&caps->refcount)))
_gst_caps_free (caps);
- }
}
GType
GstCaps *
gst_static_caps_get (GstStaticCaps * static_caps)
{
- GstCaps *caps = (GstCaps *) static_caps;
- gboolean ret;
+ GstCaps *caps;
+
+ g_return_val_if_fail (static_caps != NULL, NULL);
+
+ caps = (GstCaps *) static_caps;
if (caps->type == 0) {
- if (static_caps->string == NULL) {
- g_warning ("static caps is NULL");
- return NULL;
- }
+ if (G_UNLIKELY (static_caps->string == NULL))
+ goto no_string;
caps->type = GST_TYPE_CAPS;
/* initialize the caps to a refcount of 1 so the caps can be writable... */
gst_atomic_int_set (&caps->refcount, 1);
caps->structs = g_ptr_array_new ();
- ret = gst_caps_from_string_inplace (caps, static_caps->string);
- if (!ret) {
+ /* convert to string */
+ if (G_UNLIKELY (!gst_caps_from_string_inplace (caps, static_caps->string)))
g_critical ("Could not convert static caps \"%s\"", static_caps->string);
- }
}
/* ref the caps, makes it not writable */
gst_caps_ref (caps);
return caps;
+
+ /* ERRORS */
+no_string:
+ {
+ g_warning ("static caps string is NULL");
+ return NULL;
+ }
}
/* manipulation */
-
static GstStructure *
gst_caps_remove_and_get_structure (GstCaps * caps, guint idx)
{
g_return_if_fail (GST_IS_CAPS (caps));
g_return_if_fail (IS_WRITABLE (caps));
- if (structure) {
+ if (G_LIKELY (structure)) {
g_return_if_fail (structure->parent_refcount == NULL);
#if 0
#ifdef USE_POISONING
static GstAllocTrace *_gst_clock_entry_trace;
#endif
+#if GLIB_CHECK_VERSION (2, 10, 0)
+#define ALLOC_ENTRY() g_slice_new (GstClockEntry)
+#define FREE_ENTRY(entry) g_slice_free (GstClockEntry, entry)
+#else
+#define ALLOC_ENTRY() g_new (GstClockEntry, 1)
+#define FREE_ENTRY(entry) g_free (entry)
+#endif
+
/* #define DEBUGGING_ENABLED */
#define DEFAULT_STATS FALSE
{
GstClockEntry *entry;
- /* FIXME, use g_slice, we do this a lot and potentially from
- * different threads. */
- entry = g_new0 (GstClockEntry, 1);
+ entry = ALLOC_ENTRY ();
#ifndef GST_DISABLE_TRACE
gst_alloc_trace_new (_gst_clock_entry_trace, entry);
#endif
gst_atomic_int_set (&entry->refcount, 1);
entry->clock = clock;
+ entry->type = type;
entry->time = time;
entry->interval = interval;
- entry->type = type;
entry->status = GST_CLOCK_BUSY;
+ entry->func = NULL;
+ entry->user_data = NULL;
return (GstClockID) entry;
}
#ifndef GST_DISABLE_TRACE
gst_alloc_trace_free (_gst_clock_entry_trace, id);
#endif
- g_free (id);
+ FREE_ENTRY (id);
}
/**