From 3bcae1939870094062930c6932e436e43a29701c Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Thu, 12 Apr 2012 13:21:17 +0300 Subject: [PATCH] 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 --- ext/pulse/pulsesrc.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ext/pulse/pulsesrc.c b/ext/pulse/pulsesrc.c index 995b533372..41e5b4a7f5 100644 --- a/ext/pulse/pulsesrc.c +++ b/ext/pulse/pulsesrc.c @@ -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; +}