Skip to content

Instantly share code, notes, and snippets.

@fredoche
Forked from joleuger/README_audioclient.md
Last active August 29, 2015 14:19
Show Gist options
  • Save fredoche/d097b4ff5b93642cffc2 to your computer and use it in GitHub Desktop.
Save fredoche/d097b4ff5b93642cffc2 to your computer and use it in GitHub Desktop.

Add user audioserver

Add user to group bluetooth

> usermod -a -G audioserver bluetooth
> udevadm control --reload
> udevadm trigger

Reason: The file /etc/dbus-1/system.d/bluetooth.conf requires it.

Quote:

  <!-- allow users of bluetooth group to communicate with hcid -->
  <policy group="bluetooth">
    <allow send_destination="org.bluez"/>
  </policy>

Add to file default-script-file = /home/audioserver/.config/pulse/default.pa

/home/audioserver/.config/pulse/daemon.conf

Add to file /home/audioserver/.config/pulse/default.pa

load-module module-native-protocol-unix # (must be enabled)
# load-module module-suspend-on-idle (must be disabled)
load-module module-null-sink rate=44100 channels=2 sink_name=broadcast_on_all_speakers
set-default-sink broadcast_on_lan
## And disable everything not needed

Add services below to /home/audioserver/.config/systemd/user/ Don't forget to edit $$$ipaddress$$$

Enable services. Login as audioserver. Be sure systemd.pam is used. su audioserver does not use this file and thus circumvents logind and envirnoment variables are not set. Perhaps by using ssh.

> loginctl enable-linger audioserver
> mkdir /home/audioserver/.ssh
> cat /root/.ssh/id_rsa.pub >> /home/audioserver/.ssh/authorized_keys
> chown -R audioserver:audioserver /home/audioserver/.config
> ssh -l audioserver localhost
> systemctl --user enable dbus.socket
> systemctl --user enable audioserver_pulseaudio.service
> systemctl --user enable audioserver_mopidy.service
> systemctl --user enable audioserver_shairport.service
> systemctl --user enable audioserver_gstreamer.service
> systemctl --user start audioserver_pulseaudio.service
> systemctl --user start audioserver_mopidy.service
> systemctl --user start audioserver_shairport.service
> systemctl --user start audioserver_gstreamer.service
> systemctl --user status
> exit
> journalctl /usr/bin/pulseaudio
> journalctl --user-unit audioserver_pulseaudio.service

For now DBus (see https://wiki.archlinux.org/index.php/Systemd/User#D-Bus):

> go get github.com/godbus/dbus
> export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus
> printenv
> qdbus org.PulseAudio1 /org/pulseaudio/server_lookup1 org.PulseAudio.ServerLookup1.Address
> qdbus --address unix:path=/run/user/1002/pulse/dbus-socket
> qdbus
Install Icecast
> apt-get install icecast2
Web-View
http://$$$ipaddress$$$:8000/
> ffmpeg -f lavfi -i aevalsrc=0 -t 5 /usr/share/icecast2/web/silence.mp3

Config of /etc/icecast2/icecast.xml 
       <source-password>$$$changeme$$$</source-password>
    <relays-on-demand>1</relays-on-demand>
    <relay>
        <server>mp3ad.egofm.c.nmdn.net</server>
        <port>80</port>
        <mount>/ps-egofm_192/livestream.mp3</mount>
        <local-mount>/egofm.mp3</local-mount>
        <on-demand>1</on-demand>

        <relay-shoutcast-metadata>1</relay-shoutcast-metadata>
    </relay>
    
    <mount>
        <mount-name>/broadcast_on_lan.mp3</mount-name>
        <fallback-mount>/silence.mp3</fallback-mount>
        <fallback-override>1</fallback-override>
    </mount>
    <mount>
        <mount-name>/mopidy.mp3</mount-name>
        <fallback-mount>/silence.mp3</fallback-mount>
        <fallback-override>1</fallback-override>
    </mount>
    
> apt-get install gstreamer1.0-plugins-ugly lame gstreamer1.0-plugins-good

##TODO

[Unit]
Description=pulseaudio audioserver, soundclient gstreamer
Requires=audioserver_pulseaudio.service
[Service]
Type=simple
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus
Environment=PULSE_CONFIG=/home/audioserver/.config/pulse/daemon.conf
ExecStartPre=/bin/sleep 3
ExecStart=/usr/bin/gst-launch-1.0 pulsesrc device=broadcast_on_lan.monitor ! audioconvert ! lamemp3enc target=1 bitrate=256 cbr=true ! shout2send ip=127.0.0.1 port=8000 password=PASSWORD mount=broadcast_on_lan.mp3
[Install]
WantedBy=default.target
# See http://hstuart.dk/2010/11/07/gstreamer-and-pulseaudio-to-a-squeezebox/
[Unit]
Description=pulseaudio audioserver, soundclient mopidy
Requires=audioserver_pulseaudio.service
[Service]
Type=simple
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus
Environment=PULSE_CONFIG=/home/audioserver/.config/pulse/daemon.conf
ExecStartPre=/bin/sleep 3
ExecStart=/usr/local/bin/mopidy
[Install]
WantedBy=default.target
[Unit]
Description=pulseaudio audioserver
Requires=dbus.socket
[Service]
Type=dbus
BusName=org.PulseAudio1
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus
Environment=PULSE_CONFIG=/home/audioserver/.config/pulse/daemon.conf
ExecStart=/usr/bin/pulseaudio -vv
[Install]
WantedBy=default.target
[Unit]
Description=pulseaudio audioserver, sound receiver for airplay requests
Requires=audioserver_pulseaudio.service
[Service]
Type=simple
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus
Environment=PULSE_CONFIG=/home/audioserver/.config/pulse/daemon.conf
ExecStartPre=/bin/sleep 3
ExecStart=/usr/local/bin/shairport --name Broadcast --output pulse -- -s broadcast_on_lan -n AirPlay
[Install]
WantedBy=default.target
[Unit]
Description=pulseaudio audioserver, soundclient vlc
Requires=audioserver_pulseaudio.service
[Service]
Type=simple
Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus
Environment=PULSE_CONFIG=/home/audioserver/.config/pulse/daemon.conf
ExecStartPre=/bin/sleep 3
ExecStart=/usr/bin/cvlc pulse://broadcast_on_lan.monitor --http-port=5003 --sout-vorbis-quality=9 --sout '#transcode{acodec=vorb,aenc=vorbis}:standard{access=http,mux=ogg,dst=$$$ipaddress$$$:5003/broadcast_on_lan}' -vvv
#Alternatives:
#ExecStart=/usr/bin/cvlc pulse://broadcast_on_lan.monitor --http-port=5003 --sout '#transcode{acodec=mp3,ab=256}:rtp{dst=224.1.1.1,port=5000,sdp=http://$$$ipaddress$$$:5003/broadcast_on_lan.sdp}'
#ExecStart=/usr/bin/cvlc pulse://broadcast_on_lan.monitor --http-port=5003 --sout-vorbis-quality=9 --sout '#transcode{acodec=vorb,aenc=vorbis}:standard{access=http,mux=ogg,dst=$$$ipaddress$$$:5003/broadcast_on_lan}' -vvv
#Vlc audioserver client
#ExecStart=/usr/bin/vlc -vvv http://$$$ipaddress$$$:5003/broadcast_on_lan.sdp
#ExecStart=/usr/bin/vlc -vvv http://$$$ipaddress$$$:5003/broadcast_on_lan
[Install]
WantedBy=default.target
[Unit]
Description=D-Bus User Message Bus
Documentation=man:dbus-daemon(1)
Requires=dbus.socket
[Service]
ExecStart=/usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation
ExecReload=/usr/bin/dbus-send --print-reply --session --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
[Install]
Also=dbus.socket
[Unit]
Description=D-Bus User Message Bus Socket
[Socket]
ListenStream=%t/bus
[Install]
WantedBy=sockets.target
Also=dbus.service
#EXTM3U
http://$$$IP-ADDRESS$$$:8000/egofm.mp3
#EXTM3U
http://$$$IP-ADDRESS$$$:8000/broadcast_on_lan.mp3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment