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

Commit b92c988f authored by Phil Burk's avatar Phil Burk
Browse files

aaudio: fix audioserver crash when starting a stream is rejected

Bug: 65738271
Test: repeat when not root:   input_monitor  -m2 -pl
Change-Id: I98659dbd78a75785565b1b6f0254a48220253af6
parent 523b3047
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -115,15 +115,33 @@ aaudio_result_t aaudio::AAudioServiceEndpointShared::stopSharingThread() {
aaudio_result_t AAudioServiceEndpointShared::startStream(sp<AAudioServiceStreamBase> sharedStream,
                                                         audio_port_handle_t *clientHandle) {
    aaudio_result_t result = AAUDIO_OK;
    if (++mRunningStreamCount == 1) {
        // TODO use real-time technique to avoid mutex, eg. atomic command FIFO

    {
        std::lock_guard<std::mutex> lock(mLockStreams);
        if (++mRunningStreamCount == 1) { // atomic
            result = getStreamInternal()->requestStart();
        startSharingThread_l();
            if (result != AAUDIO_OK) {
                --mRunningStreamCount;
            } else {
                result = startSharingThread_l();
                if (result != AAUDIO_OK) {
                    getStreamInternal()->requestStop();
                    --mRunningStreamCount;
                }
            }
        }
    }

    if (result == AAUDIO_OK) {
        result = getStreamInternal()->startClient(sharedStream->getAudioClient(), clientHandle);
        if (result != AAUDIO_OK) {
            if (--mRunningStreamCount == 0) { // atomic
                stopSharingThread();
                getStreamInternal()->requestStop();
            }
        }
    }

    return result;
}

@@ -141,7 +159,6 @@ aaudio_result_t AAudioServiceEndpointShared::stopStream(sp<AAudioServiceStreamBa
    return AAUDIO_OK;
}


// Get timestamp that was written by the real-time service thread, eg. mixer.
aaudio_result_t AAudioServiceEndpointShared::getFreeRunningPosition(int64_t *positionFrames,
                                                                  int64_t *timeNanos) {