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

Add get buffer ID to sink/src api #8433

Merged
merged 2 commits into from
Nov 22, 2023
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
6 changes: 3 additions & 3 deletions src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static int do_conversion_copy(struct comp_dev *dev,

comp_get_copy_limits(src, sink, processed_data);

i = IPC4_SINK_QUEUE_ID(sink->id);
i = IPC4_SINK_QUEUE_ID(buf_get_id(sink));
if (i >= IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT)
return -EINVAL;
buffer_stream_invalidate(src, processed_data->source_bytes);
Expand Down Expand Up @@ -483,7 +483,7 @@ static int copier_module_copy(struct processing_module *mod,
uint32_t samples;
int sink_queue_id;

sink_queue_id = IPC4_SINK_QUEUE_ID(sink_c->id);
sink_queue_id = IPC4_SINK_QUEUE_ID(buf_get_id(sink_c));
if (sink_queue_id >= IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT)
return -EINVAL;

Expand Down Expand Up @@ -668,7 +668,7 @@ static int copier_set_sink_fmt(struct comp_dev *dev, const void *data,

sink = container_of(sink_list, struct comp_buffer, source_list);

sink_id = IPC4_SINK_QUEUE_ID(sink->id);
sink_id = IPC4_SINK_QUEUE_ID(buf_get_id(sink));
if (sink_id == sink_fmt->sink_id) {
ipc4_update_buffer_format(sink, &sink_fmt->sink_fmt);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/copier/copier_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void copier_update_params(struct copier_data *cd, struct comp_dev *dev,

sink = container_of(sink_list, struct comp_buffer, source_list);

j = IPC4_SINK_QUEUE_ID(sink->id);
j = IPC4_SINK_QUEUE_ID(buf_get_id(sink));

ipc4_update_buffer_format(sink, &cd->out_fmt[j]);
}
Expand Down
4 changes: 2 additions & 2 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,

sink_dev = sink->sink;

j = IPC4_SINK_QUEUE_ID(sink->id);
j = IPC4_SINK_QUEUE_ID(buf_get_id(sink));

if (j >= IPC4_COPIER_MODULE_OUTPUT_PINS_COUNT) {
comp_err(dev, "Sink queue ID: %d >= max output pin count: %d\n",
Expand Down Expand Up @@ -1644,7 +1644,7 @@ int dai_zephyr_unbind(struct dai_data *dd, struct comp_dev *dev, void *data)
buf_id = IPC4_COMP_ID(bu->extension.r.src_queue, bu->extension.r.dst_queue);

if (dd && dd->local_buffer) {
if (dd->local_buffer->id == buf_id) {
if (buf_get_id(dd->local_buffer) == buf_id) {
comp_dbg(dev, "dai_zephyr_unbind: local_buffer %x unbound", buf_id);
dd->local_buffer = NULL;
}
Expand Down
8 changes: 5 additions & 3 deletions src/audio/dp_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ static const struct sink_ops dp_queue_sink_ops = {
.audio_set_ipc_params = dp_queue_set_ipc_params_sink,
};

struct dp_queue *dp_queue_create(size_t min_available, size_t min_free_space, uint32_t flags)
struct dp_queue *dp_queue_create(size_t min_available, size_t min_free_space, uint32_t flags,
uint32_t id)
{
struct dp_queue *dp_queue;

Expand Down Expand Up @@ -286,8 +287,9 @@ struct dp_queue *dp_queue_create(size_t min_available, size_t min_free_space, ui
if (!dp_queue->_data_buffer)
goto err;

tr_info(&dp_queue_tr, "DpQueue created, shared: %u min_available: %u min_free_space %u, size %u",
dp_queue_is_shared(dp_queue), min_available, min_free_space,
dp_queue->audio_stream_params.id = id;
tr_info(&dp_queue_tr, "DpQueue created, id: %u shared: %u min_available: %u min_free_space %u, size %u",
id, dp_queue_is_shared(dp_queue), min_available, min_free_space,
dp_queue->data_buffer_size);

/* return a pointer to allocated structure */
Expand Down
3 changes: 2 additions & 1 deletion src/audio/google/google_rtc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ static int google_rtc_audio_processing_prepare(struct processing_module *mod,
struct comp_buffer *source = container_of(source_buffer_list_item,
struct comp_buffer, sink_list);
#if CONFIG_IPC_MAJOR_4
if (IPC4_SINK_QUEUE_ID(source->id) == SOF_AEC_FEEDBACK_QUEUE_ID) {
if (IPC4_SINK_QUEUE_ID(buf_get_id(source)) ==
SOF_AEC_FEEDBACK_QUEUE_ID) {
#else
if (source->source->pipeline->pipeline_id != dev->pipeline->pipeline_id) {
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static int kpb_bind(struct comp_dev *dev, void *data)
break;
}

sink_buf_id = sink->id;
sink_buf_id = buf_get_id(sink);

if (sink_buf_id == buf_id) {
if (sink_buf_id == 0)
Expand Down Expand Up @@ -903,7 +903,7 @@ static int kpb_prepare(struct comp_dev *dev)

audio_stream_init_alignment_constants(byte_align, frame_align_req,
&sink->stream);
sink_id = sink->id;
sink_id = buf_get_id(sink);

if (sink_id == 0)
audio_stream_set_channels(&sink->stream, kpb->num_of_sel_mic);
Expand Down
4 changes: 2 additions & 2 deletions src/audio/mixin_mixout/mixin_mixout.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static int mixin_process(struct processing_module *mod,
unused_in_between_buf_c = container_of(output_buffers[i].data,
struct comp_buffer, stream);
mixout = unused_in_between_buf_c->sink;
sink_id = IPC4_SRC_QUEUE_ID(unused_in_between_buf_c->id);
sink_id = IPC4_SRC_QUEUE_ID(buf_get_id(unused_in_between_buf_c));

active_mixouts[i] = mixout;
sinks_ids[i] = sink_id;
Expand Down Expand Up @@ -570,7 +570,7 @@ static int mixin_params(struct processing_module *mod)
/* Applying channel remapping may produce sink stream with channel count
* different from source channel count.
*/
sink_id = IPC4_SRC_QUEUE_ID(sink->id);
sink_id = IPC4_SRC_QUEUE_ID(buf_get_id(sink));
if (sink_id >= MIXIN_MAX_SINKS) {
comp_err(dev, "Sink index out of range: %u, max sink count: %u",
(uint32_t)sink_id, MIXIN_MAX_SINKS);
Expand Down
6 changes: 4 additions & 2 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ static int module_adapter_dp_queue_prepare(struct comp_dev *dev)
sink_get_min_free_space(audio_stream_get_sink(&source_buffer->stream));

/* create a shadow dp queue */
dp_queue = dp_queue_create(min_available, min_free_space, dp_mode);
dp_queue = dp_queue_create(min_available, min_free_space, dp_mode,
buf_get_id(source_buffer));

if (!dp_queue)
goto err;
Expand Down Expand Up @@ -223,7 +224,8 @@ static int module_adapter_dp_queue_prepare(struct comp_dev *dev)
sink_get_min_free_space(audio_stream_get_sink(&sink_buffer->stream));

/* create a shadow dp queue */
dp_queue = dp_queue_create(min_available, min_free_space, dp_mode);
dp_queue = dp_queue_create(min_available, min_free_space, dp_mode,
buf_get_id(sink_buffer));

if (!dp_queue)
goto err;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mux/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static void set_mux_params(struct processing_module *mod)
source = container_of(source_list, struct comp_buffer, sink_list);
audio_stream_init_alignment_constants(byte_align, frame_align_req,
&source->stream);
j = source->id;
j = buf_get_id(source);
cd->config.streams[j].pipeline_id = source->pipeline_id;
if (j == BASE_CFG_QUEUED_ID)
audio_fmt = &cd->md.base_cfg.audio_fmt;
Expand Down
8 changes: 4 additions & 4 deletions src/audio/pipeline/pipeline-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ int pipeline_connect(struct comp_dev *comp, struct comp_buffer *buffer,
uint32_t flags;

if (dir == PPL_CONN_DIR_COMP_TO_BUFFER)
comp_info(comp, "connect buffer %d as sink", buffer->id);
comp_info(comp, "connect buffer %d as sink", buf_get_id(buffer));
else
comp_info(comp, "connect buffer %d as source", buffer->id);
comp_info(comp, "connect buffer %d as source", buf_get_id(buffer));

irq_local_disable(flags);

Expand All @@ -202,9 +202,9 @@ void pipeline_disconnect(struct comp_dev *comp, struct comp_buffer *buffer, int
uint32_t flags;

if (dir == PPL_CONN_DIR_COMP_TO_BUFFER)
comp_dbg(comp, "disconnect buffer %d as sink", buffer->id);
comp_dbg(comp, "disconnect buffer %d as sink", buf_get_id(buffer));
else
comp_dbg(comp, "disconnect buffer %d as source", buffer->id);
comp_dbg(comp, "disconnect buffer %d as source", buf_get_id(buffer));

irq_local_disable(flags);

Expand Down
3 changes: 2 additions & 1 deletion src/audio/rtnr/rtnr.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ static int rtnr_copy(struct comp_dev *dev)
/* Process integer multiple of RTNR internal block length */
frames = frames & ~RTNR_BLK_LENGTH_MASK;

comp_dbg(dev, "rtnr_copy() source->id: %d, frames = %d", source->id, frames);
comp_dbg(dev, "rtnr_copy() source_id: %d, frames = %d", buf_get_id(source),
frames);

if (frames) {
source_bytes = frames * audio_stream_frame_bytes(&source->stream);
Expand Down
6 changes: 6 additions & 0 deletions src/audio/sink_api_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,9 @@ size_t sink_get_min_free_space(struct sof_sink *sink)
{
return sink->min_free_space;
}

uint32_t sink_get_id(struct sof_sink *sink)
Copy link
Member

Choose a reason for hiding this comment

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

These should be static inline. There is PR in flow for splitting header directories and we will be able to catch this in the correct folder i.e. for baseFW or module usage.

Copy link
Contributor

Choose a reason for hiding this comment

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

static inline and put it tou sink_api.h and source_api.h accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. We agreed lately the full sink/src encapsulation is too expensive and all "small" functions should be inline (#8100)

It has been implemented for sink/src as a part of #8365. Till 8365 is merged I prefer to follow the obsolete way to avoid merge conflicts

{
return sink->audio_stream_params->id;
}

5 changes: 5 additions & 0 deletions src/audio/source_api_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,8 @@ size_t source_get_min_available(struct sof_source *source)
{
return source->min_available;
}

uint32_t source_get_id(struct sof_source *source)
{
return source->audio_stream_params->id;
}
1 change: 1 addition & 0 deletions src/include/sof/audio/audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* TODO: compressed formats
*/
struct sof_audio_stream_params {
uint32_t id;
enum sof_ipc_frame frame_fmt; /**< Sample data format */
enum sof_ipc_frame valid_sample_fmt;

Expand Down
19 changes: 9 additions & 10 deletions src/include/sof/audio/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern struct tr_ctx buffer_tr;
#define trace_buf_get_id(buf_ptr) ((buf_ptr)->pipeline_id)

/** \brief Retrieves subid (comp id) from the buffer */
#define trace_buf_get_subid(buf_ptr) ((buf_ptr)->id)
#define buf_get_id(buf_ptr) ((buf_ptr)->stream.runtime_stream_params.id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the ID really a runtime parameter? Isn't it persistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is set once, not modified later. Anyway - in rutime
As it is a common parameter for all streams, no matter how buffers are implemented, so I put it to this container
But you're right, it the name of the container may be somehow misleading, I'll change it


#if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG)

Expand All @@ -58,36 +58,36 @@ extern struct tr_ctx buffer_tr;
#endif

#define buf_err(buf_ptr, __e, ...) LOG_ERR(__BUF_FMT __e, trace_buf_get_id(buf_ptr), \
trace_buf_get_subid(buf_ptr), ##__VA_ARGS__)
buf_get_id(buf_ptr), ##__VA_ARGS__)

#define buf_warn(buf_ptr, __e, ...) LOG_WRN(__BUF_FMT __e, trace_buf_get_id(buf_ptr), \
trace_buf_get_subid(buf_ptr), ##__VA_ARGS__)
buf_get_id(buf_ptr), ##__VA_ARGS__)

#define buf_info(buf_ptr, __e, ...) LOG_INF(__BUF_FMT __e, trace_buf_get_id(buf_ptr), \
trace_buf_get_subid(buf_ptr), ##__VA_ARGS__)
buf_get_id(buf_ptr), ##__VA_ARGS__)

#define buf_dbg(buf_ptr, __e, ...) LOG_DBG(__BUF_FMT __e, trace_buf_get_id(buf_ptr), \
trace_buf_get_subid(buf_ptr), ##__VA_ARGS__)
buf_get_id(buf_ptr), ##__VA_ARGS__)

#else
/** \brief Trace error message from buffer */
#define buf_err(buf_ptr, __e, ...) \
trace_dev_err(trace_buf_get_tr_ctx, trace_buf_get_id, \
trace_buf_get_subid, \
buf_get_id, \
(__sparse_force const struct comp_buffer *)buf_ptr, \
__e, ##__VA_ARGS__)

/** \brief Trace warning message from buffer */
#define buf_warn(buf_ptr, __e, ...) \
trace_dev_warn(trace_buf_get_tr_ctx, trace_buf_get_id, \
trace_buf_get_subid, \
buf_get_id, \
(__sparse_force const struct comp_buffer *)buf_ptr, \
__e, ##__VA_ARGS__)

/** \brief Trace info message from buffer */
#define buf_info(buf_ptr, __e, ...) \
trace_dev_info(trace_buf_get_tr_ctx, trace_buf_get_id, \
trace_buf_get_subid, \
buf_get_id, \
(__sparse_force const struct comp_buffer *)buf_ptr, \
__e, ##__VA_ARGS__)

Expand All @@ -97,7 +97,7 @@ extern struct tr_ctx buffer_tr;
#else
#define buf_dbg(buf_ptr, __e, ...) \
trace_dev_dbg(trace_buf_get_tr_ctx, trace_buf_get_id, \
trace_buf_get_subid, \
buf_get_id, \
(__sparse_force const struct comp_buffer *)buf_ptr, \
__e, ##__VA_ARGS__)
#endif
Expand Down Expand Up @@ -139,7 +139,6 @@ struct comp_buffer {
struct audio_stream stream;

/* configuration */
uint32_t id;
uint32_t pipeline_id;
uint32_t caps;
uint32_t core;
Expand Down
5 changes: 4 additions & 1 deletion src/include/sof/audio/dp_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ struct dp_queue {
*
* @param flags a combinatin of DP_QUEUE_MODE_* flags determining working mode
*
* @param id a stream ID, accessible later by sink_get_id/source_get_id
*
*/
struct dp_queue *dp_queue_create(size_t min_available, size_t min_free_space, uint32_t flags);
struct dp_queue *dp_queue_create(size_t min_available, size_t min_free_space, uint32_t flags,
uint32_t id);

/**
* @brief remove the queue from the list, free dp queue memory
Expand Down
1 change: 1 addition & 0 deletions src/include/sof/audio/sink_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ int sink_set_overrun(struct sof_sink *sink, bool overrun_permitted);
int sink_set_buffer_fmt(struct sof_sink *sink, uint32_t buffer_fmt);
void sink_set_min_free_space(struct sof_sink *sink, size_t min_free_space);
size_t sink_get_min_free_space(struct sof_sink *sink);
uint32_t sink_get_id(struct sof_sink *sink);

/**
* initial set of audio parameters, provided in sof_ipc_stream_params
Expand Down
1 change: 1 addition & 0 deletions src/include/sof/audio/source_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ unsigned int source_get_rate(struct sof_source *source);
unsigned int source_get_channels(struct sof_source *source);
uint32_t source_get_buffer_fmt(struct sof_source *source);
bool source_get_underrun(struct sof_source *source);
uint32_t source_get_id(struct sof_source *source);

/** set of functions for setting audio parameters */
int source_set_frm_fmt(struct sof_source *source, enum sof_ipc_frame frm_fmt);
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/ipc-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared
buffer = buffer_alloc(desc->size, desc->caps, desc->flags, PLATFORM_DCACHE_ALIGN,
is_shared);
if (buffer) {
buffer->id = desc->comp.id;
buffer->stream.runtime_stream_params.id = desc->comp.id;
buffer->pipeline_id = desc->comp.pipeline_id;
buffer->core = desc->comp.core;

Expand Down
2 changes: 1 addition & 1 deletion src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ int ipc_comp_disconnect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
buffer_id = IPC4_COMP_ID(bu->extension.r.src_queue, bu->extension.r.dst_queue);
list_for_item(sink_list, &src->bsink_list) {
struct comp_buffer *buf = container_of(sink_list, struct comp_buffer, source_list);
bool found = buf->id == buffer_id;
bool found = buf_get_id(buf) == buffer_id;

if (found) {
buffer = buf;
Expand Down
4 changes: 2 additions & 2 deletions src/probe/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ static struct comp_buffer *ipc4_get_buffer(struct ipc_comp_dev *dev, probe_point
case PROBE_TYPE_INPUT:
list_for_item(source_list, &dev->cd->bsource_list) {
buf = container_of(source_list, struct comp_buffer, sink_list);
queue_id = IPC4_SRC_QUEUE_ID(buf->id);
queue_id = IPC4_SRC_QUEUE_ID(buf_get_id(buf));

if (queue_id == probe_point.fields.index)
return buf;
Expand All @@ -1082,7 +1082,7 @@ static struct comp_buffer *ipc4_get_buffer(struct ipc_comp_dev *dev, probe_point
case PROBE_TYPE_OUTPUT:
list_for_item(sink_list, &dev->cd->bsink_list) {
buf = container_of(sink_list, struct comp_buffer, source_list);
queue_id = IPC4_SINK_QUEUE_ID(buf->id);
queue_id = IPC4_SINK_QUEUE_ID(buf_get_id(buf));

if (queue_id == probe_point.fields.index)
return buf;
Expand Down
6 changes: 4 additions & 2 deletions src/samples/audio/smart_amp_test_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ static int smart_amp_process(struct processing_module *mod,
for (i = 0; i < num_input_buffers; i++) {
buf = container_of(input_buffers[i].data, struct comp_buffer, stream);

if (IPC4_SINK_QUEUE_ID(buf->id) == SOF_SMART_AMP_FEEDBACK_QUEUE_ID) {
if (IPC4_SINK_QUEUE_ID(buf_get_id(buf)) ==
SOF_SMART_AMP_FEEDBACK_QUEUE_ID) {
fb_input = &input_buffers[i];
fb_buf_c = buf;
} else {
Expand Down Expand Up @@ -356,7 +357,8 @@ static int smart_amp_prepare(struct processing_module *mod,
source_buffer = container_of(blist, struct comp_buffer,
sink_list);
audio_stream_init_alignment_constants(1, 1, &source_buffer->stream);
if (IPC4_SINK_QUEUE_ID(source_buffer->id) == SOF_SMART_AMP_FEEDBACK_QUEUE_ID) {
if (IPC4_SINK_QUEUE_ID(buf_get_id(source_buffer)) ==
SOF_SMART_AMP_FEEDBACK_QUEUE_ID) {
audio_stream_set_channels(&source_buffer->stream,
sad->config.feedback_channels);
audio_stream_set_rate(&source_buffer->stream,
Expand Down