Re: get uaudio pcm/mixer device name using devd

From: Mazin Fadl <mazen_at_illumed.net>
Date: Tue, 03 May 2022 23:50:41 UTC
I've solved my problem by referencing the kernel log in the action
script to find the pcm/mixer device.

The updated configuration in case it is useful to someone else:

attach 100 {
        # find vendor and product ids to match against
        # from devinfo(8) or usbconfig(8)
        match   "vendor"        "0x040d";
        match   "product"       "0x340b";

        action "/etc/set_usb_audio.sh $device-name";
        # for our device gives "uaudioN"
};

in set_usb_audio.sh:

pcm=$(grep -F "$1" /var/log/messages | grep -o 'pcm[[:digit:]]\+' | tail -n1)

if [ -n "$pcm" ]; then
	logger set_usb_audio.sh: found usb audio playback on "$pcm"
	# set default audio card
	mixer -d "${pcm#pcm}" >/dev/null 2>&1
fi

Possible path not taken is to use devinfo(8) output, instead of the
message log, to find the pcm device but this was easiest.

Regards,

mazin