FreeCalypso > hg > themwi-system-sw
comparison 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 |
comparison
equal
deleted
inserted
replaced
126:815e4c59162e | 127:f062c32a5116 |
---|---|
3 * in the GSM to PSTN direction. | 3 * in the GSM to PSTN direction. |
4 */ | 4 */ |
5 | 5 |
6 #include <sys/types.h> | 6 #include <sys/types.h> |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 #include <sys/time.h> | |
8 #include <netinet/in.h> | 9 #include <netinet/in.h> |
9 #include <stdio.h> | 10 #include <stdio.h> |
10 #include <stdint.h> | 11 #include <stdint.h> |
11 #include <stdlib.h> | 12 #include <stdlib.h> |
12 #include <string.h> | 13 #include <string.h> |
17 #include "../include/tmgw_ctrl.h" | 18 #include "../include/tmgw_ctrl.h" |
18 #include "../include/tmgw_const.h" | 19 #include "../include/tmgw_const.h" |
19 #include "struct.h" | 20 #include "struct.h" |
20 #include "select.h" | 21 #include "select.h" |
21 #include "int_defs.h" | 22 #include "int_defs.h" |
23 | |
24 extern struct timeval cur_event_time; | |
22 | 25 |
23 #define ERR_WRONG_UDP_SRC 0x0001 | 26 #define ERR_WRONG_UDP_SRC 0x0001 |
24 #define ERR_BAD_RTP_PACKET 0x0002 | 27 #define ERR_BAD_RTP_PACKET 0x0002 |
25 #define ERR_SSRC_CHANGE 0x0004 | 28 #define ERR_SSRC_CHANGE 0x0004 |
26 #define ERR_SEQ_BREAK 0x0008 | 29 #define ERR_SEQ_BREAK 0x0008 |
69 if (!(ep->g2p_err_flags & ERR_SSRC_CHANGE)) { | 72 if (!(ep->g2p_err_flags & ERR_SSRC_CHANGE)) { |
70 syslog(LOG_ERR, "GSM RTP stream changed SSRC"); | 73 syslog(LOG_ERR, "GSM RTP stream changed SSRC"); |
71 ep->g2p_err_flags |= ERR_SSRC_CHANGE; | 74 ep->g2p_err_flags |= ERR_SSRC_CHANGE; |
72 } | 75 } |
73 ep->g2p_state = 0; | 76 ep->g2p_state = 0; |
77 if (ep->dtmf_pp) | |
78 dtmf_stop_immediate(ep); | |
74 } | 79 } |
75 if (ep->g2p_state) { | 80 if (ep->g2p_state) { |
76 seq_delta = ntohs(pkt.seq) - ep->g2p_last_seq; | 81 seq_delta = ntohs(pkt.seq) - ep->g2p_last_seq; |
77 ts_delta = ntohl(pkt.tstamp) - ep->g2p_last_ts; | 82 ts_delta = ntohl(pkt.tstamp) - ep->g2p_last_ts; |
78 if (seq_delta <= 0) | 83 if (seq_delta <= 0) |
102 m_out = 1; | 107 m_out = 1; |
103 ep->g2p_state = 1; | 108 ep->g2p_state = 1; |
104 ep->g2p_ssrc = pkt.ssrc; | 109 ep->g2p_ssrc = pkt.ssrc; |
105 ep->g2p_last_ts = ntohl(pkt.tstamp); | 110 ep->g2p_last_ts = ntohl(pkt.tstamp); |
106 ep->g2p_last_seq = ntohs(pkt.seq); | 111 ep->g2p_last_seq = ntohs(pkt.seq); |
112 ep->g2p_local_time = cur_event_time; | |
107 /* actual transcoding and forwarding */ | 113 /* actual transcoding and forwarding */ |
108 if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN)) { | 114 if (!(ep->fwd_mode & TMGW_FWD_ENABLE_GSM2PSTN)) { |
109 ep->g2p_drop_flag = 1; | 115 ep->g2p_drop_flag = 1; |
110 return; | 116 return; |
111 } | 117 } |
118 if (ep->dtmf_pp) | |
119 return; | |
112 if (ep->g2p_drop_flag) { | 120 if (ep->g2p_drop_flag) { |
113 ep->g2p_drop_flag = 0; | 121 ep->g2p_drop_flag = 0; |
114 m_out = 1; | 122 m_out = 1; |
123 } | |
124 if (ep->dtmf_aftermath) { | |
125 ts_delta = ep->g2p_last_ts - ep->dtmf_last_ts; | |
126 if (ts_delta <= 0) | |
127 return; | |
128 ep->dtmf_aftermath = 0; | |
129 if (ts_delta == SAMPLES_PER_FRAME) | |
130 m_out = 0; | |
131 else | |
132 m_out = 1; | |
115 } | 133 } |
116 switch (ep->gsm_payload_msg_type) { | 134 switch (ep->gsm_payload_msg_type) { |
117 case GSM_TCHF_FRAME: | 135 case GSM_TCHF_FRAME: |
118 gsm_decode(ep->gsm_decoder_state, pkt.payload, pcm_samples); | 136 gsm_decode(ep->gsm_decoder_state, pkt.payload, pcm_samples); |
119 break; | 137 break; |