switch_hash_t *fifo_hash;
switch_mutex_t *mutex;
switch_memory_pool_t *pool;
+ int running;
} globals;
{
fifo_node_t *node;
+ if (!globals.running) {
+ return NULL;
+ }
+
node = switch_core_alloc(globals.pool, sizeof(*node));
node->name = switch_core_strdup(globals.pool, name);
{
switch_event_t *event;
+ if (!globals.running) {
+ return;
+ }
+
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "%s", "park");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", node->name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-state", "%s", node->waiting_count > 0 ? "CS_RING" : "CS_HANGUP");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "unique-id", "%s", node->name);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "answer-state", "%s", node->waiting_count > 0 ? "early" : "terminated");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "astate", "%s", node->waiting_count > 0 ? "early" : "terminated");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-direction", "%s", "inbound");
switch_event_fire(&event);
}
char *to = switch_event_get_header(event, "to");
char *dup_to = NULL, *node_name;
fifo_node_t *node;
+
+ if (!globals.running) {
+ return;
+ }
if (!to || strncasecmp(to, "park+", 5)) {
return;
switch_time_t ts = switch_timestamp_now();
switch_size_t retsize;
-
+ if (!globals.running) {
+ return;
+ }
if (switch_strlen_zero(data)) {
const void *var;
int x = 0, verbose = 0;
+
+ if (!globals.running) {
+ return SWITCH_STATUS_FALSE;
+ }
+
if (!switch_strlen_zero(cmd)) {
data = strdup(cmd);
switch_assert(data);
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_APP(app_interface, "fifo", "Park with FIFO", FIFO_DESC, fifo_function, FIFO_USAGE, SAF_NONE);
SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX);
+ globals.running = 1;
return SWITCH_STATUS_SUCCESS;
}
switch_hash_index_t *hi;
void *val, *pop;
fifo_node_t *node;
+ switch_memory_pool_t *pool = globals.pool;
switch_mutex_lock(globals.mutex);
+
+ globals.running = 0;
/* Cleanup*/
for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
switch_core_hash_destroy(&node->caller_hash);
switch_core_hash_destroy(&node->consumer_hash);
}
- switch_mutex_unlock(globals.mutex);
switch_core_hash_destroy(&globals.fifo_hash);
- switch_core_destroy_memory_pool(&globals.pool);
+ memset(&globals, 0, sizeof(globals));
+ switch_mutex_unlock(globals.mutex);
+
+ switch_core_destroy_memory_pool(&pool);
return SWITCH_STATUS_SUCCESS;
}
typedef struct {
switch_file_handle_t fh;
int mux;
+ int loop;
} displace_helper_t;
-static switch_bool_t displace_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
+static switch_bool_t write_displace_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
{
displace_helper_t *dh = (displace_helper_t *) user_data;
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
}
if (st != SWITCH_STATUS_SUCCESS || len == 0) {
- return SWITCH_FALSE;
+ if (dh->loop) {
+ uint32_t pos = 0;
+ switch_core_file_seek(&dh->fh, &pos, 0, SEEK_SET);
+ } else {
+ return SWITCH_FALSE;
+ }
}
switch_core_media_bug_set_write_replace_frame(bug, rframe);
return SWITCH_TRUE;
}
+
+
+static switch_bool_t read_displace_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
+{
+ displace_helper_t *dh = (displace_helper_t *) user_data;
+ uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
+ switch_frame_t frame = { 0 };
+
+ frame.data = data;
+ frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
+
+ switch (type) {
+ case SWITCH_ABC_TYPE_INIT:
+ break;
+ case SWITCH_ABC_TYPE_CLOSE:
+ if (dh) {
+ switch_core_file_close(&dh->fh);
+ }
+ break;
+ case SWITCH_ABC_TYPE_WRITE_REPLACE:
+ {
+ switch_frame_t *rframe = switch_core_media_bug_get_write_replace_frame(bug);
+ if (dh && !dh->mux) {
+ memset(rframe->data, 255, rframe->datalen);
+ }
+ switch_core_media_bug_set_write_replace_frame(bug, rframe);
+ }
+ break;
+ case SWITCH_ABC_TYPE_READ_REPLACE:
+ if (dh) {
+ switch_frame_t *rframe = NULL;
+ switch_size_t len;
+ switch_status_t st;
+ rframe = switch_core_media_bug_get_read_replace_frame(bug);
+ len = rframe->samples;
+
+ if (dh->mux) {
+ int16_t buf[1024];
+ int16_t *fp = rframe->data;
+ uint32_t x;
+
+ st = switch_core_file_read(&dh->fh, buf, &len);
+
+ for(x = 0; x < (uint32_t) len; x++) {
+ int32_t mixed = fp[x] + buf[x];
+ switch_normalize_to_16bit(mixed);
+ fp[x] = (int16_t) mixed;
+ }
+ } else {
+ st = switch_core_file_read(&dh->fh, rframe->data, &len);
+ rframe->samples = (uint32_t) len;
+ rframe->datalen = rframe->samples * 2;
+ }
+
+ if (st != SWITCH_STATUS_SUCCESS || len == 0) {
+ if (dh->loop) {
+ uint32_t pos = 0;
+ switch_core_file_seek(&dh->fh, &pos, 0, SEEK_SET);
+ } else {
+ return SWITCH_FALSE;
+ }
+ }
+
+ switch_core_media_bug_set_read_replace_frame(bug, rframe);
+ }
+ break;
+ case SWITCH_ABC_TYPE_WRITE:
+ default:
+ break;
+ }
+
+ return SWITCH_TRUE;
+}
+
SWITCH_DECLARE(switch_status_t) switch_ivr_stop_displace_session(switch_core_session_t *session, const char *file)
{
switch_media_bug_t *bug;
}
-SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_t *session, char *file, uint32_t limit, const char *flags)
+SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_t *session, const char *file, uint32_t limit, const char *flags)
{
switch_channel_t *channel;
switch_codec_t *read_codec;
return SWITCH_STATUS_MEMERR;
}
-
-
+
read_codec = switch_core_session_get_read_codec(session);
switch_assert(read_codec != NULL);
dh->fh.channels = read_codec->implementation->number_of_channels;
dh->fh.samplerate = read_codec->implementation->actual_samples_per_second;
-
-
+
if (switch_core_file_open(&dh->fh,
file,
read_codec->implementation->number_of_channels,
dh->mux++;
}
- if ((status = switch_core_media_bug_add(session, displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
+ if (flags && strchr(flags, 'l')) {
+ dh->loop++;
+ }
+
+ if (flags && strchr(flags, 'r')) {
+ status = switch_core_media_bug_add(session, read_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug);
+ } else {
+ status = switch_core_media_bug_add(session, write_displace_callback, dh, to, SMBF_WRITE_REPLACE | SMBF_READ_REPLACE, &bug);
+ }
+
+ if (status != SWITCH_STATUS_SUCCESS) {
switch_core_file_close(&dh->fh);
return status;
}
switch_core_session_t *other_session = NULL;
const char *other_uuid = NULL;
char *app = "playback";
+ char *cause = NULL;
+ char *mypath;
+ char *p;
switch_assert(path);
- if ((session = switch_core_session_locate(uuid))) {
- char *cause = NULL;
- char *mypath;
- char *p;
+ if (!(session = switch_core_session_locate(uuid))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "uuid [%s] does not match an existing session.\n", switch_str_nil(uuid));
+ return SWITCH_STATUS_FALSE;
+ }
- master = session;
+ master = session;
- channel = switch_core_session_get_channel(session);
- switch_assert(channel != NULL);
+ channel = switch_core_session_get_channel(session);
+ switch_assert(channel != NULL);
- if ((switch_channel_test_flag(channel, CF_EVENT_PARSE))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Channel [%s] already broadcasting...broadcast aborted\n",
- switch_channel_get_name(channel));
- switch_core_session_rwunlock(session);
- return SWITCH_STATUS_FALSE;
- }
+ if ((switch_channel_test_flag(channel, CF_EVENT_PARSE))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Channel [%s] already broadcasting...broadcast aborted\n",
+ switch_channel_get_name(channel));
+ switch_core_session_rwunlock(session);
+ return SWITCH_STATUS_FALSE;
+ }
- mypath = strdup(path);
+ mypath = strdup(path);
- if ((nomedia = switch_channel_test_flag(channel, CF_BYPASS_MEDIA))) {
- switch_ivr_media(uuid, SMF_REBRIDGE);
- }
+ if ((nomedia = switch_channel_test_flag(channel, CF_BYPASS_MEDIA))) {
+ switch_ivr_media(uuid, SMF_REBRIDGE);
+ }
- if ((p = strchr(mypath, ':')) && *(p+1) == ':') {
- app = mypath;
- *p++ = '\0';
- *p++ = '\0';
- path = p;
- }
+ if ((p = strchr(mypath, ':')) && *(p+1) == ':') {
+ app = mypath;
+ *p++ = '\0';
+ *p++ = '\0';
+ path = p;
+ }
- if ((cause = strchr(app, '!'))) {
- *cause++ = '\0';
- if (!cause) {
- cause = "normal_clearing";
- }
+ if ((cause = strchr(app, '!'))) {
+ *cause++ = '\0';
+ if (!cause) {
+ cause = "normal_clearing";
}
+ }
- if ((flags & SMF_ECHO_BLEG) && (other_uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE))
- && (other_session = switch_core_session_locate(other_uuid))) {
- if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "%s", app);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event-lock", "%s", "true");
- if ((flags & SMF_LOOP)) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "loops", "%d", -1);
- }
-
- switch_core_session_queue_private_event(other_session, &event);
+ if ((flags & SMF_ECHO_BLEG) && (other_uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))
+ && (other_session = switch_core_session_locate(other_uuid))) {
+ if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "%s", app);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event-lock", "%s", "true");
+ if ((flags & SMF_LOOP)) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "loops", "%d", -1);
}
-
- switch_core_session_rwunlock(other_session);
- master = other_session;
- other_session = NULL;
+
+ switch_core_session_queue_private_event(other_session, &event);
}
+
+ switch_core_session_rwunlock(other_session);
+ master = other_session;
+ other_session = NULL;
+ }
- if ((flags & SMF_ECHO_ALEG)) {
- if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "%s", app);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event-lock", "%s", "true");
- if ((flags & SMF_LOOP)) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "loops", "%d", -1);
- }
- switch_core_session_queue_private_event(session, &event);
+ if ((flags & SMF_ECHO_ALEG)) {
+ if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "%s", app);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", path);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event-lock", "%s", "true");
+ if ((flags & SMF_LOOP)) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "loops", "%d", -1);
}
- master = session;
+ switch_core_session_queue_private_event(session, &event);
}
+ master = session;
+ }
- if (nomedia) {
- if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "nomedia");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "nomedia-uuid", "%s", uuid);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event-lock", "%s", "true");
- switch_core_session_queue_private_event(master, &event);
- }
+ if (nomedia) {
+ if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "nomedia");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "nomedia-uuid", "%s", uuid);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event-lock", "%s", "true");
+ switch_core_session_queue_private_event(master, &event);
}
+ }
- if (cause) {
- if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "hangup");
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", cause);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event-lock", "%s", "true");
- switch_core_session_queue_private_event(session, &event);
- }
+ if (cause) {
+ if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-name", "hangup");
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "execute-app-arg", "%s", cause);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event-lock", "%s", "true");
+ switch_core_session_queue_private_event(session, &event);
}
-
- switch_core_session_rwunlock(session);
- switch_safe_free(mypath);
}
+ switch_core_session_rwunlock(session);
+ switch_safe_free(mypath);
+
+
return SWITCH_STATUS_SUCCESS;