audioclock: API: Add gst_audio_clock_new_full() with a GDestroyNotify for the user_data
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 8 Jul 2010 06:32:22 +0000 (08:32 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 16 Jul 2010 15:40:17 +0000 (17:40 +0200)
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
gst-libs/gst/audio/gstaudioclock.c
gst-libs/gst/audio/gstaudioclock.h
win32/common/libgstaudio.def

index 4c6b6f6..8fc9c89 100644 (file)
@@ -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
index 16e7635..5b324d6 100644 (file)
@@ -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
index 6036528..cdbe474 100644 (file)
@@ -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);
index bade681..414b2b1 100644 (file)
@@ -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