From 12aefaa078c380bb6ebe1fffe9134908e6fae347 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 14 Jun 2012 17:11:11 +0200 Subject: [PATCH] miniobject: remove the size field The size field is used by subclasses to store the total allocated size of the memory for this miniobject. Because miniobject doesn't really do anything with this field we can move it to the subclasses. --- gst/gstbuffer.c | 9 +++++++-- gst/gstbufferlist.c | 9 ++++++--- gst/gstcaps.c | 8 ++++++-- gst/gstevent.c | 11 ++++++++--- gst/gstmemory.c | 15 +++++++++------ gst/gstmessage.c | 14 +++++++++----- gst/gstminiobject.c | 3 +-- gst/gstminiobject.h | 12 +----------- gst/gstquery.c | 9 ++++++--- gst/gstsample.c | 8 +++++--- gst/gsttaglist.c | 11 ++++++++--- 11 files changed, 66 insertions(+), 43 deletions(-) diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index 37d4bf89ef..41bfe37cbf 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -138,6 +138,7 @@ struct _GstMetaItem #define GST_BUFFER_MEM_MAX 16 +#define GST_BUFFER_SLICE_SIZE(b) (((GstBufferImpl *)(b))->slice_size) #define GST_BUFFER_MEM_LEN(b) (((GstBufferImpl *)(b))->len) #define GST_BUFFER_MEM_ARRAY(b) (((GstBufferImpl *)(b))->mem) #define GST_BUFFER_MEM_PTR(b,i) (((GstBufferImpl *)(b))->mem[i]) @@ -148,6 +149,8 @@ typedef struct { GstBuffer buffer; + gsize slice_size; + /* the memory blocks */ guint len; GstMemory *mem[GST_BUFFER_MEM_MAX]; @@ -505,7 +508,7 @@ _gst_buffer_free (GstBuffer * buffer) /* get the size, when unreffing the memory, we could also unref the buffer * itself */ - msize = GST_MINI_OBJECT_SIZE (buffer); + msize = GST_BUFFER_SLICE_SIZE (buffer); /* free our memory */ len = GST_BUFFER_MEM_LEN (buffer); @@ -522,7 +525,7 @@ _gst_buffer_free (GstBuffer * buffer) static void gst_buffer_init (GstBufferImpl * buffer, gsize size) { - gst_mini_object_init (GST_MINI_OBJECT_CAST (buffer), _gst_buffer_type, size); + gst_mini_object_init (GST_MINI_OBJECT_CAST (buffer), _gst_buffer_type); buffer->buffer.mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_copy; @@ -531,6 +534,8 @@ gst_buffer_init (GstBufferImpl * buffer, gsize size) buffer->buffer.mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_free; + GST_BUFFER_SLICE_SIZE (buffer) = size; + GST_BUFFER (buffer)->pool = NULL; GST_BUFFER_PTS (buffer) = GST_CLOCK_TIME_NONE; GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE; diff --git a/gst/gstbufferlist.c b/gst/gstbufferlist.c index f3e047eb3d..0e1cd7577c 100644 --- a/gst/gstbufferlist.c +++ b/gst/gstbufferlist.c @@ -54,6 +54,8 @@ struct _GstBufferList { GstMiniObject mini_object; + gsize slice_size; + GArray *array; }; @@ -97,18 +99,19 @@ _gst_buffer_list_free (GstBufferList * list) gst_buffer_unref (g_array_index (list->array, GstBuffer *, i)); g_array_free (list->array, TRUE); - g_slice_free1 (GST_MINI_OBJECT_SIZE (list), list); + g_slice_free1 (list->slice_size, list); } static void gst_buffer_list_init (GstBufferList * list, gsize size, guint asize) { - gst_mini_object_init (GST_MINI_OBJECT_CAST (list), _gst_buffer_list_type, - size); + gst_mini_object_init (GST_MINI_OBJECT_CAST (list), _gst_buffer_list_type); list->mini_object.copy = (GstMiniObjectCopyFunction) _gst_buffer_list_copy; list->mini_object.free = (GstMiniObjectFreeFunction) _gst_buffer_list_free; + list->slice_size = size; + list->array = g_array_sized_new (FALSE, FALSE, sizeof (GstBuffer *), asize); GST_LOG ("init %p", list); diff --git a/gst/gstcaps.c b/gst/gstcaps.c index ec95ed5891..68ed8c84d4 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -75,9 +75,12 @@ typedef struct _GstCapsImpl { GstCaps caps; + gsize slice_size; + GPtrArray *array; } GstCapsImpl; +#define GST_CAPS_SLICE_SIZE(c) (((GstCapsImpl *)(c))->slice_size) #define GST_CAPS_ARRAY(c) (((GstCapsImpl *)(c))->array) #define GST_CAPS_LEN(c) (GST_CAPS_ARRAY(c)->len) @@ -179,18 +182,19 @@ _gst_caps_free (GstCaps * caps) #ifdef DEBUG_REFCOUNT GST_CAT_TRACE (GST_CAT_CAPS, "freeing caps %p", caps); #endif - g_slice_free1 (GST_MINI_OBJECT_SIZE (caps), caps); + g_slice_free1 (GST_CAPS_SLICE_SIZE (caps), caps); } static void gst_caps_init (GstCaps * caps, gsize size) { - gst_mini_object_init (GST_MINI_OBJECT_CAST (caps), _gst_caps_type, size); + gst_mini_object_init (GST_MINI_OBJECT_CAST (caps), _gst_caps_type); caps->mini_object.copy = (GstMiniObjectCopyFunction) _gst_caps_copy; caps->mini_object.dispose = NULL; caps->mini_object.free = (GstMiniObjectFreeFunction) _gst_caps_free; + GST_CAPS_SLICE_SIZE (caps) = size; /* the 32 has been determined by logging caps sizes in _gst_caps_free * but g_ptr_array uses 16 anyway if it expands once, so this does not help * in practice diff --git a/gst/gstevent.c b/gst/gstevent.c index 3ba388a8b7..c4359692bc 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -92,9 +92,12 @@ typedef struct { GstEvent event; + gsize slice_size; + GstStructure *structure; } GstEventImpl; +#define GST_EVENT_SLICE_SIZE(e) (((GstEventImpl *)(e))->slice_size) #define GST_EVENT_STRUCTURE(e) (((GstEventImpl *)(e))->structure) typedef struct @@ -229,7 +232,7 @@ _gst_event_free (GstEvent * event) gst_structure_free (s); } - g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event); + g_slice_free1 (GST_EVENT_SLICE_SIZE (event), event); } static void gst_event_init (GstEventImpl * event, gsize size, @@ -262,11 +265,13 @@ _gst_event_copy (GstEvent * event) static void gst_event_init (GstEventImpl * event, gsize size, GstEventType type) { - gst_mini_object_init (GST_MINI_OBJECT_CAST (event), _gst_event_type, size); + gst_mini_object_init (GST_MINI_OBJECT_CAST (event), _gst_event_type); event->event.mini_object.copy = (GstMiniObjectCopyFunction) _gst_event_copy; event->event.mini_object.free = (GstMiniObjectFreeFunction) _gst_event_free; + GST_EVENT_SLICE_SIZE (event) = size; + GST_EVENT_TYPE (event) = type; GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE; GST_EVENT_SEQNUM (event) = gst_util_seqnum_next (); @@ -318,7 +323,7 @@ gst_event_new_custom (GstEventType type, GstStructure * structure) /* ERRORS */ had_parent: { - g_slice_free1 (GST_MINI_OBJECT_SIZE (event), event); + g_slice_free1 (GST_EVENT_SLICE_SIZE (event), event); g_warning ("structure is already owned by another object"); return NULL; } diff --git a/gst/gstmemory.c b/gst/gstmemory.c index 4bc4674138..bc392907e3 100644 --- a/gst/gstmemory.c +++ b/gst/gstmemory.c @@ -95,6 +95,8 @@ struct _GstAllocator { GstMiniObject mini_object; + gsize slice_size; + GstMemoryInfo info; gpointer user_data; @@ -105,6 +107,7 @@ struct _GstAllocator typedef struct { GstMemory mem; + gsize slice_size; guint8 *data; gpointer user_data; GDestroyNotify notify; @@ -137,8 +140,7 @@ _default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags, gsize maxsize, gsize offset, gsize size, gsize align, gpointer user_data, GDestroyNotify notify) { - gst_mini_object_init (GST_MINI_OBJECT_CAST (mem), GST_TYPE_MEMORY, - slice_size); + gst_mini_object_init (GST_MINI_OBJECT_CAST (mem), GST_TYPE_MEMORY); mem->mem.mini_object.copy = (GstMiniObjectCopyFunction) _gst_memory_copy; mem->mem.mini_object.dispose = NULL; @@ -152,6 +154,7 @@ _default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags, mem->mem.align = align; mem->mem.offset = offset; mem->mem.size = size; + mem->slice_size = slice_size; mem->data = data; mem->user_data = user_data; mem->notify = notify; @@ -254,7 +257,7 @@ _default_mem_free (GstMemoryDefault * mem) if (mem->notify) mem->notify (mem->user_data); - g_slice_free1 (GST_MINI_OBJECT_SIZE (mem), mem); + g_slice_free1 (mem->slice_size, mem); } static GstMemoryDefault * @@ -764,7 +767,7 @@ _gst_allocator_free (GstAllocator * allocator) if (allocator->notify) allocator->notify (allocator->user_data); - g_slice_free1 (GST_MINI_OBJECT_SIZE (allocator), allocator); + g_slice_free1 (allocator->slice_size, allocator); } static GstAllocator * @@ -804,12 +807,12 @@ gst_allocator_new (const GstMemoryInfo * info, gpointer user_data, allocator = g_slice_new0 (GstAllocator); - gst_mini_object_init (GST_MINI_OBJECT_CAST (allocator), - GST_TYPE_ALLOCATOR, sizeof (GstAllocator)); + gst_mini_object_init (GST_MINI_OBJECT_CAST (allocator), GST_TYPE_ALLOCATOR); allocator->mini_object.copy = (GstMiniObjectCopyFunction) _gst_allocator_copy; allocator->mini_object.free = (GstMiniObjectFreeFunction) _gst_allocator_free; + allocator->slice_size = sizeof (GstAllocator); allocator->info = *info; allocator->user_data = user_data; allocator->notify = notify; diff --git a/gst/gstmessage.c b/gst/gstmessage.c index ae03f99c41..948449da7a 100644 --- a/gst/gstmessage.c +++ b/gst/gstmessage.c @@ -64,10 +64,13 @@ typedef struct { GstMessage message; + gsize slice_size; + GstStructure *structure; } GstMessageImpl; -#define GST_MESSAGE_STRUCTURE(m) (((GstMessageImpl *)(m))->structure) +#define GST_MESSAGE_SLICE_SIZE(m) (((GstMessageImpl *)(m))->slice_size) +#define GST_MESSAGE_STRUCTURE(m) (((GstMessageImpl *)(m))->structure) typedef struct { @@ -198,7 +201,7 @@ _gst_message_free (GstMessage * message) gst_structure_free (structure); } - g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message); + g_slice_free1 (GST_MESSAGE_SLICE_SIZE (message), message); } static void @@ -239,14 +242,15 @@ static void gst_message_init (GstMessageImpl * message, gsize size, GstMessageType type, GstObject * src) { - gst_mini_object_init (GST_MINI_OBJECT_CAST (message), _gst_message_type, - size); + gst_mini_object_init (GST_MINI_OBJECT_CAST (message), _gst_message_type); message->message.mini_object.copy = (GstMiniObjectCopyFunction) _gst_message_copy; message->message.mini_object.free = (GstMiniObjectFreeFunction) _gst_message_free; + GST_MESSAGE_SLICE_SIZE (message) = size; + GST_MESSAGE_TYPE (message) = type; if (src) gst_object_ref (src); @@ -298,7 +302,7 @@ gst_message_new_custom (GstMessageType type, GstObject * src, /* ERRORS */ had_parent: { - g_slice_free1 (GST_MINI_OBJECT_SIZE (message), message); + g_slice_free1 (GST_MESSAGE_SLICE_SIZE (message), message); g_warning ("structure is already owned by another object"); return NULL; } diff --git a/gst/gstminiobject.c b/gst/gstminiobject.c index 55d846bb3f..705152a25f 100644 --- a/gst/gstminiobject.c +++ b/gst/gstminiobject.c @@ -80,12 +80,11 @@ _priv_gst_mini_object_initialize (void) * Returns: (transfer full): the new mini-object. */ void -gst_mini_object_init (GstMiniObject * mini_object, GType type, gsize size) +gst_mini_object_init (GstMiniObject * mini_object, GType type) { mini_object->type = type; mini_object->refcount = 1; mini_object->flags = 0; - mini_object->size = size; mini_object->n_weak_refs = 0; mini_object->weak_refs = NULL; diff --git a/gst/gstminiobject.h b/gst/gstminiobject.h index 69843086bf..76cc193d3b 100644 --- a/gst/gstminiobject.h +++ b/gst/gstminiobject.h @@ -149,14 +149,6 @@ 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: * @type: the GType of the object @@ -179,7 +171,6 @@ struct _GstMiniObject { /*< public >*/ /* with COW */ gint refcount; guint flags; - gsize size; GstMiniObjectCopyFunction copy; GstMiniObjectDisposeFunction dispose; @@ -195,8 +186,7 @@ struct _GstMiniObject { } *weak_refs; }; -void gst_mini_object_init (GstMiniObject *mini_object, - GType type, gsize size); +void gst_mini_object_init (GstMiniObject *mini_object, GType type); GstMiniObject * gst_mini_object_copy (const GstMiniObject *mini_object) G_GNUC_MALLOC; gboolean gst_mini_object_is_writable (const GstMiniObject *mini_object); diff --git a/gst/gstquery.c b/gst/gstquery.c index 5fadc9deb7..694113c9c8 100644 --- a/gst/gstquery.c +++ b/gst/gstquery.c @@ -77,10 +77,12 @@ static GType _gst_query_type = 0; typedef struct { GstQuery query; + gsize slice_size; GstStructure *structure; } GstQueryImpl; +#define GST_QUERY_SLICE_SIZE(q) (((GstQueryImpl *)(q))->slice_size) #define GST_QUERY_STRUCTURE(q) (((GstQueryImpl *)(q))->structure) @@ -202,7 +204,7 @@ _gst_query_free (GstQuery * query) gst_structure_free (s); } - g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query); + g_slice_free1 (GST_QUERY_SLICE_SIZE (query), query); } static GstQuery * @@ -223,11 +225,12 @@ _gst_query_copy (GstQuery * query) static void gst_query_init (GstQueryImpl * query, gsize size, GstQueryType type) { - gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, size); + gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type); query->query.mini_object.copy = (GstMiniObjectCopyFunction) _gst_query_copy; query->query.mini_object.free = (GstMiniObjectFreeFunction) _gst_query_free; + GST_QUERY_SLICE_SIZE (query) = size; GST_QUERY_TYPE (query) = type; } @@ -711,7 +714,7 @@ gst_query_new_custom (GstQueryType type, GstStructure * structure) /* ERRORS */ had_parent: { - g_slice_free1 (GST_MINI_OBJECT_SIZE (query), query); + g_slice_free1 (GST_QUERY_SLICE_SIZE (query), query); g_warning ("structure is already owned by another object"); return NULL; } diff --git a/gst/gstsample.c b/gst/gstsample.c index 4a7551b744..44342ccf9c 100644 --- a/gst/gstsample.c +++ b/gst/gstsample.c @@ -37,6 +37,8 @@ struct _GstSample { GstMiniObject mini_object; + gsize slice_size; + GstBuffer *buffer; GstCaps *caps; GstSegment segment; @@ -74,7 +76,7 @@ _gst_sample_free (GstSample * sample) if (sample->caps) gst_caps_unref (sample->caps); - g_slice_free1 (GST_MINI_OBJECT_SIZE (sample), sample); + g_slice_free1 (sample->slice_size, sample); } /** @@ -103,12 +105,12 @@ gst_sample_new (GstBuffer * buffer, GstCaps * caps, const GstSegment * segment, GST_LOG ("new %p", sample); - gst_mini_object_init (GST_MINI_OBJECT_CAST (sample), _gst_sample_type, - sizeof (GstSample)); + gst_mini_object_init (GST_MINI_OBJECT_CAST (sample), _gst_sample_type); sample->mini_object.copy = (GstMiniObjectCopyFunction) _gst_sample_copy; sample->mini_object.free = (GstMiniObjectFreeFunction) _gst_sample_free; + sample->slice_size = sizeof (GstSample); sample->buffer = buffer ? gst_buffer_ref (buffer) : NULL; sample->caps = caps ? gst_caps_ref (caps) : NULL; diff --git a/gst/gsttaglist.c b/gst/gsttaglist.c index 5658fe7f46..b0e9fde545 100644 --- a/gst/gsttaglist.c +++ b/gst/gsttaglist.c @@ -58,10 +58,13 @@ typedef struct _GstTagListImpl { GstTagList taglist; + gsize slice_size; + GstStructure *structure; } GstTagListImpl; -#define GST_TAG_LIST_STRUCTURE(taglist) ((GstTagListImpl*)(taglist))->structure +#define GST_TAG_LIST_SLICE_SIZE(taglist) ((GstTagListImpl*)(taglist))->slice_size +#define GST_TAG_LIST_STRUCTURE(taglist) ((GstTagListImpl*)(taglist))->structure /* FIXME 0.11: use GParamSpecs or something similar for tag registrations, @@ -666,11 +669,13 @@ static void gst_tag_list_init (GstTagList * taglist, gsize size) { gst_mini_object_init (GST_MINI_OBJECT_CAST (taglist), - gst_tag_list_get_type (), size); + gst_tag_list_get_type ()); taglist->mini_object.copy = (GstMiniObjectCopyFunction) __gst_tag_list_copy; taglist->mini_object.dispose = NULL; taglist->mini_object.free = (GstMiniObjectFreeFunction) __gst_tag_list_free; + + GST_TAG_LIST_SLICE_SIZE (taglist) = size; } /* takes ownership of the structure */ @@ -706,7 +711,7 @@ __gst_tag_list_free (GstTagList * list) gst_structure_free (GST_TAG_LIST_STRUCTURE (list)); /* why not just pass sizeof (GstTagListImpl) here? */ - g_slice_free1 (GST_MINI_OBJECT_SIZE (list), list); + g_slice_free1 (GST_TAG_LIST_SLICE_SIZE (list), list); } static GstTagList *