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

Commit d5b638fe authored by Andy Hung's avatar Andy Hung
Browse files

RecordThread: Immediate retry on audio read overrun

Otherwise another sleep and FastCapture write can cause overrun again.

Test: Force OVERRUN fifo error and AudioRecordTest still passes.
Bug: 26983118
Change-Id: I039e3a42863cbe96ca84d0f03020b836d5c944d1
parent 0926bb01
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -6603,8 +6603,17 @@ reacquire_wakelock:
        if (mPipeSource != 0) {
            size_t framesToRead = mBufferSize / mFrameSize;
            framesToRead = min(mRsmpInFramesOA - rear, mRsmpInFramesP2 / 2);

            // The audio fifo read() returns OVERRUN on overflow, and advances the read pointer
            // to the full buffer point (clearing the overflow condition).  Upon OVERRUN error,
            // we immediately retry the read() to get data and prevent another overflow.
            for (int retries = 0; retries <= 2; ++retries) {
                ALOGW_IF(retries > 0, "overrun on read from pipe, retry #%d", retries);
                framesRead = mPipeSource->read((uint8_t*)mRsmpInBuffer + rear * mFrameSize,
                        framesToRead);
                if (framesRead != OVERRUN) break;
            }

            // since pipe is non-blocking, simulate blocking input by waiting for 1/2 of
            // buffer size or at least for 20ms.
            size_t sleepFrames = max(