Unable to hear audio from other end using PJSIP app-kotlin and asterisk server

Hello developers! I am facing the following problem:-
I am building voip dialer app using PJSIP. I downloaded this app on 2 different devices with different usernames as given the in sip.conf of asterisk server which I setup on my ubuntu machine. Now when I called from one device to other, the call is picked up but I just cannot hear voice from the other end.
My sip.conf in asterisk server:-

[general]
context=internal
allowguest=yes
allowoverlap=no
bindport=5060
bindaddr=0.0.0.0
srvlookup=no
disallow=all
allow=ulaw
alwaysauthreject=no
canreinvite=no
nat=force_rport,comedia
session-timers=refuse
localnet=192.168.0.0/255.255.255.0
externip=192.168.x.x

[7001]
type=friend
username=7001
host=dynamic
secret=7001
context=internal


[7002]
type=friend
username=7002
host=dynamic
secret=7002
context=internal

My kotlin pjsip code is same as in here: https://github.com/pjsip/pjproject/blob/master/pjsip-apps/src/swig/java/android/app-kotlin/src/mainenter code here/java/org/pjsip/pjsua2/app_kotlin/MainActivity.kt with few changes as follows:-

/* Setup Call button */
        val buttonCall = findViewById<Button>(R.id.button_call)
        buttonCall.setOnClickListener {
            if (g.ep.libGetState() != pjsua_state.PJSUA_STATE_RUNNING)
                return@setOnClickListener

            if (g.call == null) {
                try {
                    /* Setup null audio (good for emulator) */
//                    g.ep.audDevManager().setNullDev()
                    // List available devices first (useful for debugging)
                    val soundDevList = g.ep.audDevManager().enumDev2()
                    Log.d("AUDIO", "Available sound devices: ${soundDevList.size}")

                    for (i in soundDevList.indices) {
                        val dev = soundDevList[i]
                        Log.d("AUDIO", "Device $i: ${dev.name}, input=${dev.inputCount}, output=${dev.outputCount}")
                    }

                    // Use default devices (usually index 0 for both)
                    g.ep.audDevManager().setCaptureDev(0)
                    g.ep.audDevManager().setPlaybackDev(0)

                    /* Make call (to itself) */
                    val call = MyCall(g.acc, -1)
                    val prm = CallOpParam(true)
                    call.makeCall(CALL_DST_URI, prm)
                    g.call = call
                    Log.d("MAIN ACTIVITY buttonCall", "----------------Call initiated to $CALL_DST_URI")
                } catch (e: Exception) {
                    Log.e("MAIN ACTIVITY buttonCall", "-----------------Error initiating call: ${e.message}", e)
//                    println(e)
                }
            } else {
                try {
                    g.ep.hangupAllCalls()
                    Log.d("MAIN ACTIVITY buttonCall", "-----------------Hanging up all calls")
                } catch (e: Exception) {
                    Log.e("MAIN ACTIVITY buttonCall", "-----------------Error hanging up calls: ${e.message}", e)
//                    println(e)
                }
            }
        }

I have built pjsip, I can setup SIP connection to the server, I also saw the log output of the command “rtp debug on” on being typed in asterisk server, where rtp P2P packets are sent from one device and received on other. Please help me understand what do I need to do here?

I have also asked the stack overflow question here:-

Please describe your NAT environment in details (I assume at least one x is not 0, but having a local use network number on both sides of NAT is uncommon).

Also, chan_sip only has third party support; it is no longer part of the official Asterisk project. Most people here have not used it in many years.

app_kotlin is not an Asterisk app and Google gives no good candidate hits.

This is dangerous.

This is not advisable unless the endpoints share a common IP address.

Generally for missing media, we need to see the, in this case, “sip set debug on” logs, to see what addresses are being used for the SIP and in the SDP.

Yes the last number x in the address of externip=192.168.x.x is non zero. app-kotlin is a pjsip app, since the audio isn’t heard from the other end, I really don’t know where is the problem. The endpoints are on the same network wifi, hence have common IP address starting with 198.168.x.x

Here are the logs after setting “sip set debug on”:
!) On registering the two devices:-

SIP Debugging enabled

<--- SIP read from UDP:192.168.0.104:5060 --->

REGISTER sip:192.168.0.106 SIP/2.0

Via: SIP/2.0/UDP 192.168.0.104:5060;rport;branch=z9hG4bKPjd0ff7ee7-cbb0-4df5-bebc-7797bb208d30

Route: <sip:192.168.0.106;lr>

Max-Forwards: 70

From: <sip:7001@192.168.0.106>;tag=0382f24a-2852-453f-8a44-7310fef07439

To: <sip:7001@192.168.0.106>

Call-ID: db48da61-f7a8-492c-879b-9599797e8691

CSeq: 27352 REGISTER

Contact: <sip:7001@192.168.0.104:5060;ob>

Expires: 600

Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS

Content-Length: 0

<------------->

--- (12 headers 0 lines) ---

Sending to 192.168.0.104:5060 (NAT)

Sending to 192.168.0.104:5060 (NAT)

<--- Transmitting (NAT) to 192.168.0.104:5060 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.0.104:5060;branch=z9hG4bKPjd0ff7ee7-cbb0-4df5-bebc-7797bb208d30;received=192.168.0.104;rport=5060
From: <sip:7001@192.168.0.106>;tag=0382f24a-2852-453f-8a44-7310fef07439
To: <sip:7001@192.168.0.106>;tag=as189801ee
Call-ID: db48da61-f7a8-492c-879b-9599797e8691
CSeq: 27352 REGISTER
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="4d859fc4"
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog 'db48da61-f7a8-492c-879b-9599797e8691' in 32000 ms (Method: REGISTER)

<--- SIP read from UDP:192.168.0.104:5060 --->
REGISTER sip:192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.104:5060;rport;branch=z9hG4bKPj679da2db-b1a2-415d-8ca2-7339014d026a
Route: <sip:192.168.0.106;lr>
Max-Forwards: 70
From: <sip:7001@192.168.0.106>;tag=0382f24a-2852-453f-8a44-7310fef07439
To: <sip:7001@192.168.0.106>
Call-ID: db48da61-f7a8-492c-879b-9599797e8691
CSeq: 27353 REGISTER
Contact: <sip:7001@192.168.0.104:5060;ob>
Expires: 600
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Authorization: Digest username="7001", realm="asterisk", nonce="4d859fc4", uri="sip:192.168.0.106", response="d4959da6989f23bd5516b03767674377", algorithm=MD5
Content-Length: 0

<------------->
--- (13 headers 0 lines) ---
Sending to 192.168.0.104:5060 (NAT)
	-- Registered SIP '7001' at 192.168.0.104:5060

<--- Transmitting (NAT) to 192.168.0.104:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.104:5060;branch=z9hG4bKPj679da2db-b1a2-415d-8ca2-7339014d026a;received=192.168.0.104;rport=5060
From: <sip:7001@192.168.0.106>;tag=0382f24a-2852-453f-8a44-7310fef07439
To: <sip:7001@192.168.0.106>;tag=as189801ee
Call-ID: db48da61-f7a8-492c-879b-9599797e8691
CSeq: 27353 REGISTER
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Expires: 600
Contact: <sip:7001@192.168.0.104:5060;ob>;expires=600
Date: Mon, 14 Apr 2025 16:57:05 GMT
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog 'db48da61-f7a8-492c-879b-9599797e8691' in 32000 ms (Method: REGISTER)

<--- SIP read from UDP:192.168.0.104:5060 --->

<------------->

<--- SIP read from UDP:192.168.0.104:5060 --->

<------------->
Really destroying SIP dialog 'db48da61-f7a8-492c-879b-9599797e8691' Method: REGISTER

<--- SIP read from UDP:192.168.0.103:5060 --->
REGISTER sip:192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;rport;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97
Route: <sip:192.168.0.106;lr>
Max-Forwards: 70
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Contact: <sip:7002@192.168.0.103:5060;ob>
Expires: 600
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0

<------------->
--- (12 headers 0 lines) ---
Sending to 192.168.0.103:5060 (NAT)
Sending to 192.168.0.103:5060 (NAT)
	-- Registered SIP '7002' at 192.168.0.103:5060

