Skip to content

Commit

Permalink
buf: move hw_params_configured flag to stream_params structure
Browse files Browse the repository at this point in the history
hw_params_configured is a flag indicating that a buffer params has
been already set, and should be kept in the same structure as the
params themselves

this commit moves hw_params_configured to sof_audio_stream_params
and introduces API to handle the flag

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
  • Loading branch information
marcinszkudlinski authored and kv2019i committed Sep 27, 2024
1 parent 4a8a356 commit 7033e15
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ int buffer_set_params(struct comp_buffer *buffer,
return -EINVAL;
}

if (buffer->hw_params_configured && !force_update)
if (audio_buffer_hw_params_configured(&buffer->audio_buffer) && !force_update)
return 0;

ret = audio_stream_set_params(&buffer->stream, params);
Expand All @@ -442,7 +442,7 @@ int buffer_set_params(struct comp_buffer *buffer,
for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++)
buffer->chmap[i] = params->chmap[i];

buffer->hw_params_configured = true;
audio_buffer_set_hw_params_configured(&buffer->audio_buffer);

return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions src/audio/buffers/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ static int ring_buffer_set_ipc_params(struct ring_buffer *ring_buffer,
bool force_update)
{
CORE_CHECK_STRUCT(&ring_buffer->audio_buffer);
if (ring_buffer->_hw_params_configured && !force_update)

if (audio_buffer_hw_params_configured(&ring_buffer->audio_buffer) && !force_update)
return 0;

struct sof_audio_stream_params *audio_stream_params =
Expand All @@ -235,7 +236,7 @@ static int ring_buffer_set_ipc_params(struct ring_buffer *ring_buffer,
audio_stream_params->channels = params->channels;
audio_stream_params->buffer_fmt = params->buffer_fmt;

ring_buffer->_hw_params_configured = true;
audio_buffer_set_hw_params_configured(&ring_buffer->audio_buffer);

return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ static int do_conversion_copy(struct comp_dev *dev,
int i;

/* buffer params might be not yet configured by component on another pipeline */
if (!src->hw_params_configured || !sink->hw_params_configured)
if (!audio_buffer_hw_params_configured(&src->audio_buffer) ||
!audio_buffer_hw_params_configured(&sink->audio_buffer))
return 0;

comp_get_copy_limits(src, sink, processed_data);
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 @@ -194,7 +194,7 @@ int create_endpoint_buffer(struct comp_dev *dev,
for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++)
buffer->chmap[i] = (chan_map >> i * 4) & 0xf;

buffer->hw_params_configured = true;
audio_buffer_set_hw_params_configured(&buffer->audio_buffer);

if (create_multi_endpoint_buffer)
cd->multi_endpoint_buffer = buffer;
Expand Down
8 changes: 4 additions & 4 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
}

if (sink_dev && sink_dev->state == COMP_STATE_ACTIVE &&
sink->hw_params_configured) {
audio_buffer_hw_params_configured(&sink->audio_buffer)) {
ret = stream_copy_from_no_consume(dd->local_buffer, sink,
converter[j], bytes, dd->chmap);
}
Expand Down Expand Up @@ -353,7 +353,7 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
}

if (sink_dev && sink_dev->state == COMP_STATE_ACTIVE &&
sink->hw_params_configured)
audio_buffer_hw_params_configured(&sink->audio_buffer))
ret = stream_copy_from_no_consume(dd->dma_buffer,
sink, converter[j],
bytes, dd->chmap);
Expand Down Expand Up @@ -1650,7 +1650,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
sink_dev = sink->sink;

