Return the enumerated device names from the backend

Rather than using an out parameter.
This commit is contained in:
Chris Robinson
2020-03-30 15:37:41 -07:00
parent 167bdce48d
commit f2ddf971df
34 changed files with 192 additions and 144 deletions
+16 -6
View File
@@ -1217,18 +1217,28 @@ void ProbeAllDevicesList()
DO_INITCONFIG();
std::lock_guard<std::recursive_mutex> _{ListLock};
alcAllDevicesList.clear();
if(PlaybackFactory)
PlaybackFactory->probe(DevProbe::Playback, &alcAllDevicesList);
if(!PlaybackFactory)
decltype(alcAllDevicesList){}.swap(alcAllDevicesList);
else
{
std::string names{PlaybackFactory->probe(DevProbe::Playback)};
if(names.empty()) names += '\0';
names.swap(alcAllDevicesList);
}
}
void ProbeCaptureDeviceList()
{
DO_INITCONFIG();
std::lock_guard<std::recursive_mutex> _{ListLock};
alcCaptureDeviceList.clear();
if(CaptureFactory)
CaptureFactory->probe(DevProbe::Capture, &alcCaptureDeviceList);
if(!CaptureFactory)
decltype(alcCaptureDeviceList){}.swap(alcCaptureDeviceList);
else
{
std::string names{CaptureFactory->probe(DevProbe::Capture)};
if(names.empty()) names += '\0';
names.swap(alcCaptureDeviceList);
}
}
} // namespace
+15 -11
View File
@@ -1229,27 +1229,31 @@ bool AlsaBackendFactory::init()
bool AlsaBackendFactory::querySupport(BackendType type)
{ return (type == BackendType::Playback || type == BackendType::Capture); }
void AlsaBackendFactory::probe(DevProbe type, std::string *outnames)
std::string AlsaBackendFactory::probe(DevProbe type)
{
auto add_device = [outnames](const DevMap &entry) -> void
std::string outnames;
auto add_device = [&outnames](const DevMap &entry) -> void
{
/* +1 to also append the null char (to ensure a null-separated list and
* double-null terminated list).
*/
outnames->append(entry.name.c_str(), entry.name.length()+1);
outnames.append(entry.name.c_str(), entry.name.length()+1);
};
switch(type)
{
case DevProbe::Playback:
PlaybackDevices = probe_devices(SND_PCM_STREAM_PLAYBACK);
std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
break;
case DevProbe::Playback:
PlaybackDevices = probe_devices(SND_PCM_STREAM_PLAYBACK);
std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
break;
case DevProbe::Capture:
CaptureDevices = probe_devices(SND_PCM_STREAM_CAPTURE);
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
case DevProbe::Capture:
CaptureDevices = probe_devices(SND_PCM_STREAM_CAPTURE);
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
}
return outnames;
}
BackendPtr AlsaBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+1 -1
View File
@@ -66,7 +66,7 @@ struct BackendFactory {
virtual bool querySupport(BackendType type) = 0;
virtual void probe(DevProbe type, std::string *outnames) = 0;
virtual std::string probe(DevProbe type) = 0;
virtual BackendPtr createBackend(ALCdevice *device, BackendType type) = 0;
+8 -6
View File
@@ -637,16 +637,18 @@ bool CoreAudioBackendFactory::init() { return true; }
bool CoreAudioBackendFactory::querySupport(BackendType type)
{ return type == BackendType::Playback || type == BackendType::Capture; }
void CoreAudioBackendFactory::probe(DevProbe type, std::string *outnames)
std::string CoreAudioBackendFactory::probe(DevProbe type)
{
std::string outnames;
switch(type)
{
case DevProbe::Playback:
case DevProbe::Capture:
/* Includes null char. */
outnames->append(ca_device, sizeof(ca_device));
break;
case DevProbe::Playback:
case DevProbe::Capture:
/* Includes null char. */
outnames.append(ca_device, sizeof(ca_device));
break;
}
return outnames;
}
BackendPtr CoreAudioBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+20 -17
View File
@@ -869,14 +869,15 @@ bool DSoundBackendFactory::init()
bool DSoundBackendFactory::querySupport(BackendType type)
{ return (type == BackendType::Playback || type == BackendType::Capture); }
void DSoundBackendFactory::probe(DevProbe type, std::string *outnames)
std::string DSoundBackendFactory::probe(DevProbe type)
{
auto add_device = [outnames](const DevMap &entry) -> void
std::string outnames;
auto add_device = [&outnames](const DevMap &entry) -> void
{
/* +1 to also append the null char (to ensure a null-separated list and
* double-null terminated list).
*/
outnames->append(entry.name.c_str(), entry.name.length()+1);
outnames.append(entry.name.c_str(), entry.name.length()+1);
};
/* Initialize COM to prevent name truncation */
@@ -884,24 +885,26 @@ void DSoundBackendFactory::probe(DevProbe type, std::string *outnames)
HRESULT hrcom{CoInitialize(nullptr)};
switch(type)
{
case DevProbe::Playback:
PlaybackDevices.clear();
hr = DirectSoundEnumerateW(DSoundEnumDevices, &PlaybackDevices);
if(FAILED(hr))
ERR("Error enumerating DirectSound playback devices (0x%lx)!\n", hr);
std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
break;
case DevProbe::Playback:
PlaybackDevices.clear();
hr = DirectSoundEnumerateW(DSoundEnumDevices, &PlaybackDevices);
if(FAILED(hr))
ERR("Error enumerating DirectSound playback devices (0x%lx)!\n", hr);
std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
break;
case DevProbe::Capture:
CaptureDevices.clear();
hr = DirectSoundCaptureEnumerateW(DSoundEnumDevices, &CaptureDevices);
if(FAILED(hr))
ERR("Error enumerating DirectSound capture devices (0x%lx)!\n", hr);
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
case DevProbe::Capture:
CaptureDevices.clear();
hr = DirectSoundCaptureEnumerateW(DSoundEnumDevices, &CaptureDevices);
if(FAILED(hr))
ERR("Error enumerating DirectSound capture devices (0x%lx)!\n", hr);
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
}
if(SUCCEEDED(hrcom))
CoUninitialize();
return outnames;
}
BackendPtr DSoundBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+9 -8
View File
@@ -504,18 +504,19 @@ bool JackBackendFactory::init()
bool JackBackendFactory::querySupport(BackendType type)
{ return (type == BackendType::Playback); }
void JackBackendFactory::probe(DevProbe type, std::string *outnames)
std::string JackBackendFactory::probe(DevProbe type)
{
std::string outnames;
switch(type)
{
case DevProbe::Playback:
/* Includes null char. */
outnames->append(jackDevice, sizeof(jackDevice));
break;
case DevProbe::Capture:
break;
case DevProbe::Playback:
/* Includes null char. */
outnames.append(jackDevice, sizeof(jackDevice));
break;
case DevProbe::Capture:
break;
}
return outnames;
}
BackendPtr JackBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+2 -2
View File
@@ -66,8 +66,8 @@ bool LoopbackBackendFactory::init()
bool LoopbackBackendFactory::querySupport(BackendType)
{ return true; }
void LoopbackBackendFactory::probe(DevProbe, std::string*)
{ }
std::string LoopbackBackendFactory::probe(DevProbe)
{ return std::string{}; }
BackendPtr LoopbackBackendFactory::createBackend(ALCdevice *device, BackendType)
{ return BackendPtr{new LoopbackBackend{device}}; }
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+9 -7
View File
@@ -154,17 +154,19 @@ bool NullBackendFactory::init()
bool NullBackendFactory::querySupport(BackendType type)
{ return (type == BackendType::Playback); }
void NullBackendFactory::probe(DevProbe type, std::string *outnames)
std::string NullBackendFactory::probe(DevProbe type)
{
std::string outnames;
switch(type)
{
case DevProbe::Playback:
/* Includes null char. */
outnames->append(nullDevice, sizeof(nullDevice));
break;
case DevProbe::Capture:
break;
case DevProbe::Playback:
/* Includes null char. */
outnames.append(nullDevice, sizeof(nullDevice));
break;
case DevProbe::Capture:
break;
}
return outnames;
}
BackendPtr NullBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+8 -6
View File
@@ -939,16 +939,18 @@ bool OSLBackendFactory::init() { return true; }
bool OSLBackendFactory::querySupport(BackendType type)
{ return (type == BackendType::Playback || type == BackendType::Capture); }
void OSLBackendFactory::probe(DevProbe type, std::string *outnames)
std::string OSLBackendFactory::probe(DevProbe type)
{
std::string outnames;
switch(type)
{
case DevProbe::Playback:
case DevProbe::Capture:
/* Includes null char. */
outnames->append(opensl_device, sizeof(opensl_device));
break;
case DevProbe::Playback:
case DevProbe::Capture:
/* Includes null char. */
outnames.append(opensl_device, sizeof(opensl_device));
break;
}
return outnames;
}
BackendPtr OSLBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+17 -13
View File
@@ -670,32 +670,36 @@ bool OSSBackendFactory::init()
bool OSSBackendFactory::querySupport(BackendType type)
{ return (type == BackendType::Playback || type == BackendType::Capture); }
void OSSBackendFactory::probe(DevProbe type, std::string *outnames)
std::string OSSBackendFactory::probe(DevProbe type)
{
auto add_device = [outnames](const DevMap &entry) -> void
std::string outnames;
auto add_device = [&outnames](const DevMap &entry) -> void
{
struct stat buf;
if(stat(entry.device_name.c_str(), &buf) == 0)
{
/* Includes null char. */
outnames->append(entry.name.c_str(), entry.name.length()+1);
outnames.append(entry.name.c_str(), entry.name.length()+1);
}
};
switch(type)
{
case DevProbe::Playback:
PlaybackDevices.clear();
ALCossListPopulate(&PlaybackDevices, DSP_CAP_OUTPUT);
std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
break;
case DevProbe::Playback:
PlaybackDevices.clear();
ALCossListPopulate(&PlaybackDevices, DSP_CAP_OUTPUT);
std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
break;
case DevProbe::Capture:
CaptureDevices.clear();
ALCossListPopulate(&CaptureDevices, DSP_CAP_INPUT);
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
case DevProbe::Capture:
CaptureDevices.clear();
ALCossListPopulate(&CaptureDevices, DSP_CAP_INPUT);
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
}
return outnames;
}
BackendPtr OSSBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+8 -6
View File
@@ -419,16 +419,18 @@ bool PortBackendFactory::init()
bool PortBackendFactory::querySupport(BackendType type)
{ return (type == BackendType::Playback || type == BackendType::Capture); }
void PortBackendFactory::probe(DevProbe type, std::string *outnames)
std::string PortBackendFactory::probe(DevProbe type)
{
std::string outnames;
switch(type)
{
case DevProbe::Playback:
case DevProbe::Capture:
/* Includes null char. */
outnames->append(pa_device, sizeof(pa_device));
break;
case DevProbe::Playback:
case DevProbe::Capture:
/* Includes null char. */
outnames.append(pa_device, sizeof(pa_device));
break;
}
return outnames;
}
BackendPtr PortBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+7 -3
View File
@@ -1501,14 +1501,16 @@ bool PulseBackendFactory::init()
bool PulseBackendFactory::querySupport(BackendType type)
{ return type == BackendType::Playback || type == BackendType::Capture; }
void PulseBackendFactory::probe(DevProbe type, std::string *outnames)
std::string PulseBackendFactory::probe(DevProbe type)
{
auto add_device = [outnames](const DevMap &entry) -> void
std::string outnames;
auto add_device = [&outnames](const DevMap &entry) -> void
{
/* +1 to also append the null char (to ensure a null-separated list and
* double-null terminated list).
*/
outnames->append(entry.name.c_str(), entry.name.length()+1);
outnames.append(entry.name.c_str(), entry.name.length()+1);
};
switch(type)
@@ -1523,6 +1525,8 @@ void PulseBackendFactory::probe(DevProbe type, std::string *outnames)
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
}
return outnames;
}
BackendPtr PulseBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+7 -4
View File
@@ -193,22 +193,25 @@ bool SDL2BackendFactory::init()
bool SDL2BackendFactory::querySupport(BackendType type)
{ return type == BackendType::Playback; }
void SDL2BackendFactory::probe(DevProbe type, std::string *outnames)
std::string SDL2BackendFactory::probe(DevProbe type)
{
std::string outnames;
if(type != DevProbe::Playback)
return;
return outnames;
int num_devices{SDL_GetNumAudioDevices(SDL_FALSE)};
/* Includes null char. */
outnames->append(defaultDeviceName, sizeof(defaultDeviceName));
outnames.append(defaultDeviceName, sizeof(defaultDeviceName));
for(int i{0};i < num_devices;++i)
{
std::string name{DEVNAME_PREFIX};
name += SDL_GetAudioDeviceName(i, SDL_FALSE);
if(!name.empty())
outnames->append(name.c_str(), name.length()+1);
outnames.append(name.c_str(), name.length()+1);
}
return outnames;
}
BackendPtr SDL2BackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+8 -6
View File
@@ -452,16 +452,18 @@ bool SndIOBackendFactory::init()
bool SndIOBackendFactory::querySupport(BackendType type)
{ return (type == BackendType::Playback || type == BackendType::Capture); }
void SndIOBackendFactory::probe(DevProbe type, std::string *outnames)
std::string SndIOBackendFactory::probe(DevProbe type)
{
std::string outnames;
switch(type)
{
case DevProbe::Playback:
case DevProbe::Capture:
/* Includes null char. */
outnames->append(sndio_device, sizeof(sndio_device));
break;
case DevProbe::Playback:
case DevProbe::Capture:
/* Includes null char. */
outnames.append(sndio_device, sizeof(sndio_device));
break;
}
return outnames;
}
BackendPtr SndIOBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+13 -11
View File
@@ -270,21 +270,23 @@ bool SolarisBackendFactory::init()
bool SolarisBackendFactory::querySupport(BackendType type)
{ return type == BackendType::Playback; }
void SolarisBackendFactory::probe(DevProbe type, std::string *outnames)
std::string SolarisBackendFactory::probe(DevProbe type)
{
std::string outnames;
switch(type)
{
case DevProbe::Playback:
{
struct stat buf;
if(stat(solaris_driver.c_str(), &buf) == 0)
outnames->append(solaris_device, sizeof(solaris_device));
}
break;
case DevProbe::Capture:
break;
case DevProbe::Playback:
{
struct stat buf;
if(stat(solaris_driver.c_str(), &buf) == 0)
outnames.append(solaris_device, sizeof(solaris_device));
}
break;
case DevProbe::Capture:
break;
}
return outnames;
}
BackendPtr SolarisBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+6 -3
View File
@@ -1744,14 +1744,15 @@ bool WasapiBackendFactory::init()
bool WasapiBackendFactory::querySupport(BackendType type)
{ return type == BackendType::Playback || type == BackendType::Capture; }
void WasapiBackendFactory::probe(DevProbe type, std::string *outnames)
std::string WasapiBackendFactory::probe(DevProbe type)
{
auto add_device = [outnames](const DevMap &entry) -> void
std::string outnames;
auto add_device = [&outnames](const DevMap &entry) -> void
{
/* +1 to also append the null char (to ensure a null-separated list and
* double-null terminated list).
*/
outnames->append(entry.name.c_str(), entry.name.length()+1);
outnames.append(entry.name.c_str(), entry.name.length()+1);
};
switch(type)
@@ -1766,6 +1767,8 @@ void WasapiBackendFactory::probe(DevProbe type, std::string *outnames)
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
}
return outnames;
}
BackendPtr WasapiBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+9 -7
View File
@@ -373,17 +373,19 @@ bool WaveBackendFactory::init()
bool WaveBackendFactory::querySupport(BackendType type)
{ return type == BackendType::Playback; }
void WaveBackendFactory::probe(DevProbe type, std::string *outnames)
std::string WaveBackendFactory::probe(DevProbe type)
{
std::string outnames;
switch(type)
{
case DevProbe::Playback:
/* Includes null char. */
outnames->append(waveDevice, sizeof(waveDevice));
break;
case DevProbe::Capture:
break;
case DevProbe::Playback:
/* Includes null char. */
outnames.append(waveDevice, sizeof(waveDevice));
break;
case DevProbe::Capture:
break;
}
return outnames;
}
BackendPtr WaveBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;
+13 -11
View File
@@ -590,28 +590,30 @@ bool WinMMBackendFactory::init()
bool WinMMBackendFactory::querySupport(BackendType type)
{ return type == BackendType::Playback || type == BackendType::Capture; }
void WinMMBackendFactory::probe(DevProbe type, std::string *outnames)
std::string WinMMBackendFactory::probe(DevProbe type)
{
auto add_device = [outnames](const std::string &dname) -> void
std::string outnames;
auto add_device = [&outnames](const std::string &dname) -> void
{
/* +1 to also append the null char (to ensure a null-separated list and
* double-null terminated list).
*/
if(!dname.empty())
outnames->append(dname.c_str(), dname.length()+1);
outnames.append(dname.c_str(), dname.length()+1);
};
switch(type)
{
case DevProbe::Playback:
ProbePlaybackDevices();
std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
break;
case DevProbe::Playback:
ProbePlaybackDevices();
std::for_each(PlaybackDevices.cbegin(), PlaybackDevices.cend(), add_device);
break;
case DevProbe::Capture:
ProbeCaptureDevices();
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
case DevProbe::Capture:
ProbeCaptureDevices();
std::for_each(CaptureDevices.cbegin(), CaptureDevices.cend(), add_device);
break;
}
return outnames;
}
BackendPtr WinMMBackendFactory::createBackend(ALCdevice *device, BackendType type)
+1 -1
View File
@@ -9,7 +9,7 @@ public:
bool querySupport(BackendType type) override;
void probe(DevProbe type, std::string *outnames) override;
std::string probe(DevProbe type) override;
BackendPtr createBackend(ALCdevice *device, BackendType type) override;