Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support pulseaudio in raspberrypi #141

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dist-scripts/debian/gmrender-resurrect-pre.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=gmrender-resurrect-pre service
Before=gmrender-resurrect.service

[Service]
Type=oneshot
User=pi
Group=audio

ExecStart=/bin/sh -c "touch /tmp/gmrender-resurrect.vars"

[Install]
WantedBy=multi-user.target
18 changes: 15 additions & 3 deletions dist-scripts/debian/gmrender-resurrect.default
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DAEMON_USER="nobody:audio"
# controller UI. Some string that helps you recognize the player, e.g.
# "Livingroom Player"
# Default is the short hostname of this device
UPNP_DEVICE_NAME=`hostname -s`
UPNP_DEVICE_NAME="$HOSTNAME"

# Initial volume in decibel. 0.0 is 'full volume', -10 correspondents to
# '75' on the exported volume scale (Note, this does not change the ALSA
Expand All @@ -25,17 +25,29 @@ INITIAL_VOLUME_DB=-10
# 'aplay -L'), then gmediarenderer will use that ALSA device to play
# audio. Otherwise, whatever default is configured for gstreamer for the
# '$DAEMON_USER' is used.
ALSA_DEVICE="sysdefault"
RET=`dpkg -l pulseaudio`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you are making the choice of pulseaudio vs. Alsa dependent on the existence of a particular packet, which sounds like it will result in non-repeatable results: if accidentally a pulseaudio package is installed, suddenly the way gmrender works is changing, which can make things surprising.

So I suggest to rather have this as a variable at the top (USE_PULSEAUDIO=1 or something).

if [ $? -eq 0 ] ; then
PULSEAUDIO_DEVICE=`aplay -l|awk '/^card 0/ {print $3}'`
else
ALSA_DEVICE="sysdefault"
fi

#ALSA_DEVICE="iec958"
LOG_PATH='/var/log/gmediarender.log'
[ ! -f "$LOG_PATH" ] && touch /var/log/gmediarender.log && chown pi $LOG_PATH

if [ -n "$ALSA_DEVICE" ] ; then
if [ -n "$PULSEAUDIO_DEVICE" ] ; then
GS_SINK_PARAM="--gstout-audiosink=autoaudiosink"
GS_DEVICE_PARAM="--gstout-audiodevice=$PULSEAUDIO_DEVICE"
elif [ -n "$ALSA_DEVICE" ] ; then
GS_SINK_PARAM="--gstout-audiosink=alsasink"
GS_DEVICE_PARAM="--gstout-audiodevice=$ALSA_DEVICE"
fi

# A simple stable UUID, based on this systems' first ethernet
# device's MAC address, only using tools readily available to generate.
UPNP_UUID=`ip link show | awk '/ether/ {print "salt:)-" $2}' | head -1 | md5sum | awk '{print $1}'`
LOG="--logfile=$LOG_PATH"

# Alternatively use the MD5 summ of the short host name.
# UPNP_UUID=`hostname -s | md5sum | | awk '{print $1}'`
14 changes: 11 additions & 3 deletions dist-scripts/debian/gmrender-resurrect.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ Description=gmrender-resurrect service
After=network.target sound.target

[Service]
Environment="UPNP_DEVICE_NAME=Raspberry"
ExecStartPre=/bin/sh -c "/bin/systemctl set-environment UPNP_UUID=`ip link show | awk '/ether/ {print \"salt:)-\" $2}' | head -1 | md5sum | awk '{print $1}'`"
User=pi
Group=audio
Environment="GS_SINK_PARAM=autoaudiosink"

ExecStartPre=/bin/sh -c "/usr/bin/test -f '/tmp/gmrender-resurrect.vars' || /bin/rm /tmp/gmrender-resurrect.vars"
ExecStartPre=/bin/sh -c "echo UPNP_DEVICE_NAME=`/bin/hostname` > /tmp/gmrender-resurrect.vars"
ExecStartPre=/bin/sh -c "echo UPNP_UUID=`ip link show | awk '/ether/ {print \"salt:)-\" $2}' | head -1 | md5sum | awk '{print $1}'` >> /tmp/gmrender-resurrect.vars"
ExecStartPre=/bin/sh -c "pulseaudio --version ||echo GS_SINK_PARAM=alsasink >>/tmp/gmrender-resurrect.vars"
ExecStartPre=/bin/sh -c "echo GS_DEVICE_PARAM=`aplay -l|awk '/^card 0/ {print $3}'` >>/tmp/gmrender-resurrect.vars"

