Skip to content
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
90 changes: 86 additions & 4 deletions src/audio/mux/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ static int mux_set_values(struct comp_dev *dev, struct comp_data *cd,
{
uint8_t i;
uint8_t j;
bool channel_set;

comp_info(dev, "mux_set_values()");

/* check if number of streams configured doesn't exceed maximum */
if (cfg->num_streams > MUX_MAX_STREAMS) {
Expand All @@ -69,12 +72,44 @@ static int mux_set_values(struct comp_dev *dev, struct comp_data *cd,
}
}

for (i = 0; i < cfg->num_streams; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we have an inline comment on what each loop block is doing

for (j = 0 ; j < PLATFORM_MAX_CHANNELS; j++) {
if (popcount(cfg->streams[i].mask[j]) > 1) {
comp_cl_err(&comp_mux, "mux_set_values(): mux component is not able to mix channels");
return -EINVAL;
}
}
}

if (dev->comp.type == SOF_COMP_MUX) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto

for (j = 0 ; j < PLATFORM_MAX_CHANNELS; j++) {
channel_set = false;
for (i = 0 ; i < cfg->num_streams; i++) {
if (popcount(cfg->streams[i].mask[j])) {
if (!channel_set) {
channel_set = true;
} else {
comp_cl_err(&comp_mux, "mux_set_values(): mux component is not able to mix channels");
return -EINVAL;
}
}
}
}
}

for (i = 0; i < cfg->num_streams; i++) {
cd->config.streams[i].pipeline_id = cfg->streams[i].pipeline_id;
for (j = 0; j < PLATFORM_MAX_CHANNELS; j++)
cd->config.streams[i].mask[j] = cfg->streams[i].mask[j];
}

cd->config.num_streams = cfg->num_streams;

if (dev->comp.type == SOF_COMP_MUX)
mux_prepare_look_up_table(dev);
else
demux_prepare_look_up_table(dev);

if (dev->state > COMP_STATE_INIT) {
if (dev->comp.type == SOF_COMP_MUX)
cd->mux = mux_get_processing_function(dev);
Expand Down Expand Up @@ -157,6 +192,21 @@ static uint8_t get_stream_index(struct comp_data *cd, uint32_t pipe_id)
return 0;
}

static struct mux_look_up *get_lookup_table(struct comp_data *cd,
uint32_t pipe_id)
{
int i;

for (i = 0; i < MUX_MAX_STREAMS; i++)
if (cd->config.streams[i].pipeline_id == pipe_id)
return &cd->lookup[i];

comp_cl_err(&comp_mux, "get_lookup_table(): couldn't find configuration for connected pipeline %u",
pipe_id);

return 0;
}

static int mux_verify_params(struct comp_dev *dev,
struct sof_ipc_stream_params *params)
{
Expand Down Expand Up @@ -269,13 +319,41 @@ static int mux_cmd(struct comp_dev *dev, int cmd, void *data,
}
}

static void prepare_active_look_up(struct comp_dev *dev,
struct audio_stream *sink,
const struct audio_stream **sources)
{
struct comp_data *cd = comp_get_drvdata(dev);
const struct audio_stream *source;
uint8_t active_elem;
uint8_t elem;

cd->active_lookup.num_elems = 0;

active_elem = 0;

/* init pointers */
for (elem = 0; elem < cd->lookup[0].num_elems; elem++) {
source = sources[cd->lookup[0].copy_elem[elem].stream_id];
Comment thread
lgirdwood marked this conversation as resolved.
Resolved
if (!source)
continue;

cd->active_lookup.copy_elem[active_elem] =
cd->lookup[0].copy_elem[elem];
active_elem++;
cd->active_lookup.num_elems = active_elem;
}
}

/* process and copy stream data from source to sink buffers */
static int demux_copy(struct comp_dev *dev)
{
struct comp_data *cd = comp_get_drvdata(dev);
struct comp_buffer *source;
struct comp_buffer *sink;
struct comp_buffer *sinks[MUX_MAX_STREAMS] = { NULL };
struct mux_look_up *look_ups[MUX_MAX_STREAMS] = { NULL };
struct mux_look_up *look_up;
struct list_item *clist;
uint32_t num_sinks = 0;
uint32_t i = 0;
Expand All @@ -300,7 +378,9 @@ static int demux_copy(struct comp_dev *dev)
if (sink->sink->state == dev->state) {
num_sinks++;
i = get_stream_index(cd, sink->pipeline_id);
look_up = get_lookup_table(cd, sink->pipeline_id);
sinks[i] = sink;
look_ups[i] = look_up;
}
buffer_unlock(sink, flags);
}
Expand Down Expand Up @@ -346,8 +426,8 @@ static int demux_copy(struct comp_dev *dev)
continue;

buffer_invalidate(source, source_bytes);
cd->demux(&sinks[i]->stream, &source->stream, frames,
&cd->config.streams[i]);
cd->demux(dev, &sinks[i]->stream, &source->stream, frames,
look_ups[i]);
buffer_writeback(sinks[i], sinks_bytes[i]);
}

Expand Down Expand Up @@ -441,9 +521,11 @@ static int mux_copy(struct comp_dev *dev)
}
sink_bytes = frames * audio_stream_frame_bytes(&sink->stream);

prepare_active_look_up(dev, &sink->stream, &sources_stream[0]);

/* produce output */
cd->mux(&sink->stream, &sources_stream[0], frames,
&cd->config.streams[0]);
cd->mux(dev, &sink->stream, &sources_stream[0], frames,
&cd->active_lookup);
buffer_writeback(sink, sink_bytes);

/* update components */
Expand Down
Loading