Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
06ac7bc
audio: ffmpeg_dec: add FFmpeg (libavcodec/libavfilter) module
lrgirdwo Jul 11, 2026
7e6618b
topology2: add ffmpeg_dec benchmark test topology
lrgirdwo Jul 12, 2026
c70c0ce
audio: ffmpeg_dec: add MP3 decoder
lrgirdwo Jul 12, 2026
d81b938
audio: ffmpeg_dec: add MP3 encoder via libshine
lrgirdwo Jul 12, 2026
0712481
audio: ffmpeg_dec: add encoder mode (PCM -> MP3 via libshine)
lrgirdwo Jul 12, 2026
fb9fd55
audio: ffmpeg_dec: document HiFi intrinsics opportunities
lrgirdwo Jul 12, 2026
f9033d9
audio: webrtc_vad: add GMM voice activity detector module
lrgirdwo Jul 20, 2026
ac03eec
audio: webrtc_ns: add WebRTC spectral noise suppressor module
lrgirdwo Jul 20, 2026
91c0b5a
audio: webrtc_aec: add AECm echo cancellation module
lrgirdwo Jul 20, 2026
b4cfc8b
audio: webrtc_ns2: add RNNoise deep-learning noise suppressor module
lrgirdwo Jul 20, 2026
22e3eee
audio: webrtc: wire VAD/NS/AEC/NS2 modules into build system
lrgirdwo Jul 20, 2026
46e6b20
topology2: add integration topologies for WebRTC audio modules
lrgirdwo Jul 20, 2026
06e1cfc
audio: ffmpeg_dec: add root Kconfig and standalone cmake helper
lrgirdwo Jul 20, 2026
e9da0d5
docs: add detailed architecture, build, and usage READMEs for ffmpeg …
lrgirdwo Jul 20, 2026
10f174f
ffmpeg_dec: HIFI.md: add AAC-LC decode hot-spot appendix
lrgirdwo Jul 22, 2026
fe84b2a
ffmpeg_dec: enable FFmpeg asm + repoint to sof-hifi for Xtensa HiFi f…
lrgirdwo Jul 22, 2026
95e9fd3
ffmpeg_dec: bump ffmpeg to sof-hifi 181d38ad (clang float_dsp build fix)
lrgirdwo Jul 22, 2026
dfc4205
ffmpeg_dec: support cross-building FFmpeg with the LLVM xt-clang
lrgirdwo Jul 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 108 additions & 3 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,112 @@
# SPDX-License-Identifier: BSD-3-Clause

mainmenu "SOF $(PROJECTVERSION) Configuration"
config COMP_FFMPEG_DEC
tristate "FFmpeg (libavcodec) audio decoder"
select COMP_FFMPEG_DEC_STUB if COMP_STUBS
help
Select to include the FFmpeg audio decoder module. It wraps
libavcodec decoders behind the SOF module interface, decoding a
compressed elementary stream to PCM. The real backend cross-builds
libavcodec/libavutil/libswresample from the FFmpeg source pulled in
by west (see west.yml), enabling only the decoders selected below.
Without the source (or for CI) select COMP_FFMPEG_DEC_STUB to build
the dependency-free passthrough stub.

comment "Compiler: $(CC_VERSION_TEXT)"
config COMP_FFMPEG_DEC_STUB
bool "FFmpeg decoder stub backend"
depends on COMP_FFMPEG_DEC
help
Build the ffmpeg_dec module against a dependency-free passthrough
backend instead of libavcodec. Intended for testing and CI so the
SOF glue and LLEXT packaging can be validated without the FFmpeg
source or a cross-built archive.

source "Kconfig.sof"
if COMP_FFMPEG_DEC && !COMP_FFMPEG_DEC_STUB

comment "FFmpeg decoders to build (footprint scales with selection)"

config FFMPEG_DEC_FLAC
bool "FLAC decoder"
default y
help
Lossless integer decoder. Smallest footprint, no floating-point
math. Enables --enable-decoder=flac in the libavcodec build.

config FFMPEG_DEC_AAC
bool "AAC-LC decoder"
help
AAC Low Complexity decoder. Pulls in the single-precision float
math layer (see FFMPEG_DEC_FLOAT_MATH). Enables
--enable-decoder=aac in the libavcodec build.

config FFMPEG_DEC_OPUS
bool "Opus decoder"
help
Opus (SILK+CELT) decoder. Pulls in the single-precision float math
layer. Enables --enable-decoder=opus in the libavcodec build.

