From 126efa5e06d1a90f41736b78e746e982bffb980a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 14 Apr 2011 15:46:08 -0400 Subject: [PATCH] dtmfsrc: Align DTMF sound buffers with last-stop from event Also make sure the timestamps never go backwards --- gst/dtmf/gstdtmfsrc.c | 48 ++++++++++++++++++++++++++++++++++++++---------- gst/dtmf/gstdtmfsrc.h | 2 ++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/gst/dtmf/gstdtmfsrc.c b/gst/dtmf/gstdtmfsrc.c index 79525b5..eb55268 100644 --- a/gst/dtmf/gstdtmfsrc.c +++ b/gst/dtmf/gstdtmfsrc.c @@ -323,6 +323,7 @@ gst_dtmf_src_handle_dtmf_event (GstDTMFSrc * dtmfsrc, gint event_type; gboolean start; gint method; + GstClockTime last_stop; if (!gst_structure_get_int (event_structure, "type", &event_type) || !gst_structure_get_boolean (event_structure, "start", &start) || @@ -335,6 +336,14 @@ gst_dtmf_src_handle_dtmf_event (GstDTMFSrc * dtmfsrc, } } + + GST_OBJECT_LOCK (dtmfsrc); + if (gst_structure_get_clock_time (event_structure, "last-stop", &last_stop)) + dtmfsrc->last_stop = last_stop; + else + dtmfsrc->last_stop = GST_CLOCK_TIME_NONE; + GST_OBJECT_UNLOCK (dtmfsrc); + if (start) { gint event_number; gint event_volume; @@ -447,19 +456,37 @@ gst_dtmf_src_get_property (GObject * object, guint prop_id, GValue * value, static void gst_dtmf_prepare_timestamps (GstDTMFSrc * dtmfsrc) { - GstClock *clock; + GstClockTime last_stop; + GstClockTime timestamp; - clock = gst_element_get_clock (GST_ELEMENT (dtmfsrc)); - if (clock != NULL) { - dtmfsrc->timestamp = gst_clock_get_time (clock) - - gst_element_get_base_time (GST_ELEMENT (dtmfsrc)); - gst_object_unref (clock); + GST_OBJECT_LOCK (dtmfsrc); + last_stop = dtmfsrc->last_stop; + GST_OBJECT_UNLOCK (dtmfsrc); + + if (GST_CLOCK_TIME_IS_VALID (last_stop)) { + timestamp = last_stop; } else { - gchar *dtmf_name = gst_element_get_name (dtmfsrc); - GST_ERROR_OBJECT (dtmfsrc, "No clock set for element %s", dtmf_name); - dtmfsrc->timestamp = GST_CLOCK_TIME_NONE; - g_free (dtmf_name); + GstClock *clock; + + /* If there is no valid start time, lets use now as the start time */ + + clock = gst_element_get_clock (GST_ELEMENT (dtmfsrc)); + if (clock != NULL) { + timestamp = gst_clock_get_time (clock) + - gst_element_get_base_time (GST_ELEMENT (dtmfsrc)); + gst_object_unref (clock); + } else { + gchar *dtmf_name = gst_element_get_name (dtmfsrc); + GST_ERROR_OBJECT (dtmfsrc, "No clock set for element %s", dtmf_name); + dtmfsrc->timestamp = GST_CLOCK_TIME_NONE; + g_free (dtmf_name); + return; + } } + + /* Make sure the timestamp always goes forward */ + if (timestamp > dtmfsrc->timestamp) + dtmfsrc->timestamp = timestamp; } static void @@ -823,6 +850,7 @@ gst_dtmf_src_change_state (GstElement * element, GstStateChange transition) g_slice_free (GstDTMFSrcEvent, event); event = g_async_queue_try_pop (dtmfsrc->event_queue); } + dtmfsrc->timestamp = 0; no_preroll = TRUE; break; default: diff --git a/gst/dtmf/gstdtmfsrc.h b/gst/dtmf/gstdtmfsrc.h index aa5d35a6..cda5840 100644 --- a/gst/dtmf/gstdtmfsrc.h +++ b/gst/dtmf/gstdtmfsrc.h @@ -81,6 +81,8 @@ struct _GstDTMFSrc gboolean paused; GstClockID clockid; + GstClockTime last_stop; + gint sample_rate; }; -- 2.7.4