comparison sip-manual-out/rtp_tx.c @ 195:a3d71489672f

sip-manual-out: implement tfo-req command
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Mar 2023 17:22:42 -0800
parents f8a33603288f
children d3c99b41fb04
comparison
equal deleted inserted replaced
194:05d01e810217 195:a3d71489672f
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 "../include/tmgw_const.h" 15 #include "../include/tmgw_const.h"
16 #include "../include/rtp_defs.h" 16 #include "../include/rtp_defs.h"
17 #include "../libutil/osmo_bits.h"
17 18
18 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr; 19 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr;
19 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected; 20 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected;
20 extern struct timeval cur_event_time; 21 extern struct timeval cur_event_time;
21 22
22 static uint32_t rtp_ssrc; 23 static uint32_t rtp_ssrc;
23 static uint32_t rtp_out_ts; 24 static uint32_t rtp_out_ts;
24 static uint16_t rtp_out_seq; 25 static uint16_t rtp_out_seq;
25 26
27 static uint16_t is_out_buf[7], *is_out_ptr;
28 static unsigned is_out_count;
29
26 void 30 void
27 assign_rtpout_ssrc() 31 assign_rtpout_ssrc()
28 { 32 {
29 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid(); 33 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid();
34 }
35
36 static void
37 insert_is_msg(payload, word)
38 uint8_t *payload;
39 uint16_t word;
40 {
41 ubit_t is_bits[10];
42 uint8_t *bytep;
43 unsigned n;
44
45 uint16_to_bits(word, is_bits, 10);
46 for (n = 0; n < 10; n++) {
47 bytep = payload + n * 16;
48 *bytep &= 0xFE;
49 *bytep |= is_bits[n];
50 }
30 } 51 }
31 52
32 void 53 void
33 generate_rtp_packet() 54 generate_rtp_packet()
34 { 55 {
40 pkt.seq = htons(rtp_out_seq++); 61 pkt.seq = htons(rtp_out_seq++);
41 pkt.tstamp = htonl(rtp_out_ts); 62 pkt.tstamp = htonl(rtp_out_ts);
42 rtp_out_ts += 160; 63 rtp_out_ts += 160;
43 pkt.ssrc = rtp_ssrc; 64 pkt.ssrc = rtp_ssrc;
44 memset(pkt.payload, pcma_selected ? 0xD5 : 0xFF, RTP_MAX_PAYLOAD); 65 memset(pkt.payload, pcma_selected ? 0xD5 : 0xFF, RTP_MAX_PAYLOAD);
66 if (is_out_count) {
67 insert_is_msg(pkt.payload, *is_out_ptr++);
68 is_out_count--;
69 }
45 addrlen = sizeof(struct sockaddr_in); 70 addrlen = sizeof(struct sockaddr_in);
46 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0, 71 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0,
47 (struct sockaddr *) &rtp_remote_addr, addrlen); 72 (struct sockaddr *) &rtp_remote_addr, addrlen);
48 } 73 }
74
75 void
76 send_tfo_req(sig, codec)
77 unsigned sig, codec;
78 {
79 is_out_buf[0] = 0x15A;
80 is_out_buf[1] = 0x1A9;
81 is_out_buf[2] = 0x05D;
82 is_out_buf[3] = 0x14E;
83 is_out_buf[4] = 0x14B;
84 encode_tfo_ext_words(sig, codec, 0, is_out_buf + 5);
85 is_out_ptr = is_out_buf;
86 is_out_count = 7;
87 }