audioclock: add methods for the internal offset

Add two methods for getting the unadjusted time of the clock and one for
adjusting an internal time. We will need these methods for correctly handling
the time after a gst_audio_clock_reset().

Add a debug category and some debug lines to the audio clock.

API: gst_audio_clock_get_time()
API: gst_audio_clock_adjust()
API: GST_AUDIO_CLOCK_CAST()
This commit is contained in:
Wim Taymans 2009-04-14 13:08:52 +02:00
parent 4265511b70
commit 4231d54823
3 changed files with 73 additions and 3 deletions

View file

@ -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;
}

View file

@ -23,6 +23,7 @@
#ifndef __GST_AUDIO_CLOCK_H__
#define __GST_AUDIO_CLOCK_H__
#include <gst/gst.h>
#include <gst/gstsystemclock.h>
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__ */

View file

@ -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