Skip to content

Commit

Permalink
exttension to audio/audio_buffer.h API
Browse files Browse the repository at this point in the history
add .clean
  • Loading branch information
marcinszkudlinski committed Oct 15, 2024
1 parent 538006a commit 5ab25fb
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 28 deletions.
14 changes: 14 additions & 0 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ static int comp_buffer_sink_set_alignment_constants(struct sof_sink *sink,
return 0;
}

static void comp_buffer_clean(struct sof_audio_buffer *audio_buffer)
{
if (!audio_buffer)
return;

struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer);

/* reset rw pointers and avail/free bytes counters */
audio_stream_reset(&buffer->stream);
/* clear buffer contents */
buffer_zero(buffer);
}

/* free component in the pipeline */
static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)
{
Expand Down Expand Up @@ -197,6 +210,7 @@ static const struct sink_ops comp_buffer_sink_ops = {

static const struct audio_buffer_ops audio_buffer_ops = {
.free = comp_buffer_free,
.clean = comp_buffer_clean,
};

static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, uint32_t caps,
Expand Down
44 changes: 34 additions & 10 deletions src/audio/buffers/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ static inline struct ring_buffer *ring_buffer_from_source(struct sof_source *sou
return container_of(audio_buffer, struct ring_buffer, audio_buffer);
}

/**
* @brief remove the queue from the list, free memory
*/
static void ring_buffer_free(struct sof_audio_buffer *buffer)
{
struct ring_buffer *ring_buffer = (struct ring_buffer *)buffer;

rfree((__sparse_force void *)ring_buffer->_data_buffer);
}

/**
* @brief return true if the ring buffer is shared between 2 cores
*/
Expand Down Expand Up @@ -93,6 +83,39 @@ static inline void ring_buffer_writeback_shared(struct ring_buffer *ring_buffer,
dcache_writeback_region(ptr, size);
}


/**
* @brief remove the queue from the list, free memory
*/
static void ring_buffer_free(struct sof_audio_buffer *audio_buffer)
{
if (!audio_buffer)
return;

struct ring_buffer *ring_buffer =
container_of(audio_buffer, struct ring_buffer, audio_buffer);

rfree((__sparse_force void *)ring_buffer->_data_buffer);
}

static void ring_buffer_clean(struct sof_audio_buffer *audio_buffer)
{
if (!audio_buffer)
return;

struct ring_buffer *ring_buffer =
container_of(audio_buffer, struct ring_buffer, audio_buffer);

ring_buffer->_write_offset = 0;
ring_buffer->_read_offset = 0;

ring_buffer_invalidate_shared(ring_buffer, ring_buffer->_data_buffer,
ring_buffer->data_buffer_size);
bzero(ring_buffer->_data_buffer, ring_buffer->data_buffer_size);
ring_buffer_writeback_shared(ring_buffer, ring_buffer->_data_buffer,
ring_buffer->data_buffer_size);
}

static inline
uint8_t __sparse_cache *ring_buffer_get_pointer(struct ring_buffer *ring_buffer, size_t offset)
{
Expand Down Expand Up @@ -277,6 +300,7 @@ static const struct sink_ops ring_buffer_sink_ops = {

static const struct audio_buffer_ops audio_buffer_ops = {
.free = ring_buffer_free,
.clean = ring_buffer_clean
};

struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_space, bool is_shared,
Expand Down
4 changes: 2 additions & 2 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ int module_adapter_prepare(struct comp_dev *dev)
irq_local_enable(flags);

buffer_set_params(buffer, mod->stream_params, BUFFER_UPDATE_FORCE);
buffer_reset_pos(buffer, NULL);
audio_buffer_clean(&buffer->audio_buffer);
}
} else {
list_for_item(blist, &mod->sink_buffer_list) {
Expand All @@ -400,7 +400,7 @@ int module_adapter_prepare(struct comp_dev *dev)
}

buffer_set_params(buffer, mod->stream_params, BUFFER_UPDATE_FORCE);
buffer_reset_pos(buffer, NULL);
audio_buffer_clean(&buffer->audio_buffer);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/audio/pipeline/pipeline-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ static int pipeline_comp_reset(struct comp_dev *current,
return pipeline_for_each_comp(current, ctx, dir);
}

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

/* reset the whole pipeline */
int pipeline_reset(struct pipeline *p, struct comp_dev *host)
{
Expand Down
5 changes: 5 additions & 0 deletions src/audio/pipeline/pipeline-params.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ static int pipeline_comp_prepare(struct comp_dev *current,
return pipeline_for_each_comp(current, ctx, dir);
}

static void buffer_reset_pos(struct comp_buffer *buffer, void *data)
{
audio_buffer_clean(&buffer->audio_buffer);
}

/* prepare the pipeline for usage */
int pipeline_prepare(struct pipeline *p, struct comp_dev *dev)
{
Expand Down
18 changes: 18 additions & 0 deletions src/include/sof/audio/audio_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ struct audio_buffer_ops {
* OPTIONAL
*/
void (*free)(struct sof_audio_buffer *buffer);

/**
* @brief clean all buffer data leaving config as is
* the procedure is to be called only when buffer is not in use
* OPTIONAL
*/
void (*clean)(struct sof_audio_buffer *buffer);
};

/* base class for all buffers, all buffers must inherit from it */
Expand Down Expand Up @@ -267,4 +274,15 @@ void audio_buffer_init(struct sof_audio_buffer *buffer, uint32_t buffer_type, bo
*/
void audio_buffer_free(struct sof_audio_buffer *buffer);

/**
* @brief clean all buffer data leaving config as is
* the procedure is to be called only when buffer is not in use
*/
static inline
void audio_buffer_clean(struct sof_audio_buffer *buffer)
{
if (buffer->ops->clean)
buffer->ops->clean(buffer);
}

#endif /* __SOF_AUDIO_BUFFER__ */
14 changes: 0 additions & 14 deletions src/include/sof/audio/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,25 +279,11 @@ static inline uint32_t buffer_pipeline_id(const struct comp_buffer *buffer)
return buffer->stream.runtime_stream_params.pipeline_id;
}

static inline void buffer_reset_pos(struct comp_buffer *buffer, void *data)
{
/* reset rw pointers and avail/free bytes counters */
audio_stream_reset(&buffer->stream);

/* clear buffer contents */
buffer_zero(buffer);
}

/* Run-time buffer re-configuration calls this too, so it must use cached access */
static inline void buffer_init_stream(struct comp_buffer *buffer, size_t size)
{
/* addr should be set in alloc function */
audio_stream_init(&buffer->stream, buffer->stream.addr, size);
}

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

#endif /* __SOF_AUDIO_BUFFER_H__ */
4 changes: 2 additions & 2 deletions tools/plugin/modules/alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ static int arecord_params(struct comp_dev *dev, struct sof_ipc_stream_params *pa

/* file component sink/source buffer period count */
buffer = comp_dev_get_first_data_consumer(dev);
buffer_reset_pos(buffer, NULL);
audio_buffer_clean(&buffer->audio_buffer);

comp_dbg(dev, "prepare done ret = %d", ret);

Expand Down Expand Up @@ -461,7 +461,7 @@ static int aplay_params(struct comp_dev *dev, struct sof_ipc_stream_params *para

/* file component sink/source buffer period count */
buffer = comp_dev_get_first_data_producer(dev);
buffer_reset_pos(buffer, NULL);
audio_buffer_clean(&buffer->audio_buffer);

comp_dbg(dev, "prepare done ret = %d", ret);
return 0;
Expand Down

0 comments on commit 5ab25fb

Please sign in to comment.