From 1ac1f914e3aea81e16511934ce8dd87cf6b62f33 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 28 Jan 2022 16:21:03 +0100 Subject: [PATCH] pulse-server: allows allocate MAXLENGTH for the ringbuffer See #2069 --- src/modules/module-protocol-pulse/defs.h | 2 +- .../module-protocol-pulse/pulse-server.c | 24 +++++++++---------- src/modules/module-protocol-pulse/server.c | 6 ++--- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/modules/module-protocol-pulse/defs.h b/src/modules/module-protocol-pulse/defs.h index 8a9b38644..1e2bed318 100644 --- a/src/modules/module-protocol-pulse/defs.h +++ b/src/modules/module-protocol-pulse/defs.h @@ -52,7 +52,7 @@ #define MIN_BUFFERS 1u #define MAX_BUFFERS 4u -#define MAXLENGTH (4*1024*1024) /* 4MB */ +#define MAXLENGTH (4u*1024*1024) /* 4MB */ #define SCACHE_ENTRY_SIZE_MAX (1024*1024*16) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 7e6448390..e926de4e6 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -463,7 +463,7 @@ static int reply_create_playback_stream(struct stream *stream, struct pw_manager lat.denom = stream->ss.rate; lat.num = fix_playback_buffer_attr(stream, &stream->attr); - stream->buffer = calloc(1, stream->attr.maxlength); + stream->buffer = calloc(1, MAXLENGTH); if (stream->buffer == NULL) return -errno; @@ -601,7 +601,7 @@ static int reply_create_record_stream(struct stream *stream, struct pw_manager_o lat.denom = stream->ss.rate; lat.num = fix_record_buffer_attr(stream, &stream->attr); - stream->buffer = calloc(1, stream->attr.maxlength); + stream->buffer = calloc(1, MAXLENGTH); if (stream->buffer == NULL) return -errno; @@ -1186,8 +1186,8 @@ do_process_done(struct spa_loop *loop, return -errno; spa_ringbuffer_read_data(&stream->ring, - stream->buffer, stream->attr.maxlength, - index % stream->attr.maxlength, + stream->buffer, MAXLENGTH, + index % MAXLENGTH, msg->data, towrite); client_queue_message(client, msg); @@ -1255,8 +1255,8 @@ static void stream_process(void *data) if ((stream->attr.prebuf == 0 || do_flush) && !stream->corked) { if (avail > 0) { spa_ringbuffer_read_data(&stream->ring, - stream->buffer, stream->attr.maxlength, - index % stream->attr.maxlength, + stream->buffer, MAXLENGTH, + index % MAXLENGTH, p, avail); } pd.playing_for = size; @@ -1282,8 +1282,8 @@ static void stream_process(void *data) size = SPA_MIN(size, minreq); spa_ringbuffer_read_data(&stream->ring, - stream->buffer, stream->attr.maxlength, - index % stream->attr.maxlength, + stream->buffer, MAXLENGTH, + index % MAXLENGTH, p, size); index += size; @@ -1315,10 +1315,10 @@ static void stream_process(void *data) } spa_ringbuffer_write_data(&stream->ring, - stream->buffer, stream->attr.maxlength, - index % stream->attr.maxlength, + stream->buffer, MAXLENGTH, + index % MAXLENGTH, SPA_PTROFF(p, buf->datas[0].chunk->offset, void), - SPA_MIN(size, stream->attr.maxlength)); + SPA_MIN(size, MAXLENGTH)); index += size; pd.write_inc = size; @@ -2080,7 +2080,7 @@ static int do_create_upload_stream(struct client *client, uint32_t command, uint stream->props = props; - stream->buffer = calloc(1, stream->attr.maxlength); + stream->buffer = calloc(1, MAXLENGTH); if (stream->buffer == NULL) goto error_errno; diff --git a/src/modules/module-protocol-pulse/server.c b/src/modules/module-protocol-pulse/server.c index f952cc4fa..d3bcfd4e3 100644 --- a/src/modules/module-protocol-pulse/server.c +++ b/src/modules/module-protocol-pulse/server.c @@ -178,10 +178,10 @@ static int handle_memblock(struct client *client, struct message *msg) /* always write data to ringbuffer, we expect the other side * to recover */ spa_ringbuffer_write_data(&stream->ring, - stream->buffer, stream->attr.maxlength, - index % stream->attr.maxlength, + stream->buffer, MAXLENGTH, + index % MAXLENGTH, msg->data, - SPA_MIN(msg->length, stream->attr.maxlength)); + SPA_MIN(msg->length, MAXLENGTH)); index += msg->length; stream->write_index += msg->length; spa_ringbuffer_write_update(&stream->ring, index);