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

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

audio: fix race when stopping a stream

Stopping a Legacy stream could result in the stream
becoming killed. Then it could not be restarted.

This change results in the stream callback just returning safely.

Bug: 192095564
Test: see bug report
Test: atest CtsNativeMediaAAudioTestCases
Change-Id: I2d58e94bf9e7288b56e750e03188102b383b6479
parent 0d0a5832
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -94,10 +94,15 @@ void AudioStreamLegacy::processCallbackCommon(aaudio_callback_operation_t opcode
            AudioTrack::Buffer *audioBuffer = static_cast<AudioTrack::Buffer *>(info);
            if (getState() == AAUDIO_STREAM_STATE_DISCONNECTED) {
                ALOGW("processCallbackCommon() data, stream disconnected");
                // This will kill the stream and prevent it from being restarted.
                // That is OK because the stream is disconnected.
                audioBuffer->size = SIZE_STOP_CALLBACKS;
            } else if (!mCallbackEnabled.load()) {
                ALOGW("processCallbackCommon() no data because callback disabled");
                audioBuffer->size = SIZE_STOP_CALLBACKS;
                ALOGW("processCallbackCommon() no data because callback disabled, set size=0");
                // Do NOT use SIZE_STOP_CALLBACKS here because that will kill the stream and
                // prevent it from being restarted. This can occur because of a race condition
                // caused by Legacy callbacks running after the track is "stopped".
                audioBuffer->size = 0;
            } else {
                if (audioBuffer->frameCount == 0) {
                    ALOGW("processCallbackCommon() data, frameCount is zero");