Index: /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
===================================================================
--- /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 1741)
+++ /pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 1742)
@@ -316,9 +316,11 @@
 pj_status_t pjsua_media_channel_init(pjsua_call_id call_id,
 				     pjsip_role_e role,
-				     int security_level);
+				     int security_level,
+				     int *sip_err_code);
 pj_status_t pjsua_media_channel_create_sdp(pjsua_call_id call_id, 
 					   pj_pool_t *pool,
 					   const pjmedia_sdp_session *rem_sdp,
-					   pjmedia_sdp_session **p_sdp);
+					   pjmedia_sdp_session **p_sdp,
+					   int *sip_err_code);
 pj_status_t pjsua_media_channel_update(pjsua_call_id call_id,
 				       pjmedia_sdp_session *local_sdp,
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 1741)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 1742)
@@ -402,5 +402,5 @@
     /* Init media channel */
     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
-				      get_secure_level(dest_uri));
+				      get_secure_level(dest_uri), NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Error initializing media channel", status);
@@ -412,5 +412,6 @@
     offer = NULL;
 #else
-    status = pjsua_media_channel_create_sdp(call->index, dlg->pool, NULL, &offer);
+    status = pjsua_media_channel_create_sdp(call->index, dlg->pool, NULL, 
+					    &offer, NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "pjmedia unable to create SDP", status);
@@ -559,5 +560,5 @@
     pjsua_call *call;
     int call_id = -1;
-    int secure_level;
+    int secure_level, sip_err_code;
     pjmedia_sdp_session *offer, *answer;
     pj_status_t status;
@@ -692,7 +693,9 @@
     /* Init media channel */
     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS, 
-				      secure_level);
-    if (status != PJ_SUCCESS) {
-	pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL,
+				      secure_level, &sip_err_code);
+    if (status != PJ_SUCCESS) {
+	pjsua_perror(THIS_FILE, "Error initializing media channel", status);
+	pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 
+				      sip_err_code, NULL,
 				      NULL, NULL);
 	PJSUA_UNLOCK();
@@ -719,7 +722,9 @@
     /* Get media capability from media endpoint: */
     status = pjsua_media_channel_create_sdp(call->index, rdata->tp_info.pool, 
-					    offer, &answer);
-    if (status != PJ_SUCCESS) {
-	pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL,
+					    offer, &answer, &sip_err_code);
+    if (status != PJ_SUCCESS) {
+	pjsua_perror(THIS_FILE, "Error creating SDP answer", status);
+	pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 
+				      sip_err_code, NULL,
 				      NULL, NULL);
 	pjsua_media_channel_deinit(call->index);
@@ -1425,5 +1430,6 @@
     /* Init media channel */
     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC,
-				      get_secure_level(&dlg->remote.info_str));
+				      get_secure_level(&dlg->remote.info_str),
+				      NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Error initializing media channel", status);
@@ -1436,5 +1442,5 @@
     PJ_TODO(create_active_inactive_sdp_based_on_unhold_arg);
     status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, 
-					    NULL, &sdp);
+					    NULL, &sdp, NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint", 
@@ -1495,5 +1501,6 @@
     /* Init media channel */
     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC,
-				      get_secure_level(&dlg->remote.info_str));
+				      get_secure_level(&dlg->remote.info_str),
+				      NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Error initializing media channel", status);
@@ -1504,5 +1511,5 @@
     /* Create SDP */
     status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, 
-					    NULL, &sdp);
+					    NULL, &sdp, NULL);
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint", 
@@ -2624,5 +2631,5 @@
 	secure_level = get_secure_level(&call->inv->dlg->remote.info_str);
 	status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS,
-					  secure_level);
+					  secure_level, NULL);
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Error initializing media channel", status);
@@ -2632,5 +2639,5 @@
 
 	status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, 
-					        offer, &answer);
+					        offer, &answer, NULL);
     }
 
@@ -2680,5 +2687,5 @@
 	secure_level = get_secure_level(&call->inv->dlg->remote.info_str);
 	status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC,
-					  secure_level);
+					  secure_level, NULL);
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Error initializing media channel", status);
@@ -2688,5 +2695,5 @@
 
 	status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, 
-					        NULL, offer);
+					        NULL, offer, NULL);
     }
 
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 1741)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 1742)
@@ -747,5 +747,6 @@
 pj_status_t pjsua_media_channel_init(pjsua_call_id call_id,
 				     pjsip_role_e role,
-				     int security_level)
+				     int security_level,
+				     int *sip_err_code)
 {
     pjsua_call *call = &pjsua_var.calls[call_id];
@@ -774,4 +775,6 @@
     if (acc->cfg.use_srtp != PJMEDIA_SRTP_DISABLED) {
 	if (security_level < acc->cfg.srtp_secure_signaling) {
+	    if (sip_err_code)
+		*sip_err_code = PJSIP_SC_NOT_ACCEPTABLE;
 	    return PJSIP_ESESSIONINSECURE;
 	}
@@ -785,6 +788,9 @@
 					   call->med_tp,
 					   &srtp_opt, &srtp);
-    if (status != PJ_SUCCESS)
-	return status;
+    if (status != PJ_SUCCESS) {
+	if (sip_err_code)
+	    *sip_err_code = PJSIP_SC_INTERNAL_SERVER_ERROR;
+	return status;
+    }
 
     /* Set SRTP as current media transport */
@@ -802,5 +808,6 @@
 					   pj_pool_t *pool,
 					   const pjmedia_sdp_session *rem_sdp,
-					   pjmedia_sdp_session **p_sdp)
+					   pjmedia_sdp_session **p_sdp,
+					   int *sip_status_code)
 {
     enum { MAX_MEDIA = 1, MEDIA_IDX = 0 };
@@ -823,6 +830,8 @@
     status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pool, MAX_MEDIA,
 				      &skinfo, &sdp);
-    if (status != PJ_SUCCESS)
+    if (status != PJ_SUCCESS) {
+	if (sip_status_code) *sip_status_code = 500;
 	goto on_error;
+    }
 
     /* Add NAT info in the SDP */
@@ -853,6 +862,8 @@
     status = pjmedia_transport_media_create(call->med_tp, pool, 
 					    sdp, rem_sdp, MEDIA_IDX);
-    if (status != PJ_SUCCESS)
+    if (status != PJ_SUCCESS) {
+	if (sip_status_code) *sip_status_code = PJSIP_SC_NOT_ACCEPTABLE;
 	goto on_error;
+    }
 
     *p_sdp = sdp;
