ext/alsa/gstalsasink.c: If we fail to set the buffer_time and period_time alsa parameters, post a warning and leave a...

Original commit message from CVS:
* ext/alsa/gstalsasink.c: (set_hwparams):
If we fail to set the buffer_time and period_time alsa
parameters, post a warning and leave alsa select a
default instead of failing. Fixes #342085
This commit is contained in:
Wim Taymans 2006-06-16 11:04:21 +00:00
parent 4f986df2a1
commit a2ae3341a7
2 changed files with 63 additions and 22 deletions

View file

@ -1,3 +1,10 @@
2006-06-16 Wim Taymans <wim@fluendo.com>
* ext/alsa/gstalsasink.c: (set_hwparams):
If we fail to set the buffer_time and period_time alsa
parameters, post a warning and leave alsa select a
default instead of failing. Fixes #342085
2006-06-16 Tim-Philipp Müller <tim at centricular dot net> 2006-06-16 Tim-Philipp Müller <tim at centricular dot net>
* docs/libs/gst-plugins-base-libs-sections.txt: * docs/libs/gst-plugins-base-libs-sections.txt:

View file

@ -331,12 +331,19 @@ set_hwparams (GstAlsaSink * alsa)
guint rrate; guint rrate;
gint err, dir; gint err, dir;
snd_pcm_hw_params_t *params; snd_pcm_hw_params_t *params;
guint period_time, buffer_time;
snd_pcm_hw_params_alloca (&params); snd_pcm_hw_params_alloca (&params);
GST_DEBUG_OBJECT (alsa, "Negotiating to %d channels @ %d Hz (format = %s)", GST_DEBUG_OBJECT (alsa, "Negotiating to %d channels @ %d Hz (format = %s)",
alsa->channels, alsa->rate, snd_pcm_format_name (alsa->format)); alsa->channels, alsa->rate, snd_pcm_format_name (alsa->format));
/* start with requested values, if we cannot configure alsa for those values,
* we set these values to -1, which will leave the default alsa values */
buffer_time = alsa->buffer_time;
period_time = alsa->period_time;
retry:
/* choose all parameters */ /* choose all parameters */
CHECK (snd_pcm_hw_params_any (alsa->handle, params), no_config); CHECK (snd_pcm_hw_params_any (alsa->handle, params), no_config);
/* set the interleaved read/write format */ /* set the interleaved read/write format */
@ -355,26 +362,67 @@ set_hwparams (GstAlsaSink * alsa)
if (rrate != alsa->rate) if (rrate != alsa->rate)
goto rate_match; goto rate_match;
if (alsa->buffer_time != -1) { /* get and dump some limits */
/* set the buffer time */ {
CHECK (snd_pcm_hw_params_set_buffer_time_near (alsa->handle, params, guint min, max;
&alsa->buffer_time, &dir), buffer_time);
snd_pcm_hw_params_get_buffer_time_min (params, &min, &dir);
snd_pcm_hw_params_get_buffer_time_max (params, &max, &dir);
GST_DEBUG_OBJECT (alsa, "buffer time %u, min %u, max %u",
alsa->buffer_time, min, max);
snd_pcm_hw_params_get_period_time_min (params, &min, &dir);
snd_pcm_hw_params_get_period_time_max (params, &max, &dir);
GST_DEBUG_OBJECT (alsa, "period time %u, min %u, max %u",
alsa->period_time, min, max);
snd_pcm_hw_params_get_periods_min (params, &min, &dir);
snd_pcm_hw_params_get_periods_max (params, &max, &dir);
GST_DEBUG_OBJECT (alsa, "periods min %u, max %u", min, max);
} }
if (alsa->period_time != -1) {
/* now try to configure the buffer time and period time, if one
* of those fail, we fall back to the defaults and emit a warning. */
if (buffer_time != -1) {
/* set the buffer time */
if ((err = snd_pcm_hw_params_set_buffer_time_near (alsa->handle, params,
&buffer_time, &dir)) < 0) {
GST_ELEMENT_WARNING (alsa, RESOURCE, SETTINGS, (NULL),
("Unable to set buffer time %i for playback: %s",
buffer_time, snd_strerror (err)));
/* disable buffer_time the next round */
buffer_time = -1;
goto retry;
}
}
if (period_time != -1) {
/* set the period time */ /* set the period time */
CHECK (snd_pcm_hw_params_set_period_time_near (alsa->handle, params, if ((err = snd_pcm_hw_params_set_period_time_near (alsa->handle, params,
&alsa->period_time, &dir), period_time); &period_time, &dir)) < 0) {
GST_ELEMENT_WARNING (alsa, RESOURCE, SETTINGS, (NULL),
("Unable to set period time %i for playback: %s",
period_time, snd_strerror (err)));
/* disable period_time the next round */
period_time = -1;
goto retry;
}
} }
/* write the parameters to device */ /* write the parameters to device */
CHECK (snd_pcm_hw_params (alsa->handle, params), set_hw_params); CHECK (snd_pcm_hw_params (alsa->handle, params), set_hw_params);
/* now get the configured values */
CHECK (snd_pcm_hw_params_get_buffer_size (params, &alsa->buffer_size), CHECK (snd_pcm_hw_params_get_buffer_size (params, &alsa->buffer_size),
buffer_size); buffer_size);
CHECK (snd_pcm_hw_params_get_period_size (params, &alsa->period_size, &dir), CHECK (snd_pcm_hw_params_get_period_size (params, &alsa->period_size, &dir),
period_size); period_size);
GST_DEBUG_OBJECT (alsa, "buffer size %u, period size %u", alsa->buffer_size,
alsa->period_size);
return 0; return 0;
/* ERRORS */ /* ERRORS */
@ -427,26 +475,12 @@ rate_match:
("Rate doesn't match (requested %iHz, get %iHz)", alsa->rate, err)); ("Rate doesn't match (requested %iHz, get %iHz)", alsa->rate, err));
return -EINVAL; return -EINVAL;
} }
buffer_time:
{
GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
("Unable to set buffer time %i for playback: %s",
alsa->buffer_time, snd_strerror (err)));
return err;
}
buffer_size: buffer_size:
{ {
GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
("Unable to get buffer size for playback: %s", snd_strerror (err))); ("Unable to get buffer size for playback: %s", snd_strerror (err)));
return err; return err;
} }
period_time:
{
GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),
("Unable to set period time %i for playback: %s", alsa->period_time,
snd_strerror (err)));
return err;
}
period_size: period_size:
{ {
GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL), GST_ELEMENT_ERROR (alsa, RESOURCE, SETTINGS, (NULL),