comparison sip-manual-out/main.c @ 187:258932879f8b

sip-manual-out: rework for internal RTP handling, using themwi-rtp-mgr
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 16 Mar 2023 23:46:17 -0800
parents a36b731bfef9
children f8a33603288f
comparison
equal deleted inserted replaced
186:068fce34e565 187:258932879f8b
18 18
19 extern int sip_socket; 19 extern int sip_socket;
20 extern struct in_addr sip_bind_ip, sip_dest_ip; 20 extern struct in_addr sip_bind_ip, sip_dest_ip;
21 extern unsigned sip_bind_port, sip_dest_port; 21 extern unsigned sip_bind_port, sip_dest_port;
22 extern char sip_dest_domain[]; 22 extern char sip_dest_domain[];
23 extern struct sockaddr_in dummy_rtp_endp; 23 extern struct sockaddr_in rtp_local_addr;
24 extern int rtp_udp_fd, rtcp_udp_fd;
24 25
25 struct sockaddr_in sip_dest_sin; 26 struct sockaddr_in sip_dest_sin;
26 char from_uri[128], to_uri[128], call_id[128]; 27 char from_uri[128], to_uri[128], call_id[128];
27 struct timeval cur_event_time; 28 struct timeval cur_event_time;
28 unsigned max_forwards = 70; 29 unsigned max_forwards = 70;
53 } 54 }
54 rc = out_msg_add_header(&msg, "Content-Type", "application/sdp"); 55 rc = out_msg_add_header(&msg, "Content-Type", "application/sdp");
55 if (rc < 0) 56 if (rc < 0)
56 goto msg_size_err; 57 goto msg_size_err;
57 bzero(&sdp, sizeof sdp); 58 bzero(&sdp, sizeof sdp);
58 sdp.conn_ip = dummy_rtp_endp.sin_addr; 59 sdp.conn_ip = rtp_local_addr.sin_addr;
59 sdp.conn_port = ntohs(dummy_rtp_endp.sin_port); 60 sdp.conn_port = ntohs(rtp_local_addr.sin_port);
60 if (pcma_codec_force) 61 if (pcma_codec_force)
61 sdp.codec_mask = SDP_CODEC_MASK_PCMA; 62 sdp.codec_mask = SDP_CODEC_MASK_PCMA;
62 else { 63 else {
63 sdp.codec_mask = SDP_CODEC_MASK_BOTH; 64 sdp.codec_mask = SDP_CODEC_MASK_BOTH;
64 if (pcma_codec_pref) 65 if (pcma_codec_pref)
109 } 110 }
110 if (argc != optind + 3) 111 if (argc != optind + 3)
111 goto usage; 112 goto usage;
112 read_config_file(argv[optind]); 113 read_config_file(argv[optind]);
113 open_sip_udp_socket(); 114 open_sip_udp_socket();
114 obtain_dummy_rtp(); 115 obtain_rtp_endp();
115 sip_dest_sin.sin_family = AF_INET; 116 sip_dest_sin.sin_family = AF_INET;
116 sip_dest_sin.sin_addr = sip_dest_ip; 117 sip_dest_sin.sin_addr = sip_dest_ip;
117 sip_dest_sin.sin_port = htons(sip_dest_port); 118 sip_dest_sin.sin_port = htons(sip_dest_port);
118 sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[optind+1], 119 sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[optind+1],
119 inet_ntoa(sip_bind_ip), ntohs(dummy_rtp_endp.sin_port)); 120 inet_ntoa(sip_bind_ip), ntohs(rtp_local_addr.sin_port));
120 sprintf(to_uri, "sip:%s@%s", argv[optind+2], sip_dest_domain); 121 sprintf(to_uri, "sip:%s@%s", argv[optind+2], sip_dest_domain);
121 if (logfile) { 122 if (logfile) {
122 rc = open_sip_log_file(logfile); 123 rc = open_sip_log_file(logfile);
123 if (rc < 0) 124 if (rc < 0)
124 exit(1); /* error msg already printed */ 125 exit(1); /* error msg already printed */
127 128
128 main(argc, argv) 129 main(argc, argv)
129 char **argv; 130 char **argv;
130 { 131 {
131 fd_set fds; 132 fd_set fds;
132 int rc; 133 int rc, max_fd;
133 134
134 preliminary_proc(argc, argv); 135 preliminary_proc(argc, argv);
135 gettimeofday(&cur_event_time, 0); 136 gettimeofday(&cur_event_time, 0);
136 sprintf(call_id, "%08u_%u@%s", 137 sprintf(call_id, "%08u_%u@%s",
137 (unsigned)(cur_event_time.tv_sec % 100000000), 138 (unsigned)(cur_event_time.tv_sec % 100000000),
138 ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip)); 139 ntohs(rtp_local_addr.sin_port), inet_ntoa(sip_bind_ip));
139 send_invite_req(); 140 send_invite_req();
140 /* main select loop */ 141 /* main select loop */
142 max_fd = sip_socket;
143 if (rtp_udp_fd > max_fd)
144 max_fd = rtp_udp_fd;
145 if (rtcp_udp_fd > max_fd)
146 max_fd = rtcp_udp_fd;
141 for (;;) { 147 for (;;) {
142 FD_ZERO(&fds); 148 FD_ZERO(&fds);
143 FD_SET(0, &fds); 149 FD_SET(0, &fds);
144 FD_SET(sip_socket, &fds); 150 FD_SET(sip_socket, &fds);
145 rc = select(sip_socket+1, &fds, 0, 0, 0); 151 FD_SET(rtp_udp_fd, &fds);
152 FD_SET(rtcp_udp_fd, &fds);
153 rc = select(max_fd+1, &fds, 0, 0, 0);
146 if (rc < 0) { 154 if (rc < 0) {
147 if (errno == EINTR) 155 if (errno == EINTR)
148 continue; 156 continue;
149 perror("select"); 157 perror("select");
150 exit(1); 158 exit(1);
152 gettimeofday(&cur_event_time, 0); 160 gettimeofday(&cur_event_time, 0);
153 if (FD_ISSET(0, &fds)) 161 if (FD_ISSET(0, &fds))
154 select_stdin(); 162 select_stdin();
155 if (FD_ISSET(sip_socket, &fds)) 163 if (FD_ISSET(sip_socket, &fds))
156 sip_socket_select(); 164 sip_socket_select();
165 if (FD_ISSET(rtp_udp_fd, &fds))
166 rtp_rx_select();
167 if (FD_ISSET(rtcp_udp_fd, &fds))
168 rtcp_rx_select();
157 } 169 }
158 } 170 }