[Freeswitch-branches] [commit] r5441 - in freeswitch/branches/greenlizard: scripts src/mod/endpoints/mod_portaudio src/mod/languages/mod_python src/mod/languages/mod_spidermonkey_core_db src/mod/languages/mod_spidermonkey_odbc

Freeswitch SVN greenlizard at freeswitch.org
Fri Jun 22 14:46:26 EDT 2007


Author: greenlizard
Date: Fri Jun 22 14:46:25 2007
New Revision: 5441

Modified:
   freeswitch/branches/greenlizard/scripts/api.js
   freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/mod_portaudio.c
   freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/pablio.c
   freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/pablio.h
   freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i
   freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c
   freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c

Log:
merge trunk 5430 to 5439

Modified: freeswitch/branches/greenlizard/scripts/api.js
==============================================================================
--- freeswitch/branches/greenlizard/scripts/api.js	(original)
+++ freeswitch/branches/greenlizard/scripts/api.js	Fri Jun 22 14:46:25 2007
@@ -53,10 +53,12 @@
 request.write("</form><hr noshade size=1><br>");
 
 if ((command = request.getHeader("command"))) {
-	cmd_list = command.split(" ", 2);
+	cmd_list = command.split(" ");
+    cmd = cmd_list.shift();
+    args = cmd_list.join(" ");
 
-	if ((reply = apiExecute(cmd_list[0], cmd_list[1]))) {
-		request.write("<B>Command Result</b><br><pre>" + reply + "\n</pre>");
+	if ((reply = apiExecute(cmd, args))) {
+		request.write("<br><B>Command Result</b><br><pre>" + reply + "\n</pre>");
 	}
 }
 

Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/mod_portaudio.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/mod_portaudio.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/mod_portaudio.c	Fri Jun 22 14:46:25 2007
@@ -29,7 +29,7 @@
  * mod_portaudio.c -- PortAudio Endpoint Module
  *
  */
-#include <switch.h>
+#include "switch.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -47,8 +47,7 @@
 static switch_endpoint_interface_t *channel_endpoint_interface;
 
 #define SAMPLE_TYPE  paInt16
-//#define SAMPLE_TYPE  paFloat32
-typedef short SAMPLE;
+typedef int16_t SAMPLE;
 
 typedef switch_status_t (*pa_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
 
@@ -86,7 +85,6 @@
 	switch_frame_t hold_frame;
 	unsigned char holdbuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
 	switch_codec_t write_codec;
-	switch_timer_t timer;
 	struct private_object *next;
 };
 
@@ -268,7 +266,7 @@
 						if (olen == 0) {
 							break;
 						}
-						WriteAudioStream(globals.ring_stream, abuf, (long) olen);
+						WriteAudioStream(globals.ring_stream, abuf, (long) olen, &globals.timer);
 					}
 				}
 			}
@@ -282,8 +280,6 @@
 	if (ring_file) {
 		deactivate_ring_device();
 		switch_core_file_close(&fh);
-		switch_core_codec_destroy(&tech_pvt->write_codec);
-		switch_core_timer_destroy(&tech_pvt->timer);
 	}
 
 	if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
