Skip to content

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

Merged
lgirdwood merged 9 commits into
thesofproject:mainfrom
lgirdwood:topic/ffmpeg-llext-split
Nov 28, 2026
Merged

lgirdwood merged 9 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.

@lgirdwood
lgirdwood force-pushed the topic/ffmpeg-llext-split branch from 12752f8 to e9dc085 Compare November 24, 2026 13:50
lgirdwood pushed a commit to lgirdwood/sof that referenced this pull request Nov 26, 2026
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().

@lgirdwood lgirdwood left a comment

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.

In general needs a small one line inline comment for each code block, and a comment for each new function with doxygen for public functions. Alos not following why we have changes to llext build now that rlocatable llext is upstream

Comment on lines +944 to +950
switch (ret) {
case -EBUSY:
return IPC4_BUSY;
case -ENOTSUP:
return IPC4_UNAVAILABLE;
default:
return IPC4_ERROR_INVALID_PARAM;

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.

can we LOG_ERR these to be helpful.

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.

Fixed and squashed into c6793fe: added LOG_ERR() in basefw_library_unload() for invalid parameters and lib_manager_unload_library() errors.

Comment thread src/include/sof/audio/codec_info.h Outdated
for (i = 0; i < count; i++) {
int ret = sof_codec_info_add(owner, items[i]);

if (ret < 0)

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.

if we fail let LOG_ERR

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.

Fixed and squashed into c6793fe: moved sof_codec_info_add_items() into base_fw.c with LOG_ERR() on NULL items and sof_codec_info_add() failures.

Comment on lines +1404 to +1416
ctx = _ext_lib->desc[lib_id];
if (!ctx)
return -ENOENT;

module_id = LIB_MANAGER_PACK_LIB_ID(lib_id);
if (ctx->load_type == SOF_MAN_MOD_TYPE_LLEXT ||
ctx->load_type == SOF_MAN_MOD_TYPE_LLEXT_AUX) {
ret = llext_manager_remove_library(module_id);
if (ret < 0)
return ret;
} else {
return -ENOTSUP;
}

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 LOG_ERR failures.

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.

Fixed and squashed into 884c5e9: added LOG_ERR() on every failure path in lib_manager_unload_library().


ret = sof_codec_info_add_items(mctx, sec, sec_size / sizeof(uint32_t));
if (ret < 0)
tr_warn(&lib_manager_tr, "failed to register codec info for mod %u: %d",

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 use Zephyr LOG APIs.

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.

Fixed and squashed into 884c5e9: switched llext_manager_register_lib_codecs() and llext_manager_remove_library() to Zephyr LOG_WRN().

tr_dbg(&lib_manager_tr, "remove %#zx @ %lx partition", part.size, part.start);
return k_mem_domain_remove_partition(domain, &part);
}

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 add the use case and why this change fixes the use case in the commit message.

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.

Updated d733a37 commit message with the DP/LL detached .cold/.coldrodata teardown use case and explanation, and switched tr_err() in llext_manager_rm_cold_partitions() to LOG_ERR().

Comment on lines +955 to +978
#if defined(CONFIG_FFMPEG_DEC_APTX_HD) || defined(CONFIG_COMP_FFMPEG_DEC_STUB)
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_APTX_HD, SOF_IPC_STREAM_PLAYBACK),
#endif
#if defined(CONFIG_FFMPEG_ENC_APTX_HD)
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_APTX_HD, SOF_IPC_STREAM_CAPTURE),
#endif
#if defined(CONFIG_FFMPEG_DEC_G726) || defined(CONFIG_COMP_FFMPEG_DEC_STUB)
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_G726, SOF_IPC_STREAM_PLAYBACK),
#endif
#if defined(CONFIG_FFMPEG_ENC_G726)
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_G726, SOF_IPC_STREAM_CAPTURE),
#endif
#if defined(CONFIG_FFMPEG_DEC_ALAW) || defined(CONFIG_COMP_FFMPEG_DEC_STUB)
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_ALAW, SOF_IPC_STREAM_PLAYBACK),
#endif
#if defined(CONFIG_FFMPEG_ENC_ALAW)
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_ALAW, SOF_IPC_STREAM_CAPTURE),
#endif
#if defined(CONFIG_FFMPEG_DEC_MULAW) || defined(CONFIG_COMP_FFMPEG_DEC_STUB)
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_MULAW, SOF_IPC_STREAM_PLAYBACK),
#endif
#if defined(CONFIG_FFMPEG_ENC_MULAW)
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_MULAW, SOF_IPC_STREAM_CAPTURE),
#endif

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.

this data must be runtime - I would expect to be able to load the ffmpeg llext mp3 decoder to any base firmware build. Yes we can split the ffmpeg-commo.llext from ffmpeg-mp3.llext and pull in the common as a dependecy for all ffmpeg modules.

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.

