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

Commit 4943e65b authored by Eric Laurent's avatar Eric Laurent Committed by Gerrit Code Review
Browse files

Merge "PatchTrack: Ensure enough data to write once"

parents 6861be79 f37f9980
Loading
Loading
Loading
Loading
+19 −0
Original line number Original line Diff line number Diff line
@@ -1872,6 +1872,25 @@ void AudioFlinger::PlaybackThread::PatchTrack::releaseBuffer(Proxy::Buffer* buff
{
{
    mProxy->releaseBuffer(buffer);
    mProxy->releaseBuffer(buffer);
    restartIfDisabled();
    restartIfDisabled();

    // Check if the PatchTrack has enough data to write once in releaseBuffer().
    // If not, prevent an underrun from occurring by moving the track into FS_FILLING;
    // this logic avoids glitches when suspending A2DP with AudioPlaybackCapture.
    // TODO: perhaps underrun avoidance could be a track property checked in isReady() instead.
    if (mFillingUpStatus == FS_ACTIVE
            && audio_is_linear_pcm(mFormat)
            && !isOffloadedOrDirect()) {
        if (sp<ThreadBase> thread = mThread.promote();
            thread != 0) {
            PlaybackThread *playbackThread = (PlaybackThread *)thread.get();
            const size_t frameCount = playbackThread->frameCount() * sampleRate()
                    / playbackThread->sampleRate();
            if (framesReady() < frameCount) {
                ALOGD("%s(%d) Not enough data, wait for buffer to fill", __func__, mId);
                mFillingUpStatus = FS_FILLING;
            }
        }
    }
}
}


void AudioFlinger::PlaybackThread::PatchTrack::restartIfDisabled()
void AudioFlinger::PlaybackThread::PatchTrack::restartIfDisabled()