Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion scripts/cmake/uuid-registry.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ add_custom_command(
COMMAND
${PYTHON_EXECUTABLE} ${TOPDIR}/scripts/gen-uuid-reg.py
${TOPDIR}/uuid-registry.txt
${UUID_REG_H})
${UUID_REG_H}
DEPENDS ${TOPDIR}/uuid-registry.txt)

add_custom_target(uuid_reg_h DEPENDS ${UUID_REG_H})

Expand Down
45 changes: 41 additions & 4 deletions scripts/llext_link_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions scripts/llext_offset_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/audio/ffmpeg_dec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

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

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

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

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

#define FFMPEG_ENC_DEFAULT_BITRATE 128000

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

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

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

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

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

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

#define FFMPEG_REG_UUID(sym) SOF_REG_UUID(sym)

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

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

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

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

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

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

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

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

assert_can_be_cold();

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

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

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

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

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

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

#define FFMPEG_REG_UUID(sym) SOF_REG_UUID(sym)

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

SOF_LLEXT_BUILDINFO;
#endif /* FFMPEG_MOD_ROLE_AF */
Loading
Loading