From 9918d677e78afa3c85ae70759ac76b22a3f93643 Mon Sep 17 00:00:00 2001 From: Aaron van Meerten Date: Tue, 28 Jan 2025 15:00:55 -0600 Subject: [PATCH] feat(jibri): support for pulseaudio --- ansible/build-java-jibri-oracle.yml | 3 +- .../roles/jibri-java/templates/jibri.conf.j2 | 16 +++++ ansible/roles/pulseaudio/defaults/main.yml | 1 + ansible/roles/pulseaudio/files/etc-default.pa | 65 +++++++++++++++++++ .../roles/pulseaudio/files/jibri-client.conf | 1 + .../roles/pulseaudio/files/jibri-daemon.conf | 9 +++ .../roles/pulseaudio/files/jibri-default.pa | 8 +++ ansible/roles/pulseaudio/tasks/main.yml | 37 +++++++++++ 8 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/pulseaudio/defaults/main.yml create mode 100644 ansible/roles/pulseaudio/files/etc-default.pa create mode 100644 ansible/roles/pulseaudio/files/jibri-client.conf create mode 100644 ansible/roles/pulseaudio/files/jibri-daemon.conf create mode 100644 ansible/roles/pulseaudio/files/jibri-default.pa create mode 100644 ansible/roles/pulseaudio/tasks/main.yml diff --git a/ansible/build-java-jibri-oracle.yml b/ansible/build-java-jibri-oracle.yml index a8d5a231..28f1322c 100644 --- a/ansible/build-java-jibri-oracle.yml +++ b/ansible/build-java-jibri-oracle.yml @@ -23,7 +23,7 @@ tags: "provision" roles: - - { role: "jibri-kernel", tags: "jibri-kernel"} + - { role: "jibri-kernel", tags: "jibri-kernel", when: not jibri_pulseaudio_enabled } - { role: "common", tags: "common"} - { role: "boot-postinstall", tags: "boot-postinstall" } - { role: "sshusers", tags: "ssh" } @@ -44,6 +44,7 @@ - { role: "autoscaler-sidecar", tags: "autoscaler-sidecar", autoscaler_instance_type: "jibri", autoscaler_install_flag: true, autoscaler_configure_flag: false, jitsi_autoscaler_sidecar: true} - { role: "jibri-java", tags: "jibri", jibri_install_flag: true, jibri_configure_flag: false} + - { role: "pulseaudio", tags: "pulseaudio", when: jibri_pulseaudio_enabled } - { role: "jitsi-upload-integrations", tags: "jitsi-upload-integrations", upload_integrations_install_flag: true, upload_integrations_configure_flag: false } - { role: "jitsi-upload-customizations", tags: "jitsi-upload-customizations", diff --git a/ansible/roles/jibri-java/templates/jibri.conf.j2 b/ansible/roles/jibri-java/templates/jibri.conf.j2 index 455fbedf..1d78126c 100644 --- a/ansible/roles/jibri-java/templates/jibri.conf.j2 +++ b/ansible/roles/jibri-java/templates/jibri.conf.j2 @@ -5,6 +5,22 @@ jibri { recordings-directory = "{{ jibri_recordings_dir }}" finalize-script = "{{ jibri_finalize_recording_script }}" } + ffmpeg { + // resolution = "1920x1080" + // The audio source that will be used to capture audio on Linux + audio-source = "{{ 'pulse' if jibri_pulse_audio_enabled else 'alsa' }}" + // The audio device that will be used to capture audio on Linux + audio-device = "{{ 'default' if jibri_pulse_audio_enabled else 'plug:bsnoop' }}" + // framerate = 30 + // queue-size = 4096 + // streaming-max-bitrate = 2976 + // Available presets: ultrafast, superfast, veryfast, faster, fast, medium, + // slow, slower, veryslow, placebo + // video-encode-preset = "veryfast" + // The range of the CRF scale is 0-51, where 0 is lossless, + // 23 is the default, and 51 is worst quality possible. + // h264-constant-rate-factor = 25 + } webhook { subscribers = [{% if jibri_sidecar_webhook %}"{{ jibri_sidecar_webhook }}"{% endif %}{% if sip_jibri_sidecar_webhook %}{% if jibri_sidecar_webhook %},{% endif %}"{{ sip_jibri_sidecar_webhook }}"{% endif %}] } diff --git a/ansible/roles/pulseaudio/defaults/main.yml b/ansible/roles/pulseaudio/defaults/main.yml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/ansible/roles/pulseaudio/defaults/main.yml @@ -0,0 +1 @@ +--- diff --git a/ansible/roles/pulseaudio/files/etc-default.pa b/ansible/roles/pulseaudio/files/etc-default.pa new file mode 100644 index 00000000..7ddb07bf --- /dev/null +++ b/ansible/roles/pulseaudio/files/etc-default.pa @@ -0,0 +1,65 @@ +#!/usr/bin/pulseaudio -nF +# +# This file is part of PulseAudio. +# +# PulseAudio 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; either version 2 of the License, or +# (at your option) any later version. +# +# PulseAudio 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 Lesser General Public License +# along with PulseAudio; if not, see . + +# This startup script is used only if PulseAudio is started per-user +# (i.e. not in system mode) + +# Customized for Jibri + +.fail + +### Automatically restore the volume of streams and devices +load-module module-device-restore +load-module module-stream-restore +load-module module-card-restore + +### Automatically augment property information from .desktop files +### stored in /usr/share/application +load-module module-augment-properties + +### Should be after module-*-restore but before module-*-detect +load-module module-switch-on-port-available + +### Load several protocols +load-module module-native-protocol-unix + +### Automatically restore the default sink/source when changed by the user +### during runtime +### NOTE: This should be loaded as early as possible so that subsequent modules +### that look up the default sink/source get the right value +load-module module-default-device-restore + +### Make sure we always have a sink around, even if it is a null sink. +load-module module-always-sink + +### Honour intended role device property +load-module module-intended-roles + +### Automatically suspend sinks/sources that become idle for too long +load-module module-suspend-on-idle + +### If autoexit on idle is enabled we want to make sure we only quit +### when no local session needs us anymore. +#.ifexists module-console-kit.so +#load-module module-console-kit +#.endif +#.ifexists module-systemd-login.so +#load-module module-systemd-login +#.endif + +### Enable positioned event sounds +load-module module-position-event-sounds diff --git a/ansible/roles/pulseaudio/files/jibri-client.conf b/ansible/roles/pulseaudio/files/jibri-client.conf new file mode 100644 index 00000000..b16dc7ec --- /dev/null +++ b/ansible/roles/pulseaudio/files/jibri-client.conf @@ -0,0 +1 @@ +autospawn = yes diff --git a/ansible/roles/pulseaudio/files/jibri-daemon.conf b/ansible/roles/pulseaudio/files/jibri-daemon.conf new file mode 100644 index 00000000..115c233a --- /dev/null +++ b/ansible/roles/pulseaudio/files/jibri-daemon.conf @@ -0,0 +1,9 @@ +# daemonize = no +high-priority = no +realtime-scheduling = yes +realtime-priority = 5 +exit-idle-time = -1 +flat-volumes = no +deferred-volume-safety-margin-usec = 1 +log-level = info +log-target = file:/var/log/jitsi/jibri/pulse.log diff --git a/ansible/roles/pulseaudio/files/jibri-default.pa b/ansible/roles/pulseaudio/files/jibri-default.pa new file mode 100644 index 00000000..0ac59a70 --- /dev/null +++ b/ansible/roles/pulseaudio/files/jibri-default.pa @@ -0,0 +1,8 @@ +.include /etc/pulse/default.pa + +# Load the virtual sink and set it as default +load-module module-virtual-sink sink_name=jibri-loop +set-default-sink jibri-loop + +# set the monitor of the jibri-loop sink to be the default source +set-default-source jibri-loop.monitor diff --git a/ansible/roles/pulseaudio/tasks/main.yml b/ansible/roles/pulseaudio/tasks/main.yml new file mode 100644 index 00000000..1d986412 --- /dev/null +++ b/ansible/roles/pulseaudio/tasks/main.yml @@ -0,0 +1,37 @@ +--- +- name: Install pulseaudio + ansible.builtin.apt: + name: ['pulseaudio'] + state: present + +- name: Install /etc/pulse/default.pa + ansible.builtin.copy: + src: default.pa + dest: /etc/pulse/default.pa + owner: root + group: root + mode: 0644 + +- name: Install jibri pulse defaults + ansible.builtin.copy: + src: jibri-default.pa + dest: /home/jibri/.config/pulse/default.pa + owner: jibri + group: jibri + mode: 0644 + +- name: Install jibri pulse client config + ansible.builtin.copy: + src: jibri-client.conf + dest: /home/jibri/.config/pulse/client.conf + owner: jibri + group: jibri + mode: 0644 + +- name: Install jibri pulse daemon config + ansible.builtin.copy: + src: jibri-daemon.conf + dest: /home/jibri/.config/pulse/daemon.conf + owner: jibri + group: jibri + mode: 0644