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

Commit 762365c3 authored by Phil Burk's avatar Phil Burk
Browse files

aaudio: suspend a stream when its queue is full

This will prevent log spam when AAUDIO_CALLBACK_RESULT_STOP
is returned from an audio callback.

Bug: 120845500
Test: test_return_stop.cpp
Change-Id: Icfe1541d6fa7b045285ac3dfbb75dfed5424d49b
parent d00c4607
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -258,7 +258,7 @@ void *AudioStreamInternalCapture::callbackLoop() {
        callbackResult = maybeCallDataCallback(mCallbackBuffer, mCallbackFrames);

        if (callbackResult == AAUDIO_CALLBACK_RESULT_STOP) {
            ALOGD("callback returned AAUDIO_CALLBACK_RESULT_STOP");
            ALOGD("%s(): callback returned AAUDIO_CALLBACK_RESULT_STOP", __func__);
            break;
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ void *AudioStreamInternalPlay::callbackLoop() {
                break;
            }
        } else if (callbackResult == AAUDIO_CALLBACK_RESULT_STOP) {
            ALOGV("%s(): callback returned AAUDIO_CALLBACK_RESULT_STOP", __func__);
            ALOGD("%s(): callback returned AAUDIO_CALLBACK_RESULT_STOP", __func__);
            break;
        }
    }
+2 −1
Original line number Diff line number Diff line
@@ -82,8 +82,9 @@ void *AAudioServiceEndpointCapture::callbackLoop() {

            std::lock_guard <std::mutex> lock(mLockStreams);
            for (const auto& clientStream : mRegisteredStreams) {
                if (clientStream->isRunning()) {
                if (clientStream->isRunning() && !clientStream->isSuspended()) {
                    int64_t clientFramesWritten = 0;

                    sp<AAudioServiceStreamShared> streamShared =
                            static_cast<AAudioServiceStreamShared *>(clientStream.get());

+4 −0
Original line number Diff line number Diff line
@@ -84,6 +84,10 @@ void *AAudioServiceEndpointPlay::callbackLoop() {
                int64_t clientFramesRead = 0;
                bool allowUnderflow = true;

                if (clientStream->isSuspended()) {
                    continue; // dead stream
                }

                aaudio_stream_state_t state = clientStream->getState();
                if (state == AAUDIO_STREAM_STATE_STOPPING) {
                    allowUnderflow = false; // just read what is already in the FIFO
+4 −1
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ aaudio_result_t AAudioServiceStreamBase::start() {
    }

    setFlowing(false);
    setSuspended(false);

    // Start with fresh presentation timestamps.
    mAtomicTimestamp.clear();
@@ -345,7 +346,9 @@ aaudio_result_t AAudioServiceStreamBase::writeUpMessageQueue(AAudioServiceMessag
    }
    int32_t count = mUpMessageQueue->getFifoBuffer()->write(command, 1);
    if (count != 1) {
        ALOGE("%s(): Queue full. Did client die? %s", __func__, getTypeText());
        ALOGW("%s(): Queue full. Did client stop? Suspending stream. what = %u, %s",
              __func__, command->what, getTypeText());
        setSuspended(true);
        return AAUDIO_ERROR_WOULD_BLOCK;
    } else {
        return AAUDIO_OK;
Loading