mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 10:41:04 +00:00
miniobject: cleanups
Use the stored size in the miniobject to free the miniobject. Refactor some init methods.
This commit is contained in:
parent
3169e8414b
commit
b108e3b999
7 changed files with 52 additions and 35 deletions
|
@ -282,7 +282,22 @@ _gst_buffer_free (GstBuffer * buffer)
|
|||
if (buffer->parent)
|
||||
gst_buffer_unref (buffer->parent);
|
||||
|
||||
g_slice_free (GstBuffer, buffer);
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (buffer), buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_buffer_init (GstBuffer * buffer, gsize size)
|
||||
{
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (buffer), _gst_buffer_type, size);
|
||||
|
||||
buffer->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_copy;
|
||||
buffer->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_free;
|
||||
|
||||
GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
|
||||
GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
|
||||
GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE;
|
||||
GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE;
|
||||
GST_BUFFER_FREE_FUNC (buffer) = g_free;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -302,17 +317,7 @@ gst_buffer_new (void)
|
|||
newbuf = g_slice_new0 (GstBuffer);
|
||||
GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf);
|
||||
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (newbuf),
|
||||
_gst_buffer_type, sizeof (GstBuffer));
|
||||
|
||||
newbuf->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_copy;
|
||||
newbuf->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_free;
|
||||
|
||||
GST_BUFFER_TIMESTAMP (newbuf) = GST_CLOCK_TIME_NONE;
|
||||
GST_BUFFER_DURATION (newbuf) = GST_CLOCK_TIME_NONE;
|
||||
GST_BUFFER_OFFSET (newbuf) = GST_BUFFER_OFFSET_NONE;
|
||||
GST_BUFFER_OFFSET_END (newbuf) = GST_BUFFER_OFFSET_NONE;
|
||||
GST_BUFFER_FREE_FUNC (newbuf) = g_free;
|
||||
gst_buffer_init (newbuf, sizeof (GstBuffer));
|
||||
|
||||
return newbuf;
|
||||
}
|
||||
|
|
|
@ -212,7 +212,17 @@ _gst_buffer_list_free (GstBufferList * list)
|
|||
}
|
||||
g_list_free (list->buffers);
|
||||
|
||||
g_slice_free (GstBufferList, list);
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (list), list);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_buffer_list_init (GstBufferList * list, gsize size)
|
||||
{
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (list), _gst_buffer_list_type,
|
||||
size);
|
||||
|
||||
list->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_list_copy;
|
||||
list->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_list_free;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,14 +245,10 @@ gst_buffer_list_new (void)
|
|||
|
||||
list = g_slice_new0 (GstBufferList);
|
||||
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (list), _gst_buffer_list_type,
|
||||
sizeof (GstBufferList));
|
||||
|
||||
list->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_list_copy;
|
||||
list->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_list_free;
|
||||
|
||||
GST_LOG ("new %p", list);
|
||||
|
||||
gst_buffer_list_init (list, sizeof (GstBufferList));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -181,14 +181,13 @@ _gst_caps_free (GstCaps * caps)
|
|||
#ifdef DEBUG_REFCOUNT
|
||||
GST_CAT_LOG (GST_CAT_CAPS, "freeing caps %p", caps);
|
||||
#endif
|
||||
g_slice_free (GstCaps, caps);
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (caps), caps);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_caps_init (GstCaps * caps)
|
||||
gst_caps_init (GstCaps * caps, gsize size)
|
||||
{
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (caps),
|
||||
_gst_caps_type, sizeof (GstCaps));
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (caps), _gst_caps_type, size);
|
||||
|
||||
caps->mini_object.copy = (GstMiniObjectCopyFunction) _gst_caps_copy;
|
||||
caps->mini_object.dispose = NULL;
|
||||
|
@ -218,7 +217,7 @@ gst_caps_new_empty (void)
|
|||
|
||||
caps = g_slice_new (GstCaps);
|
||||
|
||||
gst_caps_init (caps);
|
||||
gst_caps_init (caps, sizeof (GstCaps));
|
||||
|
||||
#ifdef DEBUG_REFCOUNT
|
||||
GST_CAT_LOG (GST_CAT_CAPS, "created caps %p", caps);
|
||||
|
@ -415,13 +414,13 @@ gst_static_caps_get (GstStaticCaps * static_caps)
|
|||
* real caps, refcount last. We do this because we must leave the refcount
|
||||
* of the result caps to 0 so that other threads don't run away with the
|
||||
* caps while we are constructing it. */
|
||||
gst_caps_init (&temp);
|
||||
gst_caps_init (&temp, sizeof (GstCaps));
|
||||
|
||||
/* convert to string */
|
||||
if (G_UNLIKELY (!gst_caps_from_string_inplace (&temp, string)))
|
||||
g_critical ("Could not convert static caps \"%s\"", string);
|
||||
|
||||
gst_caps_init (caps);
|
||||
gst_caps_init (caps, sizeof (GstCaps));
|
||||
/* now copy stuff over to the real caps. */
|
||||
GST_CAPS_FLAGS (caps) = GST_CAPS_FLAGS (&temp);
|
||||
caps->structs = temp.structs;
|
||||
|
|
|
@ -216,10 +216,10 @@ _gst_event_free (GstEvent * event)
|
|||
gst_structure_free (event->structure);
|
||||
}
|
||||
|
||||
g_slice_free (GstEvent, event);
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event);
|
||||
}
|
||||
|
||||
static void gst_event_init (GstEvent * event, GstEventType type);
|
||||
static void gst_event_init (GstEvent * event, gsize size, GstEventType type);
|
||||
|
||||
static GstEvent *
|
||||
_gst_event_copy (GstEvent * event)
|
||||
|
@ -228,7 +228,7 @@ _gst_event_copy (GstEvent * event)
|
|||
|
||||
copy = g_slice_new0 (GstEvent);
|
||||
|
||||
gst_event_init (copy, GST_EVENT_TYPE (event));
|
||||
gst_event_init (copy, sizeof (GstEvent), GST_EVENT_TYPE (event));
|
||||
|
||||
GST_EVENT_TIMESTAMP (copy) = GST_EVENT_TIMESTAMP (event);
|
||||
GST_EVENT_SEQNUM (copy) = GST_EVENT_SEQNUM (event);
|
||||
|
@ -245,10 +245,9 @@ _gst_event_copy (GstEvent * event)
|
|||
}
|
||||
|
||||
static void
|
||||
gst_event_init (GstEvent * event, GstEventType type)
|
||||
gst_event_init (GstEvent * event, gsize size, GstEventType type)
|
||||
{
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (event),
|
||||
_gst_event_type, sizeof (GstEvent));
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (event), _gst_event_type, size);
|
||||
|
||||
event->mini_object.copy = (GstMiniObjectCopyFunction) _gst_event_copy;
|
||||
event->mini_object.free = (GstMiniObjectFreeFunction) _gst_event_free;
|
||||
|
@ -268,7 +267,7 @@ gst_event_new (GstEventType type)
|
|||
GST_CAT_DEBUG (GST_CAT_EVENT, "creating new event %p %s %d", event,
|
||||
gst_event_type_get_name (type), type);
|
||||
|
||||
gst_event_init (event, type);
|
||||
gst_event_init (event, sizeof (GstEvent), type);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ _gst_message_free (GstMessage * message)
|
|||
gst_structure_free (message->structure);
|
||||
}
|
||||
|
||||
g_slice_free (GstMessage, message);
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message);
|
||||
}
|
||||
|
||||
static GstMessage *
|
||||
|
|
|
@ -133,6 +133,14 @@ typedef enum
|
|||
*/
|
||||
#define GST_MINI_OBJECT_REFCOUNT_VALUE(obj) (g_atomic_int_get (&(GST_MINI_OBJECT_CAST(obj))->refcount))
|
||||
|
||||
/**
|
||||
* GST_MINI_OBJECT_SIZE:
|
||||
* @obj: a #GstMiniObject
|
||||
*
|
||||
* Get the allocated size of @obj.
|
||||
*/
|
||||
#define GST_MINI_OBJECT_SIZE(obj) ((GST_MINI_OBJECT_CAST(obj))->size)
|
||||
|
||||
/**
|
||||
* GstMiniObject:
|
||||
* @instance: type instance
|
||||
|
|
|
@ -319,7 +319,7 @@ _gst_query_free (GstQuery * query)
|
|||
gst_structure_free (query->structure);
|
||||
}
|
||||
|
||||
g_slice_free (GstQuery, query);
|
||||
g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query);
|
||||
}
|
||||
|
||||
static GstQuery *gst_query_new (GstQueryType type, GstStructure * structure);
|
||||
|
|
Loading…
Reference in a new issue