FreeCalypso > hg > themwi-system-sw
comparison 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 |
comparison
equal
deleted
inserted
replaced
169:648a64b2e16b | 170:a6eb2de277f6 |
---|---|
19 #include "../include/tmgw_ctrl.h" | 19 #include "../include/tmgw_ctrl.h" |
20 #include "../include/tmgw_const.h" | 20 #include "../include/tmgw_const.h" |
21 #include "struct.h" | 21 #include "struct.h" |
22 #include "select.h" | 22 #include "select.h" |
23 #include "int_defs.h" | 23 #include "int_defs.h" |
24 | 24 #include "dtmf_defs.h" |
25 extern struct timeval cur_event_time; | |
26 | 25 |
27 #define ERR_WRONG_UDP_SRC 0x0001 | 26 #define ERR_WRONG_UDP_SRC 0x0001 |
28 #define ERR_BAD_RTP_PACKET 0x0002 | 27 #define ERR_BAD_RTP_PACKET 0x0002 |
29 #define ERR_SSRC_CHANGE 0x0004 | 28 #define ERR_SSRC_CHANGE 0x0004 |
30 #define ERR_SEQ_BREAK 0x0008 | 29 #define ERR_SEQ_BREAK 0x0008 |
81 if (!(ep->g2p_err_flags & ERR_SSRC_CHANGE)) { | 80 if (!(ep->g2p_err_flags & ERR_SSRC_CHANGE)) { |
82 syslog(LOG_ERR, "GSM RTP stream changed SSRC"); | 81 syslog(LOG_ERR, "GSM RTP stream changed SSRC"); |
83 ep->g2p_err_flags |= ERR_SSRC_CHANGE; | 82 ep->g2p_err_flags |= ERR_SSRC_CHANGE; |
84 } | 83 } |
85 ep->g2p_state = 0; | 84 ep->g2p_state = 0; |
86 if (ep->dtmf_pp) | |
87 dtmf_stop_immediate(ep); | |
88 } | 85 } |
89 if (ep->g2p_state) { | 86 if (ep->g2p_state) { |
90 seq_delta = ntohs(pkt.seq) - ep->g2p_last_seq; | 87 seq_delta = ntohs(pkt.seq) - ep->g2p_last_seq; |
91 ts_delta = ntohl(pkt.tstamp) - ep->g2p_last_ts; | 88 ts_delta = ntohl(pkt.tstamp) - ep->g2p_last_ts; |
92 if (seq_delta <= 0) | 89 if (seq_delta <= 0) |
95 if (!(ep->g2p_err_flags & ERR_SEQ_BREAK)) { | 92 if (!(ep->g2p_err_flags & ERR_SEQ_BREAK)) { |
96 syslog(LOG_ERR, "GSM RTP stream seq break"); | 93 syslog(LOG_ERR, "GSM RTP stream seq break"); |
97 ep->g2p_err_flags |= ERR_SEQ_BREAK; | 94 ep->g2p_err_flags |= ERR_SEQ_BREAK; |
98 } | 95 } |
99 m_out = 1; | 96 m_out = 1; |
100 } else { | 97 } else if (ts_delta != SAMPLES_PER_FRAME) { |
101 if (ts_delta == SAMPLES_PER_FRAME) | 98 if (!(ep->g2p_err_flags & ERR_TSTAMP_BREAK)) { |
102 m_out = 0; | 99 syslog(LOG_ERR, "GSM RTP stream tstamp break"); |
103 else if (ts_delta > 0 && | 100 ep->g2p_err_flags |= ERR_TSTAMP_BREAK; |
104 ts_delta % SAMPLES_PER_FRAME == 0) | |
105 m_out = 1; | |
106 else { | |
107 if (!(ep->g2p_err_flags & ERR_TSTAMP_BREAK)) { | |
108 syslog(LOG_ERR, | |
109 "GSM RTP stream tstamp break"); | |
110 ep->g2p_err_flags |= ERR_TSTAMP_BREAK; | |
111 } | |
112 m_out = 1; | |
113 } | 101 } |
114 } | 102 m_out = 1; |
103 } else | |
104 m_out = 0; | |
115 } else | 105 } else |
116 m_out = 1; | 106 m_out = 1; |
117 ep->g2p_state = 1; | 107 ep->g2p_state = 1; |
118 ep->g2p_ssrc = pkt.ssrc; | 108 ep->g2p_ssrc = pkt.ssrc; |
119 ep->g2p_last_ts = ntohl(pkt.tstamp); | 109 ep->g2p_last_ts = ntohl(pkt.tstamp); |
120 ep->g2p_last_seq = ntohs(pkt.seq); | 110 ep->g2p_last_seq = ntohs(pkt.seq); |
121 ep->g2p_local_time = cur_event_time; | |
122 /* actual transcoding and forwarding */ | 111 /* actual transcoding and forwarding */ |
123 if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN)) { | 112 if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN)) { |
124 ep->g2p_drop_flag = 1; | 113 ep->g2p_drop_flag = 1; |
125 return; | 114 return; |
126 } | 115 } |
127 if (ep->dtmf_pp) | |
128 return; | |
129 if (ep->g2p_drop_flag) { | 116 if (ep->g2p_drop_flag) { |
130 ep->g2p_drop_flag = 0; | 117 ep->g2p_drop_flag = 0; |
131 m_out = 1; | 118 m_out = 1; |
132 } | |
133 if (ep->dtmf_aftermath) { | |
134 ts_delta = ep->g2p_last_ts - ep->dtmf_last_ts; | |
135 if (ts_delta <= 0) | |
136 return; | |
137 ep->dtmf_aftermath = 0; | |
138 if (ts_delta == SAMPLES_PER_FRAME) | |
139 m_out = 0; | |
140 else | |
141 m_out = 1; | |
142 } | 119 } |
143 switch (ep->gsm_payload_msg_type) { | 120 switch (ep->gsm_payload_msg_type) { |
144 case GSM_TCHF_FRAME: | 121 case GSM_TCHF_FRAME: |
145 if (bfi) | 122 if (bfi) |
146 gsmfr_preproc_bfi(ep->gsm_decoder_extra_state, taf, | 123 gsmfr_preproc_bfi(ep->gsm_decoder_extra_state, taf, |
148 else | 125 else |
149 gsmfr_preproc_good_frame(ep->gsm_decoder_extra_state, | 126 gsmfr_preproc_good_frame(ep->gsm_decoder_extra_state, |
150 pkt.payload); | 127 pkt.payload); |
151 gsm_decode(ep->gsm_decoder_state, pkt.payload, pcm_samples); | 128 gsm_decode(ep->gsm_decoder_state, pkt.payload, pcm_samples); |
152 break; | 129 break; |
130 } | |
131 if (ep->dtmf_sample_ptr) { | |
132 bcopy(ep->dtmf_sample_ptr, pcm_samples, SAMPLES_PER_FRAME*2); | |
133 ep->dtmf_sample_ptr += SAMPLES_PER_FRAME; | |
134 ep->dtmf_frames_sent++; | |
135 if (ep->dtmf_frames_sent >= DTMF_MAX_FRAMES) | |
136 ep->dtmf_sample_ptr = 0; | |
153 } | 137 } |
154 pkt.m_pt = ep->pstn_payload_type; | 138 pkt.m_pt = ep->pstn_payload_type; |
155 if (m_out) | 139 if (m_out) |
156 pkt.m_pt |= 0x80; | 140 pkt.m_pt |= 0x80; |
157 pkt.seq = htons(++ep->g2p_out_seq); | 141 pkt.seq = htons(++ep->g2p_out_seq); |