annotate sip-manual-out/main.c @ 267:81958b35f74d

NANP validation: allow made-up area codes of N9X form
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 13 Nov 2023 15:28:09 -0800
parents eac3e0b6ce02
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This is the main module for sip-manual-out test program.
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/time.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/errno.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <netinet/in.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <arpa/inet.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <strings.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <unistd.h>
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../libsip/out_msg.h"
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libsip/sdp.h"
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern int sip_socket;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern struct in_addr sip_bind_ip, sip_dest_ip;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 extern unsigned sip_bind_port, sip_dest_port;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern char sip_dest_domain[];
187
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
23 extern struct sockaddr_in rtp_local_addr;
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
24 extern int rtp_udp_fd, rtcp_udp_fd;
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
25 extern int rtp_out_enable;
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 struct sockaddr_in sip_dest_sin;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 char from_uri[128], to_uri[128], call_id[128];
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 struct timeval cur_event_time;
120
c62d0f28da6f sip-manual-out: make Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents: 119
diff changeset
30 unsigned max_forwards = 70;
121
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
31 int declare_100rel_supp;
122
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
32 int pcma_codec_pref, pcma_codec_force;
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 send_invite_req()
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 struct sip_msg_out msg;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 struct sdp_gen sdp;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 int rc;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 rc = start_request_out_msg(&msg, "INVITE", to_uri);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (rc < 0) {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 msg_size_err: fprintf(stderr, "composing INVITE req: msg size error\n");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 exit(1);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
123
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 122
diff changeset
45 rc = add_req_boilerplate(&msg, "1 INVITE", 0);
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (rc < 0)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 goto msg_size_err;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 rc = add_contact_header(&msg);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (rc < 0)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 goto msg_size_err;
121
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
51 if (declare_100rel_supp) {
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
52 rc = out_msg_add_header(&msg, "Supported", "100rel");
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
53 if (rc < 0)
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
54 goto msg_size_err;
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
55 }
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 rc = out_msg_add_header(&msg, "Content-Type", "application/sdp");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (rc < 0)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 goto msg_size_err;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 bzero(&sdp, sizeof sdp);
187
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
60 sdp.conn_ip = rtp_local_addr.sin_addr;
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
61 sdp.conn_port = ntohs(rtp_local_addr.sin_port);
122
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
62 if (pcma_codec_force)
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
63 sdp.codec_mask = SDP_CODEC_MASK_PCMA;
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
64 else {
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
65 sdp.codec_mask = SDP_CODEC_MASK_BOTH;
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
66 if (pcma_codec_pref)
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
67 sdp.codec_mask |= SDP_CODEC_MASK_PCMA_PREF;
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
68 }
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 sdp.session_id = sdp.conn_port << 16;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 sdp.owner_ip = sip_bind_ip;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 rc = out_msg_finish_sdp(&msg, &sdp);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (rc < 0)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 goto msg_size_err;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 sip_tx_packet(&msg, &sip_dest_sin);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
77 static void
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
78 preliminary_proc(argc, argv)
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
79 char **argv;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
80 {
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
81 extern int optind;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
82 extern char *optarg;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
83 char *logfile;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
84 int opt, rc;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
85
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
86 logfile = 0;
122
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
87 while ((opt = getopt(argc, argv, "aAl:m:r")) != EOF) {
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
88 switch (opt) {
122
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
89 case 'a':
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
90 pcma_codec_pref = 1;
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
91 continue;
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
92 case 'A':
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
93 pcma_codec_force = 1;
07e4cc5f824c sip-manual-out: add options to test PCMA codec
Mychaela Falconia <falcon@freecalypso.org>
parents: 121
diff changeset
94 continue;
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
95 case 'l':
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
96 logfile = optarg;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
97 continue;
120
c62d0f28da6f sip-manual-out: make Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents: 119
diff changeset
98 case 'm':
c62d0f28da6f sip-manual-out: make Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents: 119
diff changeset
99 max_forwards = atoi(optarg);
c62d0f28da6f sip-manual-out: make Max-Forwards configurable
Mychaela Falconia <falcon@freecalypso.org>
parents: 119
diff changeset
100 continue;
121
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
101 case 'r':
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
102 declare_100rel_supp = 1;
5dc0190a624e sip-manual-out: add -r option for testing 100rel
Mychaela Falconia <falcon@freecalypso.org>
parents: 120
diff changeset
103 continue;
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
104 default:
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
105 usage:
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
106 fprintf(stderr,
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
107 "usage: %s [options] dest-conf from-num to-num\n",
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
108 argv[0]);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
109 exit(1);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
110 }
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
111 }
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
112 if (argc != optind + 3)
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
113 goto usage;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
114 read_config_file(argv[optind]);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
115 open_sip_udp_socket();
187
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
116 obtain_rtp_endp();
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
117 sip_dest_sin.sin_family = AF_INET;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
118 sip_dest_sin.sin_addr = sip_dest_ip;
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
119 sip_dest_sin.sin_port = htons(sip_dest_port);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
120 sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[optind+1],
187
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
121 inet_ntoa(sip_bind_ip), ntohs(rtp_local_addr.sin_port));
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
122 sprintf(to_uri, "sip:%s@%s", argv[optind+2], sip_dest_domain);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
123 if (logfile) {
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
124 rc = open_sip_log_file(logfile);
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
125 if (rc < 0)
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
126 exit(1); /* error msg already printed */
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
127 }
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
128 }
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
129
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 main(argc, argv)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 char **argv;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 fd_set fds;
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
134 struct timeval next_rtp_out, timeout;
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
135 int rc, max_fd, rtp_out_running;
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
119
056616f7e8ab sip-manual-out: convert command line to getopt style
Mychaela Falconia <falcon@freecalypso.org>
parents: 74
diff changeset
137 preliminary_proc(argc, argv);
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 gettimeofday(&cur_event_time, 0);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 sprintf(call_id, "%08u_%u@%s",
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 (unsigned)(cur_event_time.tv_sec % 100000000),
187
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
141 ntohs(rtp_local_addr.sin_port), inet_ntoa(sip_bind_ip));
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 send_invite_req();
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 /* main select loop */
187
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
144 max_fd = sip_socket;
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
145 if (rtp_udp_fd > max_fd)
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
146 max_fd = rtp_udp_fd;
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
147 if (rtcp_udp_fd > max_fd)
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
148 max_fd = rtcp_udp_fd;
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
149 rtp_out_running = 0;
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 for (;;) {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 FD_ZERO(&fds);
123
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 122
diff changeset
152 FD_SET(0, &fds);
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 FD_SET(sip_socket, &fds);
187
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
154 FD_SET(rtp_udp_fd, &fds);
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
155 FD_SET(rtcp_udp_fd, &fds);
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
156 if (rtp_out_enable) {
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
157 if (!rtp_out_running) {
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
158 printf("Starting RTP output\n");
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
159 bcopy(&cur_event_time, &next_rtp_out,
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
160 sizeof(struct timeval));
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
161 rtp_out_running = 1;
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
162 }
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
163 if (timercmp(&cur_event_time, &next_rtp_out, <))
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
164 timersub(&next_rtp_out, &cur_event_time,
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
165 &timeout);
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
166 else
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
167 timerclear(&timeout);
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
168 rc = select(max_fd+1, &fds, 0, 0, &timeout);
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
169 } else {
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
170 if (rtp_out_running) {
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
171 printf("Stopping RTP output\n");
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
172 rtp_out_running = 0;
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
173 }
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
174 rc = select(max_fd+1, &fds, 0, 0, 0);
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
175 }
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 if (rc < 0) {
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 if (errno == EINTR)
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 continue;
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 perror("select");
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 exit(1);
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 gettimeofday(&cur_event_time, 0);
123
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 122
diff changeset
183 if (FD_ISSET(0, &fds))
a36b731bfef9 sip-manual-out: implement sending BYE and CANCEL
Mychaela Falconia <falcon@freecalypso.org>
parents: 122
diff changeset
184 select_stdin();
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 if (FD_ISSET(sip_socket, &fds))
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 sip_socket_select();
187
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
187 if (FD_ISSET(rtp_udp_fd, &fds))
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
188 rtp_rx_select();
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
189 if (FD_ISSET(rtcp_udp_fd, &fds))
258932879f8b sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
Mychaela Falconia <falcon@freecalypso.org>
parents: 123
diff changeset
190 rtcp_rx_select();
196
eac3e0b6ce02 sip-manual-out: (hopefully) fix RTP output timing
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
191 if (rtp_out_running && (rc == 0)) {
192
f8a33603288f sip-manual-out: generate outgoing RTP stream with PCM silence
Mychaela Falconia <falcon@freecalypso.org>
parents: 187
diff changeset
192 generate_rtp_packet();
196
eac3e0b6ce02 sip-manual-out: (hopefully) fix RTP output timing
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
193 next_rtp_out.tv_usec += 20000;
eac3e0b6ce02 sip-manual-out: (hopefully) fix RTP output timing
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
194 if (next_rtp_out.tv_usec >= 1000000) {
eac3e0b6ce02 sip-manual-out: (hopefully) fix RTP output timing
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
195 next_rtp_out.tv_sec++;
eac3e0b6ce02 sip-manual-out: (hopefully) fix RTP output timing
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
196 next_rtp_out.tv_usec -= 1000000;
eac3e0b6ce02 sip-manual-out: (hopefully) fix RTP output timing
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
197 }
eac3e0b6ce02 sip-manual-out: (hopefully) fix RTP output timing
Mychaela Falconia <falcon@freecalypso.org>
parents: 192
diff changeset
198 }
71
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 }
d74b545a3c2a sip-manual-out: new test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 }