Skip to content

Commit

Permalink
[AAudio] request pause rather than stop.
Browse files Browse the repository at this point in the history
 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."
  • Loading branch information
jhlin authored and padenot committed Jul 8, 2024
1 parent 0adfabf commit 063a090
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/cubeb_aaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,7 @@ update_state(cubeb_stream * stm)
}

// handle invalid stream states
if (istate == AAUDIO_STREAM_STATE_PAUSING ||
istate == AAUDIO_STREAM_STATE_PAUSED ||
istate == AAUDIO_STREAM_STATE_FLUSHING ||
if (istate == AAUDIO_STREAM_STATE_FLUSHING ||
istate == AAUDIO_STREAM_STATE_FLUSHED ||
istate == AAUDIO_STREAM_STATE_UNKNOWN ||
istate == AAUDIO_STREAM_STATE_DISCONNECTED) {
Expand All @@ -495,9 +493,7 @@ update_state(cubeb_stream * stm)
return;
}

if (ostate == AAUDIO_STREAM_STATE_PAUSING ||
ostate == AAUDIO_STREAM_STATE_PAUSED ||
ostate == AAUDIO_STREAM_STATE_FLUSHING ||
if (ostate == AAUDIO_STREAM_STATE_FLUSHING ||
ostate == AAUDIO_STREAM_STATE_FLUSHED ||
ostate == AAUDIO_STREAM_STATE_UNKNOWN ||
ostate == AAUDIO_STREAM_STATE_DISCONNECTED) {
Expand Down Expand Up @@ -556,12 +552,12 @@ update_state(cubeb_stream * stm)
}
break;
case stream_state::STOPPING:
assert(!istate || istate == AAUDIO_STREAM_STATE_STOPPING ||
istate == AAUDIO_STREAM_STATE_STOPPED);
assert(!ostate || ostate == AAUDIO_STREAM_STATE_STOPPING ||
ostate == AAUDIO_STREAM_STATE_STOPPED);
if ((!istate || istate == AAUDIO_STREAM_STATE_STOPPED) &&
(!ostate || ostate == AAUDIO_STREAM_STATE_STOPPED)) {
assert(!istate || istate == AAUDIO_STREAM_STATE_PAUSING ||
istate == AAUDIO_STREAM_STATE_PAUSED);
assert(!ostate || ostate == AAUDIO_STREAM_STATE_PAUSING ||
ostate == AAUDIO_STREAM_STATE_PAUSED);
if ((!istate || istate == AAUDIO_STREAM_STATE_PAUSED) &&
(!ostate || ostate == AAUDIO_STREAM_STATE_PAUSED)) {
stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STOPPED);
new_state = stream_state::STOPPED;
}
Expand Down Expand Up @@ -1593,26 +1589,26 @@ aaudio_stream_stop_locked(cubeb_stream * stm, lock_guard<mutex> & lock)

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
// for a duplex stream.
// Therefor it is important to close ostream first.
if (stm->ostream) {
// Could use pause + flush here as well, the public cubeb interface
// doesn't state behavior.
res = WRAP(AAudioStream_requestStop)(stm->ostream);
res = WRAP(AAudioStream_requestPause)(stm->ostream);
if (res != AAUDIO_OK) {
LOG("AAudioStream_requestStop (ostream): %s",
LOG("AAudioStream_requestPause (ostream): %s",
WRAP(AAudio_convertResultToText)(res));
stm->state.store(stream_state::ERROR);
return CUBEB_ERROR;
}
}

if (stm->istream) {
res = WRAP(AAudioStream_requestStop)(stm->istream);
res = WRAP(AAudioStream_requestPause)(stm->istream);
if (res != AAUDIO_OK) {
LOG("AAudioStream_requestStop (istream): %s",
LOG("AAudioStream_requestPause (istream): %s",
WRAP(AAudio_convertResultToText)(res));
stm->state.store(stream_state::ERROR);
return CUBEB_ERROR;
Expand Down

0 comments on commit 063a090

Please sign in to comment.