Index: /pjproject/trunk/pjmedia/include/pjmedia/errno.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/errno.h	(revision 737)
+++ /pjproject/trunk/pjmedia/include/pjmedia/errno.h	(revision 738)
@@ -199,4 +199,19 @@
  */
 #define PJMEDIA_SDPNEG_ENOMEDIA	    (PJMEDIA_ERRNO_START+48)    /* 220048 */
+/**
+ * @hideinitializer
+ * No suitable codec for remote offer.
+ */
+#define PJMEDIA_SDPNEG_NOANSCODEC   (PJMEDIA_ERRNO_START+49)    /* 220049 */
+/**
+ * @hideinitializer
+ * No suitable telephone-event for remote offer.
+ */
+#define PJMEDIA_SDPNEG_NOANSTELEVENT (PJMEDIA_ERRNO_START+50)   /* 220050 */
+/**
+ * @hideinitializer
+ * No suitable answer for unknown remote offer.
+ */
+#define PJMEDIA_SDPNEG_NOANSUNKNOWN (PJMEDIA_ERRNO_START+51)    /* 220051 */
 
 
Index: /pjproject/trunk/pjmedia/src/pjmedia-codec/ilbc.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia-codec/ilbc.c	(revision 737)
+++ /pjproject/trunk/pjmedia/src/pjmedia-codec/ilbc.c	(revision 738)
@@ -396,5 +396,5 @@
     if (attr->setting.dec_fmtp_mode == 20)
 	ilbc_codec->dec_frame_size = 38;
-    else if (attr->setting.dec_fmtp_mode == 20)
+    else if (attr->setting.dec_fmtp_mode == 30)
 	ilbc_codec->dec_frame_size = 50;
     else {
Index: /pjproject/trunk/pjmedia/src/pjmedia/errno.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/errno.c	(revision 737)
+++ /pjproject/trunk/pjmedia/src/pjmedia/errno.c	(revision 738)
@@ -68,4 +68,7 @@
     PJ_BUILD_ERR( PJMEDIA_SDPNEG_EANSNOMEDIA,	"No common SDP media payload in answer" ),
     PJ_BUILD_ERR( PJMEDIA_SDPNEG_ENOMEDIA,	"No active media stream after negotiation" ),
+    PJ_BUILD_ERR( PJMEDIA_SDPNEG_NOANSCODEC,	"No suitable codec for remote offer"),
+    PJ_BUILD_ERR( PJMEDIA_SDPNEG_NOANSTELEVENT,	"No suitable telephone-event for remote offer"),
+    PJ_BUILD_ERR( PJMEDIA_SDPNEG_NOANSUNKNOWN,	"No suitable answer for unknown remote offer"),
 
     /* SDP comparison results */
Index: /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c	(revision 737)
+++ /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c	(revision 738)
@@ -534,7 +534,8 @@
 			 * count match 
 			 */
-			if (!pj_strcmp(&or.enc_name, &ar.enc_name) &&
+			if (!pj_stricmp(&or.enc_name, &ar.enc_name) &&
 			    or.clock_rate == ar.clock_rate &&
-			    pj_strcmp(&or.param, &ar.param)==0)
+			    (pj_stricmp(&or.param, &ar.param)==0 ||
+			     ar.param.slen==1 && *ar.param.ptr=='1'))
 			{
 			    /* Match! */
@@ -629,8 +630,8 @@
 
 /* Try to match offer with answer. */
-static pj_bool_t match_offer(pj_pool_t *pool,
-			     const pjmedia_sdp_media *offer,
-			     const pjmedia_sdp_media *local,
-			     pjmedia_sdp_media **p_answer)
+static pj_status_t match_offer(pj_pool_t *pool,
+			       const pjmedia_sdp_media *offer,
+			       const pjmedia_sdp_media *local,
+			       pjmedia_sdp_media **p_answer)
 {
     unsigned i;
@@ -698,5 +699,5 @@
 		if (!a) {
 		    pj_assert(!"Bug! Offer should have been validated");
-		    return PJ_FALSE;
+		    return PJMEDIA_SDP_EMISSINGRTPMAP;
 		}
 		pjmedia_sdp_attr_get_rtpmap(a, &or);
@@ -727,7 +728,8 @@
 			 * channel count  match 
 			 */
-			if (!pj_strcmp(&or.enc_name, &lr.enc_name) &&
+			if (!pj_stricmp(&or.enc_name, &lr.enc_name) &&
 			    or.clock_rate == lr.clock_rate &&
-			    pj_strcmp(&or.param, &lr.param)==0) 
+			    (pj_strcmp(&or.param, &lr.param)==0 ||
+			     or.param.slen==1 && *or.param.ptr=='1')) 
 			{
 			    /* Match! */
@@ -767,10 +769,14 @@
     /* See if all types of offer can be matched. */
 #if 1
-    if ((offer_has_codec && !found_matching_codec) ||
-	(offer_has_telephone_event && !found_matching_telephone_event) ||
-	(offer_has_other && !found_matching_other))
-    {
-	/* Some of the payload in the offer has no matching local sdp */
-	return PJ_FALSE;
+    if (offer_has_codec && !found_matching_codec) {
+	return PJMEDIA_SDPNEG_NOANSCODEC;
+    }
+
+    if (offer_has_telephone_event && !found_matching_telephone_event) {
+	return PJMEDIA_SDPNEG_NOANSTELEVENT;
+    }
+
+    if (offer_has_other && !found_matching_other) {
+	return PJMEDIA_SDPNEG_NOANSUNKNOWN;
     }
 #else
@@ -828,5 +834,5 @@
 
     *p_answer = answer;
-    return PJ_TRUE;
+    return PJ_SUCCESS;
 }
 
@@ -837,5 +843,5 @@
 				  pjmedia_sdp_session **p_answer)
 {
-    pj_status_t status;
+    pj_status_t status = PJMEDIA_SDPNEG_ENOMEDIA;
     pj_bool_t has_active = PJ_FALSE;
     pjmedia_sdp_session *answer;
@@ -880,8 +886,6 @@
 	    {
 		/* See if it has matching codec. */
-		pj_bool_t match;
-
-		match = match_offer(pool, om, im, &am);
-		if (match) {
+		status = match_offer(pool, om, im, &am);
+		if (status == PJ_SUCCESS) {
 		    /* Mark media as used. */
 		    media_used[j] = 1;
@@ -926,6 +930,5 @@
     *p_answer = answer;
 
-    return has_active ? PJ_SUCCESS : PJMEDIA_SDPNEG_ENOMEDIA;
-    //return PJ_SUCCESS;
+    return has_active ? PJ_SUCCESS : status;
 }
 
Index: /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 737)
+++ /pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h	(revision 738)
@@ -2103,5 +2103,5 @@
 #define PJSUA_DEFAULT_CODEC_QUALITY 5
 #define PJSUA_DEFAULT_ILBC_MODE	    20
-#define PJSUA_DEFAULT_EC_TAIL_LEN   256
+#define PJSUA_DEFAULT_EC_TAIL_LEN   0
 
 
Index: /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 737)
+++ /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 738)
@@ -615,5 +615,4 @@
 		/* Incompatible media */
 		code = PJSIP_SC_NOT_ACCEPTABLE_HERE;
-		status = PJSIP_ERRNO_FROM_SIP_STATUS(code);
 
 		if (p_tdata) {
@@ -2415,7 +2414,36 @@
 	    /* Process SDP in the answer */
 	    status = process_answer(inv, 200, tdata, NULL);
-	    if (status != PJ_SUCCESS)
+
+	    if (status != PJ_SUCCESS) {
+		/*
+		 * SDP negotiation has failed.
+		 */
+		pj_status_t rc;
+		pj_str_t reason;
+
+		/* Delete the 2xx answer */
+		pjsip_tx_data_dec_ref(tdata);
+		
+		/* Create 500 response */
+		reason = pj_str("SDP negotiation failed");
+		rc = pjsip_dlg_create_response(dlg, rdata, 500, &reason, 
+					       &tdata);
+		if (rc == PJ_SUCCESS) {
+		    pjsip_warning_hdr *w;
+		    const pj_str_t *endpt_name;
+
+		    endpt_name = pjsip_endpt_name(dlg->endpt);
+		    w = pjsip_warning_hdr_create_from_status(tdata->pool, 
+							     endpt_name,
+							     status);
+		    if (w)
+			pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)w);
+
+		    pjsip_inv_send_msg(inv, tdata);
+		}
 		return;
-
+	    }
+
+	    /* Send 2xx regardless of the status of negotiation */
 	    status = pjsip_inv_send_msg(inv, tdata);
 
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 737)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 738)
@@ -395,36 +395,4 @@
     PJSUA_LOCK();
 
-    /* Verify that we can handle the request. */
-    status = pjsip_inv_verify_request(rdata, &options, NULL, NULL,
-				      pjsua_var.endpt, &response);
-    if (status != PJ_SUCCESS) {
-
-	/*
-	 * No we can't handle the incoming INVITE request.
-	 */
-
-	if (response) {
-	    pjsip_response_addr res_addr;
-
-	    pjsip_get_response_addr(response->pool, rdata, &res_addr);
-	    pjsip_endpt_send_response(pjsua_var.endpt, &res_addr, response, 
-				      NULL, NULL);
-
-	} else {
-
-	    /* Respond with 500 (Internal Server Error) */
-	    pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL,
-					  NULL, NULL);
-	}
-
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
-    } 
-
-
-    /*
-     * Yes we can handle the incoming INVITE request.
-     */
-
     /* Find free call slot. */
     for (call_id=0; call_id<(int)pjsua_var.ua_cfg.max_calls; ++call_id) {
@@ -461,4 +429,33 @@
 	return PJ_TRUE;
     }
+
+
+    /* Verify that we can handle the request. */
+    status = pjsip_inv_verify_request(rdata, &options, answer, NULL,
+				      pjsua_var.endpt, &response);
+    if (status != PJ_SUCCESS) {
+
+	/*
+	 * No we can't handle the incoming INVITE request.
+	 */
+
+	if (response) {
+	    pjsip_response_addr res_addr;
+
+	    pjsip_get_response_addr(response->pool, rdata, &res_addr);
+	    pjsip_endpt_send_response(pjsua_var.endpt, &res_addr, response, 
+				      NULL, NULL);
+
+	} else {
+
+	    /* Respond with 500 (Internal Server Error) */
+	    pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL,
+					  NULL, NULL);
+	}
+
+	PJSUA_UNLOCK();
+	return PJ_TRUE;
+    } 
+
 
     /* 
@@ -1838,4 +1835,7 @@
 	pjsua_perror(THIS_FILE, "SDP negotiation has failed", status);
 
+	/* Stop/destroy media, if any */
+	call_destroy_media(call->index);
+
 	/* Disconnect call if we're not in the middle of initializing an
 	 * UAS dialog and if this is not a re-INVITE 
