#formats/mod_shout
formats/mod_local_stream
formats/mod_tone_stream
-formats/mod_file_string
#formats/mod_portaudio_stream
#formats/mod_shell_stream
#languages/mod_python
<!--For local streams (play all the files in a directory)-->
<load module="mod_local_stream"/>
<load module="mod_tone_stream"/>
- <load module="mod_file_string"/>
<!-- Timers -->
<!-- <load module="mod_timerfd"/> -->
* Neal Horman <neal at wanlink dot com>
* Bret McDanel <trixter AT 0xdecafbad dot com>
* Luke Dashjr <luke@openmethods.com> (OpenMethods, LLC)
+ * Cesar Cepeda <cesar@auronix.com>
*
* mod_dptools.c -- Raw Audio File Streaming Application Module
*
}
}
+
+
+/* FILE STRING INTERFACE */
+
+/* for apr_pstrcat */
+#define DEFAULT_PREBUFFER_SIZE 1024 * 64
+
+struct file_string_source;
+
+struct file_string_context {
+ char *argv[128];
+ int argc;
+ int index;
+ int samples;
+ switch_file_handle_t fh;
+};
+
+typedef struct file_string_context file_string_context_t;
+
+
+static int next_file(switch_file_handle_t *handle)
+{
+ file_string_context_t *context = handle->private_info;
+ char *file;
+ const char *prefix = handle->prefix;
+
+ top:
+
+ context->index++;
+
+ if (switch_test_flag((&context->fh), SWITCH_FILE_OPEN)) {
+ switch_core_file_close(&context->fh);
+ }
+
+ if (context->index >= context->argc) {
+ return 0;
+ }
+
+
+ if (!prefix) {
+ if (!(prefix = switch_core_get_variable_pdup("sound_prefix", handle->memory_pool))) {
+ prefix = SWITCH_GLOBAL_dirs.sounds_dir;
+ }
+ }
+
+ if (!prefix || switch_is_file_path(context->argv[context->index])) {
+ file = context->argv[context->index];
+ } else {
+ file = switch_core_sprintf(handle->memory_pool, "%s%s%s", prefix, SWITCH_PATH_SEPARATOR, context->argv[context->index]);
+ }
+
+ if (switch_core_file_open(&context->fh,
+ file, handle->channels, handle->samplerate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
+ goto top;
+ }
+
+ handle->samples = context->fh.samples;
+ handle->samplerate = context->fh.samplerate;
+ handle->channels = context->fh.channels;
+ handle->format = context->fh.format;
+ handle->sections = context->fh.sections;
+ handle->seekable = context->fh.seekable;
+ handle->speed = context->fh.speed;
+ handle->interval = context->fh.interval;
+
+ if (context->index == 0) {
+ context->samples = (handle->samplerate / 1000) * 250;
+ }
+
+ return 1;
+}
+
+
+static switch_status_t file_string_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
+{
+ file_string_context_t *context = handle->private_info;
+
+ if (samples == 0 && whence == SEEK_SET) {
+ context->index = -1;
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ if (!handle->seekable) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "File is not seekable\n");
+ return SWITCH_STATUS_NOTIMPL;
+ }
+
+ return switch_core_file_seek(&context->fh, cur_sample, samples, whence);
+}
+
+static switch_status_t file_string_file_open(switch_file_handle_t *handle, const char *path)
+{
+ file_string_context_t *context;
+ char *file_dup;
+
+ if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing!\n");
+ return SWITCH_STATUS_FALSE;
+ }
+
+ context = switch_core_alloc(handle->memory_pool, sizeof(*context));
+
+ file_dup = switch_core_strdup(handle->memory_pool, path);
+ context->argc = switch_separate_string(file_dup, '!', context->argv, (sizeof(context->argv) / sizeof(context->argv[0])));
+ context->index = -1;
+
+ handle->private_info = context;
+
+ return next_file(handle) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
+}
+
+static switch_status_t file_string_file_close(switch_file_handle_t *handle)
+{
+ file_string_context_t *context = handle->private_info;
+
+ switch_core_file_close(&context->fh);
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t file_string_file_read(switch_file_handle_t *handle, void *data, size_t *len)
+{
+ file_string_context_t *context = handle->private_info;
+ switch_status_t status;
+ size_t llen = *len;
+
+ if (context->samples > 0) {
+ if (*len > (size_t) context->samples) {
+ *len = context->samples;
+ }
+
+ context->samples -= *len;
+ switch_generate_sln_silence((int16_t *) data, *len, 400);
+ status = SWITCH_STATUS_SUCCESS;
+ } else {
+ status = switch_core_file_read(&context->fh, data, len);
+ }
+
+ if (status != SWITCH_STATUS_SUCCESS) {
+ if (!next_file(handle)) {
+ return SWITCH_STATUS_FALSE;
+ }
+ *len = llen;
+ status = switch_core_file_read(&context->fh, data, len);
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
+/* Registration */
+
+static char *file_string_supported_formats[SWITCH_MAX_CODECS] = { 0 };
+
+
+/* /FILE STRING INTERFACE */
+
+
+
#define SPEAK_DESC "Speak text to a channel via the tts interface"
#define DISPLACE_DESC "Displace audio from a file to the channels input"
#define SESS_REC_DESC "Starts a background recording of the entire session"
switch_application_interface_t *app_interface;
switch_dialplan_interface_t *dp_interface;
switch_chat_interface_t *chat_interface;
+ switch_file_interface_t *file_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
+ file_string_supported_formats[0] = "file_string";
+
+ file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
+ file_interface->interface_name = modname;
+ file_interface->extens = file_string_supported_formats;
+ file_interface->file_open = file_string_file_open;
+ file_interface->file_close = file_string_file_close;
+ file_interface->file_read = file_string_file_read;
+ file_interface->file_seek = file_string_file_seek;
+
+
error_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
error_endpoint_interface->interface_name = "error";
error_endpoint_interface->io_routines = &error_io_routines;
+++ /dev/null
-BASE=../../../..
-include $(BASE)/build/modmake.rules
+++ /dev/null
-<?xml version="1.0" encoding="Windows-1252"?>\r
-<VisualStudioProject\r
- ProjectType="Visual C++"\r
- Version="9.00"\r
- Name="mod_file_string"\r
- ProjectGUID="{70564D74-199A-4452-9C60-19ED5F242F0D}"\r
- RootNamespace="mod_file_string"\r
- Keyword="Win32Proj"\r
- TargetFrameworkVersion="131072"\r
- >\r
- <Platforms>\r
- <Platform\r
- Name="Win32"\r
- />\r
- <Platform\r
- Name="x64"\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="Debug|x64"\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
- TargetEnvironment="3"\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
- OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"\r
- RandomizedBaseAddress="1"\r
- DataExecutionPrevention="0"\r
- TargetMachine="17"\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
- <Configuration\r
- Name="Release|x64"\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
- TargetEnvironment="3"\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
- OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"\r
- RandomizedBaseAddress="1"\r
- DataExecutionPrevention="0"\r
- TargetMachine="17"\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_file_string.c"\r
- >\r
- </File>\r
- </Files>\r
- <Globals>\r
- </Globals>\r
-</VisualStudioProject>\r
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>\r
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
- <ItemGroup Label="ProjectConfigurations">\r
- <ProjectConfiguration Include="Debug|Win32">\r
- <Configuration>Debug</Configuration>\r
- <Platform>Win32</Platform>\r
- </ProjectConfiguration>\r
- <ProjectConfiguration Include="Debug|x64">\r
- <Configuration>Debug</Configuration>\r
- <Platform>x64</Platform>\r
- </ProjectConfiguration>\r
- <ProjectConfiguration Include="Release|Win32">\r
- <Configuration>Release</Configuration>\r
- <Platform>Win32</Platform>\r
- </ProjectConfiguration>\r
- <ProjectConfiguration Include="Release|x64">\r
- <Configuration>Release</Configuration>\r
- <Platform>x64</Platform>\r
- </ProjectConfiguration>\r
- </ItemGroup>\r
- <PropertyGroup Label="Globals">\r
- <ProjectName>mod_file_string</ProjectName>\r
- <ProjectGuid>{70564D74-199A-4452-9C60-19ED5F242F0D}</ProjectGuid>\r
- <RootNamespace>mod_file_string</RootNamespace>\r
- <Keyword>Win32Proj</Keyword>\r
- </PropertyGroup>\r
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />\r
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">\r
- <ConfigurationType>DynamicLibrary</ConfigurationType>\r
- <CharacterSet>MultiByte</CharacterSet>\r
- </PropertyGroup>\r
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">\r
- <ConfigurationType>DynamicLibrary</ConfigurationType>\r
- <CharacterSet>MultiByte</CharacterSet>\r
- </PropertyGroup>\r
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">\r
- <ConfigurationType>DynamicLibrary</ConfigurationType>\r
- <CharacterSet>MultiByte</CharacterSet>\r
- </PropertyGroup>\r
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">\r
- <ConfigurationType>DynamicLibrary</ConfigurationType>\r
- <CharacterSet>MultiByte</CharacterSet>\r
- </PropertyGroup>\r
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />\r
- <ImportGroup Label="ExtensionSettings">\r
- </ImportGroup>\r
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">\r
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
- <Import Project="..\..\..\..\w32\module_release.props" />\r
- </ImportGroup>\r
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">\r
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
- <Import Project="..\..\..\..\w32\module_debug.props" />\r
- </ImportGroup>\r
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">\r
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
- <Import Project="..\..\..\..\w32\module_release.props" />\r
- </ImportGroup>\r
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">\r
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />\r
- <Import Project="..\..\..\..\w32\module_debug.props" />\r
- </ImportGroup>\r
- <PropertyGroup Label="UserMacros" />\r
- <PropertyGroup>\r
- <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>\r
- </PropertyGroup>\r
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
- <ClCompile>\r
- <PrecompiledHeader>\r
- </PrecompiledHeader>\r
- </ClCompile>\r
- <Link>\r
- <RandomizedBaseAddress>false</RandomizedBaseAddress>\r
- <DataExecutionPrevention>\r
- </DataExecutionPrevention>\r
- </Link>\r
- </ItemDefinitionGroup>\r
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">\r
- <Midl>\r
- <TargetEnvironment>X64</TargetEnvironment>\r
- </Midl>\r
- <ClCompile>\r
- <PrecompiledHeader>\r
- </PrecompiledHeader>\r
- </ClCompile>\r
- <Link>\r
- <RandomizedBaseAddress>false</RandomizedBaseAddress>\r
- <DataExecutionPrevention>\r
- </DataExecutionPrevention>\r
- <TargetMachine>MachineX64</TargetMachine>\r
- </Link>\r
- </ItemDefinitionGroup>\r
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
- <ClCompile>\r
- <PrecompiledHeader>\r
- </PrecompiledHeader>\r
- </ClCompile>\r
- <Link>\r
- <RandomizedBaseAddress>false</RandomizedBaseAddress>\r
- <DataExecutionPrevention>\r
- </DataExecutionPrevention>\r
- </Link>\r
- </ItemDefinitionGroup>\r
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">\r
- <Midl>\r
- <TargetEnvironment>X64</TargetEnvironment>\r
- </Midl>\r
- <ClCompile>\r
- <PrecompiledHeader>\r
- </PrecompiledHeader>\r
- </ClCompile>\r
- <Link>\r
- <RandomizedBaseAddress>false</RandomizedBaseAddress>\r
- <DataExecutionPrevention>\r
- </DataExecutionPrevention>\r
- <TargetMachine>MachineX64</TargetMachine>\r
- </Link>\r
- </ItemDefinitionGroup>\r
- <ItemGroup>\r
- <ClCompile Include="mod_file_string.c" />\r
- </ItemGroup>\r
- <ItemGroup>\r
- <ProjectReference Include="..\..\..\..\w32\Library\FreeSwitchCore.2010.vcxproj">\r
- <Project>{202d7a4e-760d-4d0e-afa1-d7459ced30ff}</Project>\r
- <ReferenceOutputAssembly>false</ReferenceOutputAssembly>\r
- </ProjectReference>\r
- </ItemGroup>\r
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
- <ImportGroup Label="ExtensionTargets">\r
- </ImportGroup>\r
-</Project>
\ No newline at end of file
+++ /dev/null
-/*
- * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
- * Copyright (C) 2005-2011, Anthony Minessale II <anthm@freeswitch.org>
- *
- * 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 <anthm@freeswitch.org>
- * Portions created by the Initial Developer are Copyright (C)
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Anthony Minessale II <anthm@freeswitch.org>
- * Cesar Cepeda <cesar@auronix.com>
- *
- *
- * mod_file_string.c -- Local Streaming Audio
- *
- */
-#include <switch.h>
-/* for apr_pstrcat */
-#define DEFAULT_PREBUFFER_SIZE 1024 * 64
-
-SWITCH_MODULE_LOAD_FUNCTION(mod_file_string_load);
-
-SWITCH_MODULE_DEFINITION(mod_file_string, mod_file_string_load, NULL, NULL);
-
-
-struct file_string_source;
-
-static struct {
- switch_mutex_t *mutex;
- switch_hash_t *source_hash;
-} globals;
-
-struct file_string_context {
- char *argv[128];
- int argc;
- int index;
- int samples;
- switch_file_handle_t fh;
-};
-
-typedef struct file_string_context file_string_context_t;
-
-
-static int next_file(switch_file_handle_t *handle)
-{
- file_string_context_t *context = handle->private_info;
- char *file;
- const char *prefix = handle->prefix;
-
- top:
-
- context->index++;
-
- if (switch_test_flag((&context->fh), SWITCH_FILE_OPEN)) {
- switch_core_file_close(&context->fh);
- }
-
- if (context->index >= context->argc) {
- return 0;
- }
-
-
- if (!prefix) {
- if (!(prefix = switch_core_get_variable_pdup("sound_prefix", handle->memory_pool))) {
- prefix = SWITCH_GLOBAL_dirs.sounds_dir;
- }
- }
-
- if (!prefix || switch_is_file_path(context->argv[context->index])) {
- file = context->argv[context->index];
- } else {
- file = switch_core_sprintf(handle->memory_pool, "%s%s%s", prefix, SWITCH_PATH_SEPARATOR, context->argv[context->index]);
- }
-
- if (switch_core_file_open(&context->fh,
- file, handle->channels, handle->samplerate, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) {
- goto top;
- }
-
- handle->samples = context->fh.samples;
- handle->samplerate = context->fh.samplerate;
- handle->channels = context->fh.channels;
- handle->format = context->fh.format;
- handle->sections = context->fh.sections;
- handle->seekable = context->fh.seekable;
- handle->speed = context->fh.speed;
- handle->interval = context->fh.interval;
-
- if (context->index == 0) {
- context->samples = (handle->samplerate / 1000) * 250;
- }
-
- return 1;
-}
-
-
-static switch_status_t file_string_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
-{
- file_string_context_t *context = handle->private_info;
-
- if (samples == 0 && whence == SEEK_SET) {
- context->index = -1;
- return SWITCH_STATUS_SUCCESS;
- }
-
- if (!handle->seekable) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "File is not seekable\n");
- return SWITCH_STATUS_NOTIMPL;
- }
-
- return switch_core_file_seek(&context->fh, cur_sample, samples, whence);
-}
-
-static switch_status_t file_string_file_open(switch_file_handle_t *handle, const char *path)
-{
- file_string_context_t *context;
- char *file_dup;
-
- if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing!\n");
- return SWITCH_STATUS_FALSE;
- }
-
- context = switch_core_alloc(handle->memory_pool, sizeof(*context));
-
- file_dup = switch_core_strdup(handle->memory_pool, path);
- context->argc = switch_separate_string(file_dup, '!', context->argv, (sizeof(context->argv) / sizeof(context->argv[0])));
- context->index = -1;
-
- handle->private_info = context;
-
- return next_file(handle) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
-}
-
-static switch_status_t file_string_file_close(switch_file_handle_t *handle)
-{
- file_string_context_t *context = handle->private_info;
-
- switch_core_file_close(&context->fh);
-
- return SWITCH_STATUS_SUCCESS;
-}
-
-static switch_status_t file_string_file_read(switch_file_handle_t *handle, void *data, size_t *len)
-{
- file_string_context_t *context = handle->private_info;
- switch_status_t status;
- size_t llen = *len;
-
- if (context->samples > 0) {
- if (*len > (size_t) context->samples) {
- *len = context->samples;
- }
-
- context->samples -= *len;
- switch_generate_sln_silence((int16_t *) data, *len, 400);
- status = SWITCH_STATUS_SUCCESS;
- } else {
- status = switch_core_file_read(&context->fh, data, len);
- }
-
- if (status != SWITCH_STATUS_SUCCESS) {
- if (!next_file(handle)) {
- return SWITCH_STATUS_FALSE;
- }
- *len = llen;
- status = switch_core_file_read(&context->fh, data, len);
- }
-
- return SWITCH_STATUS_SUCCESS;
-}
-
-/* Registration */
-
-static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
-
-SWITCH_MODULE_LOAD_FUNCTION(mod_file_string_load)
-{
- switch_file_interface_t *file_interface;
- supported_formats[0] = "file_string";
-
- *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 = file_string_file_open;
- file_interface->file_close = file_string_file_close;
- file_interface->file_read = file_string_file_read;
- file_interface->file_seek = file_string_file_seek;
-
- memset(&globals, 0, sizeof(globals));
- /* indicate that the module should continue to be loaded */
- 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:
- */
+++ /dev/null
-<?xml version="1.0" encoding="Windows-1252"?>\r
-<VisualStudioProject\r
- ProjectType="Visual C++"\r
- Version="8.00"\r
- Name="mod_file_string"\r
- ProjectGUID="{2CA40887-1622-46A1-A7F9-17FD7E7E545B}"\r
- RootNamespace="mod_file_string"\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_file_string.c"\r
- >\r
- </File>\r
- </Files>\r
- <Globals>\r
- </Globals>\r
-</VisualStudioProject>\r