Fix frame pacing issues on Snapdragon. Improve latency on Tegra (not perfect still).

This commit is contained in:
Cameron Gutman 2013-11-15 23:42:00 -05:00
parent 79db2ed584
commit 10165f3166

View File

@ -354,6 +354,7 @@ public class NvVideoStream {
private void outputDisplayLoop(Thread t) private void outputDisplayLoop(Thread t)
{ {
long nextFrameTimeUs = 0;
while (!t.isInterrupted()) while (!t.isInterrupted())
{ {
BufferInfo info = new BufferInfo(); BufferInfo info = new BufferInfo();
@ -370,8 +371,23 @@ public class NvVideoStream {
break; break;
} }
if (outIndex >= 0) { if (outIndex >= 0) {
videoDecoder.releaseOutputBuffer(outIndex, true); boolean render = false;
if (currentTimeUs() >= nextFrameTimeUs) {
render = true;
nextFrameTimeUs = computePresentationTime(60);
}
videoDecoder.releaseOutputBuffer(outIndex, render);
} }
} }
} }
private static long currentTimeUs() {
return System.nanoTime() / 1000;
}
private long computePresentationTime(int frameRate) {
return currentTimeUs() + (1000000 / frameRate);
}
} }