Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sink / source API #7622

Merged
merged 10 commits into from
Jun 19, 2023
4 changes: 4 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ if((NOT CONFIG_LIBRARY) OR CONFIG_LIBRARY_STATIC)
host-legacy.c
component.c
buffer.c
marcinszkudlinski marked this conversation as resolved.
Show resolved Hide resolved
source_api_helper.c
sink_api_helper.c
sink_source_utils.c
audio_stream.c
channel_map.c
)
if(CONFIG_COMP_BLOB)
Expand Down
5 changes: 3 additions & 2 deletions src/audio/aria/aria.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,13 @@ static void aria_set_stream_params(struct comp_buffer *buffer, struct aria_data
enum sof_ipc_frame valid_fmt, frame_fmt;

buffer_c = buffer_acquire(buffer);
buffer_c->buffer_fmt = cd->base.audio_fmt.interleaving_style;

audio_stream_fmt_conversion(cd->base.audio_fmt.depth,
cd->base.audio_fmt.valid_bit_depth,
&frame_fmt, &valid_fmt,
cd->base.audio_fmt.s_type);

audio_stream_set_buffer_fmt(&buffer_c->stream,
cd->base.audio_fmt.interleaving_style);
audio_stream_set_frm_fmt(&buffer_c->stream, frame_fmt);
audio_stream_set_valid_fmt(&buffer_c->stream, valid_fmt);
audio_stream_set_channels(&buffer_c->stream, cd->chan_cnt);
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static int asrc_params(struct comp_dev *dev,

/* Don't change sink rate if value from IPC is 0 (auto detect) */
if (asrc_get_sink_rate(&cd->ipc_config))
sink_c->stream.rate = asrc_get_sink_rate(&cd->ipc_config);
audio_stream_set_rate(&sink_c->stream, asrc_get_sink_rate(&cd->ipc_config));
marcinszkudlinski marked this conversation as resolved.
Show resolved Hide resolved

/* set source/sink_frames/rate */
cd->source_rate = audio_stream_get_rate(&source_c->stream);
Expand Down
175 changes: 175 additions & 0 deletions src/audio/audio_stream.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2023 Intel Corporation. All rights reserved.
//

#include <sof/audio/audio_stream.h>
#include <sof/audio/buffer.h>

static size_t audio_stream_get_free_size(struct sof_sink __sparse_cache *sink)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(sink, struct audio_stream __sparse_cache,
sink_api, __sparse_cache);

return audio_stream_get_free_bytes(audio_stream);
}

static int audio_stream_get_buffer(struct sof_sink __sparse_cache *sink, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(sink, struct audio_stream __sparse_cache,
sink_api, __sparse_cache);

if (req_size > audio_stream_get_free_size(sink))
return -ENODATA;

/* get circular buffer parameters */
*data_ptr = audio_stream->w_ptr;
*buffer_start = audio_stream->addr;
*buffer_size = audio_stream->size;
return 0;
}

static int audio_stream_commit_buffer(struct sof_sink __sparse_cache *sink, size_t commit_size)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(sink, struct audio_stream __sparse_cache,
sink_api, __sparse_cache);

if (commit_size)
audio_stream_produce(audio_stream, commit_size);

return 0;
}

static size_t audio_stream_get_data_available(struct sof_source __sparse_cache *source)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(source, struct audio_stream __sparse_cache,
source_api, __sparse_cache);

return audio_stream_get_avail_bytes(audio_stream);
}

static int audio_stream_get_data(struct sof_source __sparse_cache *source, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(source, struct audio_stream __sparse_cache,
source_api, __sparse_cache);

if (req_size > audio_stream_get_data_available(source))
return -ENODATA;

/* get circular buffer parameters */
*data_ptr = audio_stream->r_ptr;
*buffer_start = audio_stream->addr;
*buffer_size = audio_stream->size;
return 0;
}

static int audio_stream_release_data(struct sof_source __sparse_cache *source, size_t free_size)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(source, struct audio_stream __sparse_cache,
source_api, __sparse_cache);

if (free_size)
audio_stream_consume(audio_stream, free_size);

return 0;
}

static int audio_stream_set_ipc_params_source(struct sof_source __sparse_cache *source,
struct sof_ipc_stream_params *params,
bool force_update)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(source, struct audio_stream __sparse_cache,
source_api, __sparse_cache);
struct comp_buffer __sparse_cache *buffer =
attr_container_of(audio_stream, struct comp_buffer __sparse_cache,
stream, __sparse_cache);

return buffer_set_params(buffer, params, force_update);
}

static int audio_stream_set_ipc_params_sink(struct sof_sink __sparse_cache *sink,
struct sof_ipc_stream_params *params,
bool force_update)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(sink, struct audio_stream __sparse_cache,
sink_api, __sparse_cache);
struct comp_buffer __sparse_cache *buffer =
attr_container_of(audio_stream, struct comp_buffer __sparse_cache,
stream, __sparse_cache);

return buffer_set_params(buffer, params, force_update);
}

static int audio_stream_source_set_alignment_constants(struct sof_source __sparse_cache *source,
const uint32_t byte_align,
const uint32_t frame_align_req)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(source, struct audio_stream __sparse_cache,
source_api, __sparse_cache);

audio_stream_init_alignment_constants(byte_align, frame_align_req, audio_stream);

return 0;
}

static int audio_stream_sink_set_alignment_constants(struct sof_sink __sparse_cache *sink,
const uint32_t byte_align,
const uint32_t frame_align_req)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(sink, struct audio_stream __sparse_cache,
sink_api, __sparse_cache);

audio_stream_init_alignment_constants(byte_align, frame_align_req, audio_stream);

return 0;
}

static const struct source_ops audio_stream_source_ops = {
.get_data_available = audio_stream_get_data_available,
.get_data = audio_stream_get_data,
.release_data = audio_stream_release_data,
.audio_set_ipc_params = audio_stream_set_ipc_params_source,
.set_alignment_constants = audio_stream_source_set_alignment_constants
};

static const struct sink_ops audio_stream_sink_ops = {
.get_free_size = audio_stream_get_free_size,
.get_buffer = audio_stream_get_buffer,
.commit_buffer = audio_stream_commit_buffer,
.audio_set_ipc_params = audio_stream_set_ipc_params_sink,
.set_alignment_constants = audio_stream_sink_set_alignment_constants
};

void audio_stream_init(struct audio_stream __sparse_cache *audio_stream,
void *buff_addr, uint32_t size)
{
audio_stream->size = size;
audio_stream->addr = buff_addr;
audio_stream->end_addr = (char *)audio_stream->addr + size;

/* set the default alignment info.
* set byte_align as 1 means no alignment limit on byte.
* set frame_align as 1 means no alignment limit on frame.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea what this means either.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a limited calculation frame number function audio_stream_avail_frames_aligned, it use shift to replace division, the byte_align and frame_align is for shift index calculation.

*/
audio_stream_init_alignment_constants(1, 1, audio_stream);

source_init(audio_stream_get_source(audio_stream), &audio_stream_source_ops,
(__sparse_force struct sof_audio_stream_params *)
&audio_stream->runtime_stream_params);
sink_init(audio_stream_get_sink(audio_stream), &audio_stream_sink_ops,
(__sparse_force struct sof_audio_stream_params *)
&audio_stream->runtime_stream_params);
audio_stream_reset(audio_stream);
}
14 changes: 7 additions & 7 deletions src/audio/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, u

/* From here no more uncached access to the buffer object, except its list headers */
buffer_c = buffer_acquire(buffer);
buffer_c->stream.addr = stream_addr;
audio_stream_set_addr(&buffer_c->stream, stream_addr);
buffer_init(buffer_c, size, caps);

buffer_c->stream.underrun_permitted = !!(flags & SOF_BUF_UNDERRUN_PERMITTED);
buffer_c->stream.overrun_permitted = !!(flags & SOF_BUF_OVERRUN_PERMITTED);
audio_stream_set_underrun(&buffer_c->stream, !!(flags & SOF_BUF_UNDERRUN_PERMITTED));
audio_stream_set_overrun(&buffer_c->stream, !!(flags & SOF_BUF_OVERRUN_PERMITTED));

