Skip to content

Commit

Permalink
module: sink: source: Move sink/source api headers to module
Browse files Browse the repository at this point in the history
Moved header files to the module directory to separate an shared interface
used by sof and native loadable modules.

Signed-off-by: Adrian Warecki <[email protected]>
  • Loading branch information
softwarecki authored and lgirdwood committed Nov 24, 2023
1 parent 60e9924 commit f21670b
Show file tree
Hide file tree
Showing 26 changed files with 742 additions and 690 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ add_subdirectory(ipc)
add_subdirectory(audio)
add_subdirectory(lib)
add_subdirectory(math)
add_subdirectory(module)

if(CONFIG_SAMPLES)
add_subdirectory(samples)
endif()
Expand Down
167 changes: 5 additions & 162 deletions src/audio/sink_api_helper.c
Original file line number Diff line number Diff line change
@@ -1,61 +1,20 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2023 Intel Corporation. All rights reserved.
//
/*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*/

#include <sof/audio/sink_api.h>
#include <sof/audio/sink_api_implementation.h>
#include <sof/audio/audio_stream.h>

/* This file contains private sink API functions intended for use only by the sof. */

void sink_init(struct sof_sink *sink, const struct sink_ops *ops,
struct sof_audio_stream_params *audio_stream_params)
{
sink->ops = ops;
sink->audio_stream_params = audio_stream_params;
}

size_t sink_get_free_size(struct sof_sink *sink)
{
return sink->ops->get_free_size(sink);
}

int sink_get_buffer(struct sof_sink *sink, size_t req_size,
void **data_ptr, void **buffer_start, size_t *buffer_size)
{
int ret;

if (sink->requested_write_frag_size)
return -EBUSY;

ret = sink->ops->get_buffer(sink, req_size, data_ptr,
buffer_start, buffer_size);

if (!ret)
sink->requested_write_frag_size = req_size;
return ret;
}

int sink_commit_buffer(struct sof_sink *sink, size_t commit_size)
{
int ret;

/* check if there was a buffer obtained for writing by sink_get_buffer */
if (!sink->requested_write_frag_size)
return -ENODATA;

/* limit size of data to be committed to previously obtained size */
if (commit_size > sink->requested_write_frag_size)
commit_size = sink->requested_write_frag_size;

ret = sink->ops->commit_buffer(sink, commit_size);

if (!ret)
sink->requested_write_frag_size = 0;

sink->num_of_bytes_processed += commit_size;
return ret;
}

size_t sink_get_num_of_processed_bytes(struct sof_sink *sink)
{
return sink->num_of_bytes_processed;
Expand All @@ -66,128 +25,12 @@ void sink_reset_num_of_processed_bytes(struct sof_sink *sink)
sink->num_of_bytes_processed = 0;
}

enum sof_ipc_frame sink_get_frm_fmt(struct sof_sink *sink)
{
return sink->audio_stream_params->frame_fmt;
}

enum sof_ipc_frame sink_get_valid_fmt(struct sof_sink *sink)
{
return sink->audio_stream_params->valid_sample_fmt;
}

uint32_t sink_get_rate(struct sof_sink *sink)
{
return sink->audio_stream_params->rate;
}

uint32_t sink_get_channels(struct sof_sink *sink)
{
return sink->audio_stream_params->channels;
}

uint32_t sink_get_buffer_fmt(struct sof_sink *sink)
{
return sink->audio_stream_params->buffer_fmt;
}

bool sink_get_overrun(struct sof_sink *sink)
{
return sink->audio_stream_params->overrun_permitted;
}

int sink_set_frm_fmt(struct sof_sink *sink, enum sof_ipc_frame frame_fmt)
{
sink->audio_stream_params->frame_fmt = frame_fmt;

/* notify the implementation */
if (sink->ops->on_audio_format_set)
return sink->ops->on_audio_format_set(sink);
return 0;
}

int sink_set_valid_fmt(struct sof_sink *sink,
enum sof_ipc_frame valid_sample_fmt)
{
sink->audio_stream_params->valid_sample_fmt = valid_sample_fmt;
if (sink->ops->on_audio_format_set)
return sink->ops->on_audio_format_set(sink);
return 0;
}

int sink_set_rate(struct sof_sink *sink, unsigned int rate)
{
sink->audio_stream_params->rate = rate;
if (sink->ops->on_audio_format_set)
return sink->ops->on_audio_format_set(sink);
return 0;
}

int sink_set_channels(struct sof_sink *sink, unsigned int channels)
{
sink->audio_stream_params->channels = channels;
if (sink->ops->on_audio_format_set)
return sink->ops->on_audio_format_set(sink);
return 0;
}

int sink_set_buffer_fmt(struct sof_sink *sink, uint32_t buffer_fmt)
{
sink->audio_stream_params->buffer_fmt = buffer_fmt;
if (sink->ops->on_audio_format_set)
return sink->ops->on_audio_format_set(sink);
return 0;
}

