From a79b5c86ea33d7103c07552ecbbde54e1c01e7bd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 7 Sep 2022 13:07:28 +0200 Subject: [PATCH] pulse-server: Handle clients that send more than requested A client can sometimes send more data than we requested. PulseAudio keeps the extra data around, it just asks for more data when it consumed some of it. PipeWire however always tries to keep tlength worth of data, as specified in the PulseAudio docs... Keep track of how much extra data has been sent and keep this around as well. Make sure we flush this extra data as well. Fixes #2626 --- src/modules/module-protocol-pulse/server.c | 4 ++++ src/modules/module-protocol-pulse/stream.c | 2 ++ src/modules/module-protocol-pulse/stream.h | 1 + 3 files changed, 7 insertions(+) diff --git a/src/modules/module-protocol-pulse/server.c b/src/modules/module-protocol-pulse/server.c index b363a66bc..471394afe 100644 --- a/src/modules/module-protocol-pulse/server.c +++ b/src/modules/module-protocol-pulse/server.c @@ -172,6 +172,10 @@ static int handle_memblock(struct client *client, struct message *msg) } else if (filled + msg->length > stream->attr.maxlength) { /* overrun */ stream_send_overflow(stream); + } else if (filled + msg->length > stream->attr.tlength) { + stream->extra_tlength = filled + msg->length - stream->attr.tlength; + pw_log_info("client %p [%s]: received %u more than asked for channel %d", + client, client->name, stream->extra_tlength, channel); } /* always write data to ringbuffer, we expect the other side diff --git a/src/modules/module-protocol-pulse/stream.c b/src/modules/module-protocol-pulse/stream.c index 730580da3..55cc82627 100644 --- a/src/modules/module-protocol-pulse/stream.c +++ b/src/modules/module-protocol-pulse/stream.c @@ -163,6 +163,7 @@ void stream_flush(struct stream *stream) if (stream->attr.prebuf > 0) stream->in_prebuf = true; + stream->extra_tlength = 0; stream->playing_for = 0; stream->underrun_for = -1; stream->is_underrun = true; @@ -193,6 +194,7 @@ uint32_t stream_pop_missing(struct stream *stream) avail = stream->write_index - stream->read_index; missing = stream->attr.tlength; + missing += stream->extra_tlength; missing -= stream->requested; missing -= avail; diff --git a/src/modules/module-protocol-pulse/stream.h b/src/modules/module-protocol-pulse/stream.h index 7ee6de36b..266ddfe6a 100644 --- a/src/modules/module-protocol-pulse/stream.h +++ b/src/modules/module-protocol-pulse/stream.h @@ -97,6 +97,7 @@ struct stream { struct sample_spec ss; struct channel_map map; struct buffer_attr attr; + uint32_t extra_tlength; uint32_t frame_size; uint32_t rate; uint64_t lat_usec;