Skip to content

Commit c7cb65c

Browse files
fixup: audio: sink_api: add sink_get_state() and use it in mux
The mux module queried the state of its downstream consumers via the legacy comp_buffer_get_from_sink() wrapper followed by comp_buffer_get_sink_state(). This couples the module to the underlying buffer implementation, which the sink/source API is meant to hide. Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>
1 parent 8a7de4d commit c7cb65c

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

src/audio/buffers/comp_buffer.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ static int comp_buffer_commit_buffer(struct sof_sink *sink, size_t commit_size)
100100
return 0;
101101
}
102102

103+
static int comp_buffer_sink_get_state(struct sof_sink *sink)
104+
{
105+
struct comp_buffer *buffer = comp_buffer_get_from_sink(sink);
106+
107+
return comp_get_state(comp_buffer_get_sink_component(buffer));
108+
}
109+
103110
static int comp_buffer_set_ipc_params(struct sof_audio_buffer *audio_buffer,
104111
struct sof_ipc_stream_params *params,
105112
bool force_update)
@@ -189,6 +196,7 @@ APP_TASK_DATA static const struct sink_ops comp_buffer_sink_ops = {
189196
.on_audio_format_set = audio_buffer_sink_on_audio_format_set,
190197
.set_alignment_constants = audio_buffer_sink_set_alignment_constants,
191198
.get_lft = audio_buffer_sink_get_lft,
199+
.get_state = comp_buffer_sink_get_state,
192200
};
193201

194202
static const struct audio_buffer_ops audio_buffer_ops = {

src/audio/mux/mux.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ static int demux_process(struct processing_module *mod,
251251
*/
252252
frames = source_get_data_frames_available(source);
253253
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)
254+
if (sink_get_state(sinks[i]) != dev->state)
257255
continue;
258256

259257
frames = MIN(frames, sink_get_free_frames(sinks[i]));
@@ -274,12 +272,11 @@ static int demux_process(struct processing_module *mod,
274272
/* produce output, one sink at a time */
275273
for (i = 0; i < num_of_sinks; i++) {
276274
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);
275+
uint32_t pipeline_id = sink_get_pipeline_id(sink);
279276
struct mux_look_up *look_up;
280277

281278
/* skip sinks that are not in the same state as the component */
282-
if (comp_buffer_get_sink_state(sink_buf) != dev->state)
279+
if (sink_get_state(sink) != dev->state)
283280
continue;
284281

285282
/* return if configuration for this pipeline is missing */

src/include/module/audio/sink_api.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ struct sink_ops {
8383
*/
8484
uint32_t (*get_lft)(struct sof_sink *sink);
8585

86+
/**
87+
* OPTIONAL: get the state of the component consuming data from this sink
88+
*
89+
* see comment of sink_get_state()
90+
*/
91+
int (*get_state)(struct sof_sink *sink);
92+
8693
/**
8794
* OPTIONAL: Notification to the sink implementation about changes in audio format
8895
*
@@ -318,6 +325,25 @@ static inline uint32_t sink_get_pipeline_id(struct sof_sink *sink)
318325
return sink->audio_stream_params->pipeline_id;
319326
}
320327

328+
/**
329+
* @brief get the state of the component consuming data from this sink
330+
*
331+
* This allows a data producer to query the state of its downstream consumer
332+
* without reaching into the underlying buffer implementation.
333+
*
334+
* @param sink a sink to be checked
335+
*
336+
* @return state of the consuming component, or COMP_STATE_NOT_EXIST (0) if there
337+
* is no connected consumer or the sink implementation does not track it
338+
*/
339+
static inline int sink_get_state(struct sof_sink *sink)
340+
{
341+
if (!sink->ops->get_state)
342+
return 0; /* COMP_STATE_NOT_EXIST */
343+
344+
return sink->ops->get_state(sink);
345+
}
346+
321347
/**
322348
* @brief hook to be called when a module connects to the API
323349
*

0 commit comments

Comments
 (0)