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

tplgtool2: print all supported formats of PCM and adjust alignment #1105

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

mengdonglin
Copy link
Contributor

@mengdonglin mengdonglin commented Sep 17, 2023

Make print_pcm_info() show all supported formats of a PCM. The alignment and order of PCM attributes are also adjusted.

Update history:
v2: use fmts = ' '.join(fmt_list[cap_index]) to get all supported formats
follow previous "key=value;" format for PCM ID and name.
make PCM name right-aligned to the longest PCM name

Example: sof-mtl-max98357a-rt5682-ssp2-ssp0-2ch-pdm1.tplg
Before change:

pcm=Headset;id=0;type=duplex;fmt=S16_LE;rate_min=48000;rate_max=48000;ch_min=2;ch_max=2;
pcm=Speakers;id=1;type=playback;fmt=S16_LE;rate_min=48000;rate_max=48000;ch_min=2;ch_max=2;
pcm=Bluetooth;id=2;type=duplex;fmt=S16_LE;rate_min=8000;rate_max=48000;ch_min=1;ch_max=2;
pcm=HDMI1;id=5;type=playback;fmt=S16_LE;rate_min=48000;rate_max=48000;ch_min=2;ch_max=8;
pcm=HDMI2;id=6;type=playback;fmt=S16_LE;rate_min=48000;rate_max=48000;ch_min=2;ch_max=8;
pcm=HDMI3;id=7;type=playback;fmt=S16_LE;rate_min=48000;rate_max=48000;ch_min=2;ch_max=8;
pcm=EchoRef;id=29;type=capture;fmt=S16_LE;rate_min=48000;rate_max=48000;ch_min=2;ch_max=2;
pcm=Deepbuffer Jack Out;id=31;type=playback;fmt=S16_LE;rate_min=48000;rate_max=48000;ch_min=2;ch_max=2;
pcm=DMIC Raw;id=99;type=capture;fmt=S32_LE;rate_min=48000;rate_max=48000;ch_min=2;ch_max=2;

After change:

pcm_id= 0;name=Headset            ;type=duplex  ;rate_min= 48000;rate_max= 48000;ch_min=2;ch_max=2;fmt=S16_LE S24_LE S32_LE
pcm_id= 1;name=Speakers           ;type=playback;rate_min= 48000;rate_max= 48000;ch_min=2;ch_max=2;fmt=S16_LE S24_LE S32_LE
pcm_id= 2;name=Bluetooth          ;type=duplex  ;rate_min=  8000;rate_max= 48000;ch_min=1;ch_max=2;fmt=S16_LE
pcm_id= 5;name=HDMI1              ;type=playback;rate_min= 48000;rate_max= 48000;ch_min=2;ch_max=8;fmt=S16_LE S32_LE
pcm_id= 6;name=HDMI2              ;type=playback;rate_min= 48000;rate_max= 48000;ch_min=2;ch_max=8;fmt=S16_LE S32_LE
pcm_id= 7;name=HDMI3              ;type=playback;rate_min= 48000;rate_max= 48000;ch_min=2;ch_max=8;fmt=S16_LE S32_LE
pcm_id=29;name=EchoRef            ;type=capture ;rate_min= 48000;rate_max= 48000;ch_min=2;ch_max=2;fmt=S16_LE S24_LE S32_LE
pcm_id=31;name=Deepbuffer Jack Out;type=playback;rate_min= 48000;rate_max= 48000;ch_min=2;ch_max=2;fmt=S16_LE S24_LE S32_LE
pcm_id=99;name=DMIC Raw           ;type=capture ;rate_min= 48000;rate_max= 48000;ch_min=2;ch_max=2;fmt=S32_LE

Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

Thanks for the examples, very useful. Not sure we need that many though. Instead, we miss at least one before/after example.

fmt = fmt_list[cap_index][0] # only show first format
fmts = ''
for fmt in fmt_list[cap_index]:
fmts = fmts + fmt + ' '
Copy link
Collaborator

Choose a reason for hiding this comment

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

fmts = ' '.join(fmt_list[cap_index])

f"rate_min={rate_min};rate_max={rate_max};ch_min={ch_min};ch_max={ch_max};")
print(f"pcm {pcm_id:>2}: {name:<22};type={pcm_type:<8};"
f"rate_min={rate_min:>6};rate_max={rate_max:>6};ch_min={ch_min};ch_max={ch_max};"
f"fmt={fmts}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
f"fmt={fmts}")
f"fmts={fmts}")

rate_min = cap["rate_min"]
rate_max = cap["rate_max"]
ch_min = cap["channels_min"]
ch_max = cap["channels_max"]
print(f"pcm={name};id={pcm_id};type={pcm_type};fmt={fmt};"
f"rate_min={rate_min};rate_max={rate_max};ch_min={ch_min};ch_max={ch_max};")
print(f"pcm {pcm_id:>2}: {name:<22};type={pcm_type:<8};"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The output looks much better. However the previous code was producing consistent output easy to parse because everything was formated key=value;. this PR breaks that.

I think we can have both the parsable output AND the indentation; try something like this:

name_semi = pcm["pcm_name"] + ";"
.
.
.

print(f"pcm={pcm_id:>2}; name={name_semi:<21} ...")

Choose a reason for hiding this comment

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

let's find the longest filed of each column, and use it for formatting.

Copy link
Contributor Author

@mengdonglin mengdonglin Sep 18, 2023

Choose a reason for hiding this comment

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

@marc-hb @aiChaoSONG Thanks for your review and suggestions! All comments addressed in v2. Can you please give a check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marc-hb Chao confirmed our test cases use output of ./tools/sof-tplgreader.py to check PCM streams, not output of this tplgtool2.py So we can make the output more human friendly. Now I still follow key=value; in v2 patches.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Chao confirmed our test cases use output of ./tools/sof-tplgreader.py to check PCM streams, not output of this tplgtool2.py

We don't know who parses the output of this script. It has existed for a very long time.

Now I still follow key=value ;

Thanks! The new whitespace could still break someone but that should be very quick and easy to fix.

@mengdonglin mengdonglin force-pushed the main branch 4 times, most recently from aa9e339 to 50656c1 Compare September 18, 2023 12:56
Make print_pcm_info() show all supported formats of a PCM, not only
the first format.

And show the formats after other attributes, thus other attributes may
have better alignment.

Signed-off-by: Mengdong Lin <[email protected]>
print_pcm_info() will show pcm ID before its name.

Also adjust alignment:
- id: 2 characters, right alignment.
- name: left alignment to the longest PCM name.
- type (playback/capture/duplex): 8 characters, left alignment.
- rate: 6 characters, right alignment, for highest rate '192000'.

Strings longer than the alignment won't be cut.

Signed-off-by: Mengdong Lin <[email protected]>
@aiChaoSONG
Copy link

No one is parsing this output yet, let merge and do improvement incrementally.

@aiChaoSONG aiChaoSONG merged commit bbae502 into thesofproject:main Sep 19, 2023
3 checks passed
@marc-hb
Copy link
Collaborator

marc-hb commented Sep 20, 2023

No one is parsing this output yet,

No one can tell that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants