Open Source - G.729 encoder & decoder usage explanation
Question:
Why do I have X number of concurrent calls but I'm using M/N encoders/decoders (where M,N > X)?
Answer:
It's more complicated than simply one concurrent call equals 1/1 encoder/decoder. The number of G.729 channels used can be better thought as the number of "legs" or channels of a call which require transcoding. One "leg" is say from Asterisk to an ITSP ('$Provider'), or from Asterisk to internal VoIP endpoint ('$Voip1'). If $Provider requires G.729, and $Voip1 cannot speak G.729, then Asterisk must transcode from G.729 to one of $Voip1's allowed codecs. This simple case will use one encoder/decoder to transcode to and from G.729, for the entire duration of the call (unless another codec is renegotiated, for 1/1 encoders/decoders for that channel).
Let's consider another example, using the systems defined above. Let '$External1' be an external caller, whose call to $Voip2 is recorded. First, $External1 calls $Voip2 through $Provider. Remember the leg from $Provider to Asterisk will require G.729, and Asterisk plays back IVR sounds (which by default are not in the G.729 format). This requires transcoding--actually one encoder will be used for playing back these recordings (1/0 encoders/decoders for this channel). When $External1 connects with $Voip2, the recording function begins (e.g. by using MixMonitor). Let this recording endpoint be called '$Recording1.' Since $Voip2 cannot speak G.729, there is transcoding between $Voip2 and Asterisk (for the $Voip2<->$External1 path), plus there is transcoding for the Asterisk->$Recording1 leg. The Asterisk->$Recording1 leg will only use a decoder, but the codec driver does not have a concept of half usage, so one extra channel will be consumed. Therefore, there are 2/1 encoders/decoders in use for this call. If any subsequent callers (e.g. $External2 ... $ExternalN) call in and navigate the IVR, each call navigating the IVR will use one encoder due to the transcoding of recorded files into G.729. If they should call to any $VoipN which cannot use G.729, another 1/1 encoders/decoders will be used for the main bridging, plus any extra decoders for recorded calls.
Asterisk by default chooses the most appropriate format when selecting a file for playback. If the format for a given call leg is G.729, and playback is requested, as seen in the example above transcoding will occur when the file is played back. This only applies if there are no .g729 format files available for the particular sound that needs to be played. The best way to install the .g729 versions of the core sounds is to select that format in "make menuselect" when compiling Asterisk. Alternatively, you may download the G.729 versions of the core Asterisk sounds from http://downloads.asterisk.org/pub/telephony/sounds/. If that is not an option, another way around this is by using the "file convert" utility to convert the sound files from one format into G.729. This is useful if for whatever reason your Asterisk distribution did not provide .g729 format sound files, the source that was used for your version is not readily available, or if network policy prohibits the transfer of files to your Asterisk system either directly or indirectly.
The files can be created by issuing the following command in the Asterisk CLI:
file convert source.fmt source.g729
Where "fmt" in this case is the source format of the file. We strongly encourage you to use .wav as the source format, as that is not compressed. Converting from another lossy compressed format to g729 could have adverse effects on the quality of the audio in the resulting files.
Summary:
The number of encoders/decoders of G.729 in use depends on the number of channels (or "legs") of a call requiring transcoding to or from G.729. In the case of IVR playback, if no .g729 format files are found in the sounds directory, Asterisk will have to use codec_g729a to transcode the file from the sounds' formats to G.729. This will use an encoder for each file played simultaneously (1/0 encoders/decoders per channel). If a channel is being recorded, another channel of G.729 will be used to transcode from G.729 to the target format, and this will use one decoder (0/1 encoders/decoders per channel). Transcoding can be avoided in both cases if sound files are recorded in the .g729 format.
Note: If you have two bridged calls (for 2/2 encoders/decoders), and three callers navigating an IVR which will require transcoding (3/0 encoders/decoders), and one of the bridged calls is being recorded (0/1 encoders/decoders), but only four G.729 channel licenses, one of the calls will fail or have one-way or no audio. In total, 5/3 encoders/decoders are required for this scenario, but only 4/4 encoders/decoders are available. That only three decoders are in use is immaterial, if one channel is used then the entire licensed channel is consumed for the duration of the call, even though only one half of the license is actually utilized for that channel.