diff --git a/app/Kconfig b/app/Kconfig index 339a16bed3e8..32cdb5d438dc 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -1,6 +1,9 @@ config SCHED_CPU_MASK_PIN_ONLY default y if SMP +config LLEXT_HEAP_SIZE + default 32 if COMP_FFMPEG_DEC = m && LLEXT_TYPE_ELF_RELOCATABLE + # Allow compiler to determine whether to generate FLIX instructions. choice COMPILER_CODEGEN_VLIW default COMPILER_CODEGEN_VLIW_AUTO if "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "xt-clang" diff --git a/scripts/cmake/uuid-registry.cmake b/scripts/cmake/uuid-registry.cmake index 0d3b287a7d62..41661e83d2a5 100644 --- a/scripts/cmake/uuid-registry.cmake +++ b/scripts/cmake/uuid-registry.cmake @@ -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}) diff --git a/scripts/llext_link_helper.py b/scripts/llext_link_helper.py index 727234654334..a52899d677d9 100755 --- a/scripts/llext_link_helper.py +++ b/scripts/llext_link_helper.py @@ -36,6 +36,10 @@ def parse_args(): help='.text section address') parser.add_argument("-s", "--size-file", required=True, type=str, help='File with stored accumulated size') + parser.add_argument("-e", "--end-addr", required=False, type=str, + help='Optional exclusive region end address for top-down placement') + parser.add_argument("-r", "--reset", action="store_true", + help='Ignore any existing size file and start at text-addr') args = parser.parse_args() @@ -211,11 +215,14 @@ def main(): # Get the size of the previous module, if this isn't the first one. # It is used to automatically calculate starting address of the current # module. - try: - with open(args.size_file, 'r') as f_size: - size = int(f_size.read().strip(), base = 0) - except OSError: + if args.reset: size = 0 + else: + try: + with open(args.size_file, 'r') as f_size: + size = int(f_size.read().strip(), base = 0) + except OSError: + size = 0 text_addr = int(args.text_addr, 0) + size text_size = 0 @@ -297,6 +304,36 @@ def main(): if not text_found: raise RuntimeError('No .text section found in the object file') + if args.end_addr: + end_addr = int(args.end_addr, 0) + text_align = next(s.header['sh_addralign'] + for s in elf.iter_sections() + if s.name == '.text' and (s.header['sh_flags'] & SH_FLAGS.SHF_ALLOC)) + max_align = max([0x1000, text_align] + + [s.header['sh_addralign'] for s in readonly + writable]) + + def _compute_end(base): + t_addr = max_alignment(base, 0x1000, text_align) + cur = align_up(t_addr + text_size, 0x1000) + for sec in readonly: + cur = align_up(cur, sec.header['sh_addralign']) + sec.header['sh_size'] + cur = align_up(cur, 0x1000) + for sec in writable: + cur = align_up(cur, sec.header['sh_addralign']) + sec.header['sh_size'] + return align_up(cur, 0x1000) + + span = _compute_end(text_addr) - text_addr + top_base = (end_addr - span) & ~(max_align - 1) + top_end = _compute_end(top_base) + if top_end > end_addr: + top_base -= align_up(top_end - end_addr, max_align) + if top_base < text_addr: + print(f'llext_link_helper.py: WARNING: {module} top-down base 0x{top_base:x} ' + f'overlaps modules ending at 0x{text_addr:x}', file=sys.stderr) + text_addr = max_alignment(top_base, 0x1000, text_align) + command = [c for c in command if not c.startswith('-Wl,-Ttext=')] + command.append(f'-Wl,-Ttext=0x{text_addr:x}') + # The original LLEXT support in SOF linked all LLEXT modules with pre- # calculated addresses. Such modules can only be used at those exact # addresses, so we map memory buffers for such modules to those diff --git a/scripts/llext_offset_calc.py b/scripts/llext_offset_calc.py index 0f302a8cbe12..3500d2e8daf4 100755 --- a/scripts/llext_offset_calc.py +++ b/scripts/llext_offset_calc.py @@ -20,6 +20,8 @@ def parse_args(): help='Object file name') parser.add_argument("-s", "--size-file", required=True, type=str, help='File to store accumulated size') + parser.add_argument("-r", "--reset", action="store_true", + help='Reset accumulated size before adding this module') args = parser.parse_args() @@ -58,11 +60,14 @@ def main(): f_output = pathlib.Path(args.size_file) - try: - with open(f_output, 'r') as f_size: - size = int(f_size.read().strip(), base = 0) - except OSError: + if args.reset: size = 0 + else: + try: + with open(f_output, 'r') as f_size: + size = int(f_size.read().strip(), base = 0) + except OSError: + size = 0 size += get_elf_size(args.input) + 0xfff # align to a page border diff --git a/src/audio/ffmpeg_dec/CMakeLists.txt b/src/audio/ffmpeg_dec/CMakeLists.txt index a598e942d5fa..5130c563e680 100644 --- a/src/audio/ffmpeg_dec/CMakeLists.txt +++ b/src/audio/ffmpeg_dec/CMakeLists.txt @@ -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) @@ -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 diff --git a/src/audio/ffmpeg_dec/ffmpeg-encode.c b/src/audio/ffmpeg_dec/ffmpeg-encode.c index 495b23734c4f..489d76138e8d 100644 --- a/src/audio/ffmpeg_dec/ffmpeg-encode.c +++ b/src/audio/ffmpeg_dec/ffmpeg-encode.c @@ -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 #include #include #include @@ -19,7 +20,11 @@ #include #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 @@ -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, @@ -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) @@ -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 +#include +#include + +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 */ diff --git a/src/audio/ffmpeg_dec/ffmpeg-filter.c b/src/audio/ffmpeg_dec/ffmpeg-filter.c index 87469ac928b0..e241abcaf252 100644 --- a/src/audio/ffmpeg_dec/ffmpeg-filter.c +++ b/src/audio/ffmpeg_dec/ffmpeg-filter.c @@ -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 #include #include #include @@ -32,7 +33,11 @@ #include #include +#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 @@ -52,7 +57,8 @@ 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", @@ -60,7 +66,8 @@ static const struct ffmpeg_af_filter_desc ffmpeg_af_filters[] = { .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", @@ -943,3 +950,63 @@ int ffmpeg_af_mod_free(struct processing_module *mod) md->private = NULL; return 0; } + +#ifdef FFMPEG_MOD_ROLE_AF +#include +#include +#include + +__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 */ diff --git a/src/audio/ffmpeg_dec/ffmpeg.cmake b/src/audio/ffmpeg_dec/ffmpeg.cmake index f06c95456fde..49f69c89e6c0 100644 --- a/src/audio/ffmpeg_dec/ffmpeg.cmake +++ b/src/audio/ffmpeg_dec/ffmpeg.cmake @@ -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, @@ -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( @@ -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 \\ @@ -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} @@ -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} ) diff --git a/src/audio/ffmpeg_dec/ffmpeg_common.c b/src/audio/ffmpeg_dec/ffmpeg_common.c new file mode 100644 index 000000000000..669c1cd16fb1 --- /dev/null +++ b/src/audio/ffmpeg_dec/ffmpeg_common.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. +// +// Shared buffer, extradata, ID3v2, and IPC4 EOS helpers across FFmpeg +// decoder, encoder, and audio-filter modules. + +#include +#include +#include +#include +#include +#include +#include "ffmpeg_dec.h" + +#if CONFIG_IPC_MAJOR_4 +#include +#include +#include +#include +#endif + +LOG_MODULE_DECLARE(ffmpeg_dec, CONFIG_SOF_LOG_LEVEL); + +static inline size_t ffmpeg_common_min(size_t a, size_t b) +{ + return a < b ? a : b; +} + +#if CONFIG_IPC_MAJOR_4 +__cold struct ipc_msg *ffmpeg_dec_eos_notification_init(struct processing_module *mod) +{ + struct comp_ipc_config *ipc_config = &mod->dev->ipc_config; + struct sof_ipc4_notify_module_data *msg_data; + union ipc4_notification_header primary; + struct ipc_msg *msg; + + primary.dat = 0; + primary.r.notif_type = SOF_IPC4_MODULE_NOTIFICATION; + primary.r.type = SOF_IPC4_GLB_NOTIFICATION; + primary.r.rsp = SOF_IPC4_MESSAGE_DIR_MSG_REQUEST; + primary.r.msg_tgt = SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG; + + msg = mod_ipc_msg_w_ext_init(mod, primary.dat, 0, sizeof(*msg_data)); + if (!msg) + return NULL; + + msg_data = (struct sof_ipc4_notify_module_data *)msg->tx_data; + msg_data->instance_id = IPC4_INST_ID(ipc_config->id); + msg_data->module_id = IPC4_MOD_ID(ipc_config->id); + msg_data->event_id = SOF_IPC4_NOTIFY_MODULE_EVENTID_COMPR_MAGIC_VAL; + msg_data->event_data_size = 0; + + return msg; +} + +void ffmpeg_dec_signal_eos(struct processing_module *mod, struct sof_sink *sink) +{ + struct ffmpeg_dec_comp_data *cd = module_get_private_data(mod); + + if (cd->eos_sent || !cd->eos_msg) + return; + + ipc_msg_send(cd->eos_msg, NULL, false); + cd->eos_sent = true; + audio_buffer_set_eos(sof_audio_buffer_from_sink(sink)); + comp_info(mod->dev, "EOS: compress drain complete"); +} +#endif /* CONFIG_IPC_MAJOR_4 */ + +int ffmpeg_dec_store_extradata(struct processing_module *mod, + const uint8_t *data, size_t size) +{ + struct ffmpeg_dec_comp_data *cd = module_get_private_data(mod); + struct comp_dev *dev = mod->dev; + + if (!size) + return 0; + + if (size > FFMPEG_DEC_MAX_EXTRADATA) { + comp_err(dev, "extradata too large: %zu", size); + return -EINVAL; + } + + memcpy_s(cd->extradata, sizeof(cd->extradata), data, size); + cd->extradata_size = size; + comp_info(dev, "stored %zu bytes of codec extradata", size); + return 0; +} + +void ffmpeg_dec_copy_from_circular(void *dst, const void *src, + const void *buf_start, size_t buf_size, + size_t bytes) +{ + size_t to_end = (size_t)((const uint8_t *)buf_start + buf_size - + (const uint8_t *)src); + + if (to_end >= bytes) { + memcpy_s(dst, bytes, src, bytes); + return; + } + memcpy_s(dst, to_end, src, to_end); + memcpy_s((uint8_t *)dst + to_end, bytes - to_end, + buf_start, bytes - to_end); +} + +void ffmpeg_dec_copy_to_circular(void *dst, void *buf_start, + size_t buf_size, const void *src, + size_t bytes) +{ + size_t to_end = (size_t)((uint8_t *)buf_start + buf_size - + (uint8_t *)dst); + + if (to_end >= bytes) { + memcpy_s(dst, bytes, src, bytes); + return; + } + memcpy_s(dst, to_end, src, to_end); + memcpy_s(buf_start, bytes - to_end, + (const uint8_t *)src + to_end, bytes - to_end); +} + +int ffmpeg_dec_skip_id3v2(struct processing_module *mod, struct sof_source *src) +{ + struct ffmpeg_dec_comp_data *cd = module_get_private_data(mod); + struct comp_dev *dev = mod->dev; + const void *sp, *sstart; + size_t sbytes, avail, req; + int ret; + + /* Drain any pending skip bytes from a previous chunk */ + if (cd->skip_bytes > 0) { + avail = source_get_data_available(src); + if (!avail) + return -ENODATA; + size_t to_skip = ffmpeg_common_min(avail, cd->skip_bytes); + + source_drop_data(src, to_skip); + cd->skip_bytes -= to_skip; + if (cd->skip_bytes > 0) + return -ENODATA; + } + + avail = source_get_data_available(src); + if (avail < 4) + return -ENODATA; + + req = ffmpeg_common_min(avail, cd->in_buf_size); + ret = source_get_data(src, req, &sp, &sstart, &sbytes); + if (ret) + return ret; + ffmpeg_dec_copy_from_circular(cd->in_buf, sp, sstart, sbytes, req); + source_release_data(src, 0); + + /* ID3v2 tag: 10-byte header with 28-bit syncsafe length */ + if (memcmp(cd->in_buf, "ID3", 3) == 0) { + uint32_t tag; + size_t total_tag; + + if (req < 10) + return -ENODATA; + + tag = ((uint32_t)(cd->in_buf[6] & 0x7f) << 21) | + ((uint32_t)(cd->in_buf[7] & 0x7f) << 14) | + ((uint32_t)(cd->in_buf[8] & 0x7f) << 7) | + (uint32_t)(cd->in_buf[9] & 0x7f); + total_tag = 10 + tag + ((cd->in_buf[5] & 0x10) ? 10 : 0); + comp_info(dev, "ID3v2 tag detected: %zu bytes", total_tag); + + if (avail >= total_tag) { + source_drop_data(src, total_tag); + return 1; + } + + source_drop_data(src, avail); + cd->skip_bytes = total_tag - avail; + return -ENODATA; + } + + return 0; +} diff --git a/src/audio/ffmpeg_dec/ffmpeg_dec-shims.c b/src/audio/ffmpeg_dec/ffmpeg_dec-shims.c index 11770a2f031c..426ebe6099ef 100644 --- a/src/audio/ffmpeg_dec/ffmpeg_dec-shims.c +++ b/src/audio/ffmpeg_dec/ffmpeg_dec-shims.c @@ -405,11 +405,18 @@ unsigned long strtoul(const char *nptr, char **endptr, int base) /* * Double-precision libm is provided by the real newlib math archive * (libnewlib_m.a, see llext/CMakeLists.txt). newlib math functions report - * domain/range errors through *__errno(). + * domain/range errors through *__errno(), and picolibc inline + * accesses *z_errno_wrap() from libavutil objects. */ +static int llext_errno; + int *__errno(void) { - static int llext_errno; + return &llext_errno; +} + +int *z_errno_wrap(void) +{ return &llext_errno; } diff --git a/src/audio/ffmpeg_dec/ffmpeg_dec.c b/src/audio/ffmpeg_dec/ffmpeg_dec.c index d551ffdffadd..453f696f6282 100644 --- a/src/audio/ffmpeg_dec/ffmpeg_dec.c +++ b/src/audio/ffmpeg_dec/ffmpeg_dec.c @@ -9,6 +9,7 @@ // ffmpeg_dec-stub.c and ffmpeg_dec-ffmpeg.c). The input is a compressed audio // elementary stream (raw data), the output is interleaved PCM. +#include #include #include #include @@ -26,195 +27,35 @@ #include #endif +#if !CONFIG_COMP_FFMPEG_DEC_MODULE /* UUID identifies the component. Registered in uuid-registry.txt. */ SOF_DEFINE_REG_UUID(ffmpeg_dec); +#endif /* Creates logging data for the component */ LOG_MODULE_REGISTER(ffmpeg_dec, CONFIG_SOF_LOG_LEVEL); -#if CONFIG_IPC_MAJOR_4 -/* - * Build the module notification the driver expects to unblock compress_drain(). - * The kernel's compress EOS handler (sof_ipc4_compr_drain_done) matches on the - * COMPR "magic" event id, so use the same template the Cadence decoder does. - */ -__cold struct ipc_msg *ffmpeg_dec_eos_notification_init(struct processing_module *mod) -{ - struct comp_ipc_config *ipc_config = &mod->dev->ipc_config; - struct sof_ipc4_notify_module_data *msg_data; - union ipc4_notification_header primary; - struct ipc_msg *msg; - - primary.dat = 0; - primary.r.notif_type = SOF_IPC4_MODULE_NOTIFICATION; - primary.r.type = SOF_IPC4_GLB_NOTIFICATION; - primary.r.rsp = SOF_IPC4_MESSAGE_DIR_MSG_REQUEST; - primary.r.msg_tgt = SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG; - - msg = mod_ipc_msg_w_ext_init(mod, primary.dat, 0, sizeof(*msg_data)); - if (!msg) - return NULL; - - msg_data = (struct sof_ipc4_notify_module_data *)msg->tx_data; - msg_data->instance_id = IPC4_INST_ID(ipc_config->id); - msg_data->module_id = IPC4_MOD_ID(ipc_config->id); - msg_data->event_id = SOF_IPC4_NOTIFY_MODULE_EVENTID_COMPR_MAGIC_VAL; - msg_data->event_data_size = 0; - - return msg; -} - -/* - * Report that the compress drain is complete: send the EOS notification (which - * unblocks the host's compress_drain()) exactly once, and mark the sink so the - * end-of-stream state propagates downstream to the DAI. - */ -void ffmpeg_dec_signal_eos(struct processing_module *mod, struct sof_sink *sink) -{ - struct ffmpeg_dec_comp_data *cd = module_get_private_data(mod); - - if (cd->eos_sent || !cd->eos_msg) - return; - - ipc_msg_send(cd->eos_msg, NULL, false); - cd->eos_sent = true; - audio_buffer_set_eos(sof_audio_buffer_from_sink(sink)); - comp_info(mod->dev, "EOS: compress drain complete"); -} -#endif /* CONFIG_IPC_MAJOR_4 */ - -/* Decoder-mode ops (compressed -> PCM). */ -int ffmpeg_dec_store_extradata(struct processing_module *mod, - const uint8_t *data, size_t size) -{ - struct ffmpeg_dec_comp_data *cd = module_get_private_data(mod); - struct comp_dev *dev = mod->dev; - - if (!size) - return 0; - - if (size > FFMPEG_DEC_MAX_EXTRADATA) { - comp_err(dev, "extradata too large: %zu", size); - return -EINVAL; - } - - memcpy_s(cd->extradata, sizeof(cd->extradata), data, size); - cd->extradata_size = size; - comp_info(dev, "stored %zu bytes of codec extradata", size); - return 0; -} +#if defined(CONFIG_FFMPEG_ENC) && !defined(FFMPEG_MOD_ROLE_DEC) +#define FFMPEG_DEC_ENABLE_ENC 1 +#endif +#if defined(CONFIG_FFMPEG_FILTER) && !defined(FFMPEG_MOD_ROLE_DEC) +#define FFMPEG_DEC_ENABLE_FILTER 1 +#endif static inline size_t ffmpeg_dec_min(size_t a, size_t b) { return a < b ? a : b; } -/* Copy @bytes out of a circular source buffer (starting at @src) into the - * linear @dst, wrapping at the buffer end if necessary. - */ -void ffmpeg_dec_copy_from_circular(void *dst, const void *src, - const void *buf_start, size_t buf_size, - size_t bytes) -{ - size_t to_end = (size_t)((const uint8_t *)buf_start + buf_size - - (const uint8_t *)src); - - if (to_end >= bytes) { - memcpy_s(dst, bytes, src, bytes); - return; - } - memcpy_s(dst, to_end, src, to_end); - memcpy_s((uint8_t *)dst + to_end, bytes - to_end, - buf_start, bytes - to_end); -} - -/* Copy @bytes from the linear @src into a circular sink buffer (starting at - * @dst), wrapping at the buffer end if necessary. - */ -void ffmpeg_dec_copy_to_circular(void *dst, void *buf_start, - size_t buf_size, const void *src, - size_t bytes) -{ - size_t to_end = (size_t)((uint8_t *)buf_start + buf_size - - (uint8_t *)dst); - - if (to_end >= bytes) { - memcpy_s(dst, bytes, src, bytes); - return; - } - memcpy_s(dst, to_end, src, to_end); - memcpy_s(buf_start, bytes - to_end, - (const uint8_t *)src + to_end, bytes - to_end); -} - -/* - * Peek at the start of the stream and skip a leading ID3v2 tag if present. - * Returns: - * 1 if an ID3v2 tag was completely skipped (caller should re-check), - * 0 if the stream does not start with an ID3v2 tag (cd->in_buf holds the - * peeked header bytes), - * -ENODATA while waiting for enough bytes to inspect or finish skipping. - */ -int ffmpeg_dec_skip_id3v2(struct processing_module *mod, struct sof_source *src) -{ - struct ffmpeg_dec_comp_data *cd = module_get_private_data(mod); - struct comp_dev *dev = mod->dev; - const void *sp, *sstart; - size_t sbytes, avail, req; - int ret; - - /* Drain any pending skip bytes from a previous chunk */ - if (cd->skip_bytes > 0) { - avail = source_get_data_available(src); - if (!avail) - return -ENODATA; - size_t to_skip = ffmpeg_dec_min(avail, cd->skip_bytes); - - source_drop_data(src, to_skip); - cd->skip_bytes -= to_skip; - if (cd->skip_bytes > 0) - return -ENODATA; - } - - avail = source_get_data_available(src); - if (avail < 4) - return -ENODATA; - - req = ffmpeg_dec_min(avail, cd->in_buf_size); - ret = source_get_data(src, req, &sp, &sstart, &sbytes); - if (ret) - return ret; - ffmpeg_dec_copy_from_circular(cd->in_buf, sp, sstart, sbytes, req); - source_release_data(src, 0); - - /* ID3v2 tag: 10-byte header with 28-bit syncsafe length */ - if (memcmp(cd->in_buf, "ID3", 3) == 0) { - uint32_t tag; - size_t total_tag; - - if (req < 10) - return -ENODATA; - - tag = ((uint32_t)(cd->in_buf[6] & 0x7f) << 21) | - ((uint32_t)(cd->in_buf[7] & 0x7f) << 14) | - ((uint32_t)(cd->in_buf[8] & 0x7f) << 7) | - (uint32_t)(cd->in_buf[9] & 0x7f); - total_tag = 10 + tag + ((cd->in_buf[5] & 0x10) ? 10 : 0); - comp_info(dev, "ID3v2 tag detected: %zu bytes", total_tag); - - if (avail >= total_tag) { - source_drop_data(src, total_tag); - return 1; - } - - source_drop_data(src, avail); - cd->skip_bytes = total_tag - avail; - return -ENODATA; - } - - return 0; -} - +#ifdef FFMPEG_MOD_ROLE_DEC +#ifndef FFMPEG_MOD_BESPOKE +#define FFMPEG_MOD_BESPOKE 0 +#endif +extern const struct ffmpeg_dec_codec_ops FFMPEG_MOD_CODEC_OPS; +static const struct ffmpeg_dec_codec_ops * const ffmpeg_dec_codecs[] = { + &FFMPEG_MOD_CODEC_OPS, +}; +#else static const struct ffmpeg_dec_codec_ops * const ffmpeg_dec_codecs[] = { #if defined(CONFIG_FFMPEG_DEC_FLAC) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) &ffmpeg_dec_flac_ops, @@ -262,6 +103,7 @@ static const struct ffmpeg_dec_codec_ops *ffmpeg_dec_find_codec_ops(enum ffmpeg_ } return NULL; } +#endif /* FFMPEG_MOD_ROLE_DEC */ #if CONFIG_IPC_MAJOR_4 static const struct ffmpeg_dec_codec_ops * @@ -332,7 +174,7 @@ __cold static int ffmpeg_dec_init(struct processing_module *mod) } if (direction == SOF_IPC_STREAM_CAPTURE) { -#if defined(CONFIG_FFMPEG_ENC) +#ifdef FFMPEG_DEC_ENABLE_ENC return ffmpeg_enc_mod_init(mod); #else comp_err(dev, "capture (encode) requested but no encoders enabled"); @@ -344,14 +186,14 @@ __cold static int ffmpeg_dec_init(struct processing_module *mod) return -EINVAL; } if (codec_params->id == SND_AUDIOCODEC_PCM) { -#if defined(CONFIG_FFMPEG_FILTER) +#ifdef FFMPEG_DEC_ENABLE_FILTER return ffmpeg_af_mod_init(mod); #else comp_err(dev, "PCM filter requested but no filters enabled"); return -ENOTSUP; #endif } -#if defined(CONFIG_FFMPEG_FILTER) +#ifdef FFMPEG_DEC_ENABLE_FILTER } else { return ffmpeg_af_mod_init(mod); #endif @@ -364,8 +206,13 @@ __cold static int ffmpeg_dec_init(struct processing_module *mod) md->private = cd; cd->backend = &ffmpeg_dec_backend; +#ifdef FFMPEG_MOD_ROLE_DEC + cd->codec_ops = &FFMPEG_MOD_CODEC_OPS; + cd->codec = cd->codec_ops->id; +#else cd->codec = FFMPEG_DEC_DEFAULT_CODEC; cd->codec_ops = ffmpeg_dec_find_codec_ops(cd->codec); +#endif #if CONFIG_IPC_MAJOR_4 if (mod->priv.cfg.ext_data && @@ -480,12 +327,12 @@ static int ffmpeg_dec_prepare(struct processing_module *mod, comp_dbg(dev, "entry"); -#if defined(CONFIG_FFMPEG_ENC) +#ifdef FFMPEG_DEC_ENABLE_ENC if (cd && cd->is_encoder) return ffmpeg_enc_mod_prepare(mod, sources, num_of_sources, sinks, num_of_sinks); #endif -#if defined(CONFIG_FFMPEG_FILTER) +#ifdef FFMPEG_DEC_ENABLE_FILTER if (cd && cd->is_filter) return ffmpeg_af_mod_prepare(mod, sources, num_of_sources, sinks, num_of_sinks); @@ -613,12 +460,12 @@ static bool ffmpeg_dec_is_ready_to_process(struct processing_module *mod, { struct ffmpeg_dec_comp_data *cd = module_get_private_data(mod); -#if defined(CONFIG_FFMPEG_ENC) +#ifdef FFMPEG_DEC_ENABLE_ENC if (cd && cd->is_encoder) return ffmpeg_enc_is_ready_to_process(mod, sources, num_of_sources, sinks, num_of_sinks); #endif -#if defined(CONFIG_FFMPEG_FILTER) +#ifdef FFMPEG_DEC_ENABLE_FILTER if (cd && cd->is_filter) return ffmpeg_af_is_ready_to_process(mod, sources, num_of_sources, sinks, num_of_sinks); @@ -686,12 +533,12 @@ static int ffmpeg_dec_process(struct processing_module *mod, size_t consumed = 0, produced = 0; int ret; -#if defined(CONFIG_FFMPEG_ENC) +#ifdef FFMPEG_DEC_ENABLE_ENC if (cd && cd->is_encoder) return ffmpeg_enc_mod_process(mod, sources, num_of_sources, sinks, num_of_sinks); #endif -#if defined(CONFIG_FFMPEG_FILTER) +#ifdef FFMPEG_DEC_ENABLE_FILTER if (cd && cd->is_filter) return ffmpeg_af_mod_process(mod, sources, num_of_sources, sinks, num_of_sinks); @@ -943,7 +790,7 @@ ffmpeg_dec_set_config(struct processing_module *mod, uint32_t config_id, return 0; } -#if defined(CONFIG_FFMPEG_FILTER) +#ifdef FFMPEG_DEC_ENABLE_FILTER { struct ffmpeg_dec_comp_data *cd = module_get_private_data(mod); @@ -969,11 +816,11 @@ static int ffmpeg_dec_reset(struct processing_module *mod) comp_dbg(mod->dev, "entry"); -#if defined(CONFIG_FFMPEG_ENC) +#ifdef FFMPEG_DEC_ENABLE_ENC if (cd && cd->is_encoder) return ffmpeg_enc_mod_reset(mod); #endif -#if defined(CONFIG_FFMPEG_FILTER) +#ifdef FFMPEG_DEC_ENABLE_FILTER if (cd && cd->is_filter) return ffmpeg_af_mod_reset(mod); #endif @@ -1012,11 +859,11 @@ __cold static int ffmpeg_dec_free(struct processing_module *mod) assert_can_be_cold(); comp_dbg(mod->dev, "entry"); -#if defined(CONFIG_FFMPEG_ENC) +#ifdef FFMPEG_DEC_ENABLE_ENC if (cd && cd->is_encoder) return ffmpeg_enc_mod_free(mod); #endif -#if defined(CONFIG_FFMPEG_FILTER) +#ifdef FFMPEG_DEC_ENABLE_FILTER if (cd && cd->is_filter) return ffmpeg_af_mod_free(mod); #endif @@ -1049,6 +896,106 @@ static const struct module_interface ffmpeg_dec_interface = { .free = ffmpeg_dec_free }; +static const uint32_t ffmpeg_dec_codec_info_items[] +#if CONFIG_COMP_FFMPEG_DEC_MODULE + __section(SOF_CODEC_INFO_SECTION) __used FFMPEG_SECTION_RETAIN +#endif + = { +#ifdef FFMPEG_MOD_ROLE_DEC + SOF_CODEC_INFO_ITEM(FFMPEG_MOD_SND_CODEC_ID, SOF_IPC_STREAM_PLAYBACK), +#if FFMPEG_MOD_BESPOKE + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_PLAYBACK), +#endif +#else +#if defined(CONFIG_FFMPEG_FILTER) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_PCM, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_DEC_FLAC) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_FLAC, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_DEC_ALAC) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_ALAC, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_DEC_AAC) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_AAC, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_DEC_MP3) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_MP3, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_ENC_MP3) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_MP3, SOF_IPC_STREAM_CAPTURE), +#endif +#if defined(CONFIG_FFMPEG_ENC_AAC) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_AAC, SOF_IPC_STREAM_CAPTURE), +#endif +#if defined(CONFIG_FFMPEG_ENC_FLAC) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_FLAC, SOF_IPC_STREAM_CAPTURE), +#endif +#if defined(CONFIG_FFMPEG_ENC_ALAC) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_ALAC, SOF_IPC_STREAM_CAPTURE), +#endif +#if defined(CONFIG_FFMPEG_DEC_SBC) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_SBC, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_ENC_SBC) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_SBC, SOF_IPC_STREAM_CAPTURE), +#endif +#if defined(CONFIG_FFMPEG_DEC_G722) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_G722, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_ENC_G722) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_G722, SOF_IPC_STREAM_CAPTURE), +#endif +#if defined(CONFIG_FFMPEG_DEC_APTX) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_APTX, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_ENC_APTX) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_APTX, SOF_IPC_STREAM_CAPTURE), +#endif +#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 +#if defined(CONFIG_FFMPEG_ENC_SBC) || defined(CONFIG_FFMPEG_ENC_G722) || \ + defined(CONFIG_FFMPEG_ENC_APTX) || defined(CONFIG_FFMPEG_ENC_APTX_HD) || \ + defined(CONFIG_FFMPEG_ENC_G726) || defined(CONFIG_FFMPEG_ENC_ALAW) || \ + defined(CONFIG_FFMPEG_ENC_MULAW) + /* Also advertise BESPOKE capture for kernels with older SND_AUDIOCODEC_MAX. */ + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_CAPTURE), +#endif +#if defined(CONFIG_FFMPEG_DEC_OPUS) || defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_OPUS_RAW, SOF_IPC_STREAM_PLAYBACK), +#endif +#if defined(CONFIG_FFMPEG_DEC_OPUS) || defined(CONFIG_FFMPEG_DEC_SBC) || \ + defined(CONFIG_FFMPEG_DEC_G722) || defined(CONFIG_FFMPEG_DEC_APTX) || \ + defined(CONFIG_FFMPEG_DEC_APTX_HD) || defined(CONFIG_FFMPEG_DEC_G726) || \ + defined(CONFIG_FFMPEG_DEC_ALAW) || defined(CONFIG_FFMPEG_DEC_MULAW) || \ + defined(CONFIG_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_PLAYBACK), +#endif +#endif /* FFMPEG_MOD_ROLE_DEC */ +}; + /* If COMP_FFMPEG_DEC is =m in Kconfig this is built as a loadable LLEXT module. */ #if CONFIG_COMP_FFMPEG_DEC_MODULE @@ -1056,9 +1003,18 @@ static const struct module_interface ffmpeg_dec_interface = { #include #include -static const struct sof_man_module_manifest mod_manifest __section(".module") __used = +#ifdef FFMPEG_MOD_ROLE_DEC +#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_dec_interface, 1, + FFMPEG_REG_UUID(FFMPEG_MOD_UUID_SYM), 40); +#else +static const struct sof_man_module_manifest mod_manifest + __section(".module") __used FFMPEG_SECTION_RETAIN = SOF_LLEXT_MODULE_MANIFEST("FFMPGDEC", &ffmpeg_dec_interface, 1, SOF_REG_UUID(ffmpeg_dec), 40); +#endif SOF_LLEXT_BUILDINFO; @@ -1067,6 +1023,14 @@ SOF_LLEXT_BUILDINFO; /* Only used for the module adapter trace context, soon to be deprecated */ DECLARE_TR_CTX(ffmpeg_dec_tr, SOF_UUID(ffmpeg_dec_uuid), LOG_LEVEL_INFO); DECLARE_MODULE_ADAPTER(ffmpeg_dec_interface, ffmpeg_dec_uuid, ffmpeg_dec_tr); -SOF_MODULE_INIT(ffmpeg_dec, sys_comp_module_ffmpeg_dec_interface_init); + +static __maybe_unused void sys_comp_ffmpeg_dec_init(void) +{ + sys_comp_module_ffmpeg_dec_interface_init(); + sof_codec_info_add_items(&ffmpeg_dec_interface, ffmpeg_dec_codec_info_items, + ARRAY_SIZE(ffmpeg_dec_codec_info_items)); +} + +SOF_MODULE_INIT(ffmpeg_dec, sys_comp_ffmpeg_dec_init); #endif diff --git a/src/audio/ffmpeg_dec/ffmpeg_dec.h b/src/audio/ffmpeg_dec/ffmpeg_dec.h index 6864f71fff05..8f9c570a557b 100644 --- a/src/audio/ffmpeg_dec/ffmpeg_dec.h +++ b/src/audio/ffmpeg_dec/ffmpeg_dec.h @@ -420,4 +420,15 @@ void ffmpeg_dec_libc_bind(struct processing_module *mod); size_t ffmpeg_dec_heap_free(void); size_t ffmpeg_dec_heap_lastfail(void); /*DBG*/ +#ifndef FFMPEG_SECTION_RETAIN +#ifdef __has_attribute +#if __has_attribute(__retain__) +#define FFMPEG_SECTION_RETAIN __attribute__((__retain__)) +#endif +#endif +#ifndef FFMPEG_SECTION_RETAIN +#define FFMPEG_SECTION_RETAIN +#endif +#endif + #endif /* __SOF_AUDIO_FFMPEG_DEC_H__ */ diff --git a/src/audio/ffmpeg_dec/ffmpeg_mod.toml.in b/src/audio/ffmpeg_dec/ffmpeg_mod.toml.in new file mode 100644 index 000000000000..7bc0dfe8663b --- /dev/null +++ b/src/audio/ffmpeg_dec/ffmpeg_mod.toml.in @@ -0,0 +1,20 @@ +#include + + REM # FFmpeg individual audio module config (@FFMPEG_MOD_NAME@) + [[module.entry]] + name = "@FFMPEG_MOD_MANIFEST_NAME@" + uuid = @FFMPEG_MOD_UUID_MACRO@ + affinity_mask = "0x1" + instance_count = "40" + domain_types = "0" + load_type = "2" + module_type = "9" + auto_start = "0" + sched_caps = [1, 0x00008000] + pin = [0, 0, 0xfeef, 0xf, 0xf, 0x45ff, 1, 0, 0xfeef, 0xf, 0xf, 0x1ff] + mod_cfg = [0, 0, 0, 0, 8192, 5000000, @FFMPEG_MOD_IBS@, @FFMPEG_MOD_OBS@, 0, 5000, 0] + + index = __COUNTER__ + +[module] +count = __COUNTER__ diff --git a/src/audio/ffmpeg_dec/llext/CMakeLists.txt b/src/audio/ffmpeg_dec/llext/CMakeLists.txt index 8d43c1ea8db6..51db01bac132 100644 --- a/src/audio/ffmpeg_dec/llext/CMakeLists.txt +++ b/src/audio/ffmpeg_dec/llext/CMakeLists.txt @@ -2,9 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 if(CONFIG_COMP_FFMPEG_DEC_STUB) - # Dependency-free build: SOF glue + passthrough stub backend, no libavcodec. + # Dependency-free build: SOF glue + passthrough stub backend, standalone LLEXT. sof_llext_build("ffmpeg_dec" - SOURCES ../ffmpeg_dec.c + SOURCES ../ffmpeg_common.c + ../ffmpeg_dec.c ../ffmpeg_dec-flac.c ../ffmpeg_dec-mp3.c ../ffmpeg_dec-aac.c @@ -16,145 +17,354 @@ if(CONFIG_COMP_FFMPEG_DEC_STUB) ../ffmpeg_dec-g726.c ../ffmpeg_dec-g711.c ../ffmpeg_dec-stub.c - LIB openmodules ) + set(FFMPEG_LLEXT_TARGETS ffmpeg_dec PARENT_SCOPE) + return() +endif() + +# Real backends: cross-build FFmpeg, libshine, vo-aacenc, and newlib_m once, +# then link each enabled decoder, encoder, and filter as its own standalone +# .llext module (no LIB openmodules packing) with per-module registration tables +# so unused codecs are never pulled into the module. +set(_ff_root_dir "${CMAKE_CURRENT_LIST_DIR}/..") +set(_ff_llext_dir "${CMAKE_CURRENT_LIST_DIR}") +include("${_ff_root_dir}/ffmpeg.cmake") + +set(_ff_common_cflags "") +if(CONFIG_FFMPEG_DEC_COLD_SPLIT) + list(APPEND _ff_common_cflags -mlongcalls) else() - # Real decoder: cross-build the FFmpeg archive (Kconfig-selected decoders) - # and link it. libc/libm are NOT bundled (non-PIC, and would clash) — the - # module provides the needed libc symbols itself (shims/alloc), resolves the - # rest from the SOF core, and supplies fast single-precision float math - # (fastmathf.c) when a float codec (AAC/Opus) is selected. - include(${CMAKE_CURRENT_LIST_DIR}/../ffmpeg.cmake) + list(APPEND _ff_common_cflags -ffunction-sections -fdata-sections -fvisibility=hidden) +endif() +# Disable scalar hardware FP0 on Clang targets (CONFIG_FPU=n) so float +# conversions and strtod/strtof emit soft-float libcalls instead of +# faulting FP0 instructions. +if(CMAKE_C_COMPILER_ID MATCHES "Clang") + list(APPEND _ff_common_cflags "SHELL:-Xclang -target-feature -Xclang -fp") +endif() - set(ffmpeg_dec_srcs - ../ffmpeg_dec.c - ../ffmpeg_dec-ffmpeg.c - ../ffmpeg_dec-convert.c - ../ffmpeg-convert-hifi.c - ../ffmpeg_dec-shims.c - ../ffmpeg_dec-alloc.c) - if(CONFIG_FFMPEG_DEC_FLAC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-flac.c) - endif() - if(CONFIG_FFMPEG_DEC_MP3) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-mp3.c) - endif() - if(CONFIG_FFMPEG_DEC_AAC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-aac.c) - endif() - if(CONFIG_FFMPEG_DEC_OPUS) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-opus.c) - endif() - if(CONFIG_FFMPEG_DEC_ALAC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-alac.c) - endif() - if(CONFIG_FFMPEG_DEC_SBC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-sbc.c) - endif() - if(CONFIG_FFMPEG_DEC_G722) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-g722.c) - endif() - if(CONFIG_FFMPEG_DEC_APTX OR CONFIG_FFMPEG_DEC_APTX_HD) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-aptx.c) - endif() - if(CONFIG_FFMPEG_DEC_G726) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-g726.c) - endif() - if(CONFIG_FFMPEG_DEC_ALAW OR CONFIG_FFMPEG_DEC_MULAW) - list(APPEND ffmpeg_dec_srcs ../ffmpeg_dec-g711.c) +get_filename_component(_ff_libm_dir "${FFMPEG_TARGET_LIBM}" DIRECTORY) + +set(_ff_all_targets "") + +# Helper: generate per-module config header, codec/parser/filter registration +# lists + archive, llext.toml.h and CMakeLists.txt, and register sof_llext_build(). +function(_ffmpeg_add_llext_module mod_name) + set(options USE_FASTMATH USE_AVFILTER USE_SHINE USE_VOAACENC TOP_DOWN) + set(one_val ROLE MANIFEST_NAME UUID_SYM IBS OBS CODEC_OPS SND_ID BESPOKE AF_DEFINE) + set(multi_val SOURCES CODEC_SYMS PARSER_SYMS FILTER_SYMS EXTRA_DEPS) + cmake_parse_arguments(ARG "${options}" "${one_val}" "${multi_val}" ${ARGN}) + + set(_mod_src_dir "${CMAKE_CURRENT_BINARY_DIR}/mods/${mod_name}") + file(MAKE_DIRECTORY "${_mod_src_dir}/libavcodec" "${_mod_src_dir}/libavfilter") + + # 1. Generate TOML header from template + string(TOUPPER "${ARG_UUID_SYM}" _uuid_upper) + set(FFMPEG_MOD_NAME "${mod_name}") + set(FFMPEG_MOD_MANIFEST_NAME "${ARG_MANIFEST_NAME}") + set(FFMPEG_MOD_UUID_MACRO "UUIDREG_STR_${_uuid_upper}") + set(FFMPEG_MOD_IBS "${ARG_IBS}") + set(FFMPEG_MOD_OBS "${ARG_OBS}") + configure_file("${_ff_root_dir}/ffmpeg_mod.toml.in" + "${_mod_src_dir}/llext.toml.h" @ONLY) + + # 2. Generate per-module macro header (included via -imacros to avoid shell quoting) + set(_cfg_h "#ifndef _FFMPEG_MOD_CFG_H_\n#define _FFMPEG_MOD_CFG_H_\n") + if(ARG_ROLE STREQUAL "dec") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_ROLE_DEC 1\n") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_CODEC_OPS ${ARG_CODEC_OPS}\n") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_SND_CODEC_ID ${ARG_SND_ID}\n") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_BESPOKE ${ARG_BESPOKE}\n") + elseif(ARG_ROLE STREQUAL "enc") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_ROLE_ENC 1\n") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_CODEC_OPS ${ARG_CODEC_OPS}\n") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_SND_CODEC_ID ${ARG_SND_ID}\n") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_BESPOKE ${ARG_BESPOKE}\n") + elseif(ARG_ROLE STREQUAL "af") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_ROLE_AF 1\n") + set(_cfg_h "${_cfg_h}#define ${ARG_AF_DEFINE} 1\n") endif() - # fastmathf provides the single-precision libm the codecs need AND sofm_log2f - # used by the shims' log10(); always built for the real (non-stub) backend. - list(APPEND ffmpeg_dec_srcs ../fastmathf.c) + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_MANIFEST_NAME \"${ARG_MANIFEST_NAME}\"\n") + set(_cfg_h "${_cfg_h}#define FFMPEG_MOD_UUID_SYM ${ARG_UUID_SYM}\n") + set(_cfg_h "${_cfg_h}#endif\n") + file(WRITE "${_mod_src_dir}/ffmpeg_mod_cfg.h" "${_cfg_h}") - # avfilter graph backend (PCM effects, e.g. afftdn noise reduction). Pulls - # libavfilter into the link; it must precede the libs it depends on. - set(ffmpeg_dec_libs avcodec swresample avutil) - set(ffmpeg_dec_libpaths "${FFMPEG_INSTALL_DIR}/lib") - if(CONFIG_FFMPEG_FILTER) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-filter.c) + # 3. Generate per-module registration lists and static archive (lib_reg.a) + set(_reg_lib "") + set(_reg_dep "") + set(_need_reg FALSE) + set(_reg_cmds "") + set(_reg_objs "") + + if(ARG_CODEC_SYMS OR ARG_PARSER_SYMS) + set(_need_reg TRUE) + set(_c_decls "") + set(_c_list "") + foreach(_cs IN LISTS ARG_CODEC_SYMS) + set(_c_decls "${_c_decls}extern const FFCodec ${_cs};\n") + set(_c_list "${_c_list} &${_cs},\n") + endforeach() + set(_p_decls "") + set(_p_list "") + foreach(_ps IN LISTS ARG_PARSER_SYMS) + set(_p_decls "${_p_decls}extern const AVCodecParser ${_ps};\n") + set(_p_list "${_p_list} &${_ps},\n") + endforeach() + file(WRITE "${_mod_src_dir}/libavcodec/codec_list.c" + "${_c_decls}static const FFCodec * const codec_list[] = {\n${_c_list} NULL };\n") + file(WRITE "${_mod_src_dir}/libavcodec/parser_list.c" + "${_p_decls}static const AVCodecParser * const parser_list[] = {\n${_p_list} NULL };\n") + set(_reg_cmds "${_reg_cmds} +\$CC \$CFLAGS -c \"${SOF_FFMPEG_SRC_DIR}/libavcodec/allcodecs.c\" -o \"${_mod_src_dir}/allcodecs.o\" +\$CC \$CFLAGS -c \"${SOF_FFMPEG_SRC_DIR}/libavcodec/parsers.c\" -o \"${_mod_src_dir}/parsers.o\"") + set(_reg_objs "${_reg_objs} \"${_mod_src_dir}/allcodecs.o\" \"${_mod_src_dir}/parsers.o\"") endif() - if(CONFIG_FFMPEG_BUILD_AVFILTER) - set(ffmpeg_dec_libs avfilter ${ffmpeg_dec_libs}) + + if(ARG_USE_AVFILTER) + set(_need_reg TRUE) + set(_f_decls "") + set(_f_list "") + foreach(_fs IN LISTS ARG_FILTER_SYMS) + set(_f_decls "${_f_decls}extern const AVFilter ${_fs};\n") + set(_f_list "${_f_list} &${_fs},\n") + endforeach() + file(WRITE "${_mod_src_dir}/libavfilter/filter_list.c" + "${_f_decls}static const AVFilter * const filter_list[] = {\n${_f_list} NULL };\n") + set(_reg_cmds "${_reg_cmds} +\$CC \$CFLAGS -c \"${SOF_FFMPEG_SRC_DIR}/libavfilter/allfilters.c\" -o \"${_mod_src_dir}/allfilters.o\"") + set(_reg_objs "${_reg_objs} \"${_mod_src_dir}/allfilters.o\"") endif() - # Encode support: PCM->compressed backend + libshine / vo-aacenc archives - # (linked AFTER libavcodec, which references libshine). - if(CONFIG_FFMPEG_ENC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-encode.c) + if(_need_reg) + set(_reg_archive "${_mod_src_dir}/lib${mod_name}_reg.a") + file(WRITE "${_mod_src_dir}/build_reg.sh" +"#!/bin/sh +set -e +CC=\"${FFMPEG_CC_FF}\" +CFLAGS=\"-Os ${FFMPEG_EXTRA_CFLAGS} -DHAVE_AV_CONFIG_H -I${_mod_src_dir} -I${FFMPEG_EXT_BUILD_DIR} -I${SOF_FFMPEG_SRC_DIR}\" +${_reg_cmds} +rm -f \"${_reg_archive}\" +${FFMPEG_CROSS_PREFIX}ar rcs \"${_reg_archive}\" ${_reg_objs} +") + add_custom_command( + OUTPUT "${_reg_archive}" + COMMAND sh "${_mod_src_dir}/build_reg.sh" + DEPENDS ffmpeg_ext "${_mod_src_dir}/build_reg.sh" + VERBATIM) + add_custom_target(${mod_name}_reg DEPENDS "${_reg_archive}") + set(_reg_lib "${mod_name}_reg") + set(_reg_dep "${mod_name}_reg") endif() - if(CONFIG_FFMPEG_ENC_MP3) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-mp3.c) - list(APPEND ffmpeg_dec_libs shine) - list(APPEND ffmpeg_dec_libpaths "${SHINE_INSTALL}/lib") + + # 4. Build SOURCES, INCLUDES, LIBS, LIBS_PATH, CFLAGS lists + set(_srcs + "${_ff_root_dir}/ffmpeg_common.c" + "${_ff_root_dir}/ffmpeg_dec-convert.c" + "${_ff_root_dir}/ffmpeg-convert-hifi.c" + "${_ff_root_dir}/ffmpeg_dec-shims.c" + "${_ff_root_dir}/ffmpeg_dec-alloc.c" + ${ARG_SOURCES}) + if(ARG_USE_FASTMATH) + list(APPEND _srcs "${_ff_root_dir}/fastmathf.c") endif() - if(CONFIG_FFMPEG_ENC_AAC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-aac.c) - list(APPEND ffmpeg_dec_libs vo-aacenc) - list(APPEND ffmpeg_dec_libpaths "${VO_AACENC_INSTALL}/lib") + + set(_incs "${FFMPEG_INSTALL_DIR}/include" "${_ff_root_dir}") + set(_libpaths "${_mod_src_dir}" "${FFMPEG_INSTALL_DIR}/lib") + set(_libs "") + + if(_reg_lib) + list(APPEND _libs "${_reg_lib}") endif() - if(CONFIG_FFMPEG_ENC_FLAC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-flac.c) + if(ARG_USE_AVFILTER) + list(APPEND _libs avfilter_noco) endif() - if(CONFIG_FFMPEG_ENC_ALAC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-alac.c) + if(ARG_CODEC_SYMS OR ARG_PARSER_SYMS) + list(APPEND _libs avcodec_noco) endif() - if(CONFIG_FFMPEG_ENC_SBC) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-sbc.c) + # Repeat _reg_lib (and avcodec_noco when parsers are present) because + # archive members in avcodec_noco (parser.o -> av_parser_iterate) + # pull parsers.o, which in turn references ff_*_parser in avcodec_noco. + if(_reg_lib) + list(APPEND _libs "${_reg_lib}") endif() - if(CONFIG_FFMPEG_ENC_G722) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-g722.c) + if(ARG_PARSER_SYMS) + list(APPEND _libs avcodec_noco) endif() - if(CONFIG_FFMPEG_ENC_APTX OR CONFIG_FFMPEG_ENC_APTX_HD) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-aptx.c) + if(ARG_USE_SHINE) + list(APPEND _libs shine) + list(APPEND _libpaths "${SHINE_INSTALL}/lib") endif() - if(CONFIG_FFMPEG_ENC_G726) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-g726.c) + if(ARG_USE_VOAACENC) + list(APPEND _libs vo-aacenc) + list(APPEND _incs "${VO_AACENC_INSTALL}/include") + list(APPEND _libpaths "${VO_AACENC_INSTALL}/lib") endif() - if(CONFIG_FFMPEG_ENC_ALAW OR CONFIG_FFMPEG_ENC_MULAW) - list(APPEND ffmpeg_dec_srcs ../ffmpeg-enc-g711.c) + if(ARG_ROLE STREQUAL "dec" OR ARG_USE_AVFILTER) + list(APPEND _libs swresample) endif() + list(APPEND _libs avutil newlib_m) + list(APPEND _libpaths "${_ff_libm_dir}") - # Real libm (newlib double math) LAST so libav*/filter references resolve against it - get_filename_component(_ff_libm_dir "${FFMPEG_TARGET_LIBM}" DIRECTORY) - list(APPEND ffmpeg_dec_libpaths "${_ff_libm_dir}") - list(APPEND ffmpeg_dec_libs newlib_m) + set(_cflags ${_ff_common_cflags} "SHELL:-imacros ${_mod_src_dir}/ffmpeg_mod_cfg.h") + set(_deps ffmpeg_ext newlib_m ${_reg_dep} ${ARG_EXTRA_DEPS}) - # Cold split: module code must also use -mlongcalls to reach FFmpeg code - # that now lives in the far (DRAM) .cold region. - set(ffmpeg_dec_cflags "") + set(_srcs_str "") + foreach(_s IN LISTS _srcs) + set(_srcs_str "${_srcs_str}\n\t\"${_s}\"") + endforeach() + set(_incs_str "") + foreach(_i IN LISTS _incs) + set(_incs_str "${_incs_str}\n\t\"${_i}\"") + endforeach() + set(_libpaths_str "") + foreach(_p IN LISTS _libpaths) + set(_libpaths_str "${_libpaths_str}\n\t\"${_p}\"") + endforeach() + set(_libs_str "") + foreach(_l IN LISTS _libs) + set(_libs_str "${_libs_str} ${_l}") + endforeach() + set(_cflags_str "") + foreach(_c IN LISTS _cflags) + set(_cflags_str "${_cflags_str} \"${_c}\"") + endforeach() + set(_deps_str "") + foreach(_d IN LISTS _deps) + set(_deps_str "${_deps_str} ${_d}") + endforeach() + + set(_link_opts_list "") + if(NOT CONFIG_LLEXT_TYPE_ELF_RELOCATABLE) + list(APPEND _link_opts_list "\"-Wl,--exclude-libs,ALL\"" "\"-Wl,--gc-sections\"") + endif() if(CONFIG_FFMPEG_DEC_COLD_SPLIT) - list(APPEND ffmpeg_dec_cflags -mlongcalls) + list(APPEND _link_opts_list "\"-Wl,-T,${_ff_llext_dir}/ffmpeg_cold.ld\"") endif() - # Disable scalar hardware FP0 on Clang targets (CONFIG_FPU=n) so float - # conversions and strtod/strtof emit soft-float libcalls instead of - # faulting FP0 instructions. - if(CMAKE_C_COMPILER_ID MATCHES "Clang") - list(APPEND ffmpeg_dec_cflags "SHELL:-Xclang -target-feature -Xclang -fp") + set(_link_opts_str "") + if(_link_opts_list) + string(JOIN " " _link_opts_joined ${_link_opts_list}) + set(_link_opts_str "\n\tLINK_OPTIONS ${_link_opts_joined}") endif() - set(ffmpeg_dec_includes "${FFMPEG_INSTALL_DIR}/include") - if(CONFIG_FFMPEG_ENC_AAC) - list(APPEND ffmpeg_dec_includes "${VO_AACENC_INSTALL}/include") + set(_placement_flags "\n\tNO_OFFSET_ADVANCE") + if(ARG_TOP_DOWN OR ARG_ROLE STREQUAL "enc") + set(_placement_flags "${_placement_flags}\n\tTOP_DOWN") endif() - sof_llext_build("ffmpeg_dec" - SOURCES ${ffmpeg_dec_srcs} - INCLUDES ${ffmpeg_dec_includes} - LIBS_PATH ${ffmpeg_dec_libpaths} - LIBS ${ffmpeg_dec_libs} - CFLAGS ${ffmpeg_dec_cflags} - LIB openmodules - ) + file(WRITE "${_mod_src_dir}/CMakeLists.txt" +"# Auto-generated per-module LLEXT build for ${mod_name} +sof_llext_build(\"${mod_name}\"${_placement_flags} + SOURCES ${_srcs_str} + INCLUDES ${_incs_str} + LIBS_PATH ${_libpaths_str} + LIBS ${_libs_str} + CFLAGS ${_cflags_str}${_link_opts_str} +) +add_dependencies(${mod_name}_llext_lib ${_deps_str}) +add_dependencies(${mod_name} ${_deps_str}) +") - # The archives must be built before the module compiles/links against them. - add_dependencies(ffmpeg_dec_llext_lib ffmpeg_ext newlib_m ${_ff_shine_dep} ${_ff_vo_aacenc_dep}) - add_dependencies(ffmpeg_dec ffmpeg_ext newlib_m ${_ff_shine_dep} ${_ff_vo_aacenc_dep}) + add_subdirectory("${_mod_src_dir}" "${PROJECT_BINARY_DIR}/${mod_name}_llext") + list(APPEND _ff_all_targets "${mod_name}") + set(_ff_all_targets "${_ff_all_targets}" PARENT_SCOPE) +endfunction() - # Cold split: place the (renamed) FFmpeg .cold code so the loader relocates - # it to DRAM. See ffmpeg_cold.ld for why INSERT AFTER .bss. - if(CONFIG_FFMPEG_DEC_COLD_SPLIT) - llext_link_options(ffmpeg_dec - "-Wl,-T,${CMAKE_CURRENT_LIST_DIR}/ffmpeg_cold.ld") +# --- Decoders (IBS=4096, OBS=16384) --- +macro(_ffmpeg_add_decoder kconf mod_name manifest_name src_file ops_sym snd_id bespoke ff_dec_syms ff_par_syms use_fastmath) + if(${kconf}) + set(_fm_flag "") + if(${use_fastmath}) + set(_fm_flag USE_FASTMATH) + endif() + _ffmpeg_add_llext_module("${mod_name}" + ROLE dec + MANIFEST_NAME "${manifest_name}" + UUID_SYM "${mod_name}" + IBS 4096 OBS 16384 + CODEC_OPS "${ops_sym}" + SND_ID "${snd_id}" + BESPOKE "${bespoke}" + SOURCES "${_ff_root_dir}/ffmpeg_dec.c" + "${_ff_root_dir}/ffmpeg_dec-ffmpeg.c" + "${_ff_root_dir}/${src_file}" + CODEC_SYMS ${ff_dec_syms} + PARSER_SYMS ${ff_par_syms} + ${_fm_flag} + ) endif() +endmacro() + +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_FLAC ffmpeg_dec_flac FFDECFLC ffmpeg_dec-flac.c ffmpeg_dec_flac_ops SND_AUDIOCODEC_FLAC 0 "ff_flac_decoder" "ff_flac_parser" FALSE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_AAC ffmpeg_dec_aac FFDECAAC ffmpeg_dec-aac.c ffmpeg_dec_aac_ops SND_AUDIOCODEC_AAC 0 "ff_aac_fixed_decoder" "ff_aac_parser;ff_aac_latm_parser" TRUE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_OPUS ffmpeg_dec_opus FFDECOPS ffmpeg_dec-opus.c ffmpeg_dec_opus_ops SND_AUDIOCODEC_OPUS_RAW 1 "ff_opus_decoder" "ff_opus_parser" TRUE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_MP3 ffmpeg_dec_mp3 FFDECMP3 ffmpeg_dec-mp3.c ffmpeg_dec_mp3_ops SND_AUDIOCODEC_MP3 0 "ff_mp3_decoder" "ff_mpegaudio_parser" TRUE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_ALAC ffmpeg_dec_alac FFDECALC ffmpeg_dec-alac.c ffmpeg_dec_alac_ops SND_AUDIOCODEC_ALAC 0 "ff_alac_decoder" "" FALSE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_SBC ffmpeg_dec_sbc FFDECSBC ffmpeg_dec-sbc.c ffmpeg_dec_sbc_ops SND_AUDIOCODEC_SBC 1 "ff_sbc_decoder" "ff_sbc_parser" FALSE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_G722 ffmpeg_dec_g722 FFDEC722 ffmpeg_dec-g722.c ffmpeg_dec_g722_ops SND_AUDIOCODEC_G722 1 "ff_adpcm_g722_decoder" "" FALSE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_APTX ffmpeg_dec_aptx FFDECAPX ffmpeg_dec-aptx.c ffmpeg_dec_aptx_ops SND_AUDIOCODEC_APTX 1 "ff_aptx_decoder" "" FALSE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_APTX_HD ffmpeg_dec_aptx_hd FFDECAHD ffmpeg_dec-aptx.c ffmpeg_dec_aptx_hd_ops SND_AUDIOCODEC_APTX_HD 1 "ff_aptx_hd_decoder" "" FALSE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_G726 ffmpeg_dec_g726 FFDEC726 ffmpeg_dec-g726.c ffmpeg_dec_g726_ops SND_AUDIOCODEC_G726 1 "ff_adpcm_g726_decoder;ff_adpcm_g726le_decoder" "" FALSE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_ALAW ffmpeg_dec_alaw FFDECALW ffmpeg_dec-g711.c ffmpeg_dec_alaw_ops SND_AUDIOCODEC_ALAW 1 "ff_pcm_alaw_decoder" "" FALSE) +_ffmpeg_add_decoder(CONFIG_FFMPEG_DEC_MULAW ffmpeg_dec_mulaw FFDECULW ffmpeg_dec-g711.c ffmpeg_dec_mulaw_ops SND_AUDIOCODEC_MULAW 1 "ff_pcm_mulaw_decoder" "" FALSE) + +# --- Encoders (IBS=16384, OBS=4096) --- +macro(_ffmpeg_add_encoder kconf mod_name manifest_name src_file ops_sym snd_id bespoke ff_enc_syms) + if(${kconf}) + _ffmpeg_add_llext_module("${mod_name}" + ROLE enc + MANIFEST_NAME "${manifest_name}" + UUID_SYM "${mod_name}" + IBS 16384 OBS 4096 + CODEC_OPS "${ops_sym}" + SND_ID "${snd_id}" + BESPOKE "${bespoke}" + SOURCES "${_ff_root_dir}/ffmpeg-encode.c" + "${_ff_root_dir}/${src_file}" + CODEC_SYMS ${ff_enc_syms} + ${ARGN} + ) + endif() +endmacro() + +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_MP3 ffmpeg_enc_mp3 FFENCMP3 ffmpeg-enc-mp3.c ffmpeg_enc_mp3_ops SND_AUDIOCODEC_MP3 0 "ff_libshine_encoder" USE_SHINE EXTRA_DEPS shine_ext) +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_AAC ffmpeg_enc_aac FFENCAAC ffmpeg-enc-aac.c ffmpeg_enc_aac_ops SND_AUDIOCODEC_AAC 0 "" USE_VOAACENC EXTRA_DEPS vo_aacenc_ext) +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_FLAC ffmpeg_enc_flac FFENCFLC ffmpeg-enc-flac.c ffmpeg_enc_flac_ops SND_AUDIOCODEC_FLAC 0 "ff_flac_encoder") +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_ALAC ffmpeg_enc_alac FFENCALC ffmpeg-enc-alac.c ffmpeg_enc_alac_ops SND_AUDIOCODEC_ALAC 0 "ff_alac_encoder") +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_SBC ffmpeg_enc_sbc FFENCSBC ffmpeg-enc-sbc.c ffmpeg_enc_sbc_ops SND_AUDIOCODEC_SBC 1 "ff_sbc_encoder") +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_G722 ffmpeg_enc_g722 FFENC722 ffmpeg-enc-g722.c ffmpeg_enc_g722_ops SND_AUDIOCODEC_G722 1 "ff_adpcm_g722_encoder") +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_APTX ffmpeg_enc_aptx FFENCAPX ffmpeg-enc-aptx.c ffmpeg_enc_aptx_ops SND_AUDIOCODEC_APTX 1 "ff_aptx_encoder") +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_APTX_HD ffmpeg_enc_aptx_hd FFENCAHD ffmpeg-enc-aptx.c ffmpeg_enc_aptx_hd_ops SND_AUDIOCODEC_APTX_HD 1 "ff_aptx_hd_encoder") +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_G726 ffmpeg_enc_g726 FFENC726 ffmpeg-enc-g726.c ffmpeg_enc_g726_ops SND_AUDIOCODEC_G726 1 "ff_adpcm_g726_encoder;ff_adpcm_g726le_encoder") +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_ALAW ffmpeg_enc_alaw FFENCALW ffmpeg-enc-g711.c ffmpeg_enc_alaw_ops SND_AUDIOCODEC_ALAW 1 "ff_pcm_alaw_encoder") +_ffmpeg_add_encoder(CONFIG_FFMPEG_ENC_MULAW ffmpeg_enc_mulaw FFENCULW ffmpeg-enc-g711.c ffmpeg_enc_mulaw_ops SND_AUDIOCODEC_MULAW 1 "ff_pcm_mulaw_encoder") + +# --- Audio Filters (IBS=16384, OBS=16384) --- +if(CONFIG_FFMPEG_FILTER_AFFTDN) + _ffmpeg_add_llext_module(ffmpeg_af_afftdn + ROLE af + MANIFEST_NAME "FFAFDN" + UUID_SYM ffmpeg_af_afftdn + IBS 16384 OBS 16384 + AF_DEFINE FFMPEG_AF_SINGLE_AFFTDN + SOURCES "${_ff_root_dir}/ffmpeg-filter.c" + FILTER_SYMS ff_asrc_abuffer ff_asink_abuffer ff_af_aformat ff_af_afftdn + USE_AVFILTER + USE_FASTMATH + ) +endif() +if(CONFIG_FFMPEG_FILTER_ALIMITER) + _ffmpeg_add_llext_module(ffmpeg_af_alimiter + ROLE af + MANIFEST_NAME "FFALIM" + UUID_SYM ffmpeg_af_alimiter + IBS 16384 OBS 16384 + AF_DEFINE FFMPEG_AF_SINGLE_ALIMITER + SOURCES "${_ff_root_dir}/ffmpeg-filter.c" + FILTER_SYMS ff_asrc_abuffer ff_asink_abuffer ff_af_aformat ff_af_alimiter + USE_AVFILTER + USE_FASTMATH + TOP_DOWN + ) endif() + +set(FFMPEG_LLEXT_TARGETS ${_ff_all_targets} PARENT_SCOPE) diff --git a/src/audio/mfcc/mfcc.c b/src/audio/mfcc/mfcc.c index 945c77c6d613..f23630c10251 100644 --- a/src/audio/mfcc/mfcc.c +++ b/src/audio/mfcc/mfcc.c @@ -4,6 +4,7 @@ // // Author: Seppo Ingalsuo +#include #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -321,6 +323,14 @@ static const struct module_interface mfcc_interface = { .reset = mfcc_reset, }; +static const uint32_t mfcc_codec_info_items[] +#if CONFIG_COMP_MFCC_MODULE + __section(SOF_CODEC_INFO_SECTION) __used +#endif + = { + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_CAPTURE), +}; + #if CONFIG_COMP_MFCC_MODULE /* modular: llext dynamic link */ @@ -338,6 +348,14 @@ SOF_LLEXT_BUILDINFO; /* unused with Zephyr, generates no output */ DECLARE_TR_CTX(mfcc_tr, SOF_UUID(mfcc_uuid), LOG_LEVEL_INFO); DECLARE_MODULE_ADAPTER(mfcc_interface, mfcc_uuid, mfcc_tr); -SOF_MODULE_INIT(mfcc, sys_comp_module_mfcc_interface_init); + +static __maybe_unused void sys_comp_mfcc_init(void) +{ + sys_comp_module_mfcc_interface_init(); + sof_codec_info_add_items(&mfcc_interface, mfcc_codec_info_items, + ARRAY_SIZE(mfcc_codec_info_items)); +} + +SOF_MODULE_INIT(mfcc, sys_comp_mfcc_init); #endif diff --git a/src/audio/module_adapter/module/cadence_ipc4.c b/src/audio/module_adapter/module/cadence_ipc4.c index 3a4489e24dcf..612385c849aa 100644 --- a/src/audio/module_adapter/module/cadence_ipc4.c +++ b/src/audio/module_adapter/module/cadence_ipc4.c @@ -3,6 +3,7 @@ // Copyright(c) 2025-2026 Intel Corporation. All rights reserved. // +#include #include #include #include @@ -644,4 +645,38 @@ static const struct module_interface cadence_codec_interface = { }; DECLARE_MODULE_ADAPTER(cadence_codec_interface, cadence_codec_uuid, cadence_codec_tr); -SOF_MODULE_INIT(cadence_codec, sys_comp_module_cadence_codec_interface_init); + +#if defined(CONFIG_CADENCE_CODEC_AAC_DEC) || defined(CONFIG_CADENCE_CODEC_MP3_DEC) || \ + defined(CONFIG_CADENCE_CODEC_MP3_ENC) || defined(CONFIG_CADENCE_CODEC_VORBIS_DEC) || \ + defined(CONFIG_SOF_COMPRESS_CODEC_PCM_DEC) +static const uint32_t cadence_codec_info_items[] = { +#ifdef CONFIG_CADENCE_CODEC_AAC_DEC + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_AAC, SOF_IPC_STREAM_PLAYBACK), +#endif +#ifdef CONFIG_CADENCE_CODEC_MP3_DEC + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_MP3, SOF_IPC_STREAM_PLAYBACK), +#endif +#ifdef CONFIG_CADENCE_CODEC_MP3_ENC + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_MP3, SOF_IPC_STREAM_CAPTURE), +#endif +#ifdef CONFIG_CADENCE_CODEC_VORBIS_DEC + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_VORBIS, SOF_IPC_STREAM_PLAYBACK), +#endif +#ifdef CONFIG_SOF_COMPRESS_CODEC_PCM_DEC + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_PCM, SOF_IPC_STREAM_PLAYBACK), +#endif +}; +#endif + +static __maybe_unused void sys_comp_cadence_codec_init(void) +{ + sys_comp_module_cadence_codec_interface_init(); +#if defined(CONFIG_CADENCE_CODEC_AAC_DEC) || defined(CONFIG_CADENCE_CODEC_MP3_DEC) || \ + defined(CONFIG_CADENCE_CODEC_MP3_ENC) || defined(CONFIG_CADENCE_CODEC_VORBIS_DEC) || \ + defined(CONFIG_SOF_COMPRESS_CODEC_PCM_DEC) + sof_codec_info_add_items(&cadence_codec_interface, cadence_codec_info_items, + ARRAY_SIZE(cadence_codec_info_items)); +#endif +} + +SOF_MODULE_INIT(cadence_codec, sys_comp_cadence_codec_init); diff --git a/src/include/ipc4/base_fw.h b/src/include/ipc4/base_fw.h index 6583365e755a..b513798886fa 100644 --- a/src/include/ipc4/base_fw.h +++ b/src/include/ipc4/base_fw.h @@ -190,6 +190,12 @@ enum ipc4_basefw_params { /** Set policy mask for microphone privacy in firmware-managed mode. */ IPC4_SET_MIC_PRIVACY_FW_MANAGED_POLICY_MASK = 36, + + /** Discover SOF specific runtime capabilities/information in TLV format via LARGE_CONFIG_GET. */ + IPC4_SOF_INFO_GET = 37, + + /** Unload an idle dynamic library by ID via LARGE_CONFIG_SET. */ + IPC4_SOF_LIBRARY_UNLOAD = 38, }; /** @@ -289,6 +295,8 @@ enum ipc4_fw_config_params { enum ipc4_fw_sof_info_params { /** Decoder/encoder codec information. */ IPC4_SOF_CODEC_INFO = 0, + /** Bitmask of runtime SOF info capabilities (IPC4_SOF_CAP_*). */ + IPC4_SOF_CAPS = 1, /** Total number of SOF config parameters. */ IPC4_SOF_CFG_PARAMS_COUNT, @@ -296,6 +304,12 @@ enum ipc4_fw_sof_info_params { IPC4_MAX_SOF_CFG_PARAM = IPC4_SOF_CFG_PARAMS_COUNT - 1, }; +/** BaseFW supports runtime query via IPC4_SOF_INFO_GET. */ +#define IPC4_SOF_CAP_RUNTIME_SOF_INFO (1U << 0) + +/** BaseFW supports unloading idle dynamic libraries via IPC4_SOF_LIBRARY_UNLOAD. */ +#define IPC4_SOF_CAP_LIBRARY_UNLOAD (1U << 1) + /** * \brief Hardware configuration parameter TLV IDs returned by IPC4_HW_CONFIG_GET. * \ingroup ipc4_base_fw_api diff --git a/src/include/module/module/llext.h b/src/include/module/module/llext.h index 4f1208f33d5e..8b4a04e13835 100644 --- a/src/include/module/module/llext.h +++ b/src/include/module/module/llext.h @@ -41,8 +41,20 @@ } \ } +#ifndef SOF_LLEXT_RETAIN +#ifdef __has_attribute +#if __has_attribute(__retain__) +#define SOF_LLEXT_RETAIN __attribute__((__retain__)) +#endif +#endif +#ifndef SOF_LLEXT_RETAIN +#define SOF_LLEXT_RETAIN +#endif +#endif + #define SOF_LLEXT_BUILDINFO \ -static const struct sof_module_api_build_info buildinfo __section(".mod_buildinfo") __used = { \ +static const struct sof_module_api_build_info buildinfo __section(".mod_buildinfo") __used \ + SOF_LLEXT_RETAIN = { \ .format = SOF_MODULE_API_BUILD_INFO_FORMAT, \ .api_version_number.full = SOF_MODULE_API_CURRENT_VERSION, \ } diff --git a/src/include/sof/audio/codec_info.h b/src/include/sof/audio/codec_info.h new file mode 100644 index 000000000000..9efe1a4d2d14 --- /dev/null +++ b/src/include/sof/audio/codec_info.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ +/* + * Copyright(c) 2026 Intel Corporation. All rights reserved. + */ + +#ifndef __SOF_AUDIO_CODEC_INFO_H__ +#define __SOF_AUDIO_CODEC_INFO_H__ + +#include +#include +#include + +/** + * \brief Encodes codec and direction information into a single 32-bit value. + * \param codec Codec type (bits 0-7, e.g. SND_AUDIOCODEC_*) + * \param dir Stream direction (bits 8-11, e.g. SOF_IPC_STREAM_*) + * \return Encoded 32-bit codec capability item + */ +#define SOF_CODEC_INFO_ITEM(codec, dir) \ + (((uint32_t)(codec) & 0xffU) | (((uint32_t)(dir) & 0xfU) << 8)) + +/** ELF section name holding LLEXT module codec capability items. */ +#define SOF_CODEC_INFO_SECTION ".sof_codec_info" + +#if CONFIG_COMP_BASEFW_IPC4 && !CONFIG_LIBRARY +/** + * \brief Add a single runtime codec capability item for a module or library. + * \param[in] owner Opaque owner token (e.g. module interface or library module ctx). + * \param[in] item Encoded SOF_CODEC_INFO_ITEM(codec, dir) value. + * \return 0 on success, negative error code on failure. + */ +int sof_codec_info_add(const void *owner, uint32_t item); + +/** + * \brief Remove runtime codec capability item(s) for an owner token. + * \param[in] owner Opaque owner token previously passed to sof_codec_info_add(). + * \param[in] item Encoded item to remove, or 0 to remove all items for @p owner. + */ +void sof_codec_info_remove(const void *owner, uint32_t item); +#else +static inline int sof_codec_info_add(const void *owner, uint32_t item) +{ + (void)owner; + (void)item; + return 0; +} + +static inline void sof_codec_info_remove(const void *owner, uint32_t item) +{ + (void)owner; + (void)item; +} +#endif + +static inline int sof_codec_info_add_items(const void *owner, const uint32_t *items, size_t count) +{ + size_t i; + + if (!items) + return -EINVAL; + + for (i = 0; i < count; i++) { + int ret = sof_codec_info_add(owner, items[i]); + + if (ret < 0) + return ret; + } + + return 0; +} + +#endif /* __SOF_AUDIO_CODEC_INFO_H__ */ diff --git a/src/include/sof/lib_manager.h b/src/include/sof/lib_manager.h index 70ca5f97102c..0a5d238f0baa 100644 --- a/src/include/sof/lib_manager.h +++ b/src/include/sof/lib_manager.h @@ -221,6 +221,24 @@ void lib_manager_get_instance_bss_address(uint32_t instance_id, */ int lib_manager_load_library(uint32_t dma_id, uint32_t lib_id, uint32_t type); +/* + * \brief Unload library + * + * param[in] lib_id - library ID to unload (1..LIB_MANAGER_MAX_LIBS - 1) + * + * Unregisters codec capabilities, unloads any cached LLEXT contexts, and frees + * library storage when no module instance is active. + */ +#ifdef CONFIG_LIBRARY_MANAGER +int lib_manager_unload_library(uint32_t lib_id); +#else +static inline int lib_manager_unload_library(uint32_t lib_id) +{ + (void)lib_id; + return -ENOTSUP; +} +#endif + struct userspace_context; /* * \brief Allocate the module and start the agent if needed diff --git a/src/kernel/audio/base_fw.c b/src/kernel/audio/base_fw.c index 16115d332d6e..5cceb500a04f 100644 --- a/src/kernel/audio/base_fw.c +++ b/src/kernel/audio/base_fw.c @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -14,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -22,8 +22,11 @@ #include #include #include +#include #include #include +#include +#include #include #include #include @@ -74,185 +77,106 @@ __cold static uint32_t get_host_buffer_size(void) return periods; } +#define SOF_IPC4_CODEC_INFO_MAX_ITEMS 64 + struct sof_ipc4_codec_info_data { uint32_t count; - uint32_t items[32]; + uint32_t items[SOF_IPC4_CODEC_INFO_MAX_ITEMS]; } __packed __aligned(4); -/** - * Encodes codec and direction information into a single 32-bit value. - * @param codec Codec type (bits 0-7) - * @param dir Stream direction (bits 8-11) - * @return Encoded 32-bit value - */ -#define SET_CODEC_INFO_ITEM(codec, dir) (((codec) & 0xff) | (((dir) & 0xf) << 8)) +struct sof_codec_info_slot { + const void *owner; + uint32_t item; +}; -static inline __maybe_unused void -add_codec_info_item(struct sof_ipc4_codec_info_data *info, - uint32_t codec, uint32_t dir) +static struct sof_codec_info_slot codec_info_slots[SOF_IPC4_CODEC_INFO_MAX_ITEMS]; +static struct k_spinlock codec_info_lock; + +static inline void add_codec_info_item(struct sof_ipc4_codec_info_data *info, + uint32_t item) { - if (info->count < ARRAY_SIZE(info->items)) { - info->items[info->count++] = SET_CODEC_INFO_ITEM(codec, dir); + uint32_t i; + + if (!item) + return; + + for (i = 0; i < info->count; i++) { + if (info->items[i] == item) + return; } + + if (info->count < ARRAY_SIZE(info->items)) + info->items[info->count++] = item; } -static void get_codec_info(struct sof_tlv **tuple) +__cold int sof_codec_info_add(const void *owner, uint32_t item) +{ + k_spinlock_key_t key; + int free_idx = -1; + uint32_t i; + + assert_can_be_cold(); + + if (!owner || !item) + return -EINVAL; + + key = k_spin_lock(&codec_info_lock); + for (i = 0; i < ARRAY_SIZE(codec_info_slots); i++) { + if (codec_info_slots[i].owner == owner && codec_info_slots[i].item == item) { + k_spin_unlock(&codec_info_lock, key); + return 0; + } + if (!codec_info_slots[i].owner && free_idx < 0) + free_idx = i; + } + + if (free_idx < 0) { + k_spin_unlock(&codec_info_lock, key); + return -ENOSPC; + } + + codec_info_slots[free_idx].owner = owner; + codec_info_slots[free_idx].item = item; + k_spin_unlock(&codec_info_lock, key); + + return 0; +} + +__cold void sof_codec_info_remove(const void *owner, uint32_t item) +{ + k_spinlock_key_t key; + uint32_t i; + + assert_can_be_cold(); + + if (!owner) + return; + + key = k_spin_lock(&codec_info_lock); + for (i = 0; i < ARRAY_SIZE(codec_info_slots); i++) { + if (codec_info_slots[i].owner == owner && + (!item || codec_info_slots[i].item == item)) { + codec_info_slots[i].owner = NULL; + codec_info_slots[i].item = 0; + } + } + k_spin_unlock(&codec_info_lock, key); +} + +static void get_codec_info(struct sof_tlv **tuple, bool include_empty) { struct sof_ipc4_codec_info_data codec_info = { 0 }; + k_spinlock_key_t key; + uint32_t i; -#ifdef CONFIG_CADENCE_CODEC_AAC_DEC - add_codec_info_item(&codec_info, SND_AUDIOCODEC_AAC, - SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_CADENCE_CODEC_MP3_DEC - add_codec_info_item(&codec_info, SND_AUDIOCODEC_MP3, - SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_CADENCE_CODEC_MP3_ENC - add_codec_info_item(&codec_info, SND_AUDIOCODEC_MP3, - SOF_IPC_STREAM_CAPTURE); -#endif -#ifdef CONFIG_CADENCE_CODEC_VORBIS_DEC - add_codec_info_item(&codec_info, SND_AUDIOCODEC_VORBIS, - SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_COMP_MFCC - add_codec_info_item(&codec_info, SND_AUDIOCODEC_BESPOKE, - SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_SOF_COMPRESS_CODEC_PCM_DEC) || defined(CONFIG_FFMPEG_FILTER) - add_codec_info_item(&codec_info, SND_AUDIOCODEC_PCM, - SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_FFMPEG_DEC_FLAC - /* FLAC decode is provided by the ffmpeg_dec (libavcodec) module. */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_FLAC, - SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_FFMPEG_DEC_ALAC - /* ALAC decode is provided by the ffmpeg_dec (libavcodec) module. */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_ALAC, - SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_DEC_AAC) && !defined(CONFIG_CADENCE_CODEC_AAC_DEC) - /* AAC-LC decode is provided by the ffmpeg_dec (libavcodec) module (guarded so - * it is not advertised twice when the Cadence AAC decoder is also present). - */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_AAC, - SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_DEC_MP3) && !defined(CONFIG_CADENCE_CODEC_MP3_DEC) - /* MP3 decode is provided by the ffmpeg_dec (libavcodec) module (guarded so - * it is not advertised twice when the Cadence MP3 decoder is also present). - */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_MP3, - SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_MP3) && !defined(CONFIG_CADENCE_CODEC_MP3_ENC) - /* MP3 encode (compress capture) via ffmpeg_dec (libshine), guarded so it is - * not advertised twice when the Cadence MP3 encoder is also present. - */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_MP3, - SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_ENC_AAC) - /* AAC-LC encode (compress capture) via ffmpeg_dec (vo-aacenc). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_AAC, - SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_ENC_FLAC) - /* FLAC encode (compress capture) via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_FLAC, - SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_ENC_ALAC) - /* ALAC encode (compress capture) via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_ALAC, - SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_SBC) - /* Bluetooth SBC / mSBC decode via ffmpeg_dec (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_SBC, - SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_SBC) - /* Bluetooth SBC / mSBC encode via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_SBC, - SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_G722) - /* ITU-T G.722 wideband speech decode via ffmpeg_dec (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_G722, - SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_G722) - /* ITU-T G.722 wideband speech encode via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_G722, - SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_APTX) - /* Bluetooth aptX decode via ffmpeg_dec (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_APTX, - SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_APTX) - /* Bluetooth aptX encode via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_APTX, - SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_APTX_HD) - /* Bluetooth aptX HD decode via ffmpeg_dec (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_APTX_HD, SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_APTX_HD) - /* Bluetooth aptX HD encode via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_APTX_HD, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_G726) - /* ITU-T G.726 ADPCM decode via ffmpeg_dec (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_G726, SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_G726) - /* ITU-T G.726 ADPCM encode via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_G726, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_ALAW) - /* ITU-T G.711 A-law decode via ffmpeg_dec (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_ALAW, SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_ALAW) - /* ITU-T G.711 A-law encode via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_ALAW, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_MULAW) - /* ITU-T G.711 mu-law decode via ffmpeg_dec (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_MULAW, SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_MULAW) - /* ITU-T G.711 mu-law encode via ffmpeg_enc (native libavcodec). */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_MULAW, SOF_IPC_STREAM_CAPTURE); -#endif -#if (defined(CONFIG_FFMPEG_ENC_SBC) || defined(CONFIG_FFMPEG_ENC_G722) || \ - defined(CONFIG_FFMPEG_ENC_APTX) || defined(CONFIG_FFMPEG_ENC_APTX_HD) || \ - defined(CONFIG_FFMPEG_ENC_G726) || defined(CONFIG_FFMPEG_ENC_ALAW) || \ - defined(CONFIG_FFMPEG_ENC_MULAW)) && !defined(CONFIG_COMP_MFCC) - /* Also advertise BESPOKE capture for kernels with older SND_AUDIOCODEC_MAX. */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_CAPTURE); -#endif -#ifdef CONFIG_FFMPEG_DEC_OPUS - /* Opus decode is provided by the ffmpeg_dec (libavcodec) module. - * Advertise OPUS_RAW and BESPOKE. - */ - add_codec_info_item(&codec_info, SND_AUDIOCODEC_OPUS_RAW, SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_DEC_OPUS) || defined(CONFIG_FFMPEG_DEC_SBC) || \ - defined(CONFIG_FFMPEG_DEC_G722) || defined(CONFIG_FFMPEG_DEC_APTX) || \ - defined(CONFIG_FFMPEG_DEC_APTX_HD) || defined(CONFIG_FFMPEG_DEC_G726) || \ - defined(CONFIG_FFMPEG_DEC_ALAW) || defined(CONFIG_FFMPEG_DEC_MULAW) - add_codec_info_item(&codec_info, SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_PLAYBACK); -#endif + key = k_spin_lock(&codec_info_lock); + for (i = 0; i < ARRAY_SIZE(codec_info_slots); i++) { + if (codec_info_slots[i].owner) + add_codec_info_item(&codec_info, codec_info_slots[i].item); + } + k_spin_unlock(&codec_info_lock, key); - if (!codec_info.count) + if (!codec_info.count && !include_empty) return; tlv_value_set(*tuple, IPC4_SOF_CODEC_INFO, sizeof(codec_info.count) + @@ -263,16 +187,32 @@ static void get_codec_info(struct sof_tlv **tuple) #define SOF_CONFIG_MEMBER_SIZE(struct_name) (sizeof(struct sof_tlv) + \ sizeof(struct struct_name)) -#define SOF_CONFIG_SIZE_MAX (SOF_CONFIG_MEMBER_SIZE(sof_ipc4_codec_info_data)) +#define SOF_CONFIG_SIZE_MAX (SOF_CONFIG_MEMBER_SIZE(sof_ipc4_codec_info_data) + \ + sizeof(struct sof_tlv) + sizeof(uint32_t)) + +static uint32_t build_sof_info_tlvs(char *buf, bool include_empty_codec_info) +{ + struct sof_tlv *sof_config_tuple = (struct sof_tlv *)buf; + uint32_t caps = IPC4_SOF_CAP_RUNTIME_SOF_INFO; + +#ifdef CONFIG_LIBRARY_MANAGER + caps |= IPC4_SOF_CAP_LIBRARY_UNLOAD; +#endif + + get_codec_info(&sof_config_tuple, include_empty_codec_info); + + tlv_value_uint32_set(sof_config_tuple, IPC4_SOF_CAPS, caps); + sof_config_tuple = tlv_next(sof_config_tuple); + + return (uint32_t)((char *)sof_config_tuple - buf); +} static void base_fw_sof_config(struct sof_tlv **tuple) { char sof_config_data[SOF_CONFIG_SIZE_MAX] = { 0 }; - struct sof_tlv *sof_config_tuple = (struct sof_tlv *)sof_config_data; uint32_t sof_config_size; - get_codec_info(&sof_config_tuple); - sof_config_size = (uint32_t)((char *)sof_config_tuple - sof_config_data); + sof_config_size = build_sof_info_tlvs(sof_config_data, false); if (sof_config_size == 0) return; @@ -281,6 +221,27 @@ static void base_fw_sof_config(struct sof_tlv **tuple) *tuple = tlv_next(*tuple); } +__cold static int basefw_sof_info_get(uint32_t *data_offset, char *data) +{ + char sof_config_data[SOF_CONFIG_SIZE_MAX] = { 0 }; + uint32_t sof_config_size; + int ret; + + assert_can_be_cold(); + + sof_config_size = build_sof_info_tlvs(sof_config_data, true); + if (*data_offset < sof_config_size) + return IPC4_INVALID_CONFIG_DATA_LEN; + + ret = memcpy_s(data, *data_offset, sof_config_data, sof_config_size); + if (ret < 0) + return IPC4_OUT_OF_MEMORY; + + *data_offset = sof_config_size; + + return IPC4_SUCCESS; +} + __cold static int basefw_config(uint32_t *data_offset, char *data) { uint16_t version[4] = {SOF_MAJOR, SOF_MINOR, SOF_MICRO, SOF_BUILD}; @@ -868,6 +829,8 @@ __cold static int basefw_get_large_config(struct comp_dev *dev, uint32_t param_i return io_global_perf_state_get(data_offset, data); case IPC4_IO_GLOBAL_PERF_DATA: return io_global_perf_data_get(data_offset, data); + case IPC4_SOF_INFO_GET: + return basefw_sof_info_get(data_offset, data); /* TODO: add more support */ case IPC4_DSP_RESOURCE_STATE: @@ -962,6 +925,32 @@ __cold static int basefw_dma_control(bool first_block, bool last_block, uint32_t return IPC4_SUCCESS; } +__cold static int basefw_library_unload(bool first_block, bool last_block, + uint32_t data_offset, const char *data) +{ + uint32_t lib_id; + int ret; + + assert_can_be_cold(); + + if (!first_block || !last_block || data_offset < sizeof(lib_id) || !data) + return IPC4_ERROR_INVALID_PARAM; + + lib_id = *(const uint32_t *)data; + ret = lib_manager_unload_library(lib_id); + if (!ret) + return IPC4_SUCCESS; + + switch (ret) { + case -EBUSY: + return IPC4_BUSY; + case -ENOTSUP: + return IPC4_UNAVAILABLE; + default: + return IPC4_ERROR_INVALID_PARAM; + } +} + __cold static int basefw_set_large_config(struct comp_dev *dev, uint32_t param_id, bool first_block, bool last_block, uint32_t data_offset, const char *data) @@ -989,6 +978,8 @@ __cold static int basefw_set_large_config(struct comp_dev *dev, uint32_t param_i case IPC4_RESOURCE_ALLOCATION_REQUEST: return basefw_resource_allocation_request(first_block, last_block, data_offset, data); + case IPC4_SOF_LIBRARY_UNLOAD: + return basefw_library_unload(first_block, last_block, data_offset, data); default: break; } diff --git a/src/kernel/include/sof/kernel/llext_manager.h b/src/kernel/include/sof/kernel/llext_manager.h index 525fa50b1506..a39dc9b9ee47 100644 --- a/src/kernel/include/sof/kernel/llext_manager.h +++ b/src/kernel/include/sof/kernel/llext_manager.h @@ -29,6 +29,13 @@ uintptr_t llext_manager_allocate_module(const struct comp_ipc_config *ipc_config int llext_manager_free_module(const uint32_t component_id); int llext_manager_add_library(uint32_t module_id); +int llext_manager_remove_library(uint32_t module_id); + +struct lib_manager_mod_ctx; +struct sof_man_fw_desc; +void llext_manager_register_lib_codecs(const struct lib_manager_mod_ctx *ctx, + const struct sof_man_fw_desc *desc); +void llext_manager_unregister_lib_codecs(const struct lib_manager_mod_ctx *ctx); int llext_manager_add_domain(const uint32_t component_id, struct k_mem_domain *domain); int llext_manager_rm_domain(const uint32_t component_id, struct k_mem_domain *domain); @@ -39,6 +46,7 @@ bool comp_is_llext(struct comp_dev *comp); #define llext_manager_allocate_module(ipc_config, ipc_specific_config) 0 #define llext_manager_free_module(component_id) 0 #define llext_manager_add_library(module_id) 0 +#define llext_manager_remove_library(module_id) 0 #define llext_manager_add_domain(component_id, domain) 0 #define comp_is_llext(comp) false #endif diff --git a/src/kernel/library_manager/lib_manager.c b/src/kernel/library_manager/lib_manager.c index 49a004c5ee23..ec604e9470a1 100644 --- a/src/kernel/library_manager/lib_manager.c +++ b/src/kernel/library_manager/lib_manager.c @@ -1388,3 +1388,40 @@ __cold int lib_manager_load_library(uint32_t dma_id, uint32_t lib_id, uint32_t t return ret; } + +__cold int lib_manager_unload_library(uint32_t lib_id) +{ + struct ext_library *_ext_lib = ext_lib_get(); + struct lib_manager_mod_ctx *ctx; + uint32_t module_id; + int ret; + + assert_can_be_cold(); + + if (lib_id == 0 || lib_id >= LIB_MANAGER_MAX_LIBS || !_ext_lib) + return -EINVAL; + + 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; + } + + if (ctx->base_addr) + rfree(ctx->base_addr); + + rfree(ctx); + _ext_lib->desc[lib_id] = NULL; + + tr_info(&lib_manager_tr, "unloaded library id: %u", lib_id); + + return 0; +} diff --git a/src/kernel/library_manager/llext_manager.c b/src/kernel/library_manager/llext_manager.c index 02a0ef947a14..16784c9f0fe4 100644 --- a/src/kernel/library_manager/llext_manager.c +++ b/src/kernel/library_manager/llext_manager.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -1170,6 +1171,140 @@ __cold int llext_manager_free_module(const uint32_t component_id) return llext_manager_unload_module(mctx); } +__cold static const void *llext_manager_elf_find_section(const uint8_t *elf, size_t elf_size, + const char *name, size_t *sec_size) +{ + const elf_ehdr_t *ehdr; + const elf_shdr_t *shdrs; + const elf_shdr_t *shstr; + const char *strtab; + unsigned int i; + + assert_can_be_cold(); + + if (!elf || elf_size < sizeof(*ehdr)) + return NULL; + + ehdr = (const elf_ehdr_t *)elf; + if (ehdr->e_ident[0] != 0x7f || ehdr->e_ident[1] != 'E' || + ehdr->e_ident[2] != 'L' || ehdr->e_ident[3] != 'F') + return NULL; + + if (ehdr->e_shentsize != sizeof(*shdrs) || !ehdr->e_shnum) + return NULL; + + if (ehdr->e_shoff > elf_size || + ehdr->e_shnum > (elf_size - ehdr->e_shoff) / sizeof(*shdrs)) + return NULL; + + if (ehdr->e_shstrndx >= ehdr->e_shnum) + return NULL; + + shdrs = (const elf_shdr_t *)(elf + ehdr->e_shoff); + shstr = &shdrs[ehdr->e_shstrndx]; + if (shstr->sh_offset > elf_size || shstr->sh_size > elf_size - shstr->sh_offset) + return NULL; + + strtab = (const char *)(elf + shstr->sh_offset); + + for (i = 0; i < ehdr->e_shnum; i++) { + const char *sec_name; + size_t max_len; + + if (shdrs[i].sh_name >= shstr->sh_size) + continue; + + sec_name = strtab + shdrs[i].sh_name; + max_len = shstr->sh_size - shdrs[i].sh_name; + if (strnlen(sec_name, max_len) == max_len) + continue; + + if (strcmp(sec_name, name) != 0) + continue; + + if (shdrs[i].sh_type == SHT_NOBITS || !shdrs[i].sh_size) + return NULL; + + if (shdrs[i].sh_offset > elf_size || + shdrs[i].sh_size > elf_size - shdrs[i].sh_offset) + return NULL; + + *sec_size = shdrs[i].sh_size; + return elf + shdrs[i].sh_offset; + } + + return NULL; +} + +__cold void llext_manager_register_lib_codecs(const struct lib_manager_mod_ctx *ctx, + const struct sof_man_fw_desc *desc) +{ + const struct sof_man_module *mod_array; + size_t lib_size; + unsigned int k; + + assert_can_be_cold(); + + if (!ctx || !ctx->mod || !desc) + return; + + mod_array = (const struct sof_man_module *)((const uint8_t *)desc + + SOF_MAN_MODULE_OFFSET(0)); + if (size_mul_overflow(desc->header.preload_page_count, PAGE_SZ, &lib_size)) + return; + + for (k = 0; k < ctx->n_mod; k++) { + const struct lib_manager_module *mctx = &ctx->mod[k]; + uint32_t entry_index = mctx->start_idx; + uint32_t next_idx = entry_index + mctx->n_mod; + size_t mod_offset; + size_t mod_size; + const void *sec; + size_t sec_size = 0; + int ret; + + if (entry_index >= desc->header.num_module_entries) + continue; + + mod_offset = mod_array[entry_index].segment[LIB_MANAGER_TEXT].file_offset; + if (mod_offset >= lib_size) + continue; + + if (next_idx >= desc->header.num_module_entries) + mod_size = lib_size - mod_offset; + else + mod_size = ALIGN_UP(mod_array[next_idx].segment[LIB_MANAGER_TEXT].file_offset - + mod_offset, PAGE_SZ); + + if (mod_size > lib_size - mod_offset) + continue; + + sec = llext_manager_elf_find_section((const uint8_t *)desc - + SOF_MAN_ELF_TEXT_OFFSET + mod_offset, + mod_size, SOF_CODEC_INFO_SECTION, &sec_size); + if (!sec || sec_size < sizeof(uint32_t) || (sec_size % sizeof(uint32_t)) != 0) + continue; + + 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", + k, ret); + } +} + +__cold void llext_manager_unregister_lib_codecs(const struct lib_manager_mod_ctx *ctx) +{ + unsigned int k; + + assert_can_be_cold(); + + if (!ctx || !ctx->mod) + return; + + for (k = 0; k < ctx->n_mod; k++) + sof_codec_info_remove(&ctx->mod[k], 0); +} + /* An auxiliary library has been loaded, need to read in its exported symbols */ __cold int llext_manager_add_library(uint32_t module_id) { @@ -1207,6 +1342,58 @@ __cold int llext_manager_add_library(uint32_t module_id) } ctx->load_type = SOF_MAN_MOD_TYPE_LLEXT; + llext_manager_register_lib_codecs(ctx, desc); + + return 0; +} + +__cold int llext_manager_remove_library(uint32_t module_id) +{ + struct lib_manager_mod_ctx *const ctx = lib_manager_get_mod_ctx(module_id); + unsigned int k; + + assert_can_be_cold(); + + if (!ctx || !ctx->mod) + return -ENOENT; + + for (k = 0; k < ctx->n_mod; k++) { + const struct lib_manager_module *mctx = &ctx->mod[k]; + + if (mctx->mapped || mctx->n_dependent || + (mctx->llext && mctx->llext->use_count > 1)) + return -EBUSY; + } + + llext_manager_unregister_lib_codecs(ctx); + + for (k = 0; k < ctx->n_mod; k++) { + struct lib_manager_module *mctx = &ctx->mod[k]; + + if (mctx->ebl && mctx->llext) { + int ret = llext_free_inspection_data(&mctx->ebl->loader, mctx->llext); + + if (ret < 0) + tr_warn(&lib_manager_tr, + "llext_free_inspection_data(%u) failed: %d", k, ret); + } + if (mctx->llext) { + int ret = llext_unload(&mctx->llext); + + if (ret < 0) + tr_warn(&lib_manager_tr, "llext_unload(%u) failed: %d", k, ret); + mctx->llext = NULL; + } + if (mctx->ebl) { + rfree(mctx->ebl); + mctx->ebl = NULL; + } + } + + rfree(ctx->mod); + ctx->mod = NULL; + ctx->n_mod = 0; + return 0; } diff --git a/src/kernel/library_manager/llext_manager_dram.c b/src/kernel/library_manager/llext_manager_dram.c index 2f6cff2b3501..3c973ba018e5 100644 --- a/src/kernel/library_manager/llext_manager_dram.c +++ b/src/kernel/library_manager/llext_manager_dram.c @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -274,6 +275,12 @@ int llext_manager_restore_from_dram(void) } _ext_lib->desc[i] = ctx; + if (ctx->base_addr) { + const struct sof_man_fw_desc *desc = (const struct sof_man_fw_desc *) + ((const uint8_t *)ctx->base_addr + SOF_MAN_ELF_TEXT_OFFSET); + + llext_manager_register_lib_codecs(ctx, desc); + } } if (lib_manager_dram.n_llext) { @@ -325,6 +332,8 @@ int llext_manager_restore_from_dram(void) struct lib_manager_module *mod = ctx->mod; + llext_manager_unregister_lib_codecs(ctx); + if (!mod) continue; diff --git a/tools/topology/topology2/development/tplg-targets.cmake b/tools/topology/topology2/development/tplg-targets.cmake index 07f91662df7e..ef11b70aae61 100644 --- a/tools/topology/topology2/development/tplg-targets.cmake +++ b/tools/topology/topology2/development/tplg-targets.cmake @@ -237,13 +237,13 @@ DEEPBUFFER_FW_DMA_MS=false,HDA_ANALOG_CAPTURE_RATE=96000,HDA_ANALOG_PLAYBACK_RAT # by ffmpeg_enc. COMPR_FFMPEG_ENC # gates compr-capture-ffmpeg.conf, which taps the HDA analog capture BE, so it # may be built alongside or independently of the decode COMPR_FFMPEG path above. -"sof-hda-generic\;sof-hda-generic-ffmpeg-mp3-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true" -"sof-hda-generic\;sof-hda-generic-ffmpeg-aac-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true" -"sof-hda-generic\;sof-hda-generic-ffmpeg-flac-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true" -"sof-hda-generic\;sof-hda-generic-ffmpeg-alac-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true" -"sof-hda-generic\;sof-hda-generic-ffmpeg-sbc-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true" -"sof-hda-generic\;sof-hda-generic-ffmpeg-g722-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true" -"sof-hda-generic\;sof-hda-generic-ffmpeg-aptx-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true" +"sof-hda-generic\;sof-hda-generic-ffmpeg-mp3-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true,COMPR_FFMPEG_ENC_CODEC=mp3" +"sof-hda-generic\;sof-hda-generic-ffmpeg-aac-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true,COMPR_FFMPEG_ENC_CODEC=aac" +"sof-hda-generic\;sof-hda-generic-ffmpeg-flac-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true,COMPR_FFMPEG_ENC_CODEC=flac" +"sof-hda-generic\;sof-hda-generic-ffmpeg-alac-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true,COMPR_FFMPEG_ENC_CODEC=alac" +"sof-hda-generic\;sof-hda-generic-ffmpeg-sbc-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true,COMPR_FFMPEG_ENC_CODEC=sbc" +"sof-hda-generic\;sof-hda-generic-ffmpeg-g722-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true,COMPR_FFMPEG_ENC_CODEC=g722" +"sof-hda-generic\;sof-hda-generic-ffmpeg-aptx-enc-compr\;HDA_CONFIG=mix,COMPR_FFMPEG_ENC=true,COMPR_FFMPEG_ENC_CODEC=aptx" # SDW + DMIC + HDMI, with 16 kHz DMIC1 "cavs-sdw\;sof-mtl-sdw-cs42l42-l0-max98363-l2-4ch-48k-16k\;PLATFORM=mtl,\ diff --git a/tools/topology/topology2/platform/intel/compr-capture-ffmpeg.conf b/tools/topology/topology2/platform/intel/compr-capture-ffmpeg.conf index f6801e6b4c9d..8c5ec78a07c9 100644 --- a/tools/topology/topology2/platform/intel/compr-capture-ffmpeg.conf +++ b/tools/topology/topology2/platform/intel/compr-capture-ffmpeg.conf @@ -69,6 +69,23 @@ IncludeByKey.COMPR_FFMPEG_ENC { # 21.33 ms) must accumulate a full frame before emitting a # packet, so the DP ring supplies headroom a 2 ms LL buffer # lacks. + IncludeByKey.COMPR_FFMPEG_LLEXT { + "true" { + IncludeByKey.COMPR_FFMPEG_ENC_CODEC { + "mp3" { uuid "dd:75:7d:98:b0:2d:ca:4c:b2:ea:b3:e9:76:36:fe:00" } + "aac" { uuid "cd:35:54:b8:14:69:fd:4d:86:46:c8:38:73:d0:af:2a" } + "flac" { uuid "8a:0b:d3:f3:3c:f3:3d:41:a4:60:9e:1c:eb:37:8a:51" } + "alac" { uuid "6f:7b:05:b0:c2:b0:8c:41:88:b8:3b:50:ba:50:8b:ce" } + "sbc" { uuid "c8:36:15:2a:36:b8:44:4b:91:64:a6:58:27:6b:50:fd" } + "g722" { uuid "97:ed:1f:f7:cb:da:5e:43:9f:fb:6a:78:4f:12:fb:84" } + "aptx" { uuid "09:08:e5:1a:b4:4a:25:44:b0:c4:6e:07:69:d1:dd:3b" } + "aptx_hd" { uuid "bd:d4:2a:25:f2:98:be:41:98:5c:a4:6a:ac:2f:36:e8" } + "g726" { uuid "0a:82:aa:e9:23:69:ea:4f:ac:ea:e0:9e:95:44:2c:63" } + "alaw" { uuid "65:30:21:c5:1d:db:66:4a:97:96:eb:20:57:a0:c4:c0" } + "mulaw" { uuid "fc:0f:28:1f:bf:27:d6:48:b0:f7:5a:6b:80:63:3b:09" } + } + } + } core_id $COMPR_ENCODER_CORE_ID stack_bytes_requirement $COMPR_FFMPEG_ENC_STACK heap_bytes_requirement $COMPR_FFMPEG_ENC_HEAP diff --git a/tools/topology/topology2/platform/intel/compr-default.conf b/tools/topology/topology2/platform/intel/compr-default.conf index 73df2ebc339a..bf727e5160db 100644 --- a/tools/topology/topology2/platform/intel/compr-default.conf +++ b/tools/topology/topology2/platform/intel/compr-default.conf @@ -20,6 +20,7 @@ Define { # decoder widget (ffmpeg_dec) instead of the Cadence decoder. Enable # instead of COMPRESSED_1 (they share the COMPR_* pcm/pipeline defines). COMPR_FFMPEG false + COMPR_FFMPEG_LLEXT true COMPR_FFMPEG_DEC_STACK 65536 # Modular heap requirement (mod_alloc): up to 192 KiB DP output ring + # 64 KiB PCM staging buffer + 4 KiB input bounce buffer + 4 KiB @@ -36,6 +37,7 @@ Define { # HDA-specific PCM name are set where the BE is defined # (cavs-mixin-mixout-hda.conf). COMPR_FFMPEG_ENC false + COMPR_FFMPEG_ENC_CODEC 'mp3' COMPR_ENC_PCM_NAME 'Compress Capture' COMPR_ENC_PCM_ID 51 COMPR_ENC_PIPELINE_ID 91 diff --git a/tools/topology/topology2/platform/intel/compr-ffmpeg.conf b/tools/topology/topology2/platform/intel/compr-ffmpeg.conf index cc80c07f00b9..53faaf4ebec7 100644 --- a/tools/topology/topology2/platform/intel/compr-ffmpeg.conf +++ b/tools/topology/topology2/platform/intel/compr-ffmpeg.conf @@ -35,6 +35,24 @@ IncludeByKey.COMPR_FFMPEG { # (after container header stripping) and per-frame decoding. stack_bytes_requirement $COMPR_FFMPEG_DEC_STACK heap_bytes_requirement $COMPR_FFMPEG_DEC_HEAP + IncludeByKey.COMPR_FFMPEG_LLEXT { + "true" { + IncludeByKey.COMPR_FFMPEG_CODEC { + "flac" { uuid "8f:cf:76:3e:91:33:c5:42:9f:f2:5b:cd:5b:11:71:39" } + "aac" { uuid "1b:ac:31:56:a9:23:e4:45:87:a3:63:d0:b0:24:af:f2" } + "opus" { uuid "59:5e:fe:3f:fb:9f:c2:4f:b7:ae:86:1a:32:e2:09:8a" } + "mp3" { uuid "33:9c:c3:0d:1f:41:54:4b:88:a7:5b:2d:07:49:b6:c1" } + "alac" { uuid "35:6f:58:14:c6:70:29:42:ae:c1:d7:4e:9e:82:c0:89" } + "sbc" { uuid "cc:dc:df:b0:0d:4c:c1:4a:9d:4f:45:17:24:f9:b8:92" } + "g722" { uuid "7a:34:5d:e3:4d:22:a1:44:9e:61:97:4e:17:25:4b:64" } + "aptx" { uuid "fe:1c:4b:f6:1e:fe:a7:4e:9d:c5:bf:4c:2a:e8:d2:18" } + "aptx_hd" { uuid "20:fb:65:7e:9e:bd:8c:47:8c:09:3b:70:0f:3e:0b:52" } + "g726" { uuid "7c:cb:9e:d1:d8:ad:29:41:a1:0b:42:b7:2c:69:75:41" } + "alaw" { uuid "a8:27:6c:d0:36:05:09:40:a2:0d:c0:37:27:8e:6d:2b" } + "mulaw" { uuid "e3:50:eb:ba:c9:5b:3f:40:85:e1:46:65:14:95:ac:25" } + } + } + } # Optional codec setup control: extradata may be delivered via # ALSA mixer bytes control; FLAC STREAMINFO is also extracted # dynamically from the incoming stream by ffmpeg_dec. diff --git a/uuid-registry.txt b/uuid-registry.txt index ca201b2df1fe..982da93b4c6d 100644 --- a/uuid-registry.txt +++ b/uuid-registry.txt @@ -82,6 +82,31 @@ f6d15ad3-b122-458c-ae9b0ab0b5867aa0 dummy_dma 5150c0e6-27f9-4ec8-8351c705b642d12f eq_iir 889f6dcd-ddcd-4e05-aa5b0d39f8bca961 esai 1207af73-f9c0-4f65-92b49d45178fc9a8 ffmpeg_dec +3e76cf8f-3391-42c5-9ff25bcd5b117139 ffmpeg_dec_flac +5631ac1b-23a9-45e4-87a363d0b024aff2 ffmpeg_dec_aac +3ffe5e59-9ffb-4fc2-b7ae861a32e2098a ffmpeg_dec_opus +0dc39c33-411f-4b54-88a75b2d0749b6c1 ffmpeg_dec_mp3 +14586f35-70c6-4229-aec1d74e9e82c089 ffmpeg_dec_alac +b0dfdccc-4c0d-4ac1-9d4f451724f9b892 ffmpeg_dec_sbc +e35d347a-224d-44a1-9e61974e17254b64 ffmpeg_dec_g722 +f64b1cfe-fe1e-4ea7-9dc5bf4c2ae8d218 ffmpeg_dec_aptx +7e65fb20-bd9e-478c-8c093b700f3e0b52 ffmpeg_dec_aptx_hd +d19ecb7c-add8-4129-a10b42b72c697541 ffmpeg_dec_g726 +d06c27a8-0536-4009-a20dc037278e6d2b ffmpeg_dec_alaw +baeb50e3-5bc9-403f-85e146651495ac25 ffmpeg_dec_mulaw +987d75dd-2db0-4cca-b2eab3e97636fe00 ffmpeg_enc_mp3 +b85435cd-6914-4dfd-8646c83873d0af2a ffmpeg_enc_aac +f3d30b8a-f33c-413d-a4609e1ceb378a51 ffmpeg_enc_flac +b0057b6f-b0c2-418c-88b83b50ba508bce ffmpeg_enc_alac +2a1536c8-b836-4b44-9164a658276b50fd ffmpeg_enc_sbc +f71fed97-dacb-435e-9ffb6a784f12fb84 ffmpeg_enc_g722 +1ae50809-4ab4-4425-b0c46e0769d1dd3b ffmpeg_enc_aptx +252ad4bd-98f2-41be-985ca46aac2f36e8 ffmpeg_enc_aptx_hd +e9aa820a-6923-4fea-aceae09e95442c63 ffmpeg_enc_g726 +c5213065-db1d-4a66-9796eb2057a0c4c0 ffmpeg_enc_alaw +1f280ffc-27bf-48d6-b0f75a6b80633b09 ffmpeg_enc_mulaw +87b7f2ee-5a71-48c7-b91db85d9a1aed9d ffmpeg_af_afftdn +511b2960-20b1-4663-aa5781dc7bf92bb9 ffmpeg_af_alimiter bfc7488c-75aa-4ce8-9dbed8da08a698c2 file 93446e12-1864-4e04-afe03b1d778ffb79 fir 61bca9a8-18d0-4a18-8e7b2639219804b7 gain diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index ed9b620aba4a..4073bd7ef77f 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -41,7 +41,8 @@ previously added LLEXT module for the establishment of a dependency chain." # Build an LLEXT module. Provice a module name, a list of sources and an address # of the .text section as arguments. function(sof_llext_build module) - set(multi_args SOURCES INCLUDES CFLAGS LIBS LIBS_PATH) + set(options NO_OFFSET_ADVANCE TOP_DOWN) + set(multi_args SOURCES INCLUDES CFLAGS LIBS LIBS_PATH LINK_OPTIONS) set(single_args LIB) cmake_parse_arguments(PARSE_ARGV 1 SOF_LLEXT "${options}" "${single_args}" "${multi_args}") @@ -107,16 +108,31 @@ function(sof_llext_build module) set(EXTRA_LINKER_PARAMS ${EXTRA_LINKER_PARAMS} -L${path}) endforeach() + foreach(opt ${SOF_LLEXT_LINK_OPTIONS}) + llext_link_options(${module} ${opt}) + set(EXTRA_LINKER_PARAMS ${EXTRA_LINKER_PARAMS} ${opt}) + endforeach() + get_target_property(proc_in_file ${module} lib_output) get_target_property(proc_out_file ${module} pkg_input) get_target_property(proc_pkg_file ${module} pkg_output) set(size_file ${PROJECT_BINARY_DIR}/module_size) - get_property(last_target GLOBAL PROPERTY SOF_LLEXT_LAST_TARGET) - if(NOT "${last_target}" STREQUAL "") - add_dependencies(${module}_llext_proc ${last_target}) + set(_reset_offset_arg "") + if(SOF_LLEXT_NO_OFFSET_ADVANCE) + # Standalone per-codec modules share the post-stock VA range without + # advancing the global module_size accumulator used by openmodules. + set_property(GLOBAL APPEND PROPERTY SOF_LLEXT_STANDALONE_TARGETS ${module}) + else() + get_property(last_target GLOBAL PROPERTY SOF_LLEXT_LAST_TARGET) + if(NOT "${last_target}" STREQUAL "") + add_dependencies(${module}_llext_proc ${last_target}) + set(_reset_offset_arg "") + else() + set(_reset_offset_arg --reset) + endif() + set_property(GLOBAL PROPERTY SOF_LLEXT_LAST_TARGET ${module}) endif() - set_property(GLOBAL PROPERTY SOF_LLEXT_LAST_TARGET ${module}) add_llext_command(TARGET ${module} POST_BUILD @@ -124,20 +140,29 @@ function(sof_llext_build module) -P ${SOF_BASE}scripts/cmake/llext_write_uuids.cmake ) + set(_end_addr_arg "") + if(SOF_LLEXT_TOP_DOWN AND CONFIG_LIBRARY_MANAGER AND CONFIG_LIBRARY_REGION_SIZE) + math(EXPR _lib_end "${CONFIG_LIBRARY_BASE_ADDRESS} + ${CONFIG_LIBRARY_REGION_SIZE}" + OUTPUT_FORMAT HEXADECIMAL) + set(_end_addr_arg --end-addr=${_lib_end}) + endif() + add_llext_command(TARGET ${module} POST_BUILD COMMAND ${PYTHON_EXECUTABLE} ${SOF_BASE}scripts/llext_link_helper.py -s ${size_file} - --text-addr=${CONFIG_LIBRARY_BASE_ADDRESS} + ${_reset_offset_arg} --text-addr=${CONFIG_LIBRARY_BASE_ADDRESS} ${_end_addr_arg} -c $ -f ${proc_in_file} -o ${proc_out_file} ${CMAKE_C_COMPILER} -- ${EXTRA_LINKER_PARAMS} $ ${EXTRA_LIBS} ) - add_llext_command(TARGET ${module} - POST_PKG - COMMAND ${PYTHON_EXECUTABLE} ${SOF_BASE}scripts/llext_offset_calc.py - -i ${proc_pkg_file} -s ${size_file} - ) + if(NOT SOF_LLEXT_NO_OFFSET_ADVANCE) + add_llext_command(TARGET ${module} + POST_PKG + COMMAND ${PYTHON_EXECUTABLE} ${SOF_BASE}scripts/llext_offset_calc.py + ${_reset_offset_arg} -i ${proc_pkg_file} -s ${size_file} + ) + endif() endfunction() # Initial SOF module will contain @@ -701,4 +726,15 @@ endif() sof_append_relative_path_definitions(modules_sof) sof_append_relative_path_definitions(sof_kernel) +get_property(_standalone_llexts GLOBAL PROPERTY SOF_LLEXT_STANDALONE_TARGETS) +get_property(_last_stock_llext GLOBAL PROPERTY SOF_LLEXT_LAST_TARGET) +if(_standalone_llexts) + foreach(_mod IN LISTS _standalone_llexts) + add_dependencies(${_mod}_llext_lib uuid_reg_h) + if(NOT "${_last_stock_llext}" STREQUAL "") + add_dependencies(${_mod}_llext_proc ${_last_stock_llext}) + endif() + endforeach() +endif() + endif() # CONFIG_SOF_FULL_ZEPHYR_APPLICATION