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

Commit 0c647585 authored by Phil Burk's avatar Phil Burk Committed by android-build-merger
Browse files

aaudio: fix audioserver crash when starting a stream is rejected

am: b92c988f

Change-Id: I2690a7de357f0964f6f6cc5defb19b27a946d4e4
parents d0a23e61 b92c988f
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) {