Repository navigation
Conversation
The host DMA of a compressed playback stream is free running around the ring buffer, the firmware reads past the last valid byte until the decoder detects the end of the stream. When the stream fits into the buffer the data after the end is zero and the decoders can detect the end of stream reliably, but after the first wrap the free part of the buffer contains stale data from the previous lap, which the decoders try to decode. This can cause the stream to never end (RAW AAC) or to decode stale data. Clear the free part of the buffer on drain, from the application write position up to the DSP read position, so the end of the stream is always followed by zeros, like for streams that never wrapped the buffer. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
ujfalusi
requested review from
bardliao,
dbaluta,
kv2019i,
lgirdwood,
plbossart and
ranj063
as code owners
December 3, 2026 13:41
There was a problem hiding this comment.
🟡 Changes recommended
The drain path uses a stale playback count and can permanently skip clearing freed buffer space, allowing wrapped streams to decode stale data or hang during draining.
1 open issue
What changed in this PR
This PR aims to prevent stale audio data from disrupting end-of-stream detection in SOF IPC4 compressed playback.
Changes:
- Adds a helper to zero unused ring-buffer space, including wrapped regions.
- Calls the helper when a playback stream drains.
| File | Description |
|---|---|
| sound/soc/sof/ipc4-compress.c | Adds ring-buffer clearing during drain to remove stale playback data. |
Review effort: Balanced
Comment on lines
+579
to
+581
| pending = crtd->total_bytes_available - crtd->total_bytes_transferred; | ||
| if (pending >= crtd->buffer_size) | ||
| return; |
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 decoders rely on what follows the last valid byte, which is not reliable, for example the Cadence AAC decoder needs a full input buffer and cannot signal the end of stream on its own. Send the end of the stream (the absolute byte offset of the end, which is the size of the stream) to the decoder module on drain, so it can feed the codec with the exact amount of remaining data and finish decoding at the real end of the stream. The parameter is sent as a struct module_param record with 0xffff in the upper 16 bits of the id, which no codec specific parameter uses, so firmware without support for it skips the parameter. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Comment on lines
+584
to
+586
| pending = crtd->total_bytes_available - crtd->total_bytes_transferred; | ||
| if (pending >= crtd->buffer_size) | ||
| return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The host DMA of a compressed playback stream is free running around the
ring buffer, so after the last valid byte the firmware keeps reading
whatever is left in the buffer until the decoder detects the end of the
stream. As long as the stream fits into the buffer the data after the end
is zero, but once the buffer has wrapped it is stale data from the
previous lap, and the decoders try to decode it. This shows up as:
completes and the application hangs
old data
The two patches:
position up to the DSP read position. The end of the stream is then
always followed by zeros, as for streams that never wrapped the buffer.
This needs no firmware change and fixes the RAW AAC hang with existing
firmware.
is the size of the stream) to the decoder module on drain, as a
struct module_paramrecord with0xffffin the upper 16 bits of theid. A decoder that supports it can feed the codec with the exact amount
of remaining data and finish at the real end of the stream, instead of
guessing from what follows it. Firmware without support skips the
record (no IPC error); the zeroing from patch 1 remains the fallback.
Firmware support for the stream end control in the Cadence module:
thesofproject/sof#11611
Tested on PTL (SoundWire, compress playback) with the existing firmware
and with the firmware supporting the stream end:
buffer and that wrap it (90 s, 285 s)
All streams play to their real end and the drain completes.