Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifdef _WIN32 |
michael@0 | 6 | #include <windows.h> //plat_api.h seems to need some of the types defined in Windows.h (e.g. boolean) |
michael@0 | 7 | #endif |
michael@0 | 8 | |
michael@0 | 9 | #include "CSFLog.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "CC_CallTypes.h" |
michael@0 | 12 | #include "CC_SIPCCService.h" |
michael@0 | 13 | #include "NullDeleter.h" |
michael@0 | 14 | #include "CC_SIPCCDevice.h" |
michael@0 | 15 | #include "CC_SIPCCDeviceInfo.h" |
michael@0 | 16 | #include "CC_SIPCCFeatureInfo.h" |
michael@0 | 17 | #include "CC_SIPCCCallServerInfo.h" |
michael@0 | 18 | #include "CC_SIPCCCall.h" |
michael@0 | 19 | #include "CC_SIPCCCallInfo.h" |
michael@0 | 20 | #include "CC_SIPCCLine.h" |
michael@0 | 21 | #include "CC_SIPCCLineInfo.h" |
michael@0 | 22 | #include "CSFMediaProvider.h" |
michael@0 | 23 | #include "CSFAudioTermination.h" |
michael@0 | 24 | #include "CSFVideoTermination.h" |
michael@0 | 25 | |
michael@0 | 26 | #include "base/platform_thread.h" |
michael@0 | 27 | #include "base/time.h" |
michael@0 | 28 | |
michael@0 | 29 | extern "C" { |
michael@0 | 30 | #include "ccapi_device.h" |
michael@0 | 31 | } |
michael@0 | 32 | #include "debug-psipcc-types.h" |
michael@0 | 33 | #include "VcmSIPCCBinding.h" |
michael@0 | 34 | |
michael@0 | 35 | #include "csf_common.h" |
michael@0 | 36 | |
michael@0 | 37 | static const char* logTag = "CC_SIPCCService"; |
michael@0 | 38 | |
michael@0 | 39 | using namespace std; |
michael@0 | 40 | |
michael@0 | 41 | #define MAX_SUPPORTED_NUM_CALLS 100 |
michael@0 | 42 | #define MAX_SUPPORTED_NUM_LINES 100 |
michael@0 | 43 | #define MAX_SUPPORTED_NUM_FEATURES 100 |
michael@0 | 44 | #define MAX_SUPPORTED_NUM_CALL_SERVERS 100 |
michael@0 | 45 | |
michael@0 | 46 | extern "C" |
michael@0 | 47 | { |
michael@0 | 48 | #include "cpr_types.h" |
michael@0 | 49 | #include "ccapi_device.h" |
michael@0 | 50 | #include "ccapi_device_info.h" |
michael@0 | 51 | #include "ccapi_call.h" |
michael@0 | 52 | |
michael@0 | 53 | #include "cpr_stdio.h" |
michael@0 | 54 | #include "config_api.h" |
michael@0 | 55 | #include "ccapi_service.h" |
michael@0 | 56 | #include "plat_api.h" |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * configCtlFetchReq |
michael@0 | 60 | * |
michael@0 | 61 | * This function tells the config manager to fetch the CTL file |
michael@0 | 62 | * and then fetch the config from the CUCM. It is expected that |
michael@0 | 63 | * this will result in processing of |
michael@0 | 64 | * the config file after the config managers response is received. |
michael@0 | 65 | * |
michael@0 | 66 | * The response received for this request is asynchronous and |
michael@0 | 67 | * should be handled via event provided by config manager. |
michael@0 | 68 | * The CCAPI_Config_reponse api needs to be called for the |
michael@0 | 69 | * handling of the response to the fetch request |
michael@0 | 70 | * |
michael@0 | 71 | */ |
michael@0 | 72 | void configCtlFetchReq(int device_handle) |
michael@0 | 73 | { |
michael@0 | 74 | CSFLogDebug(logTag, "In configCtlFetchReq"); |
michael@0 | 75 | |
michael@0 | 76 | CSF::CC_SIPCCService * pPhone = CSF::CC_SIPCCService::_self; |
michael@0 | 77 | |
michael@0 | 78 | if (pPhone == nullptr) |
michael@0 | 79 | { |
michael@0 | 80 | CSFLogError( logTag, "CC_SIPCCService::_self is NULL."); |
michael@0 | 81 | } |
michael@0 | 82 | else |
michael@0 | 83 | { |
michael@0 | 84 | CCAPI_Start_response(device_handle, pPhone->deviceName.c_str(), pPhone->sipUser.c_str(), |
michael@0 | 85 | pPhone->sipPassword.c_str(), pPhone->sipDomain.c_str()); |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | /** |
michael@0 | 90 | * configFetchReq |
michael@0 | 91 | * |
michael@0 | 92 | * This function tells the config manager to fetch the latest config |
michael@0 | 93 | * from the CUCM. It is expected that this will result in processing of |
michael@0 | 94 | * the config file after the config managers response is received. |
michael@0 | 95 | * |
michael@0 | 96 | * The response received for this request is asynchronous and |
michael@0 | 97 | * should be handled via event provided by config manager. |
michael@0 | 98 | * The CCAPI_Config_reponse api needs to be called for the |
michael@0 | 99 | * handling of the response to the fetch request |
michael@0 | 100 | * |
michael@0 | 101 | * There are cases where only the config file is needed, for eg: during |
michael@0 | 102 | * Apply Config, for those situation we use this API |
michael@0 | 103 | * |
michael@0 | 104 | */ |
michael@0 | 105 | void configFetchReq(int device_handle) |
michael@0 | 106 | { |
michael@0 | 107 | CSFLogDebug( logTag, "In configFetchReq"); |
michael@0 | 108 | |
michael@0 | 109 | configCtlFetchReq(device_handle); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | /** |
michael@0 | 113 | * configParserError |
michael@0 | 114 | * |
michael@0 | 115 | * Notify the config manager that the config file has an error |
michael@0 | 116 | * and a new config file needs to be downloaded. |
michael@0 | 117 | * |
michael@0 | 118 | * The error could be XML format error or minimum config not being |
michael@0 | 119 | * present in the config file. It is expected that |
michael@0 | 120 | * this will result in processing of |
michael@0 | 121 | * the config file after the config managers response is received. |
michael@0 | 122 | * |
michael@0 | 123 | */ |
michael@0 | 124 | void configParserError(void) |
michael@0 | 125 | { |
michael@0 | 126 | CSFLogError( logTag, "In configParserError"); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | /** |
michael@0 | 130 | * Inform application that pSipcc stack has receive a NOTIFY message of event |
michael@0 | 131 | * type "service-control" and action=apply-config. The arguments passed to this |
michael@0 | 132 | * function contains the parameter values received in the message. |
michael@0 | 133 | * |
michael@0 | 134 | * @param config_version [in] latest version stamp of phone configuration. |
michael@0 | 135 | * @param dial_plan_version [in] latest version stamp of the dial plan. |
michael@0 | 136 | * @param fcp_version [in] latest version stamp of feature policy control. |
michael@0 | 137 | * @param cucm_result [in] action taken by the cucm for the changes applied by the |
michael@0 | 138 | * user to the phone configuration. cucm result could be |
michael@0 | 139 | * @li "no_change" - the new phone configuration changes do not impact Unified CM, |
michael@0 | 140 | * @li "config_applied" - The Unified CM Administration applied the |
michael@0 | 141 | * configuration changes dynamically without requiring phone to re-register, |
michael@0 | 142 | * @li "reregister_needed" - The Unified CM Administration applied the |
michael@0 | 143 | * configuration changes and required the phone to re-register to make them |
michael@0 | 144 | * effective. |
michael@0 | 145 | * @param load_id [in] - firmware image name that phone should be running with |
michael@0 | 146 | * @param inactive_load_id [in] - firmware image name that phone should be in inactive partition. |
michael@0 | 147 | * @param load_server [in] - address of load server to download the firmware |
michael@0 | 148 | * image load_id. |
michael@0 | 149 | * @param log_server [in] - log server address where error report need to be |
michael@0 | 150 | * sent. Error report, for example, could be related to image download failure |
michael@0 | 151 | * or phone configuration file download failure. |
michael@0 | 152 | * @param ppid [in] whether peer to peer upgrade is available |
michael@0 | 153 | * @return void |
michael@0 | 154 | */ |
michael@0 | 155 | void configApplyConfigNotify(cc_string_t config_version, |
michael@0 | 156 | cc_string_t dial_plan_version, |
michael@0 | 157 | cc_string_t fcp_version, |
michael@0 | 158 | cc_string_t cucm_result, |
michael@0 | 159 | cc_string_t load_id, |
michael@0 | 160 | cc_string_t inactive_load_id, |
michael@0 | 161 | cc_string_t load_server, |
michael@0 | 162 | cc_string_t log_server, |
michael@0 | 163 | cc_boolean ppid) |
michael@0 | 164 | { |
michael@0 | 165 | CSFLogDebug( logTag, "In configApplyConfigNotify"); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | char * platGetIPAddr () |
michael@0 | 169 | { |
michael@0 | 170 | CSFLogDebug( logTag, "In platGetIPAddr()"); |
michael@0 | 171 | |
michael@0 | 172 | CSF::CC_SIPCCService * pPhone = CSF::CC_SIPCCService::_self; |
michael@0 | 173 | |
michael@0 | 174 | if (pPhone == nullptr) |
michael@0 | 175 | { |
michael@0 | 176 | CSFLogError( logTag, "In platGetIPAddr(). CC_SIPCCService::_self is NULL."); |
michael@0 | 177 | return (char *) ""; |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | return (char*) pPhone->localAddress.c_str(); |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | void ccmedia_flash_once_timer_callback (void) |
michael@0 | 184 | { |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | /** |
michael@0 | 188 | * dialPlanFetchReq |
michael@0 | 189 | * |
michael@0 | 190 | * This function tells the get file request service to fetch the latest dial |
michael@0 | 191 | * plan from the CUCM. |
michael@0 | 192 | * |
michael@0 | 193 | * @param device_handle [in] handle of the device, the response is for |
michael@0 | 194 | * @param dialPlanFileName [in] the name of dialplan file to retrieve |
michael@0 | 195 | * |
michael@0 | 196 | */ |
michael@0 | 197 | cc_boolean dialPlanFetchReq(int device_handle, char* dialPlanFileName) |
michael@0 | 198 | { |
michael@0 | 199 | return 0; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | /** |
michael@0 | 203 | * fcpFetchReq |
michael@0 | 204 | * |
michael@0 | 205 | * This function tells the get file request service to fetch the latest fcp |
michael@0 | 206 | * file from the CUCM. |
michael@0 | 207 | * |
michael@0 | 208 | * @param device_handle [in] handle of the device, the response is for |
michael@0 | 209 | * @param dialPlanFileName [in] the name of fcp file to retrieve |
michael@0 | 210 | * |
michael@0 | 211 | */ |
michael@0 | 212 | cc_boolean fcpFetchReq(int device_handle, char* fcpFileName) |
michael@0 | 213 | { |
michael@0 | 214 | return 0; |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | extern cc_int32_t SipDebugMessage; |
michael@0 | 218 | extern cc_int32_t SipDebugState; |
michael@0 | 219 | extern cc_int32_t SipDebugTask; |
michael@0 | 220 | extern cc_int32_t SipDebugRegState; |
michael@0 | 221 | extern cc_int32_t GSMDebug; |
michael@0 | 222 | extern cc_int32_t FIMDebug; |
michael@0 | 223 | extern cc_int32_t LSMDebug; |
michael@0 | 224 | extern cc_int32_t FSMDebugSM; |
michael@0 | 225 | extern int32_t CSMDebugSM; |
michael@0 | 226 | extern cc_int32_t CCDebug; |
michael@0 | 227 | extern cc_int32_t CCDebugMsg; |
michael@0 | 228 | extern cc_int32_t AuthDebug; |
michael@0 | 229 | extern cc_int32_t ConfigDebug; |
michael@0 | 230 | extern cc_int32_t DpintDebug; |
michael@0 | 231 | extern cc_int32_t KpmlDebug; |
michael@0 | 232 | extern cc_int32_t VCMDebug; |
michael@0 | 233 | extern cc_int32_t g_CCAppDebug; |
michael@0 | 234 | extern cc_int32_t g_CCLogDebug; |
michael@0 | 235 | extern cc_int32_t TNPDebug; |
michael@0 | 236 | |
michael@0 | 237 | static cc_int32_t * _maskedLoggingEntriesArray[19] = { |
michael@0 | 238 | &SipDebugMessage, //13 |
michael@0 | 239 | &SipDebugState, //12 |
michael@0 | 240 | &SipDebugTask, //11 |
michael@0 | 241 | &SipDebugRegState, //14 |
michael@0 | 242 | &GSMDebug, //7 |
michael@0 | 243 | &FIMDebug, //4 |
michael@0 | 244 | &LSMDebug, //8 |
michael@0 | 245 | &FSMDebugSM, //5 |
michael@0 | 246 | &CSMDebugSM, //?? |
michael@0 | 247 | &CCDebug, //2 |
michael@0 | 248 | &CCDebugMsg, //3 |
michael@0 | 249 | &AuthDebug, //6 |
michael@0 | 250 | &ConfigDebug, //0 |
michael@0 | 251 | &DpintDebug, //18 |
michael@0 | 252 | &KpmlDebug, //19 |
michael@0 | 253 | &VCMDebug, //?? |
michael@0 | 254 | &g_CCAppDebug, //0 |
michael@0 | 255 | &g_CCLogDebug, //?? |
michael@0 | 256 | &TNPDebug, //1 |
michael@0 | 257 | }; |
michael@0 | 258 | |
michael@0 | 259 | //Following are not covered above. : |
michael@0 | 260 | //g_cacDebug,9 |
michael@0 | 261 | //g_dcsmDebug, 10 |
michael@0 | 262 | //SipDebugTrx, 14 |
michael@0 | 263 | //TMRDebug, 15 |
michael@0 | 264 | //SipDebugDM, 16 |
michael@0 | 265 | //g_DEFDebug, 17 |
michael@0 | 266 | //g_blfDebug, 21 |
michael@0 | 267 | //g_configappDebug, 23 |
michael@0 | 268 | //CCEVENTDebug, 24 |
michael@0 | 269 | //PLATDebug, 25 |
michael@0 | 270 | |
michael@0 | 271 | //If you add more to this array then you'll need to manually update "HAS_21_BITS" below to be "HAS_22_BITS" |
michael@0 | 272 | //of whatever the new number of bits defined ends up as. Then modify the code that currently uses HAS_21_BITS |
michael@0 | 273 | //below to use your new #define. |
michael@0 | 274 | #define HAS_21_BITS 0x1FFFFF |
michael@0 | 275 | |
michael@0 | 276 | static int _maxBitValueMaskedLoggingEntries = csf_countof(_maskedLoggingEntriesArray);//Should be 21 |
michael@0 | 277 | |
michael@0 | 278 | |
michael@0 | 279 | } //end extern C |
michael@0 | 280 | |
michael@0 | 281 | extern "C" void CCAPI_DeviceListener_onDeviceEvent(ccapi_device_event_e type, cc_device_handle_t hDevice, cc_deviceinfo_ref_t dev_info) |
michael@0 | 282 | { |
michael@0 | 283 | //CSFLogDebug( logTag, "In CCAPI_DeviceListener_onDeviceEvent"); |
michael@0 | 284 | CSF::CC_SIPCCService::onDeviceEvent(type, hDevice, dev_info); |
michael@0 | 285 | } |
michael@0 | 286 | |
michael@0 | 287 | extern "C" void CCAPI_DeviceListener_onFeatureEvent(ccapi_device_event_e type, cc_deviceinfo_ref_t dev_info, cc_featureinfo_ref_t feature_info) |
michael@0 | 288 | { |
michael@0 | 289 | //CSFLogDebug( logTag, "In CCAPI_DeviceListener_onFeatureEvent"); |
michael@0 | 290 | CSF::CC_SIPCCService::onFeatureEvent(type, dev_info, feature_info); |
michael@0 | 291 | } |
michael@0 | 292 | |
michael@0 | 293 | extern "C" void CCAPI_LineListener_onLineEvent(ccapi_line_event_e type, cc_lineid_t line, cc_lineinfo_ref_t info) |
michael@0 | 294 | { |
michael@0 | 295 | //CSFLogDebug( logTag, "In CCAPI_LineListener_onLineEvent"); |
michael@0 | 296 | CSF::CC_SIPCCService::onLineEvent(type, line, info); |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | extern "C" void CCAPI_CallListener_onCallEvent(ccapi_call_event_e type, cc_call_handle_t handle, cc_callinfo_ref_t info) |
michael@0 | 300 | { |
michael@0 | 301 | //CSFLogDebug( logTag, "In CCAPI_CallListener_onCallEvent"); |
michael@0 | 302 | CSF::CC_SIPCCService::onCallEvent(type, handle, info); |
michael@0 | 303 | } |
michael@0 | 304 | |
michael@0 | 305 | |
michael@0 | 306 | |
michael@0 | 307 | namespace CSF |
michael@0 | 308 | { |
michael@0 | 309 | |
michael@0 | 310 | CC_SIPCCService* CC_SIPCCService::_self = nullptr; |
michael@0 | 311 | |
michael@0 | 312 | CC_SIPCCService::CC_SIPCCService() |
michael@0 | 313 | : loggingMask(0), |
michael@0 | 314 | bCreated(false), |
michael@0 | 315 | bStarted(false), |
michael@0 | 316 | m_lock("CC_SIPCCService"), |
michael@0 | 317 | bUseConfig(false) |
michael@0 | 318 | { |
michael@0 | 319 | // Only one instance allowed! |
michael@0 | 320 | assert(_self == nullptr); |
michael@0 | 321 | _self = this; |
michael@0 | 322 | // <emannion> Commented as part of media provider removal |
michael@0 | 323 | //vcmMediaBridge.setStreamObserver(this); |
michael@0 | 324 | //vcmMediaBridge.setMediaProviderObserver(this); |
michael@0 | 325 | } |
michael@0 | 326 | |
michael@0 | 327 | CC_SIPCCService::~CC_SIPCCService() |
michael@0 | 328 | { |
michael@0 | 329 | destroy(); |
michael@0 | 330 | |
michael@0 | 331 | _self = nullptr; |
michael@0 | 332 | } |
michael@0 | 333 | |
michael@0 | 334 | bool CC_SIPCCService::init(const std::string& user, const std::string& password, const std::string& domain, const std::string& device) |
michael@0 | 335 | { |
michael@0 | 336 | sipUser = user; |
michael@0 | 337 | sipPassword = password; |
michael@0 | 338 | sipDomain = domain; |
michael@0 | 339 | deviceName = device; |
michael@0 | 340 | |
michael@0 | 341 | if (!(bCreated = (CCAPI_Service_create() == CC_SUCCESS))) |
michael@0 | 342 | { |
michael@0 | 343 | CSFLogError( logTag, "Call to CCAPI_Service_create() failed."); |
michael@0 | 344 | return false; |
michael@0 | 345 | } |
michael@0 | 346 | return true; |
michael@0 | 347 | } |
michael@0 | 348 | |
michael@0 | 349 | void CC_SIPCCService::destroy() |
michael@0 | 350 | { |
michael@0 | 351 | stop(); |
michael@0 | 352 | |
michael@0 | 353 | if (bCreated) |
michael@0 | 354 | { |
michael@0 | 355 | if (CCAPI_Service_destroy() == CC_FAILURE) |
michael@0 | 356 | { |
michael@0 | 357 | CSFLogError( logTag, "Call to CCAPI_Service_destroy() failed."); |
michael@0 | 358 | } |
michael@0 | 359 | |
michael@0 | 360 | bCreated = false; |
michael@0 | 361 | } |
michael@0 | 362 | |
michael@0 | 363 | deviceName = ""; |
michael@0 | 364 | loggingMask = 0; |
michael@0 | 365 | |
michael@0 | 366 | CC_SIPCCDevice::reset(); |
michael@0 | 367 | CC_SIPCCDeviceInfo::reset(); |
michael@0 | 368 | CC_SIPCCFeatureInfo::reset(); |
michael@0 | 369 | CC_SIPCCCallServerInfo::reset(); |
michael@0 | 370 | CC_SIPCCLine::reset(); |
michael@0 | 371 | CC_SIPCCLineInfo::reset(); |
michael@0 | 372 | CC_SIPCCCall::reset(); |
michael@0 | 373 | CC_SIPCCCallInfo::reset(); |
michael@0 | 374 | |
michael@0 | 375 | if(audioControlWrapper != nullptr) |
michael@0 | 376 | { |
michael@0 | 377 | audioControlWrapper->setAudioControl(nullptr); |
michael@0 | 378 | } |
michael@0 | 379 | if(videoControlWrapper != nullptr) |
michael@0 | 380 | { |
michael@0 | 381 | videoControlWrapper->setVideoControl(nullptr); |
michael@0 | 382 | } |
michael@0 | 383 | } |
michael@0 | 384 | |
michael@0 | 385 | void CC_SIPCCService::setDeviceName(const std::string& deviceName) |
michael@0 | 386 | { |
michael@0 | 387 | this->deviceName = deviceName; |
michael@0 | 388 | } |
michael@0 | 389 | |
michael@0 | 390 | void CC_SIPCCService::setLoggingMask(int mask) |
michael@0 | 391 | { |
michael@0 | 392 | this->loggingMask = mask; |
michael@0 | 393 | } |
michael@0 | 394 | |
michael@0 | 395 | void CC_SIPCCService::setLocalAddressAndGateway(const std::string& localAddress, |
michael@0 | 396 | const std::string& defaultGW) |
michael@0 | 397 | { |
michael@0 | 398 | this->localAddress = localAddress; |
michael@0 | 399 | this->defaultGW = defaultGW; |
michael@0 | 400 | |
michael@0 | 401 | CCAPI_Device_IP_Update(CCAPI_Device_getDeviceID(), localAddress.c_str(), "", 0, |
michael@0 | 402 | localAddress.c_str(), "", 0); |
michael@0 | 403 | |
michael@0 | 404 | AudioTermination* audio = VcmSIPCCBinding::getAudioTermination(); |
michael@0 | 405 | if(audio != nullptr) |
michael@0 | 406 | { |
michael@0 | 407 | audio->setLocalIP(localAddress.c_str()); |
michael@0 | 408 | } |
michael@0 | 409 | VideoTermination* video = VcmSIPCCBinding::getVideoTermination(); |
michael@0 | 410 | if(video != nullptr) |
michael@0 | 411 | { |
michael@0 | 412 | video->setLocalIP(localAddress.c_str()); |
michael@0 | 413 | } |
michael@0 | 414 | } |
michael@0 | 415 | |
michael@0 | 416 | /* |
michael@0 | 417 | * New function to start sip stack without device file download. |
michael@0 | 418 | */ |
michael@0 | 419 | bool CC_SIPCCService::startService() |
michael@0 | 420 | { |
michael@0 | 421 | AudioTermination * pAudio = VcmSIPCCBinding::getAudioTermination(); |
michael@0 | 422 | VideoTermination * pVideo = VcmSIPCCBinding::getVideoTermination(); |
michael@0 | 423 | |
michael@0 | 424 | if(pAudio != nullptr) |
michael@0 | 425 | { |
michael@0 | 426 | pAudio->setMediaPorts(16384, 32766); |
michael@0 | 427 | pAudio->setDSCPValue(184); |
michael@0 | 428 | pAudio->setVADEnabled(false); |
michael@0 | 429 | } |
michael@0 | 430 | |
michael@0 | 431 | if (pVideo != nullptr) |
michael@0 | 432 | { |
michael@0 | 433 | pVideo->setDSCPValue(136); |
michael@0 | 434 | } |
michael@0 | 435 | |
michael@0 | 436 | bUseConfig = false; |
michael@0 | 437 | if (!(bStarted = (CCAPI_Service_start() == CC_SUCCESS))) |
michael@0 | 438 | { |
michael@0 | 439 | CSFLogError( logTag, "Call to CCAPI_Service_start() failed."); |
michael@0 | 440 | return false; |
michael@0 | 441 | } |
michael@0 | 442 | |
michael@0 | 443 | CC_DevicePtr devicePtr = CC_SIPCCDevice::createDevice (); |
michael@0 | 444 | if (devicePtr == nullptr) |
michael@0 | 445 | { |
michael@0 | 446 | CSFLogWarn( logTag, "stopping because createDevice failed"); |
michael@0 | 447 | stop(); |
michael@0 | 448 | return false; |
michael@0 | 449 | } |
michael@0 | 450 | CSFLogDebug( logTag, "About to imposeLoggingMask"); |
michael@0 | 451 | applyLoggingMask(loggingMask); |
michael@0 | 452 | |
michael@0 | 453 | return true; |
michael@0 | 454 | } |
michael@0 | 455 | |
michael@0 | 456 | |
michael@0 | 457 | void CC_SIPCCService::stop() |
michael@0 | 458 | { |
michael@0 | 459 | if (bStarted) |
michael@0 | 460 | { |
michael@0 | 461 | // But first, tear down all existing calls. |
michael@0 | 462 | endAllActiveCalls(); |
michael@0 | 463 | |
michael@0 | 464 | if (CCAPI_Service_stop() == CC_FAILURE) |
michael@0 | 465 | { |
michael@0 | 466 | CSFLogError( logTag, "Call to CCAPI_Service_stop() failed."); |
michael@0 | 467 | } |
michael@0 | 468 | |
michael@0 | 469 | bStarted = false; |
michael@0 | 470 | } |
michael@0 | 471 | } |
michael@0 | 472 | |
michael@0 | 473 | bool CC_SIPCCService::isStarted() |
michael@0 | 474 | { |
michael@0 | 475 | return bStarted; |
michael@0 | 476 | } |
michael@0 | 477 | |
michael@0 | 478 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 479 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 480 | // method are not safe except from ccapp_thread. |
michael@0 | 481 | CC_DevicePtr CC_SIPCCService::getActiveDevice() |
michael@0 | 482 | { |
michael@0 | 483 | return CC_SIPCCDevice::wrap(CCAPI_Device_getDeviceID()).get(); |
michael@0 | 484 | } |
michael@0 | 485 | |
michael@0 | 486 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 487 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 488 | // method are not safe except from ccapp_thread. |
michael@0 | 489 | vector<CC_DevicePtr> CC_SIPCCService::getDevices() |
michael@0 | 490 | { |
michael@0 | 491 | vector<CC_DevicePtr> devices; |
michael@0 | 492 | |
michael@0 | 493 | CC_SIPCCDevicePtr pDevice = CC_SIPCCDevice::wrap(CCAPI_Device_getDeviceID()); |
michael@0 | 494 | if(pDevice != nullptr) |
michael@0 | 495 | { |
michael@0 | 496 | devices.push_back(pDevice.get()); |
michael@0 | 497 | } |
michael@0 | 498 | |
michael@0 | 499 | return devices; |
michael@0 | 500 | } |
michael@0 | 501 | |
michael@0 | 502 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 503 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 504 | // method are not safe except from ccapp_thread. |
michael@0 | 505 | AudioControlPtr CC_SIPCCService::getAudioControl () |
michael@0 | 506 | { |
michael@0 | 507 | if(audioControlWrapper != nullptr) |
michael@0 | 508 | { |
michael@0 | 509 | return audioControlWrapper.get(); |
michael@0 | 510 | } |
michael@0 | 511 | else |
michael@0 | 512 | { |
michael@0 | 513 | audioControlWrapper = AudioControlWrapperPtr(new AudioControlWrapper(VcmSIPCCBinding::getAudioControl())); |
michael@0 | 514 | return audioControlWrapper.get(); |
michael@0 | 515 | } |
michael@0 | 516 | } |
michael@0 | 517 | |
michael@0 | 518 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 519 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 520 | // method are not safe except from ccapp_thread. |
michael@0 | 521 | VideoControlPtr CC_SIPCCService::getVideoControl () |
michael@0 | 522 | { |
michael@0 | 523 | if(videoControlWrapper != nullptr) |
michael@0 | 524 | { |
michael@0 | 525 | return videoControlWrapper.get(); |
michael@0 | 526 | } |
michael@0 | 527 | else |
michael@0 | 528 | { |
michael@0 | 529 | videoControlWrapper = VideoControlWrapperPtr(new VideoControlWrapper(VcmSIPCCBinding::getVideoControl())); |
michael@0 | 530 | return videoControlWrapper.get(); |
michael@0 | 531 | } |
michael@0 | 532 | } |
michael@0 | 533 | |
michael@0 | 534 | |
michael@0 | 535 | void CC_SIPCCService::applyLoggingMask (int newMask) |
michael@0 | 536 | { |
michael@0 | 537 | if (newMask >> _maxBitValueMaskedLoggingEntries > 0) |
michael@0 | 538 | { |
michael@0 | 539 | CSFLogWarn( logTag, "Value of 0x%x specified for mask includes at least one bit value that exceeds the maximum supported bitfield value. " |
michael@0 | 540 | "Ignoring unsupported bits.", newMask); |
michael@0 | 541 | } |
michael@0 | 542 | |
michael@0 | 543 | CSFLogDebug( logTag, "Applying a sipcc log mask = %d", newMask); |
michael@0 | 544 | |
michael@0 | 545 | loggingMask = newMask & (HAS_21_BITS); |
michael@0 | 546 | |
michael@0 | 547 | for (int i=0; i<_maxBitValueMaskedLoggingEntries; i++) |
michael@0 | 548 | { |
michael@0 | 549 | *(_maskedLoggingEntriesArray[i]) = (loggingMask >> i) & 0x1; |
michael@0 | 550 | } |
michael@0 | 551 | } |
michael@0 | 552 | |
michael@0 | 553 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 554 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 555 | // method are not safe except from ccapp_thread. |
michael@0 | 556 | void CC_SIPCCService::endAllActiveCalls() |
michael@0 | 557 | { |
michael@0 | 558 | CC_DevicePtr device = getActiveDevice(); |
michael@0 | 559 | if(device != nullptr) |
michael@0 | 560 | { |
michael@0 | 561 | CC_DeviceInfoPtr deviceInfo = device->getDeviceInfo(); |
michael@0 | 562 | vector<CC_CallPtr> calls = deviceInfo->getCalls(); |
michael@0 | 563 | CSFLogInfo( logTag, "endAllActiveCalls(): %lu calls to be ended.", calls.size()); |
michael@0 | 564 | for(vector<CC_CallPtr>::iterator it = calls.begin(); it != calls.end(); it++) |
michael@0 | 565 | { |
michael@0 | 566 | // For each active call, if it can be ended, do so. |
michael@0 | 567 | CC_CallPtr call = *it; |
michael@0 | 568 | CC_CallInfoPtr callInfo = call->getCallInfo(); |
michael@0 | 569 | if(callInfo->hasCapability(CC_CallCapabilityEnum::canEndCall)) |
michael@0 | 570 | { |
michael@0 | 571 | CSFLogDebug( logTag, "endAllActiveCalls(): ending call %s -> %s [%s]", |
michael@0 | 572 | callInfo->getCallingPartyNumber().c_str(), |
michael@0 | 573 | callInfo->getCalledPartyNumber().c_str(), |
michael@0 | 574 | call_state_getname(callInfo->getCallState())); |
michael@0 | 575 | call->endCall(); |
michael@0 | 576 | } |
michael@0 | 577 | else if(callInfo->hasCapability(CC_CallCapabilityEnum::canResume) && callInfo->getCallState() != REMHOLD) |
michael@0 | 578 | { |
michael@0 | 579 | CSFLogDebug( logTag, "endAllActiveCalls(): resume then ending call %s -> %s, [%s]", |
michael@0 | 580 | callInfo->getCallingPartyNumber().c_str(), |
michael@0 | 581 | callInfo->getCalledPartyNumber().c_str(), |
michael@0 | 582 | call_state_getname(callInfo->getCallState())); |
michael@0 | 583 | call->muteAudio(); |
michael@0 | 584 | call->resume(callInfo->getVideoDirection()); |
michael@0 | 585 | call->endCall(); |
michael@0 | 586 | } |
michael@0 | 587 | } |
michael@0 | 588 | |
michael@0 | 589 | if(!calls.empty()) |
michael@0 | 590 | { |
michael@0 | 591 | #ifdef MOZILLA_INTERNAL_API |
michael@0 | 592 | // If we had any calls, allow a short time for the SIP messaging to go out |
michael@0 | 593 | PlatformThread::Sleep(500); |
michael@0 | 594 | #endif |
michael@0 | 595 | } |
michael@0 | 596 | } |
michael@0 | 597 | } |
michael@0 | 598 | |
michael@0 | 599 | |
michael@0 | 600 | // C++ Event Handlers |
michael@0 | 601 | void CC_SIPCCService::onDeviceEvent(ccapi_device_event_e type, cc_device_handle_t handle, cc_deviceinfo_ref_t info) |
michael@0 | 602 | { |
michael@0 | 603 | if (_self == nullptr) |
michael@0 | 604 | { |
michael@0 | 605 | CSFLogError( logTag, "CC_SIPCCService::_self is NULL. Unable to notify observers of device event."); |
michael@0 | 606 | return; |
michael@0 | 607 | } |
michael@0 | 608 | |
michael@0 | 609 | mozilla::MutexAutoLock lock(_self->m_lock); |
michael@0 | 610 | |
michael@0 | 611 | CC_SIPCCDevicePtr devicePtr = CC_SIPCCDevice::wrap(handle); |
michael@0 | 612 | if (devicePtr == nullptr) |
michael@0 | 613 | { |
michael@0 | 614 | CSFLogError( logTag, "Unable to notify device observers for device handle (%u), as failed to create CC_DevicePtr", handle); |
michael@0 | 615 | return; |
michael@0 | 616 | } |
michael@0 | 617 | |
michael@0 | 618 | CC_SIPCCDeviceInfoPtr infoPtr = CC_SIPCCDeviceInfo::wrap(info); |
michael@0 | 619 | if (infoPtr == nullptr) |
michael@0 | 620 | { |
michael@0 | 621 | CSFLogError( logTag, "Unable to notify call observers for device handle (%u), as failed to create CC_DeviceInfoPtr", handle); |
michael@0 | 622 | return; |
michael@0 | 623 | } |
michael@0 | 624 | |
michael@0 | 625 | CSFLogInfo( logTag, "onDeviceEvent( %s, %s, [%s] )", |
michael@0 | 626 | device_event_getname(type), |
michael@0 | 627 | devicePtr->toString().c_str(), |
michael@0 | 628 | infoPtr->getDeviceName().c_str()); |
michael@0 | 629 | _self->notifyDeviceEventObservers(type, devicePtr.get(), infoPtr.get()); |
michael@0 | 630 | } |
michael@0 | 631 | |
michael@0 | 632 | void CC_SIPCCService::onFeatureEvent(ccapi_device_event_e type, cc_deviceinfo_ref_t /* device_info */, cc_featureinfo_ref_t feature_info) |
michael@0 | 633 | { |
michael@0 | 634 | |
michael@0 | 635 | if (_self == nullptr) |
michael@0 | 636 | { |
michael@0 | 637 | CSFLogError( logTag, "CC_SIPCCService::_self is NULL. Unable to notify observers of device event."); |
michael@0 | 638 | return; |
michael@0 | 639 | } |
michael@0 | 640 | |
michael@0 | 641 | mozilla::MutexAutoLock lock(_self->m_lock); |
michael@0 | 642 | |
michael@0 | 643 | cc_device_handle_t hDevice = CCAPI_Device_getDeviceID(); |
michael@0 | 644 | CC_DevicePtr devicePtr = CC_SIPCCDevice::wrap(hDevice).get(); |
michael@0 | 645 | if (devicePtr == nullptr) |
michael@0 | 646 | { |
michael@0 | 647 | CSFLogError( logTag, "Unable to notify device observers for device handle (%u), as failed to create CC_DevicePtr", hDevice); |
michael@0 | 648 | return; |
michael@0 | 649 | } |
michael@0 | 650 | |
michael@0 | 651 | CC_FeatureInfoPtr infoPtr = CC_SIPCCFeatureInfo::wrap(feature_info).get(); |
michael@0 | 652 | if (infoPtr == nullptr) |
michael@0 | 653 | { |
michael@0 | 654 | CSFLogError( logTag, "Unable to notify call observers for feature info handle (%p), as failed to create CC_FeatureInfoPtr", feature_info); |
michael@0 | 655 | return; |
michael@0 | 656 | } |
michael@0 | 657 | |
michael@0 | 658 | CSFLogInfo( logTag, "onFeatureEvent( %s, %s, [%s] )", |
michael@0 | 659 | device_event_getname(type), |
michael@0 | 660 | devicePtr->toString().c_str(), |
michael@0 | 661 | infoPtr->getDisplayName().c_str()); |
michael@0 | 662 | _self->notifyFeatureEventObservers(type, devicePtr, infoPtr); |
michael@0 | 663 | } |
michael@0 | 664 | |
michael@0 | 665 | void CC_SIPCCService::onLineEvent(ccapi_line_event_e eventType, cc_lineid_t line, cc_lineinfo_ref_t info) |
michael@0 | 666 | { |
michael@0 | 667 | if (_self == nullptr) |
michael@0 | 668 | { |
michael@0 | 669 | CSFLogError( logTag, "CC_SIPCCService::_self is NULL. Unable to notify observers of line event."); |
michael@0 | 670 | return; |
michael@0 | 671 | } |
michael@0 | 672 | |
michael@0 | 673 | mozilla::MutexAutoLock lock(_self->m_lock); |
michael@0 | 674 | |
michael@0 | 675 | CC_LinePtr linePtr = CC_SIPCCLine::wrap(line).get(); |
michael@0 | 676 | if (linePtr == nullptr) |
michael@0 | 677 | { |
michael@0 | 678 | CSFLogError( logTag, "Unable to notify line observers for line lineId (%u), as failed to create CC_LinePtr", line); |
michael@0 | 679 | return; |
michael@0 | 680 | } |
michael@0 | 681 | |
michael@0 | 682 | CC_LineInfoPtr infoPtr = CC_SIPCCLineInfo::wrap(info).get(); |
michael@0 | 683 | if (infoPtr == nullptr) |
michael@0 | 684 | { |
michael@0 | 685 | CSFLogError( logTag, "Unable to notify line observers for line lineId (%u), as failed to create CC_LineInfoPtr", line); |
michael@0 | 686 | return; |
michael@0 | 687 | } |
michael@0 | 688 | |
michael@0 | 689 | CSFLogInfo( logTag, "onLineEvent(%s, %s, [%s|%s]", |
michael@0 | 690 | line_event_getname(eventType), linePtr->toString().c_str(), |
michael@0 | 691 | infoPtr->getNumber().c_str(), (infoPtr->getRegState() ? "INS" : "OOS")); |
michael@0 | 692 | _self->notifyLineEventObservers(eventType, linePtr, infoPtr); |
michael@0 | 693 | } |
michael@0 | 694 | |
michael@0 | 695 | void CC_SIPCCService::onCallEvent(ccapi_call_event_e eventType, cc_call_handle_t handle, cc_callinfo_ref_t info) |
michael@0 | 696 | { |
michael@0 | 697 | if (_self == nullptr) |
michael@0 | 698 | { |
michael@0 | 699 | CSFLogError( logTag, "CC_SIPCCService::_self is NULL. Unable to notify observers of call event."); |
michael@0 | 700 | return; |
michael@0 | 701 | } |
michael@0 | 702 | |
michael@0 | 703 | mozilla::MutexAutoLock lock(_self->m_lock); |
michael@0 | 704 | |
michael@0 | 705 | CC_SIPCCCallPtr callPtr = CC_SIPCCCall::wrap(handle); |
michael@0 | 706 | if (callPtr == nullptr) |
michael@0 | 707 | { |
michael@0 | 708 | CSFLogError( logTag, "Unable to notify call observers for call handle (%u), as failed to create CC_CallPtr", handle); |
michael@0 | 709 | return; |
michael@0 | 710 | } |
michael@0 | 711 | |
michael@0 | 712 | CC_SIPCCCallInfoPtr infoPtr = CC_SIPCCCallInfo::wrap(info); |
michael@0 | 713 | if (infoPtr == nullptr) |
michael@0 | 714 | { |
michael@0 | 715 | CSFLogError( logTag, "Unable to notify call observers for call handle (%u), as failed to create CC_CallInfoPtr", handle); |
michael@0 | 716 | return; |
michael@0 | 717 | } |
michael@0 | 718 | |
michael@0 | 719 | infoPtr->setMediaData(callPtr->getMediaData()); |
michael@0 | 720 | |
michael@0 | 721 | set<CSF::CC_CallCapabilityEnum::CC_CallCapability> capSet = infoPtr->getCapabilitySet(); |
michael@0 | 722 | CSFLogInfo( logTag, "onCallEvent(%s, %s, [%s|%s]", |
michael@0 | 723 | call_event_getname(eventType), callPtr->toString().c_str(), |
michael@0 | 724 | call_state_getname(infoPtr->getCallState()), CC_CallCapabilityEnum::toString(capSet).c_str()); |
michael@0 | 725 | _self->notifyCallEventObservers(eventType, callPtr.get(), infoPtr.get()); |
michael@0 | 726 | |
michael@0 | 727 | // To prevent leaking CC_SIPCCCalls, we remove them from the wrapper |
michael@0 | 728 | // map when the call event information indicates an "on hook" event. |
michael@0 | 729 | if (infoPtr->getCallState() == ONHOOK) { |
michael@0 | 730 | CSFLogDebug( logTag, "Removing call info from wrapper map (handle=%u)", |
michael@0 | 731 | handle); |
michael@0 | 732 | CC_SIPCCCall::release(handle); |
michael@0 | 733 | } |
michael@0 | 734 | |
michael@0 | 735 | // Once the call info is dispatched to the observers, we never need to |
michael@0 | 736 | // refer to it again. The next operation will contain its own unique info. |
michael@0 | 737 | CC_SIPCCCallInfo::release(info); |
michael@0 | 738 | } |
michael@0 | 739 | |
michael@0 | 740 | void CC_SIPCCService::addCCObserver ( CC_Observer * observer ) |
michael@0 | 741 | { |
michael@0 | 742 | mozilla::MutexAutoLock lock(m_lock); |
michael@0 | 743 | if (observer == nullptr) |
michael@0 | 744 | { |
michael@0 | 745 | CSFLogError( logTag, "NULL value for \"observer\" passed to addCCObserver()."); |
michael@0 | 746 | return; |
michael@0 | 747 | } |
michael@0 | 748 | |
michael@0 | 749 | ccObservers.insert(observer); |
michael@0 | 750 | } |
michael@0 | 751 | |
michael@0 | 752 | void CC_SIPCCService::removeCCObserver ( CC_Observer * observer ) |
michael@0 | 753 | { |
michael@0 | 754 | mozilla::MutexAutoLock lock(m_lock); |
michael@0 | 755 | ccObservers.erase(observer); |
michael@0 | 756 | } |
michael@0 | 757 | |
michael@0 | 758 | //Notify Observers |
michael@0 | 759 | void CC_SIPCCService::notifyDeviceEventObservers (ccapi_device_event_e eventType, CC_DevicePtr devicePtr, CC_DeviceInfoPtr info) |
michael@0 | 760 | { |
michael@0 | 761 | // m_lock must be held by the function that called us |
michael@0 | 762 | set<CC_Observer*>::const_iterator it = ccObservers.begin(); |
michael@0 | 763 | for ( ; it != ccObservers.end(); it++ ) |
michael@0 | 764 | { |
michael@0 | 765 | (*it)->onDeviceEvent(eventType, devicePtr, info); |
michael@0 | 766 | } |
michael@0 | 767 | } |
michael@0 | 768 | |
michael@0 | 769 | void CC_SIPCCService::notifyFeatureEventObservers (ccapi_device_event_e eventType, CC_DevicePtr devicePtr, CC_FeatureInfoPtr info) |
michael@0 | 770 | { |
michael@0 | 771 | // m_lock must be held by the function that called us |
michael@0 | 772 | set<CC_Observer*>::const_iterator it = ccObservers.begin(); |
michael@0 | 773 | for ( ; it != ccObservers.end(); it++ ) |
michael@0 | 774 | { |
michael@0 | 775 | (*it)->onFeatureEvent(eventType, devicePtr, info); |
michael@0 | 776 | } |
michael@0 | 777 | } |
michael@0 | 778 | |
michael@0 | 779 | void CC_SIPCCService::notifyLineEventObservers (ccapi_line_event_e eventType, CC_LinePtr linePtr, CC_LineInfoPtr info) |
michael@0 | 780 | { |
michael@0 | 781 | // m_lock must be held by the function that called us |
michael@0 | 782 | set<CC_Observer*>::const_iterator it = ccObservers.begin(); |
michael@0 | 783 | for ( ; it != ccObservers.end(); it++ ) |
michael@0 | 784 | { |
michael@0 | 785 | (*it)->onLineEvent(eventType, linePtr, info); |
michael@0 | 786 | } |
michael@0 | 787 | } |
michael@0 | 788 | |
michael@0 | 789 | void CC_SIPCCService::notifyCallEventObservers (ccapi_call_event_e eventType, CC_CallPtr callPtr, CC_CallInfoPtr info) |
michael@0 | 790 | { |
michael@0 | 791 | // m_lock must be held by the function that called us |
michael@0 | 792 | set<CC_Observer*>::const_iterator it = ccObservers.begin(); |
michael@0 | 793 | for ( ; it != ccObservers.end(); it++ ) |
michael@0 | 794 | { |
michael@0 | 795 | (*it)->onCallEvent(eventType, callPtr, info); |
michael@0 | 796 | } |
michael@0 | 797 | } |
michael@0 | 798 | |
michael@0 | 799 | // This is called when the SIP stack has caused a new stream to be allocated. This function will |
michael@0 | 800 | // find the call associated with that stream so that the call can store the streamId. |
michael@0 | 801 | |
michael@0 | 802 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 803 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 804 | // method are not safe except from ccapp_thread. |
michael@0 | 805 | void CC_SIPCCService::registerStream(cc_call_handle_t call, int streamId, bool isVideo) |
michael@0 | 806 | { |
michael@0 | 807 | CSFLogDebug( logTag, "registerStream for call: %d strId=%d video=%s", |
michael@0 | 808 | call, streamId, isVideo ? "TRUE" : "FALSE"); |
michael@0 | 809 | // get the object corresponding to the handle |
michael@0 | 810 | CC_SIPCCCallPtr callPtr = CC_SIPCCCall::wrap(call); |
michael@0 | 811 | if (callPtr != nullptr) |
michael@0 | 812 | { |
michael@0 | 813 | callPtr->addStream(streamId, isVideo); |
michael@0 | 814 | } |
michael@0 | 815 | else |
michael@0 | 816 | { |
michael@0 | 817 | CSFLogError( logTag, "registerStream(), No call found for allocated Stream: %d, %s", |
michael@0 | 818 | streamId, isVideo ? "TRUE" : "FALSE"); |
michael@0 | 819 | } |
michael@0 | 820 | } |
michael@0 | 821 | |
michael@0 | 822 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 823 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 824 | // method are not safe except from ccapp_thread. |
michael@0 | 825 | void CC_SIPCCService::deregisterStream(cc_call_handle_t call, int streamId) |
michael@0 | 826 | { |
michael@0 | 827 | // get the object corresponding to the handle |
michael@0 | 828 | CC_SIPCCCallPtr callPtr = CC_SIPCCCall::wrap(call); |
michael@0 | 829 | if (callPtr != nullptr) |
michael@0 | 830 | { |
michael@0 | 831 | callPtr->removeStream(streamId); |
michael@0 | 832 | } |
michael@0 | 833 | else |
michael@0 | 834 | { |
michael@0 | 835 | CSFLogError( logTag, "deregisterStream(), No call found for deallocated Stream: %d", streamId); |
michael@0 | 836 | } |
michael@0 | 837 | } |
michael@0 | 838 | |
michael@0 | 839 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 840 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 841 | // method are not safe except from ccapp_thread. |
michael@0 | 842 | void CC_SIPCCService::dtmfBurst(int digit, int direction, int duration) |
michael@0 | 843 | { |
michael@0 | 844 | // We haven't a clue what stream to use. Search for a call which has an audio stream. |
michael@0 | 845 | vector<CC_SIPCCCallPtr> calls; |
michael@0 | 846 | { |
michael@0 | 847 | // First build a list of all the calls. |
michael@0 | 848 | cc_deviceinfo_ref_t deviceInfoRef = CCAPI_Device_getDeviceInfo(CCAPI_Device_getDeviceID()); |
michael@0 | 849 | cc_call_handle_t handles[MAX_SUPPORTED_NUM_CALLS] = {}; |
michael@0 | 850 | cc_uint16_t numHandles = csf_countof(handles); |
michael@0 | 851 | |
michael@0 | 852 | CCAPI_DeviceInfo_getCalls(deviceInfoRef, handles, &numHandles); |
michael@0 | 853 | |
michael@0 | 854 | for (int i=0; i<numHandles; i++) |
michael@0 | 855 | { |
michael@0 | 856 | CC_SIPCCCallPtr callPtr = CC_SIPCCCall::wrap(handles[i]); |
michael@0 | 857 | calls.push_back(callPtr); |
michael@0 | 858 | } |
michael@0 | 859 | CCAPI_Device_releaseDeviceInfo(deviceInfoRef); |
michael@0 | 860 | } |
michael@0 | 861 | |
michael@0 | 862 | // Using the list of all calls, search for those containing an audio stream. |
michael@0 | 863 | // Send a DTMF digit on the first one we find. |
michael@0 | 864 | |
michael@0 | 865 | AudioTermination * pAudio = VcmSIPCCBinding::getAudioTermination(); |
michael@0 | 866 | bool bSent = false; |
michael@0 | 867 | for(vector<CC_SIPCCCallPtr>::iterator it = calls.begin(); it != calls.end() && !bSent; it++) |
michael@0 | 868 | { |
michael@0 | 869 | CC_SIPCCCallMediaDataPtr pMediaData = (*it)->getMediaData(); |
michael@0 | 870 | |
michael@0 | 871 | mozilla::MutexAutoLock lock(pMediaData->streamMapMutex); |
michael@0 | 872 | for (StreamMapType::iterator entry = pMediaData->streamMap.begin(); entry != pMediaData->streamMap.end(); entry++) |
michael@0 | 873 | { |
michael@0 | 874 | if (entry->second.isVideo == false) |
michael@0 | 875 | { |
michael@0 | 876 | // first is the streamId |
michael@0 | 877 | if (pAudio->sendDtmf(entry->first, digit)) |
michael@0 | 878 | { |
michael@0 | 879 | // We have sent a digit, done. |
michael@0 | 880 | bSent = true; |
michael@0 | 881 | break; |
michael@0 | 882 | } |
michael@0 | 883 | else |
michael@0 | 884 | { |
michael@0 | 885 | CSFLogWarn( logTag, "dtmfBurst:sendDtmf returned fail"); |
michael@0 | 886 | } |
michael@0 | 887 | } |
michael@0 | 888 | } |
michael@0 | 889 | } |
michael@0 | 890 | } |
michael@0 | 891 | |
michael@0 | 892 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 893 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 894 | // method are not safe except from ccapp_thread. |
michael@0 | 895 | void CC_SIPCCService::sendIFrame(cc_call_handle_t call_handle) |
michael@0 | 896 | { |
michael@0 | 897 | CC_SIPCCCallPtr callPtr = CC_SIPCCCall::wrap(call_handle); |
michael@0 | 898 | CC_SIPCCCallMediaDataPtr pMediaData=callPtr->getMediaData(); |
michael@0 | 899 | if (pMediaData != nullptr) |
michael@0 | 900 | { |
michael@0 | 901 | for (StreamMapType::iterator entry = pMediaData->streamMap.begin(); entry != pMediaData->streamMap.end(); entry++) |
michael@0 | 902 | { |
michael@0 | 903 | if (entry->second.isVideo == true) |
michael@0 | 904 | { |
michael@0 | 905 | VcmSIPCCBinding::getVideoTermination()->sendIFrame( entry->first ); |
michael@0 | 906 | } |
michael@0 | 907 | } |
michael@0 | 908 | } |
michael@0 | 909 | } |
michael@0 | 910 | |
michael@0 | 911 | bool CC_SIPCCService::isValidMediaPortRange(int mediaStartPort, int mediaEndPort) |
michael@0 | 912 | { |
michael@0 | 913 | if(mediaStartPort < 1024 || |
michael@0 | 914 | mediaStartPort > 65535 || |
michael@0 | 915 | mediaEndPort < 1024 || |
michael@0 | 916 | mediaEndPort > 65535 || |
michael@0 | 917 | mediaEndPort - mediaStartPort < 3) |
michael@0 | 918 | { |
michael@0 | 919 | return false; |
michael@0 | 920 | } |
michael@0 | 921 | else |
michael@0 | 922 | { |
michael@0 | 923 | return true; |
michael@0 | 924 | } |
michael@0 | 925 | } |
michael@0 | 926 | |
michael@0 | 927 | bool CC_SIPCCService::isValidDSCPValue(int value) |
michael@0 | 928 | { |
michael@0 | 929 | //value is 8-bit value, but the two least significant bits are unused, |
michael@0 | 930 | //leaving an effective 6 bits of information. Valid values are therefore |
michael@0 | 931 | //all multiples of 4 that lie between 0 and 252 inclusive. |
michael@0 | 932 | if(value >= 0 && |
michael@0 | 933 | value <= 252 && |
michael@0 | 934 | value % 4 == 0) |
michael@0 | 935 | { |
michael@0 | 936 | return true; |
michael@0 | 937 | } |
michael@0 | 938 | else |
michael@0 | 939 | { |
michael@0 | 940 | return false; |
michael@0 | 941 | } |
michael@0 | 942 | } |
michael@0 | 943 | |
michael@0 | 944 | void CC_SIPCCService::onVideoModeChanged( bool enable ) |
michael@0 | 945 | { |
michael@0 | 946 | } |
michael@0 | 947 | |
michael@0 | 948 | // !!! Note that accessing *Ptr instances from multiple threads can |
michael@0 | 949 | // lead to deadlocks, crashes, and spinning threads. Calls to this |
michael@0 | 950 | // method are not safe except from ccapp_thread. |
michael@0 | 951 | void CC_SIPCCService::onKeyFrameRequested( int stream ) |
michael@0 | 952 | // This is called when the Video Provider indicates that it needs to send a request for new key frame to the sender |
michael@0 | 953 | { |
michael@0 | 954 | CSFLogDebug(logTag, "onKeyFrameRequested for stream "); |
michael@0 | 955 | // We haven't a clue what stream to use. Search for a call which has an audio stream. |
michael@0 | 956 | vector<CC_SIPCCCallPtr> calls; |
michael@0 | 957 | { |
michael@0 | 958 | // First build a list of all the calls. |
michael@0 | 959 | cc_deviceinfo_ref_t deviceInfoRef = CCAPI_Device_getDeviceInfo(CCAPI_Device_getDeviceID()); |
michael@0 | 960 | cc_call_handle_t handles[MAX_SUPPORTED_NUM_CALLS] = {}; |
michael@0 | 961 | cc_uint16_t numHandles = csf_countof(handles); |
michael@0 | 962 | |
michael@0 | 963 | CCAPI_DeviceInfo_getCalls(deviceInfoRef, handles, &numHandles); |
michael@0 | 964 | |
michael@0 | 965 | for (int i=0; i<numHandles; i++) |
michael@0 | 966 | { |
michael@0 | 967 | CC_SIPCCCallPtr callPtr = CC_SIPCCCall::wrap(handles[i]); |
michael@0 | 968 | //CC_SIPCCCallPtr callPtr = wrapCall(handles[i]); |
michael@0 | 969 | calls.push_back(callPtr); |
michael@0 | 970 | } |
michael@0 | 971 | CCAPI_Device_releaseDeviceInfo(deviceInfoRef); |
michael@0 | 972 | } |
michael@0 | 973 | |
michael@0 | 974 | // Using the list of all calls, search for those containing an video stream. |
michael@0 | 975 | // Send the send info SIP message when we find the one with the correct stream id. |
michael@0 | 976 | |
michael@0 | 977 | bool bSent = false; |
michael@0 | 978 | for(vector<CC_SIPCCCallPtr>::iterator it = calls.begin(); it != calls.end() && !bSent; it++) |
michael@0 | 979 | { |
michael@0 | 980 | CC_SIPCCCallMediaDataPtr pMediaData = (*it)->getMediaData(); |
michael@0 | 981 | |
michael@0 | 982 | mozilla::MutexAutoLock lock(pMediaData->streamMapMutex); |
michael@0 | 983 | for (StreamMapType::iterator entry = pMediaData->streamMap.begin(); entry != pMediaData->streamMap.end(); entry++) |
michael@0 | 984 | { |
michael@0 | 985 | if ((entry->first==stream) && (entry->second.isVideo == true)) |
michael@0 | 986 | { |
michael@0 | 987 | CSFLogDebug(logTag, "Send SIP message to originator for stream id %d", stream); |
michael@0 | 988 | if ((*it)->sendInfo ( "","application/media_control+xml", "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" |
michael@0 | 989 | "<media_control>\n" |
michael@0 | 990 | "\n" |
michael@0 | 991 | " <vc_primitive>\n" |
michael@0 | 992 | " <to_encoder>\n" |
michael@0 | 993 | " <picture_fast_update/>\n" |
michael@0 | 994 | " </to_encoder>\n" |
michael@0 | 995 | " </vc_primitive>\n" |
michael@0 | 996 | "\n" |
michael@0 | 997 | "</media_control>\n")) |
michael@0 | 998 | { |
michael@0 | 999 | CSFLogWarn(logTag, "sendinfo returned true"); |
michael@0 | 1000 | bSent = true; |
michael@0 | 1001 | break; |
michael@0 | 1002 | } |
michael@0 | 1003 | else |
michael@0 | 1004 | { |
michael@0 | 1005 | CSFLogWarn(logTag, "sendinfo returned false"); |
michael@0 | 1006 | } |
michael@0 | 1007 | } |
michael@0 | 1008 | } |
michael@0 | 1009 | } |
michael@0 | 1010 | } |
michael@0 | 1011 | |
michael@0 | 1012 | void CC_SIPCCService::onMediaLost( int callId ) |
michael@0 | 1013 | { |
michael@0 | 1014 | } |
michael@0 | 1015 | |
michael@0 | 1016 | void CC_SIPCCService::onMediaRestored( int callId ) |
michael@0 | 1017 | { |
michael@0 | 1018 | } |
michael@0 | 1019 | |
michael@0 | 1020 | bool CC_SIPCCService::setLocalVoipPort(int port) { |
michael@0 | 1021 | return CCAPI_Config_set_local_voip_port(port); |
michael@0 | 1022 | } |
michael@0 | 1023 | |
michael@0 | 1024 | bool CC_SIPCCService::setRemoteVoipPort(int port) { |
michael@0 | 1025 | return CCAPI_Config_set_remote_voip_port(port); |
michael@0 | 1026 | } |
michael@0 | 1027 | |
michael@0 | 1028 | bool CC_SIPCCService::setP2PMode(bool mode) { |
michael@0 | 1029 | return CCAPI_Config_set_p2p_mode(mode); |
michael@0 | 1030 | } |
michael@0 | 1031 | |
michael@0 | 1032 | bool CC_SIPCCService::setSDPMode(bool mode) { |
michael@0 | 1033 | return CCAPI_Config_set_sdp_mode(mode); |
michael@0 | 1034 | } |
michael@0 | 1035 | |
michael@0 | 1036 | } // End of namespace CSF |