@@ -566,30 +562,13 @@
 	if (!is_master(tech_pvt)) {
 		if (tech_pvt->hold_file) {
 			if (!tech_pvt->hfh) {
-				int codec_ms = tech_pvt->codec_ms ? tech_pvt->codec_ms : globals.codec_ms;
 				int sample_rate = tech_pvt->sample_rate ? tech_pvt->sample_rate : globals.sample_rate;
-
-				if (switch_core_codec_init(&tech_pvt->write_codec,
-										   "L16",
-										   NULL,
-										   sample_rate,
-										   codec_ms,
-										   1,
-										   SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
-										   NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
-					switch_core_codec_destroy(&globals.read_codec);
-					tech_pvt->hold_file = NULL;
-					goto cng;
-				}
-
 				if (switch_core_file_open(&tech_pvt->fh,
 										  tech_pvt->hold_file,
 										  globals.read_codec.implementation->number_of_channels,
 										  globals.read_codec.implementation->samples_per_second,
 										  SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
 										  switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
-					switch_core_codec_destroy(&tech_pvt->write_codec);
 					tech_pvt->hold_file = NULL;
 					goto cng;
 				}
@@ -598,7 +577,7 @@
 				tech_pvt->hold_frame.data = tech_pvt->holdbuf;
 				tech_pvt->hold_frame.buflen = sizeof(tech_pvt->holdbuf);
 				tech_pvt->hold_frame.rate = sample_rate;
-				tech_pvt->hold_frame.codec = &tech_pvt->write_codec;
+				tech_pvt->hold_frame.codec = &globals.write_codec;
 			}
 
 			goto hold;
@@ -612,9 +591,8 @@
 
 		{
 			switch_size_t olen = globals.read_codec.implementation->samples_per_frame;
-			if (switch_core_timer_next(&tech_pvt->timer) != SWITCH_STATUS_SUCCESS) {
+			if (switch_core_timer_next(&globals.timer) != SWITCH_STATUS_SUCCESS) {
 				switch_core_file_close(&tech_pvt->fh);
-				switch_core_codec_destroy(&tech_pvt->write_codec);
 				goto cng;
 			}
 			switch_core_file_read(tech_pvt->hfh, tech_pvt->hold_frame.data, &olen);
@@ -628,7 +606,7 @@
 
 			tech_pvt->hold_frame.datalen = (uint32_t) (olen * sizeof(int16_t));
 			tech_pvt->hold_frame.samples = (uint32_t) olen;
-			tech_pvt->hold_frame.timestamp = tech_pvt->timer.samplecount;
+			tech_pvt->hold_frame.timestamp = globals.timer.samplecount;
 			*frame = &tech_pvt->hold_frame;
 
 		}
@@ -638,7 +616,12 @@
 
 	switch_mutex_lock(globals.device_lock);
 
-	if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data, globals.read_codec.implementation->samples_per_frame)) != 0) {
+	if ((samples = ReadAudioStream(globals.audio_stream, globals.read_frame.data, 
+								   globals.read_codec.implementation->samples_per_frame, 
+								   &globals.timer)) == 0) {
+
+		goto cng;
+	} else {
 		globals.read_frame.datalen = samples * 2;
 		globals.read_frame.samples = samples;
 
@@ -682,7 +665,8 @@
 
 	if (globals.audio_stream) {
 		if (switch_test_flag((&globals), GFLAG_EAR)) {
-			WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)));
+			WriteAudioStream(globals.audio_stream, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)),
+							 &globals.timer);
 		}
 		status = SWITCH_STATUS_SUCCESS;
 	}
@@ -986,6 +970,7 @@
 		switch_core_codec_destroy(&globals.write_codec);
 	}
 
+	switch_core_timer_destroy(&globals.timer);
 	Pa_Terminate();
 
 	return SWITCH_STATUS_SUCCESS;
@@ -1248,8 +1233,6 @@
 
 
 
-
-
 		globals.read_frame.rate = sample_rate;
 		globals.read_frame.codec = &globals.read_codec;
 
@@ -1268,7 +1251,8 @@
 		outputParameters.sampleFormat = SAMPLE_TYPE;
 		outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
 		outputParameters.hostApiSpecificStreamInfo = NULL;
-		err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff);
+		err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff, 
+							  globals.read_codec.implementation->samples_per_frame);
 		/* UNLOCKED ************************************************************************************************* */
 		switch_mutex_unlock(globals.device_lock);
 
@@ -1292,7 +1276,6 @@
 
 static switch_status_t engage_ring_device(int sample_rate, int channels)
 {
-	//int codec_ms = 20;
 	PaStreamParameters outputParameters;
 	PaError err;
 
@@ -1308,7 +1291,8 @@
 		outputParameters.sampleFormat = SAMPLE_TYPE;
 		outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency;
 		outputParameters.hostApiSpecificStreamInfo = NULL;
-		err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff);
+		err = OpenAudioStream(&globals.ring_stream, NULL, &outputParameters, sample_rate, paClipOff,
+							  globals.read_codec.implementation->samples_per_frame);
 		/* UNLOCKED ************************************************************************************************* */
 		switch_mutex_unlock(globals.device_lock);
 
