diff options
author | Chris Robinson <[email protected]> | 2019-10-10 13:33:27 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-10-10 13:33:27 -0700 |
commit | 630d4d573dbe09828cb1b161581207ff53af4b52 (patch) | |
tree | c89539c7df528e68fc52ce4c9aa72aaa0069e66b /alc | |
parent | d2053e678418357faf701acdd49272075f22c1cc (diff) |
Gracefully drain the OpenSL capture buffer on disconnect
Diffstat (limited to 'alc')
-rw-r--r-- | alc/backends/opensl.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 4bba3455..a1fdccc7 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -869,9 +869,18 @@ void OpenSLCapture::stop() ALCenum OpenSLCapture::captureSamples(al::byte *buffer, ALCuint samples) { - SLAndroidSimpleBufferQueueItf bufferQueue; - SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue)}; - PRINTERR(result, "recordObj->GetInterface"); + SLAndroidSimpleBufferQueueItf bufferQueue{}; + if LIKELY(mDevice->Connected.load(std::memory_order_acquire)) + { + const SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, + &bufferQueue)}; + PRINTERR(result, "recordObj->GetInterface"); + if UNLIKELY(SL_RESULT_SUCCESS != result) + { + aluHandleDisconnect(mDevice, "Failed to get capture buffer queue: 0x%08x", result); + bufferQueue = nullptr; + } + } const ALuint update_size{mDevice->UpdateSize}; const ALuint chunk_size{update_size * mFrameSize}; @@ -890,11 +899,19 @@ ALCenum OpenSLCapture::captureSamples(al::byte *buffer, ALCuint samples) { /* Finished a chunk, reset the offset and advance the read pointer. */ mSplOffset = 0; - mRing->readAdvance(1); - result = VCALL(bufferQueue,Enqueue)(data.first.buf, chunk_size); - PRINTERR(result, "bufferQueue->Enqueue"); - if(SL_RESULT_SUCCESS != result) break; + + if LIKELY(bufferQueue) + { + const SLresult result{VCALL(bufferQueue,Enqueue)(data.first.buf, chunk_size)}; + PRINTERR(result, "bufferQueue->Enqueue"); + if UNLIKELY(SL_RESULT_SUCCESS != result) + { + aluHandleDisconnect(mDevice, "Failed to update capture buffer: 0x%08x", + result); + bufferQueue = nullptr; + } + } data.first.len--; if(!data.first.len) @@ -906,12 +923,6 @@ ALCenum OpenSLCapture::captureSamples(al::byte *buffer, ALCuint samples) i += rem; } - if UNLIKELY(SL_RESULT_SUCCESS != result) - { - aluHandleDisconnect(mDevice, "Failed to update capture buffer: 0x%08x", result); - return ALC_INVALID_DEVICE; - } - return ALC_NO_ERROR; } |