comparison sip-manual-out/rtp_tx.c @ 192:f8a33603288f

sip-manual-out: generate outgoing RTP stream with PCM silence
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Mar 2023 13:45:31 -0800
parents
children a3d71489672f
comparison
equal deleted inserted replaced
191:6ac96217c442 192:f8a33603288f
1 /*
2 * In this module we implement outgoing RTP stream generation.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <sys/time.h>
8 #include <netinet/in.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <strings.h>
14 #include <unistd.h>
15 #include "../include/tmgw_const.h"
16 #include "../include/rtp_defs.h"
17
18 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr;
19 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected;
20 extern struct timeval cur_event_time;
21
22 static uint32_t rtp_ssrc;
23 static uint32_t rtp_out_ts;
24 static uint16_t rtp_out_seq;
25
26 void
27 assign_rtpout_ssrc()
28 {
29 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid();
30 }
31
32 void
33 generate_rtp_packet()
34 {
35 struct rtp_packet pkt;
36 socklen_t addrlen;
37
38 pkt.v_p_x_cc = 0x80;
39 pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU;
40 pkt.seq = htons(rtp_out_seq++);
41 pkt.tstamp = htonl(rtp_out_ts);
42 rtp_out_ts += 160;
43 pkt.ssrc = rtp_ssrc;
44 memset(pkt.payload, pcma_selected ? 0xD5 : 0xFF, RTP_MAX_PAYLOAD);
45 addrlen = sizeof(struct sockaddr_in);
46 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0,
47 (struct sockaddr *) &rtp_remote_addr, addrlen);
48 }