Changeset 5417 for pjproject


Ignore:
Timestamp:
Aug 12, 2016 3:47:26 AM (8 years ago)
Author:
ming
Message:

Fixed #1951: Add callback to configure SRTP setting and key in pjsua/pjsua2

Location:
pjproject/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/swig/symbols.i

    r5273 r5417  
    4242 
    4343typedef enum pjmedia_srtp_use {PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, PJMEDIA_SRTP_MANDATORY} pjmedia_srtp_use; 
     44 
     45typedef enum pjmedia_srtp_crypto_option {PJMEDIA_SRTP_NO_ENCRYPTION  = 1, PJMEDIA_SRTP_NO_AUTHENTICATION  = 2} pjmedia_srtp_crypto_option; 
    4446 
    4547typedef enum pjmedia_vid_stream_rc_method {PJMEDIA_VID_STREAM_RC_NONE = 0, PJMEDIA_VID_STREAM_RC_SIMPLE_BLOCKING = 1} pjmedia_vid_stream_rc_method; 
  • pjproject/trunk/pjsip-apps/src/swig/symbols.lst

    r5273 r5417  
    99 
    1010pjmedia/event.h                 pjmedia_event_type 
    11 pjmedia/transport_srtp.h        pjmedia_srtp_use 
     11pjmedia/transport_srtp.h        pjmedia_srtp_use pjmedia_srtp_crypto_option 
    1212pjmedia/vid_stream.h            pjmedia_vid_stream_rc_method 
    1313pjmedia-videodev/videodev.h     pjmedia_vid_dev_index pjmedia_vid_dev_std_index pjmedia_vid_dev_cap 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r5410 r5417  
    13671367 
    13681368    /** 
     1369     * This callback is called when SRTP media transport is created. 
     1370     * Application can modify the SRTP setting \a srtp_opt to specify 
     1371     * the cryptos and keys which are going to be used. Note that 
     1372     * application should not modify the field 
     1373     * \a pjmedia_srtp_setting.close_member_tp and can only modify 
     1374     * the field \a pjmedia_srtp_setting.use for initial INVITE. 
     1375     * 
     1376     * @param call_id       Call ID 
     1377     * @param media_idx     The media index in the SDP for which this SRTP 
     1378     *                      media transport will be used. 
     1379     * @param srtp_opt      The SRTP setting. Application can modify this. 
     1380     */ 
     1381    void (*on_create_media_transport_srtp)(pjsua_call_id call_id, 
     1382                                           unsigned media_idx, 
     1383                                           pjmedia_srtp_setting *srtp_opt); 
     1384 
     1385    /** 
    13691386     * This callback can be used by application to override the account 
    13701387     * to be used to handle an incoming message. Initially, the account to 
  • pjproject/trunk/pjsip/include/pjsua2/call.hpp

    r5185 r5417  
    950950     */ 
    951951    unsigned        flags; 
     952}; 
     953 
     954/** 
     955 * SRTP crypto. 
     956 */ 
     957struct SrtpCrypto 
     958{ 
     959    /** 
     960     * Optional key. If empty, a random key will be autogenerated. 
     961     */ 
     962    string      key; 
     963 
     964    /** 
     965     * Crypto name. 
     966     */ 
     967    string      name; 
     968 
     969    /** 
     970     * Flags, bitmask from #pjmedia_srtp_crypto_option 
     971     */ 
     972    unsigned    flags; 
     973}; 
     974 
     975/** 
     976 * This structure contains parameters for Call::onCreateMediaTransportSrtp() 
     977 * callback. 
     978 */ 
     979struct OnCreateMediaTransportSrtpParam 
     980{ 
     981    /** 
     982     * The media index in the SDP for which the SRTP media transport 
     983     * will be used. 
     984     */ 
     985    unsigned                    mediaIdx; 
     986     
     987    /** 
     988     * Specify whether secure media transport should be used. Application 
     989     * can modify this only for initial INVITE. 
     990     * Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and 
     991     * PJMEDIA_SRTP_MANDATORY. 
     992     */ 
     993    pjmedia_srtp_use            srtpUse; 
     994     
     995    /** 
     996     * Application can modify this to specify the cryptos and keys 
     997     * which are going to be used. 
     998     */ 
     999    vector<SrtpCrypto>          cryptos; 
    9521000}; 
    9531001 
     
    17441792    { PJ_UNUSED_ARG(prm); } 
    17451793 
     1794    /** 
     1795     * This callback is called when SRTP media transport is created. 
     1796     * Application can modify the SRTP setting \a srtpOpt to specify 
     1797     * the cryptos and keys which are going to be used. Note that 
     1798     * application should not modify the field 
     1799     * \a pjmedia_srtp_setting.close_member_tp and can only modify 
     1800     * the field \a pjmedia_srtp_setting.use for initial INVITE. 
     1801     * 
     1802     * @param prm       Callback parameter. 
     1803     */ 
     1804    virtual void 
     1805    onCreateMediaTransportSrtp(OnCreateMediaTransportSrtpParam &prm) 
     1806    { PJ_UNUSED_ARG(prm); } 
     1807 
    17461808private: 
    17471809    Account             &acc; 
  • pjproject/trunk/pjsip/include/pjsua2/endpoint.hpp

    r5297 r5417  
    14031403                              pjmedia_transport *base_tp, 
    14041404                              unsigned flags); 
     1405    static void 
     1406    on_create_media_transport_srtp(pjsua_call_id call_id, 
     1407                                   unsigned media_idx, 
     1408                                   pjmedia_srtp_setting *srtp_opt); 
    14051409 
    14061410private: 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c

    r5384 r5417  
    14811481        else 
    14821482            srtp_opt.use = acc->cfg.use_srtp; 
     1483             
     1484        if (pjsua_var.ua_cfg.cb.on_create_media_transport_srtp) { 
     1485            pjsua_call *call = call_med->call; 
     1486            pjmedia_srtp_use srtp_use = srtp_opt.use; 
     1487 
     1488            (*pjsua_var.ua_cfg.cb.on_create_media_transport_srtp) 
     1489                (call->index, call_med->idx, &srtp_opt); 
     1490 
     1491            /* Close_member_tp must not be overwritten by app */ 
     1492            srtp_opt.close_member_tp = PJ_TRUE; 
     1493 
     1494            /* Revert SRTP usage policy if media is reinitialized */ 
     1495            if (call->inv && call->inv->state == PJSIP_INV_STATE_CONFIRMED) { 
     1496                srtp_opt.use = srtp_use; 
     1497            } 
     1498        } 
    14831499 
    14841500        status = pjmedia_transport_srtp_create(pjsua_var.med_endpt, 
  • pjproject/trunk/pjsip/src/pjsua2/endpoint.cpp

    r5297 r5417  
    12671267} 
    12681268 
     1269void Endpoint::on_create_media_transport_srtp(pjsua_call_id call_id, 
     1270                                              unsigned media_idx, 
     1271                                              pjmedia_srtp_setting *srtp_opt) 
     1272{ 
     1273    Call *call = Call::lookup(call_id); 
     1274    if (!call) { 
     1275        pjsua_call *in_call = &pjsua_var.calls[call_id]; 
     1276        if (in_call->incoming_data) { 
     1277            /* This can happen when there is an incoming call but the 
     1278             * on_incoming_call() callback hasn't been called. So we need to  
     1279             * call the callback here. 
     1280             */ 
     1281            on_incoming_call(in_call->acc_id, call_id, in_call->incoming_data); 
     1282 
     1283            /* New call should already be created by app. */ 
     1284            call = Call::lookup(call_id); 
     1285            if (!call) { 
     1286                return; 
     1287            } 
     1288        } else { 
     1289            return; 
     1290        } 
     1291    } 
     1292     
     1293    OnCreateMediaTransportSrtpParam prm; 
     1294    prm.mediaIdx = media_idx; 
     1295    prm.srtpUse  = srtp_opt->use; 
     1296    for (int i = 0; i < srtp_opt->crypto_count; i++) { 
     1297        SrtpCrypto crypto; 
     1298         
     1299        crypto.key   = pj2Str(srtp_opt->crypto[i].key); 
     1300        crypto.name  = pj2Str(srtp_opt->crypto[i].name); 
     1301        crypto.flags = srtp_opt->crypto[i].flags; 
     1302        prm.cryptos.push_back(crypto); 
     1303    } 
     1304     
     1305    call->onCreateMediaTransportSrtp(prm); 
     1306     
     1307    srtp_opt->use = prm.srtpUse; 
     1308    srtp_opt->crypto_count = prm.cryptos.size(); 
     1309    for (int i = 0; i < srtp_opt->crypto_count; i++) { 
     1310        srtp_opt->crypto[i].key   = str2Pj(prm.cryptos[i].key); 
     1311        srtp_opt->crypto[i].name  = str2Pj(prm.cryptos[i].name); 
     1312        srtp_opt->crypto[i].flags = prm.cryptos[i].flags; 
     1313    }     
     1314} 
     1315 
    12691316/////////////////////////////////////////////////////////////////////////////// 
    12701317/* 
Note: See TracChangeset for help on using the changeset viewer.