Skip to content

Commit

Permalink
multiroom: update snapcast to v0.22 and various improvements
Browse files Browse the repository at this point in the history
- Update snapcast to v0.22.0-r0
- Replace FIFO stream source with ALSA which significantly reduces CPU and I/O usage (fixes #294)
- Reduce multiroom-server image with multi stage builds for a slimmer image
- Reduce verbose level for both multiroom services

Connects-to: #294
Change-type: minor
Signed-off-by: Tomás Migone <tomas@balena.io>
  • Loading branch information
tmigone committed Nov 23, 2020
1 parent 2086ee6 commit 095b56c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/audio/balena-sound.pa
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Create balena-sound sinks
load-module module-null-sink sink_name=balena-sound.input
load-module module-null-sink sink_name=balena-sound.output
load-module module-pipe-sink file=/var/cache/snapcast/snapfifo sink_name=snapcast format=s16le rate=44100
load-module module-null-sink sink_name=snapcast

# Route audio internally, loopback sinks depend on configuration. See start.sh for details:
# balena-sound.input: For multiroom it's routed to snapcast sink, for standalone directly wired to balena-sound.output
Expand Down
8 changes: 5 additions & 3 deletions core/multiroom/client/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine:3.12
# Minimum snapcast version for ALSA stream source is v0.21
# Currently Alpine 3.12 is pinned to snapcast v0.19 so we need to use Alpine edge
FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine:edge
WORKDIR /usr/src

RUN install_packages snapcast-client

# Audio block setup
RUN curl --silent https://raw.githubusercontent.com/balenablocks/audio/master/scripts/alsa-bridge/alpine-setup.sh | sh
ENV PULSE_SERVER=tcp:audio:4317
ENV PULSE_SINK=balena-sound.output
RUN curl --silent https://raw.githubusercontent.com/balenablocks/audio/master/scripts/alsa-bridge/alpine-setup.sh | sh

WORKDIR /usr/src
COPY start.sh .

CMD [ "/bin/bash", "/usr/src/start.sh" ]
5 changes: 1 addition & 4 deletions core/multiroom/client/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ echo "Target snapcast server: $SNAPSERVER"

# Start snapclient
if [[ "$MODE" == "MULTI_ROOM" || "$MODE" == "MULTI_ROOM_CLIENT" ]]; then
# Start snapclient and filter out those pesky chunk logs
# grep filter can be removed when we get snapcast v0.20
# see: https://github.com/badaix/snapcast/issues/559#issuecomment-615874719
/usr/bin/snapclient --host $SNAPSERVER $LATENCY | grep -v "\[Info\] (Stream) Chunk"
/usr/bin/snapclient --host $SNAPSERVER $LATENCY --logfilter *:notice
else
echo "Multi-room client disabled. Exiting..."
exit 0
Expand Down
28 changes: 23 additions & 5 deletions core/multiroom/server/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine:3.12
# Build snapweb separately
FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine-node:latest as web-builder
WORKDIR /usr/src

RUN install_packages git make npm

RUN git clone https://github.com/badaix/snapweb.git snapweb
RUN npm install --global --no-save typescript
RUN cd snapweb && make

# Minimum snapcast version for ALSA stream source is v0.21
# Currently Alpine 3.12 is pinned to snapcast v0.19 so we need to use Alpine edge
FROM balenalib/%%BALENA_MACHINE_NAME%%-alpine:edge
WORKDIR /usr/src

RUN install_packages snapcast-server git make npm
# Install snapweb
RUN mkdir -p /var/www
COPY --from=web-builder /usr/src/snapweb/dist/* /var/www/

# Install snapcast
RUN install_packages snapcast-server
COPY snapserver.conf /etc/snapserver.conf
COPY start.sh .
RUN git clone https://github.com/badaix/snapweb.git snapweb
RUN npm install --global --no-save typescript
RUN cd snapweb && make && mkdir -p /var/www && mv dist/* /var/www

# Audio block setup
ENV PULSE_SERVER=tcp:audio:4317
ENV PULSE_SOURCE=snapcast.monitor
RUN curl --silent https://raw.githubusercontent.com/balenablocks/audio/master/scripts/alsa-bridge/alpine-setup.sh| sh

CMD [ "/bin/bash", "/usr/src/start.sh" ]
4 changes: 3 additions & 1 deletion core/multiroom/server/snapserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ port = 1780
doc_root = /var/www/

[stream]
stream = pipe:///var/cache/snapcast/snapfifo?name=balenaSound
stream = alsa://?name=balenaSoundAlsa&device=pulse
sampleformat = 44100:16:2

[logging]
filter = *:notice

0 comments on commit 095b56c

Please sign in to comment.