From 5dfc2d521bc78cb6224a73b722cf32881021294c Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Wed, 23 Oct 2024 11:07:47 -0700 Subject: [PATCH] tools: plugin: Simplify the command line Make the card/dev names and config names optional in the command line. This will simplify the command line to just pass the PCM ID to start playback using the default device as follows: aplay -Dsof:plugin:1 Signed-off-by: Ranjani Sridharan --- tools/plugin/README.md | 13 ++++++++++++ tools/plugin/alsaplug/plugin.c | 37 +++++++++++++++++----------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/tools/plugin/README.md b/tools/plugin/README.md index 673cbceb08ff..ce0cad4ea4cd 100644 --- a/tools/plugin/README.md +++ b/tools/plugin/README.md @@ -60,6 +60,19 @@ The command line is parsed as follows: - "default": The second default is the device name - "48k2c16b" is the config name for 48K, stereo, 16bit +Config name is optional in the command line. When it is not provided, hw_params will be used to +configure the endpoint. In this case, the command line can be simplified to: + +``` +aplay -Dsof:plugin:1:default:default +``` + +When using the default device, the command line can be further simplified to: + +``` +aplay -Dsof:plugin:1 +``` + This renders audio to the sof-pipe daemon using the sof-plugin topology playback PCM ID 1. The above example needs to be 48k as example pipe has no SRC/ASRC. diff --git a/tools/plugin/alsaplug/plugin.c b/tools/plugin/alsaplug/plugin.c index be5ff0e69f2b..deb767a4133f 100644 --- a/tools/plugin/alsaplug/plugin.c +++ b/tools/plugin/alsaplug/plugin.c @@ -270,28 +270,29 @@ static int parse_client_cmdline(snd_sof_plug_t *plug, char *cmdline, bool just_t cmd_item = &plug->cmdline[plug->num_cmdline]; card = strtok_r(next, ":", &next); + /* card/dev names and config are all optional */ if (!card) { - SNDERR("Invalid card name\n"); - return -EINVAL; - } - dev = strtok_r(next, ":", &next); - if (!dev) { - SNDERR("Invalid dev name\n"); - return -EINVAL; - } - config = strtok_r(next, ":", &next); - - /* tuple needs all three, any missing ? */ - if (!config) { - SNDERR("invalid cmdline, expected pcm(%s):card(%s):dev(%s):config(%s) from %s", - pcm, card, dev, config, tplg); - return -EINVAL; + strncpy(cmd_item->card_name, "default", sizeof(cmd_item->card_name)); + strncpy(cmd_item->dev_name, "default", sizeof(cmd_item->dev_name)); + fprintf(stdout, "no config name provided, will use hw_params\n"); + } else { + strncpy(cmd_item->card_name, card, sizeof(cmd_item->card_name)); + dev = strtok_r(next, ":", &next); + /* dev name must be provided along with card name */ + if (!dev) { + SNDERR("Invalid dev name\n"); + return -EINVAL; + } + strncpy(cmd_item->dev_name, dev, sizeof(cmd_item->dev_name)); + config = strtok_r(next, ":", &next); + /* config name is optional */ + if (!config) + fprintf(stdout, "no config name provided, will use hw_params\n"); + else + strncpy(cmd_item->config_name, config, sizeof(cmd_item->config_name)); } cmd_item->pcm = atoi(pcm); - strncpy(cmd_item->card_name, card, sizeof(cmd_item->card_name)); - strncpy(cmd_item->dev_name, dev, sizeof(cmd_item->dev_name)); - strncpy(cmd_item->config_name, config, sizeof(cmd_item->config_name)); /* * dev name is special, we cant use "," in the command line