From patchwork Wed Nov 1 15:04:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 10036477 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 9A346602B5 for ; Wed, 1 Nov 2017 15:07:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3293128C28 for ; Wed, 1 Nov 2017 15:07:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2753128C43; Wed, 1 Nov 2017 15:07:43 +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 3D5A8209CD for ; Wed, 1 Nov 2017 15:07:42 +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 1e9uZf-00054q-AI; Wed, 01 Nov 2017 15:04:59 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9uZd-00054c-Ju for xen-devel@lists.xenproject.org; Wed, 01 Nov 2017 15:04:57 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 7B/67-14867-892E9F95; Wed, 01 Nov 2017 15:04:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPIsWRWlGSWpSXmKPExsVyMfS6k+6MRz8 jDRYKWHzfMpnJgdHj8IcrLAGMUayZeUn5FQmsGZe6TjMVXG9krNhybBFrA2NjdBcjF4eQwAxG ielL17OBOCwCL1kkdnU9ZAJxJAT6WSVe3XzD2sXICeRkSRzZsZCli5EDyE6TeNdgCBEulTjes I4RxBYSkJc42HKZHWLqFCaJ73u2gfWyCWhJ3L+9gg3EFhFQkri3ajITiM0skCKxd10bWLOwgJ HEtVvdYDaLgKpE5ySIOK+AvUTD0l4miGVyEjfPdTKD2JwCDhK3X8wFu0cIqGb3lcoJjIILGBl WMWoUpxaVpRbpGhvqJRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhXrJefnbmIEBhwDEOxgbFoU eIhRkoNJSZRX8/7PSCG+pPyUyozE4oz4otKc1OJDjBocHAI/n/5tYZRiycvPS1WS4GUGBraQY FFqempFWmYOMCZgSiU4eJREeDc+BErzFhck5hZnpkOkTjG6cly4c+kPE8exTZeB5IE9t4Bkx8 27QPLZzNcNzEJgs6XEeRlAZguANGeU5sGNhsXzJUZZKWFeRqDDhXgKUotyM0tQ5V8xinMwKgn zPnsANIUnM68E7oJXQMcxAR3nJfED5LiSRISUVAOjEXvg4glRt3NOes54wO52JLJqrYe0icaP w/bWD/TExIK6u1Unrrp/0V2Nf1rfpg/LKha+nvmOQZV12a/yKwZhWxwuibUJSNdq39894bB1W uoTsdavzCwuXvl/F3atP3NKYsq/sr+Tvmjvqw5zL/eTyY9e/MjkZiBHfY6dFfv37uV8DG9Xnb mnxFKckWioxVxUnAgAly8M0eICAAA= X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1509548695!108966731!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 3084 invoked from network); 1 Nov 2017 15:04:55 -0000 Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by server-5.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 1 Nov 2017 15:04:55 -0000 Received: by mail-lf0-f66.google.com with SMTP id l23so2856738lfk.10 for ; Wed, 01 Nov 2017 08:04:55 -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=3rWaExpK+qBaqEnb7CWi/tIP813jyglWd4MPRxxXKEs=; b=A/iw414X7rG8Sl8JQ7OrkmRxtngG9W0+66ToGBhC8gSeinymJ60keDsIZozc6iss/n Rg7Rm03hgSOyt8TQVVH6jUxFLwJ2voPpGqtSdqP75d/2HgTz/Ml8jl3/sgPj+iJBxvkD 2B3Sb7cax0d17SFrL+WR+lcAvmEVdklB8w5+ZuUTvWaPxm2F4ApKP+lbjcDep3jP1ssS 6h3Z/V6bBwBAWJllccOUDytSoY4EyvQ6E7L9LWVNWtIBAChzxxDqtlbofGphHD3YdEJ4 IstxOVLj6iiZeE1gnfjbfoasCa9rx5Vs2SUbsefZKD74XqvNAstN2iSQSZuN38WAeKBr 253Q== 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=3rWaExpK+qBaqEnb7CWi/tIP813jyglWd4MPRxxXKEs=; b=sG2Dhf/+qrZuhh8d2DJYiJqj4K6zjDoU8R028f5AK/JMREfKjoVHvFoFNrAWv17RXe EuwqteFIlo5Ta1wFLIwwdiPlyBJ0qf1/7AcP/IASFtc5HUBTEFxSkFPJL6ztWdrVDaX9 TDAR4PLk4WxTr1sNRWg98q2KYKUBJWRbJyLg1r/Xp93d5KzEJ4uociWzv5lJ6o3Uc/q8 vi6to1/cuiPe2lYkEkzyvuoTDUFDXw2mFzUr1ra2JEpdp2oc9FAb8BoJWKtFmk0hJlHF QoqQLtzNy8smxAZGwCO5ZJVJL7Jy6Qr3YfudaRs9GRqyxgIvPtwR71HVvGGJQM4QLnUs mTwg== X-Gm-Message-State: AMCzsaU/FBReXoH2+bUoU7TmnB9vu+frHixbHh7bIBThGUEHjGux2gUy MOYfmM/FgA+9bkdCf0KThKhIsQ== X-Google-Smtp-Source: ABhQp+T7j6hWEwAuokhz3LbY5dHtJuulqTXhxetaGgiHuWp9Jtb/ThnMrhOxQaMgKpWKWD5Z1kEg/Q== X-Received: by 10.46.56.14 with SMTP id f14mr75838lja.46.1509548694831; Wed, 01 Nov 2017 08:04:54 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Nov 2017 08:04:54 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Wed, 1 Nov 2017 17:04:43 +0200 Message-Id: <1509548687-6071-2-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 1/5] libxl: add PV sound device 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 PV sound device described in sndif.h Signed-off-by: Oleksandr Grytsov --- tools/libxl/Makefile | 2 +- tools/libxl/libxl.h | 14 ++ tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_types.idl | 64 +++++++ tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_vsnd.c | 330 +++++++++++++++++++++++++++++++++++ 7 files changed, 412 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_vsnd.c diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index 49b2c63..2d52435 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -138,7 +138,7 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom_suspend.o libxl_dom_save.o libxl_usb.o \ libxl_vtpm.o libxl_nic.o libxl_disk.o libxl_console.o \ libxl_cpupool.o libxl_mem.o libxl_sched.o libxl_tmem.o \ - libxl_9pfs.o libxl_domain.o libxl_vdispl.o \ + libxl_9pfs.o libxl_domain.o libxl_vdispl.o libxl_vsnd.o \ $(LIBXL_OBJS-y) LIBXL_OBJS += libxl_genid.o LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 7d853ca..7200d49 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1913,6 +1913,20 @@ int libxl_device_vdispl_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_vdisplinfo *vdisplinfo) LIBXL_EXTERNAL_CALLERS_ONLY; +/* Virtual sounds */ +int libxl_device_vsnd_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_vsnd *vsnd, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vsnd_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_vsnd *vsnd, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vsnd_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_vsnd *vsnd, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + /* Keyboard */ int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb, const libxl_asyncop_how *ao_how) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 0ef54d2..f813114 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1449,6 +1449,7 @@ const struct libxl_device_type *device_type_tbl[] = { &libxl__pcidev_devtype, &libxl__dtdev_devtype, &libxl__vdispl_devtype, + &libxl__vsnd_devtype, NULL }; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 8b71517..6b403dc 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3575,6 +3575,7 @@ extern const struct libxl_device_type libxl__usbdev_devtype; extern const struct libxl_device_type libxl__pcidev_devtype; extern const struct libxl_device_type libxl__vdispl_devtype; extern const struct libxl_device_type libxl__p9_devtype; +extern const struct libxl_device_type libxl__vsnd_devtype; extern const struct libxl_device_type *device_type_tbl[]; diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 756e120..aa30196 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -793,6 +793,69 @@ libxl_device_vdispl = Struct("device_vdispl", [ ("connectors", Array(libxl_connector_param, "num_connectors")) ]) +libxl_vsnd_pcm_format = Enumeration("vsnd_pcm_format", [ + (1, "S8"), + (2, "U8"), + (3, "S16_LE"), + (4, "S16_BE"), + (5, "U16_LE"), + (6, "U16_BE"), + (7, "S24_LE"), + (8, "S24_BE"), + (9, "U24_LE"), + (10, "U24_BE"), + (11, "S32_LE"), + (12, "S32_BE"), + (13, "U32_LE"), + (14, "U32_BE"), + (15, "F32_LE"), + (16, "F32_BE"), + (17, "F64_LE"), + (18, "F64_BE"), + (19, "IEC958_SUBFRAME_LE"), + (20, "IEC958_SUBFRAME_BE"), + (21, "MU_LAW"), + (22, "A_LAW"), + (23, "IMA_ADPCM"), + (24, "MPEG"), + (25, "GSM") + ]) + +libxl_vsnd_params = Struct("vsnd_params", [ + ("sample_rates", Array(uint32, "num_sample_rates")), + ("sample_formats", Array(libxl_vsnd_pcm_format, "num_sample_formats")), + ("channels_min", uint32), + ("channels_max", uint32), + ("buffer_size", uint32) + ]) + +libxl_vsnd_stream_type = Enumeration("vsnd_stream_type", [ + (1, "P"), + (2, "C") + ]) + +libxl_vsnd_stream = Struct("vsnd_stream", [ + ("id", string), + ("type", libxl_vsnd_stream_type), + ("params", libxl_vsnd_params) + ]) + +libxl_vsnd_pcm = Struct("vsnd_pcm", [ + ("name", string), + ("params", libxl_vsnd_params), + ("streams", Array(libxl_vsnd_stream, "num_vsnd_streams")) + ]) + +libxl_device_vsnd = Struct("device_vsnd", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("short_name", string), + ("long_name", string), + ("params", libxl_vsnd_params), + ("pcms", Array(libxl_vsnd_pcm, "num_vsnd_pcms")) + ]) + libxl_domain_config = Struct("domain_config", [ ("c_info", libxl_domain_create_info), ("b_info", libxl_domain_build_info), @@ -807,6 +870,7 @@ libxl_domain_config = Struct("domain_config", [ ("vtpms", Array(libxl_device_vtpm, "num_vtpms")), ("p9s", Array(libxl_device_p9, "num_p9s")), ("vdispls", Array(libxl_device_vdispl, "num_vdispls")), + ("vsnds", Array(libxl_device_vsnd, "num_vsnds")), # a channel manifests as a console with a name, # see docs/misc/channels.txt ("channels", Array(libxl_device_channel, "num_channels")), diff --git a/tools/libxl/libxl_types_internal.idl b/tools/libxl/libxl_types_internal.idl index 673a6d5..7898dae 100644 --- a/tools/libxl/libxl_types_internal.idl +++ b/tools/libxl/libxl_types_internal.idl @@ -27,6 +27,7 @@ libxl__device_kind = Enumeration("device_kind", [ (10, "QUSB"), (11, "9PFS"), (12, "VDISPL"), + (13, "VSND") ]) libxl__console_backend = Enumeration("console_backend", [ diff --git a/tools/libxl/libxl_vsnd.c b/tools/libxl/libxl_vsnd.c new file mode 100644 index 0000000..99e4be3 --- /dev/null +++ b/tools/libxl/libxl_vsnd.c @@ -0,0 +1,330 @@ +/* + * Copyright (C) 2016 EPAM Systems Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_internal.h" +#include + +static int libxl__device_vsnd_setdefault(libxl__gc *gc, uint32_t domid, + libxl_device_vsnd *vsnd, + bool hotplug) +{ + return libxl__resolve_domid(gc, vsnd->backend_domname, + &vsnd->backend_domid); +} + +static int libxl__device_from_vsnd(libxl__gc *gc, uint32_t domid, + libxl_device_vsnd *vsnd, + libxl__device *device) +{ + device->backend_devid = vsnd->devid; + device->backend_domid = vsnd->backend_domid; + device->backend_kind = LIBXL__DEVICE_KIND_VSND; + device->devid = vsnd->devid; + device->domid = domid; + device->kind = LIBXL__DEVICE_KIND_VSND; + + return 0; +} + +static int libxl__vsnd_from_xenstore(libxl__gc *gc, const char *libxl_path, + libxl_devid devid, + libxl_device_vsnd *vsnd) +{ + const char *be_path; + int rc; + + vsnd->devid = devid; + rc = libxl__xs_read_mandatory(gc, XBT_NULL, + GCSPRINTF("%s/backend", libxl_path), + &be_path); + if (rc) goto out; + + rc = libxl__backendpath_parse_domid(gc, be_path, &vsnd->backend_domid); + if (rc) goto out; + + rc = 0; + +out: + + return rc; +} + +static void libxl__update_config_vsnd(libxl__gc *gc, + libxl_device_vsnd *dst, + libxl_device_vsnd *src) +{ + dst->devid = src->devid; +} + +static int libxl_device_vsnd_compare(libxl_device_vsnd *d1, + libxl_device_vsnd *d2) +{ + return COMPARE_DEVID(d1, d2); +} + +static void libxl__device_vsnd_add(libxl__egc *egc, uint32_t domid, + libxl_device_vsnd *vsnd, + libxl__ao_device *aodev) +{ + libxl__device_add_async(egc, domid, &libxl__vsnd_devtype, vsnd, aodev); +} + +static unsigned int libxl__rates_to_str_vsnd(char *str, uint32_t *sample_rates, + int num_sample_rates) +{ + unsigned int len; + int i; + + len = 0; + + if (num_sample_rates == 0) goto out; + + for (i = 0; i < num_sample_rates - 1; i++) { + if (str) { + len += sprintf(&str[len], "%u,", sample_rates[i]); + } else { + len += snprintf(NULL, 0, "%u,", sample_rates[i]); + } + } + + if (str) { + len += sprintf(&str[len], "%u", sample_rates[i]); + } else { + len += snprintf(NULL, 0, "%u", sample_rates[i]); + } + +out: + + return len; +} + +static unsigned int libxl__formats_to_str_vsnd(char *str, + libxl_vsnd_pcm_format *sample_formats, + int num_sample_formats) +{ + unsigned int len; + int i; + + len = 0; + + if (num_sample_formats == 0) goto out; + + for (i = 0; i < num_sample_formats - 1; i++) { + if (str) { + len += sprintf(&str[len], "%s,", + libxl_vsnd_pcm_format_to_string(sample_formats[i])); + } else { + len += snprintf(NULL, 0, "%s,", + libxl_vsnd_pcm_format_to_string(sample_formats[i])); + } + } + + if (str) { + len += sprintf(&str[len], "%s", + libxl_vsnd_pcm_format_to_string(sample_formats[i])); + } else { + len += snprintf(NULL, 0, "%s", + libxl_vsnd_pcm_format_to_string(sample_formats[i])); + } + +out: + + return len; +} + +static int libxl__set_params_vsnd(libxl__gc *gc, char *path, + libxl_vsnd_params *params, flexarray_t *front) +{ + char *buffer; + int len; + int rc; + + if (params->sample_rates) { + /* calculate required string size */ + len = libxl__rates_to_str_vsnd(NULL, params->sample_rates, + params->num_sample_rates); + + if (len) { + buffer = libxl__malloc(gc, len + 1); + + libxl__rates_to_str_vsnd(buffer, params->sample_rates, + params->num_sample_rates); + rc = flexarray_append_pair(front, + GCSPRINTF("%s"XENSND_FIELD_SAMPLE_RATES, + path), buffer); + if (rc) goto out; + } + } + + if (params->sample_formats) { + /* calculate required string size */ + len = libxl__formats_to_str_vsnd(NULL, params->sample_formats, + params->num_sample_formats); + + if (len) { + buffer = libxl__malloc(gc, len + 1); + + libxl__formats_to_str_vsnd(buffer, params->sample_formats, + params->num_sample_formats); + rc = flexarray_append_pair(front, + GCSPRINTF("%s"XENSND_FIELD_SAMPLE_FORMATS, + path), buffer); + if (rc) goto out; + } + } + + if (params->channels_min) { + rc = flexarray_append_pair(front, + GCSPRINTF("%s"XENSND_FIELD_CHANNELS_MIN, path), + GCSPRINTF("%u", params->channels_min)); + if (rc) goto out; + } + + if (params->channels_max) { + rc = flexarray_append_pair(front, + GCSPRINTF("%s"XENSND_FIELD_CHANNELS_MAX, path), + GCSPRINTF("%u", params->channels_max)); + if (rc) goto out; + } + + if (params->buffer_size) { + rc = flexarray_append_pair(front, + GCSPRINTF("%s"XENSND_FIELD_BUFFER_SIZE, path), + GCSPRINTF("%u", params->buffer_size)); + if (rc) goto out; + } + + rc = 0; + +out: + + return rc; +} + +static int libxl__set_streams_vsnd(libxl__gc *gc, char *path, + libxl_vsnd_stream *streams, + int num_streams, flexarray_t *front) +{ + int i; + int rc; + + for (i = 0; i < num_streams; i++) { + rc = flexarray_append_pair(front, + GCSPRINTF("%s%d/"XENSND_FIELD_STREAM_UNIQUE_ID, path, i), + streams[i].id); + if (rc) goto out; + + const char *type = libxl_vsnd_stream_type_to_string(streams[i].type); + + if (type) { + rc = flexarray_append_pair(front, + GCSPRINTF("%s%d/"XENSND_FIELD_TYPE, path, i), + (char *)type); + if (rc) goto out; + } + + rc = libxl__set_params_vsnd(gc, GCSPRINTF("%s%d/", path, i), + &streams[i].params, front); + if (rc) goto out; + } + + rc = 0; + +out: + + return rc; +} + +static int libxl__set_pcms_vsnd(libxl__gc *gc, libxl_vsnd_pcm *pcms, + int num_pcms, flexarray_t *front) +{ + int i; + int rc; + + for (i = 0; i < num_pcms; i++) { + if (pcms[i].name) { + rc = flexarray_append_pair(front, + GCSPRINTF("%d/"XENSND_FIELD_DEVICE_NAME, i), + pcms[i].name); + if (rc) goto out; + } + + char *path = GCSPRINTF("%d/", i); + + rc = libxl__set_params_vsnd(gc, path, &pcms[i].params, front); + if (rc) goto out; + + rc = libxl__set_streams_vsnd(gc, path, pcms[i].streams, + pcms[i].num_vsnd_streams, front); + if (rc) goto out; + } + + rc = 0; + +out: + + return rc; +} + +static int libxl__set_xenstore_vsnd(libxl__gc *gc, uint32_t domid, + libxl_device_vsnd *vsnd, + flexarray_t *back, flexarray_t *front, + flexarray_t *ro_front) +{ + int rc; + + if (vsnd->long_name) { + rc = flexarray_append_pair(front, XENSND_FIELD_VCARD_LONG_NAME, + vsnd->long_name); + if (rc) goto out; + } + + if (vsnd->short_name) { + rc = flexarray_append_pair(front, XENSND_FIELD_VCARD_SHORT_NAME, + vsnd->short_name); + if (rc) goto out; + } + + rc = libxl__set_params_vsnd(gc, "", &vsnd->params, front); + if (rc) goto out; + + rc = libxl__set_pcms_vsnd(gc, vsnd->pcms, vsnd->num_vsnd_pcms, front); + if (rc) goto out; + + rc = 0; + +out: + + return rc; +} + +LIBXL_DEFINE_DEVICE_ADD(vsnd) +static LIBXL_DEFINE_DEVICES_ADD(vsnd) +LIBXL_DEFINE_DEVICE_REMOVE(vsnd) +static LIBXL_DEFINE_UPDATE_DEVID(vsnd, "vsnd") + +DEFINE_DEVICE_TYPE_STRUCT(vsnd, + .update_config = (device_update_config_fn_t) libxl__update_config_vsnd, + .from_xenstore = (device_from_xenstore_fn_t) libxl__vsnd_from_xenstore, + .set_xenstore_config = (device_set_xenstore_config_fn_t) + libxl__set_xenstore_vsnd +); + +/* + * Local variables: + * mode: C + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */