diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.c b/src/mod/applications/mod_spandsp/mod_spandsp.c index 8a382cfcb1..33a06a067a 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp.c @@ -1,4 +1,4 @@ -/* +/* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application * Copyright (C) 2005-2012, Anthony Minessale II * @@ -77,24 +77,24 @@ SWITCH_STANDARD_APP(stop_dtmf_session_function) SWITCH_STANDARD_APP(tdd_encode_function) { - char *text = (char *) data; + char *text = (char *) data; - if (!zstr(text)) { - spandsp_tdd_encode_session(session, text); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Missing text data\n"); - } + if (!zstr(text)) { + spandsp_tdd_encode_session(session, text); + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Missing text data\n"); + } } SWITCH_STANDARD_APP(tdd_send_function) { - char *text = (char *) data; + char *text = (char *) data; - if (!zstr(text)) { - spandsp_tdd_send_session(session, text); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Missing text data\n"); - } + if (!zstr(text)) { + spandsp_tdd_send_session(session, text); + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Missing text data\n"); + } } SWITCH_STANDARD_APP(stop_tdd_encode_function) @@ -107,7 +107,7 @@ SWITCH_STANDARD_APP(stop_tdd_encode_function) SWITCH_STANDARD_APP(tdd_decode_function) { - spandsp_tdd_decode_session(session); + spandsp_tdd_decode_session(session); } SWITCH_STANDARD_APP(stop_tdd_decode_function) @@ -118,17 +118,17 @@ SWITCH_STANDARD_APP(stop_tdd_decode_function) SWITCH_STANDARD_APP(spandsp_fax_detect_session_function) { - int argc = 0; + int argc = 0; char *argv[4] = { 0 }; - char *dupdata; - const char *app = NULL, *arg = NULL; - int timeout = 0; + char *dupdata; + const char *app = NULL, *arg = NULL; + int timeout = 0; int tone_type = MODEM_CONNECT_TONES_FAX_CNG; - if (!zstr(data) && (dupdata = switch_core_session_strdup(session, data))) { + if (!zstr(data) && (dupdata = switch_core_session_strdup(session, data))) { if ((argc = switch_split(dupdata, ' ', argv)) >= 2) { - app = argv[0]; - arg = argv[1]; + app = argv[0]; + arg = argv[1]; if (argc > 2) { timeout = atoi(argv[2]); if (timeout < 0) { @@ -142,101 +142,101 @@ SWITCH_STANDARD_APP(spandsp_fax_detect_session_function) tone_type = MODEM_CONNECT_TONES_FAX_CNG; } } - } - } - - if (app) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Enabling fax detection '%s' '%s'\n", argv[0], argv[1]); + } + } + + if (app) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Enabling fax detection '%s' '%s'\n", argv[0], argv[1]); spandsp_fax_detect_session(session, "rw", timeout, tone_type, 1, app, arg, NULL); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot Enable fax detection '%s' '%s'\n", argv[0], argv[1]); - } + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot Enable fax detection '%s' '%s'\n", argv[0], argv[1]); + } } SWITCH_STANDARD_APP(spandsp_stop_fax_detect_session_function) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "Disabling fax detection\n"); - spandsp_fax_stop_detect_session(session); + spandsp_fax_stop_detect_session(session); } static void tdd_event_handler(switch_event_t *event) { - const char *uuid = switch_event_get_header(event, "tdd-uuid"); - const char *message = switch_event_get_body(event); - switch_core_session_t *session; + const char *uuid = switch_event_get_header(event, "tdd-uuid"); + const char *message = switch_event_get_body(event); + switch_core_session_t *session; - if (zstr(message)) { - message = switch_event_get_header(event, "tdd-message"); - } + if (zstr(message)) { + message = switch_event_get_header(event, "tdd-message"); + } - if (zstr(message)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No message for tdd handler\n"); - return; - } + if (zstr(message)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No message for tdd handler\n"); + return; + } - if (zstr(uuid)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No uuid for tdd handler\n"); - return; - } + if (zstr(uuid)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No uuid for tdd handler\n"); + return; + } - if ((session = switch_core_session_locate(uuid))) { + if ((session = switch_core_session_locate(uuid))) { - spandsp_tdd_encode_session(session, message); + spandsp_tdd_encode_session(session, message); - switch_core_session_rwunlock(session); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No session for supplied uuid.\n"); - } + switch_core_session_rwunlock(session); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No session for supplied uuid.\n"); + } } static void event_handler(switch_event_t *event) { - load_configuration(1); + load_configuration(1); } SWITCH_STANDARD_APP(t38_gateway_function) { - switch_channel_t *channel = switch_core_session_get_channel(session); - time_t timeout = switch_epoch_time_now(NULL) + 20; - const char *var; - int argc = 0; - char *argv[2] = { 0 }; - char *dupdata; - const char *direction = NULL, *flags = NULL; - - if (!zstr(data) && (dupdata = switch_core_session_strdup(session, data))) { - if ((argc = switch_split(dupdata, ' ', argv))) { - if (argc > 0) { - direction = argv[0]; - } - - if (argc > 1) { - flags = argv[1]; - } - } - } + switch_channel_t *channel = switch_core_session_get_channel(session); + time_t timeout = switch_epoch_time_now(NULL) + 20; + const char *var; + int argc = 0; + char *argv[2] = { 0 }; + char *dupdata; + const char *direction = NULL, *flags = NULL; - if (zstr(direction) || strcasecmp(direction, "self")) { - direction = "peer"; - } - - switch_channel_set_variable(channel, "t38_leg", direction); + if (!zstr(data) && (dupdata = switch_core_session_strdup(session, data))) { + if ((argc = switch_split(dupdata, ' ', argv))) { + if (argc > 0) { + direction = argv[0]; + } - if (!zstr(flags) && !strcasecmp(flags, "nocng")) { - t38_gateway_start(session, direction, NULL); - } else { - if ((var = switch_channel_get_variable(channel, "t38_gateway_detect_timeout"))) { - long to = atol(var); - if (to > -1) { - timeout = (time_t) (switch_epoch_time_now(NULL) + to); - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s invalid timeout value.\n", switch_channel_get_name(channel)); - } - } + if (argc > 1) { + flags = argv[1]; + } + } + } - //switch_ivr_tone_detect_session(session, "t38", "1100.0", "rw", timeout, 1, direction, NULL, t38_gateway_start); + if (zstr(direction) || strcasecmp(direction, "self")) { + direction = "peer"; + } + + switch_channel_set_variable(channel, "t38_leg", direction); + + if (!zstr(flags) && !strcasecmp(flags, "nocng")) { + t38_gateway_start(session, direction, NULL); + } else { + if ((var = switch_channel_get_variable(channel, "t38_gateway_detect_timeout"))) { + long to = atol(var); + if (to > -1) { + timeout = (time_t) (switch_epoch_time_now(NULL) + to); + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s invalid timeout value.\n", switch_channel_get_name(channel)); + } + } + + //switch_ivr_tone_detect_session(session, "t38", "1100.0", "rw", timeout, 1, direction, NULL, t38_gateway_start); spandsp_fax_detect_session(session, "rw", timeout, MODEM_CONNECT_TONES_FAX_CED_OR_PREAMBLE, 1, direction, NULL, t38_gateway_start); - } + } } /** @@ -265,17 +265,17 @@ SWITCH_STANDARD_APP(start_tone_detect_app) SWITCH_STANDARD_API(start_tone_detect_api) { switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_core_session_t *psession = NULL; + switch_core_session_t *psession = NULL; if (zstr(cmd)) { stream->write_function(stream, "-ERR missing descriptor name\n"); return SWITCH_STATUS_SUCCESS; } - if (!(psession = switch_core_session_locate(cmd))) { - stream->write_function(stream, "-ERR Cannot locate session\n"); - return SWITCH_STATUS_SUCCESS; - } + if (!(psession = switch_core_session_locate(cmd))) { + stream->write_function(stream, "-ERR Cannot locate session\n"); + return SWITCH_STATUS_SUCCESS; + } status = callprogress_detector_start(psession, cmd); @@ -285,8 +285,8 @@ SWITCH_STANDARD_API(start_tone_detect_api) } else { stream->write_function(stream, "-ERR failed to start tone detector\n"); } - - switch_core_session_rwunlock(psession); + + switch_core_session_rwunlock(psession); return status; } @@ -316,22 +316,22 @@ SWITCH_STANDARD_APP(stop_tone_detect_app) SWITCH_STANDARD_API(stop_tone_detect_api) { switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_core_session_t *psession = NULL; + switch_core_session_t *psession = NULL; if (zstr(cmd)) { stream->write_function(stream, "-ERR missing descriptor name\n"); return SWITCH_STATUS_SUCCESS; } - if (!(psession = switch_core_session_locate(cmd))) { - stream->write_function(stream, "-ERR Cannot locate session\n"); - return SWITCH_STATUS_SUCCESS; - } + if (!(psession = switch_core_session_locate(cmd))) { + stream->write_function(stream, "-ERR Cannot locate session\n"); + return SWITCH_STATUS_SUCCESS; + } + + callprogress_detector_stop(psession); + stream->write_function(stream, "+OK stopped\n"); + switch_core_session_rwunlock(psession); - callprogress_detector_stop(psession); - stream->write_function(stream, "+OK stopped\n"); - switch_core_session_rwunlock(psession); - return status; } @@ -340,22 +340,22 @@ SWITCH_STANDARD_API(stop_tone_detect_api) SWITCH_STANDARD_API(start_tdd_detect_api) { switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_core_session_t *psession = NULL; + switch_core_session_t *psession = NULL; - if (!(psession = switch_core_session_locate(cmd))) { - stream->write_function(stream, "-ERR Cannot locate session\n"); - return SWITCH_STATUS_SUCCESS; - } + if (!(psession = switch_core_session_locate(cmd))) { + stream->write_function(stream, "-ERR Cannot locate session\n"); + return SWITCH_STATUS_SUCCESS; + } - spandsp_tdd_decode_session(psession); + spandsp_tdd_decode_session(psession); if (status == SWITCH_STATUS_SUCCESS) { stream->write_function(stream, "+OK started\n"); } else { stream->write_function(stream, "-ERR failed to start tdd detector\n"); } - - switch_core_session_rwunlock(psession); + + switch_core_session_rwunlock(psession); return status; } @@ -364,94 +364,94 @@ SWITCH_STANDARD_API(start_tdd_detect_api) SWITCH_STANDARD_API(stop_tdd_detect_api) { switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_core_session_t *psession = NULL; + switch_core_session_t *psession = NULL; - if (!(psession = switch_core_session_locate(cmd))) { - stream->write_function(stream, "-ERR Cannot locate session\n"); - return SWITCH_STATUS_SUCCESS; - } + if (!(psession = switch_core_session_locate(cmd))) { + stream->write_function(stream, "-ERR Cannot locate session\n"); + return SWITCH_STATUS_SUCCESS; + } - spandsp_stop_tdd_decode_session(psession); + spandsp_stop_tdd_decode_session(psession); + + stream->write_function(stream, "+OK stopped\n"); + switch_core_session_rwunlock(psession); - stream->write_function(stream, "+OK stopped\n"); - switch_core_session_rwunlock(psession); - return status; } SWITCH_STANDARD_API(start_send_tdd_api) { - switch_core_session_t *psession = NULL; - char *puuid = NULL, *text = NULL; + switch_core_session_t *psession = NULL; + char *puuid = NULL, *text = NULL; if (zstr(cmd)) { stream->write_function(stream, "-ERR missing uuid\n"); return SWITCH_STATUS_SUCCESS; } - puuid = strdup((char *)cmd); + puuid = strdup((char *)cmd); - if ((text = strchr(puuid, ' '))) { - *text++ = '\0'; - } + if ((text = strchr(puuid, ' '))) { + *text++ = '\0'; + } if (zstr(text)) { stream->write_function(stream, "-ERR missing text\n"); - goto end; + goto end; } - if (!(psession = switch_core_session_locate(puuid))) { - stream->write_function(stream, "-ERR Cannot locate session\n"); - goto end; - } + if (!(psession = switch_core_session_locate(puuid))) { + stream->write_function(stream, "-ERR Cannot locate session\n"); + goto end; + } - spandsp_tdd_encode_session(psession, text); + spandsp_tdd_encode_session(psession, text); + + stream->write_function(stream, "+OK\n"); + switch_core_session_rwunlock(psession); - stream->write_function(stream, "+OK\n"); - switch_core_session_rwunlock(psession); - end: - switch_safe_free(puuid); + switch_safe_free(puuid); return SWITCH_STATUS_SUCCESS; } void mod_spandsp_indicate_data(switch_core_session_t *session, switch_bool_t self, switch_bool_t on) { - switch_core_session_t *target_session = NULL; - int locked = 0; + switch_core_session_t *target_session = NULL; + int locked = 0; - if (self) { - target_session = session; - } else { - if (switch_core_session_get_partner(session, &target_session) == SWITCH_STATUS_SUCCESS) { - locked = 1; - } else { - target_session = NULL; - } - } + if (self) { + target_session = session; + } else { + if (switch_core_session_get_partner(session, &target_session) == SWITCH_STATUS_SUCCESS) { + locked = 1; + } else { + target_session = NULL; + } + } - if (target_session) { - switch_core_session_message_t *msg; - - msg = switch_core_session_alloc(target_session, sizeof(*msg)); - MESSAGE_STAMP_FFL(msg); - msg->message_id = SWITCH_MESSAGE_INDICATE_AUDIO_DATA; - msg->from = __FILE__; - msg->numeric_arg = on; - - switch_core_session_queue_message(target_session, msg); + if (target_session) { + switch_core_session_message_t *msg; - if (locked) { - switch_core_session_rwunlock(target_session); - locked = 0; - } - } + msg = switch_core_session_alloc(target_session, sizeof(*msg)); + MESSAGE_STAMP_FFL(msg); + msg->message_id = SWITCH_MESSAGE_INDICATE_AUDIO_DATA; + msg->from = __FILE__; + msg->numeric_arg = on; + + switch_core_session_queue_message(target_session, msg); + + if (locked) { + switch_core_session_rwunlock(target_session); + locked = 0; + } + } } @@ -462,46 +462,46 @@ void mod_spandsp_indicate_data(switch_core_session_t *session, switch_bool_t sel switch_status_t load_configuration(switch_bool_t reload) { switch_xml_t xml = NULL, x_lists = NULL, x_list = NULL, cfg = NULL, callprogress = NULL, xdescriptor = NULL; - switch_status_t status = SWITCH_STATUS_FALSE; + switch_status_t status = SWITCH_STATUS_FALSE; - switch_mutex_lock(spandsp_globals.mutex); + switch_mutex_lock(spandsp_globals.mutex); if (spandsp_globals.tones) { - switch_core_hash_destroy(&spandsp_globals.tones); - } - - if (spandsp_globals.config_pool) { - switch_core_destroy_memory_pool(&spandsp_globals.config_pool); - } + switch_core_hash_destroy(&spandsp_globals.tones); + } - switch_core_new_memory_pool(&spandsp_globals.config_pool); + if (spandsp_globals.config_pool) { + switch_core_destroy_memory_pool(&spandsp_globals.config_pool); + } + + switch_core_new_memory_pool(&spandsp_globals.config_pool); switch_core_hash_init(&spandsp_globals.tones, spandsp_globals.config_pool); - spandsp_globals.modem_dialplan = "XML"; - spandsp_globals.modem_context = "default"; - spandsp_globals.modem_count = 0; + spandsp_globals.modem_dialplan = "XML"; + spandsp_globals.modem_context = "default"; + spandsp_globals.modem_count = 0; - spandsp_globals.enable_t38 = 1; + spandsp_globals.enable_t38 = 1; spandsp_globals.total_sessions = 0; spandsp_globals.verbose = 0; spandsp_globals.use_ecm = 1; spandsp_globals.disable_v17 = 0; spandsp_globals.prepend_string = switch_core_strdup(spandsp_globals.config_pool, "fax"); spandsp_globals.spool = switch_core_strdup(spandsp_globals.config_pool, "/tmp"); - spandsp_globals.ident = "SpanDSP Fax Ident"; - spandsp_globals.header = "SpanDSP Fax Header"; - spandsp_globals.timezone = ""; + spandsp_globals.ident = "SpanDSP Fax Ident"; + spandsp_globals.header = "SpanDSP Fax Header"; + spandsp_globals.timezone = ""; spandsp_globals.tonedebug = 0; if ((xml = switch_xml_open_cfg("spandsp.conf", &cfg, NULL)) || (xml = switch_xml_open_cfg("fax.conf", &cfg, NULL))) { - status = SWITCH_STATUS_SUCCESS; + status = SWITCH_STATUS_SUCCESS; if ((x_lists = switch_xml_child(cfg, "modem-settings"))) { for (x_list = switch_xml_child(x_lists, "param"); x_list; x_list = x_list->next) { const char *name = switch_xml_attr(x_list, "name"); const char *value = switch_xml_attr(x_list, "value"); - + if (zstr(name)) { continue; } @@ -510,28 +510,28 @@ switch_status_t load_configuration(switch_bool_t reload) continue; } - - if (!reload && !strcmp(name, "total-modems")) { - int tmp = atoi(value); - if (tmp > -1 && tmp < MAX_MODEMS) { - spandsp_globals.modem_count = tmp; - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%d] for total-modems\n", tmp); - } + if (!reload && !strcmp(name, "total-modems")) { + int tmp = atoi(value); + + if (tmp > -1 && tmp < MAX_MODEMS) { + spandsp_globals.modem_count = tmp; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%d] for total-modems\n", tmp); + } } else if (!strcmp(name, "dialplan")) { - spandsp_globals.modem_dialplan = switch_core_strdup(spandsp_globals.config_pool, value); + spandsp_globals.modem_dialplan = switch_core_strdup(spandsp_globals.config_pool, value); } else if (!strcmp(name, "context")) { - spandsp_globals.modem_context = switch_core_strdup(spandsp_globals.config_pool, value); + spandsp_globals.modem_context = switch_core_strdup(spandsp_globals.config_pool, value); } else if (!strcmp(name, "verbose")) { - if (switch_true(value)) { - spandsp_globals.modem_verbose = 1; - } else { - spandsp_globals.modem_verbose = 0; - } - } - } - } + if (switch_true(value)) { + spandsp_globals.modem_verbose = 1; + } else { + spandsp_globals.modem_verbose = 0; + } + } + } + } if ((x_lists = switch_xml_child(cfg, "fax-settings")) || (x_lists = switch_xml_child(cfg, "settings"))) { for (x_list = switch_xml_child(x_lists, "param"); x_list; x_list = x_list->next) { @@ -564,19 +564,19 @@ switch_status_t load_configuration(switch_bool_t reload) } else if (!strcmp(name, "enable-t38")) { if (switch_true(value)) { spandsp_globals.enable_t38= 1; - } else { + } else { spandsp_globals.enable_t38 = 0; - } + } } else if (!strcmp(name, "enable-t38-request")) { if (switch_true(value)) { spandsp_globals.enable_t38_request = 1; - } else { + } else { spandsp_globals.enable_t38_request = 0; - } + } } else if (!strcmp(name, "ident")) { - spandsp_globals.ident = switch_core_strdup(spandsp_globals.config_pool, value); + spandsp_globals.ident = switch_core_strdup(spandsp_globals.config_pool, value); } else if (!strcmp(name, "header")) { - spandsp_globals.header = switch_core_strdup(spandsp_globals.config_pool, value); + spandsp_globals.header = switch_core_strdup(spandsp_globals.config_pool, value); } else if (!strcmp(name, "spool-dir")) { spandsp_globals.spool = switch_core_strdup(spandsp_globals.config_pool, value); } else if (!strcmp(name, "file-prefix")) { @@ -588,8 +588,8 @@ switch_status_t load_configuration(switch_bool_t reload) } } - /* Configure call progress detector */ - if ((callprogress = switch_xml_child(cfg, "descriptors"))) { + /* Configure call progress detector */ + if ((callprogress = switch_xml_child(cfg, "descriptors"))) { /* check if debugging is enabled */ const char *debug = switch_xml_attr(callprogress, "debug-level"); if (!zstr(debug) && switch_is_number(debug)) { @@ -600,89 +600,89 @@ switch_status_t load_configuration(switch_bool_t reload) } } - for (xdescriptor = switch_xml_child(callprogress, "descriptor"); xdescriptor; xdescriptor = switch_xml_next(xdescriptor)) { - const char *name = switch_xml_attr(xdescriptor, "name"); - const char *tone_name = NULL; - switch_xml_t tone = NULL, element = NULL; - tone_descriptor_t *descriptor = NULL; + for (xdescriptor = switch_xml_child(callprogress, "descriptor"); xdescriptor; xdescriptor = switch_xml_next(xdescriptor)) { + const char *name = switch_xml_attr(xdescriptor, "name"); + const char *tone_name = NULL; + switch_xml_t tone = NULL, element = NULL; + tone_descriptor_t *descriptor = NULL; - /* create descriptor */ - if (zstr(name)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing name\n"); - switch_goto_status(SWITCH_STATUS_FALSE, done); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding tone_descriptor: %s\n", name); - if (tone_descriptor_create(&descriptor, name, spandsp_globals.config_pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to allocate tone_descriptor: %s\n", name); - switch_goto_status(SWITCH_STATUS_FALSE, done); - } - switch_core_hash_insert(spandsp_globals.tones, name, descriptor); + /* create descriptor */ + if (zstr(name)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing name\n"); + switch_goto_status(SWITCH_STATUS_FALSE, done); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding tone_descriptor: %s\n", name); + if (tone_descriptor_create(&descriptor, name, spandsp_globals.config_pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to allocate tone_descriptor: %s\n", name); + switch_goto_status(SWITCH_STATUS_FALSE, done); + } + switch_core_hash_insert(spandsp_globals.tones, name, descriptor); + + /* add tones to descriptor */ + for (tone = switch_xml_child(xdescriptor, "tone"); tone; tone = switch_xml_next(tone)) { + int id = 0; + tone_name = switch_xml_attr(tone, "name"); + if (zstr(tone_name)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing name for %s\n", name); + switch_goto_status(SWITCH_STATUS_FALSE, done); + } + id = tone_descriptor_add_tone(descriptor, tone_name); + if (id == -1) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Unable to add tone_descriptor: %s, tone: %s. (too many tones)\n", name, tone_name); + switch_goto_status(SWITCH_STATUS_FALSE, done); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "Adding tone_descriptor: %s, tone: %s(%d)\n", name, tone_name, id); + /* add elements to tone */ + for (element = switch_xml_child(tone, "element"); element; element = switch_xml_next(element)) { + const char *freq1_attr = switch_xml_attr(element, "freq1"); + const char *freq2_attr = switch_xml_attr(element, "freq2"); + const char *min_attr = switch_xml_attr(element, "min"); + const char *max_attr = switch_xml_attr(element, "max"); + int freq1, freq2, min, max; + if (zstr(freq1_attr)) { + freq1 = 0; + } else { + freq1 = atoi(freq1_attr); + } + if (zstr(freq2_attr)) { + freq2 = 0; + } else { + freq2 = atoi(freq2_attr); + } + if (zstr(min_attr)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Missing min in of %s %s(%d)\n", name, tone_name, id); + switch_goto_status(SWITCH_STATUS_FALSE, done); + } + min = atoi(min_attr); + if (zstr(max_attr)) { + max = 0; + } else { + max = atoi(max_attr); + } + /* check params */ + if ((freq1 < 0 || freq2 < 0 || min < 0 || max < 0) || (freq1 == 0 && min == 0 && max == 0)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid element param.\n"); + switch_goto_status(SWITCH_STATUS_FALSE, done); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "Adding tone_descriptor: %s, tone: %s(%d), element (%d, %d, %d, %d)\n", name, tone_name, id, freq1, freq2, min, max); + tone_descriptor_add_tone_element(descriptor, id, freq1, freq2, min, max); + } + } + } + } + + done: - /* add tones to descriptor */ - for (tone = switch_xml_child(xdescriptor, "tone"); tone; tone = switch_xml_next(tone)) { - int id = 0; - tone_name = switch_xml_attr(tone, "name"); - if (zstr(tone_name)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing name for %s\n", name); - switch_goto_status(SWITCH_STATUS_FALSE, done); - } - id = tone_descriptor_add_tone(descriptor, tone_name); - if (id == -1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, - "Unable to add tone_descriptor: %s, tone: %s. (too many tones)\n", name, tone_name); - switch_goto_status(SWITCH_STATUS_FALSE, done); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, - "Adding tone_descriptor: %s, tone: %s(%d)\n", name, tone_name, id); - /* add elements to tone */ - for (element = switch_xml_child(tone, "element"); element; element = switch_xml_next(element)) { - const char *freq1_attr = switch_xml_attr(element, "freq1"); - const char *freq2_attr = switch_xml_attr(element, "freq2"); - const char *min_attr = switch_xml_attr(element, "min"); - const char *max_attr = switch_xml_attr(element, "max"); - int freq1, freq2, min, max; - if (zstr(freq1_attr)) { - freq1 = 0; - } else { - freq1 = atoi(freq1_attr); - } - if (zstr(freq2_attr)) { - freq2 = 0; - } else { - freq2 = atoi(freq2_attr); - } - if (zstr(min_attr)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, - "Missing min in of %s %s(%d)\n", name, tone_name, id); - switch_goto_status(SWITCH_STATUS_FALSE, done); - } - min = atoi(min_attr); - if (zstr(max_attr)) { - max = 0; - } else { - max = atoi(max_attr); - } - /* check params */ - if ((freq1 < 0 || freq2 < 0 || min < 0 || max < 0) || (freq1 == 0 && min == 0 && max == 0)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid element param.\n"); - switch_goto_status(SWITCH_STATUS_FALSE, done); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, - "Adding tone_descriptor: %s, tone: %s(%d), element (%d, %d, %d, %d)\n", name, tone_name, id, freq1, freq2, min, max); - tone_descriptor_add_tone_element(descriptor, id, freq1, freq2, min, max); - } - } - } - } - - done: - switch_xml_free(xml); } - switch_mutex_unlock(spandsp_globals.mutex); + switch_mutex_unlock(spandsp_globals.mutex); - return status; + return status; } @@ -698,7 +698,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_spandsp_init) switch_mutex_init(&spandsp_globals.mutex, SWITCH_MUTEX_NESTED, pool); SWITCH_ADD_APP(app_interface, "t38_gateway", "Convert to T38 Gateway if tones are heard", "Convert to T38 Gateway if tones are heard", - t38_gateway_function, "", SAF_MEDIA_TAP); + t38_gateway_function, "", SAF_MEDIA_TAP); SWITCH_ADD_APP(app_interface, "rxfax", "FAX Receive Application", "FAX Receive Application", spanfax_rx_function, SPANFAX_RX_USAGE, SAF_SUPPORT_NOMEDIA); @@ -722,27 +722,27 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_spandsp_init) "[ ][ ][ ]", SAF_NONE); SWITCH_ADD_APP(app_interface, "spandsp_stop_fax_detect", "stop fax detect", "stop fax detect", spandsp_stop_fax_detect_session_function, "", SAF_NONE); - - load_configuration(0); + + load_configuration(0); mod_spandsp_fax_load(pool); - mod_spandsp_codecs_load(module_interface, pool); + mod_spandsp_codecs_load(module_interface, pool); + - if (mod_spandsp_dsp_load(module_interface, pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load or process spandsp.conf, not adding tone_detect applications\n"); - } else { - SWITCH_ADD_APP(app_interface, "start_tone_detect", "Start background tone detection with cadence", "", start_tone_detect_app, "[name]", SAF_NONE); - SWITCH_ADD_APP(app_interface, "stop_tone_detect", "Stop background tone detection with cadence", "", stop_tone_detect_app, "", SAF_NONE); - SWITCH_ADD_API(api_interface, "start_tone_detect", "Start background tone detection with cadence", start_tone_detect_api, "[name]"); - SWITCH_ADD_API(api_interface, "stop_tone_detect", "Stop background tone detection with cadence", stop_tone_detect_api, ""); + } else { + SWITCH_ADD_APP(app_interface, "start_tone_detect", "Start background tone detection with cadence", "", start_tone_detect_app, "[name]", SAF_NONE); + SWITCH_ADD_APP(app_interface, "stop_tone_detect", "Stop background tone detection with cadence", "", stop_tone_detect_app, "", SAF_NONE); + SWITCH_ADD_API(api_interface, "start_tone_detect", "Start background tone detection with cadence", start_tone_detect_api, "[name]"); + SWITCH_ADD_API(api_interface, "stop_tone_detect", "Stop background tone detection with cadence", stop_tone_detect_api, ""); } - - SWITCH_ADD_API(api_interface, "start_tdd_detect", "Start background tdd detection", start_tdd_detect_api, ""); - SWITCH_ADD_API(api_interface, "stop_tdd_detect", "Stop background tdd detection", stop_tdd_detect_api, ""); - SWITCH_ADD_API(api_interface, "uuid_send_tdd", "send tdd data to a uuid", start_send_tdd_api, " "); + SWITCH_ADD_API(api_interface, "start_tdd_detect", "Start background tdd detection", start_tdd_detect_api, ""); + SWITCH_ADD_API(api_interface, "stop_tdd_detect", "Stop background tdd detection", stop_tdd_detect_api, ""); + + SWITCH_ADD_API(api_interface, "uuid_send_tdd", "send tdd data to a uuid", start_send_tdd_api, " "); switch_console_set_complete("add uuid_send_tdd ::console::list_uuid"); @@ -776,13 +776,13 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_spandsp_shutdown) mod_spandsp_dsp_shutdown(); modem_global_shutdown(); - if (spandsp_globals.tones) { - switch_core_hash_destroy(&spandsp_globals.tones); - } + if (spandsp_globals.tones) { + switch_core_hash_destroy(&spandsp_globals.tones); + } - if (spandsp_globals.config_pool) { - switch_core_destroy_memory_pool(&spandsp_globals.config_pool); - } + if (spandsp_globals.config_pool) { + switch_core_destroy_memory_pool(&spandsp_globals.config_pool); + } return SWITCH_STATUS_UNLOAD; } diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.h b/src/mod/applications/mod_spandsp/mod_spandsp.h index 68152ffdf9..0d40b43c88 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.h +++ b/src/mod/applications/mod_spandsp/mod_spandsp.h @@ -60,9 +60,9 @@ struct spandsp_globals { short int use_ecm; short int verbose; short int disable_v17; - short int enable_t38; - short int enable_t38_request; - short int enable_t38_insist; + short int enable_t38; + short int enable_t38_request; + short int enable_t38_insist; char *ident; char *header; char *timezone; @@ -84,7 +84,7 @@ extern struct spandsp_globals spandsp_globals; typedef enum { FUNCTION_TX, FUNCTION_RX, - FUNCTION_GW + FUNCTION_GW } mod_spandsp_fax_application_mode_t; /****************************************************************************** @@ -107,7 +107,7 @@ struct tone_descriptor { /** The mapping of tone id to key */ char tone_keys[MAX_TONES][STRLEN]; - int idx; + int idx; }; typedef struct tone_descriptor tone_descriptor_t; diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c b/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c index 576c7592d1..ddf833dd94 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c @@ -40,8 +40,8 @@ typedef struct { switch_core_session_t *session; v18_state_t *tdd_state; - int head_lead; - int tail_lead; + int head_lead; + int tail_lead; } switch_tdd_t; static switch_bool_t tdd_encode_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type) @@ -63,22 +63,22 @@ static switch_bool_t tdd_encode_callback(switch_media_bug_t *bug, void *user_dat if ((frame = switch_core_media_bug_get_write_replace_frame(bug))) { int len; - if (pvt->tail_lead) { - if (!--pvt->tail_lead) { - r = SWITCH_FALSE; - } - memset(frame->data, 0, frame->datalen); + if (pvt->tail_lead) { + if (!--pvt->tail_lead) { + r = SWITCH_FALSE; + } + memset(frame->data, 0, frame->datalen); - } else if (pvt->head_lead) { - pvt->head_lead--; - memset(frame->data, 0, frame->datalen); - } else { - len = v18_tx(pvt->tdd_state, frame->data, frame->samples); + } else if (pvt->head_lead) { + pvt->head_lead--; + memset(frame->data, 0, frame->datalen); + } else { + len = v18_tx(pvt->tdd_state, frame->data, frame->samples); - if (!len) { - pvt->tail_lead = TDD_LEAD; - } - } + if (!len) { + pvt->tail_lead = TDD_LEAD; + } + } switch_core_media_bug_set_write_replace_frame(bug, frame); } @@ -106,135 +106,135 @@ switch_status_t spandsp_stop_tdd_encode_session(switch_core_session_t *session) static void put_text_msg(void *user_data, const uint8_t *msg, int len) { - switch_tdd_t *pvt = (switch_tdd_t *) user_data; - switch_event_t *event, *clone; - switch_channel_t *channel = switch_core_session_get_channel(pvt->session); - switch_core_session_t *other_session; + switch_tdd_t *pvt = (switch_tdd_t *) user_data; + switch_event_t *event, *clone; + switch_channel_t *channel = switch_core_session_get_channel(pvt->session); + switch_core_session_t *other_session; - switch_channel_add_variable_var_check(channel, "tdd_messages", (char *)msg, SWITCH_FALSE, SWITCH_STACK_PUSH); - - - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_TDD_RECV_MESSAGE) == SWITCH_STATUS_SUCCESS) { - - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", "mod_spandsp"); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "tdd"); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "TDD MESSAGE"); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "TDD-Data", (char *)msg); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(pvt->session)); - switch_event_add_body(event, "%s\n\n", (char *)msg); - - if (switch_core_session_get_partner(pvt->session, &other_session) == SWITCH_STATUS_SUCCESS) { - - if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) { - switch_core_session_receive_event(other_session, &clone); - } - - if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) { - switch_core_session_queue_event(other_session, &clone); - } - - switch_core_session_rwunlock(other_session); - } - - switch_event_fire(&event); + switch_channel_add_variable_var_check(channel, "tdd_messages", (char *)msg, SWITCH_FALSE, SWITCH_STACK_PUSH); - } - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_DEBUG, "%s got TDD Message [%s]\n", switch_channel_get_name(channel), (char *)msg); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_TDD_RECV_MESSAGE) == SWITCH_STATUS_SUCCESS) { + + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", "mod_spandsp"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "tdd"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subject", "TDD MESSAGE"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "TDD-Data", (char *)msg); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(pvt->session)); + switch_event_add_body(event, "%s\n\n", (char *)msg); + + if (switch_core_session_get_partner(pvt->session, &other_session) == SWITCH_STATUS_SUCCESS) { + + if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) { + switch_core_session_receive_event(other_session, &clone); + } + + if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) { + switch_core_session_queue_event(other_session, &clone); + } + + switch_core_session_rwunlock(other_session); + } + + switch_event_fire(&event); + + + } + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(pvt->session), SWITCH_LOG_DEBUG, "%s got TDD Message [%s]\n", switch_channel_get_name(channel), (char *)msg); } static int get_v18_mode(switch_core_session_t *session) { - switch_channel_t *channel = switch_core_session_get_channel(session); - const char *var; - int r = V18_MODE_5BIT_45; + switch_channel_t *channel = switch_core_session_get_channel(session); + const char *var; + int r = V18_MODE_5BIT_45; - if ((var = switch_channel_get_variable(channel, "v18_mode"))) { - if (!strcasecmp(var, "5BIT_45") || !strcasecmp(var, "baudot")) { - r = V18_MODE_5BIT_45; - } else if (!strcasecmp(var, "5BIT_50")) { - r = V18_MODE_5BIT_50; - } else if (!strcasecmp(var, "DTMF")) { - r = V18_MODE_DTMF; - } else if (!strcasecmp(var, "EDT")) { - r = V18_MODE_EDT; - } else if (!strcasecmp(var, "BELL103") || !strcasecmp(var, "ascii")) { - r = V18_MODE_BELL103; - } else if (!strcasecmp(var, "V23VIDEOTEX")) { - r = V18_MODE_V23VIDEOTEX; - } else if (!strcasecmp(var, "V21TEXTPHONE")) { - r = V18_MODE_V21TEXTPHONE; - } else if (!strcasecmp(var, "V18TEXTPHONE")) { - r = V18_MODE_V18TEXTPHONE; - } - } + if ((var = switch_channel_get_variable(channel, "v18_mode"))) { + if (!strcasecmp(var, "5BIT_45") || !strcasecmp(var, "baudot")) { + r = V18_MODE_5BIT_45; + } else if (!strcasecmp(var, "5BIT_50")) { + r = V18_MODE_5BIT_50; + } else if (!strcasecmp(var, "DTMF")) { + r = V18_MODE_DTMF; + } else if (!strcasecmp(var, "EDT")) { + r = V18_MODE_EDT; + } else if (!strcasecmp(var, "BELL103") || !strcasecmp(var, "ascii")) { + r = V18_MODE_BELL103; + } else if (!strcasecmp(var, "V23VIDEOTEX")) { + r = V18_MODE_V23VIDEOTEX; + } else if (!strcasecmp(var, "V21TEXTPHONE")) { + r = V18_MODE_V21TEXTPHONE; + } else if (!strcasecmp(var, "V18TEXTPHONE")) { + r = V18_MODE_V18TEXTPHONE; + } + } - return r; + return r; } switch_status_t spandsp_tdd_send_session(switch_core_session_t *session, const char *text) { - v18_state_t *tdd_state; - switch_frame_t *read_frame, write_frame = { 0 }; - uint8_t write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE]; + v18_state_t *tdd_state; + switch_frame_t *read_frame, write_frame = { 0 }; + uint8_t write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE]; switch_codec_implementation_t read_impl = { 0 }; switch_codec_t write_codec = { 0 }; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_status_t status; + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_status_t status; switch_core_session_get_read_impl(session, &read_impl); - - if (switch_core_codec_init(&write_codec, - "L16", - NULL, - read_impl.actual_samples_per_second, - read_impl.microseconds_per_packet / 1000, - read_impl.number_of_channels, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, - switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { - write_frame.data = write_buf; - write_frame.buflen = sizeof(write_buf); - write_frame.datalen = read_impl.decoded_bytes_per_packet; - write_frame.samples = write_frame.datalen / 2; - write_frame.codec = &write_codec; - switch_core_session_set_read_codec(session, &write_codec); - } else { - return SWITCH_STATUS_FALSE; - } - tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), put_text_msg, NULL); + if (switch_core_codec_init(&write_codec, + "L16", + NULL, + read_impl.actual_samples_per_second, + read_impl.microseconds_per_packet / 1000, + read_impl.number_of_channels, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, + switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) { + write_frame.data = write_buf; + write_frame.buflen = sizeof(write_buf); + write_frame.datalen = read_impl.decoded_bytes_per_packet; + write_frame.samples = write_frame.datalen / 2; + write_frame.codec = &write_codec; + switch_core_session_set_read_codec(session, &write_codec); + } else { + return SWITCH_STATUS_FALSE; + } + + tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), put_text_msg, NULL); + - v18_put(tdd_state, text, -1); - while(switch_channel_ready(channel)) { + while(switch_channel_ready(channel)) { status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); if (!SWITCH_READ_ACCEPTABLE(status)) { break; } - - if (!v18_tx(tdd_state, (void *)write_buf, write_frame.samples)) { - break; - } - if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - break; - } + if (!v18_tx(tdd_state, (void *)write_buf, write_frame.samples)) { + break; + } - } + if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { + break; + } - switch_core_codec_destroy(&write_codec); - switch_core_session_set_read_codec(session, NULL); + } - v18_free(tdd_state); + switch_core_codec_destroy(&write_codec); + switch_core_session_set_read_codec(session, NULL); - return SWITCH_STATUS_SUCCESS; + v18_free(tdd_state); + + return SWITCH_STATUS_SUCCESS; } @@ -254,12 +254,12 @@ switch_status_t spandsp_tdd_encode_session(switch_core_session_t *session, const pvt->session = session; pvt->tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), put_text_msg, NULL); - pvt->head_lead = TDD_LEAD; + pvt->head_lead = TDD_LEAD; v18_put(pvt->tdd_state, text, -1); if ((status = switch_core_media_bug_add(session, "spandsp_tdd_encode", NULL, - tdd_encode_callback, pvt, 0, SMBF_WRITE_REPLACE | SMBF_NO_PAUSE, &bug)) != SWITCH_STATUS_SUCCESS) { + tdd_encode_callback, pvt, 0, SMBF_WRITE_REPLACE | SMBF_NO_PAUSE, &bug)) != SWITCH_STATUS_SUCCESS) { v18_free(pvt->tdd_state); return status; } @@ -290,7 +290,7 @@ static switch_bool_t tdd_decode_callback(switch_media_bug_t *bug, void *user_dat case SWITCH_ABC_TYPE_READ_REPLACE: if ((frame = switch_core_media_bug_get_read_replace_frame(bug))) { - v18_rx(pvt->tdd_state, frame->data, frame->samples); + v18_rx(pvt->tdd_state, frame->data, frame->samples); switch_core_media_bug_set_read_replace_frame(bug, frame); } @@ -334,7 +334,7 @@ switch_status_t spandsp_tdd_decode_session(switch_core_session_t *session) pvt->tdd_state = v18_init(NULL, FALSE, get_v18_mode(session), put_text_msg, pvt); if ((status = switch_core_media_bug_add(session, "spandsp_tdd_decode", NULL, - tdd_decode_callback, pvt, 0, SMBF_READ_REPLACE | SMBF_NO_PAUSE, &bug)) != SWITCH_STATUS_SUCCESS) { + tdd_decode_callback, pvt, 0, SMBF_READ_REPLACE | SMBF_NO_PAUSE, &bug)) != SWITCH_STATUS_SUCCESS) { v18_free(pvt->tdd_state); return status; } @@ -505,7 +505,7 @@ switch_status_t spandsp_inband_dtmf_session(switch_core_session_t *session) } if ((status = switch_core_media_bug_add(session, "spandsp_dtmf_detect", NULL, - inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE | SMBF_NO_PAUSE, &bug)) != SWITCH_STATUS_SUCCESS) { + inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE | SMBF_NO_PAUSE, &bug)) != SWITCH_STATUS_SUCCESS) { return status; } @@ -584,9 +584,9 @@ int tone_descriptor_add_tone(tone_descriptor_t *descriptor, const char *key) } switch_set_string(descriptor->tone_keys[id], key); - if (id > descriptor->idx) { - descriptor->idx = id; - } + if (id > descriptor->idx) { + descriptor->idx = id; + } return id; } @@ -742,7 +742,7 @@ switch_status_t callprogress_detector_start(switch_core_session_t *session, cons /* start listening for tones */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) Starting tone detection for '%s'\n", switch_channel_get_name(channel), name); switch_core_media_bug_add(session, "spandsp_tone_detect", NULL, - callprogress_detector_process_buffer, detector, 0 /* stop time */, SMBF_READ_REPLACE, &bug); + callprogress_detector_process_buffer, detector, 0 /* stop time */, SMBF_READ_REPLACE, &bug); if (!bug) { return SWITCH_STATUS_FALSE; } @@ -772,9 +772,7 @@ static switch_bool_t callprogress_detector_process_buffer(switch_media_bug_t *bu break; case SWITCH_ABC_TYPE_READ_REPLACE: { - switch_frame_t *frame; - - + switch_frame_t *frame; const char *detected_tone = NULL; if (!detector->spandsp_detector) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "(%s) detector is destroyed\n", switch_channel_get_name(channel)); @@ -802,8 +800,8 @@ static switch_bool_t callprogress_detector_process_buffer(switch_media_bug_t *bu tone_detector_destroy(detector); } break; - default: - break; + default: + break; } return SWITCH_TRUE; } @@ -838,7 +836,7 @@ switch_status_t mod_spandsp_dsp_load(switch_loadable_module_interface_t **module */ void mod_spandsp_dsp_shutdown(void) { - return; + return; } diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c index 975aca1fc8..c79043a846 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c @@ -59,14 +59,14 @@ typedef enum { T38_MODE, AUDIO_MODE, - T38_GATEWAY_MODE + T38_GATEWAY_MODE } transport_mode_t; typedef enum { - T38_MODE_UNKNOWN = 0, - T38_MODE_NEGOTIATED = 1, - T38_MODE_REQUESTED = 2, - T38_MODE_REFUSED = -1, + T38_MODE_UNKNOWN = 0, + T38_MODE_NEGOTIATED = 1, + T38_MODE_REQUESTED = 2, + T38_MODE_REFUSED = -1, } t38_mode_t; @@ -78,9 +78,9 @@ struct pvt_s { fax_state_t *fax_state; t38_terminal_state_t *t38_state; t38_gateway_state_t *t38_gateway_state; - t38_core_state_t *t38_core; + t38_core_state_t *t38_core; - udptl_state_t *udptl_state; + udptl_state_t *udptl_state; char *filename; char *ident; @@ -96,10 +96,10 @@ struct pvt_s { int tx_page_end; int done; - - t38_mode_t t38_mode; - struct pvt_s *next; + t38_mode_t t38_mode; + + struct pvt_s *next; }; typedef struct pvt_s pvt_t; @@ -107,10 +107,10 @@ typedef struct pvt_s pvt_t; static void launch_timer_thread(void); static struct { - pvt_t *head; - switch_mutex_t *mutex; - switch_thread_t *thread; - int thread_running; + pvt_t *head; + switch_mutex_t *mutex; + switch_thread_t *thread; + int thread_running; } t38_state_list; @@ -118,7 +118,7 @@ static struct { static void wake_thread(int force) { if (force) { - switch_thread_cond_signal(spandsp_globals.cond); + switch_thread_cond_signal(spandsp_globals.cond); return; } @@ -130,111 +130,111 @@ static void wake_thread(int force) static int add_pvt(pvt_t *pvt) { - int r = 0; - - if (t38_state_list.thread_running) { - switch_mutex_lock(t38_state_list.mutex); - pvt->next = t38_state_list.head; - t38_state_list.head = pvt; - switch_mutex_unlock(t38_state_list.mutex); - r = 1; - wake_thread(0); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error launching thread\n"); - } + int r = 0; - return r; + if (t38_state_list.thread_running) { + switch_mutex_lock(t38_state_list.mutex); + pvt->next = t38_state_list.head; + t38_state_list.head = pvt; + switch_mutex_unlock(t38_state_list.mutex); + r = 1; + wake_thread(0); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error launching thread\n"); + } + + return r; } static int del_pvt(pvt_t *del_pvt) { - pvt_t *p, *l = NULL; - int r = 0; + pvt_t *p, *l = NULL; + int r = 0; - switch_mutex_lock(t38_state_list.mutex); + switch_mutex_lock(t38_state_list.mutex); - for (p = t38_state_list.head; p; p = p->next) { - if (p == del_pvt) { - if (l) { - l->next = p->next; - } else { - t38_state_list.head = p->next; - } - p->next = NULL; - r = 1; - break; - } + for (p = t38_state_list.head; p; p = p->next) { + if (p == del_pvt) { + if (l) { + l->next = p->next; + } else { + t38_state_list.head = p->next; + } + p->next = NULL; + r = 1; + break; + } + + l = p; + } - l = p; - } + switch_mutex_unlock(t38_state_list.mutex); - switch_mutex_unlock(t38_state_list.mutex); + wake_thread(0); - wake_thread(0); - - return r; + return r; } static void *SWITCH_THREAD_FUNC timer_thread_run(switch_thread_t *thread, void *obj) { - switch_timer_t timer = { 0 }; - pvt_t *pvt; - int samples = 160; - int ms = 20; + switch_timer_t timer = { 0 }; + pvt_t *pvt; + int samples = 160; + int ms = 20; - switch_mutex_lock(t38_state_list.mutex); - t38_state_list.thread_running = 1; - switch_mutex_unlock(t38_state_list.mutex); + switch_mutex_lock(t38_state_list.mutex); + t38_state_list.thread_running = 1; + switch_mutex_unlock(t38_state_list.mutex); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FAX timer thread started.\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FAX timer thread started.\n"); if (switch_core_timer_init(&timer, "soft", ms, samples, NULL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "timer init failed.\n"); - goto end; - } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "timer init failed.\n"); + goto end; + } - switch_mutex_lock(spandsp_globals.cond_mutex); + switch_mutex_lock(spandsp_globals.cond_mutex); - while(t38_state_list.thread_running) { + while(t38_state_list.thread_running) { - switch_mutex_lock(t38_state_list.mutex); + switch_mutex_lock(t38_state_list.mutex); - if (!t38_state_list.head) { - switch_mutex_unlock(t38_state_list.mutex); + if (!t38_state_list.head) { + switch_mutex_unlock(t38_state_list.mutex); switch_thread_cond_wait(spandsp_globals.cond, spandsp_globals.cond_mutex); - switch_core_timer_sync(&timer); - continue; - } + switch_core_timer_sync(&timer); + continue; + } - for (pvt = t38_state_list.head; pvt; pvt = pvt->next) { - if (pvt->udptl_state && pvt->session && switch_channel_ready(switch_core_session_get_channel(pvt->session))) { - t38_terminal_send_timeout(pvt->t38_state, samples); - } - } + for (pvt = t38_state_list.head; pvt; pvt = pvt->next) { + if (pvt->udptl_state && pvt->session && switch_channel_ready(switch_core_session_get_channel(pvt->session))) { + t38_terminal_send_timeout(pvt->t38_state, samples); + } + } - switch_mutex_unlock(t38_state_list.mutex); + switch_mutex_unlock(t38_state_list.mutex); - switch_core_timer_next(&timer); - } + switch_core_timer_next(&timer); + } + + switch_mutex_unlock(spandsp_globals.cond_mutex); - switch_mutex_unlock(spandsp_globals.cond_mutex); - end: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FAX timer thread ended.\n"); - - switch_mutex_lock(t38_state_list.mutex); - t38_state_list.thread_running = 0; - switch_mutex_unlock(t38_state_list.mutex); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FAX timer thread ended.\n"); - if (timer.timer_interface) { - switch_core_timer_destroy(&timer); - } - - return NULL; + switch_mutex_lock(t38_state_list.mutex); + t38_state_list.thread_running = 0; + switch_mutex_unlock(t38_state_list.mutex); + + if (timer.timer_interface) { + switch_core_timer_destroy(&timer); + } + + return NULL; } static void launch_timer_thread(void) @@ -472,8 +472,8 @@ static void phase_e_handler(t30_state_t *s, void *user_data, int result) char *fax_transfer_rate = NULL; char *fax_result_code = NULL; switch_event_t *event; - const char *var; - char *expanded; + const char *var; + char *expanded; pvt = (pvt_t *) user_data; switch_assert(pvt); @@ -590,80 +590,79 @@ static void phase_e_handler(t30_state_t *s, void *user_data, int result) switch_event_fire(&event); } - if ((var = switch_channel_get_variable(channel, "system_on_fax_result"))) { - expanded = switch_channel_expand_variables(channel, var); - switch_system(expanded, SWITCH_FALSE); - if (expanded != var) { - free(expanded); - } - } + if ((var = switch_channel_get_variable(channel, "system_on_fax_result"))) { + expanded = switch_channel_expand_variables(channel, var); + switch_system(expanded, SWITCH_FALSE); + if (expanded != var) { + free(expanded); + } + } - switch_channel_execute_on(channel, "execute_on_fax_result"); + switch_channel_execute_on(channel, "execute_on_fax_result"); - if (result == T30_ERR_OK) { - if ((var = switch_channel_get_variable(channel, "system_on_fax_success"))) { - expanded = switch_channel_expand_variables(channel, var); - switch_system(expanded, SWITCH_FALSE); - if (expanded != var) { - free(expanded); - } - } - switch_channel_execute_on(channel, "execute_on_fax_success"); - } else { - if ((var = switch_channel_get_variable(channel, "system_on_fax_failure"))) { - expanded = switch_channel_expand_variables(channel, var); - switch_system(expanded, SWITCH_FALSE); - if (expanded != var) { - free(expanded); - } - } - switch_channel_execute_on(channel, "execute_on_fax_failure"); - } - + if (result == T30_ERR_OK) { + if ((var = switch_channel_get_variable(channel, "system_on_fax_success"))) { + expanded = switch_channel_expand_variables(channel, var); + switch_system(expanded, SWITCH_FALSE); + if (expanded != var) { + free(expanded); + } + } + switch_channel_execute_on(channel, "execute_on_fax_success"); + } else { + if ((var = switch_channel_get_variable(channel, "system_on_fax_failure"))) { + expanded = switch_channel_expand_variables(channel, var); + switch_system(expanded, SWITCH_FALSE); + if (expanded != var) { + free(expanded); + } + } + switch_channel_execute_on(channel, "execute_on_fax_failure"); + } } static int t38_tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count) { - switch_frame_t out_frame = { 0 }; - switch_core_session_t *session; - pvt_t *pvt; - uint8_t pkt[LOCAL_FAX_MAX_DATAGRAM]; - int x; - int r = 0; + switch_frame_t out_frame = { 0 }; + switch_core_session_t *session; + pvt_t *pvt; + uint8_t pkt[LOCAL_FAX_MAX_DATAGRAM]; + int x; + int r = 0; - pvt = (pvt_t *) user_data; - session = pvt->session; + pvt = (pvt_t *) user_data; + session = pvt->session; - /* we need to build a real packet here and make write_frame.packet and write_frame.packetlen point to it */ - out_frame.flags = SFF_UDPTL_PACKET | SFF_PROXY_PACKET; - out_frame.packet = pkt; - if ((r = udptl_build_packet(pvt->udptl_state, pkt, buf, len)) > 0) { - out_frame.packetlen = r; - //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "WRITE %d udptl bytes\n", out_frame.packetlen); + /* we need to build a real packet here and make write_frame.packet and write_frame.packetlen point to it */ + out_frame.flags = SFF_UDPTL_PACKET | SFF_PROXY_PACKET; + out_frame.packet = pkt; + if ((r = udptl_build_packet(pvt->udptl_state, pkt, buf, len)) > 0) { + out_frame.packetlen = r; + //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "WRITE %d udptl bytes\n", out_frame.packetlen); - for (x = 0; x < count; x++) { - if (switch_core_session_write_frame(session, &out_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID WRITE: %d:%d\n", out_frame.packetlen, count); - r = -1; - break; - } - } - } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID PACKETLEN: %d PASSED: %d:%d\n", r, len, count); - } - - if (r < 0) { - t30_state_t *t30; + for (x = 0; x < count; x++) { + if (switch_core_session_write_frame(session, &out_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID WRITE: %d:%d\n", out_frame.packetlen, count); + r = -1; + break; + } + } + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "INVALID PACKETLEN: %d PASSED: %d:%d\n", r, len, count); + } - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "TERMINATING T30 STATE\n"); + if (r < 0) { + t30_state_t *t30; + + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "TERMINATING T30 STATE\n"); + + if (pvt->t38_state && (t30 = t38_terminal_get_t30_state(pvt->t38_state))) { + t30_terminate(t30); + } + switch_yield(10000); + } - if (pvt->t38_state && (t30 = t38_terminal_get_t30_state(pvt->t38_state))) { - t30_terminate(t30); - } - switch_yield(10000); - } - - return r < 0 ? r : 0; + return r < 0 ? r : 0; } static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) @@ -722,130 +721,130 @@ static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) } break; case T38_MODE: - { - switch_core_session_message_t msg = { 0 }; + { + switch_core_session_message_t msg = { 0 }; - if (pvt->t38_state == NULL) { - pvt->t38_state = (t38_terminal_state_t *) switch_core_session_alloc(pvt->session, sizeof(t38_terminal_state_t)); - } - if (pvt->t38_state == NULL) { - return SWITCH_STATUS_FALSE; - } - if (pvt->udptl_state == NULL) { - pvt->udptl_state = (udptl_state_t *) switch_core_session_alloc(pvt->session, sizeof(udptl_state_t)); - } - if (pvt->udptl_state == NULL) { - t38_terminal_free(pvt->t38_state); - pvt->t38_state = NULL; - return SWITCH_STATUS_FALSE; - } + if (pvt->t38_state == NULL) { + pvt->t38_state = (t38_terminal_state_t *) switch_core_session_alloc(pvt->session, sizeof(t38_terminal_state_t)); + } + if (pvt->t38_state == NULL) { + return SWITCH_STATUS_FALSE; + } + if (pvt->udptl_state == NULL) { + pvt->udptl_state = (udptl_state_t *) switch_core_session_alloc(pvt->session, sizeof(udptl_state_t)); + } + if (pvt->udptl_state == NULL) { + t38_terminal_free(pvt->t38_state); + pvt->t38_state = NULL; + return SWITCH_STATUS_FALSE; + } - t38 = pvt->t38_state; - t30 = t38_terminal_get_t30_state(t38); + t38 = pvt->t38_state; + t30 = t38_terminal_get_t30_state(t38); - memset(t38, 0, sizeof(t38_terminal_state_t)); + memset(t38, 0, sizeof(t38_terminal_state_t)); - if (t38_terminal_init(t38, pvt->caller, t38_tx_packet_handler, pvt) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my T.38 structs\n"); - return SWITCH_STATUS_FALSE; - } + if (t38_terminal_init(t38, pvt->caller, t38_tx_packet_handler, pvt) == NULL) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my T.38 structs\n"); + return SWITCH_STATUS_FALSE; + } - pvt->t38_core = t38_terminal_get_t38_core_state(pvt->t38_state); + pvt->t38_core = t38_terminal_get_t38_core_state(pvt->t38_state); - if (udptl_init(pvt->udptl_state, UDPTL_ERROR_CORRECTION_REDUNDANCY, fec_span, fec_entries, - (udptl_rx_packet_handler_t *) t38_core_rx_ifp_packet, (void *) pvt->t38_core) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my UDPTL structs\n"); - return SWITCH_STATUS_FALSE; - } + if (udptl_init(pvt->udptl_state, UDPTL_ERROR_CORRECTION_REDUNDANCY, fec_span, fec_entries, + (udptl_rx_packet_handler_t *) t38_core_rx_ifp_packet, (void *) pvt->t38_core) == NULL) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my UDPTL structs\n"); + return SWITCH_STATUS_FALSE; + } - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; - switch_core_session_receive_message(pvt->session, &msg); - - /* add to timer thread processing */ - if (!add_pvt(pvt)) { - if (channel) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - } - } - - span_log_set_message_handler(&t38->logging, spanfax_log_message, NULL); - span_log_set_message_handler(&t30->logging, spanfax_log_message, NULL); + msg.from = __FILE__; + msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; + switch_core_session_receive_message(pvt->session, &msg); - if (pvt->verbose) { - span_log_set_level(&t38->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - span_log_set_level(&t30->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - } - } - break; - case T38_GATEWAY_MODE: - if (pvt->t38_gateway_state == NULL) { - pvt->t38_gateway_state = (t38_gateway_state_t *) switch_core_session_alloc(pvt->session, sizeof(t38_gateway_state_t)); - } + /* add to timer thread processing */ + if (!add_pvt(pvt)) { + if (channel) { + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + } + } - if (pvt->udptl_state == NULL) { - pvt->udptl_state = (udptl_state_t *) switch_core_session_alloc(pvt->session, sizeof(udptl_state_t)); - } + span_log_set_message_handler(&t38->logging, spanfax_log_message, NULL); + span_log_set_message_handler(&t30->logging, spanfax_log_message, NULL); - if (t38_gateway_init(pvt->t38_gateway_state, t38_tx_packet_handler, pvt) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my T.38 structs\n"); - t38_gateway_free(pvt->t38_gateway_state); - pvt->t38_gateway_state = NULL; - - return SWITCH_STATUS_FALSE; - } + if (pvt->verbose) { + span_log_set_level(&t38->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); + span_log_set_level(&t30->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); + } + } + break; + case T38_GATEWAY_MODE: + if (pvt->t38_gateway_state == NULL) { + pvt->t38_gateway_state = (t38_gateway_state_t *) switch_core_session_alloc(pvt->session, sizeof(t38_gateway_state_t)); + } - pvt->t38_core = t38_gateway_get_t38_core_state(pvt->t38_gateway_state); + if (pvt->udptl_state == NULL) { + pvt->udptl_state = (udptl_state_t *) switch_core_session_alloc(pvt->session, sizeof(udptl_state_t)); + } - if (udptl_init(pvt->udptl_state, UDPTL_ERROR_CORRECTION_REDUNDANCY, fec_span, fec_entries, - (udptl_rx_packet_handler_t *) t38_core_rx_ifp_packet, (void *) pvt->t38_core) == NULL) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my UDPTL structs\n"); - t38_gateway_free(pvt->t38_gateway_state); - udptl_release(pvt->udptl_state); - pvt->udptl_state = NULL; - return SWITCH_STATUS_FALSE; - } + if (t38_gateway_init(pvt->t38_gateway_state, t38_tx_packet_handler, pvt) == NULL) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my T.38 structs\n"); + t38_gateway_free(pvt->t38_gateway_state); + pvt->t38_gateway_state = NULL; + + return SWITCH_STATUS_FALSE; + } - t38_gateway_set_transmit_on_idle(pvt->t38_gateway_state, TRUE); + pvt->t38_core = t38_gateway_get_t38_core_state(pvt->t38_gateway_state); - if (switch_true(switch_channel_get_variable(channel, "fax_v17_disabled"))) { - t38_gateway_set_supported_modems(pvt->t38_gateway_state, T30_SUPPORT_V29 | T30_SUPPORT_V27TER); - } else { - t38_gateway_set_supported_modems(pvt->t38_gateway_state, T30_SUPPORT_V17 | T30_SUPPORT_V29 | T30_SUPPORT_V27TER); - } + if (udptl_init(pvt->udptl_state, UDPTL_ERROR_CORRECTION_REDUNDANCY, fec_span, fec_entries, + (udptl_rx_packet_handler_t *) t38_core_rx_ifp_packet, (void *) pvt->t38_core) == NULL) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot initialize my UDPTL structs\n"); + t38_gateway_free(pvt->t38_gateway_state); + udptl_release(pvt->udptl_state); + pvt->udptl_state = NULL; + return SWITCH_STATUS_FALSE; + } - t38_gateway_set_ecm_capability(pvt->t38_gateway_state, pvt->use_ecm); - switch_channel_set_variable(channel, "fax_ecm_requested", pvt->use_ecm ? "true" : "false"); - - if (switch_true(switch_channel_get_variable(channel, "FAX_DISABLE_ECM"))) { - t38_gateway_set_ecm_capability(pvt->t38_gateway_state, FALSE); - } else { - t38_gateway_set_ecm_capability(pvt->t38_gateway_state, TRUE); - } - + t38_gateway_set_transmit_on_idle(pvt->t38_gateway_state, TRUE); - span_log_set_message_handler(&pvt->t38_gateway_state->logging, spanfax_log_message, NULL); - span_log_set_message_handler(&pvt->t38_core->logging, spanfax_log_message, NULL); + if (switch_true(switch_channel_get_variable(channel, "fax_v17_disabled"))) { + t38_gateway_set_supported_modems(pvt->t38_gateway_state, T30_SUPPORT_V29 | T30_SUPPORT_V27TER); + } else { + t38_gateway_set_supported_modems(pvt->t38_gateway_state, T30_SUPPORT_V17 | T30_SUPPORT_V29 | T30_SUPPORT_V27TER); + } - if (pvt->verbose) { - span_log_set_level(&pvt->t38_gateway_state->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - span_log_set_level(&pvt->t38_core->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); - } + t38_gateway_set_ecm_capability(pvt->t38_gateway_state, pvt->use_ecm); + switch_channel_set_variable(channel, "fax_ecm_requested", pvt->use_ecm ? "true" : "false"); - t38_set_t38_version(pvt->t38_core, 0); - t38_gateway_set_ecm_capability(pvt->t38_gateway_state, 1); + if (switch_true(switch_channel_get_variable(channel, "FAX_DISABLE_ECM"))) { + t38_gateway_set_ecm_capability(pvt->t38_gateway_state, FALSE); + } else { + t38_gateway_set_ecm_capability(pvt->t38_gateway_state, TRUE); + } - return SWITCH_STATUS_SUCCESS; + + span_log_set_message_handler(&pvt->t38_gateway_state->logging, spanfax_log_message, NULL); + span_log_set_message_handler(&pvt->t38_core->logging, spanfax_log_message, NULL); + + if (pvt->verbose) { + span_log_set_level(&pvt->t38_gateway_state->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); + span_log_set_level(&pvt->t38_core->logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); + } + + t38_set_t38_version(pvt->t38_core, 0); + t38_gateway_set_ecm_capability(pvt->t38_gateway_state, 1); + + return SWITCH_STATUS_SUCCESS; default: assert(0); /* What? */ return SWITCH_STATUS_SUCCESS; } /* Switch trans mode */ - + /* All the things which are common to audio and T.38 FAX setup */ t30_set_tx_ident(t30, pvt->ident); t30_set_tx_page_header_info(t30, pvt->header); - if (pvt->timezone && pvt->timezone[0]) + if (pvt->timezone && pvt->timezone[0]) t30_set_tx_page_header_tz(t30, pvt->timezone); t30_set_phase_e_handler(t30, phase_e_handler, pvt); @@ -891,7 +890,7 @@ static switch_status_t spanfax_destroy(pvt_t *pvt) int terminate; t30_state_t *t30; - if (!pvt) return SWITCH_STATUS_FALSE; + if (!pvt) return SWITCH_STATUS_FALSE; if (pvt->fax_state) { if (pvt->t38_state) { @@ -910,8 +909,8 @@ static switch_status_t spanfax_destroy(pvt_t *pvt) if (pvt->t38_state) { - /* remove from timer thread processing */ - del_pvt(pvt); + /* remove from timer thread processing */ + del_pvt(pvt); if (pvt->t38_state) { terminate = 1; @@ -928,135 +927,135 @@ static switch_status_t spanfax_destroy(pvt_t *pvt) t38_terminal_release(pvt->t38_state); } - if (pvt->t38_gateway_state) { - t38_gateway_release(pvt->t38_gateway_state); - } + if (pvt->t38_gateway_state) { + t38_gateway_release(pvt->t38_gateway_state); + } if (pvt->udptl_state) { udptl_release(pvt->udptl_state); - } + } return SWITCH_STATUS_SUCCESS; } static t38_mode_t configure_t38(pvt_t *pvt) { - switch_core_session_t *session = pvt->session; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_t38_options_t *t38_options = switch_channel_get_private(channel, "t38_options"); - int method = 2; + switch_core_session_t *session = pvt->session; + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_t38_options_t *t38_options = switch_channel_get_private(channel, "t38_options"); + int method = 2; - if (!t38_options || !pvt || !pvt->t38_core) { - pvt->t38_mode = T38_MODE_REFUSED; - return pvt->t38_mode; - } + if (!t38_options || !pvt || !pvt->t38_core) { + pvt->t38_mode = T38_MODE_REFUSED; + return pvt->t38_mode; + } - t38_set_t38_version(pvt->t38_core, t38_options->T38FaxVersion); - t38_set_max_buffer_size(pvt->t38_core, t38_options->T38FaxMaxBuffer); - t38_set_fastest_image_data_rate(pvt->t38_core, t38_options->T38MaxBitRate); - t38_set_fill_bit_removal(pvt->t38_core, t38_options->T38FaxFillBitRemoval); - t38_set_mmr_transcoding(pvt->t38_core, t38_options->T38FaxTranscodingMMR); - t38_set_jbig_transcoding(pvt->t38_core, t38_options->T38FaxTranscodingJBIG); - t38_set_max_datagram_size(pvt->t38_core, t38_options->T38FaxMaxDatagram); + t38_set_t38_version(pvt->t38_core, t38_options->T38FaxVersion); + t38_set_max_buffer_size(pvt->t38_core, t38_options->T38FaxMaxBuffer); + t38_set_fastest_image_data_rate(pvt->t38_core, t38_options->T38MaxBitRate); + t38_set_fill_bit_removal(pvt->t38_core, t38_options->T38FaxFillBitRemoval); + t38_set_mmr_transcoding(pvt->t38_core, t38_options->T38FaxTranscodingMMR); + t38_set_jbig_transcoding(pvt->t38_core, t38_options->T38FaxTranscodingJBIG); + t38_set_max_datagram_size(pvt->t38_core, t38_options->T38FaxMaxDatagram); - if (t38_options->T38FaxRateManagement) { - if (!strcasecmp(t38_options->T38FaxRateManagement, "transferredTCF")) { - method = 2; - } else { - method = 1; - } - } + if (t38_options->T38FaxRateManagement) { + if (!strcasecmp(t38_options->T38FaxRateManagement, "transferredTCF")) { + method = 2; + } else { + method = 1; + } + } - t38_set_data_rate_management_method(pvt->t38_core, method); + t38_set_data_rate_management_method(pvt->t38_core, method); - //t38_set_data_transport_protocol(pvt->t38_core, int data_transport_protocol); - //t38_set_redundancy_control(pvt->t38_core, int category, int setting); + //t38_set_data_transport_protocol(pvt->t38_core, int data_transport_protocol); + //t38_set_redundancy_control(pvt->t38_core, int category, int setting); - return pvt->t38_mode; + return pvt->t38_mode; } static t38_mode_t negotiate_t38(pvt_t *pvt) { - switch_core_session_t *session = pvt->session; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_core_session_message_t msg = { 0 }; - switch_t38_options_t *t38_options = switch_channel_get_private(channel, "t38_options"); - int enabled = 0, insist = 0; - const char *v; + switch_core_session_t *session = pvt->session; + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_core_session_message_t msg = { 0 }; + switch_t38_options_t *t38_options = switch_channel_get_private(channel, "t38_options"); + int enabled = 0, insist = 0; + const char *v; - pvt->t38_mode = T38_MODE_REFUSED; + pvt->t38_mode = T38_MODE_REFUSED; - if (pvt->app_mode == FUNCTION_GW) { - enabled = 1; - } else if ((v = switch_channel_get_variable(channel, "fax_enable_t38"))) { - enabled = switch_true(v); - } else { - enabled = spandsp_globals.enable_t38; - } + if (pvt->app_mode == FUNCTION_GW) { + enabled = 1; + } else if ((v = switch_channel_get_variable(channel, "fax_enable_t38"))) { + enabled = switch_true(v); + } else { + enabled = spandsp_globals.enable_t38; + } - if (!(enabled && t38_options)) { - /* if there is no t38_options the endpoint will refuse the transition */ - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s NO T38 options detected.\n", switch_channel_get_name(channel)); - switch_channel_set_private(channel, "t38_options", NULL); - } else { - pvt->t38_mode = T38_MODE_NEGOTIATED; - switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_NEGOTIATED); + if (!(enabled && t38_options)) { + /* if there is no t38_options the endpoint will refuse the transition */ + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s NO T38 options detected.\n", switch_channel_get_name(channel)); + switch_channel_set_private(channel, "t38_options", NULL); + } else { + pvt->t38_mode = T38_MODE_NEGOTIATED; + switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_NEGOTIATED); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38 SDP Origin = %s\n", t38_options->sdp_o_line); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxVersion = %d\n", t38_options->T38FaxVersion); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38MaxBitRate = %d\n", t38_options->T38MaxBitRate); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxFillBitRemoval = %d\n", t38_options->T38FaxFillBitRemoval); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxTranscodingMMR = %d\n", t38_options->T38FaxTranscodingMMR); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxTranscodingJBIG = %d\n", t38_options->T38FaxTranscodingJBIG); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxRateManagement = '%s'\n", t38_options->T38FaxRateManagement); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxMaxBuffer = %d\n", t38_options->T38FaxMaxBuffer); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxMaxDatagram = %d\n", t38_options->T38FaxMaxDatagram); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxUdpEC = '%s'\n", t38_options->T38FaxUdpEC); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38VendorInfo = '%s'\n", switch_str_nil(t38_options->T38VendorInfo)); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "ip = '%s'\n", - t38_options->remote_ip ? t38_options->remote_ip : "Not specified"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "port = %d\n", t38_options->remote_port); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38 SDP Origin = %s\n", t38_options->sdp_o_line); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxVersion = %d\n", t38_options->T38FaxVersion); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38MaxBitRate = %d\n", t38_options->T38MaxBitRate); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxFillBitRemoval = %d\n", t38_options->T38FaxFillBitRemoval); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxTranscodingMMR = %d\n", t38_options->T38FaxTranscodingMMR); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxTranscodingJBIG = %d\n", t38_options->T38FaxTranscodingJBIG); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxRateManagement = '%s'\n", t38_options->T38FaxRateManagement); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxMaxBuffer = %d\n", t38_options->T38FaxMaxBuffer); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxMaxDatagram = %d\n", t38_options->T38FaxMaxDatagram); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38FaxUdpEC = '%s'\n", t38_options->T38FaxUdpEC); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "T38VendorInfo = '%s'\n", switch_str_nil(t38_options->T38VendorInfo)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "ip = '%s'\n", + t38_options->remote_ip ? t38_options->remote_ip : "Not specified"); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "port = %d\n", t38_options->remote_port); - /* Time to practice our negotiating skills, by editing the t38_options */ + /* Time to practice our negotiating skills, by editing the t38_options */ - if (t38_options->T38FaxVersion > 3) { - t38_options->T38FaxVersion = 3; - } - t38_options->T38MaxBitRate = (pvt->disable_v17) ? 9600 : 14400; + if (t38_options->T38FaxVersion > 3) { + t38_options->T38FaxVersion = 3; + } + t38_options->T38MaxBitRate = (pvt->disable_v17) ? 9600 : 14400; - /* cisco gets mad when we set this to one in a response where they set it to 0, are we allowed to hardcode this to 1 on responses? */ - /* - if (!zstr(t38_options->sdp_o_line) && !switch_stristr("cisco", t38_options->sdp_o_line)) { - t38_options->T38FaxFillBitRemoval = 1; - } - */ + /* cisco gets mad when we set this to one in a response where they set it to 0, are we allowed to hardcode this to 1 on responses? */ + /* + if (!zstr(t38_options->sdp_o_line) && !switch_stristr("cisco", t38_options->sdp_o_line)) { + t38_options->T38FaxFillBitRemoval = 1; + } + */ - t38_options->T38FaxTranscodingMMR = 0; - t38_options->T38FaxTranscodingJBIG = 0; - t38_options->T38FaxRateManagement = "transferredTCF"; - t38_options->T38FaxMaxBuffer = 2000; - t38_options->T38FaxMaxDatagram = LOCAL_FAX_MAX_DATAGRAM; - if (!zstr(t38_options->T38FaxUdpEC) && - (strcasecmp(t38_options->T38FaxUdpEC, "t38UDPRedundancy") == 0 || - strcasecmp(t38_options->T38FaxUdpEC, "t38UDPFEC") == 0)) { - t38_options->T38FaxUdpEC = "t38UDPRedundancy"; - } else { - t38_options->T38FaxUdpEC = NULL; - } - t38_options->T38VendorInfo = "0 0 0"; - } + t38_options->T38FaxTranscodingMMR = 0; + t38_options->T38FaxTranscodingJBIG = 0; + t38_options->T38FaxRateManagement = "transferredTCF"; + t38_options->T38FaxMaxBuffer = 2000; + t38_options->T38FaxMaxDatagram = LOCAL_FAX_MAX_DATAGRAM; + if (!zstr(t38_options->T38FaxUdpEC) && + (strcasecmp(t38_options->T38FaxUdpEC, "t38UDPRedundancy") == 0 || + strcasecmp(t38_options->T38FaxUdpEC, "t38UDPFEC") == 0)) { + t38_options->T38FaxUdpEC = "t38UDPRedundancy"; + } else { + t38_options->T38FaxUdpEC = NULL; + } + t38_options->T38VendorInfo = "0 0 0"; + } - if ((v = switch_channel_get_variable(channel, "fax_enable_t38_insist"))) { - insist = switch_true(v); - } else { - insist = spandsp_globals.enable_t38_insist; - } + if ((v = switch_channel_get_variable(channel, "fax_enable_t38_insist"))) { + insist = switch_true(v); + } else { + insist = spandsp_globals.enable_t38_insist; + } - /* This will send the options back in a response */ - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_T38_DESCRIPTION; - msg.numeric_arg = insist; - switch_core_session_receive_message(session, &msg); + /* This will send the options back in a response */ + msg.from = __FILE__; + msg.message_id = SWITCH_MESSAGE_INDICATE_T38_DESCRIPTION; + msg.numeric_arg = insist; + switch_core_session_receive_message(session, &msg); return pvt->t38_mode; } @@ -1065,68 +1064,68 @@ static t38_mode_t negotiate_t38(pvt_t *pvt) static t38_mode_t request_t38(pvt_t *pvt) { - switch_core_session_t *session = pvt->session; - switch_channel_t *channel = switch_core_session_get_channel(session); - switch_core_session_message_t msg = { 0 }; - switch_t38_options_t *t38_options = NULL; - int enabled = 0, insist = 0; - const char *v; + switch_core_session_t *session = pvt->session; + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_core_session_message_t msg = { 0 }; + switch_t38_options_t *t38_options = NULL; + int enabled = 0, insist = 0; + const char *v; - pvt->t38_mode = T38_MODE_UNKNOWN; + pvt->t38_mode = T38_MODE_UNKNOWN; - if (pvt->app_mode == FUNCTION_GW) { - enabled = 1; - } else if ((v = switch_channel_get_variable(channel, "fax_enable_t38"))) { - enabled = switch_true(v); - } else { - enabled = spandsp_globals.enable_t38; - } + if (pvt->app_mode == FUNCTION_GW) { + enabled = 1; + } else if ((v = switch_channel_get_variable(channel, "fax_enable_t38"))) { + enabled = switch_true(v); + } else { + enabled = spandsp_globals.enable_t38; + } - if (enabled) { - if ((v = switch_channel_get_variable(channel, "fax_enable_t38_request"))) { - enabled = switch_true(v); - } else { - enabled = spandsp_globals.enable_t38_request; - } - } + if (enabled) { + if ((v = switch_channel_get_variable(channel, "fax_enable_t38_request"))) { + enabled = switch_true(v); + } else { + enabled = spandsp_globals.enable_t38_request; + } + } - if ((v = switch_channel_get_variable(channel, "fax_enable_t38_insist"))) { - insist = switch_true(v); - } else { - insist = spandsp_globals.enable_t38_insist; - } + if ((v = switch_channel_get_variable(channel, "fax_enable_t38_insist"))) { + insist = switch_true(v); + } else { + insist = spandsp_globals.enable_t38_insist; + } - if ((t38_options = switch_channel_get_private(channel, "t38_options"))) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, - "%s already has T.38 data\n", switch_channel_get_name(channel)); - enabled = 0; - } + if ((t38_options = switch_channel_get_private(channel, "t38_options"))) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, + "%s already has T.38 data\n", switch_channel_get_name(channel)); + enabled = 0; + } - if (enabled) { - t38_options = switch_core_session_alloc(session, sizeof(*t38_options)); - - t38_options->T38MaxBitRate = (pvt->disable_v17) ? 9600 : 14400; - t38_options->T38FaxVersion = 0; - t38_options->T38FaxFillBitRemoval = 1; - t38_options->T38FaxTranscodingMMR = 0; - t38_options->T38FaxTranscodingJBIG = 0; - t38_options->T38FaxRateManagement = "transferredTCF"; - t38_options->T38FaxMaxBuffer = 2000; - t38_options->T38FaxMaxDatagram = LOCAL_FAX_MAX_DATAGRAM; - t38_options->T38FaxUdpEC = "t38UDPRedundancy"; - t38_options->T38VendorInfo = "0 0 0"; - - switch_channel_set_private(channel, "t38_options", t38_options); - pvt->t38_mode = T38_MODE_REQUESTED; - switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_REQ); + if (enabled) { + t38_options = switch_core_session_alloc(session, sizeof(*t38_options)); - /* This will send a request for t.38 mode */ - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_REQUEST_IMAGE_MEDIA; - msg.numeric_arg = insist; - switch_core_session_receive_message(session, &msg); - } + t38_options->T38MaxBitRate = (pvt->disable_v17) ? 9600 : 14400; + t38_options->T38FaxVersion = 0; + t38_options->T38FaxFillBitRemoval = 1; + t38_options->T38FaxTranscodingMMR = 0; + t38_options->T38FaxTranscodingJBIG = 0; + t38_options->T38FaxRateManagement = "transferredTCF"; + t38_options->T38FaxMaxBuffer = 2000; + t38_options->T38FaxMaxDatagram = LOCAL_FAX_MAX_DATAGRAM; + t38_options->T38FaxUdpEC = "t38UDPRedundancy"; + t38_options->T38VendorInfo = "0 0 0"; + + switch_channel_set_private(channel, "t38_options", t38_options); + pvt->t38_mode = T38_MODE_REQUESTED; + switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_REQ); + + /* This will send a request for t.38 mode */ + msg.from = __FILE__; + msg.message_id = SWITCH_MESSAGE_INDICATE_REQUEST_IMAGE_MEDIA; + msg.numeric_arg = insist; + switch_core_session_receive_message(session, &msg); + } return pvt->t38_mode; } @@ -1137,9 +1136,9 @@ static t38_mode_t request_t38(pvt_t *pvt) static pvt_t *pvt_init(switch_core_session_t *session, mod_spandsp_fax_application_mode_t app_mode) { - switch_channel_t *channel; - pvt_t *pvt = NULL; - const char *tmp; + switch_channel_t *channel; + pvt_t *pvt = NULL; + const char *tmp; /* Make sure we have a valid channel when starting the FAX application */ channel = switch_core_session_get_channel(session); @@ -1151,25 +1150,25 @@ static pvt_t *pvt_init(switch_core_session_t *session, mod_spandsp_fax_applicati /* Allocate our structs */ pvt = switch_core_session_alloc(session, sizeof(pvt_t)); - pvt->session = session; + pvt->session = session; - pvt->app_mode = app_mode; + pvt->app_mode = app_mode; - pvt->tx_page_start = -1; - pvt->tx_page_end = -1; + pvt->tx_page_start = -1; + pvt->tx_page_end = -1; - switch(pvt->app_mode) { + switch(pvt->app_mode) { - case FUNCTION_TX: - pvt->caller = 1; - break; - case FUNCTION_RX: - pvt->caller = 0; - break; - case FUNCTION_GW: - break; - } + case FUNCTION_TX: + pvt->caller = 1; + break; + case FUNCTION_RX: + pvt->caller = 0; + break; + case FUNCTION_GW: + break; + } /* Retrieving our settings from the channel variables */ @@ -1200,37 +1199,37 @@ static pvt_t *pvt_init(switch_core_session_t *session, mod_spandsp_fax_applicati } if ((tmp = switch_channel_get_variable(channel, "fax_ident"))) { - char *data = NULL; + char *data = NULL; - data = strdup(tmp); - switch_url_decode(data); + data = strdup(tmp); + switch_url_decode(data); pvt->ident = switch_core_session_strdup(session, data); - switch_safe_free(data); + switch_safe_free(data); } else { pvt->ident = switch_core_session_strdup(session, spandsp_globals.ident); } if ((tmp = switch_channel_get_variable(channel, "fax_header"))) { - char *data = NULL; + char *data = NULL; - data = strdup(tmp); - switch_url_decode(data); - pvt->header = switch_core_session_strdup(session, data); + data = strdup(tmp); + switch_url_decode(data); + pvt->header = switch_core_session_strdup(session, data); - switch_safe_free(data); + switch_safe_free(data); } else { pvt->header = switch_core_session_strdup(session, spandsp_globals.header); } if ((tmp = switch_channel_get_variable(channel, "fax_timezone"))) { - char *data = NULL; + char *data = NULL; - data = strdup(tmp); - switch_url_decode(data); - pvt->timezone = switch_core_session_strdup(session, data); + data = strdup(tmp); + switch_url_decode(data); + pvt->timezone = switch_core_session_strdup(session, data); - switch_safe_free(data); + switch_safe_free(data); } else { pvt->timezone = switch_core_session_strdup(session, spandsp_globals.timezone); } @@ -1255,9 +1254,9 @@ static pvt_t *pvt_init(switch_core_session_t *session, mod_spandsp_fax_applicati if ((pvt->tx_page_end < pvt->tx_page_start) && (pvt->tx_page_end != -1)) { pvt->tx_page_end = pvt->tx_page_start; } - } + } - return pvt; + return pvt; } void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *data, mod_spandsp_fax_application_mode_t app_mode) @@ -1270,15 +1269,15 @@ void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *dat switch_frame_t write_frame = { 0 }; switch_codec_implementation_t read_impl = { 0 }; int16_t *buf = NULL; - uint32_t req_counter = 0; + uint32_t req_counter = 0; switch_core_session_get_read_impl(session, &read_impl); counter_increment(); - - pvt = pvt_init(session, app_mode); - + + pvt = pvt_init(session, app_mode); + buf = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE); @@ -1327,7 +1326,7 @@ void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *dat return; } - /* + /* Note: Disable echocan on the channel, remember to call app "disable_ec" in the dialplan before invoking fax applications */ @@ -1381,11 +1380,11 @@ void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *dat switch_ivr_sleep(session, 250, SWITCH_TRUE, NULL); - if (pvt->app_mode == FUNCTION_TX) { - req_counter = 100; - } else { - req_counter = 50; - } + if (pvt->app_mode == FUNCTION_TX) { + req_counter = 100; + } else { + req_counter = 50; + } while (switch_channel_ready(channel)) { int tx = 0; @@ -1400,7 +1399,7 @@ void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *dat - call t38_terminal_send_timeout(), sleep for a while The T.38 stuff can be placed here (and the audio stuff can be skipped) - */ + */ /* read new audio frame from the channel */ status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); @@ -1410,72 +1409,72 @@ void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *dat goto done; } - switch (pvt->t38_mode) { - case T38_MODE_REQUESTED: - { - if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38_FAIL)) { - pvt->t38_mode = T38_MODE_REFUSED; - continue; - } else if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - switch_core_session_message_t msg = { 0 }; - pvt->t38_mode = T38_MODE_NEGOTIATED; - switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_NEGOTIATED); - spanfax_init(pvt, T38_MODE); - configure_t38(pvt); - - /* This will change the rtp stack to udptl mode */ - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; - switch_core_session_receive_message(session, &msg); - } - continue; - } - break; - case T38_MODE_UNKNOWN: - { - if (req_counter) { - if (!--req_counter) { - /* If you have the means, I highly recommend picking one up. ...*/ - request_t38(pvt); - } - } - - if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - if (negotiate_t38(pvt) == T38_MODE_NEGOTIATED) { - /* is is safe to call this again, it was already called above in AUDIO_MODE */ - /* but this is the only way to set up the t38 stuff */ - spanfax_init(pvt, T38_MODE); - continue; - } - } - } - break; - case T38_MODE_NEGOTIATED: - { - /* do what we need to do when we are in t38 mode */ - if (switch_test_flag(read_frame, SFF_CNG)) { - /* dunno what to do, most likely you will not get too many of these since we turn off the timer in udptl mode */ - continue; - } - - if (switch_test_flag(read_frame, SFF_UDPTL_PACKET)) { - /* now we know we can cast frame->packet to a udptl structure */ - //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "READ %d udptl bytes\n", read_frame->packetlen); - - udptl_rx_packet(pvt->udptl_state, read_frame->packet, read_frame->packetlen); - } - } - continue; - default: - break; - } + switch (pvt->t38_mode) { + case T38_MODE_REQUESTED: + { + if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38_FAIL)) { + pvt->t38_mode = T38_MODE_REFUSED; + continue; + } else if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { + switch_core_session_message_t msg = { 0 }; + pvt->t38_mode = T38_MODE_NEGOTIATED; + switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_NEGOTIATED); + spanfax_init(pvt, T38_MODE); + configure_t38(pvt); + + /* This will change the rtp stack to udptl mode */ + msg.from = __FILE__; + msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; + switch_core_session_receive_message(session, &msg); + } + continue; + } + break; + case T38_MODE_UNKNOWN: + { + if (req_counter) { + if (!--req_counter) { + /* If you have the means, I highly recommend picking one up. ...*/ + request_t38(pvt); + } + } + + if (switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { + if (negotiate_t38(pvt) == T38_MODE_NEGOTIATED) { + /* is is safe to call this again, it was already called above in AUDIO_MODE */ + /* but this is the only way to set up the t38 stuff */ + spanfax_init(pvt, T38_MODE); + continue; + } + } + } + break; + case T38_MODE_NEGOTIATED: + { + /* do what we need to do when we are in t38 mode */ + if (switch_test_flag(read_frame, SFF_CNG)) { + /* dunno what to do, most likely you will not get too many of these since we turn off the timer in udptl mode */ + continue; + } + + if (switch_test_flag(read_frame, SFF_UDPTL_PACKET)) { + /* now we know we can cast frame->packet to a udptl structure */ + //switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "READ %d udptl bytes\n", read_frame->packetlen); + + udptl_rx_packet(pvt->udptl_state, read_frame->packet, read_frame->packetlen); + } + } + continue; + default: + break; + } if (switch_test_flag(read_frame, SFF_CNG)) { /* We have no real signal data for the FAX software, but we have a space in time if we have a CNG indication. Do a fill-in operation in the FAX machine, to keep things rolling along. */ if (fax_rx_fillin(pvt->fax_state, read_impl.samples_per_packet)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fax_rx_fillin reported an error\n"); - continue; + continue; } } else { /* Pass the new incoming audio frame to the fax_rx function */ @@ -1524,30 +1523,30 @@ void mod_spandsp_fax_process_fax(switch_core_session_t *session, const char *dat void mod_spandsp_fax_load(switch_memory_pool_t *pool) { - uint32_t sanity = 200; + uint32_t sanity = 200; - memset(&t38_state_list, 0, sizeof(t38_state_list)); + memset(&t38_state_list, 0, sizeof(t38_state_list)); switch_mutex_init(&spandsp_globals.mutex, SWITCH_MUTEX_NESTED, spandsp_globals.pool); switch_mutex_init(&t38_state_list.mutex, SWITCH_MUTEX_NESTED, spandsp_globals.pool); switch_mutex_init(&spandsp_globals.cond_mutex, SWITCH_MUTEX_NESTED, spandsp_globals.pool); switch_thread_cond_create(&spandsp_globals.cond, spandsp_globals.pool); - - launch_timer_thread(); - while(--sanity && !t38_state_list.thread_running) { - switch_yield(20000); - } + launch_timer_thread(); + + while(--sanity && !t38_state_list.thread_running) { + switch_yield(20000); + } } void mod_spandsp_fax_shutdown(void) { - switch_status_t tstatus = SWITCH_STATUS_SUCCESS; + switch_status_t tstatus = SWITCH_STATUS_SUCCESS; - t38_state_list.thread_running = 0; - wake_thread(1); - switch_thread_join(&tstatus, t38_state_list.thread); + t38_state_list.thread_running = 0; + wake_thread(1); + switch_thread_join(&tstatus, t38_state_list.thread); memset(&spandsp_globals, 0, sizeof(spandsp_globals)); } @@ -1555,83 +1554,83 @@ static const switch_state_handler_table_t t38_gateway_state_handlers; static switch_status_t t38_gateway_on_soft_execute(switch_core_session_t *session) { - switch_core_session_t *other_session; + switch_core_session_t *other_session; - switch_channel_t *other_channel, *channel = switch_core_session_get_channel(session); - pvt_t *pvt; - const char *peer_uuid = switch_channel_get_variable(channel, "t38_peer"); - switch_core_session_message_t msg = { 0 }; - switch_status_t status; - switch_frame_t *read_frame = { 0 }; + switch_channel_t *other_channel, *channel = switch_core_session_get_channel(session); + pvt_t *pvt; + const char *peer_uuid = switch_channel_get_variable(channel, "t38_peer"); + switch_core_session_message_t msg = { 0 }; + switch_status_t status; + switch_frame_t *read_frame = { 0 }; - if (!(other_session = switch_core_session_locate(peer_uuid))) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Cannot locate channel with uuid %s", - switch_channel_get_name(channel), peer_uuid); - goto end; - } + if (!(other_session = switch_core_session_locate(peer_uuid))) { + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Cannot locate channel with uuid %s", + switch_channel_get_name(channel), peer_uuid); + goto end; + } - other_channel = switch_core_session_get_channel(other_session); + other_channel = switch_core_session_get_channel(other_session); - pvt = pvt_init(session, FUNCTION_GW); - request_t38(pvt); + pvt = pvt_init(session, FUNCTION_GW); + request_t38(pvt); - msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; - msg.from = __FILE__; - msg.string_arg = peer_uuid; - switch_core_session_receive_message(session, &msg); + msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; + msg.from = __FILE__; + msg.string_arg = peer_uuid; + switch_core_session_receive_message(session, &msg); - while (switch_channel_ready(channel) && switch_channel_up(other_channel) && !switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { + while (switch_channel_ready(channel) && switch_channel_up(other_channel) && !switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); if (!SWITCH_READ_ACCEPTABLE(status) || pvt->done) { /* Our duty is over */ - goto end_unlock; + goto end_unlock; } - if (switch_test_flag(read_frame, SFF_CNG)) { - continue; - } + if (switch_test_flag(read_frame, SFF_CNG)) { + continue; + } - if (switch_core_session_write_frame(other_session, read_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - goto end_unlock; - } - } + if (switch_core_session_write_frame(other_session, read_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { + goto end_unlock; + } + } if (!(switch_channel_ready(channel) && switch_channel_up(other_channel))) { - goto end_unlock; - } + goto end_unlock; + } - if (!switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Could not negotiate T38\n", switch_channel_get_name(channel)); - goto end_unlock; - } + if (!switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Could not negotiate T38\n", switch_channel_get_name(channel)); + goto end_unlock; + } - if (pvt->t38_mode == T38_MODE_REQUESTED) { - spanfax_init(pvt, T38_GATEWAY_MODE); - configure_t38(pvt); - pvt->t38_mode = T38_MODE_NEGOTIATED; - switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_NEGOTIATED); - } else { - if (negotiate_t38(pvt) != T38_MODE_NEGOTIATED) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Could not negotiate T38\n", switch_channel_get_name(channel)); - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end_unlock; - } - switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_NEGOTIATED); - spanfax_init(pvt, T38_GATEWAY_MODE); - } + if (pvt->t38_mode == T38_MODE_REQUESTED) { + spanfax_init(pvt, T38_GATEWAY_MODE); + configure_t38(pvt); + pvt->t38_mode = T38_MODE_NEGOTIATED; + switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_NEGOTIATED); + } else { + if (negotiate_t38(pvt) != T38_MODE_NEGOTIATED) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Could not negotiate T38\n", switch_channel_get_name(channel)); + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + goto end_unlock; + } + switch_channel_set_app_flag_key("T38", channel, CF_APP_T38_NEGOTIATED); + spanfax_init(pvt, T38_GATEWAY_MODE); + } - /* This will change the rtp stack to udptl mode */ - msg.from = __FILE__; - msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; - switch_core_session_receive_message(session, &msg); + /* This will change the rtp stack to udptl mode */ + msg.from = __FILE__; + msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; + switch_core_session_receive_message(session, &msg); - /* wake up the audio side */ - switch_channel_set_private(channel, "_t38_pvt", pvt); - switch_channel_set_app_flag_key("T38", other_channel, CF_APP_T38); + /* wake up the audio side */ + switch_channel_set_private(channel, "_t38_pvt", pvt); + switch_channel_set_app_flag_key("T38", other_channel, CF_APP_T38); while (switch_channel_ready(channel) && switch_channel_up(other_channel)) { @@ -1642,111 +1641,111 @@ static switch_status_t t38_gateway_on_soft_execute(switch_core_session_t *sessio /* Our duty is over */ goto end_unlock; } - - if (switch_test_flag(read_frame, SFF_CNG)) { - continue; - } - - if (switch_test_flag(read_frame, SFF_UDPTL_PACKET)) { - udptl_rx_packet(pvt->udptl_state, read_frame->packet, read_frame->packetlen); - } - } + + if (switch_test_flag(read_frame, SFF_CNG)) { + continue; + } + + if (switch_test_flag(read_frame, SFF_UDPTL_PACKET)) { + udptl_rx_packet(pvt->udptl_state, read_frame->packet, read_frame->packetlen); + } + } end_unlock: - msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; - msg.from = __FILE__; - msg.string_arg = peer_uuid; - switch_core_session_receive_message(session, &msg); + msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; + msg.from = __FILE__; + msg.string_arg = peer_uuid; + switch_core_session_receive_message(session, &msg); - switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING); - switch_core_session_rwunlock(other_session); + switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(other_session); end: - switch_channel_clear_state_handler(channel, &t38_gateway_state_handlers); - switch_channel_set_variable(channel, "t38_peer", NULL); + switch_channel_clear_state_handler(channel, &t38_gateway_state_handlers); + switch_channel_set_variable(channel, "t38_peer", NULL); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - return SWITCH_STATUS_SUCCESS; + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + return SWITCH_STATUS_SUCCESS; } static switch_status_t t38_gateway_on_consume_media(switch_core_session_t *session) { - switch_core_session_t *other_session; - switch_channel_t *other_channel, *channel = switch_core_session_get_channel(session); - const char *peer_uuid = switch_channel_get_variable(channel, "t38_peer"); - pvt_t *pvt = NULL; - switch_codec_t read_codec = { 0 }; + switch_core_session_t *other_session; + switch_channel_t *other_channel, *channel = switch_core_session_get_channel(session); + const char *peer_uuid = switch_channel_get_variable(channel, "t38_peer"); + pvt_t *pvt = NULL; + switch_codec_t read_codec = { 0 }; switch_codec_t write_codec = { 0 }; switch_frame_t *read_frame = { 0 }; switch_frame_t write_frame = { 0 }; switch_codec_implementation_t read_impl = { 0 }; int16_t *buf = NULL; - switch_status_t status; - int tx; - const char *t38_trace = switch_channel_get_variable(channel, "t38_trace"); - char *trace_read, *trace_write; - zap_socket_t read_fd = FAX_INVALID_SOCKET, write_fd = FAX_INVALID_SOCKET; - switch_core_session_message_t msg = { 0 }; - switch_event_t *event; + switch_status_t status; + int tx; + const char *t38_trace = switch_channel_get_variable(channel, "t38_trace"); + char *trace_read, *trace_write; + zap_socket_t read_fd = FAX_INVALID_SOCKET, write_fd = FAX_INVALID_SOCKET; + switch_core_session_message_t msg = { 0 }; + switch_event_t *event; switch_core_session_get_read_impl(session, &read_impl); - - buf = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE); - if (!(other_session = switch_core_session_locate(peer_uuid))) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end; - } + buf = switch_core_session_alloc(session, SWITCH_RECOMMENDED_BUFFER_SIZE); - other_channel = switch_core_session_get_channel(other_session); - - msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; - msg.from = __FILE__; - msg.string_arg = peer_uuid; - switch_core_session_receive_message(session, &msg); + if (!(other_session = switch_core_session_locate(peer_uuid))) { + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + goto end; + } + + other_channel = switch_core_session_get_channel(other_session); + + msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE; + msg.from = __FILE__; + msg.string_arg = peer_uuid; + switch_core_session_receive_message(session, &msg); if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_BRIDGE) == SWITCH_STATUS_SUCCESS) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session)); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", peer_uuid); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-A-Unique-ID", switch_core_session_get_uuid(session)); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Bridge-B-Unique-ID", peer_uuid); switch_channel_event_set_data(channel, event); switch_event_fire(&event); } - while (switch_channel_ready(channel) && switch_channel_up(other_channel) && !switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { + while (switch_channel_ready(channel) && switch_channel_up(other_channel) && !switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); - + if (!SWITCH_READ_ACCEPTABLE(status)) { /* Our duty is over */ goto end_unlock; } - if (switch_test_flag(read_frame, SFF_CNG)) { - continue; - } + if (switch_test_flag(read_frame, SFF_CNG)) { + continue; + } - if (switch_core_session_write_frame(other_session, read_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { - goto end_unlock; - } - } + if (switch_core_session_write_frame(other_session, read_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { + goto end_unlock; + } + } if (!(switch_channel_ready(channel) && switch_channel_up(other_channel))) { - goto end_unlock; - } + goto end_unlock; + } - if (!switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end_unlock; - } - - if (!(pvt = switch_channel_get_private(other_channel, "_t38_pvt"))) { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - goto end_unlock; - } - - if (switch_core_codec_init(&read_codec, + if (!switch_channel_test_app_flag_key("T38", channel, CF_APP_T38)) { + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + goto end_unlock; + } + + if (!(pvt = switch_channel_get_private(other_channel, "_t38_pvt"))) { + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + goto end_unlock; + } + + if (switch_core_codec_init(&read_codec, "L16", NULL, read_impl.samples_per_second, @@ -1781,27 +1780,27 @@ static switch_status_t t38_gateway_on_consume_media(switch_core_session_t *sessi switch_ivr_sleep(session, 0, SWITCH_TRUE, NULL); - if (switch_true(t38_trace)) { - trace_read = switch_core_session_sprintf(session, "%s%s%s_read.raw", SWITCH_GLOBAL_dirs.temp_dir, - SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)); + if (switch_true(t38_trace)) { + trace_read = switch_core_session_sprintf(session, "%s%s%s_read.raw", SWITCH_GLOBAL_dirs.temp_dir, + SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Tracing inbound audio to %s\n", trace_read); - switch_channel_set_variable(channel, "t38_trace_read", trace_read); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Tracing inbound audio to %s\n", trace_read); + switch_channel_set_variable(channel, "t38_trace_read", trace_read); - trace_write = switch_core_session_sprintf(session, "%s%s%s_write.raw", SWITCH_GLOBAL_dirs.temp_dir, - SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)); - - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Tracing outbound audio to %s\n", trace_write); - switch_channel_set_variable(channel, "t38_trace_read", trace_write); - + trace_write = switch_core_session_sprintf(session, "%s%s%s_write.raw", SWITCH_GLOBAL_dirs.temp_dir, + SWITCH_PATH_SEPARATOR, switch_core_session_get_uuid(session)); - if ((write_fd = open(trace_read, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) != FAX_INVALID_SOCKET) { - if ((read_fd = open(trace_write, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == FAX_INVALID_SOCKET) { - close(write_fd); - write_fd = FAX_INVALID_SOCKET; - } - } - } + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Tracing outbound audio to %s\n", trace_write); + switch_channel_set_variable(channel, "t38_trace_read", trace_write); + + + if ((write_fd = open(trace_read, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) != FAX_INVALID_SOCKET) { + if ((read_fd = open(trace_write, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == FAX_INVALID_SOCKET) { + close(write_fd); + write_fd = FAX_INVALID_SOCKET; + } + } + } while (switch_channel_ready(channel) && switch_channel_up(other_channel)) { status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); @@ -1811,16 +1810,16 @@ static switch_status_t t38_gateway_on_consume_media(switch_core_session_t *sessi goto end_unlock; } - if (switch_test_flag(read_frame, SFF_CNG)) { + if (switch_test_flag(read_frame, SFF_CNG)) { /* We have no real signal data for the FAX software, but we have a space in time if we have a CNG indication. Do a fill-in operation in the FAX machine, to keep things rolling along. */ - t38_gateway_rx_fillin(pvt->t38_gateway_state, read_impl.samples_per_packet); - } else { - if (read_fd != FAX_INVALID_SOCKET) { - switch_ssize_t rv; - do { rv = write(read_fd, read_frame->data, read_frame->datalen); } while (rv == -1 && errno == EINTR); - } - if (t38_gateway_rx(pvt->t38_gateway_state, (int16_t *) read_frame->data, read_frame->samples)) { + t38_gateway_rx_fillin(pvt->t38_gateway_state, read_impl.samples_per_packet); + } else { + if (read_fd != FAX_INVALID_SOCKET) { + switch_ssize_t rv; + do { rv = write(read_fd, read_frame->data, read_frame->datalen); } while (rv == -1 && errno == EINTR); + } + if (t38_gateway_rx(pvt->t38_gateway_state, (int16_t *) read_frame->data, read_frame->samples)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "fax_rx reported an error\n"); goto end_unlock; } @@ -1840,22 +1839,22 @@ static switch_status_t t38_gateway_on_consume_media(switch_core_session_t *sessi write_frame.samples = tx; } - if (write_fd != FAX_INVALID_SOCKET) { - switch_ssize_t rv; - do { rv = write(write_fd, write_frame.data, write_frame.datalen); } while (rv == -1 && errno == EINTR); - } + if (write_fd != FAX_INVALID_SOCKET) { + switch_ssize_t rv; + do { rv = write(write_fd, write_frame.data, write_frame.datalen); } while (rv == -1 && errno == EINTR); + } if (switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) { goto end_unlock; } - } + } end_unlock: - msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; - msg.from = __FILE__; - msg.string_arg = peer_uuid; - switch_core_session_receive_message(session, &msg); + msg.message_id = SWITCH_MESSAGE_INDICATE_UNBRIDGE; + msg.from = __FILE__; + msg.string_arg = peer_uuid; + switch_core_session_receive_message(session, &msg); if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_UNBRIDGE) == SWITCH_STATUS_SUCCESS) { @@ -1863,19 +1862,19 @@ static switch_status_t t38_gateway_on_consume_media(switch_core_session_t *sessi switch_event_fire(&event); } - if (read_fd != FAX_INVALID_SOCKET) { - close(read_fd); - read_fd = FAX_INVALID_SOCKET; - } + if (read_fd != FAX_INVALID_SOCKET) { + close(read_fd); + read_fd = FAX_INVALID_SOCKET; + } - if (write_fd != FAX_INVALID_SOCKET) { - close(write_fd); - write_fd = FAX_INVALID_SOCKET; - } + if (write_fd != FAX_INVALID_SOCKET) { + close(write_fd); + write_fd = FAX_INVALID_SOCKET; + } - switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING); - switch_core_session_rwunlock(other_session); + switch_channel_hangup(other_channel, SWITCH_CAUSE_NORMAL_CLEARING); + switch_core_session_rwunlock(other_session); switch_core_session_set_read_codec(session, NULL); @@ -1890,29 +1889,29 @@ static switch_status_t t38_gateway_on_consume_media(switch_core_session_t *sessi end: - switch_channel_clear_state_handler(channel, &t38_gateway_state_handlers); - switch_channel_set_variable(channel, "t38_peer", NULL); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - - return SWITCH_STATUS_SUCCESS; + switch_channel_clear_state_handler(channel, &t38_gateway_state_handlers); + switch_channel_set_variable(channel, "t38_peer", NULL); + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + + return SWITCH_STATUS_SUCCESS; } static switch_status_t t38_gateway_on_reset(switch_core_session_t *session) { - switch_channel_t *channel = switch_core_session_get_channel(session); + switch_channel_t *channel = switch_core_session_get_channel(session); - switch_channel_set_variable(channel, "rtp_autoflush_during_bridge", "false"); - - switch_channel_clear_flag(channel, CF_REDIRECT); + switch_channel_set_variable(channel, "rtp_autoflush_during_bridge", "false"); - if (switch_channel_test_app_flag_key("T38", channel, CF_APP_TAGGED)) { - switch_channel_clear_app_flag_key("T38", channel, CF_APP_TAGGED); - switch_channel_set_state(channel, CS_CONSUME_MEDIA); - } else { - switch_channel_set_state(channel, CS_SOFT_EXECUTE); - } + switch_channel_clear_flag(channel, CF_REDIRECT); - return SWITCH_STATUS_SUCCESS; + if (switch_channel_test_app_flag_key("T38", channel, CF_APP_TAGGED)) { + switch_channel_clear_app_flag_key("T38", channel, CF_APP_TAGGED); + switch_channel_set_state(channel, CS_CONSUME_MEDIA); + } else { + switch_channel_set_state(channel, CS_SOFT_EXECUTE); + } + + return SWITCH_STATUS_SUCCESS; } static const switch_state_handler_table_t t38_gateway_state_handlers = { @@ -1925,53 +1924,53 @@ static const switch_state_handler_table_t t38_gateway_state_handlers = { /*.on_consume_media */ t38_gateway_on_consume_media, /*.on_hibernate */ NULL, /*.on_reset */ t38_gateway_on_reset, - /*.on_park */ NULL, - /*.on_reporting */ NULL, - /*.on_destroy */ NULL, - SSH_FLAG_STICKY + /*.on_park */ NULL, + /*.on_reporting */ NULL, + /*.on_destroy */ NULL, + SSH_FLAG_STICKY }; switch_bool_t t38_gateway_start(switch_core_session_t *session, const char *app, const char *data) { - switch_channel_t *other_channel = NULL, *channel = switch_core_session_get_channel(session); - switch_core_session_t *other_session = NULL; - int peer = app && !strcasecmp(app, "peer"); - - if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { - other_channel = switch_core_session_get_channel(other_session); + switch_channel_t *other_channel = NULL, *channel = switch_core_session_get_channel(session); + switch_core_session_t *other_session = NULL; + int peer = app && !strcasecmp(app, "peer"); - switch_channel_set_variable(channel, "t38_peer", switch_core_session_get_uuid(other_session)); - switch_channel_set_variable(other_channel, "t38_peer", switch_core_session_get_uuid(session)); + if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { + other_channel = switch_core_session_get_channel(other_session); - switch_channel_set_variable(peer ? other_channel : channel, "t38_gateway_format", "udptl"); - switch_channel_set_variable(peer ? channel : other_channel, "t38_gateway_format", "audio"); + switch_channel_set_variable(channel, "t38_peer", switch_core_session_get_uuid(other_session)); + switch_channel_set_variable(other_channel, "t38_peer", switch_core_session_get_uuid(session)); + + switch_channel_set_variable(peer ? other_channel : channel, "t38_gateway_format", "udptl"); + switch_channel_set_variable(peer ? channel : other_channel, "t38_gateway_format", "audio"); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s starting gateway mode to %s\n", - switch_channel_get_name(peer ? channel : other_channel), - switch_channel_get_name(peer ? other_channel : channel)); - - - switch_channel_clear_state_handler(channel, NULL); - switch_channel_clear_state_handler(other_channel, NULL); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s starting gateway mode to %s\n", + switch_channel_get_name(peer ? channel : other_channel), + switch_channel_get_name(peer ? other_channel : channel)); - switch_channel_add_state_handler(channel, &t38_gateway_state_handlers); - switch_channel_add_state_handler(other_channel, &t38_gateway_state_handlers); - switch_channel_set_app_flag_key("T38", peer ? channel : other_channel, CF_APP_TAGGED); - switch_channel_clear_app_flag_key("T38", peer ? other_channel : channel, CF_APP_TAGGED); - - switch_channel_set_flag(channel, CF_REDIRECT); - switch_channel_set_state(channel, CS_RESET); + switch_channel_clear_state_handler(channel, NULL); + switch_channel_clear_state_handler(other_channel, NULL); - switch_channel_set_flag(other_channel, CF_REDIRECT); - switch_channel_set_state(other_channel, CS_RESET); - - switch_core_session_rwunlock(other_session); + switch_channel_add_state_handler(channel, &t38_gateway_state_handlers); + switch_channel_add_state_handler(other_channel, &t38_gateway_state_handlers); - } - - return SWITCH_FALSE; + switch_channel_set_app_flag_key("T38", peer ? channel : other_channel, CF_APP_TAGGED); + switch_channel_clear_app_flag_key("T38", peer ? other_channel : channel, CF_APP_TAGGED); + + switch_channel_set_flag(channel, CF_REDIRECT); + switch_channel_set_state(channel, CS_RESET); + + switch_channel_set_flag(other_channel, CF_REDIRECT); + switch_channel_set_state(other_channel, CS_RESET); + + switch_core_session_rwunlock(other_session); + + } + + return SWITCH_FALSE; } typedef struct { diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_modem.c b/src/mod/applications/mod_spandsp/mod_spandsp_modem.c index f1a1fdb7b0..58a3638aa5 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_modem.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_modem.c @@ -72,7 +72,7 @@ static modem_t *acquire_modem(int index); static int t31_at_tx_handler(at_state_t *s, void *user_data, const uint8_t *buf, size_t len) -{ +{ modem_t *modem = user_data; #ifndef WIN32 @@ -95,10 +95,10 @@ static int t31_at_tx_handler(at_state_t *s, void *user_data, const uint8_t *buf, CloseHandle (o.hEvent); #endif - if (wrote != len) { + if (wrote != len) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to pass the full buffer onto the device file. " "%"SWITCH_SSIZE_T_FMT " bytes of " "%"SWITCH_SIZE_T_FMT " written: %s\n", wrote, len, strerror(errno)); - + if (wrote == -1) wrote = 0; #ifndef WIN32 @@ -110,8 +110,8 @@ static int t31_at_tx_handler(at_state_t *s, void *user_data, const uint8_t *buf, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Successfully flushed pty buffer\n"); } #endif - } - return wrote; + } + return wrote; } @@ -126,7 +126,7 @@ static int t31_call_control_handler(t31_state_t *s, void *user_data, int op, con switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DOH! NO CONTROL HANDLER INSTALLED\n"); } - return ret; + return ret; } @@ -193,7 +193,7 @@ int modem_close(modem_t *modem) } - if (modem->t31_state) { + if (modem->t31_state) { t31_free(modem->t31_state); modem->t31_state = NULL; } @@ -228,7 +228,7 @@ switch_status_t modem_init(modem_t *modem, modem_control_handler_t control_handl */ #if USE_OPENPTY - if (openpty(&modem->master, &modem->slave, NULL, NULL, NULL)) { + if (openpty(&modem->master, &modem->slave, NULL, NULL, NULL)) { if (modem->master < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Fatal error: failed to initialize pty\n"); @@ -260,44 +260,44 @@ switch_status_t modem_init(modem_t *modem, modem_control_handler_t control_handl goto end; } #elif !defined(HAVE_POSIX_OPENPT) - modem->master = open("/dev/ptmx", O_RDWR); + modem->master = open("/dev/ptmx", O_RDWR); #else - modem->master = posix_openpt(O_RDWR | O_NOCTTY); + modem->master = posix_openpt(O_RDWR | O_NOCTTY); #endif #ifndef WIN32 - if (modem->master < 0) { + if (modem->master < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Fatal error: failed to initialize UNIX98 master pty\n"); - } + } - if (grantpt(modem->master) < 0) { + if (grantpt(modem->master) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Fatal error: failed to grant access to slave pty\n"); - } + } - if (unlockpt(modem->master) < 0) { + if (unlockpt(modem->master) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Fatal error: failed to unlock slave pty\n"); - } + } - modem->stty = ptsname(modem->master); + modem->stty = ptsname(modem->master); - if (modem->stty == NULL) { + if (modem->stty == NULL) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Fatal error: failed to obtain slave pty filename\n"); - } + } - modem->slave = open(modem->stty, O_RDWR); + modem->slave = open(modem->stty, O_RDWR); - if (modem->slave < 0) { + if (modem->slave < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Fatal error: failed to open slave pty %s\n", modem->stty); - } + } #endif #ifdef SOLARIS - ioctl(modem->slave, I_PUSH, "ptem"); /* push ptem */ - ioctl(modem->slave, I_PUSH, "ldterm"); /* push ldterm*/ + ioctl(modem->slave, I_PUSH, "ptem"); /* push ptem */ + ioctl(modem->slave, I_PUSH, "ldterm"); /* push ldterm*/ #endif #endif @@ -305,21 +305,21 @@ switch_status_t modem_init(modem_t *modem, modem_control_handler_t control_handl modem->slot = globals.NEXT_ID++; snprintf(modem->devlink, sizeof(modem->devlink), "/dev/FS%d", modem->slot); - unlink(modem->devlink); + unlink(modem->devlink); - if (symlink(modem->stty, modem->devlink)) { + if (symlink(modem->stty, modem->devlink)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Fatal error: failed to create %s symbolic link\n", modem->devlink); modem_close(modem); status = SWITCH_STATUS_FALSE; goto end; - } + } - if (fcntl(modem->master, F_SETFL, fcntl(modem->master, F_GETFL, 0) | O_NONBLOCK)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set up non-blocking read on %s\n", ttyname(modem->master)); - modem_close(modem); - status = SWITCH_STATUS_FALSE; - goto end; - } + if (fcntl(modem->master, F_SETFL, fcntl(modem->master, F_GETFL, 0) | O_NONBLOCK)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set up non-blocking read on %s\n", ttyname(modem->master)); + modem_close(modem); + status = SWITCH_STATUS_FALSE; + goto end; + } #else timeouts.ReadIntervalTimeout=50; timeouts.ReadTotalTimeoutConstant=50; @@ -1032,14 +1032,14 @@ static int control_handler(modem_t *modem, const char *num, int op) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Control Handler op:%d state:[%s] %s\n", op, modem_state2name(modem_get_state(modem)), modem->devlink); - switch (op) { + switch (op) { - case AT_MODEM_CONTROL_ANSWER: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + case AT_MODEM_CONTROL_ANSWER: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - Answering\n", modem->devlink, modem_state2name(modem_get_state(modem))); modem_set_state(modem, MODEM_STATE_ANSWERED); - break; - case AT_MODEM_CONTROL_CALL: + break; + case AT_MODEM_CONTROL_CALL: { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - Dialing '%s'\n", modem->devlink, modem_state2name(modem_get_state(modem)), num); @@ -1056,13 +1056,13 @@ static int control_handler(modem_t *modem, const char *num, int op) } } break; - case AT_MODEM_CONTROL_OFFHOOK: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + case AT_MODEM_CONTROL_OFFHOOK: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - Going off hook\n", modem->devlink, modem_state2name(modem_get_state(modem))); modem_set_state(modem, MODEM_STATE_OFFHOOK); break; - case AT_MODEM_CONTROL_ONHOOK: - case AT_MODEM_CONTROL_HANGUP: + case AT_MODEM_CONTROL_ONHOOK: + case AT_MODEM_CONTROL_HANGUP: { if (modem_get_state(modem) != MODEM_STATE_RINGING) { int set_state = 1; @@ -1096,16 +1096,16 @@ static int control_handler(modem_t *modem, const char *num, int op) } } } - break; - case AT_MODEM_CONTROL_DTR: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + break; + case AT_MODEM_CONTROL_DTR: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - DTR %d\n", modem->devlink, modem_state2name(modem_get_state(modem)), (int) (intptr_t) num); - break; - case AT_MODEM_CONTROL_RTS: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + break; + case AT_MODEM_CONTROL_RTS: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - RTS %d\n", modem->devlink, modem_state2name(modem_get_state(modem)), (int) (intptr_t) num); - break; - case AT_MODEM_CONTROL_CTS: + break; + case AT_MODEM_CONTROL_CTS: { u_char x[1]; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, @@ -1122,26 +1122,26 @@ static int control_handler(modem_t *modem, const char *num, int op) switch_set_flag(modem, MODEM_FLAG_XOFF); } } - break; - case AT_MODEM_CONTROL_CAR: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + break; + case AT_MODEM_CONTROL_CAR: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - CAR %d\n", modem->devlink, modem_state2name(modem_get_state(modem)), (int) (intptr_t) num); - break; - case AT_MODEM_CONTROL_RNG: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + break; + case AT_MODEM_CONTROL_RNG: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - RNG %d\n", modem->devlink, modem_state2name(modem_get_state(modem)), (int) (intptr_t) num); - break; - case AT_MODEM_CONTROL_DSR: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + break; + case AT_MODEM_CONTROL_DSR: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - DSR %d\n", modem->devlink, modem_state2name(modem_get_state(modem)), (int) (intptr_t) num); - break; - default: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + break; + default: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Modem %s [%s] - operation %d\n", modem->devlink, modem_state2name(modem_get_state(modem)), op); - break; - } - /*endswitch*/ - return 0; + break; + } + /*endswitch*/ + return 0; } typedef enum { @@ -1370,14 +1370,14 @@ static void activate_modems(void) static void deactivate_modems(void) { int max = globals.SOFT_MAX_MODEMS; - int x; + int x; switch_mutex_lock(globals.mutex); - for(x = 0; x < max; x++) { + for(x = 0; x < max; x++) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Stopping Modem SLOT %d\n", x); modem_close(&globals.MODEM_POOL[x]); - } + } switch_mutex_unlock(globals.mutex); @@ -1390,39 +1390,39 @@ static void deactivate_modems(void) static modem_t *acquire_modem(int index) { - modem_t *modem = NULL; + modem_t *modem = NULL; switch_time_t now = switch_time_now(); int64_t idle_debounce = 2000000; - switch_mutex_lock(globals.mutex); - if (index > -1 && index < globals.SOFT_MAX_MODEMS) { - modem = &globals.MODEM_POOL[index]; - } else { - int x; + switch_mutex_lock(globals.mutex); + if (index > -1 && index < globals.SOFT_MAX_MODEMS) { + modem = &globals.MODEM_POOL[index]; + } else { + int x; - for(x = 0; x < globals.SOFT_MAX_MODEMS; x++) { - if (globals.MODEM_POOL[x].state == MODEM_STATE_ONHOOK && (now - globals.MODEM_POOL[x].last_event) > idle_debounce) { - modem = &globals.MODEM_POOL[x]; - break; - } - } - } + for(x = 0; x < globals.SOFT_MAX_MODEMS; x++) { + if (globals.MODEM_POOL[x].state == MODEM_STATE_ONHOOK && (now - globals.MODEM_POOL[x].last_event) > idle_debounce) { + modem = &globals.MODEM_POOL[x]; + break; + } + } + } - if (modem && (modem->state != MODEM_STATE_ONHOOK || (now - modem->last_event) < idle_debounce)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Modem %s In Use!\n", modem->devlink); - modem = NULL; - } + if (modem && (modem->state != MODEM_STATE_ONHOOK || (now - modem->last_event) < idle_debounce)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Modem %s In Use!\n", modem->devlink); + modem = NULL; + } - if (modem) { - modem_set_state(modem, MODEM_STATE_ACQUIRED); + if (modem) { + modem_set_state(modem, MODEM_STATE_ACQUIRED); modem->last_event = switch_time_now(); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Modems Available!\n"); - } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Modems Available!\n"); + } - switch_mutex_unlock(globals.mutex); + switch_mutex_unlock(globals.mutex); - return modem; + return modem; } switch_status_t modem_global_init(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool)