aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends/opensl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alc/backends/opensl.cpp')
-rw-r--r--alc/backends/opensl.cpp50
1 files changed, 26 insertions, 24 deletions
diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp
index f5b98fb8..61e3c9a7 100644
--- a/alc/backends/opensl.cpp
+++ b/alc/backends/opensl.cpp
@@ -26,20 +26,22 @@
#include <stdlib.h>
#include <jni.h>
-#include <new>
#include <array>
#include <cstring>
+#include <mutex>
+#include <new>
#include <thread>
#include <functional>
#include "albit.h"
#include "alnumeric.h"
+#include "alsem.h"
+#include "althrd_setname.h"
#include "core/device.h"
#include "core/helpers.h"
#include "core/logging.h"
#include "opthelpers.h"
#include "ringbuffer.h"
-#include "threads.h"
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
@@ -159,12 +161,10 @@ struct OpenSLPlayback final : public BackendBase {
~OpenSLPlayback() override;
void process(SLAndroidSimpleBufferQueueItf bq) noexcept;
- static void processC(SLAndroidSimpleBufferQueueItf bq, void *context) noexcept
- { static_cast<OpenSLPlayback*>(context)->process(bq); }
int mixerProc();
- void open(const char *name) override;
+ void open(std::string_view name) override;
bool reset() override;
void start() override;
void stop() override;
@@ -312,13 +312,13 @@ int OpenSLPlayback::mixerProc()
}
-void OpenSLPlayback::open(const char *name)
+void OpenSLPlayback::open(std::string_view name)
{
- if(!name)
+ if(name.empty())
name = opensl_device;
- else if(strcmp(name, opensl_device) != 0)
- throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found",
- name};
+ else if(name != opensl_device)
+ throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found",
+ static_cast<int>(name.length()), name.data()};
/* There's only one device, so if it's already open, there's nothing to do. */
if(mEngineObj) return;
@@ -564,7 +564,9 @@ void OpenSLPlayback::start()
PrintErr(result, "bufferQueue->GetInterface");
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(bufferQueue,RegisterCallback)(&OpenSLPlayback::processC, this);
+ result = VCALL(bufferQueue,RegisterCallback)(
+ [](SLAndroidSimpleBufferQueueItf bq, void *context) noexcept
+ { static_cast<OpenSLPlayback*>(context)->process(bq); }, this);
PrintErr(result, "bufferQueue->RegisterCallback");
}
if(SL_RESULT_SUCCESS != result)
@@ -642,13 +644,11 @@ struct OpenSLCapture final : public BackendBase {
~OpenSLCapture() override;
void process(SLAndroidSimpleBufferQueueItf bq) noexcept;
- static void processC(SLAndroidSimpleBufferQueueItf bq, void *context) noexcept
- { static_cast<OpenSLCapture*>(context)->process(bq); }
- void open(const char *name) override;
+ void open(std::string_view name) override;
void start() override;
void stop() override;
- void captureSamples(al::byte *buffer, uint samples) override;
+ void captureSamples(std::byte *buffer, uint samples) override;
uint availableSamples() override;
/* engine interfaces */
@@ -686,13 +686,13 @@ void OpenSLCapture::process(SLAndroidSimpleBufferQueueItf) noexcept
}
-void OpenSLCapture::open(const char* name)
+void OpenSLCapture::open(std::string_view name)
{
- if(!name)
+ if(name.empty())
name = opensl_device;
- else if(strcmp(name, opensl_device) != 0)
- throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found",
- name};
+ else if(name != opensl_device)
+ throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found",
+ static_cast<int>(name.length()), name.data()};
SLresult result{slCreateEngine(&mEngineObj, 0, nullptr, 0, nullptr, nullptr)};
PrintErr(result, "slCreateEngine");
@@ -813,13 +813,15 @@ void OpenSLCapture::open(const char* name)
}
if(SL_RESULT_SUCCESS == result)
{
- result = VCALL(bufferQueue,RegisterCallback)(&OpenSLCapture::processC, this);
+ result = VCALL(bufferQueue,RegisterCallback)(
+ [](SLAndroidSimpleBufferQueueItf bq, void *context) noexcept
+ { static_cast<OpenSLCapture*>(context)->process(bq); }, this);
PrintErr(result, "bufferQueue->RegisterCallback");
}
if(SL_RESULT_SUCCESS == result)
{
const uint chunk_size{mDevice->UpdateSize * mFrameSize};
- const auto silence = (mDevice->FmtType == DevFmtUByte) ? al::byte{0x80} : al::byte{0};
+ const auto silence = (mDevice->FmtType == DevFmtUByte) ? std::byte{0x80} : std::byte{0};
auto data = mRing->getWriteVector();
std::fill_n(data.first.buf, data.first.len*chunk_size, silence);
@@ -883,7 +885,7 @@ void OpenSLCapture::stop()
}
}
-void OpenSLCapture::captureSamples(al::byte *buffer, uint samples)
+void OpenSLCapture::captureSamples(std::byte *buffer, uint samples)
{
const uint update_size{mDevice->UpdateSize};
const uint chunk_size{update_size * mFrameSize};
@@ -932,7 +934,7 @@ void OpenSLCapture::captureSamples(al::byte *buffer, uint samples)
return;
/* For each buffer chunk that was fully read, queue another writable buffer
- * chunk to keep the OpenSL queue full. This is rather convulated, as a
+ * chunk to keep the OpenSL queue full. This is rather convoluted, as a
* result of the ring buffer holding more elements than are writable at a
* given time. The end of the write vector increments when the read pointer
* advances, which will "expose" a previously unwritable element. So for