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

Commit d85c6127 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "AudioFlinger: Add latency measurements from timestamp"

parents f4d3741b f6ab58df
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -538,6 +538,10 @@ public:
        mTimestampMutator.push(timestamp);
    }

    virtual ExtendedTimestamp getTimestamp() const {
        return mTimestampMutator.last();
    }

    // Flushes the shared ring buffer if the client had requested it using mStreaming.mFlush.
    // If flush occurs then:
    //   cblk->u.mStreaming.mFront, ServerProxy::mFlush and ServerProxy::mFlushed will be modified
+15 −0
Original line number Diff line number Diff line
@@ -135,6 +135,21 @@ struct alignas(8) /* bug 29096183, bug 29108507 */ ExtendedTimestamp {
        return INVALID_OPERATION;
    }

    double getOutputServerLatencyMs(uint32_t sampleRate) const {
        return getLatencyMs(sampleRate, LOCATION_SERVER, LOCATION_KERNEL);
    }

    double getLatencyMs(uint32_t sampleRate, Location location1, Location location2) const {
        if (mTimeNs[location1] > 0 && mTimeNs[location2] > 0) {
            const int64_t frameDifference =
                    mPosition[location1] - mPosition[location2];
            const int64_t timeDifferenceNs =
                    mTimeNs[location1] - mTimeNs[location2];
            return ((double)frameDifference * 1e9 / sampleRate - timeDifferenceNs) * 1e-6;
        }
        return 0.;
    }

    // convert fields to a printable string
    std::string toString() {
        std::stringstream ss;
+4 −0
Original line number Diff line number Diff line
@@ -489,6 +489,10 @@ void FastMixer::onWork()
                        timestamp.mPosition[ExtendedTimestamp::LOCATION_KERNEL];
                mTimestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL] =
                        timestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL];
                // We don't compensate for server - kernel time difference and
                // only update latency if we have valid info.
                dumpState->mLatencyMs =
                        (double)mNativeFramesWrittenButNotPresented * 1000 / mSampleRate;
            } else {
                // HAL reported that more frames were presented than were written
                mNativeFramesWrittenButNotPresented = 0;
+2 −2
Original line number Diff line number Diff line
@@ -68,11 +68,11 @@ void FastMixerDumpState::dump(int fd) const
    dprintf(fd, "  FastMixer command=%s writeSequence=%u framesWritten=%u\n"
                "            numTracks=%u writeErrors=%u underruns=%u overruns=%u\n"
                "            sampleRate=%u frameCount=%zu measuredWarmup=%.3g ms, warmupCycles=%u\n"
                "            mixPeriod=%.2f ms\n",
                "            mixPeriod=%.2f ms latency=%.2f ms\n",
                FastMixerState::commandToString(mCommand), mWriteSequence, mFramesWritten,
                mNumTracks, mWriteErrors, mUnderruns, mOverruns,
                mSampleRate, mFrameCount, measuredWarmupMs, mWarmupCycles,
                mixPeriodSec * 1e3);
                mixPeriodSec * 1e3, mLatencyMs);
#ifdef FAST_THREAD_STATISTICS
    // find the interval of valid samples
    uint32_t bounds = mBounds;
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ struct FastMixerDumpState : FastThreadDumpState {

    void dump(int fd) const;    // should only be called on a stable copy, not the original

    double   mLatencyMs = 0.;   // measured latency, default of 0 if no valid timestamp read.
    uint32_t mWriteSequence;    // incremented before and after each write()
    uint32_t mFramesWritten;    // total number of frames written successfully
    uint32_t mNumTracks;        // total number of active fast tracks
Loading