EnvironmentFile=/tmp/gmrender-resurrect.vars
ExecStart=/usr/local/bin/gmediarender -f "$UPNP_DEVICE_NAME" -u "$UPNP_UUID" \
--gstout-audiosink=alsasink --gstout-audiodevice=sysdefault \
--gstout-audiosink=${GS_SINK_PARAM} --gstout-audiodevice=${GS_DEVICE_PARAM} \
--logfile=/tmp/gmediarenderer.log --gstout-initial-volume-db=-10
Restart=always

Expand Down
1 change: 1 addition & 0 deletions dist-scripts/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export DEB_BUILD_HARDENING=1
override_dh_auto_configure:
./autogen.sh
dh_auto_configure --
touch /tmp/gmrender-resurrect.vars

override_dh_auto_clean:
if [ -e ./Makefile ]; then make maintainer-clean; fi
Expand Down
20 changes: 16 additions & 4 deletions scripts/init.d/gmediarenderer
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DAEMON_USER="pi:audio"

# Device name as it will be advertised to and shown in the UPnP controller UI.
# Some string that helps you recognize the player, e.g. "Livingroom Player"
UPNP_DEVICE_NAME="Raspberry"
UPNP_DEVICE_NAME=`hostname`

# Initial volume in decibel. 0.0 is 'full volume', -10 correspondents to '75' on
# the exported volume scale (Note, this does not change the ALSA volume, only
Expand All @@ -27,28 +27,40 @@ INITIAL_VOLUME_DB=-10
# gmediarenderer will use that ALSA device to play audio.
# Otherwise, whatever default is configured for gstreamer for the '$DAEMON_USER' is
# used.
ALSA_DEVICE="sysdefault"
#ALSA_DEVICE="iec958"
RET=`dpkg -l pulseaudio`
if [ $? -eq 0 ] ; then
PULSEAUDIO_DEVICE=`aplay -l|awk '/^card 0/ {print $3}'`
else
ALSA_DEVICE="sysdefault"
fi

# Path to the gmediarender binary.
BINARY_PATH=/usr/local/bin/gmediarender

if [ -n "$ALSA_DEVICE" ] ; then
LOG_PATH='/var/log/gmediarender.log'
[ ! -f "$LOG_PATH" ] && touch /var/log/gmediarender.log && chown pi $LOG_PATH

if [ -n "$PULSEAUDIO_DEVICE" ] ; then
GS_SINK_PARAM="--gstout-audiosink=autoaudiosink"
GS_DEVICE_PARAM="--gstout-audiodevice=$PULSEAUDIO_DEVICE"
elif [ -n "$ALSA_DEVICE" ] ; then
GS_SINK_PARAM="--gstout-audiosink=alsasink"
GS_DEVICE_PARAM="--gstout-audiodevice=$ALSA_DEVICE"
fi

# A simple stable UUID, based on this systems' first ethernet devices MAC address,
# only using tools readily available to generate.
UPNP_UUID=`ip link show | awk '/ether/ {print "salt:)-" $2}' | head -1 | md5sum | awk '{print $1}'`
LOG="--logfile=$LOG_PATH"

USER=root
HOME=/root
export USER HOME
case "$1" in
start)
echo "Starting GMediaRender"
start-stop-daemon -x $BINARY_PATH -c "$DAEMON_USER" -S -- -f "$UPNP_DEVICE_NAME" -d -u "$UPNP_UUID" $GS_SINK_PARAM $GS_DEVICE_PARAM --gstout-initial-volume-db=$INITIAL_VOLUME_DB
start-stop-daemon -x $BINARY_PATH -c "$DAEMON_USER" -S -- -f "$UPNP_DEVICE_NAME" -d -u "$UPNP_UUID" $GS_SINK_PARAM $GS_DEVICE_PARAM --gstout-initial-volume-db=$INITIAL_VOLUME_DB $LOG
;;

stop)
Expand Down
7 changes: 7 additions & 0 deletions scripts/logrotate.d/gmediarender
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/var/log/gmediarender.log {
rotate 2
weekly
compress
missingok
notifempty
}