spring cleaning

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2007-03-29 22:31:56 +00:00
1 parent a021945cef
commit 3a54126261
143 files changed
+22413 -31567

No files matched your search

@@ -44,11 +44,11 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
char *var;
uint8_t no_media_bridge = 0;
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
uint8_t do_continue = 0;
uint8_t do_continue = 0;
if (switch_strlen_zero(data)) {
return;
}
if (switch_strlen_zero(data)) {
return;
}
caller_channel = switch_core_session_get_channel(session);
assert(caller_channel != NULL);
@@ -60,43 +60,50 @@ static void audio_bridge_function(switch_core_session_t *session, char *data)
if ((var = switch_channel_get_variable(caller_channel, "continue_on_fail"))) {
do_continue = switch_true(var);
}
if (switch_channel_test_flag(caller_channel, CF_NOMEDIA) || ((var = switch_channel_get_variable(caller_channel, "no_media")) && switch_true(var))) {
if (!switch_channel_test_flag(caller_channel, CF_ANSWERED) && !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
if (switch_channel_test_flag(caller_channel, CF_NOMEDIA)
|| ((var = switch_channel_get_variable(caller_channel, "no_media")) && switch_true(var))) {
if (!switch_channel_test_flag(caller_channel, CF_ANSWERED)
&& !switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
switch_channel_set_flag(caller_channel, CF_NOMEDIA);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel is already up, delaying point-to-point mode 'till both legs are up.\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Channel is already up, delaying point-to-point mode 'till both legs are up.\n");
no_media_bridge = 1;
}
}
if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Originate Failed. Cause: %s\n", switch_channel_cause2str(cause));
if (!do_continue && cause != SWITCH_CAUSE_NO_ANSWER) {
/* All Causes besides NO_ANSWER terminate the originating session unless continue_on_fail is set.
We will pass the fail cause on when we hangup.*/
switch_channel_hangup(caller_channel, cause);
}
/* Otherwise.. nobody answered. Go back to the dialplan instructions in case there was more to do. */
if (switch_ivr_originate(session, &peer_session, &cause, data, timelimit, NULL, NULL, NULL, NULL) !=
SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Originate Failed. Cause: %s\n",
switch_channel_cause2str(cause));
if (!do_continue && cause != SWITCH_CAUSE_NO_ANSWER) {
/* All Causes besides NO_ANSWER terminate the originating session unless continue_on_fail is set.
We will pass the fail cause on when we hangup. */
switch_channel_hangup(caller_channel, cause);
}
/* Otherwise.. nobody answered. Go back to the dialplan instructions in case there was more to do. */
return;
} else {
if (no_media_bridge) {
switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
switch_frame_t *read_frame;
/* SIP won't let us redir media until the call has been answered #$^#%& so we will proxy any early media until they do */
while(switch_channel_ready(caller_channel) && switch_channel_ready(peer_channel) && !switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
switch_status_t status = switch_core_session_read_frame(peer_session, &read_frame, -1, 0);
uint8_t bad = 1;
switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);
switch_frame_t *read_frame;
/* SIP won't let us redir media until the call has been answered #$^#%& so we will proxy any early media until they do */
while (switch_channel_ready(caller_channel) && switch_channel_ready(peer_channel)
&& !switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
switch_status_t status = switch_core_session_read_frame(peer_session, &read_frame, -1, 0);
uint8_t bad = 1;
if (SWITCH_READ_ACCEPTABLE(status) && switch_core_session_write_frame(session, read_frame, -1, 0) == SWITCH_STATUS_SUCCESS) {
bad = 0;
}
if (bad) {
switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return;
}
}
if (SWITCH_READ_ACCEPTABLE(status)
&& switch_core_session_write_frame(session, read_frame, -1, 0) == SWITCH_STATUS_SUCCESS) {
bad = 0;
}
if (bad) {
switch_channel_hangup(caller_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_channel_hangup(peer_channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return;
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Redirecting media to point-to-point mode.\n");
switch_ivr_nomedia(switch_core_session_get_uuid(session), SMF_FORCE);
@@ -130,7 +137,8 @@ static const switch_loadable_module_interface_t mod_bridgecall_module_interface
/*.application_interface */ &bridge_application_interface
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
+137 -123
View File
@@ -76,18 +76,15 @@ static switch_status_t status_function(char *cmd, switch_core_session_t *session
stream->write_function(stream, "<h1>FreeSWITCH Status</h1>\n<b>");
}
stream->write_function(stream, "UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s\n",
duration.yr, duration.yr == 1 ? "" : "s",
duration.day, duration.day == 1 ? "" : "s",
duration.hr, duration.hr == 1 ? "" : "s",
duration.min, duration.min == 1 ? "" : "s",
duration.sec, duration.sec == 1 ? "" : "s",
duration.ms, duration.ms == 1 ? "" : "s",
duration.mms, duration.mms == 1 ? "" : "s"
);
stream->write_function(stream,
"UP %u year%s, %u day%s, %u hour%s, %u minute%s, %u second%s, %u millisecond%s, %u microsecond%s\n",
duration.yr, duration.yr == 1 ? "" : "s", duration.day, duration.day == 1 ? "" : "s",
duration.hr, duration.hr == 1 ? "" : "s", duration.min, duration.min == 1 ? "" : "s",
duration.sec, duration.sec == 1 ? "" : "s", duration.ms, duration.ms == 1 ? "" : "s",
duration.mms, duration.mms == 1 ? "" : "s");
stream->write_function(stream, "%d sessions\n", switch_core_session_count());
if (html) {
stream->write_function(stream, "</b>\n");
}
@@ -98,8 +95,10 @@ static switch_status_t status_function(char *cmd, switch_core_session_t *session
int r;
refresh++;
r = atoi(refresh);
if (r > 0) {
stream->write_function(stream, "<META HTTP-EQUIV=REFRESH CONTENT=\"%d; URL=/api/status?refresh=%d%s\">\n", r, r, html ? "html=1" : "");
if (r > 0) {
stream->write_function(stream,
"<META HTTP-EQUIV=REFRESH CONTENT=\"%d; URL=/api/status?refresh=%d%s\">\n", r, r,
html ? "html=1" : "");
}
}
}
@@ -120,7 +119,7 @@ static switch_status_t ctl_function(char *data, switch_core_session_t *session,
if ((mydata = strdup(data))) {
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (!strcmp(argv[0], "hupall")) {
arg = 1;
switch_core_session_ctl(SCSC_HUPALL, &arg);
@@ -134,19 +133,20 @@ static switch_status_t ctl_function(char *data, switch_core_session_t *session,
arg = 0;
switch_core_session_ctl(SCSC_SHUTDOWN, &arg);
} else {
stream->write_function(stream, "INVALID COMMAND [%s]\nUSAGE: fsctl [hupall|pause|resume|shutdown]\n", argv[0]);
stream->write_function(stream, "INVALID COMMAND [%s]\nUSAGE: fsctl [hupall|pause|resume|shutdown]\n",
argv[0]);
goto end;
}
}
stream->write_function(stream, "OK\n");
end:
end:
free(mydata);
} else {
stream->write_function(stream, "MEM ERR\n");
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t load_function(char *mod, switch_core_session_t *session, switch_stream_handle_t *stream)
@@ -161,7 +161,8 @@ static switch_status_t load_function(char *mod, switch_core_session_t *session,
return SWITCH_STATUS_SUCCESS;
}
if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
if (switch_loadable_module_load_module((char *) SWITCH_GLOBAL_dirs.mod_dir, (char *) mod, SWITCH_TRUE) ==
SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "OK\n");
} else {
stream->write_function(stream, "ERROR\n");
@@ -178,11 +179,11 @@ static switch_status_t reload_function(char *args, switch_core_session_t *sessio
if (session) {
return SWITCH_STATUS_FALSE;
}
if ((xml_root = switch_xml_open_root(1, &err))) {
switch_xml_free(xml_root);
}
stream->write_function(stream, "OK [%s]\n", err);
return SWITCH_STATUS_SUCCESS;
@@ -213,13 +214,13 @@ static switch_status_t kill_function(char *dest, switch_core_session_t *isession
static switch_status_t transfer_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{
switch_core_session_t *session = NULL;
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc = 0;
if (isession) {
return SWITCH_STATUS_FALSE;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 2 || argc > 4) {
@@ -229,11 +230,11 @@ static switch_status_t transfer_function(char *cmd, switch_core_session_t *isess
char *dest = argv[1];
char *dp = argv[2];
char *context = argv[3];
if ((session = switch_core_session_locate(uuid))) {
if (switch_ivr_session_transfer(session, dest, dp, context) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "OK\n");
stream->write_function(stream, "OK\n");
} else {
stream->write_function(stream, "ERROR\n");
}
@@ -249,16 +250,17 @@ static switch_status_t transfer_function(char *cmd, switch_core_session_t *isess
}
static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t *isession,
switch_stream_handle_t *stream)
{
switch_core_session_t *session = NULL;
char *argv[6] = {0};
char *argv[6] = { 0 };
int argc = 0;
if (isession) {
return SWITCH_STATUS_FALSE;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 2 || argc > 5) {
@@ -269,9 +271,9 @@ static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t
char *dp = argv[3];
char *context = argv[4];
time_t when;
if (*argv[0] == '+') {
when = time (NULL) + atol(argv[0] + 1);
when = time(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -291,13 +293,13 @@ static switch_status_t sched_transfer_function(char *cmd, switch_core_session_t
static switch_status_t sched_hangup_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{
switch_core_session_t *session = NULL;
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc = 0;
if (isession) {
return SWITCH_STATUS_FALSE;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 1) {
@@ -309,7 +311,7 @@ static switch_status_t sched_hangup_function(char *cmd, switch_core_session_t *i
switch_call_cause_t cause = SWITCH_CAUSE_ALLOTTED_TIMEOUT;
if (*argv[0] == '+') {
when = time (NULL) + atol(argv[0] + 1);
when = time(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -333,14 +335,14 @@ static switch_status_t sched_hangup_function(char *cmd, switch_core_session_t *i
static switch_status_t uuid_media_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc = 0;
switch_status_t status = SWITCH_STATUS_FALSE;
if (isession) {
return status;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 1) {
@@ -363,16 +365,17 @@ static switch_status_t uuid_media_function(char *cmd, switch_core_session_t *ise
}
static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t *isession,
switch_stream_handle_t *stream)
{
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc = 0;
switch_status_t status = SWITCH_STATUS_FALSE;
if (isession) {
return status;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 2) {
@@ -391,7 +394,7 @@ static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t
} else {
flags |= SMF_ECHO_ALEG;
}
status = switch_ivr_broadcast(argv[0], argv[1], flags);
stream->write_function(stream, "+OK Message Sent\n");
}
@@ -400,16 +403,17 @@ static switch_status_t uuid_broadcast_function(char *cmd, switch_core_session_t
}
static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t *isession,
switch_stream_handle_t *stream)
{
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc = 0;
switch_status_t status = SWITCH_STATUS_FALSE;
if (isession) {
return status;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 3) {
@@ -419,7 +423,7 @@ static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t
time_t when;
if (*argv[0] == '+') {
when = time (NULL) + atol(argv[0] + 1);
when = time(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -435,7 +439,7 @@ static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t
} else {
flags |= SMF_ECHO_ALEG;
}
status = switch_ivr_schedule_broadcast(when, argv[1], argv[2], flags);
stream->write_function(stream, "+OK Message Scheduled\n");
}
@@ -445,14 +449,14 @@ static switch_status_t sched_broadcast_function(char *cmd, switch_core_session_t
static switch_status_t uuid_hold_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc = 0;
switch_status_t status = SWITCH_STATUS_FALSE;
if (isession) {
return status;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 1) {
@@ -476,13 +480,13 @@ static switch_status_t uuid_hold_function(char *cmd, switch_core_session_t *ises
static switch_status_t uuid_bridge_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc = 0;
if (isession) {
return SWITCH_STATUS_FALSE;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc != 2) {
@@ -496,72 +500,73 @@ static switch_status_t uuid_bridge_function(char *cmd, switch_core_session_t *is
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t session_record_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
static switch_status_t session_record_function(char *cmd, switch_core_session_t *isession,
switch_stream_handle_t *stream)
{
switch_core_session_t *session = NULL;
char *argv[4] = {0};
char *uuid = NULL, *action = NULL, *path = NULL;
switch_core_session_t *session = NULL;
char *argv[4] = { 0 };
char *uuid = NULL, *action = NULL, *path = NULL;
int argc = 0;
if (isession) {
return SWITCH_STATUS_FALSE;
}
if (switch_strlen_zero(cmd)) {
goto usage;
}
goto usage;
}
if ((argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) != 3) {
goto usage;
}
goto usage;
}
uuid = argv[0];
action = argv[1];
path = argv[2];
if (!(session = switch_core_session_locate(uuid))) {
uuid = argv[0];
action = argv[1];
path = argv[2];
if (!(session = switch_core_session_locate(uuid))) {
stream->write_function(stream, "-Error Cannot locate session!\n");
return SWITCH_STATUS_SUCCESS;
}
if (switch_strlen_zero(action) || switch_strlen_zero(path)) {
goto usage;
}
return SWITCH_STATUS_SUCCESS;
}
if (!strcasecmp(action, "start")) {
switch_ivr_record_session(session, path, NULL);
} else if (!strcasecmp(action, "stop")) {
switch_ivr_stop_record_session(session, path);
} else {
goto usage;
}
if (switch_strlen_zero(action) || switch_strlen_zero(path)) {
goto usage;
}
goto done;
if (!strcasecmp(action, "start")) {
switch_ivr_record_session(session, path, NULL);
} else if (!strcasecmp(action, "stop")) {
switch_ivr_stop_record_session(session, path);
} else {
goto usage;
}
usage:
goto done;
stream->write_function(stream, "USAGE: %s\n", session_record_api_interface.syntax);
return SWITCH_STATUS_SUCCESS;
usage:
done:
stream->write_function(stream, "USAGE: %s\n", session_record_api_interface.syntax);
return SWITCH_STATUS_SUCCESS;
if (session) {
switch_core_session_rwunlock(session);
}
done:
return SWITCH_STATUS_SUCCESS;
if (session) {
switch_core_session_rwunlock(session);
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t pause_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{
switch_core_session_t *session = NULL;
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc = 0;
if (isession) {
return SWITCH_STATUS_FALSE;
}
argc = switch_separate_string(cmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
if (switch_strlen_zero(cmd) || argc < 2) {
@@ -569,7 +574,7 @@ static switch_status_t pause_function(char *cmd, switch_core_session_t *isession
} else {
char *uuid = argv[0];
char *dest = argv[1];
if ((session = switch_core_session_locate(uuid))) {
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -593,7 +598,7 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
{
switch_channel_t *caller_channel;
switch_core_session_t *caller_session;
char *argv[7] = {0};
char *argv[7] = { 0 };
int i = 0, x, argc = 0;
char *aleg, *exten, *dp, *context, *cid_name, *cid_num;
uint32_t timeout = 60;
@@ -612,12 +617,12 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
return SWITCH_STATUS_SUCCESS;
}
for(x = 0; x < argc; x++) {
for (x = 0; x < argc; x++) {
if (!strcasecmp(argv[x], "undef")) {
argv[x] = NULL;
}
}
if (!strcasecmp(argv[0], "machine")) {
machine = 1;
i++;
@@ -629,7 +634,7 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
context = argv[i++];
cid_name = argv[i++];
cid_num = argv[i++];
if (!dp) {
dp = "XML";
}
@@ -642,20 +647,22 @@ static switch_status_t originate_function(char *cmd, switch_core_session_t *ises
timeout = atoi(argv[6]);
}
if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL) != SWITCH_STATUS_SUCCESS) {
if (switch_ivr_originate(NULL, &caller_session, &cause, aleg, timeout, NULL, cid_name, cid_num, NULL) !=
SWITCH_STATUS_SUCCESS) {
if (machine) {
stream->write_function(stream, "fail: %s\n", switch_channel_cause2str(cause));
} else {
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s] cause: %s\n", aleg, switch_channel_cause2str(cause));
stream->write_function(stream, "Cannot Create Outgoing Channel! [%s] cause: %s\n", aleg,
switch_channel_cause2str(cause));
}
return SWITCH_STATUS_SUCCESS;
}
}
caller_channel = switch_core_session_get_channel(caller_session);
assert(caller_channel != NULL);
switch_channel_clear_state_handler(caller_channel, NULL);
if (*exten == '&' && *(exten + 1)) {
if (*exten == '&' && *(exten + 1)) {
switch_caller_extension_t *extension = NULL;
char *app_name = switch_core_session_strdup(caller_session, (exten + 1));
char *arg = NULL, *e;
@@ -696,7 +703,8 @@ struct holder {
int print_title;
};
static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
static int show_callback(void *pArg, int argc, char **argv, char **columnNames)
{
struct holder *holder = (struct holder *) pArg;
int x;
@@ -706,26 +714,29 @@ static int show_callback(void *pArg, int argc, char **argv, char **columnNames){
holder->stream->write_function(holder->stream, "\n<tr>");
}
for(x = 0; x < argc; x++) {
for (x = 0; x < argc; x++) {
if (holder->http) {
holder->stream->write_function(holder->stream, "<td>");
holder->stream->write_function(holder->stream, "<b>%s</b>%s", columnNames[x], x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
holder->stream->write_function(holder->stream, "<b>%s</b>%s", columnNames[x],
x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
} else {
holder->stream->write_function(holder->stream, "%s%s", columnNames[x], x == (argc - 1) ? "\n" : ",");
}
}
}
}
if (holder->http) {
holder->stream->write_function(holder->stream, "<tr bgcolor=%s>", holder->count % 2 == 0 ? "eeeeee" : "ffffff");
}
for(x = 0; x < argc; x++) {
for (x = 0; x < argc; x++) {
if (holder->http) {
holder->stream->write_function(holder->stream, "<td>");
holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "", x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "",
x == (argc - 1) ? "</td></tr>\n" : "</td><td>");
} else {
holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "", x == (argc - 1) ? "\n" : ",");
holder->stream->write_function(holder->stream, "%s%s", argv[x] ? argv[x] : "",
x == (argc - 1) ? "\n" : ",");
}
}
@@ -738,7 +749,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
char sql[1024];
char *errmsg;
switch_core_db_t *db = switch_core_db_handle();
struct holder holder = {0};
struct holder holder = { 0 };
int help = 0;
if (session) {
@@ -747,7 +758,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
if (stream->event) {
holder.http = switch_event_get_header(stream->event, "http-host");
}
}
holder.print_title = 1;
@@ -756,14 +767,14 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
if (!cmd) {
stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
return SWITCH_STATUS_SUCCESS;
} else if ( !strcmp(cmd,"codec") || !strcmp(cmd,"dialplan") || !strcmp(cmd,"file") || !strcmp(cmd,"timer")) {
sprintf (sql, "select type, name from interfaces where type = '%s'", cmd);
} else if (!strcmp(cmd,"application") || !strcmp(cmd,"api")) {
sprintf (sql, "select name, description, syntax from interfaces where type = '%s' and description != ''" , cmd);
} else if ( !strcmp(cmd,"calls")) {
sprintf (sql, "select * from calls");
} else if ( !strcmp(cmd,"channels")) {
sprintf (sql, "select * from channels");
} else if (!strcmp(cmd, "codec") || !strcmp(cmd, "dialplan") || !strcmp(cmd, "file") || !strcmp(cmd, "timer")) {
sprintf(sql, "select type, name from interfaces where type = '%s'", cmd);
} else if (!strcmp(cmd, "application") || !strcmp(cmd, "api")) {
sprintf(sql, "select name, description, syntax from interfaces where type = '%s' and description != ''", cmd);
} else if (!strcmp(cmd, "calls")) {
sprintf(sql, "select * from calls");
} else if (!strcmp(cmd, "channels")) {
sprintf(sql, "select * from channels");
} else if (!strncasecmp(cmd, "help", 4)) {
char *cmdname = NULL;
@@ -771,15 +782,16 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
holder.print_title = 0;
if ((cmdname = strchr(cmd, ' ')) != 0) {
*cmdname++ = '\0';
snprintf (sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api' and name = '%s'", cmdname);
snprintf(sql, sizeof(sql) - 1,
"select name, syntax, description from interfaces where type = 'api' and name = '%s'", cmdname);
} else {
snprintf (sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api'");
snprintf(sql, sizeof(sql) - 1, "select name, syntax, description from interfaces where type = 'api'");
}
} else {
stream->write_function(stream, "USAGE: %s\n", show_api_interface.syntax);
return SWITCH_STATUS_SUCCESS;
}
holder.stream = stream;
holder.count = 0;
@@ -794,7 +806,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
}
if (errmsg) {
stream->write_function(stream, "SQL ERR [%s]\n",errmsg);
stream->write_function(stream, "SQL ERR [%s]\n", errmsg);
switch_core_db_free(errmsg);
errmsg = NULL;
} else if (help) {
@@ -811,7 +823,7 @@ static switch_status_t show_function(char *cmd, switch_core_session_t *session,
static switch_status_t version_function(char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream)
{
char version_string[1024];
snprintf(version_string, sizeof(version_string) - 1, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
snprintf(version_string, sizeof(version_string) - 1, "FreeSwitch Version %s\n", SWITCH_VERSION_FULL);
stream->write_function(stream, version_string);
return SWITCH_STATUS_SUCCESS;
@@ -822,10 +834,10 @@ static switch_status_t help_function(char *cmd, switch_core_session_t *session,
char showcmd[1024];
int all = 0;
if (switch_strlen_zero(cmd)) {
sprintf (showcmd, "help");
sprintf(showcmd, "help");
all = 1;
} else {
snprintf(showcmd, sizeof(showcmd) -1, "help %s", cmd);
snprintf(showcmd, sizeof(showcmd) - 1, "help %s", cmd);
}
if (all) {
@@ -986,7 +998,8 @@ static switch_api_interface_t originate_api_interface = {
/*.interface_name */ "originate",
/*.desc */ "Originate a Call",
/*.function */ originate_function,
/*.syntax */ "<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]",
/*.syntax */
"<call url> <exten>|&<application_name>(<app_args>) [<dialplan>] [<context>] [<cid_name>] [<cid_num>] [<timeout_sec>]",
/*.next */ &kill_api_interface
};
@@ -1000,7 +1013,8 @@ static const switch_loadable_module_interface_t mod_commands_module_interface =
/*.api_interface */ &originate_api_interface
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &mod_commands_module_interface;
File diff suppressed because it is too large. Load diff
+119 -116
View File
@@ -43,7 +43,8 @@ static void detect_speech_function(switch_core_session_t *session, char *data)
int argc;
char *lbuf = NULL;
if (data && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (data && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if (!strcasecmp(argv[0], "grammar") && argc >= 1) {
switch_ivr_detect_speech_load_grammar(session, argv[1], argv[2]);
} else if (!strcasecmp(argv[0], "nogrammar")) {
@@ -58,16 +59,17 @@ static void detect_speech_function(switch_core_session_t *session, char *data)
switch_ivr_detect_speech(session, argv[0], argv[1], argv[2], argv[3], NULL);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", detect_speech_application_interface.syntax);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n",
detect_speech_application_interface.syntax);
}
}
static void ring_ready_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_channel_ring_ready(channel);
}
@@ -84,7 +86,7 @@ static void queue_dtmf_function(switch_core_session_t *session, char *data)
static void transfer_function(switch_core_session_t *session, char *data)
{
int argc;
char *argv[4] = {0};
char *argv[4] = { 0 };
char *mydata;
if (data && (mydata = switch_core_session_strdup(session, data))) {
@@ -99,15 +101,15 @@ static void transfer_function(switch_core_session_t *session, char *data)
static void sched_transfer_function(switch_core_session_t *session, char *data)
{
int argc;
char *argv[4] = {0};
char *argv[4] = { 0 };
char *mydata;
if (data && (mydata = switch_core_session_strdup(session, data))) {
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
time_t when;
if (*argv[0] == '+') {
when = time (NULL) + atol(argv[0] + 1);
when = time(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
@@ -122,7 +124,7 @@ static void sched_transfer_function(switch_core_session_t *session, char *data)
static void sched_hangup_function(switch_core_session_t *session, char *data)
{
int argc;
char *argv[5] = {0};
char *argv[5] = { 0 };
char *mydata;
if (data && (mydata = switch_core_session_strdup(session, data))) {
@@ -132,11 +134,11 @@ static void sched_hangup_function(switch_core_session_t *session, char *data)
switch_bool_t bleg = SWITCH_FALSE;
if (*argv[0] == '+') {
when = time (NULL) + atol(argv[0] + 1);
when = time(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
if (argv[1]) {
cause = switch_channel_str2cause(argv[1]);
}
@@ -156,20 +158,20 @@ static void sched_hangup_function(switch_core_session_t *session, char *data)
static void sched_broadcast_function(switch_core_session_t *session, char *data)
{
int argc;
char *argv[6] = {0};
char *argv[6] = { 0 };
char *mydata;
if (data && (mydata = switch_core_session_strdup(session, data))) {
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
time_t when;
switch_media_flag_t flags = SMF_NONE;
if (*argv[0] == '+') {
when = time (NULL) + atol(argv[0] + 1);
when = time(NULL) + atol(argv[0] + 1);
} else {
when = atol(argv[0]);
}
if (argv[2]) {
if (!strcmp(argv[2], "both")) {
flags |= (SMF_ECHO_ALEG | SMF_ECHO_BLEG);
@@ -207,26 +209,26 @@ static void eval_function(switch_core_session_t *session, char *data)
static void phrase_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
char *mydata = NULL;
switch_channel_t *channel;
char *mydata = NULL;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
if ((mydata = switch_core_session_strdup(session, data))) {
char *lang;
char *macro = mydata;
char *mdata = NULL;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
if ((mdata = strchr(macro, ','))) {
*mdata++ = '\0';
}
if ((mydata = switch_core_session_strdup(session, data))) {
char *lang;
char *macro = mydata;
char *mdata = NULL;
lang = switch_channel_get_variable(channel, "language");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, mdata, lang);
switch_ivr_phrase_macro(session, macro, mdata, lang, NULL);
}
if ((mdata = strchr(macro, ','))) {
*mdata++ = '\0';
}
lang = switch_channel_get_variable(channel, "language");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Execute %s(%s) lang %s\n", macro, mdata, lang);
switch_ivr_phrase_macro(session, macro, mdata, lang, NULL);
}
}
@@ -234,14 +236,14 @@ static void phrase_function(switch_core_session_t *session, char *data)
static void hangup_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
if (!switch_strlen_zero((char *) data)) {
cause = switch_channel_str2cause((char *) data);
}
if (!switch_strlen_zero((char *) data)) {
cause = switch_channel_str2cause((char *) data);
}
switch_channel_hangup(channel, cause);
}
@@ -251,7 +253,7 @@ static void answer_function(switch_core_session_t *session, char *data)
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_channel_answer(channel);
}
@@ -260,18 +262,18 @@ static void pre_answer_function(switch_core_session_t *session, char *data)
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_channel_pre_answer(channel);
}
static void redirect_function(switch_core_session_t *session, char *data)
{
switch_core_session_message_t msg = {0};
switch_core_session_message_t msg = { 0 };
/* Tell the channel to redirect */
/* Tell the channel to redirect */
msg.from = __FILE__;
msg.string_arg = data;
msg.message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
msg.message_id = SWITCH_MESSAGE_INDICATE_REDIRECT;
switch_core_session_receive_message(session, &msg);
}
@@ -283,7 +285,7 @@ static void set_function(switch_core_session_t *session, char *data)
char *var, *val = NULL;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
@@ -293,11 +295,11 @@ static void set_function(switch_core_session_t *session, char *data)
if (val) {
*val++ = '\0';
if (switch_strlen_zero(val)) {
val = NULL;
}
if (switch_strlen_zero(val)) {
val = NULL;
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SET [%s]=[%s]\n", var, val ? val : "UNDEF");
switch_channel_set_variable(channel, var, val);
}
@@ -309,7 +311,7 @@ static void export_function(switch_core_session_t *session, char *data)
char *exports, *new_exports = NULL, *new_exports_d = NULL, *var, *val = NULL;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
@@ -320,11 +322,11 @@ static void export_function(switch_core_session_t *session, char *data)
if (val) {
*val++ = '\0';
if (switch_strlen_zero(val)) {
val = NULL;
}
if (switch_strlen_zero(val)) {
val = NULL;
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "EXPORT [%s]=[%s]\n", var, val ? val : "UNDEF");
switch_channel_set_variable(channel, var, val);
@@ -346,7 +348,7 @@ static void unset_function(switch_core_session_t *session, char *data)
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
if (switch_strlen_zero(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No variable name specified.\n");
@@ -359,43 +361,43 @@ static void unset_function(switch_core_session_t *session, char *data)
static void log_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
char *level, *log_str;
char *level, *log_str;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
if (data && (level = strdup(data))) {
switch_event_types_t etype = SWITCH_LOG_DEBUG;
if ((log_str = strchr(level, ' '))) {
*log_str++ = '\0';
switch_name_event(level, &etype);
} else {
log_str = level;
}
if (data && (level = strdup(data))) {
switch_event_types_t etype = SWITCH_LOG_DEBUG;
switch_log_printf(SWITCH_CHANNEL_LOG, etype, "%s\n", log_str);
switch_safe_free(level);
}
if ((log_str = strchr(level, ' '))) {
*log_str++ = '\0';
switch_name_event(level, &etype);
} else {
log_str = level;
}
switch_log_printf(SWITCH_CHANNEL_LOG, etype, "%s\n", log_str);
switch_safe_free(level);
}
}
static void info_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
switch_event_t *event;
char *buf;
switch_event_t *event;
char *buf;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_serialize(event, &buf);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHANNEL_DATA:\n%s\n", buf);
switch_event_destroy(&event);
}
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_serialize(event, &buf);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHANNEL_DATA:\n%s\n", buf);
switch_event_destroy(&event);
}
}
static void privacy_function(switch_core_session_t *session, char *data)
@@ -405,8 +407,8 @@ static void privacy_function(switch_core_session_t *session, char *data)
char *arg;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
caller_profile = switch_channel_get_caller_profile(channel);
if (switch_strlen_zero(data)) {
@@ -416,7 +418,7 @@ static void privacy_function(switch_core_session_t *session, char *data)
switch_set_flag(caller_profile, SWITCH_CPF_SCREEN);
if(!strcasecmp(arg, "no")) {
if (!strcasecmp(arg, "no")) {
switch_clear_flag(caller_profile, SWITCH_CPF_HIDE_NAME);
switch_clear_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER);
} else if (!strcasecmp(arg, "yes")) {
@@ -428,7 +430,8 @@ static void privacy_function(switch_core_session_t *session, char *data)
} else if (!strcasecmp(arg, "number")) {
switch_set_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "INVALID privacy mode specified. Use a valid mode [no|yes|name|full|number].\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"INVALID privacy mode specified. Use a valid mode [no|yes|name|full|number].\n");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Set Privacy to %s [%d]\n", arg, caller_profile->flags);
}
@@ -440,7 +443,8 @@ static void strftime_function(switch_core_session_t *session, char *data)
int argc;
char *lbuf;
if (data && (lbuf = switch_core_session_strdup(session, data)) && (argc = switch_separate_string(lbuf, '=', argv, (sizeof(argv) / sizeof(argv[0])))) > 1) {
if (data && (lbuf = switch_core_session_strdup(session, data))
&& (argc = switch_separate_string(lbuf, '=', argv, (sizeof(argv) / sizeof(argv[0])))) > 1) {
switch_size_t retsize;
switch_time_exp_t tm;
char date[80] = "";
@@ -459,26 +463,26 @@ static void strftime_function(switch_core_session_t *session, char *data)
static switch_status_t strepoch_api_function(char *data, switch_core_session_t *session, switch_stream_handle_t *stream)
{
switch_time_t out;
if (switch_strlen_zero(data)) {
out = switch_time_now();
} else {
out = switch_str_time(data);
}
switch_time_t out;
stream->write_function(stream, "%d", (uint32_t)((out) / (int64_t)(1000000)) );
if (switch_strlen_zero(data)) {
out = switch_time_now();
} else {
out = switch_str_time(data);
}
stream->write_function(stream, "%d", (uint32_t) ((out) / (int64_t) (1000000)));
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t strftime_api_function(char *fmt, switch_core_session_t *session, switch_stream_handle_t *stream)
{
switch_size_t retsize;
switch_time_exp_t tm;
char date[80] = "";
switch_time_exp_lt(&tm, switch_time_now());
switch_strftime(date, &retsize, sizeof(date), fmt ? fmt : "%Y-%m-%d %T", &tm);
stream->write_function(stream, "%s", date);
@@ -493,14 +497,15 @@ static switch_status_t presence_api_function(char *fmt, switch_core_session_t *s
int argc = 0;
switch_event_types_t type = SWITCH_EVENT_PRESENCE_IN;
if (fmt && (lbuf = strdup(fmt)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) > 0) {
if (fmt && (lbuf = strdup(fmt))
&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) > 0) {
if (!strcasecmp(argv[0], "out")) {
type = SWITCH_EVENT_PRESENCE_OUT;
} else if (argc != 4) {
stream->write_function(stream, "Invalid");
return SWITCH_STATUS_SUCCESS;
}
if (switch_event_create(&event, type) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "proto", "dp");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "login", "%s", __FILE__);
@@ -527,9 +532,10 @@ static switch_status_t chat_api_function(char *fmt, switch_core_session_t *sessi
char *lbuf, *argv[4];
int argc = 0;
if (fmt && (lbuf = strdup(fmt)) && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
if (fmt && (lbuf = strdup(fmt))
&& (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 4) {
switch_chat_interface_t *ci;
if ((ci = switch_loadable_module_get_chat_interface(argv[0]))) {
ci->chat_send("dp", argv[1], argv[2], "", argv[3], "");
stream->write_function(stream, "Sent");
@@ -539,7 +545,7 @@ static switch_status_t chat_api_function(char *fmt, switch_core_session_t *sessi
} else {
stream->write_function(stream, "Invalid");
}
return SWITCH_STATUS_SUCCESS;
}
@@ -551,7 +557,7 @@ static switch_ivr_action_t menu_handler(switch_ivr_menu_t *menu, char *param, ch
switch_ivr_action_t action = SWITCH_IVR_ACTION_NOOP;
if (param != NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "menu_handler '%s'\n",param);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "menu_handler '%s'\n", param);
}
return action;
@@ -563,7 +569,7 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
switch_channel_t *channel = switch_core_session_get_channel(session);
char *params;
if (channel && data && (params = switch_core_session_strdup(session,data))) {
if (channel && data && (params = switch_core_session_strdup(session, data))) {
switch_xml_t cxml = NULL, cfg = NULL, xml_menus = NULL, xml_menu = NULL;
// Open the config from the xml registry
@@ -577,16 +583,17 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
switch_ivr_menu_t *menu_stack = NULL;
// build a menu tree and execute it
if (switch_ivr_menu_stack_xml_init(&xml_ctx,NULL) == SWITCH_STATUS_SUCCESS
if (switch_ivr_menu_stack_xml_init(&xml_ctx, NULL) == SWITCH_STATUS_SUCCESS
#ifdef _TEST_CALLBACK_
&& switch_ivr_menu_stack_xml_add_custom(xml_ctx, "custom", &menu_handler) == SWITCH_STATUS_SUCCESS
&& switch_ivr_menu_stack_xml_add_custom(xml_ctx, "custom",
&menu_handler) == SWITCH_STATUS_SUCCESS
#endif
&& switch_ivr_menu_stack_xml_build(xml_ctx,&menu_stack,xml_menus,xml_menu) == SWITCH_STATUS_SUCCESS)
{
&& switch_ivr_menu_stack_xml_build(xml_ctx, &menu_stack, xml_menus,
xml_menu) == SWITCH_STATUS_SUCCESS) {
switch_xml_free(cxml);
cxml = NULL;
switch_channel_pre_answer(channel);
switch_ivr_menu_execute(session,menu_stack,params,NULL);
switch_ivr_menu_execute(session, menu_stack, params, NULL);
switch_ivr_menu_stack_free(menu_stack);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create menu '%s'\n", params);
@@ -670,7 +677,7 @@ static switch_application_interface_t sched_hangup_application_interface = {
static const switch_application_interface_t queuedtmf_application_interface = {
/*.interface_name */ "queue_dtmf",
/*.application_function */ queue_dtmf_function,
/*.application_function */ queue_dtmf_function,
/* long_desc */ "Queue dtmf to be sent from a session",
/* short_desc */ "Queue dtmf to be sent",
/* syntax */ "<dtmf_data>",
@@ -680,7 +687,7 @@ static const switch_application_interface_t queuedtmf_application_interface = {
static const switch_application_interface_t redirect_application_interface = {
/*.interface_name */ "redirect",
/*.application_function */ redirect_function,
/*.application_function */ redirect_function,
/* long_desc */ "Send a redirect message to a session.",
/* short_desc */ "Send session redirect",
/* syntax */ "<redirect_data>",
@@ -690,7 +697,7 @@ static const switch_application_interface_t redirect_application_interface = {
static const switch_application_interface_t ivr_application_interface = {
/*.interface_name */ "ivr",
/*.application_function */ ivr_application_function,
/*.application_function */ ivr_application_function,
/* long_desc */ "Run an ivr menu.",
/* short_desc */ "Run an ivr menu",
/* syntax */ "<menu_name>",
@@ -700,7 +707,7 @@ static const switch_application_interface_t ivr_application_interface = {
static const switch_application_interface_t detect_speech_application_interface = {
/*.interface_name */ "detect_speech",
/*.application_function */ detect_speech_function,
/*.application_function */ detect_speech_function,
/* long_desc */ "Detect speech on a channel.",
/* short_desc */ "Detect speech",
/* syntax */ "<mod_name> <gram_name> <gram_path> [<addr>] OR grammar <gram_name> [<path>] OR pause OR resume",
@@ -777,7 +784,6 @@ static const switch_application_interface_t hangup_application_interface = {
/* syntax */ "[<cause>]",
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next */ &log_application_interface
};
static const switch_application_interface_t answer_application_interface = {
@@ -788,7 +794,6 @@ static const switch_application_interface_t answer_application_interface = {
/* syntax */ "",
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next */ &hangup_application_interface
};
static const switch_application_interface_t pre_answer_application_interface = {
@@ -799,7 +804,6 @@ static const switch_application_interface_t pre_answer_application_interface = {
/* syntax */ "",
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next */ &answer_application_interface
};
static const switch_application_interface_t eval_application_interface = {
@@ -810,7 +814,6 @@ static const switch_application_interface_t eval_application_interface = {
/* syntax */ "",
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next */ &pre_answer_application_interface
};
static const switch_application_interface_t phrase_application_interface = {
@@ -821,7 +824,6 @@ static const switch_application_interface_t phrase_application_interface = {
/* syntax */ "<macro_name>,<data>",
/* flags */ SAF_NONE,
/*.next */ &eval_application_interface
};
static const switch_application_interface_t strftime_application_interface = {
@@ -832,13 +834,13 @@ static const switch_application_interface_t strftime_application_interface = {
/* syntax */ NULL,
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next */ &phrase_application_interface
};
static const switch_application_interface_t sleep_application_interface = {
/*.interface_name */ "sleep",
/*.application_function */ sleep_function,
/* long_desc */ "Pause the channel for a given number of milliseconds, consuming the audio for that period of time.",
/* long_desc */
"Pause the channel for a given number of milliseconds, consuming the audio for that period of time.",
/* short_desc */ "Pause a channel",
/* syntax */ "<pausemilliseconds>",
/* flags */ SAF_NONE,
@@ -875,7 +877,8 @@ static const switch_loadable_module_interface_t mod_dptools_module_interface = {
/*.api_interface */ &presence_api_interface
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
+3 -2
View File
@@ -38,7 +38,7 @@ static void echo_function(switch_core_session_t *session, char *data)
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_channel_answer(channel);
@@ -67,7 +67,8 @@ static switch_loadable_module_interface_t echo_module_interface = {
/*.directory_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &echo_module_interface;
+148 -137
View File
@@ -48,10 +48,10 @@ struct enum_record {
typedef struct enum_record enum_record_t;
struct query {
const char *name; /* original query string */
const char *name; /* original query string */
char *number;
unsigned char dn[DNS_MAXDN];
enum dns_type qtyp; /* type of the query */
enum dns_type qtyp; /* type of the query */
enum_record_t *results;
};
typedef struct query enum_query_t;
@@ -77,7 +77,7 @@ static struct {
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_root, globals.root)
static void add_route(char *service, char *regex, char *replace)
static void add_route(char *service, char *regex, char *replace)
{
enum_route_t *route, *rp;
@@ -86,11 +86,11 @@ static void add_route(char *service, char *regex, char *replace)
}
memset(route, 0, sizeof(*route));
route->service = strdup(service);
route->regex = strdup(regex);
route->replace = strdup(replace);
if (!globals.route_order) {
globals.route_order = route;
} else {
@@ -107,8 +107,8 @@ static void add_route(char *service, char *regex, char *replace)
static switch_status_t load_config(void)
{
char *cf = "enum.conf";
switch_xml_t cfg, xml = NULL, param, settings, route, routes;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_xml_t cfg, xml = NULL, param, settings, route, routes;
switch_status_t status = SWITCH_STATUS_SUCCESS;
memset(&globals, 0, sizeof(globals));
if (switch_core_new_memory_pool(&globals.pool) != SWITCH_STATUS_SUCCESS) {
@@ -119,39 +119,39 @@ static switch_status_t load_config(void)
switch_core_hash_init(&globals.routes, globals.pool);
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
status = SWITCH_STATUS_FALSE;
goto done;
}
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
status = SWITCH_STATUS_FALSE;
goto done;
}
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "default-root")) {
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "default-root")) {
set_global_root(val);
} else if (!strcasecmp(var, "log-level-trace")) {
}
}
}
} else if (!strcasecmp(var, "log-level-trace")) {
if ((routes = switch_xml_child(cfg, "routes"))) {
for (route = switch_xml_child(routes, "route"); route; route = route->next) {
char *service = (char *) switch_xml_attr_soft(route, "service");
char *regex = (char *) switch_xml_attr_soft(route, "regex");
char *replace = (char *) switch_xml_attr_soft(route, "replace");
}
}
}
if ((routes = switch_xml_child(cfg, "routes"))) {
for (route = switch_xml_child(routes, "route"); route; route = route->next) {
char *service = (char *) switch_xml_attr_soft(route, "service");
char *regex = (char *) switch_xml_attr_soft(route, "regex");
char *replace = (char *) switch_xml_attr_soft(route, "replace");
if (service && regex && replace) {
add_route(service, regex, replace);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Route!\n");
}
}
}
done:
}
}
done:
if (xml) {
switch_xml_free(xml);
@@ -168,20 +168,20 @@ static switch_status_t load_config(void)
static char *reverse_number(char *in, char *root)
{
switch_size_t len;
char *out = NULL;
char *y,*z;
switch_size_t len;
char *out = NULL;
char *y, *z;
if (!(in && root)) {
return NULL;
}
if (!(in && root)) {
return NULL;
}
len = (strlen(in) * 2) + strlen(root) + 1;
if ((out = malloc(len))) {
memset(out, 0, len);
len = (strlen(in) * 2) + strlen(root) + 1;
if ((out = malloc(len))) {
memset(out, 0, len);
z = out;
for(y = in + (strlen(in) - 1); y; y--) {
z = out;
for (y = in + (strlen(in) - 1); y; y--) {
if (*y > 47 && *y < 58) {
*z++ = *y;
*z++ = '.';
@@ -189,21 +189,22 @@ static char *reverse_number(char *in, char *root)
if (y == in) {
break;
}
}
strcat(z, root);
}
}
strcat(z, root);
}
return out;
}
static void dnserror(enum_query_t *q, int errnum) {
static void dnserror(enum_query_t * q, int errnum)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to lookup %s record for %s: %s\n",
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "unable to lookup %s record for %s: %s\n",
dns_typename(q->qtyp), dns_dntosp(q->dn), dns_strerror(errnum));
}
static void add_result(enum_query_t *q, int order, int preference, char *service, char *route)
static void add_result(enum_query_t * q, int order, int preference, char *service, char *route)
{
enum_record_t *new_result, *rp, *prev = NULL;
@@ -213,12 +214,12 @@ static void add_result(enum_query_t *q, int order, int preference, char *service
}
memset(new_result, 0, sizeof(*new_result));
new_result->order = order;
new_result->preference = preference;
new_result->service = strdup(service);
new_result->route = strdup(route);
if (!q->results) {
q->results = new_result;
@@ -227,12 +228,12 @@ static void add_result(enum_query_t *q, int order, int preference, char *service
rp = q->results;
while(rp && strcmp(rp->service, new_result->service)) {
while (rp && strcmp(rp->service, new_result->service)) {
prev = rp;
rp = rp->next;
}
while(rp && !strcmp(rp->service, new_result->service) && new_result->order > rp->order) {
while (rp && !strcmp(rp->service, new_result->service) && new_result->order > rp->order) {
prev = rp;
rp = rp->next;
}
@@ -241,7 +242,7 @@ static void add_result(enum_query_t *q, int order, int preference, char *service
prev = rp;
rp = rp->next;
}
if (prev) {
new_result->next = rp;
prev->next = new_result;
@@ -252,11 +253,11 @@ static void add_result(enum_query_t *q, int order, int preference, char *service
}
static void free_results(enum_record_t **results)
static void free_results(enum_record_t ** results)
{
enum_record_t *fp, *rp;
for(rp = *results; rp;) {
for (rp = *results; rp;) {
fp = rp;
rp = rp->next;
switch_safe_free(fp->service);
@@ -266,7 +267,8 @@ static void free_results(enum_record_t **results)
*results = NULL;
}
static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *rr) {
static void parse_rr(const struct dns_parse *p, enum_query_t * q, struct dns_rr *rr)
{
const unsigned char *pkt = p->dnsp_pkt;
const unsigned char *end = p->dnsp_end;
const unsigned char *dptr = rr->dnsrr_dptr;
@@ -282,25 +284,26 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
char *regex = NULL;
char *replace = NULL;
int argc = 0;
char *argv[4] = {0};
char *argv[4] = { 0 };
int leap;
switch(rr->dnsrr_typ) {
switch (rr->dnsrr_typ) {
case DNS_T_NAPTR: /* prio weight port targetDN */
case DNS_T_NAPTR: /* prio weight port targetDN */
c = dptr;
c += 2 + 2 + 2;
if (dns_getdn(pkt, &c, end, dn, DNS_MAXDN) <= 0 || c != dend) goto xperr;
if (dns_getdn(pkt, &c, end, dn, DNS_MAXDN) <= 0 || c != dend)
goto xperr;
c = dptr;
leap = *dn;
nme = (char *)dn+1;
nme = (char *) dn + 1;
order = dns_get16(c+0);
preference = dns_get16(c+2);
flags = (char) dns_get16(c+4);
order = dns_get16(c + 0);
preference = dns_get16(c + 2);
flags = (char) dns_get16(c + 4);
if ((ptr = nme+leap)) {
if ((ptr = nme + leap)) {
service = nme;
*ptr++ = '\0';
argc = switch_separate_string(ptr, '!', argv, (sizeof(argv) / sizeof(argv[0])));
@@ -308,7 +311,7 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
replace = argv[2];
}
for(ptr = replace; ptr && *ptr; ptr++) {
for (ptr = replace; ptr && *ptr; ptr++) {
if (*ptr == '\\') {
*ptr = '$';
}
@@ -326,15 +329,17 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
if ((proceed = switch_regex_perform(q->number, regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if (strchr(regex, '(')) {
switch_perform_substitution(re, proceed, replace, q->number, substituted, sizeof(substituted), ovector);
switch_perform_substitution(re, proceed, replace, q->number, substituted, sizeof(substituted),
ovector);
uri = substituted;
} else {
uri = replace;
}
if ((route = (enum_route_t *) switch_core_hash_find(globals.routes, service))){
if ((route = (enum_route_t *) switch_core_hash_find(globals.routes, service))) {
switch_regex_safe_free(re);
if ((proceed = switch_regex_perform(uri, route->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if ((proceed =
switch_regex_perform(uri, route->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
if (strchr(route->regex, '(')) {
switch_perform_substitution(re, proceed, route->replace, uri, rbuf, sizeof(rbuf), ovector);
uri = rbuf;
@@ -343,7 +348,7 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
}
}
}
add_result(q, order, preference, service, uri);
}
@@ -358,12 +363,13 @@ static void parse_rr(const struct dns_parse *p, enum_query_t *q, struct dns_rr *
return;
xperr:
xperr:
//printf("<parse error>\n");
return;
}
static void dnscb(struct dns_ctx *ctx, void *result, void *data) {
static void dnscb(struct dns_ctx *ctx, void *result, void *data)
{
int r = dns_status(ctx);
enum_query_t *q = data;
struct dns_parse p;
@@ -375,25 +381,25 @@ static void dnscb(struct dns_ctx *ctx, void *result, void *data) {
dnserror(q, r);
return;
}
pkt = result; end = pkt + r; cur = dns_payload(pkt);
pkt = result;
end = pkt + r;
cur = dns_payload(pkt);
dns_getdn(pkt, &cur, end, dn, sizeof(dn));
dns_initparse(&p, NULL, pkt, cur, end);
p.dnsp_qcls = p.dnsp_qtyp = 0;
qdn = dn;
nrr = 0;
while((r = dns_nextrr(&p, &rr)) > 0) {
if (!dns_dnequal(qdn, rr.dnsrr_dn)) continue;
if ((qcls == DNS_C_ANY || qcls == rr.dnsrr_cls) &&
(q->qtyp == DNS_T_ANY || q->qtyp == rr.dnsrr_typ))
while ((r = dns_nextrr(&p, &rr)) > 0) {
if (!dns_dnequal(qdn, rr.dnsrr_dn))
continue;
if ((qcls == DNS_C_ANY || qcls == rr.dnsrr_cls) && (q->qtyp == DNS_T_ANY || q->qtyp == rr.dnsrr_typ))
++nrr;
else if (rr.dnsrr_typ == DNS_T_CNAME && !nrr) {
if (dns_getdn(pkt, &rr.dnsrr_dptr, end,
p.dnsp_dnbuf, sizeof(p.dnsp_dnbuf)) <= 0 ||
rr.dnsrr_dptr != rr.dnsrr_dend) {
p.dnsp_dnbuf, sizeof(p.dnsp_dnbuf)) <= 0 || rr.dnsrr_dptr != rr.dnsrr_dend) {
r = DNS_E_PROTOCOL;
break;
}
else {
} else {
qdn = p.dnsp_dnbuf;
}
}
@@ -409,28 +415,28 @@ static void dnscb(struct dns_ctx *ctx, void *result, void *data) {
dns_rewind(&p, NULL);
p.dnsp_qtyp = q->qtyp;
p.dnsp_qcls = qcls;
while(dns_nextrr(&p, &rr)) {
while (dns_nextrr(&p, &rr)) {
parse_rr(&p, q, &rr);
}
free(result);
}
static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results)
static switch_status_t enum_lookup(char *root, char *in, enum_record_t ** results)
{
switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
switch_status_t sstatus = SWITCH_STATUS_SUCCESS;
char *name = NULL;
enum_query_t query = {0};
enum_query_t query = { 0 };
enum dns_type l_qtyp = DNS_T_NAPTR;
int i = 0, abs = 0;
dns_socket fd = (dns_socket)-1;
dns_socket fd = (dns_socket) - 1;
fd_set fds;
struct timeval tv = {0};
struct timeval tv = { 0 };
time_t now = 0;
struct dns_ctx *nctx = NULL;
char *num, *mnum = NULL;
if (*in != '+') {
mnum = switch_mprintf("+%s", in);
num = mnum;
@@ -458,7 +464,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
goto done;
}
dns_ptodn(name, (unsigned int)strlen(name), query.dn, sizeof(query.dn), &abs);
dns_ptodn(name, (unsigned int) strlen(name), query.dn, sizeof(query.dn), &abs);
query.name = name;
query.number = num;
query.qtyp = l_qtyp;
@@ -466,7 +472,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
if (abs) {
abs = DNS_NOSRCH;
}
if (!dns_submit_dn(nctx, query.dn, qcls, l_qtyp, abs, 0, dnscb, &query)) {
dnserror(&query, dns_status(nctx));
}
@@ -474,7 +480,7 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
FD_ZERO(&fds);
now = 0;
while((i = dns_timeouts(nctx, -1, now)) > 0) {
while ((i = dns_timeouts(nctx, -1, now)) > 0) {
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4389 4127)
@@ -485,9 +491,10 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
#endif
tv.tv_sec = i;
tv.tv_usec = 0;
i = select((int)(fd+1), &fds, 0, 0, &tv);
i = select((int) (fd + 1), &fds, 0, 0, &tv);
now = time(NULL);
if (i > 0) dns_ioevent(nctx, now);
if (i > 0)
dns_ioevent(nctx, now);
}
if (!query.results) {
@@ -497,17 +504,17 @@ static switch_status_t enum_lookup(char *root, char *in, enum_record_t **results
*results = query.results;
query.results = NULL;
done:
done:
if (fd > -1) {
closesocket(fd);
fd = (dns_socket)-1;
fd = (dns_socket) - 1;
}
if (nctx) {
dns_free(nctx);
}
switch_safe_free(name);
switch_safe_free(mnum);
@@ -524,34 +531,37 @@ static switch_caller_extension_t *enum_dialplan_hunt(switch_core_session_t *sess
enum_route_t *rtp;
char *dp = (char *) arg;
assert(channel != NULL);
assert(channel != NULL);
caller_profile = switch_channel_get_caller_profile(channel);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ENUM Lookup on %s\n", caller_profile->destination_number);
if (enum_lookup(switch_strlen_zero(dp) ? globals.root : dp, caller_profile->destination_number, &results) == SWITCH_STATUS_SUCCESS) {
if ((extension = switch_caller_extension_new(session, caller_profile->destination_number, caller_profile->destination_number)) == 0) {
if (enum_lookup(switch_strlen_zero(dp) ? globals.root : dp, caller_profile->destination_number, &results) ==
SWITCH_STATUS_SUCCESS) {
if ((extension =
switch_caller_extension_new(session, caller_profile->destination_number,
caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
free_results(&results);
free_results(&results);
return NULL;
}
switch_channel_set_variable(channel, SWITCH_HANGUP_AFTER_BRIDGE_VARIABLE, "true");
for(rtp = globals.route_order; rtp; rtp = rtp->next) {
for(rp = results; rp; rp = rp->next) {
for (rtp = globals.route_order; rtp; rtp = rtp->next) {
for (rp = results; rp; rp = rp->next) {
if (!strcmp(rtp->service, rp->service)) {
switch_caller_extension_add_application(session, extension, "bridge", rp->route);
switch_caller_extension_add_application(session, extension, "bridge", rp->route);
}
}
}
free_results(&results);
free_results(&results);
}
if (extension) {
switch_channel_set_state(channel, CS_EXECUTE);
}
switch_channel_set_state(channel, CS_EXECUTE);
}
return extension;
@@ -560,7 +570,7 @@ static switch_caller_extension_t *enum_dialplan_hunt(switch_core_session_t *sess
static void enum_app_function(switch_core_session_t *session, char *data)
{
int argc = 0;
char *argv[4] = {0};
char *argv[4] = { 0 };
char *mydata = NULL;
char *dest = NULL, *root = NULL;
enum_record_t *results, *rp;
@@ -575,26 +585,27 @@ static void enum_app_function(switch_core_session_t *session, char *data)
assert(channel != NULL);
if (!(mydata = switch_core_session_strdup(session, data))) {
return;
}
return;
}
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
dest = argv[0];
root = argv[1] ? argv[1] : globals.root;
root = argv[1] ? argv[1] : globals.root;
if (enum_lookup(root, data, &results) == SWITCH_STATUS_SUCCESS) {
switch_hash_index_t *hi;
void *vval;
const void *vvar;
for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi;
hi = switch_hash_next(hi)) {
switch_hash_this(hi, &vvar, NULL, &vval);
if (vvar && !strncmp(vvar, "enum_", 5)) {
switch_channel_set_variable(channel, (char *) vvar, NULL);
}
}
for(rtp = globals.route_order; rtp; rtp = rtp->next) {
for(rp = results; rp; rp = rp->next) {
for (rtp = globals.route_order; rtp; rtp = rtp->next) {
for (rp = results; rp; rp = rp->next) {
if (!strcmp(rtp->service, rp->service)) {
snprintf(vbuf, sizeof(vbuf), "enum_route_%d", cnt++);
switch_channel_set_variable(channel, vbuf, rp->route);
@@ -608,19 +619,19 @@ static void enum_app_function(switch_core_session_t *session, char *data)
}
snprintf(vbuf, sizeof(vbuf), "%d", cnt);
switch_channel_set_variable(channel, "enum_route_count", vbuf);
*(rbuf+strlen(rbuf)-1) = '\0';
*(rbuf + strlen(rbuf) - 1) = '\0';
switch_channel_set_variable(channel, "enum_auto_route", rbuf);
free_results(&results);
free_results(&results);
}
}
}
static switch_status_t enum_function(char *data, switch_core_session_t *session, switch_stream_handle_t *stream)
{
int argc = 0;
char *argv[4] = {0};
char *argv[4] = { 0 };
enum_record_t *results, *rp;
char *mydata = NULL;
char *dest = NULL, *root = NULL;
@@ -639,35 +650,36 @@ static switch_status_t enum_function(char *data, switch_core_session_t *session,
if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
dest = argv[0];
root = argv[1] ? argv[1] : globals.root;
if (!enum_lookup(root, data, &results) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "No Match!\n");
return SWITCH_STATUS_SUCCESS;
}
stream->write_function(stream,
"\nOffered Routes:\n"
"Order\tPref\tService \tRoute\n"
"==============================================================================\n");
for(rp = results; rp; rp = rp->next) {
for (rp = results; rp; rp = rp->next) {
stream->write_function(stream, "%d\t%d\t%-10s\t%s\n", rp->order, rp->preference, rp->service, rp->route);
}
stream->write_function(stream,
"\nSupported Routes:\n"
"Order\tPref\tService \tRoute\n"
"==============================================================================\n");
for(rtp = globals.route_order; rtp; rtp = rtp->next) {
for(rp = results; rp; rp = rp->next) {
for (rtp = globals.route_order; rtp; rtp = rtp->next) {
for (rp = results; rp; rp = rp->next) {
if (!strcmp(rtp->service, rp->service)) {
stream->write_function(stream, "%d\t%d\t%-10s\t%s\n", rp->order, rp->preference, rp->service, rp->route);
stream->write_function(stream, "%d\t%d\t%-10s\t%s\n", rp->order, rp->preference, rp->service,
rp->route);
}
}
}
free_results(&results);
} else {
stream->write_function(stream, "Invalid Input!\n");
@@ -678,14 +690,14 @@ static switch_status_t enum_function(char *data, switch_core_session_t *session,
static const switch_dialplan_interface_t enum_dialplan_interface = {
/*.interface_name = */ "enum",
/*.hunt_function = */ enum_dialplan_hunt
/*.next = NULL */
/*.interface_name = */ "enum",
/*.hunt_function = */ enum_dialplan_hunt
/*.next = NULL */
};
static const switch_application_interface_t enum_application_interface = {
/*.interface_name */ "enum",
/*.application_function */ enum_app_function,
/*.application_function */ enum_app_function,
/* long_desc */ "Perform an ENUM lookup",
/* short_desc */ "Perform an ENUM lookup",
/* syntax */ "<number> [<root>]",
@@ -714,7 +726,8 @@ static switch_loadable_module_interface_t enum_module_interface = {
/*.directory_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
if (dns_init(0) < 0) {
@@ -729,5 +742,3 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+96 -110
View File
@@ -39,16 +39,17 @@ static const char modname[] = "mod_ivrtest";
dtmf handler function you can hook up to be executed when a digit is dialed during playback
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
*/
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf,
unsigned int buflen)
{
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF: {
char *dtmf = (char *) input;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
switch_copy_string((char *)buf, dtmf, buflen);
return SWITCH_STATUS_BREAK;
}
case SWITCH_INPUT_TYPE_DTMF:{
char *dtmf = (char *) input;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
switch_copy_string((char *) buf, dtmf, buflen);
return SWITCH_STATUS_BREAK;
}
break;
default:
break;
@@ -72,7 +73,7 @@ static void xml_function(switch_core_session_t *session, char *data)
for (team = switch_xml_child(f1, "team"); team; team = team->next) {
teamname = switch_xml_attr_soft(team, "name");
for (driver = switch_xml_child(team, "driver"); driver; driver = driver->next) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"%s, %s: %s\n", switch_xml_child(driver, "name")->txt, teamname,
switch_xml_child(driver, "points")->txt);
}
@@ -84,7 +85,7 @@ static void xml_function(switch_core_session_t *session, char *data)
static void ivr_application_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
char *params = switch_core_session_strdup(session,data);
char *params = switch_core_session_strdup(session, data);
if (channel != NULL && params != NULL) {
switch_ivr_menu_t *menu = NULL, *sub_menu = NULL;
@@ -98,12 +99,7 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
"main",
"please enter some numbers so i can figure out if I have any bugs or not",
"enter some numbers",
NULL,
"I have no idea what that is",
"cepstral",
"david",
NULL,
15000, 10, NULL);
NULL, "I have no idea what that is", "cepstral", "david", NULL, 15000, 10, NULL);
status = switch_ivr_menu_init(&sub_menu,
@@ -111,12 +107,7 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
"sub",
"/ram/congrats.wav",
"/ram/extension.wav",
NULL,
"/ram/invalid.wav",
NULL,
NULL,
NULL,
15000, 10, NULL);
NULL, "/ram/invalid.wav", NULL, NULL, NULL, 15000, 10, NULL);
if (status == SWITCH_STATUS_SUCCESS) {
// build the menu
@@ -125,10 +116,10 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
switch_ivr_menu_bind_action(menu, SWITCH_IVR_ACTION_EXECMENU, "sub", "3");
//switch_ivr_menu_bind_action(menu, SWITCH_IVR_ACTION_PLAYSOUND, "/usr/local/freeswitch/sounds/3.wav", "3");
switch_ivr_menu_bind_action(sub_menu, SWITCH_IVR_ACTION_PLAYSOUND, "/ram/swimp.raw", "1");
switch_ivr_menu_bind_action(sub_menu, SWITCH_IVR_ACTION_BACK, NULL, "2");
// start the menu
status = switch_ivr_menu_execute(session, menu, "main", NULL);
@@ -136,11 +127,11 @@ static void ivr_application_function(switch_core_session_t *session, char *data)
// cleaup the menu
switch_ivr_menu_stack_free(menu);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to build menu %s\n",params);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unable to build menu %s\n", params);
}
switch_ivr_play_file(session, NULL,"/ram/goodbye.wav",NULL);
switch_ivr_play_file(session, NULL, "/ram/goodbye.wav", NULL);
}
}
@@ -151,15 +142,13 @@ static void dirtest_function(switch_core_session_t *session, char *data)
switch_directory_handle_t dh;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
if (switch_core_directory_open(&dh,
if (switch_core_directory_open(&dh,
"ldap",
"ldap.freeswitch.org",
"cn=Manager,dc=freeswitch,dc=org",
"test",
NULL) != SWITCH_STATUS_SUCCESS) {
"cn=Manager,dc=freeswitch,dc=org", "test", NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't connect\n");
return;
}
@@ -177,16 +166,17 @@ static void dirtest_function(switch_core_session_t *session, char *data)
}
static switch_status_t show_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
static switch_status_t show_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf,
unsigned int buflen)
{
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF: {
char *dtmf = (char *) input;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
case SWITCH_INPUT_TYPE_DTMF:{
char *dtmf = (char *) input;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
switch_copy_string((char *)buf, dtmf, buflen);
}
switch_copy_string((char *) buf, dtmf, buflen);
}
break;
default:
break;
@@ -203,9 +193,9 @@ static void tts_function(switch_core_session_t *session, char *data)
char buf[10] = "";
char *argv[3];
int argc;
switch_input_args_t args = {0};
switch_input_args_t args = { 0 };
if(!(mydata = switch_core_session_strdup(session, (char *) data))) {
if (!(mydata = switch_core_session_strdup(session, (char *) data))) {
return;
}
@@ -221,14 +211,14 @@ static void tts_function(switch_core_session_t *session, char *data)
}
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
switch_channel_answer(channel);
assert(channel != NULL);
switch_channel_answer(channel);
codec = switch_core_session_get_read_codec(session);
args.input_callback = show_dtmf;
args.buf = buf;
args.buflen = sizeof(buf);
args.input_callback = show_dtmf;
args.buf = buf;
args.buflen = sizeof(buf);
switch_ivr_speak_text(session, tts_name, voice_name, codec->implementation->samples_per_second, text, &args);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Done\n");
}
@@ -236,17 +226,17 @@ static void tts_function(switch_core_session_t *session, char *data)
#ifdef BUGTEST
static switch_bool_t bug_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
{
switch_frame_t *frame;
switch_frame_t *frame;
switch(type) {
switch (type) {
case SWITCH_ABC_TYPE_WRITE_REPLACE:
frame = switch_core_media_bug_get_replace_frame(bug);
switch_core_media_bug_set_replace_frame(bug, frame);
printf("W00t\n");
break;
default:
break;
}
frame = switch_core_media_bug_get_replace_frame(bug);
switch_core_media_bug_set_replace_frame(bug, frame);
printf("W00t\n");
break;
default:
break;
}
return SWITCH_TRUE;
}
@@ -257,56 +247,46 @@ static void bugtest_function(switch_core_session_t *session, char *data)
#ifdef BUGTEST
switch_media_bug_t *bug;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status;
switch_status_t status;
if ((status = switch_core_media_bug_add(session,
bug_callback,
NULL,
SMBF_WRITE_REPLACE,
&bug)) != SWITCH_STATUS_SUCCESS) {
bug_callback, NULL, SMBF_WRITE_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return;
return;
}
#endif
//switch_ivr_schedule_broadcast(time(NULL) + 10, switch_core_session_get_uuid(session), "/Users/anthm/sr8k.wav", SMF_ECHO_ALEG);
//switch_ivr_schedule_transfer(time(NULL) + 10, switch_core_session_get_uuid(session), "2000", NULL, NULL);
//switch_ivr_schedule_hangup(time(NULL) + 10, switch_core_session_get_uuid(session), SWITCH_CAUSE_ALLOTTED_TIMEOUT);
switch_ivr_play_file(session, NULL, data, NULL);
switch_ivr_play_file(session, NULL, data, NULL);
}
#if 1
static void asrtest_function(switch_core_session_t *session, char *data)
{
switch_ivr_detect_speech(session,
"lumenvox",
"demo",
data,
"127.0.0.1",
NULL);
switch_ivr_detect_speech(session, "lumenvox", "demo", data, "127.0.0.1", NULL);
}
#else
#else
static void asrtest_function(switch_core_session_t *session, char *data)
{
switch_asr_handle_t ah = {0};
switch_asr_handle_t ah = { 0 };
switch_asr_flag_t flags = SWITCH_ASR_FLAG_NONE;
switch_channel_t *channel = switch_core_session_get_channel(session);
char *codec_name = "L16";
switch_codec_t codec = {0}, *read_codec;
switch_frame_t write_frame = {0}, *write_frame_p = NULL;
switch_codec_t codec = { 0 }, *read_codec;
switch_frame_t write_frame = { 0 }, *write_frame_p = NULL;
char xdata[1024] = "";
read_codec = switch_core_session_get_read_codec(session);
assert(read_codec != NULL);
if (switch_core_asr_open(&ah, "lumenvox",
read_codec->implementation->iananame,
8000,
"127.0.0.1",
&flags,
switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
"127.0.0.1", &flags, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
if (strcmp(ah.codec, read_codec->implementation->iananame)) {
if (switch_core_codec_init(&codec,
ah.codec,
@@ -317,36 +297,39 @@ static void asrtest_function(switch_core_session_t *session, char *data)
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
switch_core_session_set_read_codec(session, &codec);
switch_core_session_set_read_codec(session, &codec);
write_frame.data = xdata;
write_frame.buflen = sizeof(xdata);
write_frame.codec = &codec;
write_frame_p = &write_frame;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Failed %s@%uhz %u channels %dms\n",
codec_name, read_codec->implementation->samples_per_second, read_codec->implementation->number_of_channels,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name,
read_codec->implementation->samples_per_second,
read_codec->implementation->number_of_channels,
read_codec->implementation->microseconds_per_frame / 1000);
switch_core_session_reset(session);
return;
}
}
if (switch_core_asr_load_grammar(&ah, "demo", "/opt/lumenvox/engine_7.0/Lang/BuiltinGrammars/ABNFPhone.gram") != SWITCH_STATUS_SUCCESS) {
if (switch_core_asr_load_grammar(&ah, "demo", "/opt/lumenvox/engine_7.0/Lang/BuiltinGrammars/ABNFPhone.gram") !=
SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error loading Grammar\n");
goto end;
}
while(switch_channel_ready(channel)) {
while (switch_channel_ready(channel)) {
switch_frame_t *read_frame;
switch_status_t status = switch_core_session_read_frame(session, &read_frame, -1, 0);
char *xmlstr = NULL;
switch_xml_t xml = NULL, result;
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
if (switch_test_flag(read_frame, SFF_CNG)) {
continue;
}
@@ -355,7 +338,7 @@ static void asrtest_function(switch_core_session_t *session, char *data)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Feeding Data\n");
break;
}
if (switch_core_asr_check_results(&ah, &flags) == SWITCH_STATUS_SUCCESS) {
if (switch_core_asr_get_results(&ah, &xmlstr, &flags) != SWITCH_STATUS_SUCCESS) {
break;
@@ -368,7 +351,7 @@ static void asrtest_function(switch_core_session_t *session, char *data)
}
switch_safe_free(xmlstr);
}
if (write_frame_p) {
write_frame.datalen = read_frame->datalen;
switch_core_session_write_frame(session, write_frame_p, -1, 0);
@@ -378,7 +361,7 @@ static void asrtest_function(switch_core_session_t *session, char *data)
}
}
end:
end:
if (write_frame_p) {
switch_core_session_set_read_codec(session, read_codec);
switch_core_codec_destroy(&codec);
@@ -400,9 +383,9 @@ static void ivrtest_function(switch_core_session_t *session, char *data)
char buf[10] = "";
char term;
char say[128] = "";
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_channel_answer(channel);
@@ -410,18 +393,19 @@ static void ivrtest_function(switch_core_session_t *session, char *data)
while (switch_channel_get_state(channel) == CS_EXECUTE) {
memset(buf, 0, sizeof(buf));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enter up to 10 digits, press # to terminate, * to hangup\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
"Enter up to 10 digits, press # to terminate, * to hangup\n");
if (data) {
switch_input_args_t args = {0};
switch_input_args_t args = { 0 };
/* you could have passed NULL instead of on_dtmf to get this exact behaviour (copy the digits to buf and stop playing)
but you may want to pass the function if you have something cooler to do...
*/
args.input_callback = on_dtmf;
args.buf = buf;
args.buflen = sizeof(buf);
*/
args.input_callback = on_dtmf;
args.buf = buf;
args.buflen = sizeof(buf);
status = switch_ivr_play_file(session, NULL, data, &args);
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
break;
@@ -440,7 +424,7 @@ static void ivrtest_function(switch_core_session_t *session, char *data)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, say);
switch_ivr_speak_text(session, "cepstral", "david", codec->implementation->samples_per_second, say, NULL);
}
}
@@ -449,9 +433,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "I globally hooked to [%s] on the hangup event\n", switch_channel_get_name(channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "I globally hooked to [%s] on the hangup event\n",
switch_channel_get_name(channel));
return SWITCH_STATUS_SUCCESS;
}
@@ -472,7 +457,7 @@ static const switch_application_interface_t bug_application_interface = {
/*.application_function */ bugtest_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE,
/*.next*/ NULL
/*.next */ NULL
};
static const switch_application_interface_t ivr_application_interface = {
@@ -480,7 +465,7 @@ static const switch_application_interface_t ivr_application_interface = {
/*.application_function */ ivr_application_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE,
/*.next*/ &bug_application_interface
/*.next */ &bug_application_interface
};
static const switch_application_interface_t xml_application_interface = {
@@ -488,7 +473,7 @@ static const switch_application_interface_t xml_application_interface = {
/*.application_function */ xml_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE,
/*.next*/ &ivr_application_interface
/*.next */ &ivr_application_interface
};
static const switch_application_interface_t disast_application_interface = {
@@ -496,7 +481,7 @@ static const switch_application_interface_t disast_application_interface = {
/*.application_function */ disast_function,
NULL, NULL, NULL,
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next*/ &xml_application_interface
/*.next */ &xml_application_interface
};
static const switch_application_interface_t tts_application_interface = {
@@ -504,7 +489,7 @@ static const switch_application_interface_t tts_application_interface = {
/*.application_function */ tts_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE,
/*.next*/ &disast_application_interface
/*.next */ &disast_application_interface
};
static const switch_application_interface_t dirtest_application_interface = {
@@ -512,7 +497,7 @@ static const switch_application_interface_t dirtest_application_interface = {
/*.application_function */ dirtest_function,
NULL, NULL, NULL,
/* flags */ SAF_SUPPORT_NOMEDIA,
/*.next*/ &tts_application_interface
/*.next */ &tts_application_interface
};
static const switch_application_interface_t ivrtest_application_interface = {
@@ -520,7 +505,7 @@ static const switch_application_interface_t ivrtest_application_interface = {
/*.application_function */ ivrtest_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE,
/*.next*/ &dirtest_application_interface
/*.next */ &dirtest_application_interface
};
static const switch_application_interface_t asrtest_application_interface = {
@@ -528,7 +513,7 @@ static const switch_application_interface_t asrtest_application_interface = {
/*.application_function */ asrtest_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE,
/*.next*/ &ivrtest_application_interface
/*.next */ &ivrtest_application_interface
};
static const switch_loadable_module_interface_t mod_ivrtest_module_interface = {
@@ -540,7 +525,8 @@ static const switch_loadable_module_interface_t mod_ivrtest_module_interface = {
/*.application_interface */ &asrtest_application_interface
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
+4 -3
View File
@@ -35,13 +35,13 @@ static const char modname[] = "mod_park";
static void park_function(switch_core_session_t *session, char *data)
{
switch_ivr_park(session, NULL);
}
static const switch_application_interface_t park_application_interface = {
/*.interface_name */ "park",
/*.application_function */ park_function,
NULL,NULL,NULL,
NULL, NULL, NULL,
/* flags */ SAF_NONE,
NULL
};
@@ -59,7 +59,8 @@ static switch_loadable_module_interface_t park_module_interface = {
/*.directory_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &park_module_interface;
@@ -38,24 +38,25 @@ static const char modname[] = "mod_playback";
dtmf handler function you can hook up to be executed when a digit is dialed during playback
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
*/
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf,
unsigned int buflen)
{
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF: {
char *dtmf = (char *) input;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
if (*dtmf == '*') {
return SWITCH_STATUS_BREAK;
case SWITCH_INPUT_TYPE_DTMF:{
char *dtmf = (char *) input;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Digits %s\n", dtmf);
if (*dtmf == '*') {
return SWITCH_STATUS_BREAK;
}
}
}
break;
default:
break;
}
return SWITCH_STATUS_SUCCESS;
}
@@ -64,28 +65,28 @@ static void speak_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
char buf[10];
char *argv[4] = {0};
char *argv[4] = { 0 };
int argc;
char *engine = NULL;
char *voice = NULL;
char *text = NULL;
char *mydata = NULL;
switch_codec_t *codec;
switch_input_args_t args = {0};
switch_input_args_t args = { 0 };
codec = switch_core_session_get_read_codec(session);
assert(codec != NULL);
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
mydata = switch_core_session_strdup(session, data);
argc = switch_separate_string(mydata, '|', argv, sizeof(argv)/sizeof(argv[0]));
argc = switch_separate_string(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
engine = argv[0];
voice = argv[1];
text = argv[2];
if (!(engine && voice && text)) {
if (!engine) {
engine = "NULL";
@@ -102,27 +103,27 @@ static void speak_function(switch_core_session_t *session, char *data)
switch_channel_pre_answer(channel);
args.input_callback = on_dtmf;
args.buf = buf;
args.buflen = sizeof(buf);
args.input_callback = on_dtmf;
args.buf = buf;
args.buflen = sizeof(buf);
switch_ivr_speak_text(session, engine, voice, codec->implementation->samples_per_second, text, &args);
}
static void playback_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
char *file_name = NULL;
switch_input_args_t args = {0};
switch_input_args_t args = { 0 };
file_name = switch_core_session_strdup(session, data);
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_channel_pre_answer(channel);
args.input_callback = on_dtmf;
args.input_callback = on_dtmf;
switch_ivr_play_file(session, NULL, file_name, &args);
}
@@ -132,21 +133,21 @@ static void record_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
switch_status_t status;
uint32_t limit = 0;
char *path;
char *p;
switch_input_args_t args = {0};
uint32_t limit = 0;
char *path;
char *p;
switch_input_args_t args = { 0 };
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
path = switch_core_session_strdup(session, data);
if ((p = strchr(path, '+'))) {
*p++ = '\0';
limit = atoi(p);
}
path = switch_core_session_strdup(session, data);
if ((p = strchr(path, '+'))) {
*p++ = '\0';
limit = atoi(p);
}
args.input_callback = on_dtmf;
args.input_callback = on_dtmf;
status = switch_ivr_record_file(session, NULL, path, &args, limit);
if (!switch_channel_ready(channel) || (status != SWITCH_STATUS_SUCCESS && !SWITCH_STATUS_IS_BREAK(status))) {
@@ -159,9 +160,9 @@ static void record_session_function(switch_core_session_t *session, char *data)
{
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_ivr_record_session(session, data, NULL);
switch_ivr_record_session(session, data, NULL);
}
@@ -169,9 +170,9 @@ static void stop_record_session_function(switch_core_session_t *session, char *d
{
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
switch_ivr_stop_record_session(session, data);
switch_ivr_stop_record_session(session, data);
}
@@ -223,7 +224,7 @@ static const switch_application_interface_t playback_application_interface = {
/* short_desc */ "Playback File",
/* syntax */ "<path>",
/* flags */ SAF_NONE,
/*.next*/ &stop_record_session_application_interface
/*.next */ &stop_record_session_application_interface
};
static const switch_loadable_module_interface_t mod_playback_module_interface = {
@@ -235,7 +236,8 @@ static const switch_loadable_module_interface_t mod_playback_module_interface =
/*.application_interface */ &playback_application_interface
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
+126 -147
View File
@@ -68,9 +68,9 @@ static uint32_t match_count(char *str, uint32_t max)
{
char tstr[80] = "";
uint32_t matches = 0, x = 0;
uint32_t len = (uint32_t)strlen(str);
uint32_t len = (uint32_t) strlen(str);
for (x = 0; x < max ; x++) {
for (x = 0; x < max; x++) {
snprintf(tstr, sizeof(tstr), "%u", x);
if (!strncasecmp(str, tstr, len)) {
matches++;
@@ -85,68 +85,68 @@ static uint32_t match_count(char *str, uint32_t max)
dtmf handler function you can hook up to be executed when a digit is dialed during playback
if you return anything but SWITCH_STATUS_SUCCESS the playback will stop.
*/
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf,
unsigned int buflen)
{
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF: {
char *dtmf = (char *) input;
struct dtmf_buffer *dtb;
dtb = (struct dtmf_buffer *) buf;
switch(*dtmf) {
case '#':
switch_set_flag(dtb, SFLAG_MAIN);
return SWITCH_STATUS_BREAK;
case '6':
dtb->index++;
return SWITCH_STATUS_BREAK;
case '4':
dtb->index--;
return SWITCH_STATUS_BREAK;
case '*':
if (switch_test_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE)) {
switch_clear_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
} else {
switch_set_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
}
break;
case '5':
switch_core_speech_text_param_tts(dtb->sh, "voice", "next");
switch_set_flag(dtb, SFLAG_INFO);
return SWITCH_STATUS_BREAK;
break;
case '9':
switch_core_speech_text_param_tts(dtb->sh, "voice", dtb->voice);
switch_set_flag(dtb, SFLAG_INFO);
return SWITCH_STATUS_BREAK;
break;
case '2':
if (dtb->speed < 260) {
dtb->speed += 30;
case SWITCH_INPUT_TYPE_DTMF:{
char *dtmf = (char *) input;
struct dtmf_buffer *dtb;
dtb = (struct dtmf_buffer *) buf;
switch (*dtmf) {
case '#':
switch_set_flag(dtb, SFLAG_MAIN);
return SWITCH_STATUS_BREAK;
case '6':
dtb->index++;
return SWITCH_STATUS_BREAK;
case '4':
dtb->index--;
return SWITCH_STATUS_BREAK;
case '*':
if (switch_test_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE)) {
switch_clear_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
} else {
switch_set_flag(dtb->sh, SWITCH_SPEECH_FLAG_PAUSE);
}
break;
case '5':
switch_core_speech_text_param_tts(dtb->sh, "voice", "next");
switch_set_flag(dtb, SFLAG_INFO);
return SWITCH_STATUS_BREAK;
break;
case '9':
switch_core_speech_text_param_tts(dtb->sh, "voice", dtb->voice);
switch_set_flag(dtb, SFLAG_INFO);
return SWITCH_STATUS_BREAK;
break;
case '2':
if (dtb->speed < 260) {
dtb->speed += 30;
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
switch_set_flag(dtb, SFLAG_INFO);
return SWITCH_STATUS_BREAK;
}
break;
case '7':
dtb->speed = TTS_MEAN_SPEED;
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
switch_set_flag(dtb, SFLAG_INFO);
return SWITCH_STATUS_BREAK;
}
break;
case '7':
dtb->speed = TTS_MEAN_SPEED;
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
switch_set_flag(dtb, SFLAG_INFO);
return SWITCH_STATUS_BREAK;
case '8':
if (dtb->speed > 80) {
dtb->speed -= 30;
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
switch_set_flag(dtb, SFLAG_INFO);
case '8':
if (dtb->speed > 80) {
dtb->speed -= 30;
switch_core_speech_numeric_param_tts(dtb->sh, "speech/rate", dtb->speed);
switch_set_flag(dtb, SFLAG_INFO);
return SWITCH_STATUS_BREAK;
}
break;
case '0':
switch_set_flag(dtb, SFLAG_INSTRUCT);
return SWITCH_STATUS_BREAK;
}
break;
case '0':
switch_set_flag(dtb, SFLAG_INSTRUCT);
return SWITCH_STATUS_BREAK;
}
}
break;
default:
break;
@@ -159,9 +159,9 @@ static void rss_function(switch_core_session_t *session, char *data)
switch_channel_t *channel;
switch_status_t status;
const char *err = NULL;
struct dtmf_buffer dtb = {0};
struct dtmf_buffer dtb = { 0 };
switch_xml_t xml = NULL, item, xchannel = NULL;
struct rss_entry entries[TTS_MAX_ENTRIES] = {{0}};
struct rss_entry entries[TTS_MAX_ENTRIES] = { {0} };
uint32_t i = 0;
char *title_txt = "", *description_txt = "", *rights_txt = "";
switch_codec_t speech_codec, *codec = switch_core_session_get_read_codec(session);
@@ -169,31 +169,32 @@ static void rss_function(switch_core_session_t *session, char *data)
char *voice = TTS_DEFAULT_VOICE;
char *timer_name = NULL;
switch_speech_handle_t sh;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
switch_speech_flag_t flags = SWITCH_SPEECH_FLAG_NONE;
switch_core_thread_session_t thread_session;
uint32_t rate, interval = 20;
int stream_id = 0;
switch_timer_t timer = {0}, *timerp = NULL;
switch_timer_t timer = { 0 }, *timerp = NULL;
uint32_t last;
char *mydata = NULL;
char *filename = NULL;
char *argv[3], *feed_list[TTS_MAX_ENTRIES] = {0} , *feed_names[TTS_MAX_ENTRIES] = {0};
char *argv[3], *feed_list[TTS_MAX_ENTRIES] = { 0 }, *feed_names[TTS_MAX_ENTRIES] = {
0};
int argc, feed_index = 0;
char *cf = "rss.conf";
switch_xml_t cfg, cxml, feeds, feed;
switch_xml_t cfg, cxml, feeds, feed;
char buf[1024];
int32_t jumpto = -1;
uint32_t matches = 0;
switch_input_args_t args = {0};
switch_input_args_t args = { 0 };
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(channel != NULL);
if (!(cxml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return;
}
if ((feeds = switch_xml_child(cfg, "feeds"))) {
for (feed = switch_xml_child(feeds, "feed"); feed; feed = feed->next) {
@@ -210,14 +211,14 @@ static void rss_function(switch_core_session_t *session, char *data)
}
switch_xml_free(cxml);
switch_channel_answer(channel);
if (!switch_strlen_zero(data)) {
if ((mydata = switch_core_session_strdup(session, data))) {
argc = switch_separate_string(mydata, ' ', argv, sizeof(argv)/sizeof(argv[0]));
argc = switch_separate_string(mydata, ' ', argv, sizeof(argv) / sizeof(argv[0]));
if (argv[0]) {
engine = argv[0];
@@ -246,40 +247,40 @@ static void rss_function(switch_core_session_t *session, char *data)
memset(&sh, 0, sizeof(sh));
if (switch_core_speech_open(&sh,
engine,
voice,
rate,
&flags,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
voice, rate, &flags, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid TTS module!\n");
return;
}
if (switch_core_codec_init(&speech_codec,
"L16",
NULL,
(int)rate,
(int) rate,
interval,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activated\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n", rate, interval);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
rate, interval);
flags = 0;
switch_core_speech_close(&sh, &flags);
return;
}
if (timer_name) {
if (switch_core_timer_init(&timer, timer_name, interval, (int)(rate / 50), switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
if (switch_core_timer_init
(&timer, timer_name, interval, (int) (rate / 50),
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n");
switch_core_codec_destroy(&speech_codec);
flags = 0;
switch_core_speech_close(&sh, &flags);
return;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success %u bytes per %d ms!\n", (rate / 50)*2, interval);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "setup timer success %u bytes per %d ms!\n",
(rate / 50) * 2, interval);
/* start a thread to absorb incoming audio */
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
@@ -292,7 +293,7 @@ static void rss_function(switch_core_session_t *session, char *data)
while (switch_channel_ready(channel)) {
int32_t len = 0, idx = 0;
char cmd[3];
main_menu:
main_menu:
filename = NULL;
len = idx = 0;
*cmd = '\0';
@@ -304,36 +305,30 @@ static void rss_function(switch_core_session_t *session, char *data)
} else {
switch_core_speech_flush_tts(&sh);
#ifdef MATCH_COUNT
snprintf(buf + len, sizeof(buf) - len,
snprintf(buf + len, sizeof(buf) - len,
",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
"Select one of the following news sources, or press 0 to exit. "
",<break time=\"600ms\"/>");
"Select one of the following news sources, or press 0 to exit. " ",<break time=\"600ms\"/>");
#else
snprintf(buf + len, sizeof(buf) - len,
snprintf(buf + len, sizeof(buf) - len,
",<break time=\"500ms\"/>Main Menu. <break time=\"600ms\"/> "
"Select one of the following news sources, followed by the pound key or press 0 to exit. "
",<break time=\"600ms\"/>");
#endif
len = (int32_t)strlen(buf);
len = (int32_t) strlen(buf);
for (idx = 0; idx < feed_index; idx++) {
snprintf(buf + len, sizeof(buf) - len, "%d: %s. <break time=\"600ms\"/>", idx + 1, feed_names[idx]);
len = (int32_t)strlen(buf);
len = (int32_t) strlen(buf);
}
snprintf(buf + len, sizeof(buf) - len, "<break time=\"2000ms\"/>");
len = (int32_t)strlen(buf);
len = (int32_t) strlen(buf);
args.input_callback = NULL;
args.buf = cmd;
args.buflen = sizeof(cmd);
status = switch_ivr_speak_text_handle(session,
&sh,
&speech_codec,
timerp,
buf,
&args);
status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
goto finished;
}
@@ -346,31 +341,31 @@ static void rss_function(switch_core_session_t *session, char *data)
break;
}
if ((p=strchr(cmd, '#'))) {
if ((p = strchr(cmd, '#'))) {
*p = '\0';
#ifdef MATCH_COUNT
/* Hmmm... I know there are no more matches so I don't *need* them to press pound but
I already told them to press it. Will this confuse people or not? Let's make em press
pound unless this define is enabled for now.
*/
*/
} else if (match_count(cmd, feed_index) > 1) {
#else
} else {
#endif
char term;
char *cp;
int blen = sizeof(cmd) - (int)strlen(cmd);
int blen = sizeof(cmd) - (int) strlen(cmd);
cp = cmd + blen;
switch_ivr_collect_digits_count(session, cp, blen, blen, "#", &term, 5000);
}
i = atoi(cmd) - 1;
if (i > -1 && i < feed_index) {
filename = feed_list[i];
} else if (matches > 1) {
} else {
args.input_callback = NULL;
args.buf = NULL;
@@ -378,19 +373,17 @@ static void rss_function(switch_core_session_t *session, char *data)
status = switch_ivr_speak_text_handle(session,
&sh,
&speech_codec,
timerp,
"I'm sorry. That is an Invalid Selection. ",
&args);
timerp, "I'm sorry. That is an Invalid Selection. ", &args);
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
goto finished;
}
}
}
if (!filename) {
continue;
}
if (!(xml = switch_xml_parse_file(filename))) {
@@ -411,7 +404,7 @@ static void rss_function(switch_core_session_t *session, char *data)
if ((title = switch_xml_child(xchannel, "title"))) {
title_txt = title->txt;
}
if ((description = switch_xml_child(xchannel, "description"))) {
description_txt = description->txt;
}
@@ -444,19 +437,19 @@ static void rss_function(switch_core_session_t *session, char *data)
if ((title = switch_xml_child(item, "title"))) {
entries[i].title_txt = title->txt;
}
if ((description = switch_xml_child(item, "description"))) {
char *t, *e;
entries[i].description_txt = description->txt;
for(;;) {
for (;;) {
if (!(t = strchr(entries[i].description_txt, '<'))) {
break;
}
if (!(e = strchr(t, '>'))) {
break;
}
memset(t, 32, ++e-t);
memset(t, 32, ++e - t);
}
}
@@ -471,9 +464,8 @@ static void rss_function(switch_core_session_t *session, char *data)
if (entries[i].description_txt && (p = strchr(entries[i].description_txt, '<'))) {
*p = '\0';
}
#ifdef _STRIP_SOME_CHARS_
for(p = entries[i].description_txt; *p; p++) {
for (p = entries[i].description_txt; *p; p++) {
if (*p == '\'' || *p == '"' || *p == ':') {
*p = ' ';
}
@@ -493,17 +485,13 @@ static void rss_function(switch_core_session_t *session, char *data)
switch_strftime(date, &retsize, sizeof(date), "%I:%M %p", &tm);
snprintf(buf, sizeof(buf), ",<break time=\"500ms\"/>%s. %s. %s. local time: %s, Press 0 for options, 5 to change voice, or pound to return to the main menu. ",
snprintf(buf, sizeof(buf),
",<break time=\"500ms\"/>%s. %s. %s. local time: %s, Press 0 for options, 5 to change voice, or pound to return to the main menu. ",
title_txt, description_txt, rights_txt, date);
args.input_callback = NULL;
args.buf = cmd;
args.buflen = sizeof(cmd);
status = switch_ivr_speak_text_handle(session,
&sh,
&speech_codec,
timerp,
buf,
&args);
status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
goto finished;
}
@@ -519,7 +507,7 @@ static void rss_function(switch_core_session_t *session, char *data)
}
}
for(last = 0; last < TTS_MAX_ENTRIES; last++) {
for (last = 0; last < TTS_MAX_ENTRIES; last++) {
if (!entries[last].inuse) {
last--;
break;
@@ -531,8 +519,8 @@ static void rss_function(switch_core_session_t *session, char *data)
dtb.speed = TTS_MEAN_SPEED;
switch_set_flag(&dtb, SFLAG_INFO);
switch_copy_string(dtb.voice, voice, sizeof(dtb.voice));
while(entries[0].inuse && switch_channel_ready(channel)) {
while(switch_channel_ready(channel)) {
while (entries[0].inuse && switch_channel_ready(channel)) {
while (switch_channel_ready(channel)) {
uint8_t cont = 0;
if (dtb.index >= TTS_MAX_ENTRIES) {
@@ -557,12 +545,8 @@ static void rss_function(switch_core_session_t *session, char *data)
if (switch_test_flag(&dtb, SFLAG_INFO)) {
switch_clear_flag(&dtb, SFLAG_INFO);
snprintf(buf + len, sizeof(buf) - len,
"%s %s. I am speaking at %u words per minute. ",
sh.engine,
sh.voice,
dtb.speed
);
len = (uint32_t)strlen(buf);
"%s %s. I am speaking at %u words per minute. ", sh.engine, sh.voice, dtb.speed);
len = (uint32_t) strlen(buf);
}
if (switch_test_flag(&dtb, SFLAG_INSTRUCT)) {
@@ -577,33 +561,29 @@ static void rss_function(switch_core_session_t *session, char *data)
"To hear these options again, press zero or press pound to return to the main menu. ");
} else {
snprintf(buf + len, sizeof(buf) - len, "Story %d. ", dtb.index + 1);
len = (uint32_t)strlen(buf);
len = (uint32_t) strlen(buf);
if (entries[dtb.index].subject_txt) {
snprintf(buf + len, sizeof(buf) - len, "Subject: %s. ", entries[dtb.index].subject_txt);
len = (uint32_t)strlen(buf);
len = (uint32_t) strlen(buf);
}
if (entries[dtb.index].dept_txt) {
snprintf(buf + len, sizeof(buf) - len, "From the %s department. ", entries[dtb.index].dept_txt);
len = (uint32_t)strlen(buf);
snprintf(buf + len, sizeof(buf) - len, "From the %s department. ",
entries[dtb.index].dept_txt);
len = (uint32_t) strlen(buf);
}
if (entries[dtb.index].title_txt) {
snprintf(buf + len, sizeof(buf) - len, "%s", entries[dtb.index].title_txt);
len = (uint32_t)strlen(buf);
len = (uint32_t) strlen(buf);
}
}
switch_core_speech_flush_tts(&sh);
args.input_callback = on_dtmf;
args.buf = &dtb;
args.buflen = sizeof(dtb);
status = switch_ivr_speak_text_handle(session,
&sh,
&speech_codec,
timerp,
buf,
&args);
status = switch_ivr_speak_text_handle(session, &sh, &speech_codec, timerp, buf, &args);
if (status == SWITCH_STATUS_BREAK) {
continue;
} else if (status != SWITCH_STATUS_SUCCESS) {
@@ -614,7 +594,7 @@ static void rss_function(switch_core_session_t *session, char *data)
cont = 0;
continue;
}
if (entries[dtb.index].description_txt) {
args.input_callback = on_dtmf;
args.buf = &dtb;
@@ -622,9 +602,7 @@ static void rss_function(switch_core_session_t *session, char *data)
status = switch_ivr_speak_text_handle(session,
&sh,
&speech_codec,
timerp,
entries[dtb.index].description_txt,
&args);
timerp, entries[dtb.index].description_txt, &args);
}
if (status == SWITCH_STATUS_BREAK) {
continue;
@@ -638,7 +616,7 @@ static void rss_function(switch_core_session_t *session, char *data)
}
}
finished:
finished:
switch_core_speech_close(&sh, &flags);
switch_core_codec_destroy(&speech_codec);
@@ -659,7 +637,7 @@ static const switch_application_interface_t rss_application_interface = {
/*.application_function */ rss_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE,
/*.next*/ NULL
/*.next */ NULL
};
@@ -677,7 +655,8 @@ static switch_loadable_module_interface_t rss_module_interface = {
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &rss_module_interface;
+2 -1
View File
@@ -47,7 +47,8 @@ static switch_loadable_module_interface_t skel_module_interface = {
/*.directory_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &skel_module_interface;
+61 -61
View File
@@ -69,23 +69,23 @@ typedef struct {
/* This callback caches the audio in the buffer */
static swift_result_t write_audio(swift_event *event, swift_event_t type, void *udata)
static swift_result_t write_audio(swift_event * event, swift_event_t type, void *udata)
{
cepstral_t *cepstral;
swift_event_t rv = SWIFT_SUCCESS;
void *buf = NULL;
int len = 0, i = 0;
swift_event_t rv = SWIFT_SUCCESS;
void *buf = NULL;
int len = 0, i = 0;
cepstral = udata;
assert(cepstral != NULL);
if (!cepstral->port || cepstral->done || cepstral->done_gen) {
return SWIFT_UNKNOWN_ERROR;
return SWIFT_UNKNOWN_ERROR;
}
/* Only proceed when we have success */
if (!SWIFT_FAILED((rv = swift_event_get_audio(event, &buf, &len)))) {
while(!cepstral->done) {
if (!SWIFT_FAILED((rv = swift_event_get_audio(event, &buf, &len)))) {
while (!cepstral->done) {
switch_mutex_lock(cepstral->audio_lock);
if (switch_buffer_write(cepstral->audio_buffer, buf, len) > 0) {
switch_mutex_unlock(cepstral->audio_lock);
@@ -100,7 +100,7 @@ static swift_result_t write_audio(swift_event *event, swift_event_t type, void *
}
}
}
}
} else {
cepstral->done = 1;
@@ -109,11 +109,12 @@ static swift_result_t write_audio(swift_event *event, swift_event_t type, void *
if (cepstral->done) {
rv = SWIFT_UNKNOWN_ERROR;
}
return rv;
return rv;
}
static switch_status_t cepstral_speech_open(switch_speech_handle_t *sh, char *voice_name, int rate, switch_speech_flag_t *flags)
static switch_status_t cepstral_speech_open(switch_speech_handle_t *sh, char *voice_name, int rate,
switch_speech_flag_t *flags)
{
cepstral_t *cepstral = switch_core_alloc(sh->memory_pool, sizeof(*cepstral));
char srate[25];
@@ -143,7 +144,7 @@ static switch_status_t cepstral_speech_open(switch_speech_handle_t *sh, char *vo
goto all_done;
}
if (voice_name && SWIFT_FAILED(swift_port_set_voice_by_name(cepstral->port, voice_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid voice %s!\n", voice_name);
voice_name = NULL;
@@ -157,7 +158,7 @@ static switch_status_t cepstral_speech_open(switch_speech_handle_t *sh, char *vo
}
/* Set the voice found by find_first_voice() as the port's current voice */
if ( SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice)) ) {
if (SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set voice.\n");
goto all_done;
}
@@ -173,8 +174,8 @@ static switch_status_t cepstral_speech_open(switch_speech_handle_t *sh, char *vo
sh->private_info = cepstral;
return SWITCH_STATUS_SUCCESS;
all_done:
all_done:
return SWITCH_STATUS_FALSE;
}
@@ -185,18 +186,19 @@ static switch_status_t cepstral_speech_close(switch_speech_handle_t *sh, switch_
assert(sh != NULL);
cepstral = sh->private_info;
assert(cepstral != NULL);
cepstral->done = 1;
cepstral->done_gen = 1;
swift_port_stop(cepstral->port, SWIFT_ASYNC_ANY, SWIFT_EVENT_NOW);
/* Close the Swift Port and Engine */
if (NULL != cepstral->port) swift_port_close(cepstral->port);
if (NULL != cepstral->port)
swift_port_close(cepstral->port);
//if (NULL != cepstral->engine) swift_engine_close(cepstral->engine);
cepstral->port = NULL;
//cepstral->engine = NULL;
switch_buffer_destroy(&cepstral->audio_buffer);
return SWITCH_STATUS_SUCCESS;
@@ -206,7 +208,7 @@ static switch_status_t cepstral_speech_feed_tts(switch_speech_handle_t *sh, char
{
cepstral_t *cepstral;
const char *fp = "file:";
int len = (int)strlen(fp);
int len = (int) strlen(fp);
assert(sh != NULL);
cepstral = sh->private_info;
@@ -214,7 +216,7 @@ static switch_status_t cepstral_speech_feed_tts(switch_speech_handle_t *sh, char
cepstral->done_gen = 0;
cepstral->done = 0;
cepstral->tts_stream = NULL;
if (!strncasecmp(text, fp, len)) {
@@ -222,17 +224,17 @@ static switch_status_t cepstral_speech_feed_tts(switch_speech_handle_t *sh, char
if (switch_strlen_zero(text)) {
return SWITCH_STATUS_FALSE;
}
swift_port_speak_file(cepstral->port, text, NULL, &cepstral->tts_stream, NULL);
swift_port_speak_file(cepstral->port, text, NULL, &cepstral->tts_stream, NULL);
} else {
char *to_say;
char *to_say;
if (switch_strlen_zero(text)) {
return SWITCH_STATUS_FALSE;
}
if ((to_say = switch_mprintf("<break time=\"500ms\"/> %s <break time=\"500ms\"/>", text))) {
swift_port_speak_text(cepstral->port, to_say, 0, NULL, &cepstral->tts_stream, NULL);
switch_safe_free(to_say);
}
if ((to_say = switch_mprintf("<break time=\"500ms\"/> %s <break time=\"500ms\"/>", text))) {
swift_port_speak_text(cepstral->port, to_say, 0, NULL, &cepstral->tts_stream, NULL);
switch_safe_free(to_say);
}
}
return SWITCH_STATUS_SUCCESS;
@@ -243,10 +245,10 @@ static void cepstral_speech_flush_tts(switch_speech_handle_t *sh)
cepstral_t *cepstral;
cepstral = sh->private_info;
assert(cepstral != NULL);
assert(cepstral != NULL);
cepstral->done_gen = 1;
cepstral->done = 1;
cepstral->done = 1;
if (cepstral->audio_buffer) {
switch_mutex_lock(cepstral->audio_lock);
switch_buffer_zero(cepstral->audio_buffer);
@@ -257,9 +259,7 @@ static void cepstral_speech_flush_tts(switch_speech_handle_t *sh)
static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh,
void *data,
size_t *datalen,
uint32_t *rate,
switch_speech_flag_t *flags)
size_t *datalen, uint32_t * rate, switch_speech_flag_t *flags)
{
cepstral_t *cepstral;
size_t desired = *datalen;
@@ -270,7 +270,7 @@ static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh,
cepstral = sh->private_info;
assert(cepstral != NULL);
while(!cepstral->done) {
while (!cepstral->done) {
if (!cepstral->done_gen) {
int check = swift_port_status(cepstral->port, cepstral->tts_stream);
@@ -282,8 +282,8 @@ static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh,
switch_mutex_lock(cepstral->audio_lock);
used = switch_buffer_inuse(cepstral->audio_buffer);
switch_mutex_unlock(cepstral->audio_lock);
if (!used && cepstral->done_gen) {
status = SWITCH_STATUS_BREAK;
@@ -304,15 +304,15 @@ static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh,
switch_yield(1000);
continue;
}
/* There is enough, read it and return */
switch_mutex_lock(cepstral->audio_lock);
*datalen = switch_buffer_read(cepstral->audio_buffer, data, desired);
if (padding) {
size_t x = 0;
unsigned char *p = data;
for(x = 0; x < padding; x++) {
for (x = 0; x < padding; x++) {
*(p + x) = 0;
(*datalen)++;
}
@@ -323,7 +323,7 @@ static switch_status_t cepstral_speech_read_tts(switch_speech_handle_t *sh,
break;
}
return status;
}
@@ -338,7 +338,7 @@ static void cepstral_text_param_tts(switch_speech_handle_t *sh, char *param, cha
char *voice_name = val;
if (!strcasecmp(voice_name, "next")) {
if ((cepstral->voice = swift_port_find_next_voice(cepstral->port))) {
if ( SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice)) ) {
if (SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice))) {
cepstral->done = cepstral->done_gen = 1;
return;
}
@@ -354,22 +354,22 @@ static void cepstral_text_param_tts(switch_speech_handle_t *sh, char *param, cha
}
if (!voice_name) {
/* Find the first voice on the system */
if ((cepstral->voice = swift_port_find_first_voice(cepstral->port, NULL, NULL)) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find any voices!\n");
/* Find the first voice on the system */
if ((cepstral->voice = swift_port_find_first_voice(cepstral->port, NULL, NULL)) == NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to find any voices!\n");
cepstral->done = cepstral->done_gen = 1;
return;
}
}
/* Set the voice found by find_first_voice() as the port's current voice */
if ( SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice)) ) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set voice.\n");
/* Set the voice found by find_first_voice() as the port's current voice */
if (SWIFT_FAILED(swift_port_set_voice(cepstral->port, cepstral->voice))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set voice.\n");
cepstral->done = cepstral->done_gen = 1;
return;
}
}
voice_name = (char *) swift_voice_get_attribute(cepstral->voice, "name");
}
}
if (voice_name) {
switch_copy_string(sh->voice, voice_name, sizeof(sh->voice));
@@ -405,15 +405,15 @@ static void cepstral_float_param_tts(switch_speech_handle_t *sh, char *param, do
}
static const switch_speech_interface_t cepstral_speech_interface = {
/*.interface_name*/ "cepstral",
/*.speech_open*/ cepstral_speech_open,
/*.speech_close*/ cepstral_speech_close,
/*.speech_feed_tts*/ cepstral_speech_feed_tts,
/*.speech_read_tts*/ cepstral_speech_read_tts,
/*.speech_flush_tts*/ cepstral_speech_flush_tts,
/*.speech_text_param_tts*/ cepstral_text_param_tts,
/*.speech_numeric_param_tts*/ cepstral_numeric_param_tts,
/*.speech_numeric_param_tts*/ cepstral_float_param_tts
/*.interface_name */ "cepstral",
/*.speech_open */ cepstral_speech_open,
/*.speech_close */ cepstral_speech_close,
/*.speech_feed_tts */ cepstral_speech_feed_tts,
/*.speech_read_tts */ cepstral_speech_read_tts,
/*.speech_flush_tts */ cepstral_speech_flush_tts,
/*.speech_text_param_tts */ cepstral_text_param_tts,
/*.speech_numeric_param_tts */ cepstral_numeric_param_tts,
/*.speech_numeric_param_tts */ cepstral_float_param_tts
};
static const switch_loadable_module_interface_t cepstral_module_interface = {
@@ -433,11 +433,11 @@ switch_status_t switch_module_load(const switch_loadable_module_interface_t **mo
{
/* Open the Swift TTS Engine */
if ( SWIFT_FAILED(engine = swift_engine_open(NULL)) ) {
if (SWIFT_FAILED(engine = swift_engine_open(NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open Swift Engine.");
return SWITCH_STATUS_GENERR;
}
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &cepstral_module_interface;
+68 -74
View File
@@ -30,7 +30,7 @@
*
* mod_amr.c -- GSM-AMR Codec Module
*
*/
*/
#include "switch.h"
static const char modname[] = "mod_amr";
@@ -114,14 +114,14 @@ static struct {
#endif
static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
#ifdef AMR_PASSTHROUGH
codec->flags |= SWITCH_CODEC_FLAG_PASSTHROUGH;
if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
}
if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
}
return SWITCH_STATUS_SUCCESS;
#else
struct amr_context *context = NULL;
@@ -139,10 +139,10 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
if (codec->fmtp_in) {
argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0])));
for(x = 0; x < argc; x++) {
for (x = 0; x < argc; x++) {
char *data = argv[x];
char *arg;
while(*data && *data == ' ') {
while (*data && *data == ' ') {
data++;
}
if ((arg = strchr(data, '='))) {
@@ -171,16 +171,16 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
} else if (!strcasecmp(data, "mode-change-period")) {
context->change_period = atoi(arg);
} else if (!strcasecmp(data, "ptime")) {
context->ptime = (switch_byte_t)atoi(arg);
context->ptime = (switch_byte_t) atoi(arg);
} else if (!strcasecmp(data, "channels")) {
context->channels = (switch_byte_t)atoi(arg);
context->channels = (switch_byte_t) atoi(arg);
} else if (!strcasecmp(data, "maxptime")) {
context->max_ptime = (switch_byte_t)atoi(arg);
context->max_ptime = (switch_byte_t) atoi(arg);
} else if (!strcasecmp(data, "mode-set")) {
int y, m_argc;
char *m_argv[7];
m_argc = switch_separate_string(arg, ',', m_argv, (sizeof(m_argv) / sizeof(m_argv[0])));
for(y = 0; y < m_argc; y++) {
for (y = 0; y < m_argc; y++) {
context->enc_modes |= (1 << atoi(m_argv[y]));
}
}
@@ -192,7 +192,7 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
if (context->enc_modes) {
for (i = 7; i > -1; i++) {
if (context->enc_modes & (1 << i)) {
context->enc_mode = (switch_byte_t)i;
context->enc_mode = (switch_byte_t) i;
break;
}
}
@@ -201,10 +201,11 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
if (!context->enc_mode) {
context->enc_mode = globals.default_bitrate;
}
snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d", switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d",
switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
context->enc_mode = AMR_DEFAULT_BITRATE;
context->encoder_state = NULL;
context->decoder_state = NULL;
@@ -224,7 +225,7 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
#endif
}
static switch_status_t switch_amr_destroy(switch_codec_t *codec)
static switch_status_t switch_amr_destroy(switch_codec_t *codec)
{
#ifndef AMR_PASSTHROUGH
struct amr_context *context = codec->private_info;
@@ -240,45 +241,39 @@ static switch_status_t switch_amr_destroy(switch_codec_t *codec)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_amr_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len,
uint32_t *encoded_rate,
unsigned int *flag)
static switch_status_t switch_amr_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
#ifdef AMR_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
return SWITCH_STATUS_FALSE;
#else
struct amr_context *context = codec->private_info;
if (!context) {
return SWITCH_STATUS_FALSE;
}
*encoded_data_len = Encoder_Interface_Encode( context->encoder_state, context->enc_mode, (int16_t *)decoded_data, (switch_byte_t *) encoded_data, 0);
*encoded_data_len =
Encoder_Interface_Encode(context->encoder_state, context->enc_mode, (int16_t *) decoded_data,
(switch_byte_t *) encoded_data, 0);
return SWITCH_STATUS_SUCCESS;
#endif
}
static switch_status_t switch_amr_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len,
uint32_t *decoded_rate,
unsigned int *flag)
static switch_status_t switch_amr_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
#ifdef AMR_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -290,51 +285,51 @@ static switch_status_t switch_amr_decode(switch_codec_t *codec,
return SWITCH_STATUS_FALSE;
}
Decoder_Interface_Decode(context->decoder_state, (unsigned char *)encoded_data, (int16_t *)decoded_data, 0);
Decoder_Interface_Decode(context->decoder_state, (unsigned char *) encoded_data, (int16_t *) decoded_data, 0);
*decoded_data_len = codec->implementation->bytes_per_frame;
return SWITCH_STATUS_SUCCESS;
#endif
}
/* Registration */
/* Registration */
static const switch_codec_implementation_t amr_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 96,
/*.iananame */ "AMR",
static const switch_codec_implementation_t amr_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 96,
/*.iananame */ "AMR",
/*.fmtp */ "octet-align=0",
/*.samples_per_second */ 8000,
/*.bits_per_second */ 0,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 0,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 0,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_amr_init,
/*.encode */ switch_amr_encode,
/*.decode */ switch_amr_decode,
/*.destroy */ switch_amr_destroy,
/*.encoded_bytes_per_frame */ 0,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_amr_init,
/*.encode */ switch_amr_encode,
/*.decode */ switch_amr_decode,
/*.destroy */ switch_amr_destroy,
};
static const switch_codec_interface_t amr_codec_interface = {
/*.interface_name */ "GSM-AMR",
/*.implementations */ &amr_implementation,
static const switch_codec_interface_t amr_codec_interface = {
/*.interface_name */ "GSM-AMR",
/*.implementations */ &amr_implementation,
};
static switch_loadable_module_interface_t amr_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &amr_codec_interface,
/*.application_interface */ NULL
static switch_loadable_module_interface_t amr_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &amr_codec_interface,
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
char *filename)
{
#ifndef AMR_PASSTHROUGH
char *cf = "amr.conf";
@@ -349,17 +344,16 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "default-bitrate")) {
globals.default_bitrate = (switch_byte_t)atoi(val);
globals.default_bitrate = (switch_byte_t) atoi(val);
}
}
}
}
#endif
/* connect my internal structure to the blank pointer passed to me */
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &amr_module_interface;
/* indicate that the module should continue to be loaded */
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+36 -35
View File
@@ -37,7 +37,7 @@ static const char modname[] = "mod_g711";
static switch_status_t switch_g711u_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
int encoding, decoding;
@@ -53,12 +53,12 @@ static switch_status_t switch_g711u_init(switch_codec_t *codec, switch_codec_fla
static switch_status_t switch_g711u_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
@@ -77,12 +77,12 @@ static switch_status_t switch_g711u_encode(switch_codec_t *codec,
}
static switch_status_t switch_g711u_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
@@ -112,7 +112,7 @@ static switch_status_t switch_g711u_destroy(switch_codec_t *codec)
static switch_status_t switch_g711a_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
int encoding, decoding;
@@ -128,12 +128,12 @@ static switch_status_t switch_g711a_init(switch_codec_t *codec, switch_codec_fla
static switch_status_t switch_g711a_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
@@ -152,12 +152,12 @@ static switch_status_t switch_g711a_encode(switch_codec_t *codec,
}
static switch_status_t switch_g711a_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
@@ -226,7 +226,7 @@ static const switch_codec_implementation_t g711u_8k_60ms_implementation = {
/*.encode */ switch_g711u_encode,
/*.decode */ switch_g711u_decode,
/*.destroy */ switch_g711u_destroy,
/*.next*/ &g711u_8k_120ms_implementation
/*.next */ &g711u_8k_120ms_implementation
};
static const switch_codec_implementation_t g711u_8k_30ms_implementation = {
@@ -247,7 +247,7 @@ static const switch_codec_implementation_t g711u_8k_30ms_implementation = {
/*.encode */ switch_g711u_encode,
/*.decode */ switch_g711u_decode,
/*.destroy */ switch_g711u_destroy,
/*.next*/ &g711u_8k_60ms_implementation
/*.next */ &g711u_8k_60ms_implementation
};
static const switch_codec_implementation_t g711u_8k_20ms_implementation = {
@@ -268,7 +268,7 @@ static const switch_codec_implementation_t g711u_8k_20ms_implementation = {
/*.encode */ switch_g711u_encode,
/*.decode */ switch_g711u_decode,
/*.destroy */ switch_g711u_destroy,
/*.next*/ &g711u_8k_30ms_implementation
/*.next */ &g711u_8k_30ms_implementation
};
static const switch_codec_implementation_t g711u_8k_10ms_implementation = {
@@ -289,7 +289,7 @@ static const switch_codec_implementation_t g711u_8k_10ms_implementation = {
/*.encode */ switch_g711u_encode,
/*.decode */ switch_g711u_decode,
/*.destroy */ switch_g711u_destroy,
/*.next*/ &g711u_8k_20ms_implementation
/*.next */ &g711u_8k_20ms_implementation
};
@@ -332,7 +332,7 @@ static const switch_codec_implementation_t g711a_8k_60ms_implementation = {
/*.encode */ switch_g711a_encode,
/*.decode */ switch_g711a_decode,
/*.destroy */ switch_g711a_destroy,
/*.next*/ &g711a_8k_120ms_implementation
/*.next */ &g711a_8k_120ms_implementation
};
static const switch_codec_implementation_t g711a_8k_30ms_implementation = {
@@ -353,7 +353,7 @@ static const switch_codec_implementation_t g711a_8k_30ms_implementation = {
/*.encode */ switch_g711a_encode,
/*.decode */ switch_g711a_decode,
/*.destroy */ switch_g711a_destroy,
/*.next*/ &g711a_8k_60ms_implementation
/*.next */ &g711a_8k_60ms_implementation
};
static const switch_codec_implementation_t g711a_8k_20ms_implementation = {
@@ -374,7 +374,7 @@ static const switch_codec_implementation_t g711a_8k_20ms_implementation = {
/*.encode */ switch_g711a_encode,
/*.decode */ switch_g711a_decode,
/*.destroy */ switch_g711a_destroy,
/*.next*/ &g711a_8k_30ms_implementation
/*.next */ &g711a_8k_30ms_implementation
};
static const switch_codec_implementation_t g711a_8k_10ms_implementation = {
@@ -395,7 +395,7 @@ static const switch_codec_implementation_t g711a_8k_10ms_implementation = {
/*.encode */ switch_g711a_encode,
/*.decode */ switch_g711a_decode,
/*.destroy */ switch_g711a_destroy,
/*.next*/ &g711a_8k_20ms_implementation
/*.next */ &g711a_8k_20ms_implementation
};
@@ -421,7 +421,8 @@ static switch_loadable_module_interface_t g711_module_interface = {
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &g711_module_interface;
+28 -24
View File
@@ -41,7 +41,7 @@ struct g722_context {
};
static switch_status_t switch_g722_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
int encoding, decoding;
struct g722_context *context = NULL;
@@ -50,18 +50,18 @@ static switch_status_t switch_g722_init(switch_codec_t *codec, switch_codec_flag
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g722_context))))) {
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g722_context))))) {
return SWITCH_STATUS_FALSE;
} else {
if (encoding) {
if(codec->implementation->samples_per_second == 16000){
if (codec->implementation->samples_per_second == 16000) {
g722_encode_init(&context->encoder_object, 64000, G722_PACKED);
} else {
g722_encode_init(&context->encoder_object, 64000, G722_SAMPLE_RATE_8000);
}
}
if (decoding) {
if(codec->implementation->samples_per_second == 16000){
if (codec->implementation->samples_per_second == 16000) {
g722_decode_init(&context->decoder_object, 64000, G722_PACKED);
} else {
g722_decode_init(&context->decoder_object, 64000, G722_SAMPLE_RATE_8000);
@@ -70,44 +70,47 @@ static switch_status_t switch_g722_init(switch_codec_t *codec, switch_codec_flag
}
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_g722_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
struct g722_context *context = codec->private_info;
if (!context) {
return SWITCH_STATUS_FALSE;
return SWITCH_STATUS_FALSE;
}
*encoded_data_len = g722_encode(&context->encoder_object, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
*encoded_data_len =
g722_encode(&context->encoder_object, (uint8_t *) encoded_data, (int16_t *) decoded_data, decoded_data_len / 2);
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_g722_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
struct g722_context *context = codec->private_info;
if (!context) {
return SWITCH_STATUS_FALSE;
return SWITCH_STATUS_FALSE;
}
*decoded_data_len = (2 * g722_decode(&context->decoder_object, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
*decoded_data_len =
(2 *
g722_decode(&context->decoder_object, (int16_t *) decoded_data, (uint8_t *) encoded_data, encoded_data_len));
return SWITCH_STATUS_SUCCESS;
}
@@ -175,7 +178,8 @@ static switch_loadable_module_interface_t g722_module_interface = {
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &g722_module_interface;
+55 -63
View File
@@ -30,7 +30,7 @@
*
* mod_g723.c -- G723.1 Codec Module
*
*/
*/
#include "switch.h"
#ifndef G723_PASSTHROUGH
@@ -61,11 +61,11 @@ struct g723_context {
#endif
static switch_status_t switch_g723_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
#ifdef G723_PASSTHROUGH
codec->flags |= SWITCH_CODEC_FLAG_PASSTHROUGH;
return SWITCH_STATUS_FALSE;
return SWITCH_STATUS_FALSE;
#else
struct g723_context *context = NULL;
int encoding, decoding;
@@ -79,10 +79,10 @@ static switch_status_t switch_g723_init(switch_codec_t *codec, switch_codec_flag
if (encoding) {
Init_Coder(&context->encoder_object);
if( UseVx ) {
if (UseVx) {
Init_Vad(&context->encoder_object);
Init_Cod_Cng(&context->encoder_object);
}
}
}
if (decoding) {
@@ -98,7 +98,7 @@ static switch_status_t switch_g723_init(switch_codec_t *codec, switch_codec_flag
}
static switch_status_t switch_g723_destroy(switch_codec_t *codec)
static switch_status_t switch_g723_destroy(switch_codec_t *codec)
{
#ifndef G723_PASSTHROUGH
codec->private_info = NULL;
@@ -106,17 +106,13 @@ static switch_status_t switch_g723_destroy(switch_codec_t *codec)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_g723_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len,
uint32_t *encoded_rate,
unsigned int *flag)
static switch_status_t switch_g723_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
#ifdef G723_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -131,28 +127,24 @@ static switch_status_t switch_g723_encode(switch_codec_t *codec,
return SWITCH_STATUS_FALSE;
}
for(x = 0; x < Frame; x++) {
for (x = 0; x < Frame; x++) {
context->cod_float_buf[x] = decoded_slin_buf[x];
}
Coder(&context->encoder_object, (FLOAT *)context->cod_float_buf, ebuf);
Coder(&context->encoder_object, (FLOAT *) context->cod_float_buf, ebuf);
*encoded_data_len = codec->implementation->encoded_bytes_per_frame;
return SWITCH_STATUS_SUCCESS;
#endif
}
static switch_status_t switch_g723_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len,
uint32_t *decoded_rate,
unsigned int *flag)
static switch_status_t switch_g723_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
#ifdef G723_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -165,10 +157,10 @@ static switch_status_t switch_g723_decode(switch_codec_t *codec,
if (!context) {
return SWITCH_STATUS_FALSE;
}
Decod(&context->decoder_object, (FLOAT *) context->dec_float_buf, (char *) decoded_data, 0);
for (x=0;x<Frame;x++) {
for (x = 0; x < Frame; x++) {
to_slin_buf[x] = context->dec_float_buf[x];
}
*decoded_data_len = codec->implementation->bytes_per_frame;
@@ -177,49 +169,49 @@ static switch_status_t switch_g723_decode(switch_codec_t *codec,
#endif
}
/* Registration */
/* Registration */
static const switch_codec_implementation_t g723_1_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 4,
/*.iananame */ "G723",
static const switch_codec_implementation_t g723_1_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 4,
/*.iananame */ "G723",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 6300,
/*.microseconds_per_frame */ 30000,
/*.samples_per_frame */ 240,
/*.bytes_per_frame */ 480,
/*.encoded_bytes_per_frame */ 24,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 4,
/*.init */ switch_g723_init,
/*.encode */ switch_g723_encode,
/*.decode */ switch_g723_decode,
/*.destroy */ switch_g723_destroy,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 6300,
/*.microseconds_per_frame */ 30000,
/*.samples_per_frame */ 240,
/*.bytes_per_frame */ 480,
/*.encoded_bytes_per_frame */ 24,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 4,
/*.init */ switch_g723_init,
/*.encode */ switch_g723_encode,
/*.decode */ switch_g723_decode,
/*.destroy */ switch_g723_destroy,
};
static const switch_codec_interface_t g723_1_codec_interface = {
/*.interface_name */ "g723.1 6.3k",
/*.implementations */ &g723_1_implementation,
static const switch_codec_interface_t g723_1_codec_interface = {
/*.interface_name */ "g723.1 6.3k",
/*.implementations */ &g723_1_implementation,
};
static switch_loadable_module_interface_t g723_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &g723_1_codec_interface,
/*.application_interface */ NULL
static switch_loadable_module_interface_t g723_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &g723_1_codec_interface,
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &g723_module_interface;
/* indicate that the module should continue to be loaded */
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+221 -226
View File
@@ -28,15 +28,15 @@
*
* mod_g726.c -- G726 Codec Module
*
*/
*/
#include "switch.h"
#include "g72x.h"
#include "switch_bitpack.h"
static const char modname[] = "mod_g726";
typedef int (*encoder_t)(int, int, g726_state *);
typedef int (*decoder_t)(int, int, g726_state *);
typedef int (*encoder_t) (int, int, g726_state *);
typedef int (*decoder_t) (int, int, g726_state *);
typedef struct {
@@ -53,7 +53,7 @@ typedef struct {
} g726_handle_t;
static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
uint32_t encoding, decoding;
g726_handle_t *handle;
@@ -65,8 +65,8 @@ static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag
return SWITCH_STATUS_FALSE;
} else {
handle->bytes = (switch_byte_t) codec->implementation->encoded_bytes_per_frame;
switch(handle->bytes) {
switch (handle->bytes) {
case 100:
handle->encoder = g726_40_encoder;
handle->decoder = g726_40_decoder;
@@ -88,22 +88,24 @@ static switch_status_t switch_g726_init(switch_codec_t *codec, switch_codec_flag
handle->loops = 160;
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid Encoding Size %d!\n", codec->implementation->encoded_bytes_per_frame);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid Encoding Size %d!\n",
codec->implementation->encoded_bytes_per_frame);
return SWITCH_STATUS_FALSE;
break;
}
g726_init_state(&handle->context);
codec->private_info = handle;
handle->bits_per_frame = (switch_byte_t) (codec->implementation->bits_per_second / (codec->implementation->samples_per_second));
handle->mode = (flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2"))
handle->bits_per_frame =
(switch_byte_t) (codec->implementation->bits_per_second / (codec->implementation->samples_per_second));
handle->mode = (flags & SWITCH_CODEC_FLAG_AAL2 || strstr(codec->implementation->iananame, "AAL2"))
? SWITCH_BITPACK_MODE_AAL2 : SWITCH_BITPACK_MODE_RFC3551;
return SWITCH_STATUS_SUCCESS;
}
}
static switch_status_t switch_g726_destroy(switch_codec_t *codec)
static switch_status_t switch_g726_destroy(switch_codec_t *codec)
{
codec->private_info = NULL;
return SWITCH_STATUS_SUCCESS;
@@ -111,17 +113,13 @@ static switch_status_t switch_g726_destroy(switch_codec_t *codec)
static switch_status_t switch_g726_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len,
uint32_t *encoded_rate,
unsigned int *flag)
static switch_status_t switch_g726_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
g726_handle_t *handle = codec->private_info;
@@ -153,7 +151,8 @@ static switch_status_t switch_g726_encode(switch_codec_t *codec,
if (new_len <= *encoded_data_len) {
*encoded_data_len = new_len;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u >= %u\n", new_len,
*encoded_data_len);
return SWITCH_STATUS_FALSE;
}
}
@@ -163,17 +162,13 @@ static switch_status_t switch_g726_encode(switch_codec_t *codec,
static switch_status_t switch_g726_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len,
uint32_t *decoded_rate,
unsigned int *flag)
static switch_status_t switch_g726_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
g726_handle_t *handle = codec->private_info;
@@ -192,13 +187,13 @@ static switch_status_t switch_g726_decode(switch_codec_t *codec,
for (y = 0; y < handle->loops; y++) {
switch_bitpack_out(&handle->unpack, in[z++]);
}
for(y = 0; y < handle->bytes; y++) {
for (y = 0; y < handle->bytes; y++) {
*ddp++ = (int16_t) handle->decoder(handle->buf[y], AUDIO_ENCODING_LINEAR, context);
new_len += 2;
new_len += 2;
}
switch_bitpack_done(&handle->unpack);
}
if (new_len <= *decoded_data_len) {
*decoded_data_len = new_len;
} else {
@@ -213,239 +208,239 @@ static switch_status_t switch_g726_decode(switch_codec_t *codec,
/* Registration */
/* Registration */
static const switch_codec_implementation_t g726_16k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 127,
/*.iananame */ "G726-16",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 16000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 40,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t g726_24k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 126,
/*.iananame */ "G726-24",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 24000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 60,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t g726_32k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 2,
/*.iananame */ "G726-32",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 32000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 80,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t g726_40k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 125,
/*.iananame */ "G726-40",
static const switch_codec_implementation_t g726_16k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 127,
/*.iananame */ "G726-16",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 40000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 100,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
/*.bits_per_second */ 16000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 40,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t aal2_g726_16k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 124,
/*.iananame */ "AAL2-G726-16",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 16000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 40,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t aal2_g726_24k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 123,
/*.iananame */ "AAL2-G726-24",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 24000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 60,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t aal2_g726_32k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 2,
/*.iananame */ "AAL2-G726-32",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 32000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 80,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t aal2_g726_40k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 122,
/*.iananame */ "AAL2-G726-40",
static const switch_codec_implementation_t g726_24k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 126,
/*.iananame */ "G726-24",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 40000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 100,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
/*.bits_per_second */ 24000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 60,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
const switch_codec_interface_t g726_16k_codec_interface = {
/*.interface_name */ "G.726 16k",
/*.implementations */ &g726_16k_implementation,
static const switch_codec_implementation_t g726_32k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 2,
/*.iananame */ "G726-32",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 32000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 80,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
const switch_codec_interface_t g726_24k_codec_interface = {
/*.interface_name */ "G.726 24k",
/*.implementations */ &g726_24k_implementation,
static const switch_codec_implementation_t g726_40k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 125,
/*.iananame */ "G726-40",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 40000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 100,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t aal2_g726_16k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 124,
/*.iananame */ "AAL2-G726-16",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 16000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 40,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t aal2_g726_24k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 123,
/*.iananame */ "AAL2-G726-24",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 24000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 60,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t aal2_g726_32k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 2,
/*.iananame */ "AAL2-G726-32",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 32000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 80,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
static const switch_codec_implementation_t aal2_g726_40k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 122,
/*.iananame */ "AAL2-G726-40",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 40000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 100,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g726_init,
/*.encode */ switch_g726_encode,
/*.decode */ switch_g726_decode,
/*.destroy */ switch_g726_destroy,
};
const switch_codec_interface_t g726_16k_codec_interface = {
/*.interface_name */ "G.726 16k",
/*.implementations */ &g726_16k_implementation,
};
const switch_codec_interface_t g726_24k_codec_interface = {
/*.interface_name */ "G.726 24k",
/*.implementations */ &g726_24k_implementation,
/*.next */ &g726_16k_codec_interface
};
const switch_codec_interface_t g726_32k_codec_interface = {
/*.interface_name */ "G.726 32k",
/*.implementations */ &g726_32k_implementation,
const switch_codec_interface_t g726_32k_codec_interface = {
/*.interface_name */ "G.726 32k",
/*.implementations */ &g726_32k_implementation,
/*.next */ &g726_24k_codec_interface
};
const switch_codec_interface_t g726_40k_codec_interface = {
/*.interface_name */ "G.726 40k",
/*.implementations */ &g726_40k_implementation,
const switch_codec_interface_t g726_40k_codec_interface = {
/*.interface_name */ "G.726 40k",
/*.implementations */ &g726_40k_implementation,
/*.next */ &g726_32k_codec_interface
};
const switch_codec_interface_t aal2_g726_16k_codec_interface = {
/*.interface_name */ "G.726 16k (aal2)",
/*.implementations */ &aal2_g726_16k_implementation,
const switch_codec_interface_t aal2_g726_16k_codec_interface = {
/*.interface_name */ "G.726 16k (aal2)",
/*.implementations */ &aal2_g726_16k_implementation,
/*.next */ &g726_40k_codec_interface
};
const switch_codec_interface_t aal2_g726_24k_codec_interface = {
/*.interface_name */ "G.726 24k (aal2)",
/*.implementations */ &aal2_g726_24k_implementation,
const switch_codec_interface_t aal2_g726_24k_codec_interface = {
/*.interface_name */ "G.726 24k (aal2)",
/*.implementations */ &aal2_g726_24k_implementation,
/*.next */ &aal2_g726_16k_codec_interface
};
const switch_codec_interface_t aal2_g726_32k_codec_interface = {
/*.interface_name */ "G.726 32k (aal2)",
/*.implementations */ &aal2_g726_32k_implementation,
const switch_codec_interface_t aal2_g726_32k_codec_interface = {
/*.interface_name */ "G.726 32k (aal2)",
/*.implementations */ &aal2_g726_32k_implementation,
/*.next */ &aal2_g726_24k_codec_interface
};
const switch_codec_interface_t aal2_g726_40k_codec_interface = {
/*.interface_name */ "G.726 40k (aal2)",
/*.implementations */ &aal2_g726_40k_implementation,
const switch_codec_interface_t aal2_g726_40k_codec_interface = {
/*.interface_name */ "G.726 40k (aal2)",
/*.implementations */ &aal2_g726_40k_implementation,
/*.next */ &aal2_g726_32k_codec_interface
};
static switch_loadable_module_interface_t g726_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &aal2_g726_40k_codec_interface,
/*.application_interface */ NULL
static switch_loadable_module_interface_t g726_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &aal2_g726_40k_codec_interface,
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &g726_module_interface;
/* indicate that the module should continue to be loaded */
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+75 -81
View File
@@ -30,7 +30,7 @@
*
* mod_g729.c -- G729 Codec Module
*
*/
*/
static const char modname[] = "mod_g729";
@@ -46,15 +46,15 @@ struct g729_context {
#endif
static switch_status_t switch_g729_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
#ifdef G729_PASSTHROUGH
codec->flags |= SWITCH_CODEC_FLAG_PASSTHROUGH;
if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
}
if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
}
return SWITCH_STATUS_SUCCESS;
#else
#else
struct g729_context *context = NULL;
int encoding, decoding;
@@ -64,9 +64,9 @@ static switch_status_t switch_g729_init(switch_codec_t *codec, switch_codec_flag
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) {
return SWITCH_STATUS_FALSE;
} else {
if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
}
if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
}
if (encoding) {
g729_init_coder(&context->encoder_object, 0);
@@ -84,7 +84,7 @@ static switch_status_t switch_g729_init(switch_codec_t *codec, switch_codec_flag
#endif
}
static switch_status_t switch_g729_destroy(switch_codec_t *codec)
static switch_status_t switch_g729_destroy(switch_codec_t *codec)
{
#ifndef G729_PASSTHROUGH
codec->private_info = NULL;
@@ -92,17 +92,13 @@ static switch_status_t switch_g729_destroy(switch_codec_t *codec)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_g729_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len,
uint32_t *encoded_rate,
unsigned int *flag)
static switch_status_t switch_g729_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
#ifdef G729_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -117,7 +113,7 @@ static switch_status_t switch_g729_encode(switch_codec_t *codec,
if (decoded_data_len % 160 == 0) {
uint32_t new_len = 0;
INT16 * ddp = decoded_data;
INT16 *ddp = decoded_data;
char *edp = encoded_data;
int x;
int loops = (int) decoded_data_len / 160;
@@ -132,7 +128,8 @@ static switch_status_t switch_g729_encode(switch_codec_t *codec,
if (new_len <= *encoded_data_len) {
*encoded_data_len = new_len;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u >= %u\n", new_len,
*encoded_data_len);
return SWITCH_STATUS_FALSE;
}
}
@@ -140,17 +137,13 @@ static switch_status_t switch_g729_encode(switch_codec_t *codec,
#endif
}
static switch_status_t switch_g729_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len,
uint32_t *decoded_rate,
unsigned int *flag)
static switch_status_t switch_g729_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
#ifdef G729_PASSTHROUGH
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This codec is only usable in passthrough mode!\n");
@@ -189,7 +182,7 @@ static switch_status_t switch_g729_decode(switch_codec_t *codec,
uint32_t new_len = 0;
test = (uint8_t *) encoded_data;
if (*test == 0 && *(test+1) == 0) {
if (*test == 0 && *(test + 1) == 0) {
*decoded_data_len = (encoded_data_len / divisor) * 160;
memset(decoded_data, 0, *decoded_data_len);
return SWITCH_STATUS_SUCCESS;
@@ -213,55 +206,56 @@ static switch_status_t switch_g729_decode(switch_codec_t *codec,
return SWITCH_STATUS_FALSE;
}
}
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "yo this frame is an odd size [%d]\n", encoded_data_len);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "yo this frame is an odd size [%d]\n",
encoded_data_len);
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
#endif
}
/* Registration */
/* Registration */
static const switch_codec_implementation_t g729_10ms_8k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 18,
/*.iananame */ "G729",
static const switch_codec_implementation_t g729_10ms_8k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 18,
/*.iananame */ "G729",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 32000,
/*.microseconds_per_frame */ 10000,
/*.samples_per_frame */ 80,
/*.bytes_per_frame */ 160,
/*.encoded_bytes_per_frame */ 10,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g729_init,
/*.encode */ switch_g729_encode,
/*.decode */ switch_g729_decode,
/*.destroy */ switch_g729_destroy,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 32000,
/*.microseconds_per_frame */ 10000,
/*.samples_per_frame */ 80,
/*.bytes_per_frame */ 160,
/*.encoded_bytes_per_frame */ 10,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g729_init,
/*.encode */ switch_g729_encode,
/*.decode */ switch_g729_decode,
/*.destroy */ switch_g729_destroy,
};
static const switch_codec_implementation_t g729_8k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 18,
/*.iananame */ "G729",
static const switch_codec_implementation_t g729_8k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 18,
/*.iananame */ "G729",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 64000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 20,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g729_init,
/*.encode */ switch_g729_encode,
/*.decode */ switch_g729_decode,
/*.destroy */ switch_g729_destroy,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 64000,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 20,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_g729_init,
/*.encode */ switch_g729_encode,
/*.decode */ switch_g729_decode,
/*.destroy */ switch_g729_destroy,
&g729_10ms_8k_implementation
};
@@ -271,22 +265,22 @@ static const switch_codec_interface_t g729_codec_interface = {
/*.next */ NULL
};
static switch_loadable_module_interface_t g729_module_interface = {
static switch_loadable_module_interface_t g729_module_interface = {
/*.module_name */ "g729",
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &g729_codec_interface,
/*.application_interface */ NULL
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &g729_codec_interface,
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &g729_module_interface;
/* indicate that the module should continue to be loaded */
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+53 -50
View File
@@ -28,7 +28,7 @@
*
* mod_codec_gsm.c -- gsm Codec Module
*
*/
*/
#include "switch.h"
#include "gsm.h"
static const char modname[] = "mod_gsm";
@@ -37,7 +37,7 @@ struct gsm_context {
gsm decoder;
};
static switch_status_t switch_gsm_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
struct gsm_context *context;
int encoding, decoding;
@@ -55,7 +55,7 @@ static switch_status_t switch_gsm_init(switch_codec_t *codec, switch_codec_flag_
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_gsm_destroy(switch_codec_t *codec)
static switch_status_t switch_gsm_destroy(switch_codec_t *codec)
{
struct gsm_context *context = codec->private_info;
int encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE);
@@ -68,8 +68,8 @@ static switch_status_t switch_gsm_destroy(switch_codec_t *codec)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_gsm_encode(switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data,
uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data,
uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
struct gsm_context *context = codec->private_info;
if (!context) {
@@ -77,8 +77,8 @@ static switch_status_t switch_gsm_encode(switch_codec_t *codec, switch_codec_t *
}
if (decoded_data_len % 320 == 0) {
uint32_t new_len = 0;
gsm_signal * ddp = decoded_data;
gsm_byte * edp = encoded_data;
gsm_signal *ddp = decoded_data;
gsm_byte *edp = encoded_data;
int x;
int loops = (int) decoded_data_len / 320;
for (x = 0; x < loops && new_len < *encoded_data_len; x++) {
@@ -90,15 +90,16 @@ static switch_status_t switch_gsm_encode(switch_codec_t *codec, switch_codec_t *
if (new_len <= *encoded_data_len) {
*encoded_data_len = new_len;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u >= %u\n", new_len,
*encoded_data_len);
return SWITCH_STATUS_FALSE;
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_gsm_decode(switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data,
uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data,
uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
struct gsm_context *context = codec->private_info;
if (!context) {
@@ -107,8 +108,8 @@ static switch_status_t switch_gsm_decode(switch_codec_t *codec, switch_codec_t *
if (encoded_data_len % 33 == 0) {
int loops = (int) encoded_data_len / 33;
gsm_byte * edp = encoded_data;
gsm_signal * ddp = decoded_data;
gsm_byte *edp = encoded_data;
gsm_signal *ddp = decoded_data;
int x;
uint32_t new_len = 0;
@@ -121,57 +122,59 @@ static switch_status_t switch_gsm_decode(switch_codec_t *codec, switch_codec_t *
if (new_len <= *decoded_data_len) {
*decoded_data_len = new_len;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u %u\n", new_len, *decoded_data_len);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u %u\n", new_len,
*decoded_data_len);
return SWITCH_STATUS_FALSE;
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "yo this frame is an odd size [%u]\n", encoded_data_len);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "yo this frame is an odd size [%u]\n",
encoded_data_len);
}
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
static const switch_codec_implementation_t gsm_8k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 3,
/*.iananame */ "GSM",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 13200,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 33,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_gsm_init,
/*.encode */ switch_gsm_encode,
/*.decode */ switch_gsm_decode,
/*.destroy */ switch_gsm_destroy,
/* Registration */
static const switch_codec_implementation_t gsm_8k_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 3,
/*.iananame */ "GSM",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 13200,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 33,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_gsm_init,
/*.encode */ switch_gsm_encode,
/*.decode */ switch_gsm_decode,
/*.destroy */ switch_gsm_destroy,
};
static const switch_codec_interface_t gsm_codec_interface = {
/*.interface_name */ "gsm",
/*.implementations */ &gsm_8k_implementation,
static const switch_codec_interface_t gsm_codec_interface = {
/*.interface_name */ "gsm",
/*.implementations */ &gsm_8k_implementation,
};
static switch_loadable_module_interface_t gsm_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &gsm_codec_interface,
/*.application_interface */ NULL
static switch_loadable_module_interface_t gsm_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &gsm_codec_interface,
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &gsm_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &gsm_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
/* For Emacs:
+142 -144
View File
@@ -28,7 +28,7 @@
*
* mod_ilbc.c -- ilbc Codec Module
*
*/
*/
#include "switch.h"
#include "iLBC_encode.h"
#include "iLBC_decode.h"
@@ -45,11 +45,11 @@ struct ilbc_context {
};
static switch_status_t switch_ilbc_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
struct ilbc_context *context;
int encoding, decoding;
uint8_t ms = (uint8_t)(codec->implementation->microseconds_per_frame / 1000);
uint8_t ms = (uint8_t) (codec->implementation->microseconds_per_frame / 1000);
if (ms != 20 && ms != 30) {
@@ -82,13 +82,13 @@ static switch_status_t switch_ilbc_init(switch_codec_t *codec, switch_codec_flag
}
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->implementation->fmtp);
codec->private_info = context;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_ilbc_destroy(switch_codec_t *codec)
static switch_status_t switch_ilbc_destroy(switch_codec_t *codec)
{
codec->private_info = NULL;
return SWITCH_STATUS_SUCCESS;
@@ -96,14 +96,12 @@ static switch_status_t switch_ilbc_destroy(switch_codec_t *codec)
static switch_status_t switch_ilbc_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len,
uint32_t *encoded_rate,
unsigned int *flag)
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
struct ilbc_context *context = codec->private_info;
@@ -120,7 +118,7 @@ static switch_status_t switch_ilbc_encode(switch_codec_t *codec,
float buf[240];
for (x = 0; x < loops && new_len < *encoded_data_len; x++) {
for(y = 0; y < context->dbytes / sizeof(short) ; y++) {
for (y = 0; y < context->dbytes / sizeof(short); y++) {
buf[y] = ddp[y];
}
iLBC_encode(edp, buf, &context->encoder);
@@ -131,7 +129,8 @@ static switch_status_t switch_ilbc_encode(switch_codec_t *codec,
if (new_len <= *encoded_data_len) {
*encoded_data_len = new_len;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "buffer overflow!!! %u >= %u\n", new_len,
*encoded_data_len);
return SWITCH_STATUS_FALSE;
}
}
@@ -139,14 +138,12 @@ static switch_status_t switch_ilbc_encode(switch_codec_t *codec,
}
static switch_status_t switch_ilbc_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len,
uint32_t *decoded_rate,
unsigned int *flag)
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
struct ilbc_context *context = codec->private_info;
@@ -165,8 +162,8 @@ static switch_status_t switch_ilbc_decode(switch_codec_t *codec,
for (x = 0; x < loops && new_len < *decoded_data_len; x++) {
iLBC_decode(buf, edp, &context->decoder, 1);
for(y = 0; y < context->dbytes / sizeof(short) ; y++) {
ddp[y] = (short)buf[y];
for (y = 0; y < context->dbytes / sizeof(short); y++) {
ddp[y] = (short) buf[y];
}
ddp += context->dbytes / sizeof(short);
edp += context->bytes;
@@ -179,160 +176,161 @@ static switch_status_t switch_ilbc_decode(switch_codec_t *codec,
return SWITCH_STATUS_FALSE;
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "yo this frame is an odd size [%d]\n", encoded_data_len);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "yo this frame is an odd size [%d]\n",
encoded_data_len);
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
/* Registration */
static const switch_codec_implementation_t ilbc_8k_30ms_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 97,
/*.iananame */ "iLBC",
/*.fmtp */ "mode=30",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_30MS*8*8000/BLOCKL_30MS,
/*.microseconds_per_frame */ 30000,
/*.samples_per_frame */ 240,
/*.bytes_per_frame */ 480,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_30MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy
static const switch_codec_implementation_t ilbc_8k_30ms_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 97,
/*.iananame */ "iLBC",
/*.fmtp */ "mode=30",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
/*.microseconds_per_frame */ 30000,
/*.samples_per_frame */ 240,
/*.bytes_per_frame */ 480,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_30MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy
};
static const switch_codec_implementation_t ilbc_8k_20ms_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 97,
/*.iananame */ "iLBC",
/*.fmtp */ "mode=20",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_20MS*8*8000/BLOCKL_20MS,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy,
/*.next */ &ilbc_8k_30ms_implementation
static const switch_codec_implementation_t ilbc_8k_20ms_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 97,
/*.iananame */ "iLBC",
/*.fmtp */ "mode=20",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy,
/*.next */ &ilbc_8k_30ms_implementation
};
static const switch_codec_implementation_t ilbc_102_8k_30ms_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 102,
/*.iananame */ "iLBC",
/*.fmtp */ "mode=30",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_30MS*8*8000/BLOCKL_30MS,
/*.microseconds_per_frame */ 30000,
/*.samples_per_frame */ 240,
/*.bytes_per_frame */ 480,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_30MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy
static const switch_codec_implementation_t ilbc_102_8k_30ms_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 102,
/*.iananame */ "iLBC",
/*.fmtp */ "mode=30",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_30MS * 8 * 8000 / BLOCKL_30MS,
/*.microseconds_per_frame */ 30000,
/*.samples_per_frame */ 240,
/*.bytes_per_frame */ 480,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_30MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy
};
static const switch_codec_implementation_t ilbc_102_8k_20ms_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 102,
/*.iananame */ "iLBC102",
/*.fmtp */ "mode=20",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_20MS*8*8000/BLOCKL_20MS,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy,
/*.next */ &ilbc_102_8k_30ms_implementation
static const switch_codec_implementation_t ilbc_102_8k_20ms_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 102,
/*.iananame */ "iLBC102",
/*.fmtp */ "mode=20",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy,
/*.next */ &ilbc_102_8k_30ms_implementation
};
static const switch_codec_implementation_t ilbc_8k_20ms_nonext_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 97,
/*.iananame */ "iLBC20ms",
/*.fmtp */ "mode=20",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_20MS*8*8000/BLOCKL_20MS,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy
static const switch_codec_implementation_t ilbc_8k_20ms_nonext_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 97,
/*.iananame */ "iLBC20ms",
/*.fmtp */ "mode=20",
/*.samples_per_second */ 8000,
/*.bits_per_second */ NO_OF_BYTES_20MS * 8 * 8000 / BLOCKL_20MS,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ NO_OF_BYTES_20MS,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_ilbc_init,
/*.encode */ switch_ilbc_encode,
/*.decode */ switch_ilbc_decode,
/*.destroy */ switch_ilbc_destroy
};
static const switch_codec_interface_t ilbc_20ms_codec_interface = {
/*.interface_name */ "ilbc",
/*.implementations */ &ilbc_8k_20ms_nonext_implementation
static const switch_codec_interface_t ilbc_20ms_codec_interface = {
/*.interface_name */ "ilbc",
/*.implementations */ &ilbc_8k_20ms_nonext_implementation
};
static const switch_codec_interface_t ilbc_102_codec_interface = {
/*.interface_name */ "ilbc",
/*.implementations */ &ilbc_102_8k_20ms_implementation,
/*.next*/ &ilbc_20ms_codec_interface
static const switch_codec_interface_t ilbc_102_codec_interface = {
/*.interface_name */ "ilbc",
/*.implementations */ &ilbc_102_8k_20ms_implementation,
/*.next */ &ilbc_20ms_codec_interface
};
static const switch_codec_interface_t ilbc_codec_interface = {
/*.interface_name */ "ilbc",
/*.implementations */ &ilbc_8k_20ms_implementation,
/*.next*/ &ilbc_102_codec_interface
static const switch_codec_interface_t ilbc_codec_interface = {
/*.interface_name */ "ilbc",
/*.implementations */ &ilbc_8k_20ms_implementation,
/*.next */ &ilbc_102_codec_interface
};
static switch_loadable_module_interface_t ilbc_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &ilbc_codec_interface,
/*.application_interface */ NULL
static switch_loadable_module_interface_t ilbc_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &ilbc_codec_interface,
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &ilbc_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &ilbc_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+21 -17
View File
@@ -35,7 +35,7 @@ static const char modname[] = "mod_l16";
static switch_status_t switch_raw_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
int encoding, decoding;
@@ -50,15 +50,16 @@ static switch_status_t switch_raw_init(switch_codec_t *codec, switch_codec_flag_
}
static switch_status_t switch_raw_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
/* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */
if (codec && other_codec && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
if (codec && other_codec
&& codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
memcpy(encoded_data, decoded_data, decoded_data_len);
*encoded_data_len = decoded_data_len;
return SWITCH_STATUS_RESAMPLE;
@@ -67,14 +68,15 @@ static switch_status_t switch_raw_encode(switch_codec_t *codec,
}
static switch_status_t switch_raw_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
if (codec && other_codec && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
if (codec && other_codec
&& codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
memcpy(decoded_data, encoded_data, encoded_data_len);
*decoded_data_len = encoded_data_len;
return SWITCH_STATUS_RESAMPLE;
@@ -107,7 +109,7 @@ static const switch_codec_implementation_t raw_32k_60ms_implementation = {
/*.encode = */ switch_raw_encode,
/*.decode = */ switch_raw_decode,
/*.destroy = */ switch_raw_destroy
/*.next = */
/*.next = */
};
static const switch_codec_implementation_t raw_32k_30ms_implementation = {
@@ -298,6 +300,7 @@ static const switch_codec_implementation_t raw_16k_10ms_implementation = {
/*.destroy = */ switch_raw_destroy,
/*.next = */ &raw_16k_20ms_implementation
};
///////////////////////////////
@@ -426,7 +429,8 @@ static switch_loadable_module_interface_t raw_module_interface = {
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &raw_module_interface;
+60 -68
View File
@@ -28,16 +28,16 @@
*
* mod_lpc10.c -- LPC10 Codec Module
*
*/
*/
#include "switch.h"
#include "lpc10.h"
enum {
SamplesPerFrame = 180,
BitsPerFrame = 54,
BytesPerFrame = (BitsPerFrame+7)/8,
BitsPerSecond = 2400
BitsPerFrame = 54,
BytesPerFrame = (BitsPerFrame + 7) / 8,
BitsPerSecond = 2400
};
#define SampleValueScale 32768.0
@@ -52,7 +52,7 @@ struct lpc10_context {
};
static switch_status_t switch_lpc10_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
uint32_t encoding, decoding;
struct lpc10_context *context = NULL;
@@ -78,44 +78,40 @@ static switch_status_t switch_lpc10_init(switch_codec_t *codec, switch_codec_fla
}
}
static switch_status_t switch_lpc10_destroy(switch_codec_t *codec)
static switch_status_t switch_lpc10_destroy(switch_codec_t *codec)
{
codec->private_info = NULL;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_lpc10_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len,
uint32_t *encoded_rate,
unsigned int *flag)
static switch_status_t switch_lpc10_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
struct lpc10_context *context = codec->private_info;
uint8_t i;
int32_t bits[BitsPerFrame];
real speech[SamplesPerFrame];
const short *sampleBuffer = (const short *)decoded_data;
unsigned char *buffer = (unsigned char *)encoded_data;
const short *sampleBuffer = (const short *) decoded_data;
unsigned char *buffer = (unsigned char *) encoded_data;
if (!context) {
return SWITCH_STATUS_FALSE;
}
for (i = 0; i < SamplesPerFrame; i++)
speech[i] = (real)(sampleBuffer[i]/SampleValueScale);
speech[i] = (real) (sampleBuffer[i] / SampleValueScale);
lpc10_encode(speech, bits, &context->encoder_object);
memset(encoded_data, 0, BytesPerFrame);
for (i = 0; i < BitsPerFrame; i++) {
if (bits[i])
buffer[i>>3] |= 1 << (i&7);
buffer[i >> 3] |= 1 << (i & 7);
}
*encoded_data_len = BytesPerFrame;
@@ -123,91 +119,87 @@ static switch_status_t switch_lpc10_encode(switch_codec_t *codec,
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t switch_lpc10_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len,
uint32_t *decoded_rate,
unsigned int *flag)
static switch_status_t switch_lpc10_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
struct lpc10_context *context = codec->private_info;
int i;
INT32 bits[BitsPerFrame];
real speech[SamplesPerFrame];
short *sampleBuffer = (short *)decoded_data;
const unsigned char *buffer = (const unsigned char *)encoded_data;
short *sampleBuffer = (short *) decoded_data;
const unsigned char *buffer = (const unsigned char *) encoded_data;
if (!context) {
return SWITCH_STATUS_FALSE;
}
for (i = 0; i < BitsPerFrame; i++)
bits[i] = (buffer[i>>3]&(1<<(i&7))) != 0;
bits[i] = (buffer[i >> 3] & (1 << (i & 7))) != 0;
lpc10_decode(bits, speech, &context->decoder_object);
for (i = 0; i < SamplesPerFrame; i++) {
real sample = (real)(speech[i]*SampleValueScale);
real sample = (real) (speech[i] * SampleValueScale);
if (sample < MinSampleValue)
sample = MinSampleValue;
else if (sample > MaxSampleValue)
sample = MaxSampleValue;
sampleBuffer[i] = (short)sample;
sampleBuffer[i] = (short) sample;
}
*decoded_data_len = SamplesPerFrame*2;
*decoded_data_len = SamplesPerFrame * 2;
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
/* Registration */
static const switch_codec_implementation_t lpc10_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 7,
/*.iananame */ "LPC",
static const switch_codec_implementation_t lpc10_implementation = {
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 7,
/*.iananame */ "LPC",
/*.fmtp */ NULL,
/*.samples_per_second */ 8000,
/*.bits_per_second */ 240,
/*.microseconds_per_frame */ 22500,
/*.samples_per_frame */ 180,
/*.bytes_per_frame */ 360,
/*.encoded_bytes_per_frame */ 7,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_lpc10_init,
/*.encode */ switch_lpc10_encode,
/*.decode */ switch_lpc10_decode,
/*.destroy */ switch_lpc10_destroy,
/*.bits_per_second */ 240,
/*.microseconds_per_frame */ 22500,
/*.samples_per_frame */ 180,
/*.bytes_per_frame */ 360,
/*.encoded_bytes_per_frame */ 7,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_lpc10_init,
/*.encode */ switch_lpc10_encode,
/*.decode */ switch_lpc10_decode,
/*.destroy */ switch_lpc10_destroy,
};
const switch_codec_interface_t lpc10_codec_interface = {
/*.interface_name */ "LPC-10 2.4kbps",
/*.implementations */ &lpc10_implementation,
const switch_codec_interface_t lpc10_codec_interface = {
/*.interface_name */ "LPC-10 2.4kbps",
/*.implementations */ &lpc10_implementation,
};
static switch_loadable_module_interface_t lpc10_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &lpc10_codec_interface,
/*.application_interface */ NULL
static switch_loadable_module_interface_t lpc10_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &lpc10_codec_interface,
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &lpc10_module_interface;
/* indicate that the module should continue to be loaded */
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
+15 -14
View File
@@ -73,7 +73,7 @@ struct speex_context {
};
static switch_status_t switch_speex_init(switch_codec_t *codec, switch_codec_flag_t flags,
const switch_codec_settings_t *codec_settings)
const switch_codec_settings_t *codec_settings)
{
struct speex_context *context = NULL;
int encoding, decoding;
@@ -158,12 +158,12 @@ static switch_status_t switch_speex_init(switch_codec_t *codec, switch_codec_fla
}
static switch_status_t switch_speex_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *decoded_data,
uint32_t decoded_data_len,
uint32_t decoded_rate,
void *encoded_data,
uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag)
{
struct speex_context *context = codec->private_info;
short *buf;
@@ -211,12 +211,12 @@ static switch_status_t switch_speex_encode(switch_codec_t *codec,
}
static switch_status_t switch_speex_decode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
switch_codec_t *other_codec,
void *encoded_data,
uint32_t encoded_data_len,
uint32_t encoded_rate,
void *decoded_data,
uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag)
{
struct speex_context *context = codec->private_info;
short *buf;
@@ -343,7 +343,8 @@ static switch_loadable_module_interface_t speex_module_interface = {
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &speex_module_interface;
@@ -46,12 +46,12 @@ static struct {
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_directory_name, globals.directory_name)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_host, globals.host)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dn, globals.dn)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_base, globals.base)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_host, globals.host)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dn, globals.dn)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_base, globals.base)
static void load_config(void)
static void load_config(void)
{
char *cf = "dialplan_directory.conf";
switch_xml_t cfg, xml, settings, param;
@@ -100,19 +100,16 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t
caller_profile = switch_channel_get_caller_profile(channel);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name,
caller_profile->destination_number);
if (! (globals.directory_name && globals.host && globals.dn && globals.base && globals.pass)) {
caller_profile->destination_number);
if (!(globals.directory_name && globals.host && globals.dn && globals.base && globals.pass)) {
return NULL;
}
if (switch_core_directory_open(&dh,
if (switch_core_directory_open(&dh,
globals.directory_name,
globals.host,
globals.dn,
globals.pass,
NULL) != SWITCH_STATUS_SUCCESS) {
globals.host, globals.dn, globals.pass, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't connect\n");
return NULL;
}
@@ -127,10 +124,10 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t
while (switch_core_directory_next(&dh) == SWITCH_STATUS_SUCCESS) {
while (switch_core_directory_next_pair(&dh, &var, &val) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DIRECTORY VALUE [%s]=[%s]\n", var, val);
if(!strcasecmp(var, "callflow")) {
if (!strcasecmp(var, "callflow")) {
if (!extension) {
if ((extension = switch_caller_extension_new(session, caller_profile->destination_number,
caller_profile->destination_number)) == 0) {
caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
goto out;
}
@@ -143,11 +140,11 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t
}
}
}
out:
out:
switch_core_directory_close(&dh);
if (extension) {
switch_channel_set_state(channel, CS_EXECUTE);
}
@@ -159,7 +156,7 @@ static switch_caller_extension_t *directory_dialplan_hunt(switch_core_session_t
static const switch_dialplan_interface_t directory_dialplan_interface = {
/*.interface_name = */ "directory",
/*.hunt_function = */ directory_dialplan_hunt
/*.next = NULL */
/*.next = NULL */
};
static const switch_loadable_module_interface_t directory_dialplan_module_interface = {
@@ -171,7 +168,8 @@ static const switch_loadable_module_interface_t directory_dialplan_module_interf
/*.application_interface = */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
load_config();
@@ -50,7 +50,7 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
switch_channel_t *channel;
char *exten_name = (char *) switch_xml_attr_soft(xexten, "name");
int proceed = 0;
switch_stream_handle_t stream = {0};
switch_stream_handle_t stream = { 0 };
channel = switch_core_session_get_channel(session);
caller_profile = switch_channel_get_caller_profile(channel);
@@ -63,7 +63,7 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
switch_regex_t *re = NULL;
int ovector[30];
break_t do_break_i = BREAK_ON_FALSE;
field = (char *) switch_xml_attr(xcond, "field");
expression = (char *) switch_xml_attr_soft(xcond, "expression");
@@ -83,54 +83,58 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
if (field) {
if (*field == '$') {
char *cmd = switch_core_session_strdup(session, field + 1);
char *e, *arg;
field = cmd;
field_data = "";
char *e, *arg;
field = cmd;
field_data = "";
if (*field == '{') {
field++;
if ((e = strchr(field, '}'))) {
*e = '\0';
field_data = switch_channel_get_variable(channel, field);
}
} else {
switch_safe_free(stream.data);
memset(&stream, 0, sizeof(stream));
SWITCH_STANDARD_STREAM(stream);
if (*field == '{') {
field++;
if ((e = strchr(field, '}'))) {
*e = '\0';
field_data = switch_channel_get_variable(channel, field);
}
} else {
switch_safe_free(stream.data);
memset(&stream, 0, sizeof(stream));
SWITCH_STANDARD_STREAM(stream);
if ((arg = strchr(cmd, '('))) {
*arg++ = '\0';
if ((e = strchr(arg, ')'))) {
*e = '\0';
if (switch_api_execute(cmd, arg, session, &stream) == SWITCH_STATUS_SUCCESS) {
field_data = stream.data;
}
}
}
}
} else {
if ((arg = strchr(cmd, '('))) {
*arg++ = '\0';
if ((e = strchr(arg, ')'))) {
*e = '\0';
if (switch_api_execute(cmd, arg, session, &stream) == SWITCH_STATUS_SUCCESS) {
field_data = stream.data;
}
}
}
}
} else {
field_data = switch_caller_get_field_by_name(caller_profile, field);
}
if (!field_data) {
field_data = "";
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field, field_data, expression);
if (!(proceed = switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "test conditions %s(%s) =~ /%s/\n", field,
field_data, expression);
if (!
(proceed =
switch_regex_perform(field_data, expression, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Regex mismatch\n");
for (xaction = switch_xml_child(xcond, "anti-action"); xaction; xaction = xaction->next) {
char *application = (char*) switch_xml_attr_soft(xaction, "application");
char *application = (char *) switch_xml_attr_soft(xaction, "application");
char *data = (char *) switch_xml_attr_soft(xaction, "data");
if (!*extension) {
if ((*extension =
switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
switch_caller_extension_new(session, exten_name,
caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
proceed = 0;
goto done;
proceed = 0;
goto done;
}
}
switch_caller_extension_add_application(session, *extension, application, data);
}
@@ -145,20 +149,20 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
char *application = (char*) switch_xml_attr_soft(xaction, "application");
char *application = (char *) switch_xml_attr_soft(xaction, "application");
char *data = (char *) switch_xml_attr_soft(xaction, "data");
char *substituted = NULL;
uint32_t len = 0;
uint32_t len = 0;
char *app_data = NULL;
if (field && strchr(expression, '(')) {
len = (uint32_t)(strlen(data) + strlen(field_data) + 10);
if (!(substituted = malloc(len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
proceed = 0;
goto done;
}
memset(substituted, 0, len);
len = (uint32_t) (strlen(data) + strlen(field_data) + 10);
if (!(substituted = malloc(len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
proceed = 0;
goto done;
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, data, field_data, substituted, len, ovector);
app_data = substituted;
} else {
@@ -169,15 +173,15 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
if ((*extension =
switch_caller_extension_new(session, exten_name, caller_profile->destination_number)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n");
proceed = 0;
goto done;
proceed = 0;
goto done;
}
}
switch_caller_extension_add_application(session, *extension, application, app_data);
switch_safe_free(substituted);
switch_safe_free(substituted);
}
switch_regex_safe_free(re);
if (do_break_i == BREAK_ON_TRUE || do_break_i == BREAK_ALWAYS) {
@@ -185,110 +189,111 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
}
}
done:
switch_safe_free(stream.data);
done:
switch_safe_free(stream.data);
return proceed;
}
static switch_status_t dialplan_xml_locate(switch_core_session_t *session,
switch_caller_profile_t *caller_profile,
switch_xml_t *root,
switch_xml_t *node)
switch_xml_t * root, switch_xml_t * node)
{
switch_status_t status = SWITCH_STATUS_GENERR;
switch_channel_t *channel;
switch_stream_handle_t stream = {0};
switch_size_t encode_len = 1024, new_len = 0;
char *encode_buf = NULL;
char *prof[12] = {0}, *prof_names[12] = {0}, *e = NULL;
switch_hash_index_t *hi;
uint32_t x = 0;
switch_stream_handle_t stream = { 0 };
switch_size_t encode_len = 1024, new_len = 0;
char *encode_buf = NULL;
char *prof[12] = { 0 }, *prof_names[12] = {
0}, *e = NULL;
switch_hash_index_t *hi;
uint32_t x = 0;
channel = switch_core_session_get_channel(session);
SWITCH_STANDARD_STREAM(stream);
if (!(encode_buf = malloc(encode_len))) {
goto done;
}
prof[0] = caller_profile->context;
prof[1] = caller_profile->destination_number;
prof[2] = caller_profile->caller_id_name;
prof[3] = caller_profile->caller_id_number;
prof[4] = caller_profile->network_addr;
prof[5] = caller_profile->ani;
prof[6] = caller_profile->aniii;
prof[7] = caller_profile->rdnis;
prof[8] = caller_profile->source;
prof[9] = caller_profile->chan_name;
prof[10] = caller_profile->uuid;
SWITCH_STANDARD_STREAM(stream);
prof_names[0] = "context";
prof_names[1] = "destination_number";
prof_names[2] = "caller_id_name";
prof_names[3] = "caller_id_number";
prof_names[4] = "network_addr";
prof_names[5] = "ani";
prof_names[6] = "aniii";
prof_names[7] = "rdnis";
prof_names[8] = "source";
prof_names[9] = "chan_name";
prof_names[10] = "uuid";
if (!(encode_buf = malloc(encode_len))) {
goto done;
}
for (x = 0; prof[x]; x++) {
prof[0] = caller_profile->context;
prof[1] = caller_profile->destination_number;
prof[2] = caller_profile->caller_id_name;
prof[3] = caller_profile->caller_id_number;
prof[4] = caller_profile->network_addr;
prof[5] = caller_profile->ani;
prof[6] = caller_profile->aniii;
prof[7] = caller_profile->rdnis;
prof[8] = caller_profile->source;
prof[9] = caller_profile->chan_name;
prof[10] = caller_profile->uuid;
prof_names[0] = "context";
prof_names[1] = "destination_number";
prof_names[2] = "caller_id_name";
prof_names[3] = "caller_id_number";
prof_names[4] = "network_addr";
prof_names[5] = "ani";
prof_names[6] = "aniii";
prof_names[7] = "rdnis";
prof_names[8] = "source";
prof_names[9] = "chan_name";
prof_names[10] = "uuid";
for (x = 0; prof[x]; x++) {
if (switch_strlen_zero(prof[x])) {
continue;
}
new_len = (strlen(prof[x]) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
encode_len = new_len;
new_len = (strlen(prof[x]) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
if (!(tmp = realloc(encode_buf, encode_len))) {
goto done;
}
encode_len = new_len;
encode_buf = tmp;
}
switch_url_encode(prof[x], encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
}
if (!(tmp = realloc(encode_buf, encode_len))) {
goto done;
}
for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
void *val;
const void *var;
switch_hash_this(hi, &var, NULL, &val);
new_len = (strlen((char *) var) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
encode_len = new_len;
if (!(tmp = realloc(encode_buf, encode_len))) {
goto done;
}
encode_buf = tmp;
}
switch_url_encode((char *) val, encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
encode_buf = tmp;
}
switch_url_encode(prof[x], encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
}
e = (char *)stream.data + (strlen((char *)stream.data) - 1);
if (e && *e == '&') {
*e = '\0';
}
for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi;
hi = switch_hash_next(hi)) {
void *val;
const void *var;
switch_hash_this(hi, &var, NULL, &val);
new_len = (strlen((char *) var) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
encode_len = new_len;
if (!(tmp = realloc(encode_buf, encode_len))) {
goto done;
}
encode_buf = tmp;
}
switch_url_encode((char *) val, encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
}
e = (char *) stream.data + (strlen((char *) stream.data) - 1);
if (e && *e == '&') {
*e = '\0';
}
status = switch_xml_locate("dialplan", NULL, NULL, NULL, root, node, stream.data);
done:
done:
switch_safe_free(stream.data);
switch_safe_free(encode_buf);
return status;
@@ -300,7 +305,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
switch_caller_extension_t *extension = NULL;
switch_channel_t *channel;
switch_xml_t alt_root = NULL, cfg, xml = NULL, xcontext, xexten;
char *alt_path = (char *) arg;
char *alt_path = (char *) arg;
channel = switch_core_session_get_channel(session);
@@ -319,41 +324,43 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
/* get our handle to the "dialplan" section of the config */
if (!switch_strlen_zero(alt_path)) {
switch_xml_t conf = NULL, tag = NULL;
if (!(alt_root = switch_xml_parse_file(alt_path))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of [%s] failed\n", alt_path);
goto done;
}
if ((conf = switch_xml_find_child(alt_root, "section", "name", "dialplan")) &&
switch_xml_t conf = NULL, tag = NULL;
if (!(alt_root = switch_xml_parse_file(alt_path))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of [%s] failed\n", alt_path);
goto done;
}
if ((conf = switch_xml_find_child(alt_root, "section", "name", "dialplan")) &&
(tag = switch_xml_find_child(conf, "dialplan", NULL, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Getting dialplan from alternate path: %s\n", alt_path);
xml = alt_root;
cfg = tag;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Getting dialplan from alternate path: %s\n",
alt_path);
xml = alt_root;
cfg = tag;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
goto done;
}
} else {
if (dialplan_xml_locate(session, caller_profile, &xml, &cfg) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
goto done;
}
}
/* get a handle to the context tag */
}
/* get a handle to the context tag */
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", caller_profile->context))) {
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", "global"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "context %s not found\n", caller_profile->context);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "context %s not found\n",
caller_profile->context);
goto done;
}
}
if (!(xexten = switch_xml_find_child(xcontext, "extension", "name", caller_profile->destination_number))) {
xexten = switch_xml_child(xcontext, "extension");
}
while(xexten) {
while (xexten) {
int proceed = 0;
char *cont = (char *) switch_xml_attr_soft(xexten, "continue");
@@ -374,7 +381,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
switch_channel_set_state(channel, CS_EXECUTE);
}
done:
done:
switch_xml_free(xml);
return extension;
}
@@ -383,7 +390,7 @@ done:
static const switch_dialplan_interface_t dialplan_interface = {
/*.interface_name = */ "XML",
/*.hunt_function = */ dialplan_hunt
/*.next = NULL */
/*.next = NULL */
};
static const switch_loadable_module_interface_t dialplan_module_interface = {
@@ -395,7 +402,8 @@ static const switch_loadable_module_interface_t dialplan_module_interface = {
/*.application_interface = */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
+21 -20
View File
@@ -44,10 +44,10 @@ static const char modname[] = "mod_ldap";
struct ldap_context {
LDAP *ld;
LDAPMessage* msg;
LDAPMessage* entry;
BerElement* ber;
char* attr;
LDAPMessage *msg;
LDAPMessage *entry;
BerElement *ber;
char *attr;
char *var;
char *val;
char **vals;
@@ -60,14 +60,14 @@ struct ldap_context {
static switch_status_t mod_ldap_open(switch_directory_handle_t *dh, char *source, char *dsn, char *passwd)
{
struct ldap_context *context;
int auth_method = LDAP_AUTH_SIMPLE;
int auth_method = LDAP_AUTH_SIMPLE;
int desired_version = LDAP_VERSION3;
if ((context = switch_core_alloc(dh->memory_pool, sizeof(*context))) == 0) {
return SWITCH_STATUS_MEMERR;
}
if ((context->ld = ldap_init(source, LDAP_PORT)) == NULL ) {
if ((context->ld = ldap_init(source, LDAP_PORT)) == NULL) {
return SWITCH_STATUS_FALSE;
}
@@ -76,11 +76,11 @@ static switch_status_t mod_ldap_open(switch_directory_handle_t *dh, char *source
return SWITCH_STATUS_FALSE;
}
if (ldap_bind_s(context->ld, dsn, passwd, auth_method) != LDAP_SUCCESS ) {
if (ldap_bind_s(context->ld, dsn, passwd, auth_method) != LDAP_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
dh->private_info = context;
return SWITCH_STATUS_SUCCESS;
@@ -112,7 +112,7 @@ static switch_status_t mod_ldap_query(switch_directory_handle_t *dh, char *base,
if (ldap_count_entries(context->ld, context->msg) <= 0) {
return SWITCH_STATUS_FALSE;
}
return SWITCH_STATUS_SUCCESS;
}
@@ -161,7 +161,7 @@ static switch_status_t mod_ldap_next_pair(switch_directory_handle_t *dh, char **
*val = context->val;
return SWITCH_STATUS_SUCCESS;
} else {
itter:
itter:
if (context->attr && context->vals) {
if ((*val = context->vals[context->vi++])) {
*var = context->attr;
@@ -177,7 +177,7 @@ static switch_status_t mod_ldap_next_pair(switch_directory_handle_t *dh, char **
ldap_memfree(context->val);
context->val = NULL;
if (context->ber) {
ber_free(context->ber,0);
ber_free(context->ber, 0);
context->ber = NULL;
}
context->attr = ldap_first_attribute(context->ld, context->entry, &context->ber);
@@ -188,22 +188,23 @@ static switch_status_t mod_ldap_next_pair(switch_directory_handle_t *dh, char **
context->attr = ldap_next_attribute(context->ld, context->entry, context->ber);
}
context->vitt++;
if (context->entry && context->attr && (context->vals = ldap_get_values(context->ld, context->entry, context->attr)) != 0) {
if (context->entry && context->attr
&& (context->vals = ldap_get_values(context->ld, context->entry, context->attr)) != 0) {
goto itter;
}
}
return SWITCH_STATUS_FALSE;
}
static const switch_directory_interface_t ldap_directory_interface = {
/*.interface_name */ "ldap",
/*.directory_open*/ mod_ldap_open,
/*.directory_close*/ mod_ldap_close,
/*.directory_query*/ mod_ldap_query,
/*.directory_next*/ mod_ldap_next,
/*.directory_next_pair*/ mod_ldap_next_pair
/*.interface_name */ "ldap",
/*.directory_open */ mod_ldap_open,
/*.directory_close */ mod_ldap_close,
/*.directory_query */ mod_ldap_query,
/*.directory_next */ mod_ldap_next,
/*.directory_next_pair */ mod_ldap_next_pair
};
File diff suppressed because it is too large. Load diff
+127 -114
View File
@@ -98,9 +98,9 @@ typedef struct private_object private_t;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip)
static char *IAXNAMES[] =
@@ -209,9 +209,9 @@ typedef enum {
IAX_QUERY = 2
} iax_io_t;
static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *iax_session,
unsigned int *format, unsigned int *cababilities, unsigned short *samprate,
iax_io_t io)
static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *iax_session,
unsigned int *format, unsigned int *cababilities, unsigned short *samprate,
iax_io_t io)
{
char *dname = NULL;
//int rate = 8000;
@@ -225,15 +225,16 @@ static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *ia
if (globals.codec_string) {
if ((num_codecs = switch_loadable_module_get_codecs_sorted(codecs,
SWITCH_MAX_CODECS,
globals.codec_order,
globals.codec_order_last)) <= 0) {
SWITCH_MAX_CODECS,
globals.codec_order,
globals.codec_order_last)) <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
return SWITCH_STATUS_GENERR;
}
} else
if (((num_codecs =
switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, SWITCH_MAX_CODECS))) <= 0) {
switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs,
SWITCH_MAX_CODECS))) <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
return SWITCH_STATUS_GENERR;
}
@@ -244,7 +245,7 @@ static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *ia
unsigned int codec = iana2ast(imp->ianacode);
if (io == IAX_QUERY && !(codec & local_cap)) {
iax_pref_codec_add(iax_session, codec);
}
}
local_cap |= codec;
}
}
@@ -422,12 +423,13 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_ring(switch_core_session_t *session);
static switch_status_t channel_on_loopback(switch_core_session_t *session);
static switch_status_t channel_on_transmit(switch_core_session_t *session);
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id);
switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
switch_io_flag_t flags, int stream_id);
switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@@ -443,14 +445,14 @@ static void iax_out_cb(const char *s)
}
}
static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
static void tech_init(private_t * tech_pvt, switch_core_session_t *session)
{
tech_pvt->read_frame.data = tech_pvt->databuf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session;
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session;
}
/*
@@ -559,7 +561,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
globals.calls = 0;
}
switch_mutex_unlock(globals.mutex);
return SWITCH_STATUS_SUCCESS;
}
@@ -574,20 +576,20 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
switch(sig) {
case SWITCH_SIG_KILL:
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
//switch_thread_cond_signal(tech_pvt->cond);
break;
case SWITCH_SIG_BREAK:
switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
break;
default:
break;
}
switch (sig) {
case SWITCH_SIG_KILL:
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
//switch_thread_cond_signal(tech_pvt->cond);
break;
case SWITCH_SIG_BREAK:
switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
break;
default:
break;
}
return SWITCH_STATUS_SUCCESS;
}
@@ -641,33 +643,33 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *d
}
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id)
switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL;
switch_time_t started = switch_time_now();
unsigned int elapsed;
switch_byte_t *data;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
tech_pvt->read_frame.flags = SFF_NONE;
*frame = NULL;
tech_pvt->read_frame.flags = SFF_NONE;
*frame = NULL;
while (switch_test_flag(tech_pvt, TFLAG_IO)) {
if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
switch_yield(1000);
continue;
}
if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
switch_yield(1000);
continue;
}
//switch_thread_cond_wait(tech_pvt->cond, tech_pvt->mutex);
if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
switch_clear_flag(tech_pvt, TFLAG_BREAK);
goto cng;
}
switch_clear_flag(tech_pvt, TFLAG_BREAK);
goto cng;
}
if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
return SWITCH_STATUS_FALSE;
@@ -688,12 +690,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
}
if (timeout > -1) {
elapsed = (unsigned int)((switch_time_now() - started) / 1000);
if (elapsed >= (unsigned int)timeout) {
elapsed = (unsigned int) ((switch_time_now() - started) / 1000);
if (elapsed >= (unsigned int) timeout) {
return SWITCH_STATUS_SUCCESS;
}
}
switch_yield(1000);
}
@@ -701,19 +703,19 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_FALSE;
cng:
cng:
data = (switch_byte_t *) tech_pvt->read_frame.data;
data[0] = 65;
data[1] = 0;
tech_pvt->read_frame.datalen = 2;
tech_pvt->read_frame.flags = SFF_CNG;
*frame = &tech_pvt->read_frame;
return SWITCH_STATUS_SUCCESS;
tech_pvt->read_frame.datalen = 2;
tech_pvt->read_frame.flags = SFF_CNG;
*frame = &tech_pvt->read_frame;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
switch_io_flag_t flags, int stream_id)
switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL;
@@ -799,7 +801,8 @@ static const switch_loadable_module_interface_t channel_module_interface = {
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool)
{
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
@@ -812,7 +815,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
switch_core_session_add_stream(*new_session, NULL);
if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
channel = switch_core_session_get_channel(*new_session);
tech_init(tech_pvt, *new_session);
tech_init(tech_pvt, *new_session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(new_session);
@@ -863,7 +866,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
@@ -871,7 +875,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
return SWITCH_STATUS_TERM;
}
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &channel_module_interface;
@@ -943,18 +947,21 @@ static switch_status_t load_config(void)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t tech_media(private_t *tech_pvt, struct iax_event *iaxevent)
static switch_status_t tech_media(private_t * tech_pvt, struct iax_event *iaxevent)
{
unsigned int cap = iax_session_get_capability(iaxevent->session);
unsigned int format = iaxevent->ies.format;
unsigned int cap = iax_session_get_capability(iaxevent->session);
unsigned int format = iaxevent->ies.format;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (!switch_test_flag(tech_pvt, TFLAG_CODEC) &&
(status = iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error %u %u\n", iaxevent->ies.format, iaxevent->ies.capability);
}
return status;
if (!switch_test_flag(tech_pvt, TFLAG_CODEC) &&
(status =
iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate,
IAX_SET)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error %u %u\n", iaxevent->ies.format,
iaxevent->ies.capability);
}
return status;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
@@ -994,7 +1001,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
/* Wait for an event. */
if ((iaxevent = iax_get_event(0)) == NULL) {
int waitlen = 0;
if (globals.calls == 0) {
waitlen = 10000;
} else if (globals.calls < 10) {
@@ -1007,12 +1014,12 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
continue;
} else {
private_t *tech_pvt = NULL;
switch_channel_t *channel = NULL;
switch_channel_t *channel = NULL;
if ((tech_pvt = iax_get_private(iaxevent->session))) {
channel = switch_core_session_get_channel(tech_pvt->session);
}
if ((tech_pvt = iax_get_private(iaxevent->session))) {
channel = switch_core_session_get_channel(tech_pvt->session);
}
if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event %d [%s]!\n",
iaxevent->etype, IAXNAMES[iaxevent->etype]);
@@ -1031,11 +1038,11 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
break;
case IAX_EVENT_ACCEPT:
if (channel && !switch_channel_test_flag(channel, CF_ANSWERED)) {
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
switch_channel_mark_pre_answered(channel);
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
switch_channel_mark_pre_answered(channel);
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Call accepted.\n");
break;
@@ -1052,32 +1059,34 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
case IAX_EVENT_ANSWER:
// the other side answered our call
if (channel) {
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "WTF Mutiple Answer %s?\n", switch_channel_get_name(channel));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Answer %s\n", switch_channel_get_name(channel));
switch_channel_mark_answered(channel);
}
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "WTF Mutiple Answer %s?\n",
switch_channel_get_name(channel));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Answer %s\n",
switch_channel_get_name(channel));
switch_channel_mark_answered(channel);
}
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
break;
case IAX_EVENT_CONNECT:
// incoming call detected
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
"Incoming call connected %s, %s, %s %u/%u\n",
iaxevent->ies.called_number,
iaxevent->ies.calling_number,
iaxevent->ies.calling_name, iaxevent->ies.format, iaxevent->ies.capability);
"Incoming call connected %s, %s, %s %u/%u\n",
iaxevent->ies.called_number,
iaxevent->ies.calling_number,
iaxevent->ies.calling_name, iaxevent->ies.format, iaxevent->ies.capability);
if (iaxevent) {
switch_core_session_t *session;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Inbound Channel %s!\n",
iaxevent->ies.calling_name);
iaxevent->ies.calling_name);
if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
private_t *tech_pvt;
switch_channel_t *channel;
@@ -1085,7 +1094,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
switch_core_session_add_stream(session, NULL);
if ((tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t))) != 0) {
channel = switch_core_session_get_channel(session);
tech_init(tech_pvt, session);
tech_init(tech_pvt, session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(&session);
@@ -1100,9 +1109,9 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
iaxevent->ies.calling_number,
iax_get_peer_ip(iaxevent->session),
iaxevent->ies.calling_ani,
NULL,
NULL,
(char *)modname,
NULL,
(char *) modname,
iaxevent->ies.called_context,
iaxevent->ies.called_number)) != 0) {
char name[128];
@@ -1141,11 +1150,15 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
switch_mutex_unlock(tech_pvt->flag_mutex);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
//switch_thread_cond_signal(tech_pvt->cond);
iaxevent->session = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n",
switch_channel_get_name(channel));
switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel,
iaxevent->etype ==
IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING :
SWITCH_CAUSE_FACILITY_REJECTED);
//switch_thread_cond_signal(tech_pvt->cond);
iaxevent->session = NULL;
}
break;
case IAX_EVENT_CNG:
@@ -1156,7 +1169,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen) != 0) {
if (channel && switch_channel_get_state(channel) <= CS_HANGUP) {
int bytes, frames;
if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "audio with no codec yet!\n");
break;
@@ -1183,18 +1196,18 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
break;
case IAX_EVENT_DTMF:
if (channel) {
char str[2] = { (char)iaxevent->subclass };
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s DTMF %s\n", str,
switch_channel_get_name(channel));
}
switch_channel_queue_dtmf(channel, str);
char str[2] = { (char) iaxevent->subclass };
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s DTMF %s\n", str,
switch_channel_get_name(channel));
}
switch_channel_queue_dtmf(channel, str);
}
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Don't know what to do with IAX event %d.\n",
iaxevent->etype);
iaxevent->etype);
break;
}
@@ -1216,7 +1229,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
running = -1;
if (globals.fd) {
/* Die Mutha $%#$@% Die Mutha $#%#$^ Die*/
/* Die Mutha $%#$@% Die Mutha $#%#$^ Die */
shutdown(globals.fd, 2);
}
iax_shutdown();
File diff suppressed because it is too large. Load diff
+102 -111
View File
@@ -81,17 +81,17 @@
# define PaUtil_WriteMemoryBarrier()
#else
#if defined(__APPLE__) //|| defined(__FreeBSD__)
#if defined(__APPLE__) //|| defined(__FreeBSD__)
# include <libkern/OSAtomic.h>
/* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
full memory barriers, so the three types of barriers are the same. */
/* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
full memory barriers, so the three types of barriers are the same. */
# define PaUtil_FullMemoryBarrier() OSMemoryBarrier()
# define PaUtil_ReadMemoryBarrier() OSMemoryBarrier()
# define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
#elif defined(__GNUC__)
/* GCC understands volatile asm and "memory" to mean it
* should not reorder memory read/writes */
/* GCC understands volatile asm and "memory" to mean it
* should not reorder memory read/writes */
# if defined( __PPC__ )
# define PaUtil_FullMemoryBarrier() __asm__ volatile("sync":::"memory")
# define PaUtil_ReadMemoryBarrier() __asm__ volatile("sync":::"memory")
@@ -123,37 +123,39 @@
* Initialize FIFO.
* numBytes must be power of 2, returns -1 if not.
*/
long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr )
long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr)
{
if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */
rbuf->bufferSize = numBytes;
rbuf->buffer = (char *)dataPtr;
PaUtil_FlushRingBuffer( rbuf );
rbuf->bigMask = (numBytes*2)-1;
rbuf->smallMask = (numBytes)-1;
return 0;
if (((numBytes - 1) & numBytes) != 0)
return -1; /* Not Power of two. */
rbuf->bufferSize = numBytes;
rbuf->buffer = (char *) dataPtr;
PaUtil_FlushRingBuffer(rbuf);
rbuf->bigMask = (numBytes * 2) - 1;
rbuf->smallMask = (numBytes) - 1;
return 0;
}
/***************************************************************************
** Return number of bytes available for reading. */
long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf )
long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf)
{
PaUtil_ReadMemoryBarrier();
return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
PaUtil_ReadMemoryBarrier();
return ((rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask);
}
/***************************************************************************
** Return number of bytes available for writing. */
long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf )
long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf)
{
/* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
return ( rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
/* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
return (rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
}
/***************************************************************************
** Clear buffer. Should only be called when buffer is NOT being read. */
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf)
{
rbuf->writeIndex = rbuf->readIndex = 0;
rbuf->writeIndex = rbuf->readIndex = 0;
}
/***************************************************************************
@@ -162,42 +164,39 @@ void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or numBytes, whichever is smaller.
*/
long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 )
long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
{
long index;
long available = PaUtil_GetRingBufferWriteAvailable( rbuf );
if( numBytes > available ) numBytes = available;
/* Check to see if write is not contiguous. */
index = rbuf->writeIndex & rbuf->smallMask;
if( (index + numBytes) > rbuf->bufferSize )
{
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
long index;
long available = PaUtil_GetRingBufferWriteAvailable(rbuf);
if (numBytes > available)
numBytes = available;
/* Check to see if write is not contiguous. */
index = rbuf->writeIndex & rbuf->smallMask;
if ((index + numBytes) > rbuf->bufferSize) {
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
} else {
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
}
/***************************************************************************
*/
long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes)
{
/* we need to ensure that previous writes are seen before we update the write index */
PaUtil_WriteMemoryBarrier();
return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
/* we need to ensure that previous writes are seen before we update the write index */
PaUtil_WriteMemoryBarrier();
return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
}
/***************************************************************************
@@ -206,81 +205,73 @@ long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or numBytes, whichever is smaller.
*/
long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 )
long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
{
long index;
long available = PaUtil_GetRingBufferReadAvailable( rbuf );
if( numBytes > available ) numBytes = available;
/* Check to see if read is not contiguous. */
index = rbuf->readIndex & rbuf->smallMask;
if( (index + numBytes) > rbuf->bufferSize )
{
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
long index;
long available = PaUtil_GetRingBufferReadAvailable(rbuf);
if (numBytes > available)
numBytes = available;
/* Check to see if read is not contiguous. */
index = rbuf->readIndex & rbuf->smallMask;
if ((index + numBytes) > rbuf->bufferSize) {
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
} else {
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
}
/***************************************************************************
*/
long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes )
long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes)
{
/* we need to ensure that previous writes are always seen before updating the index. */
PaUtil_WriteMemoryBarrier();
return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
/* we need to ensure that previous writes are always seen before updating the index. */
PaUtil_WriteMemoryBarrier();
return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
}
/***************************************************************************
** Return bytes written. */
long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes )
long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes)
{
long size1, size2, numWritten;
void *data1, *data2;
numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
if( size2 > 0 )
{
long size1, size2, numWritten;
void *data1, *data2;
numWritten = PaUtil_GetRingBufferWriteRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
if (size2 > 0) {
memcpy( data1, data, size1 );
data = ((char *)data) + size1;
memcpy( data2, data, size2 );
}
else
{
memcpy( data1, data, size1 );
}
PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
return numWritten;
memcpy(data1, data, size1);
data = ((char *) data) + size1;
memcpy(data2, data, size2);
} else {
memcpy(data1, data, size1);
}
PaUtil_AdvanceRingBufferWriteIndex(rbuf, numWritten);
return numWritten;
}
/***************************************************************************
** Return bytes read. */
long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes )
long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes)
{
long size1, size2, numRead;
void *data1, *data2;
numRead = PaUtil_GetRingBufferReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
if( size2 > 0 )
{
memcpy( data, data1, size1 );
data = ((char *)data) + size1;
memcpy( data, data2, size2 );
}
else
{
memcpy( data, data1, size1 );
}
PaUtil_AdvanceRingBufferReadIndex( rbuf, numRead );
return numRead;
long size1, size2, numRead;
void *data1, *data2;
numRead = PaUtil_GetRingBufferReadRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
if (size2 > 0) {
memcpy(data, data1, size1);
data = ((char *) data) + size1;
memcpy(data, data2, size2);
} else {
memcpy(data, data1, size1);
}
PaUtil_AdvanceRingBufferReadIndex(rbuf, numRead);
return numRead;
}
+24 -28
View File
@@ -51,19 +51,17 @@
*/
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
extern "C" {
#endif /* __cplusplus */
typedef struct PaUtilRingBuffer
{
long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */
long writeIndex; /* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */
long readIndex; /* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */
long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */
long smallMask; /* Used for fitting indices to buffer. */
char *buffer;
}PaUtilRingBuffer;
typedef struct PaUtilRingBuffer {
long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */
long writeIndex; /* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */
long readIndex; /* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */
long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */
long smallMask; /* Used for fitting indices to buffer. */
char *buffer;
} PaUtilRingBuffer;
/** Initialize Ring Buffer.
@@ -76,13 +74,13 @@ typedef struct PaUtilRingBuffer
@return -1 if numBytes is not a power of 2, otherwise 0.
*/
long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr );
long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr);
/** Clear buffer. Should only be called when buffer is NOT being read.
@param rbuf The ring buffer.
*/
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf );
void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf);
/** Retrieve the number of bytes available in the ring buffer for writing.
@@ -90,7 +88,7 @@ void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf );
@return The number of bytes available for writing.
*/
long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf );
long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf);
/** Retrieve the number of bytes available in the ring buffer for reading.
@@ -98,7 +96,7 @@ long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf );
@return The number of bytes available for reading.
*/
long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf );
long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf);
/** Write data to the ring buffer.
@@ -110,7 +108,7 @@ long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf );
@return The number of bytes written.
*/
long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes );
long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes);
/** Read data from the ring buffer.
@@ -122,7 +120,7 @@ long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numB
@return The number of bytes read.
*/
long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes );
long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes);
/** Get address of region(s) to which we can write data.
@@ -144,9 +142,8 @@ long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes );
@return The room available to be written or numBytes, whichever is smaller.
*/
long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 );
long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2);
/** Advance the write index to the next location to be written.
@@ -156,7 +153,7 @@ long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
@return The new position.
*/
long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes );
long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes);
/** Get address of region(s) from which we can write data.
@@ -178,9 +175,8 @@ long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
@return The number of bytes available for reading.
*/
long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 );
long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2);
/** Advance the read index to the next location to be read.
@@ -190,9 +186,9 @@ long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
@return The new position.
*/
long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes );
long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* PA_RINGBUFFER_H */
#endif /* __cplusplus */
#endif /* PA_RINGBUFFER_H */
+145 -150
View File
@@ -59,13 +59,12 @@
/******** Prototypes ****************************************************/
/************************************************************************/
static int blockingIOCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData );
static PaError PABLIO_InitFIFO( PaUtilRingBuffer *rbuf, long numFrames, long bytesPerFrame );
static PaError PABLIO_TermFIFO( PaUtilRingBuffer *rbuf );
static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo * timeInfo,
PaStreamCallbackFlags statusFlags, void *userData);
static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames, long bytesPerFrame);
static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf);
/************************************************************************/
/******** Functions *****************************************************/
@@ -74,122 +73,120 @@ static PaError PABLIO_TermFIFO( PaUtilRingBuffer *rbuf );
/* Called from PortAudio.
* Read and write data only if there is room in FIFOs.
*/
static int blockingIOCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo * timeInfo,
PaStreamCallbackFlags statusFlags, void *userData)
{
PABLIO_Stream *data = (PABLIO_Stream*)userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
PABLIO_Stream *data = (PABLIO_Stream *) userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
/* This may get called with NULL inputBuffer during initial setup. */
if( inputBuffer != NULL )
{
PaUtil_WriteRingBuffer( &data->inFIFO, inputBuffer, numBytes );
}
if( outputBuffer != NULL )
{
int i;
int numRead = PaUtil_ReadRingBuffer( &data->outFIFO, outputBuffer, numBytes );
/* Zero out remainder of buffer if we run out of data. */
for( i=numRead; i<numBytes; i++ )
{
((char *)outputBuffer)[i] = 0;
}
}
/* This may get called with NULL inputBuffer during initial setup. */
if (inputBuffer != NULL) {
PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes);
}
if (outputBuffer != NULL) {
int i;
int numRead = PaUtil_ReadRingBuffer(&data->outFIFO, outputBuffer, numBytes);
/* Zero out remainder of buffer if we run out of data. */
for (i = numRead; i < numBytes; i++) {
((char *) outputBuffer)[i] = 0;
}
}
return 0;
return 0;
}
/* Allocate buffer. */
static PaError PABLIO_InitFIFO( PaUtilRingBuffer *rbuf, long numFrames, long bytesPerFrame )
static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames, long bytesPerFrame)
{
long numBytes = numFrames * bytesPerFrame;
char *buffer = (char *) malloc( numBytes );
if( buffer == NULL ) return paInsufficientMemory;
memset( buffer, 0, numBytes );
return (PaError) PaUtil_InitializeRingBuffer( rbuf, numBytes, buffer );
long numBytes = numFrames * bytesPerFrame;
char *buffer = (char *) malloc(numBytes);
if (buffer == NULL)
return paInsufficientMemory;
memset(buffer, 0, numBytes);
return (PaError) PaUtil_InitializeRingBuffer(rbuf, numBytes, buffer);
}
/* Free buffer. */
static PaError PABLIO_TermFIFO( PaUtilRingBuffer *rbuf )
static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf)
{
if( rbuf->buffer ) free( rbuf->buffer );
rbuf->buffer = NULL;
return paNoError;
if (rbuf->buffer)
free(rbuf->buffer);
rbuf->buffer = NULL;
return paNoError;
}
/************************************************************
* Write data to ring buffer.
* Will not return until all the data has been written.
*/
long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
{
long bytesWritten;
char *p = (char *) data;
long numBytes = aStream->bytesPerFrame * numFrames;
while( numBytes > 0)
{
bytesWritten = PaUtil_WriteRingBuffer( &aStream->outFIFO, p, numBytes );
numBytes -= bytesWritten;
p += bytesWritten;
if( numBytes > 0) Pa_Sleep(10);
}
return numFrames;
long bytesWritten;
char *p = (char *) data;
long numBytes = aStream->bytesPerFrame * numFrames;
while (numBytes > 0) {
bytesWritten = PaUtil_WriteRingBuffer(&aStream->outFIFO, p, numBytes);
numBytes -= bytesWritten;
p += bytesWritten;
if (numBytes > 0)
Pa_Sleep(10);
}
return numFrames;
}
/************************************************************
* Read data from ring buffer.
* Will not return until all the data has been read.
*/
long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
{
long bytesRead;
char *p = (char *) data;
long numBytes = aStream->bytesPerFrame * numFrames;
long bytesRead;
char *p = (char *) data;
long numBytes = aStream->bytesPerFrame * numFrames;
while( numBytes > 0)
{
bytesRead = PaUtil_ReadRingBuffer( &aStream->inFIFO, p, numBytes );
numBytes -= bytesRead;
p += bytesRead;
if( numBytes > 0) Pa_Sleep(10);
}
return numFrames;
while (numBytes > 0) {
bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, numBytes);
numBytes -= bytesRead;
p += bytesRead;
if (numBytes > 0)
Pa_Sleep(10);
}
return numFrames;
}
/************************************************************
* Return the number of frames that could be written to the stream without
* having to wait.
*/
long GetAudioStreamWriteable( PABLIO_Stream *aStream )
long GetAudioStreamWriteable(PABLIO_Stream * aStream)
{
int bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
return bytesEmpty / aStream->bytesPerFrame;
int bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
return bytesEmpty / aStream->bytesPerFrame;
}
/************************************************************
* Return the number of frames that are available to be read from the
* stream without having to wait.
*/
long GetAudioStreamReadable( PABLIO_Stream *aStream )
long GetAudioStreamReadable(PABLIO_Stream * aStream)
{
int bytesFull = PaUtil_GetRingBufferReadAvailable( &aStream->inFIFO );
return bytesFull / aStream->bytesPerFrame;
int bytesFull = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO);
return bytesFull / aStream->bytesPerFrame;
}
/************************************************************/
static unsigned long RoundUpToNextPowerOf2( unsigned long n )
static unsigned long RoundUpToNextPowerOf2(unsigned long n)
{
long numBits = 0;
if( ((n-1) & n) == 0) return n; /* Already Power of two. */
while( n > 0 )
{
n= n>>1;
numBits++;
}
return (1<<numBits);
long numBits = 0;
if (((n - 1) & n) == 0)
return n; /* Already Power of two. */
while (n > 0) {
n = n >> 1;
numBits++;
}
return (1 << numBits);
}
/************************************************************
@@ -197,27 +194,27 @@ static unsigned long RoundUpToNextPowerOf2( unsigned long n )
* Allocates PABLIO_Stream structure.
*
*/
PaError OpenAudioStream( PABLIO_Stream **rwblPtr,
const PaStreamParameters *inputParameters,
const PaStreamParameters *outputParameters,
double sampleRate,
PaStreamFlags streamFlags)
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters * inputParameters,
const PaStreamParameters * outputParameters, double sampleRate, PaStreamFlags streamFlags)
{
long bytesPerSample;
PaError err;
PABLIO_Stream *aStream;
long numFrames;
long bytesPerSample;
PaError err;
PABLIO_Stream *aStream;
long numFrames;
long numBytes;
int channels = 1;
/* Allocate PABLIO_Stream structure for caller. */
aStream = (PABLIO_Stream *) malloc( sizeof(PABLIO_Stream) );
if( aStream == NULL ) return paInsufficientMemory;
memset( aStream, 0, sizeof(PABLIO_Stream) );
/* Allocate PABLIO_Stream structure for caller. */
aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
if (aStream == NULL)
return paInsufficientMemory;
memset(aStream, 0, sizeof(PABLIO_Stream));
/* Initialize PortAudio */
err = Pa_Initialize();
if( err != paNoError ) goto error;
/* Initialize PortAudio */
err = Pa_Initialize();
if (err != paNoError)
goto error;
if (inputParameters) {
channels = inputParameters->channelCount;
@@ -225,81 +222,79 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr,
channels = outputParameters->channelCount;
}
numFrames = 4 * FRAMES_PER_BUFFER;
numFrames = RoundUpToNextPowerOf2( numFrames );
numFrames = 4 * FRAMES_PER_BUFFER;
numFrames = RoundUpToNextPowerOf2(numFrames);
bytesPerSample = 2;
aStream->samplesPerFrame = channels;
aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;
aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;
/* Initialize Ring Buffers */
/* Initialize Ring Buffers */
if (inputParameters) {
err = PABLIO_InitFIFO( &aStream->inFIFO, numFrames, aStream->bytesPerFrame );
if( err != paNoError ) goto error;
err = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame);
if (err != paNoError)
goto error;
}
if (outputParameters) {
err = PABLIO_InitFIFO( &aStream->outFIFO, numFrames, aStream->bytesPerFrame );
if( err != paNoError ) goto error;
err = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame);
if (err != paNoError)
goto error;
}
/* Make Write FIFO appear full initially. */
numBytes = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
PaUtil_AdvanceRingBufferWriteIndex( &aStream->outFIFO, numBytes );
numBytes = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
PaUtil_AdvanceRingBufferWriteIndex(&aStream->outFIFO, numBytes);
/* Open a PortAudio stream that we will use to communicate with the underlying
* audio drivers. */
err = Pa_OpenStream(
&aStream->stream,
inputParameters,
outputParameters,
sampleRate,
FRAMES_PER_BUFFER,
streamFlags,
blockingIOCallback,
aStream );
if( err != paNoError ) goto error;
err = Pa_StartStream( aStream->stream );
if( err != paNoError ) goto error;
*rwblPtr = aStream;
return paNoError;
/* Open a PortAudio stream that we will use to communicate with the underlying
* audio drivers. */
err = Pa_OpenStream(&aStream->stream,
inputParameters,
outputParameters, sampleRate, FRAMES_PER_BUFFER, streamFlags, blockingIOCallback, aStream);
if (err != paNoError)
goto error;
error:
CloseAudioStream( aStream );
*rwblPtr = NULL;
return err;
err = Pa_StartStream(aStream->stream);
if (err != paNoError)
goto error;
*rwblPtr = aStream;
return paNoError;
error:
CloseAudioStream(aStream);
*rwblPtr = NULL;
return err;
}
/************************************************************/
PaError CloseAudioStream( PABLIO_Stream *aStream )
PaError CloseAudioStream(PABLIO_Stream * aStream)
{
PaError err;
int bytesEmpty;
int byteSize = aStream->outFIFO.bufferSize;
PaError err;
int bytesEmpty;
int byteSize = aStream->outFIFO.bufferSize;
/* If we are writing data, make sure we play everything written. */
if( byteSize > 0 )
{
bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
while( bytesEmpty < byteSize )
{
Pa_Sleep( 10 );
bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
}
}
/* If we are writing data, make sure we play everything written. */
if (byteSize > 0) {
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
while (bytesEmpty < byteSize) {
Pa_Sleep(10);
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
}
}
err = Pa_StopStream( aStream->stream );
if( err != paNoError ) goto error;
err = Pa_CloseStream( aStream->stream );
if( err != paNoError ) goto error;
Pa_Terminate();
err = Pa_StopStream(aStream->stream);
if (err != paNoError)
goto error;
err = Pa_CloseStream(aStream->stream);
if (err != paNoError)
goto error;
Pa_Terminate();
error:
PABLIO_TermFIFO( &aStream->inFIFO );
PABLIO_TermFIFO( &aStream->outFIFO );
free( aStream );
return err;
error:
PABLIO_TermFIFO(&aStream->inFIFO);
PABLIO_TermFIFO(&aStream->outFIFO);
free(aStream);
return err;
}
+20 -24
View File
@@ -2,9 +2,8 @@
#define _PABLIO_H
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
extern "C" {
#endif /* __cplusplus */
/*
* $Id: pablio.h 1083 2006-08-23 07:30:49Z rossb $
@@ -57,15 +56,13 @@ extern "C"
#include <string.h>
typedef struct
{
PaUtilRingBuffer inFIFO;
PaUtilRingBuffer outFIFO;
PaStream *stream;
int bytesPerFrame;
int samplesPerFrame;
}
PABLIO_Stream;
typedef struct {
PaUtilRingBuffer inFIFO;
PaUtilRingBuffer outFIFO;
PaStream *stream;
int bytesPerFrame;
int samplesPerFrame;
} PABLIO_Stream;
/* Values for flags for OpenAudioStream(). */
#define PABLIO_READ (1<<0)
@@ -78,25 +75,25 @@ PABLIO_Stream;
* Write data to ring buffer.
* Will not return until all the data has been written.
*/
long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames );
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
/************************************************************
* Read data from ring buffer.
* Will not return until all the data has been read.
*/
long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames );
long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
/************************************************************
* Return the number of frames that could be written to the stream without
* having to wait.
*/
long GetAudioStreamWriteable( PABLIO_Stream *aStream );
long GetAudioStreamWriteable(PABLIO_Stream * aStream);
/************************************************************
* Return the number of frames that are available to be read from the
* stream without having to wait.
*/
long GetAudioStreamReadable( PABLIO_Stream *aStream );
long GetAudioStreamReadable(PABLIO_Stream * aStream);
/************************************************************
* Opens a PortAudio stream with default characteristics.
@@ -106,15 +103,14 @@ long GetAudioStreamReadable( PABLIO_Stream *aStream );
* PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,
* and either PABLIO_MONO or PABLIO_STEREO
*/
PaError OpenAudioStream( PABLIO_Stream **rwblPtr,
const PaStreamParameters *inputParameters,
const PaStreamParameters *outputParameters,
double sampleRate,
PaStreamCallbackFlags statusFlags);
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters * inputParameters,
const PaStreamParameters * outputParameters,
double sampleRate, PaStreamCallbackFlags statusFlags);
PaError CloseAudioStream( PABLIO_Stream *aStream );
PaError CloseAudioStream(PABLIO_Stream * aStream);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _PABLIO_H */
#endif /* __cplusplus */
#endif /* _PABLIO_H */
File diff suppressed because it is too large. Load diff
+166 -205
View File
@@ -50,137 +50,110 @@ extern "C" {
#ifndef __inline__
#define __inline__ __inline
#endif
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef unsigned __int16 uint16_t;
#endif
#if defined(__i386__)
/*! \brief Find the bit position of the highest set bit in a word
\param bits The word to be searched
\return The bit number of the highest set bit, or -1 if the word is zero. */
static __inline__ int top_bit(unsigned int bits)
{
int res;
static __inline__ int top_bit(unsigned int bits) {
int res;
__asm__ __volatile__(" movl $-1,%%edx;\n"
" bsrl %%eax,%%edx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
__asm__ __volatile__(" movl $-1,%%edx;\n" " bsrl %%eax,%%edx;\n":"=d"(res)
:"a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*//*! \brief Find the bit position of the lowest set bit in a word
\param bits The word to be searched
\return The bit number of the lowest set bit, or -1 if the word is zero. */
static __inline__ int bottom_bit(unsigned int bits) {
int res;
/*! \brief Find the bit position of the lowest set bit in a word
\param bits The word to be searched
\return The bit number of the lowest set bit, or -1 if the word is zero. */
static __inline__ int bottom_bit(unsigned int bits)
{
int res;
__asm__ __volatile__(" movl $-1,%%edx;\n"
" bsfl %%eax,%%edx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
__asm__ __volatile__(" movl $-1,%%edx;\n" " bsfl %%eax,%%edx;\n":"=d"(res)
:"a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
#elif defined(__x86_64__)
static __inline__ int top_bit(unsigned int bits)
{
int res;
static __inline__ int top_bit(unsigned int bits) {
int res;
__asm__ __volatile__(" movq $-1,%%rdx;\n"
" bsrq %%rax,%%rdx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
__asm__ __volatile__(" movq $-1,%%rdx;\n" " bsrq %%rax,%%rdx;\n":"=d"(res)
:"a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
static __inline__ int bottom_bit(unsigned int bits) {
int res;
static __inline__ int bottom_bit(unsigned int bits)
{
int res;
__asm__ __volatile__(" movq $-1,%%rdx;\n"
" bsfq %%rax,%%rdx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
__asm__ __volatile__(" movq $-1,%%rdx;\n" " bsfq %%rax,%%rdx;\n":"=d"(res)
:"a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
#else
static __inline__ int top_bit(unsigned int bits)
{
int i;
if (bits == 0)
return -1;
i = 0;
if (bits & 0xFFFF0000)
{
bits &= 0xFFFF0000;
i += 16;
}
if (bits & 0xFF00FF00)
{
bits &= 0xFF00FF00;
i += 8;
}
if (bits & 0xF0F0F0F0)
{
bits &= 0xF0F0F0F0;
i += 4;
}
if (bits & 0xCCCCCCCC)
{
bits &= 0xCCCCCCCC;
i += 2;
}
if (bits & 0xAAAAAAAA)
{
bits &= 0xAAAAAAAA;
i += 1;
}
return i;
}
static __inline__ int top_bit(unsigned int bits) {
int i;
if (bits == 0)
return -1;
i = 0;
if (bits & 0xFFFF0000) {
bits &= 0xFFFF0000;
i += 16;
}
if (bits & 0xFF00FF00) {
bits &= 0xFF00FF00;
i += 8;
}
if (bits & 0xF0F0F0F0) {
bits &= 0xF0F0F0F0;
i += 4;
}
if (bits & 0xCCCCCCCC) {
bits &= 0xCCCCCCCC;
i += 2;
}
if (bits & 0xAAAAAAAA) {
bits &= 0xAAAAAAAA;
i += 1;
}
return i;
}
/*- End of function --------------------------------------------------------*/
static __inline__ int bottom_bit(unsigned int bits)
{
int i;
if (bits == 0)
return -1;
i = 32;
if (bits & 0x0000FFFF)
{
bits &= 0x0000FFFF;
i -= 16;
}
if (bits & 0x00FF00FF)
{
bits &= 0x00FF00FF;
i -= 8;
}
if (bits & 0x0F0F0F0F)
{
bits &= 0x0F0F0F0F;
i -= 4;
}
if (bits & 0x33333333)
{
bits &= 0x33333333;
i -= 2;
}
if (bits & 0x55555555)
{
bits &= 0x55555555;
i -= 1;
}
return i;
}
static __inline__ int bottom_bit(unsigned int bits) {
int i;
if (bits == 0)
return -1;
i = 32;
if (bits & 0x0000FFFF) {
bits &= 0x0000FFFF;
i -= 16;
}
if (bits & 0x00FF00FF) {
bits &= 0x00FF00FF;
i -= 8;
}
if (bits & 0x0F0F0F0F) {
bits &= 0x0F0F0F0F;
i -= 4;
}
if (bits & 0x33333333) {
bits &= 0x33333333;
i -= 2;
}
if (bits & 0x55555555) {
bits &= 0x55555555;
i -= 1;
}
return i;
}
/*- End of function --------------------------------------------------------*/
#endif
@@ -194,7 +167,7 @@ static __inline__ int bottom_bit(unsigned int bits)
* segment, but a little inline assembly can fix that on an i386, x86_64 and
* many other modern processors.
*/
/*
* Mu-law is basically as follows:
*
@@ -222,66 +195,61 @@ static __inline__ int bottom_bit(unsigned int bits)
*/
//#define ULAW_ZEROTRAP /* turn on the trap as per the MIL-STD */
#define ULAW_BIAS 0x84 /* Bias for linear code. */
#define ULAW_BIAS 0x84 /* Bias for linear code. */
/*! \brief Encode a linear sample to u-law
\param linear The sample to encode.
\return The u-law value.
*/
static __inline__ uint8_t linear_to_ulaw(int linear)
{
uint8_t u_val;
int mask;
int seg;
static __inline__ uint8_t linear_to_ulaw(int linear) {
uint8_t u_val;
int mask;
int seg;
/* Get the sign and the magnitude of the value. */
if (linear < 0)
{
linear = ULAW_BIAS - linear;
mask = 0x7F;
}
else
{
linear = ULAW_BIAS + linear;
mask = 0xFF;
}
/* Get the sign and the magnitude of the value. */
if (linear < 0) {
linear = ULAW_BIAS - linear;
mask = 0x7F;
} else {
linear = ULAW_BIAS + linear;
mask = 0xFF;
}
seg = top_bit(linear | 0xFF) - 7;
seg = top_bit(linear | 0xFF) - 7;
/*
* Combine the sign, segment, quantization bits,
* and complement the code word.
*/
if (seg >= 8)
u_val = (uint8_t) (0x7F ^ mask);
else
u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
/*
* Combine the sign, segment, quantization bits,
* and complement the code word.
*/
if (seg >= 8)
u_val = (uint8_t) (0x7F ^ mask);
else
u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
#ifdef ULAW_ZEROTRAP
/* Optional ITU trap */
if (u_val == 0)
u_val = 0x02;
/* Optional ITU trap */
if (u_val == 0)
u_val = 0x02;
#endif
return u_val;
}
return u_val;
}
/*- End of function --------------------------------------------------------*/
/*! \brief Decode an u-law sample to a linear value.
\param ulaw The u-law sample to decode.
\return The linear value.
*/
static __inline__ int16_t ulaw_to_linear(uint8_t ulaw)
{
int t;
/* Complement to obtain normal u-law value. */
ulaw = ~ulaw;
/*
* Extract and bias the quantization bits. Then
* shift up by the segment number and subtract out the bias.
*/
t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
}
static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) {
int t;
/* Complement to obtain normal u-law value. */
ulaw = ~ulaw;
/*
* Extract and bias the quantization bits. Then
* shift up by the segment number and subtract out the bias.
*/
t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
}
/*- End of function --------------------------------------------------------*/
/*
@@ -308,71 +276,64 @@ static __inline__ int16_t ulaw_to_linear(uint8_t ulaw)
\param linear The sample to encode.
\return The A-law value.
*/
static __inline__ uint8_t linear_to_alaw(int linear)
{
int mask;
int seg;
if (linear >= 0)
{
/* Sign (bit 7) bit = 1 */
mask = ALAW_AMI_MASK | 0x80;
}
else
{
/* Sign (bit 7) bit = 0 */
mask = ALAW_AMI_MASK;
linear = -linear - 8;
}
static __inline__ uint8_t linear_to_alaw(int linear) {
int mask;
int seg;
/* Convert the scaled magnitude to segment number. */
seg = top_bit(linear | 0xFF) - 7;
if (seg >= 8)
{
if (linear >= 0)
{
/* Out of range. Return maximum value. */
return (uint8_t) (0x7F ^ mask);
}
/* We must be just a tiny step below zero */
return (uint8_t) (0x00 ^ mask);
}
/* Combine the sign, segment, and quantization bits. */
return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
}
if (linear >= 0) {
/* Sign (bit 7) bit = 1 */
mask = ALAW_AMI_MASK | 0x80;
} else {
/* Sign (bit 7) bit = 0 */
mask = ALAW_AMI_MASK;
linear = -linear - 8;
}
/* Convert the scaled magnitude to segment number. */
seg = top_bit(linear | 0xFF) - 7;
if (seg >= 8) {
if (linear >= 0) {
/* Out of range. Return maximum value. */
return (uint8_t) (0x7F ^ mask);
}
/* We must be just a tiny step below zero */
return (uint8_t) (0x00 ^ mask);
}
/* Combine the sign, segment, and quantization bits. */
return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
}
/*- End of function --------------------------------------------------------*/
/*! \brief Decode an A-law sample to a linear value.
\param alaw The A-law sample to decode.
\return The linear value.
*/
static __inline__ int16_t alaw_to_linear(uint8_t alaw)
{
int i;
int seg;
static __inline__ int16_t alaw_to_linear(uint8_t alaw) {
int i;
int seg;
alaw ^= ALAW_AMI_MASK;
i = ((alaw & 0x0F) << 4);
seg = (((int) alaw & 0x70) >> 4);
if (seg)
i = (i + 0x108) << (seg - 1);
else
i += 8;
return (int16_t) ((alaw & 0x80) ? i : -i);
}
alaw ^= ALAW_AMI_MASK;
i = ((alaw & 0x0F) << 4);
seg = (((int) alaw & 0x70) >> 4);
if (seg)
i = (i + 0x108) << (seg - 1);
else
i += 8;
return (int16_t) ((alaw & 0x80) ? i : -i);
}
/*- End of function --------------------------------------------------------*/
/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711.
\param alaw The A-law sample to transcode.
\return The best matching u-law value.
*/
uint8_t alaw_to_ulaw(uint8_t alaw);
uint8_t alaw_to_ulaw(uint8_t alaw);
/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711.
\param alaw The u-law sample to transcode.
\return The best matching A-law value.
*/
uint8_t ulaw_to_alaw(uint8_t ulaw);
uint8_t ulaw_to_alaw(uint8_t ulaw);
#ifdef __cplusplus
}
File diff suppressed because it is too large. Load diff
@@ -34,7 +34,7 @@ typedef unsigned __int32 u_int32_t;
#ifdef WANPIPE_TDM_API
#include <wanpipe_tdm_api.h> //for TDMV API
#endif
#include <sang_status_defines.h>//return codes
#include <sang_status_defines.h> //return codes
#include <sang_api.h> //for IOCTL codes
#include <sdla_te1_pmc.h> //RBS definitions
#include <sdla_te1.h> //TE1 macros
@@ -94,7 +94,7 @@ sng_fd_t sangoma_create_socket_by_name(char *device, char *card);
/* Open Span/Chan devices
* open_tdmapi_span_chan: open device based on span chan values
* sangoma_open_tdmapi_span: open first available device on span
*/
*/
sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan);
sng_fd_t sangoma_open_tdmapi_span(int span);
@@ -104,67 +104,65 @@ sng_fd_t sangoma_open_tdmapi_span(int span);
/* Device Rx/Tx functions
* writemsg_tdm: tx header + data from separate buffers
* readmsg_tdm: rx header + data to separate buffers
*/
int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen,
void *databuf, unsigned short datalen, int flag);
int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen,
void *databuf, int datalen, int flag);
*/
int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen, int flag);
int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen, int flag);
#define sangoma_readmsg_socket sangoma_readmsg_tdm
#define sangoma_sendmsg_socket sangoma_writemsg_tdm
#ifdef WANPIPE_TDM_API
void sangoma_socket_close(sng_fd_t *sp);
void sangoma_socket_close(sng_fd_t * sp);
int sangoma_socket_waitfor(sng_fd_t fd, int timeout, int flags);
/* Get Full TDM API configuration per chan */
int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Get/Set TDM Codec per chan */
int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int codec);
int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int codec);
int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Get/Set USR Tx/Rx Period in milliseconds */
int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int period);
int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int period);
int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Get user MTU/MRU values in bytes */
int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Not supported yet */
int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int power);
int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int power);
int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Flush buffers from current channel */
int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int poll_in_sec);
int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int poll_in_sec);
int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, unsigned char rbs);
int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, unsigned char rbs);
int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* DTMF Detection on Octasic chip */
int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* DTMF Detection on A200 (SLIC) chip */
int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* On/Off hook events on A200 (Analog) card */
int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
#ifndef LIBSANGOMA_GET_HWCODING
#define LIBSANGOMA_GET_HWCODING 1
#endif
int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t * tdm_api);
#endif /* WANPIPE_TDM_API */
#endif /* WANPIPE_TDM_API */
#endif
@@ -23,20 +23,21 @@
static __inline int gettimeofday(struct timeval *tp, void *nothing)
{
#ifdef WITHOUT_MM_LIB
SYSTEMTIME st;
time_t tt;
struct tm tmtm;
/* mktime converts local to UTC */
GetLocalTime (&st);
tmtm.tm_sec = st.wSecond;
tmtm.tm_min = st.wMinute;
tmtm.tm_hour = st.wHour;
tmtm.tm_mday = st.wDay;
tmtm.tm_mon = st.wMonth - 1;
tmtm.tm_year = st.wYear - 1900; tmtm.tm_isdst = -1;
tt = mktime (&tmtm);
tp->tv_sec = tt;
tp->tv_usec = st.wMilliseconds * 1000;
SYSTEMTIME st;
time_t tt;
struct tm tmtm;
/* mktime converts local to UTC */
GetLocalTime(&st);
tmtm.tm_sec = st.wSecond;
tmtm.tm_min = st.wMinute;
tmtm.tm_hour = st.wHour;
tmtm.tm_mday = st.wDay;
tmtm.tm_mon = st.wMonth - 1;
tmtm.tm_year = st.wYear - 1900;
tmtm.tm_isdst = -1;
tt = mktime(&tmtm);
tp->tv_sec = tt;
tp->tv_usec = st.wMilliseconds * 1000;
#else
/**
** The earlier time calculations using GetLocalTime
@@ -44,18 +45,18 @@ static __inline int gettimeofday(struct timeval *tp, void *nothing)
** of multimedia apis offer a better time resolution
** of 1ms.Need to link against winmm.lib for this
**/
unsigned long Ticks = 0;
unsigned long Sec =0;
unsigned long Usec = 0;
Ticks = timeGetTime();
unsigned long Ticks = 0;
unsigned long Sec = 0;
unsigned long Usec = 0;
Ticks = timeGetTime();
Sec = Ticks/1000;
Usec = (Ticks - (Sec*1000))*1000;
tp->tv_sec = Sec;
tp->tv_usec = Usec;
Sec = Ticks / 1000;
Usec = (Ticks - (Sec * 1000)) * 1000;
tp->tv_sec = Sec;
tp->tv_usec = Usec;
#endif /* WITHOUT_MM_LIB */
(void)nothing;
return 0;
(void) nothing;
return 0;
}
#endif /* WIN32 */
#endif /* HAVE_GETTIMEOFDAY */
@@ -84,37 +85,37 @@ static struct sangoma_pri_event_list SANGOMA_PRI_EVENT_LIST[] = {
char *sangoma_pri_event_str(sangoma_pri_event_t event_id)
{
{
return SANGOMA_PRI_EVENT_LIST[event_id].name;
}
static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen)
{
unsigned char tmpbuf[sizeof(wp_tdm_api_rx_hdr_t)];
/* NOTE: This code will be different for A104
* A104 receives data + 2byte CRC + 1 byte flag
* A101/2 receives data only */
int res = sangoma_readmsg_socket((sng_fd_t)(pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
buf, buflen,
0);
if (res > 0){
* A101/2 receives data only */
int res = sangoma_readmsg_socket((sng_fd_t) (pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
buf, buflen,
0);
if (res > 0) {
#ifdef WANPIPE_LEGACY_A104
/* Prior 2.3.4 release A104 API passed up
* 3 extra bytes: 2 CRC + 1 FLAG,
* PRI is expecting only 2 CRC bytes, thus we
* must remove 1 flag byte */
* 3 extra bytes: 2 CRC + 1 FLAG,
* PRI is expecting only 2 CRC bytes, thus we
* must remove 1 flag byte */
res--;
#else
/* Add 2 byte CRC and set it to ZERO */
memset(&((unsigned char*)buf)[res],0,2);
res+=2;
/* Add 2 byte CRC and set it to ZERO */
memset(&((unsigned char *) buf)[res], 0, 2);
res += 2;
#endif
}else{
res=0;
} else {
res = 0;
}
return res;
@@ -126,25 +127,23 @@ static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen)
int res;
memset(&tmpbuf[0],0,sizeof(wp_tdm_api_rx_hdr_t));
memset(&tmpbuf[0], 0, sizeof(wp_tdm_api_rx_hdr_t));
if (buflen < 1){
if (buflen < 1) {
/* HDLC Frame must be greater than 2byte CRC */
fprintf(stderr,"%s: Got short frame %i\n",__FUNCTION__,buflen);
fprintf(stderr, "%s: Got short frame %i\n", __FUNCTION__, buflen);
return 0;
}
/* FIXME: This might cause problems with other libraries
* We must remove 2 bytes from buflen because
* libpri sends 2 fake CRC bytes */
res=sangoma_sendmsg_socket((sng_fd_t)(pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
buf, (unsigned short)buflen-2,
0);
if (res > 0){
res=buflen;
res = sangoma_sendmsg_socket((sng_fd_t) (pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t), buf, (unsigned short) buflen - 2, 0);
if (res > 0) {
res = buflen;
}
return res;
}
@@ -155,10 +154,10 @@ int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype,
memset(spri, 0, sizeof(struct sangoma_pri));
if((dfd = sangoma_open_tdmapi_span_chan(span, dchan)) < 0) {
if ((dfd = sangoma_open_tdmapi_span_chan(span, dchan)) < 0) {
fprintf(stderr, "Unable to open DCHAN %d for span %d (%s)\n", dchan, span, strerror(errno));
} else {
if ((spri->pri = pri_new_cb((int)dfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, NULL))){
if ((spri->pri = pri_new_cb((int) dfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, NULL))) {
spri->span = span;
pri_set_debug(spri->pri, debug);
ret = 0;
@@ -173,10 +172,10 @@ int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype,
int sangoma_one_loop(struct sangoma_pri *spri)
{
fd_set rfds, efds;
struct timeval now = {0,0}, *next;
struct timeval now = { 0, 0 }, *next;
pri_event *event;
int sel;
int sel;
if (spri->on_loop) {
spri->on_loop(spri);
}
@@ -223,10 +222,11 @@ int sangoma_one_loop(struct sangoma_pri *spri)
if (event) {
event_handler handler;
/* 0 is catchall event handler */
if ((handler = spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
if ((handler =
spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
handler(spri, event->e, event);
} else {
fprintf(stderr,"No event handler found for event %d.\n", event->e);
fprintf(stderr, "No event handler found for event %d.\n", event->e);
}
}
@@ -237,23 +237,22 @@ int sangoma_run_pri(struct sangoma_pri *spri)
{
int ret = 0;
for (;;){
ret=sangoma_one_loop(spri);
if (ret < 0){
for (;;) {
ret = sangoma_one_loop(spri);
if (ret < 0) {
#ifndef WIN32 //This needs to be adressed fror WIN32 still
if (errno == EINTR){
#ifndef WIN32 //This needs to be adressed fror WIN32 still
if (errno == EINTR) {
/* Igonore an interrupted system call */
continue;
}
#endif
printf("Error = %i\n",ret);
#endif
printf("Error = %i\n", ret);
perror("Sangoma Run Pri: ");
break;
break;
}
}
return ret;
}
@@ -50,7 +50,7 @@ typedef enum {
typedef enum {
SANGOMA_PRI_SWITCH_UNKNOWN = PRI_SWITCH_UNKNOWN,
SANGOMA_PRI_SWITCH_NI2 = PRI_SWITCH_NI2,
SANGOMA_PRI_SWITCH_NI2 = PRI_SWITCH_NI2,
SANGOMA_PRI_SWITCH_DMS100 = PRI_SWITCH_DMS100,
SANGOMA_PRI_SWITCH_LUCENT5E = PRI_SWITCH_LUCENT5E,
SANGOMA_PRI_SWITCH_ATT4ESS = PRI_SWITCH_ATT4ESS,
@@ -67,8 +67,8 @@ typedef enum {
} sangoma_pri_flag_t;
struct sangoma_pri;
typedef int (*event_handler)(struct sangoma_pri *, sangoma_pri_event_t, pri_event *);
typedef int (*loop_handler)(struct sangoma_pri *);
typedef int (*event_handler) (struct sangoma_pri *, sangoma_pri_event_t, pri_event *);
typedef int (*loop_handler) (struct sangoma_pri *);
#define MAX_EVENT 18
struct sangoma_pri {
@@ -77,7 +77,7 @@ struct sangoma_pri {
int dchan;
unsigned int flags;
void *private_info;
event_handler eventmap[MAX_EVENT+1];
event_handler eventmap[MAX_EVENT + 1];
loop_handler on_loop;
};
@@ -11,228 +11,159 @@
#ifndef _WIN_API_COMMON_H
#define _WIN_API_COMMON_H
static
int
tdmv_api_ioctl(
HANDLE fd,
wanpipe_tdm_api_cmd_t *tdm_api_cmd
)
static
int tdmv_api_ioctl(HANDLE fd, wanpipe_tdm_api_cmd_t * tdm_api_cmd)
{
DWORD ln;
unsigned char id = 0;
int err = 0;
DWORD ln;
unsigned char id = 0;
int err = 0;
wan_udp.wan_udphdr_request_reply = 0x01;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL;
wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t);
wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL;
wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t);
//copy data from caller's buffer to driver's buffer
memcpy( wan_udp.wan_udphdr_data,
(void*)tdm_api_cmd,
sizeof(wanpipe_tdm_api_cmd_t));
memcpy(wan_udp.wan_udphdr_data, (void *) tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t));
if(DeviceIoControl(
fd,
IoctlManagementCommand,
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(fd,
IoctlManagementCommand,
(LPVOID) & wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//actual ioctl failed
err = 1;
prn(1, "Error: tdmv_api_ioctl(): DeviceIoControl failed!!\n");
return err;
}else{
} else {
err = 0;
}
if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){
if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK) {
//ioctl ok, but command failed
prn(1, "Error: tdmv_api_ioctl(): command failed! Return code: 0x%X.\n",
wan_udp.wan_udphdr_return_code);
prn(1, "Error: tdmv_api_ioctl(): command failed! Return code: 0x%X.\n", wan_udp.wan_udphdr_return_code);
return 2;
}
//copy data from driver's buffer to caller's buffer
memcpy( (void*)tdm_api_cmd,
wan_udp.wan_udphdr_data,
sizeof(wanpipe_tdm_api_cmd_t));
memcpy((void *) tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t));
return 0;
}
static
int
wanpipe_api_ioctl(
HANDLE fd,
wan_cmd_api_t *api_cmd
)
static
int wanpipe_api_ioctl(HANDLE fd, wan_cmd_api_t * api_cmd)
{
DWORD ln;
unsigned char id = 0;
int err = 0;
DWORD ln;
unsigned char id = 0;
int err = 0;
wan_udp.wan_udphdr_request_reply = 0x01;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_command = SIOC_WANPIPE_API;
wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t);
wan_udp.wan_udphdr_command = SIOC_WANPIPE_API;
wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t);
//copy data from caller's buffer to driver's buffer
memcpy( wan_udp.wan_udphdr_data,
(void*)api_cmd,
sizeof(wan_cmd_api_t));
memcpy(wan_udp.wan_udphdr_data, (void *) api_cmd, sizeof(wan_cmd_api_t));
if(DeviceIoControl(
fd,
IoctlManagementCommand,
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(fd,
IoctlManagementCommand,
(LPVOID) & wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
err = 1;
prn(1, "Error: wanpipe_api_ioctl(): DeviceIoControl failed!!\n");
return err;
}else{
} else {
err = 0;
}
if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){
prn(1, "Error: wanpipe_api_ioctl(): command failed! Return code: 0x%X.\n",
wan_udp.wan_udphdr_return_code);
if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK) {
prn(1, "Error: wanpipe_api_ioctl(): command failed! Return code: 0x%X.\n", wan_udp.wan_udphdr_return_code);
return 2;
}
//copy data from driver's buffer to caller's buffer
memcpy( (void*)api_cmd,
wan_udp.wan_udphdr_data,
sizeof(wan_cmd_api_t));
memcpy((void *) api_cmd, wan_udp.wan_udphdr_data, sizeof(wan_cmd_api_t));
return 0;
}
// Blocking read command. If used after DoApiPollCommand(),
// it will return immediatly, without blocking.
static
USHORT
DoReadCommand(
HANDLE drv,
RX_DATA_STRUCT * pRx
)
static USHORT DoReadCommand(HANDLE drv, RX_DATA_STRUCT * pRx)
{
DWORD ln;
if (DeviceIoControl(
drv,
IoctlReadCommand,
(LPVOID)NULL,
0L,
(LPVOID)pRx,
sizeof(RX_DATA_STRUCT),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(drv,
IoctlReadCommand,
(LPVOID) NULL,
0L, (LPVOID) pRx, sizeof(RX_DATA_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoReadCommand(): DeviceIoControl failed!\n");
return 1;
}else{
} else {
return 0;
}
}
// Blocking write command. If used after DoApiPollCommand(),
// it will return immediatly, without blocking.
static
UCHAR
DoWriteCommand(
HANDLE drv,
TX_DATA_STRUCT * pTx
)
static UCHAR DoWriteCommand(HANDLE drv, TX_DATA_STRUCT * pTx)
{
DWORD ln;
if(DeviceIoControl(
drv,
IoctlWriteCommand,
(LPVOID)pTx,
(ULONG)sizeof(TX_DATA_STRUCT),
(LPVOID)pTx,
sizeof(TX_DATA_STRUCT),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(drv,
IoctlWriteCommand,
(LPVOID) pTx,
(ULONG) sizeof(TX_DATA_STRUCT),
(LPVOID) pTx, sizeof(TX_DATA_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoWriteCommand(): DeviceIoControl failed!\n");
return 1;
}else{
} else {
return 0;
}
}
// Blocking API Poll command.
static
USHORT
DoApiPollCommand(
HANDLE drv,
API_POLL_STRUCT *api_poll_ptr
)
static USHORT DoApiPollCommand(HANDLE drv, API_POLL_STRUCT * api_poll_ptr)
{
DWORD ln;
if (DeviceIoControl(
drv,
IoctlApiPoll,
(LPVOID)NULL,
0L,
(LPVOID)api_poll_ptr,
sizeof(API_POLL_STRUCT),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(drv,
IoctlApiPoll,
(LPVOID) NULL,
0L,
(LPVOID) api_poll_ptr,
sizeof(API_POLL_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoApiPollCommand(): DeviceIoControl failed!\n");
return 1;
}else{
} else {
return 0;
}
}
static
int
DoManagementCommand(
HANDLE drv,
wan_udp_hdr_t* wan_udp
)
int DoManagementCommand(HANDLE drv, wan_udp_hdr_t * wan_udp)
{
DWORD ln;
static unsigned char id = 0;
static unsigned char id = 0;
wan_udp->wan_udphdr_request_reply = 0x01;
wan_udp->wan_udphdr_id = id++;
wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
if(DeviceIoControl(
drv,
IoctlManagementCommand,
(LPVOID)wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID)wan_udp,
sizeof(wan_udp_hdr_t),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(drv,
IoctlManagementCommand,
(LPVOID) wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID) wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoManagementCommand(): DeviceIoControl failed!\n");
return 1;
}else{
} else {
return 0;
}
}
File diff suppressed because it is too large. Load diff
+39 -43
View File
@@ -16,38 +16,35 @@
#include <stdint.h>
enum e_sigboost_event_id_values
{
SIGBOOST_EVENT_CALL_START = 0x80, /*128*/
SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129*/
SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130*/
SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131*/
SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/
SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/
SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/
SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/
SIGBOOST_EVENT_HEARTBEAT = 0x88, /*136*/
enum e_sigboost_event_id_values {
SIGBOOST_EVENT_CALL_START = 0x80, /*128 */
SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129 */
SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130 */
SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131 */
SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132 */
SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133 */
SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134 */
SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135 */
SIGBOOST_EVENT_HEARTBEAT = 0x88, /*136 */
};
enum e_sigboost_release_cause_values
{
SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0x00,
SIGBOOST_RELEASE_CAUSE_NORMAL = 0x90,
SIGBOOST_RELEASE_CAUSE_BUSY = 0x91,
SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92,
SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93,
SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94
enum e_sigboost_release_cause_values {
SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0x00,
SIGBOOST_RELEASE_CAUSE_NORMAL = 0x90,
SIGBOOST_RELEASE_CAUSE_BUSY = 0x91,
SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92,
SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93,
SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94
};
enum e_sigboost_call_setup_ack_nack_cause_values
{
SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10,
SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11,
SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 0x12,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_BIG = 0x13,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_BIG = 0x14,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_SMALL = 0x15,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_SMALL = 0x16,
enum e_sigboost_call_setup_ack_nack_cause_values {
SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10,
SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11,
SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 0x12,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_BIG = 0x13,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_BIG = 0x14,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_SMALL = 0x15,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_SMALL = 0x16,
};
#define MAX_DIALED_DIGITS 31
@@ -61,21 +58,20 @@ enum e_sigboost_call_setup_ack_nack_cause_values
/* 0..(MAX_PENDING_CALLS-1) is range of call_setup_id below */
#pragma pack(1)
typedef struct
{
uint32_t event_id;
uint32_t seqno;
uint32_t call_setup_id;
uint32_t trunk_group;
uint32_t span;
uint32_t chan;
uint32_t called_number_digits_count;
int8_t called_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t calling_number_digits_count; /* it's an array */
int8_t calling_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t release_cause;
struct timeval tv;
uint32_t calling_number_presentation;
typedef struct {
uint32_t event_id;
uint32_t seqno;
uint32_t call_setup_id;
uint32_t trunk_group;
uint32_t span;
uint32_t chan;
uint32_t called_number_digits_count;
int8_t called_number_digits[MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t calling_number_digits_count; /* it's an array */
int8_t calling_number_digits[MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t release_cause;
struct timeval tv;
uint32_t calling_number_presentation;
} t_sigboost;
#pragma pack()
+49 -54
View File
@@ -52,23 +52,25 @@ static struct ss7boost_client_map ss7boost_client_table[] = {
{SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"},
{SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"},
{SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"},
};
};
static switch_status_t create_udp_socket(ss7boost_client_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
static switch_status_t create_udp_socket(ss7boost_client_connection_t * mcon, char *local_ip, int local_port, char *ip,
int port)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d->%s:%d\n", local_ip, local_port, ip, port);
if (switch_sockaddr_info_get(&mcon->local_addr, local_ip, SWITCH_UNSPEC, local_port, 0, mcon->pool) != SWITCH_STATUS_SUCCESS) {
if (switch_sockaddr_info_get(&mcon->local_addr, local_ip, SWITCH_UNSPEC, local_port, 0, mcon->pool) !=
SWITCH_STATUS_SUCCESS) {
goto fail;
}
if (switch_sockaddr_info_get(&mcon->remote_addr, ip, SWITCH_UNSPEC, port, 0, mcon->pool) != SWITCH_STATUS_SUCCESS) {
goto fail;
}
if (switch_socket_create(&mcon->socket, AF_INET, SOCK_DGRAM, 0, mcon->pool) == SWITCH_STATUS_SUCCESS) {
if (switch_socket_bind(mcon->socket, mcon->local_addr) != SWITCH_STATUS_SUCCESS) {
goto fail;
@@ -77,18 +79,20 @@ static switch_status_t create_udp_socket(ss7boost_client_connection_t *mcon, cha
goto fail;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Created boost connection %s:%d->%s:%d\n", local_ip, local_port, ip, port);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Created boost connection %s:%d->%s:%d\n", local_ip,
local_port, ip, port);
return SWITCH_STATUS_SUCCESS;
fail:
fail:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating boost connection %s:%d->%s:%d\n", local_ip, local_port, ip, port);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating boost connection %s:%d->%s:%d\n", local_ip,
local_port, ip, port);
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t *mcon)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t * mcon)
{
switch_socket_close(mcon->socket);
mcon->socket = NULL;
@@ -97,12 +101,10 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t *mcon,
char *local_ip,
int local_port,
char *ip,
int port,
switch_memory_pool_t *pool)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t * mcon,
char *local_ip,
int local_port,
char *ip, int port, switch_memory_pool_t *pool)
{
memset(mcon, 0, sizeof(*mcon));
mcon->pool = pool;
@@ -111,32 +113,30 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_
switch_mutex_init(&mcon->mutex, SWITCH_MUTEX_NESTED, mcon->pool);
return SWITCH_STATUS_SUCCESS;
}
memset(mcon, 0, sizeof(*mcon));
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t *mcon, ss7boost_client_event_t **event)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t * mcon,
ss7boost_client_event_t ** event)
{
unsigned int fromlen = sizeof(struct sockaddr_in);
switch_size_t bytes = 0;
bytes = sizeof(mcon->event);
if (switch_socket_recvfrom(mcon->local_addr, mcon->socket, 0, (void *)&mcon->event, &bytes) != SWITCH_STATUS_SUCCESS) {
if (switch_socket_recvfrom(mcon->local_addr, mcon->socket, 0, (void *) &mcon->event, &bytes) !=
SWITCH_STATUS_SUCCESS) {
bytes = 0;
}
if (bytes == sizeof(mcon->event) ||
bytes == (sizeof(mcon->event)-sizeof(uint32_t))) {
if (bytes == sizeof(mcon->event) || bytes == (sizeof(mcon->event) - sizeof(uint32_t))) {
if (rxseq != mcon->event.seqno) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n",
rxseq,mcon->event.seqno);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n", rxseq, mcon->event.seqno);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
}
rxseq++;
@@ -147,7 +147,8 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t *mcon, ss7boost_client_event_t *event)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t * mcon,
ss7boost_client_event_t * event)
{
int err;
switch_size_t len;
@@ -158,23 +159,19 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client
}
if (event->span < 0 || event->chan < 0 || event->span > 7 || event->chan > 30) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Critical Error: Invalid Span=%i Chan=%i\n",
event->span,event->chan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Critical Error: Invalid Span=%i Chan=%i\n", event->span, event->chan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
}
#ifdef WIN32
//TODO set the tv with win func
#else
gettimeofday(&event->tv,NULL);
#else
gettimeofday(&event->tv, NULL);
#endif
switch_mutex_lock(mcon->mutex);
event->seqno=txseq++;
event->seqno = txseq++;
len = sizeof(*event);
if (switch_socket_sendto(mcon->socket, mcon->remote_addr, 0, (void *) event, &len) != SWITCH_STATUS_SUCCESS) {
err = -1;
@@ -182,7 +179,8 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client
switch_mutex_unlock(mcon->mutex);
if (len != sizeof(ss7boost_client_event_t)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write Error: [%d][%d][%s]\n", mcon->socket, errno, strerror(errno));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write Error: [%d][%d][%s]\n", mcon->socket, errno,
strerror(errno));
err = -1;
}
@@ -204,42 +202,39 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client
"\n",
ss7boost_client_event_id_name(event->event_id),
event->event_id,
event->span+1,
event->chan+1,
event->span + 1,
event->chan + 1,
(event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"),
(event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"),
event->release_cause,
event->span+1,
event->chan+1,
event->event_id,
event->call_setup_id,
event->seqno
);
event->span + 1, event->chan + 1, event->event_id, event->call_setup_id, event->seqno);
return err ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t *event, char *calling, char *called, int setup_id)
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event, char *calling, char *called,
int setup_id)
{
memset(event, 0, sizeof(ss7boost_client_event_t));
event->event_id = SIGBOOST_EVENT_CALL_START;
if (calling) {
strncpy((char*)event->calling_number_digits, calling, sizeof(event->calling_number_digits)-1);
strncpy((char *) event->calling_number_digits, calling, sizeof(event->calling_number_digits) - 1);
event->calling_number_digits_count = strlen(calling);
}
if (called) {
strncpy((char*)event->called_number_digits, called, sizeof(event->called_number_digits)-1);
strncpy((char *) event->called_number_digits, called, sizeof(event->called_number_digits) - 1);
event->called_number_digits_count = strlen(called);
}
event->call_setup_id = setup_id;
}
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t *event, ss7boost_client_event_id_t event_id, int chan, int span)
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t * event, ss7boost_client_event_id_t event_id,
int chan, int span)
{
memset(event, 0, sizeof(ss7boost_client_event_t));
event->event_id = event_id;
@@ -252,7 +247,7 @@ SWITCH_DECLARE(char *) ss7boost_client_event_id_name(uint32_t event_id)
int x;
char *ret = NULL;
for (x = 0 ; x < sizeof(ss7boost_client_table)/sizeof(struct ss7boost_client_map); x++) {
for (x = 0; x < sizeof(ss7boost_client_table) / sizeof(struct ss7boost_client_map); x++) {
if (ss7boost_client_table[x].event_id == event_id) {
ret = ss7boost_client_table[x].name;
break;
+15 -15
View File
@@ -70,7 +70,7 @@
(dest)->flags |= ((src)->flags & (flagz)); \
} while (0)
typedef t_sigboost ss7boost_client_event_t;
typedef t_sigboost ss7boost_client_event_t;
typedef uint32_t ss7boost_client_event_id_t;
struct ss7boost_client_connection {
@@ -80,7 +80,7 @@ struct ss7boost_client_connection {
ss7boost_client_event_t event;
unsigned int flags;
switch_mutex_t *mutex;
switch_memory_pool_t * pool;
switch_memory_pool_t *pool;
};
typedef enum {
@@ -89,19 +89,19 @@ typedef enum {
typedef struct ss7boost_client_connection ss7boost_client_connection_t;
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t *mcon);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t *mcon,
char *local_ip,
int local_port,
char *ip,
int port,
switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t *mcon, ss7boost_client_event_t **event);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t *mcon, ss7boost_client_event_t *event);
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t *event, ss7boost_client_event_id_t event_id, int chan, int span);
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t *event, char *calling, char *called, int setup_id);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t * mcon);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t * mcon,
char *local_ip,
int local_port,
char *ip, int port, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t * mcon,
ss7boost_client_event_t ** event);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t * mcon,
ss7boost_client_event_t * event);
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t * event, ss7boost_client_event_id_t event_id,
int chan, int span);
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event, char *calling, char *called,
int setup_id);
SWITCH_DECLARE(char *) ss7boost_client_event_id_name(uint32_t event_id);
#endif
+84 -70
View File
@@ -169,12 +169,13 @@ static switch_status_t woomera_on_hangup(switch_core_session_t *session);
static switch_status_t woomera_on_ring(switch_core_session_t *session);
static switch_status_t woomera_on_loopback(switch_core_session_t *session);
static switch_status_t woomera_on_transmit(switch_core_session_t *session);
static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool);
static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id);
switch_io_flag_t flags, int stream_id);
static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
switch_io_flag_t flags, int stream_id);
switch_io_flag_t flags, int stream_id);
static switch_status_t woomera_kill_channel(switch_core_session_t *session, int sig);
static void tech_destroy(private_object * tech_pvt);
static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...);
@@ -213,7 +214,8 @@ static switch_status_t woomera_on_init(switch_core_session_t *session)
if (switch_core_codec_init
(&tech_pvt->read_codec, "L16", NULL, rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n",
switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
}
@@ -221,7 +223,8 @@ static switch_status_t woomera_on_init(switch_core_session_t *session)
if (switch_core_codec_init
(&tech_pvt->write_codec, "L16", NULL, rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n",
switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
}
@@ -327,19 +330,19 @@ static switch_status_t woomera_kill_channel(switch_core_session_t *session, int
return SWITCH_STATUS_FALSE;
}
switch(sig) {
case SWITCH_SIG_KILL:
udp_socket_close(tech_pvt);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s WOOMERA KILL\n", switch_channel_get_name(channel));
break;
case SWITCH_SIG_BREAK:
{
const char p = 0;
switch_size_t len = sizeof(p);
switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, &p, &len);
}
break;
}
switch (sig) {
case SWITCH_SIG_KILL:
udp_socket_close(tech_pvt);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s WOOMERA KILL\n", switch_channel_get_name(channel));
break;
case SWITCH_SIG_BREAK:
{
const char p = 0;
switch_size_t len = sizeof(p);
switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, &p, &len);
}
break;
}
return SWITCH_STATUS_SUCCESS;
@@ -375,11 +378,11 @@ static switch_status_t woomera_waitfor_write(switch_core_session_t *session, int
assert(tech_pvt != NULL);
return SWITCH_STATUS_SUCCESS;
// return switch_socket_waitfor(tech_pvt->write_poll, ms);
// return switch_socket_waitfor(tech_pvt->write_poll, ms);
}
static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id)
switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
struct private_object *tech_pvt = NULL;
@@ -404,8 +407,9 @@ static switch_status_t woomera_read_frame(switch_core_session_t *session, switch
*frame = pframe;
len = sizeof(tech_pvt->databuf);
if (switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &len) == SWITCH_STATUS_SUCCESS) {
pframe->datalen = (uint32_t)len;
if (switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &len) ==
SWITCH_STATUS_SUCCESS) {
pframe->datalen = (uint32_t) len;
pframe->samples = (int) pframe->datalen / 2;
return SWITCH_STATUS_SUCCESS;
}
@@ -414,13 +418,13 @@ static switch_status_t woomera_read_frame(switch_core_session_t *session, switch
}
static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
switch_io_flag_t flags, int stream_id)
switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
struct private_object *tech_pvt = NULL;
switch_size_t len;
//switch_frame_t *pframe;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -430,11 +434,10 @@ static switch_status_t woomera_write_frame(switch_core_session_t *session, switc
if (!tech_pvt->udp_socket) {
return SWITCH_STATUS_GENERR;
}
//pframe = &tech_pvt->frame;
len = frame->datalen;
if (switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, frame->data, &len) == SWITCH_STATUS_SUCCESS) {
frame->datalen = (uint32_t)len;
frame->datalen = (uint32_t) len;
return SWITCH_STATUS_SUCCESS;
}
@@ -481,7 +484,8 @@ static const switch_loadable_module_interface_t woomera_module_interface = {
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool)
{
if ((*new_session = switch_core_session_request(&woomera_endpoint_interface, pool)) != 0) {
@@ -542,7 +546,8 @@ static void tech_destroy(private_object * tech_pvt)
WOOMERA_RECORD_SEPERATOR);
if (woomera_message_parse
(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Already Disconnected\n", tech_pvt->profile->name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Already Disconnected\n",
tech_pvt->profile->name);
}
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "bye%s", WOOMERA_RECORD_SEPERATOR);
@@ -570,7 +575,7 @@ static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, c
} else {
if (profile && globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Message: {%s} [%s/%d]\n%s\n%s", profile->name,
profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff);
profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff);
}
len = strlen(stuff);
switch_socket_send(socket, stuff, &len);
@@ -660,7 +665,7 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, in
bytes = 0;
while (!strstr(buf, WOOMERA_RECORD_SEPERATOR)) {
size_t len = 1;
switch_status_t status;
switch_status_t status;
if (!profile->thread_running) {
return -1;
@@ -668,16 +673,16 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, in
status = switch_socket_recv(fd, ptr, &len);
if (status == 70007) {
char bbuf = '\n';
switch_size_t blen = sizeof(bbuf);
switch_socket_send(fd, &bbuf, &blen);
continue;
}
if (status != SWITCH_STATUS_SUCCESS) {
return -1;
}
if (status == 70007) {
char bbuf = '\n';
switch_size_t blen = sizeof(bbuf);
switch_socket_send(fd, &bbuf, &blen);
continue;
}
if (status != SWITCH_STATUS_SUCCESS) {
return -1;
}
ptr++;
bytes++;
@@ -687,7 +692,7 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, in
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Receive Message: {%s} [%s/%d]\n%s\n%s", profile->name,
profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf);
profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf);
}
while ((cur = next) != 0) {
@@ -775,7 +780,8 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, in
if (event_queue && switch_test_flag(wmsg, WFLAG_EVENT)) {
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Queue Event: {%s} [%s]\n", profile->name, wmsg->command);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Queue Event: {%s} [%s]\n", profile->name,
wmsg->command);
}
/* we don't want events we want a reply so we will stash them for later */
woomera_enqueue_event(event_queue, wmsg);
@@ -801,7 +807,8 @@ static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile
switch_sockaddr_t *sa;
if (switch_sockaddr_info_get(&sa, profile->woomera_host, AF_INET, profile->woomera_port, 0, module_pool) != SWITCH_STATUS_SUCCESS) {
if (switch_sockaddr_info_get(&sa, profile->woomera_host, AF_INET, profile->woomera_port, 0, module_pool) !=
SWITCH_STATUS_SUCCESS) {
return -1;
}
@@ -809,8 +816,8 @@ static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile
return -1;
}
switch_socket_timeout_set((*new_sock), 10000000);
switch_socket_opt_set((*new_sock), SWITCH_SO_KEEPALIVE, 1);
switch_socket_timeout_set((*new_sock), 10000000);
switch_socket_opt_set((*new_sock), SWITCH_SO_KEEPALIVE, 1);
/*
status = switch_socket_bind((*new_sock), sa);
@@ -851,8 +858,8 @@ static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **wo
if (!woomera_profile_thread_running(profile, 0, 0)) {
break;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n",
profile->name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n", profile->name);
switch_sleep(WOOMERA_RECONNECT_TIME);
}
@@ -861,7 +868,8 @@ static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **wo
woomera_printf(profile, *woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
if (woomera_message_parse(*woomera_socket,
&wmsg, WOOMERA_HARD_TIMEOUT, profile, &profile->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", profile->name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
profile->name);
globals.panic = 1;
woomera_profile_thread_running(&default_profile, 1, 0);
switch_sleep(WOOMERA_RECONNECT_TIME);
@@ -890,7 +898,8 @@ static int tech_create_read_socket(private_object * tech_pvt)
tech_pvt->port = globals.next_woomera_port = WOOMERA_MIN_PORT;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d\n", tech_pvt->profile->audio_ip, tech_pvt->port);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d\n", tech_pvt->profile->audio_ip,
tech_pvt->port);
//tech_pvt->udp_socket = create_udp_socket(tech_pvt->profile->audio_ip, tech_pvt->port, &tech_pvt->udpread, 0);
switch_sockaddr_info_get(&tech_pvt->udpread, tech_pvt->profile->audio_ip, SWITCH_UNSPEC, tech_pvt->port, 0, pool);
@@ -938,7 +947,7 @@ static int tech_activate(private_object * tech_pvt)
if (woomera_message_parse(tech_pvt->command_channel,
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
}
@@ -998,7 +1007,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile,
&tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
@@ -1014,7 +1023,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile,
&tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
@@ -1095,7 +1104,8 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
NULL,
tech_pvt->profile->dialplan,
cid_name, cid_num, ip, NULL, NULL, NULL, (char *)modname, NULL, exten)) != 0) {
cid_name, cid_num, ip, NULL, NULL, NULL,
(char *) modname, NULL, exten)) != 0) {
char name[128];
snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number,
rand() & 0xffff);
@@ -1115,7 +1125,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
if (woomera_message_parse(tech_pvt->command_channel,
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
@@ -1135,7 +1145,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
if ((ptr = strchr(ip, '/')) != 0) {
*ptr = '\0';
ptr++;
port = (switch_port_t)atoi(ptr);
port = (switch_port_t) atoi(ptr);
}
/* Move Channel's State Machine to RING */
switch_channel_answer(channel);
@@ -1150,8 +1160,8 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
SWITCH_STATUS_SUCCESS) {
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n",
tech_pvt->profile->name, ip);
WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n",
tech_pvt->profile->name, ip);
}
switch_channel_hangup(channel, SWITCH_CAUSE_NETWORK_OUT_OF_ORDER);
}
@@ -1160,12 +1170,12 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
}
if (globals.debug > 2) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, WOOMERA_DEBUG_PREFIX "CHECK {%s}(%d)\n",
tech_pvt->profile->name, res);
tech_pvt->profile->name, res);
}
}
if (globals.debug > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, WOOMERA_DEBUG_PREFIX "Monitor thread for %s done.\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
}
return NULL;
@@ -1204,7 +1214,7 @@ static void *woomera_thread_run(void *obj)
break;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Woomera Thread Up {%s} %s/%d\n", profile->name,
profile->woomera_host, profile->woomera_port);
profile->woomera_host, profile->woomera_port);
}
@@ -1221,18 +1231,18 @@ static void *woomera_thread_run(void *obj)
if ((((res = woomera_dequeue_event(&profile->event_queue, &wmsg)) != 0) ||
((res = woomera_message_parse(profile->woomera_socket, &wmsg,
/* if we are not stingy with threads we can block forever */
0, profile, NULL))) != 0)) {
/* if we are not stingy with threads we can block forever */
0, profile, NULL))) != 0)) {
if (res < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! I lost my connection to woomera!\n",
profile->name);
profile->name);
woomera_socket_close(&profile->woomera_socket);
//global_set_flag(TFLAG_ABORT);
globals.panic = 1;
continue;
/* Can't get to the following code --Commented out for now.*/
/* Can't get to the following code --Commented out for now. */
/* if (profile->woomera_socket)
if (switch_test_flag(profile, PFLAG_INBOUND)) {
woomera_printf(profile, profile->woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
@@ -1268,9 +1278,11 @@ static void *woomera_thread_run(void *obj)
switch_core_session_add_stream(session, NULL);
if ((tech_pvt =
(struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
(struct private_object *) switch_core_session_alloc(session,
sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED,
switch_core_session_get_pool(session));
tech_pvt->profile = &default_profile;
channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt);
@@ -1287,7 +1299,8 @@ static void *woomera_thread_run(void *obj)
}
if (globals.debug > 2) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Main Thread {%s} Select Return %d\n", profile->name, res);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Main Thread {%s} Select Return %d\n",
profile->name, res);
}
switch_yield(100);
@@ -1326,7 +1339,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
struct woomera_profile *profile = &default_profile;
@@ -1346,7 +1360,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
strncpy(profile->dialplan, "default", sizeof(profile->dialplan) - 1);
strncpy(profile->audio_ip, "127.0.0.1", sizeof(profile->audio_ip) - 1);
strncpy(profile->woomera_host, "127.0.0.1", sizeof(profile->woomera_host) - 1);
profile->woomera_port = (switch_port_t)42420;
profile->woomera_port = (switch_port_t) 42420;
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@@ -1371,7 +1385,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
} else if (!strcmp(var, "host")) {
strncpy(profile->woomera_host, val, sizeof(profile->woomera_host) - 1);
} else if (!strcmp(var, "port")) {
profile->woomera_port = (switch_port_t)atoi(val);
profile->woomera_port = (switch_port_t) atoi(val);
} else if (!strcmp(var, "disabled")) {
if (atoi(val) > 0) {
switch_set_flag(profile, PFLAG_DISABLED);
+48 -49
View File
@@ -46,8 +46,7 @@
#include <sys/stat.h>
#include <fcntl.h>
struct switch_mod_cdr_newchannel_t
{
struct switch_mod_cdr_newchannel_t {
switch_core_session_t *session;
switch_channel_t *channel;
//switch_channel_timetable_t *timetable;
@@ -57,7 +56,7 @@ struct switch_mod_cdr_newchannel_t
//bool originate;
};
enum switch_mod_cdr_sql_types_t { CDR_INTEGER,CDR_STRING,CDR_DECIMAL,CDR_DOUBLE,CDR_TINY };
enum switch_mod_cdr_sql_types_t { CDR_INTEGER, CDR_STRING, CDR_DECIMAL, CDR_DOUBLE, CDR_TINY };
#ifdef WIN32
#define STDCALL __stdcall
@@ -65,54 +64,54 @@ enum switch_mod_cdr_sql_types_t { CDR_INTEGER,CDR_STRING,CDR_DECIMAL,CDR_DOUBLE,
#define STDCALL
#endif
typedef switch_status_t (STDCALL *modcdr_time_convert_t)(switch_time_exp_t*,switch_time_t);
typedef switch_status_t (STDCALL * modcdr_time_convert_t) (switch_time_exp_t *, switch_time_t);
class BaseCDR {
public:
BaseCDR();
virtual ~BaseCDR();
BaseCDR(switch_mod_cdr_newchannel_t *newchannel);
virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param) = 0;
virtual void disconnect() = 0;
virtual bool process_record() = 0;
virtual bool is_activated() = 0;
virtual void tempdump_record() = 0;
virtual void reread_tempdumped_records() = 0;
virtual std::string get_display_name() = 0; // Get the module name
protected:
void parse_channel_variables_xconfig(std::string& unparsed,std::list<std::string>& chanvarslist,bool fixed);
void parse_channel_variables_xconfig(std::string& unparsed,std::list<std::string>& chanvarslist,std::vector<switch_mod_cdr_sql_types_t>& chanvars_fixed_types); // Typically used for SQL types
void process_channel_variables(const std::list<std::string>& stringlist,const std::list<std::string>& fixedlist,switch_channel_t *channel,bool repeat = 1); //This is used for supplemental chanvars
void process_channel_variables(const std::list<std::string>& stringlist,switch_channel_t *channel); // This is used for fixed chanvars
void escape_string(std::string& src);
std::string escape_chararray(char* src);
switch_time_t callstartdate;
switch_time_t callanswerdate;
switch_time_t callenddate;
switch_time_t calltransferdate;
switch_call_cause_t hangupcause;
char *hangupcause_text;
char clid[80];
bool originated; // Did they originate this call?
char dialplan[80];
char myuuid[37]; // 36 + 1 to hold \0
char destuuid[37];
char src[80];
char dst[80];
char srcchannel[80];
char dstchannel[80];
char ani[80];
char aniii[80];
char network_addr[40];
char lastapp[80];
char lastdata[255];
switch_time_t billusec; // Yes, you heard me, we're measuring in microseconds
int disposition; // Currently 0 = Busy/Unanswered, 1 = Answered
int amaflags;
switch_core_session_t *coresession;
std::list<std::pair<std::string,std::string> > chanvars_fixed;
std::map<std::string,std::string> chanvars_supp;
bool errorstate; // True if there is an error writing the log
public:
BaseCDR();
virtual ~ BaseCDR();
BaseCDR(switch_mod_cdr_newchannel_t * newchannel);
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param) = 0;
virtual void disconnect() = 0;
virtual bool process_record() = 0;
virtual bool is_activated() = 0;
virtual void tempdump_record() = 0;
virtual void reread_tempdumped_records() = 0;
virtual std::string get_display_name() = 0; // Get the module name
protected:
void parse_channel_variables_xconfig(std::string & unparsed, std::list < std::string > &chanvarslist, bool fixed);
void parse_channel_variables_xconfig(std::string & unparsed, std::list < std::string > &chanvarslist, std::vector < switch_mod_cdr_sql_types_t > &chanvars_fixed_types); // Typically used for SQL types
void process_channel_variables(const std::list < std::string > &stringlist, const std::list < std::string > &fixedlist, switch_channel_t *channel, bool repeat = 1); //This is used for supplemental chanvars
void process_channel_variables(const std::list < std::string > &stringlist, switch_channel_t *channel); // This is used for fixed chanvars
void escape_string(std::string & src);
std::string escape_chararray(char *src);
switch_time_t callstartdate;
switch_time_t callanswerdate;
switch_time_t callenddate;
switch_time_t calltransferdate;
switch_call_cause_t hangupcause;
char *hangupcause_text;
char clid[80];
bool originated; // Did they originate this call?
char dialplan[80];
char myuuid[37]; // 36 + 1 to hold \0
char destuuid[37];
char src[80];
char dst[80];
char srcchannel[80];
char dstchannel[80];
char ani[80];
char aniii[80];
char network_addr[40];
char lastapp[80];
char lastdata[255];
switch_time_t billusec; // Yes, you heard me, we're measuring in microseconds
int disposition; // Currently 0 = Busy/Unanswered, 1 = Answered
int amaflags;
switch_core_session_t *coresession;
std::list < std::pair < std::string, std::string > >chanvars_fixed;
std::map < std::string, std::string > chanvars_supp;
bool errorstate; // True if there is an error writing the log
};
#endif
+19 -21
View File
@@ -42,34 +42,32 @@
#ifdef __cplusplus
#include <vector>
template<class T> BaseCDR* basecdr_factory(switch_mod_cdr_newchannel_t *newchannel)
template < class T > BaseCDR * basecdr_factory(switch_mod_cdr_newchannel_t * newchannel)
{
return new T(newchannel);
}
typedef BaseCDR* (*basecdr_creator)(switch_mod_cdr_newchannel_t *newchannel);
typedef BaseCDR *(*basecdr_creator) (switch_mod_cdr_newchannel_t * newchannel);
class BaseRegistry
{
private:
std::vector<basecdr_creator> m_bases; // Stores all modules
std::vector<basecdr_creator> active_bases; // Stores only active modules
public:
typedef std::vector<basecdr_creator>::iterator iterator;
static BaseRegistry& get();
void add(basecdr_creator);
void reset_active(); // Clears the active vector for reloading of configuration.
void add_active(iterator);
iterator begin();
iterator end();
iterator active_begin();
iterator active_end();
class BaseRegistry {
private:
std::vector < basecdr_creator > m_bases; // Stores all modules
std::vector < basecdr_creator > active_bases; // Stores only active modules
public:
typedef std::vector < basecdr_creator >::iterator iterator;
static BaseRegistry & get();
void add(basecdr_creator);
void reset_active(); // Clears the active vector for reloading of configuration.
void add_active(iterator);
iterator begin();
iterator end();
iterator active_begin();
iterator active_end();
};
class BaseRegistration
{
public:
BaseRegistration(basecdr_creator);
class BaseRegistration {
public:
BaseRegistration(basecdr_creator);
};
#define AUTO_REGISTER_BASECDR(basecdr) BaseRegistration _basecdr_registration_ ## basecdr(&basecdr_factory<basecdr>);
+8 -10
View File
@@ -51,11 +51,11 @@ CDRContainer::process_records() will iterate thru the queue and commit the recor
extern "C" {
#endif
class CDRContainer {
public:
class CDRContainer {
public:
CDRContainer();
CDRContainer(switch_memory_pool_t *module_pool);
~CDRContainer();
~CDRContainer();
void add_cdr(switch_core_session_t *session);
void process_records();
#ifdef SWITCH_QUEUE_ENHANCED
@@ -65,21 +65,19 @@ class CDRContainer {
#endif
void active(switch_stream_handle_t *stream);
void available(switch_stream_handle_t *stream);
protected:
private:
switch_xml_t cfg, xml, settings, param;
protected:
private:
switch_xml_t cfg, xml, settings, param;
switch_queue_t *cdrqueue;
std::string tempfilepath;
std::string tempfilepath;
char configfile[13];
bool queue_paused;
};
};
#ifdef __cplusplus
}
#endif
#endif
/* For Emacs:
* Local Variables:
* mode:c++
+31 -31
View File
@@ -44,38 +44,38 @@
#ifndef CSVCDR
#define CSVCDR
class CsvCDR : public BaseCDR {
public:
CsvCDR();
CsvCDR(switch_mod_cdr_newchannel_t *newchannel);
//CsvCDR(const CsvCDR& copyFrom);
virtual ~CsvCDR();
virtual bool process_record();
virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
class CsvCDR:public BaseCDR {
public:
CsvCDR();
CsvCDR(switch_mod_cdr_newchannel_t * newchannel);
//CsvCDR(const CsvCDR& copyFrom);
virtual ~ CsvCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static bool repeat_fixed_in_supp; // Repeat the fixed chanvars in the supplemental?
static std::string outputfile_path; // The directory we'll dump these into
static std::list<std::string> chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list<std::string> chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
static std::ofstream outputfile;
static std::ofstream::pos_type filesize_limit;
void check_file_size_and_open(); // Checks the size of the file, and if it's greater than size allowed, rotates it.
void open_file();
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static bool repeat_fixed_in_supp; // Repeat the fixed chanvars in the supplemental?
static std::string outputfile_path; // The directory we'll dump these into
static std::list < std::string > chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list < std::string > chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
static std::ofstream outputfile;
static std::ofstream::pos_type filesize_limit;
void check_file_size_and_open(); // Checks the size of the file, and if it's greater than size allowed, rotates it.
void open_file();
};
#endif
+30 -30
View File
@@ -50,37 +50,37 @@
#ifndef CURLCDR
#define CURLCDR
class CurlCDR : public BaseCDR {
public:
CurlCDR();
CurlCDR(switch_mod_cdr_newchannel_t *newchannel);
//CurlCDR(const CurlCDR& copyFrom);
virtual ~CurlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
virtual std::string itos(int i);
virtual std::string lltos(long long ll);
class CurlCDR:public BaseCDR {
public:
CurlCDR();
CurlCDR(switch_mod_cdr_newchannel_t * newchannel);
//CurlCDR(const CurlCDR& copyFrom);
virtual ~ CurlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
virtual std::string itos(int i);
virtual std::string lltos(long long ll);
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static const char *gateway_url; // The URL to send data to
static const char *gateway_credentials; // The credentials for http auth
static std::list<std::string> chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list<std::string> chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
static std::string postdata;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static const char *gateway_url; // The URL to send data to
static const char *gateway_credentials; // The credentials for http auth
static std::list < std::string > chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list < std::string > chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
static std::string postdata;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
};
#endif
+59 -59
View File
@@ -41,66 +41,66 @@
#ifndef MYSQLCDR
#define MYSQLCDR
class MysqlCDR : public BaseCDR {
public:
MysqlCDR();
MysqlCDR(switch_mod_cdr_newchannel_t *newchannel);
//MysqlCDR(const MysqlCDR& copyFrom);
virtual ~MysqlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
class MysqlCDR:public BaseCDR {
public:
MysqlCDR();
MysqlCDR(switch_mod_cdr_newchannel_t * newchannel);
//MysqlCDR(const MysqlCDR& copyFrom);
virtual ~ MysqlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated;
static char sql_query[1024];
static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
static char sql_query_chanvars[100];
static MYSQL *conn;
static MYSQL_STMT *stmt;
static MYSQL_STMT *stmt_chanvars;
static bool connectionstate;
static bool logchanvars;
static std::list<std::string> chanvars_fixed_list;
static std::vector<switch_mod_cdr_sql_types_t> chanvars_fixed_types;
static std::list<std::string> chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static char hostname[255];
static char username[255];
static char dbname[255];
static char password[255];
static modcdr_time_convert_t convert_time;
static std::string display_name;
//static fstream tmpfile;
std::vector<MYSQL_BIND> bindme;
//MYSQL_BIND *bindme;
MYSQL_TIME my_callstartdate;
MYSQL_TIME my_callanswerdate;
MYSQL_TIME my_calltransferdate;
MYSQL_TIME my_callenddate;
// Why all these long unsigned int's? MySQL's prep statement API expects these to actually exist and not just be params passed to the function calls. The are to measure the length of actual data in the char* arrays.
long unsigned int clid_length;
long unsigned int dialplan_length;
long unsigned int myuuid_length;
long unsigned int destuuid_length;
long unsigned int src_length;
long unsigned int dst_length;
long unsigned int srcchannel_length;
long unsigned int dstchannel_length;
long unsigned int ani_length;
long unsigned int aniii_length;
long unsigned int lastapp_length;
long unsigned int lastdata_length;
long unsigned int network_addr_length;
// Now a couple internal methods
template <typename T> void add_parameter(T& param, enum_field_types type, bool *is_null=0);
void add_string_parameter(char* param, long unsigned int& param_length, enum_field_types type, bool* is_null=0);
void set_mysql_time(switch_time_exp_t& param, MYSQL_TIME& destination);
void connect_to_database();
private:
static bool activated;
static char sql_query[1024];
static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
static char sql_query_chanvars[100];
static MYSQL *conn;
static MYSQL_STMT *stmt;
static MYSQL_STMT *stmt_chanvars;
static bool connectionstate;
static bool logchanvars;
static std::list < std::string > chanvars_fixed_list;
static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
static std::list < std::string > chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static char hostname[255];
static char username[255];
static char dbname[255];
static char password[255];
static modcdr_time_convert_t convert_time;
static std::string display_name;
//static fstream tmpfile;
std::vector < MYSQL_BIND > bindme;
//MYSQL_BIND *bindme;
MYSQL_TIME my_callstartdate;
MYSQL_TIME my_callanswerdate;
MYSQL_TIME my_calltransferdate;
MYSQL_TIME my_callenddate;
// Why all these long unsigned int's? MySQL's prep statement API expects these to actually exist and not just be params passed to the function calls. The are to measure the length of actual data in the char* arrays.
long unsigned int clid_length;
long unsigned int dialplan_length;
long unsigned int myuuid_length;
long unsigned int destuuid_length;
long unsigned int src_length;
long unsigned int dst_length;
long unsigned int srcchannel_length;
long unsigned int dstchannel_length;
long unsigned int ani_length;
long unsigned int aniii_length;
long unsigned int lastapp_length;
long unsigned int lastdata_length;
long unsigned int network_addr_length;
// Now a couple internal methods
template < typename T > void add_parameter(T & param, enum_field_types type, bool * is_null = 0);
void add_string_parameter(char *param, long unsigned int &param_length, enum_field_types type, bool * is_null = 0);
void set_mysql_time(switch_time_exp_t &param, MYSQL_TIME & destination);
void connect_to_database();
};
#endif
+46 -46
View File
@@ -52,53 +52,53 @@
#ifndef ODBCCDR
#define ODBCCDR
class OdbcCDR : public BaseCDR {
public:
OdbcCDR();
OdbcCDR(switch_mod_cdr_newchannel_t *newchannel);
//OdbcCDR(const MysqlCDR& copyFrom);
virtual ~OdbcCDR();
virtual bool process_record();
virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
class OdbcCDR:public BaseCDR {
public:
OdbcCDR();
OdbcCDR(switch_mod_cdr_newchannel_t * newchannel);
//OdbcCDR(const MysqlCDR& copyFrom);
virtual ~ OdbcCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated;
static char sql_query[1024];
static modcdr_time_convert_t convert_time;
static std::string display_name;
static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
static char sql_query_chanvars[355];
static char sql_query_ping[10];
static bool connectionstate;
static bool logchanvars;
static SQLHENV ODBC_env; /* global ODBC Environment */
static SQLHDBC ODBC_con; /* global ODBC Connection Handle */
static SQLHSTMT ODBC_stmt;
static SQLHSTMT ODBC_stmt_chanvars;
static SQLHSTMT ODBC_stmt_ping;
static std::list<std::string> chanvars_fixed_list;
static std::vector<switch_mod_cdr_sql_types_t> chanvars_fixed_types;
static std::list<std::string> chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static char dsn[255];
static char hostname[255];
static char username[255];
static char dbname[255];
static char password[255];
static char tablename[255];
static char tablename_chanvars[255];
//static fstream tmpfile;
char odbc_callstartdate[128];
char odbc_callanswerdate[128];
char odbc_calltransferdate[128];
char odbc_callenddate[128];
void disconnect_stage_1();
void connect_to_database();
private:
static bool activated;
static char sql_query[1024];
static modcdr_time_convert_t convert_time;
static std::string display_name;
static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
static char sql_query_chanvars[355];
static char sql_query_ping[10];
static bool connectionstate;
static bool logchanvars;
static SQLHENV ODBC_env; /* global ODBC Environment */
static SQLHDBC ODBC_con; /* global ODBC Connection Handle */
static SQLHSTMT ODBC_stmt;
static SQLHSTMT ODBC_stmt_chanvars;
static SQLHSTMT ODBC_stmt_ping;
static std::list < std::string > chanvars_fixed_list;
static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
static std::list < std::string > chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static char dsn[255];
static char hostname[255];
static char username[255];
static char dbname[255];
static char password[255];
static char tablename[255];
static char tablename_chanvars[255];
//static fstream tmpfile;
char odbc_callstartdate[128];
char odbc_callanswerdate[128];
char odbc_calltransferdate[128];
char odbc_callenddate[128];
void disconnect_stage_1();
void connect_to_database();
};
#endif
+27 -27
View File
@@ -43,33 +43,33 @@
#ifndef PDDCDR
#define PDDMCDR
class PddCDR : public BaseCDR {
public:
PddCDR();
PddCDR(switch_mod_cdr_newchannel_t *newchannel);
virtual ~PddCDR();
virtual bool process_record();
virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static std::string outputfile_path; // The directory we'll dump these into
static std::list<std::string> chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list<std::string> chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
std::string outputfile_name;
std::ofstream outputfile;
class PddCDR:public BaseCDR {
public:
PddCDR();
PddCDR(switch_mod_cdr_newchannel_t * newchannel);
virtual ~ PddCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static std::string outputfile_path; // The directory we'll dump these into
static std::list < std::string > chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list < std::string > chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
std::string outputfile_name;
std::ofstream outputfile;
};
#endif
+36 -36
View File
@@ -39,43 +39,43 @@
#ifndef SQLITECDR
#define SQLITECDR
class SqliteCDR : public BaseCDR {
public:
SqliteCDR();
SqliteCDR(switch_mod_cdr_newchannel_t *newchannel);
//SqliteCDR(const SqliteCDR& copyFrom);
virtual ~SqliteCDR();
virtual bool process_record();
virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
class SqliteCDR:public BaseCDR {
public:
SqliteCDR();
SqliteCDR(switch_mod_cdr_newchannel_t * newchannel);
//SqliteCDR(const SqliteCDR& copyFrom);
virtual ~ SqliteCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param);
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated;
static char sql_query[1024];
static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
static char sql_query_chanvars[100];
static std::string db_filename;
static bool use_utc_time;
switch_time_t sqlite_callstartdate;
switch_time_t sqlite_callanswerdate;
switch_time_t sqlite_calltransferdate;
switch_time_t sqlite_callenddate;
static switch_core_db_t *db;
static switch_core_db_stmt_t *stmt;
static switch_core_db_stmt_t *stmt_chanvars;
static switch_core_db_stmt_t *stmt_begin;
static switch_core_db_stmt_t *stmt_commit;
static bool connectionstate;
static bool logchanvars;
static std::list<std::string> chanvars_fixed_list;
static std::vector<switch_mod_cdr_sql_types_t> chanvars_fixed_types;
static std::list<std::string> chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static std::string display_name;
private:
static bool activated;
static char sql_query[1024];
static std::string tmp_sql_query; // Object must exist to bind the statement, this used for generating the sql
static char sql_query_chanvars[100];
static std::string db_filename;
static bool use_utc_time;
switch_time_t sqlite_callstartdate;
switch_time_t sqlite_callanswerdate;
switch_time_t sqlite_calltransferdate;
switch_time_t sqlite_callenddate;
static switch_core_db_t *db;
static switch_core_db_stmt_t *stmt;
static switch_core_db_stmt_t *stmt_chanvars;
static switch_core_db_stmt_t *stmt_begin;
static switch_core_db_stmt_t *stmt_commit;
static bool connectionstate;
static bool logchanvars;
static std::list < std::string > chanvars_fixed_list;
static std::vector < switch_mod_cdr_sql_types_t > chanvars_fixed_types;
static std::list < std::string > chanvars_supp_list; // The supplemental list
static bool repeat_fixed_in_supp;
static std::string display_name;
};
#endif
+27 -27
View File
@@ -43,34 +43,34 @@
#ifndef XMLCDR
#define XMLCDR
class XmlCDR : public BaseCDR {
public:
XmlCDR();
XmlCDR(switch_mod_cdr_newchannel_t *newchannel);
virtual ~XmlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t& cfg, switch_xml_t& xml, switch_xml_t& settings, switch_xml_t& param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
class XmlCDR:public BaseCDR {
public:
XmlCDR();
XmlCDR(switch_mod_cdr_newchannel_t * newchannel);
virtual ~ XmlCDR();
virtual bool process_record();
virtual void connect(switch_xml_t & cfg, switch_xml_t & xml, switch_xml_t & settings, switch_xml_t & param); // connect and disconnect need to be static because we're persisting connections until shutdown
virtual void disconnect();
virtual bool is_activated();
virtual void tempdump_record();
virtual void reread_tempdumped_records();
virtual std::string get_display_name();
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static std::string outputfile_path; // The directory we'll dump these into
static std::list<std::string> chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list<std::string> chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
std::string outputfile_name;
std::ofstream outputfile;
private:
static bool activated; // Is this module activated?
static bool connectionstate; // What is the status of the connection?
static bool logchanvars;
static modcdr_time_convert_t convert_time;
static std::string outputfile_path; // The directory we'll dump these into
static std::list < std::string > chanvars_fixed_list; // Normally this would be used, but not in this class
static std::list < std::string > chanvars_supp_list; // This will hold the list for all chanvars here
static std::string display_name;
char formattedcallstartdate[100];
char formattedcallanswerdate[100];
char formattedcalltransferdate[100];
char formattedcallenddate[100];
std::string outputfile_name;
std::ofstream outputfile;
};
#endif
@@ -46,17 +46,13 @@ static struct {
switch_sockaddr_t *addr;
switch_socket_t *udp_socket;
switch_hash_t *event_hash;
uint8_t event_list[SWITCH_EVENT_ALL+1];
uint8_t event_list[SWITCH_EVENT_ALL + 1];
int running;
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_address, globals.address)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
#define MULTICAST_EVENT "multicast::event"
static switch_status_t load_config(void)
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -80,7 +76,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!");
return SWITCH_STATUS_GENERR;
}
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -91,7 +87,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
} else if (!strcasecmp(var, "bindings")) {
set_global_bindings(val);
} else if (!strcasecmp(var, "port")) {
globals.port = (switch_port_t)atoi(val);
globals.port = (switch_port_t) atoi(val);
}
}
}
@@ -100,13 +96,13 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings)
if (globals.bindings) {
for(cur = globals.bindings; cur; count++) {
for (cur = globals.bindings; cur; count++) {
switch_event_types_t type;
if ((next = strchr(cur, ' '))) {
*next++ = '\0';
}
if (custom) {
switch_core_hash_insert_dup(globals.event_hash, cur, MARKER);
} else if (switch_name_event(cur, &type) == SWITCH_STATUS_SUCCESS) {
@@ -143,14 +139,14 @@ static void event_handler(switch_event_t *event)
if (event->subclass && !strcmp(event->subclass->name, MULTICAST_EVENT)) {
/* ignore our own events to avoid ping pong*/
/* ignore our own events to avoid ping pong */
return;
}
if (globals.event_list[(uint8_t)SWITCH_EVENT_ALL]) {
if (globals.event_list[(uint8_t) SWITCH_EVENT_ALL]) {
send = 1;
} else if ((globals.event_list[(uint8_t)event->event_id])) {
if (event->event_id != SWITCH_EVENT_CUSTOM ||
} else if ((globals.event_list[(uint8_t) event->event_id])) {
if (event->event_id != SWITCH_EVENT_CUSTOM ||
(event->subclass && switch_core_hash_find(globals.event_hash, event->subclass->name))) {
send = 1;
}
@@ -158,7 +154,7 @@ static void event_handler(switch_event_t *event)
if (send) {
char *packet;
switch (event->event_id) {
case SWITCH_EVENT_LOG:
return;
@@ -188,7 +184,8 @@ static switch_loadable_module_interface_t event_test_module_interface = {
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
memset(&globals, 0, sizeof(globals));
@@ -199,13 +196,14 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
}
switch_core_hash_init(&globals.event_hash, module_pool);
if (load_config() != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Configure\n");
return SWITCH_STATUS_TERM;
}
if (switch_sockaddr_info_get(&globals.addr, globals.address, SWITCH_UNSPEC, globals.port, 0, module_pool) != SWITCH_STATUS_SUCCESS) {
if (switch_sockaddr_info_get(&globals.addr, globals.address, SWITCH_UNSPEC, globals.port, 0, module_pool) !=
SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find address\n");
return SWITCH_STATUS_TERM;
}
@@ -214,7 +212,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error\n");
return SWITCH_STATUS_TERM;
}
if (switch_socket_opt_set(globals.udp_socket, SWITCH_SO_REUSEADDR, 1) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Option Error\n");
switch_socket_close(globals.udp_socket);
@@ -224,7 +222,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
if (switch_mcast_join(globals.udp_socket, globals.addr, NULL, NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Multicast Error\n");
switch_socket_close(globals.udp_socket);
return SWITCH_STATUS_TERM;
return SWITCH_STATUS_TERM;
}
if (switch_socket_bind(globals.udp_socket, globals.addr) != SWITCH_STATUS_SUCCESS) {
@@ -238,7 +236,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &event_test_module_interface;
if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
@@ -258,7 +256,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
switch_socket_shutdown(globals.udp_socket, SWITCH_SHUTDOWN_READWRITE);
globals.running = -1;
while(x < 100000 && globals.running) {
while (x < 100000 && globals.running) {
x++;
switch_yield(1000);
}
@@ -269,16 +267,16 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
{
switch_event_t *local_event;
char buf[65536] = {0};
char buf[65536] = { 0 };
switch_sockaddr_t *addr;
switch_sockaddr_info_get(&addr, NULL, SWITCH_UNSPEC, 0, 0, module_pool);
globals.running = 1;
while(globals.running == 1) {
while (globals.running == 1) {
char *myaddr;
size_t len = sizeof(buf);
memset(buf, 0, len);
switch_sockaddr_ip_get(&myaddr, globals.addr);
if (switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len) == SWITCH_STATUS_SUCCESS) {
@@ -287,25 +285,25 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
memcpy(&host_hash, buf, sizeof(host_hash));
packet = buf + sizeof(host_hash);
if (host_hash == globals.host_hash) {
continue;
}
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT %d\n--------------------------------\n%s\n", (int) len, packet);
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) == SWITCH_STATUS_SUCCESS) {
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) ==
SWITCH_STATUS_SUCCESS) {
char *var, *val, *term = NULL, tmpname[128];
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, "Multicast", "yes");
var = packet;
while(*var) {
while (*var) {
if ((val = strchr(var, ':')) != 0) {
*val++ = '\0';
while(*val == ' ') {
while (*val == ' ') {
val++;
}
if ((term = strchr(val, '\r')) != 0 || (term=strchr(val, '\n')) != 0) {
if ((term = strchr(val, '\r')) != 0 || (term = strchr(val, '\n')) != 0) {
*term = '\0';
while(*term == '\r' || *term == '\n') {
while (*term == '\r' || *term == '\n') {
term++;
}
}
@@ -315,18 +313,18 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
} else {
break;
}
}
}
if (var && strlen(var) > 1) {
switch_event_add_body(local_event, var);
}
switch_event_fire(&local_event);
}
}
}
globals.running = 0;
return SWITCH_STATUS_TERM;
}
File diff suppressed because it is too large. Load diff
@@ -53,13 +53,15 @@ static void event_handler(switch_event_t *event)
dofree++;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nEVENT (text version)\n--------------------------------\n%s", buf);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nEVENT (xml version)\n--------------------------------\n%s\n", xmlstr);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
"\nEVENT (text version)\n--------------------------------\n%s", buf);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,
"\nEVENT (xml version)\n--------------------------------\n%s\n", xmlstr);
break;
}
switch_safe_free(buf);
if (dofree) {
if (xml) {
switch_xml_free(xml);
@@ -125,7 +127,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
#endif
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &event_test_module_interface;
@@ -140,7 +143,6 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
#ifdef TORTURE_ME
if (1) {
int x = 0;
@@ -151,7 +151,7 @@ static int on_result(struct session *sess, ikspak * pak)
{
iks *msg, *ctag;
msg = iks_make_pres (IKS_SHOW_AVAILABLE, "Available");
msg = iks_make_pres(IKS_SHOW_AVAILABLE, "Available");
ctag = iks_insert(msg, "c");
iks_insert_attrib(ctag, "node", "http://www.freeswitch.org/xmpp/client/caps");
iks_insert_attrib(ctag, "ver", "1.0.0.1");
@@ -159,7 +159,7 @@ static int on_result(struct session *sess, ikspak * pak)
iks_insert_attrib(ctag, "xmlns", "http://jabber.org/protocol/caps");
iks_send(sess->parser, msg);
iks_delete(msg);
iks_delete(msg);
return IKS_FILTER_EAT;
}
@@ -231,16 +231,16 @@ static int on_stream(struct session *sess, int type, iks * node)
}
static int on_subscribe(void *user_data, ikspak *pak)
static int on_subscribe(void *user_data, ikspak * pak)
{
char *from = iks_find_attrib(pak->x, "from");
struct session *sess = (struct session *) user_data;
iks *msg = iks_make_s10n (IKS_TYPE_SUBSCRIBED, from, "mod_xmpp_event");
iks *msg = iks_make_s10n(IKS_TYPE_SUBSCRIBED, from, "mod_xmpp_event");
iks_send(sess->parser, msg);
iks_delete(msg);
msg = iks_make_s10n (IKS_TYPE_SUBSCRIBE, from, "mod_xmpp_event");
msg = iks_make_s10n(IKS_TYPE_SUBSCRIBE, from, "mod_xmpp_event");
iks_send(sess->parser, msg);
iks_delete(msg);
@@ -251,7 +251,7 @@ static int on_msg(void *user_data, ikspak * pak)
{
char *cmd = iks_find_cdata(pak->x, "body");
char *arg = NULL;
switch_stream_handle_t stream = {0};
switch_stream_handle_t stream = { 0 };
char retbuf[2048] = "";
char *p;
iks *msg;
@@ -272,12 +272,12 @@ static int on_msg(void *user_data, ikspak * pak)
stream.write_function = switch_console_stream_write;
switch_api_execute(cmd, arg, NULL, &stream);
msg = iks_make_msg(IKS_TYPE_NONE, globals.target_jid, retbuf);
iks_insert_attrib(msg, "subject", "Reply");
iks_send(globals.session.parser, msg);
iks_delete(msg);
return 0;
}
@@ -315,9 +315,7 @@ static void j_setup_filter(struct session *sess)
IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_ID, "auth", IKS_RULE_DONE);
iks_filter_add_rule(my_filter, on_subscribe, sess,
IKS_RULE_TYPE, IKS_PAK_S10N,
IKS_RULE_SUBTYPE, IKS_TYPE_SUBSCRIBE,
IKS_RULE_DONE);
IKS_RULE_TYPE, IKS_PAK_S10N, IKS_RULE_SUBTYPE, IKS_TYPE_SUBSCRIBE, IKS_RULE_DONE);
}
@@ -405,7 +403,8 @@ static switch_loadable_module_interface_t xmpp_event_module_interface = {
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &xmpp_event_module_interface;
@@ -52,55 +52,55 @@ static sw_result HOWL_API my_browser(sw_discovery discovery,
sw_discovery_browse_status status,
sw_uint32 interface_index,
sw_const_string name,
sw_const_string type,
sw_const_string domain,
sw_opaque_t extra) {
sw_const_string type, sw_const_string domain, sw_opaque_t extra)
{
//sw_discovery_resolve_id rid;
switch (status) {
case SW_DISCOVERY_BROWSE_INVALID:
case SW_DISCOVERY_BROWSE_INVALID:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Invalid\n");
}
break;
case SW_DISCOVERY_BROWSE_RELEASE:
case SW_DISCOVERY_BROWSE_RELEASE:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Release\n");
}
break;
case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Add Domain\n");
}
break;
case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN:
case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Add Default Domain\n");
}
break;
case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Remove Domain\n");
}
break;
case SW_DISCOVERY_BROWSE_REMOVE_SERVICE:
case SW_DISCOVERY_BROWSE_REMOVE_SERVICE:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Remove Service\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "remove service: 0x%x %s %s %s\n", interface_index, name, type, domain);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "remove service: 0x%x %s %s %s\n", interface_index,
name, type, domain);
}
break;
case SW_DISCOVERY_BROWSE_RESOLVED:
case SW_DISCOVERY_BROWSE_RESOLVED:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "browse reply: Resolved\n");
}
break;
case SW_DISCOVERY_BROWSE_ADD_SERVICE:
case SW_DISCOVERY_BROWSE_ADD_SERVICE:
break;
}
@@ -108,17 +108,16 @@ static sw_result HOWL_API my_browser(sw_discovery discovery,
}
static sw_result HOWL_API my_service_reply(sw_discovery discovery,
sw_discovery_oid oid,
sw_discovery_publish_status status,
sw_opaque extra) {
static sw_result HOWL_API my_service_reply(sw_discovery discovery,
sw_discovery_oid oid, sw_discovery_publish_status status, sw_opaque extra)
{
static sw_string status_text[] = {
"Started",
"Stopped",
"Name Collision",
"Invalid"
};
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "publish reply: %s\n", status_text[status]);
return SW_OKAY;
}
@@ -126,7 +125,7 @@ static sw_result HOWL_API my_service_reply(sw_discovery discovery,
static void event_handler(switch_event_t *event)
{
sw_text_record text_record;
sw_text_record text_record;
sw_result result;
switch (event->event_id) {
@@ -159,10 +158,10 @@ static void event_handler(switch_event_t *event)
service = "_freeswitch._tcp";
}
if (port) {
porti = (sw_port)atoi(port);
porti = (sw_port) atoi(port);
}
switch_mutex_lock(globals.zc_lock);
switch_mutex_lock(globals.zc_lock);
if ((result = sw_discovery_publish(globals.discovery,
0,
"freeswitch",
@@ -172,9 +171,7 @@ static void event_handler(switch_event_t *event)
porti,
sw_text_record_bytes(text_record),
sw_text_record_len(text_record),
my_service_reply,
NULL,
&globals.disc_id)) != SW_OKAY) {
my_service_reply, NULL, &globals.disc_id)) != SW_OKAY) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "publish failed: %u\n", result);
sw_text_record_fina(text_record);
switch_mutex_unlock(globals.zc_lock);
@@ -183,7 +180,7 @@ static void event_handler(switch_event_t *event)
switch_mutex_unlock(globals.zc_lock);
sw_text_record_fina(text_record);
}
break;
case SWITCH_EVENT_UNPUBLISH:
@@ -211,11 +208,11 @@ static switch_status_t load_config(void)
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcmp(var, "browse")) {
if ((oid = switch_core_alloc(module_pool, sizeof(*oid))) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Bind browser to to %s\n", val);
switch_mutex_lock(globals.zc_lock);
switch_mutex_lock(globals.zc_lock);
sw_discovery_browse(globals.discovery, 0, val, NULL, my_browser, NULL, oid);
switch_mutex_unlock(globals.zc_lock);
count++;
@@ -223,14 +220,16 @@ static switch_status_t load_config(void)
return SWITCH_STATUS_MEMERR;
}
} else if (!strcasecmp(var, "publish") && !strcasecmp(val, "yes")) {
if (switch_event_bind((char *) modname, SWITCH_EVENT_PUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
SWITCH_STATUS_SUCCESS) {
if (switch_event_bind
((char *) modname, SWITCH_EVENT_PUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler,
NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (switch_event_bind((char *) modname, SWITCH_EVENT_UNPUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
SWITCH_STATUS_SUCCESS) {
if (switch_event_bind
((char *) modname, SWITCH_EVENT_UNPUBLISH, SWITCH_EVENT_SUBCLASS_ANY, event_handler,
NULL) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
@@ -269,7 +268,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
memset(&globals, 0, sizeof(globals));
@@ -289,7 +289,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
if (load_config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
if (switch_event_reserve_subclass(MY_EVENT_PUBLISH) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!");
return SWITCH_STATUS_GENERR;
@@ -312,7 +312,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
{
RUNNING = 1;
while(RUNNING == 1) {
while (RUNNING == 1) {
sw_uint32 ms;
ms = 100;
sw_discovery_step(globals.discovery, &ms);
@@ -63,7 +63,8 @@ static switch_status_t native_file_file_open(switch_file_handle_t *handle, char
flags |= SWITCH_FOPEN_READ;
}
if (switch_file_open(&context->fd, path, flags, SWITCH_FPROT_UREAD|SWITCH_FPROT_UWRITE, handle->memory_pool) != SWITCH_STATUS_SUCCESS) {
if (switch_file_open(&context->fd, path, flags, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, handle->memory_pool) !=
SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening %s\n", path);
return SWITCH_STATUS_GENERR;
}
@@ -78,7 +79,7 @@ static switch_status_t native_file_file_open(switch_file_handle_t *handle, char
handle->seekable = 1;
handle->speed = 0;
handle->private_info = context;
handle->flags |= SWITCH_FILE_NATIVE;
handle->flags |= SWITCH_FILE_NATIVE;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening File [%s] %dhz\n", path, handle->samplerate);
@@ -88,7 +89,7 @@ static switch_status_t native_file_file_open(switch_file_handle_t *handle, char
static switch_status_t native_file_file_close(switch_file_handle_t *handle)
{
native_file_context *context = handle->private_info;
if (context->fd) {
switch_file_close(context->fd);
context->fd = NULL;
@@ -97,12 +98,13 @@ static switch_status_t native_file_file_close(switch_file_handle_t *handle)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t native_file_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
static switch_status_t native_file_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples,
int whence)
{
native_file_context *context = handle->private_info;
switch_file_seek(context->fd, whence, &samples);
return SWITCH_STATUS_FALSE;
}
@@ -121,21 +123,23 @@ static switch_status_t native_file_file_write(switch_file_handle_t *handle, void
return switch_file_write(context->fd, data, len);
}
static switch_status_t native_file_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
static switch_status_t native_file_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col,
const char *string)
{
//native_file_context *context = handle->private_info;
return SWITCH_STATUS_FALSE;
}
static switch_status_t native_file_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
static switch_status_t native_file_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col,
const char **string)
{
return SWITCH_STATUS_FALSE;
}
/* Registration */
static char *supported_formats[SWITCH_MAX_CODECS] = {0};
static char *supported_formats[SWITCH_MAX_CODECS] = { 0 };
static switch_file_interface_t native_file_file_interface = {
/*.interface_name */ modname,
@@ -163,14 +167,15 @@ static switch_loadable_module_interface_t native_file_module_interface = {
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
const switch_codec_implementation_t *codecs[SWITCH_MAX_CODECS];
uint32_t num_codecs = switch_loadable_module_get_codecs(NULL, codecs, sizeof(codecs) / sizeof(codecs[0]));
uint32_t x;
for (x = 0 ; x < num_codecs; x++) {
for (x = 0; x < num_codecs; x++) {
supported_formats[x] = codecs[x]->iananame;
}
+151 -163
View File
@@ -9,47 +9,47 @@
#include "mpg123.h"
#include "mpglib.h"
struct parameter param = { 1 , 1 , 0 , 0 };
struct parameter param = { 1, 1, 0, 0 };
int tabsel_123[2][3][16] = {
{ {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
{0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,},
{0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} },
{{0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448,},
{0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384,},
{0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,}},
{ {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,},
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,},
{0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} }
{{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256,},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,},
{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160,}}
};
long freqs[9] = { 44100, 48000, 32000,
22050, 24000, 16000 ,
11025 , 12000 , 8000 };
22050, 24000, 16000,
11025, 12000, 8000
};
#if 0
static void get_II_stuff(struct frame *fr)
{
static int translate[3][2][16] =
{ { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } ,
{ 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } ,
{ { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } ,
{ 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } ,
{ { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } ,
{ 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } };
static int translate[3][2][16] = { {{0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, 0},
{0, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}},
{{0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
{{0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, 0},
{0, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}}
};
int table,sblim;
static struct al_table *tables[5] =
{ alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 };
static int sblims[5] = { 27 , 30 , 8, 12 , 30 };
int table, sblim;
static struct al_table *tables[5] = { alloc_0, alloc_1, alloc_2, alloc_3, alloc_4 };
static int sblims[5] = { 27, 30, 8, 12, 30 };
if(fr->lsf)
table = 4;
else
table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index];
sblim = sblims[table];
if (fr->lsf)
table = 4;
else
table = translate[fr->sampling_frequency][2 - fr->stereo][fr->bitrate_index];
sblim = sblims[table];
fr->alloc = tables[table];
fr->II_sblimit = sblim;
fr->alloc = tables[table];
fr->II_sblimit = sblim;
}
#endif
@@ -58,15 +58,15 @@ static void get_II_stuff(struct frame *fr)
#if 0
int head_check(unsigned long head)
{
if( (head & 0xffe00000) != 0xffe00000)
return FALSE;
if(!((head>>17)&3))
return FALSE;
if( ((head>>12)&0xf) == 0xf)
return FALSE;
if( ((head>>10)&0x3) == 0x3 )
return FALSE;
return TRUE;
if ((head & 0xffe00000) != 0xffe00000)
return FALSE;
if (!((head >> 17) & 3))
return FALSE;
if (((head >> 12) & 0xf) == 0xf)
return FALSE;
if (((head >> 10) & 0x3) == 0x3)
return FALSE;
return TRUE;
}
#endif
@@ -75,190 +75,178 @@ int head_check(unsigned long head)
* the code a header and write the information
* into the frame structure
*/
int decode_header(struct frame *fr,unsigned long newhead)
int decode_header(struct frame *fr, unsigned long newhead)
{
if( newhead & (1<<20) ) {
fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
fr->mpeg25 = 0;
}
else {
fr->lsf = 1;
fr->mpeg25 = 1;
}
fr->lay = 4-((newhead>>17)&3);
if( ((newhead>>10)&0x3) == 0x3) {
debug_printf("%d Stream error\n", __LINE__);
return (0);
}
if(fr->mpeg25) {
fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
}
else
fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
fr->error_protection = ((newhead>>16)&0x1)^0x1;
if (newhead & (1 << 20)) {
fr->lsf = (newhead & (1 << 19)) ? 0x0 : 0x1;
fr->mpeg25 = 0;
} else {
fr->lsf = 1;
fr->mpeg25 = 1;
}
if(fr->mpeg25) /* allow Bitrate change for 2.5 ... */
fr->bitrate_index = ((newhead>>12)&0xf);
fr->lay = 4 - ((newhead >> 17) & 3);
if (((newhead >> 10) & 0x3) == 0x3) {
debug_printf("%d Stream error\n", __LINE__);
return (0);
}
if (fr->mpeg25) {
fr->sampling_frequency = 6 + ((newhead >> 10) & 0x3);
} else
fr->sampling_frequency = ((newhead >> 10) & 0x3) + (fr->lsf * 3);
fr->error_protection = ((newhead >> 16) & 0x1) ^ 0x1;
fr->bitrate_index = ((newhead>>12)&0xf);
fr->padding = ((newhead>>9)&0x1);
fr->extension = ((newhead>>8)&0x1);
fr->mode = ((newhead>>6)&0x3);
fr->mode_ext = ((newhead>>4)&0x3);
fr->copyright = ((newhead>>3)&0x1);
fr->original = ((newhead>>2)&0x1);
fr->emphasis = newhead & 0x3;
if (fr->mpeg25) /* allow Bitrate change for 2.5 ... */
fr->bitrate_index = ((newhead >> 12) & 0xf);
fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
fr->bitrate_index = ((newhead >> 12) & 0xf);
fr->padding = ((newhead >> 9) & 0x1);
fr->extension = ((newhead >> 8) & 0x1);
fr->mode = ((newhead >> 6) & 0x3);
fr->mode_ext = ((newhead >> 4) & 0x3);
fr->copyright = ((newhead >> 3) & 0x1);
fr->original = ((newhead >> 2) & 0x1);
fr->emphasis = newhead & 0x3;
if(!fr->bitrate_index)
{
debug_printf("%d Free format not supported.\n", __LINE__);
return (0);
}
fr->stereo = (fr->mode == MPG_MD_MONO) ? 1 : 2;
switch(fr->lay)
{
case 1:
if (!fr->bitrate_index) {
debug_printf("%d Free format not supported.\n", __LINE__);
return (0);
}
switch (fr->lay) {
case 1:
#if 0
fr->do_layer = do_layer1;
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
(fr->mode_ext<<2)+4 : 32;
fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
fr->framesize /= freqs[fr->sampling_frequency];
fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : 32;
fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
fr->framesize /= freqs[fr->sampling_frequency];
fr->framesize = ((fr->framesize + fr->padding) << 2) - 4;
#else
debug_printf("%d Layer 1 not supported!\n", __LINE__);
debug_printf("%d Layer 1 not supported!\n", __LINE__);
#endif
break;
case 2:
break;
case 2:
#if 0
fr->do_layer = do_layer2;
get_II_stuff(fr);
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
(fr->mode_ext<<2)+4 : fr->II_sblimit;
fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
fr->framesize /= freqs[fr->sampling_frequency];
fr->framesize += fr->padding - 4;
get_II_stuff(fr);
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : fr->II_sblimit;
fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
fr->framesize /= freqs[fr->sampling_frequency];
fr->framesize += fr->padding - 4;
#else
debug_printf("%d Layer 2 not supported!\n", __LINE__);
debug_printf("%d Layer 2 not supported!\n", __LINE__);
#endif
break;
case 3:
break;
case 3:
#if 0
fr->do_layer = do_layer3;
if(fr->lsf)
ssize = (fr->stereo == 1) ? 9 : 17;
else
ssize = (fr->stereo == 1) ? 17 : 32;
fr->do_layer = do_layer3;
if (fr->lsf)
ssize = (fr->stereo == 1) ? 9 : 17;
else
ssize = (fr->stereo == 1) ? 17 : 32;
#endif
#if 0
if(fr->error_protection)
ssize += 2;
if (fr->error_protection)
ssize += 2;
#endif
fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
fr->framesize = fr->framesize + fr->padding - 4;
break;
default:
debug_printf("%d Sorry, unknown layer type.\n", __LINE__);
return (0);
}
return 1;
fr->framesize = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
fr->framesize /= freqs[fr->sampling_frequency] << (fr->lsf);
fr->framesize = fr->framesize + fr->padding - 4;
break;
default:
debug_printf("%d Sorry, unknown layer type.\n", __LINE__);
return (0);
}
return 1;
}
#if 0
void print_header(struct frame *fr)
{
static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
static char *layers[4] = { "Unknown" , "I", "II", "III" };
static char *layers[4] = { "Unknown", "I", "II", "III" };
debug_printf("MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n",
fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
layers[fr->lay],freqs[fr->sampling_frequency],
modes[fr->mode],fr->mode_ext,fr->framesize+4);
debug_printf("MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n",
fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
layers[fr->lay], freqs[fr->sampling_frequency], modes[fr->mode], fr->mode_ext, fr->framesize + 4);
debug_printf("Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
fr->stereo,fr->copyright?"Yes":"No",
fr->original?"Yes":"No",fr->error_protection?"Yes":"No",
fr->emphasis);
fr->stereo, fr->copyright ? "Yes" : "No",
fr->original ? "Yes" : "No", fr->error_protection ? "Yes" : "No", fr->emphasis);
debug_printf("Bitrate: %d Kbits/s, Extension value: %d\n",
tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension);
tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index], fr->extension);
}
void print_header_compact(struct frame *fr)
{
static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
static char *layers[4] = { "Unknown" , "I", "II", "III" };
static char *layers[4] = { "Unknown", "I", "II", "III" };
debug_printf("MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
layers[fr->lay],
tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
freqs[fr->sampling_frequency], modes[fr->mode]);
fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
layers[fr->lay],
tabsel_123[fr->lsf][fr->lay - 1][fr->bitrate_index], freqs[fr->sampling_frequency], modes[fr->mode]);
}
#endif
unsigned int getbits(struct mpstr *mp, int number_of_bits)
{
unsigned long rval;
unsigned long rval;
if(!number_of_bits)
return 0;
if (!number_of_bits)
return 0;
{
rval = (mp->worksample).wordpointer[0];
rval <<= 8;
rval |= (mp->worksample).wordpointer[1];
rval <<= 8;
rval |= (mp->worksample).wordpointer[2];
rval <<= (mp->worksample).bitindex;
rval &= 0xffffff;
{
rval = (mp->worksample).wordpointer[0];
rval <<= 8;
rval |= (mp->worksample).wordpointer[1];
rval <<= 8;
rval |= (mp->worksample).wordpointer[2];
rval <<= (mp->worksample).bitindex;
rval &= 0xffffff;
(mp->worksample).bitindex += number_of_bits;
(mp->worksample).bitindex += number_of_bits;
rval >>= (24-number_of_bits);
rval >>= (24 - number_of_bits);
(mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
(mp->worksample).bitindex &= 7;
}
return rval;
(mp->worksample).wordpointer += ((mp->worksample).bitindex >> 3);
(mp->worksample).bitindex &= 7;
}
return rval;
}
unsigned int getbits_fast(struct mpstr *mp, int number_of_bits)
{
unsigned long rval;
unsigned long rval;
{
rval = (mp->worksample).wordpointer[0];
rval <<= 8;
rval |= (mp->worksample).wordpointer[1];
rval <<= (mp->worksample).bitindex;
rval &= 0xffff;
(mp->worksample).bitindex += number_of_bits;
{
rval = (mp->worksample).wordpointer[0];
rval <<= 8;
rval |= (mp->worksample).wordpointer[1];
rval <<= (mp->worksample).bitindex;
rval &= 0xffff;
(mp->worksample).bitindex += number_of_bits;
rval >>= (16-number_of_bits);
rval >>= (16 - number_of_bits);
(mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
(mp->worksample).bitindex &= 7;
}
return rval;
(mp->worksample).wordpointer += ((mp->worksample).bitindex >> 3);
(mp->worksample).bitindex &= 7;
}
return rval;
}
unsigned int get1bit(struct mpstr *mp)
{
unsigned char rval;
unsigned char rval;
rval = *((mp->worksample).wordpointer) << (mp->worksample).bitindex;
rval = *((mp->worksample).wordpointer) << (mp->worksample).bitindex;
(mp->worksample).bitindex++;
(mp->worksample).wordpointer += ((mp->worksample).bitindex>>3);
(mp->worksample).bitindex &= 7;
(mp->worksample).bitindex++;
(mp->worksample).wordpointer += ((mp->worksample).bitindex >> 3);
(mp->worksample).bitindex &= 7;
return rval>>7;
return rval >> 7;
}
+261 -262
View File
@@ -13,323 +13,322 @@
* the call via dct64 is a trick to force GCC to use
* (new) registers for the b1,b2 pointer to the bufs[xx] field
*/
void dct64(real *a,real *b,real *c);
void dct64(real * a, real * b, real * c);
static void dct64_1(real *out0,real *out1,real *b1,real *b2,real *samples)
static void dct64_1(real * out0, real * out1, real * b1, real * b2, real * samples)
{
{
register real *costab = pnts[0];
{
register real *costab = pnts[0];
b1[0x00] = samples[0x00] + samples[0x1F];
b1[0x01] = samples[0x01] + samples[0x1E];
b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
b1[0x00] = samples[0x00] + samples[0x1F];
b1[0x01] = samples[0x01] + samples[0x1E];
b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0];
b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1];
b1[0x02] = samples[0x02] + samples[0x1D];
b1[0x03] = samples[0x03] + samples[0x1C];
b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
b1[0x02] = samples[0x02] + samples[0x1D];
b1[0x03] = samples[0x03] + samples[0x1C];
b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2];
b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3];
b1[0x04] = samples[0x04] + samples[0x1B];
b1[0x05] = samples[0x05] + samples[0x1A];
b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
b1[0x04] = samples[0x04] + samples[0x1B];
b1[0x05] = samples[0x05] + samples[0x1A];
b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4];
b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5];
b1[0x06] = samples[0x06] + samples[0x19];
b1[0x07] = samples[0x07] + samples[0x18];
b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
b1[0x06] = samples[0x06] + samples[0x19];
b1[0x07] = samples[0x07] + samples[0x18];
b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6];
b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7];
b1[0x08] = samples[0x08] + samples[0x17];
b1[0x09] = samples[0x09] + samples[0x16];
b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
b1[0x08] = samples[0x08] + samples[0x17];
b1[0x09] = samples[0x09] + samples[0x16];
b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8];
b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9];
b1[0x0A] = samples[0x0A] + samples[0x15];
b1[0x0B] = samples[0x0B] + samples[0x14];
b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
b1[0x0A] = samples[0x0A] + samples[0x15];
b1[0x0B] = samples[0x0B] + samples[0x14];
b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA];
b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB];
b1[0x0C] = samples[0x0C] + samples[0x13];
b1[0x0D] = samples[0x0D] + samples[0x12];
b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
b1[0x0C] = samples[0x0C] + samples[0x13];
b1[0x0D] = samples[0x0D] + samples[0x12];
b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC];
b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD];
b1[0x0E] = samples[0x0E] + samples[0x11];
b1[0x0F] = samples[0x0F] + samples[0x10];
b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
b1[0x0E] = samples[0x0E] + samples[0x11];
b1[0x0F] = samples[0x0F] + samples[0x10];
b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE];
b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF];
}
}
{
register real *costab = pnts[1];
{
register real *costab = pnts[1];
b2[0x00] = b1[0x00] + b1[0x0F];
b2[0x01] = b1[0x01] + b1[0x0E];
b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
b2[0x00] = b1[0x00] + b1[0x0F];
b2[0x01] = b1[0x01] + b1[0x0E];
b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0];
b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1];
b2[0x02] = b1[0x02] + b1[0x0D];
b2[0x03] = b1[0x03] + b1[0x0C];
b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
b2[0x02] = b1[0x02] + b1[0x0D];
b2[0x03] = b1[0x03] + b1[0x0C];
b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2];
b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3];
b2[0x04] = b1[0x04] + b1[0x0B];
b2[0x05] = b1[0x05] + b1[0x0A];
b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
b2[0x04] = b1[0x04] + b1[0x0B];
b2[0x05] = b1[0x05] + b1[0x0A];
b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4];
b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5];
b2[0x06] = b1[0x06] + b1[0x09];
b2[0x07] = b1[0x07] + b1[0x08];
b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
b2[0x06] = b1[0x06] + b1[0x09];
b2[0x07] = b1[0x07] + b1[0x08];
b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6];
b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7];
/* */
/* */
b2[0x10] = b1[0x10] + b1[0x1F];
b2[0x11] = b1[0x11] + b1[0x1E];
b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
b2[0x10] = b1[0x10] + b1[0x1F];
b2[0x11] = b1[0x11] + b1[0x1E];
b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0];
b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1];
b2[0x12] = b1[0x12] + b1[0x1D];
b2[0x13] = b1[0x13] + b1[0x1C];
b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
b2[0x12] = b1[0x12] + b1[0x1D];
b2[0x13] = b1[0x13] + b1[0x1C];
b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2];
b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3];
b2[0x14] = b1[0x14] + b1[0x1B];
b2[0x15] = b1[0x15] + b1[0x1A];
b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
b2[0x14] = b1[0x14] + b1[0x1B];
b2[0x15] = b1[0x15] + b1[0x1A];
b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4];
b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5];
b2[0x16] = b1[0x16] + b1[0x19];
b2[0x17] = b1[0x17] + b1[0x18];
b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
}
b2[0x16] = b1[0x16] + b1[0x19];
b2[0x17] = b1[0x17] + b1[0x18];
b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6];
b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7];
}
{
register real *costab = pnts[2];
{
register real *costab = pnts[2];
b1[0x00] = b2[0x00] + b2[0x07];
b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
b1[0x01] = b2[0x01] + b2[0x06];
b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
b1[0x02] = b2[0x02] + b2[0x05];
b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
b1[0x03] = b2[0x03] + b2[0x04];
b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
b1[0x00] = b2[0x00] + b2[0x07];
b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0];
b1[0x01] = b2[0x01] + b2[0x06];
b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1];
b1[0x02] = b2[0x02] + b2[0x05];
b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2];
b1[0x03] = b2[0x03] + b2[0x04];
b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3];
b1[0x08] = b2[0x08] + b2[0x0F];
b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
b1[0x09] = b2[0x09] + b2[0x0E];
b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
b1[0x0A] = b2[0x0A] + b2[0x0D];
b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
b1[0x0B] = b2[0x0B] + b2[0x0C];
b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
b1[0x08] = b2[0x08] + b2[0x0F];
b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0];
b1[0x09] = b2[0x09] + b2[0x0E];
b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1];
b1[0x0A] = b2[0x0A] + b2[0x0D];
b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2];
b1[0x0B] = b2[0x0B] + b2[0x0C];
b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3];
b1[0x10] = b2[0x10] + b2[0x17];
b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
b1[0x11] = b2[0x11] + b2[0x16];
b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
b1[0x12] = b2[0x12] + b2[0x15];
b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
b1[0x13] = b2[0x13] + b2[0x14];
b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
b1[0x10] = b2[0x10] + b2[0x17];
b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0];
b1[0x11] = b2[0x11] + b2[0x16];
b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1];
b1[0x12] = b2[0x12] + b2[0x15];
b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2];
b1[0x13] = b2[0x13] + b2[0x14];
b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3];
b1[0x18] = b2[0x18] + b2[0x1F];
b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
b1[0x19] = b2[0x19] + b2[0x1E];
b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
b1[0x1A] = b2[0x1A] + b2[0x1D];
b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
b1[0x1B] = b2[0x1B] + b2[0x1C];
b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
}
b1[0x18] = b2[0x18] + b2[0x1F];
b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0];
b1[0x19] = b2[0x19] + b2[0x1E];
b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1];
b1[0x1A] = b2[0x1A] + b2[0x1D];
b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2];
b1[0x1B] = b2[0x1B] + b2[0x1C];
b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3];
}
{
register real const cos0 = pnts[3][0];
register real const cos1 = pnts[3][1];
{
register real const cos0 = pnts[3][0];
register real const cos1 = pnts[3][1];
b2[0x00] = b1[0x00] + b1[0x03];
b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
b2[0x01] = b1[0x01] + b1[0x02];
b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
b2[0x00] = b1[0x00] + b1[0x03];
b2[0x03] = (b1[0x00] - b1[0x03]) * cos0;
b2[0x01] = b1[0x01] + b1[0x02];
b2[0x02] = (b1[0x01] - b1[0x02]) * cos1;
b2[0x04] = b1[0x04] + b1[0x07];
b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
b2[0x05] = b1[0x05] + b1[0x06];
b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
b2[0x04] = b1[0x04] + b1[0x07];
b2[0x07] = (b1[0x07] - b1[0x04]) * cos0;
b2[0x05] = b1[0x05] + b1[0x06];
b2[0x06] = (b1[0x06] - b1[0x05]) * cos1;
b2[0x08] = b1[0x08] + b1[0x0B];
b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
b2[0x09] = b1[0x09] + b1[0x0A];
b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
b2[0x0C] = b1[0x0C] + b1[0x0F];
b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
b2[0x0D] = b1[0x0D] + b1[0x0E];
b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
b2[0x08] = b1[0x08] + b1[0x0B];
b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0;
b2[0x09] = b1[0x09] + b1[0x0A];
b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1;
b2[0x10] = b1[0x10] + b1[0x13];
b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
b2[0x11] = b1[0x11] + b1[0x12];
b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
b2[0x0C] = b1[0x0C] + b1[0x0F];
b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0;
b2[0x0D] = b1[0x0D] + b1[0x0E];
b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1;
b2[0x14] = b1[0x14] + b1[0x17];
b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
b2[0x15] = b1[0x15] + b1[0x16];
b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
b2[0x10] = b1[0x10] + b1[0x13];
b2[0x13] = (b1[0x10] - b1[0x13]) * cos0;
b2[0x11] = b1[0x11] + b1[0x12];
b2[0x12] = (b1[0x11] - b1[0x12]) * cos1;
b2[0x18] = b1[0x18] + b1[0x1B];
b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
b2[0x19] = b1[0x19] + b1[0x1A];
b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
b2[0x14] = b1[0x14] + b1[0x17];
b2[0x17] = (b1[0x17] - b1[0x14]) * cos0;
b2[0x15] = b1[0x15] + b1[0x16];
b2[0x16] = (b1[0x16] - b1[0x15]) * cos1;
b2[0x1C] = b1[0x1C] + b1[0x1F];
b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
b2[0x1D] = b1[0x1D] + b1[0x1E];
b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
}
b2[0x18] = b1[0x18] + b1[0x1B];
b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0;
b2[0x19] = b1[0x19] + b1[0x1A];
b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1;
{
register real const cos0 = pnts[4][0];
b2[0x1C] = b1[0x1C] + b1[0x1F];
b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0;
b2[0x1D] = b1[0x1D] + b1[0x1E];
b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1;
}
b1[0x00] = b2[0x00] + b2[0x01];
b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
b1[0x02] = b2[0x02] + b2[0x03];
b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
b1[0x02] += b1[0x03];
{
register real const cos0 = pnts[4][0];
b1[0x04] = b2[0x04] + b2[0x05];
b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
b1[0x06] = b2[0x06] + b2[0x07];
b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
b1[0x06] += b1[0x07];
b1[0x04] += b1[0x06];
b1[0x06] += b1[0x05];
b1[0x05] += b1[0x07];
b1[0x00] = b2[0x00] + b2[0x01];
b1[0x01] = (b2[0x00] - b2[0x01]) * cos0;
b1[0x02] = b2[0x02] + b2[0x03];
b1[0x03] = (b2[0x03] - b2[0x02]) * cos0;
b1[0x02] += b1[0x03];
b1[0x08] = b2[0x08] + b2[0x09];
b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
b1[0x0A] = b2[0x0A] + b2[0x0B];
b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
b1[0x0A] += b1[0x0B];
b1[0x04] = b2[0x04] + b2[0x05];
b1[0x05] = (b2[0x04] - b2[0x05]) * cos0;
b1[0x06] = b2[0x06] + b2[0x07];
b1[0x07] = (b2[0x07] - b2[0x06]) * cos0;
b1[0x06] += b1[0x07];
b1[0x04] += b1[0x06];
b1[0x06] += b1[0x05];
b1[0x05] += b1[0x07];
b1[0x0C] = b2[0x0C] + b2[0x0D];
b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
b1[0x0E] = b2[0x0E] + b2[0x0F];
b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
b1[0x0E] += b1[0x0F];
b1[0x0C] += b1[0x0E];
b1[0x0E] += b1[0x0D];
b1[0x0D] += b1[0x0F];
b1[0x08] = b2[0x08] + b2[0x09];
b1[0x09] = (b2[0x08] - b2[0x09]) * cos0;
b1[0x0A] = b2[0x0A] + b2[0x0B];
b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0;
b1[0x0A] += b1[0x0B];
b1[0x10] = b2[0x10] + b2[0x11];
b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
b1[0x12] = b2[0x12] + b2[0x13];
b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
b1[0x12] += b1[0x13];
b1[0x0C] = b2[0x0C] + b2[0x0D];
b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0;
b1[0x0E] = b2[0x0E] + b2[0x0F];
b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0;
b1[0x0E] += b1[0x0F];
b1[0x0C] += b1[0x0E];
b1[0x0E] += b1[0x0D];
b1[0x0D] += b1[0x0F];
b1[0x14] = b2[0x14] + b2[0x15];
b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
b1[0x16] = b2[0x16] + b2[0x17];
b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
b1[0x16] += b1[0x17];
b1[0x14] += b1[0x16];
b1[0x16] += b1[0x15];
b1[0x15] += b1[0x17];
b1[0x10] = b2[0x10] + b2[0x11];
b1[0x11] = (b2[0x10] - b2[0x11]) * cos0;
b1[0x12] = b2[0x12] + b2[0x13];
b1[0x13] = (b2[0x13] - b2[0x12]) * cos0;
b1[0x12] += b1[0x13];
b1[0x18] = b2[0x18] + b2[0x19];
b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
b1[0x1A] = b2[0x1A] + b2[0x1B];
b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
b1[0x1A] += b1[0x1B];
b1[0x14] = b2[0x14] + b2[0x15];
b1[0x15] = (b2[0x14] - b2[0x15]) * cos0;
b1[0x16] = b2[0x16] + b2[0x17];
b1[0x17] = (b2[0x17] - b2[0x16]) * cos0;
b1[0x16] += b1[0x17];
b1[0x14] += b1[0x16];
b1[0x16] += b1[0x15];
b1[0x15] += b1[0x17];
b1[0x1C] = b2[0x1C] + b2[0x1D];
b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
b1[0x1E] = b2[0x1E] + b2[0x1F];
b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
b1[0x1E] += b1[0x1F];
b1[0x1C] += b1[0x1E];
b1[0x1E] += b1[0x1D];
b1[0x1D] += b1[0x1F];
}
b1[0x18] = b2[0x18] + b2[0x19];
b1[0x19] = (b2[0x18] - b2[0x19]) * cos0;
b1[0x1A] = b2[0x1A] + b2[0x1B];
b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0;
b1[0x1A] += b1[0x1B];
out0[0x10*16] = b1[0x00];
out0[0x10*12] = b1[0x04];
out0[0x10* 8] = b1[0x02];
out0[0x10* 4] = b1[0x06];
out0[0x10* 0] = b1[0x01];
out1[0x10* 0] = b1[0x01];
out1[0x10* 4] = b1[0x05];
out1[0x10* 8] = b1[0x03];
out1[0x10*12] = b1[0x07];
b1[0x1C] = b2[0x1C] + b2[0x1D];
b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0;
b1[0x1E] = b2[0x1E] + b2[0x1F];
b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0;
b1[0x1E] += b1[0x1F];
b1[0x1C] += b1[0x1E];
b1[0x1E] += b1[0x1D];
b1[0x1D] += b1[0x1F];
}
out0[0x10 * 16] = b1[0x00];
out0[0x10 * 12] = b1[0x04];
out0[0x10 * 8] = b1[0x02];
out0[0x10 * 4] = b1[0x06];
out0[0x10 * 0] = b1[0x01];
out1[0x10 * 0] = b1[0x01];
out1[0x10 * 4] = b1[0x05];
out1[0x10 * 8] = b1[0x03];
out1[0x10 * 12] = b1[0x07];
#if 1
out0[0x10*14] = b1[0x08] + b1[0x0C];
out0[0x10*10] = b1[0x0C] + b1[0x0a];
out0[0x10* 6] = b1[0x0A] + b1[0x0E];
out0[0x10* 2] = b1[0x0E] + b1[0x09];
out1[0x10* 2] = b1[0x09] + b1[0x0D];
out1[0x10* 6] = b1[0x0D] + b1[0x0B];
out1[0x10*10] = b1[0x0B] + b1[0x0F];
out1[0x10*14] = b1[0x0F];
out0[0x10 * 14] = b1[0x08] + b1[0x0C];
out0[0x10 * 10] = b1[0x0C] + b1[0x0a];
out0[0x10 * 6] = b1[0x0A] + b1[0x0E];
out0[0x10 * 2] = b1[0x0E] + b1[0x09];
out1[0x10 * 2] = b1[0x09] + b1[0x0D];
out1[0x10 * 6] = b1[0x0D] + b1[0x0B];
out1[0x10 * 10] = b1[0x0B] + b1[0x0F];
out1[0x10 * 14] = b1[0x0F];
#else
b1[0x08] += b1[0x0C];
out0[0x10*14] = b1[0x08];
b1[0x0C] += b1[0x0a];
out0[0x10*10] = b1[0x0C];
b1[0x0A] += b1[0x0E];
out0[0x10* 6] = b1[0x0A];
b1[0x0E] += b1[0x09];
out0[0x10* 2] = b1[0x0E];
b1[0x09] += b1[0x0D];
out1[0x10* 2] = b1[0x09];
b1[0x0D] += b1[0x0B];
out1[0x10* 6] = b1[0x0D];
b1[0x0B] += b1[0x0F];
out1[0x10*10] = b1[0x0B];
out1[0x10*14] = b1[0x0F];
b1[0x08] += b1[0x0C];
out0[0x10 * 14] = b1[0x08];
b1[0x0C] += b1[0x0a];
out0[0x10 * 10] = b1[0x0C];
b1[0x0A] += b1[0x0E];
out0[0x10 * 6] = b1[0x0A];
b1[0x0E] += b1[0x09];
out0[0x10 * 2] = b1[0x0E];
b1[0x09] += b1[0x0D];
out1[0x10 * 2] = b1[0x09];
b1[0x0D] += b1[0x0B];
out1[0x10 * 6] = b1[0x0D];
b1[0x0B] += b1[0x0F];
out1[0x10 * 10] = b1[0x0B];
out1[0x10 * 14] = b1[0x0F];
#endif
{
real tmp;
tmp = b1[0x18] + b1[0x1C];
out0[0x10*15] = tmp + b1[0x10];
out0[0x10*13] = tmp + b1[0x14];
tmp = b1[0x1C] + b1[0x1A];
out0[0x10*11] = tmp + b1[0x14];
out0[0x10* 9] = tmp + b1[0x12];
tmp = b1[0x1A] + b1[0x1E];
out0[0x10* 7] = tmp + b1[0x12];
out0[0x10* 5] = tmp + b1[0x16];
tmp = b1[0x1E] + b1[0x19];
out0[0x10* 3] = tmp + b1[0x16];
out0[0x10* 1] = tmp + b1[0x11];
tmp = b1[0x19] + b1[0x1D];
out1[0x10* 1] = tmp + b1[0x11];
out1[0x10* 3] = tmp + b1[0x15];
tmp = b1[0x1D] + b1[0x1B];
out1[0x10* 5] = tmp + b1[0x15];
out1[0x10* 7] = tmp + b1[0x13];
tmp = b1[0x1B] + b1[0x1F];
out1[0x10* 9] = tmp + b1[0x13];
out1[0x10*11] = tmp + b1[0x17];
out1[0x10*13] = b1[0x17] + b1[0x1F];
out1[0x10*15] = b1[0x1F];
}
{
real tmp;
tmp = b1[0x18] + b1[0x1C];
out0[0x10 * 15] = tmp + b1[0x10];
out0[0x10 * 13] = tmp + b1[0x14];
tmp = b1[0x1C] + b1[0x1A];
out0[0x10 * 11] = tmp + b1[0x14];
out0[0x10 * 9] = tmp + b1[0x12];
tmp = b1[0x1A] + b1[0x1E];
out0[0x10 * 7] = tmp + b1[0x12];
out0[0x10 * 5] = tmp + b1[0x16];
tmp = b1[0x1E] + b1[0x19];
out0[0x10 * 3] = tmp + b1[0x16];
out0[0x10 * 1] = tmp + b1[0x11];
tmp = b1[0x19] + b1[0x1D];
out1[0x10 * 1] = tmp + b1[0x11];
out1[0x10 * 3] = tmp + b1[0x15];
tmp = b1[0x1D] + b1[0x1B];
out1[0x10 * 5] = tmp + b1[0x15];
out1[0x10 * 7] = tmp + b1[0x13];
tmp = b1[0x1B] + b1[0x1F];
out1[0x10 * 9] = tmp + b1[0x13];
out1[0x10 * 11] = tmp + b1[0x17];
out1[0x10 * 13] = b1[0x17] + b1[0x1F];
out1[0x10 * 15] = b1[0x1F];
}
}
/*
* the call via dct64 is a trick to force GCC to use
* (new) registers for the b1,b2 pointer to the bufs[xx] field
*/
void dct64(real *a,real *b,real *c)
void dct64(real * a, real * b, real * c)
{
real bufs[0x40];
dct64_1(a,b,bufs,bufs+0x20,c);
real bufs[0x40];
dct64_1(a, b, bufs, bufs + 0x20, c);
}
+101 -106
View File
@@ -25,129 +25,124 @@
else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
else { *(samples) = sum; }
int synth_1to1_mono(struct mpstr *mp,real *bandPtr,unsigned char *samples,int *pnt)
int synth_1to1_mono(struct mpstr *mp, real * bandPtr, unsigned char *samples, int *pnt)
{
short samples_tmp[64];
short *tmp1 = samples_tmp;
int i,ret;
int pnt1 = 0;
short samples_tmp[64];
short *tmp1 = samples_tmp;
int i, ret;
int pnt1 = 0;
ret = synth_1to1(mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
samples += *pnt;
ret = synth_1to1(mp, bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
samples += *pnt;
for(i=0;i<32;i++) {
*( (short *) samples) = *tmp1;
samples += 2;
tmp1 += 2;
}
*pnt += 64;
for (i = 0; i < 32; i++) {
*((short *) samples) = *tmp1;
samples += 2;
tmp1 += 2;
}
*pnt += 64;
return ret;
return ret;
}
int synth_1to1(struct mpstr *mp, real *bandPtr,int channel,unsigned char *out,int *pnt)
int synth_1to1(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
{
static const int step = 2;
int bo;
short *samples = (short *) (out + *pnt);
static const int step = 2;
int bo;
short *samples = (short *) (out + *pnt);
real *b0,(*buf)[0x110];
int clip = 0;
int bo1;
real *b0, (*buf)[0x110];
int clip = 0;
int bo1;
bo = mp->synth_bo;
bo = mp->synth_bo;
if(!channel) {
bo--;
bo &= 0xf;
buf = mp->synth_buffs[0];
}
else {
samples++;
buf = mp->synth_buffs[1];
}
if (!channel) {
bo--;
bo &= 0xf;
buf = mp->synth_buffs[0];
} else {
samples++;
buf = mp->synth_buffs[1];
}
if(bo & 0x1) {
b0 = buf[0];
bo1 = bo;
dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
}
else {
b0 = buf[1];
bo1 = bo+1;
dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
}
if (bo & 0x1) {
b0 = buf[0];
bo1 = bo;
dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr);
} else {
b0 = buf[1];
bo1 = bo + 1;
dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr);
}
mp->synth_bo = bo;
{
register int j;
real *window = decwin + 16 - bo1;
mp->synth_bo = bo;
for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
{
real sum;
sum = window[0x0] * b0[0x0];
sum -= window[0x1] * b0[0x1];
sum += window[0x2] * b0[0x2];
sum -= window[0x3] * b0[0x3];
sum += window[0x4] * b0[0x4];
sum -= window[0x5] * b0[0x5];
sum += window[0x6] * b0[0x6];
sum -= window[0x7] * b0[0x7];
sum += window[0x8] * b0[0x8];
sum -= window[0x9] * b0[0x9];
sum += window[0xA] * b0[0xA];
sum -= window[0xB] * b0[0xB];
sum += window[0xC] * b0[0xC];
sum -= window[0xD] * b0[0xD];
sum += window[0xE] * b0[0xE];
sum -= window[0xF] * b0[0xF];
{
register int j;
real *window = decwin + 16 - bo1;
WRITE_SAMPLE(samples,sum,clip);
}
for (j = 16; j; j--, b0 += 0x10, window += 0x20, samples += step) {
real sum;
sum = window[0x0] * b0[0x0];
sum -= window[0x1] * b0[0x1];
sum += window[0x2] * b0[0x2];
sum -= window[0x3] * b0[0x3];
sum += window[0x4] * b0[0x4];
sum -= window[0x5] * b0[0x5];
sum += window[0x6] * b0[0x6];
sum -= window[0x7] * b0[0x7];
sum += window[0x8] * b0[0x8];
sum -= window[0x9] * b0[0x9];
sum += window[0xA] * b0[0xA];
sum -= window[0xB] * b0[0xB];
sum += window[0xC] * b0[0xC];
sum -= window[0xD] * b0[0xD];
sum += window[0xE] * b0[0xE];
sum -= window[0xF] * b0[0xF];
{
real sum;
sum = window[0x0] * b0[0x0];
sum += window[0x2] * b0[0x2];
sum += window[0x4] * b0[0x4];
sum += window[0x6] * b0[0x6];
sum += window[0x8] * b0[0x8];
sum += window[0xA] * b0[0xA];
sum += window[0xC] * b0[0xC];
sum += window[0xE] * b0[0xE];
WRITE_SAMPLE(samples,sum,clip);
b0-=0x10,window-=0x20,samples+=step;
}
window += bo1<<1;
WRITE_SAMPLE(samples, sum, clip);
}
for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
{
real sum;
sum = -window[-0x1] * b0[0x0];
sum -= window[-0x2] * b0[0x1];
sum -= window[-0x3] * b0[0x2];
sum -= window[-0x4] * b0[0x3];
sum -= window[-0x5] * b0[0x4];
sum -= window[-0x6] * b0[0x5];
sum -= window[-0x7] * b0[0x6];
sum -= window[-0x8] * b0[0x7];
sum -= window[-0x9] * b0[0x8];
sum -= window[-0xA] * b0[0x9];
sum -= window[-0xB] * b0[0xA];
sum -= window[-0xC] * b0[0xB];
sum -= window[-0xD] * b0[0xC];
sum -= window[-0xE] * b0[0xD];
sum -= window[-0xF] * b0[0xE];
sum -= window[-0x0] * b0[0xF];
{
real sum;
sum = window[0x0] * b0[0x0];
sum += window[0x2] * b0[0x2];
sum += window[0x4] * b0[0x4];
sum += window[0x6] * b0[0x6];
sum += window[0x8] * b0[0x8];
sum += window[0xA] * b0[0xA];
sum += window[0xC] * b0[0xC];
sum += window[0xE] * b0[0xE];
WRITE_SAMPLE(samples, sum, clip);
b0 -= 0x10, window -= 0x20, samples += step;
}
window += bo1 << 1;
WRITE_SAMPLE(samples,sum,clip);
}
}
*pnt += 128;
for (j = 15; j; j--, b0 -= 0x10, window -= 0x20, samples += step) {
real sum;
sum = -window[-0x1] * b0[0x0];
sum -= window[-0x2] * b0[0x1];
sum -= window[-0x3] * b0[0x2];
sum -= window[-0x4] * b0[0x3];
sum -= window[-0x5] * b0[0x4];
sum -= window[-0x6] * b0[0x5];
sum -= window[-0x7] * b0[0x6];
sum -= window[-0x8] * b0[0x7];
sum -= window[-0x9] * b0[0x8];
sum -= window[-0xA] * b0[0x9];
sum -= window[-0xB] * b0[0xA];
sum -= window[-0xC] * b0[0xB];
sum -= window[-0xD] * b0[0xC];
sum -= window[-0xE] * b0[0xD];
sum -= window[-0xF] * b0[0xE];
sum -= window[-0x0] * b0[0xF];
return clip;
WRITE_SAMPLE(samples, sum, clip);
}
}
*pnt += 128;
return clip;
}
+143 -150
View File
@@ -21,198 +21,191 @@
else { *(samples) = sum; }
#define NTOM_MUL (32768)
static unsigned long ntom_val[2] = { NTOM_MUL>>1,NTOM_MUL>>1 };
static unsigned long ntom_val[2] = { NTOM_MUL >> 1, NTOM_MUL >> 1 };
static unsigned long ntom_step = NTOM_MUL;
int synth_ntom_set_step(long m,long n)
int synth_ntom_set_step(long m, long n)
{
if(param.verbose > 1)
debug_printf("Init rate converter: %ld->%ld\n",m,n);
if (param.verbose > 1)
debug_printf("Init rate converter: %ld->%ld\n", m, n);
if(n >= 96000 || m >= 96000 || m == 0 || n == 0) {
debug_printf("NtoM converter: %d illegal rates\n", __LINE__);
if (n >= 96000 || m >= 96000 || m == 0 || n == 0) {
debug_printf("NtoM converter: %d illegal rates\n", __LINE__);
return (1);
}
n *= NTOM_MUL;
ntom_step = n / m;
if(ntom_step > 8*NTOM_MUL) {
debug_printf("%d max. 1:8 conversion allowed!\n", __LINE__);
if (ntom_step > 8 * NTOM_MUL) {
debug_printf("%d max. 1:8 conversion allowed!\n", __LINE__);
return (1);
}
ntom_val[0] = ntom_val[1] = NTOM_MUL>>1;
ntom_val[0] = ntom_val[1] = NTOM_MUL >> 1;
return (0);
}
int synth_ntom_mono (struct mpstr *mp, real *bandPtr,unsigned char *samples,int *pnt)
int synth_ntom_mono(struct mpstr *mp, real * bandPtr, unsigned char *samples, int *pnt)
{
short samples_tmp[8*64];
short *tmp1 = samples_tmp;
int i,ret;
int pnt1 = 0;
short samples_tmp[8 * 64];
short *tmp1 = samples_tmp;
int i, ret;
int pnt1 = 0;
ret = synth_ntom(mp, bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
samples += *pnt;
ret = synth_ntom(mp, bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
samples += *pnt;
for(i=0;i<(pnt1>>2);i++) {
*( (short *)samples) = *tmp1;
samples += 2;
tmp1 += 2;
}
*pnt += pnt1 >> 1;
for (i = 0; i < (pnt1 >> 2); i++) {
*((short *) samples) = *tmp1;
samples += 2;
tmp1 += 2;
}
*pnt += pnt1 >> 1;
return ret;
return ret;
}
int synth_ntom(struct mpstr *mp, real *bandPtr,int channel,unsigned char *out,int *pnt)
int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
{
static const int step = 2;
int bo;
short *samples = (short *) (out + *pnt);
static const int step = 2;
int bo;
short *samples = (short *) (out + *pnt);
real *b0,(*buf)[0x110];
int clip = 0;
int bo1;
int ntom;
real *b0, (*buf)[0x110];
int clip = 0;
int bo1;
int ntom;
bo = mp->synth_bo;
if(!channel) {
bo--;
bo &= 0xf;
buf = mp->synth_buffs[0];
ntom = ntom_val[1] = ntom_val[0];
}
else {
samples++;
out += 2; /* to compute the right *pnt value */
buf = mp->synth_buffs[1];
ntom = ntom_val[1];
}
bo = mp->synth_bo;
if(bo & 0x1) {
b0 = buf[0];
bo1 = bo;
dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
}
else {
b0 = buf[1];
bo1 = bo+1;
dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
}
if (!channel) {
bo--;
bo &= 0xf;
buf = mp->synth_buffs[0];
ntom = ntom_val[1] = ntom_val[0];
} else {
samples++;
out += 2; /* to compute the right *pnt value */
buf = mp->synth_buffs[1];
ntom = ntom_val[1];
}
mp->synth_bo = bo;
{
register int j;
real *window = (mp->decwin) + 16 - bo1;
for (j=16;j;j--,window+=0x10)
{
real sum;
if (bo & 0x1) {
b0 = buf[0];
bo1 = bo;
dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr);
} else {
b0 = buf[1];
bo1 = bo + 1;
dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr);
}
ntom += ntom_step;
if(ntom < NTOM_MUL) {
window += 16;
b0 += 16;
continue;
}
mp->synth_bo = bo;
sum = *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
{
register int j;
real *window = (mp->decwin) + 16 - bo1;
while(ntom >= NTOM_MUL) {
WRITE_SAMPLE(samples,sum,clip);
samples += step;
ntom -= NTOM_MUL;
}
}
for (j = 16; j; j--, window += 0x10) {
real sum;
ntom += ntom_step;
if(ntom >= NTOM_MUL)
{
real sum;
sum = window[0x0] * b0[0x0];
sum += window[0x2] * b0[0x2];
sum += window[0x4] * b0[0x4];
sum += window[0x6] * b0[0x6];
sum += window[0x8] * b0[0x8];
sum += window[0xA] * b0[0xA];
sum += window[0xC] * b0[0xC];
sum += window[0xE] * b0[0xE];
ntom += ntom_step;
if (ntom < NTOM_MUL) {
window += 16;
b0 += 16;
continue;
}
while(ntom >= NTOM_MUL) {
WRITE_SAMPLE(samples,sum,clip);
samples += step;
ntom -= NTOM_MUL;
}
}
sum = *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
sum += *window++ * *b0++;
sum -= *window++ * *b0++;
b0-=0x10,window-=0x20;
window += bo1<<1;
while (ntom >= NTOM_MUL) {
WRITE_SAMPLE(samples, sum, clip);
samples += step;
ntom -= NTOM_MUL;
}
}
for (j=15;j;j--,b0-=0x20,window-=0x10)
{
real sum;
ntom += ntom_step;
if (ntom >= NTOM_MUL) {
real sum;
sum = window[0x0] * b0[0x0];
sum += window[0x2] * b0[0x2];
sum += window[0x4] * b0[0x4];
sum += window[0x6] * b0[0x6];
sum += window[0x8] * b0[0x8];
sum += window[0xA] * b0[0xA];
sum += window[0xC] * b0[0xC];
sum += window[0xE] * b0[0xE];
ntom += ntom_step;
if(ntom < NTOM_MUL) {
window -= 16;
b0 += 16;
continue;
}
while (ntom >= NTOM_MUL) {
WRITE_SAMPLE(samples, sum, clip);
samples += step;
ntom -= NTOM_MUL;
}
}
sum = -*(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
b0 -= 0x10, window -= 0x20;
window += bo1 << 1;
while(ntom >= NTOM_MUL) {
WRITE_SAMPLE(samples,sum,clip);
samples += step;
ntom -= NTOM_MUL;
}
}
}
for (j = 15; j; j--, b0 -= 0x20, window -= 0x10) {
real sum;
ntom_val[channel] = ntom;
*pnt = ((unsigned char *) samples - out);
ntom += ntom_step;
if (ntom < NTOM_MUL) {
window -= 16;
b0 += 16;
continue;
}
return clip;
sum = -*(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
sum -= *(--window) * *b0++;
while (ntom >= NTOM_MUL) {
WRITE_SAMPLE(samples, sum, clip);
samples += step;
ntom -= NTOM_MUL;
}
}
}
ntom_val[channel] = ntom;
*pnt = ((unsigned char *) samples - out);
return clip;
}
+257 -280
View File
@@ -6,327 +6,304 @@
* smaller tables are often the part of a bigger table
*/
struct newhuff
{
unsigned int linbits;
short *table;
struct newhuff {
unsigned int linbits;
short *table;
};
static short tab0[] =
{
0
static short tab0[] = {
0
};
static short tab1[] =
{
-5, -3, -1, 17, 1, 16, 0
static short tab1[] = {
-5, -3, -1, 17, 1, 16, 0
};
static short tab2[] =
{
-15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1,
16, 0
static short tab2[] = {
-15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1,
16, 0
};
static short tab3[] =
{
-13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1,
1, 0
static short tab3[] = {
-13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1,
1, 0
};
static short tab5[] =
{
-29, -25, -23, -15, -7, -5, -3, -1, 51, 35, 50, 49, -3, -1, 19,
3, -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, 17, -1, 1, 16,
0
static short tab5[] = {
-29, -25, -23, -15, -7, -5, -3, -1, 51, 35, 50, 49, -3, -1, 19,
3, -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, 17, -1, 1, 16,
0
};
static short tab6[] =
{
-25, -19, -13, -9, -5, -3, -1, 51, 3, 35, -1, 50, 48, -1, 19,
49, -3, -1, 34, 2, 18, -3, -1, 33, 32, 1, -1, 17, -1, 16,
0
static short tab6[] = {
-25, -19, -13, -9, -5, -3, -1, 51, 3, 35, -1, 50, 48, -1, 19,
49, -3, -1, 34, 2, 18, -3, -1, 33, 32, 1, -1, 17, -1, 16,
0
};
static short tab7[] =
{
-69, -65, -57, -39, -29, -17, -11, -7, -3, -1, 85, 69, -1, 84, 83,
-1, 53, 68, -3, -1, 37, 82, 21, -5, -1, 81, -1, 5, 52, -1,
80, -1, 67, 51, -5, -3, -1, 36, 66, 20, -1, 65, 64, -11, -7,
-3, -1, 4, 35, -1, 50, 3, -1, 19, 49, -3, -1, 48, 34, 18,
-5, -1, 33, -1, 2, 32, 17, -1, 1, 16, 0
static short tab7[] = {
-69, -65, -57, -39, -29, -17, -11, -7, -3, -1, 85, 69, -1, 84, 83,
-1, 53, 68, -3, -1, 37, 82, 21, -5, -1, 81, -1, 5, 52, -1,
80, -1, 67, 51, -5, -3, -1, 36, 66, 20, -1, 65, 64, -11, -7,
-3, -1, 4, 35, -1, 50, 3, -1, 19, 49, -3, -1, 48, 34, 18,
-5, -1, 33, -1, 2, 32, 17, -1, 1, 16, 0
};
static short tab8[] =
{
-65, -63, -59, -45, -31, -19, -13, -7, -5, -3, -1, 85, 84, 69, 83,
-3, -1, 53, 68, 37, -3, -1, 82, 5, 21, -5, -1, 81, -1, 52,
67, -3, -1, 80, 51, 36, -5, -3, -1, 66, 20, 65, -3, -1, 4,
64, -1, 35, 50, -9, -7, -3, -1, 19, 49, -1, 3, 48, 34, -1,
2, 32, -1, 18, 33, 17, -3, -1, 1, 16, 0
static short tab8[] = {
-65, -63, -59, -45, -31, -19, -13, -7, -5, -3, -1, 85, 84, 69, 83,
-3, -1, 53, 68, 37, -3, -1, 82, 5, 21, -5, -1, 81, -1, 52,
67, -3, -1, 80, 51, 36, -5, -3, -1, 66, 20, 65, -3, -1, 4,
64, -1, 35, 50, -9, -7, -3, -1, 19, 49, -1, 3, 48, 34, -1,
2, 32, -1, 18, 33, 17, -3, -1, 1, 16, 0
};
static short tab9[] =
{
-63, -53, -41, -29, -19, -11, -5, -3, -1, 85, 69, 53, -1, 83, -1,
84, 5, -3, -1, 68, 37, -1, 82, 21, -3, -1, 81, 52, -1, 67,
-1, 80, 4, -7, -3, -1, 36, 66, -1, 51, 64, -1, 20, 65, -5,
-3, -1, 35, 50, 19, -1, 49, -1, 3, 48, -5, -3, -1, 34, 2,
18, -1, 33, 32, -3, -1, 17, 1, -1, 16, 0
static short tab9[] = {
-63, -53, -41, -29, -19, -11, -5, -3, -1, 85, 69, 53, -1, 83, -1,
84, 5, -3, -1, 68, 37, -1, 82, 21, -3, -1, 81, 52, -1, 67,
-1, 80, 4, -7, -3, -1, 36, 66, -1, 51, 64, -1, 20, 65, -5,
-3, -1, 35, 50, 19, -1, 49, -1, 3, 48, -5, -3, -1, 34, 2,
18, -1, 33, 32, -3, -1, 17, 1, -1, 16, 0
};
static short tab10[] =
{
-125,-121,-111, -83, -55, -35, -21, -13, -7, -3, -1, 119, 103, -1, 118,
87, -3, -1, 117, 102, 71, -3, -1, 116, 86, -1, 101, 55, -9, -3,
-1, 115, 70, -3, -1, 85, 84, 99, -1, 39, 114, -11, -5, -3, -1,
100, 7, 112, -1, 98, -1, 69, 53, -5, -1, 6, -1, 83, 68, 23,
-17, -5, -1, 113, -1, 54, 38, -5, -3, -1, 37, 82, 21, -1, 81,
-1, 52, 67, -3, -1, 22, 97, -1, 96, -1, 5, 80, -19, -11, -7,
-3, -1, 36, 66, -1, 51, 4, -1, 20, 65, -3, -1, 64, 35, -1,
50, 3, -3, -1, 19, 49, -1, 48, 34, -7, -3, -1, 18, 33, -1,
2, 32, 17, -1, 1, 16, 0
static short tab10[] = {
-125, -121, -111, -83, -55, -35, -21, -13, -7, -3, -1, 119, 103, -1, 118,
87, -3, -1, 117, 102, 71, -3, -1, 116, 86, -1, 101, 55, -9, -3,
-1, 115, 70, -3, -1, 85, 84, 99, -1, 39, 114, -11, -5, -3, -1,
100, 7, 112, -1, 98, -1, 69, 53, -5, -1, 6, -1, 83, 68, 23,
-17, -5, -1, 113, -1, 54, 38, -5, -3, -1, 37, 82, 21, -1, 81,
-1, 52, 67, -3, -1, 22, 97, -1, 96, -1, 5, 80, -19, -11, -7,
-3, -1, 36, 66, -1, 51, 4, -1, 20, 65, -3, -1, 64, 35, -1,
50, 3, -3, -1, 19, 49, -1, 48, 34, -7, -3, -1, 18, 33, -1,
2, 32, 17, -1, 1, 16, 0
};
static short tab11[] =
{
-121,-113, -89, -59, -43, -27, -17, -7, -3, -1, 119, 103, -1, 118, 117,
-3, -1, 102, 71, -1, 116, -1, 87, 85, -5, -3, -1, 86, 101, 55,
-1, 115, 70, -9, -7, -3, -1, 69, 84, -1, 53, 83, 39, -1, 114,
-1, 100, 7, -5, -1, 113, -1, 23, 112, -3, -1, 54, 99, -1, 96,
-1, 68, 37, -13, -7, -5, -3, -1, 82, 5, 21, 98, -3, -1, 38,
6, 22, -5, -1, 97, -1, 81, 52, -5, -1, 80, -1, 67, 51, -1,
36, 66, -15, -11, -7, -3, -1, 20, 65, -1, 4, 64, -1, 35, 50,
-1, 19, 49, -5, -3, -1, 3, 48, 34, 33, -5, -1, 18, -1, 2,
32, 17, -3, -1, 1, 16, 0
static short tab11[] = {
-121, -113, -89, -59, -43, -27, -17, -7, -3, -1, 119, 103, -1, 118, 117,
-3, -1, 102, 71, -1, 116, -1, 87, 85, -5, -3, -1, 86, 101, 55,
-1, 115, 70, -9, -7, -3, -1, 69, 84, -1, 53, 83, 39, -1, 114,
-1, 100, 7, -5, -1, 113, -1, 23, 112, -3, -1, 54, 99, -1, 96,
-1, 68, 37, -13, -7, -5, -3, -1, 82, 5, 21, 98, -3, -1, 38,
6, 22, -5, -1, 97, -1, 81, 52, -5, -1, 80, -1, 67, 51, -1,
36, 66, -15, -11, -7, -3, -1, 20, 65, -1, 4, 64, -1, 35, 50,
-1, 19, 49, -5, -3, -1, 3, 48, 34, 33, -5, -1, 18, -1, 2,
32, 17, -3, -1, 1, 16, 0
};
static short tab12[] =
{
-115, -99, -73, -45, -27, -17, -9, -5, -3, -1, 119, 103, 118, -1, 87,
117, -3, -1, 102, 71, -1, 116, 101, -3, -1, 86, 55, -3, -1, 115,
85, 39, -7, -3, -1, 114, 70, -1, 100, 23, -5, -1, 113, -1, 7,
112, -1, 54, 99, -13, -9, -3, -1, 69, 84, -1, 68, -1, 6, 5,
-1, 38, 98, -5, -1, 97, -1, 22, 96, -3, -1, 53, 83, -1, 37,
82, -17, -7, -3, -1, 21, 81, -1, 52, 67, -5, -3, -1, 80, 4,
36, -1, 66, 20, -3, -1, 51, 65, -1, 35, 50, -11, -7, -5, -3,
-1, 64, 3, 48, 19, -1, 49, 34, -1, 18, 33, -7, -5, -3, -1,
2, 32, 0, 17, -1, 1, 16
static short tab12[] = {
-115, -99, -73, -45, -27, -17, -9, -5, -3, -1, 119, 103, 118, -1, 87,
117, -3, -1, 102, 71, -1, 116, 101, -3, -1, 86, 55, -3, -1, 115,
85, 39, -7, -3, -1, 114, 70, -1, 100, 23, -5, -1, 113, -1, 7,
112, -1, 54, 99, -13, -9, -3, -1, 69, 84, -1, 68, -1, 6, 5,
-1, 38, 98, -5, -1, 97, -1, 22, 96, -3, -1, 53, 83, -1, 37,
82, -17, -7, -3, -1, 21, 81, -1, 52, 67, -5, -3, -1, 80, 4,
36, -1, 66, 20, -3, -1, 51, 65, -1, 35, 50, -11, -7, -5, -3,
-1, 64, 3, 48, 19, -1, 49, 34, -1, 18, 33, -7, -5, -3, -1,
2, 32, 0, 17, -1, 1, 16
};
static short tab13[] =
{
-509,-503,-475,-405,-333,-265,-205,-153,-115, -83, -53, -35, -21, -13, -9,
-7, -5, -3, -1, 254, 252, 253, 237, 255, -1, 239, 223, -3, -1, 238,
207, -1, 222, 191, -9, -3, -1, 251, 206, -1, 220, -1, 175, 233, -1,
236, 221, -9, -5, -3, -1, 250, 205, 190, -1, 235, 159, -3, -1, 249,
234, -1, 189, 219, -17, -9, -3, -1, 143, 248, -1, 204, -1, 174, 158,
-5, -1, 142, -1, 127, 126, 247, -5, -1, 218, -1, 173, 188, -3, -1,
203, 246, 111, -15, -7, -3, -1, 232, 95, -1, 157, 217, -3, -1, 245,
231, -1, 172, 187, -9, -3, -1, 79, 244, -3, -1, 202, 230, 243, -1,
63, -1, 141, 216, -21, -9, -3, -1, 47, 242, -3, -1, 110, 156, 15,
-5, -3, -1, 201, 94, 171, -3, -1, 125, 215, 78, -11, -5, -3, -1,
200, 214, 62, -1, 185, -1, 155, 170, -1, 31, 241, -23, -13, -5, -1,
240, -1, 186, 229, -3, -1, 228, 140, -1, 109, 227, -5, -1, 226, -1,
46, 14, -1, 30, 225, -15, -7, -3, -1, 224, 93, -1, 213, 124, -3,
-1, 199, 77, -1, 139, 184, -7, -3, -1, 212, 154, -1, 169, 108, -1,
198, 61, -37, -21, -9, -5, -3, -1, 211, 123, 45, -1, 210, 29, -5,
-1, 183, -1, 92, 197, -3, -1, 153, 122, 195, -7, -5, -3, -1, 167,
151, 75, 209, -3, -1, 13, 208, -1, 138, 168, -11, -7, -3, -1, 76,
196, -1, 107, 182, -1, 60, 44, -3, -1, 194, 91, -3, -1, 181, 137,
28, -43, -23, -11, -5, -1, 193, -1, 152, 12, -1, 192, -1, 180, 106,
-5, -3, -1, 166, 121, 59, -1, 179, -1, 136, 90, -11, -5, -1, 43,
-1, 165, 105, -1, 164, -1, 120, 135, -5, -1, 148, -1, 119, 118, 178,
-11, -3, -1, 27, 177, -3, -1, 11, 176, -1, 150, 74, -7, -3, -1,
58, 163, -1, 89, 149, -1, 42, 162, -47, -23, -9, -3, -1, 26, 161,
-3, -1, 10, 104, 160, -5, -3, -1, 134, 73, 147, -3, -1, 57, 88,
-1, 133, 103, -9, -3, -1, 41, 146, -3, -1, 87, 117, 56, -5, -1,
131, -1, 102, 71, -3, -1, 116, 86, -1, 101, 115, -11, -3, -1, 25,
145, -3, -1, 9, 144, -1, 72, 132, -7, -5, -1, 114, -1, 70, 100,
40, -1, 130, 24, -41, -27, -11, -5, -3, -1, 55, 39, 23, -1, 113,
-1, 85, 7, -7, -3, -1, 112, 54, -1, 99, 69, -3, -1, 84, 38,
-1, 98, 53, -5, -1, 129, -1, 8, 128, -3, -1, 22, 97, -1, 6,
96, -13, -9, -5, -3, -1, 83, 68, 37, -1, 82, 5, -1, 21, 81,
-7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, -19, -11,
-5, -1, 65, -1, 4, 64, -3, -1, 35, 50, 19, -3, -1, 49, 3,
-1, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
0
static short tab13[] = {
-509, -503, -475, -405, -333, -265, -205, -153, -115, -83, -53, -35, -21, -13, -9,
-7, -5, -3, -1, 254, 252, 253, 237, 255, -1, 239, 223, -3, -1, 238,
207, -1, 222, 191, -9, -3, -1, 251, 206, -1, 220, -1, 175, 233, -1,
236, 221, -9, -5, -3, -1, 250, 205, 190, -1, 235, 159, -3, -1, 249,
234, -1, 189, 219, -17, -9, -3, -1, 143, 248, -1, 204, -1, 174, 158,
-5, -1, 142, -1, 127, 126, 247, -5, -1, 218, -1, 173, 188, -3, -1,
203, 246, 111, -15, -7, -3, -1, 232, 95, -1, 157, 217, -3, -1, 245,
231, -1, 172, 187, -9, -3, -1, 79, 244, -3, -1, 202, 230, 243, -1,
63, -1, 141, 216, -21, -9, -3, -1, 47, 242, -3, -1, 110, 156, 15,
-5, -3, -1, 201, 94, 171, -3, -1, 125, 215, 78, -11, -5, -3, -1,
200, 214, 62, -1, 185, -1, 155, 170, -1, 31, 241, -23, -13, -5, -1,
240, -1, 186, 229, -3, -1, 228, 140, -1, 109, 227, -5, -1, 226, -1,
46, 14, -1, 30, 225, -15, -7, -3, -1, 224, 93, -1, 213, 124, -3,
-1, 199, 77, -1, 139, 184, -7, -3, -1, 212, 154, -1, 169, 108, -1,
198, 61, -37, -21, -9, -5, -3, -1, 211, 123, 45, -1, 210, 29, -5,
-1, 183, -1, 92, 197, -3, -1, 153, 122, 195, -7, -5, -3, -1, 167,
151, 75, 209, -3, -1, 13, 208, -1, 138, 168, -11, -7, -3, -1, 76,
196, -1, 107, 182, -1, 60, 44, -3, -1, 194, 91, -3, -1, 181, 137,
28, -43, -23, -11, -5, -1, 193, -1, 152, 12, -1, 192, -1, 180, 106,
-5, -3, -1, 166, 121, 59, -1, 179, -1, 136, 90, -11, -5, -1, 43,
-1, 165, 105, -1, 164, -1, 120, 135, -5, -1, 148, -1, 119, 118, 178,
-11, -3, -1, 27, 177, -3, -1, 11, 176, -1, 150, 74, -7, -3, -1,
58, 163, -1, 89, 149, -1, 42, 162, -47, -23, -9, -3, -1, 26, 161,
-3, -1, 10, 104, 160, -5, -3, -1, 134, 73, 147, -3, -1, 57, 88,
-1, 133, 103, -9, -3, -1, 41, 146, -3, -1, 87, 117, 56, -5, -1,
131, -1, 102, 71, -3, -1, 116, 86, -1, 101, 115, -11, -3, -1, 25,
145, -3, -1, 9, 144, -1, 72, 132, -7, -5, -1, 114, -1, 70, 100,
40, -1, 130, 24, -41, -27, -11, -5, -3, -1, 55, 39, 23, -1, 113,
-1, 85, 7, -7, -3, -1, 112, 54, -1, 99, 69, -3, -1, 84, 38,
-1, 98, 53, -5, -1, 129, -1, 8, 128, -3, -1, 22, 97, -1, 6,
96, -13, -9, -5, -3, -1, 83, 68, 37, -1, 82, 5, -1, 21, 81,
-7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, -19, -11,
-5, -1, 65, -1, 4, 64, -3, -1, 35, 50, 19, -3, -1, 49, 3,
-1, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
0
};
static short tab15[] =
{
-495,-445,-355,-263,-183,-115, -77, -43, -27, -13, -7, -3, -1, 255, 239,
-1, 254, 223, -1, 238, -1, 253, 207, -7, -3, -1, 252, 222, -1, 237,
191, -1, 251, -1, 206, 236, -7, -3, -1, 221, 175, -1, 250, 190, -3,
-1, 235, 205, -1, 220, 159, -15, -7, -3, -1, 249, 234, -1, 189, 219,
-3, -1, 143, 248, -1, 204, 158, -7, -3, -1, 233, 127, -1, 247, 173,
-3, -1, 218, 188, -1, 111, -1, 174, 15, -19, -11, -3, -1, 203, 246,
-3, -1, 142, 232, -1, 95, 157, -3, -1, 245, 126, -1, 231, 172, -9,
-3, -1, 202, 187, -3, -1, 217, 141, 79, -3, -1, 244, 63, -1, 243,
216, -33, -17, -9, -3, -1, 230, 47, -1, 242, -1, 110, 240, -3, -1,
31, 241, -1, 156, 201, -7, -3, -1, 94, 171, -1, 186, 229, -3, -1,
125, 215, -1, 78, 228, -15, -7, -3, -1, 140, 200, -1, 62, 109, -3,
-1, 214, 227, -1, 155, 185, -7, -3, -1, 46, 170, -1, 226, 30, -5,
-1, 225, -1, 14, 224, -1, 93, 213, -45, -25, -13, -7, -3, -1, 124,
199, -1, 77, 139, -1, 212, -1, 184, 154, -7, -3, -1, 169, 108, -1,
198, 61, -1, 211, 210, -9, -5, -3, -1, 45, 13, 29, -1, 123, 183,
-5, -1, 209, -1, 92, 208, -1, 197, 138, -17, -7, -3, -1, 168, 76,
-1, 196, 107, -5, -1, 182, -1, 153, 12, -1, 60, 195, -9, -3, -1,
122, 167, -1, 166, -1, 192, 11, -1, 194, -1, 44, 91, -55, -29, -15,
-7, -3, -1, 181, 28, -1, 137, 152, -3, -1, 193, 75, -1, 180, 106,
-5, -3, -1, 59, 121, 179, -3, -1, 151, 136, -1, 43, 90, -11, -5,
-1, 178, -1, 165, 27, -1, 177, -1, 176, 105, -7, -3, -1, 150, 74,
-1, 164, 120, -3, -1, 135, 58, 163, -17, -7, -3, -1, 89, 149, -1,
42, 162, -3, -1, 26, 161, -3, -1, 10, 160, 104, -7, -3, -1, 134,
73, -1, 148, 57, -5, -1, 147, -1, 119, 9, -1, 88, 133, -53, -29,
-13, -7, -3, -1, 41, 103, -1, 118, 146, -1, 145, -1, 25, 144, -7,
-3, -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 71, -7,
-3, -1, 40, 130, -1, 24, 129, -7, -3, -1, 116, 8, -1, 128, 86,
-3, -1, 101, 55, -1, 115, 70, -17, -7, -3, -1, 39, 114, -1, 100,
23, -3, -1, 85, 113, -3, -1, 7, 112, 54, -7, -3, -1, 99, 69,
-1, 84, 38, -3, -1, 98, 22, -3, -1, 6, 96, 53, -33, -19, -9,
-5, -1, 97, -1, 83, 68, -1, 37, 82, -3, -1, 21, 81, -3, -1,
5, 80, 52, -7, -3, -1, 67, 36, -1, 66, 51, -1, 65, -1, 20,
4, -9, -3, -1, 35, 50, -3, -1, 64, 3, 19, -3, -1, 49, 48,
34, -9, -7, -3, -1, 18, 33, -1, 2, 32, 17, -3, -1, 1, 16,
0
static short tab15[] = {
-495, -445, -355, -263, -183, -115, -77, -43, -27, -13, -7, -3, -1, 255, 239,
-1, 254, 223, -1, 238, -1, 253, 207, -7, -3, -1, 252, 222, -1, 237,
191, -1, 251, -1, 206, 236, -7, -3, -1, 221, 175, -1, 250, 190, -3,
-1, 235, 205, -1, 220, 159, -15, -7, -3, -1, 249, 234, -1, 189, 219,
-3, -1, 143, 248, -1, 204, 158, -7, -3, -1, 233, 127, -1, 247, 173,
-3, -1, 218, 188, -1, 111, -1, 174, 15, -19, -11, -3, -1, 203, 246,
-3, -1, 142, 232, -1, 95, 157, -3, -1, 245, 126, -1, 231, 172, -9,
-3, -1, 202, 187, -3, -1, 217, 141, 79, -3, -1, 244, 63, -1, 243,
216, -33, -17, -9, -3, -1, 230, 47, -1, 242, -1, 110, 240, -3, -1,
31, 241, -1, 156, 201, -7, -3, -1, 94, 171, -1, 186, 229, -3, -1,
125, 215, -1, 78, 228, -15, -7, -3, -1, 140, 200, -1, 62, 109, -3,
-1, 214, 227, -1, 155, 185, -7, -3, -1, 46, 170, -1, 226, 30, -5,
-1, 225, -1, 14, 224, -1, 93, 213, -45, -25, -13, -7, -3, -1, 124,
199, -1, 77, 139, -1, 212, -1, 184, 154, -7, -3, -1, 169, 108, -1,
198, 61, -1, 211, 210, -9, -5, -3, -1, 45, 13, 29, -1, 123, 183,
-5, -1, 209, -1, 92, 208, -1, 197, 138, -17, -7, -3, -1, 168, 76,
-1, 196, 107, -5, -1, 182, -1, 153, 12, -1, 60, 195, -9, -3, -1,
122, 167, -1, 166, -1, 192, 11, -1, 194, -1, 44, 91, -55, -29, -15,
-7, -3, -1, 181, 28, -1, 137, 152, -3, -1, 193, 75, -1, 180, 106,
-5, -3, -1, 59, 121, 179, -3, -1, 151, 136, -1, 43, 90, -11, -5,
-1, 178, -1, 165, 27, -1, 177, -1, 176, 105, -7, -3, -1, 150, 74,
-1, 164, 120, -3, -1, 135, 58, 163, -17, -7, -3, -1, 89, 149, -1,
42, 162, -3, -1, 26, 161, -3, -1, 10, 160, 104, -7, -3, -1, 134,
73, -1, 148, 57, -5, -1, 147, -1, 119, 9, -1, 88, 133, -53, -29,
-13, -7, -3, -1, 41, 103, -1, 118, 146, -1, 145, -1, 25, 144, -7,
-3, -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 71, -7,
-3, -1, 40, 130, -1, 24, 129, -7, -3, -1, 116, 8, -1, 128, 86,
-3, -1, 101, 55, -1, 115, 70, -17, -7, -3, -1, 39, 114, -1, 100,
23, -3, -1, 85, 113, -3, -1, 7, 112, 54, -7, -3, -1, 99, 69,
-1, 84, 38, -3, -1, 98, 22, -3, -1, 6, 96, 53, -33, -19, -9,
-5, -1, 97, -1, 83, 68, -1, 37, 82, -3, -1, 21, 81, -3, -1,
5, 80, 52, -7, -3, -1, 67, 36, -1, 66, 51, -1, 65, -1, 20,
4, -9, -3, -1, 35, 50, -3, -1, 64, 3, 19, -3, -1, 49, 48,
34, -9, -7, -3, -1, 18, 33, -1, 2, 32, 17, -3, -1, 1, 16,
0
};
static short tab16[] =
{
-509,-503,-461,-323,-103, -37, -27, -15, -7, -3, -1, 239, 254, -1, 223,
253, -3, -1, 207, 252, -1, 191, 251, -5, -1, 175, -1, 250, 159, -3,
-1, 249, 248, 143, -7, -3, -1, 127, 247, -1, 111, 246, 255, -9, -5,
-3, -1, 95, 245, 79, -1, 244, 243, -53, -1, 240, -1, 63, -29, -19,
-13, -7, -5, -1, 206, -1, 236, 221, 222, -1, 233, -1, 234, 217, -1,
238, -1, 237, 235, -3, -1, 190, 205, -3, -1, 220, 219, 174, -11, -5,
-1, 204, -1, 173, 218, -3, -1, 126, 172, 202, -5, -3, -1, 201, 125,
94, 189, 242, -93, -5, -3, -1, 47, 15, 31, -1, 241, -49, -25, -13,
-5, -1, 158, -1, 188, 203, -3, -1, 142, 232, -1, 157, 231, -7, -3,
-1, 187, 141, -1, 216, 110, -1, 230, 156, -13, -7, -3, -1, 171, 186,
-1, 229, 215, -1, 78, -1, 228, 140, -3, -1, 200, 62, -1, 109, -1,
214, 155, -19, -11, -5, -3, -1, 185, 170, 225, -1, 212, -1, 184, 169,
-5, -1, 123, -1, 183, 208, 227, -7, -3, -1, 14, 224, -1, 93, 213,
-3, -1, 124, 199, -1, 77, 139, -75, -45, -27, -13, -7, -3, -1, 154,
108, -1, 198, 61, -3, -1, 92, 197, 13, -7, -3, -1, 138, 168, -1,
153, 76, -3, -1, 182, 122, 60, -11, -5, -3, -1, 91, 137, 28, -1,
192, -1, 152, 121, -1, 226, -1, 46, 30, -15, -7, -3, -1, 211, 45,
-1, 210, 209, -5, -1, 59, -1, 151, 136, 29, -7, -3, -1, 196, 107,
-1, 195, 167, -1, 44, -1, 194, 181, -23, -13, -7, -3, -1, 193, 12,
-1, 75, 180, -3, -1, 106, 166, 179, -5, -3, -1, 90, 165, 43, -1,
178, 27, -13, -5, -1, 177, -1, 11, 176, -3, -1, 105, 150, -1, 74,
164, -5, -3, -1, 120, 135, 163, -3, -1, 58, 89, 42, -97, -57, -33,
-19, -11, -5, -3, -1, 149, 104, 161, -3, -1, 134, 119, 148, -5, -3,
-1, 73, 87, 103, 162, -5, -1, 26, -1, 10, 160, -3, -1, 57, 147,
-1, 88, 133, -9, -3, -1, 41, 146, -3, -1, 118, 9, 25, -5, -1,
145, -1, 144, 72, -3, -1, 132, 117, -1, 56, 131, -21, -11, -5, -3,
-1, 102, 40, 130, -3, -1, 71, 116, 24, -3, -1, 129, 128, -3, -1,
8, 86, 55, -9, -5, -1, 115, -1, 101, 70, -1, 39, 114, -5, -3,
-1, 100, 85, 7, 23, -23, -13, -5, -1, 113, -1, 112, 54, -3, -1,
99, 69, -1, 84, 38, -3, -1, 98, 22, -1, 97, -1, 6, 96, -9,
-5, -1, 83, -1, 53, 68, -1, 37, 82, -1, 81, -1, 21, 5, -33,
-23, -13, -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20,
-5, -1, 65, -1, 4, 64, -1, 35, 50, -3, -1, 19, 49, -3, -1,
3, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
0
static short tab16[] = {
-509, -503, -461, -323, -103, -37, -27, -15, -7, -3, -1, 239, 254, -1, 223,
253, -3, -1, 207, 252, -1, 191, 251, -5, -1, 175, -1, 250, 159, -3,
-1, 249, 248, 143, -7, -3, -1, 127, 247, -1, 111, 246, 255, -9, -5,
-3, -1, 95, 245, 79, -1, 244, 243, -53, -1, 240, -1, 63, -29, -19,
-13, -7, -5, -1, 206, -1, 236, 221, 222, -1, 233, -1, 234, 217, -1,
238, -1, 237, 235, -3, -1, 190, 205, -3, -1, 220, 219, 174, -11, -5,
-1, 204, -1, 173, 218, -3, -1, 126, 172, 202, -5, -3, -1, 201, 125,
94, 189, 242, -93, -5, -3, -1, 47, 15, 31, -1, 241, -49, -25, -13,
-5, -1, 158, -1, 188, 203, -3, -1, 142, 232, -1, 157, 231, -7, -3,
-1, 187, 141, -1, 216, 110, -1, 230, 156, -13, -7, -3, -1, 171, 186,
-1, 229, 215, -1, 78, -1, 228, 140, -3, -1, 200, 62, -1, 109, -1,
214, 155, -19, -11, -5, -3, -1, 185, 170, 225, -1, 212, -1, 184, 169,
-5, -1, 123, -1, 183, 208, 227, -7, -3, -1, 14, 224, -1, 93, 213,
-3, -1, 124, 199, -1, 77, 139, -75, -45, -27, -13, -7, -3, -1, 154,
108, -1, 198, 61, -3, -1, 92, 197, 13, -7, -3, -1, 138, 168, -1,
153, 76, -3, -1, 182, 122, 60, -11, -5, -3, -1, 91, 137, 28, -1,
192, -1, 152, 121, -1, 226, -1, 46, 30, -15, -7, -3, -1, 211, 45,
-1, 210, 209, -5, -1, 59, -1, 151, 136, 29, -7, -3, -1, 196, 107,
-1, 195, 167, -1, 44, -1, 194, 181, -23, -13, -7, -3, -1, 193, 12,
-1, 75, 180, -3, -1, 106, 166, 179, -5, -3, -1, 90, 165, 43, -1,
178, 27, -13, -5, -1, 177, -1, 11, 176, -3, -1, 105, 150, -1, 74,
164, -5, -3, -1, 120, 135, 163, -3, -1, 58, 89, 42, -97, -57, -33,
-19, -11, -5, -3, -1, 149, 104, 161, -3, -1, 134, 119, 148, -5, -3,
-1, 73, 87, 103, 162, -5, -1, 26, -1, 10, 160, -3, -1, 57, 147,
-1, 88, 133, -9, -3, -1, 41, 146, -3, -1, 118, 9, 25, -5, -1,
145, -1, 144, 72, -3, -1, 132, 117, -1, 56, 131, -21, -11, -5, -3,
-1, 102, 40, 130, -3, -1, 71, 116, 24, -3, -1, 129, 128, -3, -1,
8, 86, 55, -9, -5, -1, 115, -1, 101, 70, -1, 39, 114, -5, -3,
-1, 100, 85, 7, 23, -23, -13, -5, -1, 113, -1, 112, 54, -3, -1,
99, 69, -1, 84, 38, -3, -1, 98, 22, -1, 97, -1, 6, 96, -9,
-5, -1, 83, -1, 53, 68, -1, 37, 82, -1, 81, -1, 21, 5, -33,
-23, -13, -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20,
-5, -1, 65, -1, 4, 64, -1, 35, 50, -3, -1, 19, 49, -3, -1,
3, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16,
0
};
static short tab24[] =
{
-451,-117, -43, -25, -15, -7, -3, -1, 239, 254, -1, 223, 253, -3, -1,
207, 252, -1, 191, 251, -5, -1, 250, -1, 175, 159, -1, 249, 248, -9,
-5, -3, -1, 143, 127, 247, -1, 111, 246, -3, -1, 95, 245, -1, 79,
244, -71, -7, -3, -1, 63, 243, -1, 47, 242, -5, -1, 241, -1, 31,
240, -25, -9, -1, 15, -3, -1, 238, 222, -1, 237, 206, -7, -3, -1,
236, 221, -1, 190, 235, -3, -1, 205, 220, -1, 174, 234, -15, -7, -3,
-1, 189, 219, -1, 204, 158, -3, -1, 233, 173, -1, 218, 188, -7, -3,
-1, 203, 142, -1, 232, 157, -3, -1, 217, 126, -1, 231, 172, 255,-235,
-143, -77, -45, -25, -15, -7, -3, -1, 202, 187, -1, 141, 216, -5, -3,
-1, 14, 224, 13, 230, -5, -3, -1, 110, 156, 201, -1, 94, 186, -9,
-5, -1, 229, -1, 171, 125, -1, 215, 228, -3, -1, 140, 200, -3, -1,
78, 46, 62, -15, -7, -3, -1, 109, 214, -1, 227, 155, -3, -1, 185,
170, -1, 226, 30, -7, -3, -1, 225, 93, -1, 213, 124, -3, -1, 199,
77, -1, 139, 184, -31, -15, -7, -3, -1, 212, 154, -1, 169, 108, -3,
-1, 198, 61, -1, 211, 45, -7, -3, -1, 210, 29, -1, 123, 183, -3,
-1, 209, 92, -1, 197, 138, -17, -7, -3, -1, 168, 153, -1, 76, 196,
-3, -1, 107, 182, -3, -1, 208, 12, 60, -7, -3, -1, 195, 122, -1,
167, 44, -3, -1, 194, 91, -1, 181, 28, -57, -35, -19, -7, -3, -1,
137, 152, -1, 193, 75, -5, -3, -1, 192, 11, 59, -3, -1, 176, 10,
26, -5, -1, 180, -1, 106, 166, -3, -1, 121, 151, -3, -1, 160, 9,
144, -9, -3, -1, 179, 136, -3, -1, 43, 90, 178, -7, -3, -1, 165,
27, -1, 177, 105, -1, 150, 164, -17, -9, -5, -3, -1, 74, 120, 135,
-1, 58, 163, -3, -1, 89, 149, -1, 42, 162, -7, -3, -1, 161, 104,
-1, 134, 119, -3, -1, 73, 148, -1, 57, 147, -63, -31, -15, -7, -3,
-1, 88, 133, -1, 41, 103, -3, -1, 118, 146, -1, 25, 145, -7, -3,
-1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 40, -17, -7,
-3, -1, 130, 24, -1, 71, 116, -5, -1, 129, -1, 8, 128, -1, 86,
101, -7, -5, -1, 23, -1, 7, 112, 115, -3, -1, 55, 39, 114, -15,
-7, -3, -1, 70, 100, -1, 85, 113, -3, -1, 54, 99, -1, 69, 84,
-7, -3, -1, 38, 98, -1, 22, 97, -5, -3, -1, 6, 96, 53, -1,
83, 68, -51, -37, -23, -15, -9, -3, -1, 37, 82, -1, 21, -1, 5,
80, -1, 81, -1, 52, 67, -3, -1, 36, 66, -1, 51, 20, -9, -5,
-1, 65, -1, 4, 64, -1, 35, 50, -1, 19, 49, -7, -5, -3, -1,
3, 48, 34, 18, -1, 33, -1, 2, 32, -3, -1, 17, 1, -1, 16,
0
static short tab24[] = {
-451, -117, -43, -25, -15, -7, -3, -1, 239, 254, -1, 223, 253, -3, -1,
207, 252, -1, 191, 251, -5, -1, 250, -1, 175, 159, -1, 249, 248, -9,
-5, -3, -1, 143, 127, 247, -1, 111, 246, -3, -1, 95, 245, -1, 79,
244, -71, -7, -3, -1, 63, 243, -1, 47, 242, -5, -1, 241, -1, 31,
240, -25, -9, -1, 15, -3, -1, 238, 222, -1, 237, 206, -7, -3, -1,
236, 221, -1, 190, 235, -3, -1, 205, 220, -1, 174, 234, -15, -7, -3,
-1, 189, 219, -1, 204, 158, -3, -1, 233, 173, -1, 218, 188, -7, -3,
-1, 203, 142, -1, 232, 157, -3, -1, 217, 126, -1, 231, 172, 255, -235,
-143, -77, -45, -25, -15, -7, -3, -1, 202, 187, -1, 141, 216, -5, -3,
-1, 14, 224, 13, 230, -5, -3, -1, 110, 156, 201, -1, 94, 186, -9,
-5, -1, 229, -1, 171, 125, -1, 215, 228, -3, -1, 140, 200, -3, -1,
78, 46, 62, -15, -7, -3, -1, 109, 214, -1, 227, 155, -3, -1, 185,
170, -1, 226, 30, -7, -3, -1, 225, 93, -1, 213, 124, -3, -1, 199,
77, -1, 139, 184, -31, -15, -7, -3, -1, 212, 154, -1, 169, 108, -3,
-1, 198, 61, -1, 211, 45, -7, -3, -1, 210, 29, -1, 123, 183, -3,
-1, 209, 92, -1, 197, 138, -17, -7, -3, -1, 168, 153, -1, 76, 196,
-3, -1, 107, 182, -3, -1, 208, 12, 60, -7, -3, -1, 195, 122, -1,
167, 44, -3, -1, 194, 91, -1, 181, 28, -57, -35, -19, -7, -3, -1,
137, 152, -1, 193, 75, -5, -3, -1, 192, 11, 59, -3, -1, 176, 10,
26, -5, -1, 180, -1, 106, 166, -3, -1, 121, 151, -3, -1, 160, 9,
144, -9, -3, -1, 179, 136, -3, -1, 43, 90, 178, -7, -3, -1, 165,
27, -1, 177, 105, -1, 150, 164, -17, -9, -5, -3, -1, 74, 120, 135,
-1, 58, 163, -3, -1, 89, 149, -1, 42, 162, -7, -3, -1, 161, 104,
-1, 134, 119, -3, -1, 73, 148, -1, 57, 147, -63, -31, -15, -7, -3,
-1, 88, 133, -1, 41, 103, -3, -1, 118, 146, -1, 25, 145, -7, -3,
-1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 40, -17, -7,
-3, -1, 130, 24, -1, 71, 116, -5, -1, 129, -1, 8, 128, -1, 86,
101, -7, -5, -1, 23, -1, 7, 112, 115, -3, -1, 55, 39, 114, -15,
-7, -3, -1, 70, 100, -1, 85, 113, -3, -1, 54, 99, -1, 69, 84,
-7, -3, -1, 38, 98, -1, 22, 97, -5, -3, -1, 6, 96, 53, -1,
83, 68, -51, -37, -23, -15, -9, -3, -1, 37, 82, -1, 21, -1, 5,
80, -1, 81, -1, 52, 67, -3, -1, 36, 66, -1, 51, 20, -9, -5,
-1, 65, -1, 4, 64, -1, 35, 50, -1, 19, 49, -7, -5, -3, -1,
3, 48, 34, 18, -1, 33, -1, 2, 32, -3, -1, 17, 1, -1, 16,
0
};
static short tab_c0[] =
{
-29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5,
9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8,
0
static short tab_c0[] = {
-29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5,
9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8,
0
};
static short tab_c1[] =
{
-15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9,
8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1,
0
static short tab_c1[] = {
-15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9,
8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1,
0
};
static struct newhuff ht[] =
{
{ /* 0 */ 0 , tab0 } ,
{ /* 2 */ 0 , tab1 } ,
{ /* 3 */ 0 , tab2 } ,
{ /* 3 */ 0 , tab3 } ,
{ /* 0 */ 0 , tab0 } ,
{ /* 4 */ 0 , tab5 } ,
{ /* 4 */ 0 , tab6 } ,
{ /* 6 */ 0 , tab7 } ,
{ /* 6 */ 0 , tab8 } ,
{ /* 6 */ 0 , tab9 } ,
{ /* 8 */ 0 , tab10 } ,
{ /* 8 */ 0 , tab11 } ,
{ /* 8 */ 0 , tab12 } ,
{ /* 16 */ 0 , tab13 } ,
{ /* 0 */ 0 , tab0 } ,
{ /* 16 */ 0 , tab15 } ,
static struct newhuff ht[] = {
{ /* 0 */ 0, tab0},
{ /* 2 */ 0, tab1},
{ /* 3 */ 0, tab2},
{ /* 3 */ 0, tab3},
{ /* 0 */ 0, tab0},
{ /* 4 */ 0, tab5},
{ /* 4 */ 0, tab6},
{ /* 6 */ 0, tab7},
{ /* 6 */ 0, tab8},
{ /* 6 */ 0, tab9},
{ /* 8 */ 0, tab10},
{ /* 8 */ 0, tab11},
{ /* 8 */ 0, tab12},
{ /* 16 */ 0, tab13},
{ /* 0 */ 0, tab0},
{ /* 16 */ 0, tab15},
{ /* 16 */ 1 , tab16 } ,
{ /* 16 */ 2 , tab16 } ,
{ /* 16 */ 3 , tab16 } ,
{ /* 16 */ 4 , tab16 } ,
{ /* 16 */ 6 , tab16 } ,
{ /* 16 */ 8 , tab16 } ,
{ /* 16 */ 10, tab16 } ,
{ /* 16 */ 13, tab16 } ,
{ /* 16 */ 4 , tab24 } ,
{ /* 16 */ 5 , tab24 } ,
{ /* 16 */ 6 , tab24 } ,
{ /* 16 */ 7 , tab24 } ,
{ /* 16 */ 8 , tab24 } ,
{ /* 16 */ 9 , tab24 } ,
{ /* 16 */ 11, tab24 } ,
{ /* 16 */ 13, tab24 }
{ /* 16 */ 1, tab16},
{ /* 16 */ 2, tab16},
{ /* 16 */ 3, tab16},
{ /* 16 */ 4, tab16},
{ /* 16 */ 6, tab16},
{ /* 16 */ 8, tab16},
{ /* 16 */ 10, tab16},
{ /* 16 */ 13, tab16},
{ /* 16 */ 4, tab24},
{ /* 16 */ 5, tab24},
{ /* 16 */ 6, tab24},
{ /* 16 */ 7, tab24},
{ /* 16 */ 8, tab24},
{ /* 16 */ 9, tab24},
{ /* 16 */ 11, tab24},
{ /* 16 */ 13, tab24}
};
static struct newhuff htc[] =
{
{ /* 1 , 1 , */ 0 , tab_c0 } ,
{ /* 1 , 1 , */ 0 , tab_c1 }
static struct newhuff htc[] = {
{ /* 1 , 1 , */ 0, tab_c0},
{ /* 1 , 1 , */ 0, tab_c1}
};
+119 -127
View File
@@ -9,21 +9,21 @@ void InitMP3Constants(void)
{
init_layer3_const();
make_decode_tables_const();
}
BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate)
BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate)
{
/* quiet 4096 med 8192 */
memset(mp,0,sizeof(struct mpstr));
memset(mp, 0, sizeof(struct mpstr));
mp->framesize = 0;
mp->fsizeold = -1;
mp->bsize = 0;
mp->head = mp->tail = NULL;
mp->fr.single = 3; /* force mono */
mp->fr.single = 3; /* force mono */
mp->bsnum = 0;
mp->synth_bo = 1;
mp->outsamplerate = samplerate;
@@ -37,10 +37,10 @@ BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate)
void ExitMP3(struct mpstr *mp)
{
struct buf *b,*bn;
struct buf *b, *bn;
b = mp->tail;
while(b) {
while (b) {
free(b->pnt);
bn = b->next;
free(b);
@@ -48,31 +48,30 @@ void ExitMP3(struct mpstr *mp)
}
}
static struct buf *addbuf(struct mpstr *mp,char *buf,int size)
static struct buf *addbuf(struct mpstr *mp, char *buf, int size)
{
struct buf *nbuf;
nbuf = malloc( sizeof(struct buf) );
if(!nbuf) {
debug_printf("%d Out of memory!\n", __LINE__);
nbuf = malloc(sizeof(struct buf));
if (!nbuf) {
debug_printf("%d Out of memory!\n", __LINE__);
return NULL;
}
nbuf->pnt = malloc(size);
if(!nbuf->pnt) {
if (!nbuf->pnt) {
free(nbuf);
return NULL;
}
nbuf->size = size;
memcpy(nbuf->pnt,buf,size);
memcpy(nbuf->pnt, buf, size);
nbuf->next = NULL;
nbuf->prev = mp->head;
nbuf->pos = 0;
if(!mp->tail) {
if (!mp->tail) {
mp->tail = nbuf;
}
else {
mp->head->next = nbuf;
} else {
mp->head->next = nbuf;
}
mp->head = nbuf;
@@ -83,50 +82,51 @@ static struct buf *addbuf(struct mpstr *mp,char *buf,int size)
static void remove_buf(struct mpstr *mp)
{
struct buf *buf = mp->tail;
mp->tail = buf->next;
if(mp->tail)
mp->tail->prev = NULL;
else {
mp->tail = mp->head = NULL;
}
free(buf->pnt);
free(buf);
struct buf *buf = mp->tail;
mp->tail = buf->next;
if (mp->tail)
mp->tail->prev = NULL;
else {
mp->tail = mp->head = NULL;
}
free(buf->pnt);
free(buf);
}
static int read_buf_byte(int *error, struct mpstr *mp)
{
unsigned int b;int pos;
unsigned int b;
int pos;
pos = mp->tail->pos;
while(pos >= mp->tail->size) {
while (pos >= mp->tail->size) {
remove_buf(mp);
pos = mp->tail->pos;
if(!mp->tail) {
/* We may pick up this error a few times*/
if (!mp->tail) {
/* We may pick up this error a few times */
/* But things have gone pear shaped */
debug_printf("%d Fatal Buffer error!\n", __LINE__);
debug_printf("%d Fatal Buffer error!\n", __LINE__);
*error = 1;
return (0);
return (0);
}
}
b = mp->tail->pnt[pos];
mp->bsize--;
mp->tail->pos++;
return b;
}
static int read_head(struct mpstr *mp)
static int read_head(struct mpstr *mp)
{
unsigned long head;
int error=0;
int error = 0;
head = read_buf_byte(&error, mp);
head <<= 8;
@@ -138,130 +138,127 @@ static int read_head(struct mpstr *mp)
mp->header = head;
if(error){
if (error) {
return (1);
}else
} else
return (0);
}
static int head_check(unsigned long head)
{
if( (head & 0xffe00000) != 0xffe00000)
return FALSE;
if(!((head>>17)&3))
return FALSE;
if( ((head>>12)&0xf) == 0xf || ((head>>12)&0xf) == 0)
return FALSE;
if( ((head>>10)&0x3) == 0x3 )
return FALSE;
if ((head & 0xffff0000) == 0xfffe0000)
return FALSE;
if ((head & 0xffe00000) != 0xffe00000)
return FALSE;
if (!((head >> 17) & 3))
return FALSE;
if (((head >> 12) & 0xf) == 0xf || ((head >> 12) & 0xf) == 0)
return FALSE;
if (((head >> 10) & 0x3) == 0x3)
return FALSE;
if ((head & 0xffff0000) == 0xfffe0000)
return FALSE;
return TRUE;
return TRUE;
}
static int head_shift(struct mpstr *mp)
{
unsigned long head;
int error = 0;
head = mp->header;
head <<= 8;
head |= read_buf_byte(&error, mp);
mp->header = head;
if (error){
if (error) {
return (1);
}else
} else
return (0);
}
int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
int osize,int *done)
int decodeMP3(struct mpstr *mp, char *in, int isize, char *out, int osize, int *done)
{
int len;
long n,m;
long n, m;
int down_sample_sblimit;
if(osize < 4608) {
debug_printf("%d To less out space\n", __LINE__);
if (osize < 4608) {
debug_printf("%d To less out space\n", __LINE__);
return MP3_TOOSMALL;
}
if(in) {
if(addbuf(mp,in,isize) == NULL) {
if (in) {
if (addbuf(mp, in, isize) == NULL) {
return MP3_ERR;
}
}
/* First decode header */
if(mp->framesize == 0) {
if(mp->bsize < 4) {
if (mp->framesize == 0) {
if (mp->bsize < 4) {
return MP3_NEED_MORE;
}
if (read_head(mp))
return MP3_ERR;
if(!head_check(mp->header) ) {
if (!head_check(mp->header)) {
int i;
debug_printf("Junk at the beginning of frame %08lx\n",mp->header);
debug_printf("Junk at the beginning of frame %08lx\n", mp->header);
/* step in byte steps through next 64K */
for(i=0;i<65536;i++) {
if(!mp->bsize)
for (i = 0; i < 65536; i++) {
if (!mp->bsize)
return MP3_NEED_MORE;
if(head_shift(mp))
if (head_shift(mp))
return MP3_ERR;
if(head_check(mp->header))
if (head_check(mp->header))
break;
}
if(i == 65536) {
debug_printf("%d Giving up searching valid MPEG header\n", __LINE__);
if (i == 65536) {
debug_printf("%d Giving up searching valid MPEG header\n", __LINE__);
return MP3_ERR;
}
}
decode_header(&mp->fr,mp->header);
decode_header(&mp->fr, mp->header);
mp->framesize = mp->fr.framesize;
if (!mp->initmp3){
if (!mp->initmp3) {
mp->initmp3 = 1;
n = freqs[mp->fr.sampling_frequency];
if (mp->outsamplerate) {
m = mp->outsamplerate;
} else {
m = n;
}
else {
m =n;
}
if (synth_ntom_set_step(n,m))
if (synth_ntom_set_step(n, m))
return MP3_ERR;
if(n>m) {
if (n > m) {
down_sample_sblimit = SBLIMIT * m;
down_sample_sblimit /= n;
}
else {
} else {
down_sample_sblimit = SBLIMIT;
}
init_layer3_sample_limits(mp, down_sample_sblimit);
}
}
if(mp->fr.framesize > mp->bsize)
if (mp->fr.framesize > mp->bsize)
return MP3_NEED_MORE;
(mp->worksample).wordpointer = mp->bsspace[mp->bsnum] + 512;
@@ -269,29 +266,28 @@ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
(mp->worksample).bitindex = 0;
len = 0;
while(len < mp->framesize) {
while (len < mp->framesize) {
int nlen;
int blen = mp->tail->size - mp->tail->pos;
if( (mp->framesize - len) <= blen) {
nlen = mp->framesize-len;
if ((mp->framesize - len) <= blen) {
nlen = mp->framesize - len;
} else {
nlen = blen;
}
else {
nlen = blen;
}
memcpy((mp->worksample).wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen);
len += nlen;
mp->tail->pos += nlen;
memcpy((mp->worksample).wordpointer + len, mp->tail->pnt + mp->tail->pos, nlen);
len += nlen;
mp->tail->pos += nlen;
mp->bsize -= nlen;
if(mp->tail->pos == mp->tail->size) {
remove_buf(mp);
}
if (mp->tail->pos == mp->tail->size) {
remove_buf(mp);
}
}
*done = 0;
if(mp->fr.error_protection)
getbits(mp, 16);
if (do_layer3(mp,(unsigned char *) out,done))
if (mp->fr.error_protection)
getbits(mp, 16);
if (do_layer3(mp, (unsigned char *) out, done))
return MP3_ERR;
mp->fsizeold = mp->framesize;
@@ -302,19 +298,15 @@ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
int set_pointer(struct mpstr *mp, long backstep)
{
unsigned char *bsbufold;
if(mp->fsizeold < 0 && backstep > 0) {
debug_printf("Can't step back %ld!\n",backstep);
return MP3_ERR;
}
bsbufold = mp->bsspace[mp->bsnum] + 512;
(mp->worksample).wordpointer -= backstep;
if (backstep)
memcpy((mp->worksample).wordpointer,bsbufold+mp->fsizeold-backstep,backstep);
(mp->worksample).bitindex = 0;
return MP3_OK;
unsigned char *bsbufold;
if (mp->fsizeold < 0 && backstep > 0) {
debug_printf("Can't step back %ld!\n", backstep);
return MP3_ERR;
}
bsbufold = mp->bsspace[mp->bsnum] + 512;
(mp->worksample).wordpointer -= backstep;
if (backstep)
memcpy((mp->worksample).wordpointer, bsbufold + mp->fsizeold - backstep, backstep);
(mp->worksample).bitindex = 0;
return MP3_OK;
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+47 -50
View File
@@ -58,69 +58,67 @@
#define AUSHIFT (3)
struct frame {
int stereo;
int jsbound;
int single;
int lsf;
int mpeg25;
int header_change;
int lay;
int error_protection;
int bitrate_index;
int sampling_frequency;
int padding;
int extension;
int mode;
int mode_ext;
int copyright;
int original;
int emphasis;
int framesize; /* computed framesize */
int stereo;
int jsbound;
int single;
int lsf;
int mpeg25;
int header_change;
int lay;
int error_protection;
int bitrate_index;
int sampling_frequency;
int padding;
int extension;
int mode;
int mode_ext;
int copyright;
int original;
int emphasis;
int framesize; /* computed framesize */
};
struct parameter {
int quiet; /* shut up! */
int tryresync; /* resync stream after error */
int verbose; /* verbose level */
int quiet; /* shut up! */
int tryresync; /* resync stream after error */
int verbose; /* verbose level */
int checkrange;
};
extern int decode_header(struct frame *fr,unsigned long newhead);
extern int decode_header(struct frame *fr, unsigned long newhead);
struct gr_info_s {
int scfsi;
unsigned part2_3_length;
unsigned big_values;
unsigned scalefac_compress;
unsigned block_type;
unsigned mixed_block_flag;
unsigned table_select[3];
unsigned subblock_gain[3];
unsigned maxband[3];
unsigned maxbandl;
unsigned maxb;
unsigned region1start;
unsigned region2start;
unsigned preflag;
unsigned scalefac_scale;
unsigned count1table_select;
real *full_gain[3];
real *pow2gain;
int scfsi;
unsigned part2_3_length;
unsigned big_values;
unsigned scalefac_compress;
unsigned block_type;
unsigned mixed_block_flag;
unsigned table_select[3];
unsigned subblock_gain[3];
unsigned maxband[3];
unsigned maxbandl;
unsigned maxb;
unsigned region1start;
unsigned region2start;
unsigned preflag;
unsigned scalefac_scale;
unsigned count1table_select;
real *full_gain[3];
real *pow2gain;
};
struct III_sideinfo
{
unsigned main_data_begin;
unsigned private_bits;
struct {
struct gr_info_s gr[2];
} ch[2];
struct III_sideinfo {
unsigned main_data_begin;
unsigned private_bits;
struct {
struct gr_info_s gr[2];
} ch[2];
};
struct pcm_workingsample
{
struct pcm_workingsample {
int bitindex;
unsigned char *wordpointer;
};
@@ -129,4 +127,3 @@ struct pcm_workingsample
extern long freqs[9];
extern struct parameter param;
extern real *pnts[5];
+29 -31
View File
@@ -5,11 +5,11 @@
#endif
struct buf {
unsigned char *pnt;
unsigned char *pnt;
long size;
long pos;
struct buf *next;
struct buf *prev;
struct buf *next;
struct buf *prev;
};
struct framebuf {
@@ -20,27 +20,27 @@ struct framebuf {
};
struct mpstr {
struct buf *head,*tail;
struct buf *head, *tail;
int bsize;
int framesize;
int fsizeold;
int fsizeold;
struct frame fr;
unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */
real hybrid_block[2][2][SBLIMIT*SSLIMIT];
unsigned char bsspace[2][MAXFRAMESIZE + 512]; /* MAXFRAMESIZE */
real hybrid_block[2][2][SBLIMIT * SSLIMIT];
int hybrid_blc[2];
unsigned long header;
int bsnum;
real synth_buffs[2][2][0x110];
int synth_bo;
long outscale; /* volume control default value 32768 */
long outsamplerate; /* raw output rate default same as mp3 sample rate*/
struct pcm_workingsample worksample; /* keep the state of the working sample for threads */
int initmp3; /* flag for first initialisation */
int longLimit[9][23]; /*sample limits re setting volume */
int synth_bo;
long outscale; /* volume control default value 32768 */
long outsamplerate; /* raw output rate default same as mp3 sample rate */
struct pcm_workingsample worksample; /* keep the state of the working sample for threads */
int initmp3; /* flag for first initialisation */
int longLimit[9][23]; /*sample limits re setting volume */
int shortLimit[9][14];
real decwin[512+32]; /* scale table */
};
real decwin[512 + 32]; /* scale table */
};
#define BOOL int
@@ -51,30 +51,28 @@ struct mpstr {
void InitMP3Constants(void);
BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate);
int decodeMP3(struct mpstr *mp,char *inmemory,int inmemsize,
char *outmemory,int outmemsize,int *done);
int decodeMP3(struct mpstr *mp, char *inmemory, int inmemsize, char *outmemory, int outmemsize, int *done);
void ExitMP3(struct mpstr *mp);
extern int synth_ntom_set_step(long,long);
extern int synth_ntom(struct mpstr *mp, real *bandPtr,int channel,unsigned char *out,int *pnt);
extern int synth_ntom_mono (struct mpstr *mp, real *bandPtr,unsigned char *samples,int *pnt);
extern int synth_ntom_8bit (real *,int,unsigned char *,int *);
extern int synth_ntom_mono2stereo (real *,unsigned char *,int *);
extern int synth_ntom_8bit_mono (real *,unsigned char *,int *);
extern int synth_ntom_8bit_mono2stereo (real *,unsigned char *,int *);
extern int synth_ntom_set_step(long, long);
extern int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out, int *pnt);
extern int synth_ntom_mono(struct mpstr *mp, real * bandPtr, unsigned char *samples, int *pnt);
extern int synth_ntom_8bit(real *, int, unsigned char *, int *);
extern int synth_ntom_mono2stereo(real *, unsigned char *, int *);
extern int synth_ntom_8bit_mono(real *, unsigned char *, int *);
extern int synth_ntom_8bit_mono2stereo(real *, unsigned char *, int *);
extern void init_layer3_sample_limits(struct mpstr *mp, int down_sample_sblimit);
extern void init_layer3_const(void);
extern int do_layer3(struct mpstr *mp,unsigned char *,int *);
extern int do_layer3(struct mpstr *mp, unsigned char *, int *);
extern void make_decode_tables_scale(struct mpstr *mp, long scaleval);
extern void make_decode_tables_const(void);
extern void make_conv16to8_table(int);
extern void dct64(real *,real *,real *);
extern void dct64(real *, real *, real *);
extern unsigned int get1bit(struct mpstr *mp);
extern unsigned int getbits(struct mpstr *mp, int);
extern unsigned int getbits_fast(struct mpstr *mp, int);
extern unsigned int get1bit(struct mpstr *mp);
extern unsigned int getbits(struct mpstr *mp, int);
extern unsigned int getbits_fast(struct mpstr *mp, int);
extern int set_pointer(struct mpstr *mp, long backstep);
+56 -59
View File
@@ -4,47 +4,48 @@
#include "mpg123.h"
#include "mpglib.h"
static real cos64[16],cos32[8],cos16[4],cos8[2],cos4[1];
real *pnts[] = { cos64,cos32,cos16,cos8,cos4 };
static real cos64[16], cos32[8], cos16[4], cos8[2], cos4[1];
real *pnts[] = { cos64, cos32, cos16, cos8, cos4 };
static long intwinbase[] = {
0, -1, -1, -1, -1, -1, -1, -2, -2, -2,
-2, -3, -3, -4, -4, -5, -5, -6, -7, -7,
-8, -9, -10, -11, -13, -14, -16, -17, -19, -21,
-24, -26, -29, -31, -35, -38, -41, -45, -49, -53,
-58, -63, -68, -73, -79, -85, -91, -97, -104, -111,
-117, -125, -132, -139, -147, -154, -161, -169, -176, -183,
-190, -196, -202, -208, -213, -218, -222, -225, -227, -228,
-228, -227, -224, -221, -215, -208, -200, -189, -177, -163,
-146, -127, -106, -83, -57, -29, 2, 36, 72, 111,
153, 197, 244, 294, 347, 401, 459, 519, 581, 645,
711, 779, 848, 919, 991, 1064, 1137, 1210, 1283, 1356,
1428, 1498, 1567, 1634, 1698, 1759, 1817, 1870, 1919, 1962,
2001, 2032, 2057, 2075, 2085, 2087, 2080, 2063, 2037, 2000,
1952, 1893, 1822, 1739, 1644, 1535, 1414, 1280, 1131, 970,
794, 605, 402, 185, -45, -288, -545, -814, -1095, -1388,
-1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
-5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209,
-8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959,
-9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092,
-7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082,
-70, 998, 2122, 3300, 4533, 5818, 7154, 8540, 9975, 11455,
12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289,
30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617,
48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684,
64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835,
73415, 73908, 74313, 74630, 74856, 74992, 75038 };
0, -1, -1, -1, -1, -1, -1, -2, -2, -2,
-2, -3, -3, -4, -4, -5, -5, -6, -7, -7,
-8, -9, -10, -11, -13, -14, -16, -17, -19, -21,
-24, -26, -29, -31, -35, -38, -41, -45, -49, -53,
-58, -63, -68, -73, -79, -85, -91, -97, -104, -111,
-117, -125, -132, -139, -147, -154, -161, -169, -176, -183,
-190, -196, -202, -208, -213, -218, -222, -225, -227, -228,
-228, -227, -224, -221, -215, -208, -200, -189, -177, -163,
-146, -127, -106, -83, -57, -29, 2, 36, 72, 111,
153, 197, 244, 294, 347, 401, 459, 519, 581, 645,
711, 779, 848, 919, 991, 1064, 1137, 1210, 1283, 1356,
1428, 1498, 1567, 1634, 1698, 1759, 1817, 1870, 1919, 1962,
2001, 2032, 2057, 2075, 2085, 2087, 2080, 2063, 2037, 2000,
1952, 1893, 1822, 1739, 1644, 1535, 1414, 1280, 1131, 970,
794, 605, 402, 185, -45, -288, -545, -814, -1095, -1388,
-1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
-5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209,
-8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959,
-9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092,
-7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082,
-70, 998, 2122, 3300, 4533, 5818, 7154, 8540, 9975, 11455,
12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289,
30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617,
48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684,
64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835,
73415, 73908, 74313, 74630, 74856, 74992, 75038
};
void make_decode_tables_const(void)
{
int i,k,kr,divv;
int i, k, kr, divv;
real *costab;
for(i=0;i<5;i++)
{
kr=0x10>>i; divv=0x40>>i;
for (i = 0; i < 5; i++) {
kr = 0x10 >> i;
divv = 0x40 >> i;
costab = pnts[i];
for(k=0;k<kr;k++)
for (k = 0; k < kr; k++)
costab[k] = 1.0 / (2.0 * cos(M_PI * ((double) k * 2.0 + 1.0) / (double) divv));
}
@@ -52,30 +53,26 @@ void make_decode_tables_const(void)
void make_decode_tables_scale(struct mpstr *mp, long scaleval)
{
int i,j;
real *table;
table = mp->decwin;
scaleval = -scaleval;
for(i=0,j=0;i<256;i++,j++,table+=32)
{
if(table < (mp->decwin)+512+16)
table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
if(i % 32 == 31)
table -= 1023;
if(i % 64 == 63)
scaleval = - scaleval;
}
int i, j;
real *table;
for( /* i=256 */ ;i<512;i++,j--,table+=32)
{
if(table < (mp->decwin)+512+16)
table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
if(i % 32 == 31)
table -= 1023;
if(i % 64 == 63)
scaleval = - scaleval;
}
table = mp->decwin;
scaleval = -scaleval;
for (i = 0, j = 0; i < 256; i++, j++, table += 32) {
if (table < (mp->decwin) + 512 + 16)
table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
if (i % 32 == 31)
table -= 1023;
if (i % 64 == 63)
scaleval = -scaleval;
}
for ( /* i=256 */ ; i < 512; i++, j--, table += 32) {
if (table < (mp->decwin) + 512 + 16)
table[16] = table[0] = (double) intwinbase[j] / 65536.0 * (double) scaleval;
if (i % 32 == 31)
table -= 1023;
if (i % 64 == 63)
scaleval = -scaleval;
}
}
+41 -34
View File
@@ -87,8 +87,8 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, char *pat
map = switch_core_hash_find(globals.format_hash, ext);
if (mode & SFM_WRITE) {
sf_count_t frames = 0 ;
sf_count_t frames = 0;
context->sfinfo.channels = handle->channels;
context->sfinfo.samplerate = handle->samplerate;
if (handle->samplerate == 8000 || handle->samplerate == 16000) {
@@ -99,9 +99,9 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, char *pat
context->sfinfo.format |= SF_FORMAT_PCM_32;
}
sf_command (context->handle, SFC_FILE_TRUNCATE, &frames, sizeof (frames));
}
sf_command(context->handle, SFC_FILE_TRUNCATE, &frames, sizeof(frames));
}
if (map) {
context->sfinfo.format |= map->format;
}
@@ -134,23 +134,25 @@ static switch_status_t sndfile_file_open(switch_file_handle_t *handle, char *pat
context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_ALAW;
context->sfinfo.channels = 1;
context->sfinfo.samplerate = 8000;
}
if ((mode & SFM_WRITE) && sf_format_check (&context->sfinfo) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error : file format is invalid (0x%08X).\n", context->sfinfo.format);
}
if ((mode & SFM_WRITE) && sf_format_check(&context->sfinfo) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error : file format is invalid (0x%08X).\n",
context->sfinfo.format);
return SWITCH_STATUS_GENERR;
};
if ((context->handle = sf_open(path, mode, &context->sfinfo)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening File [%s] [%s]\n", path,
sf_strerror(context->handle));
sf_strerror(context->handle));
return SWITCH_STATUS_GENERR;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opening File [%s] %dhz\n", path,
context->sfinfo.samplerate);
handle->samples = (unsigned int) context->sfinfo.frames;
handle->samplerate = context->sfinfo.samplerate;
handle->channels = (uint8_t)context->sfinfo.channels;
handle->channels = (uint8_t) context->sfinfo.channels;
handle->format = context->sfinfo.format;
handle->sections = context->sfinfo.sections;
handle->seekable = context->sfinfo.seekable;
@@ -169,7 +171,8 @@ static switch_status_t sndfile_file_close(switch_file_handle_t *handle)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t sndfile_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples, int whence)
static switch_status_t sndfile_file_seek(switch_file_handle_t *handle, unsigned int *cur_sample, int64_t samples,
int whence)
{
sndfile_context *context = handle->private_info;
@@ -233,15 +236,16 @@ static switch_status_t sndfile_file_set_string(switch_file_handle_t *handle, swi
{
sndfile_context *context = handle->private_info;
return sf_set_string(context->handle, (int)col, string) ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
return sf_set_string(context->handle, (int) col, string) ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
static switch_status_t sndfile_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
static switch_status_t sndfile_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col,
const char **string)
{
sndfile_context *context = handle->private_info;
const char *s;
if ((s = sf_get_string(context->handle, (int)col))) {
if ((s = sf_get_string(context->handle, (int) col))) {
*string = s;
return SWITCH_STATUS_SUCCESS;
}
@@ -287,17 +291,18 @@ static switch_status_t setup_formats(void)
char *extras[] = { "r8", "r16", "r24", "r32", "gsm", "ul", "al", NULL };
int exlen = (sizeof(extras) / sizeof(extras[0]));
buffer[0] = 0;
sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer));
if (strlen(buffer) < 1) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Line %d: could not retrieve lib version.\n", __LINE__);
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Line %d: could not retrieve lib version.\n",
__LINE__);
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "\nLibSndFile Version : %s Supported Formats\n", buffer);
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,
"================================================================================\n");
"================================================================================\n");
sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof(int));
sf_command(NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof(int));
@@ -310,7 +315,8 @@ static switch_status_t setup_formats(void)
skip = 0;
info.format = m;
sf_command(NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof(info));
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s (extension \"%s\")\n", info.name, info.extension);
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "%s (extension \"%s\")\n", info.name,
info.extension);
for (x = 0; x < len; x++) {
if (supported_formats[x] == info.extension) {
skip++;
@@ -327,11 +333,11 @@ static switch_status_t setup_formats(void)
map->ext = switch_core_permanent_strdup(info.extension);
map->uext = switch_core_permanent_strdup(info.extension);
map->format = info.format;
for(p = map->ext; *p; p++) {
*p = (char)tolower(*p);
for (p = map->ext; *p; p++) {
*p = (char) tolower(*p);
}
for(p = map->uext; *p; p++) {
*p = (char)toupper(*p);
for (p = map->uext; *p; p++) {
*p = (char) toupper(*p);
}
switch_core_hash_insert(globals.format_hash, map->ext, map);
switch_core_hash_insert(globals.format_hash, map->uext, map);
@@ -339,16 +345,16 @@ static switch_status_t setup_formats(void)
}
format = info.format;
for (s = 0; s < subtype_count; s++) {
for (s = 0; s < subtype_count; s++) {
info.format = s;
sf_command(NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof(info));
format = (format & SF_FORMAT_TYPEMASK) | info.format;
sfinfo.format = format;
/*
if (sf_format_check(&sfinfo)) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, " %s\n", info.name);
}
*/
if (sf_format_check(&sfinfo)) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, " %s\n", info.name);
}
*/
}
}
@@ -359,12 +365,13 @@ static switch_status_t setup_formats(void)
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_NOTICE,
"================================================================================\n");
"================================================================================\n");
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
@@ -373,7 +380,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
}
switch_core_hash_init(&globals.format_hash, module_pool);
if (setup_formats() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
+46 -44
View File
@@ -39,16 +39,17 @@
//#include <gc/gc.h>
#include <switch.h>
#define SWITCH_MONO_MODULES "mono/"
#define SWITCH_MONO_MODULES "mono/"
#define SWITCH_MONO_LIBDIR "lib/"
#define SWITCH_MONO_ASSEMBLY "FreeSwitch.dll"
/* Module functions */
switch_status_t mod_mono_load_modules(const char *module_dir);
MonoClass* mod_mono_find_assembly_class(MonoImage *image);
MonoClass *mod_mono_find_assembly_class(MonoImage * image);
/* Managed functions */
void mod_mono_switch_console_printf(switch_text_channel_t channel, char *file, const char *func, int line, char *fmt, char *msg);
void mod_mono_switch_console_printf(switch_text_channel_t channel, char *file, const char *func, int line, char *fmt,
char *msg);
static const char modname[] = "mod_mono";
static switch_memory_pool_t *mono_pool = NULL;
@@ -61,7 +62,7 @@ static struct {
typedef struct {
MonoAssembly *assembly;
MonoClass *class;
MonoObject *object;
MonoObject *object;
} mono_plugin;
static switch_loadable_module_interface_t mono_module_interface = {
@@ -74,7 +75,8 @@ static switch_loadable_module_interface_t mono_module_interface = {
* This function will initialise the memory pool and plugin hash for this module,
* it will then initialise a new mono domain.
*/
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **interface,
char *filename)
{
*interface = &mono_module_interface;
@@ -83,23 +85,24 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate memory pool\n");
return SWITCH_STATUS_FALSE;
}
/* Initialise plugin hash */
if (switch_core_hash_init(&globals.plugins, mono_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not initialise plugins hash\n");
return SWITCH_STATUS_FALSE;
}
}
/* Construct the path to the FreeSwitch assembly, then check to make sure it exists */
switch_size_t assembly_dir_len = strlen(SWITCH_GLOBAL_dirs.base_dir) + strlen(SWITCH_MONO_LIBDIR) + 2; /* Account for / and \0 */
switch_size_t assembly_dir_len = strlen(SWITCH_GLOBAL_dirs.base_dir) + strlen(SWITCH_MONO_LIBDIR) + 2; /* Account for / and \0 */
switch_size_t assembly_file_len = assembly_dir_len + strlen(SWITCH_MONO_ASSEMBLY);
char *assembly_dir = (char *) switch_core_alloc(mono_pool, assembly_dir_len);
char *assembly_dir = (char *) switch_core_alloc(mono_pool, assembly_dir_len);
char *assembly_file = (char *) switch_core_alloc(mono_pool, assembly_file_len);
apr_finfo_t *assembly_finfo = (apr_finfo_t *) switch_core_alloc(mono_pool, sizeof(*assembly_finfo));
snprintf(assembly_dir, assembly_dir_len, "%s/%s", SWITCH_GLOBAL_dirs.base_dir, SWITCH_MONO_LIBDIR);
snprintf(assembly_file, assembly_file_len, "%s/%s%s", SWITCH_GLOBAL_dirs.base_dir, SWITCH_MONO_LIBDIR, SWITCH_MONO_ASSEMBLY);
snprintf(assembly_file, assembly_file_len, "%s/%s%s", SWITCH_GLOBAL_dirs.base_dir, SWITCH_MONO_LIBDIR,
SWITCH_MONO_ASSEMBLY);
if (apr_stat(assembly_finfo, assembly_file, 0, mono_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Could not find FreeSwitch.NET assembly\n");
@@ -108,22 +111,21 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
/* Mono wants to know where it will be able to find the FreeSwitch assembly if it's not in the GAC */
if (getenv("MONO_PATH") != NULL) {
switch_size_t mono_path_len = strlen(getenv("MONO_PATH")) + strlen(assembly_dir) + 2; /* Account for : and \0 */
switch_size_t mono_path_len = strlen(getenv("MONO_PATH")) + strlen(assembly_dir) + 2; /* Account for : and \0 */
char *mono_path = (char *) switch_core_alloc(mono_pool, mono_path_len);
snprintf(mono_path, mono_path_len, "%s:%s", getenv("MONO_PATH"), assembly_dir);
setenv("MONO_PATH", mono_path, 1);
}
else
} else
setenv("MONO_PATH", assembly_dir, 1);
/* Now find where our managed modules are */
switch_size_t module_dir_len = strlen(SWITCH_GLOBAL_dirs.mod_dir) + strlen(SWITCH_MONO_MODULES) + 2; /* Account for / and \0 */
switch_size_t module_dir_len = strlen(SWITCH_GLOBAL_dirs.mod_dir) + strlen(SWITCH_MONO_MODULES) + 2; /* Account for / and \0 */
char *module_dir = (char *) switch_core_alloc(mono_pool, module_dir_len);
snprintf(module_dir, module_dir_len, "%s/%s", SWITCH_GLOBAL_dirs.mod_dir, SWITCH_MONO_MODULES);
/* Initialise the mono domain */
if (!(globals.domain = mono_jit_init("freeswitch"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initialising mono runtime\n");
@@ -139,7 +141,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
return SWITCH_STATUS_FALSE;
}
/* Finally, go through and initialise each plugin before returning SUCCESS */
/* Finally, go through and initialise each plugin before returning SUCCESS */
switch_hash_index_t *p = NULL;
for (p = switch_hash_first(mono_pool, globals.plugins); p; p = switch_hash_next(p)) {
@@ -150,10 +152,10 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
switch_hash_this(p, &key, key_length, &value);
plugin = (mono_plugin *) value;
mono_runtime_object_init(plugin->object);
}
return SWITCH_STATUS_SUCCESS;
}
@@ -175,16 +177,16 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
/*
* This function will load the managed modules
*
*/
*/
switch_status_t mod_mono_load_modules(const char *module_dir)
{
apr_finfo_t *module_finfo = (apr_finfo_t *) switch_core_alloc(mono_pool, sizeof(*module_finfo));
if (apr_stat(module_finfo, module_dir, 0, mono_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not access module dir!.\n");
return SWITCH_STATUS_FALSE;
}
apr_dir_t *module_dir_handle;
char *file;
size_t len;
@@ -196,22 +198,21 @@ switch_status_t mod_mono_load_modules(const char *module_dir)
MonoAssembly *assembly;
MonoImage *image;
gpointer iter;
iter=NULL;
mono_plugin *plugin=NULL;
iter = NULL;
mono_plugin *plugin = NULL;
if (apr_dir_open(&module_dir_handle, module_dir, mono_pool) != SWITCH_STATUS_SUCCESS)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Could not open directory: %s\n", module_dir);
/* Read the modules directory */
while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == SWITCH_STATUS_SUCCESS)
{
while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == SWITCH_STATUS_SUCCESS) {
assembly = (MonoAssembly *) switch_core_alloc(mono_pool, sizeof(assembly));
image = (MonoImage *) switch_core_alloc(mono_pool, sizeof(image));
const char *fname = finfo.fname;
if (finfo.filetype != APR_REG)
continue;
if (!fname)
fname = finfo.name;
@@ -222,7 +223,7 @@ switch_status_t mod_mono_load_modules(const char *module_dir)
continue;
len = strlen(module_dir) + strlen(fname) + 2;
file = (char *)switch_core_alloc(mono_pool, len);
file = (char *) switch_core_alloc(mono_pool, len);
snprintf(file, len, "%s%s", module_dir, fname);
/* Attempt to open the assembly */
@@ -233,53 +234,54 @@ switch_status_t mod_mono_load_modules(const char *module_dir)
continue;
}
/* Get the image from assembly */
/* Get the image from assembly */
image = mono_assembly_get_image(assembly);
plugin = (mono_plugin *)switch_core_alloc(mono_pool, sizeof(*plugin));
plugin = (mono_plugin *) switch_core_alloc(mono_pool, sizeof(*plugin));
plugin->assembly = assembly;
plugin->class = mod_mono_find_assembly_class(mono_assembly_get_image(plugin->assembly));
plugin->class = mod_mono_find_assembly_class(mono_assembly_get_image(plugin->assembly));
if (!plugin->class)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No plugin class\n");
plugin->object = mono_object_new(globals.domain, plugin->class);
switch_core_hash_insert(globals.plugins, (char *) mono_image_get_name(mono_assembly_get_image(assembly)), plugin);
switch_core_hash_insert(globals.plugins, (char *) mono_image_get_name(mono_assembly_get_image(assembly)),
plugin);
plugin = NULL;
}
}
return SWITCH_STATUS_SUCCESS;
}
/*
*
*/
MonoClass* mod_mono_find_assembly_class(MonoImage *image)
*/
MonoClass *mod_mono_find_assembly_class(MonoImage * image)
{
MonoClass *class, *parent_class = NULL;
int i, total;
total = mono_image_get_table_rows(image, MONO_TABLE_TYPEDEF);
for (i = 1; i <= total; ++i)
{
for (i = 1; i <= total; ++i) {
class = mono_class_get(image, MONO_TOKEN_TYPE_DEF | i);
parent_class = mono_class_get_parent(class);
if (parent_class)
if (parent_class)
if (!strcmp("Module", mono_class_get_name(parent_class)))
return class;
}
return NULL;
}
/*
*
*/
void mono_switch_console_printf(switch_text_channel_t channel, char *file, const char *func, int line, char *fmt, char *msg)
void mono_switch_console_printf(switch_text_channel_t channel, char *file, const char *func, int line, char *fmt,
char *msg)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, msg);
}
+11 -11
View File
@@ -50,7 +50,7 @@ static struct {
} globals;
static void destroy_perl(PerlInterpreter **to_destroy)
static void destroy_perl(PerlInterpreter ** to_destroy)
{
perl_destruct(*to_destroy);
perl_free(*to_destroy);
@@ -59,7 +59,7 @@ static void destroy_perl(PerlInterpreter **to_destroy)
static PerlInterpreter *clone_perl(void)
{
return perl_clone(globals.my_perl, CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
return perl_clone(globals.my_perl, CLONEf_COPY_STACKS | CLONEf_KEEP_PTR_TABLE);
}
@@ -69,9 +69,7 @@ static void perl_function(switch_core_session_t *session, char *data)
char code[1024];
PerlInterpreter *my_perl = clone_perl();
sprintf(code, "package fs_perl;\n"
"$SWITCH_ENV{UUID} = \"%s\";\n"
"chdir(\"%s/perl\");\n",
uuid, SWITCH_GLOBAL_dirs.base_dir);
"$SWITCH_ENV{UUID} = \"%s\";\n" "chdir(\"%s/perl\");\n", uuid, SWITCH_GLOBAL_dirs.base_dir);
Perl_eval_pv(my_perl, code, TRUE);
@@ -84,8 +82,9 @@ static const switch_application_interface_t perl_application_interface = {
/*.interface_name */ "perl",
/*.application_function */ perl_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE, /* should we support no media mode here? If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
/*.next*/ NULL
/* flags */ SAF_NONE,
/* should we support no media mode here? If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
/*.next */ NULL
};
static switch_loadable_module_interface_t perl_module_interface = {
@@ -102,7 +101,7 @@ static switch_loadable_module_interface_t perl_module_interface = {
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
{
if (globals.my_perl) {
perl_destruct(globals.my_perl);
@@ -113,12 +112,13 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
PerlInterpreter *my_perl;
char code[1024];
if (!(my_perl = perl_alloc())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not allocate perl intrepreter\n");
return SWITCH_STATUS_MEMERR;
@@ -131,7 +131,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
perl_run(my_perl);
globals.my_perl = my_perl;
sprintf(code, "use lib '%s/perl';use fs_perl;use freeswitch\n", SWITCH_GLOBAL_dirs.base_dir);
Perl_eval_pv(my_perl, code, TRUE);
Perl_eval_pv(my_perl, code, TRUE);
/* connect my internal structure to the blank pointer passed to me */
+3 -4
View File
@@ -4,12 +4,11 @@
#include <EXTERN.h>
#include <perl.h>
EXTERN_C void xs_init (pTHX);
EXTERN_C void xs_init(pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void boot_DynaLoader(pTHX_ CV * cv);
EXTERN_C void
xs_init(pTHX)
EXTERN_C void xs_init(pTHX)
{
char *file = __FILE__;
dXSUB_SYS;
File diff suppressed because it is too large. Load diff
@@ -1,4 +1,4 @@
#ifndef FREESWITCH_PYTHON_H
#ifndef FREESWITCH_PYTHON_H
#define FREESWITCH_PYTHON_H
#include <Python.h>
@@ -9,45 +9,41 @@ extern "C" {
#include <switch.h>
extern void *globalDTMFCallbackFunction;
extern switch_status_t PythonDTMFCallback(switch_core_session *session,
void *input,
switch_input_type_t itype,
void *buf,
unsigned int buflen);
extern void *globalDTMFCallbackFunction;
extern switch_status_t PythonDTMFCallback(switch_core_session * session,
void *input, switch_input_type_t itype, void *buf, unsigned int buflen);
class SessionContainer {
private:
switch_core_session_t *session;
switch_channel_t *channel;
char *uuid;
PyObject *dtmfCallbackFunction;
char *tts_name;
char *voice_name;
public:
SessionContainer(char *uuid);
~SessionContainer();
void console_log(char *level_str, char *msg);
void console_clean_log(char *msg);
int answer();
int pre_answer();
void hangup(char *cause);
void set_variable(char *var, char *val);
void get_variable(char *var, char *val);
void set_state(char *state);
int play_file(char *file, char *timer_name);
void set_dtmf_callback(PyObject *pyfunc);
int speak_text(char *text);
void set_tts_parms(char *tts_name, char *voice_name);
int get_digits(char *dtmf_buf, int len, char *terminators, char *terminator, int timeout);
int transfer(char *extensions, char *dialplan, char *context);
int play_and_get_digits(int min_digits, int max_digits, int max_tries, int timeout, char *terminators,
char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex);
protected:
};
class SessionContainer {
private:
switch_core_session_t *session;
switch_channel_t *channel;
char *uuid;
PyObject *dtmfCallbackFunction;
char *tts_name;
char *voice_name;
public:
SessionContainer(char *uuid);
~SessionContainer();
void console_log(char *level_str, char *msg);
void console_clean_log(char *msg);
int answer();
int pre_answer();
void hangup(char *cause);
void set_variable(char *var, char *val);
void get_variable(char *var, char *val);
void set_state(char *state);
int play_file(char *file, char *timer_name);
void set_dtmf_callback(PyObject * pyfunc);
int speak_text(char *text);
void set_tts_parms(char *tts_name, char *voice_name);
int get_digits(char *dtmf_buf, int len, char *terminators, char *terminator, int timeout);
int transfer(char *extensions, char *dialplan, char *context);
int play_and_get_digits(int min_digits, int max_digits, int max_tries, int timeout, char *terminators,
char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex);
protected:
};
#ifdef __cplusplus
}
#endif
#endif
+31 -29
View File
@@ -50,54 +50,55 @@ const char modname[] = "mod_python";
static void python_function(switch_core_session_t *session, char *data)
{
char *uuid = switch_core_session_get_uuid(session);
char *argv[1];
FILE* pythonfile;
char *argv[1];
FILE *pythonfile;
argv[0] = uuid;
pythonfile = fopen(data, "r");
argv[0] = uuid;
pythonfile = fopen(data, "r");
Py_Initialize();
PySys_SetArgv(1, argv);
init_freeswitch();
PyRun_SimpleFile(pythonfile, "");
Py_Finalize();
Py_Initialize();
PySys_SetArgv(1, argv);
init_freeswitch();
PyRun_SimpleFile(pythonfile, "");
Py_Finalize();
}
static switch_status_t launch_python(char *text, switch_core_session_t *session, switch_stream_handle_t *stream)
{
FILE* pythonfile;
FILE *pythonfile;
if (switch_strlen_zero(text)) {
stream->write_function(stream, "USAGE: %s\n", python_run_interface.syntax);
return SWITCH_STATUS_SUCCESS;
}
if (switch_strlen_zero(text)) {
stream->write_function(stream, "USAGE: %s\n", python_run_interface.syntax);
return SWITCH_STATUS_SUCCESS;
}
pythonfile = fopen(text, "r");
pythonfile = fopen(text, "r");
Py_Initialize();
init_freeswitch();
PyRun_SimpleFile(pythonfile, "");
Py_Finalize();
Py_Initialize();
init_freeswitch();
PyRun_SimpleFile(pythonfile, "");
Py_Finalize();
stream->write_function(stream, "OK\n");
return SWITCH_STATUS_SUCCESS;
stream->write_function(stream, "OK\n");
return SWITCH_STATUS_SUCCESS;
}
static const switch_application_interface_t python_application_interface = {
/*.interface_name */ "python",
/*.application_function */ python_function,
NULL, NULL, NULL,
/* flags */ SAF_NONE, /* should we support no media mode here? If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
/*.next*/ NULL
/* flags */ SAF_NONE,
/* should we support no media mode here? If so, we need to detect the mode, and either disable the media functions or indicate media if/when we need */
/*.next */ NULL
};
static switch_api_interface_t python_run_interface = {
/*.interface_name */ "python",
/*.desc */ "run a python script",
/*.function */ launch_python,
/*.syntax */ "python </path/to/script>",
/*.next */ NULL
/*.interface_name */ "python",
/*.desc */ "run a python script",
/*.function */ launch_python,
/*.syntax */ "python </path/to/script>",
/*.next */ NULL
};
static switch_loadable_module_interface_t python_module_interface = {
@@ -113,7 +114,8 @@ static switch_loadable_module_interface_t python_module_interface = {
/*.directory_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &python_module_interface;
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -52,18 +52,14 @@
#include "jsscript.h"
SWITCH_BEGIN_EXTERN_C
#define JS_BUFFER_SIZE 1024 * 32
#define JS_BLOCK_SIZE JS_BUFFER_SIZE
#ifdef __ICC
#pragma warning (disable:310 193 1418)
#endif
#ifdef _MSC_VER
#pragma warning(disable: 4311)
#endif
#ifdef WIN32
#if defined(SWITCH_SM_DECLARE_STATIC)
#define SWITCH_SM_DECLARE(type) type __cdecl
@@ -75,8 +71,7 @@ SWITCH_BEGIN_EXTERN_C
#else //not win32
#define SWITCH_SM_DECLARE(type) type
#endif
int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval)
int eval_some_js(char *code, JSContext * cx, JSObject * obj, jsval * rval)
{
JSScript *script = NULL;
char *cptr;
@@ -101,22 +96,22 @@ int eval_some_js(char *code, JSContext *cx, JSObject *obj, jsval *rval)
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open File: %s\n", script_name);
}
}
}
}
if (script) {
result = JS_ExecuteScript(cx, obj, script, rval) == JS_TRUE ? 1 : 0;
JS_DestroyScript(cx, script);
} else {
result = -1;
}
switch_safe_free(path);
return result;
}
typedef switch_status_t(*spidermonkey_load_t)(JSContext *cx, JSObject *obj);
typedef switch_status_t (*spidermonkey_load_t) (JSContext * cx, JSObject * obj);
struct sm_module_interface {
const char *name;
@@ -125,7 +120,7 @@ struct sm_module_interface {
};
typedef struct sm_module_interface sm_module_interface_t;
typedef switch_status_t(*spidermonkey_init_t)(const sm_module_interface_t **module_interface);
typedef switch_status_t (*spidermonkey_init_t) (const sm_module_interface_t ** module_interface);
struct js_session {
switch_core_session_t *session;
@@ -139,6 +134,4 @@ struct js_session {
SWITCH_END_EXTERN_C
#endif
@@ -34,19 +34,19 @@
static const char modname[] = "CoreDB";
struct db_obj {
switch_memory_pool_t *pool;
switch_core_db_t *db;
switch_core_db_stmt_t *stmt;
char *dbname;
char code_buffer[2048];
JSContext *cx;
JSObject *obj;
switch_memory_pool_t *pool;
switch_core_db_t *db;
switch_core_db_stmt_t *stmt;
char *dbname;
char code_buffer[2048];
JSContext *cx;
JSObject *obj;
};
/* DB Object */
/*********************************************************************************/
static JSBool db_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool db_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
switch_memory_pool_t *pool;
switch_core_db_t *db;
@@ -55,7 +55,7 @@ static JSBool db_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
if (argc > 0) {
char *dbname = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
switch_core_new_memory_pool(&pool);
if (! (db = switch_core_db_open_file(dbname))) {
if (!(db = switch_core_db_open_file(dbname))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Open DB!\n");
switch_core_destroy_memory_pool(&pool);
return JS_FALSE;
@@ -73,10 +73,10 @@ static JSBool db_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv
return JS_FALSE;
}
static void db_destroy(JSContext *cx, JSObject *obj)
static void db_destroy(JSContext * cx, JSObject * obj)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
if (dbo) {
switch_memory_pool_t *pool = dbo->pool;
if (dbo->stmt) {
@@ -85,7 +85,7 @@ static void db_destroy(JSContext *cx, JSObject *obj)
}
switch_core_db_close(dbo->db);
switch_core_destroy_memory_pool(&pool);
pool = NULL;
pool = NULL;
}
}
@@ -100,7 +100,7 @@ static int db_callback(void *pArg, int argc, char **argv, char **columnNames)
snprintf(code, sizeof(code), "~var _Db_RoW_ = {}");
eval_some_js(code, dbo->cx, dbo->obj, &rval);
for(x=0; x < argc; x++) {
for (x = 0; x < argc; x++) {
snprintf(code, sizeof(code), "~_Db_RoW_[\"%s\"] = \"%s\"", columnNames[x], argv[x]);
eval_some_js(code, dbo->cx, dbo->obj, &rval);
}
@@ -110,51 +110,51 @@ static int db_callback(void *pArg, int argc, char **argv, char **columnNames)
snprintf(code, sizeof(code), "~delete _Db_RoW_");
eval_some_js(code, dbo->cx, dbo->obj, &rval);
return 0;
}
static JSBool db_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool db_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
struct db_obj *dbo = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
if (argc > 0) {
char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char *err = NULL;
void *arg = NULL;
switch_core_db_callback_func_t cb_func = NULL;
if (argc > 0) {
char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
char *err = NULL;
void *arg = NULL;
switch_core_db_callback_func_t cb_func = NULL;
if (argc > 1) {
char *js_func = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
switch_copy_string(dbo->code_buffer, js_func, sizeof(dbo->code_buffer));
cb_func = db_callback;
arg = dbo;
}
if (argc > 1) {
char *js_func = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
switch_copy_string(dbo->code_buffer, js_func, sizeof(dbo->code_buffer));
cb_func = db_callback;
arg = dbo;
}
switch_core_db_exec(dbo->db, sql, cb_func, arg, &err);
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", err);
switch_core_db_free(err);
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
}
}
return JS_TRUE;
switch_core_db_exec(dbo->db, sql, cb_func, arg, &err);
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", err);
switch_core_db_free(err);
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
}
}
return JS_TRUE;
}
static JSBool db_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool db_next(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
if (dbo->stmt) {
if (dbo->stmt) {
int running = 1;
while (running < 5000) {
int result = switch_core_db_step(dbo->stmt);
if (result == SWITCH_CORE_DB_ROW) {
*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
break;
} else if (result == SWITCH_CORE_DB_BUSY) {
running++;
@@ -169,7 +169,7 @@ static JSBool db_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsv
return JS_TRUE;
}
static JSBool db_fetch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool db_fetch(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
int colcount = switch_core_db_column_count(dbo->stmt);
@@ -179,16 +179,15 @@ static JSBool db_fetch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
snprintf(code, sizeof(code), "~var _dB_RoW_DaTa_ = {}");
eval_some_js(code, dbo->cx, dbo->obj, rval);
if (*rval == JS_FALSE) {
return JS_TRUE;
return JS_TRUE;
}
for (x = 0; x < colcount; x++) {
snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"",
(char *) switch_core_db_column_name(dbo->stmt, x),
(char *) switch_core_db_column_text(dbo->stmt, x));
snprintf(code, sizeof(code), "~_dB_RoW_DaTa_[\"%s\"] = \"%s\"",
(char *) switch_core_db_column_name(dbo->stmt, x), (char *) switch_core_db_column_text(dbo->stmt, x));
eval_some_js(code, dbo->cx, dbo->obj, rval);
if (*rval == JS_FALSE) {
return JS_TRUE;
return JS_TRUE;
}
}
@@ -198,11 +197,11 @@ static JSBool db_fetch(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
}
static JSBool db_prepare(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool db_prepare(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct db_obj *dbo = JS_GetPrivate(cx, obj);
*rval = BOOLEAN_TO_JSVAL( JS_FALSE );
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
if (dbo->stmt) {
switch_core_db_finalize(dbo->stmt);
@@ -211,10 +210,10 @@ static JSBool db_prepare(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
if (argc > 0) {
char *sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
if(switch_core_db_prepare(dbo->db, sql, -1, &dbo->stmt, 0)) {
if (switch_core_db_prepare(dbo->db, sql, -1, &dbo->stmt, 0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error %s\n", switch_core_db_errmsg(dbo->db));
} else {
*rval = BOOLEAN_TO_JSVAL( JS_TRUE );
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
}
}
return JS_TRUE;
@@ -234,27 +233,27 @@ static JSFunctionSpec db_methods[] = {
static JSPropertySpec db_props[] = {
{"path", DB_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
{"path", DB_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
{0}
};
static JSBool db_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
static JSBool db_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
JSBool res = JS_TRUE;
struct db_obj *dbo = JS_GetPrivate(cx, obj);
char *name;
int param = 0;
name = JS_GetStringBytes(JS_ValueToString(cx, id));
/* numbers are our props anything else is a method */
if (name[0] >= 48 && name[0] <= 57) {
param = atoi(name);
} else {
return JS_TRUE;
}
switch(param) {
/* numbers are our props anything else is a method */
if (name[0] >= 48 && name[0] <= 57) {
param = atoi(name);
} else {
return JS_TRUE;
}
switch (param) {
case DB_NAME:
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dbo->dbname));
break;
@@ -264,38 +263,28 @@ static JSBool db_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
JSClass db_class = {
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, db_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, db_destroy, NULL, NULL, NULL,
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, db_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, db_destroy, NULL, NULL, NULL,
db_construct
};
switch_status_t db_load(JSContext *cx, JSObject *obj)
switch_status_t db_load(JSContext * cx, JSObject * obj)
{
JS_InitClass(cx,
obj,
NULL,
&db_class,
db_construct,
3,
db_props,
db_methods,
db_props,
db_methods
);
JS_InitClass(cx, obj, NULL, &db_class, db_construct, 3, db_props, db_methods, db_props, db_methods);
return SWITCH_STATUS_SUCCESS;
}
const sm_module_interface_t DB_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ db_load,
/*.next*/ NULL
/*.spidermonkey_load */ db_load,
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &DB_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -40,9 +40,10 @@ static const char modname[] = "etpan";
#define B64BUFFLEN 1024
static const char c64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static int write_buf(int fd, char *buf) {
static int write_buf(int fd, char *buf)
{
int len = (int)strlen(buf);
int len = (int) strlen(buf);
if (fd && write(fd, buf, len) != len) {
close(fd);
return 0;
@@ -53,17 +54,17 @@ static int write_buf(int fd, char *buf) {
/* etpan Object */
/*********************************************************************************/
static JSBool etpan_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool etpan_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
return JS_TRUE;
}
static void etpan_destroy(JSContext *cx, JSObject *obj)
static void etpan_destroy(JSContext * cx, JSObject * obj)
{
}
#if 0
static JSBool etpan_my_method(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool etpan_my_method(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
return JS_FALSE;
}
@@ -73,27 +74,26 @@ enum etpan_tinyid {
etpan_NAME
};
static JSBool js_email(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool js_email(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
char *to = NULL, *from = NULL, *headers, *body = NULL, *file = NULL;
char *bound = "XXXX_boundary_XXXX";
char filename[80], buf[B64BUFFLEN];
int fd = 0, ifd = 0;
int x=0, y=0, bytes=0, ilen=0;
unsigned int b=0, l=0;
int x = 0, y = 0, bytes = 0, ilen = 0;
unsigned int b = 0, l = 0;
unsigned char in[B64BUFFLEN];
unsigned char out[B64BUFFLEN+512];
unsigned char out[B64BUFFLEN + 512];
char *path = NULL;
if (
argc > 3 &&
if (argc > 3 &&
(from = JS_GetStringBytes(JS_ValueToString(cx, argv[0]))) &&
(to = JS_GetStringBytes(JS_ValueToString(cx, argv[1]))) &&
(headers = JS_GetStringBytes(JS_ValueToString(cx, argv[2]))) &&
(body = JS_GetStringBytes(JS_ValueToString(cx, argv[3])))
(body = JS_GetStringBytes(JS_ValueToString(cx, argv[3])))
) {
if ( argc > 4) {
if (argc > 4) {
file = JS_GetStringBytes(JS_ValueToString(cx, argv[4]));
}
snprintf(filename, 80, "%smail.%ld%04x", SWITCH_GLOBAL_dirs.temp_dir, time(NULL), rand() & 0xffff);
@@ -110,22 +110,22 @@ static JSBool js_email(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
return JS_FALSE;
}
}
if (!write_buf(fd, headers))
return JS_FALSE;
if (!write_buf(fd, "\n\n"))
return JS_FALSE;
if (file) {
snprintf(buf, B64BUFFLEN, "--%s\nContent-Type: text/plain\n\n", bound);
if (!write_buf(fd, buf))
return JS_FALSE;
}
if (!write_buf(fd, body))
return JS_FALSE;
if (file) {
snprintf(buf, B64BUFFLEN, "\n\n--%s\nContent-Type: application/octet-stream\n"
"Content-Transfer-Encoding: base64\n"
@@ -133,40 +133,41 @@ static JSBool js_email(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
"Content-Disposition: attachment; filename=\"%s\"\n\n", bound, file);
if (!write_buf(fd, buf))
return JS_FALSE;
while((ilen=read(ifd, in, B64BUFFLEN))) {
for (x=0;x<ilen;x++) {
b = (b<<8) + in[x];
while ((ilen = read(ifd, in, B64BUFFLEN))) {
for (x = 0; x < ilen; x++) {
b = (b << 8) + in[x];
l += 8;
while (l >= 6) {
out[bytes++] = c64[(b>>(l-=6))%64];
if (++y!=72)
out[bytes++] = c64[(b >> (l -= 6)) % 64];
if (++y != 72)
continue;
out[bytes++] = '\n';
y=0;
y = 0;
}
}
if (write(fd, &out, bytes) != bytes) {
if (write(fd, &out, bytes) != bytes) {
return -1;
} else
bytes=0;
} else
bytes = 0;
}
if (l > 0) {
out[bytes++] = c64[((b%16)<<(6-l))%64];
out[bytes++] = c64[((b % 16) << (6 - l)) % 64];
}
if (l != 0) while (l < 6) {
out[bytes++] = '=', l += 2;
}
if (write(fd, &out, bytes) != bytes) {
if (l != 0)
while (l < 6) {
out[bytes++] = '=', l += 2;
}
if (write(fd, &out, bytes) != bytes) {
return -1;
}
}
if (file) {
snprintf(buf, B64BUFFLEN, "\n\n--%s--\n.\n", bound);
if (!write_buf(fd, buf))
@@ -192,23 +193,23 @@ static JSBool js_email(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, js
}
return JS_TRUE;
}
return JS_FALSE;
}
static JSFunctionSpec etpan_methods[] = {
// {"myMethod", odbc_my_method, 1},
// {"myMethod", odbc_my_method, 1},
{0}
};
static JSPropertySpec etpan_props[] = {
// {"name", etpan_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
// {"name", etpan_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
{0}
};
static JSBool etpan_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
static JSBool etpan_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
JSBool res = JS_TRUE;
@@ -216,44 +217,35 @@ static JSBool etpan_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *v
}
JSClass etpan_class = {
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, etpan_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, etpan_destroy, NULL, NULL, NULL,
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, etpan_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, etpan_destroy, NULL, NULL, NULL,
etpan_construct
};
static JSFunctionSpec etpan_functions[] = {
{"email", js_email, 2},
{"email", js_email, 2},
{0}
};
switch_status_t etpan_load(JSContext *cx, JSObject *obj)
switch_status_t etpan_load(JSContext * cx, JSObject * obj)
{
JS_DefineFunctions(cx, obj, etpan_functions);
JS_InitClass(cx,
obj,
NULL,
&etpan_class,
etpan_construct,
3,
etpan_props,
etpan_methods,
etpan_props,
etpan_methods
);
obj, NULL, &etpan_class, etpan_construct, 3, etpan_props, etpan_methods, etpan_props, etpan_methods);
return SWITCH_STATUS_SUCCESS;
}
const sm_module_interface_t etpan_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ etpan_load,
/*.next*/ NULL
/*.spidermonkey_load */ etpan_load,
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &etpan_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -271,259 +263,258 @@ int smtp_tls = 0;
int smtp_esmtp = 1;
struct mem_message {
char *data;
size_t len;
MMAPString *mstring;
char *data;
size_t len;
MMAPString *mstring;
};
#define BLOCKSIZE 4096
int collect(struct mem_message *message) {
struct stat sb;
int len;
int collect(struct mem_message *message)
{
struct stat sb;
int len;
memset(message, 0, sizeof(struct mem_message));
memset(message, 0, sizeof(struct mem_message));
#ifndef MMAP_UNAVAILABLE
/* if stdin is a file whose size is known, try to mmap it */
if (!fstat(0, &sb) && S_ISREG(sb.st_mode) && sb.st_size >= 0) {
message->len = sb.st_size;
if ((message->data = mmap(NULL, message->len, PROT_READ, MAP_SHARED,
STDIN_FILENO, 0)) != MAP_FAILED)
return 0;
}
/* if stdin is a file whose size is known, try to mmap it */
if (!fstat(0, &sb) && S_ISREG(sb.st_mode) && sb.st_size >= 0) {
message->len = sb.st_size;
if ((message->data = mmap(NULL, message->len, PROT_READ, MAP_SHARED, STDIN_FILENO, 0)) != MAP_FAILED)
return 0;
}
#endif
/* read the buffer from stdin by blocks, until EOF or error.
save the message in a mmap_string */
if ((message->mstring = mmap_string_sized_new(BLOCKSIZE)) == NULL) {
perror("mmap_string_new");
goto error;
}
message->len = 0;
/* read the buffer from stdin by blocks, until EOF or error.
save the message in a mmap_string */
if ((message->mstring = mmap_string_sized_new(BLOCKSIZE)) == NULL) {
perror("mmap_string_new");
goto error;
}
message->len = 0;
while ((len = read(STDIN_FILENO,
message->mstring->str + message->len, BLOCKSIZE)) > 0) {
message->len += len;
/* reserve room for next block */
if ((mmap_string_set_size(message->mstring,
message->len + BLOCKSIZE)) == NULL) {
perror("mmap_string_set_size");
goto error;
}
}
while ((len = read(STDIN_FILENO, message->mstring->str + message->len, BLOCKSIZE)) > 0) {
message->len += len;
/* reserve room for next block */
if ((mmap_string_set_size(message->mstring, message->len + BLOCKSIZE)) == NULL) {
perror("mmap_string_set_size");
goto error;
}
}
if (len == 0) {
message->data = message->mstring->str;
return 0; /* OK */
}
if (len == 0) {
message->data = message->mstring->str;
return 0; /* OK */
}
perror("read");
perror("read");
error:
if (message->mstring != NULL)
mmap_string_free(message->mstring);
return -1;
error:
if (message->mstring != NULL)
mmap_string_free(message->mstring);
return -1;
}
char *guessfrom() {
char *guessfrom()
{
#ifndef _MSC_VER
uid_t uid;
struct passwd *pw;
char hostname[256];
int len;
char *gfrom;
uid_t uid;
struct passwd *pw;
char hostname[256];
int len;
char *gfrom;
if (gethostname(hostname, sizeof(hostname))) {
perror("gethostname");
return NULL;
}
hostname[sizeof(hostname) - 1] = '\0';
if (gethostname(hostname, sizeof(hostname))) {
perror("gethostname");
return NULL;
}
hostname[sizeof(hostname) - 1] = '\0';
uid = getuid();
pw = getpwuid(uid);
len = ((pw != NULL) ? strlen(pw->pw_name) : 12)
+ strlen(hostname) + 2;
uid = getuid();
pw = getpwuid(uid);
if ((gfrom = malloc(len)) == NULL) {
perror("malloc");
return NULL;
}
if (pw != NULL && pw->pw_name != NULL)
snprintf(gfrom, len, "%s@%s", pw->pw_name, hostname);
else
snprintf(gfrom, len, "#%u@%s", uid, hostname);
return gfrom;
len = ((pw != NULL) ? strlen(pw->pw_name) : 12)
+ strlen(hostname) + 2;
if ((gfrom = malloc(len)) == NULL) {
perror("malloc");
return NULL;
}
if (pw != NULL && pw->pw_name != NULL)
snprintf(gfrom, len, "%s@%s", pw->pw_name, hostname);
else
snprintf(gfrom, len, "#%u@%s", uid, hostname);
return gfrom;
#else
return NULL;
#endif
}
void release(struct mem_message *message) {
if (message->mstring != NULL)
mmap_string_free(message->mstring);
void release(struct mem_message *message)
{
if (message->mstring != NULL)
mmap_string_free(message->mstring);
#ifndef MMAP_UNAVAILABLE
else if (message->data != NULL)
munmap(message->data, message->len);
else if (message->data != NULL)
munmap(message->data, message->len);
#endif
}
int send_message(char *data, size_t len, char**rcpts) {
int s = -1;
int ret;
char **r;
int esmtp = 0;
mailsmtp *smtp = NULL;
int send_message(char *data, size_t len, char **rcpts)
{
int s = -1;
int ret;
char **r;
int esmtp = 0;
mailsmtp *smtp = NULL;
if ((smtp = mailsmtp_new(0, NULL)) == NULL) {
perror("mailsmtp_new");
goto error;
}
if ((smtp = mailsmtp_new(0, NULL)) == NULL) {
perror("mailsmtp_new");
goto error;
}
/* first open the stream */
if ((ret = mailsmtp_socket_connect(smtp,
(smtp_server != NULL ? smtp_server : "localhost"),
smtp_port)) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_socket_connect: %s\n", mailsmtp_strerror(ret));
goto error;
}
/* then introduce ourselves */
if (smtp_esmtp && (ret = mailesmtp_ehlo(smtp)) == MAILSMTP_NO_ERROR)
esmtp = 1;
else if (!smtp_esmtp || ret == MAILSMTP_ERROR_NOT_IMPLEMENTED)
ret = mailsmtp_helo(smtp);
if (ret != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_helo: %s\n", mailsmtp_strerror(ret));
goto error;
}
/* first open the stream */
if ((ret = mailsmtp_socket_connect(smtp,
(smtp_server != NULL ? smtp_server : "localhost"),
smtp_port)) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_socket_connect: %s\n", mailsmtp_strerror(ret));
goto error;
}
if (esmtp && smtp_tls &&
(ret = mailsmtp_socket_starttls(smtp)) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_starttls: %s\n", mailsmtp_strerror(ret));
goto error;
}
if (esmtp && smtp_user != NULL &&
(ret = mailsmtp_auth(smtp, smtp_user,
(smtp_password != NULL) ? smtp_password : ""))
!= MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_auth: %s: %s\n", smtp_user, mailsmtp_strerror(ret));
goto error;
}
/* then introduce ourselves */
if (smtp_esmtp && (ret = mailesmtp_ehlo(smtp)) == MAILSMTP_NO_ERROR)
esmtp = 1;
else if (!smtp_esmtp || ret == MAILSMTP_ERROR_NOT_IMPLEMENTED)
ret = mailsmtp_helo(smtp);
if (ret != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_helo: %s\n", mailsmtp_strerror(ret));
goto error;
}
/* source */
if ((ret = (esmtp ?
mailesmtp_mail(smtp, smtp_from, 1, "etPanSMTPTest") :
mailsmtp_mail(smtp, smtp_from))) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_mail: %s, %s\n", smtp_from, mailsmtp_strerror(ret));
goto error;
}
/* recipients */
for (r = rcpts; *r != NULL; r++) {
if ((ret = (esmtp ?
mailesmtp_rcpt(smtp, *r,
MAILSMTP_DSN_NOTIFY_FAILURE|MAILSMTP_DSN_NOTIFY_DELAY,
NULL) :
mailsmtp_rcpt(smtp, *r))) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_rcpt: %s: %s\n", *r, mailsmtp_strerror(ret));
goto error;
}
}
/* message */
if ((ret = mailsmtp_data(smtp)) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_data: %s\n", mailsmtp_strerror(ret));
goto error;
}
if ((ret = mailsmtp_data_message(smtp, data, len)) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_data_message: %s\n", mailsmtp_strerror(ret));
goto error;
}
mailsmtp_free(smtp);
return 0;
if (esmtp && smtp_tls && (ret = mailsmtp_socket_starttls(smtp)) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_starttls: %s\n", mailsmtp_strerror(ret));
goto error;
}
error:
if (smtp != NULL)
mailsmtp_free(smtp);
if (s >= 0)
close(s);
return -1;
if (esmtp && smtp_user != NULL &&
(ret = mailsmtp_auth(smtp, smtp_user, (smtp_password != NULL) ? smtp_password : ""))
!= MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_auth: %s: %s\n", smtp_user, mailsmtp_strerror(ret));
goto error;
}
/* source */
if ((ret = (esmtp ?
mailesmtp_mail(smtp, smtp_from, 1, "etPanSMTPTest") :
mailsmtp_mail(smtp, smtp_from))) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_mail: %s, %s\n", smtp_from, mailsmtp_strerror(ret));
goto error;
}
/* recipients */
for (r = rcpts; *r != NULL; r++) {
if ((ret = (esmtp ?
mailesmtp_rcpt(smtp, *r,
MAILSMTP_DSN_NOTIFY_FAILURE | MAILSMTP_DSN_NOTIFY_DELAY,
NULL) : mailsmtp_rcpt(smtp, *r))) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_rcpt: %s: %s\n", *r, mailsmtp_strerror(ret));
goto error;
}
}
/* message */
if ((ret = mailsmtp_data(smtp)) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_data: %s\n", mailsmtp_strerror(ret));
goto error;
}
if ((ret = mailsmtp_data_message(smtp, data, len)) != MAILSMTP_NO_ERROR) {
fprintf(stderr, "mailsmtp_data_message: %s\n", mailsmtp_strerror(ret));
goto error;
}
mailsmtp_free(smtp);
return 0;
error:
if (smtp != NULL)
mailsmtp_free(smtp);
if (s >= 0)
close(s);
return -1;
}
int main(int argc, char **argv) {
struct mem_message message;
int index, r;
int main(int argc, char **argv)
{
struct mem_message message;
int index, r;
static struct option long_options[] = {
{"server", 1, 0, 's'},
{"port", 1, 0, 'p'},
{"user", 1, 0, 'u'},
{"password", 1, 0, 'v'},
{"from", 1, 0, 'f'},
{"tls", 0, 0, 'S'},
{"no-esmtp", 0, 0, 'E'},
};
static struct option long_options[] = {
{"server", 1, 0, 's'},
{"port", 1, 0, 'p'},
{"user", 1, 0, 'u'},
{"password", 1, 0, 'v'},
{"from", 1, 0, 'f'},
{"tls", 0, 0, 'S'},
{"no-esmtp", 0, 0, 'E'},
};
while(1) {
if ((r = getopt_long(argc, argv, "s:p:u:v:f:SE", long_options, &index)) < 0)
break;
switch (r) {
case 's':
if (smtp_server != NULL)
free(smtp_server);
smtp_server = strdup(optarg);
break;
case 'p':
smtp_port = (uint16_t) strtoul(optarg, NULL, 10);
break;
case 'u':
if (smtp_user != NULL)
free(smtp_user);
smtp_user = strdup(optarg);
break;
case 'v':
if (smtp_password != NULL)
free(smtp_password);
smtp_password = strdup(optarg);
break;
case 'f':
if (smtp_from != NULL)
free(smtp_from);
smtp_from = strdup(optarg);
break;
case 'S':
smtp_tls = 1;
break;
case 'E':
smtp_esmtp = 0;
break;
}
}
while (1) {
if ((r = getopt_long(argc, argv, "s:p:u:v:f:SE", long_options, &index)) < 0)
break;
switch (r) {
case 's':
if (smtp_server != NULL)
free(smtp_server);
smtp_server = strdup(optarg);
break;
case 'p':
smtp_port = (uint16_t) strtoul(optarg, NULL, 10);
break;
case 'u':
if (smtp_user != NULL)
free(smtp_user);
smtp_user = strdup(optarg);
break;
case 'v':
if (smtp_password != NULL)
free(smtp_password);
smtp_password = strdup(optarg);
break;
case 'f':
if (smtp_from != NULL)
free(smtp_from);
smtp_from = strdup(optarg);
break;
case 'S':
smtp_tls = 1;
break;
case 'E':
smtp_esmtp = 0;
break;
}
}
argc -= optind;
argv += optind;
argc -= optind;
argv += optind;
if (argc < 1) {
fprintf(stderr, "usage: smtpsend [-f from] [-u user] [-v password] [-s server] [-p port] [-S] <rcpts>...\n");
return EXIT_FAILURE;
}
if (argc < 1) {
fprintf(stderr, "usage: smtpsend [-f from] [-u user] [-v password] [-s server] [-p port] [-S] <rcpts>...\n");
return EXIT_FAILURE;
}
if (smtp_from == NULL && (smtp_from = guessfrom()) == NULL) {
fprintf(stderr, "can't guess a valid from, please use -f option.\n");
return EXIT_FAILURE;
}
/* reads message from stdin */
if (collect(&message))
return EXIT_FAILURE;
send_message(message.data, message.len, argv);
if (smtp_from == NULL && (smtp_from = guessfrom()) == NULL) {
fprintf(stderr, "can't guess a valid from, please use -f option.\n");
return EXIT_FAILURE;
}
release(&message);
return EXIT_SUCCESS;
/* reads message from stdin */
if (collect(&message))
return EXIT_FAILURE;
send_message(message.data, message.len, argv);
release(&message);
return EXIT_SUCCESS;
}
#endif
@@ -46,30 +46,30 @@
static const char modname[] = "ODBC";
struct odbc_obj {
char *dsn;
char *username;
char *password;
SQLHENV env;
SQLHDBC con;
SQLHSTMT stmt;
uint32_t state;
SQLCHAR *colbuf;
int32 cblen;
SQLCHAR *code;
int32 codelen;
char *dsn;
char *username;
char *password;
SQLHENV env;
SQLHDBC con;
SQLHSTMT stmt;
uint32_t state;
SQLCHAR *colbuf;
int32 cblen;
SQLCHAR *code;
int32 codelen;
};
typedef enum {
ODBC_STATE_INIT,
ODBC_STATE_DOWN,
ODBC_STATE_CONNECTED,
ODBC_STATE_ERROR
ODBC_STATE_INIT,
ODBC_STATE_DOWN,
ODBC_STATE_CONNECTED,
ODBC_STATE_ERROR
} odbc_state_t;
typedef struct odbc_obj odbc_obj_t;
typedef enum {
ODBC_SUCCESS = 0,
ODBC_FAIL = -1
ODBC_SUCCESS = 0,
ODBC_FAIL = -1
} odbc_status_t;
@@ -77,59 +77,59 @@ static odbc_obj_t *new_odbc_obj(char *dsn, char *username, char *password)
{
odbc_obj_t *new_obj;
if (!(new_obj = malloc(sizeof(*new_obj)))) {
goto err;
}
if (!(new_obj->dsn = strdup(dsn))) {
goto err;
}
if (!(new_obj = malloc(sizeof(*new_obj)))) {
goto err;
}
if (!(new_obj->username = strdup(username))) {
goto err;
}
if (!(new_obj->dsn = strdup(dsn))) {
goto err;
}
if (!(new_obj->password = strdup(password))) {
goto err;
}
if (!(new_obj->username = strdup(username))) {
goto err;
}
if (!(new_obj->password = strdup(password))) {
goto err;
}
new_obj->env = SQL_NULL_HANDLE;
new_obj->state = ODBC_STATE_INIT;
return new_obj;
err:
err:
if (new_obj) {
switch_safe_free(new_obj->dsn);
switch_safe_free(new_obj->username);
switch_safe_free(new_obj->password);
switch_safe_free(new_obj);
switch_safe_free(new_obj);
}
return NULL;
}
odbc_status_t odbc_obj_disconnect(odbc_obj_t *obj)
odbc_status_t odbc_obj_disconnect(odbc_obj_t * obj)
{
int result;
if (obj->state == ODBC_STATE_CONNECTED) {
result = SQLDisconnect(obj->con);
if (result == ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, obj->dsn);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", obj->dsn);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", obj->dsn);
}
if (obj->state == ODBC_STATE_CONNECTED) {
result = SQLDisconnect(obj->con);
if (result == ODBC_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Disconnected %d from [%s]\n", result, obj->dsn);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Disconnectiong [%s]\n", obj->dsn);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[%s] already disconnected\n", obj->dsn);
}
obj->state = ODBC_STATE_DOWN;
return ODBC_SUCCESS;
}
odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
odbc_status_t odbc_obj_connect(odbc_obj_t * obj)
{
int result;
SQLINTEGER err;
@@ -140,14 +140,14 @@ odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
result = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &obj->env);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHandle\n");
return ODBC_FAIL;
}
result = SQLSetEnvAttr(obj->env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SetEnv\n");
SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
return ODBC_FAIL;
}
@@ -155,7 +155,7 @@ odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
result = SQLAllocHandle(SQL_HANDLE_DBC, obj->env, &obj->con);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error AllocHDB %d\n", result);
SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
return ODBC_FAIL;
}
@@ -169,14 +169,14 @@ odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connecting %s\n", obj->dsn);
result = SQLConnect(obj->con,
(SQLCHAR *) obj->dsn, SQL_NTS,
(SQLCHAR *) obj->username, SQL_NTS,
(SQLCHAR *) obj->password, SQL_NTS);
(SQLCHAR *) obj->dsn, SQL_NTS,
(SQLCHAR *) obj->username, SQL_NTS, (SQLCHAR *) obj->password, SQL_NTS);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO)) {
SQLGetDiagRec(SQL_HANDLE_DBC, obj->con, 1, stat, &err, msg, 100, &mlen);
SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SQLConnect=%d errno=%d %s\n", result, (int)err, msg);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error SQLConnect=%d errno=%d %s\n", result, (int) err,
msg);
return ODBC_FAIL;
} else {
@@ -187,9 +187,9 @@ odbc_status_t odbc_obj_connect(odbc_obj_t *obj)
return ODBC_SUCCESS;
}
static void destroy_odbc_obj(odbc_obj_t **objp)
static void destroy_odbc_obj(odbc_obj_t ** objp)
{
odbc_obj_t *obj = *objp;
odbc_obj_t *obj = *objp;
odbc_obj_disconnect(obj);
@@ -198,282 +198,284 @@ static void destroy_odbc_obj(odbc_obj_t **objp)
SQLFreeHandle(SQL_HANDLE_ENV, obj->env);
switch_safe_free(obj->dsn);
switch_safe_free(obj->username);
switch_safe_free(obj->password);
switch_safe_free(obj->username);
switch_safe_free(obj->password);
switch_safe_free(obj->colbuf);
switch_safe_free(obj->code);
switch_safe_free(obj);
switch_safe_free(obj);
}
/* ODBC Object */
/*********************************************************************************/
static JSBool odbc_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = NULL;
char *dsn, *username, *password;
int32 blen = 1024;
odbc_obj_t *odbc_obj = NULL;
char *dsn, *username, *password;
int32 blen = 1024;
if (argc < 3) {
return JS_FALSE;
}
if (argc < 3) {
return JS_FALSE;
}
dsn = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
username = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
password = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
dsn = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
username = JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
password = JS_GetStringBytes(JS_ValueToString(cx, argv[2]));
if (argc > 3) {
int32 len;
JS_ValueToInt32(cx, argv[3], &len);
if (argc > 3) {
int32 len;
JS_ValueToInt32(cx, argv[3], &len);
if (len > 0) {
blen = len;
}
}
if (dsn && username && password) {
odbc_obj = new_odbc_obj(dsn, username, password);
}
if (len > 0) {
blen = len;
}
}
if (!odbc_obj) {
return JS_FALSE;
}
if (dsn && username && password) {
odbc_obj = new_odbc_obj(dsn, username, password);
}
if (!(odbc_obj->colbuf = (SQLCHAR *) malloc(blen))) {
destroy_odbc_obj(&odbc_obj);
return JS_FALSE;
}
if (!odbc_obj) {
return JS_FALSE;
}
odbc_obj->cblen = blen;
if (!(odbc_obj->colbuf = (SQLCHAR *) malloc(blen))) {
destroy_odbc_obj(&odbc_obj);
return JS_FALSE;
}
blen += 1536;
odbc_obj->cblen = blen;
if (!(odbc_obj->code = (SQLCHAR *) malloc(blen))) {
destroy_odbc_obj(&odbc_obj);
return JS_FALSE;
}
odbc_obj->codelen = blen;
blen += 1536;
if (!(odbc_obj->code = (SQLCHAR *) malloc(blen))) {
destroy_odbc_obj(&odbc_obj);
return JS_FALSE;
}
odbc_obj->codelen = blen;
JS_SetPrivate(cx, obj, odbc_obj);
return JS_TRUE;
}
static void odbc_destroy(JSContext *cx, JSObject *obj)
static void odbc_destroy(JSContext * cx, JSObject * obj)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
if (odbc_obj) {
destroy_odbc_obj(&odbc_obj);
}
if (odbc_obj) {
destroy_odbc_obj(&odbc_obj);
}
}
static JSBool odbc_connect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_connect(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
JSBool tf = JS_TRUE;
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
JSBool tf = JS_TRUE;
if (odbc_obj) {
if (odbc_obj_connect(odbc_obj) == ODBC_SUCCESS) {
tf = JS_TRUE;
} else {
tf = JS_FALSE;
}
}
*rval = BOOLEAN_TO_JSVAL( tf );
if (odbc_obj) {
if (odbc_obj_connect(odbc_obj) == ODBC_SUCCESS) {
tf = JS_TRUE;
} else {
tf = JS_FALSE;
}
}
*rval = BOOLEAN_TO_JSVAL(tf);
return JS_TRUE;
}
static JSBool odbc_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_exec(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
char *sql;
JSBool tf = JS_FALSE;
int result;
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
char *sql;
JSBool tf = JS_FALSE;
int result;
if (argc < 1) {
goto done;
}
if (argc < 1) {
goto done;
}
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
goto done;
}
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
goto done;
}
if (odbc_obj->stmt) {
SQLFreeHandle (SQL_HANDLE_STMT, odbc_obj->stmt);
odbc_obj->stmt = NULL;
}
sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
if (odbc_obj->stmt) {
SQLFreeHandle(SQL_HANDLE_STMT, odbc_obj->stmt);
odbc_obj->stmt = NULL;
}
if (SQLAllocHandle(SQL_HANDLE_STMT, odbc_obj->con, &odbc_obj->stmt) != SQL_SUCCESS) {
goto done;
}
sql = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
if (SQLPrepare(odbc_obj->stmt, (unsigned char *)sql, SQL_NTS) != SQL_SUCCESS) {
goto done;
}
if (SQLAllocHandle(SQL_HANDLE_STMT, odbc_obj->con, &odbc_obj->stmt) != SQL_SUCCESS) {
goto done;
}
result = SQLExecute(odbc_obj->stmt);
if (SQLPrepare(odbc_obj->stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
goto done;
}
if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
goto done;
}
tf = JS_TRUE;
done:
result = SQLExecute(odbc_obj->stmt);
*rval = BOOLEAN_TO_JSVAL( tf );
if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
goto done;
}
return JS_TRUE;
tf = JS_TRUE;
done:
*rval = BOOLEAN_TO_JSVAL(tf);
return JS_TRUE;
}
static JSBool odbc_num_rows(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_num_rows(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
SQLSMALLINT rows = 0;
SQLSMALLINT rows = 0;
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
goto done;
}
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
goto done;
}
if (odbc_obj->stmt) {
SQLNumResultCols(odbc_obj->stmt, &rows);
}
if (odbc_obj->stmt) {
SQLNumResultCols(odbc_obj->stmt, &rows);
}
done:
done:
*rval = INT_TO_JSVAL( rows );
*rval = INT_TO_JSVAL(rows);
return JS_TRUE;
return JS_TRUE;
}
static JSBool odbc_next_row(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_next_row(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
int result = 0;
JSBool tf = JS_FALSE;
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
int result = 0;
JSBool tf = JS_FALSE;
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
goto done;
}
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
goto done;
}
if (odbc_obj->stmt) {
if ((result = SQLFetch(odbc_obj->stmt) == SQL_SUCCESS)) {
tf = JS_TRUE;
}
}
if (odbc_obj->stmt) {
if ((result = SQLFetch(odbc_obj->stmt) == SQL_SUCCESS)) {
tf = JS_TRUE;
}
}
done:
done:
*rval = BOOLEAN_TO_JSVAL( tf );
*rval = BOOLEAN_TO_JSVAL(tf);
return JS_TRUE;
return JS_TRUE;
}
static char *escape_data(char *in)
{
switch_size_t nlen = strlen(in);
uint32_t qc = 0;
char *p, *q, *r;
switch_size_t nlen = strlen(in);
uint32_t qc = 0;
char *p, *q, *r;
for(p = in; p && *p; p++) {
if (*p == '"') {
qc += 2;
}
}
nlen += qc + 1;
for (p = in; p && *p; p++) {
if (*p == '"') {
qc += 2;
}
}
if (!(q = (char *) malloc(nlen))) {
return NULL;
}
nlen += qc + 1;
r = q;
qc = 0;
for(p = in; p && *p; p++) {
if (*p == '"') {
*r++ = '\\';
}
*r++ = *p;
if (++qc > nlen) {
break;
}
}
*r++ = '\0';
if (!(q = (char *) malloc(nlen))) {
return NULL;
}
r = q;
qc = 0;
for (p = in; p && *p; p++) {
if (*p == '"') {
*r++ = '\\';
}
*r++ = *p;
if (++qc > nlen) {
break;
}
}
*r++ = '\0';
return q;
return q;
}
static JSBool odbc_get_data(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool odbc_get_data(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
JSBool tf = JS_FALSE;
odbc_obj_t *odbc_obj = (odbc_obj_t *) JS_GetPrivate(cx, obj);
JSBool tf = JS_FALSE;
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
goto done;
}
if (odbc_obj->state != ODBC_STATE_CONNECTED) {
goto done;
}
if (odbc_obj->stmt) {
SQLSMALLINT c = 0, x = 0;
int result;
char code[66560];
if (odbc_obj->stmt) {
SQLSMALLINT c = 0, x = 0;
int result;
char code[66560];
snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
eval_some_js(code, cx, obj, rval);
if (*rval == JS_FALSE) {
return JS_TRUE;
}
snprintf(code, sizeof(code), "~var _oDbC_dB_RoW_DaTa_ = {}");
eval_some_js(code, cx, obj, rval);
if (*rval == JS_FALSE) {
return JS_TRUE;
}
result = SQLNumResultCols(odbc_obj->stmt, &c);
if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
for (x = 1; x <= c; x++) {
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
SQLUINTEGER ColumnSize;
SQLCHAR name[1024] = "";
SQLCHAR *data = odbc_obj->colbuf;
SQLCHAR *esc = NULL;
result = SQLNumResultCols(odbc_obj->stmt, &c);
if (result == SQL_SUCCESS || result == SQL_SUCCESS_WITH_INFO) {
for (x = 1; x <= c; x++) {
SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable;
SQLUINTEGER ColumnSize;
SQLCHAR name[1024] = "";
SQLCHAR *data = odbc_obj->colbuf;
SQLCHAR *esc = NULL;
SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
if (strchr((char *)odbc_obj->colbuf, '"')) { /* please don't */
esc = (SQLCHAR *) escape_data((char *)odbc_obj->colbuf);
data = esc;
}
SQLDescribeCol(odbc_obj->stmt, x, name, sizeof(name), &NameLength, &DataType, &ColumnSize,
&DecimalDigits, &Nullable);
SQLGetData(odbc_obj->stmt, x, SQL_C_CHAR, odbc_obj->colbuf, odbc_obj->cblen, NULL);
snprintf((char *)odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name, data);
switch_safe_free(esc);
if (strchr((char *) odbc_obj->colbuf, '"')) { /* please don't */
esc = (SQLCHAR *) escape_data((char *) odbc_obj->colbuf);
data = esc;
}
eval_some_js((char *)odbc_obj->code, cx, obj, rval);
snprintf((char *) odbc_obj->code, odbc_obj->codelen, "~_oDbC_dB_RoW_DaTa_[\"%s\"] = \"%s\"", name,
data);
switch_safe_free(esc);
if (*rval == JS_FALSE) {
return JS_TRUE;
}
}
eval_some_js((char *) odbc_obj->code, cx, obj, rval);
JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
return JS_TRUE;
}
if (*rval == JS_FALSE) {
return JS_TRUE;
}
}
}
JS_GetProperty(cx, obj, "_oDbC_dB_RoW_DaTa_", rval);
return JS_TRUE;
}
done:
}
*rval = BOOLEAN_TO_JSVAL( tf );
done:
return JS_TRUE;
*rval = BOOLEAN_TO_JSVAL(tf);
return JS_TRUE;
}
@@ -492,50 +494,40 @@ static JSFunctionSpec odbc_methods[] = {
static JSPropertySpec odbc_props[] = {
// {"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
// {"name", odbc_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
{0}
};
static JSBool odbc_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
static JSBool odbc_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
JSBool res = JS_TRUE;
return res;
}
JSClass odbc_class = {
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, odbc_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, odbc_destroy, NULL, NULL, NULL,
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, odbc_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, odbc_destroy, NULL, NULL, NULL,
odbc_construct
};
switch_status_t odbc_load(JSContext *cx, JSObject *obj)
switch_status_t odbc_load(JSContext * cx, JSObject * obj)
{
JS_InitClass(cx,
obj,
NULL,
&odbc_class,
odbc_construct,
3,
odbc_props,
odbc_methods,
odbc_props,
odbc_methods
);
JS_InitClass(cx, obj, NULL, &odbc_class, odbc_construct, 3, odbc_props, odbc_methods, odbc_props, odbc_methods);
return SWITCH_STATUS_SUCCESS;
}
const sm_module_interface_t odbc_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ odbc_load,
/*.next*/ NULL
/*.spidermonkey_load */ odbc_load,
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &odbc_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -35,16 +35,16 @@ static const char modname[] = "Skel";
/* Skel Object */
/*********************************************************************************/
static JSBool skel_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool skel_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
return JS_TRUE;
}
static void skel_destroy(JSContext *cx, JSObject *obj)
static void skel_destroy(JSContext * cx, JSObject * obj)
{
}
static JSBool skel_my_method(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool skel_my_method(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
return JS_FALSE;
}
@@ -60,12 +60,12 @@ static JSFunctionSpec skel_methods[] = {
static JSPropertySpec skel_props[] = {
{"name", SKEL_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
{"name", SKEL_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
{0}
};
static JSBool skel_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
static JSBool skel_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
JSBool res = JS_TRUE;
@@ -73,37 +73,27 @@ static JSBool skel_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp
}
JSClass skel_class = {
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, skel_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, skel_destroy, NULL, NULL, NULL,
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, skel_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, skel_destroy, NULL, NULL, NULL,
skel_construct
};
switch_status_t spidermonkey_load(JSContext *cx, JSObject *obj)
switch_status_t spidermonkey_load(JSContext * cx, JSObject * obj)
{
JS_InitClass(cx,
obj,
NULL,
&skel_class,
skel_construct,
3,
skel_props,
skel_methods,
skel_props,
skel_methods
);
JS_InitClass(cx, obj, NULL, &skel_class, skel_construct, 3, skel_props, skel_methods, skel_props, skel_methods);
return SWITCH_STATUS_SUCCESS;
}
const sm_module_interface_t skel_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ spidermonkey_load,
/*.next*/ NULL
/*.spidermonkey_load */ spidermonkey_load,
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &skel_module_interface;
return SWITCH_STATUS_SUCCESS;
@@ -57,7 +57,7 @@ struct teletone_obj {
};
static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map_t *map)
static int teletone_handler(teletone_generation_session_t * ts, teletone_tone_map_t * map)
{
struct teletone_obj *tto = ts->user_data;
int wrote;
@@ -74,7 +74,7 @@ static int teletone_handler(teletone_generation_session_t *ts, teletone_tone_map
/* TeleTone Object */
/*********************************************************************************/
static JSBool teletone_construct(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool teletone_construct(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
JSObject *session_obj;
struct teletone_obj *tto = NULL;
@@ -129,8 +129,8 @@ static JSBool teletone_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
if (switch_core_timer_init(&tto->timer_base,
timer_name,
ms,
(read_codec->implementation->samples_per_second / 50) * read_codec->implementation->number_of_channels,
pool) == SWITCH_STATUS_SUCCESS) {
(read_codec->implementation->samples_per_second / 50) *
read_codec->implementation->number_of_channels, pool) == SWITCH_STATUS_SUCCESS) {
tto->timer = &tto->timer_base;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Timer INIT Success %u\n", ms);
} else {
@@ -149,7 +149,7 @@ static JSBool teletone_construct(JSContext *cx, JSObject *obj, uintN argc, jsval
return JS_TRUE;
}
static void teletone_destroy(JSContext *cx, JSObject *obj)
static void teletone_destroy(JSContext * cx, JSObject * obj)
{
struct teletone_obj *tto = JS_GetPrivate(cx, obj);
switch_memory_pool_t *pool;
@@ -169,26 +169,26 @@ static void teletone_destroy(JSContext *cx, JSObject *obj)
}
}
static JSBool teletone_add_tone(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool teletone_add_tone(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct teletone_obj *tto = JS_GetPrivate(cx, obj);
if (argc > 2) {
if (argc > 2) {
int x;
char *fval;
char *map_str;
map_str = JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
for(x = 1; x < TELETONE_MAX_TONES; x++) {
for (x = 1; x < TELETONE_MAX_TONES; x++) {
fval = JS_GetStringBytes(JS_ValueToString(cx, argv[x]));
tto->ts.TONES[(int)*map_str].freqs[x-1] = strtod(fval, NULL);
tto->ts.TONES[(int) *map_str].freqs[x - 1] = strtod(fval, NULL);
}
return JS_TRUE;
}
return JS_FALSE;
}
static JSBool teletone_on_dtmf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool teletone_on_dtmf(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct teletone_obj *tto = JS_GetPrivate(cx, obj);
if (argc > 0) {
@@ -201,7 +201,7 @@ static JSBool teletone_on_dtmf(JSContext *cx, JSObject *obj, uintN argc, jsval *
return JS_TRUE;
}
static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
static JSBool teletone_generate(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval)
{
struct teletone_obj *tto = JS_GetPrivate(cx, obj);
int32 loops = 0;
@@ -209,7 +209,7 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
if (argc > 0) {
char *script;
switch_core_session_t *session;
switch_frame_t write_frame = {0};
switch_frame_t write_frame = { 0 };
unsigned char *fdata[1024];
switch_frame_t *read_frame;
int stream_id;
@@ -225,7 +225,7 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
if (!tto->loop_buffer) {
switch_buffer_create_dynamic(&tto->loop_buffer, JS_BLOCK_SIZE, JS_BUFFER_SIZE, 0);
}
}
}
if (tto->audio_buffer) {
switch_buffer_zero(tto->audio_buffer);
@@ -244,14 +244,14 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
write_frame.data = fdata;
channel = switch_core_session_get_channel(session);
if (tto->timer) {
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
switch_core_service_session(session, &thread_session, stream_id);
}
}
for(;;) {
for (;;) {
if (switch_test_flag(tto, TTF_DTMF)) {
char dtmf[128];
@@ -262,7 +262,7 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
jsval aargv[4];
switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf));
aargv[aargc++] = STRING_TO_JSVAL (JS_NewStringCopyZ(cx, dtmf));
aargv[aargc++] = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, dtmf));
JS_CallFunction(cx, obj, tto->function, aargc, aargv, &tto->ret);
ret = JS_GetStringBytes(JS_ValueToString(cx, tto->ret));
if (strcmp(ret, "true") && strcmp(ret, "undefined")) {
@@ -271,7 +271,7 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
}
}
}
if (tto->timer) {
if (switch_core_timer_next(tto->timer) != SWITCH_STATUS_SUCCESS) {
break;
@@ -280,23 +280,26 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
} else {
switch_status_t status;
status = switch_core_session_read_frame(session, &read_frame, -1, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
}
if ((write_frame.datalen = (uint32_t)switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
if (loops) {
if ((write_frame.datalen =
(uint32_t) switch_buffer_read(tto->audio_buffer, fdata,
write_frame.codec->implementation->bytes_per_frame)) <= 0) {
if (loops) {
switch_buffer_t *tmp;
/* Switcharoo*/
/* Switcharoo */
tmp = tto->audio_buffer;
tto->audio_buffer = tto->loop_buffer;
tto->loop_buffer = tmp;
loops--;
/* try again */
if ((write_frame.datalen =
(uint32_t)switch_buffer_read(tto->audio_buffer, fdata, write_frame.codec->implementation->bytes_per_frame)) <= 0) {
if ((write_frame.datalen =
(uint32_t) switch_buffer_read(tto->audio_buffer, fdata,
write_frame.codec->implementation->bytes_per_frame)) <= 0) {
break;
}
} else {
@@ -321,7 +324,7 @@ static JSBool teletone_generate(JSContext *cx, JSObject *obj, uintN argc, jsval
}
return JS_TRUE;
}
return JS_FALSE;
}
@@ -332,18 +335,18 @@ enum teletone_tinyid {
static JSFunctionSpec teletone_methods[] = {
{"generate", teletone_generate, 1},
{"onDTMF", teletone_on_dtmf, 1},
{"addTone", teletone_add_tone, 10},
{"addTone", teletone_add_tone, 10},
{0}
};
static JSPropertySpec teletone_props[] = {
{"name", TELETONE_NAME, JSPROP_READONLY|JSPROP_PERMANENT},
{"name", TELETONE_NAME, JSPROP_READONLY | JSPROP_PERMANENT},
{0}
};
static JSBool teletone_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
static JSBool teletone_getProperty(JSContext * cx, JSObject * obj, jsval id, jsval * vp)
{
JSBool res = JS_TRUE;
@@ -351,37 +354,31 @@ static JSBool teletone_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval
}
JSClass teletone_class = {
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, teletone_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, teletone_destroy, NULL, NULL, NULL,
modname, JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, teletone_getProperty, JS_PropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, teletone_destroy, NULL, NULL, NULL,
teletone_construct
};
switch_status_t teletone_load(JSContext *cx, JSObject *obj)
switch_status_t teletone_load(JSContext * cx, JSObject * obj)
{
JS_InitClass(cx,
obj,
NULL,
&teletone_class,
teletone_construct,
3,
teletone_props,
teletone_methods,
teletone_props,
teletone_methods
);
teletone_construct, 3, teletone_props, teletone_methods, teletone_props, teletone_methods);
return SWITCH_STATUS_SUCCESS;
}
const sm_module_interface_t teletone_module_interface = {
/*.name = */ modname,
/*.spidermonkey_load*/ teletone_load,
/*.next*/ NULL
/*.spidermonkey_load */ teletone_load,
/*.next */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t **module_interface)
SWITCH_MOD_DECLARE(switch_status_t) spidermonkey_init(const sm_module_interface_t ** module_interface)
{
*module_interface = &teletone_module_interface;
return SWITCH_STATUS_SUCCESS;
+29 -25
View File
@@ -32,25 +32,27 @@
#include <switch.h>
static const char modname[] = "mod_console";
static const uint8_t STATIC_LEVELS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
static const uint8_t STATIC_LEVELS[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
static int COLORIZE = 0;
#ifdef WIN32
static HANDLE hStdout;
static WORD wOldColorAttrs;
static CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
static WORD COLORS[] =
{ FOREGROUND_RED | FOREGROUND_INTENSITY,
FOREGROUND_RED | FOREGROUND_INTENSITY,
FOREGROUND_RED | FOREGROUND_INTENSITY,
FOREGROUND_RED | FOREGROUND_INTENSITY,
FOREGROUND_BLUE | FOREGROUND_INTENSITY,
FOREGROUND_BLUE | FOREGROUND_INTENSITY,
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
FOREGROUND_GREEN | FOREGROUND_INTENSITY };
static WORD COLORS[] = { FOREGROUND_RED | FOREGROUND_INTENSITY,
FOREGROUND_RED | FOREGROUND_INTENSITY,
FOREGROUND_RED | FOREGROUND_INTENSITY,
FOREGROUND_RED | FOREGROUND_INTENSITY,
FOREGROUND_BLUE | FOREGROUND_INTENSITY,
FOREGROUND_BLUE | FOREGROUND_INTENSITY,
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
FOREGROUND_GREEN | FOREGROUND_INTENSITY,
FOREGROUND_GREEN | FOREGROUND_INTENSITY
};
#else
static const char *COLORS[] =
{ SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN, SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW, "" };
static const char *COLORS[] =
{ SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FRED, SWITCH_SEQ_FMAGEN, SWITCH_SEQ_FCYAN,
SWITCH_SEQ_FGREEN, SWITCH_SEQ_FYELLOW, ""
};
#endif
static switch_loadable_module_interface_t console_module_interface = {
@@ -71,7 +73,8 @@ static switch_hash_t *log_hash = NULL;
static switch_hash_t *name_hash = NULL;
static int8_t all_level = -1;
static void del_mapping(char *var) {
static void del_mapping(char *var)
{
if (!strcasecmp(var, "all")) {
all_level = -1;
return;
@@ -94,7 +97,7 @@ static void add_mapping(char *var, char *val)
}
del_mapping(name);
switch_core_hash_insert(log_hash, name, (void *) &STATIC_LEVELS[(uint8_t)switch_log_str2level(val)]);
switch_core_hash_insert(log_hash, name, (void *) &STATIC_LEVELS[(uint8_t) switch_log_str2level(val)]);
}
static switch_status_t config_logger(void)
@@ -109,7 +112,7 @@ static switch_status_t config_logger(void)
switch_core_hash_init(&log_hash, module_pool);
switch_core_hash_init(&name_hash, module_pool);
if ((settings = switch_xml_child(cfg, "mappings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -127,7 +130,7 @@ static switch_status_t config_logger(void)
if (!strcasecmp(var, "colorize") && switch_true(val)) {
#ifdef WIN32
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE
if (switch_core_get_console() == stdout && hStdout != INVALID_HANDLE_VALUE
&& GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
wOldColorAttrs = csbiInfo.wAttributes;
COLORIZE = 1;
@@ -150,11 +153,11 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
if ((handle = switch_core_data_channel(SWITCH_CHANNEL_ID_LOG))) {
uint8_t *lookup = NULL;
switch_log_level_t level = SWITCH_LOG_DEBUG;
switch_log_level_t level = SWITCH_LOG_DEBUG;
if (log_hash) {
lookup = switch_core_hash_find(log_hash, node->file);
if (!lookup) {
lookup = switch_core_hash_find(log_hash, node->func);
}
@@ -164,13 +167,13 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
level = (switch_log_level_t) *lookup;
} else if (all_level > -1) {
level = (switch_log_level_t) all_level;
}
}
if (!log_hash || (((all_level > - 1) || lookup) && level >= node->level)) {
if (!log_hash || (((all_level > -1) || lookup) && level >= node->level)) {
if (COLORIZE) {
#ifdef WIN32
SetConsoleTextAttribute(hStdout, COLORS[node->level]);
WriteFile(hStdout, node->data, (DWORD)strlen(node->data), NULL, NULL);
WriteFile(hStdout, node->data, (DWORD) strlen(node->data), NULL, NULL);
SetConsoleTextAttribute(hStdout, wOldColorAttrs);
#else
fprintf(handle, "%s%s%s", COLORS[node->level], node->data, SWITCH_SEQ_DEFAULT_COLOR);
@@ -183,11 +186,12 @@ static switch_status_t switch_console_logger(const switch_log_node_t *node, swit
fprintf(stderr, "HELP I HAVE NO CONSOLE TO LOG TO!\n");
fflush(stderr);
}
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "OH OH no pool\n");
@@ -200,7 +204,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
/* setup my logger function */
switch_log_bind_logger(switch_console_logger, SWITCH_LOG_DEBUG);
config_logger();
/* indicate that the module should continue to be loaded */
+30 -29
View File
@@ -50,56 +50,56 @@ static struct {
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ident, globals.ident)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_level, globals.level)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_format, globals.format)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_facility, globals.facility)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_level, globals.level)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_format, globals.format)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_facility, globals.facility)
static switch_loadable_module_interface_t console_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/*.api_interface */ NULL,
/*.file_interface */ NULL,
/*.speech_interface */ NULL,
/*.directory_interface */ NULL
};
static switch_loadable_module_interface_t console_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL,
/*.api_interface */ NULL,
/*.file_interface */ NULL,
/*.speech_interface */ NULL,
/*.directory_interface */ NULL
};
static switch_status_t mod_syslog_logger(const switch_log_node_t *node, switch_log_level_t level)
{
char *message = NULL;
char line_no[sizeof(int)*8+1];
char line_no[sizeof(int) * 8 + 1];
char date[80] = "";
switch_time_exp_t time;
switch_size_t retsize;
message = (char *)malloc(strlen(globals.format)+2);
message = (char *) malloc(strlen(globals.format) + 2);
switch_copy_string(message, globals.format, strlen(globals.format)+1);
switch_copy_string(message, globals.format, strlen(globals.format) + 1);
message = switch_string_replace(message, "${message}", node->content);
if (switch_time_exp_lt(&time, node->timestamp) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &time);
message = switch_string_replace(message, "${time}", date);
message = switch_string_replace(message, "${file}", node->file);
message = switch_string_replace(message, "${func}", node->func);
snprintf(line_no, sizeof(line_no), "%d", node->line);
message = switch_string_replace(message, "${line}", line_no);
if (!switch_strlen_zero(message)) {
syslog(LOG_ERR, "%s", message);
}
free(message);
return SWITCH_STATUS_SUCCESS;
}
@@ -125,7 +125,7 @@ static switch_status_t load_config(void)
} else if (!strcmp(var, "level")) {
set_global_level(val);;
}
}
}
switch_xml_free(xml);
@@ -148,26 +148,27 @@ static switch_status_t load_config(void)
return 0;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **interface,
char *filename)
{
switch_status_t status;
*interface = &console_module_interface;
if ((status=load_config()) != SWITCH_STATUS_SUCCESS) {
if ((status = load_config()) != SWITCH_STATUS_SUCCESS) {
return status;
}
openlog(globals.ident, LOG_PID, LOG_USER);
switch_log_bind_logger(mod_syslog_logger, SWITCH_LOG_DEBUG);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_unload(const switch_loadable_module_interface_t **interface)
{
closelog();
return SWITCH_STATUS_SUCCESS;
}
+108 -130
View File
@@ -58,24 +58,21 @@ static const char modname[] = "mod_say_en";
static switch_status_t en_spell(switch_core_session_t *session,
char *tosay,
switch_say_type_t type,
switch_say_method_t method,
switch_input_args_t *args)
switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
char *p;
for(p = tosay; p && *p; p++) {
for (p = tosay; p && *p; p++) {
int a = tolower((int) *p);
if (a >= 48 && a <= 57) {
say_file("digits/%d.wav", a-48);
}
else {
if (type == SST_NAME_SPELLED) {
say_file("ascii/%d.wav", a);
} else if (type == SST_NAME_PHONETIC) {
say_file("phonetic-ascii/%d.wav", a);
}
}
if (a >= 48 && a <= 57) {
say_file("digits/%d.wav", a - 48);
} else {
if (type == SST_NAME_SPELLED) {
say_file("ascii/%d.wav", a);
} else if (type == SST_NAME_PHONETIC) {
say_file("phonetic-ascii/%d.wav", a);
}
}
}
return SWITCH_STATUS_SUCCESS;
@@ -83,11 +80,7 @@ static switch_status_t en_spell(switch_core_session_t *session,
static switch_status_t play_group(switch_say_method_t method,
int a,
int b,
int c,
char *what,
switch_core_session_t *session,
switch_input_args_t *args)
int b, int c, char *what, switch_core_session_t *session, switch_input_args_t *args)
{
if (a) {
@@ -118,14 +111,14 @@ static switch_status_t play_group(switch_say_method_t method,
return SWITCH_STATUS_SUCCESS;
}
static char *strip_commas(char *in, char *out, switch_size_t len)
{
char *p = in, *q = out;
char *ret = out;
switch_size_t x = 0;
for(;p && *p; p++) {
for (; p && *p; p++) {
if ((*p > 47 && *p < 58)) {
*q++ = *p;
} else if (*p != ',') {
@@ -148,10 +141,10 @@ static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
char *ret = out;
switch_size_t x = 0;
// valid are 0 - 9, period (.), minus (-), and plus (+) - remove all others
for(;p && *p; p++) {
for (; p && *p; p++) {
if ((*p > 47 && *p < 58) || *p == '.' || *p == '-' || *p == '+') {
*q++ = *p;
}
}
if (++x > len) {
ret = NULL;
@@ -165,15 +158,14 @@ static char *strip_nonnumerics(char *in, char *out, switch_size_t len)
static switch_status_t en_say_general_count(switch_core_session_t *session,
char *tosay,
switch_say_type_t type,
switch_say_method_t method,
switch_input_args_t *args)
switch_say_method_t method, switch_input_args_t *args)
{
switch_channel_t *channel;
int in;
int x = 0, places[9] = {0};
int x = 0, places[9] = { 0 };
char sbuf[13] = "";
switch_status_t status;
assert(session != NULL);
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -186,23 +178,28 @@ static switch_status_t en_say_general_count(switch_core_session_t *session,
in = atoi(tosay);
if (in != 0) {
for(x = 8; x >= 0; x--) {
int num = (int)pow(10, x);
for (x = 8; x >= 0; x--) {
int num = (int) pow(10, x);
if ((places[x] = in / num)) {
in -= places[x] * num;
}
}
switch (method) {
case SSM_COUNTED:
case SSM_PRONOUNCED:
if ((status = play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
if ((status =
play_group(SSM_PRONOUNCED, places[8], places[7], places[6], "digits/million.wav", session,
args)) != SWITCH_STATUS_SUCCESS) {
return status;
}
if ((status = play_group(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/thousand.wav", session, args)) != SWITCH_STATUS_SUCCESS) {
if ((status =
play_group(SSM_PRONOUNCED, places[5], places[4], places[3], "digits/thousand.wav", session,
args)) != SWITCH_STATUS_SUCCESS) {
return status;
}
if ((status = play_group(method, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
if ((status =
play_group(method, places[2], places[1], places[0], NULL, session, args)) != SWITCH_STATUS_SUCCESS) {
return status;
}
break;
@@ -219,8 +216,7 @@ static switch_status_t en_say_general_count(switch_core_session_t *session,
default:
break;
}
}
else {
} else {
say_file("digits/0.wav");
}
@@ -229,10 +225,7 @@ static switch_status_t en_say_general_count(switch_core_session_t *session,
static switch_status_t en_ip(switch_core_session_t *session,
char *tosay,
switch_say_type_t type,
switch_say_method_t method,
switch_input_args_t *args)
char *tosay, switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
char *a, *b, *c, *d;
switch_status_t status = SWITCH_STATUS_SUCCESS;
@@ -269,7 +262,7 @@ static switch_status_t en_ip(switch_core_session_t *session,
say_file("digits/dot.wav");
say_num(atoi(d), method);
done:
done:
switch_safe_free(a);
return status;
}
@@ -277,15 +270,13 @@ static switch_status_t en_ip(switch_core_session_t *session,
static switch_status_t en_say_time(switch_core_session_t *session,
char *tosay,
switch_say_type_t type,
switch_say_method_t method,
switch_input_args_t *args)
switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
int32_t t;
switch_time_t target = 0;
switch_time_exp_t tm;
uint8_t say_date = 0, say_time = 0;
if (type == SST_TIME_MEASUREMENT) {
int64_t hours = 0;
int64_t minutes = 0;
@@ -295,7 +286,7 @@ static switch_status_t en_say_time(switch_core_session_t *session,
if (strchr(tosay, ':')) {
char *tme = switch_core_session_strdup(session, tosay);
char *p;
if ((p = strrchr(tme, ':'))) {
*p++ = '\0';
seconds = atoi(p);
@@ -305,10 +296,9 @@ static switch_status_t en_say_time(switch_core_session_t *session,
if (tme) {
hours = atoi(tme);
}
} else {
minutes = atoi(tme);
}
else {
minutes = atoi(tme);
}
}
} else {
if ((seconds = atoi(tosay)) <= 0) {
@@ -320,7 +310,7 @@ static switch_status_t en_say_time(switch_core_session_t *session,
r = seconds % 60;
seconds = r;
}
if (minutes >= 60) {
hours = minutes / 60;
r = minutes % 60;
@@ -330,45 +320,39 @@ static switch_status_t en_say_time(switch_core_session_t *session,
if (hours) {
say_num(hours, SSM_PRONOUNCED);
if (hours == 1) {
say_file("time/hour.wav"); //TODO -- NEED TO GET "hour.wav" recorded
}
else {
say_file("time/hours.wav");
}
if (hours == 1) {
say_file("time/hour.wav"); //TODO -- NEED TO GET "hour.wav" recorded
} else {
say_file("time/hours.wav");
}
} else {
say_file("digits/0.wav");
say_file("time/hours.wav");
}
else {
say_file("digits/0.wav");
say_file("time/hours.wav");
}
if (minutes) {
say_num(minutes, SSM_PRONOUNCED);
if (minutes == 1) {
say_file("time/minute.wav");
}
else {
say_file("time/minutes.wav");
}
if (minutes == 1) {
say_file("time/minute.wav");
} else {
say_file("time/minutes.wav");
}
} else {
say_file("digits/0.wav");
say_file("time/minutes.wav");
}
else {
say_file("digits/0.wav");
say_file("time/minutes.wav");
}
if (seconds) {
say_num(seconds, SSM_PRONOUNCED);
if (seconds == 1) {
say_file("time/second.wav");
}
else {
say_file("time/seconds.wav");
}
if (seconds == 1) {
say_file("time/second.wav");
} else {
say_file("time/seconds.wav");
}
} else {
say_file("digits/0.wav");
say_file("time/seconds.wav");
}
else {
say_file("digits/0.wav");
say_file("time/seconds.wav");
}
return SWITCH_STATUS_SUCCESS;
}
@@ -379,8 +363,8 @@ static switch_status_t en_say_time(switch_core_session_t *session,
target = switch_time_now();
}
switch_time_exp_lt(&tm, target);
switch(type) {
switch (type) {
case SST_CURRENT_DATE_TIME:
say_date = say_time = 1;
break;
@@ -403,10 +387,10 @@ static switch_status_t en_say_time(switch_core_session_t *session,
if (say_time) {
int32_t hour = tm.tm_hour, pm = 0;
if (hour > 12) {
hour -= 12;
pm = 1;
pm = 1;
} else if (hour == 12) {
pm = 1;
} else if (hour == 0) {
@@ -433,21 +417,19 @@ static switch_status_t en_say_time(switch_core_session_t *session,
static switch_status_t en_say_money(switch_core_session_t *session,
char *tosay,
switch_say_type_t type,
switch_say_method_t method,
switch_input_args_t *args)
char *tosay,
switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
switch_channel_t *channel;
char sbuf[16] = ""; /* enuough for 999,999,999,999.99 (w/o the commas or leading $) */
char sbuf[16] = ""; /* enuough for 999,999,999,999.99 (w/o the commas or leading $) */
char *dollars = NULL;
char *cents = NULL;
assert(session != NULL);
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
if (strlen(tosay) > 15 || !(tosay = strip_nonnumerics(tosay, sbuf, sizeof(sbuf)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Parse Error!\n");
return SWITCH_STATUS_GENERR;
@@ -457,49 +439,46 @@ static switch_status_t en_say_money(switch_core_session_t *session,
if ((cents = strchr(sbuf, '.'))) {
*cents++ = '\0';
if (strlen(cents) > 2) {
cents[2] = '\0';
}
if (strlen(cents) > 2) {
cents[2] = '\0';
}
}
/* If positive sign - skip over" */
if (sbuf[0] == '+') {
dollars++;
}
/* If positive sign - skip over" */
if (sbuf[0] == '+') {
dollars++;
}
/* If negative say "negative" */
if (sbuf[0] == '-') {
say_file("currency/negative.wav");
dollars++;
}
/* Say dollar amount */
en_say_general_count(session, dollars, type, method, args);
if (atoi(dollars) == 1) {
say_file("currency/dollar.wav");
}
else {
} else {
say_file("currency/dollars.wav");
}
/* Say "and" */
say_file("currency/and.wav");
/* Say cents */
if (cents) {
en_say_general_count(session, cents, type, method, args);
if (atoi(cents) == 1) {
say_file("currency/cent.wav");
}
else {
say_file("currency/cents.wav");
}
}
else {
say_file("digits/0.wav");
say_file("currency/cents.wav");
}
/* Say cents */
if (cents) {
en_say_general_count(session, cents, type, method, args);
if (atoi(cents) == 1) {
say_file("currency/cent.wav");
} else {
say_file("currency/cents.wav");
}
} else {
say_file("digits/0.wav");
say_file("currency/cents.wav");
}
return SWITCH_STATUS_SUCCESS;
}
@@ -507,14 +486,12 @@ static switch_status_t en_say_money(switch_core_session_t *session,
static switch_status_t en_say(switch_core_session_t *session,
char *tosay,
switch_say_type_t type,
switch_say_method_t method,
switch_input_args_t *args)
switch_say_type_t type, switch_say_method_t method, switch_input_args_t *args)
{
switch_say_callback_t say_cb = NULL;
switch(type) {
switch (type) {
case SST_NUMBER:
case SST_ITEMS:
case SST_PERSONS:
@@ -541,15 +518,15 @@ static switch_status_t en_say(switch_core_session_t *session,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown Say type=[%d]\n", type);
break;
}
if (say_cb) {
return say_cb(session, tosay, type, method, args);
}
}
return SWITCH_STATUS_FALSE;
}
static const switch_say_interface_t en_say_interface= {
static const switch_say_interface_t en_say_interface = {
/*.name */ "en",
/*.say_function */ en_say,
};
@@ -566,11 +543,12 @@ static switch_loadable_module_interface_t say_en_module_interface = {
/*.speech_interface */ NULL,
/*.directory_interface */ NULL,
/*.chat_interface */ NULL,
/*.say_inteface*/ &en_say_interface,
/*.asr_interface*/ NULL
/*.say_inteface */ &en_say_interface,
/*.asr_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &say_en_module_interface;
+26 -26
View File
@@ -50,8 +50,8 @@ static const char modname[] = "mod_softtimer";
#define MAX_ELEMENTS 1000
struct timer_private {
switch_size_t reference;
switch_size_t start;
switch_size_t reference;
switch_size_t start;
uint32_t roll;
uint32_t ready;
};
@@ -64,7 +64,7 @@ struct timer_matrix {
};
typedef struct timer_matrix timer_matrix_t;
static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS+1];
static timer_matrix_t TIMER_MATRIX[MAX_ELEMENTS + 1];
#define IDLE_SPEED 100
@@ -110,16 +110,16 @@ static inline switch_status_t timer_step(switch_timer_t *timer)
check_roll();
samples = timer->samples * (private_info->reference - private_info->start);
if (samples > UINT32_MAX) {
private_info->start = private_info->reference;
samples = timer->samples;
}
timer->samplecount = (uint32_t)samples;
private_info->reference++;
return SWITCH_STATUS_SUCCESS;
timer->samplecount = (uint32_t) samples;
private_info->reference++;
return SWITCH_STATUS_SUCCESS;
}
@@ -129,12 +129,12 @@ static inline switch_status_t timer_next(switch_timer_t *timer)
timer_step(timer);
while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
check_roll();
switch_yield(1000);
}
if (globals.RUNNING == 1) {
if (globals.RUNNING == 1) {
return SWITCH_STATUS_SUCCESS;
}
@@ -142,11 +142,10 @@ static inline switch_status_t timer_next(switch_timer_t *timer)
}
static inline switch_status_t timer_check(switch_timer_t *timer)
{
timer_private_t *private_info = timer->private_info;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_size_t diff;
switch_size_t diff;
if (globals.RUNNING != 1 || !private_info->ready) {
return SWITCH_STATUS_SUCCESS;
@@ -155,16 +154,16 @@ static inline switch_status_t timer_check(switch_timer_t *timer)
check_roll();
if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
} else {
diff = 0;
diff = 0;
}
if (diff) {
status = SWITCH_STATUS_FALSE;
} else {
timer_step(timer);
}
if (diff) {
status = SWITCH_STATUS_FALSE;
} else {
timer_step(timer);
}
return status;
}
@@ -198,7 +197,8 @@ static const switch_loadable_module_interface_t mod_softtimer_module_interface =
/*.timer_interface */ &timer_interface
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
@@ -224,13 +224,13 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
switch_time_t reference = switch_time_now();
uint32_t current_ms = 0;
uint32_t x;
memset(&globals, 0, sizeof(globals));
switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
globals.RUNNING = 1;
while(globals.RUNNING == 1) {
while (globals.RUNNING == 1) {
reference += STEP_MIC;
while (switch_time_now() < reference) {
@@ -244,8 +244,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
if (i == 0) {
i = 1;
}
index = (current_ms % i == 0) ? i : 0;
index = (current_ms % i == 0) ? i : 0;
if (TIMER_MATRIX[index].count) {
TIMER_MATRIX[index].tick++;
@@ -271,12 +271,12 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
{
if (globals.RUNNING) {
switch_mutex_lock(globals.mutex);
globals.RUNNING = -1;
switch_mutex_unlock(globals.mutex);
while (globals.RUNNING) {
switch_yield(10000);
}
+9 -8
View File
@@ -37,7 +37,7 @@ static const char modname[] = "mod_xml_cdr";
static switch_status_t my_on_hangup(switch_core_session_t *session)
{
switch_xml_t cdr;
if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(session);
char *xml_text;
@@ -51,16 +51,16 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if ((alt = switch_channel_get_variable(channel, "xml_cdr_base"))) {
logdir = alt;
}
if ((path = switch_mprintf("%s/xml_cdr/%s.cdr.xml", logdir, uuid_str))) {
if ((xml_text = switch_xml_toxml(cdr))) {
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
write(fd, header, (unsigned)strlen(header));
write(fd, xml_text, (unsigned)strlen(xml_text));
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
write(fd, header, (unsigned) strlen(header));
write(fd, xml_text, (unsigned) strlen(xml_text));
close(fd);
fd = -1;
} else {
char ebuf[512] = {0};
char ebuf[512] = { 0 };
#ifdef WIN32
strerror_s(ebuf, sizeof(ebuf), errno);
#else
@@ -77,7 +77,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Generating Data!\n");
}
return SWITCH_STATUS_SUCCESS;
}
@@ -100,7 +100,8 @@ static const switch_loadable_module_interface_t mod_xml_cdr_module_interface = {
/*.application_interface */ NULL
};
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* test global state handlers */
switch_core_add_state_handler(&state_handlers);
+81 -84
View File
@@ -36,7 +36,7 @@ static const char modname[] = "mod_xml_curl";
struct xml_binding {
char *url;
char *bindings;
char *cred;
char *cred;
};
typedef struct xml_binding xml_binding_t;
@@ -48,7 +48,7 @@ struct config_data {
static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
{
register unsigned int realsize = (unsigned int)(size * nmemb);
register unsigned int realsize = (unsigned int) (size * nmemb);
struct config_data *config_data = data;
write(config_data->fd, ptr, realsize);
@@ -58,45 +58,42 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
static switch_xml_t xml_url_fetch(const char *section,
const char *tag_name,
const char *key_name,
const char *key_value,
const char *params,
void *user_data)
const char *key_name, const char *key_value, const char *params, void *user_data)
{
char filename[512] = "";
CURL *curl_handle = NULL;
struct config_data config_data;
switch_xml_t xml = NULL;
char *data = NULL;
char *data = NULL;
switch_uuid_t uuid;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
xml_binding_t *binding = (xml_binding_t *) user_data;
char *file_url;
xml_binding_t *binding = (xml_binding_t *) user_data;
char *file_url;
if (!binding) {
return NULL;
}
if (!binding) {
return NULL;
}
if ((file_url = strstr(binding->url, "file:"))) {
file_url += 5;
if (!(xml = switch_xml_parse_file(file_url))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
}
return xml;
}
if ((file_url = strstr(binding->url, "file:"))) {
file_url += 5;
if (!(data = switch_mprintf("section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
section,
tag_name ? tag_name : "",
key_name ? key_name : "",
key_value ? key_value : "",
params ? strchr(params,'=') ? "&" : "&params=" : "", params ? params : ""))) {
if (!(xml = switch_xml_parse_file(file_url))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
return NULL;
}
return xml;
}
if (!(data = switch_mprintf("section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
section,
tag_name ? tag_name : "",
key_name ? key_name : "",
key_value ? key_value : "",
params ? strchr(params, '=') ? "&" : "&params=" : "", params ? params : ""))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
return NULL;
}
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);
@@ -107,18 +104,18 @@ static switch_xml_t xml_url_fetch(const char *section,
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
config_data.name = filename;
if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC)) > -1) {
if (!switch_strlen_zero(binding->cred)) {
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
}
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
if (!switch_strlen_zero(binding->cred)) {
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
}
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl_handle, CURLOPT_URL, binding->url);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&config_data);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &config_data);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
curl_easy_perform(curl_handle);
curl_easy_cleanup(curl_handle);
@@ -127,14 +124,14 @@ static switch_xml_t xml_url_fetch(const char *section,
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error!\n");
}
switch_safe_free(data);
switch_safe_free(data);
if (!(xml = switch_xml_parse_file(filename))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Parsing Result!\n");
}
unlink(filename);
return xml;
}
@@ -152,12 +149,12 @@ static switch_loadable_module_interface_t xml_curl_module_interface = {
/*.directory_interface */ NULL
};
static switch_status_t do_config(void)
static switch_status_t do_config(void)
{
char *cf = "xml_curl.conf";
switch_xml_t cfg, xml, bindings_tag, binding_tag, param;
xml_binding_t *binding = NULL;
int x = 0;
xml_binding_t *binding = NULL;
int x = 0;
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
@@ -165,56 +162,55 @@ static switch_status_t do_config(void)
}
if (!(bindings_tag = switch_xml_child(cfg, "bindings"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing <bindings> tag!\n");
return SWITCH_STATUS_FALSE;
}
for (binding_tag = switch_xml_child(bindings_tag, "binding"); binding_tag; binding_tag = binding_tag->next) {
char *bname = (char *) switch_xml_attr_soft(binding_tag, "name");
char *url = NULL;
char *bind_cred = NULL;
char *bind_mask = NULL;
char *bname = (char *) switch_xml_attr_soft(binding_tag, "name");
char *url = NULL;
char *bind_cred = NULL;
char *bind_mask = NULL;
for (param = switch_xml_child(binding_tag, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
if (!strcasecmp(var, "gateway-url")) {
if (!strcasecmp(var, "gateway-url")) {
bind_mask = (char *) switch_xml_attr_soft(param, "bindings");
if (val) {
url = val;
}
if (val) {
url = val;
}
} else if (!strcasecmp(var, "gateway-credentials")) {
bind_cred = val;
}
bind_cred = val;
}
}
if (!url) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no url!\n");
continue;
}
if (!(binding = malloc(sizeof(*binding)))) {
return SWITCH_STATUS_FALSE;
}
memset(binding, 0, sizeof(*binding));
if (!url) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Binding has no url!\n");
continue;
}
binding->url = strdup(url);
if (!(binding = malloc(sizeof(*binding)))) {
return SWITCH_STATUS_FALSE;
}
memset(binding, 0, sizeof(*binding));
if (bind_mask) {
binding->bindings = strdup(bind_mask);
}
binding->url = strdup(url);
if (bind_cred) {
binding->cred = strdup(bind_cred);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
switch_strlen_zero(bname) ? "N/A" : bname,
binding->url,
binding->bindings ? binding->bindings : "all");
if (bind_mask) {
binding->bindings = strdup(bind_mask);
}
if (bind_cred) {
binding->cred = strdup(bind_cred);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
switch_strlen_zero(bname) ? "N/A" : bname,
binding->url, binding->bindings ? binding->bindings : "all");
switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->bindings), binding);
x++;
binding = NULL;
x++;
binding = NULL;
}
switch_xml_free(xml);
@@ -223,16 +219,17 @@ static switch_status_t do_config(void)
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &xml_curl_module_interface;
if (do_config() == SWITCH_STATUS_SUCCESS) {
curl_global_init(CURL_GLOBAL_ALL);
} else {
return SWITCH_STATUS_FALSE;
}
curl_global_init(CURL_GLOBAL_ALL);
} else {
return SWITCH_STATUS_FALSE;
}
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
+76 -64
View File
@@ -66,10 +66,10 @@ static struct {
} globals;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_realm, globals.realm)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_user, globals.user)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_user, globals.user)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_pass, globals.pass)
static switch_status_t do_config(void)
static switch_status_t do_config(void)
{
char *cf = "xml_rpc.conf";
switch_xml_t cfg, xml, settings, param;
@@ -93,11 +93,11 @@ static switch_status_t do_config(void)
} else if (!strcasecmp(var, "auth-pass")) {
pass = val;
} else if (!strcasecmp(var, "http-port")) {
globals.port = (uint16_t)atoi(val);
globals.port = (uint16_t) atoi(val);
}
}
}
if (!globals.port) {
globals.port = 8080;
}
@@ -112,14 +112,15 @@ static switch_status_t do_config(void)
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &xml_rpc_module_interface;
memset(&globals, 0, sizeof(globals));
do_config();
do_config();
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
@@ -136,73 +137,82 @@ static switch_status_t http_stream_write(switch_stream_handle_t *handle, const c
va_start(ap, fmt);
ret = switch_vasprintf(&data, fmt, ap);
va_end(ap);
if (data) {
ret = 0;
HTTPWrite(r, data, (uint32_t)strlen(data));
HTTPWrite(r, data, (uint32_t) strlen(data));
free(data);
}
return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
abyss_bool HandleHook(TSession *r)
abyss_bool HandleHook(TSession * r)
{
char *m = "text/html";
switch_stream_handle_t stream = {0};
char *m = "text/html";
switch_stream_handle_t stream = { 0 };
char *command;
stream.data = r;
stream.write_function = http_stream_write;
if (globals.realm) {
if (!RequestAuth(r,globals.realm, globals.user, globals.pass)) {
if (!RequestAuth(r, globals.realm, globals.user, globals.pass)) {
return TRUE;
}
}
if(strncmp(r->uri, "/api/", 5)) {
if (strncmp(r->uri, "/api/", 5)) {
return FALSE;
}
if (switch_event_create(&stream.event, SWITCH_EVENT_API) == SWITCH_STATUS_SUCCESS) {
if (r->uri) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-URI", "%s", r->uri);
if (r->query) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-QUERY", "%s", r->query);
if (r->host) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-HOST", "%s", r->host);
if (r->from) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-FROM", "%s", r->from);
if (r->useragent) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER-AGENT", "%s", r->useragent);
if (r->referer) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REFERER", "%s", r->referer);
if (r->requestline) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REQUESTLINE", "%s", r->requestline);
if (r->user) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER", "%s", r->user);
if (r->port) switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-PORT", "%u", r->port);
if (r->uri)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-URI", "%s", r->uri);
if (r->query)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-QUERY", "%s", r->query);
if (r->host)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-HOST", "%s", r->host);
if (r->from)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-FROM", "%s", r->from);
if (r->useragent)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER-AGENT", "%s", r->useragent);
if (r->referer)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REFERER", "%s", r->referer);
if (r->requestline)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-REQUESTLINE", "%s", r->requestline);
if (r->user)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-USER", "%s", r->user);
if (r->port)
switch_event_add_header(stream.event, SWITCH_STACK_BOTTOM, "HTTP-PORT", "%u", r->port);
}
command = r->uri + 5;
ResponseChunked(r);
ResponseStatus(r,200);
ResponseStatus(r, 200);
ResponseContentType(r, m);
ResponseWrite(r);
ResponseWrite(r);
switch_api_execute(command, r->query, NULL, &stream);
HTTPWriteEnd(r);
return TRUE;
return TRUE;
}
static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData)
static xmlrpc_value *freeswitch_api(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData)
{
char *command, *arg;
switch_stream_handle_t stream = {0};
switch_stream_handle_t stream = { 0 };
xmlrpc_value *val = NULL;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg);
if (envP->fault_occurred) {
return NULL;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg);
if (envP->fault_occurred) {
return NULL;
}
SWITCH_STANDARD_STREAM(stream);
@@ -217,17 +227,17 @@ static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const
return val;
}
static xmlrpc_value *freeswitch_man(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData)
static xmlrpc_value *freeswitch_man(xmlrpc_env * const envP, xmlrpc_value * const paramArrayP, void *const userData)
{
char *oid, *relative_oid, *s_action, *data;
char buf[SWITCH_MAX_MANAGEMENT_BUFFER_LEN] = "";
switch_management_action_t action = SMA_NONE;
xmlrpc_value *val;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
if (envP->fault_occurred) {
return NULL;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
if (envP->fault_occurred) {
return NULL;
}
if (!strncasecmp(oid, FREESWITCH_OID_PREFIX, strlen(FREESWITCH_OID_PREFIX))) {
@@ -262,46 +272,48 @@ static xmlrpc_value *freeswitch_man(xmlrpc_env *const envP, xmlrpc_value *const
snprintf(buf, sizeof(buf), "Invalid Action %s\n", s_action);
}
/* Return our result. */
val = xmlrpc_build_value(envP, "s", buf);
/* Return our result. */
val = xmlrpc_build_value(envP, "s", buf);
return val;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
{
TServer abyssServer;
xmlrpc_registry * registryP;
xmlrpc_env env;
TServer abyssServer;
xmlrpc_registry *registryP;
xmlrpc_env env;
char logfile[512];
globals.running = 1;
xmlrpc_env_init(&env);
registryP = xmlrpc_registry_new(&env);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL,"freeswitch_api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.management", &freeswitch_man, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL,"freeswitch_management", &freeswitch_man, NULL);
xmlrpc_env_init(&env);
MIMETypeInit();
registryP = xmlrpc_registry_new(&env);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch_api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.management", &freeswitch_man, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch_management", &freeswitch_man, NULL);
MIMETypeInit();
MIMETypeAdd("text/html", "html");
snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, "freeswitch_http.log");
ServerCreate(&abyssServer, "XmlRpcServer", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir, logfile);
xmlrpc_server_abyss_set_handler(&env, &abyssServer, "/RPC2", registryP);
snprintf(logfile, sizeof(logfile), "%s%s%s", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR,
"freeswitch_http.log");
ServerCreate(&abyssServer, "XmlRpcServer", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir, logfile);
ServerInit(&abyssServer);
xmlrpc_server_abyss_set_handler(&env, &abyssServer, "/RPC2", registryP);
ServerInit(&abyssServer);
ServerAddHandler(&abyssServer, HandleHook);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting HTTP Port %d, DocRoot [%s]\n", globals.port, SWITCH_GLOBAL_dirs.htdocs_dir);
while (globals.running) {
ServerRunOnce2(&abyssServer, ABYSS_FOREGROUND);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Starting HTTP Port %d, DocRoot [%s]\n", globals.port,
SWITCH_GLOBAL_dirs.htdocs_dir);
while (globals.running) {
ServerRunOnce2(&abyssServer, ABYSS_FOREGROUND);
}
return SWITCH_STATUS_SUCCESS;