diff --git a/src/audio/ffmpeg_dec/ffmpeg_dec.c b/src/audio/ffmpeg_dec/ffmpeg_dec.c index 81eaab628441..5628be100740 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 @@ -967,6 +968,71 @@ 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 +#endif + = { +#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_ENC_SBC) || defined(CONFIG_FFMPEG_ENC_G722) || \ + defined(CONFIG_FFMPEG_ENC_APTX) + /* 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_COMP_FFMPEG_DEC_STUB) + SOF_CODEC_INFO_ITEM(SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_PLAYBACK), +#endif +}; + /* If COMP_FFMPEG_DEC is =m in Kconfig this is built as a loadable LLEXT module. */ #if CONFIG_COMP_FFMPEG_DEC_MODULE @@ -985,6 +1051,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/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/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/include/sof/llext_manager.h b/src/include/sof/llext_manager.h index 525fa50b1506..a39dc9b9ee47 100644 --- a/src/include/sof/llext_manager.h +++ b/src/include/sof/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/audio/base_fw.c b/src/kernel/audio/base_fw.c index 880306a4a03b..c353d37ec053 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,15 +15,17 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include +#include +#include #include #include #include @@ -73,143 +76,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 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) +{ + 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; +} + +__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; +} -static void get_codec_info(struct sof_tlv **tuple) +__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 - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_AAC, SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_CADENCE_CODEC_MP3_DEC - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_MP3, SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_CADENCE_CODEC_MP3_ENC - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_MP3, SOF_IPC_STREAM_CAPTURE); -#endif -#ifdef CONFIG_CADENCE_CODEC_VORBIS_DEC - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_VORBIS, SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_COMP_MFCC - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_BESPOKE, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_SOF_COMPRESS_CODEC_PCM_DEC) || defined(CONFIG_FFMPEG_FILTER) - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_PCM, SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_FFMPEG_DEC_FLAC - /* FLAC decode is provided by the ffmpeg_dec (libavcodec) module. */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_FLAC, SOF_IPC_STREAM_PLAYBACK); -#endif -#ifdef CONFIG_FFMPEG_DEC_ALAC - /* ALAC decode is provided by the ffmpeg_dec (libavcodec) module. */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(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). - */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(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). - */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(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. - */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_MP3, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_ENC_AAC) - /* AAC-LC encode (compress capture) via ffmpeg_dec (vo-aacenc). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_AAC, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_ENC_FLAC) - /* FLAC encode (compress capture) via ffmpeg_enc (native libavcodec). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_FLAC, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_ENC_ALAC) - /* ALAC encode (compress capture) via ffmpeg_enc (native libavcodec). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_ALAC, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_SBC) - /* Bluetooth SBC / mSBC decode via ffmpeg_dec (native libavcodec). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_SBC, SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_SBC) - /* Bluetooth SBC / mSBC encode via ffmpeg_enc (native libavcodec). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(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). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(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). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_G722, SOF_IPC_STREAM_CAPTURE); -#endif -#if defined(CONFIG_FFMPEG_DEC_APTX) - /* Bluetooth aptX decode via ffmpeg_dec (native libavcodec). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_APTX, SOF_IPC_STREAM_PLAYBACK); -#endif -#if defined(CONFIG_FFMPEG_ENC_APTX) - /* Bluetooth aptX encode via ffmpeg_enc (native libavcodec). */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(SND_AUDIOCODEC_APTX, SOF_IPC_STREAM_CAPTURE); -#endif -#if (defined(CONFIG_FFMPEG_ENC_SBC) || defined(CONFIG_FFMPEG_ENC_G722) || \ - defined(CONFIG_FFMPEG_ENC_APTX)) && !defined(CONFIG_COMP_MFCC) - /* Also advertise BESPOKE capture for kernels with older SND_AUDIOCODEC_MAX. */ - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(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. - */ - codec_info.items[codec_info.count++] = - SET_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) - codec_info.items[codec_info.count++] = - SET_CODEC_INFO_ITEM(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) + @@ -220,16 +186,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; @@ -238,6 +220,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}; @@ -825,6 +828,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: @@ -919,6 +924,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) @@ -946,6 +977,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/library_manager/lib_manager.c b/src/kernel/library_manager/lib_manager.c index f2b25edd7ea2..ee2d1cdc9a01 100644 --- a/src/kernel/library_manager/lib_manager.c +++ b/src/kernel/library_manager/lib_manager.c @@ -1370,3 +1370,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 267955040cce..eea1a22f08db 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..35430d7784f1 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 a42d7892c5b8..edd69626580e 100644 --- a/tools/topology/topology2/development/tplg-targets.cmake +++ b/tools/topology/topology2/development/tplg-targets.cmake @@ -580,4 +580,7 @@ COMPRESSED_1=true,COMPRESSED_2=false" "cavs-sdw\;sof-sdca-amp-compr\;SDW_JACK=false,NUM_HDMIS=0,COMPRESSED=true,\ COMPRESSED_1=false,COMPRESSED_2=true" +# Media decode feature topology with per-format module UUID lists +"media-decode-feature\;sof-media-decode-feature\;" + ) diff --git a/tools/topology/topology2/include/common/media_format.conf b/tools/topology/topology2/include/common/media_format.conf new file mode 100644 index 000000000000..82f1318c21ed --- /dev/null +++ b/tools/topology/topology2/include/common/media_format.conf @@ -0,0 +1,49 @@ +# +# Class definition for media_format (compressed codec capabilities -> module UUIDs) +# +# Each entry maps a compressed codec ID and stream constraints (min/max rate, +# channel count, bit depth) to a candidate SOF module UUID. Use CombineArrays +# inside a media_decoder widget to list one or more module UUIDs per format +# in preference order. +# + +Class.Base."media_format" { + DefineAttribute."instance" {} + + DefineAttribute."codec_id" { + token_ref "media_codec.word" + } + + DefineAttribute."min_rate" { + token_ref "media_codec.word" + } + + DefineAttribute."max_rate" { + token_ref "media_codec.word" + } + + DefineAttribute."channels" { + token_ref "media_codec.word" + } + + DefineAttribute."bit_depth" { + token_ref "media_codec.word" + } + + DefineAttribute."module_uuid" { + type "string" + token_ref "media_codec.uuid" + } + + attributes { + !constructor [ + "instance" + ] + unique "instance" + } + + min_rate 8000 + max_rate 192000 + channels 2 + bit_depth 16 +} diff --git a/tools/topology/topology2/include/common/tokens.conf b/tools/topology/topology2/include/common/tokens.conf index d03092360591..ca18a5613e28 100644 --- a/tools/topology/topology2/include/common/tokens.conf +++ b/tools/topology/topology2/include/common/tokens.conf @@ -192,4 +192,14 @@ Object.Base.VendorToken { node_type 1980 deep_buffer_dma_ms 1981 } + + "19" { + name "media_codec" + codec_id 2200 + min_rate 2201 + max_rate 2202 + channels 2203 + bit_depth 2204 + module_uuid 2205 + } } diff --git a/tools/topology/topology2/include/components/media_decoder.conf b/tools/topology/topology2/include/components/media_decoder.conf new file mode 100644 index 000000000000..e8202f8f9aab --- /dev/null +++ b/tools/topology/topology2/include/components/media_decoder.conf @@ -0,0 +1,53 @@ +# +# Media decoder widget component +# +# A generic compressed media decoder container widget (DAPM type "decoder"). +# Instances carry Object.Base.media_format entries mapping codec formats to +# priority-ordered module UUIDs so the host driver can bind an already-loaded +# decoder module or demand-load (and purge if needed) the matching LLEXT module. +# + +Class.Widget."media_decoder" { + DefineAttribute."index" { + type "integer" + } + + DefineAttribute."instance" { + type "integer" + } + + + + DefineAttribute."cpc" { + token_ref "comp.word" + } + + attributes { + !constructor [ + "index" + "instance" + ] + !mandatory [ + "no_pm" + "uuid" + "num_input_audio_formats" + "num_output_audio_formats" + ] + !immutable [ + "type" + ] + unique "instance" + } + + # Default container/fallback UUID (Cadence codec adapter); overridden at runtime + # when a media_format entry selects a specific module UUID. + uuid "43:84:21:d8:f3:5f:4c:4a:b3:88:6c:fe:07:b9:56:aa" + type "decoder" + no_pm "true" + core_id 0 + cpc 5000 + num_input_pins 1 + num_output_pins 1 + heap_bytes_requirement 196608 + stack_bytes_requirement 16384 +} diff --git a/tools/topology/topology2/include/pipelines/cavs/compr-playback-media.conf b/tools/topology/topology2/include/pipelines/cavs/compr-playback-media.conf new file mode 100644 index 000000000000..7f6e7808cc90 --- /dev/null +++ b/tools/topology/topology2/include/pipelines/cavs/compr-playback-media.conf @@ -0,0 +1,91 @@ +# +# FE playback pipeline: compr-playback-media +# +# Compress playback pipeline using the media_decoder container widget, which +# lists supported codec formats and their candidate module UUIDs. +# + + + + + + + + + + + + + +Class.Pipeline."compr-playback-media" { + + + + attributes { + !constructor [ + "index" + ] + + !immutable [ + "direction" + ] + + unique "instance" + } + + Object.Widget { + host-copier."1" { + type "aif_in" + node_type $HDA_HOST_OUTPUT_CLASS + num_output_pins 1 + deep_buffer_dma_ms $COMPR_DEEPBUFFER_MS + } + + media_decoder."1" { + scheduler_domain "DP" + no_pm "true" + } + + module-copier."2" {} + + src."1" {} + + micsel."1" {} + + gain."1" {} + + mixin."1" {} + + pipeline."1" { + priority 0 + lp_mode 1 + } + } + + Object.Base.route [ + { + source media_decoder.$index.1 + sink module-copier.$index.2 + } + { + source module-copier.$index.2 + sink src.$index.1 + } + { + source src.$index.1 + sink micsel.$index.1 + } + { + source micsel.$index.1 + sink gain.$index.1 + } + { + source gain.$index.1 + sink mixin.$index.1 + } + ] + + direction "playback" + dynamic_pipeline 1 + time_domain "timer" +} diff --git a/tools/topology/topology2/media-decode-feature.conf b/tools/topology/topology2/media-decode-feature.conf new file mode 100644 index 000000000000..49720713b447 --- /dev/null +++ b/tools/topology/topology2/media-decode-feature.conf @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/topology/topology2/platform/intel/compr-media.conf b/tools/topology/topology2/platform/intel/compr-media.conf new file mode 100644 index 000000000000..386e8dbb3e60 --- /dev/null +++ b/tools/topology/topology2/platform/intel/compr-media.conf @@ -0,0 +1,205 @@ +# +# Media decode compress playback configuration with per-format module UUIDs. +# Used by media-decode-feature.conf (standalone feature topology) or included +# from platform topologies. +# + +Define { + COMPR_PIPELINE_SINK "mixout.1.1" + MEDIA_DECODE_CADENCE_UUID "43:84:21:d8:f3:5f:4c:4a:b3:88:6c:fe:07:b9:56:aa" + MEDIA_DECODE_FFMPEG_UUID "73:af:07:12:c0:f9:65:4f:92:b4:9d:45:17:8f:c9:a8" + SND_AUDIOCODEC_PCM 1 + SND_AUDIOCODEC_MP3 2 + SND_AUDIOCODEC_AAC 6 + SND_AUDIOCODEC_VORBIS 9 + SND_AUDIOCODEC_FLAC 10 + SND_AUDIOCODEC_BESPOKE 14 + SND_AUDIOCODEC_ALAC 15 + SND_AUDIOCODEC_OPUS_RAW 17 + SND_AUDIOCODEC_SBC 18 + SND_AUDIOCODEC_G722 19 + SND_AUDIOCODEC_APTX 20 +} + +Object.Pipeline.compr-playback-media [ + { + index $COMPR_PIPELINE_ID + + Object.Widget.host-copier.1 { + stream_name $COMPR_PCM_NAME + pcm_id $COMPR_PCM_ID + + + } + + Object.Widget.media_decoder.1 { + core_id $COMPR_DECODER_CORE_ID + stack_bytes_requirement $COMPR_FFMPEG_DEC_STACK + heap_bytes_requirement $COMPR_FFMPEG_DEC_HEAP + + + CombineArrays.Object.Base.media_format [ + { + codec_id [ $SND_AUDIOCODEC_MP3 ] + min_rate [ 8000 ] + max_rate [ 48000 ] + channels [ 1 2 ] + bit_depth [ 16 24 32 ] + module_uuid [ + $MEDIA_DECODE_FFMPEG_UUID + $MEDIA_DECODE_CADENCE_UUID + ] + } + { + codec_id [ $SND_AUDIOCODEC_AAC ] + min_rate [ 8000 ] + max_rate [ 96000 ] + channels [ 1 2 6 8 ] + bit_depth [ 16 24 32 ] + module_uuid [ + $MEDIA_DECODE_CADENCE_UUID + $MEDIA_DECODE_FFMPEG_UUID + ] + } + { + codec_id [ $SND_AUDIOCODEC_FLAC ] + min_rate [ 8000 ] + max_rate [ 192000 ] + channels [ 1 2 6 8 ] + bit_depth [ 16 24 32 ] + module_uuid [ + $MEDIA_DECODE_FFMPEG_UUID + ] + } + { + codec_id [ $SND_AUDIOCODEC_ALAC ] + min_rate [ 8000 ] + max_rate [ 192000 ] + channels [ 1 2 6 8 ] + bit_depth [ 16 24 32 ] + module_uuid [ + $MEDIA_DECODE_FFMPEG_UUID + ] + } + { + codec_id [ $SND_AUDIOCODEC_VORBIS ] + min_rate [ 8000 ] + max_rate [ 192000 ] + channels [ 1 2 ] + bit_depth [ 16 24 32 ] + module_uuid [ + $MEDIA_DECODE_CADENCE_UUID + ] + } + { + codec_id [ $SND_AUDIOCODEC_OPUS_RAW ] + min_rate [ 8000 ] + max_rate [ 48000 ] + channels [ 1 2 ] + bit_depth [ 16 24 32 ] + module_uuid [ + $MEDIA_DECODE_FFMPEG_UUID + ] + } + { + codec_id [ $SND_AUDIOCODEC_PCM ] + min_rate [ 8000 ] + max_rate [ 192000 ] + channels [ 1 2 ] + bit_depth [ 16 24 32 ] + module_uuid [ + $MEDIA_DECODE_CADENCE_UUID + ] + } + ] + } + + Object.Widget.module-copier.2 { + + + } + + Object.Widget.src.1 { + rate_out 48000 + + } + + Object.Widget.micsel.1 { + Object.Control.bytes."1" { + name '$COMPR_PCM_NAME selector bytes' + + } + + + } + + Object.Widget.gain.1 { + Object.Control.mixer.1 { + name 'Pre Mixer $COMPR_PCM_NAME Volume' + } + num_input_audio_formats 1 + Object.Base.input_audio_format [ + { + in_rate 48000 + in_bit_depth 32 + in_valid_bit_depth 32 + } + ] + num_output_audio_formats 1 + Object.Base.output_audio_format [ + { + out_rate 48000 + out_bit_depth 32 + out_valid_bit_depth 32 + } + ] + } + + Object.Widget.mixin.1 { + Object.Base.input_audio_format [ + { + in_rate 48000 + in_bit_depth 32 + in_valid_bit_depth 32 + } + ] + Object.Base.output_audio_format [ + { + out_rate 48000 + out_bit_depth 32 + out_valid_bit_depth 32 + } + ] + } + } +] + +Object.PCM.pcm [ + { + name $COMPR_PCM_NAME + id $COMPR_PCM_ID + direction playback + compress "true" + + Object.Base.fe_dai.1 { + name "$COMPR_PCM_NAME" + } + + Object.PCM.pcm_caps.1 { + name $COMPR_PCM_NAME + formats 'S32_LE' + rates '8000' + } + } +] + +Object.Base.route [ + { + source mixin.$COMPR_PIPELINE_ID.1 + sink $COMPR_PIPELINE_SINK + } + { + source host-copier.$COMPR_PCM_ID.playback + sink media_decoder.$COMPR_PIPELINE_ID.1 + } +] diff --git a/tools/topology/validator/known-issues.txt b/tools/topology/validator/known-issues.txt index 72aa9550c072..41e170f7db95 100644 --- a/tools/topology/validator/known-issues.txt +++ b/tools/topology/validator/known-issues.txt @@ -21,6 +21,7 @@ sof-sdca-amp-ref G001 # module-copier.21.22 of an amp function topology and sof-sdca-amp-ref-dai G001 # module-copier.21.22 of an amp function topology sof-sdca-jack-compr G001 # mixout.1.1 of sof-sdca-jack-id0 sof-sdca-jack-ref-dai G001 # module-copier.1.12 of sof-sdca-jack-id0 +sof-media-decode-feature G001 # mixout.1.1 of base/function topology # UAOL DAI type is not known to the upstream kernel find_dai() table sof-hda-generic*uaol W004 diff --git a/tools/topology/validator/schema/kernel_tokens.py b/tools/topology/validator/schema/kernel_tokens.py index 5bd2d13069d4..60cce54820db 100644 --- a/tools/topology/validator/schema/kernel_tokens.py +++ b/tools/topology/validator/schema/kernel_tokens.py @@ -7,7 +7,7 @@ # Token tables are lists of (token id, SND_SOC_TPLG_TUPLE_TYPE_ name, getter) # in the order the kernel declares them. -KERNEL_VERSION = 'sound-7.2-rc7-28692-gc6cf13c7c483' +KERNEL_VERSION = 'v7.4-rc1-8643-gcd8df21fce84' TOKEN_NAMES = {100: 'SOF_TKN_BUF_SIZE', 101: 'SOF_TKN_BUF_CAPS', @@ -133,7 +133,13 @@ 2000: 'SOF_TKN_IMX_MICFIL_RATE', 2001: 'SOF_TKN_IMX_MICFIL_CH', 2100: 'SOF_TKN_AMD_ACP_SDW_RATE', - 2101: 'SOF_TKN_AMD_ACP_SDW_CH'} + 2101: 'SOF_TKN_AMD_ACP_SDW_CH', + 2200: 'SOF_TKN_MEDIA_CODEC_ID', + 2201: 'SOF_TKN_MEDIA_CODEC_MIN_RATE', + 2202: 'SOF_TKN_MEDIA_CODEC_MAX_RATE', + 2203: 'SOF_TKN_MEDIA_CODEC_CHANNELS', + 2204: 'SOF_TKN_MEDIA_CODEC_BIT_DEPTH', + 2205: 'SOF_TKN_MEDIA_CODEC_MODULE_UUID'} TOKEN_GROUPS = ['SOF_PCM_TOKENS', 'SOF_PIPELINE_TOKENS', @@ -166,7 +172,8 @@ 'SOF_ACPDMIC_TOKENS', 'SOF_ACPI2S_TOKENS', 'SOF_MICFIL_TOKENS', - 'SOF_ACP_SDW_TOKENS'] + 'SOF_ACP_SDW_TOKENS', + 'SOF_MEDIA_CODEC_TOKENS'] GENERIC_TABLES = {'dapm_widget_tokens': [(417, 'BOOL', 'get_w_no_wname_in_long_name')], 'comp_pin_tokens': [(411, 'WORD', 'get_token_u32'), (412, 'WORD', 'get_token_u32')], @@ -226,7 +233,14 @@ (262, 'WORD', 'get_token_u32')]), 'SOF_SRC_TOKENS': ('SRC tokens', [(301, 'WORD', 'get_token_u32')]), 'SOF_ASRC_TOKENS': ('ASRC tokens', - [(321, 'WORD', 'get_token_u32'), (323, 'WORD', 'get_token_u32')])} + [(321, 'WORD', 'get_token_u32'), (323, 'WORD', 'get_token_u32')]), + 'SOF_MEDIA_CODEC_TOKENS': ('IPC4 Media codec tokens', + [(2200, 'WORD', 'get_token_u32'), + (2201, 'WORD', 'get_token_u32'), + (2202, 'WORD', 'get_token_u32'), + (2203, 'WORD', 'get_token_u32'), + (2204, 'WORD', 'get_token_u32'), + (2205, 'UUID', 'get_token_uuid')])} IPC4_WIDGET_TOKEN_LISTS = {'aif_in': ('sof_ipc4_widget_setup_pcm', ['SOF_COMP_TOKENS', @@ -306,18 +320,21 @@ 'SOF_AUDIO_FMT_NUM_TOKENS', 'SOF_IN_AUDIO_FORMAT_TOKENS', 'SOF_OUT_AUDIO_FORMAT_TOKENS', + 'SOF_MEDIA_CODEC_TOKENS', 'SOF_COMP_EXT_TOKENS']), 'decoder': ('sof_ipc4_widget_setup_comp_process', ['SOF_COMP_TOKENS', 'SOF_AUDIO_FMT_NUM_TOKENS', 'SOF_IN_AUDIO_FORMAT_TOKENS', 'SOF_OUT_AUDIO_FORMAT_TOKENS', + 'SOF_MEDIA_CODEC_TOKENS', 'SOF_COMP_EXT_TOKENS']), 'encoder': ('sof_ipc4_widget_setup_comp_process', ['SOF_COMP_TOKENS', 'SOF_AUDIO_FMT_NUM_TOKENS', 'SOF_IN_AUDIO_FORMAT_TOKENS', 'SOF_OUT_AUDIO_FORMAT_TOKENS', + 'SOF_MEDIA_CODEC_TOKENS', 'SOF_COMP_EXT_TOKENS'])} DAI_TYPES = {'SSP': 'SOF_DAI_INTEL_SSP', diff --git a/tools/topology/validator/tplgparse/kernel_engine.py b/tools/topology/validator/tplgparse/kernel_engine.py index 525d01eef2a3..e7fbfd6bffb3 100644 --- a/tools/topology/validator/tplgparse/kernel_engine.py +++ b/tools/topology/validator/tplgparse/kernel_engine.py @@ -359,6 +359,8 @@ def widget_parse_tokens(data: bytes, token_list, kw: KernelWidget): if g == "SOF_COMP_EXT_TOKENS": kw.comp_ext = parse_tokens(data, group(g), kw.trace, ref) continue + if g == "SOF_MEDIA_CODEC_TOKENS": + continue if g == "SOF_IN_AUDIO_FORMAT_TOKENS": num_sets = get_token_value(TKN_NUM_INPUT_AUDIO_FORMATS, kw.tuples) if num_sets is None: