Here's a different approach that works well for me. Asterisk has a built in Limit feature you can use from the dialplan suring the dial command:
L(x[:y][:z]): Limit the call to 'x' ms, warning when 'y' ms are left, repeated every 'z' ms) Only 'x' is required, 'y' and 'z' are optional. The following special variables are optional for limit calls: (from app_dial.c)
* LIMIT_PLAYAUDIO_CALLER - yes|no (default yes) - Play sounds to the caller.
* LIMIT_PLAYAUDIO_CALLEE - yes|no - Play sounds to the callee.
* LIMIT_TIMEOUT_FILE - File to play when time is up.
* LIMIT_CONNECT_FILE - File to play when call begins.
* LIMIT_WARNING_FILE - File to play as warning if 'y' is defined. If LIMIT_WARNING_FILE is not defined, then the default behaviour is to announce ("You have [XX minutes] YY seconds").
And example would be:
exten => 960,2,dial(SIP/960|55|L(1800000:60000:30000))
This example would call SIP extension 960 (and wait 55 seconds for an answer). If answered would limit the call to 30 minutes, telling the called party when there's 1 minute left for the call. To do it without the announcement it would be:
exten => 960,2,dial(SIP/960|55|L(1800000))
Since Limit uses ms, 30 minutes was converted to 1800000 ms.