[Freeswitch-svn] [commit] r2458 - in freeswitch/trunk/src: . mod/codecs/mod_g726

Freeswitch SVN brian at freeswitch.org
Wed Aug 30 15:46:44 EDT 2006


Author: brian
Date: Wed Aug 30 15:46:43 2006
New Revision: 2458

Modified:
   freeswitch/trunk/src/mod/codecs/mod_g726/mod_g726.c
   freeswitch/trunk/src/switch_rtp.c

Log:
wip

Modified: freeswitch/trunk/src/mod/codecs/mod_g726/mod_g726.c
==============================================================================
--- freeswitch/trunk/src/mod/codecs/mod_g726/mod_g726.c	(original)
+++ freeswitch/trunk/src/mod/codecs/mod_g726/mod_g726.c	Wed Aug 30 15:46:43 2006
@@ -80,6 +80,26 @@
 typedef int (*encoder_t)(int, int, g726_state *);
 typedef int (*decoder_t)(int, int, g726_state *);
 
+
+static void print_bits(uint8_t byte)
+{
+	int i;
+
+	for (i=7;i>=0;i--) {
+		//for (i=0;i<=7;i++) {
+		if(byte & (1 << i)) {
+			printf("1");
+		} else {
+			printf("0");
+		}
+	}
+}
+
+
+
+
+
+
 static switch_status_t switch_g726_encode(switch_codec_t *codec, 
 										switch_codec_t *other_codec, 
 										void *decoded_data,
@@ -132,15 +152,29 @@
 
 		for (x = 0; x < loops && new_len < *encoded_data_len; x++) {
 			int edata = encoder(*ddp, AUDIO_ENCODING_LINEAR, context);
+			int bits = handle->bbits + handle->bits_per_frame;
 			
-			
 			handle->ecount++;
 			if (!handle->bbits) {
+				//printf("new byte assign the %d bits\n", handle->bits_per_frame);
 				*handle->ptr = edata;
-			} else if ((handle->bbits + handle->bits_per_frame) <= BITS_IN_A_BYTE) {
-				printf ("WTF %d\n", BITS_IN_A_BYTE - (handle->bits_per_frame * handle->ecount));
-				*handle->ptr += (edata << (BITS_IN_A_BYTE - (handle->bits_per_frame * handle->ecount)));
-				handle->ecount = 0;
+			} else if (bits <= BITS_IN_A_BYTE) {
+				int shift_by = ((handle->bits_per_frame * (handle->ecount)) - handle->bits_per_frame);
+				//printf ("shift by %d and add %d bits\n", shift_by, handle->bits_per_frame);
+				//*handle->ptr <<= shift_by;
+				//*handle->ptr |= edata;
+				if (shift_by);
+
+				//printf("edata\n");
+				//print_bits(edata);
+				//printf("\n");
+
+				*handle->ptr |= (edata << 4);
+
+				//printf("handle\n");
+				//print_bits(*handle->ptr);
+				//printf("\n");				
+
 			} else {
 				int remain, next, rdata, ndata;
 
@@ -155,9 +189,17 @@
 				handle->bbits = 0;
 				handle->ecount = 0;
 			}
-			handle->bits += handle->bits_per_frame;
+			handle->bits = bits;
 			handle->bbits += handle->bits_per_frame;
 
+			if (0) {
+			for(x = 0; x < 5; x++) {
+				print_bits(handle->buf[x]);
+				printf(" ");
+			}
+			printf("\n");
+			}
+
 			if ((handle->bits % BITS_IN_A_BYTE) == 0) {
 				int bytes = handle->bits / BITS_IN_A_BYTE, count;
 				for(count = 0; count < bytes; count++) {
@@ -165,6 +207,7 @@
 				}
 				handle->bits = handle->bbits = 0;
 				handle->ptr = handle->buf;
+				handle->ecount = 0;
 				memset(handle->buf, 0, sizeof(handle->buf));
 			}
 			ddp++;

Modified: freeswitch/trunk/src/switch_rtp.c
==============================================================================
--- freeswitch/trunk/src/switch_rtp.c	(original)
+++ freeswitch/trunk/src/switch_rtp.c	Wed Aug 30 15:46:43 2006
@@ -317,8 +317,7 @@
 	}
 
 	if (rtp_session->sock) {
-		switch_socket_close(rtp_session->sock);
-		rtp_session->sock = NULL;
+		switch_rtp_kill_socket(rtp_session);
 	}
 	
 	if (switch_socket_create(&rtp_session->sock, AF_INET, SOCK_DGRAM, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
@@ -541,8 +540,10 @@
 
 SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session)
 {
+	switch_mutex_lock(rtp_session->flag_mutex);
 	apr_socket_shutdown(rtp_session->sock, APR_SHUTDOWN_READWRITE);
-	switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_IO);
+	switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_IO);
+	switch_mutex_unlock(rtp_session->flag_mutex);
 }
 
 SWITCH_DECLARE(uint8_t) switch_rtp_ready(switch_rtp_t *rtp_session)
@@ -557,8 +558,11 @@
 		return;
 	}
 
+	switch_mutex_lock((*rtp_session)->flag_mutex);
 	switch_rtp_kill_socket(*rtp_session);
 	switch_socket_close((*rtp_session)->sock);
+	(*rtp_session)->sock = NULL;
+	switch_mutex_unlock((*rtp_session)->flag_mutex);
 
 	if (switch_test_flag((*rtp_session), SWITCH_RTP_FLAG_VAD)) {
 		switch_rtp_disable_vad(*rtp_session);



More information about the Freeswitch-svn mailing list