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

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

Merge "AudioTimestamp: advance first timestamp time after start if stale" into qt-dev

parents 04a1833e 3b8c633f
Loading
Loading
Loading
Loading
+22 −17
Original line number Diff line number Diff line
@@ -2754,17 +2754,17 @@ status_t AudioTrack::getTimestamp_l(AudioTimestamp& timestamp)
    // Prevent retrograde motion in timestamp.
    // This is sometimes caused by erratic reports of the available space in the ALSA drivers.
    if (status == NO_ERROR) {
        // previousTimestampValid is set to false when starting after a stop or flush.
        if (previousTimestampValid) {
            const int64_t previousTimeNanos =
                    audio_utils_ns_from_timespec(&mPreviousTimestamp.mTime);
            int64_t currentTimeNanos = audio_utils_ns_from_timespec(&timestamp.mTime);

        // Fix stale time when checking timestamp right after start().
        // The position is at the last reported location but the time can be stale
        // due to pause or standby or cold start latency.
        //
        // We keep advancing the time (but not the position) to ensure that the
        // stale value does not confuse the application.
        //
        // For offload compatibility, use a default lag value here.
        // Any time discrepancy between this update and the pause timestamp is handled
        // by the retrograde check afterwards.
        int64_t currentTimeNanos = audio_utils_ns_from_timespec(&timestamp.mTime);
        const int64_t lagNs = int64_t(mAfLatency * 1000000LL);
        const int64_t limitNs = mStartNs - lagNs;
        if (currentTimeNanos < limitNs) {
@@ -2776,6 +2776,11 @@ status_t AudioTrack::getTimestamp_l(AudioTimestamp& timestamp)
            currentTimeNanos = limitNs;
        }

        // previousTimestampValid is set to false when starting after a stop or flush.
        if (previousTimestampValid) {
            const int64_t previousTimeNanos =
                    audio_utils_ns_from_timespec(&mPreviousTimestamp.mTime);

            // retrograde check
            if (currentTimeNanos < previousTimeNanos) {
                ALOGW("%s(%d): retrograde timestamp time corrected, %lld < %lld",