mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-08 18:39:54 +00:00
miniobjects: pass copy, dispose and free function to gst_mini_object_init()
So mini objects don't have to poke into the GstMiniObject part of the structure. Saves lines of code, and seems slightly cleaner. We don't have proper OO hierarchies or methods here after all.
This commit is contained in:
parent
8973bca63c
commit
1be934f0dd
11 changed files with 52 additions and 67 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue