[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: FC3 T2 alsactl store issues unresolved



Le sam 25/09/2004 Ã 01:37, maxer1 a Ãcrit :
> Latest dev after FC3T2 upgrade.
> 
> [...]
> Any ideas why alsactl store doesn't appear to be working at all?
> 

"store" works :-) It's "restore" that doesn't work.

> Is this a problem in initscripts?
> 

Sorry for my _very_ poor English.
I spent one day with this.

Initscripts, is not the only problem. The issue is with
udev/alsactl/alsa-lib. As with many devices, alsactl talk to the
hardware only with a special file (which provide major and minor
number).

The modprobe.conf :
        install snd-ens1371 /sbin/modprobe --ignore-install snd-ens1371 && /usr/sbin/alsactl restore >/dev/null 2>&1 || :

"alsactl restore" is done _before_ udev create special files in
/dev/snd/. udev is executed _after_ modprobe.

At boot time, 'alsactl restore' "silently print" :
alsactl: load_state:1134: No soundcards found...

alsactl is trying to open the device but failed :
        open("/dev/snd/controlC0", O_RDONLY)    = -1 ENOENT (No such file or directory)
        open("/dev/aloadC0", O_RDONLY)          = -1 ENOENT (No such file or directory)

So, the setting is not restored.

I find two ways to solve this issue :
	- adapt initscript and modprobe.conf
	- patch alsa-lib to use /sys

The first is simple, works, but not perfect.
The second is "new" because we use a device without special file already
in place. Seams there is something broken here :-)

The first solution (not tested and i am very weak in shell programming) :
        --- rc.sysinit.orig     2004-09-25 20:20:09.060208486 +0200
        +++ rc.sysinit  2004-09-25 20:24:48.494075002 +0200
        @@ -204,6 +204,9 @@
         for module in `/sbin/modprobe -c | awk '/^alias[[:space:]]+snd-card-[[:digit:]]+[[:space:]]/ { print $3 }'` $audio; do
                modprobe $module >/dev/null 2>&1
         done
        +if [ "$module" = "" ] ; then
        +       /usr/sbin/alsactl restore >/dev/null 2>&1
        +fi
        
         echo -n $" audio"
        
At that point in rc.sysinit, /usr is not mounted ! and libasound is in
/usr/lib (and some other piece of alsa stay in /usr/share/alsa). Perhaps
the soundcards initialisation should be moved after the mount all other
partitions.
Note that the modules are "modprobed" two times ! With "/sbin/modprobe
-c ..." and with $audio provided by kmodule.

For modprobe.conf we can remove this useless line :
        install snd-XXXX /sbin/modprobe --ignore-install snd-XXXX && /usr/sbin/alsactl restore >/dev/null 2>&1 || :


That's all for the first solution.




The second solution i try to make is a little more harder.
If alsa-lib don't find the special file, alsa-lib create it "on the
fly". Only root can do that.

Only /dev is writable at hardware initialisation (if we don't touch
rc.sysinit).

This "quick and dirty" patch use /sys to find out the major and minor
number. This information is in /sys/class/sound/controlCN/dev .

See attachment. Be very careful, I am not an alsa hacker :-) Works here
only (two sound cards).



And now a word about how s-c-soundcard handle multi-cards.
Why it touch/create /etc/asound.conf ?
asound.conf is for alsa-lib, the end-user! He can add plugins, etc...
There are nothing to do with the hardware detection and it is not the
best way to identify a sound card. We should use modprobe.conf or udev
(like scsi_id does, or like i do with my ide drives :-)). With udev,
it's harder but possible.



Please, don't touch /etc/asound.conf. 
The only benefit of asound.conf using by s-c-soundcard is to not
unload/reload the modules (or reboot).
And think fc2 users already use a custom asound.conf.
btw, fc3 provide OSS emulation (for realplay, etc...) and OSS software
... don't use alsa-lib (asound.conf).

There is a ticket in bugzilla :
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=133535

But how Fedora handle the sound is broken in many places and this can be
summarize by "Sound settings not saved on shutdown".
diff -urN alsa-lib-1.0.6.orig/src/control/cards.c alsa-lib-1.0.6/src/control/cards.c
--- alsa-lib-1.0.6.orig/src/control/cards.c	2003-02-19 10:37:01.000000000 +0100
+++ alsa-lib-1.0.6/src/control/cards.c	2004-09-25 15:48:39.544074018 +0200
@@ -33,6 +33,7 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include "control_local.h"
+#include "open_tmp_sndnod_local.h"
 
 #ifndef DOC_HIDDEN
 #define SND_FILE_CONTROL	"/dev/snd/controlC%i"
@@ -54,7 +55,8 @@
 	if ((open_dev=open(control, O_RDONLY)) < 0) {
 		char aload[32];
 		sprintf(aload, SND_FILE_LOAD, card);
-		open_dev = open(aload, O_RDONLY);
+		if (open_dev = open(aload, O_RDONLY) <0)
+			open_dev = open_tmp_sndnod(card, O_RDONLY, O_RDONLY);
 	}
 	if (open_dev >= 0) {
 		close (open_dev);
diff -urN alsa-lib-1.0.6.orig/src/control/control_hw.c alsa-lib-1.0.6/src/control/control_hw.c
--- alsa-lib-1.0.6.orig/src/control/control_hw.c	2003-10-21 19:39:15.000000000 +0200
+++ alsa-lib-1.0.6/src/control/control_hw.c	2004-09-25 15:51:42.733415290 +0200
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include "control_local.h"
+#include "open_tmp_sndnod_local.h"
 
 #ifndef PIC
 /* entry for static linking */
@@ -339,7 +340,8 @@
 		fmode |= O_ASYNC;
 	if ((fd = open(filename, fmode)) < 0) {
 		snd_card_load(card);
-		if ((fd = open(filename, O_RDWR)) < 0)
+		if ((fd = open(filename, O_RDWR)) < 0 &&
+			(fd = open_tmp_sndnod(card, fmode, O_RDWR)) < 0)
 			return -errno;
 	}
 #if 0
diff -urN alsa-lib-1.0.6.orig/src/control/Makefile.am alsa-lib-1.0.6/src/control/Makefile.am
--- alsa-lib-1.0.6.orig/src/control/Makefile.am	2001-10-24 16:14:12.000000000 +0200
+++ alsa-lib-1.0.6/src/control/Makefile.am	2004-09-25 15:17:50.000000000 +0200
@@ -2,9 +2,9 @@
 
 libcontrol_la_SOURCES = cards.c hcontrol.c \
                         control.c control_hw.c control_shm.c \
-			setup.c control_symbols.c
+			setup.c control_symbols.c open_tmp_sndnod_local.c
 
-noinst_HEADERS = control_local.h
+noinst_HEADERS = control_local.h open_tmp_sndnod_local.h
 
 all: libcontrol.la
 
diff -urN alsa-lib-1.0.6.orig/src/control/Makefile.in alsa-lib-1.0.6/src/control/Makefile.in
--- alsa-lib-1.0.6.orig/src/control/Makefile.in	2004-08-15 10:43:54.000000000 +0200
+++ alsa-lib-1.0.6/src/control/Makefile.in	2004-09-25 16:14:45.693046818 +0200
@@ -151,10 +151,10 @@
 
 libcontrol_la_SOURCES = cards.c hcontrol.c \
                         control.c control_hw.c control_shm.c \
-			setup.c control_symbols.c
+			setup.c control_symbols.c open_tmp_sndnod_local.c
 
 
-noinst_HEADERS = control_local.h
+noinst_HEADERS = control_local.h open_tmp_sndnod_local.h
 
 INCLUDES = -I$(top_srcdir)/include
 subdir = src/control
@@ -165,7 +165,7 @@
 libcontrol_la_LDFLAGS =
 libcontrol_la_LIBADD =
 am_libcontrol_la_OBJECTS = cards.lo hcontrol.lo control.lo control_hw.lo \
-	control_shm.lo setup.lo control_symbols.lo
+	control_shm.lo setup.lo control_symbols.lo open_tmp_sndnod_local.lo
 libcontrol_la_OBJECTS = $(am_libcontrol_la_OBJECTS)
 
 DEFAULT_INCLUDES =  -I. -I$(srcdir) -I$(top_builddir)/include
@@ -175,6 +175,7 @@
 @AMDEP_TRUE@	./$(DEPDIR)/control_hw.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/control_shm.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/control_symbols.Plo \
+ AMDEP_TRUE@	./$(DEPDIR)/open_tmp_sndnod_local.Plo \
 @AMDEP_TRUE@	./$(DEPDIR)/hcontrol.Plo ./$(DEPDIR)/setup.Plo
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
 	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -212,6 +213,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/control_hw Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/control_shm Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/control_symbols Plo am__quote@
+ AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/open_tmp_sndnod_local Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/hcontrol Plo am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote  /$(DEPDIR)/setup Plo am__quote@
 
diff -urN alsa-lib-1.0.6.orig/src/control/open_tmp_sndnod_local.c alsa-lib-1.0.6/src/control/open_tmp_sndnod_local.c
--- alsa-lib-1.0.6.orig/src/control/open_tmp_sndnod_local.c	1970-01-01 01:00:00.000000000 +0100
+++ alsa-lib-1.0.6/src/control/open_tmp_sndnod_local.c	2004-09-25 17:31:41.993940042 +0200
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "open_tmp_sndnod_local.h"
+
+#define SNDRV_SYSFS_DEV_CONTROL "/sys/class/sound/controlC%i/dev"
+#define SNDRV_SYSFS_DEV_CONTROL_SIZE     32
+#define REP_TMP	"/dev"
+
+int open_tmp_sndnod(int card, int mode1, int mode2) {
+	char sysfs_dev[SNDRV_SYSFS_DEV_CONTROL_SIZE];
+	char buffer[32];
+	int fd;
+	unsigned int major, minor;
+	ssize_t len;
+	char * tmp_node = NULL;
+	sprintf(sysfs_dev, SNDRV_SYSFS_DEV_CONTROL, card);
+	if ( (fd = open(sysfs_dev, O_RDONLY)) < 0 ) {
+		goto error;
+	}
+	len = read(fd, buffer, sizeof(buffer) - 1);
+	close(fd);
+	fd = -1;
+	buffer[len+1] = '\0';
+	if (sscanf(buffer, "%u:%u", &major, &minor) != 2) {
+		goto error;
+	}
+	if ((tmp_node = tempnam(REP_TMP, ".")) == NULL) {
+		goto error;
+	}
+	if (mknod(tmp_node, S_IFCHR | S_IRUSR | S_IWUSR, makedev(major, minor)) != 0) {
+		goto error;
+	}
+	if ((fd = open(tmp_node, mode1)) < 0 && mode1 != mode2 ) {
+		fd = open(tmp_node, mode2);
+	}
+	unlink(tmp_node);
+error:
+	if (tmp_node != NULL) {
+		free(tmp_node);
+	}
+	return fd;
+}
diff -urN alsa-lib-1.0.6.orig/src/control/open_tmp_sndnod_local.h alsa-lib-1.0.6/src/control/open_tmp_sndnod_local.h
--- alsa-lib-1.0.6.orig/src/control/open_tmp_sndnod_local.h	1970-01-01 01:00:00.000000000 +0100
+++ alsa-lib-1.0.6/src/control/open_tmp_sndnod_local.h	2004-09-25 16:03:55.550230826 +0200
@@ -0,0 +1 @@
+extern int open_tmp_sndnod(int card, int mode1, int mode2) ;

Attachment: signature.asc
Description: Ceci est une partie de message =?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e=2E?=


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]