diff options
author | Max Kellermann <max@musicpd.org> | 2017-01-24 22:58:09 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-01-24 23:05:29 +0100 |
commit | f92b71ca99cd7bdfc6b0d7ba31ae2597f7113468 (patch) | |
tree | 8a9176dd40fe2dd86564d54d6a2a50cdbd0c7698 /src/output | |
parent | 2b79fe2d6a9cfa4bebf6375dbf266da66dbdaafe (diff) |
output/alsa: move code from AlsaSetup() to AlsaSetupSw()
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/plugins/AlsaOutputPlugin.cxx | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index f6b7f44c8..36ac5c6bc 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -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 * the configured settings and the audio format. * @@ -639,32 +671,8 @@ AlsaSetup(AlsaOutput *ad, AudioFormat &audio_format, throw FormatRuntimeError("snd_pcm_hw_params_get_period_size() failed: %s", snd_strerror(-err)); - /* configure SW params */ - snd_pcm_sw_params_t *swparams; - 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)); + AlsaSetupSw(ad->pcm, alsa_buffer_size - alsa_period_size, + alsa_period_size); FormatDebug(alsa_output_domain, "buffer_size=%u period_size=%u", (unsigned)alsa_buffer_size, (unsigned)alsa_period_size); |