AudioRecord: Add retrograde detection to timestamps

Test: atest AudioRecordTest
Test: camera record stop/start with debug log
Bug: 147198344
Change-Id: Idd7a0bbd1938073b7b7751595b15e20e54ea3373
gugelfrei
Andy Hung 4 years ago
parent 1cfbd0a8a1
commit 7efe2b8832

@ -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;
}

@ -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:

Loading…
Cancel
Save