pulse-server: ensure positive stream delay in GET_PLAYBACK/RECORD_LATENCY

Pulseaudio protocol requires stream latency is uint64. Clamp the
Pipewire signed latency to the range, better than wrapping around.
This commit is contained in:
Pauli Virtanen 2024-11-19 22:00:57 +02:00 committed by Wim Taymans
parent 5a492c2265
commit 48ad0861e4

View file

@ -2161,6 +2161,7 @@ static int do_get_playback_latency(struct client *client, uint32_t command, uint
uint32_t channel;
struct timeval tv, now;
struct stream *stream;
uint64_t delay;
int res;
if ((res = message_get(m,
@ -2182,9 +2183,11 @@ static int do_get_playback_latency(struct client *client, uint32_t command, uint
gettimeofday(&now, NULL);
delay = SPA_CLAMP(stream->delay, 0, INT64_MAX);
reply = reply_new(client, tag);
message_put(reply,
TAG_USEC, stream->delay, /* sink latency + queued samples */
TAG_USEC, delay, /* sink latency + queued samples */
TAG_USEC, 0LL, /* always 0 */
TAG_BOOLEAN, stream->playing_for > 0 &&
!stream->corked, /* playing state */
@ -2210,6 +2213,7 @@ static int do_get_record_latency(struct client *client, uint32_t command, uint32
uint32_t channel;
struct timeval tv, now;
struct stream *stream;
uint64_t delay;
int res;
if ((res = message_get(m,
@ -2229,10 +2233,13 @@ static int do_get_record_latency(struct client *client, uint32_t command, uint32
gettimeofday(&now, NULL);
delay = SPA_CLAMP(stream->delay, 0, INT64_MAX);
reply = reply_new(client, tag);
message_put(reply,
TAG_USEC, 0LL, /* monitor latency */
TAG_USEC, stream->delay, /* source latency + queued */
TAG_USEC, delay, /* source latency + queued */
TAG_BOOLEAN, !stream->corked, /* playing state */
TAG_TIMEVAL, &tv,
TAG_TIMEVAL, &now,