fix(microphone): list usable ALSA capture endpoints

This commit is contained in:
linbo 2026-08-25 13:54:41 +08:00
parent 36c74af588
commit e0da0f1f80

View File

@ -2,6 +2,7 @@
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
#include <string_view>
#include <utility> #include <utility>
extern "C" { extern "C" {
@ -26,6 +27,17 @@ struct DeviceListDeleter {
} }
}; };
bool isFfmpegCaptureEndpoint(const char* device_name)
{
constexpr std::string_view kPlugHardwarePrefix = "plughw:";
if (!device_name) {
return false;
}
const std::string_view name(device_name);
return name.compare(0, kPlugHardwarePrefix.size(), kPlugHardwarePrefix) == 0;
}
} // namespace } // namespace
std::vector<MicrophoneInputDeviceInfo> listAvailableMicrophoneInputDevices() std::vector<MicrophoneInputDeviceInfo> listAvailableMicrophoneInputDevices()
@ -55,7 +67,7 @@ std::vector<MicrophoneInputDeviceInfo> listAvailableMicrophoneInputDevices()
for (int index = 0; index < device_list->nb_devices; ++index) { for (int index = 0; index < device_list->nb_devices; ++index) {
const AVDeviceInfo* source = device_list->devices[index]; const AVDeviceInfo* source = device_list->devices[index];
if (!source || !source->device_name || source->device_name[0] == '\0') { if (!source || !isFfmpegCaptureEndpoint(source->device_name)) {
continue; continue;
} }