diff --git a/src/audio/codec_adapter/codec/cadence.c b/src/audio/codec_adapter/codec/cadence.c index 907b44bdc886..b05427e3e553 100644 --- a/src/audio/codec_adapter/codec/cadence.c +++ b/src/audio/codec_adapter/codec/cadence.c @@ -95,7 +95,7 @@ static struct cadence_api cadence_api_table[] = { int cadence_codec_init(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(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); @@ -104,14 +104,14 @@ int cadence_codec_init(struct comp_dev *dev) comp_dbg(dev, "cadence_codec_init() start"); - cd = codec_allocate_memory(dev, sizeof(struct cadence_codec_data), 0); + cd = module_allocate_memory(dev, sizeof(struct cadence_codec_data), 0); if (!cd) { comp_err(dev, "cadence_codec_init(): failed to allocate memory for cadence codec data"); return -ENOMEM; } codec->private = cd; - codec->cpd.init_done = 0; + codec->mpd.init_done = 0; cd->self = NULL; cd->mem_tabs = NULL; cd->api = NULL; @@ -137,7 +137,7 @@ int cadence_codec_init(struct comp_dev *dev) if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_init() error %x: failed to get lib name", ret); - codec_free_memory(dev, cd); + module_free_memory(dev, cd); goto out; } /* Get codec object size */ @@ -145,14 +145,14 @@ int cadence_codec_init(struct comp_dev *dev) if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_init() error %x: failed to get lib object size", ret); - codec_free_memory(dev, cd); + module_free_memory(dev, cd); goto out; } /* Allocate space for codec object */ - cd->self = codec_allocate_memory(dev, obj_size, 0); + cd->self = module_allocate_memory(dev, obj_size, 0); if (!cd->self) { comp_err(dev, "cadence_codec_init(): failed to allocate space for lib object"); - codec_free_memory(dev, cd); + module_free_memory(dev, cd); goto out; } else { comp_dbg(dev, "cadence_codec_init(): allocated %d bytes for lib object", @@ -172,19 +172,19 @@ int cadence_codec_init(struct comp_dev *dev) return ret; } -static int apply_config(struct comp_dev *dev, enum codec_cfg_type type) +static int apply_config(struct comp_dev *dev, enum module_cfg_type type) { int ret = 0; int size; - struct codec_config *cfg; + struct module_config *cfg; void *data; - struct codec_param *param; - struct codec_data *codec = comp_get_codec(dev); + struct module_param *param; + struct module_data *codec = comp_get_module_data(dev); struct cadence_codec_data *cd = codec->private; comp_dbg(dev, "apply_config() start"); - cfg = (type == CODEC_CFG_SETUP) ? &codec->s_cfg : + cfg = (type == MODULE_CFG_SETUP) ? &codec->s_cfg : &codec->r_cfg; data = cfg->data; size = cfg->size; @@ -228,7 +228,7 @@ static int init_memory_tables(struct comp_dev *dev) { int ret, no_mem_tables, i, mem_type, mem_size, mem_alignment; void *ptr, *scratch, *persistent; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct cadence_codec_data *cd = codec->private; scratch = NULL; @@ -277,7 +277,7 @@ static int init_memory_tables(struct comp_dev *dev) goto err; } /* Allocate memory for this type, taking alignment into account */ - ptr = codec_allocate_memory(dev, mem_size, mem_alignment); + ptr = module_allocate_memory(dev, mem_size, mem_alignment); if (!ptr) { comp_err(dev, "init_memory_tables() error %x: failed to allocate memory for %d", ret, mem_type); @@ -300,12 +300,12 @@ static int init_memory_tables(struct comp_dev *dev) persistent = ptr; break; case XA_MEMTYPE_INPUT: - codec->cpd.in_buff = ptr; - codec->cpd.in_buff_size = mem_size; + codec->mpd.in_buff = ptr; + codec->mpd.in_buff_size = mem_size; break; case XA_MEMTYPE_OUTPUT: - codec->cpd.out_buff = ptr; - codec->cpd.out_buff_size = mem_size; + codec->mpd.out_buff = ptr; + codec->mpd.out_buff_size = mem_size; break; default: comp_err(dev, "init_memory_tables() error %x: unrecognized memory type!", @@ -321,19 +321,19 @@ static int init_memory_tables(struct comp_dev *dev) return 0; err: if (scratch) - codec_free_memory(dev, scratch); + module_free_memory(dev, scratch); if (persistent) - codec_free_memory(dev, persistent); - if (codec->cpd.in_buff) - codec_free_memory(dev, codec->cpd.in_buff); - if (codec->cpd.out_buff) - codec_free_memory(dev, codec->cpd.out_buff); + module_free_memory(dev, persistent); + if (codec->mpd.in_buff) + module_free_memory(dev, codec->mpd.in_buff); + if (codec->mpd.out_buff) + module_free_memory(dev, codec->mpd.out_buff); return ret; } static int cadence_codec_get_samples(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); uint32_t api_id = CODEC_GET_API_ID(codec->id); comp_dbg(dev, "cadence_codec_get_samples() start"); @@ -356,10 +356,10 @@ static int cadence_codec_get_samples(struct comp_dev *dev) static int cadence_codec_init_process(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct cadence_codec_data *cd = codec->private; - API_CALL(cd, XA_API_CMD_SET_INPUT_BYTES, 0, &codec->cpd.avail, ret); + API_CALL(cd, XA_API_CMD_SET_INPUT_BYTES, 0, &codec->mpd.avail, ret); if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_init_process() error %x: failed to set size of input data", ret); @@ -374,14 +374,14 @@ static int cadence_codec_init_process(struct comp_dev *dev) } API_CALL(cd, XA_API_CMD_INIT, XA_CMD_TYPE_INIT_DONE_QUERY, - &codec->cpd.init_done, ret); + &codec->mpd.init_done, ret); if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_init_process() error %x: failed to get lib init status", ret); return ret; } - API_CALL(cd, XA_API_CMD_GET_CURIDX_INPUT_BUF, 0, &codec->cpd.consumed, ret); + API_CALL(cd, XA_API_CMD_GET_CURIDX_INPUT_BUF, 0, &codec->mpd.consumed, ret); if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_init_process() error %x: could not get consumed bytes", ret); @@ -393,7 +393,7 @@ static int cadence_codec_init_process(struct comp_dev *dev) int cadence_codec_prepare(struct comp_dev *dev) { int ret = 0, mem_tabs_size; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct cadence_codec_data *cd = codec->private; comp_dbg(dev, "cadence_codec_prepare() start"); @@ -407,7 +407,7 @@ int cadence_codec_prepare(struct comp_dev *dev) comp_warn(dev, "cadence_codec_prepare(): no new setup configuration available, using the old one"); codec->s_cfg.avail = true; } - ret = apply_config(dev, CODEC_CFG_SETUP); + ret = apply_config(dev, MODULE_CFG_SETUP); if (ret) { comp_err(dev, "cadence_codec_prepare() error %x: failed to applay setup config", ret); @@ -420,7 +420,7 @@ int cadence_codec_prepare(struct comp_dev *dev) /* Runtime config */ if (codec->r_cfg.avail) { - ret = apply_config(dev, CODEC_CFG_RUNTIME); + ret = apply_config(dev, MODULE_CFG_RUNTIME); if (ret) { comp_err(dev, "cadence_codec_prepare() error %x: failed to applay runtime config", ret); @@ -436,7 +436,7 @@ int cadence_codec_prepare(struct comp_dev *dev) goto err; } - cd->mem_tabs = codec_allocate_memory(dev, mem_tabs_size, 4); + cd->mem_tabs = module_allocate_memory(dev, mem_tabs_size, 4); if (!cd->mem_tabs) { comp_err(dev, "cadence_codec_prepare() error: failed to allocate space for memtabs"); ret = -ENOMEM; @@ -472,7 +472,7 @@ int cadence_codec_prepare(struct comp_dev *dev) * in codec_adapter_copy(). */ API_CALL(cd, XA_API_CMD_INIT, XA_CMD_TYPE_INIT_DONE_QUERY, - &codec->cpd.init_done, ret); + &codec->mpd.init_done, ret); if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_init_process() error %x: failed to get lib init status", ret); @@ -482,24 +482,24 @@ int cadence_codec_prepare(struct comp_dev *dev) comp_dbg(dev, "cadence_codec_prepare() done"); return 0; free: - codec_free_memory(dev, cd->mem_tabs); + module_free_memory(dev, cd->mem_tabs); err: return ret; } int cadence_codec_process(struct comp_dev *dev) { - struct comp_data *comp_data = comp_get_drvdata(dev); - struct comp_buffer *local_buff = comp_data->local_buff; - struct codec_data *codec = comp_get_codec(dev); + struct processing_module *mod = comp_get_drvdata(dev); + struct comp_buffer *local_buff = mod->local_buff; + struct module_data *codec = comp_get_module_data(dev); struct cadence_codec_data *cd = codec->private; int ret; /* do not proceed with processing if not enough free left in the local buffer */ - if (codec->cpd.init_done) { + if (codec->mpd.init_done) { int output_bytes = cadence_codec_get_samples(dev) * - comp_data->stream_params.sample_container_bytes * - comp_data->stream_params.channels; + mod->stream_params.sample_container_bytes * + mod->stream_params.channels; if (local_buff->stream.free < output_bytes) return -ENOSPC; @@ -509,7 +509,7 @@ int cadence_codec_process(struct comp_dev *dev) comp_dbg(dev, "cadence_codec_process() start"); - API_CALL(cd, XA_API_CMD_SET_INPUT_BYTES, 0, &codec->cpd.avail, ret); + API_CALL(cd, XA_API_CMD_SET_INPUT_BYTES, 0, &codec->mpd.avail, ret); if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_process() error %x: failed to set size of input data", ret); @@ -523,14 +523,14 @@ int cadence_codec_process(struct comp_dev *dev) goto err; } - API_CALL(cd, XA_API_CMD_GET_OUTPUT_BYTES, 0, &codec->cpd.produced, ret); + API_CALL(cd, XA_API_CMD_GET_OUTPUT_BYTES, 0, &codec->mpd.produced, ret); if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_process() error %x: could not get produced bytes", ret); goto err; } - API_CALL(cd, XA_API_CMD_GET_CURIDX_INPUT_BUF, 0, &codec->cpd.consumed, ret); + API_CALL(cd, XA_API_CMD_GET_CURIDX_INPUT_BUF, 0, &codec->mpd.consumed, ret); if (ret != LIB_NO_ERROR) { comp_err(dev, "cadence_codec_process() error %x: could not get consumed bytes", ret); @@ -546,7 +546,7 @@ int cadence_codec_process(struct comp_dev *dev) int cadence_codec_apply_config(struct comp_dev *dev) { - return apply_config(dev, CODEC_CFG_RUNTIME); + return apply_config(dev, MODULE_CFG_RUNTIME); } int cadence_codec_reset(struct comp_dev *dev) @@ -557,7 +557,7 @@ int cadence_codec_reset(struct comp_dev *dev) * runtime parameters therefore we need to free all the resources * and start over. */ - codec_free_all_memory(dev); + module_free_all_memory(dev); ret = cadence_codec_init(dev); if (ret) { comp_err(dev, "cadence_codec_reset() error %x: could not re-initialize codec after reset", @@ -575,11 +575,11 @@ int cadence_codec_reset(struct comp_dev *dev) int cadence_codec_free(struct comp_dev *dev) { - codec_free_all_memory(dev); + module_free_all_memory(dev); return 0; } -static struct codec_interface cadence_interface = { +static struct module_interface cadence_interface = { .init = cadence_codec_init, .prepare = cadence_codec_prepare, .process = cadence_codec_process, diff --git a/src/audio/codec_adapter/codec/dts.c b/src/audio/codec_adapter/codec/dts.c index d29137646dc4..6b076ae6312b 100644 --- a/src/audio/codec_adapter/codec/dts.c +++ b/src/audio/codec_adapter/codec/dts.c @@ -24,7 +24,7 @@ static void *dts_effect_allocate_codec_memory(void *dev_void, unsigned int lengt comp_dbg(dev, "dts_effect_allocate_codec_memory() start"); - pMem = codec_allocate_memory(dev, (uint32_t)length, (uint32_t)alignment); + pMem = module_allocate_memory(dev, (uint32_t)length, (uint32_t)alignment); if (pMem == NULL) comp_err(dev, @@ -60,19 +60,19 @@ static int dts_effect_convert_sof_interface_result(struct comp_dev *dev, static int dts_effect_populate_buffer_configuration(struct comp_dev *dev, DtsSofInterfaceBufferConfiguration *buffer_config) { - struct comp_data *cd = comp_get_drvdata(dev); + struct processing_module *mod = comp_get_drvdata(dev); const struct audio_stream *stream; DtsSofInterfaceBufferLayout buffer_layout; DtsSofInterfaceBufferFormat buffer_format; comp_dbg(dev, "dts_effect_populate_buffer_configuration() start"); - if (cd->ca_source == NULL) + if (!mod->ca_source) return -EINVAL; - stream = &cd->ca_source->stream; + stream = &mod->ca_source->stream; - switch (cd->ca_source->buffer_fmt) { + switch (mod->ca_source->buffer_fmt) { case SOF_IPC_BUFFER_INTERLEAVED: buffer_layout = DTS_SOF_INTERFACE_BUFFER_LAYOUT_INTERLEAVED; break; @@ -116,7 +116,7 @@ static int dts_effect_populate_buffer_configuration(struct comp_dev *dev, int dts_codec_init(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); DtsSofInterfaceResult dts_result; DtsSofInterfaceVersionInfo interface_version; DtsSofInterfaceVersionInfo sdk_version; @@ -160,7 +160,7 @@ int dts_codec_init(struct comp_dev *dev) int dts_codec_prepare(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); DtsSofInterfaceBufferConfiguration buffer_configuration; DtsSofInterfaceResult dts_result; @@ -177,10 +177,10 @@ int dts_codec_prepare(struct comp_dev *dev) dts_result = dtsSofInterfacePrepare( (DtsSofInterfaceInst *)codec->private, &buffer_configuration, - &codec->cpd.in_buff, - &codec->cpd.in_buff_size, - &codec->cpd.out_buff, - &codec->cpd.out_buff_size); + &codec->mpd.in_buff, + &codec->mpd.in_buff_size, + &codec->mpd.out_buff, + &codec->mpd.out_buff_size); ret = dts_effect_convert_sof_interface_result(dev, dts_result); if (ret) @@ -194,7 +194,7 @@ int dts_codec_prepare(struct comp_dev *dev) static int dts_codec_init_process(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); DtsSofInterfaceResult dts_result; comp_dbg(dev, "dts_codec_init_process() start"); @@ -202,9 +202,9 @@ static int dts_codec_init_process(struct comp_dev *dev) dts_result = dtsSofInterfaceInitProcess(codec->private); ret = dts_effect_convert_sof_interface_result(dev, dts_result); - codec->cpd.produced = 0; - codec->cpd.consumed = 0; - codec->cpd.init_done = 1; + codec->mpd.produced = 0; + codec->mpd.consumed = 0; + codec->mpd.init_done = 1; if (ret) comp_err(dev, "dts_codec_init_process() failed %d %d", ret, dts_result); @@ -217,11 +217,11 @@ static int dts_codec_init_process(struct comp_dev *dev) int dts_codec_process(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); DtsSofInterfaceResult dts_result; unsigned int bytes_processed = 0; - if (!codec->cpd.init_done) + if (!codec->mpd.init_done) return dts_codec_init_process(dev); comp_dbg(dev, "dts_codec_process() start"); @@ -229,8 +229,8 @@ int dts_codec_process(struct comp_dev *dev) dts_result = dtsSofInterfaceProcess(codec->private, &bytes_processed); ret = dts_effect_convert_sof_interface_result(dev, dts_result); - codec->cpd.consumed = !ret ? bytes_processed : 0; - codec->cpd.produced = !ret ? bytes_processed : 0; + codec->mpd.consumed = !ret ? bytes_processed : 0; + codec->mpd.produced = !ret ? bytes_processed : 0; if (ret) comp_err(dev, "dts_codec_process() failed %d %d", ret, dts_result); @@ -243,9 +243,9 @@ int dts_codec_process(struct comp_dev *dev) int dts_codec_apply_config(struct comp_dev *dev) { int ret = 0; - struct codec_data *codec = comp_get_codec(dev); - struct codec_config *config; - struct codec_param *param; + struct module_data *codec = comp_get_module_data(dev); + struct module_config *config; + struct module_param *param; uint32_t config_header_size; uint32_t config_data_size; uint32_t param_header_size; @@ -278,10 +278,10 @@ int dts_codec_apply_config(struct comp_dev *dev) return -EINVAL; } - /* Allow for multiple codec_params to be packed into the data pointed to by config + /* Allow for multiple module_params to be packed into the data pointed to by config */ for (i = 0; i < config_data_size; param_number++) { - param = (struct codec_param *)((char *)config->data + i); + param = (struct module_param *)((char *)config->data + i); param_header_size = sizeof(param->id) + sizeof(param->size); /* If param->size is less than param_header_size, then this param is not valid */ @@ -308,7 +308,7 @@ int dts_codec_apply_config(struct comp_dev *dev) } } - /* Advance to the next codec_param */ + /* Advance to the next module_param */ i += param->size; } @@ -320,7 +320,7 @@ int dts_codec_apply_config(struct comp_dev *dev) int dts_codec_reset(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); DtsSofInterfaceResult dts_result; comp_dbg(dev, "dts_codec_reset() start"); @@ -339,7 +339,7 @@ int dts_codec_reset(struct comp_dev *dev) int dts_codec_free(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); DtsSofInterfaceResult dts_result; comp_dbg(dev, "dts_codec_free() start"); @@ -355,7 +355,7 @@ int dts_codec_free(struct comp_dev *dev) return ret; } -static struct codec_interface dts_interface = { +static struct module_interface dts_interface = { .init = dts_codec_init, .prepare = dts_codec_prepare, .process = dts_codec_process, diff --git a/src/audio/codec_adapter/codec/generic.c b/src/audio/codec_adapter/codec/generic.c index 7294d864655c..aa5cc81c2a4c 100644 --- a/src/audio/codec_adapter/codec/generic.c +++ b/src/audio/codec_adapter/codec/generic.c @@ -16,27 +16,25 @@ /*****************************************************************************/ /* Local helper functions */ /*****************************************************************************/ -static int validate_config(struct codec_config *cfg); +static int validate_config(struct module_config *cfg); -int -codec_load_config(struct comp_dev *dev, void *cfg, size_t size, - enum codec_cfg_type type) +int module_load_config(struct comp_dev *dev, void *cfg, size_t size, enum module_cfg_type type) { int ret; - struct codec_config *dst; - struct comp_data *cd = comp_get_drvdata(dev); - struct codec_data *codec = &cd->codec; + struct module_config *dst; + struct processing_module *mod = comp_get_drvdata(dev); + struct module_data *md = &mod->priv; - comp_dbg(dev, "codec_load_config() start"); + comp_dbg(dev, "module_load_config() start"); if (!cfg || !size) { - comp_err(dev, "codec_load_config(): wrong input params! dev %x, cfg %x size %d", + comp_err(dev, "module_load_config(): wrong input params! dev %x, cfg %x size %d", (uint32_t)dev, (uint32_t)cfg, size); return -EINVAL; } - dst = (type == CODEC_CFG_SETUP) ? &codec->s_cfg : - &codec->r_cfg; + dst = (type == MODULE_CFG_SETUP) ? &md->s_cfg : + &md->r_cfg; if (!dst->data) { /* No space for config available yet, allocate now */ @@ -49,7 +47,7 @@ codec_load_config(struct comp_dev *dev, void *cfg, size_t size, dst->data = rballoc(0, SOF_MEM_CAPS_RAM, size); } if (!dst->data) { - comp_err(dev, "codec_load_config(): failed to allocate space for setup config."); + comp_err(dev, "module_load_config(): failed to allocate space for setup config."); ret = -ENOMEM; goto err; } @@ -58,7 +56,7 @@ codec_load_config(struct comp_dev *dev, void *cfg, size_t size, assert(!ret); ret = validate_config(dst->data); if (ret) { - comp_err(dev, "codec_load_config(): validation of config failed!"); + comp_err(dev, "module_load_config(): validation of config failed!"); ret = -EINVAL; goto err; } @@ -67,105 +65,104 @@ codec_load_config(struct comp_dev *dev, void *cfg, size_t size, dst->size = size; dst->avail = true; - comp_dbg(dev, "codec_load_config() done"); + comp_dbg(dev, "module_load_config() done"); return ret; err: - if (dst->data && type == CODEC_CFG_RUNTIME) + if (dst->data && type == MODULE_CFG_RUNTIME) rfree(dst->data); dst->data = NULL; return ret; } -int codec_init(struct comp_dev *dev, struct codec_interface *interface) +int module_init(struct comp_dev *dev, struct module_interface *interface) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); - uint32_t codec_id = cd->ca_config.codec_id; - struct codec_data *codec = &cd->codec; + struct processing_module *mod = comp_get_drvdata(dev); + uint32_t module_id = mod->ca_config.module_id; + struct module_data *md = &mod->priv; - comp_info(dev, "codec_init() start"); + comp_info(dev, "module_init() start"); - if (cd->codec.state == CODEC_INITIALIZED) + if (mod->priv.state == MODULE_INITIALIZED) return 0; - if (cd->codec.state > CODEC_INITIALIZED) + if (mod->priv.state > MODULE_INITIALIZED) return -EPERM; - codec->id = codec_id; + md->id = module_id; if (!interface) { - comp_err(dev, "codec_init(): could not find codec interface for codec id %x", - codec_id); + comp_err(dev, "module_init(): could not find module interface for module id %x", + module_id); ret = -EIO; goto out; } else if (!interface->init || !interface->prepare || !interface->process || !interface->apply_config || !interface->reset || !interface->free) { - comp_err(dev, "codec_init(): codec %x is missing mandatory interfaces", - codec_id); + comp_err(dev, "module_init(): module %x is missing mandatory interfaces", + module_id); ret = -EIO; goto out; } /* Assign interface */ - codec->ops = interface; + md->ops = interface; /* Init memory list */ - list_init(&codec->memory.mem_list); + list_init(&md->memory.mem_list); - /* Now we can proceed with codec specific initialization */ - ret = codec->ops->init(dev); + /* Now we can proceed with module specific initialization */ + ret = md->ops->init(dev); if (ret) { - comp_err(dev, "codec_init() error %d: codec specific init failed, codec_id %x", - ret, codec_id); + comp_err(dev, "module_init() error %d: module specific init failed, module_id %x", + ret, module_id); goto out; } - comp_info(dev, "codec_init() done"); - codec->state = CODEC_INITIALIZED; + comp_info(dev, "module_init() done"); + md->state = MODULE_INITIALIZED; out: return ret; } -void *codec_allocate_memory(struct comp_dev *dev, uint32_t size, - uint32_t alignment) +void *module_allocate_memory(struct comp_dev *dev, uint32_t size, uint32_t alignment) { - struct codec_memory *container; + struct module_memory *container; void *ptr; - struct comp_data *cd = comp_get_drvdata(dev); + struct processing_module *mod = comp_get_drvdata(dev); if (!size) { - comp_err(dev, "codec_allocate_memory: requested allocation of 0 bytes."); + comp_err(dev, "module_allocate_memory: requested allocation of 0 bytes."); return NULL; } /* Allocate memory container */ container = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, - sizeof(struct codec_memory)); + sizeof(struct module_memory)); if (!container) { - comp_err(dev, "codec_allocate_memory: failed to allocate memory container."); + comp_err(dev, "module_allocate_memory: failed to allocate memory container."); return NULL; } - /* Allocate memory for codec */ + /* Allocate memory for module */ if (alignment) ptr = rballoc_align(0, SOF_MEM_CAPS_RAM, size, alignment); else ptr = rballoc(0, SOF_MEM_CAPS_RAM, size); if (!ptr) { - comp_err(dev, "codec_allocate_memory: failed to allocate memory for codec %x.", - cd->ca_config.codec_id); + comp_err(dev, "module_allocate_memory: failed to allocate memory for module %x.", + mod->ca_config.module_id); return NULL; } /* Store reference to allocated memory */ container->ptr = ptr; - list_item_prepend(&container->mem_list, &cd->codec.memory.mem_list); + list_item_prepend(&container->mem_list, &mod->priv.memory.mem_list); return ptr; } -int codec_free_memory(struct comp_dev *dev, void *ptr) +int module_free_memory(struct comp_dev *dev, void *ptr) { - struct comp_data *cd = comp_get_drvdata(dev); - struct codec_memory *mem; + struct processing_module *mod = comp_get_drvdata(dev); + struct module_memory *mem; struct list_item *mem_list; struct list_item *_mem_list; @@ -173,8 +170,8 @@ int codec_free_memory(struct comp_dev *dev, void *ptr) return 0; /* Find which container keeps this memory */ - list_for_item_safe(mem_list, _mem_list, &cd->codec.memory.mem_list) { - mem = container_of(mem_list, struct codec_memory, mem_list); + list_for_item_safe(mem_list, _mem_list, &mod->priv.memory.mem_list) { + mem = container_of(mem_list, struct module_memory, mem_list); if (mem->ptr == ptr) { rfree(mem->ptr); list_item_del(&mem->mem_list); @@ -183,36 +180,36 @@ int codec_free_memory(struct comp_dev *dev, void *ptr) } } - comp_err(dev, "codec_free_memory: error: could not find memory pointed by %p", + comp_err(dev, "module_free_memory: error: could not find memory pointed by %p", (uint32_t)ptr); return -EINVAL; } -static int validate_config(struct codec_config *cfg) +static int validate_config(struct module_config *cfg) { /* TODO: validation of codec specific setup config */ return 0; } -int codec_prepare(struct comp_dev *dev) +int module_prepare(struct comp_dev *dev) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); - uint32_t codec_id = cd->ca_config.codec_id; - struct codec_data *codec = &cd->codec; + struct processing_module *mod = comp_get_drvdata(dev); + uint32_t module_id = mod->ca_config.module_id; + struct module_data *md = &mod->priv; - comp_dbg(dev, "codec_prepare() start"); + comp_dbg(dev, "module_prepare() start"); - if (cd->codec.state == CODEC_IDLE) + if (mod->priv.state == MODULE_IDLE) return 0; - if (cd->codec.state < CODEC_INITIALIZED) + if (mod->priv.state < MODULE_INITIALIZED) return -EPERM; - ret = codec->ops->prepare(dev); + ret = md->ops->prepare(dev); if (ret) { - comp_err(dev, "codec_prepare() error %d: codec specific prepare failed, codec_id 0x%x", - ret, codec_id); + comp_err(dev, "module_prepare() error %d: module specific prepare failed, module_id 0x%x", + ret, module_id); goto end; } @@ -220,138 +217,139 @@ int codec_prepare(struct comp_dev *dev) * as it has been applied during the procedure - it is safe to * free it. */ - if (codec->r_cfg.data) - rfree(codec->r_cfg.data); + if (md->r_cfg.data) + rfree(md->r_cfg.data); - codec->s_cfg.avail = false; - codec->r_cfg.avail = false; - codec->r_cfg.data = NULL; + md->s_cfg.avail = false; + md->r_cfg.avail = false; + md->r_cfg.data = NULL; - codec->state = CODEC_IDLE; - comp_dbg(dev, "codec_prepare() done"); + md->state = MODULE_IDLE; + comp_dbg(dev, "module_prepare() done"); end: return ret; } -int codec_process(struct comp_dev *dev) +int module_process(struct comp_dev *dev) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); - uint32_t codec_id = cd->ca_config.codec_id; - struct codec_data *codec = &cd->codec; - comp_dbg(dev, "codec_process() start"); + struct processing_module *mod = comp_get_drvdata(dev); + uint32_t module_id = mod->ca_config.module_id; + struct module_data *md = &mod->priv; - if (cd->codec.state != CODEC_IDLE) { - comp_err(dev, "codec_process(): wrong state of codec %x, state %d", - cd->ca_config.codec_id, codec->state); + comp_dbg(dev, "module_process() start"); + + if (mod->priv.state != MODULE_IDLE) { + comp_err(dev, "module_process(): wrong state of module %x, state %d", + mod->ca_config.module_id, md->state); return -EPERM; } - ret = codec->ops->process(dev); + ret = md->ops->process(dev); if (ret) { - comp_err(dev, "codec_process() error %d: codec process failed for codec_id %x", - ret, codec_id); + comp_err(dev, "module_process() error %d: for module_id %x", + ret, module_id); goto out; } - comp_dbg(dev, "codec_process() done"); + comp_dbg(dev, "module_process() done"); out: - codec->state = CODEC_IDLE; + md->state = MODULE_IDLE; return ret; } -int codec_apply_runtime_config(struct comp_dev *dev) +int module_apply_runtime_config(struct comp_dev *dev) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); - uint32_t codec_id = cd->ca_config.codec_id; - struct codec_data *codec = &cd->codec; + struct processing_module *mod = comp_get_drvdata(dev); + uint32_t module_id = mod->ca_config.module_id; + struct module_data *md = &mod->priv; - comp_dbg(dev, "codec_apply_config() start"); + comp_dbg(dev, "module_apply_config() start"); - ret = codec->ops->apply_config(dev); + ret = md->ops->apply_config(dev); if (ret) { - comp_err(dev, "codec_apply_config() error %d: codec process failed for codec_id %x", - ret, codec_id); + comp_err(dev, "module_apply_config() error %d: for module_id %x", + ret, module_id); goto out; } - cd->codec.r_cfg.avail = false; + mod->priv.r_cfg.avail = false; /* Configuration had been applied, we can free it now. */ - rfree(codec->r_cfg.data); - codec->r_cfg.data = NULL; + rfree(md->r_cfg.data); + md->r_cfg.data = NULL; - comp_dbg(dev, "codec_apply_config() end"); + comp_dbg(dev, "module_apply_config() end"); out: return ret; } -int codec_reset(struct comp_dev *dev) +int module_reset(struct comp_dev *dev) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); - struct codec_data *codec = &cd->codec; + struct processing_module *mod = comp_get_drvdata(dev); + struct module_data *md = &mod->priv; - ret = codec->ops->reset(dev); + ret = md->ops->reset(dev); if (ret) { - comp_err(dev, "codec_apply_config() error %d: codec specific .reset() failed for codec_id %x", - ret, cd->ca_config.codec_id); + comp_err(dev, "module_reset() error %d: module specific reset() failed for module_id %x", + ret, mod->ca_config.module_id); return ret; } - codec->r_cfg.avail = false; - codec->r_cfg.size = 0; - rfree(codec->r_cfg.data); + md->r_cfg.avail = false; + md->r_cfg.size = 0; + rfree(md->r_cfg.data); - /* Codec reset itself to the initial condition after prepare() + /* module resets itself to the initial condition after prepare() * so let's change its state to reflect that. */ - codec->state = CODEC_IDLE; + md->state = MODULE_IDLE; return 0; } -void codec_free_all_memory(struct comp_dev *dev) +void module_free_all_memory(struct comp_dev *dev) { - struct comp_data *cd = comp_get_drvdata(dev); - struct codec_memory *mem; + struct processing_module *mod = comp_get_drvdata(dev); + struct module_memory *mem; struct list_item *mem_list; struct list_item *_mem_list; /* Find which container keeps this memory */ - list_for_item_safe(mem_list, _mem_list, &cd->codec.memory.mem_list) { - mem = container_of(mem_list, struct codec_memory, mem_list); + list_for_item_safe(mem_list, _mem_list, &mod->priv.memory.mem_list) { + mem = container_of(mem_list, struct module_memory, mem_list); rfree(mem->ptr); list_item_del(&mem->mem_list); rfree(mem); } } -int codec_free(struct comp_dev *dev) +int module_free(struct comp_dev *dev) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); - struct codec_data *codec = &cd->codec; - - ret = codec->ops->free(dev); - if (ret) { - comp_warn(dev, "codec_apply_config() error %d: codec specific .free() failed for codec_id %x", - ret, cd->ca_config.codec_id); - } - /* Free all memory requested by codec */ - codec_free_all_memory(dev); - /* Free all memory shared by codec_adapter & codec */ - codec->s_cfg.avail = false; - codec->s_cfg.size = 0; - codec->r_cfg.avail = false; - codec->r_cfg.size = 0; - rfree(codec->r_cfg.data); - rfree(codec->s_cfg.data); - if (codec->runtime_params) - rfree(codec->runtime_params); - - codec->state = CODEC_DISABLED; + struct processing_module *mod = comp_get_drvdata(dev); + struct module_data *md = &mod->priv; + + ret = md->ops->free(dev); + if (ret) + comp_warn(dev, "module_free(): error: %d for module_id %x", + ret, mod->ca_config.module_id); + + /* Free all memory requested by module */ + module_free_all_memory(dev); + /* Free all memory shared by codec_adapter & module */ + md->s_cfg.avail = false; + md->s_cfg.size = 0; + md->r_cfg.avail = false; + md->r_cfg.size = 0; + rfree(md->r_cfg.data); + rfree(md->s_cfg.data); + if (md->runtime_params) + rfree(md->runtime_params); + + md->state = MODULE_DISABLED; return ret; } diff --git a/src/audio/codec_adapter/codec/passthrough.c b/src/audio/codec_adapter/codec/passthrough.c index e9fd8ed3dc2d..b1aba5e453bb 100644 --- a/src/audio/codec_adapter/codec/passthrough.c +++ b/src/audio/codec_adapter/codec/passthrough.c @@ -21,56 +21,56 @@ static int passthrough_codec_init(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); + struct module_data *codec = comp_get_module_data(dev); + struct processing_module *mod = comp_get_drvdata(dev); comp_info(dev, "passthrough_codec_prepare()"); - codec->cpd.in_buff = rballoc(0, SOF_MEM_CAPS_RAM, cd->period_bytes); - if (!codec->cpd.in_buff) { + codec->mpd.in_buff = rballoc(0, SOF_MEM_CAPS_RAM, mod->period_bytes); + if (!codec->mpd.in_buff) { comp_err(dev, "passthrough_codec_prepare(): Failed to alloc in_buff"); return -ENOMEM; } - codec->cpd.in_buff_size = cd->period_bytes; + codec->mpd.in_buff_size = mod->period_bytes; - codec->cpd.out_buff = rballoc(0, SOF_MEM_CAPS_RAM, cd->period_bytes); - if (!codec->cpd.out_buff) { + codec->mpd.out_buff = rballoc(0, SOF_MEM_CAPS_RAM, mod->period_bytes); + if (!codec->mpd.out_buff) { comp_err(dev, "passthrough_codec_prepare(): Failed to alloc out_buff"); - rfree(codec->cpd.in_buff); + rfree(codec->mpd.in_buff); return -ENOMEM; } - codec->cpd.out_buff_size = cd->period_bytes; + codec->mpd.out_buff_size = mod->period_bytes; return 0; } static int passthrough_codec_init_process(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); comp_dbg(dev, "passthrough_codec_init_process()"); - codec->cpd.produced = 0; - codec->cpd.consumed = 0; - codec->cpd.init_done = 1; + codec->mpd.produced = 0; + codec->mpd.consumed = 0; + codec->mpd.init_done = 1; return 0; } 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); + struct module_data *codec = comp_get_module_data(dev); + struct processing_module *mod = comp_get_drvdata(dev); - if (!codec->cpd.init_done) + if (!codec->mpd.init_done) return passthrough_codec_init_process(dev); comp_dbg(dev, "passthrough_codec_process()"); - memcpy_s(codec->cpd.out_buff, codec->cpd.out_buff_size, - codec->cpd.in_buff, codec->cpd.in_buff_size); - codec->cpd.produced = cd->period_bytes; - codec->cpd.consumed = cd->period_bytes; + memcpy_s(codec->mpd.out_buff, codec->mpd.out_buff_size, + codec->mpd.in_buff, codec->mpd.in_buff_size); + codec->mpd.produced = mod->period_bytes; + codec->mpd.consumed = mod->period_bytes; return 0; } @@ -93,17 +93,17 @@ static int passthrough_codec_reset(struct comp_dev *dev) static int passthrough_codec_free(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); comp_info(dev, "passthrough_codec_free()"); - rfree(codec->cpd.in_buff); - rfree(codec->cpd.out_buff); + rfree(codec->mpd.in_buff); + rfree(codec->mpd.out_buff); return 0; } -static struct codec_interface passthrough_interface = { +static struct module_interface passthrough_interface = { .init = passthrough_codec_init, .prepare = passthrough_codec_prepare, .process = passthrough_codec_process, diff --git a/src/audio/codec_adapter/codec/waves.c b/src/audio/codec_adapter/codec/waves.c index 85b841a5e796..ded143cc4dc8 100644 --- a/src/audio/codec_adapter/codec/waves.c +++ b/src/audio/codec_adapter/codec/waves.c @@ -186,7 +186,7 @@ static bool rate_is_supported(uint32_t rate) /* allocate memory for MaxxEffect object */ static int waves_effect_allocate(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct waves_codec_data *waves_codec = codec->private; MaxxStatus_t status; @@ -199,7 +199,7 @@ static int waves_effect_allocate(struct comp_dev *dev) return -EINVAL; } - waves_codec->effect = (MaxxEffect_t *)codec_allocate_memory(dev, + waves_codec->effect = (MaxxEffect_t *)module_allocate_memory(dev, waves_codec->effect_size, 16); if (!waves_codec->effect) { @@ -218,7 +218,7 @@ static int waves_effect_allocate(struct comp_dev *dev) /* checks if sink/source parameters fit MaxxEffect */ static int waves_effect_check(struct comp_dev *dev) { - struct comp_data *component = comp_get_drvdata(dev); + struct processing_module *component = comp_get_drvdata(dev); const struct audio_stream *src_fmt = &component->ca_source->stream; const struct audio_stream *snk_fmt = &component->ca_sink->stream; @@ -280,9 +280,9 @@ static int waves_effect_check(struct comp_dev *dev) /* initializes MaxxEffect based on stream parameters */ static int waves_effect_init(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct waves_codec_data *waves_codec = codec->private; - struct comp_data *component = comp_get_drvdata(dev); + struct processing_module *component = comp_get_drvdata(dev); const struct audio_stream *src_fmt = &component->ca_source->stream; @@ -357,7 +357,7 @@ static int waves_effect_init(struct comp_dev *dev) /* allocate additional buffers for MaxxEffect */ static int waves_effect_buffers(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct waves_codec_data *waves_codec = codec->private; MaxxStatus_t status; int ret; @@ -375,7 +375,7 @@ static int waves_effect_buffers(struct comp_dev *dev) goto err; } - response = codec_allocate_memory(dev, waves_codec->response_max_bytes, 16); + response = module_allocate_memory(dev, waves_codec->response_max_bytes, 16); if (!response) { comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for response", waves_codec->response_max_bytes); @@ -383,7 +383,7 @@ static int waves_effect_buffers(struct comp_dev *dev) goto err; } - i_buffer = codec_allocate_memory(dev, waves_codec->buffer_bytes, 16); + i_buffer = module_allocate_memory(dev, waves_codec->buffer_bytes, 16); if (!i_buffer) { comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for i_buffer", waves_codec->buffer_bytes); @@ -391,7 +391,7 @@ static int waves_effect_buffers(struct comp_dev *dev) goto err; } - o_buffer = codec_allocate_memory(dev, waves_codec->buffer_bytes, 16); + o_buffer = module_allocate_memory(dev, waves_codec->buffer_bytes, 16); if (!o_buffer) { comp_err(dev, "waves_effect_buffers() failed to allocate %d bytes for o_buffer", waves_codec->buffer_bytes); @@ -402,10 +402,10 @@ static int waves_effect_buffers(struct comp_dev *dev) waves_codec->i_buffer = i_buffer; waves_codec->o_buffer = o_buffer; waves_codec->response = response; - codec->cpd.in_buff = waves_codec->i_buffer; - codec->cpd.in_buff_size = waves_codec->buffer_bytes; - codec->cpd.out_buff = waves_codec->o_buffer; - codec->cpd.out_buff_size = waves_codec->buffer_bytes; + codec->mpd.in_buff = waves_codec->i_buffer; + codec->mpd.in_buff_size = waves_codec->buffer_bytes; + codec->mpd.out_buff = waves_codec->o_buffer; + codec->mpd.out_buff_size = waves_codec->buffer_bytes; comp_info(dev, "waves_effect_buffers() size response %d, i_buffer %d, o_buffer %d", waves_codec->response_max_bytes, waves_codec->buffer_bytes, @@ -416,18 +416,18 @@ static int waves_effect_buffers(struct comp_dev *dev) err: if (i_buffer) - codec_free_memory(dev, i_buffer); + module_free_memory(dev, i_buffer); if (o_buffer) - codec_free_memory(dev, o_buffer); + module_free_memory(dev, o_buffer); if (response) - codec_free_memory(dev, response); + module_free_memory(dev, response); return ret; } /* get MaxxEffect revision */ static int waves_effect_revision(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct waves_codec_data *waves_codec = codec->private; const char *revision = NULL; uint32_t revision_len; @@ -475,7 +475,7 @@ static int waves_effect_revision(struct comp_dev *dev) /* apply MaxxEffect message */ static int waves_effect_message(struct comp_dev *dev, void *data, uint32_t size) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct waves_codec_data *waves_codec = codec->private; MaxxStatus_t status; uint32_t response_size = 0; @@ -508,18 +508,18 @@ static int waves_effect_message(struct comp_dev *dev, void *data, uint32_t size) } /* apply codec config */ -static int waves_effect_config(struct comp_dev *dev, enum codec_cfg_type type) +static int waves_effect_config(struct comp_dev *dev, enum module_cfg_type type) { - struct codec_config *cfg; - struct codec_data *codec = comp_get_codec(dev); - struct codec_param *param; + struct module_config *cfg; + struct module_data *codec = comp_get_module_data(dev); + struct module_param *param; uint32_t index; uint32_t param_number = 0; int ret = 0; comp_info(dev, "waves_codec_configure() start type %d", type); - cfg = (type == CODEC_CFG_SETUP) ? &codec->s_cfg : &codec->r_cfg; + cfg = (type == MODULE_CFG_SETUP) ? &codec->s_cfg : &codec->r_cfg; comp_info(dev, "waves_codec_configure() config %p, size %d, avail %d", cfg->data, cfg->size, cfg->avail); @@ -536,13 +536,13 @@ static int waves_effect_config(struct comp_dev *dev, enum codec_cfg_type type) return -EINVAL; } - /* incoming data in cfg->data is arranged according to struct codec_param - * there migh be more than one struct codec_param inside cfg->data, glued back to back + /* incoming data in cfg->data is arranged according to struct module_param + * there migh be more than one struct module_param inside cfg->data, glued back to back */ for (index = 0; index < cfg->size && (!ret); param_number++) { uint32_t param_data_size; - param = (struct codec_param *)((char *)cfg->data + index); + param = (struct module_param *)((char *)cfg->data + index); param_data_size = param->size - sizeof(param->size) - sizeof(param->id); comp_info(dev, "waves_codec_configure() param num %d id %d size %d", @@ -576,7 +576,7 @@ static int waves_effect_config(struct comp_dev *dev, enum codec_cfg_type type) /* apply setup config */ static int waves_effect_setup_config(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); int ret; comp_dbg(dev, "waves_effect_setup_config() start"); @@ -591,7 +591,7 @@ static int waves_effect_setup_config(struct comp_dev *dev) codec->s_cfg.avail = true; } - ret = waves_effect_config(dev, CODEC_CFG_SETUP); + ret = waves_effect_config(dev, MODULE_CFG_SETUP); codec->s_cfg.avail = false; comp_dbg(dev, "waves_effect_setup_config() done"); @@ -600,13 +600,13 @@ static int waves_effect_setup_config(struct comp_dev *dev) int waves_codec_init(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct waves_codec_data *waves_codec; int ret = 0; comp_dbg(dev, "waves_codec_init() start"); - waves_codec = codec_allocate_memory(dev, sizeof(struct waves_codec_data), 16); + waves_codec = module_allocate_memory(dev, sizeof(struct waves_codec_data), 16); if (!waves_codec) { comp_err(dev, "waves_codec_init() failed to allocate %d bytes for waves_codec_data", sizeof(struct waves_codec_data)); @@ -617,7 +617,7 @@ int waves_codec_init(struct comp_dev *dev) ret = waves_effect_allocate(dev); if (ret) { - codec_free_memory(dev, waves_codec); + module_free_memory(dev, waves_codec); codec->private = NULL; } } @@ -655,13 +655,13 @@ int waves_codec_prepare(struct comp_dev *dev) static int waves_codec_init_process(struct comp_dev *dev) { - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); comp_dbg(dev, "waves_codec_init_process()"); - codec->cpd.produced = 0; - codec->cpd.consumed = 0; - codec->cpd.init_done = 1; + codec->mpd.produced = 0; + codec->mpd.consumed = 0; + codec->mpd.init_done = 1; return 0; } @@ -669,10 +669,10 @@ static int waves_codec_init_process(struct comp_dev *dev) int waves_codec_process(struct comp_dev *dev) { int ret; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct waves_codec_data *waves_codec = codec->private; - if (!codec->cpd.init_done) + if (!codec->mpd.init_done) return waves_codec_init_process(dev); comp_dbg(dev, "waves_codec_process() start"); @@ -684,12 +684,12 @@ int waves_codec_process(struct comp_dev *dev) /* here input buffer should always be filled up as requested * since no one updates it`s size except code in prepare. - * on the other hand there is available/produced counters in cpd, check them anyways + * on the other hand there is available/produced counters in mpd, check them anyways */ - if (codec->cpd.avail != waves_codec->buffer_bytes) { + if (codec->mpd.avail != waves_codec->buffer_bytes) { comp_warn(dev, "waves_codec_process() input buffer %d is not full %d", - codec->cpd.avail, waves_codec->buffer_bytes); - num_input_samples = codec->cpd.avail / + codec->mpd.avail, waves_codec->buffer_bytes); + num_input_samples = codec->mpd.avail / (waves_codec->sample_size_in_bytes * waves_codec->i_format.numChannels); } @@ -708,9 +708,9 @@ int waves_codec_process(struct comp_dev *dev) comp_err(dev, "waves_codec_process() MaxxEffect_Process returned %d", status); ret = -EINVAL; } else { - codec->cpd.produced = waves_codec->o_stream.numAvailableSamples * + codec->mpd.produced = waves_codec->o_stream.numAvailableSamples * waves_codec->o_format.numChannels * waves_codec->sample_size_in_bytes; - codec->cpd.consumed = codec->cpd.produced; + codec->mpd.consumed = codec->mpd.produced; ret = 0; } @@ -726,7 +726,7 @@ int waves_codec_apply_config(struct comp_dev *dev) int ret; comp_dbg(dev, "waves_codec_apply_config() start"); - ret = waves_effect_config(dev, CODEC_CFG_RUNTIME); + ret = waves_effect_config(dev, MODULE_CFG_RUNTIME); if (ret) comp_err(dev, "waves_codec_apply_config() failed %d", ret); @@ -739,7 +739,7 @@ int waves_codec_reset(struct comp_dev *dev) { MaxxStatus_t status; int ret = 0; - struct codec_data *codec = comp_get_codec(dev); + struct module_data *codec = comp_get_module_data(dev); struct waves_codec_data *waves_codec = codec->private; comp_dbg(dev, "waves_codec_reset() start"); @@ -759,7 +759,7 @@ int waves_codec_reset(struct comp_dev *dev) int waves_codec_free(struct comp_dev *dev) { - /* codec is using codec_adapter method codec_allocate_memory for all allocations + /* codec is using codec_adapter method module_allocate_memory for all allocations * codec_adapter will free it all on component free call * nothing to do here */ @@ -767,7 +767,7 @@ int waves_codec_free(struct comp_dev *dev) return 0; } -static struct codec_interface waves_interface = { +static struct module_interface waves_interface = { .init = waves_codec_init, .prepare = waves_codec_prepare, .process = waves_codec_process, diff --git a/src/audio/codec_adapter/codec_adapter.c b/src/audio/codec_adapter/codec_adapter.c index 501bbbc875e9..333f18598e59 100644 --- a/src/audio/codec_adapter/codec_adapter.c +++ b/src/audio/codec_adapter/codec_adapter.c @@ -35,12 +35,12 @@ int validate_setup_config(struct ca_config *cfg); */ struct comp_dev *codec_adapter_new(const struct comp_driver *drv, struct comp_ipc_config *config, - struct codec_interface *interface, + struct module_interface *interface, void *spec) { int ret; struct comp_dev *dev; - struct comp_data *cd; + struct processing_module *mod; struct ipc_config_process *ipc_codec_adapter = spec; comp_cl_dbg(drv, "codec_adapter_new() start"); @@ -59,14 +59,14 @@ struct comp_dev *codec_adapter_new(const struct comp_driver *drv, dev->ipc_config = *config; dev->drv = drv; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); - if (!cd) { - comp_err(dev, "codec_adapter_new(), failed to allocate memory for comp_data"); + mod = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*mod)); + if (!mod) { + comp_err(dev, "codec_adapter_new(), failed to allocate memory for module"); rfree(dev); return NULL; } - comp_set_drvdata(dev, cd); + comp_set_drvdata(dev, mod); /* Copy setup config */ ret = load_setup_config(dev, ipc_codec_adapter->data, ipc_codec_adapter->size); @@ -76,7 +76,7 @@ struct comp_dev *codec_adapter_new(const struct comp_driver *drv, goto err; } /* Init processing codec */ - ret = codec_init(dev, interface); + ret = module_init(dev, interface); if (ret) { comp_err(dev, "codec_adapter_new() %d: codec initialization failed", ret); @@ -88,7 +88,7 @@ struct comp_dev *codec_adapter_new(const struct comp_driver *drv, comp_dbg(dev, "codec_adapter_new() done"); return dev; err: - rfree(cd); + rfree(mod); rfree(dev); return NULL; } @@ -108,7 +108,7 @@ int validate_setup_config(struct ca_config *cfg) * The setup config comprises of two parts - one contains essential data * for the initialization of codec_adapter and follows struct ca_config. * Second contains codec specific data needed to setup the codec itself. - * The latter is send in a TLV format organized by struct codec_param. + * The latter is send in a TLV format organized by struct module_param. * * \return integer representing either: * 0 -> success @@ -119,7 +119,7 @@ int load_setup_config(struct comp_dev *dev, void *cfg, uint32_t size) int ret; void *lib_cfg; size_t lib_cfg_size; - struct comp_data *cd = comp_get_drvdata(dev); + struct processing_module *mod = comp_get_drvdata(dev); comp_dbg(dev, "load_setup_config() start."); @@ -134,10 +134,10 @@ int load_setup_config(struct comp_dev *dev, void *cfg, uint32_t size) goto end; } /* Copy codec_adapter part */ - ret = memcpy_s(&cd->ca_config, sizeof(cd->ca_config), cfg, + ret = memcpy_s(&mod->ca_config, sizeof(mod->ca_config), cfg, sizeof(struct ca_config)); assert(!ret); - ret = validate_setup_config(&cd->ca_config); + ret = validate_setup_config(&mod->ca_config); if (ret) { comp_err(dev, "load_setup_config(): validation of setup config for codec_adapter failed."); goto end; @@ -146,10 +146,10 @@ int load_setup_config(struct comp_dev *dev, void *cfg, uint32_t size) lib_cfg_size = size - sizeof(struct ca_config); if (lib_cfg_size) { lib_cfg = (char *)cfg + sizeof(struct ca_config); - ret = codec_load_config(dev, lib_cfg, lib_cfg_size, CODEC_CFG_SETUP); + ret = module_load_config(dev, lib_cfg, lib_cfg_size, MODULE_CFG_SETUP); if (ret) { comp_err(dev, "load_setup_config(): %d: failed to load setup config for codec id %x", - ret, cd->ca_config.codec_id); + ret, mod->ca_config.module_id); goto end; } } @@ -170,8 +170,8 @@ int load_setup_config(struct comp_dev *dev, void *cfg, uint32_t size) int codec_adapter_prepare(struct comp_dev *dev) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); - struct codec_data *codec = &cd->codec; + struct processing_module *mod = comp_get_drvdata(dev); + struct module_data *md = &mod->priv; uint32_t buff_periods = 2; /* default periods of local buffer, * may change if case of deep buffering */ @@ -180,15 +180,13 @@ int codec_adapter_prepare(struct comp_dev *dev) comp_dbg(dev, "codec_adapter_prepare() start"); /* Init sink & source buffers */ - cd->ca_sink = list_first_item(&dev->bsink_list, struct comp_buffer, - source_list); - cd->ca_source = list_first_item(&dev->bsource_list, struct comp_buffer, - sink_list); + mod->ca_sink = list_first_item(&dev->bsink_list, struct comp_buffer, source_list); + mod->ca_source = list_first_item(&dev->bsource_list, struct comp_buffer, sink_list); - if (!cd->ca_source) { + if (!mod->ca_source) { comp_err(dev, "codec_adapter_prepare(): source buffer not found"); return -EINVAL; - } else if (!cd->ca_sink) { + } else if (!mod->ca_sink) { comp_err(dev, "codec_adapter_prepare(): sink buffer not found"); return -EINVAL; } @@ -204,7 +202,7 @@ int codec_adapter_prepare(struct comp_dev *dev) } /* Prepare codec */ - ret = codec_prepare(dev); + ret = module_prepare(dev); if (ret) { comp_err(dev, "codec_adapter_prepare() error %x: codec prepare failed", ret); @@ -219,43 +217,42 @@ int codec_adapter_prepare(struct comp_dev *dev) * generate output once started (same situation happens for compress streams * as well). */ - if (codec->cpd.in_buff_size != cd->period_bytes) { - if (codec->cpd.in_buff_size > cd->period_bytes) { - buff_periods = (codec->cpd.in_buff_size % cd->period_bytes) ? - (codec->cpd.in_buff_size / cd->period_bytes) + 2 : - (codec->cpd.in_buff_size / cd->period_bytes) + 1; + if (md->mpd.in_buff_size != mod->period_bytes) { + if (md->mpd.in_buff_size > mod->period_bytes) { + buff_periods = (md->mpd.in_buff_size % mod->period_bytes) ? + (md->mpd.in_buff_size / mod->period_bytes) + 2 : + (md->mpd.in_buff_size / mod->period_bytes) + 1; } else { - buff_periods = (cd->period_bytes % codec->cpd.in_buff_size) ? - (cd->period_bytes / codec->cpd.in_buff_size) + 2 : - (cd->period_bytes / codec->cpd.in_buff_size) + 1; + buff_periods = (mod->period_bytes % md->mpd.in_buff_size) ? + (mod->period_bytes / md->mpd.in_buff_size) + 2 : + (mod->period_bytes / md->mpd.in_buff_size) + 1; } - cd->deep_buff_bytes = cd->period_bytes * buff_periods; + mod->deep_buff_bytes = mod->period_bytes * buff_periods; } else { - cd->deep_buff_bytes = 0; + mod->deep_buff_bytes = 0; } /* Allocate local buffer */ - buff_size = MAX(cd->period_bytes, codec->cpd.out_buff_size) * buff_periods; - if (cd->local_buff) { - ret = buffer_set_size(cd->local_buff, buff_size); + buff_size = MAX(mod->period_bytes, md->mpd.out_buff_size) * buff_periods; + if (mod->local_buff) { + ret = buffer_set_size(mod->local_buff, buff_size); if (ret < 0) { comp_err(dev, "codec_adapter_prepare(): buffer_set_size() failed, buff_size = %u", buff_size); return ret; } } else { - cd->local_buff = buffer_alloc(buff_size, SOF_MEM_CAPS_RAM, - PLATFORM_DCACHE_ALIGN); - if (!cd->local_buff) { + mod->local_buff = buffer_alloc(buff_size, SOF_MEM_CAPS_RAM, PLATFORM_DCACHE_ALIGN); + if (!mod->local_buff) { comp_err(dev, "codec_adapter_prepare(): failed to allocate local buffer"); return -ENOMEM; } } - buffer_set_params(cd->local_buff, &cd->stream_params, + buffer_set_params(mod->local_buff, &mod->stream_params, BUFFER_UPDATE_FORCE); - buffer_reset_pos(cd->local_buff, NULL); + buffer_reset_pos(mod->local_buff, NULL); comp_dbg(dev, "codec_adapter_prepare() done"); @@ -266,7 +263,7 @@ int codec_adapter_params(struct comp_dev *dev, struct sof_ipc_stream_params *params) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); + struct processing_module *mod = comp_get_drvdata(dev); ret = comp_verify_params(dev, 0, params); if (ret < 0) { @@ -274,18 +271,18 @@ int codec_adapter_params(struct comp_dev *dev, return ret; } - ret = memcpy_s(&cd->stream_params, sizeof(struct sof_ipc_stream_params), + ret = memcpy_s(&mod->stream_params, sizeof(struct sof_ipc_stream_params), params, sizeof(struct sof_ipc_stream_params)); assert(!ret); - cd->period_bytes = params->sample_container_bytes * + mod->period_bytes = params->sample_container_bytes * params->channels * params->rate / 1000; return 0; } static void codec_adapter_copy_from_source_to_lib(const struct audio_stream *source, - const struct codec_processing_data *cpd, + const struct module_processing_data *mpd, size_t bytes) { /* head_size - available data until end of local buffer */ @@ -296,17 +293,17 @@ codec_adapter_copy_from_source_to_lib(const struct audio_stream *source, */ uint32_t tail_size = bytes - head_size; /* copy head_size to lib buffer */ - memcpy_s(cpd->in_buff, cpd->in_buff_size, source->r_ptr, head_size); + memcpy_s(mpd->in_buff, mpd->in_buff_size, source->r_ptr, head_size); if (tail_size) /* copy reset of the samples after wrap-up */ - memcpy_s((char *)cpd->in_buff + head_size, cpd->in_buff_size, + memcpy_s((char *)mpd->in_buff + head_size, mpd->in_buff_size, audio_stream_wrap(source, (char *)source->r_ptr + head_size), tail_size); } static void -codec_adapter_copy_from_lib_to_sink(const struct codec_processing_data *cpd, +codec_adapter_copy_from_lib_to_sink(const struct module_processing_data *mpd, const struct audio_stream *sink, size_t bytes) { @@ -320,13 +317,13 @@ codec_adapter_copy_from_lib_to_sink(const struct codec_processing_data *cpd, uint32_t tail_size = bytes - head_size; /* copy head_size to sink buffer */ - memcpy_s(sink->w_ptr, sink->size, cpd->out_buff, head_size); + memcpy_s(sink->w_ptr, sink->size, mpd->out_buff, head_size); if (tail_size) /* copy reset of the samples after wrap-up */ memcpy_s(audio_stream_wrap(sink, (char *)sink->w_ptr + head_size), sink->size, - (char *)cpd->out_buff + head_size, tail_size); + (char *)mpd->out_buff + head_size, tail_size); } /** @@ -356,12 +353,12 @@ int codec_adapter_copy(struct comp_dev *dev) { int ret = 0; uint32_t bytes_to_process, copy_bytes, processed = 0, produced = 0; - struct comp_data *cd = comp_get_drvdata(dev); - struct codec_data *codec = &cd->codec; - struct comp_buffer *source = cd->ca_source; - struct comp_buffer *sink = cd->ca_sink; - uint32_t codec_buff_size = codec->cpd.in_buff_size; - struct comp_buffer *local_buff = cd->local_buff; + struct processing_module *mod = comp_get_drvdata(dev); + struct module_data *md = &mod->priv; + struct comp_buffer *source = mod->ca_source; + struct comp_buffer *sink = mod->ca_sink; + uint32_t codec_buff_size = md->mpd.in_buff_size; + struct comp_buffer *local_buff = mod->local_buff; struct comp_copy_limits cl; comp_get_copy_limits_with_lock(source, local_buff, &cl); @@ -379,27 +376,27 @@ int codec_adapter_copy(struct comp_dev *dev) goto db_verify; } - if (!codec->cpd.init_done) { + if (!md->mpd.init_done) { buffer_stream_invalidate(source, codec_buff_size); - codec_adapter_copy_from_source_to_lib(&source->stream, &codec->cpd, + codec_adapter_copy_from_source_to_lib(&source->stream, &md->mpd, codec_buff_size); - codec->cpd.avail = codec_buff_size; - ret = codec_process(dev); + md->mpd.avail = codec_buff_size; + ret = module_process(dev); if (ret) return ret; - bytes_to_process -= codec->cpd.consumed; - processed += codec->cpd.consumed; - comp_update_buffer_consume(source, codec->cpd.consumed); + bytes_to_process -= md->mpd.consumed; + processed += md->mpd.consumed; + comp_update_buffer_consume(source, md->mpd.consumed); if (bytes_to_process < codec_buff_size) goto db_verify; } buffer_stream_invalidate(source, codec_buff_size); - codec_adapter_copy_from_source_to_lib(&source->stream, &codec->cpd, + codec_adapter_copy_from_source_to_lib(&source->stream, &md->mpd, codec_buff_size); - codec->cpd.avail = codec_buff_size; - ret = codec_process(dev); + md->mpd.avail = codec_buff_size; + ret = module_process(dev); if (ret) { if (ret == -ENOSPC) { ret = 0; @@ -409,42 +406,42 @@ int codec_adapter_copy(struct comp_dev *dev) comp_err(dev, "codec_adapter_copy() error %x: lib processing failed", ret); goto db_verify; - } else if (codec->cpd.produced == 0) { + } else if (md->mpd.produced == 0) { /* skipping as lib has not produced anything */ comp_err(dev, "codec_adapter_copy() error %x: lib hasn't processed anything", ret); goto db_verify; } - codec_adapter_copy_from_lib_to_sink(&codec->cpd, &local_buff->stream, - codec->cpd.produced); + codec_adapter_copy_from_lib_to_sink(&md->mpd, &local_buff->stream, + md->mpd.produced); - bytes_to_process -= codec->cpd.consumed; - processed += codec->cpd.consumed; - produced += codec->cpd.produced; + bytes_to_process -= md->mpd.consumed; + processed += md->mpd.consumed; + produced += md->mpd.produced; - audio_stream_produce(&local_buff->stream, codec->cpd.produced); - comp_update_buffer_consume(source, codec->cpd.consumed); + audio_stream_produce(&local_buff->stream, md->mpd.produced); + comp_update_buffer_consume(source, md->mpd.consumed); db_verify: - if (!produced && !cd->deep_buff_bytes) { + if (!produced && !mod->deep_buff_bytes) { comp_dbg(dev, "codec_adapter_copy(): nothing processed in this call"); /* we haven't produced anything in this period but we * still have data in the local buffer to copy to sink */ - if (audio_stream_get_avail_bytes(&local_buff->stream) >= cd->period_bytes) + if (audio_stream_get_avail_bytes(&local_buff->stream) >= mod->period_bytes) goto copy_period; else goto end; } - if (cd->deep_buff_bytes) { - if (cd->deep_buff_bytes >= audio_stream_get_avail_bytes(&local_buff->stream)) { - generate_zeroes(sink, cd->period_bytes); + if (mod->deep_buff_bytes) { + if (mod->deep_buff_bytes >= audio_stream_get_avail_bytes(&local_buff->stream)) { + generate_zeroes(sink, mod->period_bytes); goto end; } else { comp_dbg(dev, "codec_adapter_copy(): deep buffering has ended after gathering %d bytes of processed data", audio_stream_get_avail_bytes(&local_buff->stream)); - cd->deep_buff_bytes = 0; + mod->deep_buff_bytes = 0; } } @@ -453,7 +450,7 @@ int codec_adapter_copy(struct comp_dev *dev) copy_bytes = cl.frames * cl.source_frame_bytes; audio_stream_copy(&local_buff->stream, 0, &sink->stream, 0, - copy_bytes / cd->stream_params.sample_container_bytes); + copy_bytes / mod->stream_params.sample_container_bytes); buffer_stream_writeback(sink, copy_bytes); comp_update_buffer_produce(sink, copy_bytes); @@ -465,14 +462,14 @@ int codec_adapter_copy(struct comp_dev *dev) } static int codec_adapter_set_params(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata, - enum codec_cfg_type type) + enum module_cfg_type type) { int ret; char *dst, *src; static uint32_t size; uint32_t offset; - struct comp_data *cd = comp_get_drvdata(dev); - struct codec_data *codec = &cd->codec; + struct processing_module *mod = comp_get_drvdata(dev); + struct module_data *md = &mod->priv; comp_dbg(dev, "codec_adapter_set_params(): start: num_of_elem %d, elem remain %d msg_index %u", cdata->num_elems, cdata->elems_remaining, cdata->msg_index); @@ -481,7 +478,7 @@ static int codec_adapter_set_params(struct comp_dev *dev, struct sof_ipc_ctrl_da if (cdata->msg_index == 0) { size = cdata->num_elems + cdata->elems_remaining; /* Check that there is no work-in-progress on previous request */ - if (codec->runtime_params) { + if (md->runtime_params) { comp_err(dev, "codec_adapter_set_params() error: busy with previous request"); ret = -EBUSY; goto end; @@ -496,29 +493,29 @@ static int codec_adapter_set_params(struct comp_dev *dev, struct sof_ipc_ctrl_da size, MAX_BLOB_SIZE); ret = -EINVAL; goto end; - } else if (type != CODEC_CFG_SETUP && type != CODEC_CFG_RUNTIME) { + } else if (type != MODULE_CFG_SETUP && type != MODULE_CFG_RUNTIME) { comp_err(dev, "codec_adapter_set_params() error: unknown config type"); ret = -EINVAL; goto end; } /* Allocate buffer for new params */ - codec->runtime_params = rballoc(0, SOF_MEM_CAPS_RAM, size); - if (!codec->runtime_params) { + md->runtime_params = rballoc(0, SOF_MEM_CAPS_RAM, size); + if (!md->runtime_params) { comp_err(dev, "codec_adapter_set_params(): space allocation for new params failed"); ret = -ENOMEM; goto end; } - memset(codec->runtime_params, 0, size); - } else if (!codec->runtime_params) { + memset(md->runtime_params, 0, size); + } else if (!md->runtime_params) { comp_err(dev, "codec_adapter_set_params() error: no memory available for runtime params in consecutive load"); ret = -EIO; goto end; } offset = size - (cdata->num_elems + cdata->elems_remaining); - dst = (char *)codec->runtime_params + offset; + dst = (char *)md->runtime_params + offset; src = (char *)cdata->data->data; ret = memcpy_s(dst, size - offset, src, cdata->num_elems); @@ -529,8 +526,8 @@ static int codec_adapter_set_params(struct comp_dev *dev, struct sof_ipc_ctrl_da */ if (!cdata->elems_remaining) { switch (type) { - case CODEC_CFG_SETUP: - ret = load_setup_config(dev, codec->runtime_params, size); + case MODULE_CFG_SETUP: + ret = load_setup_config(dev, md->runtime_params, size); if (ret) { comp_err(dev, "codec_adapter_set_params(): error %d: load of setup config failed.", ret); @@ -539,9 +536,8 @@ static int codec_adapter_set_params(struct comp_dev *dev, struct sof_ipc_ctrl_da } break; - case CODEC_CFG_RUNTIME: - ret = codec_load_config(dev, codec->runtime_params, size, - CODEC_CFG_RUNTIME); + case MODULE_CFG_RUNTIME: + ret = module_load_config(dev, md->runtime_params, size, MODULE_CFG_RUNTIME); if (ret) { comp_err(dev, "codec_adapter_set_params() error %d: load of runtime config failed.", ret); @@ -550,11 +546,11 @@ static int codec_adapter_set_params(struct comp_dev *dev, struct sof_ipc_ctrl_da comp_dbg(dev, "codec_adapter_set_params() load of runtime config done."); } - if (codec->state >= CODEC_INITIALIZED) { + if (md->state >= MODULE_INITIALIZED) { /* We are already prepared so we can apply runtime * config right away. */ - ret = codec_apply_runtime_config(dev); + ret = module_apply_runtime_config(dev); if (ret) { comp_err(dev, "codec_adapter_set_params() error %x: codec runtime config apply failed", ret); @@ -562,7 +558,7 @@ static int codec_adapter_set_params(struct comp_dev *dev, struct sof_ipc_ctrl_da comp_dbg(dev, "codec_adapter_set_params() apply of runtime config done."); } } else { - cd->codec.r_cfg.avail = true; + mod->priv.r_cfg.avail = true; } break; @@ -574,9 +570,9 @@ static int codec_adapter_set_params(struct comp_dev *dev, struct sof_ipc_ctrl_da goto end; done: - if (codec->runtime_params) - rfree(codec->runtime_params); - codec->runtime_params = NULL; + if (md->runtime_params) + rfree(md->runtime_params); + md->runtime_params = NULL; return ret; end: return ret; @@ -590,8 +586,8 @@ static int ca_set_binary_data(struct comp_dev *dev, comp_dbg(dev, "ca_set_binary_data() start, data type %d", cdata->data->type); switch (cdata->data->type) { - case CODEC_CFG_SETUP: - case CODEC_CFG_RUNTIME: + case MODULE_CFG_SETUP: + case MODULE_CFG_RUNTIME: ret = codec_adapter_set_params(dev, cdata, cdata->data->type); break; default: @@ -607,10 +603,10 @@ static int codec_adapter_ctrl_set_data(struct comp_dev *dev, struct sof_ipc_ctrl_data *cdata) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); + struct processing_module *mod = comp_get_drvdata(dev); comp_dbg(dev, "codec_adapter_ctrl_set_data() start, state %d, cmd %d", - cd->codec.state, cdata->cmd); + mod->priv.state, cdata->cmd); /* Check version from ABI header */ if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, cdata->data->abi)) { @@ -672,16 +668,16 @@ int codec_adapter_trigger(struct comp_dev *dev, int cmd) int codec_adapter_reset(struct comp_dev *dev) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); + struct processing_module *mod = comp_get_drvdata(dev); comp_dbg(dev, "codec_adapter_reset(): resetting"); - ret = codec_reset(dev); + ret = module_reset(dev); if (ret) { comp_err(dev, "codec_adapter_reset(): error %d, codec reset has failed", ret); } - buffer_zero(cd->local_buff); + buffer_zero(mod->local_buff); comp_dbg(dev, "codec_adapter_reset(): done"); @@ -691,16 +687,16 @@ int codec_adapter_reset(struct comp_dev *dev) void codec_adapter_free(struct comp_dev *dev) { int ret; - struct comp_data *cd = comp_get_drvdata(dev); + struct processing_module *mod = comp_get_drvdata(dev); comp_dbg(dev, "codec_adapter_free(): start"); - ret = codec_free(dev); + ret = module_free(dev); if (ret) { comp_err(dev, "codec_adapter_free(): error %d, codec reset has failed", ret); } - buffer_free(cd->local_buff); - rfree(cd); + buffer_free(mod->local_buff); + rfree(mod); rfree(dev); } diff --git a/src/include/sof/audio/codec_adapter/codec/generic.h b/src/include/sof/audio/codec_adapter/codec/generic.h index b1f5747631d0..6b99139e7d7c 100644 --- a/src/include/sof/audio/codec_adapter/codec/generic.h +++ b/src/include/sof/audio/codec_adapter/codec/generic.h @@ -16,7 +16,7 @@ #include #include -#define comp_get_codec(d) (&(((struct comp_data *)((d)->priv_data))->codec)) +#define comp_get_module_data(d) (&(((struct processing_module *)((d)->priv_data))->priv)) #define CODEC_GET_INTERFACE_ID(id) ((id) >> 0x8) #define CODEC_GET_API_ID(id) ((id) & 0xFF) #define API_CALL(cd, cmd, sub_cmd, value, ret) \ @@ -64,77 +64,77 @@ UT_STATIC void sys_comp_codec_##adapter_init(void) \ DECLARE_MODULE(sys_comp_codec_##adapter_init) /*****************************************************************************/ -/* Codec generic data types */ +/* Module generic data types */ /*****************************************************************************/ /** - * \struct codec_interface - * \brief Codec specific interfaces + * \struct module_interface + * \brief 3rd party processing module interface */ -struct codec_interface { +struct module_interface { /** - * The unique ID for a codec, used for initialization as well as + * The unique ID for a module, used for initialization as well as * parameters loading. */ uint32_t id; /** - * Codec specific initialization procedure, called as part of + * Module specific initialization procedure, called as part of * codec_adapter component creation in .new() */ int (*init)(struct comp_dev *dev); /** - * Codec specific prepare procedure, called as part of codec_adapter + * Module specific prepare procedure, called as part of codec_adapter * component preparation in .prepare() */ int (*prepare)(struct comp_dev *dev); /** - * Codec specific processing procedure, called as part of codec_adapter + * Module specific processing procedure, called as part of codec_adapter * component copy in .copy(). This procedure is responsible to consume * samples provided by the codec_adapter and produce/output the processed * ones back to codec_adapter. */ int (*process)(struct comp_dev *dev); /** - * Codec specific apply config procedure, called by codec_adapter every time + * Module specific apply config procedure, called by codec_adapter every time * a new RUNTIME configuration has been sent if the adapter has been * prepared. This will not be called for SETUP cfg. */ int (*apply_config)(struct comp_dev *dev); /** - * Codec specific reset procedure, called as part of codec_adapter component + * Module specific reset procedure, called as part of codec_adapter component * reset in .reset(). This should reset all parameters to their initial stage * but leave allocated memory intact. */ int (*reset)(struct comp_dev *dev); /** - * Codec specific free procedure, called as part of codec_adapter component - * free in .free(). This should free all memory allocated by codec. + * Module specific free procedure, called as part of codec_adapter component + * free in .free(). This should free all memory allocated by module. */ int (*free)(struct comp_dev *dev); }; /** - * \enum codec_cfg_type + * \enum module_cfg_type * \brief Specific configuration types which can be either: */ -enum codec_cfg_type { - CODEC_CFG_SETUP, /**< Used to pass setup parameters */ - CODEC_CFG_RUNTIME /**< Used every time runtime parameters has been loaded. */ +enum module_cfg_type { + MODULE_CFG_SETUP, /**< Used to pass setup parameters */ + MODULE_CFG_RUNTIME /**< Used every time runtime parameters has been loaded. */ }; /** - * \enum codec_state - * \brief Codec specific states + * \enum module_state + * \brief Module-specific states */ -enum codec_state { - CODEC_DISABLED, /**< Codec isn't initialized yet or has been freed.*/ - CODEC_INITIALIZED, /**< Codec initialized or reset. */ - CODEC_IDLE, /**< Codec is idle now. */ - CODEC_PROCESSING, /**< Codec is processing samples now. */ +enum module_state { + MODULE_DISABLED, /**< Module isn't initialized yet or has been freed.*/ + MODULE_INITIALIZED, /**< Module initialized or reset. */ + MODULE_IDLE, /**< Module is idle now. */ + MODULE_PROCESSING, /**< Module is processing samples now. */ }; /** codec adapter setup config parameters */ struct ca_config { - uint32_t codec_id; + uint32_t module_id; uint32_t reserved; uint32_t sample_rate; uint32_t sample_width; @@ -142,14 +142,14 @@ struct ca_config { }; /** - * \struct codec_config - * \brief Codec TLV parameters container - used for both config types. + * \struct module_param + * \brief Module TLV parameters container - used for both config types. * For example if one want to set the sample_rate to 16 [kHz] and this * parameter was assigned to id 0x01, its max size is four bytes then the * configuration filed should look like this (note little-endian format): * 0x01 0x00 0x00 0x00, 0x0C 0x00 0x00 0x00, 0x10 0x00 0x00 0x00. */ -struct codec_param { +struct module_param { /** * Specifies the unique id of a parameter. For example the parameter * sample_rate may have an id of 0x01. @@ -160,56 +160,56 @@ struct codec_param { }; /** - * \struct codec_config - * \brief Codec config container, used for both config types. + * \struct module_config + * \brief Module config container, used for both config types. */ -struct codec_config { +struct module_config { size_t size; /**< Specifies the size of whole config */ bool avail; /**< Marks config as available to use.*/ void *data; /**< tlv config, a pointer to memory where config is stored. */ }; /** - * \struct codec_memory - * \brief codec memory block - used for every memory allocated by codec + * \struct module_memory + * \brief module memory block - used for every memory allocated by module */ -struct codec_memory { +struct module_memory { void *ptr; /**< A pointr to particular memory block */ - struct list_item mem_list; /**< list of memory allocated by codec */ + struct list_item mem_list; /**< list of memory allocated by module */ }; /** - * \struct codec_processing_data - * \brief Processing data shared between particular codec & codec_adapter + * \struct module_processing_data + * \brief Processing data shared between particular module & codec_adapter */ -struct codec_processing_data { - uint32_t in_buff_size; /**< Specifies the size of codec input buffer. */ - uint32_t out_buff_size; /**< Specifies the size of codec output buffer.*/ - uint32_t avail; /**< Specifies how much data is available for codec to process.*/ - uint32_t produced; /**< Specifies how much data the codec produced in its last task.*/ - uint32_t consumed; /**< Specified how much data the codec consumed in its last task */ - uint32_t init_done; /**< Specifies if the codec initialization is finished */ - void *in_buff; /**< A pointer to codec input buffer. */ - void *out_buff; /**< A pointer to codec output buffer. */ +struct module_processing_data { + uint32_t in_buff_size; /**< Specifies the size of module input buffer. */ + uint32_t out_buff_size; /**< Specifies the size of module output buffer.*/ + uint32_t avail; /**< Specifies how much data is available for module to process.*/ + uint32_t produced; /**< Specifies how much data the module produced in its last task.*/ + uint32_t consumed; /**< Specified how much data the module consumed in its last task */ + uint32_t init_done; /**< Specifies if the module initialization is finished */ + void *in_buff; /**< A pointer to module input buffer. */ + void *out_buff; /**< A pointer to module output buffer. */ }; -/** private, runtime codec data */ -struct codec_data { +/** private, runtime module data */ +struct module_data { uint32_t id; - enum codec_state state; + enum module_state state; void *private; /**< self object, memory tables etc here */ void *runtime_params; - struct codec_config s_cfg; /**< setup config */ - struct codec_config r_cfg; /**< runtime config */ - struct codec_interface *ops; /**< codec specific operations */ - struct codec_memory memory; /**< memory allocated by codec */ - struct codec_processing_data cpd; /**< shared data comp <-> codec */ + struct module_config s_cfg; /**< setup config */ + struct module_config r_cfg; /**< runtime config */ + struct module_interface *ops; /**< module specific operations */ + struct module_memory memory; /**< memory allocated by module */ + struct module_processing_data mpd; /**< shared data comp <-> module */ }; /* codec_adapter private, runtime data */ -struct comp_data { +struct processing_module { struct ca_config ca_config; - struct codec_data codec; /**< codec private data */ + struct module_data priv; /**< module private data */ struct comp_buffer *ca_sink; struct comp_buffer *ca_source; struct comp_buffer *local_buff; @@ -219,24 +219,22 @@ struct comp_data { }; /*****************************************************************************/ -/* Codec generic interfaces */ +/* Module generic interfaces */ /*****************************************************************************/ -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, 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); -void codec_free_all_memory(struct comp_dev *dev); -int codec_prepare(struct comp_dev *dev); -int codec_process(struct comp_dev *dev); -int codec_apply_runtime_config(struct comp_dev *dev); -int codec_reset(struct comp_dev *dev); -int codec_free(struct comp_dev *dev); +int module_load_config(struct comp_dev *dev, void *cfg, size_t size, enum module_cfg_type type); +int module_init(struct comp_dev *dev, struct module_interface *interface); +void *module_allocate_memory(struct comp_dev *dev, uint32_t size, uint32_t alignment); +int module_free_memory(struct comp_dev *dev, void *ptr); +void module_free_all_memory(struct comp_dev *dev); +int module_prepare(struct comp_dev *dev); +int module_process(struct comp_dev *dev); +int module_apply_runtime_config(struct comp_dev *dev); +int module_reset(struct comp_dev *dev); +int module_free(struct comp_dev *dev); struct comp_dev *codec_adapter_new(const struct comp_driver *drv, struct comp_ipc_config *config, - struct codec_interface *interface, + struct module_interface *interface, void *spec); int codec_adapter_prepare(struct comp_dev *dev); int codec_adapter_params(struct comp_dev *dev, struct sof_ipc_stream_params *params);