[Asterisk-Dev] Retrieving variable set by SetVar() in extensions.conf

Steve Kann stevek at stevek.com
Thu Mar 31 06:39:03 MST 2005


On Mar 30, 2005, at 10:35 PM, Kevin P. Fleming wrote:

> Alf Thomas Nilsen wrote:
>> I am trying to add some functionality to Asterisk that will allow one 
>> to define a payload size for any given codec and/or channel. As it is 
>> today, each codec has a hardcoded size in the source code. I have 
>> thought that the best way to do this would be to have a variable set 
>> to the wanted size in extensions.conf using SetVar(). However, I am 
>> new to Asterisk and I’m having a hard time understanding the source 
>> code. Therefore I am not sure how to retrieve the variables I set 
>> using SetVar() inside the source code (let’s say, rtp.c for example). 
>> I guess it’s possible since predefined variables like SIP_CODEC 
>> exists.
>
> We don't set the 'size', we set (or respond to) the sample rate, which 
> determines the packet size. You can't just change the packet size 
> without negotiation the sample size with the device at the other end 
> of the channel.

I think what Alf might want to do is send more than one encoded "frame" 
per higher-level frame.  Since the word frame is used multiple times 
here, let me explain:

Example:  A GSM frame is 20 ms == 160 samples == 33 bytes.  Presently, 
asterisk sends _one_ of these per IAX2 or RTP packet.    I'm pretty 
sure that most user-agents will be perfectly happy if you sent 2 GSM 
frames (i.e. 66 bytes) per VoIP frame, every 40ms.

For most compressed codecs, this is the case.  For the uncompressed or 
companded formats (G.711a/u, slinear), the "frame" size is really one 
sample, and you can send as many or few samples as you want.

Asterisk itself more or less will handle this situation properly, and 
will indeed generate frames like this in certain situations.  For 
example, if you have a call that comes in as iLBC (30ms frames), and is 
bridged to some channel using 20ms frames, it will actually send out 
frames with durations of 20, 40, 20, 40, 20, 40, ...   [Which, 
incidentally, screws up the new jitterbuffer at the moment, patch for 
this and other edge cases coming soon].

In iaxclient, we know the sub-frame size for all the codecs, and the 
API lets you set a minimum wire frame duration, and iaxclient will then 
send frames whose duration is >= the minimum wire duration specified, 
while also a multiple of the codec's "sub-frame" size.

It gets a bit messy with Speex, though, since the bitrate it uses is 
not constant, and in several places we want to get the duration of the 
frame, and it's not simply dividing the number of bytes by a constant 
like most other codecs.

Anyway, you could do something like this in *; you'd need to either let 
the codec know during translation, or have the channels re-pack frames 
into larger frames.


-SteveK








More information about the asterisk-dev mailing list