mirror of
https://github.com/Genymobile/scrcpy
synced 2024-12-18 13:24:40 +00:00
Fix audio PTS when not monotonically increasing
Some decoders fail to guarantee that PTS must be strictly monotonically increasing. Fix the PTS when they are not. Fixes #4054 <https://github.com/Genymobile/scrcpy/issues/4054>
This commit is contained in:
parent
2aec7b4c9d
commit
68a9996eb2
@ -105,8 +105,17 @@ public final class AudioEncoder implements AsyncProcessor {
|
||||
private void outputThread(MediaCodec mediaCodec) throws IOException, InterruptedException {
|
||||
streamer.writeAudioHeader();
|
||||
|
||||
long lastPts = 0;
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
OutputTask task = outputTasks.take();
|
||||
|
||||
if (task.bufferInfo.presentationTimeUs <= lastPts) {
|
||||
// Fix PTS if not strictly monotonically increasing
|
||||
task.bufferInfo.presentationTimeUs = ++lastPts;
|
||||
} else {
|
||||
lastPts = task.bufferInfo.presentationTimeUs;
|
||||
}
|
||||
|
||||
ByteBuffer buffer = mediaCodec.getOutputBuffer(task.index);
|
||||
try {
|
||||
streamer.writePacket(buffer, task.bufferInfo);
|
||||
|
Loading…
Reference in New Issue
Block a user