Skip to content

Commit

Permalink
audio: module adapter: create ipc3 and ipc4 specific source file
Browse files Browse the repository at this point in the history
create ipc3 and ipc4 specific source file, these files will
only be used to store specific code accordingly.

Signed-off-by: Baofeng Tian <[email protected]>
  • Loading branch information
btian1 committed Sep 4, 2023
1 parent d964b7b commit 7276bcc
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 55 deletions.
6 changes: 5 additions & 1 deletion src/audio/module_adapter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# SPDX-License-Identifier: BSD-3-Clause


add_local_sources(sof module_adapter.c module/generic.c)
if(CONFIG_IPC_MAJOR_3)
add_local_sources(sof module_adapter.c module_adapter_ipc3.c module/generic.c)
elseif(CONFIG_IPC_MAJOR_4)
add_local_sources(sof module_adapter.c module_adapter_ipc4.c module/generic.c)
endif()

if((NOT CONFIG_LIBRARY) OR CONFIG_LIBRARY_STATIC)
if(CONFIG_CADENCE_CODEC)
Expand Down
58 changes: 4 additions & 54 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,62 +90,12 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
comp_set_drvdata(dev, mod);
list_init(&mod->sink_buffer_list);

#if CONFIG_IPC_MAJOR_3
const unsigned char *data;
uint32_t size;

switch (config->type) {
case SOF_COMP_VOLUME:
{
const struct ipc_config_volume *ipc_volume = spec;

size = sizeof(*ipc_volume);
data = spec;
break;
}
case SOF_COMP_SRC:
{
const struct ipc_config_src *ipc_src = spec;

size = sizeof(*ipc_src);
data = spec;
break;
}
default:
{
const struct ipc_config_process *ipc_module_adapter = spec;

size = ipc_module_adapter->size;
data = ipc_module_adapter->data;
break;
}
}

/* Copy initial config */
if (size) {
ret = module_load_config(dev, data, size);
if (ret) {
comp_err(dev, "module_adapter_new() error %d: config loading has failed.",
ret);
goto err;
}
dst->init_data = dst->data;
} else {
ret = module_adapter_init_data(dev, dst, config, spec);
if (ret) {
comp_err(dev, "module_adapter_new() %d: module init data failed",
ret);
goto err;
}
#else
if (drv->type == SOF_COMP_MODULE_ADAPTER) {
const struct ipc_config_process *ipc_module_adapter = spec;

dst->init_data = ipc_module_adapter->data;
dst->size = ipc_module_adapter->size;
dst->avail = true;

memcpy(&dst->base_cfg, ipc_module_adapter->data, sizeof(dst->base_cfg));
} else {
dst->init_data = spec;
}
#endif

/* Modules must modify them if they support more than 1 source/sink */
mod->max_sources = 1;
Expand Down
88 changes: 88 additions & 0 deletions src/audio/module_adapter/module_adapter_ipc3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2023 Intel Corporation. All rights reserved.
//
// Author: Baofeng Tian <[email protected]>

/**
* \file
* \brief Module Adapter ipc3: module adapter ipc3 specific code
* \author Baofeng Tian <[email protected]>
*/

#include <sof/audio/buffer.h>
#include <sof/audio/component.h>
#include <sof/audio/ipc-config.h>
#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/pipeline.h>
#include <sof/common.h>
#include <sof/platform.h>
#include <sof/ut.h>
#include <rtos/interrupt.h>
#include <limits.h>
#include <stdint.h>

LOG_MODULE_DECLARE(module_adapter, CONFIG_SOF_LOG_LEVEL);

/*
* \module adapter data initialize.
* \param[in] dev - device.
* \param[in] config - component ipc descriptor pointer.
* \param[in] dst - module adatper config data.
* \param[in] spec - passdowned data from driver.
*
* \return: 0 - no error; < 0, error happened.
*/
int module_adapter_init_data(struct comp_dev *dev,
struct module_config *dst,
const struct comp_ipc_config *config,
const void *spec)
{
int ret;

const unsigned char *data;
uint32_t size;

switch (config->type) {
case SOF_COMP_VOLUME:
{
const struct ipc_config_volume *ipc_volume = spec;

size = sizeof(*ipc_volume);
data = spec;
break;
}
case SOF_COMP_SRC:
{
const struct ipc_config_src *ipc_src = spec;

size = sizeof(*ipc_src);
data = spec;
break;
}
default:
{
const struct ipc_config_process *ipc_module_adapter = spec;

size = ipc_module_adapter->size;
data = ipc_module_adapter->data;
break;
}
}

/* Copy initial config */
if (size) {
ret = module_load_config(dev, data, size);
if (ret < 0) {
comp_err(dev, "module_adapter_new() error %d: config loading has failed.",
ret);
return ret;
}
dst->init_data = dst->data;
} else {
return -EINVAL;
}

return 0;
}

56 changes: 56 additions & 0 deletions src/audio/module_adapter/module_adapter_ipc4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2023 Intel Corporation. All rights reserved.
//
// Author: Baofeng Tian <[email protected]>

/**
* \file
* \brief Module Adapter ipc4: module adapter ipc4 specific code
* \author Baofeng Tian <[email protected]>
*/

#include <sof/audio/buffer.h>
#include <sof/audio/component.h>
#include <sof/audio/ipc-config.h>
#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/pipeline.h>
#include <sof/common.h>
#include <sof/platform.h>
#include <sof/ut.h>
#include <rtos/interrupt.h>
#include <limits.h>
#include <stdint.h>

LOG_MODULE_DECLARE(module_adapter, CONFIG_SOF_LOG_LEVEL);

/*
* \module adapter data initialize.
* \param[in] dev - device.
* \param[in] config - component ipc descriptor pointer.
* \param[in] dst - module adatper config data.
* \param[in] spec - passdowned data from driver.
*
* \return: 0 - no error; < 0, error happened.
*/
int module_adapter_init_data(struct comp_dev *dev,
struct module_config *dst,
const struct comp_ipc_config *config,
const void *spec)
{
if (dev->drv->type == SOF_COMP_MODULE_ADAPTER) {
const struct ipc_config_process *ipc_module_adapter = spec;

dst->init_data = ipc_module_adapter->data;
dst->size = ipc_module_adapter->size;
dst->avail = true;

memcpy_s(&dst->base_cfg, sizeof(dst->base_cfg), ipc_module_adapter->data,
sizeof(dst->base_cfg));
} else {
dst->init_data = spec;
}

return 0;
}

5 changes: 5 additions & 0 deletions src/include/sof/audio/module_adapter/module/generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,9 @@ static inline int module_process_stream(struct processing_module *mod,
output_buffers, num_output_buffers);
}

