Skip to content

Commit

Permalink
use of API with defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinszkudlinski committed Oct 16, 2024
1 parent aff0ac6 commit 33bc512
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 88 deletions.
57 changes: 14 additions & 43 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,6 @@ static int comp_buffer_release_data(struct sof_source *source, size_t free_size)
return 0;
}

static int comp_buffer_set_ipc_params_source(struct sof_source *source,
struct sof_ipc_stream_params *params,
bool force_update)
{
struct comp_buffer *buffer = comp_buffer_get_from_source(source);

return buffer_set_params(buffer, params, force_update);
}

static int comp_buffer_source_format_set(struct sof_source *source)
{
struct comp_buffer *buffer = comp_buffer_get_from_source(source);

audio_stream_recalc_align(&buffer->stream);
return 0;
}

static int comp_buffer_source_set_alignment_constants(struct sof_source *source,
const uint32_t byte_align,
const uint32_t frame_align_req)
{
struct comp_buffer *buffer = comp_buffer_get_from_source(source);

audio_stream_set_align(byte_align, frame_align_req, &buffer->stream);
return 0;
}

static size_t comp_buffer_get_free_size(struct sof_sink *sink)
{
struct comp_buffer *buffer = comp_buffer_get_from_sink(sink);
Expand Down Expand Up @@ -125,28 +98,29 @@ static int comp_buffer_commit_buffer(struct sof_sink *sink, size_t commit_size)
return 0;
}

static int comp_buffer_set_ipc_params_sink(struct sof_sink *sink,
struct sof_ipc_stream_params *params,
bool force_update)
static int comp_buffer_set_ipc_params(struct sof_audio_buffer *audio_buffer,
struct sof_ipc_stream_params *params,
bool force_update)
{
struct comp_buffer *buffer = comp_buffer_get_from_sink(sink);
struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer);

return buffer_set_params(buffer, params, force_update);
return 0;
}

static int comp_buffer_sink_format_set(struct sof_sink *sink)
static int comp_buffer_format_set(struct sof_audio_buffer *audio_buffer)
{
struct comp_buffer *buffer = comp_buffer_get_from_sink(sink);
struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer);

audio_stream_recalc_align(&buffer->stream);
return 0;
}

static int comp_buffer_sink_set_alignment_constants(struct sof_sink *sink,
const uint32_t byte_align,
const uint32_t frame_align_req)
static int comp_buffer_set_alignment_constants(struct sof_audio_buffer *audio_buffer,
const uint32_t byte_align,
const uint32_t frame_align_req)
{
struct comp_buffer *buffer = comp_buffer_get_from_sink(sink);
struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer);

audio_stream_set_align(byte_align, frame_align_req, &buffer->stream);
return 0;
Expand Down Expand Up @@ -194,23 +168,20 @@ static struct source_ops comp_buffer_source_ops = {
.get_data_available = comp_buffer_get_data_available,
.get_data = comp_buffer_get_data,
.release_data = comp_buffer_release_data,
.audio_set_ipc_params = comp_buffer_set_ipc_params_source,
.on_audio_format_set = comp_buffer_source_format_set,
.set_alignment_constants = comp_buffer_source_set_alignment_constants
};

static struct sink_ops comp_buffer_sink_ops = {
.get_free_size = comp_buffer_get_free_size,
.get_buffer = comp_buffer_get_buffer,
.commit_buffer = comp_buffer_commit_buffer,
.audio_set_ipc_params = comp_buffer_set_ipc_params_sink,
.on_audio_format_set = comp_buffer_sink_format_set,
.set_alignment_constants = comp_buffer_sink_set_alignment_constants
};

static const struct audio_buffer_ops audio_buffer_ops = {
.free = comp_buffer_free,
.clean = comp_buffer_clean,
.audio_set_ipc_params = comp_buffer_set_ipc_params,
.on_audio_format_set = comp_buffer_format_set,
.set_alignment_constants = comp_buffer_set_alignment_constants
};

static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size, uint32_t caps,
Expand Down
46 changes: 1 addition & 45 deletions src/audio/buffers/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,65 +242,21 @@ static int ring_buffer_release_data(struct sof_source *source, size_t free_size)
return 0;
}

static int ring_buffer_set_ipc_params(struct ring_buffer *ring_buffer,
struct sof_ipc_stream_params *params,
bool force_update)
{
CORE_CHECK_STRUCT(&ring_buffer->audio_buffer);

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

struct sof_audio_stream_params *audio_stream_params =
audio_buffer_get_stream_params(&ring_buffer->audio_buffer);

audio_stream_params->frame_fmt = params->frame_fmt;
audio_stream_params->rate = params->rate;
audio_stream_params->channels = params->channels;
audio_stream_params->buffer_fmt = params->buffer_fmt;

audio_buffer_set_hw_params_configured(&ring_buffer->audio_buffer);

return 0;
}

static int ring_buffer_set_ipc_params_source(struct sof_source *source,
struct sof_ipc_stream_params *params,
bool force_update)
{
struct ring_buffer *ring_buffer = ring_buffer_from_source(source);

CORE_CHECK_STRUCT(&ring_buffer->audio_buffer);
return ring_buffer_set_ipc_params(ring_buffer, params, force_update);
}

static int ring_buffer_set_ipc_params_sink(struct sof_sink *sink,
struct sof_ipc_stream_params *params,
bool force_update)
{
struct ring_buffer *ring_buffer = ring_buffer_from_sink(sink);

CORE_CHECK_STRUCT(&ring_buffer->audio_buffer);
return ring_buffer_set_ipc_params(ring_buffer, params, force_update);
}

static struct source_ops ring_buffer_source_ops = {
.get_data_available = ring_buffer_get_data_available,
.get_data = ring_buffer_get_data,
.release_data = ring_buffer_release_data,
.audio_set_ipc_params = ring_buffer_set_ipc_params_source,
};

static struct sink_ops ring_buffer_sink_ops = {
.get_free_size = ring_buffer_get_free_size,
.get_buffer = ring_buffer_get_buffer,
.commit_buffer = ring_buffer_commit_buffer,
.audio_set_ipc_params = ring_buffer_set_ipc_params_sink,
};

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

struct ring_buffer *ring_buffer_create(size_t min_available, size_t min_free_space, bool is_shared,
Expand Down

0 comments on commit 33bc512

Please sign in to comment.