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

Commit eebc3ad4 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "audioflinger: fix offload underrun sleep logic" into nyc-dev

parents 7c6a1621 3eaf66b8
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -3162,12 +3162,14 @@ bool AudioFlinger::PlaybackThread::threadLoop()
                if ((mType == OFFLOAD) && !audio_has_proportional_frames(mFormat)) {
                    Mutex::Autolock _l(mLock);
                    if (!mSignalPending && !exitPending()) {
                        // Do not sleep more than one buffer duration since last write and not
                        // less than kDirectMinSleepTimeUs
                        // If more than one buffer has been written to the audio HAL since exiting
                        // standby or last flush, do not sleep more than one buffer duration
                        // since last write and not less than kDirectMinSleepTimeUs.
                        // Wake up if a command is received
                        uint32_t timeoutUs = mSleepTimeUs;
                        if (mBytesWritten >= (int64_t) mBufferSize) {
                            nsecs_t now = systemTime();
                            uint32_t deltaUs = (uint32_t)((now - mLastWriteTime) / 1000);
                        uint32_t timeoutUs = mSleepTimeUs;
                            if (timeoutUs + deltaUs > mBufferDurationUs) {
                                if (mBufferDurationUs > deltaUs) {
                                    timeoutUs = mBufferDurationUs - deltaUs;
@@ -3178,6 +3180,7 @@ bool AudioFlinger::PlaybackThread::threadLoop()
                                    timeoutUs = kDirectMinSleepTimeUs;
                                }
                            }
                        }
                        mWaitWorkCV.waitRelative(mLock, microseconds((nsecs_t)timeoutUs));
                    }
                } else {
@@ -5418,6 +5421,8 @@ void AudioFlinger::OffloadThread::flushHw_l()
    mBytesRemaining = 0;
    mPausedWriteLength = 0;
    mPausedBytesRemaining = 0;
    // reset bytes written count to reflect that DSP buffers are empty after flush.
    mBytesWritten = 0;

    if (mUseAsyncWrite) {
        // discard any pending drain or write ack by incrementing sequence