Index: /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c	(revision 1725)
+++ /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c	(revision 1726)
@@ -182,7 +182,4 @@
 };
 
-char * octet_string_hex_string(const void *s, int length);
-
-
 const char* get_libsrtp_errstr(int err)
 {
@@ -344,5 +341,5 @@
     }
 
-    status = pj_lock_create_null_mutex(pool, pool->obj_name, &srtp->mutex);
+    status = pj_lock_create_recursive_mutex(pool, pool->obj_name, &srtp->mutex);
     if (status != PJ_SUCCESS) {
 	pj_pool_release(pool);
@@ -634,5 +631,5 @@
 
     if (srtp->bypass_srtp)
-	return pjmedia_transport_send_rtp(srtp->real_tp, pkt, size);
+	return pjmedia_transport_send_rtcp(srtp->real_tp, pkt, size);
 
     if (!srtp->session_inited)
@@ -673,5 +670,5 @@
     pj_status_t status;
 
-    pj_lock_destroy(srtp->mutex);
+    pj_lock_acquire(srtp->mutex);
 
     pjmedia_transport_detach(tp, NULL);
@@ -683,4 +680,7 @@
     status = pjmedia_transport_srtp_stop(tp);
 
+    pj_lock_release(srtp->mutex);
+
+    pj_lock_destroy(srtp->mutex);
     pj_pool_release(srtp->pool);
 
@@ -714,5 +714,6 @@
 	srtp->rtp_cb(srtp->user_data, srtp->rx_buffer, len);
     } else {
-	PJ_LOG(5, (THIS_FILE, "Failed to unprotect SRTP"));
+	PJ_LOG(5, (THIS_FILE, "Failed to unprotect SRTP size=%d, err=%d", 
+		   size, err));
     }
 
@@ -746,5 +747,6 @@
 	srtp->rtcp_cb(srtp->user_data, srtp->rx_buffer, len);
     } else {
-	PJ_LOG(5, (THIS_FILE, "Failed to unprotect SRTCP"));
+	PJ_LOG(5, (THIS_FILE, "Failed to unprotect SRTCP size=%d, err=%d",
+		   size, err));
     }
     
@@ -798,6 +800,8 @@
 
 	} while (!key_ok);
-	key[crypto_suites[cs_idx].cipher_key_len] = '\0';
-	pj_strdup2(pool, &crypto->key, key);
+	crypto->key.ptr = pj_pool_zalloc(pool, 
+					 crypto_suites[cs_idx].cipher_key_len);
+	pj_memcpy(crypto->key.ptr, key, crypto_suites[cs_idx].cipher_key_len);
+	crypto->key.slen = crypto_suites[cs_idx].cipher_key_len;
     }
 
@@ -965,5 +969,5 @@
 	    /* Offer crypto-suites based on setting. */
 	    buffer_len = MAXLEN;
-	    status = generate_crypto_attr_value(pool, buffer, &buffer_len,
+	    status = generate_crypto_attr_value(srtp->pool, buffer, &buffer_len,
 						&srtp->setting.crypto[i],
 						i+1);
@@ -974,5 +978,5 @@
 	    if (buffer_len) {
 		pj_strset(&attr_value, buffer, buffer_len);
-		attr = pjmedia_sdp_attr_create(pool, ID_CRYPTO.ptr, 
+		attr = pjmedia_sdp_attr_create(srtp->pool, ID_CRYPTO.ptr, 
 					       &attr_value);
 		m_loc->attr[m_loc->attr_count++] = attr;
@@ -1002,5 +1006,5 @@
 	    has_crypto_attr = PJ_TRUE;
 
-	    status = parse_attr_crypto(pool, m_rem->attr[i], 
+	    status = parse_attr_crypto(srtp->pool, m_rem->attr[i], 
 				       &tmp_rx_crypto, &tags[cr_attr_count]);
 	    if (status != PJ_SUCCESS)
@@ -1022,4 +1026,16 @@
 		    {
 			int cs_idx = get_crypto_idx(&tmp_rx_crypto.name);
+
+			/* Force to use test key */
+			//char *hex_test_key = "58b29c5c8f42308120ce857e439f2d"
+			//		     "7810a8b10ad0b1446be5470faea496";
+			//pj_str_t* test_key = &srtp->setting.crypto[j].key;
+			//char  *raw_test_key = pj_pool_zalloc(srtp->pool, 64);
+			//hex_string_to_octet_string(
+			//		raw_test_key,
+			//		hex_test_key,
+			//		strlen(hex_test_key));
+			//pj_strset(test_key, raw_test_key, 
+			//	  crypto_suites[cs_idx].cipher_key_len);
 
 			if (tmp_rx_crypto.key.slen != 
@@ -1070,5 +1086,5 @@
 	 */
 	buffer_len = MAXLEN;
-	status = generate_crypto_attr_value(pool, buffer, &buffer_len,
+	status = generate_crypto_attr_value(srtp->pool, buffer, &buffer_len,
 					    &srtp->tx_policy,
 					    chosen_tag);
@@ -1079,5 +1095,6 @@
 	if (buffer_len) {
 	    pj_strset(&attr_value, buffer, buffer_len);
-	    attr = pjmedia_sdp_attr_create(pool, ID_CRYPTO.ptr, &attr_value);
+	    attr = pjmedia_sdp_attr_create(srtp->pool, ID_CRYPTO.ptr, 
+					   &attr_value);
 	    m_loc->attr[m_loc->attr_count++] = attr;
 	}
@@ -1162,5 +1179,5 @@
 	    has_crypto_attr = PJ_TRUE;
 
-	    status = parse_attr_crypto(pool, m_rem->attr[i], 
+	    status = parse_attr_crypto(srtp->pool, m_rem->attr[i], 
 				       &tmp_tx_crypto, &rem_tag);
 	    if (status != PJ_SUCCESS)
