Index: /pjproject/trunk/pjmedia/include/pjmedia/echo.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/echo.h	(revision 4081)
+++ /pjproject/trunk/pjmedia/include/pjmedia/echo.h	(revision 4082)
@@ -96,6 +96,11 @@
      * without using WSOLA to expand and shrink audio samples.
      */
-    PJMEDIA_ECHO_USE_SIMPLE_FIFO = 32
-
+    PJMEDIA_ECHO_USE_SIMPLE_FIFO = 32,
+
+    /**
+     * If PJMEDIA_ECHO_USE_SW_ECHO flag is specified, software echo canceller
+     * will be used instead of device EC.
+     */
+    PJMEDIA_ECHO_USE_SW_ECHO = 64
 
 } pjmedia_echo_flag;
Index: /pjproject/trunk/pjmedia/include/pjmedia/sound_port.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/sound_port.h	(revision 4081)
+++ /pjproject/trunk/pjmedia/include/pjmedia/sound_port.h	(revision 4082)
@@ -77,4 +77,6 @@
 /**
  * This structure specifies the parameters to create the sound port.
+ * Use pjmedia_snd_port_param_default() to initialize this structure with
+ * default values (mostly zeroes)
  */
 typedef struct pjmedia_snd_port_param
@@ -89,5 +91,18 @@
      */
     unsigned options;
+
+    /**
+     * Echo cancellation options/flags.
+     */
+    unsigned ec_options;
+
 } pjmedia_snd_port_param;
