From 1a915c2cede9b5e58e547e7f083dc0608a0c3cbb Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 5 Sep 2022 18:13:12 +0200 Subject: [PATCH] pulse-server: set record attributes more like PulseAudio PulseAudio assigns half of the fragsize to the source latency. PulseAudio sends in chunks up to a fixed limit. Checked against #2418 --- src/modules/module-protocol-pulse/pulse-server.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index e8dc1960d..309ecbe30 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -87,6 +87,9 @@ #define DEFAULT_POSITION "[ FL FR ]" #define MAX_FORMATS 32 +/* The max amount of data we send in one block when capturing. In PulseAudio this + * size is derived from the mempool PA_MEMPOOL_SLOT_SIZE */ +#define MAX_FRAGSIZE (64*1024) #define TEMPORARY_MOVE_TIMEOUT (SPA_NSEC_PER_SEC) @@ -670,13 +673,9 @@ static uint32_t fix_record_buffer_attr(struct stream *s, struct buffer_attr *att attr->tlength = attr->minreq = attr->prebuf = 0; - if (s->early_requests) { - latency = attr->fragsize; - } else if (s->adjust_latency) { - latency = attr->fragsize; - } else { - latency = attr->fragsize; - } + /* pulseaudio configures half the fragsize as latency in the source. */ + latency = attr->fragsize / 2; + /* make sure can queue at least to fragsize without overruns */ if (attr->maxlength < attr->fragsize * 4) attr->maxlength = attr->fragsize * 4; @@ -1335,7 +1334,8 @@ do_process_done(struct spa_loop *loop, pw_log_trace("avail:%d index:%u", avail, index); while ((uint32_t)avail >= stream->attr.fragsize) { - towrite = SPA_MIN((uint32_t)avail, stream->attr.fragsize); + towrite = SPA_MIN(avail, MAX_FRAGSIZE); + towrite = SPA_ROUND_DOWN(towrite, stream->frame_size); msg = message_alloc(impl, stream->channel, towrite); if (msg == NULL)