From 24286f16123cd3ccb2c6347359ff692e95eca8a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Mon, 19 Aug 2013 12:46:45 -0400 Subject: [PATCH] v4l2: Use G_DEFINE_ macros for added thread safety --- sys/v4l2/gstv4l2tuner.c | 66 ++--------------------------------------- sys/v4l2/tuner.c | 29 ++---------------- sys/v4l2/tunerchannel.c | 37 ++--------------------- sys/v4l2/tunernorm.c | 36 ++-------------------- 4 files changed, 11 insertions(+), 157 deletions(-) diff --git a/sys/v4l2/gstv4l2tuner.c b/sys/v4l2/gstv4l2tuner.c index 536fbbd7c5..3a82eb72a6 100644 --- a/sys/v4l2/gstv4l2tuner.c +++ b/sys/v4l2/gstv4l2tuner.c @@ -31,47 +31,15 @@ #include "gstv4l2object.h" #include "v4l2_calls.h" -static void gst_v4l2_tuner_channel_class_init (GstV4l2TunerChannelClass * - klass); -static void gst_v4l2_tuner_channel_init (GstV4l2TunerChannel * channel); +G_DEFINE_TYPE (GstV4l2TunerChannel, gst_v4l2_tuner_channel, + GST_TYPE_TUNER_CHANNEL); -static void gst_v4l2_tuner_norm_class_init (GstV4l2TunerNormClass * klass); -static void gst_v4l2_tuner_norm_init (GstV4l2TunerNorm * norm); +G_DEFINE_TYPE (GstV4l2TunerNorm, gst_v4l2_tuner_norm, GST_TYPE_TUNER_NORM); -static GstTunerNormClass *norm_parent_class = NULL; -static GstTunerChannelClass *channel_parent_class = NULL; - -GType -gst_v4l2_tuner_channel_get_type (void) -{ - static GType gst_v4l2_tuner_channel_type = 0; - - if (!gst_v4l2_tuner_channel_type) { - static const GTypeInfo v4l2_tuner_channel_info = { - sizeof (GstV4l2TunerChannelClass), - NULL, - NULL, - (GClassInitFunc) gst_v4l2_tuner_channel_class_init, - NULL, - NULL, - sizeof (GstV4l2TunerChannel), - 0, - (GInstanceInitFunc) gst_v4l2_tuner_channel_init, - NULL - }; - - gst_v4l2_tuner_channel_type = - g_type_register_static (GST_TYPE_TUNER_CHANNEL, - "GstV4l2TunerChannel", &v4l2_tuner_channel_info, 0); - } - - return gst_v4l2_tuner_channel_type; -} static void gst_v4l2_tuner_channel_class_init (GstV4l2TunerChannelClass * klass) { - channel_parent_class = g_type_class_peek_parent (klass); } static void @@ -82,37 +50,9 @@ gst_v4l2_tuner_channel_init (GstV4l2TunerChannel * channel) channel->audio = (guint32) - 1; } -GType -gst_v4l2_tuner_norm_get_type (void) -{ - static GType gst_v4l2_tuner_norm_type = 0; - - if (!gst_v4l2_tuner_norm_type) { - static const GTypeInfo v4l2_tuner_norm_info = { - sizeof (GstV4l2TunerNormClass), - NULL, - NULL, - (GClassInitFunc) gst_v4l2_tuner_norm_class_init, - NULL, - NULL, - sizeof (GstV4l2TunerNorm), - 0, - (GInstanceInitFunc) gst_v4l2_tuner_norm_init, - NULL - }; - - gst_v4l2_tuner_norm_type = - g_type_register_static (GST_TYPE_TUNER_NORM, - "GstV4l2TunerNorm", &v4l2_tuner_norm_info, 0); - } - - return gst_v4l2_tuner_norm_type; -} - static void gst_v4l2_tuner_norm_class_init (GstV4l2TunerNormClass * klass) { - norm_parent_class = g_type_class_peek_parent (klass); } static void diff --git a/sys/v4l2/tuner.c b/sys/v4l2/tuner.c index eb897b5418..b6b3fe9179 100644 --- a/sys/v4l2/tuner.c +++ b/sys/v4l2/tuner.c @@ -82,37 +82,12 @@ enum LAST_SIGNAL }; -static void gst_tuner_class_init (GstTunerInterface * iface); - static guint gst_tuner_signals[LAST_SIGNAL] = { 0 }; -GType -gst_tuner_get_type (void) -{ - static GType gst_tuner_type = 0; - - if (!gst_tuner_type) { - static const GTypeInfo gst_tuner_info = { - sizeof (GstTunerInterface), - (GBaseInitFunc) gst_tuner_class_init, - NULL, - NULL, - NULL, - NULL, - 0, - 0, - NULL, - }; - - gst_tuner_type = g_type_register_static (G_TYPE_INTERFACE, - "GstTuner", &gst_tuner_info, 0); - } - - return gst_tuner_type; -} +G_DEFINE_INTERFACE (GstTuner, gst_tuner, G_TYPE_INVALID); static void -gst_tuner_class_init (GstTunerInterface * iface) +gst_tuner_default_init (GstTunerInterface * iface) { static gboolean initialized = FALSE; diff --git a/sys/v4l2/tunerchannel.c b/sys/v4l2/tunerchannel.c index 0911f672be..6e456967bc 100644 --- a/sys/v4l2/tunerchannel.c +++ b/sys/v4l2/tunerchannel.c @@ -51,47 +51,17 @@ enum LAST_SIGNAL }; -static void gst_tuner_channel_class_init (GstTunerChannelClass * klass); -static void gst_tuner_channel_init (GstTunerChannel * channel); +G_DEFINE_TYPE (GstTunerChannel, gst_tuner_channel, G_TYPE_OBJECT); + static void gst_tuner_channel_dispose (GObject * object); -static GObjectClass *parent_class = NULL; static guint signals[LAST_SIGNAL] = { 0 }; -GType -gst_tuner_channel_get_type (void) -{ - static GType gst_tuner_channel_type = 0; - - if (!gst_tuner_channel_type) { - static const GTypeInfo tuner_channel_info = { - sizeof (GstTunerChannelClass), - NULL, - NULL, - (GClassInitFunc) gst_tuner_channel_class_init, - NULL, - NULL, - sizeof (GstTunerChannel), - 0, - (GInstanceInitFunc) gst_tuner_channel_init, - NULL - }; - - gst_tuner_channel_type = - g_type_register_static (G_TYPE_OBJECT, - "GstTunerChannel", &tuner_channel_info, 0); - } - - return gst_tuner_channel_type; -} - static void gst_tuner_channel_class_init (GstTunerChannelClass * klass) { GObjectClass *object_klass = (GObjectClass *) klass; - parent_class = g_type_class_peek_parent (klass); - /** * GstTunerChannel::frequency-changed: * @tunerchannel: The #GstTunerChannel @@ -143,6 +113,5 @@ gst_tuner_channel_dispose (GObject * object) channel->label = NULL; } - if (parent_class->dispose) - parent_class->dispose (object); + G_OBJECT_CLASS (gst_tuner_channel_parent_class)->dispose (object); } diff --git a/sys/v4l2/tunernorm.c b/sys/v4l2/tunernorm.c index a43fce536b..5c57ffb7d2 100644 --- a/sys/v4l2/tunernorm.c +++ b/sys/v4l2/tunernorm.c @@ -44,47 +44,18 @@ enum LAST_SIGNAL }; -static void gst_tuner_norm_class_init (GstTunerNormClass * klass); -static void gst_tuner_norm_init (GstTunerNorm * norm); +G_DEFINE_TYPE (GstTunerNorm, gst_tuner_norm, G_TYPE_OBJECT); + static void gst_tuner_norm_dispose (GObject * object); -static GObjectClass *parent_class = NULL; /*static guint signals[LAST_SIGNAL] = { 0 };*/ -GType -gst_tuner_norm_get_type (void) -{ - static GType gst_tuner_norm_type = 0; - - if (!gst_tuner_norm_type) { - static const GTypeInfo tuner_norm_info = { - sizeof (GstTunerNormClass), - NULL, - NULL, - (GClassInitFunc) gst_tuner_norm_class_init, - NULL, - NULL, - sizeof (GstTunerNorm), - 0, - (GInstanceInitFunc) gst_tuner_norm_init, - NULL - }; - - gst_tuner_norm_type = - g_type_register_static (G_TYPE_OBJECT, - "GstTunerNorm", &tuner_norm_info, 0); - } - - return gst_tuner_norm_type; -} - static void gst_tuner_norm_class_init (GstTunerNormClass * klass) { GObjectClass *object_klass = (GObjectClass *) klass; - parent_class = g_type_class_peek_parent (klass); object_klass->dispose = gst_tuner_norm_dispose; } @@ -106,6 +77,5 @@ gst_tuner_norm_dispose (GObject * object) norm->label = NULL; } - if (parent_class->dispose) - parent_class->dispose (object); + G_OBJECT_CLASS (gst_tuner_norm_parent_class)->dispose (object); } -- 2.34.1