[Freeswitch-svn] [commit] r4473 - in freeswitch/trunk/src: . mod/endpoints/mod_sofia mod/timers/mod_softtimer

Freeswitch SVN anthm at freeswitch.org
Wed Mar 7 18:24:09 EST 2007


Author: anthm
Date: Wed Mar  7 18:24:09 2007
New Revision: 4473

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c
   freeswitch/trunk/src/switch_rtp.c

Log:
wip

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	Wed Mar  7 18:24:09 2007
@@ -787,9 +787,10 @@
 	if (tech_pvt->te > 95) {
 		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d telephone-event/8000\na=fmtp:%d 0-16\n", tech_pvt->te, tech_pvt->te);
 	}
-
-	snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d CN/%d\n", tech_pvt->cng_pt, rate);
-
+	if (tech_pvt->cng_pt) {
+		snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d CN/%d\n", tech_pvt->cng_pt, rate);
+		tech_pvt->cng_pt = 0;
+	}
     if (ptime) {
         snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", ptime);
     }

Modified: freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c
==============================================================================
--- freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c	(original)
+++ freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c	Wed Mar  7 18:24:09 2007
@@ -53,6 +53,7 @@
     switch_size_t reference;
     switch_size_t start;
 	uint32_t roll;
+	uint32_t ready;
 };
 typedef struct timer_private timer_private_t;
 
@@ -83,6 +84,7 @@
 		timer->private_info = private_info;
 		private_info->start = private_info->reference = TIMER_MATRIX[timer->interval].tick;
 		private_info->roll = TIMER_MATRIX[timer->interval].roll;
+		private_info->ready = 1;
 		return SWITCH_STATUS_SUCCESS;
 	}
 
@@ -102,7 +104,7 @@
 	timer_private_t *private_info = timer->private_info;
 	uint64_t samples;
 
