From b5ede1c04a040d2598a89d09a8559139999583ea Mon Sep 17 00:00:00 2001 From: Adam Miartus Date: Tue, 25 Feb 2020 19:04:06 +0100 Subject: [PATCH] QTISA-183 alsa: allow recovery for read and write both read and write can fail, therefore allow recovery Change-Id: I32462c68aaa2395da11d2969a73ab5b5f28af879 Signed-off-by: Adam Miartus (cherry picked from commit 1996a103ac2b14062d81ef222cf902c1c45b8812) Signed-off-by: Timo Wischer --- linux/alsa/JackAlsaDriver.cpp | 39 ++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/linux/alsa/JackAlsaDriver.cpp b/linux/alsa/JackAlsaDriver.cpp index c63fb9f6..e848e2ac 100644 --- a/linux/alsa/JackAlsaDriver.cpp +++ b/linux/alsa/JackAlsaDriver.cpp @@ -484,16 +484,9 @@ int JackAlsaDriver::Read() do { nframes = alsa_driver_wait((alsa_driver_t *)fDriver, -1, &wait_status, &fDelayedUsecs); - if (wait_status == ALSA_DRIVER_WAIT_ERROR) - return -1; /* driver failed */ - - if (wait_status == ALSA_DRIVER_WAIT_XRUN) { - /* we detected an xrun and restarted: notify - * clients about the delay. - */ - jack_log("ALSA XRun wait_status = %d", wait_status); - NotifyXRun(fBeginDateUst, fDelayedUsecs); - continue; + if (wait_status != ALSA_DRIVER_WAIT_OK) { + jack_error("JackAlsaDriver::Read wait failed, xrun recovery"); + goto retry; } } while (nframes == 0); @@ -503,12 +496,34 @@ int JackAlsaDriver::Read() // Has to be done before read JackDriver::CycleIncTime(); - return alsa_driver_read((alsa_driver_t *)fDriver, fEngineControl->fBufferSize); + if (alsa_driver_read((alsa_driver_t *)fDriver, fEngineControl->fBufferSize) != 0) { + jack_error("JackAlsaDriver::Read read failed, xrun recovery"); + goto retry; + } + + return 0; + +retry: + /* we detected an xrun and restarted: notify + * clients about the delay. + */ + jack_error("JackAlsaDriver::Read failed, xrun recovery"); + alsa_driver_xrun_recovery((alsa_driver_t *)fDriver, &fDelayedUsecs); + NotifyXRun(fBeginDateUst, fDelayedUsecs); + + return -1; } int JackAlsaDriver::Write() { - return alsa_driver_write((alsa_driver_t *)fDriver, fEngineControl->fBufferSize); + if (alsa_driver_write((alsa_driver_t *)fDriver, fEngineControl->fBufferSize) != 0) { + jack_error("JackAlsaDriver::Write failed, xrun recovery"); + alsa_driver_xrun_recovery((alsa_driver_t *)fDriver, &fDelayedUsecs); + NotifyXRun(fBeginDateUst, fDelayedUsecs); + return -1; + } + + return 0; } void JackAlsaDriver::ReadInputAux(alsa_device_t *device, jack_nframes_t orig_nframes, snd_pcm_sframes_t contiguous, snd_pcm_sframes_t nread)