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

FreeSWITCH SVN anthm at freeswitch.org
Fri Mar 20 06:58:45 PDT 2009


Author: anthm
Date: Fri Mar 20 08:58:45 2009
New Revision: 12682

Log:
FSCORE-339

Modified:
   freeswitch/trunk/src/include/switch_module_interfaces.h
   freeswitch/trunk/src/switch_core_file.c
   freeswitch/trunk/src/switch_ivr_async.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	Fri Mar 20 08:58:45 2009
@@ -317,7 +317,8 @@
 	uint32_t thresh;
 	uint32_t silence_hits;
 	uint32_t offset_pos;
-	//uint32_t last_pos;
+	switch_size_t samples_in;
+	switch_size_t samples_out;
 	int32_t vol;
 	switch_audio_resampler_t *resampler;
 	switch_buffer_t *buffer;

Modified: freeswitch/trunk/src/switch_core_file.c
==============================================================================
--- freeswitch/trunk/src/switch_core_file.c	(original)
+++ freeswitch/trunk/src/switch_core_file.c	Fri Mar 20 08:58:45 2009
@@ -177,6 +177,7 @@
 				if ((status = fh->file_interface->file_read(fh, fh->pre_buffer_data, &rlen)) != SWITCH_STATUS_SUCCESS || !rlen) {
 					switch_set_flag(fh, SWITCH_FILE_BUFFER_DONE);
 				} else {
+					fh->samples_in += rlen;
 					if (fh->channels > 1) {
 						switch_mux_channels((int16_t *)fh->pre_buffer_data, rlen, fh->channels);
 					}
@@ -202,6 +203,8 @@
 			goto top;
 		}
 
+		fh->samples_in += *len;
+
 		if (fh->channels > 1) {
 			switch_mux_channels((int16_t *)data, *len, fh->channels);
 		}
@@ -317,11 +320,16 @@
 			if ((status = fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen)) != SWITCH_STATUS_SUCCESS) {
 				*len = 0;
 			}
+			fh->samples_out += blen;
 		}
 		
 		return status;
 	} else {
-		return fh->file_interface->file_write(fh, data, len);
+		switch_status_t status;
+		if ((status = fh->file_interface->file_write(fh, data, len)) == SWITCH_STATUS_SUCCESS) {
+			fh->samples_out += *len;
+		}
+		return status;
 	}
 }
 

Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/trunk/src/switch_ivr_async.c	Fri Mar 20 08:58:45 2009
@@ -439,12 +439,23 @@
 	case SWITCH_ABC_TYPE_INIT:
 		break;
 	case SWITCH_ABC_TYPE_CLOSE:
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stop recording file %s\n", rh->file);
-		switch_channel_set_private(channel, rh->file, NULL);
+		{
+			switch_codec_implementation_t read_impl = {0};
+			switch_core_session_get_read_impl(session, &read_impl);
+
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stop recording file %s\n", rh->file);
+			switch_channel_set_private(channel, rh->file, NULL);
+			
+			if (rh->fh) {
+				switch_core_file_close(rh->fh);
+			}
 		
-		if (rh->fh) {
-			switch_core_file_close(rh->fh);
+			if (rh->fh->samples_out < read_impl.samples_per_second * 3) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Discarding short file %s\n", rh->file);
+				switch_file_remove(rh->file, switch_core_session_get_pool(session));
+			}
 		}
+
 		break;
 	case SWITCH_ABC_TYPE_READ_PING:
 		if (rh->fh) {



More information about the Freeswitch-trunk mailing list