diff --git a/client/stream.cpp b/client/stream.cpp index 2b34f75e..ee53bc7f 100644 --- a/client/stream.cpp +++ b/client/stream.cpp @@ -102,7 +102,7 @@ void Stream::addChunk(unique_ptr 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 recent_; + if (chunks_.back_copy(recent_)) + { + cs::nsec req_chunk_duration = cs::nsec(static_cast(frames / format_.nsRate())); + auto youngest = recent_->end() - req_chunk_duration; + cs::msec age = std::chrono::duration_cast(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(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 diff --git a/common/queue.h b/common/queue.h index 1beab462..593e6537 100644 --- a/common/queue.h +++ b/common/queue.h @@ -98,6 +98,16 @@ public: cond_.notify_one(); } + bool back_copy(T& copy) + { + std::lock_guard mlock(mutex_); + if (queue_.empty()) + return false; + T t = queue_.back(); + copy = t; + return true; + } + void push_front(T&& item) { { diff --git a/server/streamreader/pipe_stream.cpp b/server/streamreader/pipe_stream.cpp index f3cb207a..11364fdc 100644 --- a/server/streamreader/pipe_stream.cpp +++ b/server/streamreader/pipe_stream.cpp @@ -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";