buffer_release(buffer_c);

Expand Down Expand Up @@ -155,7 +155,7 @@ int buffer_set_params(struct comp_buffer __sparse_cache *buffer,
return -EINVAL;
}

buffer->buffer_fmt = params->buffer_fmt;
audio_stream_set_buffer_fmt(&buffer->stream, params->buffer_fmt);
for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++)
buffer->chmap[i] = params->chmap[i];

Expand All @@ -170,15 +170,15 @@ bool buffer_params_match(struct comp_buffer __sparse_cache *buffer,
assert(params);

if ((flag & BUFF_PARAMS_FRAME_FMT) &&
buffer->stream.frame_fmt != params->frame_fmt)
audio_stream_get_frm_fmt(&buffer->stream) != params->frame_fmt)
return false;

if ((flag & BUFF_PARAMS_RATE) &&
buffer->stream.rate != params->rate)
audio_stream_get_rate(&buffer->stream) != params->rate)
return false;

if ((flag & BUFF_PARAMS_CHANNELS) &&
buffer->stream.channels != params->channels)
audio_stream_get_channels(&buffer->stream) != params->channels)
marcinszkudlinski marked this conversation as resolved.
Show resolved Hide resolved
return false;

return true;
Expand Down
14 changes: 7 additions & 7 deletions src/audio/copier/copier_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,16 @@ void update_buffer_format(struct comp_buffer __sparse_cache *buf_c,
enum sof_ipc_frame valid_fmt, frame_fmt;
int i;

buf_c->stream.channels = fmt->channels_count;
buf_c->stream.rate = fmt->sampling_frequency;
audio_stream_set_channels(&buf_c->stream, fmt->channels_count);
audio_stream_set_rate(&buf_c->stream, fmt->sampling_frequency);
audio_stream_fmt_conversion(fmt->depth,
fmt->valid_bit_depth,
&frame_fmt, &valid_fmt,
fmt->s_type);

buf_c->stream.frame_fmt = frame_fmt;
buf_c->stream.valid_sample_fmt = valid_fmt;

buf_c->buffer_fmt = fmt->interleaving_style;
audio_stream_set_frm_fmt(&buf_c->stream, frame_fmt);
audio_stream_set_valid_fmt(&buf_c->stream, valid_fmt);
audio_stream_set_buffer_fmt(&buf_c->stream, fmt->interleaving_style);

for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++)
buf_c->chmap[i] = (fmt->ch_map >> i * 4) & 0xf;
Expand Down Expand Up @@ -238,7 +237,8 @@ int create_endpoint_buffer(struct comp_dev *parent_dev,
audio_stream_set_rate(&buffer_c->stream, copier_cfg->base.audio_fmt.sampling_frequency);
audio_stream_set_frm_fmt(&buffer_c->stream, config->frame_fmt);
audio_stream_set_valid_fmt(&buffer_c->stream, valid_fmt);
buffer_c->buffer_fmt = copier_cfg->base.audio_fmt.interleaving_style;
audio_stream_set_buffer_fmt(&buffer_c->stream,
copier_cfg->base.audio_fmt.interleaving_style);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're clearly confusing format and interleaving style....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again - not my code, just API change
This PR is not intended to fix copier

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I beg to disagree. YOU are adding a new set_buffer_fmt L153 which only sets the interleaving style.

Naming matters and we'd miss an opportunity to clean-up the APIs and later their implementation.


for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++)
buffer_c->chmap[i] = (chan_map >> i * 4) & 0xf;
Expand Down
8 changes: 4 additions & 4 deletions src/audio/eq_fir/eq_fir.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ static int eq_fir_init(struct processing_module *mod)
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
fir_reset(&cd->fir[i]);

mod->simple_copy = true;

return 0;

