From patchwork Mon Oct 2 09:49:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9980579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 41F56603FF for ; Mon, 2 Oct 2017 09:52:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 331EB288B1 for ; Mon, 2 Oct 2017 09:52:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2805A28953; Mon, 2 Oct 2017 09:52:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 786BD28947 for ; Mon, 2 Oct 2017 09:52:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyxM2-0005pR-8V; Mon, 02 Oct 2017 09:49:38 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dyxM0-0005oJ-UG for xen-devel@lists.xenproject.org; Mon, 02 Oct 2017 09:49:37 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 73/7C-02224-0BB02D95; Mon, 02 Oct 2017 09:49:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrFIsWRWlGSWpSXmKPExsVyMfS6k+567ku RBv9eSFh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlf9uxiLNjtWvHt/3m2BsbThl2MXBxCAjMY JXadOs8M4rAIvGSROHxzLROIIyHQzyrx7thl9i5GTiAnS+LFxv1AVRxAdprEsiuxEOEKieZ55 5hAbCEBeYmDLSDlIFOnMUnMfPeRFSTBJqAlcf/2CjYQW0RASeLeqslgDcwCKRJ717UxgtjCAs YSb2cuYAGxWQRUJZbvOgjWyyvgILG7YwYzxDI5iZvnOsFsTgFHiR0r17NALHaQ+NnYwDqBUXA BI8MqRo3i1KKy1CJdIwO9pKLM9IyS3MTMHF1DA2O93NTi4sT01JzEpGK95PzcTYzAkKtnYGDc wdh8wu8QoyQHk5Io73+OS5FCfEn5KZUZicUZ8UWlOanFhxg1ODgEfj7928IoxZKXn5eqJMGrD AxtIcGi1PTUirTMHGBUwJRKcPAoifC6gKR5iwsSc4sz0yFSpxjtOS7cufSHiePYpstA8sCeW0 Cy4+bdP0xCYFOlxHmNQNoEQNoySvPghsKi+BKjrJQwLyMDA4MQT0FqUW5mCar8K0ZxDkYlYd6 LXEBTeDLzSuB2vwI6iwnorDldF0DOKklESEk1ME648o7/5zPTxLezLPkshPJvPS65ed/g8ral BzzjHy967WV/YHuJZotnx7qGHLbte9g+OUgJeWifj/p+Pzx/mdvZibULHXjnFc7fwXyy6IGIg OjNoFnfWMUsHH4YHipWuGaqsSj8blKiZdWnFdGtx5U5pVy+q08//yhes+rQo+SUL9tPat5/ba nEUpyRaKjFXFScCABXzGGk3QIAAA== X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1506937775!117535101!1 X-Originating-IP: [209.85.215.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21780 invoked from network); 2 Oct 2017 09:49:35 -0000 Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by server-8.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 2 Oct 2017 09:49:35 -0000 Received: by mail-lf0-f66.google.com with SMTP id m199so2004398lfe.5 for ; Mon, 02 Oct 2017 02:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f5b8acGwFS4OA/jEvo+LH/UV4oCti8Gcrlz3v1RlDWU=; b=QqHQF2hMobHsQM3uB+Q7b4AHzz9YJIYY7Jk+GxcUPIPYEaMnvpX6DjLEwnRp0pzBEB axinH2MTDonf5AWcFF1e3KJz3X+5T+7kap0Mvg89dr+y3ECHGTwEuEe3LTsEvSEJKFp2 STAC+7vMgLAG5pMDhZpfJrFo4Tj9fSIwdyNDipprCDkoCRGMERSl3qn2vAeWcFBw1OqJ BA/qBI0JSwcWkMlqMpg4lqDdWyXaLrses99UAZNl0GoQ/hlsYiKgNiN7oC6r8Gbc/dar TMpTEBFHZZrzR1e8ejd6LFtEid8Mgt4EmfA+Ba7zSHPJx5VulDbkdtJYFIPfLralsO7I 42rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=f5b8acGwFS4OA/jEvo+LH/UV4oCti8Gcrlz3v1RlDWU=; b=SJQihxINE5ShBhin/QUmFrOTPawK1UFEVEi6Qk7+resmOytT0EXO5Ukuq3+oKchhuv /tB4xmjXbGvOm0VTsRiddryHgEclxlTu+umI+WUue4cHHLcL4/HE8Y5CvsGR65lIrh/N lJoBa3Dc/akuVjHfCpb1e/oFcduO1bUxqii3Mz4jhinDV/a4w4PHxpDa3fYJyOYsDHt3 3OK3iY6h7xizLT5pxG4PACkrZwOnHp3QQct0ciVrCE50vHzJgJGOdEvsD44Cpmk723yF ADFMhGJLyuKjNMfyTrNjoMXp7zjUiBhQc+rdY7z/Lx72VxzPhJmXbyrV41pbWAnkKSmS /I2A== X-Gm-Message-State: AHPjjUjGp6j6WKr+iCB6UObdjwmgVkYIQt6iYWjCA5JKUkyA0MmzWTx6 w5e3HRevvGcoFzm9S3eCJHJyUg== X-Google-Smtp-Source: AOwi7QBSPap+md6MJ7N+cZnH01TWc+5YSfRF8X14dTwaPlPMpCFIDnZlYOqxtj6nVIvXASJtUfKbKw== X-Received: by 10.46.109.10 with SMTP id i10mr6942931ljc.76.1506937774553; Mon, 02 Oct 2017 02:49:34 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id b10sm2217504lje.15.2017.10.02.02.49.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Oct 2017 02:49:34 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Mon, 2 Oct 2017 12:49:22 +0300 Message-Id: <1506937764-30329-4-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506937764-30329-1-git-send-email-al1img@gmail.com> References: <1506937764-30329-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH 3/5] xl: add PV sound condif parser X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Grytsov Add config parser for virtual sound devices Signed-off-by: Oleksandr Grytsov --- tools/xl/xl_parse.c | 250 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/xl/xl_parse.h | 1 + 2 files changed, 251 insertions(+) diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 0678fbc..d4c2efb 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -851,6 +851,254 @@ out: return rc; } +static int parse_vsnd_params(libxl_vsnd_params *params, char *token) +{ + char *oparg; + + if (MATCH_OPTION("sample-rates", token, oparg)) { + int i; + libxl_string_list rates = NULL; + + split_string_into_string_list(oparg, ";", &rates); + + params->num_sample_rates = libxl_string_list_length(&rates); + params->sample_rates = calloc(params->num_sample_rates, + sizeof(*params->sample_rates)); + + for (i = 0; i < params->num_sample_rates; i++) { + params->sample_rates[i] = strtoul(rates[i], NULL, 0); + } + + libxl_string_list_dispose(&rates); + } else if (MATCH_OPTION("sample-formats", token, oparg)) { + int i; + libxl_string_list formats = NULL; + + split_string_into_string_list(oparg, ";", &formats); + + params->num_sample_formats = libxl_string_list_length(&formats); + params->sample_formats = calloc(params->num_sample_formats, + sizeof(*params->sample_formats)); + + for (i = 0; i < params->num_sample_formats; i++) { + libxl_vsnd_pcm_format format; + + if (libxl_vsnd_pcm_format_from_string(formats[i], &format)) { + fprintf(stderr, "Invalid pcm format: %s\n", formats[i]); + exit(EXIT_FAILURE); + } + + params->sample_formats[i] = format; + } + + libxl_string_list_dispose(&formats); + } else if (MATCH_OPTION("channels-min", token, oparg)) { + params->channels_min = strtoul(oparg, NULL, 0); + } else if (MATCH_OPTION("channels-max", token, oparg)) { + params->channels_max = strtoul(oparg, NULL, 0); + } else if (MATCH_OPTION("buffer-size", token, oparg)) { + params->buffer_size = strtoul(oparg, NULL, 0); + } else { + return 1; + } + + return 0; +} + +static int parse_vsnd_pcm_stream(libxl_device_vsnd *vsnd, char *param) +{ + if (vsnd->num_vsnd_pcms == 0) { + fprintf(stderr, "No vsnd pcm device\n"); + return -1; + } + + libxl_vsnd_pcm *pcm = &vsnd->pcms[vsnd->num_vsnd_pcms - 1]; + + if (pcm->num_vsnd_streams == 0) { + fprintf(stderr, "No vsnd stream\n"); + return -1; + } + + libxl_vsnd_stream *stream = &pcm->streams[pcm->num_vsnd_streams - 1]; + + if (parse_vsnd_params(&stream->params, param)) { + char *oparg; + + if (MATCH_OPTION("id", param, oparg)) { + stream->id = strtoul(oparg, NULL, 0); + } else if (MATCH_OPTION("type", param, oparg)) { + + if (libxl_vsnd_stream_type_from_string(oparg, &stream->type)) { + fprintf(stderr, "Invalid stream type: %s\n", oparg); + return -1; + } + } else { + fprintf(stderr, "Invalid parameter: %s\n", param); + return -1; + } + } + + return 0; +} + +static int parse_vsnd_pcm_param(libxl_device_vsnd *vsnd, char *param) +{ + if (vsnd->num_vsnd_pcms == 0) { + fprintf(stderr, "No pcm device\n"); + return -1; + } + + libxl_vsnd_pcm *pcm = &vsnd->pcms[vsnd->num_vsnd_pcms - 1]; + + if (parse_vsnd_params(&pcm->params, param)) { + char *oparg; + + if (MATCH_OPTION("name", param, oparg)) { + pcm->name = strdup(oparg); + } else { + fprintf(stderr, "Invalid parameter: %s\n", param); + return -1; + } + } + + return 0; +} + +static int parse_vsnd_card_param(libxl_device_vsnd *vsnd, char *param) +{ + if (parse_vsnd_params(&vsnd->params, param)) { + char *oparg; + + if (MATCH_OPTION("backend", param, oparg)) { + vsnd->backend_domname = strdup(oparg); + } else if (MATCH_OPTION("short-name", param, oparg)) { + vsnd->short_name = strdup(oparg); + } else if (MATCH_OPTION("long-name", param, oparg)) { + vsnd->long_name = strdup(oparg); + } else { + fprintf(stderr, "Invalid parameter: %s\n", param); + return -1; + } + } + + return 0; +} + +static int parse_vsnd_create_item(libxl_device_vsnd *vsnd, const char *key) +{ + if (strcasecmp(key, "card") == 0) { + + } else if (strcasecmp(key, "pcm") == 0) { + ARRAY_EXTEND_INIT_NODEVID(vsnd->pcms, vsnd->num_vsnd_pcms, + libxl_vsnd_pcm_init); + } else if (strcasecmp(key, "stream") == 0) { + if (vsnd->num_vsnd_pcms == 0) { + ARRAY_EXTEND_INIT_NODEVID(vsnd->pcms, vsnd->num_vsnd_pcms, + libxl_vsnd_pcm_init); + } + + libxl_vsnd_pcm *pcm = &vsnd->pcms[vsnd->num_vsnd_pcms - 1]; + + ARRAY_EXTEND_INIT_NODEVID(pcm->streams, pcm->num_vsnd_streams, + libxl_vsnd_stream_init); + } else { + fprintf(stderr, "Invalid key: %s\n", key); + return -1; + } + + return 0; +} + +int parse_vsnd_item(libxl_device_vsnd *vsnd, const char *spec) +{ + char *buf = strdup(spec); + char *token = strtok(buf, ","); + char *key = NULL; + int ret; + + while(token) { + while (*token == ' ') token++; + + if (!key) { + key = token; + ret = parse_vsnd_create_item(vsnd, key); + if (ret) goto out; + } else { + if (strcasecmp(key, "card") == 0) { + ret = parse_vsnd_card_param(vsnd, token); + if (ret) goto out; + } else if (strcasecmp(key, "pcm") == 0) { + ret = parse_vsnd_pcm_param(vsnd, token); + if (ret) goto out; + } else if (strcasecmp(key, "stream") == 0) { + ret = parse_vsnd_pcm_stream(vsnd, token); + if (ret) goto out; + } + } + token = strtok (NULL, ","); + } + + ret = 0; + +out: + free(buf); + return ret; +} + +static void parse_vsnd_card_config(const XLU_Config *config, + XLU_ConfigValue *card_value, + libxl_domain_config *d_config) +{ + int ret; + + XLU_ConfigList *card_list; + + // get card + ret = xlu_cfg_value_get_list(config, card_value, &card_list, 0); + + if (ret) { + fprintf(stderr, "Failed to get vsnd card list: %s\n", strerror(ret)); + goto out; + } + + libxl_device_vsnd *vsnd; + + vsnd = ARRAY_EXTEND_INIT(d_config->vsnds, + d_config->num_vsnds, + libxl_device_vsnd_init); + + const char *card_item; + int item = 0; + + while ((card_item = xlu_cfg_get_listitem(card_list, item++)) != NULL) { + ret = parse_vsnd_item(vsnd, card_item); + if (ret) goto out; + } + + ret = 0; + +out: + if (ret) exit(EXIT_FAILURE); +} + +static void parse_vsnd_config(const XLU_Config *config, + libxl_domain_config *d_config) +{ + XLU_ConfigList *vsnds; + + if (!xlu_cfg_get_list(config, "vsnd", &vsnds, 0, 0)) { + XLU_ConfigValue *card_value; + + d_config->num_vsnds = 0; + d_config->vsnds = NULL; + + while ((card_value = xlu_cfg_get_listitem2(vsnds, d_config->num_vsnds)) + != NULL) { + parse_vsnd_card_config(config, card_value, d_config); + } + } +} + void parse_config_data(const char *config_source, const char *config_data, int config_len, @@ -1564,6 +1812,8 @@ void parse_config_data(const char *config_source, } } + parse_vsnd_config(config, d_config); + if (!xlu_cfg_get_list (config, "channel", &channels, 0, 0)) { d_config->num_channels = 0; d_config->channels = NULL; diff --git a/tools/xl/xl_parse.h b/tools/xl/xl_parse.h index cc459fb..9a948ea 100644 --- a/tools/xl/xl_parse.h +++ b/tools/xl/xl_parse.h @@ -34,6 +34,7 @@ int parse_usbdev_config(libxl_device_usbdev *usbdev, char *token); int parse_cpurange(const char *cpu, libxl_bitmap *cpumap); int parse_nic_config(libxl_device_nic *nic, XLU_Config **config, char *token); int parse_vdispl_config(libxl_device_vdispl *vdispl, char *token); +int parse_vsnd_item(libxl_device_vsnd *vsnd, const char *spec); int match_option_size(const char *prefix, size_t len, char *arg, char **argopt);