Setup pulse audio for remote audio

This commit is contained in:
Sonny Bakker 2021-11-21 16:58:56 +01:00
parent 470d8053bf
commit 00b7536f5e
12 changed files with 62 additions and 147 deletions

View file

@ -1,64 +1,14 @@
- name: set up sudoers configuration
become: yes
template:
src: 'templates/sudoers.j2'
dest: '/etc/sudoers.d/10-sonny'
owner: root
group: root
mode: '0644'
# remote mpd server is used now
- name: copy systemd configuration files
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- {
src: 'templates/mpd/service.j2',
dest: '{{ xdg_config_dir }}/systemd/user/mpd.service',
}
- {
src: 'templates/mpd/socket.j2',
dest: '{{ xdg_config_dir }}/systemd/user/mpd.socket',
}
- name: check for mpd socket
stat:
path: '{{ xdg_config_dir }}/systemd/user/mpd.socket'
register: mpd_socket
- name: create mpd files
file:
path: '{{ item.path }}'
state: '{{ item.state }}'
loop:
- { path: '{{ mpd_configuration_dir }}', state: 'directory' }
- { path: '{{ mpd_configuration_dir }}/playlists', state: 'directory' }
- { path: '{{ mpd_configuration_dir }}/log', state: 'touch' }
- { path: '{{ mpd_configuration_dir }}/database', state: 'touch' }
- { path: '{{ mpd_configuration_dir }}/sticker.sql', state: 'touch' }
- { path: '{{ mpd_configuration_dir }}/state', state: 'touch' }
- name: copy configuration file
template:
src: 'templates/mpd/mpd.j2'
dest: '{{ mpd_configuration_dir }}/mpd.conf'
- name: copy nfs connection scripts
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
mode: '0755'
loop:
- { src: 'templates/mpd/music_mount.j2', dest: '{{ xdg_script_dir }}/music_mount' }
- { src: 'templates/mpd/music_umount.j2', dest: '{{ xdg_script_dir }}/music_umount' }
- name: restart mpd service
systemd:
name: mpd.service
state: restarted
enabled: no
scope: user
when: platform == "desktop"
- name: enable mpd socket
- name: disable mpd socket
systemd:
name: mpd.socket
state: started
enabled: yes
state: stopped
enabled: no
scope: user
when: platform == "desktop"
when: mpd_socket.stat.exists

View file

@ -1,4 +1,23 @@
# Note that pulsaudio should be removed by install pipewire-pulse manually
# Note that pulsaudio should be removed by installing pipewire-pulse manually
- name: create pipewire-pulse override directory
file:
path: '{{ xdg_config_dir }}/systemd/user/pipewire-pulse.service.d/'
state: directory
# sets up an post activation script to load the module-native-protocol-tcp
# with given parameters. This is not yet supported through pipewire-pulse's configuration,
# see https://gitlab.freedesktop.org/pipewire/pipewire/-/wikis/Migrate-PulseAudio#module-native-protocol-tcp
- name: copy pipewire-pulse service override
template:
src: 'templates/pipewire-pulse.j2'
dest: '{{ xdg_config_dir }}/systemd/user/pipewire-pulse.service.d/override.conf'
- name: copy pipewire-pulse script
template:
src: 'templates/{{ platform }}/pulse-script.j2'
dest: '{{ xdg_script_dir }}/pulse-script'
mode: 0755
- name: start pipewire socket
systemd:
@ -7,9 +26,13 @@
enabled: true
scope: user
- name: start pipewire-pulse socket
- name: restart pipewire-pulse
systemd:
name: pipewire-pulse.socket
state: started
enabled: true
name: '{{ item.name }}'
state: restarted
enabled: '{{ item.enabled }}'
scope: user
daemon-reload: true
loop:
- { name: 'pipewire-pulse.socket', enabled: true }
- { name: 'pipewire-pulse.service', enabled: false }

View file

@ -1,8 +1,9 @@
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
#
#!/usr/bin/nft -f
# vim:set ts=2 sw=2 et:
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0;
@ -26,6 +27,9 @@ table inet filter {
# syncthing
ip saddr 10.8.1.1 tcp dport 22000 accept
# allow remote pulse audio
ip saddr 10.8.1.1 tcp dport 4713 accept
# allow dhcp requests for bridget connections
iifname "vmbr0" udp dport { 53, 67 } accept

View file

@ -0,0 +1,5 @@
#!/usr/bin/sh
#
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
/usr/bin/pactl load-module module-native-protocol-tcp auth-anonymous=1 listen=10.8.1.10

View file

@ -0,0 +1,5 @@
#!/usr/bin/sh
#
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
/usr/bin/pactl load-module module-native-protocol-tcp auth-anonymous=1 listen=10.8.1.6

View file

@ -0,0 +1,8 @@
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
#
# see /usr/share/pipewire/pipewire-pulse.conf for reference
context.exec = [
{ path = "pactl" args = "module-native-protocol-tcp auth-anonymous=1 listen=10.8.1.6" }
]

View file

@ -1,44 +0,0 @@
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
music_directory "{{ mpd_music_dir }}"
playlist_directory "{{ mpd_playlist_dir }}"
state_file "{{ mpd_state_path }}"
sticker_file "{{ mpd_sticker_path }}"
log_level "secure"
bind_to_address "{{ mpd_listen_address }}"
port "{{ mpd_listen_port }}"
auto_update "yes"
filesystem_charset "UTF-8"
samplerate_converter "1"
database {
plugin "proxy"
host "{{ mpd_database_address }}"
port "{{ mpd_database_port }}"
}
audio_output {
type "pulse"
name "mpd"
replay_gain_handler "software"
mixer_type "hardware"
format "96000:24:1"
}
input {
enabled "no"
plugin "tidal"
}
input {
enabled "no"
plugin "qobuz"
}
decoder {
plugin "wildmidi"
enabled "no"
}

View file

@ -1,5 +0,0 @@
#!/bin/bash
#
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
sudo mount -t nfs -o vers=4,soft,async,proto=tcp,port=2049 10.8.0.1:/srv/nfs4/music {{ mpd_music_dir }}

View file

@ -1,14 +0,0 @@
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
[Unit]
Description=Music Player Daemon
Documentation=man:mpd(1) man:mpd.conf(5)
[Service]
Type=notify
ExecStartPre={{ xdg_script_dir }}/music_mount
ExecStart=/usr/bin/mpd --no-daemon {{ mpd_configuration_dir }}/mpd.conf
ExecStopPost={{ xdg_script_dir }}/music_umount
Restart=on-failure
RestartSec=15s
TimeoutStopSec=3

View file

@ -1,11 +0,0 @@
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
[Socket]
ListenStream=/run/user/1000/mpd.socket
ListenStream={{ mpd_listen_port }}
Backlog=5
KeepAlive=true
PassCredentials=true
[Install]
WantedBy=sockets.target

View file

@ -1,6 +1,4 @@
#!/bin/bash
#
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
pkill cantata
sudo umount {{ mpd_music_dir }}
[Service]
ExecStartPost={{ xdg_script_dir }}/pulse-script

View file

@ -1,4 +0,0 @@
# {{ ansible_managed }} {{ ansible_date_time.time }} {{ ansible_date_time.date }}
sonny ALL=(ALL) NOPASSWD: /usr/bin/mount
sonny ALL=(ALL) NOPASSWD: /usr/bin/umount