Reduce underruns in screen off, esp. with EQ

Add MonoPipe APIs to specify setpoint.
Use screen state to configure pipe setpoint.
Fix a long-standing bug where pipe sleep time was excessive,
  which interacted poorly with governor and low clock frequencies.
  Now it deducts the elapsed time since last write(),
  which was significant when there was EQ and low clock frequency.

Bug: 6618373
Change-Id: I6f3b0072c2244aeb033ef0795ad164491a164ff5
diff --git a/services/audioflinger/MonoPipe.h b/services/audioflinger/MonoPipe.h
index aaaa51f..f6e2cb3 100644
--- a/services/audioflinger/MonoPipe.h
+++ b/services/audioflinger/MonoPipe.h
@@ -58,7 +58,9 @@
 
             // average number of frames present in the pipe under normal conditions.
             // See throttling mechanism in MonoPipe::write()
-            size_t  getAvgFrames() const { return (mReqFrames * 11) / 16; }
+            size_t  getAvgFrames() const { return mSetpoint; }
+            void    setAvgFrames(size_t setpoint);
+            size_t  maxFrames() const { return mMaxFrames; }
 
 private:
     const size_t    mReqFrames;     // as requested in constructor, unrounded
@@ -71,6 +73,9 @@
                                     // read by writer with android_atomic_acquire_load
     volatile int32_t mRear;         // written by writer with android_atomic_release_store,
                                     // read by reader with android_atomic_acquire_load
+    bool            mWriteTsValid;  // whether mWriteTs is valid
+    struct timespec mWriteTs;       // time that the previous write() completed
+    size_t          mSetpoint;      // target value for pipe fill depth
     const bool      mWriteCanBlock; // whether write() should block if the pipe is full
 };