All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Keqiao <keqiao.zhang@intel.com>
To: alsa-devel@alsa-project.org
Cc: keqiao.zhang@intel.com
Subject: [PATCH v1 2/4] alsabat: parse the card and PCM ID for XRUN injections path
Date: Thu, 31 Aug 2017 21:37:07 +0800	[thread overview]
Message-ID: <20170831133709.25537-3-keqiao.zhang@intel.com> (raw)
In-Reply-To: <20170831133709.25537-1-keqiao.zhang@intel.com>

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 <keqiao.zhang@intel.com>
---
 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;
+		}
+	}
+	return 0;
+}
+
 static void get_format(struct bat *bat, char *optarg)
 {
 	if (strcasecmp(optarg, "cd") == 0) {
@@ -561,6 +624,12 @@ static int bat_init(struct bat *bat)
 			return err;
 	}
 
+	if (bat->xarg) {
+		err = parse_card_and_pcm_id(bat);
+		if (err < 0)
+			return err;
+	}
+
 	/* Set default playback and capture devices */
 	if (bat->playback.device == NULL && bat->capture.device == NULL)
 		bat->playback.device = bat->capture.device = DEFAULT_DEV_NAME;
diff --git a/bat/common.h b/bat/common.h
index a014f87..9f71c6c 100644
--- a/bat/common.h
+++ b/bat/common.h
@@ -16,6 +16,7 @@
 #define TEMP_RECORD_FILE_NAME		"/tmp/bat.wav.XXXXXX"
 #define DEFAULT_DEV_NAME		"default"
 
+#define MAX_DEV				15
 #define OPT_BASE			300
 #define OPT_LOG				(OPT_BASE + 1)
 #define OPT_READFILE			(OPT_BASE + 2)
@@ -167,6 +168,8 @@ struct pcm {
 	unsigned int device_tiny;
 	char *device;
 	char *file;
+	char *pcm_id;
+	char *card_id;
 	enum _bat_op_mode mode;
 	void *(*fct)(struct bat *);
 };
-- 
2.9.3

  parent reply	other threads:[~2017-08-31 13:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 13:37 [PATCH v1 0/4] *** add XRUN injections suppport in alsabat *** Zhang Keqiao
2017-08-31 13:37 ` [PATCH v1 1/4] alsabat: add one option for XRUN injections Zhang Keqiao
2017-08-31 13:37 ` Zhang Keqiao [this message]
2017-08-31 18:19   ` [PATCH v1 2/4] alsabat: parse the card and PCM ID for XRUN injections path Takashi Iwai
2017-08-31 13:37 ` [PATCH v1 3/4] alsabat: add XRUN injections function Zhang Keqiao
2017-08-31 18:22   ` Takashi Iwai
2017-08-31 13:37 ` [PATCH v1 4/4] alsabat: XRUN injections test criteria Zhang Keqiao
2017-08-31 18:23 ` [PATCH v1 0/4] *** add XRUN injections suppport in alsabat *** Takashi Iwai

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=20170831133709.25537-3-keqiao.zhang@intel.com \
    --to=keqiao.zhang@intel.com \
    --cc=alsa-devel@alsa-project.org \
    /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.