From 98064ed9bfee75bf6b438db38b87f2387ec0d491 Mon Sep 17 00:00:00 2001 From: Evan Nemerson Date: Thu, 26 Jun 2014 18:01:06 -0700 Subject: [PATCH] audioringbuffer: add set_callback_full() for g-i https://bugzilla.gnome.org/show_bug.cgi?id=678301 --- docs/libs/gst-plugins-base-libs-sections.txt | 1 + gst-libs/gst/audio/gstaudioringbuffer.c | 39 +++++++++++++++++++- gst-libs/gst/audio/gstaudioringbuffer.h | 14 +++++-- win32/common/libgstaudio.def | 1 + 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 961c876821..58781a0e8a 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -593,6 +593,7 @@ GST_AUDIO_RING_BUFFER_SIGNAL GST_AUDIO_RING_BUFFER_WAIT gst_audio_ring_buffer_set_callback +gst_audio_ring_buffer_set_callback_full gst_audio_ring_buffer_acquire gst_audio_ring_buffer_release diff --git a/gst-libs/gst/audio/gstaudioringbuffer.c b/gst-libs/gst/audio/gstaudioringbuffer.c index 1302c282c9..fb254e5c01 100644 --- a/gst-libs/gst/audio/gstaudioringbuffer.c +++ b/gst-libs/gst/audio/gstaudioringbuffer.c @@ -109,6 +109,9 @@ gst_audio_ring_buffer_finalize (GObject * object) g_cond_clear (&ringbuffer->cond); g_free (ringbuffer->empty_seg); + if (ringbuffer->cb_data_notify != NULL) + ringbuffer->cb_data_notify (ringbuffer->cb_data); + G_OBJECT_CLASS (gst_audio_ring_buffer_parent_class)->finalize (G_OBJECT (ringbuffer)); } @@ -356,9 +359,9 @@ gst_audio_ring_buffer_convert (GstAudioRingBuffer * buf, } /** - * gst_audio_ring_buffer_set_callback: + * gst_audio_ring_buffer_set_callback: (skip) * @buf: the #GstAudioRingBuffer to set the callback on - * @cb: (scope async): the callback to set + * @cb: (allow-none): the callback to set * @user_data: user data passed to the callback * * Sets the given callback function on the buffer. This function @@ -370,12 +373,44 @@ void gst_audio_ring_buffer_set_callback (GstAudioRingBuffer * buf, GstAudioRingBufferCallback cb, gpointer user_data) { + gst_audio_ring_buffer_set_callback_full (buf, cb, user_data, NULL); +} + +/** + * gst_audio_ring_buffer_set_callback_full: (rename-to gst_audio_ring_buffer_set_callback) + * @buf: the #GstAudioRingBuffer to set the callback on + * @cb: (allow-none): the callback to set + * @user_data: user data passed to the callback + * @notify: function to be called when @user_data is no longer needed + * + * Sets the given callback function on the buffer. This function + * will be called every time a segment has been written to a device. + * + * MT safe. + * + * Since: 1.12 + */ +void +gst_audio_ring_buffer_set_callback_full (GstAudioRingBuffer * buf, + GstAudioRingBufferCallback cb, gpointer user_data, GDestroyNotify notify) +{ + gpointer old_data = NULL; + GDestroyNotify old_notify; + g_return_if_fail (GST_IS_AUDIO_RING_BUFFER (buf)); GST_OBJECT_LOCK (buf); + old_notify = buf->cb_data_notify; + old_data = buf->cb_data; + buf->callback = cb; buf->cb_data = user_data; + buf->cb_data_notify = notify; GST_OBJECT_UNLOCK (buf); + + if (old_notify) { + old_notify (old_data); + } } diff --git a/gst-libs/gst/audio/gstaudioringbuffer.h b/gst-libs/gst/audio/gstaudioringbuffer.h index b0e3e9b36d..4ddc8e1613 100644 --- a/gst-libs/gst/audio/gstaudioringbuffer.h +++ b/gst-libs/gst/audio/gstaudioringbuffer.h @@ -205,8 +205,10 @@ struct _GstAudioRingBuffer { gint may_start; gboolean active; + GDestroyNotify cb_data_notify; + /*< private >*/ - gpointer _gst_reserved[GST_PADDING]; + gpointer _gst_reserved[GST_PADDING - 1]; }; /** @@ -260,9 +262,13 @@ struct _GstAudioRingBufferClass { GType gst_audio_ring_buffer_get_type(void); /* callback stuff */ -void gst_audio_ring_buffer_set_callback (GstAudioRingBuffer *buf, - GstAudioRingBufferCallback cb, - gpointer user_data); +void gst_audio_ring_buffer_set_callback (GstAudioRingBuffer *buf, + GstAudioRingBufferCallback cb, + gpointer user_data); +void gst_audio_ring_buffer_set_callback_full (GstAudioRingBuffer *buf, + GstAudioRingBufferCallback cb, + gpointer user_data, + GDestroyNotify notify); gboolean gst_audio_ring_buffer_parse_caps (GstAudioRingBufferSpec *spec, GstCaps *caps); void gst_audio_ring_buffer_debug_spec_caps (GstAudioRingBufferSpec *spec); diff --git a/win32/common/libgstaudio.def b/win32/common/libgstaudio.def index 0590d87de1..6fa0756e51 100644 --- a/win32/common/libgstaudio.def +++ b/win32/common/libgstaudio.def @@ -197,6 +197,7 @@ EXPORTS gst_audio_ring_buffer_release gst_audio_ring_buffer_samples_done gst_audio_ring_buffer_set_callback + gst_audio_ring_buffer_set_callback_full gst_audio_ring_buffer_set_channel_positions gst_audio_ring_buffer_set_flushing gst_audio_ring_buffer_set_sample