From a402eac7f293b1f63ce1c0a9449cf3a997dc061e Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 14 Nov 2023 09:15:34 +0100 Subject: [PATCH] Compute PTS of intermediate blocks If several reads are performed for a single captured audio block (e.g. if the read size is smaller than the captured block), then the provided timestamp was the same for all packets. Recompute the timestamp for each of them. --- server/src/main/java/com/genymobile/scrcpy/AudioCapture.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java index e94b49ed..c05bb41d 100644 --- a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java @@ -34,6 +34,7 @@ public final class AudioCapture { private AudioRecord recorder; private final AudioTimestamp timestamp = new AudioTimestamp(); + private long previousRecorderTimestamp = -1; private long previousPts = 0; private long nextPts = 0; @@ -145,8 +146,9 @@ public final class AudioCapture { long pts; int ret = recorder.getTimestamp(timestamp, AudioTimestamp.TIMEBASE_MONOTONIC); - if (ret == AudioRecord.SUCCESS) { + if (ret == AudioRecord.SUCCESS && timestamp.nanoTime != previousRecorderTimestamp) { pts = timestamp.nanoTime / 1000; + previousRecorderTimestamp = timestamp.nanoTime; } else { if (nextPts == 0) { Ln.w("Could not get any audio timestamp");