1

I want to build a streaming server using Debian 10, Darkice and Icecast that streams two live recorded channels.

The sound cards are two Behringer UCA202 always plugged into the same physical USB-ports of the machine. Let's say one is the upper USB-port and the other one is the lower USB-port.

When checking with amixer -l one of the sound cards is named CODEC and the other one is CODEC_1. You can enter that in the config file of Darkice for the corresponding channel and assign a mountpoint for Icecast there.

So for the moment we have the following configuration:

Card in upper USB -> name is CODEC -> Mountpoint stream1 in Icecast

Card in lower USB -> name is CODEC_1 -> Mountpoint stream2 in Icecast

The problem is that after a reboot the sound cards can sometimes switch their names due to the nature of device discovery. CODEC becomes CODEC_1 and vice versa. And with this happening the streams on the mount points have also switched and stream1 is from the wrong sound card.

Now how can I assign the same name each time so that CODEC is always the sound card on the upper USB-port? Some kind of udev rule probably?

As requested I've added the output of udevadm info -ap /sys/

Here we go with the output of udevadm info -ap /sys/class/sound/controlC0

  looking at device '/devices/pci0000:00/0000:00:1a.1/usb3/3-2/3-2:1.0/sound/card0/controlC0':
    KERNEL=="controlC0"
    SUBSYSTEM=="sound"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:1a.1/usb3/3-2/3-2:1.0/sound/card0':
    KERNELS=="card0"
    SUBSYSTEMS=="sound"
    DRIVERS==""
    ATTRS{id}=="CODEC_1"
    ATTRS{number}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:1a.1/usb3/3-2/3-2:1.0':
    KERNELS=="3-2:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="snd-usb-audio"
    ATTRS{bInterfaceClass}=="01"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bNumEndpoints}=="00"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{authorized}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1a.1/usb3/3-2':
    KERNELS=="3-2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bMaxPacketSize0}=="8"
    ATTRS{busnum}=="3"
    ATTRS{rx_lanes}=="1"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="2"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{maxchild}=="0"
    ATTRS{configuration}==""
    ATTRS{tx_lanes}=="1"
    ATTRS{bcdDevice}=="0100"
    ATTRS{product}=="USB Audio CODEC "
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{speed}=="12"
    ATTRS{idVendor}=="08bb"
    ATTRS{bmAttributes}=="80"
    ATTRS{devnum}=="3"
    ATTRS{authorized}=="1"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{idProduct}=="2902"
    ATTRS{version}==" 1.10"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bNumInterfaces}==" 4"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="unknown"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{manufacturer}=="Burr-Brown from TI              "
    ATTRS{urbnum}=="1331512"

  looking at parent device '/devices/pci0000:00/0000:00:1a.1/usb3':
    KERNELS=="usb3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{serial}=="0000:00:1a.1"
    ATTRS{urbnum}=="89"
    ATTRS{idProduct}=="0001"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{configuration}==""
    ATTRS{busnum}=="3"
    ATTRS{devnum}=="1"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{rx_lanes}=="1"
    ATTRS{devpath}=="0"
    ATTRS{speed}=="12"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bDeviceClass}=="09"
    ATTRS{removable}=="unknown"
    ATTRS{product}=="UHCI Host Controller"
    ATTRS{version}==" 1.10"
    ATTRS{bcdDevice}=="0419"
    ATTRS{authorized_default}=="1"
    ATTRS{authorized}=="1"
    ATTRS{tx_lanes}=="1"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{ltm_capable}=="no"
    ATTRS{idVendor}=="1d6b"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{maxchild}=="2"
    ATTRS{quirks}=="0x0"
    ATTRS{manufacturer}=="Linux 4.19.0-5-amd64 uhci_hcd"
    ATTRS{bMaxPower}=="0mA"

  looking at parent device '/devices/pci0000:00/0000:00:1a.1':
    KERNELS=="0000:00:1a.1"
    SUBSYSTEMS=="pci"
    DRIVERS=="uhci_hcd"
    ATTRS{ari_enabled}=="0"
    ATTRS{driver_override}=="(null)"
    ATTRS{d3cold_allowed}=="0"
    ATTRS{device}=="0x2835"
    ATTRS{msi_bus}=="1"
    ATTRS{subsystem_device}=="0x2808"
    ATTRS{broken_parity_status}=="0"
    ATTRS{local_cpulist}=="0-1"
    ATTRS{irq}=="21"
    ATTRS{subsystem_vendor}=="0x103c"
    ATTRS{class}=="0x0c0300"
    ATTRS{numa_node}=="-1"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{vendor}=="0x8086"
    ATTRS{revision}=="0x02"
    ATTRS{enable}=="1"
    ATTRS{local_cpus}=="3"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