config FFMPEG_DEC_MP3
bool "MP3 decoder"
help
MPEG-1/2 Layer III decoder. Enables --enable-decoder=mp3 and the
mpegaudio parser in the libavcodec build. Uses the float math layer.

config FFMPEG_ENC_MP3
bool "MP3 encoder (libshine, fixed-point)"
help
MPEG-1 Layer III encoder via libshine, a small fixed-point encoder
(west-pinned; FFmpeg has no native MP3 encoder). Cross-builds libshine
and enables --enable-libshine --enable-encoder=libshine. Fixed-point, so
no float math dependency. The encoder is built into the archive; a module
encode path (PCM->MP3) is a separate build mode.

comment "FFmpeg audio filters (libavfilter; need the avfilter-graph backend to run)"

config FFMPEG_FILTER_AFFTDN
bool "FFT noise reduction (afftdn)"
help
Build FFmpeg's FFT-based denoiser (afftdn) into libavfilter. Pure DSP,
no external model file (unlike arnndn). Enabling any filter turns on
libavfilter in the cross-build. NOTE: a filter is only usable at runtime
once the module gains an avfilter-graph backend; selecting it here just
builds the filter into the archive.

config FFMPEG_DEC_FILTER_MODE
bool "Build as a PCM filter effect instead of a decoder [EXPERIMENTAL]"
select FFMPEG_FILTER_AFFTDN
help
Build the module as a PCM source->sink effect that runs an FFmpeg
audio filter graph (default afftdn noise reduction) via the modern
.process interface, instead of the compressed-stream decoder. Turns on
libavfilter and the fast float math. Structurally complete and
load-ready; real-time latency/format tuning needs on-hardware bring-up.

# Turns on libavfilter in the FFmpeg cross-build when any filter is selected.
config FFMPEG_BUILD_AVFILTER
bool
default y if FFMPEG_FILTER_AFFTDN

# Selected automatically when a decoder or filter that needs IEEE float math is
# built. Gates compilation of the fast single-precision libm (fastmathf.c).
config FFMPEG_DEC_FLOAT_MATH
bool
default y if FFMPEG_DEC_AAC || FFMPEG_DEC_OPUS || FFMPEG_DEC_MP3 || FFMPEG_FILTER_AFFTDN

config FFMPEG_DEC_COLD_SPLIT
bool "Place cold FFmpeg code (av_cold init/setup) in DRAM [EXPERIMENTAL]"
depends on COLD_STORE_EXECUTE_DRAM
default n
help
EXPERIMENTAL. Build libavcodec with -mtext-section-literals and rename
FFmpeg's cold functions (its av_cold init/table-generation code, which GCC
emits into .text.unlikely) into SOF's .cold section so the LLEXT loader
places them in DRAM, keeping the hot per-frame decode in fast SRAM.

Measured cold code is small (~1 KB for FLAC, ~26 KB for AAC) because
FFmpeg only marks init functions av_cold. Placing that much cold code in a
-shared LLEXT currently hits Xtensa linker limits (cold->hot call8 range
needs -mlongcalls; the orphan .cold lands at a bad LMA and overlaps .hash),
so this is off by default pending proper cold-region placement in the LLEXT
memory map. See git history / TESTING notes.

endif # COMP_FFMPEG_DEC && !COMP_FFMPEG_DEC_STUB
199 changes: 199 additions & 0 deletions ffmpeg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# SPDX-License-Identifier: BSD-3-Clause
#
# Cross-build decoder-only FFmpeg static libraries for the ffmpeg_dec module.
#
# Invokes FFmpeg's autotools build as an ExternalProject, cross-compiled with the
# Zephyr target toolchain, enabling only the decoders selected in Kconfig. The
# source comes from the west-pinned FFmpeg project (see west.yml). Produces
# libavcodec/libavutil/libswresample .a under ${FFMPEG_INSTALL_DIR} for the LLEXT
# to link, and defines the 'ffmpeg_ext' target it must depend on.

include(ExternalProject)

# --- 1. Locate the FFmpeg source (west module), overridable for local trees ---
if(NOT DEFINED SOF_FFMPEG_SRC_DIR)
set(SOF_FFMPEG_SRC_DIR "${sof_top_dir}/../modules/audio/ffmpeg"
CACHE PATH "FFmpeg source tree (west-pinned)")
endif()
cmake_path(NORMAL_PATH SOF_FFMPEG_SRC_DIR)
if(NOT EXISTS "${SOF_FFMPEG_SRC_DIR}/configure")
message(FATAL_ERROR
"ffmpeg_dec: FFmpeg source not found at '${SOF_FFMPEG_SRC_DIR}'.\n"
"Run 'west update' (FFmpeg is pinned in west.yml) or pass "
"-DSOF_FFMPEG_SRC_DIR=<path-to-clean-ffmpeg-checkout>.")
endif()

# --- 2. Kconfig -> --enable-decoder / --enable-parser lists ---
set(_ff_decoders "")
set(_ff_parsers "")
if(CONFIG_FFMPEG_DEC_FLAC)
list(APPEND _ff_decoders flac)
list(APPEND _ff_parsers flac)
endif()
if(CONFIG_FFMPEG_DEC_AAC)
list(APPEND _ff_decoders aac aac_latm)
list(APPEND _ff_parsers aac aac_latm)
endif()
if(CONFIG_FFMPEG_DEC_OPUS)
list(APPEND _ff_decoders opus)
list(APPEND _ff_parsers opus)
endif()
if(CONFIG_FFMPEG_DEC_MP3)
list(APPEND _ff_decoders mp3)
list(APPEND _ff_parsers mpegaudio)
endif()
if(NOT _ff_decoders)
message(FATAL_ERROR "ffmpeg_dec: no decoder selected (Kconfig FFMPEG_DEC_*)")
endif()
list(JOIN _ff_decoders "," _ff_dec_csv)
list(JOIN _ff_parsers "," _ff_par_csv)

# --- 2b. Kconfig -> libavfilter audio filters (off unless a filter is chosen) ---
set(_ff_avfilter_cfg --disable-avfilter)
if(CONFIG_FFMPEG_BUILD_AVFILTER)
set(_ff_filters "")
if(CONFIG_FFMPEG_FILTER_AFFTDN)
list(APPEND _ff_filters afftdn)
endif()
list(JOIN _ff_filters "," _ff_filt_csv)
# abuffer/abuffersink feed/drain a filter graph; aformat negotiates format.
set(_ff_avfilter_cfg
--enable-avfilter
--enable-filter=abuffer,abuffersink,aformat,${_ff_filt_csv})
message(STATUS "ffmpeg_dec: enabling avfilter, filters [${_ff_filt_csv}]")
endif()

# --- 3. Derive the cross toolchain prefix from the Zephyr target compiler ---
# e.g. .../bin/xtensa-intel_ace30_ptl_zephyr-elf-gcc
# -> prefix .../bin/xtensa-intel_ace30_ptl_zephyr-elf-
get_filename_component(_tc_dir "${CMAKE_C_COMPILER}" DIRECTORY)
get_filename_component(_tc_name "${CMAKE_C_COMPILER}" NAME)
string(REGEX REPLACE "gcc$" "" _tc_prefix_name "${_tc_name}")
set(_ff_cross_prefix "${_tc_dir}/${_tc_prefix_name}")

# GCC 14 (Zephyr SDK) promotes these to errors; FFmpeg 7.x trips them.
set(_ff_extra_cflags "-fPIC -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration")

