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

Commit 6641f9d4 authored by Robert Wu's avatar Robert Wu
Browse files

AAudio: Handle weird callback sizes better

For a callback size of 7, AAudio output streams often glitch.

This happens when the wrapping buffer is almost empty. In these cases,
AAudio should be careful and put only one frame at a time.

This CL also adds some breaks to mimic the code before a SRC was added
to AAudio.

Bug: 310282314
Test: OboeTester Test Output
Change-Id: I2c2106a4727bcb3d880883b7ac494fea26fe7d96
parent 32d319ba
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -214,6 +214,8 @@ aaudio_result_t AudioStreamInternalCapture::readNowWithConversion(void *buffer,
        int32_t framesAvailableInWrappingBuffer = totalFramesInWrappingBuffer;
        uint8_t *currentWrappingBuffer = (uint8_t *) wrappingBuffer.data[partIndex];

        if (framesAvailableInWrappingBuffer <= 0) break;

        // Put data from the wrapping buffer into the flowgraph 8 frames at a time.
        // Continuously pull as much data as possible from the flowgraph into the byte buffer.
        // The return value of mFlowGraph.process is the number of frames actually pulled.
+7 −1
Original line number Diff line number Diff line
@@ -258,14 +258,20 @@ aaudio_result_t AudioStreamInternalPlay::writeNowWithConversion(const void *buff
            currentWrappingBuffer += numBytesActuallyWrittenToWrappingBuffer;
            framesAvailableInWrappingBuffer -= framesActuallyWrittenToWrappingBuffer;
            framesWrittenToAudioEndpoint += framesActuallyWrittenToWrappingBuffer;
        } else {
            break;
        }

        // Put data from byteBuffer into the flowgraph one buffer (8 frames) at a time.
        // Continuously pull as much data as possible from the flowgraph into the wrapping buffer.
        // The return value of mFlowGraph.process is the number of frames actually pulled.
        while (framesAvailableInWrappingBuffer > 0 && framesLeftInByteBuffer > 0) {
            const int32_t framesToWriteFromByteBuffer = std::min(flowgraph::kDefaultBufferSize,
            int32_t framesToWriteFromByteBuffer = std::min(flowgraph::kDefaultBufferSize,
                    framesLeftInByteBuffer);
            // If the wrapping buffer is running low, write one frame at a time.
            if (framesAvailableInWrappingBuffer < flowgraph::kDefaultBufferSize) {
                framesToWriteFromByteBuffer = 1;
            }

            const int32_t numBytesToWriteFromByteBuffer = getBytesPerFrame() *
                    framesToWriteFromByteBuffer;