Asterisk source code parsing-SIP call

Source: Internet
Author: User
Is the call flowchart of Asterisk:
We use the call process of SIP as an example to describe the call process of other channels.
The call process (incoming) is as follows:
Do_monitor-> sipsock_read-> handle_request-> handle_request_invite-> sip_new/ast_pbx_start-> pbx_thread->__ ast_pbx_run
-> Ast_spawn_extension-> pbx_extension_helper-> pbx_exec-> execute dialplan
When the chan_sip module is loaded, an independent listening thread do_monitor is started to continuously listen for External messages on the SIP port. When a SIP user calls the called number, the do_monitor of chan_sip calls the sipsock_read function, after receiving the invite message on the SIP port, call handle_request and handle_request_invite for processing. In handle_request_invite, first parse the invite message, analyze the service attributes of the SIP user, confirm that the user is called, and then call sip_new to apply for channel resources, call the ast_pbx_start function to start a pbx_thread to process the call. The pbx_thread thread calls _ ast_pbx_run.
_ Ast_pbx_run is a key function linking dialplan and kernel. It first calls the ast_exists_extension function, matches the corresponding dialplan according to the context attribute of the extension number, and then enters a for endless loop, execute the statements in the context corresponding to dialplan one by one.
The pbx_extension_helper function calls pbx_extension_helper. In pbx_extension_helper, after pbx_find_extension is called to locate the corresponding context, the dialplan execution statement "executing..." is printed through verbose ......", At the same time, pbx_exec is called to execute the dialplan. Execute the dial statement to call the called object.
In the process of waiting for the called connection, the media negotiation process is completed, and a 180 or OK message is sent to the caller.
When other users call the SIP user of Asterisk, the function call process (outbound) is as follows: Dial-> dial_exec-> dial_exec_full-> ast_request/ast_call/wait_for_answer/listener, pbx_exec calls the interface function dial_exec of application dial, and dial_exec calls dial_exec_full.

In dial_exec_full, first call ast_request and call the callback function sip_request_call corresponding to chan_sip in ast_request to apply for channel resources for the called SIP user. Then, call ast_call and call the callback function sip_call corresponding to chan_sip in ast_call to send an INVITE message to the called SIP user.
Then the call thread will call wait_for_answer to wait for the called connection. When the call is connected, that is, the wait_for_answer function returns, the ast_bridge_call bridge media is called in dial_exec_full, so that the call is formally connected. When the listener thread of chan_sip receives the bye message, call handle_request_bye to locate the corresponding channel and execute hangup to release the call.

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.