Ignore:
Timestamp:
Jan 18, 2008 6:49:29 PM (16 years ago)
Author:
bennylp
Message:

More ticket #452: SRTP creation/destruction, added use_srtp and srtp_secure_signaling in pjsua_account_config, updated pjsua

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_media.c

    r1700 r1709  
    536536        } 
    537537 
    538         if (pjsua_var.media_cfg.enable_srtp) { 
    539             pjmedia_transport *tp; 
    540             unsigned srtp_options = 0; 
    541  
    542             status = pjmedia_transport_udp_attach(pjsua_var.med_endpt, NULL, 
    543                                                   &skinfo, 0, &tp); 
    544             status = pjmedia_transport_srtp_create(pjsua_var.med_endpt, tp, 
    545                                                    srtp_options,  
    546                                                    &pjsua_var.calls[i].med_tp); 
    547         } else { 
    548             status = pjmedia_transport_udp_attach(pjsua_var.med_endpt, NULL, 
    549                                                   &skinfo, 0, 
    550                                                   &pjsua_var.calls[i].med_tp); 
    551         } 
     538        status = pjmedia_transport_udp_attach(pjsua_var.med_endpt, NULL, 
     539                                              &skinfo, 0, 
     540                                              &pjsua_var.calls[i].med_tp); 
    552541        if (status != PJ_SUCCESS) { 
    553542            pjsua_perror(THIS_FILE, "Unable to create media transport", 
     
    757746 
    758747pj_status_t pjsua_media_channel_init(pjsua_call_id call_id, 
    759                                      pjsip_role_e role) 
     748                                     pjsip_role_e role, 
     749                                     int security_level) 
    760750{ 
    761751    pjsua_call *call = &pjsua_var.calls[call_id]; 
    762  
    763     if (pjsua_var.media_cfg.enable_ice) { 
    764         pj_ice_sess_role ice_role; 
    765         pj_status_t status; 
    766  
    767         ice_role = (role==PJSIP_ROLE_UAC ? PJ_ICE_SESS_ROLE_CONTROLLING :  
    768                                            PJ_ICE_SESS_ROLE_CONTROLLED); 
    769  
    770         /* Restart ICE */ 
    771         pjmedia_transport_media_stop(call->med_tp); 
    772  
    773         status = pjmedia_ice_init_ice(call->med_tp, ice_role, NULL, NULL); 
    774         if (status != PJ_SUCCESS) 
    775             return status; 
    776     } 
    777  
    778     return PJ_SUCCESS; 
    779 } 
    780  
    781 pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id,  
    782                                            pj_pool_t *pool, 
    783                                            const pjmedia_sdp_session *rem_sdp, 
    784                                            pjmedia_sdp_session **p_sdp) 
    785 { 
    786     pjmedia_sdp_session *sdp; 
    787     pjmedia_sock_info skinfo; 
    788     pjsua_call *call = &pjsua_var.calls[call_id]; 
    789     pj_status_t status; 
     752    pjsua_acc *acc = &pjsua_var.acc[call->acc_id]; 
     753    pjmedia_srtp_use use_srtp; 
     754 
     755    PJ_UNUSED_ARG(role); 
    790756 
    791757    /* Return error if media transport has not been created yet 
     
    796762    } 
    797763 
     764    /* Stop media transport (for good measure!) */ 
     765    pjmedia_transport_media_stop(call->med_tp); 
     766     
     767    /* See if we need to use SRTP */ 
     768    use_srtp = acc->cfg.use_srtp; 
     769    if (use_srtp != PJMEDIA_SRTP_DISABLED) { 
     770        pj_status_t status; 
     771        pjmedia_transport *srtp; 
     772 
     773        if (security_level < acc->cfg.srtp_secure_signaling) { 
     774            return PJSIP_ESESSIONINSECURE; 
     775        } 
     776 
     777        /* Create SRTP */ 
     778        status = pjmedia_transport_srtp_create(pjsua_var.med_endpt,  
     779                                               call->med_tp, 
     780                                               NULL, &srtp); 
     781        if (status != PJ_SUCCESS) 
     782            return status; 
     783 
     784        /* Set SRTP as current media transport */ 
     785        call->med_tp = srtp; 
     786    } 
     787 
     788    return PJ_SUCCESS; 
     789} 
     790 
     791pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id,  
     792                                           pj_pool_t *pool, 
     793                                           const pjmedia_sdp_session *rem_sdp, 
     794                                           pjmedia_sdp_session **p_sdp) 
     795{ 
     796    enum { MAX_MEDIA = 1, MEDIA_IDX = 0 }; 
     797    pjmedia_sdp_session *sdp; 
     798    pjmedia_sock_info skinfo; 
     799    pjsua_call *call = &pjsua_var.calls[call_id]; 
     800    pj_status_t status; 
     801 
     802    /* Return error if media transport has not been created yet 
     803     * (e.g. application is starting) 
     804     */ 
     805    if (call->med_tp == NULL) { 
     806        return PJ_EBUSY; 
     807    } 
     808 
    798809    /* Get media socket info */ 
    799810    pjmedia_transport_get_info(call->med_tp, &skinfo); 
    800811 
    801812    /* Create SDP */ 
    802     status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pool, 1, 
     813    status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pool, MAX_MEDIA, 
    803814                                      &skinfo, &sdp); 
    804815    if (status != PJ_SUCCESS) 
     
    829840    } 
    830841 
    831     //if (pjsua_var.media_cfg.enable_ice) { 
    832         //status = pjmedia_transport_media_create(call->med_tp, pool, sdp, NULL); 
    833         status = pjmedia_transport_media_create(call->med_tp, pool,  
    834                                                 sdp, rem_sdp); 
    835         if (status != PJ_SUCCESS) 
    836             goto on_error; 
    837     //} 
     842    /* Give the SDP to media transport */ 
     843    status = pjmedia_transport_media_create(call->med_tp, pool,  
     844                                            sdp, rem_sdp, MEDIA_IDX); 
     845    if (status != PJ_SUCCESS) 
     846        goto on_error; 
    838847 
    839848    *p_sdp = sdp; 
     
    874883    stop_media_session(call_id); 
    875884 
    876     //if (pjsua_var.media_cfg.enable_ice) { 
    877         pjmedia_transport_media_stop(call->med_tp); 
    878     //} 
    879  
     885    pjmedia_transport_media_stop(call->med_tp); 
     886 
     887    if (call->med_tp != call->med_orig) { 
     888        pjmedia_transport_close(call->med_tp); 
     889        call->med_tp = call->med_orig; 
     890    } 
    880891    return PJ_SUCCESS; 
    881892} 
     
    962973        call->media_dir = PJMEDIA_DIR_NONE; 
    963974 
    964         /* Shutdown ICE session */ 
    965         //if (pjsua_var.media_cfg.enable_ice) { 
    966             pjmedia_transport_media_stop(call->med_tp); 
    967         //} 
     975        /* Shutdown transport's session */ 
     976        pjmedia_transport_media_stop(call->med_tp); 
    968977 
    969978        /* No need because we need keepalive? */ 
    970979 
    971980    } else { 
    972         /* Start ICE */ 
    973         //if (pjsua_var.media_cfg.enable_ice) { 
    974             status = pjmedia_transport_media_start(call->med_tp,  
    975                                                    call->inv->pool, 
    976                                                    local_sdp, remote_sdp, 0); 
    977             if (status != PJ_SUCCESS) 
    978                 return status; 
    979         //} 
     981        /* Start media transport */ 
     982        status = pjmedia_transport_media_start(call->med_tp,  
     983                                               call->inv->pool, 
     984                                               local_sdp, remote_sdp, 0); 
     985        if (status != PJ_SUCCESS) 
     986            return status; 
    980987 
    981988        /* Override ptime, if this option is specified. */ 
Note: See TracChangeset for help on using the changeset viewer.