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

Commit daf7b246 authored by Robert Wu's avatar Robert Wu
Browse files

Fix race condition for stream open

When the stream goes to a weird state during a stream open, don't return
ERROR_OK.

Bug: 193071260
Test: OboeTester works fine
Change-Id: I32932ce9b4782f19455b54b4b121c4c2c683aa36
parent 24e7ab51
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -215,7 +215,6 @@ aaudio_result_t AudioStreamTrack::open(const AudioStreamBuilder& builder)
        mBlockAdapter = nullptr;
    }

    setState(AAUDIO_STREAM_STATE_OPEN);
    setDeviceId(mAudioTrack->getRoutedDeviceId());

    aaudio_session_id_t actualSessionId =
@@ -248,6 +247,19 @@ aaudio_result_t AudioStreamTrack::open(const AudioStreamBuilder& builder)
             "open() perfMode changed from %d to %d",
             perfMode, actualPerformanceMode);

    if (getState() != AAUDIO_STREAM_STATE_UNINITIALIZED) {
        ALOGE("%s - Open canceled since state = %d", __func__, getState());
        if (getState() == AAUDIO_STREAM_STATE_DISCONNECTED)
        {
            ALOGE("%s - Opening while state is disconnected", __func__);
            safeReleaseClose();
            return AAUDIO_ERROR_DISCONNECTED;
        }
        safeReleaseClose();
        return AAUDIO_ERROR_INVALID_STATE;
    }

    setState(AAUDIO_STREAM_STATE_OPEN);
    return AAUDIO_OK;
}