diff options
Diffstat (limited to 'Alc/backends')
-rw-r--r-- | Alc/backends/alsa.cpp | 29 | ||||
-rw-r--r-- | Alc/backends/oss.cpp | 25 | ||||
-rw-r--r-- | Alc/backends/solaris.cpp | 11 |
3 files changed, 28 insertions, 37 deletions
diff --git a/Alc/backends/alsa.cpp b/Alc/backends/alsa.cpp index ebdc6129..aeb38585 100644 --- a/Alc/backends/alsa.cpp +++ b/Alc/backends/alsa.cpp @@ -207,11 +207,6 @@ ALSA_FUNCS(MAKE_FUNC); struct DevMap { std::string name; std::string device_name; - - template<typename StrT0, typename StrT1> - DevMap(StrT0&& name_, StrT1&& devname_) - : name{std::forward<StrT0>(name_)}, device_name{std::forward<StrT1>(devname_)} - { } }; al::vector<DevMap> PlaybackDevices; @@ -233,10 +228,9 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) snd_pcm_info_t *pcminfo; snd_pcm_info_malloc(&pcminfo); - devlist.emplace_back(alsaDevice, + devlist.emplace_back(DevMap{alsaDevice, GetConfigValue(nullptr, "alsa", (stream==SND_PCM_STREAM_PLAYBACK) ? "device" : "capture", - "default") - ); + "default")}); if(stream == SND_PCM_STREAM_PLAYBACK) { @@ -254,15 +248,15 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) } const char *oldsep{sep++}; - devlist.emplace_back(std::string(customdevs, oldsep), - next ? std::string(sep, next++) : std::string(sep)); + devlist.emplace_back(DevMap{std::string(customdevs, oldsep), + next ? std::string(sep, next++) : std::string(sep)}); const auto &entry = devlist.back(); TRACE("Got device \"%s\", \"%s\"\n", entry.name.c_str(), entry.device_name.c_str()); } } - const char *main_prefix{"plughw:"}; - ConfigValueStr(nullptr, "alsa", prefix_name(stream), &main_prefix); + const std::string main_prefix{ + ConfigValueStr(nullptr, "alsa", prefix_name(stream)).value_or("plughw:")}; int card{-1}; int err{snd_card_next(&card)}; @@ -288,9 +282,8 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) name = prefix_name(stream); name += '-'; name += cardid; - - const char *card_prefix{main_prefix}; - ConfigValueStr(nullptr, "alsa", name.c_str(), &card_prefix); + const std::string card_prefix{ + ConfigValueStr(nullptr, "alsa", name.c_str()).value_or(main_prefix)}; int dev{-1}; while(1) @@ -315,8 +308,8 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) name += cardid; name += '-'; name += std::to_string(dev); - const char *device_prefix{card_prefix}; - ConfigValueStr(nullptr, "alsa", name.c_str(), &device_prefix); + const std::string device_prefix{ + ConfigValueStr(nullptr, "alsa", name.c_str()).value_or(card_prefix)}; /* "CardName, PcmName (CARD=cardid,DEV=dev)" */ name = cardname; @@ -335,7 +328,7 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) device += ",DEV="; device += std::to_string(dev); - devlist.emplace_back(std::move(name), std::move(device)); + devlist.emplace_back(DevMap{std::move(name), std::move(device)}); const auto &entry = devlist.back(); TRACE("Got device \"%s\", \"%s\"\n", entry.name.c_str(), entry.device_name.c_str()); } diff --git a/Alc/backends/oss.cpp b/Alc/backends/oss.cpp index 0a28fcd8..e5b74334 100644 --- a/Alc/backends/oss.cpp +++ b/Alc/backends/oss.cpp @@ -80,17 +80,12 @@ namespace { constexpr char DefaultName[] = "OSS Default"; -const char *DefaultPlayback{"/dev/dsp"}; -const char *DefaultCapture{"/dev/dsp"}; +std::string DefaultPlayback{"/dev/dsp"}; +std::string DefaultCapture{"/dev/dsp"}; struct DevMap { std::string name; std::string device_name; - - template<typename StrT0, typename StrT1> - DevMap(StrT0&& name_, StrT1&& devname_) - : name{std::forward<StrT0>(name_)}, device_name{std::forward<StrT1>(devname_)} - { } }; bool checkName(const al::vector<DevMap> &list, const std::string &name) @@ -111,7 +106,7 @@ al::vector<DevMap> CaptureDevices; #define DSP_CAP_INPUT 0x00010000 void ALCossListPopulate(al::vector<DevMap> *devlist, int type) { - devlist->emplace_back(DefaultName, (type==DSP_CAP_INPUT) ? DefaultCapture : DefaultPlayback); + devlist->emplace_back(DevMap{DefaultName, (type==DSP_CAP_INPUT) ? DefaultCapture : DefaultPlayback}); } #else @@ -156,7 +151,7 @@ void ALCossListAppend(al::vector<DevMap> *list, const char *handle, size_t hlen, newname += std::to_string(++count); } - list->emplace_back(std::move(newname), std::move(devname)); + list->emplace_back(DevMap{std::move(newname), std::move(devname)}); const DevMap &entry = list->back(); TRACE("Got device \"%s\", \"%s\"\n", entry.name.c_str(), entry.device_name.c_str()); @@ -212,7 +207,7 @@ done: close(fd); fd = -1; - const char *defdev{(type_flag==DSP_CAP_INPUT) ? DefaultCapture : DefaultPlayback}; + const char *defdev{((type_flag==DSP_CAP_INPUT) ? DefaultCapture : DefaultPlayback).c_str()}; auto iter = std::find_if(devlist->cbegin(), devlist->cend(), [defdev](const DevMap &entry) -> bool { return entry.device_name == defdev; } @@ -331,7 +326,7 @@ int OSSPlayback::mixerProc() ALCenum OSSPlayback::open(const ALCchar *name) { - const char *devname{DefaultPlayback}; + const char *devname{DefaultPlayback.c_str()}; if(!name) name = DefaultName; else @@ -548,7 +543,7 @@ int OSScapture::recordProc() ALCenum OSScapture::open(const ALCchar *name) { - const char *devname{DefaultCapture}; + const char *devname{DefaultCapture.c_str()}; if(!name) name = DefaultName; else @@ -700,8 +695,10 @@ BackendFactory &OSSBackendFactory::getFactory() bool OSSBackendFactory::init() { - ConfigValueStr(nullptr, "oss", "device", &DefaultPlayback); - ConfigValueStr(nullptr, "oss", "capture", &DefaultCapture); + if(auto devopt = ConfigValueStr(nullptr, "oss", "device")) + DefaultPlayback = std::move(*devopt); + if(auto capopt = ConfigValueStr(nullptr, "oss", "capture")) + DefaultCapture = std::move(*capopt); return true; } diff --git a/Alc/backends/solaris.cpp b/Alc/backends/solaris.cpp index 5c378bff..5c12ad72 100644 --- a/Alc/backends/solaris.cpp +++ b/Alc/backends/solaris.cpp @@ -52,7 +52,7 @@ namespace { constexpr ALCchar solaris_device[] = "Solaris Default"; -const char *solaris_driver = "/dev/audio"; +std::string solaris_driver{"/dev/audio"}; struct SolarisBackend final : public BackendBase { @@ -149,10 +149,10 @@ ALCenum SolarisBackend::open(const ALCchar *name) else if(strcmp(name, solaris_device) != 0) return ALC_INVALID_VALUE; - mFd = ::open(solaris_driver, O_WRONLY); + mFd = ::open(solaris_driver.c_str(), O_WRONLY); if(mFd == -1) { - ERR("Could not open %s: %s\n", solaris_driver, strerror(errno)); + ERR("Could not open %s: %s\n", solaris_driver.c_str(), strerror(errno)); return ALC_INVALID_VALUE; } @@ -267,7 +267,8 @@ BackendFactory &SolarisBackendFactory::getFactory() bool SolarisBackendFactory::init() { - ConfigValueStr(nullptr, "solaris", "device", &solaris_driver); + if(auto devopt = ConfigValueStr(nullptr, "solaris", "device")) + solaris_driver = std::move(*devopt); return true; } @@ -282,7 +283,7 @@ void SolarisBackendFactory::probe(DevProbe type, std::string *outnames) { #ifdef HAVE_STAT struct stat buf; - if(stat(solaris_driver, &buf) == 0) + if(stat(solaris_driver.c_str(), &buf) == 0) #endif outnames->append(solaris_device, sizeof(solaris_device)); } |