From: Takashi Iwai Subject: Re: [PATCH v1 2/4] alsabat: parse the card and PCM ID for XRUN injections path Date: Thu, 31 Aug 2017 20:19:27 +0200 Message-ID: References: <20170831133709.25537-1-keqiao.zhang@intel.com> <20170831133709.25537-3-keqiao.zhang@intel.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id A5D4A266B70 for ; Thu, 31 Aug 2017 20:19:30 +0200 (CEST) In-Reply-To: <20170831133709.25537-3-keqiao.zhang@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Zhang Keqiao Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org On Thu, 31 Aug 2017 15:37:07 +0200, Zhang Keqiao wrote: > > This patch intends to parse the card ID and PCM ID of playback > and capture, then replace it in the path macro. > > Signed-off-by: Zhang Keqiao > --- > bat/bat.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > bat/common.h | 3 +++ > 2 files changed, 72 insertions(+) > > diff --git a/bat/bat.c b/bat/bat.c > index bf6873a..b12e5d3 100644 > --- a/bat/bat.c > +++ b/bat/bat.c > @@ -127,6 +127,69 @@ static void get_sine_frequencies(struct bat *bat, char *freq) > } > } > > +/* parse the card and pcm ID of playback device and capture device */ > +/* Then we can get the path for specify device to do the XRUN injection */ > +static int parse_card_and_pcm_id(struct bat *bat) > +{ > + char *tmp1; > + char *tmp2; > + char playback_device[MAX_DEV]; > + char capture_device[MAX_DEV]; > + > + strcpy(playback_device, bat->playback.device); > + strcpy(capture_device, bat->capture.device); > + > + if (bat->playback.device == bat->capture.device) { > + tmp1 = strchr(playback_device, ','); > + if (tmp1 != NULL) { > + *tmp1 = '\0'; > + bat->playback.pcm_id = bat->capture.pcm_id = (tmp1 + 1); > + } else { > + fprintf(bat->err, _("err, cannot find the pcm ID\n")); > + return -EINVAL; > + } > + tmp2 = strchr(playback_device, ':'); > + if (tmp2 != NULL) { > + bat->playback.card_id = bat->capture.card_id = (tmp2 + 1); > + } else { > + fprintf(bat->err, _("err, cannot find the card ID\n")); > + return -EINVAL; > + } > + } else { > + tmp1 = strchr(playback_device, ','); > + if (tmp1 != NULL) { > + *tmp1 = '\0'; > + bat->playback.pcm_id = (tmp1 + 1); > + } else { > + fprintf(bat->err, _("err, cannot find the pcm ID of playback\n")); > + return -EINVAL; > + } > + tmp2 = strchr(playback_device, ':'); > + if (tmp2 != NULL) > + bat->playback.card_id = (tmp2 + 1); > + else { > + fprintf(bat->err, _("err, cannot find the card ID of playback\n")); > + return -EINVAL; > + } > + tmp1 = strchr(capture_device, ','); > + if (tmp1 != NULL) { > + *tmp1 = '\0'; > + bat->capture.pcm_id = (tmp1 + 1); > + } else { > + fprintf(bat->err, _("err, cannot find the pcm ID of capture")); > + return -EINVAL; > + } > + tmp2 = strchr(capture_device, ':'); > + if (tmp2 != NULL) > + bat->capture.card_id = (tmp2 + 1); > + else { > + fprintf(bat->err, _("err, cannot find the card ID of capture")); > + return -EINVAL; > + } > + } FYI, a handy function for this kind of parsing is sscanf(). For example, the above can be a simple form like: if (sscanf(bat->playback.device, "pcm:%d,%d", &card, &pcm) != 2) return -EINVAL; thanks, Takashi