Closed #1129:
 - Added run-time configuration for activating/deactivating stream keep-alive (non-codec-VAD mechanism), also added this config to account settings.
 - Fixed bug wrong session info pointer "si" in pjsua_media_channel_update() when call audio index is not zero.




git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3313 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/docs/doxygen.cfg b/pjsip/docs/doxygen.cfg
index fc87325..d6c2318 100644
--- a/pjsip/docs/doxygen.cfg
+++ b/pjsip/docs/doxygen.cfg
@@ -846,7 +846,8 @@
 

 PREDEFINED             = PJ_DECL(x)=x PJ_DEF(x)=x PJ_IDECL(x)=x \

 			 PJ_IDEF(x)=x PJ_INLINE(x)=x PJ_DECL_DATA(x)=x \

-			 PJMEDIA_HAS_SRTP=1

+			 PJMEDIA_HAS_SRTP=1 \

+			 PJMEDIA_STREAM_ENABLE_KA=1

 

 

 # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then 

diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index 0ab2494..44f7345 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -2317,6 +2317,17 @@
      */
     unsigned	     reg_use_proxy;
 
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && (PJMEDIA_STREAM_ENABLE_KA != 0)
+    /**
+     * Specify whether stream keep-alive and NAT hole punching with
+     * non-codec-VAD mechanism (see @ref PJMEDIA_STREAM_ENABLE_KA) is enabled
+     * for this account.
+     *
+     * Default: PJ_FALSE (disabled)
+     */
+    pj_bool_t	     use_stream_ka;
+#endif
+
 } pjsua_acc_config;
 
 
diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c
index fbda32c..0163ed5 100644
--- a/pjsip/src/pjsua-lib/pjsua_acc.c
+++ b/pjsip/src/pjsua-lib/pjsua_acc.c
@@ -754,6 +754,10 @@
     acc->cfg.srtp_optional_dup_offer = cfg->srtp_optional_dup_offer;    
 #endif
 
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && (PJMEDIA_STREAM_ENABLE_KA != 0)
+    acc->cfg.use_stream_ka = cfg->use_stream_ka;
+#endif
+
     /* Global outbound proxy */
     if (global_route_crc != acc->global_route_crc) {
 	unsigned i, rcnt;
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index a0e43b2..9fb0a5d 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -185,6 +185,9 @@
     cfg->contact_rewrite_method = PJSUA_CONTACT_REWRITE_METHOD;
     cfg->reg_use_proxy = PJSUA_REG_USE_OUTBOUND_PROXY |
 			 PJSUA_REG_USE_ACC_PROXY;
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
+    cfg->use_stream_ka = (PJMEDIA_STREAM_ENABLE_KA != 0);
+#endif
 }
 
 PJ_DEF(void) pjsua_buddy_config_default(pjsua_buddy_config *cfg)
diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c
index 2eb0894..85a28cc 100644
--- a/pjsip/src/pjsua-lib/pjsua_media.c
+++ b/pjsip/src/pjsua-lib/pjsua_media.c
@@ -1545,8 +1545,10 @@
     
     /* Reset session info with only one media stream */
     sess_info.stream_cnt = 1;
-    if (si != &sess_info.stream_info[0])
+    if (si != &sess_info.stream_info[0]) {
 	pj_memcpy(&sess_info.stream_info[0], si, sizeof(pjmedia_stream_info));
+	si = &sess_info.stream_info[0];
+    }
 
     /* Check if no media is active */
     if (sess_info.stream_cnt == 0 || si->dir == PJMEDIA_DIR_NONE)
@@ -1638,6 +1640,11 @@
 	si->rtp_seq = call->rtp_tx_seq;
 	si->rtp_seq_ts_set = call->rtp_tx_seq_ts_set;
 
+#if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0
+	/* Enable/disable stream keep-alive and NAT hole punch. */
+	si->use_ka = pjsua_var.acc[call->acc_id].cfg.use_stream_ka;
+#endif
+
 	/* Create session based on session info. */
 	status = pjmedia_session_create( pjsua_var.med_endpt, &sess_info,
 					 &call->med_tp,