From 16f77f6d91ac50bb9d666b69567796cf56aa3552 Mon Sep 17 00:00:00 2001 From: Fred Oh Date: Wed, 10 Apr 2024 15:23:53 -0700 Subject: [PATCH] sof-tplgreader: parse rates from topology file Related to sampling rate in caps, there are rates, rate_min and rate_max. Added support for the rates list from the topology file and use first in the list as supported rate. The sampling rate 48000 is intentionally placed first in the dictionary to ensure it appears first in the list. Signed-off-by: Fred Oh --- README.md | 5 ++++- tools/sof-tplgreader.py | 14 +++++++++++++- tools/tplgtool.py | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f368d76a..0fdcb24f 100644 --- a/README.md +++ b/README.md @@ -146,9 +146,12 @@ apl * tplgtool2.py
Dumps info from tplg binary file. + SOF CI uses this to generate a topology graph. * tplgtool.py -
Dumps info from tplg binary file. (deprecated) +
Dumps info from tplg binary file. sof-tplgreader.py still use this but new features + will go to tplgtool2.py. When all functions are migrated to tplgtool2.py + it will be deprecated. ## System configuration tips diff --git a/tools/sof-tplgreader.py b/tools/sof-tplgreader.py index cb45cd73..26fd06a2 100755 --- a/tools/sof-tplgreader.py +++ b/tools/sof-tplgreader.py @@ -63,11 +63,13 @@ def loadFile(self, filename, sofcard=0): # supported formats of playback pipeline in formats[0] # supported formats of capture pipeline in formats[1] formats = TplgFormatter.get_pcm_fmt(pcm) + rates = TplgFormatter.get_pcm_rate_list(pcm) # if capture is present, pcm['capture'] = 1, otherwise, pcm['capture'] = 0, # same thing for pcm['playback'] pipeline_dict['fmts'] = " ".join(formats[pcm['capture']]) # use the first supported format for test pipeline_dict['fmt'] = pipeline_dict['fmts'].split(' ')[0] + pipeline_dict['rates'] = " ".join(rates[pcm['capture']]) pipeline_dict['rate_min'], pipeline_dict['rate_max'] = self._key2str(cap, 'rate') pipeline_dict['ch_min'], pipeline_dict['ch_max'] = self._key2str(cap, 'channels') # for pcm with both playback and capture capabilities, we can extract two pipelines. @@ -95,7 +97,17 @@ def loadFile(self, filename, sofcard=0): # format pipeline, this change for script direct access 'rate' 'channel' 'dev' 'snd' for pipeline in self._pipeline_lst: #pipeline['fmt']=pipeline['fmt'].upper().replace('LE', '_LE') - pipeline['rate'] = pipeline['rate_min'] if int(pipeline['rate_min']) != 0 else pipeline['rate_max'] + # If rates is available get first sampling rate from the list. + # If rates list doesn't have any, then get it from rate_min or rate_max. + # If none of them is available, then set rate to 0 + if pipeline['rates']: + pipeline['rate'] = pipeline['rates'].split(' ')[0] + elif int(pipeline['rate_min']) != 0: + pipeline['rate'] = pipeline['rate_min'] + elif int(pipeline['rate_max']) != 0: + pipeline['rate'] = pipeline['rate_max'] + else: + pipeline['rate'] = 0 pipeline['channel'] = pipeline['ch_min'] pipeline['dev'] = "hw:" + str(sofcard) + ',' + pipeline['id'] # the character devices for PCM under /dev/snd take the form of diff --git a/tools/tplgtool.py b/tools/tplgtool.py index 2e7873ef..3ae6150a 100755 --- a/tools/tplgtool.py +++ b/tools/tplgtool.py @@ -607,6 +607,17 @@ def _to_fmt_string(fmt): fmts.append("FLOAT") return fmts + + # transform number denoted pipeline sampling rates to string + @staticmethod + def _to_rate_string(rate): + # Note: intentionally put 48000 first to make first in the list + bit_rates_dict = {7 : 48000, + 1 : 8000, 3 : 16000, 4 : 22050, 5 : 32000, 6 : 44100, + 8 : 64000, 9 : 96000} + return [ str(bit_rates_dict[bit]) for bit in bit_rates_dict + if rate & (1 << bit) != 0 ] + # always return a list, playback stream fmt in fmt_list[0] # capture stream fmt in fmt_list[1], the format of absense # stream is UNKNOWN @@ -618,6 +629,12 @@ def get_pcm_fmt(pcm): fmt_list.append(TplgFormatter._to_fmt_string(cap["formats"])) return fmt_list + # always return a list, pcm rates in the list in ascending order + @staticmethod + def get_pcm_rate_list(pcm): + caps = pcm["caps"] + return [ TplgFormatter._to_rate_string(cap["rates"]) for cap in caps ] + @staticmethod def get_pcm_type(item): if item["playback"] == 1 and item["capture"] == 1: