diff options
Diffstat (limited to 'alc')
-rw-r--r-- | alc/backends/alsa.cpp | 3 | ||||
-rw-r--r-- | alc/backends/coreaudio.cpp | 1 | ||||
-rw-r--r-- | alc/backends/dsound.cpp | 3 | ||||
-rw-r--r-- | alc/backends/jack.cpp | 11 | ||||
-rw-r--r-- | alc/backends/opensl.cpp | 21 | ||||
-rw-r--r-- | alc/backends/oss.cpp | 1 | ||||
-rw-r--r-- | alc/backends/portaudio.cpp | 1 | ||||
-rw-r--r-- | alc/backends/sndio.cpp | 1 | ||||
-rw-r--r-- | alc/backends/wasapi.cpp | 5 | ||||
-rw-r--r-- | alc/backends/winmm.cpp | 1 | ||||
-rw-r--r-- | alc/ringbuffer.cpp | 4 |
11 files changed, 8 insertions, 44 deletions
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 7c6ce4f9..91415c32 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -981,10 +981,7 @@ void AlsaCapture::open(const ALCchar *name) hp = nullptr; if(needring) - { mRing = CreateRingBuffer(mDevice->BufferSize, mDevice->frameSizeFromFmt(), false); - if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; - } mDevice->DeviceName = name; return; diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 9e1d4e47..5a0e4027 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -570,7 +570,6 @@ void CoreAudioCapture::open(const ALCchar *name) mDevice->Frequency, Resampler::FastBSinc24); mRing = CreateRingBuffer(outputFrameCount, mFrameSize, false); - if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to allocate ring buffer"}; mDevice->DeviceName = name; } diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 005c9584..b74f2d3e 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -743,10 +743,7 @@ void DSoundCapture::open(const ALCchar *name) if(SUCCEEDED(hr)) mDSC->CreateCaptureBuffer(&DSCBDescription, &mDSCbuffer, nullptr); if(SUCCEEDED(hr)) - { mRing = CreateRingBuffer(mDevice->BufferSize, InputType.Format.nBlockAlign, false); - if(!mRing) hr = DSERR_OUTOFMEMORY; - } if(FAILED(hr)) { diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 2a22ed84..0814ca8d 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -212,11 +212,7 @@ int JackPlayback::bufferSizeNotify(jack_nframes_t numframes) mRing = nullptr; mRing = CreateRingBuffer(bufsize, mDevice->frameSizeFromFmt(), true); - if(!mRing) - { - ERR("Failed to reallocate ringbuffer\n"); - aluHandleDisconnect(mDevice, "Failed to reallocate %u-sample buffer", bufsize); - } + return 0; } @@ -407,11 +403,6 @@ bool JackPlayback::reset() mRing = nullptr; mRing = CreateRingBuffer(bufsize, mDevice->frameSizeFromFmt(), true); - if(!mRing) - { - ERR("Failed to allocate ringbuffer\n"); - return false; - } SetDefaultChannelOrder(mDevice); diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 4e68da27..258443f2 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -521,14 +521,7 @@ bool OpenSLPlayback::reset() if(SL_RESULT_SUCCESS == result) { const ALuint num_updates{mDevice->BufferSize / mDevice->UpdateSize}; - try { - mRing = CreateRingBuffer(num_updates, mFrameSize*mDevice->UpdateSize, true); - } - catch(std::exception& e) { - ERR("Failed allocating ring buffer %ux%ux%u: %s\n", mDevice->UpdateSize, - num_updates, mFrameSize, e.what()); - result = SL_RESULT_MEMORY_FAILURE; - } + mRing = CreateRingBuffer(num_updates, mFrameSize*mDevice->UpdateSize, true); } if(SL_RESULT_SUCCESS != result) @@ -703,16 +696,10 @@ void OpenSLCapture::open(const ALCchar* name) mDevice->Frequency/100*5)}; ALuint num_updates{(length+update_len-1) / update_len}; - try { - mRing = CreateRingBuffer(num_updates, update_len*mFrameSize, false); + mRing = CreateRingBuffer(num_updates, update_len*mFrameSize, false); - mDevice->UpdateSize = update_len; - mDevice->BufferSize = static_cast<ALuint>(mRing->writeSpace() * update_len); - } - catch(std::exception& e) { - ERR("Failed to allocate ring buffer: %s\n", e.what()); - result = SL_RESULT_MEMORY_FAILURE; - } + mDevice->UpdateSize = update_len; + mDevice->BufferSize = static_cast<ALuint>(mRing->writeSpace() * update_len); } if(SL_RESULT_SUCCESS == result) { diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 856aceb0..59cc44e4 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -612,7 +612,6 @@ void OSScapture::open(const ALCchar *name) ossFormat}; mRing = CreateRingBuffer(mDevice->BufferSize, frameSize, false); - if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; mDevice->DeviceName = name; } diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 7c60d2bb..f50f1f16 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -286,7 +286,6 @@ void PortCapture::open(const ALCchar *name) ALuint frame_size{mDevice->frameSizeFromFmt()}; mRing = CreateRingBuffer(samples, frame_size, false); - if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; auto devidopt = ConfigValueInt(nullptr, "port", "capture"); if(devidopt && *devidopt >= 0) mParams.device = *devidopt; diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 026ff2b9..7799316f 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -393,7 +393,6 @@ void SndioCapture::open(const ALCchar *name) mDevice->Frequency, par.sig?'s':'u', par.bits, par.rchan, par.rate}; mRing = CreateRingBuffer(mDevice->BufferSize, par.bps*par.rchan, false); - if(!mRing) throw al::backend_exception{ALC_OUT_OF_MEMORY, "Failed to allocate ring buffer"}; SetDefaultChannelOrder(mDevice); diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 2c4fe130..37a547af 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -1601,11 +1601,6 @@ HRESULT WasapiCapture::resetProxy() buffer_len = maxu(mDevice->BufferSize, buffer_len); mRing = CreateRingBuffer(buffer_len, mDevice->frameSizeFromFmt(), false); - if(!mRing) - { - ERR("Failed to allocate capture ring buffer\n"); - return E_OUTOFMEMORY; - } hr = mClient->SetEventHandle(mNotifyEvent); if(FAILED(hr)) diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index dde74304..c2ccbc05 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -519,7 +519,6 @@ void WinMMCapture::open(const ALCchar *name) CapturedDataSize = static_cast<ALuint>(maxz(CapturedDataSize, BufferSize*mWaveBuffer.size())); mRing = CreateRingBuffer(CapturedDataSize, mFormat.nBlockAlign, false); - if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Could not create ring buffer"}; al_free(mWaveBuffer[0].lpData); mWaveBuffer[0] = WAVEHDR{}; diff --git a/alc/ringbuffer.cpp b/alc/ringbuffer.cpp index d61f6129..1f72f4b1 100644 --- a/alc/ringbuffer.cpp +++ b/alc/ringbuffer.cpp @@ -25,6 +25,7 @@ #include <algorithm> #include <climits> #include <cstdint> +#include <stdexcept> #include "almalloc.h" @@ -45,7 +46,8 @@ RingBufferPtr CreateRingBuffer(size_t sz, size_t elem_sz, int limit_writes) #endif } ++power_of_two; - if(power_of_two < sz) return nullptr; + if(power_of_two <= sz || power_of_two > std::numeric_limits<size_t>::max()/elem_sz) + throw std::overflow_error{"Ring buffer size overflow"}; const size_t bufbytes{power_of_two * elem_sz}; RingBufferPtr rb{new (FamCount{bufbytes}) RingBuffer{bufbytes}}; |