[Freeswitch-svn] [commit] r2417 - in freeswitch/trunk/src: . include mod/endpoints/mod_dingaling mod/endpoints/mod_exosip mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Mon Aug 28 19:05:27 EDT 2006


Author: anthm
Date: Mon Aug 28 19:05:26 2006
New Revision: 2417

Modified:
   freeswitch/trunk/src/include/switch_rtp.h
   freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
   freeswitch/trunk/src/mod/endpoints/mod_exosip/mod_exosip.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_rtp.c

Log:
tweaks

Modified: freeswitch/trunk/src/include/switch_rtp.h
==============================================================================
--- freeswitch/trunk/src/include/switch_rtp.h	(original)
+++ freeswitch/trunk/src/include/switch_rtp.h	Mon Aug 28 19:05:26 2006
@@ -140,6 +140,13 @@
 SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session);
 
 /*! 
+  \brief Test if an RTP session is ready
+  \param rtp_session an RTP session to test
+  \return a true value if it's ready
+*/
+SWITCH_DECLARE(uint8_t) switch_rtp_ready(switch_rtp_t *rtp_session);
+
+/*! 
   \brief Destroy an RTP session
   \param rtp_session an RTP session to destroy
 */

Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Mon Aug 28 19:05:26 2006
@@ -286,7 +286,7 @@
 	int ms = 20;
 	switch_rtp_flag_t flags;
 
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		return 1;
 	}
 
@@ -695,7 +695,7 @@
 		ldl_session_destroy(&tech_pvt->dlsession);
 	}
 
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		switch_rtp_destroy(&tech_pvt->rtp_session);
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NUKE RTP\n");
 		tech_pvt->rtp_session = NULL;
@@ -734,7 +734,7 @@
 
 			}
 
-			if (tech_pvt->rtp_session) {
+			if (switch_rtp_ready(tech_pvt->rtp_session)) {
 				switch_rtp_kill_socket(tech_pvt->rtp_session);
 			}
 
@@ -1629,7 +1629,7 @@
 			if (*msg == '+') {
 				switch_channel_queue_dtmf(channel, msg + 1);
 				switch_set_flag_locked(tech_pvt, TFLAG_DTMF);
-				if (tech_pvt->rtp_session) {
+				if (switch_rtp_ready(tech_pvt->rtp_session)) {
 					switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK);
 				}
 			}

Modified: freeswitch/trunk/src/mod/endpoints/mod_exosip/mod_exosip.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_exosip/mod_exosip.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_exosip/mod_exosip.c	Mon Aug 28 19:05:26 2006
@@ -490,7 +490,7 @@
 {
 	int loops = 0;//, sock = -1;
 
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
 			switch_yield(10000);
 			loops++;
@@ -587,7 +587,7 @@
 										   key,
 										   &err, switch_core_session_get_pool(tech_pvt->session));
 
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		uint8_t vad_in = switch_test_flag(tech_pvt, TFLAG_VAD_IN) ? 1 : 0;
 		uint8_t vad_out = switch_test_flag(tech_pvt, TFLAG_VAD_OUT) ? 1 : 0;
 		uint8_t inb = switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? 0 : 1;
@@ -840,7 +840,7 @@
 	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 	switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		switch_rtp_kill_socket(tech_pvt->rtp_session);
 	}
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Mon Aug 28 19:05:26 2006
@@ -579,7 +579,7 @@
 {
 	int loops = 0;//, sock = -1;
 
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
 			switch_yield(10000);
 			loops++;
@@ -606,7 +606,7 @@
 
 	assert(tech_pvt->codecs[tech_pvt->codec_index] != NULL);
 
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		return SWITCH_STATUS_SUCCESS;
 	}
 
@@ -680,7 +680,7 @@
 										   &err,
 										   switch_core_session_get_pool(tech_pvt->session));
 	
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		uint8_t vad_in = switch_test_flag(tech_pvt, TFLAG_VAD_IN) ? 1 : 0;
 		uint8_t vad_out = switch_test_flag(tech_pvt, TFLAG_VAD_OUT) ? 1 : 0;
 		uint8_t inb = switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? 0 : 1;
@@ -906,7 +906,7 @@
 	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 	switch_set_flag_locked(tech_pvt, TFLAG_HUP);
 
-	if (tech_pvt->rtp_session) {
+	if (switch_rtp_ready(tech_pvt->rtp_session)) {
 		switch_rtp_kill_socket(tech_pvt->rtp_session);
 	}
 

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Mon Aug 28 19:05:26 2006
@@ -1242,7 +1242,8 @@
 	*frame = NULL;
 
 	while (switch_channel_test_flag(session->channel, CF_HOLD)) {
-		return SWITCH_STATUS_BREAK;
+		status = SWITCH_STATUS_BREAK;
+		goto done;
 	}
 
 	if (session->endpoint_interface->io_routines->read_frame) {
@@ -1261,15 +1262,20 @@
 		}
 	}
 
-	if (status != SWITCH_STATUS_SUCCESS || !(*frame)) {
-		return status;
+	if (status != SWITCH_STATUS_SUCCESS) {
+		goto done;
 	}
 
+	if (!(*frame)) {
+		goto done;
+	}
+
 	assert(session != NULL);
 	assert(*frame != NULL);
 	
 	if (switch_test_flag(*frame, SFF_CNG)) {
-		return SWITCH_STATUS_SUCCESS;
+		status = SWITCH_STATUS_SUCCESS;
+		goto done;
 	}
 
 	if ((session->read_codec && (*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) {
@@ -1318,7 +1324,7 @@
 			default:
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s decoder error!\n",
 								  session->read_codec->codec_interface->interface_name);
-				return status;
+				goto done;
 			}
 		}
 		if (session->read_resampler) {
@@ -1346,7 +1352,8 @@
 					switch_buffer_create(session->pool, &session->raw_read_buffer, bytes);
 				}
 				if (!switch_buffer_write(session->raw_read_buffer, read_frame->data, read_frame->datalen)) {
-					return SWITCH_STATUS_MEMERR;
+					status = SWITCH_STATUS_MEMERR;
+					goto done;
 				}
 			}
 
@@ -1401,6 +1408,11 @@
 				goto top;
 			}
 		}
+	}
+
+ done:
+	if (!(*frame)) {
+		status = SWITCH_STATUS_FALSE;
 	}
 
 	return status;

Modified: freeswitch/trunk/src/switch_rtp.c
==============================================================================
--- freeswitch/trunk/src/switch_rtp.c	(original)
+++ freeswitch/trunk/src/switch_rtp.c	Mon Aug 28 19:05:26 2006
@@ -170,6 +170,7 @@
 	struct switch_rtp_rfc2833_data dtmf_data;
 	uint8_t mini;
 	switch_payload_t te;
+	switch_mutex_t *flag_mutex;
 };
 
 static int global_init = 0;
@@ -332,9 +333,9 @@
 
 	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER) || switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK)) {
 		switch_socket_opt_set(rtp_session->sock, APR_SO_NONBLOCK, TRUE);
-		switch_set_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
+		switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_NOBLOCK);
 	}
-	switch_set_flag(rtp_session, SWITCH_RTP_FLAG_IO);
+	switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_IO);
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -378,9 +379,13 @@
 		return SWITCH_STATUS_MEMERR;
 	}
 
+
+
 	rtp_session->pool = pool;
 	rtp_session->flags = flags;
 	rtp_session->te = 101;
+
+	switch_mutex_init(&rtp_session->flag_mutex, SWITCH_MUTEX_NESTED, rtp_session->pool);
 	switch_mutex_init(&rtp_session->dtmf_data.dtmf_mutex, SWITCH_MUTEX_NESTED, rtp_session->pool);
 	switch_buffer_create(rtp_session->pool, &rtp_session->dtmf_data.dtmf_buffer, 128);
 	/* for from address on recvfrom calls */
