Skip to content

Commit

Permalink
buf: use buffer sink API in components
Browse files Browse the repository at this point in the history
This commit makes all components use API for accessing
the previous/next component

pipeline code, like module adapter or ipc helpers was
omitted intentionally

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
  • Loading branch information
marcinszkudlinski authored and lgirdwood committed Oct 2, 2024
1 parent 40eac5d commit f9b1a1d
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static int asrc_dai_find(struct comp_dev *dev, struct comp_data *cd)
do {
sinkb = comp_dev_get_first_data_consumer(dev);

dev = sinkb->sink;
dev = comp_buffer_get_sink_component(sinkb);

if (!dev) {
comp_err(asrc_dev, "At end, no DAI found.");
Expand Down
12 changes: 8 additions & 4 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,13 @@ void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
if (!bytes) {
#if CONFIG_SOF_LOG_DBG_BUFFER
struct comp_dev *src_component = comp_buffer_get_source_component(buffer);
struct comp_dev *sink_component = comp_buffer_get_sink_component(buffer);

buf_dbg(buffer, "comp_update_buffer_produce(), no bytes to produce, source->comp.id = %u, source->comp.type = %u, sink->comp.id = %u, sink->comp.type = %u",
src_component ? dev_comp_id(src_component) : (unsigned int)UINT32_MAX,
src_component ? dev_comp_type(src_component) : (unsigned int)UINT32_MAX,
buffer->sink ? dev_comp_id(buffer->sink) : (unsigned int)UINT32_MAX,
buffer->sink ? dev_comp_type(buffer->sink) : (unsigned int)UINT32_MAX);
sink_component ? dev_comp_id(sink_component) : (unsigned int)UINT32_MAX,
sink_component ? dev_comp_type(sink_component) : (unsigned int)UINT32_MAX);
#endif
return;
}
Expand Down Expand Up @@ -524,11 +526,13 @@ void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
if (!bytes) {
#if CONFIG_SOF_LOG_DBG_BUFFER
struct comp_dev *src_component = comp_buffer_get_source_component(buffer);
struct comp_dev *sink_component = comp_buffer_get_sink_component(buffer);

buf_dbg(buffer, "comp_update_buffer_consume(), no bytes to consume, source->comp.id = %u, source->comp.type = %u, sink->comp.id = %u, sink->comp.type = %u",
src_component ? dev_comp_id(src_component) : (unsigned int)UINT32_MAX,
src_component ? dev_comp_type(src_component) : (unsigned int)UINT32_MAX,
buffer->sink ? dev_comp_id(buffer->sink) : (unsigned int)UINT32_MAX,
buffer->sink ? dev_comp_type(buffer->sink) : (unsigned int)UINT32_MAX);
sink_component ? dev_comp_id(sink_component) : (unsigned int)UINT32_MAX,
sink_component ? dev_comp_type(sink_component) : (unsigned int)UINT32_MAX);
#endif
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ static int copier_copy_to_sinks(struct copier_data *cd, struct comp_dev *dev,
comp_dev_for_each_consumer(dev, sink) {
struct comp_dev *sink_dev;

sink_dev = sink->sink;
sink_dev = comp_buffer_get_sink_component(sink);
processed_data->sink_bytes = 0;
if (sink_dev->state == COMP_STATE_ACTIVE) {
ret = do_conversion_copy(dev, cd, src_c, sink, processed_data);
Expand Down Expand Up @@ -508,7 +508,7 @@ static int copier_module_copy(struct processing_module *mod,
struct comp_dev *sink_dev;

sink_c = container_of(output_buffers[i].data, struct comp_buffer, stream);
sink_dev = sink_c->sink;
sink_dev = comp_buffer_get_sink_component(sink_c);
processed_data.sink_bytes = 0;
if (sink_dev->state == COMP_STATE_ACTIVE) {
uint32_t source_samples;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/crossover/crossover.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static int crossover_assign_sinks(struct processing_module *mod,
unsigned int sink_id, state;

sink_id = crossover_get_sink_id(cd, buffer_pipeline_id(sink), j);
state = sink->sink->state;
state = comp_buffer_get_sink_state(sink);
if (state != dev->state) {
j++;
continue;
Expand Down
8 changes: 4 additions & 4 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
if (sink == dd->dma_buffer)
continue;

sink_dev = sink->sink;
sink_dev = comp_buffer_get_sink_component(sink);

j = IPC4_SRC_QUEUE_ID(buf_get_id(sink));

Expand Down Expand Up @@ -346,7 +346,7 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
if (sink == dd->local_buffer)
continue;

sink_dev = sink->sink;
sink_dev = comp_buffer_get_sink_component(sink);

j = IPC4_SINK_QUEUE_ID(buf_get_id(sink));

Expand Down Expand Up @@ -1659,7 +1659,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
comp_dev_for_each_consumer(dev, sink) {
struct comp_dev *sink_dev;

sink_dev = sink->sink;
sink_dev = comp_buffer_get_sink_component(sink);

if (sink_dev && sink_dev->state == COMP_STATE_ACTIVE &&
audio_buffer_hw_params_configured(&sink->audio_buffer)) {
Expand Down Expand Up @@ -1689,7 +1689,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
comp_dev_for_each_consumer(dev, sink) {
struct comp_dev *sink_dev;

sink_dev = sink->sink;
sink_dev = comp_buffer_get_sink_component(sink);

if (sink_dev && sink_dev->state == COMP_STATE_ACTIVE &&
audio_buffer_hw_params_configured(&sink->audio_buffer)) {
Expand Down
24 changes: 12 additions & 12 deletions src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static int kpb_bind(struct comp_dev *dev, void *data)
comp_dev_for_each_consumer(dev, sink) {
int sink_buf_id;

if (!sink->sink) {
if (!comp_buffer_get_sink_component(sink)) {
ret = -EINVAL;
break;
}
Expand Down Expand Up @@ -862,11 +862,11 @@ static int kpb_prepare(struct comp_dev *dev)
comp_dev_for_each_consumer(dev, sink) {
enum sof_comp_type type;

if (!sink->sink) {
if (!comp_buffer_get_sink_component(sink)) {
ret = -EINVAL;
break;
}
type = dev_comp_type(sink->sink);
type = dev_comp_type(comp_buffer_get_sink_component(sink));

switch (type) {
case SOF_COMP_SELECTOR:
Expand Down Expand Up @@ -1562,7 +1562,7 @@ static int kpb_register_client(struct comp_data *kpb, struct kpb_client *cli)
static void kpb_init_draining(struct comp_dev *dev, struct kpb_client *cli)
{
struct comp_data *kpb = comp_get_drvdata(dev);
bool is_sink_ready = (kpb->host_sink->sink->state == COMP_STATE_ACTIVE);
bool is_sink_ready = (comp_buffer_get_sink_state(kpb->host_sink) == COMP_STATE_ACTIVE);
size_t sample_width = kpb->config.sampling_width;
size_t drain_req = cli->drain_req * kpb->config.channels *
(kpb->config.sampling_freq / 1000) *
Expand Down Expand Up @@ -1691,15 +1691,15 @@ static void kpb_init_draining(struct comp_dev *dev, struct kpb_client *cli)
kpb->draining_task_data.sync_mode_on = kpb->sync_draining_mode;

/* save current sink copy type */
comp_get_attribute(kpb->host_sink->sink, COMP_ATTR_COPY_TYPE,
&kpb->draining_task_data.copy_type);
comp_get_attribute(comp_buffer_get_sink_component(kpb->host_sink),
COMP_ATTR_COPY_TYPE, &kpb->draining_task_data.copy_type);

if (kpb->force_copy_type != COMP_COPY_INVALID)
comp_set_attribute(kpb->host_sink->sink, COMP_ATTR_COPY_TYPE,
&kpb->force_copy_type);
comp_set_attribute(comp_buffer_get_sink_component(kpb->host_sink),
COMP_ATTR_COPY_TYPE, &kpb->force_copy_type);

/* Pause selector copy. */
kpb->sel_sink->sink->state = COMP_STATE_PAUSED;
comp_buffer_get_sink_component(kpb->sel_sink)->state = COMP_STATE_PAUSED;

/* Schedule draining task */
schedule_task(&kpb->draining_task, 0, 0);
Expand Down Expand Up @@ -1827,13 +1827,13 @@ static enum task_state kpb_draining_task(void *arg)

if (size_to_copy) {
comp_update_buffer_produce(sink, size_to_copy);
comp_copy(sink->sink);
comp_copy(comp_buffer_get_sink_component(sink));
} else if (!audio_stream_get_free_bytes(&sink->stream)) {
/* There is no free space in sink buffer.
* Call .copy() on sink component so it can
* process its data further.
*/
comp_copy(sink->sink);
comp_copy(comp_buffer_get_sink_component(sink));
}

if (sync_mode_on && period_bytes >= period_bytes_limit) {
Expand Down Expand Up @@ -1870,7 +1870,7 @@ static enum task_state kpb_draining_task(void *arg)
draining_time_end = sof_cycle_get_64();

/* Reset host-sink copy mode back to its pre-draining value */
comp_set_attribute(kpb->host_sink->sink, COMP_ATTR_COPY_TYPE,
comp_set_attribute(comp_buffer_get_sink_component(kpb->host_sink), COMP_ATTR_COPY_TYPE,
&kpb->draining_task_data.copy_type);

draining_time_ms = k_cyc_to_ms_near64(draining_time_end - draining_time_start);
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mixin_mixout/mixin_mixout.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ static int mixin_process(struct processing_module *mod,
*/
/* unused buffer between mixin and mixout */
unused_in_between_buf = comp_buffer_get_from_sink(sinks[i]);
mixout = unused_in_between_buf->sink;
mixout = comp_buffer_get_sink_component(unused_in_between_buf);

/* Skip non-active mixout like it is not connected so it does not
* block other possibly connected mixouts. In addition, non-active
Expand Down
4 changes: 2 additions & 2 deletions src/audio/mux/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static int demux_process(struct processing_module *mod,

/* align sink streams with their respective configurations */
comp_dev_for_each_consumer(dev, sink) {
if (sink->sink->state == dev->state) {
if (comp_buffer_get_sink_state(sink) == dev->state) {
i = get_stream_index(dev, cd, buffer_pipeline_id(sink));
/* return if index wrong */
if (i < 0) {
Expand Down Expand Up @@ -440,7 +440,7 @@ static int demux_trigger(struct processing_module *mod, int cmd)
struct comp_buffer *b;

comp_dev_for_each_producer(mod->dev, b) {
if (b->sink->pipeline != mod->dev->pipeline)
if (comp_buffer_get_sink_component(b)->pipeline != mod->dev->pipeline)
audio_stream_set_overrun(&b->stream, true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/include/sof/audio/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void buffer_detach(struct comp_buffer *buffer, struct list_item *head, int dir);
static inline struct comp_dev *buffer_get_comp(struct comp_buffer *buffer, int dir)
{
struct comp_dev *comp = (dir == PPL_DIR_DOWNSTREAM) ?
buffer->sink :
comp_buffer_get_sink_component(buffer) :
comp_buffer_get_source_component(buffer);
return comp;
}
Expand Down

0 comments on commit f9b1a1d

Please sign in to comment.