diff mgw/gsm2pstn.c @ 127:f062c32a5116

mgw: implement DTMF
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 01 Oct 2022 20:31:15 -0800
parents 3b3f07b112f3
children 8c28426abef0
line wrap: on
line diff
--- a/mgw/gsm2pstn.c	Sat Oct 01 17:09:51 2022 -0800
+++ b/mgw/gsm2pstn.c	Sat Oct 01 20:31:15 2022 -0800
@@ -5,6 +5,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
@@ -20,6 +21,8 @@
 #include "select.h"
 #include "int_defs.h"
 
+extern struct timeval cur_event_time;
+
 #define	ERR_WRONG_UDP_SRC	0x0001
 #define	ERR_BAD_RTP_PACKET	0x0002
 #define	ERR_SSRC_CHANGE		0x0004
@@ -71,6 +74,8 @@
 			ep->g2p_err_flags |= ERR_SSRC_CHANGE;
 		}
 		ep->g2p_state = 0;
+		if (ep->dtmf_pp)
+			dtmf_stop_immediate(ep);
 	}
 	if (ep->g2p_state) {
 		seq_delta = ntohs(pkt.seq) - ep->g2p_last_seq;
@@ -104,15 +109,28 @@
 	ep->g2p_ssrc = pkt.ssrc;
 	ep->g2p_last_ts = ntohl(pkt.tstamp);
 	ep->g2p_last_seq = ntohs(pkt.seq);
+	ep->g2p_local_time = cur_event_time;
 	/* actual transcoding and forwarding */
 	if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN)) {
 		ep->g2p_drop_flag = 1;
 		return;
 	}
+	if (ep->dtmf_pp)
+		return;
 	if (ep->g2p_drop_flag) {
 		ep->g2p_drop_flag = 0;
 		m_out = 1;
 	}
+	if (ep->dtmf_aftermath) {
+		ts_delta = ep->g2p_last_ts - ep->dtmf_last_ts;
+		if (ts_delta <= 0)
+			return;
+		ep->dtmf_aftermath = 0;
+		if (ts_delta == SAMPLES_PER_FRAME)
+			m_out = 0;
+		else
+			m_out = 1;
+	}
 	switch (ep->gsm_payload_msg_type) {
 	case GSM_TCHF_FRAME:
 		gsm_decode(ep->gsm_decoder_state, pkt.payload, pcm_samples);