From 19200b676a083939b77fcbfcf3b144871cb30ea5 Mon Sep 17 00:00:00 2001 From: Apehum <36326454+Apehum@users.noreply.github.com> Date: Sun, 17 Nov 2024 06:09:47 +0800 Subject: [PATCH] fix(client): update last buffer time in al source if samples write was skipped --- .../plo/voice/api/client/audio/device/source/AlSource.java | 5 +++++ .../plo/voice/client/audio/device/source/StreamAlSource.kt | 6 +++++- .../plo/voice/client/audio/source/BaseClientAudioSource.kt | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/api/client/src/main/java/su/plo/voice/api/client/audio/device/source/AlSource.java b/api/client/src/main/java/su/plo/voice/api/client/audio/device/source/AlSource.java index f190f4c3..9e9906ca 100644 --- a/api/client/src/main/java/su/plo/voice/api/client/audio/device/source/AlSource.java +++ b/api/client/src/main/java/su/plo/voice/api/client/audio/device/source/AlSource.java @@ -157,6 +157,11 @@ public interface AlSource extends DeviceSource { */ void setCloseTimeoutMs(long timeoutMs); + /** + * Updates last buffer time to current time provided by the time supplier. + */ + void updateLastBufferTime(); + /** * Gets the OpenAL format of the source. * diff --git a/client/src/main/kotlin/su/plo/voice/client/audio/device/source/StreamAlSource.kt b/client/src/main/kotlin/su/plo/voice/client/audio/device/source/StreamAlSource.kt index 4a6ab435..21a4aaac 100644 --- a/client/src/main/kotlin/su/plo/voice/client/audio/device/source/StreamAlSource.kt +++ b/client/src/main/kotlin/su/plo/voice/client/audio/device/source/StreamAlSource.kt @@ -99,6 +99,10 @@ class StreamAlSource private constructor( this.closeTimeoutMs = timeoutMs } + override fun updateLastBufferTime() { + lastBufferTime = timeSupplier.currentTimeMillis + } + override fun write(samples: ShortArray, applyFilters: Boolean) { val processedSamples = if (applyFilters) { device.processFilters(samples) @@ -202,7 +206,7 @@ class StreamAlSource private constructor( queueWithEmptyBuffers() fillQueue() - lastBufferTime = timeSupplier.currentTimeMillis + updateLastBufferTime() availableBuffer[0] = -1 while (isStreaming.get()) { diff --git a/client/src/main/kotlin/su/plo/voice/client/audio/source/BaseClientAudioSource.kt b/client/src/main/kotlin/su/plo/voice/client/audio/source/BaseClientAudioSource.kt index 69a5e4e3..07da4bcd 100644 --- a/client/src/main/kotlin/su/plo/voice/client/audio/source/BaseClientAudioSource.kt +++ b/client/src/main/kotlin/su/plo/voice/client/audio/source/BaseClientAudioSource.kt @@ -382,6 +382,8 @@ abstract class BaseClientAudioSource( } catch (e: CodecException) { BaseVoice.DEBUG_LOGGER.warn("Failed to decode source audio", e) } + } else { + source.updateLastBufferTime() } lastSequenceNumber = packet.sequenceNumber