From 8989ad93d94f1f99a8ad238456fefd914b966b7f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 8 Jul 2010 08:32:22 +0200 Subject: [PATCH] audioclock: API: Add gst_audio_clock_new_full() with a GDestroyNotify for the user_data Elements usually use their own instance as instance data but the clock can have a longer lifetime than their elements and the clock doesn't own a reference of the element. Fixes bug #623807. --- docs/libs/gst-plugins-base-libs-sections.txt | 1 + gst-libs/gst/audio/gstaudioclock.c | 47 ++++++++++++++++++++++++++++ gst-libs/gst/audio/gstaudioclock.h | 3 ++ win32/common/libgstaudio.def | 1 + 4 files changed, 52 insertions(+) diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 4c6b6f6..8fc9c89 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -107,6 +107,7 @@ gst_buffer_format_type_get_type GstAudioClock GstAudioClockGetTimeFunc gst_audio_clock_new +gst_audio_clock_new_full gst_audio_clock_adjust gst_audio_clock_get_time gst_audio_clock_reset diff --git a/gst-libs/gst/audio/gstaudioclock.c b/gst-libs/gst/audio/gstaudioclock.c index 16e7635..5b324d6 100644 --- a/gst-libs/gst/audio/gstaudioclock.c +++ b/gst-libs/gst/audio/gstaudioclock.c @@ -45,6 +45,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_audio_clock_debug); static void gst_audio_clock_class_init (GstAudioClockClass * klass); static void gst_audio_clock_init (GstAudioClock * clock); +static void gst_audio_clock_dispose (GObject * object); + static GstClockTime gst_audio_clock_get_internal_time (GstClock * clock); static GstSystemClockClass *parent_class = NULL; @@ -81,11 +83,14 @@ static void gst_audio_clock_class_init (GstAudioClockClass * klass) { GstClockClass *gstclock_class; + GObjectClass *gobject_class; + gobject_class = (GObjectClass *) klass; gstclock_class = (GstClockClass *) klass; parent_class = g_type_class_peek_parent (klass); + gobject_class->dispose = gst_audio_clock_dispose; gstclock_class->get_internal_time = gst_audio_clock_get_internal_time; GST_DEBUG_CATEGORY_INIT (gst_audio_clock_debug, "audioclock", 0, @@ -101,6 +106,19 @@ gst_audio_clock_init (GstAudioClock * clock) GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER); } +static void +gst_audio_clock_dispose (GObject * object) +{ + GstAudioClock *clock = GST_AUDIO_CLOCK (object); + + if (clock->abidata.ABI.destroy_notify && clock->user_data) + clock->abidata.ABI.destroy_notify (clock->user_data); + clock->abidata.ABI.destroy_notify = NULL; + clock->user_data = NULL; + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + /** * gst_audio_clock_new: * @name: the name of the clock @@ -127,6 +145,35 @@ gst_audio_clock_new (const gchar * name, GstAudioClockGetTimeFunc func, } /** + * gst_audio_clock_new_full: + * @name: the name of the clock + * @func: a function + * @user_data: user data + * @destroy_notify: #GDestroyNotify for @user_data + * + * Create a new #GstAudioClock instance. Whenever the clock time should be + * calculated it will call @func with @user_data. When @func returns + * #GST_CLOCK_TIME_NONE, the clock will return the last reported time. + * + * Returns: a new #GstAudioClock casted to a #GstClock. + * + * Since: 0.10.31 + */ +GstClock * +gst_audio_clock_new_full (const gchar * name, GstAudioClockGetTimeFunc func, + gpointer user_data, GDestroyNotify destroy_notify) +{ + GstAudioClock *aclock = + GST_AUDIO_CLOCK (g_object_new (GST_TYPE_AUDIO_CLOCK, "name", name, NULL)); + + aclock->func = func; + aclock->user_data = user_data; + aclock->abidata.ABI.destroy_notify = destroy_notify; + + return (GstClock *) aclock; +} + +/** * gst_audio_clock_reset: * @clock: a #GstAudioClock * @time: a #GstClockTime diff --git a/gst-libs/gst/audio/gstaudioclock.h b/gst-libs/gst/audio/gstaudioclock.h index 6036528..cdbe474 100644 --- a/gst-libs/gst/audio/gstaudioclock.h +++ b/gst-libs/gst/audio/gstaudioclock.h @@ -77,6 +77,7 @@ struct _GstAudioClock { union { struct { GstClockTimeDiff time_offset; + GDestroyNotify destroy_notify; } ABI; /* adding + 0 to mark ABI change to be undone later */ gpointer _gst_reserved[GST_PADDING + 0]; @@ -93,6 +94,8 @@ struct _GstAudioClockClass { GType gst_audio_clock_get_type (void); GstClock* gst_audio_clock_new (const gchar *name, GstAudioClockGetTimeFunc func, gpointer user_data); +GstClock* gst_audio_clock_new_full (const gchar *name, GstAudioClockGetTimeFunc func, + gpointer user_data, GDestroyNotify destroy_notify); void gst_audio_clock_reset (GstAudioClock *clock, GstClockTime time); GstClockTime gst_audio_clock_get_time (GstClock * clock); diff --git a/win32/common/libgstaudio.def b/win32/common/libgstaudio.def index bade681..414b2b1 100644 --- a/win32/common/libgstaudio.def +++ b/win32/common/libgstaudio.def @@ -6,6 +6,7 @@ EXPORTS gst_audio_clock_get_time gst_audio_clock_get_type gst_audio_clock_new + gst_audio_clock_new_full gst_audio_clock_reset gst_audio_default_registry_mixer_filter gst_audio_duration_from_pad_buffer -- 2.7.4