From nobody Wed Oct 30 19:55:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683807303; cv=none; d=zohomail.com; s=zohoarc; b=PsZgSGkrWf87g7yoc2OLDuUqEizCrP8WjY7JwT2sLSyv0noTz8mQJoXzLIrKoBdvKYMCvXmnsrArIqaAiDx6ftvFqFfHEngzdnUPTFcK43mtBz7WqPZtjPP84HPq5uqkJ2nUyMhqV6M4ro9duyVlP6YEUevIJunfl/rB3aRUFV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683807303; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6BqM2FO6IZ7kGmXrxJIVkhhh/e+SBRc+6C4LuDeQeLM=; b=GJP1rZ1M4hFgJVt+C1Cv1JQpZJ4f2okVm4TpUlfUtZdMt6AH5DPjF9W9/VeFqOEQdBN+kP9BF9M6XGJ6VlCqsFiNdZ0x1HfDucwbOWVxAAfbsz34elIhIGqYvCAKhRQ5bfTeFiImhCwVX5woVFeGDNf5HGdHlObvZYozjtB5XkY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1683807303480900.40543107391; Thu, 11 May 2023 05:15:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-78-XNPCS445OheJylTAKoT9sQ-1; Thu, 11 May 2023 08:15:00 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4CA2B101A554; Thu, 11 May 2023 12:14:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D7E1492C13; Thu, 11 May 2023 12:14:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E47A419451DD; Thu, 11 May 2023 12:14:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7223A19451C7 for ; Thu, 11 May 2023 12:14:54 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 55E6A63F8A; Thu, 11 May 2023 12:14:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id D52F047CD0 for ; Thu, 11 May 2023 12:14:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683807302; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6BqM2FO6IZ7kGmXrxJIVkhhh/e+SBRc+6C4LuDeQeLM=; b=OD8vt0yr8WhYzA7cKSBXfTgg2+NHXAQU9BRe1lENYbMNgdsQpxPHB1z6m99kaVjQnwXx6t cu8rkOsIciFX0IifIoAKIbcWapQIH1Hw8vzXAWgTjStZEcSxdCH73uAyQM79hd8FbXWtww JNh/BPwSZtHOfveL/AclKDetgpij5HM= X-MC-Unique: XNPCS445OheJylTAKoT9sQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] conf: Introduce pipewire audio backend Date: Thu, 11 May 2023 14:14:50 +0200 Message-Id: <329e92fbb0e9015ff72878b9a3d338f75853ef5e.1683807150.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683807305844100003 Content-Type: text/plain; charset="utf-8"; x-default="true" QEMU gained support for PipeWire audio backend (see QEMU commit of v8.0.0-403-gc2d3d1c294). Its configuration knobs are basically the same as pulseaudio's, except for PA's server name. Therefore, a lot of code is copied over from pulseadio and fixed by s/Pulse/Pipewire/ or s/pulseaudio/pipewire/. Signed-off-by: Michal Privoznik --- docs/formatdomain.rst | 35 +++++++++- src/conf/domain_conf.c | 70 +++++++++++++++++++ src/conf/domain_conf.h | 12 ++++ src/conf/schemas/domaincommon.rng | 37 ++++++++++ src/qemu/qemu_command.c | 2 + src/qemu/qemu_validate.c | 1 + .../qemuxml2argvdata/audio-pipewire-best.xml | 43 ++++++++++++ .../qemuxml2argvdata/audio-pipewire-full.xml | 43 ++++++++++++ .../audio-pipewire-minimal.xml | 36 ++++++++++ .../audio-pipewire-best.xml | 43 ++++++++++++ .../audio-pipewire-full.xml | 43 ++++++++++++ .../audio-pipewire-minimal.xml | 36 ++++++++++ tests/qemuxml2xmltest.c | 3 + 13 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxml2argvdata/audio-pipewire-best.xml create mode 100644 tests/qemuxml2argvdata/audio-pipewire-full.xml create mode 100644 tests/qemuxml2argvdata/audio-pipewire-minimal.xml create mode 100644 tests/qemuxml2xmloutdata/audio-pipewire-best.xml create mode 100644 tests/qemuxml2xmloutdata/audio-pipewire-full.xml create mode 100644 tests/qemuxml2xmloutdata/audio-pipewire-minimal.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 99383e725c..1ec68c4776 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -7270,7 +7270,8 @@ to the guest sound device. ``type`` The required ``type`` attribute specifies audio backend type. Currently, the supported values are ``none``, ``alsa``, ``coreaudio``, - ``dbus``, ``jack``, ``oss``, ``pulseaudio``, ``sdl``, ``spice``, ``file= ``. + ``dbus``, ``jack``, ``oss``, ``pipewire``, ``pulseaudio``, ``sdl``, + ``spice``, ``file``. =20 ``id`` Integer id of the audio device. Must be greater than 0. @@ -7354,7 +7355,7 @@ following environment variables: * ``QEMU_AUDIO_DRV`` =20 Valid values are ``pa``, ``none``, ``alsa``, ``coreaudio``, ``jack``, ``= oss``, - ``sdl``, ``spice`` or ``wav``. + ``pipewire``, ``sdl``, ``spice`` or ``wav``. =20 None audio backend ^^^^^^^^^^^^^^^^^^ @@ -7503,6 +7504,36 @@ and ```` elements =20 :since:`Since 6.7.0, bhyve; Since 7.2.0, qemu` =20 +PipeWire audio backend +^^^^^^^^^^^^^^^^^^^^^^ + +The ``pipewire`` audio backend delegates to a PipeWire daemon audio input = and +output. + +The following additional attributes are permitted on the ```` and +```` elements: + +* ``name`` + + The sink/source name to use + +* ``streamName`` + + The name to identify the stream associated with the VM + +* ``latency`` + + Desired latency for the server to target in microseconds + +:: + + + +:since:`Since 9.4.0, qemu` + PulseAudio audio backend ^^^^^^^^^^^^^^^^^^^^^^^^ =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6a864a8db9..62484631cc 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -788,6 +788,7 @@ VIR_ENUM_IMPL(virDomainAudioType, "spice", "file", "dbus", + "pipewire", ); =20 VIR_ENUM_IMPL(virDomainAudioSDLDriver, @@ -3226,6 +3227,13 @@ virDomainAudioIOPulseAudioFree(virDomainAudioIOPulse= Audio *def) g_free(def->streamName); } =20 +static void +virDomainAudioIOPipewireAudioFree(virDomainAudioIOPipewireAudio *def) +{ + g_free(def->name); + g_free(def->streamName); +} + void virDomainAudioDefFree(virDomainAudioDef *def) { @@ -3270,6 +3278,11 @@ virDomainAudioDefFree(virDomainAudioDef *def) g_free(def->backend.file.path); break; =20 + case VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE: + virDomainAudioIOPipewireAudioFree(&def->backend.pipewire.input); + virDomainAudioIOPipewireAudioFree(&def->backend.pipewire.output); + break; + case VIR_DOMAIN_AUDIO_TYPE_DBUS: case VIR_DOMAIN_AUDIO_TYPE_LAST: break; @@ -11897,6 +11910,21 @@ virDomainAudioSDLParse(virDomainAudioIOSDL *def, } =20 =20 +static int +virDomainAudioPipewireAudioParse(virDomainAudioIOPipewireAudio *def, + xmlNodePtr node) +{ + def->name =3D virXMLPropString(node, "name"); + def->streamName =3D virXMLPropString(node, "streamName"); + + if (virXMLPropUInt(node, "latency", 10, VIR_XML_PROP_NONE, + &def->latency) < 0) + return -1; + + return 0; +} + + static virDomainAudioDef * virDomainAudioDefParseXML(virDomainXMLOption *xmlopt G_GNUC_UNUSED, xmlNodePtr node, @@ -12027,6 +12055,15 @@ virDomainAudioDefParseXML(virDomainXMLOption *xmlo= pt G_GNUC_UNUSED, case VIR_DOMAIN_AUDIO_TYPE_DBUS: break; =20 + case VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE: + if (inputNode && + virDomainAudioPipewireAudioParse(&def->backend.pipewire.input,= inputNode) < 0) + goto error; + if (outputNode && + virDomainAudioPipewireAudioParse(&def->backend.pipewire.output= , outputNode) < 0) + goto error; + break; + case VIR_DOMAIN_AUDIO_TYPE_LAST: default: virReportEnumRangeError(virDomainAudioType, def->type); @@ -24679,6 +24716,18 @@ virDomainAudioSDLFormat(virDomainAudioIOSDL *def, } =20 =20 +static void +virDomainAudioPipewireAudioFormat(virDomainAudioIOPipewireAudio *def, + virBuffer *buf) +{ + virBufferEscapeString(buf, " name=3D'%s'", def->name); + virBufferEscapeString(buf, " streamName=3D'%s'", def->streamName); + if (def->latency) + virBufferAsprintf(buf, " latency=3D'%u'", def->latency); + +} + + static int virDomainAudioDefFormat(virBuffer *buf, virDomainAudioDef *def) @@ -24761,6 +24810,11 @@ virDomainAudioDefFormat(virBuffer *buf, case VIR_DOMAIN_AUDIO_TYPE_DBUS: break; =20 + case VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE: + virDomainAudioPipewireAudioFormat(&def->backend.pipewire.input, &i= nputBuf); + virDomainAudioPipewireAudioFormat(&def->backend.pipewire.output, &= outputBuf); + break; + case VIR_DOMAIN_AUDIO_TYPE_LAST: default: virReportEnumRangeError(virDomainAudioType, def->type); @@ -29065,6 +29119,16 @@ virDomainAudioIOSDLIsEqual(virDomainAudioIOSDL *th= is, } =20 =20 +static bool +virDomainAudioIOPipewireAudioIsEqual(virDomainAudioIOPipewireAudio *this, + virDomainAudioIOPipewireAudio *that) +{ + return STREQ_NULLABLE(this->name, that->name) && + STREQ_NULLABLE(this->streamName, that->streamName) && + this->latency =3D=3D that->latency; +} + + static bool virDomainAudioBackendIsEqual(virDomainAudioDef *this, virDomainAudioDef *that) @@ -29125,6 +29189,12 @@ virDomainAudioBackendIsEqual(virDomainAudioDef *th= is, case VIR_DOMAIN_AUDIO_TYPE_FILE: return STREQ_NULLABLE(this->backend.file.path, that->backend.file.= path); =20 + case VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE: + return virDomainAudioIOPipewireAudioIsEqual(&this->backend.pipewir= e.input, + &that->backend.pipewire.i= nput) && + virDomainAudioIOPipewireAudioIsEqual(&this->backend.pipewire.o= utput, + &that->backend.pipewire.outp= ut); + case VIR_DOMAIN_AUDIO_TYPE_DBUS: case VIR_DOMAIN_AUDIO_TYPE_LAST: default: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c1cb2ed69d..7abac25ae1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1614,6 +1614,7 @@ typedef enum { VIR_DOMAIN_AUDIO_TYPE_SPICE, VIR_DOMAIN_AUDIO_TYPE_FILE, VIR_DOMAIN_AUDIO_TYPE_DBUS, + VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE, =20 VIR_DOMAIN_AUDIO_TYPE_LAST } virDomainAudioType; @@ -1689,6 +1690,13 @@ struct _virDomainAudioIOSDL { unsigned int bufferCount; }; =20 +typedef struct _virDomainAudioIOPipewireAudio virDomainAudioIOPipewireAudi= o; +struct _virDomainAudioIOPipewireAudio { + char *name; + char *streamName; + unsigned int latency; +}; + struct _virDomainAudioDef { virDomainAudioType type; =20 @@ -1732,6 +1740,10 @@ struct _virDomainAudioDef { struct { char *path; } file; + struct { + virDomainAudioIOPipewireAudio input; + virDomainAudioIOPipewireAudio output; + } pipewire; } backend; }; =20 diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index f8c7b6a648..793544e15e 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -5121,6 +5121,26 @@ =20 + + + + + + + + + + + + + + + + + + + + @@ -5296,6 +5316,23 @@ + + + pipewire + + + + + + + + + + + + + + pulseaudio diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2a6d9408f6..3a08cac870 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -142,6 +142,7 @@ qemuAudioDriverTypeToString(virDomainAudioType type) case VIR_DOMAIN_AUDIO_TYPE_SDL: case VIR_DOMAIN_AUDIO_TYPE_SPICE: case VIR_DOMAIN_AUDIO_TYPE_DBUS: + case VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE: case VIR_DOMAIN_AUDIO_TYPE_LAST: break; } @@ -7887,6 +7888,7 @@ qemuBuildAudioCommandLineArg(virCommand *cmd, case VIR_DOMAIN_AUDIO_TYPE_DBUS: break; =20 + case VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE: case VIR_DOMAIN_AUDIO_TYPE_LAST: default: virReportEnumRangeError(virDomainAudioType, def->type); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index da4b9a3b35..90e2517649 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4476,6 +4476,7 @@ qemuValidateDomainDeviceDefAudio(virDomainAudioDef *a= udio, case VIR_DOMAIN_AUDIO_TYPE_PULSEAUDIO: case VIR_DOMAIN_AUDIO_TYPE_SDL: case VIR_DOMAIN_AUDIO_TYPE_FILE: + case VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE: break; =20 case VIR_DOMAIN_AUDIO_TYPE_SPICE: diff --git a/tests/qemuxml2argvdata/audio-pipewire-best.xml b/tests/qemuxml= 2argvdata/audio-pipewire-best.xml new file mode 100644 index 0000000000..e71688d25b --- /dev/null +++ b/tests/qemuxml2argvdata/audio-pipewire-best.xml @@ -0,0 +1,43 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + + +
+ + +
+ + +
+ + + + + + + + diff --git a/tests/qemuxml2argvdata/audio-pipewire-full.xml b/tests/qemuxml= 2argvdata/audio-pipewire-full.xml new file mode 100644 index 0000000000..5811eef6d4 --- /dev/null +++ b/tests/qemuxml2argvdata/audio-pipewire-full.xml @@ -0,0 +1,43 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + + +
+ + +
+ + +
+ + + + + + + + diff --git a/tests/qemuxml2argvdata/audio-pipewire-minimal.xml b/tests/qemu= xml2argvdata/audio-pipewire-minimal.xml new file mode 100644 index 0000000000..2085225722 --- /dev/null +++ b/tests/qemuxml2argvdata/audio-pipewire-minimal.xml @@ -0,0 +1,36 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + + +
+ + +
+ + +
+ + + + +