boatbod
Member
I have a headless ubuntu 16.04 machine running multiple instances of op25 and darkice that I use to send two streams to Broadcastify. It took me a while to figure just out how to get everything set up and able to auto-start itself at boot time. Here's what I did:
Set up ALSA loopback devices
Any streaming setup is going to require a way to take the audio from your application (op25) and deliver it to your streaming client (darkice). Since this is a headless server, I have no need to listen to the audio locally, therefore a simple alsa loopback is needed per stream.
First make sure the snd-aloop device with 2 separate substreams is loaded at boot time. This is hardware dependent, but if your system uses the hda-intel card you can use this script.
A Raspberry PI3 has different sound hardware and would require the following instead.
Next, set up the appropriate asound.conf to define loopback device names loop0 and loop1
Set up Darkice
Install the package.
Edit the basic configuration files to suit your server's password and mount point.
Set up OP25
Assuming you already have a working op25 installation, all you need to do is change the audio output device to match the appropriate ALSA loopback name.
Set up systemd auto startup at boot time
First create the service files to define which commands and/or scripts need to be run and what they depend on.
Once the files are created, enable them using the systemctl command.
Then either reboot, or start the services manually
Notes
1. The systemctl process will monitor both the darkice executable and op25-stream0.sh script and restart it if it fails. To properly stop either process, use the systemctl stop command.
If you want to permanently disable it from restarting after boot, use "systemctl disable"
2. You can add a second stream very easily by duplicating the darkice and systemd files (with appropriate renaming) and substituting "loop1" alsa device instead of "loop0".
3. I chose to use the http-based terminal type because it behaves nicely in a headless environment and can be accessed remotely across a network. Change the IP address in the op25 startup script accordingly.
Set up ALSA loopback devices
Any streaming setup is going to require a way to take the audio from your application (op25) and deliver it to your streaming client (darkice). Since this is a headless server, I have no need to listen to the audio locally, therefore a simple alsa loopback is needed per stream.
First make sure the snd-aloop device with 2 separate substreams is loaded at boot time. This is hardware dependent, but if your system uses the hda-intel card you can use this script.
Code:
[b]/etc/modprobe.d/hda-intel.conf[/b]
softdep snd-hda-intel post: snd-aloop
options snd-aloop enable=1 index=1 pcm_substreams=2
Code:
[b]/etc/modprobe.d/bcm2835.conf[/b]
softdep snd-bcm2835 post: snd-aloop
options snd-aloop enable=1 index=1 pcm_substreams=2
Next, set up the appropriate asound.conf to define loopback device names loop0 and loop1
Code:
[b]/etc/asound.conf[/b]
# output device
pcm.loopout0 {
type plug
slave.pcm "hw:Loopback,0,0"
}
# input device
pcm.loopin0 {
type dsnoop
ipc_key 686592
slave.pcm "hw:Loopback,1,0"
}
# duplex plug device
pcm.loop0 {
type plug
slave {
pcm {
type asym
playback.pcm "loopout0"
capture.pcm "loopin0"
}
}
}
# output device
pcm.loopout1 {
type plug
slave.pcm "hw:Loopback,0,1"
}
# input device
pcm.loopin1 {
type dsnoop
ipc_key 686593
slave.pcm "hw:Loopback,1,1"
}
# duplex plug device
pcm.loop1 {
type plug
slave {
pcm {
type asym
playback.pcm "loopout1"
capture.pcm "loopin1"
}
}
}
Set up Darkice
Install the package.
Code:
sudo apt-get install darkice
Code:
[b]/etc/darkice-stream0.cfg[/b]
# sample DarkIce configuration file, edit for your needs before using
# see the darkice.cfg man page for details
# this section describes general aspects of the live streaming session
[general]
duration = 0 # duration of encoding, in seconds. 0 means forever
bufferSecs = 1 # size of internal slip buffer, in seconds
reconnect = yes # reconnect to the server(s) if disconnected
# this section describes the audio input that will be streamed
[input]
device = loop0 # OSS DSP soundcard device for the audio input
sampleRate = 22050 # sample rate in Hz. 22050 is the RR Standard
bitsPerSample = 16 # bits per sample. 16 for mono feeds, 32 for stereo feeds
channel = 1 # channels. 1 = mono, 2 = stereo
# this section describes a streaming connection to an IceCast server
# there may be up to 8 of these sections, named [icecast-0] ... [icecast-7]
# these can be mixed with [icecast2-x] and [shoutcast-x] sections
# If you want to send to your own icecast server, you basically copy
# this whole section and put in the values to point the feed to your own
# server instead of the RR information below
# Don't forget, the name [icecast2-0] needs to change to [icecast2-1]
# and 2 and 3 as you add more feed destinations.
[icecast2-0]
# The audio format to encode to, we're using mp3 here
format = mp3
# The bit rate mode to use, the commented out lines are for a fixed bit
# rate "constant bit rate" at 16 bits. I prefer the variable bit rate
# for the sound quality it has and the throughput is very similar on avg
#bitrateMode = cbr (do not use vbr)
#bitrate = 16 or 32 (16 for mono feeds, 32 for stereo feeds)
sampleRate = 22050 # sample rate in Hz. 22050 is the RR Standard
bitrateMode = cbr
bitrate = 16
# Quality at .1, max is 1.0, but as you increase, so does the bandwidth
# used. For mono scanner audio .1 is totally fine.
quality = 0.1
# Takes the input and mixes it down to a mono output for the feed.
channel = 1
# Cuts frequency response over 5kHz. For scanner feed this mostly
# eliminates hiss and harshness on paging tones. Saves a bunch of
# bandwidth as well.
lowpass = 5000
# Server shown on your RR feed owner page that hosts your feed
# You need to log in to RR, go to Account -> My Live Audio Feeds ->
# click the feed owner page icon at the far right of your feed listing.
# Then you will see all this information.
# From Feed Technical Details, the "Server"
server = SERVER.broadcastify.com
# From Feed Technical Details, the "Port"
port = 80 # port of the IceCast server, usually 8000
# From Feed Technical Details, the Password exactly as shown
password = PASSWORD
# From Feed Technical Details, the mount...remove the leading "/", it's
# not needed in this file. So if it is /999999 make it just 999999
mountPoint = MOUNTPOINT
# name of the stream
# On My Live Audio Feeds, it's the first part ending in a colon ":"
name = Short name
# On My Live Audio Feeds, it's the part in parentheses in the Feed name
description = Description
# I don't think this is really needed because RR takes care of links
url = http://api.radioreference.com/js/?key=XXXXXXX&feedId=XXXX
genre = Scanner
public = yes
Set up OP25
Assuming you already have a working op25 installation, all you need to do is change the audio output device to match the appropriate ALSA loopback name.
Code:
[b]~/op25/op25/gr-op25_repeater/apps/op25-stream0.sh[/b]
./rx.py -l http:127.0.0.1:8080 --args "rtl=0" --gains 'lna:36' [b]-O loop0[/b] -D cqpsk -S 960000 -T trunk-fire.tsv -q 0 -d -200 -v 1 -2 -u 23456 -U 2> stderr-stream0.2
Set up systemd auto startup at boot time
First create the service files to define which commands and/or scripts need to be run and what they depend on.
Code:
[b]/etc/systemd/system/darkice-stream0.service[/b]
[Unit]
Description=darkice-stream0
After=syslog.target network.target nss-lookup.target network-online.target
Requires=network-online.target
[Service]
ExecStart=/usr/bin/darkice -c /etc/darkice-stream0.cfg
RestartSec=5
Restart=on-failure
[Install]
WantedBy=multi-user.target
Code:
[b]/etc/systemd/system/op25-stream0.service[/b]
[Unit]
Description=op25-fire
After=syslog.target network.target nss-lookup.target network-online.target
Requires=network-online.target
[Service]
User=[b]username[/b]
Group=[b]group[/b]
WorkingDirectory=/home/homedir/op25/op25/gr-op25_repeater/apps
ExecStart=/bin/bash -- op25-stream0.sh
RestartSec=5
Restart=on-failure
[Install]
WantedBy=multi-user.target
Once the files are created, enable them using the systemctl command.
Code:
systemctl enable darkice-stream0
systemctl enable op25-stream0
Code:
systemctl start darkice-stream0
systemctl start op25-stream0
Notes
1. The systemctl process will monitor both the darkice executable and op25-stream0.sh script and restart it if it fails. To properly stop either process, use the systemctl stop command.
Code:
systemctl stop op25-stream0
2. You can add a second stream very easily by duplicating the darkice and systemd files (with appropriate renaming) and substituting "loop1" alsa device instead of "loop0".
3. I chose to use the http-based terminal type because it behaves nicely in a headless environment and can be accessed remotely across a network. Change the IP address in the op25 startup script accordingly.