From a4cde36476ba2f20466f3d44f421ad1eb21b8576 Mon Sep 17 00:00:00 2001 From: Danny Smith Date: Fri, 8 Jun 2018 11:03:03 +0200 Subject: [PATCH] alsasrc: added option for chosing timestamps Added an option for chosing if driver or pipeline timestamps shall be used. --- ext/alsa/gstalsasrc.c | 31 +++++++++++++++++++++++++++---- ext/alsa/gstalsasrc.h | 1 + 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ext/alsa/gstalsasrc.c b/ext/alsa/gstalsasrc.c index 6ee0ca8..3c28ac9 100644 --- a/ext/alsa/gstalsasrc.c +++ b/ext/alsa/gstalsasrc.c @@ -54,9 +54,10 @@ #define ESTRPIPE EPIPE #endif -#define DEFAULT_PROP_DEVICE "default" -#define DEFAULT_PROP_DEVICE_NAME "" -#define DEFAULT_PROP_CARD_NAME "" +#define DEFAULT_PROP_DEVICE "default" +#define DEFAULT_PROP_DEVICE_NAME "" +#define DEFAULT_PROP_CARD_NAME "" +#define DEFAULT_PROP_USE_DRIVER_TIMESTAMP TRUE enum { @@ -64,6 +65,7 @@ enum PROP_DEVICE, PROP_DEVICE_NAME, PROP_CARD_NAME, + PROP_USE_DRIVER_TIMESTAMP, PROP_LAST }; @@ -171,6 +173,12 @@ gst_alsasrc_class_init (GstAlsaSrcClass * klass) g_param_spec_string ("card-name", "Card name", "Human-readable name of the sound card", DEFAULT_PROP_CARD_NAME, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (gobject_class, PROP_USE_DRIVER_TIMESTAMP, + g_param_spec_boolean ("use-driver-timestamps", "Use driver timestamps", + "Use driver timestamps or the pipeline clock timestamps", + DEFAULT_PROP_USE_DRIVER_TIMESTAMP, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); } static void @@ -189,6 +197,11 @@ gst_alsasrc_set_property (GObject * object, guint prop_id, src->device = g_strdup (DEFAULT_PROP_DEVICE); } break; + case PROP_USE_DRIVER_TIMESTAMP: + GST_OBJECT_LOCK (src); + src->use_driver_timestamps = g_value_get_boolean (value); + GST_OBJECT_UNLOCK (src); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -217,6 +230,11 @@ gst_alsasrc_get_property (GObject * object, guint prop_id, gst_alsa_find_card_name (GST_OBJECT_CAST (src), src->device, SND_PCM_STREAM_CAPTURE)); break; + case PROP_USE_DRIVER_TIMESTAMP: + GST_OBJECT_LOCK (src); + g_value_set_boolean (value, src->use_driver_timestamps); + GST_OBJECT_UNLOCK (src); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -250,9 +268,13 @@ gst_alsasrc_change_state (GstElement * element, GstStateChange transition) if (GST_IS_SYSTEM_CLOCK (clk)) { gint clocktype; g_object_get (clk, "clock-type", &clocktype, NULL); - if (clocktype == GST_CLOCK_TYPE_MONOTONIC) { + if (clocktype == GST_CLOCK_TYPE_MONOTONIC && + alsa->use_driver_timestamps) { GST_INFO ("Using driver timestamps !"); alsa->driver_timestamps = TRUE; + } else { + GST_INFO ("Not using driver timestamps !"); + alsa->driver_timestamps = FALSE; } } @@ -273,6 +295,7 @@ gst_alsasrc_init (GstAlsaSrc * alsasrc) alsasrc->device = g_strdup (DEFAULT_PROP_DEVICE); alsasrc->cached_caps = NULL; alsasrc->driver_timestamps = FALSE; + alsasrc->use_driver_timestamps = DEFAULT_PROP_USE_DRIVER_TIMESTAMP; g_mutex_init (&alsasrc->alsa_lock); } diff --git a/ext/alsa/gstalsasrc.h b/ext/alsa/gstalsasrc.h index 57e2701..708c460 100644 --- a/ext/alsa/gstalsasrc.h +++ b/ext/alsa/gstalsasrc.h @@ -64,6 +64,7 @@ struct _GstAlsaSrc { guint channels; gint bpf; gboolean driver_timestamps; + gboolean use_driver_timestamps; guint buffer_time; guint period_time; -- 2.7.4