From nobody Mon Sep 16 19:54:14 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=1683807304; cv=none; d=zohomail.com; s=zohoarc; b=gJ9WiAFwU5OG9aPqtn+/IxTic6Yu31T6QnOS+WvmiaSlKJA5n40JOa2QTY/dz6pbxWsh8XSDwQVvW7gDi0QREN2sbHNo641dmOYTvgZ3sJCaJ/wXO4CoWcbxGFx7veQ3Kh2jFCEe5pGv5joxSOujIoUOhTq/LeuNa+tp0ZzL+QE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683807304; 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=yNs8FrSSLIWkIbwzBDuNtwGSXdfssWvzZisBNfgrBN0=; b=iJk0E0b7eF35LuxFE02hx8yIIQiJfMM6l90A/IOqXJEx7rD8YEpB9MBlB6YISX6SzSZIFGf3C0VUotHA+IpnTWdN4+5pk1r7oS4+CwCkZ9UaQNHypOkPcopt5fo73eFjTNkzBdaZ+wDDmtt09BEb29wq2H850JgS65+LgCyC0f8= 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 1683807304641901.096082852909; Thu, 11 May 2023 05:15:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-108-RlF0rtV0MR2Hle71ra8MMA-1; Thu, 11 May 2023 08:15:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 949012811BCC; 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 796732166B26; 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 51FD019451EF; Thu, 11 May 2023 12:14:56 +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 0E62319451DD for ; Thu, 11 May 2023 12:14:55 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E56B463F8A; 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 8CF5047CD0 for ; Thu, 11 May 2023 12:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683807303; 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=yNs8FrSSLIWkIbwzBDuNtwGSXdfssWvzZisBNfgrBN0=; b=d7Yyo0fR7uItaSW/279brXQVcimC2X+LTCcHuvaQ7VldUCW2LKe3b+rk3PeWerPEhpfwVB SXocqCNErvCGqT/ryomXOjEtE2Mhj4YCL7dOqxH+QZHL71N/GfHIuCncVkWvgdoQb9VlB7 EDrUev8KIEh+9ck7AiTcHo1Okzd9JcE= X-MC-Unique: RlF0rtV0MR2Hle71ra8MMA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] qemu: Generate cmd line for pipewire audio backend Date: Thu, 11 May 2023 14:14:51 +0200 Message-Id: <6fcd316a29202f4b802cfa0dc92abcb121c1763f.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.6 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: 1683807306712100005 Content-Type: text/plain; charset="utf-8"; x-default="true" This is mostly straightforward, except for a teensy-weensy detail: usually, there's no system wide daemon running, no system wide available socket that anybody could connect to. PipeWire uses a per user daemon approach instead. But this in turn means, that the socket location floats between various locations and is derived from various environment variables (just like the actual socket name) and thus we must pass the variables to QEMU. Signed-off-by: Michal Privoznik --- src/qemu/qemu_command.c | 61 +++++++++++++++++++ .../audio-many-backends.x86_64-latest.args | 2 + .../qemuxml2argvdata/audio-many-backends.xml | 1 + .../audio-pipewire-best.x86_64-latest.args | 36 +++++++++++ .../audio-pipewire-full.x86_64-latest.args | 36 +++++++++++ .../audio-pipewire-minimal.x86_64-latest.args | 36 +++++++++++ tests/qemuxml2argvtest.c | 12 ++++ 7 files changed, 184 insertions(+) create mode 100644 tests/qemuxml2argvdata/audio-pipewire-best.x86_64-lates= t.args create mode 100644 tests/qemuxml2argvdata/audio-pipewire-full.x86_64-lates= t.args create mode 100644 tests/qemuxml2argvdata/audio-pipewire-minimal.x86_64-la= test.args diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3a08cac870..b31f4db6b1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7783,6 +7783,60 @@ qemuBuildAudioSDLProps(virDomainAudioIOSDL *def, } =20 =20 +static int +qemuBuildAudioPipewireAudioProps(virDomainAudioIOPipewireAudio *def, + virJSONValue **props) +{ + return virJSONValueObjectAdd(props, + "S:name", def->name, + "S:stream-name", def->streamName, + "p:latency", def->latency, + NULL); +} + + +static void +qemuBuildAudioPipewireAudioEnv(virCommand *cmd) +{ + const char *envVars[] =3D { "PIPEWIRE_RUNTIME_DIR", "XDG_RUNTIME_DIR", + "USERPROFILE" }; + size_t i; + + /* PipeWire needs access to its daemon socket. The socket name is + * configurable (core.name in pipewire.conf, or PIPEWIRE_CORE and + * PIPEWIRE_REMOTE env vars). If the socket name is not an absolute + * path, then the socket is looked for in the following directories + * (in order): + * + * - PIPEWIRE_RUNTIME_DIR + * - XDG_RUNTIME_DIR + * - USERPROFILE + * + * This order is defined in get_runtime_dir() from + * src/modules/module-protocol-native/local-socket.c from PipeWire's + * codebase. + * + * Now, PIPEWIRE_CORE and/or PIPEWIRE_REMOTE should be passed + * whenever present in the environment. But for the other three + * (socket location dirs), we can add just the first existing one + * (basically mimic get_runtime_dir() logic). + */ + + virCommandAddEnvPass(cmd, "PIPEWIRE_CORE"); + virCommandAddEnvPass(cmd, "PIPEWIRE_REMOTE"); + + for (i =3D 0; i < G_N_ELEMENTS(envVars); i++) { + const char *value =3D getenv(envVars[i]); + + if (!value) + continue; + + virCommandAddEnvPair(cmd, envVars[i], value); + break; + } +} + + static int qemuBuildAudioCommandLineArg(virCommand *cmd, virDomainAudioDef *def) @@ -7889,6 +7943,13 @@ qemuBuildAudioCommandLineArg(virCommand *cmd, break; =20 case VIR_DOMAIN_AUDIO_TYPE_PIPEWIRE: + if (qemuBuildAudioPipewireAudioProps(&def->backend.pipewire.input,= &in) < 0 || + qemuBuildAudioPipewireAudioProps(&def->backend.pipewire.output= , &out) < 0) + return -1; + + qemuBuildAudioPipewireAudioEnv(cmd); + break; + case VIR_DOMAIN_AUDIO_TYPE_LAST: default: virReportEnumRangeError(virDomainAudioType, def->type); diff --git a/tests/qemuxml2argvdata/audio-many-backends.x86_64-latest.args = b/tests/qemuxml2argvdata/audio-many-backends.x86_64-latest.args index 9caf591daf..13dd55054e 100644 --- a/tests/qemuxml2argvdata/audio-many-backends.x86_64-latest.args +++ b/tests/qemuxml2argvdata/audio-many-backends.x86_64-latest.args @@ -6,6 +6,7 @@ LOGNAME=3Dtest \ XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +XDG_RUNTIME_DIR=3D/bad-test-used-env-xdg-runtime-dir \ /usr/bin/qemu-system-x86_64 \ -name guest=3DQEMUGuest1,debug-threads=3Don \ -S \ @@ -32,6 +33,7 @@ XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGue= st1/.config \ -audiodev '{"id":"audio1","driver":"none"}' \ -audiodev '{"id":"audio2","driver":"alsa"}' \ -audiodev '{"id":"audio3","driver":"pa"}' \ +-audiodev '{"id":"audio4","driver":"pipewire"}' \ -vnc 127.0.0.1:0,audiodev=3Daudio2 \ -device '{"driver":"cirrus-vga","id":"video0","bus":"pci.0","addr":"0x2"}'= \ -device '{"driver":"AC97","id":"sound0","audiodev":"audio1","bus":"pci.0",= "addr":"0x3"}' \ diff --git a/tests/qemuxml2argvdata/audio-many-backends.xml b/tests/qemuxml= 2argvdata/audio-many-backends.xml index c681784526..1659723f91 100644 --- a/tests/qemuxml2argvdata/audio-many-backends.xml +++ b/tests/qemuxml2argvdata/audio-many-backends.xml @@ -51,6 +51,7 @@