diff --git a/src/audio/codec_adapter/codec/cadence.c b/src/audio/codec_adapter/codec/cadence.c index 0f92059a5..a21abf202 100644 --- a/src/audio/codec_adapter/codec/cadence.c +++ b/src/audio/codec_adapter/codec/cadence.c @@ -14,6 +14,12 @@ #include #include +/* d8218443-5ff3-4a4c-b388-6cfe07b956aa */ +DECLARE_SOF_RT_UUID("cadence_codec", cadence_uuid, 0xd8218443, 0x5ff3, 0x4a4c, + 0xb3, 0x88, 0x6c, 0xfe, 0x07, 0xb9, 0x56, 0xaa); + +DECLARE_TR_CTX(cadence_tr, SOF_UUID(cadence_uuid), LOG_LEVEL_INFO); + /*****************************************************************************/ /* Cadence API functions array */ /*****************************************************************************/ @@ -478,3 +484,15 @@ int cadence_codec_free(struct comp_dev *dev) /* Nothing to do */ return 0; } + +static struct codec_interface cadence_interface = { + .init = cadence_codec_init, + .prepare = cadence_codec_prepare, + .init_process = cadence_codec_init_process, + .process = cadence_codec_process, + .apply_config = cadence_codec_apply_config, + .reset = cadence_codec_reset, + .free = cadence_codec_free +}; + +DECLARE_CODEC_ADAPTER(cadence_interface, cadence_uuid, cadence_tr); diff --git a/src/audio/codec_adapter/codec/generic.c b/src/audio/codec_adapter/codec/generic.c index f7ea002bf..10b15c11a 100644 --- a/src/audio/codec_adapter/codec/generic.c +++ b/src/audio/codec_adapter/codec/generic.c @@ -12,7 +12,6 @@ */ #include -#include /*****************************************************************************/ /* Local helper functions */ @@ -77,16 +76,12 @@ err: return ret; } -int codec_init(struct comp_dev *dev) +int codec_init(struct comp_dev *dev, struct codec_interface *interface) { int ret; struct comp_data *cd = comp_get_drvdata(dev); uint32_t codec_id = cd->ca_config.codec_id; - uint32_t interface_id = CODEC_GET_INTERFACE_ID(codec_id); struct codec_data *codec = &cd->codec; - struct codec_interface *interface = NULL; - uint32_t i; - uint32_t no_of_interfaces = ARRAY_SIZE(interfaces); comp_info(dev, "codec_init() start"); @@ -97,13 +92,6 @@ int codec_init(struct comp_dev *dev) codec->id = codec_id; - /* Find proper interface */ - for (i = 0; i < no_of_interfaces; i++) { - if (interfaces[i].id == interface_id) { - interface = &interfaces[i]; - break; - } - } if (!interface) { comp_err(dev, "codec_init(): could not find codec interface for codec id %x", codec_id); diff --git a/src/audio/codec_adapter/codec/passthrough.c b/src/audio/codec_adapter/codec/passthrough.c index 1085a763a..3bd1ad2c8 100644 --- a/src/audio/codec_adapter/codec/passthrough.c +++ b/src/audio/codec_adapter/codec/passthrough.c @@ -7,15 +7,19 @@ // Passthrough codec implementation to demonstrate Codec Adapter API #include -#include -int passthrough_codec_init(struct comp_dev *dev) +/* 376b5e44-9c82-4ec2-bc83-10ea101afa8f */ +DECLARE_SOF_RT_UUID("passthrough_codec", passthrough_uuid, 0x376b5e44, 0x9c82, 0x4ec2, + 0xbc, 0x83, 0x10, 0xea, 0x10, 0x1a, 0xf8, 0x8f); +DECLARE_TR_CTX(passthrough_tr, SOF_UUID(passthrough_uuid), LOG_LEVEL_INFO); + +static int passthrough_codec_init(struct comp_dev *dev) { comp_info(dev, "passthrough_codec_init() start"); return 0; } -int passthrough_codec_prepare(struct comp_dev *dev) +static int passthrough_codec_prepare(struct comp_dev *dev) { struct codec_data *codec = comp_get_codec(dev); struct comp_data *cd = comp_get_drvdata(dev); @@ -40,7 +44,7 @@ int passthrough_codec_prepare(struct comp_dev *dev) return 0; } -int passthrough_codec_init_process(struct comp_dev *dev) +static int passthrough_codec_init_process(struct comp_dev *dev) { struct codec_data *codec = comp_get_codec(dev); @@ -53,7 +57,7 @@ int passthrough_codec_init_process(struct comp_dev *dev) return 0; } -int passthrough_codec_process(struct comp_dev *dev) +static int passthrough_codec_process(struct comp_dev *dev) { struct codec_data *codec = comp_get_codec(dev); struct comp_data *cd = comp_get_drvdata(dev); @@ -68,7 +72,7 @@ int passthrough_codec_process(struct comp_dev *dev) return 0; } -int passthrough_codec_apply_config(struct comp_dev *dev) +static int passthrough_codec_apply_config(struct comp_dev *dev) { comp_info(dev, "passthrough_codec_apply_config()"); @@ -76,7 +80,7 @@ int passthrough_codec_apply_config(struct comp_dev *dev) return 0; } -int passthrough_codec_reset(struct comp_dev *dev) +static int passthrough_codec_reset(struct comp_dev *dev) { comp_info(dev, "passthrough_codec_reset()"); @@ -84,7 +88,7 @@ int passthrough_codec_reset(struct comp_dev *dev) return 0; } -int passthrough_codec_free(struct comp_dev *dev) +static int passthrough_codec_free(struct comp_dev *dev) { struct codec_data *codec = comp_get_codec(dev); @@ -95,3 +99,15 @@ int passthrough_codec_free(struct comp_dev *dev) return 0; } + +static struct codec_interface passthrough_interface = { + .init = passthrough_codec_init, + .prepare = passthrough_codec_prepare, + .init_process = passthrough_codec_init_process, + .process = passthrough_codec_process, + .apply_config = passthrough_codec_apply_config, + .reset = passthrough_codec_reset, + .free = passthrough_codec_free +}; + +DECLARE_CODEC_ADAPTER(passthrough_interface, passthrough_uuid, passthrough_tr); diff --git a/src/audio/codec_adapter/codec/waves.c b/src/audio/codec_adapter/codec/waves.c index cb873c268..d61f7c7c7 100644 --- a/src/audio/codec_adapter/codec/waves.c +++ b/src/audio/codec_adapter/codec/waves.c @@ -21,6 +21,11 @@ #define MAX_CONFIG_SIZE_BYTES (8192) #define NUM_IO_STREAMS (1) +/* d944281a-afe9-4695-a043-d7f62b89538e*/ +DECLARE_SOF_RT_UUID("waves_codec", waves_uuid, 0xd944281a, 0xafe9, 0x4695, + 0xa0, 0x43, 0xd7, 0xf6, 0x2b, 0x89, 0x53, 0x8e); +DECLARE_TR_CTX(waves_tr, SOF_UUID(waves_uuid), LOG_LEVEL_INFO); + struct waves_codec_data { uint32_t sample_rate; uint32_t buffer_bytes; @@ -758,3 +763,15 @@ int waves_codec_free(struct comp_dev *dev) comp_dbg(dev, "waves_codec_free()"); return 0; } + +static struct codec_interface waves_interface = { + .init = waves_codec_init, + .prepare = waves_codec_prepare, + .init_process = waves_codec_init_process, + .process = waves_codec_process, + .apply_config = waves_codec_apply_config, + .reset = waves_codec_reset, + .free = waves_codec_free +}; + +DECLARE_CODEC_ADAPTER(waves_interface, waves_uuid, waves_tr); diff --git a/src/audio/codec_adapter/codec_adapter.c b/src/audio/codec_adapter/codec_adapter.c index dc93f475e..92f046d39 100644 --- a/src/audio/codec_adapter/codec_adapter.c +++ b/src/audio/codec_adapter/codec_adapter.c @@ -22,13 +22,8 @@ #include #include -static const struct comp_driver comp_codec_adapter; - -/* d8218443-5ff3-4a4c-b388-6cfe07b956aa */ -DECLARE_SOF_RT_UUID("codec_adapter", ca_uuid, 0xd8218443, 0x5ff3, 0x4a4c, - 0xb3, 0x88, 0x6c, 0xfe, 0x07, 0xb9, 0x56, 0xaa); - -DECLARE_TR_CTX(ca_tr, SOF_UUID(ca_uuid), LOG_LEVEL_INFO); +int load_setup_config(struct comp_dev *dev, void *cfg, uint32_t size); +int validate_setup_config(struct ca_config *cfg); /** * \brief Create a codec adapter component. @@ -37,8 +32,9 @@ DECLARE_TR_CTX(ca_tr, SOF_UUID(ca_uuid), LOG_LEVEL_INFO); * * \return: a pointer to newly created codec adapter component. */ -static struct comp_dev *codec_adapter_new(const struct comp_driver *drv, - struct sof_ipc_comp *comp) +struct comp_dev *codec_adapter_new(const struct comp_driver *drv, + struct sof_ipc_comp *comp, + struct codec_interface *interface) { int ret; struct comp_dev *dev; @@ -82,7 +78,7 @@ static struct comp_dev *codec_adapter_new(const struct comp_driver *drv, goto err; } /* Init processing codec */ - ret = codec_init(dev); + ret = codec_init(dev, interface); if (ret) { comp_err(dev, "codec_adapter_new() %d: codec initialization failed", ret); @@ -100,7 +96,7 @@ err: return NULL; } -static inline int validate_setup_config(struct ca_config *cfg) +int validate_setup_config(struct ca_config *cfg) { /* TODO: validate codec_adapter setup parameters */ return 0; @@ -121,7 +117,7 @@ static inline int validate_setup_config(struct ca_config *cfg) * 0 -> success * negative value -> failure. */ -static int load_setup_config(struct comp_dev *dev, void *cfg, uint32_t size) +int load_setup_config(struct comp_dev *dev, void *cfg, uint32_t size) { int ret; void *lib_cfg; @@ -178,7 +174,7 @@ end: * 0 - success * value < 0 - failure. */ -static int codec_adapter_prepare(struct comp_dev *dev) +int codec_adapter_prepare(struct comp_dev *dev) { int ret; struct comp_data *cd = comp_get_drvdata(dev); @@ -274,8 +270,8 @@ static int codec_adapter_prepare(struct comp_dev *dev) return 0; } -static int codec_adapter_params(struct comp_dev *dev, - struct sof_ipc_stream_params *params) +int codec_adapter_params(struct comp_dev *dev, + struct sof_ipc_stream_params *params) { int ret; struct comp_data *cd = comp_get_drvdata(dev); @@ -363,7 +359,7 @@ static void generate_zeroes(struct comp_buffer *sink, uint32_t bytes) comp_update_buffer_produce(sink, bytes); } -static int codec_adapter_copy(struct comp_dev *dev) +int codec_adapter_copy(struct comp_dev *dev) { int ret = 0; uint32_t bytes_to_process, copy_bytes, processed = 0, produced = 0; @@ -640,8 +636,8 @@ static int codec_adapter_ctrl_set_data(struct comp_dev *dev, } /* Used to pass standard and bespoke commands (with data) to component */ -static int codec_adapter_cmd(struct comp_dev *dev, int cmd, void *data, - int max_data_size) +int codec_adapter_cmd(struct comp_dev *dev, int cmd, void *data, + int max_data_size) { int ret; struct sof_ipc_ctrl_data *cdata = data; @@ -666,14 +662,14 @@ static int codec_adapter_cmd(struct comp_dev *dev, int cmd, void *data, return ret; } -static int codec_adapter_trigger(struct comp_dev *dev, int cmd) +int codec_adapter_trigger(struct comp_dev *dev, int cmd) { comp_dbg(dev, "codec_adapter_trigger(): component got trigger cmd %x", cmd); return comp_set_state(dev, cmd); } -static int codec_adapter_reset(struct comp_dev *dev) +int codec_adapter_reset(struct comp_dev *dev) { int ret; struct comp_data *cd = comp_get_drvdata(dev); @@ -693,7 +689,7 @@ static int codec_adapter_reset(struct comp_dev *dev) return comp_set_state(dev, COMP_TRIGGER_RESET); } -static void codec_adapter_free(struct comp_dev *dev) +void codec_adapter_free(struct comp_dev *dev) { int ret; struct comp_data *cd = comp_get_drvdata(dev); @@ -709,31 +705,3 @@ static void codec_adapter_free(struct comp_dev *dev) rfree(cd); rfree(dev); } - -static const struct comp_driver comp_codec_adapter = { - .type = SOF_COMP_NONE, - .uid = SOF_RT_UUID(ca_uuid), - .tctx = &ca_tr, - .ops = { - .create = codec_adapter_new, - .prepare = codec_adapter_prepare, - .params = codec_adapter_params, - .copy = codec_adapter_copy, - .cmd = codec_adapter_cmd, - .trigger = codec_adapter_trigger, - .reset = codec_adapter_reset, - .free = codec_adapter_free, - }, -}; - -static SHARED_DATA struct comp_driver_info comp_codec_adapter_info = { - .drv = &comp_codec_adapter, -}; - -UT_STATIC void sys_comp_codec_adapter_init(void) -{ - comp_register(platform_shared_get(&comp_codec_adapter_info, - sizeof(comp_codec_adapter_info))); -} - -DECLARE_MODULE(sys_comp_codec_adapter_init); diff --git a/src/include/sof/audio/codec_adapter/codec/generic.h b/src/include/sof/audio/codec_adapter/codec/generic.h index c2b48596c..2609445dc 100644 --- a/src/include/sof/audio/codec_adapter/codec/generic.h +++ b/src/include/sof/audio/codec_adapter/codec/generic.h @@ -13,6 +13,8 @@ #define __SOF_AUDIO_CODEC_GENERIC__ #include +#include +#include #define comp_get_codec(d) (&(((struct comp_data *)((d)->priv_data))->codec)) #define CODEC_GET_INTERFACE_ID(id) ((id) >> 0x8) @@ -25,6 +27,41 @@ (value)); \ } while (0) +#define DECLARE_CODEC_ADAPTER(adapter, uuid, tr) \ +static struct comp_dev *adapter_shim_new(const struct comp_driver *drv, \ + struct sof_ipc_comp *comp)\ +{ \ + return codec_adapter_new(drv, comp, &(adapter));\ +} \ +\ +static const struct comp_driver comp_codec_adapter = { \ + .type = SOF_COMP_NONE, \ + .uid = SOF_RT_UUID(uuid), \ + .tctx = &(tr), \ + .ops = { \ + .create = adapter_shim_new, \ + .prepare = codec_adapter_prepare, \ + .params = codec_adapter_params, \ + .copy = codec_adapter_copy, \ + .cmd = codec_adapter_cmd, \ + .trigger = codec_adapter_trigger, \ + .reset = codec_adapter_reset, \ + .free = codec_adapter_free, \ + }, \ +}; \ +\ +static SHARED_DATA struct comp_driver_info comp_codec_adapter_info = { \ + .drv = &comp_codec_adapter, \ +}; \ +\ +UT_STATIC void sys_comp_codec_##adapter_init(void) \ +{ \ + comp_register(platform_shared_get(&comp_codec_adapter_info, \ + sizeof(comp_codec_adapter_info))); \ +} \ +\ +DECLARE_MODULE(sys_comp_codec_##adapter_init) + /*****************************************************************************/ /* Codec generic data types */ /*****************************************************************************/ @@ -205,7 +242,7 @@ struct comp_data { /*****************************************************************************/ int codec_load_config(struct comp_dev *dev, void *cfg, size_t size, enum codec_cfg_type type); -int codec_init(struct comp_dev *dev); +int codec_init(struct comp_dev *dev, struct codec_interface *interface); void *codec_allocate_memory(struct comp_dev *dev, uint32_t size, uint32_t alignment); int codec_free_memory(struct comp_dev *dev, void *ptr); @@ -217,4 +254,15 @@ int codec_apply_runtime_config(struct comp_dev *dev); int codec_reset(struct comp_dev *dev); int codec_free(struct comp_dev *dev); +struct comp_dev *codec_adapter_new(const struct comp_driver *drv, + struct sof_ipc_comp *comp, + struct codec_interface *interface); +int codec_adapter_prepare(struct comp_dev *dev); +int codec_adapter_params(struct comp_dev *dev, struct sof_ipc_stream_params *params); +int codec_adapter_copy(struct comp_dev *dev); +int codec_adapter_cmd(struct comp_dev *dev, int cmd, void *data, int max_data_size); +int codec_adapter_trigger(struct comp_dev *dev, int cmd); +void codec_adapter_free(struct comp_dev *dev); +int codec_adapter_reset(struct comp_dev *dev); + #endif /* __SOF_AUDIO_CODEC_GENERIC__ */ diff --git a/src/include/sof/audio/codec_adapter/interfaces.h b/src/include/sof/audio/codec_adapter/interfaces.h deleted file mode 100644 index dfc4a4ce0..000000000 --- a/src/include/sof/audio/codec_adapter/interfaces.h +++ /dev/null @@ -1,74 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2020 Intel Corporation. All rights reserved. - * - * - * \file interfaces.h - * \brief Description of supported codecs - * \author Marcin Rajwa - * - */ -#ifndef __SOF_AUDIO_CODEC_INTERFACES__ -#define __SOF_AUDIO_CODEC_INTERFACES__ - -#if CONFIG_CADENCE_CODEC -#include -#endif /* CONFIG_CADENCE_CODEC */ - -#if CONFIG_PASSTHROUGH_CODEC -#include -#endif - -#if CONFIG_WAVES_CODEC -#include -#endif - -#define CADENCE_ID 0xCADE01 -#define PASSTHROUGH_ID 0xD03311 -#define WAVES_ID 0x574101 - -/*****************************************************************************/ -/* Linked codecs interfaces */ -/*****************************************************************************/ -static struct codec_interface interfaces[] = { -#if CONFIG_CADENCE_CODEC - { - .id = CADENCE_ID, /**< Cadence interface */ - .init = cadence_codec_init, - .prepare = cadence_codec_prepare, - .init_process = cadence_codec_init_process, - .process = cadence_codec_process, - .apply_config = cadence_codec_apply_config, - .reset = cadence_codec_reset, - .free = cadence_codec_free - }, -#endif /* CONFIG_CADENCE_CODEC */ - -#ifdef CONFIG_PASSTHROUGH_CODEC - { - .id = PASSTHROUGH_ID, /** passthrough interface */ - .init = passthrough_codec_init, - .prepare = passthrough_codec_prepare, - .init_process = passthrough_codec_init_process, - .process = passthrough_codec_process, - .apply_config = passthrough_codec_apply_config, - .reset = passthrough_codec_reset, - .free = passthrough_codec_free - }, -#endif /* CONFIG_PASSTHROUGH_CODEC */ - -#if CONFIG_WAVES_CODEC - { - .id = WAVES_ID, - .init = waves_codec_init, - .prepare = waves_codec_prepare, - .init_process = waves_codec_init_process, - .process = waves_codec_process, - .apply_config = waves_codec_apply_config, - .reset = waves_codec_reset, - .free = waves_codec_free - }, -#endif /* CONFIG_WAVES_CODEC */ -}; - -#endif /* __SOF_AUDIO_CODEC_INTERFACES__ */