Compare commits

...

2 Commits

Author SHA1 Message Date
4f7869d130 Fix audio PTS when not monotonically increasing
Some decoders fail to guarantee that PTS must be monotonically
increasing. Fix the PTS when they're not.

Fixes #4054 <https://github.com/Genymobile/scrcpy/issues/4054>
2023-06-02 21:39:29 +02:00
0f28d39127 Do not add 1µS to the PTS in corner cases
The PTS must be monotonically increasing, but not strictly.
2023-06-02 21:38:30 +02:00
2 changed files with 10 additions and 1 deletions

View File

@ -163,7 +163,7 @@ public final class AudioCapture {
// - 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;
pts = previousPts;
}
previousPts = pts;

View File

@ -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 monotonically increasing
task.bufferInfo.presentationTimeUs = lastPts;
} else {
lastPts = task.bufferInfo.presentationTimeUs;
}
ByteBuffer buffer = mediaCodec.getOutputBuffer(task.index);
try {
streamer.writePacket(buffer, task.bufferInfo);