File 0001-client-node-fix-buffer-size-calculation.patch of Package pipewire.16602

From 61c1fe546e374db03f3b05749123cf9739b966f2 Mon Sep 17 00:00:00 2001
From: Wim Taymans <wtaymans@redhat.com>
Date: Mon, 15 Jun 2020 20:44:08 +0200
Subject: [PATCH] client-node: fix buffer size calculation

Calculate the size of the buffer as the difference between the first
byte and the last byte. This takes into account the alignment.
---
 src/modules/module-client-node/client-node.c | 13 ++++++-------
 src/modules/module-client-node/remote-node.c |  6 +++---
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c
index 43bd8570..09980bd1 100644
--- a/src/modules/module-client-node/client-node.c
+++ b/src/modules/module-client-node/client-node.c
@@ -769,8 +769,7 @@ do_port_use_buffers(struct impl *impl,
 	for (i = 0; i < n_buffers; i++) {
 		struct buffer *b = &mix->buffers[i];
 		struct pw_memblock *mem, *m;
-		size_t data_size;
-		void *baseptr;
+		void *baseptr, *endptr;
 
 		b->outbuf = buffers[i];
 		memcpy(&b->buffer, buffers[i], sizeof(struct spa_buffer));
@@ -787,14 +786,14 @@ do_port_use_buffers(struct impl *impl,
 		if ((mem = pw_mempool_find_ptr(impl->context->pool, baseptr)) == NULL)
 			return -EINVAL;
 
-		data_size = buffers[i]->n_datas * sizeof(struct spa_chunk);
+		endptr = SPA_MEMBER(baseptr, buffers[i]->n_datas * sizeof(struct spa_chunk), void);
 		for (j = 0; j < buffers[i]->n_metas; j++) {
-			data_size += SPA_ROUND_UP_N(buffers[i]->metas[j].size, 8);
+			endptr = SPA_MEMBER(endptr, SPA_ROUND_UP_N(buffers[i]->metas[j].size, 8), void);
 		}
 		for (j = 0; j < buffers[i]->n_datas; j++) {
 			struct spa_data *d = buffers[i]->datas;
 			if (d->type == SPA_DATA_MemPtr)
-				data_size += d->maxsize;
+				endptr = SPA_MEMBER(d->data, d->maxsize, void);
 		}
 
 		m = pw_mempool_import_block(this->client->pool, mem);
@@ -805,8 +804,8 @@ do_port_use_buffers(struct impl *impl,
 
 		mb[i].buffer = &b->buffer;
 		mb[i].mem_id = m->id;
-		mb[i].offset = SPA_PTRDIFF(baseptr, SPA_MEMBER(mem->map->ptr, 0, void));
-		mb[i].size = data_size;
+		mb[i].offset = SPA_PTRDIFF(baseptr, mem->map->ptr);
+		mb[i].size = SPA_PTRDIFF(endptr, baseptr);
 		spa_log_debug(this->log, NAME" %p: buffer %d %d %d %d", this, i, mb[i].mem_id,
 				mb[i].offset, mb[i].size);
 
diff --git a/src/modules/module-client-node/remote-node.c b/src/modules/module-client-node/remote-node.c
index a68e7507..8ab1bac3 100644
--- a/src/modules/module-client-node/remote-node.c
+++ b/src/modules/module-client-node/remote-node.c
@@ -653,7 +653,7 @@ client_node_port_use_buffers(void *object,
 		b->datas = SPA_MEMBER(b->metas, sizeof(struct spa_meta) * b->n_metas,
 				       struct spa_data);
 
-		pw_log_debug("add buffer %d %d %u %u %p", mm->block->id,
+		pw_log_debug("add buffer mem:%d id:%d offset:%u size:%u %p", mm->block->id,
 				bid->id, buffers[i].offset, buffers[i].size, bid->buf);
 
 		offset = 0;
@@ -696,8 +696,8 @@ client_node_port_use_buffers(void *object,
 				int offs = SPA_PTR_TO_INT(d->data);
 				d->data = SPA_MEMBER(mm->ptr, offs, void);
 				d->fd = -1;
-				pw_log_debug(" data %d %u -> mem %p maxsize %d",
-						j, bid->id, d->data, d->maxsize);
+				pw_log_debug(" data %d id:%u -> mem:%p offs:%d maxsize:%d",
+						j, bid->id, d->data, offs, d->maxsize);
 			} else {
 				pw_log_warn("unknown buffer data type %d", d->type);
 			}
openSUSE Build Service is sponsored by