Audio latency updates

Add priority inversion as one of the contributors to audio latency.
Add more tips to latency measurement.
Add latency video link.

Change-Id: I03080dc0ba003c6b95cd2d5eaa3b4a4dfc8960a8
diff --git a/src/devices/audio/avoiding_pi.jd b/src/devices/audio/avoiding_pi.jd
index 2e0a07a..022c766 100644
--- a/src/devices/audio/avoiding_pi.jd
+++ b/src/devices/audio/avoiding_pi.jd
@@ -78,6 +78,13 @@
 </p>
 
 <p>
+A common workaround for priority inversion is to increase audio buffer sizes.
+However, this method increases latency and merely hides the problem
+instead of solving it. It is better to understand and prevent priority
+inversion, as seen below.
+</p>
+
+<p>
 In the Android audio implementation, priority inversion is most
 likely to occur in these places. And so you should focus your attention here:
 </p>
diff --git a/src/devices/audio/latency_app.jd b/src/devices/audio/latency_app.jd
index 22e3984..5672147 100644
--- a/src/devices/audio/latency_app.jd
+++ b/src/devices/audio/latency_app.jd
@@ -165,10 +165,16 @@
 
 <dl>
 
-<dt><a href="https://www.youtube.com/watch?v=d3kfEeMZ65c">Google I/O 2013 - High performance audio on Android</a></dt>
+<dt><a href="https://youtu.be/d3kfEeMZ65c">High performance audio on Android</a>
+(Google I/O 2013)</dt>
 <dd>The whole video is about latency.</dd>
 
-<dt><a href="https://www.youtube.com/watch?v=92fgcUNCHic">Google I/O 2014 - Building great multi-media experiences on Android</a></dt>
+<dt><a href="https://youtu.be/92fgcUNCHic">Building great multi-media experiences on Android</a>
+(Google I/O 2014)</dt>
 <dd>The first 14 minutes are about audio in general and input latency in particular.</dd>
 
+<dt><a href="https://youtu.be/PnDK17zP9BI">Audio latency: buffer sizes</a>
+(100 Days of Google Dev)</dt>
+<dd>Describes the relationship between audio latency, buffer sizes, and task scheduling.</dd>
+
 </dl>
diff --git a/src/devices/audio/latency_contrib.jd b/src/devices/audio/latency_contrib.jd
index fb7cd71..2969ba2 100644
--- a/src/devices/audio/latency_contrib.jd
+++ b/src/devices/audio/latency_contrib.jd
@@ -49,6 +49,9 @@
   system designer then increases buffer sizes or buffer counts.
   This has the desired result of eliminating the underruns or overruns, but it also
   has the undesired side effect of increasing latency.
+  For more information about buffer sizes, see the video
+  <a href="https://youtu.be/PnDK17zP9BI">Audio latency: buffer sizes</a>.
+
 </p>
 
 <p>
@@ -64,6 +67,7 @@
 <ul>
   <li>Linux CFS (Completely Fair Scheduler)</li>
   <li>high-priority threads with SCHED_FIFO scheduling</li>
+  <li>priority inversion</li>
   <li>long scheduling latency</li>
   <li>long-running interrupt handlers</li>
   <li>long interrupt disable time</li>
@@ -123,6 +127,18 @@
   with the scheduling of true periodic threads.
 </p>
 
+<h3 id="priorityInversion">Priority inversion</h3>
+<p>
+  <a href="http://en.wikipedia.org/wiki/Priority_inversion">Priority inversion</a>
+  is a classic failure mode of real-time systems,
+  where a higher-priority task is blocked for an unbounded time waiting
+  for a lower-priority task to release a resource such as (shared
+  state protected by) a
+  <a href="http://en.wikipedia.org/wiki/Mutual_exclusion">mutex</a>.
+  See the article "<a href="avoiding_pi.html">Avoiding priority inversion</a>" for techniques to
+  mitigate it.
+</p>
+
 <h3 id="schedLatency">Scheduling latency</h3>
 <p>
   Scheduling latency is the time between when a thread becomes
diff --git a/src/devices/audio/latency_measure.jd b/src/devices/audio/latency_measure.jd
index 6285ff9..9abe015 100644
--- a/src/devices/audio/latency_measure.jd
+++ b/src/devices/audio/latency_measure.jd
@@ -118,6 +118,11 @@
   precise output latency or input latency values in isolation, but might be useful
   for establishing rough estimates.</p>
 
+  <p>
+  Output latency to on-device speaker can be significantly larger than
+  output latency to headset connector.  This is due to speaker correction and protection.
+  </p>
+
 <p>
 We have published an example implementation at
 <a href="https://android.googlesource.com/platform/frameworks/wilhelm/+/master/tests/examples/slesTestFeedback.cpp">slesTestFeedback.cpp</a>.
@@ -145,6 +150,10 @@
   <strong>Figure 1.</strong> Round-trip measurement
 </p>
 
+<p>You may need to remove the USB cable to reduce noise,
+and adjust the volume level to get a stable oscillation.
+</p>
+
 <h2 id="measuringInput">Measuring Input Latency</h2>
 
 <p>