comparison test-v22/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 test-fsk/rtp_tx.c@030d52b96a23
children
comparison
equal deleted inserted replaced
9:ff535725e01f 10:3c5734b88c20
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 <spandsp.h>
16 #include "../include/tmgw_const.h"
17 #include "../include/rtp_defs.h"
18 #include "../include/pstn_defs.h"
19 #include "../libutil/osmo_bits.h"
20
21 extern struct sockaddr_in rtp_local_addr, rtp_remote_addr;
22 extern int rtp_udp_fd, rtcp_udp_fd, pcma_selected;
23 extern struct timeval cur_event_time;
24
25 static uint32_t rtp_ssrc;
26 static uint32_t rtp_out_ts;
27 static uint16_t rtp_out_seq;
28
29 static g711_state_t *g711_enc_state;
30
31 void
32 assign_rtpout_ssrc()
33 {
34 rtp_ssrc = cur_event_time.tv_sec ^ cur_event_time.tv_usec ^ getpid();
35 }
36
37 void
38 init_pcm_tx()
39 {
40 g711_enc_state = g711_init(NULL, pcma_selected ? G711_ALAW : G711_ULAW);
41 if (!g711_enc_state) {
42 fprintf(stderr, "error: g711_init() failed!\n");
43 exit(1);
44 }
45 }
46
47 void
48 generate_rtp_packet()
49 {
50 struct rtp_packet pkt;
51 socklen_t addrlen;
52 int16_t linear[FRAME_20MS];
53
54 pkt.v_p_x_cc = 0x80;
55 pkt.m_pt = pcma_selected ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU;
56 pkt.seq = htons(rtp_out_seq++);
57 pkt.tstamp = htonl(rtp_out_ts);
58 rtp_out_ts += FRAME_20MS;
59 pkt.ssrc = rtp_ssrc;
60 fill_tx_frame(linear);
61 g711_encode(g711_enc_state, pkt.payload, linear, FRAME_20MS);
62 addrlen = sizeof(struct sockaddr_in);
63 sendto(rtp_udp_fd, &pkt, RTP_PACKET_SIZE_PSTN, 0,
64 (struct sockaddr *) &rtp_remote_addr, addrlen);
65 }