Commit 61c1fe54 authored by Wim Taymans's avatar Wim Taymans
Browse files

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.
parent fd0ebdd7
Pipeline #161060 passed with stages
in 1 minute and 26 seconds
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment