summaryrefslogtreecommitdiff
path: root/sys/tinyalsa
diff options
context:
space:
mode:
authorArun Raghavan <arun@centricular.com>2016-02-05 15:43:22 +0530
committerArun Raghavan <git@arunraghavan.net>2016-02-05 15:56:05 +0530
commit5f9065c11481c78edcf223acae0a63564f30a791 (patch)
tree9a106fbb7e77f7f61204f6949442538040832440 /sys/tinyalsa
parent1b0198631c229f427630fd5dc24f05f3b04378d0 (diff)
downloadgstreamer-plugins-bad-5f9065c11481c78edcf223acae0a63564f30a791.tar.gz
tinyalsasink: Limit period size and count to what the h/w permits
Diffstat (limited to 'sys/tinyalsa')
-rw-r--r--sys/tinyalsa/tinyalsasink.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/sys/tinyalsa/tinyalsasink.c b/sys/tinyalsa/tinyalsasink.c
index 2d6e3a6b8..f5ebb7662 100644
--- a/sys/tinyalsa/tinyalsasink.c
+++ b/sys/tinyalsa/tinyalsasink.c
@@ -277,17 +277,41 @@ pcm_config_from_spec (struct pcm_config *config,
config->period_count = spec->buffer_time / spec->latency_time;
}
+#define LIMIT(i, min, max) \
+ if ((i) < (min)) \
+ (i) = (min); \
+ else if ((i) > (max)) \
+ (i) = (max);
+
static gboolean
gst_tinyalsa_sink_prepare (GstAudioSink * asink, GstAudioRingBufferSpec * spec)
{
GstTinyalsaSink *sink = GST_TINYALSA_SINK (asink);
struct pcm_config config = { 0, };
+ struct pcm_params *params = NULL;
+ int period_size_min, period_size_max;
+ int periods_min, periods_max;
pcm_config_from_spec (&config, spec);
GST_DEBUG_OBJECT (sink, "Requesting %u periods of %u frames",
config.period_count, config.period_size);
+ params = pcm_params_get (sink->card, sink->device, PCM_OUT);
+ if (!params)
+ GST_ERROR_OBJECT (sink, "Could not get PCM params");
+
+ period_size_min = pcm_params_get_min (params, PCM_PARAM_PERIOD_SIZE);
+ period_size_max = pcm_params_get_max (params, PCM_PARAM_PERIOD_SIZE);
+ periods_min = pcm_params_get_min (params, PCM_PARAM_PERIODS);
+ periods_max = pcm_params_get_max (params, PCM_PARAM_PERIODS);
+
+ pcm_params_free (params);
+
+ /* Snap period size/count to the permitted range */
+ LIMIT (config.period_size, period_size_min, period_size_max);
+ LIMIT (config.period_count, periods_min, periods_max);
+
/* mutex with getcaps */
GST_OBJECT_LOCK (sink);