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 <[email protected]>
  • Loading branch information
marcinszkudlinski committed Sep 12, 2023
1 parent f114ace commit 6216746
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/audio/audio_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ static size_t audio_stream_get_data_available(struct sof_source *source)
}

static int audio_stream_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 audio_stream *audio_stream = container_of(source, struct audio_stream, source_api);
struct comp_buffer *buffer = container_of(audio_stream, struct comp_buffer, stream);
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 *source,
struct sof_sink *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 *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 *source)
}

int source_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)
{
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 *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 *source);
* @retval -ENODATA if req_size is bigger than available data
*/
int source_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);

/**
* 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 *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 6216746

Please sign in to comment.