[Freeswitch-svn] [commit] r10360 - in freeswitch/trunk/src: . include

FreeSWITCH SVN anthm at freeswitch.org
Wed Nov 12 07:34:35 PST 2008


Author: anthm
Date: Wed Nov 12 10:34:34 2008
New Revision: 10360

Log:
add mutex to codecs

Modified:
   freeswitch/trunk/src/include/switch_module_interfaces.h
   freeswitch/trunk/src/switch_core_codec.c

Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h	Wed Nov 12 10:34:34 2008
@@ -544,6 +544,7 @@
 	/*! private data for the codec module to store handle specific info */
 	void *private_info;
 	switch_payload_t agreed_pt;
+	switch_mutex_t *mutex;
 };
 
 /*! \brief A table of settings and callbacks that define a paticular implementation of a codec */

Modified: freeswitch/trunk/src/switch_core_codec.c
==============================================================================
--- freeswitch/trunk/src/switch_core_codec.c	(original)
+++ freeswitch/trunk/src/switch_core_codec.c	Wed Nov 12 10:34:34 2008
@@ -450,7 +450,7 @@
 		}
 
 		implementation->init(codec, flags, codec_settings);
-
+		switch_mutex_init(&codec->mutex, SWITCH_MUTEX_NESTED, codec->memory_pool);
 		return SWITCH_STATUS_SUCCESS;
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec %s Exists but not at the desired implementation. %dhz %dms\n", codec_name, rate,
@@ -467,6 +467,8 @@
 														 uint32_t decoded_rate,
 														 void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
 {
+	switch_status_t status;
+
 	switch_assert(codec != NULL);
 	switch_assert(encoded_data != NULL);
 	switch_assert(decoded_data != NULL);
@@ -481,8 +483,13 @@
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
 
-	return codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len, decoded_rate, encoded_data, encoded_data_len, encoded_rate,
-										 flag);
+	if (codec->mutex) switch_mutex_lock(codec->mutex);
+	status = codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len, 
+										   decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
+	if (codec->mutex) switch_mutex_unlock(codec->mutex);
+
+	return status;
+										   
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
@@ -492,6 +499,8 @@
 														 uint32_t encoded_rate,
 														 void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
 {
+	switch_status_t status;
+
 	switch_assert(codec != NULL);
 	switch_assert(encoded_data != NULL);
 	switch_assert(decoded_data != NULL);
@@ -506,27 +515,40 @@
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
 
-	return codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate, decoded_data, decoded_data_len, decoded_rate,
-										 flag);
+	if (codec->mutex) switch_mutex_lock(codec->mutex);
+	status = codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate, 
+										   decoded_data, decoded_data_len, decoded_rate, flag);
+	if (codec->mutex) switch_mutex_unlock(codec->mutex);
+
+	return status;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
 {
-	switch_assert(codec != NULL);
+	switch_mutex_t *mutex;
+	switch_memory_pool_t *pool;
 
+	switch_assert(codec != NULL);	
+	
 	if (!codec->implementation) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n");
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
 
+	pool = codec->memory_pool;
+	mutex = codec->mutex;
+
+	if (mutex) switch_mutex_lock(mutex);
+
 	codec->implementation->destroy(codec);
+	memset(codec, 0, sizeof(*codec));
+	
+	if (mutex) switch_mutex_unlock(mutex);
 
 	if (switch_test_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL)) {
-		switch_core_destroy_memory_pool(&codec->memory_pool);
+		switch_core_destroy_memory_pool(&pool);
 	}
 
-	memset(codec, 0, sizeof(*codec));
-
 	return SWITCH_STATUS_SUCCESS;
 }
 



More information about the Freeswitch-svn mailing list