int sink_set_overrun(struct sof_sink *sink, bool overrun_permitted)
{
sink->audio_stream_params->overrun_permitted = overrun_permitted;
if (sink->ops->on_audio_format_set)
return sink->ops->on_audio_format_set(sink);
return 0;
}

size_t sink_get_frame_bytes(struct sof_sink *sink)
{
return get_frame_bytes(sink_get_frm_fmt(sink),
sink_get_channels(sink));
}

size_t sink_get_free_frames(struct sof_sink *sink)
{
return sink_get_free_size(sink) /
sink_get_frame_bytes(sink);
}

int sink_set_params(struct sof_sink *sink,
struct sof_ipc_stream_params *params, bool force_update)
{
if (sink->ops->audio_set_ipc_params)
return sink->ops->audio_set_ipc_params(sink, params, force_update);
return 0;
}

int sink_set_alignment_constants(struct sof_sink *sink,
const uint32_t byte_align,
const uint32_t frame_align_req)
{
if (sink->ops->set_alignment_constants)
return sink->ops->set_alignment_constants(sink, byte_align, frame_align_req);
return 0;
}

void sink_set_min_free_space(struct sof_sink *sink, size_t min_free_space)
{
sink->min_free_space = min_free_space;
}

size_t sink_get_min_free_space(struct sof_sink *sink)
{
return sink->min_free_space;
}

uint32_t sink_get_id(struct sof_sink *sink)
{
return sink->audio_stream_params->id;
}

97 changes: 5 additions & 92 deletions src/audio/source_api_helper.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2023 Intel Corporation. All rights reserved.
//
/*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*/

#include <sof/audio/source_api.h>
#include <sof/audio/source_api_implementation.h>
#include <sof/audio/audio_stream.h>

/* This file contains private source API functions intended for use only by the sof. */

void source_init(struct sof_source *source, const struct source_ops *ops,
struct sof_audio_stream_params *audio_stream_params)
{
Expand All @@ -15,47 +16,6 @@ void source_init(struct sof_source *source, const struct source_ops *ops,
source->audio_stream_params = audio_stream_params;
}

size_t source_get_data_available(struct sof_source *source)
{
return source->ops->get_data_available(source);
}

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

if (source->requested_read_frag_size)
return -EBUSY;

ret = source->ops->get_data(source, req_size, data_ptr, buffer_start, buffer_size);

if (!ret)
source->requested_read_frag_size = req_size;
return ret;
}

int source_release_data(struct sof_source *source, size_t free_size)
{
int ret;

/* Check if anything was obtained before for reading by source_get_data */
if (!source->requested_read_frag_size)
return -ENODATA;

/* limit size of data to be freed to previously obtained size */
if (free_size > source->requested_read_frag_size)
free_size = source->requested_read_frag_size;

ret = source->ops->release_data(source, free_size);

if (!ret)
source->requested_read_frag_size = 0;

source->num_of_bytes_processed += free_size;
return ret;
}

size_t source_get_num_of_processed_bytes(struct sof_source *source)
{
return source->num_of_bytes_processed;
Expand All @@ -66,31 +26,6 @@ void source_reset_num_of_processed_bytes(struct sof_source *source)
source->num_of_bytes_processed = 0;
}

enum sof_ipc_frame source_get_frm_fmt(struct sof_source *source)
{
return source->audio_stream_params->frame_fmt;
}

enum sof_ipc_frame source_get_valid_fmt(struct sof_source *source)
{
return source->audio_stream_params->valid_sample_fmt;
}

unsigned int source_get_rate(struct sof_source *source)
{
return source->audio_stream_params->rate;
}

unsigned int source_get_channels(struct sof_source *source)
{
return source->audio_stream_params->channels;
}

uint32_t source_get_buffer_fmt(struct sof_source *source)
{
return source->audio_stream_params->buffer_fmt;
}

bool source_get_underrun(struct sof_source *source)
{
return source->audio_stream_params->underrun_permitted;
Expand Down Expand Up @@ -145,18 +80,6 @@ int source_set_underrun(struct sof_source *source, bool underrun_permitted)
return 0;
}

size_t source_get_frame_bytes(struct sof_source *source)
{
return get_frame_bytes(source_get_frm_fmt(source),
source_get_channels(source));
}

size_t source_get_data_frames_available(struct sof_source *source)
{
return source_get_data_available(source) /
source_get_frame_bytes(source);
}

int source_set_params(struct sof_source *source,
struct sof_ipc_stream_params *params, bool force_update)
{
Expand All @@ -178,13 +101,3 @@ void source_set_min_available(struct sof_source *source, size_t min_available)
{
source->min_available = min_available;
}

size_t source_get_min_available(struct sof_source *source)
{
return source->min_available;
}

uint32_t source_get_id(struct sof_source *source)
{
return source->audio_stream_params->id;
}
Loading

0 comments on commit f21670b

Please sign in to comment.