Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
config SCHED_CPU_MASK_PIN_ONLY
default y if SMP

# Zephyr's LLEXT loader allocates ELF section/symbol metadata from this static
# .llext_heap during llext_load(), independent of the DP module vregion heap
# sized by topology (heap_bytes_requirement). Relocatable FFmpeg LLEXTs need 32 KB.
config LLEXT_HEAP_SIZE
default 32 if COMP_FFMPEG_DEC = m && LLEXT_TYPE_ELF_RELOCATABLE

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 should come from the vregion topology heap size

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.

Topology already sizes the codec DP module's runtime vregion heap via heap_bytes_requirement ($COMPR_FFMPEG_DEC_HEAP in compr-ffmpeg.conf and $COMPR_FFMPEG_ENC_HEAP in compr-capture-ffmpeg.conf). CONFIG_LLEXT_HEAP_SIZE configures Zephyr's static .llext_heap used by llext_load() for ELF section/symbol metadata before any module instance or vregion exists; added a clarifying comment above config LLEXT_HEAP_SIZE in app/Kconfig (1958a9543).


# Allow compiler to determine whether to generate FLIX instructions.
choice COMPILER_CODEGEN_VLIW
default COMPILER_CODEGEN_VLIW_AUTO if "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "xt-clang"
Expand Down
3 changes: 2 additions & 1 deletion scripts/cmake/uuid-registry.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ add_custom_command(
COMMAND
${PYTHON_EXECUTABLE} ${TOPDIR}/scripts/gen-uuid-reg.py
${TOPDIR}/uuid-registry.txt
${UUID_REG_H})
${UUID_REG_H}
DEPENDS ${TOPDIR}/uuid-registry.txt)

add_custom_target(uuid_reg_h DEPENDS ${UUID_REG_H})

Expand Down
9 changes: 9 additions & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ config COMP_BASEFW_IPC4
help
Select for BASEFW component

config SOF_IPC4_CODEC_INFO_MAX_ITEMS
int "Maximum runtime codec capability items in BaseFW"
default 64
range 16 256
depends on COMP_BASEFW_IPC4
help
Maximum number of codec capability entries stored in the BaseFW
static runtime codec registry for IPC4_FW_SOF_INFO queries.

config IPC4_BASE_FW_INTEL
bool "BASEFW component Intel vendor extensions"
depends on COMP_BASEFW_IPC4
Expand Down
7 changes: 5 additions & 2 deletions src/audio/ffmpeg_dec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

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)
if(FFMPEG_LLEXT_TARGETS)
add_dependencies(app ${FFMPEG_LLEXT_TARGETS})
endif()
else()
add_local_sources(sof ffmpeg_dec.c)
add_local_sources(sof ffmpeg_common.c ffmpeg_dec.c)

