The following analysis is based on the Linphone version I have modified internally.
Linphone includes the SIP protocol parsing, multimedia codec and RTP transmission functions, these functions are done through different components division of labor, I will analyze the next Linphone
Those threads that have appeared in life.
The first, of course, is the main thread, which is the UI thread, which is usually considered an activity, which is responsible for drawing the interface, initializing the Linphone kernel library to
And the invocation of the function interface.
The second thread is a SIP protocol processing thread that is created when the main thread initializes the Linphone internal library:
Osip_thread_create (20000, _exosip_thread, NULL);
This thread listens to the SIP socket interface, is responsible for the SIP message sends, receives, analyzes the SIP message and does the protocol processing, finally invokes the various business callback function to do the further processing.
The third thread is a loop created by Linphonemanager after initializing the Linphone internal library, which loops through calls to Linphone_core_iterate and handles various
Osip event and call status changes.
The fourth thread is an audio stream that is created by the loop thread after the session is established. Responsible for the audio stream codec, and the audio encoding data of the RTP send receive.
The fifth thread is a video stream that is created by the loop thread after the session is established. Responsible for the codec of video stream, and the RTP sending and receiving of video encoded data.
The following analysis of some common scenarios to analyze how these threads work.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +
Scene One, click on the Decode Dial key to initiate a point-to-point call
---------------------------------------------------------------
When the user taps the dialing key, the main line thread's onclick function executes, calling the Linphone library's call function through JNI, this function does some initialization and then calls the SIP call
Interface to add a ' initiate call ' transaction to the SIP's transaction queue.
Code Invocation Process:
OnClick ()
|
The Java method for JNI invocation
|
C Method for JNI invocation
|
LINPHONE_CORE_INVITE_ADDRESS_P2P ()
|
Linphone_core_start_invite ()
|
Sal_call ()
|
Exosip_call_send_initial_invite ()
|
Osip_transaction_add_event ()
|
Osip_fifo_add ()
--------------------------------------------------------------------------
The SIP protocol thread then detects the ' initiating call ' transaction and processes the transaction.
Exosip_execute ()
|
Osip_ict_execute ()
|
Osip_fifo_tryget ()
Osip_transaction_execute ()
|
__ICT_GET_FSM ()
Fsm_callmethod ()
Transition->method ()
Ict_snd_invite ()
|
__osip_message_callback (Osip_ict_invite_sent, ICT, ict->orig_request);
|
Cb_sndinvite ()
The SIP's invite message is sent to the address in the function ict_snd_invite, followed by the callback function Cb_sndinvite (), which is used to notify Linphone, ' initiate the call
Called ' request is complete. We can also do some of our custom processing in this callback.
---------------------------------------------------------------
When the target machine receives the SIP's invite message, if the call is answered by pressing the answer button, the target will reply to a 200 message to the caller (200 = OK), and the caller
When a 200 message is received, a SIP event is generated, and then the loop thread polls for the SIP event and processes it. Let's look at the code flow. The first is the SIP protocol thread:
---------------------------------------------------------------
Exosip_execute ()
|
Osip_ict_execute ()
|
Osip_fifo_tryget ()
Osip_transaction_execute ()
|
__ICT_GET_FSM ()
Fsm_callmethod ()
Transition->method ()
Ict_rcv_2xx ()
|
__osip_message_callback (osip_ict_status_2xx_received, ICT, EVT->SIP);
|
Cb_rcv2xx ()
|
Report_event ()
|
Exosip_event_add ();
---------------------------------------------------------------------
Then the loop thread:
Sal_iterate ()
|
Exosip_event_wait ();
Process_event ();
|
Call_accepted ()
|
Sal->callbacks.call_accepted (OP);
||
Call_accepted ()
|
Linphone_core_update_streams ()
|
Linphone_call_start_media_streams ()
|
-------------------------------------------------------------------------------
| |
Linphone_call_start_audio_stream () Linphone_call_start_video_stream ()
| |
Audio_stream_start_full () Video_stream_start ()
| |
Stream->ticker=ms_ticker_new (); Stream->ticker = Ms_ticker_new ();
The function ms_ticker_new () creates a thread (that is, the audio thread or video stream), which is implemented by looping through the process method of the filter.
The following is a detailed description of the video streamline process as an example.
-----------------------------------------------------------------------------------
Linphone the video call as an assembly line, each link in the pipeline is responsible for one step. Then there are two lines of video call:
1. Camera Capture-----Video encoding-----RTP send
2. RTP Receive-----Video decoding-----video display
Each loop is implemented as a filter, and the filter needs to implement a fixed number of interfaces: Init, pre_process, process, post_process, UnInit. Filter's Process
The function receives input from the other filter, which is internally processed and passed to the predetermined filter.
Linphone depending on the needs of the different filter link into a pipeline, a pipeline containing a source filter, an output filter (export can also have 2) and a number of
Between the filter, the data is generated from the source filter, and the data stream is passed to the next filter in the process method, and the next filter is processed to pass the data stream to the next
filter, so until the last output filter.
Combined to the video capture is the camera plug-in complete video of YUV data collection, and passed to the encoder plug-in, encoder plug-in to complete the video encoding, and will encode the data
Passed to the RTP send plug-in, the RTP send plug-in packages the encoded data and then passes it through the socket to the network.
------------------------------------------------------------------------------------
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"Original: http://blog.csdn.net/dxpqxb/article/details/7679875"