diff --git a/gst-libs/gst/audio/gstaudioclock.c b/gst-libs/gst/audio/gstaudioclock.c index d23cfab0186effef0b1181cc0ea58063a2b911e9..9a439f1100bc691964602b6475006f26f357360b 100644 --- a/gst-libs/gst/audio/gstaudioclock.c +++ b/gst-libs/gst/audio/gstaudioclock.c @@ -39,6 +39,9 @@ #include "gstaudioclock.h" +GST_DEBUG_CATEGORY_STATIC (gst_audio_clock_debug); +#define GST_CAT_DEFAULT gst_audio_clock_debug + static void gst_audio_clock_class_init (GstAudioClockClass * klass); static void gst_audio_clock_init (GstAudioClock * clock); @@ -88,6 +91,9 @@ gst_audio_clock_class_init (GstAudioClockClass * klass) parent_class = g_type_class_peek_parent (klass); gstclock_class->get_internal_time = gst_audio_clock_get_internal_time; + + GST_DEBUG_CATEGORY_INIT (gst_audio_clock_debug, "audioclock", 0, + "audioclock"); } static void @@ -136,10 +142,18 @@ gst_audio_clock_new (const gchar * name, GstAudioClockGetTimeFunc func, void gst_audio_clock_reset (GstAudioClock * clock, GstClockTime time) { + GstClockTimeDiff time_offset; + if (clock->last_time >= time) - clock->abidata.ABI.time_offset = clock->last_time - time; + time_offset = clock->last_time - time; else - clock->abidata.ABI.time_offset = -(time - clock->last_time); + time_offset = -(time - clock->last_time); + + clock->abidata.ABI.time_offset = time_offset; + + GST_DEBUG_OBJECT (clock, + "reset clock to %" GST_TIME_FORMAT ", offset %" GST_TIME_FORMAT, + GST_TIME_ARGS (time), GST_TIME_ARGS (time_offset)); } static GstClockTime @@ -148,7 +162,7 @@ gst_audio_clock_get_internal_time (GstClock * clock) GstAudioClock *aclock; GstClockTime result; - aclock = GST_AUDIO_CLOCK (clock); + aclock = GST_AUDIO_CLOCK_CAST (clock); result = aclock->func (clock, aclock->user_data); if (result == GST_CLOCK_TIME_NONE) @@ -159,3 +173,51 @@ gst_audio_clock_get_internal_time (GstClock * clock) } return result; } + +/** + * gst_audio_clock_get_time: + * @clock: a #GstAudioClock + * + * Report the time as returned by the #GstAudioClockGetTimeFunc without applying + * any offsets. + * + * Returns: the time as reported by the time function of the audio clock + * + * Since: 0.10.23 + */ +GstClockTime +gst_audio_clock_get_time (GstClock * clock) +{ + GstAudioClock *aclock; + GstClockTime result; + + aclock = GST_AUDIO_CLOCK_CAST (clock); + + result = aclock->func (clock, aclock->user_data); + + return result; +} + +/** + * gst_audio_clock_adjust: + * @clock: a #GstAudioClock + * @time: a #GstClockTime + * + * Adjust @time with the internal offset of the audio clock. + * + * Returns: @time adjusted with the internal offset. + * + * Since: 0.10.23 + */ +GstClockTime +gst_audio_clock_adjust (GstClock * clock, GstClockTime time) +{ + GstAudioClock *aclock; + GstClockTime result; + + aclock = GST_AUDIO_CLOCK_CAST (clock); + + result = time + aclock->abidata.ABI.time_offset; + + return result; +} diff --git a/gst-libs/gst/audio/gstaudioclock.h b/gst-libs/gst/audio/gstaudioclock.h index 0613a14ec81b00443502f1e03a37954449cfc047..603652899235d0061793ef554290a2acaa3baa4a 100644 --- a/gst-libs/gst/audio/gstaudioclock.h +++ b/gst-libs/gst/audio/gstaudioclock.h @@ -23,6 +23,7 @@ #ifndef __GST_AUDIO_CLOCK_H__ #define __GST_AUDIO_CLOCK_H__ +#include #include G_BEGIN_DECLS @@ -37,6 +38,8 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_CLOCK)) #define GST_IS_AUDIO_CLOCK_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_CLOCK)) +#define GST_AUDIO_CLOCK_CAST(obj) \ + ((GstAudioClock*)(obj)) typedef struct _GstAudioClock GstAudioClock; typedef struct _GstAudioClockClass GstAudioClockClass; @@ -92,6 +95,9 @@ GstClock* gst_audio_clock_new (const gchar *name, GstAudioCloc gpointer user_data); void gst_audio_clock_reset (GstAudioClock *clock, GstClockTime time); +GstClockTime gst_audio_clock_get_time (GstClock * clock); +GstClockTime gst_audio_clock_adjust (GstClock * clock, GstClockTime time); + G_END_DECLS #endif /* __GST_AUDIO_CLOCK_H__ */ diff --git a/win32/common/libgstaudio.def b/win32/common/libgstaudio.def index 7f2abc8c367d8e69c346e6b130ec944ad93c4713..bade681465e262bb51bceaba4015614737cb4c72 100644 --- a/win32/common/libgstaudio.def +++ b/win32/common/libgstaudio.def @@ -2,6 +2,8 @@ EXPORTS gst_audio_buffer_clip gst_audio_channel_position_get_type gst_audio_check_channel_positions + gst_audio_clock_adjust + gst_audio_clock_get_time gst_audio_clock_get_type gst_audio_clock_new gst_audio_clock_reset