diff options
author | Chris Robinson <[email protected]> | 2021-10-21 05:54:03 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-10-21 05:54:03 -0700 |
commit | e70f3e97b3d4d149fb5b9a5473660d99d6d9e352 (patch) | |
tree | ad2136f299cb4b17279b6f90109a4a09ab3b32ae /alc/backends | |
parent | ed3e40c22d3bc0ea2dca4e0967588e7edf80b859 (diff) |
Remove the last external uses of GetConfigValue
Diffstat (limited to 'alc/backends')
-rw-r--r-- | alc/backends/alsa.cpp | 65 | ||||
-rw-r--r-- | alc/backends/wave.cpp | 10 |
2 files changed, 41 insertions, 34 deletions
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 3deeddad..0ad84692 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -262,29 +262,36 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) snd_pcm_info_t *pcminfo; snd_pcm_info_malloc(&pcminfo); - devlist.emplace_back(DevMap{alsaDevice, - GetConfigValue(nullptr, "alsa", (stream==SND_PCM_STREAM_PLAYBACK) ? "device" : "capture", - "default")}); + auto defname = ConfigValueStr(nullptr, "alsa", + (stream == SND_PCM_STREAM_PLAYBACK) ? "device" : "capture"); + devlist.emplace_back(DevMap{alsaDevice, defname ? defname->c_str() : "default"}); - const char *customdevs{GetConfigValue(nullptr, "alsa", - (stream == SND_PCM_STREAM_PLAYBACK) ? "custom-devices" : "custom-captures", "")}; - while(const char *curdev{customdevs}) + if(auto customdevs = ConfigValueStr(nullptr, "alsa", + (stream == SND_PCM_STREAM_PLAYBACK) ? "custom-devices" : "custom-captures")) { - if(!curdev[0]) break; - customdevs = strchr(curdev, ';'); - const char *sep{strchr(curdev, '=')}; - if(!sep) + size_t nextpos{customdevs->find_first_not_of(';')}; + size_t curpos; + while((curpos=nextpos) < customdevs->length()) { - std::string spec{customdevs ? std::string(curdev, customdevs++) : std::string(curdev)}; - ERR("Invalid ALSA device specification \"%s\"\n", spec.c_str()); - continue; - } + nextpos = customdevs->find_first_of(';', curpos+1); + + size_t seppos{customdevs->find_first_of('=', curpos)}; + if(seppos == curpos || seppos >= nextpos) + { + std::string spec{customdevs->substr(curpos, nextpos-curpos)}; + ERR("Invalid ALSA device specification \"%s\"\n", spec.c_str()); + } + else + { + devlist.emplace_back(DevMap{customdevs->substr(curpos, seppos-curpos), + customdevs->substr(seppos+1, nextpos-seppos-1)}); + const auto &entry = devlist.back(); + TRACE("Got device \"%s\", \"%s\"\n", entry.name.c_str(), entry.device_name.c_str()); + } - const char *oldsep{sep++}; - devlist.emplace_back(DevMap{std::string(curdev, oldsep), - customdevs ? std::string(sep, customdevs++) : std::string(sep)}); - const auto &entry = devlist.back(); - TRACE("Got device \"%s\", \"%s\"\n", entry.name.c_str(), entry.device_name.c_str()); + if(nextpos < customdevs->length()) + nextpos = customdevs->find_first_not_of(';', nextpos+1); + } } const std::string main_prefix{ @@ -616,16 +623,15 @@ int AlsaPlayback::mixerNoMMapProc() void AlsaPlayback::open(const char *name) { - const char *driver{}; + al::optional<std::string> driveropt; + const char *driver{"default"}; if(name) { if(PlaybackDevices.empty()) PlaybackDevices = probe_devices(SND_PCM_STREAM_PLAYBACK); auto iter = std::find_if(PlaybackDevices.cbegin(), PlaybackDevices.cend(), - [name](const DevMap &entry) -> bool - { return entry.name == name; } - ); + [name](const DevMap &entry) -> bool { return entry.name == name; }); if(iter == PlaybackDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", name}; @@ -634,7 +640,8 @@ void AlsaPlayback::open(const char *name) else { name = alsaDevice; - driver = GetConfigValue(nullptr, "alsa", "device", "default"); + if(bool{driveropt = ConfigValueStr(nullptr, "alsa", "device")}) + driver = driveropt->c_str(); } TRACE("Opening device \"%s\"\n", driver); @@ -889,16 +896,15 @@ AlsaCapture::~AlsaCapture() void AlsaCapture::open(const char *name) { - const char *driver{}; + al::optional<std::string> driveropt; + const char *driver{"default"}; if(name) { if(CaptureDevices.empty()) CaptureDevices = probe_devices(SND_PCM_STREAM_CAPTURE); auto iter = std::find_if(CaptureDevices.cbegin(), CaptureDevices.cend(), - [name](const DevMap &entry) -> bool - { return entry.name == name; } - ); + [name](const DevMap &entry) -> bool { return entry.name == name; }); if(iter == CaptureDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", name}; @@ -907,7 +913,8 @@ void AlsaCapture::open(const char *name) else { name = alsaDevice; - driver = GetConfigValue(nullptr, "alsa", "capture", "default"); + if(bool{driveropt = ConfigValueStr(nullptr, "alsa", "capture")}) + driver = driveropt->c_str(); } TRACE("Opening device \"%s\"\n", driver); diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index b0ead591..db3d1151 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -203,8 +203,8 @@ int WaveBackend::mixerProc() void WaveBackend::open(const char *name) { - const char *fname{GetConfigValue(nullptr, "wave", "file", "")}; - if(!fname[0]) throw al::backend_exception{al::backend_error::NoDevice, + auto fname = ConfigValueStr(nullptr, "wave", "file"); + if(!fname) throw al::backend_exception{al::backend_error::NoDevice, "No wave output filename"}; if(!name) @@ -218,15 +218,15 @@ void WaveBackend::open(const char *name) #ifdef _WIN32 { - std::wstring wname{utf8_to_wstr(fname)}; + std::wstring wname{utf8_to_wstr(fname->c_str())}; mFile = _wfopen(wname.c_str(), L"wb"); } #else - mFile = fopen(fname, "wb"); + mFile = fopen(fname->c_str(), "wb"); #endif if(!mFile) throw al::backend_exception{al::backend_error::DeviceError, "Could not open file '%s': %s", - fname, strerror(errno)}; + fname->c_str(), strerror(errno)}; mDevice->DeviceName = name; } |