Skip to contentSkip to conversation

ALSA: pcm: update state after xrun

PATCH In review Mikael Magnusson 2 participants 2 messages Nov 12 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ALSA: pcm: update state after xrun

If the snd_pcm_update_hw_ptr call from snd_pcm_status is what triggers the xrun state (eg, as opposed to an IRQ), the returned status->state was stale and told userspace the device was still playing, so they could get confused about device state and hang indefinitely.

---

Changes from v1:
incorporate feedback from Sashiko and Takashi:
also set the trigger_tstamp since it can change in this scenario. check return value to determine if we need to update the status fields.

PS Sorry it took a while to send the respin, I don't have a dedicated testing machine, and I didn't have an opportunity to reboot to test it until now.

 sound/core/pcm_native.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
sound/core/pcm_native.c +7 -1
index 1f5ebfd288..5d80b56449 100644
@@ -1127,7 +1127,13 @@ int snd_pcm_status64(struct snd_pcm_substream *substream,
 	status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec;
 	status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec;
 	if (snd_pcm_running(substream)) {
-		snd_pcm_update_hw_ptr(substream);
+		if (snd_pcm_update_hw_ptr(substream) < 0) {
+			/* update_hw_ptr may have put us in xrun state, update state */
+			status->state = runtime->state;
+			status->suspended_state = runtime->suspended_state;
+			status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec;
+			status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec;
+		}
 		if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
 			status->tstamp_sec = runtime->status->tstamp.tv_sec;
 			status->tstamp_nsec =
Signature · 1 line
2.38.1