[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] alsa: Skip resume PCM if hardware doesn't support it

Arun Raghavan gitlab at gitlab.freedesktop.org
Thu Dec 12 02:56:52 UTC 2019



Arun Raghavan pushed to branch master at PulseAudio / pulseaudio


Commits:
734a00c8 by Kai-Heng Feng at 2019-12-10T08:16:18Z
alsa: Skip resume PCM if hardware doesn't support it

Hardwares without SNDRV_PCM_INFO_RESUME capability, like USB Audio,
don't support snd_pcm_resume() when it's in suspended state.

Let's use snd_pcm_hw_params_can_resume() to check hardware's capability
before snd_pcm_resume() attempt. If it doesn't support resume, just go
to snd_pcm_drop() to leave suspended state directly.

- - - - -


1 changed file:

- src/modules/alsa/alsa-util.c


Changes:

=====================================
src/modules/alsa/alsa-util.c
=====================================
@@ -1066,6 +1066,7 @@ void pa_alsa_init_proplist_ctl(pa_proplist *p, const char *name) {
 
 int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents) {
     snd_pcm_state_t state;
+    snd_pcm_hw_params_t *hwparams;
     int err;
 
     pa_assert(pcm);
@@ -1103,16 +1104,25 @@ int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents) {
             break;
 
         case SND_PCM_STATE_SUSPENDED:
-            /* Retry resume 3 times before giving up, then fallback to restarting the stream. */
-            for (int i = 0; i < 3; i++) {
-                if ((err = snd_pcm_resume(pcm)) == 0)
-                    return 0;
-                if (err != -EAGAIN)
-                    break;
-                pa_msleep(25);
+            snd_pcm_hw_params_alloca(&hwparams);
+
+            if ((err = snd_pcm_hw_params_any(pcm, hwparams)) < 0) {
+		pa_log_debug("snd_pcm_hw_params_any() failed: %s", pa_alsa_strerror(err));
+		return -1;
             }
-            pa_log_warn("Could not recover alsa device from SUSPENDED state, trying to restart PCM");
-            /* Fall through */
+
+            if (snd_pcm_hw_params_can_resume(hwparams)) {
+                /* Retry resume 3 times before giving up, then fallback to restarting the stream. */
+                for (int i = 0; i < 3; i++) {
+                    if ((err = snd_pcm_resume(pcm)) == 0)
+                        return 0;
+                    if (err != -EAGAIN)
+                        break;
+                    pa_msleep(25);
+                }
+                pa_log_warn("Could not recover alsa device from SUSPENDED state, trying to restart PCM");
+	    }
+	    /* Fall through */
 
         default:
 



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/commit/734a00c849815a45697970d593068c301a04ebbb

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/commit/734a00c849815a45697970d593068c301a04ebbb
You're receiving this email because of your account on gitlab.freedesktop.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20191212/07755019/attachment-0001.htm>


More information about the pulseaudio-commits mailing list