diff options
author | Mohammed Sameer <msameer@foolab.org> | 2012-04-12 13:21:17 +0300 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2012-06-07 14:29:52 +0200 |
commit | e62d5bdace82f263385d005dcc2f57560cdfcdb9 (patch) | |
tree | 300dc9963b0f527a6c9420d042ca4761c0b45333 /ext | |
parent | 2f976b7bb8afa1bbec7484bcef5e51dfdc5072e5 (diff) |
Better GstClock for pulsesrc
This clock uses the actual stream time (pa_stream_get_time) to get a more accurate timestamp.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/pulse/pulsesrc.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ext/pulse/pulsesrc.c b/ext/pulse/pulsesrc.c index 7bafb4e77..d8387bdb3 100644 --- a/ext/pulse/pulsesrc.c +++ b/ext/pulse/pulsesrc.c @@ -111,6 +111,8 @@ static GstStateChangeReturn gst_pulsesrc_change_state (GstElement * static void gst_pulsesrc_init_interfaces (GType type); +static GstClockTime gst_pulsesrc_get_time (GstClock * clock, GstPulseSrc * src); + #if (G_BYTE_ORDER == G_LITTLE_ENDIAN) # define ENDIANNESS "LITTLE_ENDIAN, BIG_ENDIAN" #else @@ -398,6 +400,14 @@ gst_pulsesrc_init (GstPulseSrc * pulsesrc, GstPulseSrcClass * klass) /* this should be the default but it isn't yet */ gst_base_audio_src_set_slave_method (GST_BASE_AUDIO_SRC (pulsesrc), GST_BASE_AUDIO_SRC_SLAVE_SKEW); + + // override with a custom clock + if (GST_BASE_AUDIO_SRC (pulsesrc)->clock) { + gst_object_unref (GST_BASE_AUDIO_SRC (pulsesrc)->clock); + } + + GST_BASE_AUDIO_SRC (pulsesrc)->clock = gst_audio_clock_new ("GstPulseSrcClock", + (GstAudioClockGetTimeFunc) gst_pulsesrc_get_time, pulsesrc); } static void @@ -1748,3 +1758,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; +} |