diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index 8028d64ca..a1c1ebb79 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -377,7 +377,7 @@ pull_frames(struct state *state, total_frames += n_frames; to_write -= n_frames; - spa_log_trace(state->log, "alsa-util %p: written %lu frames, left %ld", state, total_frames, to_write); + spa_log_trace(state->log, "alsa-util %p: %u written %lu frames, left %ld", state, index, total_frames, to_write); } try_pull(state, frames, do_pull); diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index c6ef12a23..0d2691b71 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -686,46 +686,47 @@ static struct spa_buffer *find_free_buffer(struct impl *this, struct port *port) static void do_volume(struct impl *this, struct spa_buffer *dbuf, struct spa_buffer *sbuf) { - uint32_t si, di, i, n_samples, n_bytes, soff, doff; + uint32_t i, n_samples, n_bytes; struct spa_data *sd, *dd; int16_t *src, *dst; double volume; + uint32_t towrite, savail, davail; + uint32_t sindex, dindex; volume = this->props.volume; - si = di = 0; - soff = doff = 0; + sd = sbuf->datas; + dd = dbuf->datas; - while (true) { - if (si == sbuf->n_datas || di == dbuf->n_datas) - break; + savail = spa_ringbuffer_get_read_index(&sd[0].chunk->area, &sindex); + davail = spa_ringbuffer_get_write_index(&dd[0].chunk->area, &dindex); + davail = dd[0].maxsize - davail; - sd = &sbuf->datas[si]; - dd = &dbuf->datas[di]; + towrite = SPA_MIN(savail, davail); - src = (int16_t *) ((uint8_t *) sd->data + sd->chunk->area.readindex + soff); - dst = (int16_t *) ((uint8_t *) dd->data + doff); + while (towrite > 0) { + uint32_t soffset = sindex % sd[0].maxsize; + uint32_t doffset = dindex % dd[0].maxsize; - n_bytes = SPA_MIN(sd->chunk->area.writeindex - soff, dd->maxsize - doff); - n_samples = n_bytes / sizeof(uint16_t); + src = SPA_MEMBER(sd[0].data, soffset, int16_t); + dst = SPA_MEMBER(dd[0].data, doffset, int16_t); + n_bytes = towrite; + if (soffset + n_bytes > sd[0].maxsize) + n_bytes = sd[0].maxsize - soffset; + if (doffset + n_bytes > dd[0].maxsize) + n_bytes = dd[0].maxsize - doffset; + + n_samples = n_bytes / sizeof(int16_t); for (i = 0; i < n_samples; i++) dst[i] = src[i] * volume; - soff += n_bytes; - doff += n_bytes; - - spa_ringbuffer_set_avail(&dd->chunk->area, doff); - - if (soff >= sd->chunk->area.writeindex) { - si++; - soff = 0; - } - if (doff >= dd->maxsize) { - di++; - doff = 0; - } + sindex += n_bytes; + dindex += n_bytes; + towrite -= n_bytes; } + spa_ringbuffer_read_update(&sd[0].chunk->area, sindex); + spa_ringbuffer_write_update(&dd[0].chunk->area, dindex); } static int impl_node_process_input(struct spa_node *node) @@ -751,8 +752,10 @@ static int impl_node_process_input(struct spa_node *node) input = in_port->io; spa_return_val_if_fail(input != NULL, -EIO); - if (input->buffer_id >= in_port->n_buffers) - return SPA_STATUS_NEED_BUFFER; + if (input->buffer_id >= in_port->n_buffers) { + input->status = -EINVAL; + return -EINVAL; + } if ((dbuf = find_free_buffer(this, out_port)) == NULL) { spa_log_error(this->log, NAME " %p: out of buffers", this); diff --git a/spa/tests/test-graph.c b/spa/tests/test-graph.c index ea7b826c4..a6d27139c 100644 --- a/spa/tests/test-graph.c +++ b/spa/tests/test-graph.c @@ -171,7 +171,7 @@ init_buffer(struct data *data, struct spa_buffer **bufs, struct buffer *ba, int b->datas[0].maxsize = size; b->datas[0].data = malloc(size); b->datas[0].chunk = &b->chunks[0]; - spa_ringbuffer_set_avail(&b->datas[0].chunk->area, size); + spa_ringbuffer_set_avail(&b->datas[0].chunk->area, 0); b->datas[0].chunk->stride = 0; } }