mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
dtmfsrc: Align DTMF sound buffers with last-stop from event
Also make sure the timestamps never go backwards
This commit is contained in:
parent
2c7257481a
commit
e8268053c2
2 changed files with 40 additions and 10 deletions
|
@ -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:
|
||||
|
|
|
@ -81,6 +81,8 @@ struct _GstDTMFSrc
|
|||
gboolean paused;
|
||||
GstClockID clockid;
|
||||
|
||||
GstClockTime last_stop;
|
||||
|
||||
gint sample_rate;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue