Commit e7ccf786 authored by Sebastian Dröge's avatar Sebastian Dröge

gst: Use G_DEFINE_TYPE and friends or at least g_once_init_* in the _get_type() functions

parent 42febffe
......@@ -274,59 +274,34 @@ enum
/* FILL ME */
};
static void gst_bin_base_init (gpointer g_class);
static void gst_bin_class_init (GstBinClass * klass);
static void gst_bin_init (GstBin * bin);
static void gst_bin_child_proxy_init (gpointer g_iface, gpointer iface_data);
static GstElementClass *parent_class = NULL;
static guint gst_bin_signals[LAST_SIGNAL] = { 0 };
GType
gst_bin_get_type (void)
{
static GType gst_bin_type = 0;
const gchar *compat;
if (G_UNLIKELY (gst_bin_type == 0)) {
static const GTypeInfo bin_info = {
sizeof (GstBinClass),
gst_bin_base_init,
NULL,
(GClassInitFunc) gst_bin_class_init,
NULL,
NULL,
sizeof (GstBin),
0,
(GInstanceInitFunc) gst_bin_init,
NULL
};
static const GInterfaceInfo child_proxy_info = {
gst_bin_child_proxy_init,
NULL,
NULL
};
gst_bin_type =
g_type_register_static (GST_TYPE_ELEMENT, "GstBin", &bin_info, 0);
g_type_add_interface_static (gst_bin_type, GST_TYPE_CHILD_PROXY,
&child_proxy_info);
GST_DEBUG_CATEGORY_INIT (bin_debug, "bin", GST_DEBUG_BOLD,
"debugging info for the 'bin' container element");
/* compatibility stuff */
compat = g_getenv ("GST_COMPAT");
if (compat != NULL) {
if (strstr (compat, "no-live-preroll"))
enable_latency = FALSE;
else if (strstr (compat, "live-preroll"))
enable_latency = TRUE;
}
}
return gst_bin_type;
}
#define _do_init(type) \
{ \
const gchar *compat; \
static const GInterfaceInfo iface_info = { \
gst_bin_child_proxy_init, \
NULL, \
NULL}; \
\
g_type_add_interface_static (type, GST_TYPE_CHILD_PROXY, &iface_info); \
\
GST_DEBUG_CATEGORY_INIT (bin_debug, "bin", GST_DEBUG_BOLD, \
"debugging info for the 'bin' container element"); \
\
/* compatibility stuff */ \
compat = g_getenv ("GST_COMPAT"); \
if (compat != NULL) { \
if (strstr (compat, "no-live-preroll")) \
enable_latency = FALSE; \
else if (strstr (compat, "live-preroll")) \
enable_latency = TRUE; \
} \
}
GST_BOILERPLATE_FULL (GstBin, gst_bin, GstElement, GST_TYPE_ELEMENT, _do_init);
static void
gst_bin_base_init (gpointer g_class)
......@@ -409,8 +384,6 @@ gst_bin_class_init (GstBinClass * klass)
gstobject_class = (GstObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GstBinPrivate));
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_bin_set_property);
......@@ -511,7 +484,7 @@ gst_bin_class_init (GstBinClass * klass)
}
static void
gst_bin_init (GstBin * bin)
gst_bin_init (GstBin * bin, GstBinClass * klass)
{
GstBus *bus;
......
......@@ -120,8 +120,6 @@
#include "gstutils.h"
#include "gstminiobject.h"
static void gst_buffer_init (GTypeInstance * instance, gpointer g_class);
static void gst_buffer_class_init (gpointer g_class, gpointer class_data);
static void gst_buffer_finalize (GstBuffer * buffer);
static GstBuffer *_gst_buffer_copy (GstBuffer * buffer);
static GType gst_subbuffer_get_type (void);
......@@ -129,8 +127,6 @@ static GType gst_subbuffer_get_type (void);
static GType _gst_subbuffer_type = 0;
static GType _gst_buffer_type = 0;
static GstMiniObjectClass *parent_class = NULL;
void
_gst_buffer_initialize (void)
{
......@@ -141,41 +137,19 @@ _gst_buffer_initialize (void)
g_type_class_ref (gst_subbuffer_get_type ());
}
GType
gst_buffer_get_type (void)
{
if (G_UNLIKELY (_gst_buffer_type == 0)) {
static const GTypeInfo buffer_info = {
sizeof (GstBufferClass),
NULL,
NULL,
gst_buffer_class_init,
NULL,
NULL,
sizeof (GstBuffer),
0,
gst_buffer_init,
NULL
};
_gst_buffer_type = g_type_register_static (GST_TYPE_MINI_OBJECT,
"GstBuffer", &buffer_info, 0);
}
return _gst_buffer_type;
#define _do_init \
{ \
_gst_buffer_type = g_define_type_id; \
}
G_DEFINE_TYPE_WITH_CODE (GstBuffer, gst_buffer, GST_TYPE_MINI_OBJECT, _do_init);
static void
gst_buffer_class_init (gpointer g_class, gpointer class_data)
gst_buffer_class_init (GstBufferClass * klass)
{
GstBufferClass *buffer_class = GST_BUFFER_CLASS (g_class);
parent_class = g_type_class_peek_parent (g_class);
buffer_class->mini_object_class.copy =
(GstMiniObjectCopyFunction) _gst_buffer_copy;
buffer_class->mini_object_class.finalize =
klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_buffer_copy;
klass->mini_object_class.finalize =
(GstMiniObjectFinalizeFunction) gst_buffer_finalize;
}
static void
......@@ -191,7 +165,8 @@ gst_buffer_finalize (GstBuffer * buffer)
gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL);
parent_class->finalize (GST_MINI_OBJECT_CAST (buffer));
GST_MINI_OBJECT_CLASS (gst_buffer_parent_class)->finalize
(GST_MINI_OBJECT_CAST (buffer));
}
/**
......@@ -268,12 +243,8 @@ _gst_buffer_copy (GstBuffer * buffer)
}
static void
gst_buffer_init (GTypeInstance * instance, gpointer g_class)
gst_buffer_init (GstBuffer * buffer)
{
GstBuffer *buffer;
buffer = (GstBuffer *) instance;
GST_CAT_LOG (GST_CAT_BUFFER, "init %p", buffer);
GST_BUFFER_TIMESTAMP (buffer) = GST_CLOCK_TIME_NONE;
......@@ -490,43 +461,20 @@ struct _GstSubBufferClass
GstBufferClass buffer_class;
};
static GstBufferClass *sub_parent_class;
static void gst_subbuffer_init (GTypeInstance * instance, gpointer g_class);
static void gst_subbuffer_class_init (gpointer g_class, gpointer class_data);
static void gst_subbuffer_finalize (GstSubBuffer * buffer);
static GType
gst_subbuffer_get_type (void)
{
if (G_UNLIKELY (_gst_subbuffer_type == 0)) {
static const GTypeInfo subbuffer_info = {
sizeof (GstSubBufferClass),
NULL,
NULL,
gst_subbuffer_class_init,
NULL,
NULL,
sizeof (GstSubBuffer),
0,
gst_subbuffer_init,
NULL
};
_gst_subbuffer_type = g_type_register_static (GST_TYPE_BUFFER,
"GstSubBuffer", &subbuffer_info, 0);
}
return _gst_subbuffer_type;
#define _do_init_sub \
{ \
_gst_subbuffer_type = g_define_type_id; \
}
G_DEFINE_TYPE_WITH_CODE (GstSubBuffer, gst_subbuffer, GST_TYPE_BUFFER,
_do_init_sub);
static void
gst_subbuffer_class_init (gpointer g_class, gpointer class_data)
gst_subbuffer_class_init (GstSubBufferClass * klass)
{
GstBufferClass *buffer_class = GST_BUFFER_CLASS (g_class);
sub_parent_class = g_type_class_peek_parent (g_class);
buffer_class->mini_object_class.finalize =
klass->buffer_class.mini_object_class.finalize =
(GstMiniObjectFinalizeFunction) gst_subbuffer_finalize;
}
......@@ -535,12 +483,12 @@ gst_subbuffer_finalize (GstSubBuffer * buffer)
{
gst_buffer_unref (buffer->parent);
GST_MINI_OBJECT_CLASS (sub_parent_class)->
finalize (GST_MINI_OBJECT_CAST (buffer));
GST_MINI_OBJECT_CLASS (gst_subbuffer_parent_class)->finalize
(GST_MINI_OBJECT_CAST (buffer));
}
static void
gst_subbuffer_init (GTypeInstance * instance, gpointer g_class)
gst_subbuffer_init (GstSubBuffer * instance)
{
GST_BUFFER_FLAG_SET (GST_BUFFER_CAST (instance), GST_BUFFER_FLAG_READONLY);
}
......
......@@ -479,9 +479,10 @@ gst_child_proxy_base_init (gpointer g_class)
GType
gst_child_proxy_get_type (void)
{
static GType type = 0;
static volatile gsize type = 0;
if (G_UNLIKELY (type == 0)) {
if (g_once_init_enter (&type)) {
GType _type;
static const GTypeInfo info = {
sizeof (GstChildProxyInterface),
gst_child_proxy_base_init, /* base_init */
......@@ -493,9 +494,12 @@ gst_child_proxy_get_type (void)
0, /* n_preallocs */
NULL /* instance_init */
};
type = g_type_register_static (G_TYPE_INTERFACE, "GstChildProxy", &info, 0);
g_type_interface_add_prerequisite (type, GST_TYPE_OBJECT);
_type =
g_type_register_static (G_TYPE_INTERFACE, "GstChildProxy", &info, 0);
g_type_interface_add_prerequisite (_type, GST_TYPE_OBJECT);
g_once_init_leave (&type, (gsize) _type);
}
return type;
}
......@@ -148,9 +148,10 @@ static guint gst_element_signals[LAST_SIGNAL] = { 0 };
GType
gst_element_get_type (void)
{
static GType gst_element_type = 0;
static volatile gsize gst_element_type = 0;
if (G_UNLIKELY (gst_element_type == 0)) {
if (g_once_init_enter (&gst_element_type)) {
GType _type;
static const GTypeInfo element_info = {
sizeof (GstElementClass),
gst_element_base_class_init,
......@@ -164,8 +165,9 @@ gst_element_get_type (void)
NULL
};
gst_element_type = g_type_register_static (GST_TYPE_OBJECT, "GstElement",
_type = g_type_register_static (GST_TYPE_OBJECT, "GstElement",
&element_info, G_TYPE_FLAG_ABSTRACT);
g_once_init_leave (&gst_element_type, _type);
}
return gst_element_type;
}
......
......@@ -79,39 +79,20 @@ static GstPluginFeatureClass *parent_class = NULL;
/* static guint gst_element_factory_signals[LAST_SIGNAL] = { 0 }; */
GType
gst_element_factory_get_type (void)
{
static GType elementfactory_type = 0;
if (G_UNLIKELY (elementfactory_type == 0)) {
static const GTypeInfo elementfactory_info = {
sizeof (GstElementFactoryClass),
NULL,
NULL,
(GClassInitFunc) gst_element_factory_class_init,
NULL,
NULL,
sizeof (GstElementFactory),
0,
(GInstanceInitFunc) gst_element_factory_init,
NULL
};
elementfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
"GstElementFactory", &elementfactory_info, 0);
GST_DEBUG_CATEGORY_INIT (element_factory_debug, "GST_ELEMENT_FACTORY",
GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED,
"element factories keep information about installed elements");
}
return elementfactory_type;
#define _do_init \
{ \
GST_DEBUG_CATEGORY_INIT (element_factory_debug, "GST_ELEMENT_FACTORY", \
GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, \
"element factories keep information about installed elements"); \
}
G_DEFINE_TYPE_WITH_CODE (GstElementFactory, gst_element_factory,
GST_TYPE_PLUGIN_FEATURE, _do_init);
static void
gst_element_factory_class_init (GstElementFactoryClass * klass)
{
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
GObjectClass *gobject_class = (GObjectClass *) klass;
parent_class = g_type_class_peek_parent (klass);
......
......@@ -87,8 +87,6 @@
#define GST_EVENT_SEQNUM(e) ((GstEvent*)e)->abidata.seqnum
static void gst_event_init (GTypeInstance * instance, gpointer g_class);
static void gst_event_class_init (gpointer g_class, gpointer class_data);
static void gst_event_finalize (GstEvent * event);
static GstEvent *_gst_event_copy (GstEvent * event);
......@@ -188,57 +186,30 @@ gst_event_type_get_flags (GstEventType type)
return ret;
}
GType
gst_event_get_type (void)
{
static GType _gst_event_type = 0;
int i;
if (G_UNLIKELY (_gst_event_type == 0)) {
static const GTypeInfo event_info = {
sizeof (GstEventClass),
NULL,
NULL,
gst_event_class_init,
NULL,
NULL,
sizeof (GstEvent),
0,
gst_event_init,
NULL
};
_gst_event_type = g_type_register_static (GST_TYPE_MINI_OBJECT,
"GstEvent", &event_info, 0);
for (i = 0; event_quarks[i].name; i++) {
event_quarks[i].quark = g_quark_from_static_string (event_quarks[i].name);
}
}
return _gst_event_type;
#define _do_init \
{ \
gint i; \
\
for (i = 0; event_quarks[i].name; i++) { \
event_quarks[i].quark = g_quark_from_static_string (event_quarks[i].name); \
} \
}
G_DEFINE_TYPE_WITH_CODE (GstEvent, gst_event, GST_TYPE_MINI_OBJECT, _do_init);
static void
gst_event_class_init (gpointer g_class, gpointer class_data)
gst_event_class_init (GstEventClass * klass)
{
GstEventClass *event_class = GST_EVENT_CLASS (g_class);
parent_class = g_type_class_peek_parent (klass);
parent_class = g_type_class_peek_parent (g_class);
event_class->mini_object_class.copy =
(GstMiniObjectCopyFunction) _gst_event_copy;
event_class->mini_object_class.finalize =
klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_event_copy;
klass->mini_object_class.finalize =
(GstMiniObjectFinalizeFunction) gst_event_finalize;
}
static void
gst_event_init (GTypeInstance * instance, gpointer g_class)
gst_event_init (GstEvent * event)
{
GstEvent *event;
event = GST_EVENT (instance);
GST_EVENT_TIMESTAMP (event) = GST_CLOCK_TIME_NONE;
}
......
......@@ -124,41 +124,18 @@ gst_index_entry_get_type (void)
return index_entry_type;
}
GType
gst_index_get_type (void)
{
static GType index_type = 0;
if (!index_type) {
static const GTypeInfo index_info = {
sizeof (GstIndexClass),
NULL,
NULL,
(GClassInitFunc) gst_index_class_init,
NULL,
NULL,
sizeof (GstIndex),
0,
(GInstanceInitFunc) gst_index_init,
NULL
};
index_type =
g_type_register_static (GST_TYPE_OBJECT, "GstIndex", &index_info, 0);
GST_DEBUG_CATEGORY_INIT (index_debug, "GST_INDEX", GST_DEBUG_BOLD,
"Generic indexing support");
}
return index_type;
#define _do_init \
{ \
GST_DEBUG_CATEGORY_INIT (index_debug, "GST_INDEX", GST_DEBUG_BOLD, \
"Generic indexing support"); \
}
G_DEFINE_TYPE_WITH_CODE (GstIndex, gst_index, GST_TYPE_OBJECT, _do_init);
static void
gst_index_class_init (GstIndexClass * klass)
{
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
......
......@@ -43,44 +43,23 @@ static void gst_index_factory_finalize (GObject * object);
static GstPluginFeatureClass *factory_parent_class = NULL;
/* static guint gst_index_factory_signals[LAST_SIGNAL] = { 0 }; */
GType
gst_index_factory_get_type (void)
{
static GType indexfactory_type = 0;
if (G_UNLIKELY (indexfactory_type == 0)) {
static const GTypeInfo indexfactory_info = {
sizeof (GstIndexFactoryClass),
NULL,
NULL,
(GClassInitFunc) gst_index_factory_class_init,
NULL,
NULL,
sizeof (GstIndexFactory),
0,
NULL,
NULL
};
indexfactory_type = g_type_register_static (GST_TYPE_PLUGIN_FEATURE,
"GstIndexFactory", &indexfactory_info, 0);
}
return indexfactory_type;
}
G_DEFINE_TYPE (GstIndexFactory, gst_index_factory, GST_TYPE_PLUGIN_FEATURE);
static void
gst_index_factory_class_init (GstIndexFactoryClass * klass)
{
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) klass;
GObjectClass *gobject_class = (GObjectClass *) klass;
factory_parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_index_factory_finalize);
}
static void
gst_index_factory_init (GstIndexFactory * factory)
{
}
static void
gst_index_factory_finalize (GObject * object)
{
......
......@@ -47,9 +47,10 @@ gst_implements_interface_supported_default (GstImplementsInterface * iface,
GType
gst_implements_interface_get_type (void)
{
static GType gst_interface_type = 0;
static volatile gsize gst_interface_type = 0;
if (!gst_interface_type) {
if (g_once_init_enter (&gst_interface_type)) {
GType _type;
static const GTypeInfo gst_interface_info = {
sizeof (GstImplementsInterfaceClass),
(GBaseInitFunc) gst_implements_interface_class_init,
......@@ -63,10 +64,11 @@ gst_implements_interface_get_type (void)
NULL
};
gst_interface_type = g_type_register_static (G_TYPE_INTERFACE,
_type = g_type_register_static (G_TYPE_INTERFACE,
"GstImplementsInterface", &gst_interface_info, 0);
g_type_interface_add_prerequisite (gst_interface_type, GST_TYPE_ELEMENT);
g_type_interface_add_prerequisite (_type, GST_TYPE_ELEMENT);
g_once_init_leave (&gst_interface_type, _type);
}
return gst_interface_type;
......
......@@ -62,8 +62,6 @@
#define GST_MESSAGE_SEQNUM(e) ((GstMessage*)e)->abidata.ABI.seqnum
static void gst_message_init (GTypeInstance * instance, gpointer g_class);
static void gst_message_class_init (gpointer g_class, gpointer class_data);
static void gst_message_finalize (GstMessage * message);
static GstMessage *_gst_message_copy (GstMessage * message);
......@@ -155,55 +153,32 @@ gst_message_type_to_quark (GstMessageType type)
return 0;
}
GType
gst_message_get_type (void)
{
static GType _gst_message_type;
if (G_UNLIKELY (_gst_message_type == 0)) {
gint i;
static const GTypeInfo message_info = {
sizeof (GstMessageClass),
NULL,
NULL,
gst_message_class_init,
NULL,
NULL,
sizeof (GstMessage),
0,
gst_message_init,
NULL
};
_gst_message_type = g_type_register_static (GST_TYPE_MINI_OBJECT,
"GstMessage", &message_info, 0);
for (i = 0; message_quarks[i].name; i++) {
message_quarks[i].quark =
g_quark_from_static_string (message_quarks[i].name);
}
}
return _gst_message_type;
#define _do_init \
{ \
gint i; \
\
for (i = 0; message_quarks[i].name; i++) { \
message_quarks[i].quark = \
g_quark_from_static_string (message_quarks[i].name); \
} \
}
G_DEFINE_TYPE_WITH_CODE (GstMessage, gst_message, GST_TYPE_MINI_OBJECT,
_do_init);
static void
gst_message_class_init (gpointer g_class, gpointer class_data)
gst_message_class_init (GstMessageClass * klass)
{
GstMessageClass *message_class = GST_MESSAGE_CLASS (g_class);
parent_class = g_type_class_peek_parent (klass);
parent_class = g_type_class_peek_parent (g_class);
message_class->mini_object_class.copy =
(GstMiniObjectCopyFunction) _gst_message_copy;
message_class->mini_object_class.finalize =
klass->mini_object_class.copy = (GstMiniObjectCopyFunction) _gst_message_copy;
klass->mini_object_class.finalize =
(GstMiniObjectFinalizeFunction) gst_message_finalize;
}
static void
gst_message_init (GTypeInstance * instance, gpointer g_class)
gst_message_init (GstMessage * message)
{
GstMessage *message = GST_MESSAGE (instance);
GST_CAT_LOG (GST_CAT_MESSAGE, "new message %p", message);
GST_MESSAGE_TIMESTAMP (message) = GST_CLOCK_TIME_NONE;
}
......
......@@ -140,9 +140,6 @@ static void gst_signal_object_init (GstSignalObject * object);
static guint gst_signal_object_signals[SO_LAST_SIGNAL] = { 0 };
#endif