module: waves: rework module to use sink/source api#10790
Conversation
There was a problem hiding this comment.
Pull request overview
Reworks the WAVES module adapter processing path to use the sink/source API (ring-buffer based) instead of the legacy raw input/output buffer API, aligning the module with the pipeline 2.0 transition.
Changes:
- Switch
waves_codec_process()to the sink/sourceprocesscallback signature. - Read input via
source_get_data()(with wrap handling) into the module’s internal input buffer. - Write output via
sink_get_buffer()+sink_commit_buffer()(with wrap handling) from the module’s internal output buffer.
Comments suppressed due to low confidence (3)
src/audio/module_adapter/module/waves/waves.c:766
source_get_data()expectsvoid const **buffer_start, butsrc_buf_startis declared asvoid *and passed by address, which is an incompatible pointer type and can trigger build warnings/errors. Declaresrc_buf_startasconst void *(oruint8_t const *) and keep the pointer types consistent withsource_api.h.
const void *src_ptr;
void *src_buf_start;
size_t src_buf_size;
src/audio/module_adapter/module/waves/waves.c:796
- Input is released from the source (
source_release_data(..., n_bytes)) immediately after copying, beforeMaxxEffect_Process()and before ensuring the output can be written. If processing fails orsink_get_buffer()returns an error, the input has already been consumed and will be lost (previous legacy path keptconsumed=0on errors). Delay releasing the source until after successful processing/output commit, and on failure paths release 0 bytes to drop the reservation without consuming.
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);
} 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;
src/audio/module_adapter/module/waves/waves.c:836
- There is no check that the sink has enough free space before running the effect, and
sink_get_buffer()errors are handled after the input has already been released. If the sink is full, this can cause dropped samples or re-processing on retry (depending on how source release is fixed). Add an earlysink_get_free_size()check (e.g., againstcodec->mpd.out_buff_size/expected produced bytes) and return-ENOSPCwithout consuming input when there isn’t enough space.
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;
ret = sink_get_buffer(sinks[0], codec->mpd.produced,
&snk_ptr, &snk_buf_start, &snk_buf_size);
if (!ret) {
| 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) |
There was a problem hiding this comment.
@softwarecki do we have an init check for this when buffers are setup ? Seems valid.
There was a problem hiding this comment.
@lgirdwood Number of sources and sinks is checked in module_adapter_prepare(). It returns an error if any of these values is zero. So process() cannot be called without at least one source and sink.
sof/src/audio/module_adapter/module_adapter.c
Lines 488 to 515 in c351193
Rework the waves module to only use the sink/source api to prepare sof for the full transition to pipeline 2.0. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
| /* 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); |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
size_t n_bytes = codec->mpd.in_buff_size; at line 770.
kv2019i
left a comment
There was a problem hiding this comment.
A couple of smaller notes, see comments inline.
| 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); |
There was a problem hiding this comment.
This is a slight change in function. source_release_data() consumes the data before call to MaxxEffect_Process(). If process fails, it's not possibly to retry. The old raw-buffer path seemed to handle this case.
There was a problem hiding this comment.
Also, should the consumed amount be set based on how much was actually consumed by process (like done in old code)?
Rework the waves module to only use the sink/source api to prepare sof for the full transition to pipeline 2.0.