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
diff --git a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
index ac927ae..3badb0b 100644
--- a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
@@ -258,14 +258,20 @@
             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;