Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/uncleared track meta on stop audio #1127

Merged
Merged
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 @@
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 @@
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) {

Check notice on line 852 in src/dpp/discordvoiceclient.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/dpp/discordvoiceclient.cpp#L852

C-style pointer casting
outbuf.erase(outbuf.begin());
track_marker_found = true;
if (tracks > 0) {
Expand Down Expand Up @@ -1165,20 +1167,29 @@

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;

Check notice on line 1173 in src/dpp/discordvoiceclient.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/dpp/discordvoiceclient.cpp#L1173

C-style pointer casting
});

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
Loading