SWITCH_DECLARE(void) switch_core_launch_thread(void *(*func)(switch_thread *, void*), void *obj);
SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel);
SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, void *(*func)(switch_thread *, void *), void *obj);
-SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples);
+SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples, switch_memory_pool *pool);
SWITCH_DECLARE(int) switch_core_timer_next(switch_timer *timer);
SWITCH_DECLARE(switch_status) switch_core_timer_destroy(switch_timer *timer);
SWITCH_DECLARE(void) switch_core_thread_session_end(switch_core_thread_session *thread_session);
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_read(switch_core_session *session, switch_waitfor_read_hook waitfor_read);
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_waitfor_write(switch_core_session *session, switch_waitfor_write_hook waitfor_write);
SWITCH_DECLARE(switch_status) switch_core_session_add_event_hook_send_dtmf(switch_core_session *session, switch_send_dtmf_hook send_dtmf);
-SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, switch_codec_flag flags, const switch_codec_settings *codec_settings);
+SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, switch_codec_flag flags, const switch_codec_settings *codec_settings, switch_memory_pool *pool);
SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec,
switch_codec *other_codec,
void *decoded_data,
const switch_codec_interface *codec_interface;
const switch_application_interface *application_interface;
const switch_api_interface *api_interface;
+ const switch_file_interface *file_interface;
};
SWITCH_DECLARE(switch_status) switch_loadable_module_init(void);
SWITCH_DECLARE(int) loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array, int arraylen);
SWITCH_DECLARE(int) loadable_module_get_codecs_sorted(switch_memory_pool *pool, switch_codec_interface **array, int arraylen, char **prefs, int preflen);
SWITCH_DECLARE(switch_status) switch_api_execute(char *cmd, char *arg, char *retbuf, size_t len);
+SWITCH_DECLARE(switch_api_interface *) loadable_module_get_file_interface(char *name);
SWITCH_DECLARE(void) loadable_module_shutdown(void);
#ifdef __cplusplus
struct switch_timer {
int interval;
+ unsigned int flags;
unsigned int samples;
unsigned int samplecount;
struct switch_timer_interface *timer_interface;
struct switch_file_interface {
const char *interface_name;
+ switch_status (*file_open)(switch_file_handle *);
+ switch_status (*file_close)(switch_file_handle *);
+ switch_status (*file_read)(switch_file_handle *, void *data, size_t len);
+ switch_status (*file_write)(switch_file_handle *, void *data, size_t len);
+ switch_status (*file_seek)(switch_file_handle *, unsigned int samples, int whence);
const struct switch_file_interface *next;
const char *extens[];
-
};
struct switch_file_handle {
const struct switch_file_interface *file_interface;
+ unsigned int flags;
switch_file_t *fd;
unsigned int sample_count;
- switch_codec_flag flags;
switch_memory_pool *memory_pool;
void *private;
};
SWITCH_CODEC_FLAG_SILENCE_START = (1 << 2),
SWITCH_CODEC_FLAG_SILENCE_STOP = (1 << 3),
SWITCH_CODEC_FLAG_SILENCE = (1 << 4),
+ SWITCH_CODEC_FLAG_FREE_POOL = (1 << 5),
} switch_codec_flag;
+typedef enum {
+ SWITCH_TIMER_FLAG_FREE_POOL = (1 << 0),
+} switch_timer_flag;
+
typedef enum {
SWITCH_CODEC_TYPE_AUDIO,
SWITCH_CODEC_TYPE_VIDEO,
typedef struct switch_codec_interface switch_codec_interface;
typedef struct switch_application_interface switch_application_interface;
typedef struct switch_api_interface switch_api_interface;
+typedef struct switch_file_interface switch_file_interface;
+typedef struct switch_file_handle switch_file_handle;
typedef struct switch_core_session switch_core_session;
typedef struct switch_loadable_module_interface switch_loadable_module_interface;
typedef struct switch_caller_profile switch_caller_profile;
int rate = atoi(drate);
if (switch_core_codec_init(&tech_pvt->read_codec,
- dname,
- rate,
- globals.codec_ms,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
- dname,
- rate,
- globals.codec_ms,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
int rate = atoi(drate);
- if (switch_core_codec_init(&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init(&tech_pvt->read_codec,
+ dname,
+ rate,
+ globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
} else {
- if (switch_core_codec_init(&tech_pvt->write_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init(&tech_pvt->write_codec,
+ dname,
+ rate,
+ globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
0,
0,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
return SWITCH_STATUS_GENERR;
} else {
dname,
0,
0,
- SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_core_codec_destroy(&tech_pvt->read_codec);
return SWITCH_STATUS_GENERR;
{
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
- switch_channel *channel, *orig_channel;
+ switch_channel *channel;
switch_caller_profile *caller_profile;
unsigned int req = 0, cap = 0;
switch_timer timer;
switch_core_thread_session thread_session;
switch_codec codec;
+ switch_memory_pool *pool = switch_core_session_get_pool(session);
char *codec_name;
int x;
write_frame.data = buf;
write_frame.buflen = sizeof(buf);
- if (switch_file_open(&fd, data, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ if (switch_file_open(&fd, data, SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD, pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE FAILED\n");
switch_channel_hangup(channel);
return;
write_frame.samples = samples;
/* You can use zap instead of soft if you have it loaded */
- if (switch_core_timer_init(&timer, "soft", interval, samples) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_timer_init(&timer, "soft", interval, samples, pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer failed!\n");
switch_channel_hangup(channel);
return;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval);
- if (switch_core_codec_init(&codec, codec_name, 8000, interval, SWITCH_CODEC_FLAG_ENCODE|SWITCH_CODEC_FLAG_DECODE, NULL) == SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init(&codec, codec_name, 8000, interval, SWITCH_CODEC_FLAG_ENCODE|SWITCH_CODEC_FLAG_DECODE, NULL, pool) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
write_frame.codec = &codec;
} else {
assert(channel != NULL);
if (switch_core_codec_init(&tech_pvt->read_codec,
- "L16",
- sample_rate,
- codec_ms,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ "L16",
+ sample_rate,
+ codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
return SWITCH_STATUS_FALSE;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
- "L16",
- sample_rate,
- codec_ms,
- SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ "L16",
+ sample_rate,
+ codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_core_codec_destroy(&tech_pvt->read_codec);
return SWITCH_STATUS_FALSE;
return SWITCH_STATUS_SUCCESS;
}
+switch_status raw_file_open(switch_file_handle *handle)
+{
+ return SWITCH_STATUS_SUCCESS;
+}
+
+switch_status raw_file_close(switch_file_handle *handle)
+{
+ return SWITCH_STATUS_SUCCESS;
+}
+
+switch_status raw_file_seek(switch_file_handle *handle, unsigned int samples, int whence)
+{
+ return SWITCH_STATUS_NOTIMPL;
+}
+
/* Registration */
+static const switch_file_interface raw_file_interface = {
+ /*.interface_name*/ "raw",
+ /*.file_open*/ raw_file_open,
+ /*.file_close*/ raw_file_close,
+ /*.file_read*/ NULL,
+ /*.file_write*/ NULL,
+ /*.file_seek*/ raw_file_seek,
+ /*.next*/ NULL,
+ /*.extens*/ {"raw", "r8k"}
+};
+
+
static const switch_codec_implementation raw_32k_implementation = {
/*.samples_per_second = */ 32000,
/*.bits_per_second = */ 512000,
/*.timer_interface*/ NULL,
/*.dialplan_interface*/ NULL,
/*.codec_interface*/ &raw_codec_interface,
- /*.application_interface*/ NULL
+ /*.application_interface*/ NULL,
+ /*.api_interface*/ NULL,
+ /*.file_interface*/ &raw_file_interface
};
tech_pvt->frame.data = tech_pvt->databuf;
- if (switch_core_codec_init(&tech_pvt->read_codec, "L16", 8000, 30, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init(&tech_pvt->read_codec, "L16", 8000, 30, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
}
- if (switch_core_codec_init(&tech_pvt->write_codec, "L16", 8000, 30, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init(&tech_pvt->write_codec, "L16", 8000, 30, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
{
if ((*new_session = switch_core_session_request(&woomerachan_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
- switch_channel *channel, *orig_channel;
+ switch_channel *channel;
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, switch_codec_flag flags, const switch_codec_settings *codec_settings)
+SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *codec_name, int rate, int ms, switch_codec_flag flags, const switch_codec_settings *codec_settings, switch_memory_pool *pool)
{
const switch_codec_interface *codec_interface;
const switch_codec_implementation *iptr, *implementation = NULL;
codec->codec_interface = codec_interface;
codec->implementation = implementation;
codec->flags = flags;
- if ((status = switch_core_new_memory_pool(&codec->memory_pool)) != SWITCH_STATUS_SUCCESS) {
- return status;
+
+ if (pool) {
+ codec->memory_pool = pool;
+ } else {
+ if ((status = switch_core_new_memory_pool(&codec->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+ return status;
+ }
+ switch_set_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL);
}
implementation->init(codec, flags, codec_settings);
}
codec->implementation->destroy(codec);
- switch_core_destroy_memory_pool(&codec->memory_pool);
+
+ if (switch_test_flag(codec, SWITCH_CODEC_FLAG_FREE_POOL)) {
+ switch_core_destroy_memory_pool(&codec->memory_pool);
+ }
+
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples)
+SWITCH_DECLARE(switch_status) switch_core_timer_init(switch_timer *timer, char *timer_name, int interval, int samples, switch_memory_pool *pool)
{
switch_timer_interface *timer_interface;
switch_status status;
timer->samples = samples;
timer->samplecount = 0;
timer->timer_interface = timer_interface;
- if ((status = switch_core_new_memory_pool(&timer->memory_pool)) != SWITCH_STATUS_SUCCESS) {
- return status;
+
+ if (pool) {
+ timer->memory_pool = pool;
+ } else {
+ if ((status = switch_core_new_memory_pool(&timer->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+ return status;
+ }
+ switch_set_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL);
}
timer->timer_interface->timer_init(timer);
}
timer->timer_interface->timer_destroy(timer);
- switch_core_destroy_memory_pool(&timer->memory_pool);
+
+ if (switch_test_flag(timer, SWITCH_TIMER_FLAG_FREE_POOL)) {
+ switch_core_destroy_memory_pool(&timer->memory_pool);
+ }
+
return SWITCH_STATUS_SUCCESS;
}
switch_hash *timer_hash;
switch_hash *application_hash;
switch_hash *api_hash;
+ switch_hash *file_hash;
switch_memory_pool *pool;
};
switch_core_hash_init(&loadable_modules.timer_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.application_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.api_hash, loadable_modules.pool);
+ switch_core_hash_init(&loadable_modules.file_hash, loadable_modules.pool);
switch_core_hash_init(&loadable_modules.dialplan_hash, loadable_modules.pool);
while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
}
}
+ if (new_module->interface->file_interface) {
+ const switch_file_interface *ptr;
+
+ for(ptr = new_module->interface->file_interface; ptr; ptr = ptr->next) {
+ int i;
+ for (i = 0 ; ptr->extens[i]; i++) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding File Format '%s'\n", ptr->extens[i]);
+ switch_core_hash_insert(loadable_modules.api_hash,
+ (char *) ptr->extens[i],
+ (void *) ptr);
+ }
+ }
+ }
+
}
}
return switch_core_hash_find(loadable_modules.api_hash, name);
}
+SWITCH_DECLARE(switch_api_interface *) loadable_module_get_file_interface(char *name)
+{
+ return switch_core_hash_find(loadable_modules.file_hash, name);
+}
+
SWITCH_DECLARE(int) loadable_module_get_codecs(switch_memory_pool *pool, switch_codec_interface **array, int arraylen)
{
switch_hash_index_t* hi;