Commit 864a52d8 authored by Philippe Normand's avatar Philippe Normand 🥑 Committed by Tim-Philipp Müller
Browse files

pulsesink: use G_TYPE_DEFINE to define ring buffer type

The existing get_type() implementation is racy, and the
g_type_class_ref() workaround didn't actually work because
it was in the wrong function. Since class creation in GObject
is thread-safe these days (since 2.16), the class_ref workaround
is no longer needed and it is sufficient to ensure the _get_type()
function is thread-safe, which G_TYPE_DEFINE does.
parent f6240a47
......@@ -131,9 +131,7 @@ struct _GstPulseRingBufferClass
GstRingBufferClass parent_class;
static void gst_pulseringbuffer_class_init (GstPulseRingBufferClass * klass);
static void gst_pulseringbuffer_init (GstPulseRingBuffer * ringbuffer,
GstPulseRingBufferClass * klass);
static GType gst_pulseringbuffer_get_type (void);
static void gst_pulseringbuffer_finalize (GObject * object);
static GstRingBufferClass *ring_parent_class = NULL;
......@@ -151,32 +149,7 @@ static guint gst_pulseringbuffer_commit (GstRingBuffer * buf,
guint64 * sample, guchar * data, gint in_samples, gint out_samples,
gint * accum);
/* ringbuffer abstract base class */
static GType
gst_pulseringbuffer_get_type (void)
static GType ringbuffer_type = 0;
if (!ringbuffer_type) {
static const GTypeInfo ringbuffer_info = {
sizeof (GstPulseRingBufferClass),
(GClassInitFunc) gst_pulseringbuffer_class_init,
sizeof (GstPulseRingBuffer),
(GInstanceInitFunc) gst_pulseringbuffer_init,
ringbuffer_type =
g_type_register_static (GST_TYPE_RING_BUFFER, "GstPulseSinkRingBuffer",
&ringbuffer_info, 0);
return ringbuffer_type;
G_DEFINE_TYPE (GstPulseRingBuffer, gst_pulseringbuffer, GST_TYPE_RING_BUFFER);
static void
gst_pulseringbuffer_class_init (GstPulseRingBufferClass * klass)
......@@ -207,15 +180,10 @@ gst_pulseringbuffer_class_init (GstPulseRingBufferClass * klass)
GST_DEBUG_FUNCPTR (gst_pulseringbuffer_clear);
gstringbuffer_class->commit = GST_DEBUG_FUNCPTR (gst_pulseringbuffer_commit);
/* ref class from a thread-safe context to work around missing bit of
* thread-safety in GObject */
g_type_class_ref (GST_TYPE_PULSERING_BUFFER);
static void
gst_pulseringbuffer_init (GstPulseRingBuffer * pbuf,
GstPulseRingBufferClass * g_class)
gst_pulseringbuffer_init (GstPulseRingBuffer * pbuf)
pbuf->stream_name = NULL;
pbuf->context = NULL;
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