comparison test-fsk/rtp_tx.c @ 4:030d52b96a23

test-fsk: implement SpanDSP Tx output
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 04 Mar 2024 22:08:19 -0800
parents cc997f9ae186
children
comparison
equal deleted inserted replaced
3:cc997f9ae186 4:030d52b96a23
10 #include <stdint.h> 10 #include <stdint.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <string.h> 12 #include <string.h>
13 #include <strings.h> 13 #include <strings.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 #include <spandsp.h>
15 #include "../include/tmgw_const.h" 16 #include "../include/tmgw_const.h"
16 #include "../include/rtp_defs.h" 17 #include "../include/rtp_defs.h"
18 #include "../include/pstn_defs.h"
17 #include "../libutil/osmo_bits.h" 19 #include "../libutil/osmo_bits.h"
18 20
19 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr; 21 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr;
20 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected; 22 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected;
21 extern struct timeval cur_event_time; 23 extern struct timeval cur_event_time;
24 extern int fsk_mode_tx;
22 25
23 static uint32_t rtp_ssrc; 26 static uint32_t rtp_ssrc;
24 static uint32_t rtp_out_ts; 27 static uint32_t rtp_out_ts;
25 static uint16_t rtp_out_seq; 28 static uint16_t rtp_out_seq;
26 29
27 static uint8_t pcm_fill_octet; 30 static fsk_tx_state_t *fsk_tx_state;
31 static g711_state_t *g711_enc_state;
28 32
29 void 33 void
30 assign_rtpout_ssrc() 34 assign_rtpout_ssrc()
31 { 35 {
32 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid(); 36 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid();
33 } 37 }
34 38
39 static int
40 supply_bit()
41 {
42 return 1;
43 }
44
35 void 45 void
36 init_pcm_fill_octet() 46 init_pcm_tx()
37 { 47 {
38 if (pcma_selected) 48 fsk_tx_state = fsk_tx_init(NULL, &preset_fsk_specs[fsk_mode_tx],
39 pcm_fill_octet = 0xD5; 49 supply_bit, NULL);
40 else 50 if (!fsk_tx_state) {
41 pcm_fill_octet = 0xFF; 51 fprintf(stderr, "error: fsk_tx_init() failed!\n");
52 exit(1);
53 }
54 g711_enc_state = g711_init(NULL, pcma_selected ? G711_ALAW : G711_ULAW);
55 if (!g711_enc_state) {
56 fprintf(stderr, "error: g711_init() failed!\n");
57 exit(1);
58 }
42 } 59 }
43 60
44 void 61 void
45 generate_rtp_packet() 62 generate_rtp_packet()
46 { 63 {
47 struct rtp_packet pkt; 64 struct rtp_packet pkt;
48 socklen_t addrlen; 65 socklen_t addrlen;
66 int16_t linear[FRAME_20MS];
49 67
50 pkt.v_p_x_cc = 0x80; 68 pkt.v_p_x_cc = 0x80;
51 pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU; 69 pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU;
52 pkt.seq = htons(rtp_out_seq++); 70 pkt.seq = htons(rtp_out_seq++);
53 pkt.tstamp = htonl(rtp_out_ts); 71 pkt.tstamp = htonl(rtp_out_ts);
54 rtp_out_ts += 160; 72 rtp_out_ts += FRAME_20MS;
55 pkt.ssrc = rtp_ssrc; 73 pkt.ssrc = rtp_ssrc;
56 memset(pkt.payload, pcm_fill_octet, RTP_MAX_PAYLOAD); 74 fsk_tx(fsk_tx_state, linear, FRAME_20MS);
75 g711_encode(g711_enc_state, pkt.payload, linear, FRAME_20MS);
57 addrlen = sizeof(struct sockaddr_in); 76 addrlen = sizeof(struct sockaddr_in);
58 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0, 77 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0,
59 (struct sockaddr *) &rtp_remote_addr, addrlen); 78 (struct sockaddr *) &rtp_remote_addr, addrlen);
60 } 79 }
61
62 void
63 set_pcm_fill_octet(oct)
64 unsigned oct;
65 {
66 pcm_fill_octet = oct;
67 }