set(FFMPEG_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/ffmpeg-install" CACHE INTERNAL "ffmpeg_dec libs")

# Hot/cold split: GCC emits av_cold (init/setup) functions into .text.unlikely.
# We rename that to SOF's .cold (post-install, below) so the LLEXT loader places
# it in DRAM. -mtext-section-literals interleaves each function's Xtensa L32R
# literals into its text section (as SOF does for LLEXT module code) so the
# renamed section carries its literals and L32R stays in range. We deliberately
# do NOT use -ffunction-sections: keeping one .text.unlikely per object lets a
# single objcopy --rename-section catch it, and lets .cold be placed by SOF's
# existing orphan .cold handling (a hand-written linker script that forces .cold
# ahead of .text overruns the SRAM budget and overlaps .rodata for big codecs).
if(CONFIG_FFMPEG_DEC_COLD_SPLIT)
# -mlongcalls: cold code lives in DRAM (.cold, relocated by the loader) far
# from the hot SRAM .text, so calls between them exceed call8 range; longcalls
# emit an indirect L32R+CALLX with unlimited range. -mtext-section-literals
# keeps each function's literals in its own text section so the rename carries
# them. Coarse split: rename the whole FFmpeg .text (not just av_cold) into
# .cold so essentially all of libav* executes from DRAM, freeing SRAM.
set(_ff_extra_cflags "${_ff_extra_cflags} -mtext-section-literals -mlongcalls")
set(_ff_objcopy "${_ff_cross_prefix}objcopy")
set(_ff_cold_rename
COMMAND ${_ff_objcopy} --rename-section .text=.cold
${FFMPEG_INSTALL_DIR}/lib/libavcodec.a
COMMAND ${_ff_objcopy} --rename-section .text=.cold
${FFMPEG_INSTALL_DIR}/lib/libavutil.a
COMMAND ${_ff_objcopy} --rename-section .text=.cold
${FFMPEG_INSTALL_DIR}/lib/libswresample.a)
endif()

# --- 3b. MP3 encoder via libshine (fixed-point; FFmpeg has no native one) ---
set(_ff_cfg_env "PATH=${_tc_dir}:$ENV{PATH}")
set(_ff_shine_cfg "")
set(_ff_shine_dep "")
if(CONFIG_FFMPEG_ENC_MP3)
set(SHINE_SRC "${sof_top_dir}/../modules/audio/shine")
if(NOT EXISTS "${SHINE_SRC}/src/lib/layer3.h")
message(FATAL_ERROR "ffmpeg_dec: libshine source not at '${SHINE_SRC}'; run 'west update'")
endif()
set(SHINE_INSTALL "${CMAKE_CURRENT_BINARY_DIR}/shine-install")
file(MAKE_DIRECTORY "${SHINE_INSTALL}/lib/pkgconfig" "${SHINE_INSTALL}/include/shine")
# pkg-config file for FFmpeg's require_pkg_config libshine.
file(WRITE "${SHINE_INSTALL}/lib/pkgconfig/shine.pc"
"prefix=${SHINE_INSTALL}
libdir=\${prefix}/lib
includedir=\${prefix}/include
Name: shine
Description: Shine fixed-point MP3 encoder
Version: 3.1.1
Libs: -L\${libdir} -lshine
Cflags: -I\${includedir}
")
# FFmpeg's -lshine link *test* pulls newlib malloc -> Zephyr runtime syms
# (z_errno_wrap, ...) that only exist at module load. Provide dummies so the
# configure test links; --extra-ldflags only affects tests, not the .a build.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/shine_cfgstub.c"
"int z_errno_wrap(void){return 0;}
void *stdout;
int open(const char *p, int f, ...){return -1;}
void *sbrk(int i){return (void *)-1;}
")
# libshine's lib needs no config.h; build the objects directly and archive
# (its autotools CLI/shared link cannot work bare-metal).
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/shine-build.sh"
"#!/bin/sh
set -e
export PATH=${_tc_dir}:\$PATH
mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/shine-obj
for f in ${SHINE_SRC}/src/lib/*.c; do
${CMAKE_C_COMPILER} -O2 -fPIC -mtext-section-literals -DSHINE_HAVE_BSWAP_H \\
-I${SHINE_SRC}/src/lib -c \"\$f\" \\
-o ${CMAKE_CURRENT_BINARY_DIR}/shine-obj/\$(basename \"\$f\").o
done
${_ff_cross_prefix}ar rcs ${SHINE_INSTALL}/lib/libshine.a ${CMAKE_CURRENT_BINARY_DIR}/shine-obj/*.o
cp ${SHINE_SRC}/src/lib/layer3.h ${SHINE_INSTALL}/include/shine/layer3.h
${CMAKE_C_COMPILER} -fPIC -c ${CMAKE_CURRENT_BINARY_DIR}/shine_cfgstub.c \\
-o ${CMAKE_CURRENT_BINARY_DIR}/shine_cfgstub.o
")
add_custom_command(
OUTPUT "${SHINE_INSTALL}/lib/libshine.a" "${CMAKE_CURRENT_BINARY_DIR}/shine_cfgstub.o"
COMMAND sh "${CMAKE_CURRENT_BINARY_DIR}/shine-build.sh"
VERBATIM)
add_custom_target(shine_ext DEPENDS "${SHINE_INSTALL}/lib/libshine.a")

set(_ff_cfg_env "PATH=${_tc_dir}:$ENV{PATH}" "PKG_CONFIG_PATH=${SHINE_INSTALL}/lib/pkgconfig")
set(_ff_shine_cfg --enable-libshine --enable-encoder=libshine --pkg-config=pkg-config
"--extra-ldflags=${CMAKE_CURRENT_BINARY_DIR}/shine_cfgstub.o")
set(_ff_shine_dep shine_ext)
message(STATUS "ffmpeg_dec: enabling MP3 encoder via libshine (${SHINE_SRC})")
endif()

# --- 4. Configure + make + install (out-of-tree; source must be clean) ---
ExternalProject_Add(ffmpeg_ext
DEPENDS ${_ff_shine_dep}
SOURCE_DIR "${SOF_FFMPEG_SRC_DIR}"
BUILD_IN_SOURCE 0
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env ${_ff_cfg_env}
<SOURCE_DIR>/configure
--prefix=${FFMPEG_INSTALL_DIR}
--enable-cross-compile --target-os=none --arch=xtensa
--cross-prefix=${_ff_cross_prefix} --cc=${CMAKE_C_COMPILER}
--disable-asm --disable-all --disable-everything --disable-autodetect
--disable-programs --disable-doc --disable-network
--disable-avformat --disable-avdevice ${_ff_avfilter_cfg}
--disable-swscale --disable-postproc
--disable-pthreads --disable-w32threads --disable-os2threads
--disable-runtime-cpudetect --disable-debug
--enable-avcodec --enable-avutil --enable-swresample
--enable-decoder=${_ff_dec_csv} --enable-parser=${_ff_par_csv}
${_ff_shine_cfg}
--enable-small --enable-pic
"--extra-cflags=${_ff_extra_cflags}"
BUILD_COMMAND
${CMAKE_COMMAND} -E env "PATH=${_tc_dir}:$ENV{PATH}" make -j 8
INSTALL_COMMAND make install
${_ff_cold_rename}
BUILD_BYPRODUCTS
${FFMPEG_INSTALL_DIR}/lib/libavcodec.a
${FFMPEG_INSTALL_DIR}/lib/libavutil.a
${FFMPEG_INSTALL_DIR}/lib/libswresample.a
)

message(STATUS "ffmpeg_dec: cross-building FFmpeg decoders [${_ff_dec_csv}] from ${SOF_FFMPEG_SRC_DIR}")
15 changes: 15 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ if(NOT CONFIG_COMP_MODULE_SHARED_LIBRARY_BUILD)
if(CONFIG_COMP_DRC)
add_subdirectory(drc)
endif()
if(CONFIG_COMP_FFMPEG_DEC)
add_subdirectory(ffmpeg_dec)
endif()
if(CONFIG_COMP_FIR)
add_subdirectory(eq_fir)
endif()
Expand Down Expand Up @@ -107,6 +110,18 @@ if(NOT CONFIG_COMP_MODULE_SHARED_LIBRARY_BUILD)
if(CONFIG_COMP_VOLUME)
add_subdirectory(volume)
endif()
if(CONFIG_COMP_WEBRTC_VAD)
add_subdirectory(webrtc_vad)
endif()
if(CONFIG_COMP_WEBRTC_NS)
add_subdirectory(webrtc_ns)
endif()
if(CONFIG_COMP_WEBRTC_AEC)
add_subdirectory(webrtc_aec)
endif()
if(CONFIG_COMP_WEBRTC_NS2)
add_subdirectory(webrtc_ns2)
endif()
if(CONFIG_DTS_CODEC)
add_subdirectory(codec)
endif()
Expand Down
5 changes: 5 additions & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ rsource "dcblock/Kconfig"
rsource "drc/Kconfig"
rsource "eq_fir/Kconfig"
rsource "eq_iir/Kconfig"
rsource "ffmpeg_dec/Kconfig"
rsource "google/Kconfig"
rsource "igo_nr/Kconfig"
rsource "mfcc/Kconfig"
Expand All @@ -161,6 +162,10 @@ rsource "tensorflow/Kconfig"
rsource "tone/Kconfig"
rsource "up_down_mixer/Kconfig"
rsource "volume/Kconfig"
rsource "webrtc_vad/Kconfig"
rsource "webrtc_ns/Kconfig"
rsource "webrtc_aec/Kconfig"
rsource "webrtc_ns2/Kconfig"
# --- End Kconfig Sources (alphabetical order) ---

rsource "level_multiplier/Kconfig"
Expand Down
18 changes: 18 additions & 0 deletions src/audio/ffmpeg_dec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: BSD-3-Clause

if(CONFIG_COMP_FFMPEG_DEC STREQUAL "m" AND DEFINED CONFIG_LLEXT)
add_subdirectory(llext ${PROJECT_BINARY_DIR}/ffmpeg_dec_llext)
add_dependencies(app ffmpeg_dec)
else()
add_local_sources(sof ffmpeg_dec.c)

if(CONFIG_COMP_FFMPEG_DEC_STUB)
add_local_sources(sof ffmpeg_dec-stub.c)
else()
add_local_sources(sof ffmpeg_dec-ffmpeg.c)
# NOTE: ffmpeg_dec-shims.c / ffmpeg_dec-alloc.c are LLEXT-only (see
# llext/CMakeLists.txt). They provide libc/libm symbols the isolated LLEXT
# cannot import; in a built-in (=y) or native/testbench build the real libc
# provides those, so including them here would multiply-define malloc etc.
endif()
endif()
Loading
Loading