Skip to content

module: cadence: use the stream end from the host for end of stream - #11611

Open
ujfalusi wants to merge 1 commit into
thesofproject:mainfrom
ujfalusi:peter/pr/compr-drain
Open

ujfalusi wants to merge 1 commit into
thesofproject:mainfrom
ujfalusi:peter/pr/compr-drain

Conversation

@ujfalusi

@ujfalusi ujfalusi commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

The firmware cannot tell where the valid data ends in a compressed playback stream since the host DMA is free running around the buffer. The codec is fed with full input buffers and the end of stream is guessed from what follows the last valid byte: zeros if the stream fits into the buffer, stale data from the previous lap otherwise. With RAW AAC the stale data causes a fatal error and the drain never completes, with ADTS AAC the first frame which produces no output (oversized frame, resync) ends the stream early.

Add a generic stream control parameter for compress modules: the host sends struct module_param records with 0xffff in the upper 16 bits of the id. SOF_COMPR_CTRL_STREAM_END carries the absolute byte offset of the end of the stream (the size of the stream), sent by the host on drain.

In the Cadence module handle the stream controls without storing them as codec configuration and track the position in the input stream. When the stream end is known:

  • pass only the remaining bytes of the stream to the codec, the last input buffer can be partial
  • signal INPUT_OVER only when the last byte of the stream is passed
  • finish when the codec reports done or when the whole stream is consumed and no more output is produced

Without the stream end the existing behavior is kept.

The firmware cannot tell where the valid data ends in a compressed
playback stream since the host DMA is free running around the buffer.
The codec is fed with full input buffers and the end of stream is
guessed from what follows the last valid byte: zeros if the stream fits
into the buffer, stale data from the previous lap otherwise.
With RAW AAC the stale data causes a fatal error and the drain never
completes, with ADTS AAC the first frame which produces no output
(oversized frame, resync) ends the stream early.

Add a generic stream control parameter for compress modules: the host
sends struct module_param records with 0xffff in the upper 16 bits of
the id. SOF_COMPR_CTRL_STREAM_END carries the absolute byte offset of
the end of the stream (the size of the stream), sent by the host on
drain.

In the Cadence module handle the stream controls without storing them
as codec configuration and track the position in the input stream.
When the stream end is known:
- pass only the remaining bytes of the stream to the codec, the last
  input buffer can be partial
- signal INPUT_OVER only when the last byte of the stream is passed
- finish when the codec reports done or when the whole stream is
  consumed and no more output is produced

Without the stream end the existing behavior is kept.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.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.

🟡 Changes recommended

SOF_COMPR_CTRL_ID is expected to produce the host control ID 0xffff0001, but shifting signed 0xffff left by 16 produces a value not representable in a 32-bit signed int, invoking undefined behavior.

1 open issue
What changed in this PR

Updates SOF’s Cadence codec integration to use host-provided stream boundaries, avoiding drain failures and premature completion caused by padding or stale data.

Changes:

  • Adds generic compressed-stream control parameters.
  • Tracks input position and limits codec input to valid stream bytes.
  • Uses the known boundary for end-of-stream handling while preserving legacy behavior when unavailable.
File Description
src/​include/​sof/​audio/​module_adapter/​module/​compress_ctrl.h Defines stream-control IDs and helpers.
src/​include/​sof/​audio/​module_adapter/​module/​cadence.h Adds stream-position and end-offset state.
src/​audio/​module_adapter/​module/​cadence.c Updates input-over signaling and completion detection.
src/​audio/​module_adapter/​module/​cadence_ipc4.c Handles controls, bounds input, tracks consumption, and resets stream state.

Review effort: Balanced

/* Absolute byte offset of the end of the stream (stream size), payload: uint64_t */
#define SOF_COMPR_CTRL_STREAM_END 1

#define SOF_COMPR_CTRL_PARAM_ID(ctrl) ((SOF_COMPR_CTRL_ID << 16) | (ctrl))
@intel-sofci

Copy link
Copy Markdown

PR 11611: test results

Run date: 2026-12-03 19:38 UTC

Tested commit: e82ced73a15aa312089824a1a6c8d97eba67c212

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

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.

3 participants