When moh audio stream ends; never recovers

I don’t know whether the issue is with mplayer, or with asterisk. I have the following in pjsip.conf:

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0

[siptrunk-auth]
type=auth
auth_type=userpass
username=mysipusername
password=mysippassword

[siptrunk-aor]
type=aor
contact=sip:voip.provider.com
[siptrunk]
type=endpoint
transport=transport-udp
context=from-siptrunk
disallow=all
allow=ulaw
outbound_auth=siptrunk-auth
aors=siptrunk-aor

[siptrunk-registration]
type=registration
transport=transport-udp
outbound_auth=siptrunk-auth
server_uri=sip:voip.provider.com
client_uri=sip:mysipusername@voip.provider.com
contact_user=inbound-calls
retry_interval=60

[siptrunk-identify]
type=identify
match=voip.provider.com
endpoint=siptrunk

And in extensions.conf:

[from-siptrunk]
exten => inbound-calls,1,Verbose(1,Playing some music.)
same => n,Answer
same => n,MusicOnHold(ulawstream)
same => n,Hangup()

In musiconhold.conf

[ulawstream]
mode=custom
application=/usr/sbin/moh.sh

And in /usr/sbin/moh.sh:

#!/bin/bash

if -n "`ls /tmp/asterisk-moh-pipe.*`" ; then
rm /tmp/asterisk-moh-pipe.*
fi

PIPE="/tmp/asterisk-moh-pipe.$"
mknod $PIPE p

/usr/sbin/mplayer https://my.icecastserver.com/live.mp3 -really-quiet -quiet -ao pcm:file$
rm $PIPE

I have a livestream going to an icecast server. I cannot hear audio in asterisk with any other method. But the problem is, when the livestream ends, I cannot get moh hold to play audio again unless I stop asterisk, uninstall mplayer, reinstall mplayer, then start asterisk again. Then I can start the livestream again and can hear audio. But sometimes that doesn’t work and I give up, try again, and then it will work.

In the console, it always says " Playing some music." whether or not it’s playing audio. Debug on and verbose increased doesn’t show anything wrong when it’s not playing.

I ended up giving up on this method, and used this instead:

sudo apt install madplay
sudo mkdir /var/lib/asterisk/mohmp3-empty
sudo touch /var/lib/asterisk/mohmp3-empty/moh.mp3
cd /etc/asterisk
sudo nano mohstream.sh

In mohstream.sh:

#!/bin/bash
/usr/bin/wget -q -O - https://my.icecastserver.com/live.mp3 | /usr/bin/madplay -Q -z -o raw:- --mono -R 8000 -a -12 -

Save and exit nano.
sudo chmod a+x mohstream.sh

In musiconhold.conf

[ulawstream]
mode=custom
dir=/var/lib/asterisk/mohmp3-empty
application=/etc/asterisk/mohstream.sh

sudo systemctl restart asterisk

Now, when I call in and am listening to moh, and I stop the stream, and in the asterisk console (sudo asterisk -rvv) I get the warning: res_musiconhold.c:809 monmp3thread: poll() failed: Interrupted system call when the stream is stopped… but it ends up being fine. I can start the stream again, and I can resume listening.

If you want to check to see if the script is running, you can do ps aux and the script should be in the list of things running.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.