# HG changeset patch # User Mychaela Falconia # Date 1665526229 28800 # Node ID 529906fddcfa4a39301157f1fcea0bbae0007a2e # Parent cfc2499061457446353aa6dc62565a51139b5242 mgw DTMF timing fix in the corner case of no speech arriving between the end of one DTMF and the start of next diff -r cfc249906145 -r 529906fddcfa mgw/dtmf_ctrl.c --- a/mgw/dtmf_ctrl.c Tue Oct 11 13:48:39 2022 -0800 +++ b/mgw/dtmf_ctrl.c Tue Oct 11 14:10:29 2022 -0800 @@ -62,7 +62,7 @@ { struct endpoint *ep; struct dtmf_desc *desc; - struct timeval tv_diff; + struct timeval tv_last, tv_diff; unsigned delta_frames; ep = find_ep_by_id(conn, req->ep_id); @@ -90,11 +90,15 @@ return; } /* figure out starting timestamp */ - if (!ep->dtmf_aftermath) + if (ep->dtmf_aftermath) + tv_last = ep->dtmf_last_time; + else { ep->dtmf_last_ts = ep->g2p_last_ts; + tv_last = ep->g2p_local_time; + } ep->dtmf_m_bit = 0; - if (timercmp(&cur_event_time, &ep->g2p_local_time, >)) { - timersub(&cur_event_time, &ep->g2p_local_time, &tv_diff); + if (timercmp(&cur_event_time, &tv_last, >)) { + timersub(&cur_event_time, &tv_last, &tv_diff); delta_frames = tv_diff.tv_sec * 50 + tv_diff.tv_usec / 20000; if (delta_frames) { ep->dtmf_last_ts += delta_frames * SAMPLES_PER_FRAME; diff -r cfc249906145 -r 529906fddcfa mgw/dtmf_timer.c --- a/mgw/dtmf_timer.c Tue Oct 11 13:48:39 2022 -0800 +++ b/mgw/dtmf_timer.c Tue Oct 11 14:10:29 2022 -0800 @@ -55,6 +55,7 @@ sendto(ep->rtp_pstn.rtp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0, (struct sockaddr *) &ep->rtp_pstn.remote_addr, addrlen); ep->dtmf_frames_sent++; + ep->dtmf_last_time = cur_event_time; frame_limit = ep->dtmf_stop_req ? DTMF_MIN_FRAMES : DTMF_MAX_FRAMES; if (ep->dtmf_frames_sent >= frame_limit) return 1; diff -r cfc249906145 -r 529906fddcfa mgw/struct.h --- a/mgw/struct.h Tue Oct 11 13:48:39 2022 -0800 +++ b/mgw/struct.h Tue Oct 11 14:10:29 2022 -0800 @@ -42,6 +42,7 @@ /* DTMF generation toward PSTN */ unsigned dtmf_frames_sent; uint32_t dtmf_last_ts; + struct timeval dtmf_last_time; int16_t *dtmf_sample_ptr; int dtmf_m_bit; int dtmf_stop_req;