latency: handle negative latency correctly

In our current world, it is possible to have a negative delay. This
means that the stream should be delayed to sync with other streams.

The pulse-server sets negative delay and the Latency message can hold
those negative values so make sure we handle them in the helper
functions as well.

Do the delay calculations in pw_stream and JACK with signed values to
correctly handle negative values. Clamp JACK latency range to 0 because
negative latency is not supported in JACK.

We should also probably make sure we never end up with negative
latency, mostly in ALSA when we set a Latency offset, but that is
another detail.
This commit is contained in:
Wim Taymans 2024-10-23 10:47:58 +02:00
parent 9243ed0cbd
commit da86026b7a
5 changed files with 40 additions and 20 deletions

View file

@ -38,21 +38,27 @@ spa_latency_info_combine_start(struct spa_latency_info *info, enum spa_direction
{
*info = SPA_LATENCY_INFO(direction,
.min_quantum = FLT_MAX,
.max_quantum = 0.0f,
.min_rate = UINT32_MAX,
.max_rate = 0,
.min_ns = UINT64_MAX,
.max_ns = 0);
.max_quantum = FLT_MIN,
.min_rate = INT32_MAX,
.max_rate = INT32_MIN,
.min_ns = INT64_MAX,
.max_ns = INT64_MIN);
}
static inline void
spa_latency_info_combine_finish(struct spa_latency_info *info)
{
if (info->min_quantum == FLT_MAX)
info->min_quantum = 0;
if (info->min_rate == UINT32_MAX)
if (info->max_quantum == FLT_MIN)
info->max_quantum = 0;
if (info->min_rate == INT32_MAX)
info->min_rate = 0;
if (info->min_ns == UINT64_MAX)
if (info->max_rate == INT32_MIN)
info->max_rate = 0;
if (info->min_ns == INT64_MAX)
info->min_ns = 0;
if (info->max_ns == INT64_MIN)
info->max_ns = 0;
}
static inline int