comparison mgw/dtmf_ctrl.c @ 150:529906fddcfa

mgw DTMF timing fix in the corner case of no speech arriving between the end of one DTMF and the start of next
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2022 14:10:29 -0800
parents f062c32a5116
children a6eb2de277f6
comparison
equal deleted inserted replaced
149:cfc249906145 150:529906fddcfa
60 struct tmgw_ctrl_req *req; 60 struct tmgw_ctrl_req *req;
61 struct tmgw_ctrl_resp *resp; 61 struct tmgw_ctrl_resp *resp;
62 { 62 {
63 struct endpoint *ep; 63 struct endpoint *ep;
64 struct dtmf_desc *desc; 64 struct dtmf_desc *desc;
65 struct timeval tv_diff; 65 struct timeval tv_last, tv_diff;
66 unsigned delta_frames; 66 unsigned delta_frames;
67 67
68 ep = find_ep_by_id(conn, req->ep_id); 68 ep = find_ep_by_id(conn, req->ep_id);
69 if (!ep) { 69 if (!ep) {
70 protocol_err: resp->res = TMGW_RESP_ERR_PROT; 70 protocol_err: resp->res = TMGW_RESP_ERR_PROT;
88 if (!ep->g2p_state) { 88 if (!ep->g2p_state) {
89 resp->res = TMGW_RESP_ERR_NOTRDY; 89 resp->res = TMGW_RESP_ERR_NOTRDY;
90 return; 90 return;
91 } 91 }
92 /* figure out starting timestamp */ 92 /* figure out starting timestamp */
93 if (!ep->dtmf_aftermath) 93 if (ep->dtmf_aftermath)
94 tv_last = ep->dtmf_last_time;
95 else {
94 ep->dtmf_last_ts = ep->g2p_last_ts; 96 ep->dtmf_last_ts = ep->g2p_last_ts;
97 tv_last = ep->g2p_local_time;
98 }
95 ep->dtmf_m_bit = 0; 99 ep->dtmf_m_bit = 0;
96 if (timercmp(&cur_event_time, &ep->g2p_local_time, >)) { 100 if (timercmp(&cur_event_time, &tv_last, >)) {
97 timersub(&cur_event_time, &ep->g2p_local_time, &tv_diff); 101 timersub(&cur_event_time, &tv_last, &tv_diff);
98 delta_frames = tv_diff.tv_sec * 50 + tv_diff.tv_usec / 20000; 102 delta_frames = tv_diff.tv_sec * 50 + tv_diff.tv_usec / 20000;
99 if (delta_frames) { 103 if (delta_frames) {
100 ep->dtmf_last_ts += delta_frames * SAMPLES_PER_FRAME; 104 ep->dtmf_last_ts += delta_frames * SAMPLES_PER_FRAME;
101 ep->dtmf_m_bit = 1; 105 ep->dtmf_m_bit = 1;
102 } 106 }