From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id AHcdJfSvAGQXnAAAbAwnHQ (envelope-from ) for ; Thu, 02 Mar 2023 15:17:24 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id +EkIJPSvAGRifAEAG6o9tA (envelope-from ) for ; Thu, 02 Mar 2023 15:17:24 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id F11512D165 for ; Thu, 2 Mar 2023 15:17:23 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXjk3-0003z5-SE; Thu, 02 Mar 2023 09:17:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXjjy-0003qZ-Vq for guix-patches@gnu.org; Thu, 02 Mar 2023 09:17:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXjjy-0001Yy-4L for guix-patches@gnu.org; Thu, 02 Mar 2023 09:17:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pXjjx-0005ja-My for guix-patches@gnu.org; Thu, 02 Mar 2023 09:17:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#61900] [PATCH] home: services: Add 'pulseaudio-rtp-sink' and 'pulseaudio-rtp-source'. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Mar 2023 14:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61900 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= , 61900@debbugs.gnu.org Cc: paren@disroot.org, Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 61900-submit@debbugs.gnu.org id=B61900.167776659922008 (code B ref 61900); Thu, 02 Mar 2023 14:17:01 +0000 Received: (at 61900) by debbugs.gnu.org; 2 Mar 2023 14:16:39 +0000 Received: from localhost ([127.0.0.1]:56237 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXjja-0005it-02 for submit@debbugs.gnu.org; Thu, 02 Mar 2023 09:16:38 -0500 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:38085) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pXjjX-0005ih-Ls for 61900@debbugs.gnu.org; Thu, 02 Mar 2023 09:16:36 -0500 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id 914591BF208; Thu, 2 Mar 2023 14:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1677766589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=X2jkMyNoQcCfjlsACKx0TPNRMICC8exnxmN0RW6PvDc=; b=CZA360hHnfMOhIS6S229C62NG3dJucAHfi90tDLAWHCKTn+YXbNp4qyG3SwY2WH9a/mt+F q2KoFnAZFZkKIyvOr7ADjlw/bRg58ZI0zxSfhPBjCZwK/+MVM0144MynDR6ZPh3X2XeTHT h8R2HVXmNTvhyAAyPCBg8BiZ/AlA9ANVyefXeRIOxFCrbn0yno0hREPVjgQ3mHXAss/WE/ K4RCLWVhd8PXwrH9kiIiWXPEHl/I6AGxdoWIWQY4yGdJSb5ujWGuaK770d8CFv2TqlEWB3 pBlOwZ7lr+jWoqKXk13IsDNgkgMQ/VCcQopCv+j7m63N4x3Rv8oxYjDNz53mYg== From: Andrew Tropin In-Reply-To: <20230301222601.22216-1-ludo@gnu.org> References: <20230301222601.22216-1-ludo@gnu.org> Date: Thu, 02 Mar 2023 18:16:24 +0400 Message-ID: <87y1ofb5mv.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1677766644; a=rsa-sha256; cv=none; b=Dol8S0pADmzbGOiV8gDb/DqAF6qnhaov2Sl35D8hluc0YR83mO+v9/6S/RnD8U5VK9ZB+w QqJ5VziI76WWmJDJPuRXBzKeHecZKzonz/sahZ5Vfp6/mAo3ZWRjyhwDB7InTJA63O4Wkc 8XFVyuZtkDLAXcCi/HPlVL86Shj0fZsdutB1BzjK85VxfXEkJdigWftrlam3L7V+O4UHdf W1a3nscIDe1Cb4TXZD7KiUM+fbMbQS0cmsjJnzvRaker7JADwem2c8VcX7tPR8MqnGcofY mxPIuY9vFgntXXxjJK2675M0ChRa+h94R0nqeYW9vtHoSvynNLMraGRY8fOQ/Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=CZA360hH; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1677766644; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=X2jkMyNoQcCfjlsACKx0TPNRMICC8exnxmN0RW6PvDc=; b=BjGfhW9iS0wb++nJMq47JP8/rm98GQr959tGYUtAPzPU4BY3C67P0qQUlMQj5mOAkeJXRv C3et0T2HdQo14R7qRN2LIe60f+/Jh9iA2ZtBbmNlK/WjCHEYAourSLVVjOxnYO+xhJ6HO0 WP0tPu4dQMjcq+fmfvnL/O72onVb2PUyl7TeHrvxHZuPpjHiVEy7L3c9blQzGPhiNzq1jw tTfwEgvZH6BxpsMGt6U7C4SFRoOUNk0gt4dqJ3YyqN9P3N9n9FrkSCSxpAyfLxxwbKC+OW fGwVpsK0SjU1OLypuhDkdEQ4SvElp6Ov2VPXxCS9M0qCL16b8cKAsRsiVHLByQ== X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -4.39 X-Spam-Score: -4.39 X-Migadu-Queue-Id: F11512D165 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=CZA360hH; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none X-TUID: WV9i5UDKaWZn --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2023-03-01 23:26, Ludovic Court=C3=A8s wrote: > * gnu/home/services/sound.scm: New file. > * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. > * doc/guix.texi (Sound Home Services): New section. > --- > doc/guix.texi | 114 ++++++++++++++++++++++++--- > gnu/home/services/sound.scm | 151 ++++++++++++++++++++++++++++++++++++ > gnu/local.mk | 3 +- > 3 files changed, 258 insertions(+), 10 deletions(-) > create mode 100644 gnu/home/services/sound.scm > > Hi there! > > Here=E2=80=99s a Guix Home service I=E2=80=99ve been using for some time.= In a nutshell, > when I want to send audio to a device that=E2=80=99s further away from my= laptop, > I run: > > herd start pulseaudio-rtp-sink > > That adds a PulseAudio =E2=80=9Csink=E2=80=9D, which I can select in pavu= control or > pulsemixer to send audio streams over there. And then to turn that off: > > herd stop pulseaudio-rtp-sink > > Thoughts? > > Ludo=E2=80=99. > > diff --git a/doc/guix.texi b/doc/guix.texi > index a7ef00f421..7716686f87 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -41513,15 +41513,16 @@ service with the @code{simple-service} procedur= e from @code{(gnu > services)}. >=20=20 > @menu > -* Essential Home Services:: Environment variables, packages, on-* scrip= ts. > -* Shells: Shells Home Services. POSIX shells, Bas= h, Zsh. > -* Mcron: Mcron Home Service. Scheduled User's = Job Execution. > -* Power Management: Power Management Home Services. Services for batt= ery power. > -* Shepherd: Shepherd Home Service. Managing User's D= aemons. > -* SSH: Secure Shell. Setting up the se= cure shell client. > -* Desktop: Desktop Home Services. Services for grap= hical environments. > -* Guix: Guix Home Services. Services for Guix. > -* Fonts: Fonts Home Services. Services for mana= ging User's fonts. > +* Essential Home Services:: Environment variables, packages, on-* sc= ripts. > +* Shells: Shells Home Services. POSIX shells, Bash, Zsh. > +* Mcron: Mcron Home Service. Scheduled User's Job Execution. > +* Power Management: Power Management Home Services. Services for batter= y power. > +* Shepherd: Shepherd Home Service. Managing User's Daemons. > +* SSH: Secure Shell. Setting up the secure shell client. > +* Desktop: Desktop Home Services. Services for graphical environments. > +* Guix: Guix Home Services. Services for Guix. > +* Fonts: Fonts Home Services. Services for managing User's fonts. > +* Sound: Sound Home Services. Dealing with audio. > @end menu > @c In addition to that Home Services can provide >=20=20 > @@ -42435,6 +42436,101 @@ like this: > @end lisp > @end defvar >=20=20 > +@node Sound Home Services > +@subsection Sound Home Services > + > +The @code{(gnu home services sound)} module provides services related to > +sound support. > + > +@cindex PulseAudio, home service > +@cindex RTP, for PulseAudio > + > +The following services dynamically reconfigure the > +@uref{https://pulseaudio.org,PulseAudio sound server}: they let you > +toggle broadcast of audio output over the network using the > +@acronym{RTP, real-time transport protocol} and, correspondingly, > +playback of sound received over RTP. Once > +@code{home-pulseaudio-rtp-sink-service-type} is among your home > +services, you can start broadcasting audio output by running this > +command: > + > +@example > +herd start pulseaudio-rtp-sink > +@end example > + > +You can then run a PulseAudio-capable mixer, such as @code{pavucontrol} > +or @code{pulsemixer} (both from the same-named package) to control which > +audio stream(s) should be sent to the RTP ``sink''. > + > +By default, audio is broadcasted to a multicast address: any device on > +the @acronym{LAN, local area network} receives it and may play it. > +Using multicast in this way puts a lot of pressure on the network and > +degrades its performance, so you may instead prefer sending to > +specifically one device. The first way to do that is by specifying the > +IP address of the target device when starting the service: > + > +@example > +herd start pulseaudio-rtp-sink 192.168.1.42 > +@end example > + > +The other option is to specify this IP address as the one to use by > +default in your home environment configuration: > + > +@lisp > +(service home-pulseaudio-rtp-sink-service-type > + "192.168.1.42") > +@end lisp > + > +On the device where you intend to receive and play the RTP stream, you > +can use @code{home-pulseaudio-rtp-source-service-type}, like so: > + > +@lisp > +(service home-pulseaudio-rtp-source-service-type) > +@end lisp > + > +This will then let you start the receiving module for PulseAudio: > + > +@example > +herd start pulseaudio-rtp-source > +@end example > + > +Again, by default it will listen on the multicast address. If, instead, > +you'd like it to listen for direct incoming connections, you can do that > +by running: > + > +@lisp > +(service home-pulseaudio-rtp-source-service-type > + "0.0.0.0") > +@end lisp > + > +The reference of these services is given below. > + > +@defvar home-pulseaudio-rtp-sink-service-type > +@defvarx home-pulseaudio-rtp-source-service-type > +This is the type of the service to send, respectively receive, audio > +streams over @acronym{RTP, real-time transport protocol}. > + > +The value associated with this service is the IP address (a string) > +where to send, respectively receive, the audio stream. By default, > +audio is sent/received on multicast address > +@code{%pulseaudio-rtp-multicast-address}. > + > +This service defines one Shepherd service: @code{pulseaudio-rtp-sink}, > +respectively @code{pulseaudio-rtp-source}. The service is not started > +by default, so you have to explicitly start it when you want to turn it > +on, as in this example: > + > +@example > +herd start pulseaudio-rtp-sink > +@end example > + > +Stopping the Shepherd service turns off broadcasting. > +@end defvar > + > +@defvar %pulseaudio-rtp-multicast-address > +This is the multicast address used by default by the two services above. > +@end defvar > + > @node Invoking guix home > @section Invoking @command{guix home} >=20=20 > diff --git a/gnu/home/services/sound.scm b/gnu/home/services/sound.scm > new file mode 100644 > index 0000000000..22c1a99250 > --- /dev/null > +++ b/gnu/home/services/sound.scm > @@ -0,0 +1,151 @@ > +;;; GNU Guix --- Functional package management for GNU > +;;; Copyright =C2=A9 2023 Ludovic Court=C3=A8s > +;;; > +;;; This file is part of GNU Guix. > +;;; > +;;; GNU Guix is free software; you can redistribute it and/or modify it > +;;; under the terms of the GNU General Public License as published by > +;;; the Free Software Foundation; either version 3 of the License, or (at > +;;; your option) any later version. > +;;; > +;;; GNU Guix 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 General Public License for more details. > +;;; > +;;; You should have received a copy of the GNU General Public License > +;;; along with GNU Guix. If not, see . > + > +(define-module (gnu home services sound) > + #:use-module (gnu home services) > + #:use-module (gnu home services shepherd) > + #:use-module (guix records) > + #:use-module (guix gexp) > + #:use-module (srfi srfi-1) > + #:use-module (ice-9 match) > + #:export (home-pulseaudio-rtp-sink-service-type > + home-pulseaudio-rtp-source-service-type > + %pulseaudio-rtp-multicast-address)) > + > + > +;;; > +;;; PulseAudio support. > +;;; > + > +(define (with-pulseaudio-connection sock exp) > + ;; Wrap EXP in an expression where SOCK is bound to a socket connected= to > + ;; the user's PulseAudio command-line interface socket. > + #~(let* ((#$sock (socket AF_UNIX SOCK_STREAM 0)) > + (pulse-user-file > + (lambda (name) > + (string-append "/run/user/" (number->string (getuid)) > + "/pulse/" name))) > + (file (pulse-user-file "cli"))) > + (let loop ((tries 0)) > + (catch #t > + (lambda () > + (connect #$sock AF_UNIX file) > + (let ((result #$exp)) > + (close-port #$sock) > + result)) > + (lambda (key . args) > + (if (and (eq? key 'system-error) > + (=3D ENOENT (system-error-errno (cons key args))) > + (< tries 3)) > + ;; The CLI socket doesn't exist yet, so send pulseaudio > + ;; SIGUSR2 so that it creates it and listens to it. > + (let ((pid (call-with-input-file (pulse-user-file "pid") > + read))) > + (when (and (integer? pid) (> pid 1)) > + (kill pid SIGUSR2)) > + ((@ (fibers) sleep) 1) > + (loop (+ tries 1))) > + (begin > + (close-port #$sock) > + (apply throw key args)))))))) > + > +(define %pulseaudio-rtp-multicast-address > + ;; Default address used by 'module-rtp-sink' and 'module-rtp-recv'. T= his is > + ;; a multicast address, for the Session Announcement Protocol (SAP) an= d the > + ;; Session Description Protocol (SDP). > + "224.0.0.56") > + > +(define (pulseaudio-rtp-sink-shepherd-services destination-ip) > + (list (shepherd-service > + (provision '(pulseaudio-rtp-sink)) > + (start > + #~(lambda* (#:optional (destination-ip #$destination-ip)) > + #$(with-pulseaudio-connection > + #~sock > + #~(begin > + (display "\ > +load-module module-null-sink \ > +sink_name=3Drtp sink_properties=3D\"device.description=3D'RTP network ou= tput'\"\n" > + sock) > + (display (string-append "\ > +load-module module-rtp-send source=3Drtp.monitor" > + (if destination-ip > + (string-append > + " destination_ip=3D" > + destination-ip) > + "") > + "\n") > + sock) > + #t)))) > + (stop > + #~(lambda (_) > + #$(with-pulseaudio-connection > + #~sock > + #~(begin > + (display "unload-module module-rtp-send\n" > + sock) > + (display "unload-module module-null-sink\n" > + sock) > + #f)))) > + (auto-start? #f)))) > + > +(define home-pulseaudio-rtp-sink-service-type > + (service-type > + (name 'pulseaudio-rtp-sink) > + (extensions > + (list (service-extension home-shepherd-service-type > + pulseaudio-rtp-sink-shepherd-services))) > + (description > + "Define a PulseAudio sink to broadcast audio output over RTP, which = can > +then by played by another PulseAudio instance.") > + > + ;; By default, send to the SAP multicast address, 224.0.0.56, which c= an be > + ;; network-intensive. > + (default-value %pulseaudio-rtp-multicast-address))) > + > +(define (pulseaudio-rtp-source-shepherd-services source-ip) > + (list (shepherd-service > + (provision '(pulseaudio-rtp-source)) > + (start > + #~(lambda* (#:optional (source-ip #$source-ip)) > + #$(with-pulseaudio-connection > + #~sock > + #~(begin > + (format sock "\ > +load-module module-rtp-recv sap_address=3D~a\n" source-ip) > + #t)))) > + (stop > + #~(lambda (_) > + #$(with-pulseaudio-connection > + #~sock > + #~(begin > + (display "unload-module module-rtp-recv\n" > + sock) > + #f)))) > + (auto-start? #f)))) > + > +(define home-pulseaudio-rtp-source-service-type > + (service-type > + (name 'pulseaudio-rtp-source) > + (extensions > + (list (service-extension home-shepherd-service-type > + pulseaudio-rtp-source-shepherd-services))) > + (description > + "Define a PulseAudio source to receive audio broadcasted over RTP by > +another PulseAudio instance.") > + (default-value %pulseaudio-rtp-multicast-address))) > diff --git a/gnu/local.mk b/gnu/local.mk > index dd1d546be5..55b5295439 100644 > --- a/gnu/local.mk > +++ b/gnu/local.mk > @@ -1,5 +1,5 @@ > # GNU Guix --- Functional package management for GNU > -# Copyright =C2=A9 2012-2021, 2021-2022 Ludovic Court=C3=A8s > +# Copyright =C2=A9 2012-2023 Ludovic Court=C3=A8s > # Copyright =C2=A9 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2022 = Andreas Enge > # Copyright =C2=A9 2016 Mathieu Lirzin > # Copyright =C2=A9 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 = Mark H Weaver > @@ -94,6 +94,7 @@ GNU_SYSTEM_MODULES =3D \ > %D%/home/services/pm.scm \ > %D%/home/services/shells.scm \ > %D%/home/services/shepherd.scm \ > + %D%/home/services/sound.scm \ > %D%/home/services/ssh.scm \ > %D%/home/services/mcron.scm \ > %D%/home/services/utils.scm \ > > base-commit: ff5fbcc19bce6e94ead0cc79b27ae8ed0307463d Hi Ludo, thank you for the interesting services! I expected them to have an ability to specify a port, but it seems it is supported only in pipewire, but not in pulseaudio. https://docs.pipewire.org/page_module_rtp_source.html The patch looks good to me. =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmQAr7gACgkQIgjSCVjB 3rCZSA//apns0iKRmYHIUa07n4MW/REGOivpQ5e/dnFtkQEQrB3HslFG6ZtiGB/j ku1e8wvNcyKzHR1wk2a+2BBah+y/h7OsQJKDN9NnSkuTqzYx0KpcJA998KiTdH4m wK0AWTligc1hsU8SjNVC8ezSTWOLsXO29oXKYiA4tyTFpokYvM+IFad1iuVxikYc SYbJsMQLpgCn4ZcDlSmUZ6HS2PvytkU7m4iF67P9MB7YYVE6wlO5ceC3esSGdMcl 4LH7/NhpiQ8cOEYnNgx0LouEA+o9EHUgA9zmErtdzF8GDRl19Ev+SYdNv1t9rb8k ekCULbdWMzox5b+9H5RuYbSmH5uiqCF8x8/cJWPP9qbYtSATDiWD4KAKzT1kbJYi QCOULYkgRpVV4N5J7tN9A4X7blXGu0hVzRAkWR3D4fa+LV5NoKiH/dgBVetmbTvu 5VfYY3gy5OXCPP6UGFa++ya4JBqNROawrHd0MO+wCjafhyPnrfonm3gFd51780bg 4YqJZv8F+mHK8Vz6eVPMaunAimoF+UeTikRp39LXaWCkC4VCkwk2/Fb0baOSXSJw lzFn10xs8C07UGDtmXwWbt/LJws33HN6ny3d8R7XVnAlSYeGtBHyPdP2giXZDpKP VAgtHZTXqQ+MgDrInOGmBGF5Uuvlxf8z3l3SThVLNVkMJLqHKpY= =m48N -----END PGP SIGNATURE----- --=-=-=--