Skip to content

Commit

Permalink
fix: fix uncleared track meta on stop audio (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Life authored May 1, 2024
1 parent bf63f66 commit 698c14f
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/dpp/discordvoiceclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ dpp::utility::uptime discord_voice_client::get_remaining() {
discord_voice_client& discord_voice_client::stop_audio() {
std::lock_guard<std::mutex> lock(this->stream_mutex);
outbuf.clear();
track_meta.clear();
tracks = 0;
return *this;
}

Expand Down Expand Up @@ -847,7 +849,7 @@ void discord_voice_client::write_ready()
std::lock_guard<std::mutex> lock(this->stream_mutex);
if (!this->paused && outbuf.size()) {
type = send_audio_type;
if (outbuf[0].packet.size() == 2 && (*((uint16_t*)(outbuf[0].packet.data()))) == AUDIO_TRACK_MARKER) {
if (outbuf[0].packet.size() == sizeof(uint16_t) && (*((uint16_t*)(outbuf[0].packet.data()))) == AUDIO_TRACK_MARKER) {
outbuf.erase(outbuf.begin());
track_marker_found = true;
if (tracks > 0) {
Expand Down Expand Up @@ -1165,20 +1167,29 @@ uint32_t discord_voice_client::get_tracks_remaining() {

discord_voice_client& discord_voice_client::skip_to_next_marker() {
std::lock_guard<std::mutex> lock(this->stream_mutex);
/* Keep popping the first entry off the outbuf until the first entry is a track marker */
while (!outbuf.empty() && outbuf[0].packet.size() != sizeof(uint16_t) && (*((uint16_t*)(outbuf[0].packet.data()))) != AUDIO_TRACK_MARKER) {
outbuf.erase(outbuf.begin());
}
if (outbuf.size()) {
/* Remove the actual track marker out of the buffer */
outbuf.erase(outbuf.begin());
if (!outbuf.empty()) {
/* Find the first marker to skip to */
auto i = std::find_if(outbuf.begin(), outbuf.end(), [](const voice_out_packet &v){
return v.packet.size() == sizeof(uint16_t) && (*((uint16_t*)(v.packet.data()))) == AUDIO_TRACK_MARKER;
});

if (i != outbuf.end()) {
/* Skip queued packets until including found marker */
outbuf.erase(outbuf.begin(), i+1);
} else {
/* No market found, skip the whole queue */
outbuf.clear();
}
}

if (tracks > 0) {
tracks--;
}

if (!track_meta.empty()) {
track_meta.erase(track_meta.begin());
}

return *this;
}

Expand Down

0 comments on commit 698c14f

Please sign in to comment.