err_init:
Expand Down Expand Up @@ -566,7 +564,9 @@ static void eq_fir_set_alignment(struct audio_stream __sparse_cache *source,
audio_stream_init_alignment_constants(byte_align, frame_align_req, sink);
}

static int eq_fir_prepare(struct processing_module *mod)
static int eq_fir_prepare(struct processing_module *mod,
struct sof_source __sparse_cache **sources, int num_of_sources,
struct sof_sink __sparse_cache **sinks, int num_of_sinks)
{
struct comp_data *cd = module_get_private_data(mod);
struct comp_buffer *sourceb, *sinkb;
Expand Down Expand Up @@ -641,7 +641,7 @@ static struct module_interface eq_fir_interface = {
.free = eq_fir_free,
.set_configuration = eq_fir_set_config,
.get_configuration = eq_fir_get_config,
.process = eq_fir_process,
.process_audio_stream = eq_fir_process,
.prepare = eq_fir_prepare,
.reset = eq_fir_reset,
};
Expand Down
12 changes: 4 additions & 8 deletions src/audio/eq_iir/eq_iir.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,6 @@ static int eq_iir_init(struct processing_module *mod)
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
iir_reset_df1(&cd->iir[i]);

/*
* set the simple_copy flag as the eq_iir component always produces period_bytes
* every period and has only 1 input/output buffer
*/
mod->simple_copy = true;

return 0;
err:
rfree(cd);
Expand Down Expand Up @@ -885,7 +879,9 @@ static void eq_iir_set_passthrough_func(struct comp_data *cd,
#endif
}

static int eq_iir_prepare(struct processing_module *mod)
static int eq_iir_prepare(struct processing_module *mod,
struct sof_source __sparse_cache **sources, int num_of_sources,
struct sof_sink __sparse_cache **sinks, int num_of_sinks)
{
struct comp_data *cd = module_get_private_data(mod);
struct comp_buffer *sourceb, *sinkb;
Expand Down Expand Up @@ -967,7 +963,7 @@ static int eq_iir_reset(struct processing_module *mod)
static struct module_interface eq_iir_interface = {
.init = eq_iir_init,
.prepare = eq_iir_prepare,
.process = eq_iir_process,
.process_audio_stream = eq_iir_process,
.set_configuration = eq_iir_set_config,
.get_configuration = eq_iir_get_config,
.reset = eq_iir_reset,
Expand Down
2 changes: 1 addition & 1 deletion src/audio/google/google_hotword_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static int ghd_params(struct comp_dev *dev,
sink_list);
source_c = buffer_acquire(sourceb);

if (source_c->stream.channels != 1) {
if (audio_stream_get_channels(source_c->stream) != 1) {
comp_err(dev, "ghd_params(): Only single-channel supported");
ret = -EINVAL;
} else if (audio_stream_get_frm_fmt(&source_c->stream) != SOF_IPC_FRAME_S16_LE) {
Expand Down
2 changes: 1 addition & 1 deletion src/audio/host-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ static uint32_t host_get_copy_bytes_normal(struct host_data *hd, struct comp_dev
}

dma_buf_c = buffer_acquire(hd->dma_buffer);
dma_sample_bytes = get_sample_bytes(dma_buf_c->stream.frame_fmt);
dma_sample_bytes = get_sample_bytes(audio_stream_get_frm_fmt(&dma_buf_c->stream));
buffer_release(dma_buf_c);

buffer_c = buffer_acquire(buffer);
Expand Down
3 changes: 2 additions & 1 deletion src/audio/igo_nr/igo_nr.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ static int32_t igo_nr_params(struct comp_dev *dev,
cd->source_rate = audio_stream_get_rate(&source_c->stream);
cd->sink_rate = audio_stream_get_rate(&sink_c->stream);

if (source_c->stream.channels != audio_stream_get_channels(&sink_c->stream)) {
if (audio_stream_get_channels(source_c->stream) !=
audio_stream_get_channels(&sink_c->stream)) {
comp_err(dev, "igo_nr_params(), mismatch source/sink stream channels");
cd->invalid_param = true;
}
Expand Down
Loading