Index: /pjproject/branches/users/nanang/pjmedia/include/pjmedia/errno.h
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/include/pjmedia/errno.h	(revision 1699)
+++ /pjproject/branches/users/nanang/pjmedia/include/pjmedia/errno.h	(revision 1700)
@@ -527,4 +527,20 @@
 
 
+/************************************************************
+ * SRTP TRANSPORT ERRORS
+ ***********************************************************/
+/**
+ * @hideinitializer
+ * Secure transport required in SDP media descriptor.
+ */
+#define PJMEDIA_SRTP_ESDPREQSECTP   (PJMEDIA_ERRNO_START+220)    /* 220220 */
+/**
+ * @hideinitializer
+ * SDP contains ambigue answer.
+ */
+#define PJMEDIA_SRTP_ESDPAMBIGUEANS (PJMEDIA_ERRNO_START+221)    /* 220221 */
+
+
+
 /**
  * Get error message for the specified error code. Note that this
Index: /pjproject/branches/users/nanang/pjmedia/src/pjmedia/errno.c
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/src/pjmedia/errno.c	(revision 1699)
+++ /pjproject/branches/users/nanang/pjmedia/src/pjmedia/errno.c	(revision 1700)
@@ -142,4 +142,9 @@
     PJ_BUILD_ERR( PJMEDIA_ESNDINDEVID,	    "Invalid sound device ID" ),
     PJ_BUILD_ERR( PJMEDIA_ESNDINSAMPLEFMT,  "Invalid sample format for sound device" ),
+
+    /* SRTP transport errors: */
+    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPREQSECTP,   "Secure transport required in SDP media descriptor" ),
+    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPAMBIGUEANS, "SDP contains ambigue answer" ),
+    
 };
 
Index: /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c	(revision 1699)
+++ /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c	(revision 1700)
@@ -22,4 +22,5 @@
 #include <pjlib-util/base64.h>
 #include <pj/assert.h>
+#include <pj/lock.h>
 #include <pj/log.h>
 #include <pj/os.h>
@@ -72,5 +73,5 @@
     pjmedia_transport	 base;	    /**< Base transport interface. */
     pj_pool_t		*pool;
-    pj_mutex_t		*mutex;
+    pj_lock_t		*mutex;
     char		 tx_buffer[MAX_BUFFER_LEN];
     char		 rx_buffer[MAX_BUFFER_LEN];
