int debug;
int panic;
int mtu;
+ int dtmf_on;
+ int dtmf_off;
char *dialplan;
} globals;
switch_caller_profile *caller_profile;
int socket;
int callno;
+ int span;
int cause;
q931_call *call;
+ teletone_dtmf_detect_state_t dtmf_detect;
teletone_generation_session_t tone_session;
switch_buffer *dtmf_buffer;
};
switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
+
+ /* Setup artificial DTMF stuff */
+ memset(&tech_pvt->tone_session, 0, sizeof(tech_pvt->tone_session));
teletone_init_session(&tech_pvt->tone_session, 1024, NULL, NULL);
- if (1 || globals.debug) {
+ if (globals.debug) {
tech_pvt->tone_session.debug = globals.debug;
tech_pvt->tone_session.debug_stream = stdout;
}
tech_pvt->tone_session.rate = rate;
- tech_pvt->tone_session.duration = 150 * (tech_pvt->tone_session.rate / 1000);
- tech_pvt->tone_session.wait = 50 * (tech_pvt->tone_session.rate / 1000);
+ tech_pvt->tone_session.duration = globals.dtmf_on * (tech_pvt->tone_session.rate / 1000);
+ tech_pvt->tone_session.wait = globals.dtmf_off * (tech_pvt->tone_session.rate / 1000);
+ teletone_dtmf_detect_init (&tech_pvt->dtmf_detect, rate);
+
/* Move Channel's State Machine to RING */
switch_channel_set_state(channel, CS_RING);
switch_channel *channel = NULL;
void *bp;
int bytes = 0, res = 0;
+ char digit_str[80];
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
bp += bytes;
}
tech_pvt->read_frame.datalen = bytes;
+ tech_pvt->read_frame.samples = bytes / 2;
+
+ res = teletone_dtmf_detect (&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
+ res = teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
+
+ if(digit_str[0]) {
+ switch_channel_queue_dtmf(channel, digit_str);
+ if (globals.debug) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DTMF DETECTED: [%s]\n", digit_str);
+ }
+ }
*frame = &tech_pvt->read_frame;
return SWITCH_STATUS_SUCCESS;
int res = 0;
int bytes = frame->datalen;
void *bp = frame->data;
+ unsigned char dtmf[1024];
+ int inuse, bread, bwrote = 0;
switch_status status = SWITCH_STATUS_SUCCESS;
channel = switch_core_session_get_channel(session);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
- return SWITCH_STATUS_SUCCESS;
+ while (tech_pvt->dtmf_buffer && bwrote < frame->datalen && bytes > 0 && (inuse = switch_buffer_inuse(tech_pvt->dtmf_buffer)) > 0) {
+ if ((bread = switch_buffer_read(tech_pvt->dtmf_buffer, dtmf, PACKET_LEN)) < PACKET_LEN) {
+ while (bread < PACKET_LEN) {
+ dtmf[bread++] = 0;
+ }
+ }
+ sangoma_socket_waitfor(tech_pvt->socket, -1, POLLOUT | POLLERR | POLLHUP);
+ res = sangoma_sendmsg_socket(tech_pvt->socket,
+ &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), dtmf, bread, 0);
+ if (res < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE,
+ "Bad Write %d bytes returned %d (%s)!\n", bread,
+ res, strerror(errno));
+ if (errno == EBUSY) {
+ continue;
+ }
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Failed!\n");
+ status = SWITCH_STATUS_GENERR;
+ break;
+ } else {
+ bytes -= res;
+ bwrote += res;
+ bp += res;
+ res = 0;
+ }
+ }
+
while (bytes > 0) {
sangoma_socket_waitfor(tech_pvt->socket, -1, POLLOUT | POLLERR | POLLHUP);
res = sangoma_sendmsg_socket(tech_pvt->socket,
if (!tech_pvt->dtmf_buffer) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Allocate DTMF Buffer....");
- if (switch_buffer_create(switch_core_session_get_pool(session), &tech_pvt->dtmf_buffer, 960) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "FAILURE!\n");
+ if (switch_buffer_create(switch_core_session_get_pool(session), &tech_pvt->dtmf_buffer, 3192) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "FAILURE!\n");
return SWITCH_STATUS_FALSE;
} else {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "SUCCESS!\n");
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "SUCCESS!\n");
}
}
for (cur = digits; *cur; cur++) {
tech_pvt->call = event->ringing.call;
}
tech_pvt->callno = event->ring.channel;
-
+ tech_pvt->span = spri->span;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Ringing on channel %d but it's not in use?\n", event->ringing.channel);
}
if (!tech_pvt->call) {
tech_pvt->call = event->ring.call;
}
-
+
tech_pvt->callno = event->ring.channel;
+ tech_pvt->span = spri->span;
if ((fd = sangoma_create_socket_intr(spri->span, event->ring.channel)) < 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open fd!\n");
int current_span = 0;
globals.mtu = DEFAULT_MTU;
+ globals.dtmf_on = 150;
+ globals.dtmf_off = 50;
if (!switch_config_open_file(&cfg, cf)) {
globals.debug = atoi(val);
} else if (!strcmp(var, "mtu")) {
globals.mtu = atoi(val);
+ } else if (!strcmp(var, "dtmf_on")) {
+ globals.dtmf_on = atoi(val);
+ } else if (!strcmp(var, "dtmf_off")) {
+ globals.dtmf_off = atoi(val);
}
} else if (!strcasecmp(cfg.category, "span")) {
if (!strcmp(var, "span")) {