Changeset 5899 for pjproject


Ignore:
Timestamp:
Oct 17, 2018 4:38:39 AM (6 years ago)
Author:
nanang
Message:

Close #2158:

  • Added OnCallTransferRequestParam?.newCall to allow application to instantiate a new Call for the new outgoing call in transfer scenario.
  • Also added OnCallReplacedParam?.newCall mainly for informational purpose (that app should instantiate new Call for replace scenario).
Location:
pjproject/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/samples/pjsua2_demo.cpp

    r5717 r5899  
    4040     
    4141    virtual void onCallState(OnCallStateParam &prm); 
     42    virtual void onCallTransferRequest(OnCallTransferRequestParam &prm); 
     43    virtual void onCallReplaced(OnCallReplacedParam &prm); 
    4244}; 
    4345 
     
    5557        std::cout << "*** Account is being deleted: No of calls=" 
    5658                  << calls.size() << std::endl; 
     59 
     60        for (std::vector<Call *>::iterator it = calls.begin(); 
     61             it != calls.end(); ) 
     62        { 
     63            delete (*it); 
     64            it = calls.erase(it); 
     65        } 
    5766    } 
    5867     
     
    100109     
    101110    if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { 
    102         myAcc->removeCall(this); 
     111        //myAcc->removeCall(this); 
    103112        /* Delete the call */ 
    104         delete this; 
    105     } 
    106 } 
     113        //delete this; 
     114    } 
     115} 
     116 
     117void MyCall::onCallTransferRequest(OnCallTransferRequestParam &prm) 
     118{ 
     119    /* Create new Call for call transfer */ 
     120    prm.newCall = new MyCall(*myAcc); 
     121} 
     122 
     123void MyCall::onCallReplaced(OnCallReplacedParam &prm) 
     124{ 
     125    /* Create new Call for call replace */ 
     126    prm.newCall = new MyCall(*myAcc, prm.newCallId); 
     127} 
     128 
    107129 
    108130static void mainProg1(Endpoint &ep) throw(Error) 
     
    148170    // Destroy library 
    149171    std::cout << "*** PJSUA2 SHUTTING DOWN ***" << std::endl; 
    150     delete call; 
    151     delete acc; 
     172    delete acc; /* Will delete all calls too */ 
    152173} 
    153174 
     
    347368        ep.libCreate(); 
    348369 
    349         mainProg3(ep); 
     370        mainProg1(ep); 
    350371        ret = PJ_SUCCESS; 
    351372    } catch (Error & err) { 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r5872 r5899  
    10371037     *                  transferred to. 
    10381038     * @param code      Status code to be returned for the call transfer 
    1039      *                  request. On input, it contains status code 200. 
     1039     *                  request. On input, it contains status code 202. 
    10401040     */ 
    10411041    void (*on_call_transfer_request)(pjsua_call_id call_id, 
     
    10541054     *                  transferred to. 
    10551055     * @param code      Status code to be returned for the call transfer 
    1056      *                  request. On input, it contains status code 200. 
     1056     *                  request. On input, it contains status code 202. 
    10571057     * @param opt       The current call setting, application can update 
    10581058     *                  this setting for the call being transferred. 
  • pjproject/trunk/pjsip/include/pjsua2/call.hpp

    r5877 r5899  
    785785     * The destination where the call will be transferred to. 
    786786     */ 
    787     string              dstUri; 
     787    string               dstUri; 
    788788     
    789789    /** 
    790790     * Status code to be returned for the call transfer request. On input, 
    791      * it contains status code 200. 
    792      */ 
    793     pjsip_status_code   statusCode; 
     791     * it contains status code 202. 
     792     */ 
     793    pjsip_status_code    statusCode; 
    794794     
    795795    /** 
     
    797797     * for the call being transferred. 
    798798     */ 
    799     CallSetting         opt; 
     799    CallSetting          opt; 
     800 
     801    /** 
     802     * New Call derived object instantiated by application when the call 
     803     * transfer is about to be accepted. 
     804     */ 
     805    Call                *newCall; 
    800806}; 
    801807 
     
    867873     * The new call id. 
    868874     */ 
    869     pjsua_call_id       newCallId; 
     875    pjsua_call_id        newCallId; 
     876 
     877    /** 
     878     * New Call derived object instantiated by application. 
     879     */ 
     880    Call                *newCall; 
    870881}; 
    871882 
     
    17171728    /** 
    17181729     * Notify application on call being transferred (i.e. REFER is received). 
    1719      * Application can decide to accept/reject transfer request 
    1720      * by setting the code (default is 202). When this callback 
    1721      * is not implemented, the default behavior is to accept the 
    1722      * transfer. 
     1730     * Application can decide to accept/reject transfer request by setting 
     1731     * the code (default is 202). When this callback is not implemented, 
     1732     * the default behavior is to accept the transfer. 
     1733     * 
     1734     * If application decides to accept the transfer request, it must also 
     1735     * instantiate the new Call object for the transfer operation and return 
     1736     * this new Call object to prm.newCall. 
     1737     *  
     1738     * If application does not specify new Call object, library will reuse the 
     1739     * existing Call object for initiating the new call (to the transfer 
     1740     * destination). In this case, any events from both calls (transferred and 
     1741     * transferring) will be delivered to the same Call object, where the call 
     1742     * ID will be switched back and forth between callbacks. Application must 
     1743     * be careful to not destroy the Call object when receiving disconnection 
     1744     * event of the transferred call after the transfer process is completed. 
    17231745     * 
    17241746     * @param prm       Callback parameter. 
     
    17531775     * 
    17541776     * After this callback is called, normally PJSUA-API will disconnect 
    1755      * this call and establish a new call \a newCallId. 
     1777     * this call and establish a new call. To be able to control the call, 
     1778     * e.g: hold, transfer, change media parameters, application must 
     1779     * instantiate a new Call object for the new call using call ID 
     1780     * specified in prm.newCallId, and return the Call object via 
     1781     * prm.newCall. 
    17561782     * 
    17571783     * @param prm       Callback parameter. 
     
    19531979    std::vector<Media *> medias; 
    19541980    pj_pool_t           *sdp_pool; 
     1981    Call                *child;     /* New outgoing call in call transfer.  */ 
    19551982}; 
    19561983 
  • pjproject/trunk/pjsip/src/pjsua2/call.cpp

    r5878 r5899  
    450450 
    451451Call::Call(Account& account, int call_id) 
    452 : acc(account), id(call_id) 
     452: acc(account), id(call_id), userData(NULL), sdp_pool(NULL), child(NULL) 
    453453{ 
    454454    if (call_id != PJSUA_INVALID_ID) 
     
    503503{ 
    504504    Call *call = (Call*)pjsua_call_get_user_data(call_id); 
    505     if (call) 
    506         call->id = call_id; 
     505    if (call && call_id != call->id) { 
     506        if (call->child && call->child->id == PJSUA_INVALID_ID) { 
     507            /* This must be a new call from call transfer */ 
     508            call = call->child; 
     509            pjsua_call_set_user_data(call_id, call); 
     510        } 
     511        call->id = call_id; 
     512    } 
    507513    return call; 
    508514} 
     
    821827        } 
    822828        medias.clear(); 
     829 
     830        /* Remove this Call object association */ 
     831        pjsua_call_set_user_data(id, NULL); 
    823832    } 
    824833     
  • pjproject/trunk/pjsip/src/pjsua2/endpoint.cpp

    r5891 r5899  
    11921192    prm.statusCode = *code; 
    11931193    prm.opt.fromPj(*opt); 
     1194    prm.newCall = NULL; 
    11941195     
    11951196    call->onCallTransferRequest(prm); 
     
    11971198    *code = prm.statusCode; 
    11981199    *opt = prm.opt.toPj(); 
     1200    if (*code/100 <= 2) { 
     1201        if (prm.newCall) { 
     1202            /* We don't manage (e.g: create, delete) the call child, 
     1203             * so let's just override any existing child. 
     1204             */ 
     1205            call->child = prm.newCall; 
     1206            call->child->id = PJSUA_INVALID_ID; 
     1207        } else { 
     1208            PJ_LOG(4,(THIS_FILE, 
     1209                      "Warning: application reuses Call instance in " 
     1210                      "call transfer (call ID:%d)", call_id)); 
     1211        } 
     1212    } 
    11991213} 
    12001214 
     
    12551269    OnCallReplacedParam prm; 
    12561270    prm.newCallId = new_call_id; 
     1271    prm.newCall = NULL; 
    12571272     
    12581273    call->onCallReplaced(prm); 
     1274 
     1275    if (prm.newCall) { 
     1276        /* Sanity checks */ 
     1277        pj_assert(prm.newCall->id == new_call_id); 
     1278        pj_assert(prm.newCall->acc.getId() == call->acc.getId()); 
     1279        pj_assert(pjsua_call_get_user_data(new_call_id) == prm.newCall); 
     1280    } else { 
     1281        PJ_LOG(4,(THIS_FILE, 
     1282                  "Warning: application has not created new Call instance " 
     1283                  "for call replace (old call ID:%d, new call ID: %d)", 
     1284                  old_call_id, new_call_id)); 
     1285    } 
    12591286} 
    12601287 
Note: See TracChangeset for help on using the changeset viewer.