Commit f92b71ca authored by Max Kellermann's avatar Max Kellermann

output/alsa: move code from AlsaSetup() to AlsaSetupSw()

parent 2b79fe2d
...@@ -604,6 +604,38 @@ configure_hw: ...@@ -604,6 +604,38 @@ configure_hw:
} }
/** /**
* Wrapper for snd_pcm_sw_params().
*/
static void
AlsaSetupSw(snd_pcm_t *pcm, snd_pcm_uframes_t start_threshold,
snd_pcm_uframes_t avail_min)
{
snd_pcm_sw_params_t *swparams;
snd_pcm_sw_params_alloca(&swparams);
int err = snd_pcm_sw_params_current(pcm, swparams);
if (err < 0)
throw FormatRuntimeError("snd_pcm_sw_params_current() failed: %s",
snd_strerror(-err));
err = snd_pcm_sw_params_set_start_threshold(pcm, swparams,
start_threshold);
if (err < 0)
throw FormatRuntimeError("snd_pcm_sw_params_set_start_threshold() failed: %s",
snd_strerror(-err));
err = snd_pcm_sw_params_set_avail_min(pcm, swparams, avail_min);
if (err < 0)
throw FormatRuntimeError("snd_pcm_sw_params_set_avail_min() failed: %s",
snd_strerror(-err));
err = snd_pcm_sw_params(pcm, swparams);
if (err < 0)
throw FormatRuntimeError("snd_pcm_sw_params() failed: %s",
snd_strerror(-err));
}
/**
* Set up the snd_pcm_t object which was opened by the caller. Set up * Set up the snd_pcm_t object which was opened by the caller. Set up
* the configured settings and the audio format. * the configured settings and the audio format.
* *
...@@ -639,32 +671,8 @@ AlsaSetup(AlsaOutput *ad, AudioFormat &audio_format, ...@@ -639,32 +671,8 @@ AlsaSetup(AlsaOutput *ad, AudioFormat &audio_format,
throw FormatRuntimeError("snd_pcm_hw_params_get_period_size() failed: %s", throw FormatRuntimeError("snd_pcm_hw_params_get_period_size() failed: %s",
snd_strerror(-err)); snd_strerror(-err));
/* configure SW params */ AlsaSetupSw(ad->pcm, alsa_buffer_size - alsa_period_size,
snd_pcm_sw_params_t *swparams; alsa_period_size);
snd_pcm_sw_params_alloca(&swparams);
err = snd_pcm_sw_params_current(ad->pcm, swparams);
if (err < 0)
throw FormatRuntimeError("snd_pcm_sw_params_current() failed: %s",
snd_strerror(-err));
err = snd_pcm_sw_params_set_start_threshold(ad->pcm, swparams,
alsa_buffer_size -
alsa_period_size);
if (err < 0)
throw FormatRuntimeError("snd_pcm_sw_params_set_start_threshold() failed: %s",
snd_strerror(-err));
err = snd_pcm_sw_params_set_avail_min(ad->pcm, swparams,
alsa_period_size);
if (err < 0)
throw FormatRuntimeError("snd_pcm_sw_params_set_avail_min() failed: %s",
snd_strerror(-err));
err = snd_pcm_sw_params(ad->pcm, swparams);
if (err < 0)
throw FormatRuntimeError("snd_pcm_sw_params() failed: %s",
snd_strerror(-err));
FormatDebug(alsa_output_domain, "buffer_size=%u period_size=%u", FormatDebug(alsa_output_domain, "buffer_size=%u period_size=%u",
(unsigned)alsa_buffer_size, (unsigned)alsa_period_size); (unsigned)alsa_buffer_size, (unsigned)alsa_period_size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment