All of lore.kernel.org
 help / color / mirror / Atom feed
From: guneshwor.o.singh@intel.com
To: alsa-devel@alsa-project.org, tiwai@suse.com
Cc: vinod.koul@intel.com, mengdong.lin@intel.com,
	Guneshwor Singh <guneshwor.o.singh@intel.com>,
	liam.r.girdwood@intel.com
Subject: [PATCH 3/3] topology: Add parsing for rates from conf
Date: Wed, 31 May 2017 19:16:46 +0530	[thread overview]
Message-ID: <20170531134646.9081-3-guneshwor.o.singh@intel.com> (raw)
In-Reply-To: <20170531134646.9081-1-guneshwor.o.singh@intel.com>

From: Guneshwor Singh <guneshwor.o.singh@intel.com>

rate_min and rate_max are parsed currently, some drivers
may also use rates to specify PCM stream capability. So
add support to parse it.

Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com>
---
 include/topology.h |  1 +
 src/topology/pcm.c | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/include/topology.h b/include/topology.h
index ccb3a004..42d23762 100644
--- a/include/topology.h
+++ b/include/topology.h
@@ -534,6 +534,7 @@ extern "C" {
  * SectionPCMCapabilities."name" {
  *
  *	formats "S24_LE,S16_LE"		# Supported formats
+ *	rates "48000"			# Supported rates
  *	rate_min "48000"		# Max supported sample rate
  *	rate_max "48000"		# Min supported sample rate
  *	channels_min "2"		# Min number of channels
diff --git a/src/topology/pcm.c b/src/topology/pcm.c
index daef20e4..52165243 100644
--- a/src/topology/pcm.c
+++ b/src/topology/pcm.c
@@ -309,6 +309,29 @@ static int split_format(struct snd_soc_tplg_stream_caps *caps, char *str)
 	return 0;
 }
 
+static int split_rate(struct snd_soc_tplg_stream_caps *caps, char *str)
+{
+	char *s = NULL;
+	snd_pcm_rates_t rate;
+	int i = 0;
+
+	s = strtok(str, ",");
+	while ((s) && (i < SND_SOC_TPLG_MAX_RATES)) {
+		rate = snd_pcm_rate_value(s);
+
+		if (rate == SND_PCM_RATE_UNKNOWN) {
+			SNDERR("error: unsupported stream rate %s\n", s);
+			return -EINVAL;
+		}
+
+		caps->rates |= 1 << rate;
+		s = strtok(NULL, ", ");
+		i++;
+	}
+
+	return 0;
+}
+
 /* Parse pcm stream capabilities */
 int tplg_parse_stream_caps(snd_tplg_t *tplg,
 	snd_config_t *cfg, void *private ATTRIBUTE_UNUSED)
@@ -360,6 +383,21 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg,
 			continue;
 		}
 
+		if (strcmp(id, "rates") == 0) {
+			s = strdup(val);
+			if (!s)
+				return -ENOMEM;
+
+			err = split_rate(sc, s);
+			free(s);
+
+			if (err < 0)
+				return err;
+
+			tplg_dbg("\t\t%s: %s\n", id, val);
+			continue;
+		}
+
 		if (strcmp(id, "rate_min") == 0) {
 			sc->rate_min = atoi(val);
 			tplg_dbg("\t\t%s: %d\n", id, sc->rate_min);
-- 
2.13.0

  parent reply	other threads:[~2017-05-31 13:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-31 13:46 [PATCH 1/3] pcm: add support to get PCM sample rate from name guneshwor.o.singh
2017-05-31 13:46 ` [PATCH 2/3] topology: Add max rates definition guneshwor.o.singh
2017-05-31 13:46 ` guneshwor.o.singh [this message]
2017-05-31 13:53 ` [PATCH 1/3] pcm: add support to get PCM sample rate from name Takashi Iwai
2017-06-01  4:09   ` Singh, Guneshwor
2017-06-01  5:55     ` Takashi Iwai
2017-06-01  5:59       ` Singh, Guneshwor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170531134646.9081-3-guneshwor.o.singh@intel.com \
    --to=guneshwor.o.singh@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=liam.r.girdwood@intel.com \
    --cc=mengdong.lin@intel.com \
    --cc=tiwai@suse.com \
    --cc=vinod.koul@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.