summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorSeungha Yang <seungha@centricular.com>2021-06-06 22:32:08 +0900
committerSeungha Yang <seungha@centricular.com>2021-07-26 20:13:03 +0900
commit4d1101d335923383c4410ef1234447258916370d (patch)
tree1bb7b1a40a9a16165d1e956fe039c8ebd8cdf4b3 /gst
parentf9d7b708e12e5560759c585b44cfa3e523b61526 (diff)
downloadgstreamer-plugins-bad-4d1101d335923383c4410ef1234447258916370d.tar.gz
audiolatency: Expose samplesperbuffer property
... for user to be able to set the number of required samples. For instance, our default value is 240 samples (about 5ms latency in case that sample rate is 48000), which might be larger than actual buffer size of audio capture device. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2307>
Diffstat (limited to 'gst')
-rw-r--r--gst/audiolatency/gstaudiolatency.c32
-rw-r--r--gst/audiolatency/gstaudiolatency.h1
2 files changed, 30 insertions, 3 deletions
diff --git a/gst/audiolatency/gstaudiolatency.c b/gst/audiolatency/gstaudiolatency.c
index 4ea491a0f..f3eae724d 100644
--- a/gst/audiolatency/gstaudiolatency.c
+++ b/gst/audiolatency/gstaudiolatency.c
@@ -86,12 +86,15 @@ GST_ELEMENT_REGISTER_DEFINE (audiolatency, "audiolatency", GST_RANK_PRIMARY,
GST_TYPE_AUDIOLATENCY);
#define DEFAULT_PRINT_LATENCY FALSE
+#define DEFAULT_SAMPLES_PER_BUFFER 240
+
enum
{
PROP_0,
PROP_PRINT_LATENCY,
PROP_LAST_LATENCY,
- PROP_AVERAGE_LATENCY
+ PROP_AVERAGE_LATENCY,
+ PROP_SAMPLES_PER_BUFFER,
};
static gint64 gst_audiolatency_get_latency (GstAudioLatency * self);
@@ -119,6 +122,9 @@ gst_audiolatency_get_property (GObject * object,
case PROP_AVERAGE_LATENCY:
g_value_set_int64 (value, gst_audiolatency_get_average_latency (self));
break;
+ case PROP_SAMPLES_PER_BUFFER:
+ g_value_set_int (value, self->samples_per_buffer);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -135,6 +141,11 @@ gst_audiolatency_set_property (GObject * object,
case PROP_PRINT_LATENCY:
self->print_latency = g_value_get_boolean (value);
break;
+ case PROP_SAMPLES_PER_BUFFER:
+ self->samples_per_buffer = g_value_get_int (value);
+ g_object_set (self->audiosrc,
+ "samplesperbuffer", self->samples_per_buffer, NULL);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -165,6 +176,20 @@ gst_audiolatency_class_init (GstAudioLatencyClass * klass)
"The running average latency, in microseconds", 0,
G_USEC_PER_SEC, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+ /**
+ * GstAudioLatency:samplesperbuffer:
+ *
+ * The number of audio samples in each outgoing buffer.
+ * See also #GstAudioTestSrc:samplesperbuffer
+ *
+ * Since: 1.20
+ */
+ g_object_class_install_property (gobject_class, PROP_SAMPLES_PER_BUFFER,
+ g_param_spec_int ("samplesperbuffer", "Samples per buffer",
+ "Number of samples in each outgoing buffer",
+ 1, G_MAXINT, DEFAULT_SAMPLES_PER_BUFFER,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
gst_element_class_add_static_pad_template (gstelement_class, &src_template);
gst_element_class_add_static_pad_template (gstelement_class, &sink_template);
@@ -183,6 +208,7 @@ gst_audiolatency_init (GstAudioLatency * self)
self->send_pts = 0;
self->recv_pts = 0;
self->print_latency = DEFAULT_PRINT_LATENCY;
+ self->samples_per_buffer = DEFAULT_SAMPLES_PER_BUFFER;
/* Setup sinkpad */
self->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink");
@@ -195,8 +221,8 @@ gst_audiolatency_init (GstAudioLatency * self)
/* Setup srcpad */
self->audiosrc = gst_element_factory_make ("audiotestsrc", NULL);
- g_object_set (self->audiosrc, "wave", 8, "samplesperbuffer", 240,
- "is-live", TRUE, NULL);
+ g_object_set (self->audiosrc, "wave", 8, "samplesperbuffer",
+ DEFAULT_SAMPLES_PER_BUFFER, "is-live", TRUE, NULL);
gst_bin_add (GST_BIN (self), self->audiosrc);
templ = gst_static_pad_template_get (&src_template);
diff --git a/gst/audiolatency/gstaudiolatency.h b/gst/audiolatency/gstaudiolatency.h
index 414b833ac..a7c68cb40 100644
--- a/gst/audiolatency/gstaudiolatency.h
+++ b/gst/audiolatency/gstaudiolatency.h
@@ -56,6 +56,7 @@ struct _GstAudioLatency
/* properties */
gboolean print_latency;
+ gint samples_per_buffer;
};
struct _GstAudioLatencyClass