> Launching Playback(silence/1&tt-weasels) on Local/201@devices-ecf0;1
\end{verbatim}
\end{astlisting}
We then start playing back the files.
\begin{astlisting}
\begin{verbatim}
-- <Local/201@devices-ecf0;1> Playing 'silence/1.slin' (language 'en')
== Spawn extension (devices, 201, 4) exited non-zero on 'Local/201@devices-ecf0;2'
\end{verbatim}
\end{astlisting}
At this point we now see the Local channel has been optimized out of the call
path. This is important as we'll see in examples later. By default, the Local
channel will try to optimize itself out of the call path as soon as it can. Now
that the call has been established and audio is flowing, it gets out of the way.
\begin{astlisting}
\begin{verbatim}
-- <SIP/0004f2040001-00000022> Playing 'tt-weasels.ulaw' (language 'en')
[Mar 1 13:35:23] NOTICE[16814]: pbx_spool.c:349 attempt_thread: Call completed to Local/201@devices
\end{verbatim}
\end{astlisting}
We can now see the tt-weasels file is played directly to the destination
(instead of through the Local channel which was optimized out of the call path)
and then a NOTICE stating the call was completed.
\subsection{Understanding When To Use /n}
By default, the Local channel will try to optimize itself out of the call path.
This means that once the Local channel has established the call between the
destination and Asterisk, the Local channel will get out of the way and let
Asterisk and the end point talk directly, instead of flowing through the Local
channel.
This can have some adverse effects when you're expecting information to be
available during the call that gets associated with the Local channel. When the
Local channel is optimized out of the call path, any Dial() flags, or channel
variables associated with the Local channel are also destroyed and are no longer
available to Asterisk.
We can force the Local channel to remain in the call path by utilizing the /n
directive. By adding /n to the end of the channel definition, we can keep the
Local channel in the call path, along with any channel variables, or other
channel specific information.
For example, if we were calling a Local channel from the Dial() application, we
could change:
\begin{verbatim}
Dial(Local/201@devices)
\end{verbatim}
...into the following line:
\begin{verbatim}
Dial(Local/201@devices/n)
\end{verbatim}
By adding /n to the end, our Local channel will now stay in the call path and
not go away.
Lets take a look at an example that demonstrates when the use of the /n
directive is necessary. If we spawn a Local channel which then performs another
Dial() to a SIP channel, but we use the L() option (which is used to limit the
amount of time a call can be active, along with warning tones when the time is
nearly up), it will be associated with the Local channel, which is then
optimized out of the call path, and thus won't perform as expected.
Here is an overview of our call flow, and the information associated with the
channels:
\begin{enumerate}
\item SIP device PHONE\_A calls Asterisk via a SIP INVITE
\item Asterisk accepts the INVITE and then starts processing dialplan logic
\item Our dialplan calls Dial(Local/2@services) -- notice no /n
\item The Local channel then executes dialplan at extension 2 within the services context
\item Extension 2 within [services] then performs another Dial() to a SIP channel with the line: Dial(SIP/PHONE\_B,,L(60000:450000:15000))
\item The call is then placed to SIP/PHONE\_B which then answers the call.
\item The Local channel containing the information for tracking the time allowance of the call is then optimized out of the call path, losing all information about when to terminate the call.
\item SIP/PHONE\_A and SIP/PHONE\_B then continue talking indefinitely.
\end{enumerate}
Now, if we were to modify our dialplan at step three (3) then we would force the
Local channel to stay in the call path, and the L() option associated with the
Dial() from the Local channel would remain, and our warning sounds and timing
would work as expected.
There are two workarounds for the above described scenario:
\begin{enumerate}
\item Use Dial(Local/2@services/n) to cause the Local channel to remain in the call
path so that the L() option used inside the Local channel is not discarded
when optimization is performed.
\item Place the L() option outside of the Local channel so that when it is
optimized out of the call path, the information required to make L() work is
associated with the outside channel. For example:
\begin{verbatim}
Dial(Local/2@services,,L(60000:45000:15000))
\end{verbatim}
\end{enumerate}
\subsection{Local channel modifiers}
There are additional modifiers for the Local channel as well. They include:
\begin{itemize}
\item 'n' -- Adding "/n" at the end of the string will make the Local channel not
do a native transfer (the "n" stands for "n"o release) upon the remote
end answering the line. This is an esoteric, but important feature if
you expect the Local channel to handle calls exactly like a normal
channel. If you do not have the "no release" feature set, then as soon
as the destination (inside of the Local channel) answers the line and
one audio frame passes, the variables and dial plan will revert back
to that of the original call, and the Local channel will become a
zombie and be removed from the active channels list. This is desirable
in some circumstances, but can result in unexpected dialplan behavior
if you are doing fancy things with variables in your call handling.
\item 'j' -- Adding "/j" at the end of the string allows you to use the generic
jitterbuffer on incoming calls going to Asterisk applications. For
example, this would allow you to use a jitterbuffer for an incoming
SIP call to Voicemail by putting a Local channel in the middle. The
'j' option must be used in conjunction with the 'n' option to make
sure that the Local channel does not get optimized out of the call.
This option is available starting in the Asterisk 1.6.0 branch.
\item 'm' -- Using the "/m" option will cause the Local channel to forward music on
hold (MoH) start and stop requests. Normally the Local channel acts on
them and it is started or stopped on the Local channel itself. This
options allows those requests to be forwarded through the Local
channel.
This option is available starting in the Asterisk 1.4 branch.
\item 'b' -- The "/b" option causes the Local channel to return the actual channel
that is behind it when queried. This is useful for transfer scenarios
as the actual channel will be transferred, not the Local channel.
This option is available starting in the Asterisk 1.6.0 branch.