<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97;received=192.168.0.103;rport=5060
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>;tag=as5b979072
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Expires: 600
Contact: <sip:7002@192.168.0.103:5060;ob>;expires=600
Date: Mon, 14 Apr 2025 16:57:40 GMT
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog 'b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca' in 32000 ms (Method: REGISTER)

<--- SIP read from UDP:192.168.0.103:5060 --->
REGISTER sip:192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;rport;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97
Route: <sip:192.168.0.106;lr>
Max-Forwards: 70
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Contact: <sip:7002@192.168.0.103:5060;ob>
Expires: 600
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0

<------------->
--- (12 headers 0 lines) ---
Sending to 192.168.0.103:5060 (NAT)

<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97;received=192.168.0.103;rport=5060
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>;tag=as5b979072
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Expires: 600
Contact: <sip:7002@192.168.0.103:5060;ob>;expires=600
Date: Mon, 14 Apr 2025 16:57:40 GMT
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog 'b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca' in 32000 ms (Method: REGISTER)

<--- SIP read from UDP:192.168.0.103:5060 --->
REGISTER sip:192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;rport;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97
Route: <sip:192.168.0.106;lr>
Max-Forwards: 70
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Contact: <sip:7002@192.168.0.103:5060;ob>
Expires: 600
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0

<------------->
--- (12 headers 0 lines) ---
Sending to 192.168.0.103:5060 (NAT)

<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97;received=192.168.0.103;rport=5060
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>;tag=as5b979072
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Expires: 600
Contact: <sip:7002@192.168.0.103:5060;ob>;expires=600
Date: Mon, 14 Apr 2025 16:57:41 GMT
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog 'b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca' in 32000 ms (Method: REGISTER)


<--- SIP read from UDP:192.168.0.103:5060 --->
REGISTER sip:192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;rport;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97
Route: <sip:192.168.0.106;lr>
Max-Forwards: 70
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Contact: <sip:7002@192.168.0.103:5060;ob>
Expires: 600
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0

<------------->
--- (12 headers 0 lines) ---
Sending to 192.168.0.103:5060 (NAT)

<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97;received=192.168.0.103;rport=5060
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>;tag=as5b979072
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Expires: 600
Contact: <sip:7002@192.168.0.103:5060;ob>;expires=600
Date: Mon, 14 Apr 2025 16:57:47 GMT
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog 'b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca' in 32000 ms (Method: REGISTER)


And the logs when I start the call:-

<--- SIP read from UDP:192.168.0.103:5060 --->
REGISTER sip:192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;rport;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97
Route: <sip:192.168.0.106;lr>
Max-Forwards: 70
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Contact: <sip:7002@192.168.0.103:5060;ob>
Expires: 600
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0

<------------->
--- (12 headers 0 lines) ---
Sending to 192.168.0.103:5060 (NAT)

<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPjc8fade7f-337f-4610-8eac-1cffc9c5be97;received=192.168.0.103;rport=5060
From: <sip:7002@192.168.0.106>;tag=dce66cc7-20f3-4e7a-8c09-7dd705e54567
To: <sip:7002@192.168.0.106>;tag=as5b979072
Call-ID: b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca
CSeq: 32 REGISTER
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Expires: 600
Contact: <sip:7002@192.168.0.103:5060;ob>;expires=600
Date: Mon, 14 Apr 2025 16:58:03 GMT
Content-Length: 0

<------------>
Scheduling destruction of SIP dialog 'b9dc8d69-2973-4f77-ae78-f8f1cc2d16ca' in 32000 ms (Method: REGISTER)

<--- SIP read from UDP:192.168.0.103:5060 --->
INVITE sip:7001@192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;rport;branch=z9hG4bKPja6e992cd-def2-40f8-996a-b282cc240b78
Max-Forwards: 70
From: sip:7002@192.168.0.106;tag=8691875d-8fb3-416d-a420-6b5414550ff3
To: sip:7001@192.168.0.106
Contact: <sip:7002@192.168.0.103:5060;ob>
Call-ID: 3253a3f8-997a-4f02-a39a-da82fce63a52
CSeq: 28312 INVITE
Route: <sip:192.168.0.106;lr>
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Supported: replaces, 100rel, timer, norefersub
Session-Expires: 1800
Min-SE: 90
Content-Type: application/sdp
Content-Length: 1121

