diff options
author | Chris Robinson <[email protected]> | 2020-04-28 19:25:58 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-04-28 19:25:58 -0700 |
commit | 4094135ed7e7d1f2c22cf944094f7f0daf2cd8e6 (patch) | |
tree | 4ab7df9fb3afb2554fbe4c48e522263fb7e2d670 /alc/backends | |
parent | 065775d814a972bfedf2cc8e5db35a56f1eecb93 (diff) |
Don't return a bool from the backend start method
Diffstat (limited to 'alc/backends')
-rw-r--r-- | alc/backends/alsa.cpp | 21 | ||||
-rw-r--r-- | alc/backends/base.h | 2 | ||||
-rw-r--r-- | alc/backends/coreaudio.cpp | 22 | ||||
-rw-r--r-- | alc/backends/dsound.cpp | 24 | ||||
-rw-r--r-- | alc/backends/jack.cpp | 23 | ||||
-rw-r--r-- | alc/backends/loopback.cpp | 6 | ||||
-rw-r--r-- | alc/backends/null.cpp | 11 | ||||
-rw-r--r-- | alc/backends/oboe.cpp | 7 | ||||
-rw-r--r-- | alc/backends/opensl.cpp | 35 | ||||
-rw-r--r-- | alc/backends/oss.cpp | 22 | ||||
-rw-r--r-- | alc/backends/portaudio.cpp | 28 | ||||
-rw-r--r-- | alc/backends/pulseaudio.cpp | 10 | ||||
-rw-r--r-- | alc/backends/sdl2.cpp | 9 | ||||
-rw-r--r-- | alc/backends/sndio.cpp | 36 | ||||
-rw-r--r-- | alc/backends/solaris.cpp | 11 | ||||
-rw-r--r-- | alc/backends/wasapi.cpp | 18 | ||||
-rw-r--r-- | alc/backends/wave.cpp | 11 | ||||
-rw-r--r-- | alc/backends/winmm.cpp | 22 |
18 files changed, 120 insertions, 198 deletions
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 689649dc..993a4d2e 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -418,7 +418,7 @@ struct AlsaPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; ClockLatency getClockLatency() override; @@ -792,7 +792,7 @@ bool AlsaPlayback::reset() return true; } -bool AlsaPlayback::start() +void AlsaPlayback::start() { int err{}; snd_pcm_access_t access{}; @@ -818,23 +818,19 @@ bool AlsaPlayback::start() { err = snd_pcm_prepare(mPcmHandle); if(err < 0) - { - ERR("snd_pcm_prepare(data->mPcmHandle) failed: %s\n", snd_strerror(err)); - return false; - } + throw al::backend_exception{ALC_INVALID_DEVICE, + "snd_pcm_prepare(data->mPcmHandle) failed: %s", snd_strerror(err)}; thread_func = &AlsaPlayback::mixerProc; } try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(thread_func), this}; - return true; } catch(std::exception& e) { - ERR("Could not create playback thread: %s\n", e.what()); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - mBuffer.clear(); - return false; } void AlsaPlayback::stop() @@ -871,7 +867,7 @@ struct AlsaCapture final : public BackendBase { ~AlsaCapture() override; void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -995,7 +991,7 @@ void AlsaCapture::open(const ALCchar *name) } -bool AlsaCapture::start() +void AlsaCapture::start() { int err{snd_pcm_prepare(mPcmHandle)}; if(err < 0) @@ -1008,7 +1004,6 @@ bool AlsaCapture::start() snd_strerror(err)}; mDoCapture = true; - return true; } void AlsaCapture::stop() diff --git a/alc/backends/base.h b/alc/backends/base.h index db9b2296..91a494e2 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -22,7 +22,7 @@ struct BackendBase { virtual void open(const ALCchar *name) = 0; virtual bool reset(); - virtual bool start() = 0; + virtual void start() = 0; virtual void stop() = 0; virtual ALCenum captureSamples(al::byte *buffer, ALCuint samples); diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index df889439..12a8cec4 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -61,7 +61,7 @@ struct CoreAudioPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; AudioUnit mAudioUnit{}; @@ -269,15 +269,11 @@ bool CoreAudioPlayback::reset() return true; } -bool CoreAudioPlayback::start() +void CoreAudioPlayback::start() { - OSStatus err{AudioOutputUnitStart(mAudioUnit)}; + const OSStatus err{AudioOutputUnitStart(mAudioUnit)}; if(err != noErr) - { - ERR("AudioOutputUnitStart failed\n"); - return false; - } - return true; + throw al::backend_exception{ALC_INVALID_DEVICE, "AudioOutputUnitStart failed: %d", err}; } void CoreAudioPlayback::stop() @@ -304,7 +300,7 @@ struct CoreAudioCapture final : public BackendBase { } void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -576,15 +572,11 @@ void CoreAudioCapture::open(const ALCchar *name) } -bool CoreAudioCapture::start() +void CoreAudioCapture::start() { OSStatus err{AudioOutputUnitStart(mAudioUnit)}; if(err != noErr) - { - ERR("AudioOutputUnitStart failed\n"); - return false; - } - return true; + throw al::backend_exception{ALC_INVALID_DEVICE, "AudioOutputUnitStart failed: %d", err}; } void CoreAudioCapture::stop() diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 68b63a50..24fba98c 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -169,7 +169,7 @@ struct DSoundPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; IDirectSound *mDS{nullptr}; @@ -563,19 +563,16 @@ retry_open: return true; } -bool DSoundPlayback::start() +void DSoundPlayback::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&DSoundPlayback::mixerProc), this}; - return true; } catch(std::exception& e) { - ERR("Failed to start mixing thread: %s\n", e.what()); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - catch(...) { - } - return false; } void DSoundPlayback::stop() @@ -593,7 +590,7 @@ struct DSoundCapture final : public BackendBase { ~DSoundCapture() override; void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -762,16 +759,11 @@ void DSoundCapture::open(const ALCchar *name) mDevice->DeviceName = name; } -bool DSoundCapture::start() +void DSoundCapture::start() { - HRESULT hr{mDSCbuffer->Start(DSCBSTART_LOOPING)}; + const HRESULT hr{mDSCbuffer->Start(DSCBSTART_LOOPING)}; if(FAILED(hr)) - { - ERR("start failed: 0x%08lx\n", hr); - aluHandleDisconnect(mDevice, "Failure starting capture: 0x%lx", hr); - return false; - } - return true; + throw al::backend_exception{ALC_INVALID_DEVICE, "Failure starting capture: 0x%lx", hr}; } void DSoundCapture::stop() diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index a8d54f88..547bf66f 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -163,7 +163,7 @@ struct JackPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; ClockLatency getClockLatency() override; @@ -380,21 +380,17 @@ bool JackPlayback::reset() return true; } -bool JackPlayback::start() +void JackPlayback::start() { if(jack_activate(mClient)) - { - ERR("Failed to activate client\n"); - return false; - } + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to activate client"}; const char **ports{jack_get_ports(mClient, nullptr, nullptr, JackPortIsPhysical|JackPortIsInput)}; if(ports == nullptr) { - ERR("No physical playback ports found\n"); jack_deactivate(mClient); - return false; + throw al::backend_exception{ALC_INVALID_DEVICE, "No physical playback ports found"}; } std::mismatch(std::begin(mPort), std::end(mPort), ports, [this](const jack_port_t *port, const char *pname) -> bool @@ -432,16 +428,13 @@ bool JackPlayback::start() mPlaying.store(true, std::memory_order_release); mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&JackPlayback::mixerProc), this}; - return true; } catch(std::exception& e) { - ERR("Could not create playback thread: %s\n", e.what()); - } - catch(...) { + jack_deactivate(mClient); + mPlaying.store(false, std::memory_order_release); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - jack_deactivate(mClient); - mPlaying.store(false, std::memory_order_release); - return false; } void JackPlayback::stop() diff --git a/alc/backends/loopback.cpp b/alc/backends/loopback.cpp index 071d095d..bee026c8 100644 --- a/alc/backends/loopback.cpp +++ b/alc/backends/loopback.cpp @@ -33,7 +33,7 @@ struct LoopbackBackend final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; DEF_NEWDEL(LoopbackBackend) @@ -51,8 +51,8 @@ bool LoopbackBackend::reset() return true; } -bool LoopbackBackend::start() -{ return true; } +void LoopbackBackend::start() +{ } void LoopbackBackend::stop() { } diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index 8692e513..3df75378 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -54,7 +54,7 @@ struct NullBackend final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; std::atomic<bool> mKillNow{true}; @@ -123,19 +123,16 @@ bool NullBackend::reset() return true; } -bool NullBackend::start() +void NullBackend::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&NullBackend::mixerProc), this}; - return true; } catch(std::exception& e) { - ERR("Failed to start mixing thread: %s\n", e.what()); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - catch(...) { - } - return false; } void NullBackend::stop() diff --git a/alc/backends/oboe.cpp b/alc/backends/oboe.cpp index 04bb9cf4..d884a0af 100644 --- a/alc/backends/oboe.cpp +++ b/alc/backends/oboe.cpp @@ -27,7 +27,7 @@ struct OboePlayback final : public BackendBase, public oboe::AudioStreamCallback void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; }; @@ -199,13 +199,12 @@ bool OboePlayback::reset() return true; } -bool OboePlayback::start() +void OboePlayback::start() { - oboe::Result result{mStream->start()}; + const oboe::Result result{mStream->start()}; if(result != oboe::Result::OK) throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start stream: %s", oboe::convertToText(result)}; - return true; } void OboePlayback::stop() diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 83054121..944437c6 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -155,7 +155,7 @@ struct OpenSLPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; ClockLatency getClockLatency() override; @@ -540,7 +540,7 @@ bool OpenSLPlayback::reset() return true; } -bool OpenSLPlayback::start() +void OpenSLPlayback::start() { mRing->reset(); @@ -548,24 +548,23 @@ bool OpenSLPlayback::start() SLresult result{VCALL(mBufferQueueObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue)}; PRINTERR(result, "bufferQueue->GetInterface"); + if(SL_RESULT_SUCCESS == result) + { + result = VCALL(bufferQueue,RegisterCallback)(&OpenSLPlayback::processC, this); + PRINTERR(result, "bufferQueue->RegisterCallback"); + } if(SL_RESULT_SUCCESS != result) - return false; - - result = VCALL(bufferQueue,RegisterCallback)(&OpenSLPlayback::processC, this); - PRINTERR(result, "bufferQueue->RegisterCallback"); - if(SL_RESULT_SUCCESS != result) return false; + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to register callback: 0x%08x", + result}; try { mKillNow.store(false, std::memory_order_release); mThread = std::thread(std::mem_fn(&OpenSLPlayback::mixerProc), this); - return true; } catch(std::exception& e) { - ERR("Could not create playback thread: %s\n", e.what()); - } - catch(...) { + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - return false; } void OpenSLPlayback::stop() @@ -631,7 +630,7 @@ struct OpenSLCapture final : public BackendBase { { static_cast<OpenSLCapture*>(context)->process(bq); } void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -837,7 +836,7 @@ void OpenSLCapture::open(const ALCchar* name) mDevice->DeviceName = name; } -bool OpenSLCapture::start() +void OpenSLCapture::start() { SLRecordItf record; SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_RECORD, &record)}; @@ -848,14 +847,8 @@ bool OpenSLCapture::start() result = VCALL(record,SetRecordState)(SL_RECORDSTATE_RECORDING); PRINTERR(result, "record->SetRecordState"); } - if(SL_RESULT_SUCCESS != result) - { - aluHandleDisconnect(mDevice, "Failed to start capture: 0x%08x", result); - return false; - } - - return true; + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start capture: 0x%08x", result}; } void OpenSLCapture::stop() diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 2176078a..cb3c0adb 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -251,7 +251,7 @@ struct OSSPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; int mFd{-1}; @@ -432,19 +432,16 @@ bool OSSPlayback::reset() return true; } -bool OSSPlayback::start() +void OSSPlayback::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&OSSPlayback::mixerProc), this}; - return true; } catch(std::exception& e) { - ERR("Could not create playback thread: %s\n", e.what()); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - catch(...) { - } - return false; } void OSSPlayback::stop() @@ -465,7 +462,7 @@ struct OSScapture final : public BackendBase { int recordProc(); void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -614,19 +611,16 @@ void OSScapture::open(const ALCchar *name) mDevice->DeviceName = name; } -bool OSScapture::start() +void OSScapture::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&OSScapture::recordProc), this}; - return true; } catch(std::exception& e) { - ERR("Could not create record thread: %s\n", e.what()); - } - catch(...) { + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start recording thread: %s", + e.what()}; } - return false; } void OSScapture::stop() diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 1ea2c7d0..ac63bcb7 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -88,7 +88,7 @@ struct PortPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; PaStream *mStream{nullptr}; @@ -209,15 +209,12 @@ bool PortPlayback::reset() return true; } -bool PortPlayback::start() +void PortPlayback::start() { - PaError err{Pa_StartStream(mStream)}; - if(err != paNoError) - { - ERR("Pa_StartStream() returned an error: %s\n", Pa_GetErrorText(err)); - return false; - } - return true; + const PaError err{Pa_StartStream(mStream)}; + if(err == paNoError) + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start playback: %s", + Pa_GetErrorText(err)}; } void PortPlayback::stop() @@ -243,7 +240,7 @@ struct PortCapture final : public BackendBase { } void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -326,15 +323,12 @@ void PortCapture::open(const ALCchar *name) } -bool PortCapture::start() +void PortCapture::start() { - PaError err{Pa_StartStream(mStream)}; + const PaError err{Pa_StartStream(mStream)}; if(err != paNoError) - { - ERR("Error starting stream: %s\n", Pa_GetErrorText(err)); - return false; - } - return true; + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start recording: %s", + Pa_GetErrorText(err)}; } void PortCapture::stop() diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 9ca178c1..8ebea1d9 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -714,7 +714,7 @@ struct PulsePlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; ClockLatency getClockLatency() override; @@ -1047,7 +1047,7 @@ bool PulsePlayback::reset() return true; } -bool PulsePlayback::start() +void PulsePlayback::start() { auto plock = mMainloop.getUniqueLock(); @@ -1080,7 +1080,6 @@ bool PulsePlayback::start() } mMainloop.waitForOperation(op, plock); - return true; } void PulsePlayback::stop() @@ -1142,7 +1141,7 @@ struct PulseCapture final : public BackendBase { { static_cast<PulseCapture*>(pdata)->streamMovedCallback(stream); } void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -1308,13 +1307,12 @@ void PulseCapture::open(const ALCchar *name) } } -bool PulseCapture::start() +void PulseCapture::start() { auto plock = mMainloop.getUniqueLock(); pa_operation *op{pa_stream_cork(mStream, 0, &PulseMainloop::streamSuccessCallbackC, &mMainloop)}; mMainloop.waitForOperation(op, plock); - return true; } void PulseCapture::stop() diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index b47ff185..df6e56b1 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -58,7 +58,7 @@ struct Sdl2Backend final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; SDL_AudioDeviceID mDeviceID{0u}; @@ -170,11 +170,8 @@ bool Sdl2Backend::reset() return true; } -bool Sdl2Backend::start() -{ - SDL_PauseAudioDevice(mDeviceID, 0); - return true; -} +void Sdl2Backend::start() +{ SDL_PauseAudioDevice(mDeviceID, 0); } void Sdl2Backend::stop() { SDL_PauseAudioDevice(mDeviceID, 1); } diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 73948a82..d34a0144 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -53,7 +53,7 @@ struct SndioPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; sio_hdl *mSndHandle{nullptr}; @@ -207,26 +207,20 @@ bool SndioPlayback::reset() return true; } -bool SndioPlayback::start() +void SndioPlayback::start() { if(!sio_start(mSndHandle)) - { - ERR("Error starting playback\n"); - return false; - } + throw al::backend_exception{ALC_INVALID_DEVICE, "Error starting playback"}; try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&SndioPlayback::mixerProc), this}; - return true; } catch(std::exception& e) { - ERR("Could not create playback thread: %s\n", e.what()); - } - catch(...) { + sio_stop(mSndHandle); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - sio_stop(mSndHandle); - return false; } void SndioPlayback::stop() @@ -247,7 +241,7 @@ struct SndioCapture final : public BackendBase { int recordProc(); void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -398,26 +392,20 @@ void SndioCapture::open(const ALCchar *name) mDevice->DeviceName = name; } -bool SndioCapture::start() +void SndioCapture::start() { if(!sio_start(mSndHandle)) - { - ERR("Error starting playback\n"); - return false; - } + throw al::backend_exception{ALC_INVALID_DEVICE, "Error starting capture"}; try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&SndioCapture::recordProc), this}; - return true; } catch(std::exception& e) { - ERR("Could not create record thread: %s\n", e.what()); - } - catch(...) { + sio_stop(mSndHandle); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - sio_stop(mSndHandle); - return false; } void SndioCapture::stop() diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 6f058a16..8309d442 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -65,7 +65,7 @@ struct SolarisBackend final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; int mFd{-1}; @@ -228,19 +228,16 @@ bool SolarisBackend::reset() return true; } -bool SolarisBackend::start() +void SolarisBackend::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&SolarisBackend::mixerProc), this}; - return true; } catch(std::exception& e) { - ERR("Could not create playback thread: %s\n", e.what()); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - catch(...) { - } - return false; } void SolarisBackend::stop() diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index cf2b7e17..0d2a6dad 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -641,7 +641,7 @@ struct WasapiPlayback final : public BackendBase, WasapiProxy { bool reset() override; HRESULT resetProxy() override; - bool start() override; + void start() override; HRESULT startProxy() override; void stop() override; void stopProxy() override; @@ -1108,10 +1108,11 @@ HRESULT WasapiPlayback::resetProxy() } -bool WasapiPlayback::start() +void WasapiPlayback::start() { - HRESULT hr{pushMessage(MsgType::StartDevice).get()}; - return SUCCEEDED(hr) ? true : false; + const HRESULT hr{pushMessage(MsgType::StartDevice).get()}; + if(FAILED(hr)) + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start playback: 0x%lx", hr}; } HRESULT WasapiPlayback::startProxy() @@ -1190,7 +1191,7 @@ struct WasapiCapture final : public BackendBase, WasapiProxy { void closeProxy() override; HRESULT resetProxy() override; - bool start() override; + void start() override; HRESULT startProxy() override; void stop() override; void stopProxy() override; @@ -1650,10 +1651,11 @@ HRESULT WasapiCapture::resetProxy() } -bool WasapiCapture::start() +void WasapiCapture::start() { - HRESULT hr{pushMessage(MsgType::StartDevice).get()}; - return SUCCEEDED(hr) ? true : false; + const HRESULT hr{pushMessage(MsgType::StartDevice).get()}; + if(FAILED(hr)) + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start recording: 0x%lx", hr}; } HRESULT WasapiCapture::startProxy() diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 813be401..a10044de 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -99,7 +99,7 @@ struct WaveBackend final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; FILE *mFile{nullptr}; @@ -332,19 +332,16 @@ bool WaveBackend::reset() return true; } -bool WaveBackend::start() +void WaveBackend::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&WaveBackend::mixerProc), this}; - return true; } catch(std::exception& e) { - ERR("Failed to start mixing thread: %s\n", e.what()); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - catch(...) { - } - return false; } void WaveBackend::stop() diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index ec382522..3bf0a198 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -136,7 +136,7 @@ struct WinMMPlayback final : public BackendBase { void open(const ALCchar *name) override; bool reset() override; - bool start() override; + void start() override; void stop() override; std::atomic<ALuint> mWritable{0u}; @@ -323,7 +323,7 @@ bool WinMMPlayback::reset() return true; } -bool WinMMPlayback::start() +void WinMMPlayback::start() { try { std::for_each(mWaveBuffer.begin(), mWaveBuffer.end(), @@ -334,14 +334,11 @@ bool WinMMPlayback::start() mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&WinMMPlayback::mixerProc), this}; - return true; } catch(std::exception& e) { - ERR("Failed to start mixing thread: %s\n", e.what()); + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start mixing thread: %s", + e.what()}; } - catch(...) { - } - return false; } void WinMMPlayback::stop() @@ -371,7 +368,7 @@ struct WinMMCapture final : public BackendBase { int captureProc(); void open(const ALCchar *name) override; - bool start() override; + void start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; @@ -531,7 +528,7 @@ void WinMMCapture::open(const ALCchar *name) mDevice->DeviceName = CaptureDevices[DeviceID]; } -bool WinMMCapture::start() +void WinMMCapture::start() { try { for(size_t i{0};i < mWaveBuffer.size();++i) @@ -544,14 +541,11 @@ bool WinMMCapture::start() mThread = std::thread{std::mem_fn(&WinMMCapture::captureProc), this}; waveInStart(mInHdl); - return true; } catch(std::exception& e) { - ERR("Failed to start mixing thread: %s\n", e.what()); - } - catch(...) { + throw al::backend_exception{ALC_INVALID_DEVICE, "Failed to start recording thread: %s", + e.what()}; } - return false; } void WinMMCapture::stop() |