title: How to reduce latency in MediaCodec video/avc decoding
body: <p>I performed some simple timing of <a href="https://github.com/google/grafika/blob/master/src/com/android/grafika/MoviePlayer.java" rel="noreferrer">MoviePlayer.java</a> in the <a href="https://github.com/google/grafika" rel="noreferrer">Grafika</a> MediaCodec sample code running on a Nexus 5. I put a log statement at these locations:</p>
  
  <p>At line 203 just before</p>
  
  <pre><code>decoder.queueInputBuffer
  </code></pre>
  
  <p>At line 244 after</p>
  
  <pre><code>decoder.dequeueOutputBuffer
  </code></pre>
  
  <p>I correlated the log statements using <code>presentationTimeUs</code>.</p>
  
  <p>Here is an excerpt from logcat:</p>
  
  <pre><code>01-29 10:56:43.295: I/Grafika(21286): queueInputBuffer index/pts, 2,0
  01-29 10:56:43.305: I/Grafika(21286): queueInputBuffer index/pts, 0,33100
  01-29 10:56:43.315: I/Grafika(21286): queueInputBuffer index/pts, 3,66466
  01-29 10:56:43.325: I/Grafika(21286): queueInputBuffer index/pts, 1,99833
  01-29 10:56:43.325: I/Grafika(21286): queueInputBuffer index/pts, 2,133200
  01-29 10:56:43.335: I/Grafika(21286): queueInputBuffer index/pts, 0,166566
  01-29 10:56:43.345: I/ATSParser(21286): discontinuity on stream pid 0x1011
  01-29 10:56:43.345: I/ATSParser(21286): discontinuity on stream pid 0x1100
  01-29 10:56:43.345: I/Grafika(21286): queueInputBuffer index/pts, 3,199933
  01-29 10:56:43.345: I/Grafika(21286): dequeueOutputBuffer index/pts, 7,0
  01-29 10:56:43.345: I/Grafika(21286): queueInputBuffer index/pts, 1,300033
  01-29 10:56:43.355: I/Grafika(21286): dequeueOutputBuffer index/pts, 6,33100
  01-29 10:56:43.385: I/Grafika(21286): queueInputBuffer index/pts, 2,333400
  01-29 10:56:43.385: I/Grafika(21286): dequeueOutputBuffer index/pts, 5,66466
  01-29 10:56:43.415: I/Grafika(21286): queueInputBuffer index/pts, 0,366766
  01-29 10:56:43.415: I/Grafika(21286): dequeueOutputBuffer index/pts, 4,99833
  01-29 10:56:43.445: I/Grafika(21286): queueInputBuffer index/pts, 3,400133
  01-29 10:56:43.445: I/Grafika(21286): dequeueOutputBuffer index/pts, 3,133200
  </code></pre>
  
  <p>I found the time difference from when the first input buffer is queued to when the corresponding output buffer is dequeued is 50 millis. This seems like a lot of time for HW accelerated decoding. </p>
  
  <p><strong>Is there a way to decrease this latency?</strong></p>