mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-07 13:49:18 +00:00
Fix RFC2833 issues with DTMF getting duplicated and with duration wrapping over.
(closes issue #14815) Reported by: geoff2010 Patches: v1-14815.patch uploaded by dimas (license 88) Tested by: geoff2010, file, dimas, ZX81, moliveras (closes issue #14460) Reported by: moliveras Tested by: moliveras git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@194208 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
81
main/rtp.c
81
main/rtp.c
@@ -73,7 +73,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||||||
|
|
||||||
#define RTP_MTU 1200
|
#define RTP_MTU 1200
|
||||||
|
|
||||||
#define DEFAULT_DTMF_TIMEOUT 3000 /*!< samples */
|
#define DEFAULT_DTMF_TIMEOUT (150 * (8000 / 1000)) /*!< samples */
|
||||||
|
|
||||||
static int dtmftimeout = DEFAULT_DTMF_TIMEOUT;
|
static int dtmftimeout = DEFAULT_DTMF_TIMEOUT;
|
||||||
|
|
||||||
@@ -139,7 +139,8 @@ struct ast_rtp {
|
|||||||
/* DTMF Reception Variables */
|
/* DTMF Reception Variables */
|
||||||
char resp;
|
char resp;
|
||||||
unsigned int lastevent;
|
unsigned int lastevent;
|
||||||
int dtmfcount;
|
unsigned int dtmf_duration; /*!< Total duration in samples since the digit start event */
|
||||||
|
unsigned int dtmf_timeout; /*!< When this timestamp is reached we consider END frame lost and forcibly abort digit */
|
||||||
/* DTMF Transmission Variables */
|
/* DTMF Transmission Variables */
|
||||||
unsigned int lastdigitts;
|
unsigned int lastdigitts;
|
||||||
char sending_digit; /*!< boolean - are we sending digits */
|
char sending_digit; /*!< boolean - are we sending digits */
|
||||||
@@ -689,7 +690,7 @@ static struct ast_frame *process_cisco_dtmf(struct ast_rtp *rtp, unsigned char *
|
|||||||
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
||||||
}
|
}
|
||||||
rtp->resp = resp;
|
rtp->resp = resp;
|
||||||
rtp->dtmfcount = dtmftimeout;
|
rtp->dtmf_timeout = 0;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,23 +746,59 @@ static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *dat
|
|||||||
if (ast_test_flag(rtp, FLAG_DTMF_COMPENSATE)) {
|
if (ast_test_flag(rtp, FLAG_DTMF_COMPENSATE)) {
|
||||||
if ((rtp->lastevent != timestamp) || (rtp->resp && rtp->resp != resp)) {
|
if ((rtp->lastevent != timestamp) || (rtp->resp && rtp->resp != resp)) {
|
||||||
rtp->resp = resp;
|
rtp->resp = resp;
|
||||||
rtp->dtmfcount = 0;
|
rtp->dtmf_timeout = 0;
|
||||||
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
||||||
f->len = 0;
|
f->len = 0;
|
||||||
rtp->lastevent = timestamp;
|
rtp->lastevent = timestamp;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((!(rtp->resp) && (!(event_end & 0x80))) || (rtp->resp && rtp->resp != resp)) {
|
/* The duration parameter measures the complete
|
||||||
rtp->resp = resp;
|
duration of the event (from the beginning) - RFC2833.
|
||||||
f = send_dtmf(rtp, AST_FRAME_DTMF_BEGIN);
|
Account for the fact that duration is only 16 bits long
|
||||||
rtp->dtmfcount = dtmftimeout;
|
(about 8 seconds at 8000 Hz) and can wrap if digit
|
||||||
} else if ((event_end & 0x80) && (rtp->lastevent != seqno) && rtp->resp) {
|
is held for too long. */
|
||||||
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
unsigned int new_duration = rtp->dtmf_duration;
|
||||||
f->len = ast_tvdiff_ms(ast_samp2tv(samples, 8000), ast_tv(0, 0)); /* XXX hard coded 8kHz */
|
unsigned int last_duration = new_duration & 0xFFFF;
|
||||||
rtp->resp = 0;
|
|
||||||
rtp->dtmfcount = 0;
|
if (last_duration > 64000 && samples < last_duration)
|
||||||
rtp->lastevent = seqno;
|
new_duration += 0xFFFF + 1;
|
||||||
|
new_duration = (new_duration & ~0xFFFF) | samples;
|
||||||
|
|
||||||
|
if (event_end & 0x80) {
|
||||||
|
/* End event */
|
||||||
|
if ((rtp->lastevent != seqno) && rtp->resp) {
|
||||||
|
rtp->dtmf_duration = new_duration;
|
||||||
|
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
||||||
|
f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, 8000), ast_tv(0, 0));
|
||||||
|
rtp->resp = 0;
|
||||||
|
rtp->dtmf_duration = rtp->dtmf_timeout = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Begin/continuation */
|
||||||
|
|
||||||
|
if (rtp->resp && rtp->resp != resp) {
|
||||||
|
/* Another digit already began. End it */
|
||||||
|
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
||||||
|
f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, 8000), ast_tv(0, 0));
|
||||||
|
rtp->resp = 0;
|
||||||
|
rtp->dtmf_duration = rtp->dtmf_timeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (rtp->resp) {
|
||||||
|
/* Digit continues */
|
||||||
|
rtp->dtmf_duration = new_duration;
|
||||||
|
} else {
|
||||||
|
/* New digit began */
|
||||||
|
rtp->resp = resp;
|
||||||
|
f = send_dtmf(rtp, AST_FRAME_DTMF_BEGIN);
|
||||||
|
rtp->dtmf_duration = samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtp->dtmf_timeout = timestamp + rtp->dtmf_duration + dtmftimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rtp->lastevent = seqno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
@@ -1291,17 +1328,15 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
|
|||||||
|
|
||||||
rtp->rxseqno = seqno;
|
rtp->rxseqno = seqno;
|
||||||
|
|
||||||
if (rtp->dtmfcount) {
|
if (rtp->dtmf_timeout && rtp->dtmf_timeout < timestamp) {
|
||||||
rtp->dtmfcount -= (timestamp - rtp->lastrxts);
|
rtp->dtmf_timeout = 0;
|
||||||
|
|
||||||
if (rtp->dtmfcount < 0) {
|
if (rtp->resp) {
|
||||||
rtp->dtmfcount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rtp->resp && !rtp->dtmfcount) {
|
|
||||||
struct ast_frame *f;
|
struct ast_frame *f;
|
||||||
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
f = send_dtmf(rtp, AST_FRAME_DTMF_END);
|
||||||
|
f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, 8000), ast_tv(0, 0));
|
||||||
rtp->resp = 0;
|
rtp->resp = 0;
|
||||||
|
rtp->dtmf_timeout = rtp->dtmf_duration = 0;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2085,7 +2120,7 @@ void ast_rtp_reset(struct ast_rtp *rtp)
|
|||||||
rtp->lastevent = 0;
|
rtp->lastevent = 0;
|
||||||
rtp->lasttxformat = 0;
|
rtp->lasttxformat = 0;
|
||||||
rtp->lastrxformat = 0;
|
rtp->lastrxformat = 0;
|
||||||
rtp->dtmfcount = 0;
|
rtp->dtmf_timeout = 0;
|
||||||
rtp->seqno = 0;
|
rtp->seqno = 0;
|
||||||
rtp->rxseqno = 0;
|
rtp->rxseqno = 0;
|
||||||
}
|
}
|
||||||
@@ -3848,7 +3883,7 @@ int ast_rtp_reload(void)
|
|||||||
}
|
}
|
||||||
if ((s = ast_variable_retrieve(cfg, "general", "dtmftimeout"))) {
|
if ((s = ast_variable_retrieve(cfg, "general", "dtmftimeout"))) {
|
||||||
dtmftimeout = atoi(s);
|
dtmftimeout = atoi(s);
|
||||||
if ((dtmftimeout < 0) || (dtmftimeout > 20000)) {
|
if ((dtmftimeout < 0) || (dtmftimeout > 64000)) {
|
||||||
ast_log(LOG_WARNING, "DTMF timeout of '%d' outside range, using default of '%d' instead\n",
|
ast_log(LOG_WARNING, "DTMF timeout of '%d' outside range, using default of '%d' instead\n",
|
||||||
dtmftimeout, DEFAULT_DTMF_TIMEOUT);
|
dtmftimeout, DEFAULT_DTMF_TIMEOUT);
|
||||||
dtmftimeout = DEFAULT_DTMF_TIMEOUT;
|
dtmftimeout = DEFAULT_DTMF_TIMEOUT;
|
||||||
|
Reference in New Issue
Block a user