Skip to content

Commit

Permalink
source API: mark data pointers as const
Browse files Browse the repository at this point in the history
Data provided by source interface cannot be modified in any way
by the module using source API.
Mark pointers as const

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
  • Loading branch information
marcinszkudlinski committed Aug 25, 2023
1 parent 8c902e9 commit fc29214
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/audio/audio_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ static size_t audio_stream_get_data_available(struct sof_source __sparse_cache *
}

static int audio_stream_get_data(struct sof_source __sparse_cache *source, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size)
void const **data_ptr, void const **buffer_start,
size_t *buffer_size)
{
struct audio_stream __sparse_cache *audio_stream =
attr_container_of(source, struct audio_stream __sparse_cache,
Expand Down
13 changes: 8 additions & 5 deletions src/audio/dp_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,26 @@ static int dp_queue_commit_buffer(struct sof_sink *sink, size_t commit_size)
}

static int dp_queue_get_data(struct sof_source *source, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size)
void const **data_ptr, void const **buffer_start, size_t *buffer_size)
{
struct dp_queue *dp_queue = dp_queue_from_source(source);
void *_data_ptr;

if (req_size > dp_queue_get_data_available(source))
return -ENODATA;

_data_ptr = dp_queue_get_pointer(dp_queue, dp_queue->read_offset);

/* clean cache in provided data range */
dp_queue_invalidate_shared(dp_queue, _data_ptr, req_size);

/*
* note! a sparse warning will be generated here till
* https://github.com/thesofproject/sof/issues/8006 is implemented
*/
*buffer_start = dp_queue->data_buffer;
*buffer_size = dp_queue->data_buffer_size;
*data_ptr = dp_queue_get_pointer(dp_queue, dp_queue->read_offset);

/* clean cache in provided data range */
dp_queue_invalidate_shared(dp_queue, *data_ptr, req_size);
*data_ptr = _data_ptr;

return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions src/audio/sink_source_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
int source_to_sink_copy(struct sof_source __sparse_cache *source,
struct sof_sink __sparse_cache *sink, bool free, size_t size)
{
uint8_t *src_ptr;
uint8_t *src_begin;
uint8_t *src_end;
uint8_t const *src_ptr;
uint8_t const *src_begin;
uint8_t const *src_end;
uint8_t *dst_ptr;
uint8_t *dst_begin;
uint8_t *dst_end;
Expand All @@ -32,8 +32,8 @@ int source_to_sink_copy(struct sof_source __sparse_cache *source,
return -ENOSPC;

ret = source_get_data(source, size,
(void **)&src_ptr,
(void **)&src_begin,
(void const **)&src_ptr,
(void const **)&src_begin,
&src_size);
if (ret)
return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/source_api_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ size_t source_get_data_available(struct sof_source __sparse_cache *source)
}

int source_get_data(struct sof_source __sparse_cache *source, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size)
void const **data_ptr, void const **buffer_start, size_t *buffer_size)
{
int ret;

Expand Down
24 changes: 13 additions & 11 deletions src/audio/src/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct comp_data {
uint32_t sink_rate;
uint32_t source_rate;
int32_t *sbuf_w_ptr;
int32_t *sbuf_r_ptr;
int32_t const *sbuf_r_ptr;
int sbuf_avail;
int data_shift;
int source_frames;
Expand Down Expand Up @@ -353,7 +353,8 @@ static int src_2s(struct comp_data *cd,
int s2_blk_out;
uint32_t n_read = 0, n_written = 0;
int ret;
uint8_t *buffer_start;
uint8_t const *source_buffer_start;
uint8_t *sink_buffer_start;
void *sbuf_end_addr = &cd->delay_lines[cd->param.sbuf_length];
size_t sbuf_size = cd->param.sbuf_length * sizeof(int32_t);
/* chan sink == chan src therefore we only need to use one*/
Expand All @@ -366,18 +367,18 @@ static int src_2s(struct comp_data *cd,
uint32_t sink_frag_size = cd->param.blk_out * sink_get_frame_bytes(sink);

ret = source_get_data(source, source_frag_size,
&s1.x_rptr, (void **)&buffer_start, &s1.x_size);
&s1.x_rptr, (void const **)&source_buffer_start, &s1.x_size);
if (ret)
return ret;
s1.x_end_addr = buffer_start + s1.x_size;
s1.x_end_addr = source_buffer_start + s1.x_size;

ret = sink_get_buffer(sink, sink_frag_size,
&s2.y_wptr, (void **)&buffer_start, &s2.y_size);
&s2.y_wptr, (void **)&sink_buffer_start, &s2.y_size);
if (ret) {
source_release_data(source, 0);
return ret;
}
s2.y_end_addr = buffer_start + s2.y_size;
s2.y_end_addr = sink_buffer_start + s2.y_size;

s1.y_end_addr = sbuf_end_addr;
s1.y_size = sbuf_size;
Expand Down Expand Up @@ -448,23 +449,24 @@ static int src_1s(struct comp_data *cd, struct sof_source __sparse_cache *source
{
struct src_stage_prm s1;
int ret;
uint8_t *buffer_start;
uint8_t const *source_buffer_start;
uint8_t *sink_buffer_start;
uint32_t source_frag_size = cd->param.blk_in * source_get_frame_bytes(source);
uint32_t sink_frag_size = cd->param.blk_out * sink_get_frame_bytes(sink);

ret = source_get_data(source, source_frag_size,
&s1.x_rptr, (void **)&buffer_start, &s1.x_size);
&s1.x_rptr, (void const **)&source_buffer_start, &s1.x_size);
if (ret)
return ret;
s1.x_end_addr = buffer_start + s1.x_size;
s1.x_end_addr = source_buffer_start + s1.x_size;

ret = sink_get_buffer(sink, sink_frag_size,
&s1.y_wptr, (void **)&buffer_start, &s1.y_size);
&s1.y_wptr, (void **)&sink_buffer_start, &s1.y_size);
if (ret) {
source_release_data(source, 0);
return ret;
}
s1.y_end_addr = buffer_start + s1.y_size;
s1.y_end_addr = sink_buffer_start + s1.y_size;

s1.times = cd->param.stage1_times;
s1.state = &cd->src.state1;
Expand Down
2 changes: 1 addition & 1 deletion src/include/sof/audio/source_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ size_t source_get_data_frames_available(struct sof_source __sparse_cache *source
* @retval -ENODATA if req_size is bigger than available data
*/
int source_get_data(struct sof_source __sparse_cache *source, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size);
void const **data_ptr, void const **buffer_start, size_t *buffer_size);

/**
* Releases fragment previously obtained by source_get_data()
Expand Down
2 changes: 1 addition & 1 deletion src/include/sof/audio/source_api_implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct source_ops {
* see comment of source_get_data_available()
*/
int (*get_data)(struct sof_source __sparse_cache *source, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size);
void const **data_ptr, void const **buffer_start, size_t *buffer_size);

/**
* see comment of source_release_data()
Expand Down
4 changes: 2 additions & 2 deletions src/include/sof/audio/src/src.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ struct polyphase_src {
struct src_stage_prm {
int nch;
int times;
void *x_rptr;
void *x_end_addr;
void const *x_rptr;
void const *x_end_addr;
size_t x_size;
void *y_wptr;
void *y_addr;
Expand Down

0 comments on commit fc29214

Please sign in to comment.