In standalone LLEXT builds (FFMPEG_MOD_ROLE_DEC), each .llext carries only its own .sof_codec_info item and can be loaded dynamically onto any base FW (ffmpeg_dec.c's #else Kconfig block is only for monolithic built-in/stub builds). Keeping ffmpeg_common.o self-contained inside each codec .llext avoids multi-library unload dependency complexity here; splitting ffmpeg-common.llext as a shared aux dependency can be done as a follow-up optimization.

#ifdef CONFIG_MMU
size_t pre_pad_size = (uintptr_t)vma & (PAGE_SZ - 1);
void *aligned_vma = (__sparse_force uint8_t *)vma - pre_pad_size;
uint32_t k_flags = K_MEM_CACHE_WB;

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.

commit message line wrapping is wrong.

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.

Fixed line wrapping and added the unload/reload use case in af156bc70.


if (!size)
return;

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.

we should explain why we do this in inline comment.

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.

Added function and inline comments explaining the empty-size guard and K_MEM_CACHE_WB / K_MEM_PERM_RW restoration in llext_manager_detached_update_flags() (af156bc70).

Comment thread src/include/sof/audio/codec_info.h Outdated

static inline int sof_codec_info_add_items(const void *owner, const uint32_t *items, size_t count)
{
size_t i;

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.

looks like this needs squashed into a previous patch in this PR.

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.

Squashed into c6793fe7b.

Comment thread zephyr/CMakeLists.txt
set(single_args LIB)
cmake_parse_arguments(PARSE_ARGV 1 SOF_LLEXT "${options}" "${single_args}" "${multi_args}")

cmake_path(SET SOF_BASE NORMALIZE ${APPLICATION_SOURCE_DIR}/..)

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.

another patch that needs squashed.

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.

Squashed the SOF_BASE (CMAKE_CURRENT_FUNCTION_LIST_DIR/..) fix into 1958a9543 and dropped --reset cleanly.

Loading or unloading DP LLEXT modules whose .cold/.coldrodata segments
are detached in DRAM can share cold partition metadata across LL and DP
memory domains. Detach cold partitions before section mapping/unloading
and switch partition removal error logs to Zephyr LOG_ERR().

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
DP codec modules execute on secondary cores (e.g., FFmpeg on core 1)
while IPC setup and teardown on core 0 access the module's vregion
interim heap. Explicitly flush D-cache over k_heap metadata updates so
all cores observe coherent interim heap state under SMP.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/ffmpeg-llext-split branch from 623533a to af156bc Compare November 28, 2026 17:06
@lgirdwood

Copy link
Copy Markdown
Member Author

Addressed review 6013898972 in rebased branch af156bc70 (9 clean commits onto origin/main):

  • Dropped build-time LLEXT VMA packing: reverted scripts/llext_link_helper.py and scripts/llext_offset_calc.py to origin/main and removed NO_OFFSET_ADVANCE, TOP_DOWN, --end-addr, and --reset from zephyr/CMakeLists.txt and src/audio/ffmpeg_dec/llext/CMakeLists.txt, relying on upstream relocatable vpage_reserve() placement.
  • Squashed fixups & cleaned commit history: folded the logging and SOF_BASE fixes into their original commits, removed # Conflicts: trailers, wrapped all commit messages to <=72 chars, and added use-case explanations.
  • Kconfig, Doxygen, & inline comments: added CONFIG_SOF_IPC4_CODEC_INFO_MAX_ITEMS, Doxygen on new public headers (lib_manager.h, llext_manager.h, codec_info.h), function/block comments across base_fw.c, lib_manager.c, llext_manager.c, llext.h, app/Kconfig, and ffmpeg_dec.c, and Zephyr LOG_* error/info logging throughout.
  • Clarified open questions inline: replied on threads regarding IPC4_SOF_INFO_GET / IPC4_SOF_CAPS (shared with Linux PR topology: Add Waves codec to mt8186 topology config: Add Waves overri… #6044), CONFIG_LLEXT_HEAP_SIZE (Zephyr llext_load() metadata heap vs topology vregion DP heap in compr-ffmpeg.conf), and runtime .sof_codec_info vs legacy built-in fallback / future ffmpeg-common.llext split.

Remove build-time per-codec #ifdef checks from get_codec_info() in
base_fw.c and replace them with a pre-allocated static slot table
(sized by CONFIG_SOF_IPC4_CODEC_INFO_MAX_ITEMS) updated 1-by-1 via
sof_codec_info_add() / sof_codec_info_add_items() /
sof_codec_info_remove() under a spinlock to avoid 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 or
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>
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, using Zephyr LOG_* APIs and
documenting public helpers with Doxygen.

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>
Prepare Zephyr LLEXT build rules for standalone per-codec modules:
- Add LINK_OPTIONS support to sof_llext_build() and ensure all LLEXT
  modules depend on uuid_reg_h when generated headers are enabled.
- Derive SOF_BASE in sof_llext_build() from
  CMAKE_CURRENT_FUNCTION_LIST_DIR/.. so out-of-tree
  APPLICATION_SOURCE_DIR builds always use SOF's scripts.
- Add SOF_LLEXT_RETAIN (__attribute__((__retain__))) on .mod_buildinfo
  so -ffunction-sections/-fdata-sections and --gc-sections preserve
  module metadata sections.
- Add DEPENDS on uuid-registry.txt for uuid_reg_h regeneration.
- Default CONFIG_LLEXT_HEAP_SIZE=32 for relocatable FFmpeg LLEXT
  metadata.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
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, and -fdata-sections and linked against per-module
shim registration libraries so unused codecs and parsers are stripped.

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>
Repeated load/unload cycles of large FFmpeg LLEXTs via
IPC4_SOF_LIBRARY_UNLOAD exhausted virtual memory pages and panicked on
subsequent reloads when freed detached cold pages kept read-only MMU
permissions or lost segment addresses before both domains tore down.

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 on
non-empty detached ELF pages during unmap/rollback so returning them to
l3_heap leaves writable heap pages cleanly reusable.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/ffmpeg-llext-split branch from af156bc to cac7540 Compare November 28, 2026 18:12
@intel-sofci

Copy link
Copy Markdown

PR 11519: test results

Run date: 2026-11-28 18:46 UTC

Tested commit: cac7540e63b8d411c146f359a3e3f97844e2f01d

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

@lgirdwood
lgirdwood merged commit 6af4fcf into thesofproject:main Nov 28, 2026
46 of 47 checks passed
@lgirdwood
lgirdwood deleted the topic/ffmpeg-llext-split branch November 28, 2026 20:39
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