每次重新启动后,相同的 USB 声卡具有相同的设备名称

每次重新启动后,相同的 USB 声卡具有相同的设备名称

我想使用 Debian 10、Darkice 和 Icecast 构建一个流媒体服务器,用于流式传输两个实时录制的频道。

声卡是两个 Behringer UCA202,始终插入机器的相同物理 USB 端口。假设一个是上面的 USB 端口,另一个是下面的 USB 端口。

当检查时amixer-l其中一张声卡名为 CODEC,另一张名为 CODEC_1。您可以在 Darkice 的配置文件中输入相应通道的信息,并为 Icecast 分配一个挂载点。

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

上方 USB 中的卡 -> 名称为 CODEC -> Icecast 中的挂载点stream1

下部 USB 中的卡 -> 名称为 CODEC_1 -> Icecast 中的挂载点stream2

问题是,重新启动后,由于设备发现的性质,声卡有时会切换名称。 CODEC 变为 CODEC_1,反之亦然。随着这种情况的发生,挂载点上的流也发生了切换,stream1 来自错误的声卡。

现在我如何每次分配相同的名称,以便 CODEC 始终是上 USB 端口上的声卡?可能是某种 udev 规则?

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

这里我们输出udevadm 信息 -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 信息 -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==""

答案1

根据提供的 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

答案2

我的回答

Udev 规则针对看似无法区分的设备

可能会有帮助。我有 4 个相同的相机需要确定......

相关内容