@@ -174,10 +175,11 @@
 static pj_status_t pjmedia_srtp_init_lib(void)
 {
-    err_status_t err;
     static pj_bool_t initialized = PJ_FALSE;
 
     if (initialized == PJ_FALSE) {
+	err_status_t err;
 	err = srtp_init();
 	if (err != err_status_ok) { 
+	    PJ_LOG(4, (THIS_FILE, "Failed to init libsrtp."));
 	    return SRTP_ERROR(err);
 	}
@@ -208,7 +210,6 @@
     /* Init libsrtp. */
     status = pjmedia_srtp_init_lib();
-    if (status != PJ_SUCCESS) {
+    if (status != PJ_SUCCESS)
 	return status;
-    }
 
     pool = pjmedia_endpt_create_pool(endpt, "srtp%p", 1000, 1000);
@@ -220,5 +221,5 @@
     srtp->options = options;
 
-    status = pj_mutex_create_recursive(pool, pool->obj_name, &srtp->mutex);
+    status = pj_lock_create_null_mutex(pool, pool->obj_name, &srtp->mutex);
     if (status != PJ_SUCCESS) {
 	pj_pool_release(pool);
@@ -259,5 +260,6 @@
 
     if (p_srtp->session_inited) {
-	return PJ_EEXISTS;
+	PJ_LOG(4, (THIS_FILE, "SRTP could not be re-init'd before deinit'd"));
+	return PJ_EINVALIDOP;
     }
 
@@ -276,4 +278,5 @@
 
     if ((cs_tx_idx == -1) || (cs_rx_idx == -1)) {
+	PJ_LOG(4, (THIS_FILE, "Crypto-suite specified is not supported."));
 	return PJ_ENOTSUP;
     }
@@ -330,7 +333,7 @@
     p_srtp->session_inited = PJ_TRUE;
 
-    PJ_LOG(3, (THIS_FILE, "TX %s key=%s", crypto_suites[cs_tx_idx].name,
+    PJ_LOG(5, (THIS_FILE, "TX %s key=%s", crypto_suites[cs_tx_idx].name,
 	   octet_string_hex_string(policy_tx->key.ptr, policy_tx->key.slen)));
-    PJ_LOG(3, (THIS_FILE, "RX %s key=%s", crypto_suites[cs_rx_idx].name,
+    PJ_LOG(5, (THIS_FILE, "RX %s key=%s", crypto_suites[cs_rx_idx].name,
 	   octet_string_hex_string(policy_rx->key.ptr, policy_rx->key.slen)));
 
@@ -352,11 +355,9 @@
     err = srtp_dealloc(p_srtp->srtp_rx_ctx);
     if (err != err_status_ok) {
-	PJ_TODO(LOG_ERROR_DEALLOC_RX);
-	//return SRTP_ERROR(err);
+	PJ_LOG(4, (THIS_FILE, "Failed to dealloc RX SRTP context"));
     }
     err = srtp_dealloc(p_srtp->srtp_tx_ctx);
     if (err != err_status_ok) {
-	PJ_TODO(LOG_ERROR_DEALLOC_TX);
-	//return SRTP_ERROR(err);
+	PJ_LOG(4, (THIS_FILE, "Failed to dealloc TX SRTP context"));
     }
 
@@ -402,7 +403,6 @@
     status = pjmedia_transport_attach(srtp->real_tp, srtp, rem_addr, rem_rtcp,
 				      addr_len, &srtp_rtp_cb, &srtp_rtcp_cb);
-    if (status != PJ_SUCCESS) {
-	PJ_TODO(HANDLE_FAILURE);
-    }
+    if (status != PJ_SUCCESS)
+	return status;
 
     /* Save the callbacks */
@@ -443,5 +443,5 @@
     PJ_ASSERT_RETURN(size < sizeof(srtp->tx_buffer), PJ_ETOOBIG);
 
-    pj_mutex_lock(srtp->mutex);
+    pj_lock_acquire(srtp->mutex);
     pj_memcpy(srtp->tx_buffer, pkt, size);
     
@@ -453,5 +453,5 @@
     }
     
-    pj_mutex_unlock(srtp->mutex);
+    pj_lock_release(srtp->mutex);
 
     return status;
@@ -472,5 +472,5 @@
     PJ_ASSERT_RETURN((size) < sizeof(srtp->tx_buffer), PJ_ETOOBIG);
 
-    pj_mutex_lock(srtp->mutex);
+    pj_lock_acquire(srtp->mutex);
     pj_memcpy(srtp->tx_buffer, pkt, size);
 
@@ -483,5 +483,5 @@
     }
 
-    pj_mutex_unlock(srtp->mutex);
+    pj_lock_release(srtp->mutex);
 
     return status;
@@ -501,4 +501,6 @@
     transport_srtp *srtp = (transport_srtp *) tp;
     pj_status_t status;
+
+    pj_lock_destroy(srtp->mutex);
 
     pjmedia_transport_detach(tp, NULL);
@@ -509,11 +511,8 @@
 
     status = pjmedia_transport_srtp_deinit_session(tp);
-    if (status != PJ_SUCCESS)
-	return status;
-
-    pj_mutex_destroy(srtp->mutex);
+
     pj_pool_release(srtp->pool);
 
-    return PJ_SUCCESS;
+    return status;
 }
 
@@ -531,19 +530,16 @@
     }
 
-    pj_mutex_lock(srtp->mutex);
+    pj_lock_acquire(srtp->mutex);
     pj_memcpy(srtp->rx_buffer, pkt, size);
 
     err = srtp_unprotect(srtp->srtp_rx_ctx, srtp->rx_buffer, &len);
     
-    /* unprotect should returns less (or same, if auth disabled) size */
-    PJ_TODO(CHECK_SIZE_AFTER_UNPROTECT);
-
     if (err == err_status_ok) {
 	srtp->rtp_cb(srtp->user_data, srtp->rx_buffer, len);
     } else {
-	PJ_TODO(LOG_ERROR_UNPROTECT);
-    }
-
-    pj_mutex_unlock(srtp->mutex);
+	PJ_LOG(5, (THIS_FILE, "Failed to unprotect SRTP"));
+    }
+
+    pj_lock_release(srtp->mutex);
 }
 
@@ -561,19 +557,16 @@
     }
 
-    pj_mutex_lock(srtp->mutex);
+    pj_lock_acquire(srtp->mutex);
     pj_memcpy(srtp->rx_buffer, pkt, size);
 
     err = srtp_unprotect_rtcp(srtp->srtp_rx_ctx, srtp->rx_buffer, &len);
-
-    /* unprotect should returns less (or same, if auth disabled) size */
-    PJ_TODO(CHECK_SIZE_AFTER_UNPROTECT);
 
     if (err == err_status_ok) {
 	srtp->rtcp_cb(srtp->user_data, srtp->rx_buffer, len);
     } else {
-	PJ_TODO(LOG_ERROR_UNPROTECT);
+	PJ_LOG(5, (THIS_FILE, "Failed to unprotect SRTCP"));
     }
     
-    pj_mutex_unlock(srtp->mutex);
+    pj_lock_release(srtp->mutex);
 }
 
@@ -780,5 +773,5 @@
 	pj_stricmp(&media_remote->desc.transport, &ID_RTP_SAVP))
     {
-	return PJMEDIA_SDP_EINPROTO;
+	return PJMEDIA_SRTP_ESDPREQSECTP;
     }
 
@@ -800,6 +793,9 @@
 	for (i=0; i<media_remote->attr_count; ++i) {
 	    if (!pj_stricmp2(&media_local->attr[i]->name, "crypto")) {
-		if (attr)
-		    return PJMEDIA_ERROR;
+		if (attr) {
+		    PJ_LOG(5,(THIS_FILE, "More than one crypto attr in " \
+					 "the SDP answer."));
+		    return PJMEDIA_SRTP_ESDPAMBIGUEANS;
+		}
 
 		attr = media_local->attr[i];
@@ -990,7 +986,6 @@
 
     status = pjmedia_transport_srtp_deinit_session(tp);
-    if (status != PJ_SUCCESS) {
-	PJ_TODO(LOG_ERROR_DEINIT_SRTP);
-    }
+    if (status != PJ_SUCCESS)
+	PJ_LOG(4, (THIS_FILE, "Failed deinit session."));
 
     return pjmedia_transport_media_stop(srtp->real_tp);
Index: /pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- /pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_media.c	(revision 1699)
+++ /pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_media.c	(revision 1700)
@@ -538,6 +538,5 @@
 	if (pjsua_var.media_cfg.enable_srtp) {
 	    pjmedia_transport *tp;
-	    unsigned srtp_options = 
-				PJMEDIA_SRTP_AUTO_CLOSE_UNDERLYING_TRANSPORT;
+	    unsigned srtp_options = 0;
 
 	    status = pjmedia_transport_udp_attach(pjsua_var.med_endpt, NULL,
@@ -928,5 +927,6 @@
     for (i=0; i < sess_info.stream_cnt; ++i) {
 	if (sess_info.stream_info[i].type == PJMEDIA_TYPE_AUDIO &&
-	    sess_info.stream_info[i].proto == PJMEDIA_TP_PROTO_RTP_AVP)
+	    (sess_info.stream_info[i].proto == PJMEDIA_TP_PROTO_RTP_AVP ||
+	     sess_info.stream_info[i].proto == PJMEDIA_TP_PROTO_RTP_SAVP))
 	{
 	    si = &sess_info.stream_info[i];
Index: /pjproject/branches/users/nanang/third_party/srtp/crypto/rng/rand_source.c
===================================================================
--- /pjproject/branches/users/nanang/third_party/srtp/crypto/rng/rand_source.c	(revision 1699)
+++ /pjproject/branches/users/nanang/third_party/srtp/crypto/rng/rand_source.c	(revision 1700)
@@ -109,5 +109,5 @@
   if (read(dev_random_fdes, dest, len) != len)
     return err_status_fail;
-#elif (_MSC_VER >= 1400)
+#elif 0 && (_MSC_VER >= 1400)
   unsigned int *dst = dest;
   while (len)
