Better GstClock for pulsesrc

This clock uses the actual stream time (pa_stream_get_time) to get a more accurate timestamp.

Conflicts:

	ext/pulse/pulsesrc.c
This commit is contained in:
Mohammed Sameer 2012-04-12 13:21:17 +03:00 committed by Wim Taymans
parent 088c4442c4
commit 3bcae19398

View file

@ -104,6 +104,8 @@ static gboolean gst_pulsesrc_negotiate (GstBaseSrc * basesrc);
static GstStateChangeReturn gst_pulsesrc_change_state (GstElement *
element, GstStateChange transition);
static GstClockTime gst_pulsesrc_get_time (GstClock * clock, GstPulseSrc * src);
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
# define FORMATS "{ S16LE, S16BE, F32LE, F32BE, S32LE, S32BE, U8 }"
#else
@ -291,6 +293,15 @@ gst_pulsesrc_init (GstPulseSrc * pulsesrc)
/* this should be the default but it isn't yet */
gst_audio_base_src_set_slave_method (GST_AUDIO_BASE_SRC (pulsesrc),
GST_AUDIO_BASE_SRC_SLAVE_SKEW);
/* override with a custom clock */
if (GST_AUDIO_BASE_SRC (pulsesrc)->clock) {
gst_object_unref (GST_AUDIO_BASE_SRC (pulsesrc)->clock);
}
GST_AUDIO_BASE_SRC (pulsesrc)->clock =
gst_audio_clock_new ("GstPulseSrcClock",
(GstAudioClockGetTimeFunc) gst_pulsesrc_get_time, pulsesrc);
}
static void
@ -1659,3 +1670,28 @@ mainloop_start_failed:
return GST_STATE_CHANGE_FAILURE;
}
}
static GstClockTime
gst_pulsesrc_get_time (GstClock * clock, GstPulseSrc * src)
{
pa_usec_t time = 0;
pa_threaded_mainloop_lock (src->mainloop);
if (gst_pulsesrc_is_dead (src, TRUE)) {
goto unlock_and_out;
}
if (pa_stream_get_time (src->stream, &time) < 0) {
GST_DEBUG_OBJECT (src, "could not get time");
time = GST_CLOCK_TIME_NONE;
} else {
time *= 1000;
}
unlock_and_out:
pa_threaded_mainloop_unlock (src->mainloop);
return time;
}