Skip to content
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

volume-basic-test.sh: switch to .tplg parsing to test topologies v2 #1193

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions tools/topo_vol_kcontrols.py
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)
ranj063 marked this conversation as resolved.
Show resolved Hide resolved

# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation doesn't look like usual python, is this intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python list comprehension @plbossart

Copy link
Collaborator Author

@marc-hb marc-hb May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python list comprehension

Yes.

This new script was formatted with black; recommended. Warning: black formats in place, make a backup first if needed.

]

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
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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()
4 changes: 3 additions & 1 deletion tools/tplgtool2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea what this does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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:
Expand Down