Andreas Wehrmann
2019-Oct-03 11:13 UTC
[asterisk-users] Asterisk not using common codec between (SIP) endpoints
Hello people, I've ran into two problem that I can't seem to be able to solve on my own. Here's my scenario (running Asterisk 13.28.1): In short: - Asterisk behaves unexpectedly (at least to me) when negotiating between endpoints that have a different but intersecting set of codecs (preventing direct media flow). - Also, when an endpoint sends RTP with an unexpected (but internally hardcoded) payload type, Asterisk seems to get "confused" with what codec is supposed to be active (which seems to break transcoding). I've got a couple of phones (supported codecs are: g722,alaw,ulaw (in that order)) and a "special" media gateway which supports alaw, ulaw only. What I mean by "special" is, that it sends status information via RTP payload type 102; this is hardcoded and I cannot change it; also that thing sends it regardless of what was negotiated via SDP (yes, it's stupid and annoying to deal with). What I actually wanted to test was to see whether Asterisk would correctly negotiate codecs when making calls between the different kinds of participants (phones and gateways). Here's what I tested: - Calls between phones (OK) -- phone01 calls phone02 (phone01 offer: g722, alaw, ulaw) -- phone02 accepts (Asterisk/phone02 offer/answer: g722, alaw, ulaw) -- Asterisk sends reinvite to both to establish direct media flow (codec: g722) -- OKAY - this is exactly what i would expect - Phone calls mediagateway; mediagateway sends special RTP (NOK: Asterisk attempts to transcode and RTP engine seems to get confused) -- phone01 calls mediagateway (phone01 offer: g722, alaw, ulaw) -- mediagateway accepts call (Asterisk offer: alaw, ulaw | mediagateway answer: alaw) -- Asterisk accepts call from phone01 (Asterisk answer: g722, alaw, ulaw) -- Asterisk attempts to transcodes between g722 and alaw --> My expectation here would be for Asterisk to reduce the set of codecs in the answer to phone01 to alaw only, since this would enable direct media flow between the endpoints. But even if it accepts the call like I described above, I would expect Asterisk to reinvite the calls later to use alaw only and get out of the way to enable direct media flow. -- After mediagateway accepts the call, it sends a few status messages via RTP PT 102; this seems to confuse the RTP engine in Asterisk (see the console output at the end of this mail) which also seems to break transcoding, because audio doesn't work in either direction. My questions are: - Is there a way to make Asterisk always try to get out of the media path? I thought direct_media=yes and an overlapping set of codecs would suffice. - Even if direct_media is disabled: Is there a way to make Asterisk always use a common codec between SIP endpoints, so it doesn't need to transcode? - When Asterisk receives unexpected RTP packets or RTP packets of an unexpected type in a session, shouldn't it just ignore them? This is what I observed in older Asterisk versions (very old, like 1.4) where it would simply print a warning about an unknown/unhandled payload type. I'll attach my pjsip.conf, extensions.ael and a tcpdump that shows my phone (10.137.8.20) calling the mediagateway (10.254.0.221) via Asterisk (10.137.8.19). The rest of the configs are the default configs created with "make basic-pbx". I do hope, I'm not missing something obvious here... A few additions: I ran the tests with Asterisk 16.5.1 also, the results are: - Calls between phones work as expected, G722 is used and Asterisks reinvites to establish direct media flow between the phones. - When a phone calls a mediagateway, the results are as above with the exception of having audio in both directions. The status messages sent via RTP PT 102 do not seem to confuse Asterisk 16.5.1. - I also ran this test: I have two endpoints (direct_media=yes) each with allowed codecs set to ulaw, alaw on one endpoint and alaw, ulaw (reverse order) set on the other endpoint. When endpoint A calls B and offers codecs (in that order) ulaw, alaw and endpoint B accepts alaw only, Asterisk uses ulaw for the call from A and alaw in the call to B. Like I said above: I really hope I'm not missing something obvious. I need Asterisk to use the same codec in both calls (if there is an overlapping set) and try to get out of the way by establishing a direct media path if somehow possible. Best Regards, Andreas NOTE: The following is the console output from Asterisk 13 when the mediagateway answers and sends RTP PT 102 at the beginning of the call. [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (ending codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (ending codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (starting codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (ending codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (ending codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (starting codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (ending codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (ending codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: translate.c:490 ast_translator_build_path: No translator path: (starting codec is not valid) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:55] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:56] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:56] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:56] WARNING[23961][C-00000000]: chan_pjsip.c:856 chan_pjsip_write: Channel PJSIP/boslwzldi21-00000001 asked to send alaw frame when native formats are (siren7) (rd:alaw->slin16;(alaw at 8000)->(slin at 8000)->(slin at 16000) wr:slin16->alaw;(slin at 16000)->(slin at 8000)->(alaw at 8000)) [Oct 2 07:24:56] WARNING[23961][C-00000000]: channel.c:5751 set_format: Unable to find a codec translation path: (siren7) -> (alaw) [Oct 2 07:24:56] WARNING[23961][C-00000000]: channel.c:5751 set_format: Unable to find a codec translation path: (alaw) -> (siren7) -------------- next part -------------- context internal { 96 => { Dial(PJSIP/boslwzldi21); } 100 => { Dial(PJSIP/andytel); } 102 => { Dial(PJSIP/boslwztel02); } } -------------- next part -------------- A non-text attachment was scrubbed... Name: phone_calls_mediagateway_sip_rtp_asterisk13.pcap Type: application/vnd.tcpdump.pcap Size: 8179 bytes Desc: not available URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20191003/c242c99c/attachment.pcap> -------------- next part -------------- ;================================ TRANSPORTS =[transport-udp] type = transport protocol = udp bind = 10.137.8.19 ;================================ ENDPOINTS = [endpoint-basic] type=endpoint context = internal disallow = all allow = g722,alaw,ulaw direct_media = yes [endpoint-radio] type=endpoint context = internal disallow = all allow = alaw,ulaw direct_media = yes [auth-userpass](!) type = auth auth_type = userpass password = SnomSecret realm = A [aor-single-reg](!) type = aor max_contacts = 1 remove_existing = yes qualify_frequency = 60 ;============== RADIO GATEWAYS [boslwzldi21](endpoint-radio) aors=boslwzldi21 [boslwzldi21](aor-single-reg) contact=sip:10.254.0.221 [boslwzldi21] type = identify endpoint = boslwzldi21 match = 10.254.0.221 ;============= SNOM [andytel](endpoint-basic) ;auth=andytel aors=andytel [andytel](aor-single-reg) [andytel](auth-userpass) username=andytel [boslwztel02](endpoint-basic) ;auth=auth-userpass aors=boslwztel02 [boslwztel02](aor-single-reg) [boslwztel02](auth-userpass) username=boslwztel02
Administrator TOOTAI
2019-Oct-03 13:08 UTC
[asterisk-users] Asterisk not using common codec between (SIP) endpoints
Hi Le 03/10/2019 à 13:13, Andreas Wehrmann a écrit : [...]> > - Even if direct_media is disabled: Is there a way to make Asterisk > always use a common codec between SIP endpoints, > so it doesn't need to transcode?Before calling the gatreway add same = n,set(SIP_CODEC=alaw) [...] -- Daniel
Andreas Wehrmann
2019-Oct-03 14:10 UTC
[asterisk-users] Asterisk not using common codec between (SIP) endpoints
On 03.10.19 15:08, Administrator TOOTAI wrote:> Before calling the gatreway add > > same = n,set(SIP_CODEC=alaw) > > [...] >Hey there, that doesn't work as it seems to be implemented for chan_sip only; I'm using chan_pjsip; sorry if I didn't explain myself properly. Anyway, in my case that would not really be an acceptable solution anyway, because I need the called party to be able to pick from the range of codecs presented to it because the codec chosen by the destination might change (my example is a simplified version). I don't think putting the burden of worrying about audio codecs on the dialplan writer is a good idea, since this should be dealt with automatically with respect to what is configured and negotiated. This is also because in the systems I have to work with, the 'engineers' usual provide the configuration (endpoints, NAT config and the like) while the technicians implement the dialplan (or the business logic so to speak) according to customer needs. They (the technicians) usually don't know (much) about codecs or how the channels techs work exactly... Thanks, Andy