- Timestamp:
- Oct 1, 2013 9:41:01 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/types.cpp
r4598 r4608 18 18 */ 19 19 #include <pjsua2/types.hpp> 20 #include "util.hpp" 20 21 21 22 using namespace pj; … … 23 24 24 25 /////////////////////////////////////////////////////////////////////////////// 25 inline pj_str_t str2Pj(const string &is)26 {27 pj_str_t os;28 os.ptr = (char*)is.c_str();29 os.slen = is.size();30 return os;31 }32 33 inline string pj2Str(const pj_str_t &is)34 {35 return string(is.ptr, is.slen);36 }37 38 ///////////////////////////////////////////////////////////////////////////////39 26 40 27 Error::Error() 41 : status(PJ_SUCCESS) 28 : status(PJ_SUCCESS), srcLine(0) 42 29 { 43 30 } 44 31 45 32 Error::Error( pj_status_t prm_status, 33 const string &prm_title, 46 34 const string &prm_reason, 47 const string &prm_title,48 35 const string &prm_src_file, 49 36 int prm_src_line) 50 : status(prm_status), reason(prm_reason), title(prm_title),37 : status(prm_status), title(prm_title), reason(prm_reason), 51 38 srcFile(prm_src_file), srcLine(prm_src_line) 52 39 { … … 58 45 } 59 46 60 ///////////////////////////////////////////////////////////////////////////////61 62 AuthCredInfo::AuthCredInfo()63 : dataType(0)64 {65 }66 67 ///////////////////////////////////////////////////////////////////////////////68 69 UaConfig::UaConfig()70 {71 pjsua_config ua_cfg;72 73 pjsua_config_default(&ua_cfg);74 fromPj(ua_cfg);75 }76 77 void UaConfig::fromPj(const pjsua_config &ua_cfg)78 {79 unsigned i;80 81 this->maxCalls = ua_cfg.max_calls;82 this->threadCnt = ua_cfg.thread_cnt;83 this->userAgent = pj2Str(ua_cfg.user_agent);84 85 for (i=0; i<ua_cfg.nameserver_count; ++i) {86 this->nameserver.push_back(pj2Str(ua_cfg.nameserver[i]));87 }88 89 for (i=0; i<ua_cfg.stun_srv_cnt; ++i) {90 this->stunServer.push_back(pj2Str(ua_cfg.stun_srv[i]));91 }92 93 this->stunIgnoreFailure = ua_cfg.stun_ignore_failure;94 this->natTypeInSdp = ua_cfg.nat_type_in_sdp;95 this->mwiUnsolicitedEnabled = ua_cfg.enable_unsolicited_mwi;96 }97 98 pjsua_config UaConfig::toPj() const99 {100 unsigned i;101 pjsua_config pua_cfg;102 103 pjsua_config_default(&pua_cfg);104 105 pua_cfg.max_calls = this->maxCalls;106 pua_cfg.thread_cnt = this->threadCnt;107 pua_cfg.user_agent = str2Pj(this->userAgent);108 109 for (i=0; i<this->nameserver.size() && i<PJ_ARRAY_SIZE(pua_cfg.nameserver);110 ++i)111 {112 pua_cfg.nameserver[i] = str2Pj(this->nameserver[i]);113 }114 pua_cfg.nameserver_count = i;115 116 for (i=0; i<this->stunServer.size() && i<PJ_ARRAY_SIZE(pua_cfg.stun_srv);117 ++i)118 {119 pua_cfg.stun_srv[i] = str2Pj(this->stunServer[i]);120 }121 pua_cfg.stun_srv_cnt = i;122 123 pua_cfg.nat_type_in_sdp = this->natTypeInSdp;124 pua_cfg.enable_unsolicited_mwi = this->mwiUnsolicitedEnabled;125 126 return pua_cfg;127 }128 129 ///////////////////////////////////////////////////////////////////////////////130 131 LogConfig::LogConfig()132 {133 pjsua_logging_config lc;134 135 pjsua_logging_config_default(&lc);136 fromPj(lc);137 }138 139 void LogConfig::fromPj(const pjsua_logging_config &lc)140 {141 this->msgLogging = lc.msg_logging;142 this->level = lc.level;143 this->consoleLevel = lc.console_level;144 this->decor = lc.decor;145 this->filename = pj2Str(lc.log_filename);146 this->fileFlags = lc.log_file_flags;147 this->writer = NULL;148 }149 150 pjsua_logging_config LogConfig::toPj() const151 {152 pjsua_logging_config lc;153 154 pjsua_logging_config_default(&lc);155 156 lc.msg_logging = this->msgLogging;157 lc.level = this->level;158 lc.console_level = this->consoleLevel;159 lc.decor = this->decor;160 lc.log_file_flags = this->fileFlags;161 lc.log_filename = str2Pj(this->filename);162 163 return lc;164 }165 166 ///////////////////////////////////////////////////////////////////////////////167 168 MediaConfig::MediaConfig()169 {170 pjsua_media_config mc;171 172 pjsua_media_config_default(&mc);173 fromPj(mc);174 }175 176 void MediaConfig::fromPj(const pjsua_media_config &mc)177 {178 this->clockRate = mc.clock_rate;179 this->sndClockRate = mc.snd_clock_rate;180 this->channelCount = mc.channel_count;181 this->audioFramePtime = mc.audio_frame_ptime;182 this->maxMediaPorts = mc.max_media_ports;183 this->hasIoqueue = mc.has_ioqueue;184 this->threadCnt = mc.thread_cnt;185 this->quality = mc.quality;186 this->ptime = mc.ptime;187 this->noVad = mc.no_vad;188 this->ilbcMode = mc.ilbc_mode;189 this->txDropPct = mc.tx_drop_pct;190 this->rxDropPct = mc.rx_drop_pct;191 this->ecOptions = mc.ec_options;192 this->ecTailLen = mc.ec_tail_len;193 this->sndRecLatency = mc.snd_rec_latency;194 this->sndPlayLatency = mc.snd_play_latency;195 this->jbInit = mc.jb_init;196 this->jbMinPre = mc.jb_min_pre;197 this->jbMaxPre = mc.jb_max_pre;198 this->jbMax = mc.jb_max;199 this->sndAutoCloseTime = mc.snd_auto_close_time;200 this->vidPreviewEnableNative = mc.vid_preview_enable_native;201 }202 203 pjsua_media_config MediaConfig::toPj() const204 {205 pjsua_media_config mcfg;206 207 pjsua_media_config_default(&mcfg);208 209 mcfg.clock_rate = this->clockRate;210 mcfg.snd_clock_rate = this->sndClockRate;211 mcfg.channel_count = this->channelCount;212 mcfg.audio_frame_ptime = this->audioFramePtime;213 mcfg.max_media_ports = this->maxMediaPorts;214 mcfg.has_ioqueue = this->hasIoqueue;215 mcfg.thread_cnt = this->threadCnt;216 mcfg.quality = this->quality;217 mcfg.ptime = this->ptime;218 mcfg.no_vad = this->noVad;219 mcfg.ilbc_mode = this->ilbcMode;220 mcfg.tx_drop_pct = this->txDropPct;221 mcfg.rx_drop_pct = this->rxDropPct;222 mcfg.ec_options = this->ecOptions;223 mcfg.ec_tail_len = this->ecTailLen;224 mcfg.snd_rec_latency = this->sndRecLatency;225 mcfg.snd_play_latency = this->sndPlayLatency;226 mcfg.jb_init = this->jbInit;227 mcfg.jb_min_pre = this->jbMinPre;228 mcfg.jb_max_pre = this->jbMaxPre;229 mcfg.jb_max = this->jbMax;230 mcfg.snd_auto_close_time = this->sndAutoCloseTime;231 mcfg.vid_preview_enable_native = this->vidPreviewEnableNative;232 233 return mcfg;234 }235 47 236 48 /////////////////////////////////////////////////////////////////////////////// … … 299 111 { 300 112 this->port = prm.port; 113 this->portRange = prm.port_range; 301 114 this->publicAddress = pj2Str(prm.public_addr); 302 115 this->boundAddress = pj2Str(prm.bound_addr); … … 311 124 312 125 tc.port = this->port; 126 tc.port_range = this->portRange; 313 127 tc.public_addr = str2Pj(this->publicAddress); 314 128 tc.bound_addr = str2Pj(this->boundAddress); … … 342 156 } 343 157 158 /////////////////////////////////////////////////////////////////////////////// 159 160 void SipHeader::fromPj(const pjsip_hdr *hdr) throw(Error) 161 { 162 char buf[256]; 163 164 int len = pjsip_hdr_print_on((void*)hdr, buf, sizeof(buf)-1); 165 if (len <= 0) 166 PJSUA2_RAISE_ERROR(PJ_ETOOSMALL); 167 buf[len] = '\0'; 168 169 char *pos = strchr(buf, ':'); 170 if (!pos) 171 PJSUA2_RAISE_ERROR(PJSIP_EINVALIDHDR); 172 173 // Trim white space after header name 174 char *end_name = pos; 175 while (end_name>buf && pj_isspace(*(end_name-1))) --end_name; 176 177 // Trim whitespaces after colon 178 char *start_val = pos+1; 179 while (*start_val && pj_isspace(*start_val)) ++start_val; 180 181 hName = string(buf, end_name); 182 hValue = string(start_val); 183 } 184 185 pjsip_generic_string_hdr &SipHeader::toPj() const 186 { 187 pj_str_t hname = str2Pj(hName); 188 pj_str_t hvalue = str2Pj(hValue); 189 190 pjsip_generic_string_hdr_init2(&pjHdr, &hname, &hvalue); 191 return pjHdr; 192 }
Note: See TracChangeset
for help on using the changeset viewer.