From patchwork Wed Nov 1 15:04:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 10036463 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 7462B604D7 for ; Wed, 1 Nov 2017 15:07:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AEFF28C44 for ; Wed, 1 Nov 2017 15:07:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3D5128C50; Wed, 1 Nov 2017 15:07:32 +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 6170D28C44 for ; Wed, 1 Nov 2017 15:07:32 +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 1e9uZh-00055r-M0; Wed, 01 Nov 2017 15:05:01 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9uZg-00055I-3F for xen-devel@lists.xenproject.org; Wed, 01 Nov 2017 15:05:00 +0000 Received: from [85.158.143.35] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-4.bemta-6.messagelabs.com id 0E/8F-30895-B92E9F95; Wed, 01 Nov 2017 15:04:59 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPIsWRWlGSWpSXmKPExsVyMfS6i+6sRz8 jDU61yFt83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBnfG/wKOlwrdq38xNrAuNGwi5GLQ0hgOqNE z41GdhCHReAli8SZy32MII6EQD+rxIHWQ8xdjJxATpbEiWf/WSDsNImtLddYIewKiZ1NL9hAb CEBeYmDLZfZIcZOYZL4cWwKE0iCTUBL4v7tFWBFIgJKEvdWTQaLMwukSOxd18YIYgsLmEnMff kDrIZFQFViwYtF7CA2r4C9xO7VH6COkJO4ea4TzOYUcJC4/WIu0EEcQMuAaq5UTmAUXMDIsIp Rozi1qCy1SNfITC+pKDM9oyQ3MTNH19DATC83tbg4MT01JzGpWC85P3cTIzDgGIBgB+OZBYGH GCU5mJREeTXv/4wU4kvKT6nMSCzOiC8qzUktPsSowcEh8PPp3xZGKZa8/LxUJQnejodAdYJFq empFWmZOcCYgCmV4OBREuE9+gAozVtckJhbnJkOkTrF6Mpx4c6lP0wcxzZdBpIH9twCkh037w LJZzNfNzALgc2WEudlBZktANKcUZoHNxoWz5cYZaWEeRmBDhfiKUgtys0sQZV/xSjOwagkzPs M5ASezLwSuAteAR3HBHScl8QPkONKEhFSUg2MPnUrVv2OsX2pFMd36YPvgja55U5PriUVKHfe Tza9m8o+/cVRhrz973KfGM2Q+LScL8ft+Tz55/1JUWoSUw6VsaapnF+cxsLs4yNxIVuiXT9cc rEYt2qwwLfVEzcfFNQ5UbBti+ubinrrg0ENf17NvbKo1vHn4acc9g56dyz81l6u2cw3J3alEk txRqKhFnNRcSIAVYIC1uICAAA= X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-11.tower-21.messagelabs.com!1509548698!76839223!1 X-Originating-IP: [209.85.215.68] 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 31129 invoked from network); 1 Nov 2017 15:04:58 -0000 Received: from mail-lf0-f68.google.com (HELO mail-lf0-f68.google.com) (209.85.215.68) by server-11.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Nov 2017 15:04:58 -0000 Received: by mail-lf0-f68.google.com with SMTP id n69so2891371lfn.2 for ; Wed, 01 Nov 2017 08:04:58 -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=vHY85HkbmByVHp34FQKZ18gk+hjEJeuUVnbDs/le2IE=; b=ucYcRbbP6RKsqcBTo/oTZrmLpZECHIzcDmAKVIovi+Z4hnmAhDgD9oiMxTUtcdu5wk nNRt71El/SeiTMgAmCQRqIIXUmo02Of+X68Qzq82tL/qsFvZbYn495kI9dcwFlx7MgKc z9cZQYf6iURmot4guk37SN24wfzqWVX67dNG3duDB2Vk0V6CMe85/aFJ29lSH7hAo0bX 4RBug2iJP98/EPy+pL6LvHRDUw83VC690qHsURd8EAxVqf9H7nOuDT1UFZT/Ipa58dE6 U7uJGpieFgXIj4ZE6WgPdqsjmA7GLcgreSKvzBF97NM1ZIkdJzSU7nuvbWrbyKrpHQ3g UUcw== 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=vHY85HkbmByVHp34FQKZ18gk+hjEJeuUVnbDs/le2IE=; b=PpFj/WCgz9j+eMzWih4XRm4NU/ftDnugw0B4eXrIdpgXpgW2K4Asvlmq+eFhVaYNAA KCCssqIRFmQGoPg6lCAZjrIO+JaivQfv2xb8y+9VaqISIolp6p7dI+zsrjCiRBuY5RI+ VP1GuyoPTuVrty7KPUB4iRJH3/G/eeap+yLXh2slAkf1ecfHGBudqQ0CaUquWMRrnsjQ 9/EugHdIpMekVWEcGtdikiCkCa8sOTOq+rQu1J84IRkxWv0WRGDVGZdPEC7kcPucrQH/ FBRPo5W/kQbS2/8e9L5OlYd2isJw/oJR3gs0aUV6SESa8QAkMivOlUjM90P1PJlOHDQs 2Q9A== X-Gm-Message-State: AJaThX51cFqo+YnrXhvwMaY7sYxKwrVnxGl3cJMUI21NdH9TMiDWFO/4 ekqx9u40qOqTqm1wvcB6laDwwQ== X-Google-Smtp-Source: ABhQp+RxFPb0lNT/JRTSxCFhiL02wWPCOZFFV6xDLsTe+fm6II3SZ7/qEkcmyJQ6rzjbepGw6fW8cA== X-Received: by 10.25.26.143 with SMTP id a137mr47642lfa.105.1509548697421; Wed, 01 Nov 2017 08:04:57 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-59.209.223.85.sovam.net.ua. [85.223.209.59]) by smtp.gmail.com with ESMTPSA id 77sm173505ljj.12.2017.11.01.08.04.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Nov 2017 08:04:56 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Wed, 1 Nov 2017 17:04:45 +0200 Message-Id: <1509548687-6071-4-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509548687-6071-1-git-send-email-al1img@gmail.com> References: <1509548687-6071-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH v1 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 | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/xl/xl_parse.h | 1 + 2 files changed, 247 insertions(+) diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 0678fbc..e25d096 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -851,6 +851,250 @@ out: return rc; } +static int parse_vsnd_params(libxl_vsnd_params *params, char *token) +{ + char *oparg; + int i; + + if (MATCH_OPTION("sample-rates", token, oparg)) { + 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)) { + 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 = strdup(oparg); + } 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; + libxl_device_vsnd *vsnd; + const char *card_item; + int item = 0; + + 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; + } + + vsnd = ARRAY_EXTEND_INIT(d_config->vsnds, + d_config->num_vsnds, + libxl_device_vsnd_init); + + 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 +1808,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);