if (sink_dev && sink_dev->state == COMP_STATE_ACTIVE &&
sink->hw_params_configured) {
audio_buffer_hw_params_configured(&sink->audio_buffer)) {
sink_frames =
audio_stream_get_free_frames(&sink->stream);
frames = MIN(frames, sink_frames);
Expand Down Expand Up @@ -1680,7 +1680,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
sink_dev = sink->sink;

if (sink_dev && sink_dev->state == COMP_STATE_ACTIVE &&
sink->hw_params_configured) {
audio_buffer_hw_params_configured(&sink->audio_buffer)) {
sink_frames =
audio_stream_get_free_frames(&sink->stream);
frames = MIN(frames, sink_frames);
Expand Down
2 changes: 1 addition & 1 deletion src/audio/mux/mux_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void set_mux_params(struct processing_module *mod)
if (!list_is_empty(&dev->bsink_list)) {
sink = comp_dev_get_first_data_consumer(dev);

if (!sink->hw_params_configured) {
if (!audio_buffer_hw_params_configured(&sink->audio_buffer)) {
ipc4_update_buffer_format(sink, &cd->md.output_format);
params->frame_fmt = audio_stream_get_frm_fmt(&sink->stream);
}
Expand Down
2 changes: 1 addition & 1 deletion src/audio/selector/selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ static void set_selector_params(struct processing_module *mod,
*/
src_buf = comp_dev_get_first_data_producer(dev);

if (!src_buf->hw_params_configured)
if (!audio_buffer_hw_params_configured(&src_buf->audio_buffer))
ipc4_update_buffer_format(src_buf, &mod->priv.cfg.base_cfg.audio_fmt);
}

Expand Down
2 changes: 2 additions & 0 deletions src/include/module/audio/audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct sof_audio_stream_params {
bool underrun_permitted; /**< indicates whether underrun is permitted */

uint32_t buffer_fmt; /**< enum sof_ipc_buffer_format */

bool hw_params_configured; /**< indicates whether hw params were set */
};

#endif /* __MODULE_AUDIO_AUDIO_STREAM_H__ */
15 changes: 15 additions & 0 deletions src/include/sof/audio/audio_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ static inline bool audio_buffer_is_shared(struct sof_audio_buffer *buffer)
return buffer->is_shared;
}

static inline bool audio_buffer_hw_params_configured(struct sof_audio_buffer *buffer)
{
return buffer->audio_stream_params->hw_params_configured;
}

static inline void audio_buffer_set_hw_params_configured(struct sof_audio_buffer *buffer)
{
buffer->audio_stream_params->hw_params_configured = true;
}

static inline void audio_buffer_reset_params(struct sof_audio_buffer *buffer)
{
buffer->audio_stream_params->hw_params_configured = false;
}

/**
* @brief return a handler to stream params structure
*/
Expand Down
3 changes: 1 addition & 2 deletions src/include/sof/audio/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ struct comp_buffer {
/* runtime stream params */
uint16_t chmap[SOF_IPC_MAX_CHANNELS]; /**< channel map - SOF_CHMAP_ */

bool hw_params_configured; /**< indicates whether hw params were set */
bool walking; /**< indicates if the buffer is being walked */
};

Expand Down Expand Up @@ -285,7 +284,7 @@ static inline void buffer_init_stream(struct comp_buffer *buffer, size_t size)

static inline void buffer_reset_params(struct comp_buffer *buffer, void *data)
{
buffer->hw_params_configured = false;
audio_buffer_reset_params(&buffer->audio_buffer);
}

#endif /* __SOF_AUDIO_BUFFER_H__ */
2 changes: 0 additions & 2 deletions src/include/sof/audio/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ struct ring_buffer {
uint8_t __sparse_cache *_data_buffer;
size_t _write_offset; /* private: to be modified by data producer using API */
size_t _read_offset; /* private: to be modified by data consumer using API */

bool _hw_params_configured;
};

/**
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 @@ -1196,7 +1196,7 @@ void ipc4_update_buffer_format(struct comp_buffer *buf_c,
for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++)
buf_c->chmap[i] = (fmt->ch_map >> i * 4) & 0xf;

buf_c->hw_params_configured = true;
audio_buffer_set_hw_params_configured(&buf_c->audio_buffer);
}

void ipc4_update_source_format(struct sof_source *source,
Expand Down

0 comments on commit 7033e15

Please sign in to comment.