Skip to content

P20 selector - convert the selector module to only use the sink/source - #11243

Open
piotrhoppeintel wants to merge 3 commits into
thesofproject:mainfrom
piotrhoppeintel:p20-selector
Open

piotrhoppeintel wants to merge 3 commits into
thesofproject:mainfrom
piotrhoppeintel:p20-selector

Conversation

@piotrhoppeintel

Copy link
Copy Markdown
Contributor

Rework the selector module to only use the sink/source api to
prepare the SOF for the full transition to pipeline 2.0.

Add release_source_and_commit_sink() to release processed source
data and commit produced data to the sink. Always commit the sink,
while preserving the source release error when both operations fail.

Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

A critical zero-frame handling issue and documentation mismatches remain unresolved.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Migrates the selector module to sink/source APIs for Pipeline 2.0 compatibility.

Changes:

  • Updates selector callbacks and generic processing.
  • Adds shared source-release/sink-commit utilities.
  • Adapts selector tests to the new interfaces.
File Summary
test/​cmocka/​src/​audio/​selector/​selector_test.c Updated selector tests for sink/source APIs.
src/​include/​sof/​audio/​sink_source_utils.h Declares the shared utility.
src/​include/​sof/​audio/​selector.h Updates selector callback signatures.
src/​audio/​sink_source_utils.c Implements source-release and sink-commit handling.
src/​audio/​selector/​selector.c Migrates processing; zero-frame handling requires correction.
src/​audio/​selector/​selector_generic.c Updates processing implementations; Doxygen parameter names need correction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/audio/selector/selector.c
@lgirdwood

Copy link
Copy Markdown
Member

@piotrhoppeintel 1 CI failure to check.

int sink_ret;

src_ret = source_release_data(source, free_size);
sink_ret = sink_commit_buffer(sink, (src_ret ? 0 : commit_size));

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.

superfluous internal parentheses

#include <limits.h>

int release_source_and_commit_sink(struct sof_source *source, size_t free_size,
struct sof_sink *sink, size_t commit_size)

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.

I'm wondering if it's small enough to be an inline?

const unsigned int nch = source_get_channels(source);
const int16_t *src, *src_start, *src_ch;
int16_t *dst, *dst_start;
int src_samples, dst_samples;

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.

I think @softwarecki defines these as size_t too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but in this case, src_samples and dst_samples are passed as parameters to the source_get_data_s16() and sink_get_buffer_s16() functions, and they require an int type.

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.

Pending PR #11193

Comment thread src/audio/selector/selector_generic.c Outdated
src = audio_stream_wrap(source, src + b);
dst = audio_stream_wrap(sink, dst + b);
bytes_copied += b;
const int frame_bytes = source_get_frame_bytes(source);

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.

size_t? Would be good to define and document at least recommended common types for all of these...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Changed the type to size_t.

cd->sel_func(sel_state->dev, &sel_state->sink->stream, &sel_state->source->stream,
sel_state->dev->frames);
ret = cd->sel_func(sel_state->dev, sink, source, sel_state->dev->frames);
assert_int_equal(ret, 0);

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.

would this test be broken after the previous commit? Maybe these commits need to be merged then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a new case where 0 should be returned when no frames are being processed. It is related to the changes requested by Copilot.

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.

@piotrhoppeintel sorry, this was a comment to the entire commit, not that hunk specifically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Specifically, the changes are mainly required by the different change types, and 'source/since' comes from buffers. The 'input_stream_buffer' and 'output_stream_buffer' wrappers are no longer used, as noted above. There were no test failures; these changes are purely technical.

Rework selector processing to use the sink/source API instead
of direct audio stream access, preparing the module for the
pipeline 2.0 transition.

Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>
Update the selector unit test to pass sof_source and sof_sink
objects to the processing functions. Remove obsolete stream buffer
wrappers and verify the processing return value.

Signed-off-by: Piotr Hoppe <piotr.hoppe@intel.com>

@softwarecki softwarecki left a comment

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.

Wouldn't it be cleaner to get the buffers once in selector_process() and pass circ_buf_source/circ_buf_sink structures to the individual processing variants? That would avoid duplicating the buffer acquisition code in each processing function.

int sink_frame_bytes = audio_stream_frame_bytes(sink);
int n_chan_source = MIN(SEL_SOURCE_CHANNELS_MAX, audio_stream_get_channels(source));
int n_chan_sink = MIN(SEL_SINK_CHANNELS_MAX, audio_stream_get_channels(sink));
const int n_chan_source = MIN(SEL_SOURCE_CHANNELS_MAX, (int)source_get_channels(source));

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.

unsigned int

int n_chan_sink = MIN(SEL_SINK_CHANNELS_MAX, audio_stream_get_channels(sink));
const int n_chan_source = MIN(SEL_SOURCE_CHANNELS_MAX, (int)source_get_channels(source));
const int n_chan_sink = MIN(SEL_SINK_CHANNELS_MAX, (int)sink_get_channels(sink));
const int source_frame_bytes = source_get_frame_bytes(source);

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.

size_t

int n_chan_source = MIN(SEL_SOURCE_CHANNELS_MAX, audio_stream_get_channels(source));
int n_chan_sink = MIN(SEL_SINK_CHANNELS_MAX, audio_stream_get_channels(sink));
const int n_chan_source = MIN(SEL_SOURCE_CHANNELS_MAX, (int)source_get_channels(source));
const int n_chan_sink = MIN(SEL_SINK_CHANNELS_MAX, (int)sink_get_channels(sink));

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.

unsigned int

const int n_chan_source = MIN(SEL_SOURCE_CHANNELS_MAX, (int)source_get_channels(source));
const int n_chan_sink = MIN(SEL_SINK_CHANNELS_MAX, (int)sink_get_channels(sink));
const int source_frame_bytes = source_get_frame_bytes(source);
const unsigned int src_channels = source_get_channels(source);

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.

Move above n_chan_source and use this value to calculate it.

const int source_frame_bytes = source_get_frame_bytes(source);
const unsigned int src_channels = source_get_channels(source);
const unsigned int dst_channels = sink_get_channels(sink);
const int sink_frame_bytes = sink_get_frame_bytes(sink);

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.

size_t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants