mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-26 17:18:15 +00:00
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.
This commit is contained in:
parent
c95d0034af
commit
8989ad93d9
4 changed files with 52 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -126,6 +144,35 @@ gst_audio_clock_new (const gchar * name, GstAudioClockGetTimeFunc func,
|
|||
return (GstClock *) aclock;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue