Tests with other user agents revealed some bugs which
have been fixed below:

- some UAs sends "telephone-event/8000/1" instead of
  "telephone-event/8000", which caused SDP negotiation
  to fail. Fixed in sdp_neg.c.
- codec name was (incorrectly) compared case-sensitively,
  causing negotiation to fail. Fixed in sdp_neg.c.
- Also improved error reporting in SDP negotiation by 
  introducing few more error codes.
- Added Warning header in Not Acceptable response sent
  by pjsip_inv_session when SDP negotiation fails.
- PJSUA-LIB will try to negotiate both SDPs before
  sending 100 response.
- Fixed bug in iLBC codec when setting the mode to 30.

Also:
- Echo cancellation by default is disabled now since
  it doesn't seem to work. Further investigation needed.




git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@738 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c
index bb2ccd1..d3b88a7 100644
--- a/pjsip/src/pjsua-lib/pjsua_call.c
+++ b/pjsip/src/pjsua-lib/pjsua_call.c
@@ -394,38 +394,6 @@
 
     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) {
 	if (pjsua_var.calls[call_id].inv == NULL)
@@ -461,6 +429,35 @@
 	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;
+    } 
+
+
     /* 
      * Get which account is most likely to be associated with this incoming
      * call. We need the account to find which contact URI to put for
@@ -1837,6 +1834,9 @@
 
 	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 
 	 */