[Freeswitch-svn] [commit] r7491 - in freeswitch/trunk/src: . mod/applications/mod_esf

Freeswitch SVN anthm at freeswitch.org
Fri Feb 1 20:46:11 EST 2008


Author: anthm
Date: Fri Feb  1 20:46:11 2008
New Revision: 7491

Modified:
   freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c
   freeswitch/trunk/src/switch_core_io.c

Log:
 fix esf for g722

Modified: freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c	Fri Feb  1 20:46:11 2008
@@ -63,7 +63,7 @@
 	switch_status_t status;
 	switch_size_t bytes;
 	ls_control_packet_t control_packet;
-	switch_codec_t *read_codec;
+	switch_codec_t codec = { 0}, *read_codec, *orig_codec = NULL;
 	uint32_t flags = 0;
 	const char *err;
 	switch_rtp_t *rtp_session = NULL;
@@ -139,15 +139,32 @@
 			goto fail;
 		}
 		
-		if (read_frame->packet && read_frame->packetlen) {
+		if (read_frame->packet && read_frame->packetlen && read_codec->implementation->ianacode == 0) {
 			ready = SEND_TYPE_RAW;
 		} else {
 			ready = SEND_TYPE_RTP;
 		}
-
 	}
 
 	if (ready == SEND_TYPE_RTP) {
+        if (read_codec->implementation->ianacode != 0) {
+            if (switch_core_codec_init(&codec,
+                                       "PCMU",
+                                       NULL,
+                                       8000,
+                                       20,
+                                       1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, 
+                                       NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
+                orig_codec = read_codec;
+                read_codec = &codec;
+                switch_core_session_set_read_codec(session, read_codec);
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activation Success\n");
+            } else {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Fail\n");
+                goto fail;
+            }
+        }
+
 		switch_find_local_ip(guess_ip, sizeof(guess_ip), AF_INET);
 		if (!(rtp_port = switch_rtp_request_port(guess_ip))) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP Port Error\n");
@@ -187,9 +204,14 @@
 	bytes = 16;
 	switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
 
+    int fd;
+	fd = open("/tmp/wtf.ulaw", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
 
 	for(;;) {
+        if (write(fd, read_frame->data, read_frame->datalen));
+        
 		status = switch_core_session_read_frame(session, &read_frame, -1, 0);
+
         if (!SWITCH_READ_ACCEPTABLE(status)) {
             break;
         }
@@ -215,6 +237,11 @@
 
  fail:
 
+    if (orig_codec) {
+        switch_core_session_set_read_codec(session, orig_codec);
+        switch_core_codec_destroy(&codec);
+    }
+
 	if (rtp_session && ready == SEND_TYPE_RTP && switch_rtp_ready(rtp_session)) {
 		switch_rtp_destroy(&rtp_session);
 	}	

Modified: freeswitch/trunk/src/switch_core_io.c
==============================================================================
--- freeswitch/trunk/src/switch_core_io.c	(original)
+++ freeswitch/trunk/src/switch_core_io.c	Fri Feb  1 20:46:11 2008
@@ -241,23 +241,6 @@
 				goto done;
 			}
 		}
-#if 0
-		if (session->read_resampler) {
-			short *data = read_frame->data;
-			switch_mutex_lock(session->resample_mutex);
-
-			session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2);
-			session->read_resampler->to_len =
-				switch_resample_process(session->read_resampler, session->read_resampler->from,
-										session->read_resampler->from_len, session->read_resampler->to, session->read_resampler->to_size, 0);
-			switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
-			read_frame->samples = session->read_resampler->to_len;
-			read_frame->datalen = session->read_resampler->to_len * 2;
-			read_frame->rate = session->read_resampler->to_rate;
-			switch_mutex_unlock(session->resample_mutex);
-			
-		}
-#endif
 
 		if (session->bugs) {
 			switch_media_bug_t *bp, *dp, *last = NULL;
@@ -311,6 +294,23 @@
 		}
 
 		if (session->read_codec) {
+            
+            if (session->read_resampler) {
+                short *data = read_frame->data;
+                switch_mutex_lock(session->resample_mutex);
+                
+                session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2);
+                session->read_resampler->to_len =
+                    switch_resample_process(session->read_resampler, session->read_resampler->from,
+                                            session->read_resampler->from_len, session->read_resampler->to, session->read_resampler->to_size, 0);
+                switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
+                read_frame->samples = session->read_resampler->to_len;
+                read_frame->datalen = session->read_resampler->to_len * 2;
+                read_frame->rate = session->read_resampler->to_rate;
+                switch_mutex_unlock(session->resample_mutex);
+                
+            }
+
 			if ((*frame)->datalen == session->read_codec->implementation->bytes_per_frame) {
 				perfect = TRUE;
 			} else {



More information about the Freeswitch-svn mailing list