[Freeswitch-svn] [commit] r7039 - freeswitch/trunk/src/mod/formats/mod_tone_stream

Freeswitch SVN anthm at freeswitch.org
Mon Dec 31 13:37:10 EST 2007


Author: anthm
Date: Mon Dec 31 13:37:10 2007
New Revision: 7039

Added:
   freeswitch/trunk/src/mod/formats/mod_tone_stream/
   freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.2008.vcproj
   freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.c
   freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.vcproj

Log:
add mod_tone_stream

Added: freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.2008.vcproj
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.2008.vcproj	Mon Dec 31 13:37:10 2007
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="mod_tone_stream"
+	ProjectGUID="{2CA40887-1622-46A1-A7F9-17FD7E7E545B}"
+	RootNamespace="mod_tone_stream"
+	Keyword="Win32Proj"
+	TargetFrameworkVersion="131072"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			ConfigurationType="2"
+			InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				UsePrecompiledHeader="0"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				RandomizedBaseAddress="1"
+				DataExecutionPrevention="0"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			ConfigurationType="2"
+			InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				UsePrecompiledHeader="0"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				RandomizedBaseAddress="1"
+				DataExecutionPrevention="0"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<File
+			RelativePath=".\mod_tone_stream.c"
+			>
+		</File>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

Added: freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.c	Mon Dec 31 13:37:10 2007
@@ -0,0 +1,195 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct at yahoo.com>
+ *
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ *
+ * The Initial Developer of the Original Code is
+ * Anthony Minessale II <anthmct at yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony Minessale II <anthmct at yahoo.com>
+ *
+ *
+ * mod_tone_stream.c -- Tone Generation Stream
+ *
+ */
+#include <switch.h>
+/* for apr_pstrcat */
+#define DEFAULT_PREBUFFER_SIZE 1024 * 16
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_tone_stream_load);
+SWITCH_MODULE_DEFINITION(mod_tone_stream, mod_tone_stream_load, NULL, NULL);
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_tone_stream_shutdown);
+
+
+static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
+{
+	switch_buffer_t *audio_buffer = ts->user_data;
+	int wrote;
+
+	if (!audio_buffer) {
+		return -1;
+	}
+
+	wrote = teletone_mux_tones(ts, map);
+	switch_buffer_write(audio_buffer, ts->buffer, wrote * 2);
+
+	return 0;
+}
+
+static switch_status_t tone_stream_file_open(switch_file_handle_t *handle, const char *path)
+{
+	switch_buffer_t *audio_buffer = NULL;
+	teletone_generation_session_t ts;
+	char *tonespec;
+	int loops = 0;
+	char *tmp;
+	int fd = -1;
+	char buf[1024] = "";
+	size_t len;
+
+	memset(&ts, 0, sizeof(ts));
+
+	tonespec = switch_core_strdup(handle->memory_pool, path);
+
+	switch_buffer_create_dynamic(&audio_buffer, 1024, 1024, 0);
+	switch_assert(audio_buffer);
+
+	if ((tmp = strstr(tonespec, ";loops="))) {
+		*tmp = '\0';
+		loops = atoi(tmp + 7);
+		switch_buffer_set_loops(audio_buffer, loops);
+	}
+
+	if (!handle->samplerate) {
+		handle->samplerate = 8000;
+	}
+
+	teletone_init_session(&ts, 0, teletone_handler, audio_buffer);
+    ts.rate = handle->samplerate;
+    ts.channels = 1;
+	
+	if (!strncasecmp(tonespec, "path=", 5)) {
+		tmp = tonespec + 5;
+		if ((fd = open(tmp, O_RDONLY)) < 0) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "failed to open [%s]\n", tmp);
+			return SWITCH_STATUS_FALSE;
+		}
+
+		while((len = switch_fd_read_line(fd, buf, sizeof(buf)))) {
+			teletone_run(&ts, buf);
+		}
+		close(fd);
+		fd = -1;
+	} else {
+		teletone_run(&ts, tonespec);
+	}
+
+	teletone_destroy_session(&ts);
+	
+	handle->private_info = audio_buffer;
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t tone_stream_file_close(switch_file_handle_t *handle)
+{
+	switch_buffer_t *audio_buffer = handle->private_info;
+	
+	switch_buffer_destroy(&audio_buffer);
+	
+	return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t tone_stream_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
+{
+	return SWITCH_STATUS_FALSE;
+}
+
+static switch_status_t tone_stream_file_read(switch_file_handle_t *handle, void *data, size_t *len)
+{
+	switch_buffer_t *audio_buffer = handle->private_info;
+	switch_size_t bytes;
+	
+	if ((bytes = (uint32_t) switch_buffer_read_loop(audio_buffer, data, *len * 2)) <= 0) {
+		*len = 0;
+		return SWITCH_STATUS_FALSE;
+	} else {
+		*len = bytes / 2;
+	}
+
+
+    return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t tone_stream_file_write(switch_file_handle_t *handle, void *data, size_t *len)
+{
+	return SWITCH_STATUS_FALSE;
+}
+
+static switch_status_t tone_stream_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
+{
+	return SWITCH_STATUS_FALSE;
+}
+
+static switch_status_t tone_stream_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
+{
+	return SWITCH_STATUS_FALSE;
+}
+
+/* Registration */
+
+static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
+
+SWITCH_MODULE_LOAD_FUNCTION(mod_tone_stream_load)
+{
+	switch_file_interface_t *file_interface;
+	supported_formats[0] = "tone_stream";
+	
+	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
+	file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
+	file_interface->interface_name = modname;
+	file_interface->extens = supported_formats;
+	file_interface->file_open = tone_stream_file_open;
+	file_interface->file_close = tone_stream_file_close;
+	file_interface->file_read = tone_stream_file_read;
+	file_interface->file_write = tone_stream_file_write;
+	file_interface->file_seek = tone_stream_file_seek;
+	file_interface->file_set_string = tone_stream_file_set_string;
+	file_interface->file_get_string = tone_stream_file_get_string;
+
+	/* indicate that the module should continue to be loaded */
+	return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_tone_stream_shutdown)
+{
+	return SWITCH_STATUS_SUCCESS;
+}
+
+/* For Emacs:
+ * Local Variables:
+ * mode:c
+ * indent-tabs-mode:t
+ * tab-width:4
+ * c-basic-offset:4
+ * End:
+ * For VIM:
+ * vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
+ */

Added: freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.vcproj
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/formats/mod_tone_stream/mod_tone_stream.vcproj	Mon Dec 31 13:37:10 2007
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="mod_tone_stream"
+	ProjectGUID="{2CA40887-1622-46A1-A7F9-17FD7E7E545B}"
+	RootNamespace="mod_tone_stream"
+	Keyword="Win32Proj"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			ConfigurationType="2"
+			InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCCLCompilerTool"
+				UsePrecompiledHeader="0"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			ConfigurationType="2"
+			InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
+			CharacterSet="2"
+			>
+			<Tool
+				Name="VCCLCompilerTool"
+				UsePrecompiledHeader="0"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<File
+			RelativePath=".\mod_tone_stream.c"
+			>
+		</File>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>



More information about the Freeswitch-svn mailing list