Commit f3b0d3cd authored by Wim Taymans's avatar Wim Taymans

init: add _get_type() functions

Remove gst_mini_object_register() and add a GST_DEFINE_MINI_OBJECT macro to
define a _get_type() function for the boxed miniobject.
Remove a bunch of custom _get_type() functions and replace them with the
miniobject macro.
Rename some _init method to _priv_*_initialize() like the rest of them.

Inspired by patch from Johan Dahlin and see bug #657603
parent 41455989
...@@ -665,12 +665,12 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data, ...@@ -665,12 +665,12 @@ init_post (GOptionContext * context, GOptionGroup * group, gpointer data,
g_log_set_handler (g_log_domain_gstreamer, llf, debug_log_handler, NULL); g_log_set_handler (g_log_domain_gstreamer, llf, debug_log_handler, NULL);
_priv_gst_quarks_initialize (); _priv_gst_quarks_initialize ();
_gst_memory_init (); _priv_gst_memory_initialize ();
_priv_gst_format_initialize (); _priv_gst_format_initialize ();
_priv_gst_query_initialize (); _priv_gst_query_initialize ();
_priv_gst_structure_initialize (); _priv_gst_structure_initialize ();
_priv_gst_caps_initialize (); _priv_gst_caps_initialize ();
_gst_meta_init (); _priv_gst_meta_initialize ();
g_type_class_ref (gst_object_get_type ()); g_type_class_ref (gst_object_get_type ());
g_type_class_ref (gst_pad_get_type ()); g_type_class_ref (gst_pad_get_type ());
......
...@@ -100,6 +100,8 @@ void _priv_gst_caps_initialize (void); ...@@ -100,6 +100,8 @@ void _priv_gst_caps_initialize (void);
void _priv_gst_event_initialize (void); void _priv_gst_event_initialize (void);
void _priv_gst_format_initialize (void); void _priv_gst_format_initialize (void);
void _priv_gst_message_initialize (void); void _priv_gst_message_initialize (void);
void _priv_gst_memory_initialize (void);
void _priv_gst_meta_initialize (void);
void _priv_gst_plugin_initialize (void); void _priv_gst_plugin_initialize (void);
void _priv_gst_query_initialize (void); void _priv_gst_query_initialize (void);
void _priv_gst_tag_initialize (void); void _priv_gst_tag_initialize (void);
......
...@@ -223,12 +223,12 @@ _memory_add (GstBuffer * buffer, guint idx, GstMemory * mem) ...@@ -223,12 +223,12 @@ _memory_add (GstBuffer * buffer, guint idx, GstMemory * mem)
GST_BUFFER_MEM_LEN (buffer) = len + 1; GST_BUFFER_MEM_LEN (buffer) = len + 1;
} }
GST_DEFINE_MINI_OBJECT (GstBuffer, gst_buffer);
void void
_priv_gst_buffer_initialize (void) _priv_gst_buffer_initialize (void)
{ {
if (G_LIKELY (_gst_buffer_type == 0)) { _gst_buffer_type = gst_buffer_get_type ();
_gst_buffer_type = gst_mini_object_register ("GstBuffer");
}
} }
/** /**
......
...@@ -240,6 +240,8 @@ struct _GstBuffer { ...@@ -240,6 +240,8 @@ struct _GstBuffer {
guint64 offset_end; guint64 offset_end;
}; };
GType gst_buffer_get_type (void);
/* allocation */ /* allocation */
GstBuffer * gst_buffer_new (void); GstBuffer * gst_buffer_new (void);
GstBuffer * gst_buffer_new_allocate (const GstAllocator * allocator, gsize maxsize, gsize align); GstBuffer * gst_buffer_new_allocate (const GstAllocator * allocator, gsize maxsize, gsize align);
......
...@@ -54,12 +54,12 @@ struct _GstBufferList ...@@ -54,12 +54,12 @@ struct _GstBufferList
GType _gst_buffer_list_type = 0; GType _gst_buffer_list_type = 0;
GST_DEFINE_MINI_OBJECT (GstBufferList, gst_buffer_list);
void void
_priv_gst_buffer_list_initialize (void) _priv_gst_buffer_list_initialize (void)
{ {
if (G_LIKELY (_gst_buffer_list_type == 0)) { _gst_buffer_list_type = gst_buffer_list_get_type ();
_gst_buffer_list_type = gst_mini_object_register ("GstBufferList");
}
} }
static GstBufferList * static GstBufferList *
......
...@@ -153,6 +153,8 @@ gst_buffer_list_copy (const GstBufferList * list) ...@@ -153,6 +153,8 @@ gst_buffer_list_copy (const GstBufferList * list)
*/ */
#define gst_buffer_list_make_writable(list) GST_BUFFER_LIST_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (list))) #define gst_buffer_list_make_writable(list) GST_BUFFER_LIST_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (list)))
GType gst_buffer_list_get_type (void);
/* allocation */ /* allocation */
GstBufferList * gst_buffer_list_new (void); GstBufferList * gst_buffer_list_new (void);
GstBufferList * gst_buffer_list_sized_new (guint size); GstBufferList * gst_buffer_list_sized_new (guint size);
......
...@@ -115,10 +115,12 @@ static gboolean gst_caps_from_string_inplace (GstCaps * caps, ...@@ -115,10 +115,12 @@ static gboolean gst_caps_from_string_inplace (GstCaps * caps,
GType _gst_caps_type = 0; GType _gst_caps_type = 0;
GST_DEFINE_MINI_OBJECT (GstCaps, gst_caps);
void void
_priv_gst_caps_initialize (void) _priv_gst_caps_initialize (void)
{ {
_gst_caps_type = gst_mini_object_register ("GstCaps"); _gst_caps_type = gst_caps_get_type ();
g_value_register_transform_func (_gst_caps_type, g_value_register_transform_func (_gst_caps_type,
G_TYPE_STRING, gst_caps_transform_to_string); G_TYPE_STRING, gst_caps_transform_to_string);
......
...@@ -336,6 +336,8 @@ struct _GstStaticCaps { ...@@ -336,6 +336,8 @@ struct _GstStaticCaps {
gpointer _gst_reserved[GST_PADDING]; gpointer _gst_reserved[GST_PADDING];
}; };
GType gst_caps_get_type (void);
GstCaps * gst_caps_new_empty (void); GstCaps * gst_caps_new_empty (void);
GstCaps * gst_caps_new_any (void); GstCaps * gst_caps_new_any (void);
GstCaps * gst_caps_new_simple (const char *media_type, GstCaps * gst_caps_new_simple (const char *media_type,
......
...@@ -128,12 +128,14 @@ static GstEventQuarks event_quarks[] = { ...@@ -128,12 +128,14 @@ static GstEventQuarks event_quarks[] = {
{0, NULL, 0} {0, NULL, 0}
}; };
GST_DEFINE_MINI_OBJECT (GstEvent, gst_event);
void void
_priv_gst_event_initialize (void) _priv_gst_event_initialize (void)
{ {
gint i; gint i;
_gst_event_type = gst_mini_object_register ("GstEvent"); _gst_event_type = gst_event_get_type ();
g_type_class_ref (gst_seek_flags_get_type ()); g_type_class_ref (gst_seek_flags_get_type ());
g_type_class_ref (gst_seek_type_get_type ()); g_type_class_ref (gst_seek_type_get_type ());
......
...@@ -412,6 +412,7 @@ gst_event_copy (const GstEvent * event) ...@@ -412,6 +412,7 @@ gst_event_copy (const GstEvent * event)
return GST_EVENT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (event))); return GST_EVENT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (event)));
} }
GType gst_event_get_type (void);
/* custom event */ /* custom event */
GstEvent* gst_event_new_custom (GstEventType type, GstStructure *structure); GstEvent* gst_event_new_custom (GstEventType type, GstStructure *structure);
......
...@@ -308,7 +308,7 @@ static GStaticRWLock lock = G_STATIC_RW_LOCK_INIT; ...@@ -308,7 +308,7 @@ static GStaticRWLock lock = G_STATIC_RW_LOCK_INIT;
static GHashTable *allocators; static GHashTable *allocators;
void void
_gst_memory_init (void) _priv_gst_memory_initialize (void)
{ {
static const GstMemoryInfo _mem_info = { static const GstMemoryInfo _mem_info = {
(GstMemoryAllocFunction) _default_mem_alloc, (GstMemoryAllocFunction) _default_mem_alloc,
......
...@@ -264,8 +264,6 @@ struct _GstMemoryInfo { ...@@ -264,8 +264,6 @@ struct _GstMemoryInfo {
gpointer user_data; gpointer user_data;
}; };
void _gst_memory_init (void);
/* allocators */ /* allocators */
const GstAllocator * gst_allocator_register (const gchar *name, const GstMemoryInfo *info); const GstAllocator * gst_allocator_register (const gchar *name, const GstMemoryInfo *info);
const GstAllocator * gst_allocator_find (const gchar *name); const GstAllocator * gst_allocator_find (const gchar *name);
......
...@@ -60,8 +60,6 @@ ...@@ -60,8 +60,6 @@
#include "gstquark.h" #include "gstquark.h"
static GType _gst_message_type = 0;
typedef struct typedef struct
{ {
GstMessage message; GstMessage message;
...@@ -109,6 +107,9 @@ static GstMessageQuarks message_quarks[] = { ...@@ -109,6 +107,9 @@ static GstMessageQuarks message_quarks[] = {
{0, NULL, 0} {0, NULL, 0}
}; };
static GType _gst_message_type = 0;
GST_DEFINE_MINI_OBJECT (GstMessage, gst_message);
void void
_priv_gst_message_initialize (void) _priv_gst_message_initialize (void)
{ {
...@@ -125,6 +126,8 @@ _priv_gst_message_initialize (void) ...@@ -125,6 +126,8 @@ _priv_gst_message_initialize (void)
message_quarks[i].quark = message_quarks[i].quark =
g_quark_from_static_string (message_quarks[i].name); g_quark_from_static_string (message_quarks[i].name);
} }
_gst_message_type = gst_message_get_type ();
} }
/** /**
...@@ -167,16 +170,6 @@ gst_message_type_to_quark (GstMessageType type) ...@@ -167,16 +170,6 @@ gst_message_type_to_quark (GstMessageType type)
return 0; return 0;
} }
GType
gst_message_get_type (void)
{
if (G_UNLIKELY (_gst_message_type == 0)) {
_gst_message_type = gst_mini_object_register ("GstMessage");
}
return _gst_message_type;
}
static void static void
_gst_message_free (GstMessage * message) _gst_message_free (GstMessage * message)
{ {
......
...@@ -36,7 +36,7 @@ static GHashTable *metainfo = NULL; ...@@ -36,7 +36,7 @@ static GHashTable *metainfo = NULL;
static GStaticRWLock lock = G_STATIC_RW_LOCK_INIT; static GStaticRWLock lock = G_STATIC_RW_LOCK_INIT;
void void
_gst_meta_init (void) _priv_gst_meta_initialize (void)
{ {
metainfo = g_hash_table_new (g_str_hash, g_str_equal); metainfo = g_hash_table_new (g_str_hash, g_str_equal);
} }
......
...@@ -107,8 +107,6 @@ struct _GstMetaInfo { ...@@ -107,8 +107,6 @@ struct _GstMetaInfo {
GstMetaTransformFunction transform_func; GstMetaTransformFunction transform_func;
}; };
void _gst_meta_init (void);
const GstMetaInfo * gst_meta_register (const gchar *api, const gchar *impl, const GstMetaInfo * gst_meta_register (const gchar *api, const gchar *impl,
gsize size, gsize size,
GstMetaInitFunction init_func, GstMetaInitFunction init_func,
......
...@@ -48,30 +48,6 @@ static GstAllocTrace *_gst_mini_object_trace; ...@@ -48,30 +48,6 @@ static GstAllocTrace *_gst_mini_object_trace;
/* Mutex used for weak referencing */ /* Mutex used for weak referencing */
G_LOCK_DEFINE_STATIC (weak_refs_mutex); G_LOCK_DEFINE_STATIC (weak_refs_mutex);
/**
* gst_mini_object_register:
* @name: name of the new boxed type
*
* This function creates a new G_TYPE_BOXED derived type id for a new boxed type
* with name @name. The default miniobject refcounting copy and free function
* are used for the boxed type.
*
* Returns: a new G_TYPE_BOXED derived type id for @name.
*/
GType
gst_mini_object_register (const gchar * name)
{
GType type;
g_return_val_if_fail (name != NULL, 0);
type = g_boxed_type_register_static (name,
(GBoxedCopyFunc) gst_mini_object_ref,
(GBoxedFreeFunc) gst_mini_object_unref);
return type;
}
/** /**
* gst_mini_object_init: * gst_mini_object_init:
* @mini_object: a #GstMiniObject * @mini_object: a #GstMiniObject
......
...@@ -193,8 +193,6 @@ struct _GstMiniObject { ...@@ -193,8 +193,6 @@ struct _GstMiniObject {
} *weak_refs; } *weak_refs;
}; };
GType gst_mini_object_register (const gchar *name);
void gst_mini_object_init (GstMiniObject *mini_object, void gst_mini_object_init (GstMiniObject *mini_object,
GType type, gsize size); GType type, gsize size);
...@@ -217,6 +215,10 @@ gboolean gst_mini_object_replace (GstMiniObject **olddata, GstMin ...@@ -217,6 +215,10 @@ gboolean gst_mini_object_replace (GstMiniObject **olddata, GstMin
gboolean gst_mini_object_take (GstMiniObject **olddata, GstMiniObject *newdata); gboolean gst_mini_object_take (GstMiniObject **olddata, GstMiniObject *newdata);
GstMiniObject * gst_mini_object_steal (GstMiniObject **olddata); GstMiniObject * gst_mini_object_steal (GstMiniObject **olddata);
#define GST_DEFINE_MINI_OBJECT(TypeName,type_name) \
G_DEFINE_BOXED_TYPE(TypeName,type_name, \
(GBoxedCopyFunc) gst_mini_object_ref, \
(GBoxedFreeFunc)gst_mini_object_unref)
G_END_DECLS G_END_DECLS
......
...@@ -108,6 +108,8 @@ static GstQueryTypeDefinition standard_definitions[] = { ...@@ -108,6 +108,8 @@ static GstQueryTypeDefinition standard_definitions[] = {
{GST_QUERY_NONE, NULL, NULL, 0} {GST_QUERY_NONE, NULL, NULL, 0}
}; };
GST_DEFINE_MINI_OBJECT (GstQuery, gst_query);
void void
_priv_gst_query_initialize (void) _priv_gst_query_initialize (void)
{ {
...@@ -135,7 +137,7 @@ _priv_gst_query_initialize (void) ...@@ -135,7 +137,7 @@ _priv_gst_query_initialize (void)
} }
g_static_mutex_unlock (&mutex); g_static_mutex_unlock (&mutex);
gst_query_get_type (); _gst_query_type = gst_query_get_type ();
} }
/** /**
...@@ -176,16 +178,6 @@ gst_query_type_to_quark (GstQueryType query) ...@@ -176,16 +178,6 @@ gst_query_type_to_quark (GstQueryType query)
return def->quark; return def->quark;
} }
GType
gst_query_get_type (void)
{
if (G_UNLIKELY (_gst_query_type == 0)) {
_gst_query_type = gst_mini_object_register ("GstQuery");
}
return _gst_query_type;
}
/** /**
* gst_query_type_register: * gst_query_type_register:
* @nick: The nick of the new query * @nick: The nick of the new query
......
...@@ -102,11 +102,13 @@ EXPORTS ...@@ -102,11 +102,13 @@ EXPORTS
gst_buffer_flags_get_type gst_buffer_flags_get_type
gst_buffer_get_meta gst_buffer_get_meta
gst_buffer_get_sizes gst_buffer_get_sizes
gst_buffer_get_type
gst_buffer_is_span_fast gst_buffer_is_span_fast
gst_buffer_iterate_meta gst_buffer_iterate_meta
gst_buffer_join gst_buffer_join
gst_buffer_list_foreach gst_buffer_list_foreach
gst_buffer_list_get gst_buffer_list_get
gst_buffer_list_get_type
gst_buffer_list_insert gst_buffer_list_insert
gst_buffer_list_len gst_buffer_list_len
gst_buffer_list_new gst_buffer_list_new
...@@ -180,6 +182,7 @@ EXPORTS ...@@ -180,6 +182,7 @@ EXPORTS
gst_caps_from_string gst_caps_from_string
gst_caps_get_size gst_caps_get_size
gst_caps_get_structure gst_caps_get_structure
gst_caps_get_type
gst_caps_intersect gst_caps_intersect
gst_caps_intersect_full gst_caps_intersect_full
gst_caps_intersect_mode_get_type gst_caps_intersect_mode_get_type
...@@ -395,6 +398,7 @@ EXPORTS ...@@ -395,6 +398,7 @@ EXPORTS
gst_event_copy_segment gst_event_copy_segment
gst_event_get_seqnum gst_event_get_seqnum
gst_event_get_structure gst_event_get_structure
gst_event_get_type
gst_event_has_name gst_event_has_name
gst_event_new_buffer_size gst_event_new_buffer_size
gst_event_new_caps gst_event_new_caps
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment