Added to pjsua: write new media settings, modify call stat output, fixed general bug

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@293 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c
index 1fc8060..b245a49 100644
--- a/pjsip/src/pjsua-lib/pjsua_call.c
+++ b/pjsip/src/pjsua-lib/pjsua_call.c
@@ -283,14 +283,27 @@
      */
     
     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);
+	int st_code;
 
-	pjsip_dlg_respond(dlg, rdata, 500, NULL, NULL, NULL);
-	pjsip_inv_terminate(inv, 500, PJ_FALSE);
+	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 {
 	status = pjsip_inv_send_msg(inv, response, NULL);
@@ -762,8 +775,12 @@
 
 	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);
 	}
 	return;