v=0
o=- 3953638682 3953638682 IN IP4 192.168.0.103
s=pjmedia
b=AS:352
t=0 0
a=X-nat:0
m=audio 4000 RTP/AVP 96 97 98 99 100 101 3 0 8 9 120 121 122
c=IN IP4 192.168.0.103
b=TIAS:64000
a=rtcp:4001 IN IP4 192.168.0.103
a=sendrecv
a=rtpmap:96 speex/16000
a=rtpmap:97 speex/8000
a=rtpmap:98 speex/32000
a=rtpmap:99 AMR/8000
a=fmtp:99 octet-align=1
a=rtpmap:100 AMR-WB/16000
a=fmtp:100 octet-align=1
a=rtpmap:101 iLBC/8000
a=fmtp:101 mode=30
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:9 G722/8000
a=rtpmap:120 telephone-event/16000
a=fmtp:120 0-16
a=rtpmap:121 telephone-event/8000
a=fmtp:121 0-16
a=rtpmap:122 telephone-event/32000
a=fmtp:122 0-16
a=ssrc:1011807305 cname:36a185a466778f10
m=video 4002 RTP/AVP 99 103 106
c=IN IP4 192.168.0.103
b=TIAS:256000
a=rtcp:4003 IN IP4 192.168.0.103
a=sendrecv
a=rtpmap:99 H264/90000
a=fmtp:99 profile-level-id=42e01e; packetization-mode=1
a=rtpmap:103 VP8/90000
a=fmtp:103 max-fr=30; max-fs=580
a=rtpmap:106 VP9/90000
a=fmtp:106 max-fr=30; max-fs=580
a=ssrc:815506237 cname:36a185a466778f10
a=rtcp-fb:* nack pli
<------------->
--- (15 headers 44 lines) ---
Sending to 192.168.0.103:5060 (NAT)
Sending to 192.168.0.103:5060 (NAT)
Using INVITE request as basis request - 3253a3f8-997a-4f02-a39a-da82fce63a52
Found peer '7002' for '7002' from 192.168.0.103:5060
  == Using SIP RTP CoS mark 5
Got SDP version 3953638682 and unique parts [- 3953638682 IN IP4 192.168.0.103]
Found RTP audio format 96
Found RTP audio format 97
Found RTP audio format 98
Found RTP audio format 99
Found RTP audio format 100
Found RTP audio format 101
Found RTP audio format 3
Found RTP audio format 0
Found RTP audio format 8
Found RTP audio format 9
Found RTP audio format 120
Found RTP audio format 121
Found RTP audio format 122
Found audio description format speex for ID 96
Found audio description format speex for ID 97
Found audio description format speex for ID 98
Found audio description format AMR for ID 99
Found audio description format AMR-WB for ID 100
Found audio description format iLBC for ID 101
Found audio description format GSM for ID 3
Found audio description format PCMU for ID 0
Found audio description format PCMA for ID 8
Found audio description format G722 for ID 9
Found unknown media description format telephone-event for ID 120
Found audio description format telephone-event for ID 121
Found unknown media description format telephone-event for ID 122
Capabilities: us - (ulaw), peer - audio=(ulaw|gsm|alaw|g722|speex16|speex|speex32|amr|amrwb|ilbc)/video=(nothing)/text=(nothing), combined - (ulaw)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
   	> 0x7e816c0514e0 -- Strict RTP learning after remote address set to: 192.168.0.103:4000
Peer audio RTP is at port 192.168.0.103:4000
Looking for 7001 in internal (domain 192.168.0.106)
sip_route_dump: route/path hop: <sip:7002@192.168.0.103:5060;ob>

<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPja6e992cd-def2-40f8-996a-b282cc240b78;received=192.168.0.103;rport=5060
From: sip:7002@192.168.0.106;tag=8691875d-8fb3-416d-a420-6b5414550ff3
To: sip:7001@192.168.0.106
Call-ID: 3253a3f8-997a-4f02-a39a-da82fce63a52
CSeq: 28312 INVITE
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Contact: <sip:7001@192.168.0.106:5060>
Content-Length: 0


<------------>
	-- Executing [7001@internal:1] Answer("SIP/7002-00000010", "") in new stack
Audio is at 10540
Adding codec ulaw to SDP
Adding non-codec 0x1 (telephone-event) to SDP
<--- Reliably Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPja6e992cd-def2-40f8-996a-b282cc240b78;received=192.168.0.103;rport=5060
From: sip:7002@192.168.0.106;tag=8691875d-8fb3-416d-a420-6b5414550ff3
To: sip:7001@192.168.0.106;tag=as48da30fb
Call-ID: 3253a3f8-997a-4f02-a39a-da82fce63a52
CSeq: 28312 INVITE
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Contact: <sip:7001@192.168.0.106:5060>
Content-Type: application/sdp
Content-Length: 313

v=0
o=root 2001546104 2001546104 IN IP4 192.168.0.106
s=Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
c=IN IP4 192.168.0.106
t=0 0
m=audio 10540 RTP/AVP 0 121
a=rtpmap:0 PCMU/8000
a=rtpmap:121 telephone-event/8000
a=fmtp:121 0-16
a=ptime:20
a=maxptime:140
a=sendrecv
m=video 0 RTP/AVP 99 103 106
<------------>

<--- SIP read from UDP:192.168.0.103:5060 --->
INVITE sip:7001@192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;rport;branch=z9hG4bKPja6e992cd-def2-40f8-996a-b282cc240b78
Max-Forwards: 70
From: sip:7002@192.168.0.106;tag=8691875d-8fb3-416d-a420-6b5414550ff3
To: sip:7001@192.168.0.106
Contact: <sip:7002@192.168.0.103:5060;ob>
Call-ID: 3253a3f8-997a-4f02-a39a-da82fce63a52
CSeq: 28312 INVITE
Route: <sip:192.168.0.106;lr>
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Supported: replaces, 100rel, timer, norefersub
Session-Expires: 1800
Min-SE: 90
Content-Type: application/sdp
Content-Length: 1121

v=0
o=- 3953638682 3953638682 IN IP4 192.168.0.103
s=pjmedia
b=AS:352
t=0 0
a=X-nat:0
m=audio 4000 RTP/AVP 96 97 98 99 100 101 3 0 8 9 120 121 122
c=IN IP4 192.168.0.103
b=TIAS:64000
a=rtcp:4001 IN IP4 192.168.0.103
a=sendrecv
a=rtpmap:96 speex/16000
a=rtpmap:97 speex/8000
a=rtpmap:98 speex/32000
a=rtpmap:99 AMR/8000
a=fmtp:99 octet-align=1
a=rtpmap:100 AMR-WB/16000
a=fmtp:100 octet-align=1
a=rtpmap:101 iLBC/8000
a=fmtp:101 mode=30
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:9 G722/8000
a=rtpmap:120 telephone-event/16000
a=fmtp:120 0-16
a=rtpmap:121 telephone-event/8000
a=fmtp:121 0-16
a=rtpmap:122 telephone-event/32000
a=fmtp:122 0-16
a=ssrc:1011807305 cname:36a185a466778f10
m=video 4002 RTP/AVP 99 103 106
c=IN IP4 192.168.0.103
b=TIAS:256000
a=rtcp:4003 IN IP4 192.168.0.103
a=sendrecv
a=rtpmap:99 H264/90000
a=fmtp:99 profile-level-id=42e01e; packetization-mode=1
a=rtpmap:103 VP8/90000
a=fmtp:103 max-fr=30; max-fs=580
a=rtpmap:106 VP9/90000
a=fmtp:106 max-fr=30; max-fs=580
a=ssrc:815506237 cname:36a185a466778f10
a=rtcp-fb:* nack pli
<------------->
--- (15 headers 44 lines) ---
Ignoring this INVITE request

<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPja6e992cd-def2-40f8-996a-b282cc240b78;received=192.168.0.103;rport=5060
From: sip:7002@192.168.0.106;tag=8691875d-8fb3-416d-a420-6b5414550ff3
To: sip:7001@192.168.0.106
Call-ID: 3253a3f8-997a-4f02-a39a-da82fce63a52
CSeq: 28312 INVITE
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Contact: <sip:7001@192.168.0.106:5060>
Content-Length: 0


<------------>
Audio is at 10540
Adding codec ulaw to SDP
Adding non-codec 0x1 (telephone-event) to SDP

<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPja6e992cd-def2-40f8-996a-b282cc240b78;received=192.168.0.103;rport=5060
From: sip:7002@192.168.0.106;tag=8691875d-8fb3-416d-a420-6b5414550ff3
To: sip:7001@192.168.0.106;tag=as48da30fb
Call-ID: 3253a3f8-997a-4f02-a39a-da82fce63a52
CSeq: 28312 INVITE
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Contact: <sip:7001@192.168.0.106:5060>
Content-Type: application/sdp
Content-Length: 313
v=0
o=root 2001546104 2001546105 IN IP4 192.168.0.106
s=Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
c=IN IP4 192.168.0.106
t=0 0
m=audio 10540 RTP/AVP 0 121
a=rtpmap:0 PCMU/8000
a=rtpmap:121 telephone-event/8000
a=fmtp:121 0-16
a=ptime:20
a=maxptime:140
a=sendrecv
m=video 0 RTP/AVP 99 103 106

<------------>
Retransmitting #1 (NAT) to 192.168.0.103:5060:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPja6e992cd-def2-40f8-996a-b282cc240b78;received=192.168.0.103;rport=5060
From: sip:7002@192.168.0.106;tag=8691875d-8fb3-416d-a420-6b5414550ff3
To: sip:7001@192.168.0.106;tag=as48da30fb
Call-ID: 3253a3f8-997a-4f02-a39a-da82fce63a52
CSeq: 28312 INVITE
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Contact: <sip:7001@192.168.0.106:5060>
Content-Type: application/sdp
Content-Length: 313
v=0
o=root 2001546104 2001546104 IN IP4 192.168.0.106
s=Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
c=IN IP4 192.168.0.106
t=0 0
m=audio 10540 RTP/AVP 0 121
a=rtpmap:0 PCMU/8000
a=rtpmap:121 telephone-event/8000
a=fmtp:121 0-16
a=ptime:20
a=maxptime:140
a=sendrecv
m=video 0 RTP/AVP 99 103 106

---
	-- Executing [7001@internal:2] Dial("SIP/7002-00000010", "SIP/7001,60") in new stack
  == Using SIP RTP CoS mark 5
Audio is at 13964
Adding codec ulaw to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (NAT) to 192.168.0.104:5060:
INVITE sip:7001@192.168.0.104:5060;ob SIP/2.0
Via: SIP/2.0/UDP 192.168.0.106:5060;branch=z9hG4bK4543e4cf;rport
Max-Forwards: 70
From: <sip:7002@192.168.0.106>;tag=as64b9aa76
To: <sip:7001@192.168.0.104:5060;ob>
Contact: <sip:7002@192.168.0.106:5060>
Call-ID: 35488d725bfc33a951cbd7246dbb502f@192.168.0.106:5060
CSeq: 102 INVITE
User-Agent: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Date: Mon, 14 Apr 2025 16:58:04 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Content-Type: application/sdp
Content-Length: 283

v=0
o=root 1356293601 1356293601 IN IP4 192.168.0.106
s=Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
c=IN IP4 192.168.0.106
t=0 0
m=audio 13964 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:140
a=sendrecv
-- Called SIP/7001

<--- SIP read from UDP:192.168.0.104:5060 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.0.106:5060;rport=5060;received=192.168.0.106;branch=z9hG4bK4543e4cf
Call-ID: 35488d725bfc33a951cbd7246dbb502f@192.168.0.106:5060
From: <sip:7002@192.168.0.106>;tag=as64b9aa76
To: <sip:7001@192.168.0.104;ob>
CSeq: 102 INVITE
Content-Length: 0

<------------->
--- (7 headers 0 lines) ---

<--- SIP read from UDP:192.168.0.104:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.106:5060;rport=5060;received=192.168.0.106;branch=z9hG4bK4543e4cf
Call-ID: 35488d725bfc33a951cbd7246dbb502f@192.168.0.106:5060
From: <sip:7002@192.168.0.106>;tag=as64b9aa76
To: <sip:7001@192.168.0.104;ob>;tag=7e66d267-cf73-47e7-9d5b-a68162234387
CSeq: 102 INVITE
Contact: <sip:7001@192.168.0.104:5060;ob>
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Supported: replaces, 100rel, timer, norefersub
Content-Type: application/sdp
Content-Length: 318
v=0
o=- 3953638684 3953638685 IN IP4 192.168.0.104
s=pjmedia
b=AS:84
t=0 0
a=X-nat:0
m=audio 4000 RTP/AVP 0 101
c=IN IP4 192.168.0.104
b=TIAS:64000
a=rtcp:4001 IN IP4 192.168.0.104
a=sendrecv
a=rtpmap:0 PCMU/8000
a=ssrc:406034045 cname:5745e7b5280ce9da
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
<------------->
--- (11 headers 15 lines) ---
Got SDP version 3953638685 and unique parts [- 3953638684 IN IP4 192.168.0.104]
Found RTP audio format 0
Found RTP audio format 101
Found audio description format PCMU for ID 0
Found audio description format telephone-event for ID 101
Capabilities: us - (ulaw), peer - audio=(ulaw)/video=(nothing)/text=(nothing), combined - (ulaw)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
   	> 0x7e81c0042cb0 -- Strict RTP learning after remote address set to: 
192.168.0.104:4000
Peer audio RTP is at port 192.168.0.104:4000
sip_route_dump: route/path hop: <sip:7001@192.168.0.104:5060;ob>
Transmitting (NAT) to 192.168.0.104:5060:
ACK sip:7001@192.168.0.104:5060;ob SIP/2.0
Via: SIP/2.0/UDP 192.168.0.106:5060;branch=z9hG4bK077fa9ba;rport
Max-Forwards: 70
From: <sip:7002@192.168.0.106>;tag=as64b9aa76
To: <sip:7001@192.168.0.104:5060;ob>;tag=7e66d267-cf73-47e7-9d5b-a68162234387
Contact: <sip:7002@192.168.0.106:5060>
Call-ID: 35488d725bfc33a951cbd7246dbb502f@192.168.0.106:5060
CSeq: 102 ACK
User-Agent: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Content-Length: 0

I don’t understand what and where is the problem.

The log is incomplete.

The initiator is behaving as though it is not seeing responses from the logging machine, but there isn’t a complete set of re transmissions,

There is no incoming ACK and not enough outgoing OKs for the call to timeout.

How about you refer to the logs here:-

[Apr 14 22:30:13] WARNING[30701]: chan_sip.c:4153 retrans_pkt: Retransmission timeout reached on transmission 7daa9466-d441-46fd-bff6-453db4411fb0 for seqno 28520 (Critical Response) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions
Packet timed out after 32000ms with no response

That looks like it is complete, but just confirms that 192.168.0.103:5060 is behaving as though it never received any of the SIP responses that Asterisk sent.

Thank you @david551 for replying, I’m beginner in this, could you guide me what steps should I take to resolve it? The I had also tried with “rtp set debug on” the logs showed rtp packets transfer.

Capture packets at the far end. If the responses are getting there, debug the far end. Otherwise repeat at every hop between the two ends and debug the router or firewall at which they get lost. The call hasn’t got to the point where the far end knows where to send RTP, so there is no point in doing RTP debugging.

What I observed is the device at 192.168.0.103:5060 → username 7002 was facing issues very initially to register SIP on server, I tried all the methods but no improvement, so I removed the secret (ie the password) from sip.conf for user 7002 and then it got registered. When I type “sip show users” in asterisk CLI I can see the 2 devices registered. So in conclusion some devices register easily with SIP server and some not inspire all devices being on same network and similar ip addresses.

That’s because, with a password, you get the sequence:

Register
401 (challenge)
Register with authentication
200

which will never get beyond the 401, as that will never get through. Without the authenticated register, it will never become registered on Asterisk.

Without authentication, it will be registered, on Asterisk, after the first register. You will probably find that there are m multiple re-transmissions, and it eventually fails at the far end, but registration is not necessary for it to send calls to Asterisk, and Asterisk wouldn’t need to successfully send the 200.

It looks like only 7002 has broken connectivity, but your register log is for 7001.

What could be the possible reasons some phones couldn’t connect with SIP server? I observed Samsung mobiles could do it easily, whereas other brand phones like One Plus and Motorola just couldn’t connect with the server. Could it be network or brand-specific problem?

Mis-configuration.

Also, I would say this is much more likely to be a network problem, than a phone problem. Even phone misconfiguration problems tend to have a large network element; the misconfiguration tends to relate to NAT.

“SIP Server” is commonly misused. Asterisk will be both a User Agent Client and a User Agent Server in your call case, although it is the Server role in which it is failing. It is a SIP Registrar for the registration.

UDP is connectionless, so there is no connection. Registration is not necessary for a successful inbound call.

Most network related failures to fully establish sessions relate to the wrong contact address being used, but that isn’t the problem here.

The second most common one is the wrong VIa address, due to uncompensated NAT, but this call is on the local network, and has rport on the Via, which compensates for most cases (and in this example shows that the Via address is correct).

You are going to have to trace the response through the network. My working hypothesis would be that there a firewall issue at the remote end.

One of the the things I see that might hang you up is this:
externip=192.168.x.x
You should use a PUBLIC / External IP not your private IP

That’s why I asked for a detailed description of his NAT environment, but I don’t think I got an answer. However, the failing case seems to be on the network declared to be the local one, and he says that the public one is not the same one, as the x isn’t a zero.

Ohk I will try with it. Thanks!

Yes the IP address is the private IP address of the device. All the 3 devices are on same network wifi. I realized there might be NAT behind 192.168.0.103 from these SIP logs:-

Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0
<------------->
--- (12 headers 0 lines) ---
Sending to 192.168.0.103:5060 (NAT)
<--- Transmitting (NAT) to 192.168.0.103:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.103:5060;branch=z9hG4bKPje0b957a2-e0cf-468a-b915-8774390d571f;received=192.168.0.103;rport=5060
From: <sip:7002@192.168.0.106>;tag=0e083e75-273a-43a4-bc27-24c145b570ae
To: <sip:7002@192.168.0.106>;tag=as4e7f38b9
Call-ID: c7255729-b19d-449e-8ed8-d501324a2473
CSeq: 14200 REGISTER
Server: Asterisk PBX 20.6.0~dfsg+~cs6.13.40431414-2build5
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces
Expires: 600
Contact: <sip:7002@192.168.0.103:5060;ob>;expires=600
Date: Wed, 16 Apr 2025 01:46:41 GMT
Content-Length: 0
<------------>
Scheduling destruction of SIP dialog 'c7255729-b19d-449e-8ed8-d501324a2473' in 32000 ms (Method: REGISTER)
<--- SIP read from UDP:192.168.0.103:5060 --->
REGISTER sip:192.168.0.106 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:5060;rport;branch=z9hG4bKPje0b957a2-e0cf-468a-b915-8774390d571f
Route: <sip:192.168.0.106;lr>
Max-Forwards: 70
From: <sip:7002@192.168.0.106>;tag=0e083e75-273a-43a4-bc27-24c145b570ae
To: <sip:7002@192.168.0.106>
Call-ID: c7255729-b19d-449e-8ed8-d501324a2473
CSeq: 14200 REGISTER
Contact: <sip:7002@192.168.0.103:5060;ob>
Expires: 600
Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS
Content-Length: 0

Infact using the same above configurations, I tried with linphone app on phone, I installed line phone on both the phones, connected to asterisk using the configurations in sip.conf and could successfully call and hear the audio from both the ends. Suggesting I guess problem might not be with the server.