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

Commit 0264215f authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "AudioRecord: Add retrograde detection to timestamps" into rvc-dev am:...

Merge "AudioRecord: Add retrograde detection to timestamps" into rvc-dev am: 3e66c387 am: bb3a0a40 am: e65907d0

Change-Id: I9b6f8caf253664af1ea1a7277143385ab9f2699b
parents a4ea63ff e65907d0
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -411,6 +411,9 @@ status_t AudioRecord::start(AudioSystem::sync_event_t event, audio_session_t tri
    mFramesReadServerOffset -= mFramesRead + framesFlushed;
    mFramesRead = 0;
    mProxy->clearTimestamp();  // timestamp is invalid until next server push
    mPreviousTimestamp.clear();
    mTimestampRetrogradePositionReported = false;
    mTimestampRetrogradeTimeReported = false;

    // reset current position as seen by client to 0
    mProxy->setEpoch(mProxy->getEpoch() - mProxy->getPosition());
@@ -600,6 +603,39 @@ status_t AudioRecord::getTimestamp(ExtendedTimestamp *timestamp)
                timestamp->mPosition[i] += mFramesReadServerOffset;
            }
        }

        bool timestampRetrogradeTimeReported = false;
        bool timestampRetrogradePositionReported = false;
        for (int i = 0; i < ExtendedTimestamp::LOCATION_MAX; ++i) {
            if (timestamp->mTimeNs[i] >= 0 && mPreviousTimestamp.mTimeNs[i] >= 0) {
                if (timestamp->mTimeNs[i] < mPreviousTimestamp.mTimeNs[i]) {
                    if (!mTimestampRetrogradeTimeReported) {
                        ALOGD("%s: retrograde time adjusting [%d] current:%lld to previous:%lld",
                                __func__, i, (long long)timestamp->mTimeNs[i],
                                (long long)mPreviousTimestamp.mTimeNs[i]);
                        timestampRetrogradeTimeReported = true;
                    }
                    timestamp->mTimeNs[i] = mPreviousTimestamp.mTimeNs[i];
                }
                if (timestamp->mPosition[i] < mPreviousTimestamp.mPosition[i]) {
                    if (!mTimestampRetrogradePositionReported) {
                        ALOGD("%s: retrograde position"
                                " adjusting [%d] current:%lld to previous:%lld",
                                __func__, i, (long long)timestamp->mPosition[i],
                                (long long)mPreviousTimestamp.mPosition[i]);
                        timestampRetrogradePositionReported = true;
                    }
                    timestamp->mPosition[i] = mPreviousTimestamp.mPosition[i];
                }
            }
        }
        mPreviousTimestamp = *timestamp;
        if (timestampRetrogradeTimeReported) {
            mTimestampRetrogradeTimeReported = true;
        }
        if (timestampRetrogradePositionReported) {
            mTimestampRetrogradePositionReported = true;
        }
    }
    return status;
}
+4 −0
Original line number Diff line number Diff line
@@ -711,6 +711,10 @@ private:

    bool                    mInOverrun;         // whether recorder is currently in overrun state

    ExtendedTimestamp       mPreviousTimestamp{}; // used to detect retrograde motion
    bool                    mTimestampRetrogradePositionReported = false; // reduce log spam
    bool                    mTimestampRetrogradeTimeReported = false;     // reduce log spam

private:
    class DeathNotifier : public IBinder::DeathRecipient {
    public: