mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-20 20:46:16 +02:00
Fix message queueing
This commit is contained in:
parent
c445deb95a
commit
4cb67c7960
1 changed files with 15 additions and 11 deletions
|
@ -128,10 +128,10 @@ void StreamSession::stop()
|
||||||
|
|
||||||
void StreamSession::send_next()
|
void StreamSession::send_next()
|
||||||
{
|
{
|
||||||
shared_const_buffer buffer = messages_.front();
|
auto& buffer = messages_.front();
|
||||||
messages_.pop_front();
|
|
||||||
boost::asio::async_write(socket_, buffer,
|
boost::asio::async_write(socket_, buffer,
|
||||||
boost::asio::bind_executor(strand_, [ this, self = shared_from_this(), buffer ](boost::system::error_code ec, std::size_t length) {
|
boost::asio::bind_executor(strand_, [ this, self = shared_from_this(), buffer ](boost::system::error_code ec, std::size_t length) {
|
||||||
|
messages_.pop_front();
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "StreamSession write error (msg length: " << length << "): " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "StreamSession write error (msg length: " << length << "): " << ec.message() << "\n";
|
||||||
|
@ -148,7 +148,10 @@ void StreamSession::sendAsync(shared_const_buffer const_buf, bool send_now)
|
||||||
{
|
{
|
||||||
strand_.post([ this, self = shared_from_this(), const_buf, send_now ]() {
|
strand_.post([ this, self = shared_from_this(), const_buf, send_now ]() {
|
||||||
// delete PCM chunks that are older than the overall buffer duration
|
// delete PCM chunks that are older than the overall buffer duration
|
||||||
messages_.erase(std::remove_if(messages_.begin(), messages_.end(),
|
if (messages_.size() > 1)
|
||||||
|
{
|
||||||
|
// don't remove the first message as it might beeing sent already
|
||||||
|
messages_.erase(std::remove_if(messages_.begin() + 1, messages_.end(),
|
||||||
[this](const shared_const_buffer& buffer) {
|
[this](const shared_const_buffer& buffer) {
|
||||||
const auto& msg = buffer.message();
|
const auto& msg = buffer.message();
|
||||||
if (!msg.is_pcm_chunk)
|
if (!msg.is_pcm_chunk)
|
||||||
|
@ -157,6 +160,7 @@ void StreamSession::sendAsync(shared_const_buffer const_buf, bool send_now)
|
||||||
return (age > std::chrono::milliseconds(bufferMs_) + 100ms);
|
return (age > std::chrono::milliseconds(bufferMs_) + 100ms);
|
||||||
}),
|
}),
|
||||||
messages_.end());
|
messages_.end());
|
||||||
|
}
|
||||||
|
|
||||||
if (send_now)
|
if (send_now)
|
||||||
messages_.push_front(const_buf);
|
messages_.push_front(const_buf);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue