@@ -51,12 +51,12 @@ public abstract class BaseEncoder implements EncoderCallback {
5151 private ExecutorService executorService ;
5252 protected BlockingQueue <Frame > queue = new ArrayBlockingQueue <>(80 );
5353 protected MediaCodec codec ;
54- protected long presentTimeUs ;
54+ protected volatile long presentTimeUs ;
5555 protected volatile boolean running = false ;
5656 protected boolean isBufferMode = true ;
5757 protected CodecUtil .CodecType codecType = CodecUtil .CodecType .FIRST_COMPATIBLE_FOUND ;
5858 private MediaCodec .Callback callback ;
59- private long oldTimeStamp = 0L ;
59+ private volatile long oldTimeStamp = 0L ;
6060 protected boolean shouldReset = true ;
6161 protected boolean prepared = false ;
6262 private Handler handler ;
@@ -134,10 +134,10 @@ private void initCodec() {
134134
135135 protected void fixTimeStamp (MediaCodec .BufferInfo info ) {
136136 if (oldTimeStamp > info .presentationTimeUs ) {
137- info .presentationTimeUs = oldTimeStamp ;
138- } else {
139- oldTimeStamp = info .presentationTimeUs ;
137+ final long currentTs = TimeUtils .getCurrentTimeMicro () - presentTimeUs ;
138+ info .presentationTimeUs = Math .max (currentTs , oldTimeStamp + 1 );
140139 }
140+ oldTimeStamp = info .presentationTimeUs ;
141141 }
142142
143143 private void reloadCodec (IllegalStateException e ) {
0 commit comments