Enforce monotonical PTS
Audio PTS may come from two sources: - recorder.getTimestamp() if the call works; - an estimation from the previous PTS and the packet size as a fallback. Therefore, the property that PTS are monotonically increasing is no guaranteed in corner cases, so enforce it.
This commit is contained in:
@@ -87,6 +87,7 @@ public final class AudioEncoder {
|
|||||||
class AudioEncoderCallbacks extends MediaCodec.Callback {
|
class AudioEncoderCallbacks extends MediaCodec.Callback {
|
||||||
|
|
||||||
private final AudioTimestamp timestamp = new AudioTimestamp();
|
private final AudioTimestamp timestamp = new AudioTimestamp();
|
||||||
|
private long previousPts;
|
||||||
private long nextPts;
|
private long nextPts;
|
||||||
private boolean eofSignaled;
|
private boolean eofSignaled;
|
||||||
private boolean ended;
|
private boolean ended;
|
||||||
@@ -129,7 +130,18 @@ public final class AudioEncoder {
|
|||||||
eofSignaled = true;
|
eofSignaled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (previousPts != 0 && pts < previousPts) {
|
||||||
|
// Audio PTS may come from two sources:
|
||||||
|
// - recorder.getTimestamp() if the call works;
|
||||||
|
// - an estimation from the previous PTS and the packet size as a fallback.
|
||||||
|
//
|
||||||
|
// Therefore, the property that PTS are monotonically increasing is no guaranteed in corner cases, so enforce it.
|
||||||
|
pts = previousPts + 1;
|
||||||
|
}
|
||||||
|
|
||||||
codec.queueInputBuffer(index, 0, r, pts, flags);
|
codec.queueInputBuffer(index, 0, r, pts, flags);
|
||||||
|
|
||||||
|
previousPts = pts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user