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

Commit 972a173d authored by Eric Laurent's avatar Eric Laurent
Browse files

audioflinger: longer offload thread standby delay

- Increase offloaded output thread standby delay to 1 second
to allow transition between tracks with going to stanby
if reusing the same audio track (gapless)

- Make sure pause/flush/resume sequence is sent to the HAL
in the right order

- Fix format display in track dump

Bug: 8174034.
Change-Id: I43ef6f8fdbf7427e4eff6cc2d0665d7d1463ea8a
parent 99bf6267
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -109,6 +109,9 @@ static const uint32_t kMinNormalMixBufferSizeMs = 20;
// maximum normal mix buffer size
static const uint32_t kMaxNormalMixBufferSizeMs = 24;

// Offloaded output thread standby delay: allows track transition without going to standby
static const nsecs_t kOffloadStandbyDelayNs = seconds(1);

// Whether to use fast mixer
static const enum {
    FastMixer_Never,    // never initialize or use: for debugging only
@@ -2137,13 +2140,11 @@ bool AudioFlinger::PlaybackThread::threadLoop()
                mWaitWorkCV.wait(mLock);
                ALOGV("async completion/wake");
                acquireWakeLock_l();
                standbyTime = systemTime() + standbyDelay;
                sleepTime = 0;
                if (exitPending()) {
                    break;
                }
                if (!mActiveTracks.size() && (systemTime() > standbyTime)) {
                    continue;
                }
                sleepTime = 0;
            } else if ((!mActiveTracks.size() && systemTime() > standbyTime) ||
                                   isSuspended()) {
                // put audio hardware into standby after short delay
@@ -3701,7 +3702,11 @@ void AudioFlinger::DirectOutputThread::cacheParameters_l()

    // use shorter standby delay as on normal output to release
    // hardware resources as soon as possible
    if (audio_is_linear_pcm(mFormat)) {
        standbyDelay = microseconds(activeSleepTime*2);
    } else {
        standbyDelay = kOffloadStandbyDelayNs;
    }
}

// ----------------------------------------------------------------------------
@@ -3837,6 +3842,9 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::OffloadThread::prepareTr
    size_t count = mActiveTracks.size();

    mixer_state mixerStatus = MIXER_IDLE;
    bool doHwPause = false;
    bool doHwResume = false;

    // find out which tracks need to be processed
    for (size_t i = 0; i < count; i++) {
        sp<Track> t = mActiveTracks[i].promote();
@@ -3868,7 +3876,7 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::OffloadThread::prepareTr
            track->setPaused();
            if (last) {
                if (!mHwPaused) {
                    mOutput->stream->pause(mOutput->stream);
                    doHwPause = true;
                    mHwPaused = true;
                }
                // If we were part way through writing the mixbuffer to
@@ -3901,7 +3909,7 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::OffloadThread::prepareTr

            if (last) {
                if (mHwPaused) {
                    mOutput->stream->resume(mOutput->stream);
                    doHwResume = true;
                    mHwPaused = false;
                    // threadLoop_mix() will handle the case that we need to
                    // resume an interrupted write
@@ -3963,10 +3971,17 @@ AudioFlinger::PlaybackThread::mixer_state AudioFlinger::OffloadThread::prepareTr
        processVolume_l(track, last);
    }

    // make sure the pause/flush/resume sequence is executed in the right order
    if (doHwPause) {
        mOutput->stream->pause(mOutput->stream);
    }
    if (mFlushPending) {
        flushHw_l();
        mFlushPending = false;
    }
    if (doHwResume) {
        mOutput->stream->resume(mOutput->stream);
    }

    // remove all the tracks that need to be...
    removeTracks_l(*tracksToRemove);
+2 −2
Original line number Diff line number Diff line
@@ -467,7 +467,7 @@ void AudioFlinger::PlaybackThread::Track::dump(char* buffer, size_t size)
        nowInUnderrun = '?';
        break;
    }
    snprintf(&buffer[7], size-7, " %6u %4u %3u %08X %7u %6u %1c %1d %5u %5.2g %5.2g  "
    snprintf(&buffer[7], size-7, " %6u %4u %08X %08X %7u %6u %1c %1d %5u %5.2g %5.2g  "
                                 "%08X %08X %08X 0x%03X %9u%c\n",
            (mClient == 0) ? getpid_cached : mClient->pid(),
            mStreamType,