Skip to content

Commit

Permalink
Add ice aggressive option.
Browse files Browse the repository at this point in the history
git-svn-id: http://csipsimple.googlecode.com/svn/trunk/CSipSimple@2409 9f815046-5998-e9c0-b7e2-ac03a23edfa4
  • Loading branch information
r3gis3r committed May 10, 2014
1 parent 09d9586 commit bb24300
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 34 deletions.
12 changes: 11 additions & 1 deletion jni/swig-glue/pjsip_header.i
Original file line number Diff line number Diff line change
Expand Up @@ -945,4 +945,14 @@ struct pjsip_auth_clt_pref
*/
pj_str_t algorithm;

};
};

/* From ice_session.h */
struct pj_ice_sess_options
{
pj_bool_t aggressive;

unsigned nominated_check_delay;

int controlled_agent_want_nom_timeout;
};
2 changes: 2 additions & 0 deletions res/values/prefs_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<string name="nat_traversal">NAT traversal</string>
<string name="enable_ice">Enable ICE</string>
<string name="enable_ice_desc">Turn on ICE feature</string>
<string name="ice_aggressive">Aggressive ICE</string>
<string name="ice_aggressive_desc">Whether to use aggressive nomination</string>
<string name="enable_turn">Enable TURN</string>
<string name="enable_turn_desc">Turn on TURN feature</string>
<string name="turn_server">Turn server</string>
Expand Down
6 changes: 6 additions & 0 deletions res/xml/prefs_network.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@
android:key="enable_ice"
android:summary="@string/enable_ice_desc"
android:title="@string/enable_ice" />
<CheckBoxPreference
android:defaultValue="true"
android:dependency="enable_ice"
android:key="ice_aggressive"
android:summary="@string/ice_aggressive_desc"
android:title="@string/ice_aggressive" />
<CheckBoxPreference
android:defaultValue="false"
android:key="enable_stun"
Expand Down
10 changes: 10 additions & 0 deletions src/com/csipsimple/api/SipConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,16 @@ public class SipConfigManager {
* @see #setPreferenceBooleanValue(Context, String, boolean)
*/
public static final String ENABLE_ICE = "enable_ice";

/**
* Aggressive ICE nomination.<br/>
* Specify whether to use aggressive nomination. <br/>
* <a target="_blank" href=
* "http://www.pjsip.org/pjnath/docs/html/structpj__ice__sess__options.htm#ac8cc479ffdceffe057e4b1f9f823d531"
* >Pjsip documentation</a>
*
*/
public static final String ICE_AGGRESSIVE = "ice_aggressive";
/**
* Enable STUN.<br/>
* <a target="_blank" href=
Expand Down
36 changes: 22 additions & 14 deletions src/com/csipsimple/pjsip/PjSipService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.pjsip.pjsua.SWIGTYPE_p_pj_stun_auth_cred;
import org.pjsip.pjsua.csipsimple_config;
import org.pjsip.pjsua.dynamic_factory;
import org.pjsip.pjsua.pj_ice_sess_options;
import org.pjsip.pjsua.pj_pool_t;
import org.pjsip.pjsua.pj_qos_params;
import org.pjsip.pjsua.pj_str_t;
Expand Down Expand Up @@ -440,8 +441,8 @@ public boolean sipStart() throws SameThreadException {
}
}
// STUN
int isStunEnabled = prefsWrapper.getStunEnabled();
if (isStunEnabled == 1) {
boolean isStunEnabled = prefsWrapper.getPreferenceBooleanValue(SipConfigManager.ENABLE_STUN);
if (isStunEnabled) {
String[] servers = prefsWrapper.getPreferenceStringValue(
SipConfigManager.STUN_SERVER).split(",");
cfg.setStun_srv_cnt(servers.length);
Expand All @@ -452,9 +453,8 @@ public boolean sipStart() throws SameThreadException {
stunServersCount++;
}
cfg.setStun_srv(stunServers);
cfg.setStun_map_use_stun2(prefsWrapper
.getPreferenceBooleanValue(SipConfigManager.ENABLE_STUN2) ? pjsuaConstants.PJ_TRUE
: pjsuaConstants.PJ_FALSE);
cfg.setStun_map_use_stun2(boolToPjsuaConstant(prefsWrapper
.getPreferenceBooleanValue(SipConfigManager.ENABLE_STUN2)));
}

// LOGGING CONFIG
Expand Down Expand Up @@ -488,8 +488,8 @@ public boolean sipStart() throws SameThreadException {
echoMode = SipConfigManager.ECHO_MODE_SIMPLE;
}
mediaCfg.setEc_options(echoMode);
mediaCfg.setNo_vad(prefsWrapper
.getPreferenceBooleanValue(SipConfigManager.ENABLE_VAD) ? 0 : 1);
mediaCfg.setNo_vad(boolToPjsuaConstant(!prefsWrapper
.getPreferenceBooleanValue(SipConfigManager.ENABLE_VAD)));
mediaCfg.setQuality(prefsWrapper.getMediaQuality());
mediaCfg.setClock_rate(clockRate);
mediaCfg.setAudio_frame_ptime(prefsWrapper
Expand All @@ -506,16 +506,22 @@ public boolean sipStart() throws SameThreadException {
// Global thread count is 0, so don't use sip one anyway
hasOwnIoQueue = false;
}
mediaCfg.setHas_ioqueue(hasOwnIoQueue ? 1 : 0);
mediaCfg.setHas_ioqueue(boolToPjsuaConstant(hasOwnIoQueue));

// ICE
mediaCfg.setEnable_ice(prefsWrapper.getIceEnabled());

boolean iceEnabled = prefsWrapper.getPreferenceBooleanValue(SipConfigManager.ENABLE_ICE);
mediaCfg.setEnable_ice(boolToPjsuaConstant(iceEnabled));
if(iceEnabled) {
pj_ice_sess_options iceOpts = mediaCfg.getIce_opt();
boolean aggressiveIce = prefsWrapper.getPreferenceBooleanValue(SipConfigManager.ICE_AGGRESSIVE);
iceOpts.setAggressive(boolToPjsuaConstant(aggressiveIce));
}

// TURN
int isTurnEnabled = prefsWrapper.getTurnEnabled();
if (isTurnEnabled == 1) {
boolean isTurnEnabled = prefsWrapper.getPreferenceBooleanValue(SipConfigManager.ENABLE_TURN);
if (isTurnEnabled) {
SWIGTYPE_p_pj_stun_auth_cred creds = mediaCfg.getTurn_auth_cred();
mediaCfg.setEnable_turn(isTurnEnabled);
mediaCfg.setEnable_turn(boolToPjsuaConstant(isTurnEnabled));
mediaCfg.setTurn_server(pjsua.pj_str_copy(prefsWrapper.getTurnServer()));
pjsua.set_turn_credentials(
pjsua.pj_str_copy(prefsWrapper
Expand Down Expand Up @@ -2364,6 +2370,8 @@ public void setVideoAndroidCapturer(SurfaceView window) {
pjsua.vid_set_android_capturer((Object) window);
}


private static int boolToPjsuaConstant(boolean v) {
return v ? pjsuaConstants.PJ_TRUE : pjsuaConstants.PJ_FALSE;
}

}
3 changes: 2 additions & 1 deletion src/com/csipsimple/ui/prefs/PrefsLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ public static void afterBuildPrefsForType(Context ctxt, IPreferenceHelper pfh, i
}

if(!pfw.isAdvancedUser()) {


pfh.hidePreference(NWK_NAT_TRAVERSAL_KEY, SipConfigManager.ICE_AGGRESSIVE);
pfh.hidePreference(NWK_NAT_TRAVERSAL_KEY, SipConfigManager.ENABLE_TURN);
pfh.hidePreference(NWK_NAT_TRAVERSAL_KEY, SipConfigManager.TURN_SERVER);
pfh.hidePreference(NWK_NAT_TRAVERSAL_KEY, SipConfigManager.TURN_USERNAME);
Expand Down
18 changes: 0 additions & 18 deletions src/com/csipsimple/utils/PreferencesProviderWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,24 +528,6 @@ public long getMediaQuality() {
return 4;
}

/**
* Get whether ice is enabled
*
* @return 1 if enabled (pjstyle)
*/
public int getIceEnabled() {
return getPreferenceBooleanValue(SipConfigManager.ENABLE_ICE) ? 1 : 0;
}

/**
* Get whether turn is enabled
*
* @return 1 if enabled (pjstyle)
*/
public int getTurnEnabled() {
return getPreferenceBooleanValue(SipConfigManager.ENABLE_TURN) ? 1 : 0;
}

/**
* Get whether turn is enabled
*
Expand Down
1 change: 1 addition & 0 deletions src/com/csipsimple/utils/PreferencesWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public class PreferencesWrapper {
put(SipConfigManager.USE_IPV6, false);
put(SipConfigManager.ENABLE_DNS_SRV, false);
put(SipConfigManager.ENABLE_ICE, false);
put(SipConfigManager.ICE_AGGRESSIVE, true);
put(SipConfigManager.ENABLE_TURN, false);
put(SipConfigManager.ENABLE_STUN, false);
put(SipConfigManager.ENABLE_STUN2, false);
Expand Down

0 comments on commit bb24300

Please sign in to comment.