codec_adapter: cadence: Introduce cadence_codec_post_init

This new function encapsulates all Cadence API calls at init time. We
introduce this new function because the init API calls need to be
done after we figure out cadence codec api id.

Right now cadence codec api id is hardcoded to DEFAULT_CODEC_ID but
later it will be needed to be determined dyncamically at runtime.

It will be sent from host via sof_ipc_stream_params.

Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
This commit is contained in:
Daniel Baluta 2022-03-23 13:30:20 +02:00 committed by Daniel Baluta
parent cf808895cc
commit 98862784fb
1 changed files with 50 additions and 33 deletions

View File

@ -94,13 +94,59 @@ static struct cadence_api cadence_api_table[] = {
#endif
};
static int cadence_codec_post_init(struct processing_module *mod)
{
int ret;
struct comp_dev *dev = mod->dev;
struct module_data *codec = comp_get_module_data(dev);
struct cadence_codec_data *cd = codec->private;
uint32_t obj_size;
comp_dbg(dev, "cadence_codec_post_init() start");
/* Obtain codec name */
API_CALL(cd, XA_API_CMD_GET_LIB_ID_STRINGS,
XA_CMD_TYPE_LIB_NAME, cd->name, ret);
if (ret != LIB_NO_ERROR) {
comp_err(dev, "cadence_codec_init() error %x: failed to get lib name",
ret);
return ret;
}
/* Get codec object size */
API_CALL(cd, XA_API_CMD_GET_API_SIZE, 0, &obj_size, ret);
if (ret != LIB_NO_ERROR) {
comp_err(dev, "cadence_codec_init() error %x: failed to get lib object size",
ret);
return ret;
}
/* Allocate space for codec object */
cd->self = rballoc(0, SOF_MEM_CAPS_RAM, obj_size);
if (!cd->self) {
comp_err(dev, "cadence_codec_init(): failed to allocate space for lib object");
return -ENOMEM;
}
comp_dbg(dev, "cadence_codec_post_init(): allocated %d bytes for lib object", obj_size);
/* Set all params to their default values */
API_CALL(cd, XA_API_CMD_INIT, XA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS,
NULL, ret);
if (ret != LIB_NO_ERROR) {
rfree(cd->self);
return ret;
}
comp_dbg(dev, "cadence_codec_post_init() done");
return 0;
}
static int cadence_codec_init(struct processing_module *mod)
{
int ret;
struct comp_dev *dev = mod->dev;
struct module_data *codec = comp_get_module_data(dev);
struct cadence_codec_data *cd = NULL;
uint32_t obj_size;
uint32_t no_of_api = ARRAY_SIZE(cadence_api_table);
uint32_t api_id = CODEC_GET_API_ID(DEFAULT_CODEC_ID);
uint32_t i;
@ -160,38 +206,9 @@ static int cadence_codec_init(struct processing_module *mod)
setup_cfg->avail = true;
}
/* Obtain codec name */
API_CALL(cd, XA_API_CMD_GET_LIB_ID_STRINGS,
XA_CMD_TYPE_LIB_NAME, cd->name, ret);
if (ret != LIB_NO_ERROR) {
comp_err(dev, "cadence_codec_init() error %x: failed to get lib name",
ret);
goto free;
}
/* Get codec object size */
API_CALL(cd, XA_API_CMD_GET_API_SIZE, 0, &obj_size, ret);
if (ret != LIB_NO_ERROR) {
comp_err(dev, "cadence_codec_init() error %x: failed to get lib object size",
ret);
goto free;
}
/* Allocate space for codec object */
cd->self = rballoc(0, SOF_MEM_CAPS_RAM, obj_size);
if (!cd->self) {
comp_err(dev, "cadence_codec_init(): failed to allocate space for lib object");
ret = -ENOMEM;
goto free;
}
comp_dbg(dev, "cadence_codec_init(): allocated %d bytes for lib object", obj_size);
/* Set all params to their default values */
API_CALL(cd, XA_API_CMD_INIT, XA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS,
NULL, ret);
if (ret != LIB_NO_ERROR) {
rfree(cd->self);
goto free;
}
ret = cadence_codec_post_init(mod);
if (ret)
return ret;
comp_dbg(dev, "cadence_codec_init() done");