And here is the output of udevadm info -ap /sys/class/sound/controlC1

  looking at device '/devices/pci0000:00/0000:00:1a.1/usb3/3-1/3-1:1.0/sound/card1/controlC1':
    KERNEL=="controlC1"
    SUBSYSTEM=="sound"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:1a.1/usb3/3-1/3-1:1.0/sound/card1':
    KERNELS=="card1"
    SUBSYSTEMS=="sound"
    DRIVERS==""
    ATTRS{id}=="CODEC"
    ATTRS{number}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1a.1/usb3/3-1/3-1:1.0':
    KERNELS=="3-1:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="snd-usb-audio"
    ATTRS{bInterfaceClass}=="01"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bNumEndpoints}=="00"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bInterfaceSubClass}=="01"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{authorized}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1a.1/usb3/3-1':
    KERNELS=="3-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{tx_lanes}=="1"
    ATTRS{bMaxPacketSize0}=="8"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{speed}=="12"
    ATTRS{product}=="USB Audio CODEC "
    ATTRS{version}==" 1.10"
    ATTRS{bcdDevice}=="0100"
    ATTRS{busnum}=="3"
    ATTRS{ltm_capable}=="no"
    ATTRS{devnum}=="5"
    ATTRS{configuration}==""
    ATTRS{devpath}=="1"
    ATTRS{manufacturer}=="Burr-Brown from TI              "
    ATTRS{quirks}=="0x0"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{authorized}=="1"
    ATTRS{rx_lanes}=="1"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{bNumInterfaces}==" 4"
    ATTRS{maxchild}=="0"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{urbnum}=="62"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="2902"
    ATTRS{idVendor}=="08bb"

  looking at parent device '/devices/pci0000:00/0000:00:1a.1/usb3':
    KERNELS=="usb3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{manufacturer}=="Linux 4.19.0-5-amd64 uhci_hcd"
    ATTRS{idVendor}=="1d6b"
    ATTRS{devnum}=="1"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{authorized_default}=="1"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{product}=="UHCI Host Controller"
    ATTRS{ltm_capable}=="no"
    ATTRS{rx_lanes}=="1"
    ATTRS{removable}=="unknown"
    ATTRS{maxchild}=="2"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{bcdDevice}=="0419"
    ATTRS{busnum}=="3"
    ATTRS{serial}=="0000:00:1a.1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{idProduct}=="0001"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bmAttributes}=="e0"
    ATTRS{authorized}=="1"
    ATTRS{quirks}=="0x0"
    ATTRS{speed}=="12"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{devpath}=="0"
    ATTRS{configuration}==""
    ATTRS{urbnum}=="89"
    ATTRS{version}==" 1.10"
    ATTRS{tx_lanes}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:1a.1':
    KERNELS=="0000:00:1a.1"
    SUBSYSTEMS=="pci"
    DRIVERS=="uhci_hcd"
    ATTRS{local_cpulist}=="0-1"
    ATTRS{driver_override}=="(null)"
    ATTRS{irq}=="21"
    ATTRS{revision}=="0x02"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0300"
    ATTRS{subsystem_vendor}=="0x103c"
    ATTRS{enable}=="1"
    ATTRS{subsystem_device}=="0x2808"
    ATTRS{d3cold_allowed}=="0"
    ATTRS{local_cpus}=="3"
    ATTRS{ari_enabled}=="0"
    ATTRS{msi_bus}=="1"
    ATTRS{vendor}=="0x8086"
    ATTRS{numa_node}=="-1"
    ATTRS{device}=="0x2835"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
  • Some equivalent to the predictable network interface names? Not sure. But do those cards have a unique ID you can read from a startup script that adapts the config file? – Philippos Jul 31 at 11:15
  • 1
    udevadm info -ap /sys/... can be your friend to figure out the unique parameters. I think you might be able to use e.g. ATTRS{devpath} and/or ATTRS{busnum} to identify the devices by the usb socket they were plugged into. See reactivated.net/writing_udev_rules.html for how to write the rules.. – Jonas Berlin Jul 31 at 13:17
  • @Whiskydrinker, Do you need more detailed assistance how to get going? Could you start with adding the output from for i in /sys/class/sound/card* ; do udevadm info -ap $i ; done into your question to get going? – Jonas Berlin Aug 1 at 5:57
1

from the udevadm info supplied, you should be able to temporarily rename the 2 device IDs with:

echo 'CODEC_A' | sudo tee /devices/pci0000:00/0000:00:1a.1/usb3/3-1/3-1:1.0/sound/card1/id 

echo 'CODEC_B' | sudo tee /devices/pci0000:00/0000:00:1a.1/usb3/3-2/3-2:1.0/sound/card0/id

new alias id names should be shown in

cat /proc/asound/cards

for the udev rules, substitute 'card0' or 'card1' with 'card?' so card ID assigned by udev ignores card index number and is only based on USB connection

DEVPATH=="/devices/pci0000:00/0000:00:1a.1/usb3/3-1/3-1:1.0/sound/card?", ATTR{id}="CODEC_A"

DEVPATH=="/devices/pci0000:00/0000:00:1a.1/usb3/3-2/3-2:1.0/sound/card?", ATTR{id}="CODEC_B"

more information about this at https://alsa.opensrc.org/Udev

  • 1
    This has worked. But I had to add some additional wildcards since the 3 in usb3/3-1/3-1:1.0 sometimes became a 2 and sometimes a 4 when rebooting. – Whiskydrinker Aug 28 at 11:46
  • expect if there are more usb devices than just those 2 that they could boot to any order. posting your modified udev rules to show the additional wildcards would help other users if they need similar modifications – nik gnomic Aug 28 at 16:24
  • 1
    DEVPATH=="/devices/pci0000:00/0000:00:1a.1/usb?/?-2/?-2:1.0/sound/card?", ATTR{id}="CODEC_B" works for CODEC_B. – Whiskydrinker Aug 29 at 12:30
0

My answer to

Udev rules for seemingly indistinguishable devices

might be helpful. I had 4 identical cameras to nail down ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.