@@ -1405,7 +1389,6 @@
 
 	if (tech_pvt) {
 		switch_channel_hangup(switch_core_session_get_channel(tech_pvt->session), SWITCH_CAUSE_NORMAL_CLEARING);
-		//switch_set_flag_locked(tech_pvt, TFLAG_HUP);
 		stream->write_function(stream, "OK\n");
 	} else {
 		stream->write_function(stream, "NO SUCH CALL\n");

Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/pablio.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/pablio.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/pablio.c	Fri Jun 22 14:46:25 2007
@@ -40,6 +40,7 @@
  * license above.
  */
 
+#include <switch.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
@@ -49,11 +50,6 @@
 #include <string.h>
 #include <time.h>
 
-/************************************************************************/
-/******** Constants *****************************************************/
-/************************************************************************/
-
-#define FRAMES_PER_BUFFER    (256)
 
 /************************************************************************/
 /******** Prototypes ****************************************************/
@@ -69,17 +65,20 @@
 /************************************************************************/
 
 /* Called from PortAudio.
- * Read and write data only if there is room in FIFOs.
+ * Read and write data 
  */
 static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
 							  unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
 {
 	PABLIO_Stream *data = (PABLIO_Stream *) userData;
 	long numBytes = data->bytesPerFrame * framesPerBuffer;
-
+	
 	/* This may get called with NULL inputBuffer during initial setup. */
 	if (inputBuffer != NULL) {
-		PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes);
+		if (PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes) != numBytes) {
+			PaUtil_FlushRingBuffer(&data->inFIFO);
+			PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes);
+		}
 	}
 	if (outputBuffer != NULL) {
 		int i;
@@ -117,17 +116,24 @@
  * Write data to ring buffer.
  * Will not return until all the data has been written.
  */
-long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
+long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer)
 {
 	long bytesWritten;
 	char *p = (char *) data;
 	long numBytes = aStream->bytesPerFrame * numFrames;
+
 	while (numBytes > 0) {
 		bytesWritten = PaUtil_WriteRingBuffer(&aStream->outFIFO, p, numBytes);
 		numBytes -= bytesWritten;
 		p += bytesWritten;
-		if (numBytes > 0)
-			Pa_Sleep(10);
+		if (numBytes > 0) {
+			if (switch_core_timer_check(timer) == SWITCH_STATUS_SUCCESS) {
+				PaUtil_FlushRingBuffer(&aStream->outFIFO);
+				printf("ASS\n");
+				return 0;
+			}
+			switch_yield(1000);
+		}
 	}
 	return numFrames;
 }
@@ -136,18 +142,22 @@
  * Read data from ring buffer.
  * Will not return until all the data has been read.
  */
-long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
+long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer)
 {
 	long bytesRead;
 	char *p = (char *) data;
 	long numBytes = aStream->bytesPerFrame * numFrames;
-
+	
 	while (numBytes > 0) {
 		bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, numBytes);
 		numBytes -= bytesRead;
-		p += bytesRead;
-		if (numBytes > 0)
-			Pa_Sleep(10);
+		if (numBytes > 0) {
+			if (switch_core_timer_check(timer) == SWITCH_STATUS_SUCCESS) {
+				PaUtil_FlushRingBuffer(&aStream->inFIFO);
+				return 0;
+			}
+			switch_yield(1000);
+		}
 	}
 	return numFrames;
 }
@@ -172,12 +182,12 @@
 	return bytesFull / aStream->bytesPerFrame;
 }
 
-/************************************************************/
+/***********************************************************/
 static unsigned long RoundUpToNextPowerOf2(unsigned long n)
 {
 	long numBits = 0;
 	if (((n - 1) & n) == 0)
-		return n;				/* Already Power of two. */
+		return n;				
 	while (n > 0) {
 		n = n >> 1;
 		numBits++;
@@ -185,20 +195,25 @@
 	return (1 << numBits);
 }
 
+
+
 /************************************************************
  * Opens a PortAudio stream with default characteristics.
  * Allocates PABLIO_Stream structure.
  *
  */
 PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
-						const PaStreamParameters * inputParameters, const PaStreamParameters * outputParameters, double sampleRate,
-						PaStreamFlags streamFlags)
+						const PaStreamParameters *inputParameters,
+						const PaStreamParameters *outputParameters,
+						double sampleRate,
+						PaStreamFlags streamFlags,
+						long samples_per_frame)
 {
-	long bytesPerSample;
+	long bytesPerSample = 2;
 	PaError err;
 	PABLIO_Stream *aStream;
 	long numFrames;
-	long numBytes;
+	//long numBytes;
 	int channels = 1;
 
 	/* Allocate PABLIO_Stream structure for caller. */
@@ -218,12 +233,8 @@
 		channels = outputParameters->channelCount;
 	}
 
-	numFrames = 4 * FRAMES_PER_BUFFER;
-	numFrames = RoundUpToNextPowerOf2(numFrames);
-
-	bytesPerSample = 2;
-	aStream->samplesPerFrame = channels;
-	aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;
+	numFrames = RoundUpToNextPowerOf2(samples_per_frame * 5);
+	aStream->bytesPerFrame = bytesPerSample;
 
 	/* Initialize Ring Buffers */
 
@@ -240,13 +251,14 @@
 	}
 
 	/* Make Write FIFO appear full initially. */
-	numBytes = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
-	PaUtil_AdvanceRingBufferWriteIndex(&aStream->outFIFO, numBytes);
+	//numBytes = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
+	//PaUtil_AdvanceRingBufferWriteIndex(&aStream->outFIFO, numBytes);
 
 
 	/* Open a PortAudio stream that we will use to communicate with the underlying
 	 * audio drivers. */
