Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 367
Support for dynamic codec adapter id - Part 1#5591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
46758a6
codec_adapter: cadence: Introduce cadence_codec_post_init
dbaluta 9930dc7
codec_adapter: cadence: Introduce cadence_codec_resolve_api
dbaluta b5ee289
codec_adapter: cadence: Move cadence_resolve_api
dbaluta 78b2904
codec_adapter: cadence: Only apply config is codec is prepared
dbaluta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -94,105 +94,134 @@ static struct cadence_api cadence_api_table[] = { | ||
| #endif | ||
| }; | ||
| static int cadence_codec_init(struct processing_module *mod) | ||
| static int cadence_codec_resolve_api(struct processing_module *mod, uint32_t api_id) | ||
| { | ||
| 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; | ||
| comp_dbg(dev, "cadence_codec_init() start"); | ||
| cd = rballoc(0, SOF_MEM_CAPS_RAM, sizeof(struct cadence_codec_data)); | ||
| if (!cd) { | ||
| comp_err(dev, "cadence_codec_init(): failed to allocate memory for cadence codec data"); | ||
| return -ENOMEM; | ||
| } | ||
| codec->private = cd; | ||
| codec->mpd.init_done = 0; | ||
| cd->self = NULL; | ||
| cd->mem_tabs = NULL; | ||
| cd->api = NULL; | ||
| cd->setup_cfg.avail = false; | ||
| struct cadence_codec_data *cd = codec->private; | ||
| uint32_t n_apis = ARRAY_SIZE(cadence_api_table); | ||
| int i; | ||
| /* Find and assign API function */ | ||
| for (i = 0; i < no_of_api; i++) { | ||
| for (i = 0; i < n_apis; i++) { | ||
| if (cadence_api_table[i].id == api_id) { | ||
| cd->api = cadence_api_table[i].api; | ||
| break; | ||
| } | ||
| } | ||
| cd->api_id = api_id; | ||
| /* Verify API assignment */ | ||
| if (!cd->api) { | ||
| comp_err(dev, "cadence_codec_init(): could not find API function for id %x", | ||
| comp_err(dev, "cadence_codec_resolve_api(): could not find API function for id %x", | ||
| api_id); | ||
| ret = -EINVAL; | ||
| goto free; | ||
| return -EINVAL; | ||
| } | ||
| /* copy the setup config only for the first init */ | ||
| if (codec->state == MODULE_DISABLED && codec->cfg.avail) { | ||
| struct module_config *setup_cfg = &cd->setup_cfg; | ||
| cd->api_id = api_id; | ||
| /* allocate memory for set up config */ | ||
| setup_cfg->data = rballoc(0, SOF_MEM_CAPS_RAM, codec->cfg.size); | ||
| if (!setup_cfg->data) { | ||
| comp_err(dev, "cadence_codec_init(): failed to alloc setup config"); | ||
| ret = -ENOMEM; | ||
| goto free; | ||
| } | ||
| return 0; | ||
| } | ||
| /* copy the setup config */ | ||
| setup_cfg->size = codec->cfg.size; | ||
| ret = memcpy_s(setup_cfg->data, setup_cfg->size, codec->cfg.data, setup_cfg->size); | ||
| if (ret) { | ||
| comp_err(dev, "cadence_codec_init(): failed to copy setup config %d", ret); | ||
| goto free; | ||
| } | ||
| setup_cfg->avail = true; | ||
| } | ||
| 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 api_id = CODEC_GET_API_ID(DEFAULT_CODEC_ID); | ||
| uint32_t obj_size; | ||
| comp_dbg(dev, "cadence_codec_post_init() start"); | ||
| ret = cadence_codec_resolve_api(mod, api_id); | ||
| if (ret < 0) | ||
| return ret; | ||
| /* 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; | ||
| 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); | ||
| goto free; | ||
| return ret; | ||
| } | ||
| /* Allocate space for codec object */ | ||
| cd->self = rballoc(0, SOF_MEM_CAPS_RAM, obj_size); | ||
dbaluta marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| if (!cd->self) { | ||
| comp_err(dev, "cadence_codec_init(): failed to allocate space for lib object"); | ||
| ret = -ENOMEM; | ||
| goto free; | ||
| return -ENOMEM; | ||
| } | ||
| comp_dbg(dev, "cadence_codec_init(): allocated %d bytes for lib object", obj_size); | ||
| 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); | ||
| goto free; | ||
| 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; | ||
| comp_dbg(dev, "cadence_codec_init() start"); | ||
| cd = rballoc(0, SOF_MEM_CAPS_RAM, sizeof(struct cadence_codec_data)); | ||
| if (!cd) { | ||
| comp_err(dev, "cadence_codec_init(): failed to allocate memory for cadence codec data"); | ||
| return -ENOMEM; | ||
| } | ||
| codec->private = cd; | ||
| codec->mpd.init_done = 0; | ||
| cd->self = NULL; | ||
| cd->mem_tabs = NULL; | ||
| cd->api = NULL; | ||
| cd->setup_cfg.avail = false; | ||
| /* copy the setup config only for the first init */ | ||
| if (codec->state == MODULE_DISABLED && codec->cfg.avail) { | ||
| struct module_config *setup_cfg = &cd->setup_cfg; | ||
| /* allocate memory for set up config */ | ||
| setup_cfg->data = rballoc(0, SOF_MEM_CAPS_RAM, codec->cfg.size); | ||
| if (!setup_cfg->data) { | ||
| comp_err(dev, "cadence_codec_init(): failed to alloc setup config"); | ||
| ret = -ENOMEM; | ||
| goto free; | ||
| } | ||
| /* copy the setup config */ | ||
| setup_cfg->size = codec->cfg.size; | ||
| ret = memcpy_s(setup_cfg->data, setup_cfg->size, codec->cfg.data, setup_cfg->size); | ||
| if (ret) { | ||
| comp_err(dev, "cadence_codec_init(): failed to copy setup config %d", ret); | ||
| goto free; | ||
| } | ||
| setup_cfg->avail = true; | ||
| } | ||
| ret = cadence_codec_post_init(mod); | ||
| if (ret) | ||
| return ret; | ||
| comp_dbg(dev, "cadence_codec_init() done"); | ||
| return 0; | ||
| @@ -649,7 +678,7 @@ cadence_codec_set_configuration(struct processing_module *mod, uint32_t config_i | ||
| /* return if more fragments are expected or if the module is not prepared */ | ||
| if ((pos != MODULE_CFG_FRAGMENT_LAST && pos != MODULE_CFG_FRAGMENT_SINGLE) || | ||
| md->state < MODULE_INITIALIZED) | ||
| md->state < MODULE_IDLE) | ||
| return 0; | ||
| /* whole configuration received, apply it now */ | ||
ranj063 marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what error codes are returned by module API methods and by this function? Below this function returns
-ENOMEM, but API methods don't return POSIX error codes, do they?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lyakh , yes API methods do not return POSIX error codes. They return a set of error codes documented in specific header files.
For example: https://github.com/thesofproject/sof/blob/main/src/include/sof/audio/cadence/xa_error_standards.h
We could deal with this later, as this PR series only deals with moving code around in order to be able to use dynamic codec id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dbaluta do you plan submitting a PR for this in the near future or should I file a bug for this to make sure it isn't lost? This seems a severe enough bug to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fill a bug so we can track it. There is definitely a lot of improvements we can do wrt codec adapter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#5658