Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions src/audio/module_adapter/module/passthrough.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,38 +63,62 @@ static int passthrough_codec_init_process(struct processing_module *mod)
return 0;
}

static int
passthrough_codec_process(struct processing_module *mod,
struct input_stream_buffer *input_buffers, int num_input_buffers,
struct output_stream_buffer *output_buffers, int num_output_buffers)
static int passthrough_codec_process(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
const void *src_ptr, *src_buf_start;
void *snk_ptr, *snk_buf_start;
size_t src_buf_size, snk_buf_size;
size_t n_bytes = codec->mpd.in_buff_size;
size_t size_to_wrap;
int err;

comp_dbg(dev, "entry");

/* Proceed only if we have enough data to fill the module buffer completely */
if (input_buffers[0].size < codec->mpd.in_buff_size) {
if (source_get_data_available(sources[0]) < n_bytes) {
comp_dbg(dev, "not enough data to process");
return -ENODATA;
}

if (!codec->mpd.init_done)
passthrough_codec_init_process(mod);

memcpy_s(codec->mpd.in_buff, codec->mpd.in_buff_size,
input_buffers[0].data, codec->mpd.in_buff_size);

memcpy_s(codec->mpd.out_buff, codec->mpd.out_buff_size,
codec->mpd.in_buff, codec->mpd.in_buff_size);
codec->mpd.produced = mod->period_bytes;
codec->mpd.consumed = mod->period_bytes;
input_buffers[0].consumed = codec->mpd.consumed;

/* copy the produced samples into the output buffer */
memcpy_s(output_buffers[0].data, codec->mpd.produced, codec->mpd.out_buff,
codec->mpd.produced);
output_buffers[0].size = codec->mpd.produced;
err = source_get_data(sources[0], n_bytes, &src_ptr, &src_buf_start, &src_buf_size);
if (err)
return err;

/* src_buf_size is the total ring buffer size; handle wrap when copying to in_buff */
size_to_wrap = (const uint8_t *)src_buf_start + src_buf_size - (const uint8_t *)src_ptr;
if (n_bytes <= size_to_wrap) {
memcpy_s(codec->mpd.in_buff, n_bytes, src_ptr, n_bytes);
} else {
memcpy_s(codec->mpd.in_buff, n_bytes, src_ptr, size_to_wrap);
memcpy_s((uint8_t *)codec->mpd.in_buff + size_to_wrap, n_bytes - size_to_wrap,
src_buf_start, n_bytes - size_to_wrap);
}
source_release_data(sources[0], n_bytes);

memcpy_s(codec->mpd.out_buff, codec->mpd.out_buff_size, codec->mpd.in_buff, n_bytes);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are .in_buff and .out_buff temporary buffers? Looks like at least one of them could be eliminated, e.g. simply by removing this memcpy() and copying directly from .in_buff below. Maybe even both could be eliminated. But this doesn't have to be solved in this PR and maybe I'm mistaken entirely and those intermediate buffers have other roles too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a sample module, a template for future codecs. Instead of memcpy, somebody could simply insert own processing function. The waves module uses this template.


err = sink_get_buffer(sinks[0], n_bytes, &snk_ptr, &snk_buf_start, &snk_buf_size);
if (err)
return err;

/* snk_buf_size is the total ring buffer size; handle wrap when copying from out_buff */
size_to_wrap = (uint8_t *)snk_buf_start + snk_buf_size - (uint8_t *)snk_ptr;
if (n_bytes <= size_to_wrap) {
memcpy_s(snk_ptr, n_bytes, codec->mpd.out_buff, n_bytes);
} else {
memcpy_s(snk_ptr, n_bytes, codec->mpd.out_buff, size_to_wrap);
memcpy_s(snk_buf_start, n_bytes - size_to_wrap,
(const uint8_t *)codec->mpd.out_buff + size_to_wrap,
n_bytes - size_to_wrap);
}
sink_commit_buffer(sinks[0], n_bytes);

return 0;
}
Expand All @@ -121,7 +145,7 @@ static int passthrough_codec_free(struct processing_module *mod)
static const struct module_interface passthrough_interface = {
.init = passthrough_codec_init,
.prepare = passthrough_codec_prepare,
.process_raw_data = passthrough_codec_process,
.process = passthrough_codec_process,
.reset = passthrough_codec_reset,
.free = passthrough_codec_free
};
Expand Down
Loading