From 42abe2870abefaa8eaa3c7995931ab380165c266 Mon Sep 17 00:00:00 2001 From: Apehum <36326454+Apehum@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:59:26 +0800 Subject: [PATCH] fix: set startTime when first frame received in AudioSender --- .../plo/voice/api/server/audio/source/AudioSender.kt | 8 +++++++- client/changelog.md | 11 ++--------- proxy/changelog.md | 3 ++- server/changelog.md | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api/server-proxy-common/src/main/kotlin/su/plo/voice/api/server/audio/source/AudioSender.kt b/api/server-proxy-common/src/main/kotlin/su/plo/voice/api/server/audio/source/AudioSender.kt index 9eedfff9..7009e027 100644 --- a/api/server-proxy-common/src/main/kotlin/su/plo/voice/api/server/audio/source/AudioSender.kt +++ b/api/server-proxy-common/src/main/kotlin/su/plo/voice/api/server/audio/source/AudioSender.kt @@ -39,7 +39,7 @@ class AudioSender( val job = CoroutineScope(Dispatchers.Default).launch { var sequenceNumber = 0L - val startTime = System.nanoTime() + var startTime = 0L var endOfStream = false @@ -49,6 +49,7 @@ class AudioSender( if (!endOfStream) { endOfStream = true onEnd.invoke(sequenceNumber++) + startTime = 0L } delay(10L) @@ -61,6 +62,7 @@ class AudioSender( endOfStream = true onEnd.invoke(sequenceNumber++) + startTime = 0L continue } @@ -76,6 +78,10 @@ class AudioSender( continue } + if (startTime == 0L) { + startTime = System.nanoTime() + } + val frameTime = 20_000_000 * sequenceNumber val waitTime = startTime + frameTime - System.nanoTime() diff --git a/client/changelog.md b/client/changelog.md index 7a1f88cd..69ba0ade 100644 --- a/client/changelog.md +++ b/client/changelog.md @@ -5,12 +5,5 @@ If you encounter any issues, please report them on Discord: https://discord.gg/u Versions 2.0.x and 2.1.x are protocol-compatible, so there’s no need to worry if the server hasn't been updated to 2.1.x. -### Changes in 2.1.1 -- Build for 1.19.3 was reintroduced. -- Soften Minecraft version bounds: - - 1.20.4 now allows 1.20.2, 1.20.3 and 1.20.4 - - 1.19.2 now allows 1.19, 1.19.1 and 1.19.2 -- Updated to 1.21.2. -- Updated [slib](https://github.com/plasmoapp/mc-slib) to fix crash with EssentialAddons on world join. -- Fixed audio sources causing a high CPU load. [#421](https://github.com/plasmoapp/plasmo-voice/issues/421) -- Attempt to fix "Cannot measure distance between worlds" exception, see [#422](https://github.com/plasmoapp/plasmo-voice/issues/422). \ No newline at end of file +### Changes in 2.1.2 +- Fixed buffer overflow when using AudioSender with delayed first frame. \ No newline at end of file diff --git a/proxy/changelog.md b/proxy/changelog.md index e0a8907e..69ba0ade 100644 --- a/proxy/changelog.md +++ b/proxy/changelog.md @@ -5,4 +5,5 @@ If you encounter any issues, please report them on Discord: https://discord.gg/u Versions 2.0.x and 2.1.x are protocol-compatible, so there’s no need to worry if the server hasn't been updated to 2.1.x. -### Changes in 2.1.1 \ No newline at end of file +### Changes in 2.1.2 +- Fixed buffer overflow when using AudioSender with delayed first frame. \ No newline at end of file diff --git a/server/changelog.md b/server/changelog.md index 7b905611..69ba0ade 100644 --- a/server/changelog.md +++ b/server/changelog.md @@ -5,5 +5,5 @@ If you encounter any issues, please report them on Discord: https://discord.gg/u Versions 2.0.x and 2.1.x are protocol-compatible, so there’s no need to worry if the server hasn't been updated to 2.1.x. -### Changes in 2.1.1 -- Attempt to fix "Cannot measure distance between worlds" exception, see [#422](https://github.com/plasmoapp/plasmo-voice/issues/422). \ No newline at end of file +### Changes in 2.1.2 +- Fixed buffer overflow when using AudioSender with delayed first frame. \ No newline at end of file