diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index c4c2f358d1..756c26c4dd 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -525,14 +525,10 @@ _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); - - buffer->buffer.mini_object.copy = - (GstMiniObjectCopyFunction) _gst_buffer_copy; - buffer->buffer.mini_object.dispose = - (GstMiniObjectDisposeFunction) _gst_buffer_dispose; - buffer->buffer.mini_object.free = - (GstMiniObjectFreeFunction) _gst_buffer_free; + gst_mini_object_init (GST_MINI_OBJECT_CAST (buffer), _gst_buffer_type, + (GstMiniObjectCopyFunction) _gst_buffer_copy, + (GstMiniObjectDisposeFunction) _gst_buffer_dispose, + (GstMiniObjectFreeFunction) _gst_buffer_free); GST_BUFFER_SLICE_SIZE (buffer) = size; diff --git a/gst/gstbufferlist.c b/gst/gstbufferlist.c index 31b8bae465..f0b885d8bf 100644 --- a/gst/gstbufferlist.c +++ b/gst/gstbufferlist.c @@ -103,10 +103,9 @@ _gst_buffer_list_free (GstBufferList * list) static void gst_buffer_list_init (GstBufferList * list, guint asize) { - 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; + gst_mini_object_init (GST_MINI_OBJECT_CAST (list), _gst_buffer_list_type, + (GstMiniObjectCopyFunction) _gst_buffer_list_copy, NULL, + (GstMiniObjectFreeFunction) _gst_buffer_list_free); list->array = g_array_sized_new (FALSE, FALSE, sizeof (GstBuffer *), asize); diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 3a558bee81..f49409812a 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -185,11 +185,9 @@ _gst_caps_free (GstCaps * caps) static void gst_caps_init (GstCaps * caps) { - 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_mini_object_init (GST_MINI_OBJECT_CAST (caps), _gst_caps_type, + (GstMiniObjectCopyFunction) _gst_caps_copy, NULL, + (GstMiniObjectFreeFunction) _gst_caps_free); /* 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 diff --git a/gst/gstevent.c b/gst/gstevent.c index 4531da39cb..9e8f2852de 100644 --- a/gst/gstevent.c +++ b/gst/gstevent.c @@ -261,10 +261,9 @@ _gst_event_copy (GstEvent * event) static void gst_event_init (GstEventImpl * event, GstEventType type) { - 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_mini_object_init (GST_MINI_OBJECT_CAST (event), _gst_event_type, + (GstMiniObjectCopyFunction) _gst_event_copy, NULL, + (GstMiniObjectFreeFunction) _gst_event_free); GST_EVENT_TYPE (event) = type; GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE; diff --git a/gst/gstmemory.c b/gst/gstmemory.c index c268895fbc..efcb73c2ac 100644 --- a/gst/gstmemory.c +++ b/gst/gstmemory.c @@ -138,11 +138,10 @@ _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); + gst_mini_object_init (GST_MINI_OBJECT_CAST (mem), GST_TYPE_MEMORY, + (GstMiniObjectCopyFunction) _gst_memory_copy, NULL, + (GstMiniObjectFreeFunction) _gst_memory_free); - mem->mem.mini_object.copy = (GstMiniObjectCopyFunction) _gst_memory_copy; - mem->mem.mini_object.dispose = NULL; - mem->mem.mini_object.free = (GstMiniObjectFreeFunction) _gst_memory_free; mem->mem.mini_object.flags = flags; mem->mem.allocator = _default_mem_impl; @@ -805,10 +804,9 @@ 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); - - allocator->mini_object.copy = (GstMiniObjectCopyFunction) _gst_allocator_copy; - allocator->mini_object.free = (GstMiniObjectFreeFunction) _gst_allocator_free; + gst_mini_object_init (GST_MINI_OBJECT_CAST (allocator), GST_TYPE_ALLOCATOR, + (GstMiniObjectCopyFunction) _gst_allocator_copy, NULL, + (GstMiniObjectFreeFunction) _gst_allocator_free); allocator->info = *info; allocator->user_data = user_data; diff --git a/gst/gstmessage.c b/gst/gstmessage.c index a4d6fd5adb..8bdef12ad6 100644 --- a/gst/gstmessage.c +++ b/gst/gstmessage.c @@ -239,12 +239,9 @@ static void gst_message_init (GstMessageImpl * message, GstMessageType type, GstObject * src) { - 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_mini_object_init (GST_MINI_OBJECT_CAST (message), _gst_message_type, + (GstMiniObjectCopyFunction) _gst_message_copy, NULL, + (GstMiniObjectFreeFunction) _gst_message_free); GST_MESSAGE_TYPE (message) = type; if (src) diff --git a/gst/gstminiobject.c b/gst/gstminiobject.c index bf488d5d4f..123feff5ee 100644 --- a/gst/gstminiobject.c +++ b/gst/gstminiobject.c @@ -91,22 +91,34 @@ _priv_gst_mini_object_initialize (void) } /** - * gst_mini_object_init: + * gst_mini_object_init: (skip) * @mini_object: a #GstMiniObject * @type: the #GType of the mini-object to create + * @copy_func: the copy function, or NULL + * @dispose_func: the dispose function, or NULL + * @free_func: the free function or NULL * - * Initializes a mini-object with the desired type and size. + * Initializes a mini-object with the desired type and copy/dispose/free + * functions. * * MT safe * * Returns: (transfer full): the new mini-object. */ void -gst_mini_object_init (GstMiniObject * mini_object, GType type) +gst_mini_object_init (GstMiniObject * mini_object, GType type, + GstMiniObjectCopyFunction copy_func, + GstMiniObjectDisposeFunction dispose_func, + GstMiniObjectFreeFunction free_func) { mini_object->type = type; mini_object->refcount = 1; mini_object->flags = 0; + + mini_object->copy = copy_func; + mini_object->dispose = dispose_func; + mini_object->free = free_func; + mini_object->n_qdata = 0; mini_object->qdata = NULL; diff --git a/gst/gstminiobject.h b/gst/gstminiobject.h index e9bc14bb1b..f4e53a2ab2 100644 --- a/gst/gstminiobject.h +++ b/gst/gstminiobject.h @@ -181,7 +181,10 @@ struct _GstMiniObject { gpointer qdata; }; -void gst_mini_object_init (GstMiniObject *mini_object, GType type); +void gst_mini_object_init (GstMiniObject *mini_object, GType type, + GstMiniObjectCopyFunction copy_func, + GstMiniObjectDisposeFunction dispose_func, + GstMiniObjectFreeFunction free_func); 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 161cd43b55..f63f59be03 100644 --- a/gst/gstquery.c +++ b/gst/gstquery.c @@ -220,17 +220,6 @@ _gst_query_copy (GstQuery * query) return copy; } -static void -gst_query_init (GstQueryImpl * query, GstQueryType type) -{ - 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_TYPE (query) = type; -} - /** * gst_query_new_position: * @format: the default #GstFormat for the new query @@ -702,8 +691,12 @@ gst_query_new_custom (GstQueryType type, GstStructure * structure) &query->query.mini_object.refcount)) goto had_parent; } - gst_query_init (query, type); + gst_mini_object_init (GST_MINI_OBJECT_CAST (query), _gst_query_type, + (GstMiniObjectCopyFunction) _gst_query_copy, NULL, + (GstMiniObjectFreeFunction) _gst_query_free); + + GST_QUERY_TYPE (query) = type; GST_QUERY_STRUCTURE (query) = structure; return GST_QUERY_CAST (query); diff --git a/gst/gstsample.c b/gst/gstsample.c index 3194a80692..4e4a36be5a 100644 --- a/gst/gstsample.c +++ b/gst/gstsample.c @@ -103,10 +103,9 @@ 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); - - sample->mini_object.copy = (GstMiniObjectCopyFunction) _gst_sample_copy; - sample->mini_object.free = (GstMiniObjectFreeFunction) _gst_sample_free; + gst_mini_object_init (GST_MINI_OBJECT_CAST (sample), _gst_sample_type, + (GstMiniObjectCopyFunction) _gst_sample_copy, NULL, + (GstMiniObjectFreeFunction) _gst_sample_free); 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 2110a14cff..9d6a076427 100644 --- a/gst/gsttaglist.c +++ b/gst/gsttaglist.c @@ -655,17 +655,6 @@ gst_tag_is_fixed (const gchar * tag) return info->merge_func == NULL; } -static void -gst_tag_list_init (GstTagList * taglist) -{ - gst_mini_object_init (GST_MINI_OBJECT_CAST (taglist), - 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; -} - /* takes ownership of the structure */ static GstTagList * gst_tag_list_new_internal (GstStructure * s) @@ -676,7 +665,9 @@ gst_tag_list_new_internal (GstStructure * s) tag_list = (GstTagList *) g_slice_new (GstTagListImpl); - gst_tag_list_init (tag_list); + gst_mini_object_init (GST_MINI_OBJECT_CAST (tag_list), GST_TYPE_TAG_LIST, + (GstMiniObjectCopyFunction) __gst_tag_list_copy, NULL, + (GstMiniObjectFreeFunction) __gst_tag_list_free); GST_TAG_LIST_STRUCTURE (tag_list) = s;