Changes between Initial Version and Version 1 of pjsip-doc/call


Ignore:
Timestamp:
Dec 4, 2013 1:56:06 AM (10 years ago)
Author:
bennylp
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • pjsip-doc/call

    v1 v1  
     1{{{ 
     2#!rst 
     3 
     4Calls 
     5===== 
     6Calls are represented by ​Call class. 
     7 
     8Subclassing the Call Class 
     9------------------------------------ 
     10To use the Call class, application MUST create its own subclass, such as:: 
     11 
     12    class MyCall : public Call 
     13    { 
     14    public: 
     15        MyCall(Account &acc, int call_id = PJSUA_INVALID_ID) 
     16        : Call(acc, call_id) 
     17        { } 
     18 
     19        ~MyCall() 
     20        { } 
     21 
     22        // Notification when call's state has changed. 
     23        virtual void onCallState(OnCallStateParam &prm); 
     24 
     25        // Notification when call's media state has changed. 
     26        virtual void onCallMediaState(OnCallMediaStateParam &prm); 
     27    }; 
     28 
     29In its subclass, application can implement the call callbacks, which is basically used to process events related to the call, such as call state change or incoming call transfer request. 
     30 
     31Making Outgoing Calls 
     32-------------------------------------- 
     33Making outgoing call is simple, just invoke ​makeCall() method of the Call object. Assuming you have the Account object as acc variable and destination URI string in dst_uri, you can initiate outgoing call with the snippet below:: 
     34 
     35    Call *call = new MyCall(*acc); 
     36    CallOpParam prm(true); // Use default call settings 
     37    try { 
     38        call->makeCall(dest_uri, prm); 
     39    } catch(Error& err) { 
     40    } 
     41 
     42The snippet above creates a Call object and initiates outgoing call to dst_uri using the default call settings. Subsequent operations to the call can use the method in the ​call instance, and events to the call will be reported to the callback. More on the callback will be explained a bit later. 
     43 
     44Receiving Incoming Calls 
     45-------------------------------------- 
     46Incoming calls are reported as ​onIncomingCall() of the ​Account class. You must derive a class from the Account class to handle incoming calls. 
     47 
     48Below is a sample code of the callback implementation:: 
     49 
     50    void MyAccount::onIncomingCall(OnIncomingCallParam &iprm) 
     51    { 
     52        Call *call = new MyCall(*this, iprm.callId); 
     53        CallOpParam prm; 
     54        prm.statusCode = (pjsip_status_code)200; 
     55        call->answer(prm); 
     56    } 
     57 
     58For incoming calls, the call instance is created in the callback parameter as shown above. Application should make sure to store the call instance during the lifetime of the call (that is until the call is disconnected). 
     59 
     60Call Properties 
     61------------------- 
     62All call properties such as state, media state, remote peer information, etc. are stored as ​CallInfo class, which can be retrieved from the call object with using getInfo() method of the Call. 
     63 
     64Call Disconnection 
     65-------------------------------------- 
     66Call disconnection event is a special event since once the callback that reports this event returns, the call is no longer valid and any operations invoked to the call object will raise error exception. Thus, it is recommended to delete the call object inside the callback. 
     67 
     68The call disconnection is reported in ​onCallState() method of ​Call and it can be detected as follows:: 
     69 
     70    void MyCall::onCallState(OnCallStateParam &prm) 
     71    { 
     72        CallInfo ci = getInfo(); 
     73        if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { 
     74            /* Delete the call */ 
     75            delete this; 
     76        } 
     77    } 
     78 
     79Working with Call's Audio Media 
     80------------------------------------------------- 
     81You can only operate with the call's audio media (e.g. connecting the call to the sound device in the conference bridge) when the call's audio media is ready (or active). The changes to the call's media state is reported in ​onCallMediaState() callback, and if the call’s audio media is ready (or active) the function getMedia() will return a valid audio media. 
     82 
     83Below is a sample code to connect the call to the sound device when the media is active:: 
     84 
     85    void MyCall::onCallMediaState(OnCallMediaStateParam &prm) 
     86    { 
     87        CallInfo ci = getInfo(); 
     88        // Iterate all medias 
     89        for (unsigned i = 0; i < ci.media.size(); i++) { 
     90            if (getMedia(i)) { // Check if the media is valid 
     91                AudioMedia *aud_med = getMedia(i); 
     92                // Connect the call audio media to sound device 
     93                aud_med->startTransmit(); 
     94                ->startTransmit(*aud_med); 
     95            } 
     96        } 
     97    } 
     98 
     99When the audio media becomes inactive (for example when the call is put on hold), there is no need to stop the audio media's transmission to/from the sound device since the call's audio media will be removed automatically from the conference bridge when it's no longer valid, and this will automatically remove all connections to/from the call. 
     100 
     101Call Operations 
     102-------------------------------------- 
     103Some of the operations to the Call object, such as making outgoing call, answering, holding, sending re-INVITE, etc. Please see the reference documentation of Call for more info. 
     104 
     105}}}