FreeCalypso > hg > themwi-system-sw
annotate sip-manual-out/rtp_tx.c @ 204:de7c64c4d6fd
themwi-update-outrt: add inn-default-rt possibility
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 04 Apr 2023 21:21:04 -0800 |
parents | f3164f732b84 |
children | fbfa72b114e8 |
rev | line source |
---|---|
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement outgoing RTP stream generation. |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/socket.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/time.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <netinet/in.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <strings.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <unistd.h> |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "../include/tmgw_const.h" |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "../include/rtp_defs.h" |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
17 #include "../libutil/osmo_bits.h" |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern struct timeval cur_event_time; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 static uint32_t rtp_ssrc; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 static uint32_t rtp_out_ts; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 static uint16_t rtp_out_seq; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
201
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
27 static uint16_t tfo_fill_buf[9], tfo_req_buf[7]; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
28 static uint16_t *is_out_ptr; |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
29 static unsigned is_out_count; |
202
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
30 static int tfo_stop_req; |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
31 |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 void |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 assign_rtpout_ssrc() |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 { |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid(); |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
201
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
38 void |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
39 prepare_tfo_fill() |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
40 { |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
41 tfo_fill_buf[0] = 0x15A; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
42 tfo_fill_buf[1] = 0x1A9; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
43 tfo_fill_buf[2] = 0x129; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
44 tfo_fill_buf[3] = 0x15A; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
45 tfo_fill_buf[4] = 0x1A9; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
46 tfo_fill_buf[5] = 0x129; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
47 tfo_fill_buf[6] = 0x15A; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
48 tfo_fill_buf[7] = 0x1A9; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
49 tfo_fill_buf[8] = 0x129; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
50 } |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
51 |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
52 static void |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
53 insert_is_msg(payload, word) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
54 uint8_t *payload; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
55 uint16_t word; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
56 { |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
57 ubit_t is_bits[10]; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
58 uint8_t *bytep; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
59 unsigned n; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
60 |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
61 uint16_to_bits(word, is_bits, 10); |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
62 for (n = 0; n < 10; n++) { |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
63 bytep = payload + n * 16; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
64 *bytep &= 0xFE; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
65 *bytep |= is_bits[n]; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
66 } |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
67 } |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
68 |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 void |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 generate_rtp_packet() |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 { |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 struct rtp_packet pkt; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 socklen_t addrlen; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 pkt.v_p_x_cc = 0x80; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 pkt.seq = htons(rtp_out_seq++); |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 pkt.tstamp = htonl(rtp_out_ts); |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 rtp_out_ts += 160; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 pkt.ssrc = rtp_ssrc; |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 memset(pkt.payload, pcma_selected ? 0xD5 : 0xFF, RTP_MAX_PAYLOAD); |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
82 if (is_out_count) { |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
83 insert_is_msg(pkt.payload, *is_out_ptr++); |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
84 is_out_count--; |
202
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
85 if (!is_out_count && !tfo_stop_req) { |
201
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
86 is_out_ptr = tfo_req_buf; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
87 is_out_count = 7; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
88 } |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
89 } |
192
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 addrlen = sizeof(struct sockaddr_in); |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0, |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 (struct sockaddr *) &rtp_remote_addr, addrlen); |
f8a33603288f
sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
94 |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
95 void |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
96 send_tfo_req(sig, codec) |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
97 unsigned sig, codec; |
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
98 { |
201
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
99 tfo_req_buf[0] = 0x15A; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
100 tfo_req_buf[1] = 0x1A9; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
101 tfo_req_buf[2] = 0x05D; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
102 tfo_req_buf[3] = 0x14E; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
103 tfo_req_buf[4] = 0x14B; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
104 encode_tfo_ext_words(sig, codec, 0, tfo_req_buf + 5); |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
105 is_out_ptr = tfo_fill_buf; |
d3c99b41fb04
sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents:
195
diff
changeset
|
106 is_out_count = 9; |
202
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
107 tfo_stop_req = 0; |
195
a3d71489672f
sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents:
192
diff
changeset
|
108 } |
202
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
109 |
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
110 void |
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
111 stop_tfo_out() |
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
112 { |
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
113 tfo_stop_req = 1; |
f3164f732b84
sip-manual-out: add tfo-stop command
Mychaela Falconia <falcon@freecalypso.org>
parents:
201
diff
changeset
|
114 } |