Index: pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 292)
+++ pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 293)
@@ -199,4 +199,5 @@
 
     /* Account: */
+    pj_bool_t	     has_acc;	    /**< Any --id cmdline?		*/
     int		     acc_cnt;	    /**< Number of client registrations	*/
     pjsua_acc	     acc[PJSUA_MAX_ACC];    /** Client regs array.	*/
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 292)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 293)
@@ -284,12 +284,25 @@
     
     status = pjsip_inv_initial_answer(inv, rdata, 
-				      (pjsua.auto_answer ? 200 : 100), 
+				      (pjsua.auto_answer ? pjsua.auto_answer 
+					: 100), 
 				      NULL, NULL, &response);
     if (status != PJ_SUCCESS) {
 	
-	pjsua_perror(THIS_FILE, "Unable to create 100 response", status);
-
-	pjsip_dlg_respond(dlg, rdata, 500, NULL, NULL, NULL);
-	pjsip_inv_terminate(inv, 500, PJ_FALSE);
+	int st_code;
+
+	pjsua_perror(THIS_FILE, "Unable to send answer to incoming INVITE", 
+		     status);
+
+	/* If failed to send 2xx response, there's a good chance that it is
+	 * because SDP negotiation has failed.
+	 */
+	if (pjsua.auto_answer/100 == 2)
+	    st_code = PJSIP_SC_UNSUPPORTED_MEDIA_TYPE;
+	else
+	    st_code = 500;
+
+	pjsip_dlg_respond(dlg, rdata, st_code, NULL, NULL, NULL);
+	pjsip_inv_terminate(inv, st_code, PJ_FALSE);
+	return PJ_TRUE;
 
     } else {
@@ -763,6 +776,10 @@
 	pjsua_perror(THIS_FILE, "SDP negotiation has failed", status);
 
-	/* Disconnect call if this is not a re-INVITE */
-	if (inv->state != PJSIP_INV_STATE_CONFIRMED) {
+	/* Disconnect call if we're not in the middle of initializing an
+	 * UAS dialog and if this is not a re-INVITE 
+	 */
+	if (inv->state != PJSIP_INV_STATE_NULL &&
+	    inv->state != PJSIP_INV_STATE_CONFIRMED) 
+	{
 	    call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE);
 	}
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 292)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 293)
@@ -75,5 +75,5 @@
     /* Default for media: */
     pjsua.clock_rate = 8000;
-    pjsua.complexity = 4;
+    pjsua.complexity = -1;
     pjsua.quality = 4;
 
@@ -85,4 +85,5 @@
 	pjsua.acc[i].local_uri = pj_str(PJSUA_LOCAL_URI);
 	pjsua.acc[i].reg_timeout = 55;
+	pjsua.acc[i].online_status = PJ_TRUE;
 	pj_list_init(&pjsua.acc[i].route_set);
 	pj_list_init(&pjsua.acc[i].pres_srv_list);
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_settings.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_settings.c	(revision 292)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_settings.c	(revision 293)
@@ -93,5 +93,5 @@
     puts  ("  --rtp-port=N        Base port to try for RTP (default=4000)");
     puts  ("  --add-codec=name    Specify alternate codec order");
-    puts  ("  --complexity=N      Specify encoding complexity (0-10, default=4)");
+    puts  ("  --complexity=N      Specify encoding complexity (0-10, default=none(-1))");
     puts  ("  --quality=N         Specify encoding quality (0-10, default=4)");
     puts  ("");
@@ -394,4 +394,5 @@
 	    }
 	    cur_acc->local_uri = pj_str(optarg);
+	    pjsua.has_acc = 1;
 	    break;
 
@@ -577,4 +578,21 @@
 }
 
