Blob Blame History Raw
From 737b64e1940b29c575be3942cd9f87aa390d93b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A9=8D=E4=B8=B9=E5=B0=BC=20Dan=20Jacobson?=
 <jidanni@jidanni.org>
Date: Sun, 18 Oct 2020 18:33:54 +0800
Subject: [PATCH 02/14] alsamixer: Fix the mixer views description in man page

Fix grammar mess.

From: Dan Jacobson <jidanni@jidanni.org>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 alsamixer/alsamixer.1 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/alsamixer/alsamixer.1 b/alsamixer/alsamixer.1
index 8d34680..2d711cf 100644
--- a/alsamixer/alsamixer.1
+++ b/alsamixer/alsamixer.1
@@ -34,7 +34,7 @@ Toggle the using of colors.
 
 .SH MIXER VIEWS
 
-The top-left corner of \fBalsamixer\fP is the are to show some basic
+The top-left corner of \fBalsamixer\fP shows some basic
 information: the card name, the mixer chip name, the current view
 mode and the currently selected mixer item.
 When the mixer item is switched off, \fI[Off]\fP is displayed in its
-- 
2.29.2

From 986a1bd3d2eebd41a2925969826fca870b2cd330 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Fri, 23 Oct 2020 12:05:56 +0200
Subject: [PATCH 06/14] aplay: cosmetic code fix in xrun()

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 aplay/aplay.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/aplay/aplay.c b/aplay/aplay.c
index a27220d..ae60988 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -1676,7 +1676,8 @@ static void xrun(void)
 			prg_exit(EXIT_FAILURE);
 		}
 		return;		/* ok, data should be accepted again */
