Ensure that no input buffers will ever be submitted with the same timestamp per SDK docs

This commit is contained in:
Cameron Gutman 2014-10-17 14:45:58 -07:00
parent b19360ac75
commit fa847ef2fc

View File

@ -39,6 +39,7 @@ public class MediaCodecDecoderRenderer implements VideoDecoderRenderer {
private boolean adaptivePlayback; private boolean adaptivePlayback;
private int initialWidth, initialHeight; private int initialWidth, initialHeight;
private long lastTimestampUs;
private long totalTimeMs; private long totalTimeMs;
private long decoderTimeMs; private long decoderTimeMs;
private int totalFrames; private int totalFrames;
@ -463,6 +464,14 @@ public class MediaCodecDecoderRenderer implements VideoDecoderRenderer {
totalFrames++; totalFrames++;
} }
long timestampUs = currentTime * 1000;
if (timestampUs == lastTimestampUs) {
// We can't submit multiple buffers with the same timestamp
// so bump it up by one before queuing
timestampUs = lastTimestampUs + 1;
}
lastTimestampUs = timestampUs;
// Clear old input data // Clear old input data
buf.clear(); buf.clear();
@ -521,7 +530,7 @@ public class MediaCodecDecoderRenderer implements VideoDecoderRenderer {
try { try {
videoDecoder.queueInputBuffer(inputBufferIndex, videoDecoder.queueInputBuffer(inputBufferIndex,
0, buf.position(), 0, buf.position(),
currentTime * 1000, codecFlags); timestampUs, codecFlags);
} catch (Exception e) { } catch (Exception e) {
throw new RendererException(this, e, buf, codecFlags); throw new RendererException(this, e, buf, codecFlags);
} }
@ -542,7 +551,7 @@ public class MediaCodecDecoderRenderer implements VideoDecoderRenderer {
try { try {
videoDecoder.queueInputBuffer(inputBufferIndex, videoDecoder.queueInputBuffer(inputBufferIndex,
0, decodeUnit.getDataLength(), 0, decodeUnit.getDataLength(),
currentTime * 1000, codecFlags); timestampUs, codecFlags);
} catch (Exception e) { } catch (Exception e) {
throw new RendererException(this, e, buf, codecFlags); throw new RendererException(this, e, buf, codecFlags);
} }