From 46f2544e5f22d8048d667f902c60e9649b1d61d7 Mon Sep 17 00:00:00 2001 From: Robert Wu <85952307+robertwu1@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:03:20 -0700 Subject: [PATCH] update LiveEffect --- include/oboe/FullDuplexStream.h | 7 ++++--- .../LiveEffect/src/main/cpp/LiveEffectEngine.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/include/oboe/FullDuplexStream.h b/include/oboe/FullDuplexStream.h index 1301c4fa1..ba2e7cfcb 100644 --- a/include/oboe/FullDuplexStream.h +++ b/include/oboe/FullDuplexStream.h @@ -41,9 +41,10 @@ namespace oboe { * Caller is responsible for closing both streams. * * Callers should handle error callbacks with setErrorCallback() for the output stream. - * When an error callback occurs for the output stream, Oboe will stopping the output stream. - * The caller is responsible for stopping the input stream. - * The caller should also reopen and restart both streams. + * When an error callback occurs for the output stream, Oboe will stop and close the output stream. + * The caller is responsible for stopping and closing the input stream. + * The caller should also reopen and restart both streams when the error callback is ErrorDisconnect. + * See the LiveEffect sample as an example of this. * */ class FullDuplexStream : public AudioStreamDataCallback { diff --git a/samples/LiveEffect/src/main/cpp/LiveEffectEngine.cpp b/samples/LiveEffect/src/main/cpp/LiveEffectEngine.cpp index 3e6fc0313..140dd3284 100644 --- a/samples/LiveEffect/src/main/cpp/LiveEffectEngine.cpp +++ b/samples/LiveEffect/src/main/cpp/LiveEffectEngine.cpp @@ -235,4 +235,20 @@ void LiveEffectEngine::onErrorAfterClose(oboe::AudioStream *oboeStream, LOGE("%s stream Error after close: %s", oboe::convertToText(oboeStream->getDirection()), oboe::convertToText(error)); + + // Stop the Full Duplex stream. + // Since the error callback occurs only for the output stream, close the input stream. + mFullDuplexPass.stop(); + mFullDuplexPass.setOutputStream(nullptr); + closeStream(mRecordingStream); + mFullDuplexPass.setInputStream(nullptr); + + // Restart the stream if the error is a disconnect. + if (error == oboe::Result::ErrorDisconnected) { + LOGI("Restarting AudioStream"); + oboe::Result result = openStreams(); + if (result == oboe::Result::OK) { + mFullDuplexPass.start(); + } + } }