-	} if (snd_pcm_status_get_state(status) == SND_PCM_STATE_DRAINING) {
+	}
+	if (snd_pcm_status_get_state(status) == SND_PCM_STATE_DRAINING) {
 		if (verbose) {
 			fprintf(stderr, _("Status(DRAINING):\n"));
 			snd_pcm_status_dump(status, log);
-- 
2.29.2


From c1b92db5ef01311e5fc983f3134caa00826d0c2d Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Sun, 8 Nov 2020 19:11:12 +0100
Subject: [PATCH 07/14] aplay: fix the CPU busy loop in the pause handler

Use the standard poll mechanism to ensure that there's
something in the input to avoid busy loop on the file
descriptor with the non-block mode set.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 aplay/aplay.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/aplay/aplay.c b/aplay/aplay.c
index ae60988..d385da2 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -1553,6 +1553,19 @@ static void done_stdin(void)
 	tcsetattr(fileno(stdin), TCSANOW, &term);
 }
 
+static char wait_for_input(void)
+{
+	struct pollfd pfd;
+	unsigned char b;
+
+	do {
+		pfd.fd = fileno(stdin);
+		pfd.events = POLLIN;
+		poll(&pfd, 1, -1);
+	} while (read(fileno(stdin), &b, 1) != 1);
+	return b;
+}
+
 static void do_pause(void)
 {
 	int err;
@@ -1571,7 +1584,7 @@ static void do_pause(void)
 		return;
 	}
 	while (1) {
-		while (read(fileno(stdin), &b, 1) != 1);
+		b = wait_for_input();
 		if (b == ' ' || b == '\r') {
 			while (read(fileno(stdin), &b, 1) == 1);
 			if (snd_pcm_state(handle) == SND_PCM_STATE_SUSPENDED)
@@ -1596,7 +1609,7 @@ static void check_stdin(void)
 				while (read(fileno(stdin), &b, 1) == 1);
 				fprintf(stderr, _("\r=== PAUSE ===                                                            "));
 				fflush(stderr);
-			do_pause();
+				do_pause();
 				fprintf(stderr, "                                                                          \r");
 				fflush(stderr);
 			}
-- 
2.29.2


From 5812f37d877c12bc594b9ffddc493d305991963a Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Wed, 9 Dec 2020 18:35:49 +0100
Subject: [PATCH 08/14] alsa-info: Add lsusb and stream outputs

We need more detailed information for USB-audio devices, at least the
lsusb -v output and the contents of stream* proc files.
Let's add them to alsa-info.sh output.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 alsa-info/alsa-info.sh | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/alsa-info/alsa-info.sh b/alsa-info/alsa-info.sh
index f179bfa..3871b97 100755
--- a/alsa-info/alsa-info.sh
+++ b/alsa-info/alsa-info.sh
@@ -476,6 +476,18 @@ cat /proc/asound/card*/codec\#* > $TEMPDIR/alsa-hda-intel.tmp 2> /dev/null
 cat /proc/asound/card*/codec97\#0/ac97\#0-0 > $TEMPDIR/alsa-ac97.tmp 2> /dev/null
 cat /proc/asound/card*/codec97\#0/ac97\#0-0+regs > $TEMPDIR/alsa-ac97-regs.tmp 2> /dev/null
 
+#Check for USB descriptors
+if [ -x /usr/bin/lsusb ]; then
+    for f in /proc/asound/card[0-9]*/usbbus; do
+	test -f "$f" || continue
+	id=$(sed 's@/@:@' $f)
+	lsusb -v -s $id >> $TEMPDIR/lsusb.tmp 2> /dev/null
+    done
+fi
+
+#Check for USB stream setup
+cat /proc/asound/card*/stream[0-9]* > $TEMPDIR/alsa-usbstream.tmp 2> /dev/null
+
 #Check for USB mixer setup
 cat /proc/asound/card*/usbmixer > $TEMPDIR/alsa-usbmixer.tmp 2> /dev/null
 
@@ -649,6 +661,27 @@ if [ -s "$TEMPDIR/alsa-ac97.tmp" ]; then
 	echo "" >> $FILE
 fi
 
+if [ -s "$TEMPDIR/lsusb.tmp" ]; then
+        echo "!!USB Descriptors" >> $FILE
+        echo "!!---------------" >> $FILE
+        echo "--startcollapse--" >> $FILE
+        cat $TEMPDIR/lsusb.tmp >> $FILE
+        echo "--endcollapse--" >> $FILE
+	echo "" >> $FILE
+	echo "" >> $FILE
+fi
+
+if [ -s "$TEMPDIR/lsusb.tmp" ]; then
+        echo "!!USB Stream information" >> $FILE
+        echo "!!----------------------" >> $FILE
+        echo "--startcollapse--" >> $FILE
+        echo "" >> $FILE
+        cat $TEMPDIR/alsa-usbstream.tmp >> $FILE
+        echo "--endcollapse--" >> $FILE
+	echo "" >> $FILE
+	echo "" >> $FILE
+fi
+
 if [ -s "$TEMPDIR/alsa-usbmixer.tmp" ]; then
         echo "!!USB Mixer information" >> $FILE
         echo "!!---------------------" >> $FILE
-- 
2.29.2


From 878e1a7c0f03233530e7675ae015aced069c971d Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Fri, 11 Dec 2020 23:41:59 +0100
Subject: [PATCH 10/14] alsactl: Fix double decrease of lock timeout

The state_lock() has a loop to wait for the lock file creation, and
the timeout value gets decremented twice mistakenly, which leads to a
half timeout (5 seconds) than expected 10 seconds.  Fix it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 alsactl/lock.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/alsactl/lock.c b/alsactl/lock.c
index 4a48539..05f6e4d 100644
--- a/alsactl/lock.c
+++ b/alsactl/lock.c
@@ -63,7 +63,6 @@ static int state_lock_(const char *file, int lock, int timeout, int _fd)
 			if (fd < 0) {
 				if (errno == EBUSY || errno == EAGAIN) {
 					sleep(1);
-					timeout--;
 				} else {
 					err = -errno;
 					goto out;
-- 
2.29.2


From c53f7cd03881092d5a61505d23ab8f920b7faf12 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Fri, 11 Dec 2020 23:46:23 +0100
Subject: [PATCH 11/14] alsactl: Fix race at creating a lock file

A race at creating a lock file in state_lock() was discovered
recently: namely, between the first open(O_RDWR) and the second
open(O_RDWR|O_CREAT|O_EXCL) calls, another alsactl invocation may
already create a lock file, then the second open() will return EEXIST,
which isn't handled properly and treated as a fatal error.

In this patch, we check EEXIST case and try again open() with O_RDWR.
This must succeed usually, and if it fails, handle finally as the
fatal error.

BugLink: https://bugzilla.opensuse.org/show_bug.cgi?id=1179904
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 alsactl/lock.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/alsactl/lock.c b/alsactl/lock.c
index 05f6e4d..5b47462 100644
--- a/alsactl/lock.c
+++ b/alsactl/lock.c
@@ -63,10 +63,15 @@ static int state_lock_(const char *file, int lock, int timeout, int _fd)
 			if (fd < 0) {
 				if (errno == EBUSY || errno == EAGAIN) {
 					sleep(1);
-				} else {
-					err = -errno;
-					goto out;
+					continue;
 				}
+				if (errno == EEXIST) {
+					fd = open(nfile, O_RDWR);
+					if (fd >= 0)
+						break;
+				}
+				err = -errno;
+				goto out;
 			}
 		}
 	}
-- 
2.29.2


From 12487b40b6e7230a003eb6e4333ee820d8578592 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Fri, 11 Dec 2020 23:55:34 +0100
Subject: [PATCH 12/14] alsactl: Remove asound.state file check from
 alsa-restore.service again

We added the check of asound.state file presence some time ago to
assure that alsactl gets called only if the state file is already
present.  Since then, the situation has changed significantly:
e.g. now alsactl does initialize if the state file isn't present, and
the same alsa-restore.service is used to save the state.  This means
that we should start this service no matter the state file exists at
the boot time or not.  So, revert the old change again.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 alsactl/alsa-restore.service.in | 1 -
 1 file changed, 1 deletion(-)

diff --git a/alsactl/alsa-restore.service.in b/alsactl/alsa-restore.service.in
index a84c2e8..80fd5fd 100644
--- a/alsactl/alsa-restore.service.in
+++ b/alsactl/alsa-restore.service.in
@@ -7,7 +7,6 @@
 Description=Save/Restore Sound Card State
 ConditionPathExists=!@daemonswitch@
 ConditionPathExistsGlob=/dev/snd/control*
-ConditionPathExists=@asoundrcfile@
 
 [Service]
 Type=oneshot
-- 
2.29.2


From 76bc37aeb77d51f995e223582d25335cd98b2eea Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Sun, 3 Jan 2021 17:19:03 +0100
Subject: [PATCH 13/14] aplay: add test code for snd_pcm_status() to
 --test-position

We need to test also snd_pcm_status() values.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 aplay/aplay.c | 48 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 38 insertions(+), 10 deletions(-)

diff --git a/aplay/aplay.c b/aplay/aplay.c
index d385da2..5a6d5c3 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -1953,22 +1953,38 @@ static void do_test_position(void)
 	static snd_pcm_sframes_t minavail, mindelay;
 	static snd_pcm_sframes_t badavail = 0, baddelay = 0;
 	snd_pcm_sframes_t outofrange;
-	snd_pcm_sframes_t avail, delay;
+	snd_pcm_sframes_t avail, delay, savail, sdelay;
+	snd_pcm_status_t *status;
 	int err;
 
+	snd_pcm_status_alloca(&status);
 	err = snd_pcm_avail_delay(handle, &avail, &delay);
 	if (err < 0)
 		return;
+	err = snd_pcm_status(handle, status);
+	if (err < 0)
+		return;
+	savail = snd_pcm_status_get_avail(status);
+	sdelay = snd_pcm_status_get_delay(status);
 	outofrange = (test_coef * (snd_pcm_sframes_t)buffer_frames) / 2;
 	if (avail > outofrange || avail < -outofrange ||
 	    delay > outofrange || delay < -outofrange) {
-	  badavail = avail; baddelay = delay;
-	  availsum = delaysum = samples = 0;
-	  maxavail = maxdelay = 0;
-	  minavail = mindelay = buffer_frames * 16;
-	  fprintf(stderr, _("Suspicious buffer position (%li total): "
-	  	"avail = %li, delay = %li, buffer = %li\n"),
-	  	++counter, (long)avail, (long)delay, (long)buffer_frames);
+		badavail = avail; baddelay = delay;
+		availsum = delaysum = samples = 0;
+		maxavail = maxdelay = 0;
+		minavail = mindelay = buffer_frames * 16;
+		fprintf(stderr, _("Suspicious buffer position (%li total): "
+			"avail = %li, delay = %li, buffer = %li\n"),
+			++counter, (long)avail, (long)delay, (long)buffer_frames);
+	} else if (savail > outofrange || savail < -outofrange ||
+		   sdelay > outofrange || sdelay < -outofrange) {
+		badavail = savail; baddelay = sdelay;
+		availsum = delaysum = samples = 0;
+		maxavail = maxdelay = 0;
+		minavail = mindelay = buffer_frames * 16;
+		fprintf(stderr, _("Suspicious status buffer position (%li total): "
+			"avail = %li, delay = %li, buffer = %li\n"),
+			++counter, (long)savail, (long)sdelay, (long)buffer_frames);
 	} else if (verbose) {
 		time(&now);
 		if (tmr == (time_t) -1) {
@@ -1979,19 +1995,27 @@ static void do_test_position(void)
 		}
 		if (avail > maxavail)
 			maxavail = avail;
+		if (savail > maxavail)
+			maxavail = savail;
 		if (delay > maxdelay)
 			maxdelay = delay;
+		if (sdelay > maxdelay)
+			maxdelay = sdelay;
 		if (avail < minavail)
 			minavail = avail;
+		if (savail < minavail)
+			minavail = savail;
 		if (delay < mindelay)
 			mindelay = delay;
+		if (sdelay < mindelay)
+			mindelay = sdelay;
 		availsum += avail;
 		delaysum += delay;
 		samples++;
-		if (avail != 0 && now != tmr) {
+		if ((maxavail != 0 || maxdelay != 0) && now != tmr) {
 			fprintf(stderr, "BUFPOS: avg%li/%li "
 				"min%li/%li max%li/%li (%li) (%li:%li/%li)\n",
-				(long)(availsum / samples),
+                         (long)(availsum / samples),
 				(long)(delaysum / samples),
 				(long)minavail, (long)mindelay,
 				(long)maxavail, (long)maxdelay,
@@ -2000,6 +2024,10 @@ static void do_test_position(void)
 			tmr = now;
 		}
 	}
+	if (verbose == 1) {
+		fprintf(stderr, _("Status(R/W) (standalone avail=%li delay=%li):\n"), (long)avail, (long)delay);
+		snd_pcm_status_dump(status, log);
+	}
 }
 
 /*
-- 
2.29.2


From 3980fe71c9795271639239ad8fa982a59de8ff1f Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Mon, 4 Jan 2021 12:13:03 +0100
Subject: [PATCH 14/14] aplay: add avail > delay checks to --test-position

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 aplay/aplay.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/aplay/aplay.c b/aplay/aplay.c
index 5a6d5c3..b75be6c 100644
--- a/aplay/aplay.c
+++ b/aplay/aplay.c
@@ -1985,6 +1985,14 @@ static void do_test_position(void)
 		fprintf(stderr, _("Suspicious status buffer position (%li total): "
 			"avail = %li, delay = %li, buffer = %li\n"),
 			++counter, (long)savail, (long)sdelay, (long)buffer_frames);
+	} else if (avail > delay) {
+		fprintf(stderr, _("Suspicious buffer position avail > delay (%li total): "
+			"avail = %li, delay = %li\n"),
+			++counter, (long)avail, (long)delay);
+	} else if (savail > sdelay) {
+		fprintf(stderr, _("Suspicious status buffer position avail > delay (%li total): "
+			"avail = %li, delay = %li\n"),
+			++counter, (long)savail, (long)sdelay);
 	} else if (verbose) {
 		time(&now);
 		if (tmr == (time_t) -1) {
-- 
2.29.2