-	err = Pa_OpenStream(&aStream->stream, inputParameters, outputParameters, sampleRate, FRAMES_PER_BUFFER, streamFlags, blockingIOCallback, aStream);
+	err = Pa_OpenStream(&aStream->stream, inputParameters, outputParameters, sampleRate, samples_per_frame, streamFlags, blockingIOCallback, aStream);
+
 	if (err != paNoError)
 		goto error;
 

Modified: freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/pablio.h
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/pablio.h	(original)
+++ freeswitch/branches/greenlizard/src/mod/endpoints/mod_portaudio/pablio.h	Fri Jun 22 14:46:25 2007
@@ -61,7 +61,6 @@
 		PaUtilRingBuffer outFIFO;
 		PaStream *stream;
 		int bytesPerFrame;
-		int samplesPerFrame;
 	} PABLIO_Stream;
 
 /* Values for flags for OpenAudioStream(). */
@@ -75,13 +74,13 @@
  * Write data to ring buffer.
  * Will not return until all the data has been written.
  */
-	long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
+	long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer);
 
 /************************************************************
  * Read data from ring buffer.
  * Will not return until all the data has been read.
  */
-	long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
+	long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, switch_timer_t *timer);
 
 /************************************************************
  * Return the number of frames that could be written to the stream without
@@ -105,7 +104,7 @@
  */
 	PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
 							const PaStreamParameters * inputParameters,
-							const PaStreamParameters * outputParameters, double sampleRate, PaStreamCallbackFlags statusFlags);
+							const PaStreamParameters * outputParameters, double sampleRate, PaStreamCallbackFlags statusFlags, long samples_per_frame);
 
 	PaError CloseAudioStream(PABLIO_Stream * aStream);
 

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i	Fri Jun 22 14:46:25 2007
@@ -9,14 +9,12 @@
 %cstring_bounded_mutable(char *dtmf_buf, 128);
 %cstring_bounded_mutable(char *terminator, 8);
 
-
 /** insert the following includes into generated code so it compiles */
 %{
 #include "switch_cpp.h"
 #include "freeswitch_python.h"
 %}
 
-
 %ignore SwitchToMempool;   
 
 /**

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey_core_db/mod_spidermonkey_core_db.c	Fri Jun 22 14:46:25 2007
@@ -242,6 +242,16 @@
 };
 
 
+static JSBool db_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval *vp)
+{
+	char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
+
+	if (strcmp(name, "_dB_RoW_DaTa_")) {
+		*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
+	}
+	return JS_TRUE;
+}
+
 static JSBool db_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
 {
 	JSBool res = JS_TRUE;
@@ -268,7 +278,7 @@
 
 JSClass db_class = {
 	modname, JSCLASS_HAS_PRIVATE,
-	JS_PropertyStub, JS_PropertyStub, db_getProperty, DEFAULT_SET_PROPERTY,
+	JS_PropertyStub, JS_PropertyStub, db_getProperty, db_setProperty,
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, db_destroy, NULL, NULL, NULL,
 	db_construct
 };

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_spidermonkey_odbc/mod_spidermonkey_odbc.c	Fri Jun 22 14:46:25 2007
@@ -424,21 +424,39 @@
 
 
 static JSPropertySpec odbc_props[] = {
-//  {"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
+	{"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT}, 
 	{0}
 };
 
+static JSBool odbc_setProperty(JSContext * cx, JSObject * obj, jsval id, jsval *vp)
+{
+	char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
+
+	if (strcmp(name, "_oDbC_dB_RoW_DaTa_")) {
+		*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
+	}
+	return JS_TRUE;
+}
 
-static JSBool odbc_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
+static JSBool odbc_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval *vp)
 {
-	JSBool res = JS_TRUE;
+	int param;
+	char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
+	
+	/* numbers are our props anything else is a method */
+	if (name[0] >= 48 && name[0] <= 57) {
+		param = atoi(name);
+	} else {
+		return JS_TRUE;
+	}
 
-	return res;
+	*vp = BOOLEAN_TO_JSVAL(JS_FALSE);
+	return JS_TRUE;
 }
 
 JSClass odbc_class = {
 	modname, JSCLASS_HAS_PRIVATE,
-	JS_PropertyStub, JS_PropertyStub, odbc_getProperty, DEFAULT_SET_PROPERTY,
+	JS_PropertyStub, JS_PropertyStub, odbc_getProperty, odbc_setProperty,
 	JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, odbc_destroy, NULL, NULL, NULL,
 	odbc_construct
 };



More information about the Freeswitch-branches mailing list