Ignore:
Timestamp:
Oct 1, 2013 9:41:01 AM (11 years ago)
Author:
bennylp
Message:

Re #1519:

  • Account API (prototype)
  • Account config implementation
  • Refactoring in types, endpoint, etc for better consistency
  • Should compile ok with make but not running yet
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/endpoint.cpp

    r4598 r4608  
    1818 */ 
    1919#include <pjsua2/endpoint.hpp> 
     20#include "util.hpp" 
    2021 
    2122using namespace pj; 
     
    2930{ 
    3031    pj_uint32_t         signature; 
    31     TimerCompleteParam  prm; 
     32    OnTimerParam        prm; 
    3233    pj_timer_entry      entry; 
    3334}; 
     
    3536 
    3637/////////////////////////////////////////////////////////////////////////////// 
     38 
     39UaConfig::UaConfig() 
     40{ 
     41    pjsua_config ua_cfg; 
     42 
     43    pjsua_config_default(&ua_cfg); 
     44    fromPj(ua_cfg); 
     45} 
     46 
     47void UaConfig::fromPj(const pjsua_config &ua_cfg) 
     48{ 
     49    unsigned i; 
     50 
     51    this->maxCalls = ua_cfg.max_calls; 
     52    this->threadCnt = ua_cfg.thread_cnt; 
     53    this->userAgent = pj2Str(ua_cfg.user_agent); 
     54 
     55    for (i=0; i<ua_cfg.nameserver_count; ++i) { 
     56        this->nameserver.push_back(pj2Str(ua_cfg.nameserver[i])); 
     57    } 
     58 
     59    for (i=0; i<ua_cfg.stun_srv_cnt; ++i) { 
     60        this->stunServer.push_back(pj2Str(ua_cfg.stun_srv[i])); 
     61    } 
     62 
     63    this->stunIgnoreFailure = ua_cfg.stun_ignore_failure; 
     64    this->natTypeInSdp = ua_cfg.nat_type_in_sdp; 
     65    this->mwiUnsolicitedEnabled = ua_cfg.enable_unsolicited_mwi; 
     66} 
     67 
     68pjsua_config UaConfig::toPj() const 
     69{ 
     70    unsigned i; 
     71    pjsua_config pua_cfg; 
     72 
     73    pjsua_config_default(&pua_cfg); 
     74 
     75    pua_cfg.max_calls = this->maxCalls; 
     76    pua_cfg.thread_cnt = this->threadCnt; 
     77    pua_cfg.user_agent = str2Pj(this->userAgent); 
     78 
     79    for (i=0; i<this->nameserver.size() && i<PJ_ARRAY_SIZE(pua_cfg.nameserver); 
     80         ++i) 
     81    { 
     82        pua_cfg.nameserver[i] = str2Pj(this->nameserver[i]); 
     83    } 
     84    pua_cfg.nameserver_count = i; 
     85 
     86    for (i=0; i<this->stunServer.size() && i<PJ_ARRAY_SIZE(pua_cfg.stun_srv); 
     87         ++i) 
     88    { 
     89        pua_cfg.stun_srv[i] = str2Pj(this->stunServer[i]); 
     90    } 
     91    pua_cfg.stun_srv_cnt = i; 
     92 
     93    pua_cfg.nat_type_in_sdp = this->natTypeInSdp; 
     94    pua_cfg.enable_unsolicited_mwi = this->mwiUnsolicitedEnabled; 
     95 
     96    return pua_cfg; 
     97} 
     98 
     99/////////////////////////////////////////////////////////////////////////////// 
     100 
     101LogConfig::LogConfig() 
     102{ 
     103    pjsua_logging_config lc; 
     104 
     105    pjsua_logging_config_default(&lc); 
     106    fromPj(lc); 
     107} 
     108 
     109void LogConfig::fromPj(const pjsua_logging_config &lc) 
     110{ 
     111    this->msgLogging = lc.msg_logging; 
     112    this->level = lc.level; 
     113    this->consoleLevel = lc.console_level; 
     114    this->decor = lc.decor; 
     115    this->filename = pj2Str(lc.log_filename); 
     116    this->fileFlags = lc.log_file_flags; 
     117    this->writer = NULL; 
     118} 
     119 
     120pjsua_logging_config LogConfig::toPj() const 
     121{ 
     122    pjsua_logging_config lc; 
     123 
     124    pjsua_logging_config_default(&lc); 
     125 
     126    lc.msg_logging = this->msgLogging; 
     127    lc.level = this->level; 
     128    lc.console_level = this->consoleLevel; 
     129    lc.decor = this->decor; 
     130    lc.log_file_flags = this->fileFlags; 
     131    lc.log_filename = str2Pj(this->filename); 
     132 
     133    return lc; 
     134} 
     135 
     136/////////////////////////////////////////////////////////////////////////////// 
     137 
     138MediaConfig::MediaConfig() 
     139{ 
     140    pjsua_media_config mc; 
     141 
     142    pjsua_media_config_default(&mc); 
     143    fromPj(mc); 
     144} 
     145 
     146void MediaConfig::fromPj(const pjsua_media_config &mc) 
     147{ 
     148    this->clockRate = mc.clock_rate; 
     149    this->sndClockRate = mc.snd_clock_rate; 
     150    this->channelCount = mc.channel_count; 
     151    this->audioFramePtime = mc.audio_frame_ptime; 
     152    this->maxMediaPorts = mc.max_media_ports; 
     153    this->hasIoqueue = mc.has_ioqueue; 
     154    this->threadCnt = mc.thread_cnt; 
     155    this->quality = mc.quality; 
     156    this->ptime = mc.ptime; 
     157    this->noVad = mc.no_vad; 
     158    this->ilbcMode = mc.ilbc_mode; 
     159    this->txDropPct = mc.tx_drop_pct; 
     160    this->rxDropPct = mc.rx_drop_pct; 
     161    this->ecOptions = mc.ec_options; 
     162    this->ecTailLen = mc.ec_tail_len; 
     163    this->sndRecLatency = mc.snd_rec_latency; 
     164    this->sndPlayLatency = mc.snd_play_latency; 
     165    this->jbInit = mc.jb_init; 
     166    this->jbMinPre = mc.jb_min_pre; 
     167    this->jbMaxPre = mc.jb_max_pre; 
     168    this->jbMax = mc.jb_max; 
     169    this->sndAutoCloseTime = mc.snd_auto_close_time; 
     170    this->vidPreviewEnableNative = mc.vid_preview_enable_native; 
     171} 
     172 
     173pjsua_media_config MediaConfig::toPj() const 
     174{ 
     175    pjsua_media_config mcfg; 
     176 
     177    pjsua_media_config_default(&mcfg); 
     178 
     179    mcfg.clock_rate = this->clockRate; 
     180    mcfg.snd_clock_rate = this->sndClockRate; 
     181    mcfg.channel_count = this->channelCount; 
     182    mcfg.audio_frame_ptime = this->audioFramePtime; 
     183    mcfg.max_media_ports = this->maxMediaPorts; 
     184    mcfg.has_ioqueue = this->hasIoqueue; 
     185    mcfg.thread_cnt = this->threadCnt; 
     186    mcfg.quality = this->quality; 
     187    mcfg.ptime = this->ptime; 
     188    mcfg.no_vad = this->noVad; 
     189    mcfg.ilbc_mode = this->ilbcMode; 
     190    mcfg.tx_drop_pct = this->txDropPct; 
     191    mcfg.rx_drop_pct = this->rxDropPct; 
     192    mcfg.ec_options = this->ecOptions; 
     193    mcfg.ec_tail_len = this->ecTailLen; 
     194    mcfg.snd_rec_latency = this->sndRecLatency; 
     195    mcfg.snd_play_latency = this->sndPlayLatency; 
     196    mcfg.jb_init = this->jbInit; 
     197    mcfg.jb_min_pre = this->jbMinPre; 
     198    mcfg.jb_max_pre = this->jbMaxPre; 
     199    mcfg.jb_max = this->jbMax; 
     200    mcfg.snd_auto_close_time = this->sndAutoCloseTime; 
     201    mcfg.vid_preview_enable_native = this->vidPreviewEnableNative; 
     202 
     203    return mcfg; 
     204} 
     205 
     206 
     207/////////////////////////////////////////////////////////////////////////////// 
    37208/* 
    38209 * Endpoint instance 
     
    51222void Endpoint::testException() throw(Error) 
    52223{ 
    53     PJSUA2_CHECK_RAISE_ERROR("Endpoint::testException()", PJ_EINVALIDOP); 
     224    PJSUA2_CHECK_RAISE_ERROR(PJ_EINVALIDOP); 
    54225} 
    55226 
     
    82253        return; 
    83254 
    84     NatCheckStunServersCompleteParam prm; 
     255    OnNatCheckStunServersCompleteParam prm; 
    85256 
    86257    prm.userData = res->token; 
     
    106277        return; 
    107278 
    108     ep.epCallback->OnTimerComplete(ut->prm); 
     279    ep.epCallback->onTimer(ut->prm); 
    109280} 
    110281 
     
    116287        return; 
    117288 
    118     NatDetectionCompleteParam prm; 
     289    OnNatDetectionCompleteParam prm; 
    119290 
    120291    prm.status = res->status; 
     
    135306        return; 
    136307 
    137     TransportStateChangedParam prm; 
     308    OnTransportStateParam prm; 
    138309 
    139310    prm.hnd = (TransportHandle)tp; 
     
    141312    prm.lastError = info ? info->status : PJ_SUCCESS; 
    142313 
    143     ep.epCallback->onTransportStateChanged(prm); 
     314    ep.epCallback->onTransportState(prm); 
    144315} 
    145316 
     
    153324 
    154325    status = pjsua_create(); 
    155     PJSUA2_CHECK_RAISE_ERROR("Endpoint::libCreate()", status); 
     326    PJSUA2_CHECK_RAISE_ERROR(status); 
    156327} 
    157328 
     
    186357    /* Init! */ 
    187358    status = pjsua_init(&ua_cfg, &log_cfg, &med_cfg); 
    188     PJSUA2_CHECK_RAISE_ERROR("Endpoint::libInit()", status); 
     359    PJSUA2_CHECK_RAISE_ERROR(status); 
    189360} 
    190361 
     
    194365 
    195366    status = pjsua_start(); 
    196     PJSUA2_CHECK_RAISE_ERROR("Endpoint::libStart()", status); 
     367    PJSUA2_CHECK_RAISE_ERROR(status); 
    197368} 
    198369 
     
    210381    } 
    211382 
    212     PJSUA2_CHECK_RAISE_ERROR("Endpoint::libDestroy()", status); 
     383    PJSUA2_CHECK_RAISE_ERROR(status); 
    213384} 
    214385 
     
    271442    if (status != PJ_SUCCESS) { 
    272443        delete ut; 
    273         PJSUA2_CHECK_RAISE_ERROR("Endpoint::utilTimerSchedule()", status); 
     444        PJSUA2_CHECK_RAISE_ERROR(status); 
    274445    } 
    275446 
     
    302473 
    303474    status = pj_ssl_cipher_get_availables(ciphers, &count); 
    304     PJSUA2_CHECK_RAISE_ERROR("Endpoint::utilSslGetAvailableCiphers()", status); 
     475    PJSUA2_CHECK_RAISE_ERROR(status); 
    305476 
    306477    return IntVector(ciphers, ciphers + count); 
     
    319490 
    320491    status = pjsua_detect_nat_type(); 
    321     PJSUA2_CHECK_RAISE_ERROR("Endpoint::natDetectType()", status); 
     492    PJSUA2_CHECK_RAISE_ERROR(status); 
    322493} 
    323494 
     
    328499 
    329500    status = pjsua_get_nat_type(&type); 
    330     PJSUA2_CHECK_RAISE_ERROR("Endpoint::natGetType()", status); 
     501    PJSUA2_CHECK_RAISE_ERROR(status); 
    331502 
    332503    return type; 
     
    349520    status = pjsua_resolve_stun_servers(count, srv, wait, token, 
    350521                                        &Endpoint::stun_resolve_cb); 
    351     PJSUA2_CHECK_RAISE_ERROR("Endpoint::natCheckStunServers()", status); 
     522    PJSUA2_CHECK_RAISE_ERROR(status); 
    352523} 
    353524 
     
    358529 
    359530    status = pjsua_cancel_stun_resolution(token, notify_cb); 
    360     PJSUA2_CHECK_RAISE_ERROR("Endpoint::natCancelCheckStunServers()", status); 
     531    PJSUA2_CHECK_RAISE_ERROR(status); 
    361532} 
    362533 
     
    374545    tcfg = cfg.toPj(); 
    375546    status = pjsua_transport_create(type, &tcfg, &tid); 
    376     PJSUA2_CHECK_RAISE_ERROR("Endpoint::transportCreate()", status); 
     547    PJSUA2_CHECK_RAISE_ERROR(status); 
    377548 
    378549    return tid; 
     
    386557 
    387558    status = pjsua_enum_transports(tids, &count); 
    388     PJSUA2_CHECK_RAISE_ERROR("Endpoint::transportEnum()", status); 
     559    PJSUA2_CHECK_RAISE_ERROR(status); 
    389560 
    390561    return IntVector(tids, tids+count); 
     
    397568 
    398569    status = pjsua_transport_get_info(id, &tinfo); 
    399     PJSUA2_CHECK_RAISE_ERROR("Endpoint::transportGetInfo()", status); 
     570    PJSUA2_CHECK_RAISE_ERROR(status); 
    400571 
    401572    return TransportInfo(tinfo); 
     
    407578 
    408579    status = pjsua_transport_set_enable(id, enabled); 
    409     PJSUA2_CHECK_RAISE_ERROR("Endpoint::transportSetEnable()", status); 
     580    PJSUA2_CHECK_RAISE_ERROR(status); 
    410581} 
    411582 
     
    415586 
    416587    status = pjsua_transport_close(id, PJ_FALSE); 
    417     PJSUA2_CHECK_RAISE_ERROR("Endpoint::transportClose()", status); 
    418 } 
    419  
     588    PJSUA2_CHECK_RAISE_ERROR(status); 
     589} 
     590 
Note: See TracChangeset for help on using the changeset viewer.