Linux

每次重新啟動後相同 USB 音效卡的相同設備名稱

  • August 23, 2021

我想使用 Debian 10、Darkice 和 Icecast 建構一個流媒體伺服器,它可以流式傳輸兩個實時錄製的頻道。

音效卡是兩個 Behringer UCA202,始終插入機器的相同物理 USB 埠。假設一個是上部 USB 埠,另一個是下部 USB 埠。

使用amixer -l檢查時,其中一個音效卡名為 CODEC,另一個名為 CODEC_1。您可以在相應通道的 Darkice 配置文件中輸入它,並在那里為 Icecast 分配一個掛載點。

所以目前我們有以下配置:

上部 USB 中的卡 -> 名稱為 CODEC -> Icecast 中的掛載點 stream1

下部 USB 中的卡 -> 名稱為 CODEC_1 -> Icecast 中的 Mountpoint stream2

問題是在重新啟動後,音效卡有時會由於設備發現的性質而改變它們的名稱。CODEC 變為 CODEC_1,反之亦然。隨著這種情況的發生,掛載點上的流也發生了切換,並且 stream1 來自錯誤的音效卡。

現在如何每次都分配相同的名稱,以便 CODEC 始終是上部 USB 埠上的音效卡?可能是某種 udev 規則?

根據要求,我添加了 udevadm info -ap /sys/ 的輸出

在這裡,我們使用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==""

這是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==""

根據提供的 udevadm 資訊,您應該能夠臨時重命名 2 個設備 ID:

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

新的別名 ID 名稱應顯示在

cat /proc/asound/cards

對於 udev 規則,將 ‘card0’ 或 ‘card1’ 替換為 ‘card?’ 所以udev分配的卡ID忽略卡索引號,僅基於USB連接

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”

有關此的更多資訊,請訪問https://alsa.opensrc.org/Udev

引用自:https://unix.stackexchange.com/questions/533102