diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index c2564fbac..ff0e206d0 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -49,7 +49,6 @@ static struct spa_log_topic *log_topic = &SPA_LOG_TOPIC(0, "spa.audiomixer"); #define MAX_BUFFERS 64 #define MAX_PORTS 128 #define MAX_CHANNELS 64 -#define MAX_BUFFER_SIZE (MAX_SAMPLES * MAX_CHANNELS * 8) #define PORT_DEFAULT_VOLUME 1.0 #define PORT_DEFAULT_MUTE false @@ -74,8 +73,6 @@ struct buffer { struct spa_buffer *buffer; struct spa_meta_header *h; struct spa_buffer buf; - struct spa_data datas[1]; - struct spa_chunk chunk[1]; }; struct port { @@ -128,9 +125,6 @@ struct impl { unsigned int started:1; uint32_t stride; uint32_t blocks; - - uint8_t empty[MAX_BUFFER_SIZE]; - }; #define PORT_VALID(p) ((p) != NULL && (p)->valid) @@ -657,6 +651,7 @@ impl_node_port_use_buffers(void *object, b->flags = 0; b->id = i; b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h)); + b->buf = *buffers[i]; if (d[0].data == NULL) { spa_log_error(this->log, "%p: invalid memory on buffer %p", this, @@ -725,9 +720,9 @@ static int impl_node_process(void *object) struct impl *this = object; struct port *outport; struct spa_io_buffers *outio; - uint32_t n_samples, n_buffers, i, maxsize; + uint32_t n_buffers, i, maxsize; struct buffer **buffers; - struct buffer *outb; + struct buffer *outb; const void **datas; spa_return_val_if_fail(this != NULL, -EINVAL); @@ -752,7 +747,7 @@ static int impl_node_process(void *object) datas = alloca(MAX_PORTS * sizeof(void *)); n_buffers = 0; - maxsize = MAX_SAMPLES * this->stride; + maxsize = UINT32_MAX; for (i = 0; i < this->last_port; i++) { struct port *inport = GET_IN_PORT(this, i); @@ -789,22 +784,22 @@ static int impl_node_process(void *object) return -EPIPE; } - n_samples = maxsize / this->stride; - if (n_buffers == 1) { *outb->buffer = *buffers[0]->buffer; } else { - outb->buffer->n_datas = 1; - outb->buffer->datas = outb->datas; - outb->datas[0].data = this->empty; - outb->datas[0].chunk = outb->chunk; - outb->datas[0].chunk->offset = 0; - outb->datas[0].chunk->size = n_samples * this->stride; - outb->datas[0].chunk->stride = this->stride; - outb->datas[0].maxsize = maxsize; + struct spa_data *d = outb->buf.datas; - mix_ops_process(&this->ops, outb->datas[0].data, datas, n_buffers, n_samples); + *outb->buffer = outb->buf; + + maxsize = SPA_MIN(maxsize, d[0].maxsize); + + d[0].chunk->offset = 0; + d[0].chunk->size = maxsize; + d[0].chunk->stride = this->stride; + + mix_ops_process(&this->ops, d[0].data, + datas, n_buffers, maxsize / this->stride); } outio->buffer_id = outb->id; diff --git a/spa/plugins/audiomixer/mixer-dsp.c b/spa/plugins/audiomixer/mixer-dsp.c index b04e93f1c..d205590d7 100644 --- a/spa/plugins/audiomixer/mixer-dsp.c +++ b/spa/plugins/audiomixer/mixer-dsp.c @@ -73,8 +73,6 @@ struct buffer { struct spa_buffer *buffer; struct spa_meta_header *h; struct spa_buffer buf; - struct spa_data datas[1]; - struct spa_chunk chunk[1]; }; struct port { @@ -126,8 +124,6 @@ struct impl { unsigned int have_format:1; unsigned int started:1; - - float empty[MAX_SAMPLES + MAX_ALIGN]; }; #define PORT_VALID(p) ((p) != NULL && (p)->valid) @@ -601,12 +597,13 @@ impl_node_port_use_buffers(void *object, b->flags = 0; b->id = i; b->h = spa_buffer_find_meta_data(buffers[i], SPA_META_Header, sizeof(*b->h)); + b->buf = *buffers[i]; if (d[0].data == NULL) { spa_log_error(this->log, "%p: invalid memory on buffer %d", this, i); return -EINVAL; } - if (!SPA_IS_ALIGNED(d[0].data, 16)) { + if (!SPA_IS_ALIGNED(d[0].data, 32)) { spa_log_warn(this->log, "%p: memory on buffer %d not aligned", this, i); } if (direction == SPA_DIRECTION_OUTPUT) @@ -668,9 +665,9 @@ static int impl_node_process(void *object) struct impl *this = object; struct port *outport; struct spa_io_buffers *outio; - uint32_t n_samples, n_buffers, i, maxsize; - struct buffer **buffers; - struct buffer *outb; + uint32_t n_buffers, i, maxsize; + struct buffer **buffers; + struct buffer *outb; const void **datas; spa_return_val_if_fail(this != NULL, -EINVAL); @@ -695,7 +692,7 @@ static int impl_node_process(void *object) datas = alloca(MAX_PORTS * sizeof(void *)); n_buffers = 0; - maxsize = MAX_SAMPLES * sizeof(float); + maxsize = UINT32_MAX; for (i = 0; i < this->last_port; i++) { struct port *inport = GET_IN_PORT(this, i); @@ -732,21 +729,20 @@ static int impl_node_process(void *object) return -EPIPE; } - n_samples = maxsize / sizeof(float); - if (n_buffers == 1) { *outb->buffer = *buffers[0]->buffer; - } - else { - outb->buffer->n_datas = 1; - outb->buffer->datas = outb->datas; - outb->datas[0].data = SPA_PTR_ALIGN(this->empty, MAX_ALIGN, void); - outb->datas[0].chunk = outb->chunk; - outb->datas[0].chunk->offset = 0; - outb->datas[0].chunk->size = n_samples * sizeof(float); - outb->datas[0].chunk->stride = sizeof(float); + } else { + struct spa_data *d = outb->buf.datas; + *outb->buffer = outb->buf; - mix_ops_process(&this->ops, outb->datas[0].data, datas, n_buffers, n_samples); + maxsize = SPA_MIN(maxsize, d[0].maxsize); + + d[0].chunk->offset = 0; + d[0].chunk->size = maxsize; + d[0].chunk->stride = sizeof(float); + + mix_ops_process(&this->ops, d[0].data, + datas, n_buffers, maxsize / sizeof(float)); } outio->buffer_id = outb->id;