Add Peer Call Answer Notification Event in ESP-ADF RTC (AUD-6222)
Is your feature request related to a problem? Please describe.
Currently, when initiating an esp_rtc_call in ESP-ADF, we receive notifications for ESP_RTC_EVENT_CALLING and ESP_RTC_EVENT_AUDIO_SESSION_BEGIN. However, there is no event that explicitly notifies when the peer picks up the call (when the remote party answers).
This limitation makes it difficult to track call state transitions accurately, particularly for use cases where developers need to trigger specific actions upon call acceptance, such as logging call status or starting timers.
Describe the solution you'd like
I would like ESP-ADF to include an event that is triggered when the remote peer picks up the call. This could be something like:
ESP_RTC_EVENT_CALL_ANSWERED
This event should be fired when the SIP 200 OK response is received after sending an INVITE, indicating that the call has been accepted.
Describe alternatives you've considered
An alternative approach could be to expose lower-level SIP messages or provide a callback that allows developers to inspect and react to SIP responses directly. However, having a built-in event for call acceptance within ESP-ADF would simplify development.
Please give as many details as you can. Include suggestions for useful APIs or interfaces if relevant.
Additional context
For example, in a standard SIP exchange, when a call is accepted, the 200 OK response is received:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.1.100:5060;branch=z9hG4bK-524287-1---1f2e317f01a41f73
To: <sip:[email protected]>;tag=1928301774
From: <sip:[email protected]>;tag=456248
Call-ID: [email protected]
CSeq: 1 INVITE
Content-Type: application/sdp
Content-Length: 199
With this enhancement, ESP-ADF would be able to detect and notify when the 200 OK response is received.
When call is accepted, peer SDP is received and media session started, so ESP_RTC_EVENT_AUDIO_SESSION_BEGIN or ESP_RTC_EVENT_VIDEO_SESSION_BEGIN is send to user. Is it enough?
While receiving SDP and starting the media session (triggering ESP_RTC_EVENT_AUDIO_SESSION_BEGIN or ESP_RTC_EVENT_VIDEO_SESSION_BEGIN) indicates that the call is being set up, it doesn’t necessarily mean the remote party has answered. In our application, where we use a service that bridges our VoIP server to public phone numbers, we observe that this event is triggered while the recipient’s phone is still ringing. It’s only when a definitive 200 OK response is received that the peer has actually picked up the call. Thus, relying solely on the media session begin events is not sufficient, we need a distinct event that accurately indicates when the call is truly answered.
@carlosrodridel Could you please fetch one session wireshark dump for me? I have hardly seen 200 OK without SDP before.
@TempoTian , sorry for the misunderstanding, 200 OK is sent with SDP information. But I think I might have a clue of the actual problem :
If you look at the logs from my application, you'll see that ESP_RTC_EVENT_AUDIO_SESSION_BEGIN (log 56656 ) is triggered right after receiving the SIP/2.0 183 In band info available message, which includes SDP data. This event is sent just before the ringing and the final answer (the 200 OK response to the INVITE). It appears that in our case, the SDP is exchanged earlier in the call setup, leading to the premature triggering of the media session start event, while the call is still in the ringing state.
INVITE sip:[email protected]:5060 SIP/2.0
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;branch=z9hG4bK-1234301716;rport
From: <sip:[email protected]:5060>;tag=-962242274
To: <sip:[email protected]:5060>
Contact: <sip:[email protected]:11580;transport=UDP>
Max-Forwards: 70
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
CSeq: 3 INVITE
Expires: 300
User-Agent: ADETEC_GATEWAY
Content-Length: 160
Allow: INVITE, ACK, CANCEL, BYE, UPDATE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
Authorization: Digest username="003XXXXXXXXXX", realm="sip3.ovh.fr", nonce="1d4b0af675084fac4e1113b5509fe1d8", uri="sip:sip3.ovh.fr:5060", response="a9137766a53a7c2391cc70cfe1bd9b49", algorithm=MD5, opaque="1d45f693748baf6"
v=0
o=Z 0 3 IN IP4 10.XXX.XXX.XXX
s=SIP Call
c=IN IP4 10.XXX.XXX.XXX
t=0 0
m=audio 35507 RTP/AVP 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
I (54516) SIP: [2025-03-31/10:45:17]=======================>>
I (54676) SIP: [2025-03-31/10:45:17]<<=====READ 0308 bytes==
I (54676) SIP:
SIP/2.0 100 Trying
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
CSeq: 3 INVITE
From: <sip:[email protected]:5060>;tag=-962242274
To: <sip:[email protected]:5060>
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;received=37.174.190.152;rport=60644;branch=z9hG4bK-1234301716
Content-Length: 0
I (54677) SIP: [2025-03-31/10:45:17]<<======================
I (54685) SIP: [2025-03-31/10:45:17]<<=====READ 0749 bytes==
I (54685) SIP:
SIP/2.0 407 authentication required
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
Contact: <sip:[email protected]:5060;user=phone>
CSeq: 3 INVITE
From: <sip:[email protected]:5060>;tag=-962242274
Proxy-Authenticate: Digest realm="sip3.ovh.fr",nonce="efe32eeb13ebc2934f463b9946f7ab8c",opaque="efd7614c7a628f0",stale=false,algorithm=MD5
Record-Route: <sip:91.XXX.XXX.XXX:5060;transport=udp;lr>;session=85387
To: <sip:[email protected]:5060>;tag=00-07509-efe32fab-1e31a61a6
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;received=37.174.190.152;rport=60644;branch=z9hG4bK-1234301716
Allow: REFER,INVITE,NOTIFY,ACK,UPDATE,OPTIONS,REGISTER,SUBSCRIBE,NOTIFY,CANCEL,BYE,PRACK
Server: Cirpack/v4.76 (gw_sip)
Content-Length: 0
I (54687) SIP: [2025-03-31/10:45:17]<<======================
I (54688) SIP: Required ACK & Authentication
I (54688) SIP: [2025-03-31/10:45:17]=======WRITE 0533 bytes>>
I (54689) SIP:
ACK sip:[email protected]:5060;user=phone SIP/2.0
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;branch=z9hG4bK-1234301716;rport
Route: <sip:91.XXX.XXX.XXX:5060;transport=udp;lr>;session=85387
From: <sip:[email protected]:5060>;tag=-962242274
To: <sip:[email protected]:5060>;tag=00-07509-efe32fab-1e31a61a6
Contact: <sip:[email protected]:11580;transport=UDP>
Max-Forwards: 70
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
CSeq: 3 ACK
Expires: 300
User-Agent: ADETEC_GATEWAY
Content-Length: 0
I (54690) SIP: [2025-03-31/10:45:17]=======================>>
I (54696) SIP: [2025-03-31/10:45:17]=======WRITE 0942 bytes>>
I (54696) SIP:
INVITE sip:[email protected]:5060 SIP/2.0
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;branch=z9hG4bK-495879169;rport
From: <sip:[email protected]:5060>;tag=1127545089
To: <sip:[email protected]:5060>
Contact: <sip:[email protected]:11580;transport=UDP>
Max-Forwards: 70
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
CSeq: 4 INVITE
Expires: 300
User-Agent: ADETEC_GATEWAY
Content-Length: 160
Allow: INVITE, ACK, CANCEL, BYE, UPDATE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Content-Type: application/sdp
Proxy-Authorization: Digest username="003XXXXXXXXXX", realm="sip3.ovh.fr", nonce="efe32eeb13ebc2934f463b9946f7ab8c", uri="sip:sip3.ovh.fr:5060", response="3f6a246f3163fc3cff9689f001e52c64", algorithm=MD5, opaque="efd7614c7a628f0"
v=0
o=Z 0 3 IN IP4 10.XXX.XXX.XXX
s=SIP Call
c=IN IP4 10.XXX.XXX.XXX
t=0 0
m=audio 35507 RTP/AVP 8 101
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
I (54698) SIP: [2025-03-31/10:45:17]=======================>>
I (54773) SIP: [2025-03-31/10:45:17]<<=====READ 0307 bytes==
I (54774) SIP:
SIP/2.0 100 Trying
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
CSeq: 4 INVITE
From: <sip:[email protected]:5060>;tag=1127545089
To: <sip:[email protected]:5060>
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;received=37.174.190.152;rport=60644;branch=z9hG4bK-495879169
Content-Length: 0
I (54774) SIP: [2025-03-31/10:45:17]<<======================
W (54775) SIP: CHANGE STATE FROM 64, TO 68, :func: _sip_uac_request_invite:1377
E (54775) VoIpService: ESP_RTC_EVENT_CALLING Remote Ring...
I (54776) AnepDTMFClient: DIALER_EVENT_ALERTING
I (56652) SIP: [2025-03-31/10:45:18]<<=====READ 0866 bytes==
I (56652) SIP:
SIP/2.0 183 In band info available
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
Contact: <sip:91.XXX.XXX.XXX:5060>
Content-Type: application/sdp
CSeq: 4 INVITE
From: <sip:[email protected]:5060>;tag=1127545089
Record-Route: <sip:91.XXX.XXX.XXX:5060;transport=udp;lr>;session=85398
To: <sip:[email protected]:5060>;tag=00-07536-efe32fbe-40f9f6b92
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;received=37.174.190.152;rport=60644;branch=z9hG4bK-495879169
Allow: REFER,INVITE,NOTIFY,ACK,UPDATE,OPTIONS,REGISTER,SUBSCRIBE,NOTIFY,CANCEL,BYE,PRACK
Server: Cirpack/v4.76 (gw_sip)
Content-Length: 248
v=0
o=anonymous 174341073661 174341073662 IN IP4 91.XXX.XXX.XXX
s=SIP Call
c=IN IP4 91.121.129.146
t=0 0
m=audio 31482 RTP/AVP 8 101
b=AS:82
a=rtpmap:8 PCMA/8000/1
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
a=sendrecv
I (56654) SIP: [2025-03-31/10:45:18]<<======================
I (56655) SIP: Remote RTP addr=91.121.129.146
I (56656) SIP: Remote ARTP port=31482
E (56656) VoIpService: ESP_RTC_EVENT_AUDIO_SESSION_BEGIN
I (56657) AUDIO_PIPELINE: link el->rb, el:0x3da1cfb8, tag:algo, rb:0x3da1d918
I (56657) AUDIO_THREAD: The algo task allocate stack on external memory
I (56658) AUDIO_ELEMENT: [algo-0x3da1cfb8] Element task created
I (56658) AUDIO_ELEMENT: [raw-0x3da1ce60] Element task created
I (56658) AUDIO_PIPELINE: Func:audio_pipeline_run, Line:359, MEM Total:6306175 Bytes, Inter:146047 Bytes, Dram:146047 Bytes, Dram largest free:122880Bytes
I (56659) AUDIO_ELEMENT: [algo] AEL_MSG_CMD_RESUME,state:1
I (56659) AFE_VC: afe interface for voice communication
I (56659) AFE_VC: AFE version: VC_V220727
I (56659) AFE_VC: Initial auido front-end, total channel: 2, mic num: 1, ref num: 1
I (56660) AFE_VC: aec_init: 1, se_init: 1, vad_init: 0
I (56660) AFE_VC: wakenet_init: 0, voice_communication_agc_init: 0
I (56660) AFE_VC: ns_mode: 0
I (56671) AUDIO_PIPELINE: Pipeline started
I (56671) AUDIO_THREAD: The _audio_enc task allocate stack on external memory
I (56672) AV_STREAM: audio_enc started
I (56672) AUDIO_THREAD: The _audio_dec task allocate stack on external memory
I (56673) AV_STREAM: audio_dec started
I (56673) SLIC: Mode dtmf 0
I (56673) AnepDTMFClient: DIALER_EVENT_CONNECT
W (56673) SIP: CHANGE STATE FROM 68, TO 72, :func: _sip_uac_process_res:1758
I (56681) AFE_VC: mode: 0, (Sep 4 2024 11:49:31)
I (56681) AUDIO_THREAD: The algo_fetch task allocate stack on external memory
I (56862) SIP: [2025-03-31/10:45:18]<<=====READ 0851 bytes==
I (56862) SIP:
SIP/2.0 180 Ringing
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
Contact: <sip:91.XXX.XXX.XXX:5060>
Content-Type: application/sdp
CSeq: 4 INVITE
From: <sip:[email protected]:5060>;tag=1127545089
Record-Route: <sip:91.XXX.XXX.XXX:5060;transport=udp;lr>;session=85398
To: <sip:[email protected]:5060>;tag=00-07536-efe32fbe-40f9f6b92
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;received=37.174.190.152;rport=60644;branch=z9hG4bK-495879169
Allow: REFER,INVITE,NOTIFY,ACK,UPDATE,OPTIONS,REGISTER,SUBSCRIBE,NOTIFY,CANCEL,BYE,PRACK
Server: Cirpack/v4.76 (gw_sip)
Content-Length: 248
v=0
o=anonymous 174341073661 174341073662 IN IP4 91.XXX.XXX.XXX
s=SIP Call
c=IN IP4 91.121.129.146
t=0 0
m=audio 31482 RTP/AVP 8 101
b=AS:82
a=rtpmap:8 PCMA/8000/1
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
a=sendrecv
I (56870) SIP: [2025-03-31/10:45:19]<<======================
W (56872) SIP: CHANGE STATE FROM 72, TO 68, :func: _sip_uac_process_res:1733
I (63597) PowerManager: Battery is fully charged
I (65542) SIP: [2025-03-31/10:45:23]<<=====READ 0846 bytes==
I (65542) SIP:
SIP/2.0 200 OK
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
Contact: <sip:91.XXX.XXX.XXX:5060>
Content-Type: application/sdp
CSeq: 4 INVITE
From: <sip:[email protected]:5060>;tag=1127545089
Record-Route: <sip:91.XXX.XXX.XXX:5060;transport=udp;lr>;session=85398
To: <sip:[email protected]:5060>;tag=00-07536-efe32fbe-40f9f6b92
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;received=37.174.190.152;rport=60644;branch=z9hG4bK-495879169
Allow: REFER,INVITE,NOTIFY,ACK,UPDATE,OPTIONS,REGISTER,SUBSCRIBE,NOTIFY,CANCEL,BYE,PRACK
Server: Cirpack/v4.76 (gw_sip)
Content-Length: 248
v=0
o=anonymous 174341073661 174341073662 IN IP4 91.XXX.XXX.XXX
s=SIP Call
c=IN IP4 91.121.129.146
t=0 0
m=audio 31482 RTP/AVP 8 101
b=AS:82
a=rtpmap:8 PCMA/8000/1
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
a=sendrecv
I (65544) SIP: [2025-03-31/10:45:23]<<======================
I (65546) SIP: Remote ARTP port=31482
I (65546) SIP: Remote RTP addr=91.121.129.146
W (65546) SIP: CHANGE STATE FROM 68, TO 96, :func: _sip_uac_process_res_ok:1333
I (65547) SIP: [2025-03-31/10:45:23]=======WRITE 0735 bytes>>
I (65547) SIP:
ACK sip:91.XXX.XXX.XXX:5060 SIP/2.0
Via: SIP/2.0/UDP 10.XXX.XXX.XXX:11580;branch=z9hG4bK-495879169;rport
Route: <sip:91.XXX.XXX.XXX:5060;transport=udp;lr>;session=85398
From: <sip:[email protected]:5060>;tag=1127545089
To: <sip:[email protected]:5060>;tag=00-07536-efe32fbe-40f9f6b92
Contact: <sip:[email protected]:11580;transport=UDP>
Max-Forwards: 70
Call-ID: A2C586009A091938886A73D47C82CBB11D05D8F7F331
CSeq: 4 ACK
Expires: 300
User-Agent: ADETEC_GATEWAY
Content-Length: 0
Authorization: Digest username="003XXXXXXXXXX", realm="sip3.ovh.fr", nonce="efe32eeb13ebc2934f463b9946f7ab8c", uri="sip:sip3.ovh.fr:5060", response="bf063979639f4f28280215ac0c0bc05e", algorithm=MD5, opaque="efd7614c7a628f0"
OK, I understand your request. So I add a CALL_ANSWERED event when receive 200 OK, is it suitable for you? If yes I will add this event for you.
Yes, that would be perfect!, Thanks a lot
I have add the new event ESP_RTC_EVENT_CALL_ANSWERED. You can test it, the lib is latest, I will prepare to merge recent changed in next week, if verify OK it will also be merged.
@TempoTian I tested the new event on the ESP32S3, and it perfectly satisfies our needs, and we can now accurately detect when the call is actually answered. Thanks for the prompt update! please let me know when it's merged.