diff 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
line wrap: on
line diff
--- a/sip-manual-out/main.c	Sun Mar 12 08:41:10 2023 -0800
+++ b/sip-manual-out/main.c	Thu Mar 16 23:46:17 2023 -0800
@@ -20,7 +20,8 @@
 extern struct in_addr sip_bind_ip, sip_dest_ip;
 extern unsigned sip_bind_port, sip_dest_port;
 extern char sip_dest_domain[];
-extern struct sockaddr_in dummy_rtp_endp;
+extern struct sockaddr_in rtp_local_addr;
+extern int rtp_udp_fd, rtcp_udp_fd;
 
 struct sockaddr_in sip_dest_sin;
 char from_uri[128], to_uri[128], call_id[128];
@@ -55,8 +56,8 @@
 	if (rc < 0)
 		goto msg_size_err;
 	bzero(&sdp, sizeof sdp);
-	sdp.conn_ip = dummy_rtp_endp.sin_addr;
-	sdp.conn_port = ntohs(dummy_rtp_endp.sin_port);
+	sdp.conn_ip = rtp_local_addr.sin_addr;
+	sdp.conn_port = ntohs(rtp_local_addr.sin_port);
 	if (pcma_codec_force)
 		sdp.codec_mask = SDP_CODEC_MASK_PCMA;
 	else {
@@ -111,12 +112,12 @@
 		goto usage;
 	read_config_file(argv[optind]);
 	open_sip_udp_socket();
-	obtain_dummy_rtp();
+	obtain_rtp_endp();
 	sip_dest_sin.sin_family = AF_INET;
 	sip_dest_sin.sin_addr = sip_dest_ip;
 	sip_dest_sin.sin_port = htons(sip_dest_port);
 	sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[optind+1],
-		inet_ntoa(sip_bind_ip), ntohs(dummy_rtp_endp.sin_port));
+		inet_ntoa(sip_bind_ip), ntohs(rtp_local_addr.sin_port));
 	sprintf(to_uri, "sip:%s@%s", argv[optind+2], sip_dest_domain);
 	if (logfile) {
 		rc = open_sip_log_file(logfile);
@@ -129,20 +130,27 @@
 	char **argv;
 {
 	fd_set fds;
-	int rc;
+	int rc, max_fd;
 
 	preliminary_proc(argc, argv);
 	gettimeofday(&cur_event_time, 0);
 	sprintf(call_id, "%08u_%u@%s",
 		(unsigned)(cur_event_time.tv_sec % 100000000),
-		ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip));
+		ntohs(rtp_local_addr.sin_port), inet_ntoa(sip_bind_ip));
 	send_invite_req();
 	/* main select loop */
+	max_fd = sip_socket;
+	if (rtp_udp_fd > max_fd)
+		max_fd = rtp_udp_fd;
+	if (rtcp_udp_fd > max_fd)
+		max_fd = rtcp_udp_fd;
 	for (;;) {
 		FD_ZERO(&fds);
 		FD_SET(0, &fds);
 		FD_SET(sip_socket, &fds);
-		rc = select(sip_socket+1, &fds, 0, 0, 0);
+		FD_SET(rtp_udp_fd, &fds);
+		FD_SET(rtcp_udp_fd, &fds);
+		rc = select(max_fd+1, &fds, 0, 0, 0);
 		if (rc < 0) {
 			if (errno == EINTR)
 				continue;
@@ -154,5 +162,9 @@
 			select_stdin();
 		if (FD_ISSET(sip_socket, &fds))
 			sip_socket_select();
+		if (FD_ISSET(rtp_udp_fd, &fds))
+			rtp_rx_select();
+		if (FD_ISSET(rtcp_udp_fd, &fds))
+			rtcp_rx_select();
 	}
 }