Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c377ef1 authored by Phil Burk's avatar Phil Burk
Browse files

aaudio: allow start when flushing

The state switch in the start() code did not allow
a start when in AAUDIO_STREAM_STATE_FLUSHING.

The bug was a regression in R and was not in Q.

Bug: 158603375
Bug: 159900922
Test: test_various.cpp
Test: atest CtsNativeMediaAAudioTestCases
Change-Id: I742a9d3d07d445c0f3a80187b5a32cda5c700e82
parent 29112a13
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ aaudio_result_t AudioStream::systemStart() {
        case AAUDIO_STREAM_STATE_PAUSED:
        case AAUDIO_STREAM_STATE_STOPPING:
        case AAUDIO_STREAM_STATE_STOPPED:
        case AAUDIO_STREAM_STATE_FLUSHING:
        case AAUDIO_STREAM_STATE_FLUSHED:
            break; // Proceed with starting.

+6 −2
Original line number Diff line number Diff line
@@ -345,13 +345,17 @@ aaudio_result_t AudioStreamRecord::requestStart()
    // Enable callback before starting AudioRecord to avoid shutting
    // down because of a race condition.
    mCallbackEnabled.store(true);
    aaudio_stream_state_t originalState = getState();
    // Set before starting the callback so that we are in the correct state
    // before updateStateMachine() can be called by the callback.
    setState(AAUDIO_STREAM_STATE_STARTING);
    mFramesWritten.reset32(); // service writes frames
    mTimestampPosition.reset32();
    status_t err = mAudioRecord->start(); // resets position to zero
    if (err != OK) {
        mCallbackEnabled.store(false);
        setState(originalState);
        return AAudioConvert_androidToAAudioResult(err);
    } else {
        setState(AAUDIO_STREAM_STATE_STARTING);
    }
    return AAUDIO_OK;
}
+6 −2
Original line number Diff line number Diff line
@@ -307,11 +307,15 @@ aaudio_result_t AudioStreamTrack::requestStart() {
    // Enable callback before starting AudioTrack to avoid shutting
    // down because of a race condition.
    mCallbackEnabled.store(true);
    aaudio_stream_state_t originalState = getState();
    // Set before starting the callback so that we are in the correct state
    // before updateStateMachine() can be called by the callback.
    setState(AAUDIO_STREAM_STATE_STARTING);
    err = mAudioTrack->start();
    if (err != OK) {
        mCallbackEnabled.store(false);
        setState(originalState);
        return AAudioConvert_androidToAAudioResult(err);
    } else {
        setState(AAUDIO_STREAM_STATE_STARTING);
    }
    return AAUDIO_OK;
}