Skip to content

ffmpeg_dec: decode pipeline, platform, topology fixups and test tooling - #11390

Draft
lgirdwood wants to merge 7 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-decode-fixes
Draft

lgirdwood wants to merge 7 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-decode-fixes

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

This series contains the remaining core, topology, and tooling updates for ffmpeg_dec compressed audio decode support on top of the merged ffmpeg_dec integration (#11284 / #11343):

  1. audio: src: align the SRC delay line allocation to SOF_FRAME_BYTE_ALIGN
    • Use mod_alloc_align(..., SOF_FRAME_BYTE_ALIGN) for cd->delay_lines so SIMD circular buffer accesses in the SRC filter do not fault when ffmpeg_dec is paired with an SRC stage.
  2. platform: cavs: initialize DP scheduler on primary core
    • Call scheduler_dp_init() unconditionally during platform_init() on CAVS/ACE platforms when CONFIG_SOF_USERSPACE_APPLICATION=y so DP modules (such as ffmpeg_dec) can be scheduled on core 0 as well as secondary cores.
  3. topology2: compr-ffmpeg: use COMPR_DECODER_CORE_ID and add Opus target
    • Parameterize the ffmpeg_dec pipeline and component core_id via COMPR_DECODER_CORE_ID, size COMPR_FFMPEG_DEC_HEAP to 256 KiB to cover the 64 KiB PCM staging buffer and decoder working set, and add the sof-hda-generic-ffmpeg-opus-compr build target.
  4. topology2: add ffmpeg_dec benchmark test topology
    • Add the playback benchmark topology (ffmpeg_dec32, HDA and SoundWire) with DP scheduling and decoder stack/heap budgets for ffmpeg_dec.
  5. tools: test: add ffmpeg_dec FLAC test vector generator script
    • Add tools/test/audio/ffmpeg_dec_prepare.sh referenced by src/audio/ffmpeg_dec/TESTING.md to generate raw FLAC frames, 34-byte STREAMINFO extradata, and reference S32_LE PCM vectors.
  6. audio: host: align remaining compress drain bytes to dma_copy_align
    • Round the remaining committed compress drain byte count in host_get_copy_bytes_normal() up to MAX(dma_sample_bytes, hd->dma_copy_align) for the DMA transfer/reload, and clamp the bytes copied into the downstream sink in host_common_update() to the actual payload remainder (consuming any trailing DMA padding from the source DMA buffer).
  7. audio: ffmpeg_dec: strip container header before lazy backend configure
    • Embed extradata inline in struct ffmpeg_dec_comp_data (avoiding mod_alloc() on the user-mode DP thread) and strip the container header before lazy backend configuration so stream-embedded setup headers (such as FLAC STREAMINFO) are extracted before avcodec_open2().

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

Decoder heap undersizing, excess DMA bytes published downstream, and backend initialization on the shared LL thread risk allocation failures, payload corruption, and audio stalls; benchmark routing and SoundWire integration are also incomplete.

5 open issues
What changed in this PR

This PR updates SOF’s ffmpeg_dec runtime integration, topology configuration, and test tooling for compressed audio decoding.

Changes:

  • Adjusts SRC allocation alignment, primary-core DP scheduler initialization, and compressed-stream drain alignment.
  • Stores codec extradata inline and extracts container headers before lazy backend configuration.
  • Parameterizes decoder core selection, adds an Opus target and benchmark fragments, and provides FLAC test-vector preparation.
File Description
tools/​topology/​topology2/​platform/​intel/​compr-ffmpeg.conf Uses configurable decoder core selection.
tools/​topology/​topology2/​platform/​intel/​compr-default.conf Updates comments to cover both decoder implementations.
tools/​topology/​topology2/​include/​bench/​ffmpeg_dec_s32.conf Adds S32 decoder benchmark instances.
tools/​topology/​topology2/​include/​bench/​ffmpeg_dec_s24.conf Adds S24 decoder benchmark instances.
tools/​topology/​topology2/​include/​bench/​ffmpeg_dec_s16.conf Adds S16 decoder benchmark instances.
tools/​topology/​topology2/​include/​bench/​ffmpeg_dec_route.conf Adds playback and capture benchmark routes.
tools/​topology/​topology2/​include/​bench/​ffmpeg_dec_controls_playback.conf Adds commented playback control placeholders.
tools/​topology/​topology2/​include/​bench/​ffmpeg_dec_controls_capture.conf Adds commented capture control placeholders.
tools/​topology/​topology2/​development/​tplg-targets.cmake Registers the FFmpeg Opus compressed-playback target.
tools/​topology/​topology2/​development/​tplg-targets-bench.cmake Adds FFmpeg to S32 benchmark target generation.
tools/​topology/​topology2/​cavs-benchmark-hda.conf Includes the decoder class and S32 benchmark selection.
tools/​test/​audio/​ffmpeg_dec_prepare.sh Generates FLAC data, STREAMINFO, and reference PCM.
src/​platform/​intel/​cavs/​platform.c Initializes the enabled DP scheduler during platform startup.
src/​audio/​src/​src_common.c Requests eight-byte alignment for SRC delay lines.
src/​audio/​host-zephyr.c Rounds drain remainder to DMA copy alignment.
src/​audio/​ffmpeg_dec/​ffmpeg_dec.h Replaces the extradata pointer with inline storage.
src/​audio/​ffmpeg_dec/​ffmpeg_dec.c Updates extradata handling and strips headers before backend configuration.

Review effort: Balanced

Comment thread src/audio/host-zephyr.c
(uint64_t)hd->dma_copy_align);

remaining = ALIGN_UP(remaining, (uint64_t)dma_sample_bytes);
remaining = ALIGN_UP(remaining, align);
"sof-hda-generic\;sof-hda-generic-ffmpeg-compr\;HDA_CONFIG=mix,COMPR_FFMPEG=true"
"sof-hda-generic\;sof-hda-generic-ffmpeg-mp3-compr\;HDA_CONFIG=mix,COMPR_FFMPEG=true,COMPR_FFMPEG_CODEC=mp3"
"sof-hda-generic\;sof-hda-generic-ffmpeg-aac-compr\;HDA_CONFIG=mix,COMPR_FFMPEG=true,COMPR_FFMPEG_CODEC=aac,COMPR_FFMPEG_DEC_HEAP=901120"
"sof-hda-generic\;sof-hda-generic-ffmpeg-opus-compr\;HDA_CONFIG=mix,COMPR_FFMPEG=true,COMPR_FFMPEG_CODEC=opus"
@@ -0,0 +1,13 @@
# Created with script "bench_comp_generate.sh ffmpeg_dec"
Object.Widget.ffmpeg_dec.1 {
Comment on lines 74 to 84
set(components_s32
"micsel_multich"
"ffmpeg_dec"
)

set(component_parameters_s32
"BENCH_MICSEL_PARAMS=default"
"BENCH_FFMPEG_DEC_PARAMS=default"
)

set (plat "mtl")
Comment on lines +12 to +13
source '$BENCH_CAPTURE_DAI_COPIER'
sink 'ffmpeg_dec.$BENCH_CAPTURE_HOST_PIPELINE.2'
Comment thread src/audio/src/src_common.c Outdated
Comment on lines +538 to +547
/*
* The base of delay_lines (and hence buffer_start, which is offset
* from it by a multiple of 8 bytes) must itself be 8-byte aligned:
* the HiFi FIR cores issue 64-bit AE_L32X2/AE_S32X2 circular
* accesses into it and fault (EXCCAUSE 9) on a 4-byte-aligned base.
* ALIGN_UP above only rounds the size; request the alignment on the
* allocation explicitly rather than relying on the allocator default
* (mod_alloc()/alignment 0 may return a 4-byte-aligned pointer).
*/
cd->delay_lines = mod_alloc_align(mod, delay_lines_size, sizeof(int32_t) * 2);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

lets make this a single line comment and use an existing macro for vector size/alignment.

The HiFi FIR cores in the SRC filter issue 64-bit AE_L32X2/AE_S32X2
circular accesses into cd->delay_lines and fault (EXCCAUSE 9) on a
4-byte-aligned base. Allocate cd->delay_lines with SOF_FRAME_BYTE_ALIGN
alignment rather than relying on the default mod_alloc() alignment.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Initialize scheduler_dp_init() in CAVS platform_init() when
CONFIG_ZEPHYR_DP_SCHEDULER is enabled, matching ACE platform_init().
This allows data-processing (DP) scheduled modules such as ffmpeg_dec
to run on the primary core on cAVS platforms (e.g. Tiger Lake).

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Use the COMPR_DECODER_CORE_ID define instead of a hardcoded core_id 1 on
the ffmpeg_dec widget, size COMPR_FFMPEG_DEC_HEAP to 256 KiB to cover
the 64 KiB PCM staging buffer and decoder working set, and add the
sof-hda-generic-ffmpeg-opus-compr topology build target.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add the ffmpeg_dec component to the playback benchmark harness (HDA and
SoundWire) with DP scheduling and decoder stack/heap budgets so a
topology instantiating the module can be built and driven by testbench
or on target.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add tools/test/audio/ffmpeg_dec_prepare.sh to generate FLAC test
vectors, STREAMINFO extradata blobs, and bit-exact S32_LE reference PCM
files for verifying the ffmpeg_dec module, as referenced in
src/audio/ffmpeg_dec/TESTING.md.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
In host_get_copy_bytes_normal(), the remaining committed compress drain
bytes (hd->drain_bytes - hd->total_data_processed) were rounded up only
to dma_sample_bytes before clamping dma_copy_bytes. However, the return
value of host_get_copy_bytes_normal() is rounded down to
hd->dma_copy_align (e.g. 32 bytes on HDA). When the final tail of a
compressed stream is smaller than hd->dma_copy_align, ALIGN_DOWN()
rounds dma_copy_bytes down to zero, preventing hd->total_data_processed
from ever reaching hd->drain_bytes and stalling compress drain EOS.

Round the remaining drain byte count up to MAX(dma_sample_bytes,
hd->dma_copy_align) for the DMA transfer/reload, and clamp the bytes
copied into the downstream sink in host_common_update() to the actual
payload remainder (consuming any trailing DMA padding from the source
DMA buffer) so stale HDA bytes are never published to the decoder.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
For container-wrapped FLAC streams without topology-supplied extradata,
ffmpeg_dec_skip_container() dynamically extracts the 34-byte STREAMINFO
header from the stream. Running the lazy backend configure block before
ffmpeg_dec_skip_container() caused avcodec_open2() to open the FLAC
decoder with empty extradata before STREAMINFO could be parsed.

Additionally, ffmpeg_dec_skip_container() runs inside ffmpeg_dec_process()
on the user-mode DP thread, where calling mod_alloc() in
ffmpeg_dec_store_extradata() faults for built-in DP modules. Embed the
extradata buffer inline in struct ffmpeg_dec_comp_data and run container
header stripping before lazy backend configuration.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/ffmpeg-decode-fixes branch from 2c699be to 33474be Compare November 3, 2026 20:48
@lgirdwood

Copy link
Copy Markdown
Member Author

Addressed review comments:

  1. src/audio/src/src_common.c: Shortened the comment to a single line and used SOF_FRAME_BYTE_ALIGN in mod_alloc_align().
  2. src/audio/host-zephyr.c: Kept the DMA transfer/reload aligned to hd->dma_copy_align in host_get_copy_bytes_normal(), and clamped the bytes copied into the downstream sink in host_common_update() to the actual committed payload remainder (consuming any trailing DMA padding from the source DMA buffer).
  3. tools/topology/topology2/platform/intel/compr-default.conf & tplg-targets.cmake: Updated COMPR_FFMPEG_DEC_HEAP to 262144 (256 KiB) for the default and Opus compress targets to cover the 64 KiB PCM staging buffer, input bounce buffer, and decoder working set.
  4. tools/topology/topology2/include/bench/ffmpeg_dec_s{16,24,32}.conf: Configured scheduler_domain "DP", stack_bytes_requirement 65536, and heap_bytes_requirement 262144 on the benchmark decoder widget.
  5. tools/topology/topology2/cavs-benchmark-sdw.conf: Added <ffmpeg_dec.conf> and the ffmpeg_dec32 BENCH_CONFIG entry for the SoundWire benchmark targets.
  6. tools/topology/topology2/include/bench/ffmpeg_dec_route.conf: Removed the second decoder instance from the microphone capture path and routed capture directly.

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