diff -Nru pulseaudio-13.99.1/debian/changelog pulseaudio-13.99.1/debian/changelog --- pulseaudio-13.99.1/debian/changelog 2020-06-05 09:52:22.000000000 +0800 +++ pulseaudio-13.99.1/debian/changelog 2020-07-15 17:52:36.000000000 +0800 @@ -1,3 +1,10 @@ +pulseaudio (1:13.99.1-1ubuntu3.5) focal; urgency=medium + + * d/p/0033-alsa-make-the-unsuspend-more-robust.patch + * (LP: #1887610) + + -- Hui Wang Wed, 15 Jul 2020 17:52:36 +0800 + pulseaudio (1:13.99.1-1ubuntu3.4) focal; urgency=medium * d/p/0032-alsa-mixer-store-the-ucm_device-with-the-order-of-th.patch diff -Nru pulseaudio-13.99.1/debian/patches/0033-alsa-make-the-unsuspend-more-robust.patch pulseaudio-13.99.1/debian/patches/0033-alsa-make-the-unsuspend-more-robust.patch --- pulseaudio-13.99.1/debian/patches/0033-alsa-make-the-unsuspend-more-robust.patch 1970-01-01 08:00:00.000000000 +0800 +++ pulseaudio-13.99.1/debian/patches/0033-alsa-make-the-unsuspend-more-robust.patch 2020-07-15 17:52:16.000000000 +0800 @@ -0,0 +1,124 @@ +From eabfaaf7cf1c1631fba74453382945f72267385a Mon Sep 17 00:00:00 2001 +From: Hui Wang +Date: Thu, 9 Jul 2020 10:48:33 +0800 +Subject: [PATCH] alsa: make the unsuspend more robust + +We met a weird situation on a couple of Lenovo machines and at least +on one Dell machine. First we open the gnome-sound-setting, then +suspend and resume the system, after the system resume back, the audio +devices change to dummy, the audio doesn't work anymore. And pacmd +list-cards shows no available sound card. + +Through debugging I found after resume, the alsa receives POLLERR +events and it will call unsuspend to recover the pcm, but at that +moment, the device nodes in /dev/snd/ is not accessible, so the +snd_pcm_open() fails and the pulseaudio unload the module-alsa-card. + +Here I add retry and pa_msleep if snd_pcm_open fails, I tested it on +all machines which have this problem, pa_msleep(25) is ok for most of +them, there is only one machine which needs to call pa_msleep(25) +twice, so for safety reason, I set the max retry times to 4. + +Signed-off-by: Hui Wang +(cherry picked from commit ede8cbb131f7493f14f5717aefd5b4e0603a05d1) +Signed-off-by: Hui Wang +--- + src/modules/alsa/alsa-sink.c | 29 +++++++++++++++++++++-------- + src/modules/alsa/alsa-source.c | 27 ++++++++++++++++++++------- + 2 files changed, 41 insertions(+), 15 deletions(-) + +diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c +index 042d4dfd9..cadfcab79 100644 +--- a/src/modules/alsa/alsa-sink.c ++++ b/src/modules/alsa/alsa-sink.c +@@ -1152,7 +1152,7 @@ static void update_size(struct userdata *u, pa_sample_spec *ss) { + /* Called from IO context */ + static int unsuspend(struct userdata *u, bool recovering) { + pa_sample_spec ss; +- int err; ++ int err, i; + bool b, d; + snd_pcm_uframes_t period_frames, buffer_frames; + snd_pcm_uframes_t tsched_frames = 0; +@@ -1172,13 +1172,26 @@ static int unsuspend(struct userdata *u, bool recovering) { + pa_snprintf(device_name, len, "%s,AES0=6", u->device_name); + } + +- if ((err = snd_pcm_open(&u->pcm_handle, device_name ? device_name : u->device_name, SND_PCM_STREAM_PLAYBACK, +- SND_PCM_NONBLOCK| +- SND_PCM_NO_AUTO_RESAMPLE| +- SND_PCM_NO_AUTO_CHANNELS| +- SND_PCM_NO_AUTO_FORMAT)) < 0) { +- pa_log("Error opening PCM device %s: %s", u->device_name, pa_alsa_strerror(err)); +- goto fail; ++ /* ++ * On some machines, during the system suspend and resume, the thread_func could receive ++ * POLLERR events before the dev nodes in /dev/snd/ are accessible, and thread_func calls ++ * the unsuspend() to try to recover the PCM, this will make the snd_pcm_open() fail, here ++ * we add msleep and retry to make sure those nodes are accessible. ++ */ ++ for (i = 0; i < 4; i++) { ++ if ((err = snd_pcm_open(&u->pcm_handle, device_name ? device_name : u->device_name, SND_PCM_STREAM_PLAYBACK, ++ SND_PCM_NONBLOCK| ++ SND_PCM_NO_AUTO_RESAMPLE| ++ SND_PCM_NO_AUTO_CHANNELS| ++ SND_PCM_NO_AUTO_FORMAT)) < 0 && recovering) ++ pa_msleep(25); ++ else ++ break; ++ } ++ ++ if (err < 0) { ++ pa_log("Error opening PCM device %s: %s", u->device_name, pa_alsa_strerror(err)); ++ goto fail; + } + + if (pa_frame_size(&u->sink->sample_spec) != u->frame_size) { +diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c +index 104de4e26..2c74ffcbc 100644 +--- a/src/modules/alsa/alsa-source.c ++++ b/src/modules/alsa/alsa-source.c +@@ -1033,7 +1033,7 @@ static void update_size(struct userdata *u, pa_sample_spec *ss) { + /* Called from IO context */ + static int unsuspend(struct userdata *u, bool recovering) { + pa_sample_spec ss; +- int err; ++ int err, i; + bool b, d; + snd_pcm_uframes_t period_frames, buffer_frames; + snd_pcm_uframes_t tsched_frames = 0; +@@ -1044,12 +1044,25 @@ static int unsuspend(struct userdata *u, bool recovering) { + + pa_log_info("Trying resume..."); + +- if ((err = snd_pcm_open(&u->pcm_handle, u->device_name, SND_PCM_STREAM_CAPTURE, +- SND_PCM_NONBLOCK| +- SND_PCM_NO_AUTO_RESAMPLE| +- SND_PCM_NO_AUTO_CHANNELS| +- SND_PCM_NO_AUTO_FORMAT)) < 0) { +- pa_log("Error opening PCM device %s: %s", u->device_name, pa_alsa_strerror(err)); ++ /* ++ * On some machines, during the system suspend and resume, the thread_func could receive ++ * POLLERR events before the dev nodes in /dev/snd/ are accessible, and thread_func calls ++ * the unsuspend() to try to recover the PCM, this will make the snd_pcm_open() fail, here ++ * we add msleep and retry to make sure those nodes are accessible. ++ */ ++ for (i = 0; i < 4; i++) { ++ if ((err = snd_pcm_open(&u->pcm_handle, u->device_name, SND_PCM_STREAM_CAPTURE, ++ SND_PCM_NONBLOCK| ++ SND_PCM_NO_AUTO_RESAMPLE| ++ SND_PCM_NO_AUTO_CHANNELS| ++ SND_PCM_NO_AUTO_FORMAT)) < 0 && recovering) ++ pa_msleep(25); ++ else ++ break; ++ } ++ ++ if (err < 0) { ++ pa_log("Error opening PCM device %s: %s", u->device_name, pa_alsa_strerror(err)); + goto fail; + } + +-- +2.17.1 + diff -Nru pulseaudio-13.99.1/debian/patches/series pulseaudio-13.99.1/debian/patches/series --- pulseaudio-13.99.1/debian/patches/series 2020-06-05 09:52:22.000000000 +0800 +++ pulseaudio-13.99.1/debian/patches/series 2020-07-15 17:52:32.000000000 +0800 @@ -1,6 +1,7 @@ git_cherrypick_fixes.patch disable-autospawn.patch 0032-alsa-mixer-store-the-ucm_device-with-the-order-of-th.patch +0033-alsa-make-the-unsuspend-more-robust.patch # Ubuntu specific config/fixes 0001-volume-config-changes.patch