Changeset 3585


Ignore:
Timestamp:
Jun 16, 2011 5:10:45 AM (13 years ago)
Author:
ming
Message:

Closed #1173: PJSUA callback to allow creation of custom media transports by application

Location:
pjproject/branches/1.x/pjsip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.x/pjsip/include/pjsua-lib/pjsua.h

    r3570 r3585  
    419419                                                 registration callback. */ 
    420420} pjsua_reg_info; 
     421 
     422 
     423/** 
     424 * This enumeration specifies the options for custom media transport creation. 
     425 */ 
     426typedef enum pjsua_create_media_transport_flag 
     427{ 
     428   /** 
     429    * This flag indicates that the media transport must also close its 
     430    * "member" or "child" transport when pjmedia_transport_close() is 
     431    * called. If this flag is not specified, then the media transport 
     432    * must not call pjmedia_transport_close() of its member transport. 
     433    */ 
     434   PJSUA_MED_TP_CLOSE_MEMBER = 1 
     435 
     436} pjsua_create_media_transport_flag; 
    421437 
    422438 
     
    919935                                   pj_status_t status, void *param); 
    920936 
     937    /** 
     938     * This callback can be used by application to implement custom media 
     939     * transport adapter for the call, or to replace the media transport 
     940     * with something completely new altogether. 
     941     * 
     942     * This callback is called when a new call is created. The library has 
     943     * created a media transport for the call, and it is provided as the 
     944     * \a base_tp argument of this callback. Upon returning, the callback 
     945     * must return an instance of media transport to be used by the call. 
     946     * 
     947     * @param call_id       Call ID 
     948     * @param media_idx     The media index in the SDP for which this media 
     949     *                      transport will be used. 
     950     * @param base_tp       The media transport which otherwise will be 
     951     *                      used by the call has this callback not been 
     952     *                      implemented. 
     953     * @param flags         Bitmask from pjsua_create_media_transport_flag. 
     954     * 
     955     * @return              The callback must return an instance of media 
     956     *                      transport to be used by the call. 
     957     */ 
     958    pjmedia_transport* (*on_create_media_transport)(pjsua_call_id call_id, 
     959                                                    unsigned media_idx, 
     960                                                    pjmedia_transport *base_tp, 
     961                                                    unsigned flags); 
     962 
    921963} pjsua_callback; 
    922964 
  • pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_media.c

    r3571 r3585  
    11751175    pjsua_call *call = &pjsua_var.calls[call_id]; 
    11761176    pj_status_t status; 
     1177    pj_bool_t use_custom_med_tp = PJ_FALSE; 
     1178    unsigned custom_med_tp_flags = 0; 
    11771179 
    11781180#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 
     
    11931195    } 
    11941196 
     1197    if (!call->med_orig && 
     1198        pjsua_var.ua_cfg.cb.on_create_media_transport) 
     1199    { 
     1200        use_custom_med_tp = PJ_TRUE; 
     1201    } 
     1202 
    11951203#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 
    11961204    /* This function may be called when SRTP transport already exists  
    11971205     * (e.g: in re-invite, update), don't need to destroy/re-create. 
    11981206     */ 
    1199     if (!call->med_orig || call->med_tp == call->med_orig) { 
     1207    if (!call->med_orig) { 
    12001208 
    12011209        /* Check if SRTP requires secure signaling */ 
     
    12111219        pjmedia_srtp_setting_default(&srtp_opt); 
    12121220        srtp_opt.close_member_tp = PJ_FALSE; 
     1221        if (use_custom_med_tp) 
     1222            custom_med_tp_flags |= PJSUA_MED_TP_CLOSE_MEMBER; 
    12131223        /* If media session has been ever established, let's use remote's  
    12141224         * preference in SRTP usage policy, especially when it is stricter. 
     
    12681278    PJ_LOG(4,(THIS_FILE, "Media index %d selected for call %d", 
    12691279              call->audio_idx, call->index)); 
     1280 
     1281    if (use_custom_med_tp) { 
     1282        /* Use custom media transport returned by the application */ 
     1283        call->med_tp = (*pjsua_var.ua_cfg.cb.on_create_media_transport)( 
     1284                           call_id, call->audio_idx, call->med_tp, 
     1285                           custom_med_tp_flags); 
     1286        if (!call->med_tp) { 
     1287            if (sip_err_code) *sip_err_code = PJSIP_SC_NOT_ACCEPTABLE; 
     1288            pjsua_media_channel_deinit(call_id); 
     1289            return PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_NOT_ACCEPTABLE); 
     1290        } 
     1291    } 
    12701292 
    12711293    /* Create the media transport */ 
     
    15441566        pjmedia_transport_close(call->med_tp); 
    15451567        call->med_tp = call->med_orig; 
     1568        call->med_orig = NULL; 
    15461569    } 
    15471570 
Note: See TracChangeset for help on using the changeset viewer.