[Asterisk-Dev] removing limitation of ast_channel::nativeformats to one codec (with patch)

Valentin Nechayev netch at portaone.com
Thu Mar 24 06:40:42 MST 2005


Hi,
we had got problem with interaction of Sipura2000 and Asterisk when the latter
plays sound (using Playback()) and gets stream of another selected codec
at its input. Due to internal codec preference order, Asterisk had got G.729
as preferred (and played g729 recorded sound using standard "dummy" codec
library), then had got G.711u input and had fallen into situation it can't
recode g729 sound file to re-switched G.711u codec.
I created a patch (attached below) which fixes this in our tests.

Example of problem log:

SDP from UA (thru SER which only proxies ports without changing RTP):

v=0
o=- 329409 329409 IN IP4 192.168.1.180
s=-
c=IN IP4 193.28.87.7
t=0 0
m=audio 35194 RTP/AVP 0 2 4 8 18 96 97 98 100 101
a=rtpmap:0 PCMU/8000
a=rtpmap:2 G726-32/8000
a=rtpmap:4 G723/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729a/8000
a=rtpmap:96 G726-40/8000
a=rtpmap:97 G726-24/8000
a=rtpmap:98 G726-16/8000
a=rtpmap:100 NSE/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:30
a=sendrecv
a=nortpproxy:yes

SDP from Asterisk:

v=0
o=root 792 792 IN IP4 193.28.87.7
s=session
c=IN IP4 193.28.87.7
t=0 0
m=audio 18292 RTP/AVP 18 4 0 8 101
a=rtpmap:18 G729/8000
a=rtpmap:4 G723/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -

Asterisk debug during Playback():

Mar 21 23:00:10 DEBUG[792]: channel.c:1740 ast_set_write_format: Set channel
 SIP/193.28.87.7-08efa000 to write format g729
Mar 21 23:00:10 DEBUG[792]: rtp.c:1195 ast_rtp_write: Ooh, format changed fr
om unknown to g729
Mar 21 23:00:10 DEBUG[792]: chan_sip.c:2223 sip_rtp_read: Oooh, format changed to 4
Mar 21 23:00:10 DEBUG[792]: channel.c:1773 ast_set_read_format: Set channel 
SIP/193.28.87.7-08efa000 to read format g729
Mar 21 23:00:10 DEBUG[792]: channel.c:1740 ast_set_write_format: Set channel
 SIP/193.28.87.7-08efa000 to write format g729
Mar 21 23:00:10 DEBUG[792]: rtp.c:1195 ast_rtp_write: Ooh, format changed from g729 to ulaw
(and here silence begins because Asterisk can't convert g729 sound to g711.)

The following patch attempts to restore possibly initially supposed role
of ast_channel::nativeformats, while putting not only one bit of selected
codec to this field, but a mask. ast_codec_choose() returns the mask of
possible codecs instead of the only one selected; sip_rtp_read() changes
equalness test to mask test. It was successfully tested in our environment.

diff -rNu 00/asterisk-1.0.6/channels/chan_sip.c work/asterisk-1.0.6/channels/chan_sip.c
--- 00/asterisk-1.0.6/channels/chan_sip.c	Mon Mar 21 17:14:30 2005
+++ work/asterisk-1.0.6/channels/chan_sip.c	Wed Mar 23 17:13:45 2005
@@ -2219,7 +2219,7 @@
 	if (p->owner) {
 		/* We already hold the channel lock */
 		if (f->frametype == AST_FRAME_VOICE) {
-			if (f->subclass != p->owner->nativeformats) {
+			if (!(f->subclass & p->owner->nativeformats)) {
 				ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
 				p->owner->nativeformats = f->subclass;
 				ast_set_read_format(p->owner, p->owner->readformat);
diff -rNu 00/asterisk-1.0.6/frame.c work/asterisk-1.0.6/frame.c
--- 00/asterisk-1.0.6/frame.c	Fri Jan 28 03:18:25 2005
+++ work/asterisk-1.0.6/frame.c	Wed Mar 23 17:03:45 2005
@@ -948,8 +948,7 @@
 		if(!slot)
 			break;
 		if ( formats & AST_FORMAT_LIST[slot-1].bits ) {
-			ret = AST_FORMAT_LIST[slot-1].bits;
-			break;
+			ret |= AST_FORMAT_LIST[slot-1].bits;
 		}
 	}
 	if(ret)

Thanks,

-- 
Valentin Nechayev
Porta Software Ltd., Software Engineer
mailto:netch at portaone.com



More information about the asterisk-dev mailing list