Skip to content

audio: ffmpeg_dec: split decoders, encoders, and filters into standalone per-codec LLEXTs - #11519

Open
lgirdwood wants to merge 10 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-llext-split
Open

lgirdwood wants to merge 10 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-llext-split

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Summary

Split the monolithic ffmpeg_dec.llext archive module into 25 standalone per-codec LLEXT modules (12 decoders, 11 encoders, and 2 audio filters), each with a dedicated UUID in uuid-registry.txt and <UUID>.bin symlink, keeping stock SOF openmodules in sof-<plat>-openmodules.ri:

  • Decoders (12): ffmpeg_dec_{flac,aac,opus,mp3,alac,sbc,g722,aptx,aptx_hd,g726,alaw,mulaw}
  • Encoders (11): ffmpeg_enc_{mp3,aac,flac,alac,sbc,g722,aptx,aptx_hd,g726,alaw,mulaw}
  • Audio filters (2): ffmpeg_af_{afftdn,alimiter}

Each module compiles with -fvisibility=hidden -ffunction-sections -fdata-sections and links a generated tiny codec/parser/filter shim registration archive against libavcodec_noco.a / libavfilter_noco.a / libswresample.a / libavutil.a / libnewlib_m.a (+ libshine / libvo-aacenc where selected) so unused FFmpeg codecs and parsers are dead-stripped.

LLEXT VMA & Loading Infrastructure

  • Added NO_OFFSET_ADVANCE, TOP_DOWN, and --reset support to sof_llext_build(), scripts/llext_link_helper.py, and scripts/llext_offset_calc.py so standalone per-codec decoders share the post-stock VMA slot (0xa0709000 on PTL relocatable builds) while encoders (ROLE enc) and ffmpeg_af_alimiter pack top-down from CONFIG_LIBRARY_BASE_ADDRESS + CONFIG_LIBRARY_REGION_SIZE without advancing module_size.
  • Added SOF_LLEXT_RETAIN (__attribute__((__retain__))) on .module and .mod_buildinfo so --gc-sections does not discard LLEXT manifests.
  • Defaulted CONFIG_LLEXT_HEAP_SIZE=32 when COMP_FFMPEG_DEC=m and LLEXT_TYPE_ELF_RELOCATABLE=y so large relocatable LLEXT symbol tables (e.g. ffmpeg_dec_aac, ffmpeg_enc_mp3, ffmpeg_dec_opus) fit at load time.
  • Added DEPENDS ${TOPDIR}/uuid-registry.txt in scripts/cmake/uuid-registry.cmake so uuid-registry.h regenerates automatically when UUIDs are added.

Topology2

  • Wired compr-ffmpeg.conf (COMPR_FFMPEG_LLEXT=true, default) and compr-capture-ffmpeg.conf to per-codec standalone module UUIDs, keeping monolithic UUID fallback when COMPR_FFMPEG_LLEXT=false.

Dependencies

Testing

  • Hardware verified on Damsel Fly (PTL / ACE 3.0) in CONFIG_LLEXT_TYPE_ELF_RELOCATABLE=y (with CONFIG_VIRTUAL_HEAP=n and CONFIG_SOF_ZEPHYR_HEAP_SIZE=0x80000 / 0xc0000 for compress PCM/FFmpeg buffer headroom):
    • ffmpeg_dec_mp3.llext: loaded alongside sof-ptl-openmodules.ri, opened libavcodec (mp3), decoded test_short.mp3.
    • ffmpeg_dec_flac.llext (tested at 0xc0000 heap): extracted 34-byte STREAMINFO, opened libavcodec (flac), decoded test.flac.
    • ffmpeg_dec_aac.llext: loaded, opened libavcodec (aac_fixed), decoded test.aac.
    • ffmpeg_enc_mp3.llext: loaded top-down, captured 16 KiB valid MPEG-1 Layer III frames (0xfffb9404...).
    • ffmpeg_enc_aac.llext: loaded top-down, captured 16 KiB valid MPEG-2 ADTS AAC-LC frames (0xfff94c80...).
  • Build checks:
    • intel_adsp/ace30/ptl with CONFIG_LLEXT_TYPE_ELF_RELOCATABLE=y (VMA range 0xa0688000..0xa0807c40, within 0x180000).
    • intel_adsp/ace30/ptl with CONFIG_LLEXT_TYPE_ELF_SHAREDLIB=y (zero missing dynamic symbols across all 25 LLEXTs; rimage signed).
    • intel_adsp/ace30/ptl with CONFIG_COMP_FFMPEG_DEC=m + CONFIG_COMP_FFMPEG_DEC_STUB=y, and CONFIG_COMP_FFMPEG_DEC=y (built-in).
    • Topology2: all 15 topology2_dev_sof-hda-generic-ffmpeg-*.tplg targets validated with alsatplg (0 errors).

Next Steps (Follow-up)

  • Split WebRTC modules into standalone LLEXTs in a separate PR once this FFmpeg split lands.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…try, query, and unload

Remove all build-time per-codec #ifdef checks from get_codec_info() in
base_fw.c and replace them with a build-time pre-allocated slot table
updated 1-by-1 via sof_codec_info_add() / sof_codec_info_remove() under
a spinlock (avoiding heap fragmentation across LLEXT load/unload cycles).

Add IPC4_SOF_INFO_GET (37) and IPC4_SOF_LIBRARY_UNLOAD (38) along with
IPC4_SOF_CAP_RUNTIME_SOF_INFO and IPC4_SOF_CAP_LIBRARY_UNLOAD under
IPC4_SOF_CAPS so hosts can query updated codecs after library load/unload
and purge idle dynamic libraries. Keep IPC4_FW_CONFIG emitting
IPC4_SOF_CODEC_INFO and IPC4_SOF_CAPS for backwards compatibility.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>

# Conflicts:
#	src/kernel/audio/base_fw.c
…brary unload

Parse the optional ".sof_codec_info" ELF section when loading or
DRAM-restoring an LLEXT library and register each codec item 1-by-1
with base_fw. Add lib_manager_unload_library() and
llext_manager_remove_library() to reject unsupported library types
(-ENOTSUP), free retained LLEXT inspection data before unloading, and
unregister the library's codec entries.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
… LLEXT

Move codec capability declarations out of base_fw.c into ffmpeg_dec,
mfcc, and cadence_ipc4: embed ".sof_codec_info" tables in LLEXT builds
and register built-in codec items 1-by-1 during SOF_MODULE_INIT via
sof_codec_info_add_items(). Mark the init wrappers __maybe_unused for
host library builds where SOF_MODULE_INIT is a no-op.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add NO_OFFSET_ADVANCE, TOP_DOWN, and --reset support to sof_llext_build(),
llext_link_helper.py, and llext_offset_calc.py so mutually exclusive standalone
LLEXTs can share the post-stock VMA slot or pack top-down from LIBRARY_REGION_SIZE
end without advancing module_size. Also retain .module/.mod_buildinfo sections,
add DEPENDS on uuid-registry.txt, and default CONFIG_LLEXT_HEAP_SIZE=32 for
relocatable FFmpeg builds.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…one LLEXTs

Split monolithic ffmpeg_dec LLEXT into 25 per-codec standalone LLEXT modules
(12 decoders, 11 encoders, 2 audio filters) with dedicated UUIDs in
uuid-registry.txt, each compiled with -fvisibility=hidden / -ffunction-sections /
-fdata-sections and linked against per-module shim registration libraries so
unused codecs and parsers are dead-stripped.

Place encoders (ROLE enc) and ffmpeg_af_alimiter top-down inside
LIBRARY_REGION_SIZE using NO_OFFSET_ADVANCE and TOP_DOWN while decoders share
the post-stock VA slot, fitting within default 0x180000 in relocatable mode.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Route COMPR_FFMPEG (decoder) and COMPR_FFMPEG_ENC (encoder) pipelines to the
per-codec standalone module UUIDs when COMPR_FFMPEG_LLEXT is enabled (default),
keeping legacy monolithic UUID fallback when disabled, and pass
COMPR_FFMPEG_ENC_CODEC for per-codec encoder topologies.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…ched heap perms

Keep .cold/.coldrodata addresses until teardown completes in both LL and DP domains, release vpage reservations in llext_manager_remove_library(), and restore SYS_MM_MEM_PERM_RW (K_MEM_PERM_RW | K_MEM_CACHE_WB) on detached ELF pages when unmapping or rolling back so freeing back to l3_heap does not leave read-only pages that panic on subsequent library loads.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/ffmpeg-llext-split branch from 12752f8 to e9dc085 Compare November 24, 2026 13:50
Address PR thesofproject#11519 review feedback:
- base_fw.c: log invalid parameters and lib_manager_unload_library() failures with LOG_ERR() in basefw_library_unload().
- codec_info.h / base_fw.c: move sof_codec_info_add_items() implementation to base_fw.c alongside sof_codec_info_add() and sof_codec_info_remove() (with stub under #else), and log NULL items or sof_codec_info_add() failures with LOG_ERR().
- lib_manager.c: log failure paths in lib_manager_unload_library() with LOG_ERR() and switch the unload success log to LOG_INF().
- llext_manager.c: replace new tr_err()/tr_warn() calls in LLEXT codec registration and unload paths with Zephyr LOG_WRN()/LOG_ERR().

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood

Copy link
Copy Markdown
Member Author

Addressed review comments in 2721296:

  1. src/kernel/audio/base_fw.c (basefw_library_unload): added LOG_ERR() logging for invalid IPC unload parameters and lib_manager_unload_library() failures.
  2. src/include/sof/audio/codec_info.h / src/kernel/audio/base_fw.c (sof_codec_info_add_items): moved the sof_codec_info_add_items() implementation into base_fw.c alongside sof_codec_info_add()/sof_codec_info_remove() (keeping the declaration and #else stub in codec_info.h) and added LOG_ERR() on NULL items and sof_codec_info_add() failures.
  3. src/kernel/library_manager/lib_manager.c (lib_manager_unload_library): added LOG_ERR() on invalid lib_id, unloaded library (-ENOENT), llext_manager_remove_library() failures, and unsupported load types (-ENOTSUP), and switched the unload success message to LOG_INF().
  4. src/kernel/library_manager/llext_manager.c: replaced new tr_err() / tr_warn() calls in llext_manager_register_lib_codecs(), llext_manager_remove_library(), and llext_manager_rm_cold_partitions() with Zephyr LOG_WRN() / LOG_ERR().

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.

2 participants