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

Commit 196a088e authored by Robert Wu's avatar Robert Wu Committed by Android (Google) Code Review
Browse files

Merge "AAudio: Handle weird callback sizes better" into main

parents 733e7d90 6641f9d4
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;