[asterisk-users] AGI: blocking script until playback complete

Steve Edwards asterisk.org at sedwards.com
Wed Feb 22 15:13:01 CST 2012


On Wed, 22 Feb 2012, Chris Bagnall wrote:

> However, today I have a scenario where I want the script to remain 
> running during the playback of a file so that I can read DTMF at the end 
> of playback.

If by 'remain running' you mean 'do other stuff while the file is playing' 
you can stream the file in a separate thread while continuing with the 
'mainline' code.

If you mean your script is returning to the dialplan before the file is 
finished playing, you're doing something wrong.

> However, doing this:
>
> GET DATA en_welcome 5000 6
>
> Results (correctly) in the following in the asterisk console:
>    -- <SIP/a.b.c.d-dc027b50> Playing 'en_welcome' (language 'en')
>
> But the AGI continues to run on after this point, not waiting for either 
> the sound file to be played, nor for the expected 6 DTMF digits.
>
> Adding a simple 10 second sleep/wait to the AGI allows the sound file to 
> be successfully played back.

Sure sounds like you are doing something wrong. Anytime a 'sleep' helps, 
something is definitely wrong.

Most AGI 'weirdness' can be traced to violating the AGI protocol. These 
are the most common mistakes:

0) Not using an established library. Nobody gets it right the first time 
:)

1) Not reading the AGI environment from STDIN before issuing any AGI 
requests.

2) Forgetting that every request must be followed by reading the response.

3) Doing any I/O on STDIN or STDOUT. These channels are connected to 
Asterisk, not any console. Don't even think about popping in a quick 
'debugging printf.'

Looking over my own AGI code, I don't see any examples where I used GET 
DATA. I tend to use STREAM FILE and WAIT FOR DIGIT. I'm a 1.2 Luddite, so 
any bugs I've been exposed to may have been fixed by now.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list