-
Notifications
You must be signed in to change notification settings - Fork 139
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
topology: Fix dmic nhlt blob building, and fix $[] attribute value resolving #250
Changes from all commits
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 |
---|---|---|
|
@@ -1589,6 +1589,7 @@ pre_process_object_variables_expand_fcn(snd_config_t **dst, const char *str, voi | |
snd_config_t *object_cfg = tplg_pp->current_obj_cfg; | ||
snd_config_t *conf_defines; | ||
const char *object_id; | ||
const char *val; | ||
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. @jsarha will this still work if you had the object defined like this instead?
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, that works after this change. This is the original problem the "topology: Expand attribute references inside $[] expressions"-commit is fixing. E.g. allow Object.Base.input_audio_format.in_rate be defined as |
||
int ret; | ||
|
||
ret = snd_config_search(tplg_pp->input_cfg, "Define", &conf_defines); | ||
|
@@ -1600,14 +1601,31 @@ pre_process_object_variables_expand_fcn(snd_config_t **dst, const char *str, voi | |
if (ret >= 0) | ||
return ret; | ||
|
||
/* No global define found, proceeed to object attribute search */ | ||
if (snd_config_get_id(object_cfg, &object_id) < 0) | ||
return -EINVAL; | ||
|
||
/* find variable from object attribute values if not found in global definitions */ | ||
ret = pre_process_find_variable(dst, str, object_cfg); | ||
if (ret < 0) | ||
if (ret < 0) { | ||
SNDERR("Failed to find definition for attribute %s in '%s' object\n", | ||
str, object_id); | ||
return ret; | ||
} | ||
|
||
/* the extracted value may contain a nested $-expression */ | ||
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 can happen only in the case of a variable that points to a object attribute right? So can we move this block inside the previous if block after like 1612? 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. @ranj063 , is there any reason for us to forbid 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. @jarsha its not that we want to forbid but it's not really useful isn't it? The global definitions are all known prior to building all objects. So, having references to other globals is the only option and that seems futile isn't it? 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. @ranj063 , I don't think the preprocessor works that way. The top level definitions are never resolved for
And then in
I tested that this work. I can imagine that there could be some use for some common expressions defined at top-level, relying on generic object attributes, and used in several objects. 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 does that even make sense. Have a global definition that uses a local attribute definition? The other way around makes sense. 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. I can see some sense in that, but if you don't, that is good enough. We can very well live without this "feature". I'll disable it. |
||
if (snd_config_get_string(*dst, &val) >= 0) { | ||
if (val[0] == '$') { | ||
char *var = strdup(val); | ||
|
||
snd_config_remove(*dst); | ||
snd_config_delete(*dst); | ||
ret = snd_config_evaluate_string(dst, var, | ||
pre_process_object_variables_expand_fcn, | ||
tplg_pp); | ||
free(var); | ||
} | ||
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. Shouldn't we "snd_config_delete(*dst)" also in this case won L1623...? 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. No, I don't think so. The *dst is passed to the caller and it should do what is necessary (however a string value in $[] is probably an error). The reason why I have to delete *dst here is because I reuse *dst to store the result of the defines search and the pointer holding the result of object attribute search may be lost. 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. Then again a paranoid programmer would check strdup() result and return -ENOMEM in case its NULL. But since this is a commmand line tool, and there is probably some out of memory error produced by libc, I do not think its necessary. 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. could this be a recursive case like
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.
EDIT: My point was that 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. Now that I think about it, I guess it could be that the object attribute is an expression of form $ [channels * 4] , plain $channels *4 should not be allowed. But yes, a recursive call to snd_config_evaluate_string() should do it. About @perexg 's question, there is a functional difference in tplg_evaluate_config_string() and snd_config_evaluate_string(). tplg_evaluate_config_string() expands $ VAR_NAME occurrences in the middle of the string, unlike plain snd_config_evaluate_string(). However, the functionality could probably be moved to snd_config_evaluate_string(). 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 would be also more elegant to use
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. I am not yet too fluent with snd_config_* -functions, but is the remove necessary in this case, where the *dst is already a product of snd_config_copy()? 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. Now that I have read the code back and forth a bit, I am pretty sure the remove is unnecessary for a node, that has just been copied with snd_config_copy(). However, @perexg if you still think that it is good coding practice to add it there, then certainly I will. |
||
} | ||
|
||
return ret; | ||
} | ||
|
@@ -1623,7 +1641,7 @@ pre_process_object_variables_expand_fcn(snd_config_t **dst, const char *str, voi | |
* or '\0'. | ||
* | ||
* In '$[<contents>]' case all letters but '[' and ']' are allow in | ||
* any sequence. Nested '[]' is also allowed if the number if '[' and | ||
* any sequence. Nested '[]' is also allowed if the number of '[' and | ||
* ']' match. | ||
* | ||
* The function modifies *stringp, and *prefix - if not NULL - points | ||
|
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.
typo in commit: clock diver -> clock divider