Index: /pjproject/branches/1.0/pjmedia/src/pjmedia/conference.c
===================================================================
--- /pjproject/branches/1.0/pjmedia/src/pjmedia/conference.c	(revision 2788)
+++ /pjproject/branches/1.0/pjmedia/src/pjmedia/conference.c	(revision 2789)
@@ -887,6 +887,12 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
+    pj_mutex_lock(conf->mutex);
+
     /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
+    conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     conf_port = conf->ports[slot];
@@ -897,4 +903,6 @@
     if (rx != PJMEDIA_PORT_NO_CHANGE)
 	conf_port->rx_setting = rx;
+
+    pj_mutex_unlock(conf->mutex);
 
     return PJ_SUCCESS;
@@ -918,8 +926,4 @@
 		     sink_slot<conf->max_ports, PJ_EINVAL);
 
-    /* Ports must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[src_slot] != NULL, PJ_EINVAL);
-    PJ_ASSERT_RETURN(conf->ports[sink_slot] != NULL, PJ_EINVAL);
-
     /* For now, level MUST be zero. */
     PJ_ASSERT_RETURN(level == 0, PJ_EINVAL);
@@ -927,6 +931,11 @@
     pj_mutex_lock(conf->mutex);
 
+    /* Ports must be valid. */
     src_port = conf->ports[src_slot];
     dst_port = conf->ports[sink_slot];
+    if (!src_port || !dst_port) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     /* Check if connection has been made */
@@ -980,12 +989,13 @@
 		     sink_slot<conf->max_ports, PJ_EINVAL);
 
+    pj_mutex_lock(conf->mutex);
+
     /* Ports must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[src_slot] != NULL, PJ_EINVAL);
-    PJ_ASSERT_RETURN(conf->ports[sink_slot] != NULL, PJ_EINVAL);
-
-    pj_mutex_lock(conf->mutex);
-
     src_port = conf->ports[src_slot];
     dst_port = conf->ports[sink_slot];
+    if (!src_port || !dst_port) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     /* Check if connection has been made */
@@ -1058,7 +1068,4 @@
     PJ_ASSERT_RETURN(conf && port < conf->max_ports, PJ_EINVAL);
 
-    /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[port] != NULL, PJ_EINVAL);
-
     /* Suspend the sound devices.
      * Don't want to remove port while port is being accessed by sound
@@ -1068,5 +1075,11 @@
     pj_mutex_lock(conf->mutex);
 
+    /* Port must be valid. */
     conf_port = conf->ports[port];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
+
     conf_port->tx_setting = PJMEDIA_PORT_DISABLE;
     conf_port->rx_setting = PJMEDIA_PORT_DISABLE;
@@ -1137,4 +1150,7 @@
     PJ_ASSERT_RETURN(conf && p_count && ports, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
     for (i=0; i<conf->max_ports && count<*p_count; ++i) {
 	if (!conf->ports[i])
@@ -1144,4 +1160,7 @@
     }
 
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
+
     *p_count = count;
     return PJ_SUCCESS;
@@ -1160,8 +1179,13 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
     /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
-
     conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     info->slot = slot;
@@ -1178,4 +1202,7 @@
     info->rx_adj_level = conf_port->rx_adj_level - NORMAL_LEVEL;
 
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
+
     return PJ_SUCCESS;
 }
@@ -1190,4 +1217,7 @@
     PJ_ASSERT_RETURN(conf && size && info, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
     for (i=0; i<conf->max_ports && count<*size; ++i) {
 	if (!conf->ports[i])
@@ -1197,4 +1227,7 @@
 	++count;
     }
+
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
 
     *size = count;
@@ -1216,8 +1249,13 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
     /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
-
     conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     if (tx_level != NULL) {
@@ -1227,4 +1265,7 @@
     if (rx_level != NULL) 
 	*rx_level = conf_port->rx_level;
+
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
 
     return PJ_SUCCESS;
@@ -1244,7 +1285,4 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
-    /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
-
     /* Value must be from -128 to +127 */
     /* Disabled, you can put more than +127, at your own risk: 
@@ -1253,8 +1291,19 @@
     PJ_ASSERT_RETURN(adj_level >= -128, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
+    /* Port must be valid. */
     conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     /* Set normalized adjustment level. */
     conf_port->rx_adj_level = adj_level + NORMAL_LEVEL;
+
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
 
     return PJ_SUCCESS;
@@ -1274,7 +1323,4 @@
     PJ_ASSERT_RETURN(conf && slot<conf->max_ports, PJ_EINVAL);
 
-    /* Port must be valid. */
-    PJ_ASSERT_RETURN(conf->ports[slot] != NULL, PJ_EINVAL);
-
     /* Value must be from -128 to +127 */
     /* Disabled, you can put more than +127,, at your own risk:
@@ -1283,8 +1329,19 @@
     PJ_ASSERT_RETURN(adj_level >= -128, PJ_EINVAL);
 
+    /* Lock mutex */
+    pj_mutex_lock(conf->mutex);
+
+    /* Port must be valid. */
     conf_port = conf->ports[slot];
+    if (conf_port == NULL) {
+	pj_mutex_unlock(conf->mutex);
+	return PJ_EINVAL;
+    }
 
     /* Set normalized adjustment level. */
     conf_port->tx_adj_level = adj_level + NORMAL_LEVEL;
+
+    /* Unlock mutex */
+    pj_mutex_unlock(conf->mutex);
 
     return PJ_SUCCESS;
