diff --git a/channels/chan_modem.c b/channels/chan_modem.c index 59018c09cd..c2f7e61870 100755 --- a/channels/chan_modem.c +++ b/channels/chan_modem.c @@ -63,6 +63,13 @@ static char msn[AST_MAX_EXTENSION]=""; /* Default Listen */ static char incomingmsn[AST_MAX_EXTENSION]=""; +/* Default DTMF-detection mode (i4l/asterisk) */ +static int dtmfmode = MODEM_DTMF_AST; +/* Default DTMF-generation mode (i4l (outband) / asterisk (inband) */ +static int dtmfmodegen = MODEM_DTMF_AST; + +struct ast_dsp *dsp = NULL; + /* Default valid outgoing MSN */ static char outgoingmsn[AST_MAX_EXTENSION]=""; @@ -711,6 +718,8 @@ static struct ast_modem_pvt *mkif(char *iface) strncpy(tmp->language, language, sizeof(tmp->language)-1); strncpy(tmp->msn, msn, sizeof(tmp->msn)-1); strncpy(tmp->incomingmsn, incomingmsn, sizeof(tmp->incomingmsn)-1); + tmp->dtmfmode = dtmfmode; + tmp->dtmfmodegen = dtmfmodegen; snprintf(tmp->outgoingmsn, sizeof(tmp->outgoingmsn), ",%s,", outgoingmsn); strncpy(tmp->dev, iface, sizeof(tmp->dev)-1); /* Maybe in the future we want to allow variable @@ -972,6 +981,36 @@ int load_module() strncpy(msn, v->value, sizeof(msn)-1); } else if (!strcasecmp(v->name, "incomingmsn")) { strncpy(incomingmsn, v->value, sizeof(incomingmsn)-1); + } else if (!strcasecmp(v->name, "dtmfmode")) { + char tmp[80]; + char *alt; + strncpy(tmp, v->value, sizeof(tmp) - 1); + alt = strchr(tmp, '/'); + if (!strcasecmp(tmp, "none")) + dtmfmode=MODEM_DTMF_NONE; + else if (!strcasecmp(tmp, "asterisk")) + dtmfmode = MODEM_DTMF_AST; + else if (!strcasecmp(tmp, "i4l")) + dtmfmode = MODEM_DTMF_I4L; + else { + ast_log(LOG_WARNING, "Unknown dtmf detection mode '%s', using 'asterisk'\n", v->value); + dtmfmode = MODEM_DTMF_AST; + } + if (alt) { + if (!strcasecmp(alt, "none")) + dtmfmodegen=MODEM_DTMF_NONE; + else if (!strcasecmp(alt, "asterisk")) + dtmfmodegen = MODEM_DTMF_AST; + else if (!strcasecmp(alt, "i4l")) + dtmfmodegen = MODEM_DTMF_I4L; + else if (!strcasecmp(alt, "both")) + dtmfmodegen = MODEM_DTMF_I4L | MODEM_DTMF_AST; + else { + ast_log(LOG_WARNING, "Unknown dtmf generation mode '%s', using 'asterisk'\n", v->value); + dtmfmodegen = MODEM_DTMF_AST; + } + } else + dtmfmodegen = dtmfmode; } else if (!strcasecmp(v->name, "outgoingmsn")) { strncpy(outgoingmsn, v->value, sizeof(outgoingmsn)-1); } else if (!strcasecmp(v->name, "language")) { diff --git a/channels/chan_modem_i4l.c b/channels/chan_modem_i4l.c index ec854d06d9..ce7de41740 100755 --- a/channels/chan_modem_i4l.c +++ b/channels/chan_modem_i4l.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "alaw.h" #define STATE_COMMAND 0 @@ -94,6 +96,21 @@ static int i4l_startrec(struct ast_modem_pvt *p) return -1; } p->ministate = STATE_VOICE; + + /* let ast dsp detect dtmf */ + if (p->dtmfmode & MODEM_DTMF_AST) { + if (p->dsp) { + ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev); + } else { + p->dsp = ast_dsp_new(); + if (p->dsp) { + ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev); + ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT); + ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0); + } + } + } + return 0; } @@ -277,7 +294,7 @@ static struct ast_frame *i4l_handle_escape(struct ast_modem_pvt *p, char esc) case '9': case '*': case '#': - ast_log(LOG_DEBUG, "DTMF: '%c' (%d)\n", esc, esc); + ast_log(LOG_DEBUG, "Detected outband DTMF digit: '%c' (%d)\n", esc, esc); p->fr.frametype=AST_FRAME_DTMF; p->fr.subclass=esc; return &p->fr; @@ -409,8 +426,11 @@ static struct ast_frame *i4l_read(struct ast_modem_pvt *p) if (f) break; } - if (f) + if (f) { + if( ! (!(p->dtmfmode & MODEM_DTMF_I4L) && f->frametype == AST_FRAME_DTMF)) return f; + } + /* If we get here, we have a complete voice frame */ p->fr.frametype = AST_FRAME_VOICE; p->fr.subclass = AST_FORMAT_SLINEAR; @@ -421,6 +441,16 @@ static struct ast_frame *i4l_read(struct ast_modem_pvt *p) p->fr.offset = AST_FRIENDLY_OFFSET; p->fr.src = __FUNCTION__; p->obuflen = 0; + + /* process with dsp */ + if (p->dsp) { + f = ast_dsp_process(p->owner, p->dsp, &p->fr); + if (f && (f->frametype == AST_FRAME_DTMF)) { + ast_log(LOG_DEBUG, "Detected inband DTMF digit: %c on %s\n", f->subclass, p->dev); + return f; + } + } + return &p->fr; } return NULL; @@ -510,6 +540,21 @@ static int i4l_answer(struct ast_modem_pvt *p) return -1; } p->ministate = STATE_VOICE; + + /* let ast dsp detect dtmf */ + if (p->dtmfmode & MODEM_DTMF_AST) { + if (p->dsp) { + ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev); + } else { + p->dsp = ast_dsp_new(); + if (p->dsp) { + ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev); + ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT); + ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0); + } + } + } + return 0; } @@ -517,9 +562,16 @@ static int i4l_dialdigit(struct ast_modem_pvt *p, char digit) { char c[2]; if (p->ministate == STATE_VOICE) { + if (p->dtmfmodegen & MODEM_DTMF_I4L) { c[0] = CHAR_DLE; c[1] = digit; write(p->fd, c, 2); + ast_log(LOG_DEBUG, "Send ISDN out-of-band DTMF %c\n",digit); + } + if(p->dtmfmodegen & MODEM_DTMF_AST) { + ast_log(LOG_DEBUG, "Generating inband DTMF\n"); + return -1; + } } else ast_log(LOG_DEBUG, "Asked to send digit but call not up on %s\n", p->dev); return 0; @@ -567,9 +619,14 @@ static int i4l_hangup(struct ast_modem_pvt *p) char dummy[50]; int dtr = TIOCM_DTR; + /* free the memory used by the DSP */ + if (p->dsp) { + ast_dsp_free(p->dsp); + p->dsp = NULL; + } + /* down DTR to hangup modem */ ioctl(p->fd, TIOCMBIC, &dtr); - /* Read anything outstanding */ while(read(p->fd, dummy, sizeof(dummy)) > 0); diff --git a/configs/modem.conf.sample b/configs/modem.conf.sample index 77dd64cc09..3af4530b0b 100755 --- a/configs/modem.conf.sample +++ b/configs/modem.conf.sample @@ -69,7 +69,18 @@ mode=immediate ; number. ;outgoingmsn=50780023,50780024 ; + +; Set DTMF-detection/generation mode to: +; asterisk: Let Asterisk do inband detection (default) +; i4l: Use the inband detection made by ISDN4Linux +; none: Don't detect inband DTMF +; both: Transmit using both in-band and out of band (generation only) ; +; You may specify either one mode, or the detection/generation mode +; individually separated by a '/'. +; +;dtmfmode=asterisk ; Detect using Asterisk +;dtmfmode=asterisk/both ; Detect using Asterisk, generate w/ both ; two other devices, which are in group '1' and are used when an ; outgoing dial used: exten => s,1,Dial,Modem/g1:1234|60|r ; (we do not need more outgoing devices, since ISDN2 has only 2 channels.) diff --git a/include/asterisk/vmodem.h b/include/asterisk/vmodem.h index b6dc37d075..a2651bdd47 100755 --- a/include/asterisk/vmodem.h +++ b/include/asterisk/vmodem.h @@ -27,6 +27,10 @@ #define MODEM_DEV_SPKRPHONE 6 #define MODEM_DEV_HANDSET 9 +#define MODEM_DTMF_NONE (1 << 0) +#define MODEM_DTMF_AST (1 << 1) +#define MODEM_DTMF_I4L (1 << 2) + /* Thirty millisecond sections */ #define MODEM_MAX_LEN 30 #define MODEM_MAX_BUF MODEM_MAX_LEN * 16 @@ -115,6 +119,12 @@ struct ast_modem_pvt { unsigned int group; /*! Caller ID if available */ char cid[AST_MAX_EXTENSION]; + /*! DTMF-detection mode (i4l/asterisk) */ + int dtmfmode; + /*! DTMF-generation mode (i4l (outband) / asterisk (inband) */ + int dtmfmodegen; + /*! DSP for DTMF detection */ + struct ast_dsp *dsp; /*! Dialed Number if available */ char dnid[AST_MAX_EXTENSION]; /*! Modem initialization String */