@@ -390,7 +395,7 @@
 	if (crypto_key) {
 		int len;
 
-		switch_set_flag(rtp_session, SWITCH_RTP_FLAG_SECURE);
+		switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_SECURE);
 		crypto_policy_set_rtp_default(&policy.rtp);
 		crypto_policy_set_rtcp_default(&policy.rtcp);
 		policy.ssrc.type  = ssrc_any_inbound;
@@ -502,7 +507,7 @@
 
 	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI)) {
 		switch_rtp_miniframe_probe(rtp_session);
-		switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_MINI);
+		switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_MINI);
 	}
 
 	return rtp_session;
@@ -537,24 +542,33 @@
 SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session)
 {
 	apr_socket_shutdown(rtp_session->sock, APR_SHUTDOWN_READWRITE);
-	switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_IO);
+	switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_IO);
 }
 
+SWITCH_DECLARE(uint8_t) switch_rtp_ready(switch_rtp_t *rtp_session)
+{
+	return switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) ? 1 : 0;
+}
 
 SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session)
 {
+
+	if (!switch_test_flag((*rtp_session), SWITCH_RTP_FLAG_IO)) {
+		return;
+	}
+
 	switch_rtp_kill_socket(*rtp_session);
 	switch_socket_close((*rtp_session)->sock);
 
 	if (switch_test_flag((*rtp_session), SWITCH_RTP_FLAG_VAD)) {
 		switch_rtp_disable_vad(*rtp_session);
 	}
+
 	if (switch_test_flag((*rtp_session), SWITCH_RTP_FLAG_SECURE)) {
 		srtp_dealloc((*rtp_session)->recv_ctx);
 		srtp_dealloc((*rtp_session)->send_ctx);
 	}
 
-	*rtp_session = NULL;
 	return;
 }
 
@@ -591,7 +605,7 @@
 SWITCH_DECLARE(void) switch_rtp_set_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags) 
 {
 	
-	switch_set_flag(rtp_session, flags);
+	switch_set_flag_locked(rtp_session, flags);
 
 }
 
@@ -605,7 +619,7 @@
 SWITCH_DECLARE(void) switch_rtp_clear_flag(switch_rtp_t *rtp_session, switch_rtp_flag_t flags) 
 {
 	
-	switch_clear_flag(rtp_session, flags);
+	switch_clear_flag_locked(rtp_session, flags);
 
 }
 
@@ -698,7 +712,7 @@
 		status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *)&rtp_session->recv_msg, &bytes);
 		
 		if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
-			switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_BREAK);
+			switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
 			return 0;
 		}
 
@@ -727,7 +741,7 @@
 			uint32_t effective_size = (uint32_t)(bytes - sizeof(srtp_mini_hdr_t));
 			if (rtp_session->recv_msg.header.pt == RTP_MAGIC_NUMBER) {
 				if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_MINI)) {
-					switch_set_flag(rtp_session, SWITCH_RTP_FLAG_MINI);
+					switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_MINI);
 					rtp_session->rpacket_size = ntohl(rtp_session->recv_msg.header.ts);
 					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "YAY MINI-RTP! %d\n", rtp_session->rpacket_size);
 					switch_rtp_miniframe_probe(rtp_session);
@@ -802,7 +816,7 @@
 						switch_rtp_set_remote_address(rtp_session, tx_host, rtp_session->from_addr->port, &err);
 					}
 				}
-				switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
+				switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
 			}
 		}
 
@@ -1231,7 +1245,7 @@
 		return SWITCH_STATUS_GENERR;
 	}
 	switch_core_codec_destroy(&rtp_session->vad_data.vad_codec);
-	switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_VAD);
+	switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_VAD);
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -1268,7 +1282,7 @@
 	rtp_session->vad_data.start = 0;
 	rtp_session->vad_data.next_scan = time(NULL);
 	rtp_session->vad_data.scan_freq = 0;
-	switch_set_flag(rtp_session, SWITCH_RTP_FLAG_VAD);
+	switch_set_flag_locked(rtp_session, SWITCH_RTP_FLAG_VAD);
 	switch_set_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_CNG);
 	return SWITCH_STATUS_SUCCESS;
 }



More information about the Freeswitch-svn mailing list