diff mgw/gsm2pstn.c @ 170:a6eb2de277f6

mgw: massive simplification for continuous RTP stream from BTS
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 20 Nov 2022 01:58:47 -0800
parents 648a64b2e16b
children c985c33baeac
line wrap: on
line diff
--- a/mgw/gsm2pstn.c	Sat Nov 19 23:08:49 2022 -0800
+++ b/mgw/gsm2pstn.c	Sun Nov 20 01:58:47 2022 -0800
@@ -21,8 +21,7 @@
 #include "struct.h"
 #include "select.h"
 #include "int_defs.h"
-
-extern struct timeval cur_event_time;
+#include "dtmf_defs.h"
 
 #define	ERR_WRONG_UDP_SRC	0x0001
 #define	ERR_BAD_RTP_PACKET	0x0002
@@ -83,8 +82,6 @@
 			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;
@@ -97,49 +94,29 @@
 				ep->g2p_err_flags |= ERR_SEQ_BREAK;
 			}
 			m_out = 1;
-		} else {
-			if (ts_delta == SAMPLES_PER_FRAME)
-				m_out = 0;
-			else if (ts_delta > 0 &&
-				 ts_delta % SAMPLES_PER_FRAME == 0)
-				m_out = 1;
-			else {
-				if (!(ep->g2p_err_flags & ERR_TSTAMP_BREAK)) {
-					syslog(LOG_ERR,
-						"GSM RTP stream tstamp break");
-					ep->g2p_err_flags |= ERR_TSTAMP_BREAK;
-				}
-				m_out = 1;
+		} else if (ts_delta != SAMPLES_PER_FRAME) {
+			if (!(ep->g2p_err_flags & ERR_TSTAMP_BREAK)) {
+				syslog(LOG_ERR, "GSM RTP stream tstamp break");
+				ep->g2p_err_flags |= ERR_TSTAMP_BREAK;
 			}
-		}
+			m_out = 1;
+		} else
+			m_out = 0;
 	} else
 		m_out = 1;
 	ep->g2p_state = 1;
 	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:
 		if (bfi)
@@ -151,6 +128,13 @@
 		gsm_decode(ep->gsm_decoder_state, pkt.payload, pcm_samples);
 		break;
 	}
+	if (ep->dtmf_sample_ptr) {
+		bcopy(ep->dtmf_sample_ptr, pcm_samples, SAMPLES_PER_FRAME*2);
+		ep->dtmf_sample_ptr += SAMPLES_PER_FRAME;
+		ep->dtmf_frames_sent++;
+		if (ep->dtmf_frames_sent >= DTMF_MAX_FRAMES)
+			ep->dtmf_sample_ptr = 0;
+	}
 	pkt.m_pt = ep->pstn_payload_type;
 	if (m_out)
 		pkt.m_pt |= 0x80;