From 7e42c905a895a4801b27281f10b9ea1500e141d2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 29 Mar 2022 09:18:18 +0200 Subject: [PATCH] remove the rate_match io Now that the stream provides us with a requested size, we don't need to use the rate_match anymore. --- pipewire-alsa/alsa-plugins/pcm_pipewire.c | 17 +---------- src/modules/module-echo-cancel.c | 30 ++----------------- src/modules/module-example-source.c | 18 ++--------- .../module-protocol-pulse/pulse-server.c | 3 +- .../module-protocol-pulse/sample-play.c | 16 ++-------- .../module-protocol-pulse/sample-play.h | 2 -- src/modules/module-protocol-simple.c | 22 ++------------ src/tools/pw-cat.c | 8 +---- 8 files changed, 12 insertions(+), 104 deletions(-) diff --git a/pipewire-alsa/alsa-plugins/pcm_pipewire.c b/pipewire-alsa/alsa-plugins/pcm_pipewire.c index f3ff8ec51..e8664d6da 100644 --- a/pipewire-alsa/alsa-plugins/pcm_pipewire.c +++ b/pipewire-alsa/alsa-plugins/pcm_pipewire.c @@ -90,7 +90,6 @@ typedef struct { struct spa_hook stream_listener; struct pw_time time; - struct spa_io_rate_match *rate_match; struct spa_audio_info_raw format; } snd_pcm_pipewire_t; @@ -374,19 +373,6 @@ static void on_stream_param_changed(void *data, uint32_t id, const struct spa_po pw_stream_update_params(pw->stream, params, n_params); } -static void on_stream_io_changed(void *data, uint32_t id, void *area, uint32_t size) -{ - snd_pcm_pipewire_t *pw = data; - switch (id) { - case SPA_IO_RateMatch: - if (pw->io.stream == SND_PCM_STREAM_PLAYBACK) - pw->rate_match = area; - break; - default: - break; - } -} - static void on_stream_drained(void *data) { snd_pcm_pipewire_t *pw = data; @@ -422,7 +408,7 @@ static void on_stream_process(void *data) if (b == NULL) return; - want = pw->rate_match ? pw->rate_match->size : hw_avail; + want = b->requested ? b->requested : hw_avail; xfer = snd_pcm_pipewire_process(pw, b, &hw_avail, want); @@ -451,7 +437,6 @@ static void on_stream_process(void *data) static const struct pw_stream_events stream_events = { PW_VERSION_STREAM_EVENTS, .param_changed = on_stream_param_changed, - .io_changed = on_stream_io_changed, .process = on_stream_process, .drained = on_stream_drained, }; diff --git a/src/modules/module-echo-cancel.c b/src/modules/module-echo-cancel.c index 41914ed66..b0cf33063 100644 --- a/src/modules/module-echo-cancel.c +++ b/src/modules/module-echo-cancel.c @@ -169,7 +169,6 @@ struct impl { void *rec_buffer[SPA_AUDIO_MAX_CHANNELS]; uint32_t rec_ringsize; struct spa_ringbuffer rec_ring; - struct spa_io_rate_match *rec_rate_match; struct pw_stream *playback; struct spa_hook playback_listener; @@ -180,7 +179,6 @@ struct impl { uint32_t play_ringsize; struct spa_ringbuffer play_ring; struct spa_ringbuffer play_delayed_ring; - struct spa_io_rate_match *play_rate_match; void *out_buffer[SPA_AUDIO_MAX_CHANNELS]; uint32_t out_ringsize; @@ -338,17 +336,6 @@ static void capture_destroy(void *d) impl->capture = NULL; } -static void capture_io_changed(void *data, uint32_t id, void *area, uint32_t size) -{ - struct impl *impl = data; - - switch (id) { - case SPA_IO_RateMatch: - impl->rec_rate_match = area; - break; - } -} - static void capture_process(void *data) { struct impl *impl = data; @@ -382,7 +369,7 @@ static void capture_process(void *data) * if it has a specific requirement, else keep the block size the same * on input and output or what the resampler needs */ if (impl->aec_blocksize == 0) { - impl->aec_blocksize = SPA_MAX(size, impl->rec_rate_match->size); + impl->aec_blocksize = size; pw_log_debug("Setting AEC block size to %u", impl->aec_blocksize); } @@ -454,7 +441,6 @@ static const struct pw_stream_events capture_events = { PW_VERSION_STREAM_EVENTS, .destroy = capture_destroy, .state_changed = input_state_changed, - .io_changed = capture_io_changed, .process = capture_process, .param_changed = input_param_changed }; @@ -523,17 +509,6 @@ static void sink_destroy(void *d) impl->sink = NULL; } -static void sink_io_changed(void *data, uint32_t id, void *area, uint32_t size) -{ - struct impl *impl = data; - - switch (id) { - case SPA_IO_RateMatch: - impl->play_rate_match = area; - break; - } -} - static void sink_process(void *data) { struct impl *impl = data; @@ -567,7 +542,7 @@ static void sink_process(void *data) } if (impl->aec_blocksize == 0) { - impl->aec_blocksize = SPA_MAX(size, impl->rec_rate_match->size); + impl->aec_blocksize = size; pw_log_debug("Setting AEC block size to %u", impl->aec_blocksize); } @@ -608,7 +583,6 @@ static const struct pw_stream_events playback_events = { static const struct pw_stream_events sink_events = { PW_VERSION_STREAM_EVENTS, .destroy = sink_destroy, - .io_changed = sink_io_changed, .process = sink_process, .state_changed = output_state_changed, .param_changed = output_param_changed diff --git a/src/modules/module-example-source.c b/src/modules/module-example-source.c index d6ea2e8dd..85a502423 100644 --- a/src/modules/module-example-source.c +++ b/src/modules/module-example-source.c @@ -95,7 +95,6 @@ struct impl { struct pw_properties *stream_props; struct pw_stream *stream; struct spa_hook stream_listener; - struct spa_io_rate_match *rate_match; struct spa_audio_info_raw info; uint32_t frame_size; @@ -157,10 +156,7 @@ static void capture_stream_process(void *d) bd = &buf->buffer->datas[0]; data = bd->data; - if (impl->rate_match) - size = SPA_MIN(impl->rate_match->size * impl->frame_size, bd->maxsize); - else - size = bd->maxsize; + size = buf->requested ? buf->requested * impl->frame_size : bd->maxsize; /* fill buffer contents here */ pw_log_info("fill buffer data %p with up to %u bytes", data, size); @@ -168,25 +164,15 @@ static void capture_stream_process(void *d) bd->chunk->size = size; bd->chunk->stride = impl->frame_size; bd->chunk->offset = 0; + buf->size = size / impl->frame_size; pw_stream_queue_buffer(impl->stream, buf); } -static void stream_io_changed(void *data, uint32_t id, void *area, uint32_t size) -{ - struct impl *impl = data; - switch (id) { - case SPA_IO_RateMatch: - impl->rate_match = area; - break; - } -} - static const struct pw_stream_events capture_stream_events = { PW_VERSION_STREAM_EVENTS, .destroy = stream_destroy, .state_changed = stream_state_changed, - .io_changed = stream_io_changed, .process = capture_stream_process }; diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 27205ce13..05c1d9b2a 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -1260,8 +1260,7 @@ static void stream_process(void *data) if (stream->direction == PW_DIRECTION_OUTPUT) { int32_t avail = spa_ringbuffer_get_read_index(&stream->ring, &index); - if (stream->rate_match) - minreq = stream->rate_match->size * stream->frame_size; + minreq = buffer->requested * stream->frame_size; if (minreq == 0) minreq = stream->attr.minreq; diff --git a/src/modules/module-protocol-pulse/sample-play.c b/src/modules/module-protocol-pulse/sample-play.c index 51511616b..37c68a312 100644 --- a/src/modules/module-protocol-pulse/sample-play.c +++ b/src/modules/module-protocol-pulse/sample-play.c @@ -61,17 +61,6 @@ static void sample_play_stream_state_changed(void *data, enum pw_stream_state ol } } -static void sample_play_stream_io_changed(void *data, uint32_t id, void *area, uint32_t size) -{ - struct sample_play *p = data; - - switch (id) { - case SPA_IO_RateMatch: - p->rate_match = area; - break; - } -} - static void sample_play_stream_destroy(void *data) { struct sample_play *p = data; @@ -111,8 +100,8 @@ static void sample_play_stream_process(void *data) return; size = SPA_MIN(size, buf->datas[0].maxsize); - if (p->rate_match) - size = SPA_MIN(size, p->rate_match->size * p->stride); + if (b->requested) + size = SPA_MIN(size, b->requested * p->stride); memcpy(d, s->buffer + p->offset, size); @@ -135,7 +124,6 @@ static void sample_play_stream_drained(void *data) static const struct pw_stream_events sample_play_stream_events = { PW_VERSION_STREAM_EVENTS, .state_changed = sample_play_stream_state_changed, - .io_changed = sample_play_stream_io_changed, .destroy = sample_play_stream_destroy, .process = sample_play_stream_process, .drained = sample_play_stream_drained, diff --git a/src/modules/module-protocol-pulse/sample-play.h b/src/modules/module-protocol-pulse/sample-play.h index 7b7f24463..57389359e 100644 --- a/src/modules/module-protocol-pulse/sample-play.h +++ b/src/modules/module-protocol-pulse/sample-play.h @@ -37,7 +37,6 @@ struct pw_loop; struct pw_stream; struct pw_context; struct pw_properties; -struct spa_io_rate_match; struct sample_play_events { #define VERSION_SAMPLE_PLAY_EVENTS 0 @@ -55,7 +54,6 @@ struct sample_play { struct spa_list link; struct sample *sample; struct pw_stream *stream; - struct spa_io_rate_match *rate_match; uint32_t id; struct spa_hook listener; struct pw_context *context; diff --git a/src/modules/module-protocol-simple.c b/src/modules/module-protocol-simple.c index a8044e7d2..000121001 100644 --- a/src/modules/module-protocol-simple.c +++ b/src/modules/module-protocol-simple.c @@ -121,8 +121,6 @@ struct client { struct pw_stream *playback; struct spa_hook playback_listener; - struct spa_io_rate_match *rate_match; - unsigned int disconnect:1; unsigned int disconnecting:1; unsigned int cleanup:1; @@ -282,12 +280,9 @@ static void playback_process(void *data) } d = &buf->buffer->datas[0]; - if (client->rate_match) { - size = client->rate_match->size * impl->frame_size; - size = SPA_MIN(size, d->maxsize); - } else { - size = d->maxsize; - } + size = d->maxsize; + if (buf->requested) + size = SPA_MIN(size, buf->requested * impl->frame_size); offset = 0; while (size > 0) { @@ -354,16 +349,6 @@ static void playback_destroy(void *data) client->playback = NULL; } -static void playback_io_changed(void *data, uint32_t id, void *area, uint32_t size) -{ - struct client *client = data; - switch (id) { - case SPA_IO_RateMatch: - client->rate_match = area; - break; - } -} - static const struct pw_stream_events capture_stream_events = { PW_VERSION_STREAM_EVENTS, .destroy = capture_destroy, @@ -375,7 +360,6 @@ static const struct pw_stream_events playback_stream_events = { PW_VERSION_STREAM_EVENTS, .destroy = playback_destroy, .state_changed = on_stream_state_changed, - .io_changed = playback_io_changed, .process = playback_process }; diff --git a/src/tools/pw-cat.c b/src/tools/pw-cat.c index 8ff8f797c..c51e2a9ec 100644 --- a/src/tools/pw-cat.c +++ b/src/tools/pw-cat.c @@ -162,7 +162,6 @@ struct data { int sync; struct spa_io_position *position; - struct spa_io_rate_match *rate_match; bool drained; uint64_t clock_time; @@ -880,10 +879,6 @@ on_io_changed(void *userdata, uint32_t id, void *data, uint32_t size) case SPA_IO_Position: d->position = data; break; - case SPA_IO_RateMatch: - if (d->data_type == TYPE_PCM) - d->rate_match = data; - break; default: break; } @@ -951,8 +946,7 @@ static void on_process(void *userdata) if (data->mode == mode_playback) { n_frames = d->maxsize / data->stride; - if (data->rate_match && data->rate_match->size > 0) - n_frames = SPA_MIN((uint32_t)n_frames, data->rate_match->size); + n_frames = SPA_MIN(n_frames, (int)b->requested); n_fill_frames = data->fill(data, p, n_frames);