mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-21 13:06:15 +02:00
Make sending of silence configurable
This commit is contained in:
parent
90c7ba8a67
commit
4b7c313fa0
4 changed files with 22 additions and 6 deletions
|
@ -69,6 +69,8 @@ AlsaStream::AlsaStream(PcmListener* pcmListener, boost::asio::io_context& ioc, c
|
|||
: PcmStream(pcmListener, ioc, uri), handle_(nullptr), read_timer_(ioc), silence_(0ms)
|
||||
{
|
||||
device_ = uri_.getQuery("device", "hw:0");
|
||||
send_silence_ = (uri_.getQuery("send_silence", "false") == "true");
|
||||
idle_threshold_ = std::chrono::milliseconds(std::max(cpt::stoi(uri_.getQuery("idle_threshold", "100")), 10));
|
||||
LOG(DEBUG, LOG_TAG) << "Device: " << device_ << "\n";
|
||||
}
|
||||
|
||||
|
@ -215,7 +217,7 @@ void AlsaStream::do_read()
|
|||
if (std::memcmp(chunk_->payload, silent_chunk_.data(), silent_chunk_.size()) == 0)
|
||||
{
|
||||
silence_ += chunk_->duration<std::chrono::microseconds>();
|
||||
if (silence_ > 100ms)
|
||||
if (silence_ > idle_threshold_)
|
||||
{
|
||||
setState(ReaderState::kIdle);
|
||||
}
|
||||
|
@ -223,6 +225,8 @@ void AlsaStream::do_read()
|
|||
else
|
||||
{
|
||||
silence_ = 0ms;
|
||||
if ((state_ == ReaderState::kIdle) && !send_silence_)
|
||||
first_ = true;
|
||||
setState(ReaderState::kPlaying);
|
||||
}
|
||||
|
||||
|
@ -234,7 +238,10 @@ void AlsaStream::do_read()
|
|||
tvEncodedChunk_ = std::chrono::steady_clock::now() - duration;
|
||||
}
|
||||
|
||||
chunkRead(*chunk_);
|
||||
if ((state_ == ReaderState::kPlaying) || ((state_ == ReaderState::kIdle) && send_silence_))
|
||||
{
|
||||
chunkRead(*chunk_);
|
||||
}
|
||||
|
||||
nextTick_ += duration;
|
||||
auto currentTick = std::chrono::steady_clock::now();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue