Skip to content

Commit b5db075

Browse files
module: audio: add component state accessors to sink and source APIs
Add optional get_state callbacks and accessors for querying upstream and downstream component states. Return COMP_STATE_NOT_EXIST when unavailable. Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>
1 parent 1122d31 commit b5db075

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

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
*

src/include/module/audio/source_api.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ struct source_ops {
7979
*/
8080
int (*release_data)(struct sof_source *source, size_t free_size);
8181

82+
/**
83+
* OPTIONAL: get the state of the component producing data to this source
84+
*
85+
* see comment of source_get_comp_state()
86+
*/
87+
int (*get_state)(struct sof_source *source);
88+
8289
/**
8390
* OPTIONAL: Notification to the source implementation about changes in audio format
8491
*
@@ -341,6 +348,25 @@ static inline enum sof_audio_buffer_state source_get_state(const struct sof_sour
341348
return source->audio_stream_params->state;
342349
}
343350

351+
/**
352+
* @brief get the state of the component producing data to this source
353+
*
354+
* This allows a data consumer to query the state of its upstream producer
355+
* without reaching into the underlying buffer implementation.
356+
*
357+
* @param source a source to be checked
358+
*
359+
* @return state of the producing component, or COMP_STATE_NOT_EXIST (0) if there
360+
* is no connected producer or the source implementation does not track it
361+
*/
362+
static inline int source_get_comp_state(struct sof_source *source)
363+
{
364+
if (!source->ops->get_state)
365+
return 0; /* COMP_STATE_NOT_EXIST */
366+
367+
return source->ops->get_state(source);
368+
}
369+
344370
static inline uint32_t source_align_frames_round_up(struct sof_source *source, uint32_t frames)
345371
{
346372
uint16_t align = source->audio_stream_params->align_frame_cnt;

0 commit comments

Comments
 (0)