From 55d76ac3a72b47407a992d989ba2516adf6744b9 Mon Sep 17 00:00:00 2001 From: Adam Miartus Date: Tue, 25 Jul 2023 14:29:35 +0200 Subject: [PATCH] alsa_driver: extract alsa_driver_get_status to a separate function --- linux/alsa/alsa_driver.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/linux/alsa/alsa_driver.c b/linux/alsa/alsa_driver.c index 1d381e67..d85dc0ce 100644 --- a/linux/alsa/alsa_driver.c +++ b/linux/alsa/alsa_driver.c @@ -1283,28 +1283,35 @@ alsa_driver_restart (alsa_driver_t *driver) } static int -alsa_driver_xrun_recovery (alsa_driver_t *driver, float *delayed_usecs) +alsa_driver_get_status (alsa_driver_t *driver) { - snd_pcm_status_t *status; int res; + snd_pcm_t *pcm_handle; + snd_pcm_status_t *status; snd_pcm_status_alloca(&status); if (driver->capture_handle) { - if ((res = snd_pcm_status(driver->capture_handle, status)) - < 0) { - jack_error("status error: %s", snd_strerror(res)); - } + pcm_handle = driver->capture_handle; } else { - if ((res = snd_pcm_status(driver->playback_handle, status)) - < 0) { - jack_error("status error: %s", snd_strerror(res)); - } + pcm_handle = driver->playback_handle; + } + res = snd_pcm_status(pcm_handle, status); + if (res < 0) { + jack_error("status error: %s", snd_strerror(res)); + return -1; } + return snd_pcm_status_get_state(status); +} + +static int +alsa_driver_xrun_recovery (alsa_driver_t *driver, float *delayed_usecs) +{ + int status; + int res; - if (snd_pcm_status_get_state(status) == SND_PCM_STATE_SUSPENDED) - { - jack_log("**** alsa_pcm: pcm in suspended state, resuming it" ); + status = alsa_driver_get_status(driver); + if (status == SND_PCM_STATE_SUSPENDED) { if (driver->capture_handle) { if ((res = alsa_driver_prepare(driver->capture_handle, SND_PCM_STREAM_CAPTURE)) < 0) { @@ -1319,7 +1326,7 @@ alsa_driver_xrun_recovery (alsa_driver_t *driver, float *delayed_usecs) } } - if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN + if (status == SND_PCM_STATE_XRUN && driver->process_count > XRUN_REPORT_DELAY) { struct timeval now, diff, tstamp; driver->xrun_count++;