FreeCalypso > hg > sipout-test-utils
annotate test-v22/rtp_tx.c @ 18:f7321b25195e default tip
new build system for ThemWi sw components
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 14 May 2024 18:08:35 -0800 |
parents | 3c5734b88c20 |
children |
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; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 static uint32_t rtp_ssrc; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 static uint32_t rtp_out_ts; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 static uint16_t rtp_out_seq; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
4
030d52b96a23
test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
29 static g711_state_t *g711_enc_state; |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 assign_rtpout_ssrc() |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 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
|
35 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 void |
4
030d52b96a23
test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
38 init_pcm_tx() |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
4
030d52b96a23
test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
40 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
|
41 if (!g711_enc_state) { |
030d52b96a23
test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
42 fprintf(stderr, "error: g711_init() failed!\n"); |
030d52b96a23
test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
43 exit(1); |
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 } |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 void |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 generate_rtp_packet() |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 { |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 struct rtp_packet pkt; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 socklen_t addrlen; |
4
030d52b96a23
test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
52 int16_t linear[FRAME_20MS]; |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 pkt.v_p_x_cc = 0x80; |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 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
|
56 pkt.seq = htons(rtp_out_seq++); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 pkt.tstamp = htonl(rtp_out_ts); |
4
030d52b96a23
test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
58 rtp_out_ts += FRAME_20MS; |
0
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 pkt.ssrc = rtp_ssrc; |
10
3c5734b88c20
sipout-test-v22 put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
60 fill_tx_frame(linear); |
4
030d52b96a23
test-fsk: implement SpanDSP Tx output
Mychaela Falconia <falcon@freecalypso.org>
parents:
3
diff
changeset
|
61 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
|
62 addrlen = sizeof(struct sockaddr_in); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0, |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 (struct sockaddr *) &rtp_remote_addr, addrlen); |
35c0d9f03c0a
beginning with sipout-test-voice,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |