replace spaces with tabs in mod_spandsp
This commit is contained in:
parent
0235d6a6fb
commit
913b39830f
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
|
@ -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 <descriptor> 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 <descriptor> 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 <tone> name for <descriptor> %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 <element> of <descriptor> %s <tone> %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 <tone> name for <descriptor> %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 <element> of <descriptor> %s <tone> %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)
|
|||
"<app>[ <arg>][ <timeout>][ <tone_type>]", 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, "<uuid>");
|
||||
SWITCH_ADD_API(api_interface, "stop_tdd_detect", "Stop background tdd detection", stop_tdd_detect_api, "<uuid>");
|
||||
|
||||
SWITCH_ADD_API(api_interface, "uuid_send_tdd", "send tdd data to a uuid", start_send_tdd_api, "<uuid> <text>");
|
||||
SWITCH_ADD_API(api_interface, "start_tdd_detect", "Start background tdd detection", start_tdd_detect_api, "<uuid>");
|
||||
SWITCH_ADD_API(api_interface, "stop_tdd_detect", "Stop background tdd detection", stop_tdd_detect_api, "<uuid>");
|
||||
|
||||
SWITCH_ADD_API(api_interface, "uuid_send_tdd", "send tdd data to a uuid", start_send_tdd_api, "<uuid> <text>");
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue