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>
This commit is contained in:
Seungha Yang 2021-06-06 22:32:08 +09:00
parent f9d7b708e1
commit 4d1101d335
3 changed files with 44 additions and 3 deletions

View file

@ -1261,6 +1261,20 @@
"readable": true,
"type": "gboolean",
"writable": true
},
"samplesperbuffer": {
"blurb": "Number of samples in each outgoing buffer",
"conditionally-available": false,
"construct": false,
"construct-only": false,
"controllable": false,
"default": "240",
"max": "2147483647",
"min": "1",
"mutable": "null",
"readable": true,
"type": "gint",
"writable": true
}
},
"rank": "primary"

View file

@ -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);

View file

@ -56,6 +56,7 @@ struct _GstAudioLatency
/* properties */
gboolean print_latency;
gint samples_per_buffer;
};
struct _GstAudioLatencyClass