annotate sip-manual-out/rtp_tx.c @ 201:d3c99b41fb04

sip-manual-out TFO: rework for continuous output of TFO_REQ
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 02 Apr 2023 18:01:34 -0800
parents a3d71489672f
children f3164f732b84
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
30
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 void
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 assign_rtpout_ssrc()
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 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
35 }
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
201
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 195
diff changeset
37 void
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 195
diff changeset
38 prepare_tfo_fill()
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 195
diff changeset
39 {
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 195
diff changeset
40 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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 }
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 195
diff changeset
50
195
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
51 static void
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
52 insert_is_msg(payload, word)
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
53 uint8_t *payload;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
54 uint16_t word;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
55 {
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
56 ubit_t is_bits[10];
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
57 uint8_t *bytep;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
58 unsigned n;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
59
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
60 uint16_to_bits(word, is_bits, 10);
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
61 for (n = 0; n < 10; n++) {
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
62 bytep = payload + n * 16;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
63 *bytep &= 0xFE;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
64 *bytep |= is_bits[n];
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
65 }
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
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 void
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 generate_rtp_packet()
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 {
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 struct rtp_packet pkt;
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 socklen_t addrlen;
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 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
75 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
76 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
77 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
78 rtp_out_ts += 160;
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 pkt.ssrc = rtp_ssrc;
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 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
81 if (is_out_count) {
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
82 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
83 is_out_count--;
201
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 195
diff changeset
84 if (!is_out_count) {
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 195
diff changeset
85 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
86 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
87 }
195
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
88 }
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 addrlen = sizeof(struct sockaddr_in);
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 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
91 (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
92 }
195
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
93
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
94 void
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
95 send_tfo_req(sig, codec)
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
96 unsigned sig, codec;
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
97 {
201
d3c99b41fb04 sip-manual-out TFO: rework for continuous output of TFO_REQ
Mychaela Falconia <falcon@freecalypso.org>
parents: 195
diff changeset
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 is_out_count = 9;
195
a3d71489672f sip-manual-out: implement tfo-req command
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
106 }