Return direct/offload corrected timestamps
Previously, for direct/offload outputs with timestamp correction
enabled, getTimestamp would not return corrected timestamps, but
only raw HAL timestamps with downstream latency compensation.
To resolve this, run timestamp correction routine in getTimestamp
and return latest kernel timestamps, as threadLoop() timestamps
may be stale for (large buffer) direct/offload outputs.
Also, use timestamp verifier discontinuity new API to fix corrected
timestamps after pause/standby. Direct non-pcm and offload threads
should register timestamp verifier zero discontinuties on standby, but
other threads should register continuous discontinuities. On pause, all
threads should register continuous discontinuity. Update to use new
timestamp verifier API to set the discontinuity type on each
discontinuity event.
Test: Offloaded (eac3) into MSD HAL AudioTrack (corrected) timestamps
Jitter standard deviation reduced.
Change-Id: I28a95c3922165689dfcbd13ab83b35dab8ec6adb
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 709a3cc..9f65562 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -590,6 +590,11 @@
ExtendedTimestamp mTimestamp;
TimestampVerifier< // For timestamp statistics.
int64_t /* frame count */, int64_t /* time ns */> mTimestampVerifier;
+ // DIRECT and OFFLOAD threads should reset frame count to zero on stop/flush
+ // TODO: add confirmation checks:
+ // 1) DIRECT threads and linear PCM format really resets to 0?
+ // 2) Is frame count really valid if not linear pcm?
+ // 3) Are all 64 bits of position returned, not just lowest 32 bits?
// Timestamp corrected device should be a single device.
audio_devices_t mTimestampCorrectedDevice = AUDIO_DEVICE_NONE;
@@ -1023,6 +1028,8 @@
int64_t mBytesWritten;
int64_t mFramesWritten; // not reset on standby
+ int64_t mLastFramesWritten = -1; // track changes in timestamp
+ // server frames written.
int64_t mSuspendedFrames; // not reset on standby
// mHapticChannelMask and mHapticChannelCount will only be valid when the thread support
@@ -1035,6 +1042,14 @@
// copy rather than the one in AudioFlinger. This optimization saves a lock.
bool mMasterMute;
void setMasterMute_l(bool muted) { mMasterMute = muted; }
+
+ auto discontinuityForStandbyOrFlush() const { // call on threadLoop or with lock.
+ return ((mType == DIRECT && !audio_is_linear_pcm(mFormat))
+ || mType == OFFLOAD)
+ ? mTimestampVerifier.DISCONTINUITY_MODE_ZERO
+ : mTimestampVerifier.DISCONTINUITY_MODE_CONTINUOUS;
+ }
+
protected:
ActiveTracks<Track> mActiveTracks;
@@ -1081,6 +1096,8 @@
void updateMetadata_l() final;
virtual void sendMetadataToBackend_l(const StreamOutHalInterface::SourceMetadata& metadata);
+ void collectTimestamps_l();
+
// The Tracks class manages tracks added and removed from the Thread.
template <typename T>
class Tracks {