
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 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;
}
- }
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