Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Full Duplex Stream to Oboe library #1920

Merged
merged 11 commits into from
Oct 12, 2023
7 changes: 4 additions & 3 deletions include/oboe/FullDuplexStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
robertwu1 marked this conversation as resolved.
Show resolved Hide resolved
* See the LiveEffect sample as an example of this.
*
robertwu1 marked this conversation as resolved.
Show resolved Hide resolved
*/
robertwu1 marked this conversation as resolved.
Show resolved Hide resolved
class FullDuplexStream : public AudioStreamDataCallback {
Expand Down
16 changes: 16 additions & 0 deletions samples/LiveEffect/src/main/cpp/LiveEffectEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}