int module_adapter_init_data(struct comp_dev *dev,
struct module_config *dst,
const struct comp_ipc_config *config,
const void *spec);

#endif /* __SOF_AUDIO_MODULE_GENERIC__ */
1 change: 1 addition & 0 deletions test/cmocka/src/audio/eq_fir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_library(audio_for_eq_fir STATIC
${PROJECT_SOURCE_DIR}/src/math/fir_hifi3.c
${PROJECT_SOURCE_DIR}/src/math/numbers.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter_ipc3.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module/generic.c
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
Expand Down
1 change: 1 addition & 0 deletions test/cmocka/src/audio/eq_iir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_library(audio_for_eq_iir STATIC
${PROJECT_SOURCE_DIR}/src/math/iir_df2t_hifi3.c
${PROJECT_SOURCE_DIR}/src/math/numbers.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter_ipc3.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module/generic.c
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
Expand Down
1 change: 1 addition & 0 deletions test/cmocka/src/audio/mixer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cmocka_test(mixer
${PROJECT_SOURCE_DIR}/src/ipc/ipc-common.c
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter_ipc3.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module/generic.c
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
Expand Down
1 change: 1 addition & 0 deletions test/cmocka/src/audio/mux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_library(
${PROJECT_SOURCE_DIR}/src/ipc/ipc-helper.c
${PROJECT_SOURCE_DIR}/test/cmocka/src/notifier_mocks.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter_ipc3.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module/generic.c
)
sof_append_relative_path_definitions(audio_mux)
Expand Down
1 change: 1 addition & 0 deletions test/cmocka/src/audio/volume/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_library(audio_for_volume STATIC
${PROJECT_SOURCE_DIR}/src/audio/volume/volume_hifi3_with_peakvol.c
${PROJECT_SOURCE_DIR}/src/audio/volume/volume_hifi4_with_peakvol.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module_adapter_ipc3.c
${PROJECT_SOURCE_DIR}/src/audio/module_adapter/module/generic.c
${PROJECT_SOURCE_DIR}/src/audio/buffer.c
${PROJECT_SOURCE_DIR}/src/audio/source_api_helper.c
Expand Down
9 changes: 9 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,19 @@ elseif(CONFIG_IPC_MAJOR_4)
)
endif()

if(CONFIG_IPC_MAJOR_3)
zephyr_library_sources_ifdef(CONFIG_COMP_MODULE_ADAPTER
${SOF_AUDIO_PATH}/module_adapter/module_adapter.c
${SOF_AUDIO_PATH}/module_adapter/module_adapter_ipc3.c
${SOF_AUDIO_PATH}/module_adapter/module/generic.c
)
elseif(CONFIG_IPC_MAJOR_4)
zephyr_library_sources_ifdef(CONFIG_COMP_MODULE_ADAPTER
${SOF_AUDIO_PATH}/module_adapter/module_adapter.c
${SOF_AUDIO_PATH}/module_adapter/module_adapter_ipc4.c
${SOF_AUDIO_PATH}/module_adapter/module/generic.c
)
endif()

zephyr_library_sources_ifdef(CONFIG_LIBRARY_MANAGER
${SOF_SRC_PATH}/library_manager/lib_manager.c
Expand Down

0 comments on commit 7276bcc

Please sign in to comment.