Fix race condition for non-started fast tracks
This required re-implementing how fast tracks are considered active.
Now, they use the same logic as normal tracks, except underrun is ignored.
Other changes:
- add framesReady() to AudioBufferProvider interface
- rebased
- add track underrun counter state to fast mixer dump state
- move dumpsys header to Track::appendDumpHeader()
so it closer to where tracks are dumped
- display track state in dumpsys as a character code
- measure and display warmup time and cycles in dumpsys
- copy in the presentation complete code
- add ExtendedAudioBufferProvider for framesReady() which returns size_t
- simplify underrun tracking
- deferred reset track after stop()
- add comments
Change-Id: I7db8821bc565230ec76da1f9380fe3fb09735e5b
diff --git a/services/audioflinger/FastMixer.h b/services/audioflinger/FastMixer.h
index 8a8fcb8..a6dd310 100644
--- a/services/audioflinger/FastMixer.h
+++ b/services/audioflinger/FastMixer.h
@@ -42,8 +42,23 @@
}; // class FastMixer
+// Represents the dump state of a fast track
+struct FastTrackDump {
+ FastTrackDump() : mUnderruns(0) { }
+ /*virtual*/ ~FastTrackDump() { }
+ uint32_t mUnderruns; // Underrun status, represented as follows:
+ // bit 0 == 0 means not currently in underrun
+ // bit 0 == 1 means currently in underrun
+ // bits 1 to 31 == total number of underruns
+ // Not reset to zero for new tracks or if track generation changes.
+ // This representation is used to keep the information atomic.
+};
+
// The FastMixerDumpState keeps a cache of FastMixer statistics that can be logged by dumpsys.
-// Since used non-atomically, only POD types are permitted, and the contents can't be trusted.
+// Each individual native word-sized field is accessed atomically. But the
+// overall structure is non-atomic, that is there may be an inconsistency between fields.
+// No barriers or locks are used for either writing or reading.
+// Only POD types are permitted, and the contents shouldn't be trusted (i.e. do range checks).
// It has a different lifetime than the FastMixer, and so it can't be a member of FastMixer.
struct FastMixerDumpState {
FastMixerDumpState();
@@ -60,6 +75,9 @@
uint32_t mOverruns; // total number of overruns
uint32_t mSampleRate;
size_t mFrameCount;
+ struct timespec mMeasuredWarmupTs; // measured warmup time
+ uint32_t mWarmupCycles; // number of loop cycles required to warmup
+ FastTrackDump mTracks[FastMixerState::kMaxFastTracks];
#ifdef FAST_MIXER_STATISTICS
// cycle times in seconds
float mMean;