aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends/oboe.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alc/backends/oboe.cpp')
-rw-r--r--alc/backends/oboe.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/alc/backends/oboe.cpp b/alc/backends/oboe.cpp
index 461f5a6a..b7bab19a 100644
--- a/alc/backends/oboe.cpp
+++ b/alc/backends/oboe.cpp
@@ -28,7 +28,9 @@ struct OboePlayback final : public BackendBase, public oboe::AudioStreamCallback
oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboeStream, void *audioData,
int32_t numFrames) override;
- void open(const char *name) override;
+ void onErrorAfterClose(oboe::AudioStream* /* audioStream */, oboe::Result /* error */) override;
+
+ void open(std::string_view name) override;
bool reset() override;
void start() override;
void stop() override;
@@ -46,14 +48,21 @@ oboe::DataCallbackResult OboePlayback::onAudioReady(oboe::AudioStream *oboeStrea
return oboe::DataCallbackResult::Continue;
}
+void OboePlayback::onErrorAfterClose(oboe::AudioStream* audioStream, oboe::Result error)
+{
+ if (error == oboe::Result::ErrorDisconnected) {
+ mDevice->handleDisconnect("Oboe AudioStream was disconnected: %s", oboe::convertToText(error));
+ }
+ TRACE("Error was %s", oboe::convertToText(error));
+}
-void OboePlayback::open(const char *name)
+void OboePlayback::open(std::string_view name)
{
- if(!name)
+ if(name.empty())
name = device_name;
- else if(std::strcmp(name, device_name) != 0)
- throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found",
- name};
+ else if(name != device_name)
+ throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found",
+ static_cast<int>(name.length()), name.data()};
/* Open a basic output stream, just to ensure it can work. */
oboe::ManagedStream stream;
@@ -197,8 +206,7 @@ void OboePlayback::stop()
{
oboe::Result result{mStream->stop()};
if(result != oboe::Result::OK)
- throw al::backend_exception{al::backend_error::DeviceError, "Failed to stop stream: %s",
- oboe::convertToText(result)};
+ ERR("Failed to stop stream: %s\n", oboe::convertToText(result));
}
@@ -212,10 +220,10 @@ struct OboeCapture final : public BackendBase, public oboe::AudioStreamCallback
oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboeStream, void *audioData,
int32_t numFrames) override;
- 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;
};
@@ -227,13 +235,13 @@ oboe::DataCallbackResult OboeCapture::onAudioReady(oboe::AudioStream*, void *aud
}
-void OboeCapture::open(const char *name)
+void OboeCapture::open(std::string_view name)
{
- if(!name)
+ if(name.empty())
name = device_name;
- else if(std::strcmp(name, device_name) != 0)
- throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found",
- name};
+ else if(name != device_name)
+ throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found",
+ static_cast<int>(name.length()), name.data()};
oboe::AudioStreamBuilder builder;
builder.setDirection(oboe::Direction::Input)
@@ -315,14 +323,13 @@ void OboeCapture::stop()
{
const oboe::Result result{mStream->stop()};
if(result != oboe::Result::OK)
- throw al::backend_exception{al::backend_error::DeviceError, "Failed to stop stream: %s",
- oboe::convertToText(result)};
+ ERR("Failed to stop stream: %s\n", oboe::convertToText(result));
}
uint OboeCapture::availableSamples()
{ return static_cast<uint>(mRing->readSpace()); }
-void OboeCapture::captureSamples(al::byte *buffer, uint samples)
+void OboeCapture::captureSamples(std::byte *buffer, uint samples)
{ mRing->read(buffer, samples); }
} // namespace