Commit 9503b61e authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Wait for AAudio state changes

From certain crash reports, it appears that we are getting calls to
OnAudioDataRequestedCallback() after destroying AAudioOutputStream. This
shouldn't happen, but there might be underlying issues in AAudio.

This CL waits for our AAudio stream to transition to a target state,
before allowing the stream to be destroyed. This means waiting for
STOPPED and CLOSED when stopping and closing.

Change-Id: I0e7fb332a1da9b4709a14b3206503be8434af534
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340061Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796127}
parent 07350bd4
...@@ -26,4 +26,5 @@ aaudio_result_t AAudioStream_close(AAudioStream* stream); ...@@ -26,4 +26,5 @@ aaudio_result_t AAudioStream_close(AAudioStream* stream);
aaudio_result_t AAudioStream_requestStart(AAudioStream* stream); aaudio_result_t AAudioStream_requestStart(AAudioStream* stream);
aaudio_result_t AAudioStream_requestStop(AAudioStream* stream); aaudio_result_t AAudioStream_requestStop(AAudioStream* stream);
aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream, clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds); aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream, clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds);
int64_t AAudioStream_getFramesWritten(AAudioStream* stream); int64_t AAudioStream_getFramesWritten(AAudioStream* stream);
\ No newline at end of file aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream, aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState, int64_t timeoutNanoseconds);
\ No newline at end of file
...@@ -145,14 +145,24 @@ void AAudioOutputStream::Stop() { ...@@ -145,14 +145,24 @@ void AAudioOutputStream::Stop() {
// not always be asynchronous, we don't hold |lock_| while we call stop. // not always be asynchronous, we don't hold |lock_| while we call stop.
auto result = AAudioStream_requestStop(aaudio_stream_); auto result = AAudioStream_requestStop(aaudio_stream_);
base::AutoLock al(lock_); {
if (result != AAUDIO_OK) { base::AutoLock al(lock_);
DLOG(ERROR) << "Failed to stop audio stream, result: " if (result != AAUDIO_OK) {
<< AAudio_convertResultToText(result); DLOG(ERROR) << "Failed to stop audio stream, result: "
callback_->OnError(AudioSourceCallback::ErrorType::kUnknown); << AAudio_convertResultToText(result);
callback_->OnError(AudioSourceCallback::ErrorType::kUnknown);
}
callback_ = nullptr;
} }
callback_ = nullptr; // Wait for AAUDIO_STREAM_STATE_STOPPED, but do not explicitly check for the
// success of this wait.
aaudio_stream_state_t current_state = AAUDIO_STREAM_STATE_STOPPING;
aaudio_stream_state_t next_state = AAUDIO_STREAM_STATE_UNINITIALIZED;
static const int64_t kTimeoutNanoseconds = 1e8;
result = AAudioStream_waitForStateChange(aaudio_stream_, current_state,
&next_state, kTimeoutNanoseconds);
} }
base::TimeDelta AAudioOutputStream::GetDelay(base::TimeTicks delay_timestamp) { base::TimeDelta AAudioOutputStream::GetDelay(base::TimeTicks delay_timestamp) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment