The Sofia__freeswitch of FreeSWITCH kernel research

Source: Internet
Author: User
Tags ack lua freeswitch

the Sofia of FreeSWITCH kernel research

call flow involves content

1, received the nua_i_invite of a, returned 407, as follows:

Sofia_handle_sip_i_invite =>sofia_reg_handle_register => sofia_reg_auth_challenge => 407

2, received the nua_i_invite of a, returned 180, as follows:

Sofia_handle_sip_i_invite =>sofia_reg_handle_register => Sofia_reg_parse_auth

Processing Nua_i_state messages
Sofia.c:sofia_handle_sip_i_state
...
Mod_dialplan_xml.c:dialplan_hunt (Ring_ready)
Resolves the dialing scheme, executes the Lua script, and sets the channel variables.
...
Send 180 Event

Data tables involved:
Sip_registrations, Ip_dialogs

3, send invite to B extension, specific as follows:
Processing Nua_r_invite messages
Sofia_handle_sip_r_invite => originate_on_routing
Data tables involved:
Sip_dialogs

4, B answer, the two sides call, specific as follows:

Sofia_receive_message:switch_message_indicate_answer

=>sofia_answer_channel

=>sofia_glue_tech_choose_port

=>sofia_glue_set_local_sdp

=>sofia_glue_activate_rtp

Coding Negotiation Process

This describes the following negotiation process to match the FreeSWITCH default codec, to find the support type's specific rate information from the loaded module

Sofia_handle_sip_i_invite
=> Sofia_glue_tech_prepare_codecs
=> switch_loadable_module_get_codecs_sorted negotiated to be called SDP

Sofia_glue_do_invite
=> Sofia_glue_tech_prepare_codecs
=> switch_loadable_module_get_codecs_sorted

Ocodec +codec_string generates m headers and sends invite containing the SDP

Sofia_glue_do_invite
=> SOFIA_GLUE_SET_LOCAL_SDP
=> generate_m
=> Nua_invite Negotiation OK SDP

Sofia_answer_channel
=> Sofia_glue_tech_prepare_codecs
=> switch_loadable_module_get_codecs_sorted

Media Interaction RTP Data interaction

Audio_bridge_on_exchange_media
=> Audio_bridge_thread

Send and receive audio data
=> Switch_core_session_read_frame
=> Session->endpoint_interface->io_routines->read_frame namely: Sofia_read_frame

=> Switch_core_session_write_frame
=> Perform_write
=> Session->endpoint_interface->io_routines->write_frame namely: Sofia_write_frame

Send and receive video data
1, start the thread
=> Launch_video
=> Video_bridge_thread

2, send and receive data
=> Switch_core_session_read_video_frame
=>session->endpoint_interface->io_routines->read_video_frame
namely: Sofia_read_video_frame

=>switch_core_session_write_video_frame
=> Session->endpoint_interface->io_routines->write_video_frame
That is: Sofia_write_video_frame terminate the RTP interaction

Audio_bridge_thread
=> Switch_core_session_kill_channel (Session_b, switch_sig_break);
namely: Switch_core_session_perform_kill_channel
=> Session->endpoint_interface->io_routines->kill_channel
namely: Sofia_kill_channel
=> switch_rtp_break Sofia Protocol Stack protocol stack structure diagram

NUA: Basic SIP User Agent functionality that includes call management, messaging, and event retrieval.
The Nta:sofia SIP Transaction API (NTA) provides a simple interface for SIP transactions, transport, and information processing.
Tport: This module contains a common transport interface used by the SIP,RTSP and HTTP protocols, which is the abstraction layer between the protocol stack and the Transport Protocol implementation. SIP Signaling Specific process

Scene Description: A call B, b after the call after a period of time, hang up the phone. A Send INVITE Request

Tport.c:tport_recv_data
Nta.c:agent_recv_request FS Response 100 to a ext

Nua_server.c:nua_stack_process_request
Nua_server.c:sr_status1 (SR, sip_100_trying)
Nta.c:nta_incoming_treply
Nta.c:incoming_reply
Tport.c:tport_tsend FS Send authentication request to a ext.

Nua_application_event

Processing Nua_i_invite messages

Sofia.c:sofia_process_dispatch_event
Sofia.c:our_sofia_event_callback
Sofia.c:sofia_handle_sip_i_invite
Sofia.c:sofia_reg_handle_register
Sofia_reg.c:sofia_reg_auth_challenge

Reply 407

Nua.c:nua_respond
Nua_stack.c:nua_signal
Nua_stack.c:nua_stack_signal
Nua_server.c:nua_stack_respond
Nua_server.c:nua_server_respond

Send 407 to extension a

Nua_invite_server_respond
Nua_base_server_respond
Nta_incoming_mreply
Incoming_reply
Tport_tsend
Tport_resolve
Tport_by_addrinfo
Tport_prepare_and_send
Tport_send_msg
Tport_vsend
Sent 407 Proxy authentication Required for INVITE (1)

Call State (A): Init-> received
Call State (A): Received-> terminated

· A ext. Send ACK
Nta.c:agent_recv_message
Nta.c:agent_recv_request

· A extension resend invite request, additional authentication information
Tport.c:tport_recv_data
Nta.c:agent_recv_request

· FS Response 100 to extension a

Nua_server.c:nua_stack_process_request
Nua_server.c:sr_status1 (SR, sip_100_trying)
Nta.c:nta_incoming_treply
Nta.c:incoming_reply
Tport.c:tport_tsend FS send INVITE to extension b

Switch_ivr_originate.c:switch_ivr_originate

Sofia_on_init
Sofia_glue_do_invite
Nua_invite:nua_r_invite message
Nua_signal

Sofia.c:sofia_process_dispatch_event
Sofia.c:our_sofia_event_callback
Sofia.c:sofia_handle_sip_r_invite
...
Sofia_on_init
Sofia_on_routing
Switch_ivr_originate.c:originate_on_routing
...
Nua_stack_signal
Nua_stack_invite
...
Nta_leg_tcreate
...
Perform a Send Invite request
Nta.c:outgoing_send
Tport_tsend

Call State (b): init-> calling B extension response 180 to FS
Tport_recv_event
Agent_recv_response

Processing Nua_r_invite messages

Sofia.c:sofia_process_dispatch_event
Sofia.c:our_sofia_event_callback
Sofia.c:sofia_handle_sip_r_invite

Call State (B): Calling-> proceeding FS send 180 to a ext

Nua_session.c:signal_call_state_change
Nua_stack_tevent:nua_i_state
Nua_application_event

Processing Nua_i_invite messages

Sofia.c:sofia_process_dispatch_event
Sofia.c:our_sofia_event_callback
Sofia.c:sofia_handle_sip_i_invite
Sofia_reg.c:sofia_reg_handle_register
Sofia_reg.c:sofia_reg_parse_auth

Processing Nua_i_state messages
Sofia.c:sofia_handle_sip_i_state
...
Mod_dialplan_xml.c:dialplan_hunt (Ring_ready)
Resolves the dialing scheme, executes the Lua script, and sets the channel variables.
...

Send 180
Switch_channel_mark_ring_ready

Nua_invite_server_respond
Nua_base_server_respond
Nta_incoming_mreply
Incoming_reply
Tport_tsend
Tport_resolve
Tport_by_addrinfo
Tport_prepare_and_send
Tport_send_msg
Tport_vsend

Call State (A): Init-> received

b Send Okl
Tport_recv_event
Agent_recv_response

Processing Nua_r_invite messages

Sofia.c:sofia_process_dispatch_event
Sofia.c:our_sofia_event_callback
Sofia.c:sofia_handle_sip_r_invite

Call State (b): Proceeding-> completing FS send ack to B
Nua_ack
Nua_signal:nua_r_ack
Outgoing_send
Tport_tsend

Call State (A): Received-> early
Call State (B): Completing-> ready FS send OK to a
Sofia_glue_tech_set_codec
Switch_rtp_create
Sofia_glue_negotiate_sdp
Sofia_glue_activate_rtp
...
Switch_channel_perform_answer:switch_message_indicate_answer
Switch_channel_perform_mark_answered
...
Auto_record.lua: Performing recording operations B
...
Auto_record.lua: Performing recording Operations A
...
Sofia_receive_message (Switch_message_indicate_answer)
...
Send OK
nua_respond:200
Nua_signal:nua_r_respond
Nua_stack_signal
Nua_stack_respond
Nua_server_respond
Nta_incoming_treply
Nta_incoming_mreply
Incoming_reply
Tport_tsend

Call State (a): Early-> completed a response ack
Nta.c:agent_recv_message
Nta.c:agent_recv_request

Call State (A): Completed-> ready

· After the call for a while, a actively send bye
Tport_recv_event
Agent_recv_message
Agent_recv_request
...
Sofia_on_hangup

· FS Send bye to B
Nua_bye:nua_r_bye
Nua_stack_signal
Outgoing_send
Tport_tsend

· FS Send OK to a
Nta:sent 200OK for BYE
Tport_tsend

Call State (A): Ready-> terminating
Call State (A): Terminated B sends OK to FS, responds to hang up request
Nta:received OK for BYE

State change:
Call State (B): Ready-> terminating
Call State (B): terminating-> terminated

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.