mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-29 10:17:16 +02:00
Log chunk age
This commit is contained in:
parent
2b894c8b07
commit
ecd5f57b0c
3 changed files with 27 additions and 2 deletions
|
@ -102,7 +102,7 @@ void Stream::addChunk(unique_ptr<msg::PcmChunk> chunk)
|
|||
if (age > 5s + bufferMs_)
|
||||
return;
|
||||
|
||||
LOG(DEBUG, LOG_TAG) << "new chunk: " << chunk->durationMs() << " ms, age: " << age.count() << " ms, Chunks: " << chunks_.size() << "\n";
|
||||
LOG(TRACE, LOG_TAG) << "new chunk: " << chunk->durationMs() << " ms, age: " << age.count() << " ms, Chunks: " << chunks_.size() << "\n";
|
||||
|
||||
auto resampled = resampler_->resample(std::move(chunk));
|
||||
if (resampled)
|
||||
|
@ -240,6 +240,21 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
|||
return false;
|
||||
}
|
||||
|
||||
static int64_t min_buffer = 0;
|
||||
std::shared_ptr<msg::PcmChunk> recent_;
|
||||
if (chunks_.back_copy(recent_))
|
||||
{
|
||||
cs::nsec req_chunk_duration = cs::nsec(static_cast<cs::nsec::rep>(frames / format_.nsRate()));
|
||||
auto youngest = recent_->end() - req_chunk_duration;
|
||||
cs::msec age = std::chrono::duration_cast<cs::msec>(TimeProvider::serverNow() - youngest + outputBufferDacTime);
|
||||
min_buffer = std::max(min_buffer, age.count());
|
||||
if (now != lastUpdate_)
|
||||
{
|
||||
LOG(TRACE, LOG_TAG) << "getPlayerChunk duration: " << std::chrono::duration_cast<std::chrono::milliseconds>(req_chunk_duration).count() << ", min buffer: " << min_buffer << "\n";
|
||||
min_buffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// we have a chunk
|
||||
/// age = chunk age (server now - rec time: some positive value) - buffer (e.g. 1000ms) + time to DAC
|
||||
/// age = 0 => play now
|
||||
|
|
|
@ -98,6 +98,16 @@ public:
|
|||
cond_.notify_one();
|
||||
}
|
||||
|
||||
bool back_copy(T& copy)
|
||||
{
|
||||
std::lock_guard<std::mutex> mlock(mutex_);
|
||||
if (queue_.empty())
|
||||
return false;
|
||||
T t = queue_.back();
|
||||
copy = t;
|
||||
return true;
|
||||
}
|
||||
|
||||
void push_front(T&& item)
|
||||
{
|
||||
{
|
||||
|
|
|
@ -57,7 +57,7 @@ void PipeStream::do_connect()
|
|||
{
|
||||
int fd = open(uri_.path.c_str(), O_RDONLY | O_NONBLOCK);
|
||||
int pipe_size = -1;
|
||||
#ifndef MACOS
|
||||
#if !defined(MACOS)
|
||||
pipe_size = fcntl(fd, F_GETPIPE_SZ);
|
||||
#endif
|
||||
LOG(INFO, LOG_TAG) << "Stream: " << name_ << ", connect to pipe: " << uri_.path << ", fd: " << fd << ", pipe size: " << pipe_size << "\n";
|
||||
|
|
Loading…
Add table
Reference in a new issue