Skip to content

Commit abef163

Browse files
committed
Report the ring PipeWire was given, not a racing measurement of it
poll()'s one-shot quantum report sized the ring as free_space() + available(). Those are two separate samples of a position the realtime callback owns, and free_space() derives from available() itself, so a process() that consumes between the two makes the sum understate the ring by whatever it took. That figure decides which line is printed. Understated far enough it reports `tight`, and further still `starves` -- a WARN telling the operator their stream will underrun on every cycle and to raise --buffer-ms, about a stream that is sized correctly. Precisely the case the warning exists to distinguish. The configured size is deterministic and already factored out, so ask pipewire_ring_frames() for it; ring_capacity_() builds the ring from the same call, so the reported figure is the one the ring was actually given. The guard moves from bytes_per_frame_ to rate_ with it: nothing is divided here now, and rate_ is what the report needs to be meaningful. Reported by Copilot on PR #27.
1 parent 49e3c3d commit abef163

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/pipewire_sink.cpp‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,12 @@ void PipeWireSink::poll(int64_t now_ms) {
565565
const uint32_t quantum = this->quantum_frames_.load(std::memory_order_relaxed);
566566
if (quantum != 0 && !this->quantum_logged_.exchange(true, std::memory_order_relaxed)) {
567567
const std::lock_guard<std::mutex> lock(this->mutex_);
568-
if (this->bytes_per_frame_ != 0) {
569-
const size_t ring_frames = (this->ring_.free_space() + this->ring_.available()) /
570-
this->bytes_per_frame_;
568+
if (this->rate_ != 0) {
569+
// The size the ring was built at, rather than a measurement of it. free_space() and
570+
// available() are two samples of a position the realtime callback owns, and it can
571+
// consume between them -- their sum then understates the ring, which here would mean
572+
// warning an operator to raise --buffer-ms on a stream that is sized correctly.
573+
const size_t ring_frames = pipewire_ring_frames(this->rate_, this->buffer_ms_);
571574
const PipeWireQuantumFit fit = pipewire_quantum_fit(ring_frames, quantum, this->rate_);
572575
if (fit.starves) {
573576
// Broken rather than merely tight, and not something this player can negotiate

0 commit comments

Comments
 (0)