0

I have a few webcam devices connected over USB and I want to record the audio from them using arecord. The device list is below (Cards 1 through 4):

t:~$ arecord --list-devices
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC Analog [ALC Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: TT [CA TT], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: TT_1 [CA TT], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: TT_2 [CA TT], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 4: TT_3 [CA TT], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

When I list the devices that PulseAudio sees, I have the following (partial list only showing the Webcams):

t:~$pactl list
Module #0
        Name: module-device-restore 
....
Card #11
    Name: alsa_card.usb-VS_Inc_CA_TT-02
    Driver: module-alsa-card.c
    Owner Module: 38
    Properties:
        alsa.card = "1"
        alsa.card_name = "CA TT"
        alsa.long_card_name = "VS Inc CA TT at usb-0000:00:14.0-3"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:00:14.0-usb-0:3:1.2"
        sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.2/sound/card1"
        udev.id = "usb-VS_Inc_CA_TT-02"
        device.bus = "usb"
        device.vendor.id = "1a1a"
        device.vendor.name = "Technology Inc."
        device.product.id = "2a2a"
        device.product.name = "CA TT"
        device.serial = "VS_Inc_CA_TT"
        device.form_factor = "webcam"
        device.string = "1"
        device.description = "CA TT"
        module-udev-detect.discovered = "1"
        device.icon_name = "camera-web-usb"
    Profiles:
        input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
        input:iec958-stereo: Digital Stereo (IEC958) Input (sinks: 0, sources: 1, priority: 55, available: yes)
        off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
    Active Profile: input:analog-stereo
    Ports:
        analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
            Part of profile(s): input:analog-stereo
        iec958-stereo-input: Digital Input (S/PDIF) (priority: 0, latency offset: 0 usec)
            Part of profile(s): input:iec958-stereo

Card #12
    Name: alsa_card.usb-VS_Inc_CA_TT-02.2
    Driver: module-alsa-card.c
    Owner Module: 39
    Properties:
        alsa.card = "2"
        alsa.card_name = "CA TT"
        alsa.long_card_name = "VS Inc CA TT at usb-0000:00:14.0-4"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:00:14.0-usb-0:4:1.2"
        sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4:1.2/sound/card2"
        udev.id = "usb-VS_Inc_CA_TT-02"
        device.bus = "usb"
        device.vendor.id = "1a1a"
        device.vendor.name = "Technology Inc."
        device.product.id = "2a2a"
        device.product.name = "CA TT"
        device.serial = "VS_Inc_CA_TT"
        device.form_factor = "webcam"
        device.string = "2"
        device.description = "CA TT"
        module-udev-detect.discovered = "1"
        device.icon_name = "camera-web-usb"
    Profiles:
        input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
        input:iec958-stereo: Digital Stereo (IEC958) Input (sinks: 0, sources: 1, priority: 55, available: yes)
        off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
    Active Profile: input:analog-stereo
    Ports:
        analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
            Part of profile(s): input:analog-stereo
        iec958-stereo-input: Digital Input (S/PDIF) (priority: 0, latency offset: 0 usec)
            Part of profile(s): input:iec958-stereo

Card #13
    Name: alsa_card.usb-VS_Inc_CA_TT-02.3
    Driver: module-alsa-card.c
    Owner Module: 40
    Properties:
        alsa.card = "3"
        alsa.card_name = "CA TT"
        alsa.long_card_name = "VS Inc CA TT at usb-0000:00:14.0-1"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:00:14.0-usb-0:1:1.2"
        sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.2/sound/card3"
        udev.id = "usb-VS_Inc_CA_TT-02"
        device.bus = "usb"
        device.vendor.id = "1a1a"
        device.vendor.name = "Technology Inc."
        device.product.id = "2a2a"
        device.product.name = "CA TT"
        device.serial = "VS_Inc_CA_TT"
        device.form_factor = "webcam"
        device.string = "3"
        device.description = "CA TT"
        module-udev-detect.discovered = "1"
        device.icon_name = "camera-web-usb"
    Profiles:
        input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
        input:iec958-stereo: Digital Stereo (IEC958) Input (sinks: 0, sources: 1, priority: 55, available: yes)
        off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
    Active Profile: input:analog-stereo
    Ports:
        analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
            Part of profile(s): input:analog-stereo
        iec958-stereo-input: Digital Input (S/PDIF) (priority: 0, latency offset: 0 usec)
            Part of profile(s): input:iec958-stereo

Card #14
    Name: alsa_card.usb-VS_Inc_CA_TT-02.4
    Driver: module-alsa-card.c
    Owner Module: 41
    Properties:
        alsa.card = "4"
        alsa.card_name = "CA TT"
        alsa.long_card_name = "VS Inc CA TT at usb-0000:00:14.0-2"
        alsa.driver_name = "snd_usb_audio"
        device.bus_path = "pci-0000:00:14.0-usb-0:2:1.2"
        sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb2/2-2/2-2:1.2/sound/card4"
        udev.id = "usb-VS_Inc_CA_TT-02"
        device.bus = "usb"
        device.vendor.id = "1a1a"
        device.vendor.name = "Technology Inc."
        device.product.id = "2a2a"
        device.product.name = "CA TT"
        device.serial = "VS_Inc_CA_TT"
        device.form_factor = "webcam"
        device.string = "4"
        device.description = "CA TT"
        module-udev-detect.discovered = "1"
        device.icon_name = "camera-web-usb"
    Profiles:
        input:analog-stereo: Analog Stereo Input (sinks: 0, sources: 1, priority: 60, available: yes)
        input:iec958-stereo: Digital Stereo (IEC958) Input (sinks: 0, sources: 1, priority: 55, available: yes)
        off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
    Active Profile: input:analog-stereo
    Ports:
        analog-input: Analog Input (priority: 10000, latency offset: 0 usec)
            Part of profile(s): input:analog-stereo
        iec958-stereo-input: Digital Input (S/PDIF) (priority: 0, latency offset: 0 usec)
            Part of profile(s): input:iec958-stereo

Now, I am writing a shell script that reads the card number from a fixed config file and I don't want the card numbers in the arecord --list-devices to change if one of the webcams is unplugged. I want to make sure that the webcam connected to first USB port (/devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.2) is always mapped to card 1, the second one to card 2 and so on. In other words, I want the mapping between Webcams/USB-port to the card number is fixed.

Is this possible?

1 Answer 1

1

Changing the card number for devices with identical USB IDs is not possible.

But it is possible to use udev rules to change the card ID (TT_2 etc. above), which can also be used with arecord. See "Identify two identical audio devices" on https://alsa.opensrc.org/Udev:

SUBSYSTEM!="sound", GOTO="my_usb_audio_end"
ACTION!="add", GOTO="my_usb_audio_end"

DEVPATH=="/devices/pci0000:00/0000:00:13.2/usb2/2-6/2-6.2/2-6.2:1.0/sound/card?", ATTR{id}="UA1A_A"
DEVPATH=="/devices/pci0000:00/0000:00:13.2/usb2/2-6/2-6.3/2-6.3:1.0/sound/card?", ATTR{id}="UA1A_B"

LABEL="my_usb_audio_end"
$ arecord -D default:UA1A_A something.wav
1
  • So here's what I actually did. First found a list of all my pcm devices ls -la /dev/snd/pcm* . Then looked up the udev info using udevadm info -a -p $(udevadm info -q path -n /dev/snd/pcmC1); Then added the id using the corresponding kernel SUBSYSTEM=="sound", KERNELS=="2-3:1.2", ATTR{id}="UA1A_A" Commented Sep 14, 2020 at 20:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.