Don't delete "on air" messages

This commit is contained in:
badaix 2020-02-27 20:49:59 +01:00
parent 4cb67c7960
commit 17f8a1e14b
2 changed files with 13 additions and 14 deletions

View file

@ -129,6 +129,7 @@ void StreamSession::stop()
void StreamSession::send_next() void StreamSession::send_next()
{ {
auto& buffer = messages_.front(); auto& buffer = messages_.front();
buffer.on_air = true;
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(); messages_.pop_front();
@ -148,19 +149,15 @@ 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
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(), 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 || buffer.on_air)
return false; return false;
auto age = chronos::clk::now() - msg.rec_time; auto age = chronos::clk::now() - msg.rec_time;
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);

View file

@ -59,7 +59,7 @@ class shared_const_buffer
}; };
public: public:
shared_const_buffer(msg::BaseMessage& message) shared_const_buffer(msg::BaseMessage& message) : on_air(false)
{ {
tv t; tv t;
message.sent = t; message.sent = t;
@ -94,6 +94,8 @@ public:
return *message_; return *message_;
} }
bool on_air;
private: private:
std::shared_ptr<Message> message_; std::shared_ptr<Message> message_;
boost::asio::const_buffer buffer_; boost::asio::const_buffer buffer_;