Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/dpp/voice/enabled/read_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@ void discord_voice_client::send(const char* packet, size_t len, uint64_t duratio
frame.packet.assign(packet, packet + len);
frame.duration = duration;

std::lock_guard<std::mutex> lock(this->stream_mutex);
outbuf.emplace_back(frame);
bool was_empty = false;
{
std::lock_guard<std::mutex> lock(this->stream_mutex);
was_empty = outbuf.empty();
outbuf.emplace_back(frame);
}

if (was_empty) {
udp_events.flags = WANT_READ | WANT_WRITE | WANT_ERROR;
owner->socketengine->update_socket(udp_events);
}
} else [[unlikely]] {
this->udp_send(packet, len);
}
Expand Down
18 changes: 12 additions & 6 deletions src/dpp/voice/enabled/write_ready.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@
namespace dpp {

void discord_voice_client::write_ready() {
/*
* WANT_WRITE has been reset everytime this method is being called,
* ALWAYS set it again no matter what we're gonna do.
*/
udp_events.flags = WANT_READ | WANT_WRITE | WANT_ERROR;
owner->socketengine->update_socket(udp_events);
bool needs_write = false;
{
std::lock_guard<std::mutex> lock(this->stream_mutex);
const bool needs_stop_frames = this->paused && !this->sent_stop_frames;
const bool has_audio = !outbuf.empty();
needs_write = needs_stop_frames || has_audio;
}

if (needs_write) {
udp_events.flags = WANT_READ | WANT_WRITE | WANT_ERROR;
owner->socketengine->update_socket(udp_events);
}

uint64_t duration = 0;
bool track_marker_found = false;
Expand Down
Loading