From ff05ebada63c1c91473e1034bfa92da7f938b1b0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 20 Jun 2022 11:39:00 +0200 Subject: [PATCH] pulse-server: tweak record attributes Add some 'before' debug info of the attributes. First clamp the fragsize to the maxlength and then clamp to the minfrag or else we could bypass the configured minfrag by setting a lower maxlength. Scale the maxlength to at least twice the fragsize so that we can buffer enough data in the ringbuffer to serve fragsize bytes. See #2447 --- .../module-protocol-pulse/pulse-server.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 56e10d2ca..5d230afb5 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -452,6 +452,10 @@ static uint32_t fix_playback_buffer_attr(struct stream *s, struct buffer_attr *a if (frame_size == 0) frame_size = 4; + pw_log_info("[%s] maxlength:%u tlength:%u minreq:%u prebuf:%u", + s->client->name, attr->maxlength, attr->tlength, + attr->minreq, attr->prebuf); + minreq = frac_to_bytes_round_up(s->min_req, &s->ss); max_latency = defs->quantum_limit * frame_size; @@ -648,6 +652,9 @@ static uint32_t fix_record_buffer_attr(struct stream *s, struct buffer_attr *att if (frame_size == 0) frame_size = 4; + pw_log_info("[%s] maxlength:%u fragsize:%u", + s->client->name, attr->maxlength, attr->fragsize); + if (attr->maxlength == (uint32_t) -1 || attr->maxlength > MAXLENGTH) attr->maxlength = MAXLENGTH; attr->maxlength -= attr->maxlength % frame_size; @@ -657,12 +664,9 @@ static uint32_t fix_record_buffer_attr(struct stream *s, struct buffer_attr *att if (attr->fragsize == (uint32_t) -1 || attr->fragsize == 0) attr->fragsize = frac_to_bytes_round_up(s->default_frag, &s->ss); - attr->fragsize -= attr->fragsize % frame_size; + attr->fragsize = SPA_MIN(attr->fragsize, attr->maxlength); + attr->fragsize = SPA_ROUND_UP(attr->fragsize, frame_size); attr->fragsize = SPA_MAX(attr->fragsize, minfrag); - attr->fragsize = SPA_MAX(attr->fragsize, frame_size); - - if (attr->fragsize > attr->maxlength) - attr->fragsize = attr->maxlength; attr->tlength = attr->minreq = attr->prebuf = 0; @@ -673,6 +677,9 @@ static uint32_t fix_record_buffer_attr(struct stream *s, struct buffer_attr *att } else { latency = attr->fragsize; } + /* make sure can queue at least to fragsize without overruns */ + if (attr->maxlength < attr->fragsize * 2) + attr->maxlength = attr->fragsize * 2; pw_log_info("[%s] maxlength:%u fragsize:%u minfrag:%u latency:%u", s->client->name, attr->maxlength, attr->fragsize, minfrag,