+
+/**
+ * Initialize pjmedia_snd_port_param with default values.
+ *
+ * @param prm		    The parameter.
+ */
+PJ_DECL(void) pjmedia_snd_port_param_default(pjmedia_snd_port_param *prm);
 
 /**
Index: /pjproject/trunk/pjmedia/src/pjmedia-audiodev/coreaudio_dev.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-audiodev/coreaudio_dev.c	(revision 4081)
+++ /pjproject/trunk/pjmedia/src/pjmedia-audiodev/coreaudio_dev.c	(revision 4082)
@@ -1965,4 +1965,9 @@
 	strm->param.ec_enabled = *(pj_bool_t*)pval;
 
+        PJ_LOG(4, (THIS_FILE, "Using %s audio unit", 
+                              (desc.componentSubType ==
+                               kAudioUnitSubType_RemoteIO? "RemoteIO":
+                               "VoiceProcessingIO")));
+        
 	return PJ_SUCCESS;
     }
Index: /pjproject/trunk/pjmedia/src/pjmedia-codec/passthrough.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-codec/passthrough.c	(revision 4081)
+++ /pjproject/trunk/pjmedia/src/pjmedia-codec/passthrough.c	(revision 4082)
@@ -262,5 +262,6 @@
 	
 	if (len == 0) {
-	    info->frame_type = (pj_uint8_t)(enc_setting->amr_nb? 14 : 15);
+	    /* DTX */
+	    info->frame_type = 15;
 	} else {
 	    info->frame_type = pjmedia_codec_amr_get_mode2(enc_setting->amr_nb, 
Index: /pjproject/trunk/pjmedia/src/pjmedia/sound_port.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/sound_port.c	(revision 4081)
+++ /pjproject/trunk/pjmedia/src/pjmedia/sound_port.c	(revision 4082)
@@ -53,4 +53,5 @@
     unsigned		 bits_per_sample;
     unsigned		 options;
+    unsigned		 prm_ec_options;
 
     /* software ec */
@@ -188,4 +189,10 @@
 }
 
+/* Initialize with default values (zero) */
+PJ_DEF(void) pjmedia_snd_port_param_default(pjmedia_snd_port_param *prm)
+{
+    pj_bzero(prm, sizeof(*prm));
+}
+
 /*
  * Start the sound stream.
@@ -227,9 +234,12 @@
     if (param_copy.flags & PJMEDIA_AUD_DEV_CAP_EC) {
 	/* EC is wanted */
-	if (snd_port->aud_caps & PJMEDIA_AUD_DEV_CAP_EC) {
+	if ((snd_port->prm_ec_options & PJMEDIA_ECHO_USE_SW_ECHO) == 0 &&
+            snd_port->aud_caps & PJMEDIA_AUD_DEV_CAP_EC)
+        {
 	    /* Device supports EC */
 	    /* Nothing to do */
 	} else {
-	    /* Device doesn't support EC, remove EC settings from
+	    /* Application wants to use software EC or device
+             * doesn't support EC, remove EC settings from
 	     * device parameters
 	     */
@@ -263,9 +273,11 @@
 				  snd_port->samples_per_frame);
 
-    /* Create software EC if parameter specifies EC but device 
-     * doesn't support EC. Only do this if the format is PCM!
+    /* Create software EC if parameter specifies EC and
+     * (app specifically requests software EC or device
+     * doesn't support EC). Only do this if the format is PCM!
      */
     if ((snd_port->aud_param.flags & PJMEDIA_AUD_DEV_CAP_EC) &&
-	(snd_port->aud_caps & PJMEDIA_AUD_DEV_CAP_EC)==0 &&
+	((snd_port->aud_caps & PJMEDIA_AUD_DEV_CAP_EC)==0 ||
+         (snd_port->prm_ec_options & PJMEDIA_ECHO_USE_SW_ECHO) != 0) &&
 	param_copy.ext_fmt.id == PJMEDIA_FORMAT_PCM)
     {
@@ -278,5 +290,6 @@
 	    
 	status = pjmedia_snd_port_set_ec(snd_port, pool, 
-					 snd_port->aud_param.ec_tail_ms, 0);
+					 snd_port->aud_param.ec_tail_ms,
+					 snd_port->prm_ec_options);
 	if (status != PJ_SUCCESS) {
 	    pjmedia_aud_stream_destroy(snd_port->aud_stream);
@@ -339,5 +352,5 @@
     pj_status_t status;
 
-    PJ_UNUSED_ARG(options);
+    pjmedia_snd_port_param_default(&param);
 
     status = pjmedia_aud_dev_default_param(rec_id, &param.base);
@@ -353,4 +366,5 @@
     param.base.bits_per_sample = bits_per_sample;
     param.options = options;
+    param.ec_options = 0;
 
     return pjmedia_snd_port_create2(pool, &param, p_port);
@@ -372,5 +386,5 @@
     pj_status_t status;
 
-    PJ_UNUSED_ARG(options);
+    pjmedia_snd_port_param_default(&param);
 
     status = pjmedia_aud_dev_default_param(dev_id, &param.base);
@@ -385,4 +399,5 @@
     param.base.bits_per_sample = bits_per_sample;
     param.options = options;
+    param.ec_options = 0;
 
     return pjmedia_snd_port_create2(pool, &param, p_port);
@@ -405,5 +420,5 @@
     pj_status_t status;
 
-    PJ_UNUSED_ARG(options);
+    pjmedia_snd_port_param_default(&param);
 
     status = pjmedia_aud_dev_default_param(dev_id, &param.base);
@@ -418,4 +433,5 @@
     param.base.bits_per_sample = bits_per_sample;
     param.options = options;
+    param.ec_options = 0;
 
     return pjmedia_snd_port_create2(pool, &param, p_port);
@@ -446,6 +462,7 @@
     snd_port->samples_per_frame = prm->base.samples_per_frame;
     snd_port->bits_per_sample = prm->base.bits_per_sample;
-    pj_memcpy(&snd_port->aud_param, prm, sizeof(snd_port->aud_param));
+    pj_memcpy(&snd_port->aud_param, &prm->base, sizeof(snd_port->aud_param));
     snd_port->options = prm->options;
+    snd_port->prm_ec_options = prm->ec_options;
 
     ptime_usec = prm->base.samples_per_frame * 1000 / prm->base.channel_count /
@@ -510,5 +527,7 @@
 
     /* Determine whether we use device or software EC */
-    if (snd_port->aud_caps & PJMEDIA_AUD_DEV_CAP_EC) {
+    if ((snd_port->prm_ec_options & PJMEDIA_ECHO_USE_SW_ECHO) == 0 &&
+        snd_port->aud_caps & PJMEDIA_AUD_DEV_CAP_EC)
+    {
 	/* We use device EC */
 	pj_bool_t ec_enabled;
Index: /pjproject/trunk/pjsip-apps/src/pjsystest/systest.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsystest/systest.c	(revision 4081)
+++ /pjproject/trunk/pjsip-apps/src/pjsystest/systest.c	(revision 4082)
@@ -968,6 +968,7 @@
     }
 
-    status = pjsua_recorder_create(pj_cstr(&tmp, AEC_REC_PATH), 0, 0, -1,
-			           0, &writer_id);
+    status = pjsua_recorder_create(
+                 pj_cstr(&tmp, add_path(doc_path, AEC_REC_PATH)), 0, 0, -1,
+                 0, &writer_id);
     if (status != PJ_SUCCESS) {
 	PJ_PERROR(1,(THIS_FILE, status, "Error writing WAV file %s",
@@ -1000,5 +1001,7 @@
      * Play the result.
      */
-    status = pjsua_player_create(pj_cstr(&tmp, AEC_REC_PATH), 0, &player_id);
+    status = pjsua_player_create(
+                 pj_cstr(&tmp, add_path(doc_path, AEC_REC_PATH)),
+                 0, &player_id);
     if (status != PJ_SUCCESS) {
 	PJ_PERROR(1,(THIS_FILE, status, "Error opening WAV file %s", AEC_REC_PATH));
Index: /pjproject/trunk/pjsip/build/pjsip_core.vcproj
===================================================================
--- /pjproject/trunk/pjsip/build/pjsip_core.vcproj	(revision 4081)
+++ /pjproject/trunk/pjsip/build/pjsip_core.vcproj	(revision 4082)
@@ -3489,356 +3489,4 @@
 				</File>
 				<File
-					RelativePath="..\src\pjsip\sip_transport_tls_ossl.c"
-					>
-					<FileConfiguration
-						Name="Release|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|Pocket PC 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|Smartphone 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|Windows Mobile 6 Standard SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|Windows Mobile 6 Professional SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release|Windows Mobile 5.0 Smartphone SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Pocket PC 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Smartphone 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Windows Mobile 6 Standard SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Windows Mobile 6 Professional SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug|Windows Mobile 5.0 Smartphone SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Static|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Static|Pocket PC 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Static|Smartphone 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Static|Windows Mobile 6 Standard SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Static|Windows Mobile 6 Professional SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Static|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Static|Windows Mobile 5.0 Smartphone SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Dynamic|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Dynamic|Pocket PC 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Dynamic|Smartphone 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Dynamic|Windows Mobile 6 Standard SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Dynamic|Windows Mobile 6 Professional SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Dynamic|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Dynamic|Windows Mobile 5.0 Smartphone SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Dynamic|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Dynamic|Pocket PC 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Dynamic|Smartphone 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Dynamic|Windows Mobile 6 Standard SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Dynamic|Windows Mobile 6 Professional SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Dynamic|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Debug-Dynamic|Windows Mobile 5.0 Smartphone SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Static|Win32"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-							AdditionalIncludeDirectories=""
-							PreprocessorDefinitions=""
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Static|Pocket PC 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Static|Smartphone 2003 (ARMV4)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Static|Windows Mobile 6 Standard SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Static|Windows Mobile 6 Professional SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Static|Windows Mobile 5.0 Pocket PC SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-					<FileConfiguration
-						Name="Release-Static|Windows Mobile 5.0 Smartphone SDK (ARMV4I)"
-						ExcludedFromBuild="true"
-						>
-						<Tool
-							Name="VCCLCompilerTool"
-						/>
-					</FileConfiguration>
-				</File>
-				<File
 					RelativePath="..\src\pjsip\sip_transport_udp.c"
 					>
Index: /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c	(revision 4081)
+++ /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c	(revision 4082)
@@ -1819,5 +1819,4 @@
 	pjsip_tx_data *tdata;
 	pj_status_t status;
-	int next_refresh;
 
 	/* Only want to handle initial NOTIFY receive event. */
@@ -1899,17 +1898,12 @@
 	     pj_stricmp(&sub_state->sub_state, &STR_PENDING)==0))
 	{
-	    next_refresh = sub_state->expires_param;
-
-	} else {
-	    next_refresh = sub->expires->ivalue;
-	}
-
-	/* Update time */
-	update_expires(sub, next_refresh);
-
-	/* Start UAC refresh timer, only when we're not unsubscribing */
-	if (sub->expires->ivalue != 0) {
-	    unsigned timeout = (next_refresh > TIME_UAC_REFRESH) ?
-		next_refresh - TIME_UAC_REFRESH : next_refresh;
+	    int next_refresh = sub_state->expires_param;
+	    unsigned timeout;
+
+	    update_expires(sub, next_refresh);
+
+	    /* Start UAC refresh timer, only when we're not unsubscribing */
+	    timeout = (next_refresh > TIME_UAC_REFRESH) ?
+			next_refresh - TIME_UAC_REFRESH : next_refresh;
 
 	    PJ_LOG(5,(sub->obj_name, "Will refresh in %d seconds", timeout));
Index: /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 4081)
+++ /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 4082)
@@ -2243,5 +2243,5 @@
 
     default:
-	pj_assert("!Invalid operation!");
+	pj_assert(!"Invalid operation!");
 	pj_log_pop_indent();
 	return PJ_EINVALIDOP;
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 4081)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 4082)
@@ -1270,8 +1270,6 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Session Timer init failed", status);
-	status = pjsip_inv_end_session(inv, PJSIP_SC_INTERNAL_SERVER_ERROR,
-				       NULL, &response);
-	if (status == PJ_SUCCESS && response)
-	    status = pjsip_inv_send_msg(inv, response);
+        pjsip_dlg_respond(dlg, rdata, PJSIP_SC_INTERNAL_SERVER_ERROR, NULL, NULL, NULL);
+	pjsip_inv_terminate(inv, PJSIP_SC_INTERNAL_SERVER_ERROR, PJ_FALSE);
 
 	pjsua_media_channel_deinit(call->index);
