annotate test-fsk/rtp_tx.c @ 10:3c5734b88c20

sipout-test-v22 put together
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 07 Mar 2024 02:33:49 -0800
parents 030d52b96a23
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement outgoing RTP stream generation.
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/time.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <unistd.h>
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
15 #include <spandsp.h>
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../include/tmgw_const.h"
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../include/rtp_defs.h"
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
18 #include "../include/pstn_defs.h"
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "../libutil/osmo_bits.h"
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern struct timeval cur_event_time;
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
24 extern int fsk_mode_tx;
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static uint32_t rtp_ssrc;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 static uint32_t rtp_out_ts;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static uint16_t rtp_out_seq;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
30 static fsk_tx_state_t *fsk_tx_state;
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
31 static g711_state_t *g711_enc_state;
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 void
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 assign_rtpout_ssrc()
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid();
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
39 static int
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
40 supply_bit()
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
41 {
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
42 return 1;
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
43 }
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
44
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 void
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
46 init_pcm_tx()
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 {
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
48 fsk_tx_state = fsk_tx_init(NULL, &preset_fsk_specs[fsk_mode_tx],
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
49 supply_bit, NULL);
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
50 if (!fsk_tx_state) {
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
51 fprintf(stderr, "error: fsk_tx_init() failed!\n");
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
52 exit(1);
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
53 }
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
54 g711_enc_state = g711_init(NULL, pcma_selected ? G711_ALAW : G711_ULAW);
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
55 if (!g711_enc_state) {
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
56 fprintf(stderr, "error: g711_init() failed!\n");
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
57 exit(1);
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
58 }
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 void
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 generate_rtp_packet()
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 struct rtp_packet pkt;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 socklen_t addrlen;
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
66 int16_t linear[FRAME_20MS];
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 pkt.v_p_x_cc = 0x80;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU;
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 pkt.seq = htons(rtp_out_seq++);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 pkt.tstamp = htonl(rtp_out_ts);
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
72 rtp_out_ts += FRAME_20MS;
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 pkt.ssrc = rtp_ssrc;
4
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
74 fsk_tx(fsk_tx_state, linear, FRAME_20MS);
030d52b96a23 test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
75 g711_encode(g711_enc_state, pkt.payload, linear, FRAME_20MS);
0
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 addrlen = sizeof(struct sockaddr_in);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0,
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 (struct sockaddr *) &rtp_remote_addr, addrlen);
35c0d9f03c0a beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }