Include the time it takes to get an input buffer in the frame latency calculation

This commit is contained in:
Cameron Gutman 2015-03-25 01:08:23 -04:00
parent 072a439c2d
commit 17afbffdb5

View File

@ -239,13 +239,13 @@ public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
inputIndex = dequeueInputBuffer(false, false); inputIndex = dequeueInputBuffer(false, false);
du = depacketizer.pollNextDecodeUnit(); du = depacketizer.pollNextDecodeUnit();
if (du != null) {
lastDuDequeueTime = System.currentTimeMillis();
notifyDuReceived(du);
}
// Stop if we can't get a DU or input buffer // Stop if we can't get a DU or input buffer
if (du == null || inputIndex == -1) { if (du == null || inputIndex == -1) {
if (du != null) {
lastDuDequeueTime = System.currentTimeMillis();
}
break; break;
} }
@ -283,6 +283,7 @@ public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer {
du = depacketizer.pollNextDecodeUnit(); du = depacketizer.pollNextDecodeUnit();
if (du != null) { if (du != null) {
lastDuDequeueTime = System.currentTimeMillis(); lastDuDequeueTime = System.currentTimeMillis();
notifyDuReceived(du);
} }
} }
@ -421,14 +422,7 @@ public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void submitDecodeUnit(DecodeUnit decodeUnit, ByteBuffer buf, int inputBufferIndex) { private void submitDecodeUnit(DecodeUnit decodeUnit, ByteBuffer buf, int inputBufferIndex) {
long currentTime = System.currentTimeMillis(); long timestampUs = System.currentTimeMillis() * 1000;
long delta = currentTime-decodeUnit.getReceiveTimestamp();
if (delta >= 0 && delta < 1000) {
totalTimeMs += currentTime-decodeUnit.getReceiveTimestamp();
totalFrames++;
}
long timestampUs = currentTime * 1000;
if (timestampUs <= lastTimestampUs) { if (timestampUs <= lastTimestampUs) {
// We can't submit multiple buffers with the same timestamp // We can't submit multiple buffers with the same timestamp
// so bump it up by one before queuing // so bump it up by one before queuing
@ -614,10 +608,21 @@ public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer {
return decoderName; return decoderName;
} }
private void notifyDuReceived(DecodeUnit du) {
long currentTime = System.currentTimeMillis();
long delta = currentTime-du.getReceiveTimestamp();
if (delta >= 0 && delta < 1000) {
totalTimeMs += currentTime-du.getReceiveTimestamp();
totalFrames++;
}
}
@Override @Override
public void directSubmitDecodeUnit(DecodeUnit du) { public void directSubmitDecodeUnit(DecodeUnit du) {
int inputIndex; int inputIndex;
notifyDuReceived(du);
for (;;) { for (;;) {
try { try {
inputIndex = dequeueInputBuffer(true, true); inputIndex = dequeueInputBuffer(true, true);