From 49f6a880864d35bec9245dc934af3a14f0019c2d Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 16 Aug 2019 10:22:09 -0400 Subject: [PATCH] TT#64259 add function to convert DTMF codes and chars Change-Id: I0b36263033a8614fa448fd4c37dbbc62b516d40a --- daemon/dtmf.c | 24 ++++++++++++++---------- include/dtmf.h | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/daemon/dtmf.c b/daemon/dtmf.c index 82fd6c7d7..fb3358251 100644 --- a/daemon/dtmf.c +++ b/daemon/dtmf.c @@ -124,16 +124,8 @@ int dtmf_event_payload(str *buf, uint64_t *pts, uint64_t duration, struct dtmf_e else if (prev_event.code == 0) ret = 1; // start event - int dtmf_code = -1; - if (cur_event->code >= '0' && cur_event->code <= '9') - dtmf_code = cur_event->code - '0'; - else if (cur_event->code == '*') - dtmf_code = 10; - else if (cur_event->code == '#') - dtmf_code = 11; - else if (cur_event->code >= 'A' && cur_event->code <= 'D') - dtmf_code = cur_event->code - 'A' + 12; - else { + int dtmf_code = dtmf_code_from_char(cur_event->code); + if (dtmf_code == -1) { ilog(LOG_ERR | LOG_FLAG_LIMIT, "Unknown DTMF event code %i", cur_event->code); return 0; } @@ -158,3 +150,15 @@ int dtmf_event_payload(str *buf, uint64_t *pts, uint64_t duration, struct dtmf_e return ret; } + +int dtmf_code_from_char(char c) { + if (c >= '0' && c <= '9') + return c - '0'; + else if (c == '*') + return 10; + else if (c == '#') + return 11; + else if (c >= 'A' && c <= 'D') + return c - 'A' + 12; + return -1; +} diff --git a/include/dtmf.h b/include/dtmf.h index 96ae42308..57717a23e 100644 --- a/include/dtmf.h +++ b/include/dtmf.h @@ -19,6 +19,7 @@ void dtmf_init(void); int dtmf_event(struct media_packet *, str *, int); int dtmf_event_payload(str *, uint64_t *, uint64_t, struct dtmf_event *, GQueue *); void dtmf_event_free(void *); +int dtmf_code_from_char(char); #endif