Skip to content

Commit e141e0b

Browse files
committed
fixing audio ts
1 parent 140827d commit e141e0b

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

encoder/src/main/java/com/pedro/encoder/audio/AudioEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected long calculatePts(Frame frame, long presentTimeUs) {
160160
@Override
161161
protected void checkBuffer(@NonNull ByteBuffer byteBuffer,
162162
@NonNull MediaCodec.BufferInfo bufferInfo) {
163-
fixTimeStamp(bufferInfo);
163+
//fixTimeStamp(bufferInfo);
164164
}
165165

166166
@Override

encoder/src/main/java/com/pedro/encoder/input/audio/MicrophoneManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class MicrophoneManager {
6363
private float microphoneVolume = 1f;
6464
private float internalVolume = 1f;
6565
private final AudioUtils audioUtils = new AudioUtils();
66+
private volatile long lastTimestamp = 0;
6667

6768
enum Mode {
6869
MICROPHONE, INTERNAL, MIX
@@ -195,7 +196,8 @@ public synchronized void start() {
195196
handler.post(() -> {
196197
while (running) {
197198
Frame frame = read();
198-
if (frame != null) {
199+
if (frame != null && lastTimestamp >= frame.getTimeStamp()) {
200+
lastTimestamp = frame.getTimeStamp();
199201
getMicrophoneData.inputPCMData(frame);
200202
}
201203
}
@@ -322,6 +324,7 @@ public synchronized void stop() {
322324
audioPostProcessEffect.release();
323325
}
324326
Log.i(TAG, "Microphone stopped");
327+
lastTimestamp = 0;
325328
}
326329

327330
/**

library/src/main/java/com/pedro/library/base/recording/BaseRecordController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected boolean updateFormat(MediaCodec.BufferInfo newInfo, MediaCodec.BufferI
107107
newInfo.offset = oldInfo.offset;
108108
newInfo.size = oldInfo.size;
109109
long ts = Math.max(0, oldInfo.presentationTimeUs - startTs - pauseTime);
110-
if (newInfo.presentationTimeUs >= ts) {
110+
if (newInfo.presentationTimeUs >= oldInfo.presentationTimeUs) {
111111
Log.e(TAG, "out of order frame discarded");
112112
return false; //should discard frame
113113
} else {

0 commit comments

Comments
 (0)