]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add mod_tone_stream
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 31 Dec 2007 18:37:10 +0000 (18:37 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 31 Dec 2007 18:37:10 +0000 (18:37 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7039 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/formats/mod_tone_stream/mod_tone_stream.2008.vcproj [new file with mode: 0644]
src/mod/formats/mod_tone_stream/mod_tone_stream.c [new file with mode: 0644]
src/mod/formats/mod_tone_stream/mod_tone_stream.vcproj [new file with mode: 0644]

diff --git a/src/mod/formats/mod_tone_stream/mod_tone_stream.2008.vcproj b/src/mod/formats/mod_tone_stream/mod_tone_stream.2008.vcproj
new file mode 100644 (file)
index 0000000..e70f763
--- /dev/null
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="9.00"\r
+       Name="mod_tone_stream"\r
+       ProjectGUID="{2CA40887-1622-46A1-A7F9-17FD7E7E545B}"\r
+       RootNamespace="mod_tone_stream"\r
+       Keyword="Win32Proj"\r
+       TargetFrameworkVersion="131072"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               UsePrecompiledHeader="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               RandomizedBaseAddress="1"\r
+                               DataExecutionPrevention="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               UsePrecompiledHeader="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               RandomizedBaseAddress="1"\r
+                               DataExecutionPrevention="0"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <File\r
+                       RelativePath=".\mod_tone_stream.c"\r
+                       >\r
+               </File>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/src/mod/formats/mod_tone_stream/mod_tone_stream.c b/src/mod/formats/mod_tone_stream/mod_tone_stream.c
new file mode 100644 (file)
index 0000000..c917d3d
--- /dev/null
@@ -0,0 +1,195 @@
+/* 
+ * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
+ * Copyright (C) 2005/2006, Anthony Minessale II <anthmct@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@yahoo.com>
+ * Portions created by the Initial Developer are Copyright (C)
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * 
+ * Anthony Minessale II <anthmct@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:
+ */
diff --git a/src/mod/formats/mod_tone_stream/mod_tone_stream.vcproj b/src/mod/formats/mod_tone_stream/mod_tone_stream.vcproj
new file mode 100644 (file)
index 0000000..9160951
--- /dev/null
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="mod_tone_stream"\r
+       ProjectGUID="{2CA40887-1622-46A1-A7F9-17FD7E7E545B}"\r
+       RootNamespace="mod_tone_stream"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               UsePrecompiledHeader="0"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       ConfigurationType="2"\r
+                       InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               UsePrecompiledHeader="0"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <File\r
+                       RelativePath=".\mod_tone_stream.c"\r
+                       >\r
+               </File>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r