[AAudio] request pause rather than stop.
Some checks failed
Build / build (macos-13, Debug) (push) Has been cancelled
Build / build (macos-13, Release) (push) Has been cancelled
Build / build (macos-14, Debug) (push) Has been cancelled
Build / build (macos-14, Release) (push) Has been cancelled
Build / build (ubuntu-20.04, Debug) (push) Has been cancelled
Build / build (ubuntu-20.04, Release) (push) Has been cancelled
Build / build (windows-2019, Debug) (push) Has been cancelled
Build / build (windows-2019, Release) (push) Has been cancelled
Build / build-android (arm64-v8a, Debug) (push) Has been cancelled
Build / build-android (arm64-v8a, Release) (push) Has been cancelled
Build / build-android (armeabi-v7a, Debug) (push) Has been cancelled
Build / build-android (armeabi-v7a, Release) (push) Has been cancelled
Build / build-android (x86_64, Debug) (push) Has been cancelled
Build / build-android (x86_64, Release) (push) Has been cancelled
Build / check_format (push) Has been cancelled

According to the document,

 AAudioStream_requestStop():
 "The stream will stop after all of the data currently buffered has been played."

 AAudioStream_requestPause():
 "Pausing a stream will freeze the data flow but not flush any buffers."
This commit is contained in:
John Lin 2024-06-20 19:23:37 -07:00 committed by Paul Adenot
parent 0adfabf98d
commit 063a090221

View file

@ -483,9 +483,7 @@ update_state(cubeb_stream * stm)
} }
// handle invalid stream states // handle invalid stream states
if (istate == AAUDIO_STREAM_STATE_PAUSING || if (istate == AAUDIO_STREAM_STATE_FLUSHING ||
istate == AAUDIO_STREAM_STATE_PAUSED ||
istate == AAUDIO_STREAM_STATE_FLUSHING ||
istate == AAUDIO_STREAM_STATE_FLUSHED || istate == AAUDIO_STREAM_STATE_FLUSHED ||
istate == AAUDIO_STREAM_STATE_UNKNOWN || istate == AAUDIO_STREAM_STATE_UNKNOWN ||
istate == AAUDIO_STREAM_STATE_DISCONNECTED) { istate == AAUDIO_STREAM_STATE_DISCONNECTED) {
@ -495,9 +493,7 @@ update_state(cubeb_stream * stm)
return; return;
} }
if (ostate == AAUDIO_STREAM_STATE_PAUSING || if (ostate == AAUDIO_STREAM_STATE_FLUSHING ||
ostate == AAUDIO_STREAM_STATE_PAUSED ||
ostate == AAUDIO_STREAM_STATE_FLUSHING ||
ostate == AAUDIO_STREAM_STATE_FLUSHED || ostate == AAUDIO_STREAM_STATE_FLUSHED ||
ostate == AAUDIO_STREAM_STATE_UNKNOWN || ostate == AAUDIO_STREAM_STATE_UNKNOWN ||
ostate == AAUDIO_STREAM_STATE_DISCONNECTED) { ostate == AAUDIO_STREAM_STATE_DISCONNECTED) {
@ -556,12 +552,12 @@ update_state(cubeb_stream * stm)
} }
break; break;
case stream_state::STOPPING: case stream_state::STOPPING:
assert(!istate || istate == AAUDIO_STREAM_STATE_STOPPING || assert(!istate || istate == AAUDIO_STREAM_STATE_PAUSING ||
istate == AAUDIO_STREAM_STATE_STOPPED); istate == AAUDIO_STREAM_STATE_PAUSED);
assert(!ostate || ostate == AAUDIO_STREAM_STATE_STOPPING || assert(!ostate || ostate == AAUDIO_STREAM_STATE_PAUSING ||
ostate == AAUDIO_STREAM_STATE_STOPPED); ostate == AAUDIO_STREAM_STATE_PAUSED);
if ((!istate || istate == AAUDIO_STREAM_STATE_STOPPED) && if ((!istate || istate == AAUDIO_STREAM_STATE_PAUSED) &&
(!ostate || ostate == AAUDIO_STREAM_STATE_STOPPED)) { (!ostate || ostate == AAUDIO_STREAM_STATE_PAUSED)) {
stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STOPPED); stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STOPPED);
new_state = stream_state::STOPPED; new_state = stream_state::STOPPED;
} }
@ -1593,16 +1589,16 @@ aaudio_stream_stop_locked(cubeb_stream * stm, lock_guard<mutex> & lock)
aaudio_result_t res; aaudio_result_t res;
// No callbacks are triggered anymore when requestStop returns. // No callbacks are triggered anymore when requestPause returns.
// That is important as we otherwise might read from a closed istream // That is important as we otherwise might read from a closed istream
// for a duplex stream. // for a duplex stream.
// Therefor it is important to close ostream first. // Therefor it is important to close ostream first.
if (stm->ostream) { if (stm->ostream) {
// Could use pause + flush here as well, the public cubeb interface // Could use pause + flush here as well, the public cubeb interface
// doesn't state behavior. // doesn't state behavior.
res = WRAP(AAudioStream_requestStop)(stm->ostream); res = WRAP(AAudioStream_requestPause)(stm->ostream);
if (res != AAUDIO_OK) { if (res != AAUDIO_OK) {
LOG("AAudioStream_requestStop (ostream): %s", LOG("AAudioStream_requestPause (ostream): %s",
WRAP(AAudio_convertResultToText)(res)); WRAP(AAudio_convertResultToText)(res));
stm->state.store(stream_state::ERROR); stm->state.store(stream_state::ERROR);
return CUBEB_ERROR; return CUBEB_ERROR;
@ -1610,9 +1606,9 @@ aaudio_stream_stop_locked(cubeb_stream * stm, lock_guard<mutex> & lock)
} }
if (stm->istream) { if (stm->istream) {
res = WRAP(AAudioStream_requestStop)(stm->istream); res = WRAP(AAudioStream_requestPause)(stm->istream);
if (res != AAUDIO_OK) { if (res != AAUDIO_OK) {
LOG("AAudioStream_requestStop (istream): %s", LOG("AAudioStream_requestPause (istream): %s",
WRAP(AAudio_convertResultToText)(res)); WRAP(AAudio_convertResultToText)(res));
stm->state.store(stream_state::ERROR); stm->state.store(stream_state::ERROR);
return CUBEB_ERROR; return CUBEB_ERROR;