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

Pipeline2.0: add API to access sink/src components linked to a buffer #9530

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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 All @@ -470,7 +470,7 @@ static int asrc_dai_find(struct comp_dev *dev, struct comp_data *cd)
do {
sourceb = comp_dev_get_first_data_producer(dev);

dev = sourceb->source;
dev = comp_buffer_get_source_component(sourceb);

if (!dev) {
comp_err(asrc_dev, "At beginning, no DAI found.");
Expand Down
22 changes: 14 additions & 8 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,14 @@ void comp_update_buffer_produce(struct comp_buffer *buffer, uint32_t bytes)
/* return if no bytes */
if (!bytes) {
#if CONFIG_SOF_LOG_DBG_BUFFER
struct comp_dev *src_component = comp_buffer_get_source_component(buffer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would need a "__unused" attribute to not create compiler warnings when buf_dbg() is a no-op.

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",
buffer->source ? dev_comp_id(buffer->source) : (unsigned int)UINT32_MAX,
buffer->source ? dev_comp_type(buffer->source) : (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);
src_component ? dev_comp_id(src_component) : (unsigned int)UINT32_MAX,
src_component ? dev_comp_type(src_component) : (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 @@ -520,11 +523,14 @@ void comp_update_buffer_consume(struct comp_buffer *buffer, uint32_t bytes)
/* return if no 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",
buffer->source ? dev_comp_id(buffer->source) : (unsigned int)UINT32_MAX,
buffer->source ? dev_comp_type(buffer->source) : (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);
src_component ? dev_comp_id(src_component) : (unsigned int)UINT32_MAX,
src_component ? dev_comp_type(src_component) : (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 @@ -284,7 +284,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 @@ -335,7 +335,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 @@ -1648,7 +1648,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 @@ -1678,7 +1678,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
3 changes: 1 addition & 2 deletions src/audio/google/google_rtc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,7 @@ static inline void execute_aec(struct google_rtc_audio_processing_comp_data *cd)
static bool ref_stream_active(struct google_rtc_audio_processing_comp_data *cd)
{
#ifdef CONFIG_IPC_MAJOR_3
return cd->ref_comp_buffer->source &&
cd->ref_comp_buffer->source->state == COMP_STATE_ACTIVE;
return (comp_buffer_get_source_state(cd->ref_comp_buffer) == COMP_STATE_ACTIVE);
#else
return true;
#endif
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
6 changes: 3 additions & 3 deletions src/audio/mixer/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static int mixer_reset(struct processing_module *mod)
/* FIXME: this is racy and implicitly protected by serialised IPCs */
bool stop = false;

if (source->source && source->source->state > COMP_STATE_READY)
if (comp_buffer_get_source_state(source) > COMP_STATE_READY)
stop = true;

/* only mix the sources with the same state with mixer */
Expand Down Expand Up @@ -233,8 +233,8 @@ static int mixer_prepare(struct processing_module *mod,
* done.
*/
mixer_set_frame_alignment(&source->stream);
stop = source->source && (source->source->state == COMP_STATE_PAUSED ||
source->source->state == COMP_STATE_ACTIVE);
stop = comp_buffer_get_source_state(source) == COMP_STATE_PAUSED ||
comp_buffer_get_source_state(source) == COMP_STATE_ACTIVE;

/* only prepare downstream if we have no active sources */
if (stop)
Expand Down
11 changes: 6 additions & 5 deletions 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 Expand Up @@ -485,7 +485,7 @@ static int mixout_process(struct processing_module *mod,
* sof_source implementation.
*/
unused_in_between_buf = comp_buffer_get_from_source(sources[i]);
mixin = unused_in_between_buf->source;
mixin = comp_buffer_get_source_component(unused_in_between_buf);

pending_frames = get_mixin_pending_frames(md, mixin);
if (!pending_frames)
Expand All @@ -501,7 +501,7 @@ static int mixout_process(struct processing_module *mod,
struct comp_dev *mixin;

unused_in_between_buf = comp_buffer_get_from_source(sources[i]);
mixin = unused_in_between_buf->source;
mixin = comp_buffer_get_source_component(unused_in_between_buf);

pending_frames = get_mixin_pending_frames(md, mixin);
if (!pending_frames)
Expand Down Expand Up @@ -569,8 +569,9 @@ static int mixout_reset(struct processing_module *mod)
* sof_source implementation.
*/
source_buf = comp_buffer_get_from_source(mod->sources[i]);
stop = (dev->pipeline == source_buf->source->pipeline &&
source_buf->source->state > COMP_STATE_PAUSED);
stop = (dev->pipeline ==
comp_buffer_get_source_component(source_buf)->pipeline &&
comp_buffer_get_source_state(source_buf) > COMP_STATE_PAUSED);

if (stop)
/* should not reset the downstream components */
Expand Down
10 changes: 5 additions & 5 deletions src/audio/mux/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,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 @@ -298,7 +298,7 @@ static int mux_process(struct processing_module *mod,
/* align source streams with their respective configurations */
j = 0;
comp_dev_for_each_producer(dev, source) {
if (source->source->state == dev->state) {
if (comp_buffer_get_source_state(source) == dev->state) {
if (frames)
frames = MIN(frames, input_buffers[j].size);
else
Expand Down Expand Up @@ -329,7 +329,7 @@ static int mux_process(struct processing_module *mod,
/* Update consumed and produced */
j = 0;
comp_dev_for_each_producer(dev, source) {
if (source->source->state == dev->state)
if (comp_buffer_get_source_state(source) == dev->state)
mod->input_buffers[j].consumed = source_bytes;
j++;
}
Expand All @@ -348,7 +348,7 @@ static int mux_reset(struct processing_module *mod)

if (dir == SOF_IPC_STREAM_PLAYBACK) {
comp_dev_for_each_producer(dev, source) {
int state = source->source->state;
int state = comp_buffer_get_source_state(source);

/* only mux the sources with the same state with mux */
if (state > COMP_STATE_READY)
Expand Down Expand Up @@ -439,7 +439,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/audio/selector/selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static int selector_trigger(struct comp_dev *dev, int cmd)
* kpb_init_draining() and kpb_draining_task() are interrupted by
* new pipeline_task()
*/
type = dev_comp_type(sourceb->source);
type = dev_comp_type(comp_buffer_get_source_component(sourceb));

return type == SOF_COMP_KPB ? PPL_STATUS_PATH_TERMINATE : ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/audio/smart_amp/smart_amp.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ static int smart_amp_copy(struct comp_dev *dev)
if (sad->feedback_buf) {
struct comp_buffer *feedback_buf = sad->feedback_buf;

if (comp_get_state(dev, feedback_buf->source) == dev->state) {
if (comp_get_state(feedback_buf->source) == dev->state) {
/* feedback */
avail_feedback_frames =
audio_stream_get_avail_frames(&feedback_buf->stream);
Expand Down
20 changes: 19 additions & 1 deletion src/include/sof/audio/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ struct comp_buffer {
struct list_item sink_list; /* list in comp buffers */
};

/*
* get a component providing data to the buffer
*/
static inline struct comp_dev *comp_buffer_get_source_component(const struct comp_buffer *buffer)
{
return buffer->source;
}

/*
* get a component consuming data from the buffer
*/
static inline struct comp_dev *comp_buffer_get_sink_component(const struct comp_buffer *buffer)
{
return buffer->sink;
}

/* Only to be used for synchronous same-core notifications! */
struct buffer_cb_transact {
struct comp_buffer *buffer;
Expand Down Expand Up @@ -252,7 +268,9 @@ 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 : buffer->source;
struct comp_dev *comp = (dir == PPL_DIR_DOWNSTREAM) ?
comp_buffer_get_sink_component(buffer) :
comp_buffer_get_source_component(buffer);
return comp;
}

Expand Down
Loading
Loading