From 33bc512f704b5be782a597c14d72a72f3a1d2a73 Mon Sep 17 00:00:00 2001 From: Marcin Szkudlinski Date: Wed, 16 Oct 2024 16:08:06 +0200 Subject: [PATCH] use of API with defaults --- src/audio/buffers/comp_buffer.c | 57 ++++++++------------------------- src/audio/buffers/ring_buffer.c | 46 +------------------------- 2 files changed, 15 insertions(+), 88 deletions(-) diff --git a/src/audio/buffers/comp_buffer.c b/src/audio/buffers/comp_buffer.c index 3d2a2cd9040f..94ef276d6e96 100644 --- a/src/audio/buffers/comp_buffer.c +++ b/src/audio/buffers/comp_buffer.c @@ -64,33 +64,6 @@ static int comp_buffer_release_data(struct sof_source *source, size_t free_size) return 0; } -static int comp_buffer_set_ipc_params_source(struct sof_source *source, - struct sof_ipc_stream_params *params, - bool force_update) -{ - struct comp_buffer *buffer = comp_buffer_get_from_source(source); - - return buffer_set_params(buffer, params, force_update); -} - -static int comp_buffer_source_format_set(struct sof_source *source) -{ - struct comp_buffer *buffer = comp_buffer_get_from_source(source); - - audio_stream_recalc_align(&buffer->stream); - return 0; -} - -static int comp_buffer_source_set_alignment_constants(struct sof_source *source, - const uint32_t byte_align, - const uint32_t frame_align_req) -{ - struct comp_buffer *buffer = comp_buffer_get_from_source(source); - - audio_stream_set_align(byte_align, frame_align_req, &buffer->stream); - return 0; -} - static size_t comp_buffer_get_free_size(struct sof_sink *sink) { struct comp_buffer *buffer = comp_buffer_get_from_sink(sink); @@ -125,28 +98,29 @@ static int comp_buffer_commit_buffer(struct sof_sink *sink, size_t commit_size) return 0; } -static int comp_buffer_set_ipc_params_sink(struct sof_sink *sink, - struct sof_ipc_stream_params *params, - bool force_update) +static int comp_buffer_set_ipc_params(struct sof_audio_buffer *audio_buffer, + struct sof_ipc_stream_params *params, + bool force_update) { - struct comp_buffer *buffer = comp_buffer_get_from_sink(sink); + struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer); return buffer_set_params(buffer, params, force_update); + return 0; } -static int comp_buffer_sink_format_set(struct sof_sink *sink) +static int comp_buffer_format_set(struct sof_audio_buffer *audio_buffer) { - struct comp_buffer *buffer = comp_buffer_get_from_sink(sink); + struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer); audio_stream_recalc_align(&buffer->stream); return 0; } -static int comp_buffer_sink_set_alignment_constants(struct sof_sink *sink, - const uint32_t byte_align, - const uint32_t frame_align_req) +static int comp_buffer_set_alignment_constants(struct sof_audio_buffer *audio_buffer, + const uint32_t byte_align, + const uint32_t frame_align_req) { - struct comp_buffer *buffer = comp_buffer_get_from_sink(sink); + struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer); audio_stream_set_align(byte_align, frame_align_req, &buffer->stream); return 0; @@ -194,23 +168,20 @@ static struct source_ops comp_buffer_source_ops = { .get_data_available = comp_buffer_get_data_available, .get_data = comp_buffer_get_data, .release_data = comp_buffer_release_data, - .audio_set_ipc_params = comp_buffer_set_ipc_params_source, - .on_audio_format_set = comp_buffer_source_format_set, - .set_alignment_constants = comp_buffer_source_set_alignment_constants }; static struct sink_ops comp_buffer_sink_ops = { .get_free_size = comp_buffer_get_free_size, .get_buffer = comp_buffer_get_buffer, .commit_buffer = comp_buffer_commit_buffer, - .audio_set_ipc_params = comp_buffer_set_ipc_params_sink, - .on_audio_format_set = comp_buffer_sink_format_set, - .set_alignment_constants = comp_buffer_sink_set_alignment_constants }; static const struct audio_buffer_ops audio_buffer_ops = { .free = comp_buffer_free, .clean = comp_buffer_clean, + .audio_set_ipc_params = comp_buffer_set_ipc_params, + .on_audio_format_set = comp_buffer_format_set, + .set_alignment_constants = comp_buffer_set_alignment_constants }; static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, uint32_t caps, diff --git a/src/audio/buffers/ring_buffer.c b/src/audio/buffers/ring_buffer.c index f73f13a70072..ef5eabcf0306 100644 --- a/src/audio/buffers/ring_buffer.c +++ b/src/audio/buffers/ring_buffer.c @@ -242,65 +242,21 @@ static int ring_buffer_release_data(struct sof_source *source, size_t free_size) return 0; } -static int ring_buffer_set_ipc_params(struct ring_buffer *ring_buffer, - struct sof_ipc_stream_params *params, - bool force_update) -{ - CORE_CHECK_STRUCT(&ring_buffer->audio_buffer); - - if (audio_buffer_hw_params_configured(&ring_buffer->audio_buffer) && !force_update) - return 0; - - struct sof_audio_stream_params *audio_stream_params = - audio_buffer_get_stream_params(&ring_buffer->audio_buffer); - - audio_stream_params->frame_fmt = params->frame_fmt; - audio_stream_params->rate = params->rate; - audio_stream_params->channels = params->channels; - audio_stream_params->buffer_fmt = params->buffer_fmt; - - audio_buffer_set_hw_params_configured(&ring_buffer->audio_buffer); - - return 0; -} - -static int ring_buffer_set_ipc_params_source(struct sof_source *source, - struct sof_ipc_stream_params *params, - bool force_update) -{ - struct ring_buffer *ring_buffer = ring_buffer_from_source(source); - - CORE_CHECK_STRUCT(&ring_buffer->audio_buffer); - return ring_buffer_set_ipc_params(ring_buffer, params, force_update); -} - -static int ring_buffer_set_ipc_params_sink(struct sof_sink *sink, - struct sof_ipc_stream_params *params, - bool force_update) -{ - struct ring_buffer *ring_buffer = ring_buffer_from_sink(sink); - - CORE_CHECK_STRUCT(&ring_buffer->audio_buffer); - return ring_buffer_set_ipc_params(ring_buffer, params, force_update); -} - static struct source_ops ring_buffer_source_ops = { .get_data_available = ring_buffer_get_data_available, .get_data = ring_buffer_get_data, .release_data = ring_buffer_release_data, - .audio_set_ipc_params = ring_buffer_set_ipc_params_source, }; static struct sink_ops ring_buffer_sink_ops = { .get_free_size = ring_buffer_get_free_size, .get_buffer = ring_buffer_get_buffer, .commit_buffer = ring_buffer_commit_buffer, - .audio_set_ipc_params = ring_buffer_set_ipc_params_sink, }; static const struct audio_buffer_ops audio_buffer_ops = { .free = ring_buffer_free, - .clean = ring_buffer_clean + .clean = ring_buffer_clean, }; struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_space, bool is_shared,