2006-01-03 22:13:59 +00:00
|
|
|
/*
|
|
|
|
* 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_sndfile.c -- Framework Demo Module
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <switch.h>
|
|
|
|
#include <sndfile.h>
|
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_sndfile_load);
|
2007-09-29 01:06:08 +00:00
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sndfile_shutdown);
|
|
|
|
SWITCH_MODULE_DEFINITION(mod_sndfile, mod_sndfile_load, mod_sndfile_shutdown, NULL);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-02-12 22:42:22 +00:00
|
|
|
static switch_memory_pool_t *module_pool = NULL;
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
switch_hash_t *format_hash;
|
|
|
|
} globals;
|
|
|
|
|
|
|
|
struct format_map {
|
|
|
|
char *ext;
|
|
|
|
char *uext;
|
|
|
|
uint32_t format;
|
|
|
|
};
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
struct sndfile_context {
|
|
|
|
SF_INFO sfinfo;
|
2006-01-20 15:05:05 +00:00
|
|
|
SNDFILE *handle;
|
2006-01-03 22:13:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct sndfile_context sndfile_context;
|
|
|
|
|
2007-11-01 11:28:26 +00:00
|
|
|
static switch_status_t sndfile_file_open(switch_file_handle_t *handle, const char *path)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
|
|
|
sndfile_context *context;
|
|
|
|
int mode = 0;
|
|
|
|
char *ext;
|
2007-02-12 22:42:22 +00:00
|
|
|
struct format_map *map = NULL;
|
2007-12-12 21:30:55 +00:00
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
char *alt_path = NULL, *next, *last, *ldup = NULL;
|
|
|
|
size_t alt_len = 0;
|
2007-02-12 22:42:22 +00:00
|
|
|
|
2006-02-20 04:36:29 +00:00
|
|
|
if ((ext = strrchr(path, '.')) == 0) {
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Format\n");
|
2006-01-20 15:05:05 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
ext++;
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) {
|
|
|
|
mode += SFM_READ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) {
|
|
|
|
mode += SFM_WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mode) {
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Mode!\n");
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
|
|
|
|
2006-02-20 04:36:29 +00:00
|
|
|
if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) {
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_MEMERR;
|
|
|
|
}
|
|
|
|
|
2007-02-12 22:42:22 +00:00
|
|
|
map = switch_core_hash_find(globals.format_hash, ext);
|
|
|
|
|
2006-01-27 01:46:14 +00:00
|
|
|
if (mode & SFM_WRITE) {
|
2007-03-29 22:31:56 +00:00
|
|
|
sf_count_t frames = 0;
|
|
|
|
|
2006-01-27 01:46:14 +00:00
|
|
|
context->sfinfo.channels = handle->channels;
|
|
|
|
context->sfinfo.samplerate = handle->samplerate;
|
|
|
|
if (handle->samplerate == 8000 || handle->samplerate == 16000) {
|
|
|
|
context->sfinfo.format |= SF_FORMAT_PCM_16;
|
|
|
|
} else if (handle->samplerate == 24000) {
|
|
|
|
context->sfinfo.format |= SF_FORMAT_PCM_24;
|
|
|
|
} else if (handle->samplerate == 32000) {
|
|
|
|
context->sfinfo.format |= SF_FORMAT_PCM_32;
|
|
|
|
}
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
sf_command(context->handle, SFC_FILE_TRUNCATE, &frames, sizeof(frames));
|
|
|
|
}
|
|
|
|
|
2007-02-13 03:02:52 +00:00
|
|
|
if (map) {
|
|
|
|
context->sfinfo.format |= map->format;
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2007-02-13 03:02:52 +00:00
|
|
|
if (!strcmp(ext, "r8") || !strcmp(ext, "raw")) {
|
|
|
|
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16;
|
|
|
|
context->sfinfo.channels = 1;
|
|
|
|
context->sfinfo.samplerate = 8000;
|
|
|
|
} else if (!strcmp(ext, "r16")) {
|
|
|
|
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16;
|
|
|
|
context->sfinfo.channels = 1;
|
|
|
|
context->sfinfo.samplerate = 16000;
|
|
|
|
} else if (!strcmp(ext, "r24")) {
|
|
|
|
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_24;
|
|
|
|
context->sfinfo.channels = 1;
|
|
|
|
context->sfinfo.samplerate = 24000;
|
|
|
|
} else if (!strcmp(ext, "r32")) {
|
|
|
|
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_32;
|
|
|
|
context->sfinfo.channels = 1;
|
|
|
|
context->sfinfo.samplerate = 32000;
|
|
|
|
} else if (!strcmp(ext, "gsm")) {
|
|
|
|
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_GSM610;
|
|
|
|
context->sfinfo.channels = 1;
|
|
|
|
context->sfinfo.samplerate = 8000;
|
|
|
|
} else if (!strcmp(ext, "ul")) {
|
|
|
|
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_ULAW;
|
|
|
|
context->sfinfo.channels = 1;
|
|
|
|
context->sfinfo.samplerate = 8000;
|
|
|
|
} else if (!strcmp(ext, "al")) {
|
|
|
|
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_ALAW;
|
|
|
|
context->sfinfo.channels = 1;
|
|
|
|
context->sfinfo.samplerate = 8000;
|
2007-03-29 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((mode & SFM_WRITE) && sf_format_check(&context->sfinfo) == 0) {
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error : file format is invalid (0x%08X).\n", context->sfinfo.format);
|
2006-01-27 01:46:14 +00:00
|
|
|
return SWITCH_STATUS_GENERR;
|
2007-12-12 21:30:55 +00:00
|
|
|
}
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2007-12-12 21:30:55 +00:00
|
|
|
alt_len = strlen(path) + 10;
|
|
|
|
switch_zmalloc(alt_path, alt_len);
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2007-12-12 21:30:55 +00:00
|
|
|
switch_copy_string(alt_path, path, alt_len);
|
2008-05-22 02:16:32 +00:00
|
|
|
if ((last = strrchr(alt_path, '/'))) {
|
2007-12-12 21:30:55 +00:00
|
|
|
next = ++last;
|
|
|
|
ldup = strdup(last);
|
|
|
|
switch_assert(ldup);
|
|
|
|
switch_snprintf(next, alt_len - (last - alt_path), "%d%s%s", handle->samplerate, SWITCH_PATH_SEPARATOR, ldup);
|
|
|
|
if ((context->handle = sf_open(alt_path, mode, &context->sfinfo))) {
|
|
|
|
path = alt_path;
|
|
|
|
}
|
|
|
|
}
|
2008-05-22 02:16:32 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
else if ((last = strrchr(alt_path, '\\'))) {
|
|
|
|
next = ++last;
|
|
|
|
ldup = strdup(last);
|
|
|
|
switch_assert(ldup);
|
|
|
|
switch_snprintf(next, alt_len - (last - alt_path), "%d%s%s", handle->samplerate, SWITCH_PATH_SEPARATOR, ldup);
|
|
|
|
if ((context->handle = sf_open(alt_path, mode, &context->sfinfo))) {
|
|
|
|
path = alt_path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-12 21:30:55 +00:00
|
|
|
if (!context->handle) {
|
|
|
|
if ((context->handle = sf_open(path, mode, &context->sfinfo)) == 0) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening File [%s] [%s]\n", path, sf_strerror(context->handle));
|
|
|
|
status = SWITCH_STATUS_GENERR;
|
|
|
|
goto end;
|
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
2008-05-14 16:01:13 +00:00
|
|
|
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening File [%s] rate %dhz\n", path, context->sfinfo.samplerate);
|
2006-01-20 15:05:05 +00:00
|
|
|
handle->samples = (unsigned int) context->sfinfo.frames;
|
2006-01-03 22:13:59 +00:00
|
|
|
handle->samplerate = context->sfinfo.samplerate;
|
2007-03-29 22:31:56 +00:00
|
|
|
handle->channels = (uint8_t) context->sfinfo.channels;
|
2006-01-03 22:13:59 +00:00
|
|
|
handle->format = context->sfinfo.format;
|
|
|
|
handle->sections = context->sfinfo.sections;
|
|
|
|
handle->seekable = context->sfinfo.seekable;
|
2006-02-28 02:08:42 +00:00
|
|
|
handle->speed = 0;
|
2006-02-26 04:52:34 +00:00
|
|
|
handle->private_info = context;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2008-05-27 04:54:52 +00:00
|
|
|
end:
|
|
|
|
|
2007-12-12 21:30:55 +00:00
|
|
|
switch_safe_free(alt_path);
|
|
|
|
switch_safe_free(ldup);
|
|
|
|
|
|
|
|
return status;
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t sndfile_file_close(switch_file_handle_t *handle)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-02-26 04:52:34 +00:00
|
|
|
sndfile_context *context = handle->private_info;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
sf_close(context->handle);
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
static switch_status_t sndfile_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-02-26 04:52:34 +00:00
|
|
|
sndfile_context *context = handle->private_info;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
if (!handle->seekable) {
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "File is not seekable\n");
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2006-01-20 15:05:05 +00:00
|
|
|
*cur_sample = (unsigned int) sf_seek(context->handle, samples, whence);
|
2006-02-28 02:08:42 +00:00
|
|
|
handle->pos = *cur_sample;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t sndfile_file_read(switch_file_handle_t *handle, void *data, size_t *len)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
|
|
|
size_t inlen = *len;
|
2006-02-26 04:52:34 +00:00
|
|
|
sndfile_context *context = handle->private_info;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2006-01-20 15:05:05 +00:00
|
|
|
if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) {
|
|
|
|
*len = (size_t) sf_read_raw(context->handle, data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_INT)) {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_readf_int(context->handle, (int *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_SHORT)) {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_readf_short(context->handle, (short *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_FLOAT)) {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_readf_float(context->handle, (float *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_DOUBLE)) {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_readf_double(context->handle, (double *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_readf_int(context->handle, (int *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
handle->sample_count += *len;
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t sndfile_file_write(switch_file_handle_t *handle, void *data, size_t *len)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
|
|
|
size_t inlen = *len;
|
2006-02-26 04:52:34 +00:00
|
|
|
sndfile_context *context = handle->private_info;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
|
|
|
if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) {
|
|
|
|
*len = (size_t) sf_write_raw(context->handle, data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_INT)) {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_writef_int(context->handle, (int *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_SHORT)) {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_writef_short(context->handle, (short *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_FLOAT)) {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_writef_float(context->handle, (float *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_DOUBLE)) {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_writef_double(context->handle, (double *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
} else {
|
2006-01-20 15:05:05 +00:00
|
|
|
*len = (size_t) sf_writef_int(context->handle, (int *) data, inlen);
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
handle->sample_count += *len;
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-07-25 22:37:52 +00:00
|
|
|
static switch_status_t sndfile_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
|
|
|
|
{
|
|
|
|
sndfile_context *context = handle->private_info;
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
return sf_set_string(context->handle, (int) col, string) ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
|
2006-07-25 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
static switch_status_t sndfile_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
|
2006-07-25 22:37:52 +00:00
|
|
|
{
|
|
|
|
sndfile_context *context = handle->private_info;
|
|
|
|
const char *s;
|
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
if ((s = sf_get_string(context->handle, (int) col))) {
|
2006-07-25 22:37:52 +00:00
|
|
|
*string = s;
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
static char **supported_formats;
|
|
|
|
|
2006-04-29 23:43:28 +00:00
|
|
|
static switch_status_t setup_formats(void)
|
2006-01-03 22:13:59 +00:00
|
|
|
{
|
2006-01-20 15:05:05 +00:00
|
|
|
SF_FORMAT_INFO info;
|
|
|
|
SF_INFO sfinfo;
|
|
|
|
char buffer[128];
|
|
|
|
int format, major_count, subtype_count, m, s;
|
|
|
|
int len, x, skip;
|
2007-02-12 22:42:22 +00:00
|
|
|
char *extras[] = { "r8", "r16", "r24", "r32", "gsm", "ul", "al", NULL };
|
2006-01-03 22:13:59 +00:00
|
|
|
int exlen = (sizeof(extras) / sizeof(extras[0]));
|
2006-01-20 15:05:05 +00:00
|
|
|
buffer[0] = 0;
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-01-20 15:05:05 +00:00
|
|
|
sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer));
|
|
|
|
if (strlen(buffer) < 1) {
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Line %d: could not retrieve lib version.\n", __LINE__);
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-04-16 06:05:53 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "\nLibSndFile Version : %s Supported Formats\n", buffer);
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "================================================================================\n");
|
2006-01-20 15:05:05 +00:00
|
|
|
sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof(int));
|
|
|
|
sf_command(NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof(int));
|
|
|
|
|
|
|
|
sfinfo.channels = 1;
|
2006-01-03 22:13:59 +00:00
|
|
|
len = ((major_count + (exlen + 2)) * sizeof(char *));
|
2006-07-27 15:45:19 +00:00
|
|
|
supported_formats = switch_core_permanent_alloc(len);
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
len = 0;
|
2006-01-20 15:05:05 +00:00
|
|
|
for (m = 0; m < major_count; m++) {
|
2006-01-03 22:13:59 +00:00
|
|
|
skip = 0;
|
2006-01-20 15:05:05 +00:00
|
|
|
info.format = m;
|
|
|
|
sf_command(NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof(info));
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s (extension \"%s\")\n", info.name, info.extension);
|
2006-01-20 15:05:05 +00:00
|
|
|
for (x = 0; x < len; x++) {
|
2006-01-03 22:13:59 +00:00
|
|
|
if (supported_formats[x] == info.extension) {
|
|
|
|
skip++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!skip) {
|
2007-02-12 22:42:22 +00:00
|
|
|
char *p;
|
|
|
|
struct format_map *map = switch_core_permanent_alloc(sizeof(*map));
|
2007-12-12 22:55:46 +00:00
|
|
|
switch_assert(map);
|
2008-05-27 04:54:52 +00:00
|
|
|
|
2007-02-12 22:42:22 +00:00
|
|
|
map->ext = switch_core_permanent_strdup(info.extension);
|
|
|
|
map->uext = switch_core_permanent_strdup(info.extension);
|
|
|
|
map->format = info.format;
|
2008-05-21 22:40:04 +00:00
|
|
|
if (map->ext) {
|
|
|
|
for (p = map->ext; *p; p++) {
|
|
|
|
*p = (char) tolower(*p);
|
|
|
|
}
|
|
|
|
switch_core_hash_insert(globals.format_hash, map->ext, map);
|
2007-02-12 22:42:22 +00:00
|
|
|
}
|
2008-05-21 22:40:04 +00:00
|
|
|
if (map->uext) {
|
|
|
|
for (p = map->uext; *p; p++) {
|
|
|
|
*p = (char) toupper(*p);
|
|
|
|
}
|
|
|
|
switch_core_hash_insert(globals.format_hash, map->uext, map);
|
2007-02-12 22:42:22 +00:00
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
supported_formats[len++] = (char *) info.extension;
|
|
|
|
}
|
|
|
|
format = info.format;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2007-03-29 22:31:56 +00:00
|
|
|
for (s = 0; s < subtype_count; s++) {
|
2006-01-20 15:05:05 +00:00
|
|
|
info.format = s;
|
|
|
|
sf_command(NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof(info));
|
|
|
|
format = (format & SF_FORMAT_TYPEMASK) | info.format;
|
|
|
|
sfinfo.format = format;
|
2006-04-06 02:55:09 +00:00
|
|
|
/*
|
2007-03-29 22:31:56 +00:00
|
|
|
if (sf_format_check(&sfinfo)) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, " %s\n", info.name);
|
|
|
|
}
|
|
|
|
*/
|
2006-01-03 22:13:59 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-20 15:05:05 +00:00
|
|
|
for (m = 0; m < exlen; m++) {
|
2006-01-03 22:13:59 +00:00
|
|
|
supported_formats[len++] = extras[m];
|
|
|
|
}
|
|
|
|
|
2007-03-30 00:13:31 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_NOTICE, "================================================================================\n");
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-06-13 17:06:10 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_sndfile_load)
|
2006-01-20 15:05:05 +00:00
|
|
|
{
|
2007-06-20 07:53:33 +00:00
|
|
|
switch_file_interface_t *file_interface;
|
2006-01-20 15:05:05 +00:00
|
|
|
|
2007-02-12 22:42:22 +00:00
|
|
|
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
|
|
|
|
return SWITCH_STATUS_TERM;
|
|
|
|
}
|
2006-01-03 22:13:59 +00:00
|
|
|
|
2007-02-12 22:42:22 +00:00
|
|
|
switch_core_hash_init(&globals.format_hash, module_pool);
|
2007-03-29 22:31:56 +00:00
|
|
|
|
2006-01-03 22:13:59 +00:00
|
|
|
if (setup_formats() != SWITCH_STATUS_SUCCESS) {
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* connect my internal structure to the blank pointer passed to me */
|
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 = sndfile_file_open;
|
|
|
|
file_interface->file_close = sndfile_file_close;
|
|
|
|
file_interface->file_read = sndfile_file_read;
|
|
|
|
file_interface->file_write = sndfile_file_write;
|
|
|
|
file_interface->file_seek = sndfile_file_seek;
|
|
|
|
file_interface->file_set_string = sndfile_file_set_string;
|
|
|
|
file_interface->file_get_string = sndfile_file_get_string;
|
2006-01-03 22:13:59 +00:00
|
|
|
|
|
|
|
/* indicate that the module should continue to be loaded */
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2006-11-27 22:30:48 +00:00
|
|
|
|
2007-09-29 01:06:08 +00:00
|
|
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sndfile_shutdown)
|
|
|
|
{
|
|
|
|
switch_core_hash_destroy(&globals.format_hash);
|
|
|
|
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:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
|
|
|
*/
|