if(CONFIG_FFMPEG_DEC_FLAC OR CONFIG_COMP_FFMPEG_DEC_STUB)
add_local_sources(sof ffmpeg_dec-flac.c)
Expand Down Expand Up @@ -88,6 +90,7 @@ else()
# must target THAT scope via TARGET_DIRECTORY, else CMake silently
# ignores it and the glue keeps hardware FP0.
set(_ffmpeg_dec_sources
${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg_common.c
${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg_dec.c
${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg_dec-ffmpeg.c
${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg_dec-convert.c
Expand Down
47 changes: 47 additions & 0 deletions src/audio/ffmpeg_dec/ffmpeg-encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// domain, so a DP-scheduled codec (needed to keep the heavy codec init and
// per-frame encode off the LL tick) must use the sink/source .process interface.

#include <sof/audio/codec_info.h>
#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/source_api.h>
#include <sof/audio/sink_api.h>
Expand All @@ -19,7 +20,11 @@
#include <errno.h>
#include "ffmpeg_dec.h"

#ifdef FFMPEG_MOD_ROLE_ENC
LOG_MODULE_REGISTER(ffmpeg_dec, CONFIG_SOF_LOG_LEVEL);
#else
LOG_MODULE_DECLARE(ffmpeg_dec, CONFIG_SOF_LOG_LEVEL);
#endif

#define FFMPEG_ENC_DEFAULT_BITRATE 128000

Expand All @@ -35,6 +40,15 @@ LOG_MODULE_DECLARE(ffmpeg_dec, CONFIG_SOF_LOG_LEVEL);
*/
#define FFMPEG_ENC_PCM_STAGE 16384

#ifdef FFMPEG_MOD_ROLE_ENC
#ifndef FFMPEG_MOD_BESPOKE
#define FFMPEG_MOD_BESPOKE 0
#endif
extern const struct ffmpeg_enc_codec_ops FFMPEG_MOD_CODEC_OPS;
static const struct ffmpeg_enc_codec_ops * const ffmpeg_enc_codecs[] = {
&FFMPEG_MOD_CODEC_OPS,
};
#else
static const struct ffmpeg_enc_codec_ops * const ffmpeg_enc_codecs[] = {
#if defined(CONFIG_FFMPEG_ENC_MP3)
&ffmpeg_enc_mp3_ops,
Expand Down Expand Up @@ -70,6 +84,7 @@ static const struct ffmpeg_enc_codec_ops * const ffmpeg_enc_codecs[] = {
&ffmpeg_enc_mulaw_ops,
#endif
};
#endif /* FFMPEG_MOD_ROLE_ENC */

static const struct ffmpeg_enc_codec_ops *
ffmpeg_enc_find_codec_ops_by_snd_id(const struct snd_codec *codec_params)
Expand Down Expand Up @@ -528,3 +543,35 @@ int ffmpeg_enc_mod_free(struct processing_module *mod)
mod->priv.private = NULL;
return 0;
}

#ifdef FFMPEG_MOD_ROLE_ENC
#include <module/module/api_ver.h>
#include <module/module/llext.h>
#include <rimage/sof/user/manifest.h>

static const struct module_interface ffmpeg_enc_mod_interface = {
.init = ffmpeg_enc_mod_init,
.prepare = ffmpeg_enc_mod_prepare,
.process = ffmpeg_enc_mod_process,
.is_ready_to_process = ffmpeg_enc_is_ready_to_process,
.reset = ffmpeg_enc_mod_reset,
.free = ffmpeg_enc_mod_free,
};

static const uint32_t ffmpeg_enc_codec_info_items[]
__section(SOF_CODEC_INFO_SECTION) __used FFMPEG_SECTION_RETAIN = {
SOF_CODEC_INFO_ITEM(FFMPEG_MOD_SND_CODEC_ID, SOF_IPC_STREAM_CAPTURE),
#if FFMPEG_MOD_BESPOKE
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_CAPTURE),
#endif
};

#define FFMPEG_REG_UUID(sym) SOF_REG_UUID(sym)

static const struct sof_man_module_manifest mod_manifest
__section(".module") __used FFMPEG_SECTION_RETAIN =
SOF_LLEXT_MODULE_MANIFEST(FFMPEG_MOD_MANIFEST_NAME, &ffmpeg_enc_mod_interface, 1,
FFMPEG_REG_UUID(FFMPEG_MOD_UUID_SYM), 40);

SOF_LLEXT_BUILDINFO;
#endif /* FFMPEG_MOD_ROLE_ENC */
71 changes: 69 additions & 2 deletions src/audio/ffmpeg_dec/ffmpeg-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// Built when CONFIG_FFMPEG_FILTER is enabled (selected by any
// CONFIG_FFMPEG_FILTER_* option), which pulls libavfilter into the module.

#include <sof/audio/codec_info.h>
#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/source_api.h>
#include <sof/audio/sink_api.h>
Expand All @@ -32,7 +33,11 @@
#include <libavutil/opt.h>
#include <libavutil/samplefmt.h>

#ifdef FFMPEG_MOD_ROLE_AF
LOG_MODULE_REGISTER(ffmpeg_dec, CONFIG_SOF_LOG_LEVEL);
#else
LOG_MODULE_DECLARE(ffmpeg_dec, CONFIG_SOF_LOG_LEVEL);
#endif

#define FFMPEG_AF_MAX_NAME 32
#define FFMPEG_AF_MAX_ARGS 128
Expand All @@ -52,15 +57,17 @@ struct ffmpeg_af_filter_desc {
};

static const struct ffmpeg_af_filter_desc ffmpeg_af_filters[] = {
#if defined(CONFIG_FFMPEG_FILTER_AFFTDN)
#if (!defined(FFMPEG_MOD_ROLE_AF) && defined(CONFIG_FFMPEG_FILTER_AFFTDN)) || \
defined(FFMPEG_AF_SINGLE_AFFTDN)
{
.id = FFMPEG_AF_FILTER_AFFTDN,
.name = "afftdn",
.default_args = "nr=28:nf=-20",
.sample_fmt = AV_SAMPLE_FMT_FLTP,
},
#endif
#if defined(CONFIG_FFMPEG_FILTER_ALIMITER)
#if (!defined(FFMPEG_MOD_ROLE_AF) && defined(CONFIG_FFMPEG_FILTER_ALIMITER)) || \
defined(FFMPEG_AF_SINGLE_ALIMITER)
{
.id = FFMPEG_AF_FILTER_ALIMITER,
.name = "alimiter",
Expand Down Expand Up @@ -943,3 +950,63 @@ int ffmpeg_af_mod_free(struct processing_module *mod)
md->private = NULL;
return 0;
}

#ifdef FFMPEG_MOD_ROLE_AF
#include <module/module/api_ver.h>
#include <module/module/llext.h>
#include <rimage/sof/user/manifest.h>

__cold static int
ffmpeg_af_set_config_ext(struct processing_module *mod, uint32_t config_id,
enum module_cfg_fragment_position pos, uint32_t data_offset_size,
const uint8_t *fragment, size_t fragment_size, uint8_t *response,
size_t response_size)
{
struct comp_dev *dev = mod->dev;
struct module_config *config = &mod->priv.cfg;
int ret;

assert_can_be_cold();

ret = module_set_configuration(mod, config_id, pos, data_offset_size, fragment,
fragment_size, response, response_size);
if (ret < 0) {
comp_err(dev, "module_set_configuration failed %d", ret);
return ret;
}

if (pos != MODULE_CFG_FRAGMENT_LAST && pos != MODULE_CFG_FRAGMENT_SINGLE)
return 0;

if (!config->size || !config->data) {
comp_warn(dev, "empty filter config");
return 0;
}

return ffmpeg_af_mod_set_config(mod, config->data, config->size);
}

static const struct module_interface ffmpeg_af_mod_interface = {
.init = ffmpeg_af_mod_init,
.prepare = ffmpeg_af_mod_prepare,
.process = ffmpeg_af_mod_process,
.is_ready_to_process = ffmpeg_af_is_ready_to_process,
.set_configuration = ffmpeg_af_set_config_ext,
.reset = ffmpeg_af_mod_reset,
.free = ffmpeg_af_mod_free,
};

static const uint32_t ffmpeg_af_codec_info_items[]
__section(SOF_CODEC_INFO_SECTION) __used FFMPEG_SECTION_RETAIN = {
SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_PCM, SOF_IPC_STREAM_PLAYBACK),
};

#define FFMPEG_REG_UUID(sym) SOF_REG_UUID(sym)

static const struct sof_man_module_manifest mod_manifest
__section(".module") __used FFMPEG_SECTION_RETAIN =
SOF_LLEXT_MODULE_MANIFEST(FFMPEG_MOD_MANIFEST_NAME, &ffmpeg_af_mod_interface, 1,
FFMPEG_REG_UUID(FFMPEG_MOD_UUID_SYM), 40);

SOF_LLEXT_BUILDINFO;
#endif /* FFMPEG_MOD_ROLE_AF */
46 changes: 40 additions & 6 deletions src/audio/ffmpeg_dec/ffmpeg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,18 @@ if(CONFIG_FFMPEG_BUILD_AVFILTER)
endif()

# --- 3. Derive the cross toolchain + per-compiler cross flags ---
if(CONFIG_LLEXT_BUILD_PIC OR NOT CONFIG_COMP_FFMPEG_DEC STREQUAL "m")
set(_ff_pic_cflag "-fPIC")
set(_ff_pic_cfg "--enable-pic")
else()
set(_ff_pic_cflag "-fno-pic -fno-pie")
set(_ff_pic_cfg "--disable-pic")
endif()
# GCC 14 (Zephyr SDK) promotes these to errors; FFmpeg 7.x trips them.
set(_ff_extra_cflags "-fPIC -mlongcalls -mtext-section-literals -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration")
set(_ff_extra_cflags "${_ff_pic_cflag} -mlongcalls -mtext-section-literals -Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration")
if(NOT CONFIG_FFMPEG_DEC_COLD_SPLIT)
set(_ff_extra_cflags "${_ff_extra_cflags} -ffunction-sections -fdata-sections -fvisibility=hidden")
endif()

# SOF decodes AAC-LC only. Tell the AAC decoder to skip the per-element SBR/PS
# storage (~437 KiB of a ~554 KiB ExtChannelElement); LC never exercises SBR,
Expand Down Expand Up @@ -487,13 +497,13 @@ export PATH=${_tc_dir}:\$PATH
CC=\"${_ff_cc}\"
mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/shine-obj
for f in ${SHINE_SRC}/src/lib/*.c; do
\$CC -O2 -fPIC -mlongcalls -mtext-section-literals -DSHINE_HAVE_BSWAP_H \\
\$CC -O2 ${_ff_pic_cflag} -ffunction-sections -fdata-sections -fvisibility=hidden -mlongcalls -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
\$CC -fPIC -c ${CMAKE_CURRENT_BINARY_DIR}/shine_cfgstub.c \\
\$CC ${_ff_pic_cflag} -c ${CMAKE_CURRENT_BINARY_DIR}/shine_cfgstub.c \\
-o ${CMAKE_CURRENT_BINARY_DIR}/shine_cfgstub.o
")
add_custom_command(
Expand Down Expand Up @@ -583,7 +593,7 @@ export PATH=${_tc_dir}:\$PATH
CC=\"${_ff_cc}\"
mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/vo-aacenc-obj
for f in ${_vo_aacenc_srclist}; do
\$CC -O2 -DNDEBUG -fPIC -mlongcalls -mtext-section-literals -D__unused= \\
\$CC -O2 -DNDEBUG ${_ff_pic_cflag} -ffunction-sections -fdata-sections -fvisibility=hidden -mlongcalls -mtext-section-literals -D__unused= \\
-I${VO_AACENC_SRC}/aacenc/inc \\
-I${VO_AACENC_SRC}/aacenc/basic_op \\
-I${VO_AACENC_SRC}/common/include \\
Expand All @@ -606,17 +616,40 @@ cp ${VO_AACENC_SRC}/common/include/*.h ${VO_AACENC_INSTALL}/include/vo-aacenc/
endif()

# --- 4. Configure + make + install (out-of-tree; source must be clean) ---
set(FFMPEG_EXT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/ffmpeg-build" CACHE INTERNAL "ffmpeg_ext build dir")
set(FFMPEG_CC_FF "${_ff_cc_ff}" CACHE INTERNAL "ffmpeg C compiler command")
set(FFMPEG_EXTRA_CFLAGS "${_ff_extra_cflags}" CACHE INTERNAL "ffmpeg extra cflags")
set(FFMPEG_CROSS_PREFIX "${_ff_cross_prefix}" CACHE INTERNAL "ffmpeg cross prefix")

set(_ff_byproducts
${FFMPEG_INSTALL_DIR}/lib/libavcodec.a
${FFMPEG_INSTALL_DIR}/lib/libavcodec_noco.a
${FFMPEG_INSTALL_DIR}/lib/libavutil.a
${FFMPEG_INSTALL_DIR}/lib/libswresample.a)
set(_ff_noco_cmds
COMMAND ${CMAKE_COMMAND} -E copy
${FFMPEG_INSTALL_DIR}/lib/libavcodec.a
${FFMPEG_INSTALL_DIR}/lib/libavcodec_noco.a
COMMAND ${_ff_cross_prefix}ar d
${FFMPEG_INSTALL_DIR}/lib/libavcodec_noco.a
allcodecs.o parsers.o)
if(CONFIG_FFMPEG_BUILD_AVFILTER)
list(APPEND _ff_byproducts ${FFMPEG_INSTALL_DIR}/lib/libavfilter.a)
list(APPEND _ff_byproducts
${FFMPEG_INSTALL_DIR}/lib/libavfilter.a
${FFMPEG_INSTALL_DIR}/lib/libavfilter_noco.a)
list(APPEND _ff_noco_cmds
COMMAND ${CMAKE_COMMAND} -E copy
${FFMPEG_INSTALL_DIR}/lib/libavfilter.a
${FFMPEG_INSTALL_DIR}/lib/libavfilter_noco.a
COMMAND ${_ff_cross_prefix}ar d
${FFMPEG_INSTALL_DIR}/lib/libavfilter_noco.a
allfilters.o)
endif()

ExternalProject_Add(ffmpeg_ext
DEPENDS ${_ff_shine_dep} ${_ff_vo_aacenc_dep}
SOURCE_DIR "${SOF_FFMPEG_SRC_DIR}"
BINARY_DIR "${FFMPEG_EXT_BUILD_DIR}"
BUILD_IN_SOURCE 0
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env ${_ff_cfg_env}
Expand All @@ -639,13 +672,14 @@ ExternalProject_Add(ffmpeg_ext
${_ff_dec_cfg}
${_ff_enc_cfg}
${_ff_shine_cfg}
--enable-small --enable-pic --enable-hardcoded-tables
--enable-small ${_ff_pic_cfg} --enable-hardcoded-tables
"--extra-cflags=${_ff_extra_cflags}"
${_ff_flacenc_prep}
BUILD_COMMAND
${CMAKE_COMMAND} -E env "PATH=${_tc_dir}:$ENV{PATH}" make -j 8
INSTALL_COMMAND make install
${_ff_cold_rename}
${_ff_noco_cmds}
BUILD_BYPRODUCTS
${_ff_byproducts}
)
Expand Down
Loading
Loading