问题
I am writing a C program where I would like to enumerate all the capture devices in my system (in practice, I know I have three webcams plus the "integrated" microphone), recognize them and start capturing from them all at the same time.
I has some success using snd_device_name_hint() to enumerate all PCM devices and then snd_device_name_get_hint() to determine the "IOID" to see if they support capture. But now, how do I open the related device with snd_pcm_open() so that I can capture? I would like to use the "hw" interface as I do not want to overload the system with many conversion rates, so I would also like to see if there is a method to report the HW supported sampling frequencies.
Thank you!
回答1:
snd_device_name_hint()
can return multiple device names for the same hardware device (e.g., plughw
and hw
).
It can also returns devices that do not correspond to a single hardware device (such as null
, or PulseAudio/Jack/Bluetooth devices).
To enumerate hardware devices, call snd_card_next()
and snd_ctl_pcm_next_device()
(see the aplay source code for an example).
To check whether a sample rate is supported, call snd_pcm_hw_params_test_rate()
.
来源:https://stackoverflow.com/questions/19696926/enumerating-capture-alsa-devices-and-capture-from-them