-	if (globals.RUNNING != 1) {
+	if (globals.RUNNING != 1 || private_info->ready == 0) {
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -127,7 +129,7 @@
 
 	timer_step(timer);
 
-	while (globals.RUNNING == 1 && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
+	while (globals.RUNNING == 1 && private_info->ready  && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
 		check_roll();
 		switch_yield(1000);
 	}
@@ -146,7 +148,7 @@
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
     switch_size_t diff;
 
-	if (globals.RUNNING != 1) {
+	if (globals.RUNNING != 1 || !private_info->ready) {
 		return SWITCH_STATUS_SUCCESS;
 	}
 
@@ -170,13 +172,14 @@
 
 static inline switch_status_t timer_destroy(switch_timer_t *timer)
 {
+	timer_private_t *private_info = timer->private_info;
 	switch_mutex_lock(globals.mutex);
 	TIMER_MATRIX[timer->interval].count--;
 	if (TIMER_MATRIX[timer->interval].count == 0) {
 		TIMER_MATRIX[timer->interval].tick = 0;
 	}
 	switch_mutex_unlock(globals.mutex);
-	timer->private_info = NULL;
+	private_info->ready = 0;
 	return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/trunk/src/switch_rtp.c
==============================================================================
--- freeswitch/trunk/src/switch_rtp.c	(original)
+++ freeswitch/trunk/src/switch_rtp.c	Wed Mar  7 18:24:09 2007
@@ -779,8 +779,12 @@
 			switch_core_timer_step(&rtp_session->timer);
 		}
 		
-		if (rtp_session->recv_msg.header.pt == rtp_session->cng_pt) {
-			*flags |= SFF_CNG;
+		if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
+			return -1;
+		}
+		
+		if (rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) {
+			continue;
 		}
 
 		if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
@@ -795,10 +799,6 @@
             return 2 + rtp_header_len;
 		}
 
-		if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
-			return -1;
-		}
-		
 		if (bytes < 0) {
 			return (int)bytes;
 		} else if (bytes > 0 && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
@@ -824,7 +824,7 @@
 				uint8_t data[2] = {0};
 				switch_frame_flag_t flags = SFF_NONE;
 				data[0] = 127;
-
+				printf("WTF %u %u\n", rtp_session->timer.samplecount, (rtp_session->last_write_ts + (rtp_session->packet_size * 5)));
 				rtp_session->last_write_ts = rtp_session->timer.samplecount;
 				rtp_session->seq = ntohs(rtp_session->seq) + 1;
 				rtp_session->seq = htons(rtp_session->seq);
@@ -958,12 +958,13 @@
 
 SWITCH_DECLARE(switch_size_t) switch_rtp_has_dtmf(switch_rtp_t *rtp_session)
 {
-	switch_size_t has;
+	switch_size_t has = 0;
 
-	assert(rtp_session != NULL);
-	switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
-	has = switch_buffer_inuse(rtp_session->dtmf_data.dtmf_buffer);
-	switch_mutex_unlock(rtp_session->dtmf_data.dtmf_mutex);
+	if (switch_rtp_ready(rtp_session)) {
+		switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
+		has = switch_buffer_inuse(rtp_session->dtmf_data.dtmf_buffer);
+		switch_mutex_unlock(rtp_session->dtmf_data.dtmf_mutex);
+	}
 
 	return has;
 }
@@ -975,7 +976,9 @@
 	switch_size_t wr = 0;
 	char *p;
 
-	assert(rtp_session != NULL);
+	if (!switch_rtp_ready(rtp_session)) {
+		return SWITCH_STATUS_FALSE;
+	}
 
 	switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
 
@@ -1005,9 +1008,11 @@
 
 SWITCH_DECLARE(switch_size_t) switch_rtp_dequeue_dtmf(switch_rtp_t *rtp_session, char *dtmf, switch_size_t len)
 {
-	switch_size_t bytes;
+	switch_size_t bytes = 0;
 
-	assert(rtp_session != NULL);
+	if (!switch_rtp_ready(rtp_session)) {
+		return bytes;
+	}
 
 	switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
 	if ((bytes = switch_buffer_read(rtp_session->dtmf_data.dtmf_buffer, dtmf, len)) > 0) {
@@ -1024,6 +1029,10 @@
 {
 	char *c;
 
+	if (!switch_rtp_ready(rtp_session)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
 	if (!rtp_session->dtmf_data.dtmf_queue) {
 		switch_queue_create(&rtp_session->dtmf_data.dtmf_queue, 100, rtp_session->pool);
 	}
@@ -1046,8 +1055,13 @@
 
 SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags)
 {
+	int bytes = 0;
 
-	int bytes = rtp_common_read(rtp_session, payload_type, flags);
+	if (!switch_rtp_ready(rtp_session)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	bytes = rtp_common_read(rtp_session, payload_type, flags);
 	
 	if (bytes < 0) {
 		*datalen = 0;
@@ -1068,7 +1082,13 @@
 
 SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame)
 {
-	int bytes = rtp_common_read(rtp_session, &frame->payload, &frame->flags);
+	int bytes = 0;
+
+	if (!switch_rtp_ready(rtp_session)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	bytes = rtp_common_read(rtp_session, &frame->payload, &frame->flags);
 
 	frame->data = rtp_session->recv_msg.body;
 	frame->packet = &rtp_session->recv_msg;
@@ -1099,7 +1119,13 @@
 														 switch_frame_flag_t *flags)
 {
 
-	int bytes = rtp_common_read(rtp_session, payload_type, flags);
+	int bytes = 0;
+
+	if (!switch_rtp_ready(rtp_session)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	bytes = rtp_common_read(rtp_session, payload_type, flags);
 	*data = rtp_session->recv_msg.body;
 
 	if (bytes < 0) {
@@ -1116,10 +1142,16 @@
 static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t datalen, uint8_t m, switch_payload_t payload, switch_frame_flag_t *flags)
 {
 	switch_size_t bytes;
-	uint8_t fwd = (uint8_t)(!flags || (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)));
+	uint8_t fwd = 0;
 	rtp_msg_t *send_msg;
 	uint8_t send = 1;
 
+	if (!switch_rtp_ready(rtp_session)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
+	fwd = (uint8_t)(!flags || (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)));
+	
 	if (fwd) {
 		bytes = datalen;
 		send_msg = (rtp_msg_t *) data;
@@ -1283,6 +1315,11 @@
 
 SWITCH_DECLARE(switch_status_t) switch_rtp_disable_vad(switch_rtp_t *rtp_session)
 {
+
+	if (!switch_rtp_ready(rtp_session)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
 	if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD)) {
 		return SWITCH_STATUS_GENERR;
 	}
@@ -1293,6 +1330,11 @@
 
 SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session, switch_core_session_t *session, switch_codec_t *codec, switch_vad_flag_t flags)
 {
+
+	if (!switch_rtp_ready(rtp_session)) {
+		return SWITCH_STATUS_FALSE;
+	}
+
 	if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD)) {
 		return SWITCH_STATUS_GENERR;
 	}
@@ -1334,6 +1376,10 @@
 {
 	uint8_t mark = 0;
 
+	if (!switch_rtp_ready(rtp_session)) {
+		return -1;
+	}
+
 	if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
 		return -1;
 	}
@@ -1359,13 +1405,21 @@
 
 SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, uint32_t ts)
 {
-	uint8_t fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && switch_test_flag(frame, SFF_RAW_RTP)) ? 1 : 0;
-	uint8_t packetize = (rtp_session->packet_size > frame->datalen && (frame->payload == rtp_session->payload)) ? 1 : 0;
+	uint8_t fwd = 0;
+	uint8_t packetize = 0;
 	void *data;
 	uint32_t len;
 	uint8_t mark = 0;
 	switch_payload_t payload;
 
+	
+	if (!switch_rtp_ready(rtp_session)) {
+		return -1;
+	}
+
+	fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && switch_test_flag(frame, SFF_RAW_RTP)) ? 1 : 0;
+	packetize = (rtp_session->packet_size > frame->datalen && (frame->payload == rtp_session->payload)) ? 1 : 0;
+
 	if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
 		return -1;
 	}
@@ -1423,6 +1477,10 @@
 {
 	rtp_msg_t send_msg = {{0}};
 
+	if (!switch_rtp_ready(rtp_session)) {
+		return -1;
+	}
+
 	if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
 		return -1;
 	}



More information about the Freeswitch-svn mailing list