mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 23:56:43 +02:00
Remove PosixStream layer
This commit is contained in:
parent
86cd4b2b63
commit
275a53a845
21 changed files with 201 additions and 162 deletions
|
@ -1,6 +1,6 @@
|
|||
/***
|
||||
This file is part of snapcast
|
||||
Copyright (C) 2014-2021 Johannes Pohl
|
||||
Copyright (C) 2014-2024 Johannes Pohl
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -76,18 +76,6 @@ AlsaStream::AlsaStream(PcmStream::Listener* pcmListener, boost::asio::io_context
|
|||
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));
|
||||
double silence_threshold_percent = 0.;
|
||||
try
|
||||
{
|
||||
silence_threshold_percent = cpt::stod(uri_.getQuery("silence_threshold_percent", "0"));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
int32_t max_amplitude = std::pow(2, sampleFormat_.bits() - 1) - 1;
|
||||
silence_threshold_ = max_amplitude * (silence_threshold_percent / 100.);
|
||||
LOG(DEBUG, LOG_TAG) << "Device: " << device_ << ", silence threshold percent: " << silence_threshold_percent
|
||||
<< ", silence threshold amplitude: " << silence_threshold_ << "\n";
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,10 +87,6 @@ void AlsaStream::start()
|
|||
// max_idle_bytes_ = sampleFormat_.rate() * sampleFormat_.frameSize() * dryout_ms_ / 1000;
|
||||
|
||||
initAlsa();
|
||||
chunk_ = std::make_unique<msg::PcmChunk>(sampleFormat_, chunk_ms_);
|
||||
silent_chunk_ = std::vector<char>(chunk_->payloadSize, 0);
|
||||
LOG(DEBUG, LOG_TAG) << "Chunk duration: " << chunk_->durationMs() << " ms, frames: " << chunk_->getFrameCount() << ", size: " << chunk_->payloadSize
|
||||
<< "\n";
|
||||
first_ = true;
|
||||
tvEncodedChunk_ = std::chrono::steady_clock::now();
|
||||
PcmStream::start();
|
||||
|
@ -205,41 +189,6 @@ void AlsaStream::uninitAlsa()
|
|||
}
|
||||
|
||||
|
||||
bool AlsaStream::isSilent(const msg::PcmChunk& chunk) const
|
||||
{
|
||||
if (silence_threshold_ == 0)
|
||||
return (std::memcmp(chunk.payload, silent_chunk_.data(), silent_chunk_.size()) == 0);
|
||||
|
||||
if (sampleFormat_.sampleSize() == 1)
|
||||
{
|
||||
auto payload = chunk.getPayload<int8_t>();
|
||||
for (size_t n = 0; n < payload.second; ++n)
|
||||
{
|
||||
if (abs(payload.first[n]) > silence_threshold_)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sampleFormat_.sampleSize() == 2)
|
||||
{
|
||||
auto payload = chunk.getPayload<int16_t>();
|
||||
for (size_t n = 0; n < payload.second; ++n)
|
||||
{
|
||||
if (abs(payload.first[n]) > silence_threshold_)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (sampleFormat_.sampleSize() == 4)
|
||||
{
|
||||
auto payload = chunk.getPayload<int32_t>();
|
||||
for (size_t n = 0; n < payload.second; ++n)
|
||||
{
|
||||
if (abs(payload.first[n]) > silence_threshold_)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AlsaStream::do_read()
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue