Repository navigation
RFC: Preparation to dynamically setup codec_id for codec_adapter #5245
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
Changes from all commits
8fc259f
186b86e
cb7db16
6244f83
67cf947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,15 +94,89 @@ static struct cadence_api cadence_api_table[] = { | |
| #endif | ||
| }; | ||
|
|
||
| static int cadence_codec_resolve_api(struct comp_dev *dev, uint32_t api_id) | ||
| { | ||
| struct module_data *codec = comp_get_module_data(dev); | ||
| uint32_t no_of_api = ARRAY_SIZE(cadence_api_table); | ||
| struct cadence_codec_data *cd = codec->private; | ||
| int i; | ||
|
|
||
| /* Find and assign API function */ | ||
| for (i = 0; i < no_of_api; i++) { | ||
| if (cadence_api_table[i].id == api_id) { | ||
| cd->api = cadence_api_table[i].api; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| cd->api_id = api_id; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be assigned after the verification below or is this by design - even if the ID isn't found? |
||
|
|
||
| /* Verify API assignment */ | ||
| if (!cd->api) { | ||
| comp_err(dev, "cadence_codec_init(): could not find API function for id %x", | ||
| api_id); | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
||
| static int cadence_codec_post_init(struct comp_dev *dev) | ||
| { | ||
| uint32_t api_id = CODEC_GET_API_ID(DEFAULT_CODEC_ID); | ||
| struct module_data *codec = comp_get_module_data(dev); | ||
| struct cadence_codec_data *cd = codec->private; | ||
| uint32_t obj_size; | ||
| int ret; | ||
|
|
||
| comp_dbg(dev, "cadence_codec_post_init() start"); | ||
|
|
||
| ret = cadence_codec_resolve_api(dev, 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_post_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_post_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_post_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 comp_dev *dev) | ||
| { | ||
| int ret; | ||
| 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"); | ||
|
|
||
|
|
@@ -119,24 +193,6 @@ static int cadence_codec_init(struct comp_dev *dev) | |
| cd->api = NULL; | ||
| cd->setup_cfg.avail = false; | ||
|
|
||
| /* Find and assign API function */ | ||
| for (i = 0; i < no_of_api; 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", | ||
| api_id); | ||
| ret = -EINVAL; | ||
| goto free; | ||
| } | ||
|
|
||
| /* 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; | ||
|
|
@@ -160,45 +216,9 @@ static int cadence_codec_init(struct comp_dev *dev) | |
| 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; | ||
| } | ||
|
|
||
| comp_dbg(dev, "cadence_codec_init() done"); | ||
|
|
||
| return 0; | ||
| free: | ||
| rfree(cd); | ||
| return ret; | ||
| } | ||
|
|
||
| static int cadence_codec_apply_config(struct comp_dev *dev) | ||
|
|
@@ -429,6 +449,13 @@ static int cadence_codec_prepare(struct comp_dev *dev) | |
|
|
||
| comp_dbg(dev, "cadence_codec_prepare() start"); | ||
|
|
||
| ret = cadence_codec_post_init(dev); | ||
| if (ret < 0) { | ||
| comp_err(dev, "cadence_codec_prepare() error %x: failed post init", | ||
| ret); | ||
| return ret; | ||
| } | ||
|
|
||
| ret = cadence_codec_apply_config(dev); | ||
| if (ret) { | ||
| comp_err(dev, "cadence_codec_prepare() error %x: failed to apply config", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,7 +95,9 @@ struct sof_ipc_stream_params { | |
| uint32_t host_period_bytes; | ||
| uint16_t no_stream_position; /**< 1 means don't send stream position */ | ||
|
|
||
| uint16_t reserved[3]; | ||
| uint8_t codec_id; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs a minor ABI update
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @plbossart what do you think of using the PCM_PARAMS IPC to send the API ID for compressed codecs? This field be ignored for PCM data.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's natural to think of this, set_params and hw_params are similar in nature, but the former takes extra information into account. Your proposal to use the codec_id is too limiting in general. For example for AAC you will need to send the format information for ADTS or ADIF. It gets even worse if you ever want to support encoders. struct snd_codec {
__u32 id;
__u32 ch_in;
__u32 ch_out;
__u32 sample_rate;
__u32 bit_rate;
__u32 rate_control;
__u32 profile;
__u32 level;
__u32 ch_mode;
__u32 format;
__u32 align;
union snd_codec_options options;
__u32 reserved[3];
} __attribute__((packed, aligned(4)));
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @plbossart we have the capability to send the format information through the kcontrol data. Is that enough?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will of course mean 2 IPC's instead of 1
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, but we need to modify pcm_params_ipc to add snd_codec inside it.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This could work in hw_params / set_params we could sent the normal SOF_IPC_STREAM_PCM_PARAMS IPC and then also call snd_sof_ipc_set_get_comp_data with SET_DATA containing the snd_codec. But is it possible to call snd_sof_ipc_set_get_comp_data from set_params/hw_params? For PCM case we can just use the default codec id (and maybe fix it later if Intel decides to add more codecs).
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but why? we can send it in the data part of the COMP SET_DATA IPC isnt it which will precede the PCM_PARAMS
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, absolutely
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we only need to do it from set_params() right? or do we need this in hw_params() too? |
||
|
|
||
| uint8_t reserved[5]; | ||
| uint16_t chmap[SOF_IPC_MAX_CHANNELS]; /**< channel map - SOF_CHMAP_ */ | ||
| } __attribute__((packed, aligned(4))); | ||
|
|
||
|
|
||
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.
unsigned intshould be fine for this. My personal current favourite for this kind of variables would ben_apis, not saying it's the absolute best, butno_of_<single_form_noun>seems even less clear to me :-)