Skip to content

Commit 565c35c

Browse files
committed
aaudio: Notify state thread on errors.
1 parent 8322b43 commit 565c35c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/cubeb_aaudio.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ aaudio_duplex_data_cb(AAudioStream * astream, void * user_data,
889889
reinitialize_stream(stm);
890890
} else {
891891
stm->state.store(stream_state::ERROR);
892+
stm->context->state.waiting.store(true);
893+
stm->context->state.cond.notify_one();
892894
}
893895
LOG("AAudioStream_read: %s",
894896
WRAP(AAudio_convertResultToText)(in_num_frames));
@@ -924,6 +926,8 @@ aaudio_duplex_data_cb(AAudioStream * astream, void * user_data,
924926
if (done_frames < 0 || done_frames > num_frames) {
925927
LOG("Error in data callback or resampler: %ld", done_frames);
926928
stm->state.store(stream_state::ERROR);
929+
stm->context->state.waiting.store(true);
930+
stm->context->state.cond.notify_one();
927931
return AAUDIO_CALLBACK_RESULT_STOP;
928932
}
929933
if (done_frames < num_frames) {
@@ -975,6 +979,8 @@ aaudio_output_data_cb(AAudioStream * astream, void * user_data,
975979
if (done_frames < 0 || done_frames > num_frames) {
976980
LOG("Error in data callback or resampler: %ld", done_frames);
977981
stm->state.store(stream_state::ERROR);
982+
stm->context->state.waiting.store(true);
983+
stm->context->state.cond.notify_one();
978984
return AAUDIO_CALLBACK_RESULT_STOP;
979985
}
980986

@@ -1028,6 +1034,8 @@ aaudio_input_data_cb(AAudioStream * astream, void * user_data,
10281034
if (done_frames < 0 || done_frames > num_frames) {
10291035
LOG("Error in data callback or resampler: %ld", done_frames);
10301036
stm->state.store(stream_state::ERROR);
1037+
stm->context->state.waiting.store(true);
1038+
stm->context->state.cond.notify_one();
10311039
return AAUDIO_CALLBACK_RESULT_STOP;
10321040
}
10331041

@@ -1082,6 +1090,8 @@ reinitialize_stream(cubeb_stream * stm)
10821090
LOG("aaudio_stream_init_impl error while reiniting: %s",
10831091
WRAP(AAudio_convertResultToText)(err));
10841092
stm->state.store(stream_state::ERROR);
1093+
stm->context->state.waiting.store(true);
1094+
stm->context->state.cond.notify_one();
10851095
return;
10861096
}
10871097

@@ -1093,6 +1103,8 @@ reinitialize_stream(cubeb_stream * stm)
10931103
LOG("aaudio_stream_start error while reiniting: %s",
10941104
WRAP(AAudio_convertResultToText)(err));
10951105
stm->state.store(stream_state::ERROR);
1106+
stm->context->state.waiting.store(true);
1107+
stm->context->state.cond.notify_one();
10961108
return;
10971109
}
10981110
}
@@ -1114,6 +1126,8 @@ aaudio_error_cb(AAudioStream * astream, void * user_data, aaudio_result_t error)
11141126

11151127
LOG("AAudio error callback: %s", WRAP(AAudio_convertResultToText)(error));
11161128
stm->state.store(stream_state::ERROR);
1129+
stm->context->state.waiting.store(true);
1130+
stm->context->state.cond.notify_one();
11171131
}
11181132

11191133
static int
@@ -1619,10 +1633,12 @@ aaudio_stream_start_locked(cubeb_stream * stm, lock_guard<mutex> & lock)
16191633

16201634
if (success) {
16211635
stm->pos_estimate.start(now_ns());
1622-
stm->context->state.waiting.store(true);
1623-
stm->context->state.cond.notify_one();
16241636
}
16251637

1638+
// Wake the state thread to trigger STARTED/ERROR state callback.
1639+
stm->context->state.waiting.store(true);
1640+
stm->context->state.cond.notify_one();
1641+
16261642
return ret;
16271643
}
16281644

0 commit comments

Comments
 (0)