Skip to content

Commit aa8dbb3

Browse files
module: mux: rework module to use sink/source api
Rework the mux module to only use the sink/source api to prepare the SOF for the full transition to pipeline 2.0. Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>
1 parent 0194725 commit aa8dbb3

3 files changed

Lines changed: 173 additions & 178 deletions

File tree

src/audio/mux/mux.c

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,17 @@ static struct mux_look_up *get_lookup_table(struct comp_dev *dev, struct comp_da
203203
}
204204

205205
static void demux_prepare_active_look_up(struct comp_data *cd,
206-
struct audio_stream *sink,
207-
const struct audio_stream *source,
206+
struct sof_sink *sink,
207+
struct sof_source *source,
208208
struct mux_look_up *look_up)
209209
{
210210
int elem;
211211
int active_elem = 0;
212212

213213
/* init pointers */
214214
for (elem = 0; elem < look_up->num_elems; elem++) {
215-
if (look_up->copy_elem[elem].in_ch >= audio_stream_get_channels(source) ||
216-
look_up->copy_elem[elem].out_ch >= audio_stream_get_channels(sink))
215+
if (look_up->copy_elem[elem].in_ch >= source_get_channels(source) ||
216+
look_up->copy_elem[elem].out_ch >= sink_get_channels(sink))
217217
continue;
218218

219219
cd->active_lookup.copy_elem[active_elem] = look_up->copy_elem[elem];
@@ -225,56 +225,77 @@ static void demux_prepare_active_look_up(struct comp_data *cd,
225225

226226
/* process and copy stream data from source to sink buffers */
227227
static int demux_process(struct processing_module *mod,
228-
struct input_stream_buffer *input_buffers, int num_input_buffers,
229-
struct output_stream_buffer *output_buffers, int num_output_buffers)
228+
struct sof_source **sources, int num_of_sources,
229+
struct sof_sink **sinks, int num_of_sinks)
230230
{
231231
struct comp_data *cd = module_get_private_data(mod);
232232
struct comp_dev *dev = mod->dev;
233-
struct comp_buffer *sink;
234-
struct audio_stream *sinks_stream[MUX_MAX_STREAMS] = { NULL };
235-
struct mux_look_up *look_ups[MUX_MAX_STREAMS] = { NULL };
236-
int frames;
237-
int sink_bytes;
238-
int source_bytes;
233+
struct sof_source *source = sources[0];
234+
const void *source_data;
235+
const void *source_start;
236+
size_t source_size;
237+
size_t source_bytes;
238+
uint32_t frames;
239+
int ret;
239240
int i;
240241

241242
comp_dbg(dev, "entry");
242243

243-
/* align sink streams with their respective configurations */
244-
comp_dev_for_each_consumer(dev, sink) {
245-
if (comp_buffer_get_sink_state(sink) == dev->state) {
246-
i = get_stream_index(dev, cd, buffer_pipeline_id(sink));
247-
/* return if index wrong */
248-
if (i < 0) {
249-
return i;
250-
}
244+
/* if there are no sinks active, then there is nothing to do */
245+
if (num_of_sinks == 0)
246+
return 0;
251247

252-
look_ups[i] = get_lookup_table(dev, cd, buffer_pipeline_id(sink));
253-
sinks_stream[i] = &sink->stream;
254-
}
248+
/* the same number of frames is distributed to every sink, so it is
249+
* limited by both the source availability and every active sink's free
250+
* space
251+
*/
252+
frames = source_get_data_frames_available(source);
253+
for (i = 0; i < num_of_sinks; i++) {
254+
struct comp_buffer *sink_buf = comp_buffer_get_from_sink(sinks[i]);
255+
256+
if (comp_buffer_get_sink_state(sink_buf) != dev->state)
257+
continue;
258+
259+
frames = MIN(frames, sink_get_free_frames(sinks[i]));
255260
}
256261

257-
/* if there are no sinks active, then sinks[] is also empty */
258-
if (num_output_buffers == 0)
262+
if (!frames)
259263
return 0;
260264

261-
frames = input_buffers[0].size;
262-
source_bytes = frames * audio_stream_frame_bytes(mod->input_buffers[0].data);
263-
sink_bytes = frames * audio_stream_frame_bytes(mod->output_buffers[0].data);
265+
/* the source is read-only and shared by all sinks, so it is obtained
266+
* once here and released once after all sinks have been served
267+
*/
268+
source_bytes = frames * source_get_frame_bytes(source);
269+
ret = source_get_data(source, source_bytes, &source_data, &source_start,
270+
&source_size);
271+
if (ret)
272+
return ret;
264273

265274
/* produce output, one sink at a time */
266-
for (i = 0; i < num_output_buffers; i++) {
267-
if (sinks_stream[i]) {
268-
demux_prepare_active_look_up(cd, sinks_stream[i],
269-
input_buffers[0].data, look_ups[i]);
270-
cd->demux(dev, sinks_stream[i], input_buffers[0].data,
271-
frames, &cd->active_lookup);
275+
for (i = 0; i < num_of_sinks; i++) {
276+
struct sof_sink *sink = sinks[i];
277+
struct comp_buffer *sink_buf = comp_buffer_get_from_sink(sink);
278+
uint32_t pipeline_id = buffer_pipeline_id(sink_buf);
279+
struct mux_look_up *look_up;
280+
281+
/* skip sinks that are not in the same state as the component */
282+
if (comp_buffer_get_sink_state(sink_buf) != dev->state)
283+
continue;
284+
285+
/* return if configuration for this pipeline is missing */
286+
if (get_stream_index(dev, cd, pipeline_id) < 0) {
287+
source_release_data(source, 0);
288+
return -EINVAL;
272289
}
273-
mod->output_buffers[i].size = sink_bytes;
290+
291+
look_up = get_lookup_table(dev, cd, pipeline_id);
292+
demux_prepare_active_look_up(cd, sink, source, look_up);
293+
cd->demux(dev, sink, source, source_data, source_start,
294+
source_size, frames, &cd->active_lookup);
274295
}
275296

276-
/* Update consumed */
277-
mod->input_buffers[0].consumed = source_bytes;
297+
/* consume the processed data from the source */
298+
source_release_data(source, source_bytes);
278299
return 0;
279300
}
280301

@@ -454,7 +475,7 @@ static const struct module_interface demux_interface = {
454475
.set_configuration = mux_set_config,
455476
.get_configuration = mux_get_config,
456477
.prepare = mux_prepare,
457-
.process_audio_stream = demux_process,
478+
.process = demux_process,
458479
.trigger = demux_trigger,
459480
.reset = mux_reset,
460481
.free = mux_free,

src/audio/mux/mux.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ struct mux_stream_data {
6666
uint8_t reserved2[3]; // padding to ensure proper alignment of following instances
6767
} __attribute__((packed, aligned(4)));
6868

69-
typedef void(*demux_func)(struct comp_dev *dev, struct audio_stream *sink,
70-
const struct audio_stream *source, uint32_t frames,
71-
struct mux_look_up *look_up);
69+
typedef void(*demux_func)(struct comp_dev *dev, struct sof_sink *sink,
70+
struct sof_source *source, const void *source_data,
71+
const void *source_start, size_t source_size,
72+
uint32_t frames, struct mux_look_up *look_up);
7273
typedef void(*mux_func)(struct comp_dev *dev, struct audio_stream *sink,
7374
const struct audio_stream **sources, uint32_t frames,
7475
struct mux_look_up *look_up);

0 commit comments

Comments
 (0)