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

Commit 88074c7d authored by Andy Hung's avatar Andy Hung Committed by android-build-merger
Browse files

Merge "AudioFlinger: Properly account for underruns" into qt-dev

am: 377cc84d

Change-Id: Iaeea128e9e7f1d8269326faaf7fad0c3b7da0081
parents 598a5324 377cc84d
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -3277,6 +3277,7 @@ bool AudioFlinger::PlaybackThread::threadLoop()

        Vector< sp<EffectChain> > effectChains;
        audio_session_t activeHapticSessionId = AUDIO_SESSION_NONE;
        std::vector<sp<Track>> activeTracks;

        // If the device is AUDIO_DEVICE_OUT_BUS, check for downstream latency.
        //
@@ -3563,6 +3564,12 @@ bool AudioFlinger::PlaybackThread::threadLoop()
                }
            }

            // Acquire a local copy of active tracks with lock (release w/o lock).
            //
            // Control methods on the track acquire the ThreadBase lock (e.g. start()
            // stop(), pause(), etc.), but the threadLoop is entitled to call audio
            // data / buffer methods on tracks from activeTracks without the ThreadBase lock.
            activeTracks.insert(activeTracks.end(), mActiveTracks.begin(), mActiveTracks.end());
        } // mLock scope ends

        if (mBytesRemaining == 0) {
@@ -3577,6 +3584,13 @@ bool AudioFlinger::PlaybackThread::threadLoop()
                threadLoop_sleepTime();
                if (mSleepTimeUs == 0) {
                    mCurrentWriteLength = mSinkBufferSize;

                    // Tally underrun frames as we are inserting 0s here.
                    for (const auto& track : activeTracks) {
                        if (track->mFillingUpStatus == Track::FS_ACTIVE) {
                            track->mAudioTrackServerProxy->tallyUnderrunFrames(mNormalFrameCount);
                        }
                    }
                }
            }
            // Either threadLoop_mix() or threadLoop_sleepTime() should have set