+static const char *good_number(char *buf, pj_int32_t val)
+{
+    if (val < 1000) {
+	pj_ansi_sprintf(buf, "%d", val);
+    } else if (val < 1000000) {
+	pj_ansi_sprintf(buf, "%d.%dK", 
+			val / 1000,
+			(val % 1000) / 100);
+    } else {
+	pj_ansi_sprintf(buf, "%d.%02dM", 
+			val / 1000000,
+			(val % 1000000) / 10000);
+    }
+
+    return buf;
+}
+
 static void dump_media_session(pjmedia_session *session)
 {
@@ -589,4 +607,5 @@
 	int rem_port;
 	const char *dir;
+	char stxpkt[10], stxoct[10], srxpkt[10], srxoct[10];
 
 	pjmedia_session_get_stream_stat(session, i, &strm_stat);
@@ -605,16 +624,21 @@
 	
 	PJ_LOG(3,(THIS_FILE, 
-		  "%s[Media strm#%d] %.*s, %s, peer=%s:%d",
+		  "%s#%d %.*s @%dKHz, %s, peer=%s:%d",
 		  "               ",
 		  i,
 		  info.stream_info[i].fmt.encoding_name.slen,
 		  info.stream_info[i].fmt.encoding_name.ptr,
+		  info.stream_info[i].fmt.sample_rate / 1000,
 		  dir,
 		  rem_addr, rem_port));
 	PJ_LOG(3,(THIS_FILE, 
-		  "%s tx {pkt=%u, bytes=%u} rx {pkt=%u, bytes=%u}",
-		  "                             ",
-		  strm_stat.enc.pkt, strm_stat.enc.bytes,
-		  strm_stat.dec.pkt, strm_stat.dec.bytes));
+		  "%s tx{pt=%d,pkt=%s,oct=%s} rx{pt=%d,pkt=%s,oct=%s}",
+		  "                 ",
+		  info.stream_info[i].tx_pt,
+		  good_number(stxpkt, strm_stat.enc.pkt), 
+		  good_number(stxoct, strm_stat.enc.bytes),
+		  info.stream_info[i].fmt.pt,
+		  good_number(srxpkt, strm_stat.dec.pkt), 
+		  good_number(srxoct, strm_stat.dec.bytes)));
 
     }
@@ -763,10 +787,12 @@
 
     /* Save account settings. */
-    for (acc_index=0; acc_index < pjsua.acc_cnt; ++acc_index) {
-	
-	save_account_settings(acc_index, &cfg);
-
-	if (acc_index < pjsua.acc_cnt-1)
-	    pj_strcat2(&cfg, "--next-account\n");
+    if (pjsua.has_acc) {
+	for (acc_index=0; acc_index < pjsua.acc_cnt; ++acc_index) {
+	    
+	    save_account_settings(acc_index, &cfg);
+
+	    if (acc_index < pjsua.acc_cnt-1)
+		pj_strcat2(&cfg, "--next-account\n");
+	}
     }
 
@@ -850,5 +876,29 @@
 	pj_strcat2(&cfg, line);
     }
-
+    /* Media clock rate. */
+    if (pjsua.clock_rate >= 32000)
+	pj_strcat2(&cfg, "--uwb\n");
+    else if (pjsua.clock_rate >= 16000)
+	pj_strcat2(&cfg, "--wb\n");
+
+    /* Encoding quality and complexity */
+    pj_ansi_sprintf(line, "--quality %d\n",
+		    pjsua.quality);
+    pj_strcat2(&cfg, line);
+    pj_ansi_sprintf(line, "--complexity %d\n",
+		    pjsua.complexity);
+    pj_strcat2(&cfg, line);
+
+    /* Start RTP port. */
+    pj_ansi_sprintf(line, "--rtp-port %d\n",
+		    pjsua.start_rtp_port);
+    pj_strcat2(&cfg, line);
+
+    /* Add codec. */
+    for (i=0; i<pjsua.codec_cnt; ++i) {
+	pj_ansi_sprintf(line, "--add-codec %s\n",
+		    pjsua.codec_arg[i].ptr);
+	pj_strcat2(&cfg, line);
+    }
 
     pj_strcat2(&cfg, "#\n# User agent:\n#\n");
