-
Notifications
You must be signed in to change notification settings - Fork 59
volume-basic-test.sh: switch to .tplg parsing to test topologies v2 #1193
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
3eaebc6
ac8d62a
09df371
1dce3d7
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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| """Parses the .tplg file argument and returns a list of volume | ||
| kcontrols, one per line. | ||
| Pro tip: try using these commands _interactively_ with ipython3 | ||
| """ | ||
|
|
||
| # Keep this script short and simple. If you want to get something else | ||
| # from .tplg files, create another script. | ||
|
|
||
| import sys | ||
| from tplgtool2 import TplgBinaryFormat, TplgType, DapmType, SofVendorToken | ||
|
|
||
| TPLG_FORMAT = TplgBinaryFormat() | ||
|
|
||
|
|
||
| def main(): | ||
| "Main" | ||
|
|
||
| parsed_tplg = TPLG_FORMAT.parse_file(sys.argv[1]) | ||
|
|
||
| # pylint: disable=invalid-name | ||
| DAPMs = [ | ||
| item for item in parsed_tplg if item.header.type == TplgType.DAPM_WIDGET.name | ||
| ] | ||
|
|
||
| for dapm in DAPMs: | ||
| gain_blocks = [b for b in dapm.blocks if b.widget.id == DapmType.PGA.name] | ||
|
|
||
| for gb in gain_blocks: | ||
| # debug | ||
| # print(f"{gb.widget.id}: {gb.widget.name}") | ||
| print_volume_kcontrols(gb) | ||
|
|
||
|
|
||
| def print_volume_kcontrols(gain_block): | ||
| "Print volume kcontrols" | ||
|
|
||
| # Either 1 volume kcontrol, or 1 volume + 1 switch | ||
| assert gain_block.widget.num_kcontrols in (1, 2) | ||
|
|
||
| # A switch is either a DapmType.SWITCH, or DapmType.MIXER | ||
| # with a max "volume" = 1. Don't include switches here. | ||
| volume_kcontrols = [ | ||
| kc | ||
| for kc in gain_block.kcontrols | ||
| if kc.hdr.type == DapmType.MIXER.name and kc.body.max != 1 | ||
|
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. indentation doesn't look like usual python, is this intentional?
Contributor
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. python list comprehension @plbossart
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. This new script was formatted with |
||
| ] | ||
|
|
||
| assert len(volume_kcontrols) == 1 | ||
|
|
||
| wname_prefix = ( | ||
| f"{gain_block.widget.name} " if has_wname_prefix(gain_block.widget) else "" | ||
| ) | ||
|
|
||
| for vkc in volume_kcontrols: | ||
| print(wname_prefix + vkc.hdr.name) | ||
|
|
||
|
|
||
| # This could probably be moved to tplgtool2.py? | ||
| def has_wname_prefix(widget): | ||
| """Is the kcontrol name prefixed with the widget name? ("PGAxx" or "Dmicxx") | ||
| Check SOF_TKN_COMP_NO_WNAME_IN_KCONTROL_NAME""" | ||
|
|
||
| wname_elems = [ | ||
| prv.elems | ||
| for prv in widget.priv | ||
| if prv.elems[0].token | ||
| == SofVendorToken.SOF_TKN_COMP_NO_WNAME_IN_KCONTROL_NAME.name | ||
|
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. same here, indentation is probably something intentional but someone like me will never figure out what this does.
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. List comprehension here too. This is just building a list from another, filtered list. |
||
| ] | ||
|
|
||
| if len(wname_elems) == 0: # typically: topo v1 | ||
| no_wname_prefix = 0 | ||
| elif len(wname_elems) == 1: # typically: topo v2 | ||
| assert len(wname_elems[0]) == 1 | ||
| no_wname_prefix = wname_elems[0][0].value | ||
| else: | ||
| assert False, f"Unexpected len of wname_elems={wname_elems}" | ||
|
|
||
| assert no_wname_prefix in (0, 1) | ||
|
|
||
| # Double-negation: "no_wname false" => prefix | ||
| return not no_wname_prefix | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,7 +198,7 @@ class PcmFormatsFlag(enum.IntFlag): | |
| class SofVendorToken(enum.IntEnum): | ||
| r"""SOF vendor tokens | ||
|
|
||
| See `tools/topology1/sof/tokens.m4` in SOF. | ||
| Duplicates Linux' `include/uapi/sound/sof/tokens.h` | ||
| """ | ||
| # sof_buffer_tokens | ||
| SOF_TKN_BUF_SIZE = 100 | ||
|
|
@@ -235,6 +235,7 @@ class SofVendorToken(enum.IntEnum): | |
| SOF_TKN_COMP_CORE_ID = 404 | ||
| SOF_TKN_COMP_UUID = 405 | ||
| SOF_TKN_COMP_CPC = 406 | ||
| SOF_TKN_COMP_NO_WNAME_IN_KCONTROL_NAME = 417 | ||
| # sof_ssp_tokens | ||
| SOF_TKN_INTEL_SSP_CLKS_CONTROL = 500 | ||
| SOF_TKN_INTEL_SSP_MCLK_ID = 501 | ||
|
|
@@ -1330,6 +1331,7 @@ def main(): | |
| errors = 0 | ||
| for f in files: | ||
| tplg = GroupedTplg(tplgFormat.parse_file(f)) | ||
| assert set(dump_types) <= set(supported_dump), f"unsupported type in {dump_types}" | ||
|
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. no idea what this does.
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. Before this commit, a typo in the command-line argument was silently producing no output. |
||
| if 'pcm' in dump_types: | ||
| tplg.print_pcm_info() | ||
| if 'graph' in dump_types: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.