-
Notifications
You must be signed in to change notification settings - Fork 356
module: waves: rework module to use sink/source api #10790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -753,28 +753,47 @@ static int waves_codec_init_process(struct processing_module *mod) | |
| return 0; | ||
| } | ||
|
|
||
| static int | ||
| waves_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 waves_codec_process(struct processing_module *mod, | ||
| struct sof_source **sources, int num_of_sources, | ||
| struct sof_sink **sinks, int num_of_sinks) | ||
| { | ||
| int ret; | ||
| struct comp_dev *dev = mod->dev; | ||
| struct module_data *codec = &mod->priv; | ||
| struct waves_codec_data *waves_codec = codec->private; | ||
| const void *src_ptr; | ||
| const void *src_buf_start; | ||
| size_t src_buf_size; | ||
| void *snk_ptr; | ||
| void *snk_buf_start; | ||
| size_t snk_buf_size; | ||
| size_t n_bytes = codec->mpd.in_buff_size; | ||
| size_t size_to_wrap; | ||
|
|
||
| /* 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) | ||
| waves_codec_init_process(mod); | ||
|
|
||
| memcpy_s(codec->mpd.in_buff, codec->mpd.in_buff_size, | ||
| input_buffers[0].data, codec->mpd.in_buff_size); | ||
| codec->mpd.avail = codec->mpd.in_buff_size; | ||
| ret = source_get_data(sources[0], n_bytes, &src_ptr, &src_buf_start, &src_buf_size); | ||
| if (ret) | ||
| return ret; | ||
|
|
||
| /* 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't fully understand why you didn’t use codec->mpd.in_buff_size as a destination size. I guess it would require another check due to the subtraction in the 2nd memcpy_s under "else"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } 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); | ||
| codec->mpd.avail = n_bytes; | ||
|
|
||
| comp_dbg(dev, "start"); | ||
|
|
||
|
|
@@ -812,12 +831,24 @@ waves_codec_process(struct processing_module *mod, | |
| codec->mpd.produced = waves_codec->o_stream.numAvailableSamples * | ||
| waves_codec->o_format.numChannels * waves_codec->sample_size_in_bytes; | ||
| codec->mpd.consumed = codec->mpd.produced; | ||
| input_buffers[0].consumed = codec->mpd.consumed; | ||
| ret = 0; | ||
| /* 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; | ||
| ret = sink_get_buffer(sinks[0], codec->mpd.produced, | ||
| &snk_ptr, &snk_buf_start, &snk_buf_size); | ||
| if (!ret) { | ||
| /* snk_buf_size is the total ring buffer size; handle wrap */ | ||
| size_to_wrap = (uint8_t *)snk_buf_start + snk_buf_size - | ||
| (uint8_t *)snk_ptr; | ||
| if (codec->mpd.produced <= size_to_wrap) { | ||
| memcpy_s(snk_ptr, codec->mpd.produced, | ||
| codec->mpd.out_buff, codec->mpd.produced); | ||
| } else { | ||
| memcpy_s(snk_ptr, codec->mpd.produced, | ||
| codec->mpd.out_buff, size_to_wrap); | ||
| memcpy_s(snk_buf_start, codec->mpd.produced - size_to_wrap, | ||
| (const uint8_t *)codec->mpd.out_buff + size_to_wrap, | ||
| codec->mpd.produced - size_to_wrap); | ||
| } | ||
| sink_commit_buffer(sinks[0], codec->mpd.produced); | ||
| } | ||
| } | ||
|
|
||
| if (ret) | ||
|
|
@@ -899,7 +930,7 @@ waves_codec_set_configuration(struct processing_module *mod, uint32_t config_id, | |
| static const struct module_interface waves_interface = { | ||
| .init = waves_codec_init, | ||
| .prepare = waves_codec_prepare, | ||
| .process_raw_data = waves_codec_process, | ||
| .process = waves_codec_process, | ||
| .set_configuration = waves_codec_set_configuration, | ||
| .reset = waves_codec_reset, | ||
| .free = waves_codec_free | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@softwarecki do we have an init check for this when buffers are setup ? Seems valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lgirdwood Number of sources and sinks is checked in
module_adapter_prepare(). It returns an error if any of these values is zero. Soprocess()cannot be called without at least one source and sink.sof/src/audio/module_adapter/module_adapter.c
Lines 488 to 515 in c351193