From b972257e64fed60229bb267ac629765ebdf7ca50 Mon Sep 17 00:00:00 2001 From: Neko-Life Date: Tue, 9 Jul 2024 02:14:10 +0700 Subject: [PATCH] fix: add packets_left count --- include/dpp/dispatcher.h | 7 ++++++- src/dpp/discordvoiceclient.cpp | 3 ++- src/unittest/test.cpp | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/dpp/dispatcher.h b/include/dpp/dispatcher.h index 6310aef3d4..d6be8caa69 100644 --- a/include/dpp/dispatcher.h +++ b/include/dpp/dispatcher.h @@ -1980,7 +1980,12 @@ struct DPP_EXPORT voice_buffer_send_t : public event_dispatch_t { /** * @brief encoded size of sent buffer */ - int buffer_size = 0; + uint64_t buffer_size = 0; + + /** + * @brief number of packet waiting to be sent in the queue + */ + size_t packets_left = 0; }; /** diff --git a/src/dpp/discordvoiceclient.cpp b/src/dpp/discordvoiceclient.cpp index 88932cca32..76dcc5dea7 100644 --- a/src/dpp/discordvoiceclient.cpp +++ b/src/dpp/discordvoiceclient.cpp @@ -899,7 +899,8 @@ void discord_voice_client::write_ready() last_timestamp = std::chrono::high_resolution_clock::now(); if (!creator->on_voice_buffer_send.empty()) { voice_buffer_send_t snd(nullptr, ""); - snd.buffer_size = (int)bufsize; + snd.buffer_size = bufsize; + snd.packets_left = outbuf.size(); snd.voice_client = this; creator->on_voice_buffer_send.call(snd); } diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index cf159d46e6..1574191f7e 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -1140,7 +1140,13 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b }); bot.on_voice_buffer_send([&](const dpp::voice_buffer_send_t & event) { - if (event.buffer_size == 0) { + static bool sent_some_data = false; + + if (event.buffer_size > 0) { + sent_some_data = true; + } + + if (sent_some_data && event.packets_left == 0) { set_test(VOICESEND, true); } });