2006-09-22 19:50:54 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
2014-02-05 21:02:28 +00:00
|
|
|
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
2006-09-22 19:50:54 +00:00
|
|
|
*
|
|
|
|
* 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
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-09-22 19:50:54 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2009-02-04 21:20:54 +00:00
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
2006-09-22 19:50:54 +00:00
|
|
|
*
|
|
|
|
*
|
2007-12-12 21:30:55 +00:00
|
|
|
* mod_native_file.c -- Native Files
|
2006-09-22 19:50:54 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <switch.h>
|
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_native_file_load);
|
|
|
|
SWITCH_MODULE_DEFINITION(mod_native_file, mod_native_file_load, NULL, NULL);
|
2006-09-22 19:50:54 +00:00
|
|
|
|
|
|
|
struct native_file_context {
|
|
|
|
switch_file_t *fd;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct native_file_context native_file_context;
|
|
|
|
|
2007-11-01 11:28:26 +00:00
|
|
|
static switch_status_t native_file_file_open(switch_file_handle_t *handle, const char *path)
|
2006-09-22 19:50:54 +00:00
|
|
|
{
|
|
|
|
native_file_context *context;
|
|
|
|
char *ext;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
if ((ext = strrchr(path, '.')) == 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Format\n");
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
ext++;
|
|
|
|
|
|
|
|
if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) {
|
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
2009-11-17 21:40:09 +00:00
|
|
|
flags |= SWITCH_FOPEN_WRITE | SWITCH_FOPEN_CREATE;
|
2010-10-27 00:34:47 +00:00
|
|
|
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND) || switch_test_flag(handle, SWITCH_FILE_WRITE_OVER)) {
|
2009-11-17 21:40:09 +00:00
|
|
|
flags |= SWITCH_FOPEN_READ;
|
|
|
|
} else {
|
|
|
|
flags |= SWITCH_FOPEN_TRUNCATE;
|
|
|
|
}
|
|
|
|
|
2006-09-22 19:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) {
|
|
|
|
flags |= SWITCH_FOPEN_READ;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
if (switch_file_open(&context->fd, path, flags, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, handle->memory_pool) != SWITCH_STATUS_SUCCESS) {
|
2006-09-22 19:50:54 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
2009-11-17 21:40:09 +00:00
|
|
|
if (switch_test_flag(handle, SWITCH_FILE_WRITE_APPEND)) {
|
|
|
|
int64_t samples = 0;
|
|
|
|
switch_file_seek(context->fd, SEEK_END, &samples);
|
|
|
|
handle->pos = samples;
|
|
|
|
}
|
|
|
|
|
2006-09-22 19:50:54 +00:00
|
|
|
handle->samples = 0;
|
|
|
|
handle->samplerate = 8000;
|
2014-09-10 18:09:32 +00:00
|
|
|
|
|
|
|
if (ext) {
|
|
|
|
if (!strcasecmp(ext, "G722")) {
|
|
|
|
handle->samplerate = 16000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-22 19:50:54 +00:00
|
|
|
handle->channels = 1;
|
|
|
|
handle->format = 0;
|
|
|
|
handle->sections = 0;
|
Ringback (sponsored by Front Logic)
This addition lets you set artifical ringback on a channel
that is waiting for an originated call to be answered.
the syntax is
<action application="set" data="ringback=[data]"/>
where data is either the full path to an audio file
or a teletone generation script..
syntax of teletone scripts
LEGEND:
0-9,a-d,*,# (standard dtmf tones)
variables: c,r,d,v,>,<,+,w,l,L,%
c (channels) - Sets the number of channels.
r (rate) - Sets the sample rate.
d (duration) - Sets the default tone duration.
v (volume) - Sets the default volume.
> (decrease vol) - factor to decrease volume by per frame (0 for even decrease across duration).
< (increase vol) - factor to increase volume by per frame (0 for even increase across duration).
+ (step) - factor to step by used by < and >.
w (wait) - default silence after each tone.
l (loops) - number of times to repeat each tone in the script.
L (LOOPS) - number of times to repeat the the whole script.
% (manual tone) - a generic tone specified by a duration, a wait and a list of frequencies.
standard tones can have custom duration per use with the () modifier
7(1000, 500) to generate DTMF 7 for 1 second then pause .5 seconds
EXAMPLES
UK Ring Tone [400+450 hz on for 400ms off for 200ms then 400+450 hz on for 400ms off for 2200ms]
%(400,200,400,450);%(400,2200,400,450)
US Ring Tone [440+480 hz on for 2000ms off for 4000ms]
%(2000,4000,440,480)
ATT BONG [volume level 4000, even decay, step by 2, # key for 60ms with no wait, volume level 2000, 350+440hz {us dialtone} for 940ms
v=4000;>=0;+=2;#(60,0);v=2000;%(940,0,350,440)
SIT Tone 913.8 hz for 274 ms with no wait, 1370.6 hz for 274 ms with no wait, 1776.7 hz for 380ms with no wait
%(274,0,913.8);%(274,0,1370.6);%(380,0,1776.7)
ATTN TONE (phone's off the hook!) 1400+2060+2450+2600 hz for 100ms with 100ms wait
%(100,100,1400,2060,2450,2600)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3408 d0543943-73ff-0310-b7d9-9358b9ac24b2
2006-11-19 01:05:06 +00:00
|
|
|
handle->seekable = 1;
|
2006-09-22 19:50:54 +00:00
|
|
|
handle->speed = 0;
|
2009-07-27 18:54:27 +00:00
|
|
|
handle->pos = 0;
|
2006-09-22 19:50:54 +00:00
|
|
|
handle->private_info = context;
|
2007-03-29 22:31:56 +00:00
|
|
|
handle->flags |= SWITCH_FILE_NATIVE;
|
2006-09-22 19:50:54 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening File [%s] %dhz\n", path, handle->samplerate);
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-11-17 21:40:09 +00:00
|
|
|
static switch_status_t native_file_file_truncate(switch_file_handle_t *handle, int64_t offset)
|
|
|
|
{
|
|
|
|
native_file_context *context = handle->private_info;
|
|
|
|
switch_status_t status;
|
|
|
|
|
|
|
|
if ((status = switch_file_trunc(context->fd, offset)) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
handle->pos = 0;
|
|
|
|
}
|
2010-02-06 03:38:24 +00:00
|
|
|
|
2009-11-17 21:40:09 +00:00
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-09-22 19:50:54 +00:00
|
|
|
static switch_status_t native_file_file_close(switch_file_handle_t *handle)
|
|
|
|
{
|
|
|
|
native_file_context *context = handle->private_info;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-09-22 19:50:54 +00:00
|
|
|
if (context->fd) {
|
|
|
|
switch_file_close(context->fd);
|
|
|
|
context->fd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
static switch_status_t native_file_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
|
2006-09-22 19:50:54 +00:00
|
|
|
{
|
2009-07-27 18:54:27 +00:00
|
|
|
switch_status_t status;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2009-07-27 18:54:27 +00:00
|
|
|
native_file_context *context = handle->private_info;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2009-07-27 18:54:27 +00:00
|
|
|
status = switch_file_seek(context->fd, whence, &samples);
|
|
|
|
if (status == SWITCH_STATUS_SUCCESS) {
|
|
|
|
handle->pos += samples;
|
|
|
|
}
|
2006-09-22 19:50:54 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static switch_status_t native_file_file_read(switch_file_handle_t *handle, void *data, size_t *len)
|
|
|
|
{
|
2009-07-27 18:54:27 +00:00
|
|
|
switch_status_t status;
|
|
|
|
|
2006-09-22 19:50:54 +00:00
|
|
|
native_file_context *context = handle->private_info;
|
|
|
|
|
2009-07-27 18:54:27 +00:00
|
|
|
status = switch_file_read(context->fd, data, len);
|
|
|
|
if (status == SWITCH_STATUS_SUCCESS) {
|
|
|
|
handle->pos += *len;
|
|
|
|
}
|
|
|
|
return status;
|
2006-09-22 19:50:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static switch_status_t native_file_file_write(switch_file_handle_t *handle, void *data, size_t *len)
|
|
|
|
{
|
|
|
|
native_file_context *context = handle->private_info;
|
|
|
|
|
|
|
|
return switch_file_write(context->fd, data, len);
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
static switch_status_t native_file_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
|
2006-09-22 19:50:54 +00:00
|
|
|
{
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
static switch_status_t native_file_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
|
2006-09-22 19:50:54 +00:00
|
|
|
{
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
2008-06-30 17:52:22 +00:00
|
|
|
static char *supported_formats[SWITCH_MAX_CODECS + 1] = { 0 };
|
2006-09-22 19:50:54 +00:00
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_native_file_load)
|
2006-09-22 19:50:54 +00:00
|
|
|
{
|
2007-06-20 07:53:33 +00:00
|
|
|
switch_file_interface_t *file_interface;
|
2006-09-22 19:50:54 +00:00
|
|
|
|
|
|
|
const switch_codec_implementation_t *codecs[SWITCH_MAX_CODECS];
|
2007-09-24 19:34:25 +00:00
|
|
|
uint32_t num_codecs = switch_loadable_module_get_codecs(codecs, sizeof(codecs) / sizeof(codecs[0]));
|
2006-09-22 19:50:54 +00:00
|
|
|
uint32_t x;
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
for (x = 0; x < num_codecs; x++) {
|
2009-09-28 20:36:49 +00:00
|
|
|
supported_formats[x] = switch_core_strdup(pool, codecs[x]->iananame);
|
2006-09-22 19:50:54 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 07:53:33 +00:00
|
|
|
*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 = native_file_file_open;
|
|
|
|
file_interface->file_close = native_file_file_close;
|
2009-11-17 21:40:09 +00:00
|
|
|
file_interface->file_truncate = native_file_file_truncate;
|
2007-06-20 07:53:33 +00:00
|
|
|
file_interface->file_read = native_file_file_read;
|
|
|
|
file_interface->file_write = native_file_file_write;
|
|
|
|
file_interface->file_seek = native_file_file_seek;
|
|
|
|
file_interface->file_set_string = native_file_file_set_string;
|
|
|
|
file_interface->file_get_string = native_file_file_get_string;
|
2006-09-22 19:50:54 +00:00
|
|
|
|
|
|
|
/* indicate that the module should continue to be loaded */
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-11-27 22:30:48 +00:00
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
2008-02-03 22:14:57 +00:00
|
|
|
* indent-tabs-mode:t
|
2006-11-27 22:30:48 +00:00
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
2013-06-25 16:50:17 +00:00
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
|
2006-11-27 22:30:48 +00:00
|
|
|
*/
|