mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-03 04:06:31 +02:00
Reformat code
This commit is contained in:
parent
25b289e627
commit
051ba91cfc
1 changed files with 22 additions and 17 deletions
|
@ -51,16 +51,18 @@ template <typename Rep, typename Period>
|
||||||
void wait(boost::asio::steady_timer& timer, const std::chrono::duration<Rep, Period>& duration, std::function<void()> handler)
|
void wait(boost::asio::steady_timer& timer, const std::chrono::duration<Rep, Period>& duration, std::function<void()> handler)
|
||||||
{
|
{
|
||||||
timer.expires_after(duration);
|
timer.expires_after(duration);
|
||||||
timer.async_wait([handler = std::move(handler)](const boost::system::error_code& ec) {
|
timer.async_wait(
|
||||||
if (ec)
|
[handler = std::move(handler)](const boost::system::error_code& ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error during async wait: " << ec.message() << "\n";
|
if (ec)
|
||||||
}
|
{
|
||||||
else
|
LOG(ERROR, LOG_TAG) << "Error during async wait: " << ec.message() << "\n";
|
||||||
{
|
}
|
||||||
handler();
|
else
|
||||||
}
|
{
|
||||||
});
|
handler();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -265,7 +267,8 @@ void AlsaStream::do_read()
|
||||||
// Calculate when there will be enough data available, add half chunk duration tolerance and try later
|
// Calculate when there will be enough data available, add half chunk duration tolerance and try later
|
||||||
auto available = std::chrono::milliseconds(static_cast<size_t>(double(avail) / double(sampleFormat_.rate()) * 1000.));
|
auto available = std::chrono::milliseconds(static_cast<size_t>(double(avail) / double(sampleFormat_.rate()) * 1000.));
|
||||||
auto missing = chunk_->duration<std::chrono::milliseconds>() - available;
|
auto missing = chunk_->duration<std::chrono::milliseconds>() - available;
|
||||||
LOG(INFO, LOG_TAG) << "Not enough data available: " << available.count() << " ms, missing: " << missing.count() << " ms, needed: " << chunk_->duration<std::chrono::milliseconds>().count() << " ms\n";
|
LOG(INFO, LOG_TAG) << "Not enough data available: " << available.count() << " ms, missing: " << missing.count()
|
||||||
|
<< " ms, needed: " << chunk_->duration<std::chrono::milliseconds>().count() << " ms\n";
|
||||||
missing += chunk_->duration<std::chrono::milliseconds>() / 2;
|
missing += chunk_->duration<std::chrono::milliseconds>() / 2;
|
||||||
resync(missing);
|
resync(missing);
|
||||||
first_ = true;
|
first_ = true;
|
||||||
|
@ -273,12 +276,14 @@ void AlsaStream::do_read()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// check if there is too much data available, i.e. if we are far behind
|
// check if there is too much data available, i.e. if we are far behind
|
||||||
else if (avail > static_cast<int32_t>(3*chunk_->getFrameCount()))
|
else if (avail > static_cast<int32_t>(3 * chunk_->getFrameCount()))
|
||||||
{
|
{
|
||||||
// Fast forward, by reading and dropping audio frames
|
// Fast forward, by reading and dropping audio frames
|
||||||
// const auto newAvail = static_cast<int32_t>(chunk_->getFrameCount() + static_cast<uint32_t>(chunk_->format.msRate() * 20));
|
// const auto newAvail = static_cast<int32_t>(chunk_->getFrameCount() + static_cast<uint32_t>(chunk_->format.msRate() * 20));
|
||||||
const auto newAvail = 1.5 * chunk_->getFrameCount();
|
const auto newAvail = 1.5 * chunk_->getFrameCount();
|
||||||
LOG(INFO, LOG_TAG) << "Too many frames available, fast forwarding from " << avail << " frames (" << double(avail) / double(sampleFormat_.rate()) * 1000. << " ms) to " << newAvail << " frames (" << double(newAvail) / double(sampleFormat_.rate()) * 1000. << " ms)\n";
|
LOG(INFO, LOG_TAG) << "Too many frames available, fast forwarding from " << avail << " frames ("
|
||||||
|
<< double(avail) / double(sampleFormat_.rate()) * 1000. << " ms) to " << newAvail << " frames ("
|
||||||
|
<< double(newAvail) / double(sampleFormat_.rate()) * 1000. << " ms)\n";
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
int count = snd_pcm_readi(handle_, chunk_->payload, std::min(chunk_->getFrameCount(), static_cast<uint32_t>(avail - newAvail)));
|
int count = snd_pcm_readi(handle_, chunk_->payload, std::min(chunk_->getFrameCount(), static_cast<uint32_t>(avail - newAvail)));
|
||||||
|
@ -288,9 +293,9 @@ void AlsaStream::do_read()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
avail -= count;
|
avail -= count;
|
||||||
LOG(DEBUG, LOG_TAG) << "Read " << count << " frames (" << double(count) / double(sampleFormat_.rate()) * 1000. << " ms), available: " << avail << " frames (" << double(avail) / double(sampleFormat_.rate()) * 1000. << " ms)\n";
|
LOG(DEBUG, LOG_TAG) << "Read " << count << " frames (" << double(count) / double(sampleFormat_.rate()) * 1000.
|
||||||
}
|
<< " ms), available: " << avail << " frames (" << double(avail) / double(sampleFormat_.rate()) * 1000. << " ms)\n";
|
||||||
while (avail > newAvail);
|
} while (avail > newAvail);
|
||||||
first_ = true;
|
first_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue