Skip to content

Commit

Permalink
update LiveEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
robertwu1 committed Oct 6, 2023
1 parent 5bc326c commit 46f2544
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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.
* See the LiveEffect sample as an example of this.
*
*/
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();
}
}
}

0 comments on commit 46f2544

Please sign in to comment.