[solved] Asterisks locks alsa device if chan_alsa is loaded

I am implementing an extension 900 which routes the audio to alsa device. I am also using mpd which plays music through alsa.

Asterisk 15, Openwrt 18.06

mpd.conf

 cat /etc/mpd.conf 
log_file "syslog"

bind_to_address "127.0.0.1"
bind_to_address "192.168.1.18"

input {
    plugin          "curl"
}

audio_output {
    type            "alsa"
    name		    "sun4icodec"
    device          "hw:0,0"
    mixer_control   "Power Amplifier"
}

Here is the section of extensions.conf related to the extension


;SIP 900
exten => 900,1,NoOp(Testing calls to speakers. Dialing ${EXTEN} from ${CALLERID})
same => n,System(kill -9 `pgrep mpg123`)
same => n,System(amixer set 'Power Amplifier' 80%)
same => n,System(/usr/bin/aplay /var/lib/myapp/sounds/tone3.wav &)
same => n,System(sleep(4))
same => n,NoOp(Testing calls to speakers. Dialing ${EXTEN} from ${CALLERID})
same => n,Dial(CONSOLE/ALSA)
same => n,Hangup()
same => n,System(sleep(1))
same => n,System(amixer set 'Power Amplifier' 80%;)
same => n,System(sleep(4))

When chan_alsa is loaded it locks the alsa device and when something is played on mpd I get the following error

aplay: main:722: audio open error: Resource busy

I came across this on a website https://www.voip-info.org/asterisk-config-alsaconf/ but I am not sure how to implement this. Can please guide me how to solve this.. twiddle software and/or hardware mixing

  • output_device = <ALSA device name>
    Indicates the name of the ALSA device to use for playing sound, i.e. for listening. A device name specified here is passed, unchanged, to the ALSA sound layer, so any ALSA device name should work. Warning : Asterisk may lock the ALSA device specified here for the entire duration the Asterisk process is running. You may have to twiddle software and/or hardware mixing settings to keep Asterisk from hogging your output device.

Solved by using alsa's dmix plugin. Instead of accessing the sound card hw:0,0 directly all the applications must access it via the dmix plugin.

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